summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2013-05-22 19:49:05 +0100
committerRobert Bragg <robert@linux.intel.com>2013-05-30 15:19:13 +0100
commitc15d91f1c6293bebd4494d1e20586121483cddef (patch)
tree253b33705a05a5297c7aef874aabfa2ea8e59cd5 /tests
parentab2ae18f3207514c91fa6fd9f2d3f2ed93a86497 (diff)
downloadcogl-c15d91f1c6293bebd4494d1e20586121483cddef.tar.gz
conform: Add color attribute based blending test
This adds a test to make sure that if the same pipeline is used to draw two primitives, one which doesn't need blending because it has an opaque color associated, and another using a color attribute that requires blending then Cogl should recognize that it needs to enable blending for the second primitive even though the pipeline hasn't changed. Reviewed-by: Neil Roberts <neil@linux.intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/conform/Makefile.am1
-rw-r--r--tests/conform/test-blend.c64
-rw-r--r--tests/conform/test-conform-main.c1
-rw-r--r--tests/conform/test-utils.c14
-rw-r--r--tests/conform/test-utils.h18
5 files changed, 98 insertions, 0 deletions
diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
index 8b73c53f..e4457419 100644
--- a/tests/conform/Makefile.am
+++ b/tests/conform/Makefile.am
@@ -28,6 +28,7 @@ unported_test_sources = \
test_sources = \
test-atlas-migration.c \
test-blend-strings.c \
+ test-blend.c \
test-depth-test.c \
test-color-hsl.c \
test-color-mask.c \
diff --git a/tests/conform/test-blend.c b/tests/conform/test-blend.c
new file mode 100644
index 00000000..e67f11b0
--- /dev/null
+++ b/tests/conform/test-blend.c
@@ -0,0 +1,64 @@
+#include <cogl/cogl.h>
+
+#include <string.h>
+
+#include "test-utils.h"
+
+static void
+paint (void)
+{
+ CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
+ int width = cogl_framebuffer_get_width (test_fb);
+ int half_width = width / 2;
+ int height = cogl_framebuffer_get_height (test_fb);
+ CoglVertexP2 tri0_vertices[] = {
+ { 0, 0 },
+ { 0, height },
+ { half_width, height },
+ };
+ CoglVertexP2C4 tri1_vertices[] = {
+ { half_width, 0, 0x80, 0x80, 0x80, 0x80 },
+ { half_width, height, 0x80, 0x80, 0x80, 0x80 },
+ { width, height, 0x80, 0x80, 0x80, 0x80 },
+ };
+ CoglPrimitive *tri0;
+ CoglPrimitive *tri1;
+
+ cogl_framebuffer_clear4f (test_fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 0);
+
+ tri0 = cogl_primitive_new_p2 (test_ctx, COGL_VERTICES_MODE_TRIANGLES,
+ 3, tri0_vertices);
+ tri1 = cogl_primitive_new_p2c4 (test_ctx, COGL_VERTICES_MODE_TRIANGLES,
+ 3, tri1_vertices);
+
+ /* Check that cogl correctly handles the case where we draw
+ * different primitives same pipeline and switch from using the
+ * opaque color associated with the pipeline and using a colour
+ * attribute with an alpha component which implies blending is
+ * required.
+ *
+ * If Cogl gets this wrong then then in all likelyhood the second
+ * primitive will be drawn with blending still disabled.
+ */
+
+ cogl_framebuffer_draw_primitive (test_fb, pipeline, tri0);
+ cogl_framebuffer_draw_primitive (test_fb, pipeline, tri1);
+
+ test_utils_check_pixel_and_alpha (test_fb,
+ half_width + 5,
+ height - 5,
+ 0x80808080);
+}
+
+void
+test_blend (void)
+{
+ cogl_framebuffer_orthographic (test_fb, 0, 0,
+ cogl_framebuffer_get_width (test_fb),
+ cogl_framebuffer_get_height (test_fb),
+ -1,
+ 100);
+
+ paint ();
+}
+
diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c
index 671d0b24..c0234f21 100644
--- a/tests/conform/test-conform-main.c
+++ b/tests/conform/test-conform-main.c
@@ -53,6 +53,7 @@ main (int argc, char **argv)
UNPORTED_TEST (test_fixed);
UNPORTED_TEST (test_materials);
ADD_TEST (test_blend_strings, 0, 0);
+ ADD_TEST (test_blend, 0, 0);
ADD_TEST (test_premult, 0, 0);
UNPORTED_TEST (test_readpixels);
ADD_TEST (test_path, 0, 0);
diff --git a/tests/conform/test-utils.c b/tests/conform/test-utils.c
index a10019ad..b8f2dcd9 100644
--- a/tests/conform/test-utils.c
+++ b/tests/conform/test-utils.c
@@ -265,6 +265,20 @@ test_utils_check_pixel (CoglFramebuffer *fb,
}
void
+test_utils_check_pixel_and_alpha (CoglFramebuffer *fb,
+ int x, int y, uint32_t expected_pixel)
+{
+ uint8_t pixel[4];
+
+ cogl_framebuffer_read_pixels (fb,
+ x, y, 1, 1,
+ COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+ pixel);
+
+ test_utils_compare_pixel_and_alpha (pixel, expected_pixel);
+}
+
+void
test_utils_check_pixel_rgb (CoglFramebuffer *fb,
int x, int y, int r, int g, int b)
{
diff --git a/tests/conform/test-utils.h b/tests/conform/test-utils.h
index ae2fb64f..49dbe1b5 100644
--- a/tests/conform/test-utils.h
+++ b/tests/conform/test-utils.h
@@ -52,6 +52,24 @@ void
test_utils_check_pixel (CoglFramebuffer *framebuffer,
int x, int y, uint32_t expected_pixel);
+/**
+ * @framebuffer: The #CoglFramebuffer to read from
+ * @x: x co-ordinate of the pixel to test
+ * @y: y co-ordinate of the pixel to test
+ * @pixel: An integer of the form 0xRRGGBBAA representing the expected
+ * pixel value
+ *
+ * This performs reads a pixel on the given cogl @framebuffer and
+ * asserts that it matches the given color. The alpha channel is also
+ * checked unlike with test_utils_check_pixel(). The pixels are
+ * converted to a string and compared with g_assert_cmpstr so that if
+ * the comparison fails then the assert will display a meaningful
+ * message.
+ */
+void
+test_utils_check_pixel_and_alpha (CoglFramebuffer *fb,
+ int x, int y, uint32_t expected_pixel);
+
/*
* test_utils_check_pixel:
* @framebuffer: The #CoglFramebuffer to read from