| 1 | /// @ref core |
| 2 | /// @file glm/common.hpp |
| 3 | /// |
| 4 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 5 | /// |
| 6 | /// @defgroup core_func_common Common functions |
| 7 | /// @ingroup core |
| 8 | /// |
| 9 | /// Provides GLSL common functions |
| 10 | /// |
| 11 | /// These all operate component-wise. The description is per component. |
| 12 | /// |
| 13 | /// Include <glm/common.hpp> to use these core features. |
| 14 | |
| 15 | #pragma once |
| 16 | |
| 17 | #include "detail/qualifier.hpp" |
| 18 | #include "detail/_fixes.hpp" |
| 19 | |
| 20 | namespace glm |
| 21 | { |
| 22 | /// @addtogroup core_func_common |
| 23 | /// @{ |
| 24 | |
| 25 | /// Returns x if x >= 0; otherwise, it returns -x. |
| 26 | /// |
| 27 | /// @tparam genType floating-point or signed integer; scalar or vector types. |
| 28 | /// |
| 29 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/abs.xml">GLSL abs man page</a> |
| 30 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 31 | template<typename genType> |
| 32 | GLM_FUNC_DECL GLM_CONSTEXPR genType abs(genType x); |
| 33 | |
| 34 | /// Returns x if x >= 0; otherwise, it returns -x. |
| 35 | /// |
| 36 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 37 | /// @tparam T Floating-point or signed integer scalar types |
| 38 | /// @tparam Q Value from qualifier enum |
| 39 | /// |
| 40 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/abs.xml">GLSL abs man page</a> |
| 41 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 42 | template<length_t L, typename T, qualifier Q> |
| 43 | GLM_FUNC_DECL GLM_CONSTEXPR vec<L, T, Q> abs(vec<L, T, Q> const& x); |
| 44 | |
| 45 | /// Returns 1.0 if x > 0, 0.0 if x == 0, or -1.0 if x < 0. |
| 46 | /// |
| 47 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 48 | /// @tparam T Floating-point scalar types |
| 49 | /// @tparam Q Value from qualifier enum |
| 50 | /// |
| 51 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/sign.xml">GLSL sign man page</a> |
| 52 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 53 | template<length_t L, typename T, qualifier Q> |
| 54 | GLM_FUNC_DECL vec<L, T, Q> sign(vec<L, T, Q> const& x); |
| 55 | |
| 56 | /// Returns a value equal to the nearest integer that is less then or equal to x. |
| 57 | /// |
| 58 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 59 | /// @tparam T Floating-point scalar types |
| 60 | /// @tparam Q Value from qualifier enum |
| 61 | /// |
| 62 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/floor.xml">GLSL floor man page</a> |
| 63 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 64 | template<length_t L, typename T, qualifier Q> |
| 65 | GLM_FUNC_DECL vec<L, T, Q> floor(vec<L, T, Q> const& x); |
| 66 | |
| 67 | /// Returns a value equal to the nearest integer to x |
| 68 | /// whose absolute value is not larger than the absolute value of x. |
| 69 | /// |
| 70 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 71 | /// @tparam T Floating-point scalar types |
| 72 | /// @tparam Q Value from qualifier enum |
| 73 | /// |
| 74 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/trunc.xml">GLSL trunc man page</a> |
| 75 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 76 | template<length_t L, typename T, qualifier Q> |
| 77 | GLM_FUNC_DECL vec<L, T, Q> trunc(vec<L, T, Q> const& x); |
| 78 | |
| 79 | /// Returns a value equal to the nearest integer to x. |
| 80 | /// The fraction 0.5 will round in a direction chosen by the |
| 81 | /// implementation, presumably the direction that is fastest. |
| 82 | /// This includes the possibility that round(x) returns the |
| 83 | /// same value as roundEven(x) for all values of x. |
| 84 | /// |
| 85 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 86 | /// @tparam T Floating-point scalar types |
| 87 | /// @tparam Q Value from qualifier enum |
| 88 | /// |
| 89 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/round.xml">GLSL round man page</a> |
| 90 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 91 | template<length_t L, typename T, qualifier Q> |
| 92 | GLM_FUNC_DECL vec<L, T, Q> round(vec<L, T, Q> const& x); |
| 93 | |
| 94 | /// Returns a value equal to the nearest integer to x. |
| 95 | /// A fractional part of 0.5 will round toward the nearest even |
| 96 | /// integer. (Both 3.5 and 4.5 for x will return 4.0.) |
| 97 | /// |
| 98 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 99 | /// @tparam T Floating-point scalar types |
| 100 | /// @tparam Q Value from qualifier enum |
| 101 | /// |
| 102 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/roundEven.xml">GLSL roundEven man page</a> |
| 103 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 104 | /// @see <a href="http://developer.amd.com/documentation/articles/pages/New-Round-to-Even-Technique.aspx">New round to even technique</a> |
| 105 | template<length_t L, typename T, qualifier Q> |
| 106 | GLM_FUNC_DECL vec<L, T, Q> roundEven(vec<L, T, Q> const& x); |
| 107 | |
| 108 | /// Returns a value equal to the nearest integer |
| 109 | /// that is greater than or equal to x. |
| 110 | /// |
| 111 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 112 | /// @tparam T Floating-point scalar types |
| 113 | /// @tparam Q Value from qualifier enum |
| 114 | /// |
| 115 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/ceil.xml">GLSL ceil man page</a> |
| 116 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 117 | template<length_t L, typename T, qualifier Q> |
| 118 | GLM_FUNC_DECL vec<L, T, Q> ceil(vec<L, T, Q> const& x); |
| 119 | |
| 120 | /// Return x - floor(x). |
| 121 | /// |
| 122 | /// @tparam genType Floating-point scalar or vector types. |
| 123 | /// |
| 124 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/fract.xml">GLSL fract man page</a> |
| 125 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 126 | template<typename genType> |
| 127 | GLM_FUNC_DECL genType fract(genType x); |
| 128 | |
| 129 | /// Return x - floor(x). |
| 130 | /// |
| 131 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 132 | /// @tparam T Floating-point scalar types |
| 133 | /// @tparam Q Value from qualifier enum |
| 134 | /// |
| 135 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/fract.xml">GLSL fract man page</a> |
| 136 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 137 | template<length_t L, typename T, qualifier Q> |
| 138 | GLM_FUNC_DECL vec<L, T, Q> fract(vec<L, T, Q> const& x); |
| 139 | |
| 140 | template<typename genType> |
| 141 | GLM_FUNC_DECL genType mod(genType x, genType y); |
| 142 | |
| 143 | template<length_t L, typename T, qualifier Q> |
| 144 | GLM_FUNC_DECL vec<L, T, Q> mod(vec<L, T, Q> const& x, T y); |
| 145 | |
| 146 | /// Modulus. Returns x - y * floor(x / y) |
| 147 | /// for each component in x using the floating point value y. |
| 148 | /// |
| 149 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 150 | /// @tparam T Floating-point scalar types, include glm/gtc/integer for integer scalar types support |
| 151 | /// @tparam Q Value from qualifier enum |
| 152 | /// |
| 153 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/mod.xml">GLSL mod man page</a> |
| 154 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 155 | template<length_t L, typename T, qualifier Q> |
| 156 | GLM_FUNC_DECL vec<L, T, Q> mod(vec<L, T, Q> const& x, vec<L, T, Q> const& y); |
| 157 | |
| 158 | /// Returns the fractional part of x and sets i to the integer |
| 159 | /// part (as a whole number floating point value). Both the |
| 160 | /// return value and the output parameter will have the same |
| 161 | /// sign as x. |
| 162 | /// |
| 163 | /// @tparam genType Floating-point scalar or vector types. |
| 164 | /// |
| 165 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/modf.xml">GLSL modf man page</a> |
| 166 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 167 | template<typename genType> |
| 168 | GLM_FUNC_DECL genType modf(genType x, genType& i); |
| 169 | |
| 170 | /// Returns y if y < x; otherwise, it returns x. |
| 171 | /// |
| 172 | /// @tparam genType Floating-point or integer; scalar or vector types. |
| 173 | /// |
| 174 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/min.xml">GLSL min man page</a> |
| 175 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 176 | template<typename genType> |
| 177 | GLM_FUNC_DECL GLM_CONSTEXPR genType min(genType x, genType y); |
| 178 | |
| 179 | /// Returns y if y < x; otherwise, it returns x. |
| 180 | /// |
| 181 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 182 | /// @tparam T Floating-point or integer scalar types |
| 183 | /// @tparam Q Value from qualifier enum |
| 184 | /// |
| 185 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/min.xml">GLSL min man page</a> |
| 186 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 187 | template<length_t L, typename T, qualifier Q> |
| 188 | GLM_FUNC_DECL GLM_CONSTEXPR vec<L, T, Q> min(vec<L, T, Q> const& x, T y); |
| 189 | |
| 190 | /// Returns y if y < x; otherwise, it returns x. |
| 191 | /// |
| 192 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 193 | /// @tparam T Floating-point or integer scalar types |
| 194 | /// @tparam Q Value from qualifier enum |
| 195 | /// |
| 196 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/min.xml">GLSL min man page</a> |
| 197 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 198 | template<length_t L, typename T, qualifier Q> |
| 199 | GLM_FUNC_DECL GLM_CONSTEXPR vec<L, T, Q> min(vec<L, T, Q> const& x, vec<L, T, Q> const& y); |
| 200 | |
| 201 | /// Returns y if x < y; otherwise, it returns x. |
| 202 | /// |
| 203 | /// @tparam genType Floating-point or integer; scalar or vector types. |
| 204 | /// |
| 205 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/max.xml">GLSL max man page</a> |
| 206 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 207 | template<typename genType> |
| 208 | GLM_FUNC_DECL GLM_CONSTEXPR genType max(genType x, genType y); |
| 209 | |
| 210 | /// Returns y if x < y; otherwise, it returns x. |
| 211 | /// |
| 212 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 213 | /// @tparam T Floating-point or integer scalar types |
| 214 | /// @tparam Q Value from qualifier enum |
| 215 | /// |
| 216 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/max.xml">GLSL max man page</a> |
| 217 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 218 | template<length_t L, typename T, qualifier Q> |
| 219 | GLM_FUNC_DECL GLM_CONSTEXPR vec<L, T, Q> max(vec<L, T, Q> const& x, T y); |
| 220 | |
| 221 | /// Returns y if x < y; otherwise, it returns x. |
| 222 | /// |
| 223 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 224 | /// @tparam T Floating-point or integer scalar types |
| 225 | /// @tparam Q Value from qualifier enum |
| 226 | /// |
| 227 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/max.xml">GLSL max man page</a> |
| 228 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 229 | template<length_t L, typename T, qualifier Q> |
| 230 | GLM_FUNC_DECL GLM_CONSTEXPR vec<L, T, Q> max(vec<L, T, Q> const& x, vec<L, T, Q> const& y); |
| 231 | |
| 232 | /// Returns min(max(x, minVal), maxVal) for each component in x |
| 233 | /// using the floating-point values minVal and maxVal. |
| 234 | /// |
| 235 | /// @tparam genType Floating-point or integer; scalar or vector types. |
| 236 | /// |
| 237 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/clamp.xml">GLSL clamp man page</a> |
| 238 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 239 | template<typename genType> |
| 240 | GLM_FUNC_DECL GLM_CONSTEXPR genType clamp(genType x, genType minVal, genType maxVal); |
| 241 | |
| 242 | /// Returns min(max(x, minVal), maxVal) for each component in x |
| 243 | /// using the floating-point values minVal and maxVal. |
| 244 | /// |
| 245 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 246 | /// @tparam T Floating-point or integer scalar types |
| 247 | /// @tparam Q Value from qualifier enum |
| 248 | /// |
| 249 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/clamp.xml">GLSL clamp man page</a> |
| 250 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 251 | template<length_t L, typename T, qualifier Q> |
| 252 | GLM_FUNC_DECL GLM_CONSTEXPR vec<L, T, Q> clamp(vec<L, T, Q> const& x, T minVal, T maxVal); |
| 253 | |
| 254 | /// Returns min(max(x, minVal), maxVal) for each component in x |
| 255 | /// using the floating-point values minVal and maxVal. |
| 256 | /// |
| 257 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 258 | /// @tparam T Floating-point or integer scalar types |
| 259 | /// @tparam Q Value from qualifier enum |
| 260 | /// |
| 261 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/clamp.xml">GLSL clamp man page</a> |
| 262 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 263 | template<length_t L, typename T, qualifier Q> |
| 264 | GLM_FUNC_DECL GLM_CONSTEXPR vec<L, T, Q> clamp(vec<L, T, Q> const& x, vec<L, T, Q> const& minVal, vec<L, T, Q> const& maxVal); |
| 265 | |
| 266 | /// If genTypeU is a floating scalar or vector: |
| 267 | /// Returns x * (1.0 - a) + y * a, i.e., the linear blend of |
| 268 | /// x and y using the floating-point value a. |
| 269 | /// The value for a is not restricted to the range [0, 1]. |
| 270 | /// |
| 271 | /// If genTypeU is a boolean scalar or vector: |
| 272 | /// Selects which vector each returned component comes |
| 273 | /// from. For a component of 'a' that is false, the |
| 274 | /// corresponding component of 'x' is returned. For a |
| 275 | /// component of 'a' that is true, the corresponding |
| 276 | /// component of 'y' is returned. Components of 'x' and 'y' that |
| 277 | /// are not selected are allowed to be invalid floating point |
| 278 | /// values and will have no effect on the results. Thus, this |
| 279 | /// provides different functionality than |
| 280 | /// genType mix(genType x, genType y, genType(a)) |
| 281 | /// where a is a Boolean vector. |
| 282 | /// |
| 283 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/mix.xml">GLSL mix man page</a> |
| 284 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 285 | /// |
| 286 | /// @param[in] x Value to interpolate. |
| 287 | /// @param[in] y Value to interpolate. |
| 288 | /// @param[in] a Interpolant. |
| 289 | /// |
| 290 | /// @tparam genTypeT Floating point scalar or vector. |
| 291 | /// @tparam genTypeU Floating point or boolean scalar or vector. It can't be a vector if it is the length of genTypeT. |
| 292 | /// |
| 293 | /// @code |
| 294 | /// #include <glm/glm.hpp> |
| 295 | /// ... |
| 296 | /// float a; |
| 297 | /// bool b; |
| 298 | /// glm::dvec3 e; |
| 299 | /// glm::dvec3 f; |
| 300 | /// glm::vec4 g; |
| 301 | /// glm::vec4 h; |
| 302 | /// ... |
| 303 | /// glm::vec4 r = glm::mix(g, h, a); // Interpolate with a floating-point scalar two vectors. |
| 304 | /// glm::vec4 s = glm::mix(g, h, b); // Returns g or h; |
| 305 | /// glm::dvec3 t = glm::mix(e, f, a); // Types of the third parameter is not required to match with the first and the second. |
| 306 | /// glm::vec4 u = glm::mix(g, h, r); // Interpolations can be perform per component with a vector for the last parameter. |
| 307 | /// @endcode |
| 308 | template<typename genTypeT, typename genTypeU> |
| 309 | GLM_FUNC_DECL genTypeT mix(genTypeT x, genTypeT y, genTypeU a); |
| 310 | |
| 311 | template<length_t L, typename T, typename U, qualifier Q> |
| 312 | GLM_FUNC_DECL vec<L, T, Q> mix(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, U, Q> const& a); |
| 313 | |
| 314 | template<length_t L, typename T, typename U, qualifier Q> |
| 315 | GLM_FUNC_DECL vec<L, T, Q> mix(vec<L, T, Q> const& x, vec<L, T, Q> const& y, U a); |
| 316 | |
| 317 | /// Returns 0.0 if x < edge, otherwise it returns 1.0 for each component of a genType. |
| 318 | /// |
| 319 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/step.xml">GLSL step man page</a> |
| 320 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 321 | template<typename genType> |
| 322 | GLM_FUNC_DECL genType step(genType edge, genType x); |
| 323 | |
| 324 | /// Returns 0.0 if x < edge, otherwise it returns 1.0. |
| 325 | /// |
| 326 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 327 | /// @tparam T Floating-point scalar types |
| 328 | /// @tparam Q Value from qualifier enum |
| 329 | /// |
| 330 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/step.xml">GLSL step man page</a> |
| 331 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 332 | template<length_t L, typename T, qualifier Q> |
| 333 | GLM_FUNC_DECL vec<L, T, Q> step(T edge, vec<L, T, Q> const& x); |
| 334 | |
| 335 | /// Returns 0.0 if x < edge, otherwise it returns 1.0. |
| 336 | /// |
| 337 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 338 | /// @tparam T Floating-point scalar types |
| 339 | /// @tparam Q Value from qualifier enum |
| 340 | /// |
| 341 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/step.xml">GLSL step man page</a> |
| 342 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 343 | template<length_t L, typename T, qualifier Q> |
| 344 | GLM_FUNC_DECL vec<L, T, Q> step(vec<L, T, Q> const& edge, vec<L, T, Q> const& x); |
| 345 | |
| 346 | /// Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and |
| 347 | /// performs smooth Hermite interpolation between 0 and 1 |
| 348 | /// when edge0 < x < edge1. This is useful in cases where |
| 349 | /// you would want a threshold function with a smooth |
| 350 | /// transition. This is equivalent to: |
| 351 | /// genType t; |
| 352 | /// t = clamp ((x - edge0) / (edge1 - edge0), 0, 1); |
| 353 | /// return t * t * (3 - 2 * t); |
| 354 | /// Results are undefined if edge0 >= edge1. |
| 355 | /// |
| 356 | /// @tparam genType Floating-point scalar or vector types. |
| 357 | /// |
| 358 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/smoothstep.xml">GLSL smoothstep man page</a> |
| 359 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 360 | template<typename genType> |
| 361 | GLM_FUNC_DECL genType smoothstep(genType edge0, genType edge1, genType x); |
| 362 | |
| 363 | template<length_t L, typename T, qualifier Q> |
| 364 | GLM_FUNC_DECL vec<L, T, Q> smoothstep(T edge0, T edge1, vec<L, T, Q> const& x); |
| 365 | |
| 366 | template<length_t L, typename T, qualifier Q> |
| 367 | GLM_FUNC_DECL vec<L, T, Q> smoothstep(vec<L, T, Q> const& edge0, vec<L, T, Q> const& edge1, vec<L, T, Q> const& x); |
| 368 | |
| 369 | /// Returns true if x holds a NaN (not a number) |
| 370 | /// representation in the underlying implementation's set of |
| 371 | /// floating point representations. Returns false otherwise, |
| 372 | /// including for implementations with no NaN |
| 373 | /// representations. |
| 374 | /// |
| 375 | /// /!\ When using compiler fast math, this function may fail. |
| 376 | /// |
| 377 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 378 | /// @tparam T Floating-point scalar types |
| 379 | /// @tparam Q Value from qualifier enum |
| 380 | /// |
| 381 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/isnan.xml">GLSL isnan man page</a> |
| 382 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 383 | template<length_t L, typename T, qualifier Q> |
| 384 | GLM_FUNC_DECL vec<L, bool, Q> isnan(vec<L, T, Q> const& x); |
| 385 | |
| 386 | /// Returns true if x holds a positive infinity or negative |
| 387 | /// infinity representation in the underlying implementation's |
| 388 | /// set of floating point representations. Returns false |
| 389 | /// otherwise, including for implementations with no infinity |
| 390 | /// representations. |
| 391 | /// |
| 392 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 393 | /// @tparam T Floating-point scalar types |
| 394 | /// @tparam Q Value from qualifier enum |
| 395 | /// |
| 396 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/isinf.xml">GLSL isinf man page</a> |
| 397 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 398 | template<length_t L, typename T, qualifier Q> |
| 399 | GLM_FUNC_DECL vec<L, bool, Q> isinf(vec<L, T, Q> const& x); |
| 400 | |
| 401 | /// Returns a signed integer value representing |
| 402 | /// the encoding of a floating-point value. The floating-point |
| 403 | /// value's bit-level representation is preserved. |
| 404 | /// |
| 405 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/floatBitsToInt.xml">GLSL floatBitsToInt man page</a> |
| 406 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 407 | GLM_FUNC_DECL int floatBitsToInt(float const& v); |
| 408 | |
| 409 | /// Returns a signed integer value representing |
| 410 | /// the encoding of a floating-point value. The floatingpoint |
| 411 | /// value's bit-level representation is preserved. |
| 412 | /// |
| 413 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 414 | /// @tparam Q Value from qualifier enum |
| 415 | /// |
| 416 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/floatBitsToInt.xml">GLSL floatBitsToInt man page</a> |
| 417 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 418 | template<length_t L, qualifier Q> |
| 419 | GLM_FUNC_DECL vec<L, int, Q> floatBitsToInt(vec<L, float, Q> const& v); |
| 420 | |
| 421 | /// Returns a unsigned integer value representing |
| 422 | /// the encoding of a floating-point value. The floatingpoint |
| 423 | /// value's bit-level representation is preserved. |
| 424 | /// |
| 425 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/floatBitsToUint.xml">GLSL floatBitsToUint man page</a> |
| 426 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 427 | GLM_FUNC_DECL uint floatBitsToUint(float const& v); |
| 428 | |
| 429 | /// Returns a unsigned integer value representing |
| 430 | /// the encoding of a floating-point value. The floatingpoint |
| 431 | /// value's bit-level representation is preserved. |
| 432 | /// |
| 433 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 434 | /// @tparam Q Value from qualifier enum |
| 435 | /// |
| 436 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/floatBitsToUint.xml">GLSL floatBitsToUint man page</a> |
| 437 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 438 | template<length_t L, qualifier Q> |
| 439 | GLM_FUNC_DECL vec<L, uint, Q> floatBitsToUint(vec<L, float, Q> const& v); |
| 440 | |
| 441 | /// Returns a floating-point value corresponding to a signed |
| 442 | /// integer encoding of a floating-point value. |
| 443 | /// If an inf or NaN is passed in, it will not signal, and the |
| 444 | /// resulting floating point value is unspecified. Otherwise, |
| 445 | /// the bit-level representation is preserved. |
| 446 | /// |
| 447 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/intBitsToFloat.xml">GLSL intBitsToFloat man page</a> |
| 448 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 449 | GLM_FUNC_DECL float intBitsToFloat(int const& v); |
| 450 | |
| 451 | /// Returns a floating-point value corresponding to a signed |
| 452 | /// integer encoding of a floating-point value. |
| 453 | /// If an inf or NaN is passed in, it will not signal, and the |
| 454 | /// resulting floating point value is unspecified. Otherwise, |
| 455 | /// the bit-level representation is preserved. |
| 456 | /// |
| 457 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 458 | /// @tparam Q Value from qualifier enum |
| 459 | /// |
| 460 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/intBitsToFloat.xml">GLSL intBitsToFloat man page</a> |
| 461 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 462 | template<length_t L, qualifier Q> |
| 463 | GLM_FUNC_DECL vec<L, float, Q> intBitsToFloat(vec<L, int, Q> const& v); |
| 464 | |
| 465 | /// Returns a floating-point value corresponding to a |
| 466 | /// unsigned integer encoding of a floating-point value. |
| 467 | /// If an inf or NaN is passed in, it will not signal, and the |
| 468 | /// resulting floating point value is unspecified. Otherwise, |
| 469 | /// the bit-level representation is preserved. |
| 470 | /// |
| 471 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/uintBitsToFloat.xml">GLSL uintBitsToFloat man page</a> |
| 472 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 473 | GLM_FUNC_DECL float uintBitsToFloat(uint const& v); |
| 474 | |
| 475 | /// Returns a floating-point value corresponding to a |
| 476 | /// unsigned integer encoding of a floating-point value. |
| 477 | /// If an inf or NaN is passed in, it will not signal, and the |
| 478 | /// resulting floating point value is unspecified. Otherwise, |
| 479 | /// the bit-level representation is preserved. |
| 480 | /// |
| 481 | /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector |
| 482 | /// @tparam Q Value from qualifier enum |
| 483 | /// |
| 484 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/uintBitsToFloat.xml">GLSL uintBitsToFloat man page</a> |
| 485 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 486 | template<length_t L, qualifier Q> |
| 487 | GLM_FUNC_DECL vec<L, float, Q> uintBitsToFloat(vec<L, uint, Q> const& v); |
| 488 | |
| 489 | /// Computes and returns a * b + c. |
| 490 | /// |
| 491 | /// @tparam genType Floating-point scalar or vector types. |
| 492 | /// |
| 493 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/fma.xml">GLSL fma man page</a> |
| 494 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 495 | template<typename genType> |
| 496 | GLM_FUNC_DECL genType fma(genType const& a, genType const& b, genType const& c); |
| 497 | |
| 498 | /// Splits x into a floating-point significand in the range |
| 499 | /// [0.5, 1.0) and an integral exponent of two, such that: |
| 500 | /// x = significand * exp(2, exponent) |
| 501 | /// |
| 502 | /// The significand is returned by the function and the |
| 503 | /// exponent is returned in the parameter exp. For a |
| 504 | /// floating-point value of zero, the significant and exponent |
| 505 | /// are both zero. For a floating-point value that is an |
| 506 | /// infinity or is not a number, the results are undefined. |
| 507 | /// |
| 508 | /// @tparam genType Floating-point scalar or vector types. |
| 509 | /// |
| 510 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/frexp.xml">GLSL frexp man page</a> |
| 511 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 512 | template<typename genType, typename genIType> |
| 513 | GLM_FUNC_DECL genType frexp(genType const& x, genIType& exp); |
| 514 | |
| 515 | /// Builds a floating-point number from x and the |
| 516 | /// corresponding integral exponent of two in exp, returning: |
| 517 | /// significand * exp(2, exponent) |
| 518 | /// |
| 519 | /// If this product is too large to be represented in the |
| 520 | /// floating-point type, the result is undefined. |
| 521 | /// |
| 522 | /// @tparam genType Floating-point scalar or vector types. |
| 523 | /// |
| 524 | /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/ldexp.xml">GLSL ldexp man page</a>; |
| 525 | /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a> |
| 526 | template<typename genType, typename genIType> |
| 527 | GLM_FUNC_DECL genType ldexp(genType const& x, genIType const& exp); |
| 528 | |
| 529 | /// @} |
| 530 | }//namespace glm |
| 531 | |
| 532 | #include "detail/func_common.inl" |
| 533 |