pipeline: Add a snippet hook for the texture lookup

This adds a per-layer snippet hook for the texure lookup. Here the
snippet can modify the texture coordinates used for the lookup or
modify the texel resulting from the lookup. This is the first
per-layer hook so this also adds the
COGL_PIPELINE_LAYER_STATE_FRAGMENT_SNIPPETS state and all of the
boilerplate needed to make that work.

Most of the functions used by the pipeline state to manage the snippet
list has been moved into cogl-pipeline-snippet.c so that it can be
shared with the layer state.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
Neil Roberts
2011-11-25 17:36:03 +00:00
committed by Robert Bragg
parent 4cdf66f89b
commit df0f9a862f
11 changed files with 420 additions and 148 deletions

View File

@ -32,6 +32,8 @@
#include <string.h>
#include "cogl-pipeline-snippet-private.h"
#include "cogl-snippet-private.h"
#include "cogl-util.h"
/* Helper functions that are used by both GLSL pipeline backends */
@ -158,3 +160,101 @@ _cogl_pipeline_snippet_generate_code (const CoglPipelineSnippetData *data)
data->arguments ? data->arguments : "");
}
}
static void
_cogl_pipeline_snippet_free (CoglPipelineSnippet *pipeline_snippet)
{
cogl_object_unref (pipeline_snippet->snippet);
g_slice_free (CoglPipelineSnippet, pipeline_snippet);
}
void
_cogl_pipeline_snippet_list_free (CoglPipelineSnippetList *list)
{
CoglPipelineSnippet *pipeline_snippet, *tmp;
COGL_LIST_FOREACH_SAFE (pipeline_snippet, list, list_node, tmp)
_cogl_pipeline_snippet_free (pipeline_snippet);
}
void
_cogl_pipeline_snippet_list_add (CoglPipelineSnippetList *list,
CoglPipelineSnippetHook hook,
CoglSnippet *snippet)
{
CoglPipelineSnippet *pipeline_snippet = g_slice_new (CoglPipelineSnippet);
pipeline_snippet->hook = hook;
pipeline_snippet->snippet = cogl_object_ref (snippet);
_cogl_snippet_make_immutable (pipeline_snippet->snippet);
if (COGL_LIST_EMPTY (list))
COGL_LIST_INSERT_HEAD (list, pipeline_snippet, list_node);
else
{
CoglPipelineSnippet *tail;
for (tail = COGL_LIST_FIRST (list);
COGL_LIST_NEXT (tail, list_node);
tail = COGL_LIST_NEXT (tail, list_node));
COGL_LIST_INSERT_AFTER (tail, pipeline_snippet, list_node);
}
}
void
_cogl_pipeline_snippet_list_copy (CoglPipelineSnippetList *dst,
const CoglPipelineSnippetList *src)
{
CoglPipelineSnippet *tail = NULL;
const CoglPipelineSnippet *l;
COGL_LIST_INIT (dst);
COGL_LIST_FOREACH (l, src, list_node)
{
CoglPipelineSnippet *copy = g_slice_dup (CoglPipelineSnippet, l);
cogl_object_ref (copy->snippet);
if (tail)
COGL_LIST_INSERT_AFTER (tail, copy, list_node);
else
COGL_LIST_INSERT_HEAD (dst, copy, list_node);
tail = copy;
}
}
void
_cogl_pipeline_snippet_list_hash (CoglPipelineSnippetList *list,
unsigned int *hash)
{
CoglPipelineSnippet *l;
COGL_LIST_FOREACH (l, list, list_node)
{
*hash = _cogl_util_one_at_a_time_hash (*hash,
&l->hook,
sizeof (CoglPipelineSnippetHook));
*hash = _cogl_util_one_at_a_time_hash (*hash,
&l->snippet,
sizeof (CoglSnippet *));
}
}
gboolean
_cogl_pipeline_snippet_list_equal (CoglPipelineSnippetList *list0,
CoglPipelineSnippetList *list1)
{
CoglPipelineSnippet *l0, *l1;
for (l0 = COGL_LIST_FIRST (list0), l1 = COGL_LIST_FIRST (list1);
l0 && l1;
l0 = COGL_LIST_NEXT (l0, list_node), l1 = COGL_LIST_NEXT (l1, list_node))
if (l0->hook != l1->hook || l0->snippet != l1->snippet)
return FALSE;
return l0 == NULL && l1 == NULL;
}