Equalizer  1.4.1
eqPly.cpp
00001 
00002 /* Copyright (c) 2005-2012, 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     std::string( "\t\ty, Y:                      Adjust model unit\n" ) +
00070     std::string( "\t\tz, Z:                      Adjust eye base\n" )
00071                                );
00072 }
00073 
00074 const std::string& EqPly::getHelp()
00075 {
00076     return _help;
00077 }
00078 
00079 EqPly::EqPly( const LocalInitData& initData )
00080         : _initData( initData )
00081 {}
00082 
00083 int EqPly::run()
00084 {
00085     // 1. connect to server
00086     eq::ServerPtr server = new eq::Server;
00087     if( !connectServer( server ))
00088     {
00089         LBERROR << "Can't open server" << std::endl;
00090         return EXIT_FAILURE;
00091     }
00092 
00093     // 2. choose config
00094     eq::ConfigParams configParams;
00095     Config* config = static_cast<Config*>(server->chooseConfig( configParams ));
00096 
00097     if( !config )
00098     {
00099         LBERROR << "No matching config on server" << std::endl;
00100         disconnectServer( server );
00101         return EXIT_FAILURE;
00102     }
00103 
00104     // 3. init config
00105     lunchbox::Clock clock;
00106 
00107     config->setInitData( _initData );
00108     if( !config->init( ))
00109     {
00110         LBWARN << "Error during initialization: " << config->getError()
00111                << std::endl;
00112         server->releaseConfig( config );
00113         disconnectServer( server );
00114         return EXIT_FAILURE;
00115     }
00116     if( config->getError( ))
00117         LBWARN << "Error during initialization: " << config->getError()
00118                << std::endl;
00119 
00120     LBLOG( LOG_STATS ) << "Config init took " << clock.getTimef() << " ms"
00121                        << std::endl;
00122 
00123     // 4. run main loop
00124     uint32_t maxFrames = _initData.getMaxFrames();
00125     int lastFrame = 0;
00126     
00127     clock.reset();
00128     while( config->isRunning( ) && maxFrames-- )
00129     {
00130         config->startFrame();
00131         if( config->getError( ))
00132             LBWARN << "Error during frame start: " << config->getError()
00133                    << std::endl;
00134         config->finishFrame();
00135 
00136         if( config->getAnimationFrame() == 1 )
00137         {
00138             const float time = clock.resetTimef();
00139             const size_t nFrames = config->getFinishedFrame() - lastFrame;
00140             lastFrame = config->getFinishedFrame();
00141 
00142             LBLOG( LOG_STATS ) << time << " ms for " << nFrames << " frames @ "
00143                                << ( nFrames / time * 1000.f) << " FPS)"
00144                                << std::endl;
00145         }
00146 
00147         while( !config->needRedraw( )) // wait for an event requiring redraw
00148         {
00149             if( hasCommands( )) // execute non-critical pending commands
00150             {
00151                 processCommand();
00152                 config->handleEvents(); // non-blocking
00153             }
00154             else  // no pending commands, block on user event
00155             {
00156                 const eq::ConfigEvent* event = config->nextEvent();
00157                 if( !config->handleEvent( event ))
00158                     LBVERB << "Unhandled " << event << std::endl;
00159             }
00160         }
00161         config->handleEvents(); // process all pending events
00162     }
00163     const uint32_t frame = config->finishAllFrames();
00164     const float time = clock.resetTimef();
00165     const size_t nFrames = frame - lastFrame;
00166     LBLOG( LOG_STATS ) << time << " ms for " << nFrames << " frames @ "
00167                        << ( nFrames / time * 1000.f) << " FPS)" << std::endl;
00168 
00169     // 5. exit config
00170     clock.reset();
00171     config->exit();
00172     LBLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<std::endl;
00173 
00174     // 6. cleanup and exit
00175     server->releaseConfig( config );
00176     if( !disconnectServer( server ))
00177         LBERROR << "Client::disconnectServer failed" << std::endl;
00178 
00179     return EXIT_SUCCESS;
00180 }
00181 
00182 void EqPly::clientLoop()
00183 {
00184     do
00185     {
00186          eq::Client::clientLoop();
00187          LBINFO << "Configuration run successfully executed" << std::endl;
00188     }
00189     while( _initData.isResident( )); // execute at lease one config run
00190 }
00191 }
Generated on Mon Nov 26 2012 14:41:48 for Equalizer 1.4.1 by  doxygen 1.7.6.1