changed format to screen fbo for a more explicit and safe one

This commit is contained in:
Anselme 2015-12-08 00:09:14 +01:00
parent 80a4bac43b
commit 6f258f295d
3 changed files with 30 additions and 25 deletions

View File

@ -18,7 +18,7 @@ class ForwardModule : public Module
public:
ForwardModule() :
shaderSources(NULL),
renderTarget(FrameBuffer::getScreen())
renderTarget(FrameBuffer::screen)
{}
virtual void renderGL(Camera* myCamera, Scene* scene);
@ -47,7 +47,7 @@ private:
ShaderSource* shaderSources;
std::vector<Shader*> shaders;
std::vector<unsigned int> flags;
FrameBuffer* renderTarget;
const FrameBuffer* renderTarget;
void lightPass(Camera* myCamera, Scene* scene, Light* light, unsigned int type);
};

View File

@ -2,11 +2,10 @@
#include "texture.h"
#include "glassert.h"
FrameBuffer::FrameBuffer(bool isNULL)
const FrameBuffer* FrameBuffer::screen = new FrameBuffer(0);
FrameBuffer::FrameBuffer()
{
if(isNULL)
fbo = 0;
else
glAssert(glGenFramebuffers(1, &fbo));
}
@ -18,32 +17,34 @@ FrameBuffer::~FrameBuffer()
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()
void FrameBuffer::bindFBO() const
{
glAssert(glBindFramebuffer(GL_FRAMEBUFFER, fbo));
}
Texture* FrameBuffer::getTexture(int texId)
{
if(fbo != 0)
return textures[texId];
else
return NULL;
}
FrameBuffer* FrameBuffer::getScreen()
{
static FrameBuffer* screen = NULL;
if(screen == NULL)
screen = new FrameBuffer(true);
return screen;
}

View File

@ -8,19 +8,23 @@ class Texture;
class FrameBuffer
{
private:
FrameBuffer(int id) : fbo(id) {}
protected:
GLuint fbo;
std::vector<Texture*> textures;
std::vector<GLuint> attachments;
public:
FrameBuffer(bool isNULL = false);
FrameBuffer();
~FrameBuffer();
void addTexture(Texture* tex, GLenum attachment);
void initGL();
void bindFBO();
void bindFBO() const;
Texture* getTexture(int texId);
static FrameBuffer* getScreen();
static const FrameBuffer* screen;
};
#endif // FRAMEBUFFER_H