fix the spelling in whole piglit
[piglit.git] / tests / spec / gl-1.0 / rendermode-feedback.c
blob1515b2beaac91c7ac016f54c00973e0720e19fe7
1 /* Copyright © 2011 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
12 * Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
23 #include "piglit-util-gl.h"
25 /**
26 * @file rendermode-feedback.c
28 * Tests that glRenderMode(GL_FEEDBACK) rendering trivially works.
31 static float vertex_array[] = {
32 1.0, 2.0, 0.4, 1.0,
33 3.0, 4.0, 0.6, 1.0,
34 5.0, 6.0, 0.8, 1.0,
37 static float color_array[] = {
38 0.01, 0.02, 0.03, 0.04,
39 0.05, 0.06, 0.07, 0.08,
40 0.09, 0.10, 0.11, 0.12,
43 static float texcoord_array[] = {
44 101.0, 102.0, 103.0, 104.0,
45 105.0, 106.0, 107.0, 108.0,
46 109.0, 110.0, 111.0, 112.0,
49 static const float gl_2d_values[] =
50 {GL_POLYGON_TOKEN, 3,
51 1.0, 2.0,
52 3.0, 4.0,
53 5.0, 6.0};
55 static const float gl_3d_values[] =
56 {GL_POLYGON_TOKEN, 3,
57 1.0, 2.0, 0.3,
58 3.0, 4.0, 0.2,
59 5.0, 6.0, 0.1};
61 static const float gl_3d_color_values[] =
62 {GL_POLYGON_TOKEN, 3,
63 1.0, 2.0, 0.3, 0.01, 0.02, 0.03, 0.04,
64 3.0, 4.0, 0.2, 0.05, 0.06, 0.07, 0.08,
65 5.0, 6.0, 0.1, 0.09, 0.10, 0.11, 0.12};
67 static const float gl_3d_color_texture_values[] =
68 {GL_POLYGON_TOKEN, 3,
69 1.0, 2.0, 0.3, 0.01, 0.02, 0.03, 0.04, 101.0, 102.0, 103.0, 104.0,
70 3.0, 4.0, 0.2, 0.05, 0.06, 0.07, 0.08, 105.0, 106.0, 107.0, 108.0,
71 5.0, 6.0, 0.1, 0.09, 0.10, 0.11, 0.12, 109.0, 110.0, 111.0, 112.0};
73 static const float gl_4d_color_texture_values[] =
74 {GL_POLYGON_TOKEN, 3,
75 1.0, 2.0, 0.3, 1.0, 0.01, 0.02, 0.03, 0.04, 101.0, 102.0, 103.0, 104.0,
76 3.0, 4.0, 0.2, 1.0, 0.05, 0.06, 0.07, 0.08, 105.0, 106.0, 107.0, 108.0,
77 5.0, 6.0, 0.1, 1.0, 0.09, 0.10, 0.11, 0.12, 109.0, 110.0, 111.0, 112.0};
79 struct type {
80 GLenum type;
81 const float *values;
82 int count;
83 } types[] = {
84 { GL_2D, gl_2d_values, ARRAY_SIZE(gl_2d_values) },
86 { GL_3D, gl_3d_values, ARRAY_SIZE(gl_3d_values) },
88 { GL_3D_COLOR, gl_3d_color_values, ARRAY_SIZE(gl_3d_color_values) },
90 { GL_3D_COLOR_TEXTURE, gl_3d_color_texture_values,
91 ARRAY_SIZE(gl_3d_color_texture_values) },
93 { GL_4D_COLOR_TEXTURE, gl_4d_color_texture_values,
94 ARRAY_SIZE(gl_4d_color_texture_values) },
97 static enum piglit_result run_subtest(void * data);
98 static const struct piglit_gl_test_config * piglit_config;
100 PIGLIT_GL_TEST_CONFIG_BEGIN
102 piglit_config = &config;
104 struct piglit_subtest tests[ARRAY_SIZE(types) + 1] = { 0 };
105 for (unsigned i = 0; i < ARRAY_SIZE(types); ++i) {
106 tests[i].name = piglit_get_gl_enum_name(types[i].type);
107 tests[i].option = tests[i].name;
108 tests[i].subtest_func = run_subtest;
109 tests[i].data = (void *)&types[i];
111 config.subtests = tests;
113 config.supports_gl_compat_version = 10;
115 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
116 config.khr_no_error_support = PIGLIT_NO_ERRORS;
118 PIGLIT_GL_TEST_CONFIG_END
120 static void
121 report_failure(struct type *type, float *buffer, int count)
123 int i;
125 fprintf(stderr, "Feedback failed for %s:\n",
126 piglit_get_gl_enum_name(type->type));
128 fprintf(stderr, " Expected: Observed: (%d/%d)\n",
129 count, type->count);
130 for (i = 0; i < types->count; i++) {
131 fprintf(stderr, " %9f %9f\n", type->values[i], buffer[i]);
133 fprintf(stderr, "\n");
136 static enum piglit_result
137 run_subtest(void * data) {
138 struct type * type = (struct type *)data;
139 bool case_pass = true;
140 int returned_count, j;
141 const char *name = piglit_get_gl_enum_name(type->type);
142 float buffer[2 +
143 ARRAY_SIZE(vertex_array) +
144 ARRAY_SIZE(color_array) +
145 ARRAY_SIZE(texcoord_array)];
147 printf("Testing %s\n", name);
149 for (j = 0; j < ARRAY_SIZE(buffer); j++)
150 buffer[j] = -1.0;
152 glFeedbackBuffer(ARRAY_SIZE(buffer), type->type, buffer);
153 glRenderMode(GL_FEEDBACK);
154 glDrawArrays(GL_TRIANGLES, 0, 4);
155 returned_count = glRenderMode(GL_RENDER);
157 if (returned_count != type->count) {
158 case_pass = false;
159 } else {
160 for (j = 0; j < type->count; j++) {
161 if (fabs(buffer[j] - type->values[j]) > .01)
162 case_pass = false;
166 if (!case_pass) {
167 report_failure(type, buffer, returned_count);
169 return case_pass ? PIGLIT_PASS : PIGLIT_FAIL;
172 enum piglit_result
173 piglit_display(void)
175 enum piglit_result result = PIGLIT_PASS;
177 piglit_ortho_projection(piglit_width, piglit_height, false);
179 glClearColor(0.0, 1.0, 0.0, 0.0);
180 glClear(GL_COLOR_BUFFER_BIT);
182 glVertexPointer(4, GL_FLOAT, 0, vertex_array);
183 glColorPointer(4, GL_FLOAT, 0, color_array);
184 glTexCoordPointer(4, GL_FLOAT, 0, texcoord_array);
185 glEnableClientState(GL_VERTEX_ARRAY);
186 glEnableClientState(GL_COLOR_ARRAY);
187 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
189 result = piglit_run_selected_subtests(
190 piglit_config->subtests,
191 piglit_config->selected_subtests,
192 piglit_config->num_selected_subtests,
193 result);
195 piglit_present_results();
197 return result;
200 void
201 piglit_init(int argc, char **argv)
203 piglit_require_extension("GL_EXT_vertex_array");