1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
/*
* Copyright © 2011 Intel Corporation
* Copyright (c) 2010 VMware, Inc.
* Copyright (c) 2011 Dave Airlie
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* on the rights to use, copy, modify, merge, publish, distribute, sub
* license, and/or sell copies of the Software, and to permit persons to whom
* the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* @file fbo-blending.c
*
* From the GL_EXT_texture_integer spec:
*
* "Per-fragment operations that require floating-point color
* components, including multisample alpha operations, alpha test,
* blending, and dithering, have no effect when the corresponding
* colors are written to an integer color buffer."
*
* This test covers alpha test, blending, and dithering. All formats
* tested due to failures in i965 differing based on render target
* format.
*/
#include "piglit-util.h"
PIGLIT_GL_TEST_MAIN(
100 /*window_width*/,
100 /*window_height*/,
GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE)
static GLuint tex;
static int color_loc;
/* Numbers chosen to always avoid clamping -- we should test that in
* some other test.
*/
static const uint32_t color[4] = {
0x5,
0x4,
0x3,
0x2,
};
struct format_info {
const char *name;
GLenum internal_format, base_format;
int size;
bool sign;
};
/* Only test 32-bit formats - since you won't see precision problems on lower sizes */
static const struct format_info formats[] = {
{ "GL_RGBA8I", GL_RGBA8I, GL_RGBA_INTEGER, 8, true },
{ "GL_RGBA8UI", GL_RGBA8UI , GL_RGBA_INTEGER, 8, false },
{ "GL_RGBA16I", GL_RGBA16I, GL_RGBA_INTEGER, 16, true },
{ "GL_RGBA16UI", GL_RGBA16UI, GL_RGBA_INTEGER, 16, false },
{ "GL_RGBA32I", GL_RGBA32I, GL_RGBA_INTEGER, 32, true },
{ "GL_RGBA32UI", GL_RGBA32UI, GL_RGBA_INTEGER, 32, false },
{ "GL_RGBA8I (bgra)", GL_RGBA8I, GL_BGRA_INTEGER, 8, true },
{ "GL_RGBA8UI (bgra)", GL_RGBA8UI , GL_BGRA_INTEGER, 8, false },
{ "GL_RGBA16I (bgra)", GL_RGBA16I, GL_BGRA_INTEGER, 16, true },
{ "GL_RGBA16UI (bgra)", GL_RGBA16UI, GL_BGRA_INTEGER, 16, false },
{ "GL_RGBA32I (bgra)", GL_RGBA32I, GL_BGRA_INTEGER, 32, true },
{ "GL_RGBA32UI (bgra)", GL_RGBA32UI, GL_BGRA_INTEGER, 32, false },
{ "GL_RGB8I", GL_RGB8I, GL_RGB_INTEGER, 8, true },
{ "GL_RGB8UI", GL_RGB8UI , GL_RGB_INTEGER, 8, false },
{ "GL_RGB16I", GL_RGB16I, GL_RGB_INTEGER, 16, true },
{ "GL_RGB16UI", GL_RGB16UI, GL_RGB_INTEGER, 16, false },
{ "GL_RGB32I", GL_RGB32I, GL_RGB_INTEGER, 32, true },
{ "GL_RGB32UI", GL_RGB32UI, GL_RGB_INTEGER, 32, false },
{ "GL_ALPHA8I_EXT", GL_ALPHA8I_EXT, GL_ALPHA_INTEGER_EXT, 8, true },
{ "GL_ALPHA8UI_EXT", GL_ALPHA8UI_EXT , GL_ALPHA_INTEGER_EXT, 8, false },
{ "GL_ALPHA16I_EXT", GL_ALPHA16I_EXT, GL_ALPHA_INTEGER_EXT, 16, true },
{ "GL_ALPHA16UI_EXT", GL_ALPHA16UI_EXT, GL_ALPHA_INTEGER_EXT, 16, false },
{ "GL_ALPHA32I_EXT", GL_ALPHA32I_EXT, GL_ALPHA_INTEGER_EXT, 32, true },
{ "GL_ALPHA32UI_EXT", GL_ALPHA32UI_EXT, GL_ALPHA_INTEGER_EXT, 32, false },
{ "GL_LUMINANCE8I_EXT", GL_LUMINANCE8I_EXT, GL_LUMINANCE_INTEGER_EXT, 8, true },
{ "GL_LUMINANCE8UI_EXT", GL_LUMINANCE8UI_EXT , GL_LUMINANCE_INTEGER_EXT, 8, false },
{ "GL_LUMINANCE16I_EXT", GL_LUMINANCE16I_EXT, GL_LUMINANCE_INTEGER_EXT, 16, true },
{ "GL_LUMINANCE16UI_EXT", GL_LUMINANCE16UI_EXT, GL_LUMINANCE_INTEGER_EXT, 16, false },
{ "GL_LUMINANCE32I_EXT", GL_LUMINANCE32I_EXT, GL_LUMINANCE_INTEGER_EXT, 32, true },
{ "GL_LUMINANCE32UI_EXT", GL_LUMINANCE32UI_EXT, GL_LUMINANCE_INTEGER_EXT, 32, false },
{ "GL_LUMINANCE_ALPHA8I_EXT", GL_LUMINANCE_ALPHA8I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, 8, true },
{ "GL_LUMINANCE_ALPHA8UI_EXT", GL_LUMINANCE_ALPHA8UI_EXT , GL_LUMINANCE_ALPHA_INTEGER_EXT, 8, false },
{ "GL_LUMINANCE_ALPHA16I_EXT", GL_LUMINANCE_ALPHA16I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, 16, true },
{ "GL_LUMINANCE_ALPHA16UI_EXT", GL_LUMINANCE_ALPHA16UI_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, 16, false },
{ "GL_LUMINANCE_ALPHA32I_EXT", GL_LUMINANCE_ALPHA32I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, 32, true },
{ "GL_LUMINANCE_ALPHA32UI_EXT", GL_LUMINANCE_ALPHA32UI_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, 32, false },
{ "GL_INTENSITY8I_EXT", GL_INTENSITY8I_EXT, GL_RED_INTEGER_EXT, 8, true },
{ "GL_INTENSITY8UI_EXT", GL_INTENSITY8UI_EXT , GL_RED_INTEGER_EXT, 8, false },
{ "GL_INTENSITY16I_EXT", GL_INTENSITY16I_EXT, GL_RED_INTEGER_EXT, 16, true },
{ "GL_INTENSITY16UI_EXT", GL_INTENSITY16UI_EXT, GL_RED_INTEGER_EXT, 16, false },
{ "GL_INTENSITY32I_EXT", GL_INTENSITY32I_EXT, GL_RED_INTEGER_EXT, 32, true },
{ "GL_INTENSITY32UI_EXT", GL_INTENSITY32UI_EXT, GL_RED_INTEGER_EXT, 32, false },
};
static const struct format_info rg_formats[] = {
{ "GL_RG8I", GL_RG8I, GL_RG_INTEGER, 8, true },
{ "GL_RG8UI", GL_RG8UI , GL_RG_INTEGER, 8, false },
{ "GL_RG16I", GL_RG16I, GL_RG_INTEGER, 16, true },
{ "GL_RG16UI", GL_RG16UI, GL_RG_INTEGER, 16, false },
{ "GL_RG32I", GL_RG32I, GL_RG_INTEGER, 32, true },
{ "GL_RG32UI", GL_RG32UI, GL_RG_INTEGER, 32, false },
{ "GL_R8I", GL_R8I, GL_RED_INTEGER, 8, true },
{ "GL_R8UI", GL_R8UI , GL_RED_INTEGER, 8, false },
{ "GL_R16I", GL_R16I, GL_RED_INTEGER, 16, true },
{ "GL_R16UI", GL_R16UI, GL_RED_INTEGER, 16, false },
{ "GL_R32I", GL_R32I, GL_RED_INTEGER, 32, true },
{ "GL_R32UI", GL_R32UI, GL_RED_INTEGER, 32, false },
};
static const struct format_info rgb10_formats[] = {
{ "GL_RGB10_A2UI", GL_RGB10_A2UI, GL_RGBA_INTEGER, 10, false },
{ "GL_RGB10_A2UI (bgra)", GL_RGB10_A2UI, GL_BGRA_INTEGER, 10, false },
{ "GL_RGB10_A2UI (rev)", GL_RGB10_A2UI, GL_RGBA_INTEGER, 10, true },
{ "GL_RGB10_A2UI (rev bgra)", GL_RGB10_A2UI, GL_BGRA_INTEGER, 10, true },
};
static GLenum
get_datatype(const struct format_info *info)
{
switch (info->size) {
case 8:
return info->sign ? GL_BYTE : GL_UNSIGNED_BYTE;
case 16:
return info->sign ? GL_SHORT : GL_UNSIGNED_SHORT;
case 32:
return info->sign ? GL_INT : GL_UNSIGNED_INT;
case 10:
return GL_UNSIGNED_INT_2_10_10_10_REV;
default:
assert(0);
return 0;
}
}
static void
usage(void)
{
fprintf(stderr, "usage:\n");
fprintf(stderr,
"ext_texture_integer-fbo-blending "
"[GL_ARB_texture_rg | GL_ARB_texture_rgb10_a2ui]\n");
exit(1);
}
static enum piglit_result
test_format(const struct format_info *info)
{
const GLenum type = get_datatype(info);
GLenum status;
uint32_t expected_color[4];
printf("%s:\n", info->name);
/* Create texture */
glTexImage2D(GL_TEXTURE_2D, 0, info->internal_format, 1, 1, 0,
info->base_format, type, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D, tex, 0);
status = glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
printf(" framebuffer incomplete.\n");
return PIGLIT_SKIP;
}
piglit_draw_rect(-1, -1, 2, 2);
memcpy(expected_color, color, sizeof(color));
switch (info->base_format) {
case GL_RGBA_INTEGER:
case GL_BGRA_INTEGER:
break;
case GL_RGB_INTEGER:
expected_color[3] = 1;
break;
case GL_LUMINANCE_INTEGER_EXT:
expected_color[1] = expected_color[0];
expected_color[2] = expected_color[0];
expected_color[3] = 1;
break;
case GL_LUMINANCE_ALPHA_INTEGER_EXT:
expected_color[1] = expected_color[0];
expected_color[2] = expected_color[0];
break;
case GL_RED_INTEGER:
if (strstr(info->name, "INTENSITY")) {
expected_color[1] = expected_color[0];
expected_color[2] = expected_color[0];
expected_color[3] = expected_color[0];
} else {
expected_color[1] = 0;
expected_color[2] = 0;
expected_color[3] = 1;
}
break;
case GL_RG_INTEGER:
expected_color[2] = 0;
expected_color[3] = 1;
break;
case GL_ALPHA_INTEGER_EXT:
expected_color[0] = 0;
expected_color[1] = 0;
expected_color[2] = 0;
break;
default:
abort();
}
if (piglit_probe_rect_rgba_uint(0, 0, 1, 1, expected_color))
return PIGLIT_PASS;
else {
printf(" Input color: %d %d %d %d\n",
color[0], color[1], color[2], color[3]);
return PIGLIT_FAIL;
}
}
enum piglit_result
piglit_display(void)
{
/* unreached */
return PIGLIT_FAIL;
}
void
piglit_init(int argc, char **argv)
{
GLuint fbo;
static const char *vs_source =
"#version 130\n"
"void main()\n"
"{\n"
" gl_Position = gl_Vertex;\n"
"}\n";
static const char *fs_source =
"#version 130\n"
"uniform uvec4 color;\n"
"out uvec4 result;\n"
"void main()\n"
"{\n"
" result = color;\n"
"}\n";
GLuint fs, vs, prog;
int f, i;
enum piglit_result result = PIGLIT_SKIP;
const struct format_info *test_formats = formats;
int num_test_formats = ARRAY_SIZE(formats);
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "GL_ARB_texture_rg") == 0) {
piglit_require_extension(argv[i]);
test_formats = rg_formats;
num_test_formats = ARRAY_SIZE(rg_formats);
} else if (strcmp(argv[i], "GL_ARB_texture_rgb10_a2ui") == 0) {
piglit_require_extension(argv[i]);
test_formats = rgb10_formats;
num_test_formats = ARRAY_SIZE(rgb10_formats);
} else {
usage();
exit(1);
}
}
piglit_require_extension("GL_EXT_texture_integer");
piglit_require_GLSL_version(130);
fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
prog = piglit_link_simple_program(vs, fs);
if (!prog || !fs || !vs)
piglit_report_result(PIGLIT_FAIL);
glUseProgram(prog);
color_loc = glGetUniformLocation(prog, "color");
glUniform4uiv(color_loc, 1, color);
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
/* Turn on all the knobs (except multisample alpha, which
* we'll leave to an EXT_framebuffer_multisample test) that
* are supposed to be ignored.
*/
glEnable(GL_BLEND);
glBlendFunc(GL_ZERO, GL_ZERO);
glEnable(GL_DITHER);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_NEVER, 1);
for (f = 0; f < num_test_formats; f++)
piglit_merge_result(&result, test_format(&test_formats[f]));
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDeleteFramebuffers(1, &fbo);
piglit_report_result(result);
}
|