From b858385b84f33115d951d44ee5db69d0b8683bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 May 2020 14:43:29 +0200 Subject: [PATCH] Shaders: unify assert for common flags in 2D and 3D meshvisualizer. --- src/Magnum/Shaders/MeshVisualizer.cpp | 20 +++++++++---------- .../Shaders/Test/MeshVisualizerGLTest.cpp | 16 +++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Magnum/Shaders/MeshVisualizer.cpp b/src/Magnum/Shaders/MeshVisualizer.cpp index 7ac9a5794..114e47bac 100644 --- a/src/Magnum/Shaders/MeshVisualizer.cpp +++ b/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}; diff --git a/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp b/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp index 5811c6a95..c65c88e7b 100644 --- a/src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp +++ b/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)