This commit is contained in:
Christophe Riccio 2014-01-18 03:19:46 +01:00
commit 49cc8e83e4
7 changed files with 99 additions and 243 deletions

View File

@ -258,6 +258,18 @@ namespace glm
/// glm::dvec3 t = glm::mix(e, f, a); // Types of the third parameter is not required to match with the first and the second. /// glm::dvec3 t = glm::mix(e, f, a); // Types of the third parameter is not required to match with the first and the second.
/// glm::vec4 u = glm::mix(g, h, r); // Interpolations can be perform per component with a vector for the last parameter. /// glm::vec4 u = glm::mix(g, h, r); // Interpolations can be perform per component with a vector for the last parameter.
/// @endcode /// @endcode
template <typename T, typename U, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> mix(
vecType<T, P> const & x,
vecType<T, P> const & y,
vecType<U, P> const & a);
template <typename T, typename U, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> mix(
vecType<T, P> const & x,
vecType<T, P> const & y,
U const & a);
template <typename genTypeT, typename genTypeU> template <typename genTypeT, typename genTypeU>
GLM_FUNC_DECL genTypeT mix( GLM_FUNC_DECL genTypeT mix(
genTypeT const & x, genTypeT const & x,

View File

@ -64,6 +64,63 @@ namespace detail
return x; return x;
} }
}; };
template <typename T, typename U, precision P, template <class, precision> class vecType>
struct compute_mix_vector
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & x, vecType<T, P> const & y, vecType<U, P> const & a)
{
return vecType<T, P>(vecType<U, P>(x) + a * vecType<U, P>(y - x));
}
};
template <typename T, precision P, template <class, precision> class vecType>
struct compute_mix_vector<T, bool, P, vecType>
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & x, vecType<T, P> const & y, vecType<bool, P> const & a)
{
vecType<T, P> Result;
for(length_t i = 0; i < x.length(); ++i)
Result[i] = a[i] ? y[i] : x[i];
return Result;
}
};
template <typename T, typename U, precision P, template <class, precision> class vecType>
struct compute_mix_scalar
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & x, vecType<T, P> const & y, U const & a)
{
return vecType<T, P>(vecType<U, P>(x) + a * vecType<U, P>(y - x));
}
};
template <typename T, precision P, template <class, precision> class vecType>
struct compute_mix_scalar<T, bool, P, vecType>
{
GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & x, vecType<T, P> const & y, bool const & a)
{
return a ? y : x;
}
};
template <typename T, typename U>
struct compute_mix
{
GLM_FUNC_QUALIFIER static T call(T const & x, T const & y, U const & a)
{
return static_cast<T>(static_cast<U>(x) + a * static_cast<U>(y - x));
}
};
template <typename T>
struct compute_mix<T, bool>
{
GLM_FUNC_QUALIFIER static T call(T const & x, T const & y, bool const & a)
{
return a ? y : x;
}
};
}//namespace detail }//namespace detail
// abs // abs
@ -459,250 +516,37 @@ namespace detail
clamp(x.w, minVal.w, maxVal.w)); clamp(x.w, minVal.w, maxVal.w));
} }
// mix template <typename T, typename U, precision P, template <typename, precision> class vecType>
template <typename genType> GLM_FUNC_QUALIFIER vecType<T, P> mix
GLM_FUNC_QUALIFIER genType mix
( (
genType const & x, vecType<T, P> const & x,
genType const & y, vecType<T, P> const & y,
genType const & a vecType<U, P> const & a
) )
{ {
GLM_STATIC_ASSERT( return detail::compute_mix_vector<T, U, P, vecType>::call(x, y, a);
std::numeric_limits<genType>::is_iec559,
"'mix' only accept floating-point inputs");
return x + a * (y - x);
} }
template <typename T, precision P> template <typename T, typename U, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER detail::tvec2<T, P> mix GLM_FUNC_QUALIFIER vecType<T, P> mix
( (
detail::tvec2<T, P> const & x, vecType<T, P> const & x,
detail::tvec2<T, P> const & y, vecType<T, P> const & y,
T const & a U const & a
) )
{ {
GLM_STATIC_ASSERT( return detail::compute_mix_scalar<T, U, P, vecType>::call(x, y, a);
std::numeric_limits<T>::is_iec559,
"'mix' only accept floating-point inputs");
return x + a * (y - x);
} }
template <typename T, precision P> template <typename genTypeT, typename genTypeU>
GLM_FUNC_QUALIFIER detail::tvec3<T, P> mix GLM_FUNC_QUALIFIER genTypeT mix
( (
detail::tvec3<T, P> const & x, genTypeT const & x,
detail::tvec3<T, P> const & y, genTypeT const & y,
T const & a genTypeU const & a
) )
{ {
GLM_STATIC_ASSERT( return detail::compute_mix<genTypeT, genTypeU>::call(x, y, a);
std::numeric_limits<T>::is_iec559,
"'mix' only accept floating-point inputs");
return x + a * (y - x);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER detail::tvec4<T, P> mix
(
detail::tvec4<T, P> const & x,
detail::tvec4<T, P> const & y,
T const & a
)
{
GLM_STATIC_ASSERT(
std::numeric_limits<T>::is_iec559,
"'mix' only accept floating-point inputs");
return x + a * (y - x);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER detail::tvec2<T, P> mix
(
detail::tvec2<T, P> const & x,
detail::tvec2<T, P> const & y,
detail::tvec2<T, P> const & a
)
{
GLM_STATIC_ASSERT(
std::numeric_limits<T>::is_iec559,
"'mix' only accept floating-point inputs");
return x + a * (y - x);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER detail::tvec3<T, P> mix
(
detail::tvec3<T, P> const & x,
detail::tvec3<T, P> const & y,
detail::tvec3<T, P> const & a
)
{
GLM_STATIC_ASSERT(
std::numeric_limits<T>::is_iec559,
"'mix' only accept floating-point inputs");
return x + a * (y - x);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER detail::tvec4<T, P> mix
(
detail::tvec4<T, P> const & x,
detail::tvec4<T, P> const & y,
detail::tvec4<T, P> const & a
)
{
GLM_STATIC_ASSERT(
std::numeric_limits<T>::is_iec559,
"'mix' only accept floating-point inputs");
return x + a * (y - x);
}
//template <typename genTypeT>
//GLM_FUNC_QUALIFIER genTypeT mix
//(
// genTypeT const & x,
// genTypeT const & y,
// float const & a
//)
//{
// // It could be a vector too
// //GLM_STATIC_ASSERT(
// // detail::type<genTypeT>::is_float &&
// // detail::type<genTypeU>::is_float);
// return x + a * (y - x);
//}
template <>
GLM_FUNC_QUALIFIER float mix
(
float const & x,
float const & y,
bool const & a
)
{
return a ? y : x;
}
template <>
GLM_FUNC_QUALIFIER double mix
(
double const & x,
double const & y,
bool const & a
)
{
return a ? y : x;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER detail::tvec2<T, P> mix
(
detail::tvec2<T, P> const & x,
detail::tvec2<T, P> const & y,
bool a
)
{
GLM_STATIC_ASSERT(
std::numeric_limits<T>::is_iec559,
"'mix' only accept floating-point inputs");
return a ? y : x;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER detail::tvec3<T, P> mix
(
detail::tvec3<T, P> const & x,
detail::tvec3<T, P> const & y,
bool a
)
{
GLM_STATIC_ASSERT(
std::numeric_limits<T>::is_iec559,
"'mix' only accept floating-point inputs");
return a ? y : x;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER detail::tvec4<T, P> mix
(
detail::tvec4<T, P> const & x,
detail::tvec4<T, P> const & y,
bool a
)
{
GLM_STATIC_ASSERT(
std::numeric_limits<T>::is_iec559,
"'mix' only accept floating-point inputs");
return a ? y : x;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER detail::tvec2<T, P> mix
(
detail::tvec2<T, P> const & x,
detail::tvec2<T, P> const & y,
typename detail::tvec2<T, P>::bool_type a
)
{
GLM_STATIC_ASSERT(
std::numeric_limits<T>::is_iec559,
"'mix' only accept floating-point inputs");
detail::tvec2<T, P> result;
for(int i = 0; i < x.length(); ++i)
result[i] = a[i] ? y[i] : x[i];
return result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER detail::tvec3<T, P> mix
(
detail::tvec3<T, P> const & x,
detail::tvec3<T, P> const & y,
typename detail::tvec3<T, P>::bool_type a
)
{
GLM_STATIC_ASSERT(
std::numeric_limits<T>::is_iec559,
"'mix' only accept floating-point inputs");
detail::tvec3<T, P> result;
for(int i = 0; i < x.length(); ++i)
result[i] = a[i] ? y[i] : x[i];
return result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER detail::tvec4<T, P> mix
(
detail::tvec4<T, P> const & x,
detail::tvec4<T, P> const & y,
typename detail::tvec4<T, P>::bool_type a
)
{
GLM_STATIC_ASSERT(
std::numeric_limits<T>::is_iec559,
"'mix' only accept floating-point inputs");
detail::tvec4<T, P> result;
for(int i = 0; i < x.length(); ++i)
result[i] = a[i] ? y[i] : x[i];
return result;
} }
// step // step

View File

@ -668,7 +668,7 @@
#if(defined(GLM_MESSAGES) && !defined(GLM_MESSAGE_ARCH_DISPLAYED)) #if(defined(GLM_MESSAGES) && !defined(GLM_MESSAGE_ARCH_DISPLAYED))
# define GLM_MESSAGE_ARCH_DISPLAYED # define GLM_MESSAGE_ARCH_DISPLAYED
# if(GLM_ARCH == GLM_ARCH_PURE) # if(GLM_ARCH == GLM_ARCH_PURE)
# pragma message("GLM: Platform independent") # pragma message("GLM: Platform independent code")
# elif(GLM_ARCH & GLM_ARCH_AVX2) # elif(GLM_ARCH & GLM_ARCH_AVX2)
# pragma message("GLM: AVX2 instruction set") # pragma message("GLM: AVX2 instruction set")
# elif(GLM_ARCH & GLM_ARCH_AVX) # elif(GLM_ARCH & GLM_ARCH_AVX)

View File

@ -49,6 +49,8 @@ GLM 0.9.5.2: 2014-0X-XX
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
- Fixed warnings with the Android NDK 9c - Fixed warnings with the Android NDK 9c
- Fixed non power of two matrix products - Fixed non power of two matrix products
- Fixed mix function link error
- Fixed SSE code included in GLM tests on "pure" platforms
================================================================================ ================================================================================
GLM 0.9.5.1: 2014-01-11 GLM 0.9.5.1: 2014-01-11

View File

@ -11,7 +11,6 @@
#include <glm/gtx/bit.hpp> #include <glm/gtx/bit.hpp>
#include <glm/gtc/type_precision.hpp> #include <glm/gtc/type_precision.hpp>
#include <emmintrin.h>
#if(GLM_ARCH != GLM_ARCH_PURE) #if(GLM_ARCH != GLM_ARCH_PURE)
# include <glm/detail/intrinsic_integer.hpp> # include <glm/detail/intrinsic_integer.hpp>
#endif #endif
@ -152,6 +151,7 @@ namespace bitfieldInterleave
return REG1 | (REG2 << 1); return REG1 | (REG2 << 1);
} }
#if(GLM_ARCH != GLM_ARCH_PURE)
inline glm::uint64 sseBitfieldInterleave(glm::uint32 x, glm::uint32 y) inline glm::uint64 sseBitfieldInterleave(glm::uint32 x, glm::uint32 y)
{ {
GLM_ALIGN(16) glm::uint32 const Array[4] = {x, 0, y, 0}; GLM_ALIGN(16) glm::uint32 const Array[4] = {x, 0, y, 0};
@ -267,6 +267,7 @@ namespace bitfieldInterleave
return Result[0]; return Result[0];
} }
#endif//(GLM_ARCH != GLM_ARCH_PURE)
int test() int test()
{ {
@ -287,16 +288,17 @@ namespace bitfieldInterleave
glm::uint64 B = fastBitfieldInterleave(x, y); glm::uint64 B = fastBitfieldInterleave(x, y);
glm::uint64 C = loopBitfieldInterleave(x, y); glm::uint64 C = loopBitfieldInterleave(x, y);
glm::uint64 D = interleaveBitfieldInterleave(x, y); glm::uint64 D = interleaveBitfieldInterleave(x, y);
glm::uint64 E = sseBitfieldInterleave(x, y);
glm::uint64 F = sseUnalignedBitfieldInterleave(x, y);
assert(A == B); assert(A == B);
assert(A == C); assert(A == C);
assert(A == D); assert(A == D);
# if(GLM_ARCH != GLM_ARCH_PURE)
glm::uint64 E = sseBitfieldInterleave(x, y);
glm::uint64 F = sseUnalignedBitfieldInterleave(x, y);
assert(A == E); assert(A == E);
assert(A == F); assert(A == F);
# if(GLM_ARCH != GLM_ARCH_PURE)
__m128i G = glm::detail::_mm_bit_interleave_si128(_mm_set_epi32(0, y, 0, x)); __m128i G = glm::detail::_mm_bit_interleave_si128(_mm_set_epi32(0, y, 0, x));
glm::uint64 Result[2]; glm::uint64 Result[2];
_mm_storeu_si128((__m128i*)Result, G); _mm_storeu_si128((__m128i*)Result, G);
@ -366,6 +368,7 @@ namespace bitfieldInterleave
std::cout << "interleaveBitfieldInterleave Time " << Time << " clocks" << std::endl; std::cout << "interleaveBitfieldInterleave Time " << Time << " clocks" << std::endl;
} }
# if(GLM_ARCH != GLM_ARCH_PURE)
{ {
std::clock_t LastTime = std::clock(); std::clock_t LastTime = std::clock();
@ -387,6 +390,7 @@ namespace bitfieldInterleave
std::cout << "sseUnalignedBitfieldInterleave Time " << Time << " clocks" << std::endl; std::cout << "sseUnalignedBitfieldInterleave Time " << Time << " clocks" << std::endl;
} }
# endif//(GLM_ARCH != GLM_ARCH_PURE)
{ {
std::clock_t LastTime = std::clock(); std::clock_t LastTime = std::clock();

View File

@ -7,9 +7,6 @@
// File : test/gtx/associated_min_max.cpp // File : test/gtx/associated_min_max.cpp
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
#include <emmintrin.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_precision.hpp> #include <glm/gtc/type_precision.hpp>
#include <glm/gtx/associated_min_max.hpp> #include <glm/gtx/associated_min_max.hpp>

View File

@ -7,9 +7,6 @@
// File : test/gtx/associated_min_max.cpp // File : test/gtx/associated_min_max.cpp
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
#include <emmintrin.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_precision.hpp> #include <glm/gtc/type_precision.hpp>
#include <glm/gtx/associated_min_max.hpp> #include <glm/gtx/associated_min_max.hpp>