ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_framebuffer_multisample / draw-buffers-alpha-to-one.cpp
blobfe171d22dcacff4ca0eea1ae5b1eebc23c750992
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 "draw-buffers-common.h"
26 /**
27 * \file draw-buffers-alpha-to-one.cpp
29 * Verify sample alpha to one with multiple draw buffers
31 * When rendering to multiple draw buffers, GL_SAMPLE_ALPHA_TO_ONE should
32 * modify the alpha values sent to each draw buffer. OpenGL 3.3 specification's
33 * section 4.1.3 (page 196 of pdf) is little unclear about the exact behavior
34 * in above mentioned case:
36 * "All alpha values in this section refer only to the alpha component of the
37 * fragment shader output linked to color number zero, index zero (see section
38 * 3.9.2) if a fragment shader is in use, or the alpha component of the result
39 * of fixed-function fragment shading. If the fragment shader does not write to
40 * this output, the alpha value is undefined."
42 * And later in the same section it is stated that:
44 * "Next, if SAMPLE_ALPHA_TO_ONE is enabled, each alpha value is replaced by
45 * the maximum representable alpha value for fixed-point color buffers, or by
46 * 1.0 for floating-point buffers. Otherwise, the alpha values are not changed."
48 * By reading above two references together, specification seems to suggest that
49 * alpha values for only draw buffer zero will be modified when GL_SAMPLE_TO_ONE.
50 * is enabled. But with NVIDIA's proprietary drivers this test verifies that
51 * alpha values for all the draw buffers will be modified. In my opinion, this
52 * section needs clarification from khronos.
54 * At present test is based on the behavior observed with NVIDIA's proprietary
55 * drivers.
57 * This test operates by drawing a pattern in multisample FBO to generate
58 * reference and test images for all the draw buffers. Reference images are drawn
59 * to right half of window system draw buffer and test images to left half.
61 * Compare the left and right halves of window system frame buffer to verify
62 * the test image.
64 * Author: Anuj Phogat <anuj.phogat@gmail.com>
67 PIGLIT_GL_TEST_CONFIG_BEGIN
69 config.supports_gl_compat_version = 10;
71 config.window_width = 512;
72 config.window_height = 768;
73 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
74 config.khr_no_error_support = PIGLIT_NO_ERRORS;
76 PIGLIT_GL_TEST_CONFIG_END
78 static int samples;
80 void
81 print_usage_and_exit(char *prog_name)
83 printf("Usage: %s <num_samples>\n", prog_name);
84 piglit_report_result(PIGLIT_FAIL);
87 void
88 piglit_init(int argc, char **argv)
90 /* At present fragment shader supports only fixed number of
91 * attachments (3)
93 int num_attachments = 3;
95 if (argc < 2)
96 print_usage_and_exit(argv[0]);
98 char *endptr = NULL;
99 samples = strtol(argv[1], &endptr, 0);
100 if (endptr != argv[1] + strlen(argv[1]))
101 print_usage_and_exit(argv[0]);
104 piglit_require_gl_version(21);
105 piglit_require_extension("GL_ARB_framebuffer_object");
106 piglit_require_extension("GL_ARB_vertex_array_object");
108 int pattern_width = piglit_width / 2;
109 int pattern_height = piglit_height / num_attachments;
111 piglit_ortho_projection(pattern_width,
112 pattern_height,
113 GL_TRUE);
115 /* Skip the test if samples > GL_MAX_SAMPLES */
116 GLint max_samples;
117 glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
119 if (samples > max_samples)
120 piglit_report_result(PIGLIT_SKIP);
122 ms_fbo_and_draw_buffers_setup(samples,
123 pattern_width,
124 pattern_height,
125 num_attachments,
126 GL_COLOR_BUFFER_BIT,
127 GL_RGBA);
128 shader_compile(false /* sample_alpha_to_coverage */,
129 false /* dual_src_blend */,
130 true /* frag_out_zero_write */);
133 enum piglit_result
134 piglit_display()
136 bool pass = true;
137 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
138 glClearColor(0.0, 0.0, 0.0, 1.0);
139 glClear(GL_COLOR_BUFFER_BIT);
140 allocate_data_arrays();
142 draw_reference_image(false /* sample_alpha_to_coverage */,
143 true /* sample_alpha_to_one */);
145 draw_test_image(false /* sample_alpha_to_coverage */,
146 true /* sample_alpha_to_one */);
148 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
150 glBindFramebuffer(GL_READ_FRAMEBUFFER, piglit_winsys_fbo);
151 pass = piglit_probe_rect_halves_equal_rgba(0, 0,
152 piglit_width,
153 piglit_height)
154 && pass;
156 /* Free the memory allocated for data arrays */
157 free_data_arrays();
159 if (!piglit_automatic)
160 piglit_present_results();
162 return pass ? PIGLIT_PASS : PIGLIT_FAIL;