HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderSetupTask.h
Go to the documentation of this file.
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_HDX_RENDER_SETUP_TASK_H
25 #define PXR_IMAGING_HDX_RENDER_SETUP_TASK_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdx/api.h"
30 #include "pxr/imaging/hd/task.h"
31 #include "pxr/imaging/hd/tokens.h"
32 #include "pxr/imaging/hd/enums.h"
34 
36 
37 #include "pxr/base/gf/vec2f.h"
38 #include "pxr/base/gf/vec4f.h"
39 #include "pxr/base/gf/vec4d.h"
40 
41 #include <memory>
42 #include <optional>
43 
45 
47  std::shared_ptr<class HdxRenderSetupTask>;
49  std::shared_ptr<class HdStRenderPassShader>;
50 using HdStShaderCodeSharedPtr = std::shared_ptr<class HdStShaderCode>;
51 
52 using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
53 
54 struct HdxRenderTaskParams;
56 
57 
58 /// \class HdxRenderSetupTask
59 ///
60 /// A task for setting up render pass state (camera, renderpass shader, GL
61 /// states).
62 ///
63 /// HdxRenderTask depends on the output of this task. Applications can choose
64 /// to create a render setup task, and pass it the HdxRenderTaskParams; or they
65 /// can pass the HdxRenderTaskParams directly to the render task, which will
66 /// create a render setup task internally. See the HdxRenderTask documentation
67 /// for details.
68 ///
69 class HdxRenderSetupTask : public HdTask
70 {
71 public:
72  HDX_API
73  HdxRenderSetupTask(HdSceneDelegate* delegate, SdfPath const& id);
74 
75  HDX_API
76  ~HdxRenderSetupTask() override;
77 
78 
79  // APIs used from HdxRenderTask to manage the sync/prepare process.
80  HDX_API
81  void SyncParams(HdSceneDelegate* delegate,
83  HDX_API
84  void PrepareCamera(HdRenderIndex* renderIndex);
85 
87  return _renderPassState;
88  }
89 
90  /// Sync the render pass resources
91  HDX_API
92  void Sync(HdSceneDelegate* delegate,
93  HdTaskContext* ctx,
94  HdDirtyBits* dirtyBits) override;
95 
96  /// Prepare the tasks resources
97  HDX_API
98  void Prepare(HdTaskContext* ctx,
99  HdRenderIndex* renderIndex) override;
100 
101  /// Execute render pass task
102  HDX_API
103  void Execute(HdTaskContext* ctx) override;
104 
105 private:
106  HdRenderPassStateSharedPtr _renderPassState;
107  HdStRenderPassShaderSharedPtr _colorRenderPassShader;
108  HdStRenderPassShaderSharedPtr _idRenderPassShader;
109  SdfPath _cameraId;
110  CameraUtilFraming _framing;
111  std::optional<CameraUtilConformWindowPolicy> _overrideWindowPolicy;
112  // Used when client did not specify the camera framing (more expressive
113  // and preferred).
114  GfVec4d _viewport;
115  HdRenderPassAovBindingVector _aovBindings;
116  HdRenderPassAovBindingVector _aovInputBindings;
117 
118  void _SetRenderpassShadersForStorm(
119  HdxRenderTaskParams const& params,
120  HdStRenderPassState *renderPassState);
121 
122  HdRenderPassStateSharedPtr &_GetRenderPassState(HdRenderIndex* renderIndex);
123 
124  void _PrepareAovBindings(HdTaskContext* ctx, HdRenderIndex* renderIndex);
125 
126 
127  HdxRenderSetupTask() = delete;
128  HdxRenderSetupTask(const HdxRenderSetupTask &) = delete;
129  HdxRenderSetupTask &operator =(const HdxRenderSetupTask &) = delete;
130 };
131 
132 /// \class HdxRenderTaskParams
133 ///
134 /// RenderTask parameters (renderpass state).
135 ///
137 {
139  // Global Params
140  : overrideColor(0.0)
141  , wireframeColor(0.0)
142  , pointColor(GfVec4f(0,0,0,1))
143  , pointSize(3.0)
144  , enableLighting(false)
145  , enableIdRender(false)
146  , alphaThreshold(0.0)
147  , enableSceneMaterials(true)
148  , enableSceneLights(true)
149  , enableClipping(true)
150  // Selection/Masking params
151  , maskColor(1.0f, 0.0f, 0.0f, 1.0f)
152  , indicatorColor(0.0f, 1.0f, 0.0f, 1.0f)
153  , pointSelectedSize(3.0)
154  // Storm render pipeline state
155  , depthBiasUseDefault(true)
156  , depthBiasEnable(false)
158  , depthBiasSlopeFactor(1.0f)
160  , depthMaskEnable(true)
162  , stencilRef(0)
163  , stencilMask(~0)
167  , stencilEnable(false)
174  , blendConstantColor(0.0f, 0.0f, 0.0f, 0.0f)
175  , blendEnable(false)
176  , enableAlphaToCoverage(true)
177  , useAovMultiSample(true)
178  , resolveAovMultiSample(true)
179  // Camera framing and viewer state
180  , viewport(0.0)
182  {}
183 
184  // ---------------------------------------------------------------------- //
185  // Application rendering state
186  // XXX: Several of the parameters below are specific to (or work only with)
187  // Storm and stem from its integration in Presto and usdview.
188  // ---------------------------------------------------------------------- //
189  // "Global" parameters while rendering.
193  float pointSize;
200 
201  // Selection/Masking params
205 
206  // AOVs to render to
207  // XXX: As a transitional API, if this is empty it indicates the renderer
208  // should write color and depth to the GL framebuffer.
211 
212  // ---------------------------------------------------------------------- //
213  // Render pipeline state for rasterizers.
214  // XXX: These are relevant only for Storm.
215  // ---------------------------------------------------------------------- //
216  bool depthBiasUseDefault; // inherit application GL state
220 
223 
224  // Stencil
232 
233  // Blending
242 
243  // AlphaToCoverage
245 
246  // If true (default), render into the multi-sampled AOVs (rather than
247  // the resolved AOVs).
249 
250  // If true (default), multi-sampled AOVs will be resolved at the end of a
251  // render pass.
253 
254  // ---------------------------------------------------------------------- //
255  // Viewer & Camera Framing state
256  // ---------------------------------------------------------------------- //
259  // Only used if framing is invalid.
262  std::optional<CameraUtilConformWindowPolicy> overrideWindowPolicy;
263 };
264 
265 // VtValue requirements
266 HDX_API
267 std::ostream& operator<<(std::ostream& out, const HdxRenderTaskParams& pv);
268 HDX_API
269 bool operator==(const HdxRenderTaskParams& lhs, const HdxRenderTaskParams& rhs);
270 HDX_API
271 bool operator!=(const HdxRenderTaskParams& lhs, const HdxRenderTaskParams& rhs);
272 
273 
275 
276 #endif //PXR_IMAGING_HDX_RENDER_SETUP_TASK_H
HdBlendFactor blendAlphaDstFactor
HdStencilOp stencilZFailOp
std::shared_ptr< class HdRenderPassState > HdRenderPassStateSharedPtr
Definition: engine.h:42
HdCompareFunction
Definition: enums.h:36
std::shared_ptr< class HdStShaderCode > HdStShaderCodeSharedPtr
HdCullStyle
Definition: enums.h:122
HDX_API void Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.
HdBlendFactor blendAlphaSrcFactor
uint32_t HdDirtyBits
Definition: types.h:158
HdRenderPassAovBindingVector aovInputBindings
HdCompareFunction stencilFunc
HdStencilOp stencilFailOp
Definition: vec4d.h:62
HdBlendFactor
Definition: enums.h:87
#define HDX_API
Definition: api.h:40
GLenum const GLfloat * params
Definition: glcorearb.h:105
HDX_API void Execute(HdTaskContext *ctx) override
Execute render pass task.
HdStencilOp stencilZPassOp
GLfloat f
Definition: glcorearb.h:1926
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
CameraUtilFraming framing
Definition: task.h:54
Definition: path.h:290
HdStencilOp
Definition: enums.h:54
HDX_API void SyncParams(HdSceneDelegate *delegate, HdxRenderTaskParams const &params)
std::unordered_map< TfToken, VtValue, TfToken::HashFunctor > HdTaskContext
Definition: renderIndex.h:77
std::shared_ptr< class HdStRenderPassShader > HdStRenderPassShaderSharedPtr
Definition: vec4f.h:62
std::optional< CameraUtilConformWindowPolicy > overrideWindowPolicy
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
HdRenderPassStateSharedPtr const & GetRenderPassState() const
std::shared_ptr< class HdxRenderSetupTask > HdxRenderSetupTaskSharedPtr
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HDX_API std::ostream & operator<<(std::ostream &out, const HdxRenderTaskParams &pv)
HdBlendFactor blendColorSrcFactor
HDX_API void PrepareCamera(HdRenderIndex *renderIndex)
HdRenderPassAovBindingVector aovBindings
HdBlendOp
Definition: enums.h:72
std::vector< HdRenderPassAovBinding > HdRenderPassAovBindingVector
Definition: aov.h:154
HdCompareFunction depthFunc
HdBlendFactor blendColorDstFactor
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the tasks resources.
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
HDX_API ~HdxRenderSetupTask() override