From 9a5a4cdaedd635995988cd7d462898e526472f73 Mon Sep 17 00:00:00 2001 From: Nigel Stewart Date: Sat, 21 Feb 2015 20:53:05 +1000 Subject: [PATCH] [CoreSupport] Migrate glewinfo on Mac from AGL to CGL, with the possibility of running in (core) OpenGL 3.2 mode. --- auto/src/glewinfo_tail.c | 44 ++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/auto/src/glewinfo_tail.c b/auto/src/glewinfo_tail.c index a2b184a..b48a3f1 100644 --- a/auto/src/glewinfo_tail.c +++ b/auto/src/glewinfo_tail.c @@ -185,26 +185,34 @@ void glewDestroyContext () #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX) -#include +#include +#include -AGLContext ctx, octx; +CGLContextObj ctx, octx; GLboolean glewCreateContext () { - int attrib[] = { AGL_RGBA, AGL_NONE }; - AGLPixelFormat pf; - /*int major, minor; - SetPortWindowPort(wnd); - aglGetVersion(&major, &minor); - fprintf(stderr, "GL %d.%d\n", major, minor);*/ - pf = aglChoosePixelFormat(NULL, 0, attrib); - if (NULL == pf) return GL_TRUE; - ctx = aglCreateContext(pf, NULL); - if (NULL == ctx || AGL_NO_ERROR != aglGetError()) return GL_TRUE; - aglDestroyPixelFormat(pf); - /*aglSetDrawable(ctx, GetWindowPort(wnd));*/ - octx = aglGetCurrentContext(); - if (GL_FALSE == aglSetCurrentContext(ctx)) return GL_TRUE; + const CGLPixelFormatAttribute attrib[4] = + { + kCGLPFAAccelerated, /* No software rendering */ +#if 0 + kCGLPFAOpenGLProfile, /* OSX 10.7 Lion onwards */ + (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core, /* 3.2 Core Context */ +#endif + 0 + }; + CGLPixelFormatObj pf; + GLint npix; + CGLError error; + + error = CGLChoosePixelFormat(attrib, &pf, &npix); + if (error) return GL_TRUE; + error = CGLCreateContext(pf, NULL, &ctx); + if (error) return GL_TRUE; + CGLReleasePixelFormat(pf); + octx = CGLGetCurrentContext(); + error = CGLSetCurrentContext(ctx); + if (error) return GL_TRUE; /* Needed for Regal on the Mac */ #if defined(GLEW_REGAL) && defined(__APPLE__) RegalMakeCurrent(ctx); @@ -214,8 +222,8 @@ GLboolean glewCreateContext () void glewDestroyContext () { - aglSetCurrentContext(octx); - if (NULL != ctx) aglDestroyContext(ctx); + CGLSetCurrentContext(octx); + CGLReleaseContext(ctx); } /* ------------------------------------------------------------------------ */