ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_framebuffer_multisample / sample-alpha-to-coverage.cpp
blob397c7569de8352f3f1c94ef1f568f59a90444af0
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 sample-alpha-to-coverage.cpp
29 * Verify sample alpha to coverage with multisample FBO
31 * When rendering to multisample FBO, fragment's alpha value should be
32 * used to determine the coverage value.
34 * This test operates by drawing a pattern in multisample FBO to generate
35 * reference and test image. Reference image is drawn to right half of window
36 * system frame buffer and test image to left half.
38 * Compute the expected color / depth values.
40 * Probe color / depth buffer blitted to downsampled FBO (resolve_fbo) and
41 * compare against expected color values.
43 * Author: Anuj Phogat <anuj.phogat@gmail.com>
46 PIGLIT_GL_TEST_CONFIG_BEGIN
48 config.supports_gl_compat_version = 10;
50 config.window_width = 512;
51 config.window_height = 256;
52 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
53 config.khr_no_error_support = PIGLIT_NO_ERRORS;
55 PIGLIT_GL_TEST_CONFIG_END
57 static GLenum buffer_to_test;
59 void
60 print_usage_and_exit(char *prog_name)
62 printf("Usage: %s <num_samples> <test_type>\n"
63 " where <test_type> is one of:\n"
64 " color\n"
65 " depth\n",
66 prog_name);
67 piglit_report_result(PIGLIT_FAIL);
70 void
71 piglit_init(int argc, char **argv)
73 const int num_attachments = 1;
74 int samples;
76 piglit_require_gl_version(21);
77 piglit_require_extension("GL_ARB_framebuffer_object");
78 piglit_require_extension("GL_ARB_vertex_array_object");
80 if (argc < 3)
81 print_usage_and_exit(argv[0]);
83 char *endptr = NULL;
84 samples = strtol(argv[1], &endptr, 0);
85 if (endptr != argv[1] + strlen(argv[1]))
86 print_usage_and_exit(argv[0]);
88 if (strcmp(argv[2], "color") == 0) {
89 buffer_to_test = GL_COLOR_BUFFER_BIT;
90 } else if (strcmp(argv[2], "depth") == 0) {
91 buffer_to_test = GL_DEPTH_BUFFER_BIT;
92 glEnable(GL_DEPTH_TEST);
93 glDepthFunc(GL_ALWAYS);
94 } else
95 print_usage_and_exit(argv[0]);
97 int pattern_width = piglit_width / 2;
98 int pattern_height = piglit_height / num_attachments;
100 piglit_ortho_projection(pattern_width,
101 pattern_height,
102 GL_TRUE);
104 /* Skip the test if samples > GL_MAX_SAMPLES */
105 GLint max_samples;
106 glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
108 if (samples > max_samples)
109 piglit_report_result(PIGLIT_SKIP);
111 ms_fbo_and_draw_buffers_setup(samples,
112 pattern_width,
113 pattern_height,
114 num_attachments,
115 buffer_to_test,
116 GL_RGBA);
117 shader_compile(true /* sample_alpha_to_coverage */,
118 false /* dual_src_blend */,
119 true /* frag_out_zero_write */);
122 enum piglit_result
123 piglit_display()
125 bool pass = true;
126 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, piglit_winsys_fbo);
127 glClearColor(0.0, 0.0, 0.0, 1.0);
128 glClear(GL_COLOR_BUFFER_BIT);
129 allocate_data_arrays();
131 /* Reference image drawn here doesn't represent an expected image.
132 * Reference image is drawn only to visualize the image difference
133 * caused by enabling sample_alpha_to_coverage in test image.
135 if(buffer_to_test == GL_COLOR_BUFFER_BIT)
136 draw_reference_image(true /* sample_alpha_to_coverage */,
137 false /* sample_alpha_to_one */);
139 draw_test_image(true /* sample_alpha_to_coverage */,
140 false /* sample_alpha_to_one */);
142 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
144 /* Probe all the test image blitted to resolve fbo and compare with
145 * expected color values. This method of verification is appropriate
146 * for tests with sample-alpha-to-coverage enabled. Possibility of
147 * dithering effect when the coverage value is not a strict multiple
148 * of 1 / num_samples makes image compare (test / reference image)
149 * unsuitable for this test.
151 if(buffer_to_test == GL_COLOR_BUFFER_BIT)
152 pass = probe_framebuffer_color() && pass;
153 else if (buffer_to_test == GL_DEPTH_BUFFER_BIT)
154 pass = probe_framebuffer_depth() && pass;
156 /* Free the memory allocated for data arrays */
157 free_data_arrays();
159 if (!piglit_automatic && buffer_to_test == GL_COLOR_BUFFER_BIT)
160 piglit_present_results();
162 return pass ? PIGLIT_PASS : PIGLIT_FAIL;