diff options
-rw-r--r-- | src/mesa/shader/shader_api.c | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c index a1e73ef125c..82c2b857fff 100644 --- a/src/mesa/shader/shader_api.c +++ b/src/mesa/shader/shader_api.c @@ -369,6 +369,54 @@ copy_string(GLchar *dst, GLsizei maxLength, GLsizei *length, const GLchar *src) /** + * Return size (in floats) of the given GLSL type. + * See also _slang_sizeof_type_specifier(). + */ +static GLint +sizeof_glsl_type(GLenum type) +{ + switch (type) { + case GL_BOOL: + case GL_FLOAT: + case GL_INT: + return 1; + case GL_BOOL_VEC2: + case GL_FLOAT_VEC2: + case GL_INT_VEC2: + return 2; + case GL_BOOL_VEC3: + case GL_FLOAT_VEC3: + case GL_INT_VEC3: + return 3; + case GL_BOOL_VEC4: + case GL_FLOAT_VEC4: + case GL_INT_VEC4: + return 4; + case GL_FLOAT_MAT2: + return 8; /* 2 rows of 4, actually */ + case GL_FLOAT_MAT3: + return 12; /* 3 rows of 4, actually */ + case GL_FLOAT_MAT4: + return 16; + case GL_FLOAT_MAT2x3: + return 6; + case GL_FLOAT_MAT2x4: + return 8; + case GL_FLOAT_MAT3x2: + return 12; /* 3 rows of 4, actually */ + case GL_FLOAT_MAT3x4: + return 12; + case GL_FLOAT_MAT4x2: + return 16; /* 4 rows of 4, actually */ + case GL_FLOAT_MAT4x3: + return 12; + default: + return 0; /* error */ + } +} + + +/** * Called via ctx->Driver.AttachShader() */ void @@ -665,13 +713,17 @@ _mesa_get_active_uniform(GLcontext *ctx, GLuint program, GLuint index, if (shProg->Uniforms->Parameters[j].Type == PROGRAM_UNIFORM || shProg->Uniforms->Parameters[j].Type == PROGRAM_SAMPLER) { if (ind == index) { + GLuint uSize = shProg->Uniforms->Parameters[j].Size; + GLenum uType = shProg->Uniforms->Parameters[j].DataType; /* found it */ copy_string(nameOut, maxLength, length, shProg->Uniforms->Parameters[j].Name); - if (size) - *size = shProg->Uniforms->Parameters[j].Size; + if (size) { + /* convert from floats to 'type' (eg: sizeof(mat4x4)=1) */ + *size = uSize / sizeof_glsl_type(uType); + } if (type) - *type = shProg->Uniforms->Parameters[j].DataType; + *type = uType; return; } ind++; |