mesa: remove unused gl_texture_format fields
[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
1355 * given gl_texture_format.
1356 */
1357 void
1358 _mesa_format_to_type_and_comps(const struct gl_texture_format *format,
1359 GLenum *datatype, GLuint *comps)
1360 {
1361 switch (format->MesaFormat) {
1362 case MESA_FORMAT_RGBA8888:
1363 case MESA_FORMAT_RGBA8888_REV:
1364 case MESA_FORMAT_ARGB8888:
1365 case MESA_FORMAT_ARGB8888_REV:
1366 *datatype = CHAN_TYPE;
1367 *comps = 4;
1368 return;
1369 case MESA_FORMAT_RGB888:
1370 case MESA_FORMAT_BGR888:
1371 *datatype = GL_UNSIGNED_BYTE;
1372 *comps = 3;
1373 return;
1374 case MESA_FORMAT_RGB565:
1375 case MESA_FORMAT_RGB565_REV:
1376 *datatype = GL_UNSIGNED_SHORT_5_6_5;
1377 *comps = 3;
1378 return;
1379
1380 case MESA_FORMAT_ARGB4444:
1381 case MESA_FORMAT_ARGB4444_REV:
1382 *datatype = GL_UNSIGNED_SHORT_4_4_4_4;
1383 *comps = 4;
1384 return;
1385
1386 case MESA_FORMAT_ARGB1555:
1387 case MESA_FORMAT_ARGB1555_REV:
1388 *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
1389 *comps = 4;
1390 return;
1391
1392 case MESA_FORMAT_AL88:
1393 case MESA_FORMAT_AL88_REV:
1394 *datatype = GL_UNSIGNED_BYTE;
1395 *comps = 2;
1396 return;
1397 case MESA_FORMAT_RGB332:
1398 *datatype = GL_UNSIGNED_BYTE_3_3_2;
1399 *comps = 3;
1400 return;
1401
1402 case MESA_FORMAT_A8:
1403 case MESA_FORMAT_L8:
1404 case MESA_FORMAT_I8:
1405 case MESA_FORMAT_CI8:
1406 *datatype = GL_UNSIGNED_BYTE;
1407 *comps = 1;
1408 return;
1409
1410 case MESA_FORMAT_YCBCR:
1411 case MESA_FORMAT_YCBCR_REV:
1412 *datatype = GL_UNSIGNED_SHORT;
1413 *comps = 2;
1414 return;
1415
1416 case MESA_FORMAT_Z24_S8:
1417 *datatype = GL_UNSIGNED_INT;
1418 *comps = 1; /* XXX OK? */
1419 return;
1420
1421 case MESA_FORMAT_S8_Z24:
1422 *datatype = GL_UNSIGNED_INT;
1423 *comps = 1; /* XXX OK? */
1424 return;
1425
1426 case MESA_FORMAT_Z16:
1427 *datatype = GL_UNSIGNED_SHORT;
1428 *comps = 1;
1429 return;
1430
1431 case MESA_FORMAT_Z32:
1432 *datatype = GL_UNSIGNED_INT;
1433 *comps = 1;
1434 return;
1435
1436 case MESA_FORMAT_DUDV8:
1437 *datatype = GL_BYTE;
1438 *comps = 2;
1439 return;
1440
1441 case MESA_FORMAT_SIGNED_RGBA8888:
1442 case MESA_FORMAT_SIGNED_RGBA8888_REV:
1443 *datatype = GL_BYTE;
1444 *comps = 4;
1445 return;
1446
1447 #if FEATURE_EXT_texture_sRGB
1448 case MESA_FORMAT_SRGB8:
1449 *datatype = GL_UNSIGNED_BYTE;
1450 *comps = 3;
1451 return;
1452 case MESA_FORMAT_SRGBA8:
1453 case MESA_FORMAT_SARGB8:
1454 *datatype = GL_UNSIGNED_BYTE;
1455 *comps = 4;
1456 return;
1457 case MESA_FORMAT_SL8:
1458 *datatype = GL_UNSIGNED_BYTE;
1459 *comps = 1;
1460 return;
1461 case MESA_FORMAT_SLA8:
1462 *datatype = GL_UNSIGNED_BYTE;
1463 *comps = 2;
1464 return;
1465 #endif
1466
1467 #if FEATURE_texture_fxt1
1468 case MESA_FORMAT_RGB_FXT1:
1469 case MESA_FORMAT_RGBA_FXT1:
1470 #endif
1471 #if FEATURE_texture_s3tc
1472 case MESA_FORMAT_RGB_DXT1:
1473 case MESA_FORMAT_RGBA_DXT1:
1474 case MESA_FORMAT_RGBA_DXT3:
1475 case MESA_FORMAT_RGBA_DXT5:
1476 #if FEATURE_EXT_texture_sRGB
1477 case MESA_FORMAT_SRGB_DXT1:
1478 case MESA_FORMAT_SRGBA_DXT1:
1479 case MESA_FORMAT_SRGBA_DXT3:
1480 case MESA_FORMAT_SRGBA_DXT5:
1481 #endif
1482 /* XXX generate error instead? */
1483 *datatype = GL_UNSIGNED_BYTE;
1484 *comps = 0;
1485 return;
1486 #endif
1487
1488 case MESA_FORMAT_RGBA:
1489 *datatype = CHAN_TYPE;
1490 *comps = 4;
1491 return;
1492 case MESA_FORMAT_RGB:
1493 *datatype = CHAN_TYPE;
1494 *comps = 3;
1495 return;
1496 case MESA_FORMAT_LUMINANCE_ALPHA:
1497 *datatype = CHAN_TYPE;
1498 *comps = 2;
1499 return;
1500 case MESA_FORMAT_ALPHA:
1501 case MESA_FORMAT_LUMINANCE:
1502 case MESA_FORMAT_INTENSITY:
1503 *datatype = CHAN_TYPE;
1504 *comps = 1;
1505 return;
1506
1507 case MESA_FORMAT_RGBA_FLOAT32:
1508 *datatype = GL_FLOAT;
1509 *comps = 4;
1510 return;
1511 case MESA_FORMAT_RGBA_FLOAT16:
1512 *datatype = GL_HALF_FLOAT_ARB;
1513 *comps = 4;
1514 return;
1515 case MESA_FORMAT_RGB_FLOAT32:
1516 *datatype = GL_FLOAT;
1517 *comps = 3;
1518 return;
1519 case MESA_FORMAT_RGB_FLOAT16:
1520 *datatype = GL_HALF_FLOAT_ARB;
1521 *comps = 3;
1522 return;
1523 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
1524 *datatype = GL_FLOAT;
1525 *comps = 2;
1526 return;
1527 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
1528 *datatype = GL_HALF_FLOAT_ARB;
1529 *comps = 2;
1530 return;
1531 case MESA_FORMAT_ALPHA_FLOAT32:
1532 case MESA_FORMAT_LUMINANCE_FLOAT32:
1533 case MESA_FORMAT_INTENSITY_FLOAT32:
1534 *datatype = GL_FLOAT;
1535 *comps = 1;
1536 return;
1537 case MESA_FORMAT_ALPHA_FLOAT16:
1538 case MESA_FORMAT_LUMINANCE_FLOAT16:
1539 case MESA_FORMAT_INTENSITY_FLOAT16:
1540 *datatype = GL_HALF_FLOAT_ARB;
1541 *comps = 1;
1542 return;
1543
1544 default:
1545 _mesa_problem(NULL, "bad format in _mesa_format_to_type_and_comps");
1546 *datatype = 0;
1547 *comps = 1;
1548 }
1549 }
1550
1551
1552
1553 /**
1554 * Table to map MESA_FORMAT_ to texel fetch/store funcs.
1555 * XXX this is somewhat temporary.
1556 */
1557 static struct {
1558 GLuint Name;
1559 FetchTexelFuncF Fetch1D;
1560 FetchTexelFuncF Fetch2D;
1561 FetchTexelFuncF Fetch3D;
1562 StoreTexelFunc StoreTexel;
1563 }
1564 texfetch_funcs[MESA_FORMAT_COUNT] =
1565 {
1566 {
1567 MESA_FORMAT_RGBA,
1568 fetch_texel_1d_f_rgba,
1569 fetch_texel_2d_f_rgba,
1570 fetch_texel_3d_f_rgba,
1571 store_texel_rgba
1572 },
1573 {
1574 MESA_FORMAT_RGB,
1575 fetch_texel_1d_f_rgb,
1576 fetch_texel_2d_f_rgb,
1577 fetch_texel_3d_f_rgb,
1578 store_texel_rgb
1579 },
1580 {
1581 MESA_FORMAT_ALPHA,
1582 fetch_texel_1d_f_alpha,
1583 fetch_texel_2d_f_alpha,
1584 fetch_texel_3d_f_alpha,
1585 store_texel_alpha
1586 },
1587 {
1588 MESA_FORMAT_LUMINANCE,
1589 fetch_texel_1d_f_luminance,
1590 fetch_texel_2d_f_luminance,
1591 fetch_texel_3d_f_luminance,
1592 store_texel_luminance
1593 },
1594 {
1595 MESA_FORMAT_LUMINANCE_ALPHA,
1596 fetch_texel_1d_f_luminance_alpha,
1597 fetch_texel_2d_f_luminance_alpha,
1598 fetch_texel_3d_f_luminance_alpha,
1599 store_texel_luminance_alpha
1600 },
1601 {
1602 MESA_FORMAT_INTENSITY,
1603 fetch_texel_1d_f_intensity,
1604 fetch_texel_2d_f_intensity,
1605 fetch_texel_3d_f_intensity,
1606 store_texel_intensity
1607 },
1608 {
1609 MESA_FORMAT_SRGB8,
1610 fetch_texel_1d_srgb8,
1611 fetch_texel_2d_srgb8,
1612 fetch_texel_3d_srgb8,
1613 store_texel_srgb8
1614 },
1615 {
1616 MESA_FORMAT_SRGBA8,
1617 fetch_texel_1d_srgba8,
1618 fetch_texel_2d_srgba8,
1619 fetch_texel_3d_srgba8,
1620 store_texel_srgba8
1621 },
1622 {
1623 MESA_FORMAT_SARGB8,
1624 fetch_texel_1d_sargb8,
1625 fetch_texel_2d_sargb8,
1626 fetch_texel_3d_sargb8,
1627 store_texel_sargb8
1628 },
1629 {
1630 MESA_FORMAT_SL8,
1631 fetch_texel_1d_sl8,
1632 fetch_texel_2d_sl8,
1633 fetch_texel_3d_sl8,
1634 store_texel_sl8
1635 },
1636 {
1637 MESA_FORMAT_SLA8,
1638 fetch_texel_1d_sla8,
1639 fetch_texel_2d_sla8,
1640 fetch_texel_3d_sla8,
1641 store_texel_sla8
1642 },
1643 {
1644 MESA_FORMAT_RGB_FXT1,
1645 NULL,
1646 _mesa_fetch_texel_2d_f_rgb_fxt1,
1647 NULL,
1648 NULL
1649 },
1650 {
1651 MESA_FORMAT_RGBA_FXT1,
1652 NULL,
1653 _mesa_fetch_texel_2d_f_rgba_fxt1,
1654 NULL,
1655 NULL
1656 },
1657 {
1658 MESA_FORMAT_RGB_DXT1,
1659 NULL,
1660 _mesa_fetch_texel_2d_f_rgb_dxt1,
1661 NULL,
1662 NULL
1663 },
1664 {
1665 MESA_FORMAT_RGBA_DXT1,
1666 NULL,
1667 _mesa_fetch_texel_2d_f_rgba_dxt1,
1668 NULL,
1669 NULL
1670 },
1671 {
1672 MESA_FORMAT_RGBA_DXT3,
1673 NULL,
1674 _mesa_fetch_texel_2d_f_rgba_dxt3,
1675 NULL,
1676 NULL
1677 },
1678 {
1679 MESA_FORMAT_RGBA_DXT5,
1680 NULL,
1681 _mesa_fetch_texel_2d_f_rgba_dxt5,
1682 NULL,
1683 NULL
1684 },
1685 {
1686 MESA_FORMAT_SRGB_DXT1,
1687 NULL,
1688 _mesa_fetch_texel_2d_f_srgb_dxt1,
1689 NULL,
1690 NULL
1691 },
1692 {
1693 MESA_FORMAT_SRGBA_DXT1,
1694 NULL,
1695 _mesa_fetch_texel_2d_f_srgba_dxt1,
1696 NULL,
1697 NULL
1698 },
1699 {
1700 MESA_FORMAT_SRGBA_DXT3,
1701 NULL,
1702 _mesa_fetch_texel_2d_f_srgba_dxt3,
1703 NULL,
1704 NULL
1705 },
1706 {
1707 MESA_FORMAT_SRGBA_DXT5,
1708 NULL,
1709 _mesa_fetch_texel_2d_f_srgba_dxt5,
1710 NULL,
1711 NULL
1712 },
1713 {
1714 MESA_FORMAT_RGBA_FLOAT32,
1715 fetch_texel_1d_f_rgba_f32,
1716 fetch_texel_2d_f_rgba_f32,
1717 fetch_texel_3d_f_rgba_f32,
1718 store_texel_rgba_f32
1719 },
1720 {
1721 MESA_FORMAT_RGBA_FLOAT16,
1722 fetch_texel_1d_f_rgba_f16,
1723 fetch_texel_2d_f_rgba_f16,
1724 fetch_texel_3d_f_rgba_f16,
1725 store_texel_rgba_f16
1726 },
1727 {
1728 MESA_FORMAT_RGB_FLOAT32,
1729 fetch_texel_1d_f_rgb_f32,
1730 fetch_texel_2d_f_rgb_f32,
1731 fetch_texel_3d_f_rgb_f32,
1732 store_texel_rgb_f32
1733 },
1734 {
1735 MESA_FORMAT_RGB_FLOAT16,
1736 fetch_texel_1d_f_rgb_f16,
1737 fetch_texel_2d_f_rgb_f16,
1738 fetch_texel_3d_f_rgb_f16,
1739 store_texel_rgb_f16
1740 },
1741 {
1742 MESA_FORMAT_ALPHA_FLOAT32,
1743 fetch_texel_1d_f_alpha_f32,
1744 fetch_texel_2d_f_alpha_f32,
1745 fetch_texel_3d_f_alpha_f32,
1746 store_texel_alpha_f32
1747 },
1748 {
1749 MESA_FORMAT_ALPHA_FLOAT16,
1750 fetch_texel_1d_f_alpha_f16,
1751 fetch_texel_2d_f_alpha_f16,
1752 fetch_texel_3d_f_alpha_f16,
1753 store_texel_alpha_f16
1754 },
1755 {
1756 MESA_FORMAT_LUMINANCE_FLOAT32,
1757 fetch_texel_1d_f_luminance_f32,
1758 fetch_texel_2d_f_luminance_f32,
1759 fetch_texel_3d_f_luminance_f32,
1760 store_texel_luminance_f32
1761 },
1762 {
1763 MESA_FORMAT_LUMINANCE_FLOAT16,
1764 fetch_texel_1d_f_luminance_f16,
1765 fetch_texel_2d_f_luminance_f16,
1766 fetch_texel_3d_f_luminance_f16,
1767 store_texel_luminance_f16
1768 },
1769 {
1770 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
1771 fetch_texel_1d_f_luminance_alpha_f32,
1772 fetch_texel_2d_f_luminance_alpha_f32,
1773 fetch_texel_3d_f_luminance_alpha_f32,
1774 store_texel_luminance_alpha_f32
1775 },
1776 {
1777 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
1778 fetch_texel_1d_f_luminance_alpha_f16,
1779 fetch_texel_2d_f_luminance_alpha_f16,
1780 fetch_texel_3d_f_luminance_alpha_f16,
1781 store_texel_luminance_alpha_f16
1782 },
1783 {
1784 MESA_FORMAT_INTENSITY_FLOAT32,
1785 fetch_texel_1d_f_intensity_f32,
1786 fetch_texel_2d_f_intensity_f32,
1787 fetch_texel_3d_f_intensity_f32,
1788 store_texel_intensity_f32
1789 },
1790 {
1791 MESA_FORMAT_INTENSITY_FLOAT16,
1792 fetch_texel_1d_f_intensity_f16,
1793 fetch_texel_2d_f_intensity_f16,
1794 fetch_texel_3d_f_intensity_f16,
1795 store_texel_intensity_f16
1796 },
1797 {
1798 MESA_FORMAT_DUDV8,
1799 fetch_texel_1d_dudv8,
1800 fetch_texel_2d_dudv8,
1801 fetch_texel_3d_dudv8,
1802 NULL
1803 },
1804 {
1805 MESA_FORMAT_SIGNED_RGBA8888,
1806 fetch_texel_1d_signed_rgba8888,
1807 fetch_texel_2d_signed_rgba8888,
1808 fetch_texel_3d_signed_rgba8888,
1809 store_texel_signed_rgba8888
1810 },
1811 {
1812 MESA_FORMAT_SIGNED_RGBA8888_REV,
1813 fetch_texel_1d_signed_rgba8888_rev,
1814 fetch_texel_2d_signed_rgba8888_rev,
1815 fetch_texel_3d_signed_rgba8888_rev,
1816 store_texel_signed_rgba8888_rev
1817 },
1818 {
1819 MESA_FORMAT_RGBA8888,
1820 fetch_texel_1d_f_rgba8888,
1821 fetch_texel_2d_f_rgba8888,
1822 fetch_texel_3d_f_rgba8888,
1823 store_texel_rgba8888
1824 },
1825 {
1826 MESA_FORMAT_RGBA8888_REV,
1827 fetch_texel_1d_f_rgba8888_rev,
1828 fetch_texel_2d_f_rgba8888_rev,
1829 fetch_texel_3d_f_rgba8888_rev,
1830 store_texel_rgba8888_rev
1831 },
1832 {
1833 MESA_FORMAT_ARGB8888,
1834 fetch_texel_1d_f_argb8888,
1835 fetch_texel_2d_f_argb8888,
1836 fetch_texel_3d_f_argb8888,
1837 store_texel_argb8888
1838 },
1839 {
1840 MESA_FORMAT_ARGB8888_REV,
1841 fetch_texel_1d_f_argb8888_rev,
1842 fetch_texel_2d_f_argb8888_rev,
1843 fetch_texel_3d_f_argb8888_rev,
1844 store_texel_argb8888_rev
1845 },
1846 {
1847 MESA_FORMAT_RGB888,
1848 fetch_texel_1d_f_rgb888,
1849 fetch_texel_2d_f_rgb888,
1850 fetch_texel_3d_f_rgb888,
1851 store_texel_rgb888
1852 },
1853 {
1854 MESA_FORMAT_BGR888,
1855 fetch_texel_1d_f_bgr888,
1856 fetch_texel_2d_f_bgr888,
1857 fetch_texel_3d_f_bgr888,
1858 store_texel_bgr888
1859 },
1860 {
1861 MESA_FORMAT_RGB565,
1862 fetch_texel_1d_f_rgb565,
1863 fetch_texel_2d_f_rgb565,
1864 fetch_texel_3d_f_rgb565,
1865 store_texel_rgb565
1866 },
1867 {
1868 MESA_FORMAT_RGB565_REV,
1869 fetch_texel_1d_f_rgb565_rev,
1870 fetch_texel_2d_f_rgb565_rev,
1871 fetch_texel_3d_f_rgb565_rev,
1872 store_texel_rgb565_rev
1873 },
1874 {
1875 MESA_FORMAT_RGBA4444,
1876 fetch_texel_1d_f_rgba4444,
1877 fetch_texel_2d_f_rgba4444,
1878 fetch_texel_3d_f_rgba4444,
1879 store_texel_rgba4444
1880 },
1881 {
1882 MESA_FORMAT_ARGB4444,
1883 fetch_texel_1d_f_argb4444,
1884 fetch_texel_2d_f_argb4444,
1885 fetch_texel_3d_f_argb4444,
1886 store_texel_argb4444
1887 },
1888 {
1889 MESA_FORMAT_ARGB4444_REV,
1890 fetch_texel_1d_f_argb4444_rev,
1891 fetch_texel_2d_f_argb4444_rev,
1892 fetch_texel_3d_f_argb4444_rev,
1893 store_texel_argb4444_rev
1894 },
1895 {
1896 MESA_FORMAT_RGBA5551,
1897 fetch_texel_1d_f_rgba5551,
1898 fetch_texel_2d_f_rgba5551,
1899 fetch_texel_3d_f_rgba5551,
1900 store_texel_rgba5551
1901 },
1902 {
1903 MESA_FORMAT_ARGB1555,
1904 fetch_texel_1d_f_argb1555,
1905 fetch_texel_2d_f_argb1555,
1906 fetch_texel_3d_f_argb1555,
1907 store_texel_argb1555
1908 },
1909 {
1910 MESA_FORMAT_ARGB1555_REV,
1911 fetch_texel_1d_f_argb1555_rev,
1912 fetch_texel_2d_f_argb1555_rev,
1913 fetch_texel_3d_f_argb1555_rev,
1914 store_texel_argb1555_rev
1915 },
1916 {
1917 MESA_FORMAT_AL88,
1918 fetch_texel_1d_f_al88,
1919 fetch_texel_2d_f_al88,
1920 fetch_texel_3d_f_al88,
1921 store_texel_al88
1922 },
1923 {
1924 MESA_FORMAT_AL88_REV,
1925 fetch_texel_1d_f_al88_rev,
1926 fetch_texel_2d_f_al88_rev,
1927 fetch_texel_3d_f_al88_rev,
1928 store_texel_al88_rev
1929 },
1930 {
1931 MESA_FORMAT_RGB332,
1932 fetch_texel_1d_f_rgb332,
1933 fetch_texel_2d_f_rgb332,
1934 fetch_texel_3d_f_rgb332,
1935 store_texel_rgb332
1936 },
1937 {
1938 MESA_FORMAT_A8,
1939 fetch_texel_1d_f_a8,
1940 fetch_texel_2d_f_a8,
1941 fetch_texel_3d_f_a8,
1942 store_texel_a8
1943 },
1944 {
1945 MESA_FORMAT_L8,
1946 fetch_texel_1d_f_l8,
1947 fetch_texel_2d_f_l8,
1948 fetch_texel_3d_f_l8,
1949 store_texel_l8
1950 },
1951 {
1952 MESA_FORMAT_I8,
1953 fetch_texel_1d_f_i8,
1954 fetch_texel_2d_f_i8,
1955 fetch_texel_3d_f_i8,
1956 store_texel_i8
1957 },
1958 {
1959 MESA_FORMAT_CI8,
1960 fetch_texel_1d_f_ci8,
1961 fetch_texel_2d_f_ci8,
1962 fetch_texel_3d_f_ci8,
1963 store_texel_ci8
1964 },
1965 {
1966 MESA_FORMAT_YCBCR,
1967 fetch_texel_1d_f_ycbcr,
1968 fetch_texel_2d_f_ycbcr,
1969 fetch_texel_3d_f_ycbcr,
1970 store_texel_ycbcr
1971 },
1972 {
1973 MESA_FORMAT_YCBCR_REV,
1974 fetch_texel_1d_f_ycbcr_rev,
1975 fetch_texel_2d_f_ycbcr_rev,
1976 fetch_texel_3d_f_ycbcr_rev,
1977 store_texel_ycbcr_rev
1978 },
1979 {
1980 MESA_FORMAT_Z24_S8,
1981 fetch_texel_1d_f_z24_s8,
1982 fetch_texel_2d_f_z24_s8,
1983 fetch_texel_3d_f_z24_s8,
1984 store_texel_z24_s8
1985 },
1986 {
1987 MESA_FORMAT_S8_Z24,
1988 fetch_texel_1d_f_s8_z24,
1989 fetch_texel_2d_f_s8_z24,
1990 fetch_texel_3d_f_s8_z24,
1991 store_texel_s8_z24
1992 },
1993 {
1994 MESA_FORMAT_Z16,
1995 fetch_texel_1d_f_z16,
1996 fetch_texel_2d_f_z16,
1997 fetch_texel_3d_f_z16,
1998 store_texel_z16
1999 },
2000 {
2001 MESA_FORMAT_Z32,
2002 fetch_texel_1d_f_z32,
2003 fetch_texel_2d_f_z32,
2004 fetch_texel_3d_f_z32,
2005 store_texel_z32
2006 }
2007 };
2008
2009
2010 FetchTexelFuncF
2011 _mesa_get_texel_fetch_func(GLuint format, GLuint dims)
2012 {
2013 FetchTexelFuncF f;
2014 GLuint i;
2015 /* XXX replace loop with direct table lookup */
2016 for (i = 0; i < MESA_FORMAT_COUNT; i++) {
2017 if (texfetch_funcs[i].Name == format) {
2018 switch (dims) {
2019 case 1:
2020 f = texfetch_funcs[i].Fetch1D;
2021 break;
2022 case 2:
2023 f = texfetch_funcs[i].Fetch2D;
2024 break;
2025 case 3:
2026 f = texfetch_funcs[i].Fetch3D;
2027 break;
2028 }
2029 if (!f)
2030 f = fetch_null_texelf;
2031 return f;
2032 }
2033 }
2034 return NULL;
2035 }
2036
2037
2038 StoreTexelFunc
2039 _mesa_get_texel_store_func(GLuint format)
2040 {
2041 GLuint i;
2042 /* XXX replace loop with direct table lookup */
2043 for (i = 0; i < MESA_FORMAT_COUNT; i++) {
2044 if (texfetch_funcs[i].Name == format) {
2045 if (texfetch_funcs[i].StoreTexel)
2046 return texfetch_funcs[i].StoreTexel;
2047 else
2048 return store_null_texel;
2049 }
2050 }
2051 return NULL;
2052 }