60b2065a6c898e252f564fbf7656f9367555b122
[mesa.git] / src / mesa / main / texformat.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.1
4 *
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008 VMware, Inc.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions 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 MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /**
28 * \file texformat.c
29 * Texture formats.
30 *
31 * \author Gareth Hughes
32 */
33
34
35 #include "colormac.h"
36 #include "context.h"
37 #include "texcompress.h"
38 #include "texcompress_fxt1.h"
39 #include "texcompress_s3tc.h"
40 #include "texformat.h"
41 #include "texstore.h"
42
43
44 #if FEATURE_EXT_texture_sRGB
45
46 /**
47 * Convert an 8-bit sRGB value from non-linear space to a
48 * linear RGB value in [0, 1].
49 * Implemented with a 256-entry lookup table.
50 */
51 static INLINE GLfloat
52 nonlinear_to_linear(GLubyte cs8)
53 {
54 static GLfloat table[256];
55 static GLboolean tableReady = GL_FALSE;
56 if (!tableReady) {
57 /* compute lookup table now */
58 GLuint i;
59 for (i = 0; i < 256; i++) {
60 const GLfloat cs = UBYTE_TO_FLOAT(i);
61 if (cs <= 0.04045) {
62 table[i] = cs / 12.92f;
63 }
64 else {
65 table[i] = (GLfloat) _mesa_pow((cs + 0.055) / 1.055, 2.4);
66 }
67 }
68 tableReady = GL_TRUE;
69 }
70 return table[cs8];
71 }
72
73
74 #endif /* FEATURE_EXT_texture_sRGB */
75
76
77 /* Texel fetch routines for all supported formats
78 */
79 #define DIM 1
80 #include "texformat_tmp.h"
81
82 #define DIM 2
83 #include "texformat_tmp.h"
84
85 #define DIM 3
86 #include "texformat_tmp.h"
87
88 /**
89 * Null texel fetch function.
90 *
91 * Have to have this so the FetchTexel function pointer is never NULL.
92 */
93 static void fetch_null_texelf( const struct gl_texture_image *texImage,
94 GLint i, GLint j, GLint k, GLfloat *texel )
95 {
96 (void) texImage; (void) i; (void) j; (void) k;
97 texel[RCOMP] = 0.0;
98 texel[GCOMP] = 0.0;
99 texel[BCOMP] = 0.0;
100 texel[ACOMP] = 0.0;
101 _mesa_warning(NULL, "fetch_null_texelf() called!");
102 }
103
104 static void store_null_texel(struct gl_texture_image *texImage,
105 GLint i, GLint j, GLint k, const void *texel)
106 {
107 (void) texImage;
108 (void) i;
109 (void) j;
110 (void) k;
111 (void) texel;
112 /* no-op */
113 }
114
115
116 /**
117 * Notes about the predefined gl_texture_formats:
118 *
119 * 1. There are 1D, 2D and 3D functions for fetching texels from texture
120 * images, returning both GLchan values and GLfloat values. (six
121 * functions in total)
122 * You don't have to provide both the GLchan and GLfloat functions;
123 * just one or the other is OK. Mesa will use an "adaptor" to convert
124 * between GLchan/GLfloat when needed.
125 * Since the adaptors have small performance penalty, we provide both
126 * GLchan and GLfloat functions for some common formats like RGB, RGBA.
127 */
128
129
130 /***************************************************************/
131 /** \name Default GLchan-based formats */
132 /*@{*/
133
134 const struct gl_texture_format _mesa_texformat_rgba = {
135 MESA_FORMAT_RGBA, /* MesaFormat */
136 GL_RGBA, /* BaseFormat */
137 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
138 CHAN_BITS, /* RedBits */
139 CHAN_BITS, /* GreenBits */
140 CHAN_BITS, /* BlueBits */
141 CHAN_BITS, /* AlphaBits */
142 0, /* LuminanceBits */
143 0, /* IntensityBits */
144 0, /* IndexBits */
145 0, /* DepthBits */
146 0, /* StencilBits */
147 4 * sizeof(GLchan), /* TexelBytes */
148 };
149
150 const struct gl_texture_format _mesa_texformat_rgb = {
151 MESA_FORMAT_RGB, /* MesaFormat */
152 GL_RGB, /* BaseFormat */
153 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
154 CHAN_BITS, /* RedBits */
155 CHAN_BITS, /* GreenBits */
156 CHAN_BITS, /* BlueBits */
157 0, /* AlphaBits */
158 0, /* LuminanceBits */
159 0, /* IntensityBits */
160 0, /* IndexBits */
161 0, /* DepthBits */
162 0, /* StencilBits */
163 3 * sizeof(GLchan), /* TexelBytes */
164 };
165
166 const struct gl_texture_format _mesa_texformat_alpha = {
167 MESA_FORMAT_ALPHA, /* MesaFormat */
168 GL_ALPHA, /* BaseFormat */
169 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
170 0, /* RedBits */
171 0, /* GreenBits */
172 0, /* BlueBits */
173 CHAN_BITS, /* AlphaBits */
174 0, /* LuminanceBits */
175 0, /* IntensityBits */
176 0, /* IndexBits */
177 0, /* DepthBits */
178 0, /* StencilBits */
179 sizeof(GLchan), /* TexelBytes */
180 };
181
182 const struct gl_texture_format _mesa_texformat_luminance = {
183 MESA_FORMAT_LUMINANCE, /* MesaFormat */
184 GL_LUMINANCE, /* BaseFormat */
185 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
186 0, /* RedBits */
187 0, /* GreenBits */
188 0, /* BlueBits */
189 0, /* AlphaBits */
190 CHAN_BITS, /* LuminanceBits */
191 0, /* IntensityBits */
192 0, /* IndexBits */
193 0, /* DepthBits */
194 0, /* StencilBits */
195 sizeof(GLchan), /* TexelBytes */
196 };
197
198 const struct gl_texture_format _mesa_texformat_luminance_alpha = {
199 MESA_FORMAT_LUMINANCE_ALPHA, /* MesaFormat */
200 GL_LUMINANCE_ALPHA, /* BaseFormat */
201 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
202 0, /* RedBits */
203 0, /* GreenBits */
204 0, /* BlueBits */
205 CHAN_BITS, /* AlphaBits */
206 CHAN_BITS, /* LuminanceBits */
207 0, /* IntensityBits */
208 0, /* IndexBits */
209 0, /* DepthBits */
210 0, /* StencilBits */
211 2 * sizeof(GLchan), /* TexelBytes */
212 };
213
214 const struct gl_texture_format _mesa_texformat_intensity = {
215 MESA_FORMAT_INTENSITY, /* MesaFormat */
216 GL_INTENSITY, /* BaseFormat */
217 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
218 0, /* RedBits */
219 0, /* GreenBits */
220 0, /* BlueBits */
221 0, /* AlphaBits */
222 0, /* LuminanceBits */
223 CHAN_BITS, /* IntensityBits */
224 0, /* IndexBits */
225 0, /* DepthBits */
226 0, /* StencilBits */
227 sizeof(GLchan), /* TexelBytes */
228 };
229
230
231 #if FEATURE_EXT_texture_sRGB
232
233 const struct gl_texture_format _mesa_texformat_srgb8 = {
234 MESA_FORMAT_SRGB8, /* MesaFormat */
235 GL_RGB, /* BaseFormat */
236 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
237 8, /* RedBits */
238 8, /* GreenBits */
239 8, /* BlueBits */
240 0, /* AlphaBits */
241 0, /* LuminanceBits */
242 0, /* IntensityBits */
243 0, /* IndexBits */
244 0, /* DepthBits */
245 0, /* StencilBits */
246 3, /* TexelBytes */
247 };
248
249 const struct gl_texture_format _mesa_texformat_srgba8 = {
250 MESA_FORMAT_SRGBA8, /* MesaFormat */
251 GL_RGBA, /* BaseFormat */
252 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
253 8, /* RedBits */
254 8, /* GreenBits */
255 8, /* BlueBits */
256 8, /* AlphaBits */
257 0, /* LuminanceBits */
258 0, /* IntensityBits */
259 0, /* IndexBits */
260 0, /* DepthBits */
261 0, /* StencilBits */
262 4, /* TexelBytes */
263 };
264
265 const struct gl_texture_format _mesa_texformat_sargb8 = {
266 MESA_FORMAT_SARGB8, /* MesaFormat */
267 GL_RGBA, /* BaseFormat */
268 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
269 8, /* RedBits */
270 8, /* GreenBits */
271 8, /* BlueBits */
272 8, /* AlphaBits */
273 0, /* LuminanceBits */
274 0, /* IntensityBits */
275 0, /* IndexBits */
276 0, /* DepthBits */
277 0, /* StencilBits */
278 4, /* TexelBytes */
279 };
280
281 const struct gl_texture_format _mesa_texformat_sl8 = {
282 MESA_FORMAT_SL8, /* MesaFormat */
283 GL_LUMINANCE, /* BaseFormat */
284 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
285 0, /* RedBits */
286 0, /* GreenBits */
287 0, /* BlueBits */
288 0, /* AlphaBits */
289 8, /* LuminanceBits */
290 0, /* IntensityBits */
291 0, /* IndexBits */
292 0, /* DepthBits */
293 0, /* StencilBits */
294 1, /* TexelBytes */
295 };
296
297 /* Note: this format name looks like a misnomer, make it sal8? */
298 const struct gl_texture_format _mesa_texformat_sla8 = {
299 MESA_FORMAT_SLA8, /* MesaFormat */
300 GL_LUMINANCE_ALPHA, /* BaseFormat */
301 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
302 0, /* RedBits */
303 0, /* GreenBits */
304 0, /* BlueBits */
305 8, /* AlphaBits */
306 8, /* LuminanceBits */
307 0, /* IntensityBits */
308 0, /* IndexBits */
309 0, /* DepthBits */
310 0, /* StencilBits */
311 2, /* TexelBytes */
312 };
313
314 #endif /* FEATURE_EXT_texture_sRGB */
315
316 const struct gl_texture_format _mesa_texformat_rgba_float32 = {
317 MESA_FORMAT_RGBA_FLOAT32, /* MesaFormat */
318 GL_RGBA, /* BaseFormat */
319 GL_FLOAT, /* DataType */
320 8 * sizeof(GLfloat), /* RedBits */
321 8 * sizeof(GLfloat), /* GreenBits */
322 8 * sizeof(GLfloat), /* BlueBits */
323 8 * sizeof(GLfloat), /* AlphaBits */
324 0, /* LuminanceBits */
325 0, /* IntensityBits */
326 0, /* IndexBits */
327 0, /* DepthBits */
328 0, /* StencilBits */
329 4 * sizeof(GLfloat), /* TexelBytes */
330 };
331
332 const struct gl_texture_format _mesa_texformat_rgba_float16 = {
333 MESA_FORMAT_RGBA_FLOAT16, /* MesaFormat */
334 GL_RGBA, /* BaseFormat */
335 GL_FLOAT, /* DataType */
336 8 * sizeof(GLhalfARB), /* RedBits */
337 8 * sizeof(GLhalfARB), /* GreenBits */
338 8 * sizeof(GLhalfARB), /* BlueBits */
339 8 * sizeof(GLhalfARB), /* AlphaBits */
340 0, /* LuminanceBits */
341 0, /* IntensityBits */
342 0, /* IndexBits */
343 0, /* DepthBits */
344 0, /* StencilBits */
345 4 * sizeof(GLhalfARB), /* TexelBytes */
346 };
347
348 const struct gl_texture_format _mesa_texformat_rgb_float32 = {
349 MESA_FORMAT_RGB_FLOAT32, /* MesaFormat */
350 GL_RGB, /* BaseFormat */
351 GL_FLOAT, /* DataType */
352 8 * sizeof(GLfloat), /* RedBits */
353 8 * sizeof(GLfloat), /* GreenBits */
354 8 * sizeof(GLfloat), /* BlueBits */
355 0, /* AlphaBits */
356 0, /* LuminanceBits */
357 0, /* IntensityBits */
358 0, /* IndexBits */
359 0, /* DepthBits */
360 0, /* StencilBits */
361 3 * sizeof(GLfloat), /* TexelBytes */
362 };
363
364 const struct gl_texture_format _mesa_texformat_rgb_float16 = {
365 MESA_FORMAT_RGB_FLOAT16, /* MesaFormat */
366 GL_RGB, /* BaseFormat */
367 GL_FLOAT, /* DataType */
368 8 * sizeof(GLhalfARB), /* RedBits */
369 8 * sizeof(GLhalfARB), /* GreenBits */
370 8 * sizeof(GLhalfARB), /* BlueBits */
371 0, /* AlphaBits */
372 0, /* LuminanceBits */
373 0, /* IntensityBits */
374 0, /* IndexBits */
375 0, /* DepthBits */
376 0, /* StencilBits */
377 3 * sizeof(GLhalfARB), /* TexelBytes */
378 };
379
380 const struct gl_texture_format _mesa_texformat_alpha_float32 = {
381 MESA_FORMAT_ALPHA_FLOAT32, /* MesaFormat */
382 GL_ALPHA, /* BaseFormat */
383 GL_FLOAT, /* DataType */
384 0, /* RedBits */
385 0, /* GreenBits */
386 0, /* BlueBits */
387 8 * sizeof(GLfloat), /* AlphaBits */
388 0, /* LuminanceBits */
389 0, /* IntensityBits */
390 0, /* IndexBits */
391 0, /* DepthBits */
392 0, /* StencilBits */
393 1 * sizeof(GLfloat), /* TexelBytes */
394 };
395
396 const struct gl_texture_format _mesa_texformat_alpha_float16 = {
397 MESA_FORMAT_ALPHA_FLOAT16, /* MesaFormat */
398 GL_ALPHA, /* BaseFormat */
399 GL_FLOAT, /* DataType */
400 0, /* RedBits */
401 0, /* GreenBits */
402 0, /* BlueBits */
403 8 * sizeof(GLhalfARB), /* AlphaBits */
404 0, /* LuminanceBits */
405 0, /* IntensityBits */
406 0, /* IndexBits */
407 0, /* DepthBits */
408 0, /* StencilBits */
409 1 * sizeof(GLhalfARB), /* TexelBytes */
410 };
411
412 const struct gl_texture_format _mesa_texformat_luminance_float32 = {
413 MESA_FORMAT_LUMINANCE_FLOAT32, /* MesaFormat */
414 GL_LUMINANCE, /* BaseFormat */
415 GL_FLOAT, /* DataType */
416 0, /* RedBits */
417 0, /* GreenBits */
418 0, /* BlueBits */
419 0, /* AlphaBits */
420 8 * sizeof(GLfloat), /* LuminanceBits */
421 0, /* IntensityBits */
422 0, /* IndexBits */
423 0, /* DepthBits */
424 0, /* StencilBits */
425 1 * sizeof(GLfloat), /* TexelBytes */
426 };
427
428 const struct gl_texture_format _mesa_texformat_luminance_float16 = {
429 MESA_FORMAT_LUMINANCE_FLOAT16, /* MesaFormat */
430 GL_LUMINANCE, /* BaseFormat */
431 GL_FLOAT, /* DataType */
432 0, /* RedBits */
433 0, /* GreenBits */
434 0, /* BlueBits */
435 0, /* AlphaBits */
436 8 * sizeof(GLhalfARB), /* LuminanceBits */
437 0, /* IntensityBits */
438 0, /* IndexBits */
439 0, /* DepthBits */
440 0, /* StencilBits */
441 1 * sizeof(GLhalfARB), /* TexelBytes */
442 };
443
444 const struct gl_texture_format _mesa_texformat_luminance_alpha_float32 = {
445 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32, /* MesaFormat */
446 GL_LUMINANCE_ALPHA, /* BaseFormat */
447 GL_FLOAT, /* DataType */
448 0, /* RedBits */
449 0, /* GreenBits */
450 0, /* BlueBits */
451 8 * sizeof(GLfloat), /* AlphaBits */
452 8 * sizeof(GLfloat), /* LuminanceBits */
453 0, /* IntensityBits */
454 0, /* IndexBits */
455 0, /* DepthBits */
456 0, /* StencilBits */
457 2 * sizeof(GLfloat), /* TexelBytes */
458 };
459
460 const struct gl_texture_format _mesa_texformat_luminance_alpha_float16 = {
461 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16, /* MesaFormat */
462 GL_LUMINANCE_ALPHA, /* BaseFormat */
463 GL_FLOAT, /* DataType */
464 0, /* RedBits */
465 0, /* GreenBits */
466 0, /* BlueBits */
467 8 * sizeof(GLhalfARB), /* AlphaBits */
468 8 * sizeof(GLhalfARB), /* LuminanceBits */
469 0, /* IntensityBits */
470 0, /* IndexBits */
471 0, /* DepthBits */
472 0, /* StencilBits */
473 2 * sizeof(GLhalfARB), /* TexelBytes */
474 };
475
476 const struct gl_texture_format _mesa_texformat_intensity_float32 = {
477 MESA_FORMAT_INTENSITY_FLOAT32, /* MesaFormat */
478 GL_INTENSITY, /* BaseFormat */
479 GL_FLOAT, /* DataType */
480 0, /* RedBits */
481 0, /* GreenBits */
482 0, /* BlueBits */
483 0, /* AlphaBits */
484 0, /* LuminanceBits */
485 8 * sizeof(GLfloat), /* IntensityBits */
486 0, /* IndexBits */
487 0, /* DepthBits */
488 0, /* StencilBits */
489 1 * sizeof(GLfloat), /* TexelBytes */
490 };
491
492 const struct gl_texture_format _mesa_texformat_intensity_float16 = {
493 MESA_FORMAT_INTENSITY_FLOAT16, /* MesaFormat */
494 GL_INTENSITY, /* BaseFormat */
495 GL_FLOAT, /* DataType */
496 0, /* RedBits */
497 0, /* GreenBits */
498 0, /* BlueBits */
499 0, /* AlphaBits */
500 0, /* LuminanceBits */
501 8 * sizeof(GLhalfARB), /* IntensityBits */
502 0, /* IndexBits */
503 0, /* DepthBits */
504 0, /* StencilBits */
505 1 * sizeof(GLhalfARB), /* TexelBytes */
506 };
507
508 const struct gl_texture_format _mesa_texformat_dudv8 = {
509 MESA_FORMAT_DUDV8, /* MesaFormat */
510 GL_DUDV_ATI, /* BaseFormat */
511 GL_SIGNED_NORMALIZED, /* DataType */
512 /* maybe should add dudvBits field, but spec seems to be
513 lacking the ability to query with GetTexLevelParameter anyway */
514 0, /* RedBits */
515 0, /* GreenBits */
516 0, /* BlueBits */
517 0, /* AlphaBits */
518 0, /* LuminanceBits */
519 0, /* IntensityBits */
520 0, /* IndexBits */
521 0, /* DepthBits */
522 0, /* StencilBits */
523 2, /* TexelBytes */
524 };
525
526 const struct gl_texture_format _mesa_texformat_signed_rgba8888 = {
527 MESA_FORMAT_SIGNED_RGBA8888, /* MesaFormat */
528 GL_RGBA, /* BaseFormat */
529 GL_SIGNED_NORMALIZED, /* DataType */
530 8, /* RedBits */
531 8, /* GreenBits */
532 8, /* BlueBits */
533 8, /* AlphaBits */
534 0, /* LuminanceBits */
535 0, /* IntensityBits */
536 0, /* IndexBits */
537 0, /* DepthBits */
538 0, /* StencilBits */
539 4, /* TexelBytes */
540 };
541
542 const struct gl_texture_format _mesa_texformat_signed_rgba8888_rev = {
543 MESA_FORMAT_SIGNED_RGBA8888_REV, /* MesaFormat */
544 GL_RGBA, /* BaseFormat */
545 GL_SIGNED_NORMALIZED, /* DataType */
546 8, /* RedBits */
547 8, /* GreenBits */
548 8, /* BlueBits */
549 8, /* AlphaBits */
550 0, /* LuminanceBits */
551 0, /* IntensityBits */
552 0, /* IndexBits */
553 0, /* DepthBits */
554 0, /* StencilBits */
555 4, /* TexelBytes */
556 };
557
558 /*@}*/
559
560
561 /***************************************************************/
562 /** \name Hardware formats */
563 /*@{*/
564
565 const struct gl_texture_format _mesa_texformat_rgba8888 = {
566 MESA_FORMAT_RGBA8888, /* MesaFormat */
567 GL_RGBA, /* BaseFormat */
568 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
569 8, /* RedBits */
570 8, /* GreenBits */
571 8, /* BlueBits */
572 8, /* AlphaBits */
573 0, /* LuminanceBits */
574 0, /* IntensityBits */
575 0, /* IndexBits */
576 0, /* DepthBits */
577 0, /* StencilBits */
578 4, /* TexelBytes */
579 };
580
581 const struct gl_texture_format _mesa_texformat_rgba8888_rev = {
582 MESA_FORMAT_RGBA8888_REV, /* MesaFormat */
583 GL_RGBA, /* BaseFormat */
584 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
585 8, /* RedBits */
586 8, /* GreenBits */
587 8, /* BlueBits */
588 8, /* AlphaBits */
589 0, /* LuminanceBits */
590 0, /* IntensityBits */
591 0, /* IndexBits */
592 0, /* DepthBits */
593 0, /* StencilBits */
594 4, /* TexelBytes */
595 };
596
597 const struct gl_texture_format _mesa_texformat_argb8888 = {
598 MESA_FORMAT_ARGB8888, /* MesaFormat */
599 GL_RGBA, /* BaseFormat */
600 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
601 8, /* RedBits */
602 8, /* GreenBits */
603 8, /* BlueBits */
604 8, /* AlphaBits */
605 0, /* LuminanceBits */
606 0, /* IntensityBits */
607 0, /* IndexBits */
608 0, /* DepthBits */
609 0, /* StencilBits */
610 4, /* TexelBytes */
611 };
612
613 const struct gl_texture_format _mesa_texformat_argb8888_rev = {
614 MESA_FORMAT_ARGB8888_REV, /* MesaFormat */
615 GL_RGBA, /* BaseFormat */
616 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
617 8, /* RedBits */
618 8, /* GreenBits */
619 8, /* BlueBits */
620 8, /* AlphaBits */
621 0, /* LuminanceBits */
622 0, /* IntensityBits */
623 0, /* IndexBits */
624 0, /* DepthBits */
625 0, /* StencilBits */
626 4, /* TexelBytes */
627 };
628
629 const struct gl_texture_format _mesa_texformat_rgb888 = {
630 MESA_FORMAT_RGB888, /* MesaFormat */
631 GL_RGB, /* BaseFormat */
632 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
633 8, /* RedBits */
634 8, /* GreenBits */
635 8, /* BlueBits */
636 0, /* AlphaBits */
637 0, /* LuminanceBits */
638 0, /* IntensityBits */
639 0, /* IndexBits */
640 0, /* DepthBits */
641 0, /* StencilBits */
642 3, /* TexelBytes */
643 };
644
645 const struct gl_texture_format _mesa_texformat_bgr888 = {
646 MESA_FORMAT_BGR888, /* MesaFormat */
647 GL_RGB, /* BaseFormat */
648 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
649 8, /* RedBits */
650 8, /* GreenBits */
651 8, /* BlueBits */
652 0, /* AlphaBits */
653 0, /* LuminanceBits */
654 0, /* IntensityBits */
655 0, /* IndexBits */
656 0, /* DepthBits */
657 0, /* StencilBits */
658 3, /* TexelBytes */
659 };
660
661 const struct gl_texture_format _mesa_texformat_rgb565 = {
662 MESA_FORMAT_RGB565, /* MesaFormat */
663 GL_RGB, /* BaseFormat */
664 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
665 5, /* RedBits */
666 6, /* GreenBits */
667 5, /* BlueBits */
668 0, /* AlphaBits */
669 0, /* LuminanceBits */
670 0, /* IntensityBits */
671 0, /* IndexBits */
672 0, /* DepthBits */
673 0, /* StencilBits */
674 2, /* TexelBytes */
675 };
676
677 const struct gl_texture_format _mesa_texformat_rgb565_rev = {
678 MESA_FORMAT_RGB565_REV, /* MesaFormat */
679 GL_RGB, /* BaseFormat */
680 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
681 5, /* RedBits */
682 6, /* GreenBits */
683 5, /* BlueBits */
684 0, /* AlphaBits */
685 0, /* LuminanceBits */
686 0, /* IntensityBits */
687 0, /* IndexBits */
688 0, /* DepthBits */
689 0, /* StencilBits */
690 2, /* TexelBytes */
691 };
692
693 const struct gl_texture_format _mesa_texformat_rgba4444 = {
694 MESA_FORMAT_RGBA4444, /* MesaFormat */
695 GL_RGBA, /* BaseFormat */
696 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
697 4, /* RedBits */
698 4, /* GreenBits */
699 4, /* BlueBits */
700 4, /* AlphaBits */
701 0, /* LuminanceBits */
702 0, /* IntensityBits */
703 0, /* IndexBits */
704 0, /* DepthBits */
705 0, /* StencilBits */
706 2, /* TexelBytes */
707 };
708
709 const struct gl_texture_format _mesa_texformat_argb4444 = {
710 MESA_FORMAT_ARGB4444, /* MesaFormat */
711 GL_RGBA, /* BaseFormat */
712 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
713 4, /* RedBits */
714 4, /* GreenBits */
715 4, /* BlueBits */
716 4, /* AlphaBits */
717 0, /* LuminanceBits */
718 0, /* IntensityBits */
719 0, /* IndexBits */
720 0, /* DepthBits */
721 0, /* StencilBits */
722 2, /* TexelBytes */
723 };
724
725 const struct gl_texture_format _mesa_texformat_argb4444_rev = {
726 MESA_FORMAT_ARGB4444_REV, /* MesaFormat */
727 GL_RGBA, /* BaseFormat */
728 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
729 4, /* RedBits */
730 4, /* GreenBits */
731 4, /* BlueBits */
732 4, /* AlphaBits */
733 0, /* LuminanceBits */
734 0, /* IntensityBits */
735 0, /* IndexBits */
736 0, /* DepthBits */
737 0, /* StencilBits */
738 2, /* TexelBytes */
739 };
740
741 const struct gl_texture_format _mesa_texformat_rgba5551 = {
742 MESA_FORMAT_RGBA5551, /* MesaFormat */
743 GL_RGBA, /* BaseFormat */
744 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
745 5, /* RedBits */
746 5, /* GreenBits */
747 5, /* BlueBits */
748 1, /* AlphaBits */
749 0, /* LuminanceBits */
750 0, /* IntensityBits */
751 0, /* IndexBits */
752 0, /* DepthBits */
753 0, /* StencilBits */
754 2, /* TexelBytes */
755 };
756
757 const struct gl_texture_format _mesa_texformat_argb1555 = {
758 MESA_FORMAT_ARGB1555, /* MesaFormat */
759 GL_RGBA, /* BaseFormat */
760 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
761 5, /* RedBits */
762 5, /* GreenBits */
763 5, /* BlueBits */
764 1, /* AlphaBits */
765 0, /* LuminanceBits */
766 0, /* IntensityBits */
767 0, /* IndexBits */
768 0, /* DepthBits */
769 0, /* StencilBits */
770 2, /* TexelBytes */
771 };
772
773 const struct gl_texture_format _mesa_texformat_argb1555_rev = {
774 MESA_FORMAT_ARGB1555_REV, /* MesaFormat */
775 GL_RGBA, /* BaseFormat */
776 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
777 5, /* RedBits */
778 5, /* GreenBits */
779 5, /* BlueBits */
780 1, /* AlphaBits */
781 0, /* LuminanceBits */
782 0, /* IntensityBits */
783 0, /* IndexBits */
784 0, /* DepthBits */
785 0, /* StencilBits */
786 2, /* TexelBytes */
787 };
788
789 const struct gl_texture_format _mesa_texformat_al88 = {
790 MESA_FORMAT_AL88, /* MesaFormat */
791 GL_LUMINANCE_ALPHA, /* BaseFormat */
792 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
793 0, /* RedBits */
794 0, /* GreenBits */
795 0, /* BlueBits */
796 8, /* AlphaBits */
797 8, /* LuminanceBits */
798 0, /* IntensityBits */
799 0, /* IndexBits */
800 0, /* DepthBits */
801 0, /* StencilBits */
802 2, /* TexelBytes */
803 };
804
805 const struct gl_texture_format _mesa_texformat_al88_rev = {
806 MESA_FORMAT_AL88_REV, /* MesaFormat */
807 GL_LUMINANCE_ALPHA, /* BaseFormat */
808 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
809 0, /* RedBits */
810 0, /* GreenBits */
811 0, /* BlueBits */
812 8, /* AlphaBits */
813 8, /* LuminanceBits */
814 0, /* IntensityBits */
815 0, /* IndexBits */
816 0, /* DepthBits */
817 0, /* StencilBits */
818 2, /* TexelBytes */
819 };
820
821 const struct gl_texture_format _mesa_texformat_rgb332 = {
822 MESA_FORMAT_RGB332, /* MesaFormat */
823 GL_RGB, /* BaseFormat */
824 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
825 3, /* RedBits */
826 3, /* GreenBits */
827 2, /* BlueBits */
828 0, /* AlphaBits */
829 0, /* LuminanceBits */
830 0, /* IntensityBits */
831 0, /* IndexBits */
832 0, /* DepthBits */
833 0, /* StencilBits */
834 1, /* TexelBytes */
835 };
836
837 const struct gl_texture_format _mesa_texformat_a8 = {
838 MESA_FORMAT_A8, /* MesaFormat */
839 GL_ALPHA, /* BaseFormat */
840 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
841 0, /* RedBits */
842 0, /* GreenBits */
843 0, /* BlueBits */
844 8, /* AlphaBits */
845 0, /* LuminanceBits */
846 0, /* IntensityBits */
847 0, /* IndexBits */
848 0, /* DepthBits */
849 0, /* StencilBits */
850 1, /* TexelBytes */
851 };
852
853 const struct gl_texture_format _mesa_texformat_l8 = {
854 MESA_FORMAT_L8, /* MesaFormat */
855 GL_LUMINANCE, /* BaseFormat */
856 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
857 0, /* RedBits */
858 0, /* GreenBits */
859 0, /* BlueBits */
860 0, /* AlphaBits */
861 8, /* LuminanceBits */
862 0, /* IntensityBits */
863 0, /* IndexBits */
864 0, /* DepthBits */
865 0, /* StencilBits */
866 1, /* TexelBytes */
867 };
868
869 const struct gl_texture_format _mesa_texformat_i8 = {
870 MESA_FORMAT_I8, /* MesaFormat */
871 GL_INTENSITY, /* BaseFormat */
872 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
873 0, /* RedBits */
874 0, /* GreenBits */
875 0, /* BlueBits */
876 0, /* AlphaBits */
877 0, /* LuminanceBits */
878 8, /* IntensityBits */
879 0, /* IndexBits */
880 0, /* DepthBits */
881 0, /* StencilBits */
882 1, /* TexelBytes */
883 };
884
885 const struct gl_texture_format _mesa_texformat_ci8 = {
886 MESA_FORMAT_CI8, /* MesaFormat */
887 GL_COLOR_INDEX, /* BaseFormat */
888 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
889 0, /* RedBits */
890 0, /* GreenBits */
891 0, /* BlueBits */
892 0, /* AlphaBits */
893 0, /* LuminanceBits */
894 0, /* IntensityBits */
895 8, /* IndexBits */
896 0, /* DepthBits */
897 0, /* StencilBits */
898 1, /* TexelBytes */
899 };
900
901 const struct gl_texture_format _mesa_texformat_ycbcr = {
902 MESA_FORMAT_YCBCR, /* MesaFormat */
903 GL_YCBCR_MESA, /* BaseFormat */
904 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
905 0, /* RedBits */
906 0, /* GreenBits */
907 0, /* BlueBits */
908 0, /* AlphaBits */
909 0, /* LuminanceBits */
910 0, /* IntensityBits */
911 0, /* IndexBits */
912 0, /* DepthBits */
913 0, /* StencilBits */
914 2, /* TexelBytes */
915 };
916
917 const struct gl_texture_format _mesa_texformat_ycbcr_rev = {
918 MESA_FORMAT_YCBCR_REV, /* MesaFormat */
919 GL_YCBCR_MESA, /* BaseFormat */
920 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
921 0, /* RedBits */
922 0, /* GreenBits */
923 0, /* BlueBits */
924 0, /* AlphaBits */
925 0, /* LuminanceBits */
926 0, /* IntensityBits */
927 0, /* IndexBits */
928 0, /* DepthBits */
929 0, /* StencilBits */
930 2, /* TexelBytes */
931 };
932
933 const struct gl_texture_format _mesa_texformat_z24_s8 = {
934 MESA_FORMAT_Z24_S8, /* MesaFormat */
935 GL_DEPTH_STENCIL_EXT, /* BaseFormat */
936 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
937 0, /* RedBits */
938 0, /* GreenBits */
939 0, /* BlueBits */
940 0, /* AlphaBits */
941 0, /* LuminanceBits */
942 0, /* IntensityBits */
943 0, /* IndexBits */
944 24, /* DepthBits */
945 8, /* StencilBits */
946 4, /* TexelBytes */
947 };
948
949 const struct gl_texture_format _mesa_texformat_s8_z24 = {
950 MESA_FORMAT_S8_Z24, /* MesaFormat */
951 GL_DEPTH_STENCIL_EXT, /* BaseFormat */
952 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
953 0, /* RedBits */
954 0, /* GreenBits */
955 0, /* BlueBits */
956 0, /* AlphaBits */
957 0, /* LuminanceBits */
958 0, /* IntensityBits */
959 0, /* IndexBits */
960 24, /* DepthBits */
961 8, /* StencilBits */
962 4, /* TexelBytes */
963 };
964
965 const struct gl_texture_format _mesa_texformat_z16 = {
966 MESA_FORMAT_Z16, /* MesaFormat */
967 GL_DEPTH_COMPONENT, /* BaseFormat */
968 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
969 0, /* RedBits */
970 0, /* GreenBits */
971 0, /* BlueBits */
972 0, /* AlphaBits */
973 0, /* LuminanceBits */
974 0, /* IntensityBits */
975 0, /* IndexBits */
976 sizeof(GLushort) * 8, /* DepthBits */
977 0, /* StencilBits */
978 sizeof(GLushort), /* TexelBytes */
979 };
980
981 const struct gl_texture_format _mesa_texformat_z32 = {
982 MESA_FORMAT_Z32, /* MesaFormat */
983 GL_DEPTH_COMPONENT, /* BaseFormat */
984 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
985 0, /* RedBits */
986 0, /* GreenBits */
987 0, /* BlueBits */
988 0, /* AlphaBits */
989 0, /* LuminanceBits */
990 0, /* IntensityBits */
991 0, /* IndexBits */
992 sizeof(GLuint) * 8, /* DepthBits */
993 0, /* StencilBits */
994 sizeof(GLuint), /* TexelBytes */
995 };
996
997 /*@}*/
998
999
1000 /***************************************************************/
1001 /** \name Null format (useful for proxy textures) */
1002 /*@{*/
1003
1004 const struct gl_texture_format _mesa_null_texformat = {
1005 -1, /* MesaFormat */
1006 0, /* BaseFormat */
1007 GL_NONE, /* DataType */
1008 0, /* RedBits */
1009 0, /* GreenBits */
1010 0, /* BlueBits */
1011 0, /* AlphaBits */
1012 0, /* LuminanceBits */
1013 0, /* IntensityBits */
1014 0, /* IndexBits */
1015 0, /* DepthBits */
1016 0, /* StencilBits */
1017 0, /* TexelBytes */
1018 };
1019
1020 /*@}*/
1021
1022
1023 /**
1024 * Choose an appropriate texture format given the format, type and
1025 * internalFormat parameters passed to glTexImage().
1026 *
1027 * \param ctx the GL context.
1028 * \param internalFormat user's prefered internal texture format.
1029 * \param format incoming image pixel format.
1030 * \param type incoming image data type.
1031 *
1032 * \return a pointer to a gl_texture_format object which describes the
1033 * choosen texture format, or NULL on failure.
1034 *
1035 * This is called via dd_function_table::ChooseTextureFormat. Hardware drivers
1036 * will typically override this function with a specialized version.
1037 */
1038 const struct gl_texture_format *
1039 _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
1040 GLenum format, GLenum type )
1041 {
1042 (void) format;
1043 (void) type;
1044
1045 switch (internalFormat) {
1046 /* RGBA formats */
1047 case 4:
1048 case GL_RGBA:
1049 case GL_RGB10_A2:
1050 case GL_RGBA12:
1051 case GL_RGBA16:
1052 return &_mesa_texformat_rgba;
1053 case GL_RGBA8:
1054 return &_mesa_texformat_rgba8888;
1055 case GL_RGB5_A1:
1056 return &_mesa_texformat_argb1555;
1057 case GL_RGBA2:
1058 return &_mesa_texformat_argb4444_rev; /* just to test another format*/
1059 case GL_RGBA4:
1060 return &_mesa_texformat_argb4444;
1061
1062 /* RGB formats */
1063 case 3:
1064 case GL_RGB:
1065 case GL_RGB10:
1066 case GL_RGB12:
1067 case GL_RGB16:
1068 return &_mesa_texformat_rgb;
1069 case GL_RGB8:
1070 return &_mesa_texformat_rgb888;
1071 case GL_R3_G3_B2:
1072 return &_mesa_texformat_rgb332;
1073 case GL_RGB4:
1074 return &_mesa_texformat_rgb565_rev; /* just to test another format */
1075 case GL_RGB5:
1076 return &_mesa_texformat_rgb565;
1077
1078 /* Alpha formats */
1079 case GL_ALPHA:
1080 case GL_ALPHA4:
1081 case GL_ALPHA12:
1082 case GL_ALPHA16:
1083 return &_mesa_texformat_alpha;
1084 case GL_ALPHA8:
1085 return &_mesa_texformat_a8;
1086
1087 /* Luminance formats */
1088 case 1:
1089 case GL_LUMINANCE:
1090 case GL_LUMINANCE4:
1091 case GL_LUMINANCE12:
1092 case GL_LUMINANCE16:
1093 return &_mesa_texformat_luminance;
1094 case GL_LUMINANCE8:
1095 return &_mesa_texformat_l8;
1096
1097 /* Luminance/Alpha formats */
1098 case 2:
1099 case GL_LUMINANCE_ALPHA:
1100 case GL_LUMINANCE4_ALPHA4:
1101 case GL_LUMINANCE6_ALPHA2:
1102 case GL_LUMINANCE12_ALPHA4:
1103 case GL_LUMINANCE12_ALPHA12:
1104 case GL_LUMINANCE16_ALPHA16:
1105 return &_mesa_texformat_luminance_alpha;
1106 case GL_LUMINANCE8_ALPHA8:
1107 return &_mesa_texformat_al88;
1108
1109 case GL_INTENSITY:
1110 case GL_INTENSITY4:
1111 case GL_INTENSITY12:
1112 case GL_INTENSITY16:
1113 return &_mesa_texformat_intensity;
1114 case GL_INTENSITY8:
1115 return &_mesa_texformat_i8;
1116
1117 case GL_COLOR_INDEX:
1118 case GL_COLOR_INDEX1_EXT:
1119 case GL_COLOR_INDEX2_EXT:
1120 case GL_COLOR_INDEX4_EXT:
1121 case GL_COLOR_INDEX12_EXT:
1122 case GL_COLOR_INDEX16_EXT:
1123 case GL_COLOR_INDEX8_EXT:
1124 return &_mesa_texformat_ci8;
1125
1126 default:
1127 ; /* fallthrough */
1128 }
1129
1130 if (ctx->Extensions.ARB_depth_texture) {
1131 switch (internalFormat) {
1132 case GL_DEPTH_COMPONENT:
1133 case GL_DEPTH_COMPONENT24:
1134 case GL_DEPTH_COMPONENT32:
1135 return &_mesa_texformat_z32;
1136 case GL_DEPTH_COMPONENT16:
1137 return &_mesa_texformat_z16;
1138 default:
1139 ; /* fallthrough */
1140 }
1141 }
1142
1143 switch (internalFormat) {
1144 case GL_COMPRESSED_ALPHA_ARB:
1145 return &_mesa_texformat_alpha;
1146 case GL_COMPRESSED_LUMINANCE_ARB:
1147 return &_mesa_texformat_luminance;
1148 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
1149 return &_mesa_texformat_luminance_alpha;
1150 case GL_COMPRESSED_INTENSITY_ARB:
1151 return &_mesa_texformat_intensity;
1152 case GL_COMPRESSED_RGB_ARB:
1153 #if FEATURE_texture_fxt1
1154 if (ctx->Extensions.TDFX_texture_compression_FXT1)
1155 return &_mesa_texformat_rgb_fxt1;
1156 #endif
1157 #if FEATURE_texture_s3tc
1158 if (ctx->Extensions.EXT_texture_compression_s3tc ||
1159 ctx->Extensions.S3_s3tc)
1160 return &_mesa_texformat_rgb_dxt1;
1161 #endif
1162 return &_mesa_texformat_rgb;
1163 case GL_COMPRESSED_RGBA_ARB:
1164 #if FEATURE_texture_fxt1
1165 if (ctx->Extensions.TDFX_texture_compression_FXT1)
1166 return &_mesa_texformat_rgba_fxt1;
1167 #endif
1168 #if FEATURE_texture_s3tc
1169 if (ctx->Extensions.EXT_texture_compression_s3tc ||
1170 ctx->Extensions.S3_s3tc)
1171 return &_mesa_texformat_rgba_dxt3; /* Not rgba_dxt1, see spec */
1172 #endif
1173 return &_mesa_texformat_rgba;
1174 default:
1175 ; /* fallthrough */
1176 }
1177
1178 if (ctx->Extensions.MESA_ycbcr_texture) {
1179 if (internalFormat == GL_YCBCR_MESA) {
1180 if (type == GL_UNSIGNED_SHORT_8_8_MESA)
1181 return &_mesa_texformat_ycbcr;
1182 else
1183 return &_mesa_texformat_ycbcr_rev;
1184 }
1185 }
1186
1187 #if FEATURE_texture_fxt1
1188 if (ctx->Extensions.TDFX_texture_compression_FXT1) {
1189 switch (internalFormat) {
1190 case GL_COMPRESSED_RGB_FXT1_3DFX:
1191 return &_mesa_texformat_rgb_fxt1;
1192 case GL_COMPRESSED_RGBA_FXT1_3DFX:
1193 return &_mesa_texformat_rgba_fxt1;
1194 default:
1195 ; /* fallthrough */
1196 }
1197 }
1198 #endif
1199
1200 #if FEATURE_texture_s3tc
1201 if (ctx->Extensions.EXT_texture_compression_s3tc) {
1202 switch (internalFormat) {
1203 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1204 return &_mesa_texformat_rgb_dxt1;
1205 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1206 return &_mesa_texformat_rgba_dxt1;
1207 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
1208 return &_mesa_texformat_rgba_dxt3;
1209 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
1210 return &_mesa_texformat_rgba_dxt5;
1211 default:
1212 ; /* fallthrough */
1213 }
1214 }
1215
1216 if (ctx->Extensions.S3_s3tc) {
1217 switch (internalFormat) {
1218 case GL_RGB_S3TC:
1219 case GL_RGB4_S3TC:
1220 return &_mesa_texformat_rgb_dxt1;
1221 case GL_RGBA_S3TC:
1222 case GL_RGBA4_S3TC:
1223 return &_mesa_texformat_rgba_dxt3;
1224 default:
1225 ; /* fallthrough */
1226 }
1227 }
1228 #endif
1229
1230 if (ctx->Extensions.ARB_texture_float) {
1231 switch (internalFormat) {
1232 case GL_ALPHA16F_ARB:
1233 return &_mesa_texformat_alpha_float16;
1234 case GL_ALPHA32F_ARB:
1235 return &_mesa_texformat_alpha_float32;
1236 case GL_LUMINANCE16F_ARB:
1237 return &_mesa_texformat_luminance_float16;
1238 case GL_LUMINANCE32F_ARB:
1239 return &_mesa_texformat_luminance_float32;
1240 case GL_LUMINANCE_ALPHA16F_ARB:
1241 return &_mesa_texformat_luminance_alpha_float16;
1242 case GL_LUMINANCE_ALPHA32F_ARB:
1243 return &_mesa_texformat_luminance_alpha_float32;
1244 case GL_INTENSITY16F_ARB:
1245 return &_mesa_texformat_intensity_float16;
1246 case GL_INTENSITY32F_ARB:
1247 return &_mesa_texformat_intensity_float32;
1248 case GL_RGB16F_ARB:
1249 return &_mesa_texformat_rgb_float16;
1250 case GL_RGB32F_ARB:
1251 return &_mesa_texformat_rgb_float32;
1252 case GL_RGBA16F_ARB:
1253 return &_mesa_texformat_rgba_float16;
1254 case GL_RGBA32F_ARB:
1255 return &_mesa_texformat_rgba_float32;
1256 default:
1257 ; /* fallthrough */
1258 }
1259 }
1260
1261 if (ctx->Extensions.EXT_packed_depth_stencil) {
1262 switch (internalFormat) {
1263 case GL_DEPTH_STENCIL_EXT:
1264 case GL_DEPTH24_STENCIL8_EXT:
1265 return &_mesa_texformat_z24_s8;
1266 default:
1267 ; /* fallthrough */
1268 }
1269 }
1270
1271 if (ctx->Extensions.ATI_envmap_bumpmap) {
1272 switch (internalFormat) {
1273 case GL_DUDV_ATI:
1274 case GL_DU8DV8_ATI:
1275 return &_mesa_texformat_dudv8;
1276 default:
1277 ; /* fallthrough */
1278 }
1279 }
1280
1281 if (ctx->Extensions.MESA_texture_signed_rgba) {
1282 switch (internalFormat) {
1283 case GL_RGBA_SNORM:
1284 case GL_RGBA8_SNORM:
1285 return &_mesa_texformat_signed_rgba8888;
1286 default:
1287 ; /* fallthrough */
1288 }
1289 }
1290
1291
1292 #if FEATURE_EXT_texture_sRGB
1293 if (ctx->Extensions.EXT_texture_sRGB) {
1294 switch (internalFormat) {
1295 case GL_SRGB_EXT:
1296 case GL_SRGB8_EXT:
1297 return &_mesa_texformat_srgb8;
1298 case GL_SRGB_ALPHA_EXT:
1299 case GL_SRGB8_ALPHA8_EXT:
1300 return &_mesa_texformat_srgba8;
1301 case GL_SLUMINANCE_EXT:
1302 case GL_SLUMINANCE8_EXT:
1303 return &_mesa_texformat_sl8;
1304 case GL_SLUMINANCE_ALPHA_EXT:
1305 case GL_SLUMINANCE8_ALPHA8_EXT:
1306 return &_mesa_texformat_sla8;
1307 case GL_COMPRESSED_SLUMINANCE_EXT:
1308 return &_mesa_texformat_sl8;
1309 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
1310 return &_mesa_texformat_sla8;
1311 case GL_COMPRESSED_SRGB_EXT:
1312 #if FEATURE_texture_s3tc
1313 if (ctx->Extensions.EXT_texture_compression_s3tc)
1314 return &_mesa_texformat_srgb_dxt1;
1315 #endif
1316 return &_mesa_texformat_srgb8;
1317 case GL_COMPRESSED_SRGB_ALPHA_EXT:
1318 #if FEATURE_texture_s3tc
1319 if (ctx->Extensions.EXT_texture_compression_s3tc)
1320 return &_mesa_texformat_srgba_dxt3; /* Not srgba_dxt1, see spec */
1321 #endif
1322 return &_mesa_texformat_srgba8;
1323 #if FEATURE_texture_s3tc
1324 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
1325 if (ctx->Extensions.EXT_texture_compression_s3tc)
1326 return &_mesa_texformat_srgb_dxt1;
1327 break;
1328 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
1329 if (ctx->Extensions.EXT_texture_compression_s3tc)
1330 return &_mesa_texformat_srgba_dxt1;
1331 break;
1332 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
1333 if (ctx->Extensions.EXT_texture_compression_s3tc)
1334 return &_mesa_texformat_srgba_dxt3;
1335 break;
1336 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
1337 if (ctx->Extensions.EXT_texture_compression_s3tc)
1338 return &_mesa_texformat_srgba_dxt5;
1339 break;
1340 #endif
1341 default:
1342 ; /* fallthrough */
1343 }
1344 }
1345 #endif /* FEATURE_EXT_texture_sRGB */
1346
1347 _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
1348 return NULL;
1349 }
1350
1351
1352
1353 /**
1354 * Return datatype and number of components per texel for the given gl_format.
1355 */
1356 void
1357 _mesa_format_to_type_and_comps(gl_format format,
1358 GLenum *datatype, GLuint *comps)
1359 {
1360 switch (format) {
1361 case MESA_FORMAT_RGBA8888:
1362 case MESA_FORMAT_RGBA8888_REV:
1363 case MESA_FORMAT_ARGB8888:
1364 case MESA_FORMAT_ARGB8888_REV:
1365 *datatype = CHAN_TYPE;
1366 *comps = 4;
1367 return;
1368 case MESA_FORMAT_RGB888:
1369 case MESA_FORMAT_BGR888:
1370 *datatype = GL_UNSIGNED_BYTE;
1371 *comps = 3;
1372 return;
1373 case MESA_FORMAT_RGB565:
1374 case MESA_FORMAT_RGB565_REV:
1375 *datatype = GL_UNSIGNED_SHORT_5_6_5;
1376 *comps = 3;
1377 return;
1378
1379 case MESA_FORMAT_ARGB4444:
1380 case MESA_FORMAT_ARGB4444_REV:
1381 *datatype = GL_UNSIGNED_SHORT_4_4_4_4;
1382 *comps = 4;
1383 return;
1384
1385 case MESA_FORMAT_ARGB1555:
1386 case MESA_FORMAT_ARGB1555_REV:
1387 *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
1388 *comps = 4;
1389 return;
1390
1391 case MESA_FORMAT_AL88:
1392 case MESA_FORMAT_AL88_REV:
1393 *datatype = GL_UNSIGNED_BYTE;
1394 *comps = 2;
1395 return;
1396 case MESA_FORMAT_RGB332:
1397 *datatype = GL_UNSIGNED_BYTE_3_3_2;
1398 *comps = 3;
1399 return;
1400
1401 case MESA_FORMAT_A8:
1402 case MESA_FORMAT_L8:
1403 case MESA_FORMAT_I8:
1404 case MESA_FORMAT_CI8:
1405 *datatype = GL_UNSIGNED_BYTE;
1406 *comps = 1;
1407 return;
1408
1409 case MESA_FORMAT_YCBCR:
1410 case MESA_FORMAT_YCBCR_REV:
1411 *datatype = GL_UNSIGNED_SHORT;
1412 *comps = 2;
1413 return;
1414
1415 case MESA_FORMAT_Z24_S8:
1416 *datatype = GL_UNSIGNED_INT;
1417 *comps = 1; /* XXX OK? */
1418 return;
1419
1420 case MESA_FORMAT_S8_Z24:
1421 *datatype = GL_UNSIGNED_INT;
1422 *comps = 1; /* XXX OK? */
1423 return;
1424
1425 case MESA_FORMAT_Z16:
1426 *datatype = GL_UNSIGNED_SHORT;
1427 *comps = 1;
1428 return;
1429
1430 case MESA_FORMAT_Z32:
1431 *datatype = GL_UNSIGNED_INT;
1432 *comps = 1;
1433 return;
1434
1435 case MESA_FORMAT_DUDV8:
1436 *datatype = GL_BYTE;
1437 *comps = 2;
1438 return;
1439
1440 case MESA_FORMAT_SIGNED_RGBA8888:
1441 case MESA_FORMAT_SIGNED_RGBA8888_REV:
1442 *datatype = GL_BYTE;
1443 *comps = 4;
1444 return;
1445
1446 #if FEATURE_EXT_texture_sRGB
1447 case MESA_FORMAT_SRGB8:
1448 *datatype = GL_UNSIGNED_BYTE;
1449 *comps = 3;
1450 return;
1451 case MESA_FORMAT_SRGBA8:
1452 case MESA_FORMAT_SARGB8:
1453 *datatype = GL_UNSIGNED_BYTE;
1454 *comps = 4;
1455 return;
1456 case MESA_FORMAT_SL8:
1457 *datatype = GL_UNSIGNED_BYTE;
1458 *comps = 1;
1459 return;
1460 case MESA_FORMAT_SLA8:
1461 *datatype = GL_UNSIGNED_BYTE;
1462 *comps = 2;
1463 return;
1464 #endif
1465
1466 #if FEATURE_texture_fxt1
1467 case MESA_FORMAT_RGB_FXT1:
1468 case MESA_FORMAT_RGBA_FXT1:
1469 #endif
1470 #if FEATURE_texture_s3tc
1471 case MESA_FORMAT_RGB_DXT1:
1472 case MESA_FORMAT_RGBA_DXT1:
1473 case MESA_FORMAT_RGBA_DXT3:
1474 case MESA_FORMAT_RGBA_DXT5:
1475 #if FEATURE_EXT_texture_sRGB
1476 case MESA_FORMAT_SRGB_DXT1:
1477 case MESA_FORMAT_SRGBA_DXT1:
1478 case MESA_FORMAT_SRGBA_DXT3:
1479 case MESA_FORMAT_SRGBA_DXT5:
1480 #endif
1481 /* XXX generate error instead? */
1482 *datatype = GL_UNSIGNED_BYTE;
1483 *comps = 0;
1484 return;
1485 #endif
1486
1487 case MESA_FORMAT_RGBA:
1488 *datatype = CHAN_TYPE;
1489 *comps = 4;
1490 return;
1491 case MESA_FORMAT_RGB:
1492 *datatype = CHAN_TYPE;
1493 *comps = 3;
1494 return;
1495 case MESA_FORMAT_LUMINANCE_ALPHA:
1496 *datatype = CHAN_TYPE;
1497 *comps = 2;
1498 return;
1499 case MESA_FORMAT_ALPHA:
1500 case MESA_FORMAT_LUMINANCE:
1501 case MESA_FORMAT_INTENSITY:
1502 *datatype = CHAN_TYPE;
1503 *comps = 1;
1504 return;
1505
1506 case MESA_FORMAT_RGBA_FLOAT32:
1507 *datatype = GL_FLOAT;
1508 *comps = 4;
1509 return;
1510 case MESA_FORMAT_RGBA_FLOAT16:
1511 *datatype = GL_HALF_FLOAT_ARB;
1512 *comps = 4;
1513 return;
1514 case MESA_FORMAT_RGB_FLOAT32:
1515 *datatype = GL_FLOAT;
1516 *comps = 3;
1517 return;
1518 case MESA_FORMAT_RGB_FLOAT16:
1519 *datatype = GL_HALF_FLOAT_ARB;
1520 *comps = 3;
1521 return;
1522 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
1523 *datatype = GL_FLOAT;
1524 *comps = 2;
1525 return;
1526 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
1527 *datatype = GL_HALF_FLOAT_ARB;
1528 *comps = 2;
1529 return;
1530 case MESA_FORMAT_ALPHA_FLOAT32:
1531 case MESA_FORMAT_LUMINANCE_FLOAT32:
1532 case MESA_FORMAT_INTENSITY_FLOAT32:
1533 *datatype = GL_FLOAT;
1534 *comps = 1;
1535 return;
1536 case MESA_FORMAT_ALPHA_FLOAT16:
1537 case MESA_FORMAT_LUMINANCE_FLOAT16:
1538 case MESA_FORMAT_INTENSITY_FLOAT16:
1539 *datatype = GL_HALF_FLOAT_ARB;
1540 *comps = 1;
1541 return;
1542
1543 default:
1544 _mesa_problem(NULL, "bad format in _mesa_format_to_type_and_comps");
1545 *datatype = 0;
1546 *comps = 1;
1547 }
1548 }
1549
1550
1551
1552 /**
1553 * Table to map MESA_FORMAT_ to texel fetch/store funcs.
1554 * XXX this is somewhat temporary.
1555 */
1556 static struct {
1557 GLuint Name;
1558 FetchTexelFuncF Fetch1D;
1559 FetchTexelFuncF Fetch2D;
1560 FetchTexelFuncF Fetch3D;
1561 StoreTexelFunc StoreTexel;
1562 }
1563 texfetch_funcs[MESA_FORMAT_COUNT] =
1564 {
1565 {
1566 MESA_FORMAT_RGBA,
1567 fetch_texel_1d_f_rgba,
1568 fetch_texel_2d_f_rgba,
1569 fetch_texel_3d_f_rgba,
1570 store_texel_rgba
1571 },
1572 {
1573 MESA_FORMAT_RGB,
1574 fetch_texel_1d_f_rgb,
1575 fetch_texel_2d_f_rgb,
1576 fetch_texel_3d_f_rgb,
1577 store_texel_rgb
1578 },
1579 {
1580 MESA_FORMAT_ALPHA,
1581 fetch_texel_1d_f_alpha,
1582 fetch_texel_2d_f_alpha,
1583 fetch_texel_3d_f_alpha,
1584 store_texel_alpha
1585 },
1586 {
1587 MESA_FORMAT_LUMINANCE,
1588 fetch_texel_1d_f_luminance,
1589 fetch_texel_2d_f_luminance,
1590 fetch_texel_3d_f_luminance,
1591 store_texel_luminance
1592 },
1593 {
1594 MESA_FORMAT_LUMINANCE_ALPHA,
1595 fetch_texel_1d_f_luminance_alpha,
1596 fetch_texel_2d_f_luminance_alpha,
1597 fetch_texel_3d_f_luminance_alpha,
1598 store_texel_luminance_alpha
1599 },
1600 {
1601 MESA_FORMAT_INTENSITY,
1602 fetch_texel_1d_f_intensity,
1603 fetch_texel_2d_f_intensity,
1604 fetch_texel_3d_f_intensity,
1605 store_texel_intensity
1606 },
1607 {
1608 MESA_FORMAT_SRGB8,
1609 fetch_texel_1d_srgb8,
1610 fetch_texel_2d_srgb8,
1611 fetch_texel_3d_srgb8,
1612 store_texel_srgb8
1613 },
1614 {
1615 MESA_FORMAT_SRGBA8,
1616 fetch_texel_1d_srgba8,
1617 fetch_texel_2d_srgba8,
1618 fetch_texel_3d_srgba8,
1619 store_texel_srgba8
1620 },
1621 {
1622 MESA_FORMAT_SARGB8,
1623 fetch_texel_1d_sargb8,
1624 fetch_texel_2d_sargb8,
1625 fetch_texel_3d_sargb8,
1626 store_texel_sargb8
1627 },
1628 {
1629 MESA_FORMAT_SL8,
1630 fetch_texel_1d_sl8,
1631 fetch_texel_2d_sl8,
1632 fetch_texel_3d_sl8,
1633 store_texel_sl8
1634 },
1635 {
1636 MESA_FORMAT_SLA8,
1637 fetch_texel_1d_sla8,
1638 fetch_texel_2d_sla8,
1639 fetch_texel_3d_sla8,
1640 store_texel_sla8
1641 },
1642 {
1643 MESA_FORMAT_RGB_FXT1,
1644 NULL,
1645 _mesa_fetch_texel_2d_f_rgb_fxt1,
1646 NULL,
1647 NULL
1648 },
1649 {
1650 MESA_FORMAT_RGBA_FXT1,
1651 NULL,
1652 _mesa_fetch_texel_2d_f_rgba_fxt1,
1653 NULL,
1654 NULL
1655 },
1656 {
1657 MESA_FORMAT_RGB_DXT1,
1658 NULL,
1659 _mesa_fetch_texel_2d_f_rgb_dxt1,
1660 NULL,
1661 NULL
1662 },
1663 {
1664 MESA_FORMAT_RGBA_DXT1,
1665 NULL,
1666 _mesa_fetch_texel_2d_f_rgba_dxt1,
1667 NULL,
1668 NULL
1669 },
1670 {
1671 MESA_FORMAT_RGBA_DXT3,
1672 NULL,
1673 _mesa_fetch_texel_2d_f_rgba_dxt3,
1674 NULL,
1675 NULL
1676 },
1677 {
1678 MESA_FORMAT_RGBA_DXT5,
1679 NULL,
1680 _mesa_fetch_texel_2d_f_rgba_dxt5,
1681 NULL,
1682 NULL
1683 },
1684 {
1685 MESA_FORMAT_SRGB_DXT1,
1686 NULL,
1687 _mesa_fetch_texel_2d_f_srgb_dxt1,
1688 NULL,
1689 NULL
1690 },
1691 {
1692 MESA_FORMAT_SRGBA_DXT1,
1693 NULL,
1694 _mesa_fetch_texel_2d_f_srgba_dxt1,
1695 NULL,
1696 NULL
1697 },
1698 {
1699 MESA_FORMAT_SRGBA_DXT3,
1700 NULL,
1701 _mesa_fetch_texel_2d_f_srgba_dxt3,
1702 NULL,
1703 NULL
1704 },
1705 {
1706 MESA_FORMAT_SRGBA_DXT5,
1707 NULL,
1708 _mesa_fetch_texel_2d_f_srgba_dxt5,
1709 NULL,
1710 NULL
1711 },
1712 {
1713 MESA_FORMAT_RGBA_FLOAT32,
1714 fetch_texel_1d_f_rgba_f32,
1715 fetch_texel_2d_f_rgba_f32,
1716 fetch_texel_3d_f_rgba_f32,
1717 store_texel_rgba_f32
1718 },
1719 {
1720 MESA_FORMAT_RGBA_FLOAT16,
1721 fetch_texel_1d_f_rgba_f16,
1722 fetch_texel_2d_f_rgba_f16,
1723 fetch_texel_3d_f_rgba_f16,
1724 store_texel_rgba_f16
1725 },
1726 {
1727 MESA_FORMAT_RGB_FLOAT32,
1728 fetch_texel_1d_f_rgb_f32,
1729 fetch_texel_2d_f_rgb_f32,
1730 fetch_texel_3d_f_rgb_f32,
1731 store_texel_rgb_f32
1732 },
1733 {
1734 MESA_FORMAT_RGB_FLOAT16,
1735 fetch_texel_1d_f_rgb_f16,
1736 fetch_texel_2d_f_rgb_f16,
1737 fetch_texel_3d_f_rgb_f16,
1738 store_texel_rgb_f16
1739 },
1740 {
1741 MESA_FORMAT_ALPHA_FLOAT32,
1742 fetch_texel_1d_f_alpha_f32,
1743 fetch_texel_2d_f_alpha_f32,
1744 fetch_texel_3d_f_alpha_f32,
1745 store_texel_alpha_f32
1746 },
1747 {
1748 MESA_FORMAT_ALPHA_FLOAT16,
1749 fetch_texel_1d_f_alpha_f16,
1750 fetch_texel_2d_f_alpha_f16,
1751 fetch_texel_3d_f_alpha_f16,
1752 store_texel_alpha_f16
1753 },
1754 {
1755 MESA_FORMAT_LUMINANCE_FLOAT32,
1756 fetch_texel_1d_f_luminance_f32,
1757 fetch_texel_2d_f_luminance_f32,
1758 fetch_texel_3d_f_luminance_f32,
1759 store_texel_luminance_f32
1760 },
1761 {
1762 MESA_FORMAT_LUMINANCE_FLOAT16,
1763 fetch_texel_1d_f_luminance_f16,
1764 fetch_texel_2d_f_luminance_f16,
1765 fetch_texel_3d_f_luminance_f16,
1766 store_texel_luminance_f16
1767 },
1768 {
1769 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
1770 fetch_texel_1d_f_luminance_alpha_f32,
1771 fetch_texel_2d_f_luminance_alpha_f32,
1772 fetch_texel_3d_f_luminance_alpha_f32,
1773 store_texel_luminance_alpha_f32
1774 },
1775 {
1776 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
1777 fetch_texel_1d_f_luminance_alpha_f16,
1778 fetch_texel_2d_f_luminance_alpha_f16,
1779 fetch_texel_3d_f_luminance_alpha_f16,
1780 store_texel_luminance_alpha_f16
1781 },
1782 {
1783 MESA_FORMAT_INTENSITY_FLOAT32,
1784 fetch_texel_1d_f_intensity_f32,
1785 fetch_texel_2d_f_intensity_f32,
1786 fetch_texel_3d_f_intensity_f32,
1787 store_texel_intensity_f32
1788 },
1789 {
1790 MESA_FORMAT_INTENSITY_FLOAT16,
1791 fetch_texel_1d_f_intensity_f16,
1792 fetch_texel_2d_f_intensity_f16,
1793 fetch_texel_3d_f_intensity_f16,
1794 store_texel_intensity_f16
1795 },
1796 {
1797 MESA_FORMAT_DUDV8,
1798 fetch_texel_1d_dudv8,
1799 fetch_texel_2d_dudv8,
1800 fetch_texel_3d_dudv8,
1801 NULL
1802 },
1803 {
1804 MESA_FORMAT_SIGNED_RGBA8888,
1805 fetch_texel_1d_signed_rgba8888,
1806 fetch_texel_2d_signed_rgba8888,
1807 fetch_texel_3d_signed_rgba8888,
1808 store_texel_signed_rgba8888
1809 },
1810 {
1811 MESA_FORMAT_SIGNED_RGBA8888_REV,
1812 fetch_texel_1d_signed_rgba8888_rev,
1813 fetch_texel_2d_signed_rgba8888_rev,
1814 fetch_texel_3d_signed_rgba8888_rev,
1815 store_texel_signed_rgba8888_rev
1816 },
1817 {
1818 MESA_FORMAT_RGBA8888,
1819 fetch_texel_1d_f_rgba8888,
1820 fetch_texel_2d_f_rgba8888,
1821 fetch_texel_3d_f_rgba8888,
1822 store_texel_rgba8888
1823 },
1824 {
1825 MESA_FORMAT_RGBA8888_REV,
1826 fetch_texel_1d_f_rgba8888_rev,
1827 fetch_texel_2d_f_rgba8888_rev,
1828 fetch_texel_3d_f_rgba8888_rev,
1829 store_texel_rgba8888_rev
1830 },
1831 {
1832 MESA_FORMAT_ARGB8888,
1833 fetch_texel_1d_f_argb8888,
1834 fetch_texel_2d_f_argb8888,
1835 fetch_texel_3d_f_argb8888,
1836 store_texel_argb8888
1837 },
1838 {
1839 MESA_FORMAT_ARGB8888_REV,
1840 fetch_texel_1d_f_argb8888_rev,
1841 fetch_texel_2d_f_argb8888_rev,
1842 fetch_texel_3d_f_argb8888_rev,
1843 store_texel_argb8888_rev
1844 },
1845 {
1846 MESA_FORMAT_RGB888,
1847 fetch_texel_1d_f_rgb888,
1848 fetch_texel_2d_f_rgb888,
1849 fetch_texel_3d_f_rgb888,
1850 store_texel_rgb888
1851 },
1852 {
1853 MESA_FORMAT_BGR888,
1854 fetch_texel_1d_f_bgr888,
1855 fetch_texel_2d_f_bgr888,
1856 fetch_texel_3d_f_bgr888,
1857 store_texel_bgr888
1858 },
1859 {
1860 MESA_FORMAT_RGB565,
1861 fetch_texel_1d_f_rgb565,
1862 fetch_texel_2d_f_rgb565,
1863 fetch_texel_3d_f_rgb565,
1864 store_texel_rgb565
1865 },
1866 {
1867 MESA_FORMAT_RGB565_REV,
1868 fetch_texel_1d_f_rgb565_rev,
1869 fetch_texel_2d_f_rgb565_rev,
1870 fetch_texel_3d_f_rgb565_rev,
1871 store_texel_rgb565_rev
1872 },
1873 {
1874 MESA_FORMAT_RGBA4444,
1875 fetch_texel_1d_f_rgba4444,
1876 fetch_texel_2d_f_rgba4444,
1877 fetch_texel_3d_f_rgba4444,
1878 store_texel_rgba4444
1879 },
1880 {
1881 MESA_FORMAT_ARGB4444,
1882 fetch_texel_1d_f_argb4444,
1883 fetch_texel_2d_f_argb4444,
1884 fetch_texel_3d_f_argb4444,
1885 store_texel_argb4444
1886 },
1887 {
1888 MESA_FORMAT_ARGB4444_REV,
1889 fetch_texel_1d_f_argb4444_rev,
1890 fetch_texel_2d_f_argb4444_rev,
1891 fetch_texel_3d_f_argb4444_rev,
1892 store_texel_argb4444_rev
1893 },
1894 {
1895 MESA_FORMAT_RGBA5551,
1896 fetch_texel_1d_f_rgba5551,
1897 fetch_texel_2d_f_rgba5551,
1898 fetch_texel_3d_f_rgba5551,
1899 store_texel_rgba5551
1900 },
1901 {
1902 MESA_FORMAT_ARGB1555,
1903 fetch_texel_1d_f_argb1555,
1904 fetch_texel_2d_f_argb1555,
1905 fetch_texel_3d_f_argb1555,
1906 store_texel_argb1555
1907 },
1908 {
1909 MESA_FORMAT_ARGB1555_REV,
1910 fetch_texel_1d_f_argb1555_rev,
1911 fetch_texel_2d_f_argb1555_rev,
1912 fetch_texel_3d_f_argb1555_rev,
1913 store_texel_argb1555_rev
1914 },
1915 {
1916 MESA_FORMAT_AL88,
1917 fetch_texel_1d_f_al88,
1918 fetch_texel_2d_f_al88,
1919 fetch_texel_3d_f_al88,
1920 store_texel_al88
1921 },
1922 {
1923 MESA_FORMAT_AL88_REV,
1924 fetch_texel_1d_f_al88_rev,
1925 fetch_texel_2d_f_al88_rev,
1926 fetch_texel_3d_f_al88_rev,
1927 store_texel_al88_rev
1928 },
1929 {
1930 MESA_FORMAT_RGB332,
1931 fetch_texel_1d_f_rgb332,
1932 fetch_texel_2d_f_rgb332,
1933 fetch_texel_3d_f_rgb332,
1934 store_texel_rgb332
1935 },
1936 {
1937 MESA_FORMAT_A8,
1938 fetch_texel_1d_f_a8,
1939 fetch_texel_2d_f_a8,
1940 fetch_texel_3d_f_a8,
1941 store_texel_a8
1942 },
1943 {
1944 MESA_FORMAT_L8,
1945 fetch_texel_1d_f_l8,
1946 fetch_texel_2d_f_l8,
1947 fetch_texel_3d_f_l8,
1948 store_texel_l8
1949 },
1950 {
1951 MESA_FORMAT_I8,
1952 fetch_texel_1d_f_i8,
1953 fetch_texel_2d_f_i8,
1954 fetch_texel_3d_f_i8,
1955 store_texel_i8
1956 },
1957 {
1958 MESA_FORMAT_CI8,
1959 fetch_texel_1d_f_ci8,
1960 fetch_texel_2d_f_ci8,
1961 fetch_texel_3d_f_ci8,
1962 store_texel_ci8
1963 },
1964 {
1965 MESA_FORMAT_YCBCR,
1966 fetch_texel_1d_f_ycbcr,
1967 fetch_texel_2d_f_ycbcr,
1968 fetch_texel_3d_f_ycbcr,
1969 store_texel_ycbcr
1970 },
1971 {
1972 MESA_FORMAT_YCBCR_REV,
1973 fetch_texel_1d_f_ycbcr_rev,
1974 fetch_texel_2d_f_ycbcr_rev,
1975 fetch_texel_3d_f_ycbcr_rev,
1976 store_texel_ycbcr_rev
1977 },
1978 {
1979 MESA_FORMAT_Z24_S8,
1980 fetch_texel_1d_f_z24_s8,
1981 fetch_texel_2d_f_z24_s8,
1982 fetch_texel_3d_f_z24_s8,
1983 store_texel_z24_s8
1984 },
1985 {
1986 MESA_FORMAT_S8_Z24,
1987 fetch_texel_1d_f_s8_z24,
1988 fetch_texel_2d_f_s8_z24,
1989 fetch_texel_3d_f_s8_z24,
1990 store_texel_s8_z24
1991 },
1992 {
1993 MESA_FORMAT_Z16,
1994 fetch_texel_1d_f_z16,
1995 fetch_texel_2d_f_z16,
1996 fetch_texel_3d_f_z16,
1997 store_texel_z16
1998 },
1999 {
2000 MESA_FORMAT_Z32,
2001 fetch_texel_1d_f_z32,
2002 fetch_texel_2d_f_z32,
2003 fetch_texel_3d_f_z32,
2004 store_texel_z32
2005 }
2006 };
2007
2008
2009 FetchTexelFuncF
2010 _mesa_get_texel_fetch_func(GLuint format, GLuint dims)
2011 {
2012 FetchTexelFuncF f;
2013 GLuint i;
2014 /* XXX replace loop with direct table lookup */
2015 for (i = 0; i < MESA_FORMAT_COUNT; i++) {
2016 if (texfetch_funcs[i].Name == format) {
2017 switch (dims) {
2018 case 1:
2019 f = texfetch_funcs[i].Fetch1D;
2020 break;
2021 case 2:
2022 f = texfetch_funcs[i].Fetch2D;
2023 break;
2024 case 3:
2025 f = texfetch_funcs[i].Fetch3D;
2026 break;
2027 }
2028 if (!f)
2029 f = fetch_null_texelf;
2030 return f;
2031 }
2032 }
2033 return NULL;
2034 }
2035
2036
2037 StoreTexelFunc
2038 _mesa_get_texel_store_func(GLuint format)
2039 {
2040 GLuint i;
2041 /* XXX replace loop with direct table lookup */
2042 for (i = 0; i < MESA_FORMAT_COUNT; i++) {
2043 if (texfetch_funcs[i].Name == format) {
2044 if (texfetch_funcs[i].StoreTexel)
2045 return texfetch_funcs[i].StoreTexel;
2046 else
2047 return store_null_texel;
2048 }
2049 }
2050 return NULL;
2051 }