mirror of
https://github.com/brl/mutter.git
synced 2025-08-10 02:14:42 +00:00
tests/cogl: Migrate alpha test test
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2555>
This commit is contained in:
@@ -26,6 +26,7 @@ cogl_tests = [
|
||||
[ 'test-point-sprite-known-failure', ['gl', 'gl3', 'gles2'] ],
|
||||
[ 'test-no-gl-header', [] ],
|
||||
[ 'test-layer-remove', [] ],
|
||||
[ 'test-alpha-test', [] ],
|
||||
]
|
||||
|
||||
cogl_test_conformance_includes = [
|
||||
|
76
src/tests/cogl/conform/test-alpha-test.c
Normal file
76
src/tests/cogl/conform/test-alpha-test.c
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <cogl/cogl.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tests/cogl-test-utils.h"
|
||||
|
||||
static CoglTexture2D *
|
||||
create_texture (CoglContext *context)
|
||||
{
|
||||
static const uint8_t data[] =
|
||||
{
|
||||
0xff, 0x00, 0x00, 0xff,
|
||||
0x00, 0xfa, 0x00, 0xfa
|
||||
};
|
||||
|
||||
return cogl_texture_2d_new_from_data (context,
|
||||
2, 1, /* width/height */
|
||||
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
||||
4, /* rowstride */
|
||||
data,
|
||||
NULL /* error */);
|
||||
}
|
||||
|
||||
static void
|
||||
test_alpha_test (void)
|
||||
{
|
||||
CoglTexture *tex = create_texture (test_ctx);
|
||||
CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
|
||||
int fb_width = cogl_framebuffer_get_width (test_fb);
|
||||
int fb_height = cogl_framebuffer_get_height (test_fb);
|
||||
CoglColor clear_color;
|
||||
|
||||
cogl_pipeline_set_layer_texture (pipeline, 0, tex);
|
||||
cogl_pipeline_set_layer_filters (pipeline, 0,
|
||||
COGL_PIPELINE_FILTER_NEAREST,
|
||||
COGL_PIPELINE_FILTER_NEAREST);
|
||||
cogl_pipeline_set_alpha_test_function (pipeline,
|
||||
COGL_PIPELINE_ALPHA_FUNC_GEQUAL,
|
||||
254 / 255.0f /* alpha reference */);
|
||||
|
||||
cogl_color_init_from_4ub (&clear_color, 0x00, 0x00, 0xff, 0xff);
|
||||
cogl_framebuffer_clear (test_fb,
|
||||
COGL_BUFFER_BIT_COLOR,
|
||||
&clear_color);
|
||||
|
||||
cogl_framebuffer_draw_rectangle (test_fb,
|
||||
pipeline,
|
||||
-1, -1,
|
||||
1, 1);
|
||||
|
||||
cogl_object_unref (pipeline);
|
||||
cogl_object_unref (tex);
|
||||
|
||||
/* The left side of the framebuffer should use the first pixel from
|
||||
* the texture which is red */
|
||||
test_utils_check_region (test_fb,
|
||||
2, 2,
|
||||
fb_width / 2 - 4,
|
||||
fb_height - 4,
|
||||
0xff0000ff);
|
||||
/* The right side of the framebuffer should use the clear color
|
||||
* because the second pixel from the texture is clipped from the
|
||||
* alpha test */
|
||||
test_utils_check_region (test_fb,
|
||||
fb_width / 2 + 2,
|
||||
2,
|
||||
fb_width / 2 - 4,
|
||||
fb_height - 4,
|
||||
0x0000ffff);
|
||||
|
||||
if (cogl_test_verbose ())
|
||||
g_print ("OK\n");
|
||||
}
|
||||
|
||||
COGL_TEST_SUITE (
|
||||
g_test_add_func ("/alpha-test", test_alpha_test);
|
||||
)
|
Reference in New Issue
Block a user