All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderSetupTask.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_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"
29 #include "pxr/imaging/hdx/version.h"
30 #include "pxr/imaging/hd/task.h"
31 #include "pxr/imaging/hd/tokens.h"
32 #include "pxr/imaging/hd/enums.h"
33 #include "pxr/imaging/hd/renderPassState.h"
34 
35 #include "pxr/base/gf/vec2f.h"
36 #include "pxr/base/gf/vec4f.h"
37 #include "pxr/base/gf/vec4d.h"
38 
39 #include <memory>
40 
41 PXR_NAMESPACE_OPEN_SCOPE
42 
43 
44 typedef boost::shared_ptr<class HdStRenderPassShader> HdStRenderPassShaderSharedPtr;
45 typedef boost::shared_ptr<class HdxRenderSetupTask> HdxRenderSetupTaskSharedPtr;
46 typedef boost::shared_ptr<class HdStShaderCode> HdStShaderCodeSharedPtr;
47 
48 using HdRenderPassStateSharedPtr = std::shared_ptr<class HdRenderPassState>;
49 
50 struct HdxRenderTaskParams;
52 
53 
65 class HdxRenderSetupTask : public HdTask {
66 public:
67  HDX_API
68  HdxRenderSetupTask(HdSceneDelegate* delegate, SdfPath const& id);
69 
70  HDX_API
71  virtual ~HdxRenderSetupTask();
72 
73 
74  // APIs used from HdxRenderTask to manage the sync/prepare process.
75  HDX_API
76  void SyncParams(HdSceneDelegate* delegate,
77  HdxRenderTaskParams const &params);
78  HDX_API
79  void PrepareCamera(HdRenderIndex* renderIndex);
80 
81  HdRenderPassStateSharedPtr const &GetRenderPassState() const {
82  return _renderPassState;
83  }
84 
86  HDX_API
87  virtual void Sync(HdSceneDelegate* delegate,
88  HdTaskContext* ctx,
89  HdDirtyBits* dirtyBits) override;
90 
92  HDX_API
93  virtual void Prepare(HdTaskContext* ctx,
94  HdRenderIndex* renderIndex) override;
95 
97  HDX_API
98  virtual void Execute(HdTaskContext* ctx) override;
99 
100 private:
101  HdRenderPassStateSharedPtr _renderPassState;
102  HdStRenderPassShaderSharedPtr _colorRenderPassShader;
103  HdStRenderPassShaderSharedPtr _idRenderPassShader;
104  GfVec4d _viewport;
105  SdfPath _cameraId;
106  HdRenderPassAovBindingVector _aovBindings;
107 
108  static HdStShaderCodeSharedPtr _overrideShader;
109 
110  static void _CreateOverrideShader();
111 
112  void _SetHdStRenderPassState(HdxRenderTaskParams const& params,
113  HdStRenderPassState *renderPassState);
114 
115  HdRenderPassStateSharedPtr &_GetRenderPassState(HdRenderIndex* renderIndex);
116 
117  void _PrepareAovBindings(HdTaskContext* ctx, HdRenderIndex* renderIndex);
118 
119 
120  HdxRenderSetupTask() = delete;
121  HdxRenderSetupTask(const HdxRenderSetupTask &) = delete;
122  HdxRenderSetupTask &operator =(const HdxRenderSetupTask &) = delete;
123 };
124 
130 {
132  : overrideColor(0.0)
133  , wireframeColor(0.0)
134  , maskColor(1.0f, 0.0f, 0.0f, 1.0f)
135  , indicatorColor(0.0f, 1.0f, 0.0f, 1.0f)
136  , pointColor(GfVec4f(0,0,0,1))
137  , pointSize(3.0)
138  , pointSelectedSize(3.0)
139  , enableLighting(false)
140  , enableIdRender(false)
141  , alphaThreshold(0.0)
142  , enableSceneMaterials(true)
143  , depthBiasUseDefault(true)
144  , depthBiasEnable(false)
145  , depthBiasConstantFactor(0.0f)
146  , depthBiasSlopeFactor(1.0f)
147  , depthFunc(HdCmpFuncLEqual)
148  , depthMaskEnable(true)
149  , stencilFunc(HdCmpFuncAlways)
150  , stencilRef(0)
151  , stencilMask(~0)
152  , stencilFailOp(HdStencilOpKeep)
153  , stencilZFailOp(HdStencilOpKeep)
154  , stencilZPassOp(HdStencilOpKeep)
155  , stencilEnable(false)
156  , blendColorOp(HdBlendOpAdd)
157  , blendColorSrcFactor(HdBlendFactorOne)
158  , blendColorDstFactor(HdBlendFactorZero)
159  , blendAlphaOp(HdBlendOpAdd)
160  , blendAlphaSrcFactor(HdBlendFactorOne)
161  , blendAlphaDstFactor(HdBlendFactorZero)
162  , blendConstantColor(0.0f, 0.0f, 0.0f, 0.0f)
163  , blendEnable(false)
164  , enableAlphaToCoverage(true)
165  , cullStyle(HdCullStyleBackUnlessDoubleSided)
166  , aovBindings()
167  , camera()
168  , viewport(0.0)
169  {}
170 
171  // XXX: Several of the params below should move to global application state.
172  GfVec4f overrideColor;
173  GfVec4f wireframeColor;
174  GfVec4f maskColor;
175  GfVec4f indicatorColor;
176  GfVec4f pointColor;
177  float pointSize;
178  float pointSelectedSize;
179  bool enableLighting;
180  bool enableIdRender;
181  float alphaThreshold;
182  bool enableSceneMaterials;
183 
184  // Depth Bias Raster State
185  // When use default is true - state
186  // is inherited and onther values are
187  // ignored. Otherwise the raster state
188  // is set using the values specified.
189  bool depthBiasUseDefault;
190  bool depthBiasEnable;
191  float depthBiasConstantFactor;
192  float depthBiasSlopeFactor;
193 
194  HdCompareFunction depthFunc;
195  bool depthMaskEnable;
196 
197  // Stencil
198  HdCompareFunction stencilFunc;
199  int stencilRef;
200  int stencilMask;
201  HdStencilOp stencilFailOp;
202  HdStencilOp stencilZFailOp;
203  HdStencilOp stencilZPassOp;
204  bool stencilEnable;
205 
206  // Blending
207  HdBlendOp blendColorOp;
208  HdBlendFactor blendColorSrcFactor;
209  HdBlendFactor blendColorDstFactor;
210  HdBlendOp blendAlphaOp;
211  HdBlendFactor blendAlphaSrcFactor;
212  HdBlendFactor blendAlphaDstFactor;
213  GfVec4f blendConstantColor;
214  bool blendEnable;
215 
216  // AlphaToCoverage
217  bool enableAlphaToCoverage;
218 
219  // Viewer's Render Style
220  HdCullStyle cullStyle;
221 
222  // AOV bindings.
223  // XXX: As a transitional API, if this is empty it indicates the renderer
224  // should write color and depth to the GL framebuffer.
225  HdRenderPassAovBindingVector aovBindings;
226 
227  // RasterState index objects
228  SdfPath camera;
229  GfVec4d viewport;
230 };
231 
232 // VtValue requirements
233 HDX_API
234 std::ostream& operator<<(std::ostream& out, const HdxRenderTaskParams& pv);
235 HDX_API
236 bool operator==(const HdxRenderTaskParams& lhs, const HdxRenderTaskParams& rhs);
237 HDX_API
238 bool operator!=(const HdxRenderTaskParams& lhs, const HdxRenderTaskParams& rhs);
239 
240 
241 PXR_NAMESPACE_CLOSE_SCOPE
242 
243 #endif //PXR_IMAGING_HDX_RENDER_SETUP_TASK_H
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:121
virtual HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the tasks resources.
AR_API bool operator!=(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
A set of rendering parameters used among render passes.
Basic type for a vector of 4 double components.
Definition: vec4d.h:63
AR_API bool operator==(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
RenderTask parameters (renderpass state).
Adapter class providing data exchange with the client scene graph.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
A task for setting up render pass state (camera, renderpass shader, GL states).
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
virtual HDX_API void Execute(HdTaskContext *ctx) override
Execute render pass task.
virtual HDX_API void Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.