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
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
23 #include "piglit-util-gl.h"
26 * @file rendermode-feedback.c
28 * Tests that glRenderMode(GL_FEEDBACK) rendering trivially works.
31 static float vertex_array
[] = {
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
[] =
55 static const float gl_3d_values
[] =
61 static const float gl_3d_color_values
[] =
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
[] =
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
[] =
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};
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
121 report_failure(struct type
*type
, float *buffer
, int count
)
125 fprintf(stderr
, "Feedback failed for %s:\n",
126 piglit_get_gl_enum_name(type
->type
));
128 fprintf(stderr
, " Expected: Observed: (%d/%d)\n",
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
);
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
++)
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
) {
160 for (j
= 0; j
< type
->count
; j
++) {
161 if (fabs(buffer
[j
] - type
->values
[j
]) > .01)
167 report_failure(type
, buffer
, returned_count
);
169 return case_pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
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
,
195 piglit_present_results();
201 piglit_init(int argc
, char **argv
)
203 piglit_require_extension("GL_EXT_vertex_array");