X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a15107c002d8dee9e64692ecb307e41c5f90d70d..952f8d3c7a729127bf73ba4f819cbadc51753e79:/src/unix/glx11.cpp diff --git a/src/unix/glx11.cpp b/src/unix/glx11.cpp index ffa31f4eb4..84fd0d441e 100644 --- a/src/unix/glx11.cpp +++ b/src/unix/glx11.cpp @@ -68,26 +68,26 @@ wxGLContext::~wxGLContext() glXDestroyContext( wxGetX11Display(), m_glContext ); } -void wxGLContext::SetCurrent(const wxGLCanvas& win) const +bool wxGLContext::SetCurrent(const wxGLCanvas& win) const { if ( !m_glContext ) - return; + return false; const Window xid = win.GetXWindow(); - wxCHECK_RET( xid, _T("window must be shown") ); + wxCHECK2_MSG( xid, return false, _T("window must be shown") ); - MakeCurrent(xid, m_glContext); + return MakeCurrent(xid, m_glContext); } // wrapper around glXMakeContextCurrent/glXMakeCurrent depending on GLX // version /* static */ -void wxGLContext::MakeCurrent(GLXDrawable drawable, GLXContext context) +bool wxGLContext::MakeCurrent(GLXDrawable drawable, GLXContext context) { if (wxGLCanvas::GetGLXVersion() >= 13) - glXMakeContextCurrent( wxGetX11Display(), drawable, drawable, context); + return glXMakeContextCurrent( wxGetX11Display(), drawable, drawable, context); else // GLX <= 1.2 doesn't have glXMakeContextCurrent() - glXMakeCurrent( wxGetX11Display(), drawable, context); + return glXMakeCurrent( wxGetX11Display(), drawable, context); } // ============================================================================ @@ -129,26 +129,26 @@ wxGLCanvasX11::ConvertWXAttrsToGL(const int *wxattrs, int *glattrs, size_t n) if ( !wxattrs ) { - if ( GetGLXVersion() >= 13 ) - { - // leave GLX >= 1.3 choose the default attributes - glattrs[0] = None; - } - else // GLX < 1.3 + size_t i = 0; + + // use double-buffered true colour by default + glattrs[i++] = GLX_RGBA; glattrs[i++] = True; + glattrs[i++] = GLX_DOUBLEBUFFER; glattrs[i++] = True; + + if ( GetGLXVersion() < 13 ) { // default settings if attriblist = 0 - size_t i = 0; - glattrs[i++] = GLX_RGBA; - glattrs[i++] = GLX_DOUBLEBUFFER; glattrs[i++] = GLX_DEPTH_SIZE; glattrs[i++] = 1; glattrs[i++] = GLX_RED_SIZE; glattrs[i++] = 1; glattrs[i++] = GLX_GREEN_SIZE; glattrs[i++] = 1; glattrs[i++] = GLX_BLUE_SIZE; glattrs[i++] = 1; glattrs[i++] = GLX_ALPHA_SIZE; glattrs[i++] = 0; - glattrs[i++] = None; - - wxASSERT_MSG( i < n, _T("GL attributes buffer too small") ); } + //else: recent GLX can choose the defaults on its own just fine + + glattrs[i] = None; + + wxASSERT_MSG( i < n, _T("GL attributes buffer too small") ); } else // have non-default attributes { @@ -158,25 +158,11 @@ wxGLCanvasX11::ConvertWXAttrsToGL(const int *wxattrs, int *glattrs, size_t n) // check if we have any space left, knowing that we may insert 2 // more elements during this loop iteration and we always need to // terminate the list with None (hence -3) - if ( p >= n - 2 ) + if ( p > n - 3 ) return false; switch ( wxattrs[arg++] ) { - case WX_GL_RGBA: - // for GLX >= 1.3, GLX_RGBA is useless and apparently - // harmful for some implementations - // - // FIXME: is this true? - if ( GetGLXVersion() <= 12 ) - { - glattrs[p++] = GLX_RGBA; - } - - // use "continue" to skip the assignment of the attribute - // value at the end of the loop - continue; - case WX_GL_BUFFER_SIZE: glattrs[p++] = GLX_BUFFER_SIZE; break; @@ -185,17 +171,26 @@ wxGLCanvasX11::ConvertWXAttrsToGL(const int *wxattrs, int *glattrs, size_t n) glattrs[p++] = GLX_LEVEL; break; + // the following boolean attributes don't have values in wx + // API (they're turned on if specified) but do have them in + // OpenGL, so do put them into glattrs and also skip the + // copy of wx value after switch by using "continue" + // instead of "break" + case WX_GL_RGBA: + glattrs[p++] = GLX_RGBA; + glattrs[p++] = True; + continue; + case WX_GL_DOUBLEBUFFER: glattrs[p++] = GLX_DOUBLEBUFFER; glattrs[p++] = True; - - // again, we don't have value for this one in wx list (even - // though OpenGL does use it) continue; case WX_GL_STEREO: glattrs[p++] = GLX_STEREO; - break; + glattrs[p++] = True; + continue; + case WX_GL_AUX_BUFFERS: glattrs[p++] = GLX_AUX_BUFFERS; @@ -293,6 +288,24 @@ wxGLCanvasX11::InitXVisualInfo(const int *attribList, return *pXVisual != NULL; } +/* static */ +bool +wxGLCanvasBase::IsDisplaySupported(const int *attribList) +{ + GLXFBConfig *fbc = NULL; + XVisualInfo *vi = NULL; + + const bool + isSupported = wxGLCanvasX11::InitXVisualInfo(attribList, &fbc, &vi); + + if ( fbc ) + XFree(fbc); + if ( vi ) + XFree(vi); + + return isSupported; +} + // ---------------------------------------------------------------------------- // default visual management // ---------------------------------------------------------------------------- @@ -347,12 +360,13 @@ int wxGLCanvasX11::GetGLXVersion() return s_glxVersion; } -void wxGLCanvasX11::SwapBuffers() +bool wxGLCanvasX11::SwapBuffers() { const Window xid = GetXWindow(); - wxCHECK_RET( xid, _T("window must be shown") ); + wxCHECK2_MSG( xid, return false, _T("window must be shown") ); glXSwapBuffers(wxGetX11Display(), xid); + return true; } bool wxGLCanvasX11::IsShownOnScreen() const