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
24 #include "draw-buffers-common.h"
27 * \file draw-buffers-alpha-to-coverage.cpp
29 * Verify sample alpha to coverage with multiple draw buffers
31 * When rendering to multiple draw buffers, the alpha value used by
32 * GL_SAMPLE_TO_COVERAGE should come from draw buffer zero, but it should
33 * have an effect on all the draw buffers.
35 * This test operates by drawing a pattern in multisample FBO to generate
36 * reference and test images for all the draw buffers. Reference images are drawn
37 * to right half of window system draw buffer and test images to left half.
39 * Compute the expected color values for all the draw buffers.
41 * Probe all the draw buffers blitted to downsampled FBO (resolve_fbo) and
42 * compare against expected color values.
44 * Author: Anuj Phogat <anuj.phogat@gmail.com>
47 PIGLIT_GL_TEST_CONFIG_BEGIN
49 config
.supports_gl_compat_version
= 10;
51 config
.window_width
= 512;
52 config
.window_height
= 768;
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
59 print_usage_and_exit(char *prog_name
)
61 printf("Usage: %s <num_samples>\n", prog_name
);
62 piglit_report_result(PIGLIT_FAIL
);
66 piglit_init(int argc
, char **argv
)
69 /* At present fragment shader supports only fixed number of
72 int num_attachments
= 3;
75 print_usage_and_exit(argv
[0]);
78 samples
= strtol(argv
[1], &endptr
, 0);
79 if (endptr
!= argv
[1] + strlen(argv
[1]))
80 print_usage_and_exit(argv
[0]);
83 piglit_require_gl_version(21);
84 piglit_require_extension("GL_ARB_framebuffer_object");
85 piglit_require_extension("GL_ARB_vertex_array_object");
87 int pattern_width
= piglit_width
/ 2;
88 int pattern_height
= piglit_height
/ num_attachments
;
90 piglit_ortho_projection(pattern_width
,
94 /* Skip the test if samples > GL_MAX_SAMPLES */
96 glGetIntegerv(GL_MAX_SAMPLES
, &max_samples
);
98 if (samples
> max_samples
)
99 piglit_report_result(PIGLIT_SKIP
);
101 ms_fbo_and_draw_buffers_setup(samples
,
107 shader_compile(true /* sample_alpha_to_coverage */,
108 false /* dual_src_blend */,
109 true /* frag_out_zero_write */);
116 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
117 glClearColor(0.0, 0.0, 0.0, 1.0);
118 glClear(GL_COLOR_BUFFER_BIT
);
119 allocate_data_arrays();
121 /* Reference image drawn when sample_alpha_to_coverage is enabled,
122 * doesn't represent an expected image. Reference image is drawn only
123 * to visualize the image difference caused by enabling
124 * sample_alpha_to_coverage
126 draw_reference_image(true /* sample_alpha_to_coverage */,
127 false /* sample_alpha_to_one */);
129 draw_test_image(true /* sample_alpha_to_coverage */,
130 false /* sample_alpha_to_one */);
132 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
134 /* Probe test images of all the draw_buffers blitted to resolve fbo
135 * and compare with expected color values. This method of verification
136 * is appropriate for tests with sample-alpha-to-coverage enabled.
137 * Possibility of dithering effect when the coverage value is not a
138 * strict multiple of 1 / num_samples makes image compare (test /
139 * reference image) unsuitable for this test.
141 pass
= probe_framebuffer_color() && pass
;
143 /* Free the memory allocated for data arrays */
146 if (!piglit_automatic
)
147 piglit_present_results();
149 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;