From fa107651987493fd8898719ba21366cf8b701150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 3 Sep 2018 23:33:00 +0200 Subject: [PATCH] Trade: alpha mode, alpha mask and double sided material properties. --- doc/changelog.dox | 8 ++ src/Magnum/Trade/AbstractMaterialData.cpp | 39 ++++++- src/Magnum/Trade/AbstractMaterialData.h | 101 +++++++++++++++++- src/Magnum/Trade/PhongMaterialData.cpp | 6 +- src/Magnum/Trade/PhongMaterialData.h | 43 ++++++-- .../Trade/Test/AbstractImporterTest.cpp | 2 +- src/Magnum/Trade/Test/MaterialDataTest.cpp | 85 +++++++++++---- src/Magnum/Trade/Trade.h | 2 + 8 files changed, 251 insertions(+), 35 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index f9a8a8deb..4d89b2ada 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -145,6 +145,9 @@ See also: - @ref Trade::AnimationData class and animation import interface in @ref Trade::AbstractImporter::animation() and related functions +- New @ref Trade::AbstractMaterialData::flags(), + @ref Trade::AbstractMaterialData::alphaMode() and + @ref Trade::AbstractMaterialData::alphaMask() material properties - @ref Trade::ObjectData2D and @ref Trade::ObjectData3D now support also separate translation / rotation / scaling specification instead of a combined transformation matrix. See @ref Trade::ObjectData2D::transformation() @@ -374,6 +377,11 @@ See also: - `Shaders::VertexColor::Color` is deprecated, use the direct @ref Shaders::VertexColor::Color3 or @ref Shaders::VertexColor::Color4 alternatives instead +- @ref Trade::AbstractMaterialData constructor taking just two parameters + and @ref Trade::PhongMaterialData constructor taking three parameters are + deprecated, use @ref Trade::AbstractMaterialData::AbstractMaterialData(MaterialType, Flags, MaterialAlphaMode, Float, const void*) + and @ref Trade::PhongMaterialData::PhongMaterialData(Flags, MaterialAlphaMode, Float, Float, const void*) + instead @subsection changelog-latest-compatibility Potential compatibility breakages, removed APIs diff --git a/src/Magnum/Trade/AbstractMaterialData.cpp b/src/Magnum/Trade/AbstractMaterialData.cpp index f2f78c83f..e52234aee 100644 --- a/src/Magnum/Trade/AbstractMaterialData.cpp +++ b/src/Magnum/Trade/AbstractMaterialData.cpp @@ -25,11 +25,16 @@ #include "AbstractMaterialData.h" +#include #include namespace Magnum { namespace Trade { -AbstractMaterialData::AbstractMaterialData(const MaterialType type, const void* const importerState) noexcept: _type{type}, _importerState{importerState} {} +AbstractMaterialData::AbstractMaterialData(AbstractMaterialData&&) noexcept = default; + +AbstractMaterialData& AbstractMaterialData::operator=(AbstractMaterialData&&) noexcept = default; + +AbstractMaterialData::AbstractMaterialData(const MaterialType type, const Flags flags, const MaterialAlphaMode alphaMode, const Float alphaMask, const void* const importerState) noexcept: _type{type}, _alphaMode{alphaMode}, _flags{flags}, _alphaMask{alphaMask}, _importerState{importerState} {} AbstractMaterialData::~AbstractMaterialData() = default; @@ -45,4 +50,36 @@ Debug& operator<<(Debug& debug, const MaterialType value) { return debug << "Trade::MaterialType(" << Debug::nospace << reinterpret_cast(UnsignedByte(value)) << Debug::nospace << ")"; } +Debug& operator<<(Debug& debug, const AbstractMaterialData::Flag value) { + switch(value) { + /* LCOV_EXCL_START */ + #define _c(value) case AbstractMaterialData::Flag::value: return debug << "Trade::AbstractMaterialData::Flag::" #value; + _c(DoubleSided) + #undef _c + /* LCOV_EXCL_STOP */ + } + + return debug << "Trade::AbstractMaterialData::Flag(" << Debug::nospace << reinterpret_cast(UnsignedByte(value)) << Debug::nospace << ")"; +} + +Debug& operator<<(Debug& debug, const AbstractMaterialData::Flags value) { + return Containers::enumSetDebugOutput(debug, value, "Trade::AbstractMaterialData::Flags{}", { + AbstractMaterialData::Flag::DoubleSided + }); +} + +Debug& operator<<(Debug& debug, const MaterialAlphaMode value) { + switch(value) { + /* LCOV_EXCL_START */ + #define _c(value) case MaterialAlphaMode::value: return debug << "Trade::MaterialAlphaMode::" #value; + _c(Opaque) + _c(Mask) + _c(Blend) + #undef _c + /* LCOV_EXCL_STOP */ + } + + return debug << "Trade::MaterialAlphaMode(" << Debug::nospace << reinterpret_cast(UnsignedByte(value)) << Debug::nospace << ")"; +} + }} diff --git a/src/Magnum/Trade/AbstractMaterialData.h b/src/Magnum/Trade/AbstractMaterialData.h index e326d933f..8be540d21 100644 --- a/src/Magnum/Trade/AbstractMaterialData.h +++ b/src/Magnum/Trade/AbstractMaterialData.h @@ -29,6 +29,8 @@ * @brief Class @ref Magnum::Trade::AbstractMaterialData, enum @ref Magnum::Trade::MaterialType */ +#include + #include "Magnum/Magnum.h" #include "Magnum/Trade/visibility.h" @@ -43,6 +45,30 @@ enum class MaterialType: UnsignedByte { Phong /**< Phong shading (see @ref PhongMaterialData) */ }; +/** +@brief Material alpha mode + +@see @ref AbstractMaterialData::alphaMode(), + @ref AbstractMaterialData::alphaMask() +*/ +enum class MaterialAlphaMode: UnsignedByte { + /** Alpha value is ignored and the rendered output is fully opaque. */ + Opaque, + + /** + * The rendered output is either fully transparent or fully opaque, + * depending on the alpha value and specified + * @ref AbstractMaterialData::alphaMask() value. + */ + Mask, + + /** + * The alpha value is used to combine source and destination colors using + * additive blending. + */ + Blend +}; + /** @brief Base for material data @@ -50,23 +76,67 @@ Subclasses provide access to parameters for given material type. */ class MAGNUM_TRADE_EXPORT AbstractMaterialData { public: + /** + * @brief Material flag + * + * This enum is extended in subclasses. + * @see @ref Flags, @ref flags() + */ + enum class Flag: UnsignedShort { + /** + * The material is double-sided. Back faces should not be culled + * away but rendered as well, with normals flipped for correct + * lighting. + */ + DoubleSided = 1 << 0 + }; + + /** + * @brief Material flags + * + * This enum is extended in subclasses. + * @see @ref flags() + */ + typedef Containers::EnumSet Flags; + virtual ~AbstractMaterialData(); /** @brief Copying is not allowed */ AbstractMaterialData(const AbstractMaterialData&) = delete; /** @brief Move constructor */ - AbstractMaterialData(AbstractMaterialData&&) noexcept = default; + AbstractMaterialData(AbstractMaterialData&&) noexcept; /** @brief Copying is not allowed */ AbstractMaterialData& operator=(const AbstractMaterialData&) = delete; /** @brief Move assignment */ - AbstractMaterialData& operator=(AbstractMaterialData&&) noexcept = default; + AbstractMaterialData& operator=(AbstractMaterialData&&) noexcept; /** @brief Material type */ MaterialType type() const { return _type; } + /** + * @brief Material flags + * + * Not all bits returned might be defiend by @ref Flag, subclasses + * define extra values. + */ + Flags flags() const { return _flags; } + + /** @brief Alpha mode */ + MaterialAlphaMode alphaMode() const { return _alphaMode; } + + /** + * @brief Alpha mask + * + * If @ref alphaMode() is @ref MaterialAlphaMode::Mask, alpha values + * below this value are rendered as fully transparent and alpha values + * above this value as fully opaque. If @ref alphaMode() is not + * @ref MaterialAlphaMode::Mask, this value is ignored. + */ + Float alphaMask() const { return _alphaMask; } + /** * @brief Importer-specific state * @@ -78,18 +148,43 @@ class MAGNUM_TRADE_EXPORT AbstractMaterialData { /** * @brief Constructor * @param type Material type + * @param flags Untyped material flags + * @param alphaMode Alpha mode. Use + * @ref MaterialAlphaMode::Opaque for a default value. + * @param alphaMask Alpha mask value. Use @cpp 0.5f @ce for a + * default value. * @param importerState Importer-specific state */ - explicit AbstractMaterialData(MaterialType type, const void* importerState = nullptr) noexcept; + explicit AbstractMaterialData(MaterialType type, Flags flags, MaterialAlphaMode alphaMode, Float alphaMask, const void* importerState = nullptr) noexcept; + + #ifdef MAGNUM_BUILD_DEPRECATED + /** @brief Constructor + * @deprecated Use @ref AbstractMaterialData(MaterialType, Flags, MaterialAlphaMode, Float, const void*) + * instead. + */ + explicit CORRADE_DEPRECATED("use AbstractMaterialData(MaterialType, UnsignedInt, MaterialAlphaMode, Float) instead") AbstractMaterialData(MaterialType type, const void* importerState = nullptr) noexcept: AbstractMaterialData{type, {}, MaterialAlphaMode::Opaque, 0.5f, importerState} {} + #endif private: MaterialType _type; + MaterialAlphaMode _alphaMode; + Flags _flags; + Float _alphaMask; const void* _importerState; }; /** @debugoperatorenum{MaterialType} */ MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, MaterialType value); +/** @debugoperatorenum{MaterialAlphaMode} */ +MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, MaterialAlphaMode value); + +/** @debugoperatorclassenum{AbstractMaterialData,AbstractMaterialData::Flag} */ +MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, AbstractMaterialData::Flag value); + +/** @debugoperatorclassenum{AbstractMaterialData,AbstractMaterialData::Flags} */ +MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, AbstractMaterialData::Flags value); + }} #endif diff --git a/src/Magnum/Trade/PhongMaterialData.cpp b/src/Magnum/Trade/PhongMaterialData.cpp index 1171e0a0f..52f2fc754 100644 --- a/src/Magnum/Trade/PhongMaterialData.cpp +++ b/src/Magnum/Trade/PhongMaterialData.cpp @@ -31,7 +31,7 @@ namespace Magnum { namespace Trade { using namespace Math::Literals; -PhongMaterialData::PhongMaterialData(const Flags flags, const Float shininess, const void* const importerState) noexcept: AbstractMaterialData{MaterialType::Phong, importerState}, _flags{flags}, _shininess{shininess} { +PhongMaterialData::PhongMaterialData(const Flags flags, const MaterialAlphaMode alphaMode, const Float alphaMask, const Float shininess, const void* const importerState) noexcept: AbstractMaterialData{MaterialType::Phong, AbstractMaterialData::Flag(UnsignedShort(flags)), alphaMode, alphaMask, importerState}, _flags{flags}, _shininess{shininess} { if(_flags & Flag::AmbientTexture) _ambient.texture = {}; else @@ -121,11 +121,14 @@ UnsignedInt& PhongMaterialData::specularTexture() { Debug& operator<<(Debug& debug, const PhongMaterialData::Flag value) { switch(value) { + /* LCOV_EXCL_START */ #define _c(v) case PhongMaterialData::Flag::v: return debug << "Trade::PhongMaterialData::Flag::" #v; + _c(DoubleSided) _c(AmbientTexture) _c(DiffuseTexture) _c(SpecularTexture) #undef _c + /* LCOV_EXCL_STOP */ } return debug << "Trade::PhongMaterialData::Flag(" << Debug::nospace << reinterpret_cast(UnsignedByte(value)) << Debug::nospace << ")"; @@ -133,6 +136,7 @@ Debug& operator<<(Debug& debug, const PhongMaterialData::Flag value) { Debug& operator<<(Debug& debug, const PhongMaterialData::Flags value) { return Containers::enumSetDebugOutput(debug, value, "Trade::PhongMaterialData::Flags{}", { + PhongMaterialData::Flag::DoubleSided, PhongMaterialData::Flag::AmbientTexture, PhongMaterialData::Flag::DiffuseTexture, PhongMaterialData::Flag::SpecularTexture}); diff --git a/src/Magnum/Trade/PhongMaterialData.h b/src/Magnum/Trade/PhongMaterialData.h index 4078dd842..738a92f7a 100644 --- a/src/Magnum/Trade/PhongMaterialData.h +++ b/src/Magnum/Trade/PhongMaterialData.h @@ -51,17 +51,27 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { /** * @brief Material flag * + * A superset of @ref AbstractMaterialData::Flag. * @see @ref Flags, @ref flags() */ - enum class Flag: UnsignedByte { - AmbientTexture = 1 << 0, /**< The material has ambient texture instead of color */ - DiffuseTexture = 1 << 1, /**< The material has diffuse texture instead of color */ - SpecularTexture = 1 << 2 /**< The material has specular texture instead of color */ + enum class Flag: UnsignedShort { + /** @copydoc AbstractMaterialData::Flag::DoubleSided */ + DoubleSided = 1 << 0, + + /** The material has an ambient texture instead of color */ + AmbientTexture = 1 << 1, + + /** The material has a diffuse texture instead of color */ + DiffuseTexture = 1 << 2, + + /** The material has a specular texture instead of color */ + SpecularTexture = 1 << 3 }; /** * @brief Material flags * + * A superset of @ref AbstractMaterialData::Flags. * @see @ref flags() */ typedef Containers::EnumSet Flags; @@ -69,6 +79,10 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { /** * @brief Constructor * @param flags Material flags + * @param alphaMode Alpha mode. Use + * @ref MaterialAlphaMode::Opaque for a default value. + * @param alphaMask Alpha mask value. Use @cpp 0.5f @ce for a + * default value. * @param shininess Shininess * @param importerState Importer-specific state * @@ -78,7 +92,16 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { * @cpp 0xffffffff_rgbaf @ce, all texture IDs (if any) are by default * set to @cpp 0 @ce. */ - explicit PhongMaterialData(Flags flags, Float shininess, const void* importerState = nullptr) noexcept; + explicit PhongMaterialData(Flags flags, MaterialAlphaMode alphaMode, Float alphaMask, Float shininess, const void* importerState = nullptr) noexcept; + + #ifdef MAGNUM_BUILD_DEPRECATED + /** + * @brief Constructor + * @deprecated Use @ref PhongMaterialData(Flags, MaterialAlphaMode, Float, Float, const void*) + * instead. + */ + explicit CORRADE_DEPRECATED("use PhongMaterialData(Flags, MaterialAlphaMode, Float, Float, const void*) instead") PhongMaterialData(Flags flags, Float shininess, const void* importerState = nullptr) noexcept: PhongMaterialData{flags, MaterialAlphaMode::Opaque, 0.5f, shininess, importerState} {} + #endif /** @brief Copying is not allowed */ PhongMaterialData(const PhongMaterialData&) = delete; @@ -92,8 +115,14 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { /** @brief Move assignment */ PhongMaterialData& operator=(PhongMaterialData&& other) noexcept; - /** @brief Material flags */ - Flags flags() const { return _flags; } + /** + * @brief Material flags + * + * A superset of @ref AbstractMaterialData::flags(). + */ + Flags flags() const { + return Flag(UnsignedShort(AbstractMaterialData::flags())); + } /** * @brief Ambient color diff --git a/src/Magnum/Trade/Test/AbstractImporterTest.cpp b/src/Magnum/Trade/Test/AbstractImporterTest.cpp index ec7eabe68..9906eb9db 100644 --- a/src/Magnum/Trade/Test/AbstractImporterTest.cpp +++ b/src/Magnum/Trade/Test/AbstractImporterTest.cpp @@ -2355,7 +2355,7 @@ void AbstractImporterTest::material() { else return {}; } std::unique_ptr doMaterial(UnsignedInt id) override { - if(id == 7) return std::unique_ptr{new PhongMaterialData{{}, {}, &state}}; + if(id == 7) return std::unique_ptr{new PhongMaterialData{{}, {}, {}, {}, &state}}; else return {}; } }; diff --git a/src/Magnum/Trade/Test/MaterialDataTest.cpp b/src/Magnum/Trade/Test/MaterialDataTest.cpp index 561b1dbac..cdd842914 100644 --- a/src/Magnum/Trade/Test/MaterialDataTest.cpp +++ b/src/Magnum/Trade/Test/MaterialDataTest.cpp @@ -47,6 +47,10 @@ class MaterialDataTest: public TestSuite::Tester { void accessInvalidTextures(); void debugType(); + void debugFlag(); + void debugFlags(); + void debugAlphaMode(); + void debugPhongFlag(); void debugPhongFlags(); }; @@ -65,6 +69,10 @@ MaterialDataTest::MaterialDataTest() { &MaterialDataTest::accessInvalidTextures, &MaterialDataTest::debugType, + &MaterialDataTest::debugFlag, + &MaterialDataTest::debugFlags, + &MaterialDataTest::debugAlphaMode, + &MaterialDataTest::debugPhongFlag, &MaterialDataTest::debugPhongFlags}); } @@ -73,14 +81,17 @@ void MaterialDataTest::constructPhong() { using namespace Math::Literals; const int a{}; - PhongMaterialData data{{}, 80.0f, &a}; + PhongMaterialData data{{}, MaterialAlphaMode::Mask, 0.3f, 80.0f, &a}; data.ambientColor() = 0xccffbb_rgbf; data.diffuseColor() = 0xeebbff_rgbf; data.specularColor() = 0xacabad_rgbf; const PhongMaterialData& cdata = data; - CORRADE_VERIFY(cdata.flags() == PhongMaterialData::Flags{}); + CORRADE_COMPARE(cdata.type(), MaterialType::Phong); + CORRADE_COMPARE(cdata.flags(), PhongMaterialData::Flags{}); + CORRADE_COMPARE(cdata.alphaMode(), MaterialAlphaMode::Mask); + CORRADE_COMPARE(cdata.alphaMask(), 0.3f); CORRADE_COMPARE(cdata.ambientColor(), 0xccffbb_rgbf); CORRADE_COMPARE(cdata.diffuseColor(), 0xeebbff_rgbf); CORRADE_COMPARE(cdata.specularColor(), 0xacabad_rgbf); @@ -92,14 +103,17 @@ void MaterialDataTest::constructPhongAmbientTexture() { using namespace Math::Literals; const int a{}; - PhongMaterialData data{PhongMaterialData::Flag::AmbientTexture, 80.0f, &a}; + PhongMaterialData data{PhongMaterialData::Flag::AmbientTexture, MaterialAlphaMode::Mask, 0.3f, 80.0f, &a}; data.ambientTexture() = 42; data.diffuseColor() = 0xeebbff_rgbf; data.specularColor() = 0xacabad_rgbf; const PhongMaterialData& cdata = data; - CORRADE_VERIFY(cdata.flags() == PhongMaterialData::Flag::AmbientTexture); + CORRADE_COMPARE(cdata.type(), MaterialType::Phong); + CORRADE_COMPARE(cdata.flags(), PhongMaterialData::Flag::AmbientTexture); + CORRADE_COMPARE(cdata.alphaMode(), MaterialAlphaMode::Mask); + CORRADE_COMPARE(cdata.alphaMask(), 0.3f); CORRADE_COMPARE(cdata.ambientTexture(), 42); CORRADE_COMPARE(cdata.diffuseColor(), 0xeebbff_rgbf); CORRADE_COMPARE(cdata.specularColor(), 0xacabad_rgbf); @@ -111,14 +125,17 @@ void MaterialDataTest::constructPhongDiffuseTexture() { using namespace Math::Literals; const int a{}; - PhongMaterialData data{PhongMaterialData::Flag::DiffuseTexture, 80.0f, &a}; + PhongMaterialData data{PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::DoubleSided, MaterialAlphaMode::Opaque, 0.0f, 80.0f, &a}; data.ambientColor() = 0xccffbb_rgbf; data.diffuseTexture() = 42; data.specularColor() = 0xacabad_rgbf; const PhongMaterialData& cdata = data; - CORRADE_VERIFY(cdata.flags() == PhongMaterialData::Flag::DiffuseTexture); + CORRADE_COMPARE(cdata.type(), MaterialType::Phong); + CORRADE_COMPARE(cdata.flags(), PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::DoubleSided); + CORRADE_COMPARE(cdata.alphaMode(), MaterialAlphaMode::Opaque); + CORRADE_COMPARE(cdata.alphaMask(), 0.0f); CORRADE_COMPARE(cdata.ambientColor(), 0xccffbb_rgbf); CORRADE_COMPARE(cdata.diffuseTexture(), 42); CORRADE_COMPARE(cdata.specularColor(), 0xacabad_rgbf); @@ -130,14 +147,17 @@ void MaterialDataTest::constructPhongSpecularTexture() { using namespace Math::Literals; const int a{}; - PhongMaterialData data{PhongMaterialData::Flag::SpecularTexture, 30.0f, &a}; + PhongMaterialData data{PhongMaterialData::Flag::SpecularTexture, MaterialAlphaMode::Blend, 1.0f, 30.0f, &a}; data.ambientColor() = 0xccffbb_rgbf; data.diffuseColor() = 0xeebbff_rgbf; data.specularTexture() = 42; const PhongMaterialData& cdata = data; - CORRADE_VERIFY(cdata.flags() == PhongMaterialData::Flag::SpecularTexture); + CORRADE_COMPARE(cdata.type(), MaterialType::Phong); + CORRADE_COMPARE(cdata.flags(), PhongMaterialData::Flag::SpecularTexture); + CORRADE_COMPARE(cdata.alphaMode(), MaterialAlphaMode::Blend); + CORRADE_COMPARE(cdata.alphaMask(), 1.0f); CORRADE_COMPARE(cdata.ambientColor(), 0xccffbb_rgbf); CORRADE_COMPARE(cdata.diffuseColor(), 0xeebbff_rgbf); CORRADE_COMPARE(cdata.specularTexture(), 42); @@ -156,14 +176,14 @@ void MaterialDataTest::constructMovePhongNoAmbientTexture() { using namespace Math::Literals; const int a{}; - PhongMaterialData data{PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture, 80.0f, &a}; + PhongMaterialData data{PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture, {}, {}, 80.0f, &a}; data.ambientColor() = 0xccffbb_rgbf; data.diffuseTexture() = 42; data.specularTexture() = 13; PhongMaterialData b{std::move(data)}; - CORRADE_VERIFY(b.flags() == (PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture)); + CORRADE_COMPARE(b.flags(), (PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture)); CORRADE_COMPARE(b.ambientColor(), 0xccffbb_rgbf); CORRADE_COMPARE(b.diffuseTexture(), 42); CORRADE_COMPARE(b.specularTexture(), 13); @@ -171,13 +191,13 @@ void MaterialDataTest::constructMovePhongNoAmbientTexture() { CORRADE_COMPARE(b.importerState(), &a); const int c{}; - PhongMaterialData d{PhongMaterialData::Flag::AmbientTexture, 100.0f, &c}; + PhongMaterialData d{PhongMaterialData::Flag::AmbientTexture, {}, {}, 100.0f, &c}; d.ambientTexture() = 42; d.diffuseColor() = 0xeebbff_rgbf; d.specularColor() = 0xacabad_rgbf; d = std::move(b); - CORRADE_VERIFY(d.flags() == (PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture)); + CORRADE_COMPARE(d.flags(), PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture); CORRADE_COMPARE(d.ambientColor(), 0xccffbb_rgbf); CORRADE_COMPARE(d.diffuseTexture(), 42); CORRADE_COMPARE(d.specularTexture(), 13); @@ -189,14 +209,14 @@ void MaterialDataTest::constructMovePhongNoDiffuseTexture() { using namespace Math::Literals; const int a{}; - PhongMaterialData data{PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture, 80.0f, &a}; + PhongMaterialData data{PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture, {}, {}, 80.0f, &a}; data.ambientTexture() = 42; data.diffuseColor() = 0xeebbff_rgbf; data.specularTexture() = 13; PhongMaterialData b{std::move(data)}; - CORRADE_VERIFY(b.flags() == (PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture)); + CORRADE_COMPARE(b.flags(), PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture); CORRADE_COMPARE(b.ambientTexture(), 42); CORRADE_COMPARE(b.diffuseColor(), 0xeebbff_rgbf); CORRADE_COMPARE(b.specularTexture(), 13); @@ -204,13 +224,13 @@ void MaterialDataTest::constructMovePhongNoDiffuseTexture() { CORRADE_COMPARE(b.importerState(), &a); const int c{}; - PhongMaterialData d{PhongMaterialData::Flag::DiffuseTexture, 100.0f, &c}; + PhongMaterialData d{PhongMaterialData::Flag::DiffuseTexture, {}, {}, 100.0f, &c}; d.ambientColor() = 0xccffbb_rgbf; d.diffuseTexture() = 42; d.specularColor() = 0xacabad_rgbf; d = std::move(b); - CORRADE_VERIFY(d.flags() == (PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture)); + CORRADE_COMPARE(d.flags(), PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture); CORRADE_COMPARE(d.ambientTexture(), 42); CORRADE_COMPARE(d.diffuseColor(), 0xeebbff_rgbf); CORRADE_COMPARE(d.specularTexture(), 13); @@ -222,14 +242,14 @@ void MaterialDataTest::constructMovePhongNoSpecularTexture() { using namespace Math::Literals; const int a{}; - PhongMaterialData data{PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture, 80.0f, &a}; + PhongMaterialData data{PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture, {}, {}, 80.0f, &a}; data.ambientTexture() = 13; data.diffuseTexture() = 42; data.specularColor() = 0xacabad_rgbf; PhongMaterialData b{std::move(data)}; - CORRADE_VERIFY(b.flags() == (PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture)); + CORRADE_COMPARE(b.flags(), PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture); CORRADE_COMPARE(b.ambientTexture(), 13); CORRADE_COMPARE(b.diffuseTexture(), 42); CORRADE_COMPARE(b.specularColor(), 0xacabad_rgbf); @@ -237,13 +257,13 @@ void MaterialDataTest::constructMovePhongNoSpecularTexture() { CORRADE_COMPARE(b.importerState(), &a); const int c{}; - PhongMaterialData d{PhongMaterialData::Flag::SpecularTexture, 30.0f, &c}; + PhongMaterialData d{PhongMaterialData::Flag::SpecularTexture, {}, {}, 30.0f, &c}; d.ambientColor() = 0xccffbb_rgbf; d.diffuseColor() = 0xeebbff_rgbf; d.specularTexture() = 42; d = std::move(b); - CORRADE_VERIFY(d.flags() == (PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture)); + CORRADE_COMPARE(d.flags(), PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture); CORRADE_COMPARE(d.ambientTexture(), 13); CORRADE_COMPARE(d.diffuseTexture(), 42); CORRADE_COMPARE(d.specularColor(), 0xacabad_rgbf); @@ -255,7 +275,7 @@ void MaterialDataTest::accessInvalidColors() { std::ostringstream out; Error redirectError{&out}; - PhongMaterialData a{PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture, 80.0f}; + PhongMaterialData a{PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture, {}, {}, 80.0f}; a.ambientColor(); a.diffuseColor(); @@ -271,7 +291,7 @@ void MaterialDataTest::accessInvalidTextures() { std::ostringstream out; Error redirectError{&out}; - PhongMaterialData a{PhongMaterialData::Flags{}, 80.0f}; + PhongMaterialData a{PhongMaterialData::Flags{}, {}, {}, 80.0f}; a.ambientTexture(); a.diffuseTexture(); @@ -290,6 +310,27 @@ void MaterialDataTest::debugType() { CORRADE_COMPARE(out.str(), "Trade::MaterialType::Phong Trade::MaterialType(0xbe)\n"); } +void MaterialDataTest::debugFlag() { + std::ostringstream out; + + Debug{&out} << AbstractMaterialData::Flag::DoubleSided << AbstractMaterialData::Flag(0xf0); + CORRADE_COMPARE(out.str(), "Trade::AbstractMaterialData::Flag::DoubleSided Trade::AbstractMaterialData::Flag(0xf0)\n"); +} + +void MaterialDataTest::debugFlags() { + std::ostringstream out; + + Debug{&out} << AbstractMaterialData::Flag::DoubleSided << AbstractMaterialData::Flags{}; + CORRADE_COMPARE(out.str(), "Trade::AbstractMaterialData::Flag::DoubleSided Trade::AbstractMaterialData::Flags{}\n"); +} + +void MaterialDataTest::debugAlphaMode() { + std::ostringstream out; + + Debug{&out} << MaterialAlphaMode::Opaque << MaterialAlphaMode(0xee); + CORRADE_COMPARE(out.str(), "Trade::MaterialAlphaMode::Opaque Trade::MaterialAlphaMode(0xee)\n"); +} + void MaterialDataTest::debugPhongFlag() { std::ostringstream out; diff --git a/src/Magnum/Trade/Trade.h b/src/Magnum/Trade/Trade.h index ee990d2b3..b696ace1f 100644 --- a/src/Magnum/Trade/Trade.h +++ b/src/Magnum/Trade/Trade.h @@ -39,6 +39,8 @@ class AbstractImageConverter; enum class ImporterFileCallbackPolicy: UnsignedByte; class AbstractImporter; +enum class MaterialType: UnsignedByte; +enum class MaterialAlphaMode: UnsignedByte; class AbstractMaterialData; enum class AnimationTrackTarget: UnsignedByte;