Merge pull request #1040 from RohacekD/patch-constexpr

Adding constexpr qualifiers for dot and cross product #1040
master
Christophe ago%!(EXTRA string=5 years) committed by GitHub
commit 5a34b3a2d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      glm/detail/func_geometric.inl
  2. 4
      glm/geometric.hpp

@ -28,7 +28,7 @@ namespace detail
template<typename T, qualifier Q, bool Aligned> template<typename T, qualifier Q, bool Aligned>
struct compute_dot<vec<1, T, Q>, T, Aligned> struct compute_dot<vec<1, T, Q>, T, Aligned>
{ {
GLM_FUNC_QUALIFIER static T call(vec<1, T, Q> const& a, vec<1, T, Q> const& b) GLM_FUNC_QUALIFIER GLM_CONSTEXPR static T call(vec<1, T, Q> const& a, vec<1, T, Q> const& b)
{ {
return a.x * b.x; return a.x * b.x;
} }
@ -37,7 +37,7 @@ namespace detail
template<typename T, qualifier Q, bool Aligned> template<typename T, qualifier Q, bool Aligned>
struct compute_dot<vec<2, T, Q>, T, Aligned> struct compute_dot<vec<2, T, Q>, T, Aligned>
{ {
GLM_FUNC_QUALIFIER static T call(vec<2, T, Q> const& a, vec<2, T, Q> const& b) GLM_FUNC_QUALIFIER GLM_CONSTEXPR static T call(vec<2, T, Q> const& a, vec<2, T, Q> const& b)
{ {
vec<2, T, Q> tmp(a * b); vec<2, T, Q> tmp(a * b);
return tmp.x + tmp.y; return tmp.x + tmp.y;
@ -47,7 +47,7 @@ namespace detail
template<typename T, qualifier Q, bool Aligned> template<typename T, qualifier Q, bool Aligned>
struct compute_dot<vec<3, T, Q>, T, Aligned> struct compute_dot<vec<3, T, Q>, T, Aligned>
{ {
GLM_FUNC_QUALIFIER static T call(vec<3, T, Q> const& a, vec<3, T, Q> const& b) GLM_FUNC_QUALIFIER GLM_CONSTEXPR static T call(vec<3, T, Q> const& a, vec<3, T, Q> const& b)
{ {
vec<3, T, Q> tmp(a * b); vec<3, T, Q> tmp(a * b);
return tmp.x + tmp.y + tmp.z; return tmp.x + tmp.y + tmp.z;
@ -57,7 +57,7 @@ namespace detail
template<typename T, qualifier Q, bool Aligned> template<typename T, qualifier Q, bool Aligned>
struct compute_dot<vec<4, T, Q>, T, Aligned> struct compute_dot<vec<4, T, Q>, T, Aligned>
{ {
GLM_FUNC_QUALIFIER static T call(vec<4, T, Q> const& a, vec<4, T, Q> const& b) GLM_FUNC_QUALIFIER GLM_CONSTEXPR static T call(vec<4, T, Q> const& a, vec<4, T, Q> const& b)
{ {
vec<4, T, Q> tmp(a * b); vec<4, T, Q> tmp(a * b);
return (tmp.x + tmp.y) + (tmp.z + tmp.w); return (tmp.x + tmp.y) + (tmp.z + tmp.w);
@ -67,7 +67,7 @@ namespace detail
template<typename T, qualifier Q, bool Aligned> template<typename T, qualifier Q, bool Aligned>
struct compute_cross struct compute_cross
{ {
GLM_FUNC_QUALIFIER static vec<3, T, Q> call(vec<3, T, Q> const& x, vec<3, T, Q> const& y) GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<3, T, Q> call(vec<3, T, Q> const& x, vec<3, T, Q> const& y)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'cross' accepts only floating-point inputs"); GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'cross' accepts only floating-point inputs");
@ -157,14 +157,14 @@ namespace detail
// dot // dot
template<typename T> template<typename T>
GLM_FUNC_QUALIFIER T dot(T x, T y) GLM_FUNC_QUALIFIER GLM_CONSTEXPR T dot(T x, T y)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'dot' accepts only floating-point inputs"); GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'dot' accepts only floating-point inputs");
return x * y; return x * y;
} }
template<length_t L, typename T, qualifier Q> template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER T dot(vec<L, T, Q> const& x, vec<L, T, Q> const& y) GLM_FUNC_QUALIFIER GLM_CONSTEXPR T dot(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'dot' accepts only floating-point inputs"); GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'dot' accepts only floating-point inputs");
return detail::compute_dot<vec<L, T, Q>, T, detail::is_aligned<Q>::value>::call(x, y); return detail::compute_dot<vec<L, T, Q>, T, detail::is_aligned<Q>::value>::call(x, y);
@ -172,7 +172,7 @@ namespace detail
// cross // cross
template<typename T, qualifier Q> template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<3, T, Q> cross(vec<3, T, Q> const& x, vec<3, T, Q> const& y) GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<3, T, Q> cross(vec<3, T, Q> const& x, vec<3, T, Q> const& y)
{ {
return detail::compute_cross<T, Q, detail::is_aligned<Q>::value>::call(x, y); return detail::compute_cross<T, Q, detail::is_aligned<Q>::value>::call(x, y);
} }

@ -47,7 +47,7 @@ namespace glm
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/dot.xml">GLSL dot man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/dot.xml">GLSL dot man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a>
template<length_t L, typename T, qualifier Q> template<length_t L, typename T, qualifier Q>
GLM_FUNC_DECL T dot(vec<L, T, Q> const& x, vec<L, T, Q> const& y); GLM_FUNC_DECL GLM_CONSTEXPR T dot(vec<L, T, Q> const& x, vec<L, T, Q> const& y);
/// Returns the cross product of x and y. /// Returns the cross product of x and y.
/// ///
@ -56,7 +56,7 @@ namespace glm
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/cross.xml">GLSL cross man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/cross.xml">GLSL cross man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a>
template<typename T, qualifier Q> template<typename T, qualifier Q>
GLM_FUNC_DECL vec<3, T, Q> cross(vec<3, T, Q> const& x, vec<3, T, Q> const& y); GLM_FUNC_DECL GLM_CONSTEXPR vec<3, T, Q> cross(vec<3, T, Q> const& x, vec<3, T, Q> const& y);
/// Returns a vector in the same direction as x but with length of 1. /// Returns a vector in the same direction as x but with length of 1.
/// According to issue 10 GLSL 1.10 specification, if length(x) == 0 then result is undefined and generate an error. /// According to issue 10 GLSL 1.10 specification, if length(x) == 0 then result is undefined and generate an error.

Loading…
Cancel
Save