No more default initialization of vector, matrix and quaternion types

This commit is contained in:
Christophe Riccio 2017-07-24 12:46:54 +02:00
parent c834d06c27
commit 4cf8a10af2
33 changed files with 48 additions and 169 deletions

View File

@ -692,14 +692,8 @@
#if GLM_HAS_DEFAULTED_FUNCTIONS
# define GLM_DEFAULT = default
# ifdef GLM_FORCE_NO_CTOR_INIT
# define GLM_DEFAULT_CTOR = default
# else
# define GLM_DEFAULT_CTOR
# endif
#else
# define GLM_DEFAULT
# define GLM_DEFAULT_CTOR
#endif
#if GLM_HAS_CONSTEXPR || GLM_HAS_CONSTEXPR_PARTIAL

View File

@ -34,7 +34,7 @@ namespace glm
// -- Constructors --
GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL mat() GLM_DEFAULT;
GLM_FUNC_DECL mat(mat<2, 2, T, P> const & m) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL mat(mat<2, 2, T, Q> const & m);

View File

@ -7,15 +7,10 @@ namespace glm
{
// -- Constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<2, 2, T, P>::mat()
{
# ifndef GLM_FORCE_NO_CTOR_INIT
this->value[0] = col_type(1, 0);
this->value[1] = col_type(0, 1);
# endif
}
{}
# endif
# if !GLM_HAS_DEFAULTED_FUNCTIONS

View File

@ -35,7 +35,7 @@ namespace glm
// -- Constructors --
GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL mat() GLM_DEFAULT;
GLM_FUNC_DECL mat(mat<2, 3, T, P> const & m) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL mat(mat<2, 3, T, Q> const & m);

View File

@ -5,15 +5,10 @@ namespace glm
{
// -- Constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<2, 3, T, P>::mat()
{
# ifndef GLM_FORCE_NO_CTOR_INIT
this->value[0] = col_type(1, 0, 0);
this->value[1] = col_type(0, 1, 0);
# endif
}
{}
# endif
# if !GLM_HAS_DEFAULTED_FUNCTIONS

View File

@ -35,7 +35,7 @@ namespace glm
// -- Constructors --
GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL mat() GLM_DEFAULT;
GLM_FUNC_DECL mat(mat<2, 4, T, P> const & m) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL mat(mat<2, 4, T, Q> const & m);

View File

@ -5,15 +5,10 @@ namespace glm
{
// -- Constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<2, 4, T, P>::mat()
{
# ifndef GLM_FORCE_NO_CTOR_INIT
this->value[0] = col_type(1, 0, 0, 0);
this->value[1] = col_type(0, 1, 0, 0);
# endif
}
{}
# endif
# if !GLM_HAS_DEFAULTED_FUNCTIONS

View File

@ -35,7 +35,7 @@ namespace glm
// -- Constructors --
GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL mat() GLM_DEFAULT;
GLM_FUNC_DECL mat(mat<3, 2, T, P> const & m) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL mat(mat<3, 2, T, Q> const & m);

View File

@ -5,16 +5,10 @@ namespace glm
{
// -- Constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 2, T, P>::mat()
{
# ifndef GLM_FORCE_NO_CTOR_INIT
this->value[0] = col_type(1, 0);
this->value[1] = col_type(0, 1);
this->value[2] = col_type(0, 0);
# endif
}
{}
# endif
# if !GLM_HAS_DEFAULTED_FUNCTIONS

View File

@ -34,7 +34,7 @@ namespace glm
// -- Constructors --
GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL mat() GLM_DEFAULT;
GLM_FUNC_DECL mat(mat<3, 3, T, P> const & m) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL mat(mat<3, 3, T, Q> const & m);

View File

@ -7,16 +7,10 @@ namespace glm
{
// -- Constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 3, T, P>::mat()
{
# ifndef GLM_FORCE_NO_CTOR_INIT
this->value[0] = col_type(1, 0, 0);
this->value[1] = col_type(0, 1, 0);
this->value[2] = col_type(0, 0, 1);
# endif
}
{}
# endif
# if !GLM_HAS_DEFAULTED_FUNCTIONS

View File

@ -35,7 +35,7 @@ namespace glm
// -- Constructors --
GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL mat() GLM_DEFAULT;
GLM_FUNC_DECL mat(mat<3, 4, T, P> const & m) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL mat(mat<3, 4, T, Q> const & m);

View File

@ -5,16 +5,10 @@ namespace glm
{
// -- Constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<3, 4, T, P>::mat()
{
# ifndef GLM_FORCE_NO_CTOR_INIT
this->value[0] = col_type(1, 0, 0, 0);
this->value[1] = col_type(0, 1, 0, 0);
this->value[2] = col_type(0, 0, 1, 0);
# endif
}
{}
# endif
# if !GLM_HAS_DEFAULTED_FUNCTIONS

View File

@ -35,7 +35,7 @@ namespace glm
// -- Constructors --
GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL mat() GLM_DEFAULT;
GLM_FUNC_DECL mat(mat<4, 2, T, P> const & m) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL mat(mat<4, 2, T, Q> const & m);

View File

@ -5,17 +5,10 @@ namespace glm
{
// -- Constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 2, T, P>::mat()
{
# ifndef GLM_FORCE_NO_CTOR_INIT
this->value[0] = col_type(1, 0);
this->value[1] = col_type(0, 1);
this->value[2] = col_type(0, 0);
this->value[3] = col_type(0, 0);
# endif
}
{}
# endif
# if !GLM_HAS_DEFAULTED_FUNCTIONS

View File

@ -35,7 +35,7 @@ namespace glm
// -- Constructors --
GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL mat() GLM_DEFAULT;
GLM_FUNC_DECL mat(mat<4, 3, T, P> const & m) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL mat(mat<4, 3, T, Q> const & m);

View File

@ -5,17 +5,10 @@ namespace glm
{
// -- Constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 3, T, P>::mat()
{
# ifndef GLM_FORCE_NO_CTOR_INIT
this->value[0] = col_type(1, 0, 0);
this->value[1] = col_type(0, 1, 0);
this->value[2] = col_type(0, 0, 1);
this->value[3] = col_type(0, 0, 0);
# endif
}
{}
# endif
# if !GLM_HAS_DEFAULTED_FUNCTIONS

View File

@ -34,7 +34,7 @@ namespace glm
// -- Constructors --
GLM_FUNC_DECL mat() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL mat() GLM_DEFAULT;
GLM_FUNC_DECL mat(mat<4, 4, T, P> const& m) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL mat(mat<4, 4, T, Q> const& m);

View File

@ -7,17 +7,10 @@ namespace glm
{
// -- Constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER mat<4, 4, T, P>::mat()
{
# ifndef GLM_FORCE_NO_CTOR_INIT
this->value[0] = col_type(1, 0, 0, 0);
this->value[1] = col_type(0, 1, 0, 0);
this->value[2] = col_type(0, 0, 1, 0);
this->value[3] = col_type(0, 0, 0, 1);
# endif
}
{}
# endif
# if !GLM_HAS_DEFAULTED_FUNCTIONS

View File

@ -85,7 +85,7 @@ namespace glm
// -- Implicit basic constructors --
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec() GLM_DEFAULT;
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec const& v) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, T, Q> const& v);

View File

@ -5,12 +5,9 @@ namespace glm
{
// -- Implicit basic constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<1, T, P>::vec()
# ifndef GLM_FORCE_NO_CTOR_INIT
: x(0)
# endif
{}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS

View File

@ -86,7 +86,7 @@ namespace glm
// -- Implicit basic constructors --
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec() GLM_DEFAULT;
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec const& v) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<2, T, Q> const& v);

View File

@ -5,12 +5,9 @@ namespace glm
{
// -- Implicit basic constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<2, T, P>::vec()
# ifndef GLM_FORCE_NO_CTOR_INIT
: x(0), y(0)
# endif
{}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS

View File

@ -86,7 +86,7 @@ namespace glm
// -- Implicit basic constructors --
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec() GLM_DEFAULT;
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec const & v) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<3, T, Q> const & v);

View File

@ -5,12 +5,9 @@ namespace glm
{
// -- Implicit basic constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_CTOR vec<3, T, P>::vec()
# ifndef GLM_FORCE_NO_CTOR_INIT
: x(0), y(0), z(0)
# endif
{}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS

View File

@ -89,7 +89,7 @@ namespace glm
// -- Implicit basic constructors --
GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec() GLM_DEFAULT;
GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec(vec<4, T, P> const& v) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec(vec<4, T, Q> const& v);

View File

@ -154,12 +154,9 @@ namespace detail
// -- Implicit basic constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR_SIMD vec<4, T, P>::vec()
# ifndef GLM_FORCE_NO_CTOR_INIT
: x(0), y(0), z(0), w(0)
# endif
{}
# endif//!GLM_HAS_DEFAULTED_FUNCTIONS

View File

@ -77,7 +77,7 @@ namespace glm
// -- Implicit basic constructors --
GLM_FUNC_DECL GLM_CONSTEXPR tquat() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL GLM_CONSTEXPR tquat() GLM_DEFAULT;
GLM_FUNC_DECL GLM_CONSTEXPR tquat(tquat<T, P> const& q) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL GLM_CONSTEXPR tquat(tquat<T, Q> const& q);

View File

@ -83,12 +83,9 @@ namespace detail
// -- Implicit basic constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR tquat<T, P>::tquat()
# ifndef GLM_FORCE_NO_CTOR_INIT
: x(0), y(0), z(0), w(1)
# endif
{}
# endif

View File

@ -56,7 +56,7 @@ namespace glm
// -- Implicit basic constructors --
GLM_FUNC_DECL GLM_CONSTEXPR tdualquat() GLM_DEFAULT_CTOR;
GLM_FUNC_DECL GLM_CONSTEXPR tdualquat() GLM_DEFAULT;
GLM_FUNC_DECL GLM_CONSTEXPR tdualquat(tdualquat<T, P> const & d) GLM_DEFAULT;
template<precision Q>
GLM_FUNC_DECL GLM_CONSTEXPR tdualquat(tdualquat<T, Q> const & d);

View File

@ -24,13 +24,9 @@ namespace glm
// -- Implicit basic constructors --
# if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
# if !GLM_HAS_DEFAULTED_FUNCTIONS
template<typename T, precision P>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR tdualquat<T, P>::tdualquat()
# ifndef GLM_FORCE_NO_CTOR_INIT
: real(tquat<T, P>())
, dual(tquat<T, P>(0, 0, 0, 0))
# endif
{}
# endif

View File

@ -22,9 +22,8 @@
+ [3.4. SIMD support](#section3_4)
+ [3.5. Force inline](#section3_5)
+ [3.6. Vector and matrix static size](#section3_6)
+ [3.7. Disabling default constructor initialization](#section3_7)
+ [3.8. Requiring explicit conversions](#section3_8)
+ [3.9. Removing genType restriction](#section3_9)
+ [3.7. Requiring explicit conversions](#section3_7)
+ [3.8. Removing genType restriction](#section3_8)
+ [4. Stable extensions](#section4)
+ [4.1. GLM_GTC_bitfield](#section4_1)
+ [4.2. GLM_GTC_color_space](#section4_2)
@ -469,49 +468,7 @@ void foo(vec4 const & v)
}
```
### <a name="section3_7"></a> 3.7. Disabling default constructor initialization
By default and following GLSL specifications, vector and matrix default constructors initialize the components to zero. This is a reliable behavior but initialization has a cost and its not always necessary.
This behavior can be disabled at compilation time by define GLM\_FORCE\_NO\_CTOR\_INIT before any inclusion of &lt;glm/glm.hpp&gt; or other GLM include.
GLM default behavior:
```cpp
#include <glm/glm.hpp>
void foo()
{
glm::vec4 v; // v is (0.0f, 0.0f, 0.0f, 0.0f)
...
}
```
GLM behavior using GLM\_FORCE\_NO\_CTOR\_INIT:
```cpp
#define GLM_FORCE_NO_CTOR_INIT
#include <glm/glm.hpp>
void foo()
{
glm::vec4 v; // v is filled with garbage
...
}
```
Alternatively, GLM allows to explicitly not initialize a variable:
```cpp
#include <glm/glm.hpp>
void foo()
{
glm::vec4 v(glm::uninitialize);
...
}
```
### <a name="section3_8"></a> 3.8. Require explicit conversions
### <a name="section3_7"></a> 3.7. Requiring explicit conversions
GLSL supports implicit conversions of vector and matrix types. For example, an ivec4 can be implicitly converted into vec4.
@ -548,7 +505,7 @@ void foo()
}
```
### <a name="section3_9"></a> 3.9. Removing genType restriction
### <a name="section3_8"></a> 3.8. Removing genType restriction
By default GLM only supports basic types as genType for vector, matrix and quaternion types:

View File

@ -64,6 +64,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
- Added quatLookAt to GTX_quaternion #659
#### Improvements:
- No more default initialization of vector, matrix and quaternion types
- Added lowp variant of GTC_color_space convertLinearToSRGB #419
- Replaced the manual by a markdown version #458
- Optimized GTC_packing implementation