ir_constant_expression: Add support for the "faceforward" builtin.
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 22 Jul 2010 04:46:16 +0000 (21:46 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Wed, 28 Jul 2010 22:46:29 +0000 (15:46 -0700)
src/glsl/ir_constant_expression.cpp

index 580ef1d4faec445bc466aee646a2cb78067daddf..c939690129a25a5fd16bbb9b7fb8ec474554e73f 100644 (file)
@@ -881,7 +881,10 @@ ir_call::constant_expression_value()
    } else if (strcmp(callee, "exp2") == 0) {
       expr = new(mem_ctx) ir_expression(ir_unop_exp2, type, op[0], NULL);
    } else if (strcmp(callee, "faceforward") == 0) {
-      return NULL; /* FINISHME: implement this */
+      if (dot(op[2], op[1]) < 0)
+        return op[0];
+      for (unsigned c = 0; c < op[0]->type->components(); c++)
+        data.f[c] = -op[0]->value.f[c];
    } else if (strcmp(callee, "floor") == 0) {
       expr = new(mem_ctx) ir_expression(ir_unop_floor, type, op[0], NULL);
    } else if (strcmp(callee, "fract") == 0) {