All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderPassState.h
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef HD_RENDER_PASS_STATE_H
25 #define HD_RENDER_PASS_STATE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/aov.h"
30 #include "pxr/imaging/hd/version.h"
31 #include "pxr/imaging/hd/enums.h"
32 
33 #include "pxr/usd/sdf/path.h"
34 
35 #include "pxr/base/tf/token.h"
36 #include "pxr/base/vt/value.h"
37 #include "pxr/base/gf/matrix4d.h"
38 #include "pxr/base/gf/vec2f.h"
39 #include "pxr/base/gf/vec4d.h"
40 #include "pxr/base/gf/vec4f.h"
41 
42 #include <boost/shared_ptr.hpp>
43 
44 PXR_NAMESPACE_OPEN_SCOPE
45 
46 
47 typedef boost::shared_ptr<class HdRenderPassState> HdRenderPassStateSharedPtr;
48 typedef boost::shared_ptr<class HdResourceRegistry> HdResourceRegistrySharedPtr;
49 class HdCamera;
50 
58 public:
59  HD_API
61  HD_API
62  virtual ~HdRenderPassState();
63 
68  HD_API
69  virtual void Prepare(HdResourceRegistrySharedPtr const &resourceRegistry);
70 
71  // Bind, called once per frame before drawing.
72  HD_API
73  virtual void Bind();
74 
75  // Unbind, called once per frame after drawing.
76  HD_API
77  virtual void Unbind();
78 
79  // ---------------------------------------------------------------------- //
81  // ---------------------------------------------------------------------- //
82 
83  typedef std::vector<GfVec4d> ClipPlanesVector;
87  HD_API
88  void SetCameraFramingState(GfMatrix4d const &worldToViewMatrix,
89  GfMatrix4d const &projectionMatrix,
90  GfVec4d const &viewport,
91  ClipPlanesVector const & clipPlanes);
92 
95  HD_API
96  void SetCameraAndViewport(HdCamera const *camera,
97  GfVec4d const& viewport);
99  HD_API
100  GfMatrix4d const & GetWorldToViewMatrix() const;
101 
102  HD_API
103  GfMatrix4d GetProjectionMatrix() const;
104 
105  GfVec4f const & GetViewport() const { return _viewport; }
106 
107  HD_API
108  ClipPlanesVector const & GetClipPlanes() const;
109 
110  GfMatrix4d GetCullMatrix() const { return _cullMatrix; }
111 
112  HdCamera const *GetCamera() const { return _camera; }
113 
114  // ---------------------------------------------------------------------- //
116  // ---------------------------------------------------------------------- //
117 
120  HD_API
121  void SetOverrideColor(GfVec4f const &color);
122  const GfVec4f& GetOverrideColor() const { return _overrideColor; }
123 
126  HD_API
127  void SetWireframeColor(GfVec4f const &color);
128  const GfVec4f& GetWireframeColor() const { return _wireframeColor; }
129 
130  HD_API
131  void SetMaskColor(GfVec4f const &color);
132  const GfVec4f& GetMaskColor() const { return _maskColor; }
133 
134  HD_API
135  void SetIndicatorColor(GfVec4f const &color);
136  const GfVec4f& GetIndicatorColor() const { return _indicatorColor; }
137 
140  HD_API
141  void SetPointColor(GfVec4f const &color);
142  const GfVec4f& GetPointColor() const { return _pointColor; }
143 
145  HD_API
146  void SetPointSize(float size);
147  float GetPointSize() const { return _pointSize; }
148 
150  HD_API
151  void SetPointSelectedSize(float size);
152  float GetPointSelectedSize() const { return _pointSelectedSize; }
153 
155  HD_API
156  void SetLightingEnabled(bool enabled);
157  bool GetLightingEnabled() const { return _lightingEnabled; }
158 
159  // ---------------------------------------------------------------------- //
161  // ---------------------------------------------------------------------- //
162 
164  HD_API
165  void SetAovBindings(HdRenderPassAovBindingVector const &aovBindings);
166  HD_API
167  HdRenderPassAovBindingVector const& GetAovBindings() const;
168 
169  HD_API
170  void SetCullStyle(HdCullStyle cullStyle);
171  HD_API
172  HdCullStyle GetCullStyle() { return _cullStyle; }
173 
174  HD_API
175  void SetAlphaThreshold(float alphaThreshold);
176  float GetAlphaThreshold() const { return _alphaThreshold; }
177 
178  HD_API
179  void SetTessLevel(float level);
180  float GetTessLevel() const { return _tessLevel; }
181 
182  HD_API
183  void SetDrawingRange(GfVec2f const &drawRange);
184  GfVec2f GetDrawingRange() const { return _drawRange; } // in pixel
185  GfVec2f GetDrawingRangeNDC() const { // in ndc
186  return GfVec2f(2*_drawRange[0]/_viewport[2],
187  2*_drawRange[1]/_viewport[3]);
188  }
189 
190  HD_API
191  void SetDepthBiasUseDefault(bool useDefault);
192  bool GetDepthBiasUseDefault() const { return _depthBiasUseDefault; }
193 
194  HD_API
195  void SetDepthBiasEnabled(bool enabled);
196  bool GetDepthBiasEnabled() const { return _depthBiasEnabled; }
197 
198  HD_API
199  void SetDepthBias(float constantFactor, float slopeFactor);
200 
201  HD_API
202  void SetDepthFunc(HdCompareFunction depthFunc);
203  HdCompareFunction GetDepthFunc() const { return _depthFunc; }
204 
205  HD_API
206  void SetEnableDepthMask(bool state);
207 
208  HD_API
209  bool GetEnableDepthMask();
210 
211  HD_API
212  void SetStencil(HdCompareFunction func, int ref, int mask,
213  HdStencilOp fail, HdStencilOp zfail, HdStencilOp zpass);
214  HdCompareFunction GetStencilFunc() const { return _stencilFunc; }
215  int GetStencilRef() const { return _stencilRef; }
216  int GetStencilMask() const { return _stencilMask; }
217  HdStencilOp GetStencilFailOp() const { return _stencilFailOp; }
218  HdStencilOp GetStencilDepthFailOp() const { return _stencilZFailOp; }
219  HdStencilOp GetStencilDepthPassOp() const { return _stencilZPassOp; }
220  HD_API
221  void SetStencilEnabled(bool enabled);
222 
223  HD_API
224  void SetLineWidth(float width);
225  float GetLineWidth() const { return _lineWidth; }
226 
227  HD_API
228  void SetBlend(HdBlendOp colorOp,
229  HdBlendFactor colorSrcFactor,
230  HdBlendFactor colorDstFactor,
231  HdBlendOp alphaOp,
232  HdBlendFactor alphaSrcFactor,
233  HdBlendFactor alphaDstFactor);
234  HdBlendOp GetBlendColorOp() { return _blendColorOp; }
235  HdBlendFactor GetBlendColorSrcFactor() { return _blendColorSrcFactor; }
236  HdBlendFactor GetBlendColorDstFactor() { return _blendColorDstFactor; }
237  HdBlendOp GetBlendAlphaOp() { return _blendAlphaOp; }
238  HdBlendFactor GetBlendAlphaSrcFactor() { return _blendAlphaSrcFactor; }
239  HdBlendFactor GetBlendAlphaDstFactor() { return _blendAlphaDstFactor; }
240  HD_API
241  void SetBlendConstantColor(GfVec4f const & color);
242  const GfVec4f& GetBlendConstantColor() const { return _blendConstantColor; }
243  HD_API
244  void SetBlendEnabled(bool enabled);
245 
246  HD_API
247  void SetAlphaToCoverageUseDefault(bool useDefault);
248  bool GetAlphaToCoverageUseDefault() const { return _alphaToCoverageUseDefault; }
249 
250  HD_API
251  void SetAlphaToCoverageEnabled(bool enabled);
252  bool GetAlphaToCoverageEnabled() const { return _alphaToCoverageEnabled; }
253 
254  HD_API
255  void SetColorMaskUseDefault(bool useDefault);
256  bool GetColorMaskUseDefault() const { return _colorMaskUseDefault;}
257 
258  enum ColorMask {
259  ColorMaskNone,
260  ColorMaskRGB,
261  ColorMaskRGBA
262  };
263 
264  HD_API
265  void SetColorMask(ColorMask const& mask);
266  ColorMask GetColorMask() const { return _colorMask; }
267 
268 protected:
269  // ---------------------------------------------------------------------- //
270  // Camera and framing state
271  // ---------------------------------------------------------------------- //
272  HdCamera const *_camera;
273  GfVec4f _viewport;
274  // TODO: This is only used for CPU culling, should compute it on the fly.
275  GfMatrix4d _cullMatrix;
276 
277  GfMatrix4d _worldToViewMatrix;
278  GfMatrix4d _projectionMatrix;
279  ClipPlanesVector _clipPlanes;
280 
281  // ---------------------------------------------------------------------- //
282  // Application rendering state
283  // ---------------------------------------------------------------------- //
284  GfVec4f _overrideColor;
285  GfVec4f _wireframeColor;
286  GfVec4f _maskColor;
287  GfVec4f _indicatorColor;
288  GfVec4f _pointColor;
289  float _pointSize;
290  float _pointSelectedSize;
291  bool _lightingEnabled;
292 
293  // ---------------------------------------------------------------------- //
294  // Render pipeline state
295  // ---------------------------------------------------------------------- //
296  float _alphaThreshold;
297  float _tessLevel;
298  GfVec2f _drawRange;
299 
300  // Depth Bias RenderPassState
301  // When use default is true - state
302  // is inherited and onther values are
303  // ignored. Otherwise the raster state
304  // is set using the values specified.
305  bool _depthBiasUseDefault;
306  bool _depthBiasEnabled;
307  float _depthBiasConstantFactor;
308  float _depthBiasSlopeFactor;
309  HdCompareFunction _depthFunc;
310  bool _depthMaskEnabled;
311  HdCullStyle _cullStyle;
312 
313  // Stencil RenderPassState
314  HdCompareFunction _stencilFunc;
315  int _stencilRef;
316  int _stencilMask;
317  HdStencilOp _stencilFailOp;
318  HdStencilOp _stencilZFailOp;
319  HdStencilOp _stencilZPassOp;
320  bool _stencilEnabled;
321 
322  // Line width
323  float _lineWidth;
324 
325  // Blending
326  HdBlendOp _blendColorOp;
327  HdBlendFactor _blendColorSrcFactor;
328  HdBlendFactor _blendColorDstFactor;
329  HdBlendOp _blendAlphaOp;
330  HdBlendFactor _blendAlphaSrcFactor;
331  HdBlendFactor _blendAlphaDstFactor;
332  GfVec4f _blendConstantColor;
333  bool _blendEnabled;
334 
335  // alpha to coverage
336  bool _alphaToCoverageUseDefault;
337  bool _alphaToCoverageEnabled;
338 
339  bool _colorMaskUseDefault;
340  ColorMask _colorMask;
341 
342  HdRenderPassAovBindingVector _aovBindings;
343 };
344 
345 PXR_NAMESPACE_CLOSE_SCOPE
346 
347 #endif // HD_RENDER_PASS_STATE_H
HD_API void SetOverrideColor(GfVec4f const &color)
Set an override color for rendering where the R, G and B components are the color and the alpha compo...
HD_API void SetLightingEnabled(bool enabled)
XXX: Hacky way of disabling lighting.
HD_API void SetWireframeColor(GfVec4f const &color)
Set a wireframe color for rendering where the R, G and B components are the color and the alpha compo...
Hydra schema for a camera that pulls the basic params (see above) during Sync.
Definition: camera.h:80
Basic type for a vector of 4 double components.
Definition: vec4d.h:63
A set of rendering parameters used among render passes.
HD_API void SetPointSize(float size)
Set the point size for unselected points.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
HD_API void SetPointSelectedSize(float size)
Set the point size for selected points.
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
HD_API void SetAovBindings(HdRenderPassAovBindingVector const &aovBindings)
Set the attachments for this renderpass to render into.
HD_API void SetPointColor(GfVec4f const &color)
Set a point color for rendering where the R, G and B components are the color and the alpha component...
HD_API void SetCameraAndViewport(HdCamera const *camera, GfVec4d const &viewport)
Option 2: Set camera handle and viewport to use.
HD_API void SetCameraFramingState(GfMatrix4d const &worldToViewMatrix, GfMatrix4d const &projectionMatrix, GfVec4d const &viewport, ClipPlanesVector const &clipPlanes)
Camera setter API Option 1: Specify matrices, viewport and clipping planes (defined in camera space) ...
HD_API GfMatrix4d const & GetWorldToViewMatrix() const
Camera getter API.
virtual HD_API void Prepare(HdResourceRegistrySharedPtr const &resourceRegistry)
Schedule to update renderPassState parameters.