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 PXR_IMAGING_HD_PRIM_TYPE_INDEX_H
25 #define PXR_IMAGING_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 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
39 class HdChangeTracker;
40 class HdRenderDelegate;
41 class HdRenderParam;
42 class HdSceneDelegate;
43 class SdfPath;
44 using HdSceneDelegatePtrVector = std::vector<HdSceneDelegate*>;
45 
49 template <class PrimType>
50 class Hd_PrimTypeIndex {
51 public:
52  Hd_PrimTypeIndex();
53  ~Hd_PrimTypeIndex();
54 
59  void InitPrimTypes(const TfTokenVector &primTypes);
60 
67  void Clear(HdChangeTracker &tracker, HdRenderDelegate *renderDelegate);
68 
79  void InsertPrim(const TfToken &typeId,
80  HdSceneDelegate *sceneDelegate,
81  const SdfPath &primId,
82  HdChangeTracker &tracker,
83  HdRenderDelegate *renderDelegate);
84 
90  void RemovePrim(const TfToken &typeId,
91  const SdfPath &primId,
92  HdChangeTracker &tracker,
93  HdRenderDelegate *renderDelegate);
94 
102  void RemoveSubtree(const SdfPath &root,
103  HdSceneDelegate* sceneDelegate,
104  HdChangeTracker &tracker,
105  HdRenderDelegate *renderDelegate);
106 
110  PrimType *GetPrim(const TfToken &typeId,
111  const SdfPath &primId) const;
112 
121  PrimType *GetFallbackPrim(TfToken const &typeId) const;
122 
129  void GetPrimSubtree(const TfToken &typeId,
130  const SdfPath &rootPath,
131  SdfPathVector *outPaths);
132 
141  bool CreateFallbackPrims(HdRenderDelegate *renderDelegate);
142 
148  void DestroyFallbackPrims(HdRenderDelegate *renderDelegate);
149 
157  void SyncPrims(HdChangeTracker &tracker,
158  HdRenderParam *renderParam);
159 
162  const HdSceneDelegatePtrVector& GetSceneDelegatesForDirtyPrims();
163 
164 private:
165  struct _PrimInfo {
166  HdSceneDelegate *sceneDelegate;
167  PrimType *prim;
168  };
169 
170  typedef std::unordered_map<SdfPath, _PrimInfo, SdfPath::Hash> _PrimMap;
171 
172  struct _PrimTypeEntry
173  {
174  _PrimMap primMap;
175  Hd_SortedIds primIds; // Primarily for sub-tree searching
176  PrimType *fallbackPrim;
177 
178  _PrimTypeEntry()
179  : primMap()
180  , primIds()
181  , fallbackPrim(nullptr)
182  {
183  }
184  };
185 
186  typedef std::unordered_map<TfToken, size_t, TfToken::HashFunctor> _TypeIndex;
187 
188  typedef std::vector<_PrimTypeEntry> _PrimTypeList;
189 
190  _PrimTypeList _entries;
191  _TypeIndex _index;
192  HdSceneDelegatePtrVector _dirtyPrimDelegates;
193 
194 
195  // Template methods that are expected to be specialized on PrimType.
196  // These are to handle prim type specific function names on called objects.
197  static void _TrackerInsertPrim(HdChangeTracker &tracker,
198  const SdfPath &path,
199  HdDirtyBits initialDirtyState);
200 
201  static void _TrackerRemovePrim(HdChangeTracker &tracker,
202  const SdfPath &path);
203 
204  static HdDirtyBits _TrackerGetPrimDirtyBits(HdChangeTracker &tracker,
205  const SdfPath &path);
206 
207  static void _TrackerMarkPrimClean(HdChangeTracker &tracker,
208  const SdfPath &path,
209  HdDirtyBits dirtyBits);
210 
211  static PrimType *_RenderDelegateCreatePrim(HdRenderDelegate *renderDelegate,
212  const TfToken &typeId,
213  const SdfPath &primId);
214  static PrimType *_RenderDelegateCreateFallbackPrim(
215  HdRenderDelegate *renderDelegate,
216  const TfToken &typeId);
217 
218  static void _RenderDelegateDestroyPrim(HdRenderDelegate *renderDelegate,
219  PrimType *prim);
220 
221  // No copying
222  Hd_PrimTypeIndex(const Hd_PrimTypeIndex &) = delete;
223  Hd_PrimTypeIndex &operator =(const Hd_PrimTypeIndex &) = delete;
224 };
225 
226 PXR_NAMESPACE_CLOSE_SCOPE
227 
228 #endif // PXR_IMAGING_HD_PRIM_TYPE_INDEX_H
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine...
Definition: changeTracker.h:50
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:87
Adapter class providing data exchange with the client scene graph.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...