Commit 9a0b0f0f authored by Jan Möbius's avatar Jan Möbius
Browse files

Addd Missing files

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8082 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 11398a0f
//=============================================================================
//
// CLASS FBO - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include "FBO.hh"
//== NAMESPACES ===============================================================
namespace ACG
{
//== IMPLEMENTATION ==========================================================
FBO::
~FBO()
{
// delete framebuffer object
glDeleteFramebuffersEXT( 1, &fbo_ );
// delete renderbuffers
glDeleteRenderbuffersEXT(1, &depthbuffer_);
glDeleteRenderbuffersEXT(1, &stencilbuffer_);
}
//-----------------------------------------------------------------------------
void
FBO::
init()
{
// Create framebuffer object
if ( !GLEW_EXT_framebuffer_object )
{
std::cout << "Framebuffer object not supported! " << std::endl;
exit( 1 );
}
glGenFramebuffersEXT( 1, &fbo_ );
// check status
checkFramebufferStatus();
// unbind fbo
unbind();
}
//-----------------------------------------------------------------------------
void
FBO::
attachTexture2D( GLenum _attachment, GLuint _texture )
{
// bind fbo
bind();
// add texture to frame buffer object
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, _attachment, GL_TEXTURE_2D, _texture, 0 );
// check status
checkFramebufferStatus();
// unbind fbo
unbind();
}
//-----------------------------------------------------------------------------
void
FBO::
addDepthBuffer( GLuint _width, GLuint _height )
{
// create renderbuffer
glGenRenderbuffersEXT(1, &depthbuffer_);
// bind renderbuffer
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthbuffer_);
// malloc
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, _width, _height);
// attach to framebuffer object
if ( bind() )
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthbuffer_);
// check status
checkFramebufferStatus();
// normal render mode
unbind();
}
//-----------------------------------------------------------------------------
void
FBO::
addStencilBuffer( GLuint _width, GLuint _height )
{
// create renderbuffer
glGenRenderbuffersEXT(1, &stencilbuffer_);
// bind renderbuffer
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, stencilbuffer_);
// malloc
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX, _width, _height);
// attach to framebuffer object
if ( bind() )
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, stencilbuffer_);
// check status
checkFramebufferStatus();
// normal render mode
unbind();
}
//-----------------------------------------------------------------------------
bool
FBO::
bind()
{
if ( !fbo_ )
return false;
// bind framebuffer object
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fbo_ );
return true;
}
//-----------------------------------------------------------------------------
void
FBO::
unbind()
{
//set to normal rendering
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
}
//-----------------------------------------------------------------------------
bool
FBO::
checkFramebufferStatus()
{
GLenum status;
status = ( GLenum ) glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT );
std::cout << "Framebuffer status: " << status << std::endl;
switch ( status )
{
case GL_FRAMEBUFFER_COMPLETE_EXT:
std::cout << "Framebuffer ok\n";
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
std::cout << " Framebuffer incomplete attachment\n";
break;
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
std::cout << "Unsupported framebuffer format\n";
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
std::cout << "Framebuffer incomplete, missing attachment\n";
break;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
std::cout << "Framebuffer incomplete, attached images must have same dimensions\n";
break;
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
std::cout << "Framebuffer incomplete, attached images must have same format\n";
break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
std::cout << "Framebuffer incomplete, missing draw buffer\n";
break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
std::cout << "Framebuffer incomplete, missing read buffer\n";
break;
default:
std::cout << "Unhandled case\n";
break;
}
return ( status == GL_FRAMEBUFFER_COMPLETE_EXT );
}
//=============================================================================
} // namespace ACG
//=============================================================================
//=============================================================================
//
// CLASS FBO
//
// Author: Dominik Sibbing <sibbing@cs.rwth-aachen.de>
//
// Version: $Revision: 1$
// Date: $Date: 2008$
//
//=============================================================================
#ifndef ACG_FBO_HH
#define ACG_FBO_HH
//== INCLUDES =================================================================
#include <iostream>
#include <stdlib.h>
#include <ACG/GL/gl.hh>
//== FORWARDDECLARATIONS ======================================================
//== NAMESPACES ===============================================================
namespace ACG {
//== CLASS DEFINITION =========================================================
/** \class FBO FBO.hh <ACG/.../FBO.hh>
Brief Description.
A more elaborate description follows.
*/
class FBO
{
public:
/// Default constructor
FBO() {}
/// Destructor
~FBO();
/// function to generate the framebuffer object
void init();
/// function to attach a texture to fbo
void attachTexture2D( GLenum _attachment, GLuint _texture );
/// function to add a depth buffer to the fbo
void addDepthBuffer( GLuint _width, GLuint _height );
/// function to add a stencil buffer to the fbo
void addStencilBuffer( GLuint _width, GLuint _height );
/// bind the fbo and sets it as rendertarget
bool bind();
/// unbind fbo, go to normal rendering mode
void unbind();
/// function to check the framebuffer status
bool checkFramebufferStatus();
private:
/// handle of frame buffer object
GLuint fbo_;
/// depthbuffer
GLuint depthbuffer_;
/// stencilbuffer
GLuint stencilbuffer_;
};
//=============================================================================
} // namespace ACG
//=============================================================================
#endif // ACG_FBO_HH defined
//=============================================================================
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment