[Mesa-dev] [PATCH 09/18] mesa: Move the _mesa_uniform_merge_location_offset to glGetUniformLocation().

Eric Anholt eric at anholt.net
Mon Jul 2 17:38:18 PDT 2012


With the upcoming GL_ARB_uniform_buffer_object changes, the only
other caller that will want the cooked value is state_tracker.
---
 src/mesa/main/uniform_query.cpp            |   25 +++++++++++++++----------
 src/mesa/main/uniforms.c                   |    7 ++++++-
 src/mesa/main/uniforms.h                   |    4 ++--
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp |    8 +++++---
 4 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index f5d998f..25d887d 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -852,13 +852,17 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
 /**
  * Called via glGetUniformLocation().
  *
- * The return value will encode two values, the uniform location and an
- * offset (used for arrays, structs).
+ * Returns the uniform index into UniformStorage (also the
+ * glGetActiveUniformsiv uniform index), and stores the referenced
+ * array offset in *offset, or GL_INVALID_INDEX (-1).  Those two
+ * return values can be encoded into a uniform location for
+ * glUniform* using _mesa_uniform_merge_location_offset(index, offset).
  */
-extern "C" GLint
+extern "C" unsigned
 _mesa_get_uniform_location(struct gl_context *ctx,
                            struct gl_shader_program *shProg,
-			   const GLchar *name)
+                           const GLchar *name,
+                           unsigned *out_offset)
 {
    const size_t len = strlen(name);
    long offset;
@@ -901,13 +905,13 @@ _mesa_get_uniform_location(struct gl_context *ctx,
        * (or other non-digit characters) before the opening '['.
        */
       if ((i == 0) || name[i-1] != '[')
-	 return -1;
+	 return GL_INVALID_INDEX;
 
       /* Return an error if there are no digits between the opening '[' to
        * match the closing ']'.
        */
       if (i == (len - 1))
-	 return -1;
+	 return GL_INVALID_INDEX;
 
       /* Make a new string that is a copy of the old string up to (but not
        * including) the '[' character.
@@ -919,7 +923,7 @@ _mesa_get_uniform_location(struct gl_context *ctx,
       offset = strtol(&name[i], NULL, 10);
       if (offset < 0) {
 	 free(name_copy);
-	 return -1;
+	 return GL_INVALID_INDEX;
       }
 
       array_lookup = true;
@@ -941,16 +945,17 @@ _mesa_get_uniform_location(struct gl_context *ctx,
       free(name_copy);
 
    if (!found)
-      return -1;
+      return GL_INVALID_INDEX;
 
    /* Since array_elements is 0 for non-arrays, this causes look-ups of 'a[0]'
     * to (correctly) fail if 'a' is not an array.
     */
    if (array_lookup && shProg->UniformStorage[location].array_elements == 0) {
-      return -1;
+      return GL_INVALID_INDEX;
    }
 
-   return _mesa_uniform_merge_location_offset(location, offset);
+   *out_offset = offset;
+   return location;
 }
 
 extern "C" bool
diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
index e6604b1..2a048a5 100644
--- a/src/mesa/main/uniforms.c
+++ b/src/mesa/main/uniforms.c
@@ -497,6 +497,7 @@ GLint GLAPIENTRY
 _mesa_GetUniformLocationARB(GLhandleARB programObj, const GLcharARB *name)
 {
    struct gl_shader_program *shProg;
+   GLuint index, offset;
 
    GET_CURRENT_CONTEXT(ctx);
 
@@ -516,7 +517,11 @@ _mesa_GetUniformLocationARB(GLhandleARB programObj, const GLcharARB *name)
       return -1;
    }
 
-   return _mesa_get_uniform_location(ctx, shProg, name);
+   index = _mesa_get_uniform_location(ctx, shProg, name, &offset);
+   if (index == GL_INVALID_INDEX)
+      return -1;
+
+   return _mesa_uniform_merge_location_offset(index, offset);
 }
 
 
diff --git a/src/mesa/main/uniforms.h b/src/mesa/main/uniforms.h
index 7b512a5..a94dbd6 100644
--- a/src/mesa/main/uniforms.h
+++ b/src/mesa/main/uniforms.h
@@ -176,9 +176,9 @@ _mesa_GetnUniformdvARB(GLhandleARB, GLint, GLsizei, GLdouble *);
 extern GLint GLAPIENTRY
 _mesa_GetUniformLocationARB(GLhandleARB, const GLcharARB *);
 
-GLint
+unsigned
 _mesa_get_uniform_location(struct gl_context *ctx, struct gl_shader_program *shProg,
-			   const GLchar *name);
+			   const GLchar *name, unsigned *offset);
 
 void
 _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shader_program,
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index b6abe84..b499060 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -2893,13 +2893,15 @@ set_uniform_initializer(struct gl_context *ctx, void *mem_ctx,
       return;
    }
 
-   int loc = _mesa_get_uniform_location(ctx, shader_program, name);
-
-   if (loc == -1) {
+   unsigned offset;
+   unsigned index = _mesa_get_uniform_location(ctx, shader_program, name,
+					       &offset);
+   if (offset == GL_INVALID_INDEX) {
       fail_link(shader_program,
         	"Couldn't find uniform for initializer %s\n", name);
       return;
    }
+   int loc = _mesa_uniform_merge_location_offset(index, offset);
 
    for (unsigned int i = 0; i < (type->is_array() ? type->length : 1); i++) {
       ir_constant *element;
-- 
1.7.10



More information about the mesa-dev mailing list