bit.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2007-03-14
  5. // Updated : 2008-11-14
  6. // Licence : This source is under MIT License
  7. // File : glm/gtx/bit.hpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. // Dependency:
  10. // - GLM core
  11. // - GLM_GTC_half_float
  12. ///////////////////////////////////////////////////////////////////////////////////////////////////
  13. #ifndef glm_gtx_bit
  14. #define glm_gtx_bit
  15. // Dependency:
  16. #include "../glm.hpp"
  17. #include "../gtc/half_float.hpp"
  18. #if(defined(GLM_MESSAGES) && !defined(glm_ext))
  19. # pragma message("GLM: GLM_GTX_bit extension included")
  20. #endif
  21. namespace glm
  22. {
  23. namespace test{
  24. void main_gtx_bit();
  25. }//namespace test
  26. namespace gtx{
  27. //! GLM_GTX_bit extension: Allow to perform bit operations on integer values
  28. namespace bit
  29. {
  30. using namespace gtc::half_float;
  31. /// \addtogroup gtx_bit
  32. ///@{
  33. //! Build a mask of 'count' bits
  34. //! From GLM_GTX_bit extension.
  35. template <typename genIType>
  36. genIType mask(genIType const & count);
  37. //! Component wise extraction of bit fields.
  38. //! genType and genIType could be a scalar or a vector.
  39. //! From GLM_GTX_bit extension.
  40. template <typename genIUType, typename sizeType>
  41. genIUType extractField(
  42. genIUType const & v,
  43. sizeType const & first,
  44. sizeType const & count);
  45. //! Find the lowest bit set to 1 in a integer variable.
  46. //! From GLM_GTX_bit extension.
  47. template <typename genType>
  48. int lowestBit(genType const & value);
  49. //! Find the highest bit set to 1 in a integer variable.
  50. //! From GLM_GTX_bit extension.
  51. template <typename genType>
  52. int highestBit(genType const & value);
  53. //! Find the highest bit set to 1 in a integer variable and return its value.
  54. //! From GLM_GTX_bit extension.
  55. template <typename genType>
  56. genType highestBitValue(genType const & value);
  57. //! Return true if the value is a power of two number.
  58. //! From GLM_GTX_bit extension.
  59. template <typename genType>
  60. bool isPowerOfTwo(genType const & value);
  61. //! Return the power of two number which value is just higher the input value.
  62. //! From GLM_GTX_bit extension.
  63. template <typename genType>
  64. genType powerOfTwoAbove(genType const & value);
  65. //! Return the power of two number which value is just lower the input value.
  66. //! From GLM_GTX_bit extension.
  67. template <typename genType>
  68. genType powerOfTwoBelow(genType const & value);
  69. //! Return the power of two number which value is the closet to the input value.
  70. //! From GLM_GTX_bit extension.
  71. template <typename genType>
  72. genType powerOfTwoNearest(genType const & value);
  73. //! Revert all bits of any integer based type.
  74. //! From GLM_GTX_bit extension.
  75. template <typename genType>
  76. genType bitRevert(genType const & value);
  77. //! Rotate all bits to the right.
  78. //! From GLM_GTX_bit extension.
  79. template <typename genType>
  80. genType bitRotateRight(genType const & In, std::size_t Shift);
  81. //! Rotate all bits to the left.
  82. //! From GLM_GTX_bit extension.
  83. template <typename genType>
  84. genType bitRotateLeft(genType const & In, std::size_t Shift);
  85. ///@}
  86. }//namespace bit
  87. }//namespace gtx
  88. }//namespace glm
  89. #include "bit.inl"
  90. namespace glm{using namespace gtx::bit;}
  91. #endif//glm_gtx_bit