Allow constructors with sub-vectors (or whatever you'd call this).
authorRyan C. Gordon <icculus@icculus.org>
Sun, 06 Feb 2011 04:01:43 -0500
changeset 987 109aeb1b6409
parent 986 805aa6eb75af
child 988 018e77a5ba67
Allow constructors with sub-vectors (or whatever you'd call this). Now "float4(float3(1,2,3),1)" works as expected.
mojoshader_compiler.c
--- a/mojoshader_compiler.c	Wed Jan 19 01:38:01 2011 -0800
+++ b/mojoshader_compiler.c	Sun Feb 06 04:01:43 2011 -0500
@@ -2642,7 +2642,23 @@
                     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