2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 * \author Gareth Hughes
37 #include "mfeatures.h"
39 #include "texcompress.h"
40 #include "texformat.h"
42 #define RETURN_IF_SUPPORTED(f) do { \
43 if (ctx->TextureFormatSupported[f]) \
48 * Choose an appropriate texture format given the format, type and
49 * internalFormat parameters passed to glTexImage().
51 * \param ctx the GL context.
52 * \param internalFormat user's prefered internal texture format.
53 * \param format incoming image pixel format.
54 * \param type incoming image data type.
56 * \return a pointer to a gl_texture_format object which describes the
57 * choosen texture format, or NULL on failure.
59 * This is called via dd_function_table::ChooseTextureFormat. Hardware drivers
60 * will typically override this function with a specialized version.
63 _mesa_choose_tex_format( struct gl_context
*ctx
, GLint internalFormat
,
64 GLenum format
, GLenum type
)
69 switch (internalFormat
) {
70 /* shallow RGBA formats */
73 if (type
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
74 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444
);
75 } else if (type
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
76 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB1555
);
78 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888
);
79 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888
);
83 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888
);
84 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888
);
87 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB1555
);
90 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444_REV
); /* just to test another format*/
91 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444
);
94 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444
);
97 /* deep RGBA formats */
99 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB2101010
);
100 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888
);
104 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16
);
105 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16
);
106 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888
);
107 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888
);
110 /* shallow RGB formats */
114 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888
);
115 RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888
);
116 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888
);
119 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB332
);
120 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888
);
121 RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888
);
122 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888
);
125 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565_REV
); /* just to test another format */
126 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565
);
129 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565
);
132 /* deep RGB formats */
136 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16
);
137 RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888
);
138 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888
);
145 RETURN_IF_SUPPORTED(MESA_FORMAT_A8
);
150 RETURN_IF_SUPPORTED(MESA_FORMAT_A16
);
151 RETURN_IF_SUPPORTED(MESA_FORMAT_A8
);
154 /* Luminance formats */
159 RETURN_IF_SUPPORTED(MESA_FORMAT_L8
);
164 RETURN_IF_SUPPORTED(MESA_FORMAT_L16
);
165 RETURN_IF_SUPPORTED(MESA_FORMAT_L8
);
168 /* Luminance/Alpha formats */
169 case GL_LUMINANCE4_ALPHA4
:
170 RETURN_IF_SUPPORTED(MESA_FORMAT_AL44
);
171 RETURN_IF_SUPPORTED(MESA_FORMAT_AL88
);
175 case GL_LUMINANCE_ALPHA
:
176 case GL_LUMINANCE6_ALPHA2
:
177 case GL_LUMINANCE8_ALPHA8
:
178 RETURN_IF_SUPPORTED(MESA_FORMAT_AL88
);
181 case GL_LUMINANCE12_ALPHA4
:
182 case GL_LUMINANCE12_ALPHA12
:
183 case GL_LUMINANCE16_ALPHA16
:
184 RETURN_IF_SUPPORTED(MESA_FORMAT_AL1616
);
185 RETURN_IF_SUPPORTED(MESA_FORMAT_AL88
);
191 RETURN_IF_SUPPORTED(MESA_FORMAT_I8
);
196 RETURN_IF_SUPPORTED(MESA_FORMAT_I16
);
197 RETURN_IF_SUPPORTED(MESA_FORMAT_I8
);
201 case GL_COLOR_INDEX1_EXT
:
202 case GL_COLOR_INDEX2_EXT
:
203 case GL_COLOR_INDEX4_EXT
:
204 case GL_COLOR_INDEX12_EXT
:
205 case GL_COLOR_INDEX16_EXT
:
206 case GL_COLOR_INDEX8_EXT
:
207 RETURN_IF_SUPPORTED(MESA_FORMAT_CI8
);
214 if (ctx
->Extensions
.ARB_depth_texture
) {
215 switch (internalFormat
) {
216 case GL_DEPTH_COMPONENT
:
217 case GL_DEPTH_COMPONENT24
:
218 case GL_DEPTH_COMPONENT32
:
219 RETURN_IF_SUPPORTED(MESA_FORMAT_Z32
);
220 RETURN_IF_SUPPORTED(MESA_FORMAT_X8_Z24
);
221 RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24
);
223 case GL_DEPTH_COMPONENT16
:
224 RETURN_IF_SUPPORTED(MESA_FORMAT_Z16
);
225 RETURN_IF_SUPPORTED(MESA_FORMAT_X8_Z24
);
226 RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24
);
232 switch (internalFormat
) {
233 case GL_COMPRESSED_ALPHA_ARB
:
234 RETURN_IF_SUPPORTED(MESA_FORMAT_A8
);
236 case GL_COMPRESSED_LUMINANCE_ARB
:
237 RETURN_IF_SUPPORTED(MESA_FORMAT_L8
);
239 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB
:
240 RETURN_IF_SUPPORTED(MESA_FORMAT_AL88
);
242 case GL_COMPRESSED_INTENSITY_ARB
:
243 RETURN_IF_SUPPORTED(MESA_FORMAT_I8
);
245 case GL_COMPRESSED_RGB_ARB
:
246 if (ctx
->Extensions
.EXT_texture_compression_s3tc
||
247 ctx
->Extensions
.S3_s3tc
)
248 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1
);
249 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
)
250 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FXT1
);
251 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888
);
252 RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888
);
253 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888
);
255 case GL_COMPRESSED_RGBA_ARB
:
256 if (ctx
->Extensions
.EXT_texture_compression_s3tc
||
257 ctx
->Extensions
.S3_s3tc
)
258 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3
); /* Not rgba_dxt1, see spec */
259 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
)
260 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FXT1
);
261 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888
);
262 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888
);
268 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
269 if (internalFormat
== GL_YCBCR_MESA
) {
270 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
)
271 RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR
);
273 RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR_REV
);
277 #if FEATURE_texture_fxt1
278 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
279 switch (internalFormat
) {
280 case GL_COMPRESSED_RGB_FXT1_3DFX
:
281 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FXT1
);
283 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
284 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FXT1
);
292 #if FEATURE_texture_s3tc
293 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
294 switch (internalFormat
) {
295 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
296 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1
);
298 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
299 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT1
);
301 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
302 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3
);
304 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
305 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT5
);
312 if (ctx
->Extensions
.S3_s3tc
) {
313 switch (internalFormat
) {
316 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1
);
320 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3
);
328 if (ctx
->Extensions
.ARB_texture_float
) {
329 switch (internalFormat
) {
330 case GL_ALPHA16F_ARB
:
331 RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT16
);
332 RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32
);
333 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
335 case GL_ALPHA32F_ARB
:
336 RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32
);
337 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
339 case GL_LUMINANCE16F_ARB
:
340 RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT16
);
341 RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32
);
342 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
344 case GL_LUMINANCE32F_ARB
:
345 RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32
);
346 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
348 case GL_LUMINANCE_ALPHA16F_ARB
:
349 RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
);
350 RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
);
351 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
353 case GL_LUMINANCE_ALPHA32F_ARB
:
354 RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
);
355 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
357 case GL_INTENSITY16F_ARB
:
358 RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT16
);
359 RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32
);
360 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
362 case GL_INTENSITY32F_ARB
:
363 RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32
);
364 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
367 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16
);
368 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32
);
369 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
372 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32
);
373 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
376 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16
);
377 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
380 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
387 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
388 switch (internalFormat
) {
390 ASSERT(ctx
->TextureFormatSupported
[MESA_FORMAT_RGB9_E5_FLOAT
]);
391 return MESA_FORMAT_RGB9_E5_FLOAT
;
397 if (ctx
->Extensions
.EXT_packed_float
) {
398 switch (internalFormat
) {
399 case GL_R11F_G11F_B10F
:
400 ASSERT(ctx
->TextureFormatSupported
[MESA_FORMAT_R11_G11_B10_FLOAT
]);
401 return MESA_FORMAT_R11_G11_B10_FLOAT
;
407 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
408 switch (internalFormat
) {
409 case GL_DEPTH_STENCIL_EXT
:
410 case GL_DEPTH24_STENCIL8_EXT
:
411 RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_S8
);
412 RETURN_IF_SUPPORTED(MESA_FORMAT_S8_Z24
);
419 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
420 switch (internalFormat
) {
423 RETURN_IF_SUPPORTED(MESA_FORMAT_DUDV8
);
430 if (ctx
->Extensions
.EXT_texture_snorm
) {
431 switch (internalFormat
) {
434 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R8
);
438 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RG88_REV
);
442 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBX8888
);
446 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888
);
447 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV
);
450 case GL_ALPHA8_SNORM
:
451 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_A8
);
452 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888
);
453 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV
);
455 case GL_LUMINANCE_SNORM
:
456 case GL_LUMINANCE8_SNORM
:
457 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_L8
);
458 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBX8888
);
459 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888
);
460 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV
);
462 case GL_LUMINANCE_ALPHA_SNORM
:
463 case GL_LUMINANCE8_ALPHA8_SNORM
:
464 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_AL88
);
465 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888
);
466 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV
);
468 case GL_INTENSITY_SNORM
:
469 case GL_INTENSITY8_SNORM
:
470 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_I8
);
471 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888
);
472 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV
);
475 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R16
);
478 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_GR1616
);
481 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGB_16
);
483 case GL_RGBA16_SNORM
:
484 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16
);
485 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888
);
486 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV
);
488 case GL_ALPHA16_SNORM
:
489 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_A16
);
490 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16
);
491 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888
);
492 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV
);
494 case GL_LUMINANCE16_SNORM
:
495 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_L16
);
497 case GL_LUMINANCE16_ALPHA16_SNORM
:
498 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_AL1616
);
499 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16
);
500 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888
);
501 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV
);
503 case GL_INTENSITY16_SNORM
:
504 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_I16
);
505 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA_16
);
506 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888
);
507 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV
);
514 #if FEATURE_EXT_texture_sRGB
515 if (ctx
->Extensions
.EXT_texture_sRGB
) {
516 switch (internalFormat
) {
519 RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8
);
520 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8
);
522 case GL_SRGB_ALPHA_EXT
:
523 case GL_SRGB8_ALPHA8_EXT
:
524 RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA8
);
525 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8
);
527 case GL_SLUMINANCE_EXT
:
528 case GL_SLUMINANCE8_EXT
:
529 RETURN_IF_SUPPORTED(MESA_FORMAT_SL8
);
530 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8
);
532 case GL_SLUMINANCE_ALPHA_EXT
:
533 case GL_SLUMINANCE8_ALPHA8_EXT
:
534 RETURN_IF_SUPPORTED(MESA_FORMAT_SLA8
);
535 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8
);
537 case GL_COMPRESSED_SLUMINANCE_EXT
:
538 RETURN_IF_SUPPORTED(MESA_FORMAT_SL8
);
539 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8
);
541 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
542 RETURN_IF_SUPPORTED(MESA_FORMAT_SLA8
);
543 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8
);
545 case GL_COMPRESSED_SRGB_EXT
:
546 #if FEATURE_texture_s3tc
547 if (ctx
->Extensions
.EXT_texture_compression_s3tc
)
548 RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1
);
550 RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8
);
551 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8
);
553 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
554 #if FEATURE_texture_s3tc
555 if (ctx
->Extensions
.EXT_texture_compression_s3tc
)
556 RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3
); /* Not srgba_dxt1, see spec */
558 RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA8
);
559 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8
);
561 #if FEATURE_texture_s3tc
562 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
563 if (ctx
->Extensions
.EXT_texture_compression_s3tc
)
564 RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1
);
565 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8
);
567 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
568 if (ctx
->Extensions
.EXT_texture_compression_s3tc
)
569 RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT1
);
570 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8
);
572 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
573 if (ctx
->Extensions
.EXT_texture_compression_s3tc
)
574 RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3
);
575 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8
);
577 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
578 if (ctx
->Extensions
.EXT_texture_compression_s3tc
)
579 RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT5
);
580 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8
);
587 #endif /* FEATURE_EXT_texture_sRGB */
589 if (ctx
->Extensions
.EXT_texture_integer
) {
590 switch (internalFormat
) {
591 case GL_RGBA32UI_EXT
:
593 case GL_ALPHA32UI_EXT
:
594 case GL_INTENSITY32UI_EXT
:
595 case GL_LUMINANCE32UI_EXT
:
596 case GL_LUMINANCE_ALPHA32UI_EXT
:
597 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32
);
599 case GL_RGBA16UI_EXT
:
601 case GL_ALPHA16UI_EXT
:
602 case GL_INTENSITY16UI_EXT
:
603 case GL_LUMINANCE16UI_EXT
:
604 case GL_LUMINANCE_ALPHA16UI_EXT
:
605 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16
);
609 case GL_ALPHA8UI_EXT
:
610 case GL_INTENSITY8UI_EXT
:
611 case GL_LUMINANCE8UI_EXT
:
612 case GL_LUMINANCE_ALPHA8UI_EXT
:
613 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8
);
617 case GL_ALPHA32I_EXT
:
618 case GL_INTENSITY32I_EXT
:
619 case GL_LUMINANCE32I_EXT
:
620 case GL_LUMINANCE_ALPHA32I_EXT
:
621 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT32
);
625 case GL_ALPHA16I_EXT
:
626 case GL_INTENSITY16I_EXT
:
627 case GL_LUMINANCE16I_EXT
:
628 case GL_LUMINANCE_ALPHA16I_EXT
:
629 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT16
);
634 case GL_INTENSITY8I_EXT
:
635 case GL_LUMINANCE8I_EXT
:
636 case GL_LUMINANCE_ALPHA8I_EXT
:
637 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8
);
642 if (ctx
->Extensions
.ARB_texture_rg
) {
643 switch (internalFormat
) {
646 RETURN_IF_SUPPORTED(MESA_FORMAT_R8
);
649 case GL_COMPRESSED_RED
:
650 RETURN_IF_SUPPORTED(MESA_FORMAT_RED_RGTC1
);
651 RETURN_IF_SUPPORTED(MESA_FORMAT_R8
);
655 RETURN_IF_SUPPORTED(MESA_FORMAT_R16
);
660 RETURN_IF_SUPPORTED(MESA_FORMAT_RG88
);
663 case GL_COMPRESSED_RG
:
664 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_RGTC2
);
665 RETURN_IF_SUPPORTED(MESA_FORMAT_RG88
);
669 RETURN_IF_SUPPORTED(MESA_FORMAT_RG1616
);
677 if (ctx
->Extensions
.ARB_texture_rg
&& ctx
->Extensions
.ARB_texture_float
) {
678 switch (internalFormat
) {
680 RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16
);
681 RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32
);
682 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
685 RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32
);
686 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
689 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16
);
690 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32
);
691 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
694 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32
);
695 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32
);
703 if (ctx
->Extensions
.EXT_texture_format_BGRA8888
) {
704 switch (internalFormat
) {
706 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888
);
714 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
715 switch (internalFormat
) {
716 case GL_COMPRESSED_RED_RGTC1
:
717 RETURN_IF_SUPPORTED(MESA_FORMAT_RED_RGTC1
);
719 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
720 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RED_RGTC1
);
722 case GL_COMPRESSED_RG_RGTC2
:
723 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_RGTC2
);
725 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
726 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RG_RGTC2
);
733 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
734 switch (internalFormat
) {
735 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
736 RETURN_IF_SUPPORTED(MESA_FORMAT_L_LATC1
);
738 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
739 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_L_LATC1
);
741 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
742 RETURN_IF_SUPPORTED(MESA_FORMAT_LA_LATC2
);
744 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
745 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_LA_LATC2
);
752 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
753 switch (internalFormat
) {
754 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
755 RETURN_IF_SUPPORTED(MESA_FORMAT_LA_LATC2
);
762 _mesa_problem(ctx
, "unexpected format in _mesa_choose_tex_format()");
763 return MESA_FORMAT_NONE
;