Fixed GLM_GTX_bit extension
This commit is contained in:
parent
64677b50a0
commit
e724e5170c
@ -38,8 +38,11 @@ namespace glm
|
|||||||
//! Component wise extraction of bit fields.
|
//! Component wise extraction of bit fields.
|
||||||
//! genType and genIType could be a scalar or a vector.
|
//! genType and genIType could be a scalar or a vector.
|
||||||
//! From GLM_GTX_bit extension.
|
//! From GLM_GTX_bit extension.
|
||||||
template <typename genType, typename genIType>
|
template <typename genIUType, typename sizeType>
|
||||||
genIType extractField(genType const & v, genIType const & first, genIType const & count);
|
genIUType extractField(
|
||||||
|
genIUType const & v,
|
||||||
|
sizeType const & first,
|
||||||
|
sizeType const & count);
|
||||||
|
|
||||||
//! Find the lowest bit set to 1 in a integer variable.
|
//! Find the lowest bit set to 1 in a integer variable.
|
||||||
//! From GLM_GTX_bit extension.
|
//! From GLM_GTX_bit extension.
|
||||||
|
130
glm/gtx/bit.inl
130
glm/gtx/bit.inl
@ -92,141 +92,147 @@ inline genIType extractField
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
assert(first + count < sizeof(double));
|
assert(first + count < sizeof(double));
|
||||||
return (detail::uif64(value).i << first) >> ((sizeof(double) << 3) - count);
|
return (detail::uif64(value).i << first) >> ((sizeof(double) << genIType(3)) - count);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename genType, typename genIType>
|
template <typename genIUType, typename sizeType>
|
||||||
inline genIType extractField
|
inline genIUType extractField
|
||||||
(
|
(
|
||||||
genType const & value,
|
genIUType const & Value,
|
||||||
genIType const & first,
|
sizeType const & First,
|
||||||
genIType const & count
|
sizeType const & Count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
assert(first + count < sizeof(genType));
|
sizeType GenSize = sizeof(genIUType) << 3;
|
||||||
return (value << first) >> ((sizeof(genType) << 3) - count);
|
|
||||||
|
assert(First + Count <= GenSize);
|
||||||
|
|
||||||
|
genIUType ShiftLeft = Count ? Value << (GenSize - (Count + First)) : 0;
|
||||||
|
genIUType ShiftBack = ShiftLeft >> genIUType(GenSize - Count);
|
||||||
|
|
||||||
|
return ShiftBack;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename valType, typename valIType>
|
template <typename genIUType, typename sizeType>
|
||||||
inline detail::tvec2<valIType> extractField
|
inline detail::tvec2<genIUType> extractField
|
||||||
(
|
(
|
||||||
detail::tvec2<valType> const & value,
|
detail::tvec2<genIUType> const & value,
|
||||||
valIType const & first,
|
sizeType const & first,
|
||||||
valIType const & count
|
sizeType const & count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tvec2<valIType>(
|
return detail::tvec2<genIUType>(
|
||||||
extractField(value[0], first, count),
|
extractField(value[0], first, count),
|
||||||
extractField(value[1], first, count));
|
extractField(value[1], first, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename valType, typename valIType>
|
template <typename genIUType, typename sizeType>
|
||||||
inline detail::tvec3<valIType> extractField
|
inline detail::tvec3<genIUType> extractField
|
||||||
(
|
(
|
||||||
detail::tvec3<valType> const & value,
|
detail::tvec3<genIUType> const & value,
|
||||||
valIType const & first,
|
sizeType const & first,
|
||||||
valIType const & count
|
sizeType const & count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tvec3<valIType>(
|
return detail::tvec3<genIUType>(
|
||||||
extractField(value[0], first, count),
|
extractField(value[0], first, count),
|
||||||
extractField(value[1], first, count),
|
extractField(value[1], first, count),
|
||||||
extractField(value[2], first, count));
|
extractField(value[2], first, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename valType, typename valIType>
|
template <typename genIUType, typename sizeType>
|
||||||
inline detail::tvec4<valIType> extractField
|
inline detail::tvec4<genIUType> extractField
|
||||||
(
|
(
|
||||||
detail::tvec4<valType> const & value,
|
detail::tvec4<genIUType> const & value,
|
||||||
valIType const & first,
|
sizeType const & first,
|
||||||
valIType const & count
|
sizeType const & count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tvec4<valIType>(
|
return detail::tvec4<genIUType>(
|
||||||
extractField(value[0], first, count),
|
extractField(value[0], first, count),
|
||||||
extractField(value[1], first, count),
|
extractField(value[1], first, count),
|
||||||
extractField(value[2], first, count),
|
extractField(value[2], first, count),
|
||||||
extractField(value[3], first, count));
|
extractField(value[3], first, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename valType, typename valIType>
|
template <typename genIUType, typename sizeType>
|
||||||
inline detail::tvec2<valIType> extractField
|
inline detail::tvec2<genIUType> extractField
|
||||||
(
|
(
|
||||||
detail::tvec2<valType> const & value,
|
detail::tvec2<genIUType> const & value,
|
||||||
detail::tvec2<valIType> const & first,
|
detail::tvec2<sizeType> const & first,
|
||||||
detail::tvec2<valIType> const & count
|
detail::tvec2<sizeType> const & count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tvec2<valIType>(
|
return detail::tvec2<genIUType>(
|
||||||
extractField(value[0], first[0], count[0]),
|
extractField(value[0], first[0], count[0]),
|
||||||
extractField(value[1], first[1], count[1]));
|
extractField(value[1], first[1], count[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename valType, typename valIType>
|
template <typename genIUType, typename sizeType>
|
||||||
inline detail::tvec3<valIType> extractField
|
inline detail::tvec3<genIUType> extractField
|
||||||
(
|
(
|
||||||
detail::tvec3<valType> const & value,
|
detail::tvec3<genIUType> const & value,
|
||||||
detail::tvec3<valIType> const & first,
|
detail::tvec3<sizeType> const & first,
|
||||||
detail::tvec3<valIType> const & count
|
detail::tvec3<sizeType> const & count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tvec3<valIType>(
|
return detail::tvec3<genIUType>(
|
||||||
extractField(value[0], first[0], count[0]),
|
extractField(value[0], first[0], count[0]),
|
||||||
extractField(value[1], first[1], count[1]),
|
extractField(value[1], first[1], count[1]),
|
||||||
extractField(value[2], first[2], count[2]));
|
extractField(value[2], first[2], count[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename valType, typename valIType>
|
template <typename genIUType, typename sizeType>
|
||||||
inline detail::tvec4<valIType> extractField
|
inline detail::tvec4<genIUType> extractField
|
||||||
(
|
(
|
||||||
detail::tvec4<valType> const & value,
|
detail::tvec4<genIUType> const & value,
|
||||||
detail::tvec4<valIType> const & first,
|
detail::tvec4<sizeType> const & first,
|
||||||
detail::tvec4<valIType> const & count
|
detail::tvec4<sizeType> const & count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tvec4<valIType>(
|
return detail::tvec4<genIUType>(
|
||||||
extractField(value[0], first[0], count[0]),
|
extractField(value[0], first[0], count[0]),
|
||||||
extractField(value[1], first[1], count[1]),
|
extractField(value[1], first[1], count[1]),
|
||||||
extractField(value[2], first[2], count[2]),
|
extractField(value[2], first[2], count[2]),
|
||||||
extractField(value[3], first[3], count[3]));
|
extractField(value[3], first[3], count[3]));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename valType, typename valIType>
|
template <typename genIUType, typename sizeType>
|
||||||
inline detail::tvec2<valIType> extractField
|
inline detail::tvec2<genIUType> extractField
|
||||||
(
|
(
|
||||||
valType const & value,
|
genIUType const & value,
|
||||||
detail::tvec2<valIType> const & first,
|
detail::tvec2<sizeType> const & first,
|
||||||
detail::tvec2<valIType> const & count
|
detail::tvec2<sizeType> const & count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tvec2<valIType>(
|
return detail::tvec2<genIUType>(
|
||||||
extractField(value, first[0], count[0]),
|
extractField(value, first[0], count[0]),
|
||||||
extractField(value, first[1], count[1]));
|
extractField(value, first[1], count[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename valType, typename valIType>
|
template <typename genIUType, typename sizeType>
|
||||||
inline detail::tvec3<valIType> extractField
|
inline detail::tvec3<genIUType> extractField
|
||||||
(
|
(
|
||||||
valType const & value,
|
genIUType const & value,
|
||||||
detail::tvec3<valIType> const & first,
|
detail::tvec3<sizeType> const & first,
|
||||||
detail::tvec3<valIType> const & count
|
detail::tvec3<sizeType> const & count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tvec3<valIType>(
|
return detail::tvec3<genIUType>(
|
||||||
extractField(value, first[0], count[0]),
|
extractField(value, first[0], count[0]),
|
||||||
extractField(value, first[1], count[1]),
|
extractField(value, first[1], count[1]),
|
||||||
extractField(value, first[2], count[2]));
|
extractField(value, first[2], count[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename valType, typename valIType>
|
template <typename genIUType, typename sizeType>
|
||||||
inline detail::tvec4<valIType> extractField
|
inline detail::tvec4<genIUType> extractField
|
||||||
(
|
(
|
||||||
valType const & value,
|
genIUType const & value,
|
||||||
detail::tvec4<valIType> const & first,
|
detail::tvec4<sizeType> const & first,
|
||||||
detail::tvec4<valIType> const & count
|
detail::tvec4<sizeType> const & count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return detail::tvec4<valIType>(
|
return detail::tvec4<genIUType>(
|
||||||
extractField(value, first[0], count[0]),
|
extractField(value, first[0], count[0]),
|
||||||
extractField(value, first[1], count[1]),
|
extractField(value, first[1], count[1]),
|
||||||
extractField(value, first[2], count[2]),
|
extractField(value, first[2], count[2]),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user