From dd5431ef382a59337cfda04bc31cebc28085f17f Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Thu, 2 Dec 2010 16:30:55 +0000 Subject: [PATCH] cogl-pipeline-glsl: Fix reusing shaders for shared ancestors The check for whether we can reuse a program we've already generated was only being done if the pipeline already had a glsl_program_state. When there is no glsl_program_state it then looks for the nearest ancestor it can share the program with. It then wasn't checking whether that ancestor already had a GL program so it would start generating the source again. It wouldn't however compile that source again because _cogl_pipeline_backend_glsl_end does check whether there is already a program. This patch moves the check until after it has found the glsl_program_state, whether or not it was found from an ancestor or as its own state. --- clutter/cogl/cogl/cogl-pipeline-glsl.c | 32 ++++++++++++-------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/clutter/cogl/cogl/cogl-pipeline-glsl.c b/clutter/cogl/cogl/cogl-pipeline-glsl.c index 1e347dc17..3ed4324b4 100644 --- a/clutter/cogl/cogl/cogl-pipeline-glsl.c +++ b/clutter/cogl/cogl/cogl-pipeline-glsl.c @@ -305,23 +305,7 @@ _cogl_pipeline_backend_glsl_start (CoglPipeline *pipeline, set_glsl_priv (pipeline, priv); } - /* If we already have a valid GLSL program then we don't need to - relink a new one */ - if (priv->glsl_program_state) - { - /* However if the program has changed since the last link then we do - * need to relink */ - if (user_program == NULL || - (priv->glsl_program_state->user_program_age == user_program->age)) - return TRUE; - - /* Destroy the existing program. We can't just dirty the whole - glsl state because otherwise if we are not the authority on - the user program then we'll just find the same state again */ - delete_program (priv->glsl_program_state->gl_program); - priv->glsl_program_state->gl_program = 0; - } - else + if (!priv->glsl_program_state) { /* If we don't have an associated glsl program yet then find the * glsl-authority (the oldest ancestor whose state will result in @@ -358,6 +342,20 @@ _cogl_pipeline_backend_glsl_start (CoglPipeline *pipeline, glsl_program_state_ref (authority_priv->glsl_program_state); } + if (priv->glsl_program_state->gl_program) + { + /* If we already have a valid GLSL program then we don't need to + relink a new one. However if the program has changed since + the last link then we do need to relink */ + if (user_program == NULL || + (priv->glsl_program_state->user_program_age == user_program->age)) + return TRUE; + + /* We need to recreate the program so destroy the existing one */ + delete_program (priv->glsl_program_state->gl_program); + priv->glsl_program_state->gl_program = 0; + } + /* If we make it here then we have a glsl_program_state struct without a gl_program either because this is the first time we've encountered it or because the user program has changed since it