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
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 * \file internal-format-query.c
26 * Check that only general-purpose fmts are listed by COMPRESSED_TEXTURE_FORMATS
28 * From page 117 (page 129 of the PDF) of the OpenGL 1.3 spec says:
30 * "The set of specific compressed internal formats supported by the
31 * renderer can be obtained by querying the value of COMPRESSED TEXTURE
32 * FORMATS. The only values returned by this query are those corresponding
33 * to formats suitable for general-purpose usage. The renderer will not
34 * enumerate formats with restrictions that need to be specifically
35 * understood prior to use."
37 * All texture compression extensions have taken this to mean only linear RGB
38 * and linear RGBA formats should be exposed.
40 #include "piglit-util-gl.h"
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config
.supports_gl_compat_version
= 10;
46 config
.window_width
= 10;
47 config
.window_height
= 10;
48 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
;
50 PIGLIT_GL_TEST_CONFIG_END
53 * Set of formats for a particular extension
55 * Each array of "good" formats and "bad" formats is terminated by a sentinel
56 * with \c format set to zero.
59 * The arrays are sized for the largest set from any extension. They may need
60 * to be expanded in the future.
64 * Formats that are part of the extension and should be exposed.
69 * Formats that are part of the extension but should not be exposed.
75 * Formats belonging to GL_ARB_texture_comrpession_bptc
77 * The extension spec says nothing about whether or not these must be
78 * advertised via GL_COMPRESSED_TEXTURE_FORMATS. The OpenGL 4.2 spec also
79 * requires these formats, but it says that GL_NUM_COMPRESSED_TEXTURE_FORMATS
80 * must be at least 0. NVIDIA's driver does not expose them, so we'll
81 * classify them as optional.
83 static const struct format_list bptc_formats
= {
85 GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
,
86 GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
,
87 GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
,
88 GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
,
97 * Formats belonging to GL_ARB_texture_comrpession_rgtc
99 static const struct format_list rgtc_formats
= {
104 GL_COMPRESSED_RED_RGTC1
,
105 GL_COMPRESSED_SIGNED_RED_RGTC1
,
106 GL_COMPRESSED_RG_RGTC2
,
107 GL_COMPRESSED_SIGNED_RG_RGTC2
,
113 * Formats belonging to GL_3DFX_texture_comrpession_FXT1
115 static const struct format_list fxt1_formats
= {
117 GL_COMPRESSED_RGB_FXT1_3DFX
,
118 GL_COMPRESSED_RGBA_FXT1_3DFX
,
127 * Formats belonging to GL_ATI_texture_comrpession_3dc
129 static const struct format_list ati_3dc_formats
= {
134 GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
,
140 * Formats belonging to GL_EXT_texture_comrpession_latc
142 static const struct format_list latc_formats
= {
147 GL_COMPRESSED_LUMINANCE_LATC1_EXT
,
148 GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
,
149 GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
,
150 GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
,
156 * Formats belonging to GL_EXT_texture_comrpession_s3tc
158 static const struct format_list s3tc_formats
= {
160 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
161 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
,
162 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
,
166 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
,
172 * Formats belonging to GL_EXT_texture_sRGB
174 * These should only be exported if GL_EXT_texture_compression_s3tc is also
177 static const struct format_list srgb_formats
= {
182 GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
,
183 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
,
184 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
,
185 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
,
191 * Formats belonging to GL_OES_comrpessed_paletted_texture
193 static const struct format_list paletted_formats
= {
195 GL_PALETTE4_RGB8_OES
,
196 GL_PALETTE4_RGBA8_OES
,
197 GL_PALETTE4_R5_G6_B5_OES
,
198 GL_PALETTE4_RGBA4_OES
,
199 GL_PALETTE4_RGB5_A1_OES
,
200 GL_PALETTE8_RGB8_OES
,
201 GL_PALETTE8_RGBA8_OES
,
202 GL_PALETTE8_R5_G6_B5_OES
,
203 GL_PALETTE8_RGBA4_OES
,
204 GL_PALETTE8_RGB5_A1_OES
,
213 * Format belonging to GL_OES_compressed_ETC1_RGB8_texture.
215 * The GL_OES_compressed_ETC1_RGB8_texture spec says:
219 * The queries for NUM_COMPRESSED_TEXTURE_FORMATS and
220 * COMPRESSED_TEXTURE_FORMATS include ETC1_RGB8_OES."
222 static const struct format_list etc1_formats
= {
233 * Formats belonging to OpenGL ES 3.0
235 * These formats are dragged into desktop OpenGL via GL_ARB_ES3_compatibility
236 * or OpenGL 4.3. The extension spec says nothing about whether or not these
237 * must be advertised via GL_COMPRESSED_TEXTURE_FORMATS. The OpenGL 4.3 spec
238 * requires these formats, but it says that GL_NUM_COMPRESSED_TEXTURE_FORMATS
239 * must be at least 0. NVIDIA's driver exposes them, so we'll classify them
242 static const struct format_list etc2_formats
= {
244 GL_COMPRESSED_RGB8_ETC2
,
245 GL_COMPRESSED_SRGB8_ETC2
,
246 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
,
247 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
,
248 GL_COMPRESSED_RGBA8_ETC2_EAC
,
249 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
,
250 GL_COMPRESSED_R11_EAC
,
251 GL_COMPRESSED_SIGNED_R11_EAC
,
252 GL_COMPRESSED_RG11_EAC
,
253 GL_COMPRESSED_SIGNED_RG11_EAC
,
262 * Formats belonging to GL_KHR_texture_compression_astc_ldr
264 static const struct format_list astc_formats
= {
269 GL_COMPRESSED_RGBA_ASTC_4x4_KHR
,
270 GL_COMPRESSED_RGBA_ASTC_5x4_KHR
,
271 GL_COMPRESSED_RGBA_ASTC_5x5_KHR
,
272 GL_COMPRESSED_RGBA_ASTC_6x5_KHR
,
273 GL_COMPRESSED_RGBA_ASTC_6x6_KHR
,
274 GL_COMPRESSED_RGBA_ASTC_8x5_KHR
,
275 GL_COMPRESSED_RGBA_ASTC_8x6_KHR
,
276 GL_COMPRESSED_RGBA_ASTC_8x8_KHR
,
277 GL_COMPRESSED_RGBA_ASTC_10x5_KHR
,
278 GL_COMPRESSED_RGBA_ASTC_10x6_KHR
,
279 GL_COMPRESSED_RGBA_ASTC_10x8_KHR
,
280 GL_COMPRESSED_RGBA_ASTC_10x10_KHR
,
281 GL_COMPRESSED_RGBA_ASTC_12x10_KHR
,
282 GL_COMPRESSED_RGBA_ASTC_12x12_KHR
,
283 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
,
284 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
,
285 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
,
286 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
,
287 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
,
288 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
,
289 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
,
290 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
,
291 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
,
292 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
,
293 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
,
294 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
,
295 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
,
296 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
,
302 * List of all known compression methods to test
304 * The dummy first element is because this list is used by \c main to replace
305 * the \c argv vector when no command line parameters are supplied.
307 const char *all_formats
[] = {
329 reject_bad(const GLenum
*bad
, GLenum
*compressed_formats
,
330 GLint num_compressed_formats
, bool check_errors
)
336 for (i
= 0; bad
[i
] != 0; i
++) {
337 for (j
= 0; j
< num_compressed_formats
; j
++) {
338 if (compressed_formats
[j
] == 0)
341 if (compressed_formats
[j
] == bad
[i
])
345 if (j
!= num_compressed_formats
) {
348 "%s should not be available.\n",
349 piglit_get_gl_enum_name(
354 /* Replace formats that have been processed with
355 * zero. This allows detection of values that don't
356 * belong to any compression extension.
358 compressed_formats
[j
] = 0;
366 try_formats(const struct format_list
*t
, GLenum
*compressed_formats
,
367 GLint num_compressed_formats
, bool check_errors
, bool supported
,
373 pass
= reject_bad(t
->good
, compressed_formats
,
374 num_compressed_formats
, check_errors
)
380 for (i
= 0; t
->good
[i
] != 0; i
++) {
381 for (j
= 0; j
< num_compressed_formats
; j
++) {
382 if (compressed_formats
[j
] == 0)
385 if (compressed_formats
[j
] == t
->good
[i
])
389 if (j
== num_compressed_formats
) {
390 if (check_errors
&& !optional
) {
392 "%s should be available.\n",
393 piglit_get_gl_enum_name(
398 /* Replace formats that have been processed
399 * with zero. This allows detection of values
400 * that don't belong to any compression
403 compressed_formats
[j
] = 0;
408 pass
= reject_bad(t
->bad
, compressed_formats
, num_compressed_formats
,
420 glGetIntegerv(GL_TEXTURE_COMPRESSION_HINT
, &hint
);
421 if (hint
!= GL_DONT_CARE
) {
422 printf("Unexpected default GL_TEXTURE_COMPRESSION_HINT"
423 " value: %s\n", piglit_get_gl_enum_name(hint
));
427 glHint(GL_TEXTURE_COMPRESSION_HINT
, GL_NICEST
);
428 glGetIntegerv(GL_TEXTURE_COMPRESSION_HINT
, &hint
);
429 if (hint
!= GL_NICEST
) {
430 printf("Unexpected GL_TEXTURE_COMPRESSION_HINT"
431 " value: %s\n", piglit_get_gl_enum_name(hint
));
440 piglit_init(int argc
, char **argv
)
442 GLint num_compressed_formats
;
443 GLenum
*compressed_formats
= NULL
;
446 bool log_header
= true;
448 bool check_errors
= true;
450 piglit_require_extension("GL_ARB_texture_compression");
452 glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS
,
453 &num_compressed_formats
);
454 if (num_compressed_formats
== 0) {
455 printf("No compressed formats supported.\n");
457 compressed_formats
= calloc(num_compressed_formats
,
459 glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS
,
460 (GLint
*) compressed_formats
);
462 printf("Driver reported the following compressed formats:\n");
463 for (i
= 0; i
< num_compressed_formats
; i
++) {
464 printf(" 0x%04x: %s\n",
465 compressed_formats
[i
],
466 piglit_get_gl_enum_name(compressed_formats
[i
]));
472 /* First scan the list of formats looking for zeros. We use that as
473 * magic flag later in the test.
475 for (i
= 0; i
< num_compressed_formats
; i
++) {
476 if (compressed_formats
[i
] == 0) {
478 "Invalid value 0x0000 in format list.\n");
479 piglit_report_result(PIGLIT_FAIL
);
483 /* The "unknown" flag instructs the test to just check for values that
484 * don't belong to any compression extension supported by this
487 if (argc
> 1 && strcmp("unknown", argv
[1]) == 0) {
488 check_errors
= false;
494 argv
= (char **) all_formats
; /* cast away const */
495 argc
= ARRAY_SIZE(all_formats
);
499 for (i
= 1; i
< argc
; i
++) {
500 if (strcmp(argv
[i
], "bptc") == 0) {
501 pass
= try_formats(&bptc_formats
,
503 num_compressed_formats
,
505 piglit_is_extension_supported("GL_ARB_texture_compression_bptc"),
508 } else if (strcmp(argv
[i
], "s3tc") == 0) {
509 pass
= try_formats(&s3tc_formats
,
511 num_compressed_formats
,
513 piglit_is_extension_supported("GL_EXT_texture_compression_s3tc"),
516 } else if (strcmp(argv
[i
], "fxt1") == 0) {
517 pass
= try_formats(&fxt1_formats
,
519 num_compressed_formats
,
521 piglit_is_extension_supported("GL_3DFX_texture_compression_FXT1"),
524 } else if (strcmp(argv
[i
], "latc") == 0) {
525 pass
= try_formats(&latc_formats
,
527 num_compressed_formats
,
529 piglit_is_extension_supported("GL_EXT_texture_compression_latc"),
532 } else if (strcmp(argv
[i
], "3dc") == 0) {
533 pass
= try_formats(&ati_3dc_formats
,
535 num_compressed_formats
,
537 piglit_is_extension_supported("GL_ATI_texture_compression_3dc"),
540 } else if (strcmp(argv
[i
], "rgtc") == 0) {
541 pass
= try_formats(&rgtc_formats
,
543 num_compressed_formats
,
545 (piglit_is_extension_supported("GL_ARB_texture_compression_rgtc")
546 || piglit_is_extension_supported("GL_EXT_texture_compression_rgtc")),
549 } else if (strcmp(argv
[i
], "srgb") == 0) {
550 pass
= try_formats(&srgb_formats
,
552 num_compressed_formats
,
554 (piglit_is_extension_supported("GL_EXT_texture_sRGB")
555 && piglit_is_extension_supported("GL_EXT_texture_compression_s3tc")),
558 } else if (strcmp(argv
[i
], "paletted") == 0) {
559 pass
= try_formats(&paletted_formats
,
561 num_compressed_formats
,
563 piglit_is_extension_supported("GL_OES_compressed_paletted_texture"),
566 } else if (strcmp(argv
[i
], "etc1") == 0) {
567 pass
= try_formats(&etc1_formats
,
569 num_compressed_formats
,
571 piglit_is_extension_supported("GL_OES_compressed_ETC1_RGB8_texture"),
574 } else if (strcmp(argv
[i
], "etc2") == 0) {
575 pass
= try_formats(&etc2_formats
,
577 num_compressed_formats
,
579 piglit_is_extension_supported("GL_ARB_ES3_compatibility"),
582 } else if (strcmp(argv
[i
], "astc") == 0) {
583 pass
= try_formats(&astc_formats
,
585 num_compressed_formats
,
587 piglit_is_extension_supported("GL_KHR_texture_compression_astc_ldr"),
592 "Unrecognized selection `%s'\n", argv
[i
]);
593 piglit_report_result(PIGLIT_FAIL
);
597 /* After all of the known formats have been processed, the entire
598 * format array should be zeroed out. Any non-zero values are either
599 * errors or formats from unknown extensions... meaning that the test
600 * may need to be updated.
603 for (i
= 0; i
< num_compressed_formats
; i
++) {
604 if (compressed_formats
[i
] != 0) {
607 "Unrecognized compressed "
608 "texture formats:\n");
612 fprintf(stderr
, " 0x%04x: %s\n",
613 compressed_formats
[i
],
614 piglit_get_gl_enum_name(compressed_formats
[i
]));
620 pass
= test_hint() && pass
;
622 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);