Equalizer  1.8.0
Parallel Rendering Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
eVolve.cpp
1 
2 /* Copyright (c) 2005-2010, Stefan Eilemann <eile@equalizergraphics.com>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * - Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  * - Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * - Neither the name of Eyescale Software GmbH nor the names of its
13  * contributors may be used to endorse or promote products derived from this
14  * software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "eVolve.h"
30 
31 #include "config.h"
32 #include "localInitData.h"
33 
34 #include <stdlib.h>
35 
36 namespace eVolve
37 {
38 
39 static const std::string _help(
40  std::string( "eVolve - Equalizer volume rendering example\n" ) +
41  std::string( "\tRun-time commands:\n" ) +
42  std::string( "\t\tLeft Mouse Button: Rotate model\n" ) +
43  std::string( "\t\tMiddle Mouse Button: Move model in X, Y\n" ) +
44  std::string( "\t\tRight Mouse Button: Move model in Z\n" ) +
45  std::string( "\t\t<Esc>, All Mouse Buttons: Exit program\n" ) +
46  std::string( "\t\t<Space>, r: Reset camera\n" ) +
47  std::string( "\t\td: Toggle demo color mode\n" ) +
48  std::string( "\t\tb: Toggle background color\n" ) +
49  std::string( "\t\tn: Toggle normals Quality mode (raw data only)\n" ) +
50  std::string( "\t\to: Toggle " ) +
51  std::string( "perspective/orthographic\n" ) +
52  std::string( "\t\ts: Toggle statistics " ) +
53  std::string( "overlay\n" ) +
54  std::string( "\t\tl: Switch layout for active canvas\n")+
55  std::string( "\t\tF1, h: Toggle help overlay\n" )
56  );
57 
58 const std::string& EVolve::getHelp()
59 {
60  return _help;
61 }
62 
63 EVolve::EVolve( const LocalInitData& initData )
64  : _initData( initData )
65 {}
66 
67 int EVolve::run()
68 {
69  // 1. connect to server
70  eq::ServerPtr server = new eq::Server;
71  if( !connectServer( server ))
72  {
73  LBERROR << "Can't open server" << std::endl;
74  return EXIT_FAILURE;
75  }
76 
77  // 2. choose config
78  eq::fabric::ConfigParams configParams;
79  Config* config = static_cast<Config*>(server->chooseConfig( configParams ));
80 
81  if( !config )
82  {
83  LBERROR << "No matching config on server" << std::endl;
84  disconnectServer( server );
85  return EXIT_FAILURE;
86  }
87 
88  // 3. init config
89  lunchbox::Clock clock;
90 
91  config->setInitData( _initData );
92  if( !config->init( ))
93  {
94  server->releaseConfig( config );
95  disconnectServer( server );
96  return EXIT_FAILURE;
97  }
98  LBLOG( LOG_STATS ) << "Config init took " << clock.getTimef() << " ms"
99  << std::endl;
100 
101  // 4. run main loop
102  uint32_t maxFrames = _initData.getMaxFrames();
103 
104  clock.reset();
105  while( config->isRunning( ) && maxFrames-- )
106  {
107  config->startFrame();
108  config->finishFrame();
109  }
110  const uint32_t frame = config->finishAllFrames();
111  const float time = clock.getTimef();
112  LBLOG( LOG_STATS ) << "Rendering took " << time << " ms (" << frame
113  << " frames @ " << ( frame / time * 1000.f) << " FPS)"
114  << std::endl;
115 
116  // 5. exit config
117  clock.reset();
118  config->exit();
119  LBLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<std::endl;
120 
121  // 6. cleanup and exit
122  server->releaseConfig( config );
123  if( !disconnectServer( server ))
124  LBERROR << "Client::disconnectServer failed" << std::endl;
125  server = 0;
126 
127  return EXIT_SUCCESS;
128 }
129 
130 void EVolve::clientLoop()
131 {
132  do
133  {
135  LBINFO << "Configuration run successfully executed" << std::endl;
136  }
137  while( _initData.isResident( )); // execute at lease one config run
138 }
139 }
Parameters for running a configuration.
Definition: configParams.h:34
EQ_API bool isRunning() const
Proxy object for the connection to an Equalizer server.
Definition: client/server.h:40
virtual EQ_API uint32_t finishFrame()
Finish the rendering of a frame.
virtual bool exit()
virtual EQ_API uint32_t finishAllFrames()
Finish rendering all pending frames.
lunchbox::RefPtr< Server > ServerPtr
A reference-counted pointer to an eq::Server.
Statistic events (32768)
Definition: client/log.h:35
virtual uint32_t startFrame()
virtual bool init()
virtual EQ_API void clientLoop()
Implements the processing loop for render clients.