mirror of
https://github.com/g-truc/glm.git
synced 2024-11-30 03:44:38 +00:00
Fixed merge
This commit is contained in:
commit
0464c836cb
@ -41,80 +41,80 @@ namespace glm
|
||||
/// @addtogroup core_func_packing
|
||||
/// @{
|
||||
|
||||
//! First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
|
||||
//! Then, the results are packed into the returned 32-bit unsigned integer.
|
||||
//!
|
||||
//! The conversion for component c of v to fixed point is done as follows:
|
||||
//! packUnorm2x16: round(clamp(c, 0, +1) * 65535.0)
|
||||
//!
|
||||
//! The first component of the vector will be written to the least significant bits of the output;
|
||||
//! the last component will be written to the most significant bits.
|
||||
//!
|
||||
/// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
|
||||
/// Then, the results are packed into the returned 32-bit unsigned integer.
|
||||
///
|
||||
/// The conversion for component c of v to fixed point is done as follows:
|
||||
/// packUnorm2x16: round(clamp(c, 0, +1) * 65535.0)
|
||||
///
|
||||
/// The first component of the vector will be written to the least significant bits of the output;
|
||||
/// the last component will be written to the most significant bits.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm2x16.xml">GLSL packUnorm2x16 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 uint32 packUnorm2x16(vec2 const & v);
|
||||
|
||||
//! First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
|
||||
//! Then, the results are packed into the returned 32-bit unsigned integer.
|
||||
//!
|
||||
//! The conversion for component c of v to fixed point is done as follows:
|
||||
//! packSnorm2x16: round(clamp(v, -1, +1) * 32767.0)
|
||||
//!
|
||||
//! The first component of the vector will be written to the least significant bits of the output;
|
||||
//! the last component will be written to the most significant bits.
|
||||
//!
|
||||
/// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
|
||||
/// Then, the results are packed into the returned 32-bit unsigned integer.
|
||||
///
|
||||
/// The conversion for component c of v to fixed point is done as follows:
|
||||
/// packSnorm2x16: round(clamp(v, -1, +1) * 32767.0)
|
||||
///
|
||||
/// The first component of the vector will be written to the least significant bits of the output;
|
||||
/// the last component will be written to the most significant bits.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm2x16.xml">GLSL packSnorm2x16 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 uint32 packSnorm2x16(vec2 const & v);
|
||||
|
||||
//! First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
|
||||
//! Then, the results are packed into the returned 32-bit unsigned integer.
|
||||
//!
|
||||
//! The conversion for component c of v to fixed point is done as follows:
|
||||
//! packUnorm4x8: round(clamp(c, 0, +1) * 255.0)
|
||||
//!
|
||||
//! The first component of the vector will be written to the least significant bits of the output;
|
||||
//! the last component will be written to the most significant bits.
|
||||
//!
|
||||
/// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
|
||||
/// Then, the results are packed into the returned 32-bit unsigned integer.
|
||||
///
|
||||
/// The conversion for component c of v to fixed point is done as follows:
|
||||
/// packUnorm4x8: round(clamp(c, 0, +1) * 255.0)
|
||||
///
|
||||
/// The first component of the vector will be written to the least significant bits of the output;
|
||||
/// the last component will be written to the most significant bits.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm4x8.xml">GLSL packUnorm4x8 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 uint32 packUnorm4x8(vec4 const & v);
|
||||
|
||||
//! First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
|
||||
//! Then, the results are packed into the returned 32-bit unsigned integer.
|
||||
//!
|
||||
//! The conversion for component c of v to fixed point is done as follows:
|
||||
//! packSnorm4x8: round(clamp(c, -1, +1) * 127.0)
|
||||
//!
|
||||
//! The first component of the vector will be written to the least significant bits of the output;
|
||||
//! the last component will be written to the most significant bits.
|
||||
//!
|
||||
/// First, converts each component of the normalized floating-point value v into 8- or 16-bit integer values.
|
||||
/// Then, the results are packed into the returned 32-bit unsigned integer.
|
||||
///
|
||||
/// The conversion for component c of v to fixed point is done as follows:
|
||||
/// packSnorm4x8: round(clamp(c, -1, +1) * 127.0)
|
||||
///
|
||||
/// The first component of the vector will be written to the least significant bits of the output;
|
||||
/// the last component will be written to the most significant bits.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm4x8.xml">GLSL packSnorm4x8 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 uint32 packSnorm4x8(vec4 const & v);
|
||||
|
||||
//! 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.
|
||||
//!
|
||||
//! The conversion for unpacked fixed-point value f to floating point is done as follows:
|
||||
//! unpackUnorm2x16: f / 65535.0
|
||||
//!
|
||||
//! The first component of the returned vector will be extracted from the least significant bits of the input;
|
||||
//! the last component will be extracted from the most significant bits.
|
||||
//!
|
||||
/// 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.
|
||||
///
|
||||
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
|
||||
/// unpackUnorm2x16: f / 65535.0
|
||||
///
|
||||
/// The first component of the returned vector will be extracted from the least significant bits of the input;
|
||||
/// the last component will be extracted from the most significant bits.
|
||||
///
|
||||
/// @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(uint32 const & 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.
|
||||
//!
|
||||
//! The conversion for unpacked fixed-point value f to floating point is done as follows:
|
||||
//! unpackSnorm2x16: clamp(f / 32767.0, -1, +1)
|
||||
//!
|
||||
//! The first component of the returned vector will be extracted from the least significant bits of the input;
|
||||
//! the last component will be extracted from the most significant bits.
|
||||
//!
|
||||
/// 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.
|
||||
///
|
||||
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
|
||||
/// unpackSnorm2x16: clamp(f / 32767.0, -1, +1)
|
||||
///
|
||||
/// The first component of the returned vector will be extracted from the least significant bits of the input;
|
||||
/// the last component will be extracted from the most significant bits.
|
||||
///
|
||||
/// @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(uint32 const & p);
|
||||
|
@ -40,9 +40,7 @@ namespace glm
|
||||
uint32 Mask16((1 << 16) - 1);
|
||||
uint32 A((p >> 0) & Mask16);
|
||||
uint32 B((p >> 16) & Mask16);
|
||||
return vec2(
|
||||
A * 1.0f / 65535.0f,
|
||||
B * 1.0f / 65535.0f);
|
||||
return vec2(A, B) * float(1.5259021896696421759365224689097e-5); // 1.0 / 65535.0
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint32 packSnorm2x16(vec2 const & v)
|
||||
@ -53,9 +51,9 @@ namespace glm
|
||||
uint16 u;
|
||||
} A, B;
|
||||
|
||||
vec2 Unpack = clamp(v ,-1.0f, 1.0f) * 32767.0f;
|
||||
A.i = detail::int16(round(Unpack.x));
|
||||
B.i = detail::int16(round(Unpack.y));
|
||||
vec2 Unpack = round(clamp(v ,-1.0f, 1.0f) * 32767.0f);
|
||||
A.i = detail::int16(Unpack.x);
|
||||
B.i = detail::int16(Unpack.y);
|
||||
uint32 Pack = (uint32(B.u) << 16) | (uint32(A.u) << 0);
|
||||
return Pack;
|
||||
}
|
||||
|
@ -54,8 +54,9 @@ namespace glm
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/lessThan.xml">GLSL lessThan man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL typename vecType<T, P>::bool_type lessThan(vecType<T, P> const & x, vecType<T, P> const & y);
|
||||
// TODO: Mismatched
|
||||
//template <typename T, precision P, template <typename, precision> class vecType>
|
||||
//GLM_FUNC_DECL typename vecType<T, P>::bool_type lessThan(vecType<T, P> const & x, vecType<T, P> const & y);
|
||||
|
||||
/// Returns the component-wise comparison of result x <= y.
|
||||
///
|
||||
@ -90,8 +91,9 @@ namespace glm
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/equal.xml">GLSL equal man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.7 Vector Relational Functions</a>
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL typename vecType<T, P>::bool_type equal(vecType<T, P> const & x, vecType<T, P> const & y);
|
||||
//TODO: conflicts with definision
|
||||
//template <typename T, precision P, template <typename, precision> class vecType>
|
||||
//GLM_FUNC_DECL typename vecType<T, P>::bool_type equal(vecType<T, P> const & x, vecType<T, P> const & y);
|
||||
|
||||
/// Returns the component-wise comparison of result x != y.
|
||||
///
|
||||
|
478
glm/gtc/packing.hpp
Normal file
478
glm/gtc/packing.hpp
Normal file
@ -0,0 +1,478 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
/// OpenGL Mathematics (glm.g-truc.net)
|
||||
///
|
||||
/// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
|
||||
/// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
/// of this software and associated documentation files (the "Software"), to deal
|
||||
/// in the Software without restriction, including without limitation the rights
|
||||
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
/// copies of the Software, and to permit persons to whom the Software is
|
||||
/// furnished to do so, subject to the following conditions:
|
||||
///
|
||||
/// The above copyright notice and this permission notice shall be included in
|
||||
/// all copies or substantial portions of the Software.
|
||||
///
|
||||
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
/// THE SOFTWARE.
|
||||
///
|
||||
/// @ref gtc_packing
|
||||
/// @file glm/gtc/packing.hpp
|
||||
/// @date 2013-08-08 / 2013-08-08
|
||||
/// @author Christophe Riccio
|
||||
///
|
||||
/// @see core (dependence)
|
||||
///
|
||||
/// @defgroup gtc_packing GLM_GTC_packing
|
||||
/// @ingroup gtc
|
||||
///
|
||||
/// @brief This extension provides a set of function to convert vertors to packed
|
||||
/// formats.
|
||||
///
|
||||
/// <glm/gtc/packing.hpp> need to be included to use these features.
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef GLM_GTC_packing
|
||||
#define GLM_GTC_packing GLM_VERSION
|
||||
|
||||
// Dependency:
|
||||
#include "../glm.hpp"
|
||||
|
||||
#if(defined(GLM_MESSAGES) && !defined(glm_ext))
|
||||
# pragma message("GLM: GLM_GTC_packing extension included")
|
||||
#endif
|
||||
|
||||
namespace glm
|
||||
{
|
||||
/// @addtogroup gtc_packing
|
||||
/// @{
|
||||
|
||||
/// First, converts the normalized floating-point value v into a 8-bit integer value.
|
||||
/// Then, the results are packed into the returned 8-bit unsigned integer.
|
||||
///
|
||||
/// The conversion for component c of v to fixed point is done as follows:
|
||||
/// packUnorm1x8: round(clamp(c, 0, +1) * 255.0)
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint16 packUnorm2x8(vec2 const & v)
|
||||
/// @see uint32 packUnorm4x8(vec4 const & v)
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm4x8.xml">GLSL packUnorm4x8 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 uint8 packUnorm1x8(float const & v);
|
||||
|
||||
/// Convert a single 8-bit integer to a normalized floating-point value.
|
||||
///
|
||||
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
|
||||
/// unpackUnorm4x8: f / 255.0
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see vec2 unpackUnorm2x8(uint16 p)
|
||||
/// @see vec4 unpackUnorm4x8(uint32 p)
|
||||
/// @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 float unpackUnorm1x8(uint8 pdf);
|
||||
|
||||
/// First, converts each component of the normalized floating-point value v into 8-bit integer values.
|
||||
/// Then, the results are packed into the returned 16-bit unsigned integer.
|
||||
///
|
||||
/// The conversion for component c of v to fixed point is done as follows:
|
||||
/// packUnorm2x8: round(clamp(c, 0, +1) * 255.0)
|
||||
///
|
||||
/// The first component of the vector will be written to the least significant bits of the output;
|
||||
/// the last component will be written to the most significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint8 packUnorm1x8(float const & v)
|
||||
/// @see uint32 packUnorm4x8(vec4 const & v)
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm4x8.xml">GLSL packUnorm4x8 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 packUnorm2x8(vec2 const & v);
|
||||
|
||||
/// First, unpacks a single 16-bit unsigned integer p into a pair of 8-bit unsigned integers.
|
||||
/// Then, each component is converted to a normalized floating-point value to generate the returned two-component vector.
|
||||
///
|
||||
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
|
||||
/// unpackUnorm4x8: f / 255.0
|
||||
///
|
||||
/// The first component of the returned vector will be extracted from the least significant bits of the input;
|
||||
/// the last component will be extracted from the most significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see float unpackUnorm1x8(uint8 v)
|
||||
/// @see vec4 unpackUnorm4x8(uint32 p)
|
||||
/// @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 vec2 unpackUnorm2x8(uint16 p);
|
||||
|
||||
/// First, converts the normalized floating-point value v into 8-bit integer value.
|
||||
/// Then, the results are packed into the returned 8-bit unsigned integer.
|
||||
///
|
||||
/// The conversion to fixed point is done as follows:
|
||||
/// packSnorm1x8: round(clamp(s, -1, +1) * 127.0)
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint16 packSnorm2x8(vec2 const & v)
|
||||
/// @see uint32 packSnorm4x8(vec4 const & v)
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm4x8.xml">GLSL packSnorm4x8 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 uint8 packSnorm1x8(float const & s);
|
||||
|
||||
/// First, unpacks a single 8-bit unsigned integer p into a single 8-bit signed integers.
|
||||
/// Then, the value is converted to a normalized floating-point value to generate the returned scalar.
|
||||
///
|
||||
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
|
||||
/// unpackSnorm1x8: clamp(f / 127.0, -1, +1)
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see vec2 unpackSnorm2x8(uint16 p)
|
||||
/// @see vec4 unpackSnorm4x8(uint32 p)
|
||||
/// @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 float unpackSnorm1x8(uint8 p);
|
||||
|
||||
/// First, converts each component of the normalized floating-point value v into 8-bit integer values.
|
||||
/// Then, the results are packed into the returned 16-bit unsigned integer.
|
||||
///
|
||||
/// The conversion for component c of v to fixed point is done as follows:
|
||||
/// packSnorm2x8: round(clamp(c, -1, +1) * 127.0)
|
||||
///
|
||||
/// The first component of the vector will be written to the least significant bits of the output;
|
||||
/// the last component will be written to the most significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint8 packSnorm1x8(float const & v)
|
||||
/// @see uint32 packSnorm4x8(vec4 const & v)
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm4x8.xml">GLSL packSnorm4x8 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 packSnorm2x8(vec2 const & v);
|
||||
|
||||
/// First, unpacks a single 16-bit unsigned integer p into a pair of 8-bit signed integers.
|
||||
/// Then, each component is converted to a normalized floating-point value to generate the returned two-component vector.
|
||||
///
|
||||
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
|
||||
/// unpackSnorm2x8: clamp(f / 127.0, -1, +1)
|
||||
///
|
||||
/// The first component of the returned vector will be extracted from the least significant bits of the input;
|
||||
/// the last component will be extracted from the most significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see float unpackSnorm1x8(uint8 p)
|
||||
/// @see vec4 unpackSnorm4x8(uint32 p)
|
||||
/// @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 vec2 unpackSnorm2x8(uint16 p);
|
||||
|
||||
/// First, converts the normalized floating-point value v into a 16-bit integer value.
|
||||
/// Then, the results are packed into the returned 16-bit unsigned integer.
|
||||
///
|
||||
/// The conversion for component c of v to fixed point is done as follows:
|
||||
/// packUnorm1x16: round(clamp(c, 0, +1) * 65535.0)
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint16 packSnorm1x16(float const & v)
|
||||
/// @see uint64 packSnorm4x16(vec4 const & v)
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm4x8.xml">GLSL packUnorm4x8 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 packUnorm1x16(float v);
|
||||
|
||||
/// First, unpacks a single 16-bit unsigned integer p into a of 16-bit unsigned integers.
|
||||
/// Then, the value is converted to a normalized floating-point value to generate the returned scalar.
|
||||
///
|
||||
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
|
||||
/// unpackUnorm1x16: f / 65535.0
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see vec2 unpackUnorm2x16(uint32 p)
|
||||
/// @see vec4 unpackUnorm4x16(uint64 p)
|
||||
/// @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 float unpackUnorm1x16(uint16 p);
|
||||
|
||||
/// First, converts each component of the normalized floating-point value v into 16-bit integer values.
|
||||
/// Then, the results are packed into the returned 64-bit unsigned integer.
|
||||
///
|
||||
/// The conversion for component c of v to fixed point is done as follows:
|
||||
/// packUnorm4x16: round(clamp(c, 0, +1) * 65535.0)
|
||||
///
|
||||
/// The first component of the vector will be written to the least significant bits of the output;
|
||||
/// the last component will be written to the most significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint16 packUnorm1x16(float const & v)
|
||||
/// @see uint32 packUnorm2x16(vec2 const & v)
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packUnorm4x8.xml">GLSL packUnorm4x8 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 packUnorm4x16(vec4 const & v);
|
||||
|
||||
/// First, unpacks a single 64-bit unsigned integer p into four 16-bit unsigned integers.
|
||||
/// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector.
|
||||
///
|
||||
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
|
||||
/// unpackUnormx4x16: f / 65535.0
|
||||
///
|
||||
/// The first component of the returned vector will be extracted from the least significant bits of the input;
|
||||
/// the last component will be extracted from the most significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see float unpackUnorm1x16(uint16 p)
|
||||
/// @see vec2 unpackUnorm2x16(uint32 p)
|
||||
/// @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 vec4 unpackUnorm4x16(uint64 const & p);
|
||||
|
||||
/// First, converts the normalized floating-point value v into 16-bit integer value.
|
||||
/// Then, the results are packed into the returned 16-bit unsigned integer.
|
||||
///
|
||||
/// The conversion to fixed point is done as follows:
|
||||
/// packSnorm1x8: round(clamp(s, -1, +1) * 32767.0)
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint32 packSnorm2x16(vec2 const & v)
|
||||
/// @see uint64 packSnorm4x16(vec4 const & v)
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm4x8.xml">GLSL packSnorm4x8 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 packSnorm1x16(float v);
|
||||
|
||||
/// First, unpacks a single 16-bit unsigned integer p into a single 16-bit signed integers.
|
||||
/// Then, each component is converted to a normalized floating-point value to generate the returned scalar.
|
||||
///
|
||||
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
|
||||
/// unpackSnorm1x16: clamp(f / 32767.0, -1, +1)
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see vec2 unpackSnorm2x16(uint32 p)
|
||||
/// @see vec4 unpackSnorm4x16(uint64 p)
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/unpackSnorm1x16.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 float unpackSnorm1x16(uint16 p);
|
||||
|
||||
/// First, converts each component of the normalized floating-point value v into 16-bit integer values.
|
||||
/// Then, the results are packed into the returned 64-bit unsigned integer.
|
||||
///
|
||||
/// The conversion for component c of v to fixed point is done as follows:
|
||||
/// packSnorm2x8: round(clamp(c, -1, +1) * 32767.0)
|
||||
///
|
||||
/// The first component of the vector will be written to the least significant bits of the output;
|
||||
/// the last component will be written to the most significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint16 packSnorm1x16(float const & v)
|
||||
/// @see uint32 packSnorm2x16(vec2 const & v)
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/packSnorm4x8.xml">GLSL packSnorm4x8 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 packSnorm4x16(vec4 const & v);
|
||||
|
||||
/// First, unpacks a single 64-bit unsigned integer p into four 16-bit signed integers.
|
||||
/// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector.
|
||||
///
|
||||
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
|
||||
/// unpackSnorm4x16: clamp(f / 32767.0, -1, +1)
|
||||
///
|
||||
/// The first component of the returned vector will be extracted from the least significant bits of the input;
|
||||
/// the last component will be extracted from the most significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see float unpackSnorm1x16(uint16 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/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);
|
||||
|
||||
/// 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 vec2 unpackHalf2x16(uint32 const & v)
|
||||
/// @see vec4 unpackHalf4x16(uint64 const & v)
|
||||
/// @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 four-component floating-point vector
|
||||
/// to the 16-bit floating-point representation found in the OpenGL Specification,
|
||||
/// 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 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 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 forth component is obtained from the 16 most-significant bits of v.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see float unpackHalf1x16(uint16 const & v)
|
||||
/// @see vec2 unpackHalf2x16(uint32 const & v)
|
||||
/// @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 vec4 unpackHalf4x16(uint64 const & p);
|
||||
|
||||
/// Returns an unsigned integer obtained by converting the components of a four-component signed integer vector
|
||||
/// to the 10-10-10-2-bit signed integer representation found in the OpenGL Specification,
|
||||
/// and then packing these four values into a 32-bit unsigned integer.
|
||||
/// The first vector component specifies the 10 least-significant bits of the result;
|
||||
/// the forth component specifies the 2 most-significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint32 packI3x10_1x2(uvec4 const & v)
|
||||
/// @see uint32 packSnorm3x10_1x2(vec4 const & v)
|
||||
/// @see uint32 packUnorm3x10_1x2(vec4 const & v)
|
||||
/// @see ivec4 unpackI3x10_1x2(uint32 const & p)
|
||||
GLM_FUNC_DECL uint32 packI3x10_1x2(ivec4 const & v);
|
||||
|
||||
/// Unpacks a single 32-bit unsigned integer p into three 10-bit and one 2-bit signed integers.
|
||||
///
|
||||
/// The first component of the returned vector will be extracted from the least significant bits of the input;
|
||||
/// the last component will be extracted from the most significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint32 packU3x10_1x2(uvec4 const & v)
|
||||
/// @see vec4 unpackSnorm3x10_1x2(uint32 const & p);
|
||||
/// @see uvec4 unpackI3x10_1x2(uint32 const & p);
|
||||
GLM_FUNC_DECL ivec4 unpackI3x10_1x2(uint32 const & p);
|
||||
|
||||
/// Returns an unsigned integer obtained by converting the components of a four-component unsigned integer vector
|
||||
/// to the 10-10-10-2-bit unsigned integer representation found in the OpenGL Specification,
|
||||
/// and then packing these four values into a 32-bit unsigned integer.
|
||||
/// The first vector component specifies the 10 least-significant bits of the result;
|
||||
/// the forth component specifies the 2 most-significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint32 packI3x10_1x2(ivec4 const & v)
|
||||
/// @see uint32 packSnorm3x10_1x2(vec4 const & v)
|
||||
/// @see uint32 packUnorm3x10_1x2(vec4 const & v)
|
||||
/// @see ivec4 unpackU3x10_1x2(uint32 const & p)
|
||||
GLM_FUNC_DECL uint32 packU3x10_1x2(uvec4 const & v);
|
||||
|
||||
/// Unpacks a single 32-bit unsigned integer p into three 10-bit and one 2-bit unsigned integers.
|
||||
///
|
||||
/// The first component of the returned vector will be extracted from the least significant bits of the input;
|
||||
/// the last component will be extracted from the most significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint32 packU3x10_1x2(uvec4 const & v)
|
||||
/// @see vec4 unpackSnorm3x10_1x2(uint32 const & p);
|
||||
/// @see uvec4 unpackI3x10_1x2(uint32 const & p);
|
||||
GLM_FUNC_DECL uvec4 unpackU3x10_1x2(uint32 const & p);
|
||||
|
||||
/// First, converts the first three components of the normalized floating-point value v into 10-bit signed integer values.
|
||||
/// Then, converts the forth component of the normalized floating-point value v into 2-bit signed integer values.
|
||||
/// Then, the results are packed into the returned 32-bit unsigned integer.
|
||||
///
|
||||
/// The conversion for component c of v to fixed point is done as follows:
|
||||
/// packSnorm3x10_1x2(xyz): round(clamp(c, -1, +1) * 511.0)
|
||||
/// packSnorm3x10_1x2(w): round(clamp(c, -1, +1) * 1.0)
|
||||
///
|
||||
/// The first vector component specifies the 10 least-significant bits of the result;
|
||||
/// the forth component specifies the 2 most-significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see vec4 unpackSnorm3x10_1x2(uint32 const & p)
|
||||
/// @see uint32 packUnorm3x10_1x2(vec4 const & v)
|
||||
/// @see uint32 packU3x10_1x2(uvec4 const & v)
|
||||
/// @see uint32 packI3x10_1x2(ivec4 const & v)
|
||||
GLM_FUNC_DECL uint32 packSnorm3x10_1x2(vec4 const & v);
|
||||
|
||||
/// First, unpacks a single 32-bit unsigned integer p into four 16-bit signed integers.
|
||||
/// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector.
|
||||
///
|
||||
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
|
||||
/// unpackSnorm3x10_1x2(xyz): clamp(f / 511.0, -1, +1)
|
||||
/// unpackSnorm3x10_1x2(w): clamp(f / 511.0, -1, +1)
|
||||
///
|
||||
/// The first component of the returned vector will be extracted from the least significant bits of the input;
|
||||
/// the last component will be extracted from the most significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint32 packSnorm3x10_1x2(vec4 const & v)
|
||||
/// @see vec4 unpackUnorm3x10_1x2(uint32 const & p))
|
||||
/// @see uvec4 unpackI3x10_1x2(uint32 const & p)
|
||||
/// @see uvec4 unpackU3x10_1x2(uint32 const & p)
|
||||
GLM_FUNC_DECL vec4 unpackSnorm3x10_1x2(uint32 const & p);
|
||||
|
||||
/// First, converts the first three components of the normalized floating-point value v into 10-bit unsigned integer values.
|
||||
/// Then, converts the forth component of the normalized floating-point value v into 2-bit signed uninteger values.
|
||||
/// Then, the results are packed into the returned 32-bit unsigned integer.
|
||||
///
|
||||
/// The conversion for component c of v to fixed point is done as follows:
|
||||
/// packUnorm3x10_1x2(xyz): round(clamp(c, 0, +1) * 1023.0)
|
||||
/// packUnorm3x10_1x2(w): round(clamp(c, 0, +1) * 3.0)
|
||||
///
|
||||
/// The first vector component specifies the 10 least-significant bits of the result;
|
||||
/// the forth component specifies the 2 most-significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see vec4 unpackUnorm3x10_1x2(uint32 const & p)
|
||||
/// @see uint32 packUnorm3x10_1x2(vec4 const & v)
|
||||
/// @see uint32 packU3x10_1x2(uvec4 const & v)
|
||||
/// @see uint32 packI3x10_1x2(ivec4 const & v)
|
||||
GLM_FUNC_DECL uint32 packUnorm3x10_1x2(vec4 const & v);
|
||||
|
||||
/// First, unpacks a single 32-bit unsigned integer p into four 16-bit signed integers.
|
||||
/// Then, each component is converted to a normalized floating-point value to generate the returned four-component vector.
|
||||
///
|
||||
/// The conversion for unpacked fixed-point value f to floating point is done as follows:
|
||||
/// unpackSnorm3x10_1x2(xyz): clamp(f / 1023.0, 0, +1)
|
||||
/// unpackSnorm3x10_1x2(w): clamp(f / 3.0, 0, +1)
|
||||
///
|
||||
/// The first component of the returned vector will be extracted from the least significant bits of the input;
|
||||
/// the last component will be extracted from the most significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint32 packSnorm3x10_1x2(vec4 const & v)
|
||||
/// @see vec4 unpackInorm3x10_1x2(uint32 const & p))
|
||||
/// @see uvec4 unpackI3x10_1x2(uint32 const & p)
|
||||
/// @see uvec4 unpackU3x10_1x2(uint32 const & p)
|
||||
GLM_FUNC_DECL vec4 unpackUnorm3x10_1x2(uint32 const & p);
|
||||
|
||||
/// First, converts the first two components of the normalized floating-point value v into 11-bit signless floating-point values.
|
||||
/// Then, converts the third component of the normalized floating-point value v into a 10-bit signless floating-point value.
|
||||
/// Then, the results are packed into the returned 32-bit unsigned integer.
|
||||
///
|
||||
/// The first vector component specifies the 11 least-significant bits of the result;
|
||||
/// the last component specifies the 10 most-significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see vec3 unpackF2x11_1x10(uint32 const & p)
|
||||
GLM_FUNC_DECL uint32 packF2x11_1x10(vec3 const & v);
|
||||
|
||||
/// First, unpacks a single 32-bit unsigned integer p into two 11-bit signless floating-point values and one 10-bit signless floating-point value .
|
||||
/// Then, each component is converted to a normalized floating-point value to generate the returned three-component vector.
|
||||
///
|
||||
/// The first component of the returned vector will be extracted from the least significant bits of the input;
|
||||
/// the last component will be extracted from the most significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint32 packF2x11_1x10(vec3 const & v)
|
||||
GLM_FUNC_DECL vec3 unpackF2x11_1x10(uint32 const & p);
|
||||
|
||||
/// @}
|
||||
}// namespace glm
|
||||
|
||||
#include "packing.inl"
|
||||
|
||||
#endif//GLM_GTC_packing
|
||||
|
575
glm/gtc/packing.inl
Normal file
575
glm/gtc/packing.inl
Normal file
@ -0,0 +1,575 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
/// OpenGL Mathematics (glm.g-truc.net)
|
||||
///
|
||||
/// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
|
||||
/// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
/// of this software and associated documentation files (the "Software"), to deal
|
||||
/// in the Software without restriction, including without limitation the rights
|
||||
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
/// copies of the Software, and to permit persons to whom the Software is
|
||||
/// furnished to do so, subject to the following conditions:
|
||||
///
|
||||
/// The above copyright notice and this permission notice shall be included in
|
||||
/// all copies or substantial portions of the Software.
|
||||
///
|
||||
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
/// THE SOFTWARE.
|
||||
///
|
||||
/// @ref gtc_packing
|
||||
/// @file glm/gtc/packing.inl
|
||||
/// @date 2013-08-08 / 2013-08-08
|
||||
/// @author Christophe Riccio
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace glm{
|
||||
namespace detail
|
||||
{
|
||||
glm::uint16 float2half(glm::uint32 const & f)
|
||||
{
|
||||
// 10 bits => EE EEEFFFFF
|
||||
// 11 bits => EEE EEFFFFFF
|
||||
// Half bits => SEEEEEFF FFFFFFFF
|
||||
// Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF
|
||||
|
||||
// 0x00007c00 => 00000000 00000000 01111100 00000000
|
||||
// 0x000003ff => 00000000 00000000 00000011 11111111
|
||||
// 0x38000000 => 00111000 00000000 00000000 00000000
|
||||
// 0x7f800000 => 01111111 10000000 00000000 00000000
|
||||
// 0x00008000 => 00000000 00000000 10000000 00000000
|
||||
return
|
||||
((f >> 16) & 0x8000) | // sign
|
||||
((((f & 0x7f800000) - 0x38000000) >> 13) & 0x7c00) | // exponential
|
||||
((f >> 13) & 0x03ff); // Mantissa
|
||||
}
|
||||
|
||||
glm::uint32 float2packed11(glm::uint32 const & f)
|
||||
{
|
||||
// 10 bits => EE EEEFFFFF
|
||||
// 11 bits => EEE EEFFFFFF
|
||||
// Half bits => SEEEEEFF FFFFFFFF
|
||||
// Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF
|
||||
|
||||
// 0x000007c0 => 00000000 00000000 00000111 11000000
|
||||
// 0x00007c00 => 00000000 00000000 01111100 00000000
|
||||
// 0x000003ff => 00000000 00000000 00000011 11111111
|
||||
// 0x38000000 => 00111000 00000000 00000000 00000000
|
||||
// 0x7f800000 => 01111111 10000000 00000000 00000000
|
||||
// 0x00008000 => 00000000 00000000 10000000 00000000
|
||||
return
|
||||
((((f & 0x7f800000) - 0x38000000) >> 17) & 0x07c0) | // exponential
|
||||
((f >> 17) & 0x003f); // Mantissa
|
||||
}
|
||||
|
||||
glm::uint32 packed11ToFloat(glm::uint32 const & p)
|
||||
{
|
||||
// 10 bits => EE EEEFFFFF
|
||||
// 11 bits => EEE EEFFFFFF
|
||||
// Half bits => SEEEEEFF FFFFFFFF
|
||||
// Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF
|
||||
|
||||
// 0x000007c0 => 00000000 00000000 00000111 11000000
|
||||
// 0x00007c00 => 00000000 00000000 01111100 00000000
|
||||
// 0x000003ff => 00000000 00000000 00000011 11111111
|
||||
// 0x38000000 => 00111000 00000000 00000000 00000000
|
||||
// 0x7f800000 => 01111111 10000000 00000000 00000000
|
||||
// 0x00008000 => 00000000 00000000 10000000 00000000
|
||||
return
|
||||
((((p & 0x07c0) << 17) + 0x38000000) & 0x7f800000) | // exponential
|
||||
((p & 0x003f) << 17); // Mantissa
|
||||
}
|
||||
|
||||
glm::uint32 float2packed10(glm::uint32 const & f)
|
||||
{
|
||||
// 10 bits => EE EEEFFFFF
|
||||
// 11 bits => EEE EEFFFFFF
|
||||
// Half bits => SEEEEEFF FFFFFFFF
|
||||
// Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF
|
||||
|
||||
// 0x0000001F => 00000000 00000000 00000000 00011111
|
||||
// 0x0000003F => 00000000 00000000 00000000 00111111
|
||||
// 0x000003E0 => 00000000 00000000 00000011 11100000
|
||||
// 0x000007C0 => 00000000 00000000 00000111 11000000
|
||||
// 0x00007C00 => 00000000 00000000 01111100 00000000
|
||||
// 0x000003FF => 00000000 00000000 00000011 11111111
|
||||
// 0x38000000 => 00111000 00000000 00000000 00000000
|
||||
// 0x7f800000 => 01111111 10000000 00000000 00000000
|
||||
// 0x00008000 => 00000000 00000000 10000000 00000000
|
||||
return
|
||||
((((f & 0x7f800000) - 0x38000000) >> 18) & 0x03E0) | // exponential
|
||||
((f >> 18) & 0x001f); // Mantissa
|
||||
}
|
||||
|
||||
glm::uint32 packed10ToFloat(glm::uint32 const & p)
|
||||
{
|
||||
// 10 bits => EE EEEFFFFF
|
||||
// 11 bits => EEE EEFFFFFF
|
||||
// Half bits => SEEEEEFF FFFFFFFF
|
||||
// Float bits => SEEEEEEE EFFFFFFF FFFFFFFF FFFFFFFF
|
||||
|
||||
// 0x0000001F => 00000000 00000000 00000000 00011111
|
||||
// 0x0000003F => 00000000 00000000 00000000 00111111
|
||||
// 0x000003E0 => 00000000 00000000 00000011 11100000
|
||||
// 0x000007C0 => 00000000 00000000 00000111 11000000
|
||||
// 0x00007C00 => 00000000 00000000 01111100 00000000
|
||||
// 0x000003FF => 00000000 00000000 00000011 11111111
|
||||
// 0x38000000 => 00111000 00000000 00000000 00000000
|
||||
// 0x7f800000 => 01111111 10000000 00000000 00000000
|
||||
// 0x00008000 => 00000000 00000000 10000000 00000000
|
||||
return
|
||||
((((p & 0x03E0) << 18) + 0x38000000) & 0x7f800000) | // exponential
|
||||
((p & 0x001f) << 18); // Mantissa
|
||||
}
|
||||
|
||||
glm::uint half2float(glm::uint const & h)
|
||||
{
|
||||
return ((h & 0x8000) << 16) | ((( h & 0x7c00) + 0x1C000) << 13) | ((h & 0x03FF) << 13);
|
||||
}
|
||||
|
||||
union uif
|
||||
{
|
||||
glm::uint i;
|
||||
float f;
|
||||
};
|
||||
|
||||
glm::uint floatTo11bit(float x)
|
||||
{
|
||||
if(x == 0.0f)
|
||||
return 0;
|
||||
else if(glm::isnan(x))
|
||||
return ~0;
|
||||
else if(glm::isinf(x))
|
||||
return 0x1f << 6;
|
||||
|
||||
uif Union;
|
||||
Union.f = x;
|
||||
return float2packed11(Union.i);
|
||||
}
|
||||
|
||||
float packed11bitToFloat(glm::uint x)
|
||||
{
|
||||
if(x == 0)
|
||||
return 0.0f;
|
||||
else if(x == ((1 << 11) - 1))
|
||||
return ~0;//NaN
|
||||
else if(x == (0x1f << 6))
|
||||
return ~0;//Inf
|
||||
|
||||
uif Union;
|
||||
Union.i = packed11ToFloat(x);
|
||||
return Union.f;
|
||||
}
|
||||
|
||||
glm::uint floatTo10bit(float x)
|
||||
{
|
||||
if(x == 0.0f)
|
||||
return 0;
|
||||
else if(glm::isnan(x))
|
||||
return ~0;
|
||||
else if(glm::isinf(x))
|
||||
return 0x1f << 5;
|
||||
|
||||
uif Union;
|
||||
Union.f = x;
|
||||
return float2packed10(Union.i);
|
||||
}
|
||||
|
||||
float packed10bitToFloat(glm::uint x)
|
||||
{
|
||||
if(x == 0)
|
||||
return 0.0f;
|
||||
else if(x == ((1 << 10) - 1))
|
||||
return ~0;//NaN
|
||||
else if(x == (0x1f << 5))
|
||||
return ~0;//Inf
|
||||
|
||||
uif Union;
|
||||
Union.i = packed10ToFloat(x);
|
||||
return Union.f;
|
||||
}
|
||||
|
||||
glm::uint f11_f11_f10(float x, float y, float z)
|
||||
{
|
||||
return ((floatTo11bit(x) & ((1 << 11) - 1)) << 0) | ((floatTo11bit(y) & ((1 << 11) - 1)) << 11) | ((floatTo10bit(z) & ((1 << 10) - 1)) << 22);
|
||||
}
|
||||
|
||||
union u10u10u10u2
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint x : 10;
|
||||
uint y : 10;
|
||||
uint z : 10;
|
||||
uint w : 2;
|
||||
} data;
|
||||
uint32 pack;
|
||||
};
|
||||
|
||||
union i10i10i10i2
|
||||
{
|
||||
struct
|
||||
{
|
||||
int x : 10;
|
||||
int y : 10;
|
||||
int z : 10;
|
||||
int w : 2;
|
||||
} data;
|
||||
uint32 pack;
|
||||
};
|
||||
|
||||
union unorm4x16
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint16 x;
|
||||
uint16 y;
|
||||
uint16 z;
|
||||
uint16 w;
|
||||
} data;
|
||||
uint64 pack;
|
||||
};
|
||||
|
||||
union snorm4x16
|
||||
{
|
||||
struct
|
||||
{
|
||||
int16 x;
|
||||
int16 y;
|
||||
int16 z;
|
||||
int16 w;
|
||||
} data;
|
||||
uint64 pack;
|
||||
};
|
||||
|
||||
union snorm1x16
|
||||
{
|
||||
int16 data;
|
||||
uint16 pack;
|
||||
};
|
||||
|
||||
union half1x16
|
||||
{
|
||||
hdata data;
|
||||
uint16 pack;
|
||||
};
|
||||
|
||||
union half4x16
|
||||
{
|
||||
struct
|
||||
{
|
||||
hdata x;
|
||||
hdata y;
|
||||
hdata z;
|
||||
hdata w;
|
||||
} data;
|
||||
uint64 pack;
|
||||
};
|
||||
|
||||
union unorm1x8
|
||||
{
|
||||
uint8 data;
|
||||
uint8 pack;
|
||||
};
|
||||
|
||||
union unorm2x8
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8 x;
|
||||
uint8 y;
|
||||
} data;
|
||||
uint16 pack;
|
||||
};
|
||||
|
||||
union snorm1x8
|
||||
{
|
||||
int8 data;
|
||||
uint8 pack;
|
||||
};
|
||||
|
||||
union snorm2x8
|
||||
{
|
||||
struct
|
||||
{
|
||||
int8 x;
|
||||
int8 y;
|
||||
} data;
|
||||
uint16 pack;
|
||||
};
|
||||
}//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.data = Scaled;
|
||||
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));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER float unpackUnorm1x16(uint16 p)
|
||||
{
|
||||
return float(p) * 1.0f / 65535.0f;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint64 packUnorm4x16(vec4 const & v)
|
||||
{
|
||||
i16vec4 Scaled(round(clamp(v, 0.0f, 1.0f) * 65535.0f));
|
||||
detail::unorm4x16 Packing;
|
||||
Packing.data.x = Scaled[0];
|
||||
Packing.data.y = Scaled[1];
|
||||
Packing.data.z = Scaled[2];
|
||||
Packing.data.w = Scaled[3];
|
||||
return Packing.pack;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x16(uint64 const & p)
|
||||
{
|
||||
detail::unorm4x16 Packing;
|
||||
vec4 Result(
|
||||
float(Packing.data.x),
|
||||
float(Packing.data.y),
|
||||
float(Packing.data.z),
|
||||
float(Packing.data.w));
|
||||
Result *= float(1.5259021896696421759365224689097e-5); // 1.0 / 65535.0
|
||||
return Result;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint16 packSnorm1x16(float v)
|
||||
{
|
||||
float Scaled = clamp(v ,-1.0f, 1.0f) * 32767.0f;
|
||||
detail::snorm1x16 Packing;
|
||||
Packing.data = detail::int16(Scaled);
|
||||
return Packing.pack;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER float unpackSnorm1x16(uint16 p)
|
||||
{
|
||||
detail::snorm1x16 Packing;
|
||||
Packing.pack = p;
|
||||
return clamp(float(Packing.data) * float(3.0518509475997192297128208258309e-5), -1.0f, 1.0f); //1.0f / 32767.0f
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint64 packSnorm4x16(vec4 const & v)
|
||||
{
|
||||
i16vec4 Scaled(clamp(v ,-1.0f, 1.0f) * 32767.0f);
|
||||
detail::snorm4x16 Packing;
|
||||
Packing.data.x = Scaled.x;
|
||||
Packing.data.y = Scaled.y;
|
||||
Packing.data.z = Scaled.z;
|
||||
Packing.data.w = Scaled.w;
|
||||
return Packing.pack;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 const & p)
|
||||
{
|
||||
detail::snorm4x16 Packing;
|
||||
Packing.pack = p;
|
||||
vec4 Unpacked(Packing.data.x, Packing.data.y, Packing.data.z, Packing.data.w);
|
||||
return clamp(Unpacked * float(3.0518509475997192297128208258309e-5), -1.0f, 1.0f); //1.0f / 32767.0f
|
||||
}
|
||||
|
||||
GLM_FUNC_DECL uint16 packHalf1x16(float const & v)
|
||||
{
|
||||
detail::half1x16 Packing;
|
||||
Packing.data = detail::toFloat16(v);
|
||||
return Packing.pack;
|
||||
}
|
||||
|
||||
GLM_FUNC_DECL float unpackHalf1x16(uint16 const & v)
|
||||
{
|
||||
detail::half1x16 Packing;
|
||||
Packing.pack = v;
|
||||
return detail::toFloat32(Packing.data);
|
||||
}
|
||||
|
||||
GLM_FUNC_DECL uint64 packHalf4x16(glm::vec4 const & v)
|
||||
{
|
||||
detail::half4x16 Packing;
|
||||
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 glm::vec4 unpackHalf4x16(uint64 const & v)
|
||||
{
|
||||
detail::half4x16 Packing;
|
||||
Packing.pack = v;
|
||||
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)
|
||||
{
|
||||
detail::i10i10i10i2 Result;
|
||||
Result.data.x = v.x;
|
||||
Result.data.y = v.y;
|
||||
Result.data.z = v.z;
|
||||
Result.data.w = v.w;
|
||||
return Result.pack;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER ivec4 unpackI3x10_1x2(uint32 const & v)
|
||||
{
|
||||
detail::i10i10i10i2 Unpack;
|
||||
Unpack.pack = v;
|
||||
return ivec4(
|
||||
Unpack.data.x,
|
||||
Unpack.data.y,
|
||||
Unpack.data.z,
|
||||
Unpack.data.w);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint32 packU3x10_1x2(uvec4 const & v)
|
||||
{
|
||||
detail::u10u10u10u2 Result;
|
||||
Result.data.x = v.x;
|
||||
Result.data.y = v.y;
|
||||
Result.data.z = v.z;
|
||||
Result.data.w = v.w;
|
||||
return Result.pack;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uvec4 unpackU3x10_1x2(uint32 const & v)
|
||||
{
|
||||
detail::u10u10u10u2 Unpack;
|
||||
Unpack.pack = v;
|
||||
return uvec4(
|
||||
Unpack.data.x,
|
||||
Unpack.data.y,
|
||||
Unpack.data.z,
|
||||
Unpack.data.w);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint32 packSnorm3x10_1x2(vec4 const & v)
|
||||
{
|
||||
detail::i10i10i10i2 Result;
|
||||
Result.data.x = int(round(clamp(v.x,-1.0f, 1.0f) * 511.f));
|
||||
Result.data.y = int(round(clamp(v.y,-1.0f, 1.0f) * 511.f));
|
||||
Result.data.z = int(round(clamp(v.z,-1.0f, 1.0f) * 511.f));
|
||||
Result.data.w = int(round(clamp(v.w,-1.0f, 1.0f) * 1.f));
|
||||
return Result.pack;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER vec4 unpackSnorm3x10_1x2(uint32 const & v)
|
||||
{
|
||||
detail::i10i10i10i2 Unpack;
|
||||
Unpack.pack = v;
|
||||
vec4 Result;
|
||||
Result.x = clamp(float(Unpack.data.x) / 511.f, -1.0f, 1.0f);
|
||||
Result.y = clamp(float(Unpack.data.y) / 511.f, -1.0f, 1.0f);
|
||||
Result.z = clamp(float(Unpack.data.z) / 511.f, -1.0f, 1.0f);
|
||||
Result.w = clamp(float(Unpack.data.w) / 1.f, -1.0f, 1.0f);
|
||||
return Result;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint32 packUnorm3x10_1x2(vec4 const & v)
|
||||
{
|
||||
detail::i10i10i10i2 Result;
|
||||
Result.data.x = int(round(clamp(v.x, 0.0f, 1.0f) * 1023.f));
|
||||
Result.data.y = int(round(clamp(v.y, 0.0f, 1.0f) * 1023.f));
|
||||
Result.data.z = int(round(clamp(v.z, 0.0f, 1.0f) * 1023.f));
|
||||
Result.data.w = int(round(clamp(v.w, 0.0f, 1.0f) * 3.f));
|
||||
return Result.pack;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER vec4 unpackUnorm3x10_1x2(uint32 const & v)
|
||||
{
|
||||
detail::i10i10i10i2 Unpack;
|
||||
Unpack.pack = v;
|
||||
vec4 Result;
|
||||
Result.x = float(Unpack.data.x) / 1023.f;
|
||||
Result.y = float(Unpack.data.y) / 1023.f;
|
||||
Result.z = float(Unpack.data.z) / 1023.f;
|
||||
Result.w = float(Unpack.data.w) / 3.f;
|
||||
return Result;
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint32 packF2x11_1x10(vec3 const & v)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER vec3 unpackF2x11_1x10(uint32 const & v)
|
||||
{
|
||||
return vec3(
|
||||
detail::packed11bitToFloat(v >> 0),
|
||||
detail::packed11bitToFloat(v >> 11),
|
||||
detail::packed10bitToFloat(v >> 22));
|
||||
}
|
||||
|
||||
}//namespace glm
|
@ -262,7 +262,7 @@ namespace glm
|
||||
return &(mat[0].x);
|
||||
}
|
||||
|
||||
//! Return the address to the data of the matrix input.
|
||||
//! Return the address to the data of the matrix input.
|
||||
/// @see gtc_type_ptr
|
||||
template<typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER T * value_ptr
|
||||
@ -308,8 +308,8 @@ namespace glm
|
||||
template<typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER T * value_ptr
|
||||
(
|
||||
detail::tquat<T, P> & q
|
||||
)
|
||||
detail::tquat<T, P> & q
|
||||
)
|
||||
{
|
||||
return &(q[0]);
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ int test_operator_increment()
|
||||
glm::ivec2 v3 = ++v1;
|
||||
glm::ivec2 v4 = v2++;
|
||||
|
||||
Error += glm::all(glm::equal(v0, v4)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v0, v4)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v1, v2)) ? 0 : 1;
|
||||
Error += glm::all(glm::equal(v1, v3)) ? 0 : 1;
|
||||
|
||||
|
@ -6,6 +6,7 @@ glmCreateTestGTC(gtc_matrix_integer)
|
||||
glmCreateTestGTC(gtc_matrix_inverse)
|
||||
glmCreateTestGTC(gtc_matrix_transform)
|
||||
glmCreateTestGTC(gtc_noise)
|
||||
glmCreateTestGTC(gtc_packing)
|
||||
glmCreateTestGTC(gtc_quaternion)
|
||||
glmCreateTestGTC(gtc_random)
|
||||
glmCreateTestGTC(gtc_reciprocal)
|
||||
|
@ -791,27 +791,27 @@ int test_half()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
print_value(0.0);
|
||||
print_value(0.1);
|
||||
print_value(0.2);
|
||||
print_value(0.3);
|
||||
print_value(0.4);
|
||||
print_value(0.5);
|
||||
print_value(0.6);
|
||||
print_value(1.0);
|
||||
print_value(1.1);
|
||||
print_value(1.2);
|
||||
print_value(1.3);
|
||||
print_value(1.4);
|
||||
print_value(1.5);
|
||||
print_value(1.6);
|
||||
print_value(2.0);
|
||||
print_value(2.1);
|
||||
print_value(2.2);
|
||||
print_value(2.3);
|
||||
print_value(2.4);
|
||||
print_value(2.5);
|
||||
print_value(2.6);
|
||||
print_value(0.0f);
|
||||
print_value(0.1f);
|
||||
print_value(0.2f);
|
||||
print_value(0.3f);
|
||||
print_value(0.4f);
|
||||
print_value(0.5f);
|
||||
print_value(0.6f);
|
||||
print_value(1.0f);
|
||||
print_value(1.1f);
|
||||
print_value(1.2f);
|
||||
print_value(1.3f);
|
||||
print_value(1.4f);
|
||||
print_value(1.5f);
|
||||
print_value(1.6f);
|
||||
print_value(2.0f);
|
||||
print_value(2.1f);
|
||||
print_value(2.2f);
|
||||
print_value(2.3f);
|
||||
print_value(2.4f);
|
||||
print_value(2.5f);
|
||||
print_value(2.6f);
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
317
test/gtc/gtc_packing.cpp
Normal file
317
test/gtc/gtc_packing.cpp
Normal file
@ -0,0 +1,317 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
/// OpenGL Mathematics (glm.g-truc.net)
|
||||
///
|
||||
/// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
|
||||
/// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
/// of this software and associated documentation files (the "Software"), to deal
|
||||
/// in the Software without restriction, including without limitation the rights
|
||||
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
/// copies of the Software, and to permit persons to whom the Software is
|
||||
/// furnished to do so, subject to the following conditions:
|
||||
///
|
||||
/// The above copyright notice and this permission notice shall be included in
|
||||
/// all copies or substantial portions of the Software.
|
||||
///
|
||||
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
/// THE SOFTWARE.
|
||||
///
|
||||
/// @ref test
|
||||
/// @file test/gtc/packing.cpp
|
||||
/// @date 2013-08-09 / 2013-08-09
|
||||
/// @author Christophe Riccio
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/packing.hpp>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
void print_bits(glm::half const & s)
|
||||
{
|
||||
union
|
||||
{
|
||||
glm::detail::hdata h;
|
||||
unsigned short i;
|
||||
} uif;
|
||||
|
||||
uif.h = s._data();
|
||||
|
||||
printf("f16: ");
|
||||
for(std::size_t j = sizeof(s) * 8; j > 0; --j)
|
||||
{
|
||||
if(j == 10 || j == 15)
|
||||
printf(" ");
|
||||
printf("%d", (uif.i & (1 << (j - 1))) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
void print_bits(float const & s)
|
||||
{
|
||||
union
|
||||
{
|
||||
float f;
|
||||
unsigned int i;
|
||||
} uif;
|
||||
|
||||
uif.f = s;
|
||||
|
||||
printf("f32: ");
|
||||
for(std::size_t j = sizeof(s) * 8; j > 0; --j)
|
||||
{
|
||||
if(j == 23 || j == 31)
|
||||
printf(" ");
|
||||
printf("%d", (uif.i & (1 << (j - 1))) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
void print_10bits(glm::uint const & s)
|
||||
{
|
||||
printf("10b: ");
|
||||
for(std::size_t j = 10; j > 0; --j)
|
||||
{
|
||||
if(j == 5)
|
||||
printf(" ");
|
||||
printf("%d", (s & (1 << (j - 1))) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
void print_11bits(glm::uint const & s)
|
||||
{
|
||||
printf("11b: ");
|
||||
for(std::size_t j = 11; j > 0; --j)
|
||||
{
|
||||
if(j == 6)
|
||||
printf(" ");
|
||||
printf("%d", (s & (1 << (j - 1))) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
void print_value(float const & s)
|
||||
{
|
||||
printf("%2.5f, ", s);
|
||||
print_bits(s);
|
||||
printf(", ");
|
||||
print_bits(glm::half(s));
|
||||
// printf(", ");
|
||||
// print_11bits(detail::floatTo11bit(s));
|
||||
// printf(", ");
|
||||
// print_10bits(detail::floatTo10bit(s));
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int test_half()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
print_value(0.0f);
|
||||
print_value(0.1f);
|
||||
print_value(0.2f);
|
||||
print_value(0.3f);
|
||||
print_value(0.4f);
|
||||
print_value(0.5f);
|
||||
print_value(0.6f);
|
||||
print_value(1.0f);
|
||||
print_value(1.1f);
|
||||
print_value(1.2f);
|
||||
print_value(1.3f);
|
||||
print_value(1.4f);
|
||||
print_value(1.5f);
|
||||
print_value(1.6f);
|
||||
print_value(2.0f);
|
||||
print_value(2.1f);
|
||||
print_value(2.2f);
|
||||
print_value(2.3f);
|
||||
print_value(2.4f);
|
||||
print_value(2.5f);
|
||||
print_value(2.6f);
|
||||
|
||||
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;
|
||||
|
||||
std::vector<glm::vec3> Tests;
|
||||
Tests.push_back(glm::vec3(1.0));
|
||||
Tests.push_back(glm::vec3(0.0));
|
||||
Tests.push_back(glm::vec3(2.0));
|
||||
Tests.push_back(glm::vec3(0.1));
|
||||
Tests.push_back(glm::vec3(0.5));
|
||||
Tests.push_back(glm::vec3(0.9));
|
||||
|
||||
for(std::size_t i = 0; i < Tests.size(); ++i)
|
||||
{
|
||||
glm::uint32 p0 = glm::packF2x11_1x10(Tests[i]);
|
||||
glm::vec3 v0 = glm::unpackF2x11_1x10(p0);
|
||||
glm::uint32 p1 = glm::packF2x11_1x10(v0);
|
||||
glm::vec3 v1 = glm::unpackF2x11_1x10(p0);
|
||||
Error += glm::all(glm::equal(v0, v1)) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
Error += test_F2x11_1x10();
|
||||
Error += test_Snorm3x10_1x2();
|
||||
Error += test_Unorm3x10_1x2();
|
||||
Error += test_I3x10_1x2();
|
||||
Error += test_U3x10_1x2();
|
||||
Error += test_Half1x16();
|
||||
Error += test_U3x10_1x2();
|
||||
|
||||
return Error;
|
||||
}
|
Loading…
Reference in New Issue
Block a user