summaryrefslogtreecommitdiff
path: root/src/mesa/shader
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2008-07-08 16:12:01 -0600
committerBrian Paul <brian.paul@tungstengraphics.com>2008-07-08 16:12:01 -0600
commit072c47483674021425922132cf6d977090077f8e (patch)
treee3925c28127e2e862407239de343e526fa507c52 /src/mesa/shader
parent3bdf50bab0951c5435bbf4b938d37cc1fe9a5d7c (diff)
mesa: implement glGetUniformiv() with new ctx->Driver function
The old implementation could overwrite the caller's param buffer.
Diffstat (limited to 'src/mesa/shader')
-rw-r--r--src/mesa/shader/shader_api.c45
1 files changed, 41 insertions, 4 deletions
diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
index 182de37b50..c1fbcde61e 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -955,12 +955,15 @@ _mesa_get_shader_source(GLcontext *ctx, GLuint shader, GLsizei maxLength,
}
+#define MAX_UNIFORM_ELEMENTS 16
+
/**
- * Called via ctx->Driver.GetUniformfv().
+ * Helper for GetUniformfv(), GetUniformiv()
+ * Returns number of elements written to 'params' output.
*/
-static void
-_mesa_get_uniformfv(GLcontext *ctx, GLuint program, GLint location,
- GLfloat *params)
+static GLuint
+get_uniformfv(GLcontext *ctx, GLuint program, GLint location,
+ GLfloat *params)
{
struct gl_shader_program *shProg
= _mesa_lookup_shader_program(ctx, program);
@@ -984,9 +987,13 @@ _mesa_get_uniformfv(GLcontext *ctx, GLuint program, GLint location,
ASSERT(prog);
if (prog) {
+ /* See uniformiv() below */
+ assert(prog->Parameters->Parameters[progPos].Size <= MAX_UNIFORM_ELEMENTS);
+
for (i = 0; i < prog->Parameters->Parameters[progPos].Size; i++) {
params[i] = prog->Parameters->ParameterValues[progPos][i];
}
+ return prog->Parameters->Parameters[progPos].Size;
}
}
else {
@@ -996,6 +1003,35 @@ _mesa_get_uniformfv(GLcontext *ctx, GLuint program, GLint location,
else {
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetUniformfv(program)");
}
+ return 0;
+}
+
+
+/**
+ * Called via ctx->Driver.GetUniformfv().
+ */
+static void
+_mesa_get_uniformfv(GLcontext *ctx, GLuint program, GLint location,
+ GLfloat *params)
+{
+ (void) get_uniformfv(ctx, program, location, params);
+}
+
+
+/**
+ * Called via ctx->Driver.GetUniformiv().
+ */
+static void
+_mesa_get_uniformiv(GLcontext *ctx, GLuint program, GLint location,
+ GLint *params)
+{
+ GLfloat fparams[MAX_UNIFORM_ELEMENTS];
+ GLuint n = get_uniformfv(ctx, program, location, fparams);
+ GLuint i;
+ assert(n <= MAX_UNIFORM_ELEMENTS);
+ for (i = 0; i < n; i++) {
+ params[i] = (GLint) fparams[i];
+ }
}
@@ -1413,6 +1449,7 @@ _mesa_init_glsl_driver_functions(struct dd_function_table *driver)
driver->GetShaderInfoLog = _mesa_get_shader_info_log;
driver->GetShaderSource = _mesa_get_shader_source;
driver->GetUniformfv = _mesa_get_uniformfv;
+ driver->GetUniformiv = _mesa_get_uniformiv;
driver->GetUniformLocation = _mesa_get_uniform_location;
driver->IsProgram = _mesa_is_program;
driver->IsShader = _mesa_is_shader;