diff --git a/glm/gtc/packing.hpp b/glm/gtc/packing.hpp index 59595648..d34370a5 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -518,7 +518,7 @@ namespace glm template GLM_FUNC_DECL vec packUnorm(vec const & v); - /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// Convert a packed integer to a normalized floating-point vector. /// /// @see gtc_packing /// @see vecType packUnorm(vecType const & v) @@ -532,7 +532,7 @@ namespace glm template GLM_FUNC_DECL vec packSnorm(vec const & v); - /// Convert each signed integer components of a vector to normalized floating-point values. + /// Convert a packed integer to a normalized floating-point vector. /// /// @see gtc_packing /// @see vecType packSnorm(vecType const & v) @@ -545,7 +545,7 @@ namespace glm /// @see vec2 unpackUnorm2x4(uint8 p) GLM_FUNC_DECL uint8 packUnorm2x4(vec2 const & v); - /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// Convert a packed integer to a normalized floating-point vector. /// /// @see gtc_packing /// @see uint8 packUnorm2x4(vec2 const & v) @@ -557,7 +557,7 @@ namespace glm /// @see vec4 unpackUnorm4x4(uint16 p) GLM_FUNC_DECL uint16 packUnorm4x4(vec4 const & v); - /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// Convert a packed integer to a normalized floating-point vector. /// /// @see gtc_packing /// @see uint16 packUnorm4x4(vec4 const & v) @@ -569,7 +569,7 @@ namespace glm /// @see vec3 unpackUnorm1x5_1x6_1x5(uint16 p) GLM_FUNC_DECL uint16 packUnorm1x5_1x6_1x5(vec3 const & v); - /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// Convert a packed integer to a normalized floating-point vector. /// /// @see gtc_packing /// @see uint16 packUnorm1x5_1x6_1x5(vec3 const & v) @@ -581,7 +581,7 @@ namespace glm /// @see vec4 unpackUnorm3x5_1x1(uint16 p) GLM_FUNC_DECL uint16 packUnorm3x5_1x1(vec4 const & v); - /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// Convert a packed integer to a normalized floating-point vector. /// /// @see gtc_packing /// @see uint16 packUnorm3x5_1x1(vec4 const & v) @@ -593,11 +593,135 @@ namespace glm /// @see vec3 unpackUnorm2x3_1x2(uint8 p) GLM_FUNC_DECL uint8 packUnorm2x3_1x2(vec3 const & v); - /// Convert each unsigned integer components of a vector to normalized floating-point values. + /// Convert a packed integer to a normalized floating-point vector. /// /// @see gtc_packing /// @see uint8 packUnorm2x3_1x2(vec3 const & v) GLM_FUNC_DECL vec3 unpackUnorm2x3_1x2(uint8 p); + + + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see i8vec2 unpackInt2x8(int16 p) + GLM_FUNC_DECL int16 packInt2x8(i8vec2 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see int16 packInt2x8(i8vec2 const& v) + GLM_FUNC_DECL i8vec2 unpackInt2x8(int16 p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see u8vec2 unpackInt2x8(uint16 p) + GLM_FUNC_DECL uint16 packUint2x8(u8vec2 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see uint16 packInt2x8(u8vec2 const& v) + GLM_FUNC_DECL u8vec2 unpackUint2x8(uint16 p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see i8vec4 unpackInt4x8(int32 p) + GLM_FUNC_DECL int32 packInt4x8(i8vec4 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see int32 packInt2x8(i8vec4 const& v) + GLM_FUNC_DECL i8vec4 unpackInt4x8(int32 p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see u8vec4 unpackUint4x8(uint32 p) + GLM_FUNC_DECL uint32 packUint4x8(u8vec4 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see uint32 packUint4x8(u8vec2 const& v) + GLM_FUNC_DECL u8vec4 unpackUint4x8(uint32 p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see i16vec2 unpackInt2x16(int p) + GLM_FUNC_DECL int packInt2x16(i16vec2 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see int packInt2x16(i16vec2 const& v) + GLM_FUNC_DECL i16vec2 unpackInt2x16(int p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see i16vec4 unpackInt4x16(int64 p) + GLM_FUNC_DECL int64 packInt4x16(i16vec4 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see int64 packInt4x16(i16vec4 const& v) + GLM_FUNC_DECL i16vec4 unpackInt4x16(int64 p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see u16vec2 unpackUint2x16(uint p) + GLM_FUNC_DECL uint packUint2x16(u16vec2 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see uint packUint2x16(u16vec2 const& v) + GLM_FUNC_DECL u16vec2 unpackUint2x16(uint p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see u16vec4 unpackUint4x16(uint64 p) + GLM_FUNC_DECL uint64 packUint4x16(u16vec4 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see uint64 packUint4x16(u16vec4 const& v) + GLM_FUNC_DECL u16vec4 unpackUint4x16(uint64 p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see i32vec2 unpackInt2x32(int p) + GLM_FUNC_DECL int64 packInt2x32(i32vec2 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see int packInt2x16(i32vec2 const& v) + GLM_FUNC_DECL i32vec2 unpackInt2x32(int64 p); + + /// Convert each component from an integer vector into a packed unsigned integer. + /// + /// @see gtc_packing + /// @see u32vec2 unpackUint2x32(int p) + GLM_FUNC_DECL uint64 packUint2x32(u32vec2 const& v); + + /// Convert a packed integer into an integer vector. + /// + /// @see gtc_packing + /// @see int packUint2x16(u32vec2 const& v) + GLM_FUNC_DECL u32vec2 unpackUint2x32(uint64 p); + + /// @} }// namespace glm diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 7333ef86..0af0005d 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -793,5 +793,145 @@ namespace detail Unpack.pack = v; return vec3(Unpack.data.x, Unpack.data.y, Unpack.data.z) * ScaleFactor; } + + GLM_FUNC_QUALIFIER int16 packInt2x8(i8vec2 const& v) + { + int16 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER i8vec2 unpackInt2x8(int16 p) + { + i8vec2 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER uint16 packUint2x8(u8vec2 const& v) + { + uint16 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER u8vec2 unpackUint2x8(uint16 p) + { + u8vec2 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER int32 packInt4x8(i8vec4 const& v) + { + int32 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER i8vec4 unpackInt4x8(int32 p) + { + i8vec4 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER uint32 packUint4x8(u8vec4 const& v) + { + uint32 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER u8vec4 unpackUint4x8(uint32 p) + { + u8vec4 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER int packInt2x16(i16vec2 const& v) + { + int Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER i16vec2 unpackInt2x16(int p) + { + i16vec2 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER int64 packInt4x16(i16vec4 const& v) + { + int64 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER i16vec4 unpackInt4x16(int64 p) + { + i16vec4 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER uint packUint2x16(u16vec2 const& v) + { + uint Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER u16vec2 unpackUint2x16(uint p) + { + u16vec2 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER uint64 packUint4x16(u16vec4 const& v) + { + uint64 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER u16vec4 unpackUint4x16(uint64 p) + { + u16vec4 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER int64 packInt2x32(i32vec2 const& v) + { + int64 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER i32vec2 unpackInt2x32(int64 p) + { + i32vec2 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } + + GLM_FUNC_QUALIFIER uint64 packUint2x32(u32vec2 const& v) + { + uint64 Pack = 0; + memcpy(&Pack, &v, sizeof(Pack)); + return Pack; + } + + GLM_FUNC_QUALIFIER u32vec2 unpackUint2x32(uint64 p) + { + u32vec2 Unpack(uninitialize); + memcpy(&Unpack, &p, sizeof(Unpack)); + return Unpack; + } }//namespace glm diff --git a/readme.md b/readme.md index f49f2fd2..8fe751c5 100644 --- a/readme.md +++ b/readme.md @@ -58,6 +58,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - Added GTX_vec_swizzle, faster compile time swizzling then swizzle operator #558 - Added GTX_exterior_product with a vec2 cross implementation #621 - Added [GLM_ENABLE_EXPERIMENTAL](manual.md#section7_4) to enable experimental features. +- Added packing functions for integer vectors #639 #### Improvements: - Added lowp variant of GTC_color_space convertLinearToSRGB #419 diff --git a/test/gtc/gtc_packing.cpp b/test/gtc/gtc_packing.cpp index 205f90cf..a5593fd5 100644 --- a/test/gtc/gtc_packing.cpp +++ b/test/gtc/gtc_packing.cpp @@ -670,6 +670,156 @@ int test_packUnorm2x3_1x2() return Error; } +int test_packUint2x8() +{ + int Error = 0; + + glm::u8vec2 const Source(1, 2); + + glm::uint16 const Packed = glm::packUint2x8(Source); + Error += Packed != 0 ? 0 : 1; + + glm::u8vec2 const Unpacked = glm::unpackUint2x8(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packUint4x8() +{ + int Error = 0; + + glm::u8vec4 const Source(1, 2, 3, 4); + + glm::uint32 const Packed = glm::packUint4x8(Source); + Error += Packed != 0 ? 0 : 1; + + glm::u8vec4 const Unpacked = glm::unpackUint4x8(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packUint2x16() +{ + int Error = 0; + + glm::u16vec2 const Source(1, 2); + + glm::uint32 const Packed = glm::packUint2x16(Source); + Error += Packed != 0 ? 0 : 1; + + glm::u16vec2 const Unpacked = glm::unpackUint2x16(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packUint4x16() +{ + int Error = 0; + + glm::u16vec4 const Source(1, 2, 3, 4); + + glm::uint64 const Packed = glm::packUint4x16(Source); + Error += Packed != 0 ? 0 : 1; + + glm::u16vec4 const Unpacked = glm::unpackUint4x16(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packUint2x32() +{ + int Error = 0; + + glm::u32vec2 const Source(1, 2); + + glm::uint64 const Packed = glm::packUint2x32(Source); + Error += Packed != 0 ? 0 : 1; + + glm::u32vec2 const Unpacked = glm::unpackUint2x32(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packInt2x8() +{ + int Error = 0; + + glm::i8vec2 const Source(1, 2); + + glm::int16 const Packed = glm::packInt2x8(Source); + Error += Packed != 0 ? 0 : 1; + + glm::i8vec2 const Unpacked = glm::unpackInt2x8(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packInt4x8() +{ + int Error = 0; + + glm::i8vec4 const Source(1, 2, 3, 4); + + glm::int32 const Packed = glm::packInt4x8(Source); + Error += Packed != 0 ? 0 : 1; + + glm::i8vec4 const Unpacked = glm::unpackInt4x8(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packInt2x16() +{ + int Error = 0; + + glm::i16vec2 const Source(1, 2); + + glm::int32 const Packed = glm::packInt2x16(Source); + Error += Packed != 0 ? 0 : 1; + + glm::i16vec2 const Unpacked = glm::unpackInt2x16(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packInt4x16() +{ + int Error = 0; + + glm::i16vec4 const Source(1, 2, 3, 4); + + glm::int64 const Packed = glm::packInt4x16(Source); + Error += Packed != 0 ? 0 : 1; + + glm::i16vec4 const Unpacked = glm::unpackInt4x16(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + +int test_packInt2x32() +{ + int Error = 0; + + glm::i32vec2 const Source(1, 2); + + glm::int64 const Packed = glm::packInt2x32(Source); + Error += Packed != 0 ? 0 : 1; + + glm::i32vec2 const Unpacked = glm::unpackInt2x32(Packed); + Error += Source == Unpacked ? 0 : 1; + + return Error; +} + int main() { int Error = 0; @@ -699,6 +849,18 @@ int main() Error += test_packUnorm1x5_1x6_1x5(); Error += test_packUnorm2x3_1x2(); + Error += test_packUint2x8(); + Error += test_packUint4x8(); + Error += test_packUint2x16(); + Error += test_packUint4x16(); + Error += test_packUint2x32(); + + Error += test_packInt2x8(); + Error += test_packInt4x8(); + Error += test_packInt2x16(); + Error += test_packInt4x16(); + Error += test_packInt2x32(); + Error += test_F2x11_1x10(); Error += test_F3x9_E1x5(); Error += test_RGBM();