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
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
23 #include "piglit-test-pattern.h"
24 #include "piglit-fbo.h"
25 using namespace piglit_util_fbo
;
26 using namespace piglit_util_test_pattern
;
29 * \file multisample-blit.cpp
31 * Verify the accuracy of blitting from an MSAA buffer to another MSAA
34 * This test operates by drawing a test image in an MSAA buffer,
35 * blitting it to a second MSAA buffer, and then blitting it to the
36 * window system framebuffer (which is non-MSAA).
38 * To verify that the MSAA-to-MSAA blit worked properly, we also do a
39 * blit straight from the MSAA buffer to the window system
40 * framebuffer--this should produce the same image.
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config
.supports_gl_compat_version
= 10;
46 config
.window_width
= 512;
47 config
.window_height
= 256;
48 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DEPTH
| PIGLIT_GL_VISUAL_STENCIL
;
49 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
51 PIGLIT_GL_TEST_CONFIG_END
53 const int pattern_width
= 256; const int pattern_height
= 256;
57 TestPattern
*test_pattern
= NULL
;
58 ManifestProgram
*manifest_program
= NULL
;
59 GLbitfield buffer_to_test
;
60 GLenum filter_mode
= GL_NEAREST
;
63 print_usage_and_exit(char *prog_name
)
65 printf("Usage: %s <num_samples> <buffer_type>\n"
66 " where <buffer_type> is one of:\n"
70 "Available options:\n"
71 " linear: use GL_LINEAR filter mode\n",
73 piglit_report_result(PIGLIT_FAIL
);
77 piglit_init(int argc
, char **argv
)
81 print_usage_and_exit(argv
[0]);
84 num_samples
= strtol(argv
[1], &endptr
, 0);
85 if (endptr
!= argv
[1] + strlen(argv
[1]))
86 print_usage_and_exit(argv
[0]);
89 piglit_require_gl_version(21);
90 piglit_require_extension("GL_ARB_framebuffer_object");
91 piglit_require_extension("GL_ARB_vertex_array_object");
93 /* Skip the test if num_samples > GL_MAX_SAMPLES */
95 glGetIntegerv(GL_MAX_SAMPLES
, &max_samples
);
96 if (num_samples
> max_samples
)
97 piglit_report_result(PIGLIT_SKIP
);
99 if (strcmp(argv
[2], "color") == 0) {
100 test_pattern
= new Triangles();
101 buffer_to_test
= GL_COLOR_BUFFER_BIT
;
102 } else if (strcmp(argv
[2], "depth") == 0) {
103 test_pattern
= new DepthSunburst();
104 manifest_program
= new ManifestDepth();
105 buffer_to_test
= GL_DEPTH_BUFFER_BIT
;
106 } else if (strcmp(argv
[2], "stencil") == 0) {
107 test_pattern
= new StencilSunburst();
108 manifest_program
= new ManifestStencil();
109 buffer_to_test
= GL_STENCIL_BUFFER_BIT
;
111 print_usage_and_exit(argv
[0]);
114 for (int i
= 3; i
< argc
; i
++) {
115 if (strcmp(argv
[i
], "linear") == 0)
116 filter_mode
= GL_LINEAR
;
118 print_usage_and_exit(argv
[0]);
121 test_pattern
->compile();
122 if (manifest_program
)
123 manifest_program
->compile();
125 src_fbo
.setup(FboConfig(num_samples
, pattern_width
, pattern_height
));
126 dst_fbo
.setup(FboConfig(num_samples
, pattern_width
, pattern_height
));
134 /* Draw the test pattern in src_fbo. */
135 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, src_fbo
.handle
);
136 src_fbo
.set_viewport();
137 test_pattern
->draw(TestPattern::no_projection
);
139 /* Blit from src_fbo to dst_fbo. */
140 glBindFramebuffer(GL_READ_FRAMEBUFFER
, src_fbo
.handle
);
141 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, dst_fbo
.handle
);
142 glBlitFramebuffer(0, 0, pattern_width
, pattern_height
,
143 0, 0, pattern_width
, pattern_height
,
144 buffer_to_test
, filter_mode
);
146 /* If necessary, manifest the depth/stencil image in dst_fbo
147 * into a color image. This ensures that the blit that
148 * follows will depend on all samples of each pixel.
150 dst_fbo
.set_viewport();
151 if (manifest_program
)
152 manifest_program
->run();
154 /* Blit from dst_fbo to the left half of the window system
155 * framebuffer. This is the test image.
157 glBindFramebuffer(GL_READ_FRAMEBUFFER
, dst_fbo
.handle
);
158 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
159 glBlitFramebuffer(0, 0, pattern_width
, pattern_height
,
160 0, 0, pattern_width
, pattern_height
,
161 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
163 /* Now manifest the image in src_fbo and blit it directly to
164 * the window system framebuffer. This is the reference
167 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, src_fbo
.handle
);
168 src_fbo
.set_viewport();
169 if (manifest_program
)
170 manifest_program
->run();
171 glBindFramebuffer(GL_READ_FRAMEBUFFER
, src_fbo
.handle
);
172 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
173 glBlitFramebuffer(0, 0, pattern_width
, pattern_height
,
174 pattern_width
, 0, 2*pattern_width
, pattern_height
,
175 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
177 /* Check that the left and right halves of the screen match.
178 * If they don't, then there must have been a problem blitting
179 * from src_fbo to dst_fbo.
181 glBindFramebuffer(GL_READ_FRAMEBUFFER
, piglit_winsys_fbo
);
182 pass
= piglit_probe_rect_halves_equal_rgba(0, 0, piglit_width
,
183 piglit_height
) && pass
;
185 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
187 piglit_present_results();
189 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;