From 21d0092f6a571d00c20799fc009cf6d72abbf66e Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 26 Sep 2018 12:51:31 +0200 Subject: [PATCH] Fixed simplex noise build with double #734 --- glm/gtc/noise.inl | 4 +-- test/ext/ext_scalar_float_sized.cpp | 39 ---------------------- test/gtc/gtc_noise.cpp | 50 +++++++++++++++++++++++++---- 3 files changed, 46 insertions(+), 47 deletions(-) delete mode 100644 test/ext/ext_scalar_float_sized.cpp diff --git a/glm/gtc/noise.inl b/glm/gtc/noise.inl index b8ae3d2e..30d0b274 100644 --- a/glm/gtc/noise.inl +++ b/glm/gtc/noise.inl @@ -732,8 +732,8 @@ namespace gtc T const F4 = static_cast(0.309016994374947451); // First corner - vec<4, T, Q> i = floor(v + dot(v, vec4(F4))); - vec<4, T, Q> x0 = v - i + dot(i, vec4(C.x)); + vec<4, T, Q> i = floor(v + dot(v, vec<4, T, Q>(F4))); + vec<4, T, Q> x0 = v - i + dot(i, vec<4, T, Q>(C.x)); // Other corners diff --git a/test/ext/ext_scalar_float_sized.cpp b/test/ext/ext_scalar_float_sized.cpp deleted file mode 100644 index 3608f715..00000000 --- a/test/ext/ext_scalar_float_sized.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include - -#if GLM_HAS_STATIC_ASSERT - static_assert(sizeof(glm::float32) == 4, "float32 size isn't 4 bytes on this platform"); - -# ifndef GLM_FORCE_SINGLE_ONLY - static_assert(sizeof(glm::float64) == 8, "float64 size isn't 8 bytes on this platform"); -# endif -#endif - -static int test_float_size() -{ - int Error = 0; - - Error += sizeof(glm::float32) == sizeof(float) ? 0 : 1; - Error += sizeof(glm::float64) == sizeof(double) ? 0 : 1; - - return Error; -} - -static int test_float_precision() -{ - int Error = 0; - - Error += sizeof(float) <= sizeof(double) ? 0 : 1; - Error += sizeof(glm::float32) < sizeof(glm::float64) ? 0 : 1; - - return Error; -} - -int main() -{ - int Error = 0; - - Error += test_float_size(); - Error += test_float_precision(); - - return Error; -} diff --git a/test/gtc/gtc_noise.cpp b/test/gtc/gtc_noise.cpp index f559cea1..05d11363 100644 --- a/test/gtc/gtc_noise.cpp +++ b/test/gtc/gtc_noise.cpp @@ -3,7 +3,7 @@ #include #include -int test_simplex() +static int test_simplex_float() { int Error = 0; @@ -14,7 +14,18 @@ int test_simplex() return Error; } -int test_perlin() +static int test_simplex_double() +{ + int Error = 0; + + glm::u8vec4 const PixelSimplex2D(glm::byte(glm::abs(glm::simplex(glm::dvec2(0.f, 0.f))) * 255.f)); + glm::u8vec4 const PixelSimplex3D(glm::byte(glm::abs(glm::simplex(glm::dvec3(0.f, 0.f, 0.f))) * 255.f)); + glm::u8vec4 const PixelSimplex4D(glm::byte(glm::abs(glm::simplex(glm::dvec4(0.f, 0.f, 0.f, 0.f))) * 255.f)); + + return Error; +} + +static int test_perlin_float() { int Error = 0; @@ -25,7 +36,18 @@ int test_perlin() return Error; } -int test_perlin_pedioric() +static int test_perlin_double() +{ + int Error = 0; + + glm::u8vec4 const PixelPerlin2D(glm::byte(glm::abs(glm::perlin(glm::dvec2(0.f, 0.f))) * 255.f)); + glm::u8vec4 const PixelPerlin3D(glm::byte(glm::abs(glm::perlin(glm::dvec3(0.f, 0.f, 0.f))) * 255.f)); + glm::u8vec4 const PixelPerlin4D(glm::byte(glm::abs(glm::perlin(glm::dvec4(0.f, 0.f, 0.f, 0.f))) * 255.f)); + + return Error; +} + +static int test_perlin_pedioric_float() { int Error = 0; @@ -36,13 +58,29 @@ int test_perlin_pedioric() return Error; } +static int test_perlin_pedioric_double() +{ + int Error = 0; + + glm::u8vec4 const PixelPeriodic2D(glm::byte(glm::abs(glm::perlin(glm::dvec2(0.f, 0.f), glm::dvec2(2.0f))) * 255.f)); + glm::u8vec4 const PixelPeriodic3D(glm::byte(glm::abs(glm::perlin(glm::dvec3(0.f, 0.f, 0.f), glm::dvec3(2.0f))) * 255.f)); + glm::u8vec4 const PixelPeriodic4D(glm::byte(glm::abs(glm::perlin(glm::dvec4(0.f, 0.f, 0.f, 0.f), glm::dvec4(2.0f))) * 255.f)); + + return Error; +} + int main() { int Error = 0; - Error += test_simplex(); - Error += test_perlin(); - Error += test_perlin_pedioric(); + Error += test_simplex_float(); + Error += test_simplex_double(); + + Error += test_perlin_float(); + Error += test_perlin_double(); + + Error += test_perlin_pedioric_float(); + Error += test_perlin_pedioric_double(); return Error; }