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
24 /** \file blit-flipped.cpp
26 * From the GL 4.3 spec, section 18.3.1 "Blitting Pixel Rectangles":
28 * If SAMPLE_BUFFERS for either the read framebuffer or draw
29 * framebuffer is greater than zero, no copy is performed and an
30 * INVALID_OPERATION error is generated if the dimensions of the
31 * source and destination rectangles provided to BlitFramebuffer
32 * are not identical, or if the formats of the read and draw
33 * framebuffers are not identical.
35 * It is not clear from the spec whether "dimensions" should mean both
36 * sign and magnitude, or just magnitude. However, Y flips are likely
37 * to be commonplace in OpenGL applications that have been ported from
38 * DirectX applications, as a result of the fact that DirectX and
39 * OpenGL differ in their orientation of the Y axis. Furthermore, at
40 * least one commercial driver (nVidia) permits Y flips, and L4D2
41 * relies on them being permitted. So it seems prudent to assume that
42 * "dimensions" means just magnitude, not sign.
44 * This test verifies that a blit from a multisampled buffer to a
45 * single-sampled buffer is permitted to flip either in the X or Y
46 * direction, and that the resulting image is the same as what would
47 * be obtained by doing a non-flipped blit to a single-sampled buffer,
48 * and then a second blit that performs a flip.
51 #include "piglit-test-pattern.h"
52 #include "piglit-fbo.h"
53 using namespace piglit_util_fbo
;
54 using namespace piglit_util_test_pattern
;
56 const int pattern_width
= 256; const int pattern_height
= 256;
58 PIGLIT_GL_TEST_CONFIG_BEGIN
60 config
.supports_gl_compat_version
= 10;
62 config
.window_width
= pattern_width
*2;
63 config
.window_height
= pattern_height
;
64 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
65 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
67 PIGLIT_GL_TEST_CONFIG_END
69 static Fbo multisampled_fbo
, singlesampled_fbo
;
70 static TestPattern
*test_pattern
;
71 static GLint srcX0
, srcY0
, srcX1
, srcY1
;
74 print_usage_and_exit(char *prog_name
)
76 printf("Usage: %s <num_samples> <flip_direction>\n"
77 " where <flip_direction> is either x or y\n",
79 piglit_report_result(PIGLIT_FAIL
);
83 piglit_init(int argc
, char **argv
)
86 print_usage_and_exit(argv
[0]);
88 /* 1st arg: num_samples */
90 int num_samples
= strtol(argv
[1], &endptr
, 0);
91 if (endptr
!= argv
[1] + strlen(argv
[1]))
92 print_usage_and_exit(argv
[0]);
94 /* 2nd arg: flip_direction */
95 if (strcmp(argv
[2], "x") == 0) {
96 srcX0
= pattern_width
;
99 srcY1
= pattern_height
;
100 } else if (strcmp(argv
[2], "y") == 0) {
102 srcX1
= pattern_width
;
103 srcY0
= pattern_height
;
106 print_usage_and_exit(argv
[0]);
109 piglit_require_gl_version(21);
110 piglit_require_extension("GL_ARB_framebuffer_object");
111 piglit_require_extension("GL_ARB_vertex_array_object");
113 /* Skip the test if num_samples > GL_MAX_SAMPLES */
115 glGetIntegerv(GL_MAX_SAMPLES
, &max_samples
);
116 if (num_samples
> max_samples
)
117 piglit_report_result(PIGLIT_SKIP
);
119 singlesampled_fbo
.setup(FboConfig(0,
123 multisampled_fbo
.setup(FboConfig(num_samples
,
127 test_pattern
= new Triangles();
128 test_pattern
->compile();
130 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
131 piglit_report_result(PIGLIT_FAIL
);
140 /* Draw the test pattern into the multisampled buffer. */
141 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, multisampled_fbo
.handle
);
142 multisampled_fbo
.set_viewport();
143 test_pattern
->draw(TestPattern::no_projection
);
145 /* Blit it to a single-sampled buffer, flipping the
146 * appropriate coordinate. This will only work if the
147 * implementation allows multisampled blits to be flipped.
149 glBindFramebuffer(GL_READ_FRAMEBUFFER
, multisampled_fbo
.handle
);
150 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, singlesampled_fbo
.handle
);
151 glBlitFramebuffer(srcX0
, srcY0
, srcX1
, srcY1
,
152 0, 0, pattern_width
, pattern_height
,
153 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
154 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
156 /* Blit the resulting image to the screen, performing no
157 * additional flip. This is the test image.
159 glBindFramebuffer(GL_READ_FRAMEBUFFER
, singlesampled_fbo
.handle
);
160 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
161 glBlitFramebuffer(0, 0, pattern_width
, pattern_height
,
162 0, 0, pattern_width
, pattern_height
,
163 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
165 /* Blit the test pattern into the single-sampled buffer with
166 * no flip. This should always work.
168 glBindFramebuffer(GL_READ_FRAMEBUFFER
, multisampled_fbo
.handle
);
169 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, singlesampled_fbo
.handle
);
170 glBlitFramebuffer(0, 0, pattern_width
, pattern_height
,
171 0, 0, pattern_width
, pattern_height
,
172 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
174 /* Blit the resulting image to the screen, flipping the
175 * appropriate coordinate, to produce the reference image.
176 * This should always work (since it is blitting from
177 * single-sampled to single-sampled).
179 glBindFramebuffer(GL_READ_FRAMEBUFFER
, singlesampled_fbo
.handle
);
180 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
181 glBlitFramebuffer(srcX0
, srcY0
, srcX1
, srcY1
,
182 pattern_width
, 0, 2*pattern_width
, pattern_height
,
183 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
185 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
187 /* Compare the test and reference images. */
188 glBindFramebuffer(GL_READ_FRAMEBUFFER
, piglit_winsys_fbo
);
189 pass
= piglit_probe_rect_halves_equal_rgba(0, 0, 2*pattern_width
,
190 pattern_height
) && pass
;
192 piglit_present_results();
194 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;