diff --git a/glm/gtc/packing.inl b/glm/gtc/packing.inl index 332840bd..032ecd88 100644 --- a/glm/gtc/packing.inl +++ b/glm/gtc/packing.inl @@ -554,11 +554,13 @@ namespace detail 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; - 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; } @@ -566,12 +568,10 @@ namespace detail { detail::i10i10i10i2 Unpack; 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) diff --git a/readme.md b/readme.md index f7c91f97..74cd6463 100644 --- a/readme.md +++ b/readme.md @@ -62,6 +62,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) #### Improvements: - Added lowp variant of GTC_colorspace convertLinearToSRGB #419 - Replaced the manual by a markdown version #458 +- Optimized GTC_packing implementation #### Fixes: - Removed doxygen references to GTC_half_float which was removed in 0.9.4 diff --git a/test/gtc/gtc_packing.cpp b/test/gtc/gtc_packing.cpp index 4e309aa5..0229dfd3 100644 --- a/test/gtc/gtc_packing.cpp +++ b/test/gtc/gtc_packing.cpp @@ -690,10 +690,10 @@ int main() Error += test_RGBM(); // 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(); -#endif Error += test_Snorm3x10_1x2(); +//#endif Error += test_I3x10_1x2(); Error += test_U3x10_1x2();