Skip to content

Commit

Permalink
Trade: improve compat of deprecated PhongMaterialData::textureMatrix().
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mosra committed Aug 16, 2020
1 parent 745745b commit b9493de
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Magnum/Trade/PhongMaterialData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions src/Magnum/Trade/Test/MaterialDataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down

0 comments on commit b9493de

Please sign in to comment.