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 15a2b3e7..9433d54e 100644 --- a/glm/gtc/packing.hpp +++ b/glm/gtc/packing.hpp @@ -51,60 +51,423 @@ namespace glm /// @addtogroup gtc_packing /// @{ - GLM_FUNC_DECL uint16 packUnorm1x16(float v); - GLM_FUNC_DECL float unpackUnorm1x16(uint16 v); + /// 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 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); - 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); - - 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. + /// 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 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. + /// + /// 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 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); + + /// 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. + /// + /// 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); + + /// 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. + /// 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 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); + + /// 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. + /// 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 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 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); + + /// 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 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 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); + + /// 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 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); + + /// 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. + /// 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 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); + + /// 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 + /// 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 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); + + /// 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 four 16-bit values into a 64-bit unsigned integer. + /// The first vector component specifies the 16 least-significant bits of the result; + /// the forth component specifies the 16 most-significant bits. + /// + /// @see gtc_packing + /// @see 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 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); + 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_1x2(uvec4 const & v) + /// @see uint32 packSnorm3x10_1x2(vec4 const & v) + /// @see uint32 packUnorm3x10_1x2(vec4 const & v) + /// @see ivec4 unpackI3x10_1x2(uint32 const & p) + GLM_FUNC_DECL uint32 packI3x10_1x2(ivec4 const & v); - GLM_FUNC_DECL uint32 packU10U10U10U2(uvec4 const & v); - GLM_FUNC_DECL uvec4 unpackU10U10U10U2(uint32 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 + /// 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_1x2(ivec4 const & v) + /// @see uint32 packSnorm3x10_1x2(vec4 const & v) + /// @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. + /// 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_1x2(uvec4 const & v) + /// @see uint32 packI3x10_1x2(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_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. + /// 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_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. + /// 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_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. + /// 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_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. + /// + /// 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_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 9b078dad..d67cad09 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) @@ -48,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 @@ -62,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 + ((p & 0x003f) << 17); // Mantissa + } + + glm::uint32 float2packed10(glm::uint32 const & f) { // 10 bits => EE EEEFFFFF // 11 bits => EEE EEFFFFFF @@ -83,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 + ((p & 0x001f) << 18); // Mantissa + } + glm::uint half2float(glm::uint const & h) { return ((h & 0x8000) << 16) | ((( h & 0x7c00) + 0x1C000) << 13) | ((h & 0x03FF) << 13); @@ -112,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) @@ -125,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) { @@ -191,6 +257,24 @@ namespace detail uint16 pack; }; + union half4x16 + { + struct + { + hdata x; + hdata y; + hdata z; + hdata w; + } data; + uint64 pack; + }; + + union unorm1x8 + { + uint8 data; + uint8 pack; + }; + union unorm2x8 { struct @@ -201,6 +285,12 @@ namespace detail uint16 pack; }; + union snorm1x8 + { + int8 data; + uint8 pack; + }; + union snorm2x8 { struct @@ -212,6 +302,72 @@ 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.data = Scaled; + 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)); @@ -242,6 +398,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) @@ -278,40 +435,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; @@ -326,7 +449,28 @@ namespace detail return detail::toFloat32(Packing.data); } - GLM_FUNC_QUALIFIER uint32 packI10I10I10I2(ivec4 const & v) + GLM_FUNC_DECL uint64 packHalf4x16(glm::vec4 const & v) + { + detail::half4x16 Packing; + 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 glm::vec4 unpackHalf4x16(uint64 const & v) + { + detail::half4x16 Packing; + Packing.pack = v; + 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) { detail::i10i10i10i2 Result; Result.data.x = v.x; @@ -336,7 +480,7 @@ namespace detail return Result.pack; } - GLM_FUNC_QUALIFIER ivec4 unpackI10I10I10I2(uint32 const & v) + GLM_FUNC_QUALIFIER ivec4 unpackI3x10_1x2(uint32 const & v) { detail::i10i10i10i2 Unpack; Unpack.pack = v; @@ -347,7 +491,7 @@ namespace detail Unpack.data.w); } - GLM_FUNC_QUALIFIER uint32 packU10U10U10U2(uvec4 const & v) + GLM_FUNC_QUALIFIER uint32 packU3x10_1x2(uvec4 const & v) { detail::u10u10u10u2 Result; Result.data.x = v.x; @@ -357,7 +501,7 @@ namespace detail return Result.pack; } - GLM_FUNC_QUALIFIER uvec4 unpackU10U10U10U2(uint32 const & v) + GLM_FUNC_QUALIFIER uvec4 unpackU3x10_1x2(uint32 const & v) { detail::u10u10u10u2 Unpack; Unpack.pack = v; @@ -371,10 +515,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; } @@ -383,14 +527,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) | @@ -398,9 +564,12 @@ 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) { - + return vec3( + detail::packed11bitToFloat(v >> 0), + detail::packed11bitToFloat(v >> 11), + detail::packed10bitToFloat(v >> 22)); } }//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,22 +286,11 @@ 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) + 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 - ) - { - return &(q[0]); - } //! Return the constant address to the data of the input parameter. /// @see gtc_type_ptr @@ -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..b3d83739 100644 --- a/test/gtc/gtc_packing.cpp +++ b/test/gtc/gtc_packing.cpp @@ -26,10 +26,10 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// - #include #include #include +#include void print_bits(glm::half const & s) { @@ -133,11 +133,185 @@ int test_half() return Error; } +int test_Half1x16() +{ + int Error = 0; + + 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::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; + } + + 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::vec4 v0 = glm::unpackSnorm3x10_1x2(p0); + glm::uint32 p1 = glm::packSnorm3x10_1x2(v0); + glm::vec4 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::vec4 v0 = glm::unpackSnorm3x10_1x2(p0); + glm::uint32 p1 = glm::packSnorm3x10_1x2(v0); + 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; + } + + 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; }