Browse Source

Trade: alpha mode, alpha mask and double sided material properties.

pull/284/head
Vladimír Vondruš 8 years ago
parent
commit
fa10765198
  1. 8
      doc/changelog.dox
  2. 39
      src/Magnum/Trade/AbstractMaterialData.cpp
  3. 101
      src/Magnum/Trade/AbstractMaterialData.h
  4. 6
      src/Magnum/Trade/PhongMaterialData.cpp
  5. 43
      src/Magnum/Trade/PhongMaterialData.h
  6. 2
      src/Magnum/Trade/Test/AbstractImporterTest.cpp
  7. 85
      src/Magnum/Trade/Test/MaterialDataTest.cpp
  8. 2
      src/Magnum/Trade/Trade.h

8
doc/changelog.dox

@ -145,6 +145,9 @@ See also:
- @ref Trade::AnimationData class and animation import interface in - @ref Trade::AnimationData class and animation import interface in
@ref Trade::AbstractImporter::animation() and related functions @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 - @ref Trade::ObjectData2D and @ref Trade::ObjectData3D now support also
separate translation / rotation / scaling specification instead of a separate translation / rotation / scaling specification instead of a
combined transformation matrix. See @ref Trade::ObjectData2D::transformation() combined transformation matrix. See @ref Trade::ObjectData2D::transformation()
@ -374,6 +377,11 @@ See also:
- `Shaders::VertexColor::Color` is deprecated, use the direct - `Shaders::VertexColor::Color` is deprecated, use the direct
@ref Shaders::VertexColor::Color3 or @ref Shaders::VertexColor::Color4 @ref Shaders::VertexColor::Color3 or @ref Shaders::VertexColor::Color4
alternatives instead 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 @subsection changelog-latest-compatibility Potential compatibility breakages, removed APIs

39
src/Magnum/Trade/AbstractMaterialData.cpp

@ -25,11 +25,16 @@
#include "AbstractMaterialData.h" #include "AbstractMaterialData.h"
#include <Corrade/Containers/EnumSet.hpp>
#include <Corrade/Utility/Debug.h> #include <Corrade/Utility/Debug.h>
namespace Magnum { namespace Trade { 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; AbstractMaterialData::~AbstractMaterialData() = default;
@ -45,4 +50,36 @@ Debug& operator<<(Debug& debug, const MaterialType value) {
return debug << "Trade::MaterialType(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")"; return debug << "Trade::MaterialType(" << Debug::nospace << reinterpret_cast<void*>(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<void*>(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<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}
}} }}

101
src/Magnum/Trade/AbstractMaterialData.h

@ -29,6 +29,8 @@
* @brief Class @ref Magnum::Trade::AbstractMaterialData, enum @ref Magnum::Trade::MaterialType * @brief Class @ref Magnum::Trade::AbstractMaterialData, enum @ref Magnum::Trade::MaterialType
*/ */
#include <Corrade/Containers/EnumSet.h>
#include "Magnum/Magnum.h" #include "Magnum/Magnum.h"
#include "Magnum/Trade/visibility.h" #include "Magnum/Trade/visibility.h"
@ -43,6 +45,30 @@ enum class MaterialType: UnsignedByte {
Phong /**< Phong shading (see @ref PhongMaterialData) */ 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 @brief Base for material data
@ -50,23 +76,67 @@ Subclasses provide access to parameters for given material type.
*/ */
class MAGNUM_TRADE_EXPORT AbstractMaterialData { class MAGNUM_TRADE_EXPORT AbstractMaterialData {
public: 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<Flag> Flags;
virtual ~AbstractMaterialData(); virtual ~AbstractMaterialData();
/** @brief Copying is not allowed */ /** @brief Copying is not allowed */
AbstractMaterialData(const AbstractMaterialData&) = delete; AbstractMaterialData(const AbstractMaterialData&) = delete;
/** @brief Move constructor */ /** @brief Move constructor */
AbstractMaterialData(AbstractMaterialData&&) noexcept = default; AbstractMaterialData(AbstractMaterialData&&) noexcept;
/** @brief Copying is not allowed */ /** @brief Copying is not allowed */
AbstractMaterialData& operator=(const AbstractMaterialData&) = delete; AbstractMaterialData& operator=(const AbstractMaterialData&) = delete;
/** @brief Move assignment */ /** @brief Move assignment */
AbstractMaterialData& operator=(AbstractMaterialData&&) noexcept = default; AbstractMaterialData& operator=(AbstractMaterialData&&) noexcept;
/** @brief Material type */ /** @brief Material type */
MaterialType type() const { return _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 * @brief Importer-specific state
* *
@ -78,18 +148,43 @@ class MAGNUM_TRADE_EXPORT AbstractMaterialData {
/** /**
* @brief Constructor * @brief Constructor
* @param type Material type * @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 * @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: private:
MaterialType _type; MaterialType _type;
MaterialAlphaMode _alphaMode;
Flags _flags;
Float _alphaMask;
const void* _importerState; const void* _importerState;
}; };
/** @debugoperatorenum{MaterialType} */ /** @debugoperatorenum{MaterialType} */
MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, MaterialType value); 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 #endif

6
src/Magnum/Trade/PhongMaterialData.cpp

@ -31,7 +31,7 @@ namespace Magnum { namespace Trade {
using namespace Math::Literals; 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) if(_flags & Flag::AmbientTexture)
_ambient.texture = {}; _ambient.texture = {};
else else
@ -121,11 +121,14 @@ UnsignedInt& PhongMaterialData::specularTexture() {
Debug& operator<<(Debug& debug, const PhongMaterialData::Flag value) { Debug& operator<<(Debug& debug, const PhongMaterialData::Flag value) {
switch(value) { switch(value) {
/* LCOV_EXCL_START */
#define _c(v) case PhongMaterialData::Flag::v: return debug << "Trade::PhongMaterialData::Flag::" #v; #define _c(v) case PhongMaterialData::Flag::v: return debug << "Trade::PhongMaterialData::Flag::" #v;
_c(DoubleSided)
_c(AmbientTexture) _c(AmbientTexture)
_c(DiffuseTexture) _c(DiffuseTexture)
_c(SpecularTexture) _c(SpecularTexture)
#undef _c #undef _c
/* LCOV_EXCL_STOP */
} }
return debug << "Trade::PhongMaterialData::Flag(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")"; return debug << "Trade::PhongMaterialData::Flag(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
@ -133,6 +136,7 @@ Debug& operator<<(Debug& debug, const PhongMaterialData::Flag value) {
Debug& operator<<(Debug& debug, const PhongMaterialData::Flags value) { Debug& operator<<(Debug& debug, const PhongMaterialData::Flags value) {
return Containers::enumSetDebugOutput(debug, value, "Trade::PhongMaterialData::Flags{}", { return Containers::enumSetDebugOutput(debug, value, "Trade::PhongMaterialData::Flags{}", {
PhongMaterialData::Flag::DoubleSided,
PhongMaterialData::Flag::AmbientTexture, PhongMaterialData::Flag::AmbientTexture,
PhongMaterialData::Flag::DiffuseTexture, PhongMaterialData::Flag::DiffuseTexture,
PhongMaterialData::Flag::SpecularTexture}); PhongMaterialData::Flag::SpecularTexture});

43
src/Magnum/Trade/PhongMaterialData.h

@ -51,17 +51,27 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData {
/** /**
* @brief Material flag * @brief Material flag
* *
* A superset of @ref AbstractMaterialData::Flag.
* @see @ref Flags, @ref flags() * @see @ref Flags, @ref flags()
*/ */
enum class Flag: UnsignedByte { enum class Flag: UnsignedShort {
AmbientTexture = 1 << 0, /**< The material has ambient texture instead of color */ /** @copydoc AbstractMaterialData::Flag::DoubleSided */
DiffuseTexture = 1 << 1, /**< The material has diffuse texture instead of color */ DoubleSided = 1 << 0,
SpecularTexture = 1 << 2 /**< The material has specular texture instead of color */
/** 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 * @brief Material flags
* *
* A superset of @ref AbstractMaterialData::Flags.
* @see @ref flags() * @see @ref flags()
*/ */
typedef Containers::EnumSet<Flag> Flags; typedef Containers::EnumSet<Flag> Flags;
@ -69,6 +79,10 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData {
/** /**
* @brief Constructor * @brief Constructor
* @param flags Material flags * @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 shininess Shininess
* @param importerState Importer-specific state * @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 * @cpp 0xffffffff_rgbaf @ce, all texture IDs (if any) are by default
* set to @cpp 0 @ce. * 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 */ /** @brief Copying is not allowed */
PhongMaterialData(const PhongMaterialData&) = delete; PhongMaterialData(const PhongMaterialData&) = delete;
@ -92,8 +115,14 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData {
/** @brief Move assignment */ /** @brief Move assignment */
PhongMaterialData& operator=(PhongMaterialData&& other) noexcept; 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 * @brief Ambient color

2
src/Magnum/Trade/Test/AbstractImporterTest.cpp

@ -2355,7 +2355,7 @@ void AbstractImporterTest::material() {
else return {}; else return {};
} }
std::unique_ptr<AbstractMaterialData> doMaterial(UnsignedInt id) override { std::unique_ptr<AbstractMaterialData> doMaterial(UnsignedInt id) override {
if(id == 7) return std::unique_ptr<PhongMaterialData>{new PhongMaterialData{{}, {}, &state}}; if(id == 7) return std::unique_ptr<PhongMaterialData>{new PhongMaterialData{{}, {}, {}, {}, &state}};
else return {}; else return {};
} }
}; };

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

@ -47,6 +47,10 @@ class MaterialDataTest: public TestSuite::Tester {
void accessInvalidTextures(); void accessInvalidTextures();
void debugType(); void debugType();
void debugFlag();
void debugFlags();
void debugAlphaMode();
void debugPhongFlag(); void debugPhongFlag();
void debugPhongFlags(); void debugPhongFlags();
}; };
@ -65,6 +69,10 @@ MaterialDataTest::MaterialDataTest() {
&MaterialDataTest::accessInvalidTextures, &MaterialDataTest::accessInvalidTextures,
&MaterialDataTest::debugType, &MaterialDataTest::debugType,
&MaterialDataTest::debugFlag,
&MaterialDataTest::debugFlags,
&MaterialDataTest::debugAlphaMode,
&MaterialDataTest::debugPhongFlag, &MaterialDataTest::debugPhongFlag,
&MaterialDataTest::debugPhongFlags}); &MaterialDataTest::debugPhongFlags});
} }
@ -73,14 +81,17 @@ void MaterialDataTest::constructPhong() {
using namespace Math::Literals; using namespace Math::Literals;
const int a{}; const int a{};
PhongMaterialData data{{}, 80.0f, &a}; PhongMaterialData data{{}, MaterialAlphaMode::Mask, 0.3f, 80.0f, &a};
data.ambientColor() = 0xccffbb_rgbf; data.ambientColor() = 0xccffbb_rgbf;
data.diffuseColor() = 0xeebbff_rgbf; data.diffuseColor() = 0xeebbff_rgbf;
data.specularColor() = 0xacabad_rgbf; data.specularColor() = 0xacabad_rgbf;
const PhongMaterialData& cdata = data; 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.ambientColor(), 0xccffbb_rgbf);
CORRADE_COMPARE(cdata.diffuseColor(), 0xeebbff_rgbf); CORRADE_COMPARE(cdata.diffuseColor(), 0xeebbff_rgbf);
CORRADE_COMPARE(cdata.specularColor(), 0xacabad_rgbf); CORRADE_COMPARE(cdata.specularColor(), 0xacabad_rgbf);
@ -92,14 +103,17 @@ void MaterialDataTest::constructPhongAmbientTexture() {
using namespace Math::Literals; using namespace Math::Literals;
const int a{}; 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.ambientTexture() = 42;
data.diffuseColor() = 0xeebbff_rgbf; data.diffuseColor() = 0xeebbff_rgbf;
data.specularColor() = 0xacabad_rgbf; data.specularColor() = 0xacabad_rgbf;
const PhongMaterialData& cdata = data; 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.ambientTexture(), 42);
CORRADE_COMPARE(cdata.diffuseColor(), 0xeebbff_rgbf); CORRADE_COMPARE(cdata.diffuseColor(), 0xeebbff_rgbf);
CORRADE_COMPARE(cdata.specularColor(), 0xacabad_rgbf); CORRADE_COMPARE(cdata.specularColor(), 0xacabad_rgbf);
@ -111,14 +125,17 @@ void MaterialDataTest::constructPhongDiffuseTexture() {
using namespace Math::Literals; using namespace Math::Literals;
const int a{}; 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.ambientColor() = 0xccffbb_rgbf;
data.diffuseTexture() = 42; data.diffuseTexture() = 42;
data.specularColor() = 0xacabad_rgbf; data.specularColor() = 0xacabad_rgbf;
const PhongMaterialData& cdata = data; 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.ambientColor(), 0xccffbb_rgbf);
CORRADE_COMPARE(cdata.diffuseTexture(), 42); CORRADE_COMPARE(cdata.diffuseTexture(), 42);
CORRADE_COMPARE(cdata.specularColor(), 0xacabad_rgbf); CORRADE_COMPARE(cdata.specularColor(), 0xacabad_rgbf);
@ -130,14 +147,17 @@ void MaterialDataTest::constructPhongSpecularTexture() {
using namespace Math::Literals; using namespace Math::Literals;
const int a{}; 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.ambientColor() = 0xccffbb_rgbf;
data.diffuseColor() = 0xeebbff_rgbf; data.diffuseColor() = 0xeebbff_rgbf;
data.specularTexture() = 42; data.specularTexture() = 42;
const PhongMaterialData& cdata = data; 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.ambientColor(), 0xccffbb_rgbf);
CORRADE_COMPARE(cdata.diffuseColor(), 0xeebbff_rgbf); CORRADE_COMPARE(cdata.diffuseColor(), 0xeebbff_rgbf);
CORRADE_COMPARE(cdata.specularTexture(), 42); CORRADE_COMPARE(cdata.specularTexture(), 42);
@ -156,14 +176,14 @@ void MaterialDataTest::constructMovePhongNoAmbientTexture() {
using namespace Math::Literals; using namespace Math::Literals;
const int a{}; 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.ambientColor() = 0xccffbb_rgbf;
data.diffuseTexture() = 42; data.diffuseTexture() = 42;
data.specularTexture() = 13; data.specularTexture() = 13;
PhongMaterialData b{std::move(data)}; 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.ambientColor(), 0xccffbb_rgbf);
CORRADE_COMPARE(b.diffuseTexture(), 42); CORRADE_COMPARE(b.diffuseTexture(), 42);
CORRADE_COMPARE(b.specularTexture(), 13); CORRADE_COMPARE(b.specularTexture(), 13);
@ -171,13 +191,13 @@ void MaterialDataTest::constructMovePhongNoAmbientTexture() {
CORRADE_COMPARE(b.importerState(), &a); CORRADE_COMPARE(b.importerState(), &a);
const int c{}; const int c{};
PhongMaterialData d{PhongMaterialData::Flag::AmbientTexture, 100.0f, &c}; PhongMaterialData d{PhongMaterialData::Flag::AmbientTexture, {}, {}, 100.0f, &c};
d.ambientTexture() = 42; d.ambientTexture() = 42;
d.diffuseColor() = 0xeebbff_rgbf; d.diffuseColor() = 0xeebbff_rgbf;
d.specularColor() = 0xacabad_rgbf; d.specularColor() = 0xacabad_rgbf;
d = std::move(b); 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.ambientColor(), 0xccffbb_rgbf);
CORRADE_COMPARE(d.diffuseTexture(), 42); CORRADE_COMPARE(d.diffuseTexture(), 42);
CORRADE_COMPARE(d.specularTexture(), 13); CORRADE_COMPARE(d.specularTexture(), 13);
@ -189,14 +209,14 @@ void MaterialDataTest::constructMovePhongNoDiffuseTexture() {
using namespace Math::Literals; using namespace Math::Literals;
const int a{}; 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.ambientTexture() = 42;
data.diffuseColor() = 0xeebbff_rgbf; data.diffuseColor() = 0xeebbff_rgbf;
data.specularTexture() = 13; data.specularTexture() = 13;
PhongMaterialData b{std::move(data)}; 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.ambientTexture(), 42);
CORRADE_COMPARE(b.diffuseColor(), 0xeebbff_rgbf); CORRADE_COMPARE(b.diffuseColor(), 0xeebbff_rgbf);
CORRADE_COMPARE(b.specularTexture(), 13); CORRADE_COMPARE(b.specularTexture(), 13);
@ -204,13 +224,13 @@ void MaterialDataTest::constructMovePhongNoDiffuseTexture() {
CORRADE_COMPARE(b.importerState(), &a); CORRADE_COMPARE(b.importerState(), &a);
const int c{}; const int c{};
PhongMaterialData d{PhongMaterialData::Flag::DiffuseTexture, 100.0f, &c}; PhongMaterialData d{PhongMaterialData::Flag::DiffuseTexture, {}, {}, 100.0f, &c};
d.ambientColor() = 0xccffbb_rgbf; d.ambientColor() = 0xccffbb_rgbf;
d.diffuseTexture() = 42; d.diffuseTexture() = 42;
d.specularColor() = 0xacabad_rgbf; d.specularColor() = 0xacabad_rgbf;
d = std::move(b); 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.ambientTexture(), 42);
CORRADE_COMPARE(d.diffuseColor(), 0xeebbff_rgbf); CORRADE_COMPARE(d.diffuseColor(), 0xeebbff_rgbf);
CORRADE_COMPARE(d.specularTexture(), 13); CORRADE_COMPARE(d.specularTexture(), 13);
@ -222,14 +242,14 @@ void MaterialDataTest::constructMovePhongNoSpecularTexture() {
using namespace Math::Literals; using namespace Math::Literals;
const int a{}; 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.ambientTexture() = 13;
data.diffuseTexture() = 42; data.diffuseTexture() = 42;
data.specularColor() = 0xacabad_rgbf; data.specularColor() = 0xacabad_rgbf;
PhongMaterialData b{std::move(data)}; 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.ambientTexture(), 13);
CORRADE_COMPARE(b.diffuseTexture(), 42); CORRADE_COMPARE(b.diffuseTexture(), 42);
CORRADE_COMPARE(b.specularColor(), 0xacabad_rgbf); CORRADE_COMPARE(b.specularColor(), 0xacabad_rgbf);
@ -237,13 +257,13 @@ void MaterialDataTest::constructMovePhongNoSpecularTexture() {
CORRADE_COMPARE(b.importerState(), &a); CORRADE_COMPARE(b.importerState(), &a);
const int c{}; const int c{};
PhongMaterialData d{PhongMaterialData::Flag::SpecularTexture, 30.0f, &c}; PhongMaterialData d{PhongMaterialData::Flag::SpecularTexture, {}, {}, 30.0f, &c};
d.ambientColor() = 0xccffbb_rgbf; d.ambientColor() = 0xccffbb_rgbf;
d.diffuseColor() = 0xeebbff_rgbf; d.diffuseColor() = 0xeebbff_rgbf;
d.specularTexture() = 42; d.specularTexture() = 42;
d = std::move(b); 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.ambientTexture(), 13);
CORRADE_COMPARE(d.diffuseTexture(), 42); CORRADE_COMPARE(d.diffuseTexture(), 42);
CORRADE_COMPARE(d.specularColor(), 0xacabad_rgbf); CORRADE_COMPARE(d.specularColor(), 0xacabad_rgbf);
@ -255,7 +275,7 @@ void MaterialDataTest::accessInvalidColors() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&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.ambientColor();
a.diffuseColor(); a.diffuseColor();
@ -271,7 +291,7 @@ void MaterialDataTest::accessInvalidTextures() {
std::ostringstream out; std::ostringstream out;
Error redirectError{&out}; Error redirectError{&out};
PhongMaterialData a{PhongMaterialData::Flags{}, 80.0f}; PhongMaterialData a{PhongMaterialData::Flags{}, {}, {}, 80.0f};
a.ambientTexture(); a.ambientTexture();
a.diffuseTexture(); a.diffuseTexture();
@ -290,6 +310,27 @@ void MaterialDataTest::debugType() {
CORRADE_COMPARE(out.str(), "Trade::MaterialType::Phong Trade::MaterialType(0xbe)\n"); 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() { void MaterialDataTest::debugPhongFlag() {
std::ostringstream out; std::ostringstream out;

2
src/Magnum/Trade/Trade.h

@ -39,6 +39,8 @@ class AbstractImageConverter;
enum class ImporterFileCallbackPolicy: UnsignedByte; enum class ImporterFileCallbackPolicy: UnsignedByte;
class AbstractImporter; class AbstractImporter;
enum class MaterialType: UnsignedByte;
enum class MaterialAlphaMode: UnsignedByte;
class AbstractMaterialData; class AbstractMaterialData;
enum class AnimationTrackTarget: UnsignedByte; enum class AnimationTrackTarget: UnsignedByte;

Loading…
Cancel
Save