2011-11-17 11:52:50 -05:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "test-utils.h"
|
|
|
|
|
|
|
|
typedef struct _TestState
|
|
|
|
{
|
2013-02-26 12:52:20 -05:00
|
|
|
int fb_width, fb_height;
|
2011-11-17 11:52:50 -05:00
|
|
|
} TestState;
|
|
|
|
|
2012-02-10 11:33:10 -05:00
|
|
|
typedef void (* SnippetTestFunc) (TestState *state);
|
|
|
|
|
2011-11-25 12:36:03 -05:00
|
|
|
static CoglPipeline *
|
2012-02-18 11:03:10 -05:00
|
|
|
create_texture_pipeline (TestState *state)
|
2011-11-25 12:36:03 -05:00
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
2012-03-16 15:54:13 -04:00
|
|
|
CoglTexture *tex;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static const uint8_t tex_data[] =
|
2011-11-25 12:36:03 -05:00
|
|
|
{
|
|
|
|
0xff, 0x00, 0x00, 0xff, /* red */ 0x00, 0xff, 0x00, 0xff, /* green */
|
|
|
|
0x00, 0x00, 0xff, 0xff, /* blue */ 0xff, 0xff, 0x00, 0xff, /* yellow */
|
|
|
|
};
|
|
|
|
|
2013-06-08 20:09:04 -04:00
|
|
|
tex = test_utils_texture_new_from_data (test_ctx,
|
|
|
|
2, 2, /* width/height */
|
|
|
|
TEST_UTILS_TEXTURE_NO_ATLAS,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
COGL_PIXEL_FORMAT_ANY,
|
|
|
|
8, /* rowstride */
|
|
|
|
tex_data);
|
2011-11-25 12:36:03 -05:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-11-25 12:36:03 -05:00
|
|
|
|
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, tex);
|
|
|
|
|
|
|
|
cogl_pipeline_set_layer_filters (pipeline, 0,
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST,
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST);
|
|
|
|
|
2012-03-16 15:54:13 -04:00
|
|
|
cogl_object_unref (tex);
|
2011-11-25 12:36:03 -05:00
|
|
|
|
|
|
|
return pipeline;
|
|
|
|
}
|
|
|
|
|
2011-11-17 11:52:50 -05:00
|
|
|
static void
|
2012-02-10 11:33:10 -05:00
|
|
|
simple_fragment_snippet (TestState *state)
|
2011-11-17 11:52:50 -05:00
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
|
|
|
/* Simple fragment snippet */
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-11-17 11:52:50 -05:00
|
|
|
|
|
|
|
cogl_pipeline_set_color4ub (pipeline, 255, 0, 0, 255);
|
|
|
|
|
2011-11-25 15:54:14 -05:00
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
|
|
|
|
NULL, /* declarations */
|
|
|
|
"cogl_color_out.g += 1.0;");
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
2011-11-17 11:52:50 -05:00
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0, 0, 10, 10);
|
2011-11-17 11:52:50 -05:00
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 5, 5, 0xffff00ff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
simple_vertex_snippet (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
2011-11-17 11:52:50 -05:00
|
|
|
/* Simple vertex snippet */
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-11-17 11:52:50 -05:00
|
|
|
|
|
|
|
cogl_pipeline_set_color4ub (pipeline, 255, 0, 0, 255);
|
|
|
|
|
2011-11-25 15:54:14 -05:00
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX,
|
|
|
|
NULL,
|
|
|
|
"cogl_color_out.b += 1.0;");
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
2011-11-17 11:52:50 -05:00
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 10, 0, 20, 10);
|
2011-11-17 11:52:50 -05:00
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 15, 5, 0xff00ffff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shared_uniform (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
int location;
|
|
|
|
|
2011-11-25 15:54:14 -05:00
|
|
|
/* Snippets sharing a uniform across the vertex and fragment
|
|
|
|
hooks */
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-11-17 11:52:50 -05:00
|
|
|
|
|
|
|
location = cogl_pipeline_get_uniform_location (pipeline, "a_value");
|
|
|
|
cogl_pipeline_set_uniform_1f (pipeline, location, 0.25f);
|
|
|
|
|
|
|
|
cogl_pipeline_set_color4ub (pipeline, 255, 0, 0, 255);
|
|
|
|
|
2011-11-25 15:54:14 -05:00
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX,
|
|
|
|
"uniform float a_value;",
|
2011-11-17 11:52:50 -05:00
|
|
|
"cogl_color_out.b += a_value;");
|
2011-11-25 15:54:14 -05:00
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
|
|
|
|
"uniform float a_value;",
|
|
|
|
"cogl_color_out.b += a_value;");
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
2011-11-17 11:52:50 -05:00
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb,
|
2012-03-16 15:54:13 -04:00
|
|
|
pipeline,
|
|
|
|
20, 0, 30, 10);
|
2011-11-17 11:52:50 -05:00
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 25, 5, 0xff0080ff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lots_snippets (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
int location;
|
|
|
|
int i;
|
|
|
|
|
2011-11-17 11:52:50 -05:00
|
|
|
/* Lots of snippets on one pipeline */
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-11-17 11:52:50 -05:00
|
|
|
|
|
|
|
cogl_pipeline_set_color4ub (pipeline, 0, 0, 0, 255);
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
char letter = 'x' + i;
|
|
|
|
char *uniform_name = g_strdup_printf ("%c_value", letter);
|
|
|
|
char *declarations = g_strdup_printf ("uniform float %s;\n",
|
|
|
|
uniform_name);
|
|
|
|
char *code = g_strdup_printf ("cogl_color_out.%c = %s;\n",
|
|
|
|
letter,
|
|
|
|
uniform_name);
|
|
|
|
|
|
|
|
location = cogl_pipeline_get_uniform_location (pipeline, uniform_name);
|
|
|
|
cogl_pipeline_set_uniform_1f (pipeline, location, (i + 1) * 0.1f);
|
|
|
|
|
2011-11-25 15:54:14 -05:00
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
|
|
|
|
declarations,
|
|
|
|
code);
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
2011-11-17 11:52:50 -05:00
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
|
|
|
g_free (code);
|
|
|
|
g_free (uniform_name);
|
|
|
|
g_free (declarations);
|
|
|
|
}
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 30, 0, 40, 10);
|
2011-11-17 11:52:50 -05:00
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 35, 5, 0x19334cff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shared_variable_pre_post (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
2011-11-25 08:41:13 -05:00
|
|
|
/* Test that the pre string can declare variables used by the post
|
|
|
|
string */
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-11-17 11:52:50 -05:00
|
|
|
|
2011-11-25 08:41:13 -05:00
|
|
|
cogl_pipeline_set_color4ub (pipeline, 255, 255, 255, 255);
|
2011-11-17 11:52:50 -05:00
|
|
|
|
2011-11-25 15:54:14 -05:00
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
|
|
|
|
NULL, /* declarations */
|
|
|
|
"cogl_color_out = redvec;");
|
2011-11-25 08:41:13 -05:00
|
|
|
cogl_snippet_set_pre (snippet, "vec4 redvec = vec4 (1.0, 0.0, 0.0, 1.0);");
|
2011-11-25 15:54:14 -05:00
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
2011-11-17 11:52:50 -05:00
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 40, 0, 50, 10);
|
2011-11-17 11:52:50 -05:00
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 45, 5, 0xff0000ff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_pipeline_caching (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
2011-11-17 11:52:50 -05:00
|
|
|
/* Check that the pipeline caching works when unrelated pipelines
|
|
|
|
share snippets state. It's too hard to actually assert this in
|
|
|
|
the conformance test but at least it should be possible to see by
|
|
|
|
setting COGL_DEBUG=show-source to check whether this shader gets
|
|
|
|
generated twice */
|
2011-11-25 15:54:14 -05:00
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
|
|
|
|
"/* This comment should only be seen ONCE\n"
|
2011-11-17 11:52:50 -05:00
|
|
|
" when COGL_DEBUG=show-source is TRUE\n"
|
|
|
|
" even though it is used in two different\n"
|
|
|
|
" unrelated pipelines */",
|
|
|
|
"cogl_color_out = vec4 (0.0, 1.0, 0.0, 1.0);\n");
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-11-25 15:54:14 -05:00
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 50, 0, 60, 10);
|
2011-11-17 11:52:50 -05:00
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-11-25 15:54:14 -05:00
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 60, 0, 70, 10);
|
2011-11-17 11:52:50 -05:00
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 55, 5, 0x00ff00ff);
|
|
|
|
test_utils_check_pixel (test_fb, 65, 5, 0x00ff00ff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_replace_string (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
2011-11-25 09:36:31 -05:00
|
|
|
/* Check the replace string */
|
2011-11-25 15:54:14 -05:00
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT, NULL, NULL);
|
2011-11-25 09:36:31 -05:00
|
|
|
cogl_snippet_set_pre (snippet,
|
|
|
|
"cogl_color_out = vec4 (0.0, 0.5, 0.0, 1.0);");
|
|
|
|
/* Remove the generated output. If the replace string isn't working
|
|
|
|
then the code from the pre string would get overwritten with
|
|
|
|
white */
|
|
|
|
cogl_snippet_set_replace (snippet, "/* do nothing */");
|
|
|
|
cogl_snippet_set_post (snippet,
|
|
|
|
"cogl_color_out += vec4 (0.5, 0.0, 0.0, 1.0);");
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-11-25 15:54:14 -05:00
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 70, 0, 80, 10);
|
2011-11-25 09:36:31 -05:00
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 75, 5, 0x808000ff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_texture_lookup_hook (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
2011-11-25 12:36:03 -05:00
|
|
|
/* Check the texture lookup hook */
|
2011-11-25 15:54:14 -05:00
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_TEXTURE_LOOKUP,
|
|
|
|
NULL,
|
2011-11-25 12:36:03 -05:00
|
|
|
"cogl_texel.b += 1.0;");
|
|
|
|
/* Flip the texture coordinates around the y axis so that it will
|
|
|
|
get the green texel */
|
|
|
|
cogl_snippet_set_pre (snippet, "cogl_tex_coord.x = 1.0 - cogl_tex_coord.x;");
|
|
|
|
|
2012-02-18 11:03:10 -05:00
|
|
|
pipeline = create_texture_pipeline (state);
|
2011-11-25 15:54:14 -05:00
|
|
|
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_textured_rectangle (test_fb,
|
2012-03-16 15:54:13 -04:00
|
|
|
pipeline,
|
|
|
|
80, 0, 90, 10,
|
|
|
|
0, 0, 0, 0);
|
2011-11-25 12:36:03 -05:00
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 85, 5, 0x00ffffff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
2012-02-10 11:44:57 -05:00
|
|
|
static void
|
|
|
|
test_multiple_samples (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
|
|
|
/* Check that we can use the passed in sampler in the texture lookup
|
|
|
|
to sample multiple times */
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_TEXTURE_LOOKUP,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
cogl_snippet_set_replace (snippet,
|
|
|
|
"cogl_texel = "
|
|
|
|
"texture2D (cogl_sampler, vec2 (0.25, 0.25)) + "
|
|
|
|
"texture2D (cogl_sampler, vec2 (0.75, 0.25));");
|
|
|
|
|
2012-02-18 11:03:10 -05:00
|
|
|
pipeline = create_texture_pipeline (state);
|
2012-02-10 11:44:57 -05:00
|
|
|
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0, 0, 10, 10);
|
2012-02-10 11:44:57 -05:00
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 5, 5, 0xffff00ff);
|
2012-02-10 11:44:57 -05:00
|
|
|
}
|
|
|
|
|
2012-02-10 11:33:10 -05:00
|
|
|
static void
|
|
|
|
test_replace_lookup_hook (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
2011-11-25 17:02:53 -05:00
|
|
|
/* Check replacing the texture lookup hook */
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_TEXTURE_LOOKUP, NULL, NULL);
|
|
|
|
cogl_snippet_set_replace (snippet, "cogl_texel = vec4 (0.0, 0.0, 1.0, 0.0);");
|
|
|
|
|
2012-02-18 11:03:10 -05:00
|
|
|
pipeline = create_texture_pipeline (state);
|
2011-11-25 17:02:53 -05:00
|
|
|
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_textured_rectangle (test_fb,
|
2012-03-16 15:54:13 -04:00
|
|
|
pipeline,
|
|
|
|
90, 0, 100, 10,
|
|
|
|
0, 0, 0, 0);
|
2011-11-25 17:02:53 -05:00
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 95, 5, 0x0000ffff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_replace_snippet (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
2011-11-25 16:57:05 -05:00
|
|
|
/* Test replacing a previous snippet */
|
2012-02-18 11:03:10 -05:00
|
|
|
pipeline = create_texture_pipeline (state);
|
2011-11-25 16:57:05 -05:00
|
|
|
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
|
|
|
|
NULL,
|
|
|
|
"cogl_color_out = vec4 (0.5, 0.5, 0.5, 1.0);");
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT, NULL, NULL);
|
|
|
|
cogl_snippet_set_pre (snippet, "cogl_color_out = vec4 (1.0, 1.0, 1.0, 1.0);");
|
|
|
|
cogl_snippet_set_replace (snippet,
|
|
|
|
"cogl_color_out *= vec4 (1.0, 0.0, 0.0, 1.0);");
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_textured_rectangle (test_fb,
|
2012-03-16 15:54:13 -04:00
|
|
|
pipeline,
|
|
|
|
100, 0, 110, 10,
|
|
|
|
0, 0, 0, 0);
|
2011-11-25 16:57:05 -05:00
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 105, 5, 0xff0000ff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_replace_fragment_layer (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
2011-11-28 14:58:15 -05:00
|
|
|
/* Test replacing the fragment layer code */
|
2012-02-18 11:03:10 -05:00
|
|
|
pipeline = create_texture_pipeline (state);
|
2011-11-25 18:16:31 -05:00
|
|
|
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_LAYER_FRAGMENT, NULL, NULL);
|
|
|
|
cogl_snippet_set_replace (snippet, "cogl_layer = vec4 (0.0, 0.0, 1.0, 1.0);");
|
|
|
|
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
|
|
|
/* Add a second layer which samples from the texture in the first
|
|
|
|
layer. The snippet override should cause the first layer not to
|
|
|
|
generate the code for the texture lookup but this second layer
|
|
|
|
should still be able to cause it to be generated */
|
|
|
|
cogl_pipeline_set_layer_combine (pipeline, 1,
|
|
|
|
"RGB = ADD(TEXTURE_0, PREVIOUS)"
|
|
|
|
"A = REPLACE(PREVIOUS)",
|
|
|
|
NULL);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_textured_rectangle (test_fb,
|
2012-03-16 15:54:13 -04:00
|
|
|
pipeline,
|
|
|
|
110, 0, 120, 10,
|
|
|
|
0, 0, 0, 0);
|
2011-11-25 18:16:31 -05:00
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 115, 5, 0xff00ffff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_modify_fragment_layer (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
2011-11-28 14:58:15 -05:00
|
|
|
/* Test modifying the fragment layer code */
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-11-25 18:16:31 -05:00
|
|
|
|
|
|
|
cogl_pipeline_set_uniform_1f (pipeline,
|
|
|
|
cogl_pipeline_get_uniform_location (pipeline,
|
|
|
|
"a_value"),
|
|
|
|
0.5);
|
|
|
|
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_LAYER_FRAGMENT,
|
|
|
|
"uniform float a_value;",
|
|
|
|
"cogl_layer.g = a_value;");
|
|
|
|
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_textured_rectangle (test_fb,
|
2012-03-16 15:54:13 -04:00
|
|
|
pipeline,
|
|
|
|
120, 0, 130, 10,
|
|
|
|
0, 0, 0, 0);
|
2011-11-25 18:16:31 -05:00
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 125, 5, 0xff80ffff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_modify_vertex_layer (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
CoglMatrix matrix;
|
|
|
|
|
2011-11-28 14:58:15 -05:00
|
|
|
/* Test modifying the vertex layer code */
|
2012-02-18 11:03:10 -05:00
|
|
|
pipeline = create_texture_pipeline (state);
|
2011-11-28 14:58:15 -05:00
|
|
|
|
|
|
|
cogl_matrix_init_identity (&matrix);
|
|
|
|
cogl_matrix_translate (&matrix, 0.0f, 1.0f, 0.0f);
|
|
|
|
cogl_pipeline_set_layer_matrix (pipeline, 0, &matrix);
|
|
|
|
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_TEXTURE_COORD_TRANSFORM,
|
|
|
|
NULL,
|
|
|
|
"cogl_tex_coord.x = 1.0;");
|
|
|
|
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_textured_rectangle (test_fb,
|
2012-03-16 15:54:13 -04:00
|
|
|
pipeline,
|
|
|
|
130, 0, 140, 10,
|
|
|
|
0, 0, 0, 0);
|
2011-11-28 14:58:15 -05:00
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 135, 5, 0xffff00ff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_replace_vertex_layer (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
CoglMatrix matrix;
|
|
|
|
|
2011-11-28 14:58:15 -05:00
|
|
|
/* Test replacing the vertex layer code */
|
2012-02-18 11:03:10 -05:00
|
|
|
pipeline = create_texture_pipeline (state);
|
2011-11-28 14:58:15 -05:00
|
|
|
|
|
|
|
cogl_matrix_init_identity (&matrix);
|
|
|
|
cogl_matrix_translate (&matrix, 0.0f, 1.0f, 0.0f);
|
|
|
|
cogl_pipeline_set_layer_matrix (pipeline, 0, &matrix);
|
|
|
|
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_TEXTURE_COORD_TRANSFORM,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
cogl_snippet_set_replace (snippet, "cogl_tex_coord.x = 1.0;\n");
|
|
|
|
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_textured_rectangle (test_fb,
|
2012-03-16 15:54:13 -04:00
|
|
|
pipeline,
|
|
|
|
140, 0, 150, 10,
|
|
|
|
0, 0, 0, 0);
|
2011-11-28 14:58:15 -05:00
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 145, 5, 0x00ff00ff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_vertex_transform_hook (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
CoglMatrix identity_matrix;
|
|
|
|
CoglMatrix matrix;
|
|
|
|
int location;
|
|
|
|
|
2011-11-28 17:06:53 -05:00
|
|
|
/* Test the vertex transform hook */
|
2012-02-10 11:33:10 -05:00
|
|
|
|
|
|
|
cogl_matrix_init_identity (&identity_matrix);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-11-28 17:06:53 -05:00
|
|
|
|
|
|
|
cogl_pipeline_set_color4ub (pipeline, 255, 0, 255, 255);
|
|
|
|
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX_TRANSFORM,
|
|
|
|
"uniform mat4 pmat;",
|
|
|
|
NULL);
|
|
|
|
cogl_snippet_set_replace (snippet, "cogl_position_out = "
|
|
|
|
"pmat * cogl_position_in;");
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
|
|
|
/* Copy the current projection matrix to a uniform */
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_get_projection_matrix (test_fb, &matrix);
|
2011-11-28 17:06:53 -05:00
|
|
|
location = cogl_pipeline_get_uniform_location (pipeline, "pmat");
|
|
|
|
cogl_pipeline_set_uniform_matrix (pipeline,
|
|
|
|
location,
|
|
|
|
4, /* dimensions */
|
|
|
|
1, /* count */
|
|
|
|
FALSE, /* don't transpose */
|
|
|
|
cogl_matrix_get_array (&matrix));
|
|
|
|
|
|
|
|
/* Replace the real projection matrix with the identity. This should
|
|
|
|
mess up the drawing unless the snippet replacement is working */
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_set_projection_matrix (test_fb, &identity_matrix);
|
2011-11-28 17:06:53 -05:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 150, 0, 160, 10);
|
2011-11-28 17:06:53 -05:00
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
|
|
|
/* Restore the projection matrix */
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_set_projection_matrix (test_fb, &matrix);
|
2011-11-28 17:06:53 -05:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 155, 5, 0xff00ffff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
2013-02-26 12:52:20 -05:00
|
|
|
static void
|
|
|
|
test_global_vertex_hook (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
|
|
|
|
|
|
|
/* Creates a function in the global declarations hook which is used
|
|
|
|
* by a subsequent snippet. The subsequent snippets replace any
|
|
|
|
* previous snippets but this shouldn't prevent the global
|
|
|
|
* declarations from being generated */
|
|
|
|
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX_GLOBALS,
|
|
|
|
/* declarations */
|
|
|
|
"float\n"
|
|
|
|
"multiply_by_two (float number)\n"
|
|
|
|
"{\n"
|
|
|
|
" return number * 2.0;\n"
|
|
|
|
"}\n",
|
|
|
|
/* post */
|
|
|
|
"This string shouldn't be used so "
|
|
|
|
"we can safely put garbage in here.");
|
|
|
|
cogl_snippet_set_pre (snippet,
|
|
|
|
"This string shouldn't be used so "
|
|
|
|
"we can safely put garbage in here.");
|
|
|
|
cogl_snippet_set_replace (snippet,
|
|
|
|
"This string shouldn't be used so "
|
|
|
|
"we can safely put garbage in here.");
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX,
|
|
|
|
NULL, /* declarations */
|
|
|
|
NULL /* replace */);
|
|
|
|
cogl_snippet_set_replace (snippet,
|
|
|
|
"cogl_color_out.r = multiply_by_two (0.5);\n"
|
|
|
|
"cogl_color_out.gba = vec3 (0.0, 0.0, 1.0);\n"
|
|
|
|
"cogl_position_out = cogl_position_in;\n");
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
|
|
|
cogl_framebuffer_draw_rectangle (test_fb,
|
|
|
|
pipeline,
|
|
|
|
-1, 1,
|
|
|
|
10.0f * 2.0f / state->fb_width - 1.0f,
|
|
|
|
10.0f * 2.0f / state->fb_height - 1.0f);
|
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
|
|
|
test_utils_check_pixel (test_fb, 5, 5, 0xff0000ff);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_global_fragment_hook (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
|
|
|
|
|
|
|
/* Creates a function in the global declarations hook which is used
|
|
|
|
* by a subsequent snippet. The subsequent snippets replace any
|
|
|
|
* previous snippets but this shouldn't prevent the global
|
|
|
|
* declarations from being generated */
|
|
|
|
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT_GLOBALS,
|
|
|
|
/* declarations */
|
|
|
|
"float\n"
|
|
|
|
"multiply_by_four (float number)\n"
|
|
|
|
"{\n"
|
|
|
|
" return number * 4.0;\n"
|
|
|
|
"}\n",
|
|
|
|
/* post */
|
|
|
|
"This string shouldn't be used so "
|
|
|
|
"we can safely put garbage in here.");
|
|
|
|
cogl_snippet_set_pre (snippet,
|
|
|
|
"This string shouldn't be used so "
|
|
|
|
"we can safely put garbage in here.");
|
|
|
|
cogl_snippet_set_replace (snippet,
|
|
|
|
"This string shouldn't be used so "
|
|
|
|
"we can safely put garbage in here.");
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
|
|
|
|
NULL, /* declarations */
|
|
|
|
NULL /* replace */);
|
|
|
|
cogl_snippet_set_replace (snippet,
|
|
|
|
"cogl_color_out.r = multiply_by_four (0.25);\n"
|
|
|
|
"cogl_color_out.gba = vec3 (0.0, 0.0, 1.0);\n");
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
|
|
|
cogl_framebuffer_draw_rectangle (test_fb,
|
|
|
|
pipeline,
|
|
|
|
0, 0, 10, 10);
|
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
|
|
|
test_utils_check_pixel (test_fb, 5, 5, 0xff0000ff);
|
|
|
|
}
|
|
|
|
|
2012-02-10 11:33:10 -05:00
|
|
|
static void
|
|
|
|
test_snippet_order (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
2011-12-06 07:14:07 -05:00
|
|
|
/* Verify that the snippets are executed in the right order. We'll
|
|
|
|
replace the r component of the color in the pre sections of the
|
|
|
|
snippets and the g component in the post. The pre sections should
|
|
|
|
be executed in the reverse order they were added and the post
|
|
|
|
sections in the same order as they were added. Therefore the r
|
|
|
|
component should be taken from the the second snippet and the g
|
|
|
|
component from the first */
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-12-06 07:14:07 -05:00
|
|
|
|
|
|
|
cogl_pipeline_set_color4ub (pipeline, 0, 0, 0, 255);
|
|
|
|
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
|
|
|
|
NULL,
|
|
|
|
"cogl_color_out.g = 0.5;\n");
|
|
|
|
cogl_snippet_set_pre (snippet, "cogl_color_out.r = 0.5;\n");
|
|
|
|
cogl_snippet_set_replace (snippet, "cogl_color_out.ba = vec2 (0.0, 1.0);");
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
|
|
|
|
NULL,
|
|
|
|
"cogl_color_out.g = 1.0;\n");
|
|
|
|
cogl_snippet_set_pre (snippet, "cogl_color_out.r = 1.0;\n");
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 160, 0, 170, 10);
|
2011-12-06 07:14:07 -05:00
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 165, 5, 0x80ff00ff);
|
2012-02-10 11:33:10 -05:00
|
|
|
}
|
|
|
|
|
2012-02-10 11:58:31 -05:00
|
|
|
static void
|
|
|
|
test_naming_texture_units (TestState *state)
|
|
|
|
{
|
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
CoglTexture *tex1, *tex2;
|
|
|
|
|
|
|
|
/* Test that we can sample from an arbitrary texture unit by naming
|
|
|
|
its layer number */
|
|
|
|
|
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
cogl_snippet_set_replace (snippet,
|
|
|
|
"cogl_color_out = "
|
|
|
|
"texture2D (cogl_sampler100, vec2 (0.0, 0.0)) + "
|
|
|
|
"texture2D (cogl_sampler200, vec2 (0.0, 0.0));");
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
tex1 = test_utils_create_color_texture (test_ctx, 0xff0000ff);
|
|
|
|
tex2 = test_utils_create_color_texture (test_ctx, 0x00ff00ff);
|
2012-02-10 11:58:31 -05:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2012-02-10 11:58:31 -05:00
|
|
|
|
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 100, tex1);
|
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 200, tex2);
|
|
|
|
|
|
|
|
cogl_pipeline_add_snippet (pipeline, snippet);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0, 0, 10, 10);
|
2012-02-10 11:58:31 -05:00
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
cogl_object_unref (snippet);
|
|
|
|
cogl_object_unref (tex1);
|
|
|
|
cogl_object_unref (tex2);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_pixel (test_fb, 5, 5, 0xffff00ff);
|
2012-02-10 11:58:31 -05:00
|
|
|
}
|
|
|
|
|
2012-02-10 11:33:10 -05:00
|
|
|
static void
|
|
|
|
test_snippet_properties (TestState *state)
|
|
|
|
{
|
|
|
|
CoglSnippet *snippet;
|
|
|
|
|
2011-11-17 11:52:50 -05:00
|
|
|
/* Sanity check modifying the snippet */
|
2011-11-25 15:54:14 -05:00
|
|
|
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT, "foo", "bar");
|
2011-11-17 11:52:50 -05:00
|
|
|
g_assert_cmpstr (cogl_snippet_get_declarations (snippet), ==, "foo");
|
|
|
|
g_assert_cmpstr (cogl_snippet_get_post (snippet), ==, "bar");
|
2011-11-25 09:36:31 -05:00
|
|
|
g_assert_cmpstr (cogl_snippet_get_replace (snippet), ==, NULL);
|
2011-11-17 11:52:50 -05:00
|
|
|
g_assert_cmpstr (cogl_snippet_get_pre (snippet), ==, NULL);
|
|
|
|
|
|
|
|
cogl_snippet_set_declarations (snippet, "fu");
|
|
|
|
g_assert_cmpstr (cogl_snippet_get_declarations (snippet), ==, "fu");
|
|
|
|
g_assert_cmpstr (cogl_snippet_get_post (snippet), ==, "bar");
|
2011-11-25 09:36:31 -05:00
|
|
|
g_assert_cmpstr (cogl_snippet_get_replace (snippet), ==, NULL);
|
2011-11-17 11:52:50 -05:00
|
|
|
g_assert_cmpstr (cogl_snippet_get_pre (snippet), ==, NULL);
|
|
|
|
|
|
|
|
cogl_snippet_set_post (snippet, "ba");
|
|
|
|
g_assert_cmpstr (cogl_snippet_get_declarations (snippet), ==, "fu");
|
|
|
|
g_assert_cmpstr (cogl_snippet_get_post (snippet), ==, "ba");
|
2011-11-25 09:36:31 -05:00
|
|
|
g_assert_cmpstr (cogl_snippet_get_replace (snippet), ==, NULL);
|
2011-11-17 11:52:50 -05:00
|
|
|
g_assert_cmpstr (cogl_snippet_get_pre (snippet), ==, NULL);
|
|
|
|
|
|
|
|
cogl_snippet_set_pre (snippet, "fuba");
|
|
|
|
g_assert_cmpstr (cogl_snippet_get_declarations (snippet), ==, "fu");
|
|
|
|
g_assert_cmpstr (cogl_snippet_get_post (snippet), ==, "ba");
|
2011-11-25 09:36:31 -05:00
|
|
|
g_assert_cmpstr (cogl_snippet_get_replace (snippet), ==, NULL);
|
|
|
|
g_assert_cmpstr (cogl_snippet_get_pre (snippet), ==, "fuba");
|
|
|
|
|
|
|
|
cogl_snippet_set_replace (snippet, "baba");
|
|
|
|
g_assert_cmpstr (cogl_snippet_get_declarations (snippet), ==, "fu");
|
|
|
|
g_assert_cmpstr (cogl_snippet_get_post (snippet), ==, "ba");
|
|
|
|
g_assert_cmpstr (cogl_snippet_get_replace (snippet), ==, "baba");
|
2011-11-17 11:52:50 -05:00
|
|
|
g_assert_cmpstr (cogl_snippet_get_pre (snippet), ==, "fuba");
|
2011-11-25 15:54:14 -05:00
|
|
|
|
|
|
|
g_assert_cmpint (cogl_snippet_get_hook (snippet),
|
|
|
|
==,
|
|
|
|
COGL_SNIPPET_HOOK_FRAGMENT);
|
2011-11-17 11:52:50 -05:00
|
|
|
}
|
|
|
|
|
2012-02-10 11:33:10 -05:00
|
|
|
static SnippetTestFunc
|
|
|
|
tests[] =
|
|
|
|
{
|
|
|
|
simple_fragment_snippet,
|
|
|
|
simple_vertex_snippet,
|
|
|
|
shared_uniform,
|
|
|
|
lots_snippets,
|
|
|
|
shared_variable_pre_post,
|
|
|
|
test_pipeline_caching,
|
|
|
|
test_replace_string,
|
|
|
|
test_texture_lookup_hook,
|
2012-02-10 11:44:57 -05:00
|
|
|
test_multiple_samples,
|
2012-02-10 11:33:10 -05:00
|
|
|
test_replace_lookup_hook,
|
|
|
|
test_replace_snippet,
|
|
|
|
test_replace_fragment_layer,
|
|
|
|
test_modify_fragment_layer,
|
|
|
|
test_modify_vertex_layer,
|
|
|
|
test_replace_vertex_layer,
|
|
|
|
test_vertex_transform_hook,
|
2013-02-26 12:52:20 -05:00
|
|
|
test_global_fragment_hook,
|
|
|
|
test_global_vertex_hook,
|
2012-02-10 11:33:10 -05:00
|
|
|
test_snippet_order,
|
2012-02-10 11:58:31 -05:00
|
|
|
test_naming_texture_units,
|
2012-02-10 11:33:10 -05:00
|
|
|
test_snippet_properties
|
|
|
|
};
|
|
|
|
|
2011-11-17 11:52:50 -05:00
|
|
|
static void
|
2012-02-10 11:33:10 -05:00
|
|
|
run_tests (TestState *state)
|
2011-11-17 11:52:50 -05:00
|
|
|
{
|
2012-02-10 11:33:10 -05:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (tests); i++)
|
|
|
|
{
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_clear4f (test_fb,
|
2012-02-10 11:33:10 -05:00
|
|
|
COGL_BUFFER_BIT_COLOR,
|
|
|
|
0, 0, 0, 1);
|
|
|
|
|
|
|
|
tests[i] (state);
|
|
|
|
}
|
2011-11-17 11:52:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 15:54:13 -04:00
|
|
|
test_snippets (void)
|
2011-11-17 11:52:50 -05:00
|
|
|
{
|
2012-11-09 10:14:33 -05:00
|
|
|
TestState state;
|
2011-11-17 11:52:50 -05:00
|
|
|
|
2013-02-26 12:52:20 -05:00
|
|
|
state.fb_width = cogl_framebuffer_get_width (test_fb);
|
|
|
|
state.fb_height = cogl_framebuffer_get_height (test_fb);
|
|
|
|
|
2012-11-09 10:14:33 -05:00
|
|
|
cogl_framebuffer_orthographic (test_fb,
|
|
|
|
0, 0,
|
2013-02-26 12:52:20 -05:00
|
|
|
state.fb_width,
|
|
|
|
state.fb_height,
|
2012-11-09 10:14:33 -05:00
|
|
|
-1,
|
|
|
|
100);
|
2011-11-17 11:52:50 -05:00
|
|
|
|
2012-11-09 10:14:33 -05:00
|
|
|
run_tests (&state);
|
2011-11-17 11:52:50 -05:00
|
|
|
|
2012-11-09 10:14:33 -05:00
|
|
|
if (cogl_test_verbose ())
|
|
|
|
g_print ("OK\n");
|
2011-11-17 11:52:50 -05:00
|
|
|
}
|