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