Christophe Riccio 10 лет назад
Родитель
Сommit
8508e099d0
2 измененных файлов с 22 добавлено и 3 удалено
  1. 4 3
      glm/gtx/component_wise.inl
  2. 18 0
      test/gtx/gtx_component_wise.cpp

+ 4 - 3
glm/gtx/component_wise.inl

@@ -77,9 +77,10 @@ namespace detail
 	{
 		GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<floatType, P> const & v)
 		{
-			floatType const Min = static_cast<floatType>(std::numeric_limits<T>::min());
-			floatType const Max = static_cast<floatType>(std::numeric_limits<T>::max());
-			return (vecType<floatType, P>(v) + Min) * (Max - Min) * static_cast<floatType>(2) - static_cast<floatType>(1);
+			floatType const Max = static_cast<floatType>(std::numeric_limits<T>::max()) + static_cast<floatType>(0.5);
+			vecType<floatType, P> const Scaled(v * Max);
+			vecType<T, P> const Result(Scaled - static_cast<floatType>(0.5));
+			return Result;
 		}
 	};
 

+ 18 - 0
test/gtx/gtx_component_wise.cpp

@@ -104,6 +104,15 @@ namespace compScale
 			Error += A.w == 255 ? 0 : 1;
 		}
 
+		{
+			glm::i8vec4 const A = glm::compScale<glm::i8>(glm::vec4(0.0f,-1.0f, 0.5f, 1.0f));
+
+			Error += A.x == 0 ? 0 : 1;
+			Error += A.y == -128 ? 0 : 1;
+			Error += A.z == 63 ? 0 : 1;
+			Error += A.w == 127 ? 0 : 1;
+		}
+
 		{
 			glm::u16vec4 const A = glm::compScale<glm::u16>(glm::vec4(0.0f, 0.2f, 0.5f, 1.0f));
 
@@ -113,6 +122,15 @@ namespace compScale
 			Error += A.w == 65535 ? 0 : 1;
 		}
 
+		{
+			glm::i16vec4 const A = glm::compScale<glm::i16>(glm::vec4(0.0f,-1.0f, 0.5f, 1.0f));
+
+			Error += A.x == 0 ? 0 : 1;
+			Error += A.y == -32768 ? 0 : 1;
+			Error += A.z == 16383 ? 0 : 1;
+			Error += A.w == 32767 ? 0 : 1;
+		}
+
 		return Error;
 	}
 }// compScale