_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) {
caller, location);
}
- return false;
+ return NULL;
}
/* From page 12 (page 26 of the PDF) of the OpenGL 2.1 spec:
*/
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:
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.
*/
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;
}
/**
{
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();
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) {
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)");