ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ext_texture_array / gen-mipmap.c
blob6d01ab9ca9775d024f6a938bb8e88a6f1c5124c9
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
24 /**
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
29 * Brian Paul
30 * 24 July 2013
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
43 /* texture size */
44 #define WIDTH 128
45 #define HEIGHT 64
46 #define DEPTH 3
47 #define BPP 4 /* GL_RGBA/ubyte */
50 static bool
51 run_test(GLenum internalFormat)
53 unsigned char *buf, *buf2;
54 int level;
55 GLuint tex;
56 bool pass = true;
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,
66 internalFormat,
67 WIDTH, HEIGHT, DEPTH, 0,
68 GL_RGBA, GL_UNSIGNED_BYTE,
69 buf);
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 = "
97 " (%u, %u, %u, %u),"
98 " expected (255,255,255,255)\n",
99 level, x, y, z,
100 buf2[pos + 0],
101 buf2[pos + 1],
102 buf2[pos + 2],
103 buf2[pos + 3]);
104 printf("Internal tex format %s\n",
105 piglit_get_gl_enum_name(internalFormat));
106 pass = false;
107 break;
112 free(buf);
113 free(buf2);
115 return pass;
119 enum piglit_result
120 piglit_display(void)
122 bool pass = true;
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;
134 void
135 piglit_init(int argc, char **argv)
137 piglit_require_extension("GL_EXT_texture_array");