DeferredRenderer 1.0

FrameBufferObject Class Reference

A glFBO wrapper for setting up and managing off screen rendering to multiple render targets. More...

#include <FrameBufferObject.h>

List of all members.

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

Detailed Description

A glFBO wrapper for setting up and managing off screen rendering to multiple render targets.

Definition at line 15 of file FrameBufferObject.h.


Constructor & Destructor Documentation

FrameBufferObject::FrameBufferObject ( ) [inline]

empty ctor

Definition at line 20 of file FrameBufferObject.h.

{}
FrameBufferObject::FrameBufferObject ( unsigned int  _width,
unsigned int  _height 
)

constructor that will set the dimensions of the FBO and init the rener target list

Parameters:
[in]_widththe FBO width
[in]_heightthe FBO height
[in]_numOfRTthe number of render targets to have

Definition at line 5 of file FrameBufferObject.cpp.

                                                                             :
        m_width(_width),m_height(_height)
{
}
FrameBufferObject::~FrameBufferObject ( )

dtor

Definition at line 10 of file FrameBufferObject.cpp.

{}

Member Function Documentation

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);
}

Here is the caller graph for this function:

void FrameBufferObject::activateTarget ( GLuint  _id)

acivate a render target of your choice, starting from 0

Parameters:
[in]_idthe render targets color attachment id

Definition at line 101 of file FrameBufferObject.cpp.

{
    glDrawBuffer(GL_COLOR_ATTACHMENT0 + _id);
}

Here is the caller graph for this function:

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);

}

Here is the caller graph for this function:

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

Parameters:
[in]_slotthe color attachment
[in]_idthe 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);
}

Here is the caller graph for this function:

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;
    }
}

Here is the caller graph for this function:

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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int FrameBufferObject::getHeight ( ) [inline]

accessor for FBO height

Returns:
m_height

Definition at line 49 of file FrameBufferObject.h.

References m_height.

{return m_height;}
unsigned int FrameBufferObject::getWidth ( ) [inline]

accessor for FBO width

Returns:
m_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);
}

Here is the caller graph for this function:


Member Data Documentation

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.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines