summaryrefslogtreecommitdiffstats
path: root/src/glsl/ir_constant_expression.cpp
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2010-07-23 12:36:50 -0700
committerKenneth Graunke <kenneth@whitecape.org>2010-07-28 15:46:29 -0700
commit5d255e24b29930e78321c1ba807df71fea12174a (patch)
tree6a6985b1e58aadb2276410de72eb17435a6e7cad /src/glsl/ir_constant_expression.cpp
parentb09ae5dd3f9b8e380e2608f4ee3a7902f5ecc15e (diff)
downloadexternal_mesa3d-5d255e24b29930e78321c1ba807df71fea12174a.zip
external_mesa3d-5d255e24b29930e78321c1ba807df71fea12174a.tar.gz
external_mesa3d-5d255e24b29930e78321c1ba807df71fea12174a.tar.bz2
ir_constant_expression: Add support for the "mix" builtin.
Both 1.10 and 1.30 variants.
Diffstat (limited to 'src/glsl/ir_constant_expression.cpp')
-rw-r--r--src/glsl/ir_constant_expression.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
index c4e6d83..9fc37b3 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) {