All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderBuffer.h
1 //
2 // Copyright 2018 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_BUFFER_H
25 #define PXR_IMAGING_PLUGIN_HD_EMBREE_RENDER_BUFFER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/renderBuffer.h"
29 #include "pxr/base/gf/vec2f.h"
30 #include "pxr/base/gf/vec3f.h"
31 #include "pxr/base/gf/vec4f.h"
32 
33 PXR_NAMESPACE_OPEN_SCOPE
34 
35 class HdEmbreeRenderBuffer : public HdRenderBuffer
36 {
37 public:
38  HdEmbreeRenderBuffer(SdfPath const& id);
39  ~HdEmbreeRenderBuffer();
40 
47  virtual void Sync(HdSceneDelegate *sceneDelegate,
48  HdRenderParam *renderParam,
49  HdDirtyBits *dirtyBits) override;
50 
55  virtual void Finalize(HdRenderParam *renderParam) override;
56 
65  virtual bool Allocate(GfVec3i const& dimensions,
66  HdFormat format,
67  bool multiSampled) override;
68 
71  virtual unsigned int GetWidth() const override { return _width; }
72 
75  virtual unsigned int GetHeight() const override { return _height; }
76 
79  virtual unsigned int GetDepth() const override { return 1; }
80 
83  virtual HdFormat GetFormat() const override { return _format; }
84 
87  virtual bool IsMultiSampled() const override { return _multiSampled; }
88 
93  virtual void* Map() override {
94  _mappers++;
95  return _buffer.data();
96  }
97 
99  virtual void Unmap() override {
100  _mappers--;
101  }
102 
105  virtual bool IsMapped() const override {
106  return _mappers.load() != 0;
107  }
108 
112  virtual bool IsConverged() const override {
113  return _converged.load();
114  }
115 
118  void SetConverged(bool cv) {
119  _converged.store(cv);
120  }
121 
123  virtual void Resolve() override;
124 
125  // ---------------------------------------------------------------------- //
127  // ---------------------------------------------------------------------- //
128 
136  void Write(GfVec3i const& pixel, size_t numComponents, float const* value);
137 
145  void Write(GfVec3i const& pixel, size_t numComponents, int const* value);
146 
153  void Clear(size_t numComponents, float const* value);
154 
161  void Clear(size_t numComponents, int const* value);
162 
163 private:
164  // Calculate the needed buffer size, given the allocation parameters.
165  static size_t _GetBufferSize(GfVec2i const& dims, HdFormat format);
166 
167  // Return the sample format for the given buffer format. Sample buffers
168  // are always float32 or int32, but with the same number of components
169  // as the base format.
170  static HdFormat _GetSampleFormat(HdFormat format);
171 
172  // Release any allocated resources.
173  virtual void _Deallocate() override;
174 
175  // Buffer width.
176  unsigned int _width;
177  // Buffer height.
178  unsigned int _height;
179  // Buffer format.
180  HdFormat _format;
181  // Whether the buffer is operating in multisample mode.
182  bool _multiSampled;
183 
184  // The resolved output buffer.
185  std::vector<uint8_t> _buffer;
186  // For multisampled buffers: the input write buffer.
187  std::vector<uint8_t> _sampleBuffer;
188  // For multisampled buffers: the sample count buffer.
189  std::vector<uint8_t> _sampleCount;
190 
191  // The number of callers mapping this buffer.
192  std::atomic<int> _mappers;
193  // Whether the buffer has been marked as converged.
194  std::atomic<bool> _converged;
195 };
196 
197 PXR_NAMESPACE_CLOSE_SCOPE
198 
199 #endif // PXR_IMAGING_PLUGIN_HD_EMBREE_RENDER_BUFFER_H
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
virtual void Unmap()=0
Unmap the buffer. It is no longer safe to read from the buffer.
virtual bool IsMapped() const =0
Return whether the buffer is currently mapped by anybody.
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
virtual unsigned int GetWidth() const =0
Get the buffer&#39;s width.
virtual void _Deallocate()=0
Deallocate the buffer, freeing any owned resources.
Adapter class providing data exchange with the client scene graph.
virtual HD_API void Finalize(HdRenderParam *renderParam) override
Deallocate before deletion.
virtual HdFormat GetFormat() const =0
Get the buffer&#39;s per-pixel format.
Basic type for a vector of 3 int components.
Definition: vec3i.h:61
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
virtual bool IsConverged() const =0
Return whether the buffer is converged (whether the renderer is still adding samples or not)...
virtual unsigned int GetHeight() const =0
Get the buffer&#39;s height.
virtual unsigned int GetDepth() const =0
Get the buffer&#39;s depth.
A render buffer is a handle to a data resource that can be rendered into, such as a 2d image for a dr...
Definition: renderBuffer.h:51
virtual void * Map()=0
Map the buffer for reading.
virtual bool Allocate(GfVec3i const &dimensions, HdFormat format, bool multiSampled)=0
Allocate a buffer.
virtual HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Get allocation information from the scene delegate.
virtual bool IsMultiSampled() const =0
Get whether the buffer is multisampled.
virtual void Resolve()=0
Resolve the buffer so that reads reflect the latest writes.