ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_occlusion_query / occlusion_query_order.c
blob97ce1f00e4269eaa5d1cdf07b37bed34066e8d98
1 /*
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
13 * Software.
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.
23 * Authors:
24 * Ian Romanick <ian.d.romanick@intel.com>
25 * Carl Worth <cworth@cworth.org>
28 /**
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
50 static void
51 draw_some_things(double frac)
53 int i;
54 float x, y;
56 x = 0.0;
57 y = frac * piglit_height;
59 glBegin(GL_QUADS);
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);
67 x++;
68 if (x >= piglit_width) {
69 x = 0.0;
70 y++;
71 if (y >= piglit_height) {
72 y = 0.0;
77 glEnd();
80 enum piglit_result
81 piglit_display(void)
83 #define NUM_QUERIES 5
84 GLuint queries[NUM_QUERIES], available;
85 bool test_pass = true;
86 GLint result;
87 int i;
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,
121 &available);
122 if (available != 1) {
123 printf("Query #%d result not available (expected in-order processing)\n", i);
124 test_pass = false;
128 glDeleteQueries(NUM_QUERIES, queries);
130 piglit_present_results();
132 return test_pass ? PIGLIT_PASS : PIGLIT_FAIL;
135 void
136 piglit_init(int argc, char **argv)
138 GLint query_bits;
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
144 * this case...
146 glGetQueryiv(GL_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS,
147 & query_bits);
148 if (query_bits == 0) {
149 piglit_report_result(PIGLIT_SKIP);