Browse Source

GL: add debug output operators for ObjectFlags.

pull/680/head
Vladimír Vondruš 10 months ago
parent
commit
6b11916fb8
  1. 23
      src/Magnum/GL/AbstractObject.cpp
  2. 12
      src/Magnum/GL/AbstractObject.h
  3. 60
      src/Magnum/GL/Test/AbstractObjectTest.cpp
  4. 1
      src/Magnum/GL/Test/CMakeLists.txt

23
src/Magnum/GL/AbstractObject.cpp

@ -27,6 +27,7 @@
#include "AbstractObject.h" #include "AbstractObject.h"
#include <Corrade/Containers/ArrayView.h> #include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/EnumSet.hpp>
#ifndef MAGNUM_TARGET_WEBGL #ifndef MAGNUM_TARGET_WEBGL
#include <Corrade/Containers/String.h> #include <Corrade/Containers/String.h>
#endif #endif
@ -41,6 +42,28 @@
namespace Magnum { namespace GL { 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 #ifndef MAGNUM_TARGET_WEBGL
namespace { namespace {
inline GLenum extTypeFromKhrIdentifier(GLenum khrIdentifier) { inline GLenum extTypeFromKhrIdentifier(GLenum khrIdentifier) {

12
src/Magnum/GL/AbstractObject.h

@ -70,6 +70,12 @@ enum class ObjectFlag: UnsignedByte {
DeleteOnDestruction = 1 << 1 DeleteOnDestruction = 1 << 1
}; };
/**
@debugoperatorenum{ObjectFlag}
@m_since_latest
*/
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, ObjectFlag value);
/** /**
@brief Object wrapping flags @brief Object wrapping flags
@ -84,6 +90,12 @@ enum class ObjectFlag: UnsignedByte {
*/ */
typedef Containers::EnumSet<ObjectFlag> ObjectFlags; typedef Containers::EnumSet<ObjectFlag> ObjectFlags;
/**
@debugoperatorenum{ObjectFlags}
@m_since_latest
*/
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, ObjectFlags value);
/** /**
@brief Base for all OpenGL objects @brief Base for all OpenGL objects
*/ */

60
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š <mosra@centrum.cz>
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 <Corrade/Containers/String.h>
#include <Corrade/TestSuite/Tester.h>
#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)

1
src/Magnum/GL/Test/CMakeLists.txt

@ -28,6 +28,7 @@
# property that would have to be set on each target separately. # property that would have to be set on each target separately.
set(CMAKE_FOLDER "Magnum/GL/Test") 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(GLAbstractShaderProgramTest AbstractShaderProgramTest.cpp LIBRARIES MagnumGL)
corrade_add_test(GLAttributeTest AttributeTest.cpp LIBRARIES MagnumGLTestLib) corrade_add_test(GLAttributeTest AttributeTest.cpp LIBRARIES MagnumGLTestLib)
corrade_add_test(GLBufferTest BufferTest.cpp LIBRARIES MagnumGL) corrade_add_test(GLBufferTest BufferTest.cpp LIBRARIES MagnumGL)

Loading…
Cancel
Save