Equalizer
1.2.1
|
00001 00002 /* Copyright (c) 2005-2010, 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 "eqPly.h" 00030 00031 #include "config.h" 00032 #include "localInitData.h" 00033 00034 #include <stdlib.h> 00035 00036 namespace eqPly 00037 { 00038 00039 namespace 00040 { 00041 static const std::string _help( 00042 std::string( "eqPly - Equalizer polygonal rendering example\n" ) + 00043 std::string( "\tRun-time commands:\n" ) + 00044 std::string( "\t\tLeft Mouse Button: Rotate model\n" ) + 00045 std::string( "\t\tMiddle Mouse Button: Move model in X, Y\n" ) + 00046 std::string( "\t\tRight Mouse Button: Move model in Z\n" ) + 00047 std::string( "\t\t<Cursor Keys>: Move head in X,Y plane\n" )+ 00048 std::string( "\t\t<Page Up,Down>: Move head in Z\n" )+ 00049 std::string( "\t\t<Esc>, All Mouse Buttons: Exit program\n" ) + 00050 std::string( "\t\t<Space>: Reset camera (twice for Immersive Setup)\n" ) + 00051 std::string( "\t\tF1, h: Toggle help overlay\n" ) + 00052 std::string( "\t\to: Toggle perspective/orthographic\n" 00053 ) + 00054 std::string( "\t\ts: Toggle statistics overlay\n" ) + 00055 std::string( "\t\tw: Toggle wireframe mode\n" ) + 00056 std::string( "\t\td: Toggle color demo mode\n" ) + 00057 std::string( "\t\ti: Toggle usage of idle anti-aliasing\n" ) + 00058 std::string( "\t\tq, Q: Adjust non-idle image quality\n" ) + 00059 std::string( "\t\tn: Toggle navigation mode (trackball, walk)\n" ) + 00060 std::string( "\t\tr: Switch rendering mode (display list, VBO, immediate)\n" ) + 00061 std::string( "\t\tu: Toggle image compression\n" ) + 00062 std::string( "\t\tc: Switch active canvas\n" ) + 00063 std::string( "\t\tv: Switch active view\n" ) + 00064 std::string( "\t\tm: Switch model for active view\n" ) + 00065 std::string( "\t\tl: Switch layout for active canvas\n" ) + 00066 std::string( "\t\ta: Add active stereo window\n" ) + 00067 std::string( "\t\tp: Add passive stereo window\n" ) + 00068 std::string( "\t\tx: Remove window\n" ) 00069 ); 00070 } 00071 00072 const std::string& EqPly::getHelp() 00073 { 00074 return _help; 00075 } 00076 00077 EqPly::EqPly( const LocalInitData& initData ) 00078 : _initData( initData ) 00079 {} 00080 00081 int EqPly::run() 00082 { 00083 // 1. connect to server 00084 eq::ServerPtr server = new eq::Server; 00085 if( !connectServer( server )) 00086 { 00087 EQERROR << "Can't open server" << std::endl; 00088 return EXIT_FAILURE; 00089 } 00090 00091 // 2. choose config 00092 eq::ConfigParams configParams; 00093 Config* config = static_cast<Config*>(server->chooseConfig( configParams )); 00094 00095 if( !config ) 00096 { 00097 EQERROR << "No matching config on server" << std::endl; 00098 disconnectServer( server ); 00099 return EXIT_FAILURE; 00100 } 00101 00102 // 3. init config 00103 co::base::Clock clock; 00104 00105 config->setInitData( _initData ); 00106 if( !config->init( )) 00107 { 00108 EQWARN << "Error during initialization: " << config->getError() 00109 << std::endl; 00110 server->releaseConfig( config ); 00111 disconnectServer( server ); 00112 return EXIT_FAILURE; 00113 } 00114 if( config->getError( )) 00115 EQWARN << "Error during initialization: " << config->getError() 00116 << std::endl; 00117 00118 EQLOG( LOG_STATS ) << "Config init took " << clock.getTimef() << " ms" 00119 << std::endl; 00120 00121 // 4. run main loop 00122 uint32_t maxFrames = _initData.getMaxFrames(); 00123 int lastFrame = 0; 00124 00125 clock.reset(); 00126 while( config->isRunning( ) && maxFrames-- ) 00127 { 00128 config->startFrame(); 00129 if( config->getError( )) 00130 EQWARN << "Error during frame start: " << config->getError() 00131 << std::endl; 00132 config->finishFrame(); 00133 00134 if( config->getAnimationFrame() == 1 ) 00135 { 00136 const float time = clock.resetTimef(); 00137 const size_t nFrames = config->getFinishedFrame() - lastFrame; 00138 lastFrame = config->getFinishedFrame(); 00139 00140 EQLOG( LOG_STATS ) << time << " ms for " << nFrames << " frames @ " 00141 << ( nFrames / time * 1000.f) << " FPS)" 00142 << std::endl; 00143 } 00144 00145 while( !config->needRedraw( )) // wait for an event requiring redraw 00146 { 00147 if( hasCommands( )) // execute non-critical pending commands 00148 { 00149 processCommand(); 00150 config->handleEvents(); // non-blocking 00151 } 00152 else // no pending commands, block on user event 00153 { 00154 const eq::ConfigEvent* event = config->nextEvent(); 00155 if( !config->handleEvent( event )) 00156 EQVERB << "Unhandled " << event << std::endl; 00157 } 00158 } 00159 config->handleEvents(); // process all pending events 00160 } 00161 const uint32_t frame = config->finishAllFrames(); 00162 const float time = clock.resetTimef(); 00163 const size_t nFrames = frame - lastFrame; 00164 EQLOG( LOG_STATS ) << time << " ms for " << nFrames << " frames @ " 00165 << ( nFrames / time * 1000.f) << " FPS)" << std::endl; 00166 00167 // 5. exit config 00168 clock.reset(); 00169 config->exit(); 00170 EQLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<std::endl; 00171 00172 // 6. cleanup and exit 00173 server->releaseConfig( config ); 00174 if( !disconnectServer( server )) 00175 EQERROR << "Client::disconnectServer failed" << std::endl; 00176 00177 return EXIT_SUCCESS; 00178 } 00179 00180 void EqPly::clientLoop() 00181 { 00182 do 00183 { 00184 eq::Client::clientLoop(); 00185 EQINFO << "Configuration run successfully executed" << std::endl; 00186 } 00187 while( _initData.isResident( )); // execute at lease one config run 00188 } 00189 }