Mesa (master): glsl: Add a new glsl_type::sampler_coordinate_components() function.

Kenneth Graunke kwg at kemper.freedesktop.org
Thu Sep 12 07:03:43 UTC 2013


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

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Sep 11 11:14:14 2013 -0700

glsl: Add a new glsl_type::sampler_coordinate_components() function.

This computes the number of components necessary to address a sampler
based on its dimensionality.  It will be useful for texturing built-ins.

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

---

 src/glsl/glsl_types.cpp |   35 +++++++++++++++++++++++++++++++++++
 src/glsl/glsl_types.h   |   12 ++++++++++++
 2 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index 0c7e8eb..3c396dd 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -883,3 +883,38 @@ glsl_type::count_attribute_slots() const
 
    return 0;
 }
+
+int
+glsl_type::sampler_coordinate_components() const
+{
+   assert(is_sampler());
+
+   int size;
+
+   switch (sampler_dimensionality) {
+   case GLSL_SAMPLER_DIM_1D:
+   case GLSL_SAMPLER_DIM_BUF:
+      size = 1;
+      break;
+   case GLSL_SAMPLER_DIM_2D:
+   case GLSL_SAMPLER_DIM_RECT:
+   case GLSL_SAMPLER_DIM_MS:
+   case GLSL_SAMPLER_DIM_EXTERNAL:
+      size = 2;
+      break;
+   case GLSL_SAMPLER_DIM_3D:
+   case GLSL_SAMPLER_DIM_CUBE:
+      size = 3;
+      break;
+   default:
+      assert(!"Should not get here.");
+      size = 1;
+      break;
+   }
+
+   /* Array textures need an additional component for the array index. */
+   if (sampler_array)
+      size += 1;
+
+   return size;
+}
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
index 647867a..9f61eee 100644
--- a/src/glsl/glsl_types.h
+++ b/src/glsl/glsl_types.h
@@ -498,6 +498,18 @@ struct glsl_type {
       return is_array() ? length : -1;
    }
 
+   /**
+    * Return the number of coordinate components needed for this sampler type.
+    *
+    * This is based purely on the sampler's dimensionality.  For example, this
+    * returns 1 for sampler1D, and 3 for sampler2DArray.
+    *
+    * Note that this is often different than actual coordinate type used in
+    * a texturing built-in function, since those pack additional values (such
+    * as the shadow comparitor or projector) into the coordinate type.
+    */
+   int sampler_coordinate_components() const;
+
 private:
    /**
     * ralloc context for all glsl_type allocations




More information about the mesa-commit mailing list