2
* Copyright 2010 Inalogic Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3, as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the applicable version of the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of both the GNU Lesser General Public
15
* License version 3 along with this program. If not, see
16
* <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jaytaoko@inalogic.com>
26
#include "Gfx_Interface.h"
28
#include "GLDeviceObjects.h"
29
#include "GLRenderStates.h"
31
/* Xlib.h is the default header that is included and has the core functionallity */
33
/* Xatom.h includes functionallity for creating new protocol messages */
34
#include <X11/Xatom.h>
35
/* keysym.h contains keysymbols which we use to resolv what keys that are being pressed */
36
#include <X11/keysym.h>
38
#include <X11/extensions/xf86vmode.h>
47
class IOpenGLFrameBufferObject;
58
#define NUX_THREADMSG (WM_APP+0)
59
#define NUX_THREADMSG_START_RENDERING (WM_APP+1) // Connection established // start at WM_APP
60
#define NUX_THREADMSG_CHILD_WINDOW_TERMINATED (WM_APP+2) // General failure - Wait Connection failed
61
#define NUX_THREADMSG_THREAD_TERMINATED (WM_APP+3) // Set wParam = Thread ID, lParam = 0
63
// This will become GLWindow
64
class GraphicsDisplay : public GraphicSystem
66
friend class GraphicsEngine;
69
Display *m_X11Display;
72
XVisualInfo *m_X11VisualInfo;
76
GLXFBConfig _fb_config;
77
XSetWindowAttributes m_X11Attr;
80
XF86VidModeModeInfo **m_X11VideoModes;
81
/* original desktop mode which we save so we can restore it later */
82
XF86VidModeModeInfo m_X11OriginalVideoMode;
84
Atom m_WMDeleteWindow;
85
Colormap m_X11Colormap;
94
XEvent m_X11LastEvent;
97
TCHAR m_WindowClassName[256];
98
GLuint m_PixelFormat; // Holds The Results After Searching For A Match
99
NString m_WindowTitle;
104
Point m_WindowPosition;
108
unsigned int m_ScreenBitDepth;
110
// verifiy that the interface is properly created
111
bool m_GfxInterfaceCreated;
113
// Device information
114
void GetDisplayInfo();
117
bool m_is_window_minimized;
119
static int X11KeySymToINL (int Keysym);
122
bool HasXPendingEvent() const;
123
Display *GetX11Display()
128
int m_num_device_modes;
133
bool IsGfxInterfaceCreated();
135
//! Create a window with and OpenGL context.
137
@param WindowTitle The window title.
138
@param WindowWidth Initial window width.
139
@param WindowHeight Initial window height.
140
@param Style The window style.
141
@param ParentWindow The parent window.
142
@param FullscreenFlag Full screen flag.
144
bool CreateOpenGLWindow (
145
const TCHAR *WindowTitle,
146
unsigned int WindowWidth,
147
unsigned int WindowHeight,
149
const GraphicsDisplay *Parent,
150
bool FullscreenFlag = false);
152
//! Create a GLWindow from a display and window created externally.
154
@param X11Display Provided display.
155
@param X11Window Provided window.
157
bool CreateFromOpenGLWindow (Display *X11Display, Window X11Window, GLXContext OpenGLContext);
159
void DestroyOpenGLWindow();
161
void SetWindowTitle (const TCHAR *Title);
162
void SetWindowSize (int width, int height);
163
void SetWindowPosition (int width, int height);
164
void SetViewPort (int x, int y, int width, int height);
165
Point GetMouseScreenCoord();
166
Point GetMouseWindowCoord();
167
Point GetWindowCoord();
168
Rect GetWindowGeometry();
169
Rect GetNCWindowGeometry();
170
void MakeGLContextCurrent();
171
void SwapBuffer (bool glswap = true);
174
void GetSystemEvent (IEvent *evt);
177
int GetGlXMajor () const;
178
int GetGlXMinor () const;
180
#if defined (NUX_OS_LINUX)
181
void InjectXEvent (IEvent *evt, XEvent xevent);
184
IEvent &GetCurrentEvent();
186
bool isWindowMinimized() const
188
return m_is_window_minimized;
193
void EnterMaximizeWindow();
194
void ExitMaximizeWindow();
196
Window GetWindowHandle() const
200
bool IsChildWindow() const
202
return m_ParentWindow != 0;
205
// Return true if VSync swap control is available
206
bool HasVSyncSwapControl() const;
207
void EnableVSyncSwapControl();
208
void DisableVSyncSwapControl();
211
float GetFrameTime() const;
212
void ResetFrameTime();
214
GraphicsEngine *GetGraphicsEngine() const
216
return m_GraphicsContext;
218
GpuDevice *GetGpuDevice () const
220
return m_DeviceFactory;
223
/*bool StartOpenFileDialog(FileDialogOption& fdo);
224
bool StartSaveFileDialog(FileDialogOption& fdo);
225
bool StartColorDialog(ColorDialogOption& cdo);*/
228
void GetDesktopSize (int &w, int &h);
229
void GetWindowSize (int &w, int &h);
230
unsigned int GetWindowWidth();
231
unsigned int GetWindowHeight();
233
bool HasFrameBufferSupport();
234
/*void SetWindowCursor(HCURSOR cursor);
235
HCURSOR GetWindowCursor() const;*/
238
//! Pause graphics rendering.
240
Pause graphics rendering.
241
This function also sets the current openGL context to 0 for this window.
242
This is useful while a child window is being created and is sharing openGL objects with this context.
243
For wglShareLists to work, both OpenGL context must be set to 0 in their respective thread.
244
Send NUX_THREADMSG_START_RENDERING (PostThreadMessage) to this window to reactivate rendering.
246
Never call this function while doing rendering. Call it only when processing events.
248
void PauseThreadGraphicsRendering();
249
bool IsPauseThreadGraphicsRendering() const;
251
void ProcessForeignX11Event (XEvent *xevent, IEvent *nux_event);
252
void ProcessXEvent (XEvent xevent, bool foreign);
253
void RecalcXYPosition (Window TheMainWindow, XEvent xevent, int &x, int &y);
256
bool m_PauseGraphicsRendering;
259
GpuDevice *m_DeviceFactory;
260
GraphicsEngine *m_GraphicsContext;
265
GLEWContext *GetGLEWContext()
267
return &m_GLEWContext;
269
GLXEWContext *GetGLXEWContext()
271
return &m_GLXEWContext;
274
NString FindResourceLocation (const TCHAR *ResourceFileName, bool ErrorOnFail = false);
275
NString FindUITextureLocation (const TCHAR *ResourceFileName, bool ErrorOnFail = false);
276
NString FindShaderLocation (const TCHAR *ResourceFileName, bool ErrorOnFail = false);
277
NString FindFontLocation (const TCHAR *ResourceFileName, bool ErrorOnFail = false);
279
const std::vector<NString>& GetFontSearchPath() const
281
return m_FontSearchPath;
283
const std::vector<NString>& GetShaderSearchPath() const
285
return m_ShaderSearchPath;
287
const std::vector<NString>& GetUITextureSearchPath() const
289
return m_UITextureSearchPath;
293
std::vector<NString> m_FontSearchPath;
294
std::vector<NString> m_ShaderSearchPath;
295
std::vector<NString> m_UITextureSearchPath;
296
FilePath m_ResourcePathLocation;
299
GraphicsDisplay (const GraphicsDisplay &);
300
// Does not make sense for a singleton. This is a self assignment.
301
GraphicsDisplay &operator= (const GraphicsDisplay &);
303
GLEWContext m_GLEWContext;
304
GLXEWContext m_GLXEWContext;
305
friend class DisplayAccessController;
310
#endif //GFXSETUPX11_H