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
63 HD_API
64 HdSceneIndexBaseRefPtr AppendSceneIndicesForRenderer(
65 const std::string &rendererDisplayName,
66 const HdSceneIndexBaseRefPtr &inputScene,
67 const std::string &renderInstanceId=std::string());
68
69 enum InsertionOrder
70 {
71 InsertionOrderAtStart,
72 InsertionOrderAtEnd,
73 };
74
75 using InsertionPhase = int;
76
85 HD_API
86 void RegisterSceneIndexForRenderer(
87 const std::string &rendererDisplayName,
88 const TfToken &sceneIndexPluginId,
89 const HdContainerDataSourceHandle &inputArgs,
90 InsertionPhase insertionPhase,
91 InsertionOrder insertionOrder);
92
93
94 using SceneIndexAppendCallback =
95 std::function<
96 HdSceneIndexBaseRefPtr(
97 const std::string &renderInstanceId,
98 const HdSceneIndexBaseRefPtr &inputScene,
99 const HdContainerDataSourceHandle &inputArgs)>;
100
118 HD_API
119 void RegisterSceneIndexForRenderer(
120 const std::string &rendererDisplayName,
121 SceneIndexAppendCallback callback,
122 const HdContainerDataSourceHandle &inputArgs,
123 InsertionPhase insertionPhase,
124 InsertionOrder insertionOrder);
125
126
127
128protected:
129
131 const PlugRegistry &plugRegistry, const TfType &pluginType) override;
132
133private:
134 friend class TfSingleton<HdSceneIndexPluginRegistry>;
135
136 // Singleton gets private constructed
137 HdSceneIndexPluginRegistry();
138 ~HdSceneIndexPluginRegistry() override;
139
140 HdSceneIndexPlugin *_GetSceneIndexPlugin(const TfToken &pluginId);
141
142 struct _Entry
143 {
144 _Entry(const TfToken &sceneIndexPluginId,
145 const HdContainerDataSourceHandle &args)
146 : sceneIndexPluginId(sceneIndexPluginId)
147 , args(args)
148 {}
149
150 _Entry(SceneIndexAppendCallback callback,
151 const HdContainerDataSourceHandle &args)
152 : args(args)
153 , callback(callback)
154 {}
155
156 TfToken sceneIndexPluginId;
157 HdContainerDataSourceHandle args;
158 SceneIndexAppendCallback callback;
159 };
160
161 using _EntryList = std::vector<_Entry>;
162 using _PhasesMap = std::map<InsertionPhase, _EntryList>;
163 using _RenderersMap = std::map<std::string, _PhasesMap>;
164
165 HdSceneIndexBaseRefPtr _AppendForPhases(
166 const HdSceneIndexBaseRefPtr &inputScene,
167 const _PhasesMap &phasesMap,
168 const HdContainerDataSourceHandle &argsUnderlay,
169 const std::string &renderInstanceId);
170
171 _RenderersMap _sceneIndicesForRenderers;
172
173 // Used to track plugins whose plugInfo entries contain "loadWithRenderer"
174 // values to load when the specified renderer or renderers are used.
175 // Loading the plug-in allows for further registration code to run when
176 // a plug-in wouldn't be loaded elsewhere.
177 using _PreloadMap = std::map<std::string, TfTokenVector>;
178 _PreloadMap _preloadsForRenderer;
179
180};
181
182template<typename T, typename... Bases>
183void HdSceneIndexPluginRegistry::Define()
184{
185 HfPluginRegistry::Define<T, HdSceneIndexPlugin, Bases...>();
186}
187
188PXR_NAMESPACE_CLOSE_SCOPE
189
190#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:81