~elementary-os/elementaryos/os-patch-mutter-bionic

« back to all changes in this revision

Viewing changes to cogl/tests/conform/test-alpha-test.c

  • Committer: RabbitBot
  • Date: 2018-04-11 14:49:36 UTC
  • Revision ID: rabbitbot@elementary.io-20180411144936-hgymqa9d8d1xfpbh
Initial import, version 3.28.0-2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cogl/cogl.h>
 
2
#include <string.h>
 
3
 
 
4
#include "test-utils.h"
 
5
 
 
6
static CoglTexture2D *
 
7
create_texture (CoglContext *context)
 
8
{
 
9
  static const uint8_t data[] =
 
10
    {
 
11
      0xff, 0x00, 0x00, 0xff,
 
12
      0x00, 0xfa, 0x00, 0xfa
 
13
    };
 
14
 
 
15
  return cogl_texture_2d_new_from_data (context,
 
16
                                        2, 1, /* width/height */
 
17
                                        COGL_PIXEL_FORMAT_RGBA_8888_PRE,
 
18
                                        4, /* rowstride */
 
19
                                        data,
 
20
                                        NULL /* error */);
 
21
}
 
22
 
 
23
void
 
24
test_alpha_test (void)
 
25
{
 
26
  CoglTexture *tex = create_texture (test_ctx);
 
27
  CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
 
28
  int fb_width = cogl_framebuffer_get_width (test_fb);
 
29
  int fb_height = cogl_framebuffer_get_height (test_fb);
 
30
  CoglColor clear_color;
 
31
 
 
32
  cogl_pipeline_set_layer_texture (pipeline, 0, tex);
 
33
  cogl_pipeline_set_layer_filters (pipeline, 0,
 
34
                                   COGL_PIPELINE_FILTER_NEAREST,
 
35
                                   COGL_PIPELINE_FILTER_NEAREST);
 
36
  cogl_pipeline_set_alpha_test_function (pipeline,
 
37
                                         COGL_PIPELINE_ALPHA_FUNC_GEQUAL,
 
38
                                         254 / 255.0f /* alpha reference */);
 
39
 
 
40
  cogl_color_init_from_4ub (&clear_color, 0x00, 0x00, 0xff, 0xff);
 
41
  cogl_framebuffer_clear (test_fb,
 
42
                          COGL_BUFFER_BIT_COLOR,
 
43
                          &clear_color);
 
44
 
 
45
  cogl_framebuffer_draw_rectangle (test_fb,
 
46
                                   pipeline,
 
47
                                   -1, -1,
 
48
                                   1, 1);
 
49
 
 
50
  cogl_object_unref (pipeline);
 
51
  cogl_object_unref (tex);
 
52
 
 
53
  /* The left side of the framebuffer should use the first pixel from
 
54
   * the texture which is red */
 
55
  test_utils_check_region (test_fb,
 
56
                           2, 2,
 
57
                           fb_width / 2 - 4,
 
58
                           fb_height - 4,
 
59
                           0xff0000ff);
 
60
  /* The right side of the framebuffer should use the clear color
 
61
   * because the second pixel from the texture is clipped from the
 
62
   * alpha test */
 
63
  test_utils_check_region (test_fb,
 
64
                           fb_width / 2 + 2,
 
65
                           2,
 
66
                           fb_width / 2 - 4,
 
67
                           fb_height - 4,
 
68
                           0x0000ffff);
 
69
 
 
70
  if (cogl_test_verbose ())
 
71
    g_print ("OK\n");
 
72
}
 
73