Skip to content

Commit

Permalink
Fixed default initialization with vector and quaternion types using G…
Browse files Browse the repository at this point in the history
…LM_FORCE_CTOR_INIT g-truc#812
  • Loading branch information
Groovounet committed Sep 10, 2018
1 parent cf6504b commit fe83040
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 10 deletions.
9 changes: 5 additions & 4 deletions glm/detail/setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,21 +710,22 @@ namespace detail
///////////////////////////////////////////////////////////////////////////////////
// Configure the use of defaulted initialized types

#define GLM_CTOR_INITIALIZER_LIST (1 << 1)
#define GLM_CTOR_INITIALISATION (1 << 2)
#define GLM_CTOR_INIT_DISABLE 0
#define GLM_CTOR_INITIALIZER_LIST 1
#define GLM_CTOR_INITIALISATION 2

#if defined(GLM_FORCE_CTOR_INIT) && GLM_HAS_INITIALIZER_LISTS
# define GLM_CONFIG_CTOR_INIT GLM_CTOR_INITIALIZER_LIST
#elif defined(GLM_FORCE_CTOR_INIT) && !GLM_HAS_INITIALIZER_LISTS
# define GLM_CONFIG_CTOR_INIT GLM_CTOR_INITIALISATION
#else
# define GLM_CONFIG_CTOR_INIT GLM_DISABLE
# define GLM_CONFIG_CTOR_INIT GLM_CTOR_INIT_DISABLE
#endif

///////////////////////////////////////////////////////////////////////////////////
// Configure the use of defaulted function

#if GLM_HAS_DEFAULTED_FUNCTIONS && GLM_CONFIG_CTOR_INIT == GLM_DISABLE
#if GLM_HAS_DEFAULTED_FUNCTIONS && GLM_CONFIG_CTOR_INIT == GLM_CTOR_INIT_DISABLE
# define GLM_CONFIG_DEFAULTED_FUNCTIONS GLM_ENABLE
# define GLM_DEFAULT = default
#else
Expand Down
2 changes: 1 addition & 1 deletion glm/detail/type_quat.inl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace detail
# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_DISABLE
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR qua<T, Q>::qua()
# if GLM_CONFIG_DEFAULTED_FUNCTIONS != GLM_DISABLE
# if GLM_CONFIG_CTOR_INIT != GLM_CTOR_INIT_DISABLE
: x(0), y(0), z(0), w(1)
# endif
{}
Expand Down
2 changes: 1 addition & 1 deletion glm/detail/type_vec1.inl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace glm
# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_DISABLE
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<1, T, Q>::vec()
# if GLM_CONFIG_DEFAULTED_FUNCTIONS != GLM_DISABLE
# if GLM_CONFIG_CTOR_INIT != GLM_CTOR_INIT_DISABLE
: x(0)
# endif
{}
Expand Down
2 changes: 1 addition & 1 deletion glm/detail/type_vec2.inl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace glm
# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_DISABLE
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<2, T, Q>::vec()
# if GLM_CONFIG_DEFAULTED_FUNCTIONS != GLM_DISABLE
# if GLM_CONFIG_CTOR_INIT != GLM_CTOR_INIT_DISABLE
: x(0), y(0)
# endif
{}
Expand Down
2 changes: 1 addition & 1 deletion glm/detail/type_vec3.inl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace glm
# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_DISABLE
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<3, T, Q>::vec()
# if GLM_CONFIG_DEFAULTED_FUNCTIONS != GLM_DISABLE
# if GLM_CONFIG_CTOR_INIT != GLM_CTOR_INIT_DISABLE
: x(0), y(0), z(0)
# endif
{}
Expand Down
2 changes: 1 addition & 1 deletion glm/detail/type_vec4.inl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ namespace detail
# if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_DISABLE
template<typename T, qualifier Q>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<4, T, Q>::vec()
# if GLM_CONFIG_DEFAULTED_FUNCTIONS != GLM_DISABLE
# if GLM_CONFIG_CTOR_INIT != GLM_CTOR_INIT_DISABLE
: x(0), y(0), z(0), w(0)
# endif
{}
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ glm::mat4 camera(float Translate, glm::vec2 const& Rotate)
### [GLM 0.9.9.2](https://github.com/g-truc/glm/commits/master) - 2018-XX-XX
#### Fixes:
- Fixed GLM_FORCE_CXX** section in the manual
- Fixed default initialization with vector and quaternion types using GLM_FORCE_CTOR_INIT #812
### [GLM 0.9.9.1](https://github.com/g-truc/glm/releases/tag/0.9.9.1) - 2018-09-03
#### Features:
Expand Down
127 changes: 127 additions & 0 deletions test/core/core_force_ctor_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,137 @@
#include <glm/glm.hpp>
#include <glm/ext.hpp>

static int test_vec()
{
int Error = 0;

glm::vec1 V1;
Error += glm::all(glm::equal(V1, glm::vec1(0), glm::epsilon<float>())) ? 0 : 1;

glm::dvec1 U1;
Error += glm::all(glm::equal(U1, glm::dvec1(0), glm::epsilon<double>())) ? 0 : 1;

glm::vec2 V2;
Error += glm::all(glm::equal(V2, glm::vec2(0, 0), glm::epsilon<float>())) ? 0 : 1;

glm::dvec2 U2;
Error += glm::all(glm::equal(U2, glm::dvec2(0, 0), glm::epsilon<double>())) ? 0 : 1;

glm::vec3 V3;
Error += glm::all(glm::equal(V3, glm::vec3(0, 0, 0), glm::epsilon<float>())) ? 0 : 1;

glm::dvec3 U3;
Error += glm::all(glm::equal(U3, glm::dvec3(0, 0, 0), glm::epsilon<double>())) ? 0 : 1;

glm::vec4 V4;
Error += glm::all(glm::equal(V4, glm::vec4(0, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1;

glm::dvec4 U4;
Error += glm::all(glm::equal(U4, glm::dvec4(0, 0, 0, 0), glm::epsilon<double>())) ? 0 : 1;

return Error;
}

static int test_mat()
{
int Error = 0;

{
glm::mat2x2 F;
Error += glm::all(glm::equal(F, glm::mat2x2(1), glm::epsilon<float>())) ? 0 : 1;

glm::dmat2x2 D;
Error += glm::all(glm::equal(D, glm::dmat2x2(1), glm::epsilon<double>())) ? 0 : 1;
}

{
glm::mat2x3 F;
Error += glm::all(glm::equal(F, glm::mat2x3(1), glm::epsilon<float>())) ? 0 : 1;

glm::dmat2x3 D;
Error += glm::all(glm::equal(D, glm::dmat2x3(1), glm::epsilon<double>())) ? 0 : 1;
}

{
glm::mat2x4 F;
Error += glm::all(glm::equal(F, glm::mat2x4(1), glm::epsilon<float>())) ? 0 : 1;

glm::dmat2x4 D;
Error += glm::all(glm::equal(D, glm::dmat2x4(1), glm::epsilon<double>())) ? 0 : 1;
}

{
glm::mat3x2 F;
Error += glm::all(glm::equal(F, glm::mat3x2(1), glm::epsilon<float>())) ? 0 : 1;

glm::dmat3x2 D;
Error += glm::all(glm::equal(D, glm::dmat3x2(1), glm::epsilon<double>())) ? 0 : 1;
}

{
glm::mat3x3 F;
Error += glm::all(glm::equal(F, glm::mat3x3(1), glm::epsilon<float>())) ? 0 : 1;

glm::dmat3x3 D;
Error += glm::all(glm::equal(D, glm::dmat3x3(1), glm::epsilon<double>())) ? 0 : 1;
}

{
glm::mat3x4 F;
Error += glm::all(glm::equal(F, glm::mat3x4(1), glm::epsilon<float>())) ? 0 : 1;

glm::dmat3x4 D;
Error += glm::all(glm::equal(D, glm::dmat3x4(1), glm::epsilon<double>())) ? 0 : 1;
}

{
glm::mat4x2 F;
Error += glm::all(glm::equal(F, glm::mat4x2(1), glm::epsilon<float>())) ? 0 : 1;

glm::dmat4x2 D;
Error += glm::all(glm::equal(D, glm::dmat4x2(1), glm::epsilon<double>())) ? 0 : 1;
}

{
glm::mat4x3 F;
Error += glm::all(glm::equal(F, glm::mat4x3(1), glm::epsilon<float>())) ? 0 : 1;

glm::dmat4x3 D;
Error += glm::all(glm::equal(D, glm::dmat4x3(1), glm::epsilon<double>())) ? 0 : 1;
}

{
glm::mat4x4 F;
Error += glm::all(glm::equal(F, glm::mat4x4(1), glm::epsilon<float>())) ? 0 : 1;

glm::dmat4x4 D;
Error += glm::all(glm::equal(D, glm::dmat4x4(1), glm::epsilon<double>())) ? 0 : 1;
}

return Error;
}

static int test_qua()
{
int Error = 0;

glm::quat F;
Error += glm::all(glm::equal(F, glm::quat(1, 0, 0, 0), glm::epsilon<float>())) ? 0 : 1;

glm::dquat D;
Error += glm::all(glm::equal(D, glm::dquat(1, 0, 0, 0), glm::epsilon<double>())) ? 0 : 1;

return Error;
}

int main()
{
int Error = 0;

Error += test_vec();
Error += test_mat();
Error += test_qua();

return Error;
}

5 changes: 4 additions & 1 deletion test/core/core_force_pure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,10 @@ namespace heap
p->f = 0.f;
delete p;

Error += sizeof(B) == (sizeof(glm::vec4) + sizeof(float) * 2) ? 0 : 1;
std::size_t const Count1 = sizeof(B);
std::size_t const Count2 = 32;

Error += Count1 == Count2 ? 0 : 1;

return Error;
}
Expand Down

0 comments on commit fe83040

Please sign in to comment.