From 75c6f472880706dcbb9d1e20727fa8f71db8b11c Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Mon, 11 Oct 2010 16:07:08 -0700 Subject: mesa: Track an ActiveProgram distinct from CurrentProgram ActiveProgram is the GL_EXT_separate_shader_objects state variable used for glUniform calls. glUseProgram also sets this. --- src/mesa/main/shaderapi.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'src/mesa/main/shaderapi.c') diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index 968db07..26c9a18 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -117,6 +117,7 @@ void _mesa_free_shader_state(struct gl_context *ctx) { _mesa_reference_shader_program(ctx, &ctx->Shader.CurrentProgram, NULL); + _mesa_reference_shader_program(ctx, &ctx->Shader.ActiveProgram, NULL); } @@ -607,8 +608,8 @@ static GLuint get_handle(struct gl_context *ctx, GLenum pname) { if (pname == GL_PROGRAM_OBJECT_ARB) { - if (ctx->Shader.CurrentProgram) - return ctx->Shader.CurrentProgram->Name; + if (ctx->Shader.ActiveProgram) + return ctx->Shader.ActiveProgram->Name; else return 0; } @@ -908,6 +909,24 @@ print_shader_info(const struct gl_shader_program *shProg) /** + * Use the named shader program for subsequent glUniform calls + */ +static void +active_program(struct gl_context *ctx, struct gl_shader_program *shProg, + const char *caller) +{ + if ((shProg != NULL) && !shProg->LinkStatus) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(program %u not linked)", caller, shProg->Name); + return; + } + + if (ctx->Shader.ActiveProgram != shProg) { + _mesa_reference_shader_program(ctx, &ctx->Shader.ActiveProgram, shProg); + } +} + +/** * Use the named shader program for subsequent rendering. */ void @@ -940,6 +959,8 @@ _mesa_use_program(struct gl_context *ctx, GLuint program) return; } + active_program(ctx, shProg, "glUseProgram"); + /* debug code */ if (ctx->Shader.Flags & GLSL_USE_PROG) { print_shader_info(shProg); @@ -1657,18 +1678,11 @@ void GLAPIENTRY _mesa_ActiveProgramEXT(GLuint program) { GET_CURRENT_CONTEXT(ctx); - struct gl_shader_program *shProg; - - shProg = _mesa_lookup_shader_program_err(ctx, program, - "glActiveProgramEXT"); - if (!shProg->LinkStatus) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "glActiveProgramEXT(program not linked)"); - return; - } + struct gl_shader_program *shProg = (program != 0) + ? _mesa_lookup_shader_program_err(ctx, program, "glActiveProgramEXT") + : NULL; - _mesa_error(ctx, GL_INVALID_OPERATION, - "glActiveProgramEXT(NOT YET IMPLEMENTED)"); + active_program(ctx, shProg, "glActiveProgramEXT"); return; } -- cgit v1.1