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 HDST_DRAW_TARGET_H
25 #define HDST_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/glf/drawTarget.h"
35 
36 #include "pxr/usd/sdf/path.h"
37 #include "pxr/base/tf/staticTokens.h"
38 
39 #include <boost/shared_ptr.hpp>
40 
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 
55 TF_DECLARE_PUBLIC_TOKENS(HdStDrawTargetTokens, HDST_API, HDST_DRAW_TARGET_TOKENS);
56 
57 class HdSceneDelegate;
58 class HdRenderIndex;
59 class HdCamera;
61 
62 
63 typedef boost::shared_ptr<class GlfGLContext> GlfGLContextSharedPtr;
64 
65 typedef std::vector<class HdStDrawTarget const *> HdStDrawTargetPtrConstVector;
66 
74 class HdStDrawTarget : public HdSprim {
75 public:
76  HDST_API
77  HdStDrawTarget(SdfPath const & id);
78  HDST_API
79  virtual ~HdStDrawTarget();
80 
82  enum DirtyBits : HdDirtyBits {
83  Clean = 0,
84  DirtyDTEnable = 1 << 0,
85  DirtyDTCamera = 1 << 1,
86  DirtyDTResolution = 1 << 2,
87  DirtyDTAttachment = 1 << 3,
88  DirtyDTDepthClearValue = 1 << 4,
89  DirtyDTCollection = 1 << 5,
90  AllDirty = (DirtyDTEnable
91  |DirtyDTCamera
92  |DirtyDTResolution
93  |DirtyDTAttachment
94  |DirtyDTDepthClearValue
95  |DirtyDTCollection)
96  };
97 
104  unsigned int GetVersion() const { return _version; }
105 
107  HDST_API
108  virtual void Sync(HdSceneDelegate *sceneDelegate,
109  HdRenderParam *renderParam,
110  HdDirtyBits *dirtyBits) override;
111 
115  HDST_API
116  virtual HdDirtyBits GetInitialDirtyBitsMask() const override;
117 
118 
119  // ---------------------------------------------------------------------- //
121  // ---------------------------------------------------------------------- //
122  bool IsEnabled() const { return _enabled; }
123  const GlfDrawTargetRefPtr &GetGlfDrawTarget() const { return _drawTarget; }
124  const HdStDrawTargetRenderPassState *GetRenderPassState() const
125  {
126  return &_renderPassState;
127  }
128 
130  HDST_API
131  bool WriteToFile(const HdRenderIndex &renderIndex,
132  const std::string &attachment,
133  const std::string &path) const;
134 
136  HDST_API
137  static void GetDrawTargets(HdRenderIndex* renderIndex,
138  HdStDrawTargetPtrConstVector *drawTargets);
139 
140 
141 private:
142  unsigned int _version;
143 
144  bool _enabled;
145  SdfPath _cameraId;
146  GfVec2i _resolution;
147  HdRprimCollection _collection;
148 
149  HdStDrawTargetRenderPassState _renderPassState;
150  std::vector<HdStTextureResourceHandleSharedPtr> _colorTextureResourceHandles;
151  HdStTextureResourceHandleSharedPtr _depthTextureResourceHandle;
152 
154  GlfGLContextSharedPtr _drawTargetContext;
155  GlfDrawTargetRefPtr _drawTarget;
156 
157  void _SetAttachments(HdSceneDelegate *sceneDelegate,
158  const HdStDrawTargetAttachmentDescArray &attachments);
159 
160  void _SetCamera(const SdfPath &cameraPath);
161 
162  const HdCamera *_GetCamera(const HdRenderIndex &renderIndex) const;
163 
164  void _ResizeDrawTarget();
165  void _RegisterTextureResourceHandle(HdSceneDelegate *sceneDelegate,
166  const std::string &name,
167  HdStTextureResourceHandleSharedPtr *handlePtr);
168 
169  // No copy
170  HdStDrawTarget() = delete;
171  HdStDrawTarget(const HdStDrawTarget &) = delete;
172  HdStDrawTarget &operator =(const HdStDrawTarget &) = delete;
173 };
174 
175 
176 PXR_NAMESPACE_CLOSE_SCOPE
177 
178 #endif // HDST_DRAW_TARGET_H
virtual HDST_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Synchronizes state from the delegate to this object.
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:119
Describes all the color buffer attachments for a draw target.
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
unsigned int GetVersion() const
Returns the version of the under-lying GlfDrawTarget.
Definition: drawTarget.h:104
DirtyBits
Dirty bits for the HdStDrawTarget object.
Definition: drawTarget.h:82
Hydra schema for a camera that pulls the basic params (see above) during Sync.
Definition: camera.h:80
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
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:287
Sprim (state prim) is a base class of managing state for non-drawable scene entity (e...
Definition: sprim.h:54
virtual 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...
Represents an render to texture render pass.
Definition: drawTarget.h:74
static HDST_API void GetDrawTargets(HdRenderIndex *renderIndex, HdStDrawTargetPtrConstVector *drawTargets)
returns all HdStDrawTargets in the render index
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.
Represents common non-gl context specific render pass state for a draw target.