From 6320aab9b4af9325a0fae1955b44b6008cf80c92 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 6 Dec 2011 12:14:07 +0000 Subject: [PATCH] test-snippets: Add a test to verify the order of the snippets This verifies that the post strings are executed in the order they were added to the pipeline and the post strings are executed in the reverse order. Reviewed-by: Robert Bragg --- tests/conform/test-snippets.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/conform/test-snippets.c b/tests/conform/test-snippets.c index 35e7d070c..8a0339194 100644 --- a/tests/conform/test-snippets.c +++ b/tests/conform/test-snippets.c @@ -388,6 +388,37 @@ paint (TestState *state) /* Restore the projection matrix */ cogl_set_projection_matrix (&matrix); + /* 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 */ + pipeline = cogl_pipeline_new (); + + 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); + + cogl_push_source (pipeline); + cogl_rectangle (160, 0, 170, 10); + cogl_pop_source (); + cogl_object_unref (pipeline); + /* Sanity check modifying the snippet */ snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT, "foo", "bar"); g_assert_cmpstr (cogl_snippet_get_declarations (snippet), ==, "foo"); @@ -443,6 +474,7 @@ validate_result (void) test_utils_check_pixel (135, 5, 0xffff00ff); test_utils_check_pixel (145, 5, 0x00ff00ff); test_utils_check_pixel (155, 5, 0xff00ffff); + test_utils_check_pixel (165, 5, 0x80ff00ff); } void