summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian <brian@yutani.localnet.net>2007-04-18 16:05:53 -0600
committerBrian <brian@yutani.localnet.net>2007-04-18 17:14:13 -0600
commit274ac7a801766a0ae766219ec6a40ed52e479d07 (patch)
tree2a0f770a8278e4556879ad101c3c866cf43f9b02
parentaaa57412c1a682730f27f08bd89a79b8b81f982f (diff)
Fix some bugs related to querying active uniforms.
-rw-r--r--src/mesa/shader/prog_parameter.c17
-rw-r--r--src/mesa/shader/prog_parameter.h4
-rw-r--r--src/mesa/shader/shader_api.c42
3 files changed, 53 insertions, 10 deletions
diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c
index fe90ca6d7b..e2f1047463 100644
--- a/src/mesa/shader/prog_parameter.c
+++ b/src/mesa/shader/prog_parameter.c
@@ -605,3 +605,20 @@ _mesa_longest_parameter_name(const struct gl_program_parameter_list *list,
return maxLen;
}
+
+/**
+ * Count the number of parameters in the last that match the given type.
+ */
+GLuint
+_mesa_num_parameters_of_type(const struct gl_program_parameter_list *list,
+ enum register_file type)
+{
+ GLuint i, count = 0;
+ if (list) {
+ for (i = 0; i < list->NumParameters; i++) {
+ if (list->Parameters[i].Type == type)
+ count++;
+ }
+ }
+ return count;
+}
diff --git a/src/mesa/shader/prog_parameter.h b/src/mesa/shader/prog_parameter.h
index 879623b127..2e0feb972e 100644
--- a/src/mesa/shader/prog_parameter.h
+++ b/src/mesa/shader/prog_parameter.h
@@ -134,5 +134,9 @@ extern GLuint
_mesa_longest_parameter_name(const struct gl_program_parameter_list *list,
enum register_file type);
+extern GLuint
+_mesa_num_parameters_of_type(const struct gl_program_parameter_list *list,
+ enum register_file type);
+
#endif /* PROG_PARAMETER_H */
diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
index a8ca7d6221..74bdef061b 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -38,6 +38,7 @@
#include "glheader.h"
#include "context.h"
#include "hash.h"
+#include "macros.h"
#include "program.h"
#include "prog_parameter.h"
#include "prog_print.h"
@@ -643,6 +644,7 @@ _mesa_get_active_uniform(GLcontext *ctx, GLuint program, GLuint index,
struct gl_shader_program *shProg
= _mesa_lookup_shader_program(ctx, program);
GLint sz;
+ GLuint ind, j;
if (!shProg) {
_mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveUniform");
@@ -654,13 +656,26 @@ _mesa_get_active_uniform(GLcontext *ctx, GLuint program, GLuint index,
return;
}
- copy_string(nameOut, maxLength, length,
- shProg->Uniforms->Parameters[index].Name);
- sz = shProg->Uniforms->Parameters[index].Size;
- if (size)
- *size = sz;
- if (type)
- *type = vec_types[sz]; /* XXX this is a temporary hack */
+ ind = 0;
+ for (j = 0; j < shProg->Uniforms->NumParameters; j++) {
+ if (shProg->Uniforms->Parameters[j].Type == PROGRAM_UNIFORM ||
+ shProg->Uniforms->Parameters[j].Type == PROGRAM_SAMPLER) {
+ if (ind == index) {
+ /* found it */
+ copy_string(nameOut, maxLength, length,
+ shProg->Uniforms->Parameters[j].Name);
+ sz = shProg->Uniforms->Parameters[j].Size;
+ if (size)
+ *size = sz;
+ if (type)
+ *type = vec_types[sz-1]; /* XXX this is a temporary hack */
+ return;
+ }
+ ind++;
+ }
+ }
+
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveUniform(index)");
}
@@ -774,13 +789,20 @@ _mesa_get_programiv(GLcontext *ctx, GLuint program,
*params = shProg->Attributes ? shProg->Attributes->NumParameters : 0;
break;
case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
- *params = _mesa_longest_parameter_name(shProg->Attributes, PROGRAM_INPUT);
+ *params = _mesa_longest_parameter_name(shProg->Attributes,
+ PROGRAM_INPUT) + 1;
break;
case GL_ACTIVE_UNIFORMS:
- *params = shProg->Uniforms ? shProg->Uniforms->NumParameters : 0;
+ *params
+ = _mesa_num_parameters_of_type(shProg->Uniforms, PROGRAM_UNIFORM)
+ + _mesa_num_parameters_of_type(shProg->Uniforms, PROGRAM_SAMPLER);
break;
case GL_ACTIVE_UNIFORM_MAX_LENGTH:
- *params = _mesa_longest_parameter_name(shProg->Uniforms, PROGRAM_UNIFORM);
+ *params = MAX2(
+ _mesa_longest_parameter_name(shProg->Uniforms, PROGRAM_UNIFORM),
+ _mesa_longest_parameter_name(shProg->Uniforms, PROGRAM_SAMPLER));
+ if (*params > 0)
+ (*params)++; /* add one for terminating zero */
break;
default:
_mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramiv(pname)");