eqPly.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "eqPly.h"
00019
00020 #include "config.h"
00021 #include "localInitData.h"
00022
00023 #include <stdlib.h>
00024
00025 using namespace std;
00026
00027 namespace eqPly
00028 {
00029
00030 namespace
00031 {
00032 static const std::string _help(
00033 string( "eqPly - Equalizer polygonal rendering example\n" ) +
00034 string( "\tRun-time commands:\n" ) +
00035 string( "\t\tLeft Mouse Button: Rotate model\n" ) +
00036 string( "\t\tMiddle Mouse Button: Move model in X, Y\n" ) +
00037 string( "\t\tRight Mouse Button: Move model in Z\n" ) +
00038 string( "\t\t<Cursor Keys>: Move head in X,Y plane\n" )+
00039 string( "\t\t<Page Up,Down>: Move head in Z\n" )+
00040 string( "\t\t<Esc>, All Mouse Buttons: Exit program\n" ) +
00041 string( "\t\t<Space>: Reset camera\n" ) +
00042 string( "\t\tF1, h: Toggle help overlay\n" ) +
00043 string( "\t\ti: Reset camera for Immersive Setups\n" ) +
00044 string( "\t\to: Toggle perspective/orthographic\n" ) +
00045 string( "\t\ts: Toggle statistics overlay\n" ) +
00046 string( "\t\tw: Toggle wireframe mode\n" ) +
00047 string( "\t\td: Toggle color demo mode\n" ) +
00048 string( "\t\tp: Toggle navigation mode (trackball, walk)\n" ) +
00049 string( "\t\tr: Switch rendering mode (display list, VBO, immediate)\n" ) +
00050 string( "\t\tv: Switch active canvas\n" ) +
00051 string( "\t\tv: Switch active view\n" ) +
00052 string( "\t\tm: Switch model for active view\n" ) +
00053 string( "\t\tl: Switch layout for active canvas\n" ));
00054 }
00055
00056 const std::string& EqPly::getHelp()
00057 {
00058 return _help;
00059 }
00060
00061 EqPly::EqPly( const LocalInitData& initData )
00062 : _initData( initData )
00063 {}
00064
00065 int EqPly::run()
00066 {
00067
00068 eq::ServerPtr server = new eq::Server;
00069 if( !connectServer( server ))
00070 {
00071 EQERROR << "Can't open server" << endl;
00072 return EXIT_FAILURE;
00073 }
00074
00075
00076 eq::ConfigParams configParams;
00077 Config* config = static_cast<Config*>(server->chooseConfig( configParams ));
00078
00079 if( !config )
00080 {
00081 EQERROR << "No matching config on server" << endl;
00082 disconnectServer( server );
00083 return EXIT_FAILURE;
00084 }
00085
00086
00087 eq::base::Clock clock;
00088
00089 config->setInitData( _initData );
00090 if( !config->init( ))
00091 {
00092 EQERROR << "Config initialization failed: "
00093 << config->getErrorMessage() << endl;
00094 server->releaseConfig( config );
00095 disconnectServer( server );
00096 return EXIT_FAILURE;
00097 }
00098
00099 EQLOG( LOG_STATS ) << "Config init took " << clock.getTimef() << " ms"
00100 << endl;
00101
00102
00103 uint32_t maxFrames = _initData.getMaxFrames();
00104
00105 clock.reset();
00106 while( config->isRunning( ) && maxFrames-- )
00107 {
00108 config->startFrame();
00109
00110 config->finishFrame();
00111
00112 while( !config->needsRedraw( ))
00113 {
00114 if( hasCommands( ))
00115 {
00116 processCommand();
00117 config->handleEvents();
00118 }
00119 else
00120 {
00121 const eq::ConfigEvent* event = config->nextEvent();
00122 if( !config->handleEvent( event ))
00123 EQVERB << "Unhandled " << event << endl;
00124 }
00125 }
00126 config->handleEvents();
00127 }
00128 const uint32_t frame = config->finishAllFrames();
00129 const float time = clock.getTimef();
00130 EQLOG( LOG_STATS ) << "Rendering took " << time << " ms (" << frame
00131 << " frames @ " << ( frame / time * 1000.f) << " FPS)"
00132 << endl;
00133
00134
00135 clock.reset();
00136 config->exit();
00137 EQLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<endl;
00138
00139
00140 server->releaseConfig( config );
00141 if( !disconnectServer( server ))
00142 EQERROR << "Client::disconnectServer failed" << endl;
00143
00144
00145 server = 0;
00146
00147 return EXIT_SUCCESS;
00148 }
00149
00150 bool EqPly::clientLoop()
00151 {
00152 if( !_initData.isResident( ))
00153 return eq::Client::clientLoop();
00154
00155
00156 while( true )
00157 {
00158 if( !eq::Client::clientLoop( ))
00159 return false;
00160 EQINFO << "One configuration run successfully executed" << endl;
00161 }
00162 return true;
00163 }
00164 }