]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxGLCanvas::IsDisplaySupported() (patch 1879906)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 3 Feb 2008 14:55:05 +0000 (14:55 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 3 Feb 2008 14:55:05 +0000 (14:55 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51526 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/latex/wx/glcanvas.tex
include/wx/glcanvas.h
include/wx/unix/glx11.h
samples/opengl/cube/cube.cpp
src/mac/carbon/glcanvas.cpp
src/msw/glcanvas.cpp
src/unix/glx11.cpp

index 79bca359247c02f5a47da4db834875f24542bddf..5bb84cb14bc98b55420b36fc460431d1032f703b 100644 (file)
@@ -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:
 
index 771e056542ee98ebf9dbb69de2702366cbff574d..b21d6d570291183f2682d5551a19b558b5f1be09 100644 (file)
@@ -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} }
index 3ac73811c30d48180abc0caafae3a18349ad6dcd..e02657cc96032ef5d24c215b9e3863919395b6ca 100644 (file)
@@ -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
index 7f48e9189147713c464c3ff3c3b6818c31a7f6fb..687982e068d8b10cba6cc788fe462b10d8a52221 100644 (file)
@@ -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;
index 411979b571040299f32c67cbb9e7c7ea29ebe31c..325520181936b914d407cced5306da5ef47bf206 100644 (file)
@@ -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))
index b3a2a81245e557c7ebc9dac55e05e17db71ae795..07fda365914260675abe4d64e21c3b396823c684 100644 (file)
@@ -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();
index 2c5406e2fda528c42daf3e15da63f49626543884..edf2264d60c2707d2ba10daf46a2104de82eeee4 100644 (file)
@@ -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;
index b0da747670380a5b69fe5da1225f9499c1792926..780029891d0de5e04b1e04e4a23a202935b105a4 100644 (file)
@@ -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
 // ----------------------------------------------------------------------------