Loading...
Searching...
No Matches
sceneIndexPluginRegistry.h
1//
2// Copyright 2021 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_SCENE_INDEX_PLUGIN_REGISTRY_H
25#define PXR_IMAGING_HD_SCENE_INDEX_PLUGIN_REGISTRY_H
26
27#include "pxr/pxr.h"
30#include "pxr/imaging/hf/pluginRegistry.h"
31#include "pxr/imaging/hd/api.h"
32#include "pxr/imaging/hd/sceneIndex.h"
33
34PXR_NAMESPACE_OPEN_SCOPE
35
36#define HDSCENEINDEXPLUGINREGISTRY_TOKENS \
37 ((rendererDisplayName, "__rendererDisplayName")) \
38
39
40TF_DECLARE_PUBLIC_TOKENS(HdSceneIndexPluginRegistryTokens, HD_API,
41 HDSCENEINDEXPLUGINREGISTRY_TOKENS);
42
43
44
45class HdSceneIndexPlugin;
46
47class HdSceneIndexPluginRegistry final : public HfPluginRegistry
48{
49public:
53 HD_API
54 static HdSceneIndexPluginRegistry &GetInstance();
55
59 template<typename T, typename... Bases>
60 static void Define();
61
67 HD_API
68 HdSceneIndexBaseRefPtr AppendSceneIndex(
69 const TfToken &sceneIndexPluginId,
70 const HdSceneIndexBaseRefPtr &inputScene,
71 const HdContainerDataSourceHandle &inputArgs);
72
80 HD_API
81 HdSceneIndexBaseRefPtr AppendSceneIndicesForRenderer(
82 const std::string &rendererDisplayName,
83 const HdSceneIndexBaseRefPtr &inputScene,
84 const std::string &renderInstanceId=std::string());
85
86 enum InsertionOrder
87 {
88 InsertionOrderAtStart,
89 InsertionOrderAtEnd,
90 };
91
92 using InsertionPhase = int;
93
102 HD_API
103 void RegisterSceneIndexForRenderer(
104 const std::string &rendererDisplayName,
105 const TfToken &sceneIndexPluginId,
106 const HdContainerDataSourceHandle &inputArgs,
107 InsertionPhase insertionPhase,
108 InsertionOrder insertionOrder);
109
110
111 using SceneIndexAppendCallback =
112 std::function<
113 HdSceneIndexBaseRefPtr(
114 const std::string &renderInstanceId,
115 const HdSceneIndexBaseRefPtr &inputScene,
116 const HdContainerDataSourceHandle &inputArgs)>;
117
135 HD_API
136 void RegisterSceneIndexForRenderer(
137 const std::string &rendererDisplayName,
138 SceneIndexAppendCallback callback,
139 const HdContainerDataSourceHandle &inputArgs,
140 InsertionPhase insertionPhase,
141 InsertionOrder insertionOrder);
142
143
144
145protected:
146
148 const PlugRegistry &plugRegistry, const TfType &pluginType) override;
149
150private:
151 friend class TfSingleton<HdSceneIndexPluginRegistry>;
152
153 // Singleton gets private constructed
154 HdSceneIndexPluginRegistry();
155 ~HdSceneIndexPluginRegistry() override;
156
157 HdSceneIndexPlugin *_GetSceneIndexPlugin(const TfToken &pluginId);
158
159 struct _Entry
160 {
161 _Entry(const TfToken &sceneIndexPluginId,
162 const HdContainerDataSourceHandle &args)
163 : sceneIndexPluginId(sceneIndexPluginId)
164 , args(args)
165 {}
166
167 _Entry(SceneIndexAppendCallback callback,
168 const HdContainerDataSourceHandle &args)
169 : args(args)
170 , callback(callback)
171 {}
172
173 TfToken sceneIndexPluginId;
174 HdContainerDataSourceHandle args;
175 SceneIndexAppendCallback callback;
176 };
177
178 using _EntryList = std::vector<_Entry>;
179 using _PhasesMap = std::map<InsertionPhase, _EntryList>;
180 using _RenderersMap = std::map<std::string, _PhasesMap>;
181
182 HdSceneIndexBaseRefPtr _AppendForPhases(
183 const HdSceneIndexBaseRefPtr &inputScene,
184 const _PhasesMap &phasesMap,
185 const HdContainerDataSourceHandle &argsUnderlay,
186 const std::string &renderInstanceId);
187
188 _RenderersMap _sceneIndicesForRenderers;
189
190 // Used to track plugins whose plugInfo entries contain "loadWithRenderer"
191 // values to load when the specified renderer or renderers are used.
192 // Loading the plug-in allows for further registration code to run when
193 // a plug-in wouldn't be loaded elsewhere.
194 using _PreloadMap = std::map<std::string, TfTokenVector>;
195 _PreloadMap _preloadsForRenderer;
196
197};
198
199template<typename T, typename... Bases>
200void HdSceneIndexPluginRegistry::Define()
201{
202 HfPluginRegistry::Define<T, HdSceneIndexPlugin, Bases...>();
203}
204
205PXR_NAMESPACE_CLOSE_SCOPE
206
207#endif // PXR_IMAGING_HD_SCENE_INDEX_PLUGIN_REGISTRY_H
Base class for registering Hydra plugins using the plug mechanism.
static void Define()
Entry point for registering a types implementation.
virtual HF_API void _CollectAdditionalMetadata(const PlugRegistry &plugRegistry, const TfType &pluginType)
Gives subclasses an opportunity to inspect plugInfo-based metadata at the time of discovery.
Defines an interface for registering plugins.
Definition: registry.h:336
Manage a single instance of an object (see.
Definition: singleton.h:122
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
TfType represents a dynamic runtime type.
Definition: type.h:65
Manage a single instance of an object.
This file defines some macros that are useful for declaring and using static TfTokens.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:98