ir_constant_visitor: Handle bool-to-int and int-to-bool
authorIan Romanick <ian.d.romanick@intel.com>
Fri, 11 Jun 2010 20:46:30 +0000 (13:46 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 11 Jun 2010 22:43:59 +0000 (15:43 -0700)
ir_constant_expression.cpp

index 781166a8a262d4e8c8c9356a50b54672af88880d..a3ce6e7e591ef6ff0a76da281dd37bc661f07252 100644 (file)
@@ -183,6 +183,21 @@ ir_constant_visitor::visit(ir_expression *ir)
         b[c] = bool(op[0]->value.f[c]);
       }
       break;
+   case ir_unop_b2i:
+      assert(op[0]->type->base_type == GLSL_TYPE_BOOL);
+      type = ir->type;
+      for (c = 0; c < ir->operands[0]->type->components(); c++) {
+        u[c] = op[0]->value.b[c] ? 1 : 0;
+        i[c] = u[c];
+      }
+      break;
+   case ir_unop_i2b:
+      assert(op[0]->type->is_integer());
+      type = ir->type;
+      for (c = 0; c < ir->operands[0]->type->components(); c++) {
+        b[c] = bool(op[0]->value.u[c]);
+      }
+      break;
 
    case ir_unop_neg:
       type = ir->type;