examples/eVolve/window.cpp

00001 
00002 /* Copyright (c) 2007-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #include "window.h"
00019 #include "pipe.h"
00020 
00021 using namespace std;
00022 
00023 namespace eVolve
00024 {
00025 
00026 bool Window::configInit( const uint32_t initID )
00027 {
00028     // Enforce alpha channel, since we need one for rendering
00029     setIAttribute( IATTR_PLANES_ALPHA, 8 );
00030 
00031     return eq::Window::configInit( initID );
00032 }
00033 
00034 bool Window::configInitGL( const uint32_t initID )
00035 {
00036     Pipe*     pipe     = static_cast<Pipe*>( getPipe() );
00037     Renderer* renderer = pipe->getRenderer();
00038 
00039     if( !renderer )
00040         return false;
00041 
00042     if( !GLEW_ARB_shader_objects )
00043     {
00044         setErrorMessage( "eVolve needs GL_ARB_shader_objects extension" );
00045         return false;
00046     }
00047     if( !GLEW_EXT_blend_func_separate )
00048     {
00049         setErrorMessage( "eVolve needs GL_EXT_blend_func_separate extension" );
00050         return false;
00051     }
00052     if( !GLEW_ARB_multitexture )
00053     {
00054         setErrorMessage( "eVolve needs GLEW_ARB_multitexture extension" );
00055         return false;
00056     }
00057 
00058     glEnable( GL_SCISSOR_TEST ); // needed to constrain channel viewport
00059 
00060     glClear( GL_COLOR_BUFFER_BIT );
00061     swapBuffers();
00062     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
00063 
00064     renderer->glewSetContext( glewGetContext( ));
00065 
00066     if( !renderer->loadShaders( ))
00067     {
00068         setErrorMessage( "Can't load shaders" );
00069         return false;
00070     }
00071 
00072     _loadLogo();
00073     return true;
00074 }
00075 
00076 static const char* _logoTextureName = "eVolve_logo";
00077 
00078 void Window::_loadLogo()
00079 {
00080     eq::Window::ObjectManager* objects = getObjectManager();
00081 
00082     if( objects->getTexture( _logoTextureName ) != 
00083         eq::Window::ObjectManager::INVALID )
00084     {
00085         // Already loaded by first window
00086         const eq::Pipe* pipe        = getPipe();
00087         const Window*   firstWindow = static_cast< Window* >
00088                                           ( pipe->getWindows()[0] );
00089         
00090         _logoTexture = firstWindow->_logoTexture;
00091         _logoSize    = firstWindow->_logoSize;
00092         return;
00093     }
00094 
00095     eq::Image image;
00096     if( !image.readImage( "logo.rgb", eq::Frame::BUFFER_COLOR ) &&
00097         !image.readImage( "examples/eVolve/logo.rgb", eq::Frame::BUFFER_COLOR ))
00098     {
00099         EQWARN << "Can't load overlay logo 'logo.rgb'" << endl;
00100         return;
00101     }
00102 
00103     _logoTexture = objects->newTexture( _logoTextureName );
00104     EQASSERT( _logoTexture != eq::Window::ObjectManager::INVALID );
00105 
00106     const eq::PixelViewport& pvp = image.getPixelViewport();
00107     _logoSize.x() = pvp.w;
00108     _logoSize.y() = pvp.h;
00109 
00110     glBindTexture( GL_TEXTURE_RECTANGLE_ARB, _logoTexture );
00111     glTexImage2D( GL_TEXTURE_RECTANGLE_ARB, 0, 
00112                   image.getFormat( eq::Frame::BUFFER_COLOR ),
00113                   _logoSize.x(), _logoSize.y(), 0,
00114                   image.getFormat( eq::Frame::BUFFER_COLOR ), 
00115                   image.getType( eq::Frame::BUFFER_COLOR ),
00116                   image.getPixelPointer( eq::Frame::BUFFER_COLOR ));
00117 
00118     EQINFO << "Created logo texture of size " << _logoSize << endl;
00119 }
00120 
00121 
00122 void Window::swapBuffers()
00123 {
00124     const Pipe*              pipe      = static_cast<Pipe*>( getPipe( ));
00125     const FrameData::Data&   frameData = pipe->getFrameData();
00126     const eq::ChannelVector& channels  = getChannels();
00127 
00128     if( frameData.statistics && !channels.empty( ))
00129         EQ_GL_CALL( channels.back()->drawStatistics( ));
00130 
00131     eq::Window::swapBuffers();
00132 }
00133 }
Generated on Mon Aug 10 18:58:41 2009 for Equalizer 0.9 by  doxygen 1.5.8