[cogl/cogl-1.16] conform: Add color attribute based blending test



commit f4fd724caf7d55cb8ffb37ccef593bdc51f90b55
Author: Robert Bragg <robert linux intel com>
Date:   Wed May 22 19:49:05 2013 +0100

    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>
    
    (cherry picked from commit c15d91f1c6293bebd4494d1e20586121483cddef)

 tests/conform/Makefile.am         |    1 +
 tests/conform/test-blend.c        |   64 +++++++++++++++++++++++++++++++++++++
 tests/conform/test-conform-main.c |    1 +
 tests/conform/test-utils.c        |   14 ++++++++
 tests/conform/test-utils.h        |   18 ++++++++++
 5 files changed, 98 insertions(+), 0 deletions(-)
---
diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
index 263e761..eddb958 100644
--- a/tests/conform/Makefile.am
+++ b/tests/conform/Makefile.am
@@ -29,6 +29,7 @@ unported_test_sources = \
 test_sources = \
        test-atlas-migration.c \
        test-blend-strings.c \
+       test-blend.c \
        test-depth-test.c \
        test-color-mask.c \
        test-backface-culling.c \
diff --git a/tests/conform/test-blend.c b/tests/conform/test-blend.c
new file mode 100644
index 0000000..e67f11b
--- /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 79f017a..ef90900 100644
--- a/tests/conform/test-conform-main.c
+++ b/tests/conform/test-conform-main.c
@@ -54,6 +54,7 @@ main (int argc, char **argv)
   UNPORTED_TEST (test_materials);
   ADD_TEST (test_pipeline_user_matrix, 0, 0);
   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 e2a089d..827b9dc 100644
--- a/tests/conform/test-utils.c
+++ b/tests/conform/test-utils.c
@@ -266,6 +266,20 @@ test_utils_check_pixel (CoglFramebuffer *test_fb,
 }
 
 void
+test_utils_check_pixel_and_alpha (CoglFramebuffer *test_fb,
+                                  int x, int y, uint32_t expected_pixel)
+{
+  uint8_t pixel[4];
+
+  cogl_framebuffer_read_pixels (test_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 *test_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 ae2fb64..49dbe1b 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]