Enabled swizzle operator by default, removed GLM_SWIZZLE and add GLM_SWIZZLE_RELAX for Visual C++ lang extension implementation.

This commit is contained in:
Christophe Riccio 2013-09-15 17:55:05 +02:00
parent 5d66caa7da
commit 1d9e6dc95c
8 changed files with 82 additions and 96 deletions

View File

@ -56,7 +56,7 @@ namespace detail
//////////////////////////////////////
// Data
# if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
# if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE_RELAX))
union
{
struct{ T x, y; };
@ -77,10 +77,7 @@ namespace detail
union {T x, r, s;};
union {T y, g, t;};
# if(defined(GLM_SWIZZLE))
//GLM_SWIZZLE_GEN_REF_FROM_VEC2(T, P, detail::tvec2, detail::tref2)
GLM_SWIZZLE_GEN_VEC_FROM_VEC2(T, P, detail::tvec2, detail::tvec2, detail::tvec3, detail::tvec4)
# endif//(defined(GLM_SWIZZLE))
GLM_SWIZZLE_GEN_VEC_FROM_VEC2(T, P, detail::tvec2, detail::tvec2, detail::tvec3, detail::tvec4)
# endif//GLM_LANG
//////////////////////////////////////

View File

@ -56,7 +56,7 @@ namespace detail
//////////////////////////////////////
// Data
# if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
# if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE_RELAX))
union
{
struct{ T x, y, z; };
@ -78,10 +78,7 @@ namespace detail
union { T y, g, t; };
union { T z, b, p; };
# if(defined(GLM_SWIZZLE))
//GLM_SWIZZLE_GEN_REF_FROM_VEC3(T, P, detail::tvec3, detail::tref2, detail::tref3)
GLM_SWIZZLE_GEN_VEC_FROM_VEC3(T, P, detail::tvec3, detail::tvec2, detail::tvec3, detail::tvec4)
# endif//(defined(GLM_SWIZZLE))
GLM_SWIZZLE_GEN_VEC_FROM_VEC3(T, P, detail::tvec3, detail::tvec2, detail::tvec3, detail::tvec4)
# endif//GLM_LANG
//////////////////////////////////////

View File

@ -56,7 +56,7 @@ namespace detail
//////////////////////////////////////
// Data
# if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE))
# if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE_RELAX))
union
{
struct { T r, g, b, a; };
@ -79,10 +79,7 @@ namespace detail
union { T z, b, p; };
union { T w, a, q; };
# if(defined(GLM_SWIZZLE))
//GLM_SWIZZLE_GEN_REF_FROM_VEC4(T, P, detail::tvec4, detail::tref2, detail::tref3, detail::tref4)
GLM_SWIZZLE_GEN_VEC_FROM_VEC4(T, P, detail::tvec4, detail::tvec2, detail::tvec3, detail::tvec4)
# endif//(defined(GLM_SWIZZLE))
GLM_SWIZZLE_GEN_VEC_FROM_VEC4(T, P, detail::tvec4, detail::tvec2, detail::tvec3, detail::tvec4)
# endif//GLM_LANG
//////////////////////////////////////

View File

@ -8,7 +8,6 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
#define GLM_MESSAGES
#define GLM_SWIZZLE
#include <glm/glm.hpp>
int test_ivec2_swizzle()

View File

@ -7,7 +7,6 @@
// File : test/core/type_vec1.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#define GLM_SWIZZLE
#include <glm/glm.hpp>
#include <glm/gtx/vec1.hpp>

View File

@ -7,71 +7,70 @@
// File : test/core/type_vec2.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#define GLM_SWIZZLE
#include <glm/glm.hpp>
int test_vec2_operators()
{
int Error = 0;
{
glm::vec2 A(1.0f);
glm::vec2 B(1.0f);
Error += A != B ? 1 : 0;
Error += A == B ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 C = A + 1.0f;
A += 1.0f;
Error += A.x == 2.0f && A.y == 2.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 B(2.0f,-1.0f);
glm::vec2 C = A + B;
A += B;
Error += A.x == 3.0f && A.y == 0.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 C = A - 1.0f;
A -= 1.0f;
Error += A.x == 0.0f && A.y == 0.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 B(2.0f,-1.0f);
glm::vec2 C = A - B;
A -= B;
Error += A.x == -1.0f && A.y == 2.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 C = A * 2.0f;
A *= 2.0f;
Error += A.x == 2.0f && A.y == 2.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(2.0f);
glm::vec2 B(2.0f);
glm::vec2 C = A / B;
A /= B;
Error += A.x == 1.0f && A.y == 1.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
int Error = 0;
{
glm::vec2 A(1.0f);
glm::vec2 B(1.0f);
Error += A != B ? 1 : 0;
Error += A == B ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 C = A + 1.0f;
A += 1.0f;
Error += A.x == 2.0f && A.y == 2.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 B(2.0f,-1.0f);
glm::vec2 C = A + B;
A += B;
Error += A.x == 3.0f && A.y == 0.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 C = A - 1.0f;
A -= 1.0f;
Error += A.x == 0.0f && A.y == 0.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 B(2.0f,-1.0f);
glm::vec2 C = A - B;
A -= B;
Error += A.x == -1.0f && A.y == 2.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 C = A * 2.0f;
A *= 2.0f;
Error += A.x == 2.0f && A.y == 2.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(2.0f);
glm::vec2 B(2.0f);
glm::vec2 C = A / B;
A /= B;
Error += A.x == 1.0f && A.y == 1.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f, 2.0f);
glm::vec2 B(4.0f, 5.0f);
@ -191,20 +190,20 @@ int test_vec2_operators()
int test_vec2_ctor()
{
int Error = 0;
{
glm::vec2 A = glm::vec2(2.0f);
glm::vec2 B = glm::vec2(2.0f, 3.0f);
glm::vec2 C = glm::vec2(2.0f, 3.0);
//glm::vec2 D = glm::dvec2(2.0); // Build error TODO: What does the specification says?
glm::vec2 E(glm::dvec2(2.0));
glm::vec2 F(glm::ivec2(2));
}
int Error = 0;
{
glm::vec2 A = glm::vec2(2.0f);
glm::vec2 B = glm::vec2(2.0f, 3.0f);
glm::vec2 C = glm::vec2(2.0f, 3.0);
//glm::vec2 D = glm::dvec2(2.0); // Build error TODO: What does the specification says?
glm::vec2 E(glm::dvec2(2.0));
glm::vec2 F(glm::ivec2(2));
}
return Error;
}
}
int test_vec2_size()
{
@ -230,7 +229,7 @@ int test_operator_increment()
glm::ivec2 v3 = ++v1;
glm::ivec2 v4 = v2++;
Error += glm::all(glm::equal(v0, v4)) ? 0 : 1;
Error += glm::all(glm::equal(v0, v4)) ? 0 : 1;
Error += glm::all(glm::equal(v1, v2)) ? 0 : 1;
Error += glm::all(glm::equal(v1, v3)) ? 0 : 1;

View File

@ -7,7 +7,6 @@
// File : test/core/type_vec3.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#define GLM_SWIZZLE
#include <glm/glm.hpp>
#include <cstdio>
#include <vector>

View File

@ -7,7 +7,6 @@
// File : test/core/type_vec4.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#define GLM_SWIZZLE
#include <glm/glm.hpp>
#include <vector>
@ -216,7 +215,7 @@ int test_vec4_swizzle_partial()
glm::vec4 A(1, 2, 3, 4);
# if((GLM_LANG & GLM_LANG_CXXMS_FLAG) && defined(GLM_SWIZZLE))
# if(GLM_HAS_ANONYMOUS_UNION && defined(GLM_SWIZZLE_RELAX))
{
glm::vec4 B(A.xy, A.zw);
Error += A == B ? 0 : 1;
@ -242,7 +241,7 @@ int test_vec4_swizzle_partial()
glm::vec4 B(1.0f, A.yzw);
Error += A == B ? 0 : 1;
}
# endif//GLM_LANG
# endif
return Error;
}