mirror of
https://github.com/g-truc/glm.git
synced 2024-11-30 03:44:38 +00:00
Factorized float to uint and co function code.
This commit is contained in:
parent
4707333a58
commit
dddcbe58e6
@ -262,7 +262,7 @@ namespace glm
|
||||
genTypeT const & y,
|
||||
genTypeU const & a);
|
||||
|
||||
/// Returns 0.0 if x < edge, otherwise it returns 1.0.
|
||||
/// Returns 0.0 if x < edge, otherwise it returns 1.0 for each component of a genType.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/step.xml">GLSL step man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
|
||||
@ -271,10 +271,14 @@ namespace glm
|
||||
genType const & edge,
|
||||
genType const & x);
|
||||
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType step(
|
||||
typename genType::T const & edge,
|
||||
genType const & x);
|
||||
/// Returns 0.0 if x < edge, otherwise it returns 1.0.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/step.xml">GLSL step man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
|
||||
template <template <typename, precision> class vecType, typename T, precision P>
|
||||
GLM_FUNC_DECL vecType<T, P> step(
|
||||
T const & edge,
|
||||
vecType<T, P> const & x);
|
||||
|
||||
/// Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and
|
||||
/// performs smooth Hermite interpolation between 0 and 1
|
||||
@ -331,28 +335,38 @@ namespace glm
|
||||
GLM_FUNC_DECL typename genType::bool_type isinf(genType const & x);
|
||||
|
||||
/// Returns a signed integer value representing
|
||||
/// the encoding of a floating-point value. The floatingpoint
|
||||
/// the encoding of a floating-point value. The floating-point
|
||||
/// value's bit-level representation is preserved.
|
||||
///
|
||||
/// @tparam genType Single-precision floating-point scalar or vector types.
|
||||
/// @tparam genIType Signed integer scalar or vector types.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/floatBitsToInt.xml">GLSL floatBitsToInt man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
|
||||
template <typename genType, typename genIType>
|
||||
GLM_FUNC_DECL genIType floatBitsToInt(genType const & value);
|
||||
GLM_FUNC_DECL int floatBitsToInt(float const & v);
|
||||
|
||||
/// Returns a signed integer value representing
|
||||
/// the encoding of a floating-point value. The floatingpoint
|
||||
/// value's bit-level representation is preserved.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/floatBitsToInt.xml">GLSL floatBitsToInt man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
|
||||
template <template <typename, precision> class vecType, precision P>
|
||||
GLM_FUNC_DECL vecType<int, P> floatBitsToInt(vecType<float, P> const & v);
|
||||
|
||||
/// Returns a unsigned integer value representing
|
||||
/// the encoding of a floating-point value. The floatingpoint
|
||||
/// value's bit-level representation is preserved.
|
||||
///
|
||||
/// @tparam genType Single-precision floating-point scalar or vector types.
|
||||
/// @tparam genUType Unsigned integer scalar or vector types.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/floatBitsToUint.xml">GLSL floatBitsToUint man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
|
||||
template <typename genType, typename genUType>
|
||||
GLM_FUNC_DECL genUType floatBitsToUint(genType const & value);
|
||||
GLM_FUNC_DECL uint floatBitsToUint(float const & v);
|
||||
|
||||
/// Returns a unsigned integer value representing
|
||||
/// the encoding of a floating-point value. The floatingpoint
|
||||
/// value's bit-level representation is preserved.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/floatBitsToUint.xml">GLSL floatBitsToUint man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
|
||||
template <template <typename, precision> class vecType, precision P>
|
||||
GLM_FUNC_DECL vecType<uint, P> floatBitsToUint(vecType<float, P> const & v);
|
||||
|
||||
/// Returns a floating-point value corresponding to a signed
|
||||
/// integer encoding of a floating-point value.
|
||||
@ -360,15 +374,20 @@ namespace glm
|
||||
/// resulting floating point value is unspecified. Otherwise,
|
||||
/// the bit-level representation is preserved.
|
||||
///
|
||||
/// @tparam genType Single-precision floating-point scalar or vector types.
|
||||
/// @tparam genIType Signed integer scalar or vector types.
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/intBitsToFloat.xml">GLSL intBitsToFloat man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
|
||||
GLM_FUNC_DECL float intBitsToFloat(int const & v);
|
||||
|
||||
/// Returns a floating-point value corresponding to a signed
|
||||
/// integer encoding of a floating-point value.
|
||||
/// If an inf or NaN is passed in, it will not signal, and the
|
||||
/// resulting floating point value is unspecified. Otherwise,
|
||||
/// the bit-level representation is preserved.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/intBitsToFloat.xml">GLSL intBitsToFloat man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
|
||||
///
|
||||
/// @todo Clarify this declaration, we don't need to actually specify the return type
|
||||
template <typename genType, typename genIType>
|
||||
GLM_FUNC_DECL genType intBitsToFloat(genIType const & value);
|
||||
template <template <typename, precision> class vecType, precision P>
|
||||
GLM_FUNC_DECL vecType<float, P> intBitsToFloat(vecType<int, P> const & v);
|
||||
|
||||
/// Returns a floating-point value corresponding to a
|
||||
/// unsigned integer encoding of a floating-point value.
|
||||
@ -376,15 +395,20 @@ namespace glm
|
||||
/// resulting floating point value is unspecified. Otherwise,
|
||||
/// the bit-level representation is preserved.
|
||||
///
|
||||
/// @tparam genType Single-precision floating-point scalar or vector types.
|
||||
/// @tparam genUType Unsigned integer scalar or vector types.
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/uintBitsToFloat.xml">GLSL uintBitsToFloat man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
|
||||
GLM_FUNC_DECL float uintBitsToFloat(uint const & v);
|
||||
|
||||
/// Returns a floating-point value corresponding to a
|
||||
/// unsigned integer encoding of a floating-point value.
|
||||
/// If an inf or NaN is passed in, it will not signal, and the
|
||||
/// resulting floating point value is unspecified. Otherwise,
|
||||
/// the bit-level representation is preserved.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/uintBitsToFloat.xml">GLSL uintBitsToFloat man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
|
||||
///
|
||||
/// @todo Clarify this declaration, we don't need to actually specify the return type
|
||||
template <typename genType, typename genUType>
|
||||
GLM_FUNC_DECL genType uintBitsToFloat(genUType const & value);
|
||||
template <template <typename, precision> class vecType, precision P>
|
||||
GLM_FUNC_DECL vecType<float, P> uintBitsToFloat(vecType<uint, P> const & v);
|
||||
|
||||
/// Computes and returns a * b + c.
|
||||
///
|
||||
|
@ -26,6 +26,10 @@
|
||||
/// @author Christophe Riccio
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "type_vec2.hpp"
|
||||
#include "type_vec3.hpp"
|
||||
#include "type_vec4.hpp"
|
||||
#include "_vectorize.hpp"
|
||||
#include <limits>
|
||||
|
||||
namespace glm{
|
||||
@ -708,113 +712,21 @@ namespace detail
|
||||
genType const & x
|
||||
)
|
||||
{
|
||||
GLM_STATIC_ASSERT(
|
||||
std::numeric_limits<genType>::is_iec559,
|
||||
"'step' only accept floating-point inputs");
|
||||
|
||||
return x < edge ? static_cast<genType>(0) : static_cast<genType>(1);
|
||||
return mix(genType(1), genType(0), glm::lessThan(x, edge));
|
||||
}
|
||||
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER detail::tvec2<T, P> step
|
||||
template <template <typename, precision> class vecType, typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> step
|
||||
(
|
||||
T const & edge,
|
||||
detail::tvec2<T, P> const & x
|
||||
vecType<T, P> const & x
|
||||
)
|
||||
{
|
||||
GLM_STATIC_ASSERT(
|
||||
std::numeric_limits<T>::is_iec559,
|
||||
"'step' only accept floating-point inputs");
|
||||
|
||||
return detail::tvec2<T, P>(
|
||||
x.x < edge ? T(0) : T(1),
|
||||
x.y < edge ? T(0) : T(1));
|
||||
}
|
||||
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER detail::tvec3<T, P> step
|
||||
(
|
||||
T const & edge,
|
||||
detail::tvec3<T, P> const & x
|
||||
)
|
||||
{
|
||||
GLM_STATIC_ASSERT(
|
||||
std::numeric_limits<T>::is_iec559,
|
||||
"'step' only accept floating-point inputs");
|
||||
|
||||
return detail::tvec3<T, P>(
|
||||
x.x < edge ? T(0) : T(1),
|
||||
x.y < edge ? T(0) : T(1),
|
||||
x.z < edge ? T(0) : T(1));
|
||||
}
|
||||
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER detail::tvec4<T, P> step
|
||||
(
|
||||
T const & edge,
|
||||
detail::tvec4<T, P> const & x
|
||||
)
|
||||
{
|
||||
GLM_STATIC_ASSERT(
|
||||
std::numeric_limits<T>::is_iec559,
|
||||
"'step' only accept floating-point inputs");
|
||||
|
||||
return detail::tvec4<T, P>(
|
||||
x.x < edge ? T(0) : T(1),
|
||||
x.y < edge ? T(0) : T(1),
|
||||
x.z < edge ? T(0) : T(1),
|
||||
x.w < edge ? T(0) : T(1));
|
||||
}
|
||||
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER detail::tvec2<T, P> step
|
||||
(
|
||||
detail::tvec2<T, P> const & edge,
|
||||
detail::tvec2<T, P> const & x
|
||||
)
|
||||
{
|
||||
GLM_STATIC_ASSERT(
|
||||
std::numeric_limits<T>::is_iec559,
|
||||
"'step' only accept floating-point inputs");
|
||||
|
||||
return detail::tvec2<T, P>(
|
||||
x.x < edge.x ? T(0) : T(1),
|
||||
x.y < edge.y ? T(0) : T(1));
|
||||
}
|
||||
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER detail::tvec3<T, P> step
|
||||
(
|
||||
detail::tvec3<T, P> const & edge,
|
||||
detail::tvec3<T, P> const & x
|
||||
)
|
||||
{
|
||||
GLM_STATIC_ASSERT(
|
||||
std::numeric_limits<T>::is_iec559,
|
||||
"'step' only accept floating-point inputs");
|
||||
|
||||
return detail::tvec3<T, P>(
|
||||
x.x < edge.x ? T(0) : T(1),
|
||||
x.y < edge.y ? T(0) : T(1),
|
||||
x.z < edge.z ? T(0) : T(1));
|
||||
}
|
||||
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER detail::tvec4<T, P> step
|
||||
(
|
||||
detail::tvec4<T, P> const & edge,
|
||||
detail::tvec4<T, P> const & x
|
||||
)
|
||||
{
|
||||
GLM_STATIC_ASSERT(
|
||||
std::numeric_limits<T>::is_iec559,
|
||||
"'step' only accept floating-point inputs");
|
||||
|
||||
return detail::tvec4<T, P>(
|
||||
x.x < edge.x ? T(0) : T(1),
|
||||
x.y < edge.y ? T(0) : T(1),
|
||||
x.z < edge.z ? T(0) : T(1),
|
||||
x.w < edge.w ? T(0) : T(1));
|
||||
return mix(vecType<T, P>(1), vecType<T, P>(0), glm::lessThan(x, vecType<T, P>(edge)));
|
||||
}
|
||||
|
||||
// smoothstep
|
||||
@ -1090,28 +1002,10 @@ namespace detail
|
||||
return *reinterpret_cast<int*>(const_cast<float*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER detail::tvec2<int, defaultp> floatBitsToInt
|
||||
(
|
||||
detail::tvec2<float, defaultp> const & v
|
||||
)
|
||||
template <template <typename, precision> class vecType, precision P>
|
||||
GLM_FUNC_QUALIFIER vecType<int, P> floatBitsToInt(vecType<float, P> const & v)
|
||||
{
|
||||
return *reinterpret_cast<detail::tvec2<int, defaultp>*>(const_cast<detail::tvec2<float, defaultp>*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER detail::tvec3<int, defaultp> floatBitsToInt
|
||||
(
|
||||
detail::tvec3<float, defaultp> const & v
|
||||
)
|
||||
{
|
||||
return *reinterpret_cast<detail::tvec3<int, defaultp>*>(const_cast<detail::tvec3<float, defaultp>*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER detail::tvec4<int, defaultp> floatBitsToInt
|
||||
(
|
||||
detail::tvec4<float, defaultp> const & v
|
||||
)
|
||||
{
|
||||
return *reinterpret_cast<detail::tvec4<int, defaultp>*>(const_cast<detail::tvec4<float, defaultp>*>(&v));
|
||||
return *reinterpret_cast<vecType<int, P>*>(const_cast<vecType<float, P>*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint floatBitsToUint(float const & v)
|
||||
@ -1119,28 +1013,10 @@ namespace detail
|
||||
return *reinterpret_cast<uint*>(const_cast<float*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER detail::tvec2<uint, defaultp> floatBitsToUint
|
||||
(
|
||||
detail::tvec2<float, defaultp> const & v
|
||||
)
|
||||
template <template <typename, precision> class vecType, precision P>
|
||||
GLM_FUNC_QUALIFIER vecType<uint, P> floatBitsToUint(vecType<float, P> const & v)
|
||||
{
|
||||
return *reinterpret_cast<detail::tvec2<uint, defaultp>*>(const_cast<detail::tvec2<float, defaultp>*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER detail::tvec3<uint, defaultp> floatBitsToUint
|
||||
(
|
||||
detail::tvec3<float, defaultp> const & v
|
||||
)
|
||||
{
|
||||
return *reinterpret_cast<detail::tvec3<uint, defaultp>*>(const_cast<detail::tvec3<float, defaultp>*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER detail::tvec4<uint, defaultp> floatBitsToUint
|
||||
(
|
||||
detail::tvec4<float, defaultp> const & v
|
||||
)
|
||||
{
|
||||
return *reinterpret_cast<detail::tvec4<uint, defaultp>*>(const_cast<detail::tvec4<float, defaultp>*>(&v));
|
||||
return *reinterpret_cast<vecType<uint, P>*>(const_cast<vecType<float, P>*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER float intBitsToFloat(int const & v)
|
||||
@ -1148,28 +1024,10 @@ namespace detail
|
||||
return *reinterpret_cast<float*>(const_cast<int*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER detail::tvec2<float, defaultp> intBitsToFloat
|
||||
(
|
||||
detail::tvec2<int, defaultp> const & v
|
||||
)
|
||||
template <template <typename, precision> class vecType, precision P>
|
||||
GLM_FUNC_QUALIFIER vecType<float, P> intBitsToFloat(vecType<int, P> const & v)
|
||||
{
|
||||
return *reinterpret_cast<detail::tvec2<float, defaultp>*>(const_cast<detail::tvec2<int, defaultp>*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER detail::tvec3<float, defaultp> intBitsToFloat
|
||||
(
|
||||
detail::tvec3<int, defaultp> const & v
|
||||
)
|
||||
{
|
||||
return *reinterpret_cast<detail::tvec3<float, defaultp>*>(const_cast<detail::tvec3<int, defaultp>*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER detail::tvec4<float, defaultp> intBitsToFloat
|
||||
(
|
||||
detail::tvec4<int, defaultp> const & v
|
||||
)
|
||||
{
|
||||
return *reinterpret_cast<detail::tvec4<float, defaultp>*>(const_cast<detail::tvec4<int, defaultp>*>(&v));
|
||||
return *reinterpret_cast<vecType<float, P>*>(const_cast<vecType<int, P>*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER float uintBitsToFloat(uint const & v)
|
||||
@ -1177,30 +1035,12 @@ namespace detail
|
||||
return *reinterpret_cast<float*>(const_cast<uint*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER detail::tvec2<float, defaultp> uintBitsToFloat
|
||||
(
|
||||
detail::tvec2<uint, defaultp> const & v
|
||||
)
|
||||
template <template <typename, precision> class vecType, precision P>
|
||||
GLM_FUNC_QUALIFIER vecType<float, P> uintBitsToFloat(vecType<uint, P> const & v)
|
||||
{
|
||||
return *reinterpret_cast<detail::tvec2<float, defaultp>*>(const_cast<detail::tvec2<uint, defaultp>*>(&v));
|
||||
return *reinterpret_cast<vecType<float, P>*>(const_cast<vecType<uint, P>*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER detail::tvec3<float, defaultp> uintBitsToFloat
|
||||
(
|
||||
detail::tvec3<uint, defaultp> const & v
|
||||
)
|
||||
{
|
||||
return *reinterpret_cast<detail::tvec3<float, defaultp>*>(const_cast<detail::tvec3<uint, defaultp>*>(&v));
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER detail::tvec4<float, defaultp> uintBitsToFloat
|
||||
(
|
||||
detail::tvec4<uint, defaultp> const & v
|
||||
)
|
||||
{
|
||||
return *reinterpret_cast<detail::tvec4<float, defaultp>*>(const_cast<detail::tvec4<uint, defaultp>*>(&v));
|
||||
}
|
||||
|
||||
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fma
|
||||
(
|
||||
|
@ -36,6 +36,8 @@
|
||||
#ifndef glm_core_func_geometric
|
||||
#define glm_core_func_geometric GLM_VERSION
|
||||
|
||||
#include "type_vec3.hpp"
|
||||
|
||||
namespace glm
|
||||
{
|
||||
/// @addtogroup core_func_geometric
|
||||
@ -124,11 +126,11 @@ namespace glm
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/refract.xml">GLSL refract man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.5 Geometric Functions</a>
|
||||
template <typename genType>
|
||||
GLM_FUNC_DECL genType refract(
|
||||
genType const & I,
|
||||
genType const & N,
|
||||
typename genType::T const & eta);
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_DECL vecType<T, P> refract(
|
||||
vecType<T, P> const & I,
|
||||
vecType<T, P> const & N,
|
||||
T const & eta);
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
@ -26,6 +26,8 @@
|
||||
/// @author Christophe Riccio
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "type_vec2.hpp"
|
||||
#include "type_vec4.hpp"
|
||||
#include "type_float.hpp"
|
||||
|
||||
namespace glm
|
||||
|
@ -38,6 +38,8 @@
|
||||
#ifndef glm_core_func_integer
|
||||
#define glm_core_func_integer GLM_VERSION
|
||||
|
||||
#include "setup.hpp"
|
||||
|
||||
namespace glm
|
||||
{
|
||||
/// @addtogroup core_func_integer
|
||||
|
@ -26,6 +26,11 @@
|
||||
/// @author Christophe Riccio
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "type_vec2.hpp"
|
||||
#include "type_vec3.hpp"
|
||||
#include "type_vec4.hpp"
|
||||
#include "type_int.hpp"
|
||||
#include "_vectorize.hpp"
|
||||
#if(GLM_ARCH != GLM_ARCH_PURE)
|
||||
#if(GLM_COMPILER & GLM_COMPILER_VC)
|
||||
# include <intrin.h>
|
||||
|
@ -38,6 +38,11 @@
|
||||
#ifndef glm_core_func_noise
|
||||
#define glm_core_func_noise GLM_VERSION
|
||||
|
||||
#include "type_vec1.hpp"
|
||||
#include "type_vec2.hpp"
|
||||
#include "type_vec3.hpp"
|
||||
#include "setup.hpp"
|
||||
|
||||
namespace glm
|
||||
{
|
||||
/// @addtogroup core_func_noise
|
||||
|
@ -36,6 +36,9 @@
|
||||
#ifndef GLM_CORE_func_packing
|
||||
#define GLM_CORE_func_packing GLM_VERSION
|
||||
|
||||
#include "type_vec2.hpp"
|
||||
#include "type_vec4.hpp"
|
||||
|
||||
namespace glm
|
||||
{
|
||||
/// @addtogroup core_func_packing
|
||||
@ -52,7 +55,7 @@ namespace glm
|
||||
///
|
||||
/// @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);
|
||||
GLM_FUNC_DECL uint 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.
|
||||
@ -65,7 +68,7 @@ namespace glm
|
||||
///
|
||||
/// @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);
|
||||
GLM_FUNC_DECL uint 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.
|
||||
@ -78,7 +81,7 @@ namespace glm
|
||||
///
|
||||
/// @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);
|
||||
GLM_FUNC_DECL uint 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.
|
||||
@ -91,7 +94,7 @@ namespace glm
|
||||
///
|
||||
/// @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);
|
||||
GLM_FUNC_DECL uint 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.
|
||||
@ -104,7 +107,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(uint32 const & p);
|
||||
GLM_FUNC_DECL vec2 unpackUnorm2x16(uint 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.
|
||||
@ -117,7 +120,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(uint32 const & p);
|
||||
GLM_FUNC_DECL vec2 unpackSnorm2x16(uint 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.
|
||||
@ -130,7 +133,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(uint32 const & p);
|
||||
GLM_FUNC_DECL vec4 unpackUnorm4x8(uint 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.
|
||||
@ -143,7 +146,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(uint32 const & p);
|
||||
GLM_FUNC_DECL vec4 unpackSnorm4x8(uint const & 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.
|
||||
@ -172,7 +175,7 @@ namespace glm
|
||||
///
|
||||
/// @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 uint32 packHalf2x16(vec2 const & v);
|
||||
GLM_FUNC_DECL uint packHalf2x16(vec2 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,
|
||||
/// interpreting those values as 16-bit floating-point numbers according to the OpenGL Specification,
|
||||
@ -182,7 +185,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(uint32 const & v);
|
||||
GLM_FUNC_DECL vec2 unpackHalf2x16(uint const & v);
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
@ -190,4 +193,3 @@ namespace glm
|
||||
#include "func_packing.inl"
|
||||
|
||||
#endif//GLM_CORE_func_packing
|
||||
|
||||
|
@ -26,57 +26,59 @@
|
||||
/// @author Christophe Riccio
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "func_common.hpp"
|
||||
#include "type_half.hpp"
|
||||
#include "../fwd.hpp"
|
||||
|
||||
namespace glm
|
||||
{
|
||||
GLM_FUNC_QUALIFIER uint32 packUnorm2x16(vec2 const & v)
|
||||
GLM_FUNC_QUALIFIER uint packUnorm2x16(vec2 const & v)
|
||||
{
|
||||
u16vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 65535.0f));
|
||||
return *reinterpret_cast<uint32*>(&Topack);
|
||||
return *reinterpret_cast<uint*>(&Topack);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x16(uint32 const & p)
|
||||
GLM_FUNC_QUALIFIER vec2 unpackUnorm2x16(uint const & p)
|
||||
{
|
||||
vec2 Unpack(*reinterpret_cast<u16vec2*>(const_cast<uint32*>(&p)));
|
||||
vec2 Unpack(*reinterpret_cast<u16vec2*>(const_cast<uint*>(&p)));
|
||||
return Unpack * float(1.5259021896696421759365224689097e-5); // 1.0 / 65535.0
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint32 packSnorm2x16(vec2 const & v)
|
||||
GLM_FUNC_QUALIFIER uint packSnorm2x16(vec2 const & v)
|
||||
{
|
||||
i16vec2 Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f));
|
||||
return *reinterpret_cast<uint32*>(&Topack);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER vec2 unpackSnorm2x16(uint32 const & p)
|
||||
GLM_FUNC_QUALIFIER vec2 unpackSnorm2x16(uint const & p)
|
||||
{
|
||||
vec2 Unpack(*reinterpret_cast<i16vec2*>(const_cast<uint32*>(&p)));
|
||||
vec2 Unpack(*reinterpret_cast<i16vec2*>(const_cast<uint*>(&p)));
|
||||
return clamp(
|
||||
Unpack * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f,
|
||||
-1.0f, 1.0f);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint32 packUnorm4x8(vec4 const & v)
|
||||
GLM_FUNC_QUALIFIER uint packUnorm4x8(vec4 const & v)
|
||||
{
|
||||
u8vec4 Topack(round(clamp(v, 0.0f, 1.0f) * 255.0f));
|
||||
return *reinterpret_cast<uint32*>(&Topack);
|
||||
return *reinterpret_cast<uint*>(&Topack);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x8(uint32 const & p)
|
||||
GLM_FUNC_QUALIFIER vec4 unpackUnorm4x8(uint const & p)
|
||||
{
|
||||
vec4 Unpack(*reinterpret_cast<u8vec4*>(const_cast<uint32*>(&p)));
|
||||
vec4 Unpack(*reinterpret_cast<u8vec4*>(const_cast<uint*>(&p)));
|
||||
return Unpack * float(0.0039215686274509803921568627451); // 1 / 255
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER uint32 packSnorm4x8(vec4 const & v)
|
||||
GLM_FUNC_QUALIFIER uint packSnorm4x8(vec4 const & v)
|
||||
{
|
||||
i8vec4 Topack(round(clamp(v ,-1.0f, 1.0f) * 127.0f));
|
||||
return *reinterpret_cast<uint32*>(&Topack);
|
||||
return *reinterpret_cast<uint*>(&Topack);
|
||||
}
|
||||
|
||||
GLM_FUNC_QUALIFIER glm::vec4 unpackSnorm4x8(uint32 const & p)
|
||||
GLM_FUNC_QUALIFIER glm::vec4 unpackSnorm4x8(uint const & p)
|
||||
{
|
||||
vec4 Unpack(*reinterpret_cast<i8vec4*>(const_cast<uint32*>(&p)));
|
||||
vec4 Unpack(*reinterpret_cast<i8vec4*>(const_cast<uint*>(&p)));
|
||||
return clamp(
|
||||
Unpack * 0.0078740157480315f, // 1.0f / 127.0f
|
||||
-1.0f, 1.0f);
|
||||
|
@ -134,24 +134,6 @@ namespace detail
|
||||
enum{ID = float_or_int_value::GLM_FLOAT};
|
||||
};
|
||||
|
||||
union uif32
|
||||
{
|
||||
GLM_FUNC_QUALIFIER uif32() :
|
||||
i(0)
|
||||
{}
|
||||
|
||||
GLM_FUNC_QUALIFIER uif32(float f) :
|
||||
f(f)
|
||||
{}
|
||||
|
||||
GLM_FUNC_QUALIFIER uif32(uint32 i) :
|
||||
i(i)
|
||||
{}
|
||||
|
||||
float f;
|
||||
uint32 i;
|
||||
};
|
||||
|
||||
union uif64
|
||||
{
|
||||
GLM_FUNC_QUALIFIER uif64() :
|
||||
|
@ -43,6 +43,24 @@ namespace detail
|
||||
return f;
|
||||
}
|
||||
|
||||
union uif32
|
||||
{
|
||||
GLM_FUNC_QUALIFIER uif32() :
|
||||
i(0)
|
||||
{}
|
||||
|
||||
GLM_FUNC_QUALIFIER uif32(float f) :
|
||||
f(f)
|
||||
{}
|
||||
|
||||
GLM_FUNC_QUALIFIER uif32(uint32 i) :
|
||||
i(i)
|
||||
{}
|
||||
|
||||
float f;
|
||||
uint32 i;
|
||||
};
|
||||
|
||||
GLM_FUNC_QUALIFIER float toFloat32(hdata value)
|
||||
{
|
||||
int s = (value >> 15) & 0x00000001;
|
||||
|
@ -10,7 +10,6 @@
|
||||
//#include <boost/array.hpp>
|
||||
//#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
//#include <boost/thread/thread.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
#include <cstdio>
|
||||
@ -320,6 +319,57 @@ namespace test_mix
|
||||
}
|
||||
}//namespace test_mix
|
||||
|
||||
namespace test_step
|
||||
{
|
||||
template <typename EDGE, typename VEC>
|
||||
struct test
|
||||
{
|
||||
EDGE edge;
|
||||
VEC x;
|
||||
VEC result;
|
||||
};
|
||||
|
||||
test<float, glm::vec4> TestVec4Scalar [] =
|
||||
{
|
||||
{ 0.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
|
||||
{ 1.0f, glm::vec4(1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
|
||||
{ 0.0f, glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(0.0f) }
|
||||
};
|
||||
|
||||
test<glm::vec4, glm::vec4> TestVec4Vector [] =
|
||||
{
|
||||
{ glm::vec4(-1.0f, -2.0f, -3.0f, -4.0f), glm::vec4(-2.0f, -3.0f, -4.0f, -5.0f), glm::vec4(0.0f) },
|
||||
{ glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(1.0f) },
|
||||
{ glm::vec4( 2.0f, 3.0f, 4.0f, 5.0f), glm::vec4( 1.0f, 2.0f, 3.0f, 4.0f), glm::vec4(0.0f) },
|
||||
{ glm::vec4( 0.0f, 1.0f, 2.0f, 3.0f), glm::vec4(-1.0f,-2.0f,-3.0f,-4.0f), glm::vec4(0.0f) }
|
||||
};
|
||||
|
||||
int run()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
// vec4 and float
|
||||
{
|
||||
for (std::size_t i = 0; i < sizeof(TestVec4Scalar) / sizeof(test<float, glm::vec4>); ++i)
|
||||
{
|
||||
glm::vec4 Result = glm::step(TestVec4Scalar[i].edge, TestVec4Scalar[i].x);
|
||||
Error += glm::all(glm::epsilonEqual(Result, TestVec4Scalar[i].result, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
// vec4 and vec4
|
||||
{
|
||||
for (std::size_t i = 0; i < sizeof(TestVec4Vector) / sizeof(test<glm::vec4, glm::vec4>); ++i)
|
||||
{
|
||||
glm::vec4 Result = glm::step(TestVec4Vector[i].edge, TestVec4Vector[i].x);
|
||||
Error += glm::all(glm::epsilonEqual(Result, TestVec4Vector[i].result, glm::epsilon<float>())) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace test_step
|
||||
|
||||
int test_round()
|
||||
{
|
||||
int Error = 0;
|
||||
@ -582,6 +632,7 @@ int main()
|
||||
Error += test_modf();
|
||||
Error += test_floatBitsToInt();
|
||||
Error += test_floatBitsToUint();
|
||||
Error += test_step::run();
|
||||
Error += test_mix::run();
|
||||
Error += test_round();
|
||||
Error += test_roundEven();
|
||||
|
@ -7,7 +7,7 @@
|
||||
// File : test/core/func_geometric.cpp
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/core/func_geometric.hpp>
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
|
||||
int test_reflect()
|
||||
|
@ -7,7 +7,7 @@
|
||||
// File : test/core/func_integer.cpp
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/core/func_integer.hpp>
|
||||
#include <iostream>
|
||||
|
||||
enum result
|
||||
|
@ -7,7 +7,7 @@
|
||||
// File : test/core/func_noise.cpp
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/core/func_noise.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
// File : test/core/func_packing.cpp
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/core/func_packing.hpp>
|
||||
#include <glm/gtc/type_precision.hpp>
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
#include <vector>
|
||||
|
Loading…
Reference in New Issue
Block a user