Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
RenderTarget.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
3#pragma once
4
6#include "./Framebuffer.hpp"
7
8#include <glm/glm.hpp>
9#include <vector>
10
11namespace esengine {
12
14public:
15 RenderTarget() = default;
16 ~RenderTarget() = default;
17
18 RenderTarget(const RenderTarget&) = delete;
22
25 void init(GfxDevice& device, u32 width, u32 height, bool depth = true, bool linearFilter = false, bool floatColor = false);
26 void shutdown();
27
28 void bind();
29 void unbind();
30 void resize(u32 width, u32 height);
31
34 glm::uvec2 getSize() const { return { width_, height_ }; }
35 u32 getWidth() const { return width_; }
36 u32 getHeight() const { return height_; }
37
38 bool isValid() const { return framebuffer_ != nullptr; }
40
41private:
42 GfxDevice* device_ = nullptr;
43 Unique<Framebuffer> framebuffer_;
44 u32 width_ = 0;
45 u32 height_ = 0;
46 bool has_depth_ = true;
47 bool linear_filter_ = false;
48};
49
51public:
52 using Handle = u32;
53 static constexpr Handle INVALID_HANDLE = 0;
54
57
59 void setDevice(GfxDevice& device) { device_ = &device; }
60
61 Handle create(u32 width, u32 height, bool depth = true, bool linearFilter = false, bool floatColor = false);
62 RenderTarget* get(Handle handle);
63 void release(Handle handle);
64
65 bool isValid(Handle handle) const;
66
67private:
68 GfxDevice* device_ = nullptr;
69 std::vector<Unique<RenderTarget>> targets_;
70 std::vector<Handle> free_list_;
71 Handle next_handle_ = 1;
72};
73
74} // namespace esengine
GPU framebuffer abstraction for render-to-texture.
Core type definitions and utilities for ESEngine.
Abstract graphics device interface.
Definition GfxDevice.hpp:75
void setDevice(GfxDevice &device)
Binds the device used to create render targets. Call once at setup.
Handle create(u32 width, u32 height, bool depth=true, bool linearFilter=false, bool floatColor=false)
static constexpr Handle INVALID_HANDLE
void release(Handle handle)
RenderTarget * get(Handle handle)
bool isValid(Handle handle) const
RenderTarget(const RenderTarget &)=delete
TextureHandle getDepthTexture() const
TextureHandle getColorTexture() const
RenderTarget & operator=(RenderTarget &&)=default
RenderTarget & operator=(const RenderTarget &)=delete
void init(GfxDevice &device, u32 width, u32 height, bool depth=true, bool linearFilter=false, bool floatColor=false)
RenderTarget(RenderTarget &&)=default
void resize(u32 width, u32 height)
FramebufferHandle getFramebuffer() const
glm::uvec2 getSize() const
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