From 97712994267aea6ada7f8673a58e08ba4affa213 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 10 Oct 2012 23:10:04 -0400 Subject: [PATCH] Allow specifying of OpenGL 3.2 Core Profile on Mac OS X. --- src/video/cocoa/SDL_cocoaopengl.m | 36 ++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m index cfd0a3b64..880b0c145 100644 --- a/src/video/cocoa/SDL_cocoaopengl.m +++ b/src/video/cocoa/SDL_cocoaopengl.m @@ -32,9 +32,16 @@ #include "SDL_loadso.h" #include "SDL_opengl.h" - #define DEFAULT_OPENGL "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib" + +#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070 +#define kCGLPFAOpenGLProfile 99 +#define kCGLOGLPVersion_Legacy 0x1000 +#define kCGLOGLPVersion_3_2_Core 0x3200 +#endif + + int Cocoa_GL_LoadLibrary(_THIS, const char *path) { @@ -70,6 +77,9 @@ SDL_GLContext Cocoa_GL_CreateContext(_THIS, SDL_Window * window) { + const int wantver = (_this->gl_config.major_version << 8) | + (_this->gl_config.minor_version); + SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; NSAutoreleasePool *pool; SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; @@ -78,8 +88,32 @@ NSOpenGLContext *context; int i = 0; + if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) { + SDL_SetError ("OpenGL ES not supported on this platform"); + return NULL; + } + + /* Sadly, we'll have to update this as life progresses, since we need to + set an enum for context profiles, not a context version number */ + if (wantver > 0x0302) { + SDL_SetError ("OpenGL > 3.2 is not supported on this platform"); + return NULL; + } + pool = [[NSAutoreleasePool alloc] init]; + /* specify a profile if we're on Lion (10.7) or later. */ + if (data->osversion >= 0x1070) { + NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy; + if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) { + if (wantver == 0x0302) { + profile = kCGLOGLPVersion_3_2_Core; + } + } + attr[i++] = kCGLPFAOpenGLProfile; + attr[i++] = profile; + } + #ifndef FULLSCREEN_TOGGLEABLE if (window->flags & SDL_WINDOW_FULLSCREEN) { attr[i++] = NSOpenGLPFAFullScreen;