Equalizer 1.0
|
00001 00002 /* Copyright (c) 2007-2011, Stefan Eilemann <eile@equalizergraphics.com> 00003 * 2007, Tobias Wolf <twolf@access.unizh.ch> 00004 * 2010, Cedric Stalder <cedric.stalder@gmail.com> 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * - Redistributions of source code must retain the above copyright notice, this 00010 * list of conditions and the following disclaimer. 00011 * - Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * - Neither the name of Eyescale Software GmbH nor the names of its 00015 * contributors may be used to endorse or promote products derived from this 00016 * software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00021 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00022 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00028 * POSSIBILITY OF SUCH DAMAGE. 00029 */ 00030 00031 #include "window.h" 00032 #include "pipe.h" 00033 #include "config.h" 00034 00035 #include "fragmentShader.glsl.h" 00036 #include "vertexShader.glsl.h" 00037 00038 #include <fstream> 00039 #include <sstream> 00040 00041 namespace eqPly 00042 { 00043 00044 bool Window::configInitSystemWindow( const eq::uint128_t& initID ) 00045 { 00046 #ifndef Darwin 00047 if( !eq::Window::configInitSystemWindow( initID )) 00048 return false; 00049 00050 // OpenGL version is less than 2.0. 00051 if( !GLEW_EXT_framebuffer_object) 00052 { 00053 if( getDrawableConfig().accumBits ) 00054 return true; 00055 00056 configExitSystemWindow(); 00057 #endif 00058 00059 // try with 64 bit accum buffer 00060 setIAttribute( IATTR_PLANES_ACCUM, 16 ); 00061 if( eq::Window::configInitSystemWindow( initID )) 00062 return true; 00063 00064 // no anti-aliasing possible 00065 setIAttribute( IATTR_PLANES_ACCUM, eq::AUTO ); 00066 00067 return eq::Window::configInitSystemWindow( initID ); 00068 00069 #ifndef Darwin 00070 } 00071 00072 return true; 00073 #endif 00074 } 00075 00076 bool Window::configInitGL( const eq::uint128_t& initID ) 00077 { 00078 if( !eq::Window::configInitGL( initID )) 00079 return false; 00080 00081 glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, 1 ); 00082 glEnable( GL_CULL_FACE ); // OPT - produces sparser images in DB mode 00083 glCullFace( GL_BACK ); 00084 00085 EQASSERT( !_state ); 00086 _state = new VertexBufferState( getObjectManager( )); 00087 00088 const Config* config = static_cast< const Config* >( getConfig( )); 00089 const InitData& initData = config->getInitData(); 00090 00091 if( initData.showLogo( )) 00092 _loadLogo(); 00093 00094 if( initData.useGLSL() ) 00095 _loadShaders(); 00096 00097 return true; 00098 } 00099 00100 bool Window::configExitGL() 00101 { 00102 if( _state && !_state->isShared( )) 00103 _state->deleteAll(); 00104 00105 delete _state; 00106 _state = 0; 00107 00108 return eq::Window::configExitGL(); 00109 } 00110 00111 namespace 00112 { 00113 #ifdef EQ_RELEASE 00114 static const std::string _logoTextureName = std::string( EQ_INSTALL_DIR ) + 00115 std::string( "share/Equalizer/data/logo.rgb" ); 00116 #else 00117 static const std::string _logoTextureName = std::string( EQ_SOURCE_DIR ) + 00118 std::string( "examples/eqPly/logo.rgb" ); 00119 #endif 00120 } 00121 00122 void Window::_loadLogo() 00123 { 00124 if( !GLEW_ARB_texture_rectangle ) 00125 { 00126 EQWARN << "Can't load overlay logo, GL_ARB_texture_rectangle not " 00127 << "available" << std::endl; 00128 return; 00129 } 00130 00131 eq::Window::ObjectManager* om = getObjectManager(); 00132 _logoTexture = om->getEqTexture( _logoTextureName.c_str( )); 00133 if( _logoTexture ) 00134 return; 00135 00136 eq::Image image; 00137 if( !image.readImage( _logoTextureName, eq::Frame::BUFFER_COLOR )) 00138 { 00139 EQWARN << "Can't load overlay logo " << _logoTextureName << std::endl; 00140 return; 00141 } 00142 00143 _logoTexture = om->newEqTexture( _logoTextureName.c_str(), 00144 GL_TEXTURE_RECTANGLE_ARB ); 00145 EQASSERT( _logoTexture ); 00146 00147 image.upload(eq::Frame::BUFFER_COLOR, _logoTexture, eq::Vector2i::ZERO, om); 00148 EQVERB << "Created logo texture of size " << _logoTexture->getWidth() << "x" 00149 << _logoTexture->getHeight() << std::endl; 00150 } 00151 00152 void Window::_loadShaders() 00153 { 00154 if( _state->getShader( vertexShader_glsl ) != 00155 VertexBufferState::INVALID ) 00156 { 00157 // already loaded 00158 return; 00159 } 00160 00161 // Check if functions are available 00162 if( !GLEW_VERSION_2_0 ) 00163 { 00164 EQWARN << "Shader function pointers missing, using fixed function " 00165 << "pipeline" << std::endl; 00166 return; 00167 } 00168 00169 const GLuint vShader = _state->newShader( vertexShader_glsl, 00170 GL_VERTEX_SHADER ); 00171 EQASSERT( vShader != VertexBufferState::INVALID ); 00172 const GLchar* vShaderPtr = vertexShader_glsl; 00173 glShaderSource( vShader, 1, &vShaderPtr, 0 ); 00174 glCompileShader( vShader ); 00175 00176 GLint status; 00177 glGetShaderiv( vShader, GL_COMPILE_STATUS, &status ); 00178 if( !status ) 00179 { 00180 EQWARN << "Failed to compile vertex shader" << std::endl; 00181 return; 00182 } 00183 00184 const GLuint fShader = 00185 _state->newShader( fragmentShader_glsl, GL_FRAGMENT_SHADER ); 00186 EQASSERT( fShader != VertexBufferState::INVALID ); 00187 const GLchar* fShaderPtr = fragmentShader_glsl; 00188 glShaderSource( fShader, 1, &fShaderPtr, 0 ); 00189 glCompileShader( fShader ); 00190 glGetShaderiv( fShader, GL_COMPILE_STATUS, &status ); 00191 if( !status ) 00192 { 00193 EQWARN << "Failed to compile fragment shader" << std::endl; 00194 return; 00195 } 00196 00197 const GLuint program = _state->newProgram( getPipe() ); 00198 EQASSERT( program != VertexBufferState::INVALID ); 00199 glAttachShader( program, vShader ); 00200 glAttachShader( program, fShader ); 00201 glLinkProgram( program ); 00202 glGetProgramiv( program, GL_LINK_STATUS, &status ); 00203 if( !status ) 00204 { 00205 EQWARN << "Failed to link shader program" << std::endl; 00206 return; 00207 } 00208 00209 // turn off OpenGL lighting if we are using our own shaders 00210 glDisable( GL_LIGHTING ); 00211 00212 EQINFO << "Shaders loaded successfully" << std::endl; 00213 } 00214 00215 void Window::frameStart( const eq::uint128_t& frameID, const uint32_t frameNumber ) 00216 { 00217 const Pipe* pipe = static_cast<Pipe*>( getPipe( )); 00218 const FrameData& frameData = pipe->getFrameData(); 00219 00220 _state->setRenderMode( frameData.getRenderMode( )); 00221 eq::Window::frameStart( frameID, frameNumber ); 00222 } 00223 00224 }