2 * Copyright © 2010 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 * Eric Anholt <eric@anholt.net>
28 /** @file fbo-drawbuffers2-colormask.c
30 * Tests that individual color masks per render target with
31 * EXT_draw_buffers2 works.
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config
.supports_gl_compat_version
= 10;
40 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
41 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
43 PIGLIT_GL_TEST_CONFIG_END
45 static GLboolean test_clear
;
52 glGenTextures(1, &tex
);
53 glBindTexture(GL_TEXTURE_2D
, tex
);
54 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
,
55 piglit_width
, piglit_height
, 0,
56 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
58 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
59 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
61 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
,
62 GL_COLOR_ATTACHMENT0_EXT
+ i
,
66 if (!piglit_check_gl_error(GL_NO_ERROR
))
67 piglit_report_result(PIGLIT_FAIL
);
75 GLboolean pass
= GL_TRUE
;
76 GLuint tex0
, tex1
, fb
;
78 float white
[] = {1, 1, 1, 1};
79 float green
[] = {0, 1, 0, 0};
80 float blue
[] = {0, 0, 1, 0};
81 const GLenum attachments
[] = {
82 GL_COLOR_ATTACHMENT0_EXT
,
83 GL_COLOR_ATTACHMENT1_EXT
,
86 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
88 glGenFramebuffersEXT(1, &fb
);
89 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, fb
);
91 tex0
= attach_texture(0);
92 tex1
= attach_texture(1);
94 glDrawBuffersARB(2, attachments
);
96 status
= glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT
);
97 if (status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
98 fprintf(stderr
, "fbo incomplete (status = 0x%04x)\n", status
);
99 piglit_report_result(PIGLIT_SKIP
);
103 glClearColor(0.0, 0.0, 0.0, 0.0);
104 glClear(GL_COLOR_BUFFER_BIT
);
106 /* Mask only green in RT 0, blue in RT 1, then try to draw in white */
107 glColorMaskIndexedEXT(0, GL_FALSE
, GL_TRUE
, GL_FALSE
, GL_FALSE
);
108 glColorMaskIndexedEXT(1, GL_FALSE
, GL_FALSE
, GL_TRUE
, GL_FALSE
);
111 glClearColor(1.0, 1.0, 1.0, 1.0);
112 glClear(GL_COLOR_BUFFER_BIT
);
115 piglit_draw_rect(0, 0, piglit_width
, piglit_height
);
118 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, piglit_winsys_fbo
);
119 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
);
121 /* Draw the two textures to halves of the window. */
122 glEnable(GL_TEXTURE_2D
);
123 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
124 glBindTexture(GL_TEXTURE_2D
, tex0
);
125 piglit_draw_rect_tex(0, 0,
126 piglit_width
/ 2, piglit_height
,
128 glBindTexture(GL_TEXTURE_2D
, tex1
);
129 piglit_draw_rect_tex(piglit_width
/ 2, 0,
130 piglit_width
, piglit_height
,
132 glDisable(GL_TEXTURE_2D
);
133 glDeleteTextures(1, &tex0
);
134 glDeleteTextures(1, &tex1
);
135 glDeleteFramebuffersEXT(1, &fb
);
137 pass
= pass
&& piglit_probe_rect_rgb(0, 0, piglit_width
/2,
138 piglit_height
, green
);
139 pass
= pass
&& piglit_probe_rect_rgb(piglit_width
/2, 0, piglit_width
/2,
140 piglit_height
, blue
);
142 piglit_present_results();
144 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
148 piglit_init(int argc
, char **argv
)
153 for (i
= 1; i
< argc
; i
++) {
154 if (strcmp(argv
[i
], "clear") == 0) {
155 puts("Testing glClear.");
156 test_clear
= GL_TRUE
;
160 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
162 piglit_require_extension("GL_EXT_framebuffer_object");
163 piglit_require_extension("GL_ARB_draw_buffers");
164 piglit_require_extension("GL_EXT_draw_buffers2");
165 piglit_require_extension("GL_ARB_texture_non_power_of_two");
167 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB
, &num
);
169 piglit_report_result(PIGLIT_SKIP
);