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
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>
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
46 static GLuint occ_queries
[MAX_QUERIES
];
48 static void draw_box(float x
, float y
, float z
, float w
, float h
)
52 glVertex3f(x
+ w
, y
, z
);
53 glVertex3f(x
+ w
, y
+ h
, z
);
54 glVertex3f(x
, y
+ h
, z
);
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
)
76 } tests
[MAX_QUERIES
] = {
78 25.0f
, 25.0f
, 0.2f
, 20.0f
, 20.0f
, 20 * 20,
82 45.0f
, 45.0f
, -0.2f
, 20.0f
, 20.0f
, 0,
86 10.0f
, 10.0f
, -0.3f
, 75.0f
, 75.0f
,
87 (75 * 75) - (55 * 55),
91 20.0f
, 20.0f
, -0.1f
, 55.0f
, 55.0f
, 0,
95 50.0f
, 25.0f
, 0.2f
, 20.0f
, 20.0f
, 20 * 20,
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
);
118 glGetQueryObjectiv(occ_queries
[i
],
119 GL_QUERY_RESULT
, &passed
);
120 test_pass
&= check_result(passed
, tests
[i
].expected
);
126 for (i
= 0; i
< MAX_QUERIES
; i
++) {
127 glGetQueryObjectiv(occ_queries
[i
], GL_QUERY_RESULT
,
129 test_pass
&= check_result(passed
, tests
[i
].expected
);
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
;
154 piglit_init(int argc
, char **argv
)
158 glClearColor(0.0, 0.2, 0.3, 0.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
170 glGetQueryiv(GL_SAMPLES_PASSED
, GL_QUERY_COUNTER_BITS
,
172 if (query_bits
== 0) {
173 piglit_report_result(PIGLIT_SKIP
);
177 glGenQueries(MAX_QUERIES
, occ_queries
);