All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
drawModeAdapter.h
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 USDIMAGINGGL_DRAW_MODE_ADAPTER_H
25 #define USDIMAGINGGL_DRAW_MODE_ADAPTER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usdImaging/usdImagingGL/api.h"
29 #include "pxr/usdImaging/usdImaging/primAdapter.h"
30 
31 #include "pxr/usd/usdGeom/xformCache.h"
32 
33 PXR_NAMESPACE_OPEN_SCOPE
34 
35 
41 public:
43 
46  {}
47 
48  USDIMAGINGGL_API
49  virtual ~UsdImagingGLDrawModeAdapter();
50 
54  virtual SdfPath Populate(
55  UsdPrim const& prim,
56  UsdImagingIndexProxy* index,
57  UsdImagingInstancerContext const* instancerContext = NULL) override;
58 
59  // If the draw mode adapter is applied to a prim, it cuts off traversal of
60  // that prim's subtree.
61  virtual bool ShouldCullChildren() const override;
62 
63  // Because draw mode can change usdImaging topology, we need to handle
64  // render index compatibility at a later point than adapter lookup.
65  virtual bool IsSupported(UsdImagingIndexProxy const* index) const override;
66 
67  // Cards prims can take effect on master prims, so we need to let the
68  // UsdImagingInstanceAdapter know we want special handling.
69  virtual bool CanPopulateMaster() const override;
70 
71  // ---------------------------------------------------------------------- //
73  // ---------------------------------------------------------------------- //
74 
75  USDIMAGINGGL_API
76  virtual void TrackVariability(UsdPrim const& prim,
77  SdfPath const& cachePath,
78  HdDirtyBits* timeVaryingBits,
80  instancerContext = NULL) const override;
81 
82  USDIMAGINGGL_API
83  virtual void UpdateForTime(UsdPrim const& prim,
84  SdfPath const& cachePath,
85  UsdTimeCode time,
86  HdDirtyBits requestedBits,
88  instancerContext = NULL) const override;
89 
90  // ---------------------------------------------------------------------- //
92  // ---------------------------------------------------------------------- //
93 
94  USDIMAGINGGL_API
95  virtual HdDirtyBits ProcessPropertyChange(UsdPrim const& prim,
96  SdfPath const& cachePath,
97  TfToken const& property) override;
98 
99  USDIMAGINGGL_API
100  virtual void MarkDirty(UsdPrim const& prim,
101  SdfPath const& cachePath,
102  HdDirtyBits dirty,
103  UsdImagingIndexProxy* index) override;
104 
105  USDIMAGINGGL_API
106  virtual void MarkTransformDirty(UsdPrim const& prim,
107  SdfPath const& cachePath,
108  UsdImagingIndexProxy* index) override;
109 
110  USDIMAGINGGL_API
111  virtual void MarkVisibilityDirty(UsdPrim const& prim,
112  SdfPath const& cachePath,
113  UsdImagingIndexProxy* index) override;
114 
115  USDIMAGING_API
116  virtual void MarkMaterialDirty(UsdPrim const& prim,
117  SdfPath const& cachePath,
118  UsdImagingIndexProxy* index) override;
119 
120 
121  // ---------------------------------------------------------------------- //
123  // ---------------------------------------------------------------------- //
124 
125  virtual HdTextureResource::ID
126  GetTextureResourceID(UsdPrim const& usdPrim, SdfPath const &id, UsdTimeCode time, size_t salt) const override;
127 
128  virtual HdTextureResourceSharedPtr
129  GetTextureResource(UsdPrim const& usdPrim, SdfPath const &id, UsdTimeCode time) const override;
130 
131 protected:
132  USDIMAGINGGL_API
133  virtual void _RemovePrim(SdfPath const& cachePath,
134  UsdImagingIndexProxy* index) override;
135 
136 private:
137  // For cards rendering, check if we're rendering any faces with 0 area;
138  // if so, issue a warning.
139  void _SanityCheckFaceSizes(SdfPath const& cachePath,
140  GfRange3d const& extents, uint8_t axes_mask)
141  const;
142 
143  // Check whether the given cachePath is a path to the draw mode material.
144  bool _IsMaterialPath(SdfPath const& path) const;
145  // Check whether the given cachePath is a path to a draw mode texture.
146  bool _IsTexturePath(SdfPath const& path) const;
147 
148  // Check if any of the cards texture attributes are marked as time-varying.
149  void _CheckForTextureVariability(UsdPrim const& prim,
150  HdDirtyBits dirtyBits,
151  HdDirtyBits *timeVaryingBits) const;
152 
153  // Computes the extents of the given prim, using UsdGeomBBoxCache.
154  // The extents are computed at UsdTimeCode::EarliestTime() (and are not
155  // animated), and they are computed for purposes default/proxy/render.
156  GfRange3d _ComputeExtent(UsdPrim const& prim) const;
157 
158  // Returns the draw mode surface shader.
159  std::string _GetSurfaceShaderSource() const;
160 
161  // Generate geometry for "origin" draw mode.
162  void _GenerateOriginGeometry(VtValue* topo, VtValue* points,
163  GfRange3d const& extents) const;
164 
165  // Generate geometry for "bounds" draw mode.
166  void _GenerateBoundsGeometry(VtValue* topo, VtValue* points,
167  GfRange3d const& extents) const;
168 
169  // Generate geometry for "cards" draw mode, with cardGeometry "cross".
170  void _GenerateCardsCrossGeometry(VtValue* topo, VtValue* points,
171  GfRange3d const& extents, uint8_t axes_mask) const;
172 
173  // Generate geometry for "cards" draw mode, with cardGeometry "box".
174  void _GenerateCardsBoxGeometry(VtValue* topo, VtValue* points,
175  GfRange3d const& extents, uint8_t axes_mask) const;
176 
177  // Generate geometry for "cards" draw mode, with cardGeometry "fromTexture".
178  void _GenerateCardsFromTextureGeometry(VtValue* topo, VtValue* points,
179  VtValue* uv, VtValue* assign, GfRange3d* extents,
180  UsdPrim const& prim) const;
181 
182  // Given an asset attribute pointing to a texture, pull the "worldtoscreen"
183  // matrix out of image metadata.
184  bool _GetMatrixFromImageMetadata(UsdAttribute const& attr, GfMatrix4d* mat)
185  const;
186 
187  // Generate texture coordinates for cards "cross"/"box" mode.
188  void _GenerateTextureCoordinates(VtValue* uv, VtValue* assign,
189  uint8_t axes_mask) const;
190 
191  // Map from cachePath to what drawMode it was populated as.
192  typedef TfHashMap<SdfPath, TfToken, SdfPath::Hash>
193  _DrawModeMap;
194  _DrawModeMap _drawModeMap;
195 };
196 
197 
198 PXR_NAMESPACE_CLOSE_SCOPE
199 
200 #endif // USDIMAGINGGL_DRAW_MODE_ADAPTER_H
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
virtual bool IsSupported(UsdImagingIndexProxy const *index) const override
Returns true if the adapter can be populated into the target index.
virtual USDIMAGINGGL_API HdDirtyBits ProcessPropertyChange(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &property) override
Returns a bit mask of attributes to be updated, or HdChangeTracker::AllDirty if the entire prim must ...
virtual USDIMAGINGGL_API void UpdateForTime(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, HdDirtyBits requestedBits, UsdImagingInstancerContext const *instancerContext=NULL) const override
Populates the cache for the given prim, time and requestedBits.
This proxy class exposes a subset of the private Delegate API to PrimAdapters.
Definition: indexProxy.h:47
Scenegraph object for authoring and retrieving numeric, string, and array valued data, sampled over time.
Definition: attribute.h:176
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
Base class for all PrimAdapters.
Definition: primAdapter.h:67
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
virtual USDIMAGINGGL_API void TrackVariability(UsdPrim const &prim, SdfPath const &cachePath, HdDirtyBits *timeVaryingBits, UsdImagingInstancerContext const *instancerContext=NULL) const override
For the given prim, variability is detected and stored in timeVaryingBits.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
virtual SdfPath Populate(UsdPrim const &prim, UsdImagingIndexProxy *index, UsdImagingInstancerContext const *instancerContext=NULL) override
Called to populate the RenderIndex for this UsdPrim.
Object used by instancer prim adapters to pass along context about the instancer and instance prim to...
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182
Delegate support for the drawMode attribute on UsdGeomModelAPI.