Browse Source

Fixed invalid conversion from int scalar with vec4 constructor when using SSE instruction

Groove 7 years ago
parent
commit
d4daef9150
3 changed files with 14 additions and 12 deletions
  1. 3 3
      glm/detail/type_vec4_simd.inl
  2. 1 0
      readme.md
  3. 10 9
      test/gtc/gtc_type_aligned.cpp

+ 3 - 3
glm/detail/type_vec4_simd.inl

@@ -446,19 +446,19 @@ namespace detail
 	template<>
 	template<>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<4, float, aligned_lowp>::vec(int32 _x, int32 _y, int32 _z, int32 _w) :
-		data(_mm_castsi128_ps(_mm_set_epi32(_w, _z, _y, _x)))
+		data(_mm_cvtepi32_ps(_mm_set_epi32(_w, _z, _y, _x)))
 	{}
 
 	template<>
 	template<>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<4, float, aligned_mediump>::vec(int32 _x, int32 _y, int32 _z, int32 _w) :
-		data(_mm_castsi128_ps(_mm_set_epi32(_w, _z, _y, _x)))
+		data(_mm_cvtepi32_ps(_mm_set_epi32(_w, _z, _y, _x)))
 	{}
 
 	template<>
 	template<>
 	GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<4, float, aligned_highp>::vec(int32 _x, int32 _y, int32 _z, int32 _w) :
-		data(_mm_castsi128_ps(_mm_set_epi32(_w, _z, _y, _x)))
+		data(_mm_cvtepi32_ps(_mm_set_epi32(_w, _z, _y, _x)))
 	{}
 #endif// GLM_USE_ALIGNED_GENTYPES == GLM_ENABLE
 }//namespace glm

+ 1 - 0
readme.md

@@ -74,6 +74,7 @@ glm::mat4 camera(float Translate, glm::vec2 const& Rotate)
 - Fixed Visual C++ 2013 warnings in vector relational code #782
 - Fixed ICC build errors with constexpr #704
 - Fixed defaulted operator= and constructors #791
+- Fixed invalid conversion from int scalar with vec4 constructor when using SSE instruction
 
 ### [GLM 0.9.9.0](https://github.com/g-truc/glm/releases/tag/0.9.9.0) - 2018-05-22
 #### Features:

+ 10 - 9
test/gtc/gtc_type_aligned.cpp

@@ -127,19 +127,20 @@ static int test_ctor()
 	return Error;
 }
 
-using namespace glm;
-
-typedef mat<4, 4, float, aligned> aligned_mat4;
-
 static int test_aligned_mat4()
 {
 	int Error = 0;
 
-	aligned_mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
-	aligned_mat4 t = transpose(m);
-	aligned_mat4 const expected = mat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15);
-	for (length_t l = 0; l < expected.length(); ++l)
-		Error += all(equal(t[l], expected[l], 0.0001f)) ? 0 : 1;
+	glm::aligned_vec4 const u(1.f, 2.f, 3.f, 4.f);
+	Error += glm::all(glm::equal(u, glm::aligned_vec4(1.f, 2.f, 3.f, 4.f), 0.0001f)) ? 0 : 1;
+
+	glm::aligned_vec4 const v(1, 2, 3, 4);
+	Error += glm::all(glm::equal(v, glm::aligned_vec4(1.f, 2.f, 3.f, 4.f), 0.0001f)) ? 0 : 1;
+
+	glm::aligned_mat4 const m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+	glm::aligned_mat4 const t = glm::transpose(m);
+	glm::aligned_mat4 const expected = glm::mat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15);
+	Error += glm::all(glm::equal(t, expected, 0.0001f)) ? 0 : 1;
 
 	return Error;
 }