From 6bd53cc9e529cfb749f1badbbd23b1b8e6773651 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 7 Feb 2020 15:20:42 +0100 Subject: [PATCH] Added files for EXT packing extensions --- glm/ext/scalar_packing.hpp | 0 glm/ext/scalar_packing.inl | 0 glm/ext/vector_packing.hpp | 32 ++++++++++++++++++ glm/ext/vector_packing.inl | 0 glm/gtc/packing.hpp | 2 +- test/ext/ext_scalar_packing.cpp | 28 ++++++++++++++++ test/ext/ext_vector_packing.cpp | 58 +++++++++++++++++++++++++++++++++ 7 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 glm/ext/scalar_packing.hpp create mode 100644 glm/ext/scalar_packing.inl create mode 100644 glm/ext/vector_packing.hpp create mode 100644 glm/ext/vector_packing.inl create mode 100644 test/ext/ext_scalar_packing.cpp create mode 100644 test/ext/ext_vector_packing.cpp diff --git a/glm/ext/scalar_packing.hpp b/glm/ext/scalar_packing.hpp new file mode 100644 index 00000000..e69de29b diff --git a/glm/ext/scalar_packing.inl b/glm/ext/scalar_packing.inl new file mode 100644 index 00000000..e69de29b diff --git a/glm/ext/vector_packing.hpp b/glm/ext/vector_packing.hpp new file mode 100644 index 00000000..b75971e1 --- /dev/null +++ b/glm/ext/vector_packing.hpp @@ -0,0 +1,32 @@ +/// @ref vector_packing +/// @file glm/ext/vector_packing.hpp +/// +/// @see core (dependence) +/// +/// @defgroup ext_vector_packing GLM_EXT_vector_packing +/// @ingroup ext +/// +/// Include to use the features of this extension. +/// +/// This extension provides a set of function to convert vertors to packed +/// formats. + +#pragma once + +// Dependency: +#include "../detail/qualifier.hpp" + +#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_EXT_vector_packing extension included") +#endif + +namespace glm +{ + /// @addtogroup ext_vector_packing + /// @{ + + + /// @} +}// namespace glm + +#include "vector_packing.inl" diff --git a/glm/ext/vector_packing.inl b/glm/ext/vector_packing.inl new file mode 100644 index 00000000..e69de29b diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index 7c64aba3..8e416b3f 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -15,6 +15,7 @@ // Dependency: #include "type_precision.hpp" +#include "../ext/vector_packing.hpp" #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) # pragma message("GLM: GLM_GTC_packing extension included") @@ -721,7 +722,6 @@ namespace glm /// @see int packUint2x16(u32vec2 const& v) GLM_FUNC_DECL u32vec2 unpackUint2x32(uint64 p); - /// @} }// namespace glm diff --git a/test/ext/ext_scalar_packing.cpp b/test/ext/ext_scalar_packing.cpp new file mode 100644 index 00000000..77616e3f --- /dev/null +++ b/test/ext/ext_scalar_packing.cpp @@ -0,0 +1,28 @@ +#include +#include + +int test_packUnorm() +{ + int Error = 0; + + + return Error; +} + +int test_packSnorm() +{ + int Error = 0; + + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_packUnorm(); + Error += test_packSnorm(); + + return Error; +} diff --git a/test/ext/ext_vector_packing.cpp b/test/ext/ext_vector_packing.cpp new file mode 100644 index 00000000..d7cbce21 --- /dev/null +++ b/test/ext/ext_vector_packing.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include +#include + +int test_packUnorm() +{ + int Error = 0; + + std::vector A; + A.push_back(glm::vec2(1.0f, 0.7f)); + A.push_back(glm::vec2(0.5f, 0.1f)); + + for (std::size_t i = 0; i < A.size(); ++i) + { + glm::vec2 B(A[i]); + glm::u16vec2 C = glm::packUnorm(B); + glm::vec2 D = glm::unpackUnorm(C); + Error += glm::all(glm::equal(B, D, 1.0f / 255.f)) ? 0 : 1; + assert(!Error); + } + + return Error; +} + +int test_packSnorm() +{ + int Error = 0; + + std::vector A; + A.push_back(glm::vec2(1.0f, 0.0f)); + A.push_back(glm::vec2(-0.5f, -0.7f)); + A.push_back(glm::vec2(-0.1f, 0.1f)); + + for (std::size_t i = 0; i < A.size(); ++i) + { + glm::vec2 B(A[i]); + glm::i16vec2 C = glm::packSnorm(B); + glm::vec2 D = glm::unpackSnorm(C); + Error += glm::all(glm::equal(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1; + assert(!Error); + } + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_packUnorm(); + Error += test_packSnorm(); + + return Error; +}