From 86be6440e319afe4ad4b9c6f6dca1c8c2af74fcf Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 14 Oct 2011 13:15:11 +0100 Subject: [PATCH] Vectorize and reformat --- glm/gtx/bit.inl | 1264 +++++++++++++--------------- glm/gtx/closest_point.inl | 37 +- glm/gtx/color_cast.inl | 1447 ++++++++++++++++----------------- glm/gtx/color_space.inl | 247 +++--- glm/gtx/color_space_YCoCg.inl | 101 ++- glm/gtx/compatibility.inl | 229 +++--- glm/gtx/component_wise.inl | 67 +- glm/gtx/constants.inl | 771 +----------------- glm/gtx/epsilon.inl | 407 +++++----- glm/gtx/euler_angles.inl | 425 +++++----- glm/gtx/extend.inl | 83 +- glm/gtx/fast_exponential.hpp | 16 +- glm/gtx/fast_exponential.inl | 380 +++------ 13 files changed, 2195 insertions(+), 3279 deletions(-) diff --git a/glm/gtx/bit.inl b/glm/gtx/bit.inl index c136d501..7f15dea7 100644 --- a/glm/gtx/bit.inl +++ b/glm/gtx/bit.inl @@ -8,766 +8,596 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// #include "../core/_detail.hpp" +#include "../core/_vectorize.hpp" -namespace glm{ - -template -GLM_FUNC_QUALIFIER genIType mask -( - genIType const & count -) +namespace glm { - return ((genIType(1) << (count)) - genIType(1)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 mask -( - detail::tvec2 const & count -) -{ - return detail::tvec2( - mask(count[0]), - mask(count[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 mask -( - detail::tvec3 const & count -) -{ - return detail::tvec3( - mask(count[0]), - mask(count[1]), - mask(count[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 mask -( - detail::tvec4 const & count -) -{ - return detail::tvec4( - mask(count[0]), - mask(count[1]), - mask(count[2]), - mask(count[3])); -} - -// extractField -template -GLM_FUNC_QUALIFIER genIType extractField -( - half const & value, - genIType const & first, - genIType const & count -) -{ - assert(first + count < sizeof(half)); - return (value._data() << first) >> ((sizeof(half) << 3) - count); -} - -template -GLM_FUNC_QUALIFIER genIType extractField -( - float const & value, - genIType const & first, - genIType const & count -) -{ - assert(first + count < sizeof(float)); - return (detail::uif32(value).i << first) >> ((sizeof(float) << 3) - count); -} - -template -GLM_FUNC_QUALIFIER genIType extractField -( - double const & value, - genIType const & first, - genIType const & count -) -{ - assert(first + count < sizeof(double)); - return (detail::uif64(value).i << first) >> ((sizeof(double) << genIType(3)) - count); -} - -template -GLM_FUNC_QUALIFIER genIUType extractField -( - genIUType const & Value, - sizeType const & First, - sizeType const & Count -) -{ - sizeType GenSize = sizeof(genIUType) << 3; - - assert(First + Count <= GenSize); - - genIUType ShiftLeft = Count ? Value << (GenSize - (Count + First)) : 0; - genIUType ShiftBack = ShiftLeft >> genIUType(GenSize - Count); - - return ShiftBack; -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 extractField -( - detail::tvec2 const & value, - sizeType const & first, - sizeType const & count -) -{ - return detail::tvec2( - extractField(value[0], first, count), - extractField(value[1], first, count)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 extractField -( - detail::tvec3 const & value, - sizeType const & first, - sizeType const & count -) -{ - return detail::tvec3( - extractField(value[0], first, count), - extractField(value[1], first, count), - extractField(value[2], first, count)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 extractField -( - detail::tvec4 const & value, - sizeType const & first, - sizeType const & count -) -{ - return detail::tvec4( - extractField(value[0], first, count), - extractField(value[1], first, count), - extractField(value[2], first, count), - extractField(value[3], first, count)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 extractField -( - detail::tvec2 const & value, - detail::tvec2 const & first, - detail::tvec2 const & count -) -{ - return detail::tvec2( - extractField(value[0], first[0], count[0]), - extractField(value[1], first[1], count[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 extractField -( - detail::tvec3 const & value, - detail::tvec3 const & first, - detail::tvec3 const & count -) -{ - return detail::tvec3( - extractField(value[0], first[0], count[0]), - extractField(value[1], first[1], count[1]), - extractField(value[2], first[2], count[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 extractField -( - detail::tvec4 const & value, - detail::tvec4 const & first, - detail::tvec4 const & count -) -{ - return detail::tvec4( - extractField(value[0], first[0], count[0]), - extractField(value[1], first[1], count[1]), - extractField(value[2], first[2], count[2]), - extractField(value[3], first[3], count[3])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 extractField -( - genIUType const & value, - detail::tvec2 const & first, - detail::tvec2 const & count -) -{ - return detail::tvec2( - extractField(value, first[0], count[0]), - extractField(value, first[1], count[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 extractField -( - genIUType const & value, - detail::tvec3 const & first, - detail::tvec3 const & count -) -{ - return detail::tvec3( - extractField(value, first[0], count[0]), - extractField(value, first[1], count[1]), - extractField(value, first[2], count[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 extractField -( - genIUType const & value, - detail::tvec4 const & first, - detail::tvec4 const & count -) -{ - return detail::tvec4( - extractField(value, first[0], count[0]), - extractField(value, first[1], count[1]), - extractField(value, first[2], count[2]), - extractField(value, first[3], count[3])); -} - -// lowestBit -template -GLM_FUNC_QUALIFIER int lowestBit -( - genType const & Value -) -{ - assert(Value != genType(0)); // not valid call - - genType Bit; - for(Bit = genType(0); !(Value & (1 << Bit)); ++Bit){} - return Bit; -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 lowestBit -( - detail::tvec2 const & value -) -{ - return detail::tvec2( - lowestBit(value[0]), - lowestBit(value[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 lowestBit -( - detail::tvec3 const & value -) -{ - return detail::tvec3( - lowestBit(value[0]), - lowestBit(value[1]), - lowestBit(value[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 lowestBit -( - detail::tvec4 const & value -) -{ - return detail::tvec4( - lowestBit(value[0]), - lowestBit(value[1]), - lowestBit(value[2]), - lowestBit(value[3])); -} - -// highestBit -template -GLM_FUNC_QUALIFIER int highestBit -( - genType const & value -) -{ - assert(value != genType(0)); // not valid call - - genType bit = genType(-1); - for(genType tmp = value; tmp; tmp >>= 1, ++bit){} - return bit; -} - -//template <> -//GLM_FUNC_QUALIFIER int highestBit -//( -// int value -//) -//{ -// int bit = -1; -// for(int tmp = value; tmp; tmp >>= 1, ++bit); -// return bit; -//} - -template -GLM_FUNC_QUALIFIER detail::tvec2 highestBit -( - detail::tvec2 const & value -) -{ - return detail::tvec2( - highestBit(value[0]), - highestBit(value[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 highestBit -( - detail::tvec3 const & value -) -{ - return detail::tvec3( - highestBit(value[0]), - highestBit(value[1]), - highestBit(value[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 highestBit -( - detail::tvec4 const & value -) -{ - return detail::tvec4( - highestBit(value[0]), - highestBit(value[1]), - highestBit(value[2]), - highestBit(value[3])); -} - -// highestBitValue -template -GLM_FUNC_QUALIFIER genType highestBitValue -( - genType const & value -) -{ - genType tmp = value; - genType result = genType(0); - while(tmp) + template + GLM_FUNC_QUALIFIER genIType mask + ( + genIType const & count + ) { - result = (tmp & (~tmp + 1)); // grab lowest bit - tmp &= ~result; // clear lowest bit + return ((genIType(1) << (count)) - genIType(1)); } - return result; -} -template -GLM_FUNC_QUALIFIER detail::tvec2 highestBitValue -( - detail::tvec2 const & value -) -{ - return detail::tvec2( - highestBitValue(value[0]), - highestBitValue(value[1])); -} + VECTORIZE_VEC(mask) -template -GLM_FUNC_QUALIFIER detail::tvec3 highestBitValue -( - detail::tvec3 const & value -) -{ - return detail::tvec3( - highestBitValue(value[0]), - highestBitValue(value[1]), - highestBitValue(value[2])); -} + // extractField + template + GLM_FUNC_QUALIFIER genIType extractField + ( + half const & value, + genIType const & first, + genIType const & count + ) + { + assert(first + count < sizeof(half)); + return (value._data() << first) >> ((sizeof(half) << 3) - count); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 highestBitValue -( - detail::tvec4 const & value -) -{ - return detail::tvec4( - highestBitValue(value[0]), - highestBitValue(value[1]), - highestBitValue(value[2]), - highestBitValue(value[3])); -} + template + GLM_FUNC_QUALIFIER genIType extractField + ( + float const & value, + genIType const & first, + genIType const & count + ) + { + assert(first + count < sizeof(float)); + return (detail::uif32(value).i << first) >> ((sizeof(float) << 3) - count); + } -// isPowerOfTwo -template -GLM_FUNC_QUALIFIER bool isPowerOfTwo(genType const & Value) -{ - //detail::If::is_signed>::apply(abs, Value); - //return !(Value & (Value - 1)); + template + GLM_FUNC_QUALIFIER genIType extractField + ( + double const & value, + genIType const & first, + genIType const & count + ) + { + assert(first + count < sizeof(double)); + return (detail::uif64(value).i << first) >> ((sizeof(double) << genIType(3)) - count); + } - // For old complier? - genType Result = Value; - if(std::numeric_limits::is_signed) - Result = abs(Result); - return !(Result & (Result - 1)); -} + template + GLM_FUNC_QUALIFIER genIUType extractField + ( + genIUType const & Value, + sizeType const & First, + sizeType const & Count + ) + { + sizeType GenSize = sizeof(genIUType) << 3; -template -GLM_FUNC_QUALIFIER detail::tvec2 isPowerOfTwo -( - detail::tvec2 const & value -) -{ - return detail::tvec2( - isPowerOfTwo(value[0]), - isPowerOfTwo(value[1])); -} + assert(First + Count <= GenSize); -template -GLM_FUNC_QUALIFIER detail::tvec3 isPowerOfTwo -( - detail::tvec3 const & value -) -{ - return detail::tvec3( - isPowerOfTwo(value[0]), - isPowerOfTwo(value[1]), - isPowerOfTwo(value[2])); -} + genIUType ShiftLeft = Count ? Value << (GenSize - (Count + First)) : 0; + genIUType ShiftBack = ShiftLeft >> genIUType(GenSize - Count); -template -GLM_FUNC_QUALIFIER detail::tvec4 isPowerOfTwo -( - detail::tvec4 const & value -) -{ - return detail::tvec4( - isPowerOfTwo(value[0]), - isPowerOfTwo(value[1]), - isPowerOfTwo(value[2]), - isPowerOfTwo(value[3])); -} + return ShiftBack; + } -// powerOfTwoAbove -template -GLM_FUNC_QUALIFIER genType powerOfTwoAbove(genType const & value) -{ - return isPowerOfTwo(value) ? value : highestBitValue(value) << 1; -} + template + GLM_FUNC_QUALIFIER detail::tvec2 extractField + ( + detail::tvec2 const & value, + sizeType const & first, + sizeType const & count + ) + { + return detail::tvec2( + extractField(value[0], first, count), + extractField(value[1], first, count)); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 powerOfTwoAbove -( - detail::tvec2 const & value -) -{ - return detail::tvec2( - powerOfTwoAbove(value[0]), - powerOfTwoAbove(value[1])); -} + template + GLM_FUNC_QUALIFIER detail::tvec3 extractField + ( + detail::tvec3 const & value, + sizeType const & first, + sizeType const & count + ) + { + return detail::tvec3( + extractField(value[0], first, count), + extractField(value[1], first, count), + extractField(value[2], first, count)); + } -template -GLM_FUNC_QUALIFIER detail::tvec3 powerOfTwoAbove -( - detail::tvec3 const & value -) -{ - return detail::tvec3( - powerOfTwoAbove(value[0]), - powerOfTwoAbove(value[1]), - powerOfTwoAbove(value[2])); -} + template + GLM_FUNC_QUALIFIER detail::tvec4 extractField + ( + detail::tvec4 const & value, + sizeType const & first, + sizeType const & count + ) + { + return detail::tvec4( + extractField(value[0], first, count), + extractField(value[1], first, count), + extractField(value[2], first, count), + extractField(value[3], first, count)); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 powerOfTwoAbove -( - detail::tvec4 const & value -) -{ - return detail::tvec4( - powerOfTwoAbove(value[0]), - powerOfTwoAbove(value[1]), - powerOfTwoAbove(value[2]), - powerOfTwoAbove(value[3])); -} + template + GLM_FUNC_QUALIFIER detail::tvec2 extractField + ( + detail::tvec2 const & value, + detail::tvec2 const & first, + detail::tvec2 const & count + ) + { + return detail::tvec2( + extractField(value[0], first[0], count[0]), + extractField(value[1], first[1], count[1])); + } -// powerOfTwoBelow -template -GLM_FUNC_QUALIFIER genType powerOfTwoBelow -( - genType const & value -) -{ - return isPowerOfTwo(value) ? value : highestBitValue(value); -} + template + GLM_FUNC_QUALIFIER detail::tvec3 extractField + ( + detail::tvec3 const & value, + detail::tvec3 const & first, + detail::tvec3 const & count + ) + { + return detail::tvec3( + extractField(value[0], first[0], count[0]), + extractField(value[1], first[1], count[1]), + extractField(value[2], first[2], count[2])); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 powerOfTwoBelow -( - detail::tvec2 const & value -) -{ - return detail::tvec2( - powerOfTwoBelow(value[0]), - powerOfTwoBelow(value[1])); -} + template + GLM_FUNC_QUALIFIER detail::tvec4 extractField + ( + detail::tvec4 const & value, + detail::tvec4 const & first, + detail::tvec4 const & count + ) + { + return detail::tvec4( + extractField(value[0], first[0], count[0]), + extractField(value[1], first[1], count[1]), + extractField(value[2], first[2], count[2]), + extractField(value[3], first[3], count[3])); + } -template -GLM_FUNC_QUALIFIER detail::tvec3 powerOfTwoBelow -( - detail::tvec3 const & value -) -{ - return detail::tvec3( - powerOfTwoBelow(value[0]), - powerOfTwoBelow(value[1]), - powerOfTwoBelow(value[2])); -} + template + GLM_FUNC_QUALIFIER detail::tvec2 extractField + ( + genIUType const & value, + detail::tvec2 const & first, + detail::tvec2 const & count + ) + { + return detail::tvec2( + extractField(value, first[0], count[0]), + extractField(value, first[1], count[1])); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 powerOfTwoBelow -( - detail::tvec4 const & value -) -{ - return detail::tvec4( - powerOfTwoBelow(value[0]), - powerOfTwoBelow(value[1]), - powerOfTwoBelow(value[2]), - powerOfTwoBelow(value[3])); -} + template + GLM_FUNC_QUALIFIER detail::tvec3 extractField + ( + genIUType const & value, + detail::tvec3 const & first, + detail::tvec3 const & count + ) + { + return detail::tvec3( + extractField(value, first[0], count[0]), + extractField(value, first[1], count[1]), + extractField(value, first[2], count[2])); + } -// powerOfTwoNearest -template -GLM_FUNC_QUALIFIER genType powerOfTwoNearest -( - genType const & value -) -{ - if(isPowerOfTwo(value)) - return value; + template + GLM_FUNC_QUALIFIER detail::tvec4 extractField + ( + genIUType const & value, + detail::tvec4 const & first, + detail::tvec4 const & count + ) + { + return detail::tvec4( + extractField(value, first[0], count[0]), + extractField(value, first[1], count[1]), + extractField(value, first[2], count[2]), + extractField(value, first[3], count[3])); + } - genType prev = highestBitValue(value); - genType next = prev << 1; - return (next - value) < (value - prev) ? next : prev; -} + // lowestBit + template + GLM_FUNC_QUALIFIER int lowestBit + ( + genType const & Value + ) + { + assert(Value != genType(0)); // not valid call -template -GLM_FUNC_QUALIFIER detail::tvec2 powerOfTwoNearest -( - detail::tvec2 const & value -) -{ - return detail::tvec2( - powerOfTwoNearest(value[0]), - powerOfTwoNearest(value[1])); -} + genType Bit; + for(Bit = genType(0); !(Value & (1 << Bit)); ++Bit){} + return Bit; + } -template -GLM_FUNC_QUALIFIER detail::tvec3 powerOfTwoNearest -( - detail::tvec3 const & value -) -{ - return detail::tvec3( - powerOfTwoNearest(value[0]), - powerOfTwoNearest(value[1]), - powerOfTwoNearest(value[2])); -} + template + GLM_FUNC_QUALIFIER detail::tvec2 lowestBit + ( + detail::tvec2 const & value + ) + { + return detail::tvec2( + lowestBit(value[0]), + lowestBit(value[1])); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 powerOfTwoNearest -( - detail::tvec4 const & value -) -{ - return detail::tvec4( - powerOfTwoNearest(value[0]), - powerOfTwoNearest(value[1]), - powerOfTwoNearest(value[2]), - powerOfTwoNearest(value[3])); -} + template + GLM_FUNC_QUALIFIER detail::tvec3 lowestBit + ( + detail::tvec3 const & value + ) + { + return detail::tvec3( + lowestBit(value[0]), + lowestBit(value[1]), + lowestBit(value[2])); + } -template -GLM_FUNC_QUALIFIER genType bitRevert(genType const & In) -{ - GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitRevert' only accept integer values"); + template + GLM_FUNC_QUALIFIER detail::tvec4 lowestBit + ( + detail::tvec4 const & value + ) + { + return detail::tvec4( + lowestBit(value[0]), + lowestBit(value[1]), + lowestBit(value[2]), + lowestBit(value[3])); + } - genType Out = 0; - std::size_t BitSize = sizeof(genType) * 8; - for(std::size_t i = 0; i < BitSize; ++i) - if(In & (genType(1) << i)) - Out |= genType(1) << (BitSize - 1 - i); - return Out; -} + // highestBit + template + GLM_FUNC_QUALIFIER int highestBit + ( + genType const & value + ) + { + assert(value != genType(0)); // not valid call -template -GLM_FUNC_QUALIFIER detail::tvec2 bitRevert -( - detail::tvec2 const & Value -) -{ - return detail::tvec2( - bitRevert(Value[0]), - bitRevert(Value[1])); -} + genType bit = genType(-1); + for(genType tmp = value; tmp; tmp >>= 1, ++bit){} + return bit; + } -template -GLM_FUNC_QUALIFIER detail::tvec3 bitRevert -( - detail::tvec3 const & Value -) -{ - return detail::tvec3( - bitRevert(Value[0]), - bitRevert(Value[1]), - bitRevert(Value[2])); -} + //template <> + //GLM_FUNC_QUALIFIER int highestBit + //( + // int value + //) + //{ + // int bit = -1; + // for(int tmp = value; tmp; tmp >>= 1, ++bit); + // return bit; + //} -template -GLM_FUNC_QUALIFIER detail::tvec4 bitRevert -( - detail::tvec4 const & Value -) -{ - return detail::tvec4( - bitRevert(Value[0]), - bitRevert(Value[1]), - bitRevert(Value[2]), - bitRevert(Value[3])); -} + template + GLM_FUNC_QUALIFIER detail::tvec2 highestBit + ( + detail::tvec2 const & value + ) + { + return detail::tvec2( + highestBit(value[0]), + highestBit(value[1])); + } -template -GLM_FUNC_QUALIFIER genType bitRotateRight(genType const & In, std::size_t Shift) -{ - GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitRotateRight' only accept integer values"); + template + GLM_FUNC_QUALIFIER detail::tvec3 highestBit + ( + detail::tvec3 const & value + ) + { + return detail::tvec3( + highestBit(value[0]), + highestBit(value[1]), + highestBit(value[2])); + } - std::size_t BitSize = sizeof(genType) * 8; - return (In << Shift) | (In >> (BitSize - Shift)); -} + template + GLM_FUNC_QUALIFIER detail::tvec4 highestBit + ( + detail::tvec4 const & value + ) + { + return detail::tvec4( + highestBit(value[0]), + highestBit(value[1]), + highestBit(value[2]), + highestBit(value[3])); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 bitRotateRight -( - detail::tvec2 const & Value, - std::size_t Shift -) -{ - return detail::tvec2( - bitRotateRight(Value[0], Shift), - bitRotateRight(Value[1], Shift)); -} + // highestBitValue + template + GLM_FUNC_QUALIFIER genType highestBitValue + ( + genType const & value + ) + { + genType tmp = value; + genType result = genType(0); + while(tmp) + { + result = (tmp & (~tmp + 1)); // grab lowest bit + tmp &= ~result; // clear lowest bit + } + return result; + } -template -GLM_FUNC_QUALIFIER detail::tvec3 bitRotateRight -( - detail::tvec3 const & Value, - std::size_t Shift -) -{ - return detail::tvec3( - bitRotateRight(Value[0], Shift), - bitRotateRight(Value[1], Shift), - bitRotateRight(Value[2], Shift)); -} + template + GLM_FUNC_QUALIFIER detail::tvec2 highestBitValue + ( + detail::tvec2 const & value + ) + { + return detail::tvec2( + highestBitValue(value[0]), + highestBitValue(value[1])); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 bitRotateRight -( - detail::tvec4 const & Value, - std::size_t Shift -) -{ - return detail::tvec4( - bitRotateRight(Value[0], Shift), - bitRotateRight(Value[1], Shift), - bitRotateRight(Value[2], Shift), - bitRotateRight(Value[3], Shift)); -} + template + GLM_FUNC_QUALIFIER detail::tvec3 highestBitValue + ( + detail::tvec3 const & value + ) + { + return detail::tvec3( + highestBitValue(value[0]), + highestBitValue(value[1]), + highestBitValue(value[2])); + } -template -GLM_FUNC_QUALIFIER genType bitRotateLeft(genType const & In, std::size_t Shift) -{ - GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitRotateLeft' only accept integer values"); + template + GLM_FUNC_QUALIFIER detail::tvec4 highestBitValue + ( + detail::tvec4 const & value + ) + { + return detail::tvec4( + highestBitValue(value[0]), + highestBitValue(value[1]), + highestBitValue(value[2]), + highestBitValue(value[3])); + } - std::size_t BitSize = sizeof(genType) * 8; - return (In >> Shift) | (In << (BitSize - Shift)); -} + // isPowerOfTwo + template + GLM_FUNC_QUALIFIER bool isPowerOfTwo(genType const & Value) + { + //detail::If::is_signed>::apply(abs, Value); + //return !(Value & (Value - 1)); -template -GLM_FUNC_QUALIFIER detail::tvec2 bitRotateLeft -( - detail::tvec2 const & Value, - std::size_t Shift -) -{ - return detail::tvec2( - bitRotateLeft(Value[0], Shift), - bitRotateLeft(Value[1], Shift)); -} + // For old complier? + genType Result = Value; + if(std::numeric_limits::is_signed) + Result = abs(Result); + return !(Result & (Result - 1)); + } -template -GLM_FUNC_QUALIFIER detail::tvec3 bitRotateLeft -( - detail::tvec3 const & Value, - std::size_t Shift -) -{ - return detail::tvec3( - bitRotateLeft(Value[0], Shift), - bitRotateLeft(Value[1], Shift), - bitRotateLeft(Value[2], Shift)); -} + template + GLM_FUNC_QUALIFIER detail::tvec2 isPowerOfTwo + ( + detail::tvec2 const & value + ) + { + return detail::tvec2( + isPowerOfTwo(value[0]), + isPowerOfTwo(value[1])); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 bitRotateLeft -( - detail::tvec4 const & Value, - std::size_t Shift -) -{ - return detail::tvec4( - bitRotateLeft(Value[0], Shift), - bitRotateLeft(Value[1], Shift), - bitRotateLeft(Value[2], Shift), - bitRotateLeft(Value[3], Shift)); -} + template + GLM_FUNC_QUALIFIER detail::tvec3 isPowerOfTwo + ( + detail::tvec3 const & value + ) + { + return detail::tvec3( + isPowerOfTwo(value[0]), + isPowerOfTwo(value[1]), + isPowerOfTwo(value[2])); + } -template -GLM_FUNC_QUALIFIER genIUType fillBitfieldWithOne -( - genIUType const & Value, - int const & FromBit, - int const & ToBit -) -{ - assert(FromBit <= ToBit); - assert(ToBit <= sizeof(genIUType) * std::size_t(8)); + template + GLM_FUNC_QUALIFIER detail::tvec4 isPowerOfTwo + ( + detail::tvec4 const & value + ) + { + return detail::tvec4( + isPowerOfTwo(value[0]), + isPowerOfTwo(value[1]), + isPowerOfTwo(value[2]), + isPowerOfTwo(value[3])); + } - genIUType Result = Value; - for(std::size_t i = 0; i <= ToBit; ++i) - Result |= (1 << i); - return Result; -} + // powerOfTwoAbove + template + GLM_FUNC_QUALIFIER genType powerOfTwoAbove(genType const & value) + { + return isPowerOfTwo(value) ? value : highestBitValue(value) << 1; + } -template -GLM_FUNC_QUALIFIER genIUType fillBitfieldWithZero -( - genIUType const & Value, - int const & FromBit, - int const & ToBit -) -{ - assert(FromBit <= ToBit); - assert(ToBit <= sizeof(genIUType) * std::size_t(8)); + VECTORIZE_VEC(powerOfTwoAbove) - genIUType Result = Value; - for(std::size_t i = 0; i <= ToBit; ++i) - Result &= ~(1 << i); - return Result; -} + // powerOfTwoBelow + template + GLM_FUNC_QUALIFIER genType powerOfTwoBelow + ( + genType const & value + ) + { + return isPowerOfTwo(value) ? value : highestBitValue(value); + } + VECTORIZE_VEC(powerOfTwoBelow) + + // powerOfTwoNearest + template + GLM_FUNC_QUALIFIER genType powerOfTwoNearest + ( + genType const & value + ) + { + if(isPowerOfTwo(value)) + return value; + + genType prev = highestBitValue(value); + genType next = prev << 1; + return (next - value) < (value - prev) ? next : prev; + } + + VECTORIZE_VEC(powerOfTwoNearest) + + template + GLM_FUNC_QUALIFIER genType bitRevert(genType const & In) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitRevert' only accept integer values"); + + genType Out = 0; + std::size_t BitSize = sizeof(genType) * 8; + for(std::size_t i = 0; i < BitSize; ++i) + if(In & (genType(1) << i)) + Out |= genType(1) << (BitSize - 1 - i); + return Out; + } + + VECTORIZE_VEC(bitRevert) + + template + GLM_FUNC_QUALIFIER genType bitRotateRight(genType const & In, std::size_t Shift) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitRotateRight' only accept integer values"); + + std::size_t BitSize = sizeof(genType) * 8; + return (In << Shift) | (In >> (BitSize - Shift)); + } + + template + GLM_FUNC_QUALIFIER detail::tvec2 bitRotateRight + ( + detail::tvec2 const & Value, + std::size_t Shift + ) + { + return detail::tvec2( + bitRotateRight(Value[0], Shift), + bitRotateRight(Value[1], Shift)); + } + + template + GLM_FUNC_QUALIFIER detail::tvec3 bitRotateRight + ( + detail::tvec3 const & Value, + std::size_t Shift + ) + { + return detail::tvec3( + bitRotateRight(Value[0], Shift), + bitRotateRight(Value[1], Shift), + bitRotateRight(Value[2], Shift)); + } + + template + GLM_FUNC_QUALIFIER detail::tvec4 bitRotateRight + ( + detail::tvec4 const & Value, + std::size_t Shift + ) + { + return detail::tvec4( + bitRotateRight(Value[0], Shift), + bitRotateRight(Value[1], Shift), + bitRotateRight(Value[2], Shift), + bitRotateRight(Value[3], Shift)); + } + + template + GLM_FUNC_QUALIFIER genType bitRotateLeft(genType const & In, std::size_t Shift) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitRotateLeft' only accept integer values"); + + std::size_t BitSize = sizeof(genType) * 8; + return (In >> Shift) | (In << (BitSize - Shift)); + } + + template + GLM_FUNC_QUALIFIER detail::tvec2 bitRotateLeft + ( + detail::tvec2 const & Value, + std::size_t Shift + ) + { + return detail::tvec2( + bitRotateLeft(Value[0], Shift), + bitRotateLeft(Value[1], Shift)); + } + + template + GLM_FUNC_QUALIFIER detail::tvec3 bitRotateLeft + ( + detail::tvec3 const & Value, + std::size_t Shift + ) + { + return detail::tvec3( + bitRotateLeft(Value[0], Shift), + bitRotateLeft(Value[1], Shift), + bitRotateLeft(Value[2], Shift)); + } + + template + GLM_FUNC_QUALIFIER detail::tvec4 bitRotateLeft + ( + detail::tvec4 const & Value, + std::size_t Shift + ) + { + return detail::tvec4( + bitRotateLeft(Value[0], Shift), + bitRotateLeft(Value[1], Shift), + bitRotateLeft(Value[2], Shift), + bitRotateLeft(Value[3], Shift)); + } + + template + GLM_FUNC_QUALIFIER genIUType fillBitfieldWithOne + ( + genIUType const & Value, + int const & FromBit, + int const & ToBit + ) + { + assert(FromBit <= ToBit); + assert(ToBit <= sizeof(genIUType) * std::size_t(8)); + + genIUType Result = Value; + for(std::size_t i = 0; i <= ToBit; ++i) + Result |= (1 << i); + return Result; + } + + template + GLM_FUNC_QUALIFIER genIUType fillBitfieldWithZero + ( + genIUType const & Value, + int const & FromBit, + int const & ToBit + ) + { + assert(FromBit <= ToBit); + assert(ToBit <= sizeof(genIUType) * std::size_t(8)); + + genIUType Result = Value; + for(std::size_t i = 0; i <= ToBit; ++i) + Result &= ~(1 << i); + return Result; + } }//namespace glm diff --git a/glm/gtx/closest_point.inl b/glm/gtx/closest_point.inl index 5d19d7cc..91aaed2c 100644 --- a/glm/gtx/closest_point.inl +++ b/glm/gtx/closest_point.inl @@ -10,28 +10,27 @@ #ifndef glm_gtx_closest_point #define glm_gtx_closest_point -namespace glm{ - -template -GLM_FUNC_QUALIFIER detail::tvec3 closestPointOnLine -( - detail::tvec3 const & point, - detail::tvec3 const & a, - detail::tvec3 const & b -) +namespace glm { - valType LineLength = distance(a, b); - detail::tvec3 Vector = point - a; - detail::tvec3 LineDirection = (b - a) / LineLength; + template + GLM_FUNC_QUALIFIER detail::tvec3 closestPointOnLine + ( + detail::tvec3 const & point, + detail::tvec3 const & a, + detail::tvec3 const & b + ) + { + valType LineLength = distance(a, b); + detail::tvec3 Vector = point - a; + detail::tvec3 LineDirection = (b - a) / LineLength; - // Project Vector to LineDirection to get the distance of point from a - valType Distance = dot(Vector, LineDirection); - - if(Distance <= valType(0)) return a; - if(Distance >= LineLength) return b; - return a + LineDirection * Distance; -} + // Project Vector to LineDirection to get the distance of point from a + valType Distance = dot(Vector, LineDirection); + if(Distance <= valType(0)) return a; + if(Distance >= LineLength) return b; + return a + LineDirection * Distance; + } }//namespace glm #endif//glm_gtx_closest_point diff --git a/glm/gtx/color_cast.inl b/glm/gtx/color_cast.inl index ddfbcc0c..27eb6727 100644 --- a/glm/gtx/color_cast.inl +++ b/glm/gtx/color_cast.inl @@ -7,728 +7,727 @@ // File : glm/gtx/color_cast.inl /////////////////////////////////////////////////////////////////////////////////////////////////// -namespace glm{ - -template -GLM_FUNC_QUALIFIER uint8 u8channel_cast(T a) -{ - return static_cast(a * T(255)); -} - -template -GLM_FUNC_QUALIFIER uint16 u16channel_cast(T a) -{ - return static_cast(a * T(65535)); -} - -template -GLM_FUNC_QUALIFIER uint32 u32_rgbx_cast(const detail::tvec3& c) -{ - uint32 result = 0; - result += static_cast(c.x * detail::tvec3::value_type(255)) << 0; - result += static_cast(c.y * detail::tvec3::value_type(255)) << 8; - result += static_cast(c.z * detail::tvec3::value_type(255)) << 16; - return result; -} - -template -GLM_FUNC_QUALIFIER uint32 u32_xrgb_cast(const detail::tvec3& c) -{ - uint32 result = 0; - result += static_cast(c.x * detail::tvec3::value_type(255)) << 8; - result += static_cast(c.y * detail::tvec3::value_type(255)) << 16; - result += static_cast(c.z * detail::tvec3::value_type(255)) << 24; - return result; -} - -template -GLM_FUNC_QUALIFIER uint32 u32_bgrx_cast(const detail::tvec3& c) -{ - uint32 result = 0; - result += static_cast(c.x * detail::tvec3::value_type(255)) << 16; - result += static_cast(c.y * detail::tvec3::value_type(255)) << 8; - result += static_cast(c.z * detail::tvec3::value_type(255)) << 0; - return result; -} - -template -GLM_FUNC_QUALIFIER uint32 u32_xbgr_cast(const detail::tvec3& c) -{ - uint32 result = 0; - result += static_cast(c.x * detail::tvec3::value_type(255)) << 24; - result += static_cast(c.y * detail::tvec3::value_type(255)) << 16; - result += static_cast(c.z * detail::tvec3::value_type(255)) << 8; - result += static_cast(c.w * detail::tvec3::value_type(255)) << 0; - return result; -} - -template -GLM_FUNC_QUALIFIER uint32 u32_rgba_cast(const detail::tvec4& c) -{ - uint32 result = 0; - result += static_cast(c.x * detail::tvec4::value_type(255)) << 0; - result += static_cast(c.y * detail::tvec4::value_type(255)) << 8; - result += static_cast(c.z * detail::tvec4::value_type(255)) << 16; - result += static_cast(c.w * detail::tvec4::value_type(255)) << 24; - return result; -} - -template -GLM_FUNC_QUALIFIER uint32 u32_argb_cast(const detail::tvec4& c) -{ - uint32 result = 0; - result += static_cast(c.x * detail::tvec4::value_type(255)) << 8; - result += static_cast(c.y * detail::tvec4::value_type(255)) << 16; - result += static_cast(c.z * detail::tvec4::value_type(255)) << 24; - result += static_cast(c.w * detail::tvec4::value_type(255)) << 0; - return result; -} - -template -GLM_FUNC_QUALIFIER uint32 u32_bgra_cast(const detail::tvec4& c) -{ - uint32 result = 0; - result += static_cast(c.x * detail::tvec4::value_type(255)) << 16; - result += static_cast(c.y * detail::tvec4::value_type(255)) << 8; - result += static_cast(c.z * detail::tvec4::value_type(255)) << 0; - result += static_cast(c.w * detail::tvec4::value_type(255)) << 24; - return result; -} - -template -GLM_FUNC_QUALIFIER uint32 u32_abgr_cast(const detail::tvec4& c) -{ - uint32 result = 0; - result += static_cast(c.x * detail::tvec4::value_type(255)) << 24; - result += static_cast(c.y * detail::tvec4::value_type(255)) << 16; - result += static_cast(c.z * detail::tvec4::value_type(255)) << 8; - result += static_cast(c.w * detail::tvec4::value_type(255)) << 0; - return result; -} - -template -GLM_FUNC_QUALIFIER uint64 u64_rgbx_cast(const detail::tvec3& c) -{ - uint64 result = 0; - result += static_cast(c.x * detail::tvec3::value_type(65535)) << 0; - result += static_cast(c.y * detail::tvec3::value_type(65535)) << 16; - result += static_cast(c.z * detail::tvec3::value_type(65535)) << 32; - return result; -} - -template -GLM_FUNC_QUALIFIER uint64 u32_xrgb_cast(const detail::tvec3& c) -{ - uint64 result = 0; - result += static_cast(c.x * detail::tvec3::value_type(65535)) << 16; - result += static_cast(c.y * detail::tvec3::value_type(65535)) << 32; - result += static_cast(c.z * detail::tvec3::value_type(65535)) << 48; - return result; -} - -template -GLM_FUNC_QUALIFIER uint64 u32_bgrx_cast(const detail::tvec3& c) -{ - uint64 result = 0; - result += static_cast(c.x * detail::tvec3::value_type(65535)) << 32; - result += static_cast(c.y * detail::tvec3::value_type(65535)) << 16; - result += static_cast(c.z * detail::tvec3::value_type(65535)) << 0; - return result; -} - -template -GLM_FUNC_QUALIFIER uint64 u32_xbgr_cast(const detail::tvec3& c) -{ - uint64 result = 0; - result += static_cast(c.x * detail::tvec3::value_type(65535)) << 48; - result += static_cast(c.y * detail::tvec3::value_type(65535)) << 32; - result += static_cast(c.z * detail::tvec3::value_type(65535)) << 16; - result += static_cast(c.w * detail::tvec3::value_type(65535)) << 0; - return result; -} - -template -GLM_FUNC_QUALIFIER uint64 u64_rgba_cast(const detail::tvec4& c) -{ - uint64 result = 0; - result += static_cast(c.x * detail::tvec4::value_type(65535)) << 0; - result += static_cast(c.y * detail::tvec4::value_type(65535)) << 16; - result += static_cast(c.z * detail::tvec4::value_type(65535)) << 32; - result += static_cast(c.w * detail::tvec4::value_type(65535)) << 48; - return result; -} - -template -GLM_FUNC_QUALIFIER uint64 u64_argb_cast(const detail::tvec4& c) -{ - uint64 result = 0; - result += static_cast(c.x * detail::tvec4::value_type(65535)) << 16; - result += static_cast(c.y * detail::tvec4::value_type(65535)) << 32; - result += static_cast(c.z * detail::tvec4::value_type(65535)) << 48; - result += static_cast(c.w * detail::tvec4::value_type(65535)) << 0; - return result; -} - -template -GLM_FUNC_QUALIFIER uint64 u64_bgra_cast(const detail::tvec4& c) -{ - uint64 result = 0; - result += static_cast(c.x * detail::tvec4::value_type(65535)) << 32; - result += static_cast(c.y * detail::tvec4::value_type(65535)) << 16; - result += static_cast(c.z * detail::tvec4::value_type(65535)) << 0; - result += static_cast(c.w * detail::tvec4::value_type(65535)) << 48; - return result; -} - -template -GLM_FUNC_QUALIFIER uint64 u64_abgr_cast(const detail::tvec4& c) -{ - uint64 result = 0; - result += static_cast(c.x * detail::tvec4::value_type(65535)) << 48; - result += static_cast(c.y * detail::tvec4::value_type(65535)) << 32; - result += static_cast(c.z * detail::tvec4::value_type(65535)) << 16; - result += static_cast(c.w * detail::tvec4::value_type(65535)) << 0; - return result; -} - -template <> -GLM_FUNC_QUALIFIER f16 f16_channel_cast(uint32 color) -{ - return f16(static_cast(color >> 0) / static_cast(255)); -} - -template <> -GLM_FUNC_QUALIFIER f16vec3 f16_rgbx_cast(uint32 color) -{ - f16vec3 result; - result.x = f16(static_cast((color >> 0) & 0xFF) / static_cast(255)); - result.y = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); - result.z = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER f16vec3 f16_xrgb_cast(uint32 color) -{ - f16vec3 result; - result.x = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); - result.y = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); - result.z = f16(static_cast((color >> 24) & 0xFF) / static_cast(255)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER f16vec3 f16_bgrx_cast(uint32 color) -{ - f16vec3 result; - result.x = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); - result.y = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); - result.z = f16(static_cast((color >> 0) & 0xFF) / static_cast(255)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER f16vec3 f16_xbgr_cast(uint32 color) -{ - f16vec3 result; - result.x = f16(static_cast((color >> 24) & 0xFF) / static_cast(255)); - result.y = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); - result.z = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER f16vec4 f16_rgba_cast(uint32 color) -{ - f16vec4 result; - result.x = f16(static_cast((color >> 0) & 0xFF) / static_cast(255)); - result.y = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); - result.z = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); - result.w = f16(static_cast((color >> 24) & 0xFF) / static_cast(255)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER f16vec4 f16_argb_cast(uint32 color) -{ - f16vec4 result; - result.x = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); - result.y = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); - result.z = f16(static_cast((color >> 24) & 0xFF) / static_cast(255)); - result.w = f16(static_cast((color >> 0) & 0xFF) / static_cast(255)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER f16vec4 f16_bgra_cast(uint32 color) -{ - f16vec4 result; - result.x = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); - result.y = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); - result.z = f16(static_cast((color >> 0) & 0xFF) / static_cast(255)); - result.w = f16(static_cast((color >> 24) & 0xFF) / static_cast(255)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER f16vec4 f16_abgr_cast(uint32 color) -{ - f16vec4 result; - result.x = f16(static_cast((color >> 24) & 0xFF) / static_cast(255)); - result.y = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); - result.z = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); - result.w = f16(static_cast((color >> 0) & 0xFF) / static_cast(255)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER float f32_channel_cast(uint8 color) -{ - return static_cast(color >> 0) / static_cast(255); -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f32_rgbx_cast(uint32 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 0) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 16) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f32_xrgb_cast(uint32 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 8) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 24) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f32_bgrx_cast(uint32 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 16) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 0) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f32_xbgr_cast(uint32 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 24) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 8) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f32_rgba_cast(uint32 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 0) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 16) & 0xFF) / static_cast(255); - result.w = static_cast((color >> 24) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f32_argb_cast(uint32 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 8) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 24) & 0xFF) / static_cast(255); - result.w = static_cast((color >> 0) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f32_bgra_cast(uint32 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 16) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 0) & 0xFF) / static_cast(255); - result.w = static_cast((color >> 24) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f32_abgr_cast(uint32 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 24) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 8) & 0xFF) / static_cast(255); - result.w = static_cast((color >> 0) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER double f64_channel_cast(uint8 color) -{ - return static_cast(color >> 0) / static_cast(255); -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f64_rgbx_cast(uint32 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 0) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 16) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f64_xrgb_cast(uint32 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 8) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 24) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f64_bgrx_cast(uint32 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 16) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 0) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f64_xbgr_cast(uint32 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 24) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 8) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f64_rgba_cast(uint32 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 0) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 16) & 0xFF) / static_cast(255); - result.w = static_cast((color >> 24) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f64_argb_cast(uint32 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 8) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 24) & 0xFF) / static_cast(255); - result.w = static_cast((color >> 0) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f64_bgra_cast(uint32 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 16) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 0) & 0xFF) / static_cast(255); - result.w = static_cast((color >> 24) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f64_abgr_cast(uint32 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 24) & 0xFF) / static_cast(255); - result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); - result.z = static_cast((color >> 8) & 0xFF) / static_cast(255); - result.w = static_cast((color >> 0) & 0xFF) / static_cast(255); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::thalf f16_channel_cast(uint16 color) -{ - return detail::thalf(static_cast(color >> 0) / static_cast(65535)); -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f16_rgbx_cast(uint64 color) -{ - detail::tvec3 result; - result.x = detail::thalf(static_cast((color >> 0) & 0xFFFF) / static_cast(65535)); - result.y = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); - result.z = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f16_xrgb_cast(uint64 color) -{ - detail::tvec3 result; - result.x = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); - result.y = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); - result.z = detail::thalf(static_cast((color >> 48) & 0xFFFF) / static_cast(65535)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f16_bgrx_cast(uint64 color) -{ - detail::tvec3 result; - result.x = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); - result.y = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); - result.z = detail::thalf(static_cast((color >> 0) & 0xFFFF) / static_cast(65535)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f16_xbgr_cast(uint64 color) -{ - detail::tvec3 result; - result.x = detail::thalf(static_cast((color >> 48) & 0xFFFF) / static_cast(65535)); - result.y = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); - result.z = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f16_rgba_cast(uint64 color) -{ - detail::tvec4 result; - result.x = detail::thalf(static_cast((color >> 0) & 0xFFFF) / static_cast(65535)); - result.y = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); - result.z = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); - result.w = detail::thalf(static_cast((color >> 48) & 0xFFFF) / static_cast(65535)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f16_argb_cast(uint64 color) -{ - detail::tvec4 result; - result.x = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); - result.y = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); - result.z = detail::thalf(static_cast((color >> 48) & 0xFFFF) / static_cast(65535)); - result.w = detail::thalf(static_cast((color >> 0) & 0xFFFF) / static_cast(65535)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f16_bgra_cast(uint64 color) -{ - detail::tvec4 result; - result.x = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); - result.y = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); - result.z = detail::thalf(static_cast((color >> 0) & 0xFFFF) / static_cast(65535)); - result.w = detail::thalf(static_cast((color >> 48) & 0xFFFF) / static_cast(65535)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f16_abgr_cast(uint64 color) -{ - detail::tvec4 result; - result.x = detail::thalf(static_cast((color >> 48) & 0xFFFF) / static_cast(65535)); - result.y = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); - result.z = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); - result.w = detail::thalf(static_cast((color >> 0) & 0xFFFF) / static_cast(65535)); - return result; -} - -template <> -GLM_FUNC_QUALIFIER float f32_channel_cast(uint16 color) -{ - return static_cast(color >> 0) / static_cast(65535); -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f32_rgbx_cast(uint64 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f32_xrgb_cast(uint64 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f32_bgrx_cast(uint64 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f32_xbgr_cast(uint64 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f32_rgba_cast(uint64 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - result.w = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f32_argb_cast(uint64 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); - result.w = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f32_bgra_cast(uint64 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); - result.w = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f32_abgr_cast(uint64 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - result.w = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER double f64_channel_cast(uint16 color) -{ - return static_cast(color >> 0) / static_cast(65535); -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f64_rgbx_cast(uint64 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f64_xrgb_cast(uint64 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f64_bgrx_cast(uint64 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec3 f64_xbgr_cast(uint64 color) -{ - detail::tvec3 result; - result.x = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f64_rgba_cast(uint64 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - result.w = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f64_argb_cast(uint64 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); - result.w = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f64_bgra_cast(uint64 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); - result.w = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); - return result; -} - -template <> -GLM_FUNC_QUALIFIER detail::tvec4 f64_abgr_cast(uint64 color) -{ - detail::tvec4 result; - result.x = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); - result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); - result.z = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); - result.w = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); - return result; -} - +namespace glm +{ + template + GLM_FUNC_QUALIFIER uint8 u8channel_cast(T a) + { + return static_cast(a * T(255)); + } + + template + GLM_FUNC_QUALIFIER uint16 u16channel_cast(T a) + { + return static_cast(a * T(65535)); + } + + template + GLM_FUNC_QUALIFIER uint32 u32_rgbx_cast(const detail::tvec3& c) + { + uint32 result = 0; + result += static_cast(c.x * detail::tvec3::value_type(255)) << 0; + result += static_cast(c.y * detail::tvec3::value_type(255)) << 8; + result += static_cast(c.z * detail::tvec3::value_type(255)) << 16; + return result; + } + + template + GLM_FUNC_QUALIFIER uint32 u32_xrgb_cast(const detail::tvec3& c) + { + uint32 result = 0; + result += static_cast(c.x * detail::tvec3::value_type(255)) << 8; + result += static_cast(c.y * detail::tvec3::value_type(255)) << 16; + result += static_cast(c.z * detail::tvec3::value_type(255)) << 24; + return result; + } + + template + GLM_FUNC_QUALIFIER uint32 u32_bgrx_cast(const detail::tvec3& c) + { + uint32 result = 0; + result += static_cast(c.x * detail::tvec3::value_type(255)) << 16; + result += static_cast(c.y * detail::tvec3::value_type(255)) << 8; + result += static_cast(c.z * detail::tvec3::value_type(255)) << 0; + return result; + } + + template + GLM_FUNC_QUALIFIER uint32 u32_xbgr_cast(const detail::tvec3& c) + { + uint32 result = 0; + result += static_cast(c.x * detail::tvec3::value_type(255)) << 24; + result += static_cast(c.y * detail::tvec3::value_type(255)) << 16; + result += static_cast(c.z * detail::tvec3::value_type(255)) << 8; + result += static_cast(c.w * detail::tvec3::value_type(255)) << 0; + return result; + } + + template + GLM_FUNC_QUALIFIER uint32 u32_rgba_cast(const detail::tvec4& c) + { + uint32 result = 0; + result += static_cast(c.x * detail::tvec4::value_type(255)) << 0; + result += static_cast(c.y * detail::tvec4::value_type(255)) << 8; + result += static_cast(c.z * detail::tvec4::value_type(255)) << 16; + result += static_cast(c.w * detail::tvec4::value_type(255)) << 24; + return result; + } + + template + GLM_FUNC_QUALIFIER uint32 u32_argb_cast(const detail::tvec4& c) + { + uint32 result = 0; + result += static_cast(c.x * detail::tvec4::value_type(255)) << 8; + result += static_cast(c.y * detail::tvec4::value_type(255)) << 16; + result += static_cast(c.z * detail::tvec4::value_type(255)) << 24; + result += static_cast(c.w * detail::tvec4::value_type(255)) << 0; + return result; + } + + template + GLM_FUNC_QUALIFIER uint32 u32_bgra_cast(const detail::tvec4& c) + { + uint32 result = 0; + result += static_cast(c.x * detail::tvec4::value_type(255)) << 16; + result += static_cast(c.y * detail::tvec4::value_type(255)) << 8; + result += static_cast(c.z * detail::tvec4::value_type(255)) << 0; + result += static_cast(c.w * detail::tvec4::value_type(255)) << 24; + return result; + } + + template + GLM_FUNC_QUALIFIER uint32 u32_abgr_cast(const detail::tvec4& c) + { + uint32 result = 0; + result += static_cast(c.x * detail::tvec4::value_type(255)) << 24; + result += static_cast(c.y * detail::tvec4::value_type(255)) << 16; + result += static_cast(c.z * detail::tvec4::value_type(255)) << 8; + result += static_cast(c.w * detail::tvec4::value_type(255)) << 0; + return result; + } + + template + GLM_FUNC_QUALIFIER uint64 u64_rgbx_cast(const detail::tvec3& c) + { + uint64 result = 0; + result += static_cast(c.x * detail::tvec3::value_type(65535)) << 0; + result += static_cast(c.y * detail::tvec3::value_type(65535)) << 16; + result += static_cast(c.z * detail::tvec3::value_type(65535)) << 32; + return result; + } + + template + GLM_FUNC_QUALIFIER uint64 u32_xrgb_cast(const detail::tvec3& c) + { + uint64 result = 0; + result += static_cast(c.x * detail::tvec3::value_type(65535)) << 16; + result += static_cast(c.y * detail::tvec3::value_type(65535)) << 32; + result += static_cast(c.z * detail::tvec3::value_type(65535)) << 48; + return result; + } + + template + GLM_FUNC_QUALIFIER uint64 u32_bgrx_cast(const detail::tvec3& c) + { + uint64 result = 0; + result += static_cast(c.x * detail::tvec3::value_type(65535)) << 32; + result += static_cast(c.y * detail::tvec3::value_type(65535)) << 16; + result += static_cast(c.z * detail::tvec3::value_type(65535)) << 0; + return result; + } + + template + GLM_FUNC_QUALIFIER uint64 u32_xbgr_cast(const detail::tvec3& c) + { + uint64 result = 0; + result += static_cast(c.x * detail::tvec3::value_type(65535)) << 48; + result += static_cast(c.y * detail::tvec3::value_type(65535)) << 32; + result += static_cast(c.z * detail::tvec3::value_type(65535)) << 16; + result += static_cast(c.w * detail::tvec3::value_type(65535)) << 0; + return result; + } + + template + GLM_FUNC_QUALIFIER uint64 u64_rgba_cast(const detail::tvec4& c) + { + uint64 result = 0; + result += static_cast(c.x * detail::tvec4::value_type(65535)) << 0; + result += static_cast(c.y * detail::tvec4::value_type(65535)) << 16; + result += static_cast(c.z * detail::tvec4::value_type(65535)) << 32; + result += static_cast(c.w * detail::tvec4::value_type(65535)) << 48; + return result; + } + + template + GLM_FUNC_QUALIFIER uint64 u64_argb_cast(const detail::tvec4& c) + { + uint64 result = 0; + result += static_cast(c.x * detail::tvec4::value_type(65535)) << 16; + result += static_cast(c.y * detail::tvec4::value_type(65535)) << 32; + result += static_cast(c.z * detail::tvec4::value_type(65535)) << 48; + result += static_cast(c.w * detail::tvec4::value_type(65535)) << 0; + return result; + } + + template + GLM_FUNC_QUALIFIER uint64 u64_bgra_cast(const detail::tvec4& c) + { + uint64 result = 0; + result += static_cast(c.x * detail::tvec4::value_type(65535)) << 32; + result += static_cast(c.y * detail::tvec4::value_type(65535)) << 16; + result += static_cast(c.z * detail::tvec4::value_type(65535)) << 0; + result += static_cast(c.w * detail::tvec4::value_type(65535)) << 48; + return result; + } + + template + GLM_FUNC_QUALIFIER uint64 u64_abgr_cast(const detail::tvec4& c) + { + uint64 result = 0; + result += static_cast(c.x * detail::tvec4::value_type(65535)) << 48; + result += static_cast(c.y * detail::tvec4::value_type(65535)) << 32; + result += static_cast(c.z * detail::tvec4::value_type(65535)) << 16; + result += static_cast(c.w * detail::tvec4::value_type(65535)) << 0; + return result; + } + + template <> + GLM_FUNC_QUALIFIER f16 f16_channel_cast(uint32 color) + { + return f16(static_cast(color >> 0) / static_cast(255)); + } + + template <> + GLM_FUNC_QUALIFIER f16vec3 f16_rgbx_cast(uint32 color) + { + f16vec3 result; + result.x = f16(static_cast((color >> 0) & 0xFF) / static_cast(255)); + result.y = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); + result.z = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER f16vec3 f16_xrgb_cast(uint32 color) + { + f16vec3 result; + result.x = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); + result.y = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); + result.z = f16(static_cast((color >> 24) & 0xFF) / static_cast(255)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER f16vec3 f16_bgrx_cast(uint32 color) + { + f16vec3 result; + result.x = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); + result.y = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); + result.z = f16(static_cast((color >> 0) & 0xFF) / static_cast(255)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER f16vec3 f16_xbgr_cast(uint32 color) + { + f16vec3 result; + result.x = f16(static_cast((color >> 24) & 0xFF) / static_cast(255)); + result.y = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); + result.z = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER f16vec4 f16_rgba_cast(uint32 color) + { + f16vec4 result; + result.x = f16(static_cast((color >> 0) & 0xFF) / static_cast(255)); + result.y = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); + result.z = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); + result.w = f16(static_cast((color >> 24) & 0xFF) / static_cast(255)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER f16vec4 f16_argb_cast(uint32 color) + { + f16vec4 result; + result.x = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); + result.y = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); + result.z = f16(static_cast((color >> 24) & 0xFF) / static_cast(255)); + result.w = f16(static_cast((color >> 0) & 0xFF) / static_cast(255)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER f16vec4 f16_bgra_cast(uint32 color) + { + f16vec4 result; + result.x = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); + result.y = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); + result.z = f16(static_cast((color >> 0) & 0xFF) / static_cast(255)); + result.w = f16(static_cast((color >> 24) & 0xFF) / static_cast(255)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER f16vec4 f16_abgr_cast(uint32 color) + { + f16vec4 result; + result.x = f16(static_cast((color >> 24) & 0xFF) / static_cast(255)); + result.y = f16(static_cast((color >> 16) & 0xFF) / static_cast(255)); + result.z = f16(static_cast((color >> 8) & 0xFF) / static_cast(255)); + result.w = f16(static_cast((color >> 0) & 0xFF) / static_cast(255)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER float f32_channel_cast(uint8 color) + { + return static_cast(color >> 0) / static_cast(255); + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f32_rgbx_cast(uint32 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 0) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 16) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f32_xrgb_cast(uint32 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 8) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 24) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f32_bgrx_cast(uint32 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 16) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 0) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f32_xbgr_cast(uint32 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 24) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 8) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f32_rgba_cast(uint32 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 0) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 16) & 0xFF) / static_cast(255); + result.w = static_cast((color >> 24) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f32_argb_cast(uint32 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 8) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 24) & 0xFF) / static_cast(255); + result.w = static_cast((color >> 0) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f32_bgra_cast(uint32 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 16) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 0) & 0xFF) / static_cast(255); + result.w = static_cast((color >> 24) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f32_abgr_cast(uint32 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 24) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 8) & 0xFF) / static_cast(255); + result.w = static_cast((color >> 0) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER double f64_channel_cast(uint8 color) + { + return static_cast(color >> 0) / static_cast(255); + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f64_rgbx_cast(uint32 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 0) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 16) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f64_xrgb_cast(uint32 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 8) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 24) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f64_bgrx_cast(uint32 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 16) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 0) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f64_xbgr_cast(uint32 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 24) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 8) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f64_rgba_cast(uint32 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 0) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 16) & 0xFF) / static_cast(255); + result.w = static_cast((color >> 24) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f64_argb_cast(uint32 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 8) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 24) & 0xFF) / static_cast(255); + result.w = static_cast((color >> 0) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f64_bgra_cast(uint32 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 16) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 8) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 0) & 0xFF) / static_cast(255); + result.w = static_cast((color >> 24) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f64_abgr_cast(uint32 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 24) & 0xFF) / static_cast(255); + result.y = static_cast((color >> 16) & 0xFF) / static_cast(255); + result.z = static_cast((color >> 8) & 0xFF) / static_cast(255); + result.w = static_cast((color >> 0) & 0xFF) / static_cast(255); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::thalf f16_channel_cast(uint16 color) + { + return detail::thalf(static_cast(color >> 0) / static_cast(65535)); + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f16_rgbx_cast(uint64 color) + { + detail::tvec3 result; + result.x = detail::thalf(static_cast((color >> 0) & 0xFFFF) / static_cast(65535)); + result.y = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); + result.z = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f16_xrgb_cast(uint64 color) + { + detail::tvec3 result; + result.x = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); + result.y = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); + result.z = detail::thalf(static_cast((color >> 48) & 0xFFFF) / static_cast(65535)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f16_bgrx_cast(uint64 color) + { + detail::tvec3 result; + result.x = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); + result.y = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); + result.z = detail::thalf(static_cast((color >> 0) & 0xFFFF) / static_cast(65535)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f16_xbgr_cast(uint64 color) + { + detail::tvec3 result; + result.x = detail::thalf(static_cast((color >> 48) & 0xFFFF) / static_cast(65535)); + result.y = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); + result.z = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f16_rgba_cast(uint64 color) + { + detail::tvec4 result; + result.x = detail::thalf(static_cast((color >> 0) & 0xFFFF) / static_cast(65535)); + result.y = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); + result.z = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); + result.w = detail::thalf(static_cast((color >> 48) & 0xFFFF) / static_cast(65535)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f16_argb_cast(uint64 color) + { + detail::tvec4 result; + result.x = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); + result.y = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); + result.z = detail::thalf(static_cast((color >> 48) & 0xFFFF) / static_cast(65535)); + result.w = detail::thalf(static_cast((color >> 0) & 0xFFFF) / static_cast(65535)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f16_bgra_cast(uint64 color) + { + detail::tvec4 result; + result.x = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); + result.y = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); + result.z = detail::thalf(static_cast((color >> 0) & 0xFFFF) / static_cast(65535)); + result.w = detail::thalf(static_cast((color >> 48) & 0xFFFF) / static_cast(65535)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f16_abgr_cast(uint64 color) + { + detail::tvec4 result; + result.x = detail::thalf(static_cast((color >> 48) & 0xFFFF) / static_cast(65535)); + result.y = detail::thalf(static_cast((color >> 32) & 0xFFFF) / static_cast(65535)); + result.z = detail::thalf(static_cast((color >> 16) & 0xFFFF) / static_cast(65535)); + result.w = detail::thalf(static_cast((color >> 0) & 0xFFFF) / static_cast(65535)); + return result; + } + + template <> + GLM_FUNC_QUALIFIER float f32_channel_cast(uint16 color) + { + return static_cast(color >> 0) / static_cast(65535); + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f32_rgbx_cast(uint64 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f32_xrgb_cast(uint64 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f32_bgrx_cast(uint64 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f32_xbgr_cast(uint64 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f32_rgba_cast(uint64 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + result.w = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f32_argb_cast(uint64 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); + result.w = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f32_bgra_cast(uint64 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); + result.w = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f32_abgr_cast(uint64 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + result.w = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER double f64_channel_cast(uint16 color) + { + return static_cast(color >> 0) / static_cast(65535); + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f64_rgbx_cast(uint64 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f64_xrgb_cast(uint64 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f64_bgrx_cast(uint64 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec3 f64_xbgr_cast(uint64 color) + { + detail::tvec3 result; + result.x = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f64_rgba_cast(uint64 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + result.w = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f64_argb_cast(uint64 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); + result.w = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f64_bgra_cast(uint64 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); + result.w = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); + return result; + } + + template <> + GLM_FUNC_QUALIFIER detail::tvec4 f64_abgr_cast(uint64 color) + { + detail::tvec4 result; + result.x = static_cast((color >> 48) & 0xFFFF) / static_cast(65535); + result.y = static_cast((color >> 32) & 0xFFFF) / static_cast(65535); + result.z = static_cast((color >> 16) & 0xFFFF) / static_cast(65535); + result.w = static_cast((color >> 0) & 0xFFFF) / static_cast(65535); + return result; + } }//namespace glm diff --git a/glm/gtx/color_space.inl b/glm/gtx/color_space.inl index 4a270d8b..89f4e6dd 100644 --- a/glm/gtx/color_space.inl +++ b/glm/gtx/color_space.inl @@ -7,144 +7,143 @@ // File : glm/gtx/color_space.inl /////////////////////////////////////////////////////////////////////////////////////////////////// -namespace glm{ - -template -GLM_FUNC_QUALIFIER detail::tvec3 rgbColor(const detail::tvec3& hsvColor) +namespace glm { - detail::tvec3 hsv = hsvColor; - detail::tvec3 rgbColor; - - if(hsv.y == T(0)) - // achromatic (grey) - rgbColor = detail::tvec3(hsv.z); - else + template + GLM_FUNC_QUALIFIER detail::tvec3 rgbColor(const detail::tvec3& hsvColor) { - T sector = floor(hsv.x / T(60)); - T frac = (hsv.x / T(60)) - sector; - // factorial part of h - T o = hsv.z * (T(1) - hsv.y); - T p = hsv.z * (T(1) - hsv.y * frac); - T q = hsv.z * (T(1) - hsv.y * (T(1) - frac)); + detail::tvec3 hsv = hsvColor; + detail::tvec3 rgbColor; - switch(int(sector)) - { - default: - case 0: - rgbColor.r = hsv.z; - rgbColor.g = q; - rgbColor.b = o; - break; - case 1: - rgbColor.r = p; - rgbColor.g = hsv.z; - rgbColor.b = o; - break; - case 2: - rgbColor.r = o; - rgbColor.g = hsv.z; - rgbColor.b = q; - break; - case 3: - rgbColor.r = o; - rgbColor.g = p; - rgbColor.b = hsv.z; - break; - case 4: - rgbColor.r = q; - rgbColor.g = o; - rgbColor.b = hsv.z; - break; - case 5: - rgbColor.r = hsv.z; - rgbColor.g = o; - rgbColor.b = p; - break; - } + if(hsv.y == T(0)) + // achromatic (grey) + rgbColor = detail::tvec3(hsv.z); + else + { + T sector = floor(hsv.x / T(60)); + T frac = (hsv.x / T(60)) - sector; + // factorial part of h + T o = hsv.z * (T(1) - hsv.y); + T p = hsv.z * (T(1) - hsv.y * frac); + T q = hsv.z * (T(1) - hsv.y * (T(1) - frac)); + + switch(int(sector)) + { + default: + case 0: + rgbColor.r = hsv.z; + rgbColor.g = q; + rgbColor.b = o; + break; + case 1: + rgbColor.r = p; + rgbColor.g = hsv.z; + rgbColor.b = o; + break; + case 2: + rgbColor.r = o; + rgbColor.g = hsv.z; + rgbColor.b = q; + break; + case 3: + rgbColor.r = o; + rgbColor.g = p; + rgbColor.b = hsv.z; + break; + case 4: + rgbColor.r = q; + rgbColor.g = o; + rgbColor.b = hsv.z; + break; + case 5: + rgbColor.r = hsv.z; + rgbColor.g = o; + rgbColor.b = p; + break; + } + } + + return rgbColor; } - return rgbColor; -} + template + GLM_FUNC_QUALIFIER detail::tvec3 hsvColor(const detail::tvec3& rgbColor) + { + detail::tvec3 hsv = rgbColor; + float Min = min(min(rgbColor.r, rgbColor.g), rgbColor.b); + float Max = max(max(rgbColor.r, rgbColor.g), rgbColor.b); + float Delta = Max - Min; -template -GLM_FUNC_QUALIFIER detail::tvec3 hsvColor(const detail::tvec3& rgbColor) -{ - detail::tvec3 hsv = rgbColor; - float Min = min(min(rgbColor.r, rgbColor.g), rgbColor.b); - float Max = max(max(rgbColor.r, rgbColor.g), rgbColor.b); - float Delta = Max - Min; - - hsv.z = Max; + hsv.z = Max; - if(Max != T(0)) - { - hsv.y = Delta / hsv.z; - T h = T(0); + if(Max != T(0)) + { + hsv.y = Delta / hsv.z; + T h = T(0); - if(rgbColor.r == Max) - // between yellow & magenta - h = T(0) + T(60) * (rgbColor.g - rgbColor.b) / Delta; - else if(rgbColor.g == Max) - // between cyan & yellow - h = T(120) + T(60) * (rgbColor.b - rgbColor.r) / Delta; - else - // between magenta & cyan - h = T(240) + T(60) * (rgbColor.r - rgbColor.g) / Delta; + if(rgbColor.r == Max) + // between yellow & magenta + h = T(0) + T(60) * (rgbColor.g - rgbColor.b) / Delta; + else if(rgbColor.g == Max) + // between cyan & yellow + h = T(120) + T(60) * (rgbColor.b - rgbColor.r) / Delta; + else + // between magenta & cyan + h = T(240) + T(60) * (rgbColor.r - rgbColor.g) / Delta; - if(h < T(0)) - hsv.x = h + T(360); + if(h < T(0)) + hsv.x = h + T(360); + else + hsv.x = h; + } else - hsv.x = h; + { + // If r = g = b = 0 then s = 0, h is undefined + hsv.y = T(0); + hsv.x = T(0); + } + + return hsv; } - else + + template + GLM_FUNC_QUALIFIER detail::tmat4x4 saturation(const T s) { - // If r = g = b = 0 then s = 0, h is undefined - hsv.y = T(0); - hsv.x = T(0); + detail::tvec3 rgbw = detail::tvec3(T(0.2126), T(0.7152), T(0.0722)); + + T col0 = (T(1) - s) * rgbw.r; + T col1 = (T(1) - s) * rgbw.g; + T col2 = (T(1) - s) * rgbw.b; + + detail::tmat4x4 result(T(1)); + result[0][0] = col0 + s; + result[0][1] = col0; + result[0][2] = col0; + result[1][0] = col1; + result[1][1] = col1 + s; + result[1][2] = col1; + result[2][0] = col2; + result[2][1] = col2; + result[2][2] = col2 + s; + return result; } - return hsv; -} + template + GLM_FUNC_QUALIFIER detail::tvec3 saturation(const T s, const detail::tvec3& color) + { + return detail::tvec3(saturation(s) * detail::tvec4(color, T(0))); + } -template -GLM_FUNC_QUALIFIER detail::tmat4x4 saturation(const T s) -{ - detail::tvec3 rgbw = detail::tvec3(T(0.2126), T(0.7152), T(0.0722)); - - T col0 = (T(1) - s) * rgbw.r; - T col1 = (T(1) - s) * rgbw.g; - T col2 = (T(1) - s) * rgbw.b; - - detail::tmat4x4 result(T(1)); - result[0][0] = col0 + s; - result[0][1] = col0; - result[0][2] = col0; - result[1][0] = col1; - result[1][1] = col1 + s; - result[1][2] = col1; - result[2][0] = col2; - result[2][1] = col2; - result[2][2] = col2 + s; - return result; -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 saturation(const T s, const detail::tvec3& color) -{ - return detail::tvec3(saturation(s) * detail::tvec4(color, T(0))); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 saturation(const T s, const detail::tvec4& color) -{ - return saturation(s) * color; -} - -template -GLM_FUNC_QUALIFIER T luminosity(const detail::tvec3& color) -{ - const detail::tvec3 tmp = detail::tvec3(0.33, 0.59, 0.11); - return dot(color, tmp); -} + template + GLM_FUNC_QUALIFIER detail::tvec4 saturation(const T s, const detail::tvec4& color) + { + return saturation(s) * color; + } + template + GLM_FUNC_QUALIFIER T luminosity(const detail::tvec3& color) + { + const detail::tvec3 tmp = detail::tvec3(0.33, 0.59, 0.11); + return dot(color, tmp); + } }//namespace glm diff --git a/glm/gtx/color_space_YCoCg.inl b/glm/gtx/color_space_YCoCg.inl index 5dc57fe5..23aa0e4b 100644 --- a/glm/gtx/color_space_YCoCg.inl +++ b/glm/gtx/color_space_YCoCg.inl @@ -7,59 +7,58 @@ // File : glm/gtx/color_space_YCoCg.inl /////////////////////////////////////////////////////////////////////////////////////////////////// -namespace glm{ - -template -GLM_FUNC_QUALIFIER detail::tvec3 rgb2YCoCg -( - detail::tvec3 const & rgbColor -) +namespace glm { - detail::tvec3 result; - result.x/*Y */ = rgbColor.r / valType(4) + rgbColor.g / valType(2) + rgbColor.b / valType(4); - result.y/*Co*/ = rgbColor.r / valType(2) + rgbColor.g * valType(0) - rgbColor.b / valType(2); - result.z/*Cg*/ = - rgbColor.r / valType(4) + rgbColor.g / valType(2) - rgbColor.b / valType(4); - return result; -} + template + GLM_FUNC_QUALIFIER detail::tvec3 rgb2YCoCg + ( + detail::tvec3 const & rgbColor + ) + { + detail::tvec3 result; + result.x/*Y */ = rgbColor.r / valType(4) + rgbColor.g / valType(2) + rgbColor.b / valType(4); + result.y/*Co*/ = rgbColor.r / valType(2) + rgbColor.g * valType(0) - rgbColor.b / valType(2); + result.z/*Cg*/ = - rgbColor.r / valType(4) + rgbColor.g / valType(2) - rgbColor.b / valType(4); + return result; + } -template -GLM_FUNC_QUALIFIER detail::tvec3 rgb2YCoCgR -( - detail::tvec3 const & rgbColor -) -{ - detail::tvec3 result; - result.x/*Y */ = rgbColor.g / valType(2) + (rgbColor.r + rgbColor.b) / valType(4); - result.y/*Co*/ = rgbColor.r - rgbColor.b; - result.z/*Cg*/ = rgbColor.g - (rgbColor.r + rgbColor.b) / valType(2); - return result; -} + template + GLM_FUNC_QUALIFIER detail::tvec3 rgb2YCoCgR + ( + detail::tvec3 const & rgbColor + ) + { + detail::tvec3 result; + result.x/*Y */ = rgbColor.g / valType(2) + (rgbColor.r + rgbColor.b) / valType(4); + result.y/*Co*/ = rgbColor.r - rgbColor.b; + result.z/*Cg*/ = rgbColor.g - (rgbColor.r + rgbColor.b) / valType(2); + return result; + } -template -GLM_FUNC_QUALIFIER detail::tvec3 YCoCg2rgb -( - detail::tvec3 const & YCoCgColor -) -{ - detail::tvec3 result; - result.r = YCoCgColor.x + YCoCgColor.y - YCoCgColor.z; - result.g = YCoCgColor.x + YCoCgColor.z; - result.b = YCoCgColor.x - YCoCgColor.y - YCoCgColor.z; - return result; -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 YCoCgR2rgb -( - detail::tvec3 const & YCoCgRColor -) -{ - detail::tvec3 result; - valType tmp = YCoCgRColor.x - (YCoCgRColor.z / valType(2)); - result.g = YCoCgRColor.z + tmp; - result.b = tmp - (YCoCgRColor.y / valType(2)); - result.r = result.b + YCoCgRColor.y; - return result; -} + template + GLM_FUNC_QUALIFIER detail::tvec3 YCoCg2rgb + ( + detail::tvec3 const & YCoCgColor + ) + { + detail::tvec3 result; + result.r = YCoCgColor.x + YCoCgColor.y - YCoCgColor.z; + result.g = YCoCgColor.x + YCoCgColor.z; + result.b = YCoCgColor.x - YCoCgColor.y - YCoCgColor.z; + return result; + } + template + GLM_FUNC_QUALIFIER detail::tvec3 YCoCgR2rgb + ( + detail::tvec3 const & YCoCgRColor + ) + { + detail::tvec3 result; + valType tmp = YCoCgRColor.x - (YCoCgRColor.z / valType(2)); + result.g = YCoCgRColor.z + tmp; + result.b = tmp - (YCoCgRColor.y / valType(2)); + result.r = result.b + YCoCgRColor.y; + return result; + } }//namespace glm diff --git a/glm/gtx/compatibility.inl b/glm/gtx/compatibility.inl index 8a8549a1..d266f18d 100644 --- a/glm/gtx/compatibility.inl +++ b/glm/gtx/compatibility.inl @@ -7,131 +7,130 @@ // File : glm/gtx/compatibility.inl /////////////////////////////////////////////////////////////////////////////////////////////////// -namespace glm{ - -// isfinite -template -GLM_FUNC_QUALIFIER bool isfinite( - genType const & x) +namespace glm { -#if(GLM_COMPILER & GLM_COMPILER_VC) - return _finite(x); -#else//(GLM_COMPILER & GLM_COMPILER_GCC) - return std::isfinite(x) != 0; -#endif -} + // isfinite + template + GLM_FUNC_QUALIFIER bool isfinite( + genType const & x) + { + #if(GLM_COMPILER & GLM_COMPILER_VC) + return _finite(x); + #else//(GLM_COMPILER & GLM_COMPILER_GCC) + return std::isfinite(x) != 0; + #endif + } -template -GLM_FUNC_QUALIFIER detail::tvec2 isfinite( - detail::tvec2 const & x) -{ - return detail::tvec2( - isfinite(x.x), - isfinite(x.y)); -} + template + GLM_FUNC_QUALIFIER detail::tvec2 isfinite( + detail::tvec2 const & x) + { + return detail::tvec2( + isfinite(x.x), + isfinite(x.y)); + } -template -GLM_FUNC_QUALIFIER detail::tvec3 isfinite( - detail::tvec3 const & x) -{ - return detail::tvec3( - isfinite(x.x), - isfinite(x.y), - isfinite(x.z)); -} + template + GLM_FUNC_QUALIFIER detail::tvec3 isfinite( + detail::tvec3 const & x) + { + return detail::tvec3( + isfinite(x.x), + isfinite(x.y), + isfinite(x.z)); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 isfinite( - detail::tvec4 const & x) -{ - return detail::tvec4( - isfinite(x.x), - isfinite(x.y), - isfinite(x.z), - isfinite(x.w)); -} + template + GLM_FUNC_QUALIFIER detail::tvec4 isfinite( + detail::tvec4 const & x) + { + return detail::tvec4( + isfinite(x.x), + isfinite(x.y), + isfinite(x.z), + isfinite(x.w)); + } -// isinf -template -GLM_FUNC_QUALIFIER bool isinf( - genType const & x) -{ -#if(GLM_COMPILER & GLM_COMPILER_VC) - return _fpclass(x) == _FPCLASS_NINF || _fpclass(x) == _FPCLASS_PINF; -#else - return std::isinf(x) != 0; -#endif -} + // isinf + template + GLM_FUNC_QUALIFIER bool isinf( + genType const & x) + { + #if(GLM_COMPILER & GLM_COMPILER_VC) + return _fpclass(x) == _FPCLASS_NINF || _fpclass(x) == _FPCLASS_PINF; + #else + return std::isinf(x) != 0; + #endif + } -template -GLM_FUNC_QUALIFIER detail::tvec2 isinf( - detail::tvec2 const & x) -{ - return detail::tvec2( - isinf(x.x), - isinf(x.y)); -} + template + GLM_FUNC_QUALIFIER detail::tvec2 isinf( + detail::tvec2 const & x) + { + return detail::tvec2( + isinf(x.x), + isinf(x.y)); + } -template -GLM_FUNC_QUALIFIER detail::tvec3 isinf( - detail::tvec3 const & x) -{ - return detail::tvec3( - isinf(x.x), - isinf(x.y), - isinf(x.z)); -} + template + GLM_FUNC_QUALIFIER detail::tvec3 isinf( + detail::tvec3 const & x) + { + return detail::tvec3( + isinf(x.x), + isinf(x.y), + isinf(x.z)); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 isinf( - detail::tvec4 const & x) -{ - return detail::tvec4( - isinf(x.x), - isinf(x.y), - isinf(x.z), - isinf(x.w)); -} + template + GLM_FUNC_QUALIFIER detail::tvec4 isinf( + detail::tvec4 const & x) + { + return detail::tvec4( + isinf(x.x), + isinf(x.y), + isinf(x.z), + isinf(x.w)); + } -// isnan -template -GLM_FUNC_QUALIFIER bool isnan(genType const & x) -{ -#if(GLM_COMPILER & GLM_COMPILER_VC) - return _isnan(x); -#else - return std::isnan(x) != 0; -#endif -} + // isnan + template + GLM_FUNC_QUALIFIER bool isnan(genType const & x) + { + #if(GLM_COMPILER & GLM_COMPILER_VC) + return _isnan(x); + #else + return std::isnan(x) != 0; + #endif + } -template -GLM_FUNC_QUALIFIER detail::tvec2 isnan( - detail::tvec2 const & x) -{ - return detail::tvec2( - isnan(x.x), - isnan(x.y)); -} + template + GLM_FUNC_QUALIFIER detail::tvec2 isnan( + detail::tvec2 const & x) + { + return detail::tvec2( + isnan(x.x), + isnan(x.y)); + } -template -GLM_FUNC_QUALIFIER detail::tvec3 isnan( - detail::tvec3 const & x) -{ - return detail::tvec3( - isnan(x.x), - isnan(x.y), - isnan(x.z)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 isnan( - detail::tvec4 const & x) -{ - return detail::tvec4( - isnan(x.x), - isnan(x.y), - isnan(x.z), - isnan(x.w)); -} + template + GLM_FUNC_QUALIFIER detail::tvec3 isnan( + detail::tvec3 const & x) + { + return detail::tvec3( + isnan(x.x), + isnan(x.y), + isnan(x.z)); + } + template + GLM_FUNC_QUALIFIER detail::tvec4 isnan( + detail::tvec4 const & x) + { + return detail::tvec4( + isnan(x.x), + isnan(x.y), + isnan(x.z), + isnan(x.w)); + } }//namespace glm diff --git a/glm/gtx/component_wise.inl b/glm/gtx/component_wise.inl index 43ffe18b..9e484f92 100644 --- a/glm/gtx/component_wise.inl +++ b/glm/gtx/component_wise.inl @@ -7,42 +7,41 @@ // File : gtx_component_wise.inl /////////////////////////////////////////////////////////////////////////////////////////////////// -namespace glm{ - -template -GLM_FUNC_QUALIFIER typename genType::value_type compAdd(genType const & v) +namespace glm { - typename genType::size_type result = typename genType::value_type(0); - for(typename genType::size_type i = 0; i < genType::value_size(); ++i) - result += v[i]; - return result; -} + template + GLM_FUNC_QUALIFIER typename genType::value_type compAdd(genType const & v) + { + typename genType::size_type result = typename genType::value_type(0); + for(typename genType::size_type i = 0; i < genType::value_size(); ++i) + result += v[i]; + return result; + } -template -GLM_FUNC_QUALIFIER typename genType::value_type compMul(genType const & v) -{ - typename genType::value_type result = typename genType::value_type(1); - for(typename genType::size_type i = 0; i < genType::value_size(); ++i) - result *= v[i]; - return result; -} + template + GLM_FUNC_QUALIFIER typename genType::value_type compMul(genType const & v) + { + typename genType::value_type result = typename genType::value_type(1); + for(typename genType::size_type i = 0; i < genType::value_size(); ++i) + result *= v[i]; + return result; + } -template -GLM_FUNC_QUALIFIER typename genType::value_type compMin(genType const & v) -{ - typename genType::value_type result = typename genType::value_type(v[0]); - for(typename genType::size_type i = 1; i < genType::value_size(); ++i) - result = min(result, v[i]); - return result; -} - -template -GLM_FUNC_QUALIFIER typename genType::value_type compMax(genType const & v) -{ - typename genType::value_type result = typename genType::value_type(v[0]); - for(typename genType::size_type i = 1; i < genType::value_size(); ++i) - result = max(result, v[i]); - return result; -} + template + GLM_FUNC_QUALIFIER typename genType::value_type compMin(genType const & v) + { + typename genType::value_type result = typename genType::value_type(v[0]); + for(typename genType::size_type i = 1; i < genType::value_size(); ++i) + result = min(result, v[i]); + return result; + } + template + GLM_FUNC_QUALIFIER typename genType::value_type compMax(genType const & v) + { + typename genType::value_type result = typename genType::value_type(v[0]); + for(typename genType::size_type i = 1; i < genType::value_size(); ++i) + result = max(result, v[i]); + return result; + } }//namespace glm diff --git a/glm/gtx/constants.inl b/glm/gtx/constants.inl index 885c66af..7a556919 100644 --- a/glm/gtx/constants.inl +++ b/glm/gtx/constants.inl @@ -20,773 +20,8 @@ /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN /// THE SOFTWARE. /// -/// @ref gtc_half_float -/// @file glm/gtc/half_float.inl -/// @date 2009-04-29 / 2011-06-05 +/// @ref gtx_constants +/// @file glm/gtx/constants.inl +/// @date 2011-10-14 / 2011-10-14 /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// - -#include "../core/_detail.hpp" - -namespace glm{ - -template -GLM_FUNC_QUALIFIER genIType mask -( - genIType const & count -) -{ - return ((genIType(1) << (count)) - genIType(1)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 mask -( - detail::tvec2 const & count -) -{ - return detail::tvec2( - mask(count[0]), - mask(count[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 mask -( - detail::tvec3 const & count -) -{ - return detail::tvec3( - mask(count[0]), - mask(count[1]), - mask(count[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 mask -( - detail::tvec4 const & count -) -{ - return detail::tvec4( - mask(count[0]), - mask(count[1]), - mask(count[2]), - mask(count[3])); -} - -// extractField -template -GLM_FUNC_QUALIFIER genIType extractField -( - half const & value, - genIType const & first, - genIType const & count -) -{ - assert(first + count < sizeof(half)); - return (value._data() << first) >> ((sizeof(half) << 3) - count); -} - -template -GLM_FUNC_QUALIFIER genIType extractField -( - float const & value, - genIType const & first, - genIType const & count -) -{ - assert(first + count < sizeof(float)); - return (detail::uif32(value).i << first) >> ((sizeof(float) << 3) - count); -} - -template -GLM_FUNC_QUALIFIER genIType extractField -( - double const & value, - genIType const & first, - genIType const & count -) -{ - assert(first + count < sizeof(double)); - return (detail::uif64(value).i << first) >> ((sizeof(double) << genIType(3)) - count); -} - -template -GLM_FUNC_QUALIFIER genIUType extractField -( - genIUType const & Value, - sizeType const & First, - sizeType const & Count -) -{ - sizeType GenSize = sizeof(genIUType) << 3; - - assert(First + Count <= GenSize); - - genIUType ShiftLeft = Count ? Value << (GenSize - (Count + First)) : 0; - genIUType ShiftBack = ShiftLeft >> genIUType(GenSize - Count); - - return ShiftBack; -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 extractField -( - detail::tvec2 const & value, - sizeType const & first, - sizeType const & count -) -{ - return detail::tvec2( - extractField(value[0], first, count), - extractField(value[1], first, count)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 extractField -( - detail::tvec3 const & value, - sizeType const & first, - sizeType const & count -) -{ - return detail::tvec3( - extractField(value[0], first, count), - extractField(value[1], first, count), - extractField(value[2], first, count)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 extractField -( - detail::tvec4 const & value, - sizeType const & first, - sizeType const & count -) -{ - return detail::tvec4( - extractField(value[0], first, count), - extractField(value[1], first, count), - extractField(value[2], first, count), - extractField(value[3], first, count)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 extractField -( - detail::tvec2 const & value, - detail::tvec2 const & first, - detail::tvec2 const & count -) -{ - return detail::tvec2( - extractField(value[0], first[0], count[0]), - extractField(value[1], first[1], count[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 extractField -( - detail::tvec3 const & value, - detail::tvec3 const & first, - detail::tvec3 const & count -) -{ - return detail::tvec3( - extractField(value[0], first[0], count[0]), - extractField(value[1], first[1], count[1]), - extractField(value[2], first[2], count[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 extractField -( - detail::tvec4 const & value, - detail::tvec4 const & first, - detail::tvec4 const & count -) -{ - return detail::tvec4( - extractField(value[0], first[0], count[0]), - extractField(value[1], first[1], count[1]), - extractField(value[2], first[2], count[2]), - extractField(value[3], first[3], count[3])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 extractField -( - genIUType const & value, - detail::tvec2 const & first, - detail::tvec2 const & count -) -{ - return detail::tvec2( - extractField(value, first[0], count[0]), - extractField(value, first[1], count[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 extractField -( - genIUType const & value, - detail::tvec3 const & first, - detail::tvec3 const & count -) -{ - return detail::tvec3( - extractField(value, first[0], count[0]), - extractField(value, first[1], count[1]), - extractField(value, first[2], count[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 extractField -( - genIUType const & value, - detail::tvec4 const & first, - detail::tvec4 const & count -) -{ - return detail::tvec4( - extractField(value, first[0], count[0]), - extractField(value, first[1], count[1]), - extractField(value, first[2], count[2]), - extractField(value, first[3], count[3])); -} - -// lowestBit -template -GLM_FUNC_QUALIFIER int lowestBit -( - genType const & Value -) -{ - assert(Value != genType(0)); // not valid call - - genType Bit; - for(Bit = genType(0); !(Value & (1 << Bit)); ++Bit){} - return Bit; -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 lowestBit -( - detail::tvec2 const & value -) -{ - return detail::tvec2( - lowestBit(value[0]), - lowestBit(value[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 lowestBit -( - detail::tvec3 const & value -) -{ - return detail::tvec3( - lowestBit(value[0]), - lowestBit(value[1]), - lowestBit(value[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 lowestBit -( - detail::tvec4 const & value -) -{ - return detail::tvec4( - lowestBit(value[0]), - lowestBit(value[1]), - lowestBit(value[2]), - lowestBit(value[3])); -} - -// highestBit -template -GLM_FUNC_QUALIFIER int highestBit -( - genType const & value -) -{ - assert(value != genType(0)); // not valid call - - genType bit = genType(-1); - for(genType tmp = value; tmp; tmp >>= 1, ++bit){} - return bit; -} - -//template <> -//GLM_FUNC_QUALIFIER int highestBit -//( -// int value -//) -//{ -// int bit = -1; -// for(int tmp = value; tmp; tmp >>= 1, ++bit); -// return bit; -//} - -template -GLM_FUNC_QUALIFIER detail::tvec2 highestBit -( - detail::tvec2 const & value -) -{ - return detail::tvec2( - highestBit(value[0]), - highestBit(value[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 highestBit -( - detail::tvec3 const & value -) -{ - return detail::tvec3( - highestBit(value[0]), - highestBit(value[1]), - highestBit(value[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 highestBit -( - detail::tvec4 const & value -) -{ - return detail::tvec4( - highestBit(value[0]), - highestBit(value[1]), - highestBit(value[2]), - highestBit(value[3])); -} - -// highestBitValue -template -GLM_FUNC_QUALIFIER genType highestBitValue -( - genType const & value -) -{ - genType tmp = value; - genType result = genType(0); - while(tmp) - { - result = (tmp & (~tmp + 1)); // grab lowest bit - tmp &= ~result; // clear lowest bit - } - return result; -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 highestBitValue -( - detail::tvec2 const & value -) -{ - return detail::tvec2( - highestBitValue(value[0]), - highestBitValue(value[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 highestBitValue -( - detail::tvec3 const & value -) -{ - return detail::tvec3( - highestBitValue(value[0]), - highestBitValue(value[1]), - highestBitValue(value[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 highestBitValue -( - detail::tvec4 const & value -) -{ - return detail::tvec4( - highestBitValue(value[0]), - highestBitValue(value[1]), - highestBitValue(value[2]), - highestBitValue(value[3])); -} - -// isPowerOfTwo -template -GLM_FUNC_QUALIFIER bool isPowerOfTwo(genType const & Value) -{ - //detail::If::is_signed>::apply(abs, Value); - //return !(Value & (Value - 1)); - - // For old complier? - genType Result = Value; - if(std::numeric_limits::is_signed) - Result = abs(Result); - return !(Result & (Result - 1)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 isPowerOfTwo -( - detail::tvec2 const & value -) -{ - return detail::tvec2( - isPowerOfTwo(value[0]), - isPowerOfTwo(value[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 isPowerOfTwo -( - detail::tvec3 const & value -) -{ - return detail::tvec3( - isPowerOfTwo(value[0]), - isPowerOfTwo(value[1]), - isPowerOfTwo(value[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 isPowerOfTwo -( - detail::tvec4 const & value -) -{ - return detail::tvec4( - isPowerOfTwo(value[0]), - isPowerOfTwo(value[1]), - isPowerOfTwo(value[2]), - isPowerOfTwo(value[3])); -} - -// powerOfTwoAbove -template -GLM_FUNC_QUALIFIER genType powerOfTwoAbove(genType const & value) -{ - return isPowerOfTwo(value) ? value : highestBitValue(value) << 1; -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 powerOfTwoAbove -( - detail::tvec2 const & value -) -{ - return detail::tvec2( - powerOfTwoAbove(value[0]), - powerOfTwoAbove(value[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 powerOfTwoAbove -( - detail::tvec3 const & value -) -{ - return detail::tvec3( - powerOfTwoAbove(value[0]), - powerOfTwoAbove(value[1]), - powerOfTwoAbove(value[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 powerOfTwoAbove -( - detail::tvec4 const & value -) -{ - return detail::tvec4( - powerOfTwoAbove(value[0]), - powerOfTwoAbove(value[1]), - powerOfTwoAbove(value[2]), - powerOfTwoAbove(value[3])); -} - -// powerOfTwoBelow -template -GLM_FUNC_QUALIFIER genType powerOfTwoBelow -( - genType const & value -) -{ - return isPowerOfTwo(value) ? value : highestBitValue(value); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 powerOfTwoBelow -( - detail::tvec2 const & value -) -{ - return detail::tvec2( - powerOfTwoBelow(value[0]), - powerOfTwoBelow(value[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 powerOfTwoBelow -( - detail::tvec3 const & value -) -{ - return detail::tvec3( - powerOfTwoBelow(value[0]), - powerOfTwoBelow(value[1]), - powerOfTwoBelow(value[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 powerOfTwoBelow -( - detail::tvec4 const & value -) -{ - return detail::tvec4( - powerOfTwoBelow(value[0]), - powerOfTwoBelow(value[1]), - powerOfTwoBelow(value[2]), - powerOfTwoBelow(value[3])); -} - -// powerOfTwoNearest -template -GLM_FUNC_QUALIFIER genType powerOfTwoNearest -( - genType const & value -) -{ - if(isPowerOfTwo(value)) - return value; - - genType prev = highestBitValue(value); - genType next = prev << 1; - return (next - value) < (value - prev) ? next : prev; -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 powerOfTwoNearest -( - detail::tvec2 const & value -) -{ - return detail::tvec2( - powerOfTwoNearest(value[0]), - powerOfTwoNearest(value[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 powerOfTwoNearest -( - detail::tvec3 const & value -) -{ - return detail::tvec3( - powerOfTwoNearest(value[0]), - powerOfTwoNearest(value[1]), - powerOfTwoNearest(value[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 powerOfTwoNearest -( - detail::tvec4 const & value -) -{ - return detail::tvec4( - powerOfTwoNearest(value[0]), - powerOfTwoNearest(value[1]), - powerOfTwoNearest(value[2]), - powerOfTwoNearest(value[3])); -} - -template -GLM_FUNC_QUALIFIER genType bitRevert(genType const & In) -{ - GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitRevert' only accept integer values"); - - genType Out = 0; - std::size_t BitSize = sizeof(genType) * 8; - for(std::size_t i = 0; i < BitSize; ++i) - if(In & (genType(1) << i)) - Out |= genType(1) << (BitSize - 1 - i); - return Out; -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 bitRevert -( - detail::tvec2 const & Value -) -{ - return detail::tvec2( - bitRevert(Value[0]), - bitRevert(Value[1])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 bitRevert -( - detail::tvec3 const & Value -) -{ - return detail::tvec3( - bitRevert(Value[0]), - bitRevert(Value[1]), - bitRevert(Value[2])); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 bitRevert -( - detail::tvec4 const & Value -) -{ - return detail::tvec4( - bitRevert(Value[0]), - bitRevert(Value[1]), - bitRevert(Value[2]), - bitRevert(Value[3])); -} - -template -GLM_FUNC_QUALIFIER genType bitRotateRight(genType const & In, std::size_t Shift) -{ - GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitRotateRight' only accept integer values"); - - std::size_t BitSize = sizeof(genType) * 8; - return (In << Shift) | (In >> (BitSize - Shift)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 bitRotateRight -( - detail::tvec2 const & Value, - std::size_t Shift -) -{ - return detail::tvec2( - bitRotateRight(Value[0], Shift), - bitRotateRight(Value[1], Shift)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 bitRotateRight -( - detail::tvec3 const & Value, - std::size_t Shift -) -{ - return detail::tvec3( - bitRotateRight(Value[0], Shift), - bitRotateRight(Value[1], Shift), - bitRotateRight(Value[2], Shift)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 bitRotateRight -( - detail::tvec4 const & Value, - std::size_t Shift -) -{ - return detail::tvec4( - bitRotateRight(Value[0], Shift), - bitRotateRight(Value[1], Shift), - bitRotateRight(Value[2], Shift), - bitRotateRight(Value[3], Shift)); -} - -template -GLM_FUNC_QUALIFIER genType bitRotateLeft(genType const & In, std::size_t Shift) -{ - GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitRotateLeft' only accept integer values"); - - std::size_t BitSize = sizeof(genType) * 8; - return (In >> Shift) | (In << (BitSize - Shift)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 bitRotateLeft -( - detail::tvec2 const & Value, - std::size_t Shift -) -{ - return detail::tvec2( - bitRotateLeft(Value[0], Shift), - bitRotateLeft(Value[1], Shift)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 bitRotateLeft -( - detail::tvec3 const & Value, - std::size_t Shift -) -{ - return detail::tvec3( - bitRotateLeft(Value[0], Shift), - bitRotateLeft(Value[1], Shift), - bitRotateLeft(Value[2], Shift)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 bitRotateLeft -( - detail::tvec4 const & Value, - std::size_t Shift -) -{ - return detail::tvec4( - bitRotateLeft(Value[0], Shift), - bitRotateLeft(Value[1], Shift), - bitRotateLeft(Value[2], Shift), - bitRotateLeft(Value[3], Shift)); -} - -template -GLM_FUNC_QUALIFIER genIUType fillBitfieldWithOne -( - genIUType const & Value, - int const & FromBit, - int const & ToBit -) -{ - assert(FromBit <= ToBit); - assert(ToBit <= sizeof(genIUType) * std::size_t(8)); - - genIUType Result = Value; - for(std::size_t i = 0; i <= ToBit; ++i) - Result |= (1 << i); - return Result; -} - -template -GLM_FUNC_QUALIFIER genIUType fillBitfieldWithZero -( - genIUType const & Value, - int const & FromBit, - int const & ToBit -) -{ - assert(FromBit <= ToBit); - assert(ToBit <= sizeof(genIUType) * std::size_t(8)); - - genIUType Result = Value; - for(std::size_t i = 0; i <= ToBit; ++i) - Result &= ~(1 << i); - return Result; -} - -}//namespace glm diff --git a/glm/gtx/epsilon.inl b/glm/gtx/epsilon.inl index bfb2d3b1..7ebc69ae 100644 --- a/glm/gtx/epsilon.inl +++ b/glm/gtx/epsilon.inl @@ -7,224 +7,223 @@ // File : glm/gtx/epsilon.inl /////////////////////////////////////////////////////////////////////////////////////////////////// -namespace glm{ - -template -GLM_FUNC_QUALIFIER bool equalEpsilon -( - genType const & x, - genType const & y, - genType const & epsilon -) +namespace glm { - return abs(x - y) < epsilon; -} + template + GLM_FUNC_QUALIFIER bool equalEpsilon + ( + genType const & x, + genType const & y, + genType const & epsilon + ) + { + return abs(x - y) < epsilon; + } -template -GLM_FUNC_QUALIFIER bool notEqualEpsilon -( - genType const & x, - genType const & y, - genType const & epsilon -) -{ - return abs(x - y) >= epsilon; -} + template + GLM_FUNC_QUALIFIER bool notEqualEpsilon + ( + genType const & x, + genType const & y, + genType const & epsilon + ) + { + return abs(x - y) >= epsilon; + } -template -GLM_FUNC_QUALIFIER detail::tvec2 equalEpsilon -( - detail::tvec2 const & x, - detail::tvec2 const & y, - valType const & epsilon) -{ - return detail::tvec2( - abs(x.x - y.x) < epsilon, - abs(x.y - y.y) < epsilon); -} + template + GLM_FUNC_QUALIFIER detail::tvec2 equalEpsilon + ( + detail::tvec2 const & x, + detail::tvec2 const & y, + valType const & epsilon) + { + return detail::tvec2( + abs(x.x - y.x) < epsilon, + abs(x.y - y.y) < epsilon); + } -template -GLM_FUNC_QUALIFIER detail::tvec3 equalEpsilon -( - detail::tvec3 const & x, - detail::tvec3 const & y, - valType const & epsilon) -{ - return detail::tvec3( - abs(x.x - y.x) < epsilon, - abs(x.y - y.y) < epsilon, - abs(x.z - y.z) < epsilon); -} + template + GLM_FUNC_QUALIFIER detail::tvec3 equalEpsilon + ( + detail::tvec3 const & x, + detail::tvec3 const & y, + valType const & epsilon) + { + return detail::tvec3( + abs(x.x - y.x) < epsilon, + abs(x.y - y.y) < epsilon, + abs(x.z - y.z) < epsilon); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 equalEpsilon -( - detail::tvec4 const & x, - detail::tvec4 const & y, - valType const & epsilon -) -{ - return detail::tvec4( - abs(x.x - y.x) < epsilon, - abs(x.y - y.y) < epsilon, - abs(x.z - y.z) < epsilon, - abs(x.w - y.w) < epsilon); -} + template + GLM_FUNC_QUALIFIER detail::tvec4 equalEpsilon + ( + detail::tvec4 const & x, + detail::tvec4 const & y, + valType const & epsilon + ) + { + return detail::tvec4( + abs(x.x - y.x) < epsilon, + abs(x.y - y.y) < epsilon, + abs(x.z - y.z) < epsilon, + abs(x.w - y.w) < epsilon); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 notEqualEpsilon -( - detail::tvec2 const & x, - detail::tvec2 const & y, - valType const & epsilon -) -{ - return detail::tvec2( - abs(x.x - y.x) >= epsilon, - abs(x.y - y.y) >= epsilon); -} + template + GLM_FUNC_QUALIFIER detail::tvec2 notEqualEpsilon + ( + detail::tvec2 const & x, + detail::tvec2 const & y, + valType const & epsilon + ) + { + return detail::tvec2( + abs(x.x - y.x) >= epsilon, + abs(x.y - y.y) >= epsilon); + } -template -GLM_FUNC_QUALIFIER detail::tvec3 notEqualEpsilon -( - detail::tvec3 const & x, - detail::tvec3 const & y, - valType const & epsilon -) -{ - return detail::tvec3( - abs(x.x - y.x) >= epsilon, - abs(x.y - y.y) >= epsilon, - abs(x.z - y.z) >= epsilon); -} + template + GLM_FUNC_QUALIFIER detail::tvec3 notEqualEpsilon + ( + detail::tvec3 const & x, + detail::tvec3 const & y, + valType const & epsilon + ) + { + return detail::tvec3( + abs(x.x - y.x) >= epsilon, + abs(x.y - y.y) >= epsilon, + abs(x.z - y.z) >= epsilon); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 notEqualEpsilon -( - detail::tvec4 const & x, - detail::tvec4 const & y, - valType const & epsilon -) -{ - return detail::tvec4( - abs(x.x - y.x) >= epsilon, - abs(x.y - y.y) >= epsilon, - abs(x.z - y.z) >= epsilon, - abs(x.w - y.w) >= epsilon); -} + template + GLM_FUNC_QUALIFIER detail::tvec4 notEqualEpsilon + ( + detail::tvec4 const & x, + detail::tvec4 const & y, + valType const & epsilon + ) + { + return detail::tvec4( + abs(x.x - y.x) >= epsilon, + abs(x.y - y.y) >= epsilon, + abs(x.z - y.z) >= epsilon, + abs(x.w - y.w) >= epsilon); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 equalEpsilon -( - detail::tvec2 const & x, - detail::tvec2 const & y, - detail::tvec2 const & epsilon -) -{ - return detail::tvec2( - abs(x.x - y.x) < epsilon.x, - abs(x.y - y.y) < epsilon.y); -} + template + GLM_FUNC_QUALIFIER detail::tvec2 equalEpsilon + ( + detail::tvec2 const & x, + detail::tvec2 const & y, + detail::tvec2 const & epsilon + ) + { + return detail::tvec2( + abs(x.x - y.x) < epsilon.x, + abs(x.y - y.y) < epsilon.y); + } -template -GLM_FUNC_QUALIFIER detail::tvec3 equalEpsilon -( - detail::tvec3 const & x, - detail::tvec3 const & y, - detail::tvec3 const & epsilon -) -{ - return detail::tvec3( - abs(x.x - y.x) < epsilon.x, - abs(x.y - y.y) < epsilon.y, - abs(x.z - y.z) < epsilon.z); -} + template + GLM_FUNC_QUALIFIER detail::tvec3 equalEpsilon + ( + detail::tvec3 const & x, + detail::tvec3 const & y, + detail::tvec3 const & epsilon + ) + { + return detail::tvec3( + abs(x.x - y.x) < epsilon.x, + abs(x.y - y.y) < epsilon.y, + abs(x.z - y.z) < epsilon.z); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 equalEpsilon -( - detail::tvec4 const & x, - detail::tvec4 const & y, - detail::tvec4 const & epsilon -) -{ - return detail::tvec4( - abs(x.x - y.x) < epsilon.x, - abs(x.y - y.y) < epsilon.y, - abs(x.z - y.z) < epsilon.z, - abs(x.w - y.w) < epsilon.w); -} + template + GLM_FUNC_QUALIFIER detail::tvec4 equalEpsilon + ( + detail::tvec4 const & x, + detail::tvec4 const & y, + detail::tvec4 const & epsilon + ) + { + return detail::tvec4( + abs(x.x - y.x) < epsilon.x, + abs(x.y - y.y) < epsilon.y, + abs(x.z - y.z) < epsilon.z, + abs(x.w - y.w) < epsilon.w); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 equalEpsilon -( - detail::tquat const & x, - detail::tquat const & y, - detail::tquat const & epsilon -) -{ - return detail::tvec4( - abs(x.x - y.x) < epsilon.x, - abs(x.y - y.y) < epsilon.y, - abs(x.z - y.z) < epsilon.z, - abs(x.w - y.w) < epsilon.w); -} + template + GLM_FUNC_QUALIFIER detail::tvec4 equalEpsilon + ( + detail::tquat const & x, + detail::tquat const & y, + detail::tquat const & epsilon + ) + { + return detail::tvec4( + abs(x.x - y.x) < epsilon.x, + abs(x.y - y.y) < epsilon.y, + abs(x.z - y.z) < epsilon.z, + abs(x.w - y.w) < epsilon.w); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 notEqualEpsilon -( - detail::tvec2 const & x, - detail::tvec2 const & y, - detail::tvec2 const & epsilon -) -{ - return detail::tvec2( - abs(x.x - y.x) >= epsilon.x, - abs(x.y - y.y) >= epsilon.y); -} + template + GLM_FUNC_QUALIFIER detail::tvec2 notEqualEpsilon + ( + detail::tvec2 const & x, + detail::tvec2 const & y, + detail::tvec2 const & epsilon + ) + { + return detail::tvec2( + abs(x.x - y.x) >= epsilon.x, + abs(x.y - y.y) >= epsilon.y); + } -template -GLM_FUNC_QUALIFIER detail::tvec3 notEqualEpsilon -( - detail::tvec3 const & x, - detail::tvec3 const & y, - detail::tvec3 const & epsilon -) -{ - return detail::tvec3( - abs(x.x - y.x) >= epsilon.x, - abs(x.y - y.y) >= epsilon.y, - abs(x.z - y.z) >= epsilon.z); -} + template + GLM_FUNC_QUALIFIER detail::tvec3 notEqualEpsilon + ( + detail::tvec3 const & x, + detail::tvec3 const & y, + detail::tvec3 const & epsilon + ) + { + return detail::tvec3( + abs(x.x - y.x) >= epsilon.x, + abs(x.y - y.y) >= epsilon.y, + abs(x.z - y.z) >= epsilon.z); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 notEqualEpsilon -( - detail::tvec4 const & x, - detail::tvec4 const & y, - detail::tvec4 const & epsilon -) -{ - return detail::tvec4( - abs(x.x - y.x) >= epsilon.x, - abs(x.y - y.y) >= epsilon.y, - abs(x.z - y.z) >= epsilon.z, - abs(x.w - y.w) >= epsilon.w); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 notEqualEpsilon -( - detail::tquat const & x, - detail::tquat const & y, - detail::tquat const & epsilon -) -{ - return detail::tvec4( - abs(x.x - y.x) >= epsilon.x, - abs(x.y - y.y) >= epsilon.y, - abs(x.z - y.z) >= epsilon.z, - abs(x.w - y.w) >= epsilon.w); -} + template + GLM_FUNC_QUALIFIER detail::tvec4 notEqualEpsilon + ( + detail::tvec4 const & x, + detail::tvec4 const & y, + detail::tvec4 const & epsilon + ) + { + return detail::tvec4( + abs(x.x - y.x) >= epsilon.x, + abs(x.y - y.y) >= epsilon.y, + abs(x.z - y.z) >= epsilon.z, + abs(x.w - y.w) >= epsilon.w); + } + template + GLM_FUNC_QUALIFIER detail::tvec4 notEqualEpsilon + ( + detail::tquat const & x, + detail::tquat const & y, + detail::tquat const & epsilon + ) + { + return detail::tvec4( + abs(x.x - y.x) >= epsilon.x, + abs(x.y - y.y) >= epsilon.y, + abs(x.z - y.z) >= epsilon.z, + abs(x.w - y.w) >= epsilon.w); + } }//namespace glm diff --git a/glm/gtx/euler_angles.inl b/glm/gtx/euler_angles.inl index 22d70052..3322e410 100644 --- a/glm/gtx/euler_angles.inl +++ b/glm/gtx/euler_angles.inl @@ -7,239 +7,238 @@ // File : glm/gtx/euler_angles.inl /////////////////////////////////////////////////////////////////////////////////////////////////// -namespace glm{ - -template -GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleX -( - valType const & angleX -) +namespace glm { - valType cosX = glm::cos(angleX); - valType sinX = glm::sin(angleX); + template + GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleX + ( + valType const & angleX + ) + { + valType cosX = glm::cos(angleX); + valType sinX = glm::sin(angleX); - return detail::tmat4x4( - valType(1), valType(0), valType(0), valType(0), - valType(0), cosX, sinX, valType(0), - valType(0),-sinX, cosX, valType(0), - valType(0), valType(0), valType(0), valType(1)); -} + return detail::tmat4x4( + valType(1), valType(0), valType(0), valType(0), + valType(0), cosX, sinX, valType(0), + valType(0),-sinX, cosX, valType(0), + valType(0), valType(0), valType(0), valType(1)); + } -template -GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleY -( - valType const & angleY -) -{ - valType cosY = glm::cos(angleY); - valType sinY = glm::sin(angleY); + template + GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleY + ( + valType const & angleY + ) + { + valType cosY = glm::cos(angleY); + valType sinY = glm::sin(angleY); - return detail::tmat4x4( - cosY, valType(0), sinY, valType(0), - valType(0), valType(1), valType(0), valType(0), - -sinY, valType(0), cosY, valType(0), - valType(0), valType(0), valType(0), valType(1)); -} + return detail::tmat4x4( + cosY, valType(0), sinY, valType(0), + valType(0), valType(1), valType(0), valType(0), + -sinY, valType(0), cosY, valType(0), + valType(0), valType(0), valType(0), valType(1)); + } -template -GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleZ -( - valType const & angleZ -) -{ - valType cosZ = glm::cos(angleZ); - valType sinZ = glm::sin(angleZ); + template + GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleZ + ( + valType const & angleZ + ) + { + valType cosZ = glm::cos(angleZ); + valType sinZ = glm::sin(angleZ); - return detail::tmat4x4( - cosZ, sinZ, valType(0), valType(0), - -sinZ, cosZ, valType(0), valType(0), - valType(0), valType(0), valType(1), valType(0), - valType(0), valType(0), valType(0), valType(1)); -} + return detail::tmat4x4( + cosZ, sinZ, valType(0), valType(0), + -sinZ, cosZ, valType(0), valType(0), + valType(0), valType(0), valType(1), valType(0), + valType(0), valType(0), valType(0), valType(1)); + } -template -GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleXY -( - valType const & angleX, - valType const & angleY -) -{ - valType cosX = glm::cos(angleX); - valType sinX = glm::sin(angleX); - valType cosY = glm::cos(angleY); - valType sinY = glm::sin(angleY); + template + GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleXY + ( + valType const & angleX, + valType const & angleY + ) + { + valType cosX = glm::cos(angleX); + valType sinX = glm::sin(angleX); + valType cosY = glm::cos(angleY); + valType sinY = glm::sin(angleY); - return detail::tmat4x4( - cosY, -sinX * sinY, cosX * sinY, valType(0), - valType(0), cosX, sinX, valType(0), - -sinY , -sinX * cosY, cosX * cosY, valType(0), - valType(0), valType(0), valType(0), valType(1)); -} + return detail::tmat4x4( + cosY, -sinX * sinY, cosX * sinY, valType(0), + valType(0), cosX, sinX, valType(0), + -sinY , -sinX * cosY, cosX * cosY, valType(0), + valType(0), valType(0), valType(0), valType(1)); + } -template -GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleYX -( - valType const & angleY, - valType const & angleX -) -{ - valType cosX = glm::cos(angleX); - valType sinX = glm::sin(angleX); - valType cosY = glm::cos(angleY); - valType sinY = glm::sin(angleY); + template + GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleYX + ( + valType const & angleY, + valType const & angleX + ) + { + valType cosX = glm::cos(angleX); + valType sinX = glm::sin(angleX); + valType cosY = glm::cos(angleY); + valType sinY = glm::sin(angleY); - return detail::tmat4x4( - cosY, valType(0), sinY, valType(0), - -sinX * sinY, cosX, sinX * cosY, valType(0), - -cosX * sinY, -sinX, cosX * cosY, valType(0), - valType(0), valType(0), valType(0), valType(1)); -} + return detail::tmat4x4( + cosY, valType(0), sinY, valType(0), + -sinX * sinY, cosX, sinX * cosY, valType(0), + -cosX * sinY, -sinX, cosX * cosY, valType(0), + valType(0), valType(0), valType(0), valType(1)); + } -template -GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleXZ -( - valType const & angleX, - valType const & angleZ -) -{ - return eulerAngleX(angleX) * eulerAngleZ(angleZ); -} + template + GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleXZ + ( + valType const & angleX, + valType const & angleZ + ) + { + return eulerAngleX(angleX) * eulerAngleZ(angleZ); + } -template -GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleZX -( - valType const & angleZ, - valType const & angleX -) -{ - return eulerAngleZ(angleZ) * eulerAngleX(angleX); -} + template + GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleZX + ( + valType const & angleZ, + valType const & angleX + ) + { + return eulerAngleZ(angleZ) * eulerAngleX(angleX); + } -template -GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleYXZ -( - valType const & yaw, - valType const & pitch, - valType const & roll -) -{ - valType tmp_ch = glm::cos(yaw); - valType tmp_sh = glm::sin(yaw); - valType tmp_cp = glm::cos(pitch); - valType tmp_sp = glm::sin(pitch); - valType tmp_cb = glm::cos(roll); - valType tmp_sb = glm::sin(roll); + template + GLM_FUNC_QUALIFIER detail::tmat4x4 eulerAngleYXZ + ( + valType const & yaw, + valType const & pitch, + valType const & roll + ) + { + valType tmp_ch = glm::cos(yaw); + valType tmp_sh = glm::sin(yaw); + valType tmp_cp = glm::cos(pitch); + valType tmp_sp = glm::sin(pitch); + valType tmp_cb = glm::cos(roll); + valType tmp_sb = glm::sin(roll); - detail::tmat4x4 Result; - Result[0][0] = tmp_ch * tmp_cb + tmp_sh * tmp_sp * tmp_sb; - Result[0][1] = tmp_sb * tmp_cp; - Result[0][2] = -tmp_sh * tmp_cb + tmp_ch * tmp_sp * tmp_sb; - Result[0][3] = valType(0); - Result[1][0] = -tmp_ch * tmp_sb + tmp_sh * tmp_sp * tmp_cb; - Result[1][1] = tmp_cb * tmp_cp; - Result[1][2] = tmp_sb * tmp_sh + tmp_ch * tmp_sp * tmp_cb; - Result[1][3] = valType(0); - Result[2][0] = tmp_sh * tmp_cp; - Result[2][1] = -tmp_sp; - Result[2][2] = tmp_ch * tmp_cp; - Result[2][3] = valType(0); - Result[3][0] = valType(0); - Result[3][1] = valType(0); - Result[3][2] = valType(0); - Result[3][3] = valType(1); - return Result; -} + detail::tmat4x4 Result; + Result[0][0] = tmp_ch * tmp_cb + tmp_sh * tmp_sp * tmp_sb; + Result[0][1] = tmp_sb * tmp_cp; + Result[0][2] = -tmp_sh * tmp_cb + tmp_ch * tmp_sp * tmp_sb; + Result[0][3] = valType(0); + Result[1][0] = -tmp_ch * tmp_sb + tmp_sh * tmp_sp * tmp_cb; + Result[1][1] = tmp_cb * tmp_cp; + Result[1][2] = tmp_sb * tmp_sh + tmp_ch * tmp_sp * tmp_cb; + Result[1][3] = valType(0); + Result[2][0] = tmp_sh * tmp_cp; + Result[2][1] = -tmp_sp; + Result[2][2] = tmp_ch * tmp_cp; + Result[2][3] = valType(0); + Result[3][0] = valType(0); + Result[3][1] = valType(0); + Result[3][2] = valType(0); + Result[3][3] = valType(1); + return Result; + } -template -GLM_FUNC_QUALIFIER detail::tmat4x4 yawPitchRoll -( - valType const & yaw, - valType const & pitch, - valType const & roll -) -{ - valType tmp_ch = glm::cos(yaw); - valType tmp_sh = glm::sin(yaw); - valType tmp_cp = glm::cos(pitch); - valType tmp_sp = glm::sin(pitch); - valType tmp_cb = glm::cos(roll); - valType tmp_sb = glm::sin(roll); + template + GLM_FUNC_QUALIFIER detail::tmat4x4 yawPitchRoll + ( + valType const & yaw, + valType const & pitch, + valType const & roll + ) + { + valType tmp_ch = glm::cos(yaw); + valType tmp_sh = glm::sin(yaw); + valType tmp_cp = glm::cos(pitch); + valType tmp_sp = glm::sin(pitch); + valType tmp_cb = glm::cos(roll); + valType tmp_sb = glm::sin(roll); - detail::tmat4x4 Result; - Result[0][0] = tmp_ch * tmp_cb + tmp_sh * tmp_sp * tmp_sb; - Result[0][1] = tmp_sb * tmp_cp; - Result[0][2] = -tmp_sh * tmp_cb + tmp_ch * tmp_sp * tmp_sb; - Result[0][3] = valType(0); - Result[1][0] = -tmp_ch * tmp_sb + tmp_sh * tmp_sp * tmp_cb; - Result[1][1] = tmp_cb * tmp_cp; - Result[1][2] = tmp_sb * tmp_sh + tmp_ch * tmp_sp * tmp_cb; - Result[1][3] = valType(0); - Result[2][0] = tmp_sh * tmp_cp; - Result[2][1] = -tmp_sp; - Result[2][2] = tmp_ch * tmp_cp; - Result[2][3] = valType(0); - Result[3][0] = valType(0); - Result[3][1] = valType(0); - Result[3][2] = valType(0); - Result[3][3] = valType(1); - return Result; -} + detail::tmat4x4 Result; + Result[0][0] = tmp_ch * tmp_cb + tmp_sh * tmp_sp * tmp_sb; + Result[0][1] = tmp_sb * tmp_cp; + Result[0][2] = -tmp_sh * tmp_cb + tmp_ch * tmp_sp * tmp_sb; + Result[0][3] = valType(0); + Result[1][0] = -tmp_ch * tmp_sb + tmp_sh * tmp_sp * tmp_cb; + Result[1][1] = tmp_cb * tmp_cp; + Result[1][2] = tmp_sb * tmp_sh + tmp_ch * tmp_sp * tmp_cb; + Result[1][3] = valType(0); + Result[2][0] = tmp_sh * tmp_cp; + Result[2][1] = -tmp_sp; + Result[2][2] = tmp_ch * tmp_cp; + Result[2][3] = valType(0); + Result[3][0] = valType(0); + Result[3][1] = valType(0); + Result[3][2] = valType(0); + Result[3][3] = valType(1); + return Result; + } -template -GLM_FUNC_QUALIFIER detail::tmat2x2 orientate2 -( - valType const & angle -) -{ - valType c = glm::cos(angle); - valType s = glm::sin(angle); + template + GLM_FUNC_QUALIFIER detail::tmat2x2 orientate2 + ( + valType const & angle + ) + { + valType c = glm::cos(angle); + valType s = glm::sin(angle); - detail::tmat2x2 Result; - Result[0][0] = c; - Result[0][1] = s; - Result[1][0] = -s; - Result[1][1] = c; - return Result; -} + detail::tmat2x2 Result; + Result[0][0] = c; + Result[0][1] = s; + Result[1][0] = -s; + Result[1][1] = c; + return Result; + } -template -GLM_FUNC_QUALIFIER detail::tmat3x3 orientate3 -( - valType const & angle -) -{ - valType c = glm::cos(angle); - valType s = glm::sin(angle); + template + GLM_FUNC_QUALIFIER detail::tmat3x3 orientate3 + ( + valType const & angle + ) + { + valType c = glm::cos(angle); + valType s = glm::sin(angle); - detail::tmat3x3 Result; - Result[0][0] = c; - Result[0][1] = s; - Result[0][2] = 0.0f; - Result[1][0] = -s; - Result[1][1] = c; - Result[1][2] = 0.0f; - Result[2][0] = 0.0f; - Result[2][1] = 0.0f; - Result[2][2] = 1.0f; - return Result; -} + detail::tmat3x3 Result; + Result[0][0] = c; + Result[0][1] = s; + Result[0][2] = 0.0f; + Result[1][0] = -s; + Result[1][1] = c; + Result[1][2] = 0.0f; + Result[2][0] = 0.0f; + Result[2][1] = 0.0f; + Result[2][2] = 1.0f; + return Result; + } -template -GLM_FUNC_QUALIFIER detail::tmat3x3 orientate3 -( - detail::tvec3 const & angles -) -{ - return detail::tmat3x3(yawPitchRoll(angles.x, angles.y, angles.z)); -} - -template -GLM_FUNC_QUALIFIER detail::tmat4x4 orientate4 -( - detail::tvec3 const & angles -) -{ - return yawPitchRoll(angles.z, angles.x, angles.y); -} + template + GLM_FUNC_QUALIFIER detail::tmat3x3 orientate3 + ( + detail::tvec3 const & angles + ) + { + return detail::tmat3x3(yawPitchRoll(angles.x, angles.y, angles.z)); + } + template + GLM_FUNC_QUALIFIER detail::tmat4x4 orientate4 + ( + detail::tvec3 const & angles + ) + { + return yawPitchRoll(angles.z, angles.x, angles.y); + } }//namespace glm diff --git a/glm/gtx/extend.inl b/glm/gtx/extend.inl index 0e094fb2..97f1c0c0 100644 --- a/glm/gtx/extend.inl +++ b/glm/gtx/extend.inl @@ -7,50 +7,49 @@ // File : glm/gtx/extend.inl /////////////////////////////////////////////////////////////////////////////////////////////////// -namespace glm{ - -template -genType extend -( - genType const & Origin, - genType const & Source, - genType const & Distance -) +namespace glm { - return Origin + (Source - Origin) * Distance; -} + template + genType extend + ( + genType const & Origin, + genType const & Source, + genType const & Distance + ) + { + return Origin + (Source - Origin) * Distance; + } -template -detail::tvec2 extend -( - detail::tvec2 const & Origin, - detail::tvec2 const & Source, - valType const & Distance -) -{ - return Origin + (Source - Origin) * Distance; -} + template + detail::tvec2 extend + ( + detail::tvec2 const & Origin, + detail::tvec2 const & Source, + valType const & Distance + ) + { + return Origin + (Source - Origin) * Distance; + } -template -detail::tvec3 extend -( - detail::tvec3 const & Origin, - detail::tvec3 const & Source, - valType const & Distance -) -{ - return Origin + (Source - Origin) * Distance; -} - -template -detail::tvec4 extend -( - detail::tvec4 const & Origin, - detail::tvec4 const & Source, - valType const & Distance -) -{ - return Origin + (Source - Origin) * Distance; -} + template + detail::tvec3 extend + ( + detail::tvec3 const & Origin, + detail::tvec3 const & Source, + valType const & Distance + ) + { + return Origin + (Source - Origin) * Distance; + } + template + detail::tvec4 extend + ( + detail::tvec4 const & Origin, + detail::tvec4 const & Source, + valType const & Distance + ) + { + return Origin + (Source - Origin) * Distance; + } }//namespace glm diff --git a/glm/gtx/fast_exponential.hpp b/glm/gtx/fast_exponential.hpp index 993ef48f..83cda03a 100644 --- a/glm/gtx/fast_exponential.hpp +++ b/glm/gtx/fast_exponential.hpp @@ -54,17 +54,17 @@ namespace glm //! Faster than the common pow function but less accurate. //! From GLM_GTX_fast_exponential extension. - template - valType fastPow( - valType const & x, - valType const & y); + template + genType fastPow( + genType const & x, + genType const & y); //! Faster than the common pow function but less accurate. //! From GLM_GTX_fast_exponential extension. - template - T fastPow( - const T& x, - const U& y); + template + genType fastPow( + genTypeT const & x, + genTypeU const & y); //! Faster than the common exp function but less accurate. //! From GLM_GTX_fast_exponential extension. diff --git a/glm/gtx/fast_exponential.inl b/glm/gtx/fast_exponential.inl index 37d6cd5f..519d3974 100644 --- a/glm/gtx/fast_exponential.inl +++ b/glm/gtx/fast_exponential.inl @@ -7,284 +7,144 @@ // File : glm/gtx/fast_exponential.inl /////////////////////////////////////////////////////////////////////////////////////////////////// -namespace glm{ +#include "../core/_vectorize.hpp" -// fastPow: -template -GLM_FUNC_QUALIFIER T fastPow(const T x, const T y) +namespace glm { - return exp(y * log(x)); -} + // fastPow: + template + GLM_FUNC_QUALIFIER genType fastPow(genType const & x, genType const & y) + { + return exp(y * log(x)); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 fastPow( - const detail::tvec2& x, - const detail::tvec2& y) -{ - return detail::tvec2( - fastPow(x.x, y.x), - fastPow(x.y, y.y)); -} + VECTORIZE_VEC_VEC(fastPow) -template -GLM_FUNC_QUALIFIER detail::tvec3 fastPow( - const detail::tvec3& x, - const detail::tvec3& y) -{ - return detail::tvec3( - fastPow(x.x, y.x), - fastPow(x.y, y.y), - fastPow(x.z, y.z)); -} + template + GLM_FUNC_QUALIFIER T fastPow(const T x, int y) + { + T f = T(1); + for(int i = 0; i < y; ++i) + f *= x; + return f; + } -template -GLM_FUNC_QUALIFIER detail::tvec4 fastPow( - const detail::tvec4& x, - const detail::tvec4& y) -{ - return detail::tvec4( - fastPow(x.x, y.x), - fastPow(x.y, y.y), - fastPow(x.z, y.z), - fastPow(x.w, y.w)); -} + template + GLM_FUNC_QUALIFIER detail::tvec2 fastPow( + const detail::tvec2& x, + const detail::tvec2& y) + { + return detail::tvec2( + fastPow(x.x, y.x), + fastPow(x.y, y.y)); + } -template -GLM_FUNC_QUALIFIER T fastPow(const T x, int y) -{ - T f = T(1); - for(int i = 0; i < y; ++i) - f *= x; - return f; -} + template + GLM_FUNC_QUALIFIER detail::tvec3 fastPow( + const detail::tvec3& x, + const detail::tvec3& y) + { + return detail::tvec3( + fastPow(x.x, y.x), + fastPow(x.y, y.y), + fastPow(x.z, y.z)); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 fastPow( - const detail::tvec2& x, - const detail::tvec2& y) -{ - return detail::tvec2( - fastPow(x.x, y.x), - fastPow(x.y, y.y)); -} + template + GLM_FUNC_QUALIFIER detail::tvec4 fastPow( + const detail::tvec4& x, + const detail::tvec4& y) + { + return detail::tvec4( + fastPow(x.x, y.x), + fastPow(x.y, y.y), + fastPow(x.z, y.z), + fastPow(x.w, y.w)); + } -template -GLM_FUNC_QUALIFIER detail::tvec3 fastPow( - const detail::tvec3& x, - const detail::tvec3& y) -{ - return detail::tvec3( - fastPow(x.x, y.x), - fastPow(x.y, y.y), - fastPow(x.z, y.z)); -} + // fastExp + // Note: This function provides accurate results only for value between -1 and 1, else avoid it. + template + GLM_FUNC_QUALIFIER T fastExp(const T x) + { + // This has a better looking and same performance in release mode than the following code. However, in debug mode it's slower. + // return 1.0f + x * (1.0f + x * 0.5f * (1.0f + x * 0.3333333333f * (1.0f + x * 0.25 * (1.0f + x * 0.2f)))); + T x2 = x * x; + T x3 = x2 * x; + T x4 = x3 * x; + T x5 = x4 * x; + return T(1) + x + (x2 * T(0.5)) + (x3 * T(0.1666666667)) + (x4 * T(0.041666667)) + (x5 * T(0.008333333333)); + } + /* // Try to handle all values of float... but often shower than std::exp, glm::floor and the loop kill the performance + GLM_FUNC_QUALIFIER float fastExp(float x) + { + const float e = 2.718281828f; + const float IntegerPart = floor(x); + const float FloatPart = x - IntegerPart; + float z = 1.f; -template -GLM_FUNC_QUALIFIER detail::tvec4 fastPow( - const detail::tvec4& x, - const detail::tvec4& y) -{ - return detail::tvec4( - fastPow(x.x, y.x), - fastPow(x.y, y.y), - fastPow(x.z, y.z), - fastPow(x.w, y.w)); -} + for(int i = 0; i < int(IntegerPart); ++i) + z *= e; -// fastExp -// Note: This function provides accurate results only for value between -1 and 1, else avoid it. -template -GLM_FUNC_QUALIFIER T fastExp(const T x) -{ - // This has a better looking and same performance in release mode than the following code. However, in debug mode it's slower. - // return 1.0f + x * (1.0f + x * 0.5f * (1.0f + x * 0.3333333333f * (1.0f + x * 0.25 * (1.0f + x * 0.2f)))); - T x2 = x * x; - T x3 = x2 * x; - T x4 = x3 * x; - T x5 = x4 * x; - return T(1) + x + (x2 * T(0.5)) + (x3 * T(0.1666666667)) + (x4 * T(0.041666667)) + (x5 * T(0.008333333333)); -} -/* // Try to handle all values of float... but often shower than std::exp, glm::floor and the loop kill the performance -GLM_FUNC_QUALIFIER float fastExp(float x) -{ - const float e = 2.718281828f; - const float IntegerPart = floor(x); - const float FloatPart = x - IntegerPart; - float z = 1.f; + const float x2 = FloatPart * FloatPart; + const float x3 = x2 * FloatPart; + const float x4 = x3 * FloatPart; + const float x5 = x4 * FloatPart; + return z * (1.0f + FloatPart + (x2 * 0.5f) + (x3 * 0.1666666667f) + (x4 * 0.041666667f) + (x5 * 0.008333333333f)); + } - for(int i = 0; i < int(IntegerPart); ++i) - z *= e; + // Increase accuracy on number bigger that 1 and smaller than -1 but it's not enough for high and negative numbers + GLM_FUNC_QUALIFIER float fastExp(float x) + { + // This has a better looking and same performance in release mode than the following code. However, in debug mode it's slower. + // return 1.0f + x * (1.0f + x * 0.5f * (1.0f + x * 0.3333333333f * (1.0f + x * 0.25 * (1.0f + x * 0.2f)))); + float x2 = x * x; + float x3 = x2 * x; + float x4 = x3 * x; + float x5 = x4 * x; + float x6 = x5 * x; + float x7 = x6 * x; + float x8 = x7 * x; + return 1.0f + x + (x2 * 0.5f) + (x3 * 0.1666666667f) + (x4 * 0.041666667f) + (x5 * 0.008333333333f)+ (x6 * 0.00138888888888f) + (x7 * 0.000198412698f) + (x8 * 0.0000248015873f);; + } + */ - const float x2 = FloatPart * FloatPart; - const float x3 = x2 * FloatPart; - const float x4 = x3 * FloatPart; - const float x5 = x4 * FloatPart; - return z * (1.0f + FloatPart + (x2 * 0.5f) + (x3 * 0.1666666667f) + (x4 * 0.041666667f) + (x5 * 0.008333333333f)); -} + VECTORIZE_VEC(fastExp) -// Increase accuracy on number bigger that 1 and smaller than -1 but it's not enough for high and negative numbers -GLM_FUNC_QUALIFIER float fastExp(float x) -{ - // This has a better looking and same performance in release mode than the following code. However, in debug mode it's slower. - // return 1.0f + x * (1.0f + x * 0.5f * (1.0f + x * 0.3333333333f * (1.0f + x * 0.25 * (1.0f + x * 0.2f)))); - float x2 = x * x; - float x3 = x2 * x; - float x4 = x3 * x; - float x5 = x4 * x; - float x6 = x5 * x; - float x7 = x6 * x; - float x8 = x7 * x; - return 1.0f + x + (x2 * 0.5f) + (x3 * 0.1666666667f) + (x4 * 0.041666667f) + (x5 * 0.008333333333f)+ (x6 * 0.00138888888888f) + (x7 * 0.000198412698f) + (x8 * 0.0000248015873f);; -} -*/ -template -GLM_FUNC_QUALIFIER detail::tvec2 fastExp( - const detail::tvec2& x) -{ - return detail::tvec2( - fastExp(x.x), - fastExp(x.y)); -} + // fastLog + template + GLM_FUNC_QUALIFIER genType fastLog(genType const & x) + { + return std::log(x); + } -template -GLM_FUNC_QUALIFIER detail::tvec3 fastExp( - const detail::tvec3& x) -{ - return detail::tvec3( - fastExp(x.x), - fastExp(x.y), - fastExp(x.z)); -} + /* Slower than the VC7.1 function... + GLM_FUNC_QUALIFIER float fastLog(float x) + { + float y1 = (x - 1.0f) / (x + 1.0f); + float y2 = y1 * y1; + return 2.0f * y1 * (1.0f + y2 * (0.3333333333f + y2 * (0.2f + y2 * 0.1428571429f))); + } + */ -template -GLM_FUNC_QUALIFIER detail::tvec4 fastExp( - const detail::tvec4& x) -{ - return detail::tvec4( - fastExp(x.x), - fastExp(x.y), - fastExp(x.z), - fastExp(x.w)); -} + VECTORIZE_VEC(fastLog) -// fastLog -template -GLM_FUNC_QUALIFIER T fastLog(const T x) -{ - return std::log(x); -} + //fastExp2, ln2 = 0.69314718055994530941723212145818f + template + GLM_FUNC_QUALIFIER genType fastExp2(genType const & x) + { + return fastExp(0.69314718055994530941723212145818f * x); + } -/* Slower than the VC7.1 function... -GLM_FUNC_QUALIFIER float fastLog(float x) -{ - float y1 = (x - 1.0f) / (x + 1.0f); - float y2 = y1 * y1; - return 2.0f * y1 * (1.0f + y2 * (0.3333333333f + y2 * (0.2f + y2 * 0.1428571429f))); -} -*/ + VECTORIZE_VEC(fastExp2) -template -GLM_FUNC_QUALIFIER detail::tvec2 fastLog( - const detail::tvec2& x) -{ - return detail::tvec2( - fastLog(x.x), - fastLog(x.y)); -} + // fastLog2, ln2 = 0.69314718055994530941723212145818f + template + GLM_FUNC_QUALIFIER genType fastLog2(genType const & x) + { + return fastLog(x) / 0.69314718055994530941723212145818f; + } -template -GLM_FUNC_QUALIFIER detail::tvec3 fastLog( - const detail::tvec3& x) -{ - return detail::tvec3( - fastLog(x.x), - fastLog(x.y), - fastLog(x.z)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 fastLog( - const detail::tvec4& x) -{ - return detail::tvec4( - fastLog(x.x), - fastLog(x.y), - fastLog(x.z), - fastLog(x.w)); -} - -//fastExp2, ln2 = 0.69314718055994530941723212145818f -template -GLM_FUNC_QUALIFIER T fastExp2(const T x) -{ - return fastExp(0.69314718055994530941723212145818f * x); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 fastExp2( - const detail::tvec2& x) -{ - return detail::tvec2( - fastExp2(x.x), - fastExp2(x.y)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 fastExp2( - const detail::tvec3& x) -{ - return detail::tvec3( - fastExp2(x.x), - fastExp2(x.y), - fastExp2(x.z)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 fastExp2( - const detail::tvec4& x) -{ - return detail::tvec4( - fastExp2(x.x), - fastExp2(x.y), - fastExp2(x.z), - fastExp2(x.w)); -} - -// fastLog2, ln2 = 0.69314718055994530941723212145818f -template -GLM_FUNC_QUALIFIER T fastLog2(const T x) -{ - return fastLog(x) / 0.69314718055994530941723212145818f; -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 fastLog2( - const detail::tvec2& x) -{ - return detail::tvec2( - fastLog2(x.x), - fastLog2(x.y)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 fastLog2( - const detail::tvec3& x) -{ - return detail::tvec3( - fastLog2(x.x), - fastLog2(x.y), - fastLog2(x.z)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 fastLog2( - const detail::tvec4& x) -{ - return detail::tvec4( - fastLog2(x.x), - fastLog2(x.y), - fastLog2(x.z), - fastLog2(x.w)); -} + VECTORIZE_VEC(fastLog2) }//namespace glm