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