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