diff options
author | Ian Romanick <[email protected]> | 2014-08-01 18:37:58 -0700 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2014-08-07 16:17:45 -0700 |
commit | 411abcb23751ff57de9843e992647a8e41daab75 (patch) | |
tree | b7ccee0986f713c145f6986e2aad4b5d4b420271 /src/mesa/main | |
parent | f28a105868d2c1913746de3875dda000c14069fb (diff) |
mesa: Have validate_uniform_parameters return the gl_uniform_storage pointer
This simplifies all the callers, and it enables the removal of one of
the function parameters.
Signed-off-by: Ian Romanick <[email protected]>
Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r-- | src/mesa/main/uniform_query.cpp | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp index 609d94bd745..7b089fa9595 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)"); |