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
34{
35public:
39 HD_API
41
45 template<typename T, typename... Bases>
46 static void Define();
47
53 HD_API
54 HdSceneIndexBaseRefPtr AppendSceneIndex(
55 const TfToken &sceneIndexPluginId,
56 const HdSceneIndexBaseRefPtr &inputScene,
57 const HdContainerDataSourceHandle &inputArgs,
58 const std::string &renderInstanceId=std::string());
59
75 HD_API
76 HdSceneIndexBaseRefPtr AppendSceneIndicesForRenderer(
77 const std::string &rendererDisplayName,
78 const HdSceneIndexBaseRefPtr &inputScene,
79 const std::string &renderInstanceId=std::string(),
80 const std::string &appName=std::string());
81
82 enum InsertionOrder
83 {
84 InsertionOrderAtStart,
85 InsertionOrderAtEnd,
86 };
87
88 using InsertionPhase = int;
89
130 HD_API
132 const std::string &rendererDisplayName,
133 const TfToken &sceneIndexPluginId,
134 const HdContainerDataSourceHandle &inputArgs,
135 InsertionPhase insertionPhase,
136 InsertionOrder insertionOrder);
137
138
139 using SceneIndexAppendCallback =
140 std::function<
141 HdSceneIndexBaseRefPtr(
142 const std::string &renderInstanceId,
143 const HdSceneIndexBaseRefPtr &inputScene,
144 const HdContainerDataSourceHandle &inputArgs)>;
145
178 HD_API
180 const std::string &rendererDisplayName,
181 SceneIndexAppendCallback callback,
182 const HdContainerDataSourceHandle &inputArgs,
183 InsertionPhase insertionPhase,
184 InsertionOrder insertionOrder);
185
190 HD_API
191 std::vector<TfToken> LoadAndGetSceneIndexPluginIds(
192 const std::string& rendererDisplayName,
193 const std::string& appName);
194
195protected:
196
198 const PlugRegistry &plugRegistry, const TfType &pluginType) override;
199
200private:
202
203 // Singleton gets private constructed
206
207 void _LoadPluginsForRenderer(
208 const std::string &rendererDisplayName,
209 const std::string &appName);
210
211 HdSceneIndexPlugin *_GetSceneIndexPlugin(const TfToken &pluginId);
212
213 struct _Entry
214 {
215 _Entry(const TfToken &sceneIndexPluginId,
216 const HdContainerDataSourceHandle &args)
217 : sceneIndexPluginId(sceneIndexPluginId)
218 , args(args)
219 {}
220
221 _Entry(SceneIndexAppendCallback callback,
222 const HdContainerDataSourceHandle &args)
223 : args(args)
224 , callback(callback)
225 {}
226
227 TfToken sceneIndexPluginId;
228 HdContainerDataSourceHandle args;
229 SceneIndexAppendCallback callback;
230 };
231
232 using _EntryList = std::vector<_Entry>;
233 using _EntriesByPhasesMap = std::map<InsertionPhase, _EntryList>;
234 using _RendererEntries
235 = std::map<std::pair<InsertionPhase, InsertionOrder>, _EntryList>;
236
237 using _RenderersMap = std::map<std::string, _RendererEntries>;
238
239 static _EntriesByPhasesMap
240 _RendererEntriesToPhaseMap(const _RendererEntries& rendererEntries);
241
245 _EntriesByPhasesMap
246 _ComputeEntriesByPhasesMap(const std::string& rendererDisplayName) const;
247
248 HdSceneIndexBaseRefPtr _AppendForPhases(
249 const HdSceneIndexBaseRefPtr &inputScene,
250 const _EntriesByPhasesMap &entriesByPhases,
251 const HdContainerDataSourceHandle &argsUnderlay,
252 const std::string &renderInstanceId);
253
254 _RenderersMap _sceneIndicesForRenderers;
255
256 // Used to track plugins whose plugInfo entries contain "loadWithRenderer"
257 // values to load when the specified renderer or renderers are used.
258 // Loading the plug-in allows for further registration code to run when
259 // a plug-in wouldn't be loaded elsewhere.
260 using _PreloadMap = std::map<std::string, TfTokenVector>;
261 _PreloadMap _preloadsForRenderer;
262
263 // Used to track app-name-based filtering for plugin loading. If a plugin
264 // declares "preloadInApps" in its plugInfo, the plugin will appear in this
265 // map. When a plugin is in this map, its library will only be loaded if
266 // the appName provided to AppendSceneIndexes is in the list of
267 // preloadInApps for the plugin.
268 using _EnabledAppsMap = std::map<TfToken, std::set<std::string>>;
269 _EnabledAppsMap _preloadAppsForPlugins;
270};
271
272template<typename T, typename... Bases>
274{
275 HfPluginRegistry::Define<T, HdSceneIndexPlugin, Bases...>();
276}
277
278PXR_NAMESPACE_CLOSE_SCOPE
279
280#endif // PXR_IMAGING_HD_SCENE_INDEX_PLUGIN_REGISTRY_H
A registry for renderer- and application-specific scene indices.
static HD_API HdSceneIndexPluginRegistry & GetInstance()
Returns the singleton registry for HdSceneIndexPlugin.
HD_API HdSceneIndexBaseRefPtr AppendSceneIndicesForRenderer(const std::string &rendererDisplayName, const HdSceneIndexBaseRefPtr &inputScene, const std::string &renderInstanceId=std::string(), const std::string &appName=std::string())
Append scene indices generated by plug-ins registered (via RegisterSceneIndexForRenderer) for this re...
HD_API void RegisterSceneIndexForRenderer(const std::string &rendererDisplayName, SceneIndexAppendCallback callback, const HdContainerDataSourceHandle &inputArgs, InsertionPhase insertionPhase, InsertionOrder insertionOrder)
Register a scene index to be instantiated via a callback for a specified renderer (or all renderers i...
static void Define()
Entry point for defining an HdSceneIndexPlugin plugin.
HD_API void RegisterSceneIndexForRenderer(const std::string &rendererDisplayName, const TfToken &sceneIndexPluginId, const HdContainerDataSourceHandle &inputArgs, InsertionPhase insertionPhase, InsertionOrder insertionOrder)
Register a scene index to be instantiated for a specified renderer (or all renderers if rendererDispl...
void _CollectAdditionalMetadata(const PlugRegistry &plugRegistry, const TfType &pluginType) override
Gives subclasses an opportunity to inspect plugInfo-based metadata at the time of discovery.
HD_API std::vector< TfToken > LoadAndGetSceneIndexPluginIds(const std::string &rendererDisplayName, const std::string &appName)
Loads plugins for rendererDisplayName and appName.
HD_API HdSceneIndexBaseRefPtr AppendSceneIndex(const TfToken &sceneIndexPluginId, const HdSceneIndexBaseRefPtr &inputScene, const HdContainerDataSourceHandle &inputArgs, const std::string &renderInstanceId=std::string())
Given a specific scene index plug-in id, give the plug-in a chance to add scene indices to the end of...
Base class for registering Hydra plugins using the plug mechanism.
static void Define()
Entry point for registering a types implementation.
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