Line data Source code
1 :
2 : /* Copyright (c) 2005-2017, Stefan Eilemann <eile@equalizergraphics.com>
3 : * Daniel Nachbaur <danielnachbaur@gmail.com>
4 : * Maxim Makhinya
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_GLX_WINDOW_H
21 : #define EQ_GLX_WINDOW_H
22 :
23 : #include <eq/glWindow.h> // base class
24 : #include <eq/glx/types.h>
25 :
26 : namespace eq
27 : {
28 : namespace glx
29 : {
30 : namespace detail
31 : {
32 : class Window;
33 : }
34 :
35 : /** The interface defining the minimum functionality for a glX window. */
36 : class WindowIF : public GLWindow
37 : {
38 : public:
39 3 : WindowIF(NotifierInterface& parent, const WindowSettings& settings)
40 3 : : GLWindow(parent, settings)
41 : {
42 3 : }
43 3 : virtual ~WindowIF() {}
44 : /** @return the glX rendering context. @version 1.0 */
45 : virtual GLXContext getGLXContext() const = 0;
46 :
47 : /** @return the X11 drawable ID. @version 1.0 */
48 : virtual XID getXDrawable() const = 0;
49 :
50 : /** @return X11 display connection. @version 1.0 */
51 : virtual Display* getXDisplay() = 0;
52 :
53 : /** Process a (re)size event. @return true if the event was handled. */
54 0 : virtual bool processEvent(EventType type, const XEvent&, SizeEvent& event)
55 : {
56 0 : return GLWindow::processEvent(type, event);
57 : }
58 :
59 : /** Process a mouse event. @return true if the event was handled. */
60 0 : virtual bool processEvent(EventType type, const XEvent&,
61 : PointerEvent& event)
62 : {
63 0 : return GLWindow::processEvent(type, event);
64 : }
65 :
66 : /** Process a keyboard event. @return true if the event was handled. */
67 0 : virtual bool processEvent(EventType type, const XEvent&, KeyEvent& event)
68 : {
69 0 : return GLWindow::processEvent(type, event);
70 : }
71 :
72 : /** Process an axis event. @return true if the event was handled. */
73 0 : virtual bool processEvent(const XEvent&, AxisEvent& event)
74 : {
75 0 : return GLWindow::processEvent(event);
76 : }
77 :
78 : /** Process a button event. @return true if the event was handled. */
79 0 : virtual bool processEvent(const XEvent&, ButtonEvent& event)
80 : {
81 0 : return GLWindow::processEvent(event);
82 : }
83 :
84 : /** Process a stateless event. @return true if the event was handled. */
85 2 : virtual bool processEvent(EventType type, const XEvent&)
86 : {
87 2 : if (type == EVENT_UNKNOWN)
88 1 : return false;
89 1 : return GLWindow::processEvent(type);
90 : }
91 : };
92 :
93 : /** Equalizer default implementation of a glX window */
94 : class Window : public WindowIF
95 : {
96 : public:
97 : /**
98 : * Construct a new glX/X11 system window.
99 : * @version 1.7.2
100 : */
101 : Window(NotifierInterface& parent, const WindowSettings& settings,
102 : Display* xDisplay, const GLXEWContext* glxewContext,
103 : MessagePump* messagePump);
104 :
105 : /** Destruct this glX window. @version 1.0 */
106 : virtual ~Window();
107 :
108 : /** @name GLX/X11 initialization */
109 : //@{
110 : /**
111 : * Initialize this window for the glX window system.
112 : *
113 : * This method first call chooseGLXFBConfig(), then createGLXContext()
114 : * with the chosen framebuffer config, and finally creates a drawable
115 : * using configInitGLXDrawable().
116 : *
117 : * @return true if the initialization was successful, false otherwise.
118 : * @version 1.0
119 : */
120 : bool configInit() override;
121 :
122 : /** @version 1.0 */
123 : void configExit() override;
124 :
125 : /**
126 : * Choose a GLX framebuffer config based on the window's attributes.
127 : *
128 : * The returned FB config has to be freed using XFree().
129 : *
130 : * @return a pixel format, or 0 if no pixel format was found.
131 : * @version 1.0
132 : */
133 : virtual GLXFBConfig* chooseGLXFBConfig();
134 :
135 : /**
136 : * Create a glX context.
137 : *
138 : * This method does not set the window's glX context.
139 : *
140 : * @param fbConfig the framebuffer config for the context.
141 : * @return the context, or 0 if context creation failed.
142 : * @version 1.0
143 : */
144 : virtual GLXContext createGLXContext(GLXFBConfig* fbConfig);
145 :
146 : /**
147 : * Initialize the window's drawable and bind the glX context.
148 : *
149 : * Sets the window's X11 drawable on success
150 : *
151 : * @param fbConfig the framebuffer config for the context.
152 : * @return true if the drawable was created, false otherwise.
153 : * @version 1.0
154 : */
155 : virtual bool configInitGLXDrawable(GLXFBConfig* fbConfig);
156 :
157 : /**
158 : * Initialize the window with a window and bind the glX context.
159 : *
160 : * Sets the window's X11 drawable on success
161 : *
162 : * @param fbConfig the framebuffer config for the context.
163 : * @return true if the window was created, false otherwise.
164 : * @version 1.0
165 : */
166 : virtual bool configInitGLXWindow(GLXFBConfig* fbConfig);
167 :
168 : /**
169 : * Register with the pipe's GLXEventHandler, called by setXDrawable().
170 : * @version 1.0
171 : */
172 : virtual void initEventHandler();
173 :
174 : /**
175 : * Deregister with the GLXEventHandler, called by setXDrawable().
176 : * @version 1.0
177 : */
178 : virtual void exitEventHandler();
179 : //@}
180 :
181 : /** @name Data Access. */
182 : //@{
183 : /** @return the glX rendering context. @version 1.0 */
184 : GLXContext getGLXContext() const override;
185 :
186 : /** @return the X11 drawable ID. @version 1.0 */
187 : XID getXDrawable() const override;
188 :
189 : /** @return the X11 display. @version 1.0 */
190 : Display* getXDisplay() override;
191 :
192 : /** @return the GLXEW context. @version 1.0*/
193 : const GLXEWContext* glxewGetContext() const;
194 :
195 : /**
196 : * Set the X11 drawable ID for this window.
197 : *
198 : * This function should only be called from configInit() or
199 : * configExit().
200 : *
201 : * @param drawable the X11 drawable ID.
202 : * @version 1.0
203 : */
204 : virtual void setXDrawable(XID drawable);
205 :
206 : /**
207 : * Set the glX rendering context for this window.
208 : *
209 : * This function should only be called from configInit() or
210 : * configExit().
211 : * The context has to be set to 0 before it is destroyed.
212 : *
213 : * @param context the glX rendering context.
214 : * @version 1.0
215 : */
216 : virtual void setGLXContext(GLXContext context);
217 : //@}
218 :
219 : /** @name Operations. */
220 : //@{
221 : /** @version 1.0 */
222 : void makeCurrent(const bool cache = true) const override;
223 :
224 : /** @version 1.10 */
225 : void doneCurrent() const override;
226 :
227 : /** @version 1.0 */
228 : void swapBuffers() override;
229 :
230 : /** Implementation untested for glX. @version 1.0 */
231 : void joinNVSwapBarrier(const uint32_t group,
232 : const uint32_t barrier) override;
233 :
234 : /** Unbind a GLX_NV_swap_barrier. @version 1.0 */
235 : void leaveNVSwapBarrier();
236 :
237 : bool processEvent(EventType type, const XEvent& xEvent,
238 : PointerEvent& event) override;
239 : //@}
240 :
241 : private:
242 : detail::Window* const _impl;
243 :
244 : /** Create an unmapped X11 window. */
245 : XID _createGLXWindow(GLXFBConfig* fbConfig, const PixelViewport& pvp);
246 :
247 : /** Init sync-to-vertical-retrace setting. */
248 : void _initSwapSync();
249 :
250 : void _resize(const PixelViewport& pvp) override;
251 : };
252 : }
253 : }
254 : #endif // EQ_GLX_WINDOW_H
|