[Mesa-dev] [PATCH 08/15] mesa: Add gl_shader_program::AttributeBindings

Ian Romanick idr at freedesktop.org
Thu Sep 29 10:51:58 PDT 2011


From: Ian Romanick <ian.d.romanick at intel.com>

This currently mirrors the state tracking
gl_shader_program::Attributes, but I'm working towards eliminating
that.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/mesa/main/mtypes.h         |   11 ++++++++++-
 src/mesa/main/shader_query.cpp |    7 +++++++
 src/mesa/main/shaderobj.c      |   11 +++++++++++
 3 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 70f33ff..ac22f20 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2146,8 +2146,17 @@ struct gl_shader_program
    GLuint NumShaders;          /**< number of attached shaders */
    struct gl_shader **Shaders; /**< List of attached the shaders */
 
-   /** User-defined attribute bindings (glBindAttribLocation) */
+   /**
+    * User-defined attribute bindings
+    *
+    * These are set via \c glBindAttribLocation and are used to direct the
+    * GLSL linker.  These are \b not the values used in the compiled shader,
+    * and they are \b not the values returned by \c glGetAttribLocation.
+    *
+    * \sa gl_program::Attributes
+    */
    struct gl_program_parameter_list *Attributes;
+   struct hash_table *AttributeBindings;
 
    /** Transform feedback varyings */
    struct {
diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index 5ea6132..1b7d3df 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -32,6 +32,7 @@
 #include "glsl_symbol_table.h"
 #include "ir.h"
 #include "shaderobj.h"
+#include "program/hash_table.h"
 
 extern "C" {
 #include "shaderapi.h"
@@ -68,6 +69,12 @@ _mesa_BindAttribLocationARB(GLhandleARB program, GLuint index,
    }
 
    /* this will replace the current value if it's already in the list */
+   /* We add VERT_ATTRIB_GENERIC0 here so that we can tell the difference of a
+    * binding to 0 and an entry not being in the table (which returns NULL).
+    */
+   hash_table_replace(shProg->AttributeBindings,
+		      (void *)(intptr_t)(index + VERT_ATTRIB_GENERIC0),
+		      name);
    i = _mesa_add_attribute(shProg->Attributes, name, size, datatype, index);
    if (i < 0) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindAttribLocation");
diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c
index f128648..ebcdc2d 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -38,6 +38,7 @@
 #include "program/program.h"
 #include "program/prog_parameter.h"
 #include "program/prog_uniform.h"
+#include "program/hash_table.h"
 #include "ralloc.h"
 
 /**********************************************************************/
@@ -239,6 +240,11 @@ _mesa_init_shader_program(struct gl_context *ctx, struct gl_shader_program *prog
    prog->Type = GL_SHADER_PROGRAM_MESA;
    prog->RefCount = 1;
    prog->Attributes = _mesa_new_parameter_list();
+
+   prog->AttributeBindings = hash_table_ctor(0,
+					     hash_table_string_hash,
+					     hash_table_string_compare);
+
 #if FEATURE_ARB_geometry_shader4
    prog->Geom.VerticesOut = 0;
    prog->Geom.InputType = GL_TRIANGLES;
@@ -312,6 +318,11 @@ _mesa_free_shader_program_data(struct gl_context *ctx,
       shProg->Attributes = NULL;
    }
 
+   if (shProg->AttributeBindings) {
+      hash_table_dtor(shProg->AttributeBindings);
+      shProg->AttributeBindings = NULL;
+   }
+
    /* detach shaders */
    for (i = 0; i < shProg->NumShaders; i++) {
       _mesa_reference_shader(ctx, &shProg->Shaders[i], NULL);
-- 
1.7.6



More information about the mesa-dev mailing list