Equalizer  2.0.0
Parallel Rendering Framework
window.h
Go to the documentation of this file.
1 /* Copyright (c) 2005-2016, Stefan Eilemann <eile@equalizergraphics.com>
2  * Cedric Stalder <cedric.stalder@gmail.com>
3  * Daniel Nachbaur <danielnachbaur@gmail.com>
4  *
5  * This library is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License version 2.1 as published
7  * by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef EQ_WINDOW_H
20 #define EQ_WINDOW_H
21 
22 #include <eq/types.h>
23 #include <eq/notifierInterface.h> // base class
24 #include <eq/windowSettings.h> // template param
25 #include <eq/visitorResult.h> // enum
26 
27 #include <eq/fabric/renderContext.h> // member
28 #include <eq/fabric/window.h> // base class
29 #include <eq/util/bitmapFont.h> // member
30 #include <eq/util/objectManager.h> // member
31 
32 
35 namespace eq
36 {
63 class Window : public fabric::Window< Pipe, Window, Channel, WindowSettings >,
64  public NotifierInterface
65 {
66 public:
68  EQ_API explicit Window( Pipe* parent );
69 
71  EQ_API virtual ~Window();
72 
75  EQ_API co::CommandQueue* getPipeThreadQueue();
76  EQ_API co::CommandQueue* getCommandThreadQueue();
77  EQ_API uint32_t getCurrentFrame() const;
78 
80  EQ_API const Node* getNode() const;
81 
83  EQ_API Node* getNode();
84 
86  EQ_API const Config* getConfig() const;
87 
89  EQ_API Config* getConfig();
90 
92  EQ_API ClientPtr getClient();
93 
95  EQ_API ServerPtr getServer();
96 
101  bool isRunning() const { return (_state == STATE_RUNNING); }
102 
107  bool isStopped() const { return (_state == STATE_STOPPED); }
108 
118  EQ_API bool getRenderContext( const int32_t x, const int32_t y,
119  RenderContext& context ) const;
121 
135  EQ_API void setSharedContextWindow( const Window* sharedContextWindow );
136 
141  EQ_API const Window* getSharedContextWindow() const;
142 
144  util::ObjectManager& getObjectManager() { return _objectManager; }
145 
148  { return _objectManager; }
149 
154  EQ_API const util::BitmapFont* getSmallFont();
155 
160  EQ_API const util::BitmapFont* getMediumFont();
161 
176  EQ_API const GLEWContext* glewGetContext() const;
177 
179  EQ_API const GLEWContext* getTransferGlewContext() const;
180 
186  EQ_API uint32_t getColorFormat() const;
188 
198  EQ_API virtual void flush() const;
199 
207  EQ_API virtual void finish() const;
208 
210  EQ_API virtual void swapBuffers();
211 
213  EQ_API virtual void drawFPS();
214 
216  float getFPS() const { return _avgFPS; }
217 
227  EQ_API virtual void makeCurrent( const bool cache = true ) const;
228 
233  EQ_API virtual void doneCurrent() const;
234 
236  EQ_API virtual void bindFrameBuffer() const;
237 
239  EQ_API virtual void bindDrawFrameBuffer() const;
240 
242  EQ_API virtual void updateFrameBuffer() const;
243 
245  EQ_API void notifyViewportChanged() override;
247 
259  EQ_API void setSystemWindow( SystemWindow* window );
260 
262  const SystemWindow* getSystemWindow() const { return _systemWindow; }
263 
265  SystemWindow* getSystemWindow() { return _systemWindow; }
266 
268  const SystemPipe* getSystemPipe() const;
269 
272 
274  bool createTransferWindow();
275 
277  void deleteTransferWindow();
278 
280  SystemWindow* getTransferWindow();
281  const SystemWindow* getTransferWindow() const;
282 
283 
292  EQ_API EventOCommand sendError( const uint32_t error ) final;
293 
295  EQ_API bool processEvent( EventType type ) override;
296 
298  EQ_API bool processEvent( EventType type, SizeEvent& event ) override;
299 
301  EQ_API bool processEvent( EventType type, PointerEvent& event ) override;
302 
304  EQ_API bool processEvent( EventType type, KeyEvent& event ) override;
305 
307  EQ_API bool processEvent( EventType type, AxisEvent& event ) override;
308 
310  EQ_API bool processEvent( EventType type, ButtonEvent& event ) override;
311 
312  EQ_API bool processEvent( Statistic& event );
314 
315 protected:
316  friend class Pipe;
317 
319  EQ_API
320  void attach( const uint128_t& id, const uint32_t instanceID ) override;
321 
330  EQ_API void startFrame( const uint32_t frameNumber );
331 
338  EQ_API void releaseFrame( const uint32_t frameNumber );
339 
346  EQ_API void releaseFrameLocal( const uint32_t frameNumber );
348 
362  EQ_API virtual bool configInit( const uint128_t& initID );
363 
370  EQ_API virtual bool configInitSystemWindow( const uint128_t& initID );
371 
382  EQ_API virtual bool configInitGL( const uint128_t& initID );
383 
385  EQ_API virtual bool configExit();
386 
388  EQ_API virtual bool configExitSystemWindow();
389 
391  virtual bool configExitGL() { return true; }
392 
403  EQ_API virtual void frameStart( const uint128_t& frameID,
404  const uint32_t frameNumber );
405 
419  EQ_API virtual void frameFinish( const uint128_t& frameID,
420  const uint32_t frameNumber );
421 
432  EQ_API virtual void frameDrawFinish( const uint128_t& frameID,
433  const uint32_t frameNumber );
435 
436 private:
437  enum State
438  {
439  STATE_STOPPED,
440  STATE_INITIALIZING,
441  STATE_RUNNING,
442  STATE_FAILED
443  };
444 
446  const Window* _sharedContextWindow;
447 
449  SystemWindow* _transferWindow;
450 
452  SystemWindow* _systemWindow;
453 
455  State _state;
456 
458  util::ObjectManager _objectManager;
459 
461  float _lastTime;
462 
464  float _avgFPS;
465 
467  std::vector< RenderContext > _renderContexts[2];
468  enum
469  {
470  FRONT = 0,
471  BACK = 1
472  };
473 
475  int64_t _lastSwapTime;
476 
478  Channels _grabbedChannels;
479 
480  struct Private;
481  Private* _private; // placeholder for binary-compatible changes
482 
484  void _addRenderContext( const RenderContext& context );
485  friend class Channel;
486 
488  Channels _getEventChannels( const PointerEvent& event );
489 
491  void _setupObjectManager();
493  void _releaseObjectManager();
494 
496  void _updateFPS();
497 
499  void _enterBarrier( co::ObjectVersion barrier );
500 
501  /* The command functions. */
502  bool _cmdCreateChannel( co::ICommand& command );
503  bool _cmdDestroyChannel(co::ICommand& command );
504  bool _cmdConfigInit( co::ICommand& command );
505  bool _cmdConfigExit( co::ICommand& command );
506  bool _cmdFrameStart( co::ICommand& command );
507  bool _cmdFrameFinish( co::ICommand& command );
508  bool _cmdThrottleFramerate( co::ICommand& command );
509  bool _cmdFlush( co::ICommand& command );
510  bool _cmdFinish( co::ICommand& command );
511  bool _cmdBarrier( co::ICommand& command );
512  bool _cmdNVBarrier( co::ICommand& command );
513  bool _cmdSwap( co::ICommand& command );
514  bool _cmdFrameDrawFinish( co::ICommand& command );
515 
516  LB_TS_VAR( _pipeThread )
517 };
518 }
519 
520 #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:147
A channel represents a two-dimensional viewport within a Window.
Definition: channel.h:42
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:49
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:215
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:63
The interface definition for system-specific GPU handling.
Definition: systemPipe.h:38
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:211
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&#39;s drawable and context current.
bool isStopped() const
Definition: window.h:107
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:265
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:391
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:53
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 bool processEvent(EventType type) override
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:101
float getFPS() const
Definition: window.h:216
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:144
const SystemWindow * getSystemWindow() const
Definition: window.h:262