HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderBuffer.h
Go to the documentation of this file.
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 PXR_IMAGING_HD_ST_RENDER_BUFFER_H
25 #define PXR_IMAGING_HD_ST_RENDER_BUFFER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/base/gf/vec3i.h"
29 #include "pxr/imaging/hdSt/api.h"
31 #include "pxr/imaging/hgi/hgi.h"
32 #include "pxr/imaging/hgi/enums.h"
34 
36 
40  std::shared_ptr<class HdStDynamicUvTextureObject>;
41 
43 {
44 public:
45  HDST_API
46  HdStRenderBuffer(HdStResourceRegistry *resourceRegistry, SdfPath const& id);
47 
48  HDST_API
49  ~HdStRenderBuffer() override;
50 
51  HDST_API
52  bool Allocate(GfVec3i const& dimensions,
54  bool multiSampled) override;
55 
56  HDST_API
57  unsigned int GetWidth() const override;
58 
59  HDST_API
60  unsigned int GetHeight() const override;
61 
62  HDST_API
63  unsigned int GetDepth() const override;
64 
65  HDST_API
66  HdFormat GetFormat() const override {return _format;}
67 
68  HDST_API
69  bool IsMultiSampled() const override;
70 
71  /// Map the buffer for reading. The control flow should be Map(),
72  /// before any I/O, followed by memory access, followed by Unmap() when
73  /// done.
74  /// \return The address of the buffer.
75  HDST_API
76  void* Map() override;
77 
78  /// Unmap the buffer.
79  HDST_API
80  void Unmap() override;
81 
82  /// Return whether any clients have this buffer mapped currently.
83  /// \return True if the buffer is currently mapped by someone.
84  HDST_API
85  bool IsMapped() const override {
86  return _mappers.load() != 0;
87  }
88 
89  /// Is the buffer converged?
90  /// \return True if the buffer is converged (not currently being
91  /// rendered to).
92  HDST_API
93  bool IsConverged() const override {
94  return true;
95  }
96 
97  /// Resolve the sample buffer into final values.
98  HDST_API
99  void Resolve() override;
100 
101  /// Returns the texture handle.
102  HDST_API
103  VtValue GetResource(bool multiSampled) const override;
104 
105  /// The identifier that can be passed to, e.g.,
106  /// HdStResourceRegistry::AllocateTextureHandle so that a
107  /// shader can bind this buffer as texture.
108  HDST_API
110  bool multiSampled);
111 
112 protected:
113  void _Deallocate() override;
114 
115 private:
116  // HdRenderBuffer::Allocate should take a scene delegate or
117  // resource registry so that we do not need to save it here.
118  HdStResourceRegistry * _resourceRegistry;
119 
120  // Format saved here (somewhat redundantely) since the
121  // Hgi texture descriptor holds an HgiFormat instead of HdFormat.
122  HdFormat _format;
123 
124  // The GPU texture resource
126 
127  // The GPU multi-sample texture resource (optional)
128  HdStDynamicUvTextureObjectSharedPtr _textureMSAAObject;
129 
130  // The number of callers mapping this buffer.
131  std::atomic<int> _mappers;
132  // Texels are temp captured into this buffer between map and unmap.
133  std::vector<uint8_t> _mappedBuffer;
134 };
135 
137 
138 #endif
HDST_API void * Map() override
HdFormat
Definition: types.h:382
HDST_API bool IsConverged() const override
Definition: renderBuffer.h:93
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glew.h:1254
HDST_API HdStTextureIdentifier GetTextureIdentifier(bool multiSampled)
void _Deallocate() override
Deallocate the buffer, freeing any owned resources.
HDST_API bool IsMapped() const override
Definition: renderBuffer.h:85
HDST_API VtValue GetResource(bool multiSampled) const override
Returns the texture handle.
Definition: vec3i.h:61
HDST_API bool Allocate(GfVec3i const &dimensions, HdFormat format, bool multiSampled) override
HDST_API HdFormat GetFormat() const override
Get the buffer's per-pixel format.
Definition: renderBuffer.h:66
Definition: path.h:288
HDST_API unsigned int GetWidth() const override
Get the buffer's width.
HDST_API unsigned int GetDepth() const override
Get the buffer's depth.
HDST_API HdStRenderBuffer(HdStResourceRegistry *resourceRegistry, SdfPath const &id)
HDST_API ~HdStRenderBuffer() override
std::shared_ptr< class HdStDynamicUvTextureObject > HdStDynamicUvTextureObjectSharedPtr
Definition: renderBuffer.h:40
HDST_API bool IsMultiSampled() const override
Get whether the buffer is multisampled.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
#define HDST_API
Definition: api.h:40
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HDST_API void Resolve() override
Resolve the sample buffer into final values.
HDST_API unsigned int GetHeight() const override
Get the buffer's height.
Definition: value.h:174
HDST_API void Unmap() override
Unmap the buffer.