Refactored GLM_FORCE_MESSAGES, added swizzle operators and functions tests

This commit is contained in:
Christophe Riccio 2018-07-14 17:56:40 +02:00
parent d50c699515
commit 4db3abe6b5
6 changed files with 140 additions and 83 deletions

View File

@ -360,6 +360,10 @@
((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC14) && (GLM_ARCH & GLM_ARCH_X86_BIT))))
#endif
///////////////////////////////////////////////////////////////////////////////////
#define GLM_HAS_ANONYMOUS_STRUCT (GLM_LANG & GLM_LANG_CXXMS_FLAG)
///////////////////////////////////////////////////////////////////////////////////
// OpenMP
#ifdef _OPENMP
@ -465,8 +469,13 @@
// User defines: GLM_FORCE_SWIZZLE
#if defined(GLM_FORCE_SWIZZLE)
# define GLM_SWIZZLE GLM_ENABLE
#define GLM_SWIZZLE_OPERATOR 1
#define GLM_SWIZZLE_FUNCTION 2
#if defined(GLM_FORCE_SWIZZLE) && GLM_HAS_ANONYMOUS_STRUCT
# define GLM_SWIZZLE GLM_SWIZZLE_OPERATOR
#elif defined(GLM_FORCE_SWIZZLE)
# define GLM_SWIZZLE GLM_SWIZZLE_FUNCTION
#else
# define GLM_SWIZZLE GLM_DISABLE
#endif
@ -477,9 +486,9 @@
// #define GLM_FORCE_UNRESTRICTED_GENTYPE
#ifdef GLM_FORCE_UNRESTRICTED_GENTYPE
# define GLM_UNRESTRICTED_GENTYPE 1
# define GLM_UNRESTRICTED_GENTYPE GLM_ENABLE
#else
# define GLM_UNRESTRICTED_GENTYPE 0
# define GLM_UNRESTRICTED_GENTYPE GLM_DISABLE
#endif
///////////////////////////////////////////////////////////////////////////////////
@ -581,10 +590,6 @@
# define GLM_EXPLICIT
#endif
///////////////////////////////////////////////////////////////////////////////////
#define GLM_HAS_ANONYMOUS_STRUCT (GLM_LANG & GLM_LANG_CXXMS_FLAG)
///////////////////////////////////////////////////////////////////////////////////
// Length type: all length functions returns a length_t type.
// When GLM_FORCE_SIZE_T_LENGTH is defined, length_t is a typedef of size_t otherwise
@ -802,37 +807,41 @@ namespace glm
# endif
// Report swizzle operator support
# if GLM_SWIZZLE == GLM_ENABLE
# pragma message("GLM: Swizzling operators enabled")
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
# pragma message("GLM: GLM_FORCE_SWIZZLE is defined, swizzling operators enabled")
# elif GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
# pragma message("GLM: GLM_FORCE_SWIZZLE is defined, swizzling functions enabled. Enable compiler C++ language extensions to enable swizzle operators.")
# else
# pragma message("GLM: Swizzling operators disabled, #define GLM_FORCE_SWIZZLE to enable swizzle operators")
# pragma message("GLM: GLM_FORCE_SWIZZLE is undefined. swizzling functions or operators are disabled.")
# endif
// Report .length() type
# if defined GLM_FORCE_SIZE_T_LENGTH
# pragma message("GLM: .length() returns glm::length_t, a typedef of std::size_t")
# pragma message("GLM: GLM_FORCE_SIZE_T_LENGTH is defined. .length() returns a glm::length_t, a typedef of std::size_t instead of int.")
# else
# pragma message("GLM: .length() returns glm::length_t, a typedef of int following the GLSL specification")
# pragma message("GLM: GLM_FORCE_SIZE_T_LENGTH is undefined. .length() returns a glm::length_t, a typedef of int following the GLSL specification. Define GLM_FORCE_SIZE_T_LENGTH to make glm::length_t, a typedef of std::size_t.")
# endif
# ifdef GLM_FORCE_UNRESTRICTED_GENTYPE
# pragma message("GLM: Use unrestricted genType")
# pragma message("GLM: GLM_FORCE_UNRESTRICTED_GENTYPE is defined. Removes GLSL specification restrictions on valid function genTypes.")
# else
# pragma message("GLM: GLM_FORCE_UNRESTRICTED_GENTYPE is undefined. Follows strictly GLSL specification on valid function genTypes.")
# endif
# ifdef GLM_FORCE_SINGLE_ONLY
# pragma message("GLM: Using only single precision floating-point types")
# pragma message("GLM: GLM_FORCE_SINGLE_ONLY is defined. Using only single precision floating-point types")
# endif
# if GLM_DEPTH_CLIP_SPACE == GLM_DEPTH_ZERO_TO_ONE
# pragma message("GLM: Depth clip space: Zero to one")
# pragma message("GLM: GLM_FORCE_DEPTH_ZERO_TO_ONE is defined. Using zero to one depth clip space.")
# else
# pragma message("GLM: Depth clip space: negative one to one")
# pragma message("GLM: GLM_FORCE_DEPTH_ZERO_TO_ONE is undefined. Using negative one to one depth clip space.")
# endif
# if GLM_COORDINATE_SYSTEM == GLM_LEFT_HANDED
# pragma message("GLM: Coordinate system: left handed")
# pragma message("GLM: GLM_FORCE_LEFT_HANDED is defined. Using left handed coordinate system.")
# else
# pragma message("GLM: Coordinate system: right handed")
# pragma message("GLM: GLM_FORCE_LEFT_HANDED is undefined. Using right handed coordinate system.")
# endif
#endif//GLM_MESSAGES

View File

@ -4,13 +4,11 @@
#pragma once
#include "type_vec.hpp"
#if GLM_SWIZZLE == GLM_ENABLE
# if GLM_HAS_ANONYMOUS_STRUCT
#if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
# include "_swizzle.hpp"
# else
#elif GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
# include "_swizzle_func.hpp"
#endif
#endif //GLM_SWIZZLE
#include <cstddef>
namespace glm
@ -35,7 +33,7 @@ namespace glm
typename detail::storage<2, T, detail::is_aligned<Q>::value>::type data;
# if GLM_SWIZZLE == GLM_ENABLE
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
GLM_SWIZZLE2_2_MEMBERS(T, Q, x, y)
GLM_SWIZZLE2_2_MEMBERS(T, Q, r, g)
GLM_SWIZZLE2_2_MEMBERS(T, Q, s, t)
@ -45,13 +43,13 @@ namespace glm
GLM_SWIZZLE2_4_MEMBERS(T, Q, x, y)
GLM_SWIZZLE2_4_MEMBERS(T, Q, r, g)
GLM_SWIZZLE2_4_MEMBERS(T, Q, s, t)
# endif//GLM_SWIZZLE
# endif
};
# else
union {T x, r, s;};
union {T y, g, t;};
# if GLM_SWIZZLE == GLM_ENABLE
# if GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
GLM_SWIZZLE_GEN_VEC_FROM_VEC2(T, Q)
# endif//GLM_SWIZZLE
# endif
@ -106,13 +104,13 @@ namespace glm
GLM_FUNC_DECL GLM_CONSTEXPR_CXX11 GLM_EXPLICIT vec(vec<2, U, P> const& v);
// -- Swizzle constructors --
# if GLM_HAS_ANONYMOUS_STRUCT && GLM_SWIZZLE == GLM_ENABLE
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
template<int E0, int E1>
GLM_FUNC_DECL vec(detail::_swizzle<2, T, Q, E0, E1,-1,-2> const& that)
{
*this = that();
}
# endif//GLM_SWIZZLE == GLM_ENABLE
# endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
// -- Unary arithmetic operators --

View File

@ -4,13 +4,11 @@
#pragma once
#include "type_vec.hpp"
#if GLM_SWIZZLE == GLM_ENABLE
# if GLM_HAS_ANONYMOUS_STRUCT
#if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
# include "_swizzle.hpp"
# else
#elif GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
# include "_swizzle_func.hpp"
#endif
#endif //GLM_SWIZZLE == GLM_ENABLE
#include <cstddef>
namespace glm
@ -35,7 +33,7 @@ namespace glm
typename detail::storage<3, T, detail::is_aligned<Q>::value>::type data;
# if GLM_SWIZZLE == GLM_ENABLE
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
GLM_SWIZZLE3_2_MEMBERS(T, Q, x, y, z)
GLM_SWIZZLE3_2_MEMBERS(T, Q, r, g, b)
GLM_SWIZZLE3_2_MEMBERS(T, Q, s, t, p)
@ -45,14 +43,14 @@ namespace glm
GLM_SWIZZLE3_4_MEMBERS(T, Q, x, y, z)
GLM_SWIZZLE3_4_MEMBERS(T, Q, r, g, b)
GLM_SWIZZLE3_4_MEMBERS(T, Q, s, t, p)
# endif//GLM_SWIZZLE
# endif
};
# else
union { T x, r, s; };
union { T y, g, t; };
union { T z, b, p; };
# if GLM_SWIZZLE == GLM_ENABLE
# if GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
GLM_SWIZZLE_GEN_VEC_FROM_VEC3(T, Q)
# endif//GLM_SWIZZLE
# endif//GLM_LANG
@ -124,7 +122,7 @@ namespace glm
GLM_FUNC_DECL GLM_CONSTEXPR_CXX11 GLM_EXPLICIT vec(vec<3, U, P> const& v);
// -- Swizzle constructors --
# if GLM_HAS_ANONYMOUS_STRUCT && GLM_SWIZZLE == GLM_ENABLE
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
template<int E0, int E1, int E2>
GLM_FUNC_DECL vec(detail::_swizzle<3, T, Q, E0, E1, E2, -1> const& that)
{
@ -142,7 +140,7 @@ namespace glm
{
*this = vec(scalar, v());
}
# endif//GLM_HAS_ANONYMOUS_STRUCT && GLM_SWIZZLE == GLM_ENABLE
# endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
// -- Unary arithmetic operators --

View File

@ -4,13 +4,11 @@
#pragma once
#include "type_vec.hpp"
#if GLM_SWIZZLE == GLM_ENABLE
# if GLM_HAS_ANONYMOUS_STRUCT
#if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
# include "_swizzle.hpp"
# else
#elif GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
# include "_swizzle_func.hpp"
#endif
#endif //GLM_SWIZZLE
#include <cstddef>
namespace glm
@ -35,7 +33,7 @@ namespace glm
typename detail::storage<4, T, detail::is_aligned<Q>::value>::type data;
# if GLM_SWIZZLE == GLM_ENABLE
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
GLM_SWIZZLE4_2_MEMBERS(T, Q, x, y, z, w)
GLM_SWIZZLE4_2_MEMBERS(T, Q, r, g, b, a)
GLM_SWIZZLE4_2_MEMBERS(T, Q, s, t, p, q)
@ -45,7 +43,7 @@ namespace glm
GLM_SWIZZLE4_4_MEMBERS(T, Q, x, y, z, w)
GLM_SWIZZLE4_4_MEMBERS(T, Q, r, g, b, a)
GLM_SWIZZLE4_4_MEMBERS(T, Q, s, t, p, q)
# endif//GLM_SWIZZLE
# endif
};
# else
union { T x, r, s; };
@ -53,9 +51,9 @@ namespace glm
union { T z, b, p; };
union { T w, a, q; };
# if GLM_SWIZZLE == GLM_ENABLE
# if GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
GLM_SWIZZLE_GEN_VEC_FROM_VEC4(T, Q)
# endif//GLM_SWIZZLE
# endif
# endif
// -- Component accesses --
@ -175,7 +173,7 @@ namespace glm
GLM_FUNC_DECL GLM_CONSTEXPR_CXX11 GLM_EXPLICIT vec(vec<4, U, P> const& v);
// -- Swizzle constructors --
# if GLM_HAS_ANONYMOUS_STRUCT && GLM_SWIZZLE == GLM_ENABLE
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
template<int E0, int E1, int E2, int E3>
GLM_FUNC_DECL vec(detail::_swizzle<4, T, Q, E0, E1, E2, E3> const& that)
{
@ -217,7 +215,7 @@ namespace glm
{
*this = vec<4, T, Q>(x, v());
}
# endif//GLM_HAS_ANONYMOUS_STRUCT && GLM_SWIZZLE == GLM_ENABLE
# endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
// -- Unary arithmetic operators --

View File

@ -14,13 +14,11 @@
#include "../fwd.hpp"
#include "../detail/type_vec.hpp"
#if GLM_SWIZZLE == GLM_ENABLE
# if GLM_HAS_ANONYMOUS_STRUCT
# include "../detail/_swizzle.hpp"
# else
# include "../detail/_swizzle_func.hpp"
#if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
# include "_swizzle.hpp"
#elif GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
# include "_swizzle_func.hpp"
#endif
#endif //GLM_SWIZZLE
#include <cstddef>
#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
@ -52,7 +50,7 @@ namespace glm
typename detail::storage<1, T, detail::is_aligned<Q>::value>::type data;
/*
# if GLM_SWIZZLE == GLM_ENABLE
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
_GLM_SWIZZLE1_2_MEMBERS(T, Q, tvec2, x)
_GLM_SWIZZLE1_2_MEMBERS(T, Q, tvec2, r)
_GLM_SWIZZLE1_2_MEMBERS(T, Q, tvec2, s)
@ -62,14 +60,16 @@ namespace glm
_GLM_SWIZZLE1_4_MEMBERS(T, Q, tvec4, x)
_GLM_SWIZZLE1_4_MEMBERS(T, Q, tvec4, r)
_GLM_SWIZZLE1_4_MEMBERS(T, Q, tvec4, s)
# endif//GLM_SWIZZLE*/
# endif
*/
};
# else
union {T x, r, s;};
/*
# if GLM_SWIZZLE == GLM_ENABLE
# if GLM_SWIZZLE == GLM_SWIZZLE_FUNCTION
GLM_SWIZZLE_GEN_VEC_FROM_VEC1(T, Q, tvec2, tvec2, tvec3, tvec4)
# endif//GLM_SWIZZLE*/
# endif
*/
# endif
// -- Component accesses --
@ -110,13 +110,13 @@ namespace glm
// -- Swizzle constructors --
/*
# if GLM_HAS_ANONYMOUS_STRUCT && GLM_SWIZZLE == GLM_ENABLE
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
template<int E0>
GLM_FUNC_DECL tvec(detail::_swizzle<1, T, Q, tvec1, E0, -1,-2,-3> const& that)
{
*this = that();
}
# endif//GLM_SWIZZLE == GLM_ENABLE
# endif//GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
*/
// -- Unary arithmetic operators --

View File

@ -6,14 +6,39 @@ static int test_ivec2_swizzle()
{
int Error = 0;
#if GLM_SWIZZLE == GLM_ENABLE
# if GLM_SWIZZLE
{
glm::ivec2 A(1, 2);
glm::ivec2 B = A.yx();
glm::ivec2 C = B.yx();
Error += A != B ? 0 : 1;
Error += A == C ? 0 : 1;
#endif//GLM_SWIZZLE == GLM_ENABLE
}
# endif//GLM_SWIZZLE
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{
glm::ivec2 A(1, 2);
glm::ivec2 B = A.yx;
glm::ivec2 C = A.yx;
Error += A != B ? 0 : 1;
Error += B == C ? 0 : 1;
B.xy = B.yx;
C.xy = C.yx;
Error += B == C ? 0 : 1;
glm::ivec2 D(0, 0);
D.yx = A.xy;
Error += A.yx() == D ? 0 : 1;
glm::ivec2 E = A.yx;
Error += E == D ? 0 : 1;
}
# endif//GLM_SWIZZLE
return Error;
}
@ -23,14 +48,43 @@ int test_ivec3_swizzle()
int Error = 0;
# if GLM_SWIZZLE == GLM_ENABLE
{
glm::ivec3 A(1, 2, 3);
glm::ivec3 B = A.zyx();
glm::ivec3 C = B.zyx();
Error += A != B ? 0 : 1;
Error += A == C ? 0 : 1;
}
# endif//GLM_SWIZZLE == GLM_ENABLE
# if GLM_SWIZZLE == GLM_SWIZZLE_OPERATOR
{
glm::ivec3 A(1, 2, 3);
glm::ivec2 B = A.yx;
glm::ivec2 C = A.yx;
Error += A.yx() == B ? 0 : 1;
Error += B == C ? 0 : 1;
B.xy = B.yx;
C.xy = C.yx;
Error += B == C ? 0 : 1;
glm::ivec2 D(0, 0);
D.yx = A.xy;
Error += A.yx() == D ? 0 : 1;
glm::ivec2 E(0, 0);
E.xy = A.xy();
Error += E == A.xy() ? 0 : 1;
Error += E.xy() == A.xy() ? 0 : 1;
}
# endif//GLM_SWIZZLE
return Error;
}