Extended bit field functions: #4

This commit is contained in:
Christophe Riccio 2011-05-09 12:33:00 +01:00
parent 6157ddd174
commit 7c67703bca
2 changed files with 50 additions and 0 deletions

View File

@ -101,6 +101,22 @@ namespace glm
template <typename genType>
genType bitRotateLeft(genType const & In, std::size_t Shift);
//! Set to 1 a range of bits.
//! From GLM_GTX_bit extension.
template <typename genIUType>
genIUType fillBitfieldWithOne(
genIUType const & Value,
int const & FromBit,
int const & ToBit);
//! Set to 0 a range of bits.
//! From GLM_GTX_bit extension.
template <typename genIUType>
genIUType fillBitfieldWithZero(
genIUType const & Value,
int const & FromBit,
int const & ToBit);
///@}
}//namespace bit

View File

@ -738,6 +738,40 @@ GLM_FUNC_QUALIFIER detail::tvec4<valType> bitRotateLeft
bitRotateLeft(Value[3], Shift));
}
template <typename genIUType>
GLM_FUNC_QUALIFIER genIUType fillBitfieldWithOne
(
genIUType const & Value,
int const & FromBit,
int const & ToBit
)
{
assert(FromBit <= ToBit);
assert(ToBit <= sizeof(genIUType) * std::size_t(8));
genIUType Result = Value;
for(std::size_t i = 0; i <= ToBit; ++i)
Result |= (1 << i);
return Result;
}
template <typename genIUType>
GLM_FUNC_QUALIFIER genIUType fillBitfieldWithZero
(
genIUType const & Value,
int const & FromBit,
int const & ToBit
)
{
assert(FromBit <= ToBit);
assert(ToBit <= sizeof(genIUType) * std::size_t(8));
genIUType Result = Value;
for(std::size_t i = 0; i <= ToBit; ++i)
Result &= ~(1 << i);
return Result;
}
}//namespace bit
}//namespace gtx
}//namespace glm