Skip to content

Commit

Permalink
Added GLM_FORCE_SINGLE_ONLY to use GLM on platforms that don't suppor…
Browse files Browse the repository at this point in the history
…t double #627
  • Loading branch information
Groovounet committed Sep 23, 2017
1 parent aa38362 commit dc3e0b5
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 38 deletions.
10 changes: 10 additions & 0 deletions glm/detail/setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,16 @@
# endif
#endif//GLM_MESSAGES

///////////////////////////////////////////////////////////////////////////////////
// Force single only (remove explicit float64 types)

#if GLM_MESSAGES == GLM_MESSAGES_ENABLED && !defined(GLM_MESSAGE_SINGLE_ONLY_DISPLAYED)
# define GLM_MESSAGE_SINGLE_ONLY_DISPLAYED
# ifdef GLM_FORCE_SINGLE_ONLY
# pragma message("GLM: Using only single precision floating-point types")
# endif
#endif//GLM_MESSAGES

///////////////////////////////////////////////////////////////////////////////////
// Clip control

Expand Down
14 changes: 11 additions & 3 deletions glm/detail/type_float.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ namespace glm{
namespace detail
{
typedef float float32;
typedef double float64;

# ifndef GLM_FORCE_SINGLE_ONLY
typedef double float64;
# endif//GLM_FORCE_SINGLE_ONLY
}//namespace detail

typedef float lowp_float_t;
Expand Down Expand Up @@ -53,13 +56,18 @@ namespace detail
#endif

typedef float float32;
typedef double float64;

# ifndef GLM_FORCE_SINGLE_ONLY
typedef double float64;
# endif//GLM_FORCE_SINGLE_ONLY

////////////////////
// check type sizes
#ifndef GLM_STATIC_ASSERT_NULL
GLM_STATIC_ASSERT(sizeof(glm::float32) == 4, "float32 size isn't 4 bytes on this platform");
GLM_STATIC_ASSERT(sizeof(glm::float64) == 8, "float64 size isn't 8 bytes on this platform");
# ifndef GLM_FORCE_SINGLE_ONLY
GLM_STATIC_ASSERT(sizeof(glm::float64) == 8, "float64 size isn't 8 bytes on this platform");
# endif//GLM_FORCE_SINGLE_ONLY
#endif//GLM_STATIC_ASSERT_NULL

/// @}
Expand Down
60 changes: 34 additions & 26 deletions glm/gtc/type_precision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,28 +592,27 @@ namespace glm
/// @see gtc_type_precision
typedef detail::float32 float32;

/// 64 bit double-qualifier floating-point scalar.
/// @see gtc_type_precision
typedef detail::float64 float64;


/// 32 bit single-qualifier floating-point scalar.
/// @see gtc_type_precision
typedef detail::float32 float32_t;

/// 64 bit double-qualifier floating-point scalar.
/// @see gtc_type_precision
typedef detail::float64 float64_t;


/// 32 bit single-qualifier floating-point scalar.
/// @see gtc_type_precision
typedef float32 f32;

/// 64 bit double-qualifier floating-point scalar.
/// @see gtc_type_precision
typedef float64 f64;
# ifndef GLM_FORCE_SINGLE_ONLY
/// 64 bit double-qualifier floating-point scalar.
/// @see gtc_type_precision
typedef detail::float64 float64;

/// 64 bit double-qualifier floating-point scalar.
/// @see gtc_type_precision
typedef detail::float64 float64_t;

/// 64 bit double-qualifier floating-point scalar.
/// @see gtc_type_precision
typedef float64 f64;
# endif//GLM_FORCE_SINGLE_ONLY

/// Single-qualifier floating-point vector of 1 component.
/// @see gtc_type_precision
Expand Down Expand Up @@ -648,22 +647,23 @@ namespace glm
/// @see gtc_type_precision
typedef vec<4, f32, defaultp> f32vec4;

# ifndef GLM_FORCE_SINGLE_ONLY
/// Double-qualifier floating-point vector of 1 component.
/// @see gtc_type_precision
typedef vec<1, f64, defaultp> f64vec1;

/// Double-qualifier floating-point vector of 1 component.
/// @see gtc_type_precision
typedef vec<1, f64, defaultp> f64vec1;
/// Double-qualifier floating-point vector of 2 components.
/// @see gtc_type_precision
typedef vec<2, f64, defaultp> f64vec2;

/// Double-qualifier floating-point vector of 2 components.
/// @see gtc_type_precision
typedef vec<2, f64, defaultp> f64vec2;

/// Double-qualifier floating-point vector of 3 components.
/// @see gtc_type_precision
typedef vec<3, f64, defaultp> f64vec3;
/// Double-qualifier floating-point vector of 3 components.
/// @see gtc_type_precision
typedef vec<3, f64, defaultp> f64vec3;

/// Double-qualifier floating-point vector of 4 components.
/// @see gtc_type_precision
typedef vec<4, f64, defaultp> f64vec4;
/// Double-qualifier floating-point vector of 4 components.
/// @see gtc_type_precision
typedef vec<4, f64, defaultp> f64vec4;
# endif//GLM_FORCE_SINGLE_ONLY


//////////////////////
Expand Down Expand Up @@ -785,6 +785,8 @@ namespace glm
typedef mat<4, 4, f32, defaultp> f32mat4x4;


# ifndef GLM_FORCE_SINGLE_ONLY

/// Double-qualifier floating-point 1x1 matrix.
/// @see gtc_type_precision
//typedef detail::tmat1x1<f64, defaultp> f64mat1;
Expand Down Expand Up @@ -842,17 +844,23 @@ namespace glm
/// @see gtc_type_precision
typedef mat<4, 4, f64, defaultp> f64mat4x4;

# endif//GLM_FORCE_SINGLE_ONLY

//////////////////////////
// Quaternion types

/// Single-qualifier floating-point quaternion.
/// @see gtc_type_precision
typedef tquat<f32, defaultp> f32quat;

# ifndef GLM_FORCE_SINGLE_ONLY

/// Double-qualifier floating-point quaternion.
/// @see gtc_type_precision
typedef tquat<f64, defaultp> f64quat;

# endif//GLM_FORCE_SINGLE_ONLY

/// @}
}//namespace glm

Expand Down
31 changes: 22 additions & 9 deletions glm/gtx/type_aligned.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,28 +622,30 @@ namespace glm
/// @see gtx_type_aligned
GLM_ALIGNED_TYPEDEF(float32, aligned_float32, 4);

/// 64 bit double-qualifier floating-point aligned scalar.
/// 32 bit single-qualifier floating-point aligned scalar.
/// @see gtx_type_aligned
GLM_ALIGNED_TYPEDEF(float64, aligned_float64, 8);

GLM_ALIGNED_TYPEDEF(float32_t, aligned_float32_t, 4);

/// 32 bit single-qualifier floating-point aligned scalar.
/// @see gtx_type_aligned
GLM_ALIGNED_TYPEDEF(float32_t, aligned_float32_t, 4);
GLM_ALIGNED_TYPEDEF(float32, aligned_f32, 4);

# ifndef GLM_FORCE_SINGLE_ONLY

/// 64 bit double-qualifier floating-point aligned scalar.
/// @see gtx_type_aligned
GLM_ALIGNED_TYPEDEF(float64_t, aligned_float64_t, 8);

GLM_ALIGNED_TYPEDEF(float64, aligned_float64, 8);

/// 32 bit single-qualifier floating-point aligned scalar.
/// 64 bit double-qualifier floating-point aligned scalar.
/// @see gtx_type_aligned
GLM_ALIGNED_TYPEDEF(float32, aligned_f32, 4);
GLM_ALIGNED_TYPEDEF(float64_t, aligned_float64_t, 8);

/// 64 bit double-qualifier floating-point aligned scalar.
/// @see gtx_type_aligned
GLM_ALIGNED_TYPEDEF(float64, aligned_f64, 8);

# endif//GLM_FORCE_SINGLE_ONLY


/// Single-qualifier floating-point aligned vector of 1 component.
/// @see gtx_type_aligned
Expand Down Expand Up @@ -678,7 +680,7 @@ namespace glm
/// @see gtx_type_aligned
GLM_ALIGNED_TYPEDEF(fvec4, aligned_fvec4, 16);


/// Single-qualifier floating-point aligned vector of 1 component.
/// @see gtx_type_aligned
GLM_ALIGNED_TYPEDEF(f32vec1, aligned_f32vec1, 4);
Expand Down Expand Up @@ -713,6 +715,8 @@ namespace glm
GLM_ALIGNED_TYPEDEF(dvec4, aligned_dvec4, 32);


# ifndef GLM_FORCE_SINGLE_ONLY

/// Double-qualifier floating-point aligned vector of 1 component.
/// @see gtx_type_aligned
GLM_ALIGNED_TYPEDEF(f64vec1, aligned_f64vec1, 8);
Expand All @@ -729,6 +733,7 @@ namespace glm
/// @see gtx_type_aligned
GLM_ALIGNED_TYPEDEF(f64vec4, aligned_f64vec4, 32);

# endif//GLM_FORCE_SINGLE_ONLY

//////////////////////
// Float matrix types
Expand Down Expand Up @@ -883,6 +888,8 @@ namespace glm
GLM_ALIGNED_TYPEDEF(f32mat4x4, aligned_f32mat4x4, 16);


# ifndef GLM_FORCE_SINGLE_ONLY

/// Double-qualifier floating-point aligned 1x1 matrix.
/// @see gtx_type_aligned
//typedef detail::tmat1x1<f64, defaultp> f64mat1;
Expand Down Expand Up @@ -940,6 +947,8 @@ namespace glm
/// @see gtx_type_aligned
GLM_ALIGNED_TYPEDEF(f64mat4x4, aligned_f64mat4x4, 32);

# endif//GLM_FORCE_SINGLE_ONLY


//////////////////////////
// Quaternion types
Expand All @@ -960,10 +969,14 @@ namespace glm
/// @see gtx_type_aligned
GLM_ALIGNED_TYPEDEF(f32quat, aligned_f32quat, 16);

# ifndef GLM_FORCE_SINGLE_ONLY

/// Double-qualifier floating-point aligned quaternion.
/// @see gtx_type_aligned
GLM_ALIGNED_TYPEDEF(f64quat, aligned_f64quat, 32);

# endif//GLM_FORCE_SINGLE_ONLY

/// @}
}//namespace glm

Expand Down
5 changes: 5 additions & 0 deletions manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
+ [3.6. GLM\_FORCE\_SIZE\_T\_LENGTH: Vector and matrix static size](#section3_6)
+ [3.7. GLM\_FORCE\_EXPLICIT\_CTOR: Requiring explicit conversions](#section3_7)
+ [3.8. GLM\_FORCE\_UNRESTRICTED\_GENTYPE: Removing genType restriction](#section3_8)
+ [3.9. GLM\_FORCE\_SINGLE\_ONLY: Removed explicit 64-bits floating point types](#section3_9)
+ [4. Stable extensions](#section4)
+ [4.1. GLM_GTC_bitfield](#section4_1)
+ [4.2. GLM_GTC_color_space](#section4_2)
Expand Down Expand Up @@ -528,6 +529,10 @@ typedef glm::vec<4, half> my_hvec4;

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_9"></a> 3.9. GLM\_FORCE\_SINGLE\_ONLY: Removed explicit 64-bits floating point types

Some platforms (Dreamcast) doesn't support double precision floating point values. To compile on such platforms, GCC has the --m4-single-only build argument. When defining GLM\_FORCE\_SINGLE\_ONLY before including GLM headers, GLM releases the requirement of double precision floating point values support. Effectivement, all the float64 types are no longer defined and double behaves like float.

---
## <a name="section4"></a> 4. Stable extensions

Expand Down
1 change: 1 addition & 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 EXT_vec1: *vec1 types
- Added GTX_texture: levels function
- Added spearate functions to use both nagative one and zero near clip plans #680
- Added GLM_FORCE_SINGLE_ONLY to use GLM on platforms that don't support double #627
#### Improvements:
- No more default initialization of vector, matrix and quaternion types
Expand Down

0 comments on commit dc3e0b5

Please sign in to comment.