Add 'type' parameter to is_format_supported() to specify texture vs. drawing surface...
[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(enum pipe_format format, struct pipe_format_info *pinfo)
103 {
104 if (pf_layout(format) == PIPE_FORMAT_LAYOUT_RGBAZS) {
105 pipe_format_rgbazs_t info;
106
107 info = format;
108
109 #if 0
110 {
111 char fmtname[256];
112
113 pf_sprint_name( fmtname, format );
114 printf(
115 "%s\n",
116 fmtname );
117 }
118 #endif
119
120 /* Data type */
121 if (format == PIPE_FORMAT_A1R5G5B5_UNORM || format == PIPE_FORMAT_R5G6B5_UNORM) {
122 pinfo->datatype = GL_UNSIGNED_SHORT;
123 }
124 else {
125 GLuint size;
126
127 size = format_max_bits( info );
128 if (size == 8) {
129 if (pf_type(info) == PIPE_FORMAT_TYPE_UNORM)
130 pinfo->datatype = GL_UNSIGNED_BYTE;
131 else
132 pinfo->datatype = GL_BYTE;
133 }
134 else if (size == 16) {
135 if (pf_type(info) == PIPE_FORMAT_TYPE_UNORM)
136 pinfo->datatype = GL_UNSIGNED_SHORT;
137 else
138 pinfo->datatype = GL_SHORT;
139 }
140 else {
141 assert( size <= 32 );
142 if (pf_type(info) == PIPE_FORMAT_TYPE_UNORM)
143 pinfo->datatype = GL_UNSIGNED_INT;
144 else
145 pinfo->datatype = GL_INT;
146 }
147 }
148
149 /* Component bits */
150 pinfo->red_bits = format_bits( info, PIPE_FORMAT_COMP_R );
151 pinfo->green_bits = format_bits( info, PIPE_FORMAT_COMP_G );
152 pinfo->blue_bits = format_bits( info, PIPE_FORMAT_COMP_B );
153 pinfo->alpha_bits = format_bits( info, PIPE_FORMAT_COMP_A );
154 pinfo->depth_bits = format_bits( info, PIPE_FORMAT_COMP_Z );
155 pinfo->stencil_bits = format_bits( info, PIPE_FORMAT_COMP_S );
156 pinfo->luminance_bits = 0;
157 pinfo->intensity_bits = 0;
158
159 /* Format size */
160 pinfo->size = format_size( info ) / 8;
161
162 /* Luminance & Intensity bits */
163 if( pf_swizzle_x(info) == PIPE_FORMAT_COMP_R &&
164 pf_swizzle_y(info) == PIPE_FORMAT_COMP_R &&
165 pf_swizzle_z(info) == PIPE_FORMAT_COMP_R ) {
166 if( pf_swizzle_w(info) == PIPE_FORMAT_COMP_R ) {
167 pinfo->intensity_bits = pinfo->red_bits;
168 }
169 else {
170 pinfo->luminance_bits = pinfo->red_bits;
171 }
172 pinfo->red_bits = 0;
173 }
174
175 /* Base format */
176 if (pinfo->depth_bits) {
177 if (pinfo->stencil_bits) {
178 pinfo->base_format = GL_DEPTH_STENCIL_EXT;
179 }
180 else {
181 pinfo->base_format = GL_DEPTH_COMPONENT;
182 }
183 }
184 else if (pinfo->stencil_bits) {
185 pinfo->base_format = GL_STENCIL_INDEX;
186 }
187 else {
188 pinfo->base_format = GL_RGBA;
189 }
190 }
191 else {
192 pipe_format_ycbcr_t info;
193
194 assert( pf_layout(format) == PIPE_FORMAT_LAYOUT_YCBCR );
195
196 info = format;
197
198 /* TODO */
199 assert( 0 );
200 }
201
202 #if 0
203 printf(
204 "ST_FORMAT: R(%u), G(%u), B(%u), A(%u), Z(%u), S(%u)\n",
205 pinfo->red_bits,
206 pinfo->green_bits,
207 pinfo->blue_bits,
208 pinfo->alpha_bits,
209 pinfo->depth_bits,
210 pinfo->stencil_bits );
211 #endif
212
213 pinfo->format = format;
214
215 return GL_TRUE;
216 }
217
218
219 /**
220 * Return bytes per pixel for the given format.
221 */
222 GLuint
223 st_sizeof_format(enum pipe_format format)
224 {
225 struct pipe_format_info info;
226 if (!st_get_format_info( format, &info )) {
227 assert( 0 );
228 return 0;
229 }
230 return info.size;
231 }
232
233
234 /**
235 * Return bytes per pixel for the given format.
236 */
237 GLenum
238 st_format_datatype(enum pipe_format format)
239 {
240 struct pipe_format_info info;
241 if (!st_get_format_info( format, &info )) {
242 assert( 0 );
243 return 0;
244 }
245 return info.datatype;
246 }
247
248
249 enum pipe_format
250 st_mesa_format_to_pipe_format(GLuint mesaFormat)
251 {
252 switch (mesaFormat) {
253 /* fix this */
254 case MESA_FORMAT_ARGB8888_REV:
255 case MESA_FORMAT_ARGB8888:
256 return PIPE_FORMAT_A8R8G8B8_UNORM;
257 case MESA_FORMAT_ARGB4444:
258 return PIPE_FORMAT_A4R4G4B4_UNORM;
259 case MESA_FORMAT_AL88:
260 return PIPE_FORMAT_U_A8_L8;
261 case MESA_FORMAT_A8:
262 return PIPE_FORMAT_U_A8;
263 case MESA_FORMAT_L8:
264 return PIPE_FORMAT_U_L8;
265 case MESA_FORMAT_I8:
266 return PIPE_FORMAT_U_I8;
267 case MESA_FORMAT_Z16:
268 return PIPE_FORMAT_Z16_UNORM;
269 default:
270 assert(0);
271 return 0;
272 }
273 }
274
275 /**
276 * Find an RGBA format supported by the context/winsys.
277 */
278 static GLuint
279 default_rgba_format(struct pipe_context *pipe, uint type)
280 {
281 static const enum pipe_format colorFormats[] = {
282 PIPE_FORMAT_R8G8B8A8_UNORM,
283 PIPE_FORMAT_A8R8G8B8_UNORM,
284 PIPE_FORMAT_B8G8R8A8_UNORM,
285 PIPE_FORMAT_R5G6B5_UNORM
286 };
287 uint i;
288 for (i = 0; i < Elements(colorFormats); i++) {
289 if (pipe->is_format_supported( pipe, colorFormats[i], type )) {
290 return colorFormats[i];
291 }
292 }
293 return PIPE_FORMAT_NONE;
294 }
295
296
297 /**
298 * Search list of formats for first RGBA format with >8 bits/channel.
299 */
300 static GLuint
301 default_deep_rgba_format(struct pipe_context *pipe, uint type)
302 {
303 if (pipe->is_format_supported(pipe, PIPE_FORMAT_R16G16B16A16_SNORM, type)) {
304 return PIPE_FORMAT_R16G16B16A16_SNORM;
305 }
306 return PIPE_FORMAT_NONE;
307 }
308
309
310 /**
311 * Find an Z format supported by the context/winsys.
312 */
313 static GLuint
314 default_depth_format(struct pipe_context *pipe, uint type)
315 {
316 static const enum pipe_format zFormats[] = {
317 PIPE_FORMAT_Z16_UNORM,
318 PIPE_FORMAT_Z32_UNORM,
319 PIPE_FORMAT_S8Z24_UNORM,
320 PIPE_FORMAT_Z24S8_UNORM
321 };
322 uint i;
323 for (i = 0; i < Elements(zFormats); i++) {
324 if (pipe->is_format_supported( pipe, zFormats[i], type )) {
325 return zFormats[i];
326 }
327 }
328 return PIPE_FORMAT_NONE;
329 }
330
331
332 /**
333 * Choose the PIPE_FORMAT_ to use for storing a texture image based
334 * on the user's internalFormat, format and type parameters.
335 * We query the pipe device for a list of formats which it supports
336 * and choose from them.
337 * If we find a device that needs a more intricate selection mechanism,
338 * this function _could_ get pushed down into the pipe device.
339 *
340 * Note: also used for glRenderbufferStorageEXT()
341 *
342 * Note: format and type may be GL_NONE (see renderbuffers)
343 *
344 * \return PIPE_FORMAT_NONE if error/problem.
345 */
346 GLuint
347 st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat,
348 GLenum format, GLenum type, uint surfType)
349 {
350 assert(surfType == PIPE_TEXTURE ||
351 surfType == PIPE_SURFACE ||
352 surfType == PIPE_SCREEN_SURFACE);
353
354 switch (internalFormat) {
355 case 4:
356 case GL_RGBA:
357 case GL_COMPRESSED_RGBA:
358 if (format == GL_BGRA) {
359 if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) {
360 if (pipe->is_format_supported( pipe, PIPE_FORMAT_A8R8G8B8_UNORM, surfType ))
361 return PIPE_FORMAT_A8R8G8B8_UNORM;
362 }
363 else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
364 if (pipe->is_format_supported( pipe, PIPE_FORMAT_A4R4G4B4_UNORM, surfType ))
365 return PIPE_FORMAT_A4R4G4B4_UNORM;
366 }
367 else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
368 if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM, surfType ))
369 return PIPE_FORMAT_A1R5G5B5_UNORM;
370 }
371 }
372 return default_rgba_format( pipe, surfType );
373
374 case 3:
375 case GL_RGB:
376 case GL_COMPRESSED_RGB:
377 if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
378 if (pipe->is_format_supported( pipe, PIPE_FORMAT_R5G6B5_UNORM, surfType ))
379 return PIPE_FORMAT_R5G6B5_UNORM;
380 }
381 return default_rgba_format( pipe, surfType );
382
383 case GL_RGBA8:
384 case GL_RGB10_A2:
385 case GL_RGBA12:
386 return default_rgba_format( pipe, surfType );
387 case GL_RGBA16:
388 return default_deep_rgba_format( pipe, surfType );
389
390 case GL_RGBA4:
391 case GL_RGBA2:
392 if (pipe->is_format_supported( pipe, PIPE_FORMAT_A4R4G4B4_UNORM, surfType ))
393 return PIPE_FORMAT_A4R4G4B4_UNORM;
394 return default_rgba_format( pipe, surfType );
395
396 case GL_RGB5_A1:
397 if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM, surfType ))
398 return PIPE_FORMAT_A1R5G5B5_UNORM;
399 return default_rgba_format( pipe, surfType );
400
401 case GL_RGB8:
402 case GL_RGB10:
403 case GL_RGB12:
404 case GL_RGB16:
405 return default_rgba_format( pipe, surfType );
406
407 case GL_RGB5:
408 case GL_RGB4:
409 case GL_R3_G3_B2:
410 if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM, surfType ))
411 return PIPE_FORMAT_A1R5G5B5_UNORM;
412 return default_rgba_format( pipe, surfType );
413
414 case GL_ALPHA:
415 case GL_ALPHA4:
416 case GL_ALPHA8:
417 case GL_ALPHA12:
418 case GL_ALPHA16:
419 case GL_COMPRESSED_ALPHA:
420 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8, surfType ))
421 return PIPE_FORMAT_U_A8;
422 return default_rgba_format( pipe, surfType );
423
424 case 1:
425 case GL_LUMINANCE:
426 case GL_LUMINANCE4:
427 case GL_LUMINANCE8:
428 case GL_LUMINANCE12:
429 case GL_LUMINANCE16:
430 case GL_COMPRESSED_LUMINANCE:
431 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8, surfType ))
432 return PIPE_FORMAT_U_A8;
433 return default_rgba_format( pipe, surfType );
434
435 case 2:
436 case GL_LUMINANCE_ALPHA:
437 case GL_LUMINANCE4_ALPHA4:
438 case GL_LUMINANCE6_ALPHA2:
439 case GL_LUMINANCE8_ALPHA8:
440 case GL_LUMINANCE12_ALPHA4:
441 case GL_LUMINANCE12_ALPHA12:
442 case GL_LUMINANCE16_ALPHA16:
443 case GL_COMPRESSED_LUMINANCE_ALPHA:
444 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_L8, surfType ))
445 return PIPE_FORMAT_U_A8_L8;
446 return default_rgba_format( pipe, surfType );
447
448 case GL_INTENSITY:
449 case GL_INTENSITY4:
450 case GL_INTENSITY8:
451 case GL_INTENSITY12:
452 case GL_INTENSITY16:
453 case GL_COMPRESSED_INTENSITY:
454 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_I8, surfType ))
455 return PIPE_FORMAT_U_I8;
456 return default_rgba_format( pipe, surfType );
457
458 case GL_YCBCR_MESA:
459 if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE) {
460 if (pipe->is_format_supported( pipe, PIPE_FORMAT_YCBCR, surfType ))
461 return PIPE_FORMAT_YCBCR;
462 }
463 else {
464 if (pipe->is_format_supported( pipe, PIPE_FORMAT_YCBCR_REV, surfType ))
465 return PIPE_FORMAT_YCBCR_REV;
466 }
467 return PIPE_FORMAT_NONE;
468
469 #if 0
470 case GL_COMPRESSED_RGB_FXT1_3DFX:
471 return &_mesa_texformat_rgb_fxt1;
472 case GL_COMPRESSED_RGBA_FXT1_3DFX:
473 return &_mesa_texformat_rgba_fxt1;
474
475 case GL_RGB_S3TC:
476 case GL_RGB4_S3TC:
477 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
478 return &_mesa_texformat_rgb_dxt1;
479
480 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
481 return &_mesa_texformat_rgba_dxt1;
482
483 case GL_RGBA_S3TC:
484 case GL_RGBA4_S3TC:
485 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
486 return &_mesa_texformat_rgba_dxt3;
487
488 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
489 return &_mesa_texformat_rgba_dxt5;
490 #endif
491
492 case GL_DEPTH_COMPONENT16:
493 if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z16_UNORM, surfType ))
494 return PIPE_FORMAT_Z16_UNORM;
495 /* fall-through */
496 case GL_DEPTH_COMPONENT24:
497 if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM, surfType ))
498 return PIPE_FORMAT_S8Z24_UNORM;
499 if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM, surfType ))
500 return PIPE_FORMAT_Z24S8_UNORM;
501 /* fall-through */
502 case GL_DEPTH_COMPONENT32:
503 if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z32_UNORM, surfType ))
504 return PIPE_FORMAT_Z32_UNORM;
505 /* fall-through */
506 case GL_DEPTH_COMPONENT:
507 return default_depth_format( pipe, surfType );
508
509 case GL_STENCIL_INDEX:
510 case GL_STENCIL_INDEX1_EXT:
511 case GL_STENCIL_INDEX4_EXT:
512 case GL_STENCIL_INDEX8_EXT:
513 case GL_STENCIL_INDEX16_EXT:
514 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_S8, surfType ))
515 return PIPE_FORMAT_U_S8;
516 if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM, surfType ))
517 return PIPE_FORMAT_S8Z24_UNORM;
518 if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM, surfType ))
519 return PIPE_FORMAT_Z24S8_UNORM;
520 return PIPE_FORMAT_NONE;
521
522 case GL_DEPTH_STENCIL_EXT:
523 case GL_DEPTH24_STENCIL8_EXT:
524 if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM, surfType ))
525 return PIPE_FORMAT_S8Z24_UNORM;
526 if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM, surfType ))
527 return PIPE_FORMAT_Z24S8_UNORM;
528 return PIPE_FORMAT_NONE;
529
530 default:
531 return PIPE_FORMAT_NONE;
532 }
533 }
534
535
536
537 /* It works out that this function is fine for all the supported
538 * hardware. However, there is still a need to map the formats onto
539 * hardware descriptors.
540 */
541 /* Note that the i915 can actually support many more formats than
542 * these if we take the step of simply swizzling the colors
543 * immediately after sampling...
544 */
545 const struct gl_texture_format *
546 st_ChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
547 GLenum format, GLenum type)
548 {
549 #if 0
550 struct intel_context *intel = intel_context(ctx);
551 const GLboolean do32bpt = (intel->intelScreen->front.cpp == 4);
552 #else
553 const GLboolean do32bpt = 1;
554 #endif
555
556 (void) ctx;
557
558 switch (internalFormat) {
559 case 4:
560 case GL_RGBA:
561 case GL_COMPRESSED_RGBA:
562 if (format == GL_BGRA) {
563 if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) {
564 return &_mesa_texformat_argb8888;
565 }
566 else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
567 return &_mesa_texformat_argb4444;
568 }
569 else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
570 return &_mesa_texformat_argb1555;
571 }
572 }
573 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
574
575 case 3:
576 case GL_RGB:
577 case GL_COMPRESSED_RGB:
578 if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
579 return &_mesa_texformat_rgb565;
580 }
581 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565;
582
583 case GL_RGBA8:
584 case GL_RGB10_A2:
585 case GL_RGBA12:
586 case GL_RGBA16:
587 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
588
589 case GL_RGBA4:
590 case GL_RGBA2:
591 return &_mesa_texformat_argb4444;
592
593 case GL_RGB5_A1:
594 return &_mesa_texformat_argb1555;
595
596 case GL_RGB8:
597 case GL_RGB10:
598 case GL_RGB12:
599 case GL_RGB16:
600 return &_mesa_texformat_argb8888;
601
602 case GL_RGB5:
603 case GL_RGB4:
604 case GL_R3_G3_B2:
605 return &_mesa_texformat_rgb565;
606
607 case GL_ALPHA:
608 case GL_ALPHA4:
609 case GL_ALPHA8:
610 case GL_ALPHA12:
611 case GL_ALPHA16:
612 case GL_COMPRESSED_ALPHA:
613 return &_mesa_texformat_a8;
614
615 case 1:
616 case GL_LUMINANCE:
617 case GL_LUMINANCE4:
618 case GL_LUMINANCE8:
619 case GL_LUMINANCE12:
620 case GL_LUMINANCE16:
621 case GL_COMPRESSED_LUMINANCE:
622 return &_mesa_texformat_l8;
623
624 case 2:
625 case GL_LUMINANCE_ALPHA:
626 case GL_LUMINANCE4_ALPHA4:
627 case GL_LUMINANCE6_ALPHA2:
628 case GL_LUMINANCE8_ALPHA8:
629 case GL_LUMINANCE12_ALPHA4:
630 case GL_LUMINANCE12_ALPHA12:
631 case GL_LUMINANCE16_ALPHA16:
632 case GL_COMPRESSED_LUMINANCE_ALPHA:
633 return &_mesa_texformat_al88;
634
635 case GL_INTENSITY:
636 case GL_INTENSITY4:
637 case GL_INTENSITY8:
638 case GL_INTENSITY12:
639 case GL_INTENSITY16:
640 case GL_COMPRESSED_INTENSITY:
641 return &_mesa_texformat_i8;
642
643 case GL_YCBCR_MESA:
644 if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE)
645 return &_mesa_texformat_ycbcr;
646 else
647 return &_mesa_texformat_ycbcr_rev;
648
649 case GL_COMPRESSED_RGB_FXT1_3DFX:
650 return &_mesa_texformat_rgb_fxt1;
651 case GL_COMPRESSED_RGBA_FXT1_3DFX:
652 return &_mesa_texformat_rgba_fxt1;
653
654 case GL_RGB_S3TC:
655 case GL_RGB4_S3TC:
656 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
657 return &_mesa_texformat_rgb_dxt1;
658
659 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
660 return &_mesa_texformat_rgba_dxt1;
661
662 case GL_RGBA_S3TC:
663 case GL_RGBA4_S3TC:
664 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
665 return &_mesa_texformat_rgba_dxt3;
666
667 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
668 return &_mesa_texformat_rgba_dxt5;
669
670 case GL_DEPTH_COMPONENT:
671 case GL_DEPTH_COMPONENT16:
672 case GL_DEPTH_COMPONENT24:
673 case GL_DEPTH_COMPONENT32:
674 return &_mesa_texformat_z16;
675
676 case GL_DEPTH_STENCIL_EXT:
677 case GL_DEPTH24_STENCIL8_EXT:
678 return &_mesa_texformat_z24_s8;
679
680 default:
681 fprintf(stderr, "unexpected texture format %s in %s\n",
682 _mesa_lookup_enum_by_nr(internalFormat), __FUNCTION__);
683 return NULL;
684 }
685
686 return NULL; /* never get here */
687 }