From 5a165d1f3ae8eddb96c2d2026ac4a8f981733ac5 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 19 Jun 2012 15:24:30 -0700 Subject: [PATCH] mesa: Add support for getting active uniform block names. Fixes piglit ARB_uniform_buffer_object/getactiveuniformblockname. Reviewed-by: Kenneth Graunke Reviewed-by: Ian Romanick --- src/mesa/main/uniforms.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c index 940cb07c247..3236d6eb064 100644 --- a/src/mesa/main/uniforms.c +++ b/src/mesa/main/uniforms.c @@ -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 */ -- 2.30.2