summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2012-01-03 11:42:42 +0000
committerNeil Roberts <neil@linux.intel.com>2012-02-13 17:29:20 +0000
commit2caf9e0f59458666f2e5ba4fc1edfb4f6e85e743 (patch)
treead824c2add822d756188671d42cf7f04e425a005
parentaa9c2935027a3d5c6b14c80fa703375182b170fc (diff)
downloadcogl-2caf9e0f59458666f2e5ba4fc1edfb4f6e85e743.tar.gz
glsl: always emit sampler uniforms for non NULL layers
There might be custom hooks that want to sample arbitrary layers even though they aren't referenced as part of the auto generated layer combine code. This ensures the sampler uniforms are always output for non-null layers so at least these can be used. We may consider changing this later to always emit a wrapper cogl_sampleX() function for each layer so all samples of a layer can consistently be modified by a COGL_SNIPPET_HOOK_TEXTURE_LOOKUP hook. Reviewed-by: Neil Roberts <neil@linux.intel.com>
-rw-r--r--cogl/cogl-pipeline-fragend-glsl.c92
-rw-r--r--cogl/cogl-pipeline-progend-glsl.c2
2 files changed, 61 insertions, 33 deletions
diff --git a/cogl/cogl-pipeline-fragend-glsl.c b/cogl/cogl-pipeline-fragend-glsl.c
index a1885c0b..ccd0da83 100644
--- a/cogl/cogl-pipeline-fragend-glsl.c
+++ b/cogl/cogl-pipeline-fragend-glsl.c
@@ -373,6 +373,44 @@ add_constant_lookup (CoglPipelineShaderState *shader_state,
}
static void
+get_texture_target_string (CoglTextureType texture_type,
+ const char **target_string_out,
+ const char **swizzle_out)
+{
+ const char *target_string, *tex_coord_swizzle;
+
+ switch (texture_type)
+ {
+#if 0 /* TODO */
+ case COGL_TEXTURE_TYPE_1D:
+ target_string = "1D";
+ tex_coord_swizzle = "s";
+ break;
+#endif
+
+ case COGL_TEXTURE_TYPE_2D:
+ target_string = "2D";
+ tex_coord_swizzle = "st";
+ break;
+
+ case COGL_TEXTURE_TYPE_3D:
+ target_string = "3D";
+ tex_coord_swizzle = "stp";
+ break;
+
+ case COGL_TEXTURE_TYPE_RECTANGLE:
+ target_string = "2DRect";
+ tex_coord_swizzle = "st";
+ break;
+ }
+
+ if (target_string_out)
+ *target_string_out = target_string;
+ if (swizzle_out)
+ *swizzle_out = tex_coord_swizzle;
+}
+
+static void
ensure_texture_lookup_generated (CoglPipelineShaderState *shader_state,
CoglPipeline *pipeline,
CoglPipelineLayer *layer)
@@ -424,37 +462,9 @@ ensure_texture_lookup_generated (CoglPipelineShaderState *shader_state,
_cogl_pipeline_layer_get_texture_type (layer);
const char *target_string, *tex_coord_swizzle;
- switch (texture_type)
- {
-#if 0 /* TODO */
- case COGL_TEXTURE_TYPE_1D:
- target_string = "1D";
- tex_coord_swizzle = "s";
- break;
-#endif
-
- case COGL_TEXTURE_TYPE_2D:
- target_string = "2D";
- tex_coord_swizzle = "st";
- break;
-
- case COGL_TEXTURE_TYPE_3D:
- target_string = "3D";
- tex_coord_swizzle = "stp";
- break;
-
- case COGL_TEXTURE_TYPE_RECTANGLE:
- target_string = "2DRect";
- tex_coord_swizzle = "st";
- break;
- }
-
- /* Create a sampler uniform */
- if (G_LIKELY (!COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_TEXTURING)))
- g_string_append_printf (shader_state->header,
- "uniform sampler%s _cogl_sampler_%i;\n",
- target_string,
- layer->index);
+ get_texture_target_string (texture_type,
+ &target_string,
+ &tex_coord_swizzle);
g_string_append_printf (shader_state->header,
"vec4\n"
@@ -468,7 +478,7 @@ ensure_texture_lookup_generated (CoglPipelineShaderState *shader_state,
"vec4 (1.0, 1.0, 1.0, 1.0);\n");
else
g_string_append_printf (shader_state->header,
- "texture%s (_cogl_sampler_%i, coords.%s);\n",
+ "texture%s (cogl_sampler%i, coords.%s);\n",
target_string, layer->index, tex_coord_swizzle);
g_string_append (shader_state->header, "}\n");
@@ -1014,6 +1024,24 @@ _cogl_pipeline_fragend_glsl_end (CoglPipeline *pipeline,
CoglPipelineLayer *last_layer;
LayerData *layer_data, *tmp;
+ /* We always emit sampler uniforms in case there will be custom
+ * layer snippets that want to sample arbitrary layers. */
+
+ COGL_LIST_FOREACH (layer_data, &shader_state->layers, list_node)
+ {
+ CoglPipelineLayer *layer = layer_data->layer;
+ CoglTextureType texture_type =
+ _cogl_pipeline_layer_get_texture_type (layer);
+ const char *target_string;
+
+ get_texture_target_string (texture_type, &target_string, NULL);
+
+ g_string_append_printf (shader_state->header,
+ "uniform sampler%s cogl_sampler%i;\n",
+ target_string,
+ layer->index);
+ }
+
last_layer = COGL_LIST_FIRST (&shader_state->layers)->layer;
ensure_layer_generated (pipeline, last_layer->index);
diff --git a/cogl/cogl-pipeline-progend-glsl.c b/cogl/cogl-pipeline-progend-glsl.c
index a0153a6e..b03c0ec2 100644
--- a/cogl/cogl-pipeline-progend-glsl.c
+++ b/cogl/cogl-pipeline-progend-glsl.c
@@ -371,7 +371,7 @@ get_uniform_cb (CoglPipeline *pipeline,
the program has now been linked */
g_string_set_size (ctx->codegen_source_buffer, 0);
g_string_append_printf (ctx->codegen_source_buffer,
- "_cogl_sampler_%i", layer_index);
+ "cogl_sampler%i", layer_index);
GE_RET( uniform_location,
ctx, glGetUniformLocation (state->gl_program,