From cef58e189d908e9042b3305ca58196b5bafb1efe Mon Sep 17 00:00:00 2001
From: Christophe Riccio <christophe.riccio@unity3d.com>
Date: Mon, 1 Oct 2018 18:48:40 +0200
Subject: [PATCH] Added packing experiments

---
 glm/ext/scalar_packing.hpp      |  4 +-
 glm/ext/scalar_packing.inl      |  4 +-
 glm/ext/vector_packing.hpp      | 77 ++++++++++++++++++++++++++++++++-
 glm/ext/vector_packing.inl      |  4 +-
 glm/gtc/packing.hpp             | 21 +++++++++
 glm/gtc/packing.inl             | 12 +++++
 test/ext/ext_scalar_packing.cpp |  8 ++--
 test/ext/ext_vector_packing.cpp |  8 ++--
 8 files changed, 122 insertions(+), 16 deletions(-)

diff --git a/glm/ext/scalar_packing.hpp b/glm/ext/scalar_packing.hpp
index 421e11e7..c683a2e0 100644
--- a/glm/ext/scalar_packing.hpp
+++ b/glm/ext/scalar_packing.hpp
@@ -32,14 +32,14 @@ namespace glm
 	/// the forth component specifies the 16 most-significant bits.
 	///
 	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
-	GLM_FUNC_DECL uint16 packHalf(float s);
+	GLM_FUNC_DECL uint16 packFloatToHalf(float s);
 
 	/// Returns a floating-point scalar with components obtained by reinterpreting an integer scalar as 16-bit floating-point numbers and converting them to 32-bit floating-point values.
 	/// The first component of the vector is obtained from the 16 least-significant bits of v;
 	/// the forth component is obtained from the 16 most-significant bits of v.
 	///
 	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
-	GLM_FUNC_DECL float unpackHalf(uint16 p);
+	GLM_FUNC_DECL float unpackHalfToFloat(uint16 p);
 
 	/// @}
 }//namespace glm
diff --git a/glm/ext/scalar_packing.inl b/glm/ext/scalar_packing.inl
index d586ae76..a23ebbc8 100644
--- a/glm/ext/scalar_packing.inl
+++ b/glm/ext/scalar_packing.inl
@@ -2,12 +2,12 @@
 
 namespace glm
 {
-	GLM_FUNC_QUALIFIER uint16 packHalf(float Scalar)
+	GLM_FUNC_QUALIFIER uint16 packFloatToHalf(float Scalar)
 	{
 		return detail::toFloat16(Scalar);
 	}
 
-	GLM_FUNC_QUALIFIER float unpackHalf(uint16 Packed)
+	GLM_FUNC_QUALIFIER float unpackHalfToFloat(uint16 Packed)
 	{
 		return detail::toFloat32(Packed);
 	}
diff --git a/glm/ext/vector_packing.hpp b/glm/ext/vector_packing.hpp
index fbb6db10..e7a4d784 100644
--- a/glm/ext/vector_packing.hpp
+++ b/glm/ext/vector_packing.hpp
@@ -26,6 +26,48 @@ namespace glm
 	/// @addtogroup ext_vector_packing
 	/// @{
 
+	GLM_FUNC_DECL uint8 packVecToUInt(vec<1, uint8> const& v);
+
+	GLM_FUNC_DECL vec<1, uint8> unpackUInt(uint8 p);
+
+	GLM_FUNC_DECL uint16 packUInt(vec<1, uint16> const& v);
+
+	GLM_FUNC_DECL vec<1, uint16> unpackUInt(uint16 p);
+
+	GLM_FUNC_DECL uint32 packUInt(vec<1, uint32> const& v);
+
+	GLM_FUNC_DECL vec<1, uint32> unpackUInt(uint32 p);
+
+	GLM_FUNC_DECL uint64 packUInt(vec<1, uint64> const& v);
+
+	GLM_FUNC_DECL vec<1, uint64> unpackUInt(uint64 p);
+
+
+
+	GLM_FUNC_DECL uint16 packUInt(vec<2, uint8> const& v);
+
+	GLM_FUNC_DECL vec<2, uint8> unpackUInt(uint16 p);
+
+	GLM_FUNC_DECL uint32 packUInt(vec<2, uint16> const& v);
+
+	GLM_FUNC_DECL vec<2, uint16> unpackUInt(uint32 p);
+
+	GLM_FUNC_DECL uint64 packUInt(vec<2, uint32> const& v);
+
+	GLM_FUNC_DECL vec<2, uint32> unpackUInt(uint64 p);
+
+
+
+	GLM_FUNC_DECL uint32 packUInt(vec<4, uint8> const& v);
+
+	GLM_FUNC_DECL vec<4, uint8> unpackUInt(uint32 p);
+
+	GLM_FUNC_DECL uint64 packUInt(vec<4, uint16> const& v);
+
+	GLM_FUNC_DECL vec<4, uint16> unpackUInt(uint64 p);
+
+
+
 	/// Returns an unsigned integer vector obtained by converting the components of a floating-point vector
 	/// to the 16-bit floating-point representation found in the OpenGL Specification.
 	/// The first vector component specifies the 16 least-significant bits of the result;
@@ -34,7 +76,7 @@ namespace glm
 	/// @see vec<L, float, Q> unpackHalf(vec<L, uint16, Q> const& p)
 	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
 	template<length_t L, qualifier Q>
-	GLM_FUNC_DECL vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v);
+	GLM_FUNC_DECL vec<L, uint16, Q> packFloatToHalf(vec<L, float, Q> const& v);
 
 	/// Returns a floating-point vector with components obtained by reinterpreting an integer vector as 16-bit floating-point numbers and converting them to 32-bit floating-point values.
 	/// The first component of the vector is obtained from the 16 least-significant bits of v;
@@ -43,7 +85,38 @@ namespace glm
 	/// @see vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v)
 	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
 	template<length_t L, qualifier Q>
-	GLM_FUNC_DECL vec<L, float, Q> unpackHalf(vec<L, uint16, Q> const& p);
+	GLM_FUNC_DECL vec<L, float, Q> unpackHalfToFloat(vec<L, uint16, Q> const& p);
+
+
+	/// Convert each component of the normalized floating-point vector into unsigned integer values.
+	///
+	/// @see gtc_packing
+	/// @see vec<L, floatType, Q> unpackUnorm(vec<L, intType, Q> const& p);
+	template<typename uintType, length_t L, typename floatType, qualifier Q>
+	GLM_FUNC_DECL vec<L, uintType, Q> packFloatToUnorm(vec<L, floatType, Q> const& v);
+
+	/// Convert a packed integer to a normalized floating-point vector.
+	///
+	/// @see gtc_packing
+	/// @see vec<L, intType, Q> packUnorm(vec<L, floatType, Q> const& v)
+	template<typename floatType, length_t L, typename uintType, qualifier Q>
+	GLM_FUNC_DECL vec<L, floatType, Q> unpackUnormToFloat(vec<L, uintType, Q> const& v);
+
+
+	/// Convert each component of the normalized floating-point vector into signed integer values.
+	///
+	/// @see gtc_packing
+	/// @see vec<L, floatType, Q> unpackSnorm(vec<L, intType, Q> const& p);
+	template<typename intType, length_t L, typename floatType, qualifier Q>
+	GLM_FUNC_DECL vec<L, intType, Q> packFloatToSnorm(vec<L, floatType, Q> const& v);
+
+	/// Convert a packed integer to a normalized floating-point vector.
+	///
+	/// @see gtc_packing
+	/// @see vec<L, intType, Q> packSnorm(vec<L, floatType, Q> const& v)
+	template<typename floatType, length_t L, typename intType, qualifier Q>
+	GLM_FUNC_DECL vec<L, floatType, Q> unpackSnormToFloat(vec<L, intType, Q> const& v);
+
 
 	/// @}
 }//namespace glm
diff --git a/glm/ext/vector_packing.inl b/glm/ext/vector_packing.inl
index 72ba6dcd..bbbfa0b6 100644
--- a/glm/ext/vector_packing.inl
+++ b/glm/ext/vector_packing.inl
@@ -85,13 +85,13 @@ namespace detail
 }//namespace detail
 
 	template<length_t L, qualifier Q>
-	GLM_FUNC_QUALIFIER vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v)
+	GLM_FUNC_QUALIFIER vec<L, uint16, Q> packFloatToHalf(vec<L, float, Q> const& v)
 	{
 		return detail::compute_half<L, Q>::pack(v);
 	}
 
 	template<length_t L, qualifier Q>
-	GLM_FUNC_QUALIFIER vec<L, float, Q> unpackHalf(vec<L, uint16, Q> const& v)
+	GLM_FUNC_QUALIFIER vec<L, float, Q> unpackHalfToFloat(vec<L, uint16, Q> const& v)
 	{
 		return detail::compute_half<L, Q>::unpack(v);
 	}
diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp
index b391482e..25ff75d3 100644
--- a/glm/gtc/packing.hpp
+++ b/glm/gtc/packing.hpp
@@ -492,6 +492,27 @@ namespace glm
 	template<length_t L, typename T, qualifier Q>
 	GLM_FUNC_DECL vec<3, T, Q> unpackRGBM(vec<4, T, Q> const& rgbm);
 
+	/// Returns an unsigned integer vector obtained by converting the components of a floating-point vector
+	/// to the 16-bit floating-point representation found in the OpenGL Specification.
+	/// The first vector component specifies the 16 least-significant bits of the result;
+	/// the forth component specifies the 16 most-significant bits.
+	///
+	/// @see gtc_packing
+	/// @see vec<L, float, Q> unpackHalf(vec<L, uint16, Q> const& p)
+	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
+	template<length_t L, qualifier Q>
+	GLM_FUNC_DECL vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v);
+
+	/// Returns a floating-point vector with components obtained by reinterpreting an integer vector as 16-bit floating-point numbers and converting them to 32-bit floating-point values.
+	/// The first component of the vector is obtained from the 16 least-significant bits of v;
+	/// the forth component is obtained from the 16 most-significant bits of v.
+	///
+	/// @see gtc_packing
+	/// @see vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v)
+	/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
+	template<length_t L, qualifier Q>
+	GLM_FUNC_DECL vec<L, float, Q> unpackHalf(vec<L, uint16, Q> const& p);
+
 	/// Convert each component of the normalized floating-point vector into unsigned integer values.
 	///
 	/// @see gtc_packing
diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl
index 8039bef9..6b1113a8 100644
--- a/glm/gtc/packing.inl
+++ b/glm/gtc/packing.inl
@@ -576,6 +576,18 @@ namespace detail
 		return vec<3, T, Q>(rgbm.x, rgbm.y, rgbm.z) * rgbm.w * static_cast<T>(6);
 	}
 
+	template<length_t L, qualifier Q>
+	GLM_FUNC_QUALIFIER vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v)
+	{
+		return detail::compute_half<L, Q>::pack(v);
+	}
+
+	template<length_t L, qualifier Q>
+	GLM_FUNC_QUALIFIER vec<L, float, Q> unpackHalf(vec<L, uint16, Q> const& v)
+	{
+		return detail::compute_half<L, Q>::unpack(v);
+	}
+
 	template<typename uintType, length_t L, typename floatType, qualifier Q>
 	GLM_FUNC_QUALIFIER vec<L, uintType, Q> packUnorm(vec<L, floatType, Q> const& v)
 	{
diff --git a/test/ext/ext_scalar_packing.cpp b/test/ext/ext_scalar_packing.cpp
index b96b10a6..249ef31e 100644
--- a/test/ext/ext_scalar_packing.cpp
+++ b/test/ext/ext_scalar_packing.cpp
@@ -17,12 +17,12 @@ static int test_half()
 
 	for(std::size_t i = 0; i < Tests.size(); ++i)
 	{
-		glm::uint16 p0 = glm::packHalf(Tests[i]);
-		float v0 = glm::unpackHalf(p0);
+		glm::uint16 p0 = glm::packFloatToHalf(Tests[i]);
+		float v0 = glm::unpackHalfToFloat(p0);
 		Error += glm::equal(v0, Tests[i], 0.01f) ? 0 : 1;
 
-		glm::uint16 p1 = glm::packHalf(v0);
-		float v1 = glm::unpackHalf(p1);
+		glm::uint16 p1 = glm::packFloatToHalf(v0);
+		float v1 = glm::unpackHalfToFloat(p1);
 		Error += glm::equal(v1, Tests[i], 0.01f) ? 0 : 1;
 
 		Error += glm::equal(v0, v1, 0) ? 0 : 1;
diff --git a/test/ext/ext_vector_packing.cpp b/test/ext/ext_vector_packing.cpp
index 12696098..e4fd9ac5 100644
--- a/test/ext/ext_vector_packing.cpp
+++ b/test/ext/ext_vector_packing.cpp
@@ -42,15 +42,15 @@ static int test_half()
 	{
 		vecFType const Data = Tests[i].Data;
 
-		vecUType const p0 = glm::packHalf(Data);
+		vecUType const p0 = glm::packFloatToHalf(Data);
 
-		vecFType const v0 = glm::unpackHalf(p0);
+		vecFType const v0 = glm::unpackHalfToFloat(p0);
 		Error += glm::all(glm::equal(v0, Data, Epsilon)) ? 0 : 1;
 
-		vecUType const p1 = glm::packHalf(v0);
+		vecUType const p1 = glm::packFloatToHalf(v0);
 		Error += glm::all(glm::equal(p0, p1)) ? 0 : 1;
 
-		vecFType const v1 = glm::unpackHalf(p1);
+		vecFType const v1 = glm::unpackHalfToFloat(p1);
 		Error += glm::all(glm::equal(v1, Data, Epsilon)) ? 0 : 1;
 
 		vecIType const ULPs = glm::float_distance(Data, v0);