[Mesa-dev] [PATCH 1/5] mesa: Have validate_uniform_parameters return the gl_uniform_storage pointer

Ian Romanick idr at freedesktop.org
Fri Aug 1 19:09:15 PDT 2014


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

This simplifies all the callers, and it enables the removal of one of
the function parameters.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/mesa/main/uniform_query.cpp | 61 ++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 31 deletions(-)

diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index 609d94b..7b089fa 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -171,18 +171,17 @@ _mesa_GetActiveUniformsiv(GLuint program,
    _mesa_error(ctx, GL_INVALID_ENUM, "glGetActiveUniformsiv(pname)");
 }
 
-static bool
+static struct gl_uniform_storage *
 validate_uniform_parameters(struct gl_context *ctx,
 			    struct gl_shader_program *shProg,
 			    GLint location, GLsizei count,
-			    unsigned *loc,
 			    unsigned *array_index,
 			    const char *caller,
 			    bool negative_one_is_not_valid)
 {
    if (!shProg || !shProg->LinkStatus) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(program not linked)", caller);
-      return false;
+      return NULL;
    }
 
    if (location == -1) {
@@ -214,7 +213,7 @@ validate_uniform_parameters(struct gl_context *ctx,
 		     caller, location);
       }
 
-      return false;
+      return NULL;
    }
 
    /* From page 12 (page 26 of the PDF) of the OpenGL 2.1 spec:
@@ -224,7 +223,7 @@ validate_uniform_parameters(struct gl_context *ctx,
     */
    if (count < 0) {
       _mesa_error(ctx, GL_INVALID_VALUE, "%s(count < 0)", caller);
-      return false;
+      return NULL;
    }
 
    /* Page 82 (page 96 of the PDF) of the OpenGL 2.1 spec says:
@@ -243,14 +242,14 @@ validate_uniform_parameters(struct gl_context *ctx,
    if (location < -1) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(location=%d)",
                   caller, location);
-      return false;
+      return NULL;
    }
 
    /* Check that the given location is in bounds of uniform remap table. */
    if (location >= (GLint) shProg->NumUniformRemapTable) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(location=%d)",
 		  caller, location);
-      return false;
+      return NULL;
    }
 
    /* If the driver storage pointer in remap table is -1, we ignore silently.
@@ -266,30 +265,32 @@ validate_uniform_parameters(struct gl_context *ctx,
     */
    if (shProg->UniformRemapTable[location] ==
        INACTIVE_UNIFORM_EXPLICIT_LOCATION)
-      return false;
+      return NULL;
 
-   _mesa_uniform_split_location_offset(shProg, location, loc, array_index);
+   unsigned loc;
+   _mesa_uniform_split_location_offset(shProg, location, &loc, array_index);
+   struct gl_uniform_storage *const uni = &shProg->UniformStorage[loc];
 
-   if (shProg->UniformStorage[*loc].array_elements == 0 && count > 1) {
+   if (uni->array_elements == 0 && count > 1) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
 		  "%s(count > 1 for non-array, location=%d)",
 		  caller, location);
-      return false;
+      return NULL;
    }
 
    /* If the uniform is an array, check that array_index is in bounds.
     * If not an array, check that array_index is zero.
     * array_index is unsigned so no need to check for less than zero.
     */
-   unsigned limit = shProg->UniformStorage[*loc].array_elements;
+   unsigned limit = uni->array_elements;
    if (limit == 0)
       limit = 1;
    if (*array_index >= limit) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(location=%d)",
 		  caller, location);
-      return false;
+      return NULL;
    }
-   return true;
+   return uni;
 }
 
 /**
@@ -302,15 +303,14 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
 {
    struct gl_shader_program *shProg =
       _mesa_lookup_shader_program_err(ctx, program, "glGetUniformfv");
-   struct gl_uniform_storage *uni;
-   unsigned loc, offset;
+   unsigned offset;
 
-   if (!validate_uniform_parameters(ctx, shProg, location, 1,
-				    &loc, &offset, "glGetUniform", true))
+   struct gl_uniform_storage *const uni =
+      validate_uniform_parameters(ctx, shProg, location, 1,
+                                  &offset, "glGetUniform", true);
+   if (uni == NULL)
       return;
 
-   uni = &shProg->UniformStorage[loc];
-
    {
       unsigned elements = (uni->type->is_sampler())
 	 ? 1 : uni->type->components();
@@ -607,18 +607,17 @@ _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
 	      GLint location, GLsizei count,
               const GLvoid *values, GLenum type)
 {
-   unsigned loc, offset;
+   unsigned offset;
    unsigned components;
    unsigned src_components;
    enum glsl_base_type basicType;
-   struct gl_uniform_storage *uni;
 
-   if (!validate_uniform_parameters(ctx, shProg, location, count,
-				    &loc, &offset, "glUniform", false))
+   struct gl_uniform_storage *const uni =
+      validate_uniform_parameters(ctx, shProg, location, count,
+                                  &offset, "glUniform", false);
+   if (uni == NULL)
       return;
 
-   uni = &shProg->UniformStorage[loc];
-
    /* Verify that the types are compatible.
     */
    switch (type) {
@@ -894,17 +893,17 @@ _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
                      GLint location, GLsizei count,
                      GLboolean transpose, const GLfloat *values)
 {
-   unsigned loc, offset;
+   unsigned offset;
    unsigned vectors;
    unsigned components;
    unsigned elements;
-   struct gl_uniform_storage *uni;
 
-   if (!validate_uniform_parameters(ctx, shProg, location, count,
-				    &loc, &offset, "glUniformMatrix", false))
+   struct gl_uniform_storage *const uni =
+      validate_uniform_parameters(ctx, shProg, location, count,
+                                  &offset, "glUniformMatrix", false);
+   if (uni == NULL)
       return;
 
-   uni = &shProg->UniformStorage[loc];
    if (!uni->type->is_matrix()) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
 		  "glUniformMatrix(non-matrix uniform)");
-- 
1.8.1.4



More information about the mesa-dev mailing list