ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_occlusion_query / occlusion_query_meta_save.c
blob15bd56e5d3016d96ae199e289ed7d01b55fad16a
1 /*
2 * Copyright © 2014 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 * Neil Roberts <neil@linux.intel.com>
27 /**
28 * \file occlusion_query_meta_save.c
30 * Verify that doing a clear (which is potentially implemented as a
31 * meta operation) doesn't reset the samples-passed count back to
32 * zero.
35 #include "piglit-util-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config.supports_gl_compat_version = 10;
40 config.window_visual = PIGLIT_GL_VISUAL_RGB;
41 config.khr_no_error_support = PIGLIT_NO_ERRORS;
43 PIGLIT_GL_TEST_CONFIG_END
46 static bool
47 run_test(bool scissor_clear)
49 GLuint query;
50 GLint result = -1;
52 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
54 glClearColor(0.0, 1.0, 0.0, 0.0);
55 glClear(GL_COLOR_BUFFER_BIT);
57 glGenQueries(1, &query);
59 glBeginQuery(GL_SAMPLES_PASSED, query);
61 /* Render 64 pixels. This should affect the query */
62 piglit_draw_rect(0, 0, 8, 8);
64 /* Clear the framebuffer. This shouldn't affect the query */
65 glClearColor(0.0, 0.0, 1.0, 0.0);
66 if (scissor_clear) {
67 glScissor(0, 0, piglit_width / 2, piglit_height / 2);
68 glEnable(GL_SCISSOR_TEST);
70 glClear(GL_COLOR_BUFFER_BIT);
71 if (scissor_clear) {
72 glDisable(GL_SCISSOR_TEST);
75 /* Render another 64 pixels. This should continue adding to
76 * the query */
77 piglit_draw_rect(4, 0, 8, 8);
79 glEndQuery(GL_SAMPLES_PASSED);
81 glGetQueryObjectiv(query, GL_QUERY_RESULT, &result);
83 glDeleteQueries(1, &query);
85 piglit_present_results();
87 if (result != 128) {
88 printf("Failure: \n");
89 printf(" Occlusion query resulted in %d samples "
90 "(expected 128)\n",
91 result);
92 printf(" Scissor enabled? %s\n", scissor_clear ? "yes" : "no");
93 return false;
94 } else {
95 return true;
99 enum piglit_result
100 piglit_display(void)
102 bool pass = run_test(false);
103 pass = run_test(true) && pass;
105 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
108 void
109 piglit_init(int argc, char **argv)
111 GLint query_bits;
113 piglit_require_extension("GL_ARB_occlusion_query");
115 /* It is legal for a driver to support the query API but not have
116 * any query bits. I wonder how many applications actually check for
117 * this case...
119 glGetQueryiv(GL_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS, &query_bits);
120 if (query_bits == 0)
121 piglit_report_result(PIGLIT_SKIP);