Equalizer  1.11.0
Parallel Rendering Framework
window.h
Go to the documentation of this file.
1 
2 /* Copyright (c) 2005-2015, Stefan Eilemann <eile@equalizergraphics.com>
3  * Cedric Stalder <cedric.stalder@gmail.com>
4  * Daniel Nachbaur <danielnachbaur@gmail.com>
5  *
6  * This library is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License version 2.1 as published
8  * by the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef EQ_WINDOW_H
21 #define EQ_WINDOW_H
22 
23 #include <eq/types.h>
24 #include <eq/notifierInterface.h> // base class
25 #include <eq/windowSettings.h> // template param
26 #include <eq/visitorResult.h> // enum
27 
28 #include <eq/fabric/renderContext.h> // member
29 #include <eq/fabric/window.h> // base class
30 #include <eq/util/bitmapFont.h> // member
31 #include <eq/util/objectManager.h> // member
32 
33 
36 namespace eq
37 {
64 class Window : public fabric::Window< Pipe, Window, Channel, WindowSettings >,
65  public NotifierInterface
66 {
67 public:
69  EQ_API explicit Window( Pipe* parent );
70 
72  EQ_API virtual ~Window();
73 
76  EQ_API co::CommandQueue* getPipeThreadQueue();
77  EQ_API co::CommandQueue* getCommandThreadQueue();
78  EQ_API uint32_t getCurrentFrame() const;
79 
81  EQ_API const Node* getNode() const;
82 
84  EQ_API Node* getNode();
85 
87  EQ_API const Config* getConfig() const;
88 
90  EQ_API Config* getConfig();
91 
93  EQ_API ClientPtr getClient();
94 
96  EQ_API ServerPtr getServer();
97 
102  bool isRunning() const { return (_state == STATE_RUNNING); }
103 
108  bool isStopped() const { return (_state == STATE_STOPPED); }
109 
119  EQ_API bool getRenderContext( const int32_t x, const int32_t y,
120  RenderContext& context ) const;
122 
136  EQ_API void setSharedContextWindow( const Window* sharedContextWindow );
137 
142  EQ_API const Window* getSharedContextWindow() const;
143 
145  util::ObjectManager& getObjectManager() { return _objectManager; }
146 
149  { return _objectManager; }
150 
155  EQ_API const util::BitmapFont* getSmallFont();
156 
161  EQ_API const util::BitmapFont* getMediumFont();
162 
177  EQ_API const GLEWContext* glewGetContext() const;
178 
180  EQ_API const GLEWContext* getTransferGlewContext() const;
181 
187  EQ_API uint32_t getColorFormat() const;
189 
199  EQ_API virtual void flush() const;
200 
208  EQ_API virtual void finish() const;
209 
211  EQ_API virtual void swapBuffers();
212 
214  EQ_API virtual void drawFPS();
215 
217  float getFPS() const { return _avgFPS; }
218 
228  EQ_API virtual void makeCurrent( const bool cache = true ) const;
229 
234  EQ_API virtual void doneCurrent() const;
235 
237  EQ_API virtual void bindFrameBuffer() const;
238 
240  EQ_API virtual void bindDrawFrameBuffer() const;
241 
243  EQ_API virtual void updateFrameBuffer() const;
244 
246  EQ_API virtual void notifyViewportChanged();
248 
260  EQ_API void setSystemWindow( SystemWindow* window );
261 
263  const SystemWindow* getSystemWindow() const { return _systemWindow; }
264 
266  SystemWindow* getSystemWindow() { return _systemWindow; }
267 
269  const SystemPipe* getSystemPipe() const;
270 
273 
275  bool createTransferWindow();
276 
278  void deleteTransferWindow();
279 
281  SystemWindow* getTransferWindow();
282  const SystemWindow* getTransferWindow() const;
283 
284 
293  EQ_API EventOCommand sendError( const uint32_t error ) final;
294 
308  EQ_API virtual bool processEvent( const Event& event );
310 
311 protected:
312  friend class Pipe;
313 
315  EQ_API virtual void attach( const uint128_t& id, const uint32_t instanceID );
316 
325  EQ_API void startFrame( const uint32_t frameNumber );
326 
333  EQ_API void releaseFrame( const uint32_t frameNumber );
334 
341  EQ_API void releaseFrameLocal( const uint32_t frameNumber );
343 
357  EQ_API virtual bool configInit( const uint128_t& initID );
358 
365  EQ_API virtual bool configInitSystemWindow( const uint128_t& initID );
366 
375  EQ_API virtual bool configInitGL( const uint128_t& initID );
376 
378  EQ_API virtual bool configExit();
379 
381  EQ_API virtual bool configExitSystemWindow();
382 
384  virtual bool configExitGL() { return true; }
385 
396  EQ_API virtual void frameStart( const uint128_t& frameID,
397  const uint32_t frameNumber );
398 
412  EQ_API virtual void frameFinish( const uint128_t& frameID,
413  const uint32_t frameNumber );
414 
425  EQ_API virtual void frameDrawFinish( const uint128_t& frameID,
426  const uint32_t frameNumber );
428 
429 private:
430  enum State
431  {
432  STATE_STOPPED,
433  STATE_INITIALIZING,
434  STATE_RUNNING,
435  STATE_FAILED
436  };
437 
439  const Window* _sharedContextWindow;
440 
442  SystemWindow* _transferWindow;
443 
445  SystemWindow* _systemWindow;
446 
448  State _state;
449 
451  util::ObjectManager _objectManager;
452 
454  float _lastTime;
455 
457  float _avgFPS;
458 
460  std::vector< RenderContext > _renderContexts[2];
461  enum
462  {
463  FRONT = 0,
464  BACK = 1
465  };
466 
468  int64_t _lastSwapTime;
469 
471  Channels _grabbedChannels;
472 
473  struct Private;
474  Private* _private; // placeholder for binary-compatible changes
475 
477  void _addRenderContext( const RenderContext& context );
478  friend class Channel;
479 
481  Channels _getEventChannels( const PointerEvent& event );
482 
484  void _setupObjectManager();
486  void _releaseObjectManager();
487 
489  void _updateFPS();
490 
492  void _enterBarrier( co::ObjectVersion barrier );
493 
494  void _updateEvent( Event& event );
495 
496  /* The command functions. */
497  bool _cmdCreateChannel( co::ICommand& command );
498  bool _cmdDestroyChannel(co::ICommand& command );
499  bool _cmdConfigInit( co::ICommand& command );
500  bool _cmdConfigExit( co::ICommand& command );
501  bool _cmdFrameStart( co::ICommand& command );
502  bool _cmdFrameFinish( co::ICommand& command );
503  bool _cmdThrottleFramerate( co::ICommand& command );
504  bool _cmdFlush( co::ICommand& command );
505  bool _cmdFinish( co::ICommand& command );
506  bool _cmdBarrier( co::ICommand& command );
507  bool _cmdNVBarrier( co::ICommand& command );
508  bool _cmdSwap( co::ICommand& command );
509  bool _cmdFrameDrawFinish( co::ICommand& command );
510 
511  LB_TS_VAR( _pipeThread )
512 };
513 }
514 
515 #endif // EQ_WINDOW_H
virtual EQ_API bool configInitSystemWindow(const uint128_t &initID)
Initialize the OS-specific window.
const util::ObjectManager & getObjectManager() const
Definition: window.h:148
EQ_API const Config * getConfig() const
A configuration is a visualization session driven by an application.
Definition: config.h:55
virtual EQ_API ~Window()
Destruct the window.
A Pipe represents a graphics card (GPU) on a Node.
Definition: pipe.h:50
EQ_API ClientPtr getClient()
EQ_API EventOCommand sendError(const uint32_t error) final
Send a window error event to the application node.
A wrapper around AGL, WGL and GLX bitmap fonts.
Definition: bitmapFont.h:31
EQ_API void setSystemWindow(SystemWindow *window)
Set the OS-specific window.
A Node represents a single computer in the cluster.
Definition: node.h:48
EQ_API Window(Pipe *parent)
Construct a new window.
virtual EQ_API void frameDrawFinish(const uint128_t &frameID, const uint32_t frameNumber)
Finish drawing.
const SystemPipe * getSystemPipe() const
lunchbox::RefPtr< Server > ServerPtr
A reference-counted pointer to an eq::Server.
Definition: eq/types.h:213
std::vector< Channel * > Channels
A vector of pointers to channels.
Definition: fabric/window.h:41
virtual EQ_API void frameStart(const uint128_t &frameID, const uint32_t frameNumber)
Start rendering a frame.
virtual EQ_API void flush() const
Flush outstanding rendering requests.
EQ_API void setSharedContextWindow(const Window *sharedContextWindow)
Set the window with which this window shares the OpenGL context.
A Window represents an on-screen or off-screen drawable.
Definition: window.h:64
The interface definition for system-specific GPU handling.
Definition: systemPipe.h:38
virtual EQ_API bool processEvent(const Event &event)
Process a received event.
EQ_API const Node * getNode() const
A base class for notifying errors and events.
EQ_API void releaseFrame(const uint32_t frameNumber)
Signal the completion of a frame to the parent.
lunchbox::RefPtr< Client > ClientPtr
A reference-counted pointer to an eq::Client.
Definition: eq/types.h:209
EQ_API void startFrame(const uint32_t frameNumber)
Start a frame by unlocking all child resources.
virtual EQ_API void makeCurrent(const bool cache=true) const
Make the window's drawable and context current.
bool isStopped() const
Definition: window.h:108
virtual EQ_API bool configExit()
Exit this window.
EQ_API ServerPtr getServer()
The Equalizer client library.
Definition: eq/agl/types.h:23
virtual EQ_API bool configExitSystemWindow()
De-initialize the OS-specific window.
virtual EQ_API void drawFPS()
Render the current framerate as on overlay.
SystemWindow * getSystemWindow()
Definition: window.h:266
virtual EQ_API void finish() const
Finish outstanding rendering requests.
The interface definition for system-specific windowing code.
Definition: systemWindow.h:35
virtual bool configExitGL()
De-initialize the OpenGL state for this window.
Definition: window.h:384
Base data transport class for windows.
EQ_API bool getRenderContext(const int32_t x, const int32_t y, RenderContext &context) const
Get the last rendering context at the x, y position.
A facility class to manage OpenGL objects across shared contexts.
Definition: objectManager.h:52
virtual EQ_API void frameFinish(const uint128_t &frameID, const uint32_t frameNumber)
Finish rendering a frame.
virtual EQ_API void swapBuffers()
Swap the front and back buffer of the window.
EQ_API const GLEWContext * glewGetContext() const
Get the GLEW context for this window.
EQ_API const util::BitmapFont * getMediumFont()
EQ_API const util::BitmapFont * getSmallFont()
virtual EQ_API bool configInitGL(const uint128_t &initID)
Initialize the OpenGL state for this window.
virtual EQ_API bool configInit(const uint128_t &initID)
Initialize this window.
virtual EQ_API void doneCurrent() const
This results in no context being current in the current thread.
bool isRunning() const
Definition: window.h:102
float getFPS() const
Definition: window.h:217
EQ_API void releaseFrameLocal(const uint32_t frameNumber)
Signal the release of the local synchronization to the parent.
EQ_API const Window * getSharedContextWindow() const
util::ObjectManager & getObjectManager()
Definition: window.h:145
const SystemWindow * getSystemWindow() const
Definition: window.h:263