diff --git a/src/Magnum/Trade/Test/CMakeLists.txt b/src/Magnum/Trade/Test/CMakeLists.txt index cd88f4a55..adcbe1ddd 100644 --- a/src/Magnum/Trade/Test/CMakeLists.txt +++ b/src/Magnum/Trade/Test/CMakeLists.txt @@ -49,12 +49,17 @@ target_include_directories(TradeAbstractSceneConverterTest PRIVATE ${CMAKE_CURRE corrade_add_test(TradeAnimationDataTest AnimationDataTest.cpp LIBRARIES MagnumTradeTestLib) corrade_add_test(TradeCameraDataTest CameraDataTest.cpp LIBRARIES MagnumTradeTestLib) corrade_add_test(TradeDataTest DataTest.cpp LIBRARIES MagnumTrade) +corrade_add_test(TradeFlatMaterialDataTest FlatMaterialDataTest.cpp LIBRARIES MagnumTradeTestLib) corrade_add_test(TradeImageDataTest ImageDataTest.cpp LIBRARIES MagnumTradeTestLib) corrade_add_test(TradeLightDataTest LightDataTest.cpp LIBRARIES MagnumTradeTestLib) corrade_add_test(TradeMaterialDataTest MaterialDataTest.cpp LIBRARIES MagnumTradeTestLib) corrade_add_test(TradeMeshDataTest MeshDataTest.cpp LIBRARIES MagnumTradeTestLib) corrade_add_test(TradeObjectData2DTest ObjectData2DTest.cpp LIBRARIES MagnumTradeTestLib) corrade_add_test(TradeObjectData3DTest ObjectData3DTest.cpp LIBRARIES MagnumTradeTestLib) +corrade_add_test(TradePbrClearCoatMaterialDataTest PbrClearCoatMaterialDataTest.cpp LIBRARIES MagnumTradeTestLib) +corrade_add_test(TradePbrMetallicRoughnessMaterialDataTest PbrMetallicRoughnessMaterialDataTest.cpp LIBRARIES MagnumTradeTestLib) +corrade_add_test(TradePbrSpecularGlossinessMaterialDataTest PbrSpecularGlossinessMaterialDataTest.cpp LIBRARIES MagnumTradeTestLib) +corrade_add_test(TradePhongMaterialDataTest PhongMaterialDataTest.cpp LIBRARIES MagnumTradeTestLib) corrade_add_test(TradeSceneDataTest SceneDataTest.cpp LIBRARIES MagnumTrade) corrade_add_test(TradeSkinDataTest SkinDataTest.cpp LIBRARIES MagnumTradeTestLib) corrade_add_test(TradeTextureDataTest TextureDataTest.cpp LIBRARIES MagnumTrade) @@ -71,11 +76,16 @@ set_target_properties( TradeAbstractSceneConverterTest TradeAnimationDataTest TradeCameraDataTest + TradeFlatMaterialDataTest TradeImageDataTest TradeLightDataTest TradeMaterialDataTest TradeObjectData2DTest TradeObjectData3DTest + TradePbrClearCoatMaterialDataTest + TradePbrMetallicRoughnessMaterialDataTest + TradePbrSpecularGlossinessMaterialDataTest + TradePhongMaterialDataTest TradeSceneDataTest TradeTextureDataTest PROPERTIES FOLDER "Magnum/Trade/Test") diff --git a/src/Magnum/Trade/Test/FlatMaterialDataTest.cpp b/src/Magnum/Trade/Test/FlatMaterialDataTest.cpp new file mode 100644 index 000000000..d1fe604aa --- /dev/null +++ b/src/Magnum/Trade/Test/FlatMaterialDataTest.cpp @@ -0,0 +1,266 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, + 2020 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include +#include + +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" +#include "Magnum/Trade/FlatMaterialData.h" + +namespace Magnum { namespace Trade { namespace Test { namespace { + +class FlatMaterialDataTest: public TestSuite::Tester { + public: + explicit FlatMaterialDataTest(); + + void baseColor(); + void diffuseColor(); + void defaults(); + void texturedBaseColor(); + void texturedDiffuseColor(); + void texturedDefaults(); + void texturedBaseColorSingleMatrixCoordinates(); + void texturedDiffuseColorSingleMatrixCoordinates(); + void texturedMismatchedMatrixCoordinates(); + void invalidTextures(); +}; + +FlatMaterialDataTest::FlatMaterialDataTest() { + addTests({&FlatMaterialDataTest::baseColor, + &FlatMaterialDataTest::diffuseColor, + &FlatMaterialDataTest::defaults, + &FlatMaterialDataTest::texturedBaseColor, + &FlatMaterialDataTest::texturedDiffuseColor, + &FlatMaterialDataTest::texturedDefaults, + &FlatMaterialDataTest::texturedBaseColorSingleMatrixCoordinates, + &FlatMaterialDataTest::texturedDiffuseColorSingleMatrixCoordinates, + &FlatMaterialDataTest::texturedMismatchedMatrixCoordinates, + &FlatMaterialDataTest::invalidTextures}); +} + +using namespace Math::Literals; + +void FlatMaterialDataTest::baseColor() { + MaterialData base{MaterialType::Flat, { + {MaterialAttribute::BaseColor, 0xccffbbff_rgbaf}, + {MaterialAttribute::DiffuseColor, 0x33556600_rgbaf}, /* Ignored */ + }}; + + CORRADE_COMPARE(base.types(), MaterialType::Flat); + const auto& data = base.as(); + + CORRADE_VERIFY(!data.hasTexture()); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); +} + +void FlatMaterialDataTest::diffuseColor() { + MaterialData base{MaterialType::Flat, { + {MaterialAttribute::DiffuseColor, 0xccffbbff_rgbaf}, + }}; + + CORRADE_COMPARE(base.types(), MaterialType::Flat); + const auto& data = base.as(); + + CORRADE_VERIFY(!data.hasTexture()); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); +} + +void FlatMaterialDataTest::defaults() { + MaterialData base{{}, {}}; + + CORRADE_COMPARE(base.types(), MaterialTypes{}); + /* Casting is fine even if the type doesn't include Flat */ + const auto& data = base.as(); + + CORRADE_VERIFY(!data.hasTexture()); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.color(), 0xffffff_rgbf); +} + +void FlatMaterialDataTest::texturedBaseColor() { + FlatMaterialData data{{}, { + {MaterialAttribute::BaseColor, 0xccffbbff_rgbaf}, + {MaterialAttribute::BaseColorTexture, 5u}, + {MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::BaseColorTextureCoordinates, 2u}, + + /* All this is ignored */ + {MaterialAttribute::DiffuseColor, 0x33556600_rgbaf}, + {MaterialAttribute::DiffuseTexture, 6u}, + {MaterialAttribute::DiffuseTextureMatrix, Matrix3::translation({0.5f, 1.0f})}, + {MaterialAttribute::DiffuseTextureCoordinates, 3u} + }}; + + CORRADE_VERIFY(data.hasTexture()); + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); + CORRADE_COMPARE(data.texture(), 5); + CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); + CORRADE_COMPARE(data.textureCoordinates(), 2); +} + +void FlatMaterialDataTest::texturedDiffuseColor() { + FlatMaterialData data{{}, { + {MaterialAttribute::DiffuseColor, 0xccffbbff_rgbaf}, + {MaterialAttribute::DiffuseTexture, 5u}, + {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::DiffuseTextureCoordinates, 2u}, + + /* Ignored, as we have a diffuse texture */ + {MaterialAttribute::BaseColor, 0x33556600_rgbaf} + }}; + + CORRADE_VERIFY(data.hasTexture()); + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); + CORRADE_COMPARE(data.texture(), 5); + CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); + CORRADE_COMPARE(data.textureCoordinates(), 2); +} + +void FlatMaterialDataTest::texturedDefaults() { + FlatMaterialData data{{}, { + {MaterialAttribute::DiffuseTexture, 5u} + }}; + + CORRADE_VERIFY(data.hasTexture()); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.color(), 0xffffff_rgbf); + CORRADE_COMPARE(data.texture(), 5); + CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.textureCoordinates(), 0); +} + +void FlatMaterialDataTest::texturedBaseColorSingleMatrixCoordinates() { + FlatMaterialData data{{}, { + {MaterialAttribute::BaseColor, 0xccffbbff_rgbaf}, + {MaterialAttribute::BaseColorTexture, 5u}, + {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::TextureCoordinates, 2u}, + + /* This is ignored because it doesn't match the texture */ + {MaterialAttribute::DiffuseTextureMatrix, Matrix3::translation({0.5f, 1.0f})}, + {MaterialAttribute::DiffuseTextureCoordinates, 3u} + }}; + + CORRADE_VERIFY(data.hasTexture()); + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); + CORRADE_COMPARE(data.texture(), 5); + CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); + CORRADE_COMPARE(data.textureCoordinates(), 2); +} + +void FlatMaterialDataTest::texturedDiffuseColorSingleMatrixCoordinates() { + FlatMaterialData data{{}, { + {MaterialAttribute::DiffuseColor, 0xccffbbff_rgbaf}, + {MaterialAttribute::DiffuseTexture, 5u}, + {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::TextureCoordinates, 2u}, + + /* This is ignored because it doesn't match the texture */ + {MaterialAttribute::BaseColorTextureMatrix, Matrix3::translation({0.5f, 1.0f})}, + {MaterialAttribute::BaseColorTextureCoordinates, 3u} + }}; + + CORRADE_VERIFY(data.hasTexture()); + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); + CORRADE_COMPARE(data.texture(), 5); + CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); + CORRADE_COMPARE(data.textureCoordinates(), 2); +} + +void FlatMaterialDataTest::texturedMismatchedMatrixCoordinates() { + { + FlatMaterialData data{{}, { + {MaterialAttribute::BaseColorTexture, 5u}, + + /* This is ignored because it doesn't match the texture */ + {MaterialAttribute::DiffuseColor, 0x33556600_rgbaf}, + {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::DiffuseTextureCoordinates, 2u}, + }}; + + CORRADE_VERIFY(data.hasTexture()); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.color(), 0xffffff_rgbf); + CORRADE_COMPARE(data.texture(), 5); + CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.textureCoordinates(), 0); + } { + FlatMaterialData data{{}, { + {MaterialAttribute::DiffuseTexture, 5u}, + + /* This is ignored because it doesn't match the texture */ + {MaterialAttribute::BaseColor, 0x33556600_rgbaf}, + {MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::BaseColorTextureCoordinates, 2u}, + }}; + + CORRADE_VERIFY(data.hasTexture()); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.color(), 0xffffff_rgbf); + CORRADE_COMPARE(data.texture(), 5); + CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.textureCoordinates(), 0); + } +} + +void FlatMaterialDataTest::invalidTextures() { + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + FlatMaterialData data{{}, {}}; + + std::ostringstream out; + Error redirectError{&out}; + data.texture(); + data.textureMatrix(); + data.textureCoordinates(); + CORRADE_COMPARE(out.str(), + "Trade::FlatMaterialData::texture(): the material doesn't have a texture\n" + "Trade::FlatMaterialData::textureMatrix(): the material doesn't have a texture\n" + "Trade::FlatMaterialData::textureCoordinates(): the material doesn't have a texture\n"); +} + +}}}} + +CORRADE_TEST_MAIN(Magnum::Trade::Test::FlatMaterialDataTest) diff --git a/src/Magnum/Trade/Test/MaterialDataTest.cpp b/src/Magnum/Trade/Test/MaterialDataTest.cpp index b5a8c0522..392b7352c 100644 --- a/src/Magnum/Trade/Test/MaterialDataTest.cpp +++ b/src/Magnum/Trade/Test/MaterialDataTest.cpp @@ -34,10 +34,10 @@ #include "Magnum/Math/Color.h" #include "Magnum/Math/Matrix3.h" -#include "Magnum/Trade/FlatMaterialData.h" #include "Magnum/Trade/MaterialData.h" -#include "Magnum/Trade/PbrClearCoatMaterialData.h" -#include "Magnum/Trade/PbrMetallicRoughnessMaterialData.h" + +#include "Magnum/Trade/MaterialLayerData.h" +/* used by as(), asRvalue() */ #include "Magnum/Trade/PbrSpecularGlossinessMaterialData.h" #include "Magnum/Trade/PhongMaterialData.h" @@ -139,83 +139,8 @@ class MaterialDataTest: public TestSuite::Tester { void releaseAttributes(); void releaseLayers(); - #ifdef MAGNUM_BUILD_DEPRECATED - void constructPhongDeprecated(); - void constructPhongDeprecatedTextured(); - void constructPhongDeprecatedTexturedTextureTransform(); - void constructPhongDeprecatedTexturedCoordinates(); - void constructPhongDeprecatedTextureTransformNoTextures(); - void constructPhongDeprecatedNoTextureTransformationFlag(); - void constructPhongDeprecatedNoTextureCoordinatesFlag(); - #endif - - void pbrMetallicRoughnessAccess(); - void pbrMetallicRoughnessAccessDefaults(); - void pbrMetallicRoughnessAccessTextured(); - void pbrMetallicRoughnessAccessTexturedDefaults(); - void pbrMetallicRoughnessAccessTexturedImplicitPackedMetallicRoughness(); - void pbrMetallicRoughnessAccessTexturedExplicitPackedMetallicRoughness(); - void pbrMetallicRoughnessAccessTexturedExplicitPackedRoughnessMetallicOcclusion(); - void pbrMetallicRoughnessAccessTexturedExplicitPackedOcclusionRoughnessMetallic(); - void pbrMetallicRoughnessAccessTexturedExplicitPackedNormalRoughnessMetallic(); - void pbrMetallicRoughnessAccessTexturedSingleMatrixCoordinates(); - void pbrMetallicRoughnessAccessInvalidTextures(); - void pbrMetallicRoughnessAccessCommonTransformationCoordinatesNoTextures(); - void pbrMetallicRoughnessAccessCommonTransformationCoordinatesOneTexture(); - void pbrMetallicRoughnessAccessCommonTransformationCoordinatesOneDifferentTexture(); - void pbrMetallicRoughnessAccessNoCommonTransformationCoordinates(); - - void pbrSpecularGlossinessAccess(); - void pbrSpecularGlossinessAccessDefaults(); - void pbrSpecularGlossinessAccessTextured(); - void pbrSpecularGlossinessAccessTexturedDefaults(); - void pbrSpecularGlossinessAccessTexturedImplicitPackedSpecularGlossiness(); - void pbrSpecularGlossinessAccessTexturedExplicitPackedSpecularGlossiness(); - void pbrSpecularGlossinessAccessTexturedSingleMatrixCoordinates(); - void pbrSpecularGlossinessAccessInvalidTextures(); - void pbrSpecularGlossinessAccessCommonTransformationCoordinatesNoTextures(); - void pbrSpecularGlossinessAccessCommonTransformationCoordinatesOneTexture(); - void pbrSpecularGlossinessAccessCommonTransformationCoordinatesOneDifferentTexture(); - void pbrSpecularGlossinessAccessNoCommonTransformationCoordinates(); - - void phongAccess(); - void phongAccessDefaults(); - void phongAccessTextured(); - void phongAccessTexturedDefaults(); - void phongAccessTexturedSingleMatrixCoordinates(); - void phongAccessTexturedImplicitPackedSpecularGlossiness(); - void phongAccessInvalidTextures(); - void phongAccessCommonTransformationCoordinatesNoTextures(); - void phongAccessCommonTransformationCoordinatesOneTexture(); - void phongAccessCommonTransformationCoordinatesOneDifferentTexture(); - void phongAccessNoCommonTransformationCoordinates(); - - void flatAccessBaseColor(); - void flatAccessDiffuseColor(); - void flatAccessDefaults(); - void flatAccessTexturedBaseColor(); - void flatAccessTexturedDiffuseColor(); - void flatAccessTexturedDefaults(); - void flatAccessTexturedBaseColorSingleMatrixCoordinates(); - void flatAccessTexturedDiffuseColorSingleMatrixCoordinates(); - void flatAccessTexturedMismatchedMatrixCoordinates(); - void flatAccessInvalidTextures(); - void templateLayerAccess(); - void pbrClearCoatAccess(); - void pbrClearCoatAccessDefaults(); - void pbrClearCoatAccessTextured(); - void pbrClearCoatAccessTexturedDefaults(); - void pbrClearCoatAccessTexturedExplicitPackedLayerFactorRoughness(); - void pbrClearCoatAccessTexturedSingleMatrixCoordinates(); - void pbrClearCoatAccessTexturedBaseMaterialMatrixCoordinates(); - void pbrClearCoatAccessInvalidTextures(); - void pbrClearCoatAccessCommonTransformationCoordinatesNoTextures(); - void pbrClearCoatAccessCommonTransformationCoordinatesOneTexture(); - void pbrClearCoatAccessCommonTransformationCoordinatesOneDifferentTexture(); - void pbrClearCoatAccessNoCommonTransformationCoordinates(); - void debugLayer(); void debugAttribute(); void debugTextureSwizzle(); @@ -228,42 +153,6 @@ class MaterialDataTest: public TestSuite::Tester { void debugFlags(); #endif void debugAlphaMode(); - - #ifdef MAGNUM_BUILD_DEPRECATED - void debugPhongFlag(); - void debugPhongFlags(); - #endif -}; - -const Containers::StringView PbrMetallicRoughnessTextureData[] { - "BaseColorTexture", - "MetalnessTexture", - "RoughnessTexture", - "NormalTexture", - "OcclusionTexture", - "EmissiveTexture" -}; - -const Containers::StringView PbrSpecularGlossinessTextureData[] { - "DiffuseTexture", - "SpecularTexture", - "GlossinessTexture", - "NormalTexture", - "OcclusionTexture", - "EmissiveTexture" -}; - -const Containers::StringView PhongTextureData[] { - "AmbientTexture", - "DiffuseTexture", - "SpecularTexture", - "NormalTexture" -}; - -const Containers::StringView PbrClearCoatTextureData[] { - "LayerFactorTexture", - "RoughnessTexture", - "NormalTexture" }; MaterialDataTest::MaterialDataTest() { @@ -386,99 +275,8 @@ MaterialDataTest::MaterialDataTest() { &MaterialDataTest::releaseAttributes, &MaterialDataTest::releaseLayers, - #ifdef MAGNUM_BUILD_DEPRECATED - &MaterialDataTest::constructPhongDeprecated, - &MaterialDataTest::constructPhongDeprecatedTextured, - &MaterialDataTest::constructPhongDeprecatedTexturedTextureTransform, - &MaterialDataTest::constructPhongDeprecatedTexturedCoordinates, - &MaterialDataTest::constructPhongDeprecatedTextureTransformNoTextures, - &MaterialDataTest::constructPhongDeprecatedNoTextureTransformationFlag, - &MaterialDataTest::constructPhongDeprecatedNoTextureCoordinatesFlag, - #endif - - &MaterialDataTest::pbrMetallicRoughnessAccess, - &MaterialDataTest::pbrMetallicRoughnessAccessDefaults, - &MaterialDataTest::pbrMetallicRoughnessAccessTextured, - &MaterialDataTest::pbrMetallicRoughnessAccessTexturedDefaults, - &MaterialDataTest::pbrMetallicRoughnessAccessTexturedImplicitPackedMetallicRoughness, - &MaterialDataTest::pbrMetallicRoughnessAccessTexturedExplicitPackedMetallicRoughness, - &MaterialDataTest::pbrMetallicRoughnessAccessTexturedExplicitPackedRoughnessMetallicOcclusion, - &MaterialDataTest::pbrMetallicRoughnessAccessTexturedExplicitPackedOcclusionRoughnessMetallic, - &MaterialDataTest::pbrMetallicRoughnessAccessTexturedExplicitPackedNormalRoughnessMetallic, - &MaterialDataTest::pbrMetallicRoughnessAccessTexturedSingleMatrixCoordinates, - &MaterialDataTest::pbrMetallicRoughnessAccessInvalidTextures, - &MaterialDataTest::pbrMetallicRoughnessAccessCommonTransformationCoordinatesNoTextures}); - - addInstancedTests({ - &MaterialDataTest::pbrMetallicRoughnessAccessCommonTransformationCoordinatesOneTexture, - &MaterialDataTest::pbrMetallicRoughnessAccessCommonTransformationCoordinatesOneDifferentTexture}, - Containers::arraySize(PbrMetallicRoughnessTextureData)); - - addTests({&MaterialDataTest::pbrMetallicRoughnessAccessNoCommonTransformationCoordinates, - - &MaterialDataTest::pbrSpecularGlossinessAccess, - &MaterialDataTest::pbrSpecularGlossinessAccessDefaults, - &MaterialDataTest::pbrSpecularGlossinessAccessTextured, - &MaterialDataTest::pbrSpecularGlossinessAccessTexturedDefaults, - &MaterialDataTest::pbrSpecularGlossinessAccessTexturedImplicitPackedSpecularGlossiness, - &MaterialDataTest::pbrSpecularGlossinessAccessTexturedExplicitPackedSpecularGlossiness, - &MaterialDataTest::pbrSpecularGlossinessAccessTexturedSingleMatrixCoordinates, - &MaterialDataTest::pbrSpecularGlossinessAccessInvalidTextures, - &MaterialDataTest::pbrSpecularGlossinessAccessCommonTransformationCoordinatesNoTextures}); - - addInstancedTests({ - &MaterialDataTest::pbrSpecularGlossinessAccessCommonTransformationCoordinatesOneTexture, - &MaterialDataTest::pbrSpecularGlossinessAccessCommonTransformationCoordinatesOneDifferentTexture}, - Containers::arraySize(PbrSpecularGlossinessTextureData)); - - addTests({&MaterialDataTest::pbrSpecularGlossinessAccessNoCommonTransformationCoordinates, - - &MaterialDataTest::phongAccess, - &MaterialDataTest::phongAccessDefaults, - &MaterialDataTest::phongAccessTextured, - &MaterialDataTest::phongAccessTexturedDefaults, - &MaterialDataTest::phongAccessTexturedSingleMatrixCoordinates, - &MaterialDataTest::phongAccessTexturedImplicitPackedSpecularGlossiness, - &MaterialDataTest::phongAccessInvalidTextures, - &MaterialDataTest::phongAccessCommonTransformationCoordinatesNoTextures}); - - addInstancedTests({ - &MaterialDataTest::phongAccessCommonTransformationCoordinatesOneTexture, - &MaterialDataTest::phongAccessCommonTransformationCoordinatesOneDifferentTexture}, - Containers::arraySize(PhongTextureData)); - - addTests({&MaterialDataTest::phongAccessNoCommonTransformationCoordinates, - - &MaterialDataTest::flatAccessBaseColor, - &MaterialDataTest::flatAccessDiffuseColor, - &MaterialDataTest::flatAccessDefaults, - &MaterialDataTest::flatAccessTexturedBaseColor, - &MaterialDataTest::flatAccessTexturedDiffuseColor, - &MaterialDataTest::flatAccessTexturedDefaults, - &MaterialDataTest::flatAccessTexturedBaseColorSingleMatrixCoordinates, - &MaterialDataTest::flatAccessTexturedDiffuseColorSingleMatrixCoordinates, - &MaterialDataTest::flatAccessTexturedMismatchedMatrixCoordinates, - &MaterialDataTest::flatAccessInvalidTextures, - &MaterialDataTest::templateLayerAccess, - &MaterialDataTest::pbrClearCoatAccess, - &MaterialDataTest::pbrClearCoatAccessDefaults, - &MaterialDataTest::pbrClearCoatAccessTextured, - &MaterialDataTest::pbrClearCoatAccessTexturedDefaults, - &MaterialDataTest::pbrClearCoatAccessTexturedExplicitPackedLayerFactorRoughness, - &MaterialDataTest::pbrClearCoatAccessTexturedSingleMatrixCoordinates, - &MaterialDataTest::pbrClearCoatAccessTexturedBaseMaterialMatrixCoordinates, - &MaterialDataTest::pbrClearCoatAccessInvalidTextures, - &MaterialDataTest::pbrClearCoatAccessCommonTransformationCoordinatesNoTextures}); - - addInstancedTests({ - &MaterialDataTest::pbrClearCoatAccessCommonTransformationCoordinatesOneTexture, - &MaterialDataTest::pbrClearCoatAccessCommonTransformationCoordinatesOneDifferentTexture}, - Containers::arraySize(PbrClearCoatTextureData)); - - addTests({&MaterialDataTest::pbrClearCoatAccessNoCommonTransformationCoordinates, - &MaterialDataTest::debugLayer, &MaterialDataTest::debugAttribute, &MaterialDataTest::debugTextureSwizzle, @@ -490,13 +288,7 @@ MaterialDataTest::MaterialDataTest() { &MaterialDataTest::debugFlag, &MaterialDataTest::debugFlags, #endif - &MaterialDataTest::debugAlphaMode, - - #ifdef MAGNUM_BUILD_DEPRECATED - &MaterialDataTest::debugPhongFlag, - &MaterialDataTest::debugPhongFlags - #endif - }); + &MaterialDataTest::debugAlphaMode}); } using namespace Containers::Literals; @@ -2585,1940 +2377,6 @@ void MaterialDataTest::releaseLayers() { CORRADE_COMPARE(data.attributeCount(), 2); } -#ifdef MAGNUM_BUILD_DEPRECATED -void MaterialDataTest::constructPhongDeprecated() { - const int a{}; - CORRADE_IGNORE_DEPRECATED_PUSH - PhongMaterialData data{PhongMaterialData::Flag::DoubleSided, - 0xccffbb_rgbf, {}, - 0xebefbf_rgbf, {}, - 0xacabad_rgbf, {}, {}, {}, - MaterialAlphaMode::Mask, 0.3f, 80.0f, &a}; - CORRADE_IGNORE_DEPRECATED_POP - - CORRADE_COMPARE(data.types(), MaterialType::Phong); - CORRADE_IGNORE_DEPRECATED_PUSH - CORRADE_COMPARE(data.type(), MaterialType::Phong); - CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::DoubleSided); - CORRADE_IGNORE_DEPRECATED_POP - CORRADE_COMPARE(data.ambientColor(), 0xccffbb_rgbf); - CORRADE_COMPARE(data.diffuseColor(), 0xebefbf_rgbf); - CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); - CORRADE_IGNORE_DEPRECATED_PUSH - CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); - CORRADE_IGNORE_DEPRECATED_POP - CORRADE_COMPARE(data.alphaMode(), MaterialAlphaMode::Mask); - CORRADE_COMPARE(data.alphaMask(), 0.3f); - CORRADE_COMPARE(data.shininess(), 80.0f); - CORRADE_COMPARE(data.importerState(), &a); -} - -void MaterialDataTest::constructPhongDeprecatedTextured() { - const int a{}; - CORRADE_IGNORE_DEPRECATED_PUSH - PhongMaterialData data{ - PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture, - 0x111111_rgbf, 42, - 0xeebbff_rgbf, {}, - 0xacabad_rgbf, 17, {}, {}, - MaterialAlphaMode::Blend, 0.37f, 96.0f, &a}; - CORRADE_IGNORE_DEPRECATED_POP - - CORRADE_COMPARE(data.types(), MaterialType::Phong); - CORRADE_IGNORE_DEPRECATED_PUSH - CORRADE_COMPARE(data.type(), MaterialType::Phong); - CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture); - CORRADE_IGNORE_DEPRECATED_POP - CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf); - CORRADE_COMPARE(data.ambientTexture(), 42); - CORRADE_COMPARE(data.ambientTextureCoordinates(), 0); - CORRADE_COMPARE(data.diffuseColor(), 0xeebbff_rgbf); - CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); - CORRADE_COMPARE(data.specularTexture(), 17); - CORRADE_COMPARE(data.specularTextureCoordinates(), 0); - CORRADE_IGNORE_DEPRECATED_PUSH - CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); - CORRADE_IGNORE_DEPRECATED_POP - CORRADE_COMPARE(data.alphaMode(), MaterialAlphaMode::Blend); - CORRADE_COMPARE(data.alphaMask(), 0.37f); - CORRADE_COMPARE(data.shininess(), 96.0f); - CORRADE_COMPARE(data.importerState(), &a); -} - -void MaterialDataTest::constructPhongDeprecatedTexturedTextureTransform() { - const int a{}; - CORRADE_IGNORE_DEPRECATED_PUSH - PhongMaterialData data{ - PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureTransformation, - 0x111111_rgbf, {}, - 0xeebbff_rgbf, 42, - 0xacabad_rgbf, {}, 17, - Matrix3::rotation(90.0_degf), - MaterialAlphaMode::Mask, 0.5f, 96.0f, &a}; - CORRADE_IGNORE_DEPRECATED_POP - - CORRADE_COMPARE(data.types(), MaterialType::Phong); - CORRADE_IGNORE_DEPRECATED_PUSH - CORRADE_COMPARE(data.type(), MaterialType::Phong); - CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureTransformation); - CORRADE_IGNORE_DEPRECATED_POP - CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf); - CORRADE_COMPARE(data.diffuseColor(), 0xeebbff_rgbf); - CORRADE_COMPARE(data.diffuseTexture(), 42); - CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); - CORRADE_COMPARE(data.normalTexture(), 17); - CORRADE_IGNORE_DEPRECATED_PUSH - CORRADE_COMPARE(data.textureMatrix(), Matrix3::rotation(90.0_degf)); - CORRADE_IGNORE_DEPRECATED_POP - CORRADE_COMPARE(data.alphaMode(), MaterialAlphaMode::Mask); - CORRADE_COMPARE(data.alphaMask(), 0.5f); - CORRADE_COMPARE(data.shininess(), 96.0f); - CORRADE_COMPARE(data.importerState(), &a); -} - -void MaterialDataTest::constructPhongDeprecatedTexturedCoordinates() { - const int a{}; - CORRADE_IGNORE_DEPRECATED_PUSH - PhongMaterialData data{ - PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureCoordinates, - 0x111111_rgbf, 42, 3, - 0xeebbff_rgbf, {}, 6, - 0xacabad_rgbf, 17, 1, - 0, 8, {}, - MaterialAlphaMode::Blend, 0.37f, 96.0f, &a}; - CORRADE_IGNORE_DEPRECATED_POP - - CORRADE_COMPARE(data.types(), MaterialType::Phong); - CORRADE_IGNORE_DEPRECATED_PUSH - CORRADE_COMPARE(data.type(), MaterialType::Phong); - CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureCoordinates); - CORRADE_IGNORE_DEPRECATED_POP - CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf); - CORRADE_COMPARE(data.ambientTexture(), 42); - CORRADE_COMPARE(data.ambientTextureCoordinates(), 3); - CORRADE_COMPARE(data.diffuseColor(), 0xeebbff_rgbf); - CORRADE_COMPARE(data.diffuseTextureCoordinates(), 6); - CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); - CORRADE_COMPARE(data.specularTexture(), 17); - CORRADE_COMPARE(data.specularTextureCoordinates(), 1); - CORRADE_COMPARE(data.normalTexture(), 0); - CORRADE_COMPARE(data.normalTextureCoordinates(), 8); - CORRADE_IGNORE_DEPRECATED_PUSH - CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); - CORRADE_IGNORE_DEPRECATED_POP - CORRADE_COMPARE(data.ambientTextureCoordinates(), 3); - CORRADE_COMPARE(data.alphaMode(), MaterialAlphaMode::Blend); - CORRADE_COMPARE(data.alphaMask(), 0.37f); - CORRADE_COMPARE(data.shininess(), 96.0f); - CORRADE_COMPARE(data.importerState(), &a); -} - -void MaterialDataTest::constructPhongDeprecatedTextureTransformNoTextures() { - #ifdef CORRADE_NO_ASSERT - CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); - #endif - - std::ostringstream out; - Error redirectError{&out}; - CORRADE_IGNORE_DEPRECATED_PUSH - PhongMaterialData a{PhongMaterialData::Flag::TextureTransformation, - {}, {}, - {}, {}, - {}, {}, {}, {}, - {}, 0.5f, 80.0f}; - CORRADE_IGNORE_DEPRECATED_POP - CORRADE_COMPARE(out.str(), - "Trade::PhongMaterialData: texture transformation enabled but the material has no textures\n"); -} - -void MaterialDataTest::constructPhongDeprecatedNoTextureTransformationFlag() { - #ifdef CORRADE_NO_ASSERT - CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); - #endif - - std::ostringstream out; - Error redirectError{&out}; - CORRADE_IGNORE_DEPRECATED_PUSH - PhongMaterialData a{{}, - {}, {}, - {}, {}, - {}, {}, {}, Matrix3::rotation(90.0_degf), - {}, 0.5f, 80.0f}; - CORRADE_IGNORE_DEPRECATED_POP - CORRADE_COMPARE(out.str(), - "PhongMaterialData::PhongMaterialData: non-default texture matrix requires Flag::TextureTransformation to be enabled\n"); -} - -void MaterialDataTest::constructPhongDeprecatedNoTextureCoordinatesFlag() { - #ifdef CORRADE_NO_ASSERT - CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); - #endif - - std::ostringstream out; - Error redirectError{&out}; - CORRADE_IGNORE_DEPRECATED_PUSH - PhongMaterialData a{{}, - {}, {}, 1, - {}, {}, 2, - {}, {}, 3, {}, 4, {}, - {}, 0.5f, 80.0f}; - CORRADE_IGNORE_DEPRECATED_POP - CORRADE_COMPARE(out.str(), - "PhongMaterialData::PhongMaterialData: non-zero texture coordinate sets require Flag::TextureCoordinates to be enabled\n"); -} -#endif - -void MaterialDataTest::pbrMetallicRoughnessAccess() { - MaterialData base{MaterialType::PbrMetallicRoughness, { - {MaterialAttribute::BaseColor, 0xccffbbff_rgbaf}, - {MaterialAttribute::Metalness, 0.5f}, - {MaterialAttribute::Roughness, 0.79f}, - {MaterialAttribute::EmissiveColor, 0x111111_rgbf} - }}; - - CORRADE_COMPARE(base.types(), MaterialType::PbrMetallicRoughness); - const auto& data = base.as(); - - CORRADE_VERIFY(!data.hasMetalnessTexture()); - CORRADE_VERIFY(!data.hasRoughnessTexture()); - CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); - CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); - CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); - CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.baseColor(), 0xccffbbff_rgbaf); - CORRADE_COMPARE(data.metalness(), 0.5f); - CORRADE_COMPARE(data.roughness(), 0.79f); - CORRADE_COMPARE(data.emissiveColor(), 0x111111_rgbf); -} - -void MaterialDataTest::pbrMetallicRoughnessAccessDefaults() { - MaterialData base{{}, {}}; - - CORRADE_COMPARE(base.types(), MaterialTypes{}); - /* Casting is fine even if the type doesn't include PbrMetallicRoughness */ - const auto& data = base.as(); - - CORRADE_VERIFY(!data.hasMetalnessTexture()); - CORRADE_VERIFY(!data.hasRoughnessTexture()); - CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); - CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); - CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); - CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.baseColor(), 0xffffffff_rgbaf); - CORRADE_COMPARE(data.metalness(), 1.0f); - CORRADE_COMPARE(data.roughness(), 1.0f); - CORRADE_COMPARE(data.emissiveColor(), 0x000000_rgbf); -} - -void MaterialDataTest::pbrMetallicRoughnessAccessTextured() { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::BaseColor, 0xccffbbff_rgbaf}, - {MaterialAttribute::BaseColorTexture, 0u}, - {MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::BaseColorTextureCoordinates, 2u}, - {MaterialAttribute::Metalness, 0.5f}, - {MaterialAttribute::MetalnessTexture, 1u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::MetalnessTextureCoordinates, 3u}, - {MaterialAttribute::Roughness, 0.79f}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::A}, - {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, - {MaterialAttribute::RoughnessTextureCoordinates, 4u}, - {MaterialAttribute::NormalTexture, 3u}, - {MaterialAttribute::NormalTextureScale, 0.35f}, - {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::BA}, - {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})}, - {MaterialAttribute::NormalTextureCoordinates, 5u}, - {MaterialAttribute::OcclusionTexture, 4u}, - {MaterialAttribute::OcclusionTextureStrength, 0.66f}, - {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({1.0f, 0.75f})}, - {MaterialAttribute::OcclusionTextureCoordinates, 6u}, - {MaterialAttribute::EmissiveColor, 0x111111_rgbf}, - {MaterialAttribute::EmissiveTexture, 5u}, - {MaterialAttribute::EmissiveTextureMatrix, Matrix3::scaling({0.75f, 0.5f})}, - {MaterialAttribute::EmissiveTextureCoordinates, 7u} - }}; - - CORRADE_VERIFY(data.hasMetalnessTexture()); - CORRADE_VERIFY(data.hasRoughnessTexture()); - CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); - CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); - CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); - CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); - CORRADE_VERIFY(data.hasTextureTransformation()); - CORRADE_VERIFY(data.hasTextureCoordinates()); - CORRADE_COMPARE(data.baseColor(), 0xccffbbff_rgbaf); - CORRADE_COMPARE(data.baseColorTexture(), 0); - CORRADE_COMPARE(data.baseColorTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); - CORRADE_COMPARE(data.baseColorTextureCoordinates(), 2); - CORRADE_COMPARE(data.metalness(), 0.5f); - CORRADE_COMPARE(data.metalnessTexture(), 1); - CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::G); - CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.metalnessTextureCoordinates(), 3); - CORRADE_COMPARE(data.roughness(), 0.79f); - CORRADE_COMPARE(data.roughnessTexture(), 2); - CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::A); - CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); - CORRADE_COMPARE(data.roughnessTextureCoordinates(), 4); - CORRADE_COMPARE(data.normalTexture(), 3); - CORRADE_COMPARE(data.normalTextureScale(), 0.35f); - CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::BA); - CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f})); - CORRADE_COMPARE(data.normalTextureCoordinates(), 5); - CORRADE_COMPARE(data.occlusionTexture(), 4); - CORRADE_COMPARE(data.occlusionTextureStrength(), 0.66f); - CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({1.0f, 0.75f})); - CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::B); - CORRADE_COMPARE(data.occlusionTextureCoordinates(), 6); - CORRADE_COMPARE(data.emissiveColor(), 0x111111_rgbf); - CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.75f, 0.5f})); - CORRADE_COMPARE(data.emissiveTexture(), 5); - CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); -} - -void MaterialDataTest::pbrMetallicRoughnessAccessTexturedDefaults() { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::BaseColorTexture, 1u}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::RoughnessTexture, 3u}, - {MaterialAttribute::NormalTexture, 4u}, - {MaterialAttribute::OcclusionTexture, 5u}, - {MaterialAttribute::EmissiveTexture, 6u} - }}; - - CORRADE_VERIFY(data.hasMetalnessTexture()); - CORRADE_VERIFY(data.hasRoughnessTexture()); - CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); - CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); - CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); - CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.baseColor(), 0xffffffff_rgbaf); - CORRADE_COMPARE(data.baseColorTexture(), 1); - CORRADE_COMPARE(data.baseColorTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.baseColorTextureCoordinates(), 0); - CORRADE_COMPARE(data.metalness(), 1.0f); - CORRADE_COMPARE(data.metalnessTexture(), 2); - CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::R); - CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.metalnessTextureCoordinates(), 0); - CORRADE_COMPARE(data.roughness(), 1.0f); - CORRADE_COMPARE(data.roughnessTexture(), 3); - CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::R); - CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0); - CORRADE_COMPARE(data.normalTexture(), 4); - CORRADE_COMPARE(data.normalTextureScale(), 1.0f); - CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); - CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.normalTextureCoordinates(), 0); - CORRADE_COMPARE(data.occlusionTexture(), 5); - CORRADE_COMPARE(data.occlusionTextureStrength(), 1.0f); - CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::R); - CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.occlusionTextureCoordinates(), 0); - CORRADE_COMPARE(data.emissiveColor(), 0x000000_rgbf); - CORRADE_COMPARE(data.emissiveTexture(), 6); - CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.emissiveTextureCoordinates(), 0); -} - -void MaterialDataTest::pbrMetallicRoughnessAccessTexturedSingleMatrixCoordinates() { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::BaseColorTexture, 1u}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::RoughnessTexture, 3u}, - {MaterialAttribute::NormalTexture, 4u}, - {MaterialAttribute::OcclusionTexture, 5u}, - {MaterialAttribute::EmissiveTexture, 6u}, - {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::TextureCoordinates, 7u} - }}; - - CORRADE_COMPARE(data.baseColorTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.baseColorTextureCoordinates(), 7); - CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.metalnessTextureCoordinates(), 7); - CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7); - CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.normalTextureCoordinates(), 7); - CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.occlusionTextureCoordinates(), 7); - CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); -} - -void MaterialDataTest::pbrMetallicRoughnessAccessTexturedImplicitPackedMetallicRoughness() { - /* Just the texture ID, the rest is implicit */ - { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::NoneRoughnessMetallicTexture, 2u}, - }}; - CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); - CORRADE_COMPARE(data.roughnessTexture(), 2); - CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); - CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0); - CORRADE_COMPARE(data.metalnessTexture(), 2); - CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::B); - CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.metalnessTextureCoordinates(), 0); - - /* Explicit parameters for everything, but all the same */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::NoneRoughnessMetallicTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::RoughnessTextureCoordinates, 3u}, - {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTextureCoordinates, 3u} - }}; - CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); - CORRADE_COMPARE(data.roughnessTexture(), 2); - CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); - CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.roughnessTextureCoordinates(), 3); - CORRADE_COMPARE(data.metalnessTexture(), 2); - CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::B); - CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.metalnessTextureCoordinates(), 3); - - /* Swizzle is ignored when the combined texture is specified, so this is - fine */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::NoneRoughnessMetallicTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, - }}; - CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); - - /* Unexpected texture matrix */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::NoneRoughnessMetallicTexture, 2u}, - {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - }}; - CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); - - /* Unexpected texture coordinates */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::NoneRoughnessMetallicTexture, 2u}, - {MaterialAttribute::RoughnessTextureCoordinates, 1u}, - }}; - CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); - } -} - -void MaterialDataTest::pbrMetallicRoughnessAccessTexturedExplicitPackedMetallicRoughness() { - /* Just the texture IDs and swizzles, the rest is implicit */ - { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B} - }}; - CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); - - /* Explicit parameters for everything, but all the same */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::RoughnessTextureCoordinates, 3u}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTextureCoordinates, 3u} - }}; - CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); - - /* Different texture ID */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::MetalnessTexture, 3u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B} - }}; - CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); - - /* One texture missing */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - }}; - CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); - - /* Unexpected swizzle */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::R}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, - }}; - CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); - - /* Unexpected texture matrix */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - }}; - CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); - - /* Unexpected texture coordinates */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::RoughnessTextureCoordinates, 1u}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, - }}; - CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); - } -} - -void MaterialDataTest::pbrMetallicRoughnessAccessTexturedExplicitPackedRoughnessMetallicOcclusion() { - /* Just the texture IDs and swizzles, the rest is implicit */ - { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::OcclusionTexture, 2u}, - {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, - }}; - CORRADE_VERIFY(data.hasRoughnessMetallicOcclusionTexture()); - /* This isn't a superset */ - CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); - - /* Explicit parameters for everything, but all the same */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::R}, - {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::RoughnessTextureCoordinates, 3u}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::MetalnessTextureCoordinates, 3u}, - {MaterialAttribute::OcclusionTexture, 2u}, - {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::OcclusionTextureCoordinates, 3u} - }}; - CORRADE_VERIFY(data.hasRoughnessMetallicOcclusionTexture()); - /* This isn't a superset */ - CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); - - /* Different texture ID */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::MetalnessTexture, 3u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::OcclusionTexture, 2u}, - {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, - }}; - CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); - - /* One texture missing */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, - }}; - CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); - - /* Unexpected swizzle */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::A}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::OcclusionTexture, 2u}, - {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, - }}; - CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); - - /* Unexpected texture matrix */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::OcclusionTexture, 2u}, - {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - }}; - CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); - - /* Unexpected texture coordinates */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::OcclusionTexture, 2u}, - {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTextureCoordinates, 1u}, - }}; - CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); - } -} - -void MaterialDataTest::pbrMetallicRoughnessAccessTexturedExplicitPackedOcclusionRoughnessMetallic() { - /* Just the texture IDs and swizzles, the rest is implicit */ - { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::OcclusionTexture, 2u}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, - }}; - CORRADE_VERIFY(data.hasOcclusionRoughnessMetallicTexture()); - /* This is a superset */ - CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); - - /* Explicit parameters for everything, but all the same */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::OcclusionTexture, 2u}, - {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::R}, - {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::OcclusionTextureCoordinates, 3u}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::RoughnessTextureCoordinates, 3u}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTextureCoordinates, 3u} - }}; - CORRADE_VERIFY(data.hasOcclusionRoughnessMetallicTexture()); - /* This is a superset */ - CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); - - /* Different texture ID */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::OcclusionTexture, 2u}, - {MaterialAttribute::RoughnessTexture, 3u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, - }}; - CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); - - /* One texture missing */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, - }}; - CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); - - /* Unexpected swizzle */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::OcclusionTexture, 2u}, - {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::A}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, - }}; - CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); - - /* Unexpected texture matrix */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::OcclusionTexture, 2u}, - {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, - }}; - CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); - - /* Unexpected texture coordinates */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::OcclusionTexture, 2u}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTextureCoordinates, 1u}, - }}; - CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); - } -} - -void MaterialDataTest::pbrMetallicRoughnessAccessTexturedExplicitPackedNormalRoughnessMetallic() { - /* Just the texture IDs and swizzles, the rest is implicit */ - { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::NormalTexture, 2u}, - {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::RG}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A} - }}; - CORRADE_VERIFY(data.hasNormalRoughnessMetallicTexture()); - - /* Explicit parameters for everything, but all the same */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::NormalTexture, 2u}, - {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::RG}, - {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::NormalTextureCoordinates, 3u}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::RoughnessTextureCoordinates, 3u}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A}, - {MaterialAttribute::MetalnessTextureCoordinates, 3u} - }}; - CORRADE_VERIFY(data.hasNormalRoughnessMetallicTexture()); - - /* Different texture ID */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::NormalTexture, 2u}, - {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::RG}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTexture, 3u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A} - }}; - CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); - - /* One texture missing */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A}, - }}; - CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); - - /* Unexpected swizzle */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::NormalTexture, 2u}, - {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::RGB}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A}, - }}; - CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); - - /* Unexpected texture matrix */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::NormalTexture, 2u}, - {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::RG}, - {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A}, - }}; - CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); - - /* Unexpected texture coordinates */ - } { - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::NormalTexture, 2u}, - {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::RG}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::MetalnessTexture, 2u}, - {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A}, - {MaterialAttribute::MetalnessTextureCoordinates, 1u}, - }}; - CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); - } -} - -void MaterialDataTest::pbrMetallicRoughnessAccessInvalidTextures() { - #ifdef CORRADE_NO_ASSERT - CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); - #endif - - PbrMetallicRoughnessMaterialData data{{}, {}}; - - std::ostringstream out; - Error redirectError{&out}; - data.baseColorTexture(); - data.baseColorTextureMatrix(); - data.baseColorTextureCoordinates(); - data.metalnessTexture(); - data.metalnessTextureSwizzle(); - data.metalnessTextureMatrix(); - data.metalnessTextureCoordinates(); - data.roughnessTexture(); - data.roughnessTextureSwizzle(); - data.roughnessTextureMatrix(); - data.roughnessTextureCoordinates(); - data.normalTexture(); - data.normalTextureScale(); - data.normalTextureSwizzle(); - data.normalTextureMatrix(); - data.normalTextureCoordinates(); - data.occlusionTexture(); - data.occlusionTextureStrength(); - data.occlusionTextureSwizzle(); - data.occlusionTextureMatrix(); - data.occlusionTextureCoordinates(); - data.emissiveTexture(); - data.emissiveTextureMatrix(); - data.emissiveTextureCoordinates(); - CORRADE_COMPARE(out.str(), - "Trade::MaterialData::attribute(): attribute BaseColorTexture not found in layer 0\n" - "Trade::PbrMetallicRoughnessMaterialData::baseColorTextureMatrix(): the material doesn't have a base color texture\n" - "Trade::PbrMetallicRoughnessMaterialData::baseColorTextureCoordinates(): the material doesn't have a base color texture\n" - "Trade::PbrMetallicRoughnessMaterialData::metalnessTexture(): the material doesn't have a metalness texture\n" - "Trade::PbrMetallicRoughnessMaterialData::metalnessTextureSwizzle(): the material doesn't have a metalness texture\n" - "Trade::PbrMetallicRoughnessMaterialData::metalnessTextureMatrix(): the material doesn't have a metalness texture\n" - "Trade::PbrMetallicRoughnessMaterialData::metalnessTextureCoordinates(): the material doesn't have a metalness texture\n" - "Trade::PbrMetallicRoughnessMaterialData::roughnessTexture(): the material doesn't have a roughness texture\n" - "Trade::PbrMetallicRoughnessMaterialData::roughnessTextureSwizzle(): the material doesn't have a roughness texture\n" - "Trade::PbrMetallicRoughnessMaterialData::roughnessTextureMatrix(): the material doesn't have a roughness texture\n" - "Trade::PbrMetallicRoughnessMaterialData::roughnessTextureCoordinates(): the material doesn't have a roughness texture\n" - "Trade::MaterialData::attribute(): attribute NormalTexture not found in layer 0\n" - "Trade::PbrMetallicRoughnessMaterialData::normalTextureScale(): the material doesn't have a normal texture\n" - "Trade::PbrMetallicRoughnessMaterialData::normalTextureSwizzle(): the material doesn't have a normal texture\n" - "Trade::PbrMetallicRoughnessMaterialData::normalTextureMatrix(): the material doesn't have a normal texture\n" - "Trade::PbrMetallicRoughnessMaterialData::normalTextureCoordinates(): the material doesn't have a normal texture\n" - "Trade::MaterialData::attribute(): attribute OcclusionTexture not found in layer 0\n" - "Trade::PbrMetallicRoughnessMaterialData::occlusionTextureStrength(): the material doesn't have an occlusion texture\n" - "Trade::PbrMetallicRoughnessMaterialData::occlusionTextureSwizzle(): the material doesn't have an occlusion texture\n" - "Trade::PbrMetallicRoughnessMaterialData::occlusionTextureMatrix(): the material doesn't have an occlusion texture\n" - "Trade::PbrMetallicRoughnessMaterialData::occlusionTextureCoordinates(): the material doesn't have an occlusion texture\n" - "Trade::MaterialData::attribute(): attribute EmissiveTexture not found in layer 0\n" - "Trade::PbrMetallicRoughnessMaterialData::emissiveTextureMatrix(): the material doesn't have an emissive texture\n" - "Trade::PbrMetallicRoughnessMaterialData::emissiveTextureCoordinates(): the material doesn't have an emissive texture\n"); -} - -void MaterialDataTest::pbrMetallicRoughnessAccessCommonTransformationCoordinatesNoTextures() { - PbrMetallicRoughnessMaterialData a{{}, {}}; - CORRADE_VERIFY(a.hasCommonTextureTransformation()); - CORRADE_VERIFY(a.hasCommonTextureCoordinates()); - CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(a.commonTextureCoordinates(), 0); - - PbrMetallicRoughnessMaterialData b{{}, { - {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::TextureCoordinates, 7u} - }}; - CORRADE_VERIFY(b.hasCommonTextureTransformation()); - CORRADE_VERIFY(b.hasCommonTextureCoordinates()); - CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(b.commonTextureCoordinates(), 7); -} - -void MaterialDataTest::pbrMetallicRoughnessAccessCommonTransformationCoordinatesOneTexture() { - Containers::StringView textureName = PbrMetallicRoughnessTextureData[testCaseInstanceId()]; - setTestCaseDescription(textureName); - - PbrMetallicRoughnessMaterialData data{{}, { - {textureName, 5u}, - {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, - {std::string{textureName} + "Coordinates", 17u}, - - /* These shouldn't affect the above */ - {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::TextureCoordinates, 3u} - }}; - - CORRADE_VERIFY(data.hasCommonTextureTransformation()); - CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); - CORRADE_VERIFY(data.hasCommonTextureCoordinates()); - CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); -} - -void MaterialDataTest::pbrMetallicRoughnessAccessCommonTransformationCoordinatesOneDifferentTexture() { - Containers::StringView textureName = PbrMetallicRoughnessTextureData[testCaseInstanceId()]; - setTestCaseDescription(textureName); - - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::BaseColorTexture, 2u}, - {MaterialAttribute::MetalnessTexture, 3u}, - {MaterialAttribute::RoughnessTexture, 4u}, - {MaterialAttribute::NormalTexture, 5u}, - {MaterialAttribute::OcclusionTexture, 6u}, - {MaterialAttribute::EmissiveTexture, 7u}, - {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, - {std::string{textureName} + "Coordinates", 17u}, - - /* These are used by all textures except the one above, failing the - check */ - {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::TextureCoordinates, 3u} - }}; - - CORRADE_VERIFY(!data.hasCommonTextureTransformation()); - CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); -} - -void MaterialDataTest::pbrMetallicRoughnessAccessNoCommonTransformationCoordinates() { - #ifdef CORRADE_NO_ASSERT - CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); - #endif - - PbrMetallicRoughnessMaterialData data{{}, { - {MaterialAttribute::BaseColorTexture, 3u}, - {MaterialAttribute::BaseColorTextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::BaseColorTextureCoordinates, 3u}, - {MaterialAttribute::MetalnessTexture, 4u}, - {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::RoughnessTexture, 5u}, - {MaterialAttribute::RoughnessTextureCoordinates, 17u} - }}; - - CORRADE_VERIFY(!data.hasCommonTextureTransformation()); - CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); - - std::ostringstream out; - Error redirectError{&out}; - data.commonTextureMatrix(); - data.commonTextureCoordinates(); - CORRADE_COMPARE(out.str(), - "Trade::PbrMetallicRoughnessMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation\n" - "Trade::PbrMetallicRoughnessMaterialData::commonTextureCoordinates(): the material doesn't have a common texture coordinate set\n"); -} - -void MaterialDataTest::pbrSpecularGlossinessAccess() { - MaterialData base{MaterialType::PbrSpecularGlossiness, { - {MaterialAttribute::DiffuseColor, 0xccffbbff_rgbaf}, - {MaterialAttribute::SpecularColor, 0xff336600_rgbaf}, - {MaterialAttribute::Glossiness, 0.79f}, - {MaterialAttribute::EmissiveColor, 0x111111_rgbf} - }}; - - CORRADE_COMPARE(base.types(), MaterialType::PbrSpecularGlossiness); - const auto& data = base.as(); - - CORRADE_VERIFY(!data.hasSpecularTexture()); - CORRADE_VERIFY(!data.hasGlossinessTexture()); - CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.diffuseColor(), 0xccffbbff_rgbaf); - CORRADE_COMPARE(data.specularColor(), 0xff336600_rgbaf); - CORRADE_COMPARE(data.glossiness(), 0.79f); -} - -void MaterialDataTest::pbrSpecularGlossinessAccessDefaults() { - MaterialData base{{}, {}}; - - CORRADE_COMPARE(base.types(), MaterialTypes{}); - /* Casting is fine even if the type doesn't include PbrMetallicRoughness */ - const auto& data = base.as(); - - CORRADE_VERIFY(!data.hasSpecularTexture()); - CORRADE_VERIFY(!data.hasGlossinessTexture()); - CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf); - CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); - CORRADE_COMPARE(data.glossiness(), 1.0f); -} - -void MaterialDataTest::pbrSpecularGlossinessAccessTextured() { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::DiffuseColor, 0xccffbbff_rgbaf}, - {MaterialAttribute::DiffuseTexture, 0u}, - {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::DiffuseTextureCoordinates, 2u}, - {MaterialAttribute::SpecularColor, 0x33556600_rgbaf}, - {MaterialAttribute::SpecularTexture, 1u}, - {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGBA}, - {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::SpecularTextureCoordinates, 3u}, - {MaterialAttribute::Glossiness, 0.79f}, - {MaterialAttribute::GlossinessTexture, 2u}, - {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, - {MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, - {MaterialAttribute::GlossinessTextureCoordinates, 4u}, - {MaterialAttribute::NormalTexture, 3u}, - {MaterialAttribute::NormalTextureScale, 0.35f}, - {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::BA}, - {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})}, - {MaterialAttribute::NormalTextureCoordinates, 5u}, - {MaterialAttribute::OcclusionTexture, 4u}, - {MaterialAttribute::OcclusionTextureStrength, 0.66f}, - {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({1.0f, 0.75f})}, - {MaterialAttribute::OcclusionTextureCoordinates, 6u}, - {MaterialAttribute::EmissiveColor, 0x111111_rgbf}, - {MaterialAttribute::EmissiveTexture, 5u}, - {MaterialAttribute::EmissiveTextureMatrix, Matrix3::scaling({0.75f, 0.5f})}, - {MaterialAttribute::EmissiveTextureCoordinates, 7u} - }}; - - CORRADE_VERIFY(data.hasSpecularTexture()); - CORRADE_VERIFY(data.hasGlossinessTexture()); - CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); - CORRADE_VERIFY(data.hasTextureTransformation()); - CORRADE_VERIFY(data.hasTextureCoordinates()); - CORRADE_COMPARE(data.diffuseColor(), 0xccffbbff_rgbaf); - CORRADE_COMPARE(data.diffuseTexture(), 0); - CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); - CORRADE_COMPARE(data.diffuseTextureCoordinates(), 2); - CORRADE_COMPARE(data.specularColor(), 0x33556600_rgbaf); - CORRADE_COMPARE(data.specularTexture(), 1); - CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGBA); - CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.specularTextureCoordinates(), 3); - CORRADE_COMPARE(data.glossiness(), 0.79f); - CORRADE_COMPARE(data.glossinessTexture(), 2); - CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); - CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); - CORRADE_COMPARE(data.glossinessTextureCoordinates(), 4); - CORRADE_COMPARE(data.normalTexture(), 3); - CORRADE_COMPARE(data.normalTextureScale(), 0.35f); - CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::BA); - CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f})); - CORRADE_COMPARE(data.normalTextureCoordinates(), 5); - CORRADE_COMPARE(data.occlusionTexture(), 4); - CORRADE_COMPARE(data.occlusionTextureStrength(), 0.66f); - CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({1.0f, 0.75f})); - CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::B); - CORRADE_COMPARE(data.occlusionTextureCoordinates(), 6); - CORRADE_COMPARE(data.emissiveColor(), 0x111111_rgbf); - CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.75f, 0.5f})); - CORRADE_COMPARE(data.emissiveTexture(), 5); - CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); -} - -void MaterialDataTest::pbrSpecularGlossinessAccessTexturedDefaults() { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::DiffuseTexture, 1u}, - {MaterialAttribute::SpecularTexture, 2u}, - {MaterialAttribute::GlossinessTexture, 3u}, - {MaterialAttribute::NormalTexture, 4u}, - {MaterialAttribute::OcclusionTexture, 5u}, - {MaterialAttribute::EmissiveTexture, 6u} - }}; - - CORRADE_VERIFY(data.hasSpecularTexture()); - CORRADE_VERIFY(data.hasGlossinessTexture()); - CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf); - CORRADE_COMPARE(data.diffuseTexture(), 1); - CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.diffuseTextureCoordinates(), 0); - CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); - CORRADE_COMPARE(data.specularTexture(), 2); - CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); - CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.specularTextureCoordinates(), 0); - CORRADE_COMPARE(data.glossiness(), 1.0f); - CORRADE_COMPARE(data.glossinessTexture(), 3); - CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::R); - CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0); - CORRADE_COMPARE(data.normalTexture(), 4); - CORRADE_COMPARE(data.normalTextureScale(), 1.0f); - CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); - CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.normalTextureCoordinates(), 0); - CORRADE_COMPARE(data.occlusionTexture(), 5); - CORRADE_COMPARE(data.occlusionTextureStrength(), 1.0f); - CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::R); - CORRADE_COMPARE(data.occlusionTextureCoordinates(), 0); - CORRADE_COMPARE(data.emissiveColor(), 0x000000_rgbf); - CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.emissiveTexture(), 6); - CORRADE_COMPARE(data.emissiveTextureCoordinates(), 0); -} - -void MaterialDataTest::pbrSpecularGlossinessAccessTexturedSingleMatrixCoordinates() { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::DiffuseTexture, 1u}, - {MaterialAttribute::SpecularTexture, 2u}, - {MaterialAttribute::GlossinessTexture, 3u}, - {MaterialAttribute::NormalTexture, 4u}, - {MaterialAttribute::OcclusionTexture, 5u}, - {MaterialAttribute::EmissiveTexture, 6u}, - {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::TextureCoordinates, 7u} - }}; - - CORRADE_VERIFY(data.hasTextureTransformation()); - CORRADE_VERIFY(data.hasTextureCoordinates()); - CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.diffuseTextureCoordinates(), 7); - CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.specularTextureCoordinates(), 7); - CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.glossinessTextureCoordinates(), 7); - CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.normalTextureCoordinates(), 7); - CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.occlusionTextureCoordinates(), 7); - CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); -} - -void MaterialDataTest::pbrSpecularGlossinessAccessTexturedImplicitPackedSpecularGlossiness() { - /* Just the texture ID, the rest is implicit */ - { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::SpecularGlossinessTexture, 2u}, - }}; - CORRADE_VERIFY(data.hasSpecularGlossinessTexture()); - CORRADE_COMPARE(data.specularTexture(), 2); - CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); - CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.specularTextureCoordinates(), 0); - CORRADE_COMPARE(data.glossinessTexture(), 2); - CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); - CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0); - - /* Explicit parameters for everything, but all the same */ - } { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::SpecularGlossinessTexture, 2u}, - {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGB}, - {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::SpecularTextureCoordinates, 3u}, - {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, - {MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::GlossinessTextureCoordinates, 3u} - }}; - CORRADE_VERIFY(data.hasSpecularGlossinessTexture()); - CORRADE_COMPARE(data.specularTexture(), 2); - CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); - CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.specularTextureCoordinates(), 3); - CORRADE_COMPARE(data.glossinessTexture(), 2); - CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); - CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.glossinessTextureCoordinates(), 3); - - /* Swizzle is ignored when the combined texture is specified, so this is - fine. */ - } { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::SpecularGlossinessTexture, 2u}, - {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::B}, - }}; - CORRADE_VERIFY(data.hasSpecularGlossinessTexture()); - - /* Unexpected texture matrix */ - } { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::SpecularGlossinessTexture, 2u}, - {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - }}; - CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); - - /* Unexpected texture coordinates */ - } { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::SpecularGlossinessTexture, 2u}, - {MaterialAttribute::GlossinessTextureCoordinates, 1u}, - }}; - CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); - } -} - -void MaterialDataTest::pbrSpecularGlossinessAccessTexturedExplicitPackedSpecularGlossiness() { - /* Just the texture ID and swizzles, the rest is implicit */ - { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::SpecularTexture, 2u}, - {MaterialAttribute::GlossinessTexture, 2u}, - {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A} - }}; - CORRADE_VERIFY(data.hasSpecularGlossinessTexture()); - CORRADE_COMPARE(data.specularTexture(), 2); - CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); - CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.specularTextureCoordinates(), 0); - CORRADE_COMPARE(data.glossinessTexture(), 2); - CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); - CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0); - - /* Explicit parameters for everything, but all the same */ - } { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::SpecularTexture, 2u}, - {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGB}, - {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::SpecularTextureCoordinates, 3u}, - {MaterialAttribute::GlossinessTexture, 2u}, - {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, - {MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::GlossinessTextureCoordinates, 3u} - }}; - CORRADE_VERIFY(data.hasSpecularGlossinessTexture()); - CORRADE_COMPARE(data.specularTexture(), 2); - CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); - CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.specularTextureCoordinates(), 3); - CORRADE_COMPARE(data.glossinessTexture(), 2); - CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); - CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.glossinessTextureCoordinates(), 3); - - /* Different texture ID */ - } { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::SpecularTexture, 2u}, - {MaterialAttribute::GlossinessTexture, 3u}, - {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A} - }}; - CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); - - /* Unexpected swizzle 1 */ - } { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::SpecularTexture, 2u}, - {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGBA}, - {MaterialAttribute::GlossinessTexture, 2u}, - {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A} - }}; - CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); - - /* Unexpected swizzle 2 */ - } { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::SpecularTexture, 2u}, - {MaterialAttribute::GlossinessTexture, 2u}, - {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::B} - }}; - CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); - - /* Unexpected texture matrix */ - } { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::SpecularTexture, 2u}, - {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::GlossinessTexture, 2u}, - {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A} - }}; - CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); - - /* Unexpected texture coordinates */ - } { - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::SpecularTexture, 2u}, - {MaterialAttribute::GlossinessTexture, 2u}, - {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, - {MaterialAttribute::GlossinessTextureCoordinates, 1u} - }}; - CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); - } -} - -void MaterialDataTest::pbrSpecularGlossinessAccessInvalidTextures() { - #ifdef CORRADE_NO_ASSERT - CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); - #endif - - PbrSpecularGlossinessMaterialData data{{}, {}}; - - std::ostringstream out; - Error redirectError{&out}; - data.diffuseTexture(); - data.diffuseTextureMatrix(); - data.diffuseTextureCoordinates(); - data.specularTexture(); - data.specularTextureSwizzle(); - data.specularTextureMatrix(); - data.specularTextureCoordinates(); - data.glossinessTexture(); - data.glossinessTextureSwizzle(); - data.glossinessTextureMatrix(); - data.glossinessTextureCoordinates(); - data.normalTexture(); - data.normalTextureScale(); - data.normalTextureSwizzle(); - data.normalTextureMatrix(); - data.normalTextureCoordinates(); - data.occlusionTexture(); - data.occlusionTextureStrength(); - data.occlusionTextureSwizzle(); - data.occlusionTextureMatrix(); - data.occlusionTextureCoordinates(); - data.emissiveTexture(); - data.emissiveTextureMatrix(); - data.emissiveTextureCoordinates(); - CORRADE_COMPARE(out.str(), - "Trade::MaterialData::attribute(): attribute DiffuseTexture not found in layer 0\n" - "Trade::PbrSpecularGlossinessMaterialData::diffuseTextureMatrix(): the material doesn't have a diffuse texture\n" - "Trade::PbrSpecularGlossinessMaterialData::diffuseTextureCoordinates(): the material doesn't have a diffuse texture\n" - "Trade::PbrSpecularGlossinessMaterialData::specularTexture(): the material doesn't have a specular texture\n" - "Trade::PbrSpecularGlossinessMaterialData::specularTextureSwizzle(): the material doesn't have a specular texture\n" - "Trade::PbrSpecularGlossinessMaterialData::specularTextureMatrix(): the material doesn't have a specular texture\n" - "Trade::PbrSpecularGlossinessMaterialData::specularTextureCoordinates(): the material doesn't have a specular texture\n" - "Trade::PbrSpecularGlossinessMaterialData::glossinessTexture(): the material doesn't have a glossiness texture\n" - "Trade::PbrSpecularGlossinessMaterialData::glossinessTextureSwizzle(): the material doesn't have a glossiness texture\n" - "Trade::PbrSpecularGlossinessMaterialData::glossinessTextureMatrix(): the material doesn't have a glossiness texture\n" - "Trade::PbrSpecularGlossinessMaterialData::glossinessTextureCoordinates(): the material doesn't have a glossiness texture\n" - "Trade::MaterialData::attribute(): attribute NormalTexture not found in layer 0\n" - "Trade::PbrSpecularGlossinessMaterialData::normalTextureScale(): the material doesn't have a normal texture\n" - "Trade::PbrSpecularGlossinessMaterialData::normalTextureSwizzle(): the material doesn't have a normal texture\n" - "Trade::PbrSpecularGlossinessMaterialData::normalTextureMatrix(): the material doesn't have a normal texture\n" - "Trade::PbrSpecularGlossinessMaterialData::normalTextureCoordinates(): the material doesn't have a normal texture\n" - "Trade::MaterialData::attribute(): attribute OcclusionTexture not found in layer 0\n" - "Trade::PbrSpecularGlossinessMaterialData::occlusionTextureStrength(): the material doesn't have an occlusion texture\n" - "Trade::PbrSpecularGlossinessMaterialData::occlusionTextureSwizzle(): the material doesn't have an occlusion texture\n" - "Trade::PbrSpecularGlossinessMaterialData::occlusionTextureMatrix(): the material doesn't have an occlusion texture\n" - "Trade::PbrSpecularGlossinessMaterialData::occlusionTextureCoordinates(): the material doesn't have an occlusion texture\n" - "Trade::MaterialData::attribute(): attribute EmissiveTexture not found in layer 0\n" - "Trade::PbrSpecularGlossinessMaterialData::emissiveTextureMatrix(): the material doesn't have an emissive texture\n" - "Trade::PbrSpecularGlossinessMaterialData::emissiveTextureCoordinates(): the material doesn't have an emissive texture\n"); -} - -void MaterialDataTest::pbrSpecularGlossinessAccessCommonTransformationCoordinatesNoTextures() { - PbrSpecularGlossinessMaterialData a{{}, {}}; - CORRADE_VERIFY(a.hasCommonTextureTransformation()); - CORRADE_VERIFY(a.hasCommonTextureCoordinates()); - CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(a.commonTextureCoordinates(), 0); - - PbrSpecularGlossinessMaterialData b{{}, { - {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::TextureCoordinates, 7u} - }}; - CORRADE_VERIFY(b.hasCommonTextureTransformation()); - CORRADE_VERIFY(b.hasCommonTextureCoordinates()); - CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(b.commonTextureCoordinates(), 7); -} - -void MaterialDataTest::pbrSpecularGlossinessAccessCommonTransformationCoordinatesOneTexture() { - Containers::StringView textureName = PbrSpecularGlossinessTextureData[testCaseInstanceId()]; - setTestCaseDescription(textureName); - - PbrSpecularGlossinessMaterialData data{{}, { - {textureName, 5u}, - {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, - {std::string{textureName} + "Coordinates", 17u}, - - /* These shouldn't affect the above */ - {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::TextureCoordinates, 3u} - }}; - - CORRADE_VERIFY(data.hasCommonTextureTransformation()); - CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); - CORRADE_VERIFY(data.hasCommonTextureCoordinates()); - CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); -} - -void MaterialDataTest::pbrSpecularGlossinessAccessCommonTransformationCoordinatesOneDifferentTexture() { - Containers::StringView textureName = PbrSpecularGlossinessTextureData[testCaseInstanceId()]; - setTestCaseDescription(textureName); - - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::DiffuseTexture, 2u}, - {MaterialAttribute::SpecularTexture, 3u}, - {MaterialAttribute::GlossinessTexture, 4u}, - {MaterialAttribute::NormalTexture, 5u}, - {MaterialAttribute::OcclusionTexture, 6u}, - {MaterialAttribute::EmissiveTexture, 7u}, - {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, - {std::string{textureName} + "Coordinates", 17u}, - - /* These are used by all textures except the one above, failing the - check */ - {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::TextureCoordinates, 3u} - }}; - - CORRADE_VERIFY(!data.hasCommonTextureTransformation()); - CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); -} - -void MaterialDataTest::pbrSpecularGlossinessAccessNoCommonTransformationCoordinates() { - #ifdef CORRADE_NO_ASSERT - CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); - #endif - - PbrSpecularGlossinessMaterialData data{{}, { - {MaterialAttribute::DiffuseTexture, 3u}, - {MaterialAttribute::DiffuseTextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::DiffuseTextureCoordinates, 3u}, - {MaterialAttribute::SpecularTexture, 4u}, - {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::OcclusionTexture, 5u}, - {MaterialAttribute::OcclusionTextureCoordinates, 17u} - }}; - - CORRADE_VERIFY(!data.hasCommonTextureTransformation()); - CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); - - std::ostringstream out; - Error redirectError{&out}; - data.commonTextureMatrix(); - data.commonTextureCoordinates(); - CORRADE_COMPARE(out.str(), - "Trade::PbrSpecularGlossinessMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation\n" - "Trade::PbrSpecularGlossinessMaterialData::commonTextureCoordinates(): the material doesn't have a common texture coordinate set\n"); -} - -void MaterialDataTest::phongAccess() { - MaterialData base{MaterialType::Phong, { - {MaterialAttribute::AmbientColor, 0xccffbbff_rgbaf}, - {MaterialAttribute::DiffuseColor, 0xebefbfff_rgbaf}, - {MaterialAttribute::SpecularColor, 0xacabadff_rgbaf}, - {MaterialAttribute::Shininess, 96.0f} - }}; - - CORRADE_COMPARE(base.types(), MaterialType::Phong); - const auto& data = base.as(); - - CORRADE_VERIFY(!data.hasSpecularTexture()); - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.ambientColor(), 0xccffbb_rgbf); - CORRADE_COMPARE(data.diffuseColor(), 0xebefbf_rgbf); - CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); - CORRADE_COMPARE(data.shininess(), 96.0f); -} - -void MaterialDataTest::phongAccessDefaults() { - MaterialData base{{}, {}}; - - CORRADE_COMPARE(base.types(), MaterialTypes{}); - /* Casting is fine even if the type doesn't include Phong */ - const auto& data = base.as(); - - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.ambientColor(), 0x000000_rgbf); - CORRADE_COMPARE(data.diffuseColor(), 0xffffff_rgbf); - CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); - CORRADE_COMPARE(data.shininess(), 80.0f); -} - -void MaterialDataTest::phongAccessTextured() { - PhongMaterialData data{{}, { - {MaterialAttribute::AmbientColor, 0x111111ff_rgbaf}, - {MaterialAttribute::AmbientTexture, 42u}, - {MaterialAttribute::AmbientTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::AmbientTextureCoordinates, 2u}, - {MaterialAttribute::DiffuseTexture, 33u}, - {MaterialAttribute::DiffuseColor, 0xeebbffff_rgbaf}, - {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::DiffuseTextureCoordinates, 3u}, - {MaterialAttribute::SpecularColor, 0xacabadff_rgbaf}, - {MaterialAttribute::SpecularTexture, 17u}, - {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGBA}, - {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, - {MaterialAttribute::SpecularTextureCoordinates, 4u}, - {MaterialAttribute::NormalTexture, 0u}, - {MaterialAttribute::NormalTextureScale, 0.5f}, - {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::GB}, - {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})}, - {MaterialAttribute::NormalTextureCoordinates, 5u} - }}; - - CORRADE_VERIFY(data.hasSpecularTexture()); - CORRADE_VERIFY(data.hasTextureTransformation()); - CORRADE_VERIFY(data.hasTextureCoordinates()); - CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf); - CORRADE_COMPARE(data.ambientTexture(), 42); - CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); - CORRADE_COMPARE(data.ambientTextureCoordinates(), 2); - CORRADE_COMPARE(data.diffuseColor(), 0xeebbff_rgbf); - CORRADE_COMPARE(data.diffuseTexture(), 33); - CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.diffuseTextureCoordinates(), 3); - CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); - CORRADE_COMPARE(data.specularTexture(), 17); - CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGBA); - CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); - CORRADE_COMPARE(data.specularTextureCoordinates(), 4); - CORRADE_COMPARE(data.normalTexture(), 0); - CORRADE_COMPARE(data.normalTextureScale(), 0.5f); - CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::GB); - CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f})); - CORRADE_COMPARE(data.normalTextureCoordinates(), 5); -} - -void MaterialDataTest::phongAccessTexturedDefaults() { - PhongMaterialData data{{}, { - {MaterialAttribute::AmbientTexture, 42u}, - {MaterialAttribute::DiffuseTexture, 33u}, - {MaterialAttribute::SpecularTexture, 17u}, - {MaterialAttribute::NormalTexture, 1u} - }}; - - CORRADE_VERIFY(data.hasSpecularTexture()); - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.ambientColor(), 0xffffffff_rgbaf); - CORRADE_COMPARE(data.ambientTexture(), 42); - CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.ambientTextureCoordinates(), 0); - CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf); - CORRADE_COMPARE(data.diffuseTexture(), 33); - CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.diffuseTextureCoordinates(), 0); - CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); - CORRADE_COMPARE(data.specularTexture(), 17); - CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); - CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.specularTextureCoordinates(), 0); - CORRADE_COMPARE(data.normalTexture(), 1); - CORRADE_COMPARE(data.normalTextureScale(), 1.0f); - CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); - CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.normalTextureCoordinates(), 0); -} - -void MaterialDataTest::phongAccessTexturedSingleMatrixCoordinates() { - PhongMaterialData data{{}, { - {MaterialAttribute::AmbientTexture, 42u}, - {MaterialAttribute::DiffuseTexture, 33u}, - {MaterialAttribute::SpecularTexture, 17u}, - {MaterialAttribute::NormalTexture, 0u}, - {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 1.0f})}, - {MaterialAttribute::TextureCoordinates, 2u} - }}; - - CORRADE_VERIFY(data.hasTextureTransformation()); - CORRADE_VERIFY(data.hasTextureCoordinates()); - CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); - CORRADE_COMPARE(data.ambientTextureCoordinates(), 2); - CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); - CORRADE_COMPARE(data.diffuseTextureCoordinates(), 2); - CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); - CORRADE_COMPARE(data.specularTextureCoordinates(), 2); - CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); - CORRADE_COMPARE(data.normalTextureCoordinates(), 2); -} - -void MaterialDataTest::phongAccessTexturedImplicitPackedSpecularGlossiness() { - PhongMaterialData data{{}, { - {MaterialAttribute::SpecularColor, 0xacabadff_rgbaf}, - {MaterialAttribute::SpecularGlossinessTexture, 17u}, - {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, - {MaterialAttribute::SpecularTextureCoordinates, 4u}, - }}; - - #ifdef MAGNUM_BUILD_DEPRECATED - CORRADE_IGNORE_DEPRECATED_PUSH - CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::SpecularTexture|PhongMaterialData::Flag::TextureCoordinates|PhongMaterialData::Flag::TextureTransformation); - CORRADE_IGNORE_DEPRECATED_POP - #endif - CORRADE_VERIFY(data.hasSpecularTexture()); - CORRADE_VERIFY(data.hasTextureTransformation()); - CORRADE_VERIFY(data.hasTextureCoordinates()); - CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); - CORRADE_COMPARE(data.specularTexture(), 17); - CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); - CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); - CORRADE_COMPARE(data.specularTextureCoordinates(), 4); -} - -void MaterialDataTest::phongAccessInvalidTextures() { - #ifdef CORRADE_NO_ASSERT - CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); - #endif - - PhongMaterialData data{{}, {}}; - - std::ostringstream out; - Error redirectError{&out}; - data.ambientTexture(); - data.ambientTextureMatrix(); - data.ambientTextureCoordinates(); - data.diffuseTexture(); - data.diffuseTextureMatrix(); - data.diffuseTextureCoordinates(); - data.specularTexture(); - data.specularTextureSwizzle(); - data.specularTextureMatrix(); - data.specularTextureCoordinates(); - data.normalTexture(); - data.normalTextureScale(); - data.normalTextureSwizzle(); - data.normalTextureMatrix(); - data.normalTextureCoordinates(); - CORRADE_COMPARE(out.str(), - "Trade::MaterialData::attribute(): attribute AmbientTexture not found in layer 0\n" - "Trade::PhongMaterialData::ambientTextureMatrix(): the material doesn't have an ambient texture\n" - "Trade::PhongMaterialData::ambientTextureCoordinates(): the material doesn't have an ambient texture\n" - "Trade::MaterialData::attribute(): attribute DiffuseTexture not found in layer 0\n" - "Trade::PhongMaterialData::diffuseTextureMatrix(): the material doesn't have a diffuse texture\n" - "Trade::PhongMaterialData::diffuseTextureCoordinates(): the material doesn't have a diffuse texture\n" - "Trade::PhongMaterialData::specularTexture(): the material doesn't have a specular texture\n" - "Trade::PhongMaterialData::specularTextureSwizzle(): the material doesn't have a specular texture\n" - "Trade::PhongMaterialData::specularTextureMatrix(): the material doesn't have a specular texture\n" - "Trade::PhongMaterialData::specularTextureCoordinates(): the material doesn't have a specular texture\n" - "Trade::MaterialData::attribute(): attribute NormalTexture not found in layer 0\n" - "Trade::PhongMaterialData::normalTextureScale(): the material doesn't have a normal texture\n" - "Trade::PhongMaterialData::normalTextureSwizzle(): the material doesn't have a normal texture\n" - "Trade::PhongMaterialData::normalTextureMatrix(): the material doesn't have a normal texture\n" - "Trade::PhongMaterialData::normalTextureCoordinates(): the material doesn't have a normal texture\n"); -} - -void MaterialDataTest::phongAccessCommonTransformationCoordinatesNoTextures() { - PhongMaterialData a{{}, {}}; - CORRADE_VERIFY(a.hasCommonTextureTransformation()); - CORRADE_VERIFY(a.hasCommonTextureCoordinates()); - 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} - }}; - CORRADE_VERIFY(b.hasCommonTextureTransformation()); - 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() { - Containers::StringView textureName = PhongTextureData[testCaseInstanceId()]; - setTestCaseDescription(textureName); - - PhongMaterialData data{{}, { - {textureName, 5u}, - {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, - {std::string{textureName} + "Coordinates", 17u}, - - /* These shouldn't affect the above */ - {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::TextureCoordinates, 3u} - }}; - - CORRADE_VERIFY(data.hasCommonTextureTransformation()); - 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() { - Containers::StringView textureName = PhongTextureData[testCaseInstanceId()]; - setTestCaseDescription(textureName); - - PhongMaterialData data{{}, { - {MaterialAttribute::AmbientTexture, 2u}, - {MaterialAttribute::DiffuseTexture, 3u}, - {MaterialAttribute::SpecularTexture, 4u}, - {MaterialAttribute::NormalTexture, 5u}, - {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, - {std::string{textureName} + "Coordinates", 17u}, - - /* These are used by all textures except the one above, failing the - check */ - {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::TextureCoordinates, 3u} - }}; - - 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() { - #ifdef CORRADE_NO_ASSERT - CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); - #endif - - PhongMaterialData data{{}, { - {MaterialAttribute::DiffuseTexture, 3u}, - {MaterialAttribute::DiffuseTextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::DiffuseTextureCoordinates, 3u}, - {MaterialAttribute::SpecularTexture, 4u}, - {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::NormalTexture, 5u}, - {MaterialAttribute::NormalTextureCoordinates, 17u} - }}; - - CORRADE_VERIFY(!data.hasCommonTextureTransformation()); - CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); - - std::ostringstream out; - Error redirectError{&out}; - data.commonTextureMatrix(); - data.commonTextureCoordinates(); - CORRADE_COMPARE(out.str(), - "Trade::PhongMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation\n" - "Trade::PhongMaterialData::commonTextureCoordinates(): the material doesn't have a common texture coordinate set\n"); -} - -void MaterialDataTest::flatAccessBaseColor() { - MaterialData base{MaterialType::Flat, { - {MaterialAttribute::BaseColor, 0xccffbbff_rgbaf}, - {MaterialAttribute::DiffuseColor, 0x33556600_rgbaf}, /* Ignored */ - }}; - - CORRADE_COMPARE(base.types(), MaterialType::Flat); - const auto& data = base.as(); - - CORRADE_VERIFY(!data.hasTexture()); - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); -} - -void MaterialDataTest::flatAccessDiffuseColor() { - MaterialData base{MaterialType::Flat, { - {MaterialAttribute::DiffuseColor, 0xccffbbff_rgbaf}, - }}; - - CORRADE_COMPARE(base.types(), MaterialType::Flat); - const auto& data = base.as(); - - CORRADE_VERIFY(!data.hasTexture()); - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); -} - -void MaterialDataTest::flatAccessDefaults() { - MaterialData base{{}, {}}; - - CORRADE_COMPARE(base.types(), MaterialTypes{}); - /* Casting is fine even if the type doesn't include Flat */ - const auto& data = base.as(); - - CORRADE_VERIFY(!data.hasTexture()); - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.color(), 0xffffff_rgbf); -} - -void MaterialDataTest::flatAccessTexturedBaseColor() { - FlatMaterialData data{{}, { - {MaterialAttribute::BaseColor, 0xccffbbff_rgbaf}, - {MaterialAttribute::BaseColorTexture, 5u}, - {MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::BaseColorTextureCoordinates, 2u}, - - /* All this is ignored */ - {MaterialAttribute::DiffuseColor, 0x33556600_rgbaf}, - {MaterialAttribute::DiffuseTexture, 6u}, - {MaterialAttribute::DiffuseTextureMatrix, Matrix3::translation({0.5f, 1.0f})}, - {MaterialAttribute::DiffuseTextureCoordinates, 3u} - }}; - - CORRADE_VERIFY(data.hasTexture()); - CORRADE_VERIFY(data.hasTextureTransformation()); - CORRADE_VERIFY(data.hasTextureCoordinates()); - CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); - CORRADE_COMPARE(data.texture(), 5); - CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); - CORRADE_COMPARE(data.textureCoordinates(), 2); -} - -void MaterialDataTest::flatAccessTexturedDiffuseColor() { - FlatMaterialData data{{}, { - {MaterialAttribute::DiffuseColor, 0xccffbbff_rgbaf}, - {MaterialAttribute::DiffuseTexture, 5u}, - {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::DiffuseTextureCoordinates, 2u}, - - /* Ignored, as we have a diffuse texture */ - {MaterialAttribute::BaseColor, 0x33556600_rgbaf} - }}; - - CORRADE_VERIFY(data.hasTexture()); - CORRADE_VERIFY(data.hasTextureTransformation()); - CORRADE_VERIFY(data.hasTextureCoordinates()); - CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); - CORRADE_COMPARE(data.texture(), 5); - CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); - CORRADE_COMPARE(data.textureCoordinates(), 2); -} - -void MaterialDataTest::flatAccessTexturedDefaults() { - FlatMaterialData data{{}, { - {MaterialAttribute::DiffuseTexture, 5u} - }}; - - CORRADE_VERIFY(data.hasTexture()); - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.color(), 0xffffff_rgbf); - CORRADE_COMPARE(data.texture(), 5); - CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.textureCoordinates(), 0); -} - -void MaterialDataTest::flatAccessTexturedBaseColorSingleMatrixCoordinates() { - FlatMaterialData data{{}, { - {MaterialAttribute::BaseColor, 0xccffbbff_rgbaf}, - {MaterialAttribute::BaseColorTexture, 5u}, - {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::TextureCoordinates, 2u}, - - /* This is ignored because it doesn't match the texture */ - {MaterialAttribute::DiffuseTextureMatrix, Matrix3::translation({0.5f, 1.0f})}, - {MaterialAttribute::DiffuseTextureCoordinates, 3u} - }}; - - CORRADE_VERIFY(data.hasTexture()); - CORRADE_VERIFY(data.hasTextureTransformation()); - CORRADE_VERIFY(data.hasTextureCoordinates()); - CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); - CORRADE_COMPARE(data.texture(), 5); - CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); - CORRADE_COMPARE(data.textureCoordinates(), 2); -} - -void MaterialDataTest::flatAccessTexturedDiffuseColorSingleMatrixCoordinates() { - FlatMaterialData data{{}, { - {MaterialAttribute::DiffuseColor, 0xccffbbff_rgbaf}, - {MaterialAttribute::DiffuseTexture, 5u}, - {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::TextureCoordinates, 2u}, - - /* This is ignored because it doesn't match the texture */ - {MaterialAttribute::BaseColorTextureMatrix, Matrix3::translation({0.5f, 1.0f})}, - {MaterialAttribute::BaseColorTextureCoordinates, 3u} - }}; - - CORRADE_VERIFY(data.hasTexture()); - CORRADE_VERIFY(data.hasTextureTransformation()); - CORRADE_VERIFY(data.hasTextureCoordinates()); - CORRADE_COMPARE(data.color(), 0xccffbb_rgbf); - CORRADE_COMPARE(data.texture(), 5); - CORRADE_COMPARE(data.textureMatrix(), Matrix3::scaling({0.5f, 1.0f})); - CORRADE_COMPARE(data.textureCoordinates(), 2); -} - -void MaterialDataTest::flatAccessTexturedMismatchedMatrixCoordinates() { - { - FlatMaterialData data{{}, { - {MaterialAttribute::BaseColorTexture, 5u}, - - /* This is ignored because it doesn't match the texture */ - {MaterialAttribute::DiffuseColor, 0x33556600_rgbaf}, - {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::DiffuseTextureCoordinates, 2u}, - }}; - - CORRADE_VERIFY(data.hasTexture()); - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.color(), 0xffffff_rgbf); - CORRADE_COMPARE(data.texture(), 5); - CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.textureCoordinates(), 0); - } { - FlatMaterialData data{{}, { - {MaterialAttribute::DiffuseTexture, 5u}, - - /* This is ignored because it doesn't match the texture */ - {MaterialAttribute::BaseColor, 0x33556600_rgbaf}, - {MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::BaseColorTextureCoordinates, 2u}, - }}; - - CORRADE_VERIFY(data.hasTexture()); - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.color(), 0xffffff_rgbf); - CORRADE_COMPARE(data.texture(), 5); - CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.textureCoordinates(), 0); - } -} - -void MaterialDataTest::flatAccessInvalidTextures() { - #ifdef CORRADE_NO_ASSERT - CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); - #endif - - FlatMaterialData data{{}, {}}; - - std::ostringstream out; - Error redirectError{&out}; - data.texture(); - data.textureMatrix(); - data.textureCoordinates(); - CORRADE_COMPARE(out.str(), - "Trade::FlatMaterialData::texture(): the material doesn't have a texture\n" - "Trade::FlatMaterialData::textureMatrix(): the material doesn't have a texture\n" - "Trade::FlatMaterialData::textureCoordinates(): the material doesn't have a texture\n"); -} - void MaterialDataTest::templateLayerAccess() { MaterialLayerData data{{}, { {MaterialAttribute::BaseColor, 0x335566ff_rgbaf}, @@ -4573,355 +2431,6 @@ void MaterialDataTest::templateLayerAccess() { CORRADE_COMPARE(data.attributeOr("LayerFactorTexture", 5u), 3); } -void MaterialDataTest::pbrClearCoatAccess() { - MaterialData base{MaterialType::PbrClearCoat, { - {MaterialLayer::ClearCoat}, - {MaterialAttribute::Roughness, 0.7f} - }, {0, 2}}; - - CORRADE_COMPARE(base.types(), MaterialType::PbrClearCoat); - const auto& data = base.as(); - - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.roughness(), 0.7f); -} - -void MaterialDataTest::pbrClearCoatAccessDefaults() { - MaterialData base{{}, { - /* Needs to have at least the layer name, otherwise the queries will - blow up */ - {MaterialLayer::ClearCoat} - }, {0, 1}}; - - CORRADE_COMPARE(base.types(), MaterialTypes{}); - const auto& data = base.as(); - - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.layerFactor(), 1.0f); - CORRADE_COMPARE(data.roughness(), 0.0f); -} - -void MaterialDataTest::pbrClearCoatAccessTextured() { - PbrClearCoatMaterialData data{{}, { - {MaterialLayer::ClearCoat}, - {MaterialAttribute::Roughness, 0.7f}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::A}, - {MaterialAttribute::RoughnessTextureMatrix, Matrix3::translation({2.0f, 1.5f})}, - {MaterialAttribute::RoughnessTextureCoordinates, 6u}, - {MaterialAttribute::NormalTexture, 3u}, - {MaterialAttribute::NormalTextureScale, 0.5f}, - {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::NormalTextureMatrix, Matrix3::translation({0.0f, 0.5f})}, - {MaterialAttribute::NormalTextureCoordinates, 7u}, - }, {0, 11}}; - - CORRADE_VERIFY(data.hasTextureTransformation()); - CORRADE_VERIFY(data.hasTextureCoordinates()); - CORRADE_COMPARE(data.roughness(), 0.7f); - CORRADE_COMPARE(data.roughnessTexture(), 2u); - CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::A); - CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({2.0f, 1.5f})); - CORRADE_COMPARE(data.roughnessTextureCoordinates(), 6u); - CORRADE_COMPARE(data.normalTexture(), 3u); - CORRADE_COMPARE(data.normalTextureScale(), 0.5f); - CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::B); - CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); - CORRADE_COMPARE(data.normalTextureCoordinates(), 7u); -} - -void MaterialDataTest::pbrClearCoatAccessTexturedDefaults() { - PbrClearCoatMaterialData data{{}, { - {MaterialLayer::ClearCoat}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::NormalTexture, 3u}, - }, {0, 3}}; - - CORRADE_VERIFY(!data.hasTextureTransformation()); - CORRADE_VERIFY(!data.hasTextureCoordinates()); - CORRADE_COMPARE(data.roughness(), 0.0f); - CORRADE_COMPARE(data.roughnessTexture(), 2u); - CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::R); - CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0u); - CORRADE_COMPARE(data.normalTexture(), 3u); - CORRADE_COMPARE(data.normalTextureScale(), 1.0f); - CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); - CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.normalTextureCoordinates(), 0u); -} - -void MaterialDataTest::pbrClearCoatAccessTexturedExplicitPackedLayerFactorRoughness() { - /* Just the texture ID and swizzles, the rest is implicit */ - { - PbrClearCoatMaterialData data{{}, { - {MaterialLayer::ClearCoat}, - {MaterialAttribute::LayerFactorTexture, 2u}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G} - }, {0, 4}}; - CORRADE_VERIFY(data.hasLayerFactorRoughnessTexture()); - CORRADE_COMPARE(data.layerFactorTexture(), 2); - CORRADE_COMPARE(data.layerFactorTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.layerFactorTextureCoordinates(), 0); - CORRADE_COMPARE(data.roughnessTexture(), 2); - CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); - CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0); - - /* Explicit parameters for everything, but all the same */ - } { - PbrClearCoatMaterialData data{{}, { - {MaterialLayer::ClearCoat}, - {MaterialAttribute::LayerFactorTexture, 2u}, - {MaterialAttribute::LayerFactorTextureSwizzle, MaterialTextureSwizzle::R}, - {MaterialAttribute::LayerFactorTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::LayerFactorTextureCoordinates, 3u}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::RoughnessTextureCoordinates, 3u} - }, {0, 9}}; - CORRADE_VERIFY(data.hasLayerFactorRoughnessTexture()); - CORRADE_COMPARE(data.layerFactorTexture(), 2); - CORRADE_COMPARE(data.layerFactorTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.layerFactorTextureCoordinates(), 3); - CORRADE_COMPARE(data.roughnessTexture(), 2); - CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); - CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(data.roughnessTextureCoordinates(), 3); - - /* Different texture ID */ - } { - PbrClearCoatMaterialData data{{}, { - {MaterialLayer::ClearCoat}, - {MaterialAttribute::LayerFactorTexture, 2u}, - {MaterialAttribute::RoughnessTexture, 3u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - }, {0, 4}}; - CORRADE_VERIFY(!data.hasLayerFactorRoughnessTexture()); - - /* Unexpected swizzle 1 */ - } { - PbrClearCoatMaterialData data{{}, { - {MaterialLayer::ClearCoat}, - {MaterialAttribute::LayerFactorTexture, 2u}, - {MaterialAttribute::LayerFactorTextureSwizzle, MaterialTextureSwizzle::B}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - }, {0, 5}}; - CORRADE_VERIFY(!data.hasLayerFactorRoughnessTexture()); - - /* Unexpected swizzle 2 */ - } { - PbrClearCoatMaterialData data{{}, { - {MaterialLayer::ClearCoat}, - {MaterialAttribute::LayerFactorTexture, 2u}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B} - }, {0, 4}}; - CORRADE_VERIFY(!data.hasLayerFactorRoughnessTexture()); - - /* Unexpected texture matrix */ - } { - PbrClearCoatMaterialData data{{}, { - {MaterialLayer::ClearCoat}, - {MaterialAttribute::LayerFactorTexture, 2u}, - {MaterialAttribute::LayerFactorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G} - }, {0, 5}}; - CORRADE_VERIFY(!data.hasLayerFactorRoughnessTexture()); - - /* Unexpected texture coordinates */ - } { - PbrClearCoatMaterialData data{{}, { - {MaterialLayer::ClearCoat}, - {MaterialAttribute::LayerFactorTexture, 2u}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, - {MaterialAttribute::RoughnessTextureCoordinates, 1u} - }, {0, 5}}; - CORRADE_VERIFY(!data.hasLayerFactorRoughnessTexture()); - } -} - -void MaterialDataTest::pbrClearCoatAccessTexturedSingleMatrixCoordinates() { - PbrClearCoatMaterialData data{{}, { - {MaterialLayer::ClearCoat}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::NormalTexture, 3u}, - {MaterialAttribute::TextureMatrix, Matrix3::translation({0.0f, 0.5f})}, - {MaterialAttribute::TextureCoordinates, 7u}, - }, {0, 5}}; - - CORRADE_VERIFY(data.hasTextureTransformation()); - CORRADE_VERIFY(data.hasTextureCoordinates()); - CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); - CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7u); - CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); - CORRADE_COMPARE(data.normalTextureCoordinates(), 7u); -} - -void MaterialDataTest::pbrClearCoatAccessTexturedBaseMaterialMatrixCoordinates() { - PbrClearCoatMaterialData data{{}, { - {MaterialAttribute::TextureMatrix, Matrix3::translation({0.0f, 0.5f})}, - {MaterialAttribute::TextureCoordinates, 7u}, - - {MaterialLayer::ClearCoat}, - {MaterialAttribute::RoughnessTexture, 2u}, - {MaterialAttribute::NormalTexture, 3u}, - }, {2, 5}}; - - CORRADE_VERIFY(data.hasTextureTransformation()); - CORRADE_VERIFY(data.hasTextureCoordinates()); - CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); - CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7u); - CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); - CORRADE_COMPARE(data.normalTextureCoordinates(), 7u); - - CORRADE_VERIFY(data.hasCommonTextureTransformation()); - CORRADE_VERIFY(data.hasCommonTextureCoordinates()); - CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); - CORRADE_COMPARE(data.commonTextureCoordinates(), 7); -} - -void MaterialDataTest::pbrClearCoatAccessInvalidTextures() { - #ifdef CORRADE_NO_ASSERT - CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); - #endif - - PbrClearCoatMaterialData data{{}, { - {MaterialLayer::ClearCoat}, - }, {0, 1}}; - - std::ostringstream out; - Error redirectError{&out}; - data.roughnessTexture(); - data.roughnessTextureSwizzle(); - data.roughnessTextureMatrix(); - data.roughnessTextureCoordinates(); - data.normalTexture(); - data.normalTextureScale(); - data.normalTextureSwizzle(); - data.normalTextureMatrix(); - data.normalTextureCoordinates(); - CORRADE_COMPARE(out.str(), - "Trade::MaterialData::attribute(): attribute RoughnessTexture not found in layer ClearCoat\n" - "Trade::PbrClearCoatMaterialData::roughnessTextureSwizzle(): the layer doesn't have a roughness texture\n" - "Trade::PbrClearCoatMaterialData::roughnessTextureMatrix(): the layer doesn't have a roughness texture\n" - "Trade::PbrClearCoatMaterialData::roughnessTextureCoordinates(): the layer doesn't have a roughness texture\n" - "Trade::MaterialData::attribute(): attribute NormalTexture not found in layer ClearCoat\n" - "Trade::PbrClearCoatMaterialData::normalTextureScale(): the layer doesn't have a normal texture\n" - "Trade::PbrClearCoatMaterialData::normalTextureSwizzle(): the layer doesn't have a normal texture\n" - "Trade::PbrClearCoatMaterialData::normalTextureMatrix(): the layer doesn't have a normal texture\n" - "Trade::PbrClearCoatMaterialData::normalTextureCoordinates(): the layer doesn't have a normal texture\n"); -} - -void MaterialDataTest::pbrClearCoatAccessCommonTransformationCoordinatesNoTextures() { - PbrClearCoatMaterialData a{{}, { - {MaterialLayer::ClearCoat}, - }, {0, 1}}; - CORRADE_VERIFY(a.hasCommonTextureTransformation()); - CORRADE_VERIFY(a.hasCommonTextureCoordinates()); - CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); - CORRADE_COMPARE(a.commonTextureCoordinates(), 0); - - PbrClearCoatMaterialData b{{}, { - {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::TextureCoordinates, 7u}, - - {MaterialLayer::ClearCoat} - }, {2, 3}}; - CORRADE_VERIFY(b.hasCommonTextureTransformation()); - CORRADE_VERIFY(b.hasCommonTextureCoordinates()); - CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(b.commonTextureCoordinates(), 7); - - PbrClearCoatMaterialData c{{}, { - {MaterialLayer::ClearCoat}, - {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, - {MaterialAttribute::TextureCoordinates, 7u}, - }, {0, 3}}; - CORRADE_VERIFY(c.hasCommonTextureTransformation()); - CORRADE_VERIFY(c.hasCommonTextureCoordinates()); - CORRADE_COMPARE(c.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); - CORRADE_COMPARE(c.commonTextureCoordinates(), 7); -} - -void MaterialDataTest::pbrClearCoatAccessCommonTransformationCoordinatesOneTexture() { - Containers::StringView textureName = PbrClearCoatTextureData[testCaseInstanceId()]; - setTestCaseDescription(textureName); - - PbrClearCoatMaterialData data{{}, { - /* These shouldn't affect the below */ - {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::TextureCoordinates, 3u}, - - {MaterialLayer::ClearCoat}, - {textureName, 5u}, - {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, - {std::string{textureName} + "Coordinates", 17u}, - }, {2, 6}}; - - CORRADE_VERIFY(data.hasCommonTextureTransformation()); - CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); - CORRADE_VERIFY(data.hasCommonTextureCoordinates()); - CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); -} - -void MaterialDataTest::pbrClearCoatAccessCommonTransformationCoordinatesOneDifferentTexture() { - Containers::StringView textureName = PbrClearCoatTextureData[testCaseInstanceId()]; - setTestCaseDescription(textureName); - - PbrClearCoatMaterialData data{{}, { - /* These are used by all textures except the one below, failing the - check */ - {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::TextureCoordinates, 3u}, - - {MaterialLayer::ClearCoat}, - {MaterialAttribute::LayerFactorTexture, 2u}, - {MaterialAttribute::RoughnessTexture, 3u}, - {MaterialAttribute::NormalTexture, 5u}, - {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, - {std::string{textureName} + "Coordinates", 17u} - }, {2, 8}}; - - CORRADE_VERIFY(!data.hasCommonTextureTransformation()); - CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); -} - -void MaterialDataTest::pbrClearCoatAccessNoCommonTransformationCoordinates() { - #ifdef CORRADE_NO_ASSERT - CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); - #endif - - PbrClearCoatMaterialData data{{}, { - {MaterialLayer::ClearCoat}, - {MaterialAttribute::LayerFactorTexture, 3u}, - {MaterialAttribute::LayerFactorTextureMatrix, Matrix3::translation({0.5f, 0.0f})}, - {MaterialAttribute::LayerFactorTextureCoordinates, 3u}, - {MaterialAttribute::RoughnessTexture, 4u}, - {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, - {MaterialAttribute::NormalTexture, 5u}, - {MaterialAttribute::NormalTextureCoordinates, 17u} - }, {0, 8}}; - - CORRADE_VERIFY(!data.hasCommonTextureTransformation()); - CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); - - std::ostringstream out; - Error redirectError{&out}; - data.commonTextureMatrix(); - data.commonTextureCoordinates(); - CORRADE_COMPARE(out.str(), - "Trade::PbrClearCoatMaterialData::commonTextureMatrix(): the layer doesn't have a common texture coordinate transformation\n" - "Trade::PbrClearCoatMaterialData::commonTextureCoordinates(): the layer doesn't have a common texture coordinate set\n"); -} - void MaterialDataTest::debugLayer() { std::ostringstream out; @@ -4992,24 +2501,6 @@ void MaterialDataTest::debugAlphaMode() { CORRADE_COMPARE(out.str(), "Trade::MaterialAlphaMode::Opaque Trade::MaterialAlphaMode(0xee)\n"); } -#ifdef MAGNUM_BUILD_DEPRECATED -CORRADE_IGNORE_DEPRECATED_PUSH -void MaterialDataTest::debugPhongFlag() { - std::ostringstream out; - - Debug{&out} << PhongMaterialData::Flag::AmbientTexture << PhongMaterialData::Flag(0xf0); - CORRADE_COMPARE(out.str(), "Trade::PhongMaterialData::Flag::AmbientTexture Trade::PhongMaterialData::Flag(0xf0)\n"); -} - -void MaterialDataTest::debugPhongFlags() { - std::ostringstream out; - - Debug{&out} << (PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture) << PhongMaterialData::Flags{}; - CORRADE_COMPARE(out.str(), "Trade::PhongMaterialData::Flag::DiffuseTexture|Trade::PhongMaterialData::Flag::SpecularTexture Trade::PhongMaterialData::Flags{}\n"); -} -CORRADE_IGNORE_DEPRECATED_POP -#endif - }}}} CORRADE_TEST_MAIN(Magnum::Trade::Test::MaterialDataTest) diff --git a/src/Magnum/Trade/Test/PbrClearCoatMaterialDataTest.cpp b/src/Magnum/Trade/Test/PbrClearCoatMaterialDataTest.cpp new file mode 100644 index 000000000..51a051b59 --- /dev/null +++ b/src/Magnum/Trade/Test/PbrClearCoatMaterialDataTest.cpp @@ -0,0 +1,431 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, + 2020 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include +#include +#include + +#include "Magnum/Trade/PbrClearCoatMaterialData.h" + +namespace Magnum { namespace Trade { namespace Test { namespace { + +class PbrClearCoatMaterialDataTest: public TestSuite::Tester { + public: + explicit PbrClearCoatMaterialDataTest(); + + void basics(); + void defaults(); + void textured(); + void texturedDefaults(); + void texturedExplicitPackedLayerFactorRoughness(); + void texturedSingleMatrixCoordinates(); + void texturedBaseMaterialMatrixCoordinates(); + void invalidTextures(); + void commonTransformationCoordinatesNoTextures(); + void commonTransformationCoordinatesOneTexture(); + void commonTransformationCoordinatesOneDifferentTexture(); + void noCommonTransformationCoordinates(); +}; + +const Containers::StringView PbrClearCoatTextureData[] { + "LayerFactorTexture", + "RoughnessTexture", + "NormalTexture" +}; + +PbrClearCoatMaterialDataTest::PbrClearCoatMaterialDataTest() { + addTests({&PbrClearCoatMaterialDataTest::basics, + &PbrClearCoatMaterialDataTest::defaults, + &PbrClearCoatMaterialDataTest::textured, + &PbrClearCoatMaterialDataTest::texturedDefaults, + &PbrClearCoatMaterialDataTest::texturedExplicitPackedLayerFactorRoughness, + &PbrClearCoatMaterialDataTest::texturedSingleMatrixCoordinates, + &PbrClearCoatMaterialDataTest::texturedBaseMaterialMatrixCoordinates, + &PbrClearCoatMaterialDataTest::invalidTextures, + &PbrClearCoatMaterialDataTest::commonTransformationCoordinatesNoTextures}); + + addInstancedTests({ + &PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneTexture, + &PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture}, + Containers::arraySize(PbrClearCoatTextureData)); + + addTests({&PbrClearCoatMaterialDataTest::noCommonTransformationCoordinates}); +} + +using namespace Math::Literals; + +void PbrClearCoatMaterialDataTest::basics() { + MaterialData base{MaterialType::PbrClearCoat, { + {MaterialLayer::ClearCoat}, + {MaterialAttribute::Roughness, 0.7f} + }, {0, 2}}; + + CORRADE_COMPARE(base.types(), MaterialType::PbrClearCoat); + const auto& data = base.as(); + + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.roughness(), 0.7f); +} + +void PbrClearCoatMaterialDataTest::defaults() { + MaterialData base{{}, { + /* Needs to have at least the layer name, otherwise the queries will + blow up */ + {MaterialLayer::ClearCoat} + }, {0, 1}}; + + CORRADE_COMPARE(base.types(), MaterialTypes{}); + const auto& data = base.as(); + + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.layerFactor(), 1.0f); + CORRADE_COMPARE(data.roughness(), 0.0f); +} + +void PbrClearCoatMaterialDataTest::textured() { + PbrClearCoatMaterialData data{{}, { + {MaterialLayer::ClearCoat}, + {MaterialAttribute::Roughness, 0.7f}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::A}, + {MaterialAttribute::RoughnessTextureMatrix, Matrix3::translation({2.0f, 1.5f})}, + {MaterialAttribute::RoughnessTextureCoordinates, 6u}, + {MaterialAttribute::NormalTexture, 3u}, + {MaterialAttribute::NormalTextureScale, 0.5f}, + {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::NormalTextureMatrix, Matrix3::translation({0.0f, 0.5f})}, + {MaterialAttribute::NormalTextureCoordinates, 7u}, + }, {0, 11}}; + + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.roughness(), 0.7f); + CORRADE_COMPARE(data.roughnessTexture(), 2u); + CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::A); + CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({2.0f, 1.5f})); + CORRADE_COMPARE(data.roughnessTextureCoordinates(), 6u); + CORRADE_COMPARE(data.normalTexture(), 3u); + CORRADE_COMPARE(data.normalTextureScale(), 0.5f); + CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::B); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); + CORRADE_COMPARE(data.normalTextureCoordinates(), 7u); +} + +void PbrClearCoatMaterialDataTest::texturedDefaults() { + PbrClearCoatMaterialData data{{}, { + {MaterialLayer::ClearCoat}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::NormalTexture, 3u}, + }, {0, 3}}; + + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.roughness(), 0.0f); + CORRADE_COMPARE(data.roughnessTexture(), 2u); + CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::R); + CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0u); + CORRADE_COMPARE(data.normalTexture(), 3u); + CORRADE_COMPARE(data.normalTextureScale(), 1.0f); + CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.normalTextureCoordinates(), 0u); +} + +void PbrClearCoatMaterialDataTest::texturedExplicitPackedLayerFactorRoughness() { + /* Just the texture ID and swizzles, the rest is implicit */ + { + PbrClearCoatMaterialData data{{}, { + {MaterialLayer::ClearCoat}, + {MaterialAttribute::LayerFactorTexture, 2u}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G} + }, {0, 4}}; + CORRADE_VERIFY(data.hasLayerFactorRoughnessTexture()); + CORRADE_COMPARE(data.layerFactorTexture(), 2); + CORRADE_COMPARE(data.layerFactorTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.layerFactorTextureCoordinates(), 0); + CORRADE_COMPARE(data.roughnessTexture(), 2); + CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); + CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0); + + /* Explicit parameters for everything, but all the same */ + } { + PbrClearCoatMaterialData data{{}, { + {MaterialLayer::ClearCoat}, + {MaterialAttribute::LayerFactorTexture, 2u}, + {MaterialAttribute::LayerFactorTextureSwizzle, MaterialTextureSwizzle::R}, + {MaterialAttribute::LayerFactorTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::LayerFactorTextureCoordinates, 3u}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::RoughnessTextureCoordinates, 3u} + }, {0, 9}}; + CORRADE_VERIFY(data.hasLayerFactorRoughnessTexture()); + CORRADE_COMPARE(data.layerFactorTexture(), 2); + CORRADE_COMPARE(data.layerFactorTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.layerFactorTextureCoordinates(), 3); + CORRADE_COMPARE(data.roughnessTexture(), 2); + CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); + CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.roughnessTextureCoordinates(), 3); + + /* Different texture ID */ + } { + PbrClearCoatMaterialData data{{}, { + {MaterialLayer::ClearCoat}, + {MaterialAttribute::LayerFactorTexture, 2u}, + {MaterialAttribute::RoughnessTexture, 3u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + }, {0, 4}}; + CORRADE_VERIFY(!data.hasLayerFactorRoughnessTexture()); + + /* Unexpected swizzle 1 */ + } { + PbrClearCoatMaterialData data{{}, { + {MaterialLayer::ClearCoat}, + {MaterialAttribute::LayerFactorTexture, 2u}, + {MaterialAttribute::LayerFactorTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + }, {0, 5}}; + CORRADE_VERIFY(!data.hasLayerFactorRoughnessTexture()); + + /* Unexpected swizzle 2 */ + } { + PbrClearCoatMaterialData data{{}, { + {MaterialLayer::ClearCoat}, + {MaterialAttribute::LayerFactorTexture, 2u}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B} + }, {0, 4}}; + CORRADE_VERIFY(!data.hasLayerFactorRoughnessTexture()); + + /* Unexpected texture matrix */ + } { + PbrClearCoatMaterialData data{{}, { + {MaterialLayer::ClearCoat}, + {MaterialAttribute::LayerFactorTexture, 2u}, + {MaterialAttribute::LayerFactorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G} + }, {0, 5}}; + CORRADE_VERIFY(!data.hasLayerFactorRoughnessTexture()); + + /* Unexpected texture coordinates */ + } { + PbrClearCoatMaterialData data{{}, { + {MaterialLayer::ClearCoat}, + {MaterialAttribute::LayerFactorTexture, 2u}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::RoughnessTextureCoordinates, 1u} + }, {0, 5}}; + CORRADE_VERIFY(!data.hasLayerFactorRoughnessTexture()); + } +} + +void PbrClearCoatMaterialDataTest::texturedSingleMatrixCoordinates() { + PbrClearCoatMaterialData data{{}, { + {MaterialLayer::ClearCoat}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::NormalTexture, 3u}, + {MaterialAttribute::TextureMatrix, Matrix3::translation({0.0f, 0.5f})}, + {MaterialAttribute::TextureCoordinates, 7u}, + }, {0, 5}}; + + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); + CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7u); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); + CORRADE_COMPARE(data.normalTextureCoordinates(), 7u); +} + +void PbrClearCoatMaterialDataTest::texturedBaseMaterialMatrixCoordinates() { + PbrClearCoatMaterialData data{{}, { + {MaterialAttribute::TextureMatrix, Matrix3::translation({0.0f, 0.5f})}, + {MaterialAttribute::TextureCoordinates, 7u}, + + {MaterialLayer::ClearCoat}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::NormalTexture, 3u}, + }, {2, 5}}; + + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); + CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7u); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); + CORRADE_COMPARE(data.normalTextureCoordinates(), 7u); + + CORRADE_VERIFY(data.hasCommonTextureTransformation()); + CORRADE_VERIFY(data.hasCommonTextureCoordinates()); + CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::translation({0.0f, 0.5f})); + CORRADE_COMPARE(data.commonTextureCoordinates(), 7); +} + +void PbrClearCoatMaterialDataTest::invalidTextures() { + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + PbrClearCoatMaterialData data{{}, { + {MaterialLayer::ClearCoat}, + }, {0, 1}}; + + std::ostringstream out; + Error redirectError{&out}; + data.roughnessTexture(); + data.roughnessTextureSwizzle(); + data.roughnessTextureMatrix(); + data.roughnessTextureCoordinates(); + data.normalTexture(); + data.normalTextureScale(); + data.normalTextureSwizzle(); + data.normalTextureMatrix(); + data.normalTextureCoordinates(); + CORRADE_COMPARE(out.str(), + "Trade::MaterialData::attribute(): attribute RoughnessTexture not found in layer ClearCoat\n" + "Trade::PbrClearCoatMaterialData::roughnessTextureSwizzle(): the layer doesn't have a roughness texture\n" + "Trade::PbrClearCoatMaterialData::roughnessTextureMatrix(): the layer doesn't have a roughness texture\n" + "Trade::PbrClearCoatMaterialData::roughnessTextureCoordinates(): the layer doesn't have a roughness texture\n" + "Trade::MaterialData::attribute(): attribute NormalTexture not found in layer ClearCoat\n" + "Trade::PbrClearCoatMaterialData::normalTextureScale(): the layer doesn't have a normal texture\n" + "Trade::PbrClearCoatMaterialData::normalTextureSwizzle(): the layer doesn't have a normal texture\n" + "Trade::PbrClearCoatMaterialData::normalTextureMatrix(): the layer doesn't have a normal texture\n" + "Trade::PbrClearCoatMaterialData::normalTextureCoordinates(): the layer doesn't have a normal texture\n"); +} + +void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesNoTextures() { + PbrClearCoatMaterialData a{{}, { + {MaterialLayer::ClearCoat}, + }, {0, 1}}; + CORRADE_VERIFY(a.hasCommonTextureTransformation()); + CORRADE_VERIFY(a.hasCommonTextureCoordinates()); + CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(a.commonTextureCoordinates(), 0); + + PbrClearCoatMaterialData b{{}, { + {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::TextureCoordinates, 7u}, + + {MaterialLayer::ClearCoat} + }, {2, 3}}; + CORRADE_VERIFY(b.hasCommonTextureTransformation()); + CORRADE_VERIFY(b.hasCommonTextureCoordinates()); + CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(b.commonTextureCoordinates(), 7); + + PbrClearCoatMaterialData c{{}, { + {MaterialLayer::ClearCoat}, + {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::TextureCoordinates, 7u}, + }, {0, 3}}; + CORRADE_VERIFY(c.hasCommonTextureTransformation()); + CORRADE_VERIFY(c.hasCommonTextureCoordinates()); + CORRADE_COMPARE(c.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(c.commonTextureCoordinates(), 7); +} + +void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneTexture() { + Containers::StringView textureName = PbrClearCoatTextureData[testCaseInstanceId()]; + setTestCaseDescription(textureName); + + PbrClearCoatMaterialData data{{}, { + /* These shouldn't affect the below */ + {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, + {MaterialAttribute::TextureCoordinates, 3u}, + + {MaterialLayer::ClearCoat}, + {textureName, 5u}, + {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, + {std::string{textureName} + "Coordinates", 17u}, + }, {2, 6}}; + + CORRADE_VERIFY(data.hasCommonTextureTransformation()); + CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); + CORRADE_VERIFY(data.hasCommonTextureCoordinates()); + CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); +} + +void PbrClearCoatMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture() { + Containers::StringView textureName = PbrClearCoatTextureData[testCaseInstanceId()]; + setTestCaseDescription(textureName); + + PbrClearCoatMaterialData data{{}, { + /* These are used by all textures except the one below, failing the + check */ + {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, + {MaterialAttribute::TextureCoordinates, 3u}, + + {MaterialLayer::ClearCoat}, + {MaterialAttribute::LayerFactorTexture, 2u}, + {MaterialAttribute::RoughnessTexture, 3u}, + {MaterialAttribute::NormalTexture, 5u}, + {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, + {std::string{textureName} + "Coordinates", 17u} + }, {2, 8}}; + + CORRADE_VERIFY(!data.hasCommonTextureTransformation()); + CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); +} + +void PbrClearCoatMaterialDataTest::noCommonTransformationCoordinates() { + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + PbrClearCoatMaterialData data{{}, { + {MaterialLayer::ClearCoat}, + {MaterialAttribute::LayerFactorTexture, 3u}, + {MaterialAttribute::LayerFactorTextureMatrix, Matrix3::translation({0.5f, 0.0f})}, + {MaterialAttribute::LayerFactorTextureCoordinates, 3u}, + {MaterialAttribute::RoughnessTexture, 4u}, + {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::NormalTexture, 5u}, + {MaterialAttribute::NormalTextureCoordinates, 17u} + }, {0, 8}}; + + CORRADE_VERIFY(!data.hasCommonTextureTransformation()); + CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); + + std::ostringstream out; + Error redirectError{&out}; + data.commonTextureMatrix(); + data.commonTextureCoordinates(); + CORRADE_COMPARE(out.str(), + "Trade::PbrClearCoatMaterialData::commonTextureMatrix(): the layer doesn't have a common texture coordinate transformation\n" + "Trade::PbrClearCoatMaterialData::commonTextureCoordinates(): the layer doesn't have a common texture coordinate set\n"); +} + +}}}} + +CORRADE_TEST_MAIN(Magnum::Trade::Test::PbrClearCoatMaterialDataTest) diff --git a/src/Magnum/Trade/Test/PbrMetallicRoughnessMaterialDataTest.cpp b/src/Magnum/Trade/Test/PbrMetallicRoughnessMaterialDataTest.cpp new file mode 100644 index 000000000..b11ba38c6 --- /dev/null +++ b/src/Magnum/Trade/Test/PbrMetallicRoughnessMaterialDataTest.cpp @@ -0,0 +1,851 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, + 2020 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include +#include +#include + +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" +#include "Magnum/Trade/PbrMetallicRoughnessMaterialData.h" + +namespace Magnum { namespace Trade { namespace Test { namespace { + +class PbrMetallicRoughnessMaterialDataTest: public TestSuite::Tester { + public: + explicit PbrMetallicRoughnessMaterialDataTest(); + + void basics(); + void defaults(); + void textured(); + void texturedDefaults(); + void texturedImplicitPackedMetallicRoughness(); + void texturedExplicitPackedMetallicRoughness(); + void texturedExplicitPackedRoughnessMetallicOcclusion(); + void texturedExplicitPackedOcclusionRoughnessMetallic(); + void texturedExplicitPackedNormalRoughnessMetallic(); + void texturedSingleMatrixCoordinates(); + void invalidTextures(); + void commonTransformationCoordinatesNoTextures(); + void commonTransformationCoordinatesOneTexture(); + void commonTransformationCoordinatesOneDifferentTexture(); + void noCommonTransformationCoordinates(); +}; + +const Containers::StringView PbrMetallicRoughnessTextureData[] { + "BaseColorTexture", + "MetalnessTexture", + "RoughnessTexture", + "NormalTexture", + "OcclusionTexture", + "EmissiveTexture" +}; + +PbrMetallicRoughnessMaterialDataTest::PbrMetallicRoughnessMaterialDataTest() { + addTests({&PbrMetallicRoughnessMaterialDataTest::basics, + &PbrMetallicRoughnessMaterialDataTest::defaults, + &PbrMetallicRoughnessMaterialDataTest::textured, + &PbrMetallicRoughnessMaterialDataTest::texturedDefaults, + &PbrMetallicRoughnessMaterialDataTest::texturedImplicitPackedMetallicRoughness, + &PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedMetallicRoughness, + &PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedRoughnessMetallicOcclusion, + &PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedOcclusionRoughnessMetallic, + &PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedNormalRoughnessMetallic, + &PbrMetallicRoughnessMaterialDataTest::texturedSingleMatrixCoordinates, + &PbrMetallicRoughnessMaterialDataTest::invalidTextures, + &PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesNoTextures}); + + addInstancedTests({ + &PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneTexture, + &PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture}, + Containers::arraySize(PbrMetallicRoughnessTextureData)); + + addTests({&PbrMetallicRoughnessMaterialDataTest::noCommonTransformationCoordinates}); +} + +using namespace Math::Literals; + +void PbrMetallicRoughnessMaterialDataTest::basics() { + MaterialData base{MaterialType::PbrMetallicRoughness, { + {MaterialAttribute::BaseColor, 0xccffbbff_rgbaf}, + {MaterialAttribute::Metalness, 0.5f}, + {MaterialAttribute::Roughness, 0.79f}, + {MaterialAttribute::EmissiveColor, 0x111111_rgbf} + }}; + + CORRADE_COMPARE(base.types(), MaterialType::PbrMetallicRoughness); + const auto& data = base.as(); + + CORRADE_VERIFY(!data.hasMetalnessTexture()); + CORRADE_VERIFY(!data.hasRoughnessTexture()); + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); + CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); + CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.baseColor(), 0xccffbbff_rgbaf); + CORRADE_COMPARE(data.metalness(), 0.5f); + CORRADE_COMPARE(data.roughness(), 0.79f); + CORRADE_COMPARE(data.emissiveColor(), 0x111111_rgbf); +} + +void PbrMetallicRoughnessMaterialDataTest::defaults() { + MaterialData base{{}, {}}; + + CORRADE_COMPARE(base.types(), MaterialTypes{}); + /* Casting is fine even if the type doesn't include PbrMetallicRoughness */ + const auto& data = base.as(); + + CORRADE_VERIFY(!data.hasMetalnessTexture()); + CORRADE_VERIFY(!data.hasRoughnessTexture()); + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); + CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); + CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.baseColor(), 0xffffffff_rgbaf); + CORRADE_COMPARE(data.metalness(), 1.0f); + CORRADE_COMPARE(data.roughness(), 1.0f); + CORRADE_COMPARE(data.emissiveColor(), 0x000000_rgbf); +} + +void PbrMetallicRoughnessMaterialDataTest::textured() { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::BaseColor, 0xccffbbff_rgbaf}, + {MaterialAttribute::BaseColorTexture, 0u}, + {MaterialAttribute::BaseColorTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::BaseColorTextureCoordinates, 2u}, + {MaterialAttribute::Metalness, 0.5f}, + {MaterialAttribute::MetalnessTexture, 1u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::MetalnessTextureCoordinates, 3u}, + {MaterialAttribute::Roughness, 0.79f}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::A}, + {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, + {MaterialAttribute::RoughnessTextureCoordinates, 4u}, + {MaterialAttribute::NormalTexture, 3u}, + {MaterialAttribute::NormalTextureScale, 0.35f}, + {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::BA}, + {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})}, + {MaterialAttribute::NormalTextureCoordinates, 5u}, + {MaterialAttribute::OcclusionTexture, 4u}, + {MaterialAttribute::OcclusionTextureStrength, 0.66f}, + {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({1.0f, 0.75f})}, + {MaterialAttribute::OcclusionTextureCoordinates, 6u}, + {MaterialAttribute::EmissiveColor, 0x111111_rgbf}, + {MaterialAttribute::EmissiveTexture, 5u}, + {MaterialAttribute::EmissiveTextureMatrix, Matrix3::scaling({0.75f, 0.5f})}, + {MaterialAttribute::EmissiveTextureCoordinates, 7u} + }}; + + CORRADE_VERIFY(data.hasMetalnessTexture()); + CORRADE_VERIFY(data.hasRoughnessTexture()); + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); + CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); + CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.baseColor(), 0xccffbbff_rgbaf); + CORRADE_COMPARE(data.baseColorTexture(), 0); + CORRADE_COMPARE(data.baseColorTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); + CORRADE_COMPARE(data.baseColorTextureCoordinates(), 2); + CORRADE_COMPARE(data.metalness(), 0.5f); + CORRADE_COMPARE(data.metalnessTexture(), 1); + CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::G); + CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.metalnessTextureCoordinates(), 3); + CORRADE_COMPARE(data.roughness(), 0.79f); + CORRADE_COMPARE(data.roughnessTexture(), 2); + CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::A); + CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); + CORRADE_COMPARE(data.roughnessTextureCoordinates(), 4); + CORRADE_COMPARE(data.normalTexture(), 3); + CORRADE_COMPARE(data.normalTextureScale(), 0.35f); + CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::BA); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f})); + CORRADE_COMPARE(data.normalTextureCoordinates(), 5); + CORRADE_COMPARE(data.occlusionTexture(), 4); + CORRADE_COMPARE(data.occlusionTextureStrength(), 0.66f); + CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({1.0f, 0.75f})); + CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::B); + CORRADE_COMPARE(data.occlusionTextureCoordinates(), 6); + CORRADE_COMPARE(data.emissiveColor(), 0x111111_rgbf); + CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.75f, 0.5f})); + CORRADE_COMPARE(data.emissiveTexture(), 5); + CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); +} + +void PbrMetallicRoughnessMaterialDataTest::texturedDefaults() { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::BaseColorTexture, 1u}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::RoughnessTexture, 3u}, + {MaterialAttribute::NormalTexture, 4u}, + {MaterialAttribute::OcclusionTexture, 5u}, + {MaterialAttribute::EmissiveTexture, 6u} + }}; + + CORRADE_VERIFY(data.hasMetalnessTexture()); + CORRADE_VERIFY(data.hasRoughnessTexture()); + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); + CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); + CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.baseColor(), 0xffffffff_rgbaf); + CORRADE_COMPARE(data.baseColorTexture(), 1); + CORRADE_COMPARE(data.baseColorTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.baseColorTextureCoordinates(), 0); + CORRADE_COMPARE(data.metalness(), 1.0f); + CORRADE_COMPARE(data.metalnessTexture(), 2); + CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::R); + CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.metalnessTextureCoordinates(), 0); + CORRADE_COMPARE(data.roughness(), 1.0f); + CORRADE_COMPARE(data.roughnessTexture(), 3); + CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::R); + CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0); + CORRADE_COMPARE(data.normalTexture(), 4); + CORRADE_COMPARE(data.normalTextureScale(), 1.0f); + CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.normalTextureCoordinates(), 0); + CORRADE_COMPARE(data.occlusionTexture(), 5); + CORRADE_COMPARE(data.occlusionTextureStrength(), 1.0f); + CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::R); + CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.occlusionTextureCoordinates(), 0); + CORRADE_COMPARE(data.emissiveColor(), 0x000000_rgbf); + CORRADE_COMPARE(data.emissiveTexture(), 6); + CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.emissiveTextureCoordinates(), 0); +} + +void PbrMetallicRoughnessMaterialDataTest::texturedSingleMatrixCoordinates() { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::BaseColorTexture, 1u}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::RoughnessTexture, 3u}, + {MaterialAttribute::NormalTexture, 4u}, + {MaterialAttribute::OcclusionTexture, 5u}, + {MaterialAttribute::EmissiveTexture, 6u}, + {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::TextureCoordinates, 7u} + }}; + + CORRADE_COMPARE(data.baseColorTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.baseColorTextureCoordinates(), 7); + CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.metalnessTextureCoordinates(), 7); + CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.roughnessTextureCoordinates(), 7); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.normalTextureCoordinates(), 7); + CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.occlusionTextureCoordinates(), 7); + CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); +} + +void PbrMetallicRoughnessMaterialDataTest::texturedImplicitPackedMetallicRoughness() { + /* Just the texture ID, the rest is implicit */ + { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::NoneRoughnessMetallicTexture, 2u}, + }}; + CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); + CORRADE_COMPARE(data.roughnessTexture(), 2); + CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); + CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.roughnessTextureCoordinates(), 0); + CORRADE_COMPARE(data.metalnessTexture(), 2); + CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::B); + CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.metalnessTextureCoordinates(), 0); + + /* Explicit parameters for everything, but all the same */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::NoneRoughnessMetallicTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::RoughnessTextureCoordinates, 3u}, + {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::MetalnessTextureCoordinates, 3u} + }}; + CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); + CORRADE_COMPARE(data.roughnessTexture(), 2); + CORRADE_COMPARE(data.roughnessTextureSwizzle(), MaterialTextureSwizzle::G); + CORRADE_COMPARE(data.roughnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.roughnessTextureCoordinates(), 3); + CORRADE_COMPARE(data.metalnessTexture(), 2); + CORRADE_COMPARE(data.metalnessTextureSwizzle(), MaterialTextureSwizzle::B); + CORRADE_COMPARE(data.metalnessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.metalnessTextureCoordinates(), 3); + + /* Swizzle is ignored when the combined texture is specified, so this is + fine */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::NoneRoughnessMetallicTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, + }}; + CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); + + /* Unexpected texture matrix */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::NoneRoughnessMetallicTexture, 2u}, + {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + }}; + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + + /* Unexpected texture coordinates */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::NoneRoughnessMetallicTexture, 2u}, + {MaterialAttribute::RoughnessTextureCoordinates, 1u}, + }}; + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + } +} + +void PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedMetallicRoughness() { + /* Just the texture IDs and swizzles, the rest is implicit */ + { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B} + }}; + CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); + + /* Explicit parameters for everything, but all the same */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::RoughnessTextureCoordinates, 3u}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::MetalnessTextureCoordinates, 3u} + }}; + CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); + + /* Different texture ID */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::MetalnessTexture, 3u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B} + }}; + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + + /* One texture missing */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + }}; + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + + /* Unexpected swizzle */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::R}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, + }}; + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + + /* Unexpected texture matrix */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + }}; + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + + /* Unexpected texture coordinates */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::RoughnessTextureCoordinates, 1u}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, + }}; + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + } +} + +void PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedRoughnessMetallicOcclusion() { + /* Just the texture IDs and swizzles, the rest is implicit */ + { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::OcclusionTexture, 2u}, + {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, + }}; + CORRADE_VERIFY(data.hasRoughnessMetallicOcclusionTexture()); + /* This isn't a superset */ + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + + /* Explicit parameters for everything, but all the same */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::R}, + {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::RoughnessTextureCoordinates, 3u}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::MetalnessTextureCoordinates, 3u}, + {MaterialAttribute::OcclusionTexture, 2u}, + {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::OcclusionTextureCoordinates, 3u} + }}; + CORRADE_VERIFY(data.hasRoughnessMetallicOcclusionTexture()); + /* This isn't a superset */ + CORRADE_VERIFY(!data.hasNoneRoughnessMetallicTexture()); + + /* Different texture ID */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::MetalnessTexture, 3u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::OcclusionTexture, 2u}, + {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, + }}; + CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); + + /* One texture missing */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, + }}; + CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); + + /* Unexpected swizzle */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::A}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::OcclusionTexture, 2u}, + {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, + }}; + CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); + + /* Unexpected texture matrix */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::OcclusionTexture, 2u}, + {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + }}; + CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); + + /* Unexpected texture coordinates */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::OcclusionTexture, 2u}, + {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::MetalnessTextureCoordinates, 1u}, + }}; + CORRADE_VERIFY(!data.hasRoughnessMetallicOcclusionTexture()); + } +} + +void PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedOcclusionRoughnessMetallic() { + /* Just the texture IDs and swizzles, the rest is implicit */ + { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::OcclusionTexture, 2u}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, + }}; + CORRADE_VERIFY(data.hasOcclusionRoughnessMetallicTexture()); + /* This is a superset */ + CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); + + /* Explicit parameters for everything, but all the same */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::OcclusionTexture, 2u}, + {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::R}, + {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::OcclusionTextureCoordinates, 3u}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::RoughnessTextureCoordinates, 3u}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::MetalnessTextureCoordinates, 3u} + }}; + CORRADE_VERIFY(data.hasOcclusionRoughnessMetallicTexture()); + /* This is a superset */ + CORRADE_VERIFY(data.hasNoneRoughnessMetallicTexture()); + + /* Different texture ID */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::OcclusionTexture, 2u}, + {MaterialAttribute::RoughnessTexture, 3u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, + }}; + CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); + + /* One texture missing */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, + }}; + CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); + + /* Unexpected swizzle */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::OcclusionTexture, 2u}, + {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::A}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, + }}; + CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); + + /* Unexpected texture matrix */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::OcclusionTexture, 2u}, + {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, + }}; + CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); + + /* Unexpected texture coordinates */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::OcclusionTexture, 2u}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::G}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::MetalnessTextureCoordinates, 1u}, + }}; + CORRADE_VERIFY(!data.hasOcclusionRoughnessMetallicTexture()); + } +} + +void PbrMetallicRoughnessMaterialDataTest::texturedExplicitPackedNormalRoughnessMetallic() { + /* Just the texture IDs and swizzles, the rest is implicit */ + { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::NormalTexture, 2u}, + {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::RG}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A} + }}; + CORRADE_VERIFY(data.hasNormalRoughnessMetallicTexture()); + + /* Explicit parameters for everything, but all the same */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::NormalTexture, 2u}, + {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::RG}, + {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::NormalTextureCoordinates, 3u}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::RoughnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::RoughnessTextureCoordinates, 3u}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A}, + {MaterialAttribute::MetalnessTextureCoordinates, 3u} + }}; + CORRADE_VERIFY(data.hasNormalRoughnessMetallicTexture()); + + /* Different texture ID */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::NormalTexture, 2u}, + {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::RG}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::MetalnessTexture, 3u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A} + }}; + CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); + + /* One texture missing */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A}, + }}; + CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); + + /* Unexpected swizzle */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::NormalTexture, 2u}, + {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::RGB}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A}, + }}; + CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); + + /* Unexpected texture matrix */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::NormalTexture, 2u}, + {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::RG}, + {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A}, + }}; + CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); + + /* Unexpected texture coordinates */ + } { + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::NormalTexture, 2u}, + {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::RG}, + {MaterialAttribute::RoughnessTexture, 2u}, + {MaterialAttribute::RoughnessTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::MetalnessTexture, 2u}, + {MaterialAttribute::MetalnessTextureSwizzle, MaterialTextureSwizzle::A}, + {MaterialAttribute::MetalnessTextureCoordinates, 1u}, + }}; + CORRADE_VERIFY(!data.hasNormalRoughnessMetallicTexture()); + } +} + +void PbrMetallicRoughnessMaterialDataTest::invalidTextures() { + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + PbrMetallicRoughnessMaterialData data{{}, {}}; + + std::ostringstream out; + Error redirectError{&out}; + data.baseColorTexture(); + data.baseColorTextureMatrix(); + data.baseColorTextureCoordinates(); + data.metalnessTexture(); + data.metalnessTextureSwizzle(); + data.metalnessTextureMatrix(); + data.metalnessTextureCoordinates(); + data.roughnessTexture(); + data.roughnessTextureSwizzle(); + data.roughnessTextureMatrix(); + data.roughnessTextureCoordinates(); + data.normalTexture(); + data.normalTextureScale(); + data.normalTextureSwizzle(); + data.normalTextureMatrix(); + data.normalTextureCoordinates(); + data.occlusionTexture(); + data.occlusionTextureStrength(); + data.occlusionTextureSwizzle(); + data.occlusionTextureMatrix(); + data.occlusionTextureCoordinates(); + data.emissiveTexture(); + data.emissiveTextureMatrix(); + data.emissiveTextureCoordinates(); + CORRADE_COMPARE(out.str(), + "Trade::MaterialData::attribute(): attribute BaseColorTexture not found in layer 0\n" + "Trade::PbrMetallicRoughnessMaterialData::baseColorTextureMatrix(): the material doesn't have a base color texture\n" + "Trade::PbrMetallicRoughnessMaterialData::baseColorTextureCoordinates(): the material doesn't have a base color texture\n" + "Trade::PbrMetallicRoughnessMaterialData::metalnessTexture(): the material doesn't have a metalness texture\n" + "Trade::PbrMetallicRoughnessMaterialData::metalnessTextureSwizzle(): the material doesn't have a metalness texture\n" + "Trade::PbrMetallicRoughnessMaterialData::metalnessTextureMatrix(): the material doesn't have a metalness texture\n" + "Trade::PbrMetallicRoughnessMaterialData::metalnessTextureCoordinates(): the material doesn't have a metalness texture\n" + "Trade::PbrMetallicRoughnessMaterialData::roughnessTexture(): the material doesn't have a roughness texture\n" + "Trade::PbrMetallicRoughnessMaterialData::roughnessTextureSwizzle(): the material doesn't have a roughness texture\n" + "Trade::PbrMetallicRoughnessMaterialData::roughnessTextureMatrix(): the material doesn't have a roughness texture\n" + "Trade::PbrMetallicRoughnessMaterialData::roughnessTextureCoordinates(): the material doesn't have a roughness texture\n" + "Trade::MaterialData::attribute(): attribute NormalTexture not found in layer 0\n" + "Trade::PbrMetallicRoughnessMaterialData::normalTextureScale(): the material doesn't have a normal texture\n" + "Trade::PbrMetallicRoughnessMaterialData::normalTextureSwizzle(): the material doesn't have a normal texture\n" + "Trade::PbrMetallicRoughnessMaterialData::normalTextureMatrix(): the material doesn't have a normal texture\n" + "Trade::PbrMetallicRoughnessMaterialData::normalTextureCoordinates(): the material doesn't have a normal texture\n" + "Trade::MaterialData::attribute(): attribute OcclusionTexture not found in layer 0\n" + "Trade::PbrMetallicRoughnessMaterialData::occlusionTextureStrength(): the material doesn't have an occlusion texture\n" + "Trade::PbrMetallicRoughnessMaterialData::occlusionTextureSwizzle(): the material doesn't have an occlusion texture\n" + "Trade::PbrMetallicRoughnessMaterialData::occlusionTextureMatrix(): the material doesn't have an occlusion texture\n" + "Trade::PbrMetallicRoughnessMaterialData::occlusionTextureCoordinates(): the material doesn't have an occlusion texture\n" + "Trade::MaterialData::attribute(): attribute EmissiveTexture not found in layer 0\n" + "Trade::PbrMetallicRoughnessMaterialData::emissiveTextureMatrix(): the material doesn't have an emissive texture\n" + "Trade::PbrMetallicRoughnessMaterialData::emissiveTextureCoordinates(): the material doesn't have an emissive texture\n"); +} + +void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesNoTextures() { + PbrMetallicRoughnessMaterialData a{{}, {}}; + CORRADE_VERIFY(a.hasCommonTextureTransformation()); + CORRADE_VERIFY(a.hasCommonTextureCoordinates()); + CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(a.commonTextureCoordinates(), 0); + + PbrMetallicRoughnessMaterialData b{{}, { + {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::TextureCoordinates, 7u} + }}; + CORRADE_VERIFY(b.hasCommonTextureTransformation()); + CORRADE_VERIFY(b.hasCommonTextureCoordinates()); + CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(b.commonTextureCoordinates(), 7); +} + +void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneTexture() { + Containers::StringView textureName = PbrMetallicRoughnessTextureData[testCaseInstanceId()]; + setTestCaseDescription(textureName); + + PbrMetallicRoughnessMaterialData data{{}, { + {textureName, 5u}, + {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, + {std::string{textureName} + "Coordinates", 17u}, + + /* These shouldn't affect the above */ + {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, + {MaterialAttribute::TextureCoordinates, 3u} + }}; + + CORRADE_VERIFY(data.hasCommonTextureTransformation()); + CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); + CORRADE_VERIFY(data.hasCommonTextureCoordinates()); + CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); +} + +void PbrMetallicRoughnessMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture() { + Containers::StringView textureName = PbrMetallicRoughnessTextureData[testCaseInstanceId()]; + setTestCaseDescription(textureName); + + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::BaseColorTexture, 2u}, + {MaterialAttribute::MetalnessTexture, 3u}, + {MaterialAttribute::RoughnessTexture, 4u}, + {MaterialAttribute::NormalTexture, 5u}, + {MaterialAttribute::OcclusionTexture, 6u}, + {MaterialAttribute::EmissiveTexture, 7u}, + {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, + {std::string{textureName} + "Coordinates", 17u}, + + /* These are used by all textures except the one above, failing the + check */ + {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, + {MaterialAttribute::TextureCoordinates, 3u} + }}; + + CORRADE_VERIFY(!data.hasCommonTextureTransformation()); + CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); +} + +void PbrMetallicRoughnessMaterialDataTest::noCommonTransformationCoordinates() { + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + PbrMetallicRoughnessMaterialData data{{}, { + {MaterialAttribute::BaseColorTexture, 3u}, + {MaterialAttribute::BaseColorTextureMatrix, Matrix3::translation({0.5f, 0.0f})}, + {MaterialAttribute::BaseColorTextureCoordinates, 3u}, + {MaterialAttribute::MetalnessTexture, 4u}, + {MaterialAttribute::MetalnessTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::RoughnessTexture, 5u}, + {MaterialAttribute::RoughnessTextureCoordinates, 17u} + }}; + + CORRADE_VERIFY(!data.hasCommonTextureTransformation()); + CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); + + std::ostringstream out; + Error redirectError{&out}; + data.commonTextureMatrix(); + data.commonTextureCoordinates(); + CORRADE_COMPARE(out.str(), + "Trade::PbrMetallicRoughnessMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation\n" + "Trade::PbrMetallicRoughnessMaterialData::commonTextureCoordinates(): the material doesn't have a common texture coordinate set\n"); +} + +}}}} + +CORRADE_TEST_MAIN(Magnum::Trade::Test::PbrMetallicRoughnessMaterialDataTest) diff --git a/src/Magnum/Trade/Test/PbrSpecularGlossinessMaterialDataTest.cpp b/src/Magnum/Trade/Test/PbrSpecularGlossinessMaterialDataTest.cpp new file mode 100644 index 000000000..94f5c24cf --- /dev/null +++ b/src/Magnum/Trade/Test/PbrSpecularGlossinessMaterialDataTest.cpp @@ -0,0 +1,567 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, + 2020 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include +#include +#include + +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" +#include "Magnum/Trade/PbrSpecularGlossinessMaterialData.h" + +namespace Magnum { namespace Trade { namespace Test { namespace { + +class PbrSpecularGlossinessMaterialDataTest: public TestSuite::Tester { + public: + explicit PbrSpecularGlossinessMaterialDataTest(); + + void basics(); + void defaults(); + void textured(); + void texturedDefaults(); + void texturedImplicitPackedSpecularGlossiness(); + void texturedExplicitPackedSpecularGlossiness(); + void texturedSingleMatrixCoordinates(); + void invalidTextures(); + void commonTransformationCoordinatesNoTextures(); + void commonTransformationCoordinatesOneTexture(); + void commonTransformationCoordinatesOneDifferentTexture(); + void noCommonTransformationCoordinates(); +}; + +const Containers::StringView PbrSpecularGlossinessTextureData[] { + "DiffuseTexture", + "SpecularTexture", + "GlossinessTexture", + "NormalTexture", + "OcclusionTexture", + "EmissiveTexture" +}; + +PbrSpecularGlossinessMaterialDataTest::PbrSpecularGlossinessMaterialDataTest() { + addTests({&PbrSpecularGlossinessMaterialDataTest::basics, + &PbrSpecularGlossinessMaterialDataTest::defaults, + &PbrSpecularGlossinessMaterialDataTest::textured, + &PbrSpecularGlossinessMaterialDataTest::texturedDefaults, + &PbrSpecularGlossinessMaterialDataTest::texturedImplicitPackedSpecularGlossiness, + &PbrSpecularGlossinessMaterialDataTest::texturedExplicitPackedSpecularGlossiness, + &PbrSpecularGlossinessMaterialDataTest::texturedSingleMatrixCoordinates, + &PbrSpecularGlossinessMaterialDataTest::invalidTextures, + &PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesNoTextures}); + + addInstancedTests({ + &PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneTexture, + &PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture}, + Containers::arraySize(PbrSpecularGlossinessTextureData)); + + addTests({&PbrSpecularGlossinessMaterialDataTest::noCommonTransformationCoordinates}); +} + +using namespace Math::Literals; + +void PbrSpecularGlossinessMaterialDataTest::basics() { + MaterialData base{MaterialType::PbrSpecularGlossiness, { + {MaterialAttribute::DiffuseColor, 0xccffbbff_rgbaf}, + {MaterialAttribute::SpecularColor, 0xff336600_rgbaf}, + {MaterialAttribute::Glossiness, 0.79f}, + {MaterialAttribute::EmissiveColor, 0x111111_rgbf} + }}; + + CORRADE_COMPARE(base.types(), MaterialType::PbrSpecularGlossiness); + const auto& data = base.as(); + + CORRADE_VERIFY(!data.hasSpecularTexture()); + CORRADE_VERIFY(!data.hasGlossinessTexture()); + CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.diffuseColor(), 0xccffbbff_rgbaf); + CORRADE_COMPARE(data.specularColor(), 0xff336600_rgbaf); + CORRADE_COMPARE(data.glossiness(), 0.79f); +} + +void PbrSpecularGlossinessMaterialDataTest::defaults() { + MaterialData base{{}, {}}; + + CORRADE_COMPARE(base.types(), MaterialTypes{}); + /* Casting is fine even if the type doesn't include PbrMetallicRoughness */ + const auto& data = base.as(); + + CORRADE_VERIFY(!data.hasSpecularTexture()); + CORRADE_VERIFY(!data.hasGlossinessTexture()); + CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf); + CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); + CORRADE_COMPARE(data.glossiness(), 1.0f); +} + +void PbrSpecularGlossinessMaterialDataTest::textured() { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::DiffuseColor, 0xccffbbff_rgbaf}, + {MaterialAttribute::DiffuseTexture, 0u}, + {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::DiffuseTextureCoordinates, 2u}, + {MaterialAttribute::SpecularColor, 0x33556600_rgbaf}, + {MaterialAttribute::SpecularTexture, 1u}, + {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGBA}, + {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::SpecularTextureCoordinates, 3u}, + {MaterialAttribute::Glossiness, 0.79f}, + {MaterialAttribute::GlossinessTexture, 2u}, + {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, + {MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, + {MaterialAttribute::GlossinessTextureCoordinates, 4u}, + {MaterialAttribute::NormalTexture, 3u}, + {MaterialAttribute::NormalTextureScale, 0.35f}, + {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::BA}, + {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})}, + {MaterialAttribute::NormalTextureCoordinates, 5u}, + {MaterialAttribute::OcclusionTexture, 4u}, + {MaterialAttribute::OcclusionTextureStrength, 0.66f}, + {MaterialAttribute::OcclusionTextureSwizzle, MaterialTextureSwizzle::B}, + {MaterialAttribute::OcclusionTextureMatrix, Matrix3::scaling({1.0f, 0.75f})}, + {MaterialAttribute::OcclusionTextureCoordinates, 6u}, + {MaterialAttribute::EmissiveColor, 0x111111_rgbf}, + {MaterialAttribute::EmissiveTexture, 5u}, + {MaterialAttribute::EmissiveTextureMatrix, Matrix3::scaling({0.75f, 0.5f})}, + {MaterialAttribute::EmissiveTextureCoordinates, 7u} + }}; + + CORRADE_VERIFY(data.hasSpecularTexture()); + CORRADE_VERIFY(data.hasGlossinessTexture()); + CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.diffuseColor(), 0xccffbbff_rgbaf); + CORRADE_COMPARE(data.diffuseTexture(), 0); + CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); + CORRADE_COMPARE(data.diffuseTextureCoordinates(), 2); + CORRADE_COMPARE(data.specularColor(), 0x33556600_rgbaf); + CORRADE_COMPARE(data.specularTexture(), 1); + CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGBA); + CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.specularTextureCoordinates(), 3); + CORRADE_COMPARE(data.glossiness(), 0.79f); + CORRADE_COMPARE(data.glossinessTexture(), 2); + CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); + CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); + CORRADE_COMPARE(data.glossinessTextureCoordinates(), 4); + CORRADE_COMPARE(data.normalTexture(), 3); + CORRADE_COMPARE(data.normalTextureScale(), 0.35f); + CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::BA); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f})); + CORRADE_COMPARE(data.normalTextureCoordinates(), 5); + CORRADE_COMPARE(data.occlusionTexture(), 4); + CORRADE_COMPARE(data.occlusionTextureStrength(), 0.66f); + CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({1.0f, 0.75f})); + CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::B); + CORRADE_COMPARE(data.occlusionTextureCoordinates(), 6); + CORRADE_COMPARE(data.emissiveColor(), 0x111111_rgbf); + CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.75f, 0.5f})); + CORRADE_COMPARE(data.emissiveTexture(), 5); + CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); +} + +void PbrSpecularGlossinessMaterialDataTest::texturedDefaults() { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::DiffuseTexture, 1u}, + {MaterialAttribute::SpecularTexture, 2u}, + {MaterialAttribute::GlossinessTexture, 3u}, + {MaterialAttribute::NormalTexture, 4u}, + {MaterialAttribute::OcclusionTexture, 5u}, + {MaterialAttribute::EmissiveTexture, 6u} + }}; + + CORRADE_VERIFY(data.hasSpecularTexture()); + CORRADE_VERIFY(data.hasGlossinessTexture()); + CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf); + CORRADE_COMPARE(data.diffuseTexture(), 1); + CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.diffuseTextureCoordinates(), 0); + CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); + CORRADE_COMPARE(data.specularTexture(), 2); + CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); + CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.specularTextureCoordinates(), 0); + CORRADE_COMPARE(data.glossiness(), 1.0f); + CORRADE_COMPARE(data.glossinessTexture(), 3); + CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::R); + CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0); + CORRADE_COMPARE(data.normalTexture(), 4); + CORRADE_COMPARE(data.normalTextureScale(), 1.0f); + CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.normalTextureCoordinates(), 0); + CORRADE_COMPARE(data.occlusionTexture(), 5); + CORRADE_COMPARE(data.occlusionTextureStrength(), 1.0f); + CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.occlusionTextureSwizzle(), MaterialTextureSwizzle::R); + CORRADE_COMPARE(data.occlusionTextureCoordinates(), 0); + CORRADE_COMPARE(data.emissiveColor(), 0x000000_rgbf); + CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.emissiveTexture(), 6); + CORRADE_COMPARE(data.emissiveTextureCoordinates(), 0); +} + +void PbrSpecularGlossinessMaterialDataTest::texturedSingleMatrixCoordinates() { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::DiffuseTexture, 1u}, + {MaterialAttribute::SpecularTexture, 2u}, + {MaterialAttribute::GlossinessTexture, 3u}, + {MaterialAttribute::NormalTexture, 4u}, + {MaterialAttribute::OcclusionTexture, 5u}, + {MaterialAttribute::EmissiveTexture, 6u}, + {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::TextureCoordinates, 7u} + }}; + + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.diffuseTextureCoordinates(), 7); + CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.specularTextureCoordinates(), 7); + CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.glossinessTextureCoordinates(), 7); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.normalTextureCoordinates(), 7); + CORRADE_COMPARE(data.occlusionTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.occlusionTextureCoordinates(), 7); + CORRADE_COMPARE(data.emissiveTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.emissiveTextureCoordinates(), 7); +} + +void PbrSpecularGlossinessMaterialDataTest::texturedImplicitPackedSpecularGlossiness() { + /* Just the texture ID, the rest is implicit */ + { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::SpecularGlossinessTexture, 2u}, + }}; + CORRADE_VERIFY(data.hasSpecularGlossinessTexture()); + CORRADE_COMPARE(data.specularTexture(), 2); + CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); + CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.specularTextureCoordinates(), 0); + CORRADE_COMPARE(data.glossinessTexture(), 2); + CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); + CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0); + + /* Explicit parameters for everything, but all the same */ + } { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::SpecularGlossinessTexture, 2u}, + {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGB}, + {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::SpecularTextureCoordinates, 3u}, + {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, + {MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::GlossinessTextureCoordinates, 3u} + }}; + CORRADE_VERIFY(data.hasSpecularGlossinessTexture()); + CORRADE_COMPARE(data.specularTexture(), 2); + CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); + CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.specularTextureCoordinates(), 3); + CORRADE_COMPARE(data.glossinessTexture(), 2); + CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); + CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.glossinessTextureCoordinates(), 3); + + /* Swizzle is ignored when the combined texture is specified, so this is + fine. */ + } { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::SpecularGlossinessTexture, 2u}, + {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::B}, + }}; + CORRADE_VERIFY(data.hasSpecularGlossinessTexture()); + + /* Unexpected texture matrix */ + } { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::SpecularGlossinessTexture, 2u}, + {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + }}; + CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); + + /* Unexpected texture coordinates */ + } { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::SpecularGlossinessTexture, 2u}, + {MaterialAttribute::GlossinessTextureCoordinates, 1u}, + }}; + CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); + } +} + +void PbrSpecularGlossinessMaterialDataTest::texturedExplicitPackedSpecularGlossiness() { + /* Just the texture ID and swizzles, the rest is implicit */ + { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::SpecularTexture, 2u}, + {MaterialAttribute::GlossinessTexture, 2u}, + {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A} + }}; + CORRADE_VERIFY(data.hasSpecularGlossinessTexture()); + CORRADE_COMPARE(data.specularTexture(), 2); + CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); + CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.specularTextureCoordinates(), 0); + CORRADE_COMPARE(data.glossinessTexture(), 2); + CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); + CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.glossinessTextureCoordinates(), 0); + + /* Explicit parameters for everything, but all the same */ + } { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::SpecularTexture, 2u}, + {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGB}, + {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::SpecularTextureCoordinates, 3u}, + {MaterialAttribute::GlossinessTexture, 2u}, + {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, + {MaterialAttribute::GlossinessTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::GlossinessTextureCoordinates, 3u} + }}; + CORRADE_VERIFY(data.hasSpecularGlossinessTexture()); + CORRADE_COMPARE(data.specularTexture(), 2); + CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); + CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.specularTextureCoordinates(), 3); + CORRADE_COMPARE(data.glossinessTexture(), 2); + CORRADE_COMPARE(data.glossinessTextureSwizzle(), MaterialTextureSwizzle::A); + CORRADE_COMPARE(data.glossinessTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.glossinessTextureCoordinates(), 3); + + /* Different texture ID */ + } { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::SpecularTexture, 2u}, + {MaterialAttribute::GlossinessTexture, 3u}, + {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A} + }}; + CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); + + /* Unexpected swizzle 1 */ + } { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::SpecularTexture, 2u}, + {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGBA}, + {MaterialAttribute::GlossinessTexture, 2u}, + {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A} + }}; + CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); + + /* Unexpected swizzle 2 */ + } { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::SpecularTexture, 2u}, + {MaterialAttribute::GlossinessTexture, 2u}, + {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::B} + }}; + CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); + + /* Unexpected texture matrix */ + } { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::SpecularTexture, 2u}, + {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::GlossinessTexture, 2u}, + {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A} + }}; + CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); + + /* Unexpected texture coordinates */ + } { + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::SpecularTexture, 2u}, + {MaterialAttribute::GlossinessTexture, 2u}, + {MaterialAttribute::GlossinessTextureSwizzle, MaterialTextureSwizzle::A}, + {MaterialAttribute::GlossinessTextureCoordinates, 1u} + }}; + CORRADE_VERIFY(!data.hasSpecularGlossinessTexture()); + } +} + +void PbrSpecularGlossinessMaterialDataTest::invalidTextures() { + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + PbrSpecularGlossinessMaterialData data{{}, {}}; + + std::ostringstream out; + Error redirectError{&out}; + data.diffuseTexture(); + data.diffuseTextureMatrix(); + data.diffuseTextureCoordinates(); + data.specularTexture(); + data.specularTextureSwizzle(); + data.specularTextureMatrix(); + data.specularTextureCoordinates(); + data.glossinessTexture(); + data.glossinessTextureSwizzle(); + data.glossinessTextureMatrix(); + data.glossinessTextureCoordinates(); + data.normalTexture(); + data.normalTextureScale(); + data.normalTextureSwizzle(); + data.normalTextureMatrix(); + data.normalTextureCoordinates(); + data.occlusionTexture(); + data.occlusionTextureStrength(); + data.occlusionTextureSwizzle(); + data.occlusionTextureMatrix(); + data.occlusionTextureCoordinates(); + data.emissiveTexture(); + data.emissiveTextureMatrix(); + data.emissiveTextureCoordinates(); + CORRADE_COMPARE(out.str(), + "Trade::MaterialData::attribute(): attribute DiffuseTexture not found in layer 0\n" + "Trade::PbrSpecularGlossinessMaterialData::diffuseTextureMatrix(): the material doesn't have a diffuse texture\n" + "Trade::PbrSpecularGlossinessMaterialData::diffuseTextureCoordinates(): the material doesn't have a diffuse texture\n" + "Trade::PbrSpecularGlossinessMaterialData::specularTexture(): the material doesn't have a specular texture\n" + "Trade::PbrSpecularGlossinessMaterialData::specularTextureSwizzle(): the material doesn't have a specular texture\n" + "Trade::PbrSpecularGlossinessMaterialData::specularTextureMatrix(): the material doesn't have a specular texture\n" + "Trade::PbrSpecularGlossinessMaterialData::specularTextureCoordinates(): the material doesn't have a specular texture\n" + "Trade::PbrSpecularGlossinessMaterialData::glossinessTexture(): the material doesn't have a glossiness texture\n" + "Trade::PbrSpecularGlossinessMaterialData::glossinessTextureSwizzle(): the material doesn't have a glossiness texture\n" + "Trade::PbrSpecularGlossinessMaterialData::glossinessTextureMatrix(): the material doesn't have a glossiness texture\n" + "Trade::PbrSpecularGlossinessMaterialData::glossinessTextureCoordinates(): the material doesn't have a glossiness texture\n" + "Trade::MaterialData::attribute(): attribute NormalTexture not found in layer 0\n" + "Trade::PbrSpecularGlossinessMaterialData::normalTextureScale(): the material doesn't have a normal texture\n" + "Trade::PbrSpecularGlossinessMaterialData::normalTextureSwizzle(): the material doesn't have a normal texture\n" + "Trade::PbrSpecularGlossinessMaterialData::normalTextureMatrix(): the material doesn't have a normal texture\n" + "Trade::PbrSpecularGlossinessMaterialData::normalTextureCoordinates(): the material doesn't have a normal texture\n" + "Trade::MaterialData::attribute(): attribute OcclusionTexture not found in layer 0\n" + "Trade::PbrSpecularGlossinessMaterialData::occlusionTextureStrength(): the material doesn't have an occlusion texture\n" + "Trade::PbrSpecularGlossinessMaterialData::occlusionTextureSwizzle(): the material doesn't have an occlusion texture\n" + "Trade::PbrSpecularGlossinessMaterialData::occlusionTextureMatrix(): the material doesn't have an occlusion texture\n" + "Trade::PbrSpecularGlossinessMaterialData::occlusionTextureCoordinates(): the material doesn't have an occlusion texture\n" + "Trade::MaterialData::attribute(): attribute EmissiveTexture not found in layer 0\n" + "Trade::PbrSpecularGlossinessMaterialData::emissiveTextureMatrix(): the material doesn't have an emissive texture\n" + "Trade::PbrSpecularGlossinessMaterialData::emissiveTextureCoordinates(): the material doesn't have an emissive texture\n"); +} + +void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesNoTextures() { + PbrSpecularGlossinessMaterialData a{{}, {}}; + CORRADE_VERIFY(a.hasCommonTextureTransformation()); + CORRADE_VERIFY(a.hasCommonTextureCoordinates()); + CORRADE_COMPARE(a.commonTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(a.commonTextureCoordinates(), 0); + + PbrSpecularGlossinessMaterialData b{{}, { + {MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::TextureCoordinates, 7u} + }}; + CORRADE_VERIFY(b.hasCommonTextureTransformation()); + CORRADE_VERIFY(b.hasCommonTextureCoordinates()); + CORRADE_COMPARE(b.commonTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(b.commonTextureCoordinates(), 7); +} + +void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneTexture() { + Containers::StringView textureName = PbrSpecularGlossinessTextureData[testCaseInstanceId()]; + setTestCaseDescription(textureName); + + PbrSpecularGlossinessMaterialData data{{}, { + {textureName, 5u}, + {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, + {std::string{textureName} + "Coordinates", 17u}, + + /* These shouldn't affect the above */ + {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, + {MaterialAttribute::TextureCoordinates, 3u} + }}; + + CORRADE_VERIFY(data.hasCommonTextureTransformation()); + CORRADE_COMPARE(data.commonTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); + CORRADE_VERIFY(data.hasCommonTextureCoordinates()); + CORRADE_COMPARE(data.commonTextureCoordinates(), 17u); +} + +void PbrSpecularGlossinessMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture() { + Containers::StringView textureName = PbrSpecularGlossinessTextureData[testCaseInstanceId()]; + setTestCaseDescription(textureName); + + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::DiffuseTexture, 2u}, + {MaterialAttribute::SpecularTexture, 3u}, + {MaterialAttribute::GlossinessTexture, 4u}, + {MaterialAttribute::NormalTexture, 5u}, + {MaterialAttribute::OcclusionTexture, 6u}, + {MaterialAttribute::EmissiveTexture, 7u}, + {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, + {std::string{textureName} + "Coordinates", 17u}, + + /* These are used by all textures except the one above, failing the + check */ + {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, + {MaterialAttribute::TextureCoordinates, 3u} + }}; + + CORRADE_VERIFY(!data.hasCommonTextureTransformation()); + CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); +} + +void PbrSpecularGlossinessMaterialDataTest::noCommonTransformationCoordinates() { + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + PbrSpecularGlossinessMaterialData data{{}, { + {MaterialAttribute::DiffuseTexture, 3u}, + {MaterialAttribute::DiffuseTextureMatrix, Matrix3::translation({0.5f, 0.0f})}, + {MaterialAttribute::DiffuseTextureCoordinates, 3u}, + {MaterialAttribute::SpecularTexture, 4u}, + {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::OcclusionTexture, 5u}, + {MaterialAttribute::OcclusionTextureCoordinates, 17u} + }}; + + CORRADE_VERIFY(!data.hasCommonTextureTransformation()); + CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); + + std::ostringstream out; + Error redirectError{&out}; + data.commonTextureMatrix(); + data.commonTextureCoordinates(); + CORRADE_COMPARE(out.str(), + "Trade::PbrSpecularGlossinessMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation\n" + "Trade::PbrSpecularGlossinessMaterialData::commonTextureCoordinates(): the material doesn't have a common texture coordinate set\n"); +} + +}}}} + +CORRADE_TEST_MAIN(Magnum::Trade::Test::PbrSpecularGlossinessMaterialDataTest) diff --git a/src/Magnum/Trade/Test/PhongMaterialDataTest.cpp b/src/Magnum/Trade/Test/PhongMaterialDataTest.cpp new file mode 100644 index 000000000..d45d1b214 --- /dev/null +++ b/src/Magnum/Trade/Test/PhongMaterialDataTest.cpp @@ -0,0 +1,633 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, + 2020 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include +#include +#include + +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" +#include "Magnum/Trade/PhongMaterialData.h" + +namespace Magnum { namespace Trade { namespace Test { namespace { + +class PhongMaterialDataTest: public TestSuite::Tester { + public: + explicit PhongMaterialDataTest(); + + #ifdef MAGNUM_BUILD_DEPRECATED + void constructDeprecated(); + void constructDeprecatedTextured(); + void constructDeprecatedTexturedTextureTransform(); + void constructDeprecatedTexturedCoordinates(); + void constructDeprecatedTextureTransformNoTextures(); + void constructDeprecatedNoTextureTransformationFlag(); + void constructDeprecatedNoTextureCoordinatesFlag(); + #endif + + void basics(); + void defaults(); + void textured(); + void texturedDefaults(); + void texturedSingleMatrixCoordinates(); + void texturedImplicitPackedSpecularGlossiness(); + void invalidTextures(); + void commonTransformationCoordinatesNoTextures(); + void commonTransformationCoordinatesOneTexture(); + void commonTransformationCoordinatesOneDifferentTexture(); + void noCommonTransformationCoordinates(); + + #ifdef MAGNUM_BUILD_DEPRECATED + void debugFlag(); + void debugFlags(); + #endif +}; + +const Containers::StringView PhongTextureData[] { + "AmbientTexture", + "DiffuseTexture", + "SpecularTexture", + "NormalTexture" +}; + +PhongMaterialDataTest::PhongMaterialDataTest() { + addTests({ + #ifdef MAGNUM_BUILD_DEPRECATED + &PhongMaterialDataTest::constructDeprecated, + &PhongMaterialDataTest::constructDeprecatedTextured, + &PhongMaterialDataTest::constructDeprecatedTexturedTextureTransform, + &PhongMaterialDataTest::constructDeprecatedTexturedCoordinates, + &PhongMaterialDataTest::constructDeprecatedTextureTransformNoTextures, + &PhongMaterialDataTest::constructDeprecatedNoTextureTransformationFlag, + &PhongMaterialDataTest::constructDeprecatedNoTextureCoordinatesFlag, + #endif + + &PhongMaterialDataTest::basics, + &PhongMaterialDataTest::defaults, + &PhongMaterialDataTest::textured, + &PhongMaterialDataTest::texturedDefaults, + &PhongMaterialDataTest::texturedSingleMatrixCoordinates, + &PhongMaterialDataTest::texturedImplicitPackedSpecularGlossiness, + &PhongMaterialDataTest::invalidTextures, + &PhongMaterialDataTest::commonTransformationCoordinatesNoTextures}); + + addInstancedTests({ + &PhongMaterialDataTest::commonTransformationCoordinatesOneTexture, + &PhongMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture}, + Containers::arraySize(PhongTextureData)); + + addTests({ + &PhongMaterialDataTest::noCommonTransformationCoordinates, + #ifdef MAGNUM_BUILD_DEPRECATED + &PhongMaterialDataTest::debugFlag, + &PhongMaterialDataTest::debugFlags + #endif + }); +} + +using namespace Containers::Literals; +using namespace Math::Literals; + +#ifdef MAGNUM_BUILD_DEPRECATED +void PhongMaterialDataTest::constructDeprecated() { + const int a{}; + CORRADE_IGNORE_DEPRECATED_PUSH + PhongMaterialData data{PhongMaterialData::Flag::DoubleSided, + 0xccffbb_rgbf, {}, + 0xebefbf_rgbf, {}, + 0xacabad_rgbf, {}, {}, {}, + MaterialAlphaMode::Mask, 0.3f, 80.0f, &a}; + CORRADE_IGNORE_DEPRECATED_POP + + CORRADE_COMPARE(data.types(), MaterialType::Phong); + CORRADE_IGNORE_DEPRECATED_PUSH + CORRADE_COMPARE(data.type(), MaterialType::Phong); + CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::DoubleSided); + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(data.ambientColor(), 0xccffbb_rgbf); + CORRADE_COMPARE(data.diffuseColor(), 0xebefbf_rgbf); + CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); + CORRADE_IGNORE_DEPRECATED_PUSH + CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(data.alphaMode(), MaterialAlphaMode::Mask); + CORRADE_COMPARE(data.alphaMask(), 0.3f); + CORRADE_COMPARE(data.shininess(), 80.0f); + CORRADE_COMPARE(data.importerState(), &a); +} + +void PhongMaterialDataTest::constructDeprecatedTextured() { + const int a{}; + CORRADE_IGNORE_DEPRECATED_PUSH + PhongMaterialData data{ + PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture, + 0x111111_rgbf, 42, + 0xeebbff_rgbf, {}, + 0xacabad_rgbf, 17, {}, {}, + MaterialAlphaMode::Blend, 0.37f, 96.0f, &a}; + CORRADE_IGNORE_DEPRECATED_POP + + CORRADE_COMPARE(data.types(), MaterialType::Phong); + CORRADE_IGNORE_DEPRECATED_PUSH + CORRADE_COMPARE(data.type(), MaterialType::Phong); + CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture); + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf); + CORRADE_COMPARE(data.ambientTexture(), 42); + CORRADE_COMPARE(data.ambientTextureCoordinates(), 0); + CORRADE_COMPARE(data.diffuseColor(), 0xeebbff_rgbf); + CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); + CORRADE_COMPARE(data.specularTexture(), 17); + CORRADE_COMPARE(data.specularTextureCoordinates(), 0); + CORRADE_IGNORE_DEPRECATED_PUSH + CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(data.alphaMode(), MaterialAlphaMode::Blend); + CORRADE_COMPARE(data.alphaMask(), 0.37f); + CORRADE_COMPARE(data.shininess(), 96.0f); + CORRADE_COMPARE(data.importerState(), &a); +} + +void PhongMaterialDataTest::constructDeprecatedTexturedTextureTransform() { + const int a{}; + CORRADE_IGNORE_DEPRECATED_PUSH + PhongMaterialData data{ + PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureTransformation, + 0x111111_rgbf, {}, + 0xeebbff_rgbf, 42, + 0xacabad_rgbf, {}, 17, + Matrix3::rotation(90.0_degf), + MaterialAlphaMode::Mask, 0.5f, 96.0f, &a}; + CORRADE_IGNORE_DEPRECATED_POP + + CORRADE_COMPARE(data.types(), MaterialType::Phong); + CORRADE_IGNORE_DEPRECATED_PUSH + CORRADE_COMPARE(data.type(), MaterialType::Phong); + CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureTransformation); + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf); + CORRADE_COMPARE(data.diffuseColor(), 0xeebbff_rgbf); + CORRADE_COMPARE(data.diffuseTexture(), 42); + CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); + CORRADE_COMPARE(data.normalTexture(), 17); + CORRADE_IGNORE_DEPRECATED_PUSH + CORRADE_COMPARE(data.textureMatrix(), Matrix3::rotation(90.0_degf)); + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(data.alphaMode(), MaterialAlphaMode::Mask); + CORRADE_COMPARE(data.alphaMask(), 0.5f); + CORRADE_COMPARE(data.shininess(), 96.0f); + CORRADE_COMPARE(data.importerState(), &a); +} + +void PhongMaterialDataTest::constructDeprecatedTexturedCoordinates() { + const int a{}; + CORRADE_IGNORE_DEPRECATED_PUSH + PhongMaterialData data{ + PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureCoordinates, + 0x111111_rgbf, 42, 3, + 0xeebbff_rgbf, {}, 6, + 0xacabad_rgbf, 17, 1, + 0, 8, {}, + MaterialAlphaMode::Blend, 0.37f, 96.0f, &a}; + CORRADE_IGNORE_DEPRECATED_POP + + CORRADE_COMPARE(data.types(), MaterialType::Phong); + CORRADE_IGNORE_DEPRECATED_PUSH + CORRADE_COMPARE(data.type(), MaterialType::Phong); + CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureCoordinates); + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf); + CORRADE_COMPARE(data.ambientTexture(), 42); + CORRADE_COMPARE(data.ambientTextureCoordinates(), 3); + CORRADE_COMPARE(data.diffuseColor(), 0xeebbff_rgbf); + CORRADE_COMPARE(data.diffuseTextureCoordinates(), 6); + CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); + CORRADE_COMPARE(data.specularTexture(), 17); + CORRADE_COMPARE(data.specularTextureCoordinates(), 1); + CORRADE_COMPARE(data.normalTexture(), 0); + CORRADE_COMPARE(data.normalTextureCoordinates(), 8); + CORRADE_IGNORE_DEPRECATED_PUSH + CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(data.ambientTextureCoordinates(), 3); + CORRADE_COMPARE(data.alphaMode(), MaterialAlphaMode::Blend); + CORRADE_COMPARE(data.alphaMask(), 0.37f); + CORRADE_COMPARE(data.shininess(), 96.0f); + CORRADE_COMPARE(data.importerState(), &a); +} + +void PhongMaterialDataTest::constructDeprecatedTextureTransformNoTextures() { + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + std::ostringstream out; + Error redirectError{&out}; + CORRADE_IGNORE_DEPRECATED_PUSH + PhongMaterialData a{PhongMaterialData::Flag::TextureTransformation, + {}, {}, + {}, {}, + {}, {}, {}, {}, + {}, 0.5f, 80.0f}; + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(out.str(), + "Trade::PhongMaterialData: texture transformation enabled but the material has no textures\n"); +} + +void PhongMaterialDataTest::constructDeprecatedNoTextureTransformationFlag() { + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + std::ostringstream out; + Error redirectError{&out}; + CORRADE_IGNORE_DEPRECATED_PUSH + PhongMaterialData a{{}, + {}, {}, + {}, {}, + {}, {}, {}, Matrix3::rotation(90.0_degf), + {}, 0.5f, 80.0f}; + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(out.str(), + "PhongMaterialData::PhongMaterialData: non-default texture matrix requires Flag::TextureTransformation to be enabled\n"); +} + +void PhongMaterialDataTest::constructDeprecatedNoTextureCoordinatesFlag() { + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + std::ostringstream out; + Error redirectError{&out}; + CORRADE_IGNORE_DEPRECATED_PUSH + PhongMaterialData a{{}, + {}, {}, 1, + {}, {}, 2, + {}, {}, 3, {}, 4, {}, + {}, 0.5f, 80.0f}; + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(out.str(), + "PhongMaterialData::PhongMaterialData: non-zero texture coordinate sets require Flag::TextureCoordinates to be enabled\n"); +} +#endif + +void PhongMaterialDataTest::basics() { + MaterialData base{MaterialType::Phong, { + {MaterialAttribute::AmbientColor, 0xccffbbff_rgbaf}, + {MaterialAttribute::DiffuseColor, 0xebefbfff_rgbaf}, + {MaterialAttribute::SpecularColor, 0xacabadff_rgbaf}, + {MaterialAttribute::Shininess, 96.0f} + }}; + + CORRADE_COMPARE(base.types(), MaterialType::Phong); + const auto& data = base.as(); + + CORRADE_VERIFY(!data.hasSpecularTexture()); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.ambientColor(), 0xccffbb_rgbf); + CORRADE_COMPARE(data.diffuseColor(), 0xebefbf_rgbf); + CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); + CORRADE_COMPARE(data.shininess(), 96.0f); +} + +void PhongMaterialDataTest::defaults() { + MaterialData base{{}, {}}; + + CORRADE_COMPARE(base.types(), MaterialTypes{}); + /* Casting is fine even if the type doesn't include Phong */ + const auto& data = base.as(); + + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.ambientColor(), 0x000000_rgbf); + CORRADE_COMPARE(data.diffuseColor(), 0xffffff_rgbf); + CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); + CORRADE_COMPARE(data.shininess(), 80.0f); +} + +void PhongMaterialDataTest::textured() { + PhongMaterialData data{{}, { + {MaterialAttribute::AmbientColor, 0x111111ff_rgbaf}, + {MaterialAttribute::AmbientTexture, 42u}, + {MaterialAttribute::AmbientTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::AmbientTextureCoordinates, 2u}, + {MaterialAttribute::DiffuseTexture, 33u}, + {MaterialAttribute::DiffuseColor, 0xeebbffff_rgbaf}, + {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::DiffuseTextureCoordinates, 3u}, + {MaterialAttribute::SpecularColor, 0xacabadff_rgbaf}, + {MaterialAttribute::SpecularTexture, 17u}, + {MaterialAttribute::SpecularTextureSwizzle, MaterialTextureSwizzle::RGBA}, + {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, + {MaterialAttribute::SpecularTextureCoordinates, 4u}, + {MaterialAttribute::NormalTexture, 0u}, + {MaterialAttribute::NormalTextureScale, 0.5f}, + {MaterialAttribute::NormalTextureSwizzle, MaterialTextureSwizzle::GB}, + {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})}, + {MaterialAttribute::NormalTextureCoordinates, 5u} + }}; + + CORRADE_VERIFY(data.hasSpecularTexture()); + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf); + CORRADE_COMPARE(data.ambientTexture(), 42); + CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); + CORRADE_COMPARE(data.ambientTextureCoordinates(), 2); + CORRADE_COMPARE(data.diffuseColor(), 0xeebbff_rgbf); + CORRADE_COMPARE(data.diffuseTexture(), 33); + CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.diffuseTextureCoordinates(), 3); + CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); + CORRADE_COMPARE(data.specularTexture(), 17); + CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGBA); + CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); + CORRADE_COMPARE(data.specularTextureCoordinates(), 4); + CORRADE_COMPARE(data.normalTexture(), 0); + CORRADE_COMPARE(data.normalTextureScale(), 0.5f); + CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::GB); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f})); + CORRADE_COMPARE(data.normalTextureCoordinates(), 5); +} + +void PhongMaterialDataTest::texturedDefaults() { + PhongMaterialData data{{}, { + {MaterialAttribute::AmbientTexture, 42u}, + {MaterialAttribute::DiffuseTexture, 33u}, + {MaterialAttribute::SpecularTexture, 17u}, + {MaterialAttribute::NormalTexture, 1u} + }}; + + CORRADE_VERIFY(data.hasSpecularTexture()); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.ambientColor(), 0xffffffff_rgbaf); + CORRADE_COMPARE(data.ambientTexture(), 42); + CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.ambientTextureCoordinates(), 0); + CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf); + CORRADE_COMPARE(data.diffuseTexture(), 33); + CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.diffuseTextureCoordinates(), 0); + CORRADE_COMPARE(data.specularColor(), 0xffffff00_rgbaf); + CORRADE_COMPARE(data.specularTexture(), 17); + CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); + CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.specularTextureCoordinates(), 0); + CORRADE_COMPARE(data.normalTexture(), 1); + CORRADE_COMPARE(data.normalTextureScale(), 1.0f); + CORRADE_COMPARE(data.normalTextureSwizzle(), MaterialTextureSwizzle::RGB); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.normalTextureCoordinates(), 0); +} + +void PhongMaterialDataTest::texturedSingleMatrixCoordinates() { + PhongMaterialData data{{}, { + {MaterialAttribute::AmbientTexture, 42u}, + {MaterialAttribute::DiffuseTexture, 33u}, + {MaterialAttribute::SpecularTexture, 17u}, + {MaterialAttribute::NormalTexture, 0u}, + {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 1.0f})}, + {MaterialAttribute::TextureCoordinates, 2u} + }}; + + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); + CORRADE_COMPARE(data.ambientTextureCoordinates(), 2); + CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); + CORRADE_COMPARE(data.diffuseTextureCoordinates(), 2); + CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); + CORRADE_COMPARE(data.specularTextureCoordinates(), 2); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); + CORRADE_COMPARE(data.normalTextureCoordinates(), 2); +} + +void PhongMaterialDataTest::texturedImplicitPackedSpecularGlossiness() { + PhongMaterialData data{{}, { + {MaterialAttribute::SpecularColor, 0xacabadff_rgbaf}, + {MaterialAttribute::SpecularGlossinessTexture, 17u}, + {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, + {MaterialAttribute::SpecularTextureCoordinates, 4u}, + }}; + + #ifdef MAGNUM_BUILD_DEPRECATED + CORRADE_IGNORE_DEPRECATED_PUSH + CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::SpecularTexture|PhongMaterialData::Flag::TextureCoordinates|PhongMaterialData::Flag::TextureTransformation); + CORRADE_IGNORE_DEPRECATED_POP + #endif + CORRADE_VERIFY(data.hasSpecularTexture()); + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); + CORRADE_COMPARE(data.specularTexture(), 17); + CORRADE_COMPARE(data.specularTextureSwizzle(), MaterialTextureSwizzle::RGB); + CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); + CORRADE_COMPARE(data.specularTextureCoordinates(), 4); +} + +void PhongMaterialDataTest::invalidTextures() { + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + PhongMaterialData data{{}, {}}; + + std::ostringstream out; + Error redirectError{&out}; + data.ambientTexture(); + data.ambientTextureMatrix(); + data.ambientTextureCoordinates(); + data.diffuseTexture(); + data.diffuseTextureMatrix(); + data.diffuseTextureCoordinates(); + data.specularTexture(); + data.specularTextureSwizzle(); + data.specularTextureMatrix(); + data.specularTextureCoordinates(); + data.normalTexture(); + data.normalTextureScale(); + data.normalTextureSwizzle(); + data.normalTextureMatrix(); + data.normalTextureCoordinates(); + CORRADE_COMPARE(out.str(), + "Trade::MaterialData::attribute(): attribute AmbientTexture not found in layer 0\n" + "Trade::PhongMaterialData::ambientTextureMatrix(): the material doesn't have an ambient texture\n" + "Trade::PhongMaterialData::ambientTextureCoordinates(): the material doesn't have an ambient texture\n" + "Trade::MaterialData::attribute(): attribute DiffuseTexture not found in layer 0\n" + "Trade::PhongMaterialData::diffuseTextureMatrix(): the material doesn't have a diffuse texture\n" + "Trade::PhongMaterialData::diffuseTextureCoordinates(): the material doesn't have a diffuse texture\n" + "Trade::PhongMaterialData::specularTexture(): the material doesn't have a specular texture\n" + "Trade::PhongMaterialData::specularTextureSwizzle(): the material doesn't have a specular texture\n" + "Trade::PhongMaterialData::specularTextureMatrix(): the material doesn't have a specular texture\n" + "Trade::PhongMaterialData::specularTextureCoordinates(): the material doesn't have a specular texture\n" + "Trade::MaterialData::attribute(): attribute NormalTexture not found in layer 0\n" + "Trade::PhongMaterialData::normalTextureScale(): the material doesn't have a normal texture\n" + "Trade::PhongMaterialData::normalTextureSwizzle(): the material doesn't have a normal texture\n" + "Trade::PhongMaterialData::normalTextureMatrix(): the material doesn't have a normal texture\n" + "Trade::PhongMaterialData::normalTextureCoordinates(): the material doesn't have a normal texture\n"); +} + +void PhongMaterialDataTest::commonTransformationCoordinatesNoTextures() { + PhongMaterialData a{{}, {}}; + CORRADE_VERIFY(a.hasCommonTextureTransformation()); + CORRADE_VERIFY(a.hasCommonTextureCoordinates()); + 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} + }}; + CORRADE_VERIFY(b.hasCommonTextureTransformation()); + 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 PhongMaterialDataTest::commonTransformationCoordinatesOneTexture() { + Containers::StringView textureName = PhongTextureData[testCaseInstanceId()]; + setTestCaseDescription(textureName); + + PhongMaterialData data{{}, { + {textureName, 5u}, + {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, + {std::string{textureName} + "Coordinates", 17u}, + + /* These shouldn't affect the above */ + {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, + {MaterialAttribute::TextureCoordinates, 3u} + }}; + + CORRADE_VERIFY(data.hasCommonTextureTransformation()); + 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 PhongMaterialDataTest::commonTransformationCoordinatesOneDifferentTexture() { + Containers::StringView textureName = PhongTextureData[testCaseInstanceId()]; + setTestCaseDescription(textureName); + + PhongMaterialData data{{}, { + {MaterialAttribute::AmbientTexture, 2u}, + {MaterialAttribute::DiffuseTexture, 3u}, + {MaterialAttribute::SpecularTexture, 4u}, + {MaterialAttribute::NormalTexture, 5u}, + {std::string{textureName} + "Matrix", Matrix3::scaling({0.5f, 1.0f})}, + {std::string{textureName} + "Coordinates", 17u}, + + /* These are used by all textures except the one above, failing the + check */ + {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 0.0f})}, + {MaterialAttribute::TextureCoordinates, 3u} + }}; + + 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 PhongMaterialDataTest::noCommonTransformationCoordinates() { + #ifdef CORRADE_NO_ASSERT + CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); + #endif + + PhongMaterialData data{{}, { + {MaterialAttribute::DiffuseTexture, 3u}, + {MaterialAttribute::DiffuseTextureMatrix, Matrix3::translation({0.5f, 0.0f})}, + {MaterialAttribute::DiffuseTextureCoordinates, 3u}, + {MaterialAttribute::SpecularTexture, 4u}, + {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::NormalTexture, 5u}, + {MaterialAttribute::NormalTextureCoordinates, 17u} + }}; + + CORRADE_VERIFY(!data.hasCommonTextureTransformation()); + CORRADE_VERIFY(!data.hasCommonTextureCoordinates()); + + std::ostringstream out; + Error redirectError{&out}; + data.commonTextureMatrix(); + data.commonTextureCoordinates(); + CORRADE_COMPARE(out.str(), + "Trade::PhongMaterialData::commonTextureMatrix(): the material doesn't have a common texture coordinate transformation\n" + "Trade::PhongMaterialData::commonTextureCoordinates(): the material doesn't have a common texture coordinate set\n"); +} + +#ifdef MAGNUM_BUILD_DEPRECATED +CORRADE_IGNORE_DEPRECATED_PUSH +void PhongMaterialDataTest::debugFlag() { + std::ostringstream out; + + Debug{&out} << PhongMaterialData::Flag::AmbientTexture << PhongMaterialData::Flag(0xf0); + CORRADE_COMPARE(out.str(), "Trade::PhongMaterialData::Flag::AmbientTexture Trade::PhongMaterialData::Flag(0xf0)\n"); +} + +void PhongMaterialDataTest::debugFlags() { + std::ostringstream out; + + Debug{&out} << (PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture) << PhongMaterialData::Flags{}; + CORRADE_COMPARE(out.str(), "Trade::PhongMaterialData::Flag::DiffuseTexture|Trade::PhongMaterialData::Flag::SpecularTexture Trade::PhongMaterialData::Flags{}\n"); +} +CORRADE_IGNORE_DEPRECATED_POP +#endif + +}}}} + +CORRADE_TEST_MAIN(Magnum::Trade::Test::PhongMaterialDataTest)