Skip to content

Commit

Permalink
- Added GLM_FORCE_UNRESTRICTED_GENTYPE allowing non basic genType #543
Browse files Browse the repository at this point in the history
  • Loading branch information
Groovounet committed Sep 1, 2016
1 parent 1c5fd06 commit 10dc67e
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 39 deletions.
21 changes: 18 additions & 3 deletions glm/detail/setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,21 @@
///////////////////////////////////////////////////////////////////////////////////
// Swizzle operators

// User defines: GLM_SWIZZLE
// User defines: GLM_FORCE_SWIZZLE

#define GLM_SWIZZLE_ENABLED 1
#define GLM_SWIZZLE_DISABLE 0
#if defined(GLM_FORCE_SWIZZLE) || defined(GLM_SWIZZLE)
#undef GLM_SWIZZLE
#define GLM_SWIZZLE GLM_SWIZZLE_ENABLED
#else
#undef GLM_SWIZZLE
#define GLM_SWIZZLE GLM_SWIZZLE_DISABLE
#endif

#if defined(GLM_MESSAGES) && !defined(GLM_MESSAGE_SWIZZLE_DISPLAYED)
# define GLM_MESSAGE_SWIZZLE_DISPLAYED
# if defined(GLM_SWIZZLE)
# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
# pragma message("GLM: Swizzling operators enabled")
# else
# pragma message("GLM: Swizzling operators disabled, #define GLM_SWIZZLE to enable swizzle operators")
Expand All @@ -551,6 +561,11 @@
# define GLM_DEPTH_CLIP_SPACE GLM_DEPTH_NEGATIVE_ONE_TO_ONE
#endif

///////////////////////////////////////////////////////////////////////////////////
// Allows using not basic types as genType

// #define GLM_FORCE_UNRESTRICTED_GENTYPE

///////////////////////////////////////////////////////////////////////////////////
// Coordinate system, define GLM_FORCE_LEFT_HANDED before including GLM
// to use left handed coordinate system by default.
Expand Down Expand Up @@ -617,7 +632,7 @@
# define GLM_VECTOR_CALL
#endif//GLM_COMPILER

#if GLM_HAS_DEFAULTED_FUNCTIONS
#if GLM_HAS_DEFAULTED_FUNCTIONS && !defined(GLM_FORCE_UNRESTRICTED_GENTYPE)
# define GLM_DEFAULT = default
# ifdef GLM_FORCE_NO_CTOR_INIT
# define GLM_DEFAULT_CTOR = default
Expand Down
10 changes: 5 additions & 5 deletions glm/detail/type_vec1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "../fwd.hpp"
#include "type_vec.hpp"
#ifdef GLM_SWIZZLE
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
# if GLM_HAS_UNRESTRICTED_UNIONS
# include "_swizzle.hpp"
# else
Expand Down Expand Up @@ -44,7 +44,7 @@ namespace glm
T r;
T s;
/*
# ifdef GLM_SWIZZLE
# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
_GLM_SWIZZLE1_2_MEMBERS(T, P, tvec2, x)
_GLM_SWIZZLE1_2_MEMBERS(T, P, tvec2, r)
_GLM_SWIZZLE1_2_MEMBERS(T, P, tvec2, s)
Expand All @@ -66,7 +66,7 @@ namespace glm
# else
union {T x, r, s;};
/*
# ifdef GLM_SWIZZLE
# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
GLM_SWIZZLE_GEN_VEC_FROM_VEC1(T, P, tvec2, tvec2, tvec3, tvec4)
# endif//GLM_SWIZZLE*/
# endif
Expand Down Expand Up @@ -110,13 +110,13 @@ namespace glm

// -- Swizzle constructors --
/*
# if(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE))
# if(GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED))
template <int E0>
GLM_FUNC_DECL tvec1(detail::_swizzle<1, T, P, tvec1, E0, -1,-2,-3> const & that)
{
*this = that();
}
# endif//(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE))
# endif//(GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED))
*/
// -- Unary arithmetic operators --

Expand Down
10 changes: 5 additions & 5 deletions glm/detail/type_vec2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#pragma once

#include "type_vec.hpp"
#ifdef GLM_SWIZZLE
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
# if GLM_HAS_UNRESTRICTED_UNIONS
# include "_swizzle.hpp"
# else
Expand Down Expand Up @@ -43,7 +43,7 @@ namespace glm
struct{ T r, g; };
struct{ T s, t; };

# ifdef GLM_SWIZZLE
# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
_GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, x, y)
_GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, r, g)
_GLM_SWIZZLE2_2_MEMBERS(T, P, glm::tvec2, s, t)
Expand All @@ -67,7 +67,7 @@ namespace glm
union {T x, r, s;};
union {T y, g, t;};

# ifdef GLM_SWIZZLE
# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
GLM_SWIZZLE_GEN_VEC_FROM_VEC2(T, P, tvec2, tvec2, tvec3, tvec4)
# endif//GLM_SWIZZLE
# endif
Expand Down Expand Up @@ -116,13 +116,13 @@ namespace glm
GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tvec2(tvec2<U, Q> const & v);

// -- Swizzle constructors --
# if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
# if GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)
template <int E0, int E1>
GLM_FUNC_DECL tvec2(detail::_swizzle<2, T, P, glm::tvec2, E0, E1,-1,-2> const& that)
{
*this = that();
}
# endif// GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
# endif// GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)

// -- Unary arithmetic operators --

Expand Down
12 changes: 6 additions & 6 deletions glm/detail/type_vec3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#pragma once

#include "type_vec.hpp"
#ifdef GLM_SWIZZLE
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
# if GLM_HAS_UNRESTRICTED_UNIONS
# include "_swizzle.hpp"
# else
# include "_swizzle_func.hpp"
# endif
#endif //GLM_SWIZZLE
#endif //GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
#include <cstddef>

namespace glm
Expand Down Expand Up @@ -43,7 +43,7 @@ namespace glm
struct{ T r, g, b; };
struct{ T s, t, p; };

# ifdef GLM_SWIZZLE
# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
_GLM_SWIZZLE3_2_MEMBERS(T, P, glm::tvec2, x, y, z)
_GLM_SWIZZLE3_2_MEMBERS(T, P, glm::tvec2, r, g, b)
_GLM_SWIZZLE3_2_MEMBERS(T, P, glm::tvec2, s, t, p)
Expand All @@ -67,7 +67,7 @@ namespace glm
union { T y, g, t; };
union { T z, b, p; };

# ifdef GLM_SWIZZLE
# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
GLM_SWIZZLE_GEN_VEC_FROM_VEC3(T, P, tvec3, tvec2, tvec3, tvec4)
# endif//GLM_SWIZZLE
# endif//GLM_LANG
Expand Down Expand Up @@ -125,7 +125,7 @@ namespace glm
GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tvec3(tvec3<U, Q> const & v);

// -- Swizzle constructors --
# if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
# if GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)
template <int E0, int E1, int E2>
GLM_FUNC_DECL tvec3(detail::_swizzle<3, T, P, glm::tvec3, E0, E1, E2, -1> const & that)
{
Expand All @@ -143,7 +143,7 @@ namespace glm
{
*this = tvec3<T, P>(scalar, v());
}
# endif// GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
# endif// GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)

// -- Unary arithmetic operators --

Expand Down
10 changes: 5 additions & 5 deletions glm/detail/type_vec4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#pragma once

#include "type_vec.hpp"
#ifdef GLM_SWIZZLE
#if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
# if GLM_HAS_UNRESTRICTED_UNIONS
# include "_swizzle.hpp"
# else
Expand Down Expand Up @@ -45,7 +45,7 @@ namespace glm

typename detail::storage<T, sizeof(T) * 4, detail::is_aligned<P>::value>::type data;

# ifdef GLM_SWIZZLE
# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
_GLM_SWIZZLE4_2_MEMBERS(T, P, glm::tvec2, x, y, z, w)
_GLM_SWIZZLE4_2_MEMBERS(T, P, glm::tvec2, r, g, b, a)
_GLM_SWIZZLE4_2_MEMBERS(T, P, glm::tvec2, s, t, p, q)
Expand All @@ -70,7 +70,7 @@ namespace glm
union { T z, b, p; };
union { T w, a, q; };

# ifdef GLM_SWIZZLE
# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
GLM_SWIZZLE_GEN_VEC_FROM_VEC4(T, P, tvec4, tvec2, tvec3, tvec4)
# endif//GLM_SWIZZLE
# endif
Expand Down Expand Up @@ -146,7 +146,7 @@ namespace glm
GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT tvec4(tvec4<U, Q> const& v);

// -- Swizzle constructors --
# if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
# if GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)
template <int E0, int E1, int E2, int E3>
GLM_FUNC_DECL tvec4(detail::_swizzle<4, T, P, glm::tvec4, E0, E1, E2, E3> const & that)
{
Expand Down Expand Up @@ -188,7 +188,7 @@ namespace glm
{
*this = tvec4<T, P>(x, v());
}
# endif// GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
# endif// GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)

// -- Unary arithmetic operators --

Expand Down
4 changes: 2 additions & 2 deletions glm/detail/type_vec4_simd.inl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace glm{
namespace detail
{
# ifdef GLM_SWIZZLE
# if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
template <precision P, int E0, int E1, int E2, int E3>
struct _swizzle_base1<4, float, P, glm::tvec4, E0,E1,E2,E3, true> : public _swizzle_base0<float, 4>
{
Expand Down Expand Up @@ -49,7 +49,7 @@ namespace detail
return Result;
}
};
# endif//GLM_SWIZZLE
# endif// GLM_SWIZZLE == GLM_SWIZZLE_ENABLED

template <precision P>
struct compute_vec4_add<float, P, true>
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
- Added GTC_functions extension
- Added quaternion version of isnan and isinf #521
- Added lowestBitValue to GTX_bit #536
- Added GLM_FORCE_UNRESTRICTED_GENTYPE allowing non basic genType #543
##### Improvements:
- Improved SIMD and swizzle operators interactions with GCC and Clang #474
Expand Down Expand Up @@ -99,6 +100,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
- Deprecated GLM_GTX_simd_vec4 extension
- Deprecated GLM_GTX_simd_mat4 extension
- Deprecated GLM_GTX_simd_quat extension
- Deprecated GLM_SWIZZLE, use GLM_FORCE_SWIZZLE instead
--------------------------------------------------------------------------------
#### [GLM 0.9.7.6](https://github.com/g-truc/glm/releases/tag/0.9.7.6) - 2016-07-16
Expand Down
2 changes: 1 addition & 1 deletion test/core/core_func_swizzle.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define GLM_MESSAGES
#define GLM_SWIZZLE
#define GLM_FORCE_SWIZZLE
#include <glm/glm.hpp>

int test_ivec2_swizzle()
Expand Down
6 changes: 3 additions & 3 deletions test/core/core_type_vec1.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define GLM_SWIZZLE
#define GLM_FORCE_SWIZZLE
#include <glm/vector_relational.hpp>
#include <glm/gtc/vec1.hpp>
#include <vector>
Expand Down Expand Up @@ -65,7 +65,7 @@ int test_vec1_ctor()
}
#endif
*/
#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
{
glm::vec2 A = glm::vec2(1.0f, 2.0f);
glm::vec2 B = A.xy;
Expand All @@ -76,7 +76,7 @@ int test_vec1_ctor()
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
}
#endif//GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
#endif//GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)

{
glm::vec2 A = glm::vec2(2.0f);
Expand Down
6 changes: 3 additions & 3 deletions test/core/core_type_vec2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define GLM_SWIZZLE
#define GLM_FORCE_SWIZZLE
#include <glm/vector_relational.hpp>
#include <glm/vec2.hpp>
#include <vector>
Expand Down Expand Up @@ -230,7 +230,7 @@ int test_vec2_ctor()
}
#endif

#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
{
glm::vec2 A = glm::vec2(1.0f, 2.0f);
glm::vec2 B = A.xy;
Expand All @@ -241,7 +241,7 @@ int test_vec2_ctor()
Error += glm::all(glm::equal(A, C)) ? 0 : 1;
Error += glm::all(glm::equal(A, D)) ? 0 : 1;
}
#endif//GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
#endif//GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)

{
glm::vec2 A = glm::vec2(2.0f);
Expand Down
6 changes: 3 additions & 3 deletions test/core/core_type_vec3.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define GLM_SWIZZLE
#define GLM_FORCE_SWIZZLE
#include <glm/vector_relational.hpp>
#include <glm/geometric.hpp>
#include <glm/vec2.hpp>
Expand Down Expand Up @@ -40,7 +40,7 @@ int test_vec3_ctor()
}
#endif

#if(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE))
#if(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE))
{
glm::vec3 A = glm::vec3(1.0f, 2.0f, 3.0f);
glm::vec3 B = A.xyz;
Expand All @@ -59,7 +59,7 @@ int test_vec3_ctor()
Error += glm::all(glm::equal(A, G)) ? 0 : 1;
Error += glm::all(glm::equal(A, H)) ? 0 : 1;
}
#endif//(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE))
#endif//(GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE))

{
glm::vec3 A(1);
Expand Down
6 changes: 3 additions & 3 deletions test/core/core_type_vec4.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define GLM_FORCE_ALIGNED
#define GLM_SWIZZLE
#define GLM_FORCE_SWIZZLE
#include <glm/vector_relational.hpp>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
Expand Down Expand Up @@ -68,7 +68,7 @@ int test_vec4_ctor()
}
#endif

#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
#if GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)
{
glm::vec4 A = glm::vec4(1.0f, 2.0f, 3.0f, 4.0f);
glm::vec4 B = A.xyzw;
Expand Down Expand Up @@ -97,7 +97,7 @@ int test_vec4_ctor()
Error += glm::all(glm::equal(A, L)) ? 0 : 1;
Error += glm::all(glm::equal(A, M)) ? 0 : 1;
}
#endif// GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_SWIZZLE)
#endif// GLM_HAS_UNRESTRICTED_UNIONS && defined(GLM_FORCE_SWIZZLE)

{
glm::vec4 A(1);
Expand Down

0 comments on commit 10dc67e

Please sign in to comment.