]> git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/glx11.h
Use wxGetTranslation() instead of _() in the public headers.
[wxWidgets.git] / include / wx / unix / glx11.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/glx11.h
3 // Purpose: class common for all X11-based wxGLCanvas implementations
4 // Author: Vadim Zeitlin
5 // Created: 2007-04-15
6 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_UNIX_GLX11_H_
11 #define _WX_UNIX_GLX11_H_
12
13 #include <GL/glx.h>
14
15 // ----------------------------------------------------------------------------
16 // wxGLContext
17 // ----------------------------------------------------------------------------
18
19 class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase
20 {
21 public:
22 wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
23 virtual ~wxGLContext();
24
25 virtual bool SetCurrent(const wxGLCanvas& win) const;
26
27 private:
28 // attach context to the drawable or unset it (if NULL)
29 static bool MakeCurrent(GLXDrawable drawable, GLXContext context);
30
31 GLXContext m_glContext;
32
33 DECLARE_CLASS(wxGLContext)
34 };
35
36 // ----------------------------------------------------------------------------
37 // wxGLCanvasX11
38 // ----------------------------------------------------------------------------
39
40 class WXDLLIMPEXP_GL wxGLCanvasX11 : public wxGLCanvasBase
41 {
42 public:
43 // initialization and dtor
44 // -----------------------
45
46 // default ctor doesn't do anything, InitVisual() must be called
47 wxGLCanvasX11();
48
49 // initializes the XVisualInfo corresponding to the given attributes
50 bool InitVisual(const int *attribList);
51
52 // frees XVisualInfo info
53 virtual ~wxGLCanvasX11();
54
55
56 // implement wxGLCanvasBase methods
57 // --------------------------------
58
59 virtual bool SwapBuffers();
60
61
62 // X11-specific methods
63 // --------------------
64
65 // return GLX version: 13 means 1.3 &c
66 static int GetGLXVersion();
67
68 // return true if multisample extension is available
69 static bool IsGLXMultiSampleAvailable();
70
71 // get the X11 handle of this window
72 virtual Window GetXWindow() const = 0;
73
74
75 // override some wxWindow methods
76 // ------------------------------
77
78 // return true only if the window is realized: OpenGL context can't be
79 // created until we are
80 virtual bool IsShownOnScreen() const;
81
82
83 // implementation only from now on
84 // -------------------------------
85
86 // get the GLXFBConfig/XVisualInfo we use
87 GLXFBConfig *GetGLXFBConfig() const { return m_fbc; }
88 XVisualInfo *GetXVisualInfo() const { return m_vi; }
89
90 // initialize the global default GL visual, return false if matching visual
91 // not found
92 static bool InitDefaultVisualInfo(const int *attribList);
93
94 // get the default GL X11 visual (may be NULL, shouldn't be freed by caller)
95 static XVisualInfo *GetDefaultXVisualInfo() { return ms_glVisualInfo; }
96
97 // free the global GL visual, called by wxGLApp
98 static void FreeDefaultVisualInfo();
99
100 // initializes XVisualInfo (in any case) and, if supported, GLXFBConfig
101 //
102 // returns false if XVisualInfo couldn't be initialized, otherwise caller
103 // is responsible for freeing the pointers
104 static bool InitXVisualInfo(const int *attribList,
105 GLXFBConfig **pFBC, XVisualInfo **pXVisual);
106
107 private:
108 // fills in glattrs with attributes defined by wxattrs which must be
109 // 0-terminated if it is non-NULL
110 //
111 // n is the max size of glattrs, false is returned if we overflow it, it
112 // should be at least 16 to accommodate the default attributes
113 static bool ConvertWXAttrsToGL(const int *wxattrs, int *glattrs, size_t n);
114
115
116 // this is only used if it's supported i.e. if GL >= 1.3
117 GLXFBConfig *m_fbc;
118
119 // used for all GL versions, obtained from GLXFBConfig for GL >= 1.3
120 XVisualInfo *m_vi;
121
122 // the global/default versions of the above
123 static GLXFBConfig *ms_glFBCInfo;
124 static XVisualInfo *ms_glVisualInfo;
125 };
126
127 // ----------------------------------------------------------------------------
128 // wxGLApp
129 // ----------------------------------------------------------------------------
130
131 // this is used in wx/glcanvas.h, prevent it from defining a generic wxGLApp
132 #define wxGL_APP_DEFINED
133
134 class WXDLLIMPEXP_GL wxGLApp : public wxGLAppBase
135 {
136 public:
137 wxGLApp() : wxGLAppBase() { }
138
139 // implement wxGLAppBase method
140 virtual bool InitGLVisual(const int *attribList)
141 {
142 return wxGLCanvasX11::InitDefaultVisualInfo(attribList);
143 }
144
145 // and implement this wxGTK::wxApp method too
146 virtual void *GetXVisualInfo()
147 {
148 return wxGLCanvasX11::GetDefaultXVisualInfo();
149 }
150
151 // and override this wxApp method to clean up
152 virtual int OnExit()
153 {
154 wxGLCanvasX11::FreeDefaultVisualInfo();
155
156 return wxGLAppBase::OnExit();
157 }
158
159 private:
160 DECLARE_DYNAMIC_CLASS(wxGLApp)
161 };
162
163 #endif // _WX_UNIX_GLX11_H_
164