33 : device_(other.device_),
35 handle_(other.handle_),
36 colorAttachment_(other.colorAttachment_),
37 depthAttachment_(other.depthAttachment_),
38 resolveColor_(other.resolveColor_),
39 resolveDepth_(other.resolveDepth_),
40 colorAttachment1_(other.colorAttachment1_),
41 resolveColor1_(other.resolveColor1_),
42 colorAttachment2_(other.colorAttachment2_),
43 resolveColor2_(other.resolveColor2_) {
58 device_ = other.device_;
60 handle_ = other.handle_;
61 colorAttachment_ = other.colorAttachment_;
62 depthAttachment_ = other.depthAttachment_;
63 resolveColor_ = other.resolveColor_;
64 resolveDepth_ = other.resolveDepth_;
65 colorAttachment1_ = other.colorAttachment1_;
66 resolveColor1_ = other.resolveColor1_;
67 colorAttachment2_ = other.colorAttachment2_;
68 resolveColor2_ = other.resolveColor2_;
88 framebuffer->device_ = &device;
89 framebuffer->spec_ = spec;
91 if (!framebuffer->initialize()) {
104 if (device_) device_->beginRenderPass({handle_});
108 if (device_) device_->endRenderPass();
112 if (width == 0 || height == 0 || width > 8192 || height > 8192) {
113 ES_LOG_WARN(
"Invalid framebuffer size: {}x{}", width, height);
118 spec_.height = height;
122 ES_LOG_ERROR(
"Framebuffer resize failed: {}x{}", width, height);
130bool Framebuffer::initialize() {
167 TextureDesc depthDesc;
168 depthDesc.width = spec_.width;
169 depthDesc.height = spec_.height;
173 if (spec_.depthStencil) {
174 depthDesc.samples = samples;
187 if (spec_.depthStencil && device_->resolvesDepth()) {
188 depthDesc.samples = 1;
194 fb.color0 = colorAttachment_;
195 fb.depthStencil = depthAttachment_;
196 fb.resolveColor0 = resolveColor_;
197 fb.resolveDepthStencil = resolveDepth_;
198 fb.color1 = colorAttachment1_;
199 fb.resolveColor1 = resolveColor1_;
200 fb.color2 = colorAttachment2_;
201 fb.resolveColor2 = resolveColor2_;
202 fb.width = spec_.width;
203 fb.height = spec_.height;
204 handle_ = device_->createFramebuffer(fb);
206 ES_LOG_ERROR(
"Framebuffer is incomplete! (size: {}x{}, GL error 0x{:X})",
207 spec_.width, spec_.height, device_->getError());
214void Framebuffer::cleanup() {
215 if (!device_)
return;
218 device_->deleteTexture(resolveColor_);
222 device_->deleteTexture(resolveColor1_);
226 device_->deleteTexture(colorAttachment1_);
230 device_->deleteTexture(resolveColor2_);
234 device_->deleteTexture(colorAttachment2_);
238 device_->deleteTexture(resolveDepth_);
242 device_->deleteTexture(colorAttachment_);
247 device_->deleteTexture(depthAttachment_);
252 device_->deleteFramebuffer(handle_);
GPU framebuffer abstraction for render-to-texture.
Abstract graphics device interface.
Logging utilities for ESEngine.
#define ES_LOG_WARN(...)
Logs a warning message.
#define ES_LOG_ERROR(...)
Logs an error message.
Framebuffer & operator=(const Framebuffer &)=delete
void bind() const
Binds the framebuffer for rendering.
static Unique< Framebuffer > create(GfxDevice &device, const FramebufferSpec &spec)
Creates a framebuffer from specification.
void unbind() const
Unbinds the framebuffer.
void resize(u32 width, u32 height)
Resizes the framebuffer.
static constexpr GfxContent transient()
Abstract graphics device interface.
virtual u32 maxSamples()=0
Most samples an offscreen colour attachment may carry; 1 = none.
TextureHandle createTexture(const TextureDesc &desc, GfxContent content, const void *pixels)
Creates a 2D texture; uploads pixels (tightly packed, desc-sized) when non-null.
virtual bool supportsCompute() const
Whether this device runs compute shaders.
constexpr Unique< T > makeUnique(Args &&... args)
Creates a Unique pointer with the given arguments.
@ Linear
Bilinear interpolation (smooth).
@ Nearest
No interpolation (pixelated look).
std::unique_ptr< T > Unique
Unique ownership smart pointer.
std::uint32_t u32
Unsigned 32-bit integer.
Framebuffer creation parameters.
GfxPixelFormat colorFormat
Color attachment format. RGBA16F needs GfxDevice::supportsFloatTargets.
bool gbuffer
A second colour attachment (RGBA8) drawn in the same pass: the surface's material,...
bool linearFilter
Texture filter mode: false=GL_NEAREST, true=GL_LINEAR.
u32 samples
Number of samples for MSAA (1 = no multisampling).
u32 height
Framebuffer height in pixels.
bool storage
The colour attachment can also be written by a compute shader (GfxDevice::supportsCompute).
u32 width
Framebuffer width in pixels.
Immutable creation parameters of a 2D texture or 2D texture array.
bool asyncShareable
Allow a native compute queue to share this single-sample colour target.