Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
Framebuffer.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
15#pragma once
16
17// =============================================================================
18// Includes
19// =============================================================================
20
21#include "../../core/Types.hpp"
22#include "./Texture.hpp"
23
24namespace esengine {
25
26class GfxDevice;
27
28// =============================================================================
29// Framebuffer Specification
30// =============================================================================
31
48 u32 width = 1280;
50 u32 height = 720;
54 bool depthStencil = true;
56 bool linearFilter = false;
60 bool gbuffer = false;
62 bool storage = false;
63 bool mipmaps = false;
64};
65
66// =============================================================================
67// Framebuffer Class
68// =============================================================================
69
95public:
96 Framebuffer() = default;
98
99 // Non-copyable, movable
100 Framebuffer(const Framebuffer&) = delete;
102 Framebuffer(Framebuffer&& other) noexcept;
103 Framebuffer& operator=(Framebuffer&& other) noexcept;
104
105 // =========================================================================
106 // Creation
107 // =========================================================================
108
117 static Unique<Framebuffer> create(GfxDevice& device, const FramebufferSpec& spec);
118
119 // =========================================================================
120 // Operations
121 // =========================================================================
122
128 void bind() const;
129
134 void unbind() const;
135
144 void resize(u32 width, u32 height);
145
146 // =========================================================================
147 // Properties
148 // =========================================================================
149
155 return resolveColor_ != TextureHandle::Invalid ? resolveColor_ : colorAttachment_;
156 }
157
160 return resolveColor1_ != TextureHandle::Invalid ? resolveColor1_ : colorAttachment1_;
161 }
162
165 return resolveColor2_ != TextureHandle::Invalid ? resolveColor2_ : colorAttachment2_;
166 }
167
170 return resolveDepth_ != TextureHandle::Invalid ? resolveDepth_ : depthAttachment_;
171 }
172
174 u32 getWidth() const { return spec_.width; }
175
177 u32 getHeight() const { return spec_.height; }
178
180 const FramebufferSpec& getSpecification() const { return spec_; }
181
183 FramebufferHandle handle() const { return handle_; }
184
185private:
190 bool initialize();
191
195 void cleanup();
196
197 GfxDevice* device_ = nullptr;
198 FramebufferSpec spec_;
200 TextureHandle colorAttachment_ = TextureHandle::Invalid;
201 TextureHandle depthAttachment_ = TextureHandle::Invalid;
206 TextureHandle colorAttachment1_ = TextureHandle::Invalid;
207 TextureHandle resolveColor1_ = TextureHandle::Invalid;
209 TextureHandle colorAttachment2_ = TextureHandle::Invalid;
210 TextureHandle resolveColor2_ = TextureHandle::Invalid;
211};
212
213} // namespace esengine
GPU texture abstraction for 2D images.
Core type definitions and utilities for ESEngine.
TextureHandle getAlbedoAttachment() const
The third colour attachment, the surface's diffuse colour (RGBA8, alpha 1 where a surface wrote it).
Framebuffer & operator=(const Framebuffer &)=delete
u32 getHeight() const
Gets the framebuffer height in pixels.
TextureHandle getGBufferAttachment() const
The second colour attachment, resolved like the first (Invalid when the target has none).
TextureHandle getDepthAttachment() const
Gets the depth attachment texture (Invalid if none).
void bind() const
Binds the framebuffer for rendering.
u32 getWidth() const
Gets the framebuffer width in pixels.
static Unique< Framebuffer > create(GfxDevice &device, const FramebufferSpec &spec)
Creates a framebuffer from specification.
const FramebufferSpec & getSpecification() const
Gets the framebuffer specification.
FramebufferHandle handle() const
Gets the device framebuffer handle.
void unbind() const
Unbinds the framebuffer.
Framebuffer(const Framebuffer &)=delete
void resize(u32 width, u32 height)
Resizes the framebuffer.
TextureHandle getColorAttachment() const
Gets the color attachment texture.
Abstract graphics device interface.
Definition GfxDevice.hpp:75
FramebufferHandle
Handle 0 is the default framebuffer (backbuffer); it cannot be created or deleted.
Definition GfxEnums.hpp:41
std::unique_ptr< T > Unique
Unique ownership smart pointer.
Definition Types.hpp:75
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
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 depthStencil
Whether to create depth/stencil attachment.
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.