Loading...
Searching...
No Matches
sceneIndexPluginRegistry.h
1//
2// Copyright 2021 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_SCENE_INDEX_PLUGIN_REGISTRY_H
8#define PXR_IMAGING_HD_SCENE_INDEX_PLUGIN_REGISTRY_H
9
10#include "pxr/pxr.h"
13#include "pxr/imaging/hf/pluginRegistry.h"
14#include "pxr/imaging/hd/api.h"
15#include "pxr/imaging/hd/sceneIndex.h"
16
17PXR_NAMESPACE_OPEN_SCOPE
18
19#define HDSCENEINDEXPLUGINREGISTRY_TOKENS \
20 ((rendererDisplayName, "__rendererDisplayName")) \
21
22
23TF_DECLARE_PUBLIC_TOKENS(HdSceneIndexPluginRegistryTokens, HD_API,
24 HDSCENEINDEXPLUGINREGISTRY_TOKENS);
25
26
27
28class HdSceneIndexPlugin;
29
30class HdSceneIndexPluginRegistry final : public HfPluginRegistry
31{
32public:
36 HD_API
37 static HdSceneIndexPluginRegistry &GetInstance();
38
42 template<typename T, typename... Bases>
43 static void Define();
44
50 HD_API
51 HdSceneIndexBaseRefPtr AppendSceneIndex(
52 const TfToken &sceneIndexPluginId,
53 const HdSceneIndexBaseRefPtr &inputScene,
54 const HdContainerDataSourceHandle &inputArgs,
55 const std::string &renderInstanceId=std::string());
56
72 HD_API
73 HdSceneIndexBaseRefPtr AppendSceneIndicesForRenderer(
74 const std::string &rendererDisplayName,
75 const HdSceneIndexBaseRefPtr &inputScene,
76 const std::string &renderInstanceId=std::string(),
77 const std::string &appName=std::string());
78
79 enum InsertionOrder
80 {
81 InsertionOrderAtStart,
82 InsertionOrderAtEnd,
83 };
84
85 using InsertionPhase = int;
86
127 HD_API
128 void RegisterSceneIndexForRenderer(
129 const std::string &rendererDisplayName,
130 const TfToken &sceneIndexPluginId,
131 const HdContainerDataSourceHandle &inputArgs,
132 InsertionPhase insertionPhase,
133 InsertionOrder insertionOrder);
134
135
136 using SceneIndexAppendCallback =
137 std::function<
138 HdSceneIndexBaseRefPtr(
139 const std::string &renderInstanceId,
140 const HdSceneIndexBaseRefPtr &inputScene,
141 const HdContainerDataSourceHandle &inputArgs)>;
142
175 HD_API
176 void RegisterSceneIndexForRenderer(
177 const std::string &rendererDisplayName,
178 SceneIndexAppendCallback callback,
179 const HdContainerDataSourceHandle &inputArgs,
180 InsertionPhase insertionPhase,
181 InsertionOrder insertionOrder);
182
183protected:
184
186 const PlugRegistry &plugRegistry, const TfType &pluginType) override;
187
188private:
189 friend class TfSingleton<HdSceneIndexPluginRegistry>;
190
191 // Singleton gets private constructed
192 HdSceneIndexPluginRegistry();
193 ~HdSceneIndexPluginRegistry() override;
194
195 void _LoadPluginsForRenderer(
196 const std::string &rendererDisplayName,
197 const std::string &appName);
198
199 HdSceneIndexPlugin *_GetSceneIndexPlugin(const TfToken &pluginId);
200
201 struct _Entry
202 {
203 _Entry(const TfToken &sceneIndexPluginId,
204 const HdContainerDataSourceHandle &args)
205 : sceneIndexPluginId(sceneIndexPluginId)
206 , args(args)
207 {}
208
209 _Entry(SceneIndexAppendCallback callback,
210 const HdContainerDataSourceHandle &args)
211 : args(args)
212 , callback(callback)
213 {}
214
215 TfToken sceneIndexPluginId;
216 HdContainerDataSourceHandle args;
217 SceneIndexAppendCallback callback;
218 };
219
220 using _EntryList = std::vector<_Entry>;
221 using _PhasesMap = std::map<InsertionPhase, _EntryList>;
222 using _RenderersMap = std::map<std::string, _PhasesMap>;
223
224 HdSceneIndexBaseRefPtr _AppendForPhases(
225 const HdSceneIndexBaseRefPtr &inputScene,
226 const _PhasesMap &phasesMap,
227 const HdContainerDataSourceHandle &argsUnderlay,
228 const std::string &renderInstanceId);
229
230 _RenderersMap _sceneIndicesForRenderers;
231
232 // Used to track plugins whose plugInfo entries contain "loadWithRenderer"
233 // values to load when the specified renderer or renderers are used.
234 // Loading the plug-in allows for further registration code to run when
235 // a plug-in wouldn't be loaded elsewhere.
236 using _PreloadMap = std::map<std::string, TfTokenVector>;
237 _PreloadMap _preloadsForRenderer;
238
239 // Used to track app-name-based filtering for plugin loading. If a plugin
240 // declares "preloadInApps" in its plugInfo, the plugin will appear in this
241 // map. When a plugin is in this map, its library will only be loaded if
242 // the appName provided to AppendSceneIndexes is in the list of
243 // preloadInApps for the plugin.
244 using _EnabledAppsMap = std::map<TfToken, std::set<std::string>>;
245 _EnabledAppsMap _preloadAppsForPlugins;
246};
247
248template<typename T, typename... Bases>
249void HdSceneIndexPluginRegistry::Define()
250{
251 HfPluginRegistry::Define<T, HdSceneIndexPlugin, Bases...>();
252}
253
254PXR_NAMESPACE_CLOSE_SCOPE
255
256#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:319
Manage a single instance of an object (see.
Definition: singleton.h:105
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
TfType represents a dynamic runtime type.
Definition: type.h:48
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:92