All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
renderBuffer.h
1//
2// Copyright 2018 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_PLUGIN_HD_EMBREE_RENDER_BUFFER_H
8#define PXR_IMAGING_PLUGIN_HD_EMBREE_RENDER_BUFFER_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hd/renderBuffer.h"
12
13PXR_NAMESPACE_OPEN_SCOPE
14
15class HdEmbreeRenderBuffer : public HdRenderBuffer
16{
17public:
18 HdEmbreeRenderBuffer(SdfPath const& id);
19 ~HdEmbreeRenderBuffer() override;
20
27 void Sync(HdSceneDelegate *sceneDelegate,
28 HdRenderParam *renderParam,
29 HdDirtyBits *dirtyBits) override;
30
35 void Finalize(HdRenderParam *renderParam) override;
36
45 bool Allocate(GfVec3i const& dimensions,
46 HdFormat format,
47 bool multiSampled) override;
48
51 unsigned int GetWidth() const override { return _width; }
52
55 unsigned int GetHeight() const override { return _height; }
56
59 unsigned int GetDepth() const override { return 1; }
60
63 HdFormat GetFormat() const override { return _format; }
64
67 bool IsMultiSampled() const override { return _multiSampled; }
68
73 void* Map() override {
74 _mappers++;
75 return _buffer.data();
76 }
77
79 void Unmap() override {
80 _mappers--;
81 }
82
85 bool IsMapped() const override {
86 return _mappers.load() != 0;
87 }
88
92 bool IsConverged() const override {
93 return _converged.load();
94 }
95
98 void SetConverged(bool cv) {
99 _converged.store(cv);
100 }
101
103 void Resolve() override;
104
105 // ---------------------------------------------------------------------- //
107 // ---------------------------------------------------------------------- //
108
116 void Write(GfVec3i const& pixel, size_t numComponents, float const* value);
117
125 void Write(GfVec3i const& pixel, size_t numComponents, int const* value);
126
133 void Clear(size_t numComponents, float const* value);
134
141 void Clear(size_t numComponents, int const* value);
142
143private:
144 // Calculate the needed buffer size, given the allocation parameters.
145 static size_t _GetBufferSize(GfVec2i const& dims, HdFormat format);
146
147 // Return the sample format for the given buffer format. Sample buffers
148 // are always float32 or int32, but with the same number of components
149 // as the base format.
150 static HdFormat _GetSampleFormat(HdFormat format);
151
152 // Release any allocated resources.
153 void _Deallocate() override;
154
155 // Buffer width.
156 unsigned int _width;
157 // Buffer height.
158 unsigned int _height;
159 // Buffer format.
160 HdFormat _format;
161 // Whether the buffer is operating in multisample mode.
162 bool _multiSampled;
163
164 // The resolved output buffer.
165 std::vector<uint8_t> _buffer;
166 // For multisampled buffers: the input write buffer.
167 std::vector<uint8_t> _sampleBuffer;
168 // For multisampled buffers: the sample count buffer.
169 std::vector<uint8_t> _sampleCount;
170
171 // The number of callers mapping this buffer.
172 std::atomic<int> _mappers;
173 // Whether the buffer has been marked as converged.
174 std::atomic<bool> _converged;
175};
176
177PXR_NAMESPACE_CLOSE_SCOPE
178
179#endif // PXR_IMAGING_PLUGIN_HD_EMBREE_RENDER_BUFFER_H
Basic type for a vector of 2 int components.
Definition: vec2i.h:44
Basic type for a vector of 3 int components.
Definition: vec3i.h:44
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:33
virtual void Resolve()=0
Resolve the buffer so that reads reflect the latest writes.
virtual unsigned int GetWidth() const =0
Get the buffer's width.
virtual void * Map()=0
Map the buffer for reading.
HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Get allocation information from the scene delegate.
virtual unsigned int GetHeight() const =0
Get the buffer's height.
virtual bool IsMapped() const =0
Return whether the buffer is currently mapped by anybody.
HD_API void Finalize(HdRenderParam *renderParam) override
Deallocate before deletion.
virtual void _Deallocate()=0
Deallocate the buffer, freeing any owned resources.
virtual void Unmap()=0
Unmap the buffer. It is no longer safe to read from the buffer.
virtual unsigned int GetDepth() const =0
Get the buffer's depth.
virtual bool IsConverged() const =0
Return whether the buffer is converged (whether the renderer is still adding samples or not).
virtual HdFormat GetFormat() const =0
Get the buffer's per-pixel format.
virtual bool IsMultiSampled() const =0
Get whether the buffer is multisampled.
virtual bool Allocate(GfVec3i const &dimensions, HdFormat format, bool multiSampled)=0
Allocate a buffer.
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
Adapter class providing data exchange with the client scene graph.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274