2 * Copyright © 2009,2012 Intel Corporation
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:
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
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
24 * Ian Romanick <ian.d.romanick@intel.com>
25 * Carl Worth <cworth@cworth.org>
29 * \file occlusion_query_order.c
31 * Verify that once one occlusion query has results, all previous
32 * occlusion queries also have results available, as per the spec.:
34 * It must always be true that if any query object
35 * returns a result available of TRUE, all queries of
36 * the same type issued prior to that query must also
37 * return TRUE. [OpenGL 3.1 § 6.1.6]
40 #include "piglit-util-gl.h"
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config
.supports_gl_compat_version
= 10;
45 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_DEPTH
;
46 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
48 PIGLIT_GL_TEST_CONFIG_END
51 draw_some_things(double frac
)
57 y
= frac
* piglit_height
;
61 for (i
=0; i
< 1024; i
++) {
62 glVertex3f(x
, y
, 0.0);
63 glVertex3f(x
+ 1.0, y
, 0.0);
64 glVertex3f(x
+ 1.0, y
+ 1.0, 0.0);
65 glVertex3f(x
, y
+ 1.0, 0.0);
68 if (x
>= piglit_width
) {
71 if (y
>= piglit_height
) {
84 GLuint queries
[NUM_QUERIES
], available
;
85 bool test_pass
= true;
89 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
91 glClearColor(1.0, 0.0, 0.0, 1.0);
92 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
94 glGenQueries(NUM_QUERIES
, queries
);
96 glColor4f(0.0f
, 1.0f
, 0.0f
, 1.0f
);
98 /* Queue up a bunch of drawing with several queries. */
99 for (i
= 0; i
< NUM_QUERIES
- 1; i
++)
101 glBeginQuery(GL_SAMPLES_PASSED
, queries
[i
]);
103 draw_some_things((double)i
/ (NUM_QUERIES
- 1));
105 glEndQuery(GL_SAMPLES_PASSED
);
108 /* Now fire off a query with no drawing. */
109 glBeginQuery(GL_SAMPLES_PASSED
, queries
[NUM_QUERIES
- 1]);
110 glEndQuery(GL_SAMPLES_PASSED
);
112 /* Get the result for the final query. */
113 glGetQueryObjectiv(queries
[NUM_QUERIES
- 1], GL_QUERY_RESULT
, &result
);
115 /* At this point, the results of all the previous queries
116 * should be available.
118 for (i
= 0; i
< NUM_QUERIES
- 1; i
++)
120 glGetQueryObjectuiv(queries
[i
], GL_QUERY_RESULT_AVAILABLE
,
122 if (available
!= 1) {
123 printf("Query #%d result not available (expected in-order processing)\n", i
);
128 glDeleteQueries(NUM_QUERIES
, queries
);
130 piglit_present_results();
132 return test_pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
136 piglit_init(int argc
, char **argv
)
140 piglit_require_extension("GL_ARB_occlusion_query");
142 /* It is legal for a driver to support the query API but not have
143 * any query bits. I wonder how many applications actually check for
146 glGetQueryiv(GL_SAMPLES_PASSED
, GL_QUERY_COUNTER_BITS
,
148 if (query_bits
== 0) {
149 piglit_report_result(PIGLIT_SKIP
);