From 5ec69e9666e300c9ba210812a11ca5dc9111b5f9 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Sat, 22 Dec 2007 15:48:03 +0000
Subject: [PATCH] made SetCurrent() and SwapBuffers() return boolean status
 indicator instead of void (slightly modified patch 1844090)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50900 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/glcanvas.tex |  8 ++++++--
 include/wx/glcanvas.h      |  6 +++---
 include/wx/msw/glcanvas.h  |  4 ++--
 include/wx/unix/glx11.h    |  6 +++---
 src/common/glcmn.cpp       |  4 ++--
 src/msw/glcanvas.cpp       | 10 ++++++++--
 src/unix/glx11.cpp         | 19 ++++++++++---------
 7 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/docs/latex/wx/glcanvas.tex b/docs/latex/wx/glcanvas.tex
index c6e293d7de..771e056542 100644
--- a/docs/latex/wx/glcanvas.tex
+++ b/docs/latex/wx/glcanvas.tex
@@ -127,7 +127,7 @@ Ignored under most platforms.}
 
 \membersection{wxGLCanvas::SetCurrent}\label{wxglcanvassetcurrent}
 
-\func{void}{SetCurrent}{ \param{const wxGLContext&}{ context} }
+\func{bool}{SetCurrent}{ \param{const wxGLContext&}{ context} }
 
 Makes the OpenGL state that is represented by the OpenGL rendering context
 \arg{context} current, i.e. it will be used by all subsequent OpenGL calls.
@@ -139,6 +139,8 @@ Note that this function may only be called when the window is shown on screen,
 in particular it can't usually be called from the constructor as the window
 isn't yet shown at this moment.
 
+Returns \false if an error occurred.
+
 
 \membersection{wxGLCanvas::SetColour}\label{wxglcanvassetcolour}
 
@@ -150,8 +152,10 @@ wxWidgets colour database to find a named colour.
 
 \membersection{wxGLCanvas::SwapBuffers}\label{wxglcanvasswapbuffers}
 
-\func{void}{SwapBuffers}{\void}
+\func{bool}{SwapBuffers}{\void}
 
 Swaps the double-buffer of this window, making the back-buffer the front-buffer and vice versa,
 so that the output of the previous OpenGL commands is displayed on the window.
 
+Returns \false if an error occurred.
+
diff --git a/include/wx/glcanvas.h b/include/wx/glcanvas.h
index bb4ffa498a..3ac73811c3 100644
--- a/include/wx/glcanvas.h
+++ b/include/wx/glcanvas.h
@@ -66,7 +66,7 @@ public:
      */
 
     // set this context as the current one
-    virtual void SetCurrent(const wxGLCanvas& win) const = 0;
+    virtual bool SetCurrent(const wxGLCanvas& win) const = 0;
 };
 
 // ----------------------------------------------------------------------------
@@ -99,10 +99,10 @@ public:
     // ----------
 
     // set the given context associated with this window as the current one
-    void SetCurrent(const wxGLContext& context) const;
+    bool SetCurrent(const wxGLContext& context) const;
 
     // flush the back buffer (if we have it)
-    virtual void SwapBuffers() = 0;
+    virtual bool SwapBuffers() = 0;
 
 
     // accessors
diff --git a/include/wx/msw/glcanvas.h b/include/wx/msw/glcanvas.h
index 83362b0167..203816b4ea 100644
--- a/include/wx/msw/glcanvas.h
+++ b/include/wx/msw/glcanvas.h
@@ -28,7 +28,7 @@ public:
     wxGLContext(wxGLCanvas *win, const wxGLContext* other = NULL);
     virtual ~wxGLContext();
 
-    virtual void SetCurrent(const wxGLCanvas& win) const;
+    virtual bool SetCurrent(const wxGLCanvas& win) const;
 
     HGLRC GetGLRC() const { return m_glContext; }
 
@@ -67,7 +67,7 @@ public:
     virtual ~wxGLCanvas();
 
     // implement wxGLCanvasBase methods
-    virtual void SwapBuffers();
+    virtual bool SwapBuffers();
 
 
     // MSW-specific helpers
diff --git a/include/wx/unix/glx11.h b/include/wx/unix/glx11.h
index b29462b7c6..7f48e91891 100644
--- a/include/wx/unix/glx11.h
+++ b/include/wx/unix/glx11.h
@@ -23,11 +23,11 @@ public:
     wxGLContext(wxGLCanvas *win, const wxGLContext *other = NULL);
     virtual ~wxGLContext();
 
-    virtual void SetCurrent(const wxGLCanvas& win) const;
+    virtual bool SetCurrent(const wxGLCanvas& win) const;
 
 private:
     // attach context to the drawable or unset it (if NULL)
-    static void MakeCurrent(GLXDrawable drawable, GLXContext context);
+    static bool MakeCurrent(GLXDrawable drawable, GLXContext context);
 
     GLXContext m_glContext;
 
@@ -57,7 +57,7 @@ public:
     // implement wxGLCanvasBase methods
     // --------------------------------
 
-    virtual void SwapBuffers();
+    virtual bool SwapBuffers();
 
 
     // X11-specific methods
diff --git a/src/common/glcmn.cpp b/src/common/glcmn.cpp
index 0d85eab14c..07db44d4c8 100644
--- a/src/common/glcmn.cpp
+++ b/src/common/glcmn.cpp
@@ -52,14 +52,14 @@ wxGLCanvasBase::wxGLCanvasBase()
     SetBackgroundStyle(wxBG_STYLE_CUSTOM);
 }
 
-void wxGLCanvasBase::SetCurrent(const wxGLContext& context) const
+bool wxGLCanvasBase::SetCurrent(const wxGLContext& context) const
 {
     // although on MSW it works even if the window is still hidden, it doesn't
     // work in other ports (notably X11-based ones) and documentation mentions
     // that SetCurrent() can only be called for a shown window, so check for it
     wxASSERT_MSG( IsShownOnScreen(), _T("can't make hidden GL canvas current") );
 
-    context.SetCurrent(*wx_static_cast(const wxGLCanvas *, this));
+    return context.SetCurrent(*wx_static_cast(const wxGLCanvas *, this));
 }
 
 bool wxGLCanvasBase::SetColour(const wxString& colour)
diff --git a/src/msw/glcanvas.cpp b/src/msw/glcanvas.cpp
index a95e48a54b..2c5406e2fd 100644
--- a/src/msw/glcanvas.cpp
+++ b/src/msw/glcanvas.cpp
@@ -200,12 +200,14 @@ wxGLContext::~wxGLContext()
     wglDeleteContext(m_glContext);
 }
 
-void wxGLContext::SetCurrent(const wxGLCanvas& win) const
+bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
 {
     if ( !wglMakeCurrent(win.GetHDC(), m_glContext) )
     {
         wxLogLastError(_T("wglMakeCurrent"));
+        return false;
     }
+    return true;
 }
 
 // ============================================================================
@@ -313,10 +315,14 @@ bool wxGLCanvas::Create(wxWindow *parent,
 // operations
 // ----------------------------------------------------------------------------
 
-void wxGLCanvas::SwapBuffers()
+bool wxGLCanvas::SwapBuffers()
 {
     if ( !::SwapBuffers(m_hDC) )
+    {
+        return false;
         wxLogLastError(_T("SwapBuffers"));
+    }
+    return true;
 }
 
 // ----------------------------------------------------------------------------
diff --git a/src/unix/glx11.cpp b/src/unix/glx11.cpp
index b4a8b2d147..b0da747670 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);
 }
 
 // ============================================================================
@@ -351,12 +351,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
-- 
2.50.0

