1
#define COGL_VERSION_MIN_REQUIRED COGL_VERSION_1_0
7
#include "test-utils.h"
9
typedef struct _TestState
15
create_dummy_texture (void)
17
/* Create a dummy 1x1 green texture to replace the color from the
19
static const uint8_t data[4] = { 0x00, 0xff, 0x00, 0xff };
21
return test_utils_texture_new_from_data (test_ctx,
23
TEST_UTILS_TEXTURE_NONE,
24
COGL_PIXEL_FORMAT_RGB_888,
30
paint_legacy (TestState *state)
32
CoglHandle material = cogl_material_new ();
35
CoglError *error = NULL;
36
CoglHandle shader, program;
38
cogl_color_init_from_4ub (&color, 0, 0, 0, 255);
39
cogl_clear (&color, COGL_BUFFER_BIT_COLOR);
41
/* Set the primary vertex color as red */
42
cogl_color_set_from_4ub (&color, 0xff, 0x00, 0x00, 0xff);
43
cogl_material_set_color (material, &color);
45
/* Override the vertex color in the texture environment with a
46
constant green color provided by a texture */
47
tex = create_dummy_texture ();
48
cogl_material_set_layer (material, 0, tex);
49
cogl_object_unref (tex);
50
if (!cogl_material_set_layer_combine (material, 0,
51
"RGBA=REPLACE(TEXTURE)",
54
g_warning ("Error setting layer combine: %s", error->message);
55
g_assert_not_reached ();
58
/* Set up a dummy vertex shader that does nothing but the usual
59
fixed function transform */
60
shader = cogl_create_shader (COGL_SHADER_TYPE_VERTEX);
61
cogl_shader_source (shader,
65
" cogl_position_out = "
66
"cogl_modelview_projection_matrix * "
68
" cogl_color_out = cogl_color_in;\n"
69
" cogl_tex_coord_out[0] = cogl_tex_coord_in;\n"
71
cogl_shader_compile (shader);
72
if (!cogl_shader_is_compiled (shader))
74
char *log = cogl_shader_get_info_log (shader);
75
g_warning ("Shader compilation failed:\n%s", log);
77
g_assert_not_reached ();
80
program = cogl_create_program ();
81
cogl_program_attach_shader (program, shader);
82
cogl_program_link (program);
84
cogl_handle_unref (shader);
86
/* Draw something using the material */
87
cogl_set_source (material);
88
cogl_rectangle (0, 0, 50, 50);
90
/* Draw it again using the program. It should look exactly the same */
91
cogl_program_use (program);
92
cogl_rectangle (50, 0, 100, 50);
93
cogl_program_use (COGL_INVALID_HANDLE);
95
cogl_handle_unref (material);
96
cogl_handle_unref (program);
100
paint (TestState *state)
102
CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
105
CoglError *error = NULL;
106
CoglHandle shader, program;
108
cogl_color_init_from_4ub (&color, 0, 0, 0, 255);
109
cogl_clear (&color, COGL_BUFFER_BIT_COLOR);
111
/* Set the primary vertex color as red */
112
cogl_color_set_from_4ub (&color, 0xff, 0x00, 0x00, 0xff);
113
cogl_pipeline_set_color (pipeline, &color);
115
/* Override the vertex color in the texture environment with a
116
constant green color provided by a texture */
117
tex = create_dummy_texture ();
118
cogl_pipeline_set_layer_texture (pipeline, 0, tex);
119
cogl_object_unref (tex);
120
if (!cogl_pipeline_set_layer_combine (pipeline, 0,
121
"RGBA=REPLACE(TEXTURE)",
124
g_warning ("Error setting layer combine: %s", error->message);
125
g_assert_not_reached ();
128
/* Set up a dummy vertex shader that does nothing but the usual
129
fixed function transform */
130
shader = cogl_create_shader (COGL_SHADER_TYPE_VERTEX);
131
cogl_shader_source (shader,
135
" cogl_position_out = "
136
"cogl_modelview_projection_matrix * "
137
"cogl_position_in;\n"
138
" cogl_color_out = cogl_color_in;\n"
139
" cogl_tex_coord_out[0] = cogl_tex_coord_in;\n"
141
cogl_shader_compile (shader);
142
if (!cogl_shader_is_compiled (shader))
144
char *log = cogl_shader_get_info_log (shader);
145
g_warning ("Shader compilation failed:\n%s", log);
147
g_assert_not_reached ();
150
program = cogl_create_program ();
151
cogl_program_attach_shader (program, shader);
152
cogl_program_link (program);
154
cogl_handle_unref (shader);
156
/* Draw something without the program */
157
cogl_set_source (pipeline);
158
cogl_rectangle (0, 0, 50, 50);
160
/* Draw it again using the program. It should look exactly the same */
161
cogl_pipeline_set_user_program (pipeline, program);
162
cogl_handle_unref (program);
164
cogl_rectangle (50, 0, 100, 50);
165
cogl_pipeline_set_user_program (pipeline, COGL_INVALID_HANDLE);
167
cogl_object_unref (pipeline);
171
validate_result (CoglFramebuffer *framebuffer)
173
/* Non-shader version */
174
test_utils_check_pixel (framebuffer, 25, 25, 0x00ff0000);
176
test_utils_check_pixel (framebuffer, 75, 25, 0x00ff0000);
180
test_just_vertex_shader (void)
184
cogl_framebuffer_orthographic (test_fb,
186
cogl_framebuffer_get_width (test_fb),
187
cogl_framebuffer_get_height (test_fb),
191
/* XXX: we have to push/pop a framebuffer since this test currently
192
* uses the legacy cogl_rectangle() api. */
193
cogl_push_framebuffer (test_fb);
195
paint_legacy (&state);
196
validate_result (test_fb);
199
validate_result (test_fb);
201
cogl_pop_framebuffer ();
203
if (cogl_test_verbose ())