summaryrefslogtreecommitdiff
path: root/cogl/driver/gl/cogl-pipeline-vertend-glsl.c
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2012-09-27 11:06:16 +0100
committerRobert Bragg <robert@linux.intel.com>2013-01-22 17:48:06 +0000
commit1c449c67f6a02963fdcdbaaec44079a3b6aaa74c (patch)
tree3e904731bee8041dadd0d85b4ab3595dd66c2a2e /cogl/driver/gl/cogl-pipeline-vertend-glsl.c
parent14d8ec7ccabc20ae15bc3e60c136eb68a8dd8add (diff)
downloadcogl-1c449c67f6a02963fdcdbaaec44079a3b6aaa74c.tar.gz
Remove the varying array for tex_coords
This removes the need to maintain an array of tex_coord varyings and instead we now just emit a varying per-layer uniquely named using a layer_number infix like cogl_tex_coord0_out and cogl_tex_coord0_in. Notable this patch also had to change the journal flushing code to use pipeline layer numbers to determine the name of texture coordinate attributes. We now also break batches by using a deeper comparison of layers so such that two pipelines with the same number of layers can now cause a batch break if they use different layer numbers. This adds an internal _cogl_pipeline_layer_numbers_equal() function that takes two pipelines and returns TRUE if they have the same number of layers and all the layer numbers are the same too, otherwise it returns FALSE. Where we used to break batches based on changes to the number of layers we now break according to the status of _cogl_pipeline_layer_numbers_equal Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit e55b64a9cdc93285049d9b969bef67484c2d9fb3) Note: this will cause a temporary regression for the Cogl 1.x CoglShader api since it will break compatibility with existing shaders that reference the texture varyings from the fragment shader. The intention is to follow up with another patch to add back CoglShader compatibility.
Diffstat (limited to 'cogl/driver/gl/cogl-pipeline-vertend-glsl.c')
-rw-r--r--cogl/driver/gl/cogl-pipeline-vertend-glsl.c70
1 files changed, 35 insertions, 35 deletions
diff --git a/cogl/driver/gl/cogl-pipeline-vertend-glsl.c b/cogl/driver/gl/cogl-pipeline-vertend-glsl.c
index f1b14074..61e39398 100644
--- a/cogl/driver/gl/cogl-pipeline-vertend-glsl.c
+++ b/cogl/driver/gl/cogl-pipeline-vertend-glsl.c
@@ -60,9 +60,6 @@ typedef struct
a shader at all */
unsigned int user_program_age;
- /* The number of tex coord attributes that the shader was generated
- * for. If this changes then we need to regenerate the shader */
- int n_tex_coord_attribs;
} CoglPipelineShaderState;
static CoglUserDataKey shader_state_key;
@@ -152,8 +149,7 @@ get_layer_vertex_snippets (CoglPipelineLayer *layer)
static void
_cogl_pipeline_vertend_glsl_start (CoglPipeline *pipeline,
int n_layers,
- unsigned long pipelines_difference,
- int n_tex_coord_attribs)
+ unsigned long pipelines_difference)
{
CoglPipelineShaderState *shader_state;
CoglPipeline *template_pipeline = NULL;
@@ -217,13 +213,11 @@ _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 there's a user program and it
- has changed since the last link then we do need a new shader.
- Also if the number of tex coord attribs changes then we need
- to regenerate the shader with a different boiler plate */
- if ((user_program == NULL ||
- shader_state->user_program_age == user_program->age)
- && shader_state->n_tex_coord_attribs == n_tex_coord_attribs)
+ * generate a new one. However if there's a user program and it
+ * has changed since the last link then we do need a new shader.
+ */
+ if (user_program == NULL ||
+ shader_state->user_program_age == user_program->age)
return;
/* We need to recreate the shader so destroy the existing one */
@@ -236,15 +230,14 @@ _cogl_pipeline_vertend_glsl_start (CoglPipeline *pipeline,
because the user program has changed */
if (user_program)
- shader_state->user_program_age = user_program->age;
-
- shader_state->n_tex_coord_attribs = n_tex_coord_attribs;
+ {
+ shader_state->user_program_age = user_program->age;
- /* If the user program contains a vertex shader then we don't need
- to generate one */
- if (user_program &&
- _cogl_program_has_vertex_shader (user_program))
- return;
+ /* If the user program contains a vertex shader then we don't need
+ to generate one */
+ if (_cogl_program_has_vertex_shader (user_program))
+ return;
+ }
/* We reuse two grow-only GStrings for code-gen. One string
contains the uniform and attribute declarations while the
@@ -277,17 +270,26 @@ _cogl_pipeline_vertend_glsl_add_layer (CoglPipeline *pipeline,
{
CoglPipelineShaderState *shader_state;
CoglPipelineSnippetData snippet_data;
- int unit_index;
+ int layer_index = layer->index;
_COGL_GET_CONTEXT (ctx, FALSE);
shader_state = get_shader_state (pipeline);
- unit_index = _cogl_pipeline_layer_get_unit_index (layer);
-
if (shader_state->source == NULL)
return TRUE;
+ g_string_append_printf (shader_state->header,
+ "uniform mat4 cogl_texture_matrix%i;\n"
+ "attribute vec4 cogl_tex_coord%i_in;\n"
+ "varying vec4 _cogl_tex_coord%i;\n"
+ "#define cogl_tex_coord%i_out _cogl_tex_coord%i\n",
+ layer_index,
+ layer_index,
+ layer_index,
+ layer_index,
+ layer_index);
+
/* Transform the texture coordinates by the layer's user matrix.
*
* FIXME: this should avoid doing the transform if there is no user
@@ -306,18 +308,18 @@ _cogl_pipeline_vertend_glsl_add_layer (CoglPipeline *pipeline,
"{\n"
" return matrix * tex_coord;\n"
"}\n",
- unit_index);
+ layer_index);
/* Wrap the layer code in any snippets that have been hooked */
memset (&snippet_data, 0, sizeof (snippet_data));
snippet_data.snippets = get_layer_vertex_snippets (layer);
snippet_data.hook = COGL_SNIPPET_HOOK_TEXTURE_COORD_TRANSFORM;
snippet_data.chain_function = g_strdup_printf ("cogl_real_transform_layer%i",
- unit_index);
+ layer_index);
snippet_data.final_name = g_strdup_printf ("cogl_transform_layer%i",
- unit_index);
+ layer_index);
snippet_data.function_prefix = g_strdup_printf ("cogl_transform_layer%i",
- unit_index);
+ layer_index);
snippet_data.return_type = "vec4";
snippet_data.return_variable = "cogl_tex_coord";
snippet_data.return_variable_is_argument = TRUE;
@@ -332,14 +334,14 @@ _cogl_pipeline_vertend_glsl_add_layer (CoglPipeline *pipeline,
g_free ((char *) snippet_data.function_prefix);
g_string_append_printf (shader_state->source,
- " cogl_tex_coord_out[%i] = "
- "cogl_transform_layer%i (cogl_texture_matrix[%i],\n"
+ " cogl_tex_coord%i_out = "
+ "cogl_transform_layer%i (cogl_texture_matrix%i,\n"
" "
" cogl_tex_coord%i_in);\n",
- unit_index,
- unit_index,
- unit_index,
- unit_index);
+ layer_index,
+ layer_index,
+ layer_index,
+ layer_index);
return TRUE;
}
@@ -437,8 +439,6 @@ _cogl_pipeline_vertend_glsl_end (CoglPipeline *pipeline,
_cogl_glsl_shader_set_source_with_boilerplate (ctx,
NULL,
shader, GL_VERTEX_SHADER,
- shader_state
- ->n_tex_coord_attribs,
2, /* count */
source_strings, lengths);