[Cogl] [PATCH 2/2] Add a conformance test using alpha textures

Robert Bragg robert at sixbynine.org
Fri Nov 23 06:38:56 PST 2012


This looks good to land to me:

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

thanks,
- Robert


On Mon, Nov 19, 2012 at 5:28 PM, Neil Roberts <neil at linux.intel.com> wrote:

> This adds a conformance test with an alpha-component texture. The
> texture is rendered using a pipeline with the same layer combine mode
> as cogl-pango.
> ---
>  tests/conform/Makefile.am           |   1 +
>  tests/conform/test-alpha-textures.c | 124
> ++++++++++++++++++++++++++++++++++++
>  tests/conform/test-conform-main.c   |   1 +
>  3 files changed, 126 insertions(+)
>  create mode 100644 tests/conform/test-alpha-textures.c
>
> diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
> index b6430e2..4f1905c 100644
> --- a/tests/conform/Makefile.am
> +++ b/tests/conform/Makefile.am
> @@ -59,6 +59,7 @@ test_sources = \
>         test-alpha-test.c \
>         test-map-buffer-range.c \
>         test-npot-texture.c \
> +       test-alpha-textures.c \
>         $(NULL)
>
>  test_conformance_SOURCES = $(common_sources) $(test_sources)
> diff --git a/tests/conform/test-alpha-textures.c
> b/tests/conform/test-alpha-textures.c
> new file mode 100644
> index 0000000..9063b80
> --- /dev/null
> +++ b/tests/conform/test-alpha-textures.c
> @@ -0,0 +1,124 @@
> +#include <cogl/cogl.h>
> +
> +#include <string.h>
> +
> +#include "test-utils.h"
> +
> +static void
> +create_pipeline (CoglTexture **tex_out,
> +                 CoglPipeline **pipeline_out)
> +{
> +  CoglTexture2D *tex;
> +  CoglPipeline *pipeline;
> +  static const uint8_t tex_data[] =
> +    { 0x00, 0x44, 0x88, 0xcc };
> +
> +  tex = cogl_texture_2d_new_from_data (test_ctx,
> +                                       2, 2, /* width/height */
> +                                       COGL_PIXEL_FORMAT_A_8, /* format */
> +                                       COGL_PIXEL_FORMAT_ANY, /* int.
> format */
> +                                       2, /* rowstride */
> +                                       tex_data,
> +                                       NULL);
> +
> +  pipeline = cogl_pipeline_new (test_ctx);
> +
> +  cogl_pipeline_set_layer_filters (pipeline,
> +                                   0, /* layer */
> +                                   COGL_PIPELINE_FILTER_NEAREST,
> +                                   COGL_PIPELINE_FILTER_NEAREST);
> +  cogl_pipeline_set_layer_wrap_mode (pipeline,
> +                                     0, /* layer */
> +
> COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE);
> +
> +  /* This is the layer combine used by cogl-pango */
> +  cogl_pipeline_set_layer_combine (pipeline,
> +                                   0, /* layer */
> +                                   "RGBA = MODULATE (PREVIOUS,
> TEXTURE[A])",
> +                                   NULL);
> +
> +  cogl_pipeline_set_layer_texture (pipeline,
> +                                   0, /* layer */
> +                                   COGL_TEXTURE (tex));
> +
> +  *pipeline_out = pipeline;
> +  *tex_out = COGL_TEXTURE (tex);
> +}
> +
> +void
> +test_alpha_textures (void)
> +{
> +  CoglTexture *tex1, *tex2;
> +  CoglPipeline *pipeline1, *pipeline2;
> +  int fb_width = cogl_framebuffer_get_width (test_fb);
> +  int fb_height = cogl_framebuffer_get_height (test_fb);
> +  uint8_t replacement_data[1] = { 0xff };
> +
> +  create_pipeline (&tex1, &pipeline1);
> +
> +  cogl_framebuffer_draw_rectangle (test_fb,
> +                                   pipeline1,
> +                                   -1.0f, 1.0f, /* x1/y1 */
> +                                   1.0f, 0.0f /* x2/y2 */);
> +
> +  create_pipeline (&tex2, &pipeline2);
> +
> +  cogl_texture_set_region (tex2,
> +                           0, 0, /* src_x/y */
> +                           1, 1, /* dst_x/y */
> +                           1, 1, /* dst_width / dst_height */
> +                           1, 1, /* width / height */
> +                           COGL_PIXEL_FORMAT_A_8,
> +                           1, /* rowstride */
> +                           replacement_data);
> +
> +  cogl_framebuffer_draw_rectangle (test_fb,
> +                                   pipeline2,
> +                                   -1.0f, 0.0f, /* x1/y1 */
> +                                   1.0f, -1.0f /* x2/y2 */);
> +
> +  cogl_object_unref (tex1);
> +  cogl_object_unref (tex2);
> +  cogl_object_unref (pipeline1);
> +  cogl_object_unref (pipeline2);
> +
> +  /* Unmodified texture */
> +  test_utils_check_pixel (test_fb,
> +                          fb_width / 4,
> +                          fb_height / 8,
> +                          0x000000ff);
> +  test_utils_check_pixel (test_fb,
> +                          fb_width * 3 / 4,
> +                          fb_height / 8,
> +                          0x444444ff);
> +  test_utils_check_pixel (test_fb,
> +                          fb_width / 4,
> +                          fb_height * 3 / 8,
> +                          0x888888ff);
> +  test_utils_check_pixel (test_fb,
> +                          fb_width * 3 / 4,
> +                          fb_height * 3 / 8,
> +                          0xccccccff);
> +
> +  /* Modified texture */
> +  test_utils_check_pixel (test_fb,
> +                          fb_width / 4,
> +                          fb_height * 5 / 8,
> +                          0x000000ff);
> +  test_utils_check_pixel (test_fb,
> +                          fb_width * 3 / 4,
> +                          fb_height * 5 / 8,
> +                          0x444444ff);
> +  test_utils_check_pixel (test_fb,
> +                          fb_width / 4,
> +                          fb_height * 7 / 8,
> +                          0x888888ff);
> +  test_utils_check_pixel (test_fb,
> +                          fb_width * 3 / 4,
> +                          fb_height * 7 / 8,
> +                          0xffffffff);
> +
> +  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 b510543..78f3b34 100644
> --- a/tests/conform/test-conform-main.c
> +++ b/tests/conform/test-conform-main.c
> @@ -77,6 +77,7 @@ main (int argc, char **argv)
>    ADD_TEST (test_atlas_migration, 0, 0);
>    ADD_TEST (test_read_texture_formats, 0, 0);
>    ADD_TEST (test_write_texture_formats, 0, 0);
> +  ADD_TEST (test_alpha_textures, 0, 0);
>
>    UNPORTED_TEST (test_vertex_buffer_contiguous);
>    UNPORTED_TEST (test_vertex_buffer_interleved);
> --
> 1.7.11.3.g3c3efa5
>
> _______________________________________________
> Cogl mailing list
> Cogl at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/cogl
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/cogl/attachments/20121123/f7172048/attachment.html>


More information about the Cogl mailing list