ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / spec / ext_framebuffer_multisample / alpha-to-coverage-no-draw-buffer-zero.cpp
blobb972fa5aebb924af5423a6b6591477aa4b658913
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 alpha-to-coverage-no-draw-buffer-zero.cpp
29 * Verify sample alpha to coverage with multiple draw buffers when nothing
30 * is bound to draw buffer zero.
32 * When nothing is bound to draw buffer zero, GL_SAMPLE_ALPHA_TO_COVERAGE
33 * still needs to work properly for rest of the draw buffers. The alpha value
34 * used to determine coverage should come from draw buffer zero.
36 * This test operates by drawing a pattern in multisample FBO to generate
37 * reference and test images for all the draw buffers. Reference images are
38 * drawn to right half of window system draw buffer and test images to left
39 * half.
41 * Compute the expected color values for all the draw buffers.
43 * Probe all the draw buffers blitted to downsampled FBO (resolve_fbo) and
44 * compare against expected color values.
46 * Author: Anuj Phogat <anuj.phogat@gmail.com>
49 PIGLIT_GL_TEST_CONFIG_BEGIN
51 config.supports_gl_compat_version = 10;
53 config.window_width = 512;
54 config.window_height = 768;
55 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
56 config.khr_no_error_support = PIGLIT_NO_ERRORS;
58 PIGLIT_GL_TEST_CONFIG_END
60 void
61 print_usage_and_exit(char *prog_name)
63 printf("Usage: %s <num_samples>\n", prog_name);
64 piglit_report_result(PIGLIT_FAIL);
67 void
68 piglit_init(int argc, char **argv)
70 int samples;
71 /* At present fragment shader supports only fixed number of
72 * attachments (3)
74 int num_attachments = 3;
76 if (argc < 2)
77 print_usage_and_exit(argv[0]);
79 char *endptr = NULL;
80 samples = strtol(argv[1], &endptr, 0);
81 if (endptr != argv[1] + strlen(argv[1]))
82 print_usage_and_exit(argv[0]);
85 piglit_require_gl_version(21);
86 piglit_require_extension("GL_ARB_framebuffer_object");
87 piglit_require_extension("GL_ARB_vertex_array_object");
89 int pattern_width = piglit_width / 2;
90 int pattern_height = piglit_height / num_attachments;
92 piglit_ortho_projection(pattern_width,
93 pattern_height,
94 GL_TRUE);
96 /* Skip the test if samples > GL_MAX_SAMPLES */
97 GLint max_samples;
98 glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
100 if (samples > max_samples)
101 piglit_report_result(PIGLIT_SKIP);
103 ms_fbo_and_draw_buffers_setup(samples,
104 pattern_width,
105 pattern_height,
106 num_attachments,
107 GL_COLOR_BUFFER_BIT,
108 GL_NONE /* color_buffer_zero_format */);
109 shader_compile(true /* sample_alpha_to_coverage */,
110 false /* dual_src_blend */,
111 true /* frag_out_zero_write */);
114 enum piglit_result
115 piglit_display()
117 bool pass = true;
118 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
119 glClearColor(0.0, 0.0, 0.0, 1.0);
120 glClear(GL_COLOR_BUFFER_BIT);
121 allocate_data_arrays();
123 /* Reference image drawn when sample_alpha_to_coverage is enabled,
124 * doesn't represent an expected image. Reference image is drawn only
125 * to visualize the image difference caused by enabling
126 * sample_alpha_to_coverage
128 draw_reference_image(true /* sample_alpha_to_coverage */,
129 false /* sample_alpha_to_one */);
131 draw_test_image(true /* sample_alpha_to_coverage */,
132 false /* sample_alpha_to_one */);
134 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
136 /* Probe test images of all the draw_buffers blitted to resolve fbo
137 * and compare with expected color values. This method of verification
138 * is appropriate for tests with sample-alpha-to-coverage enabled.
139 * Possibility of dithering effect when the coverage value is not a
140 * strict multiple of 1 / num_samples makes image compare (test /
141 * reference image) unsuitable for this test.
143 pass = probe_framebuffer_color() && pass;
145 /* Free the memory allocated for data arrays */
146 free_data_arrays();
148 if (!piglit_automatic)
149 piglit_present_results();
151 return pass ? PIGLIT_PASS : PIGLIT_FAIL;