return correct size from glGetActiveUniform (bug 13751)
authorBrian <brian.paul@tungstengraphics.com>
Thu, 20 Dec 2007 16:05:37 +0000 (09:05 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Thu, 20 Dec 2007 16:06:05 +0000 (09:06 -0700)
src/mesa/shader/shader_api.c

index a1e73ef125c71343a9f9b62c3c560b00f5fc80c3..82c2b857fff4bb63468f61cbd372ad3db0422531 100644 (file)
@@ -368,6 +368,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()
  */
@@ -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++;