HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sceneIndexPluginRegistry.h
Go to the documentation of this file.
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"
11 #include "pxr/base/tf/singleton.h"
14 #include "pxr/imaging/hd/api.h"
16 
18 
19 #define HDSCENEINDEXPLUGINREGISTRY_TOKENS \
20  ((rendererDisplayName, "__rendererDisplayName")) \
21 
22 
23 TF_DECLARE_PUBLIC_TOKENS(HdSceneIndexPluginRegistryTokens, HD_API,
25 
26 
27 
28 class HdSceneIndexPlugin;
29 
31 {
32 public:
33  ///
34  /// Returns the singleton registry for \c HdSceneIndexPlugin
35  ///
36  HD_API
38 
39  ///
40  /// Entry point for defining an HdSceneIndexPlugin plugin.
41  ///
42  template<typename T, typename... Bases>
43  static void Define();
44 
45  ///
46  /// Given a specific scene index plug-in id, give the plug-in a chance
47  /// to add scene indices to the end of the chain. Return value is the
48  /// last scene index -- or inputScene if the plug-in chooses not to act.
49  /// Input arguments may be nullptr if not relevant to this plug-in.
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 
57  ///
58  /// Append scene indices generated by plug-ins registered (via
59  /// RegisterSceneIndexForRenderer) for this renderer. Return value is the
60  /// last scene index -- or inputScene if no plugins are registered or
61  /// taking action. This also includes plug-ins registered for all
62  /// renderers (via an empty rendererDisplayName) to be added in advance
63  /// of any registered for the specified renderer.
64  ///
65  /// Plugin libraries will only be loaded if they declare they are enabled
66  /// for the provided app name. By default, plugins are auto-loaded for all
67  /// apps, but plugin authors can put an preloadInApps array in their
68  /// plugInfo to narrow down the set of applications they are auto-loaded
69  /// for. Providing an empty app name here (the default) means this will not
70  /// auto-load any application-specific plugin libraries.
71  ///
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 
80  {
83  };
84 
86 
87  ///
88  /// Register a scene index to be instantiated for a specified
89  /// renderer (or all renderers if rendererDisplayName is empty).
90  ///
91  /// Insertion phase is a broad ordering value with lower values indicating
92  /// earlier instantiation (possibly given render plugin-specific meaning
93  /// via enum values). Insertion order indicates whether this entry
94  /// should go at the start or end of the specified phase.
95  HD_API
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 
111  ///
112  /// Register a scene index to be instantiated via a callback for a
113  /// specified renderer (or all renderers if rendererDisplayName is empty).
114  ///
115  /// This is most useful for application-specific behavior which wants to
116  /// append and manage scene index instances associated with a specific
117  /// render. To aid in that association, the callback is provided a
118  /// renderInstanceId value typically defined by the application itself.
119  ///
120  /// Insertion phase is a broad ordering value with lower values indicating
121  /// earlier instantiation (possibly given render plugin-specific meaning
122  /// via enum values). Insertion order indicates whether this entry
123  /// should go at the start or end of the specified phase.
124  ///
125  /// \note This method should be invoked *before* render index construction
126  /// when Hydra scene index emulation is enabled.
127  ///
128  HD_API
130  const std::string &rendererDisplayName,
131  SceneIndexAppendCallback callback,
132  const HdContainerDataSourceHandle &inputArgs,
133  InsertionPhase insertionPhase,
134  InsertionOrder insertionOrder);
135 
136 
137 
138 protected:
139 
141  const PlugRegistry &plugRegistry, const TfType &pluginType) override;
142 
143 private:
145 
146  // Singleton gets private constructed
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 
203 template<typename T, typename... Bases>
205 {
207 }
208 
210 
211 #endif // PXR_IMAGING_HD_SCENE_INDEX_PLUGIN_REGISTRY_H
void _CollectAdditionalMetadata(const PlugRegistry &plugRegistry, const TfType &pluginType) override
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
HD_API HdSceneIndexBaseRefPtr AppendSceneIndicesForRenderer(const std::string &rendererDisplayName, const HdSceneIndexBaseRefPtr &inputScene, const std::string &renderInstanceId=std::string(), const std::string &appName=std::string())
#define HD_API
Definition: api.h:23
std::function< HdSceneIndexBaseRefPtr(const std::string &renderInstanceId, const HdSceneIndexBaseRefPtr &inputScene, const HdContainerDataSourceHandle &inputArgs)> SceneIndexAppendCallback
HD_API HdSceneIndexBaseRefPtr AppendSceneIndex(const TfToken &sceneIndexPluginId, const HdSceneIndexBaseRefPtr &inputScene, const HdContainerDataSourceHandle &inputArgs, const std::string &renderInstanceId=std::string())
static HD_API HdSceneIndexPluginRegistry & GetInstance()
Definition: token.h:70
#define HDSCENEINDEXPLUGINREGISTRY_TOKENS
HD_API void RegisterSceneIndexForRenderer(const std::string &rendererDisplayName, const TfToken &sceneIndexPluginId, const HdContainerDataSourceHandle &inputArgs, InsertionPhase insertionPhase, InsertionOrder insertionOrder)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static void Define()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
TF_DECLARE_PUBLIC_TOKENS(HdSceneIndexPluginRegistryTokens, HD_API, HDSCENEINDEXPLUGINREGISTRY_TOKENS)
**If you just want to fire and args
Definition: thread.h:618
Definition: type.h:47