diff --git a/src/Magnum/Math/Color.h b/src/Magnum/Math/Color.h index c76181646..9b8d2c180 100644 --- a/src/Magnum/Math/Color.h +++ b/src/Magnum/Math/Color.h @@ -37,6 +37,11 @@ #include /** @todo remove when Color[34]::Hsv is removed */ #endif +#if defined(CORRADE_MSVC2017_COMPATIBILITY) && !defined(CORRADE_MSVC2015_COMPATIBILITY) +/* Needed by the fullChannel() workaround */ +#include "Magnum/Math/Half.h" +#endif + namespace Magnum { namespace Math { namespace Implementation { @@ -203,15 +208,18 @@ template inline Vector3::FloatingPointType> toXyz(ty projects using CMake. Not using SFINAE in this case makes it work. Minimal repro case here: https://twitter.com/czmosra/status/1039446378248896513 */ template constexpr typename std::enable_if::value, T>::type fullChannel() { - return T(1); + return T(1.0); } template constexpr typename std::enable_if::value, T>::type fullChannel() { return Implementation::bitMax(); } #else template constexpr T fullChannel() { return bitMax(); } -/** @todo half */ template<> constexpr float fullChannel() { return 1.0f; } +template<> constexpr Half fullChannel() { + /* This is 1.0_h, but expressible in a constexpr context */ + return Half{UnsignedShort{0x3c00}}; +} template<> constexpr double fullChannel() { return 1.0; } template<> constexpr long double fullChannel() { return 1.0l; } #endif diff --git a/src/Magnum/Math/Test/ColorTest.cpp b/src/Magnum/Math/Test/ColorTest.cpp index 09a96ed1f..5cef591e6 100644 --- a/src/Magnum/Math/Test/ColorTest.cpp +++ b/src/Magnum/Math/Test/ColorTest.cpp @@ -33,6 +33,7 @@ #endif #include "Magnum/Math/Color.h" +#include "Magnum/Math/Half.h" #include "Magnum/Math/StrictWeakOrdering.h" struct Vec3 { @@ -75,6 +76,7 @@ struct ColorTest: Corrade::TestSuite::Tester { explicit ColorTest(); void construct(); + void constructDefaultAlphaHalf(); void constructDefault(); void constructNoInit(); void constructOneValue(); @@ -152,7 +154,9 @@ typedef Math::Color3 Color3; typedef Math::Color3 Color3ub; typedef Math::Vector4 Vector4; +typedef Math::Vector4 Vector4h; typedef Math::Color4 Color4; +typedef Math::Color4 Color4h; typedef Math::Color4 Color4ub; typedef Math::ColorHsv ColorHsv; @@ -197,6 +201,7 @@ constexpr struct { ColorTest::ColorTest() { addTests({&ColorTest::construct, + &ColorTest::constructDefaultAlphaHalf, &ColorTest::constructDefault, &ColorTest::constructNoInit, &ColorTest::constructOneValue, @@ -292,6 +297,12 @@ void ColorTest::construct() { CORRADE_VERIFY((std::is_nothrow_constructible::value)); } +void ColorTest::constructDefaultAlphaHalf() { + /* The default for alpha should work also for the Half type */ + Color4h a{1.0_h, 0.5_h, 0.75_h}; + CORRADE_COMPARE(a, Vector4h(1.0_h, 0.5_h, 0.75_h, 1.0_h)); +} + void ColorTest::constructDefault() { constexpr Color3 a1; constexpr Color3 a2{ZeroInit};