Loading...
Searching...
No Matches
primTypeIndex.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HD_PRIM_TYPE_INDEX_H
8#define PXR_IMAGING_HD_PRIM_TYPE_INDEX_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hd/types.h"
12#include "pxr/imaging/hd/sortedIds.h"
13#include "pxr/base/tf/token.h"
14#include "pxr/usd/sdf/path.h"
15
16#include <set>
17#include <vector>
18#include <unordered_map>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
22class HdChangeTracker;
23class HdRenderDelegate;
24class HdRenderParam;
25class HdSceneDelegate;
26class SdfPath;
27using HdSceneDelegatePtrVector = std::vector<HdSceneDelegate*>;
28
32template <class PrimType>
33class Hd_PrimTypeIndex {
34public:
35 Hd_PrimTypeIndex();
36 ~Hd_PrimTypeIndex();
37
42 void InitPrimTypes(const TfTokenVector &primTypes);
43
50 void Clear(HdChangeTracker &tracker, HdRenderDelegate *renderDelegate);
51
62 void InsertPrim(const TfToken &typeId,
63 HdSceneDelegate *sceneDelegate,
64 const SdfPath &primId,
65 HdChangeTracker &tracker,
66 HdRenderDelegate *renderDelegate);
67
73 void RemovePrim(const TfToken &typeId,
74 const SdfPath &primId,
75 HdChangeTracker &tracker,
76 HdRenderDelegate *renderDelegate);
77
85 void RemoveSubtree(const SdfPath &root,
86 HdSceneDelegate* sceneDelegate,
87 HdChangeTracker &tracker,
88 HdRenderDelegate *renderDelegate);
89
93 PrimType *GetPrim(const TfToken &typeId,
94 const SdfPath &primId) const;
95
104 PrimType *GetFallbackPrim(TfToken const &typeId) const;
105
112 void GetPrimSubtree(const TfToken &typeId,
113 const SdfPath &rootPath,
114 SdfPathVector *outPaths);
115
124 bool CreateFallbackPrims(HdRenderDelegate *renderDelegate);
125
131 void DestroyFallbackPrims(HdRenderDelegate *renderDelegate);
132
140 void SyncPrims(HdChangeTracker &tracker,
141 HdRenderParam *renderParam,
142 HdRenderDelegate *renderDelegate);
143
146 const HdSceneDelegatePtrVector& GetSceneDelegatesForDirtyPrims();
147
148private:
149 struct _PrimInfo {
150 HdSceneDelegate *sceneDelegate;
151 PrimType *prim;
152 };
153
154 typedef std::unordered_map<SdfPath, _PrimInfo, SdfPath::Hash> _PrimMap;
155
156 struct _PrimTypeEntry
157 {
158 _PrimMap primMap;
159 Hd_SortedIds primIds; // Primarily for sub-tree searching
160 PrimType *fallbackPrim;
161
162 _PrimTypeEntry()
163 : primMap()
164 , primIds()
165 , fallbackPrim(nullptr)
166 {
167 }
168 };
169
170 typedef std::unordered_map<TfToken, size_t, TfToken::HashFunctor> _TypeIndex;
171
172 typedef std::vector<_PrimTypeEntry> _PrimTypeList;
173
174 _PrimTypeList _entries;
175 _TypeIndex _index;
176 HdSceneDelegatePtrVector _dirtyPrimDelegates;
177 TfTokenVector _primTypeNames;
178
179
180 // Template methods that are expected to be specialized on PrimType.
181 // These are to handle prim type specific function names on called objects.
182 static void _TrackerInsertPrim(HdChangeTracker &tracker,
183 const SdfPath &path,
184 HdDirtyBits initialDirtyState);
185
186 static void _TrackerRemovePrim(HdChangeTracker &tracker,
187 const SdfPath &path);
188
189 static HdDirtyBits _TrackerGetPrimDirtyBits(HdChangeTracker &tracker,
190 const SdfPath &path);
191
192 static void _TrackerMarkPrimClean(HdChangeTracker &tracker,
193 const SdfPath &path,
194 HdDirtyBits dirtyBits);
195
196 static PrimType *_RenderDelegateCreatePrim(HdRenderDelegate *renderDelegate,
197 const TfToken &typeId,
198 const SdfPath &primId);
199 static PrimType *_RenderDelegateCreateFallbackPrim(
200 HdRenderDelegate *renderDelegate,
201 const TfToken &typeId);
202
203 static void _RenderDelegateDestroyPrim(HdRenderDelegate *renderDelegate,
204 PrimType *prim);
205
206 // No copying
207 Hd_PrimTypeIndex(const Hd_PrimTypeIndex &) = delete;
208 Hd_PrimTypeIndex &operator =(const Hd_PrimTypeIndex &) = delete;
209};
210
211PXR_NAMESPACE_CLOSE_SCOPE
212
213#endif // PXR_IMAGING_HD_PRIM_TYPE_INDEX_H
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine.
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
Adapter class providing data exchange with the client scene graph.
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:71
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
std::vector< TfToken > TfTokenVector
Convenience types.
Definition token.h:440