softpipe: Support for PIPE_FORMAT_A4R4G4B4_UNORM and PIPE_FORMAT_R5G6B5_UNORM.
[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_ARGB1555:
258 return PIPE_FORMAT_A1R5G5B5_UNORM;
259 case MESA_FORMAT_ARGB4444:
260 return PIPE_FORMAT_A4R4G4B4_UNORM;
261 case MESA_FORMAT_RGB565:
262 return PIPE_FORMAT_R5G6B5_UNORM;
263 case MESA_FORMAT_AL88:
264 return PIPE_FORMAT_U_A8_L8;
265 case MESA_FORMAT_A8:
266 return PIPE_FORMAT_U_A8;
267 case MESA_FORMAT_L8:
268 return PIPE_FORMAT_U_L8;
269 case MESA_FORMAT_I8:
270 return PIPE_FORMAT_U_I8;
271 case MESA_FORMAT_Z16:
272 return PIPE_FORMAT_Z16_UNORM;
273 default:
274 assert(0);
275 return 0;
276 }
277 }
278
279 /**
280 * Find an RGBA format supported by the context/winsys.
281 */
282 static GLuint
283 default_rgba_format(struct pipe_context *pipe, uint type)
284 {
285 static const enum pipe_format colorFormats[] = {
286 PIPE_FORMAT_R8G8B8A8_UNORM,
287 PIPE_FORMAT_A8R8G8B8_UNORM,
288 PIPE_FORMAT_B8G8R8A8_UNORM,
289 PIPE_FORMAT_R5G6B5_UNORM
290 };
291 uint i;
292 for (i = 0; i < Elements(colorFormats); i++) {
293 if (pipe->is_format_supported( pipe, colorFormats[i], type )) {
294 return colorFormats[i];
295 }
296 }
297 return PIPE_FORMAT_NONE;
298 }
299
300
301 /**
302 * Search list of formats for first RGBA format with >8 bits/channel.
303 */
304 static GLuint
305 default_deep_rgba_format(struct pipe_context *pipe, uint type)
306 {
307 if (pipe->is_format_supported(pipe, PIPE_FORMAT_R16G16B16A16_SNORM, type)) {
308 return PIPE_FORMAT_R16G16B16A16_SNORM;
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(struct pipe_context *pipe, uint type)
319 {
320 static const enum pipe_format zFormats[] = {
321 PIPE_FORMAT_Z16_UNORM,
322 PIPE_FORMAT_Z32_UNORM,
323 PIPE_FORMAT_S8Z24_UNORM,
324 PIPE_FORMAT_Z24S8_UNORM
325 };
326 uint i;
327 for (i = 0; i < Elements(zFormats); i++) {
328 if (pipe->is_format_supported( pipe, zFormats[i], type )) {
329 return zFormats[i];
330 }
331 }
332 return PIPE_FORMAT_NONE;
333 }
334
335
336 /**
337 * Choose the PIPE_FORMAT_ to use for storing a texture image based
338 * on the user's internalFormat, format and type parameters.
339 * We query the pipe device for a list of formats which it supports
340 * and choose from them.
341 * If we find a device that needs a more intricate selection mechanism,
342 * this function _could_ get pushed down into the pipe device.
343 *
344 * Note: also used for glRenderbufferStorageEXT()
345 *
346 * Note: format and type may be GL_NONE (see renderbuffers)
347 *
348 * \return PIPE_FORMAT_NONE if error/problem.
349 */
350 GLuint
351 st_choose_pipe_format(struct pipe_context *pipe, GLint internalFormat,
352 GLenum format, GLenum type, uint surfType)
353 {
354 assert(surfType == PIPE_TEXTURE ||
355 surfType == PIPE_SURFACE ||
356 surfType == PIPE_SCREEN_SURFACE);
357
358 switch (internalFormat) {
359 case 4:
360 case GL_RGBA:
361 case GL_COMPRESSED_RGBA:
362 if (format == GL_BGRA) {
363 if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) {
364 if (pipe->is_format_supported( pipe, PIPE_FORMAT_A8R8G8B8_UNORM, surfType ))
365 return PIPE_FORMAT_A8R8G8B8_UNORM;
366 }
367 else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
368 if (pipe->is_format_supported( pipe, PIPE_FORMAT_A4R4G4B4_UNORM, surfType ))
369 return PIPE_FORMAT_A4R4G4B4_UNORM;
370 }
371 else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
372 if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM, surfType ))
373 return PIPE_FORMAT_A1R5G5B5_UNORM;
374 }
375 }
376 return default_rgba_format( pipe, surfType );
377
378 case 3:
379 case GL_RGB:
380 case GL_COMPRESSED_RGB:
381 if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
382 if (pipe->is_format_supported( pipe, PIPE_FORMAT_R5G6B5_UNORM, surfType ))
383 return PIPE_FORMAT_R5G6B5_UNORM;
384 }
385 return default_rgba_format( pipe, surfType );
386
387 case GL_RGBA8:
388 case GL_RGB10_A2:
389 case GL_RGBA12:
390 return default_rgba_format( pipe, surfType );
391 case GL_RGBA16:
392 return default_deep_rgba_format( pipe, surfType );
393
394 case GL_RGBA4:
395 case GL_RGBA2:
396 if (pipe->is_format_supported( pipe, PIPE_FORMAT_A4R4G4B4_UNORM, surfType ))
397 return PIPE_FORMAT_A4R4G4B4_UNORM;
398 return default_rgba_format( pipe, surfType );
399
400 case GL_RGB5_A1:
401 if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM, surfType ))
402 return PIPE_FORMAT_A1R5G5B5_UNORM;
403 return default_rgba_format( pipe, surfType );
404
405 case GL_RGB8:
406 case GL_RGB10:
407 case GL_RGB12:
408 case GL_RGB16:
409 return default_rgba_format( pipe, surfType );
410
411 case GL_RGB5:
412 case GL_RGB4:
413 case GL_R3_G3_B2:
414 if (pipe->is_format_supported( pipe, PIPE_FORMAT_A1R5G5B5_UNORM, surfType ))
415 return PIPE_FORMAT_A1R5G5B5_UNORM;
416 return default_rgba_format( pipe, surfType );
417
418 case GL_ALPHA:
419 case GL_ALPHA4:
420 case GL_ALPHA8:
421 case GL_ALPHA12:
422 case GL_ALPHA16:
423 case GL_COMPRESSED_ALPHA:
424 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8, surfType ))
425 return PIPE_FORMAT_U_A8;
426 return default_rgba_format( pipe, surfType );
427
428 case 1:
429 case GL_LUMINANCE:
430 case GL_LUMINANCE4:
431 case GL_LUMINANCE8:
432 case GL_LUMINANCE12:
433 case GL_LUMINANCE16:
434 case GL_COMPRESSED_LUMINANCE:
435 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8, surfType ))
436 return PIPE_FORMAT_U_A8;
437 return default_rgba_format( pipe, surfType );
438
439 case 2:
440 case GL_LUMINANCE_ALPHA:
441 case GL_LUMINANCE4_ALPHA4:
442 case GL_LUMINANCE6_ALPHA2:
443 case GL_LUMINANCE8_ALPHA8:
444 case GL_LUMINANCE12_ALPHA4:
445 case GL_LUMINANCE12_ALPHA12:
446 case GL_LUMINANCE16_ALPHA16:
447 case GL_COMPRESSED_LUMINANCE_ALPHA:
448 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_A8_L8, surfType ))
449 return PIPE_FORMAT_U_A8_L8;
450 return default_rgba_format( pipe, surfType );
451
452 case GL_INTENSITY:
453 case GL_INTENSITY4:
454 case GL_INTENSITY8:
455 case GL_INTENSITY12:
456 case GL_INTENSITY16:
457 case GL_COMPRESSED_INTENSITY:
458 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_I8, surfType ))
459 return PIPE_FORMAT_U_I8;
460 return default_rgba_format( pipe, surfType );
461
462 case GL_YCBCR_MESA:
463 if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE) {
464 if (pipe->is_format_supported( pipe, PIPE_FORMAT_YCBCR, surfType ))
465 return PIPE_FORMAT_YCBCR;
466 }
467 else {
468 if (pipe->is_format_supported( pipe, PIPE_FORMAT_YCBCR_REV, surfType ))
469 return PIPE_FORMAT_YCBCR_REV;
470 }
471 return PIPE_FORMAT_NONE;
472
473 #if 0
474 case GL_COMPRESSED_RGB_FXT1_3DFX:
475 return &_mesa_texformat_rgb_fxt1;
476 case GL_COMPRESSED_RGBA_FXT1_3DFX:
477 return &_mesa_texformat_rgba_fxt1;
478
479 case GL_RGB_S3TC:
480 case GL_RGB4_S3TC:
481 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
482 return &_mesa_texformat_rgb_dxt1;
483
484 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
485 return &_mesa_texformat_rgba_dxt1;
486
487 case GL_RGBA_S3TC:
488 case GL_RGBA4_S3TC:
489 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
490 return &_mesa_texformat_rgba_dxt3;
491
492 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
493 return &_mesa_texformat_rgba_dxt5;
494 #endif
495
496 case GL_DEPTH_COMPONENT16:
497 if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z16_UNORM, surfType ))
498 return PIPE_FORMAT_Z16_UNORM;
499 /* fall-through */
500 case GL_DEPTH_COMPONENT24:
501 if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM, surfType ))
502 return PIPE_FORMAT_S8Z24_UNORM;
503 if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM, surfType ))
504 return PIPE_FORMAT_Z24S8_UNORM;
505 /* fall-through */
506 case GL_DEPTH_COMPONENT32:
507 if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z32_UNORM, surfType ))
508 return PIPE_FORMAT_Z32_UNORM;
509 /* fall-through */
510 case GL_DEPTH_COMPONENT:
511 return default_depth_format( pipe, surfType );
512
513 case GL_STENCIL_INDEX:
514 case GL_STENCIL_INDEX1_EXT:
515 case GL_STENCIL_INDEX4_EXT:
516 case GL_STENCIL_INDEX8_EXT:
517 case GL_STENCIL_INDEX16_EXT:
518 if (pipe->is_format_supported( pipe, PIPE_FORMAT_U_S8, surfType ))
519 return PIPE_FORMAT_U_S8;
520 if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM, surfType ))
521 return PIPE_FORMAT_S8Z24_UNORM;
522 if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM, surfType ))
523 return PIPE_FORMAT_Z24S8_UNORM;
524 return PIPE_FORMAT_NONE;
525
526 case GL_DEPTH_STENCIL_EXT:
527 case GL_DEPTH24_STENCIL8_EXT:
528 if (pipe->is_format_supported( pipe, PIPE_FORMAT_S8Z24_UNORM, surfType ))
529 return PIPE_FORMAT_S8Z24_UNORM;
530 if (pipe->is_format_supported( pipe, PIPE_FORMAT_Z24S8_UNORM, surfType ))
531 return PIPE_FORMAT_Z24S8_UNORM;
532 return PIPE_FORMAT_NONE;
533
534 default:
535 return PIPE_FORMAT_NONE;
536 }
537 }
538
539
540
541 /* It works out that this function is fine for all the supported
542 * hardware. However, there is still a need to map the formats onto
543 * hardware descriptors.
544 */
545 /* Note that the i915 can actually support many more formats than
546 * these if we take the step of simply swizzling the colors
547 * immediately after sampling...
548 */
549 const struct gl_texture_format *
550 st_ChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
551 GLenum format, GLenum type)
552 {
553 #if 0
554 struct intel_context *intel = intel_context(ctx);
555 const GLboolean do32bpt = (intel->intelScreen->front.cpp == 4);
556 #else
557 const GLboolean do32bpt = 1;
558 #endif
559
560 (void) ctx;
561
562 switch (internalFormat) {
563 case 4:
564 case GL_RGBA:
565 case GL_COMPRESSED_RGBA:
566 if (format == GL_BGRA) {
567 if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) {
568 return &_mesa_texformat_argb8888;
569 }
570 else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
571 return &_mesa_texformat_argb4444;
572 }
573 else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
574 return &_mesa_texformat_argb1555;
575 }
576 }
577 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
578
579 case 3:
580 case GL_RGB:
581 case GL_COMPRESSED_RGB:
582 if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
583 return &_mesa_texformat_rgb565;
584 }
585 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565;
586
587 case GL_RGBA8:
588 case GL_RGB10_A2:
589 case GL_RGBA12:
590 case GL_RGBA16:
591 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
592
593 case GL_RGBA4:
594 case GL_RGBA2:
595 return &_mesa_texformat_argb4444;
596
597 case GL_RGB5_A1:
598 return &_mesa_texformat_argb1555;
599
600 case GL_RGB8:
601 case GL_RGB10:
602 case GL_RGB12:
603 case GL_RGB16:
604 return &_mesa_texformat_argb8888;
605
606 case GL_RGB5:
607 case GL_RGB4:
608 case GL_R3_G3_B2:
609 return &_mesa_texformat_rgb565;
610
611 case GL_ALPHA:
612 case GL_ALPHA4:
613 case GL_ALPHA8:
614 case GL_ALPHA12:
615 case GL_ALPHA16:
616 case GL_COMPRESSED_ALPHA:
617 return &_mesa_texformat_a8;
618
619 case 1:
620 case GL_LUMINANCE:
621 case GL_LUMINANCE4:
622 case GL_LUMINANCE8:
623 case GL_LUMINANCE12:
624 case GL_LUMINANCE16:
625 case GL_COMPRESSED_LUMINANCE:
626 return &_mesa_texformat_l8;
627
628 case 2:
629 case GL_LUMINANCE_ALPHA:
630 case GL_LUMINANCE4_ALPHA4:
631 case GL_LUMINANCE6_ALPHA2:
632 case GL_LUMINANCE8_ALPHA8:
633 case GL_LUMINANCE12_ALPHA4:
634 case GL_LUMINANCE12_ALPHA12:
635 case GL_LUMINANCE16_ALPHA16:
636 case GL_COMPRESSED_LUMINANCE_ALPHA:
637 return &_mesa_texformat_al88;
638
639 case GL_INTENSITY:
640 case GL_INTENSITY4:
641 case GL_INTENSITY8:
642 case GL_INTENSITY12:
643 case GL_INTENSITY16:
644 case GL_COMPRESSED_INTENSITY:
645 return &_mesa_texformat_i8;
646
647 case GL_YCBCR_MESA:
648 if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE)
649 return &_mesa_texformat_ycbcr;
650 else
651 return &_mesa_texformat_ycbcr_rev;
652
653 case GL_COMPRESSED_RGB_FXT1_3DFX:
654 return &_mesa_texformat_rgb_fxt1;
655 case GL_COMPRESSED_RGBA_FXT1_3DFX:
656 return &_mesa_texformat_rgba_fxt1;
657
658 case GL_RGB_S3TC:
659 case GL_RGB4_S3TC:
660 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
661 return &_mesa_texformat_rgb_dxt1;
662
663 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
664 return &_mesa_texformat_rgba_dxt1;
665
666 case GL_RGBA_S3TC:
667 case GL_RGBA4_S3TC:
668 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
669 return &_mesa_texformat_rgba_dxt3;
670
671 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
672 return &_mesa_texformat_rgba_dxt5;
673
674 case GL_DEPTH_COMPONENT:
675 case GL_DEPTH_COMPONENT16:
676 case GL_DEPTH_COMPONENT24:
677 case GL_DEPTH_COMPONENT32:
678 return &_mesa_texformat_z16;
679
680 case GL_DEPTH_STENCIL_EXT:
681 case GL_DEPTH24_STENCIL8_EXT:
682 return &_mesa_texformat_z24_s8;
683
684 default:
685 fprintf(stderr, "unexpected texture format %s in %s\n",
686 _mesa_lookup_enum_by_nr(internalFormat), __FUNCTION__);
687 return NULL;
688 }
689
690 return NULL; /* never get here */
691 }