~ubuntu-branches/ubuntu/oneiric/nux/oneiric

« back to all changes in this revision

Viewing changes to NuxGraphics/GraphicsDisplayX11.h

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-12-09 19:56:53 UTC
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20101209195653-lsc4objqdxs9exp3
Tags: upstream-0.9.10
ImportĀ upstreamĀ versionĀ 0.9.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
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.
 
7
 *
 
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.
 
13
 *
 
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/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#ifndef GFXSETUPX11_H
 
24
#define GFXSETUPX11_H
 
25
 
 
26
#include "Gfx_Interface.h"
 
27
#include "GLTimer.h"
 
28
#include "GLDeviceObjects.h"
 
29
#include "GLRenderStates.h"
 
30
 
 
31
/* Xlib.h is the default header that is included and has the core functionallity */
 
32
#include <X11/Xlib.h>
 
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>
 
37
 
 
38
#include <X11/extensions/xf86vmode.h>
 
39
 
 
40
namespace nux
 
41
{
 
42
 
 
43
  struct IEvent;
 
44
  class MainFBO;
 
45
  class GpuDevice;
 
46
  class GraphicsEngine;
 
47
  class IOpenGLFrameBufferObject;
 
48
 
 
49
  enum WindowStyle
 
50
  {
 
51
    WINDOWSTYLE_NORMAL,
 
52
    WINDOWSTYLE_PANEL,
 
53
    WINDOWSTYLE_DIALOG,
 
54
    WINDOWSTYLE_TOOL,
 
55
    WINDOWSTYLE_NOBORDER,
 
56
  };
 
57
 
 
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
 
62
 
 
63
// This will become GLWindow
 
64
  class GraphicsDisplay : public GraphicSystem
 
65
  {
 
66
    friend class GraphicsEngine;
 
67
 
 
68
  private:
 
69
    Display     *m_X11Display;
 
70
    int         m_X11Screen;
 
71
    Window      m_X11Window;
 
72
    XVisualInfo *m_X11VisualInfo;
 
73
 
 
74
    int         m_ParentWindow;
 
75
    GLXContext  m_GLCtx;
 
76
    GLXFBConfig _fb_config;
 
77
    XSetWindowAttributes m_X11Attr;
 
78
 
 
79
    int m_NumVideoModes;
 
80
    XF86VidModeModeInfo **m_X11VideoModes;
 
81
    /* original desktop mode which we save so we can restore it later */
 
82
    XF86VidModeModeInfo m_X11OriginalVideoMode;
 
83
 
 
84
    Atom            m_WMDeleteWindow;
 
85
    Colormap        m_X11Colormap;
 
86
    int             m_BorderPixel;
 
87
 
 
88
    int _x11_major;
 
89
    int _x11_minor;
 
90
    int _glx_major;
 
91
    int _glx_minor;
 
92
    bool _has_glx_13;
 
93
 
 
94
    XEvent m_X11LastEvent;
 
95
    Bool m_X11RepeatKey;
 
96
 
 
97
    TCHAR m_WindowClassName[256];
 
98
    GLuint      m_PixelFormat;      // Holds The Results After Searching For A Match
 
99
    NString     m_WindowTitle;
 
100
 
 
101
    // size, position
 
102
    Size m_ViewportSize;
 
103
    Size m_WindowSize;
 
104
    Point m_WindowPosition;
 
105
 
 
106
    // surface attibute;
 
107
    bool m_Fullscreen;
 
108
    unsigned int m_ScreenBitDepth;
 
109
 
 
110
    // verifiy that the interface is properly created
 
111
    bool m_GfxInterfaceCreated;
 
112
 
 
113
    // Device information
 
114
    void GetDisplayInfo();
 
115
    int m_BestMode;
 
116
 
 
117
    bool m_is_window_minimized;
 
118
 
 
119
    static int X11KeySymToINL (int Keysym);
 
120
 
 
121
  public:
 
122
    bool HasXPendingEvent() const;
 
123
    Display *GetX11Display()
 
124
    {
 
125
      return m_X11Display;
 
126
    }
 
127
    // Device
 
128
    int m_num_device_modes;
 
129
 
 
130
    // Event object
 
131
    IEvent *m_pEvent;
 
132
 
 
133
    bool IsGfxInterfaceCreated();
 
134
 
 
135
    //! Create a window with and OpenGL context.
 
136
    /*!
 
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.
 
143
    */
 
144
    bool CreateOpenGLWindow (
 
145
      const TCHAR *WindowTitle,
 
146
      unsigned int WindowWidth,
 
147
      unsigned int WindowHeight,
 
148
      WindowStyle Style,
 
149
      const GraphicsDisplay *Parent,
 
150
      bool FullscreenFlag = false);
 
151
 
 
152
    //! Create a GLWindow from a display and window created externally.
 
153
    /*!
 
154
        @param X11Display   Provided display.
 
155
        @param X11Window    Provided window.
 
156
    */
 
157
    bool CreateFromOpenGLWindow (Display *X11Display, Window X11Window, GLXContext OpenGLContext);
 
158
 
 
159
    void DestroyOpenGLWindow();
 
160
 
 
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);
 
172
 
 
173
    // Event methods
 
174
    void GetSystemEvent (IEvent *evt);
 
175
 
 
176
    // Os specific
 
177
    int GetGlXMajor () const;
 
178
    int GetGlXMinor () const;
 
179
 
 
180
#if defined (NUX_OS_LINUX)
 
181
    void InjectXEvent (IEvent *evt, XEvent xevent);
 
182
#endif
 
183
    
 
184
    IEvent &GetCurrentEvent();
 
185
 
 
186
    bool isWindowMinimized() const
 
187
    {
 
188
      return m_is_window_minimized;
 
189
    }
 
190
 
 
191
    void ShowWindow();
 
192
    void HideWindow();
 
193
    void EnterMaximizeWindow();
 
194
    void ExitMaximizeWindow();
 
195
 
 
196
    Window GetWindowHandle() const
 
197
    {
 
198
      return m_X11Window;
 
199
    }
 
200
    bool IsChildWindow() const
 
201
    {
 
202
      return m_ParentWindow != 0;
 
203
    }
 
204
 
 
205
    // Return true if VSync swap control is available
 
206
    bool HasVSyncSwapControl() const;
 
207
    void EnableVSyncSwapControl();
 
208
    void DisableVSyncSwapControl();
 
209
 
 
210
    // m_FrameRate
 
211
    float GetFrameTime() const;
 
212
    void ResetFrameTime();
 
213
 
 
214
    GraphicsEngine *GetGraphicsEngine() const
 
215
    {
 
216
      return m_GraphicsContext;
 
217
    }
 
218
    GpuDevice *GetGpuDevice () const
 
219
    {
 
220
      return m_DeviceFactory;
 
221
    }
 
222
    // Dialog
 
223
    /*bool StartOpenFileDialog(FileDialogOption& fdo);
 
224
    bool StartSaveFileDialog(FileDialogOption& fdo);
 
225
    bool StartColorDialog(ColorDialogOption& cdo);*/
 
226
 
 
227
 
 
228
    void GetDesktopSize (int &w, int &h);
 
229
    void GetWindowSize (int &w, int &h);
 
230
    unsigned int GetWindowWidth();
 
231
    unsigned int GetWindowHeight();
 
232
 
 
233
    bool HasFrameBufferSupport();
 
234
    /*void SetWindowCursor(HCURSOR cursor);
 
235
    HCURSOR GetWindowCursor() const;*/
 
236
 
 
237
 
 
238
    //! Pause graphics rendering.
 
239
    /*!
 
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.
 
245
 
 
246
        Never call this function while doing rendering. Call it only when processing events.
 
247
    */
 
248
    void PauseThreadGraphicsRendering();
 
249
    bool IsPauseThreadGraphicsRendering() const;
 
250
 
 
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);
 
254
 
 
255
  private:
 
256
    bool m_PauseGraphicsRendering;
 
257
    GLTimer m_Timer;
 
258
    float m_FrameTime;
 
259
    GpuDevice *m_DeviceFactory;
 
260
    GraphicsEngine *m_GraphicsContext;
 
261
    WindowStyle m_Style;
 
262
 
 
263
  public:
 
264
    ~GraphicsDisplay();
 
265
    GLEWContext *GetGLEWContext()
 
266
    {
 
267
      return &m_GLEWContext;
 
268
    }
 
269
    GLXEWContext *GetGLXEWContext()
 
270
    {
 
271
      return &m_GLXEWContext;
 
272
    }
 
273
 
 
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);
 
278
 
 
279
    const std::vector<NString>& GetFontSearchPath() const
 
280
    {
 
281
      return m_FontSearchPath;
 
282
    }
 
283
    const std::vector<NString>& GetShaderSearchPath() const
 
284
    {
 
285
      return m_ShaderSearchPath;
 
286
    }
 
287
    const std::vector<NString>& GetUITextureSearchPath() const
 
288
    {
 
289
      return m_UITextureSearchPath;
 
290
    }
 
291
 
 
292
  private:
 
293
    std::vector<NString> m_FontSearchPath;
 
294
    std::vector<NString> m_ShaderSearchPath;
 
295
    std::vector<NString> m_UITextureSearchPath;
 
296
    FilePath m_ResourcePathLocation;
 
297
 
 
298
    GraphicsDisplay();
 
299
    GraphicsDisplay (const GraphicsDisplay &);
 
300
    // Does not make sense for a singleton. This is a self assignment.
 
301
    GraphicsDisplay &operator= (const GraphicsDisplay &);
 
302
 
 
303
    GLEWContext m_GLEWContext;
 
304
    GLXEWContext m_GLXEWContext;
 
305
    friend class DisplayAccessController;
 
306
  };
 
307
 
 
308
}
 
309
 
 
310
#endif //GFXSETUPX11_H