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 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_HD_RENDER_BUFFER_H
8 #define PXR_IMAGING_HD_RENDER_BUFFER_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hd/api.h"
12 #include "pxr/imaging/hd/bprim.h"
13 
14 #include "pxr/base/gf/vec2i.h"
15 
17 
18 
19 
20 
21 /// \class HdRenderBuffer
22 ///
23 /// A render buffer is a handle to a data resource that can be rendered into,
24 /// such as a 2d image for a draw target or auxiliary rendering output.
25 ///
26 /// The render buffer can be used as an indexed prim, in which case it
27 /// communicates with the scene delegate to get buffer properties, or it can
28 /// be created out of band and supplied directly with allocation parameters.
29 ///
30 /// Render buffers can be targeted by render passes. They also contain
31 /// mapping functionality for reading and writing buffer data.
32 class HdRenderBuffer : public HdBprim
33 {
34 public:
35  // change tracking for HdRenderBuffer
37  Clean = 0,
38  DirtyDescription = 1 << 0,
40  };
41 
42  HD_API
43  HdRenderBuffer(SdfPath const& id);
44  HD_API
45  ~HdRenderBuffer() override;
46 
47  // ---------------------------------------------------------------------- //
48  /// \name Prim API
49  // ---------------------------------------------------------------------- //
50 
51  /// Get initial invalidation state.
52  HD_API
53  HdDirtyBits GetInitialDirtyBitsMask() const override;
54 
55  /// Get allocation information from the scene delegate.
56  HD_API
57  void Sync(HdSceneDelegate *sceneDelegate,
58  HdRenderParam *renderParam,
59  HdDirtyBits *dirtyBits) override;
60 
61  /// Deallocate before deletion.
62  HD_API
63  void Finalize(HdRenderParam *renderParam) override;
64 
65  // ---------------------------------------------------------------------- //
66  /// \name Renderbuffer API
67  // ---------------------------------------------------------------------- //
68 
69  /// Allocate a buffer. Can be called from Sync(), or directly.
70  /// If the buffer has already been allocated, calling Allocate() again
71  /// will destroy the old buffer and allocate a new one.
72  ///
73  /// A negative dimension or invalid format will cause an allocation error.
74  /// If the requested buffer can't be allocated, the function will return
75  /// false.
76  virtual bool Allocate(GfVec3i const& dimensions,
78  bool multiSampled) = 0;
79 
80  /// Get the buffer's width.
81  virtual unsigned int GetWidth() const = 0;
82  /// Get the buffer's height.
83  virtual unsigned int GetHeight() const = 0;
84  /// Get the buffer's depth.
85  virtual unsigned int GetDepth() const = 0;
86  /// Get the buffer's per-pixel format.
87  virtual HdFormat GetFormat() const = 0;
88  /// Get whether the buffer is multisampled.
89  virtual bool IsMultiSampled() const = 0;
90 
91  /// Map the buffer for reading.
92  virtual void* Map() = 0;
93  /// Unmap the buffer. It is no longer safe to read from the buffer.
94  virtual void Unmap() = 0;
95  /// Return whether the buffer is currently mapped by anybody.
96  virtual bool IsMapped() const = 0;
97 
98  /// Resolve the buffer so that reads reflect the latest writes.
99  ///
100  /// Some buffer implementations may defer final processing of writes until
101  /// a buffer is read, for efficiency; examples include OpenGL MSAA or
102  /// multi-sampled raytraced buffers.
103  virtual void Resolve() = 0;
104 
105  /// Return whether the buffer is converged (whether the renderer is
106  /// still adding samples or not).
107  virtual bool IsConverged() const = 0;
108 
109  /// This optional API returns a (type-erased) resource that backs this
110  /// render buffer. For example, a render buffer implementation may allocate
111  /// a gpu texture that holds the data of the buffer. This function allows
112  /// other parts of Hydra, such as a HdTask to get access to this resource.
113  virtual VtValue GetResource(bool multiSampled) const {return VtValue();}
114 
115 protected:
116  /// Deallocate the buffer, freeing any owned resources.
117  virtual void _Deallocate() = 0;
118 };
119 
121 
122 #endif // PXR_IMAGING_HD_RENDER_BUFFER_H
virtual bool IsMapped() const =0
Return whether the buffer is currently mapped by anybody.
HdFormat
Definition: types.h:408
uint32_t HdDirtyBits
Definition: types.h:143
virtual void Unmap()=0
Unmap the buffer. It is no longer safe to read from the buffer.
#define HD_API
Definition: api.h:23
virtual unsigned int GetDepth() const =0
Get the buffer's depth.
HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Get allocation information from the scene delegate.
HD_API HdDirtyBits GetInitialDirtyBitsMask() const override
Get initial invalidation state.
HD_API void Finalize(HdRenderParam *renderParam) override
Deallocate before deletion.
virtual void _Deallocate()=0
Deallocate the buffer, freeing any owned resources.
virtual void Resolve()=0
virtual bool Allocate(GfVec3i const &dimensions, HdFormat format, bool multiSampled)=0
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
HD_API HdRenderBuffer(SdfPath const &id)
Definition: vec3i.h:43
Definition: path.h:273
virtual unsigned int GetHeight() const =0
Get the buffer's height.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
virtual VtValue GetResource(bool multiSampled) const
Definition: renderBuffer.h:113
HD_API ~HdRenderBuffer() override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: bprim.h:39
virtual bool IsConverged() const =0
virtual unsigned int GetWidth() const =0
Get the buffer's width.
virtual HdFormat GetFormat() const =0
Get the buffer's per-pixel format.
virtual bool IsMultiSampled() const =0
Get whether the buffer is multisampled.
Definition: value.h:146
virtual void * Map()=0
Map the buffer for reading.