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