diff --git a/src/Context.cpp b/src/Context.cpp index 31b31f744..b63b32013 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -329,25 +329,31 @@ Context::Context() { futureExtensions.insert(std::make_pair(extension._string, extension)); /* Check for presence of extensions in future versions */ - #ifndef MAGNUM_TARGET_GLES - if(isVersionSupported(Version::GL300)) { - #else - if(isVersionSupported(Version::GLES300)) { + #ifndef MAGNUM_TARGET_GLES2 + GLint extensionCount = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount); + #ifndef MAGNUM_TARGET_GLES3 + if(extensionCount || isVersionSupported(Version::GL300)) #endif - #ifndef MAGNUM_TARGET_GLES2 - GLuint index = 0; - const char* extension; - while((extension = reinterpret_cast(glGetStringi(GL_EXTENSIONS, index++)))) { + { + _supportedExtensions.reserve(extensionCount); + for(GLint i = 0; i != extensionCount; ++i) { + const std::string extension(reinterpret_cast(glGetStringi(GL_EXTENSIONS, i))); auto found = futureExtensions.find(extension); if(found != futureExtensions.end()) { _supportedExtensions.push_back(found->second); extensionStatus.set(found->second._index); } } - #endif + } + #ifndef MAGNUM_TARGET_GLES3 + else + #endif + #endif + #ifndef MAGNUM_TARGET_GLES3 /* OpenGL 2.1 / OpenGL ES 2.0 doesn't have glGetStringi() */ - } else { + { /* Don't crash when glGetString() returns nullptr */ const char* e = reinterpret_cast(glGetString(GL_EXTENSIONS)); if(e) { @@ -361,6 +367,7 @@ Context::Context() { } } } + #endif /* Set this context as current */ CORRADE_ASSERT(!_current, "Context: Another context currently active", ); @@ -391,6 +398,26 @@ Context::~Context() { _current = nullptr; } +std::vector Context::shadingLanguageVersionStrings() const { + #ifndef MAGNUM_TARGET_GLES + GLint versionCount = 0; + glGetIntegerv(GL_NUM_SHADING_LANGUAGE_VERSIONS, &versionCount); + + /* The implementation doesn't yet support this query (< OpenGL 4.3) */ + if(!versionCount) + return {shadingLanguageVersionString()}; + + /* Get all of them */ + std::vector versions; + versions.reserve(versionCount); + for(GLint i = 0; i != versionCount; ++i) + versions.push_back(reinterpret_cast(glGetStringi(GL_SHADING_LANGUAGE_VERSION, i))); + return std::move(versions); + #else + return {shadingLanguageVersionString()}; + #endif +} + Version Context::supportedVersion(std::initializer_list versions) const { for(auto version: versions) if(isVersionSupported(version)) return version; diff --git a/src/Context.h b/src/Context.h index c0f374980..e57cbeab2 100644 --- a/src/Context.h +++ b/src/Context.h @@ -189,7 +189,8 @@ class MAGNUM_EXPORT Context { * Constructed automatically, see class documentation for more * information. * @see @fn_gl{Get} with @def_gl{MAJOR_VERSION}, @def_gl{MINOR_VERSION}, - * @def_gl{CONTEXT_FLAGS}, @fn_gl{GetString} with @def_gl{EXTENSIONS} + * @def_gl{CONTEXT_FLAGS}, @def_gl{NUM_EXTENSIONS}, + * @fn_gl{GetString} with @def_gl{EXTENSIONS} */ explicit Context(); @@ -268,6 +269,16 @@ class MAGNUM_EXPORT Context { return reinterpret_cast(glGetString(GL_SHADING_LANGUAGE_VERSION)); } + /** + * @brief Shading language version strings + * + * The result is *not* cached, repeated queries will result in repeated + * OpenGL calls. + * @see versionString(), version(), @fn_gl{Get} with @def_gl{NUM_SHADING_LANGUAGE_VERSIONS}, + * @fn_gl{GetString} with @def_gl{SHADING_LANGUAGE_VERSION} + */ + std::vector shadingLanguageVersionStrings() const; + /** @brief Context flags */ inline Flags flags() const { return _flags; } diff --git a/src/Platform/magnum-info.cpp b/src/Platform/magnum-info.cpp index f975e0f5c..2df377e93 100644 --- a/src/Platform/magnum-info.cpp +++ b/src/Platform/magnum-info.cpp @@ -83,7 +83,12 @@ MagnumInfo::MagnumInfo(const Arguments& arguments): WindowlessGlxApplication(arg Debug() << "Vendor:" << c->vendorString(); Debug() << "Renderer:" << c->rendererString(); Debug() << "OpenGL version:" << c->version() << '(' + c->versionString() + ')'; - Debug() << "GLSL version:" << c->version() << '(' + c->shadingLanguageVersionString() + ')'; + + Debug() << "Supported GLSL versions:"; + const std::vector shadingLanguageVersions = c->shadingLanguageVersionStrings(); + for(const auto& version: shadingLanguageVersions) + Debug() << " " << version; + Debug() << ""; /* Get first future (not supported) version */