1 //
2 // Copyright 2016 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 PXR_IMAGING_PLUGIN_HD_EMBREE_RENDER_PASS_H
25 #define PXR_IMAGING_PLUGIN_HD_EMBREE_RENDER_PASS_H
26 
27 #include "pxr/pxr.h"
28 
29 #include "pxr/imaging/hd/aov.h"
30 #include "pxr/imaging/hd/renderPass.h"
31 #include "pxr/imaging/hd/renderThread.h"
32 #include "pxr/imaging/plugin/hdEmbree/renderer.h"
33 #include "pxr/imaging/plugin/hdEmbree/renderBuffer.h"
34 
35 #include "pxr/base/gf/matrix4d.h"
36 #include "pxr/base/gf/rect2i.h"
37 
38 #include <atomic>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 /// \class HdEmbreeRenderPass
43 ///
44 /// HdRenderPass represents a single render iteration, rendering a view of the
45 /// scene (the HdRprimCollection) for a specific viewer (the camera/viewport
46 /// parameters in HdRenderPassState) to the current draw target.
47 ///
48 /// This class does so by raycasting into the embree scene via HdEmbreeRenderer.
49 ///
50 class HdEmbreeRenderPass final : public HdRenderPass
51 {
52 public:
53     /// Renderpass constructor.
54     ///   \param index The render index containing scene data to render.
55     ///   \param collection The initial rprim collection for this renderpass.
56     ///   \param renderThread A handle to the global render thread.
57     ///   \param renderer A handle to the global renderer.
58     HdEmbreeRenderPass(HdRenderIndex *index,
59                        HdRprimCollection const &collection,
60                        HdRenderThread *renderThread,
61                        HdEmbreeRenderer *renderer,
62                        std::atomic<int> *sceneVersion);
63 
64     /// Renderpass destructor.
65     ~HdEmbreeRenderPass() override;
66 
67     // -----------------------------------------------------------------------
68     // HdRenderPass API
69 
70     /// Determine whether the sample buffer has enough samples.
71     ///   \return True if the image has enough samples to be considered final.
72     bool IsConverged() const override;
73 
74 protected:
75 
76     // -----------------------------------------------------------------------
77     // HdRenderPass API
78 
79     /// Draw the scene with the bound renderpass state.
80     ///   \param renderPassState Input parameters (including viewer parameters)
81     ///                          for this renderpass.
82     ///   \param renderTags Which rendertags should be drawn this pass.
83     void _Execute(HdRenderPassStateSharedPtr const& renderPassState,
84                   TfTokenVector const &renderTags) override;
85 
86     /// Update internal tracking to reflect a dirty collection.
_MarkCollectionDirty()87     void _MarkCollectionDirty() override {}
88 
89 private:
90     // A handle to the render thread.
91     HdRenderThread *_renderThread;
92 
93     // A handle to the global renderer.
94     HdEmbreeRenderer *_renderer;
95 
96     // A reference to the global scene version.
97     std::atomic<int> *_sceneVersion;
98 
99     // The last scene version we rendered with.
100     int _lastSceneVersion;
101 
102     // The last settings version we rendered with.
103     int _lastSettingsVersion;
104 
105     // The pixels written to. Like viewport in OpenGL,
106     // but coordinates are y-Down.
107     GfRect2i _dataWindow;
108 
109     // The view matrix: world space to camera space
110     GfMatrix4d _viewMatrix;
111     // The projection matrix: camera space to NDC space (with
112     // respect to the data window).
113     GfMatrix4d _projMatrix;
114 
115     // The list of aov buffers this renderpass should write to.
116     HdRenderPassAovBindingVector _aovBindings;
117 
118     // If no attachments are provided, provide an anonymous renderbuffer for
119     // color and depth output.
120     HdEmbreeRenderBuffer _colorBuffer;
121     HdEmbreeRenderBuffer _depthBuffer;
122 
123     // Were the color/depth buffer converged the last time we blitted them?
124     bool _converged;
125 };
126 
127 PXR_NAMESPACE_CLOSE_SCOPE
128 
129 #endif // PXR_IMAGING_PLUGIN_HD_EMBREE_RENDER_PASS_H
130