Fixed GLSL source register swizzles. Kinda scary that never got caught before.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 06 Apr 2010 15:39:16 -0400
changeset 908 93e2e2f17bbb
parent 907 ce28b304dbd0
child 909 1859faa45249
Fixed GLSL source register swizzles. Kinda scary that never got caught before.
mojoshader.c
--- a/mojoshader.c	Tue Apr 06 15:38:54 2010 -0400
+++ b/mojoshader.c	Tue Apr 06 15:39:16 2010 -0400
@@ -1864,10 +1864,10 @@
     size_t i = 0;
     if ( (!no_swizzle(swizzle)) || (!writemask_xyzw(writemask)) )
     {
-        const int writemask0 = (writemask >> 0) & 0x1;
-        const int writemask1 = (writemask >> 1) & 0x1;
-        const int writemask2 = (writemask >> 2) & 0x1;
-        const int writemask3 = (writemask >> 3) & 0x1;
+        int writemask_count = ( ((writemask >> 0) & 0x1) +
+                                ((writemask >> 1) & 0x1) +
+                                ((writemask >> 2) & 0x1) +
+                                ((writemask >> 3) & 0x1) );
 
         const int swizzle_x = (swizzle >> 0) & 0x3;
         const int swizzle_y = (swizzle >> 2) & 0x3;
@@ -1875,10 +1875,10 @@
         const int swizzle_w = (swizzle >> 6) & 0x3;
 
         swiz_str[i++] = '.';
-        if (writemask0) swiz_str[i++] = swizzle_channels[swizzle_x];
-        if (writemask1) swiz_str[i++] = swizzle_channels[swizzle_y];
-        if (writemask2) swiz_str[i++] = swizzle_channels[swizzle_z];
-        if (writemask3) swiz_str[i++] = swizzle_channels[swizzle_w];
+        if (writemask_count-- > 0) swiz_str[i++] = swizzle_channels[swizzle_x];
+        if (writemask_count-- > 0) swiz_str[i++] = swizzle_channels[swizzle_y];
+        if (writemask_count-- > 0) swiz_str[i++] = swizzle_channels[swizzle_z];
+        if (writemask_count-- > 0) swiz_str[i++] = swizzle_channels[swizzle_w];
     } // if
     assert(i < strsize);
     swiz_str[i] = '\0';