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
28 * Verify the accuracy of multisample antialiasing.
30 * This test utilizes the functions defined in common.cpp to verfify the
33 * The test also accepts the following flags:
35 * - "small": Causes the MSAA image to be renedered in extremely tiny
36 * (16x16) tiles that are then stitched together. This verifies
37 * that MSAA works properly on very small buffers (a critical corner
40 * - "depthstencil": Causes the framebuffers to use a combined
41 * depth/stencil buffer (as opposed to separate depth and stencil
42 * buffers). On some implementations (e.g. the nVidia proprietary
43 * driver for Linux) this is necessary for framebuffer completeness.
44 * On others (e.g. i965), this is an important corner case to test.
47 PIGLIT_GL_TEST_CONFIG_BEGIN
49 config
.supports_gl_compat_version
= 10;
51 config
.window_width
= 512;
52 config
.window_height
= 256;
53 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
54 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
56 PIGLIT_GL_TEST_CONFIG_END
58 const int pattern_width
= 256; const int pattern_height
= 256;
59 const int supersample_factor
= 16;
60 int num_samples
, max_samples
;
61 bool small
= false, combine_depth_stencil
= false;
62 bool all_samples
= false;
63 GLenum filter_mode
= GL_NEAREST
;
64 test_type_enum test_type
;
68 print_usage_and_exit(char *prog_name
)
70 printf("Usage: %s <sample_arg> <test_type> [options]\n"
71 " where <sample_arg> is one of:\n"
72 " <num_samples>: test supplied sample count\n"
73 " all_samples: test all power of 2 samples\n"
74 " where <test_type> is one of:\n"
75 " color: test downsampling of color buffer\n"
76 " srgb: test downsampling of srgb color buffer\n"
77 " stencil_draw: test drawing using MSAA stencil buffer\n"
78 " stencil_resolve: test resolve of MSAA stencil buffer\n"
79 " depth_draw: test drawing using MSAA depth buffer\n"
80 " depth_resolve: test resolve of MSAA depth buffer\n"
81 "Available options:\n"
82 " small: use a very small (16x16) MSAA buffer\n"
83 " depthstencil: use a combined depth/stencil buffer\n"
84 " linear: use GL_LINEAR filter mode\n",
86 piglit_report_result(PIGLIT_FAIL
);
90 piglit_init(int argc
, char **argv
)
95 print_usage_and_exit(argv
[0]);
98 if (streq(argv
[1], "all_samples"))
101 num_samples
= strtol(argv
[1], &endptr
, 0);
102 if (endptr
!= argv
[1] + strlen(argv
[1]))
103 print_usage_and_exit(argv
[0]);
107 for (i
= 3; i
< argc
; ++i
) {
108 if (strcmp(argv
[i
], "small") == 0) {
110 } else if (strcmp(argv
[i
], "depthstencil") == 0) {
111 combine_depth_stencil
= true;
112 } else if (strcmp(argv
[i
], "linear") == 0) {
113 filter_mode
= GL_LINEAR
;
115 print_usage_and_exit(argv
[0]);
119 piglit_require_gl_version(21);
120 piglit_require_extension("GL_ARB_framebuffer_object");
121 piglit_require_extension("GL_ARB_vertex_array_object");
123 /* Skip the test if num_samples > GL_MAX_SAMPLES */
124 glGetIntegerv(GL_MAX_SAMPLES
, &max_samples
);
125 if (num_samples
> max_samples
)
126 piglit_report_result(PIGLIT_SKIP
);
128 if (strcmp(argv
[2], "color") == 0) {
129 test_type
= TEST_TYPE_COLOR
;
130 } else if (strcmp(argv
[2], "srgb") == 0) {
131 test_type
= TEST_TYPE_SRGB
;
132 } else if (strcmp(argv
[2], "stencil_draw") == 0) {
133 test_type
= TEST_TYPE_STENCIL_DRAW
;
134 } else if (strcmp(argv
[2], "stencil_resolve") == 0) {
135 test_type
= TEST_TYPE_STENCIL_RESOLVE
;
136 } else if (strcmp(argv
[2], "depth_draw") == 0) {
137 test_type
= TEST_TYPE_DEPTH_DRAW
;
138 } else if (strcmp(argv
[2], "depth_resolve") == 0) {
139 test_type
= TEST_TYPE_DEPTH_RESOLVE
;
141 print_usage_and_exit(argv
[0]);
146 test_create_and_execute()
148 test
= create_test(test_type
, num_samples
, small
,
149 combine_depth_stencil
,
150 pattern_width
, pattern_height
, supersample_factor
,
158 bool pass
= true, result
= pass
;
161 pass
= test_create_and_execute() && pass
;
162 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
163 piglit_present_results();
164 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
167 for (num_samples
= 0; num_samples
<= max_samples
; ) {
168 result
= test_create_and_execute();
169 result
= piglit_check_gl_error(GL_NO_ERROR
) && result
;
170 printf("Samples = %d, Result = %s\n\n",
171 num_samples
, result
? "pass" : "fail");
172 pass
= result
&& pass
;
173 /* Test only power of 2 samples */
174 num_samples
= num_samples
? num_samples
<< 1: num_samples
+ 2;
175 piglit_present_results();
178 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;