All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
context.h
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_23_0_PLUGIN_RENDERMAN_PLUGIN_HDX_PRMAN_CONTEXT_H
25 #define EXT_RMANPKG_23_0_PLUGIN_RENDERMAN_PLUGIN_HDX_PRMAN_CONTEXT_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/gf/matrix4d.h"
29 #include "pxr/imaging/hd/renderThread.h"
30 #include "hdPrman/context.h"
31 #include "framebuffer.h"
32 #include "renderBuffer.h"
33 
34 #include "Riley.h"
35 
36 #include <condition_variable>
37 #include <mutex>
38 #include <thread>
39 #include <atomic>
40 
41 class RixRiCtl;
42 
43 PXR_NAMESPACE_OPEN_SCOPE
44 
45 class SdfPath;
46 class HdSceneDelegate;
47 class HdRenderDelegate;
48 
49 // HdxPrman_InteractiveContext supports interactive rendering workflows.
50 // Specifically, this means it provides:
51 //
52 // - a built-in Riley camera used for the RenderPass
53 // - a framebuffer for returning image results
54 // - concurrent, background rendering support.
55 //
56 struct HdxPrman_InteractiveContext : public HdPrman_Context
57 {
58  // A framebuffer to hold PRMan results.
59  // The d_hydra.so renderman display driver handles updates via IPC.
60  HdxPrmanFramebuffer framebuffer;
61 
62  // The integrator to use.
63  // Updated from render pass state.
64  riley::IntegratorId integratorId;
65 
66  // The viewport camera to use.
67  // Updated from render pass state.
68  riley::CameraId cameraId;
69 
70  // Count of scene lights. Maintained by the delegate.
71  int sceneLightCount;
72 
73  HdxPrman_InteractiveContext();
74  virtual ~HdxPrman_InteractiveContext();
75  // Start connection to Renderman.
76  void Begin(HdRenderDelegate *renderDelegate);
77  // Starts riley and the thread if needed, and tells the thread render
78  void StartRender();
79  // End connection to Renderman, cancelling any ongoing render.
80  void End();
81  // Indicate whether fallback lights should be enabled.
82  void SetFallbackLightsEnabled(bool);
83 
84  // Request Riley (and the HdRenderThread) to stop.
85  void StopRender();
86 
87  // Checks whether context was successfully initialized.
88  // ie. riley was created
89  bool IsValid() const;
90 
91  // Creates displays in riley based on aovBindings vector
92  bool CreateDisplays(const HdRenderPassAovBindingVector& aovBindings);
93 
94  // Render thread for background rendering.
95  HdRenderThread renderThread;
96 
97  // Scene version counter.
98  std::atomic<int> sceneVersion;
99 
100  // Active render viewports
101  std::vector<riley::RenderView> renderViews;
102  riley::IntegratorId GetIntegrator();
103  void SetIntegrator(riley::IntegratorId integratorId);
104 
105  // Full option description
106  RtParamList _options;
107  int32_t resolution[2];
108 
109 private:
110  // Initialize things, like riley, that need to succeed
111  // in order for Begin to be called.
112  void _Initialize();
113 
114  // The fallback light. HdxPrman_RenderPass calls
115  // SetFallbackLightsEnabled() to maintain visibility
116  // of the fallback light XOR other lights in the scene.
117  riley::LightInstanceId _fallbackLight;
118  riley::LightShaderId _fallbackLightShader;
119  RtParamList _fallbackLightAttrs;
120  bool _fallbackLightEnabled;
121  bool _didBeginRiley;
122 };
123 
124 PXR_NAMESPACE_CLOSE_SCOPE
125 
126 #endif // EXT_RMANPKG_23_0_PLUGIN_RENDERMAN_PLUGIN_HDX_PRMAN_CONTEXT_H
A simple framebuffer used to receive display-driver output from PRMan.
Definition: framebuffer.h:45
Adapter class providing data exchange with the client scene graph.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
HdRenderThread is a utility that specific render delegates can choose to use depending on their needs...
Definition: renderThread.h:146