Loading...
Searching...
No Matches
renderBuffer.h
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"
30#include "pxr/imaging/hdSt/textureUtils.h"
31#include "pxr/imaging/hd/renderBuffer.h"
32#include "pxr/imaging/hgi/hgi.h"
33#include "pxr/imaging/hgi/enums.h"
34#include "pxr/imaging/hgi/texture.h"
35
36PXR_NAMESPACE_OPEN_SCOPE
37
40using HdStDynamicUvTextureObjectSharedPtr =
41 std::shared_ptr<class HdStDynamicUvTextureObject>;
42
43class HdStRenderBuffer : public HdRenderBuffer
44{
45public:
46 HDST_API
47 HdStRenderBuffer(HdStResourceRegistry *resourceRegistry, SdfPath const& id);
48
49 HDST_API
50 ~HdStRenderBuffer() override;
51
52 HDST_API
53 void Sync(HdSceneDelegate *sceneDelegate,
54 HdRenderParam *renderParam,
55 HdDirtyBits *dirtyBits) override;
56
57 HDST_API
58 bool Allocate(GfVec3i const& dimensions,
59 HdFormat format,
60 bool multiSampled) override;
61
62 HDST_API
63 unsigned int GetWidth() const override;
64
65 HDST_API
66 unsigned int GetHeight() const override;
67
68 HDST_API
69 unsigned int GetDepth() const override;
70
71 HDST_API
72 HdFormat GetFormat() const override {return _format;}
73
74 HDST_API
75 bool IsMultiSampled() const override;
76
77 HDST_API
78 uint32_t GetMSAASampleCount() const;
79
84 HDST_API
85 void* Map() override;
86
88 HDST_API
89 void Unmap() override;
90
93 HDST_API
94 bool IsMapped() const override {
95 return _mappers.load() != 0;
96 }
97
101 HDST_API
102 bool IsConverged() const override {
103 return true;
104 }
105
107 HDST_API
108 void Resolve() override;
109
111 HDST_API
112 VtValue GetResource(bool multiSampled) const override;
113
117 HDST_API
118 HdStTextureIdentifier GetTextureIdentifier(
119 bool multiSampled);
120
121protected:
122 void _Deallocate() override;
123
124private:
125 // HdRenderBuffer::Allocate should take a scene delegate or
126 // resource registry so that we do not need to save it here.
127 HdStResourceRegistry * _resourceRegistry;
128
129 // Format saved here (somewhat redundantely) since the
130 // Hgi texture descriptor holds an HgiFormat instead of HdFormat.
131 HdFormat _format;
132
133 uint32_t _msaaSampleCount;
134
135 // The GPU texture resource
136 HdStDynamicUvTextureObjectSharedPtr _textureObject;
137
138 // The GPU multi-sample texture resource (optional)
139 HdStDynamicUvTextureObjectSharedPtr _textureMSAAObject;
140
141 // The number of callers mapping this buffer.
142 std::atomic<int> _mappers;
143 // Texels are temp captured into this buffer between map and unmap.
144 HdStTextureUtils::AlignedBuffer<uint8_t> _mappedBuffer;
145};
146
147PXR_NAMESPACE_CLOSE_SCOPE
148
149#endif
Basic type for a vector of 3 int components.
Definition: vec3i.h:61
A render buffer is a handle to a data resource that can be rendered into, such as a 2d image for a dr...
Definition: renderBuffer.h:50
virtual void Resolve()=0
Resolve the buffer so that reads reflect the latest writes.
virtual unsigned int GetWidth() const =0
Get the buffer's width.
virtual void * Map()=0
Map the buffer for reading.
HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Get allocation information from the scene delegate.
virtual unsigned int GetHeight() const =0
Get the buffer's height.
virtual bool IsMapped() const =0
Return whether the buffer is currently mapped by anybody.
virtual void _Deallocate()=0
Deallocate the buffer, freeing any owned resources.
virtual void Unmap()=0
Unmap the buffer. It is no longer safe to read from the buffer.
virtual unsigned int GetDepth() const =0
Get the buffer's depth.
virtual bool IsConverged() const =0
Return whether the buffer is converged (whether the renderer is still adding samples or not).
virtual HdFormat GetFormat() const =0
Get the buffer's per-pixel format.
virtual bool IsMultiSampled() const =0
Get whether the buffer is multisampled.
virtual VtValue GetResource(bool multiSampled) const
This optional API returns a (type-erased) resource that backs this render buffer.
Definition: renderBuffer.h:130
virtual bool Allocate(GfVec3i const &dimensions, HdFormat format, bool multiSampled)=0
Allocate a buffer.
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
Adapter class providing data exchange with the client scene graph.
A central registry of all GPU resources.
Class to identify a texture file or a texture within the texture file (e.g., a frame in a movie).
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:164