Add fragment and vertex snippet hooks for global declarations

This adds hook points to add global function and variable declarations
to either the fragment or vertex shader. The declarations can then be
used by subsequent snippets. Only the ‘declarations’ string of the
snippet is used and the code is directly put in the global scope near
the top of the shader.

The reason this is necessary rather than just adding a normal snippet
with the declarations is that for the other hooks Cogl assumes that
the snippets are independent of each other. That means if a snippet
has a replace string then it will assume that it doesn't even need to
generate the code for earlier hooks which means the global
declarations would be lost.

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

(cherry picked from commit ebb82d5b0bc30487b7101dc66b769160b40f92ca)
This commit is contained in:
Neil Roberts
2013-02-26 17:52:20 +00:00
parent bd1e3e7642
commit 956d39ac30
6 changed files with 204 additions and 8 deletions

View File

@ -3,7 +3,7 @@
*
* An object oriented GL/GLES Abstraction/Utility Layer
*
* Copyright (C) 2011 Intel Corporation.
* Copyright (C) 2011, 2013 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -183,6 +183,23 @@ _cogl_pipeline_snippet_generate_code (const CoglPipelineSnippetData *data)
}
}
void
_cogl_pipeline_snippet_generate_declarations (GString *declarations_buf,
CoglSnippetHook hook,
CoglPipelineSnippetList *snippets)
{
CoglPipelineSnippet *snippet;
COGL_LIST_FOREACH (snippet, snippets, list_node)
if (snippet->snippet->hook == hook)
{
const char *source;
if ((source = cogl_snippet_get_declarations (snippet->snippet)))
g_string_append (declarations_buf, source);
}
}
static void
_cogl_pipeline_snippet_free (CoglPipelineSnippet *pipeline_snippet)
{