eqPly.cpp

00001 
00002 /* Copyright (c) 2005-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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     // 1. connect to server
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     // 2. choose config
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     // 3. init config
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     // 4. run main loop
00103     uint32_t maxFrames = _initData.getMaxFrames();
00104     
00105     clock.reset();
00106     while( config->isRunning( ) && maxFrames-- )
00107     {
00108         config->startFrame();
00109         // config->renderData(...);
00110         config->finishFrame();
00111 
00112         while( !config->needsRedraw( )) // wait for an event requiring redraw
00113         {
00114             if( hasCommands( )) // execute non-critical pending commands
00115             {
00116                 processCommand();
00117                 config->handleEvents(); // non-blocking
00118             }
00119             else  // no pending commands, block on user event
00120             {
00121                 const eq::ConfigEvent* event = config->nextEvent();
00122                 if( !config->handleEvent( event ))
00123                     EQVERB << "Unhandled " << event << endl;
00124             }
00125         }
00126         config->handleEvents(); // process all pending events
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     // 5. exit config
00135     clock.reset();
00136     config->exit();
00137     EQLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<endl;
00138 
00139     // 6. cleanup and exit
00140     server->releaseConfig( config );
00141     if( !disconnectServer( server ))
00142         EQERROR << "Client::disconnectServer failed" << endl;
00143 
00144     // TODO EQASSERTINFO( server->getRefCount() == 1, server->getRefCount( ));
00145     server = 0;
00146 
00147     return EXIT_SUCCESS;
00148 }
00149 
00150 bool EqPly::clientLoop()
00151 {
00152     if( !_initData.isResident( )) // execute only one config run
00153         return eq::Client::clientLoop();
00154 
00155     // else execute client loops 'forever'
00156     while( true ) // TODO: implement SIGHUP handler to exit?
00157     {
00158         if( !eq::Client::clientLoop( ))
00159             return false;
00160         EQINFO << "One configuration run successfully executed" << endl;
00161     }
00162     return true;
00163 }
00164 }
Generated on Mon Aug 10 18:58:32 2009 for Equalizer 0.9 by  doxygen 1.5.8