From 9527d39ad3afd662f14d7f1febf8dab791992db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 1 Mar 2014 00:32:30 +0100 Subject: [PATCH] Added Context::extensionStrings(). Returns list of _all_ extensions reported by the driver, even those that are not supported in Magnum and also those that are marked as disabled due to driver bugs. Usable mostly when doing fresh port to new platform to discover possible new features. The actual implementation was part of Context constructor (and now this function is called instead). It is rather ugly because we need to take care of both GL 2.1 and GL 3.0 (and also ES2 and ES3). --- src/Magnum/Context.cpp | 77 +++++++++++++++++++++--------------------- src/Magnum/Context.h | 13 +++++++ 2 files changed, 52 insertions(+), 38 deletions(-) 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; }