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
95 HD_API
96 void RegisterSceneIndexForRenderer(
97 const std::string &rendererDisplayName,
98 const TfToken &sceneIndexPluginId,
99 const HdContainerDataSourceHandle &inputArgs,
100 InsertionPhase insertionPhase,
101 InsertionOrder insertionOrder);
102
103
104 using SceneIndexAppendCallback =
105 std::function<
106 HdSceneIndexBaseRefPtr(
107 const std::string &renderInstanceId,
108 const HdSceneIndexBaseRefPtr &inputScene,
109 const HdContainerDataSourceHandle &inputArgs)>;
110
128 HD_API
129 void RegisterSceneIndexForRenderer(
130 const std::string &rendererDisplayName,
131 SceneIndexAppendCallback callback,
132 const HdContainerDataSourceHandle &inputArgs,
133 InsertionPhase insertionPhase,
134 InsertionOrder insertionOrder);
135
136
137
138protected:
139
141 const PlugRegistry &plugRegistry, const TfType &pluginType) override;
142
143private:
144 friend class TfSingleton<HdSceneIndexPluginRegistry>;
145
146 // Singleton gets private constructed
147 HdSceneIndexPluginRegistry();
148 ~HdSceneIndexPluginRegistry() override;
149
150 void _LoadPluginsForRenderer(
151 const std::string &rendererDisplayName,
152 const std::string &appName);
153
154 HdSceneIndexPlugin *_GetSceneIndexPlugin(const TfToken &pluginId);
155
156 struct _Entry
157 {
158 _Entry(const TfToken &sceneIndexPluginId,
159 const HdContainerDataSourceHandle &args)
160 : sceneIndexPluginId(sceneIndexPluginId)
161 , args(args)
162 {}
163
164 _Entry(SceneIndexAppendCallback callback,
165 const HdContainerDataSourceHandle &args)
166 : args(args)
167 , callback(callback)
168 {}
169
170 TfToken sceneIndexPluginId;
171 HdContainerDataSourceHandle args;
172 SceneIndexAppendCallback callback;
173 };
174
175 using _EntryList = std::vector<_Entry>;
176 using _PhasesMap = std::map<InsertionPhase, _EntryList>;
177 using _RenderersMap = std::map<std::string, _PhasesMap>;
178
179 HdSceneIndexBaseRefPtr _AppendForPhases(
180 const HdSceneIndexBaseRefPtr &inputScene,
181 const _PhasesMap &phasesMap,
182 const HdContainerDataSourceHandle &argsUnderlay,
183 const std::string &renderInstanceId);
184
185 _RenderersMap _sceneIndicesForRenderers;
186
187 // Used to track plugins whose plugInfo entries contain "loadWithRenderer"
188 // values to load when the specified renderer or renderers are used.
189 // Loading the plug-in allows for further registration code to run when
190 // a plug-in wouldn't be loaded elsewhere.
191 using _PreloadMap = std::map<std::string, TfTokenVector>;
192 _PreloadMap _preloadsForRenderer;
193
194 // Used to track app-name-based filtering for plugin loading. If a plugin
195 // declares "preloadInApps" in its plugInfo, the plugin will appear in this
196 // map. When a plugin is in this map, its library will only be loaded if
197 // the appName provided to AppendSceneIndexes is in the list of
198 // preloadInApps for the plugin.
199 using _EnabledAppsMap = std::map<TfToken, std::set<std::string>>;
200 _EnabledAppsMap _preloadAppsForPlugins;
201};
202
203template<typename T, typename... Bases>
204void HdSceneIndexPluginRegistry::Define()
205{
206 HfPluginRegistry::Define<T, HdSceneIndexPlugin, Bases...>();
207}
208
209PXR_NAMESPACE_CLOSE_SCOPE
210
211#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