Equalizer  1.4.1
eqPixelBench/main.cpp
00001 
00002 /* Copyright (c) 2007-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 "channel.h"
00030 #include "config.h"
00031 #include "window.h"
00032 
00033 
00034 #ifdef _WIN32
00035 #  define setenv( name, value, overwrite ) \
00036     SetEnvironmentVariable( name, value )
00037 #endif
00038 
00039 class NodeFactory : public eq::NodeFactory
00040 {
00041 public:
00042     virtual eq::Config*  createConfig( eq::ServerPtr parent )
00043         { return new eqPixelBench::Config( parent ); }
00044     virtual eq::Window* createWindow( eq::Pipe* parent )
00045         { return new eqPixelBench::Window( parent ); }
00046     virtual eq::Channel* createChannel( eq::Window* parent )
00047         { return new eqPixelBench::Channel( parent ); }
00048 };
00049 
00050 int main( int argc, char** argv )
00051 {
00052     // 1. initialization of local node
00053     NodeFactory nodeFactory;
00054     if( !eq::init( argc, argv, &nodeFactory ))
00055     {
00056         LBERROR << "Equalizer init failed" << std::endl;
00057         return EXIT_FAILURE;
00058     }
00059 
00060     eq::ClientPtr client = new eq::Client;
00061     if( !client->initLocal( argc, argv ))
00062     {
00063         LBERROR << "Can't init client" << std::endl;
00064         eq::exit();
00065         return EXIT_FAILURE;
00066     }
00067 
00068     // 2. connect to server
00069     eq::ServerPtr server = new eq::Server;
00070     if( !client->connectServer( server ))
00071     {
00072         LBERROR << "Can't open server" << std::endl;
00073         client->exitLocal();
00074         eq::exit();
00075         return EXIT_FAILURE;
00076     }
00077 
00078     // 3. choose config
00079     eq::ConfigParams configParams;
00080     eqPixelBench::Config* config = static_cast<eqPixelBench::Config*>(
00081         server->chooseConfig( configParams ));
00082     
00083     if( !config )
00084     {
00085         LBERROR << "No matching config on server" << std::endl;
00086         client->disconnectServer( server );
00087         client->exitLocal();
00088         eq::exit();
00089         return EXIT_FAILURE;
00090     }
00091 
00092     // 4. init config
00093     lunchbox::Clock clock;
00094 
00095     if( !config->init( 0 ))
00096     {
00097         server->releaseConfig( config );
00098         client->disconnectServer( server );
00099         client->exitLocal();
00100         eq::exit();
00101         return EXIT_FAILURE;
00102     }
00103     else if( config->getError( ))
00104         LBWARN << "Error during initialization: " << config->getError()
00105                << std::endl;
00106 
00107     LBLOG( eq::LOG_CUSTOM ) << "Config init took " << clock.getTimef() << " ms"
00108                             << std::endl;
00109 
00110     // 5. render three frames
00111     clock.reset();
00112     for( uint32_t i = 0; i < 3; ++i )
00113     {
00114         config->startFrame( 0 );
00115         config->finishAllFrames();
00116     }
00117     LBLOG( eq::LOG_CUSTOM ) << "Rendering took " << clock.getTimef() << " ms ("
00118                             << ( 1.0f / clock.getTimef() * 1000.f) << " FPS)"
00119                             << std::endl;
00120 
00121     // 6. exit config
00122     clock.reset();
00123     config->exit();
00124     LBLOG( eq::LOG_CUSTOM ) << "Exit took " << clock.getTimef() << " ms"
00125                             << std::endl;
00126 
00127     // 7. cleanup and exit
00128     server->releaseConfig( config );
00129     if( !client->disconnectServer( server ))
00130         LBERROR << "Client::disconnectServer failed" << std::endl;
00131     server = 0;
00132 
00133     client->exitLocal();
00134     client = 0;
00135 
00136     eq::exit();
00137     return EXIT_SUCCESS;
00138 }
Generated on Mon Nov 26 2012 14:41:49 for Equalizer 1.4.1 by  doxygen 1.7.6.1