More manual documentation

This commit is contained in:
Christophe Riccio 2018-08-30 01:04:26 +02:00
parent b40c557f25
commit 62e4c59d8d
3 changed files with 86 additions and 30 deletions

View File

@ -16,7 +16,7 @@ namespace detail
GLM_FUNC_QUALIFIER GLM_CONSTEXPR static genFIType call(genFIType x)
{
GLM_STATIC_ASSERT(
std::numeric_limits<genFIType>::is_iec559 || std::numeric_limits<genFIType>::is_signed || GLM_CONFIG_UNRESTRICTED_GENTYPE,
std::numeric_limits<genFIType>::is_iec559 || std::numeric_limits<genFIType>::is_signed,
"'abs' only accept floating-point and integer scalar or vector inputs");
return x >= genFIType(0) ? x : -x;
@ -41,7 +41,7 @@ namespace detail
GLM_FUNC_QUALIFIER GLM_CONSTEXPR static genFIType call(genFIType x)
{
GLM_STATIC_ASSERT(
(!std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer) || GLM_CONFIG_UNRESTRICTED_GENTYPE,
(!std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer),
"'abs' only accept floating-point and integer scalar or vector inputs");
return x;
}

View File

@ -15,7 +15,7 @@ namespace glm
template<typename genType>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType min(genType x, genType y)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || std::numeric_limits<genType>::is_integer || GLM_CONFIG_UNRESTRICTED_GENTYPE, "'min' only accept floating-point or integer inputs");
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || std::numeric_limits<genType>::is_integer, "'min' only accept floating-point or integer inputs");
return (y < x) ? y : x;
}
@ -23,7 +23,7 @@ namespace glm
template<typename genType>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType max(genType x, genType y)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || std::numeric_limits<genType>::is_integer || GLM_CONFIG_UNRESTRICTED_GENTYPE, "'max' only accept floating-point or integer inputs");
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || std::numeric_limits<genType>::is_integer, "'max' only accept floating-point or integer inputs");
return (x < y) ? y : x;
}
@ -474,7 +474,7 @@ namespace detail
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, T, Q> min(vec<L, T, Q> const& a, T b)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer || GLM_CONFIG_UNRESTRICTED_GENTYPE, "'min' only accept floating-point or integer inputs");
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, "'min' only accept floating-point or integer inputs");
return detail::compute_min_vector<L, T, Q, detail::is_aligned<Q>::value>::call(a, vec<L, T, Q>(b));
}
@ -488,7 +488,7 @@ namespace detail
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, T, Q> max(vec<L, T, Q> const& a, T b)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer || GLM_CONFIG_UNRESTRICTED_GENTYPE, "'max' only accept floating-point or integer inputs");
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, "'max' only accept floating-point or integer inputs");
return detail::compute_max_vector<L, T, Q, detail::is_aligned<Q>::value>::call(a, vec<L, T, Q>(b));
}
@ -502,21 +502,21 @@ namespace detail
template<typename genType>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType clamp(genType x, genType minVal, genType maxVal)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || std::numeric_limits<genType>::is_integer || GLM_CONFIG_UNRESTRICTED_GENTYPE, "'clamp' only accept floating-point or integer inputs");
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || std::numeric_limits<genType>::is_integer, "'clamp' only accept floating-point or integer inputs");
return min(max(x, minVal), maxVal);
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<L, T, Q> clamp(vec<L, T, Q> const& x, T minVal, T maxVal)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer || GLM_CONFIG_UNRESTRICTED_GENTYPE, "'clamp' only accept floating-point or integer inputs");
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, "'clamp' only accept floating-point or integer inputs");
return detail::compute_clamp_vector<L, T, Q, detail::is_aligned<Q>::value>::call(x, vec<L, T, Q>(minVal), vec<L, T, Q>(maxVal));
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER 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)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer || GLM_CONFIG_UNRESTRICTED_GENTYPE, "'clamp' only accept floating-point or integer inputs");
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer, "'clamp' only accept floating-point or integer inputs");
return detail::compute_clamp_vector<L, T, Q, detail::is_aligned<Q>::value>::call(x, minVal, maxVal);
}
@ -745,7 +745,7 @@ namespace detail
template<typename genType>
GLM_FUNC_QUALIFIER genType frexp(genType x, int& exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || GLM_CONFIG_UNRESTRICTED_GENTYPE, "'frexp' only accept floating-point inputs");
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'frexp' only accept floating-point inputs");
return std::frexp(x, &exp);
}
@ -753,7 +753,7 @@ namespace detail
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> frexp(vec<L, T, Q> const& v, vec<L, int, Q>& exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_GENTYPE, "'frexp' only accept floating-point inputs");
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'frexp' only accept floating-point inputs");
vec<L, T, Q> Result;
for (length_t l = 0; l < v.length(); ++l)
@ -764,7 +764,7 @@ namespace detail
template<typename genType>
GLM_FUNC_QUALIFIER genType ldexp(genType const& x, int const& exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || GLM_CONFIG_UNRESTRICTED_GENTYPE, "'ldexp' only accept floating-point inputs");
GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'ldexp' only accept floating-point inputs");
return std::ldexp(x, exp);
}
@ -772,7 +772,7 @@ namespace detail
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER vec<L, T, Q> ldexp(vec<L, T, Q> const& v, vec<L, int, Q> const& exp)
{
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_GENTYPE, "'ldexp' only accept floating-point inputs");
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'ldexp' only accept floating-point inputs");
vec<L, T, Q> Result;
for (length_t l = 0; l < v.length(); ++l)

View File

@ -661,27 +661,30 @@ void foo(vec4 const& v)
### <a name="section2_18"></a> 2.18. GLM\_FORCE\_UNRESTRICTED\_GENTYPE: Removing genType restriction
By default GLM only supports basic types as genType for vector, matrix and quaternion types:
GLSL has restrictions on types supported by certain functions that may appear excessive.
By default, GLM follows the GLSL specification as accurately as possible however it's possible to relax these rules using GLM\_FORCE\_UNRESTRICTED\_GENTYPE define.
```cpp
#include <glm/glm.hpp>
typedef glm::vec<4, float> my_fvec4;
float average(float const A, float const B)
{
return glm::mix(A, B, 0.5f); // By default glm::mix only supports floating-point types
}
```
GLM 0.9.8 introduced GLM\_FORCE\_UNRESTRICTED\_GENTYPE define to relax this restriction:
By defining GLM\_FORCE\_UNRESTRICTED\_GENTYPE, we allow using integer types:
```cpp
#define GLM_FORCE_UNRESTRICTED_GENTYPE
#include <glm/glm.hpp>
#include "half.hpp" // Define “half” class with behavior equivalent to “float”
typedef glm::vec<4, half> my_hvec4;
int average(int const A, int const B)
{
return glm::mix(A, B, 0.5f); // integers are ok thanks to GLM_FORCE_UNRESTRICTED_GENTYPE
}
```
However, defining `GLM_FORCE_UNRESTRICTED_GENTYPE` is not compatible with `GLM_FORCE_SWIZZLE` and will generate a compilation error if both are defined at the same time.
---
## <a name="section3"></a> 3. Stable extensions
@ -703,12 +706,12 @@ Include `<glm/ext/scalar_uint_sized.hpp>` to use these features.
#### 3.2.1. GLM_EXT_scalar_common
This extension exposes support for `min` and `max` functions taking more than two scalar arguments. Also, it adds `fmin` and `fmax` variants which prevents `NaN` probagation.
This extension exposes support for `min` and `max` functions taking more than two scalar arguments. Also, it adds `fmin` and `fmax` variants which prevents `NaN` propagation.
```cpp
#include <glm/ext/scalar_common.hpp>
float PositiveMax(float const a, float const b)
float positiveMax(float const a, float const b)
{
return glm::fmax(a, b, 0.0f);
}
@ -718,12 +721,12 @@ Include `<glm/ext/scalar_common.hpp>` to use these features.
#### 3.2.2. GLM_EXT_scalar_relational
This extension exposes `equal` and `notEqual` variants which takes an epsilon argument.
This extension exposes `equal` and `notEqual` scalar variants which takes an epsilon argument.
```cpp
#include <glm/ext/scalar_relational.hpp>
bool myEqual(float const a, float const b)
bool epsilonEqual(float const a, float const b)
{
float const CustomEpsilon = 0.0001f;
return glm::equal(a, b, CustomEpsilon);
@ -734,7 +737,26 @@ Include `<glm/ext/scalar_relational.hpp>` to use these features.
#### 3.2.3. GLM_EXT_scalar_constants
TODO
This extension exposes useful constants such as `epsilon` and `pi`.
```cpp
#include <glm/ext/scalar_constants.hpp>
float circumference(float const Diameter)
{
return glm::pi<float>() * Diameter;
}
```
```cpp
#include <glm/common.hpp> // abs
#include <glm/ext/scalar_constants.hpp> // epsilon
bool equalULP1(float const a, float const b)
{
return glm::abs(a - b) <= glm::epsilon<float>();
}
```
Include `<glm/ext/scalar_constants.hpp>` to use these features.
@ -764,13 +786,34 @@ TODO
#### 3.4.1. GLM_EXT_vector_common
TODO
This extension exposes support for `min` and `max` functions taking more than two vector arguments. Also, it adds `fmin` and `fmax` variants which prevents `NaN` propagation.
Include `<glm/ext/vector_constants.hpp>` to use these features.
```cpp
#include <glm/ext/vector_float2.hpp> // vec2
#include <glm/ext/vector_common.hpp> // fmax
float positiveMax(float const a, float const b)
{
return glm::fmax(a, b, 0.0f);
}
```
Include `<glm/ext/vector_common.hpp>` to use these features.
#### 3.4.2. GLM_EXT_vector_relational
TODO
This extension exposes `equal` and `notEqual` vector variants which takes an epsilon argument.
```cpp
#include <glm/ext/vector_float2.hpp> // vec2
#include <glm/ext/vector_relational.hpp> // equal, all
bool epsilonEqual(glm::vec2 const& A, glm::vec2 const& B)
{
float const CustomEpsilon = 0.0001f;
return glm::all(glm::equal(A, B, CustomEpsilon));
}
```
Include `<glm/ext/vector_relational.hpp>` to use these features.
@ -788,7 +831,20 @@ TODO
#### 3.6.1. GLM_EXT_matrix_relational
TODO
This extension exposes `equal` and `notEqual` matrix variants which takes an optional epsilon argument.
```cpp
#include <glm/ext/vector_bool4.hpp> // bvec4
#include <glm/ext/matrix_float4x4.hpp> // mat4
#include <glm/ext/matrix_relational.hpp> // equal, all
bool epsilonEqual(glm::mat4 const& A, glm::mat4 const& B)
{
float const CustomEpsilon = 0.0001f;
glm::bvec4 const ColumnEqual = glm::equal(A, B, CustomEpsilon); // Evaluation per column
return glm::all(ColumnEqual);
}
```
Include `<glm/ext/matrix_relational.hpp>` to use these features.