From 5d255e24b29930e78321c1ba807df71fea12174a Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Fri, 23 Jul 2010 12:36:50 -0700 Subject: ir_constant_expression: Add support for the "mix" builtin. Both 1.10 and 1.30 variants. --- src/glsl/ir_constant_expression.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index c4e6d837b0..9fc37b3777 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -999,7 +999,19 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "min") == 0) { expr = new(mem_ctx) ir_expression(ir_binop_min, type, op[0], op[1]); } else if (strcmp(callee, "mix") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float() && op[1]->type->is_float()); + if (op[2]->type->is_float()) { + unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1; + unsigned components = op[0]->type->components(); + for (unsigned c = 0, c2 = 0; c < components; c2 += c2_inc, c++) { + data.f[c] = op[0]->value.f[c] * (1 - op[2]->value.f[c2]) + + op[1]->value.f[c] * op[2]->value.f[c2]; + } + } else { + assert(op[2]->type->is_boolean()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = op[op[2]->value.b[c] ? 1 : 0]->value.f[c]; + } } else if (strcmp(callee, "mod") == 0) { expr = new(mem_ctx) ir_expression(ir_binop_mod, type, op[0], op[1]); } else if (strcmp(callee, "normalize") == 0) { -- cgit v1.2.3