HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
drawModeAdapter.h
Go to the documentation of this file.
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_USD_IMAGING_USD_IMAGING_GL_DRAW_MODE_ADAPTER_H
25 #define PXR_USD_IMAGING_USD_IMAGING_GL_DRAW_MODE_ADAPTER_H
26 
27 #include "pxr/pxr.h"
30 
32 
33 
34 /// \class UsdImagingGLDrawModeAdapter
35 ///
36 /// Delegate support for the drawMode attribute on UsdGeomModelAPI.
37 ///
39 {
40 public:
42 
45 
48 
49  /// Called to populate the RenderIndex for this UsdPrim. The adapter is
50  /// expected to create one or more Rprims in the render index using the
51  /// given proxy.
53  UsdPrim const& prim,
55  UsdImagingInstancerContext const* instancerContext = NULL) override;
56 
57  // If the draw mode adapter is applied to a prim, it cuts off traversal of
58  // that prim's subtree.
59  bool ShouldCullChildren() const override;
60 
61  // Because draw mode can change usdImaging topology, we need to handle
62  // render index compatibility at a later point than adapter lookup.
63  bool IsSupported(UsdImagingIndexProxy const* index) const override;
64 
65  // Cards mode can be applied to instance prims, so we need to let the
66  // UsdImagingInstanceAdapter know we want special handling.
67  bool CanPopulateUsdInstance() const override;
68 
69  // ---------------------------------------------------------------------- //
70  /// \name Parallel Setup and Resolve
71  // ---------------------------------------------------------------------- //
72 
74  void TrackVariability(UsdPrim const& prim,
75  SdfPath const& cachePath,
76  HdDirtyBits* timeVaryingBits,
78  instancerContext = NULL) const override;
79 
81  void UpdateForTime(UsdPrim const& prim,
82  SdfPath const& cachePath,
84  HdDirtyBits requestedBits,
86  instancerContext = NULL) const override;
87 
88  // ---------------------------------------------------------------------- //
89  /// \name Change Processing
90  // ---------------------------------------------------------------------- //
91 
94  SdfPath const& cachePath,
95  TfToken const& property) override;
96 
97  // Note: Resync/Remove are overridden so that we can resync/remove the
98  // material and cards rprim together, since they are populated together.
100  void ProcessPrimResync(SdfPath const& cachePath,
101  UsdImagingIndexProxy* index) override;
102 
104  void ProcessPrimRemoval(SdfPath const& cachePath,
105  UsdImagingIndexProxy* index) override;
106 
108  void MarkDirty(UsdPrim const& prim,
109  SdfPath const& cachePath,
110  HdDirtyBits dirty,
111  UsdImagingIndexProxy* index) override;
112 
114  void MarkTransformDirty(UsdPrim const& prim,
115  SdfPath const& cachePath,
116  UsdImagingIndexProxy* index) override;
117 
119  void MarkVisibilityDirty(UsdPrim const& prim,
120  SdfPath const& cachePath,
121  UsdImagingIndexProxy* index) override;
122 
124  void MarkMaterialDirty(UsdPrim const& prim,
125  SdfPath const& cachePath,
126  UsdImagingIndexProxy* index) override;
127 
128  // ---------------------------------------------------------------------- //
129  /// \name Data access
130  // ---------------------------------------------------------------------- //
131 
133  VtValue Get(UsdPrim const& prim,
134  SdfPath const& cachePath,
135  TfToken const& key,
137  VtIntArray *outIndices) const override;
138 
140  HdCullStyle GetCullStyle(UsdPrim const& prim,
141  SdfPath const& cachePath,
142  UsdTimeCode time) const override;
143 
145  VtValue GetTopology(UsdPrim const& prim,
146  SdfPath const& cachePath,
147  UsdTimeCode time) const override;
148 
150  GfRange3d GetExtent(UsdPrim const& prim,
151  SdfPath const& cachePath,
152  UsdTimeCode time) const override;
153 
155  bool GetDoubleSided(UsdPrim const& prim,
156  SdfPath const& cachePath,
157  UsdTimeCode time) const override;
158 
160  GfMatrix4d GetTransform(UsdPrim const& prim,
161  SdfPath const& cachePath,
163  bool ignoreRootTransform = false) const override;
164 
166  SdfPath GetMaterialId(UsdPrim const& prim,
167  SdfPath const& cachePath,
168  UsdTimeCode time) const override;
169 
171  VtValue GetMaterialResource(UsdPrim const& prim,
172  SdfPath const& cachePath,
173  UsdTimeCode time) const override;
174 
175 protected:
177  void _RemovePrim(SdfPath const& cachePath,
178  UsdImagingIndexProxy* index) override;
179 
180 private:
181  // For cards rendering, check if we're rendering any faces with 0 area;
182  // if so, issue a warning.
183  void _SanityCheckFaceSizes(SdfPath const& cachePath,
184  GfRange3d const& extents, uint8_t axes_mask)
185  const;
186 
187  void _ComputeGeometryData(UsdPrim const& prim,
188  SdfPath const& cachePath,
190  TfToken const& drawMode,
191  VtValue* topology,
192  VtValue* points,
193  GfRange3d* extent,
194  VtValue* uv,
195  VtValue* assign) const;
196 
197  // Check whether the given cachePath is a path to the draw mode material.
198  bool _IsMaterialPath(SdfPath const& path) const;
199 
200  // Check whether the given cachePath is a path to a draw mode texture.
201  bool _IsTexturePath(SdfPath const& path) const;
202 
203  // Return true if prim has a time varying extent or extentsHint attribute.
204  bool _HasVaryingExtent(UsdPrim const& prim) const;
205 
206  // Check if any of the cards texture attributes are marked as time-varying.
207  void _CheckForTextureVariability(UsdPrim const& prim,
208  HdDirtyBits dirtyBits,
209  HdDirtyBits *timeVaryingBits) const;
210 
211  // Computes the extents of the given prim, using UsdGeomBBoxCache.
212  // The extents are computed for purposes default/proxy/render.
213  GfRange3d _ComputeExtent(UsdPrim const& prim,
214  const UsdTimeCode& timecode) const;
215 
216  // Generate geometry for "origin" draw mode.
217  void _GenerateOriginGeometry(VtValue* topo, VtValue* points,
218  GfRange3d const& extents) const;
219 
220  // Generate geometry for "bounds" draw mode.
221  void _GenerateBoundsGeometry(VtValue* topo, VtValue* points,
222  GfRange3d const& extents) const;
223 
224  // Generate geometry for "cards" draw mode, with cardGeometry "cross".
225  void _GenerateCardsCrossGeometry(VtValue* topo, VtValue* points,
226  GfRange3d const& extents, uint8_t axes_mask) const;
227 
228  // Generate geometry for "cards" draw mode, with cardGeometry "box".
229  void _GenerateCardsBoxGeometry(VtValue* topo, VtValue* points,
230  GfRange3d const& extents, uint8_t axes_mask) const;
231 
232  // Generate geometry for "cards" draw mode, with cardGeometry "fromTexture".
233  void _GenerateCardsFromTextureGeometry(VtValue* topo, VtValue* points,
234  VtValue* uv, VtValue* assign, GfRange3d* extents,
235  UsdPrim const& prim) const;
236 
237  // Given an asset attribute pointing to a texture, pull the "worldtoscreen"
238  // matrix out of image metadata.
239  bool _GetMatrixFromImageMetadata(UsdAttribute const& attr, GfMatrix4d* mat)
240  const;
241 
242  // Generate texture coordinates for cards "cross"/"box" mode.
243  void _GenerateTextureCoordinates(VtValue* uv, VtValue* assign,
244  uint8_t axes_mask) const;
245 
246  // Map from cachePath to what drawMode it was populated as.
248  _DrawModeMap _drawModeMap;
249 
250  // Map from cachePath (of gprim) to what material it's bound to.
252  _MaterialMap _materialMap;
253 
254  // The default value of model:drawModeColor, fetched from the schema
255  // registry and stored for quick access...
256  GfVec3f _schemaColor;
257 };
258 
259 
261 
262 #endif // PXR_USD_IMAGING_USD_IMAGING_GL_DRAW_MODE_ADAPTER_H
USDIMAGINGGL_API HdCullStyle GetCullStyle(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
Gets the cullstyle of a specific path in the scene graph.
GLint GLenum GLsizei GLsizei GLsizei GLsizei extent
Definition: glew.h:15877
USDIMAGINGGL_API void _RemovePrim(SdfPath const &cachePath, UsdImagingIndexProxy *index) override
Returns true if the adapter can be populated into the target index.
USDIMAGINGGL_API VtValue Get(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &key, UsdTimeCode time, VtIntArray *outIndices) const override
HdCullStyle
Definition: enums.h:122
#define USDIMAGING_API
Definition: api.h:40
bool IsSupported(UsdImagingIndexProxy const *index) const override
Returns true if the adapter can be populated into the target index.
USDIMAGINGGL_API GfMatrix4d GetTransform(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, bool ignoreRootTransform=false) const override
USDIMAGING_API VtValue GetMaterialResource(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
The root transform provided by the delegate.
GA_API const UT_StringHolder uv
GT_API const UT_StringHolder time
uint32_t HdDirtyBits
Definition: types.h:158
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
Definition: vec3f.h:63
USDIMAGINGGL_API UsdImagingGLDrawModeAdapter()
USDIMAGINGGL_API GfRange3d GetExtent(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
USDIMAGINGGL_API void TrackVariability(UsdPrim const &prim, SdfPath const &cachePath, HdDirtyBits *timeVaryingBits, UsdImagingInstancerContext const *instancerContext=NULL) const override
Definition: token.h:87
#define USDIMAGINGGL_API
Definition: api.h:40
USDIMAGINGGL_API void MarkMaterialDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index) override
USDIMAGINGGL_API void MarkVisibilityDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index) override
GT_API const UT_StringHolder topology
INT property
Definition: wglew.h:145
Definition: prim.h:132
USDIMAGINGGL_API SdfPath GetMaterialId(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
The root transform provided by the delegate.
USDIMAGINGGL_API void UpdateForTime(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, HdDirtyBits requestedBits, UsdImagingInstancerContext const *instancerContext=NULL) const override
Definition: path.h:290
bool ShouldCullChildren() const override
GLuint GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glew.h:3460
USDIMAGINGGL_API bool GetDoubleSided(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
Reads double-sided from the given prim. If not authored, returns false.
USDIMAGINGGL_API void MarkTransformDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index) override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1394
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool CanPopulateUsdInstance() const override
USDIMAGINGGL_API HdDirtyBits ProcessPropertyChange(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &property) override
USDIMAGINGGL_API VtValue GetTopology(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
USDIMAGINGGL_API void ProcessPrimResync(SdfPath const &cachePath, UsdImagingIndexProxy *index) override
USDIMAGINGGL_API ~UsdImagingGLDrawModeAdapter() override
USDIMAGINGGL_API void MarkDirty(UsdPrim const &prim, SdfPath const &cachePath, HdDirtyBits dirty, UsdImagingIndexProxy *index) override
Definition: value.h:166
SdfPath Populate(UsdPrim const &prim, UsdImagingIndexProxy *index, UsdImagingInstancerContext const *instancerContext=NULL) override
USDIMAGINGGL_API void ProcessPrimRemoval(SdfPath const &cachePath, UsdImagingIndexProxy *index) override