HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sceneIndexPlugin.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_H
8 #define PXR_IMAGING_HD_SCENE_INDEX_PLUGIN_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hd/api.h"
14 
16 
17 /// A scene index plugin bundles one or more (typically filtering) scene indices
18 /// together and enables their runtime discovery and participation in the
19 /// scene index graph construction process.
20 ///
21 /// Scene index plugins leverage the Plug system and are required to have a
22 /// corresponding entry in the plugInfo.json file in the library directory they
23 /// are housed in. They are managed by the HdSceneIndexPluginRegistry.
24 ///
25 /// The JSON entry for a scene index plugin should have the following structure:
26 ///
27 /// \code
28 /// "MySceneIndexPlugin": {
29 /// "bases": ["HdSceneIndexPlugin"],
30 ///
31 /// # Mandatory fields for "hydra plugins" due to HfPluginRegistry.
32 /// "displayName": "My Awesome Plugin", # Unused currently.
33 /// "priority": 0, # Not relevant for scene index plugins.
34 ///
35 /// # Filtering fields that specify which renderers and apps the plugin
36 /// # is relevant for. The empty string "" indicates "all".
37 /// #
38 /// "loadWithRenderer": ["rendererA", "rendererB"], # Mandatory.
39 /// "loadWithApps": ["appA", "appB"], # Optional, defaults to "" (all).
40 ///
41 /// # Fields that specify tags and tag-based ordering constraints for the
42 /// # plugin. These fields provide an alternative and improvement to the
43 /// # insertion phase/order based constraints of the C++ registration API.
44 /// # These constraints are considered when the ordering policy used by the
45 /// # HdSceneIndexPluginRegistry is "Hybrid" or "JsonMetadataOnly".
46 ///
47 /// "tags": ["tagA", "tagB"], # Optional. The plugin typename serves as an
48 /// # implicit tag.
49 /// "ordering": { # Optional.
50 ///
51 /// # Tags or plugin typenames that this plugin should be ordered after.
52 /// "after": ["PluginTypeName1", "Tag3"],
53 ///
54 /// # Tags or plugin typenames that this plugin should be ordered before.
55 /// "before": ["PluginTypeName2", "Tag4"],
56 ///
57 /// # The tags above partition the plugins into three groups (indicated
58 /// # by [] below):
59 /// # [afterTags] -> [... -> "MySceneIndexPlugin" -> ...] -> [beforeTags]
60 /// # The insertion position specifies the ordering of this plugin
61 /// # within the middle group of plugins, with the options:
62 /// # - "firstAfter": insert as early as possible, after the afterTags.
63 /// # - "lastBefore": insert as late as possible, before the beforeTags.
64 /// # - "doesNotMatter": insert in any position within the middle group.
65 /// # The default is "doesNotMatter".
66 /// "position": "firstAfter"
67 /// }
68 /// }
69 ///
70 /// \endcode
71 ///
72 /// \sa HdSceneIndexPluginRegistry
73 /// \sa HdSceneIndexPluginRegistry::PluginOrderingPolicy
74 /// \sa HdSceneIndexPluginRegistry::RegisterSceneIndexForRenderer
75 ///
77 {
78 public:
79 
80  HD_API
81  HdSceneIndexBaseRefPtr AppendSceneIndex(
82  const std::string &renderInstanceId,
83  const HdSceneIndexBaseRefPtr &inputScene,
84  const HdContainerDataSourceHandle &inputArgs);
85 
86  /// Returns true if the plugin is enabled, in the sense that it should be
87  /// consulted for its contribution to the scene index chain via
88  /// AppendSceneIndex.
89  ///
90  /// Current implementation simply delegates to _IsEnabled; this may change
91  /// in the future to first consult inputArgs (e.g. to check a data source
92  /// that provides the plugin IDs to disable) before calling _IsEnabled.
93  ///
94  /// \sa HdSceneIndexPluginRegistry::AppendSceneIndex.
95  ///
96  HD_API
97  bool IsEnabled(
98  const HdContainerDataSourceHandle &inputArgs) const;
99 
100 protected:
101 
102  /// Subclasses implement this to instantiate one or more scene indicies
103  /// which take the provided scene as input. The return value should be
104  /// the final scene created -- or the inputScene itself if nothing is
105  /// created.
106  HD_API
107  virtual HdSceneIndexBaseRefPtr _AppendSceneIndex(
108  const HdSceneIndexBaseRefPtr &inputScene,
109  const HdContainerDataSourceHandle &inputArgs);
110 
111  /// Subclasses implement this to instantiate one or more scene indicies
112  /// which take the provided scene as input. The return value should be
113  /// the final scene created -- or the inputScene itself if nothing is
114  /// created.
115  ///
116  /// Callers can override this method if they want to get the render
117  /// instance ID in addition to the input scene and arguments. Callers
118  /// should only override one of the two _AppendSceneIndex overrides: if
119  /// both are overridden, only this override will be called.
120  ///
121  HD_API
122  virtual HdSceneIndexBaseRefPtr _AppendSceneIndex(
123  const std::string &renderInstanceId,
124  const HdSceneIndexBaseRefPtr &inputScene,
125  const HdContainerDataSourceHandle &inputArgs);
126 
127  /// Subclasses implement this to indicate whether the plugin is enabled.
128  /// This is preferable to using env guards to gate registration and
129  /// scene index instatiation in _AppendSceneIndex.
130  ///
131  /// Base implementation returns true.
132  HD_API
133  virtual bool _IsEnabled(
134  const HdContainerDataSourceHandle &inputArgs) const;
135 
136  HdSceneIndexPlugin() = default;
137  HD_API
138  ~HdSceneIndexPlugin() override;
139 
140 };
141 
143 
144 #endif // PXR_IMAGING_HD_SCENE_INDEX_PLUGIN_H
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
HD_API ~HdSceneIndexPlugin() override
virtual HD_API bool _IsEnabled(const HdContainerDataSourceHandle &inputArgs) const
#define HD_API
Definition: api.h:23
virtual HD_API HdSceneIndexBaseRefPtr _AppendSceneIndex(const HdSceneIndexBaseRefPtr &inputScene, const HdContainerDataSourceHandle &inputArgs)
HdSceneIndexPlugin()=default
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HD_API HdSceneIndexBaseRefPtr AppendSceneIndex(const std::string &renderInstanceId, const HdSceneIndexBaseRefPtr &inputScene, const HdContainerDataSourceHandle &inputArgs)
HD_API bool IsEnabled(const HdContainerDataSourceHandle &inputArgs) const