Browse Source

Fixed GCC 4.5 and older build #566

Christophe Riccio 9 years ago
parent
commit
2dda5af72c

+ 5 - 0
glm/detail/setup.hpp

@@ -451,6 +451,11 @@
 		((GLM_COMPILER & GLM_COMPILER_CUDA) && (GLM_COMPILER >= GLM_COMPILER_CUDA70))))
 #endif
 
+#define GLM_HAS_ONLY_XYZW ((GLM_COMPILER & GLM_COMPILER_GCC) && (GLM_COMPILER < GLM_COMPILER_GCC46))
+#if GLM_HAS_ONLY_XYZW
+#	pragma message("GLM: GCC older than 4.6 has a bug presenting the use of rgba and stpq components")
+#endif
+
 //
 #if GLM_LANG & GLM_LANG_CXX11_FLAG
 #	define GLM_HAS_ASSIGNABLE 1

+ 4 - 1
glm/detail/type_vec1.hpp

@@ -27,7 +27,10 @@ namespace glm
 
 		// -- Data --
 
-#		if GLM_HAS_ALIGNED_TYPE
+#		if GLM_HAS_ONLY_XYZW
+			T x;
+
+#		elif GLM_HAS_ALIGNED_TYPE
 #			if GLM_COMPILER & GLM_COMPILER_GCC
 #				pragma GCC diagnostic push
 #				pragma GCC diagnostic ignored "-Wpedantic"

+ 4 - 1
glm/detail/type_vec2.hpp

@@ -26,7 +26,10 @@ namespace glm
 
 		// -- Data --
 
-#		if GLM_HAS_ALIGNED_TYPE
+#		if GLM_HAS_ONLY_XYZW
+			T x, y;
+
+#		elif GLM_HAS_ALIGNED_TYPE
 #			if GLM_COMPILER & GLM_COMPILER_GCC
 #				pragma GCC diagnostic push
 #				pragma GCC diagnostic ignored "-Wpedantic"

+ 4 - 1
glm/detail/type_vec3.hpp

@@ -26,7 +26,10 @@ namespace glm
 
 		// -- Data --
 
-#		if GLM_HAS_ALIGNED_TYPE
+#		if GLM_HAS_ONLY_XYZW
+			T x, y, z;
+
+#		elif GLM_HAS_ALIGNED_TYPE
 #			if GLM_COMPILER & GLM_COMPILER_GCC
 #				pragma GCC diagnostic push
 #				pragma GCC diagnostic ignored "-Wpedantic"

+ 5 - 2
glm/detail/type_vec4.hpp

@@ -26,7 +26,10 @@ namespace glm
 
 		// -- Data --
 
-#		if GLM_HAS_ALIGNED_TYPE
+#		if GLM_HAS_ONLY_XYZW
+			T x, y, z, w;
+
+#		elif GLM_HAS_ALIGNED_TYPE
 #			if GLM_COMPILER & GLM_COMPILER_GCC
 #				pragma GCC diagnostic push
 #				pragma GCC diagnostic ignored "-Wpedantic"
@@ -36,7 +39,7 @@ namespace glm
 #				pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
 #				pragma clang diagnostic ignored "-Wnested-anon-types"
 #			endif
-		
+
 			union
 			{
 				struct { T x, y, z, w;};

+ 2 - 2
glm/gtc/color_space.inl

@@ -23,7 +23,7 @@ namespace detail
 	{
 		GLM_FUNC_QUALIFIER static tvec4<T, P> call(tvec4<T, P> const& ColorRGB, T GammaCorrection)
 		{
-			return tvec4<T, P>(compute_rgbToSrgb<T, P, tvec3>::call(tvec3<T, P>(ColorRGB), GammaCorrection), ColorRGB.a);
+			return tvec4<T, P>(compute_rgbToSrgb<T, P, tvec3>::call(tvec3<T, P>(ColorRGB), GammaCorrection), ColorRGB.w);
 		}
 	};
 
@@ -44,7 +44,7 @@ namespace detail
 	{
 		GLM_FUNC_QUALIFIER static tvec4<T, P> call(tvec4<T, P> const& ColorSRGB, T Gamma)
 		{
-			return tvec4<T, P>(compute_srgbToRgb<T, P, tvec3>::call(tvec3<T, P>(ColorSRGB), Gamma), ColorSRGB.a);
+			return tvec4<T, P>(compute_srgbToRgb<T, P, tvec3>::call(tvec3<T, P>(ColorSRGB), Gamma), ColorSRGB.w);
 		}
 	};
 }//namespace detail

+ 10 - 12
glm/gtx/color_space.inl

@@ -105,20 +105,18 @@ namespace glm
 	{
 		tvec3<T, defaultp> rgbw = tvec3<T, defaultp>(T(0.2126), T(0.7152), T(0.0722));
 
-		T col0 = (T(1) - s) * rgbw.r;
-		T col1 = (T(1) - s) * rgbw.g;
-		T col2 = (T(1) - s) * rgbw.b;
+		tvec3<T, defaultp> const col((T(1) - s) * rgbw);
 
 		tmat4x4<T, defaultp> result(T(1));
-		result[0][0] = col0 + s;
-		result[0][1] = col0;
-		result[0][2] = col0;
-		result[1][0] = col1;
-		result[1][1] = col1 + s;
-		result[1][2] = col1;
-		result[2][0] = col2;
-		result[2][1] = col2;
-		result[2][2] = col2 + s;
+		result[0][0] = col.x + s;
+		result[0][1] = col.x;
+		result[0][2] = col.x;
+		result[1][0] = col.y;
+		result[1][1] = col.y + s;
+		result[1][2] = col.y;
+		result[2][0] = col.z;
+		result[2][1] = col.z;
+		result[2][2] = col.z + s;
 		return result;
 	}
 

+ 1 - 0
readme.md

@@ -58,6 +58,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
 - Fixed intersectRayPlane returns true in parallel case #578
 - Fixed GCC 6.2 compiler warnings #580
 - Fixed GTX_matrix_decompose decompose #582 #448
+- Fixed GCC 4.5 and older build #566
 
 #### [GLM 0.9.8.3](https://github.com/g-truc/glm/releases/tag/0.9.8.3) - 2016-11-12
 ##### Improvements:

+ 9 - 4
test/core/core_func_swizzle.cpp

@@ -2,6 +2,8 @@
 #define GLM_FORCE_SWIZZLE
 #include <glm/glm.hpp>
 
+#if !GLM_HAS_ONLY_XYZW
+
 int test_ivec2_swizzle()
 {
 	int Error = 0;
@@ -60,16 +62,19 @@ int test_vec4_swizzle()
 
 	return Error;
 }
+#endif//!GLM_HAS_ONLY_XYZW
 
 int main()
 {
 	int Error = 0;
 
-	Error += test_ivec2_swizzle();
-	Error += test_ivec3_swizzle();
-	Error += test_ivec4_swizzle();
+#	if !GLM_HAS_ONLY_XYZW
+		Error += test_ivec2_swizzle();
+		Error += test_ivec3_swizzle();
+		Error += test_ivec4_swizzle();
 
-	Error += test_vec4_swizzle();
+		Error += test_vec4_swizzle();
+#	endif//!GLM_HAS_ONLY_XYZW
 
 	return Error;
 }

+ 1 - 1
test/core/core_setup_message.cpp

@@ -226,7 +226,7 @@ int test_instruction_set()
 
 int test_cpp_version()
 {
-	std::printf("__cplusplus: %lld\n", __cplusplus);
+	std::printf("__cplusplus: %d\n", static_cast<int>(__cplusplus));
 	
 	return 0;
 }

+ 8 - 3
test/core/core_type_vec3.cpp

@@ -334,6 +334,7 @@ int test_vec3_swizzle3_3()
 	return Error;
 }
 
+#if !GLM_HAS_ONLY_XYZW
 int test_vec3_swizzle_operators()
 {
 	int Error = 0;
@@ -440,6 +441,7 @@ int test_vec3_swizzle_partial()
 
 	return Error;
 }
+#endif//!GLM_HAS_ONLY_XYZW
 
 int test_operator_increment()
 {
@@ -480,10 +482,13 @@ int main()
 	Error += test_vec3_size();
 	Error += test_vec3_swizzle3_2();
 	Error += test_vec3_swizzle3_3();
-	Error += test_vec3_swizzle_partial();
-	Error += test_vec3_swizzle_operators();
-	Error += test_vec3_swizzle_functions();
 	Error += test_operator_increment();
 
+#	if !GLM_HAS_ONLY_XYZW
+		Error += test_vec3_swizzle_partial();
+		Error += test_vec3_swizzle_operators();
+		Error += test_vec3_swizzle_functions();
+#	endif//!GLM_HAS_ONLY_XYZW
+
 	return Error;
 }