summaryrefslogtreecommitdiff
path: root/glsl_types.cpp
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2010-03-24 17:11:30 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-03-24 17:11:30 -0700
commit3209c4e3692eaa9468aadcd21ce402e6b0d5b7dd (patch)
tree90f2bd3db967138bfb6620208050b18a53cdf0e3 /glsl_types.cpp
parent60b54d977a7b3df9612eb9232f6b5d6c3f393e2f (diff)
Add glsl_type::get_instance method
Gets the singleton corresponding to a particular scalar, vector, or matrix type.
Diffstat (limited to 'glsl_types.cpp')
-rw-r--r--glsl_types.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/glsl_types.cpp b/glsl_types.cpp
index 2b06a33553..6dcbba8e8c 100644
--- a/glsl_types.cpp
+++ b/glsl_types.cpp
@@ -159,3 +159,59 @@ const glsl_type *glsl_type::get_base_type() const
return glsl_error_type;
}
}
+
+
+const glsl_type *
+glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
+{
+ if ((rows < 1) || (rows > 4) || (columns < 1) || (columns > 4))
+ return glsl_error_type;
+
+
+ /* Treat GLSL vectors as Nx1 matrices.
+ */
+ if (columns == 1) {
+ switch (base_type) {
+ case GLSL_TYPE_UINT:
+ return glsl_uint_type + (rows - 1);
+ case GLSL_TYPE_INT:
+ return glsl_int_type + (rows - 1);
+ case GLSL_TYPE_FLOAT:
+ return glsl_float_type + (rows - 1);
+ case GLSL_TYPE_BOOL:
+ return glsl_bool_type + (rows - 1);
+ default:
+ return glsl_error_type;
+ }
+ } else {
+ if ((base_type != GLSL_TYPE_FLOAT) || (rows == 1))
+ return glsl_error_type;
+
+ /* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following
+ * combinations are valid:
+ *
+ * 1 2 3 4
+ * 1
+ * 2 x x x
+ * 3 x x x
+ * 4 x x x
+ */
+#define IDX(c,r) (((c-1)*3) + (r-1))
+
+ switch (IDX(columns, rows)) {
+ case IDX(2,2): return mat2_type;
+ case IDX(2,3): return mat2x3_type;
+ case IDX(2,4): return mat2x4_type;
+ case IDX(3,2): return mat3x2_type;
+ case IDX(3,3): return mat3_type;
+ case IDX(3,4): return mat3x4_type;
+ case IDX(4,2): return mat4x2_type;
+ case IDX(4,3): return mat4x3_type;
+ case IDX(4,4): return mat4_type;
+ default: return glsl_error_type;
+ }
+ }
+
+ assert(!"Should not get here.");
+ return glsl_error_type;
+}