1 /*
2 * Copyright © 2017 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
26 * Tests GL_EXT_occlusion_query_boolean extension. Test does not to cover
27 * the whole API as that is tested throughly by existing arb_occlusion_query
28 * and arb_occlusion_query2 tests. Main objective is to test that boolean
29 * query works on OpenGL ES 2.0.
30 */
31
32 #include "piglit-util-gl.h"
33
34 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config.supports_gl_es_version = 20;
36 config.window_visual = PIGLIT_GL_VISUAL_RGBA;
37 PIGLIT_GL_TEST_CONFIG_END
38
39 static const char vs_source[] =
40 "attribute vec2 piglit_vertex;\n"
41 "\n"
42 "void main()\n"
43 "{\n"
44 " gl_Position = vec4(piglit_vertex, 0.0, 1.0);\n"
45 "}\n";
46
47 static const char fs_source[] =
48 "void main()\n"
49 "{\n"
50 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
51 "}\n";
52
53 enum piglit_result
piglit_display(void)54 piglit_display(void)
55 {
56 GLuint query, samples;
57 GLint current;
58
59 glGenQueriesEXT(1, &query);
60
61 if (!piglit_check_gl_error(GL_NO_ERROR))
62 piglit_report_result(PIGLIT_FAIL);
63
64 glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, query);
65
66 if (!piglit_check_gl_error(GL_NO_ERROR))
67 piglit_report_result(PIGLIT_FAIL);
68
69 if (!glIsQueryEXT(query))
70 piglit_report_result(PIGLIT_FAIL);
71
72 glGetQueryivEXT(GL_ANY_SAMPLES_PASSED_EXT, GL_CURRENT_QUERY_EXT,
73 ¤t);
74
75 if (current != query)
76 piglit_report_result(PIGLIT_FAIL);
77
78 GLint prog = piglit_build_simple_program(vs_source, fs_source);
79 glUseProgram(prog);
80
81 piglit_draw_rect(-1, -1, 2, 2);
82
83 glDeleteProgram(prog);
84
85 glEndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT);
86
87 if (!piglit_check_gl_error(GL_NO_ERROR))
88 piglit_report_result(PIGLIT_FAIL);
89
90 glGetQueryObjectuivEXT(query, GL_QUERY_RESULT_EXT, &samples);
91
92 if (!piglit_check_gl_error(GL_NO_ERROR))
93 piglit_report_result(PIGLIT_FAIL);
94
95 if (samples != 1) {
96 piglit_report_result(PIGLIT_FAIL);
97 }
98
99 glDeleteQueriesEXT(1, &query);
100
101 if (!piglit_check_gl_error(GL_NO_ERROR))
102 piglit_report_result(PIGLIT_FAIL);
103
104 return PIGLIT_PASS;
105 }
106
107 void
piglit_init(int argc,char ** argv)108 piglit_init(int argc, char **argv)
109 {
110 piglit_require_extension("GL_EXT_occlusion_query_boolean");
111 }
112