Equalizer  1.6.1
eqPly.cpp
1 
2 /* Copyright (c) 2005-2012, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * - Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  * - Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * - Neither the name of Eyescale Software GmbH nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "eqPly.h"
31 
32 #include "config.h"
33 #include "localInitData.h"
34 
35 #include <stdlib.h>
36 
37 namespace eqPly
38 {
39 
40 namespace
41 {
42 static const std::string _help(
43  std::string( "eqPly - Equalizer polygonal rendering example\n" ) +
44  std::string( "\tRun-time commands:\n" ) +
45  std::string( "\t\tLeft Mouse Button: Rotate model\n" ) +
46  std::string( "\t\tMiddle Mouse Button: Move model in X, Y\n" ) +
47  std::string( "\t\tRight Mouse Button: Move model in Z\n" ) +
48  std::string( "\t\t<Cursor Keys>: Move head in X,Y plane\n" )+
49  std::string( "\t\t<Page Up,Down>: Move head in Z\n" )+
50  std::string( "\t\t<Esc>, All Mouse Buttons: Exit program\n" ) +
51  std::string( "\t\t<Space>: Reset camera (twice for Immersive Setup)\n" ) +
52  std::string( "\t\tF1, h: Toggle help overlay\n" ) +
53  std::string( "\t\to: Toggle perspective/orthographic\n"
54  ) +
55  std::string( "\t\ts: Toggle statistics overlay\n" ) +
56  std::string( "\t\tw: Toggle wireframe mode\n" ) +
57  std::string( "\t\td: Toggle color demo mode\n" ) +
58  std::string( "\t\ti: Toggle usage of idle anti-aliasing\n" ) +
59  std::string( "\t\tq, Q: Adjust non-idle image quality\n" ) +
60  std::string( "\t\tn: Toggle navigation mode (trackball, walk)\n" ) +
61  std::string( "\t\tr: Switch rendering mode (display list, VBO, immediate)\n" ) +
62  std::string( "\t\tu: Toggle image compression\n" ) +
63  std::string( "\t\tc: Switch active canvas\n" ) +
64  std::string( "\t\tv: Switch active view\n" ) +
65  std::string( "\t\tm: Switch model for active view\n" ) +
66  std::string( "\t\tl: Switch layout for active canvas\n" ) +
67  std::string( "\t\ta: Add active stereo window\n" ) +
68  std::string( "\t\tp: Add passive stereo window\n" ) +
69  std::string( "\t\tx: Remove window\n" ) +
70  std::string( "\t\ty, Y: Adjust model unit\n" ) +
71  std::string( "\t\tz, Z: Adjust eye base\n" ));
72 }
73 
74 const std::string& EqPly::getHelp()
75 {
76  return _help;
77 }
78 
79 EqPly::EqPly( const LocalInitData& initData )
80  : _initData( initData )
81 {}
82 
84 {
85  // 1. connect to server
86  eq::ServerPtr server = new eq::Server;
87  if( !connectServer( server ))
88  {
89  LBERROR << "Can't open server" << std::endl;
90  return EXIT_FAILURE;
91  }
92 
93  // 2. choose config
94  eq::fabric::ConfigParams configParams;
95  Config* config = static_cast<Config*>(server->chooseConfig( configParams ));
96 
97  if( !config )
98  {
99  LBERROR << "No matching config on server" << std::endl;
100  disconnectServer( server );
101  return EXIT_FAILURE;
102  }
103 
104  // 3. init config
105  lunchbox::Clock clock;
106 
107  config->setInitData( _initData );
108  if( !config->init( ))
109  {
110  LBWARN << "Error during initialization: " << config->getError()
111  << std::endl;
112  server->releaseConfig( config );
113  disconnectServer( server );
114  return EXIT_FAILURE;
115  }
116  if( config->getError( ))
117  LBWARN << "Error during initialization: " << config->getError()
118  << std::endl;
119 
120  LBLOG( LOG_STATS ) << "Config init took " << clock.getTimef() << " ms"
121  << std::endl;
122 
123  // 4. run main loop
124  uint32_t maxFrames = _initData.getMaxFrames();
125  int lastFrame = 0;
126 
127  clock.reset();
128  while( config->isRunning( ) && maxFrames-- )
129  {
130  config->startFrame();
131  if( config->getError( ))
132  LBWARN << "Error during frame start: " << config->getError()
133  << std::endl;
134  config->finishFrame();
135 
136  if( config->getAnimationFrame() == 1 )
137  {
138  const float time = clock.resetTimef();
139  const size_t nFrames = config->getFinishedFrame() - lastFrame;
140  lastFrame = config->getFinishedFrame();
141 
142  LBLOG( LOG_STATS ) << time << " ms for " << nFrames << " frames @ "
143  << ( nFrames / time * 1000.f) << " FPS)"
144  << std::endl;
145  }
146 
147  while( !config->needRedraw( )) // wait for an event requiring redraw
148  {
149  if( hasCommands( )) // execute non-critical pending commands
150  {
151  processCommand();
152  config->handleEvents(); // non-blocking
153  }
154  else // no pending commands, block on user event
155  {
156  const eq::EventICommand& event = config->getNextEvent();
157  if( !config->handleEvent( event ))
158  LBVERB << "Unhandled " << event << std::endl;
159  }
160  }
161  config->handleEvents(); // process all pending events
162  }
163  const uint32_t frame = config->finishAllFrames();
164  const float time = clock.resetTimef();
165  const size_t nFrames = frame - lastFrame;
166  LBLOG( LOG_STATS ) << time << " ms for " << nFrames << " frames @ "
167  << ( nFrames / time * 1000.f) << " FPS)" << std::endl;
168 
169  // 5. exit config
170  clock.reset();
171  config->exit();
172  LBLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<std::endl;
173 
174  // 6. cleanup and exit
175  server->releaseConfig( config );
176  if( !disconnectServer( server ))
177  LBERROR << "Client::disconnectServer failed" << std::endl;
178 
179  return EXIT_SUCCESS;
180 }
181 
183 {
184  do
185  {
187  LBINFO << "Configuration run successfully executed" << std::endl;
188  }
189  while( _initData.isResident( )); // execute at least one config run
190 }
191 }
virtual uint32_t startFrame()
virtual uint32_t finishAllFrames()
Finish rendering all pending frames.
bool hasCommands()
A command specialization for config events.
Definition: eventICommand.h:38
eq::fabric::Error getError() const
Definition: object.h:82
uint32_t getAnimationFrame()
virtual void handleEvents()
Handle all config events.
virtual void clientLoop()
Definition: eqPly.cpp:182
bool connectServer(ServerPtr server)
Open and connect an Equalizer server to the local client.
Proxy object for the connection to an Equalizer server.
Definition: client/server.h:38
lunchbox::RefPtr< Server > ServerPtr
A reference-counted pointer to an eq::Server.
virtual bool handleEvent(const eq::ConfigEvent *event)
virtual uint32_t finishFrame()
Finish the rendering of a frame.
virtual void clientLoop()
Implements the processing loop for render clients.
void processCommand(const uint32_t timeout=LB_TIMEOUT_INDEFINITE)
Get and process one pending command from the node command queue.
EventICommand getNextEvent(const uint32_t timeout=LB_TIMEOUT_INDEFINITE) const
Get the next event.
uint32_t getFinishedFrame() const
int run()
Run an eqPly instance.
Definition: eqPly.cpp:83
virtual bool init()
Manages the argument parsing and non-distributed part of the initialization data. ...
bool disconnectServer(ServerPtr server)
Disconnect and close the connection to an Equalizer server.
static const std::string & getHelp()
Definition: eqPly.cpp:74
Parameters for running a configuration.
bool isRunning() const
virtual bool exit()
The configuration, run be the EqPly application.