Add glsl_type::components to query total number of components in a type

This commit is contained in:
Ian Romanick
2010-03-26 11:13:43 -07:00
parent cef3baecf6
commit d811d47609
3 changed files with 13 additions and 10 deletions

View File

@@ -157,6 +157,16 @@ struct glsl_type {
static const glsl_type *get_instance(unsigned base_type, unsigned rows,
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).
*/

5
ir.cpp
View File

@@ -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());
}

View File

@@ -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(", ");