[cogl] tests: Port blend-strings to test both the legacy and the new API
- From: Robert Bragg <rbragg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl] tests: Port blend-strings to test both the legacy and the new API
- Date: Wed, 12 Oct 2011 12:50:51 +0000 (UTC)
commit bdfaf94afb76a3e1d77689c0f5ba8955576d6831
Author: Luca Bruno <lucabru src gnome org>
Date: Sun Oct 2 10:22:43 2011 +0200
tests: Port blend-strings to test both the legacy and the new API
https://bugzilla.gnome.org/show_bug.cgi?id=660617
Reviewed-by: Robert Bragg <robert linux intel com>
tests/conform/Makefile.am | 2 +-
tests/conform/test-blend-strings.c | 192 +++++++++++++++++++-----------------
tests/conform/test-conform-main.c | 2 +-
3 files changed, 104 insertions(+), 92 deletions(-)
---
diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
index 8ce8038..8f83b67 100644
--- a/tests/conform/Makefile.am
+++ b/tests/conform/Makefile.am
@@ -11,7 +11,6 @@ common_sources = \
$(NULL)
unported_test_sources = \
- test-blend-strings.c \
test-fixed.c \
test-materials.c \
test-viewport.c \
@@ -38,6 +37,7 @@ unported_test_sources = \
$(NULL)
test_sources = \
+ test-blend-strings.c \
test-depth-test.c \
test-color-mask.c \
test-backface-culling.c \
diff --git a/tests/conform/test-blend-strings.c b/tests/conform/test-blend-strings.c
index 77d1dd6..e722934 100644
--- a/tests/conform/test-blend-strings.c
+++ b/tests/conform/test-blend-strings.c
@@ -1,11 +1,8 @@
-
-#include <clutter/clutter.h>
#include <cogl/cogl.h>
-#include <string.h>
-#include "test-conform-common.h"
+#include <string.h>
-static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
+#include "test-utils.h"
#define QUAD_WIDTH 20
@@ -24,30 +21,28 @@ static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
typedef struct _TestState
{
- ClutterGeometry stage_geom;
+ int dummy;
} TestState;
static void
-check_pixel (GLubyte *pixel, guint32 color)
+check_pixel (int x, int y, guint32 expected_pixel)
{
- guint8 r = MASK_RED (color);
- guint8 g = MASK_GREEN (color);
- guint8 b = MASK_BLUE (color);
- guint8 a = MASK_ALPHA (color);
+ guint32 pixel;
+ char *screen_pixel;
+ char *intended_pixel;
- if (g_test_verbose ())
- g_print (" expected = %x, %x, %x, %x\n",
- r, g, b, a);
- /* FIXME - allow for hardware in-precision */
- g_assert_cmpint (pixel[RED], ==, r);
- g_assert_cmpint (pixel[GREEN], ==, g);
- g_assert_cmpint (pixel[BLUE], ==, b);
-
- /* FIXME
- * We ignore the alpha, since we don't know if our render target is
- * RGB or RGBA */
- /* g_assert (pixel[ALPHA] == a); */
+ cogl_read_pixels (x, y, 1, 1, COGL_READ_PIXELS_COLOR_BUFFER,
+ COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+ (guint8 *) &pixel);
+
+ screen_pixel = g_strdup_printf ("#%06x", GUINT32_FROM_BE (pixel) >> 8);
+ intended_pixel = g_strdup_printf ("#%06x", expected_pixel >> 8);
+
+ g_assert_cmpstr (screen_pixel, ==, intended_pixel);
+
+ g_free (screen_pixel);
+ g_free (intended_pixel);
}
static void
@@ -78,58 +73,59 @@ test_blend (TestState *state,
CoglColor blend_const_color;
CoglHandle material;
+ CoglPipeline *pipeline;
gboolean status;
GError *error = NULL;
- GLubyte pixel[4];
- GLint y_off;
- GLint x_off;
+ int y_off;
+ int x_off;
/* First write out the destination color without any blending... */
- material = cogl_material_new ();
- cogl_material_set_color4ub (material, Dr, Dg, Db, Da);
- cogl_material_set_blend (material, "RGBA = ADD (SRC_COLOR, 0)", NULL);
- cogl_set_source (material);
+ pipeline = cogl_pipeline_new ();
+ cogl_pipeline_set_color4ub (pipeline, Dr, Dg, Db, Da);
+ cogl_pipeline_set_blend (pipeline, "RGBA = ADD (SRC_COLOR, 0)", NULL);
+ cogl_set_source (pipeline);
cogl_rectangle (x * QUAD_WIDTH,
y * QUAD_WIDTH,
x * QUAD_WIDTH + QUAD_WIDTH,
y * QUAD_WIDTH + QUAD_WIDTH);
- cogl_handle_unref (material);
+ cogl_object_unref (pipeline);
/*
* Now blend a rectangle over our well defined destination:
*/
- material = cogl_material_new ();
- cogl_material_set_color4ub (material, Sr, Sg, Sb, Sa);
+ pipeline = cogl_pipeline_new ();
+ cogl_pipeline_set_color4ub (pipeline, Sr, Sg, Sb, Sa);
- status = cogl_material_set_blend (material, blend_string, &error);
+ status = cogl_pipeline_set_blend (pipeline, blend_string, &error);
if (!status)
{
/* It's not strictly a test failure; you need a more capable GPU or
* driver to test this blend string. */
- g_debug ("Failed to test blend string %s: %s",
- blend_string, error->message);
+ if (g_test_verbose ())
+ {
+ g_debug ("Failed to test blend string %s: %s",
+ blend_string, error->message);
+ g_print ("Skipping\n");
+ }
+ return;
}
cogl_color_init_from_4ub (&blend_const_color, Br, Bg, Bb, Ba);
- cogl_material_set_blend_constant (material, &blend_const_color);
+ cogl_pipeline_set_blend_constant (pipeline, &blend_const_color);
- cogl_set_source (material);
+ cogl_set_source (pipeline);
cogl_rectangle (x * QUAD_WIDTH,
y * QUAD_WIDTH,
x * QUAD_WIDTH + QUAD_WIDTH,
y * QUAD_WIDTH + QUAD_WIDTH);
- cogl_handle_unref (material);
+ cogl_object_unref (pipeline);
/* See what we got... */
y_off = y * QUAD_WIDTH + (QUAD_WIDTH / 2);
x_off = x * QUAD_WIDTH + (QUAD_WIDTH / 2);
- cogl_read_pixels (x_off, y_off, 1, 1,
- COGL_READ_PIXELS_COLOR_BUFFER,
- COGL_PIXEL_FORMAT_RGBA_8888_PRE,
- pixel);
if (g_test_verbose ())
{
g_print ("test_blend (%d, %d):\n%s\n", x, y, blend_string);
@@ -140,11 +136,62 @@ test_blend (TestState *state,
Br, Bg, Bb, Ba);
else
g_print (" blend constant = UNUSED\n");
- g_print (" result = %x, %x, %x, %x\n",
- pixel[RED], pixel[GREEN], pixel[BLUE], pixel[ALPHA]);
}
- check_pixel (pixel, expected_result);
+ check_pixel (x_off, y_off, expected_result);
+
+
+ /*
+ * Test with legacy API
+ */
+
+ /* Clear previous work */
+ cogl_set_source_color4ub (0, 0, 0, 0xff);
+ cogl_rectangle (x * QUAD_WIDTH,
+ y * QUAD_WIDTH,
+ x * QUAD_WIDTH + QUAD_WIDTH,
+ y * QUAD_WIDTH + QUAD_WIDTH);
+
+ /* First write out the destination color without any blending... */
+ material = cogl_material_new ();
+ cogl_material_set_color4ub (material, Dr, Dg, Db, Da);
+ cogl_material_set_blend (material, "RGBA = ADD (SRC_COLOR, 0)", NULL);
+ cogl_set_source (material);
+ cogl_rectangle (x * QUAD_WIDTH,
+ y * QUAD_WIDTH,
+ x * QUAD_WIDTH + QUAD_WIDTH,
+ y * QUAD_WIDTH + QUAD_WIDTH);
+ cogl_handle_unref (material);
+
+ /*
+ * Now blend a rectangle over our well defined destination:
+ */
+
+ material = cogl_material_new ();
+ cogl_material_set_color4ub (material, Sr, Sg, Sb, Sa);
+
+ status = cogl_material_set_blend (material, blend_string, &error);
+ if (!status)
+ {
+ /* This is a failure as it must be equivalent to the new API */
+ g_warning ("Error setting blend string %s: %s",
+ blend_string, error->message);
+ g_assert_not_reached ();
+ }
+
+ cogl_color_init_from_4ub (&blend_const_color, Br, Bg, Bb, Ba);
+ cogl_material_set_blend_constant (material, &blend_const_color);
+
+ cogl_set_source (material);
+ cogl_rectangle (x * QUAD_WIDTH,
+ y * QUAD_WIDTH,
+ x * QUAD_WIDTH + QUAD_WIDTH,
+ y * QUAD_WIDTH + QUAD_WIDTH);
+ cogl_handle_unref (material);
+
+ /* See what we got... */
+
+ check_pixel (x_off, y_off, expected_result);
}
static CoglHandle
@@ -204,9 +251,8 @@ test_tex_combine (TestState *state,
CoglHandle material;
gboolean status;
GError *error = NULL;
- GLubyte pixel[4];
- GLint y_off;
- GLint x_off;
+ int y_off;
+ int x_off;
tex0 = make_texture (tex0_color);
@@ -250,10 +296,6 @@ test_tex_combine (TestState *state,
y_off = y * QUAD_WIDTH + (QUAD_WIDTH / 2);
x_off = x * QUAD_WIDTH + (QUAD_WIDTH / 2);
- cogl_read_pixels (x_off, y_off, 1, 1,
- COGL_READ_PIXELS_COLOR_BUFFER,
- COGL_PIXEL_FORMAT_RGBA_8888_PRE,
- pixel);
if (g_test_verbose ())
{
g_print ("test_tex_combine (%d, %d):\n%s\n", x, y, combine_string);
@@ -264,15 +306,13 @@ test_tex_combine (TestState *state,
Cr, Cg, Cb, Ca);
else
g_print (" combine constant = UNUSED\n");
- g_print (" result = %02x, %02x, %02x, %02x\n",
- pixel[RED], pixel[GREEN], pixel[BLUE], pixel[ALPHA]);
}
- check_pixel (pixel, expected_result);
+ check_pixel (x_off, y_off, expected_result);
}
static void
-on_paint (ClutterActor *actor, TestState *state)
+paint (TestState *state)
{
test_blend (state, 0, 0, /* position */
0xff0000ff, /* src */
@@ -385,48 +425,20 @@ on_paint (ClutterActor *actor, TestState *state)
"RGB = DOT3_RGBA (PREVIOUS, TEXTURE)"
"A = REPLACE (PREVIOUS)",
0x2a2a2abb); /* expected */
-
- /* Comment this out if you want visual feedback for what this test paints */
- clutter_main_quit ();
-}
-
-static gboolean
-queue_redraw (gpointer stage)
-{
- clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
-
- return TRUE;
}
void
test_cogl_blend_strings (TestUtilsGTestFixture *fixture,
void *data)
{
+ TestUtilsSharedState *shared_state = data;
TestState state;
- ClutterActor *stage;
- ClutterActor *group;
- unsigned int idle_source;
-
- stage = clutter_stage_get_default ();
-
- clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
- clutter_actor_get_geometry (stage, &state.stage_geom);
-
- group = clutter_group_new ();
- clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
-
- /* We force continuous redrawing incase someone comments out the
- * clutter_main_quit and wants visual feedback for the test since we
- * wont be doing anything else that will trigger redrawing. */
- idle_source = g_idle_add (queue_redraw, stage);
-
- g_signal_connect (group, "paint", G_CALLBACK (on_paint), &state);
-
- clutter_actor_show_all (stage);
- clutter_main ();
+ cogl_ortho (0, cogl_framebuffer_get_width (shared_state->fb), /* left, right */
+ cogl_framebuffer_get_height (shared_state->fb), 0, /* bottom, top */
+ -1, 100 /* z near, far */);
- g_source_remove (idle_source);
+ paint (&state);
if (g_test_verbose ())
g_print ("OK\n");
diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c
index 4908a47..e26e8b8 100644
--- a/tests/conform/test-conform-main.c
+++ b/tests/conform/test-conform-main.c
@@ -134,7 +134,7 @@ main (int argc, char **argv)
UNPORTED_TEST ("/cogl", test_cogl_fixed);
UNPORTED_TEST ("/cogl", test_cogl_materials);
ADD_TEST ("/cogl", test_cogl_pipeline_user_matrix);
- UNPORTED_TEST ("/cogl", test_cogl_blend_strings);
+ ADD_TEST ("/cogl", test_cogl_blend_strings);
UNPORTED_TEST ("/cogl", test_cogl_premult);
UNPORTED_TEST ("/cogl", test_cogl_readpixels);
UNPORTED_TEST ("/cogl", test_cogl_path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]