[Cogl] [PATCH 1/2] Add a simple conformance test for alpha testing

Robert Bragg robert at sixbynine.org
Mon Oct 1 09:14:42 PDT 2012


this looks good to land to me:

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

thanks,
- Robert

On Mon, Oct 1, 2012 at 3:03 PM, Neil Roberts <neil at linux.intel.com> wrote:
> This adds a simple test which sets an alpha test on a pipeline and
> then renders a texture. It then verifies that the transparent parts of
> the texture aren't drawn. This is currently failing with the GL3
> driver because GL3 requires the alpha test to be implemented in GLSL
> but the generated alpha test uniform is only updated for the GLES2
> driver.
> ---
>  tests/conform/Makefile.am         |  1 +
>  tests/conform/test-alpha-test.c   | 74 +++++++++++++++++++++++++++++++++++++++
>  tests/conform/test-conform-main.c |  2 ++
>  3 files changed, 77 insertions(+)
>  create mode 100644 tests/conform/test-alpha-test.c
>
> diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
> index 8eeffd0..eab0b94 100644
> --- a/tests/conform/Makefile.am
> +++ b/tests/conform/Makefile.am
> @@ -56,6 +56,7 @@ test_sources = \
>         test-gles2-context.c \
>         test-euler-quaternion.c \
>         test-layer-remove.c \
> +       test-alpha-test.c \
>         $(NULL)
>
>  test_conformance_SOURCES = $(common_sources) $(test_sources)
> diff --git a/tests/conform/test-alpha-test.c b/tests/conform/test-alpha-test.c
> new file mode 100644
> index 0000000..285118b
> --- /dev/null
> +++ b/tests/conform/test-alpha-test.c
> @@ -0,0 +1,74 @@
> +#include <cogl/cogl.h>
> +#include <string.h>
> +
> +#include "test-utils.h"
> +
> +static CoglTexture2D *
> +create_texture (CoglContext *context)
> +{
> +  static const uint8_t data[] =
> +    {
> +      0xff, 0x00, 0x00, 0xff,
> +      0x00, 0xfa, 0x00, 0xfa
> +    };
> +
> +  return cogl_texture_2d_new_from_data (context,
> +                                        2, 1, /* width/height */
> +                                        COGL_PIXEL_FORMAT_RGBA_8888_PRE,
> +                                        COGL_PIXEL_FORMAT_ANY,
> +                                        4, /* rowstride */
> +                                        data,
> +                                        NULL /* error */);
> +}
> +
> +void
> +test_alpha_test (void)
> +{
> +  CoglTexture *tex = COGL_TEXTURE (create_texture (test_ctx));
> +  CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
> +  int fb_width = cogl_framebuffer_get_width (test_fb);
> +  int fb_height = cogl_framebuffer_get_height (test_fb);
> +  CoglColor clear_color;
> +
> +  cogl_pipeline_set_layer_texture (pipeline, 0, tex);
> +  cogl_pipeline_set_layer_filters (pipeline, 0,
> +                                   COGL_PIPELINE_FILTER_NEAREST,
> +                                   COGL_PIPELINE_FILTER_NEAREST);
> +  cogl_pipeline_set_alpha_test_function (pipeline,
> +                                         COGL_PIPELINE_ALPHA_FUNC_GEQUAL,
> +                                         254 / 255.0f /* alpha reference */);
> +
> +  cogl_color_init_from_4ub (&clear_color, 0x00, 0x00, 0xff, 0xff);
> +  cogl_framebuffer_clear (test_fb,
> +                          COGL_BUFFER_BIT_COLOR,
> +                          &clear_color);
> +
> +  cogl_framebuffer_draw_rectangle (test_fb,
> +                                   pipeline,
> +                                   -1, -1,
> +                                   1, 1);
> +
> +  cogl_object_unref (pipeline);
> +  cogl_object_unref (tex);
> +
> +  /* The left side of the framebuffer should use the first pixel from
> +   * the texture which is red */
> +  test_utils_check_region (test_fb,
> +                           2, 2,
> +                           fb_width / 2 - 4,
> +                           fb_height - 4,
> +                           0xff0000ff);
> +  /* The right side of the framebuffer should use the clear color
> +   * because the second pixel from the texture is clipped from the
> +   * alpha test */
> +  test_utils_check_region (test_fb,
> +                           fb_width / 2 + 2,
> +                           2,
> +                           fb_width / 2 - 4,
> +                           fb_height - 4,
> +                           0x0000ffff);
> +
> +  if (cogl_test_verbose ())
> +    g_print ("OK\n");
> +}
> +
> diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c
> index 7475685..df9d2a5 100644
> --- a/tests/conform/test-conform-main.c
> +++ b/tests/conform/test-conform-main.c
> @@ -100,6 +100,8 @@ main (int argc, char **argv)
>
>    ADD_TEST (test_version, 0);
>
> +  ADD_TEST (test_alpha_test, 0);
> +
>    UNPORTED_TEST (test_viewport);
>
>    ADD_TEST (test_gles2_context, TEST_REQUIREMENT_GLES2_CONTEXT);
> --
> 1.7.11.3.g3c3efa5
>
> _______________________________________________
> Cogl mailing list
> Cogl at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/cogl


More information about the Cogl mailing list