glsl: test loop unroll with uint overflow
[piglit.git] / tests / spec / arb_occlusion_query / occlusion_query_meta_no_fragments.c
blobb3ba8a914ffb9bd05a15598983d076f5dc0b8365
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_meta_no_fragments.c
31 * Verify that various operations, (potentially implemented as
32 * meta-operations within the OpenGL implementation), do not generate
33 * fragments as specified.
36 #include "piglit-util-gl.h"
38 PIGLIT_GL_TEST_CONFIG_BEGIN
40 config.supports_gl_compat_version = 10;
41 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_DEPTH | PIGLIT_GL_VISUAL_STENCIL;
42 config.khr_no_error_support = PIGLIT_NO_ERRORS;
44 PIGLIT_GL_TEST_CONFIG_END
46 static bool
47 verify_no_fragments(GLuint query, const char *operation)
49 GLint result;
51 glGetQueryObjectiv(query, GL_QUERY_RESULT, &result);
53 if (result != 0) {
54 printf("Occlusion query for %s resulted in %d samples, (expected 0)\n", operation, result);
55 return false;
58 return true;
61 /* Draw several things that should not generate fragments, each within
62 * an occlusion query. Then verify that each query returns 0.
65 enum piglit_result
66 piglit_display(void)
68 /* 2x2 texture data: Red, Green, Blue, and White. */
69 float data[16] = { 1.0, 0.0, 0.0,
70 0.0, 1.0, 0.0,
71 0.0, 0.0, 1.0,
72 1.0, 1.0, 1.0 };
73 GLuint texture, texture_copy, fb;
74 GLuint query;
75 int test_pass = 1;
77 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
79 glGenQueries(1, &query);
80 glGenTextures(1, &texture);
81 glGenTextures(1, &texture_copy);
82 glBindTexture(GL_TEXTURE_2D, texture);
83 glGenFramebuffers(1, &fb);
85 /* No fragments for glClear
87 * Clear is specified to bypass most of the fragment pipeline:
89 * When Clear is called, the only per-fragment
90 * operations that are applied (if enabled) are
91 * the pixel ownership test, the scissor test,
92 * and dithering. [OpenGL 3.1 § 4.2.3]
94 glBeginQuery(GL_SAMPLES_PASSED, query);
96 glClearColor(0.0, 1.0, 0.0, 0.0);
97 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
99 glEndQuery(GL_SAMPLES_PASSED);
100 test_pass &= verify_no_fragments(query, "glClear(simple)");
102 /* No fragments for scissored glClear
104 glScissor(0, 0, piglit_width / 2, piglit_height / 2);
105 glEnable(GL_SCISSOR_TEST);
106 glBeginQuery(GL_SAMPLES_PASSED, query);
108 glClearColor(0.0, 1.0, 0.0, 0.0);
109 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
111 glEndQuery(GL_SAMPLES_PASSED);
112 glDisable(GL_SCISSOR_TEST);
113 test_pass &= verify_no_fragments(query, "glClear(scissored)");
115 /* No fragments for glColorMask + glClear
117 glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
118 glBeginQuery(GL_SAMPLES_PASSED, query);
120 glClearColor(0.0, 1.0, 0.0, 0.0);
121 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
123 glEndQuery(GL_SAMPLES_PASSED);
124 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
125 test_pass &= verify_no_fragments(query, "glClear(color masked)");
127 /* No fragments for 1-bit stencil clear
129 glStencilMask(1);
130 glBeginQuery(GL_SAMPLES_PASSED, query);
132 glClearColor(0.0, 1.0, 0.0, 0.0);
133 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
135 glEndQuery(GL_SAMPLES_PASSED);
136 glStencilMask(~0);
137 test_pass &= verify_no_fragments(query, "glClear(1-bit stencil)");
139 /* No fragments for glGenerateMipmap
141 * This call does not affect the framebuffer, so
142 * should not generate any fragments. */
143 glBeginQuery(GL_SAMPLES_PASSED, query);
145 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 2, 2, 0,
146 GL_RGB, GL_FLOAT, data);
148 glGenerateMipmap(GL_TEXTURE_2D);
150 glEndQuery(GL_SAMPLES_PASSED);
151 test_pass &= verify_no_fragments(query, "glGenerateMipmap");
153 /* No fragments for glBlitFramebuffer
155 * The specification could not be more clear:
157 * Blit operations bypass the fragment
158 * pipeline. [OpenGL 3.1 § 4.3]
160 glBeginQuery(GL_SAMPLES_PASSED, query);
162 glBindFramebuffer(GL_FRAMEBUFFER, fb);
164 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
165 GL_COLOR_ATTACHMENT0_EXT,
166 GL_TEXTURE_2D,
167 texture,
170 glBindFramebuffer(GL_READ_FRAMEBUFFER, fb);
171 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
172 glBlitFramebuffer(0, 0, 2, 2,
173 2, 2, 20, 20,
174 GL_COLOR_BUFFER_BIT, GL_NEAREST);
175 glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
177 glEndQuery(GL_SAMPLES_PASSED);
178 test_pass &= verify_no_fragments(query, "glBlitFramebuffer");
180 /* No fragments for glCopyTexImage
182 * This call does not affect the framebuffer, so
183 * should not generate any fragments. */
184 glBeginQuery(GL_SAMPLES_PASSED, query);
186 glBindTexture(GL_TEXTURE_2D, texture_copy);
187 glBindFramebuffer(GL_READ_FRAMEBUFFER, fb);
188 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8,
189 0, 0, 2, 2, 0);
191 glEndQuery(GL_SAMPLES_PASSED);
192 test_pass &= verify_no_fragments(query, "glCopyTexImage2D");
194 /* Paint the copied texture just ensure it worked. */
195 glEnable(GL_TEXTURE_2D);
196 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
197 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
198 piglit_draw_rect_tex(22, 2, 18, 18, 0, 0, 1, 1);
200 /* No fragments for glCopyTexSubImage */
201 glBeginQuery(GL_SAMPLES_PASSED, query);
203 glBindTexture(GL_TEXTURE_2D, texture_copy);
204 glBindFramebuffer(GL_READ_FRAMEBUFFER, fb);
205 glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
206 1, 1, 0, 0, 1, 1);
207 glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
209 glEndQuery(GL_SAMPLES_PASSED);
210 test_pass &= verify_no_fragments(query, "glCopyTexImage2D");
212 /* Paint the copied texture so a user can see that it worked. */
213 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
214 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
215 piglit_draw_rect_tex(42, 2, 18, 18, 0, 0, 1, 1);
217 glDeleteQueries(1, &query);
219 piglit_present_results();
221 return test_pass ? PIGLIT_PASS : PIGLIT_FAIL;
224 void
225 piglit_init(int argc, char **argv)
227 GLint query_bits;
229 piglit_require_extension("GL_ARB_occlusion_query");
231 /* It is legal for a driver to support the query API but not have
232 * any query bits. I wonder how many applications actually check for
233 * this case...
235 glGetQueryiv(GL_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS,
236 & query_bits);
237 if (query_bits == 0) {
238 piglit_report_result(PIGLIT_SKIP);