Browse Source

Trade: shuffle code around to avoid unnecessary assertion checks.

It does the same, but better.
pull/470/head
Vladimír Vondruš 6 years ago
parent
commit
4ceeaee1d6
  1. 22
      src/Magnum/Trade/PbrMetallicRoughnessMaterialData.cpp
  2. 22
      src/Magnum/Trade/PbrSpecularGlossinessMaterialData.cpp
  3. 11
      src/Magnum/Trade/PhongMaterialData.cpp

22
src/Magnum/Trade/PbrMetallicRoughnessMaterialData.cpp

@ -222,13 +222,14 @@ 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::NoneRoughnessMetallicTexture))
return *value;
return attribute<UnsignedInt>(MaterialAttribute::MetalnessTexture);
if(Containers::Optional<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::MetalnessTexture))
return *value;
/* Explicit assertion because printing that MetalnessTexture isn't found
would be misleading as it can be also MetallicRoughnessTexture */
CORRADE_ASSERT_UNREACHABLE("Trade::PbrMetallicRoughnessMaterialData::metalnessTexture(): the material doesn't have a metalness texture", {});
}
MaterialTextureSwizzle PbrMetallicRoughnessMaterialData::metalnessTextureSwizzle() const {
@ -260,13 +261,14 @@ 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::NoneRoughnessMetallicTexture))
return *value;
return attribute<UnsignedInt>(MaterialAttribute::RoughnessTexture);
if(Containers::Optional<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::RoughnessTexture))
return *value;
/* Explicit assertion because printing that RoughnessTexture isn't found
would be misleading as it can be also MetallicRoughnessTexture */
CORRADE_ASSERT_UNREACHABLE("Trade::PbrMetallicRoughnessMaterialData::roughnessTexture(): the material doesn't have a roughness texture", {});
}
MaterialTextureSwizzle PbrMetallicRoughnessMaterialData::roughnessTextureSwizzle() const {

22
src/Magnum/Trade/PbrSpecularGlossinessMaterialData.cpp

@ -156,13 +156,14 @@ 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::SpecularGlossinessTexture))
return *value;
return attribute<UnsignedInt>(MaterialAttribute::SpecularTexture);
if(Containers::Optional<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::SpecularTexture))
return *value;
/* Explicit assertion because printing that SpecularTexture isn't found
would be misleading as it can be also SpecularGlossinessTexture */
CORRADE_ASSERT_UNREACHABLE("Trade::PbrSpecularGlossinessMaterialData::specularTexture(): the material doesn't have a specular texture", {});
}
MaterialTextureSwizzle PbrSpecularGlossinessMaterialData::specularTextureSwizzle() const {
@ -194,13 +195,14 @@ 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::SpecularGlossinessTexture))
return *value;
return attribute<UnsignedInt>(MaterialAttribute::GlossinessTexture);
if(Containers::Optional<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::GlossinessTexture))
return *value;
/* Explicit assertion because printing that GlossinessTexture isn't found
would be misleading as it can be also SpecularGlossinessTexture */
CORRADE_ASSERT_UNREACHABLE("Trade::PbrSpecularGlossinessMaterialData::glossinessTexture(): the material doesn't have a glossiness texture", {});
}
MaterialTextureSwizzle PbrSpecularGlossinessMaterialData::glossinessTextureSwizzle() const {

11
src/Magnum/Trade/PhongMaterialData.cpp

@ -250,13 +250,14 @@ 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<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::SpecularGlossinessTexture))
return *value;
return attribute<UnsignedInt>(MaterialAttribute::SpecularTexture);
if(Containers::Optional<UnsignedInt> value = tryAttribute<UnsignedInt>(MaterialAttribute::SpecularTexture))
return *value;
/* Explicit assertion because printing that SpecularTexture isn't found
would be misleading as it can be also SpecularGlossinessTexture */
CORRADE_ASSERT_UNREACHABLE("Trade::PhongMaterialData::specularTexture(): the material doesn't have a specular texture", {});
}
MaterialTextureSwizzle PhongMaterialData::specularTextureSwizzle() const {

Loading…
Cancel
Save