summaryrefslogtreecommitdiff
path: root/ir_constant_expression.cpp
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2010-06-11 12:30:28 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-06-11 15:43:59 -0700
commitc2ba6190921be014fecaca0a5627ecc72fa7b2a1 (patch)
tree52cad8ff5bd8c503a0c5f3d1032eac2af5a9858b /ir_constant_expression.cpp
parent9b92af9ebc018eab63623812984a77f3aa834fe0 (diff)
ir_constant_visitor: Handle constant swizzles
Diffstat (limited to 'ir_constant_expression.cpp')
-rw-r--r--ir_constant_expression.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/ir_constant_expression.cpp b/ir_constant_expression.cpp
index a7c4fe6382..781166a8a2 100644
--- a/ir_constant_expression.cpp
+++ b/ir_constant_expression.cpp
@@ -538,8 +538,33 @@ ir_constant_visitor::visit(ir_texture *ir)
void
ir_constant_visitor::visit(ir_swizzle *ir)
{
- (void) ir;
- value = NULL;
+ ir_constant *v = ir->val->constant_expression_value();
+
+ this->value = NULL;
+
+ if (v != NULL) {
+ union {
+ float f[4];
+ unsigned u[4];
+ bool b[4];
+ } data;
+
+ const unsigned swiz_idx[4] = {
+ ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w
+ };
+
+ for (unsigned i = 0; i < ir->mask.num_components; i++) {
+ switch (v->type->base_type) {
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_INT: data.u[i] = v->value.u[swiz_idx[i]]; break;
+ case GLSL_TYPE_FLOAT: data.f[i] = v->value.f[swiz_idx[i]]; break;
+ case GLSL_TYPE_BOOL: data.b[i] = v->value.b[swiz_idx[i]]; break;
+ default: assert(!"Should not get here."); break;
+ }
+ }
+
+ this->value = new ir_constant(ir->type, &data);
+ }
}