Equalizer
1.4.1
|
00001 00002 /* Copyright (c) 2007-2012, 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 00033 #include "config.h" 00034 #include "pipe.h" 00035 #include "vertexBufferState.h" 00036 00037 #include "fragmentShader.glsl.h" 00038 #include "vertexShader.glsl.h" 00039 00040 #include <fstream> 00041 #include <sstream> 00042 00043 namespace eqPly 00044 { 00045 00046 bool Window::configInitSystemWindow( const eq::uint128_t& initID ) 00047 { 00048 #ifndef Darwin 00049 if( !eq::Window::configInitSystemWindow( initID )) 00050 return false; 00051 00052 // OpenGL version is less than 2.0. 00053 if( !GLEW_EXT_framebuffer_object ) 00054 { 00055 if( getDrawableConfig().accumBits ) 00056 return true; 00057 00058 configExitSystemWindow(); 00059 #endif 00060 // try with 64 bit accum buffer 00061 setIAttribute( IATTR_PLANES_ACCUM, 16 ); 00062 if( eq::Window::configInitSystemWindow( initID )) 00063 return true; 00064 00065 // no anti-aliasing possible 00066 setIAttribute( IATTR_PLANES_ACCUM, eq::AUTO ); 00067 00068 return eq::Window::configInitSystemWindow( initID ); 00069 00070 #ifndef Darwin 00071 } 00072 00073 return true; 00074 #endif 00075 } 00076 00077 bool Window::configInitGL( const eq::uint128_t& initID ) 00078 { 00079 if( !eq::Window::configInitGL( initID )) 00080 return false; 00081 00082 glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, 1 ); 00083 glEnable( GL_CULL_FACE ); // OPT - produces sparser images in DB mode 00084 glCullFace( GL_BACK ); 00085 00086 LBASSERT( !_state ); 00087 _state = new VertexBufferState( getObjectManager( )); 00088 00089 const Config* config = static_cast< const Config* >( getConfig( )); 00090 const InitData& initData = config->getInitData(); 00091 00092 if( initData.showLogo( )) 00093 _loadLogo(); 00094 00095 if( initData.useGLSL() ) 00096 _loadShaders(); 00097 00098 return true; 00099 } 00100 00101 bool Window::configExitGL() 00102 { 00103 if( _state && !_state->isShared( )) 00104 _state->deleteAll(); 00105 00106 delete _state; 00107 _state = 0; 00108 00109 return eq::Window::configExitGL(); 00110 } 00111 00112 namespace 00113 { 00114 #ifdef EQ_RELEASE 00115 # ifdef _WIN32 // final INSTALL_DIR is not known at compile time 00116 static const std::string _logoTextureName = 00117 std::string( "../share/Equalizer/data/logo.rgb" ); 00118 # else 00119 static const std::string _logoTextureName = std::string( EQ_INSTALL_DIR ) + 00120 std::string( "share/Equalizer/data/logo.rgb" ); 00121 # endif 00122 #else 00123 static const std::string _logoTextureName = std::string( EQ_SOURCE_DIR ) + 00124 std::string( "examples/eqPly/logo.rgb" ); 00125 #endif 00126 } 00127 00128 void Window::_loadLogo() 00129 { 00130 if( !GLEW_ARB_texture_rectangle ) 00131 { 00132 LBWARN << "Can't load overlay logo, GL_ARB_texture_rectangle not " 00133 << "available" << std::endl; 00134 return; 00135 } 00136 00137 eq::Window::ObjectManager* om = getObjectManager(); 00138 _logoTexture = om->getEqTexture( _logoTextureName.c_str( )); 00139 if( _logoTexture ) 00140 return; 00141 00142 eq::Image image; 00143 if( !image.readImage( _logoTextureName, eq::Frame::BUFFER_COLOR )) 00144 { 00145 LBWARN << "Can't load overlay logo " << _logoTextureName << std::endl; 00146 return; 00147 } 00148 00149 _logoTexture = om->newEqTexture( _logoTextureName.c_str(), 00150 GL_TEXTURE_RECTANGLE_ARB ); 00151 LBASSERT( _logoTexture ); 00152 00153 image.upload(eq::Frame::BUFFER_COLOR, _logoTexture, eq::Vector2i::ZERO, om); 00154 image.deleteGLObjects( om ); 00155 LBVERB << "Created logo texture of size " << _logoTexture->getWidth() << "x" 00156 << _logoTexture->getHeight() << std::endl; 00157 } 00158 00159 void Window::_loadShaders() 00160 { 00161 if( _state->getShader( vertexShader_glsl ) != VertexBufferState::INVALID ) 00162 // already loaded 00163 return; 00164 00165 // Check if functions are available 00166 if( !GLEW_VERSION_2_0 ) 00167 { 00168 LBWARN << "Shader function pointers missing, using fixed function " 00169 << "pipeline" << std::endl; 00170 return; 00171 } 00172 00173 const GLuint vShader = _state->newShader( vertexShader_glsl, 00174 GL_VERTEX_SHADER ); 00175 LBASSERT( vShader != VertexBufferState::INVALID ); 00176 const GLchar* vShaderPtr = vertexShader_glsl; 00177 glShaderSource( vShader, 1, &vShaderPtr, 0 ); 00178 glCompileShader( vShader ); 00179 00180 GLint status; 00181 glGetShaderiv( vShader, GL_COMPILE_STATUS, &status ); 00182 if( !status ) 00183 { 00184 LBWARN << "Failed to compile vertex shader" << std::endl; 00185 return; 00186 } 00187 00188 const GLuint fShader = 00189 _state->newShader( fragmentShader_glsl, GL_FRAGMENT_SHADER ); 00190 LBASSERT( fShader != VertexBufferState::INVALID ); 00191 const GLchar* fShaderPtr = fragmentShader_glsl; 00192 glShaderSource( fShader, 1, &fShaderPtr, 0 ); 00193 glCompileShader( fShader ); 00194 glGetShaderiv( fShader, GL_COMPILE_STATUS, &status ); 00195 if( !status ) 00196 { 00197 LBWARN << "Failed to compile fragment shader" << std::endl; 00198 return; 00199 } 00200 00201 const GLuint program = _state->newProgram( getPipe() ); 00202 LBASSERT( program != VertexBufferState::INVALID ); 00203 glAttachShader( program, vShader ); 00204 glAttachShader( program, fShader ); 00205 glLinkProgram( program ); 00206 glGetProgramiv( program, GL_LINK_STATUS, &status ); 00207 if( !status ) 00208 { 00209 LBWARN << "Failed to link shader program" << std::endl; 00210 return; 00211 } 00212 00213 // turn off OpenGL lighting if we are using our own shaders 00214 glDisable( GL_LIGHTING ); 00215 00216 LBINFO << "Shaders loaded successfully" << std::endl; 00217 } 00218 00219 void Window::frameStart( const eq::uint128_t& frameID, const uint32_t frameNumber ) 00220 { 00221 const Pipe* pipe = static_cast<Pipe*>( getPipe( )); 00222 const FrameData& frameData = pipe->getFrameData(); 00223 00224 _state->setRenderMode( frameData.getRenderMode( )); 00225 eq::Window::frameStart( frameID, frameNumber ); 00226 } 00227 00228 }