From d0ae3f966ea730ea1168c64cdae73f6675f47c6a Mon Sep 17 00:00:00 2001 From: Florian Penzkofer Date: Thu, 4 Oct 2018 17:23:44 -0500 Subject: [PATCH] Fix bitfieldInsert according to GLSL spec "bitfieldInsert inserts the bits least significant bits of insert into base at offset offset..." --- glm/detail/func_integer.inl | 2 +- test/core/core_func_integer.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/glm/detail/func_integer.inl b/glm/detail/func_integer.inl index 479789af6..f4067ffcc 100644 --- a/glm/detail/func_integer.inl +++ b/glm/detail/func_integer.inl @@ -269,7 +269,7 @@ namespace detail GLM_STATIC_ASSERT(std::numeric_limits::is_integer, "'bitfieldInsert' only accept integer values"); T const Mask = static_cast(detail::mask(Bits) << Offset); - return (Base & ~Mask) | (Insert & Mask); + return (Base & ~Mask) | ((Insert << static_cast(Offset)) & Mask); } // bitfieldReverse diff --git a/test/core/core_func_integer.cpp b/test/core/core_func_integer.cpp index 5413f2058..95d650c76 100644 --- a/test/core/core_func_integer.cpp +++ b/test/core/core_func_integer.cpp @@ -41,9 +41,9 @@ namespace bitfieldInsert {0x00000000, 0xffffffff, 0, 32, 0xffffffff}, {0x00000000, 0xffffffff, 0, 31, 0x7fffffff}, {0x00000000, 0xffffffff, 0, 0, 0x00000000}, - {0xff000000, 0x0000ff00, 8, 8, 0xff00ff00}, - {0xffff0000, 0x0000ffff, 16, 16, 0x00000000}, - {0x0000ffff, 0xffff0000, 16, 16, 0xffffffff} + {0xff000000, 0x000000ff, 8, 8, 0xff00ff00}, + {0xffff0000, 0xffff0000, 16, 16, 0x00000000}, + {0x0000ffff, 0x0000ffff, 16, 16, 0xffffffff} }; static int test()