Equalizer
1.4.1
|
00001 00002 /* Copyright (c) 2009-2011, Maxim Makhinya <maxmah@gmail.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 00030 #include "eqAsync.h" 00031 00032 namespace eqAsync 00033 { 00034 00035 bool Window::configInitGL( const eq::uint128_t& initID ) 00036 { 00037 if( !eq::Window::configInitGL( initID )) 00038 return false; 00039 00040 Pipe* pipe = static_cast<Pipe*>( getPipe( )); 00041 pipe->startAsyncFetcher( this ); 00042 00043 return true; 00044 } 00045 00046 void Pipe::startAsyncFetcher( Window* wnd ) 00047 { 00048 if( _initialized ) 00049 return; 00050 _initialized = true; 00051 LBINFO << "initialize async fetcher: " << this << ", " << wnd << std::endl; 00052 _asyncFetcher.setup( wnd ); 00053 _asyncFetcher.start(); 00054 _asyncFetcher.getTextureId(); // wait for initialization to finish 00055 } 00056 00057 00058 void Pipe::frameStart( const eq::uint128_t& frameID, const uint32_t frameNumber) 00059 { 00060 eq::Pipe::frameStart( frameID, frameNumber ); 00061 00062 const void* oldKey = _txId.key; 00063 if( _asyncFetcher.tryGetTextureId( _txId )) 00064 { 00065 if( oldKey != 0 ) 00066 _asyncFetcher.deleteTexture( oldKey ); 00067 00068 LBINFO << "new texture generated " << _txId.key << std::endl; 00069 } 00070 } 00071 00072 00073 bool Pipe::configExit() 00074 { 00075 LBINFO << "exit async fetcher: " << this << std::endl; 00076 _asyncFetcher.deleteTexture( 0 ); //exit async fetcher 00077 _asyncFetcher.join(); 00078 00079 return eq::Pipe::configExit(); 00080 } 00081 00082 00083 void Channel::frameDraw( const eq::uint128_t& spin ) 00084 { 00085 // setup OpenGL State 00086 eq::Channel::frameDraw( spin ); 00087 00088 Pipe* pipe = static_cast< Pipe* >( getPipe( )); 00089 GLuint txId = pipe->getTextureId(); 00090 00091 if( txId ) 00092 { 00093 glEnable( GL_TEXTURE_2D ); 00094 glBindTexture( GL_TEXTURE_2D, txId ); 00095 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); 00096 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); 00097 } 00098 00099 const float lightPos[] = { 0.0f, 0.0f, 1.0f, 0.0f }; 00100 glLightfv( GL_LIGHT0, GL_POSITION, lightPos ); 00101 00102 const float lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f }; 00103 glLightfv( GL_LIGHT0, GL_AMBIENT, lightAmbient ); 00104 00105 // rotate scene around the origin 00106 glRotatef( static_cast< float >( spin.low( )) * 0.1f, 1.0f, 0.5f, 0.25f ); 00107 00108 float tMin = 0.f; 00109 float tMax = 1.f; 00110 // render six axis-aligned colored quads around the origin 00111 for( int i = 0; i < 6; i++ ) 00112 { 00113 glColor3f( i&1 ? 0.5f : 1.0f, i&2 ? 1.0f : 0.5f, i&4 ? 1.0f : 0.5f ); 00114 00115 glNormal3f( 0.0f, 0.0f, 1.0f ); 00116 glBegin( GL_TRIANGLE_STRIP ); 00117 glTexCoord2f( tMax, tMax ); 00118 glVertex3f( .7f, .7f, -1.0f ); 00119 glTexCoord2f( tMin, tMax ); 00120 glVertex3f( -.7f, .7f, -1.0f ); 00121 glTexCoord2f( tMax, tMin ); 00122 glVertex3f( .7f, -.7f, -1.0f ); 00123 glTexCoord2f( tMin, tMin ); 00124 glVertex3f( -.7f, -.7f, -1.0f ); 00125 glEnd(); 00126 00127 if( i < 3 ) 00128 glRotatef( 90.0f, 0.0f, 1.0f, 0.0f ); 00129 else if( i == 3 ) 00130 glRotatef( 90.0f, 1.0f, 0.0f, 0.0f ); 00131 else 00132 glRotatef( 180.0f, 1.0f, 0.0f, 0.0f ); 00133 } 00134 00135 if( txId ) 00136 { 00137 glDisable( GL_TEXTURE_2D ); 00138 } 00139 } 00140 00141 } // namespace eqAsync