Replace function instanciations with macros by templates

master
Christophe Riccio ago%!(EXTRA string=11 years)
parent 47a6947736
commit 4fc68ffe49
  1. 45
      glm/detail/func_integer.hpp
  2. 168
      glm/detail/func_integer.inl
  3. 2
      glm/detail/type_mat2x2.hpp
  4. 2
      glm/detail/type_mat2x3.hpp
  5. 2
      glm/detail/type_mat2x4.hpp
  6. 2
      glm/detail/type_mat3x2.hpp
  7. 2
      glm/detail/type_mat3x3.hpp
  8. 2
      glm/detail/type_mat3x4.hpp
  9. 2
      glm/detail/type_mat4x2.hpp
  10. 2
      glm/detail/type_mat4x3.hpp
  11. 2
      glm/detail/type_mat4x4.hpp
  12. 2
      glm/detail/type_vec1.hpp
  13. 2
      glm/detail/type_vec2.hpp
  14. 2
      glm/detail/type_vec3.hpp
  15. 2
      glm/detail/type_vec4.hpp
  16. 1
      test/gtx/gtx_integer.cpp

@ -38,6 +38,9 @@
#pragma once #pragma once
#include "setup.hpp" #include "setup.hpp"
#include "precision.hpp"
#include "func_common.hpp"
#include "func_vector_relational.hpp"
namespace glm namespace glm
{ {
@ -113,13 +116,13 @@ namespace glm
/// offset and bits is greater than the number of bits used /// offset and bits is greater than the number of bits used
/// to store the operand. /// to store the operand.
/// ///
/// @tparam genIUType Signed or unsigned integer scalar or vector types. /// @tparam T Signed or unsigned integer scalar or vector types.
/// ///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldExtract.xml">GLSL bitfieldExtract man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldExtract.xml">GLSL bitfieldExtract man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <typename genIUType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL genIUType bitfieldExtract( GLM_FUNC_DECL vecType<T, P> bitfieldExtract(
genIUType const & Value, vecType<T, P> const & Value,
int const & Offset, int const & Offset,
int const & Bits); int const & Bits);
@ -133,14 +136,14 @@ namespace glm
/// offset and bits is greater than the number of bits used to /// offset and bits is greater than the number of bits used to
/// store the operand. /// store the operand.
/// ///
/// @tparam genIUType Signed or unsigned integer scalar or vector types. /// @tparam T Signed or unsigned integer scalar or vector types.
/// ///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldInsert.xml">GLSL bitfieldInsert man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldInsert.xml">GLSL bitfieldInsert man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <typename genIUType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL genIUType bitfieldInsert( GLM_FUNC_DECL vecType<T, P> bitfieldInsert(
genIUType const & Base, vecType<T, P> const & Base,
genIUType const & Insert, vecType<T, P> const & Insert,
int const & Offset, int const & Offset,
int const & Bits); int const & Bits);
@ -148,50 +151,50 @@ namespace glm
/// The bit numbered n of the result will be taken from bit (bits - 1) - n of value, /// The bit numbered n of the result will be taken from bit (bits - 1) - n of value,
/// where bits is the total number of bits used to represent value. /// where bits is the total number of bits used to represent value.
/// ///
/// @tparam genIUType Signed or unsigned integer scalar or vector types. /// @tparam T Signed or unsigned integer scalar or vector types.
/// ///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldReverse.xml">GLSL bitfieldReverse man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitfieldReverse.xml">GLSL bitfieldReverse man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
template <typename genIUType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL genIUType bitfieldReverse(genIUType const & Value); GLM_FUNC_DECL vecType<T, P> bitfieldReverse(vecType<T, P> const & v);
/// Returns the number of bits set to 1 in the binary representation of value. /// Returns the number of bits set to 1 in the binary representation of value.
/// ///
/// @tparam genIUType Signed or unsigned integer scalar or vector types. /// @tparam T Signed or unsigned integer scalar or vector types.
/// ///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitCount.xml">GLSL bitCount man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/bitCount.xml">GLSL bitCount man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
/// ///
/// @todo Clarify the declaration to specify that scalars are suported. /// @todo Clarify the declaration to specify that scalars are suported.
template <typename T, template <typename> class genIUType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL typename genIUType<T>::signed_type bitCount(genIUType<T> const & Value); GLM_FUNC_DECL vecType<int, P> bitCount(vecType<T, P> const & v);
/// Returns the bit number of the least significant bit set to /// Returns the bit number of the least significant bit set to
/// 1 in the binary representation of value. /// 1 in the binary representation of value.
/// If value is zero, -1 will be returned. /// If value is zero, -1 will be returned.
/// ///
/// @tparam genIUType Signed or unsigned integer scalar or vector types. /// @tparam T Signed or unsigned integer scalar or vector types.
/// ///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findLSB.xml">GLSL findLSB man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findLSB.xml">GLSL findLSB man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
/// ///
/// @todo Clarify the declaration to specify that scalars are suported. /// @todo Clarify the declaration to specify that scalars are suported.
template <typename T, template <typename> class genIUType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL typename genIUType<T>::signed_type findLSB(genIUType<T> const & Value); GLM_FUNC_DECL vecType<int, P> findLSB(vecType<T, P> const & v);
/// Returns the bit number of the most significant bit in the binary representation of value. /// Returns the bit number of the most significant bit in the binary representation of value.
/// For positive integers, the result will be the bit number of the most significant bit set to 1. /// For positive integers, the result will be the bit number of the most significant bit set to 1.
/// For negative integers, the result will be the bit number of the most significant /// For negative integers, the result will be the bit number of the most significant
/// bit set to 0. For a value of zero or negative one, -1 will be returned. /// bit set to 0. For a value of zero or negative one, -1 will be returned.
/// ///
/// @tparam genIUType Signed or unsigned integer scalar or vector types. /// @tparam T Signed or unsigned integer scalar or vector types.
/// ///
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findMSB.xml">GLSL findMSB man page</a> /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/findMSB.xml">GLSL findMSB man page</a>
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a> /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.8 Integer Functions</a>
/// ///
/// @todo Clarify the declaration to specify that scalars are suported. /// @todo Clarify the declaration to specify that scalars are suported.
template <typename T, template <typename> class genIUType> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL typename genIUType<T>::signed_type findMSB(genIUType<T> const & Value); GLM_FUNC_DECL vecType<int, P> findMSB(vecType<T, P> const & v);
/// @} /// @}
}//namespace glm }//namespace glm

@ -410,78 +410,57 @@ namespace glm
} }
// bitfieldReverse // bitfieldReverse
template <typename genIUType> template <typename T>
GLM_FUNC_QUALIFIER genIUType bitfieldReverse(genIUType const & Value) GLM_FUNC_QUALIFIER T bitfieldReverse(T v)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'bitfieldReverse' only accept integer values"); GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldReverse' only accept integer values");
genIUType Out = 0; return bitfieldReverse(tvec1<T>(v)).x;
std::size_t BitSize = sizeof(genIUType) * 8;
for(std::size_t i = 0; i < BitSize; ++i)
if(Value & (genIUType(1) << i))
Out |= genIUType(1) << (BitSize - 1 - i);
return Out;
} }
VECTORIZE_VEC(bitfieldReverse) template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> bitfieldReverse(vecType<T, P> const & v)
// bitCount
template <typename genIUType>
GLM_FUNC_QUALIFIER int bitCount(genIUType const & Value)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'bitCount' only accept integer values"); GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitfieldReverse' only accept integer values");
int Count = 0; vecType<T, P> Result(0);
for(std::size_t i = 0; i < sizeof(genIUType) * std::size_t(8); ++i) vecType<T, P> const Null(0);
T const BitSize = static_cast<T>(sizeof(T) * 8);
for(T i = 0; i < BitSize; ++i)
{ {
if(Value & (1 << i)) vecType<T, P> const BitSet(v & (static_cast<T>(1) << i));
++Count; vecType<T, P> const BitFirst(BitSet >> i);
Result |= BitFirst << (BitSize - 1 - i);
} }
return Count; return Result;
} }
template <typename T, precision P> // bitCount
GLM_FUNC_QUALIFIER tvec2<int, P> bitCount template <typename genIUType>
( GLM_FUNC_QUALIFIER int bitCount(genIUType x)
tvec2<T, P> const & value
)
{ {
return tvec2<int, P>( GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'bitCount' only accept integer values");
bitCount(value[0]),
bitCount(value[1])); return bitCount(tvec1(x)).x;
} }
template <typename T, precision P> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER tvec3<int, P> bitCount GLM_FUNC_QUALIFIER vecType<int, P> bitCount(vecType<T, P> const & v)
(
tvec3<T, P> const & value
)
{ {
return tvec3<int, P>( GLM_STATIC_ASSERT(std::numeric_limits<T>::is_integer, "'bitCount' only accept integer values");
bitCount(value[0]),
bitCount(value[1]),
bitCount(value[2]));
}
template <typename T, precision P> vecType<int, P> Count(0);
GLM_FUNC_QUALIFIER tvec4<int, P> bitCount for(std::size_t i = 0; i < sizeof(T) * std::size_t(8); ++i)
(
tvec4<T, P> const & value
)
{ {
return tvec4<int, P>( if(v & (static_cast<T>(1) << i))
bitCount(value[0]), ++Count;
bitCount(value[1]), }
bitCount(value[2]), return Count;
bitCount(value[3]));
} }
// findLSB // findLSB
template <typename genIUType> template <typename genIUType>
GLM_FUNC_QUALIFIER int findLSB GLM_FUNC_QUALIFIER int findLSB(genIUType Value)
(
genIUType const & Value
)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findLSB' only accept integer values"); GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findLSB' only accept integer values");
if(Value == 0) if(Value == 0)
@ -492,50 +471,19 @@ namespace glm
return Bit; return Bit;
} }
template <typename T, precision P> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER tvec2<int, P> findLSB GLM_FUNC_QUALIFIER vecType<int, P> findLSB(vecType<T, P> const & x)
(
tvec2<T, P> const & value
)
{ {
return tvec2<int, P>( GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findLSB' only accept integer values");
findLSB(value[0]),
findLSB(value[1]));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<int, P> findLSB
(
tvec3<T, P> const & value
)
{
return tvec3<int, P>(
findLSB(value[0]),
findLSB(value[1]),
findLSB(value[2]));
}
template <typename T, precision P> return detail::functor1<int, T, P, vecType>::call(findLSB, x);
GLM_FUNC_QUALIFIER tvec4<int, P> findLSB
(
tvec4<T, P> const & value
)
{
return tvec4<int, P>(
findLSB(value[0]),
findLSB(value[1]),
findLSB(value[2]),
findLSB(value[3]));
} }
// findMSB // findMSB
#if((GLM_ARCH != GLM_ARCH_PURE) && (GLM_COMPILER & GLM_COMPILER_VC)) #if (GLM_ARCH != GLM_ARCH_PURE) && (GLM_COMPILER & GLM_COMPILER_VC)
template <typename genIUType> template <typename genIUType>
GLM_FUNC_QUALIFIER int findMSB GLM_FUNC_QUALIFIER int findMSB(genIUType Value)
(
genIUType const & Value
)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values"); GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values");
if(Value == 0) if(Value == 0)
@ -585,14 +533,10 @@ namespace glm
Mmi = _mm_and_si128(Mmi, One); Mmi = _mm_and_si128(Mmi, One);
} }
return Bit; return Bit;
*/ */
template <typename genIUType> template <typename genIUType>
GLM_FUNC_QUALIFIER int findMSB GLM_FUNC_QUALIFIER int findMSB(genIUType Value)
(
genIUType const & Value
)
{ {
GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values"); GLM_STATIC_ASSERT(std::numeric_limits<genIUType>::is_integer, "'findMSB' only accept integer values");
@ -616,39 +560,9 @@ namespace glm
} }
#endif//(GLM_COMPILER) #endif//(GLM_COMPILER)
template <typename T, precision P> template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER tvec2<int, P> findMSB GLM_FUNC_QUALIFIER vecType<int, P> findMSB(vecType<T, P> const & x)
(
tvec2<T, P> const & value
)
{
return tvec2<int, P>(
findMSB(value[0]),
findMSB(value[1]));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<int, P> findMSB
(
tvec3<T, P> const & value
)
{
return tvec3<int, P>(
findMSB(value[0]),
findMSB(value[1]),
findMSB(value[2]));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<int, P> findMSB
(
tvec4<T, P> const & value
)
{ {
return tvec4<int, P>( return detail::functor1<int, T, P, vecType>::call(findMSB, x);
findMSB(value[0]),
findMSB(value[1]),
findMSB(value[2]),
findMSB(value[3]));
} }
}//namespace glm }//namespace glm

@ -36,7 +36,7 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P = defaultp>
struct tmat2x2 struct tmat2x2
{ {
typedef T value_type; typedef T value_type;

@ -37,7 +37,7 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P = defaultp>
struct tmat2x3 struct tmat2x3
{ {
typedef T value_type; typedef T value_type;

@ -37,7 +37,7 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P = defaultp>
struct tmat2x4 struct tmat2x4
{ {
typedef T value_type; typedef T value_type;

@ -37,7 +37,7 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P = defaultp>
struct tmat3x2 struct tmat3x2
{ {
typedef T value_type; typedef T value_type;

@ -36,7 +36,7 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P = defaultp>
struct tmat3x3 struct tmat3x3
{ {
typedef T value_type; typedef T value_type;

@ -37,7 +37,7 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P = defaultp>
struct tmat3x4 struct tmat3x4
{ {
typedef T value_type; typedef T value_type;

@ -37,7 +37,7 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P = defaultp>
struct tmat4x2 struct tmat4x2
{ {
typedef T value_type; typedef T value_type;

@ -37,7 +37,7 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P = defaultp>
struct tmat4x3 struct tmat4x3
{ {
typedef T value_type; typedef T value_type;

@ -36,7 +36,7 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P = defaultp>
struct tmat4x4 struct tmat4x4
{ {
typedef T value_type; typedef T value_type;

@ -41,7 +41,7 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P = defaultp>
struct tvec1 struct tvec1
{ {
////////////////////////////////////// //////////////////////////////////////

@ -41,7 +41,7 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P = defaultp>
struct tvec2 struct tvec2
{ {
////////////////////////////////////// //////////////////////////////////////

@ -41,7 +41,7 @@
namespace glm namespace glm
{ {
template <typename T, precision P> template <typename T, precision P = defaultp>
struct tvec3 struct tvec3
{ {
////////////////////////////////////// //////////////////////////////////////

@ -66,7 +66,7 @@ namespace detail
# endif # endif
}//namespace detail }//namespace detail
template <typename T, precision P> template <typename T, precision P = defaultp>
struct tvec4 struct tvec4
{ {
////////////////////////////////////// //////////////////////////////////////

@ -70,3 +70,4 @@ int main()
return Error; return Error;
} }

Loading…
Cancel
Save