[Cogl] [PATCH] Add a conformance test for using cogl_point_coord in a shader

Robert Bragg robert at sixbynine.org
Mon Sep 2 07:34:05 PDT 2013


This looks good to land to me:

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

thanks,
Robert

On Thu, Aug 29, 2013 at 2:18 PM, Neil Roberts <neil at linux.intel.com> wrote:
> 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.
> ---
>  tests/conform/test-conform-main.c |  4 ++
>  tests/conform/test-point-sprite.c | 81 ++++++++++++++++++++++++++++++---------
>  2 files changed, 66 insertions(+), 19 deletions(-)
>
> diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c
> index 83a631e..fe3b87c 100644
> --- a/tests/conform/test-conform-main.c
> +++ b/tests/conform/test-conform-main.c
> @@ -117,6 +117,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 797673d..c068318 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,20 +61,60 @@ 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,
> +  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);
> +      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);
> +      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,
> @@ -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 orientation */,
> +           TRUE /* use GLSL */);
>  }
> --
> 1.8.3.1
>
> _______________________________________________
> Cogl mailing list
> Cogl at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/cogl


More information about the Cogl mailing list