From 3ffcdf1865737ad1d0f4ef8821dc65225f8e7749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 16 Aug 2020 13:20:54 +0200 Subject: [PATCH] Trade: improve compat of deprecated PhongMaterialData::textureMatrix(). The new materials now commonly import separate per-texture matrices instead of a single one even if they're all the same because that makes the plugin implementation *much* simpler. However, existing code that assumes there's just one matrix would get broken because textureMatrix() would not return something else. By changing that to return a common matrix if present and falling back to the global one we can preserve the original behavior. --- src/Magnum/Trade/PhongMaterialData.cpp | 1 + src/Magnum/Trade/Test/MaterialDataTest.cpp | 32 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/Magnum/Trade/PhongMaterialData.cpp b/src/Magnum/Trade/PhongMaterialData.cpp index 044786256..1a8b9150e 100644 --- a/src/Magnum/Trade/PhongMaterialData.cpp +++ b/src/Magnum/Trade/PhongMaterialData.cpp @@ -331,6 +331,7 @@ Matrix3 PhongMaterialData::commonTextureMatrix() const { #ifdef MAGNUM_BUILD_DEPRECATED Matrix3 PhongMaterialData::textureMatrix() const { + if(hasCommonTextureTransformation()) return commonTextureMatrix(); return attributeOr(MaterialAttribute::TextureMatrix, Matrix3{}); } #endif diff --git a/src/Magnum/Trade/Test/MaterialDataTest.cpp b/src/Magnum/Trade/Test/MaterialDataTest.cpp index e469b782e..56cb0485b 100644 --- a/src/Magnum/Trade/Test/MaterialDataTest.cpp +++ b/src/Magnum/Trade/Test/MaterialDataTest.cpp @@ -4211,6 +4211,14 @@ void MaterialDataTest::phongAccessCommonTransformationCoordinatesNoTextures() { CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); CORRADE_COMPARE(a.commonTextureCoordinates(), 0); + #ifdef MAGNUM_BUILD_DEPRECATED + /* textureMatrix() should return the common matrix, if possible, and + fall back to the global one if not */ + CORRADE_IGNORE_DEPRECATED_PUSH + CORRADE_COMPARE(a.textureMatrix(), Matrix3{}); + CORRADE_IGNORE_DEPRECATED_POP + #endif + PhongMaterialData b{{}, { {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, {MaterialAttribute::TextureCoordinates, 7u} @@ -4219,6 +4227,14 @@ void MaterialDataTest::phongAccessCommonTransformationCoordinatesNoTextures() { CORRADE_VERIFY(b.hasCommonTextureCoordinates()); CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); CORRADE_COMPARE(b.commonTextureCoordinates(), 7); + + #ifdef MAGNUM_BUILD_DEPRECATED + /* textureMatrix() should return the common matrix, if possible, and + fall back to the global one if not */ + CORRADE_IGNORE_DEPRECATED_PUSH + CORRADE_COMPARE(b.textureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_IGNORE_DEPRECATED_POP + #endif } void MaterialDataTest::phongAccessCommonTransformationCoordinatesOneTexture() { @@ -4239,6 +4255,14 @@ void MaterialDataTest::phongAccessCommonTransformationCoordinatesOneTexture() { CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); CORRADE_VERIFY(data.hasCommonTextureCoordinates()); CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); + + #ifdef MAGNUM_BUILD_DEPRECATED + /* textureMatrix() should return the common matrix, if possible, and + fall back to the global one if not */ + CORRADE_IGNORE_DEPRECATED_PUSH + CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); + CORRADE_IGNORE_DEPRECATED_POP + #endif } void MaterialDataTest::phongAccessCommonTransformationCoordinatesOneDifferentTexture() { @@ -4261,6 +4285,14 @@ void MaterialDataTest::phongAccessCommonTransformationCoordinatesOneDifferentTex CORRADE_VERIFY(!data.hasCommonTextureTransformation()); CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); + + #ifdef MAGNUM_BUILD_DEPRECATED + /* textureMatrix() should return the common matrix, if possible, and + fall back to the global one if not */ + CORRADE_IGNORE_DEPRECATED_PUSH + CORRADE_COMPARE(data.textureMatrix(), Matrix3::translation({0.5f, 0.0f})); + CORRADE_IGNORE_DEPRECATED_POP + #endif } void MaterialDataTest::phongAccessNoCommonTransformationCoordinates() {