Cache the debug wireframe snippet

When rendering the debug wireframe Cogl generates a child pipeline of
the application's pipeline to replace the fragment processing.
Previously it was creating a new snippet every time something was
drawn. Cogl doesn't attempt to compare the contents of snippets when
looking in the program cache for a matching pipeline so this would
cause it to generate a new program for every primitive. It then quite
quickly ends printing the warning about there being more than 50
programs in the cache. To fix that this patch makes it cache the
snippet so that Cogl can successfully recognise that it already has a
program generated for the new pipeline.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit c4bb08ee8767b5320980dba10b20921393cb5613)
This commit is contained in:
Neil Roberts 2012-05-19 23:07:17 +01:00 committed by Robert Bragg
parent 1357c4c6a6
commit 67a095b9dd

View File

@ -3277,15 +3277,21 @@ draw_wireframe (CoglContext *ctx,
* of the wire color leaving the rest of the state untouched. */ * of the wire color leaving the rest of the state untouched. */
if (cogl_has_feature (framebuffer->context, COGL_FEATURE_ID_GLSL)) if (cogl_has_feature (framebuffer->context, COGL_FEATURE_ID_GLSL))
{ {
CoglSnippet *snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT, static CoglSnippet *snippet = NULL;
/* The snippet is cached so that it will reuse the program
* from the pipeline cache if possible */
if (snippet == NULL)
{
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
NULL, NULL,
NULL); NULL);
cogl_snippet_set_replace (snippet, cogl_snippet_set_replace (snippet,
"cogl_color_out = " "cogl_color_out = "
"vec4 (0.0, 1.0, 0.0, 1.0);\n"); "vec4 (0.0, 1.0, 0.0, 1.0);\n");
}
cogl_pipeline_add_snippet (wire_pipeline, snippet); cogl_pipeline_add_snippet (wire_pipeline, snippet);
cogl_object_unref (snippet);
} }
else else
{ {