Added missing documentation, missing 4x16 half packing functions, added initial tests

This commit is contained in:
Christophe Riccio 2013-08-26 08:28:17 +02:00
parent fb13e7bf8a
commit 0abec19bc1
3 changed files with 113 additions and 1 deletions

View File

@ -342,6 +342,16 @@ namespace glm
/// @see uint32 packUnorm3x10_1x2(vec4 const & v) /// @see uint32 packUnorm3x10_1x2(vec4 const & v)
/// @see ivec4 unpackI3x10_1x2(uint32 const & p) /// @see ivec4 unpackI3x10_1x2(uint32 const & p)
GLM_FUNC_DECL uint32 packI3x10_1x2(ivec4 const & v); GLM_FUNC_DECL uint32 packI3x10_1x2(ivec4 const & v);
/// Unpacks a single 32-bit unsigned integer p into three 10-bit and one 2-bit signed integers.
///
/// The first component of the returned vector will be extracted from the least significant bits of the input;
/// the last component will be extracted from the most significant bits.
///
/// @see gtc_packing
/// @see uint32 packU3x10_1x2(uvec4 const & v)
/// @see vec4 unpackSnorm3x10_1x2(uint32 const & p);
/// @see uvec4 unpackI3x10_1x2(uint32 const & p);
GLM_FUNC_DECL ivec4 unpackI3x10_1x2(uint32 const & p); 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 /// Returns an unsigned integer obtained by converting the components of a four-component unsigned integer vector
@ -356,6 +366,16 @@ namespace glm
/// @see uint32 packUnorm3x10_1x2(vec4 const & v) /// @see uint32 packUnorm3x10_1x2(vec4 const & v)
/// @see ivec4 unpackU3x10_1x2(uint32 const & p) /// @see ivec4 unpackU3x10_1x2(uint32 const & p)
GLM_FUNC_DECL uint32 packU3x10_1x2(uvec4 const & v); 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); 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. /// First, converts the first three components of the normalized floating-point value v into 10-bit signed integer values.

View File

@ -438,6 +438,20 @@ namespace detail
return detail::toFloat32(Packing.data); return detail::toFloat32(Packing.data);
} }
GLM_FUNC_DECL uint64 packHalf4x16(float const & v)
{
detail::half4x16 Packing;
Packing.data = detail::toFloat16(v);
return Packing.pack;
}
GLM_FUNC_DECL float unpackHalf4x16(uint64 const & v)
{
detail::half4x16 Packing;
Packing.pack = v;
return detail::toFloat32(Packing.data);
}
GLM_FUNC_QUALIFIER uint32 packI3x10_1x2(ivec4 const & v) GLM_FUNC_QUALIFIER uint32 packI3x10_1x2(ivec4 const & v)
{ {
detail::i10i10i10i2 Result; detail::i10i10i10i2 Result;

View File

@ -132,11 +132,89 @@ int test_half()
return Error; return Error;
} }
int test_F2x11_1x10()
{
int Error = 0;
std::vector<glm::vec3> Tests;
Tests.push_back(glm::vec3(1.0));
Tests.push_back(glm::vec3(0.0));
Tests.push_back(glm::vec3(2.0));
Tests.push_back(glm::vec3(0.1));
Tests.push_back(glm::vec3(0.5));
Tests.push_back(glm::vec3(0.9));
for(std::size_t i = 0; i < Tests.size(); ++i)
{
glm::uint32 p0 = glm::packF2x11_1x10(Tests[i]);
glm::vec3 v0 = glm::unpackF2x11_1x10(p0);
glm::uint32 p1 = glm::packF2x11_1x10(v0);
glm::vec3 v1 = glm::unpackF2x11_1x10(p0);
Error += glm::all(glm::equal(v0, v1)) ? 0 : 1;
}
return Error;
}
int test_Snorm3x10_1x2()
{
int Error = 0;
std::vector<glm::vec4> Tests;
Tests.push_back(glm::vec4(1.0));
Tests.push_back(glm::vec4(0.0));
Tests.push_back(glm::vec4(2.0));
Tests.push_back(glm::vec4(0.1));
Tests.push_back(glm::vec4(0.5));
Tests.push_back(glm::vec4(0.9));
for(std::size_t i = 0; i < Tests.size(); ++i)
{
glm::uint32 p0 = glm::packSnorm3x10_1x2(Tests[i]);
glm::vec3 v0 = glm::unpackSnorm3x10_1x2(p0);
glm::uint32 p1 = glm::packSnorm3x10_1x2(v0);
glm::vec3 v1 = glm::unpackSnorm3x10_1x2(p0);
Error += glm::all(glm::equal(v0, v1)) ? 0 : 1;
}
return Error;
}
int test_Unorm3x10_1x2()
{
int Error = 0;
std::vector<glm::vec4> Tests;
Tests.push_back(glm::vec4(1.0));
Tests.push_back(glm::vec4(0.0));
Tests.push_back(glm::vec4(2.0));
Tests.push_back(glm::vec4(0.1));
Tests.push_back(glm::vec4(0.5));
Tests.push_back(glm::vec4(0.9));
for(std::size_t i = 0; i < Tests.size(); ++i)
{
glm::uint32 p0 = glm::packSnorm3x10_1x2(Tests[i]);
glm::vec3 v0 = glm::unpackSnorm3x10_1x2(p0);
glm::uint32 p1 = glm::packSnorm3x10_1x2(v0);
glm::vec3 v1 = glm::unpackSnorm3x10_1x2(p0);
Error += glm::all(glm::equal(v0, v1)) ? 0 : 1;
}
return Error;
}
int main() int main()
{ {
int Error(0); 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; return Error;
} }