Browse Source

Shaders: unify assert for common flags in 2D and 3D meshvisualizer.

pull/442/head
Vladimír Vondruš 6 years ago
parent
commit
b858385b84
  1. 20
      src/Magnum/Shaders/MeshVisualizer.cpp
  2. 16
      src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp

20
src/Magnum/Shaders/MeshVisualizer.cpp

@ -53,6 +53,16 @@ namespace {
namespace Implementation {
MeshVisualizerBase::MeshVisualizerBase(FlagsBase flags): _flags{flags} {
#ifndef MAGNUM_TARGET_GLES2
#ifndef CORRADE_NO_ASSERT
Int countMutuallyExclusive = 0;
if(flags & FlagBase::InstancedObjectId) ++countMutuallyExclusive;
if(flags & FlagBase::PrimitiveIdFromVertexId) ++countMutuallyExclusive;
#endif
CORRADE_ASSERT(countMutuallyExclusive <= 1,
"Shaders::MeshVisualizer: Flag::InstancedObjectId and Flag::PrimitiveId are mutually exclusive", );
#endif
#ifndef MAGNUM_TARGET_GLES2
if(_flags & FlagBase::Wireframe && !(_flags & FlagBase::NoGeometryShader)) {
#ifndef MAGNUM_TARGET_GLES
@ -180,11 +190,6 @@ MeshVisualizer2D::MeshVisualizer2D(const Flags flags): Implementation::MeshVisua
"Shaders::MeshVisualizer2D: at least Flag::Wireframe has to be enabled", );
#endif
#ifndef MAGNUM_TARGET_GLES2
CORRADE_ASSERT(!(flags & Flag::InstancedObjectId) || !(flags & Flag::PrimitiveIdFromVertexId),
"Shaders::MeshVisualizer2D: Flag::InstancedObjectId and Flag::PrimitiveId are mutually exclusive", );
#endif
Utility::Resource rs{"MagnumShaders"};
GL::Shader vert{NoCreate};
GL::Shader frag{NoCreate};
@ -334,11 +339,6 @@ MeshVisualizer3D::MeshVisualizer3D(const Flags flags): Implementation::MeshVisua
"Shaders::MeshVisualizer3D: at least Flag::Wireframe has to be enabled", );
#endif
#ifndef MAGNUM_TARGET_GLES2
CORRADE_ASSERT(!(flags & Flag::InstancedObjectId) || !(flags & Flag::PrimitiveIdFromVertexId),
"Shaders::MeshVisualizer3D: Flag::InstancedObjectId and Flag::PrimitiveId are mutually exclusive", );
#endif
Utility::Resource rs{"MagnumShaders"};
GL::Shader vert{NoCreate};
GL::Shader frag{NoCreate};

16
src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp

@ -201,15 +201,15 @@ constexpr struct {
{"no feature enabled",
MeshVisualizer2D::Flag::NoGeometryShader, /* not a feature flag */
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
"at least one visualization feature has to be enabled"
"2D: at least one visualization feature has to be enabled"
#else
"at least Flag::Wireframe has to be enabled"
"2D: at least Flag::Wireframe has to be enabled"
#endif
},
#ifndef MAGNUM_TARGET_GLES2
{"both object and primitive id",
MeshVisualizer2D::Flag::InstancedObjectId|MeshVisualizer2D::Flag::PrimitiveIdFromVertexId,
"Flag::InstancedObjectId and Flag::PrimitiveId are mutually exclusive"}
": Flag::InstancedObjectId and Flag::PrimitiveId are mutually exclusive"}
#endif
};
@ -221,15 +221,15 @@ constexpr struct {
{"no feature enabled",
MeshVisualizer3D::Flag::NoGeometryShader, /* not a feature flag */
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
"at least one visualization feature has to be enabled"
"3D: at least one visualization feature has to be enabled"
#else
"at least Flag::Wireframe has to be enabled"
"3D: at least Flag::Wireframe has to be enabled"
#endif
},
#ifndef MAGNUM_TARGET_GLES2
{"both object and primitive id",
MeshVisualizer3D::Flag::InstancedObjectId|MeshVisualizer3D::Flag::PrimitiveIdFromVertexId,
"Flag::InstancedObjectId and Flag::PrimitiveId are mutually exclusive"}
": Flag::InstancedObjectId and Flag::PrimitiveId are mutually exclusive"}
#endif
};
@ -665,7 +665,7 @@ void MeshVisualizerGLTest::construct2DInvalid() {
std::ostringstream out;
Error redirectError{&out};
MeshVisualizer2D{data.flags};
CORRADE_COMPARE(out.str(), Utility::formatString("Shaders::MeshVisualizer2D: {}\n", data.message));
CORRADE_COMPARE(out.str(), Utility::formatString("Shaders::MeshVisualizer{}\n", data.message));
}
void MeshVisualizerGLTest::construct3DInvalid() {
@ -679,7 +679,7 @@ void MeshVisualizerGLTest::construct3DInvalid() {
std::ostringstream out;
Error redirectError{&out};
MeshVisualizer3D{data.flags};
CORRADE_COMPARE(out.str(), Utility::formatString("Shaders::MeshVisualizer3D: {}\n", data.message));
CORRADE_COMPARE(out.str(), Utility::formatString("Shaders::MeshVisualizer{}\n", data.message));
}
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)

Loading…
Cancel
Save