Browse Source

Trade: add a similar assert check for Phong textureMatrix as well.

pull/442/head
Vladimír Vondruš 6 years ago
parent
commit
f1fbafb816
  1. 2
      src/Magnum/Trade/PhongMaterialData.cpp
  2. 16
      src/Magnum/Trade/PhongMaterialData.h
  3. 20
      src/Magnum/Trade/Test/MaterialDataTest.cpp

2
src/Magnum/Trade/PhongMaterialData.cpp

@ -34,6 +34,8 @@ using namespace Math::Literals;
PhongMaterialData::PhongMaterialData(const Flags flags, const Color4& ambientColor, const UnsignedInt ambientTexture, const UnsignedInt ambientCoordinateSet, const Color4& diffuseColor, const UnsignedInt diffuseTexture, const UnsignedInt diffuseCoordinateSet, const Color4& specularColor, const UnsignedInt specularTexture, const UnsignedInt specularCoordinateSet, const UnsignedInt normalTexture, const UnsignedInt normalCoordinateSet, const Matrix3& textureMatrix, const MaterialAlphaMode alphaMode, const Float alphaMask, const Float shininess, const void* const importerState) noexcept: AbstractMaterialData{MaterialType::Phong, AbstractMaterialData::Flag(UnsignedShort(flags)), alphaMode, alphaMask, importerState}, _ambientColor{ambientColor}, _diffuseColor{diffuseColor}, _specularColor{specularColor}, _shininess{shininess} {
CORRADE_ASSERT(!(flags & Flag::TextureTransformation) || (flags & (Flag::AmbientTexture|Flag::DiffuseTexture|Flag::SpecularTexture|Flag::NormalTexture)),
"Trade::PhongMaterialData: texture transformation enabled but the material has no textures", );
CORRADE_ASSERT((flags & Flag::TextureTransformation) || textureMatrix == Matrix3{},
"PhongMaterialData::PhongMaterialData: non-default texture matrix requires Flag::TextureTransformation to be enabled", );
CORRADE_ASSERT((flags & Flag::TextureCoordinateSets) || (ambientCoordinateSet == 0 && diffuseCoordinateSet == 0 && specularCoordinateSet == 0 && normalCoordinateSet == 0),
"PhongMaterialData::PhongMaterialData: non-zero texture coordinate sets require Flag::TextureCoordinateSets to be enabled", );

16
src/Magnum/Trade/PhongMaterialData.h

@ -110,8 +110,7 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData {
* doesn't have @ref Flag::SpecularTexture.
* @param normalTexture Normal texture ID. Ignored if @p flags
* doesn't have @ref Flag::NormalTexture.
* @param textureMatrix Texture coordinate transformation. Ignored
* if @p flags doesn't have @ref Flag::TextureTransformation.
* @param textureMatrix Texture coordinate transformation
* @param alphaMode Alpha mode. Use
* @ref MaterialAlphaMode::Opaque for a default value.
* @param alphaMask Alpha mask value. Use @cpp 0.5f @ce for a
@ -122,7 +121,8 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData {
* @m_since_latest
*
* All `*CoordinateSet` accessors are implicitly zero with this
* constructor.
* constructor. If @p textureMatrix is not default-constructed, expects
* @ref Flag::TextureTransformation to be enabled as well.
*/
explicit PhongMaterialData(Flags flags, const Color4& ambientColor, UnsignedInt ambientTexture, const Color4& diffuseColor, UnsignedInt diffuseTexture, const Color4& specularColor, UnsignedInt specularTexture, UnsignedInt normalTexture, const Matrix3& textureMatrix, MaterialAlphaMode alphaMode, Float alphaMask, Float shininess, const void* importerState = nullptr) noexcept;
@ -155,9 +155,7 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData {
* doesn't have @ref Flag::NormalTexture.
* @param normalCoordinateSet Normal texture coordinate set. Ignored
* if @p flags doesn't have @ref Flag::NormalTexture.
* @param textureMatrix Texture coordinate transformation.
* Ignored if @p flags doesn't have
* @ref Flag::TextureTransformation.
* @param textureMatrix Texture coordinate transformation
* @param alphaMode Alpha mode. Use
* @ref MaterialAlphaMode::Opaque for a default value.
* @param alphaMask Alpha mask value. Use @cpp 0.5f @ce for
@ -167,8 +165,10 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData {
* @param importerState Importer-specific state
* @m_since_latest
*
* If any `*CoordinateSet` is non-zero, expects
* @ref Flag::TextureCoordinateSets to be enabled as well.
* If @p textureMatrix is not default-constructed, expects
* @ref Flag::TextureTransformation to be enabled as well. If any
* `*CoordinateSet` is non-zero, expects @ref Flag::TextureCoordinateSets
* to be enabled as well.
*/
explicit PhongMaterialData(Flags flags, const Color4& ambientColor, UnsignedInt ambientTexture, UnsignedInt ambientCoordinateSet, const Color4& diffuseColor, UnsignedInt diffuseTexture, UnsignedInt diffuseCoordinateSet, const Color4& specularColor, UnsignedInt specularTexture, UnsignedInt specularCoordinateSet, UnsignedInt normalTexture, UnsignedInt normalCoordinateSet, const Matrix3& textureMatrix, MaterialAlphaMode alphaMode, Float alphaMask, Float shininess, const void* importerState = nullptr) noexcept;

20
src/Magnum/Trade/Test/MaterialDataTest.cpp

@ -40,6 +40,7 @@ class MaterialDataTest: public TestSuite::Tester {
void constructPhongTexturedTextureTransform();
void constructPhongTexturedCoordinateSets();
void constructPhongTextureTransformNoTextures();
void constructPhongNoTextureTransformationFlag();
void constructPhongNoTextureCoordinateSetsFlag();
void constructCopy();
void constructMovePhong();
@ -61,6 +62,7 @@ MaterialDataTest::MaterialDataTest() {
&MaterialDataTest::constructPhongTexturedTextureTransform,
&MaterialDataTest::constructPhongTexturedCoordinateSets,
&MaterialDataTest::constructPhongTextureTransformNoTextures,
&MaterialDataTest::constructPhongNoTextureTransformationFlag,
&MaterialDataTest::constructPhongNoTextureCoordinateSetsFlag,
&MaterialDataTest::constructCopy,
&MaterialDataTest::constructMovePhong,
@ -204,6 +206,24 @@ void MaterialDataTest::constructPhongTextureTransformNoTextures() {
"Trade::PhongMaterialData: texture transformation enabled but the material has no textures\n");
}
void MaterialDataTest::constructPhongNoTextureTransformationFlag() {
using namespace Math::Literals;
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");
#endif
std::ostringstream out;
Error redirectError{&out};
PhongMaterialData a{{},
{}, {},
{}, {},
{}, {}, {}, Matrix3::rotation(90.0_degf),
{}, 0.5f, 80.0f};
CORRADE_COMPARE(out.str(),
"PhongMaterialData::PhongMaterialData: non-default texture matrix requires Flag::TextureTransformation to be enabled\n");
}
void MaterialDataTest::constructPhongNoTextureCoordinateSetsFlag() {
#ifdef CORRADE_NO_ASSERT
CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions");

Loading…
Cancel
Save