5
#include "test-utils.h"
7
typedef struct _TestState
15
validate_result (TestState *state)
19
const char *intended_pixel = "#ffffff";
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);
26
cogl_read_pixels (0, 0, state->width, state->height,
27
COGL_READ_PIXELS_COLOR_BUFFER,
28
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
31
for (p = pixels; p < pixels + state->width * state->height; p++)
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);
40
paint (TestState *state)
42
/* This texture is painted mirrored around the x-axis */
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 */
49
/* This texture is painted mirrored about the y-axis */
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 */
57
CoglHandle tex0, tex1;
58
CoglPipeline *pipeline;
62
cogl_ortho (0, state->width, /* left, right */
63
state->height, 0, /* bottom, top */
64
-1, 100 /* z near, far */);
66
cogl_color_init_from_4ub (&bg, 0, 0, 0, 255);
67
cogl_clear (&bg, COGL_BUFFER_BIT_COLOR);
69
cogl_matrix_init_identity (&matrix);
70
cogl_set_modelview_matrix (&matrix);
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,
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,
85
pipeline = cogl_pipeline_new (state->ctx);
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);
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)",
102
g_warning ("Error setting blend string: %s", error->message);
103
g_assert_not_reached ();
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);
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);
118
cogl_set_source (pipeline);
119
cogl_rectangle (0, 0, state->width, state->height);
121
cogl_handle_unref (tex1);
122
cogl_handle_unref (tex0);
123
cogl_object_unref (pipeline);
127
test_cogl_pipeline_user_matrix (TestUtilsGTestFixture *fixture,
130
TestUtilsSharedState *shared_state = data;
133
state.ctx = shared_state->ctx;
135
state.width = cogl_framebuffer_get_width (shared_state->fb);
136
state.height = cogl_framebuffer_get_height (shared_state->fb);
139
validate_result (&state);
141
if (cogl_test_verbose ())