1#include "framebuffer.h"
5int Framebuffer::max_color_attachments = 0;
11 glGenFramebuffers(1, &buffer);
12 if(max_color_attachments == 0)
13 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS,
14 &Framebuffer::max_color_attachments);
17Framebuffer::~Framebuffer() {
18 glDeleteFramebuffers(1, &buffer);
23 GLenum ret = glCheckFramebufferStatus(target);
29 glBindFramebuffer(target, buffer);
33 glBindFramebuffer(target, buffer);
34 if(draw_buffers.size() == 0) {
35 glDrawBuffer(GL_NONE);
37 glDrawBuffers(draw_buffers.size(), draw_buffers.data());
42 glBindFramebuffer(target, 0);
48 if(width == 0 && height == 0) {
49 width = texture.
width;
51 }
else if(width != texture.
width || height != texture.
height) {
53 "match the size of previously attached textures or "
58 glFramebufferTexture(target, attachment, texture.
texture, 0);
60 GLenum attachment_max = GL_COLOR_ATTACHMENT0 + max_color_attachments;
67 draw_buffers.push_back(attachment);
70 if(attachment >= GL_COLOR_ATTACHMENT0 &&
71 attachment < attachment_max) {
73 draw_buffers.push_back(attachment);
84 if(width == 0 && height == 0) {
85 width = texture.
width;
87 }
else if(width != texture.
width || height != texture.
height) {
89 "match the size of previously attached textures or "
95 " number of layers of the texture");
99 glFramebufferTextureLayer(target, attachment, texture.
texture, 0, layer);
101 GLenum attachment_max = GL_COLOR_ATTACHMENT0 + max_color_attachments;
108 draw_buffers.push_back(attachment);
111 if(attachment >= GL_COLOR_ATTACHMENT0 &&
112 attachment < attachment_max) {
114 draw_buffers.push_back(attachment);
124 if(width == 0 && height == 0) {
125 width = buffer.width;
126 height = buffer.height;
127 }
else if(width != buffer.width || height != buffer.height) {
129 "not match the size of previously attached textures or "
134 glFramebufferRenderbuffer(target,
139 GLenum attachment_max = GL_COLOR_ATTACHMENT0 + max_color_attachments;
146 draw_buffers.push_back(attachment);
149 if(attachment >= GL_COLOR_ATTACHMENT0 &&
150 attachment < attachment_max) {
152 draw_buffers.push_back(attachment);
161 if(draw_buffers.size() == 0) {
162 glDrawBuffer(GL_NONE);
164 glDrawBuffers(draw_buffers.size(), draw_buffers.data());
182 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
184 target->bind(GL_DRAW_FRAMEBUFFER);
186 bind(GL_READ_FRAMEBUFFER);
187 glBlitFramebuffer(src_x0, src_y0, src_x1, src_y1, dst_x0, dst_y0, dst_x1, dst_y1, mask, filter);
205 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
206 bind(GL_DRAW_FRAMEBUFFER);
207 glBlitFramebuffer(src_x0, src_y0, src_x1, src_y1, dst_x0, dst_y0, dst_x1, dst_y1, mask, filter);
static std::vector< std::string > error_string
A list of all error strings.
void finalize()
Sets the draw buffers to be drawn into.
bool attach_texture_layer(GLenum attachment, Texture &texture, unsigned int layer)
Attaches the layer of a texture to the framebuffer.
void blit_from_default(unsigned int src_x0, unsigned int src_y0, unsigned int src_x1, unsigned int src_y1, unsigned int dst_x0, unsigned int dst_y0, unsigned int dst_x1, unsigned int dst_y1, GLbitfield mask, GLenum filter)
Copies a block of pixels from the default framebuffer to this one.
void bind()
Binds the framebuffer to the target set in the constructor.
void blit_to(sgltk::Framebuffer *target, unsigned int src_x0, unsigned int src_y0, unsigned int src_x1, unsigned int src_y1, unsigned int dst_x0, unsigned int dst_y0, unsigned int dst_x1, unsigned int dst_y1, GLbitfield mask, GLenum filter)
Copies a block of pixels from this framebuffer to another one.
bool attach_renderbuffer(GLenum attachment, Renderbuffer &buffer)
Attaches a renderbuffer to the framebuffer.
Framebuffer(GLenum target=GL_FRAMEBUFFER)
bool attach_texture(GLenum attachment, Texture &texture)
Attaches a texture to the framebuffer.
GLenum get_buffer_status()
Checks the completeness status of the framebuffer.
void unbind()
Restores the original framebuffer as render target.
unsigned int num_layers
The number of layers.
unsigned int width
The width of the texture.
GLuint texture
The texture name.
unsigned int height
The height of the texture.