mesa: Add support for getting active uniform block names.
authorEric Anholt <eric@anholt.net>
Tue, 19 Jun 2012 22:24:30 +0000 (15:24 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 31 Jul 2012 19:06:19 +0000 (12:06 -0700)
Fixes piglit ARB_uniform_buffer_object/getactiveuniformblockname.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/main/uniforms.c

index 940cb07c247a61865667924d72d5d0969dc38108..3236d6eb06457ee107f7b18e0d40d7fdc6b5fba0 100644 (file)
@@ -668,6 +668,10 @@ _mesa_GetActiveUniformBlockiv(GLuint program,
       params[0] = block->Binding;
       return;
 
+   case GL_UNIFORM_BLOCK_NAME_LENGTH:
+      params[0] = strlen(block->Name) + 1;
+      return;
+
    default:
       _mesa_error(ctx, GL_INVALID_ENUM,
                  "glGetActiveUniformBlockiv(pname 0x%x (%s))",
@@ -676,6 +680,48 @@ _mesa_GetActiveUniformBlockiv(GLuint program,
    }
 }
 
+static void GLAPIENTRY
+_mesa_GetActiveUniformBlockName(GLuint program,
+                               GLuint uniformBlockIndex,
+                               GLsizei bufSize,
+                               GLsizei *length,
+                               GLchar *uniformBlockName)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_shader_program *shProg;
+   struct gl_uniform_block *block;
+
+   if (!ctx->Extensions.ARB_uniform_buffer_object) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glGetActiveUniformBlockiv");
+      return;
+   }
+
+   if (bufSize < 0) {
+      _mesa_error(ctx, GL_INVALID_VALUE,
+                 "glGetActiveUniformBlockName(bufSize %d < 0)",
+                 bufSize);
+      return;
+   }
+
+   shProg = _mesa_lookup_shader_program_err(ctx, program,
+                                           "glGetActiveUniformBlockiv");
+   if (!shProg)
+      return;
+
+   if (uniformBlockIndex >= shProg->NumUniformBlocks) {
+      _mesa_error(ctx, GL_INVALID_VALUE,
+                 "glGetActiveUniformBlockiv(block index %d >= %d)",
+                 uniformBlockIndex, shProg->NumUniformBlocks);
+      return;
+   }
+
+   block = &shProg->UniformBlocks[uniformBlockIndex];
+
+   if (uniformBlockName) {
+      _mesa_copy_string(uniformBlockName, bufSize, length, block->Name);
+   }
+}
+
 /**
  * Plug in shader uniform-related functions into API dispatch table.
  */
@@ -738,6 +784,7 @@ _mesa_init_shader_uniform_dispatch(struct _glapi_table *exec)
    SET_GetUniformIndices(exec, _mesa_GetUniformIndices);
    SET_GetActiveUniformsiv(exec, _mesa_GetActiveUniformsiv);
    SET_GetActiveUniformBlockiv(exec, _mesa_GetActiveUniformBlockiv);
+   SET_GetActiveUniformBlockName(exec, _mesa_GetActiveUniformBlockName);
    SET_UniformBlockBinding(exec, _mesa_UniformBlockBinding);
 
 #endif /* FEATURE_GL */