Loading...
Searching...
No Matches
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
37PXR_NAMESPACE_OPEN_SCOPE
38
39class HdChangeTracker;
40class HdRenderDelegate;
41class HdRenderParam;
42class HdSceneDelegate;
43class SdfPath;
44using HdSceneDelegatePtrVector = std::vector<HdSceneDelegate*>;
45
49template <class PrimType>
50class Hd_PrimTypeIndex {
51public:
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 HdRenderDelegate *renderDelegate);
160
163 const HdSceneDelegatePtrVector& GetSceneDelegatesForDirtyPrims();
164
165private:
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 TfTokenVector _primTypeNames;
195
196
197 // Template methods that are expected to be specialized on PrimType.
198 // These are to handle prim type specific function names on called objects.
199 static void _TrackerInsertPrim(HdChangeTracker &tracker,
200 const SdfPath &path,
201 HdDirtyBits initialDirtyState);
202
203 static void _TrackerRemovePrim(HdChangeTracker &tracker,
204 const SdfPath &path);
205
206 static HdDirtyBits _TrackerGetPrimDirtyBits(HdChangeTracker &tracker,
207 const SdfPath &path);
208
209 static void _TrackerMarkPrimClean(HdChangeTracker &tracker,
210 const SdfPath &path,
211 HdDirtyBits dirtyBits);
212
213 static PrimType *_RenderDelegateCreatePrim(HdRenderDelegate *renderDelegate,
214 const TfToken &typeId,
215 const SdfPath &primId);
216 static PrimType *_RenderDelegateCreateFallbackPrim(
217 HdRenderDelegate *renderDelegate,
218 const TfToken &typeId);
219
220 static void _RenderDelegateDestroyPrim(HdRenderDelegate *renderDelegate,
221 PrimType *prim);
222
223 // No copying
224 Hd_PrimTypeIndex(const Hd_PrimTypeIndex &) = delete;
225 Hd_PrimTypeIndex &operator =(const Hd_PrimTypeIndex &) = delete;
226};
227
228PXR_NAMESPACE_CLOSE_SCOPE
229
230#endif // PXR_IMAGING_HD_PRIM_TYPE_INDEX_H
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine.
Definition: changeTracker.h:52
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:290
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
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:457