[Cogl] [PATCH] Unify a lot of gles2 vs gl glsl code
Robert Bragg
robert at sixbynine.org
Fri Sep 28 04:16:06 PDT 2012
From: Robert Bragg <robert at linux.intel.com>
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-private.h | 1 +
cogl/cogl-glsl-shader.c | 22 +--
cogl/cogl-pipeline.c | 3 +-
cogl/driver/gl/cogl-attribute-gl.c | 18 +-
cogl/driver/gl/cogl-pipeline-fragend-glsl.c | 43 +++--
cogl/driver/gl/cogl-pipeline-opengl.c | 19 +-
cogl/driver/gl/cogl-pipeline-progend-glsl.c | 267 +++++++++++----------------
cogl/driver/gl/cogl-pipeline-vertend-glsl.c | 40 +----
cogl/driver/gl/gl/cogl-driver-gl.c | 22 ++-
10 files changed, 201 insertions(+), 304 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-private.h b/cogl/cogl-glsl-shader-private.h
index 9d50650..012c78e 100644
--- a/cogl/cogl-glsl-shader-private.h
+++ b/cogl/cogl-glsl-shader-private.h
@@ -25,6 +25,7 @@
void
_cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx,
+ const char *version_string,
GLuint shader_gl_handle,
GLenum shader_gl_type,
int n_tex_coord_attribs,
diff --git a/cogl/cogl-glsl-shader.c b/cogl/cogl-glsl-shader.c
index ae97942..92bbe2a 100644
--- a/cogl/cogl-glsl-shader.c
+++ b/cogl/cogl-glsl-shader.c
@@ -41,6 +41,7 @@
void
_cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx,
+ const char *version_string,
GLuint shader_gl_handle,
GLenum shader_gl_type,
int n_tex_coord_attribs,
@@ -51,20 +52,18 @@ _cogl_glsl_shader_set_source_with_boilerplate (CoglContext *ctx,
const char *vertex_boilerplate;
const char *fragment_boilerplate;
- const char **strings = g_alloca (sizeof (char *) * (count_in + 3));
- GLint *lengths = g_alloca (sizeof (GLint) * (count_in + 3));
+ const char **strings = g_alloca (sizeof (char *) * (count_in + 4));
+ GLint *lengths = g_alloca (sizeof (GLint) * (count_in + 4));
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;
+ fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE;
+
+ if (version_string)
{
- vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE_GL;
- fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE_GL;
+ strings[count] = version_string;
+ lengths[count++] = -1;
}
if (ctx->driver == COGL_DRIVER_GLES2 &&
@@ -87,8 +86,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/cogl-pipeline.c b/cogl/cogl-pipeline.c
index a703a36..1b38442 100644
--- a/cogl/cogl-pipeline.c
+++ b/cogl/cogl-pipeline.c
@@ -2665,7 +2665,8 @@ _cogl_pipeline_get_layer_state_for_fragment_codegen (CoglContext *context)
COGL_PIPELINE_LAYER_STATE_UNIT |
COGL_PIPELINE_LAYER_STATE_FRAGMENT_SNIPPETS);
- if (context->driver == COGL_DRIVER_GLES2)
+ if (context->driver == COGL_DRIVER_GL ||
+ context->driver == COGL_DRIVER_GLES2)
state |= COGL_PIPELINE_LAYER_STATE_POINT_SPRITE_COORDS;
return state;
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 52da359..0d0395e 100644
--- a/cogl/driver/gl/cogl-pipeline-fragend-glsl.c
+++ b/cogl/driver/gl/cogl-pipeline-fragend-glsl.c
@@ -91,6 +91,8 @@ typedef struct
GString *header, *source;
UnitState *unit_state;
+ CoglBool ref_point_coord;
+
/* List of layers that we haven't generated code for yet. These are
in reverse order. As soon as we're about to generate code for
layer we'll remove it from the list so we don't generate it
@@ -98,8 +100,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;
@@ -117,6 +118,7 @@ shader_state_new (int n_layers)
shader_state = g_slice_new0 (CoglPipelineShaderState);
shader_state->ref_count = 1;
shader_state->unit_state = g_new0 (UnitState, n_layers);
+ shader_state->ref_point_coord = FALSE;
return shader_state;
}
@@ -284,11 +286,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 */
@@ -408,19 +409,13 @@ ensure_texture_lookup_generated (CoglPipelineShaderState *shader_state,
layer->index,
layer->index);
- /* If point sprite coord generation is being used then divert to the
- built-in varying var for that instead of the texture
- coordinates. We don't want to do this under GL because in that
- case we will instead use glTexEnv(GL_COORD_REPLACE) to replace
- the texture coords with the point sprite coords. Although GL also
- supports the gl_PointCoord variable, it requires GLSL 1.2 which
- would mean we would have to declare the GLSL version and check
- for it */
- if (ctx->driver == COGL_DRIVER_GLES2 &&
- cogl_pipeline_get_layer_point_sprite_coords_enabled (pipeline,
+ if (cogl_pipeline_get_layer_point_sprite_coords_enabled (pipeline,
layer->index))
- g_string_append_printf (shader_state->source,
- "vec4 (gl_PointCoord, 0.0, 1.0)");
+ {
+ shader_state->ref_point_coord = TRUE;
+ g_string_append_printf (shader_state->source,
+ "vec4 (gl_PointCoord, 0.0, 1.0)");
+ }
else
g_string_append_printf (shader_state->source,
"cogl_tex_coord_in[%d]",
@@ -978,6 +973,7 @@ _cogl_pipeline_fragend_glsl_end (CoglPipeline *pipeline,
GLint compile_status;
GLuint shader;
CoglPipelineSnippetData snippet_data;
+ const char *version_string;
COGL_STATIC_COUNTER (fragend_glsl_compile_counter,
"glsl fragment compile counter",
@@ -1053,7 +1049,16 @@ _cogl_pipeline_fragend_glsl_end (CoglPipeline *pipeline,
lengths[1] = shader_state->source->len;
source_strings[1] = shader_state->source->str;
+ if (shader_state->ref_point_coord &&
+ ctx->driver == COGL_DRIVER_GL)
+ {
+ version_string = "#version 120\n";
+ }
+ else
+ version_string = NULL;
+
_cogl_glsl_shader_set_source_with_boilerplate (ctx,
+ version_string,
shader, GL_FRAGMENT_SHADER,
shader_state
->n_tex_coord_attribs,
diff --git a/cogl/driver/gl/cogl-pipeline-opengl.c b/cogl/driver/gl/cogl-pipeline-opengl.c
index 50a338d..9af4996 100644
--- a/cogl/driver/gl/cogl-pipeline-opengl.c
+++ b/cogl/driver/gl/cogl-pipeline-opengl.c
@@ -828,8 +828,11 @@ flush_layers_common_gl_state_cb (CoglPipelineLayer *layer, void *user_data)
GE( ctx, glBindSampler (unit_index, sampler_state->sampler_object) );
}
- /* Under GLES2 the fragment shader will use gl_PointCoord instead of
- replacing the texture coordinates */
+ /* FIXME: If using GLSL the progend we will use gl_PointCoord
+ * instead of us needing to replace the texture coordinates but at
+ * this point we can't currently tell if we are using the fixed or
+ * glsl progend.
+ */
#if defined (HAVE_COGL_GLES) || defined (HAVE_COGL_GL)
if (ctx->driver != COGL_DRIVER_GLES2 &&
(layers_difference & COGL_PIPELINE_LAYER_STATE_POINT_SPRITE_COORDS))
@@ -1320,12 +1323,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 +1344,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 6a64c57..84644c6 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 */
@@ -265,33 +263,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;
@@ -442,6 +413,7 @@ _cogl_pipeline_vertend_glsl_end (CoglPipeline *pipeline,
source_strings[1] = shader_state->source->str;
_cogl_glsl_shader_set_source_with_boilerplate (ctx,
+ NULL,
shader, GL_VERTEX_SHADER,
shader_state
->n_tex_coord_attribs,
diff --git a/cogl/driver/gl/gl/cogl-driver-gl.c b/cogl/driver/gl/gl/cogl-driver-gl.c
index 2533002..16e6750 100644
--- a/cogl/driver/gl/gl/cogl-driver-gl.c
+++ b/cogl/driver/gl/gl/cogl-driver-gl.c
@@ -456,13 +456,6 @@ _cogl_driver_update_features (CoglContext *ctx,
_cogl_check_extension ("GL_EXT_pixel_buffer_object", gl_extensions))
private_flags |= COGL_PRIVATE_FEATURE_PBOS;
- if (COGL_CHECK_GL_VERSION (gl_major, gl_minor, 2, 0) ||
- _cogl_check_extension ("GL_ARB_point_sprite", gl_extensions))
- {
- flags |= COGL_FEATURE_POINT_SPRITE;
- COGL_FLAGS_SET (ctx->features, COGL_FEATURE_ID_POINT_SPRITE, TRUE);
- }
-
if (ctx->glGenPrograms)
{
flags |= COGL_FEATURE_SHADERS_ARBFP;
@@ -474,6 +467,21 @@ _cogl_driver_update_features (CoglContext *ctx,
flags |= COGL_FEATURE_SHADERS_GLSL;
COGL_FLAGS_SET (ctx->features, COGL_FEATURE_ID_GLSL, TRUE);
}
+
+ if ((COGL_CHECK_GL_VERSION (gl_major, gl_minor, 2, 0) ||
+ _cogl_check_extension ("GL_ARB_point_sprite", gl_extensions)) &&
+
+ /* If GLSL is supported then we only enable point sprite support
+ * too if we have glsl >= 1.2 otherwise we don't have the
+ * gl_PointCoord builtin which we depend on in the glsl backend.
+ */
+ ((flags & COGL_FEATURE_SHADERS_GLSL) == 0 ||
+ COGL_CHECK_GL_VERSION (ctx->glsl_major, ctx->glsl_minor, 1, 2)))
+ {
+ flags |= COGL_FEATURE_POINT_SPRITE;
+ COGL_FLAGS_SET (ctx->features, COGL_FEATURE_ID_POINT_SPRITE, TRUE);
+ }
+
/* If all of the old GLSL extensions are available then we can fake
* the GL 2.0 GLSL support by diverting to the old function names */
else if (ctx->glCreateProgramObject && /* GL_ARB_shader_objects */
--
1.7.7.6
More information about the Cogl
mailing list