5#include <smk/Color.hpp>
6#include <smk/Drawable.hpp>
7#include <smk/Framebuffer.hpp>
8#include <smk/RenderState.hpp>
17 option.internal_format = GL_RGB;
18 option.format = GL_RGB;
19 option.type = GL_UNSIGNED_BYTE;
20 option.generate_mipmap =
false;
21 option.min_filter = GL_LINEAR;
22 option.mag_filter = GL_LINEAR;
23 color_textures_.emplace_back(
nullptr,
width,
height, option);
34 : color_textures_(std::move(color_textures)) {
38void Framebuffer::Init() {
39 width_ = color_texture().
width();
40 height_ = color_texture().
height();
43 glGenFramebuffers(1, &frame_buffer_);
44 glBindFramebuffer(GL_FRAMEBUFFER, frame_buffer_);
47 for (
size_t i = 0; i < color_textures_.size(); ++i) {
48 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
49 GL_TEXTURE_2D, color_textures_[i].
id(), 0);
53 glGenRenderbuffers(1, &render_buffer_);
54 glBindRenderbuffer(GL_RENDERBUFFER, render_buffer_);
55 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width_, height_);
56 glBindRenderbuffer(GL_RENDERBUFFER, 0);
59 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
60 GL_RENDERBUFFER, render_buffer_);
62 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
63 std::cout <<
"ERROR::FRAMEBUFFER:: Framebuffer is not complete!"
67 glBindFramebuffer(GL_FRAMEBUFFER, 0);
72Framebuffer::~Framebuffer() {
74 glDeleteFramebuffers(1, &frame_buffer_);
79 glDeleteRenderbuffers(1, &render_buffer_);
85 this->operator=(std::move(other));
88Framebuffer& Framebuffer::operator=(Framebuffer&& other)
noexcept {
90 std::swap(color_textures_, other.color_textures_);
91 std::swap(render_buffer_, other.render_buffer_);
96 return color_textures_[0];
Framebuffer(int width, int height)
Construct a Framebuffer of a given dimensions.
RenderTarget & operator=(RenderTarget &&other) noexcept
Move operator.
int height() const
the height of the surface.
int width() const
the width of the surface.
int height() const
Access the height of the texture.
int width() const
Access the width of the texture.