X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/524c47aa3adf2af11a3069fd5da035a604f08f66..08670ea85abf4b4946a9ce64971b591d7b1ee30b:/src/osx/carbon/glcanvas.cpp diff --git a/src/osx/carbon/glcanvas.cpp b/src/osx/carbon/glcanvas.cpp index f61a03cb47..8268a38ae6 100644 --- a/src/osx/carbon/glcanvas.cpp +++ b/src/osx/carbon/glcanvas.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/glcanvas.cpp +// Name: src/osx/carbon/glcanvas.cpp // Purpose: wxGLCanvas, for using OpenGL with wxWidgets under Macintosh // Author: Stefan Csomor // Modified by: @@ -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 ) @@ -208,7 +214,7 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList) if ( !attribList[arg++] ) break; - return false; + return NULL; } data[p++] = AGL_SAMPLE_BUFFERS_ARB; @@ -225,7 +231,7 @@ WXGLPixelFormat WXGLChoosePixelFormat(const int *attribList) if ( !attribList[arg++] ) break; - return false; + return NULL; } data[p++] = AGL_SAMPLES_ARB; @@ -251,27 +257,32 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const if ( !m_glContext ) return false; - AGLDrawable drawable = (AGLDrawable)GetWindowPort( - MAC_WXHWND(win.MacGetTopLevelWindowRef())); - GLint bufnummer = win.GetAglBufferName(); aglSetInteger(m_glContext, AGL_BUFFER_NAME, &bufnummer); //win.SetLastContext(m_glContext); - - wx_const_cast(wxGLCanvas&, win).SetViewport(); - if ( !aglSetDrawable(m_glContext, drawable) ) + const_cast(win).SetViewport(); + + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 + if ( UMAGetSystemVersion() >= 0x1050 ) { - wxLogAGLError("aglSetDrawable"); - return false; + aglSetWindowRef(m_glContext, win.MacGetTopLevelWindowRef()); } - - if ( !aglSetCurrentContext(m_glContext) ) + else +#endif { - wxLogAGLError("aglSetCurrentContext"); - return false; + AGLDrawable drawable = (AGLDrawable)GetWindowPort( + MAC_WXHWND(win.MacGetTopLevelWindowRef())); + + if ( !aglSetDrawable(m_glContext, drawable) ) + { + wxLogAGLError("aglSetDrawable"); + return false; + } } - return true; + + return WXGLSetCurrentContext(m_glContext); } // ---------------------------------------------------------------------------- @@ -280,19 +291,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 @@ -310,11 +321,11 @@ that previously allocated surface is associated with the context (e.g., no new surface is created) and the subsequent call to aglSetDrawable will attach that surface. This allows multiple contexts to be attached to a single surface. Using the default buffer name zero, returns to one surface per -context behavior. +context behaviour. */ /* -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,10 +353,19 @@ bool wxGLCanvas::Create(wxWindow *parent, static GLint gCurrentBufferName = 1; m_bufferName = gCurrentBufferName++; - aglSetInteger (m_dummyContext, AGL_BUFFER_NAME, &m_bufferName); - - AGLDrawable drawable = (AGLDrawable)GetWindowPort(MAC_WXHWND(MacGetTopLevelWindowRef())); - aglSetDrawable(m_dummyContext, drawable); + aglSetInteger (m_dummyContext, AGL_BUFFER_NAME, &m_bufferName); + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 + if ( UMAGetSystemVersion() >= 0x1050 ) + { + aglSetWindowRef(m_dummyContext, MacGetTopLevelWindowRef()); + } + else +#endif + { + AGLDrawable drawable = (AGLDrawable)GetWindowPort(MAC_WXHWND(MacGetTopLevelWindowRef())); + aglSetDrawable(m_dummyContext, drawable); + } m_macCanvasIsShown = true; @@ -356,11 +376,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 )