mutter/tests/conform/test-read-alpha-texture.c
Neil Roberts b6dc23370d 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 <robert@linux.intel.com>
2012-03-05 17:43:46 +00:00

43 lines
1.3 KiB
C

#include <cogl/cogl2-experimental.h>
#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");
}