2 * Copyright © 2018 Collabora Ltd
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 * Erik Faye-Lund <erik.faye-lund@collabora.com>
28 #include "piglit-util-gl.h"
30 PIGLIT_GL_TEST_CONFIG_BEGIN
32 config
.supports_gl_compat_version
= 10;
34 /* Drivers that do not support GL_ARB_texture_non_power_of_two require
35 * window dimensions that are powers of two for this test.
37 config
.window_width
= next_power_of_two(config
.window_width
);
38 config
.window_height
= next_power_of_two(config
.window_height
);
40 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
41 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
43 PIGLIT_GL_TEST_CONFIG_END
45 static enum piglit_result
46 test_formats(const char *name
, const GLenum formats
[2],
47 const float expect
[2][4], const GLenum factors
[2])
49 GLboolean pass
= GL_TRUE
;
51 GLenum draw_bufs
[] = { GL_COLOR_ATTACHMENT0
, GL_COLOR_ATTACHMENT1
};
55 glGenFramebuffersEXT(1, &fb
);
56 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT
, fb
);
57 glViewport(0, 0, piglit_width
, piglit_height
);
59 glGenTextures(2, tex
);
60 for (i
= 0; i
< 2; ++i
) {
61 glBindTexture(GL_TEXTURE_2D
, tex
[i
]);
62 glTexImage2D(GL_TEXTURE_2D
, 0, formats
[i
],
63 piglit_width
, piglit_height
, 0,
64 GL_RGBA
, GL_FLOAT
, NULL
);
66 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
,
67 GL_COLOR_ATTACHMENT0_EXT
+ i
,
72 if (!piglit_check_gl_error(GL_NO_ERROR
))
73 piglit_report_result(PIGLIT_FAIL
);
75 status
= glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT
);
76 if (status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
77 printf(" - fbo incomplete (status = %s)\n",
78 piglit_get_gl_enum_name(status
));
82 printf("Testing %s\n", name
);
84 /* Tets 1 and 2 use glBlendFunc(GL_DST_ALPHA, ...) so make sure alpha
85 * is initialized to the expected value.
87 for (i
= 0; i
< 2; i
++) {
88 glDrawBuffers(1, &draw_bufs
[i
]);
89 glClearColor(0.0, 0.0, 0.0, expect
[i
][3]);
90 glClear(GL_COLOR_BUFFER_BIT
);
93 glDrawBuffers(2, draw_bufs
);
96 glBlendFunc(factors
[0], factors
[1]);
97 glBlendColor(1.0, 0.5, 0.25, 0.125);
98 glColor4f(1.0, 1.0, 1.0, 1.0);
100 piglit_draw_rect(-1.0, -1.0, 2.0, 2.0);
102 glReadBuffer(GL_COLOR_ATTACHMENT0
);
103 if (!piglit_probe_pixel_rgba(piglit_width
/ 2, piglit_height
/ 2,
105 printf(" when testing GL_COLOR_ATTACHMENT0.\n");
109 glReadBuffer(GL_COLOR_ATTACHMENT1
);
110 if (!piglit_probe_pixel_rgba(piglit_width
/ 2, piglit_height
/ 2,
112 printf(" when testing GL_COLOR_ATTACHMENT1.\n");
116 glDeleteTextures(2, tex
);
117 glDeleteFramebuffersEXT(1, &fb
);
119 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
122 enum piglit_result
piglit_display(void)
125 enum piglit_result result
, end_result
= PIGLIT_PASS
;
126 bool all_skip
= true;
128 static const struct {
136 { GL_DST_ALPHA
, GL_ZERO
}, {
137 { 0.5, 0.5, 0.5, 0.5 },
138 { 1.0, 1.0, 1.0, 1.0 }
142 { "alpha swizzle, variant 1",
143 { GL_RGBA
, GL_ALPHA
},
144 { GL_DST_ALPHA
, GL_ZERO
}, {
145 { 0.5, 0.5, 0.5, 0.5 },
146 { 0.0, 0.0, 0.0, 0.0 }
150 { "alpha swizzle, variant 2",
151 { GL_RGBA
, GL_ALPHA
},
152 { GL_CONSTANT_COLOR
, GL_ZERO
}, {
153 { 1.0, 0.5, 0.25, 0.125 },
154 { 0.0, 0.0, 0.0, 0.125 }
158 { "alpha swizzle, variant 3",
159 { GL_ALPHA
, GL_RGBA
},
160 { GL_CONSTANT_COLOR
, GL_ZERO
}, {
161 { 0.0, 0.0, 0.0, 0.125 },
162 { 1.0, 0.5, 0.25, 0.125 }
167 for (i
= 0; i
< ARRAY_SIZE(cases
); ++i
) {
168 result
= test_formats(cases
[i
].name
, cases
[i
].formats
,
169 cases
[i
].expect
, cases
[i
].factors
);
171 if (result
!= PIGLIT_SKIP
)
174 if (result
== PIGLIT_FAIL
)
183 void piglit_init(int argc
, char **argv
)
185 piglit_require_extension("GL_EXT_framebuffer_object");
186 piglit_require_draw_buffers(2);
188 glDisable(GL_DITHER
);