[cogl/wip/glsl-unified: 3/4] Unify a lot of gles2 vs gl glsl code



commit 9f774b2b0848353b655cc44e59d3886aec658fcc
Author: Robert Bragg <robert linux intel com>
Date:   Sun Sep 23 13:32:36 2012 +0100

    Unify a lot of gles2 vs gl glsl code
    
    Since we used to support hybrid fixed-function + glsl pipelines when
    running with OpenGL there were numerous differences in how we handled
    codegen and uniform updates between GLES2 and full OpenGL. Now that we
    only support end-to-end glsl pipelines this patch can largely unify how
    we handle GLES2 and OpenGL.
    
    Most notably we no never use the builtin attribute names. This should
    also make it easy for us to support creating strict OpenGL 3.1 contexts
    where the builtin names have been removed.

 cogl/cogl-glsl-shader-boilerplate.h         |   70 ++------
 cogl/cogl-glsl-shader.c                     |   15 +--
 cogl/driver/gl/cogl-attribute-gl.c          |   18 +-
 cogl/driver/gl/cogl-pipeline-fragend-glsl.c |   12 +-
 cogl/driver/gl/cogl-pipeline-opengl.c       |   12 +-
 cogl/driver/gl/cogl-pipeline-progend-glsl.c |  267 +++++++++++----------------
 cogl/driver/gl/cogl-pipeline-vertend-glsl.c |   39 +----
 7 files changed, 151 insertions(+), 282 deletions(-)
---
diff --git a/cogl/cogl-glsl-shader-boilerplate.h b/cogl/cogl-glsl-shader-boilerplate.h
index e5a86d8..7a79fd3 100644
--- a/cogl/cogl-glsl-shader-boilerplate.h
+++ b/cogl/cogl-glsl-shader-boilerplate.h
@@ -27,53 +27,7 @@
 #ifndef __COGL_SHADER_BOILERPLATE_H
 #define __COGL_SHADER_BOILERPLATE_H
 
-
-#define _COGL_COMMON_SHADER_BOILERPLATE_GL \
-  "#define COGL_VERSION 100\n" \
-  "\n" \
-  "#define cogl_modelview_matrix gl_ModelViewMatrix\n" \
-  "#define cogl_modelview_projection_matrix gl_ModelViewProjectionMatrix\n" \
-  "#define cogl_projection_matrix gl_ProjectionMatrix\n" \
-  "#define cogl_texture_matrix gl_TextureMatrix\n" \
-  "\n"
-
-#define _COGL_VERTEX_SHADER_BOILERPLATE_GL \
-  _COGL_COMMON_SHADER_BOILERPLATE_GL \
-  "#define cogl_position_in gl_Vertex\n" \
-  "#define cogl_color_in gl_Color\n" \
-  "#define cogl_tex_coord_in  gl_MultiTexCoord0\n" \
-  "#define cogl_tex_coord0_in gl_MultiTexCoord0\n" \
-  "#define cogl_tex_coord1_in gl_MultiTexCoord1\n" \
-  "#define cogl_tex_coord2_in gl_MultiTexCoord2\n" \
-  "#define cogl_tex_coord3_in gl_MultiTexCoord3\n" \
-  "#define cogl_tex_coord4_in gl_MultiTexCoord4\n" \
-  "#define cogl_tex_coord5_in gl_MultiTexCoord5\n" \
-  "#define cogl_tex_coord6_in gl_MultiTexCoord6\n" \
-  "#define cogl_tex_coord7_in gl_MultiTexCoord7\n" \
-  "#define cogl_normal_in gl_Normal\n" \
-  "\n" \
-  "#define cogl_position_out gl_Position\n" \
-  "#define cogl_point_size_out gl_PointSize\n" \
-  "#define cogl_color_out gl_FrontColor\n" \
-  "#define cogl_tex_coord_out gl_TexCoord\n"
-
-#define _COGL_FRAGMENT_SHADER_BOILERPLATE_GL \
-  _COGL_COMMON_SHADER_BOILERPLATE_GL \
-  "#define cogl_color_in gl_Color\n" \
-  "#define cogl_tex_coord_in gl_TexCoord\n" \
-  "\n" \
-  "#define cogl_color_out gl_FragColor\n" \
-  "#define cogl_depth_out gl_FragDepth\n" \
-  "\n" \
-  "#define cogl_front_facing gl_FrontFacing\n"
-#if 0
-  /* GLSL 1.2 has a bottom left origin, though later versions
-   * allow use of an origin_upper_left keyword which would be
-   * more appropriate for Cogl. */
-  "#define coglFragCoord   gl_FragCoord\n"
-#endif
-
-#define _COGL_COMMON_SHADER_BOILERPLATE_GLES2 \
+#define _COGL_COMMON_SHADER_BOILERPLATE \
   "#define COGL_VERSION 100\n" \
   "\n" \
   "uniform mat4 cogl_modelview_matrix;\n" \
@@ -82,12 +36,12 @@
   "uniform float cogl_point_size_in;\n"
 
 /* This declares all of the variables that we might need. This is
-   working on the assumption that the compiler will optimise them out
-   if they are not actually used. The GLSL spec for GLES at least
-   implies that this will happen for varyings but it doesn't
-   explicitly so for attributes */
-#define _COGL_VERTEX_SHADER_BOILERPLATE_GLES2 \
-  _COGL_COMMON_SHADER_BOILERPLATE_GLES2 \
+ * working on the assumption that the compiler will optimise them out
+ * if they are not actually used. The GLSL spec at least implies that
+ * this will happen for varyings but it doesn't explicitly so for
+ * attributes */
+#define _COGL_VERTEX_SHADER_BOILERPLATE \
+  _COGL_COMMON_SHADER_BOILERPLATE \
   "#define cogl_color_out _cogl_color\n" \
   "varying vec4 _cogl_color;\n" \
   "#define cogl_tex_coord_out _cogl_tex_coord\n" \
@@ -99,11 +53,11 @@
   "#define cogl_tex_coord_in cogl_tex_coord0_in;\n" \
   "attribute vec3 cogl_normal_in;\n"
 
-#define _COGL_FRAGMENT_SHADER_BOILERPLATE_GLES2 \
+#define _COGL_FRAGMENT_SHADER_BOILERPLATE \
   "#if __VERSION__ == 100\n" \
   "precision highp float;\n" \
   "#endif\n" \
-  _COGL_COMMON_SHADER_BOILERPLATE_GLES2 \
+  _COGL_COMMON_SHADER_BOILERPLATE \
   "\n" \
   "varying vec4 _cogl_color;\n" \
   "\n" \
@@ -114,6 +68,12 @@
   "#define cogl_depth_out gl_FragDepth\n" \
   "\n" \
   "#define cogl_front_facing gl_FrontFacing\n"
+#if 0
+  /* GLSL 1.2 has a bottom left origin, though later versions
+   * allow use of an origin_upper_left keyword which would be
+   * more appropriate for Cogl. */
+  "#define coglFragCoord   gl_FragCoord\n"
+#endif
 
 #endif /* __COGL_SHADER_BOILERPLATE_H */
 
diff --git a/cogl/cogl-glsl-shader.c b/cogl/cogl-glsl-shader.c
index ae97942..475ea8b 100644
--- a/cogl/cogl-glsl-shader.c
+++ b/cogl/cogl-glsl-shader.c
@@ -56,16 +56,8 @@ _cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx,
   int count = 0;
   char *tex_coord_declarations = NULL;
 
-  if (ctx->driver == COGL_DRIVER_GLES2)
-    {
-      vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE_GLES2;
-      fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE_GLES2;
-    }
-  else
-    {
-      vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE_GL;
-      fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE_GL;
-    }
+  vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE;
+  fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE;
 
   if (ctx->driver == COGL_DRIVER_GLES2 &&
       cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D))
@@ -87,8 +79,7 @@ _cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx,
       lengths[count++] = strlen (fragment_boilerplate);
     }
 
-  if (ctx->driver == COGL_DRIVER_GLES2 &&
-      n_tex_coord_attribs)
+  if (n_tex_coord_attribs)
     {
       GString *declarations = g_string_new (NULL);
 
diff --git a/cogl/driver/gl/cogl-attribute-gl.c b/cogl/driver/gl/cogl-attribute-gl.c
index 5435adb..0c21d12 100644
--- a/cogl/driver/gl/cogl-attribute-gl.c
+++ b/cogl/driver/gl/cogl-attribute-gl.c
@@ -318,8 +318,8 @@ _cogl_gl_flush_attributes_state (CoglFramebuffer *framebuffer,
       switch (attribute->name_state->name_id)
         {
         case COGL_ATTRIBUTE_NAME_ID_COLOR_ARRAY:
-#ifdef HAVE_COGL_GLES2
-          if (ctx->driver == COGL_DRIVER_GLES2)
+#ifdef COGL_PIPELINE_PROGEND_GLSL
+          if (pipeline->progend == COGL_PIPELINE_PROGEND_GLSL)
             setup_generic_attribute (ctx, pipeline, attribute, base);
           else
 #endif
@@ -333,8 +333,8 @@ _cogl_gl_flush_attributes_state (CoglFramebuffer *framebuffer,
             }
           break;
         case COGL_ATTRIBUTE_NAME_ID_NORMAL_ARRAY:
-#ifdef HAVE_COGL_GLES2
-          if (ctx->driver == COGL_DRIVER_GLES2)
+#ifdef COGL_PIPELINE_PROGEND_GLSL
+          if (pipeline->progend == COGL_PIPELINE_PROGEND_GLSL)
             setup_generic_attribute (ctx, pipeline, attribute, base);
           else
 #endif
@@ -347,8 +347,8 @@ _cogl_gl_flush_attributes_state (CoglFramebuffer *framebuffer,
             }
           break;
         case COGL_ATTRIBUTE_NAME_ID_TEXTURE_COORD_ARRAY:
-#ifdef HAVE_COGL_GLES2
-          if (ctx->driver == COGL_DRIVER_GLES2)
+#ifdef COGL_PIPELINE_PROGEND_GLSL
+          if (pipeline->progend == COGL_PIPELINE_PROGEND_GLSL)
             setup_generic_attribute (ctx, pipeline, attribute, base);
           else
 #endif
@@ -365,8 +365,8 @@ _cogl_gl_flush_attributes_state (CoglFramebuffer *framebuffer,
             }
           break;
         case COGL_ATTRIBUTE_NAME_ID_POSITION_ARRAY:
-#ifdef HAVE_COGL_GLES2
-          if (ctx->driver == COGL_DRIVER_GLES2)
+#ifdef COGL_PIPELINE_PROGEND_GLSL
+          if (pipeline->progend == COGL_PIPELINE_PROGEND_GLSL)
             setup_generic_attribute (ctx, pipeline, attribute, base);
           else
 #endif
@@ -381,7 +381,7 @@ _cogl_gl_flush_attributes_state (CoglFramebuffer *framebuffer,
           break;
         case COGL_ATTRIBUTE_NAME_ID_CUSTOM_ARRAY:
 #ifdef COGL_PIPELINE_PROGEND_GLSL
-          if (ctx->driver != COGL_DRIVER_GLES1)
+          if (pipeline->progend == COGL_PIPELINE_PROGEND_GLSL)
             setup_generic_attribute (ctx, pipeline, attribute, base);
 #endif
           break;
diff --git a/cogl/driver/gl/cogl-pipeline-fragend-glsl.c b/cogl/driver/gl/cogl-pipeline-fragend-glsl.c
index c406149..d5b2309 100644
--- a/cogl/driver/gl/cogl-pipeline-fragend-glsl.c
+++ b/cogl/driver/gl/cogl-pipeline-fragend-glsl.c
@@ -98,8 +98,7 @@ typedef struct
   LayerDataList layers;
 
   /* The number of tex coord attributes that the shader was generated
-     for. If this changes on GLES2 then we need to regenerate the
-     shader */
+   * for. If this changes then we need to regenerate the shader */
   int n_tex_coord_attribs;
 } CoglPipelineShaderState;
 
@@ -284,11 +283,10 @@ _cogl_pipeline_fragend_glsl_start (CoglPipeline *pipeline,
   if (shader_state->gl_shader)
     {
       /* If we already have a valid GLSL shader then we don't need to
-         generate a new one. However if the number of tex coord
-         attribs changes on GLES2 then we need to regenerate the
-         shader with a different boiler plate */
-      if ((ctx->driver != COGL_DRIVER_GLES2 ||
-          shader_state->n_tex_coord_attribs == n_tex_coord_attribs))
+       * generate a new one. However if the number of tex coord
+       * attribs changes then we need to regenerate the shader with a
+       * different boiler plate */
+      if (shader_state->n_tex_coord_attribs == n_tex_coord_attribs)
         return;
 
       /* We need to recreate the shader so destroy the existing one */
diff --git a/cogl/driver/gl/cogl-pipeline-opengl.c b/cogl/driver/gl/cogl-pipeline-opengl.c
index 50a338d..8139c95 100644
--- a/cogl/driver/gl/cogl-pipeline-opengl.c
+++ b/cogl/driver/gl/cogl-pipeline-opengl.c
@@ -1320,12 +1320,11 @@ done:
 
   progend = _cogl_pipeline_progends[pipeline->progend];
 
-  /* We can't assume the color will be retained between flushes on
-     GLES2 because the generic attribute values are not stored as part
-     of the program object so they could be overridden by any
-     attribute changes in another program */
-#ifdef HAVE_COGL_GLES2
-  if (ctx->driver == COGL_DRIVER_GLES2 && !skip_gl_color)
+  /* We can't assume the color will be retained between flushes when
+   * using the glsl progend because the generic attribute values are
+   * not stored as part of the program object so they could be
+   * overridden by any attribute changes in another program */
+  if (pipeline->progend == COGL_PIPELINE_PROGEND_GLSL && !skip_gl_color)
     {
       int attribute;
       CoglPipeline *authority =
@@ -1342,7 +1341,6 @@ done:
                               cogl_color_get_blue_float (&authority->color),
                               cogl_color_get_alpha_float (&authority->color)));
     }
-#endif
 
   /* Give the progend a chance to update any uniforms that might not
    * depend on the material state. This is used on GLES2 to update the
diff --git a/cogl/driver/gl/cogl-pipeline-progend-glsl.c b/cogl/driver/gl/cogl-pipeline-progend-glsl.c
index a2aaffd..ff90d3c 100644
--- a/cogl/driver/gl/cogl-pipeline-progend-glsl.c
+++ b/cogl/driver/gl/cogl-pipeline-progend-glsl.c
@@ -113,6 +113,7 @@ typedef struct
 #ifdef HAVE_COGL_GLES2
   unsigned long dirty_builtin_uniforms;
   GLint builtin_uniform_locations[G_N_ELEMENTS (builtin_uniforms)];
+#endif
 
   GLint modelview_uniform;
   GLint projection_uniform;
@@ -120,7 +121,6 @@ typedef struct
 
   CoglMatrixEntryCache projection_cache;
   CoglMatrixEntryCache modelview_cache;
-#endif
 
   /* We need to track the last pipeline that the program was used with
    * so know if we need to update all of the uniforms */
@@ -221,8 +221,6 @@ clear_attribute_cache (CoglPipelineProgramState *program_state)
     }
 }
 
-#ifdef HAVE_COGL_GLES2
-
 static void
 clear_flushed_matrix_stacks (CoglPipelineProgramState *program_state)
 {
@@ -232,8 +230,6 @@ clear_flushed_matrix_stacks (CoglPipelineProgramState *program_state)
   _cogl_matrix_entry_cache_init (&program_state->modelview_cache);
 }
 
-#endif /* HAVE_COGL_GLES2 */
-
 static CoglPipelineProgramState *
 program_state_new (int n_layers)
 {
@@ -246,10 +242,8 @@ program_state_new (int n_layers)
   program_state->unit_state = g_new (UnitState, n_layers);
   program_state->uniform_locations = NULL;
   program_state->attribute_locations = NULL;
-#ifdef HAVE_COGL_GLES2
   _cogl_matrix_entry_cache_init (&program_state->modelview_cache);
   _cogl_matrix_entry_cache_init (&program_state->projection_cache);
-#endif
 
   return program_state;
 }
@@ -273,13 +267,8 @@ destroy_program_state (void *user_data,
     {
       clear_attribute_cache (program_state);
 
-#ifdef HAVE_COGL_GLES2
-      if (ctx->driver == COGL_DRIVER_GLES2)
-        {
-          _cogl_matrix_entry_cache_destroy (&program_state->projection_cache);
-          _cogl_matrix_entry_cache_destroy (&program_state->modelview_cache);
-        }
-#endif
+      _cogl_matrix_entry_cache_destroy (&program_state->projection_cache);
+      _cogl_matrix_entry_cache_destroy (&program_state->modelview_cache);
 
       if (program_state->program)
         GE( ctx, glDeleteProgram (program_state->program) );
@@ -390,20 +379,15 @@ get_uniform_cb (CoglPipeline *pipeline,
 
   unit_state->combine_constant_uniform = uniform_location;
 
-#ifdef HAVE_COGL_GLES2
-  if (ctx->driver == COGL_DRIVER_GLES2)
-    {
-      g_string_set_size (ctx->codegen_source_buffer, 0);
-      g_string_append_printf (ctx->codegen_source_buffer,
-                              "cogl_texture_matrix[%i]", state->unit);
+  g_string_set_size (ctx->codegen_source_buffer, 0);
+  g_string_append_printf (ctx->codegen_source_buffer,
+                          "cogl_texture_matrix[%i]", state->unit);
 
-      GE_RET( uniform_location,
-              ctx, glGetUniformLocation (state->gl_program,
-                                         ctx->codegen_source_buffer->str) );
+  GE_RET( uniform_location,
+          ctx, glGetUniformLocation (state->gl_program,
+                                     ctx->codegen_source_buffer->str) );
 
-      unit_state->texture_matrix_uniform = uniform_location;
-    }
-#endif
+  unit_state->texture_matrix_uniform = uniform_location;
 
   state->unit++;
 
@@ -433,10 +417,7 @@ update_constants_cb (CoglPipeline *pipeline,
       unit_state->dirty_combine_constant = FALSE;
     }
 
-#ifdef HAVE_COGL_GLES2
-
-  if (ctx->driver == COGL_DRIVER_GLES2 &&
-      unit_state->texture_matrix_uniform != -1 &&
+  if (unit_state->texture_matrix_uniform != -1 &&
       (state->update_all || unit_state->dirty_texture_matrix))
     {
       const CoglMatrix *matrix;
@@ -449,8 +430,6 @@ update_constants_cb (CoglPipeline *pipeline,
       unit_state->dirty_texture_matrix = FALSE;
     }
 
-#endif /* HAVE_COGL_GLES2 */
-
   return TRUE;
 }
 
@@ -722,8 +701,7 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
   /* If the number of texture coordinate attributes in use has
    * changed, then delete the program so we can prepend a new
    * _cogl_tex_coord[] varying array declaration. */
-  if (ctx->driver == COGL_DRIVER_GLES2 &&
-      n_tex_coord_attribs != program_state->n_tex_coord_attribs)
+  if (n_tex_coord_attribs != program_state->n_tex_coord_attribs)
     {
       GE( ctx, glDeleteProgram (program_state->program) );
       program_state->program = 0;
@@ -777,38 +755,36 @@ _cogl_pipeline_progend_glsl_end (CoglPipeline *pipeline,
                                update_constants_cb,
                                &state);
 
-#ifdef HAVE_COGL_GLES2
-  if (ctx->driver == COGL_DRIVER_GLES2)
+  if (program_changed)
     {
-      if (program_changed)
-        {
-          int i;
-
-          clear_flushed_matrix_stacks (program_state);
+      int i;
 
-          for (i = 0; i < G_N_ELEMENTS (builtin_uniforms); i++)
-            GE_RET( program_state->builtin_uniform_locations[i], ctx,
-                    glGetUniformLocation (gl_program,
-                                          builtin_uniforms[i].uniform_name) );
+      clear_flushed_matrix_stacks (program_state);
 
-          GE_RET( program_state->modelview_uniform, ctx,
-                  glGetUniformLocation (gl_program,
-                                        "cogl_modelview_matrix") );
+      for (i = 0; i < G_N_ELEMENTS (builtin_uniforms); i++)
+        GE_RET( program_state->builtin_uniform_locations[i], ctx,
+                glGetUniformLocation (gl_program,
+                                      builtin_uniforms[i].uniform_name) );
 
-          GE_RET( program_state->projection_uniform, ctx,
-                  glGetUniformLocation (gl_program,
-                                        "cogl_projection_matrix") );
+      GE_RET( program_state->modelview_uniform, ctx,
+              glGetUniformLocation (gl_program,
+                                    "cogl_modelview_matrix") );
 
-          GE_RET( program_state->mvp_uniform, ctx,
-                  glGetUniformLocation (gl_program,
-                                        "cogl_modelview_projection_matrix") );
-        }
-      if (program_changed ||
-          program_state->last_used_for_pipeline != pipeline)
-        program_state->dirty_builtin_uniforms = ~(unsigned long) 0;
+      GE_RET( program_state->projection_uniform, ctx,
+              glGetUniformLocation (gl_program,
+                                    "cogl_projection_matrix") );
 
-      update_builtin_uniforms (pipeline, gl_program, program_state);
+      GE_RET( program_state->mvp_uniform, ctx,
+              glGetUniformLocation (gl_program,
+                                    "cogl_modelview_projection_matrix") );
     }
+
+#ifdef HAVE_COGL_GLES2
+  if (program_changed ||
+      program_state->last_used_for_pipeline != pipeline)
+    program_state->dirty_builtin_uniforms = ~(unsigned long) 0;
+
+  update_builtin_uniforms (pipeline, gl_program, program_state);
 #endif
 
   _cogl_pipeline_progend_glsl_flush_uniforms (pipeline,
@@ -900,6 +876,11 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline,
   CoglMatrixEntry *projection_entry;
   CoglMatrixEntry *modelview_entry;
   CoglPipelineProgramState *program_state;
+  CoglBool modelview_changed;
+  CoglBool projection_changed;
+  CoglBool need_modelview;
+  CoglBool need_projection;
+  CoglMatrix modelview, projection;
 
   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
 
@@ -916,117 +897,87 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline,
 
   needs_flip = cogl_is_offscreen (ctx->current_draw_buffer);
 
-#ifdef HAVE_COGL_GLES2
-  if (ctx->driver == COGL_DRIVER_GLES2)
+  projection_changed =
+    _cogl_matrix_entry_cache_maybe_update (&program_state->projection_cache,
+                                           projection_entry,
+                                           (needs_flip &&
+                                            program_state->flip_uniform ==
+                                            -1));
+
+  modelview_changed =
+    _cogl_matrix_entry_cache_maybe_update (&program_state->modelview_cache,
+                                           modelview_entry,
+                                           /* never flip modelview */
+                                           FALSE);
+
+  if (modelview_changed || projection_changed)
     {
-      CoglBool modelview_changed;
-      CoglBool projection_changed;
-      CoglBool need_modelview;
-      CoglBool need_projection;
-      CoglMatrix modelview, projection;
-
-      projection_changed =
-        _cogl_matrix_entry_cache_maybe_update (&program_state->projection_cache,
-                                               projection_entry,
-                                               (needs_flip &&
-                                                program_state->flip_uniform ==
-                                                -1));
-
-      modelview_changed =
-        _cogl_matrix_entry_cache_maybe_update (&program_state->modelview_cache,
-                                               modelview_entry,
-                                               /* never flip modelview */
-                                               FALSE);
-
-      if (modelview_changed || projection_changed)
+      if (program_state->mvp_uniform != -1)
+        need_modelview = need_projection = TRUE;
+      else
         {
-          if (program_state->mvp_uniform != -1)
-            need_modelview = need_projection = TRUE;
-          else
-            {
-              need_projection = (program_state->projection_uniform != -1 &&
-                                 projection_changed);
-              need_modelview = (program_state->modelview_uniform != -1 &&
-                                modelview_changed);
-            }
+          need_projection = (program_state->projection_uniform != -1 &&
+                             projection_changed);
+          need_modelview = (program_state->modelview_uniform != -1 &&
+                            modelview_changed);
+        }
 
-          if (need_modelview)
-            _cogl_matrix_entry_get (modelview_entry, &modelview);
-          if (need_projection)
+      if (need_modelview)
+        _cogl_matrix_entry_get (modelview_entry, &modelview);
+      if (need_projection)
+        {
+          if (needs_flip && program_state->flip_uniform == -1)
             {
-              if (needs_flip && program_state->flip_uniform == -1)
-                {
-                  CoglMatrix tmp_matrix;
-                  _cogl_matrix_entry_get (projection_entry, &tmp_matrix);
-                  cogl_matrix_multiply (&projection,
-                                        &ctx->y_flip_matrix,
-                                        &tmp_matrix);
-                }
-              else
-                _cogl_matrix_entry_get (projection_entry, &projection);
+              CoglMatrix tmp_matrix;
+              _cogl_matrix_entry_get (projection_entry, &tmp_matrix);
+              cogl_matrix_multiply (&projection,
+                                    &ctx->y_flip_matrix,
+                                    &tmp_matrix);
             }
+          else
+            _cogl_matrix_entry_get (projection_entry, &projection);
+        }
 
-          if (projection_changed && program_state->projection_uniform != -1)
-            GE (ctx, glUniformMatrix4fv (program_state->projection_uniform,
-                                         1, /* count */
-                                         FALSE, /* transpose */
-                                         cogl_matrix_get_array (&projection)));
+      if (projection_changed && program_state->projection_uniform != -1)
+        GE (ctx, glUniformMatrix4fv (program_state->projection_uniform,
+                                     1, /* count */
+                                     FALSE, /* transpose */
+                                     cogl_matrix_get_array (&projection)));
 
-          if (modelview_changed && program_state->modelview_uniform != -1)
-            GE (ctx, glUniformMatrix4fv (program_state->modelview_uniform,
-                                         1, /* count */
-                                         FALSE, /* transpose */
-                                         cogl_matrix_get_array (&modelview)));
+      if (modelview_changed && program_state->modelview_uniform != -1)
+        GE (ctx, glUniformMatrix4fv (program_state->modelview_uniform,
+                                     1, /* count */
+                                     FALSE, /* transpose */
+                                     cogl_matrix_get_array (&modelview)));
 
-          if (program_state->mvp_uniform != -1)
+      if (program_state->mvp_uniform != -1)
+        {
+          /* The journal usually uses an identity matrix for the
+             modelview so we can optimise this common case by
+             avoiding the matrix multiplication */
+          if (_cogl_matrix_entry_has_identity_flag (modelview_entry))
             {
-              /* The journal usually uses an identity matrix for the
-                 modelview so we can optimise this common case by
-                 avoiding the matrix multiplication */
-              if (_cogl_matrix_entry_has_identity_flag (modelview_entry))
-                {
-                  GE (ctx,
-                      glUniformMatrix4fv (program_state->mvp_uniform,
-                                          1, /* count */
-                                          FALSE, /* transpose */
-                                          cogl_matrix_get_array (&projection)));
-                }
-              else
-                {
-                  CoglMatrix combined;
-
-                  cogl_matrix_multiply (&combined,
-                                        &projection,
-                                        &modelview);
-                  GE (ctx,
-                      glUniformMatrix4fv (program_state->mvp_uniform,
-                                          1, /* count */
-                                          FALSE, /* transpose */
-                                          cogl_matrix_get_array (&combined)));
-                }
+              GE (ctx,
+                  glUniformMatrix4fv (program_state->mvp_uniform,
+                                      1, /* count */
+                                      FALSE, /* transpose */
+                                      cogl_matrix_get_array (&projection)));
+            }
+          else
+            {
+              CoglMatrix combined;
+
+              cogl_matrix_multiply (&combined,
+                                    &projection,
+                                    &modelview);
+              GE (ctx,
+                  glUniformMatrix4fv (program_state->mvp_uniform,
+                                      1, /* count */
+                                      FALSE, /* transpose */
+                                      cogl_matrix_get_array (&combined)));
             }
         }
     }
-  else
-#endif
-    {
-      CoglBool disable_flip;
-
-      /* If there are vertex snippets, then we'll disable flipping the
-         geometry via the matrix and use the flip vertex instead */
-      disable_flip = program_state->flip_uniform != -1;
-
-      _cogl_matrix_entry_flush_to_gl_builtins (ctx,
-                                               projection_entry,
-                                               COGL_MATRIX_PROJECTION,
-                                               framebuffer,
-                                               disable_flip);
-      _cogl_matrix_entry_flush_to_gl_builtins (ctx,
-                                               modelview_entry,
-                                               COGL_MATRIX_MODELVIEW,
-                                               framebuffer,
-                                               disable_flip);
-    }
 
   if (program_state->flip_uniform != -1
       && program_state->flushed_flip_state != needs_flip)
diff --git a/cogl/driver/gl/cogl-pipeline-vertend-glsl.c b/cogl/driver/gl/cogl-pipeline-vertend-glsl.c
index e7a0fe1..ca2adcb 100644
--- a/cogl/driver/gl/cogl-pipeline-vertend-glsl.c
+++ b/cogl/driver/gl/cogl-pipeline-vertend-glsl.c
@@ -54,8 +54,7 @@ typedef struct
   GString *header, *source;
 
   /* The number of tex coord attributes that the shader was generated
-     for. If this changes on GLES2 then we need to regenerate the
-     shader */
+   * for. If this changes then we need to regenerate the shader */
   int n_tex_coord_attribs;
 } CoglPipelineShaderState;
 
@@ -210,11 +209,10 @@ _cogl_pipeline_vertend_glsl_start (CoglPipeline *pipeline,
   if (shader_state->gl_shader)
     {
       /* If we already have a valid GLSL shader then we don't need to
-         generate a new one. However if the number of tex coord
-         attribs changes on GLES2 then we need to regenerate the
-         shader with a different boiler plate */
-      if (ctx->driver != COGL_DRIVER_GLES2 ||
-          shader_state->n_tex_coord_attribs == n_tex_coord_attribs)
+       * generate a new one. However if the number of tex coord
+       * attribs changes then we need to regenerate the shader with a
+       * different boiler plate */
+      if (shader_state->n_tex_coord_attribs == n_tex_coord_attribs)
         return;
 
       /* We need to recreate the shader so destroy the existing one */
@@ -267,33 +265,6 @@ _cogl_pipeline_vertend_glsl_add_layer (CoglPipeline *pipeline,
 
   unit_index = _cogl_pipeline_layer_get_unit_index (layer);
 
-  if (ctx->driver != COGL_DRIVER_GLES2)
-    {
-      /* We are using the fixed function uniforms for the user matrices
-         and the only way to set them is with the fixed function API so we
-         still need to flush them here */
-      if (layers_difference & COGL_PIPELINE_LAYER_STATE_USER_MATRIX)
-        {
-          CoglPipelineLayerState state = COGL_PIPELINE_LAYER_STATE_USER_MATRIX;
-          CoglPipelineLayer *authority =
-            _cogl_pipeline_layer_get_authority (layer, state);
-          CoglTextureUnit *unit = _cogl_get_texture_unit (unit_index);
-          CoglMatrixEntry *matrix_entry;
-
-          _cogl_matrix_stack_set (unit->matrix_stack,
-                                  &authority->big_state->matrix);
-
-          _cogl_set_active_texture_unit (unit_index);
-
-          matrix_entry = unit->matrix_stack->last_entry;
-          _cogl_matrix_entry_flush_to_gl_builtins (ctx,
-                                                   matrix_entry,
-                                                   COGL_MATRIX_TEXTURE,
-                                                   framebuffer,
-                                                   FALSE /* do flip */);
-        }
-    }
-
   if (shader_state->source == NULL)
     return TRUE;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]