From 276505f40992d4bbacab4ec88a6bf5d5c573eb61 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 23 May 2016 21:13:57 +0200 Subject: [PATCH 1/6] add, sub, mul and div vec4 for specialization --- glm/detail/type_vec4.inl | 102 ++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 61 deletions(-) diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index 261162a6..cd093916 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -41,6 +41,33 @@ namespace detail return tvec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); } }; + + template + struct compute_vec4_sub + { + static tvec4 call(tvec4 const & a, tvec4 const & b) + { + return tvec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } + }; + + template + struct compute_vec4_mul + { + static tvec4 call(tvec4 const & a, tvec4 const & b) + { + return tvec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + } + }; + + template + struct compute_vec4_div + { + static tvec4 call(tvec4 const & a, tvec4 const & b) + { + return tvec4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w); + } + }; }//namespace detail // -- Implicit basic constructors -- @@ -264,131 +291,84 @@ namespace detail template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+=(U scalar) { - this->x += static_cast(scalar); - this->y += static_cast(scalar); - this->z += static_cast(scalar); - this->w += static_cast(scalar); - return *this; + return (*this = detail::compute_vec4_add::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+=(tvec1 const & v) { - T const scalar = static_cast(v.x); - this->x += scalar; - this->y += scalar; - this->z += scalar; - this->w += scalar; - return *this; + return (*this = detail::compute_vec4_add::call(*this, tvec4(v.x))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+=(tvec4 const & v) { - *this = detail::compute_vec4_add::call(*this, tvec4(v)); - return *this; + return (*this = detail::compute_vec4_add::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator-=(U scalar) { - this->x -= static_cast(scalar); - this->y -= static_cast(scalar); - this->z -= static_cast(scalar); - this->w -= static_cast(scalar); - return *this; + return (*this = detail::compute_vec4_sub::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator-=(tvec1 const & v) { - T const scalar = static_cast(v.x); - this->x -= scalar; - this->y -= scalar; - this->z -= scalar; - this->w -= scalar; - return *this; + return (*this = detail::compute_vec4_sub::call(*this, tvec4(v.x))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator-=(tvec4 const & v) { - this->x -= static_cast(v.x); - this->y -= static_cast(v.y); - this->z -= static_cast(v.z); - this->w -= static_cast(v.w); - return *this; + return (*this = detail::compute_vec4_sub::call(*this, tvec4(v))); } template template - GLM_FUNC_QUALIFIER tvec4 & tvec4::operator*=(U v) + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator*=(U scalar) { - this->x *= static_cast(v); - this->y *= static_cast(v); - this->z *= static_cast(v); - this->w *= static_cast(v); - return *this; + return (*this = detail::compute_vec4_mul::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator*=(tvec1 const & v) { - this->x *= static_cast(v.x); - this->y *= static_cast(v.x); - this->z *= static_cast(v.x); - this->w *= static_cast(v.x); - return *this; + return (*this = detail::compute_vec4_mul::call(*this, tvec4(v.x))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator*=(tvec4 const & v) { - this->x *= static_cast(v.x); - this->y *= static_cast(v.y); - this->z *= static_cast(v.z); - this->w *= static_cast(v.w); - return *this; + return (*this = detail::compute_vec4_mul::call(*this, tvec4(v))); } template template - GLM_FUNC_QUALIFIER tvec4 & tvec4::operator/=(U v) + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator/=(U scalar) { - this->x /= static_cast(v); - this->y /= static_cast(v); - this->z /= static_cast(v); - this->w /= static_cast(v); - return *this; + return (*this = detail::compute_vec4_div::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator/=(tvec1 const & v) { - this->x /= static_cast(v.x); - this->y /= static_cast(v.x); - this->z /= static_cast(v.x); - this->w /= static_cast(v.x); - return *this; + return (*this = detail::compute_vec4_div::call(*this, tvec4(v.x))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator/=(tvec4 const & v) { - this->x /= static_cast(v.x); - this->y /= static_cast(v.y); - this->z /= static_cast(v.z); - this->w /= static_cast(v.w); - return *this; + return (*this = detail::compute_vec4_div::call(*this, tvec4(v))); } // -- Increment and decrement operators -- From eab004bfe5581963fe57578b748c89f1b9a663d1 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 23 May 2016 21:20:04 +0200 Subject: [PATCH 2/6] vec4 add, sub, mul and div binary operators use unary operators implementation --- glm/detail/type_vec4.inl | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index cd093916..17b4fe67 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -722,51 +722,31 @@ namespace detail template GLM_FUNC_QUALIFIER tvec4 operator/(tvec4 const & v, T scalar) { - return tvec4( - v.x / scalar, - v.y / scalar, - v.z / scalar, - v.w / scalar); + return tvec4(v) /= scalar; } template GLM_FUNC_QUALIFIER tvec4 operator/(tvec4 const & v1, tvec1 const & v2) { - return tvec4( - v1.x / v2.x, - v1.y / v2.x, - v1.z / v2.x, - v1.w / v2.x); + return tvec4(v1) /= v2; } template GLM_FUNC_QUALIFIER tvec4 operator/(T scalar, tvec4 const & v) { - return tvec4( - scalar / v.x, - scalar / v.y, - scalar / v.z, - scalar / v.w); + return tvec4(scalar) /= v; } template GLM_FUNC_QUALIFIER tvec4 operator/(tvec1 const & v1, tvec4 const & v2) { - return tvec4( - v1.x / v2.x, - v1.x / v2.y, - v1.x / v2.z, - v1.x / v2.w); + return tvec4(v1.x) /= v2; } template GLM_FUNC_QUALIFIER tvec4 operator/(tvec4 const & v1, tvec4 const & v2) { - return tvec4( - v1.x / v2.x, - v1.y / v2.y, - v1.z / v2.z, - v1.w / v2.w); + return tvec4(v1) /= v2; } // -- Binary bit operators -- From 5e60c54004aef257a2017589ff37456ac8f72770 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 23 May 2016 21:24:59 +0200 Subject: [PATCH 3/6] Use unary % operator for binary implementation --- glm/detail/type_vec4.inl | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index 17b4fe67..0df6b447 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -754,61 +754,37 @@ namespace detail template GLM_FUNC_QUALIFIER tvec4 operator%(tvec4 const & v, T scalar) { - return tvec4( - v.x % scalar, - v.y % scalar, - v.z % scalar, - v.w % scalar); + return tvec4(v) %= scalar; } template - GLM_FUNC_QUALIFIER tvec4 operator%(tvec4 const & v, tvec1 const & scalar) + GLM_FUNC_QUALIFIER tvec4 operator%(tvec4 const & v1, tvec1 const & v2) { - return tvec4( - v.x % scalar.x, - v.y % scalar.x, - v.z % scalar.x, - v.w % scalar.x); + return tvec4(v1) %= v2.x; } template GLM_FUNC_QUALIFIER tvec4 operator%(T scalar, tvec4 const & v) { - return tvec4( - scalar % v.x, - scalar % v.y, - scalar % v.z, - scalar % v.w); + return tvec4(scalar) %= v; } template GLM_FUNC_QUALIFIER tvec4 operator%(tvec1 const & scalar, tvec4 const & v) { - return tvec4( - scalar.x % v.x, - scalar.x % v.y, - scalar.x % v.z, - scalar.x % v.w); + return tvec4(scalar.x) %= v; } template GLM_FUNC_QUALIFIER tvec4 operator%(tvec4 const & v1, tvec4 const & v2) { - return tvec4( - v1.x % v2.x, - v1.y % v2.y, - v1.z % v2.z, - v1.w % v2.w); + return tvec4(v1) %= v2; } template GLM_FUNC_QUALIFIER tvec4 operator&(tvec4 const & v, T scalar) { - return tvec4( - v.x & scalar, - v.y & scalar, - v.z & scalar, - v.w & scalar); + return tvec4(v) &= scalar; } template From d871d753dc4c6b1b326476f0007e3d46d4b27baf Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 23 May 2016 21:39:33 +0200 Subject: [PATCH 4/6] Use unary bit operators for binary implementation --- glm/detail/type_vec4.inl | 108 ++++++++------------------------------- 1 file changed, 22 insertions(+), 86 deletions(-) diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index 0df6b447..8533e516 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -880,161 +880,97 @@ namespace detail template GLM_FUNC_QUALIFIER tvec4 operator^(tvec4 const & v, T scalar) { - return tvec4( - v.x ^ scalar, - v.y ^ scalar, - v.z ^ scalar, - v.w ^ scalar); + return tvec4(v) ^= scalar; } template - GLM_FUNC_QUALIFIER tvec4 operator^(tvec4 const & v, tvec1 const & scalar) + GLM_FUNC_QUALIFIER tvec4 operator^(tvec4 const & v1, tvec1 const & v2) { - return tvec4( - v.x ^ scalar.x, - v.y ^ scalar.x, - v.z ^ scalar.x, - v.w ^ scalar.x); + return tvec4(v1) ^= v2.x; } template GLM_FUNC_QUALIFIER tvec4 operator^(T scalar, tvec4 const & v) { - return tvec4( - scalar ^ v.x, - scalar ^ v.y, - scalar ^ v.z, - scalar ^ v.w); + return tvec4(scalar) ^= v; } template - GLM_FUNC_QUALIFIER tvec4 operator^(tvec1 const & scalar, tvec4 const & v) + GLM_FUNC_QUALIFIER tvec4 operator^(tvec1 const & v1, tvec4 const & v2) { - return tvec4( - scalar.x ^ v.x, - scalar.x ^ v.y, - scalar.x ^ v.z, - scalar.x ^ v.w); + return tvec4(v1.x) ^= v2; } template GLM_FUNC_QUALIFIER tvec4 operator^(tvec4 const & v1, tvec4 const & v2) { - return tvec4( - v1.x ^ v2.x, - v1.y ^ v2.y, - v1.z ^ v2.z, - v1.w ^ v2.w); + return tvec4(v1) ^= v2; } template GLM_FUNC_QUALIFIER tvec4 operator<<(tvec4 const & v, T scalar) { - return tvec4( - v.x << scalar, - v.y << scalar, - v.z << scalar, - v.w << scalar); + return tvec4(v) <<= scalar; } template - GLM_FUNC_QUALIFIER tvec4 operator<<(tvec4 const & v, tvec1 const & scalar) + GLM_FUNC_QUALIFIER tvec4 operator<<(tvec4 const & v1, tvec1 const & v2) { - return tvec4( - v.x << scalar.x, - v.y << scalar.x, - v.z << scalar.x, - v.w << scalar.x); + return tvec4(v1) <<= v2.x; } template GLM_FUNC_QUALIFIER tvec4 operator<<(T scalar, tvec4 const & v) { - return tvec4( - scalar << v.x, - scalar << v.y, - scalar << v.z, - scalar << v.w); + return tvec4(scalar) <<= v; } template - GLM_FUNC_QUALIFIER tvec4 operator<<(tvec1 const & scalar, tvec4 const & v) + GLM_FUNC_QUALIFIER tvec4 operator<<(tvec1 const & v1, tvec4 const & v2) { - return tvec4( - scalar.x << v.x, - scalar.x << v.y, - scalar.x << v.z, - scalar.x << v.w); + return tvec4(v1.x) <<= v2; } template GLM_FUNC_QUALIFIER tvec4 operator<<(tvec4 const & v1, tvec4 const & v2) { - return tvec4( - v1.x << v2.x, - v1.y << v2.y, - v1.z << v2.z, - v1.w << v2.w); + return tvec4(v1) <<= v2; } template GLM_FUNC_QUALIFIER tvec4 operator>>(tvec4 const & v, T scalar) { - return tvec4( - v.x >> scalar, - v.y >> scalar, - v.z >> scalar, - v.w >> scalar); + return tvec4(v) >>= scalar; } template - GLM_FUNC_QUALIFIER tvec4 operator>>(tvec4 const & v, tvec1 const & scalar) + GLM_FUNC_QUALIFIER tvec4 operator>>(tvec4 const & v1, tvec1 const & v2) { - return tvec4( - v.x >> scalar.x, - v.y >> scalar.x, - v.z >> scalar.x, - v.w >> scalar.x); + return tvec4(v1) >>= v2.x; } template GLM_FUNC_QUALIFIER tvec4 operator>>(T scalar, tvec4 const & v) { - return tvec4( - scalar >> v.x, - scalar >> v.y, - scalar >> v.z, - scalar >> v.w); + return tvec4(scalar) >>= v; } template - GLM_FUNC_QUALIFIER tvec4 operator>>(tvec1 const & scalar, tvec4 const & v) + GLM_FUNC_QUALIFIER tvec4 operator>>(tvec1 const & v1, tvec4 const & v2) { - return tvec4( - scalar.x >> v.x, - scalar.x >> v.y, - scalar.x >> v.z, - scalar.x >> v.w); + return tvec4(v1.x) >>= v2; } template GLM_FUNC_QUALIFIER tvec4 operator>>(tvec4 const & v1, tvec4 const & v2) { - return tvec4( - v1.x >> v2.x, - v1.y >> v2.y, - v1.z >> v2.z, - v1.w >> v2.w); + return tvec4(v1) >>= v2; } template GLM_FUNC_QUALIFIER tvec4 operator~(tvec4 const & v) { - return tvec4( - ~v.x, - ~v.y, - ~v.z, - ~v.w); + return tvec4(~v.x, ~v.y, ~v.z, ~v.w); } // -- Boolean operators -- From 3081b44ed242b08af28b2386ddfbf69584ecafaa Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 23 May 2016 21:45:08 +0200 Subject: [PATCH 5/6] Use unary bit operators for binary implementation --- glm/detail/type_vec4.inl | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index 8533e516..e4c331d8 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -830,51 +830,31 @@ namespace detail template GLM_FUNC_QUALIFIER tvec4 operator|(tvec4 const & v, T scalar) { - return tvec4( - v.x | scalar, - v.y | scalar, - v.z | scalar, - v.w | scalar); + return tvec4(v) |= scalar; } template - GLM_FUNC_QUALIFIER tvec4 operator|(tvec4 const & v, tvec1 const & scalar) + GLM_FUNC_QUALIFIER tvec4 operator|(tvec4 const & v1, tvec1 const & v2) { - return tvec4( - v.x | scalar.x, - v.y | scalar.x, - v.z | scalar.x, - v.w | scalar.x); + return tvec4(v1) |= v2; } template GLM_FUNC_QUALIFIER tvec4 operator|(T scalar, tvec4 const & v) { - return tvec4( - scalar | v.x, - scalar | v.y, - scalar | v.z, - scalar | v.w); + return tvec4(scalar) |= v; } template - GLM_FUNC_QUALIFIER tvec4 operator|(tvec1 const & scalar, tvec4 const & v) + GLM_FUNC_QUALIFIER tvec4 operator|(tvec1 const & v1, tvec4 const & v2) { - return tvec4( - scalar.x | v.x, - scalar.x | v.y, - scalar.x | v.z, - scalar.x | v.w); + return tvec4(v1.x) |= v2; } template GLM_FUNC_QUALIFIER tvec4 operator|(tvec4 const & v1, tvec4 const & v2) { - return tvec4( - v1.x | v2.x, - v1.y | v2.y, - v1.z | v2.z, - v1.w | v2.w); + return tvec4(v1) |= v2; } template From b87ead830481016c72f3f20d8906c6a7729f9b3b Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 23 May 2016 21:47:35 +0200 Subject: [PATCH 6/6] Use unary bit operators for binary implementation --- glm/detail/type_vec4.inl | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index e4c331d8..2ee48ce4 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -790,41 +790,25 @@ namespace detail template GLM_FUNC_QUALIFIER tvec4 operator&(tvec4 const & v, tvec1 const & scalar) { - return tvec4( - v.x & scalar.x, - v.y & scalar.x, - v.z & scalar.x, - v.w & scalar.x); + return tvec4(v) &= scalar; } template GLM_FUNC_QUALIFIER tvec4 operator&(T scalar, tvec4 const & v) { - return tvec4( - scalar & v.x, - scalar & v.y, - scalar & v.z, - scalar & v.w); + return tvec4(scalar) &= v; } template - GLM_FUNC_QUALIFIER tvec4 operator&(tvec1 const & scalar, tvec4 const & v) + GLM_FUNC_QUALIFIER tvec4 operator&(tvec1 const & v1, tvec4 const & v2) { - return tvec4( - scalar.x & v.x, - scalar.x & v.y, - scalar.x & v.z, - scalar.x & v.w); + return tvec4(v1.x) &= v2; } template GLM_FUNC_QUALIFIER tvec4 operator&(tvec4 const & v1, tvec4 const & v2) { - return tvec4( - v1.x & v2.x, - v1.y & v2.y, - v1.z & v2.z, - v1.w & v2.w); + return tvec4(v1) &= v2; } template