mirror of
https://github.com/g-truc/glm.git
synced 2024-11-26 18:24:35 +00:00
Fixed GTC_packing *pack*norm*x* build and added tests #292
This commit is contained in:
parent
025a4c79ff
commit
d9290d7887
@ -40,8 +40,8 @@ namespace glm
|
|||||||
{
|
{
|
||||||
u16vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 65535.0f));
|
u16vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 65535.0f));
|
||||||
// return reinterpret_cast<uint&>(Topack);
|
// return reinterpret_cast<uint&>(Topack);
|
||||||
uint* ptr(reinterpret_cast<uint*>(&Topack));
|
uint* ptr(reinterpret_cast<uint*>(&Topack));
|
||||||
return *ptr;
|
return *ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x16(uint const & p)
|
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x16(uint const & p)
|
||||||
@ -52,15 +52,13 @@ namespace glm
|
|||||||
|
|
||||||
GLM_FUNC_QUALIFIER uint packSnorm2x16(vec2 const & v)
|
GLM_FUNC_QUALIFIER uint packSnorm2x16(vec2 const & v)
|
||||||
{
|
{
|
||||||
i16vec2 Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
|
i16vec2 const Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
|
||||||
// return reinterpret_cast<uint32&>(Topack);
|
return reinterpret_cast<uint const &>(Topack);
|
||||||
uint* ptr(reinterpret_cast<uint*>(&Topack));
|
|
||||||
return *ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER vec2 unpackSnorm2x16(uint const & p)
|
GLM_FUNC_QUALIFIER vec2 unpackSnorm2x16(uint const & p)
|
||||||
{
|
{
|
||||||
vec2 Unpack(reinterpret_cast<i16vec2 const &>(p));
|
vec2 const Unpack(reinterpret_cast<i16vec2 const &>(p));
|
||||||
return clamp(
|
return clamp(
|
||||||
Unpack * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
|
Unpack * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
|
||||||
-1.0f, 1.0f);
|
-1.0f, 1.0f);
|
||||||
@ -68,13 +66,13 @@ namespace glm
|
|||||||
|
|
||||||
GLM_FUNC_QUALIFIER uint packUnorm4x8(vec4 const & v)
|
GLM_FUNC_QUALIFIER uint packUnorm4x8(vec4 const & v)
|
||||||
{
|
{
|
||||||
u8vec4 Topack(round(clamp(v, 0.0f, 1.0f) * 255.0f));
|
u8vec4 const Topack(round(clamp(v, 0.0f, 1.0f) * 255.0f));
|
||||||
return reinterpret_cast<uint&>(Topack);
|
return reinterpret_cast<uint const &>(Topack);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x8(uint const & p)
|
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x8(uint const & p)
|
||||||
{
|
{
|
||||||
vec4 Unpack(reinterpret_cast<u8vec4 const&>(p));
|
vec4 const Unpack(reinterpret_cast<u8vec4 const&>(p));
|
||||||
return Unpack * float(0.0039215686274509803921568627451); // 1 / 255
|
return Unpack * float(0.0039215686274509803921568627451); // 1 / 255
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ namespace glm
|
|||||||
/// @see vec2 unpackSnorm2x16(uint32 p)
|
/// @see vec2 unpackSnorm2x16(uint32 p)
|
||||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm2x16.xml">GLSL unpackSnorm4x8 man page</a>
|
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm2x16.xml">GLSL unpackSnorm4x8 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 vec4 unpackSnorm4x16(uint64 const & p);
|
GLM_FUNC_DECL vec4 unpackSnorm4x16(uint64 p);
|
||||||
|
|
||||||
/// Returns an unsigned integer obtained by converting the components of a floating-point scalar
|
/// 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,
|
/// to the 16-bit floating-point representation found in the OpenGL Specification,
|
||||||
|
@ -257,33 +257,31 @@ namespace detail
|
|||||||
|
|
||||||
GLM_FUNC_QUALIFIER float unpackUnorm1x8(uint8 p)
|
GLM_FUNC_QUALIFIER float unpackUnorm1x8(uint8 p)
|
||||||
{
|
{
|
||||||
float Unpack(static_cast<float>(p));
|
float const Unpack(p);
|
||||||
return Unpack * static_cast<float>(0.0039215686274509803921568627451); // 1 / 255
|
return Unpack * static_cast<float>(0.0039215686274509803921568627451); // 1 / 255
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER uint16 packUnorm2x8(vec2 const & v)
|
GLM_FUNC_QUALIFIER uint16 packUnorm2x8(vec2 const & v)
|
||||||
{
|
{
|
||||||
u8vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 255.0f));
|
u8vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 255.0f));
|
||||||
uint16* Packed = reinterpret_cast<uint16*>(&Topack);
|
return reinterpret_cast<uint16 const &>(Topack);
|
||||||
return *Packed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p)
|
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p)
|
||||||
{
|
{
|
||||||
u8vec2* Unpacked = reinterpret_cast<u8vec2*>(const_cast<uint16*>(&p));
|
vec2 const Unpack(reinterpret_cast<u8vec2 const &>(p));
|
||||||
return vec2(*Unpacked) * float(0.0039215686274509803921568627451); // 1 / 255
|
return Unpack * float(0.0039215686274509803921568627451); // 1 / 255
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER uint8 packSnorm1x8(float v)
|
GLM_FUNC_QUALIFIER uint8 packSnorm1x8(float v)
|
||||||
{
|
{
|
||||||
int8 Topack(static_cast<int8>(round(clamp(v ,-1.0f, 1.0f) * 127.0f)));
|
int8 const Topack(static_cast<int8>(round(clamp(v ,-1.0f, 1.0f) * 127.0f)));
|
||||||
uint8* Packed = reinterpret_cast<uint8*>(&Topack);
|
return reinterpret_cast<uint8 const &>(Topack);
|
||||||
return *Packed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER float unpackSnorm1x8(uint8 p)
|
GLM_FUNC_QUALIFIER float unpackSnorm1x8(uint8 p)
|
||||||
{
|
{
|
||||||
float Unpack(static_cast<float>(*const_cast<uint8*>(&p)));
|
float const Unpack(reinterpret_cast<int8 const &>(p));
|
||||||
return clamp(
|
return clamp(
|
||||||
Unpack * 0.00787401574803149606299212598425f, // 1.0f / 127.0f
|
Unpack * 0.00787401574803149606299212598425f, // 1.0f / 127.0f
|
||||||
-1.0f, 1.0f);
|
-1.0f, 1.0f);
|
||||||
@ -291,16 +289,15 @@ namespace detail
|
|||||||
|
|
||||||
GLM_FUNC_QUALIFIER uint16 packSnorm2x8(vec2 const & v)
|
GLM_FUNC_QUALIFIER uint16 packSnorm2x8(vec2 const & v)
|
||||||
{
|
{
|
||||||
i8vec2 Topack(round(clamp(v ,-1.0f, 1.0f) * 127.0f));
|
i8vec2 const Topack(round(clamp(v, -1.0f, 1.0f) * 127.0f));
|
||||||
uint16* Packed = reinterpret_cast<uint16*>(&Topack);
|
return reinterpret_cast<uint16 const &>(Topack);
|
||||||
return *Packed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p)
|
GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p)
|
||||||
{
|
{
|
||||||
i8vec2* Unpack = reinterpret_cast<i8vec2*>(const_cast<uint16*>(&p));
|
vec2 const Unpack(reinterpret_cast<i8vec2 const &>(p));
|
||||||
return clamp(
|
return clamp(
|
||||||
vec2(*Unpack) * 0.00787401574803149606299212598425f, // 1.0f / 127.0f
|
Unpack * 0.00787401574803149606299212598425f, // 1.0f / 127.0f
|
||||||
-1.0f, 1.0f);
|
-1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,33 +308,31 @@ namespace detail
|
|||||||
|
|
||||||
GLM_FUNC_QUALIFIER float unpackUnorm1x16(uint16 p)
|
GLM_FUNC_QUALIFIER float unpackUnorm1x16(uint16 p)
|
||||||
{
|
{
|
||||||
float Unpack = static_cast<float>(*const_cast<uint16*>(&p));
|
float const Unpack(p);
|
||||||
return Unpack * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0
|
return Unpack * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER uint64 packUnorm4x16(vec4 const & v)
|
GLM_FUNC_QUALIFIER uint64 packUnorm4x16(vec4 const & v)
|
||||||
{
|
{
|
||||||
u16vec4 Topack(round(clamp(v , 0.0f, 1.0f) * 65535.0f));
|
u16vec4 const Topack(round(clamp(v , 0.0f, 1.0f) * 65535.0f));
|
||||||
uint64* Packed = reinterpret_cast<uint64*>(&Topack);
|
return reinterpret_cast<uint64 const &>(Topack);
|
||||||
return *Packed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x16(uint64 p)
|
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x16(uint64 p)
|
||||||
{
|
{
|
||||||
u16vec4* Unpack = reinterpret_cast<u16vec4*>(const_cast<uint64*>(&p));
|
vec4 const Unpack(reinterpret_cast<u16vec4 const &>(p));
|
||||||
return vec4(*Unpack) * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0
|
return Unpack * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER uint16 packSnorm1x16(float v)
|
GLM_FUNC_QUALIFIER uint16 packSnorm1x16(float v)
|
||||||
{
|
{
|
||||||
int16 Topack = static_cast<int16>(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
|
int16 const Topack = static_cast<int16>(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
|
||||||
uint16* Packed = reinterpret_cast<uint16*>(&Topack);
|
return reinterpret_cast<uint16 const &>(Topack);
|
||||||
return *Packed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER float unpackSnorm1x16(uint16 p)
|
GLM_FUNC_QUALIFIER float unpackSnorm1x16(uint16 p)
|
||||||
{
|
{
|
||||||
float Unpack = static_cast<float>(*const_cast<uint16*>(&p));
|
float const Unpack(reinterpret_cast<int16 const &>(p));
|
||||||
return clamp(
|
return clamp(
|
||||||
Unpack * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
|
Unpack * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
|
||||||
-1.0f, 1.0f);
|
-1.0f, 1.0f);
|
||||||
@ -345,16 +340,15 @@ namespace detail
|
|||||||
|
|
||||||
GLM_FUNC_QUALIFIER uint64 packSnorm4x16(vec4 const & v)
|
GLM_FUNC_QUALIFIER uint64 packSnorm4x16(vec4 const & v)
|
||||||
{
|
{
|
||||||
i16vec4 Topack = static_cast<i16vec4>(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
|
i16vec4 const Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
|
||||||
uint64* Packed = reinterpret_cast<uint64*>(&Topack);
|
return reinterpret_cast<uint64 const &>(Topack);
|
||||||
return *Packed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 p)
|
GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 p)
|
||||||
{
|
{
|
||||||
i16vec4* Unpack(reinterpret_cast<i16vec4*>(const_cast<uint64*>(&p)));
|
vec4 const Unpack(reinterpret_cast<i16vec4 const &>(p));
|
||||||
return clamp(
|
return clamp(
|
||||||
vec4(*Unpack) * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
|
Unpack * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
|
||||||
-1.0f, 1.0f);
|
-1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,14 +373,12 @@ namespace detail
|
|||||||
detail::toFloat16(v.z),
|
detail::toFloat16(v.z),
|
||||||
detail::toFloat16(v.w));
|
detail::toFloat16(v.w));
|
||||||
|
|
||||||
uint64* Packed = reinterpret_cast<uint64*>(&Unpack);
|
return reinterpret_cast<uint64 const &>(Unpack);
|
||||||
return *Packed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLM_FUNC_QUALIFIER glm::vec4 unpackHalf4x16(uint64 v)
|
GLM_FUNC_QUALIFIER glm::vec4 unpackHalf4x16(uint64 v)
|
||||||
{
|
{
|
||||||
i16vec4* p = reinterpret_cast<i16vec4*>(const_cast<uint64*>(&v));
|
i16vec4 Unpack(reinterpret_cast<i16vec4 const &>(v));
|
||||||
i16vec4 Unpack(*p);
|
|
||||||
|
|
||||||
return vec4(
|
return vec4(
|
||||||
detail::toFloat32(Unpack.x),
|
detail::toFloat32(Unpack.x),
|
||||||
|
@ -80,6 +80,7 @@ Fixes:
|
|||||||
- Fixed mat4x3 = mat2x3 * mat4x2 operator #297
|
- Fixed mat4x3 = mat2x3 * mat4x2 operator #297
|
||||||
- Fixed warnings in F2x11_1x10 packing function in GTC_packing #295
|
- Fixed warnings in F2x11_1x10 packing function in GTC_packing #295
|
||||||
- Fixed Visual Studio natvis support for vec4 #288
|
- Fixed Visual Studio natvis support for vec4 #288
|
||||||
|
- Fixed GTC_packing *pack*norm*x* build and added tests #292
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
GLM 0.9.6.1: 2014-12-10
|
GLM 0.9.6.1: 2014-12-10
|
||||||
|
@ -38,12 +38,7 @@
|
|||||||
int test_packUnorm2x16()
|
int test_packUnorm2x16()
|
||||||
{
|
{
|
||||||
int Error = 0;
|
int Error = 0;
|
||||||
/*
|
|
||||||
std::vector<glm::hvec2> A;
|
|
||||||
A.push_back(glm::hvec2(glm::half( 1.0f), glm::half( 0.0f)));
|
|
||||||
A.push_back(glm::hvec2(glm::half( 0.5f), glm::half( 0.7f)));
|
|
||||||
A.push_back(glm::hvec2(glm::half( 0.1f), glm::half( 0.2f)));
|
|
||||||
*/
|
|
||||||
std::vector<glm::vec2> A;
|
std::vector<glm::vec2> A;
|
||||||
A.push_back(glm::vec2(1.0f, 0.0f));
|
A.push_back(glm::vec2(1.0f, 0.0f));
|
||||||
A.push_back(glm::vec2(0.5f, 0.7f));
|
A.push_back(glm::vec2(0.5f, 0.7f));
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <glm/gtc/packing.hpp>
|
#include <glm/gtc/packing.hpp>
|
||||||
|
#include <glm/gtc/epsilon.hpp>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -253,10 +254,273 @@ int test_F2x11_1x10()
|
|||||||
return Error;
|
return Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int test_packUnorm1x16()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
std::vector<glm::vec1> A;
|
||||||
|
A.push_back(glm::vec1(1.0f));
|
||||||
|
A.push_back(glm::vec1(0.5f));
|
||||||
|
A.push_back(glm::vec1(0.1f));
|
||||||
|
A.push_back(glm::vec1(0.0f));
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < A.size(); ++i)
|
||||||
|
{
|
||||||
|
glm::vec1 B(A[i]);
|
||||||
|
glm::uint32 C = glm::packUnorm1x16(B.x);
|
||||||
|
glm::vec1 D(glm::unpackUnorm1x16(C));
|
||||||
|
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
|
||||||
|
assert(!Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_packSnorm1x16()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
std::vector<glm::vec1> A;
|
||||||
|
A.push_back(glm::vec1( 1.0f));
|
||||||
|
A.push_back(glm::vec1( 0.0f));
|
||||||
|
A.push_back(glm::vec1(-0.5f));
|
||||||
|
A.push_back(glm::vec1(-0.1f));
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < A.size(); ++i)
|
||||||
|
{
|
||||||
|
glm::vec1 B(A[i]);
|
||||||
|
glm::uint32 C = glm::packSnorm1x16(B.x);
|
||||||
|
glm::vec1 D(glm::unpackSnorm1x16(C));
|
||||||
|
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_packUnorm2x16()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
std::vector<glm::vec2> A;
|
||||||
|
A.push_back(glm::vec2(1.0f, 0.0f));
|
||||||
|
A.push_back(glm::vec2(0.5f, 0.7f));
|
||||||
|
A.push_back(glm::vec2(0.1f, 0.2f));
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < A.size(); ++i)
|
||||||
|
{
|
||||||
|
glm::vec2 B(A[i]);
|
||||||
|
glm::uint32 C = glm::packUnorm2x16(B);
|
||||||
|
glm::vec2 D = glm::unpackUnorm2x16(C);
|
||||||
|
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
|
||||||
|
assert(!Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_packSnorm2x16()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
std::vector<glm::vec2> A;
|
||||||
|
A.push_back(glm::vec2( 1.0f, 0.0f));
|
||||||
|
A.push_back(glm::vec2(-0.5f,-0.7f));
|
||||||
|
A.push_back(glm::vec2(-0.1f, 0.1f));
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < A.size(); ++i)
|
||||||
|
{
|
||||||
|
glm::vec2 B(A[i]);
|
||||||
|
glm::uint32 C = glm::packSnorm2x16(B);
|
||||||
|
glm::vec2 D = glm::unpackSnorm2x16(C);
|
||||||
|
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
|
||||||
|
assert(!Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_packUnorm4x16()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
std::vector<glm::vec4> A;
|
||||||
|
A.push_back(glm::vec4(1.0f));
|
||||||
|
A.push_back(glm::vec4(0.5f));
|
||||||
|
A.push_back(glm::vec4(0.1f));
|
||||||
|
A.push_back(glm::vec4(0.0f));
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < A.size(); ++i)
|
||||||
|
{
|
||||||
|
glm::vec4 B(A[i]);
|
||||||
|
glm::uint64 C = glm::packUnorm4x16(B);
|
||||||
|
glm::vec4 D(glm::unpackUnorm4x16(C));
|
||||||
|
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 65535.f)) ? 0 : 1;
|
||||||
|
assert(!Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_packSnorm4x16()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
std::vector<glm::vec4> A;
|
||||||
|
A.push_back(glm::vec4( 1.0f, 0.0f, -0.5f, 0.5f));
|
||||||
|
A.push_back(glm::vec4(-0.3f,-0.7f, 0.3f, 0.7f));
|
||||||
|
A.push_back(glm::vec4(-0.1f, 0.1f, -0.2f, 0.2f));
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < A.size(); ++i)
|
||||||
|
{
|
||||||
|
glm::vec4 B(A[i]);
|
||||||
|
glm::uint64 C = glm::packSnorm4x16(B);
|
||||||
|
glm::vec4 D(glm::unpackSnorm4x16(C));
|
||||||
|
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 32767.0f * 2.0f)) ? 0 : 1;
|
||||||
|
assert(!Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_packUnorm1x8()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
std::vector<glm::vec1> A;
|
||||||
|
A.push_back(glm::vec1(1.0f));
|
||||||
|
A.push_back(glm::vec1(0.5f));
|
||||||
|
A.push_back(glm::vec1(0.0f));
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < A.size(); ++i)
|
||||||
|
{
|
||||||
|
glm::vec1 B(A[i]);
|
||||||
|
glm::uint16 C = glm::packUnorm1x8(B.x);
|
||||||
|
glm::vec1 D(glm::unpackUnorm1x8(C));
|
||||||
|
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
|
||||||
|
assert(!Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_packSnorm1x8()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
std::vector<glm::vec1> A;
|
||||||
|
A.push_back(glm::vec1( 1.0f));
|
||||||
|
A.push_back(glm::vec1(-0.7f));
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < A.size(); ++i)
|
||||||
|
{
|
||||||
|
glm::vec1 B(A[i]);
|
||||||
|
glm::uint16 C = glm::packSnorm1x8(B.x);
|
||||||
|
glm::vec1 D(glm::unpackSnorm1x8(C));
|
||||||
|
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_packUnorm2x8()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
std::vector<glm::vec2> A;
|
||||||
|
A.push_back(glm::vec2(1.0f, 0.7f));
|
||||||
|
A.push_back(glm::vec2(0.5f, 0.1f));
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < A.size(); ++i)
|
||||||
|
{
|
||||||
|
glm::vec2 B(A[i]);
|
||||||
|
glm::uint16 C = glm::packUnorm2x8(B);
|
||||||
|
glm::vec2 D = glm::unpackUnorm2x8(C);
|
||||||
|
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
|
||||||
|
assert(!Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_packSnorm2x8()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
std::vector<glm::vec2> A;
|
||||||
|
A.push_back(glm::vec2( 1.0f, 0.0f));
|
||||||
|
A.push_back(glm::vec2(-0.7f,-0.1f));
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < A.size(); ++i)
|
||||||
|
{
|
||||||
|
glm::vec2 B(A[i]);
|
||||||
|
glm::uint16 C = glm::packSnorm2x8(B);
|
||||||
|
glm::vec2 D = glm::unpackSnorm2x8(C);
|
||||||
|
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_packUnorm4x8()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
std::vector<glm::vec4> A;
|
||||||
|
A.push_back(glm::vec4(1.0f, 0.7f, 0.3f, 0.0f));
|
||||||
|
A.push_back(glm::vec4(0.5f, 0.1f, 0.2f, 0.3f));
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < A.size(); ++i)
|
||||||
|
{
|
||||||
|
glm::vec4 B(A[i]);
|
||||||
|
glm::uint32 C = glm::packUnorm4x8(B);
|
||||||
|
glm::vec4 D = glm::unpackUnorm4x8(C);
|
||||||
|
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 255.f)) ? 0 : 1;
|
||||||
|
assert(!Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_packSnorm4x8()
|
||||||
|
{
|
||||||
|
int Error = 0;
|
||||||
|
|
||||||
|
std::vector<glm::vec4> A;
|
||||||
|
A.push_back(glm::vec4( 1.0f, 0.0f,-0.5f,-1.0f));
|
||||||
|
A.push_back(glm::vec4(-0.7f,-0.1f, 0.1f, 0.7f));
|
||||||
|
|
||||||
|
for(std::size_t i = 0; i < A.size(); ++i)
|
||||||
|
{
|
||||||
|
glm::vec4 B(A[i]);
|
||||||
|
glm::uint32 C = glm::packSnorm4x8(B);
|
||||||
|
glm::vec4 D = glm::unpackSnorm4x8(C);
|
||||||
|
Error += glm::all(glm::epsilonEqual(B, D, 1.0f / 127.f)) ? 0 : 1;
|
||||||
|
assert(!Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Error;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int Error(0);
|
int Error(0);
|
||||||
|
|
||||||
|
Error += test_packSnorm1x16();
|
||||||
|
Error += test_packSnorm2x16();
|
||||||
|
Error += test_packSnorm4x16();
|
||||||
|
|
||||||
|
Error += test_packSnorm1x8();
|
||||||
|
Error += test_packSnorm2x8();
|
||||||
|
Error += test_packSnorm4x8();
|
||||||
|
|
||||||
|
Error += test_packUnorm1x16();
|
||||||
|
Error += test_packUnorm2x16();
|
||||||
|
Error += test_packUnorm4x16();
|
||||||
|
|
||||||
|
Error += test_packUnorm1x8();
|
||||||
|
Error += test_packUnorm2x8();
|
||||||
|
Error += test_packUnorm4x8();
|
||||||
|
|
||||||
Error += test_F2x11_1x10();
|
Error += test_F2x11_1x10();
|
||||||
Error += test_Snorm3x10_1x2();
|
Error += test_Snorm3x10_1x2();
|
||||||
Error += test_Unorm3x10_1x2();
|
Error += test_Unorm3x10_1x2();
|
||||||
|
Loading…
Reference in New Issue
Block a user