Browse Source

Shaders: remove MeshVisualizer default behavior.

It was rendering everything with a plain color, which is rather useless.
Moreover it wasn't consistent with TBN visualization where you might
actually want only the lines rendered and not the triangle.
pull/430/head
Vladimír Vondruš 6 years ago
parent
commit
171e8a5301
  1. 3
      doc/changelog.dox
  2. 22
      src/Magnum/Shaders/MeshVisualizer.cpp
  3. 7
      src/Magnum/Shaders/MeshVisualizer.frag
  4. 4
      src/Magnum/Shaders/MeshVisualizer.geom
  5. 47
      src/Magnum/Shaders/MeshVisualizer.h
  6. 2
      src/Magnum/Shaders/Test/CMakeLists.txt
  7. 196
      src/Magnum/Shaders/Test/MeshVisualizerGLTest.cpp

3
doc/changelog.dox

@ -530,6 +530,9 @@ See also:
@ref Primitives::GridFlag::Normals for naming consistency @ref Primitives::GridFlag::Normals for naming consistency
- @cpp Shaders::MeshVisualizer @ce is deprecated as the shader can now handle - @cpp Shaders::MeshVisualizer @ce is deprecated as the shader can now handle
both 2D and 3D, use @ref Shaders::MeshVisualizer3D instead both 2D and 3D, use @ref Shaders::MeshVisualizer3D instead
- Default constructor of @ref Shaders::MeshVisualizer3D is deprecated, you're
now required to enable at least one visualization feature when constructing
it
- @cpp Shaders::MeshVisualizer::setTransformationProjectionMatrix() @ce is - @cpp Shaders::MeshVisualizer::setTransformationProjectionMatrix() @ce is
deprecated on the 3D variant, use separate deprecated on the 3D variant, use separate
@ref Shaders::MeshVisualizer3D::setTransformationMatrix() and @ref Shaders::MeshVisualizer3D::setTransformationMatrix() and

22
src/Magnum/Shaders/MeshVisualizer.cpp

@ -69,10 +69,10 @@ MeshVisualizerBase::MeshVisualizerBase(FlagsBase flags): _flags{flags} {
GL::Version MeshVisualizerBase::setupShaders(GL::Shader& vert, GL::Shader& frag, const Utility::Resource& rs) const { GL::Version MeshVisualizerBase::setupShaders(GL::Shader& vert, GL::Shader& frag, const Utility::Resource& rs) const {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
const GL::Version version = GL::Context::current().supportedVersion({GL::Version::GL320, GL::Version::GL310, GL::Version::GL300, GL::Version::GL210}); const GL::Version version = GL::Context::current().supportedVersion({GL::Version::GL320, GL::Version::GL310, GL::Version::GL300, GL::Version::GL210});
CORRADE_INTERNAL_ASSERT(!_flags || _flags & FlagBase::NoGeometryShader || version >= GL::Version::GL320); CORRADE_INTERNAL_ASSERT(_flags & FlagBase::NoGeometryShader || version >= GL::Version::GL320);
#elif !defined(MAGNUM_TARGET_WEBGL) #elif !defined(MAGNUM_TARGET_WEBGL)
const GL::Version version = GL::Context::current().supportedVersion({GL::Version::GLES310, GL::Version::GLES300, GL::Version::GLES200}); const GL::Version version = GL::Context::current().supportedVersion({GL::Version::GLES310, GL::Version::GLES300, GL::Version::GLES200});
CORRADE_INTERNAL_ASSERT(!_flags || _flags & FlagBase::NoGeometryShader || version >= GL::Version::GLES310); CORRADE_INTERNAL_ASSERT(_flags & FlagBase::NoGeometryShader || version >= GL::Version::GLES310);
#else #else
const GL::Version version = GL::Context::current().supportedVersion({GL::Version::GLES300, GL::Version::GLES200}); const GL::Version version = GL::Context::current().supportedVersion({GL::Version::GLES300, GL::Version::GLES200});
#endif #endif
@ -96,6 +96,8 @@ GL::Version MeshVisualizerBase::setupShaders(GL::Shader& vert, GL::Shader& frag,
} }
MeshVisualizerBase& MeshVisualizerBase::setColor(const Color4& color) { MeshVisualizerBase& MeshVisualizerBase::setColor(const Color4& color) {
CORRADE_ASSERT(_flags & FlagBase::Wireframe,
"Shaders::MeshVisualizer::setColor(): the shader was not created with wireframe enabled", *this);
setUniform(_colorUniform, color); setUniform(_colorUniform, color);
return *this; return *this;
} }
@ -117,6 +119,9 @@ MeshVisualizerBase& MeshVisualizerBase::setWireframeWidth(const Float width) {
} }
MeshVisualizer2D::MeshVisualizer2D(const Flags flags): Implementation::MeshVisualizerBase{Implementation::MeshVisualizerBase::FlagBase(UnsignedByte(flags))} { MeshVisualizer2D::MeshVisualizer2D(const Flags flags): Implementation::MeshVisualizerBase{Implementation::MeshVisualizerBase::FlagBase(UnsignedByte(flags))} {
CORRADE_ASSERT(flags & (Flag::Wireframe & ~Flag::NoGeometryShader),
"Shaders::MeshVisualizer2D: at least Flag::Wireframe has to be enabled", );
Utility::Resource rs{"MagnumShaders"}; Utility::Resource rs{"MagnumShaders"};
GL::Shader vert{NoCreate}; GL::Shader vert{NoCreate};
GL::Shader frag{NoCreate}; GL::Shader frag{NoCreate};
@ -177,8 +182,8 @@ MeshVisualizer2D::MeshVisualizer2D(const Flags flags): Implementation::MeshVisua
#endif #endif
{ {
_transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix"); _transformationProjectionMatrixUniform = uniformLocation("transformationProjectionMatrix");
_colorUniform = uniformLocation("color");
if(flags & Flag::Wireframe) { if(flags & Flag::Wireframe) {
_colorUniform = uniformLocation("color");
_wireframeColorUniform = uniformLocation("wireframeColor"); _wireframeColorUniform = uniformLocation("wireframeColor");
_wireframeWidthUniform = uniformLocation("wireframeWidth"); _wireframeWidthUniform = uniformLocation("wireframeWidth");
_smoothnessUniform = uniformLocation("smoothness"); _smoothnessUniform = uniformLocation("smoothness");
@ -190,8 +195,8 @@ MeshVisualizer2D::MeshVisualizer2D(const Flags flags): Implementation::MeshVisua
/* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */ /* Set defaults in OpenGL ES (for desktop they are set in shader code itself) */
#ifdef MAGNUM_TARGET_GLES #ifdef MAGNUM_TARGET_GLES
setTransformationProjectionMatrix({}); setTransformationProjectionMatrix({});
setColor(Color3(1.0f));
if(flags & Flag::Wireframe) { if(flags & Flag::Wireframe) {
setColor(Color3(1.0f));
/* Viewport size is zero by default */ /* Viewport size is zero by default */
setWireframeColor(Color3{0.0f}); setWireframeColor(Color3{0.0f});
setWireframeWidth(1.0f); setWireframeWidth(1.0f);
@ -224,10 +229,15 @@ MeshVisualizer2D& MeshVisualizer2D::setSmoothness(const Float smoothness) {
MeshVisualizer3D::MeshVisualizer3D(const Flags flags): Implementation::MeshVisualizerBase{Implementation::MeshVisualizerBase::FlagBase(UnsignedByte(flags))} { MeshVisualizer3D::MeshVisualizer3D(const Flags flags): Implementation::MeshVisualizerBase{Implementation::MeshVisualizerBase::FlagBase(UnsignedByte(flags))} {
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
CORRADE_ASSERT(flags & ((Flag::Wireframe|Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection) & ~Flag::NoGeometryShader),
"Shaders::MeshVisualizer3D: at least one visualization feature has to be enabled", );
CORRADE_ASSERT(!(flags & Flag::NoGeometryShader && flags & (Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection)), CORRADE_ASSERT(!(flags & Flag::NoGeometryShader && flags & (Flag::TangentDirection|Flag::BitangentFromTangentDirection|Flag::BitangentDirection|Flag::NormalDirection)),
"Shaders::MeshVisualizer3D: geometry shader has to be enabled when rendering TBN direction", ); "Shaders::MeshVisualizer3D: geometry shader has to be enabled when rendering TBN direction", );
CORRADE_ASSERT(!(flags & Flag::BitangentDirection && flags & Flag::BitangentFromTangentDirection), CORRADE_ASSERT(!(flags & Flag::BitangentDirection && flags & Flag::BitangentFromTangentDirection),
"Shaders::MeshVisualizer3D: Flag::BitangentDirection and Flag::BitangentFromTangentDirection are mutually exclusive", ); "Shaders::MeshVisualizer3D: Flag::BitangentDirection and Flag::BitangentFromTangentDirection are mutually exclusive", );
#else
CORRADE_ASSERT(flags & (Flag::Wireframe & ~Flag::NoGeometryShader),
"Shaders::MeshVisualizer3D: at least Flag::Wireframe has to be enabled", );
#endif #endif
Utility::Resource rs{"MagnumShaders"}; Utility::Resource rs{"MagnumShaders"};
@ -323,8 +333,8 @@ MeshVisualizer3D::MeshVisualizer3D(const Flags flags): Implementation::MeshVisua
{ {
_transformationMatrixUniform = uniformLocation("transformationMatrix"); _transformationMatrixUniform = uniformLocation("transformationMatrix");
_projectionMatrixUniform = uniformLocation("projectionMatrix"); _projectionMatrixUniform = uniformLocation("projectionMatrix");
_colorUniform = uniformLocation("color");
if(flags & Flag::Wireframe) { if(flags & Flag::Wireframe) {
_colorUniform = uniformLocation("color");
_wireframeColorUniform = uniformLocation("wireframeColor"); _wireframeColorUniform = uniformLocation("wireframeColor");
_wireframeWidthUniform = uniformLocation("wireframeWidth"); _wireframeWidthUniform = uniformLocation("wireframeWidth");
} }
@ -350,8 +360,8 @@ MeshVisualizer3D::MeshVisualizer3D(const Flags flags): Implementation::MeshVisua
#ifdef MAGNUM_TARGET_GLES #ifdef MAGNUM_TARGET_GLES
setTransformationMatrix({}); setTransformationMatrix({});
setProjectionMatrix({}); setProjectionMatrix({});
setColor(Color3(1.0f));
if(flags & Flag::Wireframe) { if(flags & Flag::Wireframe) {
setColor(Color3(1.0f));
/* Viewport size is zero by default */ /* Viewport size is zero by default */
setWireframeColor(Color3{0.0f}); setWireframeColor(Color3{0.0f});
setWireframeWidth(1.0f); setWireframeWidth(1.0f);

7
src/Magnum/Shaders/MeshVisualizer.frag

@ -44,7 +44,7 @@
#extension GL_NV_shader_noperspective_interpolation: require #extension GL_NV_shader_noperspective_interpolation: require
#endif #endif
#ifndef TBN_DIRECTION #if defined(WIREFRAME_RENDERING) && !defined(TBN_DIRECTION)
#ifdef EXPLICIT_UNIFORM_LOCATION #ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 1) layout(location = 1)
#endif #endif
@ -54,7 +54,6 @@ uniform lowp vec4 color
#endif #endif
; ;
#if defined(WIREFRAME_RENDERING) && !defined(TBN_DIRECTION)
#ifdef EXPLICIT_UNIFORM_LOCATION #ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 2) layout(location = 2)
#endif #endif
@ -64,7 +63,6 @@ uniform lowp vec4 wireframeColor
#endif #endif
; ;
#endif #endif
#endif
#ifdef WIREFRAME_RENDERING #ifdef WIREFRAME_RENDERING
#ifdef EXPLICIT_UNIFORM_LOCATION #ifdef EXPLICIT_UNIFORM_LOCATION
@ -183,8 +181,7 @@ void main() {
fragmentColor = mix(wireframeColor, color, nearest); fragmentColor = mix(wireframeColor, color, nearest);
#endif #endif
/* Plain color rendering */
#else #else
fragmentColor = color; #error neither wireframe or TBN direction is enabled, huh?
#endif #endif
} }

4
src/Magnum/Shaders/MeshVisualizer.geom

@ -41,7 +41,7 @@ uniform lowp vec2 viewportSize; /* defaults to zero */
layout(triangles) in; layout(triangles) in;
#if defined(TANGENT_DIRECTION) || defined(BITANGENT_DIRECTION) || defined(NORMAL_DIRECTION) #if (defined(TANGENT_DIRECTION) || defined(BITANGENT_DIRECTION) || defined(NORMAL_DIRECTION)) && defined(WIREFRAME_RENDERING)
#ifdef EXPLICIT_UNIFORM_LOCATION #ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 1) layout(location = 1)
#endif #endif
@ -59,7 +59,9 @@ uniform lowp vec4 wireframeColor
= vec4(0.0, 0.0, 0.0, 1.0) = vec4(0.0, 0.0, 0.0, 1.0)
#endif #endif
; ;
#endif
#if defined(TANGENT_DIRECTION) || defined(BITANGENT_DIRECTION) || defined(NORMAL_DIRECTION)
#ifdef EXPLICIT_UNIFORM_LOCATION #ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 8) layout(location = 8)
#endif #endif

47
src/Magnum/Shaders/MeshVisualizer.h

@ -86,15 +86,16 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizerBase: public GL::AbstractShaderProgram
@m_since_latest @m_since_latest
Uses the geometry shader to visualize wireframe of 3D meshes. You need to Uses the geometry shader to visualize wireframe of 3D meshes. You need to
provide the @ref Position attribute in your triangle mesh. By default, the provide the @ref Position attribute in your triangle mesh. Use
shader renders the mesh with a white color in an identity transformation. Use
@ref setTransformationProjectionMatrix(), @ref setColor() and others to @ref setTransformationProjectionMatrix(), @ref setColor() and others to
configure the shader. configure the shader.
@image html shaders-meshvisualizer2d.png width=256px @image html shaders-meshvisualizer2d.png width=256px
This shader is a 2D variant of @ref MeshVisualizer3D with mostly identical The shader expects that you enable wireframe visualization by passing an
workflow. See its documentation for more information. appropriate @ref Flag to the constructor --- there's no default behavior with
nothing enabled. The shader is a 2D variant of @ref MeshVisualizer3D with
mostly identical workflow. See its documentation for more information.
*/ */
class MAGNUM_SHADERS_EXPORT MeshVisualizer2D: public Implementation::MeshVisualizerBase { class MAGNUM_SHADERS_EXPORT MeshVisualizer2D: public Implementation::MeshVisualizerBase {
public: public:
@ -153,8 +154,10 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer2D: public Implementation::MeshVisuali
/** /**
* @brief Constructor * @brief Constructor
* @param flags Flags * @param flags Flags
*
* At least @ref Flag::Wireframe is expected to be enabled.
*/ */
explicit MeshVisualizer2D(Flags flags = {}); explicit MeshVisualizer2D(Flags flags);
/** /**
* @brief Construct without creating the underlying OpenGL object * @brief Construct without creating the underlying OpenGL object
@ -209,7 +212,8 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer2D: public Implementation::MeshVisuali
* @brief Set base object color * @brief Set base object color
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Initial value is @cpp 0xffffffff_rgbaf @ce. * Initial value is @cpp 0xffffffff_rgbaf @ce. Expects that
* @ref Flag::Wireframe is enabled.
*/ */
MeshVisualizer2D& setColor(const Color4& color) { MeshVisualizer2D& setColor(const Color4& color) {
return static_cast<MeshVisualizer2D&>(Implementation::MeshVisualizerBase::setColor(color)); return static_cast<MeshVisualizer2D&>(Implementation::MeshVisualizerBase::setColor(color));
@ -255,14 +259,17 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer2D: public Implementation::MeshVisuali
/** /**
@brief 3D mesh visualization shader @brief 3D mesh visualization shader
Uses the geometry shader to visualize wireframe of 3D meshes. You need to Uses the geometry shader to visualize wireframe or tangent space of 3D meshes.
provide the @ref Position attribute in your triangle mesh. By default, the You need to provide the @ref Position attribute in your triangle mesh at the
shader renders the mesh with a white color in an identity transformation. Use very least. Use @ref setTransformationProjectionMatrix(), @ref setColor() and
@ref setTransformationProjectionMatrix(), @ref setColor() and others to others to configure the shader.
configure the shader.
@image html shaders-meshvisualizer3d.png width=256px @image html shaders-meshvisualizer3d.png width=256px
The shader expects that you enable either wireframe visualization or tangent
space visualization by passing an appropriate @ref Flag to the constructor ---
there's no default behavior with nothing enabled.
@section Shaders-MeshVisualizer-wireframe Wireframe visualization @section Shaders-MeshVisualizer-wireframe Wireframe visualization
Wireframe visualization is done by enabling @ref Flag::Wireframe. It is done Wireframe visualization is done by enabling @ref Flag::Wireframe. It is done
@ -538,8 +545,21 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer3D: public Implementation::MeshVisuali
/** /**
* @brief Constructor * @brief Constructor
* @param flags Flags * @param flags Flags
*
* At least @ref Flag::Wireframe or one of @ref Flag::TangentDirection,
* @ref Flag::BitangentFromTangentDirection,
* @ref Flag::BitangentDirection, @ref Flag::NormalDirection is
* expected to be enabled.
*/ */
explicit MeshVisualizer3D(Flags flags = {}); explicit MeshVisualizer3D(Flags flags);
#ifdef MAGNUM_BUILD_DEPRECATED
/**
* @brief Constructor
* @m_deprecated_since_latest Use @ref MeshVisualizer3D(Flags) instead.
*/
explicit CORRADE_DEPRECATED("use MeshVisualizer3D(Flags) instead") MeshVisualizer3D(): MeshVisualizer3D{{}} {}
#endif
/** /**
* @brief Construct without creating the underlying OpenGL object * @brief Construct without creating the underlying OpenGL object
@ -638,7 +658,8 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer3D: public Implementation::MeshVisuali
* @brief Set base object color * @brief Set base object color
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Initial value is @cpp 0xffffffff_rgbaf @ce. * Initial value is @cpp 0xffffffff_rgbaf @ce. Expects that
* @ref Flag::Wireframe is enabled.
*/ */
MeshVisualizer3D& setColor(const Color4& color) { MeshVisualizer3D& setColor(const Color4& color) {
return static_cast<MeshVisualizer3D&>(Implementation::MeshVisualizerBase::setColor(color)); return static_cast<MeshVisualizer3D&>(Implementation::MeshVisualizerBase::setColor(color));

2
src/Magnum/Shaders/Test/CMakeLists.txt

@ -151,8 +151,6 @@ if(BUILD_GL_TESTS)
MagnumShadersTestLib MagnumShadersTestLib
MagnumOpenGLTester MagnumOpenGLTester
FILES FILES
FlatTestFiles/defaults.tga
FlatTestFiles/colored3D.tga
MeshVisualizerTestFiles/defaults-wireframe2D.tga MeshVisualizerTestFiles/defaults-wireframe2D.tga
MeshVisualizerTestFiles/defaults-wireframe3D.tga MeshVisualizerTestFiles/defaults-wireframe3D.tga
MeshVisualizerTestFiles/wireframe2D.tga MeshVisualizerTestFiles/wireframe2D.tga

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

@ -69,7 +69,11 @@ struct MeshVisualizerGLTest: GL::OpenGLTester {
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
void constructWireframeGeometryShader2D(); void constructWireframeGeometryShader2D();
void constructGeometryShader3D(); void constructGeometryShader3D();
#endif
void construct2DNoFeatureEnabled();
void construct3DNoFeatureEnabled();
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
void construct3DGeometryShaderDisabledButNeeded(); void construct3DGeometryShaderDisabledButNeeded();
void construct3DConflictingBitangentInput(); void construct3DConflictingBitangentInput();
#endif #endif
@ -86,15 +90,11 @@ struct MeshVisualizerGLTest: GL::OpenGLTester {
void renderSetup(); void renderSetup();
void renderTeardown(); void renderTeardown();
void renderDefaults2D();
void renderDefaults3D();
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
void renderDefaultsWireframe2D(); void renderDefaultsWireframe2D();
void renderDefaultsWireframe3D(); void renderDefaultsWireframe3D();
void renderDefaultsTangentBitangentNormal(); void renderDefaultsTangentBitangentNormal();
#endif #endif
void render2D();
void render3D();
void renderWireframe2D(); void renderWireframe2D();
void renderWireframe3D(); void renderWireframe3D();
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
@ -131,7 +131,6 @@ constexpr struct {
const char* name; const char* name;
MeshVisualizer2D::Flags flags; MeshVisualizer2D::Flags flags;
} ConstructData2D[] { } ConstructData2D[] {
{"", {}},
{"wireframe w/o GS", MeshVisualizer2D::Flag::Wireframe|MeshVisualizer2D::Flag::NoGeometryShader}, {"wireframe w/o GS", MeshVisualizer2D::Flag::Wireframe|MeshVisualizer2D::Flag::NoGeometryShader},
}; };
@ -139,7 +138,6 @@ constexpr struct {
const char* name; const char* name;
MeshVisualizer3D::Flags flags; MeshVisualizer3D::Flags flags;
} ConstructData3D[] { } ConstructData3D[] {
{"", {}},
{"wireframe w/o GS", MeshVisualizer3D::Flag::Wireframe|MeshVisualizer3D::Flag::NoGeometryShader} {"wireframe w/o GS", MeshVisualizer3D::Flag::Wireframe|MeshVisualizer3D::Flag::NoGeometryShader}
}; };
@ -267,7 +265,8 @@ MeshVisualizerGLTest::MeshVisualizerGLTest() {
Containers::arraySize(ConstructGeometryShaderData3D)); Containers::arraySize(ConstructGeometryShaderData3D));
#endif #endif
addTests({ addTests({&MeshVisualizerGLTest::construct2DNoFeatureEnabled,
&MeshVisualizerGLTest::construct3DNoFeatureEnabled,
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
&MeshVisualizerGLTest::construct3DGeometryShaderDisabledButNeeded, &MeshVisualizerGLTest::construct3DGeometryShaderDisabledButNeeded,
&MeshVisualizerGLTest::construct3DConflictingBitangentInput, &MeshVisualizerGLTest::construct3DConflictingBitangentInput,
@ -283,17 +282,13 @@ MeshVisualizerGLTest::MeshVisualizerGLTest() {
#endif #endif
}); });
addTests({&MeshVisualizerGLTest::renderDefaults2D, #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
&MeshVisualizerGLTest::renderDefaults3D, addTests({&MeshVisualizerGLTest::renderDefaultsWireframe2D,
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
&MeshVisualizerGLTest::renderDefaultsWireframe2D,
&MeshVisualizerGLTest::renderDefaultsWireframe3D, &MeshVisualizerGLTest::renderDefaultsWireframe3D,
&MeshVisualizerGLTest::renderDefaultsTangentBitangentNormal, &MeshVisualizerGLTest::renderDefaultsTangentBitangentNormal},
#endif
&MeshVisualizerGLTest::render2D,
&MeshVisualizerGLTest::render3D},
&MeshVisualizerGLTest::renderSetup, &MeshVisualizerGLTest::renderSetup,
&MeshVisualizerGLTest::renderTeardown); &MeshVisualizerGLTest::renderTeardown);
#endif
addInstancedTests({&MeshVisualizerGLTest::renderWireframe2D}, addInstancedTests({&MeshVisualizerGLTest::renderWireframe2D},
Containers::arraySize(WireframeData2D), Containers::arraySize(WireframeData2D),
@ -429,6 +424,29 @@ void MeshVisualizerGLTest::constructGeometryShader3D() {
} }
#endif #endif
void MeshVisualizerGLTest::construct2DNoFeatureEnabled() {
std::ostringstream out;
Error redirectError{&out};
/* This isn't a feature flag */
MeshVisualizer2D{MeshVisualizer2D::Flag::NoGeometryShader};
CORRADE_COMPARE(out.str(),
"Shaders::MeshVisualizer2D: at least Flag::Wireframe has to be enabled\n");
}
void MeshVisualizerGLTest::construct3DNoFeatureEnabled() {
std::ostringstream out;
Error redirectError{&out};
/* This isn't a feature flag */
MeshVisualizer3D{MeshVisualizer3D::Flag::NoGeometryShader};
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
CORRADE_COMPARE(out.str(),
"Shaders::MeshVisualizer3D: at least one visualization feature has to be enabled\n");
#else
CORRADE_COMPARE(out.str(),
"Shaders::MeshVisualizer3D: at least Flag::Wireframe has to be enabled\n");
#endif
}
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
void MeshVisualizerGLTest::construct3DGeometryShaderDisabledButNeeded() { void MeshVisualizerGLTest::construct3DGeometryShaderDisabledButNeeded() {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
@ -505,12 +523,17 @@ void MeshVisualizerGLTest::setWireframeNotEnabled2D() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
MeshVisualizer2D shader; /* The constructor asserts for at least some feature being enabled (which
shader.setWireframeColor({}) is just wireframe in case of 2D), so fake it with a NoCreate */
MeshVisualizer2D shader{NoCreate};
shader
.setColor({})
.setWireframeColor({})
.setWireframeWidth({}) .setWireframeWidth({})
.setSmoothness({}); .setSmoothness({});
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"Shaders::MeshVisualizer::setColor(): the shader was not created with wireframe enabled\n"
"Shaders::MeshVisualizer::setWireframeColor(): the shader was not created with wireframe enabled\n" "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::setWireframeWidth(): the shader was not created with wireframe enabled\n"
"Shaders::MeshVisualizer2D::setSmoothness(): the shader was not created with wireframe enabled\n"); "Shaders::MeshVisualizer2D::setSmoothness(): the shader was not created with wireframe enabled\n");
@ -520,12 +543,18 @@ void MeshVisualizerGLTest::setWireframeNotEnabled3D() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
MeshVisualizer3D shader; /* The constructor asserts for at least some feature being enabled (which
shader.setWireframeColor({}) is just wireframe in case we're not on desktop or ES3.2), so fake it
with a NoCreate */
MeshVisualizer3D shader{NoCreate};
shader
.setColor({})
.setWireframeColor({})
.setWireframeWidth({}) .setWireframeWidth({})
.setSmoothness({}); .setSmoothness({});
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"Shaders::MeshVisualizer::setColor(): the shader was not created with wireframe enabled\n"
"Shaders::MeshVisualizer::setWireframeColor(): the shader was not created with wireframe enabled\n" "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::setWireframeWidth(): the shader was not created with wireframe enabled\n"
"Shaders::MeshVisualizer3D::setSmoothness(): the shader was not created with wireframe or TBN direction enabled\n"); "Shaders::MeshVisualizer3D::setSmoothness(): the shader was not created with wireframe or TBN direction enabled\n");
@ -533,20 +562,26 @@ void MeshVisualizerGLTest::setWireframeNotEnabled3D() {
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
void MeshVisualizerGLTest::setTangentBitangentNormalNotEnabled3D() { void MeshVisualizerGLTest::setTangentBitangentNormalNotEnabled3D() {
#ifndef MAGNUM_TARGET_GLES
if(!GL::Context::current().isExtensionSupported<GL::Extensions::ARB::geometry_shader4>())
CORRADE_SKIP(GL::Extensions::ARB::geometry_shader4::string() + std::string(" is not supported"));
#else
if(!GL::Context::current().isExtensionSupported<GL::Extensions::EXT::geometry_shader>())
CORRADE_SKIP(GL::Extensions::EXT::geometry_shader::string() + std::string(" is not supported"));
#endif
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
MeshVisualizer3D shader; MeshVisualizer3D shader{MeshVisualizer3D::Flag::Wireframe};
shader.setNormalMatrix({}) shader.setNormalMatrix({})
.setLineWidth({}) .setLineWidth({})
.setLineLength({}) .setLineLength({});
.setSmoothness({});
CORRADE_COMPARE(out.str(), CORRADE_COMPARE(out.str(),
"Shaders::MeshVisualizer3D::setNormalMatrix(): the shader was not created with TBN direction enabled\n" "Shaders::MeshVisualizer3D::setNormalMatrix(): the shader was not created with TBN direction enabled\n"
"Shaders::MeshVisualizer3D::setLineWidth(): the shader was not created with TBN direction enabled\n" "Shaders::MeshVisualizer3D::setLineWidth(): the shader was not created with TBN direction enabled\n"
"Shaders::MeshVisualizer3D::setLineLength(): the shader was not created with TBN direction enabled\n" "Shaders::MeshVisualizer3D::setLineLength(): the shader was not created with TBN direction enabled\n");
"Shaders::MeshVisualizer3D::setSmoothness(): the shader was not created with wireframe or TBN direction enabled\n");
} }
#endif #endif
@ -586,58 +621,6 @@ void MeshVisualizerGLTest::renderTeardown() {
_color = GL::Renderbuffer{NoCreate}; _color = GL::Renderbuffer{NoCreate};
} }
void MeshVisualizerGLTest::renderDefaults2D() {
GL::Mesh circle = MeshTools::compile(Primitives::circle2DSolid(32));
MeshVisualizer2D{}
.draw(circle);
MAGNUM_VERIFY_NO_GL_ERROR();
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) ||
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded))
CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found.");
#if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL))
/* SwiftShader has differently rasterized edges on four pixels */
const Float maxThreshold = 238.0f, meanThreshold = 0.298f;
#else
/* WebGL 1 doesn't have 8bit renderbuffer storage, so it's way worse */
const Float maxThreshold = 238.0f, meanThreshold = 0.298f;
#endif
CORRADE_COMPARE_WITH(
/* Dropping the alpha channel, as it's always 1.0 */
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {PixelFormat::RGBA8Unorm}).pixels<Color4ub>()),
Utility::Directory::join(_testDir, "FlatTestFiles/defaults.tga"),
(DebugTools::CompareImageToFile{_manager, maxThreshold, meanThreshold}));
}
void MeshVisualizerGLTest::renderDefaults3D() {
GL::Mesh sphere = MeshTools::compile(Primitives::uvSphereSolid(16, 32));
MeshVisualizer3D{}
.draw(sphere);
MAGNUM_VERIFY_NO_GL_ERROR();
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) ||
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded))
CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found.");
#if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL))
/* SwiftShader has differently rasterized edges on four pixels */
const Float maxThreshold = 238.0f, meanThreshold = 0.298f;
#else
/* WebGL 1 doesn't have 8bit renderbuffer storage, so it's way worse */
const Float maxThreshold = 238.0f, meanThreshold = 0.298f;
#endif
CORRADE_COMPARE_WITH(
/* Dropping the alpha channel, as it's always 1.0 */
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {PixelFormat::RGBA8Unorm}).pixels<Color4ub>()),
Utility::Directory::join(_testDir, "FlatTestFiles/defaults.tga"),
(DebugTools::CompareImageToFile{_manager, maxThreshold, meanThreshold}));
}
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
void MeshVisualizerGLTest::renderDefaultsWireframe2D() { void MeshVisualizerGLTest::renderDefaultsWireframe2D() {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
@ -772,67 +755,6 @@ void MeshVisualizerGLTest::renderDefaultsTangentBitangentNormal() {
} }
#endif #endif
void MeshVisualizerGLTest::render2D() {
GL::Mesh circle = MeshTools::compile(Primitives::circle2DSolid(32));
MeshVisualizer2D{}
.setColor(0x9999ff_rgbf)
.setTransformationProjectionMatrix(Matrix3::projection({2.1f, 2.1f}))
.draw(circle);
MAGNUM_VERIFY_NO_GL_ERROR();
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) ||
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded))
CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found.");
#if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL))
/* SwiftShader has differently rasterized edges on four pixels */
const Float maxThreshold = 170.0f, meanThreshold = 0.133f;
#else
/* WebGL 1 doesn't have 8bit renderbuffer storage, so it's way worse */
const Float maxThreshold = 170.0f, meanThreshold = 0.456f;
#endif
CORRADE_COMPARE_WITH(
/* Dropping the alpha channel, as it's always 1.0 */
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {PixelFormat::RGBA8Unorm}).pixels<Color4ub>()),
Utility::Directory::join(_testDir, "FlatTestFiles/colored2D.tga"),
(DebugTools::CompareImageToFile{_manager, maxThreshold, meanThreshold}));
}
void MeshVisualizerGLTest::render3D() {
GL::Mesh sphere = MeshTools::compile(Primitives::uvSphereSolid(16, 32));
MeshVisualizer3D{}
.setColor(0x9999ff_rgbf)
.setTransformationMatrix(
Matrix4::translation(Vector3::zAxis(-2.15f))*
Matrix4::rotationY(-15.0_degf)*
Matrix4::rotationX(15.0_degf))
.setProjectionMatrix(
Matrix4::perspectiveProjection(60.0_degf, 1.0f, 0.1f, 10.0f))
.draw(sphere);
MAGNUM_VERIFY_NO_GL_ERROR();
if(!(_manager.loadState("AnyImageImporter") & PluginManager::LoadState::Loaded) ||
!(_manager.loadState("TgaImporter") & PluginManager::LoadState::Loaded))
CORRADE_SKIP("AnyImageImporter / TgaImageImporter plugins not found.");
#if !(defined(MAGNUM_TARGET_GLES2) && defined(MAGNUM_TARGET_WEBGL))
/* SwiftShader has differently rasterized edges on four pixels */
const Float maxThreshold = 170.0f, meanThreshold = 0.133f;
#else
/* WebGL 1 doesn't have 8bit renderbuffer storage, so it's way worse */
const Float maxThreshold = 170.0f, meanThreshold = 0.456f;
#endif
CORRADE_COMPARE_WITH(
/* Dropping the alpha channel, as it's always 1.0 */
Containers::arrayCast<Color3ub>(_framebuffer.read(_framebuffer.viewport(), {PixelFormat::RGBA8Unorm}).pixels<Color4ub>()),
Utility::Directory::join(_testDir, "FlatTestFiles/colored3D.tga"),
(DebugTools::CompareImageToFile{_manager, maxThreshold, meanThreshold}));
}
void MeshVisualizerGLTest::renderWireframe2D() { void MeshVisualizerGLTest::renderWireframe2D() {
auto&& data = WireframeData2D[testCaseInstanceId()]; auto&& data = WireframeData2D[testCaseInstanceId()];
setTestCaseDescription(data.name); setTestCaseDescription(data.name);

Loading…
Cancel
Save