tests: Test reading all pixel formats
The test-read-alpha-texture test has been replaced with a test that tries reading an RGBA texture in all current pixel formats. On GLES2 this should end up testing all of the convesion code because in that case GL only supports reading back RGBA data. The test now works on GLES2 since the conversion code for all of the formats has been added so this also removes the GL requirement. Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
parent
908ba29be5
commit
70dfbdd5e3
@ -48,7 +48,7 @@ test_sources = \
|
||||
test-primitive.c \
|
||||
test-texture-3d.c \
|
||||
test-sparse-pipeline.c \
|
||||
test-read-alpha-texture.c \
|
||||
test-read-texture-formats.c \
|
||||
$(NULL)
|
||||
|
||||
test_conformance_SOURCES = $(common_sources) $(test_sources)
|
||||
|
@ -81,9 +81,7 @@ 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);
|
||||
ADD_TEST (test_cogl_read_texture_formats, 0);
|
||||
|
||||
UNPORTED_TEST (test_cogl_vertex_buffer_contiguous);
|
||||
UNPORTED_TEST (test_cogl_vertex_buffer_interleved);
|
||||
|
@ -1,42 +0,0 @@
|
||||
#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");
|
||||
}
|
203
tests/conform/test-read-texture-formats.c
Normal file
203
tests/conform/test-read-texture-formats.c
Normal file
@ -0,0 +1,203 @@
|
||||
#include <cogl/cogl2-experimental.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "test-utils.h"
|
||||
|
||||
/*
|
||||
* This tests reading back an RGBA texture in all of the available
|
||||
* pixel formats
|
||||
*/
|
||||
|
||||
static const guint8 tex_data[4] = { 0x12, 0x34, 0x56, 0x78 };
|
||||
|
||||
static void
|
||||
test_read_byte (CoglTexture2D *tex_2d,
|
||||
CoglPixelFormat format,
|
||||
guint8 expected_byte)
|
||||
{
|
||||
guint8 received_byte;
|
||||
|
||||
cogl_texture_get_data (COGL_TEXTURE (tex_2d),
|
||||
format,
|
||||
1, /* rowstride */
|
||||
&received_byte);
|
||||
|
||||
g_assert_cmpint (expected_byte, ==, received_byte);
|
||||
}
|
||||
|
||||
static void
|
||||
test_read_short (CoglTexture2D *tex_2d,
|
||||
CoglPixelFormat format,
|
||||
...)
|
||||
{
|
||||
va_list ap;
|
||||
int bits;
|
||||
guint16 received_value;
|
||||
guint16 expected_value = 0;
|
||||
char *received_value_str;
|
||||
char *expected_value_str;
|
||||
int bits_sum = 0;
|
||||
|
||||
cogl_texture_get_data (COGL_TEXTURE (tex_2d),
|
||||
format,
|
||||
2, /* rowstride */
|
||||
(guint8 *) &received_value);
|
||||
|
||||
va_start (ap, format);
|
||||
|
||||
/* Convert the va args into a single 16-bit expected value */
|
||||
while ((bits = va_arg (ap, int)) != -1)
|
||||
{
|
||||
int value = (va_arg (ap, int) * ((1 << bits) - 1) + 128) / 255;
|
||||
|
||||
bits_sum += bits;
|
||||
|
||||
expected_value |= value << (16 - bits_sum);
|
||||
}
|
||||
|
||||
va_end (ap);
|
||||
|
||||
received_value_str = g_strdup_printf ("0x%04x", received_value);
|
||||
expected_value_str = g_strdup_printf ("0x%04x", expected_value);
|
||||
g_assert_cmpstr (received_value_str, ==, expected_value_str);
|
||||
g_free (received_value_str);
|
||||
g_free (expected_value_str);
|
||||
}
|
||||
|
||||
static void
|
||||
test_read_888 (CoglTexture2D *tex_2d,
|
||||
CoglPixelFormat format,
|
||||
guint32 expected_pixel)
|
||||
{
|
||||
guint8 pixel[4];
|
||||
|
||||
cogl_texture_get_data (COGL_TEXTURE (tex_2d),
|
||||
format,
|
||||
4, /* rowstride */
|
||||
pixel);
|
||||
|
||||
test_utils_compare_pixel (pixel, expected_pixel);
|
||||
}
|
||||
|
||||
static void
|
||||
test_read_8888 (CoglTexture2D *tex_2d,
|
||||
CoglPixelFormat format,
|
||||
guint32 expected_pixel)
|
||||
{
|
||||
guint32 received_pixel;
|
||||
char *received_value_str;
|
||||
char *expected_value_str;
|
||||
|
||||
cogl_texture_get_data (COGL_TEXTURE (tex_2d),
|
||||
format,
|
||||
4, /* rowstride */
|
||||
(guint8 *) &received_pixel);
|
||||
|
||||
received_pixel = GUINT32_FROM_BE (received_pixel);
|
||||
|
||||
received_value_str = g_strdup_printf ("0x%08x", received_pixel);
|
||||
expected_value_str = g_strdup_printf ("0x%08x", expected_pixel);
|
||||
g_assert_cmpstr (received_value_str, ==, expected_value_str);
|
||||
g_free (received_value_str);
|
||||
g_free (expected_value_str);
|
||||
}
|
||||
|
||||
static void
|
||||
test_read_int (CoglTexture2D *tex_2d,
|
||||
CoglPixelFormat format,
|
||||
...)
|
||||
{
|
||||
va_list ap;
|
||||
int bits;
|
||||
guint32 received_value;
|
||||
guint32 expected_value = 0;
|
||||
char *received_value_str;
|
||||
char *expected_value_str;
|
||||
int bits_sum = 0;
|
||||
|
||||
cogl_texture_get_data (COGL_TEXTURE (tex_2d),
|
||||
format,
|
||||
4, /* rowstride */
|
||||
(guint8 *) &received_value);
|
||||
|
||||
va_start (ap, format);
|
||||
|
||||
/* Convert the va args into a single 32-bit expected value */
|
||||
while ((bits = va_arg (ap, int)) != -1)
|
||||
{
|
||||
guint32 value = (va_arg (ap, int) * ((1 << bits) - 1) + 128) / 255;
|
||||
|
||||
bits_sum += bits;
|
||||
|
||||
expected_value |= value << (32 - bits_sum);
|
||||
}
|
||||
|
||||
va_end (ap);
|
||||
|
||||
received_value_str = g_strdup_printf ("0x%08x", received_value);
|
||||
expected_value_str = g_strdup_printf ("0x%08x", expected_value);
|
||||
g_assert_cmpstr (received_value_str, ==, expected_value_str);
|
||||
g_free (received_value_str);
|
||||
g_free (expected_value_str);
|
||||
}
|
||||
|
||||
void
|
||||
test_cogl_read_texture_formats (TestUtilsGTestFixture *fixture,
|
||||
void *data)
|
||||
{
|
||||
TestUtilsSharedState *shared_state = data;
|
||||
CoglTexture2D *tex_2d;
|
||||
|
||||
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);
|
||||
|
||||
test_read_byte (tex_2d, COGL_PIXEL_FORMAT_A_8, 0x78);
|
||||
|
||||
#if 0
|
||||
/* I'm not sure what's the right value to put here because Nvidia
|
||||
and Mesa seem to behave differently so one of them must be
|
||||
wrong. */
|
||||
test_read_byte (tex_2d, COGL_PIXEL_FORMAT_G_8, 0x9c);
|
||||
#endif
|
||||
|
||||
test_read_short (tex_2d, COGL_PIXEL_FORMAT_RGB_565,
|
||||
5, 0x12, 6, 0x34, 5, 0x56,
|
||||
-1);
|
||||
test_read_short (tex_2d, COGL_PIXEL_FORMAT_RGBA_4444_PRE,
|
||||
4, 0x12, 4, 0x34, 4, 0x56, 4, 0x78,
|
||||
-1);
|
||||
test_read_short (tex_2d, COGL_PIXEL_FORMAT_RGBA_5551_PRE,
|
||||
5, 0x12, 5, 0x34, 5, 0x56, 1, 0x78,
|
||||
-1);
|
||||
|
||||
test_read_888 (tex_2d, COGL_PIXEL_FORMAT_RGB_888, 0x123456ff);
|
||||
test_read_888 (tex_2d, COGL_PIXEL_FORMAT_BGR_888, 0x563412ff);
|
||||
|
||||
test_read_8888 (tex_2d, COGL_PIXEL_FORMAT_RGBA_8888_PRE, 0x12345678);
|
||||
test_read_8888 (tex_2d, COGL_PIXEL_FORMAT_BGRA_8888_PRE, 0x56341278);
|
||||
test_read_8888 (tex_2d, COGL_PIXEL_FORMAT_ARGB_8888_PRE, 0x78123456);
|
||||
test_read_8888 (tex_2d, COGL_PIXEL_FORMAT_ABGR_8888_PRE, 0x78563412);
|
||||
|
||||
test_read_int (tex_2d, COGL_PIXEL_FORMAT_RGBA_1010102_PRE,
|
||||
10, 0x12, 10, 0x34, 10, 0x56, 2, 0x78,
|
||||
-1);
|
||||
test_read_int (tex_2d, COGL_PIXEL_FORMAT_BGRA_1010102_PRE,
|
||||
10, 0x56, 10, 0x34, 10, 0x12, 2, 0x78,
|
||||
-1);
|
||||
test_read_int (tex_2d, COGL_PIXEL_FORMAT_ARGB_2101010_PRE,
|
||||
2, 0x78, 10, 0x12, 10, 0x34, 10, 0x56,
|
||||
-1);
|
||||
test_read_int (tex_2d, COGL_PIXEL_FORMAT_ABGR_2101010_PRE,
|
||||
2, 0x78, 10, 0x56, 10, 0x34, 10, 0x12,
|
||||
-1);
|
||||
|
||||
cogl_object_unref (tex_2d);
|
||||
|
||||
if (g_test_verbose ())
|
||||
g_print ("OK\n");
|
||||
}
|
Loading…
Reference in New Issue
Block a user