Added C++17 detection, added VC language version detection, clean up alignment type, clean up swizzle operator detection

This commit is contained in:
Groove
2018-07-11 02:53:22 +02:00
parent bd2c7070d7
commit 16106b2e3e
21 changed files with 246 additions and 387 deletions

View File

@@ -50,7 +50,7 @@ int test_vec4_ctor()
}
#endif
#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
{
glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A.xyzw;
@@ -79,7 +79,7 @@ int test_vec4_ctor()
Error += glm::all(glm::equal(A, L)) ? 0 : 1;
Error += glm::all(glm::equal(A, M)) ? 0 : 1;
}
#endif// GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
#endif//GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
{
glm::vec4 A(1);

View File

@@ -1291,8 +1291,10 @@ namespace ldexp_
static int test_constexpr()
{
#if GLM_HAS_CONSTEXPR_CXX11
static_assert(glm::abs(1.0f) > 0.0f, "GLM: Failed constexpr");
static_assert(glm::abs(glm::vec3(1.0f)) != glm::vec3(0.0f), "GLM: Failed constexpr");
#endif // GLM_HAS_CONSTEXPR_CXX11
return 0;
}

View File

@@ -4,16 +4,18 @@
#if !GLM_HAS_ONLY_XYZW
int test_ivec2_swizzle()
static int test_ivec2_swizzle()
{
int Error = 0;
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
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
return Error;
}
@@ -22,12 +24,14 @@ int test_ivec3_swizzle()
{
int Error = 0;
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
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
return Error;
}
@@ -36,12 +40,14 @@ int test_ivec4_swizzle()
{
int Error = 0;
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
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
return Error;
}
@@ -50,6 +56,7 @@ int test_vec4_swizzle()
{
int Error = 0;
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
glm::vec4 A(1, 2, 3, 4);
glm::vec4 B = A.wzyx();
glm::vec4 C = B.wzyx();
@@ -59,6 +66,7 @@ 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
return Error;
}

View File

@@ -1,57 +1,38 @@
#include <glm/glm.hpp>
#if GLM_HAS_ALIGNOF
# include <type_traits>
#endif
int test_aligned()
{
int Error = 0;
size_t size1_aligned = sizeof(glm::detail::storage<int, 1, true>::type);
Error += size1_aligned == 1 ? 0 : 1;
size_t size2_aligned = sizeof(glm::detail::storage<int, 2, true>::type);
Error += size2_aligned == 2 ? 0 : 1;
size_t size4_aligned = sizeof(glm::detail::storage<int, 4, true>::type);
Error += size4_aligned == 4 ? 0 : 1;
size_t size8_aligned = sizeof(glm::detail::storage<int, 8, true>::type);
Error += size8_aligned == 8 ? 0 : 1;
size_t size16_aligned = sizeof(glm::detail::storage<int, 16, true>::type);
Error += size16_aligned == 16 ? 0 : 1;
size_t size32_aligned = sizeof(glm::detail::storage<int, 32, true>::type);
Error += size32_aligned == 32 ? 0 : 1;
size_t size64_aligned = sizeof(glm::detail::storage<int, 64, true>::type);
Error += size64_aligned == 64 ? 0 : 1;
GLM_STATIC_ASSERT(sizeof(glm::vec4) == 4 * sizeof(float), "Invalid sizeof");
size_t size1_aligned = sizeof(glm::detail::storage<1, int, true>::type);
Error += size1_aligned == sizeof(int) * 1 ? 0 : 1;
size_t size2_aligned = sizeof(glm::detail::storage<2, int, true>::type);
Error += size2_aligned == sizeof(int) * 2 ? 0 : 1;
size_t size4_aligned = sizeof(glm::detail::storage<4, int, true>::type);
Error += size4_aligned == sizeof(int) * 4 ? 0 : 1;
# if GLM_HAS_ALIGNOF
size_t align1_aligned = alignof(glm::detail::storage<int, 1, true>::type);
Error += align1_aligned == 1 ? 0 : 1;
size_t align2_aligned = alignof(glm::detail::storage<int, 2, true>::type);
Error += align2_aligned == 2 ? 0 : 1;
size_t align4_aligned = alignof(glm::detail::storage<int, 4, true>::type);
Error += align4_aligned == 4 ? 0 : 1;
size_t align8_aligned = alignof(glm::detail::storage<int, 8, true>::type);
Error += align8_aligned == 8 ? 0 : 1;
size_t align16_aligned = alignof(glm::detail::storage<int, 16, true>::type);
Error += align16_aligned == 16 ? 0 : 1;
size_t align32_aligned = alignof(glm::detail::storage<int, 32, true>::type);
Error += align32_aligned == 32 ? 0 : 1;
size_t align64_aligned = alignof(glm::detail::storage<int, 64, true>::type);
Error += align64_aligned == 64 ? 0 : 1;
size_t align1_aligned = alignof(glm::detail::storage<1, int, true>::type);
Error += align1_aligned == 4 ? 0 : 1;
size_t align2_aligned = alignof(glm::detail::storage<2, int, true>::type);
Error += align2_aligned == 8 ? 0 : 1;
size_t align4_aligned = alignof(glm::detail::storage<4, int, true>::type);
Error += align4_aligned == 16 ? 0 : 1;
# elif GLM_COMPILER & GLM_COMPILER_GCC
size_t align1_aligned = __alignof__(glm::detail::storage<int, 1, true>::type);
Error += align1_aligned == 1 ? 0 : 1;
size_t align2_aligned = __alignof__(glm::detail::storage<int, 2, true>::type);
Error += align2_aligned == 2 ? 0 : 1;
size_t align4_aligned = __alignof__(glm::detail::storage<int, 4, true>::type);
Error += align4_aligned == 4 ? 0 : 1;
size_t align8_aligned = __alignof__(glm::detail::storage<int, 8, true>::type);
Error += align8_aligned == 8 ? 0 : 1;
size_t align16_aligned = __alignof__(glm::detail::storage<int, 16, true>::type);
Error += align16_aligned == 16 ? 0 : 1;
size_t align32_aligned = __alignof__(glm::detail::storage<int, 32, true>::type);
Error += align32_aligned == 32 ? 0 : 1;
size_t align64_aligned = __alignof__(glm::detail::storage<int, 64, true>::type);
Error += align64_aligned == 64 ? 0 : 1;
size_t align1_aligned = __alignof__(glm::detail::storage<1, int, true>::type);
Error += align1_aligned == 4 ? 0 : 1;
size_t align2_aligned = __alignof__(glm::detail::storage<2, int, true>::type);
Error += align2_aligned == 8 ? 0 : 1;
size_t align8_aligned = __alignof__(glm::detail::storage<4, int, true>::type);
Error += align8_aligned == 16 ? 0 : 1;
# endif //GLM_HAS_ALIGNOF
@@ -62,61 +43,33 @@ int test_unaligned()
{
int Error = 0;
size_t size1_unaligned = sizeof(glm::detail::storage<int, 1, false>::type);
Error += size1_unaligned == 1 ? 0 : 1;
size_t size2_unaligned = sizeof(glm::detail::storage<int, 2, false>::type);
Error += size2_unaligned == 2 ? 0 : 1;
size_t size4_unaligned = sizeof(glm::detail::storage<int, 4, false>::type);
Error += size4_unaligned == 4 ? 0 : 1;
size_t size8_unaligned = sizeof(glm::detail::storage<int, 8, false>::type);
Error += size8_unaligned == 8 ? 0 : 1;
size_t size16_unaligned = sizeof(glm::detail::storage<int, 16, false>::type);
Error += size16_unaligned == 16 ? 0 : 1;
size_t size32_unaligned = sizeof(glm::detail::storage<int, 32, false>::type);
Error += size32_unaligned == 32 ? 0 : 1;
size_t size64_unaligned = sizeof(glm::detail::storage<int, 64, false>::type);
Error += size64_unaligned == 64 ? 0 : 1;
# if GLM_HAS_ALIGNOF
size_t align1_unaligned = alignof(glm::detail::storage<int, 1, false>::type);
Error += align1_unaligned == 1 ? 0 : 1;
size_t align2_unaligned = alignof(glm::detail::storage<int, 2, false>::type);
Error += align2_unaligned == 1 ? 0 : 1;
size_t align4_unaligned = alignof(glm::detail::storage<int, 4, false>::type);
Error += align4_unaligned == 1 ? 0 : 1;
size_t align8_unaligned = alignof(glm::detail::storage<int, 8, false>::type);
Error += align8_unaligned == 1 ? 0 : 1;
size_t align16_unaligned = alignof(glm::detail::storage<int, 16, false>::type);
Error += align16_unaligned == 1 ? 0 : 1;
size_t align32_unaligned = alignof(glm::detail::storage<int, 32, false>::type);
Error += align32_unaligned == 1 ? 0 : 1;
size_t align64_unaligned = alignof(glm::detail::storage<int, 64, false>::type);
Error += align64_unaligned == 1 ? 0 : 1;
size_t align1_unaligned = alignof(glm::detail::storage<1, int, false>::type);
Error += align1_unaligned == sizeof(int) ? 0 : 1;
size_t align2_unaligned = alignof(glm::detail::storage<2, int, false>::type);
Error += align2_unaligned == sizeof(int) ? 0 : 1;
size_t align3_unaligned = alignof(glm::detail::storage<3, int, false>::type);
Error += align3_unaligned == sizeof(int) ? 0 : 1;
size_t align4_unaligned = alignof(glm::detail::storage<4, int, false>::type);
Error += align4_unaligned == sizeof(int) ? 0 : 1;
# elif GLM_COMPILER & GLM_COMPILER_GCC
size_t align1_unaligned = __alignof__(glm::detail::storage<int, 1, false>::type);
Error += align1_unaligned == 1 ? 0 : 1;
size_t align2_unaligned = __alignof__(glm::detail::storage<int, 2, false>::type);
Error += align2_unaligned == 1 ? 0 : 1;
size_t align4_unaligned = __alignof__(glm::detail::storage<int, 4, false>::type);
Error += align4_unaligned == 1 ? 0 : 1;
size_t align8_unaligned = __alignof__(glm::detail::storage<int, 8, false>::type);
Error += align8_unaligned == 1 ? 0 : 1;
size_t align16_unaligned = __alignof__(glm::detail::storage<int, 16, false>::type);
Error += align16_unaligned == 1 ? 0 : 1;
size_t align32_unaligned = __alignof__(glm::detail::storage<int, 32, false>::type);
Error += align32_unaligned == 1 ? 0 : 1;
size_t align64_unaligned = __alignof__(glm::detail::storage<int, 64, false>::type);
Error += align64_unaligned == 1 ? 0 : 1;
size_t align1_unaligned = __alignof__(glm::detail::storage<1, int, false>::type);
Error += align1_unaligned == sizeof(int) ? 0 : 1;
size_t align2_unaligned = __alignof__(glm::detail::storage<2, int, false>::type);
Error += align2_unaligned == sizeof(int) ? 0 : 1;
size_t align4_unaligned = __alignof__(glm::detail::storage<3, int, false>::type);
Error += align4_unaligned == sizeof(int) ? 0 : 1;
size_t align8_unaligned = __alignof__(glm::detail::storage<4, int, false>::type);
Error += align8_unaligned == sizeof(int) ? 0 : 1;
# endif //GLM_HAS_ALIGNOF
return Error;
}
int main()
{
int Error = 0;

View File

@@ -180,7 +180,7 @@ int test_inverse()
int test_ctr()
{
int Error(0);
int Error = 0;
#if GLM_HAS_TRIVIAL_QUERIES
//Error += std::is_trivially_default_constructible<glm::mat4>::value ? 0 : 1;
@@ -190,9 +190,9 @@ int test_ctr()
//Error += std::has_trivial_copy_constructor<glm::mat4>::value ? 0 : 1;
#endif
#if(GLM_HAS_INITIALIZER_LISTS)
#if GLM_HAS_INITIALIZER_LISTS
glm::mat4 m0(
glm::vec4(0, 1, 2, 3),
glm::vec4(0, 1, 2, 3),
glm::vec4(4, 5, 6, 7),
glm::vec4(8, 9, 10, 11),
glm::vec4(12, 13, 14, 15));

View File

@@ -69,7 +69,7 @@ int test_vec1_ctor()
}
#endif
*/
#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
{
glm::vec2 A = glm::vec2(1.0f, 2.0f);
glm::vec2 B = A.xy;
@@ -80,7 +80,7 @@ int test_vec1_ctor()
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
}
#endif//GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
#endif//GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
{
glm::vec2 A = glm::vec2(2.0f);

View File

@@ -236,7 +236,7 @@ static int test_ctor()
}
#endif
#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
{
glm::vec2 A = glm::vec2(1.0f, 2.0f);
glm::vec2 B = A.xy;
@@ -247,7 +247,7 @@ static int test_ctor()
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
}
#endif//GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
#endif//GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
{
glm::vec2 A = glm::vec2(2.0f);

View File

@@ -45,7 +45,7 @@ int test_vec3_ctor()
}
#endif
#if(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE))
#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;
@@ -64,7 +64,7 @@ int test_vec3_ctor()
Error += glm::all(glm::equal(A, G)) ? 0 : 1;
Error += glm::all(glm::equal(A, H)) ? 0 : 1;
}
#endif//(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE))
#endif//(GLM_LANG & GLM_LANG_CXXMS_FLAG && defined(GLM_FORCE_SWIZZLE))
{
glm::vec3 A(1);
@@ -469,6 +469,8 @@ int test_vec3_swizzle_functions()
{
int Error = 0;
# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
// NOTE: template functions cannot pick up the implicit conversion from
// a swizzle to the unswizzled type, therefore the operator() must be
// used. E.g.:
@@ -501,6 +503,8 @@ 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
return Error;
}

View File

@@ -74,7 +74,7 @@ static int test_vec4_ctor()
}
#endif
#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
{
glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A.xyzw;
@@ -103,7 +103,7 @@ static int test_vec4_ctor()
Error += glm::all(glm::equal(A, L)) ? 0 : 1;
Error += glm::all(glm::equal(A, M)) ? 0 : 1;
}
#endif// GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
#endif// GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
{
glm::vec4 A(1);