Loading...
Searching...
No Matches
drawTargetTask.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HDX_DRAW_TARGET_TASK_H
8#define PXR_IMAGING_HDX_DRAW_TARGET_TASK_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hdx/api.h"
12#include "pxr/imaging/hdx/version.h"
13
14#include "pxr/imaging/hd/task.h"
15
16#include "pxr/base/gf/vec4f.h"
18
19PXR_NAMESPACE_OPEN_SCOPE
20
21class HdStDrawTarget;
23struct HdxDrawTargetTaskParams;
24using HdStRenderPassStateSharedPtr
25 = std::shared_ptr<class HdStRenderPassState>;
26using HdStSimpleLightingShaderSharedPtr
27 = std::shared_ptr<class HdStSimpleLightingShader>;
28TF_DECLARE_REF_PTRS(GlfSimpleLightingContext);
29
30// Not strictly necessary here.
31// But without it, would require users of the class to include it anyway
32
33class HdxDrawTargetTask : public HdTask
34{
35public:
36 using TaskParams = HdxDrawTargetTaskParams;
37
38 HDX_API
39 HdxDrawTargetTask(HdSceneDelegate* delegate, SdfPath const& id);
40
41 HDX_API
42 ~HdxDrawTargetTask() override;
43
45 HDX_API
46 void Sync(HdSceneDelegate* delegate,
47 HdTaskContext* ctx,
48 HdDirtyBits* dirtyBits) override;
49
51 HDX_API
52 void Prepare(HdTaskContext* ctx,
53 HdRenderIndex* renderIndex) override;
54
56 HDX_API
57 void Execute(HdTaskContext* ctx) override;
58
60 HDX_API
61 const TfTokenVector &GetRenderTags() const override;
62
63private:
64 struct _RenderPassInfo;
65 struct _CameraInfo;
66 using _RenderPassInfoVector = std::vector<_RenderPassInfo>;
67
68 static _RenderPassInfoVector _ComputeRenderPassInfos(
69 HdRenderIndex * renderIndex);
70
71 static _CameraInfo _ComputeCameraInfo(
72 const HdRenderIndex &renderIndex,
73 const HdStDrawTarget * drawTarget);
74 static void _UpdateLightingContext(
75 const _CameraInfo &cameraInfo,
76 GlfSimpleLightingContextConstRefPtr const &srcContext,
77 GlfSimpleLightingContextRefPtr const &ctx);
78 void _UpdateRenderPassState(
79 const HdRenderIndex &renderIndex,
80 const _CameraInfo &cameraInfo,
81 HdStSimpleLightingShaderSharedPtr const &lightingShader,
82 const HdStDrawTargetRenderPassState *srcState,
83 HdStRenderPassStateSharedPtr const &state) const;
84 static void _UpdateRenderPass(
85 _RenderPassInfo *info);
86
87 unsigned _currentDrawTargetSetVersion;
88 _RenderPassInfoVector _renderPassesInfo;
89
90 // Raster State - close match to render task
91 // but doesn't have enableHardwareShading
92 // as that has to be enabled for draw targets.
93// typedef std::vector<GfVec4d> ClipPlanesVector;
94// ClipPlanesVector _clipPlanes;
95 GfVec4f _overrideColor;
96 GfVec4f _wireframeColor;
97 bool _enableLighting;
98 float _alphaThreshold;
99
101 bool _depthBiasUseDefault;
102 bool _depthBiasEnable;
103 float _depthBiasConstantFactor;
104 float _depthBiasSlopeFactor;
105
106 HdCompareFunction _depthFunc;
107
108 // Viewer's Render Style
109 HdCullStyle _cullStyle;
110
111 // Alpha sample alpha to coverage
112 bool _enableSampleAlphaToCoverage;
113 TfTokenVector _renderTags;
114
115 HdxDrawTargetTask() = delete;
116 HdxDrawTargetTask(const HdxDrawTargetTask &) = delete;
117 HdxDrawTargetTask &operator =(const HdxDrawTargetTask &) = delete;
118};
119
120struct HdxDrawTargetTaskParams
121{
122 HdxDrawTargetTaskParams()
123 : overrideColor(0.0)
124 , wireframeColor(0.0)
125 , enableLighting(false)
126 , alphaThreshold(0.0)
127 , depthBiasUseDefault(true)
128 , depthBiasEnable(false)
129 , depthBiasConstantFactor(0.0f)
130 , depthBiasSlopeFactor(1.0f)
131 , depthFunc(HdCmpFuncLEqual)
132 // XXX: When rendering draw targets we need alpha to coverage
133 // at least until we support a transparency pass
134 , enableAlphaToCoverage(true)
135 , cullStyle(HdCullStyleBackUnlessDoubleSided)
136 {}
137
138// ClipPlanesVector clipPlanes;
139 GfVec4f overrideColor;
140 GfVec4f wireframeColor;
141 bool enableLighting;
142 float alphaThreshold;
143
144 // Depth Bias Raster State
145 // When use default is true - state
146 // is inherited and onther values are
147 // ignored. Otherwise the raster state
148 // is set using the values specified.
149
150 bool depthBiasUseDefault;
151 bool depthBiasEnable;
152 float depthBiasConstantFactor;
153 float depthBiasSlopeFactor;
154
155 HdCompareFunction depthFunc;
156
157 bool enableAlphaToCoverage;
158
159 // Viewer's Render Style
160 HdCullStyle cullStyle;
161};
162
163// VtValue requirements
164HDX_API
165std::ostream& operator<<(std::ostream& out, const HdxDrawTargetTaskParams& pv);
166HDX_API
167bool operator==(
168 const HdxDrawTargetTaskParams& lhs,
169 const HdxDrawTargetTaskParams& rhs);
170HDX_API
171bool operator!=(
172 const HdxDrawTargetTaskParams& lhs,
173 const HdxDrawTargetTaskParams& rhs);
174
175PXR_NAMESPACE_CLOSE_SCOPE
176
177#endif // PXR_IMAGING_HDX_DRAW_TARGET_TASK_H
Basic type for a vector of 4 float components.
Definition: vec4f.h:46
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:105
Adapter class providing data exchange with the client scene graph.
Represents an render to texture render pass.
Definition: drawTarget.h:47
Represents common non-gl context specific render pass state for a draw target.
HdTask represents a unit of work to perform during a Hydra render.
Definition: task.h:44
virtual void Execute(HdTaskContext *ctx)=0
Execute Phase: Runs the task.
virtual HD_API const TfTokenVector & GetRenderTags() const
Render Tag Gather.
virtual void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex)=0
Prepare Phase: Resolve bindings and manage resources.
virtual void Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits)=0
Sync Phase: Obtain task state from Scene delegate based on change processing.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Standard pointer typedefs.
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:58
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440