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