Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 10 Oct 2012 23:10:04 -0400
changeset 6567 d50613615139
parent 6566 dd7e57847ea9
child 6568 1a6b0ae81937
Allow specifying of OpenGL 3.2 Core Profile on Mac OS X.
src/video/cocoa/SDL_cocoaopengl.m
--- a/src/video/cocoa/SDL_cocoaopengl.m	Sat Oct 06 12:16:32 2012 -0700
+++ b/src/video/cocoa/SDL_cocoaopengl.m	Wed Oct 10 23:10:04 2012 -0400
@@ -32,8 +32,15 @@
 #include "SDL_loadso.h"
 #include "SDL_opengl.h"
 
+#define DEFAULT_OPENGL  "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
 
-#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;