ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / spec / ext_framebuffer_multisample / bitmap.cpp
blob966b6379d30ef0ce086624431573ef1bd7028d10
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 #include "piglit-fbo.h"
25 #include "piglit-test-pattern.h"
26 using namespace piglit_util_fbo;
27 using namespace piglit_util_test_pattern;
29 /**
30 * \file bitmap.cpp
32 * This test case verifies the functionality of glBitmap() with multisample
33 * FBO and assumes that MSAA accuracy test already passes. glBitmap() is
34 * expected to work exactly the same way on multisample FBO as it works on
35 * single sample FBO.
37 * Test operates by drawing a test pattern in a single sample FBO which
38 * generates a reference image in right half of default framebuffer.
40 * Draw the same test pattern in multisample buffer and blit it in to a single
41 * sample FBO (resolve_fbo). Then blit the resolve_fbo to left half of window
42 * system framebuffer. This is the test image.
44 * Compare the two halves of default framebuffer.
47 PIGLIT_GL_TEST_CONFIG_BEGIN
49 config.supports_gl_compat_version = 10;
51 config.window_width = 512;
52 config.window_height = 256;
53 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
54 config.khr_no_error_support = PIGLIT_NO_ERRORS;
56 PIGLIT_GL_TEST_CONFIG_END
58 const int pattern_width = 256; const int pattern_height = 256;
60 static Fbo ms_fbo, resolve_fbo;
61 static GLint num_samples;
63 static GLubyte bitmap[] =
65 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
66 0xc0, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x03,
67 0xcf, 0xff, 0xff, 0xf3, 0xcf, 0xff, 0xff, 0xf3,
68 0xcc, 0x00, 0x00, 0x33, 0xcc, 0x00, 0x00, 0x33,
69 0xcc, 0xff, 0xff, 0x33, 0xcc, 0xff, 0xff, 0x33,
70 0xcc, 0xc0, 0x03, 0x33, 0xcc, 0xc0, 0x03, 0x33,
71 0xcc, 0xcf, 0xf3, 0x33, 0xcc, 0xcf, 0xf3, 0x33,
72 0xcc, 0xcf, 0xf3, 0x33, 0xcc, 0xcf, 0xf3, 0x33,
73 0xcc, 0xcf, 0xf3, 0x33, 0xcc, 0xcf, 0xf3, 0x33,
74 0xcc, 0xcf, 0xf3, 0x33, 0xcc, 0xcf, 0xf3, 0x33,
75 0xcc, 0xc0, 0x03, 0x33, 0xcc, 0xc0, 0x03, 0x33,
76 0xcc, 0xff, 0xff, 0x33, 0xcc, 0xff, 0xff, 0x33,
77 0xcc, 0x00, 0x00, 0x33, 0xcc, 0x00, 0x00, 0x33,
78 0xcf, 0xff, 0xff, 0xf3, 0xcf, 0xff, 0xff, 0xf3,
79 0xc0, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x03,
80 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
83 void
84 draw_pattern(void)
86 const int w = 32, h = 32;
88 glClear(GL_COLOR_BUFFER_BIT);
90 glRasterPos2i (0, 0);
91 glColor3f(1.0, 1.0 , 1.0);
92 for (int i = 0; i < pattern_width / w; i++)
93 glBitmap(w, h, 0.0, 0.0, w, h, bitmap);
95 glRasterPos2i (0, pattern_height - h);
96 for (int i = 0; i < pattern_width / w; i++)
97 glBitmap(w, h, 0.0, 0.0, w, -h, bitmap);
100 void
101 print_usage_and_exit(char *prog_name)
103 printf("Usage: %s <num_samples>\n", prog_name);
104 piglit_report_result(PIGLIT_FAIL);
107 bool
108 test_multisample_bitmap()
110 bool result = true;
112 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ms_fbo.handle);
113 draw_pattern();
115 /* Blit ms_fbo to resolve_fbo to resolve multisample buffer */
116 glBindFramebuffer(GL_READ_FRAMEBUFFER, ms_fbo.handle);
117 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolve_fbo.handle);
118 glBlitFramebuffer(0, 0, pattern_width, pattern_height,
119 0, 0, pattern_width, pattern_height,
120 GL_COLOR_BUFFER_BIT, GL_NEAREST);
122 /* Blit resolve_fbo to the left half of window system framebuffer.
123 * This is the test image.
125 glBindFramebuffer(GL_READ_FRAMEBUFFER, resolve_fbo.handle);
126 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
127 glBlitFramebuffer(0, 0, pattern_width, pattern_height,
128 0, 0, pattern_width, pattern_height,
129 GL_COLOR_BUFFER_BIT, GL_NEAREST);
131 /* Check that the left and right halves of the screen match */
132 glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
133 result = piglit_probe_rect_halves_equal_rgba(0, 0, piglit_width,
134 piglit_height)
135 && result;
137 result = piglit_check_gl_error(GL_NO_ERROR) && result;
138 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
139 return result;
143 void
144 piglit_init(int argc, char **argv)
146 if (argc < 2)
147 print_usage_and_exit(argv[0]);
149 char *endptr = NULL;
150 num_samples = strtol(argv[1], &endptr, 0);
151 if (endptr != argv[1] + strlen(argv[1]))
152 print_usage_and_exit(argv[0]);
155 piglit_require_gl_version(21);
156 piglit_require_extension("GL_ARB_framebuffer_object");
157 piglit_require_extension("GL_ARB_vertex_array_object");
159 piglit_ortho_projection(pattern_width, pattern_height, GL_TRUE);
161 /* Skip the test if num_samples > GL_MAX_SAMPLES */
162 GLint max_samples;
163 glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
164 if (num_samples > max_samples)
165 piglit_report_result(PIGLIT_SKIP);
167 ms_fbo.setup(FboConfig(num_samples, pattern_width, pattern_height));
168 resolve_fbo.setup(FboConfig(0, pattern_width, pattern_height));
171 enum piglit_result
172 piglit_display()
174 bool pass = true;
175 glClearColor(0.0, 0.0, 0.0, 1.0);
176 glClear(GL_COLOR_BUFFER_BIT);
178 /* Draw test pattern in single sample resolve_fbo */
179 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolve_fbo.handle);
180 resolve_fbo.set_viewport();
181 draw_pattern();
183 /* Blit resolve_fbo to the right half of window system framebuffer. This
184 * is a reference image.
186 glBindFramebuffer(GL_READ_FRAMEBUFFER, resolve_fbo.handle);
187 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
188 glBlitFramebuffer(0, 0, pattern_width, pattern_height,
189 pattern_width, 0, 2 * pattern_width, pattern_height,
190 GL_COLOR_BUFFER_BIT, GL_NEAREST);
192 /* Test drawing bitmap in multisample FBO */
193 pass = test_multisample_bitmap() && pass;
195 if (!piglit_automatic)
196 piglit_present_results();
198 return pass ? PIGLIT_PASS : PIGLIT_FAIL;