ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_occlusion_query / occlusion_query_meta_fragments.c
blob3ce398a96c106b649bd9ce3d2d0c1bdd62e4bb51
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_fragments.c
31 * Verify that various operations, (potentially implemented as
32 * meta-operations within the OpenGL implementation), 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;
43 PIGLIT_GL_TEST_CONFIG_END
45 static bool
46 verify_fragments(GLuint query, const char *operation, int expected_fragments)
48 GLint result;
50 glGetQueryObjectiv(query, GL_QUERY_RESULT, &result);
52 if (result == expected_fragments)
53 return true;
55 printf("Occlusion query for %s resulted in %d samples, (expected %d)\n",
56 operation, result, expected_fragments);
57 return false;
60 /* Draw several things that should generate fragments, each within an
61 * occlusion query. Then verify that each query returns a non-zero
62 * value.
64 enum piglit_result
65 piglit_display(void)
67 /* 2x2 data: Red, Green, Blue, and White. */
68 float data[16] = { 1.0, 0.0, 0.0,
69 0.0, 1.0, 0.0,
70 0.0, 0.0, 1.0,
71 1.0, 1.0, 1.0 };
72 GLubyte bitmap[16] = { 0x5f, 0xff, 0xff, 0xff,
73 0xAf, 0xff, 0xff, 0xff,
74 0x5f, 0xff, 0xff, 0xff,
75 0xAf, 0xff, 0xff, 0xff };
76 GLuint query;
77 int test_pass = 1;
79 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
81 glClearColor(0.0, 1.0, 0.0, 0.0);
82 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
84 glGenQueries(1, &query);
86 /* Fragments for glDrawPixels
88 * Assuming one fragment per pixel based on:
90 * Rectangles of color, depth, and certain
91 * other values may be converted to fragments
92 * using the DrawPixels command. [OpenGL 3.0 § 3.7]
94 glBeginQuery(GL_SAMPLES_PASSED, query);
96 glRasterPos2i(2, 2);
97 glDrawPixels(2, 2, GL_RGB, GL_FLOAT, data);
99 glEndQuery(GL_SAMPLES_PASSED);
100 test_pass &= verify_fragments(query, "glDrawPixels", 4);
102 /* Fragments for glCopyPixels
104 * And here, CopyPixels is specified to behave
105 * identically to DrawPixels:
107 * The groups of elements so obtained are then
108 * written to the framebuffer just as if
109 * DrawPixels had been given width and height,
110 * beginning with final conversion of elements.
111 * [OpenGL 3.0 § 4.3.3]
113 glBeginQuery(GL_SAMPLES_PASSED, query);
115 glRasterPos2i(6, 2);
116 glCopyPixels(2, 2, 2, 2, GL_COLOR);
118 glEndQuery(GL_SAMPLES_PASSED);
119 test_pass &= verify_fragments(query, "glCopyPixels", 4);
121 /* Fragments for glBitmap.
123 * The specification implies very strongly that a bitmap
124 * should generate one fragment per set bit:
126 * Bitmaps are rectangles of zeros and ones
127 * specifying a particular pattern of frag-
128 * ments to be produced. [OpenGL 3.0 § 3.8]
130 glBeginQuery(GL_SAMPLES_PASSED, query);
132 glRasterPos2i(10, 2);
133 glColor4f(0.0, 0.0, 1.0, 0.0);
134 glBitmap(4, 4, 0, 0, 0, 0, bitmap);
136 glEndQuery(GL_SAMPLES_PASSED);
137 test_pass &= verify_fragments(query, "glBitmap", 8);
139 glDeleteQueries(1, &query);
141 piglit_present_results();
143 return test_pass ? PIGLIT_PASS : PIGLIT_FAIL;
146 void
147 piglit_init(int argc, char **argv)
149 GLint query_bits;
151 piglit_require_extension("GL_ARB_occlusion_query");
153 /* It is legal for a driver to support the query API but not have
154 * any query bits. I wonder how many applications actually check for
155 * this case...
157 glGetQueryiv(GL_SAMPLES_PASSED, GL_QUERY_COUNTER_BITS,
158 & query_bits);
159 if (query_bits == 0) {
160 piglit_report_result(PIGLIT_SKIP);