~noskcaj/ubuntu/trusty/cogl/1.16.2

« back to all changes in this revision

Viewing changes to tests/conform/test-primitive-and-journal.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha, Jeremy Bicha, Rico Tzschichholz
  • Date: 2013-02-26 16:43:25 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130226164325-t4z9rylpa20v0p6q
Tags: 1.13.4-0ubuntu1
[ Jeremy Bicha ]
* New upstream release
  - soname bump
* debian/control.in:
  - Bump minimum glib to 2.32
  - Drop obsolete breaks/replaces
  - Bump libclutter-1.0-dev breaks for soname transition
* debian/libcogl-dev.install:
  - Add some missing files

[ Rico Tzschichholz ]
* debian/control.in:
  - Build-depend on libxrandr-dev

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
typedef CoglVertexP2C4 Vertex;
 
6
 
 
7
static void
 
8
setup_orthographic_modelview (void)
 
9
{
 
10
  CoglMatrix matrix;
 
11
  int fb_width = cogl_framebuffer_get_width (test_fb);
 
12
  int fb_height = cogl_framebuffer_get_height (test_fb);
 
13
 
 
14
  /* Set up a non-identity modelview matrix. When the journal is
 
15
   * flushed it will usually flush the identity matrix. Using the
 
16
   * non-default matrix ensures that we test that Cogl restores the
 
17
   * matrix we asked for. The matrix sets up an orthographic transform
 
18
   * in the modelview matrix */
 
19
 
 
20
  cogl_matrix_init_identity (&matrix);
 
21
  cogl_matrix_orthographic (&matrix,
 
22
                            0.0f, 0.0f, /* x_1 y_1 */
 
23
                            fb_width,
 
24
                            fb_height,
 
25
                            -1.0f, /* nearval */
 
26
                            1.0f /* farval */);
 
27
  cogl_framebuffer_set_modelview_matrix (test_fb, &matrix);
 
28
}
 
29
 
 
30
static void
 
31
create_primitives (CoglPrimitive *primitives[2])
 
32
{
 
33
  static const Vertex vertex_data[8] =
 
34
    {
 
35
      /* triangle strip 1 */
 
36
      {   0,   0, 255, 0, 0, 255 },
 
37
      {   0, 100, 255, 0, 0, 255 },
 
38
      { 100,   0, 255, 0, 0, 255 },
 
39
      { 100, 100, 255, 0, 0, 255 },
 
40
      /* triangle strip 2 */
 
41
      { 200,   0, 0, 0, 255, 255 },
 
42
      { 200, 100, 0, 0, 255, 255 },
 
43
      { 300,   0, 0, 0, 255, 255 },
 
44
      { 300, 100, 0, 0, 255, 255 },
 
45
    };
 
46
 
 
47
  primitives[0] = cogl_primitive_new_p2c4 (test_ctx,
 
48
                                           COGL_VERTICES_MODE_TRIANGLE_STRIP,
 
49
                                           G_N_ELEMENTS (vertex_data),
 
50
                                           vertex_data);
 
51
  cogl_primitive_set_n_vertices (primitives[0], 4);
 
52
 
 
53
  primitives[1] = cogl_primitive_copy (primitives[0]);
 
54
  cogl_primitive_set_first_vertex (primitives[1], 4);
 
55
  cogl_primitive_set_n_vertices (primitives[1], 4);
 
56
}
 
57
 
 
58
static CoglPipeline *
 
59
create_pipeline (void)
 
60
{
 
61
  CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
 
62
 
 
63
  cogl_pipeline_set_color4ub (pipeline, 0, 255, 0, 255);
 
64
 
 
65
  return pipeline;
 
66
}
 
67
 
 
68
void
 
69
test_primitive_and_journal (void)
 
70
{
 
71
  CoglPrimitive *primitives[2];
 
72
  CoglPipeline *pipeline;
 
73
 
 
74
  setup_orthographic_modelview ();
 
75
  create_primitives (primitives);
 
76
  pipeline = create_pipeline ();
 
77
 
 
78
  /* Set a clip to clip all three rectangles to just the bottom half.
 
79
   * The journal flushes its own clip state so this verifies that the
 
80
   * clip state is correctly restored for the second primitive. */
 
81
  cogl_framebuffer_push_rectangle_clip (test_fb,
 
82
                                        0, 50, 300, 100);
 
83
 
 
84
  cogl_framebuffer_draw_primitive (test_fb,
 
85
                                   pipeline,
 
86
                                   primitives[0]);
 
87
 
 
88
  /* Draw a rectangle using the journal in-between the two primitives.
 
89
   * This should test that the journal gets flushed correctly and that
 
90
   * the modelview matrix is restored. Half of the rectangle should be
 
91
   * overriden by the second primitive */
 
92
  cogl_framebuffer_draw_rectangle (test_fb,
 
93
                                   pipeline,
 
94
                                   100, 0, /* x1/y1 */
 
95
                                   300, 100 /* x2/y2 */);
 
96
 
 
97
  cogl_framebuffer_draw_primitive (test_fb,
 
98
                                   pipeline,
 
99
                                   primitives[1]);
 
100
 
 
101
  /* Check the three rectangles */
 
102
  test_utils_check_region (test_fb,
 
103
                           1, 51,
 
104
                           98, 48,
 
105
                           0xff0000ff);
 
106
  test_utils_check_region (test_fb,
 
107
                           101, 51,
 
108
                           98, 48,
 
109
                           0x00ff00ff);
 
110
  test_utils_check_region (test_fb,
 
111
                           201, 51,
 
112
                           98, 48,
 
113
                           0x0000ffff);
 
114
 
 
115
  /* Check that the top half of all of the rectangles was clipped */
 
116
  test_utils_check_region (test_fb,
 
117
                           1, 1,
 
118
                           298, 48,
 
119
                           0x000000ff);
 
120
 
 
121
  cogl_framebuffer_pop_clip (test_fb);
 
122
 
 
123
  if (cogl_test_verbose ())
 
124
    g_print ("OK\n");
 
125
}
 
126