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  /// returns shaders (lighting/renderpass)
119  HDST_API
121 
122  HDST_API
123  size_t GetShaderHash() const;
124 
125  /// Camera setter API
126  ///
127  /// Set matrices, viewport and clipping planes explicitly that are used
128  /// when there is no HdCamera in the render pass state.
129  ///
130  /// This is used by render pass that do not have an associated HdCamera
131  /// such as the shadow render pass.
132  HDST_API
133  void SetCameraFramingState(GfMatrix4d const &worldToViewMatrix,
134  GfMatrix4d const &projectionMatrix,
135  GfVec4d const &viewport,
136  ClipPlanesVector const & clipPlanes);
137 
138  GfMatrix4d GetCullMatrix() const { return _cullMatrix; }
139 
140  /// Overrides the case when no HdCamera is given. In the case, uses
141  /// matrix specified by SetCameraFramingState.
142  HDST_API
143  GfMatrix4d GetWorldToViewMatrix() const override;
144 
145  /// Overrides the case when no HdCamera is given. In the case, uses
146  /// matrix specified by SetCameraFramingState.
147  HDST_API
148  GfMatrix4d GetProjectionMatrix() const override;
149 
150  /// Overrides the case when no HdCamera is given. In the case, uses
151  /// clip planes specified by SetCameraFramingState.
152  HDST_API ClipPlanesVector const & GetClipPlanes() const override;
153 
154  /// Helper to compute and get the y-up Viewport
155  /// This is either using the modern camera framing, which is always y-down,
156  /// or the legacy viewport.
157  HDST_API
158  GfVec4i ComputeViewport() const;
159 
160  // Helper to get graphics cmds descriptor describing textures
161  // we render into and the blend state, constructed from
162  // AOV bindings.
163  //
164  HDST_API
166  HdRenderIndex const * renderIndex) const;
167 
168  // Helper to initialize graphics pipeline descriptor state including
169  // any additional state from the geometric shader.
170  HDST_API
172  HgiGraphicsPipelineDesc * pipeDesc,
173  HdSt_GeometricShaderSharedPtr const & geometricShader,
174  bool firstDrawBatch) const;
175 
176  /// Generates the hash for the settings used to init the graphics pipeline.
177  HDST_API
178  uint64_t GetGraphicsPipelineHash(
179  HdSt_GeometricShaderSharedPtr const & geometricShader,
180  bool firstDrawBatch) const;
181 
182  // A 4d-vector v encodes a 2d-transform as follows:
183  // (x, y) |-> (v[0] * x + v[2], v[1] * y + v[3]).
185 
186  // Computes the transform from pixel coordinates to the horizontally
187  // normalized filmback space which has the following properties:
188  // 1. x = -1 and +1 corresponds to the left and right edge of the filmback,
189  // respectively.
190  // 2. (0, 0) corresponds to the center of the filmback.
191  // 3. Moving a unit in either the x- or y-direction moves by the same
192  // distance on the filmback. In other words, y = -1/a and +1/a
193  // corresponds to the bottom and top edge of the filmback, respectively,
194  // where a is the camera's aspect ratio.
195  HDST_API
198 
199 private:
200  bool _UseAlphaMask() const;
201  unsigned int _GetFramebufferHeight() const;
202  GfRange2f _ComputeFlippedFilmbackWindow() const;
203 
204  // Helper to set up the aov attachment desc so that it matches the blend
205  // setting of the render pipeline state.
206  // If an aovIndex is specified then the color mask will be correlated.
207  void _InitAttachmentDesc(HgiAttachmentDesc &attachmentDesc,
208  HdRenderPassAovBinding const & binding,
209  HdRenderBuffer const * renderBuffer,
210  int aovIndex) const;
211 
212  void _InitPrimitiveState(
213  HgiGraphicsPipelineDesc * pipeDesc,
214  HdSt_GeometricShaderSharedPtr const & geometricShader) const;
215  void _InitAttachmentState(HgiGraphicsPipelineDesc * pipeDesc,
216  bool firstDrawBatch) const;
217  void _InitDepthStencilState(HgiDepthStencilState * depthState) const;
218  void _InitMultiSampleState(HgiMultiSampleState * multisampleState) const;
219  void _InitRasterizationState(
220  HgiRasterizationState * rasterizationState,
221  HdSt_GeometricShaderSharedPtr const & geometricShader) const;
222 
223  // ---------------------------------------------------------------------- //
224  // Camera state used when no HdCamera available
225  // ---------------------------------------------------------------------- //
226 
227  GfMatrix4d _worldToViewMatrix;
228  GfMatrix4d _projectionMatrix;
229  ClipPlanesVector _clipPlanes;
230 
231  GfMatrix4d _cullMatrix; // updated during Prepare(..)
232 
233  // ---------------------------------------------------------------------- //
234  // Shader Objects
235  // ---------------------------------------------------------------------- //
236  HdStRenderPassShaderSharedPtr _renderPassShader;
237  HdSt_FallbackLightingShaderSharedPtr _fallbackLightingShader;
238  HdStLightingShaderSharedPtr _lightingShader;
239 
240  HdBufferArrayRangeSharedPtr _renderPassStateBar;
241  size_t _clipPlanesBufferSize;
242  float _alphaThresholdCurrent;
243  bool _resolveMultiSampleAov;
244 };
245 
247 
248 #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 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
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
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
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)
HDST_API AxisAlignedAffineTransform ComputeImageToHorizontallyNormalizedFilmback() const
HdStRenderPassShaderSharedPtr const & GetRenderPassShader() const
state
Definition: core.h:2289
HDST_API HdStShaderCodeSharedPtrVector GetShaders() const
returns shaders (lighting/renderpass)