glsl: test loop unroll with uint overflow
[piglit.git] / tests / spec / ext_framebuffer_multisample / line-smooth.cpp
blob1c018a5c9d2f2900f5bb2267e589bc15ab63c904
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-test-pattern.h"
25 #include "piglit-fbo.h"
26 using namespace piglit_util_fbo;
27 using namespace piglit_util_test_pattern;
29 /**
30 * \file line-smooth.cpp
32 * Page 128 (in the PDF) of the OpenGL 3.0 spec says:
33 * "If MULTISAMPLE is enabled, and the value of SAMPLE BUFFERS is one,
34 * then lines are rasterized using the following algorithm, regardless
35 * of whether line antialias-ing (LINE_SMOOTH) is enabled or disabled".
37 * This test operates by drawing a test pattern with GL_LINE_SMOOTH
38 * disabled. Blit it in to right half of window system framebuffer.
39 * This is our reference image.
41 * Draw the same test pattern second time with GL_LINE_SMOOTH enabled
42 * in a multisample buffer. Blit it in to left half of window system
43 * framebuffer. This is our test image.
45 * To verify that GL_LINE_SMOOTH don't affect MSAA, compare the two
46 * halves of default framebuffer. They are expected to match.
50 PIGLIT_GL_TEST_CONFIG_BEGIN
52 config.supports_gl_compat_version = 10;
54 config.window_width = 512;
55 config.window_height = 256;
56 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DEPTH | PIGLIT_GL_VISUAL_STENCIL;
57 config.khr_no_error_support = PIGLIT_NO_ERRORS;
59 PIGLIT_GL_TEST_CONFIG_END
61 const int pattern_width = 256; const int pattern_height = 256;
63 Fbo test_fbo;
64 TestPattern *test_pattern = NULL;
65 GLbitfield buffer_to_test;
67 void
68 print_usage_and_exit(char *prog_name)
70 printf("Usage: %s <num_samples>\n",
71 prog_name);
72 piglit_report_result(PIGLIT_FAIL);
75 void
76 piglit_init(int argc, char **argv)
78 int num_samples;
79 if (argc < 2)
80 print_usage_and_exit(argv[0]);
82 char *endptr = NULL;
83 num_samples = strtol(argv[1], &endptr, 0);
84 if (endptr != argv[1] + strlen(argv[1]))
85 print_usage_and_exit(argv[0]);
88 piglit_require_gl_version(21);
89 piglit_require_extension("GL_ARB_framebuffer_object");
90 piglit_require_extension("GL_ARB_vertex_array_object");
92 glClear(GL_COLOR_BUFFER_BIT);
94 /* Skip the test if num_samples > GL_MAX_SAMPLES */
95 GLint max_samples;
96 glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
97 if (num_samples > max_samples)
98 piglit_report_result(PIGLIT_SKIP);
100 buffer_to_test = GL_COLOR_BUFFER_BIT;
101 test_pattern = new Lines();
102 test_pattern->compile();
104 test_fbo.setup(FboConfig(num_samples, pattern_width, pattern_height));
106 glEnable (GL_BLEND);
107 glBlendFunc (GL_SRC_ALPHA_SATURATE, GL_ONE);
110 enum piglit_result
111 piglit_display()
113 bool pass = true;
114 float proj[4][4] = {
115 { 1, 0, 0, 0 },
116 { 0, 1, 0, 0 },
117 { 0, 0, 1, 0 },
118 { 0, 0, 0, 1 } };
119 /* Draw test pattern in multisample test_fbo with GL_LINE_SMOOTH
120 * disabled.
122 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, test_fbo.handle);
123 glClear(buffer_to_test);
124 test_fbo.set_viewport();
125 test_pattern->draw(proj);
127 /* Blit test_fbo to the right half of window system framebuffer.
128 * This is the reference image.
130 glBindFramebuffer(GL_READ_FRAMEBUFFER, test_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 /* Draw test pattern in mulisample test_fbo with GL_LINE_SMOOTH
137 * enabled
139 glEnable(GL_LINE_SMOOTH);
140 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
142 /* Disable depth test to correctly render overlapping smooth
143 * primitives. Otherwise we have to render the primitives in
144 * back to front order
146 glDisable (GL_DEPTH_TEST);
148 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, test_fbo.handle);
149 test_fbo.set_viewport();
150 test_pattern->draw(proj);
152 glDisable(GL_LINE_SMOOTH);
154 /* Now blit test_fbo to the left half of window system framebuffer.
155 * This is the test image.
157 glBindFramebuffer(GL_READ_FRAMEBUFFER, test_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 /* Check that the left and right halves of the screen match. If they
164 * don't, then GL_LINE_SMOOTH is not ignored with multisample
165 * rendering.
167 glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
168 pass = piglit_probe_rect_halves_equal_rgba(0, 0, piglit_width,
169 piglit_height) && pass;
171 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
173 piglit_present_results();
175 return pass ? PIGLIT_PASS : PIGLIT_FAIL;