diff --git a/glm/gtc/bitfield.hpp b/glm/gtc/bitfield.hpp index 322d73a8..f3c94cfd 100644 --- a/glm/gtc/bitfield.hpp +++ b/glm/gtc/bitfield.hpp @@ -55,21 +55,63 @@ namespace glm /// @{ /// Build a mask of 'count' bits + /// /// @see gtc_bitfield GLM_FUNC_DECL int mask(int Bits); - + + /// Build a mask of 'count' bits + /// + /// @see gtc_bitfield template class vecType> GLM_FUNC_DECL vecType mask(vecType const & v); - /// Rotate all bits to the right. + /// Rotate all bits to the right. All the bits dropped in the right side are inserted back on the left side. + /// + /// @see gtc_bitfield + template + GLM_FUNC_DECL genIUType bitfieldRotateRight(genIUType In, int Shift); + + /// Rotate all bits to the right. All the bits dropped in the right side are inserted back on the left side. + /// + /// @see gtc_bitfield + template class vecType> + GLM_FUNC_DECL vecType bitfieldRotateRight(vecType const & In, int Shift); + + /// Rotate all bits to the left. All the bits dropped in the left side are inserted back on the right side. + /// + /// @see gtc_bitfield + template + GLM_FUNC_DECL genIUType bitfieldRotateLeft(genIUType In, int Shift); + + /// Rotate all bits to the left. All the bits dropped in the left side are inserted back on the right side. + /// + /// @see gtc_bitfield + template class vecType> + GLM_FUNC_DECL vecType bitfieldRotateLeft(vecType const & In, int Shift); + + /// Set to 1 a range of bits. + /// + /// @see gtc_bitfield + template + GLM_FUNC_DECL genIUType bitfieldFillOne(genIUType Value, int FirstBit, int BitCount); + + /// Set to 1 a range of bits. + /// + /// @see gtc_bitfield + template class vecType> + GLM_FUNC_DECL vecType bitfieldFillOne(vecType const & Value, int FirstBit, int BitCount); + + /// Set to 0 a range of bits. + /// /// @see gtc_bitfield - template - GLM_FUNC_DECL genType bitRotateRight(genType In, int Shift); + template + GLM_FUNC_DECL genIUType bitfieldFillZero(genIUType Value, int FirstBit, int BitCount); - /// Rotate all bits to the left. + /// Set to 0 a range of bits. + /// /// @see gtc_bitfield - template - GLM_FUNC_DECL genType bitRotateLeft(genType In, int Shift); + template class vecType> + GLM_FUNC_DECL vecType bitfieldFillZero(vecType const & Value, int FirstBit, int BitCount); /// Interleaves the bits of x and y. /// The first bit is the first bit of x followed by the first bit of y. diff --git a/glm/gtc/bitfield.inl b/glm/gtc/bitfield.inl index ae70dd92..b67ef0ca 100644 --- a/glm/gtc/bitfield.inl +++ b/glm/gtc/bitfield.inl @@ -257,41 +257,65 @@ namespace detail } template - GLM_FUNC_QUALIFIER genIType bitRotateRight(genIType In, int Shift) + GLM_FUNC_QUALIFIER genIType bitfieldRotateRight(genIType In, int Shift) { - GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitRotateRight' only accept integer values"); + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitfieldRotateRight' only accept integer values"); int const BitSize = static_cast(sizeof(genIType) * 8); return (In << static_cast(Shift)) | (In >> static_cast(BitSize - Shift)); } template class vecType> - GLM_FUNC_QUALIFIER vecType bitRotateRight(vecType const & In, int Shift) + GLM_FUNC_QUALIFIER vecType bitfieldRotateRight(vecType const & In, int Shift) { - GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitRotateRight' only accept integer values"); + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitfieldRotateRight' only accept integer values"); int const BitSize = static_cast(sizeof(T) * 8); return (In << static_cast(Shift)) | (In >> static_cast(BitSize - Shift)); } template - GLM_FUNC_QUALIFIER genIType bitRotateLeft(genIType In, int Shift) + GLM_FUNC_QUALIFIER genIType bitfieldRotateLeft(genIType In, int Shift) { - GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitRotateLeft' only accept integer values"); + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitfieldRotateLeft' only accept integer values"); int const BitSize = static_cast(sizeof(genIType) * 8); return (In >> static_cast(Shift)) | (In << static_cast(BitSize - Shift)); } template class vecType> - GLM_FUNC_QUALIFIER vecType bitRotateLeft(vecType const & In, int Shift) + GLM_FUNC_QUALIFIER vecType bitfieldRotateLeft(vecType const & In, int Shift) { - GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitRotateLeft' only accept integer values"); + GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitfieldRotateLeft' only accept integer values"); int const BitSize = static_cast(sizeof(T) * 8); return (In >> static_cast(Shift)) | (In << static_cast(BitSize - Shift)); } + template + GLM_FUNC_QUALIFIER genIUType bitfieldFillOne(genIUType Value, int FirstBit, int BitCount) + { + return Value | static_cast(mask(BitCount) << FirstBit); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType bitfieldFillOne(vecType const & Value, int FirstBit, int BitCount) + { + return Value | static_cast(mask(BitCount) << FirstBit); + } + + template + GLM_FUNC_QUALIFIER genIUType bitfieldFillZero(genIUType Value, int FirstBit, int BitCount) + { + return Value & static_cast(~(mask(BitCount) << FirstBit)); + } + + template class vecType> + GLM_FUNC_QUALIFIER vecType bitfieldFillZero(vecType const & Value, int FirstBit, int BitCount) + { + return Value & static_cast(~(mask(BitCount) << FirstBit)); + } + GLM_FUNC_QUALIFIER int16 bitfieldInterleave(int8 x, int8 y) { union sign8 diff --git a/glm/gtx/bit.hpp b/glm/gtx/bit.hpp index 23586940..c9314ed1 100644 --- a/glm/gtx/bit.hpp +++ b/glm/gtx/bit.hpp @@ -76,22 +76,6 @@ namespace glm template GLM_FUNC_DECL genType powerOfTwoNearest(genType const & value); - //! Set to 1 a range of bits. - /// @see gtx_bit - template - GLM_FUNC_DECL genIUType fillBitfieldWithOne( - genIUType const & Value, - int const & FromBit, - int const & ToBit); - - //! Set to 0 a range of bits. - /// @see gtx_bit - template - GLM_FUNC_DECL genIUType fillBitfieldWithZero( - genIUType const & Value, - int const & FromBit, - int const & ToBit); - /// @} } //namespace glm diff --git a/glm/gtx/bit.inl b/glm/gtx/bit.inl index 9ee27331..6bbb1cb0 100644 --- a/glm/gtx/bit.inl +++ b/glm/gtx/bit.inl @@ -152,38 +152,4 @@ namespace glm } VECTORIZE_VEC(powerOfTwoNearest) - - template - 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(signed i = 0; i <= ToBit; ++i) - Result |= (1 << i); - return Result; - } - - template - 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(signed i = 0; i <= ToBit; ++i) - Result &= ~(1 << i); - return Result; - } }//namespace glm