summaryrefslogtreecommitdiff
path: root/tests/conform/test-alpha-textures.c
blob: 524ba89547628c4a6a9f953f3321c9d4714a1372 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <cogl/cogl.h>

#include <string.h>

#include "test-utils.h"

static void
create_pipeline (CoglTexture **tex_out,
                 CoglPipeline **pipeline_out)
{
  CoglTexture2D *tex;
  CoglPipeline *pipeline;
  static const uint8_t tex_data[] =
    { 0x00, 0x44, 0x88, 0xcc };

  tex = cogl_texture_2d_new_from_data (test_ctx,
                                       2, 2, /* width/height */
                                       COGL_PIXEL_FORMAT_A_8, /* format */
                                       COGL_PIXEL_FORMAT_ANY, /* int. format */
                                       2, /* rowstride */
                                       tex_data,
                                       NULL);

  pipeline = cogl_pipeline_new (test_ctx);

  cogl_pipeline_set_layer_filters (pipeline,
                                   0, /* layer */
                                   COGL_PIPELINE_FILTER_NEAREST,
                                   COGL_PIPELINE_FILTER_NEAREST);
  cogl_pipeline_set_layer_wrap_mode (pipeline,
                                     0, /* layer */
                                     COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE);

  /* This is the layer combine used by cogl-pango */
  cogl_pipeline_set_layer_combine (pipeline,
                                   0, /* layer */
                                   "RGBA = MODULATE (PREVIOUS, TEXTURE[A])",
                                   NULL);

  cogl_pipeline_set_layer_texture (pipeline,
                                   0, /* layer */
                                   tex);

  *pipeline_out = pipeline;
  *tex_out = tex;
}

void
test_alpha_textures (void)
{
  CoglTexture *tex1, *tex2;
  CoglPipeline *pipeline1, *pipeline2;
  int fb_width = cogl_framebuffer_get_width (test_fb);
  int fb_height = cogl_framebuffer_get_height (test_fb);
  uint8_t replacement_data[1] = { 0xff };

  create_pipeline (&tex1, &pipeline1);

  cogl_framebuffer_draw_rectangle (test_fb,
                                   pipeline1,
                                   -1.0f, 1.0f, /* x1/y1 */
                                   1.0f, 0.0f /* x2/y2 */);

  create_pipeline (&tex2, &pipeline2);

  cogl_texture_set_region (tex2,
                           1, 1, /* width / height */
                           COGL_PIXEL_FORMAT_A_8,
                           1, /* rowstride */
                           replacement_data,
                           1, 1, /* dst_x/y */
                           0, /* level */
                           NULL); /* abort on error */

  cogl_framebuffer_draw_rectangle (test_fb,
                                   pipeline2,
                                   -1.0f, 0.0f, /* x1/y1 */
                                   1.0f, -1.0f /* x2/y2 */);

  cogl_object_unref (tex1);
  cogl_object_unref (tex2);
  cogl_object_unref (pipeline1);
  cogl_object_unref (pipeline2);

  /* Unmodified texture */
  test_utils_check_pixel (test_fb,
                          fb_width / 4,
                          fb_height / 8,
                          0x000000ff);
  test_utils_check_pixel (test_fb,
                          fb_width * 3 / 4,
                          fb_height / 8,
                          0x444444ff);
  test_utils_check_pixel (test_fb,
                          fb_width / 4,
                          fb_height * 3 / 8,
                          0x888888ff);
  test_utils_check_pixel (test_fb,
                          fb_width * 3 / 4,
                          fb_height * 3 / 8,
                          0xccccccff);

  /* Modified texture */
  test_utils_check_pixel (test_fb,
                          fb_width / 4,
                          fb_height * 5 / 8,
                          0x000000ff);
  test_utils_check_pixel (test_fb,
                          fb_width * 3 / 4,
                          fb_height * 5 / 8,
                          0x444444ff);
  test_utils_check_pixel (test_fb,
                          fb_width / 4,
                          fb_height * 7 / 8,
                          0x888888ff);
  test_utils_check_pixel (test_fb,
                          fb_width * 3 / 4,
                          fb_height * 7 / 8,
                          0xffffffff);

  if (cogl_test_verbose ())
    g_print ("OK\n");
}