You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.4 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////
  2. /// OpenGL Mathematics (glm.g-truc.net)
  3. ///
  4. /// Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  5. /// Permission is hereby granted, free of charge, to any person obtaining a copy
  6. /// of this software and associated documentation files (the "Software"), to deal
  7. /// in the Software without restriction, including without limitation the rights
  8. /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. /// copies of the Software, and to permit persons to whom the Software is
  10. /// furnished to do so, subject to the following conditions:
  11. ///
  12. /// The above copyright notice and this permission notice shall be included in
  13. /// all copies or substantial portions of the Software.
  14. ///
  15. /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. /// THE SOFTWARE.
  22. ///
  23. /// @ref gtx_bit
  24. /// @file glm/gtx/bit.hpp
  25. /// @date 2007-03-14 / 2011-06-07
  26. /// @author Christophe Riccio
  27. ///
  28. /// @see core (dependence)
  29. /// @see gtc_half_float (dependence)
  30. ///
  31. /// @defgroup gtx_bit GLM_GTX_bit
  32. /// @ingroup gtx
  33. ///
  34. /// @brief Allow to perform bit operations on integer values
  35. ///
  36. /// <glm/gtx/bit.hpp> need to be included to use these functionalities.
  37. ///////////////////////////////////////////////////////////////////////////////////
  38. #ifndef GLM_GTX_bit
  39. #define GLM_GTX_bit GLM_VERSION
  40. // Dependency:
  41. #include "../glm.hpp"
  42. #include "../gtc/half_float.hpp"
  43. #if(defined(GLM_MESSAGES) && !defined(glm_ext))
  44. # pragma message("GLM: GLM_GTX_bit extension included")
  45. #endif
  46. namespace glm
  47. {
  48. /// @addtogroup gtx_bit
  49. /// @{
  50. /// Build a mask of 'count' bits
  51. /// @see gtx_bit
  52. template <typename genIType>
  53. genIType mask(genIType const & count);
  54. /// Component wise extraction of bit fields.
  55. /// genType and genIType could be a scalar or a vector.
  56. /// @see gtx_bit
  57. template <typename genIUType, typename sizeType>
  58. GLM_DEPRECATED genIUType extractField(
  59. genIUType const & v,
  60. sizeType const & first,
  61. sizeType const & count);
  62. //! Find the lowest bit set to 1 in a integer variable.
  63. /// @see gtx_bit
  64. template <typename genType>
  65. GLM_DEPRECATED int lowestBit(genType const & value);
  66. //! Find the highest bit set to 1 in a integer variable.
  67. /// @see gtx_bit
  68. template <typename genType>
  69. GLM_DEPRECATED int highestBit(genType const & value);
  70. //! Find the highest bit set to 1 in a integer variable and return its value.
  71. /// @see gtx_bit
  72. template <typename genType>
  73. genType highestBitValue(genType const & value);
  74. //! Return true if the value is a power of two number.
  75. /// @see gtx_bit
  76. template <typename genType>
  77. bool isPowerOfTwo(genType const & value);
  78. //! Return the power of two number which value is just higher the input value.
  79. /// @see gtx_bit
  80. template <typename genType>
  81. genType powerOfTwoAbove(genType const & value);
  82. //! Return the power of two number which value is just lower the input value.
  83. /// @see gtx_bit
  84. template <typename genType>
  85. genType powerOfTwoBelow(genType const & value);
  86. //! Return the power of two number which value is the closet to the input value.
  87. /// @see gtx_bit
  88. template <typename genType>
  89. genType powerOfTwoNearest(genType const & value);
  90. //! Revert all bits of any integer based type.
  91. /// @see gtx_bit
  92. template <typename genType>
  93. GLM_DEPRECATED genType bitRevert(genType const & value);
  94. //! Rotate all bits to the right.
  95. /// @see gtx_bit
  96. template <typename genType>
  97. genType bitRotateRight(genType const & In, std::size_t Shift);
  98. //! Rotate all bits to the left.
  99. /// @see gtx_bit
  100. template <typename genType>
  101. genType bitRotateLeft(genType const & In, std::size_t Shift);
  102. //! Set to 1 a range of bits.
  103. /// @see gtx_bit
  104. template <typename genIUType>
  105. genIUType fillBitfieldWithOne(
  106. genIUType const & Value,
  107. int const & FromBit,
  108. int const & ToBit);
  109. //! Set to 0 a range of bits.
  110. /// @see gtx_bit
  111. template <typename genIUType>
  112. genIUType fillBitfieldWithZero(
  113. genIUType const & Value,
  114. int const & FromBit,
  115. int const & ToBit);
  116. /// @}
  117. } //namespace glm
  118. #include "bit.inl"
  119. #endif//GLM_GTX_bit