SparrowRenderer/framebuffer.cpp
2015-12-07 15:37:50 +01:00

50 lines
992 B
C++

#include "framebuffer.h"
#include "texture.h"
#include "glassert.h"
FrameBuffer::FrameBuffer(bool isNULL)
{
if(isNULL)
fbo = 0;
else
glAssert(glGenFramebuffers(1, &fbo));
}
FrameBuffer::~FrameBuffer()
{
if(fbo != 0)
glAssert(glDeleteFramebuffers(1, &fbo));
}
void FrameBuffer::addTexture(Texture* tex, GLenum attachment)
{
textures.push_back(tex);
bindFBO();
glAssert(glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, tex->getTarget(), tex->getId(), 0));
attachments.push_back(attachment);
}
void FrameBuffer::initGL()
{
bindFBO();
glAssert(glDrawBuffers(attachments.size(), attachments.data()));
}
void FrameBuffer::bindFBO()
{
glAssert(glBindFramebuffer(GL_FRAMEBUFFER, fbo));
}
Texture* FrameBuffer::getTexture(int texId)
{
return textures[texId];
}
FrameBuffer* FrameBuffer::getScreen()
{
static FrameBuffer* screen = NULL;
if(screen == NULL)
screen = new FrameBuffer(true);
return screen;
}