mirror of
https://github.com/g-truc/glm.git
synced 2024-11-29 19:34:36 +00:00
Added EXT_vector/scalar_packing
This commit is contained in:
parent
84dfcc5295
commit
47b9ad7f08
47
glm/ext/scalar_packing.hpp
Normal file
47
glm/ext/scalar_packing.hpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/// @ref ext_scalar_packing
|
||||||
|
/// @file glm/ext/scalar_packing.hpp
|
||||||
|
///
|
||||||
|
/// @defgroup ext_scalar_packing GLM_EXT_scalar_packing
|
||||||
|
/// @ingroup ext
|
||||||
|
///
|
||||||
|
/// Exposes comparison functions for scalar types that take a user defined epsilon values.
|
||||||
|
///
|
||||||
|
/// Include <glm/ext/scalar_packing.hpp> to use the features of this extension.
|
||||||
|
///
|
||||||
|
/// @see core_packing
|
||||||
|
/// @see ext_vector_packing
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Dependencies
|
||||||
|
#include "../detail/qualifier.hpp"
|
||||||
|
#include "../ext/scalar_uint_sized.hpp"
|
||||||
|
|
||||||
|
#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
|
||||||
|
# pragma message("GLM: GLM_EXT_scalar_packing extension included")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace glm
|
||||||
|
{
|
||||||
|
/// @addtogroup ext_scalar_packing
|
||||||
|
/// @{
|
||||||
|
|
||||||
|
/// Returns an unsigned integer scalar obtained by converting the components of a floating-point scalar
|
||||||
|
/// to the 16-bit floating-point representation found in the OpenGL Specification.
|
||||||
|
/// The first vector component specifies the 16 least-significant bits of the result;
|
||||||
|
/// the forth component specifies the 16 most-significant bits.
|
||||||
|
///
|
||||||
|
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
|
||||||
|
GLM_FUNC_DECL uint16 packHalf(float s);
|
||||||
|
|
||||||
|
/// Returns a floating-point scalar with components obtained by reinterpreting an integer scalar as 16-bit floating-point numbers and converting them to 32-bit floating-point values.
|
||||||
|
/// The first component of the vector is obtained from the 16 least-significant bits of v;
|
||||||
|
/// the forth component is obtained from the 16 most-significant bits of v.
|
||||||
|
///
|
||||||
|
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
|
||||||
|
GLM_FUNC_DECL float unpackHalf(uint16 p);
|
||||||
|
|
||||||
|
/// @}
|
||||||
|
}//namespace glm
|
||||||
|
|
||||||
|
#include "scalar_packing.inl"
|
14
glm/ext/scalar_packing.inl
Normal file
14
glm/ext/scalar_packing.inl
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include "../detail/type_half.hpp"
|
||||||
|
|
||||||
|
namespace glm
|
||||||
|
{
|
||||||
|
GLM_FUNC_QUALIFIER uint16 packHalf(float Scalar)
|
||||||
|
{
|
||||||
|
return detail::toFloat16(Scalar);
|
||||||
|
}
|
||||||
|
|
||||||
|
GLM_FUNC_QUALIFIER float unpackHalf(uint16 Packed)
|
||||||
|
{
|
||||||
|
return detail::toFloat32(Packed);
|
||||||
|
}
|
||||||
|
}//namespace glm
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
// Dependencies
|
// Dependencies
|
||||||
#include "../detail/qualifier.hpp"
|
#include "../detail/qualifier.hpp"
|
||||||
|
#include "../ext/scalar_uint_sized.hpp"
|
||||||
|
#include "../ext/scalar_int_sized.hpp"
|
||||||
|
|
||||||
#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
|
#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
|
||||||
# pragma message("GLM: GLM_EXT_vector_packing extension included")
|
# pragma message("GLM: GLM_EXT_vector_packing extension included")
|
||||||
@ -24,6 +26,25 @@ namespace glm
|
|||||||
/// @addtogroup ext_vector_packing
|
/// @addtogroup ext_vector_packing
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
/// Returns an unsigned integer vector obtained by converting the components of a floating-point vector
|
||||||
|
/// to the 16-bit floating-point representation found in the OpenGL Specification.
|
||||||
|
/// The first vector component specifies the 16 least-significant bits of the result;
|
||||||
|
/// the forth component specifies the 16 most-significant bits.
|
||||||
|
///
|
||||||
|
/// @see vec<L, float, Q> unpackHalf(vec<L, uint16, Q> const& p)
|
||||||
|
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
|
||||||
|
template<length_t L, qualifier Q>
|
||||||
|
GLM_FUNC_DECL vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v);
|
||||||
|
|
||||||
|
/// Returns a floating-point vector with components obtained by reinterpreting an integer vector as 16-bit floating-point numbers and converting them to 32-bit floating-point values.
|
||||||
|
/// The first component of the vector is obtained from the 16 least-significant bits of v;
|
||||||
|
/// the forth component is obtained from the 16 most-significant bits of v.
|
||||||
|
///
|
||||||
|
/// @see vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v)
|
||||||
|
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
|
||||||
|
template<length_t L, qualifier Q>
|
||||||
|
GLM_FUNC_DECL vec<L, float, Q> unpackHalf(vec<L, uint16, Q> const& p);
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
}//namespace glm
|
}//namespace glm
|
||||||
|
|
||||||
|
@ -1,5 +1,98 @@
|
|||||||
namespace glm
|
#include "../detail/type_half.hpp"
|
||||||
|
|
||||||
|
namespace glm{
|
||||||
|
namespace detail
|
||||||
{
|
{
|
||||||
|
template<length_t L, qualifier Q>
|
||||||
|
struct compute_half
|
||||||
|
{};
|
||||||
|
|
||||||
|
template<qualifier Q>
|
||||||
|
struct compute_half<1, Q>
|
||||||
|
{
|
||||||
|
GLM_FUNC_QUALIFIER static vec<1, uint16, Q> pack(vec<1, float, Q> const& v)
|
||||||
|
{
|
||||||
|
int16 const Unpack(detail::toFloat16(v.x));
|
||||||
|
vec<1, uint16, Q> Packed;
|
||||||
|
memcpy(&Packed, &Unpack, sizeof(Packed));
|
||||||
|
return Packed;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLM_FUNC_QUALIFIER static vec<1, float, Q> unpack(vec<1, uint16, Q> const& v)
|
||||||
|
{
|
||||||
|
vec<1, int16, Q> Unpack;
|
||||||
|
memcpy(&Unpack, &v, sizeof(Unpack));
|
||||||
|
return vec<1, float, Q>(detail::toFloat32(v.x));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<qualifier Q>
|
||||||
|
struct compute_half<2, Q>
|
||||||
|
{
|
||||||
|
GLM_FUNC_QUALIFIER static vec<2, uint16, Q> pack(vec<2, float, Q> const& v)
|
||||||
|
{
|
||||||
|
vec<2, int16, Q> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y));
|
||||||
|
vec<2, uint16, Q> Packed;
|
||||||
|
memcpy(&Packed, &Unpack, sizeof(Packed));
|
||||||
|
return Packed;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLM_FUNC_QUALIFIER static vec<2, float, Q> unpack(vec<2, uint16, Q> const& v)
|
||||||
|
{
|
||||||
|
vec<2, int16, Q> Unpack;
|
||||||
|
memcpy(&Unpack, &v, sizeof(Unpack));
|
||||||
|
return vec<2, float, Q>(detail::toFloat32(v.x), detail::toFloat32(v.y));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<qualifier Q>
|
||||||
|
struct compute_half<3, Q>
|
||||||
|
{
|
||||||
|
GLM_FUNC_QUALIFIER static vec<3, uint16, Q> pack(vec<3, float, Q> const& v)
|
||||||
|
{
|
||||||
|
vec<3, int16, Q> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z));
|
||||||
|
vec<3, uint16, Q> Packed;
|
||||||
|
memcpy(&Packed, &Unpack, sizeof(Packed));
|
||||||
|
return Packed;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLM_FUNC_QUALIFIER static vec<3, float, Q> unpack(vec<3, uint16, Q> const& v)
|
||||||
|
{
|
||||||
|
vec<3, int16, Q> Unpack;
|
||||||
|
memcpy(&Unpack, &v, sizeof(Unpack));
|
||||||
|
return vec<3, float, Q>(detail::toFloat32(v.x), detail::toFloat32(v.y), detail::toFloat32(v.z));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<qualifier Q>
|
||||||
|
struct compute_half<4, Q>
|
||||||
|
{
|
||||||
|
GLM_FUNC_QUALIFIER static vec<4, uint16, Q> pack(vec<4, float, Q> const& v)
|
||||||
|
{
|
||||||
|
vec<4, int16, Q> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z), detail::toFloat16(v.w));
|
||||||
|
vec<4, uint16, Q> Packed;
|
||||||
|
memcpy(&Packed, &Unpack, sizeof(Packed));
|
||||||
|
return Packed;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLM_FUNC_QUALIFIER static vec<4, float, Q> unpack(vec<4, uint16, Q> const& v)
|
||||||
|
{
|
||||||
|
vec<4, int16, Q> Unpack;
|
||||||
|
memcpy(&Unpack, &v, sizeof(Unpack));
|
||||||
|
return vec<4, float, Q>(detail::toFloat32(v.x), detail::toFloat32(v.y), detail::toFloat32(v.z), detail::toFloat32(v.w));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}//namespace detail
|
||||||
|
|
||||||
|
template<length_t L, qualifier Q>
|
||||||
|
GLM_FUNC_QUALIFIER vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v)
|
||||||
|
{
|
||||||
|
return detail::compute_half<L, Q>::pack(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<length_t L, qualifier Q>
|
||||||
|
GLM_FUNC_QUALIFIER vec<L, float, Q> unpackHalf(vec<L, uint16, Q> const& v)
|
||||||
|
{
|
||||||
|
return detail::compute_half<L, Q>::unpack(v);
|
||||||
|
}
|
||||||
}//namespace glm
|
}//namespace glm
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// Dependency:
|
// Dependency:
|
||||||
#include "type_precision.hpp"
|
#include "../gtc/type_precision.hpp"
|
||||||
|
#include "../ext/scalar_packing.hpp"
|
||||||
|
#include "../ext/vector_packing.hpp"
|
||||||
|
|
||||||
#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
|
#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
|
||||||
# pragma message("GLM: GLM_GTC_packing extension included")
|
# pragma message("GLM: GLM_GTC_packing extension included")
|
||||||
@ -265,7 +267,7 @@ namespace glm
|
|||||||
/// @see uint64 packHalf4x16(vec4 const& v)
|
/// @see uint64 packHalf4x16(vec4 const& v)
|
||||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packHalf2x16.xml">GLSL packHalf2x16 man page</a>
|
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packHalf2x16.xml">GLSL packHalf2x16 man page</a>
|
||||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
|
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
|
||||||
GLM_FUNC_DECL uint16 packHalf1x16(float v);
|
GLM_FUNC_DECL uint16 packHalf1x16(vec1 v);
|
||||||
|
|
||||||
/// Returns a floating-point scalar with components obtained by unpacking a 16-bit unsigned integer into a 16-bit value,
|
/// 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,
|
/// interpreted as a 16-bit floating-point number according to the OpenGL Specification,
|
||||||
@ -276,7 +278,7 @@ namespace glm
|
|||||||
/// @see vec4 unpackHalf4x16(uint64 const& v)
|
/// @see vec4 unpackHalf4x16(uint64 const& v)
|
||||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackHalf2x16.xml">GLSL unpackHalf2x16 man page</a>
|
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackHalf2x16.xml">GLSL unpackHalf2x16 man page</a>
|
||||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
|
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
|
||||||
GLM_FUNC_DECL float unpackHalf1x16(uint16 v);
|
GLM_FUNC_DECL vec1 unpackHalf1x16(uint16 v);
|
||||||
|
|
||||||
/// Returns an unsigned integer obtained by converting the components of a four-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,
|
/// to the 16-bit floating-point representation found in the OpenGL Specification,
|
||||||
@ -490,27 +492,6 @@ namespace glm
|
|||||||
template<length_t L, typename T, qualifier Q>
|
template<length_t L, typename T, qualifier Q>
|
||||||
GLM_FUNC_DECL vec<3, T, Q> unpackRGBM(vec<4, T, Q> const& rgbm);
|
GLM_FUNC_DECL vec<3, T, Q> unpackRGBM(vec<4, T, Q> const& rgbm);
|
||||||
|
|
||||||
/// Returns an unsigned integer vector obtained by converting the components of a floating-point vector
|
|
||||||
/// to the 16-bit floating-point representation found in the OpenGL Specification.
|
|
||||||
/// The first vector component specifies the 16 least-significant bits of the result;
|
|
||||||
/// the forth component specifies the 16 most-significant bits.
|
|
||||||
///
|
|
||||||
/// @see gtc_packing
|
|
||||||
/// @see vec<L, float, Q> unpackHalf(vec<L, uint16, Q> const& p)
|
|
||||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
|
|
||||||
template<length_t L, qualifier Q>
|
|
||||||
GLM_FUNC_DECL vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v);
|
|
||||||
|
|
||||||
/// Returns a floating-point vector with components obtained by reinterpreting an integer vector as 16-bit floating-point numbers and converting them to 32-bit floating-point values.
|
|
||||||
/// The first component of the vector is obtained from the 16 least-significant bits of v;
|
|
||||||
/// the forth component is obtained from the 16 most-significant bits of v.
|
|
||||||
///
|
|
||||||
/// @see gtc_packing
|
|
||||||
/// @see vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v)
|
|
||||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
|
|
||||||
template<length_t L, qualifier Q>
|
|
||||||
GLM_FUNC_DECL vec<L, float, Q> unpackHalf(vec<L, uint16, Q> const& p);
|
|
||||||
|
|
||||||
/// Convert each component of the normalized floating-point vector into unsigned integer values.
|
/// Convert each component of the normalized floating-point vector into unsigned integer values.
|
||||||
///
|
///
|
||||||
/// @see gtc_packing
|
/// @see gtc_packing
|
||||||
@ -721,7 +702,6 @@ namespace glm
|
|||||||
/// @see int packUint2x16(u32vec2 const& v)
|
/// @see int packUint2x16(u32vec2 const& v)
|
||||||
GLM_FUNC_DECL u32vec2 unpackUint2x32(uint64 p);
|
GLM_FUNC_DECL u32vec2 unpackUint2x32(uint64 p);
|
||||||
|
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
}// namespace glm
|
}// namespace glm
|
||||||
|
|
||||||
|
@ -270,86 +270,6 @@ namespace detail
|
|||||||
} data;
|
} data;
|
||||||
uint32 pack;
|
uint32 pack;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<length_t L, qualifier Q>
|
|
||||||
struct compute_half
|
|
||||||
{};
|
|
||||||
|
|
||||||
template<qualifier Q>
|
|
||||||
struct compute_half<1, Q>
|
|
||||||
{
|
|
||||||
GLM_FUNC_QUALIFIER static vec<1, uint16, Q> pack(vec<1, float, Q> const& v)
|
|
||||||
{
|
|
||||||
int16 const Unpack(detail::toFloat16(v.x));
|
|
||||||
u16vec1 Packed;
|
|
||||||
memcpy(&Packed, &Unpack, sizeof(Packed));
|
|
||||||
return Packed;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER static vec<1, float, Q> unpack(vec<1, uint16, Q> const& v)
|
|
||||||
{
|
|
||||||
i16vec1 Unpack;
|
|
||||||
memcpy(&Unpack, &v, sizeof(Unpack));
|
|
||||||
return vec<1, float, Q>(detail::toFloat32(v.x));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<qualifier Q>
|
|
||||||
struct compute_half<2, Q>
|
|
||||||
{
|
|
||||||
GLM_FUNC_QUALIFIER static vec<2, uint16, Q> pack(vec<2, float, Q> const& v)
|
|
||||||
{
|
|
||||||
vec<2, int16, Q> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y));
|
|
||||||
u16vec2 Packed;
|
|
||||||
memcpy(&Packed, &Unpack, sizeof(Packed));
|
|
||||||
return Packed;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER static vec<2, float, Q> unpack(vec<2, uint16, Q> const& v)
|
|
||||||
{
|
|
||||||
i16vec2 Unpack;
|
|
||||||
memcpy(&Unpack, &v, sizeof(Unpack));
|
|
||||||
return vec<2, float, Q>(detail::toFloat32(v.x), detail::toFloat32(v.y));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<qualifier Q>
|
|
||||||
struct compute_half<3, Q>
|
|
||||||
{
|
|
||||||
GLM_FUNC_QUALIFIER static vec<3, uint16, Q> pack(vec<3, float, Q> const& v)
|
|
||||||
{
|
|
||||||
vec<3, int16, Q> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z));
|
|
||||||
u16vec3 Packed;
|
|
||||||
memcpy(&Packed, &Unpack, sizeof(Packed));
|
|
||||||
return Packed;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER static vec<3, float, Q> unpack(vec<3, uint16, Q> const& v)
|
|
||||||
{
|
|
||||||
i16vec3 Unpack;
|
|
||||||
memcpy(&Unpack, &v, sizeof(Unpack));
|
|
||||||
return vec<3, float, Q>(detail::toFloat32(v.x), detail::toFloat32(v.y), detail::toFloat32(v.z));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<qualifier Q>
|
|
||||||
struct compute_half<4, Q>
|
|
||||||
{
|
|
||||||
GLM_FUNC_QUALIFIER static vec<4, uint16, Q> pack(vec<4, float, Q> const& v)
|
|
||||||
{
|
|
||||||
vec<4, int16, Q> const Unpack(detail::toFloat16(v.x), detail::toFloat16(v.y), detail::toFloat16(v.z), detail::toFloat16(v.w));
|
|
||||||
u16vec4 Packed;
|
|
||||||
memcpy(&Packed, &Unpack, sizeof(Packed));
|
|
||||||
return Packed;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER static vec<4, float, Q> unpack(vec<4, uint16, Q> const& v)
|
|
||||||
{
|
|
||||||
i16vec4 Unpack;
|
|
||||||
memcpy(&Unpack, &v, sizeof(Unpack));
|
|
||||||
return vec<4, float, Q>(detail::toFloat32(v.x), detail::toFloat32(v.y), detail::toFloat32(v.z), detail::toFloat32(v.w));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}//namespace detail
|
}//namespace detail
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER uint8 packUnorm1x8(float v)
|
GLM_FUNC_QUALIFIER uint8 packUnorm1x8(float v)
|
||||||
@ -473,22 +393,22 @@ namespace detail
|
|||||||
-1.0f, 1.0f);
|
-1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER uint16 packHalf1x16(float v)
|
GLM_FUNC_QUALIFIER uint16 packHalf1x16(vec1 v)
|
||||||
{
|
{
|
||||||
int16 const Topack(detail::toFloat16(v));
|
int16 const Topack(detail::toFloat16(v.x));
|
||||||
uint16 Packed = 0;
|
uint16 Packed = 0;
|
||||||
memcpy(&Packed, &Topack, sizeof(Packed));
|
memcpy(&Packed, &Topack, sizeof(Packed));
|
||||||
return Packed;
|
return Packed;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER float unpackHalf1x16(uint16 v)
|
GLM_FUNC_QUALIFIER vec1 unpackHalf1x16(uint16 v)
|
||||||
{
|
{
|
||||||
int16 Unpack = 0;
|
i16vec1 Unpack;
|
||||||
memcpy(&Unpack, &v, sizeof(Unpack));
|
memcpy(&Unpack, &v, sizeof(Unpack));
|
||||||
return detail::toFloat32(Unpack);
|
return vec1(detail::toFloat32(Unpack.x));
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER uint64 packHalf4x16(glm::vec4 const& v)
|
GLM_FUNC_QUALIFIER uint64 packHalf4x16(vec4 const& v)
|
||||||
{
|
{
|
||||||
i16vec4 const Unpack(
|
i16vec4 const Unpack(
|
||||||
detail::toFloat16(v.x),
|
detail::toFloat16(v.x),
|
||||||
@ -656,18 +576,6 @@ namespace detail
|
|||||||
return vec<3, T, Q>(rgbm.x, rgbm.y, rgbm.z) * rgbm.w * static_cast<T>(6);
|
return vec<3, T, Q>(rgbm.x, rgbm.y, rgbm.z) * rgbm.w * static_cast<T>(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<length_t L, qualifier Q>
|
|
||||||
GLM_FUNC_QUALIFIER vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v)
|
|
||||||
{
|
|
||||||
return detail::compute_half<L, Q>::pack(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<length_t L, qualifier Q>
|
|
||||||
GLM_FUNC_QUALIFIER vec<L, float, Q> unpackHalf(vec<L, uint16, Q> const& v)
|
|
||||||
{
|
|
||||||
return detail::compute_half<L, Q>::unpack(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename uintType, length_t L, typename floatType, qualifier Q>
|
template<typename uintType, length_t L, typename floatType, qualifier Q>
|
||||||
GLM_FUNC_QUALIFIER vec<L, uintType, Q> packUnorm(vec<L, floatType, Q> const& v)
|
GLM_FUNC_QUALIFIER vec<L, uintType, Q> packUnorm(vec<L, floatType, Q> const& v)
|
||||||
{
|
{
|
||||||
|
@ -10,9 +10,10 @@ glmCreateTestGTC(ext_quaternion_type)
|
|||||||
glmCreateTestGTC(ext_scalar_common)
|
glmCreateTestGTC(ext_scalar_common)
|
||||||
glmCreateTestGTC(ext_scalar_constants)
|
glmCreateTestGTC(ext_scalar_constants)
|
||||||
glmCreateTestGTC(ext_scalar_int_sized)
|
glmCreateTestGTC(ext_scalar_int_sized)
|
||||||
|
glmCreateTestGTC(ext_scalar_packing)
|
||||||
|
glmCreateTestGTC(ext_scalar_relational)
|
||||||
glmCreateTestGTC(ext_scalar_uint_sized)
|
glmCreateTestGTC(ext_scalar_uint_sized)
|
||||||
glmCreateTestGTC(ext_scalar_ulp)
|
glmCreateTestGTC(ext_scalar_ulp)
|
||||||
glmCreateTestGTC(ext_scalar_relational)
|
|
||||||
glmCreateTestGTC(ext_vec1)
|
glmCreateTestGTC(ext_vec1)
|
||||||
glmCreateTestGTC(ext_vector_bool1)
|
glmCreateTestGTC(ext_vector_bool1)
|
||||||
glmCreateTestGTC(ext_vector_common)
|
glmCreateTestGTC(ext_vector_common)
|
||||||
|
38
test/ext/ext_scalar_packing.cpp
Normal file
38
test/ext/ext_scalar_packing.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <glm/ext/scalar_int_sized.hpp>
|
||||||
|
#include <glm/ext/scalar_packing.hpp>
|
||||||
|
#include <glm/ext/scalar_relational.hpp>
|
||||||
|
#include <glm/ext/scalar_constants.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
static int test_half()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
std::vector<float> 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::uint16 p0 = glm::packHalf(Tests[i]);
|
||||||
|
float v0 = glm::unpackHalf(p0);
|
||||||
|
glm::uint16 p1 = glm::packHalf(v0);
|
||||||
|
float v1 = glm::unpackHalf(p1);
|
||||||
|
Error += glm::equal(v0, v1, glm::epsilon<float>()) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
Error += test_half();
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
@ -1,18 +1,88 @@
|
|||||||
|
#include <glm/ext/scalar_constants.hpp>
|
||||||
|
#include <glm/ext/vector_relational.hpp>
|
||||||
#include <glm/ext/vector_packing.hpp>
|
#include <glm/ext/vector_packing.hpp>
|
||||||
|
#include <glm/ext/vector_ulp.hpp>
|
||||||
#include <glm/ext/vector_float1.hpp>
|
#include <glm/ext/vector_float1.hpp>
|
||||||
#include <glm/ext/vector_float2.hpp>
|
#include <glm/ext/vector_float2.hpp>
|
||||||
#include <glm/ext/vector_float3.hpp>
|
#include <glm/ext/vector_float3.hpp>
|
||||||
#include <glm/ext/vector_float4.hpp>
|
#include <glm/ext/vector_float4.hpp>
|
||||||
#include <glm/ext/vector_double1.hpp>
|
#include <vector>
|
||||||
#include <glm/ext/vector_double2.hpp>
|
|
||||||
#include <glm/ext/vector_double3.hpp>
|
template <glm::length_t L, glm::qualifier Q>
|
||||||
#include <glm/ext/vector_double4.hpp>
|
static int test_half()
|
||||||
|
{
|
||||||
|
typedef glm::vec<L, glm::uint16, Q> vecUType;
|
||||||
|
typedef glm::vec<L, int, Q> vecIType;
|
||||||
|
typedef glm::vec<L, float, Q> vecFType;
|
||||||
|
|
||||||
|
float const Epsilon = 0.01f;
|
||||||
|
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
struct test
|
||||||
|
{
|
||||||
|
test(vecFType const& Data, vecIType const& ULPs)
|
||||||
|
: Data(Data)
|
||||||
|
, ULPs(ULPs)
|
||||||
|
{}
|
||||||
|
|
||||||
|
vecFType Data;
|
||||||
|
vecIType ULPs;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<test> Tests;
|
||||||
|
Tests.push_back(test(vecFType(1.0f), vecIType(0)));
|
||||||
|
Tests.push_back(test(vecFType(0.0f), vecIType(0)));
|
||||||
|
Tests.push_back(test(vecFType(2.0f), vecIType(0)));
|
||||||
|
Tests.push_back(test(vecFType(0.1f), vecIType(3277)));
|
||||||
|
Tests.push_back(test(vecFType(0.5f), vecIType(0)));
|
||||||
|
Tests.push_back(test(vecFType(-0.9f), vecIType(1638)));
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||||
|
{
|
||||||
|
vecFType const Data = Tests[i].Data;
|
||||||
|
|
||||||
|
vecUType const p0 = glm::packHalf(Data);
|
||||||
|
|
||||||
|
vecFType const v0 = glm::unpackHalf(p0);
|
||||||
|
Error += glm::all(glm::equal(v0, Data, Epsilon)) ? 0 : 1;
|
||||||
|
|
||||||
|
vecUType const p1 = glm::packHalf(v0);
|
||||||
|
Error += glm::all(glm::equal(p0, p1)) ? 0 : 1;
|
||||||
|
|
||||||
|
vecFType const v1 = glm::unpackHalf(p1);
|
||||||
|
Error += glm::all(glm::equal(v1, Data, Epsilon)) ? 0 : 1;
|
||||||
|
|
||||||
|
vecIType const ULPs = glm::float_distance(Data, v0);
|
||||||
|
Error += glm::all(glm::equal(ULPs, Tests[i].ULPs)) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int Error = 0;
|
int Error = 0;
|
||||||
|
|
||||||
|
Error += test_half<1, glm::defaultp>();
|
||||||
|
Error += test_half<2, glm::defaultp>();
|
||||||
|
Error += test_half<3, glm::defaultp>();
|
||||||
|
Error += test_half<4, glm::defaultp>();
|
||||||
|
|
||||||
|
Error += test_half<1, glm::lowp>();
|
||||||
|
Error += test_half<2, glm::lowp>();
|
||||||
|
Error += test_half<3, glm::lowp>();
|
||||||
|
Error += test_half<4, glm::lowp>();
|
||||||
|
|
||||||
|
Error += test_half<1, glm::mediump>();
|
||||||
|
Error += test_half<2, glm::mediump>();
|
||||||
|
Error += test_half<3, glm::mediump>();
|
||||||
|
Error += test_half<4, glm::mediump>();
|
||||||
|
|
||||||
|
Error += test_half<1, glm::highp>();
|
||||||
|
Error += test_half<2, glm::highp>();
|
||||||
|
Error += test_half<3, glm::highp>();
|
||||||
|
Error += test_half<4, glm::highp>();
|
||||||
|
|
||||||
return Error;
|
return Error;
|
||||||
}
|
}
|
||||||
|
@ -57,31 +57,63 @@ void print_value(float const& s)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_Half1x16()
|
static int test_half1x16()
|
||||||
{
|
{
|
||||||
int Error = 0;
|
int Error = 0;
|
||||||
|
|
||||||
std::vector<float> Tests;
|
std::vector<glm::vec1> Tests;
|
||||||
Tests.push_back(0.0f);
|
Tests.push_back(glm::vec1(1.0f));
|
||||||
Tests.push_back(1.0f);
|
Tests.push_back(glm::vec1(0.0f));
|
||||||
Tests.push_back(-1.0f);
|
Tests.push_back(glm::vec1(2.0f));
|
||||||
Tests.push_back(2.0f);
|
Tests.push_back(glm::vec1(0.1f));
|
||||||
Tests.push_back(-2.0f);
|
Tests.push_back(glm::vec1(0.5f));
|
||||||
Tests.push_back(1.9f);
|
Tests.push_back(glm::vec1(-0.9f));
|
||||||
|
|
||||||
for(std::size_t i = 0; i < Tests.size(); ++i)
|
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||||
{
|
{
|
||||||
glm::uint16 p0 = glm::packHalf1x16(Tests[i]);
|
glm::uint16 p0 = glm::packHalf1x16(Tests[i]);
|
||||||
float v0 = glm::unpackHalf1x16(p0);
|
glm::vec1 v0 = glm::unpackHalf1x16(p0);
|
||||||
glm::uint16 p1 = glm::packHalf1x16(v0);
|
glm::uint16 p1 = glm::packHalf1x16(v0);
|
||||||
float v1 = glm::unpackHalf1x16(p1);
|
glm::vec1 v1 = glm::unpackHalf1x16(p1);
|
||||||
Error += glm::epsilonEqual(v0, v1, glm::epsilon<float>()) ? 0 : 1;
|
glm::u16vec1 p2 = glm::packHalf(v0);
|
||||||
|
glm::vec1 v2 = glm::unpackHalf(p2);
|
||||||
|
|
||||||
|
Error += glm::all(glm::equal(v0, v1, glm::epsilon<float>())) ? 0 : 1;
|
||||||
|
Error += glm::all(glm::equal(v0, v2, glm::epsilon<float>())) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Error;
|
return Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_Half4x16()
|
static int test_half2x16()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
std::vector<glm::vec2> Tests;
|
||||||
|
Tests.push_back(glm::vec2(1.0f));
|
||||||
|
Tests.push_back(glm::vec2(0.0f));
|
||||||
|
Tests.push_back(glm::vec2(2.0f));
|
||||||
|
Tests.push_back(glm::vec2(0.1f));
|
||||||
|
Tests.push_back(glm::vec2(0.5f));
|
||||||
|
Tests.push_back(glm::vec2(-0.9f));
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||||
|
{
|
||||||
|
glm::uint32 p0 = glm::packHalf2x16(Tests[i]);
|
||||||
|
glm::vec2 v0 = glm::unpackHalf2x16(p0);
|
||||||
|
glm::uint32 p1 = glm::packHalf2x16(v0);
|
||||||
|
glm::vec2 v1 = glm::unpackHalf2x16(p1);
|
||||||
|
glm::u16vec2 p2 = glm::packHalf(v0);
|
||||||
|
glm::vec2 v2 = glm::unpackHalf(p2);
|
||||||
|
|
||||||
|
Error += glm::all(glm::equal(v0, v1, glm::epsilon<float>())) ? 0 : 1;
|
||||||
|
Error += glm::all(glm::equal(v0, v2, glm::epsilon<float>())) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int test_half4x16()
|
||||||
{
|
{
|
||||||
int Error = 0;
|
int Error = 0;
|
||||||
|
|
||||||
@ -871,8 +903,10 @@ int main()
|
|||||||
|
|
||||||
Error += test_I3x10_1x2();
|
Error += test_I3x10_1x2();
|
||||||
Error += test_U3x10_1x2();
|
Error += test_U3x10_1x2();
|
||||||
Error += test_Half1x16();
|
|
||||||
Error += test_Half4x16();
|
Error += test_half1x16();
|
||||||
|
Error += test_half2x16();
|
||||||
|
Error += test_half4x16();
|
||||||
|
|
||||||
return Error;
|
return Error;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user