Fix vector assignment in DP3 and DP4 in GLSL profile. trunk
authorRyan C. Gordon <icculus@icculus.org>
Tue, 22 Apr 2008 02:31:01 -0400
branchtrunk
changeset 178 b1d354511685
parent 177 ca94ec9366f7
child 179 3db6b937958e
Fix vector assignment in DP3 and DP4 in GLSL profile.
mojoshader.c
--- a/mojoshader.c	Tue Apr 22 02:18:44 2008 -0400
+++ b/mojoshader.c	Tue Apr 22 02:31:01 2008 -0400
@@ -2193,20 +2193,34 @@
     output_line(ctx, "%s", code);
 } // emit_GLSL_RSQ
 
+static void emit_GLSL_dotprod(Context *ctx, const char *src0, const char *src1)
+{
+    const int vecsize = vecsize_from_writemask(ctx->dest_arg.writemask);
+    char castleft[16] = { '\0' };
+    const char *castright = "";
+    if (vecsize != 1)
+    {
+        snprintf(castleft, sizeof (castleft), "vec%d(", vecsize);
+        castright = ")";
+    } // if
+
+    const char *code = make_GLSL_destarg_assign(ctx, "%sdot(%s, %s)%s",
+                        castleft, src0, src1, castright);
+    output_line(ctx, "%s", code);
+} // emit_GLSL_dotprod
+
 static void emit_GLSL_DP3(Context *ctx)
 {
     const char *src0 = make_GLSL_srcarg_string_vec3(ctx, 0);
     const char *src1 = make_GLSL_srcarg_string_vec3(ctx, 1);
-    const char *code = make_GLSL_destarg_assign(ctx, "dot(%s, %s)", src0, src1);
-    output_line(ctx, "%s", code);
+    emit_GLSL_dotprod(ctx, src0, src1);
 } // emit_GLSL_DP3
 
 static void emit_GLSL_DP4(Context *ctx)
 {
     const char *src0 = make_GLSL_srcarg_string_full(ctx, 0);
     const char *src1 = make_GLSL_srcarg_string_full(ctx, 1);
-    const char *code = make_GLSL_destarg_assign(ctx, "dot(%s, %s)", src0, src1);
-    output_line(ctx, "%s", code);
+    emit_GLSL_dotprod(ctx, src0, src1);
 } // emit_GLSL_DP4
 
 static void emit_GLSL_MIN(Context *ctx)