ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_framebuffer_multisample / point-smooth.cpp
blobf8658ddfa61c1d733ae9710ab57469c3c4e0156a
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 point-smooth.cpp
32 * Page 122 (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 points are rasterized using the following algorithm, regardless
35 * of whether point antialias-ing (POINT SMOOTH) is enabled or disabled".
37 * This test operates by drawing a test image with GL_POINT_SMOOTH
38 * enabled in an MSAA buffer. Blit it in to left half of window system
39 * framebuffer.
41 * Draw same image second time with GL_POINT_SMOOTH disabled. Blit it
42 * in to right half of window system framebuffer. This is the reference
43 * image.
45 * To verify that GL_POINT_SMOOTH doesn't affect MSAA, compare the two
46 * halves of default framebuffer. There should be no difference.
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 Points();
102 test_pattern->compile();
104 test_fbo.setup(FboConfig(num_samples, pattern_width, pattern_height));
106 /* Blending is required to test smooth points */
107 glEnable (GL_BLEND);
108 glBlendFunc (GL_SRC_ALPHA_SATURATE, GL_ONE);
111 enum piglit_result
112 piglit_display()
114 bool pass = true;
115 float proj[4][4] = {
116 { 1, 0, 0, 0 },
117 { 0, 1, 0, 0 },
118 { 0, 0, 1, 0 },
119 { 0, 0, 0, 1 } };
120 /* Draw test pattern in multisample test_fbo with GL_POINT_SMOOTH
121 * disabled.
123 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, test_fbo.handle);
124 glClear(buffer_to_test);
125 test_fbo.set_viewport();
126 test_pattern->draw(proj);
128 /* Blit test_fbo to the right half of window system framebuffer.
129 * This is the reference image.
131 glBindFramebuffer(GL_READ_FRAMEBUFFER, test_fbo.handle);
132 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
133 glBlitFramebuffer(0, 0, pattern_width, pattern_height,
134 pattern_width, 0, 2*pattern_width, pattern_height,
135 GL_COLOR_BUFFER_BIT, GL_NEAREST);
137 /* Draw test pattern in mulisample test_fbo with GL_POINT_SMOOTH
138 * enabled
140 glEnable (GL_POINT_SMOOTH);
141 glHint( GL_POINT_SMOOTH_HINT, GL_NICEST );
142 glDisable (GL_DEPTH_TEST);
144 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, test_fbo.handle);
145 test_fbo.set_viewport();
146 test_pattern->draw(proj);
148 glDisable(GL_POINT_SMOOTH);
150 /* Now blit test_fbo to the left half of window system framebuffer.
151 * This is the test image.
153 glBindFramebuffer(GL_READ_FRAMEBUFFER, test_fbo.handle);
154 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
155 glBlitFramebuffer(0, 0, pattern_width, pattern_height,
156 0, 0, pattern_width, pattern_height,
157 GL_COLOR_BUFFER_BIT, GL_NEAREST);
159 /* Check that the left and right halves of the screen match. If they
160 * don't, then GL_POINT_SMOOTH is not ignored with multisample
161 * rendering.
163 glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
164 pass = piglit_probe_rect_halves_equal_rgba(0, 0, piglit_width,
165 piglit_height) && pass;
167 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
169 piglit_present_results();
171 return pass ? PIGLIT_PASS : PIGLIT_FAIL;