9
3

bitfield.hpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /// @ref gtc_bitfield
  2. /// @file glm/gtc/bitfield.hpp
  3. ///
  4. /// @see core (dependence)
  5. /// @see gtc_bitfield (dependence)
  6. ///
  7. /// @defgroup gtc_bitfield GLM_GTC_bitfield
  8. /// @ingroup gtc
  9. ///
  10. /// Include <glm/gtc/bitfield.hpp> to use the features of this extension.
  11. ///
  12. /// Allow to perform bit operations on integer values
  13. #include "../detail/setup.hpp"
  14. #pragma once
  15. // Dependencies
  16. #include "../ext/scalar_int_sized.hpp"
  17. #include "../ext/scalar_uint_sized.hpp"
  18. #include "../detail/qualifier.hpp"
  19. #include "../detail/_vectorize.hpp"
  20. #include "type_precision.hpp"
  21. #include <limits>
  22. #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
  23. # pragma message("GLM: GLM_GTC_bitfield extension included")
  24. #endif
  25. namespace glm
  26. {
  27. /// @addtogroup gtc_bitfield
  28. /// @{
  29. /// Build a mask of 'count' bits
  30. ///
  31. /// @see gtc_bitfield
  32. template<typename genIUType>
  33. GLM_FUNC_DECL genIUType mask(genIUType Bits);
  34. /// Build a mask of 'count' bits
  35. ///
  36. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  37. /// @tparam T Signed and unsigned integer scalar types
  38. /// @tparam Q Value from qualifier enum
  39. ///
  40. /// @see gtc_bitfield
  41. template<length_t L, typename T, qualifier Q>
  42. GLM_FUNC_DECL vec<L, T, Q> mask(vec<L, T, Q> const& v);
  43. /// Rotate all bits to the right. All the bits dropped in the right side are inserted back on the left side.
  44. ///
  45. /// @see gtc_bitfield
  46. template<typename genIUType>
  47. GLM_FUNC_DECL genIUType bitfieldRotateRight(genIUType In, int Shift);
  48. /// Rotate all bits to the right. All the bits dropped in the right side are inserted back on the left side.
  49. ///
  50. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  51. /// @tparam T Signed and unsigned integer scalar types
  52. /// @tparam Q Value from qualifier enum
  53. ///
  54. /// @see gtc_bitfield
  55. template<length_t L, typename T, qualifier Q>
  56. GLM_FUNC_DECL vec<L, T, Q> bitfieldRotateRight(vec<L, T, Q> const& In, int Shift);
  57. /// Rotate all bits to the left. All the bits dropped in the left side are inserted back on the right side.
  58. ///
  59. /// @see gtc_bitfield
  60. template<typename genIUType>
  61. GLM_FUNC_DECL genIUType bitfieldRotateLeft(genIUType In, int Shift);
  62. /// Rotate all bits to the left. All the bits dropped in the left side are inserted back on the right side.
  63. ///
  64. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  65. /// @tparam T Signed and unsigned integer scalar types
  66. /// @tparam Q Value from qualifier enum
  67. ///
  68. /// @see gtc_bitfield
  69. template<length_t L, typename T, qualifier Q>
  70. GLM_FUNC_DECL vec<L, T, Q> bitfieldRotateLeft(vec<L, T, Q> const& In, int Shift);
  71. /// Set to 1 a range of bits.
  72. ///
  73. /// @see gtc_bitfield
  74. template<typename genIUType>
  75. GLM_FUNC_DECL genIUType bitfieldFillOne(genIUType Value, int FirstBit, int BitCount);
  76. /// Set to 1 a range of bits.
  77. ///
  78. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  79. /// @tparam T Signed and unsigned integer scalar types
  80. /// @tparam Q Value from qualifier enum
  81. ///
  82. /// @see gtc_bitfield
  83. template<length_t L, typename T, qualifier Q>
  84. GLM_FUNC_DECL vec<L, T, Q> bitfieldFillOne(vec<L, T, Q> const& Value, int FirstBit, int BitCount);
  85. /// Set to 0 a range of bits.
  86. ///
  87. /// @see gtc_bitfield
  88. template<typename genIUType>
  89. GLM_FUNC_DECL genIUType bitfieldFillZero(genIUType Value, int FirstBit, int BitCount);
  90. /// Set to 0 a range of bits.
  91. ///
  92. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  93. /// @tparam T Signed and unsigned integer scalar types
  94. /// @tparam Q Value from qualifier enum
  95. ///
  96. /// @see gtc_bitfield
  97. template<length_t L, typename T, qualifier Q>
  98. GLM_FUNC_DECL vec<L, T, Q> bitfieldFillZero(vec<L, T, Q> const& Value, int FirstBit, int BitCount);
  99. /// Interleaves the bits of x and y.
  100. /// The first bit is the first bit of x followed by the first bit of y.
  101. /// The other bits are interleaved following the previous sequence.
  102. ///
  103. /// @see gtc_bitfield
  104. GLM_FUNC_DECL int16 bitfieldInterleave(int8 x, int8 y);
  105. /// Interleaves the bits of x and y.
  106. /// The first bit is the first bit of x followed by the first bit of y.
  107. /// The other bits are interleaved following the previous sequence.
  108. ///
  109. /// @see gtc_bitfield
  110. GLM_FUNC_DECL uint16 bitfieldInterleave(uint8 x, uint8 y);
  111. /// Interleaves the bits of x and y.
  112. /// The first bit is the first bit of v.x followed by the first bit of v.y.
  113. /// The other bits are interleaved following the previous sequence.
  114. ///
  115. /// @see gtc_bitfield
  116. GLM_FUNC_DECL uint16 bitfieldInterleave(u8vec2 const& v);
  117. /// Deinterleaves the bits of x.
  118. ///
  119. /// @see gtc_bitfield
  120. GLM_FUNC_DECL glm::u8vec2 bitfieldDeinterleave(glm::uint16 x);
  121. /// Interleaves the bits of x and y.
  122. /// The first bit is the first bit of x followed by the first bit of y.
  123. /// The other bits are interleaved following the previous sequence.
  124. ///
  125. /// @see gtc_bitfield
  126. GLM_FUNC_DECL int32 bitfieldInterleave(int16 x, int16 y);
  127. /// Interleaves the bits of x and y.
  128. /// The first bit is the first bit of x followed by the first bit of y.
  129. /// The other bits are interleaved following the previous sequence.
  130. ///
  131. /// @see gtc_bitfield
  132. GLM_FUNC_DECL uint32 bitfieldInterleave(uint16 x, uint16 y);
  133. /// Interleaves the bits of x and y.
  134. /// The first bit is the first bit of v.x followed by the first bit of v.y.
  135. /// The other bits are interleaved following the previous sequence.
  136. ///
  137. /// @see gtc_bitfield
  138. GLM_FUNC_DECL uint32 bitfieldInterleave(u16vec2 const& v);
  139. /// Deinterleaves the bits of x.
  140. ///
  141. /// @see gtc_bitfield
  142. GLM_FUNC_DECL glm::u16vec2 bitfieldDeinterleave(glm::uint32 x);
  143. /// Interleaves the bits of x and y.
  144. /// The first bit is the first bit of x followed by the first bit of y.
  145. /// The other bits are interleaved following the previous sequence.
  146. ///
  147. /// @see gtc_bitfield
  148. GLM_FUNC_DECL int64 bitfieldInterleave(int32 x, int32 y);
  149. /// Interleaves the bits of x and y.
  150. /// The first bit is the first bit of x followed by the first bit of y.
  151. /// The other bits are interleaved following the previous sequence.
  152. ///
  153. /// @see gtc_bitfield
  154. GLM_FUNC_DECL uint64 bitfieldInterleave(uint32 x, uint32 y);
  155. /// Interleaves the bits of x and y.
  156. /// The first bit is the first bit of v.x followed by the first bit of v.y.
  157. /// The other bits are interleaved following the previous sequence.
  158. ///
  159. /// @see gtc_bitfield
  160. GLM_FUNC_DECL uint64 bitfieldInterleave(u32vec2 const& v);
  161. /// Deinterleaves the bits of x.
  162. ///
  163. /// @see gtc_bitfield
  164. GLM_FUNC_DECL glm::u32vec2 bitfieldDeinterleave(glm::uint64 x);
  165. /// Interleaves the bits of x, y and z.
  166. /// The first bit is the first bit of x followed by the first bit of y and the first bit of z.
  167. /// The other bits are interleaved following the previous sequence.
  168. ///
  169. /// @see gtc_bitfield
  170. GLM_FUNC_DECL int32 bitfieldInterleave(int8 x, int8 y, int8 z);
  171. /// Interleaves the bits of x, y and z.
  172. /// The first bit is the first bit of x followed by the first bit of y and the first bit of z.
  173. /// The other bits are interleaved following the previous sequence.
  174. ///
  175. /// @see gtc_bitfield
  176. GLM_FUNC_DECL uint32 bitfieldInterleave(uint8 x, uint8 y, uint8 z);
  177. /// Interleaves the bits of x, y and z.
  178. /// The first bit is the first bit of x followed by the first bit of y and the first bit of z.
  179. /// The other bits are interleaved following the previous sequence.
  180. ///
  181. /// @see gtc_bitfield
  182. GLM_FUNC_DECL int64 bitfieldInterleave(int16 x, int16 y, int16 z);
  183. /// Interleaves the bits of x, y and z.
  184. /// The first bit is the first bit of x followed by the first bit of y and the first bit of z.
  185. /// The other bits are interleaved following the previous sequence.
  186. ///
  187. /// @see gtc_bitfield
  188. GLM_FUNC_DECL uint64 bitfieldInterleave(uint16 x, uint16 y, uint16 z);
  189. /// Interleaves the bits of x, y and z.
  190. /// The first bit is the first bit of x followed by the first bit of y and the first bit of z.
  191. /// The other bits are interleaved following the previous sequence.
  192. ///
  193. /// @see gtc_bitfield
  194. GLM_FUNC_DECL int64 bitfieldInterleave(int32 x, int32 y, int32 z);
  195. /// Interleaves the bits of x, y and z.
  196. /// The first bit is the first bit of x followed by the first bit of y and the first bit of z.
  197. /// The other bits are interleaved following the previous sequence.
  198. ///
  199. /// @see gtc_bitfield
  200. GLM_FUNC_DECL uint64 bitfieldInterleave(uint32 x, uint32 y, uint32 z);
  201. /// Interleaves the bits of x, y, z and w.
  202. /// The first bit is the first bit of x followed by the first bit of y, the first bit of z and finally the first bit of w.
  203. /// The other bits are interleaved following the previous sequence.
  204. ///
  205. /// @see gtc_bitfield
  206. GLM_FUNC_DECL int32 bitfieldInterleave(int8 x, int8 y, int8 z, int8 w);
  207. /// Interleaves the bits of x, y, z and w.
  208. /// The first bit is the first bit of x followed by the first bit of y, the first bit of z and finally the first bit of w.
  209. /// The other bits are interleaved following the previous sequence.
  210. ///
  211. /// @see gtc_bitfield
  212. GLM_FUNC_DECL uint32 bitfieldInterleave(uint8 x, uint8 y, uint8 z, uint8 w);
  213. /// Interleaves the bits of x, y, z and w.
  214. /// The first bit is the first bit of x followed by the first bit of y, the first bit of z and finally the first bit of w.
  215. /// The other bits are interleaved following the previous sequence.
  216. ///
  217. /// @see gtc_bitfield
  218. GLM_FUNC_DECL int64 bitfieldInterleave(int16 x, int16 y, int16 z, int16 w);
  219. /// Interleaves the bits of x, y, z and w.
  220. /// The first bit is the first bit of x followed by the first bit of y, the first bit of z and finally the first bit of w.
  221. /// The other bits are interleaved following the previous sequence.
  222. ///
  223. /// @see gtc_bitfield
  224. GLM_FUNC_DECL uint64 bitfieldInterleave(uint16 x, uint16 y, uint16 z, uint16 w);
  225. /// @}
  226. } //namespace glm
  227. #include "bitfield.inl"