perf/pixel-rate: new pixel throughput microbenchmark
[piglit.git] / tests / spec / gl-1.0 / rendermode-feedback.c
blob2e7325ccff96a8ae7db62f3337f9f1b7287931e2
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 struct piglit_subtest tests[ARRAY_SIZE(types) + 1];
99 static enum piglit_result run_subtest(void * data);
100 static const struct piglit_gl_test_config * piglit_config;
102 PIGLIT_GL_TEST_CONFIG_BEGIN
104 piglit_config = &config;
106 for (unsigned i = 0; i < ARRAY_SIZE(types); ++i) {
107 tests[i].name = piglit_get_gl_enum_name(types[i].type);
108 tests[i].option = tests[i].name;
109 tests[i].subtest_func = run_subtest;
110 tests[i].data = (void *)&types[i];
113 tests[ARRAY_SIZE(types)].name = NULL;
115 config.subtests = tests;
117 config.supports_gl_compat_version = 10;
119 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
120 config.khr_no_error_support = PIGLIT_NO_ERRORS;
122 PIGLIT_GL_TEST_CONFIG_END
124 static void
125 report_failure(struct type *type, float *buffer, int count)
127 int i;
129 fprintf(stderr, "Feedback failed for %s:\n",
130 piglit_get_gl_enum_name(type->type));
132 fprintf(stderr, " Expected: Observed: (%d/%d)\n",
133 count, type->count);
134 for (i = 0; i < types->count; i++) {
135 fprintf(stderr, " %9f %9f\n", type->values[i], buffer[i]);
137 fprintf(stderr, "\n");
140 static enum piglit_result
141 run_subtest(void * data) {
142 struct type * type = (struct type *)data;
143 bool case_pass = true;
144 int returned_count, j;
145 const char *name = piglit_get_gl_enum_name(type->type);
146 float buffer[2 +
147 ARRAY_SIZE(vertex_array) +
148 ARRAY_SIZE(color_array) +
149 ARRAY_SIZE(texcoord_array)];
151 printf("Testing %s\n", name);
153 for (j = 0; j < ARRAY_SIZE(buffer); j++)
154 buffer[j] = -1.0;
156 glFeedbackBuffer(ARRAY_SIZE(buffer), type->type, buffer);
157 glRenderMode(GL_FEEDBACK);
158 glDrawArrays(GL_TRIANGLES, 0, 4);
159 returned_count = glRenderMode(GL_RENDER);
161 if (returned_count != type->count) {
162 case_pass = false;
163 } else {
164 for (j = 0; j < type->count; j++) {
165 if (fabs(buffer[j] - type->values[j]) > .01)
166 case_pass = false;
170 if (!case_pass) {
171 report_failure(type, buffer, returned_count);
173 return case_pass ? PIGLIT_PASS : PIGLIT_FAIL;
176 enum piglit_result
177 piglit_display(void)
179 enum piglit_result result = PIGLIT_PASS;
181 piglit_ortho_projection(piglit_width, piglit_height, false);
183 glClearColor(0.0, 1.0, 0.0, 0.0);
184 glClear(GL_COLOR_BUFFER_BIT);
186 glVertexPointer(4, GL_FLOAT, 0, vertex_array);
187 glColorPointer(4, GL_FLOAT, 0, color_array);
188 glTexCoordPointer(4, GL_FLOAT, 0, texcoord_array);
189 glEnableClientState(GL_VERTEX_ARRAY);
190 glEnableClientState(GL_COLOR_ARRAY);
191 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
193 result = piglit_run_selected_subtests(
194 piglit_config->subtests,
195 piglit_config->selected_subtests,
196 piglit_config->num_selected_subtests,
197 result);
199 piglit_present_results();
201 return result;
204 void
205 piglit_init(int argc, char **argv)
207 piglit_require_extension("GL_EXT_vertex_array");