mesa: bump MAX_PROGRAM_TEMPS to 256 (there's some big shaders out there)
[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 fetch_texel_1d_rgba, /* FetchTexel1D */
158 fetch_texel_2d_rgba, /* FetchTexel2D */
159 fetch_texel_3d_rgba, /* 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 fetch_texel_1d_rgb, /* FetchTexel1D */
182 fetch_texel_2d_rgb, /* FetchTexel2D */
183 fetch_texel_3d_rgb, /* 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 fetch_texel_1d_alpha, /* FetchTexel1D */
206 fetch_texel_2d_alpha, /* FetchTexel2D */
207 fetch_texel_3d_alpha, /* FetchTexel3D */
208 NULL, /* FetchTexel1Df */
209 NULL, /* FetchTexel2Df */
210 NULL, /* 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 fetch_texel_1d_luminance, /* FetchTexel1D */
230 fetch_texel_2d_luminance, /* FetchTexel2D */
231 fetch_texel_3d_luminance, /* FetchTexel3D */
232 NULL, /* FetchTexel1Df */
233 NULL, /* FetchTexel2Df */
234 NULL, /* 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 fetch_texel_1d_luminance_alpha, /* FetchTexel1D */
254 fetch_texel_2d_luminance_alpha, /* FetchTexel2D */
255 fetch_texel_3d_luminance_alpha, /* FetchTexel3D */
256 NULL, /* FetchTexel1Df */
257 NULL, /* FetchTexel2Df */
258 NULL, /* 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 fetch_texel_1d_intensity, /* FetchTexel1D */
278 fetch_texel_2d_intensity, /* FetchTexel2D */
279 fetch_texel_3d_intensity, /* FetchTexel3D */
280 NULL, /* FetchTexel1Df */
281 NULL, /* FetchTexel2Df */
282 NULL, /* 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 const struct gl_texture_format _mesa_texformat_sla8 = {
386 MESA_FORMAT_SLA8, /* MesaFormat */
387 GL_LUMINANCE_ALPHA, /* BaseFormat */
388 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
389 0, /* RedBits */
390 0, /* GreenBits */
391 0, /* BlueBits */
392 8, /* AlphaBits */
393 8, /* LuminanceBits */
394 0, /* IntensityBits */
395 0, /* IndexBits */
396 0, /* DepthBits */
397 0, /* StencilBits */
398 2, /* TexelBytes */
399 _mesa_texstore_sla8, /* StoreTexImageFunc */
400 NULL, /* FetchTexel1D */
401 NULL, /* FetchTexel2D */
402 NULL, /* FetchTexel3D */
403 fetch_texel_1d_sla8, /* FetchTexel1Df */
404 fetch_texel_2d_sla8, /* FetchTexel2Df */
405 fetch_texel_3d_sla8, /* FetchTexel3Df */
406 store_texel_sla8 /* StoreTexel */
407 };
408
409 #endif /* FEATURE_EXT_texture_sRGB */
410
411 const struct gl_texture_format _mesa_texformat_rgba_float32 = {
412 MESA_FORMAT_RGBA_FLOAT32, /* MesaFormat */
413 GL_RGBA, /* BaseFormat */
414 GL_FLOAT, /* DataType */
415 8 * sizeof(GLfloat), /* RedBits */
416 8 * sizeof(GLfloat), /* GreenBits */
417 8 * sizeof(GLfloat), /* BlueBits */
418 8 * sizeof(GLfloat), /* AlphaBits */
419 0, /* LuminanceBits */
420 0, /* IntensityBits */
421 0, /* IndexBits */
422 0, /* DepthBits */
423 0, /* StencilBits */
424 4 * sizeof(GLfloat), /* TexelBytes */
425 _mesa_texstore_rgba_float32, /* StoreTexImageFunc */
426 NULL, /* FetchTexel1D */
427 NULL, /* FetchTexel1D */
428 NULL, /* FetchTexel1D */
429 fetch_texel_1d_f_rgba_f32, /* FetchTexel1Df */
430 fetch_texel_2d_f_rgba_f32, /* FetchTexel2Df */
431 fetch_texel_3d_f_rgba_f32, /* FetchTexel3Df */
432 store_texel_rgba_f32 /* StoreTexel */
433 };
434
435 const struct gl_texture_format _mesa_texformat_rgba_float16 = {
436 MESA_FORMAT_RGBA_FLOAT16, /* MesaFormat */
437 GL_RGBA, /* BaseFormat */
438 GL_FLOAT, /* DataType */
439 8 * sizeof(GLhalfARB), /* RedBits */
440 8 * sizeof(GLhalfARB), /* GreenBits */
441 8 * sizeof(GLhalfARB), /* BlueBits */
442 8 * sizeof(GLhalfARB), /* AlphaBits */
443 0, /* LuminanceBits */
444 0, /* IntensityBits */
445 0, /* IndexBits */
446 0, /* DepthBits */
447 0, /* StencilBits */
448 4 * sizeof(GLhalfARB), /* TexelBytes */
449 _mesa_texstore_rgba_float16, /* StoreTexImageFunc */
450 NULL, /* FetchTexel1D */
451 NULL, /* FetchTexel1D */
452 NULL, /* FetchTexel1D */
453 fetch_texel_1d_f_rgba_f16, /* FetchTexel1Df */
454 fetch_texel_2d_f_rgba_f16, /* FetchTexel2Df */
455 fetch_texel_3d_f_rgba_f16, /* FetchTexel3Df */
456 store_texel_rgba_f16 /* StoreTexel */
457 };
458
459 const struct gl_texture_format _mesa_texformat_rgb_float32 = {
460 MESA_FORMAT_RGB_FLOAT32, /* MesaFormat */
461 GL_RGB, /* BaseFormat */
462 GL_FLOAT, /* DataType */
463 8 * sizeof(GLfloat), /* RedBits */
464 8 * sizeof(GLfloat), /* GreenBits */
465 8 * sizeof(GLfloat), /* BlueBits */
466 0, /* AlphaBits */
467 0, /* LuminanceBits */
468 0, /* IntensityBits */
469 0, /* IndexBits */
470 0, /* DepthBits */
471 0, /* StencilBits */
472 3 * sizeof(GLfloat), /* TexelBytes */
473 _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */
474 NULL, /* FetchTexel1D */
475 NULL, /* FetchTexel1D */
476 NULL, /* FetchTexel1D */
477 fetch_texel_1d_f_rgb_f32, /* FetchTexel1Df */
478 fetch_texel_2d_f_rgb_f32, /* FetchTexel2Df */
479 fetch_texel_3d_f_rgb_f32, /* FetchTexel3Df */
480 store_texel_rgb_f32 /* StoreTexel */
481 };
482
483 const struct gl_texture_format _mesa_texformat_rgb_float16 = {
484 MESA_FORMAT_RGB_FLOAT16, /* MesaFormat */
485 GL_RGB, /* BaseFormat */
486 GL_FLOAT, /* DataType */
487 8 * sizeof(GLhalfARB), /* RedBits */
488 8 * sizeof(GLhalfARB), /* GreenBits */
489 8 * sizeof(GLhalfARB), /* BlueBits */
490 0, /* AlphaBits */
491 0, /* LuminanceBits */
492 0, /* IntensityBits */
493 0, /* IndexBits */
494 0, /* DepthBits */
495 0, /* StencilBits */
496 3 * sizeof(GLhalfARB), /* TexelBytes */
497 _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */
498 NULL, /* FetchTexel1D */
499 NULL, /* FetchTexel1D */
500 NULL, /* FetchTexel1D */
501 fetch_texel_1d_f_rgb_f16, /* FetchTexel1Df */
502 fetch_texel_2d_f_rgb_f16, /* FetchTexel2Df */
503 fetch_texel_3d_f_rgb_f16, /* FetchTexel3Df */
504 store_texel_rgb_f16 /* StoreTexel */
505 };
506
507 const struct gl_texture_format _mesa_texformat_alpha_float32 = {
508 MESA_FORMAT_ALPHA_FLOAT32, /* MesaFormat */
509 GL_ALPHA, /* BaseFormat */
510 GL_FLOAT, /* DataType */
511 0, /* RedBits */
512 0, /* GreenBits */
513 0, /* BlueBits */
514 8 * sizeof(GLfloat), /* AlphaBits */
515 0, /* LuminanceBits */
516 0, /* IntensityBits */
517 0, /* IndexBits */
518 0, /* DepthBits */
519 0, /* StencilBits */
520 1 * sizeof(GLfloat), /* TexelBytes */
521 _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */
522 NULL, /* FetchTexel1D */
523 NULL, /* FetchTexel1D */
524 NULL, /* FetchTexel1D */
525 fetch_texel_1d_f_alpha_f32, /* FetchTexel1Df */
526 fetch_texel_2d_f_alpha_f32, /* FetchTexel2Df */
527 fetch_texel_3d_f_alpha_f32, /* FetchTexel3Df */
528 store_texel_alpha_f32 /* StoreTexel */
529 };
530
531 const struct gl_texture_format _mesa_texformat_alpha_float16 = {
532 MESA_FORMAT_ALPHA_FLOAT16, /* MesaFormat */
533 GL_ALPHA, /* BaseFormat */
534 GL_FLOAT, /* DataType */
535 0, /* RedBits */
536 0, /* GreenBits */
537 0, /* BlueBits */
538 8 * sizeof(GLhalfARB), /* AlphaBits */
539 0, /* LuminanceBits */
540 0, /* IntensityBits */
541 0, /* IndexBits */
542 0, /* DepthBits */
543 0, /* StencilBits */
544 1 * sizeof(GLhalfARB), /* TexelBytes */
545 _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */
546 NULL, /* FetchTexel1D */
547 NULL, /* FetchTexel1D */
548 NULL, /* FetchTexel1D */
549 fetch_texel_1d_f_alpha_f16, /* FetchTexel1Df */
550 fetch_texel_2d_f_alpha_f16, /* FetchTexel2Df */
551 fetch_texel_3d_f_alpha_f16, /* FetchTexel3Df */
552 store_texel_alpha_f16 /* StoreTexel */
553 };
554
555 const struct gl_texture_format _mesa_texformat_luminance_float32 = {
556 MESA_FORMAT_LUMINANCE_FLOAT32, /* MesaFormat */
557 GL_LUMINANCE, /* BaseFormat */
558 GL_FLOAT, /* DataType */
559 0, /* RedBits */
560 0, /* GreenBits */
561 0, /* BlueBits */
562 0, /* AlphaBits */
563 8 * sizeof(GLfloat), /* LuminanceBits */
564 0, /* IntensityBits */
565 0, /* IndexBits */
566 0, /* DepthBits */
567 0, /* StencilBits */
568 1 * sizeof(GLfloat), /* TexelBytes */
569 _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */
570 NULL, /* FetchTexel1D */
571 NULL, /* FetchTexel2D */
572 NULL, /* FetchTexel3D */
573 fetch_texel_1d_f_luminance_f32, /* FetchTexel1Df */
574 fetch_texel_2d_f_luminance_f32, /* FetchTexel2Df */
575 fetch_texel_3d_f_luminance_f32, /* FetchTexel3Df */
576 store_texel_luminance_f32 /* StoreTexel */
577 };
578
579 const struct gl_texture_format _mesa_texformat_luminance_float16 = {
580 MESA_FORMAT_LUMINANCE_FLOAT16, /* MesaFormat */
581 GL_LUMINANCE, /* BaseFormat */
582 GL_FLOAT, /* DataType */
583 0, /* RedBits */
584 0, /* GreenBits */
585 0, /* BlueBits */
586 0, /* AlphaBits */
587 8 * sizeof(GLhalfARB), /* LuminanceBits */
588 0, /* IntensityBits */
589 0, /* IndexBits */
590 0, /* DepthBits */
591 0, /* StencilBits */
592 1 * sizeof(GLhalfARB), /* TexelBytes */
593 _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */
594 NULL, /* FetchTexel1D */
595 NULL, /* FetchTexel2D */
596 NULL, /* FetchTexel3D */
597 fetch_texel_1d_f_luminance_f16, /* FetchTexel1Df */
598 fetch_texel_2d_f_luminance_f16, /* FetchTexel2Df */
599 fetch_texel_3d_f_luminance_f16, /* FetchTexel3Df */
600 store_texel_luminance_f16 /* StoreTexel */
601 };
602
603 const struct gl_texture_format _mesa_texformat_luminance_alpha_float32 = {
604 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32, /* MesaFormat */
605 GL_LUMINANCE_ALPHA, /* BaseFormat */
606 GL_FLOAT, /* DataType */
607 0, /* RedBits */
608 0, /* GreenBits */
609 0, /* BlueBits */
610 8 * sizeof(GLfloat), /* AlphaBits */
611 8 * sizeof(GLfloat), /* LuminanceBits */
612 0, /* IntensityBits */
613 0, /* IndexBits */
614 0, /* DepthBits */
615 0, /* StencilBits */
616 2 * sizeof(GLfloat), /* TexelBytes */
617 _mesa_texstore_rgba_float32, /* StoreTexImageFunc */
618 NULL, /* FetchTexel1D */
619 NULL, /* FetchTexel2D */
620 NULL, /* FetchTexel3D */
621 fetch_texel_1d_f_luminance_alpha_f32,/* FetchTexel1Df */
622 fetch_texel_2d_f_luminance_alpha_f32,/* FetchTexel2Df */
623 fetch_texel_3d_f_luminance_alpha_f32,/* FetchTexel3Df */
624 store_texel_luminance_alpha_f32 /* StoreTexel */
625 };
626
627 const struct gl_texture_format _mesa_texformat_luminance_alpha_float16 = {
628 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16, /* MesaFormat */
629 GL_LUMINANCE_ALPHA, /* BaseFormat */
630 GL_FLOAT, /* DataType */
631 0, /* RedBits */
632 0, /* GreenBits */
633 0, /* BlueBits */
634 8 * sizeof(GLhalfARB), /* AlphaBits */
635 8 * sizeof(GLhalfARB), /* LuminanceBits */
636 0, /* IntensityBits */
637 0, /* IndexBits */
638 0, /* DepthBits */
639 0, /* StencilBits */
640 2 * sizeof(GLhalfARB), /* TexelBytes */
641 _mesa_texstore_rgba_float16, /* StoreTexImageFunc */
642 NULL, /* FetchTexel1D */
643 NULL, /* FetchTexel2D */
644 NULL, /* FetchTexel3D */
645 fetch_texel_1d_f_luminance_alpha_f16,/* FetchTexel1Df */
646 fetch_texel_2d_f_luminance_alpha_f16,/* FetchTexel2Df */
647 fetch_texel_3d_f_luminance_alpha_f16,/* FetchTexel3Df */
648 store_texel_luminance_alpha_f16 /* StoreTexel */
649 };
650
651 const struct gl_texture_format _mesa_texformat_intensity_float32 = {
652 MESA_FORMAT_INTENSITY_FLOAT32, /* MesaFormat */
653 GL_INTENSITY, /* BaseFormat */
654 GL_FLOAT, /* DataType */
655 0, /* RedBits */
656 0, /* GreenBits */
657 0, /* BlueBits */
658 0, /* AlphaBits */
659 0, /* LuminanceBits */
660 8 * sizeof(GLfloat), /* IntensityBits */
661 0, /* IndexBits */
662 0, /* DepthBits */
663 0, /* StencilBits */
664 1 * sizeof(GLfloat), /* TexelBytes */
665 _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */
666 NULL, /* FetchTexel1D */
667 NULL, /* FetchTexel2D */
668 NULL, /* FetchTexel3D */
669 fetch_texel_1d_f_intensity_f32, /* FetchTexel1Df */
670 fetch_texel_2d_f_intensity_f32, /* FetchTexel2Df */
671 fetch_texel_3d_f_intensity_f32, /* FetchTexel3Df */
672 store_texel_intensity_f32 /* StoreTexel */
673 };
674
675 const struct gl_texture_format _mesa_texformat_intensity_float16 = {
676 MESA_FORMAT_INTENSITY_FLOAT16, /* MesaFormat */
677 GL_INTENSITY, /* BaseFormat */
678 GL_FLOAT, /* DataType */
679 0, /* RedBits */
680 0, /* GreenBits */
681 0, /* BlueBits */
682 0, /* AlphaBits */
683 0, /* LuminanceBits */
684 8 * sizeof(GLhalfARB), /* IntensityBits */
685 0, /* IndexBits */
686 0, /* DepthBits */
687 0, /* StencilBits */
688 1 * sizeof(GLhalfARB), /* TexelBytes */
689 _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */
690 NULL, /* FetchTexel1D */
691 NULL, /* FetchTexel2D */
692 NULL, /* FetchTexel3D */
693 fetch_texel_1d_f_intensity_f16, /* FetchTexel1Df */
694 fetch_texel_2d_f_intensity_f16, /* FetchTexel2Df */
695 fetch_texel_3d_f_intensity_f16, /* FetchTexel3Df */
696 store_texel_intensity_f16 /* StoreTexel */
697 };
698
699 const struct gl_texture_format _mesa_texformat_dudv8 = {
700 MESA_FORMAT_DUDV8, /* MesaFormat */
701 GL_DUDV_ATI, /* BaseFormat */
702 /* FIXME: spec doesn't say since that parameter didn't exist then,
703 but this should be something like SIGNED_NORMALIZED */
704 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
705 /* maybe should add dudvBits field, but spec seems to be
706 lacking the ability to query with GetTexLevelParameter anyway */
707 0, /* RedBits */
708 0, /* GreenBits */
709 0, /* BlueBits */
710 0, /* AlphaBits */
711 0, /* LuminanceBits */
712 0, /* IntensityBits */
713 0, /* IndexBits */
714 0, /* DepthBits */
715 0, /* StencilBits */
716 2, /* TexelBytes */
717 _mesa_texstore_dudv8, /* StoreTexImageFunc */
718 NULL, /* FetchTexel1D */
719 NULL, /* FetchTexel2D */
720 NULL, /* FetchTexel3D */
721 fetch_texel_1d_dudv8, /* FetchTexel1Df */
722 fetch_texel_2d_dudv8, /* FetchTexel2Df */
723 fetch_texel_3d_dudv8, /* FetchTexel3Df */
724 NULL /* StoreTexel */
725 };
726
727 /*@}*/
728
729
730 /***************************************************************/
731 /** \name Hardware formats */
732 /*@{*/
733
734 const struct gl_texture_format _mesa_texformat_rgba8888 = {
735 MESA_FORMAT_RGBA8888, /* MesaFormat */
736 GL_RGBA, /* BaseFormat */
737 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
738 8, /* RedBits */
739 8, /* GreenBits */
740 8, /* BlueBits */
741 8, /* AlphaBits */
742 0, /* LuminanceBits */
743 0, /* IntensityBits */
744 0, /* IndexBits */
745 0, /* DepthBits */
746 0, /* StencilBits */
747 4, /* TexelBytes */
748 _mesa_texstore_rgba8888, /* StoreTexImageFunc */
749 fetch_texel_1d_rgba8888, /* FetchTexel1D */
750 fetch_texel_2d_rgba8888, /* FetchTexel2D */
751 fetch_texel_3d_rgba8888, /* FetchTexel3D */
752 NULL, /* FetchTexel1Df */
753 NULL, /* FetchTexel2Df */
754 NULL, /* FetchTexel3Df */
755 store_texel_rgba8888 /* StoreTexel */
756 };
757
758 const struct gl_texture_format _mesa_texformat_rgba8888_rev = {
759 MESA_FORMAT_RGBA8888_REV, /* MesaFormat */
760 GL_RGBA, /* BaseFormat */
761 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
762 8, /* RedBits */
763 8, /* GreenBits */
764 8, /* BlueBits */
765 8, /* AlphaBits */
766 0, /* LuminanceBits */
767 0, /* IntensityBits */
768 0, /* IndexBits */
769 0, /* DepthBits */
770 0, /* StencilBits */
771 4, /* TexelBytes */
772 _mesa_texstore_rgba8888, /* StoreTexImageFunc */
773 fetch_texel_1d_rgba8888_rev, /* FetchTexel1D */
774 fetch_texel_2d_rgba8888_rev, /* FetchTexel2D */
775 fetch_texel_3d_rgba8888_rev, /* FetchTexel3D */
776 NULL, /* FetchTexel1Df */
777 NULL, /* FetchTexel2Df */
778 NULL, /* FetchTexel3Df */
779 store_texel_rgba8888_rev /* StoreTexel */
780 };
781
782 const struct gl_texture_format _mesa_texformat_argb8888 = {
783 MESA_FORMAT_ARGB8888, /* MesaFormat */
784 GL_RGBA, /* BaseFormat */
785 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
786 8, /* RedBits */
787 8, /* GreenBits */
788 8, /* BlueBits */
789 8, /* AlphaBits */
790 0, /* LuminanceBits */
791 0, /* IntensityBits */
792 0, /* IndexBits */
793 0, /* DepthBits */
794 0, /* StencilBits */
795 4, /* TexelBytes */
796 _mesa_texstore_argb8888, /* StoreTexImageFunc */
797 fetch_texel_1d_argb8888, /* FetchTexel1D */
798 fetch_texel_2d_argb8888, /* FetchTexel2D */
799 fetch_texel_3d_argb8888, /* FetchTexel3D */
800 NULL, /* FetchTexel1Df */
801 NULL, /* FetchTexel2Df */
802 NULL, /* FetchTexel3Df */
803 store_texel_argb8888 /* StoreTexel */
804 };
805
806 const struct gl_texture_format _mesa_texformat_argb8888_rev = {
807 MESA_FORMAT_ARGB8888_REV, /* MesaFormat */
808 GL_RGBA, /* BaseFormat */
809 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
810 8, /* RedBits */
811 8, /* GreenBits */
812 8, /* BlueBits */
813 8, /* AlphaBits */
814 0, /* LuminanceBits */
815 0, /* IntensityBits */
816 0, /* IndexBits */
817 0, /* DepthBits */
818 0, /* StencilBits */
819 4, /* TexelBytes */
820 _mesa_texstore_argb8888, /* StoreTexImageFunc */
821 fetch_texel_1d_argb8888_rev, /* FetchTexel1D */
822 fetch_texel_2d_argb8888_rev, /* FetchTexel2D */
823 fetch_texel_3d_argb8888_rev, /* FetchTexel3D */
824 NULL, /* FetchTexel1Df */
825 NULL, /* FetchTexel2Df */
826 NULL, /* FetchTexel3Df */
827 store_texel_argb8888_rev /* StoreTexel */
828 };
829
830 const struct gl_texture_format _mesa_texformat_rgb888 = {
831 MESA_FORMAT_RGB888, /* MesaFormat */
832 GL_RGB, /* BaseFormat */
833 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
834 8, /* RedBits */
835 8, /* GreenBits */
836 8, /* BlueBits */
837 0, /* AlphaBits */
838 0, /* LuminanceBits */
839 0, /* IntensityBits */
840 0, /* IndexBits */
841 0, /* DepthBits */
842 0, /* StencilBits */
843 3, /* TexelBytes */
844 _mesa_texstore_rgb888, /* StoreTexImageFunc */
845 fetch_texel_1d_rgb888, /* FetchTexel1D */
846 fetch_texel_2d_rgb888, /* FetchTexel2D */
847 fetch_texel_3d_rgb888, /* FetchTexel3D */
848 NULL, /* FetchTexel1Df */
849 NULL, /* FetchTexel2Df */
850 NULL, /* FetchTexel3Df */
851 store_texel_rgb888 /* StoreTexel */
852 };
853
854 const struct gl_texture_format _mesa_texformat_bgr888 = {
855 MESA_FORMAT_BGR888, /* MesaFormat */
856 GL_RGB, /* BaseFormat */
857 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
858 8, /* RedBits */
859 8, /* GreenBits */
860 8, /* BlueBits */
861 0, /* AlphaBits */
862 0, /* LuminanceBits */
863 0, /* IntensityBits */
864 0, /* IndexBits */
865 0, /* DepthBits */
866 0, /* StencilBits */
867 3, /* TexelBytes */
868 _mesa_texstore_bgr888, /* StoreTexImageFunc */
869 fetch_texel_1d_bgr888, /* FetchTexel1D */
870 fetch_texel_2d_bgr888, /* FetchTexel2D */
871 fetch_texel_3d_bgr888, /* FetchTexel3D */
872 NULL, /* FetchTexel1Df */
873 NULL, /* FetchTexel2Df */
874 NULL, /* FetchTexel3Df */
875 store_texel_bgr888 /* StoreTexel */
876 };
877
878 const struct gl_texture_format _mesa_texformat_rgb565 = {
879 MESA_FORMAT_RGB565, /* MesaFormat */
880 GL_RGB, /* BaseFormat */
881 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
882 5, /* RedBits */
883 6, /* GreenBits */
884 5, /* BlueBits */
885 0, /* AlphaBits */
886 0, /* LuminanceBits */
887 0, /* IntensityBits */
888 0, /* IndexBits */
889 0, /* DepthBits */
890 0, /* StencilBits */
891 2, /* TexelBytes */
892 _mesa_texstore_rgb565, /* StoreTexImageFunc */
893 fetch_texel_1d_rgb565, /* FetchTexel1D */
894 fetch_texel_2d_rgb565, /* FetchTexel2D */
895 fetch_texel_3d_rgb565, /* FetchTexel3D */
896 NULL, /* FetchTexel1Df */
897 NULL, /* FetchTexel2Df */
898 NULL, /* FetchTexel3Df */
899 store_texel_rgb565 /* StoreTexel */
900 };
901
902 const struct gl_texture_format _mesa_texformat_rgb565_rev = {
903 MESA_FORMAT_RGB565_REV, /* MesaFormat */
904 GL_RGB, /* BaseFormat */
905 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
906 5, /* RedBits */
907 6, /* GreenBits */
908 5, /* BlueBits */
909 0, /* AlphaBits */
910 0, /* LuminanceBits */
911 0, /* IntensityBits */
912 0, /* IndexBits */
913 0, /* DepthBits */
914 0, /* StencilBits */
915 2, /* TexelBytes */
916 _mesa_texstore_rgb565, /* StoreTexImageFunc */
917 fetch_texel_1d_rgb565_rev, /* FetchTexel1D */
918 fetch_texel_2d_rgb565_rev, /* FetchTexel2D */
919 fetch_texel_3d_rgb565_rev, /* FetchTexel3D */
920 NULL, /* FetchTexel1Df */
921 NULL, /* FetchTexel2Df */
922 NULL, /* FetchTexel3Df */
923 store_texel_rgb565_rev /* StoreTexel */
924 };
925
926 const struct gl_texture_format _mesa_texformat_rgba4444 = {
927 MESA_FORMAT_RGBA4444, /* MesaFormat */
928 GL_RGBA, /* BaseFormat */
929 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
930 4, /* RedBits */
931 4, /* GreenBits */
932 4, /* BlueBits */
933 4, /* AlphaBits */
934 0, /* LuminanceBits */
935 0, /* IntensityBits */
936 0, /* IndexBits */
937 0, /* DepthBits */
938 0, /* StencilBits */
939 2, /* TexelBytes */
940 _mesa_texstore_rgba4444, /* StoreTexImageFunc */
941 fetch_texel_1d_rgba4444, /* FetchTexel1D */
942 fetch_texel_2d_rgba4444, /* FetchTexel2D */
943 fetch_texel_3d_rgba4444, /* FetchTexel3D */
944 NULL, /* FetchTexel1Df */
945 NULL, /* FetchTexel2Df */
946 NULL, /* FetchTexel3Df */
947 store_texel_rgba4444 /* StoreTexel */
948 };
949
950 const struct gl_texture_format _mesa_texformat_argb4444 = {
951 MESA_FORMAT_ARGB4444, /* MesaFormat */
952 GL_RGBA, /* BaseFormat */
953 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
954 4, /* RedBits */
955 4, /* GreenBits */
956 4, /* BlueBits */
957 4, /* AlphaBits */
958 0, /* LuminanceBits */
959 0, /* IntensityBits */
960 0, /* IndexBits */
961 0, /* DepthBits */
962 0, /* StencilBits */
963 2, /* TexelBytes */
964 _mesa_texstore_argb4444, /* StoreTexImageFunc */
965 fetch_texel_1d_argb4444, /* FetchTexel1D */
966 fetch_texel_2d_argb4444, /* FetchTexel2D */
967 fetch_texel_3d_argb4444, /* FetchTexel3D */
968 NULL, /* FetchTexel1Df */
969 NULL, /* FetchTexel2Df */
970 NULL, /* FetchTexel3Df */
971 store_texel_argb4444 /* StoreTexel */
972 };
973
974 const struct gl_texture_format _mesa_texformat_argb4444_rev = {
975 MESA_FORMAT_ARGB4444_REV, /* MesaFormat */
976 GL_RGBA, /* BaseFormat */
977 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
978 4, /* RedBits */
979 4, /* GreenBits */
980 4, /* BlueBits */
981 4, /* AlphaBits */
982 0, /* LuminanceBits */
983 0, /* IntensityBits */
984 0, /* IndexBits */
985 0, /* DepthBits */
986 0, /* StencilBits */
987 2, /* TexelBytes */
988 _mesa_texstore_argb4444, /* StoreTexImageFunc */
989 fetch_texel_1d_argb4444_rev, /* FetchTexel1D */
990 fetch_texel_2d_argb4444_rev, /* FetchTexel2D */
991 fetch_texel_3d_argb4444_rev, /* FetchTexel3D */
992 NULL, /* FetchTexel1Df */
993 NULL, /* FetchTexel2Df */
994 NULL, /* FetchTexel3Df */
995 store_texel_argb4444_rev /* StoreTexel */
996 };
997
998 const struct gl_texture_format _mesa_texformat_rgba5551 = {
999 MESA_FORMAT_RGBA5551, /* MesaFormat */
1000 GL_RGBA, /* BaseFormat */
1001 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1002 5, /* RedBits */
1003 5, /* GreenBits */
1004 5, /* BlueBits */
1005 1, /* AlphaBits */
1006 0, /* LuminanceBits */
1007 0, /* IntensityBits */
1008 0, /* IndexBits */
1009 0, /* DepthBits */
1010 0, /* StencilBits */
1011 2, /* TexelBytes */
1012 _mesa_texstore_rgba5551, /* StoreTexImageFunc */
1013 fetch_texel_1d_rgba5551, /* FetchTexel1D */
1014 fetch_texel_2d_rgba5551, /* FetchTexel2D */
1015 fetch_texel_3d_rgba5551, /* FetchTexel3D */
1016 NULL, /* FetchTexel1Df */
1017 NULL, /* FetchTexel2Df */
1018 NULL, /* FetchTexel3Df */
1019 store_texel_rgba5551 /* StoreTexel */
1020 };
1021
1022 const struct gl_texture_format _mesa_texformat_argb1555 = {
1023 MESA_FORMAT_ARGB1555, /* MesaFormat */
1024 GL_RGBA, /* BaseFormat */
1025 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1026 5, /* RedBits */
1027 5, /* GreenBits */
1028 5, /* BlueBits */
1029 1, /* AlphaBits */
1030 0, /* LuminanceBits */
1031 0, /* IntensityBits */
1032 0, /* IndexBits */
1033 0, /* DepthBits */
1034 0, /* StencilBits */
1035 2, /* TexelBytes */
1036 _mesa_texstore_argb1555, /* StoreTexImageFunc */
1037 fetch_texel_1d_argb1555, /* FetchTexel1D */
1038 fetch_texel_2d_argb1555, /* FetchTexel2D */
1039 fetch_texel_3d_argb1555, /* FetchTexel3D */
1040 NULL, /* FetchTexel1Df */
1041 NULL, /* FetchTexel2Df */
1042 NULL, /* FetchTexel3Df */
1043 store_texel_argb1555 /* StoreTexel */
1044 };
1045
1046 const struct gl_texture_format _mesa_texformat_argb1555_rev = {
1047 MESA_FORMAT_ARGB1555_REV, /* MesaFormat */
1048 GL_RGBA, /* BaseFormat */
1049 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1050 5, /* RedBits */
1051 5, /* GreenBits */
1052 5, /* BlueBits */
1053 1, /* AlphaBits */
1054 0, /* LuminanceBits */
1055 0, /* IntensityBits */
1056 0, /* IndexBits */
1057 0, /* DepthBits */
1058 0, /* StencilBits */
1059 2, /* TexelBytes */
1060 _mesa_texstore_argb1555, /* StoreTexImageFunc */
1061 fetch_texel_1d_argb1555_rev, /* FetchTexel1D */
1062 fetch_texel_2d_argb1555_rev, /* FetchTexel2D */
1063 fetch_texel_3d_argb1555_rev, /* FetchTexel3D */
1064 NULL, /* FetchTexel1Df */
1065 NULL, /* FetchTexel2Df */
1066 NULL, /* FetchTexel3Df */
1067 store_texel_argb1555_rev /* StoreTexel */
1068 };
1069
1070 const struct gl_texture_format _mesa_texformat_al88 = {
1071 MESA_FORMAT_AL88, /* MesaFormat */
1072 GL_LUMINANCE_ALPHA, /* BaseFormat */
1073 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1074 0, /* RedBits */
1075 0, /* GreenBits */
1076 0, /* BlueBits */
1077 8, /* AlphaBits */
1078 8, /* LuminanceBits */
1079 0, /* IntensityBits */
1080 0, /* IndexBits */
1081 0, /* DepthBits */
1082 0, /* StencilBits */
1083 2, /* TexelBytes */
1084 _mesa_texstore_al88, /* StoreTexImageFunc */
1085 fetch_texel_1d_al88, /* FetchTexel1D */
1086 fetch_texel_2d_al88, /* FetchTexel2D */
1087 fetch_texel_3d_al88, /* FetchTexel3D */
1088 NULL, /* FetchTexel1Df */
1089 NULL, /* FetchTexel2Df */
1090 NULL, /* FetchTexel3Df */
1091 store_texel_al88 /* StoreTexel */
1092 };
1093
1094 const struct gl_texture_format _mesa_texformat_al88_rev = {
1095 MESA_FORMAT_AL88_REV, /* MesaFormat */
1096 GL_LUMINANCE_ALPHA, /* BaseFormat */
1097 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1098 0, /* RedBits */
1099 0, /* GreenBits */
1100 0, /* BlueBits */
1101 8, /* AlphaBits */
1102 8, /* LuminanceBits */
1103 0, /* IntensityBits */
1104 0, /* IndexBits */
1105 0, /* DepthBits */
1106 0, /* StencilBits */
1107 2, /* TexelBytes */
1108 _mesa_texstore_al88, /* StoreTexImageFunc */
1109 fetch_texel_1d_al88_rev, /* FetchTexel1D */
1110 fetch_texel_2d_al88_rev, /* FetchTexel2D */
1111 fetch_texel_3d_al88_rev, /* FetchTexel3D */
1112 NULL, /* FetchTexel1Df */
1113 NULL, /* FetchTexel2Df */
1114 NULL, /* FetchTexel3Df */
1115 store_texel_al88_rev /* StoreTexel */
1116 };
1117
1118 const struct gl_texture_format _mesa_texformat_rgb332 = {
1119 MESA_FORMAT_RGB332, /* MesaFormat */
1120 GL_RGB, /* BaseFormat */
1121 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1122 3, /* RedBits */
1123 3, /* GreenBits */
1124 2, /* BlueBits */
1125 0, /* AlphaBits */
1126 0, /* LuminanceBits */
1127 0, /* IntensityBits */
1128 0, /* IndexBits */
1129 0, /* DepthBits */
1130 0, /* StencilBits */
1131 1, /* TexelBytes */
1132 _mesa_texstore_rgb332, /* StoreTexImageFunc */
1133 fetch_texel_1d_rgb332, /* FetchTexel1D */
1134 fetch_texel_2d_rgb332, /* FetchTexel2D */
1135 fetch_texel_3d_rgb332, /* FetchTexel3D */
1136 NULL, /* FetchTexel1Df */
1137 NULL, /* FetchTexel2Df */
1138 NULL, /* FetchTexel3Df */
1139 store_texel_rgb332 /* StoreTexel */
1140 };
1141
1142 const struct gl_texture_format _mesa_texformat_a8 = {
1143 MESA_FORMAT_A8, /* MesaFormat */
1144 GL_ALPHA, /* BaseFormat */
1145 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1146 0, /* RedBits */
1147 0, /* GreenBits */
1148 0, /* BlueBits */
1149 8, /* AlphaBits */
1150 0, /* LuminanceBits */
1151 0, /* IntensityBits */
1152 0, /* IndexBits */
1153 0, /* DepthBits */
1154 0, /* StencilBits */
1155 1, /* TexelBytes */
1156 _mesa_texstore_a8, /* StoreTexImageFunc */
1157 fetch_texel_1d_a8, /* FetchTexel1D */
1158 fetch_texel_2d_a8, /* FetchTexel2D */
1159 fetch_texel_3d_a8, /* FetchTexel3D */
1160 NULL, /* FetchTexel1Df */
1161 NULL, /* FetchTexel2Df */
1162 NULL, /* FetchTexel3Df */
1163 store_texel_a8 /* StoreTexel */
1164 };
1165
1166 const struct gl_texture_format _mesa_texformat_l8 = {
1167 MESA_FORMAT_L8, /* MesaFormat */
1168 GL_LUMINANCE, /* BaseFormat */
1169 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1170 0, /* RedBits */
1171 0, /* GreenBits */
1172 0, /* BlueBits */
1173 0, /* AlphaBits */
1174 8, /* LuminanceBits */
1175 0, /* IntensityBits */
1176 0, /* IndexBits */
1177 0, /* DepthBits */
1178 0, /* StencilBits */
1179 1, /* TexelBytes */
1180 _mesa_texstore_a8,/*yes*/ /* StoreTexImageFunc */
1181 fetch_texel_1d_l8, /* FetchTexel1D */
1182 fetch_texel_2d_l8, /* FetchTexel2D */
1183 fetch_texel_3d_l8, /* FetchTexel3D */
1184 NULL, /* FetchTexel1Df */
1185 NULL, /* FetchTexel2Df */
1186 NULL, /* FetchTexel3Df */
1187 store_texel_l8 /* StoreTexel */
1188 };
1189
1190 const struct gl_texture_format _mesa_texformat_i8 = {
1191 MESA_FORMAT_I8, /* MesaFormat */
1192 GL_INTENSITY, /* BaseFormat */
1193 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1194 0, /* RedBits */
1195 0, /* GreenBits */
1196 0, /* BlueBits */
1197 0, /* AlphaBits */
1198 0, /* LuminanceBits */
1199 8, /* IntensityBits */
1200 0, /* IndexBits */
1201 0, /* DepthBits */
1202 0, /* StencilBits */
1203 1, /* TexelBytes */
1204 _mesa_texstore_a8,/*yes*/ /* StoreTexImageFunc */
1205 fetch_texel_1d_i8, /* FetchTexel1D */
1206 fetch_texel_2d_i8, /* FetchTexel2D */
1207 fetch_texel_3d_i8, /* FetchTexel3D */
1208 NULL, /* FetchTexel1Df */
1209 NULL, /* FetchTexel2Df */
1210 NULL, /* FetchTexel3Df */
1211 store_texel_i8 /* StoreTexel */
1212 };
1213
1214 const struct gl_texture_format _mesa_texformat_ci8 = {
1215 MESA_FORMAT_CI8, /* MesaFormat */
1216 GL_COLOR_INDEX, /* BaseFormat */
1217 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1218 0, /* RedBits */
1219 0, /* GreenBits */
1220 0, /* BlueBits */
1221 0, /* AlphaBits */
1222 0, /* LuminanceBits */
1223 0, /* IntensityBits */
1224 8, /* IndexBits */
1225 0, /* DepthBits */
1226 0, /* StencilBits */
1227 1, /* TexelBytes */
1228 _mesa_texstore_ci8, /* StoreTexImageFunc */
1229 fetch_texel_1d_ci8, /* FetchTexel1D */
1230 fetch_texel_2d_ci8, /* FetchTexel2D */
1231 fetch_texel_3d_ci8, /* FetchTexel3D */
1232 NULL, /* FetchTexel1Df */
1233 NULL, /* FetchTexel2Df */
1234 NULL, /* FetchTexel3Df */
1235 store_texel_ci8 /* StoreTexel */
1236 };
1237
1238 const struct gl_texture_format _mesa_texformat_ycbcr = {
1239 MESA_FORMAT_YCBCR, /* MesaFormat */
1240 GL_YCBCR_MESA, /* BaseFormat */
1241 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1242 0, /* RedBits */
1243 0, /* GreenBits */
1244 0, /* BlueBits */
1245 0, /* AlphaBits */
1246 0, /* LuminanceBits */
1247 0, /* IntensityBits */
1248 0, /* IndexBits */
1249 0, /* DepthBits */
1250 0, /* StencilBits */
1251 2, /* TexelBytes */
1252 _mesa_texstore_ycbcr, /* StoreTexImageFunc */
1253 fetch_texel_1d_ycbcr, /* FetchTexel1D */
1254 fetch_texel_2d_ycbcr, /* FetchTexel2D */
1255 fetch_texel_3d_ycbcr, /* FetchTexel3D */
1256 NULL, /* FetchTexel1Df */
1257 NULL, /* FetchTexel2Df */
1258 NULL, /* FetchTexel3Df */
1259 store_texel_ycbcr /* StoreTexel */
1260 };
1261
1262 const struct gl_texture_format _mesa_texformat_ycbcr_rev = {
1263 MESA_FORMAT_YCBCR_REV, /* MesaFormat */
1264 GL_YCBCR_MESA, /* BaseFormat */
1265 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1266 0, /* RedBits */
1267 0, /* GreenBits */
1268 0, /* BlueBits */
1269 0, /* AlphaBits */
1270 0, /* LuminanceBits */
1271 0, /* IntensityBits */
1272 0, /* IndexBits */
1273 0, /* DepthBits */
1274 0, /* StencilBits */
1275 2, /* TexelBytes */
1276 _mesa_texstore_ycbcr, /* StoreTexImageFunc */
1277 fetch_texel_1d_ycbcr_rev, /* FetchTexel1D */
1278 fetch_texel_2d_ycbcr_rev, /* FetchTexel2D */
1279 fetch_texel_3d_ycbcr_rev, /* FetchTexel3D */
1280 NULL, /* FetchTexel1Df */
1281 NULL, /* FetchTexel2Df */
1282 NULL, /* FetchTexel3Df */
1283 store_texel_ycbcr_rev /* StoreTexel */
1284 };
1285
1286 const struct gl_texture_format _mesa_texformat_z24_s8 = {
1287 MESA_FORMAT_Z24_S8, /* MesaFormat */
1288 GL_DEPTH_STENCIL_EXT, /* BaseFormat */
1289 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1290 0, /* RedBits */
1291 0, /* GreenBits */
1292 0, /* BlueBits */
1293 0, /* AlphaBits */
1294 0, /* LuminanceBits */
1295 0, /* IntensityBits */
1296 0, /* IndexBits */
1297 24, /* DepthBits */
1298 8, /* StencilBits */
1299 4, /* TexelBytes */
1300 _mesa_texstore_z24_s8, /* StoreTexImageFunc */
1301 NULL, /* FetchTexel1D */
1302 NULL, /* FetchTexel2D */
1303 NULL, /* FetchTexel3D */
1304 fetch_texel_1d_f_z24_s8, /* FetchTexel1Df */
1305 fetch_texel_2d_f_z24_s8, /* FetchTexel2Df */
1306 fetch_texel_3d_f_z24_s8, /* FetchTexel3Df */
1307 store_texel_z24_s8 /* StoreTexel */
1308 };
1309
1310 const struct gl_texture_format _mesa_texformat_s8_z24 = {
1311 MESA_FORMAT_S8_Z24, /* MesaFormat */
1312 GL_DEPTH_STENCIL_EXT, /* BaseFormat */
1313 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1314 0, /* RedBits */
1315 0, /* GreenBits */
1316 0, /* BlueBits */
1317 0, /* AlphaBits */
1318 0, /* LuminanceBits */
1319 0, /* IntensityBits */
1320 0, /* IndexBits */
1321 24, /* DepthBits */
1322 8, /* StencilBits */
1323 4, /* TexelBytes */
1324 _mesa_texstore_s8_z24, /* StoreTexImageFunc */
1325 NULL, /* FetchTexel1D */
1326 NULL, /* FetchTexel2D */
1327 NULL, /* FetchTexel3D */
1328 fetch_texel_1d_f_s8_z24, /* FetchTexel1Df */
1329 fetch_texel_2d_f_s8_z24, /* FetchTexel2Df */
1330 fetch_texel_3d_f_s8_z24, /* FetchTexel3Df */
1331 store_texel_s8_z24 /* StoreTexel */
1332 };
1333
1334 const struct gl_texture_format _mesa_texformat_z16 = {
1335 MESA_FORMAT_Z16, /* MesaFormat */
1336 GL_DEPTH_COMPONENT, /* BaseFormat */
1337 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1338 0, /* RedBits */
1339 0, /* GreenBits */
1340 0, /* BlueBits */
1341 0, /* AlphaBits */
1342 0, /* LuminanceBits */
1343 0, /* IntensityBits */
1344 0, /* IndexBits */
1345 sizeof(GLushort) * 8, /* DepthBits */
1346 0, /* StencilBits */
1347 sizeof(GLushort), /* TexelBytes */
1348 _mesa_texstore_z16, /* StoreTexImageFunc */
1349 NULL, /* FetchTexel1D */
1350 NULL, /* FetchTexel1D */
1351 NULL, /* FetchTexel1D */
1352 fetch_texel_1d_f_z16, /* FetchTexel1Df */
1353 fetch_texel_2d_f_z16, /* FetchTexel2Df */
1354 fetch_texel_3d_f_z16, /* FetchTexel3Df */
1355 store_texel_z16 /* StoreTexel */
1356 };
1357
1358 const struct gl_texture_format _mesa_texformat_z32 = {
1359 MESA_FORMAT_Z32, /* MesaFormat */
1360 GL_DEPTH_COMPONENT, /* BaseFormat */
1361 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1362 0, /* RedBits */
1363 0, /* GreenBits */
1364 0, /* BlueBits */
1365 0, /* AlphaBits */
1366 0, /* LuminanceBits */
1367 0, /* IntensityBits */
1368 0, /* IndexBits */
1369 sizeof(GLuint) * 8, /* DepthBits */
1370 0, /* StencilBits */
1371 sizeof(GLuint), /* TexelBytes */
1372 _mesa_texstore_z32, /* StoreTexImageFunc */
1373 NULL, /* FetchTexel1D */
1374 NULL, /* FetchTexel1D */
1375 NULL, /* FetchTexel1D */
1376 fetch_texel_1d_f_z32, /* FetchTexel1Df */
1377 fetch_texel_2d_f_z32, /* FetchTexel2Df */
1378 fetch_texel_3d_f_z32, /* FetchTexel3Df */
1379 store_texel_z32 /* StoreTexel */
1380 };
1381
1382 /*@}*/
1383
1384
1385 /***************************************************************/
1386 /** \name Null format (useful for proxy textures) */
1387 /*@{*/
1388
1389 const struct gl_texture_format _mesa_null_texformat = {
1390 -1, /* MesaFormat */
1391 0, /* BaseFormat */
1392 GL_NONE, /* DataType */
1393 0, /* RedBits */
1394 0, /* GreenBits */
1395 0, /* BlueBits */
1396 0, /* AlphaBits */
1397 0, /* LuminanceBits */
1398 0, /* IntensityBits */
1399 0, /* IndexBits */
1400 0, /* DepthBits */
1401 0, /* StencilBits */
1402 0, /* TexelBytes */
1403 NULL, /* StoreTexImageFunc */
1404 fetch_null_texel, /* FetchTexel1D */
1405 fetch_null_texel, /* FetchTexel2D */
1406 fetch_null_texel, /* FetchTexel3D */
1407 fetch_null_texelf, /* FetchTexel1Df */
1408 fetch_null_texelf, /* FetchTexel2Df */
1409 fetch_null_texelf, /* FetchTexel3Df */
1410 store_null_texel /* StoreTexel */
1411 };
1412
1413 /*@}*/
1414
1415
1416 /**
1417 * Choose an appropriate texture format given the format, type and
1418 * internalFormat parameters passed to glTexImage().
1419 *
1420 * \param ctx the GL context.
1421 * \param internalFormat user's prefered internal texture format.
1422 * \param format incoming image pixel format.
1423 * \param type incoming image data type.
1424 *
1425 * \return a pointer to a gl_texture_format object which describes the
1426 * choosen texture format, or NULL on failure.
1427 *
1428 * This is called via dd_function_table::ChooseTextureFormat. Hardware drivers
1429 * will typically override this function with a specialized version.
1430 */
1431 const struct gl_texture_format *
1432 _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
1433 GLenum format, GLenum type )
1434 {
1435 (void) format;
1436 (void) type;
1437
1438 switch (internalFormat) {
1439 /* RGBA formats */
1440 case 4:
1441 case GL_RGBA:
1442 case GL_RGB10_A2:
1443 case GL_RGBA12:
1444 case GL_RGBA16:
1445 return &_mesa_texformat_rgba;
1446 case GL_RGBA8:
1447 return &_mesa_texformat_rgba8888;
1448 case GL_RGB5_A1:
1449 return &_mesa_texformat_argb1555;
1450 case GL_RGBA2:
1451 return &_mesa_texformat_argb4444_rev; /* just to test another format*/
1452 case GL_RGBA4:
1453 return &_mesa_texformat_argb4444;
1454
1455 /* RGB formats */
1456 case 3:
1457 case GL_RGB:
1458 case GL_RGB10:
1459 case GL_RGB12:
1460 case GL_RGB16:
1461 return &_mesa_texformat_rgb;
1462 case GL_RGB8:
1463 return &_mesa_texformat_rgb888;
1464 case GL_R3_G3_B2:
1465 return &_mesa_texformat_rgb332;
1466 case GL_RGB4:
1467 return &_mesa_texformat_rgb565_rev; /* just to test another format */
1468 case GL_RGB5:
1469 return &_mesa_texformat_rgb565;
1470
1471 /* Alpha formats */
1472 case GL_ALPHA:
1473 case GL_ALPHA4:
1474 case GL_ALPHA12:
1475 case GL_ALPHA16:
1476 return &_mesa_texformat_alpha;
1477 case GL_ALPHA8:
1478 return &_mesa_texformat_a8;
1479
1480 /* Luminance formats */
1481 case 1:
1482 case GL_LUMINANCE:
1483 case GL_LUMINANCE4:
1484 case GL_LUMINANCE12:
1485 case GL_LUMINANCE16:
1486 return &_mesa_texformat_luminance;
1487 case GL_LUMINANCE8:
1488 return &_mesa_texformat_l8;
1489
1490 /* Luminance/Alpha formats */
1491 case 2:
1492 case GL_LUMINANCE_ALPHA:
1493 case GL_LUMINANCE4_ALPHA4:
1494 case GL_LUMINANCE6_ALPHA2:
1495 case GL_LUMINANCE12_ALPHA4:
1496 case GL_LUMINANCE12_ALPHA12:
1497 case GL_LUMINANCE16_ALPHA16:
1498 return &_mesa_texformat_luminance_alpha;
1499 case GL_LUMINANCE8_ALPHA8:
1500 return &_mesa_texformat_al88;
1501
1502 case GL_INTENSITY:
1503 case GL_INTENSITY4:
1504 case GL_INTENSITY12:
1505 case GL_INTENSITY16:
1506 return &_mesa_texformat_intensity;
1507 case GL_INTENSITY8:
1508 return &_mesa_texformat_i8;
1509
1510 case GL_COLOR_INDEX:
1511 case GL_COLOR_INDEX1_EXT:
1512 case GL_COLOR_INDEX2_EXT:
1513 case GL_COLOR_INDEX4_EXT:
1514 case GL_COLOR_INDEX12_EXT:
1515 case GL_COLOR_INDEX16_EXT:
1516 case GL_COLOR_INDEX8_EXT:
1517 return &_mesa_texformat_ci8;
1518
1519 default:
1520 ; /* fallthrough */
1521 }
1522
1523 if (ctx->Extensions.ARB_depth_texture) {
1524 switch (internalFormat) {
1525 case GL_DEPTH_COMPONENT:
1526 case GL_DEPTH_COMPONENT24:
1527 case GL_DEPTH_COMPONENT32:
1528 return &_mesa_texformat_z32;
1529 case GL_DEPTH_COMPONENT16:
1530 return &_mesa_texformat_z16;
1531 default:
1532 ; /* fallthrough */
1533 }
1534 }
1535
1536 switch (internalFormat) {
1537 case GL_COMPRESSED_ALPHA_ARB:
1538 return &_mesa_texformat_alpha;
1539 case GL_COMPRESSED_LUMINANCE_ARB:
1540 return &_mesa_texformat_luminance;
1541 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
1542 return &_mesa_texformat_luminance_alpha;
1543 case GL_COMPRESSED_INTENSITY_ARB:
1544 return &_mesa_texformat_intensity;
1545 case GL_COMPRESSED_RGB_ARB:
1546 #if FEATURE_texture_fxt1
1547 if (ctx->Extensions.TDFX_texture_compression_FXT1)
1548 return &_mesa_texformat_rgb_fxt1;
1549 #endif
1550 #if FEATURE_texture_s3tc
1551 if (ctx->Extensions.EXT_texture_compression_s3tc ||
1552 ctx->Extensions.S3_s3tc)
1553 return &_mesa_texformat_rgb_dxt1;
1554 #endif
1555 return &_mesa_texformat_rgb;
1556 case GL_COMPRESSED_RGBA_ARB:
1557 #if FEATURE_texture_fxt1
1558 if (ctx->Extensions.TDFX_texture_compression_FXT1)
1559 return &_mesa_texformat_rgba_fxt1;
1560 #endif
1561 #if FEATURE_texture_s3tc
1562 if (ctx->Extensions.EXT_texture_compression_s3tc ||
1563 ctx->Extensions.S3_s3tc)
1564 return &_mesa_texformat_rgba_dxt3; /* Not rgba_dxt1, see spec */
1565 #endif
1566 return &_mesa_texformat_rgba;
1567 default:
1568 ; /* fallthrough */
1569 }
1570
1571 if (ctx->Extensions.MESA_ycbcr_texture) {
1572 if (internalFormat == GL_YCBCR_MESA) {
1573 if (type == GL_UNSIGNED_SHORT_8_8_MESA)
1574 return &_mesa_texformat_ycbcr;
1575 else
1576 return &_mesa_texformat_ycbcr_rev;
1577 }
1578 }
1579
1580 #if FEATURE_texture_fxt1
1581 if (ctx->Extensions.TDFX_texture_compression_FXT1) {
1582 switch (internalFormat) {
1583 case GL_COMPRESSED_RGB_FXT1_3DFX:
1584 return &_mesa_texformat_rgb_fxt1;
1585 case GL_COMPRESSED_RGBA_FXT1_3DFX:
1586 return &_mesa_texformat_rgba_fxt1;
1587 default:
1588 ; /* fallthrough */
1589 }
1590 }
1591 #endif
1592
1593 #if FEATURE_texture_s3tc
1594 if (ctx->Extensions.EXT_texture_compression_s3tc) {
1595 switch (internalFormat) {
1596 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1597 return &_mesa_texformat_rgb_dxt1;
1598 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1599 return &_mesa_texformat_rgba_dxt1;
1600 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
1601 return &_mesa_texformat_rgba_dxt3;
1602 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
1603 return &_mesa_texformat_rgba_dxt5;
1604 default:
1605 ; /* fallthrough */
1606 }
1607 }
1608
1609 if (ctx->Extensions.S3_s3tc) {
1610 switch (internalFormat) {
1611 case GL_RGB_S3TC:
1612 case GL_RGB4_S3TC:
1613 return &_mesa_texformat_rgb_dxt1;
1614 case GL_RGBA_S3TC:
1615 case GL_RGBA4_S3TC:
1616 return &_mesa_texformat_rgba_dxt3;
1617 default:
1618 ; /* fallthrough */
1619 }
1620 }
1621 #endif
1622
1623 if (ctx->Extensions.ARB_texture_float) {
1624 switch (internalFormat) {
1625 case GL_ALPHA16F_ARB:
1626 return &_mesa_texformat_alpha_float16;
1627 case GL_ALPHA32F_ARB:
1628 return &_mesa_texformat_alpha_float32;
1629 case GL_LUMINANCE16F_ARB:
1630 return &_mesa_texformat_luminance_float16;
1631 case GL_LUMINANCE32F_ARB:
1632 return &_mesa_texformat_luminance_float32;
1633 case GL_LUMINANCE_ALPHA16F_ARB:
1634 return &_mesa_texformat_luminance_alpha_float16;
1635 case GL_LUMINANCE_ALPHA32F_ARB:
1636 return &_mesa_texformat_luminance_alpha_float32;
1637 case GL_INTENSITY16F_ARB:
1638 return &_mesa_texformat_intensity_float16;
1639 case GL_INTENSITY32F_ARB:
1640 return &_mesa_texformat_intensity_float32;
1641 case GL_RGB16F_ARB:
1642 return &_mesa_texformat_rgb_float16;
1643 case GL_RGB32F_ARB:
1644 return &_mesa_texformat_rgb_float32;
1645 case GL_RGBA16F_ARB:
1646 return &_mesa_texformat_rgba_float16;
1647 case GL_RGBA32F_ARB:
1648 return &_mesa_texformat_rgba_float32;
1649 default:
1650 ; /* fallthrough */
1651 }
1652 }
1653
1654 if (ctx->Extensions.EXT_packed_depth_stencil) {
1655 switch (internalFormat) {
1656 case GL_DEPTH_STENCIL_EXT:
1657 case GL_DEPTH24_STENCIL8_EXT:
1658 return &_mesa_texformat_z24_s8;
1659 default:
1660 ; /* fallthrough */
1661 }
1662 }
1663
1664 if (ctx->Extensions.ATI_envmap_bumpmap) {
1665 switch (internalFormat) {
1666 case GL_DUDV_ATI:
1667 case GL_DU8DV8_ATI:
1668 return &_mesa_texformat_dudv8;
1669 default:
1670 ; /* fallthrough */
1671 }
1672 }
1673
1674 #if FEATURE_EXT_texture_sRGB
1675 if (ctx->Extensions.EXT_texture_sRGB) {
1676 switch (internalFormat) {
1677 case GL_SRGB_EXT:
1678 case GL_SRGB8_EXT:
1679 return &_mesa_texformat_srgb8;
1680 case GL_SRGB_ALPHA_EXT:
1681 case GL_SRGB8_ALPHA8_EXT:
1682 return &_mesa_texformat_srgba8;
1683 case GL_SLUMINANCE_EXT:
1684 case GL_SLUMINANCE8_EXT:
1685 return &_mesa_texformat_sl8;
1686 case GL_SLUMINANCE_ALPHA_EXT:
1687 case GL_SLUMINANCE8_ALPHA8_EXT:
1688 return &_mesa_texformat_sla8;
1689 case GL_COMPRESSED_SLUMINANCE_EXT:
1690 return &_mesa_texformat_sl8;
1691 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
1692 return &_mesa_texformat_sla8;
1693 case GL_COMPRESSED_SRGB_EXT:
1694 #if FEATURE_texture_s3tc
1695 if (ctx->Extensions.EXT_texture_compression_s3tc)
1696 return &_mesa_texformat_srgb_dxt1;
1697 #endif
1698 return &_mesa_texformat_srgb8;
1699 case GL_COMPRESSED_SRGB_ALPHA_EXT:
1700 #if FEATURE_texture_s3tc
1701 if (ctx->Extensions.EXT_texture_compression_s3tc)
1702 return &_mesa_texformat_srgba_dxt3; /* Not srgba_dxt1, see spec */
1703 #endif
1704 return &_mesa_texformat_srgba8;
1705 #if FEATURE_texture_s3tc
1706 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
1707 if (ctx->Extensions.EXT_texture_compression_s3tc)
1708 return &_mesa_texformat_srgb_dxt1;
1709 break;
1710 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
1711 if (ctx->Extensions.EXT_texture_compression_s3tc)
1712 return &_mesa_texformat_srgba_dxt1;
1713 break;
1714 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
1715 if (ctx->Extensions.EXT_texture_compression_s3tc)
1716 return &_mesa_texformat_srgba_dxt3;
1717 break;
1718 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
1719 if (ctx->Extensions.EXT_texture_compression_s3tc)
1720 return &_mesa_texformat_srgba_dxt5;
1721 break;
1722 #endif
1723 default:
1724 ; /* fallthrough */
1725 }
1726 }
1727 #endif /* FEATURE_EXT_texture_sRGB */
1728
1729 _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
1730 return NULL;
1731 }
1732
1733
1734
1735 /**
1736 * Return datatype and number of components per texel for the
1737 * given gl_texture_format.
1738 */
1739 void
1740 _mesa_format_to_type_and_comps(const struct gl_texture_format *format,
1741 GLenum *datatype, GLuint *comps)
1742 {
1743 switch (format->MesaFormat) {
1744 case MESA_FORMAT_RGBA8888:
1745 case MESA_FORMAT_RGBA8888_REV:
1746 case MESA_FORMAT_ARGB8888:
1747 case MESA_FORMAT_ARGB8888_REV:
1748 *datatype = CHAN_TYPE;
1749 *comps = 4;
1750 return;
1751 case MESA_FORMAT_RGB888:
1752 case MESA_FORMAT_BGR888:
1753 *datatype = GL_UNSIGNED_BYTE;
1754 *comps = 3;
1755 return;
1756 case MESA_FORMAT_RGB565:
1757 case MESA_FORMAT_RGB565_REV:
1758 *datatype = GL_UNSIGNED_SHORT_5_6_5;
1759 *comps = 3;
1760 return;
1761
1762 case MESA_FORMAT_ARGB4444:
1763 case MESA_FORMAT_ARGB4444_REV:
1764 *datatype = GL_UNSIGNED_SHORT_4_4_4_4;
1765 *comps = 4;
1766 return;
1767
1768 case MESA_FORMAT_ARGB1555:
1769 case MESA_FORMAT_ARGB1555_REV:
1770 *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
1771 *comps = 4;
1772 return;
1773
1774 case MESA_FORMAT_AL88:
1775 case MESA_FORMAT_AL88_REV:
1776 *datatype = GL_UNSIGNED_BYTE;
1777 *comps = 2;
1778 return;
1779 case MESA_FORMAT_RGB332:
1780 *datatype = GL_UNSIGNED_BYTE_3_3_2;
1781 *comps = 3;
1782 return;
1783
1784 case MESA_FORMAT_A8:
1785 case MESA_FORMAT_L8:
1786 case MESA_FORMAT_I8:
1787 case MESA_FORMAT_CI8:
1788 *datatype = GL_UNSIGNED_BYTE;
1789 *comps = 1;
1790 return;
1791
1792 case MESA_FORMAT_YCBCR:
1793 case MESA_FORMAT_YCBCR_REV:
1794 *datatype = GL_UNSIGNED_SHORT;
1795 *comps = 2;
1796 return;
1797
1798 case MESA_FORMAT_Z24_S8:
1799 *datatype = GL_UNSIGNED_INT;
1800 *comps = 1; /* XXX OK? */
1801 return;
1802
1803 case MESA_FORMAT_S8_Z24:
1804 *datatype = GL_UNSIGNED_INT;
1805 *comps = 1; /* XXX OK? */
1806 return;
1807
1808 case MESA_FORMAT_Z16:
1809 *datatype = GL_UNSIGNED_SHORT;
1810 *comps = 1;
1811 return;
1812
1813 case MESA_FORMAT_Z32:
1814 *datatype = GL_UNSIGNED_INT;
1815 *comps = 1;
1816 return;
1817
1818 case MESA_FORMAT_DUDV8:
1819 *datatype = GL_BYTE;
1820 *comps = 2;
1821 return;
1822
1823 #if FEATURE_EXT_texture_sRGB
1824 case MESA_FORMAT_SRGB8:
1825 *datatype = GL_UNSIGNED_BYTE;
1826 *comps = 3;
1827 return;
1828 case MESA_FORMAT_SRGBA8:
1829 case MESA_FORMAT_SARGB8:
1830 *datatype = GL_UNSIGNED_BYTE;
1831 *comps = 4;
1832 return;
1833 case MESA_FORMAT_SL8:
1834 *datatype = GL_UNSIGNED_BYTE;
1835 *comps = 1;
1836 return;
1837 case MESA_FORMAT_SLA8:
1838 *datatype = GL_UNSIGNED_BYTE;
1839 *comps = 2;
1840 return;
1841 #endif
1842
1843 #if FEATURE_texture_fxt1
1844 case MESA_FORMAT_RGB_FXT1:
1845 case MESA_FORMAT_RGBA_FXT1:
1846 #endif
1847 #if FEATURE_texture_s3tc
1848 case MESA_FORMAT_RGB_DXT1:
1849 case MESA_FORMAT_RGBA_DXT1:
1850 case MESA_FORMAT_RGBA_DXT3:
1851 case MESA_FORMAT_RGBA_DXT5:
1852 #if FEATURE_EXT_texture_sRGB
1853 case MESA_FORMAT_SRGB_DXT1:
1854 case MESA_FORMAT_SRGBA_DXT1:
1855 case MESA_FORMAT_SRGBA_DXT3:
1856 case MESA_FORMAT_SRGBA_DXT5:
1857 #endif
1858 /* XXX generate error instead? */
1859 *datatype = GL_UNSIGNED_BYTE;
1860 *comps = 0;
1861 return;
1862 #endif
1863
1864 case MESA_FORMAT_RGBA:
1865 *datatype = CHAN_TYPE;
1866 *comps = 4;
1867 return;
1868 case MESA_FORMAT_RGB:
1869 *datatype = CHAN_TYPE;
1870 *comps = 3;
1871 return;
1872 case MESA_FORMAT_LUMINANCE_ALPHA:
1873 *datatype = CHAN_TYPE;
1874 *comps = 2;
1875 return;
1876 case MESA_FORMAT_ALPHA:
1877 case MESA_FORMAT_LUMINANCE:
1878 case MESA_FORMAT_INTENSITY:
1879 *datatype = CHAN_TYPE;
1880 *comps = 1;
1881 return;
1882
1883 case MESA_FORMAT_RGBA_FLOAT32:
1884 *datatype = GL_FLOAT;
1885 *comps = 4;
1886 return;
1887 case MESA_FORMAT_RGBA_FLOAT16:
1888 *datatype = GL_HALF_FLOAT_ARB;
1889 *comps = 4;
1890 return;
1891 case MESA_FORMAT_RGB_FLOAT32:
1892 *datatype = GL_FLOAT;
1893 *comps = 3;
1894 return;
1895 case MESA_FORMAT_RGB_FLOAT16:
1896 *datatype = GL_HALF_FLOAT_ARB;
1897 *comps = 3;
1898 return;
1899 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
1900 *datatype = GL_FLOAT;
1901 *comps = 2;
1902 return;
1903 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
1904 *datatype = GL_HALF_FLOAT_ARB;
1905 *comps = 2;
1906 return;
1907 case MESA_FORMAT_ALPHA_FLOAT32:
1908 case MESA_FORMAT_LUMINANCE_FLOAT32:
1909 case MESA_FORMAT_INTENSITY_FLOAT32:
1910 *datatype = GL_FLOAT;
1911 *comps = 1;
1912 return;
1913 case MESA_FORMAT_ALPHA_FLOAT16:
1914 case MESA_FORMAT_LUMINANCE_FLOAT16:
1915 case MESA_FORMAT_INTENSITY_FLOAT16:
1916 *datatype = GL_HALF_FLOAT_ARB;
1917 *comps = 1;
1918 return;
1919
1920 default:
1921 _mesa_problem(NULL, "bad format in _mesa_format_to_type_and_comps");
1922 *datatype = 0;
1923 *comps = 1;
1924 }
1925 }