Added manual documentation for GLM_FORCE_DEFAULT_ALIGNED_GENTYPES

This commit is contained in:
Christophe Riccio
2018-08-27 21:33:55 +02:00
parent 2fdc2dc748
commit 87f9f3bd78
3 changed files with 100 additions and 22 deletions

View File

@@ -1,14 +1,21 @@
#define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES
#include <glm/glm.hpp>
#if GLM_HAS_ALIGNOF
# include <type_traits>
#endif
int test_aligned()
#if GLM_HAS_ALIGNOF
#include <type_traits>
/*
static_assert(sizeof(glm::bvec4) > sizeof(glm::bvec2), "Invalid sizeof");
static_assert(sizeof(glm::ivec4) > sizeof(glm::uvec2), "Invalid sizeof");
static_assert(sizeof(glm::dvec4) > sizeof(glm::dvec2), "Invalid sizeof");
static_assert(sizeof(glm::bvec4) == sizeof(glm::bvec3), "Invalid sizeof");
static_assert(sizeof(glm::uvec4) == sizeof(glm::uvec3), "Invalid sizeof");
static_assert(sizeof(glm::dvec4) == sizeof(glm::dvec3), "Invalid sizeof");
*/
static int test_storage_aligned()
{
int Error = 0;
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);
@@ -16,8 +23,6 @@ int test_aligned()
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<1, int, true>::type);
Error += align1_aligned == 4 ? 0 : 1;
size_t align2_aligned = alignof(glm::detail::storage<2, int, true>::type);
@@ -25,17 +30,13 @@ int test_aligned()
size_t align4_aligned = alignof(glm::detail::storage<4, int, true>::type);
Error += align4_aligned == 16 ? 0 : 1;
# endif //GLM_HAS_ALIGNOF
return Error;
}
int test_unaligned()
static int test_storage_unaligned()
{
int Error = 0;
# if GLM_HAS_ALIGNOF
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);
@@ -45,17 +46,47 @@ int test_unaligned()
size_t align4_unaligned = alignof(glm::detail::storage<4, int, false>::type);
Error += align4_unaligned == sizeof(int) ? 0 : 1;
# endif //GLM_HAS_ALIGNOF
return Error;
}
static int test_vec3_aligned()
{
int Error = 0;
struct Struct1
{
glm::vec4 A;
float B;
glm::vec3 C;
};
std::size_t const Size1 = sizeof(Struct1);
Error += Size1 == 48 ? 0 : 1;
struct Struct2
{
glm::vec4 A;
glm::vec3 B;
float C;
};
std::size_t const Size2 = sizeof(Struct2);
Error += Size2 == 48 ? 0 : 1;
return Error;
}
#endif
int main()
{
int Error = 0;
Error += test_aligned();
Error += test_unaligned();
# if GLM_HAS_ALIGNOF
Error += test_storage_aligned();
Error += test_storage_unaligned();
Error += test_vec3_aligned();
# endif
return Error;
}