Fixed GTC_packing *pack*norm*x* build and added tests #292
This commit is contained in:
@@ -283,7 +283,7 @@ namespace glm
|
||||
/// @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/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
|
||||
/// 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)
|
||||
{
|
||||
float Unpack(static_cast<float>(p));
|
||||
float const Unpack(p);
|
||||
return Unpack * static_cast<float>(0.0039215686274509803921568627451); // 1 / 255
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint16 packUnorm2x8(vec2 const & v)
|
||||
{
|
||||
u8vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 255.0f));
|
||||
uint16* Packed = reinterpret_cast<uint16*>(&Topack);
|
||||
return *Packed;
|
||||
return reinterpret_cast<uint16 const &>(Topack);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p)
|
||||
{
|
||||
u8vec2* Unpacked = reinterpret_cast<u8vec2*>(const_cast<uint16*>(&p));
|
||||
return vec2(*Unpacked) * float(0.0039215686274509803921568627451); // 1 / 255
|
||||
vec2 const Unpack(reinterpret_cast<u8vec2 const &>(p));
|
||||
return Unpack * float(0.0039215686274509803921568627451); // 1 / 255
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint8 packSnorm1x8(float v)
|
||||
{
|
||||
int8 Topack(static_cast<int8>(round(clamp(v ,-1.0f, 1.0f) * 127.0f)));
|
||||
uint8* Packed = reinterpret_cast<uint8*>(&Topack);
|
||||
return *Packed;
|
||||
int8 const Topack(static_cast<int8>(round(clamp(v ,-1.0f, 1.0f) * 127.0f)));
|
||||
return reinterpret_cast<uint8 const &>(Topack);
|
||||
}
|
||||
|
||||
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(
|
||||
Unpack * 0.00787401574803149606299212598425f, // 1.0f / 127.0f
|
||||
-1.0f, 1.0f);
|
||||
@@ -291,16 +289,15 @@ namespace detail
|
||||
|
||||
GLM_FUNC_QUALIFIER uint16 packSnorm2x8(vec2 const & v)
|
||||
{
|
||||
i8vec2 Topack(round(clamp(v ,-1.0f, 1.0f) * 127.0f));
|
||||
uint16* Packed = reinterpret_cast<uint16*>(&Topack);
|
||||
return *Packed;
|
||||
i8vec2 const Topack(round(clamp(v, -1.0f, 1.0f) * 127.0f));
|
||||
return reinterpret_cast<uint16 const &>(Topack);
|
||||
}
|
||||
|
||||
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(
|
||||
vec2(*Unpack) * 0.00787401574803149606299212598425f, // 1.0f / 127.0f
|
||||
Unpack * 0.00787401574803149606299212598425f, // 1.0f / 127.0f
|
||||
-1.0f, 1.0f);
|
||||
}
|
||||
|
||||
@@ -311,33 +308,31 @@ namespace detail
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint64 packUnorm4x16(vec4 const & v)
|
||||
{
|
||||
u16vec4 Topack(round(clamp(v , 0.0f, 1.0f) * 65535.0f));
|
||||
uint64* Packed = reinterpret_cast<uint64*>(&Topack);
|
||||
return *Packed;
|
||||
u16vec4 const Topack(round(clamp(v , 0.0f, 1.0f) * 65535.0f));
|
||||
return reinterpret_cast<uint64 const &>(Topack);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x16(uint64 p)
|
||||
{
|
||||
u16vec4* Unpack = reinterpret_cast<u16vec4*>(const_cast<uint64*>(&p));
|
||||
return vec4(*Unpack) * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0
|
||||
vec4 const Unpack(reinterpret_cast<u16vec4 const &>(p));
|
||||
return Unpack * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint16 packSnorm1x16(float v)
|
||||
{
|
||||
int16 Topack = static_cast<int16>(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
|
||||
uint16* Packed = reinterpret_cast<uint16*>(&Topack);
|
||||
return *Packed;
|
||||
int16 const Topack = static_cast<int16>(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
|
||||
return reinterpret_cast<uint16 const &>(Topack);
|
||||
}
|
||||
|
||||
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(
|
||||
Unpack * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
|
||||
-1.0f, 1.0f);
|
||||
@@ -345,16 +340,15 @@ namespace detail
|
||||
|
||||
GLM_FUNC_QUALIFIER uint64 packSnorm4x16(vec4 const & v)
|
||||
{
|
||||
i16vec4 Topack = static_cast<i16vec4>(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
|
||||
uint64* Packed = reinterpret_cast<uint64*>(&Topack);
|
||||
return *Packed;
|
||||
i16vec4 const Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
|
||||
return reinterpret_cast<uint64 const &>(Topack);
|
||||
}
|
||||
|
||||
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(
|
||||
vec4(*Unpack) * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
|
||||
Unpack * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
|
||||
-1.0f, 1.0f);
|
||||
}
|
||||
|
||||
@@ -379,19 +373,17 @@ namespace detail
|
||||
detail::toFloat16(v.z),
|
||||
detail::toFloat16(v.w));
|
||||
|
||||
uint64* Packed = reinterpret_cast<uint64*>(&Unpack);
|
||||
return *Packed;
|
||||
return reinterpret_cast<uint64 const &>(Unpack);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER glm::vec4 unpackHalf4x16(uint64 v)
|
||||
{
|
||||
i16vec4* p = reinterpret_cast<i16vec4*>(const_cast<uint64*>(&v));
|
||||
i16vec4 Unpack(*p);
|
||||
i16vec4 Unpack(reinterpret_cast<i16vec4 const &>(v));
|
||||
|
||||
return vec4(
|
||||
detail::toFloat32(Unpack.x),
|
||||
detail::toFloat32(Unpack.y),
|
||||
detail::toFloat32(Unpack.z),
|
||||
detail::toFloat32(Unpack.x),
|
||||
detail::toFloat32(Unpack.y),
|
||||
detail::toFloat32(Unpack.z),
|
||||
detail::toFloat32(Unpack.w));
|
||||
}
|
||||
|
||||
@@ -483,7 +475,7 @@ namespace detail
|
||||
|
||||
GLM_FUNC_QUALIFIER uint32 packF2x11_1x10(vec3 const & v)
|
||||
{
|
||||
return
|
||||
return
|
||||
((detail::floatTo11bit(v.x) & ((1 << 11) - 1)) << 0) |
|
||||
((detail::floatTo11bit(v.y) & ((1 << 11) - 1)) << 11) |
|
||||
((detail::floatTo10bit(v.z) & ((1 << 10) - 1)) << 22);
|
||||
@@ -492,8 +484,8 @@ namespace detail
|
||||
GLM_FUNC_QUALIFIER vec3 unpackF2x11_1x10(uint32 v)
|
||||
{
|
||||
return vec3(
|
||||
detail::packed11bitToFloat(v >> 0),
|
||||
detail::packed11bitToFloat(v >> 11),
|
||||
detail::packed11bitToFloat(v >> 0),
|
||||
detail::packed11bitToFloat(v >> 11),
|
||||
detail::packed10bitToFloat(v >> 22));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user