Avoid including X11 headers from <wx/glcanvas.h>
It's generally wxWidgets policy not to include platform-specific headers from our own to avoid namespace pollution issues, in this case with names like "None" and "Window".
This commit is contained in:
@@ -63,7 +63,7 @@ public:
|
||||
// implement wxGLCanvasX11 methods
|
||||
// --------------------------------
|
||||
|
||||
virtual Window GetXWindow() const wxOVERRIDE;
|
||||
virtual unsigned long GetXWindow() const wxOVERRIDE;
|
||||
|
||||
|
||||
// deprecated methods
|
||||
|
@@ -61,7 +61,7 @@ public:
|
||||
// implement wxGLCanvasX11 methods
|
||||
// -------------------------------
|
||||
|
||||
virtual Window GetXWindow() const;
|
||||
virtual unsigned long GetXWindow() const;
|
||||
|
||||
|
||||
// deprecated methods
|
||||
|
@@ -10,10 +10,10 @@
|
||||
#ifndef _WX_UNIX_GLX11_H_
|
||||
#define _WX_UNIX_GLX11_H_
|
||||
|
||||
#include <GL/glx.h>
|
||||
#include <GL/gl.h>
|
||||
|
||||
class wxGLContextAttrs;
|
||||
class wxGLAttributes;
|
||||
typedef struct __GLXcontextRec* GLXContext;
|
||||
typedef struct __GLXFBConfigRec* GLXFBConfig;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxGLContext
|
||||
@@ -30,9 +30,6 @@ public:
|
||||
virtual bool SetCurrent(const wxGLCanvas& win) const wxOVERRIDE;
|
||||
|
||||
private:
|
||||
// attach context to the drawable or unset it (if NULL)
|
||||
static bool MakeCurrent(GLXDrawable drawable, GLXContext context);
|
||||
|
||||
GLXContext m_glContext;
|
||||
|
||||
wxDECLARE_CLASS(wxGLContext);
|
||||
@@ -74,7 +71,7 @@ public:
|
||||
static bool IsGLXMultiSampleAvailable();
|
||||
|
||||
// get the X11 handle of this window
|
||||
virtual Window GetXWindow() const = 0;
|
||||
virtual unsigned long GetXWindow() const = 0;
|
||||
|
||||
|
||||
// GLX-specific methods
|
||||
@@ -93,36 +90,15 @@ public:
|
||||
|
||||
// get the GLXFBConfig/XVisualInfo we use
|
||||
GLXFBConfig *GetGLXFBConfig() const { return m_fbc; }
|
||||
XVisualInfo *GetXVisualInfo() const { return m_vi; }
|
||||
void* GetXVisualInfo() const { return m_vi; }
|
||||
|
||||
// initialize the global default GL visual, return false if matching visual
|
||||
// not found
|
||||
static bool InitDefaultVisualInfo(const int *attribList);
|
||||
|
||||
// get the default GL X11 visual (may be NULL, shouldn't be freed by caller)
|
||||
static XVisualInfo *GetDefaultXVisualInfo() { return ms_glVisualInfo; }
|
||||
|
||||
// free the global GL visual, called by wxGLApp
|
||||
static void FreeDefaultVisualInfo();
|
||||
|
||||
// initializes XVisualInfo (in any case) and, if supported, GLXFBConfig
|
||||
//
|
||||
// returns false if XVisualInfo couldn't be initialized, otherwise caller
|
||||
// is responsible for freeing the pointers
|
||||
static bool InitXVisualInfo(const wxGLAttributes& dispAttrs,
|
||||
GLXFBConfig **pFBC, XVisualInfo **pXVisual);
|
||||
|
||||
private:
|
||||
|
||||
// this is only used if it's supported i.e. if GL >= 1.3
|
||||
GLXFBConfig *m_fbc;
|
||||
|
||||
// used for all GL versions, obtained from GLXFBConfig for GL >= 1.3
|
||||
XVisualInfo *m_vi;
|
||||
|
||||
// the global/default versions of the above
|
||||
static GLXFBConfig *ms_glFBCInfo;
|
||||
static XVisualInfo *ms_glVisualInfo;
|
||||
void* m_vi;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -135,29 +111,15 @@ private:
|
||||
class WXDLLIMPEXP_GL wxGLApp : public wxGLAppBase
|
||||
{
|
||||
public:
|
||||
wxGLApp() : wxGLAppBase() { }
|
||||
|
||||
// implement wxGLAppBase method
|
||||
virtual bool InitGLVisual(const int *attribList) wxOVERRIDE
|
||||
{
|
||||
return wxGLCanvasX11::InitDefaultVisualInfo(attribList);
|
||||
}
|
||||
virtual bool InitGLVisual(const int *attribList) wxOVERRIDE;
|
||||
|
||||
// This method is not currently used by the library itself, but remains for
|
||||
// backwards compatibility and also because wxGTK has it we could start
|
||||
// using it for the same purpose in wxX11 too some day.
|
||||
virtual void* GetXVisualInfo() wxOVERRIDE
|
||||
{
|
||||
return wxGLCanvasX11::GetDefaultXVisualInfo();
|
||||
}
|
||||
virtual void* GetXVisualInfo() wxOVERRIDE;
|
||||
|
||||
// and override this wxApp method to clean up
|
||||
virtual int OnExit() wxOVERRIDE
|
||||
{
|
||||
wxGLCanvasX11::FreeDefaultVisualInfo();
|
||||
|
||||
return wxGLAppBase::OnExit();
|
||||
}
|
||||
virtual int OnExit() wxOVERRIDE;
|
||||
|
||||
private:
|
||||
wxDECLARE_DYNAMIC_CLASS(wxGLApp);
|
||||
|
@@ -57,7 +57,7 @@ public:
|
||||
// implement wxGLCanvasX11 methods
|
||||
// --------------------------------
|
||||
|
||||
virtual Window GetXWindow() const;
|
||||
virtual unsigned long GetXWindow() const;
|
||||
|
||||
protected:
|
||||
virtual int GetColourIndex(const wxColour& col);
|
||||
|
@@ -118,11 +118,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
||||
{ WX_GL_RGBA, WX_GL_MIN_RED, 1, WX_GL_MIN_GREEN, 1,
|
||||
WX_GL_MIN_BLUE, 1, WX_GL_DEPTH_SIZE, 1,
|
||||
WX_GL_DOUBLEBUFFER,
|
||||
# if defined(__WXMAC__) || defined(__WXQT__)
|
||||
GL_NONE };
|
||||
# else
|
||||
None };
|
||||
# endif
|
||||
0 };
|
||||
#endif
|
||||
|
||||
if (!g_doubleBuffer)
|
||||
@@ -130,7 +126,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
|
||||
wxLogWarning("Disabling double buffering");
|
||||
|
||||
#ifdef __WXGTK__
|
||||
gl_attrib[9] = None;
|
||||
gl_attrib[9] = 0;
|
||||
#endif
|
||||
g_doubleBuffer = GL_FALSE;
|
||||
}
|
||||
|
@@ -50,7 +50,7 @@ parent_set_hook(GSignalInvocationHint*, guint, const GValue* param_values, void*
|
||||
wxGLCanvas* win = (wxGLCanvas*)data;
|
||||
if (g_value_peek_pointer(¶m_values[0]) == win->m_wxwindow)
|
||||
{
|
||||
const XVisualInfo* xvi = win->GetXVisualInfo();
|
||||
const XVisualInfo* xvi = static_cast<XVisualInfo*>(win->GetXVisualInfo());
|
||||
GdkVisual* visual = gtk_widget_get_visual(win->m_wxwindow);
|
||||
if (GDK_VISUAL_XVISUAL(visual)->visualid != xvi->visualid)
|
||||
{
|
||||
@@ -239,7 +239,7 @@ bool wxGLCanvas::SetBackgroundStyle(wxBackgroundStyle /* style */)
|
||||
return false;
|
||||
}
|
||||
|
||||
Window wxGLCanvas::GetXWindow() const
|
||||
unsigned long wxGLCanvas::GetXWindow() const
|
||||
{
|
||||
GdkWindow* window = GTKGetDrawingWindow();
|
||||
return window ? GDK_WINDOW_XID(window) : 0;
|
||||
|
@@ -246,7 +246,7 @@ bool wxGLCanvas::Create(wxWindow *parent,
|
||||
if ( !InitVisual(dispAttrs) )
|
||||
return false;
|
||||
|
||||
GdkVisual *visual = gdkx_visual_get( GetXVisualInfo()->visualid );
|
||||
GdkVisual *visual = gdkx_visual_get(static_cast<XVisualInfo*>(GetXVisualInfo())->visualid);
|
||||
GdkColormap *colormap = gdk_colormap_new( visual, TRUE );
|
||||
|
||||
gtk_widget_push_colormap( colormap );
|
||||
@@ -292,7 +292,7 @@ bool wxGLCanvas::Create(wxWindow *parent,
|
||||
return true;
|
||||
}
|
||||
|
||||
Window wxGLCanvas::GetXWindow() const
|
||||
unsigned long wxGLCanvas::GetXWindow() const
|
||||
{
|
||||
GdkWindow *window = GTK_PIZZA(m_wxwindow)->bin_window;
|
||||
return window ? GDK_WINDOW_XWINDOW(window) : 0;
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#endif //WX_PRECOMP
|
||||
|
||||
#include "wx/glcanvas.h"
|
||||
#include <GL/glx.h>
|
||||
|
||||
// IRIX headers call this differently
|
||||
#ifdef __SGI__
|
||||
@@ -446,6 +447,8 @@ void wxGLAttributes::AddDefaultsForWXBefore31()
|
||||
// wxGLContext implementation
|
||||
// ============================================================================
|
||||
|
||||
static bool MakeCurrent(GLXDrawable drawable, GLXContext context);
|
||||
|
||||
// Need this X error handler for the case context creation fails
|
||||
static bool g_ctxErrorOccurred = false;
|
||||
static int CTXErrorHandler( Display* WXUNUSED(dpy), XErrorEvent* WXUNUSED(ev) )
|
||||
@@ -486,7 +489,7 @@ wxGLContext::wxGLContext(wxGLCanvas *win,
|
||||
m_isOk = false;
|
||||
|
||||
Display* dpy = wxGetX11Display();
|
||||
XVisualInfo *vi = win->GetXVisualInfo();
|
||||
XVisualInfo* vi = static_cast<XVisualInfo*>(win->GetXVisualInfo());
|
||||
wxCHECK_RET( vi, "invalid visual for OpenGL" );
|
||||
|
||||
// We need to create a temporary context to get the
|
||||
@@ -585,8 +588,7 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
|
||||
|
||||
// wrapper around glXMakeContextCurrent/glXMakeCurrent depending on GLX
|
||||
// version
|
||||
/* static */
|
||||
bool wxGLContext::MakeCurrent(GLXDrawable drawable, GLXContext context)
|
||||
static bool MakeCurrent(GLXDrawable drawable, GLXContext context)
|
||||
{
|
||||
if (wxGLCanvas::GetGLXVersion() >= 13)
|
||||
return glXMakeContextCurrent( wxGetX11Display(), drawable, drawable, context);
|
||||
@@ -598,6 +600,12 @@ bool wxGLContext::MakeCurrent(GLXDrawable drawable, GLXContext context)
|
||||
// wxGLCanvasX11 implementation
|
||||
// ============================================================================
|
||||
|
||||
static GLXFBConfig* gs_glFBCInfo;
|
||||
static XVisualInfo* gs_glVisualInfo;
|
||||
|
||||
static bool InitXVisualInfo(
|
||||
const wxGLAttributes& dispAttrs, GLXFBConfig** pFBC, XVisualInfo** pXVisual);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// initialization methods and dtor
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -610,7 +618,9 @@ wxGLCanvasX11::wxGLCanvasX11()
|
||||
|
||||
bool wxGLCanvasX11::InitVisual(const wxGLAttributes& dispAttrs)
|
||||
{
|
||||
bool ret = InitXVisualInfo(dispAttrs, &m_fbc, &m_vi);
|
||||
XVisualInfo* vi = NULL;
|
||||
bool ret = InitXVisualInfo(dispAttrs, &m_fbc, &vi);
|
||||
m_vi = vi;
|
||||
if ( !ret )
|
||||
{
|
||||
wxFAIL_MSG("Failed to get a XVisualInfo for the requested attributes.");
|
||||
@@ -620,10 +630,10 @@ bool wxGLCanvasX11::InitVisual(const wxGLAttributes& dispAttrs)
|
||||
|
||||
wxGLCanvasX11::~wxGLCanvasX11()
|
||||
{
|
||||
if ( m_fbc && m_fbc != ms_glFBCInfo )
|
||||
if (m_fbc && m_fbc != gs_glFBCInfo)
|
||||
XFree(m_fbc);
|
||||
|
||||
if ( m_vi && m_vi != ms_glVisualInfo )
|
||||
if (m_vi && m_vi != gs_glVisualInfo)
|
||||
XFree(m_vi);
|
||||
}
|
||||
|
||||
@@ -651,9 +661,7 @@ bool wxGLCanvasX11::IsGLXMultiSampleAvailable()
|
||||
return s_isMultiSampleAvailable != 0;
|
||||
}
|
||||
|
||||
|
||||
/* static */
|
||||
bool wxGLCanvasX11::InitXVisualInfo(const wxGLAttributes& dispAttrs,
|
||||
static bool InitXVisualInfo(const wxGLAttributes& dispAttrs,
|
||||
GLXFBConfig** pFBC,
|
||||
XVisualInfo** pXVisual)
|
||||
{
|
||||
@@ -667,7 +675,7 @@ bool wxGLCanvasX11::InitXVisualInfo(const wxGLAttributes& dispAttrs,
|
||||
|
||||
Display* dpy = wxGetX11Display();
|
||||
|
||||
if ( GetGLXVersion() >= 13 )
|
||||
if (wxGLCanvasX11::GetGLXVersion() >= 13)
|
||||
{
|
||||
int returned;
|
||||
*pFBC = glXChooseFBConfig(dpy, DefaultScreen(dpy), attrsListGLX, &returned);
|
||||
@@ -699,7 +707,7 @@ bool wxGLCanvasBase::IsDisplaySupported(const wxGLAttributes& dispAttrs)
|
||||
GLXFBConfig *fbc = NULL;
|
||||
XVisualInfo *vi = NULL;
|
||||
|
||||
bool isSupported = wxGLCanvasX11::InitXVisualInfo(dispAttrs, &fbc, &vi);
|
||||
bool isSupported = InitXVisualInfo(dispAttrs, &fbc, &vi);
|
||||
|
||||
if ( fbc )
|
||||
XFree(fbc);
|
||||
@@ -722,8 +730,19 @@ bool wxGLCanvasBase::IsDisplaySupported(const int *attribList)
|
||||
// default visual management
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
XVisualInfo *wxGLCanvasX11::ms_glVisualInfo = NULL;
|
||||
GLXFBConfig *wxGLCanvasX11::ms_glFBCInfo = NULL;
|
||||
static void FreeDefaultVisualInfo()
|
||||
{
|
||||
if (gs_glFBCInfo)
|
||||
{
|
||||
XFree(gs_glFBCInfo);
|
||||
gs_glFBCInfo = NULL;
|
||||
}
|
||||
if (gs_glVisualInfo)
|
||||
{
|
||||
XFree(gs_glVisualInfo);
|
||||
gs_glVisualInfo = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool wxGLCanvasX11::InitDefaultVisualInfo(const int *attribList)
|
||||
@@ -732,23 +751,7 @@ bool wxGLCanvasX11::InitDefaultVisualInfo(const int *attribList)
|
||||
wxGLAttributes dispAttrs;
|
||||
ParseAttribList(attribList, dispAttrs);
|
||||
|
||||
return InitXVisualInfo(dispAttrs, &ms_glFBCInfo, &ms_glVisualInfo);
|
||||
}
|
||||
|
||||
/* static */
|
||||
void wxGLCanvasX11::FreeDefaultVisualInfo()
|
||||
{
|
||||
if ( ms_glFBCInfo )
|
||||
{
|
||||
XFree(ms_glFBCInfo);
|
||||
ms_glFBCInfo = NULL;
|
||||
}
|
||||
|
||||
if ( ms_glVisualInfo )
|
||||
{
|
||||
XFree(ms_glVisualInfo);
|
||||
ms_glVisualInfo = NULL;
|
||||
}
|
||||
return InitXVisualInfo(dispAttrs, &gs_glFBCInfo, &gs_glVisualInfo);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -788,5 +791,25 @@ bool wxGLCanvasX11::IsShownOnScreen() const
|
||||
return GetXWindow() && wxGLCanvasBase::IsShownOnScreen();
|
||||
}
|
||||
|
||||
#endif // wxUSE_GLCANVAS
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxGLApp
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxGLApp::InitGLVisual(const int* attribList)
|
||||
{
|
||||
return wxGLCanvasX11::InitDefaultVisualInfo(attribList);
|
||||
}
|
||||
|
||||
void* wxGLApp::GetXVisualInfo()
|
||||
{
|
||||
return gs_glVisualInfo;
|
||||
}
|
||||
|
||||
int wxGLApp::OnExit()
|
||||
{
|
||||
FreeDefaultVisualInfo();
|
||||
|
||||
return wxGLAppBase::OnExit();
|
||||
}
|
||||
|
||||
#endif // wxUSE_GLCANVAS
|
||||
|
@@ -101,9 +101,9 @@ bool wxGLCanvas::Create(wxWindow *parent,
|
||||
return true;
|
||||
}
|
||||
|
||||
Window wxGLCanvas::GetXWindow() const
|
||||
unsigned long wxGLCanvas::GetXWindow() const
|
||||
{
|
||||
return (Window)
|
||||
return (unsigned long)
|
||||
#ifdef __WXMOTIF__
|
||||
GetClientXWindow();
|
||||
#else
|
||||
|
Reference in New Issue
Block a user