mirror of
https://github.com/g-truc/glm.git
synced 2024-11-23 09:14:34 +00:00
Extended bit field functions: #4
This commit is contained in:
parent
6157ddd174
commit
7c67703bca
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user