revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / workbench / libs / mesa / src / mesa / main / texformat.c
blob8cbb021d8b02b74d53a49d74fad257161d3f7d93
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.7
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.
27 /**
28 * \file texformat.c
29 * Texture formats.
31 * \author Gareth Hughes
32 * \author Brian Paul
36 #include "context.h"
37 #include "mfeatures.h"
38 #include "mtypes.h"
39 #include "texcompress.h"
40 #include "texformat.h"
42 #define RETURN_IF_SUPPORTED(f) do { \
43 if (ctx->TextureFormatSupported[f]) \
44 return f; \
45 } while (0)
47 /**
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.
62 gl_format
63 _mesa_choose_tex_format( struct gl_context *ctx, GLint internalFormat,
64 GLenum format, GLenum type )
66 (void) format;
67 (void) type;
69 switch (internalFormat) {
70 /* shallow RGBA formats */
71 case 4:
72 case GL_RGBA:
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);
80 break;
82 case GL_RGBA8:
83 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA8888);
84 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
85 break;
86 case GL_RGB5_A1:
87 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB1555);
88 break;
89 case GL_RGBA2:
90 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444_REV); /* just to test another format*/
91 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
92 break;
93 case GL_RGBA4:
94 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB4444);
95 break;
97 /* deep RGBA formats */
98 case GL_RGB10_A2:
99 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB2101010);
100 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
101 break;
102 case GL_RGBA12:
103 case GL_RGBA16:
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);
108 break;
110 /* shallow RGB formats */
111 case 3:
112 case GL_RGB:
113 case GL_RGB8:
114 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB888);
115 RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
116 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
117 break;
118 case GL_R3_G3_B2:
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);
123 break;
124 case GL_RGB4:
125 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565_REV); /* just to test another format */
126 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565);
127 break;
128 case GL_RGB5:
129 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB565);
130 break;
132 /* deep RGB formats */
133 case GL_RGB10:
134 case GL_RGB12:
135 case GL_RGB16:
136 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_16);
137 RETURN_IF_SUPPORTED(MESA_FORMAT_XRGB8888);
138 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
139 break;
141 /* Alpha formats */
142 case GL_ALPHA:
143 case GL_ALPHA4:
144 case GL_ALPHA8:
145 RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
146 break;
148 case GL_ALPHA12:
149 case GL_ALPHA16:
150 RETURN_IF_SUPPORTED(MESA_FORMAT_A16);
151 RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
152 break;
154 /* Luminance formats */
155 case 1:
156 case GL_LUMINANCE:
157 case GL_LUMINANCE4:
158 case GL_LUMINANCE8:
159 RETURN_IF_SUPPORTED(MESA_FORMAT_L8);
160 break;
162 case GL_LUMINANCE12:
163 case GL_LUMINANCE16:
164 RETURN_IF_SUPPORTED(MESA_FORMAT_L16);
165 RETURN_IF_SUPPORTED(MESA_FORMAT_L8);
166 break;
168 /* Luminance/Alpha formats */
169 case GL_LUMINANCE4_ALPHA4:
170 RETURN_IF_SUPPORTED(MESA_FORMAT_AL44);
171 RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
172 break;
174 case 2:
175 case GL_LUMINANCE_ALPHA:
176 case GL_LUMINANCE6_ALPHA2:
177 case GL_LUMINANCE8_ALPHA8:
178 RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
179 break;
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);
186 break;
188 case GL_INTENSITY:
189 case GL_INTENSITY4:
190 case GL_INTENSITY8:
191 RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
192 break;
194 case GL_INTENSITY12:
195 case GL_INTENSITY16:
196 RETURN_IF_SUPPORTED(MESA_FORMAT_I16);
197 RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
198 break;
200 case GL_COLOR_INDEX:
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);
208 break;
210 default:
211 ; /* fallthrough */
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);
222 break;
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);
227 default:
228 ; /* fallthrough */
232 switch (internalFormat) {
233 case GL_COMPRESSED_ALPHA_ARB:
234 RETURN_IF_SUPPORTED(MESA_FORMAT_A8);
235 break;
236 case GL_COMPRESSED_LUMINANCE_ARB:
237 RETURN_IF_SUPPORTED(MESA_FORMAT_L8);
238 break;
239 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
240 RETURN_IF_SUPPORTED(MESA_FORMAT_AL88);
241 break;
242 case GL_COMPRESSED_INTENSITY_ARB:
243 RETURN_IF_SUPPORTED(MESA_FORMAT_I8);
244 break;
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);
254 break;
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);
263 break;
264 default:
265 ; /* fallthrough */
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);
272 else
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);
282 break;
283 case GL_COMPRESSED_RGBA_FXT1_3DFX:
284 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FXT1);
285 break;
286 default:
287 ; /* fallthrough */
290 #endif
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);
297 break;
298 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
299 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT1);
300 break;
301 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
302 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3);
303 break;
304 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
305 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT5);
306 break;
307 default:
308 ; /* fallthrough */
312 if (ctx->Extensions.S3_s3tc) {
313 switch (internalFormat) {
314 case GL_RGB_S3TC:
315 case GL_RGB4_S3TC:
316 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
317 break;
318 case GL_RGBA_S3TC:
319 case GL_RGBA4_S3TC:
320 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3);
321 break;
322 default:
323 ; /* fallthrough */
326 #endif
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);
334 break;
335 case GL_ALPHA32F_ARB:
336 RETURN_IF_SUPPORTED(MESA_FORMAT_ALPHA_FLOAT32);
337 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
338 break;
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);
343 break;
344 case GL_LUMINANCE32F_ARB:
345 RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_FLOAT32);
346 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
347 break;
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);
352 break;
353 case GL_LUMINANCE_ALPHA32F_ARB:
354 RETURN_IF_SUPPORTED(MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32);
355 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
356 break;
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);
361 break;
362 case GL_INTENSITY32F_ARB:
363 RETURN_IF_SUPPORTED(MESA_FORMAT_INTENSITY_FLOAT32);
364 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
365 break;
366 case GL_RGB16F_ARB:
367 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16);
368 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32);
369 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
370 break;
371 case GL_RGB32F_ARB:
372 RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32);
373 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
374 break;
375 case GL_RGBA16F_ARB:
376 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
377 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
378 break;
379 case GL_RGBA32F_ARB:
380 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
381 break;
382 default:
383 ; /* fallthrough */
387 if (ctx->Extensions.EXT_texture_shared_exponent) {
388 switch (internalFormat) {
389 case GL_RGB9_E5:
390 ASSERT(ctx->TextureFormatSupported[MESA_FORMAT_RGB9_E5_FLOAT]);
391 return MESA_FORMAT_RGB9_E5_FLOAT;
392 default:
393 ; /* fallthrough */
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;
402 default:
403 ; /* fallthrough */
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);
413 break;
414 default:
415 ; /* fallthrough */
419 if (ctx->Extensions.ATI_envmap_bumpmap) {
420 switch (internalFormat) {
421 case GL_DUDV_ATI:
422 case GL_DU8DV8_ATI:
423 RETURN_IF_SUPPORTED(MESA_FORMAT_DUDV8);
424 break;
425 default:
426 ; /* fallthrough */
430 if (ctx->Extensions.EXT_texture_snorm) {
431 switch (internalFormat) {
432 case GL_RED_SNORM:
433 case GL_R8_SNORM:
434 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R8);
435 break;
436 case GL_RG_SNORM:
437 case GL_RG8_SNORM:
438 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RG88_REV);
439 break;
440 case GL_RGB_SNORM:
441 case GL_RGB8_SNORM:
442 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBX8888);
443 /* FALLTHROUGH */
444 case GL_RGBA_SNORM:
445 case GL_RGBA8_SNORM:
446 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888);
447 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGBA8888_REV);
448 break;
449 case GL_ALPHA_SNORM:
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);
454 break;
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);
461 break;
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);
467 break;
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);
473 break;
474 case GL_R16_SNORM:
475 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_R16);
476 break;
477 case GL_RG16_SNORM:
478 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_GR1616);
479 break;
480 case GL_RGB16_SNORM:
481 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RGB_16);
482 /* FALLTHROUGH */
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);
487 break;
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);
493 break;
494 case GL_LUMINANCE16_SNORM:
495 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_L16);
496 /* FALLTHROUGH */
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);
502 break;
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);
508 break;
509 default:
510 ; /* fall-through */
514 #if FEATURE_EXT_texture_sRGB
515 if (ctx->Extensions.EXT_texture_sRGB) {
516 switch (internalFormat) {
517 case GL_SRGB_EXT:
518 case GL_SRGB8_EXT:
519 RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8);
520 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
521 break;
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);
526 break;
527 case GL_SLUMINANCE_EXT:
528 case GL_SLUMINANCE8_EXT:
529 RETURN_IF_SUPPORTED(MESA_FORMAT_SL8);
530 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
531 break;
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);
536 break;
537 case GL_COMPRESSED_SLUMINANCE_EXT:
538 RETURN_IF_SUPPORTED(MESA_FORMAT_SL8);
539 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
540 break;
541 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
542 RETURN_IF_SUPPORTED(MESA_FORMAT_SLA8);
543 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
544 break;
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);
549 #endif
550 RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB8);
551 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
552 break;
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 */
557 #endif
558 RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA8);
559 RETURN_IF_SUPPORTED(MESA_FORMAT_SARGB8);
560 break;
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);
566 break;
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);
571 break;
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);
576 break;
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);
581 break;
582 #endif
583 default:
584 ; /* fallthrough */
587 #endif /* FEATURE_EXT_texture_sRGB */
589 if (ctx->Extensions.EXT_texture_integer) {
590 switch (internalFormat) {
591 case GL_RGBA32UI_EXT:
592 case GL_RGB32UI_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);
598 break;
599 case GL_RGBA16UI_EXT:
600 case GL_RGB16UI_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);
606 break;
607 case GL_RGBA8UI_EXT:
608 case GL_RGB8UI_EXT:
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);
614 break;
615 case GL_RGBA32I_EXT:
616 case GL_RGB32I_EXT:
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);
622 break;
623 case GL_RGBA16I_EXT:
624 case GL_RGB16I_EXT:
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);
630 break;
631 case GL_RGBA8I_EXT:
632 case GL_RGB8I_EXT:
633 case GL_ALPHA8I_EXT:
634 case GL_INTENSITY8I_EXT:
635 case GL_LUMINANCE8I_EXT:
636 case GL_LUMINANCE_ALPHA8I_EXT:
637 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_INT8);
638 break;
642 if (ctx->Extensions.ARB_texture_rg) {
643 switch (internalFormat) {
644 case GL_R8:
645 case GL_RED:
646 RETURN_IF_SUPPORTED(MESA_FORMAT_R8);
647 break;
649 case GL_COMPRESSED_RED:
650 RETURN_IF_SUPPORTED(MESA_FORMAT_RED_RGTC1);
651 RETURN_IF_SUPPORTED(MESA_FORMAT_R8);
652 break;
654 case GL_R16:
655 RETURN_IF_SUPPORTED(MESA_FORMAT_R16);
656 break;
658 case GL_RG:
659 case GL_RG8:
660 RETURN_IF_SUPPORTED(MESA_FORMAT_RG88);
661 break;
663 case GL_COMPRESSED_RG:
664 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_RGTC2);
665 RETURN_IF_SUPPORTED(MESA_FORMAT_RG88);
666 break;
668 case GL_RG16:
669 RETURN_IF_SUPPORTED(MESA_FORMAT_RG1616);
670 break;
672 default:
673 ; /* fallthrough */
677 if (ctx->Extensions.ARB_texture_rg && ctx->Extensions.ARB_texture_float) {
678 switch (internalFormat) {
679 case GL_R16F:
680 RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16);
681 RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32);
682 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
683 break;
684 case GL_R32F:
685 RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32);
686 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
687 break;
688 case GL_RG16F:
689 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
690 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
691 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
692 break;
693 case GL_RG32F:
694 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
695 RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
696 break;
698 default:
699 ; /* fallthrough */
703 if (ctx->Extensions.EXT_texture_format_BGRA8888) {
704 switch (internalFormat) {
705 case GL_BGRA:
706 RETURN_IF_SUPPORTED(MESA_FORMAT_ARGB8888);
707 break;
709 default:
710 ; /* fallthrough */
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);
718 break;
719 case GL_COMPRESSED_SIGNED_RED_RGTC1:
720 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RED_RGTC1);
721 break;
722 case GL_COMPRESSED_RG_RGTC2:
723 RETURN_IF_SUPPORTED(MESA_FORMAT_RG_RGTC2);
724 break;
725 case GL_COMPRESSED_SIGNED_RG_RGTC2:
726 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_RG_RGTC2);
727 break;
728 default:
729 ; /* fallthrough */
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);
737 break;
738 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
739 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_L_LATC1);
740 break;
741 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
742 RETURN_IF_SUPPORTED(MESA_FORMAT_LA_LATC2);
743 break;
744 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
745 RETURN_IF_SUPPORTED(MESA_FORMAT_SIGNED_LA_LATC2);
746 break;
747 default:
748 ; /* fallthrough */
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);
756 break;
757 default:
758 ; /* fallthrough */
762 _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
763 return MESA_FORMAT_NONE;