From 3981e0cd78e16a0f48a42696b55bf294d4a5c6bd Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 22 Apr 2008 02:31:01 -0400 Subject: [PATCH] Fix vector assignment in DP3 and DP4 in GLSL profile. --HG-- branch : trunk --- mojoshader.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/mojoshader.c b/mojoshader.c index 0a02eee8..5df452e0 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -2193,20 +2193,34 @@ static void emit_GLSL_RSQ(Context *ctx) 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)