1 //
2 // Copyright 2017 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 #ifndef PXR_IMAGING_HD_ST_RENDER_DELEGATE_H
24 #define PXR_IMAGING_HD_ST_RENDER_DELEGATE_H
25 
26 #include "pxr/pxr.h"
27 #include "pxr/imaging/hdSt/api.h"
28 #include "pxr/imaging/hd/renderDelegate.h"
29 
30 #include <memory>
31 #include <mutex>
32 
33 PXR_NAMESPACE_OPEN_SCOPE
34 
35 class Hgi;
36 class HdStRenderParam;
37 using HdStDrawItemsCacheUniquePtr =
38     std::unique_ptr<class HdSt_DrawItemsCache>;
39 using HdStDrawItemsCachePtr = HdSt_DrawItemsCache *;
40 
41 using HdStResourceRegistrySharedPtr =
42     std::shared_ptr<class HdStResourceRegistry>;
43 
44 ///
45 /// HdStRenderDelegate
46 ///
47 /// The Storm Render Delegate provides a rasterizer renderer to draw the scene.
48 /// While it currently has some ties to GL, the goal is to use Hgi to allow
49 /// it to be graphics API agnostic.
50 ///
51 class HdStRenderDelegate final : public HdRenderDelegate {
52 public:
53     HDST_API
54     HdStRenderDelegate();
55     HDST_API
56     HdStRenderDelegate(HdRenderSettingsMap const& settingsMap);
57 
58     HDST_API
59     virtual ~HdStRenderDelegate();
60 
61     // ---------------------------------------------------------------------- //
62     /// \name HdRenderDelegate virtual API
63     // ---------------------------------------------------------------------- //
64 
65     HDST_API
66     virtual void SetDrivers(HdDriverVector const& drivers) override;
67 
68     HDST_API
69     virtual HdRenderParam *GetRenderParam() const override;
70 
71     HDST_API
72     virtual const TfTokenVector &GetSupportedRprimTypes() const override;
73     HDST_API
74     virtual const TfTokenVector &GetSupportedSprimTypes() const override;
75     HDST_API
76     virtual const TfTokenVector &GetSupportedBprimTypes() const override;
77     HDST_API
78     virtual HdResourceRegistrySharedPtr GetResourceRegistry() const override;
79 
80     HDST_API
81     virtual HdRenderPassSharedPtr CreateRenderPass(HdRenderIndex *index,
82                 HdRprimCollection const& collection) override;
83     HDST_API
84     virtual HdRenderPassStateSharedPtr CreateRenderPassState() const override;
85 
86     HDST_API
87     virtual HdInstancer *CreateInstancer(HdSceneDelegate *delegate,
88                                          SdfPath const& id) override;
89 
90     HDST_API
91     virtual void DestroyInstancer(HdInstancer *instancer) override;
92 
93     HDST_API
94     virtual HdRprim *CreateRprim(TfToken const& typeId,
95                                  SdfPath const& rprimId) override;
96     HDST_API
97     virtual void DestroyRprim(HdRprim *rPrim) override;
98 
99     HDST_API
100     virtual HdSprim *CreateSprim(TfToken const& typeId,
101                                  SdfPath const& sprimId) override;
102     HDST_API
103     virtual HdSprim *CreateFallbackSprim(TfToken const& typeId) override;
104     HDST_API
105     virtual void DestroySprim(HdSprim *sPrim) override;
106 
107     HDST_API
108     virtual HdBprim *CreateBprim(TfToken const& typeId,
109                                  SdfPath const& bprimId) override;
110     HDST_API
111     virtual HdBprim *CreateFallbackBprim(TfToken const& typeId) override;
112     HDST_API
113     virtual void DestroyBprim(HdBprim *bPrim) override;
114 
115     HDST_API
116     virtual void CommitResources(HdChangeTracker *tracker) override;
117 
118     HDST_API
119     virtual TfTokenVector GetMaterialRenderContexts() const override;
120 
121     HDST_API
122     virtual TfTokenVector GetShaderSourceTypes() const override;
123 
124     HDST_API
125     virtual bool IsPrimvarFilteringNeeded() const override;
126 
127     HDST_API
128     virtual HdRenderSettingDescriptorList
129         GetRenderSettingDescriptors() const override;
130 
131     HDST_API
132     virtual VtDictionary GetRenderStats() const override;
133 
134     HDST_API
135     virtual HdAovDescriptor
136         GetDefaultAovDescriptor(TfToken const& name) const override;
137 
138     // ---------------------------------------------------------------------- //
139     /// \name Misc public API
140     // ---------------------------------------------------------------------- //
141 
142     // Returns whether or not HdStRenderDelegate can run on the current
143     // hardware.
144     HDST_API
145     static bool IsSupported();
146 
147     // Returns a raw pointer to the draw items cache owned (solely) by the
148     // render delegate.
149     HDST_API
150     HdStDrawItemsCachePtr GetDrawItemsCache() const;
151 
152     // Returns Hydra graphics interface
153     HDST_API
154     Hgi* GetHgi();
155 
156 private:
157     void _ApplyTextureSettings();
158     HdSprim *_CreateFallbackMaterialPrim();
159 
160     HdStRenderDelegate(const HdStRenderDelegate &)             = delete;
161     HdStRenderDelegate &operator =(const HdStRenderDelegate &) = delete;
162 
163     static const TfTokenVector SUPPORTED_RPRIM_TYPES;
164     static const TfTokenVector SUPPORTED_SPRIM_TYPES;
165 
166     // Resource registry used in this render delegate
167     HdStResourceRegistrySharedPtr _resourceRegistry;
168 
169     HdRenderSettingDescriptorList _settingDescriptors;
170 
171     Hgi* _hgi;
172 
173     std::unique_ptr<HdStRenderParam> _renderParam;
174 
175     HdStDrawItemsCacheUniquePtr _drawItemsCache;
176 };
177 
178 
179 PXR_NAMESPACE_CLOSE_SCOPE
180 
181 #endif // PXR_IMAGING_HD_ST_RENDER_DELEGATE_H
182