From a84721d4b7a22186a08f87815001caeb0406a40b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 8 Aug 2020 18:43:24 +0200 Subject: [PATCH] Trade: clearer asserts for "packable" textures. In these cases there can be more than one attribute, so complaining that just one particular attribute is not found is misleading. --- src/Magnum/Trade/PbrMetallicRoughnessMaterialData.cpp | 8 ++++++++ src/Magnum/Trade/PbrSpecularGlossinessMaterialData.cpp | 8 ++++++++ src/Magnum/Trade/PhongMaterialData.cpp | 4 ++++ src/Magnum/Trade/Test/MaterialDataTest.cpp | 10 +++++----- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Magnum/Trade/PbrMetallicRoughnessMaterialData.cpp b/src/Magnum/Trade/PbrMetallicRoughnessMaterialData.cpp index 951fd0f95..1070211c7 100644 --- a/src/Magnum/Trade/PbrMetallicRoughnessMaterialData.cpp +++ b/src/Magnum/Trade/PbrMetallicRoughnessMaterialData.cpp @@ -152,6 +152,10 @@ Float PbrMetallicRoughnessMaterialData::metalness() const { } UnsignedInt PbrMetallicRoughnessMaterialData::metalnessTexture() const { + /* Explicit assertion because printing that MetalnessTexture isn't found + would be misleading as it can be also MetallicRoughnessTexture */ + CORRADE_ASSERT(hasMetalnessTexture(), + "Trade::PbrMetallicRoughnessMaterialData::metalnessTexture(): the material doesn't have a metalness texture", {}); if(Containers::Optional value = tryAttribute(MaterialAttribute::MetallicRoughnessTexture)) return *value; return attribute(MaterialAttribute::MetalnessTexture); @@ -186,6 +190,10 @@ Float PbrMetallicRoughnessMaterialData::roughness() const { } UnsignedInt PbrMetallicRoughnessMaterialData::roughnessTexture() const { + /* Explicit assertion because printing that RoughnessTexture isn't found + would be misleading as it can be also MetallicRoughnessTexture */ + CORRADE_ASSERT(hasRoughnessTexture(), + "Trade::PbrMetallicRoughnessMaterialData::roughnessTexture(): the material doesn't have a roughness texture", {}); if(Containers::Optional value = tryAttribute(MaterialAttribute::MetallicRoughnessTexture)) return *value; return attribute(MaterialAttribute::RoughnessTexture); diff --git a/src/Magnum/Trade/PbrSpecularGlossinessMaterialData.cpp b/src/Magnum/Trade/PbrSpecularGlossinessMaterialData.cpp index d38cebaee..16a6e608e 100644 --- a/src/Magnum/Trade/PbrSpecularGlossinessMaterialData.cpp +++ b/src/Magnum/Trade/PbrSpecularGlossinessMaterialData.cpp @@ -101,6 +101,10 @@ Color4 PbrSpecularGlossinessMaterialData::specularColor() const { } UnsignedInt PbrSpecularGlossinessMaterialData::specularTexture() const { + /* Explicit assertion because printing that SpecularTexture isn't found + would be misleading as it can be also SpecularGlossinessTexture */ + CORRADE_ASSERT(hasSpecularTexture(), + "Trade::PbrSpecularGlossinessMaterialData::specularTexture(): the material doesn't have a specular texture", {}); if(Containers::Optional value = tryAttribute(MaterialAttribute::SpecularGlossinessTexture)) return *value; return attribute(MaterialAttribute::SpecularTexture); @@ -135,6 +139,10 @@ Float PbrSpecularGlossinessMaterialData::glossiness() const { } UnsignedInt PbrSpecularGlossinessMaterialData::glossinessTexture() const { + /* Explicit assertion because printing that GlossinessTexture isn't found + would be misleading as it can be also SpecularGlossinessTexture */ + CORRADE_ASSERT(hasGlossinessTexture(), + "Trade::PbrSpecularGlossinessMaterialData::glossinessTexture(): the material doesn't have a glossiness texture", {}); if(Containers::Optional value = tryAttribute(MaterialAttribute::SpecularGlossinessTexture)) return *value; return attribute(MaterialAttribute::GlossinessTexture); diff --git a/src/Magnum/Trade/PhongMaterialData.cpp b/src/Magnum/Trade/PhongMaterialData.cpp index a251a7546..4f1dc3d5c 100644 --- a/src/Magnum/Trade/PhongMaterialData.cpp +++ b/src/Magnum/Trade/PhongMaterialData.cpp @@ -204,6 +204,10 @@ Color4 PhongMaterialData::specularColor() const { } UnsignedInt PhongMaterialData::specularTexture() const { + /* Explicit assertion because printing that SpecularTexture isn't found + would be misleading as it can be also SpecularGlossinessTexture */ + CORRADE_ASSERT(hasSpecularTexture(), + "Trade::PhongMaterialData::specularTexture(): the material doesn't have a specular texture", {}); if(Containers::Optional value = tryAttribute(MaterialAttribute::SpecularGlossinessTexture)) return *value; return attribute(MaterialAttribute::SpecularTexture); diff --git a/src/Magnum/Trade/Test/MaterialDataTest.cpp b/src/Magnum/Trade/Test/MaterialDataTest.cpp index ed0f089e1..05e614cc7 100644 --- a/src/Magnum/Trade/Test/MaterialDataTest.cpp +++ b/src/Magnum/Trade/Test/MaterialDataTest.cpp @@ -2782,11 +2782,11 @@ void MaterialDataTest::pbrMetallicRoughnessAccessInvalidTextures() { "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::MaterialData::attribute(): attribute MetalnessTexture not found in layer 0\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::MaterialData::attribute(): attribute RoughnessTexture not found in layer 0\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" @@ -3164,11 +3164,11 @@ void MaterialDataTest::pbrSpecularGlossinessAccessInvalidTextures() { "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::MaterialData::attribute(): attribute SpecularTexture not found in layer 0\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::MaterialData::attribute(): attribute GlossinessTexture not found in layer 0\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" @@ -3379,7 +3379,7 @@ void MaterialDataTest::phongAccessInvalidTextures() { "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::MaterialData::attribute(): attribute SpecularTexture not found in layer 0\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"