X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5c33522fca7cddc441a316f5b9fb50d7685435ba..9482c64466359ec7cfd201bebc3399ac4a56b4e6:/src/osx/carbon/glcanvas.cpp diff --git a/src/osx/carbon/glcanvas.cpp b/src/osx/carbon/glcanvas.cpp index 111e298fd8..9a6226dd9a 100644 --- a/src/osx/carbon/glcanvas.cpp +++ b/src/osx/carbon/glcanvas.cpp @@ -77,14 +77,20 @@ void WXGLDestroyContext( WXGLContext context ) } } -void WXGLSwapBuffers( WXGLContext context ) +WXGLContext WXGLGetCurrentContext() { - aglSwapBuffers(context); + return aglGetCurrentContext(); } -WXGLContext WXGLGetCurrentContext() +bool WXGLSetCurrentContext(WXGLContext context) { - return aglGetCurrentContext(); + if ( !aglSetCurrentContext(context) ) + { + wxLogAGLError("aglSetCurrentContext"); + return false; + } + + return true; } void WXGLDestroyPixelFormat( WXGLPixelFormat pixelFormat ) @@ -257,7 +263,7 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const GLint bufnummer = win.GetAglBufferName(); aglSetInteger(m_glContext, AGL_BUFFER_NAME, &bufnummer); //win.SetLastContext(m_glContext); - + const_cast(win).SetViewport(); if ( !aglSetDrawable(m_glContext, drawable) ) @@ -266,12 +272,7 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const return false; } - if ( !aglSetCurrentContext(m_glContext) ) - { - wxLogAGLError("aglSetCurrentContext"); - return false; - } - return true; + return WXGLSetCurrentContext(m_glContext); } // ---------------------------------------------------------------------------- @@ -280,19 +281,19 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const /* -sharing contexts under AGL is not straightforward, to quote from +sharing contexts under AGL is not straightforward, to quote from http://lists.apple.com/archives/mac-opengl/2003/Jan/msg00402.html : -In Carbon OpenGL (AGL) you would use call aglSetInteger to setup a -buffer name and attached each context to that same name. From AGL +In Carbon OpenGL (AGL) you would use call aglSetInteger to setup a +buffer name and attached each context to that same name. From AGL you can do: GLint id = 1; ctx1 = aglCreateContext... aglSetInteger(ctx1, AGL_BUFFER_NAME, &id); // create name -aglAttachDrawable (ctx1,...); // create surface with associated with +aglAttachDrawable (ctx1,...); // create surface with associated with name (first time) ctx2 = aglCreateContext... aglSetInteger(ctx2, AGL_BUFFER_NAME, &id); // uses previously created name @@ -314,7 +315,7 @@ context behavior. */ /* -so what I'm doing is to have a dummy aglContext attached to a wxGLCanvas, +so what I'm doing is to have a dummy aglContext attached to a wxGLCanvas, assign it a buffer number */ @@ -342,8 +343,8 @@ bool wxGLCanvas::Create(wxWindow *parent, static GLint gCurrentBufferName = 1; m_bufferName = gCurrentBufferName++; - aglSetInteger (m_dummyContext, AGL_BUFFER_NAME, &m_bufferName); - + aglSetInteger (m_dummyContext, AGL_BUFFER_NAME, &m_bufferName); + AGLDrawable drawable = (AGLDrawable)GetWindowPort(MAC_WXHWND(MacGetTopLevelWindowRef())); aglSetDrawable(m_dummyContext, drawable); @@ -356,11 +357,20 @@ wxGLCanvas::~wxGLCanvas() { if ( m_glFormat ) WXGLDestroyPixelFormat(m_glFormat); - + if ( m_dummyContext ) WXGLDestroyContext(m_dummyContext); } +bool wxGLCanvas::SwapBuffers() +{ + WXGLContext context = WXGLGetCurrentContext(); + wxCHECK_MSG(context, false, wxT("should have current context")); + + aglSwapBuffers(context); + return true; +} + void wxGLCanvas::SetViewport() { if ( !m_needsUpdate )