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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HD_SCENE_INDEX_PLUGIN_REGISTRY_H
25 #define PXR_IMAGING_HD_SCENE_INDEX_PLUGIN_REGISTRY_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/tf/singleton.h"
31 #include "pxr/imaging/hd/api.h"
33 
35 
36 #define HDSCENEINDEXPLUGINREGISTRY_TOKENS \
37  ((rendererDisplayName, "__rendererDisplayName")) \
38 
39 
40 TF_DECLARE_PUBLIC_TOKENS(HdSceneIndexPluginRegistryTokens, HD_API,
42 
43 
44 
45 class HdSceneIndexPlugin;
46 
48 {
49 public:
50  ///
51  /// Returns the singleton registry for \c HdSceneIndexPlugin
52  ///
53  HD_API
55 
56  ///
57  /// Entry point for defining an HdSceneIndexPlugin plugin.
58  ///
59  template<typename T, typename... Bases>
60  static void Define();
61 
62  ///
63  /// Given a specific scene index plug-in id, give the plug-in a chance
64  /// to add scene indices to the end of the chain. Return value is the
65  /// last scene index -- or inputScene if the plug-in chooses not to act.
66  /// Input arguments may be nullptr if not relevant to this plug-in.
67  HD_API
68  HdSceneIndexBaseRefPtr AppendSceneIndex(
69  const TfToken &sceneIndexPluginId,
70  const HdSceneIndexBaseRefPtr &inputScene,
71  const HdContainerDataSourceHandle &inputArgs);
72 
73  ///
74  /// Append scene indices generated by plug-ins registered (via
75  /// RegisterSceneIndexForRenderer) for this renderer. Return value is the
76  /// last scene index -- or inputScene if no plugins are registered or
77  /// taking action. This also includes plug-ins registered for all
78  /// renderers (via an empty rendererDisplayName) to be added in advance
79  /// of any registered for the specified rendeer.
80  HD_API
81  HdSceneIndexBaseRefPtr AppendSceneIndicesForRenderer(
82  const std::string &rendererDisplayName,
83  const HdSceneIndexBaseRefPtr &inputScene,
84  const std::string &renderInstanceId=std::string());
85 
87  {
90  };
91 
93 
94  ///
95  /// Register a scene index to be instantiated for a specified
96  /// renderer (or all renderers if rendererDisplayName is empty).
97  ///
98  /// Insertion phase is a broad ordering value with lower values indicating
99  /// earlier instantiation (possibly given render plugin-specific meaning
100  /// via enum values). Insertion order indicates whether this entry
101  /// should go at the start or end of the specified phase.
102  HD_API
104  const std::string &rendererDisplayName,
105  const TfToken &sceneIndexPluginId,
106  const HdContainerDataSourceHandle &inputArgs,
107  InsertionPhase insertionPhase,
108  InsertionOrder insertionOrder);
109 
110 
111  using SceneIndexAppendCallback =
112  std::function<
113  HdSceneIndexBaseRefPtr(
114  const std::string &renderInstanceId,
115  const HdSceneIndexBaseRefPtr &inputScene,
116  const HdContainerDataSourceHandle &inputArgs)>;
117 
118  ///
119  /// Register a scene index to be instantiated via a callback for a
120  /// specified renderer (or all renderers if rendererDisplayName is empty).
121  ///
122  /// This is most useful for application-specific behavior which wants to
123  /// append and manage scene index instances associated with a specific
124  /// render. To aid in that association, the callback is provided a
125  /// renderInstanceId value typically defined by the application itself.
126  ///
127  /// Insertion phase is a broad ordering value with lower values indicating
128  /// earlier instantiation (possibly given render plugin-specific meaning
129  /// via enum values). Insertion order indicates whether this entry
130  /// should go at the start or end of the specified phase.
131  ///
132  /// \note This method should be invoked *before* render index construction
133  /// when Hydra scene index emulation is enabled.
134  ///
135  HD_API
137  const std::string &rendererDisplayName,
138  SceneIndexAppendCallback callback,
139  const HdContainerDataSourceHandle &inputArgs,
140  InsertionPhase insertionPhase,
141  InsertionOrder insertionOrder);
142 
143 
144 
145 protected:
146 
148  const PlugRegistry &plugRegistry, const TfType &pluginType) override;
149 
150 private:
152 
153  // Singleton gets private constructed
155  ~HdSceneIndexPluginRegistry() override;
156 
157  HdSceneIndexPlugin *_GetSceneIndexPlugin(const TfToken &pluginId);
158 
159  struct _Entry
160  {
161  _Entry(const TfToken &sceneIndexPluginId,
162  const HdContainerDataSourceHandle &args)
163  : sceneIndexPluginId(sceneIndexPluginId)
164  , args(args)
165  {}
166 
167  _Entry(SceneIndexAppendCallback callback,
168  const HdContainerDataSourceHandle &args)
169  : args(args)
170  , callback(callback)
171  {}
172 
173  TfToken sceneIndexPluginId;
174  HdContainerDataSourceHandle args;
175  SceneIndexAppendCallback callback;
176  };
177 
178  using _EntryList = std::vector<_Entry>;
179  using _PhasesMap = std::map<InsertionPhase, _EntryList>;
180  using _RenderersMap = std::map<std::string, _PhasesMap>;
181 
182  HdSceneIndexBaseRefPtr _AppendForPhases(
183  const HdSceneIndexBaseRefPtr &inputScene,
184  const _PhasesMap &phasesMap,
185  const HdContainerDataSourceHandle &argsUnderlay,
186  const std::string &renderInstanceId);
187 
188  _RenderersMap _sceneIndicesForRenderers;
189 
190  // Used to track plugins whose plugInfo entries contain "loadWithRenderer"
191  // values to load when the specified renderer or renderers are used.
192  // Loading the plug-in allows for further registration code to run when
193  // a plug-in wouldn't be loaded elsewhere.
194  using _PreloadMap = std::map<std::string, TfTokenVector>;
195  _PreloadMap _preloadsForRenderer;
196 
197 };
198 
199 template<typename T, typename... Bases>
201 {
203 }
204 
206 
207 #endif // PXR_IMAGING_HD_SCENE_INDEX_PLUGIN_REGISTRY_H
void _CollectAdditionalMetadata(const PlugRegistry &plugRegistry, const TfType &pluginType) override
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
#define HD_API
Definition: api.h:40
std::function< HdSceneIndexBaseRefPtr(const std::string &renderInstanceId, const HdSceneIndexBaseRefPtr &inputScene, const HdContainerDataSourceHandle &inputArgs)> SceneIndexAppendCallback
static HD_API HdSceneIndexPluginRegistry & GetInstance()
Definition: token.h:87
#define HDSCENEINDEXPLUGINREGISTRY_TOKENS
HD_API HdSceneIndexBaseRefPtr AppendSceneIndicesForRenderer(const std::string &rendererDisplayName, const HdSceneIndexBaseRefPtr &inputScene, const std::string &renderInstanceId=std::string())
HD_API void RegisterSceneIndexForRenderer(const std::string &rendererDisplayName, const TfToken &sceneIndexPluginId, const HdContainerDataSourceHandle &inputArgs, InsertionPhase insertionPhase, InsertionOrder insertionOrder)
HD_API HdSceneIndexBaseRefPtr AppendSceneIndex(const TfToken &sceneIndexPluginId, const HdSceneIndexBaseRefPtr &inputScene, const HdContainerDataSourceHandle &inputArgs)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
static void Define()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
TF_DECLARE_PUBLIC_TOKENS(HdSceneIndexPluginRegistryTokens, HD_API, HDSCENEINDEXPLUGINREGISTRY_TOKENS)
**If you just want to fire and args
Definition: thread.h:609
Definition: type.h:64