Browse Source

Optimized GTC_packing implementation

Christophe Riccio 9 years ago
parent
commit
32cfecba97
3 changed files with 13 additions and 12 deletions
  1. 10 10
      glm/gtc/packing.inl
  2. 1 0
      readme.md
  3. 2 2
      test/gtc/gtc_packing.cpp

+ 10 - 10
glm/gtc/packing.inl

@@ -554,11 +554,13 @@ namespace detail
 
 
 	GLM_FUNC_QUALIFIER uint32 packSnorm3x10_1x2(vec4 const & v)
 	GLM_FUNC_QUALIFIER uint32 packSnorm3x10_1x2(vec4 const & v)
 	{
 	{
+		ivec4 const Pack(round(clamp(v,-1.0f, 1.0f) * vec4(511.f, 511.f, 511.f, 1.f)));
+
 		detail::i10i10i10i2 Result;
 		detail::i10i10i10i2 Result;
-		Result.data.x = int(round(clamp(v.x,-1.0f, 1.0f) * 511.f));
-		Result.data.y = int(round(clamp(v.y,-1.0f, 1.0f) * 511.f));
-		Result.data.z = int(round(clamp(v.z,-1.0f, 1.0f) * 511.f));
-		Result.data.w = int(round(clamp(v.w,-1.0f, 1.0f) *   1.f));
+		Result.data.x = Pack.x;
+		Result.data.y = Pack.y;
+		Result.data.z = Pack.z;
+		Result.data.w = Pack.w;
 		return Result.pack;
 		return Result.pack;
 	}
 	}
 
 
@@ -566,12 +568,10 @@ namespace detail
 	{
 	{
 		detail::i10i10i10i2 Unpack;
 		detail::i10i10i10i2 Unpack;
 		Unpack.pack = v;
 		Unpack.pack = v;
-		vec4 Result;
-		Result.x = clamp(float(Unpack.data.x) / 511.f, -1.0f, 1.0f);
-		Result.y = clamp(float(Unpack.data.y) / 511.f, -1.0f, 1.0f);
-		Result.z = clamp(float(Unpack.data.z) / 511.f, -1.0f, 1.0f);
-		Result.w = clamp(float(Unpack.data.w) /   1.f, -1.0f, 1.0f);
-		return Result;
+
+		vec4 const Result(Unpack.data.x, Unpack.data.y, Unpack.data.z, Unpack.data.w);
+
+		return clamp(Result * vec4(1.f / 511.f, 1.f / 511.f, 1.f / 511.f, 1.f), -1.0f, 1.0f);
 	}
 	}
 
 
 	GLM_FUNC_QUALIFIER uint32 packUnorm3x10_1x2(vec4 const & v)
 	GLM_FUNC_QUALIFIER uint32 packUnorm3x10_1x2(vec4 const & v)

+ 1 - 0
readme.md

@@ -62,6 +62,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate)
 #### Improvements:
 #### Improvements:
 - Added lowp variant of GTC_colorspace convertLinearToSRGB #419
 - Added lowp variant of GTC_colorspace convertLinearToSRGB #419
 - Replaced the manual by a markdown version #458
 - Replaced the manual by a markdown version #458
+- Optimized GTC_packing implementation
 
 
 #### Fixes:
 #### Fixes:
 - Removed doxygen references to GTC_half_float which was removed in 0.9.4
 - Removed doxygen references to GTC_half_float which was removed in 0.9.4

+ 2 - 2
test/gtc/gtc_packing.cpp

@@ -690,10 +690,10 @@ int main()
 	Error += test_RGBM();
 	Error += test_RGBM();
 
 
 // It looks like GLM has a but that travis CI shows in this configuration #577
 // It looks like GLM has a but that travis CI shows in this configuration #577
-#if !((GLM_ARCH == GLM_ARCH_PURE) && (GLM_COMPILER & GLM_COMPILER_GCC))
+//#if !((GLM_ARCH == GLM_ARCH_PURE) && (GLM_COMPILER & GLM_COMPILER_GCC))
 	Error += test_Unorm3x10_1x2();
 	Error += test_Unorm3x10_1x2();
-#endif
 	Error += test_Snorm3x10_1x2();
 	Error += test_Snorm3x10_1x2();
+//#endif
 
 
 	Error += test_I3x10_1x2();
 	Error += test_I3x10_1x2();
 	Error += test_U3x10_1x2();
 	Error += test_U3x10_1x2();