Equalizer 1.0

eqPly.cpp

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\tc:                         Switch active canvas\n" ) +
00062     std::string( "\t\tv:                         Switch active view\n" ) +
00063     std::string( "\t\tm:                         Switch model for active view\n" ) +
00064     std::string( "\t\tl:                         Switch layout for active canvas\n" ) +
00065     std::string( "\t\ta:                         Add active stereo window\n" ) +
00066     std::string( "\t\tp:                         Add passive stereo window\n" ) +
00067     std::string( "\t\tx:                         Remove window\n" )
00068                                );
00069 }
00070 
00071 const std::string& EqPly::getHelp()
00072 {
00073     return _help;
00074 }
00075 
00076 EqPly::EqPly( const LocalInitData& initData )
00077         : _initData( initData )
00078 {}
00079 
00080 int EqPly::run()
00081 {
00082     // 1. connect to server
00083     eq::ServerPtr server = new eq::Server;
00084     if( !connectServer( server ))
00085     {
00086         EQERROR << "Can't open server" << std::endl;
00087         return EXIT_FAILURE;
00088     }
00089 
00090     // 2. choose config
00091     eq::ConfigParams configParams;
00092     Config* config = static_cast<Config*>(server->chooseConfig( configParams ));
00093 
00094     if( !config )
00095     {
00096         EQERROR << "No matching config on server" << std::endl;
00097         disconnectServer( server );
00098         return EXIT_FAILURE;
00099     }
00100 
00101     // 3. init config
00102     co::base::Clock clock;
00103 
00104     config->setInitData( _initData );
00105     if( !config->init( ))
00106     {
00107         EQWARN << "Error during initialization: " << config->getError()
00108                << std::endl;
00109         server->releaseConfig( config );
00110         disconnectServer( server );
00111         return EXIT_FAILURE;
00112     }
00113     if( config->getError( ))
00114         EQWARN << "Error during initialization: " << config->getError()
00115                << std::endl;
00116 
00117     EQLOG( LOG_STATS ) << "Config init took " << clock.getTimef() << " ms"
00118                        << std::endl;
00119 
00120     // 4. run main loop
00121     uint32_t maxFrames = _initData.getMaxFrames();
00122     
00123     clock.reset();
00124     while( config->isRunning( ) && maxFrames-- )
00125     {
00126         config->startFrame();
00127         if( config->getError( ))
00128             EQWARN << "Error during frame start: " << config->getError()
00129                    << std::endl;
00130         config->finishFrame();
00131 
00132         while( !config->needsRedraw( )) // wait for an event requiring redraw
00133         {
00134             if( hasCommands( )) // execute non-critical pending commands
00135             {
00136                 processCommand();
00137                 config->handleEvents(); // non-blocking
00138             }
00139             else  // no pending commands, block on user event
00140             {
00141                 const eq::ConfigEvent* event = config->nextEvent();
00142                 if( !config->handleEvent( event ))
00143                     EQVERB << "Unhandled " << event << std::endl;
00144             }
00145         }
00146         config->handleEvents(); // process all pending events
00147     }
00148     const uint32_t frame = config->finishAllFrames();
00149     const float    time  = clock.getTimef();
00150     EQLOG( LOG_STATS ) << "Rendering took " << time << " ms (" << frame
00151                        << " frames @ " << ( frame / time * 1000.f) << " FPS)"
00152                        << std::endl;
00153 
00154     // 5. exit config
00155     clock.reset();
00156     config->exit();
00157     EQLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<std::endl;
00158 
00159     // 6. cleanup and exit
00160     server->releaseConfig( config );
00161     if( !disconnectServer( server ))
00162         EQERROR << "Client::disconnectServer failed" << std::endl;
00163 
00164     return EXIT_SUCCESS;
00165 }
00166 
00167 void EqPly::clientLoop()
00168 {
00169     do
00170     {
00171          eq::Client::clientLoop();
00172          EQINFO << "Configuration run successfully executed" << std::endl;
00173     }
00174     while( _initData.isResident( )); // execute at lease one config run
00175 }
00176 }
Generated on Sun May 8 2011 19:11:05 for Equalizer 1.0 by  doxygen 1.7.3