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