All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderBuffer.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 HDXPRMAN_RENDERBUFFER_H
25 #define HDXPRMAN_RENDERBUFFER_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 HdxPrmanRenderBuffer : public HdRenderBuffer
36 {
37 public:
38  HdxPrmanRenderBuffer(SdfPath const& id);
39  ~HdxPrmanRenderBuffer();
40 
41  virtual bool Allocate(GfVec3i const& dimensions,
42  HdFormat format,
43  bool multiSampled) override;
44 
45  virtual unsigned int GetWidth() const override { return _width; }
46  virtual unsigned int GetHeight() const override { return _height; }
47  virtual unsigned int GetDepth() const override { return 1; }
48  virtual HdFormat GetFormat() const override { return _format; }
49 
50  // HdPrman doesn't handle sampling decisions at the hydra level.
51  virtual bool IsMultiSampled() const override { return false; }
52 
53  virtual void* Map() override {
54  _mappers++;
55  return _buffer.data();
56  }
57  virtual void Unmap() override {
58  _mappers--;
59  }
60  virtual bool IsMapped() const override {
61  return _mappers.load() != 0;
62  }
63 
64  virtual bool IsConverged() const override {
65  return _converged.load();
66  }
67  void SetConverged(bool cv) {
68  _converged.store(cv);
69  }
70 
71  virtual void Resolve() override {}
72 
73  // ---------------------------------------------------------------------- //
75  // ---------------------------------------------------------------------- //
76 
77  // format is the input format.
78  void Blit(HdFormat format, int width, int height, int offset, int stride,
79  uint8_t const* data);
80 
81 private:
82  static size_t _GetBufferSize(GfVec2i const& dims, HdFormat format);
83 
84  virtual void _Deallocate() override;
85 
86  unsigned int _width;
87  unsigned int _height;
88  HdFormat _format;
89 
90  std::vector<uint8_t> _buffer;
91  std::atomic<int> _mappers;
92  std::atomic<bool> _converged;
93 };
94 
95 PXR_NAMESPACE_CLOSE_SCOPE
96 
97 #endif // HDXPRMAN_RENDERBUFFER_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.
virtual unsigned int GetWidth() const =0
Get the buffer&#39;s width.
virtual void _Deallocate()=0
Deallocate the buffer, freeing any owned resources.
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:287
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:48
virtual void * Map()=0
Map the buffer for reading.
virtual bool Allocate(GfVec3i const &dimensions, HdFormat format, bool multiSampled)=0
Allocate a buffer.
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.