38 lines
751 B
C++
38 lines
751 B
C++
#include "framebuffer.h"
|
|
#include "texture.h"
|
|
#include "glassert.h"
|
|
|
|
FrameBuffer::FrameBuffer()
|
|
{
|
|
glAssert(glGenFramebuffers(1, &fbo));
|
|
}
|
|
|
|
FrameBuffer::~FrameBuffer()
|
|
{
|
|
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];
|
|
}
|