Fixed build

This commit is contained in:
Christophe Riccio 2013-08-26 11:14:46 +02:00
parent 0abec19bc1
commit b1230f2adc
2 changed files with 174 additions and 59 deletions

View File

@ -65,7 +65,7 @@ namespace detail
((f >> 17) & 0x003f); // Mantissa
}
glm::uint32 packed11Tofloat(glm::uint32 const & p)
glm::uint32 packed11ToFloat(glm::uint32 const & p)
{
// 10 bits => EE EEEFFFFF
// 11 bits => EEE EEFFFFFF
@ -80,7 +80,7 @@ namespace detail
// 0x00008000 => 00000000 00000000 10000000 00000000
return
((((p & 0x07c0) << 17) + 0x38000000) & 0x7f800000) | // exponential
((f & 0x003f) << 17); // Mantissa
((p & 0x003f) << 17); // Mantissa
}
glm::uint32 float2packed10(glm::uint32 const & f)
@ -122,7 +122,7 @@ namespace detail
// 0x00008000 => 00000000 00000000 10000000 00000000
return
((((p & 0x03E0) << 18) + 0x38000000) & 0x7f800000) | // exponential
((f & 0x001f) << 18); // Mantissa
((p & 0x001f) << 18); // Mantissa
}
glm::uint half2float(glm::uint const & h)
@ -257,6 +257,17 @@ namespace detail
uint16 pack;
};
union half4x16
{
struct
{
hdata x;
hdata y;
hdata z;
hdata w;
} data;
uint64 pack;
};
union unorm1x8
{
@ -438,18 +449,25 @@ namespace detail
return detail::toFloat32(Packing.data);
}
GLM_FUNC_DECL uint64 packHalf4x16(float const & v)
GLM_FUNC_DECL uint64 packHalf4x16(glm::vec4 const & v)
{
detail::half4x16 Packing;
Packing.data = detail::toFloat16(v);
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 float unpackHalf4x16(uint64 const & v)
GLM_FUNC_DECL glm::vec4 unpackHalf4x16(uint64 const & v)
{
detail::half4x16 Packing;
Packing.pack = v;
return detail::toFloat32(Packing.data);
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)
@ -549,9 +567,9 @@ namespace detail
GLM_FUNC_QUALIFIER vec3 unpackF2x11_1x10(uint32 const & v)
{
return vec3(
packed11bitToFloat(v >> 0),
packed11bitToFloat(v >> 11),
packed10bitToFloat(v >> 22));
detail::packed11bitToFloat(v >> 0),
detail::packed11bitToFloat(v >> 11),
detail::packed10bitToFloat(v >> 22));
}
}//namespace glm

View File

@ -29,6 +29,7 @@
#include <glm/glm.hpp>
#include <glm/gtc/packing.hpp>
#include <cstdio>
#include <vector>
void print_bits(glm::half const & s)
{
@ -132,6 +133,150 @@ int test_half()
return Error;
}
int test_Half1x16()
{
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::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<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::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<glm::ivec4> 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<glm::uvec4> 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<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::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<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::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;
@ -156,54 +301,6 @@ int test_F2x11_1x10()
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 Error(0);