From b6dc23370d242e68afd5436d6c531b79d8e5e843 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Wed, 29 Feb 2012 11:19:56 +0000 Subject: [PATCH] Add a conformance test for reading back an RGBA texture as alpha-only This just creates a 1x1 RGBA texture and then reads it back in COGL_PIXEL_FORMAT_A_8 format. Gnome Shell is doing this to create a shadow and I accidentally broke it so this should hopefully stop that happening again. https://bugzilla.gnome.org/show_bug.cgi?id=671016 Reviewed-by: Robert Bragg --- tests/conform/Makefile.am | 1 + tests/conform/test-conform-main.c | 3 ++ tests/conform/test-read-alpha-texture.c | 42 +++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 tests/conform/test-read-alpha-texture.c diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am index a39070a40..b0f2a8829 100644 --- a/tests/conform/Makefile.am +++ b/tests/conform/Makefile.am @@ -48,6 +48,7 @@ test_sources = \ test-primitive.c \ test-texture-3d.c \ test-sparse-pipeline.c \ + test-read-alpha-texture.c \ $(NULL) test_conformance_SOURCES = $(common_sources) $(test_sources) diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c index ae71c97d3..85eb48960 100644 --- a/tests/conform/test-conform-main.c +++ b/tests/conform/test-conform-main.c @@ -81,6 +81,9 @@ main (int argc, char **argv) UNPORTED_TEST (test_cogl_texture_pixmap_x11); UNPORTED_TEST (test_cogl_texture_get_set_data); UNPORTED_TEST (test_cogl_atlas_migration); + /* This doesn't currently work on GLES because there is no fallback + conversion to/from alpha-only */ + ADD_TEST (test_cogl_read_alpha_texture, TEST_REQUIREMENT_GL); UNPORTED_TEST (test_cogl_vertex_buffer_contiguous); UNPORTED_TEST (test_cogl_vertex_buffer_interleved); diff --git a/tests/conform/test-read-alpha-texture.c b/tests/conform/test-read-alpha-texture.c new file mode 100644 index 000000000..6b9ca5894 --- /dev/null +++ b/tests/conform/test-read-alpha-texture.c @@ -0,0 +1,42 @@ +#include + +#include "test-utils.h" + +/* + * This tests reading back an RGBA texture in alpha-only format. + * This test just exists because I accidentally broke it and + * gnome-shell is doing it. + * + * https://bugzilla.gnome.org/show_bug.cgi?id=671016 + */ + +static const guint8 tex_data[4] = { 0x12, 0x34, 0x56, 0x78 }; + +void +test_cogl_read_alpha_texture (TestUtilsGTestFixture *fixture, + void *data) +{ + TestUtilsSharedState *shared_state = data; + CoglTexture2D *tex_2d; + guint8 alpha_value; + + tex_2d = cogl_texture_2d_new_from_data (shared_state->ctx, + 1, 1, /* width / height */ + COGL_PIXEL_FORMAT_RGBA_8888_PRE, + COGL_PIXEL_FORMAT_RGBA_8888_PRE, + 4, /* rowstride */ + tex_data, + NULL); + + cogl_texture_get_data (COGL_TEXTURE (tex_2d), + COGL_PIXEL_FORMAT_A_8, + 1, /* rowstride */ + &alpha_value); + + cogl_object_unref (tex_2d); + + g_assert_cmpint (alpha_value, ==, 0x78); + + if (g_test_verbose ()) + g_print ("OK\n"); +}