Mesa (master): glsl: Add glsl_type::sampler_index

Ian Romanick idr at kemper.freedesktop.org
Wed Jan 11 20:52:25 UTC 2012


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Mon Nov 14 14:02:09 2011 -0800

glsl: Add glsl_type::sampler_index

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

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

diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index 8587da0..d4385a6 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -127,6 +127,35 @@ glsl_type::contains_sampler() const
    }
 }
 
+gl_texture_index
+glsl_type::sampler_index() const
+{
+   const glsl_type *const t = (this->is_array()) ? this->fields.array : this;
+
+   assert(t->is_sampler());
+
+   switch (t->sampler_dimensionality) {
+   case GLSL_SAMPLER_DIM_1D:
+      return (t->sampler_array) ? TEXTURE_1D_ARRAY_INDEX : TEXTURE_1D_INDEX;
+   case GLSL_SAMPLER_DIM_2D:
+      return (t->sampler_array) ? TEXTURE_2D_ARRAY_INDEX : TEXTURE_2D_INDEX;
+   case GLSL_SAMPLER_DIM_3D:
+      return TEXTURE_3D_INDEX;
+   case GLSL_SAMPLER_DIM_CUBE:
+      return TEXTURE_CUBE_INDEX;
+   case GLSL_SAMPLER_DIM_RECT:
+      return TEXTURE_RECT_INDEX;
+   case GLSL_SAMPLER_DIM_BUF:
+      assert(!"FINISHME: Implement ARB_texture_buffer_object");
+      break;
+   case GLSL_SAMPLER_DIM_EXTERNAL:
+      return TEXTURE_EXTERNAL_INDEX;
+   default:
+      assert(!"Should not get here.");
+      break;
+   }
+}
+
 void
 glsl_type::generate_100ES_types(glsl_symbol_table *symtab)
 {
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
index 4ac9011..2997c93 100644
--- a/src/glsl/glsl_types.h
+++ b/src/glsl/glsl_types.h
@@ -28,6 +28,7 @@
 
 #include <string.h>
 #include <assert.h>
+#include "main/mtypes.h" /* for gl_texture_index, C++'s enum rules are broken */
 
 #ifdef __cplusplus
 extern "C" {
@@ -354,6 +355,11 @@ struct glsl_type {
    bool contains_sampler() const;
 
    /**
+    * Get the Mesa texture target index for a sampler type.
+    */
+   gl_texture_index sampler_index() const;
+
+   /**
     * Query whether or not a type is an array
     */
    bool is_array() const




More information about the mesa-commit mailing list