summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2010-03-26 11:13:43 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-03-26 14:43:11 -0700
commitd811d47609323f99f3718a2c5fb75ce47032f380 (patch)
treeef3e1d993cc3022f4ed57080b0d74f1986a7ec53
parentcef3baecf636a30b62cd7a1e8de57c7650f7003e (diff)
Add glsl_type::components to query total number of components in a type
-rw-r--r--glsl_types.h10
-rw-r--r--ir.cpp5
-rw-r--r--ir_print_visitor.cpp8
3 files changed, 13 insertions, 10 deletions
diff --git a/glsl_types.h b/glsl_types.h
index beaaa78f55..720b05bcda 100644
--- a/glsl_types.h
+++ b/glsl_types.h
@@ -158,6 +158,16 @@ struct glsl_type {
unsigned columns);
/**
+ * Query the total number of scalars that make up a scalar, vector or matrix
+ */
+ unsigned components() const
+ {
+ return ((vector_elements == 0) ? 1 : vector_elements)
+ * ((matrix_columns == 0) ? 1 : matrix_columns);
+
+ }
+
+ /**
* Query whether or not a type is a scalar (non-vector and non-matrix).
*/
bool is_scalar() const
diff --git a/ir.cpp b/ir.cpp
index c4c7584bcf..06eb19691e 100644
--- a/ir.cpp
+++ b/ir.cpp
@@ -57,9 +57,6 @@ ir_label::ir_label(const char *label)
ir_constant::ir_constant(const struct glsl_type *type, const void *data)
: ir_rvalue()
{
- const unsigned elements =
- ((type->vector_elements == 0) ? 1 : type->vector_elements)
- * ((type->matrix_columns == 0) ? 1 : type->matrix_columns);
unsigned size = 0;
this->type = type;
@@ -74,7 +71,7 @@ ir_constant::ir_constant(const struct glsl_type *type, const void *data)
break;
}
- memcpy(& this->value, data, size * elements);
+ memcpy(& this->value, data, size * type->components());
}
diff --git a/ir_print_visitor.cpp b/ir_print_visitor.cpp
index 1696be69b5..682a553249 100644
--- a/ir_print_visitor.cpp
+++ b/ir_print_visitor.cpp
@@ -177,12 +177,8 @@ void ir_print_visitor::visit(ir_constant *ir)
print_type(base_type);
printf(") ");
- const unsigned num_values = 1
- * ((ir->type->vector_elements > 0) ? ir->type->vector_elements : 1)
- * ((ir->type->matrix_columns > 0) ? ir->type->matrix_columns : 1);
-
- printf("(%d) (", num_values);
- for (unsigned i = 0; i < num_values; i++) {
+ printf("(%d) (", ir->type->components());
+ for (unsigned i = 0; i < ir->type->components(); i++) {
if (i != 0)
printf(", ");