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