Equalizer  1.8.0
Parallel Rendering Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
eqPly.cpp
1 
2 /* Copyright (c) 2005-2013, 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  server->releaseConfig( config );
111  disconnectServer( server );
112  return EXIT_FAILURE;
113  }
114  LBLOG( LOG_STATS ) << "Config init took " << clock.getTimef() << " ms"
115  << std::endl;
116 
117  // 4. run main loop
118  uint32_t maxFrames = _initData.getMaxFrames();
119  int lastFrame = 0;
120 
121  clock.reset();
122  while( config->isRunning( ) && maxFrames-- )
123  {
124  config->startFrame();
125  config->finishFrame();
126 
127  if( config->getAnimationFrame() == 1 )
128  {
129  const float time = clock.resetTimef();
130  const size_t nFrames = config->getFinishedFrame() - lastFrame;
131  lastFrame = config->getFinishedFrame();
132 
133  LBLOG( LOG_STATS ) << time << " ms for " << nFrames << " frames @ "
134  << ( nFrames / time * 1000.f) << " FPS)"
135  << std::endl;
136  }
137 
138  while( !config->needRedraw( )) // wait for an event requiring redraw
139  {
140  if( hasCommands( )) // execute non-critical pending commands
141  {
142  processCommand();
143  config->handleEvents(); // non-blocking
144  }
145  else // no pending commands, block on user event
146  {
147  const eq::EventICommand& event = config->getNextEvent();
148  if( !config->handleEvent( event ))
149  LBVERB << "Unhandled " << event << std::endl;
150  }
151  }
152  config->handleEvents(); // process all pending events
153  }
154  const uint32_t frame = config->finishAllFrames();
155  const float time = clock.resetTimef();
156  const size_t nFrames = frame - lastFrame;
157  LBLOG( LOG_STATS ) << time << " ms for " << nFrames << " frames @ "
158  << ( nFrames / time * 1000.f) << " FPS)" << std::endl;
159 
160  // 5. exit config
161  clock.reset();
162  config->exit();
163  LBLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<std::endl;
164 
165  // 6. cleanup and exit
166  server->releaseConfig( config );
167  if( !disconnectServer( server ))
168  LBERROR << "Client::disconnectServer failed" << std::endl;
169 
170  return EXIT_SUCCESS;
171 }
172 
174 {
175  do
176  {
178  LBINFO << "Configuration run successfully executed" << std::endl;
179  }
180  while( _initData.isResident( )); // execute at least one config run
181 }
182 }
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
EQ_API EventICommand getNextEvent(const uint32_t timeout=LB_TIMEOUT_INDEFINITE) const
Get the next event.
virtual EQ_API uint32_t finishFrame()
Finish the rendering of a frame.
EQ_API uint32_t getFinishedFrame() const
uint32_t getAnimationFrame()
virtual bool handleEvent(const eq::ConfigEvent *event)
virtual uint32_t startFrame()
virtual EQ_API uint32_t finishAllFrames()
Finish rendering all pending frames.
lunchbox::RefPtr< Server > ServerPtr
A reference-counted pointer to an eq::Server.
A command specialization for config events.
Definition: eventICommand.h:38
virtual bool init()
EQFABRIC_API void processCommand(const uint32_t timeout=LB_TIMEOUT_INDEFINITE)
Get and process one pending command from the node command queue.
int run()
Run an eqPly instance.
Definition: eqPly.cpp:83
virtual bool exit()
virtual void clientLoop()
Definition: eqPly.cpp:173
EQ_API bool disconnectServer(ServerPtr server)
Disconnect and close the connection to an Equalizer server.
EQ_API bool hasCommands()
static const std::string & getHelp()
Definition: eqPly.cpp:74
EQ_API bool connectServer(ServerPtr server)
Open and connect an Equalizer server to the local client.
Manages the argument parsing and non-distributed part of the initialization data. ...
virtual EQ_API void clientLoop()
Implements the processing loop for render clients.
The configuration, run be the EqPly application.
virtual EQ_API void handleEvents()
Handle all config events.