Brenta Engine 1.2
Loading...
Searching...
No Matches
framebuffer.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8#include <brenta/renderer/opengl/buffer.hpp>
9
10#include <cassert>
11
12namespace brenta
13{
14
15//
16// Framebuffer
17// -----------
18//
19// The framebuffer stores a Texture that is rendered into after a
20// draw call. You usually use it like this:
21//
22// FrameBuffer fb(Window::get_width(), Window::get_height());
23// // setup...
24//
25// fb.bind();
26// Draw();
27// fb.unbind();
28//
29class FrameBuffer : public Buffer
30{
31public:
32
33 GLuint texture_id;
34 GLuint render_buffer_id;
35 GLenum color_format;
36 GLenum channel_type = GL_UNSIGNED_BYTE;
37 int width;
38 int height;
39
40 // Used for profiling
41 int memory = 0;
42 static int tot_memory;
43
44 FrameBuffer() = default;
45 FrameBuffer(int width, int height, GLenum format = GL_RGBA);
46
48 {
49 this->texture_id = other.texture_id;
50 this->render_buffer_id = other.render_buffer_id;
51 this->color_format = other.color_format;
52 this->width = other.width;
53 this->height = other.height;
54 this->target = other.target;
55 this->id = other.id;
56 this->memory = other.memory;
57
58 other.id = 0;
59 other.memory = 0;
60 }
61 FrameBuffer &operator=(FrameBuffer&& other)
62 {
63 this->texture_id = other.texture_id;
64 this->render_buffer_id = other.render_buffer_id;
65 this->color_format = other.color_format;
66 this->width = other.width;
67 this->height = other.height;
68 this->target = other.target;
69 this->id = other.id;
70 this->memory = other.memory;
71
72 other.id = 0;
73 other.memory = 0;
74
75 return *this;
76 }
77
79
80 void bind() const override;
81 void unbind() const override;
82
83 void destroy();
84
85 void rescale(int width, int height);
86 void set_color_format(GLenum color_format);
87
88};
89
90} // namespace brenta