~darkxst/ubuntu/raring/cogl/lp1163025

« back to all changes in this revision

Viewing changes to tests/conform/test-pipeline-user-matrix.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-03-13 19:11:11 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120313191111-3hgk529qkh9m6uk2
Tags: 1.9.8-0ubuntu1
* New upstream release (LP: #941617)
* Updated symbols & library name for soname update
* debian/control.in: Bump minimum glib to 2.28
* debian/patches/02_disable_armv5t_specific_optimization.patch: Disabled

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cogl/cogl.h>
 
2
 
 
3
#include <string.h>
 
4
 
 
5
#include "test-utils.h"
 
6
 
 
7
typedef struct _TestState
 
8
{
 
9
  CoglContext *ctx;
 
10
  int width;
 
11
  int height;
 
12
} TestState;
 
13
 
 
14
static void
 
15
validate_result (TestState *state)
 
16
{
 
17
  guint32 *pixels, *p;
 
18
  char *screen_pixel;
 
19
  const char *intended_pixel = "#ffffff";
 
20
 
 
21
  /* The textures are setup so that when added together with the
 
22
     correct matrices then all of the pixels should be white. We can
 
23
     verify this by reading back the entire stage */
 
24
  pixels = g_malloc (state->width * state->height * 4);
 
25
 
 
26
  cogl_read_pixels (0, 0, state->width, state->height,
 
27
                    COGL_READ_PIXELS_COLOR_BUFFER,
 
28
                    COGL_PIXEL_FORMAT_RGBA_8888_PRE,
 
29
                    (guint8 *)pixels);
 
30
 
 
31
  for (p = pixels; p < pixels + state->width * state->height; p++)
 
32
    {
 
33
      screen_pixel = g_strdup_printf ("#%06x", GUINT32_FROM_BE (*p) >> 8);
 
34
      g_assert_cmpstr (screen_pixel, ==, intended_pixel);
 
35
      g_free (screen_pixel);
 
36
    }
 
37
}
 
38
 
 
39
static void
 
40
paint (TestState *state)
 
41
{
 
42
  /* This texture is painted mirrored around the x-axis */
 
43
  guint8 data0[] = {
 
44
    0xff, 0x00, 0x00, /* red -> becomes bottom left */
 
45
    0x00, 0xff, 0x00, /* green -> becomes bottom right */
 
46
    0x00, 0x00, 0xff, /* blue -> becomes top left */
 
47
    0xff, 0x00, 0xff  /* magenta -> becomes top right */
 
48
  };
 
49
  /* This texture is painted mirrored about the y-axis */
 
50
  guint8 data1[] = {
 
51
    0x00, 0xff, 0x00, /* green -> becomes top right */
 
52
    0xff, 0xff, 0x00, /* yellow -> becomes top left */
 
53
    0xff, 0x00, 0xff, /* magenta -> becomes bottom right */
 
54
    0x00, 0xff, 0xff  /* cyan -> becomes bottom left */
 
55
  };
 
56
  CoglColor bg;
 
57
  CoglHandle tex0, tex1;
 
58
  CoglPipeline *pipeline;
 
59
  CoglMatrix matrix;
 
60
  GError *error = NULL;
 
61
 
 
62
  cogl_ortho (0, state->width, /* left, right */
 
63
              state->height, 0, /* bottom, top */
 
64
              -1, 100 /* z near, far */);
 
65
 
 
66
  cogl_color_init_from_4ub (&bg, 0, 0, 0, 255);
 
67
  cogl_clear (&bg, COGL_BUFFER_BIT_COLOR);
 
68
 
 
69
  cogl_matrix_init_identity (&matrix);
 
70
  cogl_set_modelview_matrix (&matrix);
 
71
 
 
72
  tex0 = cogl_texture_new_from_data (2, 2,
 
73
                                     COGL_TEXTURE_NO_ATLAS,
 
74
                                     COGL_PIXEL_FORMAT_RGB_888,
 
75
                                     COGL_PIXEL_FORMAT_ANY,
 
76
                                     6,
 
77
                                     data0);
 
78
  tex1 = cogl_texture_new_from_data (2, 2,
 
79
                                     COGL_TEXTURE_NO_ATLAS,
 
80
                                     COGL_PIXEL_FORMAT_RGB_888,
 
81
                                     COGL_PIXEL_FORMAT_ANY,
 
82
                                     6,
 
83
                                     data1);
 
84
 
 
85
  pipeline = cogl_pipeline_new (state->ctx);
 
86
 
 
87
  /* Set the two textures as layers */
 
88
  cogl_pipeline_set_layer_texture (pipeline, 0, tex0);
 
89
  cogl_pipeline_set_layer_filters (pipeline, 0,
 
90
                                   COGL_PIPELINE_FILTER_NEAREST,
 
91
                                   COGL_PIPELINE_FILTER_NEAREST);
 
92
  cogl_pipeline_set_layer_texture (pipeline, 1, tex1);
 
93
  cogl_pipeline_set_layer_filters (pipeline, 1,
 
94
                                   COGL_PIPELINE_FILTER_NEAREST,
 
95
                                   COGL_PIPELINE_FILTER_NEAREST);
 
96
 
 
97
  /* Set a combine mode so that the two textures get added together */
 
98
  if (!cogl_pipeline_set_layer_combine (pipeline, 1,
 
99
                                        "RGBA=ADD(PREVIOUS, TEXTURE)",
 
100
                                        &error))
 
101
    {
 
102
      g_warning ("Error setting blend string: %s", error->message);
 
103
      g_assert_not_reached ();
 
104
    }
 
105
 
 
106
  /* Set a matrix on the first layer so that it will mirror about the y-axis */
 
107
  cogl_matrix_init_identity (&matrix);
 
108
  cogl_matrix_translate (&matrix, 0.0f, 1.0f, 0.0f);
 
109
  cogl_matrix_scale (&matrix, 1.0f, -1.0f, 1.0f);
 
110
  cogl_pipeline_set_layer_matrix (pipeline, 0, &matrix);
 
111
 
 
112
  /* Set a matrix on the second layer so that it will mirror about the x-axis */
 
113
  cogl_matrix_init_identity (&matrix);
 
114
  cogl_matrix_translate (&matrix, 1.0f, 0.0f, 0.0f);
 
115
  cogl_matrix_scale (&matrix, -1.0f, 1.0f, 1.0f);
 
116
  cogl_pipeline_set_layer_matrix (pipeline, 1, &matrix);
 
117
 
 
118
  cogl_set_source (pipeline);
 
119
  cogl_rectangle (0, 0, state->width, state->height);
 
120
 
 
121
  cogl_handle_unref (tex1);
 
122
  cogl_handle_unref (tex0);
 
123
  cogl_object_unref (pipeline);
 
124
}
 
125
 
 
126
void
 
127
test_cogl_pipeline_user_matrix (TestUtilsGTestFixture *fixture,
 
128
                                void *data)
 
129
{
 
130
  TestUtilsSharedState *shared_state = data;
 
131
  TestState state;
 
132
 
 
133
  state.ctx = shared_state->ctx;
 
134
 
 
135
  state.width = cogl_framebuffer_get_width (shared_state->fb);
 
136
  state.height = cogl_framebuffer_get_height (shared_state->fb);
 
137
 
 
138
  paint (&state);
 
139
  validate_result (&state);
 
140
 
 
141
  if (cogl_test_verbose ())
 
142
    g_print ("OK\n");
 
143
}