fbo-mrt-alphatest: Actually require MRTs to be available.
[piglit.git] / tests / fbo / fbo-mrt-alphatest.c
blob7b7c17a23ce9ddf54610c18bfe02b90fb46b6efd
1 /*
2 * Copyright © 2013 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.
23 * Authors:
24 * Chris Forbes <chrisf@ijw.co.nz>
29 * fbo-mrt-alphatest asserts correct behavior for alpha-testing of fragments
30 * when multiple color buffers are being rendered to. In particular, the alpha
31 * component of the first color output is used for the alpha test.
33 * This is important for deferred renderers which use alpha-test, and is a
34 * significant edge case for the i965 driver.
37 #include "piglit-util-gl.h"
39 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config.supports_gl_compat_version = 21;
43 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
44 config.khr_no_error_support = PIGLIT_NO_ERRORS;
46 PIGLIT_GL_TEST_CONFIG_END
48 GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
49 GLuint fbo;
50 GLint prog;
51 GLuint color0, color1;
53 void
54 piglit_init(int argc, char **argv)
56 piglit_require_GLSL_version(120);
57 piglit_require_minimum_getinteger(GL_MAX_DRAW_BUFFERS, 2);
59 glGenFramebuffers(1, &fbo);
60 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
62 glGenTextures(1, &color0);
63 glBindTexture(GL_TEXTURE_2D, color0);
64 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
65 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
66 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
67 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color0, 0);
69 glGenTextures(1, &color1);
70 glBindTexture(GL_TEXTURE_2D, color1);
71 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
72 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
73 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
74 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, color1, 0);
76 glDrawBuffers(2, buffers);
78 prog = piglit_build_simple_program(
79 "#version 120\n"
80 "attribute vec4 pos;\n"
81 "void main() {\n"
82 " gl_Position = pos;\n"
83 "}\n",
85 "#version 120\n"
86 "void main() {\n"
87 " float alpha = mod(floor(gl_FragCoord.x / 16 + gl_FragCoord.y / 16), 2);\n"
88 " gl_FragData[0] = vec4(1.0, 0.0, 0.0, alpha);\n"
89 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
90 "}\n"
93 if (!piglit_check_gl_error(GL_NO_ERROR)) {
94 printf("Setup for test failed.\n");
95 piglit_report_result(PIGLIT_SKIP);
98 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
99 printf("Framebuffer not complete.\n");
100 piglit_report_result(PIGLIT_SKIP);
105 enum piglit_result
106 piglit_display(void)
108 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
109 glClearColor(0,0,1,0);
110 glClear(GL_COLOR_BUFFER_BIT);
112 glAlphaFunc(GL_GEQUAL, 0.5f);
113 glEnable(GL_ALPHA_TEST);
115 glUseProgram(prog);
116 glViewport(0, 0, 64, 64);
117 piglit_draw_rect(-1, -1, 2, 2);
119 glDisable(GL_ALPHA_TEST);
121 /* visualize it */
122 glUseProgram(0);
123 glBindFramebuffer(GL_FRAMEBUFFER, piglit_winsys_fbo);
124 glViewport(0, 0, 128, 64);
125 glClearColor(0,0,0.5,0);
126 glClear(GL_COLOR_BUFFER_BIT);
128 glEnable(GL_TEXTURE_2D);
130 glBindTexture(GL_TEXTURE_2D, color0);
131 piglit_draw_rect_tex(-1, -1, 1, 2,
132 0, 0, 1, 1);
133 glBindTexture(GL_TEXTURE_2D, color1);
134 piglit_draw_rect_tex(0, -1, 1, 2,
135 0, 0, 1, 1);
137 glDisable(GL_TEXTURE_2D);
140 bool pass = true;
141 float red[] = {1,0,0};
142 float green[] = {0,1,0};
143 float blue[] = {0,0,1};
144 pass = piglit_probe_pixel_rgb(4, 4, blue) && pass;
145 pass = piglit_probe_pixel_rgb(12, 4, red) && pass;
146 pass = piglit_probe_pixel_rgb(64 + 4, 4, blue) && pass;
147 pass = piglit_probe_pixel_rgb(64 + 12, 4, green) && pass;
149 piglit_present_results();
151 return pass ? PIGLIT_PASS : PIGLIT_FAIL;