Slightly change the representation of numeric types

For numeric types, vector_elements and matrix_columns must be at least
1.  Previously matrix_columns was 0 for vectors, and both were 0 for
scalars.  This change simplifies things in some places.
This commit is contained in:
Ian Romanick 2010-03-26 11:43:36 -07:00
parent d811d47609
commit 738c183cc9
2 changed files with 27 additions and 17 deletions

View file

@ -138,21 +138,21 @@ gen_header "core"
index=0;
bool_index=$index
gen_integral_type "bool" "GLSL_TYPE_BOOL" 0 0
gen_integral_type "bool" "GLSL_TYPE_BOOL" 1 1
for i in 2 3 4; do
gen_integral_type "bvec$i" "GLSL_TYPE_BOOL" $i 0
gen_integral_type "bvec$i" "GLSL_TYPE_BOOL" $i 1
done
int_index=$index
gen_integral_type "int" "GLSL_TYPE_INT" 0 0
gen_integral_type "int" "GLSL_TYPE_INT" 1 1
for i in 2 3 4; do
gen_integral_type "ivec$i" "GLSL_TYPE_INT" $i 0
gen_integral_type "ivec$i" "GLSL_TYPE_INT" $i 1
done
float_index=$index
gen_integral_type "float" "GLSL_TYPE_FLOAT" 0 0
gen_integral_type "float" "GLSL_TYPE_FLOAT" 1 1
for i in 2 3 4; do
gen_integral_type "vec$i" "GLSL_TYPE_FLOAT" $i 0
gen_integral_type "vec$i" "GLSL_TYPE_FLOAT" $i 1
done
matX_index=$index
@ -295,9 +295,9 @@ echo '/*@{*/'
gen_header "130"
index=0;
uint_index=$index
gen_integral_type "uint" "GLSL_TYPE_UINT" 0 0
gen_integral_type "uint" "GLSL_TYPE_UINT" 1 1
for i in 2 3 4; do
gen_integral_type "uvec$i" "GLSL_TYPE_UINT" $i 0
gen_integral_type "uvec$i" "GLSL_TYPE_UINT" $i 1
done
echo

View file

@ -27,6 +27,7 @@
#define GLSL_TYPES_H
#include <cstring>
#include <cassert>
#define GLSL_TYPE_UINT 0
#define GLSL_TYPE_INT 1
@ -60,8 +61,16 @@ struct glsl_type {
* and \c GLSL_TYPE_UINT are valid.
*/
unsigned vector_elements:3; /**< 0, 2, 3, or 4 vector elements. */
unsigned matrix_columns:3; /**< 0, 2, 3, or 4 matrix columns. */
/**
* \name Vector and matrix element counts
*
* For scalars, each of these values will be 1. For non-numeric types
* these will be 0.
*/
/*@{*/
unsigned vector_elements:3; /**< 1, 2, 3, or 4 vector elements. */
unsigned matrix_columns:3; /**< 1, 2, 3, or 4 matrix columns. */
/*@}*/
/**
* Name of the data type
@ -114,6 +123,9 @@ struct glsl_type {
name(name),
length(0)
{
/* Neither dimension is zero or both dimensions are zero.
*/
assert((vector_elements == 0) == (matrix_columns == 0));
memset(& fields, 0, sizeof(fields));
}
@ -162,9 +174,7 @@ struct glsl_type {
*/
unsigned components() const
{
return ((vector_elements == 0) ? 1 : vector_elements)
* ((matrix_columns == 0) ? 1 : matrix_columns);
return vector_elements * matrix_columns;
}
/**
@ -172,7 +182,7 @@ struct glsl_type {
*/
bool is_scalar() const
{
return (vector_elements == 0)
return (vector_elements == 1)
&& (base_type >= GLSL_TYPE_UINT)
&& (base_type <= GLSL_TYPE_BOOL);
}
@ -182,8 +192,8 @@ struct glsl_type {
*/
bool is_vector() const
{
return (vector_elements > 0)
&& (matrix_columns == 0)
return (vector_elements > 1)
&& (matrix_columns == 1)
&& (base_type >= GLSL_TYPE_UINT)
&& (base_type <= GLSL_TYPE_BOOL);
}
@ -194,7 +204,7 @@ struct glsl_type {
bool is_matrix() const
{
/* GLSL only has float matrices. */
return (matrix_columns > 0) && (base_type == GLSL_TYPE_FLOAT);
return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT);
}
/**