Browse Source

Platform: try to create core context in Sdl2Application on all platforms.

Originally enabled just on OSX, apparently something similar is needed
also in Mesa. If the version is not user-specified, core GL 3.2 is
created on OSX, core 3.0 elsewhere. If that fails, the application falls
back to creating compatibility 2.1 context.

Hopefully I didn't break anything. The only difference on OSX is that
the application doesn't fall back anymore if the version is
user-specified.
pull/87/head
Vladimír Vondruš 12 years ago
parent
commit
48e666e238
  1. 61
      src/Magnum/Platform/Sdl2Application.cpp
  2. 5
      src/Magnum/Platform/Sdl2Application.h

61
src/Magnum/Platform/Sdl2Application.cpp

@ -111,7 +111,7 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
/** @todo Remove when Emscripten has proper SDL2 support */
#ifndef CORRADE_TARGET_EMSCRIPTEN
/* Set context version, if requested */
/* Set context version, if user-specified */
if(configuration.version() != Version::None) {
Int major, minor;
std::tie(major, minor) = version(configuration.version());
@ -124,10 +124,25 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
#else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
#endif
}
#ifdef MAGNUM_TARGET_GLES
else {
/* Request usable version otherwise */
} else {
#ifndef MAGNUM_TARGET_GLES
/* First try to create core context. This is needed mainly on OS X and
Mesa, as support for recent OpenGL versions isn't implemented in
compatibility contexts (which are the default). At least GL 3.2 is
needed on OSX, at least GL 3.0 is needed on Mesa. Bite the bullet
and try 3.0 also elsewhere. */
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
#ifdef CORRADE_TARGET_APPLE
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
#else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#endif
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#else
/* For ES the major context version is compile-time constant */
#ifdef MAGNUM_TARGET_GLES3
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
#elif defined(MAGNUM_TARGET_GLES2)
@ -137,21 +152,9 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
#endif
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
#endif
}
/* 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. */
#elif defined(CORRADE_TARGET_APPLE)
else {
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
/* Create window */
if(!(window = SDL_CreateWindow(configuration.title().data(),
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
@ -162,9 +165,13 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
return false;
}
/* Fall back to GL 2.1, if 3.2 context creation fails on OS X */
#ifdef CORRADE_TARGET_APPLE
if(!(context = SDL_GL_CreateContext(window))){
/* Create context */
context = SDL_GL_CreateContext(window);
#ifndef MAGNUM_TARGET_GLES
/* Fall back to (forward compatible) GL 2.1, if core context creation fails
and if version is not user-specified */
if(configuration.version() == Version::None && !context) {
Warning() << "Platform::Sdl2Application::tryCreateContext(): cannot create core context:" << SDL_GetError() << "(falling back to compatibility context)";
SDL_DestroyWindow(window);
@ -180,22 +187,16 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
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(!(context = SDL_GL_CreateContext(window))) {
#endif
/* Cannot create context (or fallback compatibility context on desktop) */
if(!context) {
Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create context:" << SDL_GetError();
SDL_DestroyWindow(window);
window = nullptr;
return false;
}
#endif
#else
/* Emscripten-specific initialization */

5
src/Magnum/Platform/Sdl2Application.h

@ -247,6 +247,11 @@ class Sdl2Application {
* Must be called if and only if the context wasn't created by the
* constructor itself. The program exits if the context cannot be
* created, see @ref tryCreateContext() for an alternative.
*
* On desktop GL, if version is not specified in @p configuration, the
* application first tries to create core context (OpenGL 3.2+ on OS X,
* OpenGL 3.0+ elsewhere) and if that fails, falls back to
* compatibility OpenGL 2.1 context.
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
void createContext(const Configuration& configuration = Configuration());

Loading…
Cancel
Save