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; }