]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/glx11.cpp
Fix typo in last commit
[wxWidgets.git] / src / unix / glx11.cpp
index ed777163d9cb01b8af42546f1670fec6bef8d890..05f9625a8c360bb928322df20bfad2259738ada0 100644 (file)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// Name:        src/univ/glx11.cpp
+// Name:        src/unix/glx11.cpp
 // Purpose:     code common to all X11-based wxGLCanvas implementations
 // Author:      Vadim Zeitlin
 // Created:     2007-04-15
 
 #include "wx/glcanvas.h"
 
+// IRIX headers call this differently
+#ifdef __SGI__
+    #ifndef GLX_SAMPLE_BUFFERS_ARB
+        #define GLX_SAMPLE_BUFFERS_ARB GLX_SAMPLE_BUFFERS_SGIS
+    #endif
+    #ifndef GLX_SAMPLES_ARB
+        #define GLX_SAMPLES_ARB GLX_SAMPLES_SGIS
+    #endif
+#endif // __SGI__
+
 // ============================================================================
 // wxGLContext implementation
 // ============================================================================
@@ -38,7 +48,7 @@ wxGLContext::wxGLContext(wxGLCanvas *gc, const wxGLContext *other)
     if ( wxGLCanvas::GetGLXVersion() >= 13 )
     {
         GLXFBConfig *fbc = gc->GetGLXFBConfig();
-        wxCHECK_RET( fbc, _T("invalid GLXFBConfig for OpenGL") );
+        wxCHECK_RET( fbc, wxT("invalid GLXFBConfig for OpenGL") );
 
         m_glContext = glXCreateNewContext( wxGetX11Display(), fbc[0], GLX_RGBA_TYPE,
                                            other ? other->m_glContext : None,
@@ -47,14 +57,14 @@ wxGLContext::wxGLContext(wxGLCanvas *gc, const wxGLContext *other)
     else // GLX <= 1.2
     {
         XVisualInfo *vi = gc->GetXVisualInfo();
-        wxCHECK_RET( vi, _T("invalid visual for OpenGL") );
+        wxCHECK_RET( vi, wxT("invalid visual for OpenGL") );
 
         m_glContext = glXCreateContext( wxGetX11Display(), vi,
                                         other ? other->m_glContext : None,
                                         GL_TRUE );
     }
 
-    wxASSERT_MSG( m_glContext, _T("Couldn't create OpenGL context") );
+    wxASSERT_MSG( m_glContext, wxT("Couldn't create OpenGL context") );
 }
 
 wxGLContext::~wxGLContext()
@@ -74,7 +84,7 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
         return false;
 
     const Window xid = win.GetXWindow();
-    wxCHECK2_MSG( xid, return false, _T("window must be shown") );
+    wxCHECK2_MSG( xid, return false, wxT("window must be shown") );
 
     return MakeCurrent(xid, m_glContext);
 }
@@ -122,10 +132,30 @@ wxGLCanvasX11::~wxGLCanvasX11()
 // working with GL attributes
 // ----------------------------------------------------------------------------
 
+/* static */
+bool wxGLCanvasBase::IsExtensionSupported(const char *extension)
+{
+    Display * const dpy = wxGetX11Display();
+
+    return IsExtensionInList(glXQueryExtensionsString(dpy, DefaultScreen(dpy)),
+                             extension);
+}
+
+
+/* static */
+bool wxGLCanvasX11::IsGLXMultiSampleAvailable()
+{
+    static int s_isMultiSampleAvailable = -1;
+    if ( s_isMultiSampleAvailable == -1 )
+        s_isMultiSampleAvailable = IsExtensionSupported("GLX_ARB_multisample");
+
+    return s_isMultiSampleAvailable != 0;
+}
+
 bool
 wxGLCanvasX11::ConvertWXAttrsToGL(const int *wxattrs, int *glattrs, size_t n)
 {
-    wxCHECK_MSG( n >= 16, false, _T("GL attributes buffer too small") );
+    wxCHECK_MSG( n >= 16, false, wxT("GL attributes buffer too small") );
 
     /*
        Different versions of GLX API use rather different attributes lists, see
@@ -166,7 +196,7 @@ wxGLCanvasX11::ConvertWXAttrsToGL(const int *wxattrs, int *glattrs, size_t n)
 
         glattrs[i] = None;
 
-        wxASSERT_MSG( i < n, _T("GL attributes buffer too small") );
+        wxASSERT_MSG( i < n, wxT("GL attributes buffer too small") );
     }
     else // have non-default attributes
     {
@@ -257,8 +287,37 @@ wxGLCanvasX11::ConvertWXAttrsToGL(const int *wxattrs, int *glattrs, size_t n)
                     glattrs[p++] = GLX_ACCUM_ALPHA_SIZE;
                     break;
 
+                case WX_GL_SAMPLE_BUFFERS:
+#ifdef GLX_SAMPLE_BUFFERS_ARB
+                    if ( IsGLXMultiSampleAvailable() )
+                    {
+                        glattrs[p++] = GLX_SAMPLE_BUFFERS_ARB;
+                        break;
+                    }
+#endif // GLX_SAMPLE_BUFFERS_ARB
+                    // if it was specified just to disable it, no problem
+                    if ( !wxattrs[arg++] )
+                        continue;
+
+                    // otherwise indicate that it's not supported
+                    return false;
+
+                case WX_GL_SAMPLES:
+#ifdef GLX_SAMPLES_ARB
+                    if ( IsGLXMultiSampleAvailable() )
+                    {
+                        glattrs[p++] = GLX_SAMPLES_ARB;
+                        break;
+                    }
+#endif // GLX_SAMPLES_ARB
+
+                    if ( !wxattrs[arg++] )
+                        continue;
+
+                    return false;
+
                 default:
-                    wxLogDebug(_T("Unsupported OpenGL attribute %d"),
+                    wxLogDebug(wxT("Unsupported OpenGL attribute %d"),
                                wxattrs[arg - 1]);
                     continue;
             }
@@ -381,7 +440,7 @@ int wxGLCanvasX11::GetGLXVersion()
         // check the GLX version
         int glxMajorVer, glxMinorVer;
         bool ok = glXQueryVersion(wxGetX11Display(), &glxMajorVer, &glxMinorVer);
-        wxASSERT_MSG( ok, _T("GLX version not found") );
+        wxASSERT_MSG( ok, wxT("GLX version not found") );
         if (!ok)
             s_glxVersion = 10; // 1.0 by default
         else
@@ -394,7 +453,7 @@ int wxGLCanvasX11::GetGLXVersion()
 bool wxGLCanvasX11::SwapBuffers()
 {
     const Window xid = GetXWindow();
-    wxCHECK2_MSG( xid, return false, _T("window must be shown") );
+    wxCHECK2_MSG( xid, return false, wxT("window must be shown") );
 
     glXSwapBuffers(wxGetX11Display(), xid);
     return true;