accumBufferObject.cpp

00001 
00002 /* Copyright (c) 2009-2010, Stefan Eilemann <eile@equalizergraphics.com>
00003  *               2009, Sarah Amsellem <sarah.amsellem@gmail.com>
00004  *
00005  * This library is free software; you can redistribute it and/or modify it under
00006  * the terms of the GNU Lesser General Public License version 2.1 as published
00007  * by the Free Software Foundation.
00008  *  
00009  * This library is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00012  * details.
00013  * 
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this library; if not, write to the Free Software Foundation, Inc.,
00016  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 
00019 #include "accumBufferObject.h"
00020 
00021 namespace eq
00022 {
00023 namespace util
00024 {
00025 
00026 AccumBufferObject::AccumBufferObject( GLEWContext* glewContext )
00027     : FrameBufferObject( glewContext )
00028     , _texture( 0 )
00029     , _pvp( 0, 0, 0, 0 )
00030 {
00031 }
00032 
00033 AccumBufferObject::~AccumBufferObject()
00034 {
00035     exit();
00036 }
00037 
00038 bool AccumBufferObject::init( const PixelViewport& pvp,
00039                               GLuint textureFormat )
00040 {
00041     _texture = new Texture( glewGetContext( ));
00042     _texture->setFormat( textureFormat );
00043     _pvp = pvp;
00044 
00045     setColorFormat( GL_RGBA32F );
00046     if( FrameBufferObject::init( pvp.w, pvp.h, 0, 0 ))
00047     {
00048         unbind();
00049         return true;
00050     }
00051 
00052     exit();
00053     return false;
00054 }
00055 
00056 void AccumBufferObject::exit()
00057 {
00058     if( _texture )
00059         _texture->flush();
00060 
00061     delete _texture;
00062     _texture = 0;
00063 
00064     FrameBufferObject::exit();
00065 }
00066 
00067 void AccumBufferObject::load( GLfloat value )
00068 {
00069     EQ_GL_ERROR( "before AccumBufferObject::load" );
00070     _texture->copyFromFrameBuffer( _pvp );
00071 
00072     bind();
00073     _drawQuadWithTexture( _texture, getPixelViewport(), value );
00074     unbind();
00075     EQ_GL_ERROR( "after AccumBufferObject::load" );
00076 }
00077 
00078 void AccumBufferObject::accum( GLfloat value )
00079 {
00080     _texture->copyFromFrameBuffer( _pvp );
00081 
00082     bind();
00083     glEnable( GL_BLEND );
00084     glBlendFunc( GL_ONE, GL_ONE );
00085 
00086     _drawQuadWithTexture( _texture, getPixelViewport(), value );
00087 
00088     glBlendFunc( GL_ONE, GL_ZERO );
00089     glDisable( GL_BLEND );
00090     unbind();
00091 }
00092 
00093 void AccumBufferObject::display( GLfloat value )
00094 {
00095     _drawQuadWithTexture( getColorTextures()[0], _pvp, value );
00096 }
00097 
00098 void AccumBufferObject::_drawQuadWithTexture( Texture* texture, 
00099                                               const PixelViewport& pvp, 
00100                                               GLfloat value )
00101 {
00102     texture->bind();
00103 
00104     glDepthMask( false );
00105     glDisable( GL_LIGHTING );
00106     glEnable( GL_TEXTURE_RECTANGLE_ARB );
00107     glTexParameteri( GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
00108                      GL_CLAMP_TO_EDGE );
00109     glTexParameteri( GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
00110                      GL_CLAMP_TO_EDGE );
00111     glTexParameteri( GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
00112                      GL_NEAREST );
00113     glTexParameteri( GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
00114                      GL_NEAREST );
00115 
00116     glColor3f( value, value, value );
00117 
00118     const float startX = static_cast< const float >( pvp.x );
00119     const float endX   = static_cast< const float >( pvp.x + pvp.w );
00120     const float startY = static_cast< const float >( pvp.y );
00121     const float endY   = static_cast< const float >( pvp.y + pvp.h );
00122 
00123     glBegin( GL_QUADS );
00124         glTexCoord2f( 0.0f, 0.0f );
00125         glVertex3f( startX, startY, 0.0f );
00126 
00127         glTexCoord2f( static_cast< float >( pvp.w ), 0.0f );
00128         glVertex3f( endX, startY, 0.0f );
00129 
00130         glTexCoord2f( static_cast<float>( pvp.w ), static_cast<float>( pvp.h ));
00131         glVertex3f( endX, endY, 0.0f );
00132 
00133         glTexCoord2f( 0.0f, static_cast< float >( pvp.h ));
00134         glVertex3f( startX, endY, 0.0f );
00135     glEnd();
00136 
00137     // restore state
00138     glDisable( GL_TEXTURE_RECTANGLE_ARB );
00139     glDepthMask( true );
00140 }
00141 
00142 }
00143 }
00144 
Generated on Sat Feb 6 12:59:39 2010 for Equalizer 0.9.1 by  doxygen 1.6.1