diff --git a/doc/matrix-vector.dox b/doc/matrix-vector.dox index 7f6ca76f6..abf9ffb55 100644 --- a/doc/matrix-vector.dox +++ b/doc/matrix-vector.dox @@ -222,14 +222,14 @@ auto c = Vector3i{a}; // {2, 0, -5} auto d = Vector3d{a}; // {2.2, 0.25, -5.1} @endcode -For normalizing and denormalizing there are @ref Math::normalize() and -@ref Math::denormalize() functions: +For packing and unpacking there are @ref Math::pack() and @ref Math::unpack() +functions: @code Color3 a{0.8f, 1.0f, 0.3f}; -auto b = Math::denormalize(a); // {204, 255, 76} +auto b = Math::unpack(a); // {204, 255, 76} Color3ub c{64, 127, 89}; -auto d = Math::normalize(c); // {0.251, 0.498, 0.349} +auto d = Math::pack(c); // {0.251, 0.498, 0.349} @endcode See @ref matrix-vector-componentwise "below" for more information about other diff --git a/src/Magnum/Math/CMakeLists.txt b/src/Magnum/Math/CMakeLists.txt index baeaa4dfb..607815ffc 100644 --- a/src/Magnum/Math/CMakeLists.txt +++ b/src/Magnum/Math/CMakeLists.txt @@ -41,6 +41,7 @@ set(MagnumMath_HEADERS Matrix3.h Matrix4.h Quaternion.h + Packing.h Range.h RectangularMatrix.h Swizzle.h diff --git a/src/Magnum/Math/Color.h b/src/Magnum/Math/Color.h index 5408fae1f..0ddf0c2e5 100644 --- a/src/Magnum/Math/Color.h +++ b/src/Magnum/Math/Color.h @@ -31,8 +31,8 @@ #include -#include "Magnum/Math/Functions.h" #include "Magnum/Math/Matrix.h" +#include "Magnum/Math/Packing.h" #include "Magnum/Math/Vector4.h" namespace Magnum { namespace Math { @@ -67,7 +67,7 @@ template typename std::enable_if::value, Colo } } template inline typename std::enable_if::value, Color3>::type fromHsv(const typename Color3::Hsv& hsv) { - return denormalize>(fromHsv::FloatingPointType>(hsv)); + return pack>(fromHsv::FloatingPointType>(hsv)); } /* Internal hue computing function */ @@ -104,13 +104,13 @@ template inline T value(typename std::enable_if inline Deg::FloatingPointType> hue(typename std::enable_if::value, const Color3&>::type color) { - return hue::FloatingPointType>(normalize::FloatingPointType>>(color)); + return hue::FloatingPointType>(unpack::FloatingPointType>>(color)); } template inline typename Color3::FloatingPointType saturation(typename std::enable_if::value, const Color3&>::type& color) { - return saturation::FloatingPointType>(normalize::FloatingPointType>>(color)); + return saturation::FloatingPointType>(unpack::FloatingPointType>>(color)); } template inline typename Color3::FloatingPointType value(typename std::enable_if::value, const Color3&>::type color) { - return normalize::FloatingPointType>(color.max()); + return unpack::FloatingPointType>(color.max()); } /* Convert color to HSV */ @@ -121,7 +121,7 @@ template inline typename Color3::Hsv toHsv(typename std::enable_if::Hsv(hue::FloatingPointType>(color, max, delta), max != T(0) ? delta/max : T(0), max); } template inline typename Color3::Hsv toHsv(typename std::enable_if::value, const Color3&>::type color) { - return toHsv::FloatingPointType>(normalize::FloatingPointType>>(color)); + return toHsv::FloatingPointType>(unpack::FloatingPointType>>(color)); } /* sRGB -> RGB conversion */ @@ -133,18 +133,18 @@ template typename std::enable_if::value, Colo return {fromSrgb(srgbAlpha.rgb()), srgbAlpha.a()}; } template inline typename std::enable_if::value, Color3>::type fromSrgb(const Vector3::FloatingPointType>& srgb) { - return denormalize>(fromSrgb::FloatingPointType>(srgb)); + return pack>(fromSrgb::FloatingPointType>(srgb)); } template inline typename std::enable_if::value, Color4>::type fromSrgbAlpha(const Vector4::FloatingPointType>& srgbAlpha) { - return {fromSrgb(srgbAlpha.rgb()), denormalize(srgbAlpha.a())}; + return {fromSrgb(srgbAlpha.rgb()), pack(srgbAlpha.a())}; } template inline Color3 fromSrgbIntegral(const Vector3& srgb) { static_assert(std::is_integral::value, "only conversion from different integral type is supported"); - return fromSrgb(normalize::FloatingPointType>>(srgb)); + return fromSrgb(unpack::FloatingPointType>>(srgb)); } template inline Color4 fromSrgbAlphaIntegral(const Vector4& srgbAlpha) { static_assert(std::is_integral::value, "only conversion from different integral type is supported"); - return fromSrgbAlpha(normalize::FloatingPointType>>(srgbAlpha)); + return fromSrgbAlpha(unpack::FloatingPointType>>(srgbAlpha)); } /* RGB -> sRGB conversion */ @@ -156,18 +156,18 @@ template Vector4::FloatingPointType> toSrgbAlpha(typ return {toSrgb(rgba.rgb()), rgba.a()}; } template inline Vector3::FloatingPointType> toSrgb(typename std::enable_if::value, const Color3&>::type rgb) { - return toSrgb::FloatingPointType>(normalize::FloatingPointType>>(rgb)); + return toSrgb::FloatingPointType>(unpack::FloatingPointType>>(rgb)); } template inline Vector4::FloatingPointType> toSrgbAlpha(typename std::enable_if::value, const Color4&>::type rgba) { - return {toSrgb(rgba.rgb()), normalize::FloatingPointType>(rgba.a())}; + return {toSrgb(rgba.rgb()), unpack::FloatingPointType>(rgba.a())}; } template inline Vector3 toSrgbIntegral(const Color3& rgb) { static_assert(std::is_integral::value, "only conversion from different integral type is supported"); - return denormalize>(toSrgb(rgb)); + return pack>(toSrgb(rgb)); } template inline Vector4 toSrgbAlphaIntegral(const Color4& rgba) { static_assert(std::is_integral::value, "only conversion from different integral type is supported"); - return denormalize>(toSrgbAlpha(rgba)); + return pack>(toSrgbAlpha(rgba)); } /* CIE XYZ -> RGB conversion */ @@ -180,7 +180,7 @@ template typename std::enable_if::value, Colo Vector3{T(-1974)/T(3959), T(36519)/T(878810), T(705)/T(667)}}*xyz; } template inline typename std::enable_if::value, Color3>::type fromXyz(const Vector3::FloatingPointType>& xyz) { - return denormalize>(fromXyz::FloatingPointType>(xyz)); + return pack>(fromXyz::FloatingPointType>(xyz)); } /* RGB -> CIE XYZ conversion */ @@ -193,7 +193,7 @@ template Vector3::FloatingPointType> toXyz(typename Vector3{T(12673)/T(70218), T(12673)/T(175545), T(1001167)/T(1053270)}})*rgb; } template inline Vector3::FloatingPointType> toXyz(typename std::enable_if::value, const Color3&>::type rgb) { - return toXyz::FloatingPointType>(normalize::FloatingPointType>>(rgb)); + return toXyz::FloatingPointType>(unpack::FloatingPointType>>(rgb)); } /* Value for full channel (1.0f for floats, 255 for unsigned byte) */ @@ -216,11 +216,11 @@ linear RGB using @ref fromSrgb(), calculation done on the linear representation and then converted back to sRGB using @ref toSrgb(). Note that constructor conversion between different types (like in @ref Vector -classes) doesn't do any (de)normalization, you should use @ref normalize() and -@ref denormalize() instead, for example: +classes) doesn't do any (de)normalization, you should use @ref pack) and +@ref unpack() instead, for example: @code Color3 a(1.0f, 0.5f, 0.75f); -auto b = denormalize(a); // b == {255, 127, 191} +auto b = pack(a); // b == {255, 127, 191} @endcode Conversion from and to HSV is done always using floating-point types, so hue @@ -451,9 +451,9 @@ template class Color3: public Vector3 { /** * @copydoc Vector::Vector(const Vector&) * - * @attention This function doesn't do any (de)normalization, use - * @ref normalize() and @ref denormalize() instead. - * See class documentation for more information. + * @attention This function doesn't do any (un)packing, use @ref pack() + * and @ref unpack() instead. See class documentation for more + * information. */ template constexpr explicit Color3(const Vector<3, U>& other) noexcept: Vector3(other) {} @@ -846,9 +846,9 @@ class Color4: public Vector4 { /** * @copydoc Vector::Vector(const Vector&) * - * @attention This function doesn't do any (de)normalization, use - * @ref normalize() and @ref denormalize() instead. - * See @ref Color3 class documentation for more information. + * @attention This function doesn't do any (un)packing, use @ref pack) + * and @ref unpack() instead. See @ref Color3 class documentation + * for more information. */ template constexpr explicit Color4(const Vector<4, U>& other) noexcept: Vector4(other) {} @@ -1064,7 +1064,7 @@ Color3 a = 0x33b27f_rgbf; // {0.2f, 0.698039f, 0.498039f} @see @link operator""_rgbaf() @endlink, @link operator""_rgb() @endlink */ inline Color3 operator "" _rgbf(unsigned long long value) { - return Math::normalize>(Color3{UnsignedByte(value >> 16), UnsignedByte(value >> 8), UnsignedByte(value)}); + return Math::unpack>(Color3{UnsignedByte(value >> 16), UnsignedByte(value >> 8), UnsignedByte(value)}); } /** @relatesalso Magnum::Math::Color3 @@ -1099,7 +1099,7 @@ Color4 a = 0x33b27fcc_rgbaf; // {0.2f, 0.698039f, 0.498039f, 0.8f} @see @link operator""_rgbf() @endlink, @link operator""_rgba() @endlink */ inline Color4 operator "" _rgbaf(unsigned long long value) { - return Math::normalize>(Color4{UnsignedByte(value >> 24), UnsignedByte(value >> 16), UnsignedByte(value >> 8), UnsignedByte(value)}); + return Math::unpack>(Color4{UnsignedByte(value >> 24), UnsignedByte(value >> 16), UnsignedByte(value >> 8), UnsignedByte(value)}); } /** @relatesalso Magnum::Math::Color4 diff --git a/src/Magnum/Math/Functions.h b/src/Magnum/Math/Functions.h index eb62de90d..6ac6b093f 100644 --- a/src/Magnum/Math/Functions.h +++ b/src/Magnum/Math/Functions.h @@ -30,7 +30,6 @@ */ #include -#include #include #include @@ -535,89 +534,15 @@ template inline Vector fma(const Vector('\xFF'); - -// b = 1.0f -Float b = Math::normalize('\xFF'); -@endcode - -@see @ref denormalize() -*/ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline FloatingPoint normalize(const Integral& value); -#else -template inline typename std::enable_if::value && std::is_unsigned::value, FloatingPoint>::type normalize(Integral value) { - static_assert(std::is_floating_point::value && std::is_integral::value, - "Math::normalize(): normalization must be done from integral to floating-point type"); - return value/FloatingPoint(std::numeric_limits::max()); -} -template inline typename std::enable_if::value && std::is_signed::value, FloatingPoint>::type normalize(Integral value) { - static_assert(std::is_floating_point::value && std::is_integral::value, - "Math::normalize(): normalization must be done from integral to floating-point type"); - return Math::max(value/FloatingPoint(std::numeric_limits::max()), FloatingPoint(-1)); -} -template inline typename std::enable_if::value, FloatingPoint>::type normalize(const Integral& value) { - static_assert(std::is_floating_point::value && std::is_integral::value, - "Math::normalize(): normalization must be done from integral to floating-point type"); - return FloatingPoint(value)/typename FloatingPoint::Type(std::numeric_limits::max()); -} -template inline typename std::enable_if::value, FloatingPoint>::type normalize(const Integral& value) { - static_assert(std::is_floating_point::value && std::is_integral::value, - "Math::normalize(): normalization must be done from integral to floating-point type"); - return Math::max(FloatingPoint(value)/typename FloatingPoint::Type(std::numeric_limits::max()), FloatingPoint(-1)); -} -#endif - -/** -@brief Denormalize floating-point value - -Converts floating-point value in range @f$ [0, 1] @f$ to full range of given -*unsigned* integral type or range @f$ [-1, 1] @f$ to full range of given *signed* -integral type. - -@note For best precision, `FloatingPoint` type should be always larger that - resulting `Integral` type (e.g. @ref Magnum::Float "Float" to - @ref Magnum::Short "Short", @ref Magnum::Double "Double" to @ref Magnum::Int "Int" - and similarly for vector types). - -@attention Return value for floating point numbers outside the normalized - range is undefined. - -@see @ref normalize() -*/ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline Integral denormalize(const FloatingPoint& value); -#else -template inline typename std::enable_if::value, Integral>::type denormalize(FloatingPoint value) { - static_assert(std::is_floating_point::value && std::is_integral::value, - "Math::denormalize(): denormalization must be done from floating-point to integral type"); - return Integral(value*std::numeric_limits::max()); -} -template inline typename std::enable_if::value, Integral>::type denormalize(const FloatingPoint& value) { - static_assert(std::is_floating_point::value && std::is_integral::value, - "Math::denormalize(): denormalization must be done from floating-point to integral type"); - return Integral(value*std::numeric_limits::max()); -} -#endif - /*@}*/ }} +#ifdef MAGNUM_BUILD_DEPRECATED +/* In order to make the deprecated normalize() / denormalize() functions + available in the original header. The Packing.h header depends on this file + so it needs to be included after it. */ +#include "Magnum/Math/Packing.h" +#endif + #endif diff --git a/src/Magnum/Math/Packing.h b/src/Magnum/Math/Packing.h new file mode 100644 index 000000000..9c16e1aa3 --- /dev/null +++ b/src/Magnum/Math/Packing.h @@ -0,0 +1,135 @@ +#ifndef Magnum_Math_Packing_h +#define Magnum_Math_Packing_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 + 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 + +#include "Magnum/Math/Functions.h" + +namespace Magnum { namespace Math { + +/** +@brief Unpack integral value into a floating-point representation + +Converts integral value from full range of given *unsigned* integral type to +value in range @f$ [0, 1] @f$ or from *signed* integral to range @f$ [-1, 1] @f$. + +@note For best precision, resulting `FloatingPoint` type should be always + larger that `Integral` type (e.g. @ref Magnum::Float "Float" from + @ref Magnum::Short "Short", @ref Magnum::Double "Double" from + @ref Magnum::Int "Int" and similarly for vector types). + +@attention To ensure the integral type is correctly detected when using + literals, this function should be called with both template parameters + explicit, e.g.: +@code +// Literal type is (signed) char, but we assumed unsigned char, a != 1.0f +Float a = Math::unpack('\xFF'); + +// b = 1.0f +Float b = Math::unpack('\xFF'); +@endcode + +@see @ref pack() +*/ +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline FloatingPoint unpack(const Integral& value); +#else +template inline typename std::enable_if::value && std::is_unsigned::value, FloatingPoint>::type unpack(Integral value) { + static_assert(std::is_floating_point::value && std::is_integral::value, + "unpacking must be done from integral to floating-point type"); + return value/FloatingPoint(std::numeric_limits::max()); +} +template inline typename std::enable_if::value && std::is_signed::value, FloatingPoint>::type unpack(Integral value) { + static_assert(std::is_floating_point::value && std::is_integral::value, + "unpacking must be done from integral to floating-point type"); + return Math::max(value/FloatingPoint(std::numeric_limits::max()), FloatingPoint(-1.0)); +} +template inline typename std::enable_if::value, FloatingPoint>::type unpack(const Integral& value) { + static_assert(std::is_floating_point::value && std::is_integral::value, + "unpacking must be done from integral to floating-point type"); + return FloatingPoint(value)/typename FloatingPoint::Type(std::numeric_limits::max()); +} +template inline typename std::enable_if::value, FloatingPoint>::type unpack(const Integral& value) { + static_assert(std::is_floating_point::value && std::is_integral::value, + "unpacking must be done from integral to floating-point type"); + return Math::max(FloatingPoint(value)/typename FloatingPoint::Type(std::numeric_limits::max()), FloatingPoint(-1.0)); +} +#endif + +#ifdef MAGNUM_BUILD_DEPRECATED +/** @copybrief unpack() + * @deprecated Use @ref unpack() instead. + */ +template CORRADE_DEPRECATED("use unpack() instead") inline FloatingPoint normalize(const Integral& value) { + return unpack(value); +} +#endif + +/** +@brief Pack floating-point value into an integer representation + +Converts floating-point value in range @f$ [0, 1] @f$ to full range of given +*unsigned* integral type or range @f$ [-1, 1] @f$ to full range of given *signed* +integral type. + +@note For best precision, `FloatingPoint` type should be always larger that + resulting `Integral` type (e.g. @ref Magnum::Float "Float" to + @ref Magnum::Short "Short", @ref Magnum::Double "Double" to @ref Magnum::Int "Int" + and similarly for vector types). + +@attention Return value for floating point numbers outside the normalized + range is undefined. + +@see @ref unpack() +*/ +#ifdef DOXYGEN_GENERATING_OUTPUT +template inline Integral pack(const FloatingPoint& value); +#else +template inline typename std::enable_if::value, Integral>::type pack(FloatingPoint value) { + static_assert(std::is_floating_point::value && std::is_integral::value, + "packing must be done from floating-point to integral type"); + return Integral(value*std::numeric_limits::max()); +} +template inline typename std::enable_if::value, Integral>::type pack(const FloatingPoint& value) { + static_assert(std::is_floating_point::value && std::is_integral::value, + "packing must be done from floating-point to integral type"); + return Integral(value*std::numeric_limits::max()); +} +#endif + +#ifdef MAGNUM_BUILD_DEPRECATED +/** @copybrief pack() + * @deprecated Use @ref pack() instead. + */ +template CORRADE_DEPRECATED("use pack() instead") inline Integral denormalize(const FloatingPoint& value) { + return pack(value); +} +#endif + +}} + +#endif diff --git a/src/Magnum/Math/Test/CMakeLists.txt b/src/Magnum/Math/Test/CMakeLists.txt index 7a89fe901..887c8165c 100644 --- a/src/Magnum/Math/Test/CMakeLists.txt +++ b/src/Magnum/Math/Test/CMakeLists.txt @@ -26,6 +26,7 @@ corrade_add_test(MathBoolVectorTest BoolVectorTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathConstantsTest ConstantsTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathFunctionsTest FunctionsTest.cpp LIBRARIES MagnumMathTestLib) +corrade_add_test(MathPackingTest PackingTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathTagsTest TagsTest.cpp LIBRARIES MagnumMathTestLib) corrade_add_test(MathTypeTraitsTest TypeTraitsTest.cpp LIBRARIES MagnumMathTestLib) diff --git a/src/Magnum/Math/Test/ColorTest.cpp b/src/Magnum/Math/Test/ColorTest.cpp index d29fde1df..df41c73f1 100644 --- a/src/Magnum/Math/Test/ColorTest.cpp +++ b/src/Magnum/Math/Test/ColorTest.cpp @@ -75,7 +75,7 @@ struct ColorTest: Corrade::TestSuite::Tester { void constructOneValue(); void constructParts(); void constructConversion(); - void constructNormalization(); + void constructPacking(); void constructCopy(); void convert(); @@ -121,7 +121,7 @@ ColorTest::ColorTest() { &ColorTest::constructOneValue, &ColorTest::constructParts, &ColorTest::constructConversion, - &ColorTest::constructNormalization, + &ColorTest::constructPacking, &ColorTest::constructCopy, &ColorTest::convert, @@ -264,13 +264,13 @@ void ColorTest::constructConversion() { CORRADE_VERIFY((std::is_nothrow_constructible::value)); } -void ColorTest::constructNormalization() { +void ColorTest::constructPacking() { constexpr Color3 a(1.0f, 0.5f, 0.75f); - auto b = Math::denormalize(a); + auto b = Math::pack(a); CORRADE_COMPARE(b, Color3ub(255, 127, 191)); constexpr Color4 c(1.0f, 0.5f, 0.75f, 0.25f); - auto d = Math::denormalize(c); + auto d = Math::pack(c); CORRADE_COMPARE(d, Color4ub(255, 127, 191, 63)); } diff --git a/src/Magnum/Math/Test/FunctionsTest.cpp b/src/Magnum/Math/Test/FunctionsTest.cpp index 2dd2c7eff..77ed5b89f 100644 --- a/src/Magnum/Math/Test/FunctionsTest.cpp +++ b/src/Magnum/Math/Test/FunctionsTest.cpp @@ -58,14 +58,6 @@ struct FunctionsTest: Corrade::TestSuite::Tester { void lerpBool(); void lerpInverted(); void fma(); - void normalizeUnsigned(); - void normalizeSigned(); - void denormalizeUnsigned(); - void denormalizeSigned(); - void renormalizeUnsinged(); - void renormalizeSinged(); - - void normalizeTypeDeduction(); void logIntegral(); void log2(); @@ -110,14 +102,6 @@ FunctionsTest::FunctionsTest() { &FunctionsTest::lerpBool, &FunctionsTest::lerpInverted, &FunctionsTest::fma, - &FunctionsTest::normalizeUnsigned, - &FunctionsTest::normalizeSigned, - &FunctionsTest::denormalizeUnsigned, - &FunctionsTest::denormalizeSigned, - &FunctionsTest::renormalizeUnsinged, - &FunctionsTest::renormalizeSinged, - - &FunctionsTest::normalizeTypeDeduction, &FunctionsTest::logIntegral, &FunctionsTest::log2, @@ -292,170 +276,6 @@ void FunctionsTest::fma() { Vector3(6.75f, 3.25f, -0.4f)); } -void FunctionsTest::normalizeUnsigned() { - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(255)), 1.0f); - - CORRADE_COMPARE((Math::normalize(0)), 0.0); - CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0); - - #ifndef MAGNUM_TARGET_WEBGL - CORRADE_COMPARE((Math::normalize(0)), 0.0); - CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0); - #endif - - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0f); - - CORRADE_COMPARE((Math::normalize(8192)), 0.125002f); - CORRADE_COMPARE((Math::normalize(49152)), 0.750011f); - - CORRADE_COMPARE(Math::normalize(Vector3ub(0, 127, 255)), Vector3(0.0f, 0.498039f, 1.0f)); -} - -void FunctionsTest::normalizeSigned() { - CORRADE_COMPARE((Math::normalize(127)), 1.0f); - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(-128)), -1.0f); - - CORRADE_COMPARE((Math::normalize(std::numeric_limits::min())), -1.0f); - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0f); - - CORRADE_COMPARE((Math::normalize(std::numeric_limits::min())), -1.0); - CORRADE_COMPARE((Math::normalize(0)), 0.0); - CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0); - - #ifndef MAGNUM_TARGET_WEBGL - CORRADE_COMPARE((Math::normalize(std::numeric_limits::min())), -1.0); - CORRADE_COMPARE((Math::normalize(0)), 0.0); - CORRADE_COMPARE((Math::normalize(std::numeric_limits::max())), 1.0); - #endif - - CORRADE_COMPARE((Math::normalize(16384)), 0.500015f); - CORRADE_COMPARE((Math::normalize(-16384)), -0.500015f); - - CORRADE_COMPARE(Math::normalize(Vector3b(0, -127, 64)), Vector3(0.0f, -1.0f, 0.503937f)); -} - -void FunctionsTest::denormalizeUnsigned() { - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(1.0f), 255); - - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(1.0f), std::numeric_limits::max()); - - CORRADE_COMPARE(Math::denormalize(0.0), 0); - CORRADE_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); - - #ifndef MAGNUM_TARGET_WEBGL - CORRADE_COMPARE(Math::denormalize(0.0l), 0); - { - #ifdef CORRADE_MSVC2015_COMPATIBILITY - CORRADE_EXPECT_FAIL("Long double (de)normalization is broken on MSVC <= 2015."); - #endif - CORRADE_COMPARE(Math::denormalize(1.0l), std::numeric_limits::max()); - } - #endif - - CORRADE_COMPARE(Math::denormalize(0.33f), 21626); - CORRADE_COMPARE(Math::denormalize(0.66f), 43253); - - CORRADE_COMPARE(Math::denormalize(Vector3(0.0f, 0.5f, 1.0f)), Vector3ub(0, 127, 255)); -} - -void FunctionsTest::denormalizeSigned() { - CORRADE_COMPARE(Math::denormalize(-1.0f), -127); - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(1.0f), 127); - - CORRADE_COMPARE(Math::denormalize(-1.0f), std::numeric_limits::min()+1); - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(1.0f), std::numeric_limits::max()); - - #ifndef MAGNUM_TARGET_GLES - CORRADE_COMPARE(Math::denormalize(-1.0), std::numeric_limits::min()+1); - CORRADE_COMPARE(Math::denormalize(0.0), 0); - CORRADE_COMPARE(Math::denormalize(1.0), std::numeric_limits::max()); - - { - #ifdef CORRADE_MSVC2015_COMPATIBILITY - CORRADE_EXPECT_FAIL("Long double (de)normalization is broken on MSVC <= 2015."); - #endif - CORRADE_COMPARE(Math::denormalize(-1.0l), std::numeric_limits::min()+1); - } - CORRADE_COMPARE(Math::denormalize(0.0l), 0); - { - #ifdef CORRADE_MSVC2015_COMPATIBILITY - CORRADE_EXPECT_FAIL("Long double (de)normalization is broken on MSVC <= 2015."); - #endif - CORRADE_COMPARE(Math::denormalize(1.0l), std::numeric_limits::max()); - } - #endif - - CORRADE_COMPARE(Math::denormalize(-0.33f), -10813); - CORRADE_COMPARE(Math::denormalize(0.66f), 21626); - - CORRADE_COMPARE(Math::denormalize(Vector3(0.0f, -1.0f, 0.5f)), Vector3b(0, -127, 63)); -} - -void FunctionsTest::renormalizeUnsinged() { - CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); - CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); - - CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); - CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); - - CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0)), 0.0); - CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0)), 1.0); - - #ifndef MAGNUM_TARGET_WEBGL - CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0l)), 0.0l); - { - #ifdef CORRADE_MSVC2015_COMPATIBILITY - CORRADE_EXPECT_FAIL("Long double (de)normalization is broken on MSVC <= 2015."); - #endif - CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0l)), 1.0l); - } - #endif -} - -void FunctionsTest::renormalizeSinged() { - CORRADE_COMPARE(Math::normalize(Math::denormalize(-1.0f)), -1.0f); - CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); - CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); - - CORRADE_COMPARE(Math::normalize(Math::denormalize(-1.0f)), -1.0f); - CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0f)), 0.0f); - CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0f)), 1.0f); - - CORRADE_COMPARE(Math::normalize(Math::denormalize(-1.0)), -1.0); - CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0)), 0.0); - CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0)), 1.0); - - #ifndef MAGNUM_TARGET_WEBGL - CORRADE_COMPARE(Math::normalize(Math::denormalize(-1.0l)), -1.0l); - CORRADE_COMPARE(Math::normalize(Math::denormalize(0.0l)), 0.0l); - { - #ifdef CORRADE_MSVC2015_COMPATIBILITY - CORRADE_EXPECT_FAIL("Long double (de)normalization is broken on MSVC <= 2015."); - #endif - CORRADE_COMPARE(Math::normalize(Math::denormalize(1.0l)), 1.0l); - } - #endif -} - -void FunctionsTest::normalizeTypeDeduction() { - if(std::is_signed::value) - CORRADE_COMPARE(Math::normalize('\x7F'), 1.0f); - else { - /* Raspberry Pi `char` is unsigned (huh) */ - CORRADE_VERIFY(std::is_unsigned::value); - CORRADE_COMPARE(Math::normalize('\x7F'), 0.498039f); - } - CORRADE_COMPARE((Math::normalize('\x7F')), 1.0f); -} - void FunctionsTest::logIntegral() { CORRADE_COMPARE(Math::log(2, 256), 8ul); CORRADE_COMPARE(Math::log(256, 2), 0ul); diff --git a/src/Magnum/Math/Test/PackingTest.cpp b/src/Magnum/Math/Test/PackingTest.cpp new file mode 100644 index 000000000..59b9dd51e --- /dev/null +++ b/src/Magnum/Math/Test/PackingTest.cpp @@ -0,0 +1,226 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 + 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 + +#include "Magnum/Math/Packing.h" +#include "Magnum/Math/Vector3.h" + +namespace Magnum { namespace Math { namespace Test { + +struct PackingTest: Corrade::TestSuite::Tester { + explicit PackingTest(); + + void unpackUnsigned(); + void unpackSigned(); + void packUnsigned(); + void packSigned(); + void reunpackUnsinged(); + void reunpackSinged(); + void unpackTypeDeduction(); +}; + +typedef Math::Vector3 Vector3; +typedef Math::Vector3 Vector3ub; +typedef Math::Vector3 Vector3b; + +PackingTest::PackingTest() { + addTests({&PackingTest::unpackUnsigned, + &PackingTest::unpackSigned, + &PackingTest::packUnsigned, + &PackingTest::packSigned, + &PackingTest::reunpackUnsinged, + &PackingTest::reunpackSinged, + &PackingTest::unpackTypeDeduction}); +} + +void PackingTest::unpackUnsigned() { + CORRADE_COMPARE((Math::unpack(0)), 0.0f); + CORRADE_COMPARE((Math::unpack(255)), 1.0f); + + CORRADE_COMPARE((Math::unpack(0)), 0.0); + CORRADE_COMPARE((Math::unpack(std::numeric_limits::max())), 1.0); + + #ifndef MAGNUM_TARGET_WEBGL + CORRADE_COMPARE((Math::unpack(0)), 0.0); + CORRADE_COMPARE((Math::unpack(std::numeric_limits::max())), 1.0); + #endif + + CORRADE_COMPARE((Math::unpack(0)), 0.0f); + CORRADE_COMPARE((Math::unpack(std::numeric_limits::max())), 1.0f); + + CORRADE_COMPARE((Math::unpack(8192)), 0.125002f); + CORRADE_COMPARE((Math::unpack(49152)), 0.750011f); + + CORRADE_COMPARE(Math::unpack(Vector3ub(0, 127, 255)), Vector3(0.0f, 0.498039f, 1.0f)); +} + +void PackingTest::unpackSigned() { + CORRADE_COMPARE((Math::unpack(127)), 1.0f); + CORRADE_COMPARE((Math::unpack(0)), 0.0f); + CORRADE_COMPARE((Math::unpack(-128)), -1.0f); + + CORRADE_COMPARE((Math::unpack(std::numeric_limits::min())), -1.0f); + CORRADE_COMPARE((Math::unpack(0)), 0.0f); + CORRADE_COMPARE((Math::unpack(std::numeric_limits::max())), 1.0f); + + CORRADE_COMPARE((Math::unpack(std::numeric_limits::min())), -1.0); + CORRADE_COMPARE((Math::unpack(0)), 0.0); + CORRADE_COMPARE((Math::unpack(std::numeric_limits::max())), 1.0); + + #ifndef MAGNUM_TARGET_WEBGL + CORRADE_COMPARE((Math::unpack(std::numeric_limits::min())), -1.0); + CORRADE_COMPARE((Math::unpack(0)), 0.0); + CORRADE_COMPARE((Math::unpack(std::numeric_limits::max())), 1.0); + #endif + + CORRADE_COMPARE((Math::unpack(16384)), 0.500015f); + CORRADE_COMPARE((Math::unpack(-16384)), -0.500015f); + + CORRADE_COMPARE(Math::unpack(Vector3b(0, -127, 64)), Vector3(0.0f, -1.0f, 0.503937f)); +} + +void PackingTest::packUnsigned() { + CORRADE_COMPARE(Math::pack(0.0f), 0); + CORRADE_COMPARE(Math::pack(1.0f), 255); + + CORRADE_COMPARE(Math::pack(0.0f), 0); + CORRADE_COMPARE(Math::pack(1.0f), std::numeric_limits::max()); + + CORRADE_COMPARE(Math::pack(0.0), 0); + CORRADE_COMPARE(Math::pack(1.0), std::numeric_limits::max()); + + #ifndef MAGNUM_TARGET_WEBGL + CORRADE_COMPARE(Math::pack(0.0l), 0); + { + #ifdef CORRADE_MSVC2015_COMPATIBILITY + CORRADE_EXPECT_FAIL("Long double (de)normalization is broken on MSVC <= 2015."); + #endif + CORRADE_COMPARE(Math::pack(1.0l), std::numeric_limits::max()); + } + #endif + + CORRADE_COMPARE(Math::pack(0.33f), 21626); + CORRADE_COMPARE(Math::pack(0.66f), 43253); + + CORRADE_COMPARE(Math::pack(Vector3(0.0f, 0.5f, 1.0f)), Vector3ub(0, 127, 255)); +} + +void PackingTest::packSigned() { + CORRADE_COMPARE(Math::pack(-1.0f), -127); + CORRADE_COMPARE(Math::pack(0.0f), 0); + CORRADE_COMPARE(Math::pack(1.0f), 127); + + CORRADE_COMPARE(Math::pack(-1.0f), std::numeric_limits::min()+1); + CORRADE_COMPARE(Math::pack(0.0f), 0); + CORRADE_COMPARE(Math::pack(1.0f), std::numeric_limits::max()); + + #ifndef MAGNUM_TARGET_GLES + CORRADE_COMPARE(Math::pack(-1.0), std::numeric_limits::min()+1); + CORRADE_COMPARE(Math::pack(0.0), 0); + CORRADE_COMPARE(Math::pack(1.0), std::numeric_limits::max()); + + { + #ifdef CORRADE_MSVC2015_COMPATIBILITY + CORRADE_EXPECT_FAIL("Long double (de)normalization is broken on MSVC <= 2015."); + #endif + CORRADE_COMPARE(Math::pack(-1.0l), std::numeric_limits::min()+1); + } + CORRADE_COMPARE(Math::pack(0.0l), 0); + { + #ifdef CORRADE_MSVC2015_COMPATIBILITY + CORRADE_EXPECT_FAIL("Long double (de)normalization is broken on MSVC <= 2015."); + #endif + CORRADE_COMPARE(Math::pack(1.0l), std::numeric_limits::max()); + } + #endif + + CORRADE_COMPARE(Math::pack(-0.33f), -10813); + CORRADE_COMPARE(Math::pack(0.66f), 21626); + + CORRADE_COMPARE(Math::pack(Vector3(0.0f, -1.0f, 0.5f)), Vector3b(0, -127, 63)); +} + +void PackingTest::reunpackUnsinged() { + CORRADE_COMPARE(Math::unpack(Math::pack(0.0f)), 0.0f); + CORRADE_COMPARE(Math::unpack(Math::pack(1.0f)), 1.0f); + + CORRADE_COMPARE(Math::unpack(Math::pack(0.0f)), 0.0f); + CORRADE_COMPARE(Math::unpack(Math::pack(1.0f)), 1.0f); + + CORRADE_COMPARE(Math::unpack(Math::pack(0.0)), 0.0); + CORRADE_COMPARE(Math::unpack(Math::pack(1.0)), 1.0); + + #ifndef MAGNUM_TARGET_WEBGL + CORRADE_COMPARE(Math::unpack(Math::pack(0.0l)), 0.0l); + { + #ifdef CORRADE_MSVC2015_COMPATIBILITY + CORRADE_EXPECT_FAIL("Long double (de)normalization is broken on MSVC <= 2015."); + #endif + CORRADE_COMPARE(Math::unpack(Math::pack(1.0l)), 1.0l); + } + #endif +} + +void PackingTest::reunpackSinged() { + CORRADE_COMPARE(Math::unpack(Math::pack(-1.0f)), -1.0f); + CORRADE_COMPARE(Math::unpack(Math::pack(0.0f)), 0.0f); + CORRADE_COMPARE(Math::unpack(Math::pack(1.0f)), 1.0f); + + CORRADE_COMPARE(Math::unpack(Math::pack(-1.0f)), -1.0f); + CORRADE_COMPARE(Math::unpack(Math::pack(0.0f)), 0.0f); + CORRADE_COMPARE(Math::unpack(Math::pack(1.0f)), 1.0f); + + CORRADE_COMPARE(Math::unpack(Math::pack(-1.0)), -1.0); + CORRADE_COMPARE(Math::unpack(Math::pack(0.0)), 0.0); + CORRADE_COMPARE(Math::unpack(Math::pack(1.0)), 1.0); + + #ifndef MAGNUM_TARGET_WEBGL + CORRADE_COMPARE(Math::unpack(Math::pack(-1.0l)), -1.0l); + CORRADE_COMPARE(Math::unpack(Math::pack(0.0l)), 0.0l); + { + #ifdef CORRADE_MSVC2015_COMPATIBILITY + CORRADE_EXPECT_FAIL("Long double (de)normalization is broken on MSVC <= 2015."); + #endif + CORRADE_COMPARE(Math::unpack(Math::pack(1.0l)), 1.0l); + } + #endif +} + +void PackingTest::unpackTypeDeduction() { + if(std::is_signed::value) + CORRADE_COMPARE(Math::unpack('\x7F'), 1.0f); + else { + /* Raspberry Pi `char` is unsigned (huh) */ + CORRADE_VERIFY(std::is_unsigned::value); + CORRADE_COMPARE(Math::unpack('\x7F'), 0.498039f); + } + CORRADE_COMPARE((Math::unpack('\x7F')), 1.0f); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Math::Test::PackingTest) + diff --git a/src/Magnum/Test/FramebufferGLTest.cpp b/src/Magnum/Test/FramebufferGLTest.cpp index 9c9c8a655..230875c8d 100644 --- a/src/Magnum/Test/FramebufferGLTest.cpp +++ b/src/Magnum/Test/FramebufferGLTest.cpp @@ -1119,8 +1119,8 @@ void FramebufferGLTest::read() { CORRADE_COMPARE(framebuffer.checkStatus(FramebufferTarget::Read), Framebuffer::Status::Complete); CORRADE_COMPARE(framebuffer.checkStatus(FramebufferTarget::Draw), Framebuffer::Status::Complete); - Renderer::setClearColor(Math::normalize(Color4ub(128, 64, 32, 17))); - Renderer::setClearDepth(Math::normalize(48352)); + Renderer::setClearColor(Math::unpack(Color4ub(128, 64, 32, 17))); + Renderer::setClearDepth(Math::unpack(48352)); Renderer::setClearStencil(67); framebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth|FramebufferClear::Stencil); @@ -1198,8 +1198,8 @@ void FramebufferGLTest::readBuffer() { CORRADE_COMPARE(framebuffer.checkStatus(FramebufferTarget::Read), Framebuffer::Status::Complete); CORRADE_COMPARE(framebuffer.checkStatus(FramebufferTarget::Draw), Framebuffer::Status::Complete); - Renderer::setClearColor(Math::normalize(Color4ub(128, 64, 32, 17))); - Renderer::setClearDepth(Math::normalize(48352)); + Renderer::setClearColor(Math::unpack(Color4ub(128, 64, 32, 17))); + Renderer::setClearDepth(Math::unpack(48352)); Renderer::setClearStencil(67); framebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth|FramebufferClear::Stencil); @@ -1742,7 +1742,7 @@ void FramebufferGLTest::blit() { CORRADE_COMPARE(b.checkStatus(FramebufferTarget::Draw), Framebuffer::Status::Complete); /* Clear first with some color and second with another */ - Renderer::setClearColor(Math::normalize(Color4ub(128, 64, 32, 17))); + Renderer::setClearColor(Math::unpack(Color4ub(128, 64, 32, 17))); a.clear(FramebufferClear::Color); Renderer::setClearColor({}); b.clear(FramebufferClear::Color); diff --git a/src/Magnum/Test/MeshGLTest.cpp b/src/Magnum/Test/MeshGLTest.cpp index e798a7423..7504a6204 100644 --- a/src/Magnum/Test/MeshGLTest.cpp +++ b/src/Magnum/Test/MeshGLTest.cpp @@ -590,7 +590,7 @@ void MeshGLTest::addVertexBufferInt() { void MeshGLTest::addVertexBufferFloat() { typedef Attribute<0, Float> Attribute; - const Float data[] = { 0.0f, -0.7f, Math::normalize(96) }; + const Float data[] = { 0.0f, -0.7f, Math::unpack(96) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -619,7 +619,7 @@ void MeshGLTest::addVertexBufferDouble() { typedef Attribute<0, Double> Attribute; - const Double data[] = { 0.0, -0.7, Math::normalize(45828) }; + const Double data[] = { 0.0, -0.7, Math::unpack(45828) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -692,7 +692,7 @@ void MeshGLTest::addVertexBufferVectorNi() { void MeshGLTest::addVertexBufferVectorN() { typedef Attribute<0, Vector3> Attribute; - const Vector3 data[] = { {}, {0.0f, -0.9f, 1.0f}, Math::normalize(Color3ub(96, 24, 156)) }; + const Vector3 data[] = { {}, {0.0f, -0.9f, 1.0f}, Math::unpack(Color3ub(96, 24, 156)) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -723,7 +723,7 @@ void MeshGLTest::addVertexBufferVectorNd() { const Vector4d data[] = { {}, {0.0, -0.9, 1.0, 1.25}, - Math::normalize(Math::Vector4(315, 65201, 2576, 12)) + Math::unpack(Math::Vector4(315, 65201, 2576, 12)) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -748,7 +748,7 @@ void MeshGLTest::addVertexBufferMatrixNxN() { const Matrix3x3 data[] = { {}, Matrix3x3::fromDiagonal({0.0f, -0.9f, 1.0f}), - Matrix3x3::fromDiagonal(Math::normalize(Color3ub(96, 24, 156))) + Matrix3x3::fromDiagonal(Math::unpack(Color3ub(96, 24, 156))) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -777,7 +777,7 @@ void MeshGLTest::addVertexBufferMatrixNxNd() { const Matrix3x3d data[] = { {}, Matrix3x3d::fromDiagonal({0.0, -0.9, 1.0}), - Matrix3x3d::fromDiagonal(Math::normalize(Math::Vector3(315, 65201, 2576))) + Matrix3x3d::fromDiagonal(Math::unpack(Math::Vector3(315, 65201, 2576))) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -813,7 +813,7 @@ void MeshGLTest::addVertexBufferMatrixMxN() { const Matrix3x4 data[] = { {}, Matrix3x4::fromDiagonal({0.0f, -0.9f, 1.0f}), - Matrix3x4::fromDiagonal(Math::normalize(Color3ub(96, 24, 156))) + Matrix3x4::fromDiagonal(Math::unpack(Color3ub(96, 24, 156))) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -843,7 +843,7 @@ void MeshGLTest::addVertexBufferMatrixMxNd() { const Matrix3x4d data[] = { {}, Matrix3x4d::fromDiagonal({0.0f, -0.9f, 1.0f}), - Matrix3x4d::fromDiagonal(Math::normalize(Math::Vector3(315, 65201, 2576))) + Matrix3x4d::fromDiagonal(Math::unpack(Math::Vector3(315, 65201, 2576))) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -1000,7 +1000,7 @@ void MeshGLTest::addVertexBufferFloatWithHalfFloat() { void MeshGLTest::addVertexBufferFloatWithDouble() { typedef Attribute<0, Float> Attribute; - const Double data[] = { 0.0, -0.7, Math::normalize(186) }; + const Double data[] = { 0.0, -0.7, Math::unpack(186) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -1082,7 +1082,7 @@ void MeshGLTest::addVertexBufferLessVectorComponents() { const Vector3 data[] = { {}, {0.0f, -0.9f, 1.0f}, - Math::normalize(Color3ub(96, 24, 156)) + Math::unpack(Color3ub(96, 24, 156)) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -1241,14 +1241,14 @@ void MeshGLTest::addVertexBufferMultiple() { 1.0f, -0.5f, /* Second attribute */ - Math::normalize(64), - Math::normalize(17), - Math::normalize(56), - Math::normalize(15), - Math::normalize(164), - Math::normalize(17), - Math::normalize(97), - Math::normalize(28) + Math::unpack(64), + Math::unpack(17), + Math::unpack(56), + Math::unpack(15), + Math::unpack(164), + Math::unpack(17), + Math::unpack(97), + Math::unpack(28) }; Buffer buffer; @@ -1283,14 +1283,14 @@ void MeshGLTest::addVertexBufferMultipleGaps() { 1.0f, -0.5f, 0.0f, 0.0f, /* Second attribute */ - Math::normalize(64), - Math::normalize(17), - Math::normalize(56), 0.0f, - Math::normalize(15), - Math::normalize(164), - Math::normalize(17), 0.0f, - Math::normalize(97), - Math::normalize(28), 0.0f, 0.0f + Math::unpack(64), + Math::unpack(17), + Math::unpack(56), 0.0f, + Math::unpack(15), + Math::unpack(164), + Math::unpack(17), 0.0f, + Math::unpack(97), + Math::unpack(28), 0.0f, 0.0f }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -1321,14 +1321,14 @@ namespace { 0.0f, /* Offset */ /* First vertex */ - Math::normalize(64), - Math::normalize(17), - Math::normalize(56), - Math::normalize(15), - Math::normalize(164), - Math::normalize(17), - Math::normalize(97), - Math::normalize(28), + Math::unpack(64), + Math::unpack(17), + Math::unpack(56), + Math::unpack(15), + Math::unpack(164), + Math::unpack(17), + Math::unpack(97), + Math::unpack(28), /* Second vertex */ 0.3f, 0.1f, 0.5f, @@ -1351,14 +1351,14 @@ namespace { 0.0f, 0.0f, /* Third vertex */ - Math::normalize(64), - Math::normalize(17), - Math::normalize(56), - Math::normalize(15), - Math::normalize(164), - Math::normalize(17), - Math::normalize(97), - Math::normalize(28), + Math::unpack(64), + Math::unpack(17), + Math::unpack(56), + Math::unpack(15), + Math::unpack(164), + Math::unpack(17), + Math::unpack(97), + Math::unpack(28), /* Fourth vertex */ 0.3f, 0.1f, 0.5f, @@ -1502,7 +1502,7 @@ void MeshGLTest::setInstanceCount() { typedef Attribute<0, Float> Attribute; - const Float data[] = { 0.0f, -0.7f, Math::normalize(96) }; + const Float data[] = { 0.0f, -0.7f, Math::unpack(96) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -1582,7 +1582,7 @@ void MeshGLTest::setInstanceCountBaseInstance() { typedef Attribute<0, Float> Attribute; - const Float data[] = { 0.0f, -0.7f, Math::normalize(96) }; + const Float data[] = { 0.0f, -0.7f, Math::unpack(96) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -1732,7 +1732,7 @@ void MeshGLTest::addVertexBufferInstancedFloat() { /* Base vertex is ignored for instanced arrays */ -0.7f, /* First instance */ 0.3f, /* Second instance */ - Math::normalize(96) /* Third instance */ + Math::unpack(96) /* Third instance */ }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -1808,7 +1808,7 @@ void MeshGLTest::addVertexBufferInstancedDouble() { /* Base vertex is ignored for instanced arrays */ -0.7, /* First instance */ 0.3, /* Second instance */ - Math::normalize(45828) /* Third instance */ + Math::unpack(45828) /* Third instance */ }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw); @@ -1885,7 +1885,7 @@ void MeshGLTest::multiDraw() { typedef Attribute<0, Float> Attribute; - const Float data[] = { 0.0f, -0.7f, Math::normalize(96) }; + const Float data[] = { 0.0f, -0.7f, Math::unpack(96) }; Buffer buffer; buffer.setData(data, BufferUsage::StaticDraw);