packing function clean up #292

This commit is contained in:
Christophe Riccio 2015-01-09 23:57:22 +01:00
parent d9290d7887
commit 0ceb9e9394
3 changed files with 24 additions and 29 deletions

View File

@ -111,7 +111,7 @@ namespace glm
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm2x16.xml">GLSL unpackUnorm2x16 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 vec2 unpackUnorm2x16(uint const & p);
GLM_FUNC_DECL vec2 unpackUnorm2x16(uint p);
/// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers.
/// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
@ -124,7 +124,7 @@ namespace glm
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm2x16.xml">GLSL unpackSnorm2x16 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 vec2 unpackSnorm2x16(uint const & p);
GLM_FUNC_DECL vec2 unpackSnorm2x16(uint p);
/// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers.
/// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
@ -137,7 +137,7 @@ namespace glm
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackUnorm4x8.xml">GLSL unpackUnorm4x8 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 unpackUnorm4x8(uint const & p);
GLM_FUNC_DECL vec4 unpackUnorm4x8(uint p);
/// First, unpacks a single 32-bit unsigned integer p into a pair of 16-bit unsigned integers, four 8-bit unsigned integers, or four 8-bit signed integers.
/// Then, each component is converted to a normalized floating-point value to generate the returned two- or four-component vector.
@ -150,7 +150,7 @@ namespace glm
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm4x8.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 unpackSnorm4x8(uint const & p);
GLM_FUNC_DECL vec4 unpackSnorm4x8(uint p);
/// Returns a double-precision value obtained by packing the components of v into a 64-bit value.
/// If an IEEE 754 Inf or NaN is created, it will not signal, and the resulting floating point value is unspecified.
@ -169,7 +169,7 @@ namespace glm
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackDouble2x32.xml">GLSL unpackDouble2x32 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 uvec2 unpackDouble2x32(double const & v);
GLM_FUNC_DECL uvec2 unpackDouble2x32(double v);
/// Returns an unsigned integer obtained by converting the components of a two-component floating-point vector
/// to the 16-bit floating-point representation found in the OpenGL Specification,
@ -189,7 +189,7 @@ namespace glm
///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackHalf2x16.xml">GLSL unpackHalf2x16 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 vec2 unpackHalf2x16(uint const & v);
GLM_FUNC_DECL vec2 unpackHalf2x16(uint v);
/// @}
}//namespace glm

View File

@ -38,13 +38,11 @@ namespace glm
{
GLM_FUNC_QUALIFIER uint packUnorm2x16(vec2 const & v)
{
u16vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 65535.0f));
// return reinterpret_cast<uint&>(Topack);
uint* ptr(reinterpret_cast<uint*>(&Topack));
return *ptr;
u16vec2 const Topack(round(clamp(v, 0.0f, 1.0f) * 65535.0f));
return reinterpret_cast<uint const &>(Topack);
}
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x16(uint const & p)
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x16(uint p)
{
vec2 Unpack(reinterpret_cast<u16vec2 const &>(p));
return Unpack * float(1.5259021896696421759365224689097e-5); // 1.0 / 65535.0
@ -56,7 +54,7 @@ namespace glm
return reinterpret_cast<uint const &>(Topack);
}
GLM_FUNC_QUALIFIER vec2 unpackSnorm2x16(uint const & p)
GLM_FUNC_QUALIFIER vec2 unpackSnorm2x16(uint p)
{
vec2 const Unpack(reinterpret_cast<i16vec2 const &>(p));
return clamp(
@ -70,7 +68,7 @@ namespace glm
return reinterpret_cast<uint const &>(Topack);
}
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x8(uint const & p)
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x8(uint p)
{
vec4 const Unpack(reinterpret_cast<u8vec4 const&>(p));
return Unpack * float(0.0039215686274509803921568627451); // 1 / 255
@ -78,13 +76,13 @@ namespace glm
GLM_FUNC_QUALIFIER uint packSnorm4x8(vec4 const & v)
{
i8vec4 Topack(round(clamp(v ,-1.0f, 1.0f) * 127.0f));
return reinterpret_cast<uint&>(Topack);
i8vec4 const Topack(round(clamp(v ,-1.0f, 1.0f) * 127.0f));
return reinterpret_cast<uint const &>(Topack);
}
GLM_FUNC_QUALIFIER glm::vec4 unpackSnorm4x8(uint const & p)
GLM_FUNC_QUALIFIER glm::vec4 unpackSnorm4x8(uint p)
{
vec4 Unpack(reinterpret_cast<i8vec4 const &>(p));
vec4 const Unpack(reinterpret_cast<i8vec4 const &>(p));
return clamp(
Unpack * 0.0078740157480315f, // 1.0f / 127.0f
-1.0f, 1.0f);
@ -95,24 +93,23 @@ namespace glm
return reinterpret_cast<double const &>(v);
}
GLM_FUNC_QUALIFIER uvec2 unpackDouble2x32(double const & v)
GLM_FUNC_QUALIFIER uvec2 unpackDouble2x32(double v)
{
return reinterpret_cast<uvec2 const &>(v);
}
GLM_FUNC_QUALIFIER uint packHalf2x16(vec2 const & v)
{
i16vec2 Unpack(
i16vec2 const Unpack(
detail::toFloat16(v.x),
detail::toFloat16(v.y));
uint * Result = reinterpret_cast<uint*>(&Unpack);
return *Result;
return reinterpret_cast<uint const &>(Unpack);
}
GLM_FUNC_QUALIFIER vec2 unpackHalf2x16(uint const & v)
GLM_FUNC_QUALIFIER vec2 unpackHalf2x16(uint v)
{
i16vec2 Unpack(reinterpret_cast<i16vec2 const &>(v));
i16vec2 const Unpack(reinterpret_cast<i16vec2 const &>(v));
return vec2(
detail::toFloat32(Unpack.x),

View File

@ -263,7 +263,7 @@ namespace detail
GLM_FUNC_QUALIFIER uint16 packUnorm2x8(vec2 const & v)
{
u8vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 255.0f));
u8vec2 const Topack(round(clamp(v, 0.0f, 1.0f) * 255.0f));
return reinterpret_cast<uint16 const &>(Topack);
}
@ -354,15 +354,13 @@ namespace detail
GLM_FUNC_QUALIFIER uint16 packHalf1x16(float v)
{
int16 Topack = detail::toFloat16(v);
uint16* Packed = reinterpret_cast<uint16*>(&Topack);
return *Packed;
int16 const Topack(detail::toFloat16(v));
return reinterpret_cast<uint16 const &>(Topack);
}
GLM_FUNC_QUALIFIER float unpackHalf1x16(uint16 v)
{
int16* Unpack = reinterpret_cast<int16*>(const_cast<uint16*>(&v));
return detail::toFloat32(*Unpack);
return detail::toFloat32(reinterpret_cast<int16 const &>(v));
}
GLM_FUNC_QUALIFIER uint64 packHalf4x16(glm::vec4 const & v)