summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuiltin_types.sh16
-rw-r--r--glsl_types.h28
2 files changed, 27 insertions, 17 deletions
diff --git a/builtin_types.sh b/builtin_types.sh
index 6658ada41a..609073c9e4 100755
--- a/builtin_types.sh
+++ b/builtin_types.sh
@@ -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
diff --git a/glsl_types.h b/glsl_types.h
index 720b05bcda..68a32efde6 100644
--- a/glsl_types.h
+++ b/glsl_types.h
@@ -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);
}
/**