From 3e16f7ac58e9125e61c7b5650b850b1e8e89534a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 18 Feb 2014 21:17:57 +0100 Subject: [PATCH] Added function to query whether given extension is disabled. --- src/Magnum/Context.h | 36 ++++++++++++++++++++++++++++++- src/Magnum/Test/ContextGLTest.cpp | 16 +++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/Magnum/Context.h b/src/Magnum/Context.h index 081ddca13..dab32ace8 100644 --- a/src/Magnum/Context.h +++ b/src/Magnum/Context.h @@ -288,7 +288,8 @@ class MAGNUM_EXPORT Context { * @endcode * * @see isExtensionSupported(const Extension&) const, - * @ref MAGNUM_ASSERT_EXTENSION_SUPPORTED() + * @ref MAGNUM_ASSERT_EXTENSION_SUPPORTED(), + * @ref isExtensionDisabled() * @todoc Explicit reference when Doxygen is sane */ template bool isExtensionSupported() const { @@ -327,6 +328,39 @@ class MAGNUM_EXPORT Context { return isVersionSupported(_extensionRequiredVersion[extension._index]) && extensionStatus[extension._index]; } + /** + * @brief Whether given extension is supported by the driver but disabled + * + * Can be used for detecting driver bug workarounds. Disabled + * extensions return `false` in @ref isExtensionSupported() even if + * they are advertised as being supported by the driver. + */ + template bool isExtensionDisabled() const { + return isExtensionDisabled(version()); + } + + /** + * @brief Whether given extension is supported by the driver but disabled for given version + * + * Similar to above, but can also check for extensions which are + * disabled only for particular versions. + */ + template bool isExtensionDisabled(Version version) const { + /* The extension is advertised, but the minimal version has been increased */ + return T::requiredVersion() <= version && extensionStatus[T::Index] && _extensionRequiredVersion[T::Index] > version; + } + + /** + * @brief Whether given extension is supported by the driver but disabled + * + * Can be used e.g. for listing extensions available on current + * hardware, but for general usage prefer isExtensionDisabled() const, + * as it does most operations in compile time. + */ + bool isExtensionDisabled(const Extension& extension) const { + return isVersionSupported(extension._requiredVersion) && extensionStatus[extension._index] && !isVersionSupported(_extensionRequiredVersion[extension._index]); + } + #ifndef DOXYGEN_GENERATING_OUTPUT Implementation::State& state() { return *_state; } #endif diff --git a/src/Magnum/Test/ContextGLTest.cpp b/src/Magnum/Test/ContextGLTest.cpp index 1f78d7ea7..90f038f54 100644 --- a/src/Magnum/Test/ContextGLTest.cpp +++ b/src/Magnum/Test/ContextGLTest.cpp @@ -36,12 +36,14 @@ class ContextGLTest: public AbstractOpenGLTester { void isVersionSupported(); void supportedVersion(); void isExtensionSupported(); + void isExtensionDisabled(); }; ContextGLTest::ContextGLTest() { addTests({&ContextGLTest::isVersionSupported, &ContextGLTest::supportedVersion, - &ContextGLTest::isExtensionSupported}); + &ContextGLTest::isExtensionSupported, + &ContextGLTest::isExtensionDisabled}); } void ContextGLTest::isVersionSupported() { @@ -80,6 +82,18 @@ void ContextGLTest::isExtensionSupported() { #endif } +void ContextGLTest::isExtensionDisabled() { + #ifndef MAGNUM_TARGET_GLES + if(!Context::current()->isExtensionSupported()) + CORRADE_SKIP(Extensions::GL::APPLE::vertex_array_object::string() + std::string(" extension should be supported, can't test")); + + /* This is not disabled anywhere */ + CORRADE_VERIFY(!Context::current()->isExtensionDisabled()); + #else + CORRADE_SKIP("No useful extensions to test on OpenGL ES"); + #endif +} + }} CORRADE_TEST_MAIN(Magnum::Test::ContextGLTest)