From 3f20f7d8a388424e6f519a18019e070725d18503 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 3 Feb 2008 14:55:05 +0000 Subject: [PATCH] added wxGLCanvas::IsDisplaySupported() (patch 1879906) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51526 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + docs/latex/wx/glcanvas.tex | 11 +++++++++++ include/wx/glcanvas.h | 3 +++ include/wx/unix/glx11.h | 14 +++++++------- samples/opengl/cube/cube.cpp | 5 +++++ src/mac/carbon/glcanvas.cpp | 13 +++++++++++++ src/msw/glcanvas.cpp | 8 ++++++++ src/unix/glx11.cpp | 18 ++++++++++++++++++ 8 files changed, 66 insertions(+), 7 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 79bca35924..5bb84cb14b 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -278,6 +278,7 @@ All (GUI): - Made wxSizer::Fit() set the client size of the target window - Add support for wxDatePickerCtrl in wxGenericValidator (Herry Ayen Yang) - Added wxWindow::HasFocus(). +- Added wxGLCanvas::IsDisplaySupported() wxGTK: diff --git a/docs/latex/wx/glcanvas.tex b/docs/latex/wx/glcanvas.tex index 771e056542..b21d6d5702 100644 --- a/docs/latex/wx/glcanvas.tex +++ b/docs/latex/wx/glcanvas.tex @@ -125,6 +125,17 @@ and so on. Ignored under most platforms.} +\membersection{wxGLCanvas::IsDisplaySupported}\label{wxglcanvasisdisplaysupported} + +\func{static bool}{IsDisplaySupported}{ \param{const int *}{ attribList = \NULL} } + +Determines if a canvas having the specified attributes is available. + +\docparam{attribList}{See \arg{attribList} for \helpref{wxGLCanvas::wxGLCanvas}{wxglcanvasconstr}.} + +Returns \true if attributes are supported. + + \membersection{wxGLCanvas::SetCurrent}\label{wxglcanvassetcurrent} \func{bool}{SetCurrent}{ \param{const wxGLContext&}{ context} } diff --git a/include/wx/glcanvas.h b/include/wx/glcanvas.h index 3ac73811c3..e02657cc96 100644 --- a/include/wx/glcanvas.h +++ b/include/wx/glcanvas.h @@ -108,6 +108,9 @@ public: // accessors // --------- + // check if the given attributes are supported without creating a canvas + static bool IsDisplaySupported(const int *attribList); + const wxPalette *GetPalette() const { return &m_palette; } // miscellaneous helper functions diff --git a/include/wx/unix/glx11.h b/include/wx/unix/glx11.h index 7f48e91891..687982e068 100644 --- a/include/wx/unix/glx11.h +++ b/include/wx/unix/glx11.h @@ -95,6 +95,13 @@ public: // 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 int *attribList, + GLXFBConfig **pFBC, XVisualInfo **pXVisual); + private: // fills in glattrs with attributes defined by wxattrs which must be // 0-terminated if it is non-NULL @@ -103,13 +110,6 @@ private: // should be at least 16 to accommodate the default attributes static bool ConvertWXAttrsToGL(const int *wxattrs, int *glattrs, size_t n); - // 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 int *attribList, - GLXFBConfig **pFBC, XVisualInfo **pXVisual); - // this is only used if it's supported i.e. if GL >= 1.3 GLXFBConfig *m_fbc; diff --git a/samples/opengl/cube/cube.cpp b/samples/opengl/cube/cube.cpp index 411979b571..3255201819 100644 --- a/samples/opengl/cube/cube.cpp +++ b/samples/opengl/cube/cube.cpp @@ -385,6 +385,11 @@ MyFrame::MyFrame() SetClientSize(400, 400); Show(); + + // test IsDisplaySupported() function: + static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 }; + wxLogStatus("Double-buffered display %s supported", + wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not"); } void MyFrame::OnClose(wxCommandEvent& WXUNUSED(event)) diff --git a/src/mac/carbon/glcanvas.cpp b/src/mac/carbon/glcanvas.cpp index b3a2a81245..07fda36591 100644 --- a/src/mac/carbon/glcanvas.cpp +++ b/src/mac/carbon/glcanvas.cpp @@ -312,6 +312,19 @@ wxGLCanvas::~wxGLCanvas() aglDestroyPixelFormat(m_aglFormat); } +/* static */ +bool wxGLCanvasBase::IsDisplaySupported(const int *attribList) +{ + AGLPixelFormat aglFormat = ChoosePixelFormat(attribList); + + if ( !aglFormat ) + return false; + + aglDestroyPixelFormat(aglFormat); + + return true; +} + bool wxGLCanvas::SwapBuffers() { AGLContext context = aglGetCurrentContext(); diff --git a/src/msw/glcanvas.cpp b/src/msw/glcanvas.cpp index 2c5406e2fd..edf2264d60 100644 --- a/src/msw/glcanvas.cpp +++ b/src/msw/glcanvas.cpp @@ -450,6 +450,14 @@ wxGLCanvas::ChooseMatchingPixelFormat(HDC hdc, return ::ChoosePixelFormat(hdc, ppfd); } +/* static */ +bool wxGLCanvasBase::IsDisplaySupported(const int *attribList) +{ + // We need a device context to test the pixel format, so get one + // for the root window. + return wxGLCanvas::ChooseMatchingPixelFormat(ScreenHDC(), attribList) > 0; +} + bool wxGLCanvas::DoSetup(const int *attribList) { PIXELFORMATDESCRIPTOR pfd; diff --git a/src/unix/glx11.cpp b/src/unix/glx11.cpp index b0da747670..780029891d 100644 --- a/src/unix/glx11.cpp +++ b/src/unix/glx11.cpp @@ -297,6 +297,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 // ---------------------------------------------------------------------------- -- 2.47.2