Construct an ir_constant from a scalar component of another ir_constant
authorIan Romanick <ian.d.romanick@intel.com>
Fri, 4 Jun 2010 23:13:35 +0000 (16:13 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 11 Jun 2010 20:51:09 +0000 (13:51 -0700)
ir.cpp
ir.h

diff --git a/ir.cpp b/ir.cpp
index c5eb94d..f7e03cb 100644 (file)
--- a/ir.cpp
+++ b/ir.cpp
@@ -227,6 +227,19 @@ ir_constant::ir_constant(bool b)
    this->value.b[0] = b;
 }
 
+ir_constant::ir_constant(const ir_constant *c, unsigned i)
+{
+   this->type = c->type->get_base_type();
+
+   switch (this->type->base_type) {
+   case GLSL_TYPE_UINT:  this->value.u[0] = c->value.u[i]; break;
+   case GLSL_TYPE_INT:   this->value.i[0] = c->value.i[i]; break;
+   case GLSL_TYPE_FLOAT: this->value.f[0] = c->value.f[i]; break;
+   case GLSL_TYPE_BOOL:  this->value.b[0] = c->value.b[i]; break;
+   default:              assert(!"Should not get here."); break;
+   }
+}
+
 
 ir_dereference_variable::ir_dereference_variable(ir_variable *var)
 {
diff --git a/ir.h b/ir.h
index ea4f549..102f2f3 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -1026,6 +1026,18 @@ public:
    ir_constant(int i);
    ir_constant(float f);
 
+   /**
+    * Construct an ir_constant from a scalar component of another ir_constant
+    *
+    * The new \c ir_constant inherits the type of the component from the
+    * source constant.
+    *
+    * \note
+    * In the case of a matrix constant, the new constant is a scalar, \b not
+    * a vector.
+    */
+   ir_constant(const ir_constant *c, unsigned i);
+
    virtual ir_constant *as_constant()
    {
       return this;