5
#include "test-utils.h"
7
typedef struct _TestState
13
create_dummy_texture (void)
15
/* Create a dummy 1x1 green texture to replace the color from the
17
static const guint8 data[4] = { 0x00, 0xff, 0x00, 0xff };
19
return cogl_texture_new_from_data (1, 1, /* size */
21
COGL_PIXEL_FORMAT_RGB_888,
22
COGL_PIXEL_FORMAT_ANY,
28
paint_legacy (TestState *state)
30
CoglHandle material = cogl_material_new ();
34
CoglHandle shader, program;
36
cogl_color_init_from_4ub (&color, 0, 0, 0, 255);
37
cogl_clear (&color, COGL_BUFFER_BIT_COLOR);
39
/* Set the primary vertex color as red */
40
cogl_color_set_from_4ub (&color, 0xff, 0x00, 0x00, 0xff);
41
cogl_material_set_color (material, &color);
43
/* Override the vertex color in the texture environment with a
44
constant green color provided by a texture */
45
tex = create_dummy_texture ();
46
cogl_material_set_layer (material, 0, tex);
47
cogl_handle_unref (tex);
48
if (!cogl_material_set_layer_combine (material, 0,
49
"RGBA=REPLACE(TEXTURE)",
52
g_warning ("Error setting layer combine: %s", error->message);
53
g_assert_not_reached ();
56
/* Set up a dummy vertex shader that does nothing but the usual
57
fixed function transform */
58
shader = cogl_create_shader (COGL_SHADER_TYPE_VERTEX);
59
cogl_shader_source (shader,
63
" cogl_position_out = "
64
"cogl_modelview_projection_matrix * "
66
" cogl_color_out = cogl_color_in;\n"
67
" cogl_tex_coord_out[0] = cogl_tex_coord_in;\n"
69
cogl_shader_compile (shader);
70
if (!cogl_shader_is_compiled (shader))
72
char *log = cogl_shader_get_info_log (shader);
73
g_warning ("Shader compilation failed:\n%s", log);
75
g_assert_not_reached ();
78
program = cogl_create_program ();
79
cogl_program_attach_shader (program, shader);
80
cogl_program_link (program);
82
cogl_handle_unref (shader);
84
/* Draw something using the material */
85
cogl_set_source (material);
86
cogl_rectangle (0, 0, 50, 50);
88
/* Draw it again using the program. It should look exactly the same */
89
cogl_program_use (program);
90
cogl_rectangle (50, 0, 100, 50);
91
cogl_program_use (COGL_INVALID_HANDLE);
93
cogl_handle_unref (material);
94
cogl_handle_unref (program);
98
paint (TestState *state)
100
CoglPipeline *pipeline = cogl_pipeline_new (state->ctx);
103
GError *error = NULL;
104
CoglHandle shader, program;
106
cogl_color_init_from_4ub (&color, 0, 0, 0, 255);
107
cogl_clear (&color, COGL_BUFFER_BIT_COLOR);
109
/* Set the primary vertex color as red */
110
cogl_color_set_from_4ub (&color, 0xff, 0x00, 0x00, 0xff);
111
cogl_pipeline_set_color (pipeline, &color);
113
/* Override the vertex color in the texture environment with a
114
constant green color provided by a texture */
115
tex = create_dummy_texture ();
116
cogl_pipeline_set_layer_texture (pipeline, 0, tex);
117
cogl_handle_unref (tex);
118
if (!cogl_pipeline_set_layer_combine (pipeline, 0,
119
"RGBA=REPLACE(TEXTURE)",
122
g_warning ("Error setting layer combine: %s", error->message);
123
g_assert_not_reached ();
126
/* Set up a dummy vertex shader that does nothing but the usual
127
fixed function transform */
128
shader = cogl_create_shader (COGL_SHADER_TYPE_VERTEX);
129
cogl_shader_source (shader,
133
" cogl_position_out = "
134
"cogl_modelview_projection_matrix * "
135
"cogl_position_in;\n"
136
" cogl_color_out = cogl_color_in;\n"
137
" cogl_tex_coord_out[0] = cogl_tex_coord_in;\n"
139
cogl_shader_compile (shader);
140
if (!cogl_shader_is_compiled (shader))
142
char *log = cogl_shader_get_info_log (shader);
143
g_warning ("Shader compilation failed:\n%s", log);
145
g_assert_not_reached ();
148
program = cogl_create_program ();
149
cogl_program_attach_shader (program, shader);
150
cogl_program_link (program);
152
cogl_handle_unref (shader);
154
/* Draw something without the program */
155
cogl_set_source (pipeline);
156
cogl_rectangle (0, 0, 50, 50);
158
/* Draw it again using the program. It should look exactly the same */
159
cogl_pipeline_set_user_program (pipeline, program);
160
cogl_handle_unref (program);
162
cogl_rectangle (50, 0, 100, 50);
163
cogl_pipeline_set_user_program (pipeline, COGL_INVALID_HANDLE);
165
cogl_object_unref (pipeline);
169
validate_result (void)
171
/* Non-shader version */
172
test_utils_check_pixel (25, 25, 0x00ff0000);
174
test_utils_check_pixel (75, 25, 0x00ff0000);
178
test_cogl_just_vertex_shader (TestUtilsGTestFixture *fixture,
181
TestUtilsSharedState *shared_state = data;
184
state.ctx = shared_state->ctx;
186
cogl_ortho (0, cogl_framebuffer_get_width (shared_state->fb), /* left, right */
187
cogl_framebuffer_get_height (shared_state->fb), 0, /* bottom, top */
188
-1, 100 /* z near, far */);
190
/* If shaders aren't supported then we can't run the test */
191
if (cogl_features_available (COGL_FEATURE_SHADERS_GLSL))
193
paint_legacy (&state);
199
if (cogl_test_verbose ())
202
else if (cogl_test_verbose ())
203
g_print ("Skipping\n");