2 * Copyright (c) 2013 VMware, Inc.
4 * Permission is hereby, 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
25 * Test glGenerateMipmaps with a texture array.
26 * In particular, test with texture compression to expose a Mesa bug.
27 * See https://bugs.freedesktop.org/show_bug.cgi?id=66850
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config
.supports_gl_compat_version
= 10;
38 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
39 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
40 PIGLIT_GL_TEST_CONFIG_END
47 #define BPP 4 /* GL_RGBA/ubyte */
51 run_test(GLenum internalFormat
)
53 unsigned char *buf
, *buf2
;
58 buf
= malloc(WIDTH
* HEIGHT
* DEPTH
* BPP
);
59 buf2
= malloc(WIDTH
* HEIGHT
* DEPTH
* BPP
);
61 /* Create 2D array texture */
62 memset(buf
, 255, WIDTH
* HEIGHT
* DEPTH
* BPP
); /* white */
63 glGenTextures(1, &tex
);
64 glBindTexture(GL_TEXTURE_2D_ARRAY
, tex
);
65 glTexImage3D(GL_TEXTURE_2D_ARRAY
, 0,
67 WIDTH
, HEIGHT
, DEPTH
, 0,
68 GL_RGBA
, GL_UNSIGNED_BYTE
,
71 glGenerateMipmap(GL_TEXTURE_2D_ARRAY
);
73 /* now read back texture images and test */
74 for (level
= 0; (WIDTH
>> level
) > 0; level
++) {
75 int x
, y
, z
, level_size
, row_len
;
77 memset(buf2
, 0, WIDTH
* HEIGHT
* DEPTH
* BPP
);
79 glGetTexImage(GL_TEXTURE_2D_ARRAY
, level
,
80 GL_RGBA
, GL_UNSIGNED_BYTE
, buf2
);
82 /* test center texel */
83 x
= (WIDTH
>> level
) / 2;
84 y
= (HEIGHT
>> level
) / 2;
86 level_size
= (WIDTH
>> level
) * (HEIGHT
>> level
) * BPP
;
87 row_len
= (WIDTH
>> level
) * BPP
;
89 for (z
= 0; z
< DEPTH
; z
++) {
90 int pos
= z
* level_size
+ y
* row_len
+ x
* BPP
;
92 if (buf2
[pos
+ 0] != 255 ||
93 buf2
[pos
+ 1] != 255 ||
94 buf2
[pos
+ 2] != 255 ||
95 buf2
[pos
+ 3] != 255) {
96 printf("Probe at level %d, x %d, y %d, z %d = "
98 " expected (255,255,255,255)\n",
104 printf("Internal tex format %s\n",
105 piglit_get_gl_enum_name(internalFormat
));
124 pass
= run_test(GL_RGBA
) && pass
;
125 if (piglit_is_extension_supported("GL_ARB_texture_compression")) {
126 pass
= run_test(GL_COMPRESSED_RGBA
) && pass
;
127 pass
= run_test(GL_COMPRESSED_RGB
) && pass
;
130 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
135 piglit_init(int argc
, char **argv
)
137 piglit_require_extension("GL_EXT_texture_array");