From 63d4570f6a78cde9fa0edae3a7601b1e3b9ea3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 2 Jan 2014 20:11:23 +0100 Subject: [PATCH] Platform: minor code deduplication, documentation and cleanup. --- src/Platform/Sdl2Application.cpp | 35 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index 173697088..01f3409f9 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -111,23 +111,30 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) { /** @todo Remove when Emscripten has proper SDL2 support */ #ifndef CORRADE_TARGET_EMSCRIPTEN - + /* On OS X we need to create 3.2 context, as the default (2.1) contains + compatibility features which are not implemented for newer GL versions + in Apple's GL drivers, thus we would be forever stuck on 2.1 without the + new features. In practice SDL fails to create 2.1 context on recent OS X + versions. */ #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); + #endif 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; + SDL_WINDOW_OPENGL|flags))) + { + Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create window:" << SDL_GetError(); + return false; } + /* Fall back to GL 2.1, if 3.2 context creation fails on OS X */ + #ifdef __APPLE__ if(!(context = SDL_GL_CreateContext(window))){ - Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create core context:" << SDL_GetError() << " falling back to compatibility context."; + Warning() << "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); @@ -137,9 +144,10 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) { 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; + SDL_WINDOW_OPENGL|flags))) + { + Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create window:" << SDL_GetError(); + return false; } if(!(context = SDL_GL_CreateContext(window))){ @@ -149,16 +157,7 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) { return false; } } - #else - 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 context:" << SDL_GetError(); SDL_DestroyWindow(window);