From b83b12200556ce749751de8079a32d734f6aa857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 26 Apr 2017 17:47:18 +0200 Subject: [PATCH] Debug operator for Context::Flags. --- src/Magnum/Context.cpp | 11 +++++++++++ src/Magnum/Context.h | 6 ++++++ src/Magnum/Platform/magnum-info.cpp | 9 +-------- src/Magnum/Test/ContextTest.cpp | 14 +++++++++++++- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/Magnum/Context.cpp b/src/Magnum/Context.cpp index 43d2d3a86..7a741da18 100644 --- a/src/Magnum/Context.cpp +++ b/src/Magnum/Context.cpp @@ -31,6 +31,7 @@ #include /* for initialization log redirection */ #include #include +#include #include #include #include @@ -876,6 +877,16 @@ Debug& operator<<(Debug& debug, const Context::Flag value) { return debug << "Context::Flag(" << Debug::nospace << reinterpret_cast(GLint(value)) << Debug::nospace << ")"; } + +Debug& operator<<(Debug& debug, const Context::Flags value) { + return Containers::enumSetDebugOutput(debug, value, "Context::Flags{}", { + Context::Flag::Debug, + Context::Flag::NoError, + #ifndef MAGNUM_TARGET_GLES + Context::Flag::RobustAccess + #endif + }); +} #endif #endif diff --git a/src/Magnum/Context.h b/src/Magnum/Context.h index 49275372e..107ee94de 100644 --- a/src/Magnum/Context.h +++ b/src/Magnum/Context.h @@ -562,11 +562,17 @@ class MAGNUM_EXPORT Context { bool _displayInitializationLog; }; +#ifndef MAGNUM_TARGET_WEBGL +CORRADE_ENUMSET_OPERATORS(Context::Flags) +#endif CORRADE_ENUMSET_OPERATORS(Context::DetectedDrivers) #ifndef MAGNUM_TARGET_WEBGL /** @debugoperatorclassenum{Magnum::Context,Magnum::Context::Flag} */ MAGNUM_EXPORT Debug& operator<<(Debug& debug, Context::Flag value); + +/** @debugoperatorclassenum{Magnum::Context,Magnum::Context::Flags} */ +MAGNUM_EXPORT Debug& operator<<(Debug& debug, Context::Flags value); #endif /** @hideinitializer diff --git a/src/Magnum/Platform/magnum-info.cpp b/src/Magnum/Platform/magnum-info.cpp index d06ee9911..56c82bb2a 100644 --- a/src/Magnum/Platform/magnum-info.cpp +++ b/src/Magnum/Platform/magnum-info.cpp @@ -278,14 +278,7 @@ MagnumInfo::MagnumInfo(const Arguments& arguments): Platform::WindowlessApplicat #ifndef MAGNUM_TARGET_GLES Debug() << "Core profile:" << (c.isCoreProfile() ? "yes" : "no"); #endif - Debug() << "Context flags:"; - for(const auto flag: {Context::Flag::Debug, - Context::Flag::NoError, - #ifndef MAGNUM_TARGET_GLES - Context::Flag::RobustAccess - #endif - }) - if(c.flags() & flag) Debug() << " " << flag; + Debug() << "Context flags:" << c.flags(); Debug() << "Supported GLSL versions:"; const std::vector shadingLanguageVersions = c.shadingLanguageVersionStrings(); diff --git a/src/Magnum/Test/ContextTest.cpp b/src/Magnum/Test/ContextTest.cpp index fc38c7e05..a841308b6 100644 --- a/src/Magnum/Test/ContextTest.cpp +++ b/src/Magnum/Test/ContextTest.cpp @@ -34,10 +34,12 @@ struct ContextTest: TestSuite::Tester { explicit ContextTest(); void debugFlag(); + void debugFlags(); }; ContextTest::ContextTest() { - addTests({&ContextTest::debugFlag}); + addTests({&ContextTest::debugFlag, + &ContextTest::debugFlags}); } void ContextTest::debugFlag() { @@ -50,6 +52,16 @@ void ContextTest::debugFlag() { #endif } +void ContextTest::debugFlags() { + #ifdef MAGNUM_TARGET_WEBGL + CORRADE_SKIP("No context flags on Emscripten yet."); + #else + std::ostringstream out; + Debug(&out) << Context::Flags{} << (Context::Flag::Debug|Context::Flag::NoError) << (Context::Flag::Debug|Context::Flag(0xded0)); + CORRADE_COMPARE(out.str(), "Context::Flags{} Context::Flag::Debug|Context::Flag::NoError Context::Flag::Debug|Context::Flag(0xded0)\n"); + #endif +} + }} CORRADE_TEST_MAIN(Magnum::Test::ContextTest)