All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
drawTarget.h
1 //
2 // Copyright 2017 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_ST_DRAW_TARGET_H
25 #define PXR_IMAGING_HD_ST_DRAW_TARGET_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hdSt/drawTargetRenderPassState.h"
30 #include "pxr/imaging/hdSt/textureResourceHandle.h"
31 #include "pxr/imaging/hd/enums.h"
32 #include "pxr/imaging/hd/rprimCollection.h"
33 #include "pxr/imaging/hd/sprim.h"
34 #include "pxr/imaging/hgi/texture.h"
35 #include "pxr/imaging/glf/drawTarget.h"
36 
37 #include "pxr/usd/sdf/path.h"
38 #include "pxr/base/tf/staticTokens.h"
39 
40 #include <memory>
41 #include <vector>
42 
43 PXR_NAMESPACE_OPEN_SCOPE
44 
45 
46 #define HDST_DRAW_TARGET_TOKENS \
47  (attachments) \
48  (camera) \
49  (collection) \
50  (depthClearValue) \
51  (drawTargetSet) \
52  (enable) \
53  (resolution) \
54  (aovBindings) \
55  (depth) \
56  (depthPriority)
57 
58 TF_DECLARE_PUBLIC_TOKENS(HdStDrawTargetTokens, HDST_API, HDST_DRAW_TARGET_TOKENS);
59 
60 class HdCamera;
62 
63 using GlfGLContextSharedPtr = std::shared_ptr<class GlfGLContext>;
64 
65 using HdStDrawTargetPtrVector = std::vector<class HdStDrawTarget *>;
66 
74 class HdStDrawTarget : public HdSprim
75 {
76 public:
77  HDST_API
78  HdStDrawTarget(SdfPath const & id);
79  HDST_API
80  ~HdStDrawTarget() override;
81 
87  enum DirtyBits : HdDirtyBits {
88  Clean = 0,
89  DirtyDTEnable = 1 << 0,
90  DirtyDTCamera = 1 << 1,
91  DirtyDTResolution = 1 << 2,
92  DirtyDTAttachment = 1 << 3, // Legacy
93  DirtyDTAovBindings = 1 << 4,
94  DirtyDTDepthClearValue = 1 << 5, // Legacy
95  DirtyDTDepthPriority = 1 << 6,
96  DirtyDTCollection = 1 << 7,
97  AllDirty = (DirtyDTEnable
98  |DirtyDTCamera
99  |DirtyDTResolution
100  |DirtyDTAttachment
101  |DirtyDTAovBindings
102  |DirtyDTDepthClearValue
103  |DirtyDTDepthPriority
104  |DirtyDTCollection)
105  };
106 
118  HDST_API
119  static bool GetUseStormTextureSystem();
120 
127  unsigned int GetVersion() const { return _version; }
128 
130  HDST_API
131  void Sync(HdSceneDelegate *sceneDelegate,
132  HdRenderParam *renderParam,
133  HdDirtyBits *dirtyBits) override;
134 
138  HDST_API
139  HdDirtyBits GetInitialDirtyBitsMask() const override;
140 
141 
142  // ---------------------------------------------------------------------- //
144  // ---------------------------------------------------------------------- //
145  bool IsEnabled() const { return _enabled; }
146  const GlfDrawTargetRefPtr &GetGlfDrawTarget() const { return _drawTarget; }
147  const HdStDrawTargetRenderPassState *GetRenderPassState() const
148  {
149  return &_renderPassState;
150  }
151 
153  HDST_API
154  HdRprimCollection const &GetCollection() const { return _collection; }
155 
157  HDST_API
158  bool WriteToFile(const HdRenderIndex &renderIndex,
159  const std::string &attachment,
160  const std::string &path) const;
161 
163  HDST_API
164  static void GetDrawTargets(HdRenderIndex* renderIndex,
165  HdStDrawTargetPtrVector *drawTargets);
166 
171  const GfVec2i &GetResolution() const {
172  return _resolution;
173  }
174 
175 private:
176  unsigned int _version;
177 
178  bool _enabled;
179  SdfPath _cameraId;
180  GfVec2i _resolution;
181  float _depthClearValue;
182  HdRprimCollection _collection;
183 
184  HdStDrawTargetRenderPassState _renderPassState;
185  std::vector<HdStTextureResourceHandleSharedPtr> _colorTextureResourceHandles;
186  HdStTextureResourceHandleSharedPtr _depthTextureResourceHandle;
187 
189  GlfGLContextSharedPtr _drawTargetContext;
190  GlfDrawTargetRefPtr _drawTarget;
191 
192  // Is it necessary to create GPU resources because they are uninitialized
193  // or the attachments/resolution changed.
194  bool _texturesDirty;
195 
196  void _SetAttachments(HdSceneDelegate *sceneDelegate,
197  const HdStDrawTargetAttachmentDescArray &attachments);
198 
199  // Set clear value for depth attachments.
200  void _SetAttachmentDataDepthClearValue();
201 
202  void _SetCamera(const SdfPath &cameraPath);
203 
204  const HdCamera *_GetCamera(const HdRenderIndex &renderIndex) const;
205 
206  void _ResizeDrawTarget();
207  void _RegisterTextureResourceHandle(HdSceneDelegate *sceneDelegate,
208  const std::string &name,
209  HdStTextureResourceHandleSharedPtr *handlePtr);
210 
211  // No copy
212  HdStDrawTarget() = delete;
213  HdStDrawTarget(const HdStDrawTarget &) = delete;
214  HdStDrawTarget &operator =(const HdStDrawTarget &) = delete;
215 };
216 
217 
218 PXR_NAMESPACE_CLOSE_SCOPE
219 
220 #endif // PXR_IMAGING_HD_ST_DRAW_TARGET_H
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:117
HDST_API HdDirtyBits GetInitialDirtyBitsMask() const override
Returns the minimal set of dirty bits to place in the change tracker for use in the first sync of thi...
Describes all the color buffer attachments for a draw target.
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
const GfVec2i & GetResolution() const
Resolution.
Definition: drawTarget.h:171
unsigned int GetVersion() const
Returns the version of the under-lying GlfDrawTarget.
Definition: drawTarget.h:127
DirtyBits
Dirty bits for the HdStDrawTarget object.
Definition: drawTarget.h:87
Hydra schema for a camera that pulls the basic params (see above) during Sync.
Definition: camera.h:78
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
static HDST_API bool GetUseStormTextureSystem()
If true, the draw target attachments are managed by the Storm texture system.
Adapter class providing data exchange with the client scene graph.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
A named, semantic collection of objects.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
HDST_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Synchronizes state from the delegate to this object.
Sprim (state prim) is a base class of managing state for non-drawable scene entity (e...
Definition: sprim.h:52
Represents an render to texture render pass.
Definition: drawTarget.h:74
HDST_API HdRprimCollection const & GetCollection() const
Returns collection of rprims the draw target draws.
Definition: drawTarget.h:154
HDST_API bool WriteToFile(const HdRenderIndex &renderIndex, const std::string &attachment, const std::string &path) const
Debug api to output the contents of the draw target to a png file.
static HDST_API void GetDrawTargets(HdRenderIndex *renderIndex, HdStDrawTargetPtrVector *drawTargets)
returns all HdStDrawTargets in the render index
Represents common non-gl context specific render pass state for a draw target.