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