Equalizer 1.0

eVolve/window.cpp

00001 
00002 /* Copyright (c) 2007-2011, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *
00007  * - Redistributions of source code must retain the above copyright notice, this
00008  *   list of conditions and the following disclaimer.
00009  * - Redistributions in binary form must reproduce the above copyright notice,
00010  *   this list of conditions and the following disclaimer in the documentation
00011  *   and/or other materials provided with the distribution.
00012  * - Neither the name of Eyescale Software GmbH nor the names of its
00013  *   contributors may be used to endorse or promote products derived from this
00014  *   software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00026  * POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #include "window.h"
00030 
00031 #include "error.h"
00032 #include "pipe.h"
00033 
00034 namespace eVolve
00035 {
00036 
00037 bool Window::configInit( const eq::uint128_t& initID )
00038 {
00039     // Enforce alpha channel, since we need one for rendering
00040     setIAttribute( IATTR_PLANES_ALPHA, 8 );
00041 
00042     return eq::Window::configInit( initID );
00043 }
00044 
00045 bool Window::configInitGL( const eq::uint128_t& initID )
00046 {
00047     Pipe*     pipe     = static_cast<Pipe*>( getPipe() );
00048     Renderer* renderer = pipe->getRenderer();
00049 
00050     if( !renderer )
00051         return false;
00052 
00053     if( !GLEW_ARB_shader_objects )
00054     {
00055         setError( ERROR_EVOLVE_ARB_SHADER_OBJECTS_MISSING );
00056         return false;
00057     }
00058     if( !GLEW_EXT_blend_func_separate )
00059     {
00060         setError( ERROR_EVOLVE_EXT_BLEND_FUNC_SEPARATE_MISSING );
00061         return false;
00062     }
00063     if( !GLEW_ARB_multitexture )
00064     {
00065         setError( ERROR_EVOLVE_ARB_MULTITEXTURE_MISSING );
00066         return false;
00067     }
00068 
00069     glEnable( GL_SCISSOR_TEST ); // needed to constrain channel viewport
00070 
00071     glClear( GL_COLOR_BUFFER_BIT );
00072     swapBuffers();
00073     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
00074 
00075     renderer->glewSetContext( glewGetContext( ));
00076 
00077     if( !renderer->loadShaders( ))
00078     {
00079         setError( ERROR_EVOLVE_LOADSHADERS_FAILED );
00080         return false;
00081     }
00082 
00083     _loadLogo();
00084     return true;
00085 }
00086 
00087 namespace
00088 {
00089 #ifdef EQ_RELEASE
00090 static const std::string _logoTextureName = std::string( EQ_INSTALL_DIR ) +
00091                                  std::string( "share/Equalizer/data/logo.rgb" );
00092 #else
00093 static const std::string _logoTextureName = std::string( EQ_SOURCE_DIR ) +
00094                                       std::string( "examples/eVolve/logo.rgb" );
00095 #endif
00096 }
00097 
00098 void Window::_loadLogo()
00099 {
00100     if( !GLEW_ARB_texture_rectangle )
00101     {
00102         EQWARN << "Can't load overlay logo, GL_ARB_texture_rectangle not "
00103                << "available" << std::endl;
00104         return;
00105     }
00106 
00107     eq::Window::ObjectManager* om = getObjectManager();
00108     _logoTexture = om->getEqTexture( _logoTextureName.c_str( ));
00109     if( _logoTexture )
00110         return;
00111 
00112     eq::Image image;
00113     if( !image.readImage( _logoTextureName, eq::Frame::BUFFER_COLOR ))
00114     {
00115         EQWARN << "Can't load overlay logo " << _logoTextureName << std::endl;
00116         return;
00117     }
00118 
00119     _logoTexture = om->newEqTexture( _logoTextureName.c_str(),
00120                                      GL_TEXTURE_RECTANGLE_ARB );
00121     EQASSERT( _logoTexture );
00122     
00123     image.upload(eq::Frame::BUFFER_COLOR, _logoTexture, eq::Vector2i::ZERO, om);
00124     EQVERB << "Created logo texture of size " << _logoTexture->getWidth() << "x"
00125            << _logoTexture->getHeight() << std::endl;
00126 }
00127 
00128 
00129 void Window::swapBuffers()
00130 {
00131     const Pipe*         pipe      = static_cast<Pipe*>( getPipe( ));
00132     const FrameData&    frameData = pipe->getFrameData();
00133     const eq::Channels& channels  = getChannels();
00134 
00135     if( frameData.useStatistics() && !channels.empty( ))
00136         EQ_GL_CALL( channels.back()->drawStatistics( ));
00137 
00138     eq::Window::swapBuffers();
00139 }
00140 }
Generated on Sun May 8 2011 19:11:08 for Equalizer 1.0 by  doxygen 1.7.3