mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 17:40:40 -05:00
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)
This commit is contained in:
parent
8f9151303d
commit
f4fd724caf
@ -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 \
|
||||
|
64
tests/conform/test-blend.c
Normal file
64
tests/conform/test-blend.c
Normal file
@ -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 ();
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -265,6 +265,20 @@ test_utils_check_pixel (CoglFramebuffer *test_fb,
|
||||
test_utils_compare_pixel (pixel, expected_pixel);
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user