summaryrefslogtreecommitdiffstats
path: root/src/glsl/ir_constant_expression.cpp
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2010-07-21 22:23:17 -0700
committerKenneth Graunke <[email protected]>2010-07-28 15:46:29 -0700
commita4ca1cfb66160c4ea2325f503ff025a4adc35084 (patch)
tree7e896fd863a141fd61ce8b878539626b24e2e827 /src/glsl/ir_constant_expression.cpp
parentff58b7c9b6f513ed8bf57b3e4283b67b06fd9d34 (diff)
ir_constant_expression: Add support for the "clamp" builtin.
Diffstat (limited to 'src/glsl/ir_constant_expression.cpp')
-rw-r--r--src/glsl/ir_constant_expression.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
index 5485d79a88f..a2748a726cc 100644
--- a/src/glsl/ir_constant_expression.cpp
+++ b/src/glsl/ir_constant_expression.cpp
@@ -836,7 +836,30 @@ ir_call::constant_expression_value()
} else if (strcmp(callee, "ceil") == 0) {
expr = new(mem_ctx) ir_expression(ir_unop_ceil, type, op[0], NULL);
} else if (strcmp(callee, "clamp") == 0) {
- return NULL; /* FINISHME: implement this */
+ assert(num_parameters == 3);
+ unsigned c1_inc = op[1]->type->is_scalar() ? 0 : 1;
+ unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1;
+ for (unsigned c = 0, c1 = 0, c2 = 0;
+ c < op[0]->type->components();
+ c1 += c1_inc, c2 += c2_inc, c++) {
+
+ switch (op[0]->type->base_type) {
+ case GLSL_TYPE_UINT:
+ data.u[c] = CLAMP(op[0]->value.u[c], op[1]->value.u[c1],
+ op[2]->value.u[c2]);
+ break;
+ case GLSL_TYPE_INT:
+ data.i[c] = CLAMP(op[0]->value.i[c], op[1]->value.i[c1],
+ op[2]->value.u[c2]);
+ break;
+ case GLSL_TYPE_FLOAT:
+ data.f[c] = CLAMP(op[0]->value.f[c], op[1]->value.f[c1],
+ op[2]->value.f[c2]);
+ break;
+ default:
+ assert(!"Should not get here.");
+ }
+ }
} else if (strcmp(callee, "cos") == 0) {
expr = new(mem_ctx) ir_expression(ir_unop_cos, type, op[0], NULL);
} else if (strcmp(callee, "cosh") == 0) {