ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_occlusion_query / occlusion_query.c
blobd286998132a9933e6f5504265df066265270dad1
1 /*
2 * Copyright © 2009 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>
27 /**
28 * \file occlusion_query.c
29 * Simple test for GL_ARB_occlusion_query.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config.supports_gl_compat_version = 10;
38 config.window_width = 180;
39 config.window_height = 100;
40 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_DEPTH;
41 config.khr_no_error_support = PIGLIT_NO_ERRORS;
43 PIGLIT_GL_TEST_CONFIG_END
45 #define MAX_QUERIES 5
46 static GLuint occ_queries[MAX_QUERIES];
48 static void draw_box(float x, float y, float z, float w, float h)
50 glBegin(GL_QUADS);
51 glVertex3f(x, y, z);
52 glVertex3f(x + w, y, z);
53 glVertex3f(x + w, y + h, z);
54 glVertex3f(x, y + h, z);
55 glEnd();
59 static int check_result(GLint passed, GLint expected)
61 printf("samples passed = %d, expected = %d\n", passed, expected);
62 return (expected == passed) ? 1 : 0;
66 static int do_test(float x, int all_at_once)
68 static const struct {
69 float x;
70 float y;
71 float z;
72 float w;
73 float h;
74 int expected;
75 GLubyte color[3];
76 } tests[MAX_QUERIES] = {
78 25.0f, 25.0f, 0.2f, 20.0f, 20.0f, 20 * 20,
79 { 0x00, 0xff, 0x00 }
82 45.0f, 45.0f, -0.2f, 20.0f, 20.0f, 0,
83 { 0x00, 0x7f, 0xf0 }
86 10.0f, 10.0f, -0.3f, 75.0f, 75.0f,
87 (75 * 75) - (55 * 55),
88 { 0x00, 0x00, 0xff }
91 20.0f, 20.0f, -0.1f, 55.0f, 55.0f, 0,
92 { 0x7f, 0x7f, 0x00 }
95 50.0f, 25.0f, 0.2f, 20.0f, 20.0f, 20 * 20,
96 { 0x00, 0x7f, 0xf0 }
99 GLint passed;
100 int test_pass = 1;
101 unsigned i;
104 /* Draw an initial red box that is 2500 pixels. All of the occlusion
105 * query measurements are relative to this box.
107 glColor3ub(0xff, 0x00, 0x00);
108 draw_box(x + 20.0f, 20.0f, 0.0f, 55.0f, 55.0f);
110 for (i = 0; i < MAX_QUERIES; i++) {
111 glBeginQuery(GL_SAMPLES_PASSED, occ_queries[i]);
112 glColor3ubv(tests[i].color);
113 draw_box(x + tests[i].x, tests[i].y, tests[i].z,
114 tests[i].w, tests[i].h);
115 glEndQuery(GL_SAMPLES_PASSED);
117 if (! all_at_once) {
118 glGetQueryObjectiv(occ_queries[i],
119 GL_QUERY_RESULT, &passed);
120 test_pass &= check_result(passed, tests[i].expected);
125 if (all_at_once) {
126 for (i = 0; i < MAX_QUERIES; i++) {
127 glGetQueryObjectiv(occ_queries[i], GL_QUERY_RESULT,
128 &passed);
129 test_pass &= check_result(passed, tests[i].expected);
133 printf("\n");
134 return test_pass;
137 enum piglit_result
138 piglit_display(void)
140 int test_pass;
142 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
143 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
145 test_pass = do_test(0.0f, 0);
146 test_pass &= do_test(85.0f, 1);
148 piglit_present_results();
150 return test_pass ? PIGLIT_PASS : PIGLIT_FAIL;
153 void
154 piglit_init(int argc, char **argv)
156 GLint query_bits;
158 glClearColor(0.0, 0.2, 0.3, 0.0);
159 glClearDepth(1.0);
161 glEnable(GL_DEPTH_TEST);
162 glDepthFunc(GL_LESS);
164 piglit_require_extension("GL_ARB_occlusion_query");
166 /* It is legal for a driver to support the query API but not have
167 * any query bits. I wonder how many applications actually check for
168 * this case...
170 glGetQueryiv(GL_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS,
171 & query_bits);
172 if (query_bits == 0) {
173 piglit_report_result(PIGLIT_SKIP);
177 glGenQueries(MAX_QUERIES, occ_queries);