Mesa (master): mesa: Add glsl_type::get_scalar_type() function.

Paul Berry stereotype441 at kemper.freedesktop.org
Mon Oct 31 18:32:43 UTC 2011


Module: Mesa
Branch: master
Commit: fa0066ae2b2d304065ee8d93d9b5ecc8b457425a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fa0066ae2b2d304065ee8d93d9b5ecc8b457425a

Author: Paul Berry <stereotype441 at gmail.com>
Date:   Tue Oct 25 16:24:03 2011 -0700

mesa: Add glsl_type::get_scalar_type() function.

This function is similar to get_base_type(), but when called on
arrays, it returns the scalar type composing the array.  For example,
glsl_type(vec4[]) => float_type.

Acked-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/glsl/glsl_types.cpp |   23 +++++++++++++++++++++++
 src/glsl/glsl_types.h   |   11 +++++++++++
 2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index c94aec0..03e9987 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -258,6 +258,29 @@ const glsl_type *glsl_type::get_base_type() const
 }
 
 
+const glsl_type *glsl_type::get_scalar_type() const
+{
+   const glsl_type *type = this;
+
+   /* Handle arrays */
+   while (type->base_type == GLSL_TYPE_ARRAY)
+      type = type->fields.array;
+
+   /* Handle vectors and matrices */
+   switch (type->base_type) {
+   case GLSL_TYPE_UINT:
+      return uint_type;
+   case GLSL_TYPE_INT:
+      return int_type;
+   case GLSL_TYPE_FLOAT:
+      return float_type;
+   default:
+      /* Handle everything else */
+      return type;
+   }
+}
+
+
 void
 _mesa_glsl_release_types(void)
 {
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
index 0486966..2f849af 100644
--- a/src/glsl/glsl_types.h
+++ b/src/glsl/glsl_types.h
@@ -178,6 +178,17 @@ struct glsl_type {
    const glsl_type *get_base_type() const;
 
    /**
+    * Get the basic scalar type which this type aggregates.
+    *
+    * If the type is a numeric or boolean scalar, vector, or matrix, or an
+    * array of any of those, this function gets the scalar type of the
+    * individual components.  For structs and arrays of structs, this function
+    * returns the struct type.  For samplers and arrays of samplers, this
+    * function returns the sampler type.
+    */
+   const glsl_type *get_scalar_type() const;
+
+   /**
     * Query the type of elements in an array
     *
     * \return




More information about the mesa-commit mailing list