2 * Copyright © 2010 Intel Corporation
3 * Copyright © 2012 Marek Olšák <maraeo@gmail.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * Marek Olšák <maraeo@gmail.com>
29 #include "piglit-util-gl.h"
30 #include "fbo-formats.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config
.supports_gl_compat_version
= 10;
36 config
.window_width
= 512;
37 config
.window_height
= 32;
38 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
39 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
41 PIGLIT_GL_TEST_CONFIG_END
44 * Draw a quad with colormask
46 static void colormask(const float *rect
, unsigned mask
)
48 glColorMask(!!(mask
& 1), !!(mask
& 2), !!(mask
& 4), !!(mask
& 8));
49 piglit_draw_rect(rect
[0], rect
[1], rect
[2], rect
[3]);
50 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
);
53 static enum piglit_result
test_format(const struct format_desc
*format
)
55 GLboolean pass
= GL_TRUE
;
60 float defaults
[] = {-1, -1, -1, -1};
61 const char *name
= get_format_name(format
->internalformat
);
63 if (format
->base_internal_format
== GL_DEPTH_COMPONENT
||
64 format
->base_internal_format
== GL_DEPTH_STENCIL
||
65 format
->base_internal_format
== GL_STENCIL_INDEX
)
68 glGenFramebuffersEXT(1, &fb
);
69 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, fb
);
70 glViewport(0, 0, piglit_width
, piglit_height
);
72 glGenTextures(1, &tex
);
73 glBindTexture(GL_TEXTURE_2D
, tex
);
74 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
75 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
76 glTexImage2D(GL_TEXTURE_2D
, 0, format
->internalformat
,
77 piglit_width
, piglit_height
, 0,
78 GL_RGBA
, GL_FLOAT
, NULL
);
80 glGetTexLevelParameteriv(GL_TEXTURE_2D
, 0,
81 GL_TEXTURE_LUMINANCE_SIZE
, &l
);
82 glGetTexLevelParameteriv(GL_TEXTURE_2D
, 0,
83 GL_TEXTURE_ALPHA_SIZE
, &a
);
84 glGetTexLevelParameteriv(GL_TEXTURE_2D
, 0,
85 GL_TEXTURE_INTENSITY_SIZE
, &i
);
86 glGetTexLevelParameteriv(GL_TEXTURE_2D
, 0,
87 GL_TEXTURE_RED_SIZE
, &r
);
88 glGetTexLevelParameteriv(GL_TEXTURE_2D
, 0,
89 GL_TEXTURE_GREEN_SIZE
, &g
);
90 glGetTexLevelParameteriv(GL_TEXTURE_2D
, 0,
91 GL_TEXTURE_BLUE_SIZE
, &b
);
93 /* Set up expected defaults.
94 * We're using glReadPixels from the texture.
97 /* GL_INTENSITY texture: result = (I,0,0,1) */
99 defaults
[2] = defaults
[1] = 0;
101 /* GL_LUMINANCE texture: result = (L,0,0,A) */
102 defaults
[2] = defaults
[1] = 0;
122 /* Clamp the bits for the framebuffer, except we aren't checking
123 * the actual framebuffer bits.
139 piglit_set_tolerance_for_bits(i
, i
, i
, i
);
141 piglit_set_tolerance_for_bits(l
, l
, l
, a
);
143 piglit_set_tolerance_for_bits(r
, g
, b
, a
);
146 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
,
147 GL_COLOR_ATTACHMENT0_EXT
,
151 if (!piglit_check_gl_error(GL_NO_ERROR
))
152 piglit_report_result(PIGLIT_FAIL
);
154 status
= glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT
);
155 printf("Testing %s", name
);
156 if (status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
157 printf(" - fbo incomplete (status = %s)\n",
158 piglit_get_gl_enum_name(status
));
159 piglit_report_subtest_result(PIGLIT_SKIP
,
160 "%s (fbo incomplete)",
166 glClearColor(0.0, 0.0, 0.0, 0.0);
167 glClear(GL_COLOR_BUFFER_BIT
);
169 for (mask
= 0; mask
<= 15; mask
++) {
171 rect
[0] = -1 + (mask
/ 8.0);
176 colormask(rect
, mask
);
179 for (mask
= 0; mask
<= 15; mask
++) {
180 float color
[4], out
[4];
182 for (k
= 0; k
< 4; k
++) {
183 if (defaults
[k
] >= 0)
184 color
[k
] = defaults
[k
];
186 color
[k
] = (mask
& (1 << k
)) ? 1 : 0;
189 if (!piglit_probe_pixel_rgba_silent(piglit_width
* mask
/ 16, 0,
191 printf("glColorMask(%i, %i, %i, %i)\n",
192 !!(mask
& 1), !!(mask
& 2),
193 !!(mask
& 4), !!(mask
& 8));
194 printf(" Expected: %f %f %f %f\n",
195 color
[0], color
[1], color
[2], color
[3]);
196 printf(" Observed: %f %f %f %f\n",
197 out
[0], out
[1], out
[2], out
[3]);
203 * Display the texture.
205 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, piglit_winsys_fbo
);
206 glViewport(0, 0, piglit_width
, piglit_height
);
208 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_COMBINE
);
209 glTexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_RGB
, GL_REPLACE
);
210 glTexEnvi(GL_TEXTURE_ENV
, GL_COMBINE_ALPHA
, GL_REPLACE
);
212 glColor4f(1, 1, 1, 1);
213 glEnable(GL_TEXTURE_2D
);
214 glBindTexture(GL_TEXTURE_2D
, tex
);
215 piglit_draw_rect_tex(-1, -1, 2, 2,
218 glDisable(GL_TEXTURE_2D
);
219 glDeleteTextures(1, &tex
);
220 glBindFramebufferEXT(GL_FRAMEBUFFER
, piglit_winsys_fbo
);
221 glDeleteFramebuffersEXT(1, &fb
);
223 piglit_present_results();
225 piglit_report_subtest_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
,
228 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
231 enum piglit_result
piglit_display(void)
233 return fbo_formats_display(test_format
);
236 void piglit_init(int argc
, char **argv
)
238 fbo_formats_init(argc
, argv
, GL_TRUE
);