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 HDST_RENDERBUFFER_H
25 #define HDST_RENDERBUFFER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/gf/vec3i.h"
29 #include "pxr/imaging/hdSt/api.h"
30 #include "pxr/imaging/hd/renderBuffer.h"
31 #include "pxr/imaging/hgi/hgi.h"
32 #include "pxr/imaging/hgi/enums.h"
33 #include "pxr/imaging/hgi/texture.h"
34 
35 PXR_NAMESPACE_OPEN_SCOPE
36 
37 
38 class HdStRenderBuffer : public HdRenderBuffer
39 {
40 public:
41  HDST_API
42  HdStRenderBuffer(Hgi* hgi, SdfPath const& id);
43 
44  HDST_API
45  ~HdStRenderBuffer();
46 
47  HDST_API
48  bool Allocate(GfVec3i const& dimensions,
49  HdFormat format,
50  bool multiSampled) override;
51 
52  HDST_API
53  unsigned int GetWidth() const override {return _dimensions[0];}
54 
55  HDST_API
56  unsigned int GetHeight() const override {return _dimensions[1];}
57 
58  HDST_API
59  unsigned int GetDepth() const override {return _dimensions[2];}
60 
61  HDST_API
62  HdFormat GetFormat() const override {return _format;}
63 
64  HDST_API
65  bool IsMultiSampled() const override {return _multiSampled;}
66 
71  HDST_API
72  void* Map() override;
73 
75  HDST_API
76  void Unmap() override;
77 
80  HDST_API
81  bool IsMapped() const override {
82  return _mappers.load() != 0;
83  }
84 
88  HDST_API
89  bool IsConverged() const override {
90  return true;
91  }
92 
94  HDST_API
95  void Resolve() override;
96 
99  HDST_API
100  HgiTextureHandle GetMultiSampleTextureHandle() const;
101 
103  HDST_API
104  HgiTextureHandle GetTextureHandle() const;
105 
106 private:
107  // Release any allocated resources.
108  void _Deallocate() override;
109 
110  Hgi* _hgi;
111 
112  GfVec3i _dimensions;
113  HdFormat _format;
114  HgiTextureUsageBits _usage;
115  bool _multiSampled;
116 
117  // The GPU texture resource
118  HgiTextureHandle _texture;
119 
120  // The GPU multi-sample texture resource (optional)
121  HgiTextureHandle _textureMS;
122 
123  // The number of callers mapping this buffer.
124  std::atomic<int> _mappers;
125  // Texels are temp captured into this buffer between map and unmap.
126  std::vector<uint8_t> _mappedBuffer;
127 };
128 
129 PXR_NAMESPACE_CLOSE_SCOPE
130 
131 #endif
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
Represents a graphics platform independent GPU texture resource.
Definition: texture.h:48
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
Hydra Graphics Interface.
Definition: hgi.h:56
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.