From a4ca1cfb66160c4ea2325f503ff025a4adc35084 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 22:23:17 -0700 Subject: ir_constant_expression: Add support for the "clamp" builtin. --- src/glsl/ir_constant_expression.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 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 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) { -- cgit v1.2.3