Browse Source

Shaders: add debug output for LineVertexAnnotations as well.

Need to inspect a generated mesh.
pull/601/head
Vladimír Vondruš 3 years ago
parent
commit
c8d8fd7e19
  1. 28
      src/Magnum/Shaders/Line.cpp
  2. 12
      src/Magnum/Shaders/Line.h
  3. 40
      src/Magnum/Shaders/Test/LineTest.cpp

28
src/Magnum/Shaders/Line.cpp

@ -26,6 +26,7 @@
#include "Line.h"
#include <Corrade/Containers/String.h>
#include <Corrade/Containers/EnumSet.hpp>
#include "Magnum/Shaders/Implementation/lineMiterLimit.h"
@ -73,4 +74,31 @@ Debug& operator<<(Debug& debug, const LineJoinStyle value) {
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const LineVertexAnnotation value) {
const bool packed = debug.immediateFlags() >= Debug::Flag::Packed;
if(!packed)
debug << "Shaders::LineVertexAnnotation" << Debug::nospace;
switch(value) {
/* LCOV_EXCL_START */
#define _c(v) case LineVertexAnnotation::v: return debug << (packed ? "" : "::") << Debug::nospace << #v;
_c(Up)
_c(Join)
_c(Begin)
#undef _c
/* LCOV_EXCL_STOP */
}
return debug << (packed ? "" : "(") << Debug::nospace << reinterpret_cast<void*>(UnsignedInt(value)) << Debug::nospace << (packed ? "" : ")");
}
Debug& operator<<(Debug& debug, const LineVertexAnnotations value) {
return Containers::enumSetDebugOutput(debug, value, debug.immediateFlags() >= Debug::Flag::Packed ? "{}" : "Shaders::LineVertexAnnotations{}", {
LineVertexAnnotation::Up,
LineVertexAnnotation::Join,
LineVertexAnnotation::Begin,
});
}
}}

12
src/Magnum/Shaders/Line.h

@ -211,6 +211,18 @@ MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, LineCapStyle value);
*/
MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, LineJoinStyle value);
/**
* @debugoperatorenum{LineVertexAnnotation}
* @m_since_latest
*/
MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, LineVertexAnnotation value);
/**
* @debugoperatorenum{LineVertexAnnotations}
* @m_since_latest
*/
MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, LineVertexAnnotations value);
/**
@brief Per-draw uniform for line shaders
@m_since_latest

40
src/Magnum/Shaders/Test/LineTest.cpp

@ -53,6 +53,10 @@ struct LineTest: TestSuite::Tester {
void debugCapStyle();
void debugJoinStyle();
void debugVertexAnnotation();
void debugVertexAnnotationPacked();
void debugVertexAnnotations();
void debugVertexAnnotationsPacked();
};
using namespace Math::Literals;
@ -99,7 +103,11 @@ LineTest::LineTest() {
Containers::arraySize(MaterialUniformSetMiterAngleLimitInvalidData));
addTests({&LineTest::debugCapStyle,
&LineTest::debugJoinStyle});
&LineTest::debugJoinStyle,
&LineTest::debugVertexAnnotation,
&LineTest::debugVertexAnnotationPacked,
&LineTest::debugVertexAnnotations,
&LineTest::debugVertexAnnotationsPacked});
}
template<class> struct UniformTraits;
@ -301,6 +309,36 @@ void LineTest::debugJoinStyle() {
CORRADE_COMPARE(out.str(), "Shaders::LineJoinStyle::Bevel Shaders::LineJoinStyle(0xb0)\n");
}
void LineTest::debugVertexAnnotation() {
/* The values are guaranteed to fit into 8 bytes but the type itself is
32bit to avoid surprises when passing it to the default-constructed
LineGL::Annotation attribute (which defaults to 32bit), so it should
also print the whole 32bit value. */
std::ostringstream out;
Debug{&out} << LineVertexAnnotation::Join << LineVertexAnnotation(0xcafecafe);
CORRADE_COMPARE(out.str(), "Shaders::LineVertexAnnotation::Join Shaders::LineVertexAnnotation(0xcafecafe)\n");
}
void LineTest::debugVertexAnnotationPacked() {
std::ostringstream out;
/* Last is not packed, ones before should not make any flags persistent */
Debug{&out} << Debug::packed << LineVertexAnnotation::Join << Debug::packed << LineVertexAnnotation(0xcafecafe) << LineVertexAnnotation::Begin;
CORRADE_COMPARE(out.str(), "Join 0xcafecafe Shaders::LineVertexAnnotation::Begin\n");
}
void LineTest::debugVertexAnnotations() {
std::ostringstream out;
Debug{&out} << (LineVertexAnnotation::Up|LineVertexAnnotation::Join|LineVertexAnnotation(0xb00)) << LineVertexAnnotations{};
CORRADE_COMPARE(out.str(), "Shaders::LineVertexAnnotation::Up|Shaders::LineVertexAnnotation::Join|Shaders::LineVertexAnnotation(0xb00) Shaders::LineVertexAnnotations{}\n");
}
void LineTest::debugVertexAnnotationsPacked() {
std::ostringstream out;
/* Last is not packed, ones before should not make any flags persistent */
Debug{&out} << Debug::packed << (LineVertexAnnotation::Up|LineVertexAnnotation::Join|LineVertexAnnotation(0xb00)) << Debug::packed << LineVertexAnnotations{} << LineVertexAnnotation::Begin;
CORRADE_COMPARE(out.str(), "Up|Join|0xb00 {} Shaders::LineVertexAnnotation::Begin\n");
}
}}}}
CORRADE_TEST_MAIN(Magnum::Shaders::Test::LineTest)

Loading…
Cancel
Save