diff --git a/src/Magnum/Context.cpp b/src/Magnum/Context.cpp index ca70e810a..7055aa9c3 100644 --- a/src/Magnum/Context.cpp +++ b/src/Magnum/Context.cpp @@ -409,46 +409,15 @@ Context::Context() { futureExtensions.insert({extension._string, extension}); #endif - /* Check for presence of extensions in future versions */ - #ifndef MAGNUM_TARGET_GLES2 - GLint extensionCount = 0; - glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount); - #ifndef MAGNUM_TARGET_GLES3 - if(extensionCount || isVersionSupported(Version::GL300)) - #endif - { - _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); - } + /* Check for presence of future and vendor extensions */ + const std::vector extensions = extensionStrings(); + for(const std::string& extension: extensions) { + const auto found = futureExtensions.find(extension); + if(found != futureExtensions.end()) { + _supportedExtensions.push_back(found->second); + extensionStatus.set(found->second._index); } } - #ifndef MAGNUM_TARGET_GLES3 - else - #endif - #endif - - #ifndef MAGNUM_TARGET_GLES3 - /* OpenGL 2.1 / OpenGL ES 2.0 doesn't have glGetStringi() */ - { - /* Don't crash when glGetString() returns nullptr */ - const char* e = reinterpret_cast(glGetString(GL_EXTENSIONS)); - if(e) { - std::vector extensions = Utility::String::split(e, ' '); - for(const std::string& extension: extensions) { - auto found = futureExtensions.find(extension); - if(found != futureExtensions.end()) { - _supportedExtensions.push_back(found->second); - extensionStatus.set(found->second._index); - } - } - } - } - #endif /* Reset minimal required version to Version::None for whole array */ for(auto& i: _extensionRequiredVersion) i = Version::None; @@ -501,6 +470,38 @@ std::vector Context::shadingLanguageVersionStrings() const { #endif } +std::vector Context::extensionStrings() const { + std::vector extensions; + + #ifndef MAGNUM_TARGET_GLES2 + GLint extensionCount = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount); + #ifndef MAGNUM_TARGET_GLES3 + if(extensionCount || isVersionSupported(Version::GL300)) + #endif + { + extensions.reserve(extensionCount); + for(GLint i = 0; i != extensionCount; ++i) + extensions.push_back(reinterpret_cast(glGetStringi(GL_EXTENSIONS, i))); + } + #ifndef MAGNUM_TARGET_GLES3 + else + #endif + #endif + + #ifndef MAGNUM_TARGET_GLES3 + /* OpenGL 2.1 / OpenGL ES 2.0 doesn't have glGetStringi() */ + { + /* Don't crash when glGetString() returns nullptr (i.e. don't trust the + old implementations) */ + const char* e = reinterpret_cast(glGetString(GL_EXTENSIONS)); + if(e) extensions = Utility::String::splitWithoutEmptyParts(e, ' '); + } + #endif + + return extensions; +} + Version Context::supportedVersion(std::initializer_list versions) const { for(auto version: versions) if(isVersionSupported(version)) return version; diff --git a/src/Magnum/Context.h b/src/Magnum/Context.h index dab32ace8..7ddcc5291 100644 --- a/src/Magnum/Context.h +++ b/src/Magnum/Context.h @@ -233,6 +233,19 @@ class MAGNUM_EXPORT Context { */ std::vector shadingLanguageVersionStrings() const; + /** + * @brief Extension strings + * + * The result is *not* cached, repeated queries will result in repeated + * OpenGL calls. Note that this function returns list of all extensions + * reported by the driver (even those not supported by %Magnum), see + * @ref supportedExtensions(), @ref Extension::extensions() or + * @ref isExtensionSupported() for alternatives. + * @see @fn_gl{Get} with @def_gl{NUM_EXTENSIONS}, @fn_gl{GetString} + * with @def_gl{EXTENSIONS} + */ + std::vector extensionStrings() const; + /** @brief Context flags */ Flags flags() const { return _flags; }