HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rendererPlugin.h
Go to the documentation of this file.
1 //
2 // Copyright 2017 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_RENDERER_PLUGIN_H
8 #define PXR_IMAGING_HD_RENDERER_PLUGIN_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hd/api.h"
14 
16 
17 class HdRenderer;
22 
23 ///
24 /// This class defines a renderer plugin interface for Hydra.
25 /// A renderer plugin is a dynamically discovered and loaded at run-time using
26 /// the Plug system.
27 ///
28 /// This object has singleton behavior, in that is instantiated once per
29 /// library (managed by the plugin registry).
30 ///
31 /// The class is used to factory objects that provide delegate support
32 /// to other parts of the Hydra Ecosystem.
33 ///
35 {
36 public:
37 
38  /// \name Hydra 2.0 API
39  /// @{
40 
41  ///
42  /// Returns \c true if this renderer plugin is supported in the running
43  /// process and \c false if not.
44  ///
45  /// This gives the plugin a chance to perform some runtime checks to make
46  /// sure that the system meets minimum requirements. The
47  /// \p rendererCreateArgs parameter should conform to
48  /// HdRendererCreateArgsSchema to indicate the resources available when
49  /// making this determination.
50  ///
51  /// The \p reasonWhyNot param, when provided, can be filled with the reason
52  /// why the renderer plugin is not supported.
53  HD_API
54  virtual bool IsSupported(
55  HdContainerDataSourceHandle const &rendererCreateArgs,
56  std::string *reasonWhyNot = nullptr) const;
57 
58  ///
59 
60  ///
61  /// Arguments that an application should pass as input arguments to
62  /// scene indices so that they can be configured for the needs of the
63  /// renderer.
64  ///
65  /// Follows the HdSceneIndexInputArgsSchema but can have data sources
66  /// at additional data sources.
67  ///
68  /// Example: Some scene indices are computing samples for motion blur
69  /// non-lazy and need to know whether the renderer supports motion blur
70  /// in advance.
71  ///
72  /// Example: the configuration of the HdRenderIndexAdapterSceneIndex
73  /// used by the legacy UsdImagingDelegate which needs the preference
74  /// order of the material render contexts since it is resolving
75  /// which material network to use rather than leaving it to a renderer-
76  /// specific plugin scene index.
77  ///
78  HD_API
79  virtual
80  HdContainerDataSourceHandle GetSceneIndexInputArgs() const;
81 
82  ///
83  /// Create renderer through the plugin and wrap it in a handle that
84  /// keeps this plugin alive until the renderer is destroyed.
85  ///
86  /// The renderer is populated from the given scene index.
87  /// rendererCreateArgs should conform to HdRendererCreateArgsSchema.
88  ///
89  /// Note that for a seamless transition, this Hydra 2.0 method
90  /// falls back to creating a Hydra 1.0 render delegate and the
91  /// necessary "back-end" emulation for render
92  /// plugins that do not implement the Hydra 2.0
93  /// _CreateRenderer.
94  ///
95  HD_API
97  HdSceneIndexBaseRefPtr const &sceneIndex,
98  HdContainerDataSourceHandle const &rendererCreateArgs);
99 
100  /// @}
101 
102  ///
103  /// Look-up plugin id in plugin registry.
104  ///
105  HD_API
106  TfToken GetPluginId() const;
107 
108  ///
109  /// Look-up display name in plugin registry.
110  ///
111  HD_API
112  std::string GetDisplayName() const;
113 
114  /// \name Hydra 1.0 API
115  /// @{
116 
117  ///
118  /// Returns \c true if this renderer plugin is supported in the running
119  /// process and \c false if not.
120  ///
121  /// This gives the plugin a chance to perform some runtime checks to make
122  /// sure that the system meets minimum requirements. The
123  /// \p rendererCreateArgs parameter indicates the resources available when
124  /// making this determination.
125  ///
126  /// The \p reasonWhyNot param, when provided, can be filled with the reason
127  /// why the renderer plugin is not supported.
128  virtual bool IsSupported(
129  HdRendererCreateArgs const &rendererCreateArgs,
130  std::string *reasonWhyNot = nullptr) const = 0;
131 
132  ///
133  /// Create a render delegate through the plugin and wrap it in a
134  /// handle that keeps this plugin alive until render delegate is
135  /// destroyed. Initial settings can be passed in.
136  ///
137  HD_API
139  HdRenderSettingsMap const &settingsMap = {});
140  ///
141  /// Clients should use CreateDelegate since this method
142  /// will eventually become protected, use CreateRenderDelegateHandle
143  /// instead.
144  ///
145  /// Factory a Render Delegate object, that Hydra can use to
146  /// factory prims and communicate with a renderer.
147  ///
148  virtual HdRenderDelegate *CreateRenderDelegate() = 0;
149 
150  ///
151  /// Clients should use CreateDelegate since this method
152  /// will eventually become protected.
153  ///
154  /// Factory a Render Delegate object, that Hydra can use to
155  /// factory prims and communicate with a renderer. Pass in initial
156  /// settings...
157  ///
158  HD_API
160  HdRenderSettingsMap const& settingsMap);
161 
162  ///
163  /// Clients should use CreateDelegate since this method
164  /// will eventually become protected.
165  ///
166  /// Release the object factoried by CreateRenderDelegate().
167  ///
168  virtual void DeleteRenderDelegate(HdRenderDelegate *renderDelegate) = 0;
169 
170  /// @}
171 
172  ///
173  /// \deprecated Use IsSupported overload below.
174  ///
175  /// Returns \c true if this renderer plugin is supported in the running
176  /// process and \c false if not.
177  ///
178  /// This gives the plugin a chance to perform some runtime checks to make
179  /// sure that the system meets minimum requirements. The \p gpuEnabled
180  /// parameter indicates if the GPU is available for use by the plugin in
181  /// case this information is necessary to make this determination.
182  ///
183  HD_API
184  virtual bool IsSupported(bool gpuEnabled = true) const;
185 
186 protected:
187  HdRendererPlugin() = default;
188  HD_API
189  ~HdRendererPlugin() override;
190 
191  HD_API
192  virtual std::unique_ptr<HdRenderer> _CreateRenderer(
193  HdSceneIndexBaseRefPtr const &sceneIndex,
194  HdContainerDataSourceHandle const &rendererCreateArgs);
195 
196  // Instantiates render delegate and uses "back-end" emulation.
197  HD_API
198  std::unique_ptr<HdRenderer> _CreateRendererFromRenderDelegate(
199  HdSceneIndexBaseRefPtr const &sceneIndex,
200  HdContainerDataSourceHandle const &rendererCreateArgs);
201 
202 private:
203  // This class doesn't require copy support.
204  HdRendererPlugin(const HdRendererPlugin &) = delete;
205  HdRendererPlugin &operator =(const HdRendererPlugin &) = delete;
206 
207 };
208 
209 
211 
212 #endif // PXR_IMAGING_HD_RENDERER_PLUGIN_H
HdRendererPlugin()=default
HD_API TfToken GetPluginId() const
HD_API HdPluginRendererUniqueHandle CreateRenderer(HdSceneIndexBaseRefPtr const &sceneIndex, HdContainerDataSourceHandle const &rendererCreateArgs)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
HD_API ~HdRendererPlugin() override
#define HD_API
Definition: api.h:23
virtual HD_API bool IsSupported(HdContainerDataSourceHandle const &rendererCreateArgs, std::string *reasonWhyNot=nullptr) const
virtual HD_API std::unique_ptr< HdRenderer > _CreateRenderer(HdSceneIndexBaseRefPtr const &sceneIndex, HdContainerDataSourceHandle const &rendererCreateArgs)
Definition: token.h:70
virtual void DeleteRenderDelegate(HdRenderDelegate *renderDelegate)=0
HD_API HdPluginRenderDelegateUniqueHandle CreateDelegate(HdRenderSettingsMap const &settingsMap={})
HD_API std::string GetDisplayName() const
virtual HD_API HdContainerDataSourceHandle GetSceneIndexInputArgs() const
TF_DECLARE_REF_PTRS(HdSceneIndexBase)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HD_API std::unique_ptr< HdRenderer > _CreateRendererFromRenderDelegate(HdSceneIndexBaseRefPtr const &sceneIndex, HdContainerDataSourceHandle const &rendererCreateArgs)
virtual HdRenderDelegate * CreateRenderDelegate()=0