arb_copy_image: test copying of different mipmap levels of a texture
[piglit.git] / tests / fbo / fbo-formats.h
blob2bb971e510645cb3725fbee98225c2801503db94
1 /*
2 * Copyright © 2009-2010 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.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
29 struct format_desc {
30 GLenum internalformat;
32 /**
33 * Base internal format corresponding to internalformat. See
34 * for example the GL 3.0 spec, tables 3.16 through 3.19.
36 * Base internal format is always one of the following:
37 * GL_ALPHA, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL,
38 * GL_INTENSITY, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RED,
39 * GL_RG, GL_RGB, GL_RGBA.
41 GLenum base_internal_format;
43 /* For color formats, the number of bits in the smallest channel for
44 * the sized formats and 0 for unsized and compressed formats.
46 * For sized depth/stencil formats, the number of bits in the depth
47 * component (i.e., 0 for stencil-only formats).
49 unsigned min_bits;
52 static const struct format_desc core[] = {
53 { 3, GL_RGB, 0 },
54 { 4, GL_RGBA, 0 },
55 { GL_RGB, GL_RGB, 0 },
56 { GL_RGBA, GL_RGBA, 0 },
57 { GL_ALPHA, GL_ALPHA, 0 },
58 { GL_LUMINANCE, GL_LUMINANCE, 0 },
59 { GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, 0 },
60 { GL_INTENSITY, GL_INTENSITY, 0 },
62 { GL_ALPHA4, GL_ALPHA, 4 },
63 { GL_ALPHA8, GL_ALPHA, 8 },
64 { GL_ALPHA12, GL_ALPHA, 12 },
65 { GL_ALPHA16, GL_ALPHA, 16 },
67 { GL_LUMINANCE4, GL_LUMINANCE, 4 },
68 { GL_LUMINANCE8, GL_LUMINANCE, 8 },
69 { GL_LUMINANCE12, GL_LUMINANCE, 12 },
70 { GL_LUMINANCE16, GL_LUMINANCE, 16 },
72 { GL_LUMINANCE4_ALPHA4, GL_LUMINANCE_ALPHA, 4 },
73 { GL_LUMINANCE8_ALPHA8, GL_LUMINANCE_ALPHA, 8 },
74 { GL_LUMINANCE12_ALPHA12, GL_LUMINANCE_ALPHA, 12 },
75 { GL_LUMINANCE16_ALPHA16, GL_LUMINANCE_ALPHA, 16 },
77 { GL_INTENSITY4, GL_INTENSITY, 4 },
78 { GL_INTENSITY8, GL_INTENSITY, 8 },
79 { GL_INTENSITY12, GL_INTENSITY, 12 },
80 { GL_INTENSITY16, GL_INTENSITY, 16 },
82 { GL_R3_G3_B2, GL_RGB, 2 },
83 { GL_RGB4, GL_RGB, 4 },
84 { GL_RGB5, GL_RGB, 5 },
85 { GL_RGB8, GL_RGB, 8 },
86 { GL_RGB10, GL_RGB, 10 },
87 { GL_RGB12, GL_RGB, 12 },
88 { GL_RGB16, GL_RGB, 16 },
90 { GL_RGBA2, GL_RGBA, 2 },
91 { GL_RGBA4, GL_RGBA, 4 },
92 { GL_RGB5_A1, GL_RGBA, 1 },
93 { GL_RGBA8, GL_RGBA, 8 },
94 { GL_RGB10_A2, GL_RGBA, 2 },
95 { GL_RGBA12, GL_RGBA, 12 },
96 { GL_RGBA16, GL_RGBA, 16 },
99 static const struct format_desc arb_depth_texture[] = {
100 { GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, 0 },
101 { GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, 16 },
102 { GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, 24 },
103 { GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, 32 },
106 static const struct format_desc ext_packed_depth_stencil[] = {
107 { GL_DEPTH_STENCIL_EXT, GL_DEPTH_STENCIL, 0 },
108 { GL_DEPTH24_STENCIL8_EXT, GL_DEPTH_STENCIL, 24 },
111 static const struct format_desc ext_texture_srgb[] = {
112 { GL_SRGB_EXT, GL_RGB, 0 },
113 { GL_SRGB8_EXT, GL_RGB, 8 },
114 { GL_SRGB_ALPHA_EXT, GL_RGBA, 0 },
115 { GL_SRGB8_ALPHA8_EXT, GL_RGBA, 8 },
116 { GL_SLUMINANCE_ALPHA_EXT, GL_LUMINANCE_ALPHA, 0 },
117 { GL_SLUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 8 },
118 { GL_SLUMINANCE_EXT, GL_LUMINANCE, 0 },
119 { GL_SLUMINANCE8_EXT, GL_LUMINANCE, 8 },
122 static const struct format_desc ext_texture_srgb_compressed[] = {
123 { GL_COMPRESSED_SRGB_EXT, GL_RGB, 0 },
124 { GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, GL_RGB, 0 },
125 { GL_COMPRESSED_SRGB_ALPHA_EXT, GL_RGBA, 0 },
126 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_RGBA, 0 },
127 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_RGBA, 0 },
128 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_RGBA, 0 },
129 { GL_COMPRESSED_SLUMINANCE_ALPHA_EXT, GL_LUMINANCE_ALPHA, 0 },
130 { GL_COMPRESSED_SLUMINANCE_EXT, GL_LUMINANCE, 0 },
133 static const struct format_desc ext_texture_compression[] = {
134 { GL_COMPRESSED_ALPHA, GL_ALPHA, 0 },
135 { GL_COMPRESSED_LUMINANCE, GL_LUMINANCE, 0 },
136 { GL_COMPRESSED_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, 0 },
137 { GL_COMPRESSED_INTENSITY, GL_INTENSITY, 0 },
138 { GL_COMPRESSED_RGB, GL_RGB, 0 },
139 { GL_COMPRESSED_RGBA, GL_RGBA, 0 },
142 static const struct format_desc tdfx_texture_compression_fxt1[] = {
143 { GL_COMPRESSED_RGB_FXT1_3DFX, GL_RGB, 0 },
144 { GL_COMPRESSED_RGBA_FXT1_3DFX, GL_RGBA, 0 },
147 static const struct format_desc ext_texture_compression_s3tc[] = {
148 { GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_RGB, 0 },
149 { GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_RGBA, 0 },
150 { GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_RGBA, 0 },
151 { GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_RGBA, 0 },
154 static const struct format_desc ext_texture_integer[] = {
155 { GL_RGBA8UI_EXT, GL_RGBA, 8 },
156 { GL_RGBA16UI_EXT, GL_RGBA, 16 },
157 { GL_RGBA32UI_EXT, GL_RGBA, 32 },
158 { GL_RGBA8I_EXT, GL_RGBA, 8 },
159 { GL_RGBA16I_EXT, GL_RGBA, 16 },
160 { GL_RGBA32I_EXT, GL_RGBA, 32 },
161 { GL_RGB8UI_EXT, GL_RGB, 8 },
162 { GL_RGB16UI_EXT, GL_RGB, 16 },
163 { GL_RGB32UI_EXT, GL_RGB, 32 },
164 { GL_RGB8I_EXT, GL_RGB, 8 },
165 { GL_RGB16I_EXT, GL_RGB, 16 },
166 { GL_RGB32I_EXT, GL_RGB, 32 },
167 { GL_ALPHA8UI_EXT, GL_ALPHA, 8 },
168 { GL_ALPHA16UI_EXT, GL_ALPHA, 16 },
169 { GL_ALPHA32UI_EXT, GL_ALPHA, 32 },
170 { GL_ALPHA8I_EXT, GL_ALPHA, 8 },
171 { GL_ALPHA16I_EXT, GL_ALPHA, 16 },
172 { GL_ALPHA32I_EXT, GL_ALPHA, 32 },
173 { GL_INTENSITY8UI_EXT, GL_INTENSITY, 8 },
174 { GL_INTENSITY16UI_EXT, GL_INTENSITY, 16 },
175 { GL_INTENSITY32UI_EXT, GL_INTENSITY, 32 },
176 { GL_INTENSITY8I_EXT, GL_INTENSITY, 8 },
177 { GL_INTENSITY16I_EXT, GL_INTENSITY, 16 },
178 { GL_INTENSITY32I_EXT, GL_INTENSITY, 32 },
179 { GL_LUMINANCE8UI_EXT, GL_LUMINANCE, 8 },
180 { GL_LUMINANCE16UI_EXT, GL_LUMINANCE, 16 },
181 { GL_LUMINANCE32UI_EXT, GL_LUMINANCE, 32 },
182 { GL_LUMINANCE8I_EXT, GL_LUMINANCE, 8 },
183 { GL_LUMINANCE16I_EXT, GL_LUMINANCE, 16 },
184 { GL_LUMINANCE32I_EXT, GL_LUMINANCE, 32 },
185 { GL_LUMINANCE_ALPHA8UI_EXT, GL_LUMINANCE_ALPHA, 8 },
186 { GL_LUMINANCE_ALPHA16UI_EXT, GL_LUMINANCE_ALPHA, 16 },
187 { GL_LUMINANCE_ALPHA32UI_EXT, GL_LUMINANCE_ALPHA, 32 },
188 { GL_LUMINANCE_ALPHA8I_EXT, GL_LUMINANCE_ALPHA, 8 },
189 { GL_LUMINANCE_ALPHA16I_EXT, GL_LUMINANCE_ALPHA, 16 },
190 { GL_LUMINANCE_ALPHA32I_EXT, GL_LUMINANCE_ALPHA, 32 },
193 static const struct format_desc arb_texture_rg[] = {
194 { GL_R8, GL_RED, 8 },
195 { GL_R16, GL_RED, 16 },
196 { GL_RG, GL_RG, 0 },
197 { GL_RG8, GL_RG, 8 },
198 { GL_RG16, GL_RG, 16 },
201 static const struct format_desc arb_texture_rg_int[] = {
202 { GL_R8I, GL_RED, 8 },
203 { GL_R8UI, GL_RED, 8 },
204 { GL_R16I, GL_RED, 16 },
205 { GL_R16UI, GL_RED, 16 },
206 { GL_R32I, GL_RED, 32 },
207 { GL_R32UI, GL_RED, 32 },
208 { GL_RG_INTEGER, GL_RG, 0 },
209 { GL_RG8I, GL_RG, 8 },
210 { GL_RG8UI, GL_RG, 8 },
211 { GL_RG16I, GL_RG, 16 },
212 { GL_RG16UI, GL_RG, 16 },
213 { GL_RG32I, GL_RG, 32 },
214 { GL_RG32UI, GL_RG, 32 },
217 static const struct format_desc arb_texture_rg_float[] = {
218 { GL_R16F, GL_RED, 16 },
219 { GL_R32F, GL_RED, 32 },
220 { GL_RG16F, GL_RG, 16 },
221 { GL_RG32F, GL_RG, 32 },
224 static const struct format_desc ext_texture_shared_exponent[] = {
225 { GL_RGB9_E5_EXT, GL_RGB, 9 },
228 static const struct format_desc ext_packed_float[] = {
229 { GL_R11F_G11F_B10F_EXT, GL_RGB, 10 },
232 static const struct format_desc arb_depth_buffer_float[] = {
233 { GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, 32 },
234 { GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, 32 },
237 static const struct format_desc ext_texture_compression_rgtc[] = {
238 { GL_COMPRESSED_RED, GL_RED, 0 },
239 { GL_COMPRESSED_RED_RGTC1_EXT, GL_RED, 0 },
240 { GL_COMPRESSED_RG, GL_RG, 0 },
241 { GL_COMPRESSED_RED_GREEN_RGTC2_EXT, GL_RG, 0 },
244 static const struct format_desc ext_texture_compression_rgtc_signed[] = {
245 { GL_COMPRESSED_SIGNED_RED_RGTC1_EXT, GL_RED, 0 },
246 { GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, GL_RG, 0 },
249 static const struct format_desc arb_texture_float[] = {
250 { GL_RGB16F_ARB, GL_RGB, 16 },
251 { GL_RGBA16F_ARB, GL_RGBA, 16 },
252 { GL_ALPHA16F_ARB, GL_ALPHA, 16 },
253 { GL_LUMINANCE16F_ARB, GL_LUMINANCE, 16 },
254 { GL_LUMINANCE_ALPHA16F_ARB, GL_LUMINANCE_ALPHA, 16 },
255 { GL_INTENSITY16F_ARB, GL_INTENSITY, 16 },
256 { GL_RGB32F_ARB, GL_RGB, 32 },
257 { GL_RGBA32F_ARB, GL_RGBA, 32 },
258 { GL_ALPHA32F_ARB, GL_ALPHA, 32 },
259 { GL_LUMINANCE32F_ARB, GL_LUMINANCE, 32 },
260 { GL_LUMINANCE_ALPHA32F_ARB, GL_LUMINANCE_ALPHA, 32 },
261 { GL_INTENSITY32F_ARB, GL_INTENSITY, 32 }
264 static const struct format_desc ati_texture_compression_3dc[] = {
265 { GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, GL_LUMINANCE_ALPHA, 0 }
268 static const struct format_desc ext_texture_compression_latc[] = {
269 { GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_LUMINANCE, 0 },
270 { GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_LUMINANCE_ALPHA, 0 },
273 static const struct format_desc ext_texture_compression_latc_signed[] = {
274 { GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT, GL_LUMINANCE, 0 },
275 { GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT, GL_LUMINANCE_ALPHA, 0 }
278 static const struct format_desc ext_texture_snorm[] = {
279 { GL_RED_SNORM, GL_RED, 0 },
280 { GL_R8_SNORM, GL_RED, 8 },
281 { GL_RG_SNORM, GL_RG, 0 },
282 { GL_RG8_SNORM, GL_RG, 8 },
283 { GL_RGB_SNORM, GL_RGB, 0 },
284 { GL_RGB8_SNORM, GL_RGB, 8 },
285 { GL_RGBA_SNORM, GL_RGBA, 0 },
286 { GL_RGBA8_SNORM, GL_RGBA, 8 },
287 { GL_ALPHA_SNORM, GL_ALPHA, 0 },
288 { GL_ALPHA8_SNORM, GL_ALPHA, 8 },
289 { GL_LUMINANCE_SNORM, GL_LUMINANCE, 0 },
290 { GL_LUMINANCE8_SNORM, GL_LUMINANCE, 8 },
291 { GL_LUMINANCE_ALPHA_SNORM, GL_LUMINANCE_ALPHA, 0 },
292 { GL_LUMINANCE8_ALPHA8_SNORM, GL_LUMINANCE_ALPHA, 8 },
293 { GL_INTENSITY_SNORM, GL_INTENSITY, 0 },
294 { GL_INTENSITY8_SNORM, GL_INTENSITY, 8 },
295 { GL_R16_SNORM, GL_RED, 16 },
296 { GL_RG16_SNORM, GL_RG, 16 },
297 { GL_RGB16_SNORM, GL_RGB, 16 },
298 { GL_RGBA16_SNORM, GL_RGBA, 16 },
299 { GL_ALPHA16_SNORM, GL_ALPHA, 16 },
300 { GL_LUMINANCE16_SNORM, GL_LUMINANCE, 16 },
301 { GL_LUMINANCE16_ALPHA16_SNORM, GL_LUMINANCE_ALPHA, 16 },
302 { GL_INTENSITY16_SNORM, GL_INTENSITY, 16 }
305 static const struct format_desc arb_texture_compression_bptc_unorm[] = {
306 { GL_COMPRESSED_RGBA_BPTC_UNORM, GL_RGBA, 0 },
307 { GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, GL_RGBA, 0 }
310 static const struct format_desc arb_texture_compression_bptc_float[] = {
311 { GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, GL_RGB, 0 },
312 { GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, GL_RGB, 0 }
315 static const struct format_desc arb_es2_compatibility[] = {
316 { GL_RGB565, GL_RGB, 5 }
319 static const struct format_desc arb_texture_stencil8[] = {
320 { GL_STENCIL_INDEX8, GL_STENCIL_INDEX, 0 }
323 struct test_desc {
324 const struct format_desc *format;
325 unsigned num_formats;
326 const char *param;
327 GLenum basetype;
328 const char *ext[3];
331 static const struct test_desc test_sets[] = {
333 core,
334 ARRAY_SIZE(core),
335 "Core formats",
336 GL_UNSIGNED_NORMALIZED,
339 ext_texture_compression,
340 ARRAY_SIZE(ext_texture_compression),
341 "GL_ARB_texture_compression",
342 GL_UNSIGNED_NORMALIZED,
343 {"GL_ARB_texture_compression"}
346 tdfx_texture_compression_fxt1,
347 ARRAY_SIZE(tdfx_texture_compression_fxt1),
348 "GL_3DFX_texture_compression_FXT1",
349 GL_UNSIGNED_NORMALIZED,
350 {"GL_ARB_texture_compression",
351 "GL_3DFX_texture_compression_FXT1"},
354 ext_texture_compression_s3tc,
355 ARRAY_SIZE(ext_texture_compression_s3tc),
356 "GL_EXT_texture_compression_s3tc",
357 GL_UNSIGNED_NORMALIZED,
358 {"GL_ARB_texture_compression",
359 "GL_EXT_texture_compression_s3tc"},
362 arb_depth_texture,
363 ARRAY_SIZE(arb_depth_texture),
364 "GL_ARB_depth_texture",
365 GL_UNSIGNED_NORMALIZED,
366 {"GL_ARB_depth_texture"},
369 ext_packed_depth_stencil,
370 ARRAY_SIZE(ext_packed_depth_stencil),
371 "GL_EXT_packed_depth_stencil",
372 GL_UNSIGNED_NORMALIZED,
373 {"GL_EXT_packed_depth_stencil"},
376 ext_texture_srgb,
377 ARRAY_SIZE(ext_texture_srgb),
378 "GL_EXT_texture_sRGB",
379 GL_UNSIGNED_NORMALIZED,
380 {"GL_EXT_texture_sRGB"}
383 ext_texture_srgb_compressed,
384 ARRAY_SIZE(ext_texture_srgb_compressed),
385 "GL_EXT_texture_sRGB-s3tc",
386 GL_UNSIGNED_NORMALIZED,
387 {"GL_EXT_texture_sRGB",
388 "GL_ARB_texture_compression",
389 "GL_EXT_texture_compression_s3tc"},
392 ext_texture_integer,
393 ARRAY_SIZE(ext_texture_integer),
394 "GL_EXT_texture_integer",
395 GL_INT,
396 {"GL_EXT_texture_integer"}
399 arb_texture_rg,
400 ARRAY_SIZE(arb_texture_rg),
401 "GL_ARB_texture_rg",
402 GL_UNSIGNED_NORMALIZED,
403 {"GL_ARB_texture_rg"}
406 arb_texture_rg_int,
407 ARRAY_SIZE(arb_texture_rg_int),
408 "GL_ARB_texture_rg-int",
409 GL_INT,
410 {"GL_ARB_texture_rg",
411 "GL_EXT_texture_integer"}
414 arb_texture_rg_float,
415 ARRAY_SIZE(arb_texture_rg_float),
416 "GL_ARB_texture_rg-float",
417 GL_FLOAT,
418 {"GL_ARB_texture_rg",
419 "GL_ARB_texture_float"}
422 ext_texture_shared_exponent,
423 ARRAY_SIZE(ext_texture_shared_exponent),
424 "GL_EXT_texture_shared_exponent",
425 GL_UNSIGNED_NORMALIZED, /* XXX UNSIGNED_FLOAT */
426 {"GL_EXT_texture_shared_exponent"}
429 ext_packed_float,
430 ARRAY_SIZE(ext_packed_float),
431 "GL_EXT_packed_float",
432 GL_UNSIGNED_NORMALIZED, /* XXX UNSIGNED_FLOAT */
433 {"GL_EXT_packed_float"}
436 arb_depth_buffer_float,
437 ARRAY_SIZE(arb_depth_buffer_float),
438 "GL_ARB_depth_buffer_float",
439 GL_FLOAT,
440 {"GL_ARB_depth_buffer_float"},
443 ext_texture_compression_rgtc,
444 ARRAY_SIZE(ext_texture_compression_rgtc),
445 "GL_EXT_texture_compression_rgtc",
446 GL_UNSIGNED_NORMALIZED,
447 {"GL_EXT_texture_compression_rgtc"}
450 ext_texture_compression_rgtc_signed,
451 ARRAY_SIZE(ext_texture_compression_rgtc_signed),
452 "GL_EXT_texture_compression_rgtc-signed",
453 GL_SIGNED_NORMALIZED,
454 {"GL_EXT_texture_compression_rgtc"}
457 arb_texture_float,
458 ARRAY_SIZE(arb_texture_float),
459 "GL_ARB_texture_float",
460 GL_FLOAT,
461 {"GL_ARB_texture_float"}
464 ati_texture_compression_3dc,
465 ARRAY_SIZE(ati_texture_compression_3dc),
466 "GL_ATI_texture_compression_3dc",
467 GL_UNSIGNED_NORMALIZED,
468 {"GL_ATI_texture_compression_3dc"}
471 ext_texture_compression_latc,
472 ARRAY_SIZE(ext_texture_compression_latc),
473 "GL_EXT_texture_compression_latc",
474 GL_UNSIGNED_NORMALIZED,
475 {"GL_EXT_texture_compression_latc"}
478 ext_texture_compression_latc_signed,
479 ARRAY_SIZE(ext_texture_compression_latc_signed),
480 "GL_EXT_texture_compression_latc-signed",
481 GL_SIGNED_NORMALIZED,
482 {"GL_EXT_texture_compression_latc"}
485 ext_texture_snorm,
486 ARRAY_SIZE(ext_texture_snorm),
487 "GL_EXT_texture_snorm",
488 GL_SIGNED_NORMALIZED,
489 {"GL_EXT_texture_snorm"}
492 arb_es2_compatibility,
493 ARRAY_SIZE(arb_es2_compatibility),
494 "GL_ARB_ES2_compatibility",
495 GL_UNSIGNED_NORMALIZED,
496 {"GL_ARB_ES2_compatibility"}
499 arb_texture_compression_bptc_unorm,
500 ARRAY_SIZE(arb_texture_compression_bptc_unorm),
501 "GL_ARB_texture_compression_bptc-unorm",
502 GL_UNSIGNED_NORMALIZED,
503 {"GL_ARB_texture_compression_bptc"}
506 arb_texture_compression_bptc_float,
507 ARRAY_SIZE(arb_texture_compression_bptc_float),
508 "GL_ARB_texture_compression_bptc-float",
509 GL_FLOAT,
510 {"GL_ARB_texture_compression_bptc"}
513 arb_texture_stencil8,
514 ARRAY_SIZE(arb_texture_stencil8),
515 "GL_ARB_texture_stencil8",
516 GL_UNSIGNED_BYTE,
517 {"GL_ARB_texture_stencil8"}
521 static const char *
522 get_format_name(GLenum format)
524 if (format == 3)
525 return "3";
526 if (format == 4)
527 return "4";
528 return piglit_get_gl_enum_name(format);
531 static GLboolean
532 supported(const struct test_desc *test)
534 unsigned i;
536 for (i = 0; i < 3; i++) {
537 if (test->ext[i]) {
538 if (!piglit_is_extension_supported(test->ext[i])) {
539 return GL_FALSE;
544 return GL_TRUE;
547 static int test_index;
548 static int format_index;
552 * If inc_dec == +1, go to the next test set.
553 * If inc_dec == -1, go to the previous test set.
555 static void next_test_set(int inc_dec)
557 do {
558 test_index += inc_dec;
559 if (test_index >= (int) ARRAY_SIZE(test_sets)) {
560 test_index = 0;
562 else if (test_index < 0) {
563 test_index = ARRAY_SIZE(test_sets) - 1;
565 } while (!supported(&test_sets[test_index]));
566 format_index = 0;
567 printf("Using test set: %s\n", test_sets[test_index].param);
571 static void fbo_formats_key_func(unsigned char key, int x, int y)
573 switch (key) {
574 case 'n': /* next test set */
575 next_test_set(+1);
576 break;
578 case 'N': /* previous test set */
579 next_test_set(-1);
580 break;
582 case 'm': /* next format */
583 format_index++;
584 if (format_index >= (int) test_sets[test_index].num_formats) {
585 format_index = 0;
587 break;
589 case 'M': /* previous format */
590 format_index--;
591 if (format_index < 0) {
592 format_index = test_sets[test_index].num_formats - 1;
594 break;
595 case 'f': /* next format, or next test set */
596 format_index++;
597 if (format_index >= (int) test_sets[test_index].num_formats) {
598 next_test_set(+1);
600 break;
601 case 'F': /* prev format, or prev test set */
602 format_index--;
603 if (format_index < 0) {
604 next_test_set(-1);
605 format_index = test_sets[test_index].num_formats - 1;
607 break;
609 piglit_escape_exit_key(key, x, y);
613 * Look up a test set name (such as "GL_EXT_texture_sRGB").
614 * \return index >= 0 if found, -1 if not found
616 static int
617 fbo_lookup_test_set(const char *test_set_name)
619 int i, j;
621 for (i = 0; i < (int) ARRAY_SIZE(test_sets); i++) {
622 if (!strcmp(test_set_name, test_sets[i].param)) {
623 for (j = 0; j < 3; j++) {
624 if (test_sets[i].ext[j]) {
625 piglit_require_extension(test_sets[i].ext[j]);
629 return i;
633 return -1;
636 static void
637 fbo_formats_init_test_set(int test_set_index, GLboolean print_options)
639 if (!piglit_automatic)
640 piglit_set_keyboard_func(fbo_formats_key_func);
642 piglit_require_extension("GL_EXT_framebuffer_object");
643 piglit_require_extension("GL_ARB_texture_env_combine");
645 test_index = test_set_index;
647 if (!piglit_automatic && print_options) {
648 printf(" -n Next test set.\n"
649 " -N Previous test set.\n"
650 " -m Next format in the set.\n"
651 " -M Previous format in the set.\n");
654 printf("Using test set: %s\n", test_sets[test_index].param);
657 void
658 fbo_formats_init(int argc, char **argv, GLboolean print_options)
660 int test_set_index = 0;
661 if (argc == 2) {
662 test_set_index = fbo_lookup_test_set(argv[1]);
663 if (test_set_index < 0) {
664 unsigned i;
665 fprintf(stderr, "Unknown test set: %s\n", argv[1]);
666 fprintf(stderr, "Test sets:\n");
667 for (i = 0; i < ARRAY_SIZE(test_sets); i++) {
668 fprintf(stderr, "\t%s\n", test_sets[i].param);
670 exit(1);
672 } else if (argc > 2) {
673 printf("More than 1 test set specified\n");
674 exit(1);
677 fbo_formats_init_test_set(test_set_index, print_options);
681 * Try to use the given format test set (such as "GL_EXT_texture_sRGB")
682 * This is an alternative to the fbo_formats_init() function above.
683 * \return true if success, false if unknown test set name
685 bool
686 fbo_use_test_set(const char *test_set, bool print_options)
688 int test_set_index = fbo_lookup_test_set(test_set);
689 if (test_set_index >= 0) {
690 fbo_formats_init_test_set(test_set_index,
691 (GLboolean) print_options);
692 return true;
693 } else {
694 return false;
698 typedef enum piglit_result (*test_func)(const struct format_desc *format);
700 static enum piglit_result fbo_formats_display(test_func test_format)
702 enum piglit_result end_result = PIGLIT_SKIP;
703 enum piglit_result result;
704 unsigned i;
706 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo);
707 glClearColor(0.5, 0.5, 0.5, 0.5);
708 glClear(GL_COLOR_BUFFER_BIT);
710 if (piglit_automatic) {
711 for (i = 0; i < test_sets[test_index].num_formats; i++) {
712 result = test_format(&test_sets[test_index].format[i]);
713 piglit_merge_result(&end_result, result);
715 } else {
716 result = test_format(&test_sets[test_index].format[format_index]);
717 piglit_merge_result(&end_result, result);
720 piglit_present_results();
722 return end_result;