func_common.hpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2008-03-08
  5. // Updated : 2010-01-26
  6. // Licence : This source is under MIT License
  7. // File : glm/core/func_common.hpp
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. #ifndef glm_core_func_common
  10. #define glm_core_func_common
  11. #include "_fixes.hpp"
  12. namespace glm
  13. {
  14. namespace test{
  15. void main_core_func_common();
  16. }//namespace test
  17. namespace core{
  18. namespace function{
  19. //! Define common functions from Section 8.3 of GLSL 1.30.8 specification. Included in glm namespace.
  20. namespace common{
  21. /// \addtogroup core_funcs
  22. ///@{
  23. //! Returns x if x >= 0; otherwise, it returns -x.
  24. //! (From GLSL 1.30.08 specification, section 8.3)
  25. template <typename genFIType>
  26. genFIType abs(genFIType const & x);
  27. //! Returns 1.0 if x > 0, 0.0 if x == 0, or -1.0 if x < 0.
  28. //! (From GLSL 1.30.08 specification, section 8.3)
  29. template <typename genFIType>
  30. genFIType sign(genFIType const & x);
  31. //! Returns a value equal to the nearest integer that is less then or equal to x.
  32. //! (From GLSL 1.30.08 specification, section 8.3)
  33. template <typename genType>
  34. genType floor(genType const & x);
  35. //! Returns a value equal to the nearest integer to x
  36. //! whose absolute value is not larger than the absolute value of x.
  37. //! (From GLSL 1.30.08 specification, section 8.3)
  38. template <typename genType>
  39. genType trunc(genType const & x);
  40. //! Returns a value equal to the nearest integer to x.
  41. //! The fraction 0.5 will round in a direction chosen by the
  42. //! implementation, presumably the direction that is fastest.
  43. //! This includes the possibility that round(x) returns the
  44. //! same value as roundEven(x) for all values of x.
  45. //! (From GLSL 1.30.08 specification, section 8.3)
  46. template <typename genType>
  47. genType round(genType const & x);
  48. //! Returns a value equal to the nearest integer to x.
  49. //! A fractional part of 0.5 will round toward the nearest even
  50. //! integer. (Both 3.5 and 4.5 for x will return 4.0.)
  51. //! (From GLSL 1.30.08 specification, section 8.3)
  52. template <typename genType>
  53. genType roundEven(genType const & x);
  54. //! Returns a value equal to the nearest integer
  55. //! that is greater than or equal to x.
  56. //! (From GLSL 1.30.08 specification, section 8.3)
  57. template <typename genType>
  58. genType ceil(genType const & x);
  59. //! Return x - floor(x).
  60. //! (From GLSL 1.30.08 specification, section 8.3)
  61. template <typename genType>
  62. genType fract(genType const & x);
  63. //! Modulus. Returns x - y * floor(x / y)
  64. //! for each component in x using the floating point value y.
  65. //! (From GLSL 1.30.08 specification, section 8.3)
  66. template <typename genType>
  67. genType mod(
  68. genType const & x,
  69. genType const & y);
  70. //! Modulus. Returns x - y * floor(x / y)
  71. //! for each component in x using the floating point value y.
  72. //! (From GLSL 1.30.08 specification, section 8.3)
  73. template <typename genType>
  74. genType mod(
  75. genType const & x,
  76. typename genType::value_type const & y);
  77. //! Returns the fractional part of x and sets i to the integer
  78. //! part (as a whole number floating point value). Both the
  79. //! return value and the output parameter will have the same
  80. //! sign as x.
  81. //! (From GLSL 1.30.08 specification, section 8.3)
  82. template <typename genType>
  83. genType modf(
  84. genType const & x,
  85. genType & i);
  86. //! Returns y if y < x; otherwise, it returns x.
  87. //! (From GLSL 1.30.08 specification, section 8.3)
  88. template <typename genType>
  89. genType min(
  90. genType const & x,
  91. genType const & y);
  92. template <typename genType>
  93. genType min(
  94. genType const & x,
  95. typename genType::value_type const & y);
  96. //! Returns y if x < y; otherwise, it returns x.
  97. //! (From GLSL 1.30.08 specification, section 8.3)
  98. template <typename genType>
  99. genType max(
  100. genType const & x,
  101. genType const & y);
  102. template <typename genType>
  103. genType max(
  104. genType const & x,
  105. typename genType::value_type const & y);
  106. //! Returns min(max(x, minVal), maxVal) for each component in x
  107. //! using the floating-point values minVal and maxVal.
  108. //! (From GLSL 1.30.08 specification, section 8.3)
  109. template <typename genType>
  110. genType clamp(
  111. genType const & x,
  112. genType const & minVal,
  113. genType const & maxVal);
  114. template <typename genType>
  115. genType clamp(
  116. genType const & x,
  117. typename genType::value_type const & minVal,
  118. typename genType::value_type const & maxVal);
  119. //! \return If genTypeU is a floating scalar or vector:
  120. //! Returns x * (1.0 - a) + y * a, i.e., the linear blend of
  121. //! x and y using the floating-point value a.
  122. //! The value for a is not restricted to the range [0, 1].
  123. //!
  124. //! \return If genTypeU is a boolean scalar or vector:
  125. //! Selects which vector each returned component comes
  126. //! from. For a component of a that is false, the
  127. //! corresponding component of x is returned. For a
  128. //! component of a that is true, the corresponding
  129. //! component of y is returned. Components of x and y that
  130. //! are not selected are allowed to be invalid floating point
  131. //! values and will have no effect on the results. Thus, this
  132. //! provides different functionality than
  133. //! genType mix(genType x, genType y, genType(a))
  134. //! where a is a Boolean vector.
  135. //!
  136. //! From GLSL 1.30.08 specification, section 8.3
  137. //!
  138. //! \param[in] x Floating point scalar or vector.
  139. //! \param[in] y Floating point scalar or vector.
  140. //! \param[in] a Floating point or boolean scalar or vector.
  141. //!
  142. // \todo Test when 'a' is a boolean.
  143. template <typename genTypeT, typename genTypeU>
  144. genTypeT mix(genTypeT const & x, genTypeT const & y, genTypeU const & a);
  145. //! Returns 0.0 if x < edge, otherwise it returns 1.0.
  146. //! (From GLSL 1.30.08 specification, section 8.3)
  147. template <typename genType>
  148. genType step(
  149. genType const & edge,
  150. genType const & x);
  151. template <typename genType>
  152. genType step(
  153. typename genType::value_type const & edge,
  154. genType const & x);
  155. //! Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and
  156. //! performs smooth Hermite interpolation between 0 and 1
  157. //! when edge0 < x < edge1. This is useful in cases where
  158. //! you would want a threshold function with a smooth
  159. //! transition. This is equivalent to:
  160. //! genType t;
  161. //! t = clamp ((x – edge0) / (edge1 – edge0), 0, 1);
  162. //! return t * t * (3 – 2 * t);
  163. //! Results are undefined if edge0 >= edge1.
  164. //! (From GLSL 1.30.08 specification, section 8.3)
  165. template <typename genType>
  166. genType smoothstep(
  167. genType const & edge0,
  168. genType const & edge1,
  169. genType const & x);
  170. template <typename genType>
  171. genType smoothstep(
  172. typename genType::value_type const & edge0,
  173. typename genType::value_type const & edge1,
  174. genType const & x);
  175. //! Returns true if x holds a NaN (not a number)
  176. //! representation in the underlying implementation's set of
  177. //! floating point representations. Returns false otherwise,
  178. //! including for implementations with no NaN
  179. //! representations.
  180. //! (From GLSL 1.30.08 specification, section 8.3)
  181. template <typename genType>
  182. typename genType::bool_type isnan(genType const & x);
  183. //! Returns true if x holds a positive infinity or negative
  184. //! infinity representation in the underlying implementation's
  185. //! set of floating point representations. Returns false
  186. //! otherwise, including for implementations with no infinity
  187. //! representations.
  188. //! (From GLSL 1.30.08 specification, section 8.3)
  189. template <typename genType>
  190. typename genType::bool_type isinf(genType const & x);
  191. //! Returns a signed or unsigned integer value representing
  192. //! the encoding of a floating-point value. The floatingpoint
  193. //! value's bit-level representation is preserved.
  194. //! (From GLSL 4.00.08 specification, section 8.3)
  195. template <typename genType, typename genIType>
  196. genIType floatBitsToInt(genType const & value);
  197. //! Returns a signed or unsigned integer value representing
  198. //! the encoding of a floating-point value. The floatingpoint
  199. //! value's bit-level representation is preserved.
  200. //! (From GLSL 4.00.08 specification, section 8.3)
  201. template <typename genType, typename genUType>
  202. genUType floatBitsToInt(genType const & value);
  203. //! Returns a floating-point value corresponding to a signed
  204. //! or unsigned integer encoding of a floating-point value.
  205. //! If an inf or NaN is passed in, it will not signal, and the
  206. //! resulting floating point value is unspecified. Otherwise,
  207. //! the bit-level representation is preserved.
  208. //! (From GLSL 4.00.08 specification, section 8.3)
  209. template <typename genType, typename genIUType>
  210. genType intBitsToFloat(genIUType const & value);
  211. //! Computes and returns a * b + c.
  212. //! (From GLSL 4.00.08 specification, section 8.3)
  213. template <typename genType>
  214. genType fma(genType const & a, genType const & b, genType const & c);
  215. //! Splits x into a floating-point significand in the range
  216. //! [0.5, 1.0) and an integral exponent of two, such that:
  217. //! x = significand * exp(2, exponent)
  218. //! The significand is returned by the function and the
  219. //! exponent is returned in the parameter exp. For a
  220. //! floating-point value of zero, the significant and exponent
  221. //! are both zero. For a floating-point value that is an
  222. //! infinity or is not a number, the results are undefined.
  223. //! (From GLSL 4.00.08 specification, section 8.3)
  224. template <typename genType, typename genIType>
  225. genType frexp(genType const & x, genIType & exp);
  226. //! Builds a floating-point number from x and the
  227. //! corresponding integral exponent of two in exp, returning:
  228. //! significand * exp(2, exponent)
  229. //! If this product is too large to be represented in the
  230. //! floating-point type, the result is undefined.
  231. //! (From GLSL 4.00.08 specification, section 8.3)
  232. template <typename genType, typename genIType>
  233. genType ldexp(genType const & x, genIType const & exp);
  234. ///@}
  235. }//namespace common
  236. }//namespace function
  237. }//namespace core
  238. using namespace core::function::common;
  239. }//namespace glm
  240. #include "func_common.inl"
  241. #endif//glm_core_func_common