drawTargetTask.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_DRAW_TARGET_TASK_H
25 #define PXR_IMAGING_HDX_DRAW_TARGET_TASK_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdx/api.h"
29 #include "pxr/imaging/hdx/version.h"
30 
31 #include "pxr/imaging/hd/task.h"
32 
33 #include "pxr/base/gf/vec4f.h"
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
38 class HdStDrawTarget;
40 using HdStRenderPassStateSharedPtr
41  = std::shared_ptr<class HdStRenderPassState>;
42 using HdStSimpleLightingShaderSharedPtr
43  = std::shared_ptr<class HdStSimpleLightingShader>;
44 TF_DECLARE_REF_PTRS(GlfSimpleLightingContext);
45 
46 // Not strictly necessary here.
47 // But without it, would require users of the class to include it anyway
48 
49 class HdxDrawTargetTask : public HdTask
50 {
51 public:
52  HDX_API
53  HdxDrawTargetTask(HdSceneDelegate* delegate, SdfPath const& id);
54 
55  HDX_API
56  ~HdxDrawTargetTask() override;
57 
59  HDX_API
60  void Sync(HdSceneDelegate* delegate,
61  HdTaskContext* ctx,
62  HdDirtyBits* dirtyBits) override;
63 
65  HDX_API
66  void Prepare(HdTaskContext* ctx,
67  HdRenderIndex* renderIndex) override;
68 
70  HDX_API
71  void Execute(HdTaskContext* ctx) override;
72 
74  HDX_API
75  const TfTokenVector &GetRenderTags() const override;
76 
77 private:
78  struct _RenderPassInfo;
79  struct _CameraInfo;
80  using _RenderPassInfoVector = std::vector<_RenderPassInfo>;
81 
82  static _RenderPassInfoVector _ComputeRenderPassInfos(
83  HdRenderIndex * renderIndex);
84 
85  static _CameraInfo _ComputeCameraInfo(
86  const HdRenderIndex &renderIndex,
87  const HdStDrawTarget * drawTarget);
88  static void _UpdateLightingContext(
89  const _CameraInfo &cameraInfo,
90  GlfSimpleLightingContextConstRefPtr const &srcContext,
91  GlfSimpleLightingContextRefPtr const &ctx);
92  void _UpdateRenderPassState(
93  const HdRenderIndex &renderIndex,
94  const _CameraInfo &cameraInfo,
95  HdStSimpleLightingShaderSharedPtr const &lightingShader,
96  const HdStDrawTargetRenderPassState *srcState,
97  HdStRenderPassStateSharedPtr const &state) const;
98  static void _UpdateRenderPass(
99  _RenderPassInfo *info);
100 
101  unsigned _currentDrawTargetSetVersion;
102  _RenderPassInfoVector _renderPassesInfo;
103 
104  // Raster State - close match to render task
105  // but doesn't have enableHardwareShading
106  // as that has to be enabled for draw targets.
107 // typedef std::vector<GfVec4d> ClipPlanesVector;
108 // ClipPlanesVector _clipPlanes;
109  GfVec4f _overrideColor;
110  GfVec4f _wireframeColor;
111  bool _enableLighting;
112  float _alphaThreshold;
113 
115  bool _depthBiasUseDefault;
116  bool _depthBiasEnable;
117  float _depthBiasConstantFactor;
118  float _depthBiasSlopeFactor;
119 
120  HdCompareFunction _depthFunc;
121 
122  // Viewer's Render Style
123  HdCullStyle _cullStyle;
124 
125  // Alpha sample alpha to coverage
126  bool _enableSampleAlphaToCoverage;
127  TfTokenVector _renderTags;
128 
129  HdxDrawTargetTask() = delete;
130  HdxDrawTargetTask(const HdxDrawTargetTask &) = delete;
131  HdxDrawTargetTask &operator =(const HdxDrawTargetTask &) = delete;
132 };
133 
134 struct HdxDrawTargetTaskParams
135 {
136  HdxDrawTargetTaskParams()
137  : overrideColor(0.0)
138  , wireframeColor(0.0)
139  , enableLighting(false)
140  , alphaThreshold(0.0)
141  , depthBiasUseDefault(true)
142  , depthBiasEnable(false)
143  , depthBiasConstantFactor(0.0f)
144  , depthBiasSlopeFactor(1.0f)
145  , depthFunc(HdCmpFuncLEqual)
146  // XXX: When rendering draw targets we need alpha to coverage
147  // at least until we support a transparency pass
148  , enableAlphaToCoverage(true)
149  , cullStyle(HdCullStyleBackUnlessDoubleSided)
150  {}
151 
152 // ClipPlanesVector clipPlanes;
153  GfVec4f overrideColor;
154  GfVec4f wireframeColor;
155  bool enableLighting;
156  float alphaThreshold;
157 
158  // Depth Bias Raster State
159  // When use default is true - state
160  // is inherited and onther values are
161  // ignored. Otherwise the raster state
162  // is set using the values specified.
163 
164  bool depthBiasUseDefault;
165  bool depthBiasEnable;
166  float depthBiasConstantFactor;
167  float depthBiasSlopeFactor;
168 
169  HdCompareFunction depthFunc;
170 
171  bool enableAlphaToCoverage;
172 
173  // Viewer's Render Style
174  HdCullStyle cullStyle;
175 };
176 
177 // VtValue requirements
178 HDX_API
179 std::ostream& operator<<(std::ostream& out, const HdxDrawTargetTaskParams& pv);
180 HDX_API
181 bool operator==(
182  const HdxDrawTargetTaskParams& lhs,
183  const HdxDrawTargetTaskParams& rhs);
184 HDX_API
185 bool operator!=(
186  const HdxDrawTargetTaskParams& lhs,
187  const HdxDrawTargetTaskParams& rhs);
188 
189 PXR_NAMESPACE_CLOSE_SCOPE
190 
191 #endif // PXR_IMAGING_HDX_DRAW_TARGET_TASK_H
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:120
Standard pointer typedefs.
AR_API bool operator!=(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
AR_API bool operator==(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
Adapter class providing data exchange with the client scene graph.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
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].
Represents an render to texture render pass.
Definition: drawTarget.h:63
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
Represents common non-gl context specific render pass state for a draw target.