Extended bit field functions: #4

master
Christophe Riccio ago%!(EXTRA string=14 years)
parent 6157ddd174
commit 7c67703bca
  1. 16
      glm/gtx/bit.hpp
  2. 34
      glm/gtx/bit.inl

@ -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…
Cancel
Save