From 4d4b775b7b03639eeab593bcc9eac700fd9086e7 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 6 Feb 2011 04:01:43 -0500 Subject: [PATCH] Allow constructors with sub-vectors (or whatever you'd call this). Now "float4(float3(1,2,3),1)" works as expected. --- mojoshader_compiler.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mojoshader_compiler.c b/mojoshader_compiler.c index 2d0cd7e8..936f5b83 100644 --- a/mojoshader_compiler.c +++ b/mojoshader_compiler.c @@ -2642,7 +2642,23 @@ static const MOJOSHADER_astDataType *type_check_ast(Context *ctx, void *_ast) break; } // if datatype2 = type_check_ast(ctx, arg->argument); - add_type_coercion(ctx, NULL, base_dt, &arg->argument, datatype2); + + // "float4(float3(1,2,3),4)" is legal, so we need to see if + // we're a vector, and jump that number of parameters instead + // of doing type coercion. + reduced = reduce_datatype(ctx, datatype2); + if (reduced->type == MOJOSHADER_AST_DATATYPE_VECTOR) + { + // make sure things like float4(half3(1,2,3),1) convert that half3 to float3. + const int count = reduced->vector.elements; + datatype3 = vectype_from_base(ctx, base_dt->type, count); + add_type_coercion(ctx, NULL, datatype3, &arg->argument, datatype2); + i += count - 1; + } // else + else + { + add_type_coercion(ctx, NULL, base_dt, &arg->argument, datatype2); + } // else prev = arg; arg = arg->next; } // for