Equalizer  2.1.0
Parallel Rendering Framework
window.h
Go to the documentation of this file.
1 /* Copyright (c) 2005-2017, 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/notifierInterface.h> // base class
23 #include <eq/types.h>
24 #include <eq/visitorResult.h> // enum
25 #include <eq/windowSettings.h> // template param
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 
34 namespace eq
35 {
62 class Window : public fabric::Window<Pipe, Window, Channel, WindowSettings>,
63  public NotifierInterface
64 {
65 public:
67  EQ_API explicit Window(Pipe* parent);
68 
70  EQ_API virtual ~Window();
71 
74  EQ_API co::CommandQueue* getPipeThreadQueue();
75  EQ_API co::CommandQueue* getCommandThreadQueue();
76  EQ_API uint32_t getCurrentFrame() const;
77 
79  EQ_API const Node* getNode() const;
80 
82  EQ_API Node* getNode();
83 
85  EQ_API const Config* getConfig() const;
86 
88  EQ_API Config* getConfig();
89 
91  EQ_API ClientPtr getClient();
92 
94  EQ_API ServerPtr getServer();
95 
100  bool isRunning() const { return (_state == STATE_RUNNING); }
105  bool isStopped() const { return (_state == STATE_STOPPED); }
115  EQ_API bool getRenderContext(const int32_t x, const int32_t y,
116  RenderContext& context) const;
118 
132  EQ_API void setSharedContextWindow(const Window* sharedContextWindow);
133 
138  EQ_API const Window* getSharedContextWindow() const;
139 
141  util::ObjectManager& getObjectManager() { return _objectManager; }
144  {
145  return _objectManager;
146  }
147 
152  EQ_API const util::BitmapFont* getSmallFont();
153 
158  EQ_API const util::BitmapFont* getMediumFont();
159 
174  EQ_API const GLEWContext* glewGetContext() const;
175 
177  EQ_API const GLEWContext* getTransferGlewContext() const;
178 
184  EQ_API uint32_t getColorFormat() const;
186 
196  EQ_API virtual void flush() const;
197 
205  EQ_API virtual void finish() const;
206 
208  EQ_API virtual void swapBuffers();
209 
211  EQ_API virtual void drawFPS();
212 
214  float getFPS() const { return _avgFPS; }
224  EQ_API virtual void makeCurrent(const bool cache = true) const;
225 
230  EQ_API virtual void doneCurrent() const;
231 
233  EQ_API virtual void bindFrameBuffer() const;
234 
237  EQ_API virtual void bindDrawFrameBuffer() const;
238 
240  EQ_API virtual void updateFrameBuffer() const;
241 
243  EQ_API void notifyViewportChanged() override;
245 
257  EQ_API void setSystemWindow(SystemWindow* window);
258 
260  const SystemWindow* getSystemWindow() const { return _systemWindow; }
262  SystemWindow* getSystemWindow() { return _systemWindow; }
264  const SystemPipe* getSystemPipe() const;
265 
268 
270  bool createTransferWindow();
271 
273  void deleteTransferWindow();
274 
276  SystemWindow* getTransferWindow();
277  const SystemWindow* getTransferWindow() const;
278 
279 
288  EQ_API EventOCommand sendError(const uint32_t error) final;
289 
291  EQ_API bool processEvent(EventType type) override;
292 
294  EQ_API bool processEvent(EventType type, SizeEvent& event) override;
295 
297  EQ_API bool processEvent(EventType type, PointerEvent& event) override;
298 
300  EQ_API bool processEvent(EventType type, KeyEvent& event) override;
301 
303  EQ_API bool processEvent(AxisEvent& event) override;
304 
306  EQ_API bool processEvent(ButtonEvent& event) override;
307 
308  EQ_API bool processEvent(Statistic& event);
310 
311 protected:
312  friend class Pipe;
313 
315  EQ_API
316  void attach(const uint128_t& id, const uint32_t instanceID) override;
317 
326  EQ_API void startFrame(const uint32_t frameNumber);
327 
334  EQ_API void releaseFrame(const uint32_t frameNumber);
335 
342  EQ_API void releaseFrameLocal(const uint32_t frameNumber);
344 
358  EQ_API virtual bool configInit(const uint128_t& initID);
359 
366  EQ_API virtual bool configInitSystemWindow(const uint128_t& initID);
367 
378  EQ_API virtual bool configInitGL(const uint128_t& initID);
379 
381  EQ_API virtual bool configExit();
382 
384  EQ_API virtual bool configExitSystemWindow();
385 
387  virtual bool configExitGL() { return true; }
398  EQ_API virtual void frameStart(const uint128_t& frameID,
399  const uint32_t frameNumber);
400 
414  EQ_API virtual void frameFinish(const uint128_t& frameID,
415  const uint32_t frameNumber);
416 
427  EQ_API virtual void frameDrawFinish(const uint128_t& frameID,
428  const uint32_t frameNumber);
430 
431 private:
432  enum State
433  {
434  STATE_STOPPED,
435  STATE_INITIALIZING,
436  STATE_RUNNING,
437  STATE_FAILED
438  };
439 
441  const Window* _sharedContextWindow;
442 
444  SystemWindow* _transferWindow;
445 
447  SystemWindow* _systemWindow;
448 
450  State _state;
451 
453  util::ObjectManager _objectManager;
454 
456  float _lastTime;
457 
459  float _avgFPS;
460 
462  std::vector<RenderContext> _renderContexts[2];
463  enum
464  {
465  FRONT = 0,
466  BACK = 1
467  };
468 
470  int64_t _lastSwapTime;
471 
473  Channels _grabbedChannels;
474 
475  struct Private;
476  Private* _private; // placeholder for binary-compatible changes
477 
479  void _addRenderContext(const RenderContext& context);
480  friend class Channel;
481 
483  Channels _getEventChannels(const PointerEvent& event);
484 
486  void _setupObjectManager();
488  void _releaseObjectManager();
489 
491  void _updateFPS();
492 
494  void _enterBarrier(co::ObjectVersion barrier);
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  bool _cmdResize(co::ICommand& command);
511 
512  LB_TS_VAR(_pipeThread)
513 };
514 }
515 
516 #endif // EQ_WINDOW_H
virtual EQ_API bool configInitSystemWindow(const uint128_t &initID)
Initialize the OS-specific window.
lunchbox::RefPtr< Server > ServerPtr
A reference-counted pointer to an eq::Server.
Definition: eq/types.h:215
const util::ObjectManager & getObjectManager() const
Definition: window.h:143
A channel represents a two-dimensional viewport within a Window.
Definition: channel.h:46
EQ_API const Config * getConfig() const
A configuration is a visualization session driven by an application.
Definition: config.h:58
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:34
EQ_API void setSystemWindow(SystemWindow *window)
Set the OS-specific window.
A Node represents a single computer in the cluster.
Definition: node.h:52
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
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:62
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.
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:105
virtual EQ_API bool configExit()
Exit this window.
std::vector< Channel * > Channels
A vector of pointers to channels.
Definition: fabric/window.h:41
EQ_API ServerPtr getServer()
The Equalizer client library.
Definition: eq/agl/types.h:23
lunchbox::RefPtr< Client > ClientPtr
A reference-counted pointer to an eq::Client.
Definition: eq/types.h:211
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:262
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:387
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:56
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:100
float getFPS() const
Definition: window.h:214
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:141
const SystemWindow * getSystemWindow() const
Definition: window.h:260