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