diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m --- a/src/video/cocoa/SDL_cocoaopengl.m +++ b/src/video/cocoa/SDL_cocoaopengl.m @@ -48,17 +48,14 @@ @end #endif -#ifndef kCGLPFAOpenGLProfile -#define kCGLPFAOpenGLProfile 99 +#ifndef NSOpenGLPFAOpenGLProfile +#define NSOpenGLPFAOpenGLProfile 99 #endif -#ifndef kCGLOGLPVersion_Legacy -#define kCGLOGLPVersion_Legacy 0x1000 +#ifndef NSOpenGLProfileVersionLegacy +#define NSOpenGLProfileVersionLegacy 0x1000 #endif -#ifndef kCGLOGLPVersion_GL3_Core -#define kCGLOGLPVersion_GL3_Core 0x3200 -#endif -#ifndef kCGLOGLPVersion_GL4_Core -#define kCGLOGLPVersion_GL4_Core 0x4100 +#ifndef NSOpenGLProfileVersion3_2Core +#define NSOpenGLProfileVersion3_2Core 0x3200 #endif @implementation SDLOpenGLContext : NSOpenGLContext @@ -186,30 +183,26 @@ 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 > 0x0401) { - SDL_SetError ("OpenGL > 4.1 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; + NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy; if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) { + /* We can only ask for a general core profile context. We check what + * we acually get below. */ if (wantver == 0x0302) { - profile = kCGLOGLPVersion_GL3_Core; - } else if ((wantver == 0x0401) && (data->osversion >= 0x1090)) { - profile = kCGLOGLPVersion_GL4_Core; + profile = NSOpenGLProfileVersion3_2Core; + } else if ((wantver == 0x303 || wantver >= 0x0400) + && (data->osversion >= 0x1090)) { + profile = NSOpenGLProfileVersion3_2Core; } else { SDL_SetError("Requested GL version is not supported on this platform"); [pool release]; return NULL; } } - attr[i++] = kCGLPFAOpenGLProfile; + attr[i++] = NSOpenGLPFAOpenGLProfile; attr[i++] = profile; } @@ -289,9 +282,40 @@ if ( Cocoa_GL_MakeCurrent(_this, window, context) < 0 ) { Cocoa_GL_DeleteContext(_this, context); + SDL_SetError("Failed to make context current"); return NULL; } + /* The context's version must not be less than the requested version. We + * do the check just for GL 3.0+ in order to match the behaviour of SDL's + * GLX and WGL backend code. SDL also requests GL 2.1 by default, so we + * don't want to unconditionally fail on pre-2.1 systems if the default + * values are used. */ + if (wantver >= 0x300) { + const GLubyte *glversion = glGetString(GL_VERSION); + GLubyte major; + GLubyte minor; + int realver; + + if (glversion == NULL) { + Cocoa_GL_DeleteContext(_this, context); + SDL_SetError("Could not determine context version"); + return NULL; + } + + /* The version string starts with "major.minor". */ + major = glversion[0] - '0'; + minor = glversion[2] - '0'; + + realver = ((int) major << 8) | minor; + + if (realver < wantver) { + Cocoa_GL_DeleteContext(_this, context); + SDL_SetError("Requested GL version is not supported"); + return NULL; + } + } + return context; }