ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_direct_state_access / compressedtextureimage.c
blob7b93fda8fb78ccad29a27d2162f2d0dd49a845d0
1 /*
2 * Copyright © 2011 Intel Corporation
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
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 /** @file compressedtextureimage.c
26 * Tests that fetching and uploading compressed texture data works
27 * correctly.
29 * The other compressed texture tests are about decoding of data that
30 * was uploaded from uncompressed, while this tries a round-trip after
31 * the initial upload, testing glGetCompressedTexImage() and
32 * glCompressedTexImage2D().
34 * Adapted for testing glGetCompressedTextureImage in ARB_direct_state_access
35 * by Laura Ekstrand <laura@jlekstrand.net>, November 2014.
38 #include "piglit-util-gl.h"
40 #define SIZE 128
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config.supports_gl_compat_version = 10;
46 config.window_width = (SIZE*2)+60;
47 config.window_height = SIZE+20;
48 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
49 config.khr_no_error_support = PIGLIT_NO_ERRORS;
51 PIGLIT_GL_TEST_CONFIG_END
53 struct format {
54 GLenum token;
55 const char **extension;
58 static struct format *format;
60 const char *FXT1[] = {
61 "GL_3DFX_texture_compression_FXT1",
62 NULL
65 const char *S3TC[] = {
66 "GL_EXT_texture_compression_s3tc",
67 NULL
70 const char *S3TC_srgb[] = {
71 "GL_EXT_texture_compression_s3tc",
72 "GL_EXT_texture_sRGB",
73 NULL
76 const char *RGTC[] = {
77 "GL_ARB_texture_compression_rgtc",
78 NULL
81 const char *RGTC_signed[] = {
82 "GL_ARB_texture_compression_rgtc",
83 "GL_EXT_texture_snorm",
84 NULL
87 const char *BPTC[] = {
88 "GL_ARB_texture_compression_bptc",
89 NULL
92 static struct format formats[] = {
93 { GL_COMPRESSED_RGB_FXT1_3DFX, FXT1 },
94 { GL_COMPRESSED_RGBA_FXT1_3DFX, FXT1 },
96 { GL_COMPRESSED_RGB_S3TC_DXT1_EXT, S3TC },
97 { GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, S3TC },
98 { GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, S3TC },
99 { GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, S3TC },
101 { GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, S3TC_srgb },
102 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, S3TC_srgb },
103 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, S3TC_srgb },
104 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, S3TC_srgb },
106 { GL_COMPRESSED_RGBA_BPTC_UNORM, BPTC },
107 { GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, BPTC },
108 { GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, BPTC },
109 { GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, BPTC },
111 { GL_COMPRESSED_RED_RGTC1_EXT, RGTC },
112 { GL_COMPRESSED_SIGNED_RED_RGTC1_EXT, RGTC_signed },
113 { GL_COMPRESSED_RED_GREEN_RGTC2_EXT, RGTC },
114 { GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, RGTC_signed },
117 static void
118 display_mipmaps(int x, int y)
120 int i;
122 glEnable(GL_TEXTURE_2D);
124 /* Disply all the mipmap levels */
125 for (i = SIZE; i > 0; i /= 2) {
126 piglit_draw_rect_tex(x, y, i, i,
127 0, 0, 1, 1);
129 x += i + 5;
133 static bool
134 check_resulting_mipmaps(int x, int y)
136 bool pass = true;
137 int size;
138 float red[4] = {1.0, 0.0, 0.0, 1.0};
139 float green[4] = {0.0, 1.0, 0.0, 1.0};
140 float blue[4] = {0.0, 0.0, 1.0, 1.0};
141 float white[4] = {1.0, 1.0, 1.0, 1.0};
143 /* for r, rg textures, overwrite what the expected colors are. */
144 if (format->token == GL_COMPRESSED_RED_RGTC1_EXT ||
145 format->token == GL_COMPRESSED_SIGNED_RED_RGTC1_EXT) {
146 green[1] = 0;
147 blue[2] = 0;
148 white[1] = 0;
149 white[2] = 0;
151 if (format->token == GL_COMPRESSED_RED_GREEN_RGTC2_EXT ||
152 format->token == GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT) {
153 blue[2] = 0;
154 white[2] = 0;
157 for (size = SIZE; size > 0; size /= 2) {
158 if (size == 4)
159 pass = pass && piglit_probe_pixel_rgb(x + 2, y + 2,
160 red);
161 else if (size == 2)
162 pass = pass && piglit_probe_pixel_rgb(x + 1, y + 1,
163 green);
164 else if (size == 1)
165 pass = pass && piglit_probe_pixel_rgb(x, y,
166 blue);
167 else {
168 pass = pass && piglit_probe_pixel_rgb(x + size / 4,
169 y + size / 4,
170 red);
171 pass = pass && piglit_probe_pixel_rgb(x + size * 3 / 4,
172 y + size / 4,
173 green);
174 pass = pass && piglit_probe_pixel_rgb(x + size / 4,
175 y + size * 3 / 4,
176 blue);
177 pass = pass && piglit_probe_pixel_rgb(x + size * 3 / 4,
178 y + size * 3 / 4,
179 white);
181 x += size + 5;
184 return pass;
187 enum piglit_result
188 piglit_display(void)
190 GLuint tex, tex_src;
191 bool pass;
192 int level;
193 unsigned bw, bh, bs;
195 piglit_get_compressed_block_size(format->token, &bw, &bh, &bs);
196 glClearColor(0.5, 0.5, 0.5, 0.5);
197 glClear(GL_COLOR_BUFFER_BIT);
199 tex_src = piglit_rgbw_texture(format->token, SIZE, SIZE,
200 true, false,
201 GL_UNSIGNED_NORMALIZED);
202 glCreateTextures(GL_TEXTURE_2D, 1, &tex);
204 for (level = 0; (SIZE >> level) > 0; level++) {
205 int w, h;
206 int expected_size, size;
207 void *compressed;
209 w = SIZE >> level;
210 h = SIZE >> level;
211 expected_size = piglit_compressed_image_size(format->token, w, h);
213 glBindTexture(GL_TEXTURE_2D, tex_src);
214 glGetTexLevelParameteriv(GL_TEXTURE_2D, level,
215 GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
216 &size);
218 if (size != expected_size) {
219 fprintf(stderr, "Format %s level %d (%dx%d) size %d "
220 "doesn't match expected size %d\n",
221 piglit_get_gl_enum_name(format->token),
222 level, w, h, size, expected_size);
223 piglit_report_result(PIGLIT_FAIL);
226 compressed = malloc(size);
228 glGetCompressedTextureImage(tex_src, level, size, compressed);
230 glBindTexture(GL_TEXTURE_2D, tex);
231 glCompressedTexImage2D(GL_TEXTURE_2D, level, format->token,
232 w, h, 0, size, compressed);
233 if (!piglit_check_gl_error(GL_NO_ERROR))
234 piglit_report_result(PIGLIT_FAIL);
236 free(compressed);
239 glDeleteTextures(1, &tex_src);
240 glBindTextureUnit(tex, 0);
242 display_mipmaps(10, 10);
243 pass = check_resulting_mipmaps(10, 10);
245 piglit_present_results();
247 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
250 static void
251 usage(int argc, char **argv)
253 int i;
255 fprintf(stderr, "Usage: %s <format>\n", argv[0]);
256 fprintf(stderr, "format is one of:\n");
257 for (i = 0; i < ARRAY_SIZE(formats); i++) {
258 fprintf(stderr, " %s\n",
259 piglit_get_gl_enum_name(formats[i].token));
261 exit(1);
264 void
265 piglit_init(int argc, char **argv)
267 int i;
268 piglit_require_extension("GL_ARB_direct_state_access");
270 piglit_ortho_projection(piglit_width, piglit_height, false);
272 if (argc != 2)
273 usage(argc, argv);
275 format = NULL;
277 const GLenum arg = piglit_get_gl_enum_from_name(argv[1]);
278 for (i = 0; i < ARRAY_SIZE(formats); i++) {
279 if (formats[i].token == arg) {
280 format = &formats[i];
281 break;
285 if (!format)
286 usage(argc, argv);
288 for (i = 0; format->extension[i]; i++)
289 piglit_require_extension(format->extension[i]);