mirror of
https://github.com/g-truc/glm.git
synced 2024-11-26 18:24:35 +00:00
Added 1x8 packing functions. Add documentation for half packing functions.
This commit is contained in:
parent
79822f932d
commit
53bd892a88
@ -51,43 +51,72 @@ namespace glm
|
||||
/// @addtogroup gtc_packing
|
||||
/// @{
|
||||
|
||||
GLM_FUNC_DECL uint8 packUnorm1x8(float const & v);
|
||||
GLM_FUNC_DECL float unpackUnorm1x8(uint8 v);
|
||||
|
||||
GLM_FUNC_DECL uint16 packUnorm2x8(vec2 const & v);
|
||||
GLM_FUNC_DECL vec2 unpackUnorm2x8(uint16 v);
|
||||
|
||||
|
||||
GLM_FUNC_DECL uint8 packSnorm1x8(float const & v);
|
||||
GLM_FUNC_DECL float unpackSnorm1x8(uint8 v);
|
||||
|
||||
GLM_FUNC_DECL uint16 packSnorm2x8(vec2 const & v);
|
||||
GLM_FUNC_DECL vec2 unpackSnorm2x8(uint16 v);
|
||||
|
||||
|
||||
GLM_FUNC_DECL uint16 packUnorm1x16(float v);
|
||||
GLM_FUNC_DECL float unpackUnorm1x16(uint16 v);
|
||||
|
||||
GLM_FUNC_DECL uint64 packUnorm4x16(vec4 const & v);
|
||||
GLM_FUNC_DECL vec4 unpackUnorm4x16(uint64 const & v);
|
||||
|
||||
|
||||
GLM_FUNC_DECL uint16 packSnorm1x16(float v);
|
||||
GLM_FUNC_DECL float unpackSnorm1x16(uint16 v);
|
||||
|
||||
GLM_FUNC_DECL uint64 packSnorm4x16(vec4 const & v);
|
||||
GLM_FUNC_DECL vec4 unpackSnorm4x16(uint64 const & v);
|
||||
|
||||
GLM_FUNC_DECL uint16 packUnorm2x8(vec2 const & v);
|
||||
GLM_FUNC_DECL vec2 unpackUnorm2x8(uint16 v);
|
||||
|
||||
GLM_FUNC_DECL uint16 packSnorm2x8(vec2 const & v);
|
||||
GLM_FUNC_DECL vec2 unpackSnorm2x8(uint16 v);
|
||||
|
||||
|
||||
/// 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,
|
||||
/// and then packing this 16-bit value into a 16-bit unsigned integer.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint32 packHalf2x16(vec2 const & v)
|
||||
/// @see uint64 packHalf4x16(vec4 const & v)
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packHalf2x16.xml">GLSL packHalf2x16 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 uint16 packHalf1x16(float const & v);
|
||||
|
||||
/// Returns a floating-point scalar with components obtained by unpacking a 16-bit unsigned integer into a 16-bit value,
|
||||
/// interpreted as a 16-bit floating-point number according to the OpenGL Specification,
|
||||
/// and converting it to 32-bit floating-point values.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @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 float unpackHalf1x16(uint16 const & v);
|
||||
|
||||
/// Returns an unsigned integer obtained by converting the components of a two-component floating-point vector
|
||||
/// Returns an unsigned integer obtained by converting the components of a four-component floating-point vector
|
||||
/// to the 16-bit floating-point representation found in the OpenGL Specification,
|
||||
/// and then packing these two 16- bit integers into a 32-bit unsigned integer.
|
||||
/// and then packing these four 16-bit values into a 64-bit unsigned integer.
|
||||
/// The first vector component specifies the 16 least-significant bits of the result;
|
||||
/// the second component specifies the 16 most-significant bits.
|
||||
/// the forth component specifies the 16 most-significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint16 packHalf1x16(float const & v)
|
||||
/// @see uint32 packHalf2x16(vec2 const & v)
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packHalf2x16.xml">GLSL packHalf2x16 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 uint64 packHalf4x16(vec4 const & v);
|
||||
|
||||
/// Returns a two-component floating-point vector with components obtained by unpacking a 32-bit unsigned integer into a pair of 16-bit values,
|
||||
/// Returns a four-component floating-point vector with components obtained by unpacking a 64-bit unsigned integer into four 16-bit values,
|
||||
/// interpreting those values as 16-bit floating-point numbers according to the OpenGL Specification,
|
||||
/// and converting them to 32-bit floating-point values.
|
||||
/// The first component of the vector is obtained from the 16 least-significant bits of v;
|
||||
/// the second component is obtained from the 16 most-significant bits of v.
|
||||
/// the forth component is obtained from the 16 most-significant bits of v.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackHalf2x16.xml">GLSL unpackHalf2x16 man page</a>
|
||||
|
@ -26,8 +26,7 @@
|
||||
/// @author Christophe Riccio
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace glm
|
||||
{
|
||||
namespace glm{
|
||||
namespace detail
|
||||
{
|
||||
glm::uint16 float2half(glm::uint32 const & f)
|
||||
@ -191,6 +190,13 @@ namespace detail
|
||||
uint16 pack;
|
||||
};
|
||||
|
||||
|
||||
union unorm1x8
|
||||
{
|
||||
uint8 data;
|
||||
uint8 pack;
|
||||
};
|
||||
|
||||
union unorm2x8
|
||||
{
|
||||
struct
|
||||
@ -201,6 +207,12 @@ namespace detail
|
||||
uint16 pack;
|
||||
};
|
||||
|
||||
union snorm1x8
|
||||
{
|
||||
int8 data;
|
||||
uint8 pack;
|
||||
};
|
||||
|
||||
union snorm2x8
|
||||
{
|
||||
struct
|
||||
@ -212,6 +224,73 @@ namespace detail
|
||||
};
|
||||
}//namespace detail
|
||||
|
||||
|
||||
GLM_FUNC_QUALIFIER uint8 packUnorm1x8(float const & v)
|
||||
{
|
||||
int8 Scaled(round(clamp(v ,-1.0f, 1.0f) * 255.0f));
|
||||
detail::unorm1x8 Packing;
|
||||
Packing.data = Scaled;
|
||||
return Packing.pack;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER float unpackUnorm1x8(uint8 p)
|
||||
{
|
||||
detail::unorm1x8 Packing;
|
||||
Packing.pack = p;
|
||||
float Unpacked(Packing.data);
|
||||
return Unpacked * float(0.0039215686274509803921568627451);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint16 packUnorm2x8(vec2 const & v)
|
||||
{
|
||||
i8vec2 Scaled(round(clamp(v ,-1.0f, 1.0f) * 255.0f));
|
||||
detail::unorm2x8 Packing;
|
||||
Packing.data.x = Scaled.x;
|
||||
Packing.data.y = Scaled.y;
|
||||
return Packing.pack;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p)
|
||||
{
|
||||
detail::unorm2x8 Packing;
|
||||
Packing.pack = p;
|
||||
vec2 Unpacked(Packing.data.x, Packing.data.y);
|
||||
return Unpacked * float(0.0039215686274509803921568627451);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint8 packSnorm1x8(float const & v)
|
||||
{
|
||||
glm::int8 Scaled(round(clamp(v ,-1.0f, 1.0f) * 127.0f));
|
||||
detail::snorm1x8 Packing;
|
||||
Packing.x = Scaled.x;
|
||||
return Packing.pack;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER float unpackSnorm1x8(uint8 p)
|
||||
{
|
||||
detail::snorm1x8 Packing;
|
||||
Packing.pack = p;
|
||||
float Unpacked(Packing.data);
|
||||
return clamp(Unpacked * float(0.00787401574803149606299212598425), -1.0f, 1.0f);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint16 packSnorm2x8(vec2 const & v)
|
||||
{
|
||||
glm::i8vec2 Scaled(round(clamp(v ,-1.0f, 1.0f) * 127.0f));
|
||||
detail::snorm2x8 Packing;
|
||||
Packing.data.x = Scaled.x;
|
||||
Packing.data.y = Scaled.y;
|
||||
return Packing.pack;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p)
|
||||
{
|
||||
detail::snorm2x8 Packing;
|
||||
Packing.pack = p;
|
||||
vec2 Unpacked(Packing.data.x, Packing.data.y);
|
||||
return clamp(Unpacked * float(0.00787401574803149606299212598425), -1.0f, 1.0f);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint16 packUnorm1x16(float s)
|
||||
{
|
||||
return uint16(round(clamp(s, 0.0f, 1.0f) * 65535.0f));
|
||||
@ -278,40 +357,6 @@ namespace detail
|
||||
return clamp(Unpacked * float(3.0518509475997192297128208258309e-5), -1.0f, 1.0f); //1.0f / 32767.0f
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint16 packUnorm2x8(vec2 const & v)
|
||||
{
|
||||
i8vec2 Scaled(round(clamp(v ,-1.0f, 1.0f) * 255.0f));
|
||||
detail::unorm2x8 Packing;
|
||||
Packing.data.x = Scaled.x;
|
||||
Packing.data.y = Scaled.y;
|
||||
return Packing.pack;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 p)
|
||||
{
|
||||
detail::unorm2x8 Packing;
|
||||
Packing.pack = p;
|
||||
vec2 Unpacked(Packing.data.x, Packing.data.y);
|
||||
return Unpacked * float(0.0039215686274509803921568627451);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint16 packSnorm2x8(vec2 const & v)
|
||||
{
|
||||
glm::i8vec2 Scaled(round(clamp(v ,-1.0f, 1.0f) * 127.0f));
|
||||
detail::snorm2x8 Packing;
|
||||
Packing.data.x = Scaled.x;
|
||||
Packing.data.y = Scaled.y;
|
||||
return Packing.pack;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 p)
|
||||
{
|
||||
detail::snorm2x8 Packing;
|
||||
Packing.pack = p;
|
||||
vec2 Unpacked(Packing.data.x, Packing.data.y);
|
||||
return clamp(Unpacked * float(0.00787401574803149606299212598425), -1.0f, 1.0f);
|
||||
}
|
||||
|
||||
GLM_FUNC_DECL uint16 packHalf1x16(float const & v)
|
||||
{
|
||||
detail::half1x16 Packing;
|
||||
|
Loading…
Reference in New Issue
Block a user