From 6b11916fb8ab68d19baebdd822d5e56a8cfed804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 12 Jul 2025 18:18:00 +0200 Subject: [PATCH] GL: add debug output operators for ObjectFlags. --- src/Magnum/GL/AbstractObject.cpp | 23 +++++++++ src/Magnum/GL/AbstractObject.h | 12 +++++ src/Magnum/GL/Test/AbstractObjectTest.cpp | 60 +++++++++++++++++++++++ src/Magnum/GL/Test/CMakeLists.txt | 1 + 4 files changed, 96 insertions(+) create mode 100644 src/Magnum/GL/Test/AbstractObjectTest.cpp diff --git a/src/Magnum/GL/AbstractObject.cpp b/src/Magnum/GL/AbstractObject.cpp index 6467782a2..855d803a0 100644 --- a/src/Magnum/GL/AbstractObject.cpp +++ b/src/Magnum/GL/AbstractObject.cpp @@ -27,6 +27,7 @@ #include "AbstractObject.h" #include +#include #ifndef MAGNUM_TARGET_WEBGL #include #endif @@ -41,6 +42,28 @@ namespace Magnum { namespace GL { +Debug& operator<<(Debug& debug, const ObjectFlag value) { + debug << "GL::ObjectFlag" << Debug::nospace; + + switch(value) { + /* LCOV_EXCL_START */ + #define _c(value) case ObjectFlag::value: return debug << "::" #value; + _c(Created) + _c(DeleteOnDestruction) + #undef _c + /* LCOV_EXCL_STOP */ + } + + return debug << "(" << Debug::nospace << Debug::hex << UnsignedByte(value) << Debug::nospace << ")"; +} + +Debug& operator<<(Debug& debug, const ObjectFlags value) { + return Containers::enumSetDebugOutput(debug, value, "GL::ObjectFlags{}", { + ObjectFlag::Created, + ObjectFlag::DeleteOnDestruction + }); +} + #ifndef MAGNUM_TARGET_WEBGL namespace { inline GLenum extTypeFromKhrIdentifier(GLenum khrIdentifier) { diff --git a/src/Magnum/GL/AbstractObject.h b/src/Magnum/GL/AbstractObject.h index c3c1c1fea..0a2299d81 100644 --- a/src/Magnum/GL/AbstractObject.h +++ b/src/Magnum/GL/AbstractObject.h @@ -70,6 +70,12 @@ enum class ObjectFlag: UnsignedByte { DeleteOnDestruction = 1 << 1 }; +/** +@debugoperatorenum{ObjectFlag} +@m_since_latest +*/ +MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, ObjectFlag value); + /** @brief Object wrapping flags @@ -84,6 +90,12 @@ enum class ObjectFlag: UnsignedByte { */ typedef Containers::EnumSet ObjectFlags; +/** +@debugoperatorenum{ObjectFlags} +@m_since_latest +*/ +MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, ObjectFlags value); + /** @brief Base for all OpenGL objects */ diff --git a/src/Magnum/GL/Test/AbstractObjectTest.cpp b/src/Magnum/GL/Test/AbstractObjectTest.cpp new file mode 100644 index 000000000..440a46f25 --- /dev/null +++ b/src/Magnum/GL/Test/AbstractObjectTest.cpp @@ -0,0 +1,60 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, + 2020, 2021, 2022, 2023, 2024, 2025 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include + +#include "Magnum/GL/Buffer.h" + +namespace Magnum { namespace GL { namespace Test { namespace { + +struct AbstractObjectTest: TestSuite::Tester { + explicit AbstractObjectTest(); + + void debugObjectFlag(); + void debugObjectFlags(); +}; + +AbstractObjectTest::AbstractObjectTest() { + addTests({&AbstractObjectTest::debugObjectFlag, + &AbstractObjectTest::debugObjectFlags}); +} + +void AbstractObjectTest::debugObjectFlag() { + Containers::String out; + Debug{&out} << ObjectFlag::Created << ObjectFlag(0xde); + CORRADE_COMPARE(out, "GL::ObjectFlag::Created GL::ObjectFlag(0xde)\n"); +} + +void AbstractObjectTest::debugObjectFlags() { + Containers::String out; + Debug{&out} << (ObjectFlag::Created|ObjectFlag::DeleteOnDestruction|ObjectFlag(0xa0)) << ObjectFlags{}; + CORRADE_COMPARE(out, "GL::ObjectFlag::Created|GL::ObjectFlag::DeleteOnDestruction|GL::ObjectFlag(0xa0) GL::ObjectFlags{}\n"); +} + +}}}} + +CORRADE_TEST_MAIN(Magnum::GL::Test::AbstractObjectTest) diff --git a/src/Magnum/GL/Test/CMakeLists.txt b/src/Magnum/GL/Test/CMakeLists.txt index 639dc578b..b19b0acbb 100644 --- a/src/Magnum/GL/Test/CMakeLists.txt +++ b/src/Magnum/GL/Test/CMakeLists.txt @@ -28,6 +28,7 @@ # property that would have to be set on each target separately. set(CMAKE_FOLDER "Magnum/GL/Test") +corrade_add_test(GLAbstractObjectTest AbstractObjectTest.cpp LIBRARIES MagnumGL) corrade_add_test(GLAbstractShaderProgramTest AbstractShaderProgramTest.cpp LIBRARIES MagnumGL) corrade_add_test(GLAttributeTest AttributeTest.cpp LIBRARIES MagnumGLTestLib) corrade_add_test(GLBufferTest BufferTest.cpp LIBRARIES MagnumGL)