forked from AuroraMiddleware/gtk
testsuite: Add tests for gdk_texture_download_float()
This commit is contained in:
parent
9179ebb28e
commit
416763bf2d
@ -353,6 +353,50 @@ compare_textures (GdkTexture *expected,
|
||||
g_free (test_data);
|
||||
}
|
||||
|
||||
static void
|
||||
compare_textures_float (GdkTexture *expected,
|
||||
GdkTexture *test,
|
||||
float eps,
|
||||
gboolean has_alpha)
|
||||
{
|
||||
static int R = 0;
|
||||
static int G = 1;
|
||||
static int B = 2;
|
||||
static int A = 3;
|
||||
float *expected_data, *test_data;
|
||||
int width, height;
|
||||
int x, y;
|
||||
|
||||
g_assert_cmpint (gdk_texture_get_width (expected), ==, gdk_texture_get_width (test));
|
||||
g_assert_cmpint (gdk_texture_get_height (expected), ==, gdk_texture_get_height (test));
|
||||
|
||||
width = gdk_texture_get_width (expected);
|
||||
height = gdk_texture_get_height (expected);
|
||||
|
||||
expected_data = g_new (float, width * height * 4);
|
||||
gdk_texture_download_float (expected, expected_data, width * 4);
|
||||
|
||||
test_data = g_new (float, width * height * 4);
|
||||
gdk_texture_download_float (test, test_data, width * 4);
|
||||
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
for (x = 0; x < width; x++)
|
||||
{
|
||||
g_assert_cmpfloat_with_epsilon (expected_data[y * width + 4 * x + R], test_data[y * width + 4 * x + R], eps);
|
||||
g_assert_cmpfloat_with_epsilon (expected_data[y * width + 4 * x + G], test_data[y * width + 4 * x + G], eps);
|
||||
g_assert_cmpfloat_with_epsilon (expected_data[y * width + 4 * x + B], test_data[y * width + 4 * x + B], eps);
|
||||
if (has_alpha)
|
||||
g_assert_cmpfloat_with_epsilon (expected_data[y * width + 4 * x + A], test_data[y * width + 4 * x + A], eps);
|
||||
else
|
||||
g_assert_cmpfloat (1.0, ==, test_data[y * width + 4 * x + A]);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (expected_data);
|
||||
g_free (test_data);
|
||||
}
|
||||
|
||||
static GdkTexture *
|
||||
upload_to_gl (GdkTexture *texture)
|
||||
{
|
||||
@ -473,6 +517,59 @@ test_download_4x4 (gconstpointer data)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_download_float_1x1 (gconstpointer data)
|
||||
{
|
||||
GdkMemoryFormat format;
|
||||
TextureMethod method;
|
||||
GdkTexture *expected, *test;
|
||||
gsize i;
|
||||
|
||||
decode (data, &format, &method);
|
||||
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
GdkRGBA color;
|
||||
|
||||
create_random_color (&color);
|
||||
expected = create_texture (GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED, TEXTURE_METHOD_LOCAL, 1, 1, &color);
|
||||
test = create_texture (format, method, 1, 1, &color);
|
||||
|
||||
compare_textures_float (expected, test,
|
||||
G_MINFLOAT,
|
||||
gdk_memory_format_has_alpha (format));
|
||||
|
||||
g_object_unref (expected);
|
||||
g_object_unref (test);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_download_float_4x4 (gconstpointer data)
|
||||
{
|
||||
GdkMemoryFormat format;
|
||||
TextureMethod method;
|
||||
GdkTexture *expected, *test;
|
||||
gsize i;
|
||||
|
||||
decode (data, &format, &method);
|
||||
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
GdkRGBA color;
|
||||
|
||||
create_random_color (&color);
|
||||
expected = create_texture (GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED, TEXTURE_METHOD_LOCAL, 4, 4, &color);
|
||||
test = create_texture (format, method, 4, 4, &color);
|
||||
|
||||
compare_textures_float (expected, test, G_MINFLOAT, gdk_memory_format_has_alpha (format));
|
||||
|
||||
g_object_unref (expected);
|
||||
g_object_unref (test);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
add_test (const char *name,
|
||||
GTestDataFunc func)
|
||||
@ -508,6 +605,8 @@ main (int argc, char *argv[])
|
||||
|
||||
add_test ("/memorytexture/download_1x1", test_download_1x1);
|
||||
add_test ("/memorytexture/download_4x4", test_download_4x4);
|
||||
add_test ("/memorytexture/download_float_1x1", test_download_float_1x1);
|
||||
add_test ("/memorytexture/download_float_4x4", test_download_float_4x4);
|
||||
|
||||
surface = gdk_surface_new_toplevel (gdk_display_get_default());
|
||||
gl_renderer = gsk_ngl_renderer_new ();
|
||||
|
Loading…
Reference in New Issue
Block a user