Add static components and prec members to all vector and quaternion types

This commit is contained in:
Jesse Talavera-Greenberg 2015-07-03 14:57:46 -04:00
parent 98a736bcf1
commit a9c26d065b
13 changed files with 158 additions and 90 deletions

View file

@ -8,14 +8,14 @@
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -54,7 +54,13 @@ namespace glm
typedef tvec1<T, P> type;
typedef tvec1<bool, P> bool_type;
typedef T value_type;
# if GLM_HAS_CONSTEXPR
static GLM_CONSTEXPR length_t components = 1;
static GLM_CONSTEXPR precision prec = P;
# else
static const length_t components = 1;
static const precision prec = P;
# endif
//////////////////////////////////////
// Data
@ -120,7 +126,7 @@ namespace glm
//////////////////////////////////////
// Conversion vector constructors
//! Explicit conversions (From section 5.4.1 Conversion and scalar constructors of GLSL 1.30.08 specification)
template <typename U, precision Q>
GLM_FUNC_DECL explicit tvec1(tvec2<U, Q> const & v);
@ -157,23 +163,23 @@ namespace glm
GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<T, P> const & v);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator=(tvec1<U, P> const & v);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator+=(U const & s);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator+=(tvec1<U, P> const & v);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator-=(U const & s);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator-=(tvec1<U, P> const & v);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator*=(U const & s);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator*=(tvec1<U, P> const & v);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator/=(U const & s);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator/=(tvec1<U, P> const & v);
//////////////////////////////////////
@ -187,29 +193,29 @@ namespace glm
//////////////////////////////////////
// Unary bit operators
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator%=(U const & s);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator%=(tvec1<U, P> const & v);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator&=(U const & s);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator&=(tvec1<U, P> const & v);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator|=(U const & s);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator|=(tvec1<U, P> const & v);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator^=(U const & s);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator^=(tvec1<U, P> const & v);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator<<=(U const & s);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator<<=(tvec1<U, P> const & v);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator>>=(U const & s);
template <typename U>
template <typename U>
GLM_FUNC_DECL tvec1<T, P> & operator>>=(tvec1<U, P> const & v);
};
@ -313,7 +319,7 @@ namespace glm
template <typename T, precision P>
GLM_FUNC_DECL tvec1<T, P> operator>>(tvec1<T, P> const & v1, tvec1<T, P> const & v2);
template <typename T, precision P>
template <typename T, precision P>
GLM_FUNC_DECL tvec1<T, P> operator~(tvec1<T, P> const & v);
}//namespace glm

View file

@ -54,6 +54,13 @@ namespace glm
typedef tvec2<T, P> type;
typedef tvec2<bool, P> bool_type;
typedef T value_type;
# if GLM_HAS_CONSTEXPR
static GLM_CONSTEXPR length_t components = 2;
static GLM_CONSTEXPR precision prec = P;
# else
static const length_t components = 2;
static const precision prec = P;
# endif
//////////////////////////////////////
// Data

View file

@ -54,6 +54,13 @@ namespace glm
typedef tvec3<T, P> type;
typedef tvec3<bool, P> bool_type;
typedef T value_type;
# if GLM_HAS_CONSTEXPR
static GLM_CONSTEXPR length_t components = 3;
static GLM_CONSTEXPR precision prec = P;
# else
static const length_t components = 3;
static const precision prec = P;
# endif
//////////////////////////////////////
// Data

View file

@ -108,6 +108,13 @@ namespace detail
typedef tvec4<T, P> type;
typedef tvec4<bool, P> bool_type;
typedef T value_type;
# if GLM_HAS_CONSTEXPR
static GLM_CONSTEXPR length_t components = 4;
static GLM_CONSTEXPR precision prec = P;
# else
static const length_t components = 4;
static const precision prec = P;
# endif
//////////////////////////////////////
// Data

View file

@ -64,6 +64,13 @@ namespace glm
{
typedef tquat<T, P> type;
typedef T value_type;
# if GLM_HAS_CONSTEXPR
static GLM_CONSTEXPR length_t components = 4;
static GLM_CONSTEXPR precision prec = P;
# else
static const length_t components = 4;
static const precision prec = P;
# endif
public:
T x, y, z, w;

View file

@ -15,7 +15,7 @@
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -63,10 +63,17 @@ namespace glm
{
typedef T value_type;
typedef glm::tquat<T, P> part_type;
# if GLM_HAS_CONSTEXPR
static GLM_CONSTEXPR length_t components = 8;
static GLM_CONSTEXPR precision prec = P;
# else
static const length_t components = 8;
static const precision prec = P;
# endif
public:
glm::tquat<T, P> real, dual;
//////////////////////////////////////
// Component accesses
@ -115,7 +122,7 @@ namespace glm
GLM_FUNC_DECL explicit tdualquat(tmat2x4<T, P> const & holder_mat);
GLM_FUNC_DECL explicit tdualquat(tmat3x4<T, P> const & aug_mat);
// Operators
GLM_FUNC_DECL tdualquat<T, P> & operator=(tdualquat<T, P> const & m);
@ -126,51 +133,51 @@ namespace glm
template <typename U>
GLM_FUNC_DECL tdualquat<T, P> & operator/=(U s);
};
template <typename T, precision P>
GLM_FUNC_DECL tquat<T, P> operator- (
tquat<T, P> const & q);
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> operator+ (
tdualquat<T, P> const & q,
tdualquat<T, P> const & p);
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> operator* (
tdualquat<T, P> const & q,
tdualquat<T, P> const & p);
template <typename T, precision P>
GLM_FUNC_DECL tvec3<T, P> operator* (
tquat<T, P> const & q,
tvec3<T, P> const & v);
template <typename T, precision P>
GLM_FUNC_DECL tvec3<T, P> operator* (
tvec3<T, P> const & v,
tquat<T, P> const & q);
template <typename T, precision P>
GLM_FUNC_DECL tvec4<T, P> operator* (
tquat<T, P> const & q,
tvec4<T, P> const & v);
template <typename T, precision P>
GLM_FUNC_DECL tvec4<T, P> operator* (
tvec4<T, P> const & v,
tquat<T, P> const & q);
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> operator* (
tdualquat<T, P> const & q,
T const & s);
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> operator* (
T const & s,
tdualquat<T, P> const & q);
template <typename T, precision P>
GLM_FUNC_DECL tdualquat<T, P> operator/ (
tdualquat<T, P> const & q,
@ -227,17 +234,17 @@ namespace glm
GLM_FUNC_DECL tdualquat<T, P> dualquat_cast(
tmat3x4<T, P> const & x);
/// Dual-quaternion of low single-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<float, lowp> lowp_dualquat;
/// Dual-quaternion of medium single-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<float, mediump> mediump_dualquat;
/// Dual-quaternion of high single-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
@ -248,40 +255,40 @@ namespace glm
///
/// @see gtx_dual_quaternion
typedef tdualquat<float, lowp> lowp_fdualquat;
/// Dual-quaternion of medium single-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<float, mediump> mediump_fdualquat;
/// Dual-quaternion of high single-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<float, highp> highp_fdualquat;
/// Dual-quaternion of low double-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<double, lowp> lowp_ddualquat;
/// Dual-quaternion of medium double-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<double, mediump> mediump_ddualquat;
/// Dual-quaternion of high double-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef tdualquat<double, highp> highp_ddualquat;
#if(!defined(GLM_PRECISION_HIGHP_FLOAT) && !defined(GLM_PRECISION_MEDIUMP_FLOAT) && !defined(GLM_PRECISION_LOWP_FLOAT))
/// Dual-quaternion of floating-point numbers.
///
/// @see gtx_dual_quaternion
typedef highp_fdualquat dualquat;
/// Dual-quaternion of single-precision floating-point numbers.
///
/// @see gtx_dual_quaternion
@ -298,7 +305,7 @@ namespace glm
#else
# error "GLM error: multiple default precision requested for single-precision floating-point types"
#endif
#if(!defined(GLM_PRECISION_HIGHP_DOUBLE) && !defined(GLM_PRECISION_MEDIUMP_DOUBLE) && !defined(GLM_PRECISION_LOWP_DOUBLE))
/// Dual-quaternion of default double-precision floating-point numbers.

View file

@ -75,6 +75,13 @@ namespace detail
typedef fquatSIMD type;
typedef tquat<bool, defaultp> bool_type;
# if GLM_HAS_CONSTEXPR
static GLM_CONSTEXPR length_t components = 1;
static GLM_CONSTEXPR precision prec = defaultp;
# else
static const length_t components = 1;
static const precision prec = defaultp;
# endif
#ifdef GLM_SIMD_ENABLE_XYZW_UNION
union

View file

@ -98,6 +98,13 @@ namespace detail
typedef fvec4SIMD type;
typedef tvec4<bool, highp> bool_type;
# if GLM_HAS_CONSTEXPR
static GLM_CONSTEXPR length_t components = 1;
static GLM_CONSTEXPR precision prec = defaultp;
# else
static const length_t components = 1;
static const precision prec = defaultp;
# endif
#ifdef GLM_SIMD_ENABLE_XYZW_UNION
union

View file

@ -131,6 +131,7 @@ int test_vec1_size()
Error += 8 == sizeof(glm::highp_dvec1) ? 0 : 1;
Error += glm::vec1().length() == 1 ? 0 : 1;
Error += glm::dvec1().length() == 1 ? 0 : 1;
Error += glm::vec1::components == 1 ? 0 : 1;
return Error;
}
@ -168,6 +169,7 @@ int main()
glm::vec1 v;
assert(v.length() == 1);
assert(glm::vec1::components == 1);
Error += test_vec1_size();
Error += test_vec1_ctor();

View file

@ -8,14 +8,14 @@
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -102,81 +102,81 @@ int test_vec2_operators()
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
glm::vec2 C = A + B;
Error += C == glm::vec2(5, 7) ? 0 : 1;
glm::vec2 D = B - A;
Error += D == glm::vec2(3, 3) ? 0 : 1;
glm::vec2 E = A * B;
Error += E == glm::vec2(4, 10) ? 0 : 1;
glm::vec2 F = B / A;
Error += F == glm::vec2(4, 2.5) ? 0 : 1;
glm::vec2 G = A + 1.0f;
Error += G == glm::vec2(2, 3) ? 0 : 1;
glm::vec2 H = B - 1.0f;
Error += H == glm::vec2(3, 4) ? 0 : 1;
glm::vec2 I = A * 2.0f;
Error += I == glm::vec2(2, 4) ? 0 : 1;
glm::vec2 J = B / 2.0f;
Error += J == glm::vec2(2, 2.5) ? 0 : 1;
glm::vec2 K = 1.0f + A;
Error += K == glm::vec2(2, 3) ? 0 : 1;
glm::vec2 L = 1.0f - B;
Error += L == glm::vec2(-3, -4) ? 0 : 1;
glm::vec2 M = 2.0f * A;
Error += M == glm::vec2(2, 4) ? 0 : 1;
glm::vec2 N = 2.0f / B;
Error += N == glm::vec2(0.5, 2.0 / 5.0) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
A += B;
Error += A == glm::vec2(5, 7) ? 0 : 1;
A += 1.0f;
Error += A == glm::vec2(6, 8) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
B -= A;
Error += B == glm::vec2(3, 3) ? 0 : 1;
B -= 1.0f;
Error += B == glm::vec2(2, 2) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
A *= B;
Error += A == glm::vec2(4, 10) ? 0 : 1;
A *= 2.0f;
Error += A == glm::vec2(8, 20) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
B /= A;
Error += B == glm::vec2(4, 2.5) ? 0 : 1;
B /= 2.0f;
Error += B == glm::vec2(2, 1.25) ? 0 : 1;
}
@ -186,39 +186,39 @@ int test_vec2_operators()
B /= B.y;
Error += B == glm::vec2(1.0f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = -A;
Error += B == glm::vec2(-1.0f, -2.0f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = --A;
Error += B == glm::vec2(0.0f, 1.0f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = A--;
Error += B == glm::vec2(1.0f, 2.0f) ? 0 : 1;
Error += A == glm::vec2(0.0f, 1.0f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = ++A;
Error += B == glm::vec2(2.0f, 3.0f) ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B = A++;
Error += B == glm::vec2(1.0f, 2.0f) ? 0 : 1;
Error += A == glm::vec2(2.0f, 3.0f) ? 0 : 1;
}
return Error;
}
@ -283,14 +283,15 @@ int test_vec2_ctor()
int test_vec2_size()
{
int Error = 0;
Error += sizeof(glm::vec2) == sizeof(glm::mediump_vec2) ? 0 : 1;
Error += 8 == sizeof(glm::mediump_vec2) ? 0 : 1;
Error += sizeof(glm::dvec2) == sizeof(glm::highp_dvec2) ? 0 : 1;
Error += 16 == sizeof(glm::highp_dvec2) ? 0 : 1;
Error += glm::vec2().length() == 2 ? 0 : 1;
Error += glm::dvec2().length() == 2 ? 0 : 1;
Error += glm::vec2::components == 2 ? 0 : 1;
return Error;
}
@ -327,6 +328,7 @@ int main()
glm::vec2 v;
assert(v.length() == 2);
assert(glm::vec2::components == 2);
Error += test_vec2_size();
Error += test_vec2_ctor();

View file

@ -263,7 +263,7 @@ int test_vec3_size()
Error += 24 == sizeof(glm::highp_dvec3) ? 0 : 1;
Error += glm::vec3().length() == 3 ? 0 : 1;
Error += glm::dvec3().length() == 3 ? 0 : 1;
Error += glm::vec3::components == 3 ? 0 : 1;
return Error;
}
@ -494,6 +494,10 @@ int main()
{
int Error = 0;
glm::vec3 v;
assert(v.length() == 3);
assert(glm::vec3::components == 3);
Error += test_vec3_ctor();
Error += test_vec3_operators();
Error += test_vec3_size();

View file

@ -446,9 +446,12 @@ int main()
{
int Error(0);
std::size_t const Size(1000000);
glm::vec4 v;
assert(v.length() == 4);
assert(glm::vec4::components == 4);
# ifdef NDEBUG
std::size_t const Size(1000000);
Error += test_vec4_perf_AoS(Size);
Error += test_vec4_perf_SoA(Size);
# endif//NDEBUG

View file

@ -8,14 +8,14 @@
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -324,6 +324,8 @@ int main()
{
int Error(0);
assert(glm::quat::components == 4);
Error += test_quat_ctr();
Error += test_quat_mul_vec();
Error += test_quat_two_axis_ctr();