Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
framebuffer.h
1#ifndef OE_RENDER_FRAMEBUFFER_H
2#define OE_RENDER_FRAMEBUFFER_H
3
4#include <map>
5#include <glm/vec2.hpp>
6#include <glm/vec4.hpp>
7#include <memory>
8#include "texture.h"
9
10namespace oe::render
11{
12 enum TargetBuffer : int
13 {
14 COLOR_BUFFER = 0x4000,
15 DEPTH_BUFFER = 0x0100,
16 STENCIL_BUFFER = 0x0400,
17
18 ALL = 0x4500,
19 };
20
43 {
44 public:
45 Framebuffer(const glm::ivec2& dimensions);
46
47 Framebuffer(Framebuffer&&) = default;
48 Framebuffer& operator= (Framebuffer&&) = default;
49
50 Framebuffer(const uint32_t width, const uint32_t height);
52
57 std::shared_ptr<Texture> addColorAttachment(const uint32_t attachment_level = 0, const uint32_t internal_format = 0, const uint32_t format = 0, const uint32_t type = 0,
58 const uint32_t filter = 0, const uint8_t max_mips = 1
59 );
60
65 void addDepthAttachment(const uint32_t format = 0, const uint32_t type = 0, const uint32_t filter = 0);
66
70 void setDepthAttachment(std::shared_ptr<Texture> texture);
71
78 void setTextureAttachment(const uint32_t attachment_level, std::shared_ptr<Texture> texture, const int32_t mip_level = 0);
79
83 void clearContents(const glm::vec4& color = glm::vec4(0.f), const int& target = 0);
84
88 void beginRender(const bool resize_viewport = true);
89
93 void endRender();
94
98 operator bool();
99
104 inline const std::shared_ptr<Texture>& getColorAttachment(const uint32_t attachment_level) const
105 {
106 return _color_attachments.at(attachment_level);
107 }
108
113 inline const std::shared_ptr<Texture>& getDepthAttachment() const
114 {
115 return _depth_attachment;
116 }
117
129 const Framebuffer* src,
130 const glm::ivec4& src_bounds = glm::ivec4(0),
131 const glm::ivec4& target_bounds = glm::ivec4(0),
132 const TargetBuffer& type = TargetBuffer::ALL,
133 const uint8_t color_attachment_src = 0,
134 const uint8_t color_attachment_dest = 0,
135 const bool usefilter = false
136 );
137
148 void blitTo(
149 Framebuffer* target,
150 const glm::ivec4& src_bounds = glm::ivec4(0),
151 const glm::ivec4& target_bounds = glm::ivec4(0),
152 const TargetBuffer& type = TargetBuffer::ALL,
153 const uint8_t color_attachment_src = 0,
154 const uint8_t color_attachment_dest = 0,
155 const bool usefilter = false
156 ) const;
157
163 void copyFrom(Framebuffer* source, const TargetBuffer& type = TargetBuffer::ALL)
164 {
165 blitFrom(source, {}, {}, type);
166 }
167
173 void blitToDefault(const uint8_t color_attachment_src = 0, const bool& usefilter = false) const;
174
175 /*
176 * Blit textures using quad rendering
177 * faster than a classic blit
178 */
179 //void blitTexture(render::Texture* target, const glm::ivec4& src_bounds, const glm::ivec4& target_bounds, const TargetBuffer& type, const bool& usefilter = false);
180
184 inline glm::ivec2 getDimensions() const noexcept
185 {
186 return {_width, _height};
187 }
188
189 #ifdef OXYGEN_ENGINE_DEBUG_VALIDATE_ORDERED_OPERATIONS
190 bool is_between_begin_end = false;
191 #endif
192
193 private:
194 void _update_color_attachments();
195 void _clear_all_color_attachments(const glm::vec4& color);
196
197 static void _blit(
198 const Framebuffer* src,
199 Framebuffer* target,
200 const glm::ivec4& src_bounds,
201 const glm::ivec4& target_bounds,
202 const TargetBuffer& type,
203 const uint8_t color_attachment_src,
204 const uint8_t color_attachment_dest,
205 const bool usefilter
206 );
207
208 std::map<unsigned int, std::shared_ptr<Texture>> _color_attachments;
209 std::shared_ptr<Texture> _depth_attachment = {};
210
211 unsigned int _width = 0;
212 unsigned int _height = 0;
213 unsigned int _fbo = 0;
214 unsigned int _rbo = 0;
215 };
216}
217
218#endif
Definition framebuffer.h:43
void blitTo(Framebuffer *target, const glm::ivec4 &src_bounds=glm::ivec4(0), const glm::ivec4 &target_bounds=glm::ivec4(0), const TargetBuffer &type=TargetBuffer::ALL, const uint8_t color_attachment_src=0, const uint8_t color_attachment_dest=0, const bool usefilter=false) const
void addDepthAttachment(const uint32_t format=0, const uint32_t type=0, const uint32_t filter=0)
void blitToDefault(const uint8_t color_attachment_src=0, const bool &usefilter=false) const
void blitFrom(const Framebuffer *src, const glm::ivec4 &src_bounds=glm::ivec4(0), const glm::ivec4 &target_bounds=glm::ivec4(0), const TargetBuffer &type=TargetBuffer::ALL, const uint8_t color_attachment_src=0, const uint8_t color_attachment_dest=0, const bool usefilter=false)
const std::shared_ptr< Texture > & getDepthAttachment() const
Definition framebuffer.h:113
const std::shared_ptr< Texture > & getColorAttachment(const uint32_t attachment_level) const
Definition framebuffer.h:104
void clearContents(const glm::vec4 &color=glm::vec4(0.f), const int &target=0)
void setDepthAttachment(std::shared_ptr< Texture > texture)
void setTextureAttachment(const uint32_t attachment_level, std::shared_ptr< Texture > texture, const int32_t mip_level=0)
void beginRender(const bool resize_viewport=true)
std::shared_ptr< Texture > addColorAttachment(const uint32_t attachment_level=0, const uint32_t internal_format=0, const uint32_t format=0, const uint32_t type=0, const uint32_t filter=0, const uint8_t max_mips=1)
glm::ivec2 getDimensions() const noexcept
Definition framebuffer.h:184
void copyFrom(Framebuffer *source, const TargetBuffer &type=TargetBuffer::ALL)
Definition framebuffer.h:163
Prevent class to be copied.
Definition non_copyable.h:12
Render related abstractions (Shader, Framebuffer, Cubemaps, Textures)
Definition opengl.h:10