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  {}
46 
49 
50  /// Called to populate the RenderIndex for this UsdPrim. The adapter is
51  /// expected to create one or more Rprims in the render index using the
52  /// given proxy.
54  UsdPrim const& prim,
56  UsdImagingInstancerContext const* instancerContext = NULL) override;
57 
58  // If the draw mode adapter is applied to a prim, it cuts off traversal of
59  // that prim's subtree.
60  bool ShouldCullChildren() const override;
61 
62  // Because draw mode can change usdImaging topology, we need to handle
63  // render index compatibility at a later point than adapter lookup.
64  bool IsSupported(UsdImagingIndexProxy const* index) const override;
65 
66  // Cards prims can take effect on master prims, so we need to let the
67  // UsdImagingInstanceAdapter know we want special handling.
68  bool CanPopulateMaster() const override;
69 
70  // ---------------------------------------------------------------------- //
71  /// \name Parallel Setup and Resolve
72  // ---------------------------------------------------------------------- //
73 
75  void TrackVariability(UsdPrim const& prim,
76  SdfPath const& cachePath,
77  HdDirtyBits* timeVaryingBits,
79  instancerContext = NULL) const override;
80 
82  void UpdateForTime(UsdPrim const& prim,
83  SdfPath const& cachePath,
85  HdDirtyBits requestedBits,
87  instancerContext = NULL) const override;
88 
89  // ---------------------------------------------------------------------- //
90  /// \name Change Processing
91  // ---------------------------------------------------------------------- //
92 
95  SdfPath const& cachePath,
96  TfToken const& property) override;
97 
99  void MarkDirty(UsdPrim const& prim,
100  SdfPath const& cachePath,
101  HdDirtyBits dirty,
102  UsdImagingIndexProxy* index) override;
103 
105  void MarkTransformDirty(UsdPrim const& prim,
106  SdfPath const& cachePath,
107  UsdImagingIndexProxy* index) override;
108 
110  void MarkVisibilityDirty(UsdPrim const& prim,
111  SdfPath const& cachePath,
112  UsdImagingIndexProxy* index) override;
113 
115  void MarkMaterialDirty(UsdPrim const& prim,
116  SdfPath const& cachePath,
117  UsdImagingIndexProxy* index) override;
118 
119 protected:
121  void _RemovePrim(SdfPath const& cachePath,
122  UsdImagingIndexProxy* index) override;
123 
124 private:
125  // For cards rendering, check if we're rendering any faces with 0 area;
126  // if so, issue a warning.
127  void _SanityCheckFaceSizes(SdfPath const& cachePath,
128  GfRange3d const& extents, uint8_t axes_mask)
129  const;
130 
131  // Check whether the given cachePath is a path to the draw mode material.
132  bool _IsMaterialPath(SdfPath const& path) const;
133  // Check whether the given cachePath is a path to a draw mode texture.
134  bool _IsTexturePath(SdfPath const& path) const;
135 
136  // Check if any of the cards texture attributes are marked as time-varying.
137  void _CheckForTextureVariability(UsdPrim const& prim,
138  HdDirtyBits dirtyBits,
139  HdDirtyBits *timeVaryingBits) const;
140 
141  // Computes the extents of the given prim, using UsdGeomBBoxCache.
142  // The extents are computed at UsdTimeCode::EarliestTime() (and are not
143  // animated), and they are computed for purposes default/proxy/render.
144  GfRange3d _ComputeExtent(UsdPrim const& prim) const;
145 
146  // Generate geometry for "origin" draw mode.
147  void _GenerateOriginGeometry(VtValue* topo, VtValue* points,
148  GfRange3d const& extents) const;
149 
150  // Generate geometry for "bounds" draw mode.
151  void _GenerateBoundsGeometry(VtValue* topo, VtValue* points,
152  GfRange3d const& extents) const;
153 
154  // Generate geometry for "cards" draw mode, with cardGeometry "cross".
155  void _GenerateCardsCrossGeometry(VtValue* topo, VtValue* points,
156  GfRange3d const& extents, uint8_t axes_mask) const;
157 
158  // Generate geometry for "cards" draw mode, with cardGeometry "box".
159  void _GenerateCardsBoxGeometry(VtValue* topo, VtValue* points,
160  GfRange3d const& extents, uint8_t axes_mask) const;
161 
162  // Generate geometry for "cards" draw mode, with cardGeometry "fromTexture".
163  void _GenerateCardsFromTextureGeometry(VtValue* topo, VtValue* points,
164  VtValue* uv, VtValue* assign, GfRange3d* extents,
165  UsdPrim const& prim) const;
166 
167  // Given an asset attribute pointing to a texture, pull the "worldtoscreen"
168  // matrix out of image metadata.
169  bool _GetMatrixFromImageMetadata(UsdAttribute const& attr, GfMatrix4d* mat)
170  const;
171 
172  // Generate texture coordinates for cards "cross"/"box" mode.
173  void _GenerateTextureCoordinates(VtValue* uv, VtValue* assign,
174  uint8_t axes_mask) const;
175 
176  // Map from cachePath to what drawMode it was populated as.
177  using _DrawModeMap = TfHashMap<SdfPath, TfToken, SdfPath::Hash>;
178  _DrawModeMap _drawModeMap;
179 };
180 
181 
183 
184 #endif // PXR_USD_IMAGING_USD_IMAGING_GL_DRAW_MODE_ADAPTER_H
USDIMAGINGGL_API void _RemovePrim(SdfPath const &cachePath, UsdImagingIndexProxy *index) override
Returns true if the adapter can be populated into the target index.
#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.
GA_API const UT_StringHolder uv
GT_API const UT_StringHolder time
GLuint index
Definition: glew.h:1814
uint32_t HdDirtyBits
Definition: types.h:127
USDIMAGING_API void MarkMaterialDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index) 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 MarkVisibilityDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index) override
INT property
Definition: wglew.h:145
Definition: prim.h:132
USDIMAGINGGL_API void UpdateForTime(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, HdDirtyBits requestedBits, UsdImagingInstancerContext const *instancerContext=NULL) const override
Definition: path.h:288
bool ShouldCullChildren() const override
GLsizei const GLchar *const * path
Definition: glew.h:6461
USDIMAGINGGL_API void MarkTransformDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index) override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
GLuint GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glew.h:3446
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool CanPopulateMaster() const override
USDIMAGINGGL_API HdDirtyBits ProcessPropertyChange(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &property) override
USDIMAGINGGL_API ~UsdImagingGLDrawModeAdapter() override
USDIMAGINGGL_API void MarkDirty(UsdPrim const &prim, SdfPath const &cachePath, HdDirtyBits dirty, UsdImagingIndexProxy *index) override
Definition: value.h:174
SdfPath Populate(UsdPrim const &prim, UsdImagingIndexProxy *index, UsdImagingInstancerContext const *instancerContext=NULL) override