HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderPassState.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HD_ST_RENDER_PASS_STATE_H
8 #define PXR_IMAGING_HD_ST_RENDER_PASS_STATE_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
14 
15 #include <memory>
16 
18 
21 struct HgiMultiSampleState;
23 class HgiCapabilities;
24 
25 using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
26 using HdStRenderPassStateSharedPtr = std::shared_ptr<class HdStRenderPassState>;
27 
28 using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
29 
30 using HdStShaderCodeSharedPtr = std::shared_ptr<class HdStShaderCode>;
31 using HdStLightingShaderSharedPtr = std::shared_ptr<class HdStLightingShader>;
33  std::shared_ptr<class HdStRenderPassShader>;
35  std::shared_ptr<class HdSt_FallbackLightingShader>;
37  std::shared_ptr<class HdSt_GeometricShader>;
38 using HdStShaderCodeSharedPtrVector = std::vector<HdStShaderCodeSharedPtr>;
39 class HdRenderIndex;
40 class HdSt_ResourceBinder;
41 
42 /// \class HdStRenderPassState
43 ///
44 /// A set of rendering parameters used among render passes.
45 ///
46 /// Parameters are expressed as GL states, uniforms or shaders.
47 ///
49 {
50 public:
51  HDST_API
53  HDST_API
55  HDST_API
56  ~HdStRenderPassState() override;
57 
58  HDST_API
59  void
60  Prepare(HdResourceRegistrySharedPtr const &resourceRegistry) override;
61 
62  /// XXX: Bind and Unbind set./restore the following GL state.
63  /// This will be reworked to use Hgi in the near future.
64  /// Following states may be changed and restored to
65  /// the GL default at Unbind().
66  /// glEnable(GL_BLEND);
67  /// glEnable(GL_CULL_FACE);
68  /// glEnable(GL_POLYGON_OFFSET_FILL)
69  /// glEnable(GL_PROGRAM_POINT_SIZE);
70  /// glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE)
71  /// glEnable(GL_DEPTH_TEST);
72  /// glEnable(GL_STENCIL_TEST);
73  /// glPolygonOffset()
74  /// glBlend*()
75  /// glColorMask()
76  /// glCullFace()
77  /// glDepthFunc()
78  /// glDepthMask()
79  /// glLineWidth()
80  /// glStencilFunc()
81  /// glStencilOp()
82  HDST_API
83  void Bind(HgiCapabilities const &hgiCapabilities);
84  HDST_API
85  void Unbind(HgiCapabilities const &hgiCapabilities);
86 
87  /// If set to true (default) and the render pass is rendering into a
88  /// multi-sampled aovs, the aovs will be resolved at the end of the render
89  /// pass. If false or the aov is not multi-sampled or the render pass is not
90  /// rendering into the multi-sampled aov, no resolution takes place.
91  HDST_API
93  HDST_API
94  bool GetResolveAovMultiSample() const;
95 
96  /// Set lighting shader
97  HDST_API
98  void SetLightingShader(HdStLightingShaderSharedPtr const &lightingShader);
100  return _lightingShader;
101  }
102 
103  /// renderpass shader
104  HDST_API
105  void SetRenderPassShader(HdStRenderPassShaderSharedPtr const &renderPassShader);
107  return _renderPassShader;
108  }
109 
110  HDST_API
112  HdSt_ResourceBinder const &binder,
113  HdSt_GeometricShaderSharedPtr const &geometricShader);
114 
115  HDST_API
116  void ApplyStateFromCamera();
117 
118  /// scene materials
119  HDST_API
120  void SetUseSceneMaterials(bool state);
121  bool GetUseSceneMaterials() const {
122  return _useSceneMaterials;
123  }
124 
125  /// returns shaders (lighting/renderpass)
126  HDST_API
128 
129  HDST_API
130  size_t GetShaderHash() const;
131 
132  /// Camera setter API
133  ///
134  /// Set matrices, viewport and clipping planes explicitly that are used
135  /// when there is no HdCamera in the render pass state.
136  ///
137  /// This is used by render pass that do not have an associated HdCamera
138  /// such as the shadow render pass.
139  HDST_API
140  void SetCameraFramingState(GfMatrix4d const &worldToViewMatrix,
141  GfMatrix4d const &projectionMatrix,
142  GfVec4d const &viewport,
143  ClipPlanesVector const & clipPlanes);
144 
145  GfMatrix4d GetCullMatrix() const { return _cullMatrix; }
146 
147  /// Overrides the case when no HdCamera is given. In the case, uses
148  /// matrix specified by SetCameraFramingState.
149  HDST_API
150  GfMatrix4d GetWorldToViewMatrix() const override;
151 
152  /// Overrides the case when no HdCamera is given. In the case, uses
153  /// matrix specified by SetCameraFramingState.
154  HDST_API
155  GfMatrix4d GetProjectionMatrix() const override;
156 
157  /// Overrides the case when no HdCamera is given. In the case, uses
158  /// clip planes specified by SetCameraFramingState.
159  HDST_API ClipPlanesVector const & GetClipPlanes() const override;
160 
161  /// Helper to compute and get the y-up Viewport
162  /// This is either using the modern camera framing, which is always y-down,
163  /// or the legacy viewport.
164  HDST_API
165  GfVec4i ComputeViewport() const;
166 
167  // Helper to get graphics cmds descriptor describing textures
168  // we render into and the blend state, constructed from
169  // AOV bindings.
170  //
171  HDST_API
173  HdRenderIndex const * renderIndex) const;
174 
175  // Helper to initialize graphics pipeline descriptor state including
176  // any additional state from the geometric shader.
177  HDST_API
179  HgiGraphicsPipelineDesc * pipeDesc,
180  HdSt_GeometricShaderSharedPtr const & geometricShader,
181  bool firstDrawBatch) const;
182 
183  /// Generates the hash for the settings used to init the graphics pipeline.
184  HDST_API
185  uint64_t GetGraphicsPipelineHash(
186  HdSt_GeometricShaderSharedPtr const & geometricShader,
187  bool firstDrawBatch) const;
188 
189  // A 4d-vector v encodes a 2d-transform as follows:
190  // (x, y) |-> (v[0] * x + v[2], v[1] * y + v[3]).
192 
193  // Computes the transform from pixel coordinates to the horizontally
194  // normalized filmback space which has the following properties:
195  // 1. x = -1 and +1 corresponds to the left and right edge of the filmback,
196  // respectively.
197  // 2. (0, 0) corresponds to the center of the filmback.
198  // 3. Moving a unit in either the x- or y-direction moves by the same
199  // distance on the filmback. In other words, y = -1/a and +1/a
200  // corresponds to the bottom and top edge of the filmback, respectively,
201  // where a is the camera's aspect ratio.
202  HDST_API
205 
206 private:
207  bool _UseAlphaMask() const;
208  unsigned int _GetFramebufferHeight() const;
209  GfRange2f _ComputeFlippedFilmbackWindow() const;
210 
211  // Helper to set up the aov attachment desc so that it matches the blend
212  // setting of the render pipeline state.
213  // If an aovIndex is specified then the color mask will be correlated.
214  void _InitAttachmentDesc(HgiAttachmentDesc &attachmentDesc,
215  HdRenderPassAovBinding const & binding,
216  HdRenderBuffer const * renderBuffer,
217  int aovIndex) const;
218 
219  void _InitPrimitiveState(
220  HgiGraphicsPipelineDesc * pipeDesc,
221  HdSt_GeometricShaderSharedPtr const & geometricShader) const;
222  void _InitAttachmentState(HgiGraphicsPipelineDesc * pipeDesc,
223  bool firstDrawBatch) const;
224  void _InitDepthStencilState(HgiDepthStencilState * depthState) const;
225  void _InitMultiSampleState(HgiMultiSampleState * multisampleState) const;
226  void _InitRasterizationState(
227  HgiRasterizationState * rasterizationState,
228  HdSt_GeometricShaderSharedPtr const & geometricShader) const;
229 
230  // ---------------------------------------------------------------------- //
231  // Camera state used when no HdCamera available
232  // ---------------------------------------------------------------------- //
233 
234  GfMatrix4d _worldToViewMatrix;
235  GfMatrix4d _projectionMatrix;
236  ClipPlanesVector _clipPlanes;
237 
238  GfMatrix4d _cullMatrix; // updated during Prepare(..)
239 
240  // ---------------------------------------------------------------------- //
241  // Shader Objects
242  // ---------------------------------------------------------------------- //
243  HdStRenderPassShaderSharedPtr _renderPassShader;
244  HdSt_FallbackLightingShaderSharedPtr _fallbackLightingShader;
245  HdStLightingShaderSharedPtr _lightingShader;
246 
247  HdBufferArrayRangeSharedPtr _renderPassStateBar;
248  size_t _clipPlanesBufferSize;
249  float _alphaThresholdCurrent;
250  bool _resolveMultiSampleAov;
251  bool _useSceneMaterials;
252 };
253 
255 
256 #endif // PXR_IMAGING_HD_ST_RENDER_PASS_STATE_H
Definition: vec4i.h:43
HDST_API ~HdStRenderPassState() override
HDST_API GfMatrix4d GetProjectionMatrix() const override
std::shared_ptr< class HdStShaderCode > HdStShaderCodeSharedPtr
HDST_API void SetUseSceneMaterials(bool state)
scene materials
HDST_API void SetLightingShader(HdStLightingShaderSharedPtr const &lightingShader)
Set lighting shader.
HDST_API void InitGraphicsPipelineDesc(HgiGraphicsPipelineDesc *pipeDesc, HdSt_GeometricShaderSharedPtr const &geometricShader, bool firstDrawBatch) const
std::shared_ptr< class HdResourceRegistry > HdResourceRegistrySharedPtr
std::shared_ptr< class HdStLightingShader > HdStLightingShaderSharedPtr
HDST_API void SetRenderPassShader(HdStRenderPassShaderSharedPtr const &renderPassShader)
renderpass shader
HDST_API size_t GetShaderHash() const
HDST_API void Unbind(HgiCapabilities const &hgiCapabilities)
std::shared_ptr< class HdSt_GeometricShader > HdSt_GeometricShaderSharedPtr
Definition: drawItem.h:19
Definition: vec4d.h:45
HdStLightingShaderSharedPtr const & GetLightingShader() const
std::shared_ptr< class HdSt_FallbackLightingShader > HdSt_FallbackLightingShaderSharedPtr
std::shared_ptr< class HdStRenderPassState > HdStRenderPassStateSharedPtr
Definition: commandBuffer.h:28
HDST_API void ApplyStateFromCamera()
HDST_API void Bind(HgiCapabilities const &hgiCapabilities)
HDST_API HgiGraphicsCmdsDesc MakeGraphicsCmdsDesc(HdRenderIndex const *renderIndex) const
std::vector< GfVec4d > ClipPlanesVector
Sets the camera.
GfMatrix4d GetCullMatrix() const
HDST_API ClipPlanesVector const & GetClipPlanes() const override
HDST_API void SetCameraFramingState(GfMatrix4d const &worldToViewMatrix, GfMatrix4d const &projectionMatrix, GfVec4d const &viewport, ClipPlanesVector const &clipPlanes)
HDST_API bool GetResolveAovMultiSample() const
std::shared_ptr< class HdStRenderPassShader > HdStRenderPassShaderSharedPtr
Definition: vec4f.h:45
HDST_API GfMatrix4d GetWorldToViewMatrix() const override
GLuint shader
Definition: glcorearb.h:785
HDST_API HdStRenderPassState()
HDST_API GfVec4i ComputeViewport() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
HDST_API void Prepare(HdResourceRegistrySharedPtr const &resourceRegistry) override
HDST_API void SetResolveAovMultiSample(bool state)
#define HDST_API
Definition: api.h:23
std::vector< HdStShaderCodeSharedPtr > HdStShaderCodeSharedPtrVector
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
std::shared_ptr< HdBufferArrayRange > HdBufferArrayRangeSharedPtr
Definition: bufferArray.h:27
HDST_API uint64_t GetGraphicsPipelineHash(HdSt_GeometricShaderSharedPtr const &geometricShader, bool firstDrawBatch) const
Generates the hash for the settings used to init the graphics pipeline.
HDST_API void ApplyStateFromGeometricShader(HdSt_ResourceBinder const &binder, HdSt_GeometricShaderSharedPtr const &geometricShader)
bool GetUseSceneMaterials() const
HDST_API AxisAlignedAffineTransform ComputeImageToHorizontallyNormalizedFilmback() const
HdStRenderPassShaderSharedPtr const & GetRenderPassShader() const
state
Definition: core.h:2289
HDST_API HdStShaderCodeSharedPtrVector GetShaders() const
returns shaders (lighting/renderpass)