\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.
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}
\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.
+
*/
// set this context as the current one
- virtual void SetCurrent(const wxGLCanvas& win) const = 0;
+ virtual bool SetCurrent(const wxGLCanvas& win) const = 0;
};
// ----------------------------------------------------------------------------
// ----------
// 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
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; }
virtual ~wxGLCanvas();
// implement wxGLCanvasBase methods
- virtual void SwapBuffers();
+ virtual bool SwapBuffers();
// MSW-specific helpers
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;
// implement wxGLCanvasBase methods
// --------------------------------
- virtual void SwapBuffers();
+ virtual bool SwapBuffers();
// X11-specific methods
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)
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;
}
// ============================================================================
// operations
// ----------------------------------------------------------------------------
-void wxGLCanvas::SwapBuffers()
+bool wxGLCanvas::SwapBuffers()
{
if ( !::SwapBuffers(m_hDC) )
+ {
+ return false;
wxLogLastError(_T("SwapBuffers"));
+ }
+ return true;
}
// ----------------------------------------------------------------------------
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);
}
// ============================================================================
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