[svn] Writemask fix. trunk
authoricculus
Sun, 16 Mar 2008 23:20:08 -0400
branchtrunk
changeset 27 3524701d26fb
parent 26 ed1dc1eca8b2
child 28 bdb89e56bb91
[svn] Writemask fix.
d3d2glsl.c
--- a/d3d2glsl.c	Sun Mar 16 23:05:23 2008 -0400
+++ b/d3d2glsl.c	Sun Mar 16 23:20:08 2008 -0400
@@ -508,17 +508,24 @@
         return "";
     } // if
 
-    const char *dot_str = (arg->writemask != 0) ? "." : "";
-    const char *x_str = (arg->writemask0 != 0) ? "x" : "";
-    const char *y_str = (arg->writemask1 != 0) ? "y" : "";
-    const char *z_str = (arg->writemask2 != 0) ? "z" : "";
-    const char *w_str = (arg->writemask3 != 0) ? "w" : "";
+    char writemask_str[6];
+    int i = 0;
+    if (arg->writemask != 0xF)  // 0xF == 1111. No explicit mask.
+    {
+        writemask_str[i++] = '.';
+        if (arg->writemask0) writemask_str[i++] = 'x';
+        if (arg->writemask1) writemask_str[i++] = 'y';
+        if (arg->writemask2) writemask_str[i++] = 'z';
+        if (arg->writemask3) writemask_str[i++] = 'w';
+    } // if
+    writemask_str[i] = '\0';
+    assert(i < sizeof (writemask_str));
 
     // may turn out something like "_x2_sat_pp_centroid r0.xyzw" ...
     char *retval = get_scratch_buffer(ctx);
-    snprintf(retval, D3D2GLSL_SCRATCH_BUFFER_SIZE, "%s%s%s%s %s%s%s%s%s%s%s",
+    snprintf(retval, D3D2GLSL_SCRATCH_BUFFER_SIZE, "%s%s%s%s %s%s%s",
              result_shift_str, sat_str, pp_str, cent_str,
-             regtype_str, regnum_str, dot_str, x_str, y_str, z_str, w_str);
+             regtype_str, regnum_str, writemask_str);
     return retval;
 } // make_D3D_destarg_string