ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_framebuffer_multisample / no-color.cpp
blob4fb263e1c8c806eddb4f8fd0c393d4491bc5076a
1 /*
2 * Copyright © 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.
24 /**
25 * \file no-color.cpp
27 * This test verifies proper operation of multisampled FBOs that lack
28 * a color buffer. It operates by performing identical draw
29 * operations in an FBO that lacks a color buffer and an FBO that has
30 * a color buffer, and verifying that the resulting output is the
31 * same.
33 * The test can run in any of the following modes:
35 * - depth: test depth buffer behaviour, using a fragment shader that
36 * does not compute depth.
38 * - depth-computed: test depth buffer behaviour, using a fragment
39 * shader that *does* compute depth.
41 * - stencil: test stencil buffer beahviour.
43 * It can also be configured to use either a combined depth/stencil
44 * buffer, separate depth/stencil buffers, or just a single
45 * depth/stencil buffer depending on the type of test.
47 * The test operates by performing the following steps:
49 * 1. Draw a test pattern to a multisampled FBO that lacks a color
50 * buffer (let's call this the "test FBO").
52 * 2. Blit the test pattern to a multisampled FBO that has a full
53 * complement of color, depth, and stencil buffers (let's call this
54 * the "manifest FBO").
56 * 3. Do a "manifest" operation to cause colors to be drawn that are
57 * dependent upon the contents of the depth or stencil buffer.
59 * 4. Blit the color buffer from the manifest FBO to the screen. This
60 * is the test image, and is shown in the left half of the piglit
61 * window.
63 * 5. Draw the test pattern again, but this time draw it directly to
64 * the manifest FBO.
66 * 6. Do a "manifest" operation again.
68 * 7. Blit the color buffer to the screen. This is the reference
69 * image, and is shown in the right half of the piglit window.
71 * 8. Compare the test and reference images to make sure they match.
74 #include "piglit-test-pattern.h"
75 #include "piglit-fbo.h"
76 using namespace piglit_util_fbo;
77 using namespace piglit_util_test_pattern;
79 PIGLIT_GL_TEST_CONFIG_BEGIN
81 config.supports_gl_compat_version = 10;
83 config.window_width = 512;
84 config.window_height = 256;
85 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
86 config.khr_no_error_support = PIGLIT_NO_ERRORS;
88 PIGLIT_GL_TEST_CONFIG_END
90 namespace {
92 const int pattern_width = 256, pattern_height = 256;
94 GLenum buffer_to_test;
95 Fbo test_fbo;
96 Fbo manifest_fbo;
97 ManifestProgram *manifest_program;
98 TestPattern *test_pattern;
100 void
101 print_usage_and_exit(char *prog_name)
103 printf("Usage: %s <num_samples> <test_type> <buffer_config?\n"
104 " where <test_type> is one of:\n"
105 " depth: test fixed pipeline depth\n"
106 " depth-computed: test depth value computed by a shader\n"
107 " stencil: test stencil\n"
108 " and <buffer_config> is one of:\n"
109 " combined: use a single combined depth/stencil buffer\n"
110 " separate: use separate depth and stencil buffers\n"
111 " single: use just a single buffer (depth or stencil)\n",
112 prog_name);
113 piglit_report_result(PIGLIT_FAIL);
116 extern "C" void
117 piglit_init(int argc, char **argv)
119 if (argc != 4)
120 print_usage_and_exit(argv[0]);
122 /* 1st arg: num_samples */
123 char *endptr = NULL;
124 int num_samples = strtol(argv[1], &endptr, 0);
125 if (endptr != argv[1] + strlen(argv[1]))
126 print_usage_and_exit(argv[0]);
128 /* 2nd arg: test_type */
129 if (strcmp(argv[2], "depth") == 0) {
130 buffer_to_test = GL_DEPTH_BUFFER_BIT;
131 manifest_program = new ManifestDepth;
132 test_pattern = new DepthSunburst(false /* compute_depth */);
133 } else if (strcmp(argv[2], "depth-computed") == 0) {
134 buffer_to_test = GL_DEPTH_BUFFER_BIT;
135 manifest_program = new ManifestDepth;
136 test_pattern = new DepthSunburst(true /* compute_depth */);
137 } else if (strcmp(argv[2], "stencil") == 0) {
138 buffer_to_test = GL_STENCIL_BUFFER_BIT;
139 manifest_program = new ManifestStencil;
140 test_pattern = new StencilSunburst;
141 } else {
142 print_usage_and_exit(argv[0]);
145 /* 3rd arg: buffer_config */
146 FboConfig test_fbo_config(num_samples, pattern_width, pattern_height);
147 test_fbo_config.color_internalformat = GL_NONE;
148 if (strcmp(argv[3], "combined") == 0) {
149 test_fbo_config.combine_depth_stencil = true;
150 } else if (strcmp(argv[3], "separate") == 0) {
151 test_fbo_config.combine_depth_stencil = false;
152 } else if (strcmp(argv[3], "single") == 0) {
153 test_fbo_config.combine_depth_stencil = false;
154 if (buffer_to_test == GL_DEPTH_BUFFER_BIT)
155 test_fbo_config.stencil_internalformat = GL_NONE;
156 else
157 test_fbo_config.depth_internalformat = GL_NONE;
158 } else {
159 print_usage_and_exit(argv[0]);
162 piglit_require_gl_version(21);
163 piglit_require_extension("GL_ARB_framebuffer_object");
164 piglit_require_extension("GL_ARB_vertex_array_object");
166 /* Skip the test if num_samples > GL_MAX_SAMPLES */
167 GLint max_samples;
168 glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
169 if (num_samples > max_samples)
170 piglit_report_result(PIGLIT_SKIP);
172 test_fbo.setup(test_fbo_config);
173 manifest_fbo.setup(FboConfig(num_samples, pattern_width,
174 pattern_height));
175 manifest_program->compile();
176 test_pattern->compile();
178 if (!piglit_check_gl_error(GL_NO_ERROR))
179 piglit_report_result(PIGLIT_FAIL);
182 extern "C" enum piglit_result
183 piglit_display()
185 bool pass = true;
187 /* Draw the test pattern into test_fbo. */
188 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, test_fbo.handle);
189 test_fbo.set_viewport();
190 test_pattern->draw(TestPattern::no_projection);
192 /* Blit the test pattern to manifest_fbo. */
193 glBindFramebuffer(GL_READ_FRAMEBUFFER, test_fbo.handle);
194 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, manifest_fbo.handle);
195 glBlitFramebuffer(0, 0, pattern_width, pattern_height,
196 0, 0, pattern_width, pattern_height,
197 buffer_to_test, GL_NEAREST);
199 /* Manifest the pattern so that it is reflected in color
200 * values in manifest_fbo.
202 manifest_program->run();
204 /* Blit the color buffer from manifest_fbo to the screen.
205 * This is the test image.
207 glBindFramebuffer(GL_READ_FRAMEBUFFER, manifest_fbo.handle);
208 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
209 glBlitFramebuffer(0, 0, pattern_width, pattern_height,
210 0, 0, pattern_width, pattern_height,
211 GL_COLOR_BUFFER_BIT, GL_NEAREST);
213 /* Draw the test pattern into manifest_fbo. */
214 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, manifest_fbo.handle);
215 manifest_fbo.set_viewport();
216 test_pattern->draw(TestPattern::no_projection);
218 /* Manifest the pattern so that it is reflected in color
219 * values in manifest_fbo.
221 manifest_program->run();
223 /* Blit the color buffer from manifest_fbo to the screen.
224 * This is the reference image.
226 glBindFramebuffer(GL_READ_FRAMEBUFFER, manifest_fbo.handle);
227 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
228 glBlitFramebuffer(0, 0, pattern_width, pattern_height,
229 pattern_width, 0, 2*pattern_width, pattern_height,
230 GL_COLOR_BUFFER_BIT, GL_NEAREST);
232 /* Compare the test and reference images */
233 glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
234 pass = piglit_probe_rect_halves_equal_rgba(0, 0, 2*pattern_width,
235 pattern_height) && pass;
237 piglit_present_results();
239 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
242 } /* Anonymous namespace */