]> git.saurik.com Git - wxWidgets.git/blame - include/wx/unix/glx11.h
make independent from carbon
[wxWidgets.git] / include / wx / unix / glx11.h
CommitLineData
498ace9e
VZ
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
5a83f42b 20class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase
498ace9e
VZ
21{
22public:
23 wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
24 virtual ~wxGLContext();
25
5ec69e96 26 virtual bool SetCurrent(const wxGLCanvas& win) const;
498ace9e
VZ
27
28private:
29 // attach context to the drawable or unset it (if NULL)
5ec69e96 30 static bool MakeCurrent(GLXDrawable drawable, GLXContext context);
498ace9e
VZ
31
32 GLXContext m_glContext;
33
34 DECLARE_CLASS(wxGLContext)
35};
36
37// ----------------------------------------------------------------------------
38// wxGLCanvasX11
39// ----------------------------------------------------------------------------
40
5a83f42b 41class WXDLLIMPEXP_GL wxGLCanvasX11 : public wxGLCanvasBase
498ace9e
VZ
42{
43public:
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
5ec69e96 60 virtual bool SwapBuffers();
498ace9e
VZ
61
62
63 // X11-specific methods
64 // --------------------
65
66 // return GLX version: 13 means 1.3 &c
67 static int GetGLXVersion();
68
69 // get the X11 handle of this window
70 virtual Window GetXWindow() const = 0;
71
72
73 // override some wxWindow methods
74 // ------------------------------
75
76 // return true only if the window is realized: OpenGL context can't be
77 // created until we are
78 virtual bool IsShownOnScreen() const;
79
80
81 // implementation only from now on
82 // -------------------------------
83
84 // get the GLXFBConfig/XVisualInfo we use
85 GLXFBConfig *GetGLXFBConfig() const { return m_fbc; }
86 XVisualInfo *GetXVisualInfo() const { return m_vi; }
87
88 // initialize the global default GL visual, return false if matching visual
89 // not found
90 static bool InitDefaultVisualInfo(const int *attribList);
91
92 // get the default GL X11 visual (may be NULL, shouldn't be freed by caller)
93 static XVisualInfo *GetDefaultXVisualInfo() { return ms_glVisualInfo; }
94
95 // free the global GL visual, called by wxGLApp
96 static void FreeDefaultVisualInfo();
97
3f20f7d8
VZ
98 // initializes XVisualInfo (in any case) and, if supported, GLXFBConfig
99 //
100 // returns false if XVisualInfo couldn't be initialized, otherwise caller
101 // is responsible for freeing the pointers
102 static bool InitXVisualInfo(const int *attribList,
103 GLXFBConfig **pFBC, XVisualInfo **pXVisual);
104
498ace9e
VZ
105private:
106 // fills in glattrs with attributes defined by wxattrs which must be
107 // 0-terminated if it is non-NULL
108 //
109 // n is the max size of glattrs, false is returned if we overflow it, it
110 // should be at least 16 to accommodate the default attributes
111 static bool ConvertWXAttrsToGL(const int *wxattrs, int *glattrs, size_t n);
112
498ace9e
VZ
113
114 // this is only used if it's supported i.e. if GL >= 1.3
115 GLXFBConfig *m_fbc;
116
117 // used for all GL versions, obtained from GLXFBConfig for GL >= 1.3
118 XVisualInfo *m_vi;
119
120 // the global/default versions of the above
121 static GLXFBConfig *ms_glFBCInfo;
122 static XVisualInfo *ms_glVisualInfo;
123};
124
125// ----------------------------------------------------------------------------
126// wxGLApp
127// ----------------------------------------------------------------------------
128
129// this is used in wx/glcanvas.h, prevent it from defining a generic wxGLApp
130#define wxGL_APP_DEFINED
131
5a83f42b 132class WXDLLIMPEXP_GL wxGLApp : public wxGLAppBase
498ace9e
VZ
133{
134public:
1c269771 135 wxGLApp() : wxGLAppBase() { }
498ace9e
VZ
136
137 // implement wxGLAppBase method
138 virtual bool InitGLVisual(const int *attribList)
139 {
140 return wxGLCanvasX11::InitDefaultVisualInfo(attribList);
141 }
142
143 // and implement this wxGTK::wxApp method too
144 virtual void *GetXVisualInfo()
145 {
146 return wxGLCanvasX11::GetDefaultXVisualInfo();
147 }
148
149 // and override this wxApp method to clean up
150 virtual int OnExit()
151 {
152 wxGLCanvasX11::FreeDefaultVisualInfo();
153
154 return wxGLAppBase::OnExit();
155 }
156
157private:
047b6c71 158 DECLARE_DYNAMIC_CLASS(wxGLApp)
498ace9e
VZ
159};
160
161#endif // _WX_UNIX_GLX11_H_
162