Add PIPE_FORMAT_U_B8_G8_R8_A8 in default_rgba_format().
[mesa.git] / src / mesa / state_tracker / st_format.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 /**
30 * Texture Image-related functions.
31 * \author Brian Paul
32 */
33
34 #include "main/imports.h"
35 #include "main/context.h"
36 #include "main/texstore.h"
37 #include "main/texformat.h"
38 #include "main/enums.h"
39 #include "main/macros.h"
40
41 #include "pipe/p_context.h"
42 #include "pipe/p_defines.h"
43 #include "st_context.h"
44 #include "st_format.h"
45
46 static GLuint
47 format_bits(
48 pipe_format_rgbazs_t info,
49 GLuint comp )
50 {
51 GLuint size;
52
53 if (pf_swizzle_x(info) == comp) {
54 size = pf_size_x(info);
55 }
56 else if (pf_swizzle_y(info) == comp) {
57 size = pf_size_y(info);
58 }
59 else if (pf_swizzle_z(info) == comp) {
60 size = pf_size_z(info);
61 }
62 else if (pf_swizzle_w(info) == comp) {
63 size = pf_size_w(info);
64 }
65 else {
66 size = 0;
67 }
68 return size << (pf_exp8(info) * 3);
69 }
70
71 static GLuint
72 format_max_bits(
73 pipe_format_rgbazs_t info )
74 {
75 GLuint size = format_bits( info, PIPE_FORMAT_COMP_R );
76
77 size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_G ) );
78 size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_B ) );
79 size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_A ) );
80 size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_Z ) );
81 size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_S ) );
82 return size;
83 }
84
85 static GLuint
86 format_size(
87 pipe_format_rgbazs_t info )
88 {
89 return
90 format_bits( info, PIPE_FORMAT_COMP_R ) +
91 format_bits( info, PIPE_FORMAT_COMP_G ) +
92 format_bits( info, PIPE_FORMAT_COMP_B ) +
93 format_bits( info, PIPE_FORMAT_COMP_A ) +
94 format_bits( info, PIPE_FORMAT_COMP_Z ) +
95 format_bits( info, PIPE_FORMAT_COMP_S );
96 }
97
98 /*
99 * XXX temporary here
100 */
101 GLboolean
102 st_get_format_info(
103 GLuint format,
104 struct pipe_format_info *pinfo )
105 {
106 if (pf_layout(format) == PIPE_FORMAT_LAYOUT_RGBAZS) {
107 pipe_format_rgbazs_t info;
108
109 info = format;
110
111 #if 0
112 {
113 char fmtname[256];
114
115 pf_sprint_name( fmtname, format );
116 printf(
117 "%s\n",
118 fmtname );
119 }
120 #endif
121
122 /* Data type */
123 if (format == PIPE_FORMAT_U_A1_R5_G5_B5 || format == PIPE_FORMAT_U_R5_G6_B5) {
124 pinfo->datatype = GL_UNSIGNED_SHORT;
125 }
126 else {
127 GLuint size;
128
129 size = format_max_bits( info );
130 if (size == 8) {
131 if (pf_type(info) == PIPE_FORMAT_TYPE_UNORM)
132 pinfo->datatype = GL_UNSIGNED_BYTE;
133 else
134 pinfo->datatype = GL_BYTE;
135 }
136 else if (size == 16) {
137 if (pf_type(info) == PIPE_FORMAT_TYPE_UNORM)
138 pinfo->datatype = GL_UNSIGNED_SHORT;
139 else
140 pinfo->datatype = GL_SHORT;
141 }
142 else {
143 assert( size <= 32 );
144 if (pf_type(info) == PIPE_FORMAT_TYPE_UNORM)
145 pinfo->datatype = GL_UNSIGNED_INT;
146 else
147 pinfo->datatype = GL_INT;
148 }
149 }
150
151 /* Component bits */
152 pinfo->red_bits = format_bits( info, PIPE_FORMAT_COMP_R );
153 pinfo->green_bits = format_bits( info, PIPE_FORMAT_COMP_G );
154 pinfo->blue_bits = format_bits( info, PIPE_FORMAT_COMP_B );
155 pinfo->alpha_bits = format_bits( info, PIPE_FORMAT_COMP_A );
156 pinfo->depth_bits = format_bits( info, PIPE_FORMAT_COMP_Z );
157 pinfo->stencil_bits = format_bits( info, PIPE_FORMAT_COMP_S );
158 pinfo->luminance_bits = 0;
159 pinfo->intensity_bits = 0;
160
161 /* Format size */
162 pinfo->size = format_size( info ) / 8;
163
164 /* Luminance & Intensity bits */
165 if( pf_swizzle_x(info) == PIPE_FORMAT_COMP_R &&
166 pf_swizzle_y(info) == PIPE_FORMAT_COMP_R &&
167 pf_swizzle_z(info) == PIPE_FORMAT_COMP_R ) {
168 if( pf_swizzle_w(info) == PIPE_FORMAT_COMP_R ) {
169 pinfo->intensity_bits = pinfo->red_bits;
170 }
171 else {
172 pinfo->luminance_bits = pinfo->red_bits;
173 }
174 pinfo->red_bits = 0;
175 }
176
177 /* Base format */
178 if (pinfo->depth_bits) {
179 if (pinfo->stencil_bits) {
180 pinfo->base_format = GL_DEPTH_STENCIL_EXT;
181 }
182 else {
183 pinfo->base_format = GL_DEPTH_COMPONENT;
184 }
185 }
186 else if (pinfo->stencil_bits) {
187 pinfo->base_format = GL_STENCIL_INDEX;
188 }
189 else {
190 pinfo->base_format = GL_RGBA;
191 }
192 }
193 else {
194 pipe_format_ycbcr_t info;
195
196 assert( pf_layout(format) == PIPE_FORMAT_LAYOUT_YCBCR );
197
198 info = format;
199
200 /* TODO */
201 assert( 0 );
202 }
203
204 #if 0
205 printf(
206 "ST_FORMAT: R(%u), G(%u), B(%u), A(%u), Z(%u), S(%u)\n",
207 pinfo->red_bits,
208 pinfo->green_bits,
209 pinfo->blue_bits,
210 pinfo->alpha_bits,
211 pinfo->depth_bits,
212 pinfo->stencil_bits );
213 #endif
214
215 pinfo->format = format;
216
217 return GL_TRUE;
218 }
219
220
221 /**
222 * Return bytes per pixel for the given format.
223 */
224 GLuint
225 st_sizeof_format(GLuint pipeFormat)
226 {
227 struct pipe_format_info info;
228 if (!st_get_format_info( pipeFormat, &info )) {
229 assert( 0 );
230 return 0;
231 }
232 return info.size;
233 }
234
235
236 /**
237 * Return bytes per pixel for the given format.
238 */
239 GLenum
240 st_format_datatype(GLuint pipeFormat)
241 {
242 struct pipe_format_info info;
243 if (!st_get_format_info( pipeFormat, &info )) {
244 assert( 0 );
245 return 0;
246 }
247 return info.datatype;
248 }
249
250
251 GLuint
252 st_mesa_format_to_pipe_format(GLuint mesaFormat)
253 {
254 switch (mesaFormat) {
255 /* fix this */
256 case MESA_FORMAT_ARGB8888_REV:
257 case MESA_FORMAT_ARGB8888:
258 return PIPE_FORMAT_U_A8_R8_G8_B8;
259 case MESA_FORMAT_ARGB4444:
260 return PIPE_FORMAT_U_A4_R4_G4_B4;
261 case MESA_FORMAT_AL88:
262 return PIPE_FORMAT_U_A8_L8;
263 case MESA_FORMAT_A8:
264 return PIPE_FORMAT_U_A8;
265 case MESA_FORMAT_L8:
266 return PIPE_FORMAT_U_L8;
267 case MESA_FORMAT_I8:
268 return PIPE_FORMAT_U_I8;
269 case MESA_FORMAT_Z16:
270 return PIPE_FORMAT_U_Z16;
271 default:
272 assert(0);
273 return 0;
274 }
275 }
276
277 /**
278 * Find an RGBA format supported by the context/winsys.
279 */
280 static GLuint
281 default_rgba_format(
282 struct pipe_context *pipe )
283 {
284 static const uint colorFormats[] = {
285 PIPE_FORMAT_U_R8_G8_B8_A8,
286 PIPE_FORMAT_U_A8_R8_G8_B8,
287 PIPE_FORMAT_U_B8_G8_R8_A8,
288 PIPE_FORMAT_U_R5_G6_B5
289 };
290 uint i;
291 for (i = 0; i < Elements(colorFormats); i++) {
292 if (pipe->is_format_supported( pipe, colorFormats[i] )) {
293 return colorFormats[i];
294 }
295 }
296 return PIPE_FORMAT_NONE;
297 }
298
299
300 /**
301 * Search list of formats for first RGBA format with >8 bits/channel.
302 */
303 static GLuint
304 default_deep_rgba_format(
305 struct pipe_context *pipe )
306 {
307 if (pipe->is_format_supported( pipe, PIPE_FORMAT_S_R16_G16_B16_A16 )) {
308 return PIPE_FORMAT_S_R16_G16_B16_A16;
309 }
310 return PIPE_FORMAT_NONE;
311 }
312
313
314 /**
315 * Find an Z format supported by the context/winsys.
316 */
317 static GLuint
318 default_depth_format(
319 struct pipe_context *pipe )
320 {
321 static const uint zFormats[] = {
322 PIPE_FORMAT_U_Z16,
323 PIPE_FORMAT_U_Z32,
324 PIPE_FORMAT_S8_Z24,
325 PIPE_FORMAT_Z24_S8
326 };
327 uint i;
328 for (i = 0; i < Elements(zFormats); i++) {
329 if (pipe->is_format_supported( pipe, zFormats[i] )) {
330 return zFormats[i];
331 }
332 }
333 return PIPE_FORMAT_NONE;
334 }
335
336
337 /**
338 * Choose the PIPE_FORMAT_ to use for storing a texture image based
339 * on the user's internalFormat, format and type parameters.
340 * We query the pipe device for a list of formats which it supports
341 * and choose from them.
342 * If we find a device that needs a more intricate selection mechanism,
343 * this function _could_ get pushed down into the pipe device.
344 *
345 * Note: also used for glRenderbufferStorageEXT()
346 *
347 * Note: format and type may be GL_NONE (see renderbuffers)
348 *
349 * \return PIPE_FORMAT_NONE if error/problem.
350 */
351 GLuint
352 st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat,
353 GLenum format, GLenum type)
354 {
355 switch (internalFormat) {
356 case 4:
357 case GL_RGBA:
358 case GL_COMPRESSED_RGBA:
359 if (format == GL_BGRA) {
360 if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) {
361 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_R8_G8_B8 ))
362 return PIPE_FORMAT_U_A8_R8_G8_B8;
363 }
364 else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
365 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A4_R4_G4_B4 ))
366 return PIPE_FORMAT_U_A4_R4_G4_B4;
367 }
368 else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
369 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 ))
370 return PIPE_FORMAT_U_A1_R5_G5_B5;
371 }
372 }
373 return default_rgba_format( pipe );
374
375 case 3:
376 case GL_RGB:
377 case GL_COMPRESSED_RGB:
378 if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
379 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_R5_G6_B5 ))
380 return PIPE_FORMAT_U_R5_G6_B5;
381 }
382 return default_rgba_format( pipe );
383
384 case GL_RGBA8:
385 case GL_RGB10_A2:
386 case GL_RGBA12:
387 return default_rgba_format( pipe );
388 case GL_RGBA16:
389 return default_deep_rgba_format( pipe );
390
391 case GL_RGBA4:
392 case GL_RGBA2:
393 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A4_R4_G4_B4 ))
394 return PIPE_FORMAT_U_A4_R4_G4_B4;
395 return default_rgba_format( pipe );
396
397 case GL_RGB5_A1:
398 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 ))
399 return PIPE_FORMAT_U_A1_R5_G5_B5;
400 return default_rgba_format( pipe );
401
402 case GL_RGB8:
403 case GL_RGB10:
404 case GL_RGB12:
405 case GL_RGB16:
406 return default_rgba_format( pipe );
407
408 case GL_RGB5:
409 case GL_RGB4:
410 case GL_R3_G3_B2:
411 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A1_R5_G5_B5 ))
412 return PIPE_FORMAT_U_A1_R5_G5_B5;
413 return default_rgba_format( pipe );
414
415 case GL_ALPHA:
416 case GL_ALPHA4:
417 case GL_ALPHA8:
418 case GL_ALPHA12:
419 case GL_ALPHA16:
420 case GL_COMPRESSED_ALPHA:
421 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8 ))
422 return PIPE_FORMAT_U_A8;
423 return default_rgba_format( pipe );
424
425 case 1:
426 case GL_LUMINANCE:
427 case GL_LUMINANCE4:
428 case GL_LUMINANCE8:
429 case GL_LUMINANCE12:
430 case GL_LUMINANCE16:
431 case GL_COMPRESSED_LUMINANCE:
432 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8 ))
433 return PIPE_FORMAT_U_A8;
434 return default_rgba_format( pipe );
435
436 case 2:
437 case GL_LUMINANCE_ALPHA:
438 case GL_LUMINANCE4_ALPHA4:
439 case GL_LUMINANCE6_ALPHA2:
440 case GL_LUMINANCE8_ALPHA8:
441 case GL_LUMINANCE12_ALPHA4:
442 case GL_LUMINANCE12_ALPHA12:
443 case GL_LUMINANCE16_ALPHA16:
444 case GL_COMPRESSED_LUMINANCE_ALPHA:
445 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_L8 ))
446 return PIPE_FORMAT_U_A8_L8;
447 return default_rgba_format( pipe );
448
449 case GL_INTENSITY:
450 case GL_INTENSITY4:
451 case GL_INTENSITY8:
452 case GL_INTENSITY12:
453 case GL_INTENSITY16:
454 case GL_COMPRESSED_INTENSITY:
455 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_I8 ))
456 return PIPE_FORMAT_U_I8;
457 return default_rgba_format( pipe );
458
459 case GL_YCBCR_MESA:
460 if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE) {
461 if (pipe->is_format_supported( pipe, PIPE_FORMAT_YCBCR ))
462 return PIPE_FORMAT_YCBCR;
463 }
464 else {
465 if (pipe->is_format_supported( pipe, PIPE_FORMAT_YCBCR_REV ))
466 return PIPE_FORMAT_YCBCR_REV;
467 }
468 return PIPE_FORMAT_NONE;
469
470 #if 0
471 case GL_COMPRESSED_RGB_FXT1_3DFX:
472 return &_mesa_texformat_rgb_fxt1;
473 case GL_COMPRESSED_RGBA_FXT1_3DFX:
474 return &_mesa_texformat_rgba_fxt1;
475
476 case GL_RGB_S3TC:
477 case GL_RGB4_S3TC:
478 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
479 return &_mesa_texformat_rgb_dxt1;
480
481 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
482 return &_mesa_texformat_rgba_dxt1;
483
484 case GL_RGBA_S3TC:
485 case GL_RGBA4_S3TC:
486 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
487 return &_mesa_texformat_rgba_dxt3;
488
489 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
490 return &_mesa_texformat_rgba_dxt5;
491 #endif
492
493 case GL_DEPTH_COMPONENT16:
494 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_Z16 ))
495 return PIPE_FORMAT_U_Z16;
496 /* fall-through */
497 case GL_DEPTH_COMPONENT24:
498 if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 ))
499 return PIPE_FORMAT_S8_Z24;
500 if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24_S8 ))
501 return PIPE_FORMAT_Z24_S8;
502 /* fall-through */
503 case GL_DEPTH_COMPONENT32:
504 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_Z32 ))
505 return PIPE_FORMAT_U_Z32;
506 /* fall-through */
507 case GL_DEPTH_COMPONENT:
508 return default_depth_format( pipe );
509
510 case GL_STENCIL_INDEX:
511 case GL_STENCIL_INDEX1_EXT:
512 case GL_STENCIL_INDEX4_EXT:
513 case GL_STENCIL_INDEX8_EXT:
514 case GL_STENCIL_INDEX16_EXT:
515 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_S8 ))
516 return PIPE_FORMAT_U_S8;
517 if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 ))
518 return PIPE_FORMAT_S8_Z24;
519 if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24_S8 ))
520 return PIPE_FORMAT_Z24_S8;
521 return PIPE_FORMAT_NONE;
522
523 case GL_DEPTH_STENCIL_EXT:
524 case GL_DEPTH24_STENCIL8_EXT:
525 if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8_Z24 ))
526 return PIPE_FORMAT_S8_Z24;
527 if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24_S8 ))
528 return PIPE_FORMAT_Z24_S8;
529 return PIPE_FORMAT_NONE;
530
531 default:
532 return PIPE_FORMAT_NONE;
533 }
534 }
535
536
537
538 /* It works out that this function is fine for all the supported
539 * hardware. However, there is still a need to map the formats onto
540 * hardware descriptors.
541 */
542 /* Note that the i915 can actually support many more formats than
543 * these if we take the step of simply swizzling the colors
544 * immediately after sampling...
545 */
546 const struct gl_texture_format *
547 st_ChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
548 GLenum format, GLenum type)
549 {
550 #if 0
551 struct intel_context *intel = intel_context(ctx);
552 const GLboolean do32bpt = (intel->intelScreen->front.cpp == 4);
553 #else
554 const GLboolean do32bpt = 1;
555 #endif
556
557 (void) ctx;
558
559 switch (internalFormat) {
560 case 4:
561 case GL_RGBA:
562 case GL_COMPRESSED_RGBA:
563 if (format == GL_BGRA) {
564 if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) {
565 return &_mesa_texformat_argb8888;
566 }
567 else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
568 return &_mesa_texformat_argb4444;
569 }
570 else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
571 return &_mesa_texformat_argb1555;
572 }
573 }
574 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
575
576 case 3:
577 case GL_RGB:
578 case GL_COMPRESSED_RGB:
579 if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
580 return &_mesa_texformat_rgb565;
581 }
582 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565;
583
584 case GL_RGBA8:
585 case GL_RGB10_A2:
586 case GL_RGBA12:
587 case GL_RGBA16:
588 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
589
590 case GL_RGBA4:
591 case GL_RGBA2:
592 return &_mesa_texformat_argb4444;
593
594 case GL_RGB5_A1:
595 return &_mesa_texformat_argb1555;
596
597 case GL_RGB8:
598 case GL_RGB10:
599 case GL_RGB12:
600 case GL_RGB16:
601 return &_mesa_texformat_argb8888;
602
603 case GL_RGB5:
604 case GL_RGB4:
605 case GL_R3_G3_B2:
606 return &_mesa_texformat_rgb565;
607
608 case GL_ALPHA:
609 case GL_ALPHA4:
610 case GL_ALPHA8:
611 case GL_ALPHA12:
612 case GL_ALPHA16:
613 case GL_COMPRESSED_ALPHA:
614 return &_mesa_texformat_a8;
615
616 case 1:
617 case GL_LUMINANCE:
618 case GL_LUMINANCE4:
619 case GL_LUMINANCE8:
620 case GL_LUMINANCE12:
621 case GL_LUMINANCE16:
622 case GL_COMPRESSED_LUMINANCE:
623 return &_mesa_texformat_l8;
624
625 case 2:
626 case GL_LUMINANCE_ALPHA:
627 case GL_LUMINANCE4_ALPHA4:
628 case GL_LUMINANCE6_ALPHA2:
629 case GL_LUMINANCE8_ALPHA8:
630 case GL_LUMINANCE12_ALPHA4:
631 case GL_LUMINANCE12_ALPHA12:
632 case GL_LUMINANCE16_ALPHA16:
633 case GL_COMPRESSED_LUMINANCE_ALPHA:
634 return &_mesa_texformat_al88;
635
636 case GL_INTENSITY:
637 case GL_INTENSITY4:
638 case GL_INTENSITY8:
639 case GL_INTENSITY12:
640 case GL_INTENSITY16:
641 case GL_COMPRESSED_INTENSITY:
642 return &_mesa_texformat_i8;
643
644 case GL_YCBCR_MESA:
645 if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE)
646 return &_mesa_texformat_ycbcr;
647 else
648 return &_mesa_texformat_ycbcr_rev;
649
650 case GL_COMPRESSED_RGB_FXT1_3DFX:
651 return &_mesa_texformat_rgb_fxt1;
652 case GL_COMPRESSED_RGBA_FXT1_3DFX:
653 return &_mesa_texformat_rgba_fxt1;
654
655 case GL_RGB_S3TC:
656 case GL_RGB4_S3TC:
657 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
658 return &_mesa_texformat_rgb_dxt1;
659
660 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
661 return &_mesa_texformat_rgba_dxt1;
662
663 case GL_RGBA_S3TC:
664 case GL_RGBA4_S3TC:
665 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
666 return &_mesa_texformat_rgba_dxt3;
667
668 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
669 return &_mesa_texformat_rgba_dxt5;
670
671 case GL_DEPTH_COMPONENT:
672 case GL_DEPTH_COMPONENT16:
673 case GL_DEPTH_COMPONENT24:
674 case GL_DEPTH_COMPONENT32:
675 return &_mesa_texformat_z16;
676
677 case GL_DEPTH_STENCIL_EXT:
678 case GL_DEPTH24_STENCIL8_EXT:
679 return &_mesa_texformat_z24_s8;
680
681 default:
682 fprintf(stderr, "unexpected texture format %s in %s\n",
683 _mesa_lookup_enum_by_nr(internalFormat), __FUNCTION__);
684 return NULL;
685 }
686
687 return NULL; /* never get here */
688 }