Vectorize many common functions

This commit is contained in:
Christophe Riccio 2014-10-25 00:08:10 +02:00
parent 50cead0793
commit f70ee7ef28
3 changed files with 159 additions and 253 deletions

View File

@ -42,7 +42,7 @@ namespace detail
template <typename R, typename T, precision P>
struct functor1<R, T, P, tvec1>
{
GLM_FUNC_QUALIFIER static tvec1<R, P> call(T (*Func) (T x), tvec1<T, P> const & v)
GLM_FUNC_QUALIFIER static tvec1<R, P> call(R (*Func) (T x), tvec1<T, P> const & v)
{
return tvec1<R, P>(Func(v.x));
}
@ -51,7 +51,7 @@ namespace detail
template <typename R, typename T, precision P>
struct functor1<R, T, P, tvec2>
{
GLM_FUNC_QUALIFIER static tvec2<R, P> call(T (*Func) (T x), tvec2<T, P> const & v)
GLM_FUNC_QUALIFIER static tvec2<R, P> call(R (*Func) (T x), tvec2<T, P> const & v)
{
return tvec2<R, P>(Func(v.x), Func(v.y));
}
@ -60,7 +60,7 @@ namespace detail
template <typename R, typename T, precision P>
struct functor1<R, T, P, tvec3>
{
GLM_FUNC_QUALIFIER static tvec3<R, P> call(T (*Func) (T x), tvec3<T, P> const & v)
GLM_FUNC_QUALIFIER static tvec3<R, P> call(R (*Func) (T x), tvec3<T, P> const & v)
{
return tvec3<R, P>(Func(v.x), Func(v.y), Func(v.z));
}
@ -69,7 +69,7 @@ namespace detail
template <typename R, typename T, precision P>
struct functor1<R, T, P, tvec4>
{
GLM_FUNC_QUALIFIER static tvec4<R, P> call(T (*Func) (T x), tvec4<T, P> const & v)
GLM_FUNC_QUALIFIER static tvec4<R, P> call(R (*Func) (T x), tvec4<T, P> const & v)
{
return tvec4<R, P>(Func(v.x), Func(v.y), Func(v.z), Func(v.w));
}
@ -113,6 +113,45 @@ namespace detail
return tvec4<T, P>(Func(a.x, b.x), Func(a.y, b.y), Func(a.z, b.z), Func(a.w, b.w));
}
};
template <typename T, precision P, template <typename, precision> class vecType>
struct functor2_vec_sca{};
template <typename T, precision P>
struct functor2_vec_sca<T, P, tvec1>
{
GLM_FUNC_QUALIFIER static tvec1<T, P> call(T (*Func) (T x, T y), tvec1<T, P> const & a, T b)
{
return tvec1<T, P>(Func(a.x, b));
}
};
template <typename T, precision P>
struct functor2_vec_sca<T, P, tvec2>
{
GLM_FUNC_QUALIFIER static tvec2<T, P> call(T (*Func) (T x, T y), tvec2<T, P> const & a, T b)
{
return tvec2<T, P>(Func(a.x, b), Func(a.y, b));
}
};
template <typename T, precision P>
struct functor2_vec_sca<T, P, tvec3>
{
GLM_FUNC_QUALIFIER static tvec3<T, P> call(T (*Func) (T x, T y), tvec3<T, P> const & a, T b)
{
return tvec3<T, P>(Func(a.x, b), Func(a.y, b), Func(a.z, b));
}
};
template <typename T, precision P>
struct functor2_vec_sca<T, P, tvec4>
{
GLM_FUNC_QUALIFIER static tvec4<T, P> call(T (*Func) (T x, T y), tvec4<T, P> const & a, T b)
{
return tvec4<T, P>(Func(a.x, b), Func(a.y, b), Func(a.z, b), Func(a.w, b));
}
};
}//namespace detail
}//namespace glm
@ -169,7 +208,7 @@ namespace detail
GLM_FUNC_QUALIFIER tvec1<T, P> func \
( \
tvec1<T, P> const & x, \
typename tvec1<T, P>::value_type const & y \
T y \
) \
{ \
return tvec1<T, P>( \

View File

@ -136,15 +136,11 @@ namespace glm
template <typename genType>
GLM_FUNC_DECL genType mod(genType x, genType y);
/// Modulus. Returns x - y * floor(x / y)
/// for each component in x using the floating point value y.
///
/// @tparam genType Floating-point scalar or vector types.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/mod.xml">GLSL mod man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
template <typename genType>
GLM_FUNC_DECL genType mod(genType const & x, typename genType::value_type const & y);
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> mod(vecType<T, P> const & x, T y);
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> mod(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns the fractional part of x and sets i to the integer
/// part (as a whole number floating point value). Both the
@ -156,7 +152,7 @@ namespace glm
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/modf.xml">GLSL modf man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
template <typename genType>
GLM_FUNC_DECL genType modf(genType const & x, genType & i);
GLM_FUNC_DECL genType modf(genType x, genType & i);
/// Returns y if y < x; otherwise, it returns x.
///
@ -167,8 +163,11 @@ namespace glm
template <typename genType>
GLM_FUNC_DECL genType min(genType x, genType y);
template <typename genType>
GLM_FUNC_DECL genType min(genType const & x, typename genType::value_type const & y);
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> min(vecType<T, P> const & x, T y);
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> min(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns y if x < y; otherwise, it returns x.
///
@ -179,8 +178,11 @@ namespace glm
template <typename genType>
GLM_FUNC_DECL genType max(genType x, genType y);
template <typename genType>
GLM_FUNC_DECL genType max(genType const & x, typename genType::value_type const & y);
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> max(vecType<T, P> const & x, T y);
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> max(vecType<T, P> const & x, vecType<T, P> const & y);
/// Returns min(max(x, minVal), maxVal) for each component in x
/// using the floating-point values minVal and maxVal.
@ -190,10 +192,13 @@ namespace glm
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/clamp.xml">GLSL clamp man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
template <typename genType>
GLM_FUNC_DECL genType clamp(genType const & x, genType const & minVal, genType const & maxVal);
GLM_FUNC_DECL genType clamp(genType x, genType minVal, genType maxVal);
template <typename genType, precision P>
GLM_FUNC_DECL genType clamp(genType const & x, typename genType::value_type const & minVal, typename genType::value_type const & maxVal);
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> clamp(vecType<T, P> const & x, T minVal, T maxVal);
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> clamp(vecType<T, P> const & x, vecType<T, P> const & minVal, vecType<T, P> const & maxVal);
/// If genTypeU is a floating scalar or vector:
/// Returns x * (1.0 - a) + y * a, i.e., the linear blend of
@ -241,24 +246,31 @@ namespace glm
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);
GLM_FUNC_DECL vecType<T, P> mix(vecType<T, P> const & x, vecType<T, P> const & y, U a);
template <typename genTypeT, typename genTypeU>
GLM_FUNC_DECL genTypeT mix(genTypeT const & x, genTypeT const & y, genTypeU const & a);
GLM_FUNC_DECL genTypeT mix(genTypeT x, genTypeT y, genTypeU a);
/// Returns 0.0 if x < edge, otherwise it returns 1.0 for each component of a genType.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/step.xml">GLSL step man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
template <typename genType>
GLM_FUNC_DECL genType step(genType const & edge, genType const & x);
GLM_FUNC_DECL genType step(genType edge, genType x);
/// Returns 0.0 if x < edge, otherwise it returns 1.0.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/step.xml">GLSL step man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
template <template <typename, precision> class vecType, typename T, precision P>
GLM_FUNC_DECL vecType<T, P> step(T const & edge, vecType<T, P> const & x);
GLM_FUNC_DECL vecType<T, P> step(T edge, vecType<T, P> const & x);
/// Returns 0.0 if x < edge, otherwise it returns 1.0.
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/step.xml">GLSL step man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
template <template <typename, precision> class vecType, typename T, precision P>
GLM_FUNC_DECL vecType<T, P> step(vecType<T, P> const & edge, vecType<T, P> const & x);
/// Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and
/// performs smooth Hermite interpolation between 0 and 1
@ -275,10 +287,13 @@ namespace glm
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/smoothstep.xml">GLSL smoothstep man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
template <typename genType>
GLM_FUNC_DECL genType smoothstep(genType const & edge0, genType const & edge1, genType const & x);
GLM_FUNC_DECL genType smoothstep(genType edge0, genType edge1, genType x);
template <typename genType>
GLM_FUNC_DECL genType smoothstep(typename genType::value_type const & edge0, typename genType::value_type const & edge1, genType const & x);
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> smoothstep(T edge0, T edge1, vecType<T, P> const & x);
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> smoothstep(vecType<T, P> const & edge0, vecType<T, P> const & edge1, vecType<T, P> const & x);
/// Returns true if x holds a NaN (not a number)
/// representation in the underlying implementation's set of
@ -292,8 +307,8 @@ namespace glm
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/isnan.xml">GLSL isnan man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
template <typename genType>
GLM_FUNC_DECL typename genType::bool_type isnan(genType const & x);
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<bool, P> isnan(vecType<T, P> const & x);
/// Returns true if x holds a positive infinity or negative
/// infinity representation in the underlying implementation's
@ -305,8 +320,8 @@ namespace glm
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/isinf.xml">GLSL isinf man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
template <typename genType>
GLM_FUNC_DECL typename genType::bool_type isinf(genType const & x);
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<bool, P> isinf(vecType<T, P> const & x);
/// Returns a signed integer value representing
/// the encoding of a floating-point value. The floating-point

View File

@ -278,35 +278,39 @@ namespace detail
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'fract' only accept floating-point inputs");
return x - floor(x);
return tvec1<genType>(x).x;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> fract(vecType<T, P> const & x)
{
return detail::functor1<T, T, P, vecType>::call(fract, x);
return x - floor(x);
}
// mod
template <typename genType>
GLM_FUNC_QUALIFIER genType mod(genType x, genType y)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'mod' only accept floating-point inputs");
return tvec1<genType>(x, y).x;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> mod(vecType<T, P> const & x, T y)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'mod' only accept floating-point inputs");
return x - y * floor(x / y);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> mod(vecType<T, P> const & a, vecType<T, P> const & b)
GLM_FUNC_QUALIFIER vecType<T, P> mod(vecType<T, P> const & x, vecType<T, P> const & y)
{
return detail::functor2<T, P, vecType>::call(mod, a, b);
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'mod' only accept floating-point inputs");
return x - y * floor(x / y);
}
VECTORIZE_VEC_SCA(mod)
// modf
template <typename genType>
GLM_FUNC_QUALIFIER genType modf(genType const & x, genType & i)
GLM_FUNC_QUALIFIER genType modf(genType x, genType & i)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'modf' only accept floating-point inputs");
@ -364,14 +368,18 @@ namespace detail
return x < y ? x : y;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> min(vecType<T, P> const & a, T b)
{
return detail::functor2_vec_sca<T, P, vecType>::call(min, a, b);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> min(vecType<T, P> const & a, vecType<T, P> const & b)
{
return detail::functor2<T, P, vecType>::call(min, a, b);
}
VECTORIZE_VEC_SCA(min)
// max
template <typename genType>
GLM_FUNC_QUALIFIER genType max(genType x, genType y)
@ -381,125 +389,85 @@ namespace detail
return x > y ? x : y;
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> max(vecType<T, P> const & a, T b)
{
return detail::functor2_vec_sca<T, P, vecType>::call(max, a, b);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> max(vecType<T, P> const & a, vecType<T, P> const & b)
{
return detail::functor2<T, P, vecType>::call(max, a, b);
}
VECTORIZE_VEC_SCA(max)
// clamp
template <typename genType>
GLM_FUNC_QUALIFIER genType clamp(genType const & x, genType const & minVal, genType const & maxVal)
GLM_FUNC_QUALIFIER genType clamp(genType x, genType minVal, genType maxVal)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || std::numeric_limits<genType>::is_integer, "'clamp' only accept floating-point or integer inputs");
return min(maxVal, max(minVal, x));
return min(max(x, minVal), maxVal);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> clamp(tvec2<T, P> const & x, T const & minVal, T const & maxVal)
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> clamp(vecType<T, P> const & x, T minVal, T maxVal)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, "'clamp' only accept floating-point or integer inputs");
return tvec2<T, P>(
clamp(x.x, minVal, maxVal),
clamp(x.y, minVal, maxVal));
return min(max(x, minVal), maxVal);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> clamp(tvec3<T, P> const & x, T const & minVal, T const & maxVal)
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> clamp(vecType<T, P> const & x, vecType<T, P> const & minVal, vecType<T, P> const & maxVal)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, "'clamp' only accept floating-point or integer inputs");
return tvec3<T, P>(
clamp(x.x, minVal, maxVal),
clamp(x.y, minVal, maxVal),
clamp(x.z, minVal, maxVal));
return min(max(x, minVal), maxVal);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> clamp(tvec4<T, P> const & x, T const & minVal, T const & maxVal)
template <typename genTypeT, typename genTypeU>
GLM_FUNC_QUALIFIER genTypeT mix(genTypeT x, genTypeT y, genTypeU a)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, "'clamp' only accept floating-point or integer inputs");
return tvec4<T, P>(
clamp(x.x, minVal, maxVal),
clamp(x.y, minVal, maxVal),
clamp(x.z, minVal, maxVal),
clamp(x.w, minVal, maxVal));
return detail::compute_mix<genTypeT, genTypeU>::call(x, y, a);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> clamp(tvec2<T, P> const & x, tvec2<T, P> const & minVal, tvec2<T, P> const & maxVal)
template <typename T, typename U, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> mix(vecType<T, P> const & x, vecType<T, P> const & y, U a)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, "'clamp' only accept floating-point or integer inputs");
return tvec2<T, P>(
clamp(x.x, minVal.x, maxVal.x),
clamp(x.y, minVal.y, maxVal.y));
return detail::compute_mix_scalar<T, U, P, vecType>::call(x, y, a);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> clamp(tvec3<T, P> const & x, tvec3<T, P> const & minVal, tvec3<T, P> const & maxVal)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, "'clamp' only accept floating-point or integer inputs");
return tvec3<T, P>(
clamp(x.x, minVal.x, maxVal.x),
clamp(x.y, minVal.y, maxVal.y),
clamp(x.z, minVal.z, maxVal.z));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> clamp(tvec4<T, P> const & x, tvec4<T, P> const & minVal, tvec4<T, P> const & maxVal)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, "'clamp' only accept floating-point or integer inputs");
return tvec4<T, P>(
clamp(x.x, minVal.x, maxVal.x),
clamp(x.y, minVal.y, maxVal.y),
clamp(x.z, minVal.z, maxVal.z),
clamp(x.w, minVal.w, maxVal.w));
}
template <typename T, typename U, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> mix(vecType<T, P> const & x, vecType<T, P> const & y, vecType<U, P> const & a)
{
return detail::compute_mix_vector<T, U, P, vecType>::call(x, y, a);
}
template <typename T, typename U, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> mix(vecType<T, P> const & x, vecType<T, P> const & y, U const & a)
{
return detail::compute_mix_scalar<T, U, P, vecType>::call(x, y, a);
}
template <typename genTypeT, typename genTypeU>
GLM_FUNC_QUALIFIER genTypeT mix(genTypeT const & x, genTypeT const & y, genTypeU const & a)
{
return detail::compute_mix<genTypeT, genTypeU>::call(x, y, a);
}
// step
template <typename genType>
GLM_FUNC_QUALIFIER genType step(genType const & edge, genType const & x)
GLM_FUNC_QUALIFIER genType step(genType edge, genType x)
{
return mix(genType(1), genType(0), glm::lessThan(x, edge));
return mix(static_cast<genType>(1), static_cast<genType>(0), glm::lessThan(x, edge));
}
template <template <typename, precision> class vecType, typename T, precision P>
GLM_FUNC_QUALIFIER vecType<T, P> step(T const & edge, vecType<T, P> const & x)
GLM_FUNC_QUALIFIER vecType<T, P> step(T edge, vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'step' only accept floating-point inputs");
return mix(vecType<T, P>(1), vecType<T, P>(0), glm::lessThan(x, vecType<T, P>(edge)));
}
template <template <typename, precision> class vecType, typename T, precision P>
GLM_FUNC_QUALIFIER vecType<T, P> step(vecType<T, P> const & edge, vecType<T, P> const & x)
{
return mix(vecType<T, P>(1), vecType<T, P>(0), glm::lessThan(x, edge));
}
// smoothstep
template <typename genType>
GLM_FUNC_QUALIFIER genType smoothstep(genType const & edge0, genType const & edge1, genType const & x)
GLM_FUNC_QUALIFIER genType smoothstep(genType edge0, genType edge1, genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'smoothstep' only accept floating-point inputs");
@ -507,139 +475,57 @@ namespace detail
return tmp * tmp * (genType(3) - genType(2) * tmp);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> smoothstep(T const & edge0, T const & edge1, tvec2<T, P> const & x)
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> smoothstep(T edge0, T edge1, vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'smoothstep' only accept floating-point inputs");
return tvec2<T, P>(
smoothstep(edge0, edge1, x.x),
smoothstep(edge0, edge1, x.y));
vecType<T, P> tmp = clamp((x - edge0) / (edge1 - edge0), static_cast<T>(0), static_cast<T>(1));
return tmp * tmp * (static_cast<T>(3) - static_cast<T>(2) * tmp);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> smoothstep(T const & edge0, T const & edge1, tvec3<T, P> const & x)
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> smoothstep(vecType<T, P> const & edge0, vecType<T, P> const & edge1, vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'smoothstep' only accept floating-point inputs");
return tvec3<T, P>(
smoothstep(edge0, edge1, x.x),
smoothstep(edge0, edge1, x.y),
smoothstep(edge0, edge1, x.z));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> smoothstep(T const & edge0, T const & edge1, tvec4<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'smoothstep' only accept floating-point inputs");
return tvec4<T, P>(
smoothstep(edge0, edge1, x.x),
smoothstep(edge0, edge1, x.y),
smoothstep(edge0, edge1, x.z),
smoothstep(edge0, edge1, x.w));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> smoothstep(tvec2<T, P> const & edge0, tvec2<T, P> const & edge1, tvec2<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'smoothstep' only accept floating-point inputs");
return tvec2<T, P>(
smoothstep(edge0.x, edge1.x, x.x),
smoothstep(edge0.y, edge1.y, x.y));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> smoothstep(tvec3<T, P> const & edge0, tvec3<T, P> const & edge1, tvec3<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'smoothstep' only accept floating-point inputs");
return tvec3<T, P>(
smoothstep(edge0.x, edge1.x, x.x),
smoothstep(edge0.y, edge1.y, x.y),
smoothstep(edge0.z, edge1.z, x.z));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> smoothstep(tvec4<T, P> const & edge0, tvec4<T, P> const & edge1, tvec4<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'smoothstep' only accept floating-point inputs");
return tvec4<T, P>(
smoothstep(edge0.x, edge1.x, x.x),
smoothstep(edge0.y, edge1.y, x.y),
smoothstep(edge0.z, edge1.z, x.z),
smoothstep(edge0.w, edge1.w, x.w));
vecType<T, P> tmp = clamp((x - edge0) / (edge1 - edge0), static_cast<T>(0), static_cast<T>(1));
return tmp * tmp * (static_cast<T>(3) - static_cast<T>(2) * tmp);
}
// TODO: Not working on MinGW...
template <typename genType>
GLM_FUNC_QUALIFIER bool isnan(genType const & x)
GLM_FUNC_QUALIFIER bool isnan(genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'isnan' only accept floating-point inputs");
# if(GLM_LANG & GLM_LANG_CXX11_FLAG)
# if GLM_LANG & GLM_LANG_CXX11_FLAG
return std::isnan(x);
# elif(GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_INTEL))
# elif GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_INTEL)
return _isnan(x) != 0;
# elif(GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG))
# if(GLM_PLATFORM & GLM_PLATFORM_ANDROID && __cplusplus < 201103L)
# elif GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG)
# if GLM_PLATFORM & GLM_PLATFORM_ANDROID && __cplusplus < 201103L
return _isnan(x) != 0;
# else
return std::isnan(x);
# endif
# elif(GLM_COMPILER & GLM_COMPILER_CUDA)
# elif GLM_COMPILER & GLM_COMPILER_CUDA
return isnan(x) != 0;
# else
return std::isnan(x);
# endif
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tvec1<T, P>::bool_type isnan(tvec1<T, P> const & x)
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<bool, P> isnan(vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isnan' only accept floating-point inputs");
return typename tvec1<T, P>::bool_type(
isnan(x.x));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tvec2<T, P>::bool_type isnan(tvec2<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isnan' only accept floating-point inputs");
return typename tvec2<T, P>::bool_type(
isnan(x.x),
isnan(x.y));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tvec3<T, P>::bool_type isnan(tvec3<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isnan' only accept floating-point inputs");
return typename tvec3<T, P>::bool_type(
isnan(x.x),
isnan(x.y),
isnan(x.z));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tvec4<T, P>::bool_type isnan(tvec4<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isnan' only accept floating-point inputs");
return typename tvec4<T, P>::bool_type(
isnan(x.x),
isnan(x.y),
isnan(x.z),
isnan(x.w));
return detail::functor1<bool, T, P, vecType>::call(isnan, x);
}
template <typename genType>
GLM_FUNC_QUALIFIER bool isinf(genType const & x)
GLM_FUNC_QUALIFIER bool isinf(genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'isinf' only accept floating-point inputs");
@ -661,46 +547,12 @@ namespace detail
# endif
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tvec1<T, P>::bool_type isinf(tvec1<T, P> const & x)
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<bool, P> isinf(vecType<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isinf' only accept floating-point inputs");
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isnan' only accept floating-point inputs");
return typename tvec1<T, P>::bool_type(
isinf(x.x));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tvec2<T, P>::bool_type isinf(tvec2<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isinf' only accept floating-point inputs");
return typename tvec2<T, P>::bool_type(
isinf(x.x),
isinf(x.y));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tvec3<T, P>::bool_type isinf(tvec3<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isinf' only accept floating-point inputs");
return typename tvec3<T, P>::bool_type(
isinf(x.x),
isinf(x.y),
isinf(x.z));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER typename tvec4<T, P>::bool_type isinf(tvec4<T, P> const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'isinf' only accept floating-point inputs");
return typename tvec4<T, P>::bool_type(
isinf(x.x),
isinf(x.y),
isinf(x.z),
isinf(x.w));
return detail::functor1<bool, T, P, vecType>::call(isinf, x);
}
GLM_FUNC_QUALIFIER int floatBitsToInt(float const & v)
@ -754,7 +606,7 @@ namespace detail
}
template <typename genType>
GLM_FUNC_QUALIFIER genType frexp(genType const & x, int & exp)
GLM_FUNC_QUALIFIER genType frexp(genType x, int & exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'frexp' only accept floating-point inputs");