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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HD_ST_RENDER_BUFFER_H
8 #define PXR_IMAGING_HD_ST_RENDER_BUFFER_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/base/gf/vec3i.h"
12 #include "pxr/imaging/hdSt/api.h"
15 #include "pxr/imaging/hgi/hgi.h"
16 #include "pxr/imaging/hgi/enums.h"
18 
20 
24  std::shared_ptr<class HdStDynamicUvTextureObject>;
25 
27 {
28 public:
29  HDST_API
30  HdStRenderBuffer(HdStResourceRegistry *resourceRegistry, SdfPath const& id);
31 
32  HDST_API
33  ~HdStRenderBuffer() override;
34 
35  HDST_API
36  void Sync(HdSceneDelegate *sceneDelegate,
37  HdRenderParam *renderParam,
38  HdDirtyBits *dirtyBits) override;
39 
40  HDST_API
41  bool Allocate(GfVec3i const& dimensions,
43  bool multiSampled) override;
44 
45  HDST_API
46  unsigned int GetWidth() const override;
47 
48  HDST_API
49  unsigned int GetHeight() const override;
50 
51  HDST_API
52  unsigned int GetDepth() const override;
53 
54  HDST_API
55  HdFormat GetFormat() const override {return _format;}
56 
57  HDST_API
58  bool IsMultiSampled() const override;
59 
60  HDST_API
61  uint32_t GetMSAASampleCount() const;
62 
63  /// Map the buffer for reading. The control flow should be Map(),
64  /// before any I/O, followed by memory access, followed by Unmap() when
65  /// done.
66  /// \return The address of the buffer.
67  HDST_API
68  void* Map() override;
69 
70  /// Unmap the buffer.
71  HDST_API
72  void Unmap() override;
73 
74  /// Return whether any clients have this buffer mapped currently.
75  /// \return True if the buffer is currently mapped by someone.
76  HDST_API
77  bool IsMapped() const override {
78  return _mappers.load() != 0;
79  }
80 
81  /// Is the buffer converged?
82  /// \return True if the buffer is converged (not currently being
83  /// rendered to).
84  HDST_API
85  bool IsConverged() const override {
86  return true;
87  }
88 
89  /// Resolve the sample buffer into final values.
90  HDST_API
91  void Resolve() override;
92 
93  /// Returns the texture handle.
94  HDST_API
95  VtValue GetResource(bool multiSampled) const override;
96 
97  /// The identifier that can be passed to, e.g.,
98  /// HdStResourceRegistry::AllocateTextureHandle so that a
99  /// shader can bind this buffer as texture.
100  HDST_API
102  bool multiSampled);
103 
104 protected:
105  void _Deallocate() override;
106 
107 private:
108  // HdRenderBuffer::Allocate should take a scene delegate or
109  // resource registry so that we do not need to save it here.
110  HdStResourceRegistry * _resourceRegistry;
111 
112  // Format saved here (somewhat redundantely) since the
113  // Hgi texture descriptor holds an HgiFormat instead of HdFormat.
114  HdFormat _format;
115 
116  uint32_t _msaaSampleCount;
117 
118  // The GPU texture resource
120 
121  // The GPU multi-sample texture resource (optional)
122  HdStDynamicUvTextureObjectSharedPtr _textureMSAAObject;
123 
124  // The number of callers mapping this buffer.
125  std::atomic<int> _mappers;
126  // Texels are temp captured into this buffer between map and unmap.
128 };
129 
131 
132 #endif
HDST_API void * Map() override
HdFormat
Definition: types.h:408
uint32_t HdDirtyBits
Definition: types.h:143
HDST_API bool IsConverged() const override
Definition: renderBuffer.h:85
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:77
HDST_API VtValue GetResource(bool multiSampled) const override
Returns the texture handle.
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
Definition: vec3i.h:43
HDST_API bool Allocate(GfVec3i const &dimensions, HdFormat format, bool multiSampled) override
HDST_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Get allocation information from the scene delegate.
HDST_API HdFormat GetFormat() const override
Get the buffer's per-pixel format.
Definition: renderBuffer.h:55
Definition: path.h:273
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:24
HDST_API bool IsMultiSampled() const override
Get whether the buffer is multisampled.
HDST_API uint32_t GetMSAASampleCount() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define HDST_API
Definition: api.h:23
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
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:146
HDST_API void Unmap() override
Unmap the buffer.