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
27 * This test varifies turning multisampling on/off by setting up FBO with
28 * appropriate sample count.
30 * 1. Render the geometry to left half of default framebuffer and read color
31 * buffer in to a local buffer.
33 * 2. Create a FBO with MSAA turned OFF. Compare the rendered geometry with
34 * buffer in Step 1. It is expected to match.
36 * 3. Turn ON MSAA in FBO. Render the scene, draw reference image and measure
37 * the accuracy of MSAA. This varifies if MSAA is turned ON.
39 * 4. Turn OFF MSAA in FBO. Render the scene and compare to the buffer in
40 * step 1. It is expected to match.
42 * Test image is rendered in to left half of framebuffer.
43 * Reference image is rendered in to right half of framebuffer.
45 * TODO: Add testing for depth and stencil buffers.
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
;
55 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
57 PIGLIT_GL_TEST_CONFIG_END
59 static int num_samples
= 0;
60 const int pattern_width
= 256;
61 const int pattern_height
= 256;
69 GLint w
= pattern_width
, h
= pattern_height
;
70 GLfloat
*color_buffer
= NULL
;
72 test
->draw_to_default_framebuffer();
74 /* Read color buffer */
75 glBindFramebuffer(GL_READ_FRAMEBUFFER
, piglit_winsys_fbo
);
76 color_buffer
= (GLfloat
*) malloc(w
* h
* 4 * sizeof(float));
77 glReadPixels(0, 0, w
, h
, GL_RGBA
, GL_FLOAT
, color_buffer
);
79 /* Draw the test pattern in to test_fbo with num_samples = 0. This
80 * is to verify if glRenderbufferStorageMultisample() with zero sample
81 * count turns off MSAA.
83 test
->test_fbo
.set_samples(0);
84 test
->draw_test_image(&test
->test_fbo
);
86 /* Compare rendered scene with color_buffer */
87 glBindFramebuffer(GL_READ_FRAMEBUFFER
, test
->test_fbo
.handle
);
88 pass
= piglit_probe_image_rgba(0, 0, w
, h
, color_buffer
)
91 /* Switch ON MSAA in this FBO by passing num_samples > 0 */
92 test
->test_fbo
.set_samples(num_samples
);
94 /* Draw test image in multisample FBO */
95 test
->draw_test_image(&test
->test_fbo
);
97 /* Draw a reference image for MSAA */
98 test
->draw_reference_image();
100 /* Measure the accuracy of MSAA in multisample FBO by comparing the
101 * test image to reference image. This varifies if MSAA is actually
104 pass
= test
->measure_accuracy() && pass
;
106 /* Switch OFF MSAA again in this FBO */
107 test
->test_fbo
.set_samples(0);
108 test
->draw_test_image(&test
->test_fbo
);
110 /* Compare rendered scene with color_buffer */
111 glBindFramebuffer(GL_READ_FRAMEBUFFER
, test
->test_fbo
.handle
);
112 pass
= piglit_probe_image_rgba(0, 0, w
, h
, color_buffer
)
115 if (!piglit_automatic
)
116 piglit_present_results();
117 return (pass
? PIGLIT_PASS
: PIGLIT_FAIL
);
121 print_usage_and_exit(char *prog_name
)
123 printf("Usage: %s <num_samples>\n", prog_name
);
124 piglit_report_result(PIGLIT_FAIL
);
128 piglit_init(int argc
, char **argv
)
132 print_usage_and_exit(argv
[0]);
135 num_samples
= strtol(argv
[1], &endptr
, 0);
136 if (endptr
!= argv
[1] + strlen(argv
[1]))
137 print_usage_and_exit(argv
[0]);
140 piglit_require_gl_version(21);
141 piglit_require_extension("GL_ARB_framebuffer_object");
142 piglit_require_extension("GL_ARB_vertex_array_object");
144 /* Skip the test if num_samples > GL_MAX_SAMPLES */
145 glGetIntegerv(GL_MAX_SAMPLES
, &max_samples
);
146 if (num_samples
> max_samples
) {
147 printf("Sample count not supported : %d\n", num_samples
);
148 piglit_report_result(PIGLIT_SKIP
);
151 test
= create_test(TEST_TYPE_COLOR
, num_samples
,
153 true /* combine_depth_stencil */,
154 pattern_width
, pattern_height
,
155 16 /* supersample_factor */,