From a849ecae1b9c501e72770e4582690d8a3b90db3e Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Thu, 29 Aug 2013 14:14:35 +0100 Subject: [PATCH] Add a conformance test for using cogl_point_coord in a shader This adds a modification to the test-point-sprite test which uses a shader snippet which directly references cogl_point_coord instead of relying on cogl_pipeline_set_layer_point_sprite_coords_enabled to replace the texture coordinates with the point coords. Reviewed-by: Robert Bragg (cherry picked from commit 5ea57b14f5ec7d52ae378f4ca64574ef56342f56) --- tests/conform/test-conform-main.c | 4 ++ tests/conform/test-point-sprite.c | 83 +++++++++++++++++++++++-------- 2 files changed, 67 insertions(+), 20 deletions(-) diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c index 4a8e08d6a..56f93cf74 100644 --- a/tests/conform/test-conform-main.c +++ b/tests/conform/test-conform-main.c @@ -115,6 +115,10 @@ main (int argc, char **argv) ADD_TEST (test_point_sprite_orientation, TEST_REQUIREMENT_POINT_SPRITE, TEST_KNOWN_FAILURE); + ADD_TEST (test_point_sprite_glsl, + TEST_REQUIREMENT_POINT_SPRITE | + TEST_REQUIREMENT_GLSL, + 0); ADD_TEST (test_version, 0, 0); diff --git a/tests/conform/test-point-sprite.c b/tests/conform/test-point-sprite.c index ac9075cd1..c49dca1b3 100644 --- a/tests/conform/test-point-sprite.c +++ b/tests/conform/test-point-sprite.c @@ -19,7 +19,8 @@ tex_data[3 * 2 * 2] = }; static void -do_test (CoglBool check_orientation) +do_test (CoglBool check_orientation, + CoglBool use_glsl) { int fb_width = cogl_framebuffer_get_width (test_fb); int fb_height = cogl_framebuffer_get_height (test_fb); @@ -27,7 +28,6 @@ do_test (CoglBool check_orientation) CoglError *error = NULL; CoglTexture2D *tex_2d; CoglPipeline *pipeline, *solid_pipeline; - CoglBool res; int tex_height; cogl_framebuffer_orthographic (test_fb, @@ -61,21 +61,61 @@ do_test (CoglBool check_orientation) pipeline = cogl_pipeline_new (test_ctx); cogl_pipeline_set_layer_texture (pipeline, 0, COGL_TEXTURE (tex_2d)); - res = cogl_pipeline_set_layer_point_sprite_coords_enabled (pipeline, - /* layer_index */ - 0, - /* enable */ - TRUE, - &error); - g_assert (res == TRUE); - g_assert (error == NULL); - cogl_pipeline_set_layer_filters (pipeline, 0, /* layer_index */ COGL_PIPELINE_FILTER_NEAREST, COGL_PIPELINE_FILTER_NEAREST); cogl_pipeline_set_point_size (pipeline, POINT_SIZE); + /* If we're using GLSL then we don't need to enable point sprite + * coords and we can just directly reference cogl_point_coord in the + * snippet */ + if (use_glsl) + { + CoglSnippet *snippet = + cogl_snippet_new (COGL_SNIPPET_HOOK_TEXTURE_LOOKUP, + NULL, /* declarations */ + NULL /* post */); + static const char source[] = + " cogl_texel = texture2D (cogl_sampler, cogl_point_coord);\n"; + + cogl_snippet_set_replace (snippet, source); + + /* Keep a reference to the original pipeline because there is no + * way to remove a snippet in order to recreate the solid + * pipeline */ + solid_pipeline = cogl_pipeline_copy (pipeline); + + cogl_pipeline_add_layer_snippet (pipeline, 0, snippet); + + cogl_object_unref (snippet); + } + else + { + CoglBool res = + cogl_pipeline_set_layer_point_sprite_coords_enabled (pipeline, + /* layer_index */ + 0, + /* enable */ + TRUE, + &error); + g_assert (res == TRUE); + g_assert (error == NULL); + + solid_pipeline = cogl_pipeline_copy (pipeline); + + res = + cogl_pipeline_set_layer_point_sprite_coords_enabled (solid_pipeline, + /* layer_index */ + 0, + /* enable */ + FALSE, + &error); + + g_assert (res == TRUE); + g_assert (error == NULL); + } + prim = cogl_primitive_new_p2t2 (test_ctx, COGL_VERTICES_MODE_POINTS, 1, /* n_vertices */ @@ -85,13 +125,7 @@ do_test (CoglBool check_orientation) /* Render the primitive again without point sprites to make sure disabling it works */ - solid_pipeline = cogl_pipeline_copy (pipeline); - cogl_pipeline_set_layer_point_sprite_coords_enabled (solid_pipeline, - /* layer_index */ - 0, - /* enable */ - FALSE, - &error); + cogl_framebuffer_push_matrix (test_fb); cogl_framebuffer_translate (test_fb, POINT_SIZE * 2, /* x */ @@ -142,11 +176,20 @@ do_test (CoglBool check_orientation) void test_point_sprite (void) { - do_test (FALSE /* don't check orientation */); + do_test (FALSE /* don't check orientation */, + FALSE /* don't use GLSL */); } void test_point_sprite_orientation (void) { - do_test (TRUE /* check orientation */); + do_test (TRUE /* check orientation */, + FALSE /* don't use GLSL */); +} + +void +test_point_sprite_glsl (void) +{ + do_test (FALSE /* don't check orientation */, + TRUE /* use GLSL */); }