1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/glx11.h
3 // Purpose: class common for all X11-based wxGLCanvas implementations
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_UNIX_GLX11_H_
11 #define _WX_UNIX_GLX11_H_
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 class WXDLLIMPEXP_GL wxGLContext
: public wxGLContextBase
22 wxGLContext(wxGLCanvas
*win
, const wxGLContext
*other
= NULL
);
23 virtual ~wxGLContext();
25 virtual bool SetCurrent(const wxGLCanvas
& win
) const;
28 // attach context to the drawable or unset it (if NULL)
29 static bool MakeCurrent(GLXDrawable drawable
, GLXContext context
);
31 GLXContext m_glContext
;
33 DECLARE_CLASS(wxGLContext
)
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 class WXDLLIMPEXP_GL wxGLCanvasX11
: public wxGLCanvasBase
43 // initialization and dtor
44 // -----------------------
46 // default ctor doesn't do anything, InitVisual() must be called
49 // initializes the XVisualInfo corresponding to the given attributes
50 bool InitVisual(const int *attribList
);
52 // frees XVisualInfo info
53 virtual ~wxGLCanvasX11();
56 // implement wxGLCanvasBase methods
57 // --------------------------------
59 virtual bool SwapBuffers();
62 // X11-specific methods
63 // --------------------
65 // return GLX version: 13 means 1.3 &c
66 static int GetGLXVersion();
68 // return true if multisample extension is available
69 static bool IsGLXMultiSampleAvailable();
71 // get the X11 handle of this window
72 virtual Window
GetXWindow() const = 0;
75 // override some wxWindow methods
76 // ------------------------------
78 // return true only if the window is realized: OpenGL context can't be
79 // created until we are
80 virtual bool IsShownOnScreen() const;
83 // implementation only from now on
84 // -------------------------------
86 // get the GLXFBConfig/XVisualInfo we use
87 GLXFBConfig
*GetGLXFBConfig() const { return m_fbc
; }
88 XVisualInfo
*GetXVisualInfo() const { return m_vi
; }
90 // initialize the global default GL visual, return false if matching visual
92 static bool InitDefaultVisualInfo(const int *attribList
);
94 // get the default GL X11 visual (may be NULL, shouldn't be freed by caller)
95 static XVisualInfo
*GetDefaultXVisualInfo() { return ms_glVisualInfo
; }
97 // free the global GL visual, called by wxGLApp
98 static void FreeDefaultVisualInfo();
100 // initializes XVisualInfo (in any case) and, if supported, GLXFBConfig
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
);
108 // fills in glattrs with attributes defined by wxattrs which must be
109 // 0-terminated if it is non-NULL
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
);
116 // this is only used if it's supported i.e. if GL >= 1.3
119 // used for all GL versions, obtained from GLXFBConfig for GL >= 1.3
122 // the global/default versions of the above
123 static GLXFBConfig
*ms_glFBCInfo
;
124 static XVisualInfo
*ms_glVisualInfo
;
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
131 // this is used in wx/glcanvas.h, prevent it from defining a generic wxGLApp
132 #define wxGL_APP_DEFINED
134 class WXDLLIMPEXP_GL wxGLApp
: public wxGLAppBase
137 wxGLApp() : wxGLAppBase() { }
139 // implement wxGLAppBase method
140 virtual bool InitGLVisual(const int *attribList
)
142 return wxGLCanvasX11::InitDefaultVisualInfo(attribList
);
145 // and implement this wxGTK::wxApp method too
146 virtual void *GetXVisualInfo()
148 return wxGLCanvasX11::GetDefaultXVisualInfo();
151 // and override this wxApp method to clean up
154 wxGLCanvasX11::FreeDefaultVisualInfo();
156 return wxGLAppBase::OnExit();
160 DECLARE_DYNAMIC_CLASS(wxGLApp
)
163 #endif // _WX_UNIX_GLX11_H_