All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
primTypeIndex.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 HD_PRIM_TYPE_INDEX_H
25 #define HD_PRIM_TYPE_INDEX_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/types.h"
29 #include "pxr/imaging/hd/sortedIds.h"
30 #include "pxr/base/tf/token.h"
31 #include "pxr/usd/sdf/path.h"
32 
33 #include <set>
34 #include <vector>
35 #include <unordered_map>
36 #include <boost/range/iterator.hpp>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
40 class HdChangeTracker;
41 class HdRenderDelegate;
42 class HdRenderParam;
43 class HdSceneDelegate;
44 class SdfPath;
45 using HdSceneDelegatePtrVector = std::vector<HdSceneDelegate*>;
46 
50 template <class PrimType>
51 class Hd_PrimTypeIndex {
52 public:
53  Hd_PrimTypeIndex();
54  ~Hd_PrimTypeIndex();
55 
60  void InitPrimTypes(const TfTokenVector &primTypes);
61 
68  void Clear(HdChangeTracker &tracker, HdRenderDelegate *renderDelegate);
69 
80  void InsertPrim(const TfToken &typeId,
81  HdSceneDelegate *sceneDelegate,
82  const SdfPath &primId,
83  HdChangeTracker &tracker,
84  HdRenderDelegate *renderDelegate);
85 
91  void RemovePrim(const TfToken &typeId,
92  const SdfPath &primId,
93  HdChangeTracker &tracker,
94  HdRenderDelegate *renderDelegate);
95 
103  void RemoveSubtree(const SdfPath &root,
104  HdSceneDelegate* sceneDelegate,
105  HdChangeTracker &tracker,
106  HdRenderDelegate *renderDelegate);
107 
111  PrimType *GetPrim(const TfToken &typeId,
112  const SdfPath &primId) const;
113 
122  PrimType *GetFallbackPrim(TfToken const &typeId) const;
123 
130  void GetPrimSubtree(const TfToken &typeId,
131  const SdfPath &rootPath,
132  SdfPathVector *outPaths);
133 
142  bool CreateFallbackPrims(HdRenderDelegate *renderDelegate);
143 
149  void DestroyFallbackPrims(HdRenderDelegate *renderDelegate);
150 
158  void SyncPrims(HdChangeTracker &tracker,
159  HdRenderParam *renderParam);
160 
163  const HdSceneDelegatePtrVector& GetSceneDelegatesForDirtyPrims();
164 
165 private:
166  struct _PrimInfo {
167  HdSceneDelegate *sceneDelegate;
168  PrimType *prim;
169  };
170 
171  typedef std::unordered_map<SdfPath, _PrimInfo, SdfPath::Hash> _PrimMap;
172 
173  struct _PrimTypeEntry
174  {
175  _PrimMap primMap;
176  Hd_SortedIds primIds; // Primarily for sub-tree searching
177  PrimType *fallbackPrim;
178 
179  _PrimTypeEntry()
180  : primMap()
181  , primIds()
182  , fallbackPrim(nullptr)
183  {
184  }
185  };
186 
187  typedef std::unordered_map<TfToken, size_t, TfToken::HashFunctor> _TypeIndex;
188 
189  typedef std::vector<_PrimTypeEntry> _PrimTypeList;
190 
191  _PrimTypeList _entries;
192  _TypeIndex _index;
193  HdSceneDelegatePtrVector _dirtyPrimDelegates;
194 
195 
196  // Template methods that are expected to be specialized on PrimType.
197  // These are to handle prim type specific function names on called objects.
198  static void _TrackerInsertPrim(HdChangeTracker &tracker,
199  const SdfPath &path,
200  HdDirtyBits initialDirtyState);
201 
202  static void _TrackerRemovePrim(HdChangeTracker &tracker,
203  const SdfPath &path);
204 
205  static HdDirtyBits _TrackerGetPrimDirtyBits(HdChangeTracker &tracker,
206  const SdfPath &path);
207 
208  static void _TrackerMarkPrimClean(HdChangeTracker &tracker,
209  const SdfPath &path,
210  HdDirtyBits dirtyBits);
211 
212  static PrimType *_RenderDelegateCreatePrim(HdRenderDelegate *renderDelegate,
213  const TfToken &typeId,
214  const SdfPath &primId);
215  static PrimType *_RenderDelegateCreateFallbackPrim(
216  HdRenderDelegate *renderDelegate,
217  const TfToken &typeId);
218 
219  static void _RenderDelegateDestroyPrim(HdRenderDelegate *renderDelegate,
220  PrimType *prim);
221 
222  // No copying
223  Hd_PrimTypeIndex(const Hd_PrimTypeIndex &) = delete;
224  Hd_PrimTypeIndex &operator =(const Hd_PrimTypeIndex &) = delete;
225 };
226 
227 PXR_NAMESPACE_CLOSE_SCOPE
228 
229 #endif // HD_PRIM_TYPE_INDEX_H
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine...
Definition: changeTracker.h:55
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Adapter class providing data exchange with the client scene graph.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:438
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287