aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/shader/shader_api.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2008-08-06 13:07:09 -0600
committerKeith Whitwell <[email protected]>2008-09-23 17:34:59 -0700
commit5b98236e75b15b77c04545f3e06d4522fe7ad608 (patch)
tree6fe7f5d38a454bb6ca37c72a413981d45a55e4e5 /src/mesa/shader/shader_api.c
parenteda291e316601d2ebf9834c290686854ea857aec (diff)
mesa: glsl: fix glGetUniform for matrix queries
(cherry picked from commit 7a6eba54d064cadf15f93df2c1748cf5e474ef03)
Diffstat (limited to 'src/mesa/shader/shader_api.c')
-rw-r--r--src/mesa/shader/shader_api.c129
1 files changed, 79 insertions, 50 deletions
diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
index c05d052f43e..3c530d17271 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -1073,6 +1073,71 @@ _mesa_get_shader_source(GLcontext *ctx, GLuint shader, GLsizei maxLength,
}
+static void
+get_matrix_dims(GLenum type, GLint *rows, GLint *cols)
+{
+ switch (type) {
+ case GL_FLOAT_MAT2:
+ *rows = *cols = 2;
+ break;
+ case GL_FLOAT_MAT2x3:
+ *rows = 3;
+ *cols = 2;
+ break;
+ case GL_FLOAT_MAT2x4:
+ *rows = 4;
+ *cols = 2;
+ break;
+ case GL_FLOAT_MAT3:
+ *rows = 3;
+ *cols = 3;
+ break;
+ case GL_FLOAT_MAT3x2:
+ *rows = 2;
+ *cols = 3;
+ break;
+ case GL_FLOAT_MAT3x4:
+ *rows = 4;
+ *cols = 3;
+ break;
+ case GL_FLOAT_MAT4:
+ *rows = 4;
+ *cols = 4;
+ break;
+ case GL_FLOAT_MAT4x2:
+ *rows = 2;
+ *cols = 4;
+ break;
+ case GL_FLOAT_MAT4x3:
+ *rows = 3;
+ *cols = 4;
+ break;
+ default:
+ *rows = *cols = 0;
+ }
+}
+
+
+/**
+ * Determine the number of rows and columns occupied by a uniform
+ * according to its datatype.
+ */
+static void
+get_uniform_rows_cols(const struct gl_program_parameter *p,
+ GLint *rows, GLint *cols)
+{
+ get_matrix_dims(p->DataType, rows, cols);
+ if (*rows == 0 && *cols == 0) {
+ /* not a matrix type, probably a float or vector */
+ *rows = p->Size / 4 + 1;
+ if (p->Size % 4 == 0)
+ *cols = 4;
+ else
+ *cols = p->Size % 4;
+ }
+}
+
+
#define MAX_UNIFORM_ELEMENTS 16
/**
@@ -1089,7 +1154,6 @@ get_uniformfv(GLcontext *ctx, GLuint program, GLint location,
if (shProg->Uniforms &&
location >= 0 && location < (GLint) shProg->Uniforms->NumUniforms) {
GLint progPos;
- GLuint i;
const struct gl_program *prog = NULL;
progPos = shProg->Uniforms->Uniforms[location].VertPos;
@@ -1105,13 +1169,23 @@ get_uniformfv(GLcontext *ctx, GLuint program, GLint location,
ASSERT(prog);
if (prog) {
+ const struct gl_program_parameter *p =
+ &prog->Parameters->Parameters[progPos];
+ GLint rows, cols, i, j, k;
+
/* See uniformiv() below */
- assert(prog->Parameters->Parameters[progPos].Size <= MAX_UNIFORM_ELEMENTS);
+ assert(p->Size <= MAX_UNIFORM_ELEMENTS);
+
+ get_uniform_rows_cols(p, &rows, &cols);
- for (i = 0; i < prog->Parameters->Parameters[progPos].Size; i++) {
- params[i] = prog->Parameters->ParameterValues[progPos][i];
+ k = 0;
+ for (i = 0; i < rows; i++) {
+ for (j = 0; j < cols; j++ ) {
+ params[k++] = prog->Parameters->ParameterValues[progPos+i][j];
+ }
}
- return prog->Parameters->Parameters[progPos].Size;
+
+ return p->Size;
}
}
else {
@@ -1595,51 +1669,6 @@ _mesa_uniform(GLcontext *ctx, GLint location, GLsizei count,
* Set a matrix-valued program parameter.
*/
static void
-get_matrix_dims(GLenum type, GLint *rows, GLint *cols)
-{
- switch (type) {
- case GL_FLOAT_MAT2:
- *rows = *cols = 2;
- break;
- case GL_FLOAT_MAT2x3:
- *rows = 3;
- *cols = 2;
- break;
- case GL_FLOAT_MAT2x4:
- *rows = 4;
- *cols = 2;
- break;
- case GL_FLOAT_MAT3:
- *rows = 3;
- *cols = 3;
- break;
- case GL_FLOAT_MAT3x2:
- *rows = 2;
- *cols = 3;
- break;
- case GL_FLOAT_MAT3x4:
- *rows = 4;
- *cols = 3;
- break;
- case GL_FLOAT_MAT4:
- *rows = 4;
- *cols = 4;
- break;
- case GL_FLOAT_MAT4x2:
- *rows = 2;
- *cols = 4;
- break;
- case GL_FLOAT_MAT4x3:
- *rows = 3;
- *cols = 4;
- break;
- default:
- *rows = *cols = 0;
- }
-}
-
-
-static void
set_program_uniform_matrix(GLcontext *ctx, struct gl_program *program,
GLuint index, GLuint offset,
GLuint count, GLuint rows, GLuint cols,