mirror of
https://github.com/g-truc/glm.git
synced 2024-11-10 04:31:47 +00:00
Added packing experiments
This commit is contained in:
parent
3d526d1388
commit
cef58e189d
@ -32,14 +32,14 @@ namespace glm
|
||||
/// 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);
|
||||
GLM_FUNC_DECL uint16 packFloatToHalf(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);
|
||||
GLM_FUNC_DECL float unpackHalfToFloat(uint16 p);
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
namespace glm
|
||||
{
|
||||
GLM_FUNC_QUALIFIER uint16 packHalf(float Scalar)
|
||||
GLM_FUNC_QUALIFIER uint16 packFloatToHalf(float Scalar)
|
||||
{
|
||||
return detail::toFloat16(Scalar);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER float unpackHalf(uint16 Packed)
|
||||
GLM_FUNC_QUALIFIER float unpackHalfToFloat(uint16 Packed)
|
||||
{
|
||||
return detail::toFloat32(Packed);
|
||||
}
|
||||
|
@ -26,6 +26,48 @@ namespace glm
|
||||
/// @addtogroup ext_vector_packing
|
||||
/// @{
|
||||
|
||||
GLM_FUNC_DECL uint8 packVecToUInt(vec<1, uint8> const& v);
|
||||
|
||||
GLM_FUNC_DECL vec<1, uint8> unpackUInt(uint8 p);
|
||||
|
||||
GLM_FUNC_DECL uint16 packUInt(vec<1, uint16> const& v);
|
||||
|
||||
GLM_FUNC_DECL vec<1, uint16> unpackUInt(uint16 p);
|
||||
|
||||
GLM_FUNC_DECL uint32 packUInt(vec<1, uint32> const& v);
|
||||
|
||||
GLM_FUNC_DECL vec<1, uint32> unpackUInt(uint32 p);
|
||||
|
||||
GLM_FUNC_DECL uint64 packUInt(vec<1, uint64> const& v);
|
||||
|
||||
GLM_FUNC_DECL vec<1, uint64> unpackUInt(uint64 p);
|
||||
|
||||
|
||||
|
||||
GLM_FUNC_DECL uint16 packUInt(vec<2, uint8> const& v);
|
||||
|
||||
GLM_FUNC_DECL vec<2, uint8> unpackUInt(uint16 p);
|
||||
|
||||
GLM_FUNC_DECL uint32 packUInt(vec<2, uint16> const& v);
|
||||
|
||||
GLM_FUNC_DECL vec<2, uint16> unpackUInt(uint32 p);
|
||||
|
||||
GLM_FUNC_DECL uint64 packUInt(vec<2, uint32> const& v);
|
||||
|
||||
GLM_FUNC_DECL vec<2, uint32> unpackUInt(uint64 p);
|
||||
|
||||
|
||||
|
||||
GLM_FUNC_DECL uint32 packUInt(vec<4, uint8> const& v);
|
||||
|
||||
GLM_FUNC_DECL vec<4, uint8> unpackUInt(uint32 p);
|
||||
|
||||
GLM_FUNC_DECL uint64 packUInt(vec<4, uint16> const& v);
|
||||
|
||||
GLM_FUNC_DECL vec<4, uint16> unpackUInt(uint64 p);
|
||||
|
||||
|
||||
|
||||
/// 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;
|
||||
@ -34,7 +76,7 @@ namespace glm
|
||||
/// @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);
|
||||
GLM_FUNC_DECL vec<L, uint16, Q> packFloatToHalf(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;
|
||||
@ -43,7 +85,38 @@ namespace glm
|
||||
/// @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);
|
||||
GLM_FUNC_DECL vec<L, float, Q> unpackHalfToFloat(vec<L, uint16, Q> const& p);
|
||||
|
||||
|
||||
/// Convert each component of the normalized floating-point vector into unsigned integer values.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see vec<L, floatType, Q> unpackUnorm(vec<L, intType, Q> const& p);
|
||||
template<typename uintType, length_t L, typename floatType, qualifier Q>
|
||||
GLM_FUNC_DECL vec<L, uintType, Q> packFloatToUnorm(vec<L, floatType, Q> const& v);
|
||||
|
||||
/// Convert a packed integer to a normalized floating-point vector.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see vec<L, intType, Q> packUnorm(vec<L, floatType, Q> const& v)
|
||||
template<typename floatType, length_t L, typename uintType, qualifier Q>
|
||||
GLM_FUNC_DECL vec<L, floatType, Q> unpackUnormToFloat(vec<L, uintType, Q> const& v);
|
||||
|
||||
|
||||
/// Convert each component of the normalized floating-point vector into signed integer values.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see vec<L, floatType, Q> unpackSnorm(vec<L, intType, Q> const& p);
|
||||
template<typename intType, length_t L, typename floatType, qualifier Q>
|
||||
GLM_FUNC_DECL vec<L, intType, Q> packFloatToSnorm(vec<L, floatType, Q> const& v);
|
||||
|
||||
/// Convert a packed integer to a normalized floating-point vector.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see vec<L, intType, Q> packSnorm(vec<L, floatType, Q> const& v)
|
||||
template<typename floatType, length_t L, typename intType, qualifier Q>
|
||||
GLM_FUNC_DECL vec<L, floatType, Q> unpackSnormToFloat(vec<L, intType, Q> const& v);
|
||||
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
@ -85,13 +85,13 @@ namespace detail
|
||||
}//namespace detail
|
||||
|
||||
template<length_t L, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER vec<L, uint16, Q> packHalf(vec<L, float, Q> const& v)
|
||||
GLM_FUNC_QUALIFIER vec<L, uint16, Q> packFloatToHalf(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)
|
||||
GLM_FUNC_QUALIFIER vec<L, float, Q> unpackHalfToFloat(vec<L, uint16, Q> const& v)
|
||||
{
|
||||
return detail::compute_half<L, Q>::unpack(v);
|
||||
}
|
||||
|
@ -492,6 +492,27 @@ namespace glm
|
||||
template<length_t L, typename T, qualifier Q>
|
||||
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.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
|
@ -576,6 +576,18 @@ namespace detail
|
||||
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>
|
||||
GLM_FUNC_QUALIFIER vec<L, uintType, Q> packUnorm(vec<L, floatType, Q> const& v)
|
||||
{
|
||||
|
@ -17,12 +17,12 @@ static int test_half()
|
||||
|
||||
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||
{
|
||||
glm::uint16 p0 = glm::packHalf(Tests[i]);
|
||||
float v0 = glm::unpackHalf(p0);
|
||||
glm::uint16 p0 = glm::packFloatToHalf(Tests[i]);
|
||||
float v0 = glm::unpackHalfToFloat(p0);
|
||||
Error += glm::equal(v0, Tests[i], 0.01f) ? 0 : 1;
|
||||
|
||||
glm::uint16 p1 = glm::packHalf(v0);
|
||||
float v1 = glm::unpackHalf(p1);
|
||||
glm::uint16 p1 = glm::packFloatToHalf(v0);
|
||||
float v1 = glm::unpackHalfToFloat(p1);
|
||||
Error += glm::equal(v1, Tests[i], 0.01f) ? 0 : 1;
|
||||
|
||||
Error += glm::equal(v0, v1, 0) ? 0 : 1;
|
||||
|
@ -42,15 +42,15 @@ static int test_half()
|
||||
{
|
||||
vecFType const Data = Tests[i].Data;
|
||||
|
||||
vecUType const p0 = glm::packHalf(Data);
|
||||
vecUType const p0 = glm::packFloatToHalf(Data);
|
||||
|
||||
vecFType const v0 = glm::unpackHalf(p0);
|
||||
vecFType const v0 = glm::unpackHalfToFloat(p0);
|
||||
Error += glm::all(glm::equal(v0, Data, Epsilon)) ? 0 : 1;
|
||||
|
||||
vecUType const p1 = glm::packHalf(v0);
|
||||
vecUType const p1 = glm::packFloatToHalf(v0);
|
||||
Error += glm::all(glm::equal(p0, p1)) ? 0 : 1;
|
||||
|
||||
vecFType const v1 = glm::unpackHalf(p1);
|
||||
vecFType const v1 = glm::unpackHalfToFloat(p1);
|
||||
Error += glm::all(glm::equal(v1, Data, Epsilon)) ? 0 : 1;
|
||||
|
||||
vecIType const ULPs = glm::float_distance(Data, v0);
|
||||
|
Loading…
Reference in New Issue
Block a user