return correct size from glGetActiveUniform (bug 13751)

This commit is contained in:
Brian 2007-12-20 09:05:37 -07:00
parent f9e70d951a
commit a1b3a908f5

View file

@ -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()
*/
@ -666,13 +714,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++;