1 /*
2 * Copyright © 2012 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 /**
25 * \file api.c
26 *
27 * Test miscellaneous other entrypoints for GL_ARB_occlusion_query2.
28 */
29
30 #include "piglit-util-gl.h"
31
32 PIGLIT_GL_TEST_CONFIG_BEGIN
33
34 config.supports_gl_compat_version = 10;
35 config.window_visual = (PIGLIT_GL_VISUAL_RGB |
36 PIGLIT_GL_VISUAL_DOUBLE |
37 PIGLIT_GL_VISUAL_DEPTH);
38 config.khr_no_error_support = PIGLIT_NO_ERRORS;
39
40 PIGLIT_GL_TEST_CONFIG_END
41
42 static bool
test_error_begin_while_other_active(void)43 test_error_begin_while_other_active(void)
44 {
45 GLuint oq[2];
46 bool pass = true;
47
48 /* GL_ARB_occlusion_query2 specifies INVALID_OPERATION for
49 * starting either query type with the other one active.
50 */
51 glGenQueries(2, oq);
52
53 glBeginQuery(GL_SAMPLES_PASSED, oq[0]);
54 if (!piglit_check_gl_error(0))
55 pass = false;
56 glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[1]);
57 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
58 pass = false;
59 glEndQuery(GL_ANY_SAMPLES_PASSED);
60 glEndQuery(GL_SAMPLES_PASSED);
61 piglit_reset_gl_error();
62
63 glDeleteQueries(2, oq);
64
65 glGenQueries(2, oq);
66
67 glBeginQuery(GL_ANY_SAMPLES_PASSED, oq[0]);
68 if (!piglit_check_gl_error(0))
69 pass = false;
70 glBeginQuery(GL_SAMPLES_PASSED, oq[1]);
71 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
72 pass = false;
73 glEndQuery(GL_SAMPLES_PASSED);
74 glEndQuery(GL_ANY_SAMPLES_PASSED);
75 piglit_reset_gl_error();
76
77 glDeleteQueries(2, oq);
78
79 return pass;
80 }
81
82 static bool
test_counter_bits(void)83 test_counter_bits(void)
84 {
85 GLint result = -1;
86
87 /* From the GL_ARB_occlusion_query2 spec:
88 *
89 * "Modify the paragraph beginning with "For occlusion
90 * queries (SAMPLES_PASSED)..."
91 *
92 * For occlusion queries
93 * | (SAMPLES_PASSED and ANY_SAMPLES_PASSED), the number of bits
94 * | depends on the target. For a target of ANY_SAMPLES_PASSED, if
95 * | the number of bits is non-zero, the minimum number of bits
96 * | is 1. For a target of SAMPLES_PASSED,
97 * if the number of bits is non-zero, ..."
98 *
99 * So, the number of bits has to be either a zero or >= 1.
100 */
101 glGetQueryiv(GL_ANY_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS, &result);
102 if (result < 0) {
103 fprintf(stderr, "GL_QUERY_COUNTER_BITS returned %d\n", result);
104 return false;
105 }
106 return true;
107 }
108
109 static bool
test_error_begin_wrong_target(void)110 test_error_begin_wrong_target(void)
111 {
112 bool pass = true;
113 GLuint oq;
114
115 glGenQueries(1, &oq);
116
117 glBeginQuery(GL_SAMPLES_PASSED, oq);
118 if (!piglit_check_gl_error(0))
119 pass = false;
120 glEndQuery(GL_SAMPLES_PASSED);
121
122 /* From the OpenGL 3.3 spec, section "2.14. ASYNCHRONOUS QUERIES", page 94:
123 *
124 * "[...] if id is the name of an existing query object whose type does not
125 * match target, [...] the error INVALID_OPERATION is generated."
126 *
127 * Similar wording exists in the OpenGL ES 3.0.0 spec, section "2.13.
128 * ASYNCHRONOUS QUERIES", page 82.
129 */
130 glBeginQuery(GL_ANY_SAMPLES_PASSED, oq);
131 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
132 pass = false;
133 glEndQuery(GL_ANY_SAMPLES_PASSED);
134 piglit_reset_gl_error();
135
136 glDeleteQueries(1, &oq);
137
138 return pass;
139 }
140
141 static bool
test_error_end_wrong_target(void)142 test_error_end_wrong_target(void)
143 {
144 bool pass = true;
145 GLuint oq;
146
147 glGenQueries(1, &oq);
148
149 /* From the GL_ARB_occlusion_query2 spec:
150 *
151 * "If EndQueryARB is called while no query with the same
152 * target is in progress, an INVALID_OPERATION error is
153 * generated."
154 */
155 glBeginQuery(GL_SAMPLES_PASSED, oq);
156 if (!piglit_check_gl_error(0))
157 pass = false;
158 glEndQuery(GL_ANY_SAMPLES_PASSED);
159 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
160 pass = false;
161 glEndQuery(GL_SAMPLES_PASSED);
162 piglit_reset_gl_error();
163
164 glDeleteQueries(1, &oq);
165
166 glGenQueries(1, &oq);
167
168 glBeginQuery(GL_ANY_SAMPLES_PASSED, oq);
169 if (!piglit_check_gl_error(0))
170 pass = false;
171 glEndQuery(GL_SAMPLES_PASSED);
172 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
173 pass = false;
174 glEndQuery(GL_ANY_SAMPLES_PASSED);
175 piglit_reset_gl_error();
176
177 glDeleteQueries(1, &oq);
178
179 return pass;
180 }
181
182 static bool
test_current_query(void)183 test_current_query(void)
184 {
185 bool pass = true;
186 GLint result = -1;
187 GLuint oq;
188
189 glGenQueries(1, &oq);
190
191 /* Test that GL_CURRENT_QUERY returns our target and not the
192 * other one. First, check that we're inactive after the
193 * previous sequence of query code.
194 */
195 result = -1;
196 glGetQueryiv(GL_ANY_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
197 if (result != 0) {
198 fprintf(stderr,
199 "GL_CURRENT_QUERY(GL_ANY_SAMPLES_PASSED) returned %d "
200 "while inactive\n",
201 result);
202 pass = false;
203 }
204 result = -1;
205 glGetQueryiv(GL_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
206 if (result != 0) {
207 fprintf(stderr,
208 "GL_CURRENT_QUERY(GL_SAMPLES_PASSED) returned %d "
209 "while inactive\n",
210 result);
211 pass = false;
212 }
213
214 /* Test the result for GL_ANY_SAMPLES_PASSED active */
215 glBeginQuery(GL_ANY_SAMPLES_PASSED, oq);
216 result = -1;
217 glGetQueryiv(GL_ANY_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
218 if (result != oq) {
219 fprintf(stderr,
220 "GL_CURRENT_QUERY(GL_ANY_SAMPLES_PASSED) returned %d "
221 "while GL_ANY_SAMPLES_PASSED active\n",
222 result);
223 pass = false;
224 }
225 result = -1;
226 glGetQueryiv(GL_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
227 if (result != 0) {
228 fprintf(stderr,
229 "GL_CURRENT_QUERY(GL_SAMPLES_PASSED) returned %d while "
230 "GL_ANY_SAMPLES_PASSED active\n",
231 result);
232 pass = false;
233 }
234 glEndQuery(GL_ANY_SAMPLES_PASSED);
235 glDeleteQueries(1, &oq);
236
237 glGenQueries(1, &oq);
238
239 /* Test the result for GL_SAMPLES_PASSED active */
240 glBeginQuery(GL_SAMPLES_PASSED, oq);
241 result = -1;
242 glGetQueryiv(GL_ANY_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
243 if (result != 0) {
244 fprintf(stderr,
245 "GL_CURRENT_QUERY(GL_ANY_SAMPLES_PASSED) returned %d "
246 "while GL_SAMPLES_PASSED active\n",
247 result);
248 pass = false;
249 }
250 result = -1;
251 glGetQueryiv(GL_SAMPLES_PASSED, GL_CURRENT_QUERY, &result);
252 if (result != oq) {
253 fprintf(stderr,
254 "GL_CURRENT_QUERY(GL_SAMPLES_PASSED) returned %d "
255 "while GL_SAMPLES_PASSED active\n",
256 result);
257 pass = false;
258 }
259 glEndQuery(GL_SAMPLES_PASSED);
260
261 glDeleteQueries(1, &oq);
262
263 return pass;
264 }
265
266 enum piglit_result
piglit_display(void)267 piglit_display(void)
268 {
269 bool pass = true;
270
271 pass = test_counter_bits() && pass;
272 pass = test_current_query() && pass;
273
274 if (!piglit_khr_no_error) {
275 pass = test_error_begin_wrong_target() && pass;
276 pass = test_error_end_wrong_target() && pass;
277 pass = test_error_begin_while_other_active() && pass;
278 }
279
280 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
281
282 /* UNREACHED */
283 return PIGLIT_FAIL;
284 }
285
286 void
piglit_init(int argc,char ** argv)287 piglit_init(int argc, char **argv)
288 {
289 piglit_require_extension("GL_ARB_occlusion_query2");
290 }
291