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

« back to all changes in this revision

Viewing changes to cogl/tests/conform/test-point-size.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
 
 
3
#include "test-utils.h"
 
4
 
 
5
/* This test assumes the GL driver supports point sizes up to 16
 
6
   pixels. Cogl should probably have some way of querying the size so
 
7
   we start from that instead */
 
8
#define MAX_POINT_SIZE 16
 
9
/* The size of the area that we'll paint each point in */
 
10
#define POINT_BOX_SIZE (MAX_POINT_SIZE * 2)
 
11
 
 
12
static int
 
13
calc_coord_offset (int pos, int pos_index, int point_size)
 
14
{
 
15
  switch (pos_index)
 
16
    {
 
17
    case 0: return pos - point_size / 2 - 2;
 
18
    case 1: return pos - point_size / 2 + 2;
 
19
    case 2: return pos + point_size / 2 - 2;
 
20
    case 3: return pos + point_size / 2 + 2;
 
21
    }
 
22
 
 
23
  g_assert_not_reached ();
 
24
}
 
25
 
 
26
static void
 
27
verify_point_size (CoglFramebuffer *test_fb,
 
28
                   int x_pos,
 
29
                   int y_pos,
 
30
                   int point_size)
 
31
{
 
32
  int y, x;
 
33
 
 
34
  for (y = 0; y < 4; y++)
 
35
    for (x = 0; x < 4; x++)
 
36
      {
 
37
        CoglBool in_point = x >= 1 && x <= 2 && y >= 1 && y <= 2;
 
38
        uint32_t expected_pixel = in_point ? 0x00ff00ff : 0xff0000ff;
 
39
 
 
40
        test_utils_check_pixel (test_fb,
 
41
                                calc_coord_offset (x_pos, x, point_size),
 
42
                                calc_coord_offset (y_pos, y, point_size),
 
43
                                expected_pixel);
 
44
      }
 
45
}
 
46
 
 
47
void
 
48
test_point_size (void)
 
49
{
 
50
  int fb_width = cogl_framebuffer_get_width (test_fb);
 
51
  int fb_height = cogl_framebuffer_get_height (test_fb);
 
52
  int point_size;
 
53
  int x_pos;
 
54
 
 
55
  cogl_framebuffer_orthographic (test_fb,
 
56
                                 0, 0, /* x_1, y_1 */
 
57
                                 fb_width, /* x_2 */
 
58
                                 fb_height /* y_2 */,
 
59
                                 -1, 100 /* near/far */);
 
60
 
 
61
  cogl_framebuffer_clear4f (test_fb,
 
62
                            COGL_BUFFER_BIT_COLOR,
 
63
                            1.0f, 0.0f, 0.0f, 1.0f);
 
64
 
 
65
  /* Try a rendering a single point with a few different point
 
66
     sizes */
 
67
  for (x_pos = 0, point_size = MAX_POINT_SIZE;
 
68
       point_size >= 4;
 
69
       x_pos += POINT_BOX_SIZE, point_size /= 2)
 
70
    {
 
71
      CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
 
72
      CoglVertexP2 point = { x_pos + POINT_BOX_SIZE / 2,
 
73
                             POINT_BOX_SIZE / 2 };
 
74
      CoglPrimitive *prim =
 
75
        cogl_primitive_new_p2 (test_ctx,
 
76
                               COGL_VERTICES_MODE_POINTS,
 
77
                               1, /* n_vertices */
 
78
                               &point);
 
79
 
 
80
      cogl_pipeline_set_point_size (pipeline, point_size);
 
81
      cogl_pipeline_set_color4ub (pipeline, 0, 255, 0, 255);
 
82
      cogl_primitive_draw (prim, test_fb, pipeline);
 
83
 
 
84
      cogl_object_unref (prim);
 
85
      cogl_object_unref (pipeline);
 
86
    }
 
87
 
 
88
  /* Verify all of the points where drawn at the right size */
 
89
  for (x_pos = 0, point_size = MAX_POINT_SIZE;
 
90
       point_size >= 4;
 
91
       x_pos += POINT_BOX_SIZE, point_size /= 2)
 
92
    verify_point_size (test_fb,
 
93
                       x_pos + POINT_BOX_SIZE / 2,
 
94
                       POINT_BOX_SIZE / 2,
 
95
                       point_size);
 
96
 
 
97
  if (cogl_test_verbose ())
 
98
    g_print ("OK\n");
 
99
}