diff --git a/doc/changelog.dox b/doc/changelog.dox index 2ae116cac..025d72034 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -155,7 +155,7 @@ See also: @subsubsection changelog-latest-changes-shaders Shaders library -- @ref Shaders::Phong::bindAmbientTexture(), +- @ref Shaders::Flat::bindTexture(), @ref Shaders::Phong::bindAmbientTexture(), @ref Shaders::Phong::bindDiffuseTexture(), @ref Shaders::Phong::bindSpecularTexture() and @ref Shaders::Phong::bindTextures() now assert that the shader was created @@ -254,7 +254,7 @@ See also: working to fail with an assertion. See the new @ref Math::Matrix3::rotationShear() and @ref Math::Matrix4::rotationShear() accessors for a possible solution. -- @ref Shaders::Phong::bindAmbientTexture(), +- @ref Shaders::Flat::bindTexture(), @ref Shaders::Phong::bindAmbientTexture(), @ref Shaders::Phong::bindDiffuseTexture(), @ref Shaders::Phong::bindSpecularTexture() and @ref Shaders::Phong::bindTextures() now assert that the shader was created diff --git a/src/Magnum/Shaders/CMakeLists.txt b/src/Magnum/Shaders/CMakeLists.txt index 6d96f27d4..7c30a098d 100644 --- a/src/Magnum/Shaders/CMakeLists.txt +++ b/src/Magnum/Shaders/CMakeLists.txt @@ -29,7 +29,6 @@ set_target_properties(MagnumShaders_RCS-dependencies PROPERTIES FOLDER "Magnum/S set(MagnumShaders_SRCS AbstractVector.cpp DistanceFieldVector.cpp - Flat.cpp MeshVisualizer.cpp Vector.cpp VertexColor.cpp @@ -37,6 +36,7 @@ set(MagnumShaders_SRCS ${MagnumShaders_RCS}) set(MagnumShaders_GracefulAssert_SRCS + Flat.cpp Phong.cpp) set(MagnumShaders_HEADERS diff --git a/src/Magnum/Shaders/Flat.cpp b/src/Magnum/Shaders/Flat.cpp index beb3bd947..936ea31f4 100644 --- a/src/Magnum/Shaders/Flat.cpp +++ b/src/Magnum/Shaders/Flat.cpp @@ -106,7 +106,9 @@ template Flat::Flat(const Flags flags): _fla } template Flat& Flat::bindTexture(GL::Texture2D& texture) { - if(_flags & Flag::Textured) texture.bind(TextureLayer); + CORRADE_ASSERT(_flags & Flag::Textured, + "Shaders::Flat::bindTexture(): the shader was not created with texturing enabled", *this); + texture.bind(TextureLayer); return *this; } diff --git a/src/Magnum/Shaders/Flat.h b/src/Magnum/Shaders/Flat.h index 8be0055fa..a08c6018d 100644 --- a/src/Magnum/Shaders/Flat.h +++ b/src/Magnum/Shaders/Flat.h @@ -186,7 +186,8 @@ template class MAGNUM_SHADERS_EXPORT Flat: public GL::Ab * @brief Bind texture * @return Reference to self (for method chaining) * - * Has effect only if @ref Flag::Textured is set. + * Expects that the shader was created with @ref Flag::Textured + * enabled. * @see @ref setColor() */ Flat& bindTexture(GL::Texture2D& texture); diff --git a/src/Magnum/Shaders/Test/CMakeLists.txt b/src/Magnum/Shaders/Test/CMakeLists.txt index a0a604500..23732dd55 100644 --- a/src/Magnum/Shaders/Test/CMakeLists.txt +++ b/src/Magnum/Shaders/Test/CMakeLists.txt @@ -41,7 +41,7 @@ set_target_properties( if(BUILD_GL_TESTS) corrade_add_test(ShadersDistanceFieldVectorGLTest DistanceFieldVectorGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester) - corrade_add_test(ShadersFlatGLTest FlatGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester) + corrade_add_test(ShadersFlatGLTest FlatGLTest.cpp LIBRARIES MagnumShadersTestLib MagnumOpenGLTester) corrade_add_test(ShadersMeshVisualizerGLTest MeshVisualizerGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester) corrade_add_test(ShadersPhongGLTest PhongGLTest.cpp LIBRARIES MagnumShadersTestLib MagnumOpenGLTester) corrade_add_test(ShadersVectorGLTest VectorGLTest.cpp LIBRARIES MagnumShaders MagnumOpenGLTester) diff --git a/src/Magnum/Shaders/Test/FlatGLTest.cpp b/src/Magnum/Shaders/Test/FlatGLTest.cpp index c9fd62ae3..585779dd3 100644 --- a/src/Magnum/Shaders/Test/FlatGLTest.cpp +++ b/src/Magnum/Shaders/Test/FlatGLTest.cpp @@ -23,8 +23,13 @@ DEALINGS IN THE SOFTWARE. */ +#include #include +#include "Magnum/ImageView.h" +#include "Magnum/PixelFormat.h" +#include "Magnum/GL/Texture.h" +#include "Magnum/GL/TextureFormat.h" #include "Magnum/GL/OpenGLTester.h" #include "Magnum/Shaders/Flat.h" @@ -36,6 +41,9 @@ struct FlatGLTest: GL::OpenGLTester { template void construct(); template void constructMove(); + + template void bindTexture(); + template void bindTextureNotEnabled(); }; namespace { @@ -58,7 +66,12 @@ FlatGLTest::FlatGLTest() { addTests({ &FlatGLTest::constructMove<2>, - &FlatGLTest::constructMove<3>}); + &FlatGLTest::constructMove<3>, + + &FlatGLTest::bindTexture<2>, + &FlatGLTest::bindTexture<3>, + &FlatGLTest::bindTextureNotEnabled<2>, + &FlatGLTest::bindTextureNotEnabled<3>}); } template void FlatGLTest::construct() { @@ -96,6 +109,40 @@ template void FlatGLTest::constructMove() { CORRADE_VERIFY(!b.id()); } +template void FlatGLTest::bindTexture() { + setTestCaseName(Utility::formatString("bindTexture<{}>", dimensions)); + + char data[4]; + + GL::Texture2D texture; + texture + .setMinificationFilter(SamplerFilter::Linear, SamplerMipmap::Linear) + .setMagnificationFilter(SamplerFilter::Linear) + .setWrapping(SamplerWrapping::ClampToEdge) + .setImage(0, GL::TextureFormat::RGBA, ImageView2D{PixelFormat::RGBA8Unorm, {1, 1}, data}); + + MAGNUM_VERIFY_NO_GL_ERROR(); + + /* Test just that no assertion is fired */ + Flat shader{Flat::Flag::Textured}; + shader.bindTexture(texture); + + MAGNUM_VERIFY_NO_GL_ERROR(); +} + +template void FlatGLTest::bindTextureNotEnabled() { + setTestCaseName(Utility::formatString("bindTextureNotEnabled<{}>", dimensions)); + + std::ostringstream out; + Error redirectError{&out}; + + GL::Texture2D texture; + Flat shader; + shader.bindTexture(texture); + + CORRADE_COMPARE(out.str(), "Shaders::Flat::bindTexture(): the shader was not created with texturing enabled\n"); +} + }}} CORRADE_TEST_MAIN(Magnum::Shaders::Test::FlatGLTest)