Browse Source

Added Context::shadingLanguageVersionStrings(), better extension query.

Not relying on GL version when asking for extensions, i.e. Mesa might
know glGetStringi() even if it reports OpenGL 2.1 only. Similarly in
shadingLanguageVersionStrings(), not all HW is capable of 4.3, but
GL_NUM_SHADING_LANGUAGE_VERSIONS might be supported on GL3 HW too (not
my case, though).
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
ab5b6fcbb3
  1. 47
      src/Context.cpp
  2. 13
      src/Context.h
  3. 7
      src/Platform/magnum-info.cpp

47
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<const char*>(glGetStringi(GL_EXTENSIONS, index++)))) {
{
_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);
}
}
#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<const char*>(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<std::string> 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<std::string> versions;
versions.reserve(versionCount);
for(GLint i = 0; i != versionCount; ++i)
versions.push_back(reinterpret_cast<const char*>(glGetStringi(GL_SHADING_LANGUAGE_VERSION, i)));
return std::move(versions);
#else
return {shadingLanguageVersionString()};
#endif
}
Version Context::supportedVersion(std::initializer_list<Version> versions) const {
for(auto version: versions)
if(isVersionSupported(version)) return version;

13
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<const char*>(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<std::string> shadingLanguageVersionStrings() const;
/** @brief Context flags */
inline Flags flags() const { return _flags; }

7
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<std::string> shadingLanguageVersions = c->shadingLanguageVersionStrings();
for(const auto& version: shadingLanguageVersions)
Debug() << " " << version;
Debug() << "";
/* Get first future (not supported) version */

Loading…
Cancel
Save