Browse Source

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).
pull/51/head
Vladimír Vondruš 12 years ago
parent
commit
9527d39ad3
  1. 77
      src/Magnum/Context.cpp
  2. 13
      src/Magnum/Context.h

77
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<const char*>(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<std::string> 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<const char*>(glGetString(GL_EXTENSIONS));
if(e) {
std::vector<std::string> 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<std::string> Context::shadingLanguageVersionStrings() const {
#endif
}
std::vector<std::string> Context::extensionStrings() const {
std::vector<std::string> 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<const char*>(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<const char*>(glGetString(GL_EXTENSIONS));
if(e) extensions = Utility::String::splitWithoutEmptyParts(e, ' ');
}
#endif
return extensions;
}
Version Context::supportedVersion(std::initializer_list<Version> versions) const {
for(auto version: versions)
if(isVersionSupported(version)) return version;

13
src/Magnum/Context.h

@ -233,6 +233,19 @@ class MAGNUM_EXPORT Context {
*/
std::vector<std::string> 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<std::string> extensionStrings() const;
/** @brief Context flags */
Flags flags() const { return _flags; }

Loading…
Cancel
Save