From f1fbafb81626efcb78c729e386647d3412891ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 3 May 2020 11:55:11 +0200 Subject: [PATCH] Trade: add a similar assert check for Phong textureMatrix as well. --- src/Magnum/Trade/PhongMaterialData.cpp | 2 ++ src/Magnum/Trade/PhongMaterialData.h | 16 ++++++++-------- src/Magnum/Trade/Test/MaterialDataTest.cpp | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Magnum/Trade/PhongMaterialData.cpp b/src/Magnum/Trade/PhongMaterialData.cpp index c5b64cf16..25fe471cb 100644 --- a/src/Magnum/Trade/PhongMaterialData.cpp +++ b/src/Magnum/Trade/PhongMaterialData.cpp @@ -34,6 +34,8 @@ using namespace Math::Literals; PhongMaterialData::PhongMaterialData(const Flags flags, const Color4& ambientColor, const UnsignedInt ambientTexture, const UnsignedInt ambientCoordinateSet, const Color4& diffuseColor, const UnsignedInt diffuseTexture, const UnsignedInt diffuseCoordinateSet, const Color4& specularColor, const UnsignedInt specularTexture, const UnsignedInt specularCoordinateSet, const UnsignedInt normalTexture, const UnsignedInt normalCoordinateSet, const Matrix3& textureMatrix, const MaterialAlphaMode alphaMode, const Float alphaMask, const Float shininess, const void* const importerState) noexcept: AbstractMaterialData{MaterialType::Phong, AbstractMaterialData::Flag(UnsignedShort(flags)), alphaMode, alphaMask, importerState}, _ambientColor{ambientColor}, _diffuseColor{diffuseColor}, _specularColor{specularColor}, _shininess{shininess} { CORRADE_ASSERT(!(flags & Flag::TextureTransformation) || (flags & (Flag::AmbientTexture|Flag::DiffuseTexture|Flag::SpecularTexture|Flag::NormalTexture)), "Trade::PhongMaterialData: texture transformation enabled but the material has no textures", ); + CORRADE_ASSERT((flags & Flag::TextureTransformation) || textureMatrix == Matrix3{}, + "PhongMaterialData::PhongMaterialData: non-default texture matrix requires Flag::TextureTransformation to be enabled", ); CORRADE_ASSERT((flags & Flag::TextureCoordinateSets) || (ambientCoordinateSet == 0 && diffuseCoordinateSet == 0 && specularCoordinateSet == 0 && normalCoordinateSet == 0), "PhongMaterialData::PhongMaterialData: non-zero texture coordinate sets require Flag::TextureCoordinateSets to be enabled", ); diff --git a/src/Magnum/Trade/PhongMaterialData.h b/src/Magnum/Trade/PhongMaterialData.h index 128fe1c40..2c889736d 100644 --- a/src/Magnum/Trade/PhongMaterialData.h +++ b/src/Magnum/Trade/PhongMaterialData.h @@ -110,8 +110,7 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { * doesn't have @ref Flag::SpecularTexture. * @param normalTexture Normal texture ID. Ignored if @p flags * doesn't have @ref Flag::NormalTexture. - * @param textureMatrix Texture coordinate transformation. Ignored - * if @p flags doesn't have @ref Flag::TextureTransformation. + * @param textureMatrix Texture coordinate transformation * @param alphaMode Alpha mode. Use * @ref MaterialAlphaMode::Opaque for a default value. * @param alphaMask Alpha mask value. Use @cpp 0.5f @ce for a @@ -122,7 +121,8 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { * @m_since_latest * * All `*CoordinateSet` accessors are implicitly zero with this - * constructor. + * constructor. If @p textureMatrix is not default-constructed, expects + * @ref Flag::TextureTransformation to be enabled as well. */ explicit PhongMaterialData(Flags flags, const Color4& ambientColor, UnsignedInt ambientTexture, const Color4& diffuseColor, UnsignedInt diffuseTexture, const Color4& specularColor, UnsignedInt specularTexture, UnsignedInt normalTexture, const Matrix3& textureMatrix, MaterialAlphaMode alphaMode, Float alphaMask, Float shininess, const void* importerState = nullptr) noexcept; @@ -155,9 +155,7 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { * doesn't have @ref Flag::NormalTexture. * @param normalCoordinateSet Normal texture coordinate set. Ignored * if @p flags doesn't have @ref Flag::NormalTexture. - * @param textureMatrix Texture coordinate transformation. - * Ignored if @p flags doesn't have - * @ref Flag::TextureTransformation. + * @param textureMatrix Texture coordinate transformation * @param alphaMode Alpha mode. Use * @ref MaterialAlphaMode::Opaque for a default value. * @param alphaMask Alpha mask value. Use @cpp 0.5f @ce for @@ -167,8 +165,10 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { * @param importerState Importer-specific state * @m_since_latest * - * If any `*CoordinateSet` is non-zero, expects - * @ref Flag::TextureCoordinateSets to be enabled as well. + * If @p textureMatrix is not default-constructed, expects + * @ref Flag::TextureTransformation to be enabled as well. If any + * `*CoordinateSet` is non-zero, expects @ref Flag::TextureCoordinateSets + * to be enabled as well. */ explicit PhongMaterialData(Flags flags, const Color4& ambientColor, UnsignedInt ambientTexture, UnsignedInt ambientCoordinateSet, const Color4& diffuseColor, UnsignedInt diffuseTexture, UnsignedInt diffuseCoordinateSet, const Color4& specularColor, UnsignedInt specularTexture, UnsignedInt specularCoordinateSet, UnsignedInt normalTexture, UnsignedInt normalCoordinateSet, const Matrix3& textureMatrix, MaterialAlphaMode alphaMode, Float alphaMask, Float shininess, const void* importerState = nullptr) noexcept; diff --git a/src/Magnum/Trade/Test/MaterialDataTest.cpp b/src/Magnum/Trade/Test/MaterialDataTest.cpp index 0919bb6d2..952b3f55d 100644 --- a/src/Magnum/Trade/Test/MaterialDataTest.cpp +++ b/src/Magnum/Trade/Test/MaterialDataTest.cpp @@ -40,6 +40,7 @@ class MaterialDataTest: public TestSuite::Tester { void constructPhongTexturedTextureTransform(); void constructPhongTexturedCoordinateSets(); void constructPhongTextureTransformNoTextures(); + void constructPhongNoTextureTransformationFlag(); void constructPhongNoTextureCoordinateSetsFlag(); void constructCopy(); void constructMovePhong(); @@ -61,6 +62,7 @@ MaterialDataTest::MaterialDataTest() { &MaterialDataTest::constructPhongTexturedTextureTransform, &MaterialDataTest::constructPhongTexturedCoordinateSets, &MaterialDataTest::constructPhongTextureTransformNoTextures, + &MaterialDataTest::constructPhongNoTextureTransformationFlag, &MaterialDataTest::constructPhongNoTextureCoordinateSetsFlag, &MaterialDataTest::constructCopy, &MaterialDataTest::constructMovePhong, @@ -204,6 +206,24 @@ void MaterialDataTest::constructPhongTextureTransformNoTextures() { "Trade::PhongMaterialData: texture transformation enabled but the material has no textures\n"); } +void MaterialDataTest::constructPhongNoTextureTransformationFlag() { + using namespace Math::Literals; + + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + std::ostringstream out; + Error redirectError{&out}; + PhongMaterialData a{{}, + {}, {}, + {}, {}, + {}, {}, {}, Matrix3::rotation(90.0_degf), + {}, 0.5f, 80.0f}; + CORRADE_COMPARE(out.str(), + "PhongMaterialData::PhongMaterialData: non-default texture matrix requires Flag::TextureTransformation to be enabled\n"); +} + void MaterialDataTest::constructPhongNoTextureCoordinateSetsFlag() { #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");