diff --git a/src/Magnum/GL/Context.cpp b/src/Magnum/GL/Context.cpp index a9ae98e2c..58de84b38 100644 --- a/src/Magnum/GL/Context.cpp +++ b/src/Magnum/GL/Context.cpp @@ -1284,11 +1284,14 @@ Context::Configuration& Context::Configuration::addDisabledExtensions(std::initi #ifndef DOXYGEN_GENERATING_OUTPUT #ifndef MAGNUM_TARGET_WEBGL Debug& operator<<(Debug& debug, const Context::Flag value) { - debug << "GL::Context::Flag" << Debug::nospace; + const bool packed = debug.immediateFlags() >= Debug::Flag::Packed; + + if(!packed) + debug << "GL::Context::Flag" << Debug::nospace; switch(value) { /* LCOV_EXCL_START */ - #define _c(value) case Context::Flag::value: return debug << "::" #value; + #define _c(value) case Context::Flag::value: return debug << (packed ? "" : "::") << Debug::nospace << #value; _c(Debug) #ifndef MAGNUM_TARGET_GLES _c(ForwardCompatible) @@ -1301,11 +1304,11 @@ Debug& operator<<(Debug& debug, const Context::Flag value) { /* LCOV_EXCL_STOP */ } - return debug << "(" << Debug::nospace << reinterpret_cast(GLint(value)) << Debug::nospace << ")"; + return debug << (packed ? "" : "(") << Debug::nospace << reinterpret_cast(GLint(value)) << Debug::nospace << (packed ? "" : ")"); } Debug& operator<<(Debug& debug, const Context::Flags value) { - return Containers::enumSetDebugOutput(debug, value, "GL::Context::Flags{}", { + return Containers::enumSetDebugOutput(debug, value, debug.immediateFlags() >= Debug::Flag::Packed ? "{}" : "GL::Context::Flags{}", { Context::Flag::Debug, #ifndef MAGNUM_TARGET_GLES Context::Flag::ForwardCompatible, @@ -1319,11 +1322,14 @@ Debug& operator<<(Debug& debug, const Context::Flags value) { #endif Debug& operator<<(Debug& debug, const Context::DetectedDriver value) { - debug << "GL::Context::DetectedDriver" << Debug::nospace; + const bool packed = debug.immediateFlags() >= Debug::Flag::Packed; + + if(!packed) + debug << "GL::Context::DetectedDriver" << Debug::nospace; switch(value) { /* LCOV_EXCL_START */ - #define _c(value) case Context::DetectedDriver::value: return debug << "::" #value; + #define _c(value) case Context::DetectedDriver::value: return debug << (packed ? "" : "::") << Debug::nospace << #value; _c(Amd) #ifdef MAGNUM_TARGET_GLES _c(Angle) @@ -1342,11 +1348,11 @@ Debug& operator<<(Debug& debug, const Context::DetectedDriver value) { /* LCOV_EXCL_STOP */ } - return debug << "(" << Debug::nospace << reinterpret_cast(GLint(value)) << Debug::nospace << ")"; + return debug << (packed ? "" : "(") << Debug::nospace << reinterpret_cast(GLint(value)) << Debug::nospace << (packed ? "" : ")"); } Debug& operator<<(Debug& debug, const Context::DetectedDrivers value) { - return Containers::enumSetDebugOutput(debug, value, "GL::Context::DetectedDrivers{}", { + return Containers::enumSetDebugOutput(debug, value, debug.immediateFlags() >= Debug::Flag::Packed ? "{}" : "GL::Context::DetectedDrivers{}", { #ifndef MAGNUM_TARGET_WEBGL Context::DetectedDriver::Amd, #endif diff --git a/src/Magnum/GL/Test/ContextTest.cpp b/src/Magnum/GL/Test/ContextTest.cpp index eaa2afde1..c9070c4c3 100644 --- a/src/Magnum/GL/Test/ContextTest.cpp +++ b/src/Magnum/GL/Test/ContextTest.cpp @@ -56,10 +56,14 @@ struct ContextTest: TestSuite::Tester { void extensions(); void debugFlag(); + void debugFlagPacked(); void debugFlags(); + void debugFlagsPacked(); void debugDetectedDriver(); + void debugDetectedDriverPacked(); void debugDetectedDrivers(); + void debugDetectedDriversPacked(); }; ContextTest::ContextTest() { @@ -78,10 +82,14 @@ ContextTest::ContextTest() { &ContextTest::extensions, &ContextTest::debugFlag, + &ContextTest::debugFlagPacked, &ContextTest::debugFlags, + &ContextTest::debugFlagsPacked, &ContextTest::debugDetectedDriver, - &ContextTest::debugDetectedDrivers}); + &ContextTest::debugDetectedDriverPacked, + &ContextTest::debugDetectedDrivers, + &ContextTest::debugDetectedDriversPacked}); } void ContextTest::isExtension() { @@ -453,13 +461,35 @@ void ContextTest::debugFlag() { #endif } +void ContextTest::debugFlagPacked() { + #ifdef MAGNUM_TARGET_WEBGL + CORRADE_SKIP("No context flags on Emscripten yet."); + #else + std::ostringstream out; + /* Last is not packed, ones before should not make any flags persistent */ + Debug{&out} << Debug::packed << Context::Flag::Debug << Debug::packed << Context::Flag(0xdead) << Context::Flag::NoError; + CORRADE_COMPARE(out.str(), "Debug 0xdead GL::Context::Flag::NoError\n"); + #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(), "GL::Context::Flags{} GL::Context::Flag::Debug|GL::Context::Flag::NoError GL::Context::Flag::Debug|GL::Context::Flag(0xded0)\n"); + Debug{&out} << (Context::Flag::Debug|Context::Flag::NoError|Context::Flag(0xded0)) << Context::Flags{}; + CORRADE_COMPARE(out.str(), "GL::Context::Flag::Debug|GL::Context::Flag::NoError|GL::Context::Flag(0xded0) GL::Context::Flags{}\n"); + #endif +} + +void ContextTest::debugFlagsPacked() { + #ifdef MAGNUM_TARGET_WEBGL + CORRADE_SKIP("No context flags on Emscripten yet."); + #else + std::ostringstream out; + /* Last is not packed, ones before should not make any flags persistent */ + Debug{&out} << Debug::packed << (Context::Flag::Debug|Context::Flag::NoError|Context::Flag(0xded0)) << Debug::packed << Context::Flags{} << (Context::Flag::Debug|Context::Flag::NoError); + CORRADE_COMPARE(out.str(), "Debug|NoError|0xded0 {} GL::Context::Flag::Debug|GL::Context::Flag::NoError\n"); #endif } @@ -474,14 +504,38 @@ void ContextTest::debugDetectedDriver() { #endif } +void ContextTest::debugDetectedDriverPacked() { + std::ostringstream out; + /* Last is not packed, ones before should not make any flags persistent */ + #ifndef MAGNUM_TARGET_WEBGL + Debug{&out} << Debug::packed << Context::DetectedDriver::Amd << Debug::packed << Context::DetectedDriver(0xdead) << Context::DetectedDriver::NVidia; + CORRADE_COMPARE(out.str(), "Amd 0xdead GL::Context::DetectedDriver::NVidia\n"); + #else + Debug{&out} << Debug::packed << Context::DetectedDriver::Angle << Debug::packed << Context::DetectedDriver(0xdead) << Context::DetectedDriver::Angle; + CORRADE_COMPARE(out.str(), "Angle 0xdead GL::Context::DetectedDriver::Angle\n"); + #endif +} + void ContextTest::debugDetectedDrivers() { std::ostringstream out; #ifndef MAGNUM_TARGET_WEBGL - Debug{&out} << Context::DetectedDrivers{} << (Context::DetectedDriver::Amd|Context::DetectedDriver::NVidia) << (Context::DetectedDriver::Mesa|Context::DetectedDriver(0xde00)); - CORRADE_COMPARE(out.str(), "GL::Context::DetectedDrivers{} GL::Context::DetectedDriver::Amd|GL::Context::DetectedDriver::NVidia GL::Context::DetectedDriver::Mesa|GL::Context::DetectedDriver(0xde00)\n"); + Debug{&out} << (Context::DetectedDriver::Amd|Context::DetectedDriver::Mesa|Context::DetectedDriver(0xde00)) << Context::DetectedDrivers{}; + CORRADE_COMPARE(out.str(), "GL::Context::DetectedDriver::Amd|GL::Context::DetectedDriver::Mesa|GL::Context::DetectedDriver(0xde00) GL::Context::DetectedDrivers{}\n"); + #else + Debug{&out} << (Context::DetectedDriver::Angle|Context::DetectedDriver(0xde00)) << Context::DetectedDrivers{}; + CORRADE_COMPARE(out.str(), "GL::Context::DetectedDriver::Angle|GL::Context::DetectedDriver(0xde00) GL::Context::DetectedDrivers{}\n"); + #endif +} + +void ContextTest::debugDetectedDriversPacked() { + std::ostringstream out; + /* Last is not packed, ones before should not make any flags persistent */ + #ifndef MAGNUM_TARGET_WEBGL + Debug{&out} << Debug::packed << (Context::DetectedDriver::Amd|Context::DetectedDriver::Mesa|Context::DetectedDriver(0xde00)) << Debug::packed << Context::DetectedDrivers{} << (Context::DetectedDriver::Amd|Context::DetectedDriver::Mesa); + CORRADE_COMPARE(out.str(), "Amd|Mesa|0xde00 {} GL::Context::DetectedDriver::Amd|GL::Context::DetectedDriver::Mesa\n"); #else - Debug{&out} << Context::DetectedDrivers{} << (Context::DetectedDriver::Angle) << (Context::DetectedDriver::Angle|Context::DetectedDriver(0xde00)); - CORRADE_COMPARE(out.str(), "GL::Context::DetectedDrivers{} GL::Context::DetectedDriver::Angle GL::Context::DetectedDriver::Angle|GL::Context::DetectedDriver(0xde00)\n"); + Debug{&out} << Debug::packed << (Context::DetectedDriver::Angle|Context::DetectedDriver(0xde00)) << Debug::packed << Context::DetectedDrivers{} << (Context::DetectedDriver::Angle|Context::DetectedDriver(0xde00)); + CORRADE_COMPARE(out.str(), "Angle|0xde00 {} GL::Context::DetectedDriver::Angle|GL::Context::DetectedDriver(0xde00)\n"); #endif }