HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
drawTarget.h
Go to the documentation of this file.
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"
31 #include "pxr/imaging/hd/enums.h"
33 #include "pxr/imaging/hd/sprim.h"
36 
37 #include "pxr/usd/sdf/path.h"
39 
40 #include <memory>
41 #include <vector>
42 
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 
59 
60 class HdCamera;
62 
63 using GlfGLContextSharedPtr = std::shared_ptr<class GlfGLContext>;
64 
65 using HdStDrawTargetPtrVector = std::vector<class HdStDrawTarget *>;
66 
67 /// \class HdStDrawTarget
68 ///
69 /// Represents an render to texture render pass.
70 ///
71 /// \note This is a temporary API to aid transition to Storm, and is subject
72 /// to major changes.
73 ///
74 class HdStDrawTarget : public HdSprim
75 {
76 public:
77  HDST_API
78  HdStDrawTarget(SdfPath const & id);
79  HDST_API
80  ~HdStDrawTarget() override;
81 
82  /// Dirty bits for the HdStDrawTarget object
83  ///
84  /// When GetUseStormTextureSystem() is true, "Legacy" dirty
85  /// bits are ignored.
86  ///
88  Clean = 0,
89  DirtyDTEnable = 1 << 0,
90  DirtyDTCamera = 1 << 1,
92  DirtyDTAttachment = 1 << 3, // Legacy
94  DirtyDTDepthClearValue = 1 << 5, // Legacy
105  };
106 
107  /// If true, the draw target attachments are managed by the
108  /// Storm texture system. This also makes the draw target task
109  /// use HgiGraphicsCmdDesc to bind the attachments as render
110  /// targets. Shaders who want to read the attachments can bind
111  /// the textures like any other texture in the Storm texture
112  /// system.
113  /// Note: draw targets managed by the Storm texture system do not
114  /// work when bindless textures are enabled.
115  ///
116  /// If false, uses GlfDrawTarget.
117  ///
118  HDST_API
119  static bool GetUseStormTextureSystem();
120 
121  /// Returns the version of the under-lying GlfDrawTarget.
122  /// The version changes if the draw target attachments texture ids
123  /// are changed in anyway (for example switching to a new
124  /// GlfDrawTarget object or resize the resources).
125  /// The version does not increment if only the contents of the
126  /// texture resources change
127  unsigned int GetVersion() const { return _version; }
128 
129  /// Synchronizes state from the delegate to this object.
130  HDST_API
131  void Sync(HdSceneDelegate *sceneDelegate,
132  HdRenderParam *renderParam,
133  HdDirtyBits *dirtyBits) override;
134 
135  /// Returns the minimal set of dirty bits to place in the
136  /// change tracker for use in the first sync of this prim.
137  /// Typically this would be all dirty bits.
138  HDST_API
139  HdDirtyBits GetInitialDirtyBitsMask() const override;
140 
141 
142  // ---------------------------------------------------------------------- //
143  /// \name Draw Target API
144  // ---------------------------------------------------------------------- //
145  bool IsEnabled() const { return _enabled; }
146  const GlfDrawTargetRefPtr &GetGlfDrawTarget() const { return _drawTarget; }
148  {
149  return &_renderPassState;
150  }
151 
152  /// Returns collection of rprims the draw target draws.
153  HDST_API
154  HdRprimCollection const &GetCollection() const { return _collection; }
155 
156  /// Debug api to output the contents of the draw target to a png file.
157  HDST_API
158  bool WriteToFile(const HdRenderIndex &renderIndex,
159  const std::string &attachment,
160  const std::string &path) const;
161 
162  /// returns all HdStDrawTargets in the render index
163  HDST_API
164  static void GetDrawTargets(HdRenderIndex* renderIndex,
165  HdStDrawTargetPtrVector *drawTargets);
166 
167  /// Resolution.
168  ///
169  /// Set during sync.
170  ///
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 
188  /// The context which owns the draw target object.
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,
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,
210 
211  // No copy
212  HdStDrawTarget() = delete;
213  HdStDrawTarget(const HdStDrawTarget &) = delete;
214  HdStDrawTarget &operator =(const HdStDrawTarget &) = delete;
215 };
216 
217 
219 
220 #endif // PXR_IMAGING_HD_ST_DRAW_TARGET_H
GLuint const GLchar * name
Definition: glew.h:1814
std::vector< class HdStDrawTarget * > HdStDrawTargetPtrVector
Definition: drawTarget.h:65
Definition: vec2i.h:61
HDST_API HdRprimCollection const & GetCollection() const
Returns collection of rprims the draw target draws.
Definition: drawTarget.h:154
uint32_t HdDirtyBits
Definition: types.h:127
const GfVec2i & GetResolution() const
Definition: drawTarget.h:171
bool IsEnabled() const
The context which owns the draw target object.
Definition: drawTarget.h:145
GLenum attachment
Definition: glew.h:2361
const HdStDrawTargetRenderPassState * GetRenderPassState() const
The context which owns the draw target object.
Definition: drawTarget.h:147
TF_DECLARE_PUBLIC_TOKENS(HdStDrawTargetTokens, HDST_API, HDST_DRAW_TARGET_TOKENS)
const GlfDrawTargetRefPtr & GetGlfDrawTarget() const
The context which owns the draw target object.
Definition: drawTarget.h:146
std::shared_ptr< class HdStTextureResourceHandle > HdStTextureResourceHandleSharedPtr
Definition: material.h:44
unsigned int GetVersion() const
Definition: drawTarget.h:127
HDST_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Synchronizes state from the delegate to this object.
static HDST_API bool GetUseStormTextureSystem()
HDST_API HdDirtyBits GetInitialDirtyBitsMask() const override
Definition: path.h:288
std::shared_ptr< class GlfGLContext > GlfGLContextSharedPtr
Definition: drawTarget.h:51
static HDST_API void GetDrawTargets(HdRenderIndex *renderIndex, HdStDrawTargetPtrVector *drawTargets)
returns all HdStDrawTargets in the render index
GLsizei const GLchar *const * path
Definition: glew.h:6461
Definition: sprim.h:52
GLsizei const GLchar *const * string
Definition: glew.h:1844
HDST_API ~HdStDrawTarget() override
#define HDST_DRAW_TARGET_TOKENS
Definition: drawTarget.h:46
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
#define HDST_API
Definition: api.h:40
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.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
GLsizei const GLenum * attachments
Definition: glew.h:4075