Browse Source

Added GLM_FORCE_SINGLE_ONLY to use GLM on platforms that don't support double #627

Christophe Riccio 8 years ago
parent
commit
dc3e0b5ccb
6 changed files with 83 additions and 38 deletions
  1. 10 0
      glm/detail/setup.hpp
  2. 11 3
      glm/detail/type_float.hpp
  3. 34 26
      glm/gtc/type_precision.hpp
  4. 22 9
      glm/gtx/type_aligned.hpp
  5. 5 0
      manual.md
  6. 1 0
      readme.md

+ 10 - 0
glm/detail/setup.hpp

@@ -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
 

+ 11 - 3
glm/detail/type_float.hpp

@@ -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;
@@ -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
 
 	/// @}

+ 34 - 26
glm/gtc/type_precision.hpp

@@ -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
@@ -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
 
 
 	//////////////////////
@@ -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;
@@ -842,6 +844,8 @@ namespace glm
 	/// @see gtc_type_precision
 	typedef mat<4, 4, f64, defaultp> f64mat4x4;
 
+#	endif//GLM_FORCE_SINGLE_ONLY
+
 	//////////////////////////
 	// Quaternion types
 
@@ -849,10 +853,14 @@ namespace glm
 	/// @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
 

+ 22 - 9
glm/gtx/type_aligned.hpp

@@ -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
@@ -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);
@@ -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);
@@ -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 
@@ -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;
@@ -940,6 +947,8 @@ namespace glm
 	/// @see gtx_type_aligned
 	GLM_ALIGNED_TYPEDEF(f64mat4x4, aligned_f64mat4x4, 32);
 
+#	endif//GLM_FORCE_SINGLE_ONLY
+
 
 	//////////////////////////
 	// Quaternion types
@@ -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
 

+ 5 - 0
manual.md

@@ -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)
@@ -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
 

+ 1 - 0
readme.md

@@ -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