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
25 using namespace piglit_util_fbo
;
26 using namespace piglit_util_test_pattern
;
29 * \file polygon-smooth.cpp
31 * Page 134 (in the PDF) of the OpenGL 3.0 spec says:
32 * "If MULTISAMPLE is enabled, and the value of SAMPLE BUFFERS is one,
33 * then polygons are rasterized using the following algorithm, regardless
34 * of whether polygon antialias-ing (POLYGON_SMOOTH) is enabled or disabled".
36 * This test operates by drawing a test pattern in to multisample fbo with
37 * GL_POLYGON_SMOOTH disabled. Blits it in to right half of window system
38 * framebuffer. This is used as reference image.
40 * Draw the same test pattern for the second time in multisample buffer with
41 * GL_POLYGON_SMOOTH enabled. Blit it in to left half of window system
42 * framebuffer. This is the test image.
44 * To verify that GL_POLYGON_SMOOTH is ignored during MSAA, compare the two
45 * halves of default framebuffer. They are expected to match.
48 PIGLIT_GL_TEST_CONFIG_BEGIN
50 config
.supports_gl_compat_version
= 10;
52 config
.window_width
= 512;
53 config
.window_height
= 256;
54 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DEPTH
| PIGLIT_GL_VISUAL_STENCIL
;
55 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
57 PIGLIT_GL_TEST_CONFIG_END
59 const int pattern_width
= 256; const int pattern_height
= 256;
63 GLbitfield buffer_to_test
;
64 TestPattern
*test_pattern
= NULL
;
67 print_usage_and_exit(char *prog_name
)
69 printf("Usage: %s <num_samples>\n",
71 piglit_report_result(PIGLIT_FAIL
);
75 piglit_init(int argc
, char **argv
)
79 print_usage_and_exit(argv
[0]);
82 num_samples
= strtol(argv
[1], &endptr
, 0);
83 if (endptr
!= argv
[1] + strlen(argv
[1]))
84 print_usage_and_exit(argv
[0]);
87 piglit_require_gl_version(21);
88 piglit_require_extension("GL_ARB_framebuffer_object");
89 piglit_require_extension("GL_ARB_vertex_array_object");
91 /* Skip the test if num_samples > GL_MAX_SAMPLES */
93 glGetIntegerv(GL_MAX_SAMPLES
, &max_samples
);
94 if (num_samples
> max_samples
)
95 piglit_report_result(PIGLIT_SKIP
);
97 buffer_to_test
= GL_COLOR_BUFFER_BIT
;
99 test_pattern
= new Triangles();
100 test_pattern
->compile();
102 ms_fbo
.setup(FboConfig(num_samples
, pattern_width
, pattern_height
));
104 /* Enable blending to test GL_POLYGON_SMOOTH */
106 glBlendFunc (GL_SRC_ALPHA_SATURATE
, GL_ONE
);
120 /* Draw test pattern in multisample ms_fbo with GL_POLYGON_SMOOTH
123 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, ms_fbo
.handle
);
124 ms_fbo
.set_viewport();
125 test_pattern
->draw(proj
);
127 /* Blit ms_fbo to the right half of window system framebuffer. This
128 * is a reference image to test MSAA with polygon smooth.
130 glBindFramebuffer(GL_READ_FRAMEBUFFER
, ms_fbo
.handle
);
131 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
132 glBlitFramebuffer(0, 0, pattern_width
, pattern_height
,
133 pattern_width
, 0, 2 * pattern_width
, pattern_height
,
134 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
136 /* Now draw test pattern in mulisample ms_fbo with GL_POLYGON_SMOOTH
139 glDisable(GL_DEPTH_TEST
);
140 glEnable(GL_POLYGON_SMOOTH
);
141 glHint(GL_POLYGON_SMOOTH_HINT
, GL_NICEST
);
143 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, ms_fbo
.handle
);
144 ms_fbo
.set_viewport();
146 glClear(buffer_to_test
);
147 test_pattern
->draw(proj
);
149 glDisable(GL_POLYGON_SMOOTH
);
151 /* Blit ms_fbo to the left half of window system framebuffer. This
154 glBindFramebuffer(GL_READ_FRAMEBUFFER
, ms_fbo
.handle
);
155 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
156 glBlitFramebuffer(0, 0, pattern_width
, pattern_height
,
157 0, 0, pattern_width
, pattern_height
,
158 GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
160 /* Check that the left and right halves of the screen match. If they
161 * don't, then GL_POLYGON_SMOOTH is not ignored with multisample
164 glBindFramebuffer(GL_READ_FRAMEBUFFER
, piglit_winsys_fbo
);
165 pass
= piglit_probe_rect_halves_equal_rgba(0, 0, piglit_width
,
166 piglit_height
) && pass
;
167 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
169 piglit_present_results();
170 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;