From 5218fda6f8439007185623bdf36cbe43048535fc Mon Sep 17 00:00:00 2001 From: michael chung Date: Fri, 27 Dec 2013 18:20:52 -0500 Subject: [PATCH] Platform : This commit will allow failsafe core context creation on Mac OS X. Before this commit the default context creation in tryCreateContext would create the OpenGL 2.1 context.After this commit by default, the OpenGL 3.2 context is created by default, if this fails tryCreateContext will fall back to creating a OpenGL 2.1 context. --- src/Platform/Sdl2Application.cpp | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index 91b4d3d3b..173697088 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -111,6 +111,46 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) { /** @todo Remove when Emscripten has proper SDL2 support */ #ifndef CORRADE_TARGET_EMSCRIPTEN + + #ifdef __APPLE__ + + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + + if(!(window = SDL_CreateWindow(configuration.title().data(), + SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + configuration.size().x(), configuration.size().y(), + SDL_WINDOW_OPENGL|flags))){ + Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create core window:" << SDL_GetError(); + return false; + } + + if(!(context = SDL_GL_CreateContext(window))){ + Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create core context:" << SDL_GetError() << " falling back to compatibility context."; + SDL_DestroyWindow(window); + + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); + + if(!(window = SDL_CreateWindow(configuration.title().data(), + SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, + configuration.size().x(), configuration.size().y(), + SDL_WINDOW_OPENGL|flags))){ + Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create window:" << SDL_GetError(); + return false; + } + + if(!(context = SDL_GL_CreateContext(window))){ + Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create compatibility context:" << SDL_GetError(); + SDL_DestroyWindow(window); + window = nullptr; + return false; + } + } + + #else if(!(window = SDL_CreateWindow(configuration.title().data(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, configuration.size().x(), configuration.size().y(), @@ -125,6 +165,7 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) { window = nullptr; return false; } + #endif #else context = SDL_SetVideoMode(configuration.size().x(), configuration.size().y(), 24, SDL_OPENGL|SDL_HWSURFACE|SDL_DOUBLEBUF); #endif