sceneIndexPluginRegistry.h
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"
30 #include "pxr/imaging/hf/pluginRegistry.h"
31 #include "pxr/imaging/hd/api.h"
32 #include "pxr/imaging/hd/sceneIndex.h"
33 
34 PXR_NAMESPACE_OPEN_SCOPE
35 
36 #define HDSCENEINDEXPLUGINREGISTRY_TOKENS \
37  ((rendererDisplayName, "__rendererDisplayName")) \
38 
39 
40 TF_DECLARE_PUBLIC_TOKENS(HdSceneIndexPluginRegistryTokens, HD_API,
41  HDSCENEINDEXPLUGINREGISTRY_TOKENS);
42 
43 
44 
45 class HdSceneIndexPlugin;
46 
47 class HdSceneIndexPluginRegistry final : public HfPluginRegistry
48 {
49 public:
53  HD_API
54  static HdSceneIndexPluginRegistry &GetInstance();
55 
59  template<typename T, typename... Bases>
60  static void Define();
61 
67  HD_API
68  HdSceneIndexBaseRefPtr AppendSceneIndex(
69  const TfToken &sceneIndexPluginId,
70  const HdSceneIndexBaseRefPtr &inputScene,
71  const HdContainerDataSourceHandle &inputArgs);
72 
80  HD_API
81  HdSceneIndexBaseRefPtr AppendSceneIndicesForRenderer(
82  const std::string &rendererDisplayName,
83  const HdSceneIndexBaseRefPtr &inputScene);
84 
85  enum InsertionOrder
86  {
87  InsertionOrderAtStart,
88  InsertionOrderAtEnd,
89  };
90 
91  using InsertionPhase = unsigned int;
92 
101  HD_API
102  void RegisterSceneIndexForRenderer(
103  const std::string &rendererDisplayName,
104  const TfToken &sceneIndexPluginId,
105  const HdContainerDataSourceHandle &inputArgs,
106  InsertionPhase insertionPhase,
107  InsertionOrder insertionOrder);
108 
109 protected:
110 
112  const PlugRegistry &plugRegistry, const TfType &pluginType) override;
113 
114 private:
115  friend class TfSingleton<HdSceneIndexPluginRegistry>;
116 
117  // Singleton gets private constructed
118  HdSceneIndexPluginRegistry();
119  ~HdSceneIndexPluginRegistry() override;
120 
121  HdSceneIndexPlugin *_GetSceneIndexPlugin(const TfToken &pluginId);
122 
123  struct _Entry
124  {
125  _Entry(const TfToken &sceneIndexPluginId,
126  const HdContainerDataSourceHandle &args)
127  : sceneIndexPluginId(sceneIndexPluginId)
128  , args(args)
129  {}
130 
131  TfToken sceneIndexPluginId;
132  HdContainerDataSourceHandle args;
133  };
134 
135  using _EntryList = std::vector<_Entry>;
136  using _PhasesMap = std::map<InsertionPhase, _EntryList>;
137  using _RenderersMap = std::map<std::string, _PhasesMap>;
138 
139  HdSceneIndexBaseRefPtr _AppendForPhases(
140  const HdSceneIndexBaseRefPtr &inputScene,
141  const _PhasesMap &phasesMap,
142  const HdContainerDataSourceHandle &argsUnderlay);
143 
144  _RenderersMap _sceneIndicesForRenderers;
145 
146  // Used to track plugins whose plugInfo entries contain "loadWithRenderer"
147  // values to load when the specified renderer or renderers are used.
148  // Loading the plug-in allows for further registration code to run when
149  // a plug-in wouldn't be loaded elsewhere.
150  using _PreloadMap = std::map<std::string, TfTokenVector>;
151  _PreloadMap _preloadsForRenderer;
152 
153 };
154 
155 template<typename T, typename... Bases>
156 void HdSceneIndexPluginRegistry::Define()
157 {
158  HfPluginRegistry::Define<T, HdSceneIndexPlugin, Bases...>();
159 }
160 
161 PXR_NAMESPACE_CLOSE_SCOPE
162 
163 #endif // PXR_IMAGING_HD_SCENE_INDEX_PLUGIN_REGISTRY_H
Manage a single instance of an object.
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.
Manage a single instance of an object (see.
Definition: singleton.h:119
Base class for registering Hydra plugins using the plug mechanism.
Defines an interface for registering plugins.
Definition: registry.h:336
static void Define()
Entry point for registering a types implementation.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
This file defines some macros that are useful for declaring and using static TfTokens.
TfType represents a dynamic runtime type.
Definition: type.h:64