Browse Source

Fix version checks on OpenGL 2.1 and OpenGL ES 2.0.

Both don't have GL_{MAJOR,MINOR}_VERSION enums so we must decide whether
the version is older than OpenGL 3.0 / ES 3.0 either using
MAGNUM_TARGET_GLES2 preprocessor definition or checking for invalid enum
error and then we have to parse version string to ensure that the
version is not too old. On ES2 the version check wasn't present at all
(only optimistic hope), this makes it more hardened.
pull/51/head
Vladimír Vondruš 12 years ago
parent
commit
41235c20eb
  1. 48
      src/Magnum/Context.cpp

48
src/Magnum/Context.cpp

@ -295,22 +295,60 @@ Context::Context() {
} }
#endif #endif
/* Version */ /* Get version */
#ifndef MAGNUM_TARGET_GLES2 #if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_GLES2)
glGetIntegerv(GL_MAJOR_VERSION, &_majorVersion); glGetIntegerv(GL_MAJOR_VERSION, &_majorVersion);
glGetIntegerv(GL_MINOR_VERSION, &_minorVersion); glGetIntegerv(GL_MINOR_VERSION, &_minorVersion);
#else #else
_majorVersion = 2;
_minorVersion = 0; /* On GL 2.1 and ES 2.0 there is no GL_{MAJOR,MINOR}_VERSION, we have to
parse version string. On desktop GL we have no way to check version
without version (duh) so we work around that by checking for invalid
enum error. */
#ifndef MAGNUM_TARGET_GLES2
glGetIntegerv(GL_MAJOR_VERSION, &_majorVersion);
auto error = Renderer::error();
if(error == Renderer::Error::NoError)
glGetIntegerv(GL_MINOR_VERSION, &_minorVersion);
else
#endif #endif
{
#ifndef MAGNUM_TARGET_GLES2
CORRADE_ASSERT(error == Renderer::Error::InvalidEnum,
"Context: cannot retrieve OpenGL version:" << error, );
#endif
const std::string version = versionString();
#ifndef MAGNUM_TARGET_GLES
if(version.find("OpenGL 2.1") != std::string::npos)
#else
if(version.find("OpenGL ES 2.0") != std::string::npos)
#endif
{
_majorVersion = 2;
#ifndef MAGNUM_TARGET_GLES
_minorVersion = 1;
#else
_minorVersion = 0;
#endif
} else {
Error() << "Context: unsupported version string:" << version;
std::exit(1);
}
}
#endif
/* Compose the version enum */
_version = Magnum::version(_majorVersion, _minorVersion); _version = Magnum::version(_majorVersion, _minorVersion);
/* Check that version retrieval went right */
#ifndef CORRADE_NO_ASSERT #ifndef CORRADE_NO_ASSERT
const auto error = Renderer::error(); error = Renderer::error();
CORRADE_ASSERT(error == Renderer::Error::NoError, CORRADE_ASSERT(error == Renderer::Error::NoError,
"Context: cannot retrieve OpenGL version:" << error, ); "Context: cannot retrieve OpenGL version:" << error, );
#endif #endif
/* Check that the version is supported (now it probably is, but be sure) */
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
if(!isVersionSupported(Version::GL210)) if(!isVersionSupported(Version::GL210))
#elif defined(MAGNUM_TARGET_GLES2) #elif defined(MAGNUM_TARGET_GLES2)

Loading…
Cancel
Save