1 // 2 // Copyright 2019 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 EXT_RMANPKG_24_0_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_RENDER_DELEGATE_H 25 #define EXT_RMANPKG_24_0_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_RENDER_DELEGATE_H 26 27 #include "pxr/pxr.h" 28 #include "pxr/imaging/hd/renderDelegate.h" 29 #include "hdPrman/api.h" 30 31 #include <mutex> 32 33 PXR_NAMESPACE_OPEN_SCOPE 34 35 class HdPrman_RenderParam; 36 class HdPrman_RenderPass; 37 struct HdPrman_Context; 38 struct HdPrman_InteractiveContext; 39 class RixParamList; 40 41 TF_DEFINE_PRIVATE_TOKENS( 42 HdPrmanRenderSettingsTokens, 43 ((integrator, "integrator")) 44 ((integratorName, "ri:integrator:name")) 45 ((interactiveIntegrator, "interactiveIntegrator")) 46 ((interactiveIntegratorTimeout, "interactiveIntegratorTimeout")) 47 ((dataWindowNDC, "dataWindowNDC")) 48 ((pixelAspectRatio, "pixelAspectRatio")) 49 ((resolution, "resolution")) 50 ((instantaneousShutter, "instantaneousShutter")) 51 ((shutterOpen, "shutter:open")) 52 ((shutterClose, "shutter:close")) 53 ); 54 55 #define HDPRMAN_INTEGRATOR_TOKENS \ 56 (PxrPathTracer) \ 57 (PbsPathTracer) \ 58 (PxrDirectLighting) 59 60 TF_DECLARE_PUBLIC_TOKENS(HdPrmanIntegratorTokens, HDPRMAN_API, 61 HDPRMAN_INTEGRATOR_TOKENS); 62 63 class HdPrmanRenderDelegate : public HdRenderDelegate 64 { 65 public: 66 HDPRMAN_API 67 HdPrmanRenderDelegate(std::shared_ptr<HdPrman_Context> context); 68 HDPRMAN_API 69 HdPrmanRenderDelegate(std::shared_ptr<HdPrman_Context> context, 70 HdRenderSettingsMap const& settingsMap); 71 HDPRMAN_API 72 virtual ~HdPrmanRenderDelegate(); 73 74 // HdRenderDelegate API implementation. 75 HDPRMAN_API 76 HdRenderParam *GetRenderParam() const override; 77 HDPRMAN_API 78 const TfTokenVector & GetSupportedRprimTypes() const override; 79 HDPRMAN_API 80 const TfTokenVector & GetSupportedSprimTypes() const override; 81 HDPRMAN_API 82 const TfTokenVector & GetSupportedBprimTypes() const override; 83 HDPRMAN_API 84 HdResourceRegistrySharedPtr GetResourceRegistry() const override; 85 86 /// Returns a list of user-configurable render settings. 87 HDPRMAN_API 88 HdRenderSettingDescriptorList GetRenderSettingDescriptors() const override; 89 90 HDPRMAN_API 91 HdRenderSettingsMap GetRenderSettingsMap() const; 92 93 HDPRMAN_API 94 HdRenderPassSharedPtr CreateRenderPass( 95 HdRenderIndex *index, 96 HdRprimCollection const& collection) override; 97 HDPRMAN_API 98 HdInstancer *CreateInstancer(HdSceneDelegate *delegate, 99 SdfPath const& id) override; 100 HDPRMAN_API 101 void DestroyInstancer(HdInstancer *instancer) override; 102 HDPRMAN_API 103 HdRprim *CreateRprim(TfToken const& typeId, 104 SdfPath const& rprimId) override; 105 HDPRMAN_API 106 void DestroyRprim(HdRprim *rPrim) override; 107 HDPRMAN_API 108 HdSprim *CreateSprim(TfToken const& typeId, 109 SdfPath const& sprimId) override; 110 HDPRMAN_API 111 HdSprim *CreateFallbackSprim(TfToken const& typeId) override; 112 HDPRMAN_API 113 void DestroySprim(HdSprim *sPrim) override; 114 HDPRMAN_API 115 HdBprim *CreateBprim(TfToken const& typeId, 116 SdfPath const& bprimId) override; 117 HDPRMAN_API 118 HdBprim *CreateFallbackBprim(TfToken const& typeId) override; 119 HDPRMAN_API 120 void DestroyBprim(HdBprim *bPrim) override; 121 122 HDPRMAN_API 123 HdAovDescriptor GetDefaultAovDescriptor(TfToken const& name) const override; 124 125 HDPRMAN_API 126 void CommitResources(HdChangeTracker *tracker) override; 127 HDPRMAN_API 128 TfToken GetMaterialBindingPurpose() const override; 129 #if HD_API_VERSION < 41 130 HDPRMAN_API 131 TfToken GetMaterialNetworkSelector() const override; 132 #else 133 HDPRMAN_API 134 TfTokenVector GetMaterialRenderContexts() const override; 135 #endif 136 HDPRMAN_API 137 TfTokenVector GetShaderSourceTypes() const override; 138 139 HDPRMAN_API 140 void SetRenderSetting(TfToken const &key, VtValue const &value) override; 141 142 /// NOTE: RenderMan has no notion of pausing the render threads. 143 /// We don't return true, because otherwise start/stop causes 144 /// the renderer to reset to increment zero, which gives a poor 145 /// user experience and poor peformance. 146 HDPRMAN_API IsPauseSupported()147 bool IsPauseSupported() const override { return false; } 148 149 /// Return true to indicate that stopping and restarting are supported. 150 HDPRMAN_API 151 bool IsStopSupported() const override; 152 153 /// Stop background rendering threads. 154 HDPRMAN_API 155 bool Stop() override; 156 157 /// Restart background rendering threads. 158 HDPRMAN_API 159 bool Restart() override; 160 161 private: 162 // This class does not support copying. 163 HdPrmanRenderDelegate(const HdPrmanRenderDelegate &) = delete; 164 HdPrmanRenderDelegate &operator =(const HdPrmanRenderDelegate &) = delete; 165 166 void _Initialize(); 167 168 enum RenderMode 169 { 170 Interactive = 0, 171 Offline 172 }; 173 RenderMode _renderMode; 174 _IsInteractive()175 bool _IsInteractive() const { 176 return (_renderMode == RenderMode::Interactive); 177 } 178 179 protected: 180 static const TfTokenVector SUPPORTED_RPRIM_TYPES; 181 static const TfTokenVector SUPPORTED_SPRIM_TYPES; 182 static const TfTokenVector SUPPORTED_BPRIM_TYPES; 183 184 std::shared_ptr<HdPrman_Context> _context; 185 std::shared_ptr<HdPrman_RenderParam> _renderParam; 186 HdResourceRegistrySharedPtr _resourceRegistry; 187 HdRenderPassSharedPtr _renderPass; 188 HdRenderSettingDescriptorList _settingDescriptors; 189 }; 190 191 PXR_NAMESPACE_CLOSE_SCOPE 192 193 #endif // EXT_RMANPKG_24_0_PLUGIN_RENDERMAN_PLUGIN_HD_PRMAN_RENDER_DELEGATE_H 194