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(const uint32_t width, const uint32_t height);
49
54 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,
55 const uint32_t filter = 0, const uint8_t max_mips = 1
56 );
57
62 void addDepthAttachment(const uint32_t format = 0, const uint32_t type = 0, const uint32_t filter = 0);
63
67 void setDepthAttachment(std::shared_ptr<Texture> texture);
68
75 void setTextureAttachment(const uint32_t attachment_level, std::shared_ptr<Texture> texture, const int32_t mip_level = 0);
76
80 void clearContents(const glm::vec4& color = glm::vec4(0.f), const int& target = 0);
81
85 void beginRender(const bool resize_viewport = true);
86
90 void endRender();
91
95 operator bool();
96
101 inline const std::shared_ptr<Texture>& getColorAttachment(const uint32_t attachment_level) const
102 {
103 return _color_attachments.at(attachment_level);
104 }
105
110 inline const std::shared_ptr<Texture>& getDepthAttachment() const
111 {
112 return _depth_attachment;
113 }
114
126 const Framebuffer* src,
127 const glm::ivec4& src_bounds = glm::ivec4(0),
128 const glm::ivec4& target_bounds = glm::ivec4(0),
129 const TargetBuffer& type = TargetBuffer::ALL,
130 const uint8_t color_attachment_src = 0,
131 const uint8_t color_attachment_dest = 0,
132 const bool usefilter = false
133 );
134
145 void blitTo(
146 Framebuffer* target,
147 const glm::ivec4& src_bounds = glm::ivec4(0),
148 const glm::ivec4& target_bounds = glm::ivec4(0),
149 const TargetBuffer& type = TargetBuffer::ALL,
150 const uint8_t color_attachment_src = 0,
151 const uint8_t color_attachment_dest = 0,
152 const bool usefilter = false
153 ) const;
154
160 void copyFrom(Framebuffer* source, const TargetBuffer& type = TargetBuffer::ALL)
161 {
162 blitFrom(source, {}, {}, type);
163 }
164
170 void blitToDefault(const uint8_t color_attachment_src = 0, const bool& usefilter = false) const;
171
172 /*
173 * Blit textures using quad rendering
174 * faster than a classic blit
175 */
176 //void blitTexture(render::Texture* target, const glm::ivec4& src_bounds, const glm::ivec4& target_bounds, const TargetBuffer& type, const bool& usefilter = false);
177
181 inline glm::ivec2 getDimensions() const noexcept
182 {
183 return {_width, _height};
184 }
185
186 private:
187 void _update_color_attachments();
188 void _clear_all_color_attachments(const glm::vec4& color);
189
190 static void _blit(
191 const Framebuffer* src,
192 Framebuffer* target,
193 const glm::ivec4& src_bounds,
194 const glm::ivec4& target_bounds,
195 const TargetBuffer& type,
196 const uint8_t color_attachment_src,
197 const uint8_t color_attachment_dest,
198 const bool usefilter
199 );
200
201 std::map<unsigned int, std::shared_ptr<Texture>> _color_attachments;
202 std::shared_ptr<Texture> _depth_attachment = {};
203
204 unsigned int _width = 0;
205 unsigned int _height = 0;
206 unsigned int _fbo = 0;
207 unsigned int _rbo = 0;
208 };
209}
210
211#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:110
const std::shared_ptr< Texture > & getColorAttachment(const uint32_t attachment_level) const
Definition framebuffer.h:101
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:181
void copyFrom(Framebuffer *source, const TargetBuffer &type=TargetBuffer::ALL)
Definition framebuffer.h:160
Render related abstractions (Shader, Framebuffer, Cubemaps, Textures)
Definition opengl.h:10