Loading...
Searching...
No Matches
primManagingSceneIndexObserver.h
Go to the documentation of this file.
1//
2// Copyright 2023 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_HDSI_PRIM_MANAGING_SCENE_INDEX_OBSERVER_H
25#define PXR_IMAGING_HDSI_PRIM_MANAGING_SCENE_INDEX_OBSERVER_H
26
28
29#include "pxr/imaging/hdsi/api.h"
30
31#include "pxr/imaging/hd/dataSource.h"
32#include "pxr/imaging/hd/sceneIndexObserver.h"
33
34PXR_NAMESPACE_OPEN_SCOPE
35
36#define HDSI_PRIM_MANAGING_SCENE_INDEX_OBSERVER_TOKENS \
37 (primFactory)
38
39TF_DECLARE_PUBLIC_TOKENS(HdsiPrimManagingSceneIndexObserverTokens, HDSI_API,
40 HDSI_PRIM_MANAGING_SCENE_INDEX_OBSERVER_TOKENS);
41
43
66 : public HdSceneIndexObserver, public TfRefBase
67{
68public:
74 {
75 public:
76 HDSI_API
77 virtual ~PrimBase();
78
79 void Dirty(
80 const DirtiedPrimEntry &entry,
82 {
83 // NVI so that we can later implement things like a
84 // mutex guarding against Dirty from several threads
85 // on the same prim.
86 _Dirty(entry, observer);
87 }
88
89 private:
90 virtual void _Dirty(
91 const DirtiedPrimEntry &entry,
92 const HdsiPrimManagingSceneIndexObserver * observer) = 0;
93 };
94 using PrimBaseHandle = std::shared_ptr<PrimBase>;
95
101 {
102 public:
103 HDSI_API
104 virtual ~PrimFactoryBase();
105 virtual PrimBaseHandle CreatePrim(
106 const AddedPrimEntry &entry,
107 const HdsiPrimManagingSceneIndexObserver * observer) = 0;
108 };
109 using PrimFactoryBaseHandle = std::shared_ptr<PrimFactoryBase>;
110
115 static HdsiPrimManagingSceneIndexObserverRefPtr New(
116 HdSceneIndexBaseRefPtr const &sceneIndex,
117 HdContainerDataSourceHandle const &inputArgs) {
118 return TfCreateRefPtr(
120 sceneIndex, inputArgs));
121 }
122
123 HDSI_API
125
128 const HdSceneIndexBaseRefPtr &GetSceneIndex() const {
129 return _sceneIndex;
130 }
131
137 HDSI_API
138 const PrimBaseHandle &GetPrim(const SdfPath &primPath) const;
139
141 template<typename PrimType>
142 std::shared_ptr<PrimType> GetTypedPrim(const SdfPath &primPath) const
143 {
144 return std::dynamic_pointer_cast<PrimType>(GetPrim(primPath));
145 }
146
147protected:
149 const HdSceneIndexBase &sender,
150 const AddedPrimEntries &entries) override;
151
153 const HdSceneIndexBase &sender,
154 const DirtiedPrimEntries &entries) override;
155
157 const HdSceneIndexBase &sender,
158 const RemovedPrimEntries &entries) override;
159
161 const HdSceneIndexBase &sender,
162 const RenamedPrimEntries &entries) override;
163
164private:
165 HDSI_API
167 HdSceneIndexBaseRefPtr const &sceneIndex,
168 HdContainerDataSourceHandle const &inputArgs);
169
170 HdSceneIndexBaseRefPtr const _sceneIndex;
171 PrimFactoryBaseHandle const _primFactory;
172
173 // _prims defined after _primFactory so that all prims
174 // are destroyed before the handle to _primFactory is
175 // released.
176 std::map<SdfPath, PrimBaseHandle> _prims;
177};
178
179PXR_NAMESPACE_CLOSE_SCOPE
180
181#endif
Abstract interface to scene data.
Definition: sceneIndex.h:65
Observer of scene data.
Base class for prims managed by the observer.
Base class for a prim factory given to the observer.
A scene index observer that turns prims in the observed scene index into instances (of RAII subclasse...
const HdSceneIndexBaseRefPtr & GetSceneIndex() const
Get observed scene index.
void PrimsRemoved(const HdSceneIndexBase &sender, const RemovedPrimEntries &entries) override
A notification indicating prims have been removed from the scene.
void PrimsRenamed(const HdSceneIndexBase &sender, const RenamedPrimEntries &entries) override
A notification indicating prims (and their descendants) have been renamed or reparented.
HDSI_API const PrimBaseHandle & GetPrim(const SdfPath &primPath) const
Get managed prim at path.
void PrimsAdded(const HdSceneIndexBase &sender, const AddedPrimEntries &entries) override
A notification indicating prims have been added to the scene.
void PrimsDirtied(const HdSceneIndexBase &sender, const DirtiedPrimEntries &entries) override
A notification indicating prim datasources have been invalidated.
std::shared_ptr< PrimType > GetTypedPrim(const SdfPath &primPath) const
Get managed prim cast to a particular type.
static HdsiPrimManagingSceneIndexObserverRefPtr New(HdSceneIndexBaseRefPtr const &sceneIndex, HdContainerDataSourceHandle const &inputArgs)
C'tor.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:73
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:75
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:98
A notice indicating a prim of a given type was added to the scene.
A notice indicating a prim was invalidated.