glsl2: Use i2b and f2b IR opcodes for casting int or float to bool
authorIan Romanick <ian.d.romanick@intel.com>
Fri, 25 Jun 2010 23:19:45 +0000 (16:19 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Mon, 28 Jun 2010 17:04:18 +0000 (10:04 -0700)
src/glsl/ast_function.cpp

index 761af00b95e9740b9d0dd6888e85487b82249c1a..f431d1d0156858ccca932dd8ec119ce380d08bdd 100644 (file)
@@ -172,17 +172,17 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
         break;
       }
       break;
-   case GLSL_TYPE_BOOL: {
-      ir_constant *zero = NULL;
-
+   case GLSL_TYPE_BOOL:
       switch (b) {
-      case GLSL_TYPE_UINT:  zero = new(ctx) ir_constant(unsigned(0)); break;
-      case GLSL_TYPE_INT:   zero = new(ctx) ir_constant(int(0));      break;
-      case GLSL_TYPE_FLOAT: zero = new(ctx) ir_constant(0.0f);        break;
+      case GLSL_TYPE_UINT:
+      case GLSL_TYPE_INT:
+        result = new(ctx) ir_expression(ir_unop_i2b, desired_type, src, NULL);
+        break;
+      case GLSL_TYPE_FLOAT:
+        result = new(ctx) ir_expression(ir_unop_f2b, desired_type, src, NULL);
+        break;
       }
-
-      result = new(ctx) ir_expression(ir_binop_nequal, desired_type, src, zero);
-   }
+      break;
    }
 
    assert(result != NULL);