Fixed swizzle functions and tests

This commit is contained in:
Groove
2018-07-12 00:36:59 +02:00
parent e30685ef96
commit c7b6cf56e3
14 changed files with 319 additions and 211 deletions

View File

@@ -50,7 +50,7 @@ int test_vec4_ctor()
}
#endif
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT
{
glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A.xyzw;
@@ -79,7 +79,36 @@ int test_vec4_ctor()
Error += glm::all(glm::equal(A, L)) ? 0 : 1;
Error += glm::all(glm::equal(A, M)) ? 0 : 1;
}
#endif//GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
# elif GLM_SWIZZLE == GLM_ENABLE
{
glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A.xyzw();
glm::vec4 C(A.xyzw());
glm::vec4 D(A.xyzw());
glm::vec4 E(A.x, A.yzw());
glm::vec4 F(A.x, A.yzw());
glm::vec4 G(A.xyz(), A.w);
glm::vec4 H(A.xyz(), A.w);
glm::vec4 I(A.xy(), A.zw());
glm::vec4 J(A.xy(), A.zw());
glm::vec4 K(A.x, A.y, A.zw());
glm::vec4 L(A.x, A.yz(), A.w);
glm::vec4 M(A.xy(), A.z, A.w);
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
Error += glm::all(glm::equal(A, E)) ? 0 : 1;
Error += glm::all(glm::equal(A, F)) ? 0 : 1;
Error += glm::all(glm::equal(A, G)) ? 0 : 1;
Error += glm::all(glm::equal(A, H)) ? 0 : 1;
Error += glm::all(glm::equal(A, I)) ? 0 : 1;
Error += glm::all(glm::equal(A, J)) ? 0 : 1;
Error += glm::all(glm::equal(A, K)) ? 0 : 1;
Error += glm::all(glm::equal(A, L)) ? 0 : 1;
Error += glm::all(glm::equal(A, M)) ? 0 : 1;
}
# endif//GLM_SWIZZLE == GLM_ENABLE
{
glm::vec4 A(1);
@@ -311,7 +340,7 @@ int test_vec4_swizzle_partial()
glm::vec4 A(1, 2, 3, 4);
# if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE_RELAX)
# if GLM_HAS_ANONYMOUS_STRUCT && GLM_SWIZZLE == GLM_ENABLE
{
glm::vec4 B(A.xy, A.zw);
Error += A == B ? 0 : 1;

View File

@@ -2,20 +2,18 @@
#define GLM_FORCE_SWIZZLE
#include <glm/glm.hpp>
#if !GLM_HAS_ONLY_XYZW
static int test_ivec2_swizzle()
{
int Error = 0;
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
#if GLM_SWIZZLE == GLM_ENABLE
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_SWIZZLE_ENABLED
#endif//GLM_SWIZZLE == GLM_ENABLE
return Error;
}
@@ -24,14 +22,14 @@ int test_ivec3_swizzle()
{
int Error = 0;
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
#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_SWIZZLE_ENABLED
#endif//GLM_SWIZZLE == GLM_ENABLE
return Error;
}
@@ -40,14 +38,14 @@ int test_ivec4_swizzle()
{
int Error = 0;
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
#if GLM_SWIZZLE == GLM_ENABLE
glm::ivec4 A(1, 2, 3, 4);
glm::ivec4 B = A.wzyx();
glm::ivec4 C = B.wzyx();
Error += A != B ? 0 : 1;
Error += A == C ? 0 : 1;
#endif//GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
#endif//GLM_SWIZZLE == GLM_ENABLE
return Error;
}
@@ -56,7 +54,7 @@ int test_vec4_swizzle()
{
int Error = 0;
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
#if GLM_SWIZZLE == GLM_ENABLE
glm::vec4 A(1, 2, 3, 4);
glm::vec4 B = A.wzyx();
glm::vec4 C = B.wzyx();
@@ -66,23 +64,19 @@ int test_vec4_swizzle()
float f = glm::dot(C.wzyx(), C.xyzw());
Error += glm::abs(f - 20.f) < 0.01f ? 0 : 1;
#endif//GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
#endif//GLM_SWIZZLE == GLM_ENABLE
return Error;
}
#endif//!GLM_HAS_ONLY_XYZW
int main()
{
int Error = 0;
# if !GLM_HAS_ONLY_XYZW
Error += test_ivec2_swizzle();
Error += test_ivec3_swizzle();
Error += test_ivec4_swizzle();
Error += test_vec4_swizzle();
# endif//!GLM_HAS_ONLY_XYZW
Error += test_ivec2_swizzle();
Error += test_ivec3_swizzle();
Error += test_ivec4_swizzle();
Error += test_vec4_swizzle();
return Error;
}

View File

@@ -69,18 +69,6 @@ int test_vec1_ctor()
}
#endif
*/
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
{
glm::vec2 A = glm::vec2(1.0f, 2.0f);
glm::vec2 B = A.xy;
glm::vec2 C(A.xy);
glm::vec2 D(A.xy());
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
}
#endif//GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
{
glm::vec2 A = glm::vec2(2.0f);
@@ -137,6 +125,24 @@ static int test_vec1_operator_increment()
return Error;
}
static int test_swizzle()
{
int Error = 0;
#if GLM_HAS_ANONYMOUS_STRUCT && GLM_SWIZZLE == GLM_ENABLE
{
glm::vec1 A = glm::vec1(1.0f);
//glm::vec1 B = A.x;
glm::vec1 C(A.x);
//Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
}
#endif//GLM_SWIZZLE == GLM_ENABLE
return Error;
}
static int test_constexpr()
{
#if GLM_HAS_CONSTEXPR_CXX14
@@ -155,6 +161,7 @@ int main()
Error += test_vec1_ctor();
Error += test_vec1_operators();
Error += test_vec1_operator_increment();
Error += test_swizzle();
Error += test_constexpr();
return Error;

View File

@@ -236,19 +236,6 @@ static int test_ctor()
}
#endif
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
{
glm::vec2 A = glm::vec2(1.0f, 2.0f);
glm::vec2 B = A.xy;
glm::vec2 C(A.xy);
glm::vec2 D(A.xy());
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
}
#endif//GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
{
glm::vec2 A = glm::vec2(2.0f);
glm::vec2 B = glm::vec2(2.0f, 3.0f);
@@ -357,6 +344,35 @@ static int test_constexpr()
return 0;
}
static int test_swizzle()
{
int Error = 0;
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT
{
glm::vec2 A = glm::vec2(1.0f, 2.0f);
glm::vec2 B = A.xy;
glm::vec2 C(A.xy);
glm::vec2 D(A.xy());
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
}
# elif GLM_SWIZZLE == GLM_ENABLE
{
glm::vec2 A = glm::vec2(1.0f, 2.0f);
glm::vec2 B = A.xy();
glm::vec2 C(A.xy());
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
}
# endif//GLM_SWIZZLE == GLM_ENABLE
return Error;
}
int main()
{
int Error = 0;
@@ -365,6 +381,7 @@ int main()
Error += test_ctor();
Error += test_operators();
Error += test_operator_increment();
Error += test_swizzle();
Error += test_constexpr();
return Error;

View File

@@ -27,7 +27,7 @@ int test_vec3_ctor()
Error += std::is_copy_constructible<glm::vec3>::value ? 0 : 1;
# endif
#if (GLM_HAS_INITIALIZER_LISTS)
# if GLM_HAS_INITIALIZER_LISTS
{
glm::vec3 a{ 0, 1, 2 };
std::vector<glm::vec3> v = {
@@ -43,28 +43,7 @@ int test_vec3_ctor()
{4, 5, 6},
{8, 9, 0}};
}
#endif
#if(GLM_LANG & GLM_LANG_CXXMS_FLAG && defined(GLM_FORCE_SWIZZLE))
{
glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f);
glm::vec3 B = A.xyz;
glm::vec3 C(A.xyz);
glm::vec3 D(A.xyz());
glm::vec3 E(A.x, A.yz);
glm::vec3 F(A.x, A.yz());
glm::vec3 G(A.xy, A.z);
glm::vec3 H(A.xy(), A.z);
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
Error += glm::all(glm::equal(A, E)) ? 0 : 1;
Error += glm::all(glm::equal(A, F)) ? 0 : 1;
Error += glm::all(glm::equal(A, G)) ? 0 : 1;
Error += glm::all(glm::equal(A, H)) ? 0 : 1;
}
#endif//(GLM_LANG & GLM_LANG_CXXMS_FLAG && defined(GLM_FORCE_SWIZZLE))
# endif
{
glm::vec3 A(1);
@@ -338,7 +317,7 @@ int test_vec3_swizzle3_2()
{
int Error = 0;
# if(GLM_LANG & GLM_LANG_CXXMS_FLAG)
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT
glm::vec3 v(1, 2, 3);
glm::vec2 u;
@@ -402,7 +381,7 @@ int test_vec3_swizzle3_3()
{
int Error = 0;
# if(GLM_LANG & GLM_LANG_CXXMS_FLAG)
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT
glm::vec3 v(1, 2, 3);
glm::vec3 u;
@@ -424,7 +403,6 @@ int test_vec3_swizzle3_3()
return Error;
}
#if !GLM_HAS_ONLY_XYZW
int test_vec3_swizzle_operators()
{
int Error = 0;
@@ -432,7 +410,7 @@ int test_vec3_swizzle_operators()
glm::vec3 u = glm::vec3(1, 2, 3);
glm::vec3 v = glm::vec3(10, 20, 30);
# if(GLM_LANG & GLM_LANG_CXXMS_FLAG)
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT
glm::vec3 q;
// Swizzle, swizzle binary operators
@@ -469,7 +447,7 @@ int test_vec3_swizzle_functions()
{
int Error = 0;
# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
# if GLM_SWIZZLE == GLM_ENABLE
// NOTE: template functions cannot pick up the implicit conversion from
// a swizzle to the unswizzled type, therefore the operator() must be
@@ -503,7 +481,7 @@ int test_vec3_swizzle_functions()
r = glm::dot(s.xyzw(), t.xyzw()); Error += (int(r) == 300) ? 0 : 1;
r = glm::dot(s.xyz(), t.xyz()); Error += (int(r) == 140) ? 0 : 1;
#endif//GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
#endif//GLM_SWIZZLE == GLM_ENABLE
return Error;
}
@@ -512,9 +490,10 @@ int test_vec3_swizzle_partial()
{
int Error = 0;
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT
glm::vec3 A(1, 2, 3);
# if(GLM_LANG & GLM_LANG_CXXMS_FLAG)
{
glm::vec3 B(A.xy, 3.0f);
Error += A == B ? 0 : 1;
@@ -529,15 +508,14 @@ int test_vec3_swizzle_partial()
glm::vec3 B(A.xyz);
Error += A == B ? 0 : 1;
}
# endif//GLM_LANG
# endif//GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT
return Error;
}
#endif//!GLM_HAS_ONLY_XYZW
static int test_operator_increment()
{
int Error(0);
int Error = 0;
glm::ivec3 v0(1);
glm::ivec3 v1(v0);
@@ -562,6 +540,53 @@ static int test_operator_increment()
return Error;
}
static int test_swizzle()
{
int Error = 0;
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT
{
glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f);
glm::vec3 B = A.xyz;
glm::vec3 C(A.xyz);
glm::vec3 D(A.xyz());
glm::vec3 E(A.x, A.yz);
glm::vec3 F(A.x, A.yz());
glm::vec3 G(A.xy, A.z);
glm::vec3 H(A.xy(), A.z);
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
Error += glm::all(glm::equal(A, E)) ? 0 : 1;
Error += glm::all(glm::equal(A, F)) ? 0 : 1;
Error += glm::all(glm::equal(A, G)) ? 0 : 1;
Error += glm::all(glm::equal(A, H)) ? 0 : 1;
}
# elif GLM_SWIZZLE == GLM_ENABLE
{
glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f);
glm::vec3 B = A.xyz();
glm::vec3 C(A.xyz());
glm::vec3 D(A.xyz());
glm::vec3 E(A.x, A.yz());
glm::vec3 F(A.x, A.yz());
glm::vec3 G(A.xy(), A.z);
glm::vec3 H(A.xy(), A.z);
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
Error += glm::all(glm::equal(A, E)) ? 0 : 1;
Error += glm::all(glm::equal(A, F)) ? 0 : 1;
Error += glm::all(glm::equal(A, G)) ? 0 : 1;
Error += glm::all(glm::equal(A, H)) ? 0 : 1;
}
# endif//GLM_SWIZZLE == GLM_ENABLE
return Error;
}
static int test_constexpr()
{
#if GLM_HAS_CONSTEXPR_CXX14
@@ -583,16 +608,15 @@ int main()
Error += test_bvec3_ctor();
Error += test_vec3_operators();
Error += test_vec3_size();
Error += test_vec3_swizzle3_2();
Error += test_vec3_swizzle3_3();
Error += test_operator_increment();
Error += test_constexpr();
# if !GLM_HAS_ONLY_XYZW
Error += test_vec3_swizzle_partial();
Error += test_vec3_swizzle_operators();
Error += test_vec3_swizzle_functions();
# endif//!GLM_HAS_ONLY_XYZW
Error += test_swizzle();
Error += test_vec3_swizzle3_2();
Error += test_vec3_swizzle3_3();
Error += test_vec3_swizzle_partial();
Error += test_vec3_swizzle_operators();
Error += test_vec3_swizzle_functions();
return Error;
}

View File

@@ -74,37 +74,6 @@ static int test_vec4_ctor()
}
#endif
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
{
glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A.xyzw;
glm::vec4 C(A.xyzw);
glm::vec4 D(A.xyzw());
glm::vec4 E(A.x, A.yzw);
glm::vec4 F(A.x, A.yzw());
glm::vec4 G(A.xyz, A.w);
glm::vec4 H(A.xyz(), A.w);
glm::vec4 I(A.xy, A.zw);
glm::vec4 J(A.xy(), A.zw());
glm::vec4 K(A.x, A.y, A.zw);
glm::vec4 L(A.x, A.yz, A.w);
glm::vec4 M(A.xy, A.z, A.w);
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
Error += glm::all(glm::equal(A, E)) ? 0 : 1;
Error += glm::all(glm::equal(A, F)) ? 0 : 1;
Error += glm::all(glm::equal(A, G)) ? 0 : 1;
Error += glm::all(glm::equal(A, H)) ? 0 : 1;
Error += glm::all(glm::equal(A, I)) ? 0 : 1;
Error += glm::all(glm::equal(A, J)) ? 0 : 1;
Error += glm::all(glm::equal(A, K)) ? 0 : 1;
Error += glm::all(glm::equal(A, L)) ? 0 : 1;
Error += glm::all(glm::equal(A, M)) ? 0 : 1;
}
#endif// GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
{
glm::vec4 A(1);
glm::vec4 B(1, 1, 1, 1);
@@ -516,7 +485,7 @@ static int test_swizzle_partial()
glm::vec4 A(1, 2, 3, 4);
# if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE_RELAX)
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT
{
glm::vec4 B(A.xy, A.zw);
Error += A == B ? 0 : 1;
@@ -542,7 +511,74 @@ static int test_swizzle_partial()
glm::vec4 B(1.0f, A.yzw);
Error += A == B ? 0 : 1;
}
# endif
# endif//GLM_SWIZZLE == GLM_ENABLE
return Error;
}
static int test_swizzle()
{
int Error = 0;
# if GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT
{
glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A.xyzw;
glm::vec4 C(A.xyzw);
glm::vec4 D(A.xyzw());
glm::vec4 E(A.x, A.yzw);
glm::vec4 F(A.x, A.yzw());
glm::vec4 G(A.xyz, A.w);
glm::vec4 H(A.xyz(), A.w);
glm::vec4 I(A.xy, A.zw);
glm::vec4 J(A.xy(), A.zw());
glm::vec4 K(A.x, A.y, A.zw);
glm::vec4 L(A.x, A.yz, A.w);
glm::vec4 M(A.xy, A.z, A.w);
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
Error += glm::all(glm::equal(A, E)) ? 0 : 1;
Error += glm::all(glm::equal(A, F)) ? 0 : 1;
Error += glm::all(glm::equal(A, G)) ? 0 : 1;
Error += glm::all(glm::equal(A, H)) ? 0 : 1;
Error += glm::all(glm::equal(A, I)) ? 0 : 1;
Error += glm::all(glm::equal(A, J)) ? 0 : 1;
Error += glm::all(glm::equal(A, K)) ? 0 : 1;
Error += glm::all(glm::equal(A, L)) ? 0 : 1;
Error += glm::all(glm::equal(A, M)) ? 0 : 1;
}
# elif GLM_SWIZZLE == GLM_ENABLE
{
glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A.xyzw();
glm::vec4 C(A.xyzw());
glm::vec4 D(A.xyzw());
glm::vec4 E(A.x, A.yzw());
glm::vec4 F(A.x, A.yzw());
glm::vec4 G(A.xyz(), A.w);
glm::vec4 H(A.xyz(), A.w);
glm::vec4 I(A.xy(), A.zw());
glm::vec4 J(A.xy(), A.zw());
glm::vec4 K(A.x, A.y, A.zw());
glm::vec4 L(A.x, A.yz(), A.w);
glm::vec4 M(A.xy(), A.z, A.w);
Error += glm::all(glm::equal(A, B)) ? 0 : 1;
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
Error += glm::all(glm::equal(A, E)) ? 0 : 1;
Error += glm::all(glm::equal(A, F)) ? 0 : 1;
Error += glm::all(glm::equal(A, G)) ? 0 : 1;
Error += glm::all(glm::equal(A, H)) ? 0 : 1;
Error += glm::all(glm::equal(A, I)) ? 0 : 1;
Error += glm::all(glm::equal(A, J)) ? 0 : 1;
Error += glm::all(glm::equal(A, K)) ? 0 : 1;
Error += glm::all(glm::equal(A, L)) ? 0 : 1;
Error += glm::all(glm::equal(A, M)) ? 0 : 1;
}
# endif//GLM_SWIZZLE == GLM_ENABLE && GLM_HAS_ANONYMOUS_STRUCT
return Error;
}
@@ -782,6 +818,7 @@ int main()
Error += test_size();
Error += test_operators();
Error += test_equal();
Error += test_swizzle();
Error += test_swizzle_partial();
Error += test_simd();
Error += test_operator_increment();

View File

@@ -1,4 +1,6 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#if GLM_LANG & GLM_LANG_CXXMS_FLAG
#include <glm/gtc/type_precision.hpp>
#include <glm/gtx/io.hpp>
#include <iostream>
@@ -174,3 +176,11 @@ int main()
return Error;
}
#else
int main()
{
return 0;
}
#endif// GLM_LANG & GLM_LANG_CXXMS_FLAG