DeferredRenderer 1.0
|
A glFBO wrapper for setting up and managing off screen rendering to multiple render targets. More...
#include <FrameBufferObject.h>
Public Member Functions | |
FrameBufferObject () | |
empty ctor | |
FrameBufferObject (unsigned int _width, unsigned int _height) | |
constructor that will set the dimensions of the FBO and init the rener target list | |
~FrameBufferObject () | |
dtor | |
void | bind () |
make this FBO the active one for drawing | |
void | unbind () |
make the default (screen) FBO active | |
void | create (GLuint _textureId) |
this method creates the fbo render targets and the glFBO itself | |
void | checkStatus () |
errors check this FBO | |
unsigned int | getWidth () |
accessor for FBO width | |
unsigned int | getHeight () |
accessor for FBO height | |
void | activateAllTargets () |
acivates 4 targets for drawing | |
void | bindTextureSlot (GLuint _slot, GLuint _id) |
bind a texture id to an FBO color attachment | |
void | bindDepthTexture (GLuint textureId) |
void | activateTarget (GLuint _id) |
acivate a render target of your choice, starting from 0 | |
Private Attributes | |
GLuint | m_width |
the FBO width | |
GLuint | m_height |
the FBO height | |
GLuint | m_FBOid |
framebuffer id | |
GLuint | m_RBid |
depth buffer id |
A glFBO wrapper for setting up and managing off screen rendering to multiple render targets.
Definition at line 15 of file FrameBufferObject.h.
FrameBufferObject::FrameBufferObject | ( | ) | [inline] |
FrameBufferObject::FrameBufferObject | ( | unsigned int | _width, |
unsigned int | _height | ||
) |
constructor that will set the dimensions of the FBO and init the rener target list
[in] | _width | the FBO width |
[in] | _height | the FBO height |
[in] | _numOfRT | the number of render targets to have |
Definition at line 5 of file FrameBufferObject.cpp.
FrameBufferObject::~FrameBufferObject | ( | ) |
void FrameBufferObject::activateAllTargets | ( | ) |
acivates 4 targets for drawing
Definition at line 89 of file FrameBufferObject.cpp.
{ GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; glDrawBuffers(4, buffers); }
void FrameBufferObject::activateTarget | ( | GLuint | _id | ) |
acivate a render target of your choice, starting from 0
[in] | _id | the render targets color attachment id |
Definition at line 101 of file FrameBufferObject.cpp.
{ glDrawBuffer(GL_COLOR_ATTACHMENT0 + _id); }
void FrameBufferObject::bind | ( | ) |
make this FBO the active one for drawing
Definition at line 13 of file FrameBufferObject.cpp.
References m_FBOid, m_height, m_RBid, and m_width.
{ glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_FBOid); glBindRenderbuffer(GL_RENDERBUFFER_EXT, m_RBid); glPushAttrib(GL_VIEWPORT_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, m_width, m_height); }
void FrameBufferObject::bindDepthTexture | ( | GLuint | textureId | ) |
Definition at line 60 of file FrameBufferObject.cpp.
References m_FBOid.
{ glBindFramebuffer( GL_FRAMEBUFFER, m_FBOid); glFramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, textureId, 0 ); }
void FrameBufferObject::bindTextureSlot | ( | GLuint | _slot, |
GLuint | _id | ||
) |
bind a texture id to an FBO color attachment
[in] | _slot | the color attachment |
[in] | _id | the texture id |
Definition at line 54 of file FrameBufferObject.cpp.
References m_FBOid.
{ glBindFramebuffer(GL_FRAMEBUFFER, m_FBOid); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+_slot,GL_TEXTURE_2D, _id, 0); }
void FrameBufferObject::checkStatus | ( | ) |
errors check this FBO
Definition at line 30 of file FrameBufferObject.cpp.
{ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); switch(status) { case GL_FRAMEBUFFER_COMPLETE: std::cout << "Complete FBO" << std::endl; break; case GL_FRAMEBUFFER_UNSUPPORTED: std::cout << "Unsupported FBO" << std::endl; break; case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: std::cout << "Incomplete Attatchments" << std::endl; break; case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: std::cout << "Missing attatchment" << std::endl; break; default: std::cout << "Weirdness afoot" << std::endl; break; } }
void FrameBufferObject::create | ( | GLuint | _textureId | ) |
this method creates the fbo render targets and the glFBO itself
Definition at line 66 of file FrameBufferObject.cpp.
References checkStatus(), m_FBOid, m_height, m_RBid, and m_width.
{ // create a renderbuffer object to store depth info glGenRenderbuffers(1, &m_RBid); glBindRenderbuffer(GL_RENDERBUFFER, m_RBid); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_width, m_height); glBindRenderbuffer(GL_RENDERBUFFER, 0); // create a framebuffer object glGenFramebuffers(1, &m_FBOid); glBindFramebuffer(GL_FRAMEBUFFER, m_FBOid); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D, _textureId, 0); // attach the renderbuffer to depth attachment point glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RBid); checkStatus(); glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindRenderbuffer(GL_RENDERBUFFER, 0); }
unsigned int FrameBufferObject::getHeight | ( | ) | [inline] |
accessor for FBO height
Definition at line 49 of file FrameBufferObject.h.
References m_height.
{return m_height;}
unsigned int FrameBufferObject::getWidth | ( | ) | [inline] |
accessor for FBO width
Definition at line 45 of file FrameBufferObject.h.
References m_width.
{return m_width;}
void FrameBufferObject::unbind | ( | ) |
make the default (screen) FBO active
Definition at line 23 of file FrameBufferObject.cpp.
{ glPopAttrib(); glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); glBindRenderbuffer(GL_RENDERBUFFER_EXT, 0); }
GLuint FrameBufferObject::m_FBOid [private] |
framebuffer id
Definition at line 73 of file FrameBufferObject.h.
GLuint FrameBufferObject::m_height [private] |
the FBO height
Definition at line 70 of file FrameBufferObject.h.
GLuint FrameBufferObject::m_RBid [private] |
depth buffer id
Definition at line 76 of file FrameBufferObject.h.
GLuint FrameBufferObject::m_width [private] |
the FBO width
Definition at line 67 of file FrameBufferObject.h.