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 PXR_IMAGING_HD_RENDER_PASS_STATE_H
25 #define PXR_IMAGING_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/imaging/cameraUtil/framing.h"
34 
35 #include "pxr/usd/sdf/path.h"
36 
37 #include "pxr/base/tf/token.h"
38 #include "pxr/base/vt/value.h"
39 #include "pxr/base/gf/matrix4d.h"
40 #include "pxr/base/gf/vec2f.h"
41 #include "pxr/base/gf/vec4d.h"
42 #include "pxr/base/gf/vec4f.h"
43 
44 #include <memory>
45 
46 PXR_NAMESPACE_OPEN_SCOPE
47 
48 
49 using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
50 using HdResourceRegistrySharedPtr = std::shared_ptr<class HdResourceRegistry>;
51 
52 class HdCamera;
53 
61 {
62 public:
63  HD_API
65  HD_API
66  virtual ~HdRenderPassState();
67 
72  HD_API
73  virtual void Prepare(HdResourceRegistrySharedPtr const &resourceRegistry);
74 
75  // ---------------------------------------------------------------------- //
77  // ---------------------------------------------------------------------- //
78 
79  using ClipPlanesVector = std::vector<GfVec4d>;
80 
90  HD_API
92  HdCamera const *camera,
93  CameraUtilFraming const &framing,
94  const std::pair<bool, CameraUtilConformWindowPolicy> &
95  overrideWindowPolicy);
96 
98  HdCamera const *
99  GetCamera() const { return _camera; }
100 
103  const CameraUtilFraming &
104  GetFraming() const { return _framing; }
105 
108  const std::pair<bool, CameraUtilConformWindowPolicy> &
109  GetOverrideWindowPolicy() const { return _overrideWindowPolicy; }
110 
114  HD_API
115  CameraUtilConformWindowPolicy
116  GetWindowPolicy() const;
117 
122  HD_API
123  void SetCameraAndViewport(HdCamera const *camera,
124  GfVec4d const& viewport);
134  HD_API
136 
149  HD_API
151 
155  GfVec4f const & GetViewport() const { return _viewport; }
156 
157  HD_API
158  ClipPlanesVector const & GetClipPlanes() const;
159 
160  GfMatrix4d GetCullMatrix() const { return _cullMatrix; }
161 
162  // ---------------------------------------------------------------------- //
164  // ---------------------------------------------------------------------- //
165 
168  HD_API
169  void SetOverrideColor(GfVec4f const &color);
170  const GfVec4f& GetOverrideColor() const { return _overrideColor; }
171 
174  HD_API
175  void SetWireframeColor(GfVec4f const &color);
176  const GfVec4f& GetWireframeColor() const { return _wireframeColor; }
177 
178  HD_API
179  void SetMaskColor(GfVec4f const &color);
180  const GfVec4f& GetMaskColor() const { return _maskColor; }
181 
182  HD_API
183  void SetIndicatorColor(GfVec4f const &color);
184  const GfVec4f& GetIndicatorColor() const { return _indicatorColor; }
185 
188  HD_API
189  void SetPointColor(GfVec4f const &color);
190  const GfVec4f& GetPointColor() const { return _pointColor; }
191 
193  HD_API
194  void SetPointSize(float size);
195  float GetPointSize() const { return _pointSize; }
196 
198  HD_API
199  void SetPointSelectedSize(float size);
200  float GetPointSelectedSize() const { return _pointSelectedSize; }
201 
203  HD_API
204  void SetLightingEnabled(bool enabled);
205  bool GetLightingEnabled() const { return _lightingEnabled; }
206 
207  HD_API
208  void SetClippingEnabled(bool enabled);
209  bool GetClippingEnabled() const { return _clippingEnabled; }
210 
211  // ---------------------------------------------------------------------- //
213  // ---------------------------------------------------------------------- //
214 
216  HD_API
217  void SetAovBindings(HdRenderPassAovBindingVector const &aovBindings);
218  HD_API
219  HdRenderPassAovBindingVector const& GetAovBindings() const;
220 
222  HD_API
223  void SetAovInputBindings(HdRenderPassAovBindingVector const &aovBindings);
224  HD_API
225  HdRenderPassAovBindingVector const& GetAovInputBindings() const;
226 
229  HD_API
230  void SetUseAovMultiSample(bool state);
231  HD_API
232  bool GetUseAovMultiSample() const;
233 
234  HD_API
235  void SetCullStyle(HdCullStyle cullStyle);
236  HD_API
237  HdCullStyle GetCullStyle() const { return _cullStyle; }
238 
239  HD_API
240  void SetAlphaThreshold(float alphaThreshold);
241  float GetAlphaThreshold() const { return _alphaThreshold; }
242 
243  HD_API
244  void SetTessLevel(float level);
245  float GetTessLevel() const { return _tessLevel; }
246 
247  HD_API
248  void SetDrawingRange(GfVec2f const &drawRange);
249  GfVec2f GetDrawingRange() const { return _drawRange; } // in pixel
250  GfVec2f GetDrawingRangeNDC() const { // in ndc
251  return GfVec2f(2*_drawRange[0]/_viewport[2],
252  2*_drawRange[1]/_viewport[3]);
253  }
254 
255  HD_API
256  void SetDepthBiasUseDefault(bool useDefault);
257  bool GetDepthBiasUseDefault() const { return _depthBiasUseDefault; }
258 
259  HD_API
260  void SetDepthBiasEnabled(bool enabled);
261  bool GetDepthBiasEnabled() const { return _depthBiasEnabled; }
262 
263  HD_API
264  void SetDepthBias(float constantFactor, float slopeFactor);
265 
266  HD_API
267  void SetDepthFunc(HdCompareFunction depthFunc);
268  HdCompareFunction GetDepthFunc() const { return _depthFunc; }
269 
270  HD_API
271  void SetEnableDepthMask(bool state);
272  HD_API
273  bool GetEnableDepthMask();
274 
275  HD_API
276  void SetEnableDepthTest(bool enabled);
277  HD_API
278  bool GetEnableDepthTest() const;
279 
280  HD_API
281  void SetStencil(HdCompareFunction func, int ref, int mask,
282  HdStencilOp fail, HdStencilOp zfail, HdStencilOp zpass);
283  HdCompareFunction GetStencilFunc() const { return _stencilFunc; }
284  int GetStencilRef() const { return _stencilRef; }
285  int GetStencilMask() const { return _stencilMask; }
286  HdStencilOp GetStencilFailOp() const { return _stencilFailOp; }
287  HdStencilOp GetStencilDepthFailOp() const { return _stencilZFailOp; }
288  HdStencilOp GetStencilDepthPassOp() const { return _stencilZPassOp; }
289  HD_API
290  void SetStencilEnabled(bool enabled);
291  HD_API
292  bool GetStencilEnabled() const;
293 
294  HD_API
295  void SetLineWidth(float width);
296  float GetLineWidth() const { return _lineWidth; }
297 
298  HD_API
299  void SetBlend(HdBlendOp colorOp,
300  HdBlendFactor colorSrcFactor,
301  HdBlendFactor colorDstFactor,
302  HdBlendOp alphaOp,
303  HdBlendFactor alphaSrcFactor,
304  HdBlendFactor alphaDstFactor);
305  HdBlendOp GetBlendColorOp() { return _blendColorOp; }
306  HdBlendFactor GetBlendColorSrcFactor() { return _blendColorSrcFactor; }
307  HdBlendFactor GetBlendColorDstFactor() { return _blendColorDstFactor; }
308  HdBlendOp GetBlendAlphaOp() { return _blendAlphaOp; }
309  HdBlendFactor GetBlendAlphaSrcFactor() { return _blendAlphaSrcFactor; }
310  HdBlendFactor GetBlendAlphaDstFactor() { return _blendAlphaDstFactor; }
311  HD_API
312  void SetBlendConstantColor(GfVec4f const & color);
313  const GfVec4f& GetBlendConstantColor() const { return _blendConstantColor; }
314  HD_API
315  void SetBlendEnabled(bool enabled);
316 
317  HD_API
318  void SetAlphaToCoverageEnabled(bool enabled);
319  bool GetAlphaToCoverageEnabled() const { return _alphaToCoverageEnabled; }
320 
321  HD_API
322  void SetColorMaskUseDefault(bool useDefault);
323  bool GetColorMaskUseDefault() const { return _colorMaskUseDefault;}
324 
325  enum ColorMask {
326  ColorMaskNone,
327  ColorMaskRGB,
328  ColorMaskRGBA
329  };
330 
331  HD_API
332  void SetColorMasks(std::vector<ColorMask> const& masks);
333  std::vector<ColorMask> const& GetColorMasks() const { return _colorMasks; }
334 
335 protected:
336  // ---------------------------------------------------------------------- //
337  // Camera and framing state
338  // ---------------------------------------------------------------------- //
339  HdCamera const *_camera;
340  GfVec4f _viewport;
341  CameraUtilFraming _framing;
342  std::pair<bool, CameraUtilConformWindowPolicy> _overrideWindowPolicy;
343  GfMatrix4d _cullMatrix; // updated during Prepare(..)
344 
345  // Used by applications setting the view matrix directly instead of
346  // using an HdCamera. Will be removed eventually.
347  GfMatrix4d _worldToViewMatrix;
348  // Used by applications setting the projection matrix directly instead
349  // of using an HdCamera. Will be removed eventually.
350  GfMatrix4d _projectionMatrix;
351  // Used by applications setting the clip planes directly instead
352  // of using an HdCamera. Will be removed eventually.
353  ClipPlanesVector _clipPlanes;
354 
355  // ---------------------------------------------------------------------- //
356  // Application rendering state
357  // ---------------------------------------------------------------------- //
358  GfVec4f _overrideColor;
359  GfVec4f _wireframeColor;
360  GfVec4f _pointColor;
361  float _pointSize;
362  bool _lightingEnabled;
363  bool _clippingEnabled;
364 
365  GfVec4f _maskColor;
366  GfVec4f _indicatorColor;
367  float _pointSelectedSize;
368 
369  // ---------------------------------------------------------------------- //
370  // Render pipeline state
371  // ---------------------------------------------------------------------- //
372  float _alphaThreshold;
373  float _tessLevel;
374  GfVec2f _drawRange;
375 
376  bool _depthBiasUseDefault; // inherit existing state, ignore values below.
377  bool _depthBiasEnabled;
378  float _depthBiasConstantFactor;
379  float _depthBiasSlopeFactor;
380  HdCompareFunction _depthFunc;
381  bool _depthMaskEnabled;
382  bool _depthTestEnabled;
383 
384  HdCullStyle _cullStyle;
385 
386  // Stencil RenderPassState
387  HdCompareFunction _stencilFunc;
388  int _stencilRef;
389  int _stencilMask;
390  HdStencilOp _stencilFailOp;
391  HdStencilOp _stencilZFailOp;
392  HdStencilOp _stencilZPassOp;
393  bool _stencilEnabled;
394 
395  // Line width
396  float _lineWidth;
397 
398  // Blending
399  HdBlendOp _blendColorOp;
400  HdBlendFactor _blendColorSrcFactor;
401  HdBlendFactor _blendColorDstFactor;
402  HdBlendOp _blendAlphaOp;
403  HdBlendFactor _blendAlphaSrcFactor;
404  HdBlendFactor _blendAlphaDstFactor;
405  GfVec4f _blendConstantColor;
406  bool _blendEnabled;
407 
408  // alpha to coverage
409  bool _alphaToCoverageEnabled;
410 
411  bool _colorMaskUseDefault;
412  std::vector<ColorMask> _colorMasks;
413 
414  HdRenderPassAovBindingVector _aovBindings;
415  HdRenderPassAovBindingVector _aovInputBindings;
416  bool _useMultiSampleAov;
417 };
418 
419 PXR_NAMESPACE_CLOSE_SCOPE
420 
421 #endif // PXR_IMAGING_HD_RENDER_PASS_STATE_H
HD_API void SetUseAovMultiSample(bool state)
Returns true if the render pass wants to render into the multi-sample aovs.
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...
const std::pair< bool, CameraUtilConformWindowPolicy > & GetOverrideWindowPolicy() const
The override value for the window policy to conform the camera frustum that can be specified by the a...
HD_API void SetLightingEnabled(bool enabled)
XXX: Hacky way of disabling lighting.
HD_API void SetCameraAndFraming(HdCamera const *camera, CameraUtilFraming const &framing, const std::pair< bool, CameraUtilConformWindowPolicy > &overrideWindowPolicy)
Camera setter API.
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 params (see above) during Sync.
Definition: camera.h:85
Basic type for a vector of 4 double components.
Definition: vec4d.h:63
HD_API GfMatrix4d GetWorldToViewMatrix() const
Camera getter API.
A set of rendering parameters used among render passes.
HD_API void SetPointSize(float size)
Set the point size for unselected points.
HdCamera const * GetCamera() const
Get camera.
HD_API GfMatrix4d GetProjectionMatrix() const
It is expected that an HdCamera was specified that has physically based attributes.
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
GfVec4f const & GetViewport() const
Only use when clients did not specify a camera framing.
HD_API void SetAovInputBindings(HdRenderPassAovBindingVector const &aovBindings)
Set the AOVs that this renderpass needs to read from.
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)
Camera setter API The view, projection and clipping plane info of the camera will be used...
const CameraUtilFraming & GetFraming() const
Get framing information determining how the filmback plane maps to pixels.
HD_API CameraUtilConformWindowPolicy GetWindowPolicy() const
The resolved window policy to conform the camera frustum.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
virtual HD_API void Prepare(HdResourceRegistrySharedPtr const &resourceRegistry)
Schedule to update renderPassState parameters.
Framing information.
Definition: framing.h:79