src/video/cocoa/SDL_cocoaopengl.m
changeset 6567 d50613615139
parent 6382 64d54101773a
child 6832 156e608ec4ef
     1.1 --- a/src/video/cocoa/SDL_cocoaopengl.m	Sat Oct 06 12:16:32 2012 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoaopengl.m	Wed Oct 10 23:10:04 2012 -0400
     1.3 @@ -32,8 +32,15 @@
     1.4  #include "SDL_loadso.h"
     1.5  #include "SDL_opengl.h"
     1.6  
     1.7 +#define DEFAULT_OPENGL  "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
     1.8  
     1.9 -#define DEFAULT_OPENGL  "/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"
    1.10 +
    1.11 +#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
    1.12 +#define kCGLPFAOpenGLProfile 99
    1.13 +#define kCGLOGLPVersion_Legacy 0x1000
    1.14 +#define kCGLOGLPVersion_3_2_Core 0x3200
    1.15 +#endif
    1.16 +
    1.17  
    1.18  int
    1.19  Cocoa_GL_LoadLibrary(_THIS, const char *path)
    1.20 @@ -70,6 +77,9 @@
    1.21  SDL_GLContext
    1.22  Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
    1.23  {
    1.24 +    const int wantver = (_this->gl_config.major_version << 8) |
    1.25 +                        (_this->gl_config.minor_version);
    1.26 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    1.27      NSAutoreleasePool *pool;
    1.28      SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    1.29      SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata;
    1.30 @@ -78,8 +88,32 @@
    1.31      NSOpenGLContext *context;
    1.32      int i = 0;
    1.33  
    1.34 +    if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
    1.35 +        SDL_SetError ("OpenGL ES not supported on this platform");
    1.36 +        return NULL;
    1.37 +    }
    1.38 +
    1.39 +    /* Sadly, we'll have to update this as life progresses, since we need to
    1.40 +       set an enum for context profiles, not a context version number */
    1.41 +    if (wantver > 0x0302) {
    1.42 +        SDL_SetError ("OpenGL > 3.2 is not supported on this platform");
    1.43 +        return NULL;
    1.44 +    }
    1.45 +
    1.46      pool = [[NSAutoreleasePool alloc] init];
    1.47  
    1.48 +    /* specify a profile if we're on Lion (10.7) or later. */
    1.49 +    if (data->osversion >= 0x1070) {
    1.50 +        NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy;
    1.51 +        if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
    1.52 +            if (wantver == 0x0302) {
    1.53 +                profile = kCGLOGLPVersion_3_2_Core;
    1.54 +            }
    1.55 +        }
    1.56 +        attr[i++] = kCGLPFAOpenGLProfile;
    1.57 +        attr[i++] = profile;
    1.58 +    }
    1.59 +
    1.60  #ifndef FULLSCREEN_TOGGLEABLE
    1.61      if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.62          attr[i++] = NSOpenGLPFAFullScreen;