glsl: Add glsl_type::sampler_index
authorIan Romanick <ian.d.romanick@intel.com>
Mon, 14 Nov 2011 22:02:09 +0000 (14:02 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 11 Jan 2012 20:51:24 +0000 (12:51 -0800)
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/glsl/glsl_types.cpp
src/glsl/glsl_types.h

index 8587da0a3a2c60025ff7719e18ed5e1c196f60ff..d4385a644ca1f875c99033e0dd010fdbc9b8ead8 100644 (file)
@@ -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)
 {
index 4ac90118b86c7efec6524300d10d447e52d9167e..2997c9311499c7b9daa8d208436ae721dfc79efa 100644 (file)
@@ -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" {
@@ -353,6 +354,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
     */