Core GLM features can be included using individual headers to allow faster user program compilations.
* <glm/vec2.hpp>: vec2, bvec2, dvec2, ivec2 and uvec2
* <glm/vec3.hpp>: vec3, bvec3, dvec3, ivec3 and uvec3
* <glm/vec4.hpp>: vec4, bvec4, dvec4, ivec4 and uvec4
* <glm/mat2x2.hpp>: mat2, dmat2
* <glm/mat2x3.hpp>: mat2x3, dmat2x3
* <glm/mat2x4.hpp>: mat2x4, dmat2x4
* <glm/mat3x2.hpp>: mat3x2, dmat3x2
* <glm/mat3x3.hpp>: mat3, dmat3
* <glm/mat3x4.hpp>: mat3x4, dmat2
* <glm/mat4x2.hpp>: mat4x2, dmat4x2
* <glm/mat4x3.hpp>: mat4x3, dmat4x3
* <glm/mat4x4.hpp>: mat4, dmat4
* <glm/common.hpp>: all the GLSL common functions
* <glm/exponential.hpp>: all the GLSL exponential functions
* <glm/geometry.hpp>: all the GLSL geometry functions
* <glm/integer.hpp>: all the GLSL integer functions
* <glm/matrix.hpp>: all the GLSL matrix functions
* <glm/packing.hpp>: all the GLSL packing functions
* <glm/trigonometric.hpp>: all the GLSL trigonometric functions
* <glm/vector\_relational.hpp>: all the GLSL vector relational functions
```cpp
#include<glm/vec2.hpp> // vec2, bvec2, dvec2, ivec2 and uvec2
#include<glm/vec3.hpp> // vec3, bvec3, dvec3, ivec3 and uvec3
#include<glm/vec4.hpp> // vec4, bvec4, dvec4, ivec4 and uvec4
#include<glm/mat2x2.hpp> // mat2, dmat2
#include<glm/mat2x3.hpp> // mat2x3, dmat2x3
#include<glm/mat2x4.hpp> // mat2x4, dmat2x4
#include<glm/mat3x2.hpp> // mat3x2, dmat3x2
#include<glm/mat3x3.hpp> // mat3, dmat3
#include<glm/mat3x4.hpp> // mat3x4, dmat2
#include<glm/mat4x2.hpp> // mat4x2, dmat4x2
#include<glm/mat4x3.hpp> // mat4x3, dmat4x3
#include<glm/mat4x4.hpp> // mat4, dmat4
#include<glm/common.hpp> // all the GLSL common functions
#include<glm/exponential.hpp> // all the GLSL exponential functions
#include<glm/geometry.hpp> // all the GLSL geometry functions
#include<glm/integer.hpp> // all the GLSL integer functions
#include<glm/matrix.hpp> // all the GLSL matrix functions
#include<glm/packing.hpp> // all the GLSL packing functions
#include<glm/trigonometric.hpp> // all the GLSL trigonometric functions
#include<glm/vector\_relational.hpp> // all the GLSL vector relational functions
```
### 1.2. Faster program compilation
@ -140,8 +142,7 @@ GLM is a header only library that makes a heavy usage of C++ templates.
This design may significantly increase the compile time for files that use GLM. Hence, it is important to limit GLM inclusion to header and source files that actually use it. Likewise, GLM extensions should be
included only in program sources using them.
To further help compilation time, GLM 0.9.5 introduced
<glm/fwd.hpp> that provides forward declarations of GLM types.
To further help compilation time, GLM 0.9.5 introduced <glm/fwd.hpp> that provides forward declarations of GLM types.
```cpp
// Header file
@ -298,66 +299,46 @@ functions so that the programmer must convert a swizzle operators to a
vector type or call the () operator on a swizzle objects to pass it to
In C++, it is not possible to implement GLSL default precision (GLSL
4.10 specification section 4.5.3) using GLSL syntax.
In C++, it is not possible to implement GLSL default precision (GLSL 4.10 specification section 4.5.3) using GLSL syntax.
------------------------
```cpp
precision mediump int;
precision highp float;
------------------------
------------------------
To use the default precision functionality, GLM provides some defines
that need to add before any include of glm.hpp:
----------------------------------------
\#define GLM\_PRECISION\_MEDIUMP\_INT;
```
\#define GLM\_PRECISION\_HIGHP\_FLOAT;
To use the default precision functionality, GLM provides some defines that need to add before any include of glm.hpp:
\#include <glm/glm.hpp>
----------------------------------------
----------------------------------------
```cpp
#define GLM_PRECISION_MEDIUMP_INT
#define GLM_PRECISION_HIGHP_FLOAT
#include<glm/glm.hpp>
```
Available defines for floating point types (glm::vec\*, glm::mat\*):
@ -374,53 +355,36 @@ GLM\_PRECISION\_HIGHP\_DOUBLE: High precision (default)
Available defines for signed integer types (glm::ivec\*):
GLM\_PRECISION\_LOWP\_INT: Low precision
GLM\_PRECISION\_MEDIUMP\_INT: Medium precision
GLM\_PRECISION\_HIGHP\_INT: High precision (default)
Available defines for unsigned integer types (glm::uvec\*):
GLM\_PRECISION\_LOWP\_UINT: Low precision
GLM\_PRECISION\_MEDIUMP\_UINT: Medium precision
GLM\_PRECISION\_HIGHP\_UINT: High precision (default)
3.2. Compile-time message system {#compile-time-message-system .HeadingB}
--------------------------------
GLM includes a notification system which can display some information at
build time:
- Platform: Windows, Linux, Native Client, QNX, etc.
- Compiler: Visual C++, Clang, GCC, ICC, etc.
- Build model: 32bits or 64 bits
- C++ version: C++98, C++11, MS extensions, etc.
### 3.2. Compile-time message system {#compile-time-message-system .HeadingB}
- Architecture: x86, SSE, AVX, etc.
GLM includes a notification system which can display some information at build time:
- Included extensions
* Platform: Windows, Linux, Native Client, QNX, etc.
* Compiler: Visual C++, Clang, GCC, ICC, etc.
* Build model: 32bits or 64 bits
* C++ version: C++98, C++11, MS extensions, etc.
* Architecture: x86, SSE, AVX, etc.
* Included extensions
* etc.
- etc.
This system is disabled by default. To enable this system, define
GLM\_FORCE\_MESSAGES before any inclusion of <glm/glm.hpp>. The
messages are generated only by compiler supporting \#program message and
This system is disabled by default. To enable this system, define GLM\_FORCE\_MESSAGES before any inclusion of <glm/glm.hpp>. The messages are generated only by compiler supporting \#program message and
only once per project build.
-------------------------------
\#define GLM\_FORCE\_MESSAGES
\#include <glm/glm.hpp>
-------------------------------
-------------------------------
```cpp
#define GLM_FORCE_MESSAGES
#include<glm/glm.hpp>
```
3.3. C++ language detection {#c-language-detection .HeadingB}
---------------------------
### 3.3. C++ language detection
GLM will automatically take advantage of compilers’ language extensions
when enabled. To increase cross platform compatibility and to avoid
@ -428,128 +392,96 @@ compiler extensions, a programmer can define GLM\_FORCE\_CXX98 before
any inclusion of <glm/glm.hpp> to restrict the language feature
set C++98:
-------------------------------
\#define GLM\_FORCE\_CXX98
\#include <glm/glm.hpp>
-------------------------------
-------------------------------
```cpp
#define GLM_FORCE_CXX98
#include<glm/glm.hpp>
```
For C++11 and C++14, equivalent defines are available:
GLM\_FORCE\_CXX11, GLM\_FORCE\_CXX14.
-------------------------------
\#define GLM\_FORCE\_CXX11
```cpp
#define GLM_FORCE_CXX11
#include<glm/glm.hpp>
\#include <glm/glm.hpp>
-------------------------------
-------------------------------
// If the compiler doesn’t support C++11, compiler errors will happen.
```
GLM\_FORCE\_CXX14 overrides GLM\_FORCE\_CXX11 and GLM\_FORCE\_CXX11
overrides GLM\_FORCE\_CXX98 defines.
3.4. SIMD support {#simd-support .HeadingB}
-----------------
### 3.4. SIMD support
GLM provides some SIMD optimizations based on [compiler
// GLM code will be compiled using pure C++ code without any intrinsics
```
```cpp
#define GLM_FORCE_AVX2
#include<glm/glm.hpp>
// If the compiler doesn’t support AVX2 instrinsics, compiler errors will happen.
```
Additionally, GLM provides a low level SIMD API in glm/simd directory
for users who are really interested in writing fast algorithms.
3.5. Force inline {#force-inline .HeadingB}
-----------------
### 3.5. Force inline
To push further the software performance, a programmer can define
GLM\_FORCE\_INLINE before any inclusion of <glm/glm.hpp> to force
the compiler to inline GLM code.
-------------------------------
\#define GLM\_FORCE\_INLINE
\#include <glm/glm.hpp>
-------------------------------
-------------------------------
```cpp
#define GLM_FORCE_INLINE
#include<glm/glm.hpp>
```
3.6. Vector and matrix static size {#vector-and-matrix-static-size .HeadingB}
----------------------------------
### 3.6. Vector and matrix static size
GLSL supports the member function .length() for all vector and matrix
types.
GLSL supports the member function .length() for all vector and matrix types.
-------------------------------
\#include <glm/glm.hpp>
```cpp
#include<glm/glm.hpp>
void foo(vec4 const & v)
{
> int Length = v.length();
>
> …
int Length = v.length();
...
}
-------------------------------
-------------------------------
This function returns a int however this function typically interacts
with STL size\_t based code. GLM provides GLM\_FORCE\_SIZE\_T\_LENGTH
pre-processor option so that member functions length() return a size\_t.
```
Additionally, GLM defines the type glm::length\_t to identify length()
returned type, independently from GLM\_FORCE\_SIZE\_T\_LENGTH.
This function returns a int however this function typically interacts with STL size\_t based code. GLM provides GLM\_FORCE\_SIZE\_T\_LENGTH pre-processor option so that member functions length() return a size\_t.
--------------------------------------
\#define GLM\_FORCE\_SIZE\_T\_LENGTH
Additionally, GLM defines the type glm::length\_t to identify length() returned type, independently from GLM\_FORCE\_SIZE\_T\_LENGTH.
GLSL supports implicit conversions of vector and matrix types. For
example, an ivec4 can be implicitly converted into vec4.
GLSL supports implicit conversions of vector and matrix types. For example, an ivec4 can be implicitly converted into vec4.
Often, this behaviour is not desirable but following the spirit of the
library, this behavior is supported in GLM. However, GLM 0.9.6
introduced the define GLM\_FORCE\_EXPLICIT\_CTOR to require explicit
Often, this behaviour is not desirable but following the spirit of the library, this behavior is supported in GLM. However, GLM 0.9.6 introduced the define GLM\_FORCE\_EXPLICIT\_CTOR to require explicit
#include "half.hpp" // Define “half” class with equivalent behavior than “float”
\#include <glm/gtc/matrix\_transform.hpp>
typedef glm::tvec4<half> my_hvec4;
```
int foo()
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.
{
## 4. Stable extensions
glm::vec4 Position = glm::vec4(glm:: vec3(0.0f), 1.0f);
GLM extends the core GLSL feature set with extensions. These extensions include: quaternion, transformation, spline, matrix inverse, color spaces, etc.
glm::mat4 Model = glm::translate(
To include an extension, we only need to include the dedicated header file. Once included, the features are added to the GLM namespace.
> glm::mat4(1.0f), glm::vec3(1.0f));
```cpp
#include<glm/glm.hpp>
#include<glm/gtc/matrix_transform.hpp>
glm::vec4 Transformed = Model \* Position;
int foo()
{
glm::vec4 Position = glm::vec4(glm:: vec3(0.0f), 1.0f);
glm::mat4 Model = glm::translate(glm::mat4(1.0f), glm::vec3(1.0f));