Browse Source

Shaders: assert on the wireframe flag when calling related setters.

This is to be consistent with other shaders -- failing loudly is better
than habing to spend ages wondering why it doesn't render the thing.
findsdl-include-root
Vladimír Vondruš 7 years ago
parent
commit
a1a59ec4ea
  1. 4
      doc/changelog.dox
  2. 2
      src/Magnum/Shaders/CMakeLists.txt
  3. 17
      src/Magnum/Shaders/MeshVisualizer.cpp
  4. 23
      src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp

4
doc/changelog.dox

@ -781,6 +781,10 @@ See also:
to indicate an invalid format, better catching accidentally forgotten
initialization. Valid code shouldn't be affected by this change, but broken
code that seemingly worked before might start throwing assertions now.
- @ref Shaders::MeshVisualizer now asserts if its wireframe-related setters
are called when the @ref Shaders::MeshVisualizer::Flag::Wireframe flag was
not set, consistently with other shaders. This might cause failures in code
that was calling them unnecessarily before.
@section changelog-2019-01 2019.01

2
src/Magnum/Shaders/CMakeLists.txt

@ -33,7 +33,6 @@ set_target_properties(MagnumShaders_RCS-dependencies PROPERTIES FOLDER "Magnum/S
set(MagnumShaders_SRCS
AbstractVector.cpp
DistanceFieldVector.cpp
MeshVisualizer.cpp
Vector.cpp
VertexColor.cpp
@ -41,6 +40,7 @@ set(MagnumShaders_SRCS
set(MagnumShaders_GracefulAssert_SRCS
Flat.cpp
MeshVisualizer.cpp
Phong.cpp)
set(MagnumShaders_HEADERS

17
src/Magnum/Shaders/MeshVisualizer.cpp

@ -164,6 +164,8 @@ MeshVisualizer& MeshVisualizer::setTransformationProjectionMatrix(const Matrix4&
}
MeshVisualizer& MeshVisualizer::setViewportSize(const Vector2& size) {
/* Not asserting here, since the relation to wireframe is a bit vague.
Also it's an ugly hack that should be removed, ideally. */
if(_flags & Flag::Wireframe && !(_flags & Flag::NoGeometryShader))
setUniform(_viewportSizeUniform, size);
return *this;
@ -175,18 +177,25 @@ MeshVisualizer& MeshVisualizer::setColor(const Color4& color) {
}
MeshVisualizer& MeshVisualizer::setWireframeColor(const Color4& color) {
if(_flags & Flag::Wireframe) setUniform(_wireframeColorUniform, color);
CORRADE_ASSERT(_flags & Flag::Wireframe,
"Shaders::MeshVisualizer::setWireframeColor(): the shader was not created with wireframe enabled", *this);
setUniform(_wireframeColorUniform, color);
return *this;
}
MeshVisualizer& MeshVisualizer::setWireframeWidth(const Float width) {
if(_flags & Flag::Wireframe) setUniform(_wireframeWidthUniform, width);
CORRADE_ASSERT(_flags & Flag::Wireframe,
"Shaders::MeshVisualizer::setWireframeWidth(): the shader was not created with wireframe enabled", *this);
setUniform(_wireframeWidthUniform, width);
return *this;
}
MeshVisualizer& MeshVisualizer::setSmoothness(const Float smoothness) {
if(_flags & Flag::Wireframe)
setUniform(_smoothnessUniform, smoothness);
/* This is a bit vaguely related too, but less vague than setViewportSize()
so asserting. */
CORRADE_ASSERT(_flags & Flag::Wireframe,
"Shaders::MeshVisualizer::setSmoothness(): the shader was not created with wireframe enabled", *this);
setUniform(_smoothnessUniform, smoothness);
return *this;
}

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

@ -24,9 +24,11 @@
*/
#include <numeric>
#include <sstream>
#include <Corrade/Containers/ArrayViewStl.h>
#include <Corrade/Containers/StridedArrayView.h>
#include <Corrade/PluginManager/Manager.h>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/Directory.h>
#include "Magnum/DebugTools/CompareImage.h"
@ -67,6 +69,8 @@ struct MeshVisualizerGLTest: GL::OpenGLTester {
void constructMove();
void setWireframeNotEnabled();
void renderSetup();
void renderTeardown();
@ -121,7 +125,9 @@ MeshVisualizerGLTest::MeshVisualizerGLTest() {
#endif
&MeshVisualizerGLTest::constructWireframeNoGeometryShader,
&MeshVisualizerGLTest::constructMove});
&MeshVisualizerGLTest::constructMove,
&MeshVisualizerGLTest::setWireframeNotEnabled});
addTests({&MeshVisualizerGLTest::renderDefaults,
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
@ -218,6 +224,21 @@ void MeshVisualizerGLTest::constructMove() {
CORRADE_VERIFY(!b.id());
}
void MeshVisualizerGLTest::setWireframeNotEnabled() {
std::ostringstream out;
Error redirectError{&out};
MeshVisualizer shader;
shader.setWireframeColor({})
.setWireframeWidth({})
.setSmoothness({});
CORRADE_COMPARE(out.str(),
"Shaders::MeshVisualizer::setWireframeColor(): the shader was not created with wireframe enabled\n"
"Shaders::MeshVisualizer::setWireframeWidth(): the shader was not created with wireframe enabled\n"
"Shaders::MeshVisualizer::setSmoothness(): the shader was not created with wireframe enabled\n");
}
constexpr Vector2i RenderSize{80, 80};
void MeshVisualizerGLTest::renderSetup() {

Loading…
Cancel
Save