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 /** \file alpha-blending.c
26 * This test checks for Mesa bug 53077 (Output error with msaa when
27 * both of framebuffer and source color's alpha are not 1). The test
28 * operates by drawing a partially transparent non-square rectangle to
29 * a multisampled buffer (using a triangle fan) and then blitting the
30 * result to the screen. If the bug is present, artifacts will appear
31 * along the rectangle diagonal due to alpha blending being performed
32 * incorrectly while drawing the first triangle of the fan.
34 * See also https://bugs.freedesktop.org/show_bug.cgi?id=53077
36 * Note: when fast color clears are implemented for MSAA buffers, it's
37 * possible that they will cover up this bug. To avoid that, the test
38 * can be supplied a command-line option of "slow_cc", which causes it
39 * to use a clear color that cannot be fast cleared.
42 #include "piglit-util-gl.h"
44 GLuint framebuffer
, renderbuffer
;
48 static bool slow_color_clear
= false;
50 PIGLIT_GL_TEST_CONFIG_BEGIN
52 config
.supports_gl_compat_version
= 10;
54 config
.window_width
= WIDTH
;
55 config
.window_height
= HEIGHT
;
56 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
57 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
58 slow_color_clear
= PIGLIT_STRIP_ARG("slow_cc");
60 PIGLIT_GL_TEST_CONFIG_END
63 piglit_init(int argc
, char **argv
)
65 glGetIntegerv(GL_MAX_SAMPLES_EXT
, &numSamples
);
67 glGenFramebuffersEXT(1, &framebuffer
);
68 glGenRenderbuffersEXT(1, &renderbuffer
);
69 glBindFramebufferEXT(GL_FRAMEBUFFER
, framebuffer
);
70 glBindRenderbufferEXT(GL_RENDERBUFFER
, renderbuffer
);
71 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER
, numSamples
, GL_RGBA
, WIDTH
, HEIGHT
);
72 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, renderbuffer
);
73 glEnable (GL_MULTISAMPLE
);
79 GLenum src_factor
, dst_factor
;
80 float expected_color
[] = { 0.0, 0.7, 0.0, 0.79 };
86 float vertex_data
[][2] = {
87 { ((float) x0
)/WIDTH
* 2.0 - 1.0, ((float) y0
)/HEIGHT
* 2.0 - 1.0 },
88 { ((float) x1
)/WIDTH
* 2.0 - 1.0, ((float) y0
)/HEIGHT
* 2.0 - 1.0 },
89 { ((float) x1
)/WIDTH
* 2.0 - 1.0, ((float) y1
)/HEIGHT
* 2.0 - 1.0 },
90 { ((float) x0
)/WIDTH
* 2.0 - 1.0, ((float) y1
)/HEIGHT
* 2.0 - 1.0 },
93 glBindFramebufferEXT(GL_FRAMEBUFFER
,framebuffer
);
95 if (slow_color_clear
) {
96 glColor4f (0.0, 1.0, 0.5, 0.7);
97 glClearColor(0.0, 0.0, 0.5, 1.0);
98 expected_color
[2] = 0.5;
100 glColor4f (0.0, 1.0, 0.0, 0.7);
101 glClearColor(0.0, 0.0, 0.0, 1.0);
103 glClear(GL_COLOR_BUFFER_BIT
);
106 src_factor
= GL_SRC_ALPHA
;
107 dst_factor
= GL_ONE_MINUS_SRC_ALPHA
;
108 glBlendFunc (src_factor
, dst_factor
);
109 glVertexPointer(2, GL_FLOAT
, 0, vertex_data
);
110 glEnableClientState(GL_VERTEX_ARRAY
);
111 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
113 glBindFramebufferEXT(GL_READ_FRAMEBUFFER
, framebuffer
);
114 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
115 glBlitFramebuffer(0, 0, WIDTH
, HEIGHT
, 0, 0, WIDTH
, HEIGHT
, GL_COLOR_BUFFER_BIT
, GL_NEAREST
);
116 glBindFramebuffer(GL_FRAMEBUFFER
, piglit_winsys_fbo
);
118 pass
= piglit_probe_rect_rgba(x0
, y0
, x1
- x0
, y1
- y0
, expected_color
)
121 piglit_present_results();
123 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;