[cogl/fosdem-2012: 4/17] glsl: always emit sampler uniforms for non NULL layers
- From: Neil Roberts <nroberts src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/fosdem-2012: 4/17] glsl: always emit sampler uniforms for non NULL layers
- Date: Wed, 4 Jan 2012 20:56:42 +0000 (UTC)
commit ce4186b09bcc6e95b0bdcced602f4756cde3fe51
Author: Robert Bragg <robert linux intel com>
Date: Tue Jan 3 11:42:42 2012 +0000
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.
cogl/cogl-pipeline-fragend-glsl.c | 126 ++++++++++++++++++++++---------------
cogl/cogl-pipeline-progend-glsl.c | 2 +-
2 files changed, 76 insertions(+), 52 deletions(-)
---
diff --git a/cogl/cogl-pipeline-fragend-glsl.c b/cogl/cogl-pipeline-fragend-glsl.c
index 890e3b1..4ad3614 100644
--- a/cogl/cogl-pipeline-fragend-glsl.c
+++ b/cogl/cogl-pipeline-fragend-glsl.c
@@ -374,6 +374,59 @@ add_constant_lookup (CoglPipelineShaderState *shader_state,
unit_index, swizzle);
}
+static const char *
+get_texture_target_string (CoglTexture *texture,
+ const char **swizzle)
+{
+ const char *target_string, *tex_coord_swizzle;
+
+ if (texture == NULL)
+ {
+ target_string = "2D";
+ tex_coord_swizzle = "st";
+ }
+ else
+ {
+ GLenum gl_target;
+
+ cogl_texture_get_gl_texture (texture, NULL, &gl_target);
+ switch (gl_target)
+ {
+#ifdef HAVE_COGL_GL
+ case GL_TEXTURE_1D:
+ target_string = "1D";
+ tex_coord_swizzle = "s";
+ break;
+#endif
+
+ case GL_TEXTURE_2D:
+ target_string = "2D";
+ tex_coord_swizzle = "st";
+ break;
+
+#ifdef GL_ARB_texture_rectangle
+ case GL_TEXTURE_RECTANGLE_ARB:
+ target_string = "2DRect";
+ tex_coord_swizzle = "st";
+ break;
+#endif
+
+ case GL_TEXTURE_3D:
+ target_string = "3D";
+ tex_coord_swizzle = "stp";
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+ }
+
+ if (swizzle)
+ *swizzle = tex_coord_swizzle;
+
+ return target_string;
+}
+
static void
ensure_texture_lookup_generated (CoglPipelineShaderState *shader_state,
CoglPipeline *pipeline,
@@ -422,56 +475,10 @@ ensure_texture_lookup_generated (CoglPipelineShaderState *shader_state,
to be replaced */
if (!has_replace_hook (layer, COGL_SNIPPET_HOOK_TEXTURE_LOOKUP))
{
- CoglHandle texture = _cogl_pipeline_layer_get_texture (layer);
- const char *target_string, *tex_coord_swizzle;
-
- if (texture == NULL)
- {
- target_string = "2D";
- tex_coord_swizzle = "st";
- }
- else
- {
- GLenum gl_target;
-
- cogl_texture_get_gl_texture (texture, NULL, &gl_target);
- switch (gl_target)
- {
-#ifdef HAVE_COGL_GL
- case GL_TEXTURE_1D:
- target_string = "1D";
- tex_coord_swizzle = "s";
- break;
-#endif
-
- case GL_TEXTURE_2D:
- target_string = "2D";
- tex_coord_swizzle = "st";
- break;
-
-#ifdef GL_ARB_texture_rectangle
- case GL_TEXTURE_RECTANGLE_ARB:
- target_string = "2DRect";
- tex_coord_swizzle = "st";
- break;
-#endif
-
- case GL_TEXTURE_3D:
- target_string = "3D";
- tex_coord_swizzle = "stp";
- break;
-
- default:
- g_assert_not_reached ();
- }
- }
-
- /* 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,
- unit_index);
+ CoglTexture *texture = _cogl_pipeline_layer_get_texture (layer);
+ const char *tex_coord_swizzle;
+ const char *target_string =
+ get_texture_target_string (texture, &tex_coord_swizzle);
g_string_append_printf (shader_state->header,
"vec4\n"
@@ -485,7 +492,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, unit_index, tex_coord_swizzle);
g_string_append (shader_state->header, "}\n");
@@ -1041,6 +1048,23 @@ _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;
+ int unit_index = _cogl_pipeline_layer_get_unit_index (layer);
+ CoglTexture *texture = _cogl_pipeline_layer_get_texture (layer);
+ const char *target_string =
+ get_texture_target_string (texture, NULL);
+
+ g_string_append_printf (shader_state->header,
+ "uniform sampler%s cogl_sampler%i;\n",
+ target_string,
+ unit_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 561ea3e..28d2388 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", state->unit);
+ "cogl_sampler%i", state->unit);
GE_RET( uniform_location,
ctx, glGetUniformLocation (state->gl_program,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]