diff --git a/doc/changelog.dox b/doc/changelog.dox index 7d830da93..2004f6f15 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -94,6 +94,15 @@ See also: @subsubsection changelog-latest-changes-trade Trade library - Recognizing TIFF file header magic in @ref Trade::AnyImageImporter "AnyImageImporter" +- Added @ref Trade::PhongMaterialData::ambientTextureMatrix(), + @ref Trade::PhongMaterialData::diffuseTextureMatrix(), + @ref Trade::PhongMaterialData::specularTextureMatrix() and + @ref Trade::PhongMaterialData::normalTextureMatrix() exposing also + per-texture coordinate transformation, similarly to per-texture coordinate + sets added in 2020.06 +- Added @ref Trade::PhongMaterialData::textureCoordinates() exposing a common + texture coordinate set as a complement to a per-texture property added in + 2020.06 @subsection changelog-latest-buildsystem Build system @@ -119,6 +128,9 @@ See also: @subsection changelog-latest-deprecated Deprecated APIs +- @cpp Trade::AbstractMaterialData @ce as well as its containing header + `Magnum/Trade/AbstractMaterialData.h` is now a deprecated alias to the new + and more flexible @ref Trade::MaterialData. - @cpp Trade::PhongMaterialData::ambientCoordinateSet() @ce, @cpp diffuseCoordinateSet() @ce, @cpp specularCoordinateSet() @ce and @cpp normalCoordinateSet() @ce are deprecated in favor of more consistently @@ -126,6 +138,18 @@ See also: @ref Trade::PhongMaterialData::diffuseTextureCoordinates() "diffuseTextureCoordinates()", @ref Trade::PhongMaterialData::specularTextureCoordinates() "specularTextureCoordinates()" and @ref Trade::PhongMaterialData::normalTextureCoordinates() "normalTextureCoordinates()" +- @ref Trade::PhongMaterialData constructor is deprecated as the designated + way is to populate the @ref Trade::MaterialData class directly instead. +- @cpp Trade::MaterialData::type() @ce (coming from the original + `AbstractMaterialData` class) is deprecated in favor of + @ref Trade::MaterialData::types(), as a material data can now contain + attributes for multiple different material types at once +- @cpp Trade::MaterialData::flags() @ce (coming from the original + `AbstractMaterialData` class), @cpp Trade::PhongMaterialData::flags() @ce + and related enum (sets) are deprecated. The flags are no longer stored + directly but rather generated on-the-fly from attribute data, which makes + them less efficient than calling @ref Trade::MaterialData::hasAttribute() + etc. @subsection changelog-latest-compatibility Potential compatibility breakages, removed APIs @@ -160,11 +184,12 @@ See also: - @ref Trade::CameraData constructor not taking an explicit type enum, use @ref Trade::CameraData::CameraData(CameraType, Rad, Float, Float, Float, const void*) instead - - @ref Trade::AbstractMaterialData constructor taking just two parameters - and @ref Trade::PhongMaterialData constructor taking three parameters, - use @ref Trade::AbstractMaterialData::AbstractMaterialData(MaterialType, Flags, MaterialAlphaMode, Float, const void*) - and @ref Trade::PhongMaterialData::PhongMaterialData(Flags, MaterialAlphaMode, Float, Float, const void*) - instead + - @cpp Trade::AbstractMaterialData @ce constructor taking just two + parameters and @ref Trade::PhongMaterialData constructor taking three + parameters, use either the (also deprecated) + @cpp Trade::AbstractMaterialData::AbstractMaterialData(MaterialType, Flags, MaterialAlphaMode, Float, const void*) @ce + and @cpp Trade::PhongMaterialData::PhongMaterialData(Flags, MaterialAlphaMode, Float, Float, const void*) @ce + constructors or directly the new @ref Trade::MaterialData class - All includes of @ref Corrade/Containers/PointerStl.h and @ref Corrade/Containers/ArrayViewStl.h that were added in 2019.01 for preserving backwards compatibility after the move from @ref std::unique_ptr @@ -183,6 +208,16 @@ See also: implement through the redesigned @ref Trade::MaterialData APIs. However these APIs were mainly used to populate the contents in asset importers, so this shouldn't cause any breakages in user code. +- @ref Trade::MaterialData::flags() now calculates the output on-the-fly + based on what attributes are present. This means that arbitrary extra bits + passed to the constructor from @cpp AbstractMaterialData @ce subclasses are + now discarded, and thus subclasses have to override the + @ref Trade::MaterialData::flags() "flags()" function to keep the same + behavior. +- @ref Trade::MaterialData, which the deprecated + @cpp Trade::AbstractMaterialData @ce aliases to, doesn't have a + @cpp virtual @ce destructor as subclasses with extra data members aren't a + desired use case anymore. @section changelog-2020-06 2020.06 @@ -2486,10 +2521,10 @@ Released 2018-10-23, tagged as - `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 +- @cpp Trade::AbstractMaterialData @ce 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*) + deprecated, use @cpp Trade::AbstractMaterialData::AbstractMaterialData(MaterialType, Flags, MaterialAlphaMode, Float, const void*) @ce + and @cpp Trade::PhongMaterialData::PhongMaterialData(Flags, MaterialAlphaMode, Float, Float, const void*) @ce instead - @ref Trade::CameraData constructor not taking an explicit type enum is deprecated, use @ref Trade::CameraData::CameraData(CameraType, Rad, Float, Float, Float, const void*) diff --git a/doc/snippets/MagnumTrade.cpp b/doc/snippets/MagnumTrade.cpp index 57dcb68e1..d94679d9f 100644 --- a/doc/snippets/MagnumTrade.cpp +++ b/doc/snippets/MagnumTrade.cpp @@ -33,6 +33,7 @@ #include "Magnum/Mesh.h" #include "Magnum/PixelFormat.h" #include "Magnum/Animation/Player.h" +#include "Magnum/Math/Color.h" #include "Magnum/Math/Swizzle.h" #include "Magnum/MeshTools/Interleave.h" #include "Magnum/MeshTools/Transform.h" diff --git a/src/Magnum/Trade/AbstractMaterialData.cpp b/src/Magnum/Trade/AbstractMaterialData.cpp deleted file mode 100644 index 0a7a1e3b8..000000000 --- a/src/Magnum/Trade/AbstractMaterialData.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - This file is part of Magnum. - - Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, - 2020 Vladimír Vondruš - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -#include "AbstractMaterialData.h" - -#include -#include - -namespace Magnum { namespace Trade { - -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; - -Debug& operator<<(Debug& debug, const AbstractMaterialData::Flag value) { - debug << "Trade::AbstractMaterialData::Flag" << Debug::nospace; - - switch(value) { - /* LCOV_EXCL_START */ - #define _c(value) case AbstractMaterialData::Flag::value: return debug << "::" #value; - _c(DoubleSided) - #undef _c - /* LCOV_EXCL_STOP */ - } - - return debug << "(" << 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) { - debug << "Trade::MaterialAlphaMode" << Debug::nospace; - - switch(value) { - /* LCOV_EXCL_START */ - #define _c(value) case MaterialAlphaMode::value: return debug << "::" #value; - _c(Opaque) - _c(Mask) - _c(Blend) - #undef _c - /* LCOV_EXCL_STOP */ - } - - return debug << "(" << Debug::nospace << reinterpret_cast(UnsignedByte(value)) << Debug::nospace << ")"; -} - -}} diff --git a/src/Magnum/Trade/AbstractMaterialData.h b/src/Magnum/Trade/AbstractMaterialData.h index b833bf740..d0dedb11e 100644 --- a/src/Magnum/Trade/AbstractMaterialData.h +++ b/src/Magnum/Trade/AbstractMaterialData.h @@ -25,143 +25,34 @@ DEALINGS IN THE SOFTWARE. */ +#ifdef MAGNUM_BUILD_DEPRECATED /** @file * @brief Class @ref Magnum::Trade::AbstractMaterialData, enum @ref Magnum::Trade::MaterialType + * @m_deprecated_since_latest Use @ref Magnum/Trade/MaterialData.h and the + * @ref Magnum::Trade::MaterialData "MaterialData" class instead. */ +#endif -#include "Magnum/Trade/MaterialData.h" - -namespace Magnum { namespace Trade { - -/** -@brief Material alpha mode +#include "Magnum/configure.h" -@see @ref AbstractMaterialData::alphaMode(), - @ref AbstractMaterialData::alphaMask() -*/ -enum class MaterialAlphaMode: UnsignedByte { - /** Alpha value is ignored and the rendered output is fully opaque. */ - Opaque, +#ifdef MAGNUM_BUILD_DEPRECATED +#include "Magnum/Trade/MaterialData.h" - /** - * The rendered output is either fully transparent or fully opaque, - * depending on the alpha value and specified - * @ref AbstractMaterialData::alphaMask() value. - */ - Mask, +#ifndef _MAGNUM_NO_DEPRECATED_MESHDATA +CORRADE_DEPRECATED_FILE("use Magnum/Trade/MaterialData.h and the MaterialData class instead") +#endif - /** - * The alpha value is used to combine source and destination colors using - * additive blending. - */ - Blend -}; +namespace Magnum { namespace Trade { /** -@brief Base for material data - -Subclasses provide access to parameters for given material type. +@brief @copybrief MaterialData +@m_deprecated_since_latest Use @ref MaterialData instead. */ -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; - - /** @brief Copying is not allowed */ - AbstractMaterialData& operator=(const AbstractMaterialData&) = delete; - - /** @brief Move assignment */ - 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 - * - * See @ref AbstractImporter::importerState() for more information. - */ - const void* importerState() const { return _importerState; } - - protected: - /** - * @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, Flags flags, MaterialAlphaMode alphaMode, Float alphaMask, const void* importerState = nullptr) noexcept; - - private: - MaterialType _type; - MaterialAlphaMode _alphaMode; - Flags _flags; - Float _alphaMask; - const void* _importerState; -}; - -/** @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); +typedef CORRADE_DEPRECATED("use MaterialData instead") MaterialData AbstractMaterialData; }} +#else +#error use Magnum/Trade/MaterialData.h and the MaterialData class instead +#endif #endif diff --git a/src/Magnum/Trade/CMakeLists.txt b/src/Magnum/Trade/CMakeLists.txt index 0ce26fe34..e2019cb8f 100644 --- a/src/Magnum/Trade/CMakeLists.txt +++ b/src/Magnum/Trade/CMakeLists.txt @@ -26,7 +26,6 @@ find_package(Corrade REQUIRED PluginManager) set(MagnumTrade_SRCS - AbstractMaterialData.cpp ArrayAllocator.cpp Data.cpp LightData.cpp @@ -51,7 +50,6 @@ set(MagnumTrade_GracefulAssert_SRCS set(MagnumTrade_HEADERS AbstractImporter.h AbstractImageConverter.h - AbstractMaterialData.h AbstractSceneConverter.h AnimationData.h ArrayAllocator.h @@ -89,6 +87,8 @@ if(MAGNUM_BUILD_DEPRECATED) MeshData2D.cpp MeshData3D.cpp) list(APPEND MagnumTrade_HEADERS + AbstractMaterialData.h + MeshData2D.h MeshData3D.h) endif() diff --git a/src/Magnum/Trade/MaterialData.cpp b/src/Magnum/Trade/MaterialData.cpp index 727a5a4a5..47c65d15a 100644 --- a/src/Magnum/Trade/MaterialData.cpp +++ b/src/Magnum/Trade/MaterialData.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "Magnum/Math/Vector4.h" #include "Magnum/Math/Matrix.h" @@ -275,6 +276,33 @@ const void* MaterialData::tryAttribute(const MaterialAttribute name) const { return tryAttribute(string); } +#ifdef MAGNUM_BUILD_DEPRECATED +CORRADE_IGNORE_DEPRECATED_PUSH +MaterialData::Flags MaterialData::flags() const { + Flags flags; + if(isDoubleSided()) + flags |= Flag::DoubleSided; + return flags; +} +CORRADE_IGNORE_DEPRECATED_POP +#endif + +bool MaterialData::isDoubleSided() const { + return attributeOr(MaterialAttribute::DoubleSided, false); +} + +MaterialAlphaMode MaterialData::alphaMode() const { + if(attributeOr(MaterialAttribute::AlphaBlend, false)) + return MaterialAlphaMode::Blend; + if(hasAttribute(MaterialAttribute::AlphaMask)) + return MaterialAlphaMode::Mask; + return MaterialAlphaMode::Opaque; +} + +Float MaterialData::alphaMask() const { + return attributeOr(MaterialAttribute::AlphaMask, 0.5f); +} + Containers::Array MaterialData::release() { return std::move(_data); } @@ -344,4 +372,44 @@ Debug& operator<<(Debug& debug, const MaterialTypes value) { }); } +#ifdef MAGNUM_BUILD_DEPRECATED +CORRADE_IGNORE_DEPRECATED_PUSH +Debug& operator<<(Debug& debug, const MaterialData::Flag value) { + debug << "Trade::MaterialData::Flag" << Debug::nospace; + + switch(value) { + /* LCOV_EXCL_START */ + #define _c(value) case MaterialData::Flag::value: return debug << "::" #value; + _c(DoubleSided) + #undef _c + /* LCOV_EXCL_STOP */ + } + + return debug << "(" << Debug::nospace << reinterpret_cast(UnsignedByte(value)) << Debug::nospace << ")"; +} + +Debug& operator<<(Debug& debug, const MaterialData::Flags value) { + return Containers::enumSetDebugOutput(debug, value, "Trade::MaterialData::Flags{}", { + MaterialData::Flag::DoubleSided + }); +} +CORRADE_IGNORE_DEPRECATED_POP +#endif + +Debug& operator<<(Debug& debug, const MaterialAlphaMode value) { + debug << "Trade::MaterialAlphaMode" << Debug::nospace; + + switch(value) { + /* LCOV_EXCL_START */ + #define _c(value) case MaterialAlphaMode::value: return debug << "::" #value; + _c(Opaque) + _c(Mask) + _c(Blend) + #undef _c + /* LCOV_EXCL_STOP */ + } + + return debug << "(" << Debug::nospace << reinterpret_cast(UnsignedByte(value)) << Debug::nospace << ")"; +} + }} diff --git a/src/Magnum/Trade/MaterialData.h b/src/Magnum/Trade/MaterialData.h index be54b499f..9ca17cc58 100644 --- a/src/Magnum/Trade/MaterialData.h +++ b/src/Magnum/Trade/MaterialData.h @@ -31,6 +31,7 @@ */ #include +#include #include #include @@ -63,6 +64,8 @@ enum class MaterialAttribute: UnsignedInt { * preferred, however renderers can fall back to alpha-masked rendering. * Alpha values below this value are meant to be rendered as fully * transparent and alpha values above this value as fully opaque. + * @see @ref MaterialAlphaMode, @ref MaterialData::alphaMode(), + * @ref MaterialData::alphaMask() */ AlphaMask = 1, @@ -74,6 +77,7 @@ enum class MaterialAttribute: UnsignedInt { * the material should be treated as opaque. If set together with * @ref MaterialAttribute::AlphaMask, blending is preferred, however * renderers can fall back to alpha-masked rendering. + * @see @ref MaterialAlphaMode, @ref MaterialData::alphaMode() */ AlphaBlend, @@ -81,6 +85,7 @@ enum class MaterialAttribute: UnsignedInt { * Double sided, @ref MaterialAttributeType::Bool. * * If not present, the default value is @cpp false @ce. + * @see @ref MaterialData::isDoubleSided() */ DoubleSided, @@ -89,6 +94,7 @@ enum class MaterialAttribute: UnsignedInt { * * If @ref MaterialAttribute::AmbientTexture is present as well, these two * are multiplied together. + * @see @ref PhongMaterialData::ambientColor() */ AmbientColor, @@ -98,6 +104,7 @@ enum class MaterialAttribute: UnsignedInt { * * If @ref MaterialAttribute::AmbientColor is present as well, these two * are multiplied together. + * @see @ref PhongMaterialData::ambientTexture() */ AmbientTexture, @@ -107,6 +114,7 @@ enum class MaterialAttribute: UnsignedInt { * * Has a precedence over @ref MaterialAttribute::TextureMatrix if both are * present. + * @see @ref PhongMaterialData::ambientTextureMatrix() */ AmbientTextureMatrix, @@ -116,6 +124,7 @@ enum class MaterialAttribute: UnsignedInt { * * Has a precedence over @ref MaterialAttribute::TextureCoordinates if both * are present. + * @see @ref PhongMaterialData::ambientTextureCoordinates() */ AmbientTextureCoordinates, @@ -124,6 +133,7 @@ enum class MaterialAttribute: UnsignedInt { * * If @ref MaterialAttribute::DiffuseTexture is present as well, these two * are multiplied together. + * @see @ref PhongMaterialData::diffuseColor() */ DiffuseColor, @@ -133,6 +143,7 @@ enum class MaterialAttribute: UnsignedInt { * * If @ref MaterialAttribute::DiffuseColor is present as well, these two * are multiplied together. + * @see @ref PhongMaterialData::diffuseTexture() */ DiffuseTexture, @@ -142,6 +153,7 @@ enum class MaterialAttribute: UnsignedInt { * * Has a precedence over @ref MaterialAttribute::TextureMatrix if both are * present. + * @see @ref PhongMaterialData::diffuseTextureMatrix() */ DiffuseTextureMatrix, @@ -151,6 +163,7 @@ enum class MaterialAttribute: UnsignedInt { * * Has a precedence over @ref MaterialAttribute::TextureCoordinates if both * are present. + * @see @ref PhongMaterialData::diffuseTextureCoordinates() */ DiffuseTextureCoordinates, @@ -159,6 +172,7 @@ enum class MaterialAttribute: UnsignedInt { * * If @ref MaterialAttribute::SpecularTexture is present as well, these two * are multiplied together. + * @see @ref PhongMaterialData::specularColor() */ SpecularColor, @@ -168,6 +182,7 @@ enum class MaterialAttribute: UnsignedInt { * * If @ref MaterialAttribute::SpecularColor is present as well, these two * are multiplied together. + * @see @ref PhongMaterialData::specularTexture() */ SpecularTexture, @@ -177,6 +192,7 @@ enum class MaterialAttribute: UnsignedInt { * * Has a precedence over @ref MaterialAttribute::TextureMatrix if both are * present. + * @see @ref PhongMaterialData::specularTextureMatrix() */ SpecularTextureMatrix, @@ -186,17 +202,21 @@ enum class MaterialAttribute: UnsignedInt { * * Has a precedence over @ref MaterialAttribute::TextureCoordinates if both * are present. + * @see @ref PhongMaterialData::specularTextureCoordinates() */ SpecularTextureCoordinates, /** * Shininess value for Phong materials, @ref MaterialAttributeType::Float. + * + * @see @ref PhongMaterialData::shininess() */ Shininess, /** * Tangent-space normal map texture index, * @ref MaterialAttributeType::UnsignedInt. + * @see @ref PhongMaterialData::normalTexture() */ NormalTexture, @@ -206,6 +226,7 @@ enum class MaterialAttribute: UnsignedInt { * * Has a precedence over @ref MaterialAttribute::TextureMatrix if both are * present. + * @see @ref PhongMaterialData::normalTextureMatrix() */ NormalTextureMatrix, @@ -215,6 +236,7 @@ enum class MaterialAttribute: UnsignedInt { * * Has a precedence over @ref MaterialAttribute::TextureCoordinates if both * are present. + * @see @ref PhongMaterialData::normalTextureCoordinates() */ NormalTextureCoordinates, @@ -227,6 +249,7 @@ enum class MaterialAttribute: UnsignedInt { * @ref MaterialAttribute::SpecularTextureMatrix / * @ref MaterialAttribute::NormalTextureMatrix have a precedence over this * attribute for given texture, if present. + * @see @ref PhongMaterialData::textureMatrix() */ TextureMatrix, @@ -237,8 +260,9 @@ enum class MaterialAttribute: UnsignedInt { * @ref MaterialAttribute::AmbientTextureCoordinates / * @ref MaterialAttribute::DiffuseTextureCoordinates / * @ref MaterialAttribute::SpecularTextureCoordinates / - * @ref MaterialAttribute::NormalTextureCoordinates have a precedence over - * this attribute for given texture, if present. + * @ref MaterialAttribute::NormalTextureCoordinates have a precedence + * over this attribute for given texture, if present. + * @see @ref PhongMaterialData::textureCoordinates() */ TextureCoordinates, }; @@ -510,11 +534,13 @@ class MAGNUM_TRADE_EXPORT MaterialAttributeData { /** @brief Material type -@see @ref MaterialTypes, @ref MaterialData::types(), - @ref AbstractMaterialData::type() +@see @ref MaterialTypes, @ref MaterialData::types() */ enum class MaterialType: UnsignedInt { - Phong = 1 << 0 /**< Phong shading */ + /** + * Phong. Use @ref PhongMaterialData for convenience attribute access. + */ + Phong = 1 << 0 }; /** @debugoperatorenum{MaterialType} */ @@ -533,6 +559,34 @@ CORRADE_ENUMSET_OPERATORS(MaterialTypes) /** @debugoperatorenum{MaterialTypes} */ MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, MaterialTypes value); +/** +@brief Material alpha mode + +Convenience access to @ref MaterialAttribute::AlphaBlend and +@ref MaterialAttribute::AlphaMask attributes. +@see @ref MaterialData::alphaMode(), @ref MaterialData::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 MaterialData::alphaMask() value. + */ + Mask, + + /** + * The alpha value is used to combine source and destination colors using + * additive blending. + */ + Blend +}; + +/** @debugoperatorenum{MaterialAlphaMode} */ +MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, MaterialAlphaMode value); + /** @brief Material data @m_since_latest @@ -567,6 +621,41 @@ precision. */ class MAGNUM_TRADE_EXPORT MaterialData { public: + #ifdef MAGNUM_BUILD_DEPRECATED + /** + * @brief Material flag + * @m_deprecated_since_latest The flags are no longer stored directly + * but generated on-the-fly from attribute data, which makes them + * less efficient than calling @ref hasAttribute(), + * @ref isDoubleSided() etc. + * + * This enum is further extended in subclasses. + * @see @ref Flags, @ref flags() + */ + enum class CORRADE_DEPRECATED_ENUM("use hasAttribute() etc. instead") Flag: UnsignedInt { + /** + * 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 + * @m_deprecated_since_latest The flags are no longer stored directly + * but generated on-the-fly from attribute data, which makes them + * less efficient than calling @ref hasAttribute(), + * @ref isDoubleSided() etc. + * + * This enum is extended in subclasses. + * @see @ref flags() + */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC warns about Flag, ugh */ + typedef CORRADE_DEPRECATED("use hasAttribute() etc. instead") Containers::EnumSet Flags; + CORRADE_IGNORE_DEPRECATED_POP + #endif + /** * @brief Construct * @param types Which material types are described by this @@ -618,6 +707,16 @@ class MAGNUM_TRADE_EXPORT MaterialData { */ MaterialTypes types() const { return _types; } + #ifdef MAGNUM_BUILD_DEPRECATED + /** + * @brief Material type + * @m_deprecated_since_latest Use @ref types() instead. + */ + CORRADE_DEPRECATED("use types() instead") MaterialType type() const { + return MaterialType(UnsignedInt(_types & MaterialType::Phong)); + } + #endif + /** * @brief Raw attribute data * @@ -744,6 +843,47 @@ class MAGNUM_TRADE_EXPORT MaterialData { template T attributeOr(Containers::StringView name, const T& defaultValue) const; template T attributeOr(MaterialAttribute name, const T& defaultValue) const; /**< @overload */ + /** + * @brief Whether a material is double-sided + * + * Convenience access to the @ref MaterialAttribute::DoubleSided + * attribute. If not present, the default is @cpp false @ce. + */ + bool isDoubleSided() const; + + #ifdef MAGNUM_BUILD_DEPRECATED + /** + * @brief Material flags + * @m_deprecated_since_latest The flags are no longer stored directly + * but generated on-the-fly from attribute data, which makes them + * less efficient than calling @ref hasAttribute(), + * @ref isDoubleSided() etc. + * + * Not all bits returned might be defined by @ref Flag, subclasses may + * define extra values. + */ + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC warns about Flags, ugh */ + CORRADE_DEPRECATED("use hasAttribute() instead") Flags flags() const; + CORRADE_IGNORE_DEPRECATED_POP + #endif + + /** + * @brief Alpha mode + * + * Convenience access to @ref MaterialAttribute::AlphaBlend and + * @ref MaterialAttribute::AlphaMask attributes. If neither is present, + * the default is @ref MaterialAlphaMode::Opaque. + */ + MaterialAlphaMode alphaMode() const; + + /** + * @brief Alpha mask + * + * Convenience access to the @ref MaterialAttribute::AlphaMask + * attribute. If not present, the default is @cpp 0.5f @ce. + */ + Float alphaMask() const; + /** * @brief Release data storage * @@ -773,6 +913,32 @@ class MAGNUM_TRADE_EXPORT MaterialData { const void* _importerState; }; +#ifdef MAGNUM_BUILD_DEPRECATED +CORRADE_IGNORE_DEPRECATED_PUSH +CORRADE_ENUMSET_OPERATORS(MaterialData::Flags) + +/** +@debugoperatorclassenum{MaterialData,MaterialData::Flag} +@m_deprecated_since_latest The flags are no longer stored directly but + generated on-the-fly from attribute data, which makes them less efficient + than calling @ref MaterialData::hasAttribute(), + @ref MaterialData::isDoubleSided() etc. +*/ +/* Not marked with CORRADE_DEPRECATED() as there's enough warnings already */ +MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, MaterialData::Flag value); + +/** +@debugoperatorclassenum{MaterialData,MaterialData::Flags} +@m_deprecated_since_latest The flags are no longer stored directly but + generated on-the-fly from attribute data, which makes them less efficient + than calling @ref MaterialData::hasAttribute(), + @ref MaterialData::isDoubleSided() etc. +*/ +/* Not marked with CORRADE_DEPRECATED() as there's enough warnings already */ +MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, MaterialData::Flags value); +CORRADE_IGNORE_DEPRECATED_POP +#endif + namespace Implementation { /* LCOV_EXCL_START */ template struct MaterialAttributeTypeFor { diff --git a/src/Magnum/Trade/PhongMaterialData.cpp b/src/Magnum/Trade/PhongMaterialData.cpp index c5c920f78..bf0b48915 100644 --- a/src/Magnum/Trade/PhongMaterialData.cpp +++ b/src/Magnum/Trade/PhongMaterialData.cpp @@ -27,92 +27,228 @@ #include "PhongMaterialData.h" #include +#ifdef MAGNUM_BUILD_DEPRECATED +#include +#endif + +#include "Magnum/Math/Color.h" +#include "Magnum/Math/Matrix3.h" namespace Magnum { namespace Trade { using namespace Math::Literals; -PhongMaterialData::PhongMaterialData(const Flags flags, const Color4& ambientColor, const UnsignedInt ambientTexture, const UnsignedInt ambientTextureCoordinates, const Color4& diffuseColor, const UnsignedInt diffuseTexture, const UnsignedInt diffuseTextureCoordinates, const Color4& specularColor, const UnsignedInt specularTexture, const UnsignedInt specularTextureCoordinates, const UnsignedInt normalTexture, const UnsignedInt normalTextureCoordinates, 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} { +#ifdef MAGNUM_BUILD_DEPRECATED +CORRADE_IGNORE_DEPRECATED_PUSH +PhongMaterialData::PhongMaterialData(const Flags flags, const Color4& ambientColor, const UnsignedInt ambientTexture, const UnsignedInt ambientTextureCoordinates, const Color4& diffuseColor, const UnsignedInt diffuseTexture, const UnsignedInt diffuseTextureCoordinates, const Color4& specularColor, const UnsignedInt specularTexture, const UnsignedInt specularTextureCoordinates, const UnsignedInt normalTexture, const UnsignedInt normalTextureCoordinates, const Matrix3& textureMatrix, const MaterialAlphaMode alphaMode, const Float alphaMask, const Float shininess, const void* const importerState) noexcept: MaterialData{MaterialType::Phong, [&](){ + Containers::Array data; + + if(flags & Flag::DoubleSided) + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::DoubleSided, true); + if(alphaMode == MaterialAlphaMode::Blend) + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::AlphaBlend, true); + /* Include a mask also if it has a non-default value to stay compatible + with existing behavior */ + if(alphaMode == MaterialAlphaMode::Mask || alphaMask != 0.0f) + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::AlphaMask, alphaMask); + 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", ); + "Trade::PhongMaterialData: texture transformation enabled but the material has no textures", data); CORRADE_ASSERT((flags & Flag::TextureTransformation) || textureMatrix == Matrix3{}, - "PhongMaterialData::PhongMaterialData: non-default texture matrix requires Flag::TextureTransformation to be enabled", ); - CORRADE_ASSERT((flags & Flag::TextureCoordinates) || (ambientTextureCoordinates == 0 && diffuseTextureCoordinates == 0 && specularTextureCoordinates == 0 && normalTextureCoordinates == 0), - "PhongMaterialData::PhongMaterialData: non-zero texture coordinate sets require Flag::TextureCoordinates to be enabled", ); + "PhongMaterialData::PhongMaterialData: non-default texture matrix requires Flag::TextureTransformation to be enabled", data); + CORRADE_ASSERT((flags & Flag::TextureCoordinateSets) || (ambientTextureCoordinates == 0 && diffuseTextureCoordinates == 0 && specularTextureCoordinates == 0 && normalTextureCoordinates == 0), + "PhongMaterialData::PhongMaterialData: non-zero texture coordinate sets require Flag::TextureCoordinates to be enabled", data); + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::AmbientColor, ambientColor); if(flags & Flag::AmbientTexture) { - _ambientTexture = ambientTexture; - _ambientTextureCoordinates = ambientTextureCoordinates; + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::AmbientTexture, ambientTexture); + if(ambientTextureCoordinates) + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::AmbientTextureCoordinates, ambientTextureCoordinates); } + + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::DiffuseColor, diffuseColor); if(flags & Flag::DiffuseTexture) { - _diffuseTexture = diffuseTexture; - _diffuseTextureCoordinates = diffuseTextureCoordinates; + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::DiffuseTexture, diffuseTexture); + if(diffuseTextureCoordinates) + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::DiffuseTextureCoordinates, diffuseTextureCoordinates); } + + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::SpecularColor, specularColor); if(flags & Flag::SpecularTexture) { - _specularTexture = specularTexture; - _specularTextureCoordinates = specularTextureCoordinates; + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::SpecularTexture, specularTexture); + if(specularTextureCoordinates) + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::SpecularTextureCoordinates, specularTextureCoordinates); } + if(flags & Flag::NormalTexture) { - _normalTexture = normalTexture; - _normalTextureCoordinates = normalTextureCoordinates; + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::NormalTexture, normalTexture); + if(normalTextureCoordinates) + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::NormalTextureCoordinates, normalTextureCoordinates); } + if(flags & Flag::TextureTransformation) - _textureMatrix = textureMatrix; + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::TextureMatrix, textureMatrix); + + arrayAppend(data, Containers::InPlaceInit, MaterialAttribute::Shininess, shininess); + + return data; +}(), importerState} { + /* The data can't be filled here because it won't be sorted correctly */ } PhongMaterialData::PhongMaterialData(const Flags flags, const Color4& ambientColor, const UnsignedInt ambientTexture, const Color4& diffuseColor, const UnsignedInt diffuseTexture, const Color4& specularColor, const UnsignedInt specularTexture, const UnsignedInt normalTexture, const Matrix3& textureMatrix, const MaterialAlphaMode alphaMode, const Float alphaMask, const Float shininess, const void* const importerState) noexcept: PhongMaterialData{flags, ambientColor, ambientTexture, 0, diffuseColor, diffuseTexture, 0, specularColor, specularTexture, 0, normalTexture, 0, textureMatrix, alphaMode, alphaMask, shininess, importerState} {} -#ifdef MAGNUM_BUILD_DEPRECATED PhongMaterialData::PhongMaterialData(const Flags flags, const MaterialAlphaMode alphaMode, const Float alphaMask, const Float shininess, const void* const importerState) noexcept: PhongMaterialData{flags, 0x000000ff_rgbaf, {}, 0xffffffff_rgbaf, {}, 0xffffffff_rgbaf, {}, {}, {}, alphaMode, alphaMask, shininess, importerState} {} +CORRADE_IGNORE_DEPRECATED_POP +#endif + +#ifdef MAGNUM_BUILD_DEPRECATED +CORRADE_IGNORE_DEPRECATED_PUSH +PhongMaterialData::Flags PhongMaterialData::flags() const { + /* "Append" to flags recognized by the base class */ + Flags flags{Flag(UnsignedInt(MaterialData::flags()))}; + + if(hasAttribute(MaterialAttribute::AmbientTexture)) + flags |= Flag::AmbientTexture; + if(hasAttribute(MaterialAttribute::DiffuseTexture)) + flags |= Flag::DiffuseTexture; + if(hasAttribute(MaterialAttribute::SpecularTexture)) + flags |= Flag::SpecularTexture; + if(hasAttribute(MaterialAttribute::NormalTexture)) + flags |= Flag::NormalTexture; + if(hasTextureTransformation()) + flags |= Flag::TextureTransformation; + if(hasTextureCoordinates()) + flags |= Flag::TextureCoordinates; + + return flags; +} +CORRADE_IGNORE_DEPRECATED_POP #endif -PhongMaterialData::PhongMaterialData(PhongMaterialData&& other) noexcept = default; +bool PhongMaterialData::hasTextureTransformation() const { + return hasAttribute(MaterialAttribute::AmbientTextureMatrix) || + hasAttribute(MaterialAttribute::DiffuseTextureMatrix) || + hasAttribute(MaterialAttribute::SpecularTextureMatrix) || + hasAttribute(MaterialAttribute::NormalTextureMatrix) || + hasAttribute(MaterialAttribute::TextureMatrix); +} + +bool PhongMaterialData::hasTextureCoordinates() const { + return attributeOr(MaterialAttribute::AmbientTextureCoordinates, 0u) || + attributeOr(MaterialAttribute::DiffuseTextureCoordinates, 0u) || + attributeOr(MaterialAttribute::SpecularTextureCoordinates, 0u) || + attributeOr(MaterialAttribute::NormalTextureCoordinates, 0u) || + attributeOr(MaterialAttribute::TextureCoordinates, 0u); +} -PhongMaterialData& PhongMaterialData::operator=(PhongMaterialData&& other) noexcept = default; +Color4 PhongMaterialData::ambientColor() const { + return attributeOr(MaterialAttribute::AmbientColor, + hasAttribute(MaterialAttribute::AmbientTexture) ? 0xffffffff_rgbaf : 0x000000ff_rgbaf); +} UnsignedInt PhongMaterialData::ambientTexture() const { - CORRADE_ASSERT(flags() & Flag::AmbientTexture, "Trade::PhongMaterialData::ambientTexture(): the material doesn't have an ambient texture", {}); - return _ambientTexture; + return attribute(MaterialAttribute::AmbientTexture); } +Matrix3 PhongMaterialData::ambientTextureMatrix() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::AmbientTexture), + "Trade::PhongMaterialData::ambientTextureMatrix(): the material doesn't have an ambient texture", {}); + if(Containers::Optional set = tryAttribute(MaterialAttribute::AmbientTextureMatrix)) + return *set; + return attributeOr(MaterialAttribute::TextureMatrix, Matrix3{}); +} UnsignedInt PhongMaterialData::ambientTextureCoordinates() const { - CORRADE_ASSERT(flags() & Flag::AmbientTexture, "Trade::PhongMaterialData::ambientTextureCoordinates(): the material doesn't have an ambient texture", {}); - return _ambientTextureCoordinates; + CORRADE_ASSERT(hasAttribute(MaterialAttribute::AmbientTexture), + "Trade::PhongMaterialData::ambientTextureCoordinates(): the material doesn't have an ambient texture", {}); + if(Containers::Optional set = tryAttribute(MaterialAttribute::AmbientTextureCoordinates)) + return *set; + return attributeOr(MaterialAttribute::TextureCoordinates, 0u); +} + +Color4 PhongMaterialData::diffuseColor() const { + return attributeOr(MaterialAttribute::DiffuseColor, 0xffffffff_rgbaf); } UnsignedInt PhongMaterialData::diffuseTexture() const { - CORRADE_ASSERT(flags() & Flag::DiffuseTexture, "Trade::PhongMaterialData::diffuseTexture(): the material doesn't have a diffuse texture", {}); - return _diffuseTexture; + return attribute(MaterialAttribute::DiffuseTexture); } +Matrix3 PhongMaterialData::diffuseTextureMatrix() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::DiffuseTexture), + "Trade::PhongMaterialData::diffuseTextureMatrix(): the material doesn't have a diffuse texture", {}); + if(Containers::Optional set = tryAttribute(MaterialAttribute::DiffuseTextureMatrix)) + return *set; + return attributeOr(MaterialAttribute::TextureMatrix, Matrix3{}); +} UnsignedInt PhongMaterialData::diffuseTextureCoordinates() const { - CORRADE_ASSERT(flags() & Flag::DiffuseTexture, "Trade::PhongMaterialData::diffuseTextureCoordinates(): the material doesn't have a diffuse texture", {}); - return _diffuseTextureCoordinates; + CORRADE_ASSERT(hasAttribute(MaterialAttribute::DiffuseTexture), + "Trade::PhongMaterialData::diffuseTextureCoordinates(): the material doesn't have a diffuse texture", {}); + if(Containers::Optional set = tryAttribute(MaterialAttribute::DiffuseTextureCoordinates)) + return *set; + return attributeOr(MaterialAttribute::TextureCoordinates, 0u); +} + +Color4 PhongMaterialData::specularColor() const { + return attributeOr(MaterialAttribute::SpecularColor, 0xffffffff_rgbaf); } UnsignedInt PhongMaterialData::specularTexture() const { - CORRADE_ASSERT(flags() & Flag::SpecularTexture, "Trade::PhongMaterialData::specularTexture(): the material doesn't have a specular texture", {}); - return _specularTexture; + return attribute(MaterialAttribute::SpecularTexture); } +Matrix3 PhongMaterialData::specularTextureMatrix() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::SpecularTexture), + "Trade::PhongMaterialData::specularTextureMatrix(): the material doesn't have a specular texture", {}); + if(Containers::Optional set = tryAttribute(MaterialAttribute::SpecularTextureMatrix)) + return *set; + return attributeOr(MaterialAttribute::TextureMatrix, Matrix3{}); +} UnsignedInt PhongMaterialData::specularTextureCoordinates() const { - CORRADE_ASSERT(flags() & Flag::SpecularTexture, "Trade::PhongMaterialData::specularTextureCoordinates(): the material doesn't have a specular texture", {}); - return _specularTextureCoordinates; + CORRADE_ASSERT(hasAttribute(MaterialAttribute::SpecularTexture), + "Trade::PhongMaterialData::specularTextureCoordinates(): the material doesn't have a specular texture", {}); + if(Containers::Optional set = tryAttribute(MaterialAttribute::SpecularTextureCoordinates)) + return *set; + return attributeOr(MaterialAttribute::TextureCoordinates, 0u); } UnsignedInt PhongMaterialData::normalTexture() const { - CORRADE_ASSERT(flags() & Flag::NormalTexture, "Trade::PhongMaterialData::normalTexture(): the material doesn't have a normal texture", {}); - return _normalTexture; + return attribute(MaterialAttribute::NormalTexture); +} + +Matrix3 PhongMaterialData::normalTextureMatrix() const { + CORRADE_ASSERT(hasAttribute(MaterialAttribute::NormalTexture), + "Trade::PhongMaterialData::normalTextureMatrix(): the material doesn't have a normal texture", {}); + if(Containers::Optional set = tryAttribute(MaterialAttribute::NormalTextureMatrix)) + return *set; + return attributeOr(MaterialAttribute::TextureMatrix, Matrix3{}); } UnsignedInt PhongMaterialData::normalTextureCoordinates() const { - CORRADE_ASSERT(flags() & Flag::NormalTexture, "Trade::PhongMaterialData::normalTextureCoordinates(): the material doesn't have a normal texture", {}); - return _normalTextureCoordinates; + CORRADE_ASSERT(hasAttribute(MaterialAttribute::NormalTexture), + "Trade::PhongMaterialData::normalTextureCoordinates(): the material doesn't have a normal texture", {}); + if(Containers::Optional set = tryAttribute(MaterialAttribute::NormalTextureCoordinates)) + return *set; + return attributeOr(MaterialAttribute::TextureCoordinates, 0u); +} + +Matrix3 PhongMaterialData::textureMatrix() const { + return attributeOr(MaterialAttribute::TextureMatrix, Matrix3{}); +} + +UnsignedInt PhongMaterialData::textureCoordinates() const { + return attributeOr(MaterialAttribute::TextureCoordinates, 0u); +} + +Float PhongMaterialData::shininess() const { + return attributeOr(MaterialAttribute::Shininess, 80.0f); } +#ifdef MAGNUM_BUILD_DEPRECATED +CORRADE_IGNORE_DEPRECATED_PUSH Debug& operator<<(Debug& debug, const PhongMaterialData::Flag value) { debug << "Trade::PhongMaterialData::Flag" << Debug::nospace; @@ -143,5 +279,7 @@ Debug& operator<<(Debug& debug, const PhongMaterialData::Flags value) { PhongMaterialData::Flag::TextureTransformation, PhongMaterialData::Flag::TextureCoordinates}); } +CORRADE_IGNORE_DEPRECATED_POP +#endif }} diff --git a/src/Magnum/Trade/PhongMaterialData.h b/src/Magnum/Trade/PhongMaterialData.h index abeccc3cb..d7d8cce3f 100644 --- a/src/Magnum/Trade/PhongMaterialData.h +++ b/src/Magnum/Trade/PhongMaterialData.h @@ -30,10 +30,7 @@ * @brief Class @ref Magnum::Trade::PhongMaterialData */ -#include "Magnum/Magnum.h" -#include "Magnum/Math/Color.h" -#include "Magnum/Math/Matrix3.h" -#include "Magnum/Trade/AbstractMaterialData.h" +#include "Magnum/Trade/MaterialData.h" namespace Magnum { namespace Trade { @@ -42,16 +39,22 @@ namespace Magnum { namespace Trade { @see @ref AbstractImporter::material() */ -class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { +class MAGNUM_TRADE_EXPORT PhongMaterialData: public MaterialData { public: + #ifdef MAGNUM_BUILD_DEPRECATED /** * @brief Material flag + * @m_deprecated_since_latest The flags are no longer stored directly + * but generated on-the-fly from attribute data, which makes them + * less efficient than calling @ref hasAttribute(), + * @ref isDoubleSided(), @ref hasTextureTransformation(), + * @ref hasTextureCoordinates() etc. * - * A superset of @ref AbstractMaterialData::Flag. + * A superset of @ref MaterialData::Flag. * @see @ref Flags, @ref flags() */ - enum class Flag: UnsignedShort { - /** @copydoc AbstractMaterialData::Flag::DoubleSided */ + enum class CORRADE_DEPRECATED_ENUM("use hasAttribute() etc. instead") Flag: UnsignedInt { + /** @copydoc MaterialData::Flag::DoubleSided */ DoubleSided = 1 << 0, /** The material has an ambient texture */ @@ -93,12 +96,30 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { /** * @brief Material flags + * @m_deprecated_since_latest The flags are no longer stored directly + * but generated on-the-fly from attribute data, which makes them + * less efficient than calling @ref hasAttribute(), + * @ref isDoubleSided(), @ref hasTextureTransformation(), + * @ref hasTextureCoordinates() etc. * - * A superset of @ref AbstractMaterialData::Flags. + * A superset of @ref MaterialData::Flags. * @see @ref flags() */ - typedef Containers::EnumSet Flags; + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC warns about Flags, ugh */ + typedef CORRADE_DEPRECATED("use hasAttribute() etc. instead") Containers::EnumSet Flags; + CORRADE_IGNORE_DEPRECATED_POP + #endif + #ifndef DOXYGEN_GENERATING_OUTPUT + /* Allow constructing subclasses directly. While not used in the + general Importer workflow, it allows users to create instances with + desired convenience APIs easier (and simplifies testing). It's + however hidden from the docs as constructing instances this way + isn't really common and it would add a lot of noise. */ + using MaterialData::MaterialData; + #endif + + #ifdef MAGNUM_BUILD_DEPRECATED /** * @brief Constructor * @param flags Material flags @@ -107,12 +128,12 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { * non-textured material and @cpp 0xffffffff_rgbaf @ce for a * default value for a textured material. * @param ambientTexture Ambient texture ID. Ignored if @p flags - * doesn't have @ref Flag::AmbientTexture + * doesn't have @ref Flag::AmbientTexture. * @param diffuseColor Diffuse color. Use * @cpp 0xffffffff_rgbaf @ce for a default value for both a * non-textured and a textured material. * @param diffuseTexture Diffuse texture ID. Ignored if @p flags - * doesn't have @ref Flag::DiffuseTexture + * doesn't have @ref Flag::DiffuseTexture. * @param specularColor Specular color. Use * @cpp 0xffffff00_rgbaf @ce for a default value for both a * non-textured and a textured material. @@ -128,13 +149,19 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { * @param shininess Shininess. Use @cpp 80.0f @ce for a default * value. * @param importerState Importer-specific state - * @m_since{2020,06} * * All `*TextureCoordinates()` accessors are implicitly zero with this * constructor. If @p textureMatrix is not default-constructed, expects * @ref Flag::TextureTransformation to be enabled as well. + * + * @m_deprecated_since_latest Populate a @ref MaterialData instance + * using @ref MaterialData::MaterialData(MaterialTypes, Containers::Array&&, const void*) + * instead. This class is not meant to be constructed directly + * anymore. */ - 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; + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC warns about Flags, ugh */ + explicit CORRADE_DEPRECATED("use MaterialData::MaterialData(MaterialTypes, Containers::Array&&, const void*) instead") 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; + CORRADE_IGNORE_DEPRECATED_POP /** * @brief Construct with non-zero texture coordinate sets @@ -173,69 +200,122 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { * @param shininess Shininess. Use @cpp 80.0f @ce for a * default value. * @param importerState Importer-specific state - * @m_since{2020,06} * * If @p textureMatrix is not default-constructed, expects * @ref Flag::TextureTransformation to be enabled as well. If any * `*Coordinates` parameter is non-zero, expects * @ref Flag::TextureCoordinates to be enabled as well. + * + * @m_deprecated_since_latest Populate a @ref MaterialData instance + * using @ref MaterialData::MaterialData(MaterialTypes, Containers::Array&&, const void*) + * instead. This class is not meant to be constructed directly + * anymore. */ - explicit PhongMaterialData(Flags flags, const Color4& ambientColor, UnsignedInt ambientTexture, UnsignedInt ambientTextureCoordinates, const Color4& diffuseColor, UnsignedInt diffuseTexture, UnsignedInt diffuseTextureCoordinates, const Color4& specularColor, UnsignedInt specularTexture, UnsignedInt specularTextureCoordinates, UnsignedInt normalTexture, UnsignedInt normalTextureCoordinates, const Matrix3& textureMatrix, MaterialAlphaMode alphaMode, Float alphaMask, Float shininess, const void* importerState = nullptr) noexcept; + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC warns about Flags, ugh */ + explicit CORRADE_DEPRECATED("use MaterialData::MaterialData(MaterialTypes, Containers::Array&&, const void*) instead") PhongMaterialData(Flags flags, const Color4& ambientColor, UnsignedInt ambientTexture, UnsignedInt ambientTextureCoordinates, const Color4& diffuseColor, UnsignedInt diffuseTexture, UnsignedInt diffuseTextureCoordinates, const Color4& specularColor, UnsignedInt specularTexture, UnsignedInt specularTextureCoordinates, UnsignedInt normalTexture, UnsignedInt normalTextureCoordinates, const Matrix3& textureMatrix, MaterialAlphaMode alphaMode, Float alphaMask, Float shininess, const void* importerState = nullptr) noexcept; + CORRADE_IGNORE_DEPRECATED_POP - #ifdef MAGNUM_BUILD_DEPRECATED /** * @brief Constructor - * @m_deprecated_since{2020,06} Use @ref PhongMaterialData(Flags, const Color4&, UnsignedInt, const Color4&, UnsignedInt, const Color4&, UnsignedInt, UnsignedInt, const Matrix3&, MaterialAlphaMode, Float, Float, const void*) - * instead. + * @m_deprecated_since{2020,06} Populate a @ref MaterialData instance + * using @ref MaterialData::MaterialData(MaterialTypes, Containers::Array&&, const void*) + * instead. This class is not meant to be constructed directly + * anymore. */ - explicit CORRADE_DEPRECATED("use PhongMaterialData(Flags, const Color4&, UnsignedInt, const Color4&, UnsignedInt, const Color4&, UnsignedInt, UnsignedInt, const Matrix3&, MaterialAlphaMode, Float, Float, const void*) instead") PhongMaterialData(Flags flags, MaterialAlphaMode alphaMode, Float alphaMask, Float shininess, const void* importerState = nullptr) noexcept; + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC warns about Flags, ugh */ + explicit CORRADE_DEPRECATED("use MaterialData::MaterialData(MaterialTypes, Containers::Array&&, const void*) instead") PhongMaterialData(Flags flags, MaterialAlphaMode alphaMode, Float alphaMask, Float shininess, const void* importerState = nullptr) noexcept; + CORRADE_IGNORE_DEPRECATED_POP #endif - /** @brief Copying is not allowed */ - PhongMaterialData(const PhongMaterialData&) = delete; - - /** @brief Move constructor */ - PhongMaterialData(PhongMaterialData&& other) noexcept; - - /** @brief Copying is not allowed */ - PhongMaterialData& operator=(const PhongMaterialData&) = delete; + /** + * @brief Whether the material has texture transformation + * @m_since_latest + * + * Returns @cpp true @ce if any of the + * @ref MaterialAttribute::AmbientTextureMatrix, + * @ref MaterialAttribute::DiffuseTextureMatrix, + * @ref MaterialAttribute::SpecularTextureMatrix, + * @ref MaterialAttribute::NormalTextureMatrix or + * @ref MaterialAttribute::TextureMatrix attributes is present, + * @cpp false @ce otherwise. + */ + bool hasTextureTransformation() const; - /** @brief Move assignment */ - PhongMaterialData& operator=(PhongMaterialData&& other) noexcept; + /** + * @brief Whether the material uses extra texture coordinate sets + * @m_since_latest + * + * Returns @cpp true @ce if any of the + * @ref MaterialAttribute::AmbientTextureCoordinates, + * @ref MaterialAttribute::DiffuseTextureCoordinates, + * @ref MaterialAttribute::SpecularTextureCoordinates, + * @ref MaterialAttribute::NormalTextureCoordinates or + * @ref MaterialAttribute::TextureCoordinates attributes is present and + * has a non-zero value, @cpp false @ce otherwise. + */ + bool hasTextureCoordinates() const; + #ifdef MAGNUM_BUILD_DEPRECATED /** * @brief Material flags + * @m_deprecated_since_latest The flags are no longer stored directly + * but generated on-the-fly from attribute data, which makes them + * less efficient than calling @ref hasAttribute(), + * @ref isDoubleSided(), @ref hasTextureTransformation(), + * @ref hasTextureCoordinates() etc. * - * A superset of @ref AbstractMaterialData::flags(). + * A superset of @ref MaterialData::flags(). */ - Flags flags() const { - return Flag(UnsignedShort(AbstractMaterialData::flags())); - } + CORRADE_IGNORE_DEPRECATED_PUSH /* GCC warns about Flags, ugh */ + CORRADE_DEPRECATED("use hasAttribute() instead") Flags flags() const; + CORRADE_IGNORE_DEPRECATED_POP + #endif /** * @brief Ambient color * - * If the material has @ref Flag::AmbientTexture, the color and texture - * is multiplied together. - * @see @ref flags() + * Convenience access to the @ref MaterialAttribute::AmbientColor + * attribute. If not present, the default is either + * @cpp 0xffffffff_rgbaf @ce if there's + * @ref MaterialAttribute::AmbientTexture and @cpp 0x000000ff_rgbaf @ce + * otherwise. + * + * If the material has @ref MaterialAttribute::AmbientTexture, the + * color and texture is meant to be multiplied together. + * @see @ref hasAttribute() */ - Color4 ambientColor() const { return _ambientColor; } + Color4 ambientColor() const; /** * @brief Ambient texture ID * - * Available only if the material has @ref Flag::AmbientTexture. - * Multiplied with @ref ambientColor(). - * @see @ref flags(), @ref AbstractImporter::texture() + * Available only if @ref MaterialAttribute::AmbientTexture is + * present. Meant to be multiplied with @ref ambientColor(). + * @see @ref hasAttribute() */ UnsignedInt ambientTexture() const; + /** + * @brief Ambient texture coordinate transformation matrix + * @m_since_latest + * + * Convenience access to the @ref MaterialAttribute::AmbientTextureMatrix + * / @ref MaterialAttribute::TextureMatrix attributes. If neither is + * present, the default is an identity matrix. Available only if the + * material has @ref MaterialAttribute::AmbientTexture. + * @see @ref hasAttribute() + */ + Matrix3 ambientTextureMatrix() const; + /** * @brief Ambient texture coordinate set * @m_since_latest * - * Available only if the material has @ref Flag::AmbientTexture. - * @see @ref flags(), @ref AbstractImporter::texture() + * Convenience access to the @ref MaterialAttribute::AmbientTextureCoordinates + * / @ref MaterialAttribute::TextureCoordinates attributes. If neither + * is present, the default is @cpp 0 @ce. Available only if the + * material has @ref MaterialAttribute::AmbientTexture. + * @see @ref hasAttribute() */ UnsignedInt ambientTextureCoordinates() const; @@ -253,27 +333,45 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { /** * @brief Diffuse color * - * If the material has @ref Flag::DiffuseTexture, the color and texture - * is multiplied together. - * @see @ref flags() + * Convenience access to the @ref MaterialAttribute::DiffuseColor + * attribute. If not present, the default is @cpp 0xffffffff_rgbaf @ce. + * + * If the material has @ref MaterialAttribute::DiffuseTexture, the + * color and texture is meant to be multiplied together. + * @see @ref hasAttribute() */ - Color4 diffuseColor() const { return _diffuseColor; } + Color4 diffuseColor() const; /** * @brief Diffuse texture ID * - * Available only if the material has @ref Flag::DiffuseTexture. - * Multiplied with @ref diffuseColor(). - * @see @ref flags(), @ref AbstractImporter::texture() + * Available only if @ref MaterialAttribute::DiffuseTexture is + * present. Meant to be multiplied with @ref diffuseColor(). + * @see @ref hasAttribute(), @ref AbstractImporter::texture() */ UnsignedInt diffuseTexture() const; + /** + * @brief Diffuse texture coordinate transformation matrix + * @m_since_latest + * + * Convenience access to the @ref MaterialAttribute::DiffuseTextureMatrix + * / @ref MaterialAttribute::TextureMatrix attributes. If neither is + * present, the default is an identity matrix. Available only if the + * material has @ref MaterialAttribute::DiffuseTexture. + * @see @ref hasAttribute() + */ + Matrix3 diffuseTextureMatrix() const; + /** * @brief Diffuse texture coordinate set * @m_since_latest * - * Available only if the material has @ref Flag::DiffuseTexture. - * @see @ref flags(), @ref AbstractImporter::texture() + * Convenience access to the @ref MaterialAttribute::DiffuseTextureCoordinates + * / @ref MaterialAttribute::TextureCoordinates attributes. If neither + * is present, the default is @cpp 0 @ce. Available only if the + * material has @ref MaterialAttribute::DiffuseTexture. + * @see @ref hasAttribute() */ UnsignedInt diffuseTextureCoordinates() const; @@ -291,27 +389,45 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { /** * @brief Specular color * - * If the material has @ref Flag::SpecularTexture, the color and - * texture is multiplied together. - * @see @ref flags() + * Convenience access to the @ref MaterialAttribute::SpecularColor + * attribute. If not present, the default is @cpp 0xffffffff_rgbaf @ce. + * + * If the material has @ref MaterialAttribute::SpecularTexture, the + * color and texture is meant to be multiplied together. + * @see @ref hasAttribute() */ - Color4 specularColor() const { return _specularColor; } + Color4 specularColor() const; /** * @brief Specular texture ID * - * Available only if the material has @ref Flag::SpecularTexture. - * Multiplied with @ref specularColor(). - * @see @ref flags(), @ref AbstractImporter::texture() + * Available only if @ref MaterialAttribute::SpecularTexture is + * present. Meant to be multiplied with @ref specularColor(). + * @see @ref hasAttribute(), @ref AbstractImporter::texture() */ UnsignedInt specularTexture() const; + /** + * @brief Specular texture coordinate transformation matrix + * @m_since_latest + * + * Convenience access to the @ref MaterialAttribute::SpecularTextureMatrix + * / @ref MaterialAttribute::TextureMatrix attributes. If neither is + * present, the default is an identity matrix. Available only if the + * material has @ref MaterialAttribute::SpecularTexture. + * @see @ref hasAttribute() + */ + Matrix3 specularTextureMatrix() const; + /** * @brief Specular texture coordinate set * @m_since_latest * - * Available only if the material has @ref Flag::SpecularTexture. - * @see @ref flags(), @ref AbstractImporter::texture() + * Convenience access to the @ref MaterialAttribute::SpecularTextureCoordinates + * / @ref MaterialAttribute::TextureCoordinates attributes. If neither + * is present, the default is @cpp 0 @ce. Available only if the + * material has @ref MaterialAttribute::SpecularTexture. + * @see @ref hasAttribute() */ UnsignedInt specularTextureCoordinates() const; @@ -330,17 +446,32 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { * @brief Normal texture ID * @m_since{2020,06} * - * Available only if the material has @ref Flag::NormalTexture. - * @see @ref flags(), @ref AbstractImporter::texture() + * Available only if @ref MaterialAttribute::NormalTexture is present. + * @see @ref hasAttribute(), @ref AbstractImporter::texture() */ UnsignedInt normalTexture() const; + /** + * @brief Normal texture coordinate transformation matrix + * @m_since_latest + * + * Convenience access to the @ref MaterialAttribute::NormalTextureMatrix + * / @ref MaterialAttribute::TextureMatrix attributes. If neither is + * present, the default is an identity matrix. Available only if the + * material has @ref MaterialAttribute::NormalTexture. + * @see @ref hasAttribute() + */ + Matrix3 normalTextureMatrix() const; + /** * @brief Normal texture coordinate set * @m_since_latest * - * Available only if the material has @ref Flag::NormalTexture. - * @see @ref flags(), @ref AbstractImporter::texture() + * Convenience access to the @ref MaterialAttribute::NormalTextureCoordinates + * / @ref MaterialAttribute::TextureCoordinates attributes. If neither + * is present, the default is @cpp 0 @ce. Available only if the + * material has @ref MaterialAttribute::NormalTexture. + * @see @ref hasAttribute() */ UnsignedInt normalTextureCoordinates() const; @@ -356,43 +487,78 @@ class MAGNUM_TRADE_EXPORT PhongMaterialData: public AbstractMaterialData { #endif /** - * @brief Texture coordinate transformation matrix + * @brief Common texture coordinate transformation matrix for all textures * @m_since{2020,06} * - * If the material doesn't have @ref Flag::TextureTransformation, - * returns an identity matrix. - * @see @ref flags() + * Convenience access to the @ref MaterialAttribute::TextureMatrix + * attribute. If not present, the default is an identity matrix. Note + * that the material may also define per-texture transformation using + * the @ref MaterialAttribute::AmbientTextureMatrix, + * @ref MaterialAttribute::DiffuseTextureMatrix, + * @ref MaterialAttribute::SpecularTextureMatrix and + * @ref MaterialAttribute::NormalTextureMatrix attributes, which then + * take precedence over the common one. + * @see @ref hasAttribute(), @ref ambientTextureMatrix(), + * @ref diffuseTextureMatrix(), @ref specularTextureMatrix(), + * @ref normalTextureMatrix() + */ + Matrix3 textureMatrix() const; + + /** + * @brief Common texture coordinate set index for all textures + * @m_since_latest + * + * Convenience access to the @ref MaterialAttribute::TextureCoordinates + * attribute. If not present, the default is @cpp 0 @ce. Note that the + * material may also define per-texture coordinate set using the + * @ref MaterialAttribute::AmbientTextureCoordinates, + * @ref MaterialAttribute::DiffuseTextureCoordinates, + * @ref MaterialAttribute::SpecularTextureCoordinates and + * @ref MaterialAttribute::NormalTextureCoordinates attributes, which + * then take precedence over the common one. + * @see @ref hasAttribute(), @ref ambientTextureCoordinates(), + * @ref diffuseTextureCoordinates(), + * @ref specularTextureCoordinates(), + * @ref normalTextureCoordinates() + */ + UnsignedInt textureCoordinates() const; + + /** + * @brief Shininess + * + * Convenience access to the @ref MaterialAttribute::Shininess + * attribute. If not present, the default is @cpp 80.0f @ce. */ - Matrix3 textureMatrix() const { return _textureMatrix; } - - /** @brief Shininess */ - Float shininess() const { return _shininess; } - - private: - /* Initializing texture IDs to insane values to make accidents worse - and thus better noticeable */ - Color4 _ambientColor; - UnsignedInt _ambientTexture{~UnsignedInt{}}; - UnsignedInt _ambientTextureCoordinates; - Color4 _diffuseColor; - UnsignedInt _diffuseTexture{~UnsignedInt{}}; - UnsignedInt _diffuseTextureCoordinates; - Color4 _specularColor; - UnsignedInt _specularTexture{~UnsignedInt{}}; - UnsignedInt _specularTextureCoordinates; - UnsignedInt _normalTexture{~UnsignedInt{}}; - UnsignedInt _normalTextureCoordinates; - Matrix3 _textureMatrix; - Float _shininess; + Float shininess() const; }; +#ifdef MAGNUM_BUILD_DEPRECATED +CORRADE_IGNORE_DEPRECATED_PUSH CORRADE_ENUMSET_OPERATORS(PhongMaterialData::Flags) -/** @debugoperatorclassenum{PhongMaterialData,PhongMaterialData::Flag} */ +/** +@debugoperatorclassenum{PhongMaterialData,PhongMaterialData::Flag} +@m_deprecated_since_latest The flags are no longer stored directly but + generated on-the-fly from attribute data, which makes them less efficient + than calling @ref MaterialData::hasAttribute(), + @ref MaterialData::isDoubleSided(), + @ref PhongMaterialData::hasTextureTransformation(), + @ref PhongMaterialData::hasTextureCoordinates() etc. +*/ MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, PhongMaterialData::Flag value); -/** @debugoperatorclassenum{PhongMaterialData,PhongMaterialData::Flags} */ +/** +@debugoperatorclassenum{PhongMaterialData,PhongMaterialData::Flags} +@m_deprecated_since_latest The flags are no longer stored directly but + generated on-the-fly from attribute data, which makes them less efficient + than calling @ref MaterialData::hasAttribute(), + @ref MaterialData::isDoubleSided(), + @ref PhongMaterialData::hasTextureTransformation(), + @ref PhongMaterialData::hasTextureCoordinates() etc. +*/ MAGNUM_TRADE_EXPORT Debug& operator<<(Debug& debug, PhongMaterialData::Flags value); +CORRADE_IGNORE_DEPRECATED_POP +#endif }} diff --git a/src/Magnum/Trade/Test/MaterialDataTest.cpp b/src/Magnum/Trade/Test/MaterialDataTest.cpp index 913dcc176..6ad01acc0 100644 --- a/src/Magnum/Trade/Test/MaterialDataTest.cpp +++ b/src/Magnum/Trade/Test/MaterialDataTest.cpp @@ -31,6 +31,7 @@ #include #include +#include "Magnum/Math/Color.h" #include "Magnum/Math/Matrix3.h" #include "Magnum/Trade/MaterialData.h" #include "Magnum/Trade/PhongMaterialData.h" @@ -73,6 +74,7 @@ class MaterialDataTest: public TestSuite::Tester { void constructCopy(); void constructMove(); + void access(); void accessOptional(); void accessOutOfBounds(); void accessInvalidAttributeName(); @@ -81,29 +83,38 @@ class MaterialDataTest: public TestSuite::Tester { void release(); - void constructPhong(); - void constructPhongTextured(); - void constructPhongTexturedTextureTransform(); - void constructPhongTexturedCoordinates(); - void constructPhongTextureTransformNoTextures(); - void constructPhongNoTextureTransformationFlag(); - void constructPhongNoTextureCoordinatesFlag(); - void constructPhongCopy(); - void constructPhongMove(); + #ifdef MAGNUM_BUILD_DEPRECATED + void constructPhongDeprecated(); + void constructPhongDeprecatedTextured(); + void constructPhongDeprecatedTexturedTextureTransform(); + void constructPhongDeprecatedTexturedCoordinates(); + void constructPhongDeprecatedTextureTransformNoTextures(); + void constructPhongDeprecatedNoTextureTransformationFlag(); + void constructPhongDeprecatedNoTextureCoordinatesFlag(); + #endif - void accessInvalidTextures(); + void phongAccess(); + void phongAccessDefaults(); + void phongAccessTextured(); + void phongAccessTexturedDefaults(); + void phongAccessTexturedSingleMatrixCoordinates(); + void phongAccessInvalidTextures(); void debugAttribute(); void debugAttributeType(); void debugType(); void debugTypes(); + #ifdef MAGNUM_BUILD_DEPRECATED void debugFlag(); void debugFlags(); + #endif void debugAlphaMode(); + #ifdef MAGNUM_BUILD_DEPRECATED void debugPhongFlag(); void debugPhongFlags(); + #endif }; MaterialDataTest::MaterialDataTest() { @@ -163,6 +174,7 @@ MaterialDataTest::MaterialDataTest() { &MaterialDataTest::constructCopy, &MaterialDataTest::constructMove, + &MaterialDataTest::access, &MaterialDataTest::accessOptional, &MaterialDataTest::accessOutOfBounds, &MaterialDataTest::accessInvalidAttributeName, @@ -171,29 +183,39 @@ MaterialDataTest::MaterialDataTest() { &MaterialDataTest::release, - &MaterialDataTest::constructPhong, - &MaterialDataTest::constructPhongTextured, - &MaterialDataTest::constructPhongTexturedTextureTransform, - &MaterialDataTest::constructPhongTexturedCoordinates, - &MaterialDataTest::constructPhongTextureTransformNoTextures, - &MaterialDataTest::constructPhongNoTextureTransformationFlag, - &MaterialDataTest::constructPhongNoTextureCoordinatesFlag, - &MaterialDataTest::constructPhongCopy, - &MaterialDataTest::constructPhongMove, - - &MaterialDataTest::accessInvalidTextures, + #ifdef MAGNUM_BUILD_DEPRECATED + &MaterialDataTest::constructPhongDeprecated, + &MaterialDataTest::constructPhongDeprecatedTextured, + &MaterialDataTest::constructPhongDeprecatedTexturedTextureTransform, + &MaterialDataTest::constructPhongDeprecatedTexturedCoordinates, + &MaterialDataTest::constructPhongDeprecatedTextureTransformNoTextures, + &MaterialDataTest::constructPhongDeprecatedNoTextureTransformationFlag, + &MaterialDataTest::constructPhongDeprecatedNoTextureCoordinatesFlag, + #endif + + &MaterialDataTest::phongAccess, + &MaterialDataTest::phongAccessDefaults, + &MaterialDataTest::phongAccessTextured, + &MaterialDataTest::phongAccessTexturedDefaults, + &MaterialDataTest::phongAccessTexturedSingleMatrixCoordinates, + &MaterialDataTest::phongAccessInvalidTextures, &MaterialDataTest::debugAttribute, &MaterialDataTest::debugAttributeType, &MaterialDataTest::debugType, &MaterialDataTest::debugTypes, + #ifdef MAGNUM_BUILD_DEPRECATED &MaterialDataTest::debugFlag, &MaterialDataTest::debugFlags, + #endif &MaterialDataTest::debugAlphaMode, + #ifdef MAGNUM_BUILD_DEPRECATED &MaterialDataTest::debugPhongFlag, - &MaterialDataTest::debugPhongFlags}); + &MaterialDataTest::debugPhongFlags + #endif + }); } using namespace Containers::Literals; @@ -674,6 +696,32 @@ void MaterialDataTest::constructMove() { CORRADE_VERIFY(std::is_nothrow_move_assignable::value); } +void MaterialDataTest::access() { + MaterialData a{{}, { + {MaterialAttribute::DoubleSided, false}, + {MaterialAttribute::AlphaBlend, true}, + {MaterialAttribute::AlphaMask, 0.9f} + }}; + CORRADE_VERIFY(!a.isDoubleSided()); + CORRADE_COMPARE(a.alphaMode(), MaterialAlphaMode::Blend); + CORRADE_COMPARE(a.alphaMask(), 0.9f); + + MaterialData b{{}, { + {MaterialAttribute::AlphaBlend, false}, + {MaterialAttribute::AlphaMask, 0.3f} + }}; + CORRADE_VERIFY(!b.isDoubleSided()); + CORRADE_COMPARE(b.alphaMode(), MaterialAlphaMode::Mask); + CORRADE_COMPARE(b.alphaMask(), 0.3f); + + MaterialData c{{}, { + {MaterialAttribute::DoubleSided, true}, + }}; + CORRADE_VERIFY(c.isDoubleSided()); + CORRADE_COMPARE(c.alphaMode(), MaterialAlphaMode::Opaque); + CORRADE_COMPARE(c.alphaMask(), 0.5f); +} + void MaterialDataTest::accessOptional() { MaterialData data{{}, { {MaterialAttribute::AlphaMask, 0.5f}, @@ -835,18 +883,22 @@ void MaterialDataTest::release() { CORRADE_COMPARE(data.attributeCount(), 0); } -void MaterialDataTest::constructPhong() { - using namespace Math::Literals; - +#ifdef MAGNUM_BUILD_DEPRECATED +void MaterialDataTest::constructPhongDeprecated() { const int a{}; - PhongMaterialData data{{}, + CORRADE_IGNORE_DEPRECATED_PUSH + PhongMaterialData data{PhongMaterialData::Flag::DoubleSided, 0xccffbb_rgbf, {}, 0xebefbf_rgbf, {}, 0xacabad_rgbf, {}, {}, {}, MaterialAlphaMode::Mask, 0.3f, 80.0f, &a}; + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(data.types(), MaterialType::Phong); + CORRADE_IGNORE_DEPRECATED_PUSH CORRADE_COMPARE(data.type(), MaterialType::Phong); - CORRADE_COMPARE(data.flags(), PhongMaterialData::Flags{}); + CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::DoubleSided); + CORRADE_IGNORE_DEPRECATED_POP CORRADE_COMPARE(data.ambientColor(), 0xccffbb_rgbf); CORRADE_COMPARE(data.diffuseColor(), 0xebefbf_rgbf); CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); @@ -857,19 +909,22 @@ void MaterialDataTest::constructPhong() { CORRADE_COMPARE(data.importerState(), &a); } -void MaterialDataTest::constructPhongTextured() { - using namespace Math::Literals; - +void MaterialDataTest::constructPhongDeprecatedTextured() { const int a{}; + CORRADE_IGNORE_DEPRECATED_PUSH PhongMaterialData data{ PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture, 0x111111_rgbf, 42, 0xeebbff_rgbf, {}, 0xacabad_rgbf, 17, {}, {}, MaterialAlphaMode::Blend, 0.37f, 96.0f, &a}; + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(data.types(), MaterialType::Phong); + CORRADE_IGNORE_DEPRECATED_PUSH CORRADE_COMPARE(data.type(), MaterialType::Phong); CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture); + CORRADE_IGNORE_DEPRECATED_POP CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf); CORRADE_COMPARE(data.ambientTexture(), 42); CORRADE_COMPARE(data.ambientTextureCoordinates(), 0); @@ -884,207 +939,290 @@ void MaterialDataTest::constructPhongTextured() { CORRADE_COMPARE(data.importerState(), &a); } -void MaterialDataTest::constructPhongTexturedTextureTransform() { - using namespace Math::Literals; - +void MaterialDataTest::constructPhongDeprecatedTexturedTextureTransform() { const int a{}; + CORRADE_IGNORE_DEPRECATED_PUSH PhongMaterialData data{ PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureTransformation, 0x111111_rgbf, {}, 0xeebbff_rgbf, 42, 0xacabad_rgbf, {}, 17, Matrix3::rotation(90.0_degf), - MaterialAlphaMode::Opaque, 0.5f, 96.0f, &a}; + MaterialAlphaMode::Mask, 0.5f, 96.0f, &a}; + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(data.types(), MaterialType::Phong); + CORRADE_IGNORE_DEPRECATED_PUSH CORRADE_COMPARE(data.type(), MaterialType::Phong); CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureTransformation); + CORRADE_IGNORE_DEPRECATED_POP CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf); CORRADE_COMPARE(data.diffuseColor(), 0xeebbff_rgbf); CORRADE_COMPARE(data.diffuseTexture(), 42); CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); CORRADE_COMPARE(data.normalTexture(), 17); CORRADE_COMPARE(data.textureMatrix(), Matrix3::rotation(90.0_degf)); - CORRADE_COMPARE(data.alphaMode(), MaterialAlphaMode::Opaque); + CORRADE_COMPARE(data.alphaMode(), MaterialAlphaMode::Mask); CORRADE_COMPARE(data.alphaMask(), 0.5f); CORRADE_COMPARE(data.shininess(), 96.0f); CORRADE_COMPARE(data.importerState(), &a); } -void MaterialDataTest::constructPhongTexturedCoordinates() { - using namespace Math::Literals; - +void MaterialDataTest::constructPhongDeprecatedTexturedCoordinates() { const int a{}; + CORRADE_IGNORE_DEPRECATED_PUSH PhongMaterialData data{ - PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture|PhongMaterialData::Flag::TextureCoordinates, + PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureCoordinates, 0x111111_rgbf, 42, 3, - 0xeebbff_rgbf, {}, 0, + 0xeebbff_rgbf, {}, 6, 0xacabad_rgbf, 17, 1, - {}, 0, {}, + 0, 8, {}, MaterialAlphaMode::Blend, 0.37f, 96.0f, &a}; + CORRADE_IGNORE_DEPRECATED_POP + CORRADE_COMPARE(data.types(), MaterialType::Phong); + CORRADE_IGNORE_DEPRECATED_PUSH CORRADE_COMPARE(data.type(), MaterialType::Phong); - CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::SpecularTexture|PhongMaterialData::Flag::TextureCoordinates); + CORRADE_COMPARE(data.flags(), PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureCoordinates); + CORRADE_IGNORE_DEPRECATED_POP CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf); CORRADE_COMPARE(data.ambientTexture(), 42); CORRADE_COMPARE(data.ambientTextureCoordinates(), 3); CORRADE_COMPARE(data.diffuseColor(), 0xeebbff_rgbf); + CORRADE_COMPARE(data.diffuseTextureCoordinates(), 6); CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); CORRADE_COMPARE(data.specularTexture(), 17); CORRADE_COMPARE(data.specularTextureCoordinates(), 1); + CORRADE_COMPARE(data.normalTexture(), 0); + CORRADE_COMPARE(data.normalTextureCoordinates(), 8); CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.ambientTextureCoordinates(), 3); CORRADE_COMPARE(data.alphaMode(), MaterialAlphaMode::Blend); CORRADE_COMPARE(data.alphaMask(), 0.37f); CORRADE_COMPARE(data.shininess(), 96.0f); CORRADE_COMPARE(data.importerState(), &a); } -void MaterialDataTest::constructPhongTextureTransformNoTextures() { +void MaterialDataTest::constructPhongDeprecatedTextureTransformNoTextures() { #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif std::ostringstream out; Error redirectError{&out}; + CORRADE_IGNORE_DEPRECATED_PUSH PhongMaterialData a{PhongMaterialData::Flag::TextureTransformation, {}, {}, {}, {}, {}, {}, {}, {}, {}, 0.5f, 80.0f}; + CORRADE_IGNORE_DEPRECATED_POP CORRADE_COMPARE(out.str(), "Trade::PhongMaterialData: texture transformation enabled but the material has no textures\n"); } -void MaterialDataTest::constructPhongNoTextureTransformationFlag() { +void MaterialDataTest::constructPhongDeprecatedNoTextureTransformationFlag() { #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif std::ostringstream out; Error redirectError{&out}; + CORRADE_IGNORE_DEPRECATED_PUSH PhongMaterialData a{{}, {}, {}, {}, {}, {}, {}, {}, Matrix3::rotation(90.0_degf), {}, 0.5f, 80.0f}; + CORRADE_IGNORE_DEPRECATED_POP CORRADE_COMPARE(out.str(), "PhongMaterialData::PhongMaterialData: non-default texture matrix requires Flag::TextureTransformation to be enabled\n"); } -void MaterialDataTest::constructPhongNoTextureCoordinatesFlag() { +void MaterialDataTest::constructPhongDeprecatedNoTextureCoordinatesFlag() { #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif std::ostringstream out; Error redirectError{&out}; + CORRADE_IGNORE_DEPRECATED_PUSH PhongMaterialData a{{}, {}, {}, 1, {}, {}, 2, {}, {}, 3, {}, 4, {}, {}, 0.5f, 80.0f}; + CORRADE_IGNORE_DEPRECATED_POP CORRADE_COMPARE(out.str(), "PhongMaterialData::PhongMaterialData: non-zero texture coordinate sets require Flag::TextureCoordinates to be enabled\n"); } +#endif + +void MaterialDataTest::phongAccess() { + MaterialData base{MaterialType::Phong, { + {MaterialAttribute::AmbientColor, 0xccffbbff_rgbaf}, + {MaterialAttribute::DiffuseColor, 0xebefbfff_rgbaf}, + {MaterialAttribute::SpecularColor, 0xacabadff_rgbaf}, + {MaterialAttribute::Shininess, 96.0f} + }}; + + CORRADE_COMPARE(base.types(), MaterialType::Phong); + const PhongMaterialData& data = static_cast(base); -void MaterialDataTest::constructPhongCopy() { - CORRADE_VERIFY(!(std::is_constructible{})); - CORRADE_VERIFY(!(std::is_constructible{})); - CORRADE_VERIFY(!(std::is_assignable{})); - CORRADE_VERIFY(!(std::is_assignable{})); + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.ambientColor(), 0xccffbb_rgbf); + CORRADE_COMPARE(data.diffuseColor(), 0xebefbf_rgbf); + CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); + CORRADE_COMPARE(data.shininess(), 96.0f); } -void MaterialDataTest::constructPhongMove() { - using namespace Math::Literals; +void MaterialDataTest::phongAccessDefaults() { + MaterialData base{{}, {}}; - const int a{}; - PhongMaterialData data{ - PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureTransformation|PhongMaterialData::Flag::TextureCoordinates, - 0x111111_rgbf, 1, 0, - 0xeebbff_rgbf, 42, 1, - 0xacabad_rgbf, 24, 2, 17, 3, - Matrix3::rotation(90.0_degf), - MaterialAlphaMode::Blend, 0.55f, 13.0f, &a}; - - PhongMaterialData b{std::move(data)}; - CORRADE_COMPARE(b.type(), MaterialType::Phong); - CORRADE_COMPARE(b.flags(), PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureTransformation|PhongMaterialData::Flag::TextureCoordinates); - CORRADE_COMPARE(b.ambientColor(), 0x111111_rgbf); - CORRADE_COMPARE(b.ambientTexture(), 1); - CORRADE_COMPARE(b.ambientTextureCoordinates(), 0); - CORRADE_COMPARE(b.diffuseColor(), 0xeebbff_rgbf); - CORRADE_COMPARE(b.diffuseTexture(), 42); - CORRADE_COMPARE(b.diffuseTextureCoordinates(), 1); - CORRADE_COMPARE(b.specularColor(), 0xacabad_rgbf); - CORRADE_COMPARE(b.specularTexture(), 24); - CORRADE_COMPARE(b.specularTextureCoordinates(), 2); - CORRADE_COMPARE(b.normalTexture(), 17); - CORRADE_COMPARE(b.normalTextureCoordinates(), 3); - CORRADE_COMPARE(b.textureMatrix(), Matrix3::rotation(90.0_degf)); - CORRADE_COMPARE(b.alphaMode(), MaterialAlphaMode::Blend); - CORRADE_COMPARE(b.alphaMask(), 0.55f); - CORRADE_COMPARE(b.shininess(), 13.0f); - CORRADE_COMPARE(b.importerState(), &a); - - const int c{}; - PhongMaterialData d{{}, - 0xccffbb_rgbf, {}, - 0xebefbf_rgbf, {}, - 0xacabad_rgbf, {}, {}, {}, - MaterialAlphaMode::Mask, 0.3f, 80.0f, &c}; - d = std::move(b); - - CORRADE_COMPARE(d.type(), MaterialType::Phong); - CORRADE_COMPARE(d.flags(), PhongMaterialData::Flag::AmbientTexture|PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture|PhongMaterialData::Flag::NormalTexture|PhongMaterialData::Flag::TextureTransformation|PhongMaterialData::Flag::TextureCoordinates); - CORRADE_COMPARE(d.ambientColor(), 0x111111_rgbf); - CORRADE_COMPARE(d.ambientTexture(), 1); - CORRADE_COMPARE(d.ambientTextureCoordinates(), 0); - CORRADE_COMPARE(d.diffuseColor(), 0xeebbff_rgbf); - CORRADE_COMPARE(d.diffuseTexture(), 42); - CORRADE_COMPARE(d.diffuseTextureCoordinates(), 1); - CORRADE_COMPARE(d.specularColor(), 0xacabad_rgbf); - CORRADE_COMPARE(d.specularTexture(), 24); - CORRADE_COMPARE(d.specularTextureCoordinates(), 2); - CORRADE_COMPARE(d.normalTexture(), 17); - CORRADE_COMPARE(d.normalTextureCoordinates(), 3); - CORRADE_COMPARE(d.textureMatrix(), Matrix3::rotation(90.0_degf)); - CORRADE_COMPARE(d.alphaMode(), MaterialAlphaMode::Blend); - CORRADE_COMPARE(d.alphaMask(), 0.55f); - CORRADE_COMPARE(d.shininess(), 13.0f); - CORRADE_COMPARE(d.importerState(), &a); - - CORRADE_VERIFY(std::is_nothrow_move_constructible::value); - CORRADE_VERIFY(std::is_nothrow_move_assignable::value); + CORRADE_COMPARE(base.types(), MaterialTypes{}); + /* Casting is fine even if the type doesn't include Phong */ + const PhongMaterialData& data = static_cast(base); + + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.ambientColor(), 0x000000_rgbf); + CORRADE_COMPARE(data.diffuseColor(), 0xffffff_rgbf); + CORRADE_COMPARE(data.specularColor(), 0xffffff_rgbf); + CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.textureCoordinates(), 0); + CORRADE_COMPARE(data.shininess(), 80.0f); +} + +void MaterialDataTest::phongAccessTextured() { + PhongMaterialData data{{}, { + {MaterialAttribute::AmbientColor, 0x111111ff_rgbaf}, + {MaterialAttribute::AmbientTexture, 42u}, + {MaterialAttribute::AmbientTextureMatrix, Matrix3::scaling({0.5f, 1.0f})}, + {MaterialAttribute::AmbientTextureCoordinates, 2u}, + {MaterialAttribute::DiffuseTexture, 33u}, + {MaterialAttribute::DiffuseColor, 0xeebbffff_rgbaf}, + {MaterialAttribute::DiffuseTextureMatrix, Matrix3::scaling({0.5f, 0.5f})}, + {MaterialAttribute::DiffuseTextureCoordinates, 3u}, + {MaterialAttribute::SpecularColor, 0xacabadff_rgbaf}, + {MaterialAttribute::SpecularTexture, 17u}, + {MaterialAttribute::SpecularTextureMatrix, Matrix3::scaling({1.0f, 1.0f})}, + {MaterialAttribute::SpecularTextureCoordinates, 4u}, + {MaterialAttribute::NormalTexture, 0u}, + {MaterialAttribute::NormalTextureMatrix, Matrix3::scaling({1.0f, 0.5f})}, + {MaterialAttribute::NormalTextureCoordinates, 5u} + }}; + + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.ambientColor(), 0x111111_rgbf); + CORRADE_COMPARE(data.ambientTexture(), 42); + CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3::scaling({0.5f, 1.0f})); + CORRADE_COMPARE(data.ambientTextureCoordinates(), 2); + CORRADE_COMPARE(data.diffuseColor(), 0xeebbff_rgbf); + CORRADE_COMPARE(data.diffuseTexture(), 33); + CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::scaling({0.5f, 0.5f})); + CORRADE_COMPARE(data.diffuseTextureCoordinates(), 3); + CORRADE_COMPARE(data.specularColor(), 0xacabad_rgbf); + CORRADE_COMPARE(data.specularTexture(), 17); + CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::scaling({1.0f, 1.0f})); + CORRADE_COMPARE(data.specularTextureCoordinates(), 4); + CORRADE_COMPARE(data.normalTexture(), 0); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::scaling({1.0f, 0.5f})); + CORRADE_COMPARE(data.normalTextureCoordinates(), 5); + + CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.textureCoordinates(), 0); +} + +void MaterialDataTest::phongAccessTexturedDefaults() { + PhongMaterialData data{{}, { + {MaterialAttribute::AmbientTexture, 42u}, + {MaterialAttribute::DiffuseTexture, 33u}, + {MaterialAttribute::SpecularTexture, 17u}, + {MaterialAttribute::NormalTexture, 1u} + }}; + + CORRADE_VERIFY(!data.hasTextureTransformation()); + CORRADE_VERIFY(!data.hasTextureCoordinates()); + CORRADE_COMPARE(data.ambientColor(), 0xffffffff_rgbaf); + CORRADE_COMPARE(data.ambientTexture(), 42); + CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.ambientTextureCoordinates(), 0); + CORRADE_COMPARE(data.diffuseColor(), 0xffffffff_rgbaf); + CORRADE_COMPARE(data.diffuseTexture(), 33); + CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.diffuseTextureCoordinates(), 0); + CORRADE_COMPARE(data.specularColor(), 0xffffffff_rgbaf); + CORRADE_COMPARE(data.specularTexture(), 17); + CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.specularTextureCoordinates(), 0); + CORRADE_COMPARE(data.normalTexture(), 1); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.normalTextureCoordinates(), 0); + + CORRADE_COMPARE(data.textureMatrix(), Matrix3{}); + CORRADE_COMPARE(data.textureCoordinates(), 0); } -void MaterialDataTest::accessInvalidTextures() { +void MaterialDataTest::phongAccessTexturedSingleMatrixCoordinates() { + PhongMaterialData data{{}, { + {MaterialAttribute::AmbientTexture, 42u}, + {MaterialAttribute::DiffuseTexture, 33u}, + {MaterialAttribute::SpecularTexture, 17u}, + {MaterialAttribute::NormalTexture, 0u}, + {MaterialAttribute::TextureMatrix, Matrix3::translation({0.5f, 1.0f})}, + {MaterialAttribute::TextureCoordinates, 2u} + }}; + + CORRADE_VERIFY(data.hasTextureTransformation()); + CORRADE_VERIFY(data.hasTextureCoordinates()); + CORRADE_COMPARE(data.ambientTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); + CORRADE_COMPARE(data.ambientTextureCoordinates(), 2); + CORRADE_COMPARE(data.diffuseTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); + CORRADE_COMPARE(data.diffuseTextureCoordinates(), 2); + CORRADE_COMPARE(data.specularTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); + CORRADE_COMPARE(data.specularTextureCoordinates(), 2); + CORRADE_COMPARE(data.normalTextureMatrix(), Matrix3::translation({0.5f, 1.0f})); + CORRADE_COMPARE(data.normalTextureCoordinates(), 2); + + CORRADE_COMPARE(data.textureMatrix(), Matrix3::translation({0.5f, 1.0f})); + CORRADE_COMPARE(data.textureCoordinates(), 2); +} + +void MaterialDataTest::phongAccessInvalidTextures() { #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif - PhongMaterialData a{{}, - {}, {}, - {}, {}, - {}, {}, {}, {}, - {}, 0.5f, 80.0f}; + PhongMaterialData data{{}, {}}; std::ostringstream out; Error redirectError{&out}; - a.ambientTexture(); - a.ambientTextureCoordinates(); - a.diffuseTexture(); - a.diffuseTextureCoordinates(); - a.specularTexture(); - a.specularTextureCoordinates(); - a.normalTexture(); - a.normalTextureCoordinates(); + data.ambientTexture(); + data.ambientTextureMatrix(); + data.ambientTextureCoordinates(); + data.diffuseTexture(); + data.diffuseTextureMatrix(); + data.diffuseTextureCoordinates(); + data.specularTexture(); + data.specularTextureMatrix(); + data.specularTextureCoordinates(); + data.normalTexture(); + data.normalTextureMatrix(); + data.normalTextureCoordinates(); CORRADE_COMPARE(out.str(), - "Trade::PhongMaterialData::ambientTexture(): the material doesn't have an ambient texture\n" + "Trade::MaterialData::attribute(): attribute AmbientTexture not found\n" + "Trade::PhongMaterialData::ambientTextureMatrix(): the material doesn't have an ambient texture\n" "Trade::PhongMaterialData::ambientTextureCoordinates(): the material doesn't have an ambient texture\n" - "Trade::PhongMaterialData::diffuseTexture(): the material doesn't have a diffuse texture\n" + "Trade::MaterialData::attribute(): attribute DiffuseTexture not found\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::PhongMaterialData::specularTexture(): the material doesn't have a specular texture\n" + "Trade::MaterialData::attribute(): attribute SpecularTexture not found\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" - "Trade::PhongMaterialData::normalTexture(): the material doesn't have a normal texture\n" + "Trade::MaterialData::attribute(): attribute NormalTexture not found\n" + "Trade::PhongMaterialData::normalTextureMatrix(): the material doesn't have a normal texture\n" "Trade::PhongMaterialData::normalTextureCoordinates(): the material doesn't have a normal texture\n"); } @@ -1116,19 +1254,23 @@ void MaterialDataTest::debugTypes() { CORRADE_COMPARE(out.str(), "Trade::MaterialType::Phong|Trade::MaterialType(0xe0) Trade::MaterialTypes{}\n"); } +#ifdef MAGNUM_BUILD_DEPRECATED +CORRADE_IGNORE_DEPRECATED_PUSH 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"); + Debug{&out} << MaterialData::Flag::DoubleSided << MaterialData::Flag(0xf0); + CORRADE_COMPARE(out.str(), "Trade::MaterialData::Flag::DoubleSided Trade::MaterialData::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"); + Debug{&out} << MaterialData::Flag::DoubleSided << MaterialData::Flags{}; + CORRADE_COMPARE(out.str(), "Trade::MaterialData::Flag::DoubleSided Trade::MaterialData::Flags{}\n"); } +CORRADE_IGNORE_DEPRECATED_POP +#endif void MaterialDataTest::debugAlphaMode() { std::ostringstream out; @@ -1137,6 +1279,8 @@ void MaterialDataTest::debugAlphaMode() { CORRADE_COMPARE(out.str(), "Trade::MaterialAlphaMode::Opaque Trade::MaterialAlphaMode(0xee)\n"); } +#ifdef MAGNUM_BUILD_DEPRECATED +CORRADE_IGNORE_DEPRECATED_PUSH void MaterialDataTest::debugPhongFlag() { std::ostringstream out; @@ -1150,6 +1294,8 @@ void MaterialDataTest::debugPhongFlags() { Debug{&out} << (PhongMaterialData::Flag::DiffuseTexture|PhongMaterialData::Flag::SpecularTexture) << PhongMaterialData::Flags{}; CORRADE_COMPARE(out.str(), "Trade::PhongMaterialData::Flag::DiffuseTexture|Trade::PhongMaterialData::Flag::SpecularTexture Trade::PhongMaterialData::Flags{}\n"); } +CORRADE_IGNORE_DEPRECATED_POP +#endif }}}} diff --git a/src/Magnum/Trade/Trade.h b/src/Magnum/Trade/Trade.h index 154dd4762..c3541a183 100644 --- a/src/Magnum/Trade/Trade.h +++ b/src/Magnum/Trade/Trade.h @@ -52,9 +52,11 @@ enum class MaterialAttribute: UnsignedInt; enum class MaterialAttributeType: UnsignedByte; enum class MaterialType: UnsignedInt; enum class MaterialAlphaMode: UnsignedByte; -class AbstractMaterialData; class MaterialAttributeData; class MaterialData; +#ifdef MAGNUM_BUILD_DEPRECATED +typedef CORRADE_DEPRECATED("use MaterialData instead") MaterialData AbstractMaterialData; +#endif enum class AnimationTrackTargetType: UnsignedByte; enum class AnimationTrackType: UnsignedByte;