HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
indexProxy.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 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_INDEX_PROXY_H
25 #define PXR_USD_IMAGING_USD_IMAGING_INDEX_PROXY_H
26 
27 /// \file usdImaging/indexProxy.h
28 
29 #include "pxr/pxr.h"
32 
33 #include "pxr/usd/sdf/path.h"
34 #include "pxr/usd/usd/prim.h"
35 
36 #include "pxr/base/tf/token.h"
37 
38 
40 
41 
42 /// \class UsdImagingIndexProxy
43 ///
44 /// This proxy class exposes a subset of the private Delegate API to
45 /// PrimAdapters.
46 ///
48 public:
49  /// A note on paths/prims: the core function of UsdImagingIndexProxy and
50  /// UsdImagingDelegate is to maintain a set of mappings between USD prims
51  /// and hydra prims (and a set of adapters that know how to translate
52  /// USD properties to hydra buffers). A USD prim can represent multiple
53  /// hydra prims (e.g. point instancer prototypes that are referenced twice),
54  /// and a hydra prim can represent multiple USD prims (e.g. a single hydra
55  /// instancer prim representing multiple native instances).
56  ///
57  /// There are three different prim "namespaces" that the delegate works
58  /// with: "USD paths", which represent paths to USD prims; "index paths",
59  /// which represent paths to hydra prims in the render index; and
60  /// "cache paths", which represent paths to buffers in the value cache
61  /// backing hydra prims. Cache paths and index paths are the same,
62  /// except that index paths have the "delegateID" prefixed onto their path.
63  ///
64  /// Index paths are only used in the interface to hydra. In IndexProxy
65  /// and the adapters, the pattern is to use "cachePath" as a key to look
66  /// up state for a hydra prim; and pass "usdPrim" when we additionally
67  /// need to specify the related USD prim. The naming helps clarify them,
68  /// and the fact that we pass a UsdPrim and not an SdfPath further ensures
69  /// that we pass valid USD paths instead of passing cache paths by mistake.
70 
71 
72  /// Adds a dependency from the given usdPrim to the given cache path.
73  /// Insert* will automatically add a dependency, so this is for hydra prims
74  /// that may depend on more than one usd prim (e.g. subsets, instancers)
76  void AddDependency(SdfPath const& cachePath,
77  UsdPrim const& usdPrim);
78 
79  /// Insert a hydra prim with the specified cache path. As mentioned above,
80  /// the delegateID will be prepended before adding the prim in hydra, but
81  /// cachePath will be the key into all internal usdImaging datastructures.
82  /// usdPrim is the USD prim this hydra prim is representing (e.g. the
83  /// UsdGeomMesh for which we are inserting a hydra mesh). If no
84  /// adapter is specified, UsdImagingDelegate will choose based on Usd
85  /// prim type; some clients (e.g. instancing) want to override the adapter
86  /// choice but this should be used sparingly.
87  ///
88  /// For Rprims and Instancers, "parentPath" is the parent instancer.
90  void InsertRprim(TfToken const& primType,
91  SdfPath const& cachePath,
92  SdfPath const& parentPath,
93  UsdPrim const& usdPrim,
96 
98  void InsertSprim(TfToken const& primType,
99  SdfPath const& cachePath,
100  UsdPrim const& usdPrim,
103 
105  void InsertBprim(TfToken const& primType,
106  SdfPath const& cachePath,
107  UsdPrim const& usdPrim,
110 
112  void InsertInstancer(SdfPath const& cachePath,
113  SdfPath const& parentPath,
114  UsdPrim const& usdPrim,
117 
118  // Mark a prim as needing follow-up work by the delegate
119  // (e.g. TrackVariability); this is automatically called on Insert*, but
120  // needs to manually be called in some special cases like native
121  // instancer population.
123  void Refresh(SdfPath const& cachePath);
124 
125  //
126  // All removals are deferred to avoid surprises during change processing.
127  //
128 
129  // Removes the Rprim at the specified cache path.
130  void RemoveRprim(SdfPath const& cachePath) {
131  _rprimsToRemove.push_back(cachePath);
132  _hdPrimInfoToRemove.push_back(cachePath);
133  _RemoveDependencies(cachePath);
134  }
135 
136  // Removes the Sprim at the specified cache path.
137  void RemoveSprim(TfToken const& primType, SdfPath const& cachePath) {
138  _TypeAndPath primToRemove = {primType, cachePath};
139  _sprimsToRemove.push_back(primToRemove);
140  _hdPrimInfoToRemove.push_back(cachePath);
141  _RemoveDependencies(cachePath);
142  }
143 
144  // Removes the Bprim at the specified cache path.
145  void RemoveBprim(TfToken const& primType, SdfPath const& cachePath) {
146  _TypeAndPath primToRemove = {primType, cachePath};
147  _bprimsToRemove.push_back(primToRemove);
148  _hdPrimInfoToRemove.push_back(cachePath);
149  _RemoveDependencies(cachePath);
150  }
151 
152  // Removes the HdInstancer at the specified cache path.
153  void RemoveInstancer(SdfPath const& cachePath) {
154  _instancersToRemove.push_back(cachePath);
155  _hdPrimInfoToRemove.push_back(cachePath);
156  _RemoveDependencies(cachePath);
157  }
158 
160  void MarkRprimDirty(SdfPath const& cachePath, HdDirtyBits dirtyBits);
161 
163  void MarkSprimDirty(SdfPath const& cachePath, HdDirtyBits dirtyBits);
164 
166  void MarkBprimDirty(SdfPath const& cachePath, HdDirtyBits dirtyBits);
167 
169  void MarkInstancerDirty(SdfPath const& cachePath, HdDirtyBits dirtyBits);
170 
172  bool IsRprimTypeSupported(TfToken const& typeId) const;
173 
175  bool IsSprimTypeSupported(TfToken const& typeId) const;
176 
178  bool IsBprimTypeSupported(TfToken const& typeId) const;
179 
180  // Check if the given path has been populated yet.
182  bool IsPopulated(SdfPath const& cachePath) const;
183 
184  // Recursively repopulate the specified usdPath into the render index.
186  void Repopulate(SdfPath const& usdPath);
187 
190  UsdPrim const& materialPrim);
191 
192 private:
193  friend class UsdImagingDelegate;
195  UsdImagingDelegate::_Worker* worker)
196  : _delegate(delegate)
197  , _worker(worker)
198  {}
199 
200  // Sort and de-duplicate "repopulate" paths to prevent double-inserts.
201  // Called by UsdImagingDelegate::ApplyPendingUpdates.
202  void _UniqueifyPathsToRepopulate();
203 
204  bool _AddHdPrimInfo(SdfPath const& cachePath,
205  UsdPrim const& usdPrim,
206  UsdImagingPrimAdapterSharedPtr const& adapter);
207 
208  // XXX: Workaround for some bugs in USD edit processing, and weird uses
209  // of HdPrimInfo by instanced prims. Remove the dependency between
210  // a hydra prim and whatever USD prim is in its primInfo.
212  void _RemovePrimInfoDependency(SdfPath const& cachePath);
213 
215  void _RemoveDependencies(SdfPath const& cachePath);
216 
217  SdfPathVector const& _GetUsdPathsToRepopulate() {
218  return _usdPathsToRepopulate;
219  }
220  void _ProcessRemovals();
221 
222  void _AddTask(SdfPath const& usdPath);
223 
224  struct _TypeAndPath {
225  TfToken primType;
226  SdfPath cachePath;
227  };
228 
229  typedef std::vector<_TypeAndPath> _TypeAndPathVector;
230 
231  typedef std::vector<UsdImagingDelegate::_DependencyMap::value_type>
232  _DependencyVector;
233 
234  UsdImagingDelegate* _delegate;
235  UsdImagingDelegate::_Worker* _worker;
236  SdfPathVector _usdPathsToRepopulate;
237  SdfPathVector _rprimsToRemove;
238  _TypeAndPathVector _sprimsToRemove;
239  _TypeAndPathVector _bprimsToRemove;
240  SdfPathVector _instancersToRemove;
241  SdfPathVector _hdPrimInfoToRemove;
242  _DependencyVector _dependenciesToRemove;
243 };
244 
245 
247 
248 #endif //PXR_USD_IMAGING_USD_IMAGING_INDEX_PROXY_H
USDIMAGING_API void Refresh(SdfPath const &cachePath)
USDIMAGING_API void InsertRprim(TfToken const &primType, SdfPath const &cachePath, SdfPath const &parentPath, UsdPrim const &usdPrim, UsdImagingPrimAdapterSharedPtr adapter=UsdImagingPrimAdapterSharedPtr())
USDIMAGING_API bool IsSprimTypeSupported(TfToken const &typeId) const
#define USDIMAGING_API
Definition: api.h:40
USDIMAGING_API void InsertSprim(TfToken const &primType, SdfPath const &cachePath, UsdPrim const &usdPrim, UsdImagingPrimAdapterSharedPtr adapter=UsdImagingPrimAdapterSharedPtr())
void RemoveInstancer(SdfPath const &cachePath)
Definition: indexProxy.h:153
uint32_t HdDirtyBits
Definition: types.h:127
USDIMAGING_API void MarkInstancerDirty(SdfPath const &cachePath, HdDirtyBits dirtyBits)
friend class UsdImagingIndexProxy
Definition: delegate.h:504
void RemoveRprim(SdfPath const &cachePath)
Definition: indexProxy.h:130
USDIMAGING_API UsdImagingPrimAdapterSharedPtr GetMaterialAdapter(UsdPrim const &materialPrim)
Definition: token.h:87
USDIMAGING_API void InsertBprim(TfToken const &primType, SdfPath const &cachePath, UsdPrim const &usdPrim, UsdImagingPrimAdapterSharedPtr adapter=UsdImagingPrimAdapterSharedPtr())
USDIMAGING_API bool IsRprimTypeSupported(TfToken const &typeId) const
Definition: prim.h:132
USDIMAGING_API void AddDependency(SdfPath const &cachePath, UsdPrim const &usdPrim)
USDIMAGING_API void InsertInstancer(SdfPath const &cachePath, SdfPath const &parentPath, UsdPrim const &usdPrim, UsdImagingPrimAdapterSharedPtr adapter=UsdImagingPrimAdapterSharedPtr())
USDIMAGING_API void MarkRprimDirty(SdfPath const &cachePath, HdDirtyBits dirtyBits)
Definition: path.h:288
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:209
void RemoveBprim(TfToken const &primType, SdfPath const &cachePath)
Definition: indexProxy.h:145
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
void RemoveSprim(TfToken const &primType, SdfPath const &cachePath)
Definition: indexProxy.h:137
USDIMAGING_API bool IsPopulated(SdfPath const &cachePath) const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
std::shared_ptr< UsdImagingPrimAdapter > UsdImagingPrimAdapterSharedPtr
USDIMAGING_API void MarkSprimDirty(SdfPath const &cachePath, HdDirtyBits dirtyBits)
USDIMAGING_API void MarkBprimDirty(SdfPath const &cachePath, HdDirtyBits dirtyBits)
USDIMAGING_API void Repopulate(SdfPath const &usdPath)
USDIMAGING_API bool IsBprimTypeSupported(TfToken const &typeId) const