From 573712405b13b1c0142d80a9522f8ad838d27e1a Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 9 Aug 2013 00:01:02 +0200 Subject: [PATCH 01/15] Added declaration for new GTC_packing extension --- glm/gtc/packing.hpp | 115 +++++++++++++++++++++++++++++++++++ glm/gtc/packing.inl | 32 ++++++++++ test/core/core_type_vec2.cpp | 2 +- 3 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 glm/gtc/packing.hpp create mode 100644 glm/gtc/packing.inl diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp new file mode 100644 index 00000000..0f366384 --- /dev/null +++ b/glm/gtc/packing.hpp @@ -0,0 +1,115 @@ +/////////////////////////////////////////////////////////////////////////////////// +/// OpenGL Mathematics (glm.g-truc.net) +/// +/// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net) +/// Permission is hereby granted, free of charge, to any person obtaining a copy +/// of this software and associated documentation files (the "Software"), to deal +/// in the Software without restriction, including without limitation the rights +/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +/// copies of the Software, and to permit persons to whom the Software is +/// furnished to do so, subject to the following conditions: +/// +/// The above copyright notice and this permission notice shall be included in +/// all copies or substantial portions of the Software. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +/// THE SOFTWARE. +/// +/// @ref gtc_packing +/// @file glm/gtc/packing.hpp +/// @date 2013-08-08 / 2013-08-08 +/// @author Christophe Riccio +/// +/// @see core (dependence) +/// +/// @defgroup gtc_packing GLM_GTC_packing +/// @ingroup gtc +/// +/// @brief This extension provides a set of function to convert vertors to packed +/// formats. +/// +/// need to be included to use these features. +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef GLM_GTC_packing +#define GLM_GTC_packing GLM_VERSION + +// Dependency: +#include "../glm.hpp" + +#if(defined(GLM_MESSAGES) && !defined(glm_ext)) +# pragma message("GLM: GLM_GTC_packing extension included") +#endif + +namespace glm +{ + /// @addtogroup gtc_packing + /// @{ + + uint16 packUnorm1x16(float v); + float unpackUnorm1x16(uint16 v); + + uint64 packUnorm4x16(vec4 const & v); + vec4 unpackUnorm4x16(uint64 const & v); + + uint16 packSnorm1x16(float v); + float unpackSnorm1x16(uint16 v); + + uint64 packSnorm4x16(vec4 const & v); + vec4 unpackSnorm4x16(uint64 const & v); + + uint16 packUnorm2x8(vec2 const & v); + vec2 unpackUnorm2x8(uint16 v); + + uint16 packSnorm2x8(vec2 const & v); + vec2 unpackSnorm2x8(uint16 v); + + GLM_FUNC_DECL uint16 packHalf1x16(float const & v); + GLM_FUNC_DECL float unpackHalf1x16(uint16 const & v); + + /// Returns an unsigned integer obtained by converting the components of a two-component floating-point vector + /// to the 16-bit floating-point representation found in the OpenGL Specification, + /// and then packing these two 16- bit integers into a 32-bit unsigned integer. + /// The first vector component specifies the 16 least-significant bits of the result; + /// the second component specifies the 16 most-significant bits. + /// + /// @see gtc_packing + /// @see GLSL packHalf2x16 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL uint64 packHalf4x16(vec4 const & v); + + /// Returns a two-component floating-point vector with components obtained by unpacking a 32-bit unsigned integer into a pair of 16-bit values, + /// interpreting those values as 16-bit floating-point numbers according to the OpenGL Specification, + /// 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 second component is obtained from the 16 most-significant bits of v. + /// + /// @see gtc_packing + /// @see GLSL unpackHalf2x16 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL vec4 unpackHalf4x16(uint64 const & v); + + GLM_FUNC_DECL uint32 packSnorm3x10Snorm1x2(vec4 const & v); + GLM_FUNC_DECL vec4 unpackSnorm3x10Snorm1x2(uint32 const & v); + + GLM_FUNC_DECL uint32 packI3x10I1x2(ivec4 const & v); + GLM_FUNC_DECL ivec4 unpackI3x10I1x2(uint32 const & v); + + GLM_FUNC_DECL uint32 packU3x10U1x2(uvec4 const & v); + GLM_FUNC_DECL uvec4 unpackU3x10U1x2(uint32 const & v); + + GLM_FUNC_DECL uint32 packF11F11F10(vec3 const & v); + GLM_FUNC_DECL vec3 unpackF11F11F10(uint32 const & v); + + /// @} +}// namespace glm + +#include "packing.inl" + +#endif//GLM_GTC_packing + diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl new file mode 100644 index 00000000..dcaa12f3 --- /dev/null +++ b/glm/gtc/packing.inl @@ -0,0 +1,32 @@ +/////////////////////////////////////////////////////////////////////////////////// +/// OpenGL Mathematics (glm.g-truc.net) +/// +/// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net) +/// Permission is hereby granted, free of charge, to any person obtaining a copy +/// of this software and associated documentation files (the "Software"), to deal +/// in the Software without restriction, including without limitation the rights +/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +/// copies of the Software, and to permit persons to whom the Software is +/// furnished to do so, subject to the following conditions: +/// +/// The above copyright notice and this permission notice shall be included in +/// all copies or substantial portions of the Software. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +/// THE SOFTWARE. +/// +/// @ref gtc_packing +/// @file glm/gtc/packing.inl +/// @date 2013-08-08 / 2013-08-08 +/// @author Christophe Riccio +/////////////////////////////////////////////////////////////////////////////////// + +namespace glm +{ + +}//namespace glm diff --git a/test/core/core_type_vec2.cpp b/test/core/core_type_vec2.cpp index 6f2b2560..ebdf2306 100644 --- a/test/core/core_type_vec2.cpp +++ b/test/core/core_type_vec2.cpp @@ -230,7 +230,7 @@ int test_operator_increment() glm::ivec2 v3 = ++v1; glm::ivec2 v4 = v2++; - Error += glm::all(glm::equal(v0, v4)) ? 0 : 1; + Error += glm::all(glm::equal(v0, v4)) ? 0 : 1; Error += glm::all(glm::equal(v1, v2)) ? 0 : 1; Error += glm::all(glm::equal(v1, v3)) ? 0 : 1; From cf14790806202852f62bcdb6646865c3894913f2 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 10 Aug 2013 19:52:59 +0200 Subject: [PATCH 02/15] Added packF11F11F10 implementation --- glm/gtc/packing.hpp | 4 +- glm/gtc/packing.inl | 116 ++++++++++++++++++++++++++++++++ test/gtc/CMakeLists.txt | 1 + test/gtc/gtc_packing.cpp | 142 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 261 insertions(+), 2 deletions(-) create mode 100644 test/gtc/gtc_packing.cpp diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index 0f366384..f77b9f0d 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -100,8 +100,8 @@ namespace glm GLM_FUNC_DECL uint32 packI3x10I1x2(ivec4 const & v); GLM_FUNC_DECL ivec4 unpackI3x10I1x2(uint32 const & v); - GLM_FUNC_DECL uint32 packU3x10U1x2(uvec4 const & v); - GLM_FUNC_DECL uvec4 unpackU3x10U1x2(uint32 const & v); + GLM_FUNC_DECL uint32 packU10U10U10U2(uvec4 const & v); + GLM_FUNC_DECL uvec4 unpackU10U10U10U2(uint32 const & v); GLM_FUNC_DECL uint32 packF11F11F10(vec3 const & v); GLM_FUNC_DECL vec3 unpackF11F11F10(uint32 const & v); diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index dcaa12f3..2ae8e139 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -28,5 +28,121 @@ namespace glm { +namespace detail +{ + glm::uint16 float2half(glm::uint32 const & f) + { + // 10 bits => EE EEEFFFFF + // 11 bits => EEE EEFFFFFF + // Half bits => SEEEEEFF FFFFFFFF + // Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF + + // 0x00007c00 => 00000000 00000000 01111100 00000000 + // 0x000003ff => 00000000 00000000 00000011 11111111 + // 0x38000000 => 00111000 00000000 00000000 00000000 + // 0x7f800000 => 01111111 10000000 00000000 00000000 + // 0x00008000 => 00000000 00000000 10000000 00000000 + return + ((f >> 16) & 0x8000) | // sign + ((((f & 0x7f800000) - 0x38000000) >> 13) & 0x7c00) | // exponential + ((f >> 13) & 0x03ff); // Mantissa + } + + glm::uint16 float2packed11(glm::uint32 const & f) + { + // 10 bits => EE EEEFFFFF + // 11 bits => EEE EEFFFFFF + // Half bits => SEEEEEFF FFFFFFFF + // Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF + + // 0x000007c0 => 00000000 00000000 00000111 11000000 + // 0x00007c00 => 00000000 00000000 01111100 00000000 + // 0x000003ff => 00000000 00000000 00000011 11111111 + // 0x38000000 => 00111000 00000000 00000000 00000000 + // 0x7f800000 => 01111111 10000000 00000000 00000000 + // 0x00008000 => 00000000 00000000 10000000 00000000 + return + ((((f & 0x7f800000) - 0x38000000) >> 17) & 0x07c0) | // exponential + ((f >> 17) & 0x003f); // Mantissa + } + + glm::uint float2packed10(glm::uint const & f) + { + // 10 bits => EE EEEFFFFF + // 11 bits => EEE EEFFFFFF + // Half bits => SEEEEEFF FFFFFFFF + // Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF + + // 0x0000001F => 00000000 00000000 00000000 00011111 + // 0x0000003F => 00000000 00000000 00000000 00111111 + // 0x000003E0 => 00000000 00000000 00000011 11100000 + // 0x000007C0 => 00000000 00000000 00000111 11000000 + // 0x00007C00 => 00000000 00000000 01111100 00000000 + // 0x000003FF => 00000000 00000000 00000011 11111111 + // 0x38000000 => 00111000 00000000 00000000 00000000 + // 0x7f800000 => 01111111 10000000 00000000 00000000 + // 0x00008000 => 00000000 00000000 10000000 00000000 + return + ((((f & 0x7f800000) - 0x38000000) >> 18) & 0x03E0) | // exponential + ((f >> 18) & 0x001f); // Mantissa + } + + glm::uint half2float(glm::uint const & h) + { + return ((h & 0x8000) << 16) | ((( h & 0x7c00) + 0x1C000) << 13) | ((h & 0x03FF) << 13); + } + + union uif + { + glm::uint i; + float f; + }; + + glm::uint floatTo11bit(float x) + { + if(x == 0.0f) + return 0; + else if(glm::isnan(x)) + return ~0; + else if(glm::isinf(x)) + return 0x1f << 6; + + uif Union; + Union.f = x; + return float2packed11(Union.i); + } + + glm::uint floatTo10bit(float x) + { + if(x == 0.0f) + return 0; + else if(glm::isnan(x)) + return ~0; + else if(glm::isinf(x)) + return 0x1f << 5; + + uif Union; + Union.f = x; + return float2packed10(Union.i); + } + + glm::uint f11_f11_f10(float x, float y, float z) + { + return ((floatTo11bit(x) & ((1 << 11) - 1)) << 0) | ((floatTo11bit(y) & ((1 << 11) - 1)) << 11) | ((floatTo10bit(z) & ((1 << 10) - 1)) << 22); + } +}//namespace detail + + GLM_FUNC_QUALIFIER uint32 packF11F11F10(vec3 const & v) + { + return + ((detail::floatTo11bit(v.x) & ((1 << 11) - 1)) << 0) | + ((detail::floatTo11bit(v.y) & ((1 << 11) - 1)) << 11) | + ((detail::floatTo10bit(v.z) & ((1 << 10) - 1)) << 22); + } + + GLM_FUNC_QUALIFIER vec3 unpackF11F11F10(uint32 const & v) + { + + } }//namespace glm diff --git a/test/gtc/CMakeLists.txt b/test/gtc/CMakeLists.txt index 273341a8..62c33063 100644 --- a/test/gtc/CMakeLists.txt +++ b/test/gtc/CMakeLists.txt @@ -6,6 +6,7 @@ glmCreateTestGTC(gtc_matrix_integer) glmCreateTestGTC(gtc_matrix_inverse) glmCreateTestGTC(gtc_matrix_transform) glmCreateTestGTC(gtc_noise) +glmCreateTestGTC(gtc_packing) glmCreateTestGTC(gtc_quaternion) glmCreateTestGTC(gtc_random) glmCreateTestGTC(gtc_reciprocal) diff --git a/test/gtc/gtc_packing.cpp b/test/gtc/gtc_packing.cpp new file mode 100644 index 00000000..7eaf5730 --- /dev/null +++ b/test/gtc/gtc_packing.cpp @@ -0,0 +1,142 @@ +/////////////////////////////////////////////////////////////////////////////////// +/// OpenGL Mathematics (glm.g-truc.net) +/// +/// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net) +/// Permission is hereby granted, free of charge, to any person obtaining a copy +/// of this software and associated documentation files (the "Software"), to deal +/// in the Software without restriction, including without limitation the rights +/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +/// copies of the Software, and to permit persons to whom the Software is +/// furnished to do so, subject to the following conditions: +/// +/// The above copyright notice and this permission notice shall be included in +/// all copies or substantial portions of the Software. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +/// THE SOFTWARE. +/// +/// @ref test +/// @file test/gtc/packing.cpp +/// @date 2013-08-09 / 2013-08-09 +/// @author Christophe Riccio +/////////////////////////////////////////////////////////////////////////////////// + + +#include +#include + +void print_bits(glm::half const & s) +{ + union + { + glm::detail::hdata h; + unsigned short i; + } uif; + + uif.h = s._data(); + + printf("f16: "); + for(std::size_t j = sizeof(s) * 8; j > 0; --j) + { + if(j == 10 || j == 15) + printf(" "); + printf("%d", (uif.i & (1 << (j - 1))) ? 1 : 0); + } +} + +void print_bits(float const & s) +{ + union + { + float f; + unsigned int i; + } uif; + + uif.f = s; + + printf("f32: "); + for(std::size_t j = sizeof(s) * 8; j > 0; --j) + { + if(j == 23 || j == 31) + printf(" "); + printf("%d", (uif.i & (1 << (j - 1))) ? 1 : 0); + } +} + +void print_10bits(glm::uint const & s) +{ + printf("10b: "); + for(std::size_t j = 10; j > 0; --j) + { + if(j == 5) + printf(" "); + printf("%d", (s & (1 << (j - 1))) ? 1 : 0); + } +} + +void print_11bits(glm::uint const & s) +{ + printf("11b: "); + for(std::size_t j = 11; j > 0; --j) + { + if(j == 6) + printf(" "); + printf("%d", (s & (1 << (j - 1))) ? 1 : 0); + } +} + +void print_value(float const & s) +{ + printf("%2.5f, ", s); + print_bits(s); + printf(", "); + print_bits(glm::half(s)); + printf(", "); + print_11bits(detail::floatTo11bit(s)); + printf(", "); + print_10bits(detail::floatTo10bit(s)); + printf("\n"); +} + +int test_half() +{ + int Error = 0; + + print_value(0.0); + print_value(0.1); + print_value(0.2); + print_value(0.3); + print_value(0.4); + print_value(0.5); + print_value(0.6); + print_value(1.0); + print_value(1.1); + print_value(1.2); + print_value(1.3); + print_value(1.4); + print_value(1.5); + print_value(1.6); + print_value(2.0); + print_value(2.1); + print_value(2.2); + print_value(2.3); + print_value(2.4); + print_value(2.5); + print_value(2.6); + + return Error; +} + +int main() +{ + int Error(0); + + Error += test_half(); + + return Error; +} From a105876133a98c9b396437a4b98527d22bf36b5b Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 11 Aug 2013 02:16:47 +0200 Subject: [PATCH 03/15] Added GTC_packing implementation --- glm/core/func_packing.inl | 10 +- glm/core/func_vector_relational.hpp | 10 +- glm/gtc/packing.hpp | 34 ++-- glm/gtc/packing.inl | 260 +++++++++++++++++++++++++++- test/gtc/gtc_half_float.cpp | 42 ++--- test/gtc/gtc_packing.cpp | 51 +++--- 6 files changed, 333 insertions(+), 74 deletions(-) diff --git a/glm/core/func_packing.inl b/glm/core/func_packing.inl index ce22d4e9..2ee447e1 100644 --- a/glm/core/func_packing.inl +++ b/glm/core/func_packing.inl @@ -40,9 +40,7 @@ namespace glm uint32 Mask16((1 << 16) - 1); uint32 A((p >> 0) & Mask16); uint32 B((p >> 16) & Mask16); - return vec2( - A * 1.0f / 65535.0f, - B * 1.0f / 65535.0f); + return vec2(A, B) * float(1.5259021896696421759365224689097e-5); // 1.0 / 65535.0 } GLM_FUNC_QUALIFIER uint32 packSnorm2x16(vec2 const & v) @@ -53,9 +51,9 @@ namespace glm uint16 u; } A, B; - vec2 Unpack = clamp(v ,-1.0f, 1.0f) * 32767.0f; - A.i = detail::int16(round(Unpack.x)); - B.i = detail::int16(round(Unpack.y)); + vec2 Unpack = round(clamp(v ,-1.0f, 1.0f) * 32767.0f); + A.i = detail::int16(Unpack.x); + B.i = detail::int16(Unpack.y); uint32 Pack = (uint32(B.u) << 16) | (uint32(A.u) << 0); return Pack; } diff --git a/glm/core/func_vector_relational.hpp b/glm/core/func_vector_relational.hpp index b2fe4407..4c7d6813 100644 --- a/glm/core/func_vector_relational.hpp +++ b/glm/core/func_vector_relational.hpp @@ -52,8 +52,9 @@ namespace glm /// /// @see GLSL lessThan man page /// @see GLSL 4.20.8 specification, section 8.7 Vector Relational Functions - template class vecType> - GLM_FUNC_DECL typename vecType::bool_type lessThan(vecType const & x, vecType const & y); + // TODO: Mismatched + //template class vecType> + //GLM_FUNC_DECL typename vecType::bool_type lessThan(vecType const & x, vecType const & y); /// Returns the component-wise comparison of result x <= y. /// @@ -88,8 +89,9 @@ namespace glm /// /// @see GLSL equal man page /// @see GLSL 4.20.8 specification, section 8.7 Vector Relational Functions - template class vecType> - GLM_FUNC_DECL typename vecType::bool_type equal(vecType const & x, vecType const & y); + //TODO: conflicts with definision + //template class vecType> + //GLM_FUNC_DECL typename vecType::bool_type equal(vecType const & x, vecType const & y); /// Returns the component-wise comparison of result x != y. /// diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index f77b9f0d..15a2b3e7 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -51,23 +51,23 @@ namespace glm /// @addtogroup gtc_packing /// @{ - uint16 packUnorm1x16(float v); - float unpackUnorm1x16(uint16 v); + GLM_FUNC_DECL uint16 packUnorm1x16(float v); + GLM_FUNC_DECL float unpackUnorm1x16(uint16 v); - uint64 packUnorm4x16(vec4 const & v); - vec4 unpackUnorm4x16(uint64 const & v); + GLM_FUNC_DECL uint64 packUnorm4x16(vec4 const & v); + GLM_FUNC_DECL vec4 unpackUnorm4x16(uint64 const & v); - uint16 packSnorm1x16(float v); - float unpackSnorm1x16(uint16 v); + GLM_FUNC_DECL uint16 packSnorm1x16(float v); + GLM_FUNC_DECL float unpackSnorm1x16(uint16 v); - uint64 packSnorm4x16(vec4 const & v); - vec4 unpackSnorm4x16(uint64 const & v); + GLM_FUNC_DECL uint64 packSnorm4x16(vec4 const & v); + GLM_FUNC_DECL vec4 unpackSnorm4x16(uint64 const & v); - uint16 packUnorm2x8(vec2 const & v); - vec2 unpackUnorm2x8(uint16 v); + GLM_FUNC_DECL uint16 packUnorm2x8(vec2 const & v); + GLM_FUNC_DECL vec2 unpackUnorm2x8(uint16 v); - uint16 packSnorm2x8(vec2 const & v); - vec2 unpackSnorm2x8(uint16 v); + GLM_FUNC_DECL uint16 packSnorm2x8(vec2 const & v); + GLM_FUNC_DECL vec2 unpackSnorm2x8(uint16 v); GLM_FUNC_DECL uint16 packHalf1x16(float const & v); GLM_FUNC_DECL float unpackHalf1x16(uint16 const & v); @@ -93,16 +93,16 @@ namespace glm /// @see GLSL unpackHalf2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL vec4 unpackHalf4x16(uint64 const & v); - - GLM_FUNC_DECL uint32 packSnorm3x10Snorm1x2(vec4 const & v); - GLM_FUNC_DECL vec4 unpackSnorm3x10Snorm1x2(uint32 const & v); - GLM_FUNC_DECL uint32 packI3x10I1x2(ivec4 const & v); - GLM_FUNC_DECL ivec4 unpackI3x10I1x2(uint32 const & v); + GLM_FUNC_DECL uint32 packI10I10I10I2(ivec4 const & v); + GLM_FUNC_DECL ivec4 unpackI10I10I10I2(uint32 const & v); GLM_FUNC_DECL uint32 packU10U10U10U2(uvec4 const & v); GLM_FUNC_DECL uvec4 unpackU10U10U10U2(uint32 const & v); + GLM_FUNC_DECL uint32 packSnorm3x10_1x2(vec4 const & v); + GLM_FUNC_DECL vec4 unpackSnorm3x10_1x2(uint32 const & v); + GLM_FUNC_DECL uint32 packF11F11F10(vec3 const & v); GLM_FUNC_DECL vec3 unpackF11F11F10(uint32 const & v); diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 2ae8e139..9b078dad 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -130,12 +130,270 @@ namespace detail { return ((floatTo11bit(x) & ((1 << 11) - 1)) << 0) | ((floatTo11bit(y) & ((1 << 11) - 1)) << 11) | ((floatTo10bit(z) & ((1 << 10) - 1)) << 22); } + + union u10u10u10u2 + { + struct + { + uint x : 10; + uint y : 10; + uint z : 10; + uint w : 2; + } data; + uint32 pack; + }; + + union i10i10i10i2 + { + struct + { + int x : 10; + int y : 10; + int z : 10; + int w : 2; + } data; + uint32 pack; + }; + + union unorm4x16 + { + struct + { + uint16 x; + uint16 y; + uint16 z; + uint16 w; + } data; + uint64 pack; + }; + + union snorm4x16 + { + struct + { + int16 x; + int16 y; + int16 z; + int16 w; + } data; + uint64 pack; + }; + + union snorm1x16 + { + int16 data; + uint16 pack; + }; + + union half1x16 + { + hdata data; + uint16 pack; + }; + + union unorm2x8 + { + struct + { + uint8 x; + uint8 y; + } data; + uint16 pack; + }; + + union snorm2x8 + { + struct + { + int8 x; + int8 y; + } data; + uint16 pack; + }; }//namespace detail + GLM_FUNC_QUALIFIER uint16 packUnorm1x16(float s) + { + return uint16(round(clamp(s, 0.0f, 1.0f) * 65535.0f)); + } + + GLM_FUNC_QUALIFIER float unpackUnorm1x16(uint16 p) + { + return float(p) * 1.0f / 65535.0f; + } + + GLM_FUNC_QUALIFIER uint64 packUnorm4x16(vec4 const & v) + { + i16vec4 Scaled(round(clamp(v, 0.0f, 1.0f) * 65535.0f)); + detail::unorm4x16 Packing; + Packing.data.x = Scaled[0]; + Packing.data.y = Scaled[1]; + Packing.data.z = Scaled[2]; + Packing.data.w = Scaled[3]; + return Packing.pack; + } + + GLM_FUNC_QUALIFIER vec4 unpackUnorm4x16(uint64 const & p) + { + detail::unorm4x16 Packing; + vec4 Result( + float(Packing.data.x), + float(Packing.data.y), + float(Packing.data.z), + float(Packing.data.w)); + Result *= float(1.5259021896696421759365224689097e-5); // 1.0 / 65535.0 + } + + GLM_FUNC_QUALIFIER uint16 packSnorm1x16(float v) + { + float Scaled = clamp(v ,-1.0f, 1.0f) * 32767.0f; + detail::snorm1x16 Packing; + Packing.data = detail::int16(Scaled); + return Packing.pack; + } + + GLM_FUNC_QUALIFIER float unpackSnorm1x16(uint16 p) + { + detail::snorm1x16 Packing; + Packing.pack = p; + return clamp(float(Packing.data) * float(3.0518509475997192297128208258309e-5), -1.0f, 1.0f); //1.0f / 32767.0f + } + + GLM_FUNC_QUALIFIER uint64 packSnorm4x16(vec4 const & v) + { + i16vec4 Scaled(clamp(v ,-1.0f, 1.0f) * 32767.0f); + detail::snorm4x16 Packing; + Packing.data.x = Scaled.x; + Packing.data.y = Scaled.y; + Packing.data.z = Scaled.z; + Packing.data.w = Scaled.w; + return Packing.pack; + } + + GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 const & p) + { + detail::snorm4x16 Packing; + Packing.pack = p; + vec4 Unpacked(Packing.data.x, Packing.data.y, Packing.data.z, Packing.data.w); + return clamp(Unpacked * float(3.0518509475997192297128208258309e-5), -1.0f, 1.0f); //1.0f / 32767.0f + } + + GLM_FUNC_QUALIFIER uint16 packUnorm2x8(vec2 const & v) + { + i8vec2 Scaled(round(clamp(v ,-1.0f, 1.0f) * 255.0f)); + detail::unorm2x8 Packing; + Packing.data.x = Scaled.x; + Packing.data.y = Scaled.y; + return Packing.pack; + } + + GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p) + { + detail::unorm2x8 Packing; + Packing.pack = p; + vec2 Unpacked(Packing.data.x, Packing.data.y); + return Unpacked * float(0.0039215686274509803921568627451); + } + + GLM_FUNC_QUALIFIER uint16 packSnorm2x8(vec2 const & v) + { + glm::i8vec2 Scaled(round(clamp(v ,-1.0f, 1.0f) * 127.0f)); + detail::snorm2x8 Packing; + Packing.data.x = Scaled.x; + Packing.data.y = Scaled.y; + return Packing.pack; + } + + GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p) + { + detail::snorm2x8 Packing; + Packing.pack = p; + vec2 Unpacked(Packing.data.x, Packing.data.y); + return clamp(Unpacked * float(0.00787401574803149606299212598425), -1.0f, 1.0f); + } + + GLM_FUNC_DECL uint16 packHalf1x16(float const & v) + { + detail::half1x16 Packing; + Packing.data = detail::toFloat16(v); + return Packing.pack; + } + + GLM_FUNC_DECL float unpackHalf1x16(uint16 const & v) + { + detail::half1x16 Packing; + Packing.pack = v; + return detail::toFloat32(Packing.data); + } + + GLM_FUNC_QUALIFIER uint32 packI10I10I10I2(ivec4 const & v) + { + detail::i10i10i10i2 Result; + Result.data.x = v.x; + Result.data.y = v.y; + Result.data.z = v.z; + Result.data.w = v.w; + return Result.pack; + } + + GLM_FUNC_QUALIFIER ivec4 unpackI10I10I10I2(uint32 const & v) + { + detail::i10i10i10i2 Unpack; + Unpack.pack = v; + return ivec4( + Unpack.data.x, + Unpack.data.y, + Unpack.data.z, + Unpack.data.w); + } + + GLM_FUNC_QUALIFIER uint32 packU10U10U10U2(uvec4 const & v) + { + detail::u10u10u10u2 Result; + Result.data.x = v.x; + Result.data.y = v.y; + Result.data.z = v.z; + Result.data.w = v.w; + return Result.pack; + } + + GLM_FUNC_QUALIFIER uvec4 unpackU10U10U10U2(uint32 const & v) + { + detail::u10u10u10u2 Unpack; + Unpack.pack = v; + return uvec4( + Unpack.data.x, + Unpack.data.y, + Unpack.data.z, + Unpack.data.w); + } + + GLM_FUNC_QUALIFIER uint32 packSnorm3x10_1x2(vec4 const & v) + { + detail::i10i10i10i2 Result; + Result.data.x = int(v.x * 511.f); + Result.data.y = int(v.y * 511.f); + Result.data.z = int(v.z * 511.f); + Result.data.w = int(v.w * 1.f); + return Result.pack; + } + + GLM_FUNC_QUALIFIER vec4 unpackSnorm3x10_1x2(uint32 const & v) + { + detail::i10i10i10i2 Unpack; + Unpack.pack = v; + vec4 Result; + Result.x = float(Unpack.data.x) / 511.f; + Result.y = float(Unpack.data.y) / 511.f; + Result.z = float(Unpack.data.z) / 511.f; + Result.w = float(Unpack.data.w) / 1.f; + return Result; + } + GLM_FUNC_QUALIFIER uint32 packF11F11F10(vec3 const & v) { return - ((detail::floatTo11bit(v.x) & ((1 << 11) - 1)) << 0) | + ((detail::floatTo11bit(v.x) & ((1 << 11) - 1)) << 0) | ((detail::floatTo11bit(v.y) & ((1 << 11) - 1)) << 11) | ((detail::floatTo10bit(v.z) & ((1 << 10) - 1)) << 22); } diff --git a/test/gtc/gtc_half_float.cpp b/test/gtc/gtc_half_float.cpp index f054f599..41266142 100644 --- a/test/gtc/gtc_half_float.cpp +++ b/test/gtc/gtc_half_float.cpp @@ -791,27 +791,27 @@ int test_half() { int Error = 0; - print_value(0.0); - print_value(0.1); - print_value(0.2); - print_value(0.3); - print_value(0.4); - print_value(0.5); - print_value(0.6); - print_value(1.0); - print_value(1.1); - print_value(1.2); - print_value(1.3); - print_value(1.4); - print_value(1.5); - print_value(1.6); - print_value(2.0); - print_value(2.1); - print_value(2.2); - print_value(2.3); - print_value(2.4); - print_value(2.5); - print_value(2.6); + print_value(0.0f); + print_value(0.1f); + print_value(0.2f); + print_value(0.3f); + print_value(0.4f); + print_value(0.5f); + print_value(0.6f); + print_value(1.0f); + print_value(1.1f); + print_value(1.2f); + print_value(1.3f); + print_value(1.4f); + print_value(1.5f); + print_value(1.6f); + print_value(2.0f); + print_value(2.1f); + print_value(2.2f); + print_value(2.3f); + print_value(2.4f); + print_value(2.5f); + print_value(2.6f); return Error; } diff --git a/test/gtc/gtc_packing.cpp b/test/gtc/gtc_packing.cpp index 7eaf5730..bd401792 100644 --- a/test/gtc/gtc_packing.cpp +++ b/test/gtc/gtc_packing.cpp @@ -29,6 +29,7 @@ #include #include +#include void print_bits(glm::half const & s) { @@ -96,10 +97,10 @@ void print_value(float const & s) print_bits(s); printf(", "); print_bits(glm::half(s)); - printf(", "); - print_11bits(detail::floatTo11bit(s)); - printf(", "); - print_10bits(detail::floatTo10bit(s)); +// printf(", "); +// print_11bits(detail::floatTo11bit(s)); +// printf(", "); +// print_10bits(detail::floatTo10bit(s)); printf("\n"); } @@ -107,27 +108,27 @@ int test_half() { int Error = 0; - print_value(0.0); - print_value(0.1); - print_value(0.2); - print_value(0.3); - print_value(0.4); - print_value(0.5); - print_value(0.6); - print_value(1.0); - print_value(1.1); - print_value(1.2); - print_value(1.3); - print_value(1.4); - print_value(1.5); - print_value(1.6); - print_value(2.0); - print_value(2.1); - print_value(2.2); - print_value(2.3); - print_value(2.4); - print_value(2.5); - print_value(2.6); + print_value(0.0f); + print_value(0.1f); + print_value(0.2f); + print_value(0.3f); + print_value(0.4f); + print_value(0.5f); + print_value(0.6f); + print_value(1.0f); + print_value(1.1f); + print_value(1.2f); + print_value(1.3f); + print_value(1.4f); + print_value(1.5f); + print_value(1.6f); + print_value(2.0f); + print_value(2.1f); + print_value(2.2f); + print_value(2.3f); + print_value(2.4f); + print_value(2.5f); + print_value(2.6f); return Error; } From 53bd892a88a1bed9a0f95d2e1079aea806a16b7b Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 19 Aug 2013 00:36:56 +0200 Subject: [PATCH 04/15] Added 1x8 packing functions. Add documentation for half packing functions. --- glm/gtc/packing.hpp | 51 ++++++++++++++----- glm/gtc/packing.inl | 117 ++++++++++++++++++++++++++++++-------------- 2 files changed, 121 insertions(+), 47 deletions(-) diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index 15a2b3e7..4e5f815c 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -51,43 +51,72 @@ namespace glm /// @addtogroup gtc_packing /// @{ + GLM_FUNC_DECL uint8 packUnorm1x8(float const & v); + GLM_FUNC_DECL float unpackUnorm1x8(uint8 v); + + GLM_FUNC_DECL uint16 packUnorm2x8(vec2 const & v); + GLM_FUNC_DECL vec2 unpackUnorm2x8(uint16 v); + + + GLM_FUNC_DECL uint8 packSnorm1x8(float const & v); + GLM_FUNC_DECL float unpackSnorm1x8(uint8 v); + + GLM_FUNC_DECL uint16 packSnorm2x8(vec2 const & v); + GLM_FUNC_DECL vec2 unpackSnorm2x8(uint16 v); + + GLM_FUNC_DECL uint16 packUnorm1x16(float v); GLM_FUNC_DECL float unpackUnorm1x16(uint16 v); GLM_FUNC_DECL uint64 packUnorm4x16(vec4 const & v); GLM_FUNC_DECL vec4 unpackUnorm4x16(uint64 const & v); + GLM_FUNC_DECL uint16 packSnorm1x16(float v); GLM_FUNC_DECL float unpackSnorm1x16(uint16 v); GLM_FUNC_DECL uint64 packSnorm4x16(vec4 const & v); GLM_FUNC_DECL vec4 unpackSnorm4x16(uint64 const & v); - GLM_FUNC_DECL uint16 packUnorm2x8(vec2 const & v); - GLM_FUNC_DECL vec2 unpackUnorm2x8(uint16 v); - - GLM_FUNC_DECL uint16 packSnorm2x8(vec2 const & v); - GLM_FUNC_DECL vec2 unpackSnorm2x8(uint16 v); - + + /// Returns an unsigned integer obtained by converting the components of a floating-point scalar + /// to the 16-bit floating-point representation found in the OpenGL Specification, + /// and then packing this 16-bit value into a 16-bit unsigned integer. + /// + /// @see gtc_packing + /// @see uint32 packHalf2x16(vec2 const & v) + /// @see uint64 packHalf4x16(vec4 const & v) + /// @see GLSL packHalf2x16 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint16 packHalf1x16(float const & v); + + /// Returns a floating-point scalar with components obtained by unpacking a 16-bit unsigned integer into a 16-bit value, + /// interpreted as a 16-bit floating-point number according to the OpenGL Specification, + /// and converting it to 32-bit floating-point values. + /// + /// @see gtc_packing + /// @see GLSL unpackHalf2x16 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL float unpackHalf1x16(uint16 const & v); - /// Returns an unsigned integer obtained by converting the components of a two-component floating-point vector + /// Returns an unsigned integer obtained by converting the components of a four-component floating-point vector /// to the 16-bit floating-point representation found in the OpenGL Specification, - /// and then packing these two 16- bit integers into a 32-bit unsigned integer. + /// and then packing these four 16-bit values into a 64-bit unsigned integer. /// The first vector component specifies the 16 least-significant bits of the result; - /// the second component specifies the 16 most-significant bits. + /// the forth component specifies the 16 most-significant bits. /// /// @see gtc_packing + /// @see uint16 packHalf1x16(float const & v) + /// @see uint32 packHalf2x16(vec2 const & v) /// @see GLSL packHalf2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint64 packHalf4x16(vec4 const & v); - /// Returns a two-component floating-point vector with components obtained by unpacking a 32-bit unsigned integer into a pair of 16-bit values, + /// Returns a four-component floating-point vector with components obtained by unpacking a 64-bit unsigned integer into four 16-bit values, /// interpreting those values as 16-bit floating-point numbers according to the OpenGL Specification, /// 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 second component is obtained from the 16 most-significant bits of v. + /// the forth component is obtained from the 16 most-significant bits of v. /// /// @see gtc_packing /// @see GLSL unpackHalf2x16 man page diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 9b078dad..982d96db 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -26,8 +26,7 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// -namespace glm -{ +namespace glm{ namespace detail { glm::uint16 float2half(glm::uint32 const & f) @@ -191,6 +190,13 @@ namespace detail uint16 pack; }; + + union unorm1x8 + { + uint8 data; + uint8 pack; + }; + union unorm2x8 { struct @@ -201,6 +207,12 @@ namespace detail uint16 pack; }; + union snorm1x8 + { + int8 data; + uint8 pack; + }; + union snorm2x8 { struct @@ -212,6 +224,73 @@ namespace detail }; }//namespace detail + + GLM_FUNC_QUALIFIER uint8 packUnorm1x8(float const & v) + { + int8 Scaled(round(clamp(v ,-1.0f, 1.0f) * 255.0f)); + detail::unorm1x8 Packing; + Packing.data = Scaled; + return Packing.pack; + } + + GLM_FUNC_QUALIFIER float unpackUnorm1x8(uint8 p) + { + detail::unorm1x8 Packing; + Packing.pack = p; + float Unpacked(Packing.data); + return Unpacked * float(0.0039215686274509803921568627451); + } + + GLM_FUNC_QUALIFIER uint16 packUnorm2x8(vec2 const & v) + { + i8vec2 Scaled(round(clamp(v ,-1.0f, 1.0f) * 255.0f)); + detail::unorm2x8 Packing; + Packing.data.x = Scaled.x; + Packing.data.y = Scaled.y; + return Packing.pack; + } + + GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p) + { + detail::unorm2x8 Packing; + Packing.pack = p; + vec2 Unpacked(Packing.data.x, Packing.data.y); + return Unpacked * float(0.0039215686274509803921568627451); + } + + GLM_FUNC_QUALIFIER uint8 packSnorm1x8(float const & v) + { + glm::int8 Scaled(round(clamp(v ,-1.0f, 1.0f) * 127.0f)); + detail::snorm1x8 Packing; + Packing.x = Scaled.x; + return Packing.pack; + } + + GLM_FUNC_QUALIFIER float unpackSnorm1x8(uint8 p) + { + detail::snorm1x8 Packing; + Packing.pack = p; + float Unpacked(Packing.data); + return clamp(Unpacked * float(0.00787401574803149606299212598425), -1.0f, 1.0f); + } + + GLM_FUNC_QUALIFIER uint16 packSnorm2x8(vec2 const & v) + { + glm::i8vec2 Scaled(round(clamp(v ,-1.0f, 1.0f) * 127.0f)); + detail::snorm2x8 Packing; + Packing.data.x = Scaled.x; + Packing.data.y = Scaled.y; + return Packing.pack; + } + + GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p) + { + detail::snorm2x8 Packing; + Packing.pack = p; + vec2 Unpacked(Packing.data.x, Packing.data.y); + return clamp(Unpacked * float(0.00787401574803149606299212598425), -1.0f, 1.0f); + } + GLM_FUNC_QUALIFIER uint16 packUnorm1x16(float s) { return uint16(round(clamp(s, 0.0f, 1.0f) * 65535.0f)); @@ -278,40 +357,6 @@ namespace detail return clamp(Unpacked * float(3.0518509475997192297128208258309e-5), -1.0f, 1.0f); //1.0f / 32767.0f } - GLM_FUNC_QUALIFIER uint16 packUnorm2x8(vec2 const & v) - { - i8vec2 Scaled(round(clamp(v ,-1.0f, 1.0f) * 255.0f)); - detail::unorm2x8 Packing; - Packing.data.x = Scaled.x; - Packing.data.y = Scaled.y; - return Packing.pack; - } - - GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p) - { - detail::unorm2x8 Packing; - Packing.pack = p; - vec2 Unpacked(Packing.data.x, Packing.data.y); - return Unpacked * float(0.0039215686274509803921568627451); - } - - GLM_FUNC_QUALIFIER uint16 packSnorm2x8(vec2 const & v) - { - glm::i8vec2 Scaled(round(clamp(v ,-1.0f, 1.0f) * 127.0f)); - detail::snorm2x8 Packing; - Packing.data.x = Scaled.x; - Packing.data.y = Scaled.y; - return Packing.pack; - } - - GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p) - { - detail::snorm2x8 Packing; - Packing.pack = p; - vec2 Unpacked(Packing.data.x, Packing.data.y); - return clamp(Unpacked * float(0.00787401574803149606299212598425), -1.0f, 1.0f); - } - GLM_FUNC_DECL uint16 packHalf1x16(float const & v) { detail::half1x16 Packing; From 180788150919da3e9c664002ba5d63147be3fee1 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 21 Aug 2013 00:14:02 +0200 Subject: [PATCH 05/15] Added packXNorm documentation --- glm/gtc/packing.hpp | 96 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 84 insertions(+), 12 deletions(-) diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index 4e5f815c..39f526b9 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -51,33 +51,105 @@ namespace glm /// @addtogroup gtc_packing /// @{ + /// First, converts the normalized floating-point value v into a 8-bit integer value. + /// Then, the results are packed into the returned 8-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packUnorm1x8: round(clamp(c, 0, +1) * 255.0) + /// + /// @see GLSL packUnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint8 packUnorm1x8(float const & v); GLM_FUNC_DECL float unpackUnorm1x8(uint8 v); - + + /// First, converts each component of the normalized floating-point value v into 8-bit integer values. + /// Then, the results are packed into the returned 16-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packUnorm2x8: round(clamp(c, 0, +1) * 255.0) + /// + /// The first component of the vector will be written to the least significant bits of the output; + /// the last component will be written to the most significant bits. + /// + /// @see GLSL packUnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint16 packUnorm2x8(vec2 const & v); GLM_FUNC_DECL vec2 unpackUnorm2x8(uint16 v); - - GLM_FUNC_DECL uint8 packSnorm1x8(float const & v); - GLM_FUNC_DECL float unpackSnorm1x8(uint8 v); + /// First, converts the normalized floating-point value v into 8-bit integer value. + /// Then, the results are packed into the returned 8-bit unsigned integer. + /// + /// The conversion to fixed point is done as follows: + /// packSnorm1x8: round(clamp(s, -1, +1) * 127.0) + /// + /// @see GLSL packSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL uint8 packSnorm1x8(float const & s); + GLM_FUNC_DECL float unpackSnorm1x8(uint8 p); + /// First, converts each component of the normalized floating-point value v into 8-bit integer values. + /// Then, the results are packed into the returned 16-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packSnorm2x8: round(clamp(c, -1, +1) * 127.0) + /// + /// The first component of the vector will be written to the least significant bits of the output; + /// the last component will be written to the most significant bits. + /// + /// @see GLSL packSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint16 packSnorm2x8(vec2 const & v); - GLM_FUNC_DECL vec2 unpackSnorm2x8(uint16 v); - + GLM_FUNC_DECL vec2 unpackSnorm2x8(uint16 p); + /// First, converts the normalized floating-point value v into a 16-bit integer value. + /// Then, the results are packed into the returned 16-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packUnorm1x16: round(clamp(c, 0, +1) * 65535.0) + /// + /// @see GLSL packUnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint16 packUnorm1x16(float v); - GLM_FUNC_DECL float unpackUnorm1x16(uint16 v); + GLM_FUNC_DECL float unpackUnorm1x16(uint16 p); + /// First, converts each component of the normalized floating-point value v into 16-bit integer values. + /// Then, the results are packed into the returned 64-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packUnorm4x16: round(clamp(c, 0, +1) * 65535.0) + /// + /// The first component of the vector will be written to the least significant bits of the output; + /// the last component will be written to the most significant bits. + /// + /// @see GLSL packUnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint64 packUnorm4x16(vec4 const & v); - GLM_FUNC_DECL vec4 unpackUnorm4x16(uint64 const & v); + GLM_FUNC_DECL vec4 unpackUnorm4x16(uint64 const & p); - + /// First, converts the normalized floating-point value v into 16-bit integer value. + /// Then, the results are packed into the returned 16-bit unsigned integer. + /// + /// The conversion to fixed point is done as follows: + /// packSnorm1x8: round(clamp(s, -1, +1) * 32767.0) + /// + /// @see GLSL packSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint16 packSnorm1x16(float v); - GLM_FUNC_DECL float unpackSnorm1x16(uint16 v); + GLM_FUNC_DECL float unpackSnorm1x16(uint16 p); + /// First, converts each component of the normalized floating-point value v into 16-bit integer values. + /// Then, the results are packed into the returned 64-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packSnorm2x8: round(clamp(c, -1, +1) * 32767.0) + /// + /// The first component of the vector will be written to the least significant bits of the output; + /// the last component will be written to the most significant bits. + /// + /// @see GLSL packSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint64 packSnorm4x16(vec4 const & v); - GLM_FUNC_DECL vec4 unpackSnorm4x16(uint64 const & v); - + GLM_FUNC_DECL vec4 unpackSnorm4x16(uint64 const & p); /// Returns an unsigned integer obtained by converting the components of a floating-point scalar /// to the 16-bit floating-point representation found in the OpenGL Specification, From da95e96fcf5319d281a34bdb67a2b1f04aa0e0ee Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 22 Aug 2013 23:24:18 +0200 Subject: [PATCH 06/15] Fixed build on Clang and C++11 --- glm/gtc/packing.inl | 7 +++++-- glm/gtc/type_ptr.inl | 19 ++++--------------- test/gtc/gtc_packing.cpp | 1 - 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 982d96db..7013024d 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -262,7 +262,7 @@ namespace detail { glm::int8 Scaled(round(clamp(v ,-1.0f, 1.0f) * 127.0f)); detail::snorm1x8 Packing; - Packing.x = Scaled.x; + Packing.data = Scaled; return Packing.pack; } @@ -321,6 +321,7 @@ namespace detail float(Packing.data.z), float(Packing.data.w)); Result *= float(1.5259021896696421759365224689097e-5); // 1.0 / 65535.0 + return Result; } GLM_FUNC_QUALIFIER uint16 packSnorm1x16(float v) @@ -445,7 +446,9 @@ namespace detail GLM_FUNC_QUALIFIER vec3 unpackF11F11F10(uint32 const & v) { - + vec3 Result; + // TODO + return Result; } }//namespace glm diff --git a/glm/gtc/type_ptr.inl b/glm/gtc/type_ptr.inl index 6b3e1ac0..e2276d8c 100644 --- a/glm/gtc/type_ptr.inl +++ b/glm/gtc/type_ptr.inl @@ -286,21 +286,10 @@ namespace glm //! Return the address to the data of the matrix input. /// @see gtc_type_ptr - template - GLM_FUNC_QUALIFIER T * value_ptr(detail::tmat4x3 & mat) - { - return &(mat[0].x); - } - - /// Return the constant address to the data of the quaternion input. - /// @see gtc_type_ptr template - GLM_FUNC_QUALIFIER T * value_ptr - ( - detail::tquat & q - ) + GLM_FUNC_QUALIFIER T * value_ptr(detail::tmat4x3 & mat) { - return &(q[0]); + return &(mat[0].x); } //! Return the constant address to the data of the input parameter. @@ -316,10 +305,10 @@ namespace glm //! Return the address to the data of the quaternion input. /// @see gtc_type_ptr - template + template GLM_FUNC_QUALIFIER T * value_ptr ( - detail::tquat & q + detail::tquat & q ) { return &(q[0]); diff --git a/test/gtc/gtc_packing.cpp b/test/gtc/gtc_packing.cpp index bd401792..cbbfa8e8 100644 --- a/test/gtc/gtc_packing.cpp +++ b/test/gtc/gtc_packing.cpp @@ -26,7 +26,6 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// - #include #include #include From 59cc657adab0b92a6f6b666ca447571238f8e564 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 23 Aug 2013 00:34:39 +0200 Subject: [PATCH 07/15] Added documentation for GTC_packing --- glm/core/func_packing.hpp | 108 +++++++++++++++++++------------------- glm/gtc/packing.hpp | 45 ++++++++++++++++ 2 files changed, 99 insertions(+), 54 deletions(-) diff --git a/glm/core/func_packing.hpp b/glm/core/func_packing.hpp index 4ce811a1..221f3aca 100644 --- a/glm/core/func_packing.hpp +++ b/glm/core/func_packing.hpp @@ -41,80 +41,80 @@ namespace glm /// @addtogroup core_func_packing /// @{ - //! First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values. - //! Then, the results are packed into the returned 32-bit unsigned integer. - //! - //! The conversion for component c of v to fixed point is done as follows: - //! packUnorm2x16: round(clamp(c, 0, +1) * 65535.0) - //! - //! The first component of the vector will be written to the least significant bits of the output; - //! the last component will be written to the most significant bits. - //! + /// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values. + /// Then, the results are packed into the returned 32-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packUnorm2x16: round(clamp(c, 0, +1) * 65535.0) + /// + /// The first component of the vector will be written to the least significant bits of the output; + /// the last component will be written to the most significant bits. + /// /// @see GLSL packUnorm2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint32 packUnorm2x16(vec2 const & v); - //! First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values. - //! Then, the results are packed into the returned 32-bit unsigned integer. - //! - //! The conversion for component c of v to fixed point is done as follows: - //! packSnorm2x16: round(clamp(v, -1, +1) * 32767.0) - //! - //! The first component of the vector will be written to the least significant bits of the output; - //! the last component will be written to the most significant bits. - //! + /// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values. + /// Then, the results are packed into the returned 32-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packSnorm2x16: round(clamp(v, -1, +1) * 32767.0) + /// + /// The first component of the vector will be written to the least significant bits of the output; + /// the last component will be written to the most significant bits. + /// /// @see GLSL packSnorm2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint32 packSnorm2x16(vec2 const & v); - //! First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values. - //! Then, the results are packed into the returned 32-bit unsigned integer. - //! - //! The conversion for component c of v to fixed point is done as follows: - //! packUnorm4x8: round(clamp(c, 0, +1) * 255.0) - //! - //! The first component of the vector will be written to the least significant bits of the output; - //! the last component will be written to the most significant bits. - //! + /// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values. + /// Then, the results are packed into the returned 32-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packUnorm4x8: round(clamp(c, 0, +1) * 255.0) + /// + /// The first component of the vector will be written to the least significant bits of the output; + /// the last component will be written to the most significant bits. + /// /// @see GLSL packUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint32 packUnorm4x8(vec4 const & v); - //! First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values. - //! Then, the results are packed into the returned 32-bit unsigned integer. - //! - //! The conversion for component c of v to fixed point is done as follows: - //! packSnorm4x8: round(clamp(c, -1, +1) * 127.0) - //! - //! The first component of the vector will be written to the least significant bits of the output; - //! the last component will be written to the most significant bits. - //! + /// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values. + /// Then, the results are packed into the returned 32-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packSnorm4x8: round(clamp(c, -1, +1) * 127.0) + /// + /// The first component of the vector will be written to the least significant bits of the output; + /// the last component will be written to the most significant bits. + /// /// @see GLSL packSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint32 packSnorm4x8(vec4 const & v); - //! First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers. - //! Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector. - //! - //! The conversion for unpacked fixed-point value f to floating point is done as follows: - //! unpackUnorm2x16: f / 65535.0 - //! - //! The first component of the returned vector will be extracted from the least significant bits of the input; - //! the last component will be extracted from the most significant bits. - //! + /// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackUnorm2x16: f / 65535.0 + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// /// @see GLSL unpackUnorm2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL vec2 unpackUnorm2x16(uint32 const & p); - //! First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers. - //! Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector. - //! - //! The conversion for unpacked fixed-point value f to floating point is done as follows: - //! unpackSnorm2x16: clamp(f / 32767.0, -1, +1) - //! - //! The first component of the returned vector will be extracted from the least significant bits of the input; - //! the last component will be extracted from the most significant bits. - //! + /// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackSnorm2x16: clamp(f / 32767.0, -1, +1) + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// /// @see GLSL unpackSnorm2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL vec2 unpackSnorm2x16(uint32 const & p); diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index 39f526b9..6e4e7a9c 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -57,6 +57,9 @@ namespace glm /// The conversion for component c of v to fixed point is done as follows: /// packUnorm1x8: round(clamp(c, 0, +1) * 255.0) /// + /// @see gtc_packing + /// @see uint16 packUnorm2x8(vec2 const & v) + /// @see uint32 packUnorm4x8(vec4 const & v) /// @see GLSL packUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint8 packUnorm1x8(float const & v); @@ -71,6 +74,9 @@ namespace glm /// The first component of the vector will be written to the least significant bits of the output; /// the last component will be written to the most significant bits. /// + /// @see gtc_packing + /// @see uint8 packUnorm1x8(float const & v) + /// @see uint32 packUnorm4x8(vec4 const & v) /// @see GLSL packUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint16 packUnorm2x8(vec2 const & v); @@ -82,6 +88,9 @@ namespace glm /// The conversion to fixed point is done as follows: /// packSnorm1x8: round(clamp(s, -1, +1) * 127.0) /// + /// @see gtc_packing + /// @see uint16 packSnorm2x8(vec2 const & v) + /// @see uint32 packSnorm4x8(vec4 const & v) /// @see GLSL packSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint8 packSnorm1x8(float const & s); @@ -96,6 +105,9 @@ namespace glm /// The first component of the vector will be written to the least significant bits of the output; /// the last component will be written to the most significant bits. /// + /// @see gtc_packing + /// @see uint8 packSnorm1x8(float const & v) + /// @see uint32 packSnorm4x8(vec4 const & v) /// @see GLSL packSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint16 packSnorm2x8(vec2 const & v); @@ -107,9 +119,21 @@ namespace glm /// The conversion for component c of v to fixed point is done as follows: /// packUnorm1x16: round(clamp(c, 0, +1) * 65535.0) /// + /// @see gtc_packing + /// @see uint16 packSnorm1x16(float const & v) + /// @see uint64 packSnorm4x16(vec4 const & v) /// @see GLSL packUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint16 packUnorm1x16(float v); + + /// First, unpacks a single 16-bit unsigned integer p into a of 16-bit unsigned integers. + /// Then, the value is converted to a normalized floating-point value to generate the returned scalar. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackUnorm1x16: f / 65535.0 + /// + /// @see GLSL unpackUnorm2x16 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL float unpackUnorm1x16(uint16 p); /// First, converts each component of the normalized floating-point value v into 16-bit integer values. @@ -121,9 +145,24 @@ namespace glm /// The first component of the vector will be written to the least significant bits of the output; /// the last component will be written to the most significant bits. /// + /// @see gtc_packing + /// @see uint16 packUnorm1x16(float const & v) + /// @see uint32 packUnorm2x16(vec2 const & v) /// @see GLSL packUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint64 packUnorm4x16(vec4 const & v); + + /// First, unpacks a single 64-bit unsigned integer p into four 16-bit unsigned integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackUnormx4x16: f / 65535.0 + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see GLSL unpackUnorm2x16 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL vec4 unpackUnorm4x16(uint64 const & p); /// First, converts the normalized floating-point value v into 16-bit integer value. @@ -132,6 +171,9 @@ namespace glm /// The conversion to fixed point is done as follows: /// packSnorm1x8: round(clamp(s, -1, +1) * 32767.0) /// + /// @see gtc_packing + /// @see uint32 packSnorm2x16(vec2 const & v) + /// @see uint64 packSnorm4x16(vec4 const & v) /// @see GLSL packSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint16 packSnorm1x16(float v); @@ -146,6 +188,9 @@ namespace glm /// The first component of the vector will be written to the least significant bits of the output; /// the last component will be written to the most significant bits. /// + /// @see gtc_packing + /// @see uint16 packSnorm1x16(float const & v) + /// @see uint32 packSnorm2x16(vec2 const & v) /// @see GLSL packSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint64 packSnorm4x16(vec4 const & v); From 965b6417224a2b26d6ef0f3601bc41a894a678ab Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sat, 24 Aug 2013 23:38:36 +0200 Subject: [PATCH 08/15] Added documentation for GTC+packing --- glm/gtc/packing.hpp | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index 6e4e7a9c..f11276e3 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -63,7 +63,18 @@ namespace glm /// @see GLSL packUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint8 packUnorm1x8(float const & v); - GLM_FUNC_DECL float unpackUnorm1x8(uint8 v); + + /// Convert a single 8-bit integer to a normalized floating-point value. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackUnorm4x8: f / 255.0 + /// + /// @see gtc_packing + /// @see vec2 unpackUnorm2x8(uint16 p) + /// @see vec4 unpackUnorm4x8(uint32 p) + /// @see GLSL unpackUnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL float unpackUnorm1x8(uint8 p); /// First, converts each component of the normalized floating-point value v into 8-bit integer values. /// Then, the results are packed into the returned 16-bit unsigned integer. @@ -80,7 +91,22 @@ namespace glm /// @see GLSL packUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint16 packUnorm2x8(vec2 const & v); - GLM_FUNC_DECL vec2 unpackUnorm2x8(uint16 v); + + /// First, unpacks a single 16-bit unsigned integer p into a pair of 8-bit unsigned integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned two-component vector. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackUnorm4x8: f / 255.0 + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see float unpackUnorm1x8(uint8 v) + /// @see vec4 unpackUnorm4x8(uint32 p) + /// @see GLSL unpackUnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions + GLM_FUNC_DECL vec2 unpackUnorm2x8(uint16 p); /// First, converts the normalized floating-point value v into 8-bit integer value. /// Then, the results are packed into the returned 8-bit unsigned integer. @@ -212,6 +238,8 @@ namespace glm /// and converting it to 32-bit floating-point values. /// /// @see gtc_packing + /// @see vec2 unpackHalf2x16(uint32 const & v) + /// @see vec4 unpackHalf4x16(uint64 const & v) /// @see GLSL unpackHalf2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL float unpackHalf1x16(uint16 const & v); @@ -236,6 +264,8 @@ namespace glm /// the forth component is obtained from the 16 most-significant bits of v. /// /// @see gtc_packing + /// @see float unpackHalf1x16(uint16 const & v) + /// @see vec2 unpackHalf2x16(uint32 const & v) /// @see GLSL unpackHalf2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL vec4 unpackHalf4x16(uint64 const & v); From 44f9db1c3bedf40a602ea4c5ae0a12bae1b5e34a Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 25 Aug 2013 00:02:03 +0200 Subject: [PATCH 09/15] Added documentation for GTC+packing --- glm/gtc/packing.hpp | 62 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index f11276e3..6fe95adf 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -74,7 +74,7 @@ namespace glm /// @see vec4 unpackUnorm4x8(uint32 p) /// @see GLSL unpackUnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL float unpackUnorm1x8(uint8 p); + GLM_FUNC_DECL float unpackUnorm1x8(uint8 pdf); /// First, converts each component of the normalized floating-point value v into 8-bit integer values. /// Then, the results are packed into the returned 16-bit unsigned integer. @@ -120,6 +120,18 @@ namespace glm /// @see GLSL packSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint8 packSnorm1x8(float const & s); + + /// First, unpacks a single 8-bit unsigned integer p into a single 8-bit signed integers. + /// Then, the value is converted to a normalized floating-point value to generate the returned scalar. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackSnorm1x8: clamp(f / 127.0, -1, +1) + /// + /// @see gtc_packing + /// @see vec2 unpackSnorm2x8(uint16 p) + /// @see vec4 unpackSnorm4x8(uint32 p) + /// @see GLSL unpackSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL float unpackSnorm1x8(uint8 p); /// First, converts each component of the normalized floating-point value v into 8-bit integer values. @@ -137,6 +149,21 @@ namespace glm /// @see GLSL packSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint16 packSnorm2x8(vec2 const & v); + + /// First, unpacks a single 16-bit unsigned integer p into a pair of 8-bit signed integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned two-component vector. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackSnorm2x8: clamp(f / 127.0, -1, +1) + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see float unpackSnorm1x8(uint8 p) + /// @see vec4 unpackSnorm4x8(uint32 p) + /// @see GLSL unpackSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL vec2 unpackSnorm2x8(uint16 p); /// First, converts the normalized floating-point value v into a 16-bit integer value. @@ -158,6 +185,9 @@ namespace glm /// The conversion for unpacked fixed-point value f to floating point is done as follows: /// unpackUnorm1x16: f / 65535.0 /// + /// @see gtc_packing + /// @see vec2 unpackUnorm2x16(uint32 p) + /// @see vec4 unpackUnorm4x16(uint64 p) /// @see GLSL unpackUnorm2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL float unpackUnorm1x16(uint16 p); @@ -187,6 +217,9 @@ namespace glm /// The first component of the returned vector will be extracted from the least significant bits of the input; /// the last component will be extracted from the most significant bits. /// + /// @see gtc_packing + /// @see float unpackUnorm1x16(uint16 p) + /// @see vec2 unpackUnorm2x16(uint32 p) /// @see GLSL unpackUnorm2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL vec4 unpackUnorm4x16(uint64 const & p); @@ -203,6 +236,18 @@ namespace glm /// @see GLSL packSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint16 packSnorm1x16(float v); + + /// First, unpacks a single 16-bit unsigned integer p into a single 16-bit signed integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned scalar. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackSnorm1x16: clamp(f / 32767.0, -1, +1) + /// + /// @see gtc_packing + /// @see vec2 unpackSnorm2x16(uint32 p) + /// @see vec4 unpackSnorm4x16(uint64 p) + /// @see GLSL unpackSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL float unpackSnorm1x16(uint16 p); /// First, converts each component of the normalized floating-point value v into 16-bit integer values. @@ -220,6 +265,21 @@ namespace glm /// @see GLSL packSnorm4x8 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL uint64 packSnorm4x16(vec4 const & v); + + /// First, unpacks a single 64-bit unsigned integer p into four 16-bit signed integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackSnorm4x16: clamp(f / 32767.0, -1, +1) + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see float unpackSnorm1x16(uint16 p) + /// @see vec2 unpackSnorm2x16(uint32 p) + /// @see GLSL unpackSnorm4x8 man page + /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions GLM_FUNC_DECL vec4 unpackSnorm4x16(uint64 const & p); /// Returns an unsigned integer obtained by converting the components of a floating-point scalar From 65d29dddaada1ac6d4d9b6729dea1d21256e1cf2 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 25 Aug 2013 22:26:10 +0200 Subject: [PATCH 10/15] Completed GTC_packing documentation --- glm/gtc/packing.hpp | 123 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 115 insertions(+), 8 deletions(-) diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index 6fe95adf..0db69d1d 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -328,19 +328,126 @@ namespace glm /// @see vec2 unpackHalf2x16(uint32 const & v) /// @see GLSL unpackHalf2x16 man page /// @see GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions - GLM_FUNC_DECL vec4 unpackHalf4x16(uint64 const & v); + GLM_FUNC_DECL vec4 unpackHalf4x16(uint64 const & p); - GLM_FUNC_DECL uint32 packI10I10I10I2(ivec4 const & v); - GLM_FUNC_DECL ivec4 unpackI10I10I10I2(uint32 const & v); + /// Returns an unsigned integer obtained by converting the components of a four-component signed integer vector + /// to the 10-10-10-2-bit signed integer representation found in the OpenGL Specification, + /// and then packing these four values into a 32-bit unsigned integer. + /// The first vector component specifies the 10 least-significant bits of the result; + /// the forth component specifies the 2 most-significant bits. + /// + /// @see gtc_packing + /// @see uint32 packI3x10_I1x2(uvec4 const & v) + /// @see uint32 packSnorm3x10_1x2(vec4 const & v) + /// @see uint32 packUnorm3x10_1x2(vec4 const & v) + /// @see ivec4 unpackI3x10_I1x2(uint32 const & p) + GLM_FUNC_DECL uint32 packI3x10_I1x2(ivec4 const & v); + GLM_FUNC_DECL ivec4 unpackI3x10_I1x2(uint32 const & p); - GLM_FUNC_DECL uint32 packU10U10U10U2(uvec4 const & v); - GLM_FUNC_DECL uvec4 unpackU10U10U10U2(uint32 const & v); + /// Returns an unsigned integer obtained by converting the components of a four-component unsigned integer vector + /// to the 10-10-10-2-bit unsigned integer representation found in the OpenGL Specification, + /// and then packing these four values into a 32-bit unsigned integer. + /// The first vector component specifies the 10 least-significant bits of the result; + /// the forth component specifies the 2 most-significant bits. + /// + /// @see gtc_packing + /// @see uint32 packI3x10_I1x2(ivec4 const & v) + /// @see uint32 packSnorm3x10_1x2(vec4 const & v) + /// @see uint32 packUnorm3x10_1x2(vec4 const & v) + /// @see ivec4 unpackU3x10_U1x2(uint32 const & p) + GLM_FUNC_DECL uint32 packU3x10_U1x2(uvec4 const & v); + GLM_FUNC_DECL uvec4 unpackU3x10_U1x2(uint32 const & p); + /// First, converts the first three components of the normalized floating-point value v into 10-bit signed integer values. + /// Then, converts the forth component of the normalized floating-point value v into 2-bit signed integer values. + /// Then, the results are packed into the returned 32-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packSnorm3x10_1x2(xyz): round(clamp(c, -1, +1) * 511.0) + /// packSnorm3x10_1x2(w): round(clamp(c, -1, +1) * 1.0) + /// + /// The first vector component specifies the 10 least-significant bits of the result; + /// the forth component specifies the 2 most-significant bits. + /// + /// @see gtc_packing + /// @see vec4 unpackSnorm3x10_1x2(uint32 const & p) + /// @see uint32 packUnorm3x10_1x2(vec4 const & v) + /// @see uint32 packU3x10_U1x2(uvec4 const & v) + /// @see uint32 packI3x10_I1x2(ivec4 const & v) GLM_FUNC_DECL uint32 packSnorm3x10_1x2(vec4 const & v); - GLM_FUNC_DECL vec4 unpackSnorm3x10_1x2(uint32 const & v); - GLM_FUNC_DECL uint32 packF11F11F10(vec3 const & v); - GLM_FUNC_DECL vec3 unpackF11F11F10(uint32 const & v); + /// First, unpacks a single 32-bit unsigned integer p into four 16-bit signed integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackSnorm3x10_1x2(xyz): clamp(f / 511.0, -1, +1) + /// unpackSnorm3x10_1x2(w): clamp(f / 511.0, -1, +1) + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see uint32 packSnorm3x10_1x2(vec4 const & v) + /// @see vec4 unpackUnorm3x10_1x2(uint32 const & p)) + /// @see uvec4 unpackI3x10_I1x2(uint32 const & p) + /// @see uvec4 unpackU3x10_U1x2(uint32 const & p) + GLM_FUNC_DECL vec4 unpackSnorm3x10_1x2(uint32 const & p); + + /// First, converts the first three components of the normalized floating-point value v into 10-bit unsigned integer values. + /// Then, converts the forth component of the normalized floating-point value v into 2-bit signed uninteger values. + /// Then, the results are packed into the returned 32-bit unsigned integer. + /// + /// The conversion for component c of v to fixed point is done as follows: + /// packUnorm3x10_1x2(xyz): round(clamp(c, 0, +1) * 1023.0) + /// packUnorm3x10_1x2(w): round(clamp(c, 0, +1) * 3.0) + /// + /// The first vector component specifies the 10 least-significant bits of the result; + /// the forth component specifies the 2 most-significant bits. + /// + /// @see gtc_packing + /// @see vec4 unpackUnorm3x10_1x2(uint32 const & p) + /// @see uint32 packUnorm3x10_1x2(vec4 const & v) + /// @see uint32 packU3x10_U1x2(uvec4 const & v) + /// @see uint32 packI3x10_I1x2(ivec4 const & v) + GLM_FUNC_DECL uint32 packUnorm3x10_1x2(vec4 const & v); + + /// First, unpacks a single 32-bit unsigned integer p into four 16-bit signed integers. + /// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector. + /// + /// The conversion for unpacked fixed-point value f to floating point is done as follows: + /// unpackSnorm3x10_1x2(xyz): clamp(f / 1023.0, 0, +1) + /// unpackSnorm3x10_1x2(w): clamp(f / 3.0, 0, +1) + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see uint32 packSnorm3x10_1x2(vec4 const & v) + /// @see vec4 unpackInorm3x10_1x2(uint32 const & p)) + /// @see uvec4 unpackI3x10_I1x2(uint32 const & p) + /// @see uvec4 unpackU3x10_U1x2(uint32 const & p) + GLM_FUNC_DECL vec4 unpackUnorm3x10_1x2(uint32 const & p); + + /// First, converts the first two components of the normalized floating-point value v into 11-bit signless floating-point values. + /// Then, converts the third component of the normalized floating-point value v into a 10-bit signless floating-point value. + /// Then, the results are packed into the returned 32-bit unsigned integer. + /// + /// The first vector component specifies the 11 least-significant bits of the result; + /// the last component specifies the 10 most-significant bits. + /// + /// @see gtc_packing + /// @see vec3 unpackF2x11_F1x10(uint32 const & p) + GLM_FUNC_DECL uint32 packF2x11_F1x10(vec3 const & v); + + /// First, unpacks a single 32-bit unsigned integer p into two 11-bit signless floating-point values and one 10-bit signless floating-point value . + /// Then, each component is converted to a normalized floating-point value to generate the returned three-component vector. + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see uint32 packF2x11_F1x10(vec3 const & v) + GLM_FUNC_DECL vec3 unpackF2x11_F1x10(uint32 const & p); /// @} }// namespace glm From 5645369d56ea83dab802d37d515c3f68dcf392d4 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 25 Aug 2013 22:30:52 +0200 Subject: [PATCH 11/15] Fixed packing implementation function names --- glm/gtc/packing.inl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 7013024d..3772a845 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -372,7 +372,7 @@ namespace detail return detail::toFloat32(Packing.data); } - GLM_FUNC_QUALIFIER uint32 packI10I10I10I2(ivec4 const & v) + GLM_FUNC_QUALIFIER uint32 packInorm3x10_1x2(ivec4 const & v) { detail::i10i10i10i2 Result; Result.data.x = v.x; @@ -382,7 +382,7 @@ namespace detail return Result.pack; } - GLM_FUNC_QUALIFIER ivec4 unpackI10I10I10I2(uint32 const & v) + GLM_FUNC_QUALIFIER ivec4 unpackInorm3x10_1x2(uint32 const & v) { detail::i10i10i10i2 Unpack; Unpack.pack = v; @@ -393,7 +393,7 @@ namespace detail Unpack.data.w); } - GLM_FUNC_QUALIFIER uint32 packU10U10U10U2(uvec4 const & v) + GLM_FUNC_QUALIFIER uint32 packUnorm3x10_1x2(uvec4 const & v) { detail::u10u10u10u2 Result; Result.data.x = v.x; @@ -403,7 +403,7 @@ namespace detail return Result.pack; } - GLM_FUNC_QUALIFIER uvec4 unpackU10U10U10U2(uint32 const & v) + GLM_FUNC_QUALIFIER uvec4 unpackUnorm3x10_1x2(uint32 const & v) { detail::u10u10u10u2 Unpack; Unpack.pack = v; From 6fd6cf2c8c15d5e621d23f49bfc9b6730c3e0774 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 25 Aug 2013 22:50:48 +0200 Subject: [PATCH 12/15] Fixed packing implementation function names, added missing (un)PackUnom3x10_1_2 implementations, fixed rounding and clamping on (un)packSnom3x10_1x2 implementations --- glm/gtc/packing.hpp | 40 ++++++++++++++++++------------------ glm/gtc/packing.inl | 50 ++++++++++++++++++++++++++++++++------------- 2 files changed, 56 insertions(+), 34 deletions(-) diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index 0db69d1d..4ff4b0a6 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -337,12 +337,12 @@ namespace glm /// the forth component specifies the 2 most-significant bits. /// /// @see gtc_packing - /// @see uint32 packI3x10_I1x2(uvec4 const & v) + /// @see uint32 packI3x10_1x2(uvec4 const & v) /// @see uint32 packSnorm3x10_1x2(vec4 const & v) /// @see uint32 packUnorm3x10_1x2(vec4 const & v) - /// @see ivec4 unpackI3x10_I1x2(uint32 const & p) - GLM_FUNC_DECL uint32 packI3x10_I1x2(ivec4 const & v); - GLM_FUNC_DECL ivec4 unpackI3x10_I1x2(uint32 const & p); + /// @see ivec4 unpackI3x10_1x2(uint32 const & p) + GLM_FUNC_DECL uint32 packI3x10_1x2(ivec4 const & v); + GLM_FUNC_DECL ivec4 unpackI3x10_1x2(uint32 const & p); /// Returns an unsigned integer obtained by converting the components of a four-component unsigned integer vector /// to the 10-10-10-2-bit unsigned integer representation found in the OpenGL Specification, @@ -351,12 +351,12 @@ namespace glm /// the forth component specifies the 2 most-significant bits. /// /// @see gtc_packing - /// @see uint32 packI3x10_I1x2(ivec4 const & v) + /// @see uint32 packI3x10_1x2(ivec4 const & v) /// @see uint32 packSnorm3x10_1x2(vec4 const & v) /// @see uint32 packUnorm3x10_1x2(vec4 const & v) - /// @see ivec4 unpackU3x10_U1x2(uint32 const & p) - GLM_FUNC_DECL uint32 packU3x10_U1x2(uvec4 const & v); - GLM_FUNC_DECL uvec4 unpackU3x10_U1x2(uint32 const & p); + /// @see ivec4 unpackU3x10_1x2(uint32 const & p) + GLM_FUNC_DECL uint32 packU3x10_1x2(uvec4 const & v); + GLM_FUNC_DECL uvec4 unpackU3x10_1x2(uint32 const & p); /// First, converts the first three components of the normalized floating-point value v into 10-bit signed integer values. /// Then, converts the forth component of the normalized floating-point value v into 2-bit signed integer values. @@ -372,8 +372,8 @@ namespace glm /// @see gtc_packing /// @see vec4 unpackSnorm3x10_1x2(uint32 const & p) /// @see uint32 packUnorm3x10_1x2(vec4 const & v) - /// @see uint32 packU3x10_U1x2(uvec4 const & v) - /// @see uint32 packI3x10_I1x2(ivec4 const & v) + /// @see uint32 packU3x10_1x2(uvec4 const & v) + /// @see uint32 packI3x10_1x2(ivec4 const & v) GLM_FUNC_DECL uint32 packSnorm3x10_1x2(vec4 const & v); /// First, unpacks a single 32-bit unsigned integer p into four 16-bit signed integers. @@ -389,8 +389,8 @@ namespace glm /// @see gtc_packing /// @see uint32 packSnorm3x10_1x2(vec4 const & v) /// @see vec4 unpackUnorm3x10_1x2(uint32 const & p)) - /// @see uvec4 unpackI3x10_I1x2(uint32 const & p) - /// @see uvec4 unpackU3x10_U1x2(uint32 const & p) + /// @see uvec4 unpackI3x10_1x2(uint32 const & p) + /// @see uvec4 unpackU3x10_1x2(uint32 const & p) GLM_FUNC_DECL vec4 unpackSnorm3x10_1x2(uint32 const & p); /// First, converts the first three components of the normalized floating-point value v into 10-bit unsigned integer values. @@ -407,8 +407,8 @@ namespace glm /// @see gtc_packing /// @see vec4 unpackUnorm3x10_1x2(uint32 const & p) /// @see uint32 packUnorm3x10_1x2(vec4 const & v) - /// @see uint32 packU3x10_U1x2(uvec4 const & v) - /// @see uint32 packI3x10_I1x2(ivec4 const & v) + /// @see uint32 packU3x10_1x2(uvec4 const & v) + /// @see uint32 packI3x10_1x2(ivec4 const & v) GLM_FUNC_DECL uint32 packUnorm3x10_1x2(vec4 const & v); /// First, unpacks a single 32-bit unsigned integer p into four 16-bit signed integers. @@ -424,8 +424,8 @@ namespace glm /// @see gtc_packing /// @see uint32 packSnorm3x10_1x2(vec4 const & v) /// @see vec4 unpackInorm3x10_1x2(uint32 const & p)) - /// @see uvec4 unpackI3x10_I1x2(uint32 const & p) - /// @see uvec4 unpackU3x10_U1x2(uint32 const & p) + /// @see uvec4 unpackI3x10_1x2(uint32 const & p) + /// @see uvec4 unpackU3x10_1x2(uint32 const & p) GLM_FUNC_DECL vec4 unpackUnorm3x10_1x2(uint32 const & p); /// First, converts the first two components of the normalized floating-point value v into 11-bit signless floating-point values. @@ -436,8 +436,8 @@ namespace glm /// the last component specifies the 10 most-significant bits. /// /// @see gtc_packing - /// @see vec3 unpackF2x11_F1x10(uint32 const & p) - GLM_FUNC_DECL uint32 packF2x11_F1x10(vec3 const & v); + /// @see vec3 unpackF2x11_1x10(uint32 const & p) + GLM_FUNC_DECL uint32 packF2x11_1x10(vec3 const & v); /// First, unpacks a single 32-bit unsigned integer p into two 11-bit signless floating-point values and one 10-bit signless floating-point value . /// Then, each component is converted to a normalized floating-point value to generate the returned three-component vector. @@ -446,8 +446,8 @@ namespace glm /// the last component will be extracted from the most significant bits. /// /// @see gtc_packing - /// @see uint32 packF2x11_F1x10(vec3 const & v) - GLM_FUNC_DECL vec3 unpackF2x11_F1x10(uint32 const & p); + /// @see uint32 packF2x11_1x10(vec3 const & v) + GLM_FUNC_DECL vec3 unpackF2x11_1x10(uint32 const & p); /// @} }// namespace glm diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 3772a845..e70b526f 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -372,7 +372,7 @@ namespace detail return detail::toFloat32(Packing.data); } - GLM_FUNC_QUALIFIER uint32 packInorm3x10_1x2(ivec4 const & v) + GLM_FUNC_QUALIFIER uint32 packI3x10_1x2(ivec4 const & v) { detail::i10i10i10i2 Result; Result.data.x = v.x; @@ -382,7 +382,7 @@ namespace detail return Result.pack; } - GLM_FUNC_QUALIFIER ivec4 unpackInorm3x10_1x2(uint32 const & v) + GLM_FUNC_QUALIFIER ivec4 unpackI3x10_1x2(uint32 const & v) { detail::i10i10i10i2 Unpack; Unpack.pack = v; @@ -393,7 +393,7 @@ namespace detail Unpack.data.w); } - GLM_FUNC_QUALIFIER uint32 packUnorm3x10_1x2(uvec4 const & v) + GLM_FUNC_QUALIFIER uint32 packU3x10_1x2(uvec4 const & v) { detail::u10u10u10u2 Result; Result.data.x = v.x; @@ -403,7 +403,7 @@ namespace detail return Result.pack; } - GLM_FUNC_QUALIFIER uvec4 unpackUnorm3x10_1x2(uint32 const & v) + GLM_FUNC_QUALIFIER uvec4 unpackU3x10_1x2(uint32 const & v) { detail::u10u10u10u2 Unpack; Unpack.pack = v; @@ -417,10 +417,10 @@ namespace detail GLM_FUNC_QUALIFIER uint32 packSnorm3x10_1x2(vec4 const & v) { detail::i10i10i10i2 Result; - Result.data.x = int(v.x * 511.f); - Result.data.y = int(v.y * 511.f); - Result.data.z = int(v.z * 511.f); - Result.data.w = int(v.w * 1.f); + Result.data.x = int(round(clamp(v.x,-1.0f, 1.0f) * 511.f)); + Result.data.y = int(round(clamp(v.y,-1.0f, 1.0f) * 511.f)); + Result.data.z = int(round(clamp(v.z,-1.0f, 1.0f) * 511.f)); + Result.data.w = int(round(clamp(v.w,-1.0f, 1.0f) * 1.f)); return Result.pack; } @@ -429,14 +429,36 @@ namespace detail detail::i10i10i10i2 Unpack; Unpack.pack = v; vec4 Result; - Result.x = float(Unpack.data.x) / 511.f; - Result.y = float(Unpack.data.y) / 511.f; - Result.z = float(Unpack.data.z) / 511.f; - Result.w = float(Unpack.data.w) / 1.f; + Result.x = clamp(float(Unpack.data.x) / 511.f, -1.0f, 1.0f); + Result.y = clamp(float(Unpack.data.y) / 511.f, -1.0f, 1.0f); + Result.z = clamp(float(Unpack.data.z) / 511.f, -1.0f, 1.0f); + Result.w = clamp(float(Unpack.data.w) / 1.f, -1.0f, 1.0f); return Result; } - GLM_FUNC_QUALIFIER uint32 packF11F11F10(vec3 const & v) + GLM_FUNC_QUALIFIER uint32 packUnorm3x10_1x2(vec4 const & v) + { + detail::i10i10i10i2 Result; + Result.data.x = int(round(clamp(v.x, 0.0f, 1.0f) * 1023.f)); + Result.data.y = int(round(clamp(v.y, 0.0f, 1.0f) * 1023.f)); + Result.data.z = int(round(clamp(v.z, 0.0f, 1.0f) * 1023.f)); + Result.data.w = int(round(clamp(v.w, 0.0f, 1.0f) * 3.f)); + return Result.pack; + } + + GLM_FUNC_QUALIFIER vec4 unpackUnorm3x10_1x2(uint32 const & v) + { + detail::i10i10i10i2 Unpack; + Unpack.pack = v; + vec4 Result; + Result.x = float(Unpack.data.x) / 1023.f; + Result.y = float(Unpack.data.y) / 1023.f; + Result.z = float(Unpack.data.z) / 1023.f; + Result.w = float(Unpack.data.w) / 3.f; + return Result; + } + + GLM_FUNC_QUALIFIER uint32 packF2x11_1x10(vec3 const & v) { return ((detail::floatTo11bit(v.x) & ((1 << 11) - 1)) << 0) | @@ -444,7 +466,7 @@ namespace detail ((detail::floatTo10bit(v.z) & ((1 << 10) - 1)) << 22); } - GLM_FUNC_QUALIFIER vec3 unpackF11F11F10(uint32 const & v) + GLM_FUNC_QUALIFIER vec3 unpackF2x11_1x10(uint32 const & v) { vec3 Result; // TODO From fb13e7bf8ad5feeb323c280f1f7cca39936c762a Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 26 Aug 2013 07:38:34 +0200 Subject: [PATCH 13/15] Added unpack 111110 implementation, missing inf and NaN code path --- glm/gtc/packing.inl | 87 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 10 deletions(-) diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index e70b526f..0864e6b3 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -47,7 +47,7 @@ namespace detail ((f >> 13) & 0x03ff); // Mantissa } - glm::uint16 float2packed11(glm::uint32 const & f) + glm::uint32 float2packed11(glm::uint32 const & f) { // 10 bits => EE EEEFFFFF // 11 bits => EEE EEFFFFFF @@ -61,11 +61,29 @@ namespace detail // 0x7f800000 => 01111111 10000000 00000000 00000000 // 0x00008000 => 00000000 00000000 10000000 00000000 return - ((((f & 0x7f800000) - 0x38000000) >> 17) & 0x07c0) | // exponential - ((f >> 17) & 0x003f); // Mantissa + ((((f & 0x7f800000) - 0x38000000) >> 17) & 0x07c0) | // exponential + ((f >> 17) & 0x003f); // Mantissa } - glm::uint float2packed10(glm::uint const & f) + glm::uint32 packed11Tofloat(glm::uint32 const & p) + { + // 10 bits => EE EEEFFFFF + // 11 bits => EEE EEFFFFFF + // Half bits => SEEEEEFF FFFFFFFF + // Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF + + // 0x000007c0 => 00000000 00000000 00000111 11000000 + // 0x00007c00 => 00000000 00000000 01111100 00000000 + // 0x000003ff => 00000000 00000000 00000011 11111111 + // 0x38000000 => 00111000 00000000 00000000 00000000 + // 0x7f800000 => 01111111 10000000 00000000 00000000 + // 0x00008000 => 00000000 00000000 10000000 00000000 + return + ((((p & 0x07c0) << 17) + 0x38000000) & 0x7f800000) | // exponential + ((f & 0x003f) << 17); // Mantissa + } + + glm::uint32 float2packed10(glm::uint32 const & f) { // 10 bits => EE EEEFFFFF // 11 bits => EEE EEFFFFFF @@ -82,10 +100,31 @@ namespace detail // 0x7f800000 => 01111111 10000000 00000000 00000000 // 0x00008000 => 00000000 00000000 10000000 00000000 return - ((((f & 0x7f800000) - 0x38000000) >> 18) & 0x03E0) | // exponential - ((f >> 18) & 0x001f); // Mantissa + ((((f & 0x7f800000) - 0x38000000) >> 18) & 0x03E0) | // exponential + ((f >> 18) & 0x001f); // Mantissa } + glm::uint32 packed10ToFloat(glm::uint32 const & p) + { + // 10 bits => EE EEEFFFFF + // 11 bits => EEE EEFFFFFF + // Half bits => SEEEEEFF FFFFFFFF + // Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF + + // 0x0000001F => 00000000 00000000 00000000 00011111 + // 0x0000003F => 00000000 00000000 00000000 00111111 + // 0x000003E0 => 00000000 00000000 00000011 11100000 + // 0x000007C0 => 00000000 00000000 00000111 11000000 + // 0x00007C00 => 00000000 00000000 01111100 00000000 + // 0x000003FF => 00000000 00000000 00000011 11111111 + // 0x38000000 => 00111000 00000000 00000000 00000000 + // 0x7f800000 => 01111111 10000000 00000000 00000000 + // 0x00008000 => 00000000 00000000 10000000 00000000 + return + ((((p & 0x03E0) << 18) + 0x38000000) & 0x7f800000) | // exponential + ((f & 0x001f) << 18); // Mantissa + } + glm::uint half2float(glm::uint const & h) { return ((h & 0x8000) << 16) | ((( h & 0x7c00) + 0x1C000) << 13) | ((h & 0x03FF) << 13); @@ -111,6 +150,20 @@ namespace detail return float2packed11(Union.i); } + float packed11bitToFloat(glm::uint x) + { + if(x == 0) + return 0.0f; + else if(x == ((1 << 11) - 1)) + return ~0;//NaN + else if(x == (0x1f << 6)) + return ~0;//Inf + + uif Union; + Union.i = packed11ToFloat(x); + return Union.f; + } + glm::uint floatTo10bit(float x) { if(x == 0.0f) @@ -124,6 +177,20 @@ namespace detail Union.f = x; return float2packed10(Union.i); } + + float packed10bitToFloat(glm::uint x) + { + if(x == 0) + return 0.0f; + else if(x == ((1 << 10) - 1)) + return ~0;//NaN + else if(x == (0x1f << 5)) + return ~0;//Inf + + uif Union; + Union.i = packed10ToFloat(x); + return Union.f; + } glm::uint f11_f11_f10(float x, float y, float z) { @@ -224,7 +291,6 @@ namespace detail }; }//namespace detail - GLM_FUNC_QUALIFIER uint8 packUnorm1x8(float const & v) { int8 Scaled(round(clamp(v ,-1.0f, 1.0f) * 255.0f)); @@ -468,9 +534,10 @@ namespace detail GLM_FUNC_QUALIFIER vec3 unpackF2x11_1x10(uint32 const & v) { - vec3 Result; - // TODO - return Result; + return vec3( + packed11bitToFloat(v >> 0), + packed11bitToFloat(v >> 11), + packed10bitToFloat(v >> 22)); } }//namespace glm From 0abec19bc172de8b11ac9a2de3226df43ac7a933 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 26 Aug 2013 08:28:17 +0200 Subject: [PATCH 14/15] Added missing documentation, missing 4x16 half packing functions, added initial tests --- glm/gtc/packing.hpp | 20 ++++++++++ glm/gtc/packing.inl | 14 +++++++ test/gtc/gtc_packing.cpp | 80 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 113 insertions(+), 1 deletion(-) diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index 4ff4b0a6..9433d54e 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -342,6 +342,16 @@ namespace glm /// @see uint32 packUnorm3x10_1x2(vec4 const & v) /// @see ivec4 unpackI3x10_1x2(uint32 const & p) GLM_FUNC_DECL uint32 packI3x10_1x2(ivec4 const & v); + + /// Unpacks a single 32-bit unsigned integer p into three 10-bit and one 2-bit signed integers. + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see uint32 packU3x10_1x2(uvec4 const & v) + /// @see vec4 unpackSnorm3x10_1x2(uint32 const & p); + /// @see uvec4 unpackI3x10_1x2(uint32 const & p); GLM_FUNC_DECL ivec4 unpackI3x10_1x2(uint32 const & p); /// Returns an unsigned integer obtained by converting the components of a four-component unsigned integer vector @@ -356,6 +366,16 @@ namespace glm /// @see uint32 packUnorm3x10_1x2(vec4 const & v) /// @see ivec4 unpackU3x10_1x2(uint32 const & p) GLM_FUNC_DECL uint32 packU3x10_1x2(uvec4 const & v); + + /// Unpacks a single 32-bit unsigned integer p into three 10-bit and one 2-bit unsigned integers. + /// + /// The first component of the returned vector will be extracted from the least significant bits of the input; + /// the last component will be extracted from the most significant bits. + /// + /// @see gtc_packing + /// @see uint32 packU3x10_1x2(uvec4 const & v) + /// @see vec4 unpackSnorm3x10_1x2(uint32 const & p); + /// @see uvec4 unpackI3x10_1x2(uint32 const & p); GLM_FUNC_DECL uvec4 unpackU3x10_1x2(uint32 const & p); /// First, converts the first three components of the normalized floating-point value v into 10-bit signed integer values. diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 0864e6b3..0dc4b996 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -438,6 +438,20 @@ namespace detail return detail::toFloat32(Packing.data); } + GLM_FUNC_DECL uint64 packHalf4x16(float const & v) + { + detail::half4x16 Packing; + Packing.data = detail::toFloat16(v); + return Packing.pack; + } + + GLM_FUNC_DECL float unpackHalf4x16(uint64 const & v) + { + detail::half4x16 Packing; + Packing.pack = v; + return detail::toFloat32(Packing.data); + } + GLM_FUNC_QUALIFIER uint32 packI3x10_1x2(ivec4 const & v) { detail::i10i10i10i2 Result; diff --git a/test/gtc/gtc_packing.cpp b/test/gtc/gtc_packing.cpp index cbbfa8e8..ca8fd8da 100644 --- a/test/gtc/gtc_packing.cpp +++ b/test/gtc/gtc_packing.cpp @@ -132,11 +132,89 @@ int test_half() return Error; } +int test_F2x11_1x10() +{ + int Error = 0; + + std::vector Tests; + Tests.push_back(glm::vec3(1.0)); + Tests.push_back(glm::vec3(0.0)); + Tests.push_back(glm::vec3(2.0)); + Tests.push_back(glm::vec3(0.1)); + Tests.push_back(glm::vec3(0.5)); + Tests.push_back(glm::vec3(0.9)); + + for(std::size_t i = 0; i < Tests.size(); ++i) + { + glm::uint32 p0 = glm::packF2x11_1x10(Tests[i]); + glm::vec3 v0 = glm::unpackF2x11_1x10(p0); + glm::uint32 p1 = glm::packF2x11_1x10(v0); + glm::vec3 v1 = glm::unpackF2x11_1x10(p0); + Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; + } + + return Error; +} + +int test_Snorm3x10_1x2() +{ + int Error = 0; + + std::vector Tests; + Tests.push_back(glm::vec4(1.0)); + Tests.push_back(glm::vec4(0.0)); + Tests.push_back(glm::vec4(2.0)); + Tests.push_back(glm::vec4(0.1)); + Tests.push_back(glm::vec4(0.5)); + Tests.push_back(glm::vec4(0.9)); + + for(std::size_t i = 0; i < Tests.size(); ++i) + { + glm::uint32 p0 = glm::packSnorm3x10_1x2(Tests[i]); + glm::vec3 v0 = glm::unpackSnorm3x10_1x2(p0); + glm::uint32 p1 = glm::packSnorm3x10_1x2(v0); + glm::vec3 v1 = glm::unpackSnorm3x10_1x2(p0); + Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; + } + + return Error; +} + +int test_Unorm3x10_1x2() +{ + int Error = 0; + + std::vector Tests; + Tests.push_back(glm::vec4(1.0)); + Tests.push_back(glm::vec4(0.0)); + Tests.push_back(glm::vec4(2.0)); + Tests.push_back(glm::vec4(0.1)); + Tests.push_back(glm::vec4(0.5)); + Tests.push_back(glm::vec4(0.9)); + + for(std::size_t i = 0; i < Tests.size(); ++i) + { + glm::uint32 p0 = glm::packSnorm3x10_1x2(Tests[i]); + glm::vec3 v0 = glm::unpackSnorm3x10_1x2(p0); + glm::uint32 p1 = glm::packSnorm3x10_1x2(v0); + glm::vec3 v1 = glm::unpackSnorm3x10_1x2(p0); + Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; + } + + return Error; +} + int main() { int Error(0); - Error += test_half(); + Error += test_F2x11_1x10(); + Error += test_Snorm3x10_1x2(); + Error += test_Unorm3x10_1x2(); + Error += test_I3x10_1x2(); + Error += test_U3x10_1x2(); + Error += test_Half1x16(); + Error += test_U3x10_1x2(); return Error; } From b1230f2adceaee0c3ceb92ff48bf4404f7390948 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 26 Aug 2013 11:14:46 +0200 Subject: [PATCH 15/15] Fixed build --- glm/gtc/packing.inl | 40 ++++++++---- test/gtc/gtc_packing.cpp | 129 ++++++++++++++++++++++++++++++++++----- 2 files changed, 142 insertions(+), 27 deletions(-) diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 0dc4b996..d67cad09 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -65,7 +65,7 @@ namespace detail ((f >> 17) & 0x003f); // Mantissa } - glm::uint32 packed11Tofloat(glm::uint32 const & p) + glm::uint32 packed11ToFloat(glm::uint32 const & p) { // 10 bits => EE EEEFFFFF // 11 bits => EEE EEFFFFFF @@ -80,7 +80,7 @@ namespace detail // 0x00008000 => 00000000 00000000 10000000 00000000 return ((((p & 0x07c0) << 17) + 0x38000000) & 0x7f800000) | // exponential - ((f & 0x003f) << 17); // Mantissa + ((p & 0x003f) << 17); // Mantissa } glm::uint32 float2packed10(glm::uint32 const & f) @@ -122,7 +122,7 @@ namespace detail // 0x00008000 => 00000000 00000000 10000000 00000000 return ((((p & 0x03E0) << 18) + 0x38000000) & 0x7f800000) | // exponential - ((f & 0x001f) << 18); // Mantissa + ((p & 0x001f) << 18); // Mantissa } glm::uint half2float(glm::uint const & h) @@ -257,7 +257,18 @@ namespace detail uint16 pack; }; - + union half4x16 + { + struct + { + hdata x; + hdata y; + hdata z; + hdata w; + } data; + uint64 pack; + }; + union unorm1x8 { uint8 data; @@ -438,18 +449,25 @@ namespace detail return detail::toFloat32(Packing.data); } - GLM_FUNC_DECL uint64 packHalf4x16(float const & v) + GLM_FUNC_DECL uint64 packHalf4x16(glm::vec4 const & v) { detail::half4x16 Packing; - Packing.data = detail::toFloat16(v); + Packing.data.x = detail::toFloat16(v.x); + Packing.data.y = detail::toFloat16(v.y); + Packing.data.z = detail::toFloat16(v.z); + Packing.data.w = detail::toFloat16(v.w); return Packing.pack; } - GLM_FUNC_DECL float unpackHalf4x16(uint64 const & v) + GLM_FUNC_DECL glm::vec4 unpackHalf4x16(uint64 const & v) { detail::half4x16 Packing; Packing.pack = v; - return detail::toFloat32(Packing.data); + return glm::vec4( + detail::toFloat32(Packing.data.x), + detail::toFloat32(Packing.data.y), + detail::toFloat32(Packing.data.z), + detail::toFloat32(Packing.data.w)); } GLM_FUNC_QUALIFIER uint32 packI3x10_1x2(ivec4 const & v) @@ -549,9 +567,9 @@ namespace detail GLM_FUNC_QUALIFIER vec3 unpackF2x11_1x10(uint32 const & v) { return vec3( - packed11bitToFloat(v >> 0), - packed11bitToFloat(v >> 11), - packed10bitToFloat(v >> 22)); + detail::packed11bitToFloat(v >> 0), + detail::packed11bitToFloat(v >> 11), + detail::packed10bitToFloat(v >> 22)); } }//namespace glm diff --git a/test/gtc/gtc_packing.cpp b/test/gtc/gtc_packing.cpp index ca8fd8da..b3d83739 100644 --- a/test/gtc/gtc_packing.cpp +++ b/test/gtc/gtc_packing.cpp @@ -29,6 +29,7 @@ #include #include #include +#include void print_bits(glm::half const & s) { @@ -132,24 +133,96 @@ int test_half() return Error; } -int test_F2x11_1x10() +int test_Half1x16() { int Error = 0; - std::vector Tests; - Tests.push_back(glm::vec3(1.0)); - Tests.push_back(glm::vec3(0.0)); - Tests.push_back(glm::vec3(2.0)); - Tests.push_back(glm::vec3(0.1)); - Tests.push_back(glm::vec3(0.5)); - Tests.push_back(glm::vec3(0.9)); + std::vector Tests; + Tests.push_back(0.0f); + Tests.push_back(1.0f); + Tests.push_back(-1.0f); + Tests.push_back(2.0f); + Tests.push_back(-2.0f); + Tests.push_back(1.9f); for(std::size_t i = 0; i < Tests.size(); ++i) { - glm::uint32 p0 = glm::packF2x11_1x10(Tests[i]); - glm::vec3 v0 = glm::unpackF2x11_1x10(p0); - glm::uint32 p1 = glm::packF2x11_1x10(v0); - glm::vec3 v1 = glm::unpackF2x11_1x10(p0); + glm::uint32 p0 = glm::packHalf1x16(Tests[i]); + float v0 = glm::unpackHalf1x16(p0); + glm::uint32 p1 = glm::packHalf1x16(v0); + float v1 = glm::unpackHalf1x16(p0); + Error += (v0 == v1) ? 0 : 1; + } + + return Error; +} + +int test_Half4x16() +{ + int Error = 0; + + std::vector Tests; + Tests.push_back(glm::vec4(1.0)); + Tests.push_back(glm::vec4(0.0)); + Tests.push_back(glm::vec4(2.0)); + Tests.push_back(glm::vec4(0.1)); + Tests.push_back(glm::vec4(0.5)); + Tests.push_back(glm::vec4(-0.9)); + + for(std::size_t i = 0; i < Tests.size(); ++i) + { + glm::uint64 p0 = glm::packHalf4x16(Tests[i]); + glm::vec4 v0 = glm::unpackHalf4x16(p0); + glm::uint64 p1 = glm::packHalf4x16(v0); + glm::vec4 v1 = glm::unpackHalf4x16(p0); + Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; + } + + return Error; +} + +int test_I3x10_1x2() +{ + int Error = 0; + + std::vector Tests; + Tests.push_back(glm::ivec4(0)); + Tests.push_back(glm::ivec4(1)); + Tests.push_back(glm::ivec4(-1)); + Tests.push_back(glm::ivec4(2)); + Tests.push_back(glm::ivec4(-2)); + Tests.push_back(glm::ivec4(3)); + + for(std::size_t i = 0; i < Tests.size(); ++i) + { + glm::uint32 p0 = glm::packI3x10_1x2(Tests[i]); + glm::ivec4 v0 = glm::unpackI3x10_1x2(p0); + glm::uint32 p1 = glm::packI3x10_1x2(v0); + glm::ivec4 v1 = glm::unpackI3x10_1x2(p0); + Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; + } + + return Error; +} + +int test_U3x10_1x2() +{ + int Error = 0; + + std::vector Tests; + Tests.push_back(glm::uvec4(0)); + Tests.push_back(glm::uvec4(1)); + Tests.push_back(glm::uvec4(2)); + Tests.push_back(glm::uvec4(3)); + Tests.push_back(glm::uvec4(4)); + Tests.push_back(glm::uvec4(5)); + + for(std::size_t i = 0; i < Tests.size(); ++i) + { + glm::uint32 p0 = glm::packU3x10_1x2(Tests[i]); + glm::uvec4 v0 = glm::unpackU3x10_1x2(p0); + glm::uint32 p1 = glm::packU3x10_1x2(v0); + glm::uvec4 v1 = glm::unpackU3x10_1x2(p0); Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; } @@ -171,9 +244,9 @@ int test_Snorm3x10_1x2() for(std::size_t i = 0; i < Tests.size(); ++i) { glm::uint32 p0 = glm::packSnorm3x10_1x2(Tests[i]); - glm::vec3 v0 = glm::unpackSnorm3x10_1x2(p0); + glm::vec4 v0 = glm::unpackSnorm3x10_1x2(p0); glm::uint32 p1 = glm::packSnorm3x10_1x2(v0); - glm::vec3 v1 = glm::unpackSnorm3x10_1x2(p0); + glm::vec4 v1 = glm::unpackSnorm3x10_1x2(p0); Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; } @@ -195,9 +268,33 @@ int test_Unorm3x10_1x2() for(std::size_t i = 0; i < Tests.size(); ++i) { glm::uint32 p0 = glm::packSnorm3x10_1x2(Tests[i]); - glm::vec3 v0 = glm::unpackSnorm3x10_1x2(p0); + glm::vec4 v0 = glm::unpackSnorm3x10_1x2(p0); glm::uint32 p1 = glm::packSnorm3x10_1x2(v0); - glm::vec3 v1 = glm::unpackSnorm3x10_1x2(p0); + glm::vec4 v1 = glm::unpackSnorm3x10_1x2(p0); + Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; + } + + return Error; +} + +int test_F2x11_1x10() +{ + int Error = 0; + + std::vector Tests; + Tests.push_back(glm::vec3(1.0)); + Tests.push_back(glm::vec3(0.0)); + Tests.push_back(glm::vec3(2.0)); + Tests.push_back(glm::vec3(0.1)); + Tests.push_back(glm::vec3(0.5)); + Tests.push_back(glm::vec3(0.9)); + + for(std::size_t i = 0; i < Tests.size(); ++i) + { + glm::uint32 p0 = glm::packF2x11_1x10(Tests[i]); + glm::vec3 v0 = glm::unpackF2x11_1x10(p0); + glm::uint32 p1 = glm::packF2x11_1x10(v0); + glm::vec3 v1 = glm::unpackF2x11_1x10(p0); Error += glm::all(glm::equal(v0, v1)) ? 0 : 1; }