Merge commit 'origin/master' into gallium-0.2
[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
700 /*@}*/
701
702
703 /***************************************************************/
704 /** \name Hardware formats */
705 /*@{*/
706
707 const struct gl_texture_format _mesa_texformat_rgba8888 = {
708 MESA_FORMAT_RGBA8888, /* MesaFormat */
709 GL_RGBA, /* BaseFormat */
710 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
711 8, /* RedBits */
712 8, /* GreenBits */
713 8, /* BlueBits */
714 8, /* AlphaBits */
715 0, /* LuminanceBits */
716 0, /* IntensityBits */
717 0, /* IndexBits */
718 0, /* DepthBits */
719 0, /* StencilBits */
720 4, /* TexelBytes */
721 _mesa_texstore_rgba8888, /* StoreTexImageFunc */
722 fetch_texel_1d_rgba8888, /* FetchTexel1D */
723 fetch_texel_2d_rgba8888, /* FetchTexel2D */
724 fetch_texel_3d_rgba8888, /* FetchTexel3D */
725 NULL, /* FetchTexel1Df */
726 NULL, /* FetchTexel2Df */
727 NULL, /* FetchTexel3Df */
728 store_texel_rgba8888 /* StoreTexel */
729 };
730
731 const struct gl_texture_format _mesa_texformat_rgba8888_rev = {
732 MESA_FORMAT_RGBA8888_REV, /* MesaFormat */
733 GL_RGBA, /* BaseFormat */
734 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
735 8, /* RedBits */
736 8, /* GreenBits */
737 8, /* BlueBits */
738 8, /* AlphaBits */
739 0, /* LuminanceBits */
740 0, /* IntensityBits */
741 0, /* IndexBits */
742 0, /* DepthBits */
743 0, /* StencilBits */
744 4, /* TexelBytes */
745 _mesa_texstore_rgba8888, /* StoreTexImageFunc */
746 fetch_texel_1d_rgba8888_rev, /* FetchTexel1D */
747 fetch_texel_2d_rgba8888_rev, /* FetchTexel2D */
748 fetch_texel_3d_rgba8888_rev, /* FetchTexel3D */
749 NULL, /* FetchTexel1Df */
750 NULL, /* FetchTexel2Df */
751 NULL, /* FetchTexel3Df */
752 store_texel_rgba8888_rev /* StoreTexel */
753 };
754
755 const struct gl_texture_format _mesa_texformat_argb8888 = {
756 MESA_FORMAT_ARGB8888, /* MesaFormat */
757 GL_RGBA, /* BaseFormat */
758 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
759 8, /* RedBits */
760 8, /* GreenBits */
761 8, /* BlueBits */
762 8, /* AlphaBits */
763 0, /* LuminanceBits */
764 0, /* IntensityBits */
765 0, /* IndexBits */
766 0, /* DepthBits */
767 0, /* StencilBits */
768 4, /* TexelBytes */
769 _mesa_texstore_argb8888, /* StoreTexImageFunc */
770 fetch_texel_1d_argb8888, /* FetchTexel1D */
771 fetch_texel_2d_argb8888, /* FetchTexel2D */
772 fetch_texel_3d_argb8888, /* FetchTexel3D */
773 NULL, /* FetchTexel1Df */
774 NULL, /* FetchTexel2Df */
775 NULL, /* FetchTexel3Df */
776 store_texel_argb8888 /* StoreTexel */
777 };
778
779 const struct gl_texture_format _mesa_texformat_argb8888_rev = {
780 MESA_FORMAT_ARGB8888_REV, /* MesaFormat */
781 GL_RGBA, /* BaseFormat */
782 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
783 8, /* RedBits */
784 8, /* GreenBits */
785 8, /* BlueBits */
786 8, /* AlphaBits */
787 0, /* LuminanceBits */
788 0, /* IntensityBits */
789 0, /* IndexBits */
790 0, /* DepthBits */
791 0, /* StencilBits */
792 4, /* TexelBytes */
793 _mesa_texstore_argb8888, /* StoreTexImageFunc */
794 fetch_texel_1d_argb8888_rev, /* FetchTexel1D */
795 fetch_texel_2d_argb8888_rev, /* FetchTexel2D */
796 fetch_texel_3d_argb8888_rev, /* FetchTexel3D */
797 NULL, /* FetchTexel1Df */
798 NULL, /* FetchTexel2Df */
799 NULL, /* FetchTexel3Df */
800 store_texel_argb8888_rev /* StoreTexel */
801 };
802
803 const struct gl_texture_format _mesa_texformat_rgb888 = {
804 MESA_FORMAT_RGB888, /* MesaFormat */
805 GL_RGB, /* BaseFormat */
806 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
807 8, /* RedBits */
808 8, /* GreenBits */
809 8, /* BlueBits */
810 0, /* AlphaBits */
811 0, /* LuminanceBits */
812 0, /* IntensityBits */
813 0, /* IndexBits */
814 0, /* DepthBits */
815 0, /* StencilBits */
816 3, /* TexelBytes */
817 _mesa_texstore_rgb888, /* StoreTexImageFunc */
818 fetch_texel_1d_rgb888, /* FetchTexel1D */
819 fetch_texel_2d_rgb888, /* FetchTexel2D */
820 fetch_texel_3d_rgb888, /* FetchTexel3D */
821 NULL, /* FetchTexel1Df */
822 NULL, /* FetchTexel2Df */
823 NULL, /* FetchTexel3Df */
824 store_texel_rgb888 /* StoreTexel */
825 };
826
827 const struct gl_texture_format _mesa_texformat_bgr888 = {
828 MESA_FORMAT_BGR888, /* MesaFormat */
829 GL_RGB, /* BaseFormat */
830 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
831 8, /* RedBits */
832 8, /* GreenBits */
833 8, /* BlueBits */
834 0, /* AlphaBits */
835 0, /* LuminanceBits */
836 0, /* IntensityBits */
837 0, /* IndexBits */
838 0, /* DepthBits */
839 0, /* StencilBits */
840 3, /* TexelBytes */
841 _mesa_texstore_bgr888, /* StoreTexImageFunc */
842 fetch_texel_1d_bgr888, /* FetchTexel1D */
843 fetch_texel_2d_bgr888, /* FetchTexel2D */
844 fetch_texel_3d_bgr888, /* FetchTexel3D */
845 NULL, /* FetchTexel1Df */
846 NULL, /* FetchTexel2Df */
847 NULL, /* FetchTexel3Df */
848 store_texel_bgr888 /* StoreTexel */
849 };
850
851 const struct gl_texture_format _mesa_texformat_rgb565 = {
852 MESA_FORMAT_RGB565, /* MesaFormat */
853 GL_RGB, /* BaseFormat */
854 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
855 5, /* RedBits */
856 6, /* GreenBits */
857 5, /* BlueBits */
858 0, /* AlphaBits */
859 0, /* LuminanceBits */
860 0, /* IntensityBits */
861 0, /* IndexBits */
862 0, /* DepthBits */
863 0, /* StencilBits */
864 2, /* TexelBytes */
865 _mesa_texstore_rgb565, /* StoreTexImageFunc */
866 fetch_texel_1d_rgb565, /* FetchTexel1D */
867 fetch_texel_2d_rgb565, /* FetchTexel2D */
868 fetch_texel_3d_rgb565, /* FetchTexel3D */
869 NULL, /* FetchTexel1Df */
870 NULL, /* FetchTexel2Df */
871 NULL, /* FetchTexel3Df */
872 store_texel_rgb565 /* StoreTexel */
873 };
874
875 const struct gl_texture_format _mesa_texformat_rgb565_rev = {
876 MESA_FORMAT_RGB565_REV, /* MesaFormat */
877 GL_RGB, /* BaseFormat */
878 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
879 5, /* RedBits */
880 6, /* GreenBits */
881 5, /* BlueBits */
882 0, /* AlphaBits */
883 0, /* LuminanceBits */
884 0, /* IntensityBits */
885 0, /* IndexBits */
886 0, /* DepthBits */
887 0, /* StencilBits */
888 2, /* TexelBytes */
889 _mesa_texstore_rgb565, /* StoreTexImageFunc */
890 fetch_texel_1d_rgb565_rev, /* FetchTexel1D */
891 fetch_texel_2d_rgb565_rev, /* FetchTexel2D */
892 fetch_texel_3d_rgb565_rev, /* FetchTexel3D */
893 NULL, /* FetchTexel1Df */
894 NULL, /* FetchTexel2Df */
895 NULL, /* FetchTexel3Df */
896 store_texel_rgb565_rev /* StoreTexel */
897 };
898
899 const struct gl_texture_format _mesa_texformat_rgba4444 = {
900 MESA_FORMAT_RGBA4444, /* MesaFormat */
901 GL_RGBA, /* BaseFormat */
902 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
903 4, /* RedBits */
904 4, /* GreenBits */
905 4, /* BlueBits */
906 4, /* AlphaBits */
907 0, /* LuminanceBits */
908 0, /* IntensityBits */
909 0, /* IndexBits */
910 0, /* DepthBits */
911 0, /* StencilBits */
912 2, /* TexelBytes */
913 _mesa_texstore_rgba4444, /* StoreTexImageFunc */
914 fetch_texel_1d_rgba4444, /* FetchTexel1D */
915 fetch_texel_2d_rgba4444, /* FetchTexel2D */
916 fetch_texel_3d_rgba4444, /* FetchTexel3D */
917 NULL, /* FetchTexel1Df */
918 NULL, /* FetchTexel2Df */
919 NULL, /* FetchTexel3Df */
920 store_texel_rgba4444 /* StoreTexel */
921 };
922
923 const struct gl_texture_format _mesa_texformat_argb4444 = {
924 MESA_FORMAT_ARGB4444, /* MesaFormat */
925 GL_RGBA, /* BaseFormat */
926 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
927 4, /* RedBits */
928 4, /* GreenBits */
929 4, /* BlueBits */
930 4, /* AlphaBits */
931 0, /* LuminanceBits */
932 0, /* IntensityBits */
933 0, /* IndexBits */
934 0, /* DepthBits */
935 0, /* StencilBits */
936 2, /* TexelBytes */
937 _mesa_texstore_argb4444, /* StoreTexImageFunc */
938 fetch_texel_1d_argb4444, /* FetchTexel1D */
939 fetch_texel_2d_argb4444, /* FetchTexel2D */
940 fetch_texel_3d_argb4444, /* FetchTexel3D */
941 NULL, /* FetchTexel1Df */
942 NULL, /* FetchTexel2Df */
943 NULL, /* FetchTexel3Df */
944 store_texel_argb4444 /* StoreTexel */
945 };
946
947 const struct gl_texture_format _mesa_texformat_argb4444_rev = {
948 MESA_FORMAT_ARGB4444_REV, /* MesaFormat */
949 GL_RGBA, /* BaseFormat */
950 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
951 4, /* RedBits */
952 4, /* GreenBits */
953 4, /* BlueBits */
954 4, /* AlphaBits */
955 0, /* LuminanceBits */
956 0, /* IntensityBits */
957 0, /* IndexBits */
958 0, /* DepthBits */
959 0, /* StencilBits */
960 2, /* TexelBytes */
961 _mesa_texstore_argb4444, /* StoreTexImageFunc */
962 fetch_texel_1d_argb4444_rev, /* FetchTexel1D */
963 fetch_texel_2d_argb4444_rev, /* FetchTexel2D */
964 fetch_texel_3d_argb4444_rev, /* FetchTexel3D */
965 NULL, /* FetchTexel1Df */
966 NULL, /* FetchTexel2Df */
967 NULL, /* FetchTexel3Df */
968 store_texel_argb4444_rev /* StoreTexel */
969 };
970
971 const struct gl_texture_format _mesa_texformat_rgba5551 = {
972 MESA_FORMAT_RGBA5551, /* MesaFormat */
973 GL_RGBA, /* BaseFormat */
974 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
975 5, /* RedBits */
976 5, /* GreenBits */
977 5, /* BlueBits */
978 1, /* AlphaBits */
979 0, /* LuminanceBits */
980 0, /* IntensityBits */
981 0, /* IndexBits */
982 0, /* DepthBits */
983 0, /* StencilBits */
984 2, /* TexelBytes */
985 _mesa_texstore_rgba5551, /* StoreTexImageFunc */
986 fetch_texel_1d_rgba5551, /* FetchTexel1D */
987 fetch_texel_2d_rgba5551, /* FetchTexel2D */
988 fetch_texel_3d_rgba5551, /* FetchTexel3D */
989 NULL, /* FetchTexel1Df */
990 NULL, /* FetchTexel2Df */
991 NULL, /* FetchTexel3Df */
992 store_texel_rgba5551 /* StoreTexel */
993 };
994
995 const struct gl_texture_format _mesa_texformat_argb1555 = {
996 MESA_FORMAT_ARGB1555, /* MesaFormat */
997 GL_RGBA, /* BaseFormat */
998 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
999 5, /* RedBits */
1000 5, /* GreenBits */
1001 5, /* BlueBits */
1002 1, /* AlphaBits */
1003 0, /* LuminanceBits */
1004 0, /* IntensityBits */
1005 0, /* IndexBits */
1006 0, /* DepthBits */
1007 0, /* StencilBits */
1008 2, /* TexelBytes */
1009 _mesa_texstore_argb1555, /* StoreTexImageFunc */
1010 fetch_texel_1d_argb1555, /* FetchTexel1D */
1011 fetch_texel_2d_argb1555, /* FetchTexel2D */
1012 fetch_texel_3d_argb1555, /* FetchTexel3D */
1013 NULL, /* FetchTexel1Df */
1014 NULL, /* FetchTexel2Df */
1015 NULL, /* FetchTexel3Df */
1016 store_texel_argb1555 /* StoreTexel */
1017 };
1018
1019 const struct gl_texture_format _mesa_texformat_argb1555_rev = {
1020 MESA_FORMAT_ARGB1555_REV, /* MesaFormat */
1021 GL_RGBA, /* BaseFormat */
1022 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1023 5, /* RedBits */
1024 5, /* GreenBits */
1025 5, /* BlueBits */
1026 1, /* AlphaBits */
1027 0, /* LuminanceBits */
1028 0, /* IntensityBits */
1029 0, /* IndexBits */
1030 0, /* DepthBits */
1031 0, /* StencilBits */
1032 2, /* TexelBytes */
1033 _mesa_texstore_argb1555, /* StoreTexImageFunc */
1034 fetch_texel_1d_argb1555_rev, /* FetchTexel1D */
1035 fetch_texel_2d_argb1555_rev, /* FetchTexel2D */
1036 fetch_texel_3d_argb1555_rev, /* FetchTexel3D */
1037 NULL, /* FetchTexel1Df */
1038 NULL, /* FetchTexel2Df */
1039 NULL, /* FetchTexel3Df */
1040 store_texel_argb1555_rev /* StoreTexel */
1041 };
1042
1043 const struct gl_texture_format _mesa_texformat_al88 = {
1044 MESA_FORMAT_AL88, /* MesaFormat */
1045 GL_LUMINANCE_ALPHA, /* BaseFormat */
1046 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1047 0, /* RedBits */
1048 0, /* GreenBits */
1049 0, /* BlueBits */
1050 8, /* AlphaBits */
1051 8, /* LuminanceBits */
1052 0, /* IntensityBits */
1053 0, /* IndexBits */
1054 0, /* DepthBits */
1055 0, /* StencilBits */
1056 2, /* TexelBytes */
1057 _mesa_texstore_al88, /* StoreTexImageFunc */
1058 fetch_texel_1d_al88, /* FetchTexel1D */
1059 fetch_texel_2d_al88, /* FetchTexel2D */
1060 fetch_texel_3d_al88, /* FetchTexel3D */
1061 NULL, /* FetchTexel1Df */
1062 NULL, /* FetchTexel2Df */
1063 NULL, /* FetchTexel3Df */
1064 store_texel_al88 /* StoreTexel */
1065 };
1066
1067 const struct gl_texture_format _mesa_texformat_al88_rev = {
1068 MESA_FORMAT_AL88_REV, /* MesaFormat */
1069 GL_LUMINANCE_ALPHA, /* BaseFormat */
1070 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1071 0, /* RedBits */
1072 0, /* GreenBits */
1073 0, /* BlueBits */
1074 8, /* AlphaBits */
1075 8, /* LuminanceBits */
1076 0, /* IntensityBits */
1077 0, /* IndexBits */
1078 0, /* DepthBits */
1079 0, /* StencilBits */
1080 2, /* TexelBytes */
1081 _mesa_texstore_al88, /* StoreTexImageFunc */
1082 fetch_texel_1d_al88_rev, /* FetchTexel1D */
1083 fetch_texel_2d_al88_rev, /* FetchTexel2D */
1084 fetch_texel_3d_al88_rev, /* FetchTexel3D */
1085 NULL, /* FetchTexel1Df */
1086 NULL, /* FetchTexel2Df */
1087 NULL, /* FetchTexel3Df */
1088 store_texel_al88_rev /* StoreTexel */
1089 };
1090
1091 const struct gl_texture_format _mesa_texformat_rgb332 = {
1092 MESA_FORMAT_RGB332, /* MesaFormat */
1093 GL_RGB, /* BaseFormat */
1094 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1095 3, /* RedBits */
1096 3, /* GreenBits */
1097 2, /* BlueBits */
1098 0, /* AlphaBits */
1099 0, /* LuminanceBits */
1100 0, /* IntensityBits */
1101 0, /* IndexBits */
1102 0, /* DepthBits */
1103 0, /* StencilBits */
1104 1, /* TexelBytes */
1105 _mesa_texstore_rgb332, /* StoreTexImageFunc */
1106 fetch_texel_1d_rgb332, /* FetchTexel1D */
1107 fetch_texel_2d_rgb332, /* FetchTexel2D */
1108 fetch_texel_3d_rgb332, /* FetchTexel3D */
1109 NULL, /* FetchTexel1Df */
1110 NULL, /* FetchTexel2Df */
1111 NULL, /* FetchTexel3Df */
1112 store_texel_rgb332 /* StoreTexel */
1113 };
1114
1115 const struct gl_texture_format _mesa_texformat_a8 = {
1116 MESA_FORMAT_A8, /* MesaFormat */
1117 GL_ALPHA, /* BaseFormat */
1118 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1119 0, /* RedBits */
1120 0, /* GreenBits */
1121 0, /* BlueBits */
1122 8, /* AlphaBits */
1123 0, /* LuminanceBits */
1124 0, /* IntensityBits */
1125 0, /* IndexBits */
1126 0, /* DepthBits */
1127 0, /* StencilBits */
1128 1, /* TexelBytes */
1129 _mesa_texstore_a8, /* StoreTexImageFunc */
1130 fetch_texel_1d_a8, /* FetchTexel1D */
1131 fetch_texel_2d_a8, /* FetchTexel2D */
1132 fetch_texel_3d_a8, /* FetchTexel3D */
1133 NULL, /* FetchTexel1Df */
1134 NULL, /* FetchTexel2Df */
1135 NULL, /* FetchTexel3Df */
1136 store_texel_a8 /* StoreTexel */
1137 };
1138
1139 const struct gl_texture_format _mesa_texformat_l8 = {
1140 MESA_FORMAT_L8, /* MesaFormat */
1141 GL_LUMINANCE, /* BaseFormat */
1142 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1143 0, /* RedBits */
1144 0, /* GreenBits */
1145 0, /* BlueBits */
1146 0, /* AlphaBits */
1147 8, /* LuminanceBits */
1148 0, /* IntensityBits */
1149 0, /* IndexBits */
1150 0, /* DepthBits */
1151 0, /* StencilBits */
1152 1, /* TexelBytes */
1153 _mesa_texstore_a8,/*yes*/ /* StoreTexImageFunc */
1154 fetch_texel_1d_l8, /* FetchTexel1D */
1155 fetch_texel_2d_l8, /* FetchTexel2D */
1156 fetch_texel_3d_l8, /* FetchTexel3D */
1157 NULL, /* FetchTexel1Df */
1158 NULL, /* FetchTexel2Df */
1159 NULL, /* FetchTexel3Df */
1160 store_texel_l8 /* StoreTexel */
1161 };
1162
1163 const struct gl_texture_format _mesa_texformat_i8 = {
1164 MESA_FORMAT_I8, /* MesaFormat */
1165 GL_INTENSITY, /* BaseFormat */
1166 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1167 0, /* RedBits */
1168 0, /* GreenBits */
1169 0, /* BlueBits */
1170 0, /* AlphaBits */
1171 0, /* LuminanceBits */
1172 8, /* IntensityBits */
1173 0, /* IndexBits */
1174 0, /* DepthBits */
1175 0, /* StencilBits */
1176 1, /* TexelBytes */
1177 _mesa_texstore_a8,/*yes*/ /* StoreTexImageFunc */
1178 fetch_texel_1d_i8, /* FetchTexel1D */
1179 fetch_texel_2d_i8, /* FetchTexel2D */
1180 fetch_texel_3d_i8, /* FetchTexel3D */
1181 NULL, /* FetchTexel1Df */
1182 NULL, /* FetchTexel2Df */
1183 NULL, /* FetchTexel3Df */
1184 store_texel_i8 /* StoreTexel */
1185 };
1186
1187 const struct gl_texture_format _mesa_texformat_ci8 = {
1188 MESA_FORMAT_CI8, /* MesaFormat */
1189 GL_COLOR_INDEX, /* BaseFormat */
1190 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1191 0, /* RedBits */
1192 0, /* GreenBits */
1193 0, /* BlueBits */
1194 0, /* AlphaBits */
1195 0, /* LuminanceBits */
1196 0, /* IntensityBits */
1197 8, /* IndexBits */
1198 0, /* DepthBits */
1199 0, /* StencilBits */
1200 1, /* TexelBytes */
1201 _mesa_texstore_ci8, /* StoreTexImageFunc */
1202 fetch_texel_1d_ci8, /* FetchTexel1D */
1203 fetch_texel_2d_ci8, /* FetchTexel2D */
1204 fetch_texel_3d_ci8, /* FetchTexel3D */
1205 NULL, /* FetchTexel1Df */
1206 NULL, /* FetchTexel2Df */
1207 NULL, /* FetchTexel3Df */
1208 store_texel_ci8 /* StoreTexel */
1209 };
1210
1211 const struct gl_texture_format _mesa_texformat_ycbcr = {
1212 MESA_FORMAT_YCBCR, /* MesaFormat */
1213 GL_YCBCR_MESA, /* BaseFormat */
1214 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1215 0, /* RedBits */
1216 0, /* GreenBits */
1217 0, /* BlueBits */
1218 0, /* AlphaBits */
1219 0, /* LuminanceBits */
1220 0, /* IntensityBits */
1221 0, /* IndexBits */
1222 0, /* DepthBits */
1223 0, /* StencilBits */
1224 2, /* TexelBytes */
1225 _mesa_texstore_ycbcr, /* StoreTexImageFunc */
1226 fetch_texel_1d_ycbcr, /* FetchTexel1D */
1227 fetch_texel_2d_ycbcr, /* FetchTexel2D */
1228 fetch_texel_3d_ycbcr, /* FetchTexel3D */
1229 NULL, /* FetchTexel1Df */
1230 NULL, /* FetchTexel2Df */
1231 NULL, /* FetchTexel3Df */
1232 store_texel_ycbcr /* StoreTexel */
1233 };
1234
1235 const struct gl_texture_format _mesa_texformat_ycbcr_rev = {
1236 MESA_FORMAT_YCBCR_REV, /* MesaFormat */
1237 GL_YCBCR_MESA, /* BaseFormat */
1238 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1239 0, /* RedBits */
1240 0, /* GreenBits */
1241 0, /* BlueBits */
1242 0, /* AlphaBits */
1243 0, /* LuminanceBits */
1244 0, /* IntensityBits */
1245 0, /* IndexBits */
1246 0, /* DepthBits */
1247 0, /* StencilBits */
1248 2, /* TexelBytes */
1249 _mesa_texstore_ycbcr, /* StoreTexImageFunc */
1250 fetch_texel_1d_ycbcr_rev, /* FetchTexel1D */
1251 fetch_texel_2d_ycbcr_rev, /* FetchTexel2D */
1252 fetch_texel_3d_ycbcr_rev, /* FetchTexel3D */
1253 NULL, /* FetchTexel1Df */
1254 NULL, /* FetchTexel2Df */
1255 NULL, /* FetchTexel3Df */
1256 store_texel_ycbcr_rev /* StoreTexel */
1257 };
1258
1259 const struct gl_texture_format _mesa_texformat_z24_s8 = {
1260 MESA_FORMAT_Z24_S8, /* MesaFormat */
1261 GL_DEPTH_STENCIL_EXT, /* BaseFormat */
1262 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1263 0, /* RedBits */
1264 0, /* GreenBits */
1265 0, /* BlueBits */
1266 0, /* AlphaBits */
1267 0, /* LuminanceBits */
1268 0, /* IntensityBits */
1269 0, /* IndexBits */
1270 24, /* DepthBits */
1271 8, /* StencilBits */
1272 4, /* TexelBytes */
1273 _mesa_texstore_z24_s8, /* StoreTexImageFunc */
1274 NULL, /* FetchTexel1D */
1275 NULL, /* FetchTexel2D */
1276 NULL, /* FetchTexel3D */
1277 fetch_texel_1d_f_z24_s8, /* FetchTexel1Df */
1278 fetch_texel_2d_f_z24_s8, /* FetchTexel2Df */
1279 fetch_texel_3d_f_z24_s8, /* FetchTexel3Df */
1280 store_texel_z24_s8 /* StoreTexel */
1281 };
1282
1283 const struct gl_texture_format _mesa_texformat_s8_z24 = {
1284 MESA_FORMAT_S8_Z24, /* MesaFormat */
1285 GL_DEPTH_STENCIL_EXT, /* BaseFormat */
1286 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1287 0, /* RedBits */
1288 0, /* GreenBits */
1289 0, /* BlueBits */
1290 0, /* AlphaBits */
1291 0, /* LuminanceBits */
1292 0, /* IntensityBits */
1293 0, /* IndexBits */
1294 24, /* DepthBits */
1295 8, /* StencilBits */
1296 4, /* TexelBytes */
1297 _mesa_texstore_s8_z24, /* StoreTexImageFunc */
1298 NULL, /* FetchTexel1D */
1299 NULL, /* FetchTexel2D */
1300 NULL, /* FetchTexel3D */
1301 fetch_texel_1d_f_s8_z24, /* FetchTexel1Df */
1302 fetch_texel_2d_f_s8_z24, /* FetchTexel2Df */
1303 fetch_texel_3d_f_s8_z24, /* FetchTexel3Df */
1304 store_texel_s8_z24 /* StoreTexel */
1305 };
1306
1307 const struct gl_texture_format _mesa_texformat_z16 = {
1308 MESA_FORMAT_Z16, /* MesaFormat */
1309 GL_DEPTH_COMPONENT, /* BaseFormat */
1310 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1311 0, /* RedBits */
1312 0, /* GreenBits */
1313 0, /* BlueBits */
1314 0, /* AlphaBits */
1315 0, /* LuminanceBits */
1316 0, /* IntensityBits */
1317 0, /* IndexBits */
1318 sizeof(GLushort) * 8, /* DepthBits */
1319 0, /* StencilBits */
1320 sizeof(GLushort), /* TexelBytes */
1321 _mesa_texstore_z16, /* StoreTexImageFunc */
1322 NULL, /* FetchTexel1D */
1323 NULL, /* FetchTexel1D */
1324 NULL, /* FetchTexel1D */
1325 fetch_texel_1d_f_z16, /* FetchTexel1Df */
1326 fetch_texel_2d_f_z16, /* FetchTexel2Df */
1327 fetch_texel_3d_f_z16, /* FetchTexel3Df */
1328 store_texel_z16 /* StoreTexel */
1329 };
1330
1331 const struct gl_texture_format _mesa_texformat_z32 = {
1332 MESA_FORMAT_Z32, /* MesaFormat */
1333 GL_DEPTH_COMPONENT, /* BaseFormat */
1334 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1335 0, /* RedBits */
1336 0, /* GreenBits */
1337 0, /* BlueBits */
1338 0, /* AlphaBits */
1339 0, /* LuminanceBits */
1340 0, /* IntensityBits */
1341 0, /* IndexBits */
1342 sizeof(GLuint) * 8, /* DepthBits */
1343 0, /* StencilBits */
1344 sizeof(GLuint), /* TexelBytes */
1345 _mesa_texstore_z32, /* StoreTexImageFunc */
1346 NULL, /* FetchTexel1D */
1347 NULL, /* FetchTexel1D */
1348 NULL, /* FetchTexel1D */
1349 fetch_texel_1d_f_z32, /* FetchTexel1Df */
1350 fetch_texel_2d_f_z32, /* FetchTexel2Df */
1351 fetch_texel_3d_f_z32, /* FetchTexel3Df */
1352 store_texel_z32 /* StoreTexel */
1353 };
1354
1355 /*@}*/
1356
1357
1358 /***************************************************************/
1359 /** \name Null format (useful for proxy textures) */
1360 /*@{*/
1361
1362 const struct gl_texture_format _mesa_null_texformat = {
1363 -1, /* MesaFormat */
1364 0, /* BaseFormat */
1365 GL_NONE, /* DataType */
1366 0, /* RedBits */
1367 0, /* GreenBits */
1368 0, /* BlueBits */
1369 0, /* AlphaBits */
1370 0, /* LuminanceBits */
1371 0, /* IntensityBits */
1372 0, /* IndexBits */
1373 0, /* DepthBits */
1374 0, /* StencilBits */
1375 0, /* TexelBytes */
1376 NULL, /* StoreTexImageFunc */
1377 fetch_null_texel, /* FetchTexel1D */
1378 fetch_null_texel, /* FetchTexel2D */
1379 fetch_null_texel, /* FetchTexel3D */
1380 fetch_null_texelf, /* FetchTexel1Df */
1381 fetch_null_texelf, /* FetchTexel2Df */
1382 fetch_null_texelf, /* FetchTexel3Df */
1383 store_null_texel /* StoreTexel */
1384 };
1385
1386 /*@}*/
1387
1388
1389 /**
1390 * Choose an appropriate texture format given the format, type and
1391 * internalFormat parameters passed to glTexImage().
1392 *
1393 * \param ctx the GL context.
1394 * \param internalFormat user's prefered internal texture format.
1395 * \param format incoming image pixel format.
1396 * \param type incoming image data type.
1397 *
1398 * \return a pointer to a gl_texture_format object which describes the
1399 * choosen texture format, or NULL on failure.
1400 *
1401 * This is called via dd_function_table::ChooseTextureFormat. Hardware drivers
1402 * will typically override this function with a specialized version.
1403 */
1404 const struct gl_texture_format *
1405 _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
1406 GLenum format, GLenum type )
1407 {
1408 (void) format;
1409 (void) type;
1410
1411 switch (internalFormat) {
1412 /* RGBA formats */
1413 case 4:
1414 case GL_RGBA:
1415 case GL_RGB10_A2:
1416 case GL_RGBA12:
1417 case GL_RGBA16:
1418 return &_mesa_texformat_rgba;
1419 case GL_RGBA8:
1420 return &_mesa_texformat_rgba8888;
1421 case GL_RGB5_A1:
1422 return &_mesa_texformat_argb1555;
1423 case GL_RGBA2:
1424 return &_mesa_texformat_argb4444_rev; /* just to test another format*/
1425 case GL_RGBA4:
1426 return &_mesa_texformat_argb4444;
1427
1428 /* RGB formats */
1429 case 3:
1430 case GL_RGB:
1431 case GL_RGB10:
1432 case GL_RGB12:
1433 case GL_RGB16:
1434 return &_mesa_texformat_rgb;
1435 case GL_RGB8:
1436 return &_mesa_texformat_rgb888;
1437 case GL_R3_G3_B2:
1438 return &_mesa_texformat_rgb332;
1439 case GL_RGB4:
1440 return &_mesa_texformat_rgb565_rev; /* just to test another format */
1441 case GL_RGB5:
1442 return &_mesa_texformat_rgb565;
1443
1444 /* Alpha formats */
1445 case GL_ALPHA:
1446 case GL_ALPHA4:
1447 case GL_ALPHA12:
1448 case GL_ALPHA16:
1449 return &_mesa_texformat_alpha;
1450 case GL_ALPHA8:
1451 return &_mesa_texformat_a8;
1452
1453 /* Luminance formats */
1454 case 1:
1455 case GL_LUMINANCE:
1456 case GL_LUMINANCE4:
1457 case GL_LUMINANCE12:
1458 case GL_LUMINANCE16:
1459 return &_mesa_texformat_luminance;
1460 case GL_LUMINANCE8:
1461 return &_mesa_texformat_l8;
1462
1463 /* Luminance/Alpha formats */
1464 case 2:
1465 case GL_LUMINANCE_ALPHA:
1466 case GL_LUMINANCE4_ALPHA4:
1467 case GL_LUMINANCE6_ALPHA2:
1468 case GL_LUMINANCE12_ALPHA4:
1469 case GL_LUMINANCE12_ALPHA12:
1470 case GL_LUMINANCE16_ALPHA16:
1471 return &_mesa_texformat_luminance_alpha;
1472 case GL_LUMINANCE8_ALPHA8:
1473 return &_mesa_texformat_al88;
1474
1475 case GL_INTENSITY:
1476 case GL_INTENSITY4:
1477 case GL_INTENSITY12:
1478 case GL_INTENSITY16:
1479 return &_mesa_texformat_intensity;
1480 case GL_INTENSITY8:
1481 return &_mesa_texformat_i8;
1482
1483 case GL_COLOR_INDEX:
1484 case GL_COLOR_INDEX1_EXT:
1485 case GL_COLOR_INDEX2_EXT:
1486 case GL_COLOR_INDEX4_EXT:
1487 case GL_COLOR_INDEX12_EXT:
1488 case GL_COLOR_INDEX16_EXT:
1489 case GL_COLOR_INDEX8_EXT:
1490 return &_mesa_texformat_ci8;
1491
1492 default:
1493 ; /* fallthrough */
1494 }
1495
1496 if (ctx->Extensions.ARB_depth_texture) {
1497 switch (internalFormat) {
1498 case GL_DEPTH_COMPONENT:
1499 case GL_DEPTH_COMPONENT24:
1500 case GL_DEPTH_COMPONENT32:
1501 return &_mesa_texformat_z32;
1502 case GL_DEPTH_COMPONENT16:
1503 return &_mesa_texformat_z16;
1504 default:
1505 ; /* fallthrough */
1506 }
1507 }
1508
1509 if (ctx->Extensions.ARB_texture_compression) {
1510 switch (internalFormat) {
1511 case GL_COMPRESSED_ALPHA_ARB:
1512 return &_mesa_texformat_alpha;
1513 case GL_COMPRESSED_LUMINANCE_ARB:
1514 return &_mesa_texformat_luminance;
1515 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
1516 return &_mesa_texformat_luminance_alpha;
1517 case GL_COMPRESSED_INTENSITY_ARB:
1518 return &_mesa_texformat_intensity;
1519 case GL_COMPRESSED_RGB_ARB:
1520 #if FEATURE_texture_fxt1
1521 if (ctx->Extensions.TDFX_texture_compression_FXT1)
1522 return &_mesa_texformat_rgb_fxt1;
1523 #endif
1524 #if FEATURE_texture_s3tc
1525 if (ctx->Extensions.EXT_texture_compression_s3tc ||
1526 ctx->Extensions.S3_s3tc)
1527 return &_mesa_texformat_rgb_dxt1;
1528 #endif
1529 return &_mesa_texformat_rgb;
1530 case GL_COMPRESSED_RGBA_ARB:
1531 #if FEATURE_texture_fxt1
1532 if (ctx->Extensions.TDFX_texture_compression_FXT1)
1533 return &_mesa_texformat_rgba_fxt1;
1534 #endif
1535 #if FEATURE_texture_s3tc
1536 if (ctx->Extensions.EXT_texture_compression_s3tc ||
1537 ctx->Extensions.S3_s3tc)
1538 return &_mesa_texformat_rgba_dxt3; /* Not rgba_dxt1, see spec */
1539 #endif
1540 return &_mesa_texformat_rgba;
1541 default:
1542 ; /* fallthrough */
1543 }
1544 }
1545
1546 if (ctx->Extensions.MESA_ycbcr_texture) {
1547 if (internalFormat == GL_YCBCR_MESA) {
1548 if (type == GL_UNSIGNED_SHORT_8_8_MESA)
1549 return &_mesa_texformat_ycbcr;
1550 else
1551 return &_mesa_texformat_ycbcr_rev;
1552 }
1553 }
1554
1555 #if FEATURE_texture_fxt1
1556 if (ctx->Extensions.TDFX_texture_compression_FXT1) {
1557 switch (internalFormat) {
1558 case GL_COMPRESSED_RGB_FXT1_3DFX:
1559 return &_mesa_texformat_rgb_fxt1;
1560 case GL_COMPRESSED_RGBA_FXT1_3DFX:
1561 return &_mesa_texformat_rgba_fxt1;
1562 default:
1563 ; /* fallthrough */
1564 }
1565 }
1566 #endif
1567
1568 #if FEATURE_texture_s3tc
1569 if (ctx->Extensions.EXT_texture_compression_s3tc) {
1570 switch (internalFormat) {
1571 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1572 return &_mesa_texformat_rgb_dxt1;
1573 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1574 return &_mesa_texformat_rgba_dxt1;
1575 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
1576 return &_mesa_texformat_rgba_dxt3;
1577 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
1578 return &_mesa_texformat_rgba_dxt5;
1579 default:
1580 ; /* fallthrough */
1581 }
1582 }
1583
1584 if (ctx->Extensions.S3_s3tc) {
1585 switch (internalFormat) {
1586 case GL_RGB_S3TC:
1587 case GL_RGB4_S3TC:
1588 return &_mesa_texformat_rgb_dxt1;
1589 case GL_RGBA_S3TC:
1590 case GL_RGBA4_S3TC:
1591 return &_mesa_texformat_rgba_dxt3;
1592 default:
1593 ; /* fallthrough */
1594 }
1595 }
1596 #endif
1597
1598 if (ctx->Extensions.ARB_texture_float) {
1599 switch (internalFormat) {
1600 case GL_ALPHA16F_ARB:
1601 return &_mesa_texformat_alpha_float16;
1602 case GL_ALPHA32F_ARB:
1603 return &_mesa_texformat_alpha_float32;
1604 case GL_LUMINANCE16F_ARB:
1605 return &_mesa_texformat_luminance_float16;
1606 case GL_LUMINANCE32F_ARB:
1607 return &_mesa_texformat_luminance_float32;
1608 case GL_LUMINANCE_ALPHA16F_ARB:
1609 return &_mesa_texformat_luminance_alpha_float16;
1610 case GL_LUMINANCE_ALPHA32F_ARB:
1611 return &_mesa_texformat_luminance_alpha_float32;
1612 case GL_INTENSITY16F_ARB:
1613 return &_mesa_texformat_intensity_float16;
1614 case GL_INTENSITY32F_ARB:
1615 return &_mesa_texformat_intensity_float32;
1616 case GL_RGB16F_ARB:
1617 return &_mesa_texformat_rgb_float16;
1618 case GL_RGB32F_ARB:
1619 return &_mesa_texformat_rgb_float32;
1620 case GL_RGBA16F_ARB:
1621 return &_mesa_texformat_rgba_float16;
1622 case GL_RGBA32F_ARB:
1623 return &_mesa_texformat_rgba_float32;
1624 default:
1625 ; /* fallthrough */
1626 }
1627 }
1628
1629 if (ctx->Extensions.EXT_packed_depth_stencil) {
1630 switch (internalFormat) {
1631 case GL_DEPTH_STENCIL_EXT:
1632 case GL_DEPTH24_STENCIL8_EXT:
1633 return &_mesa_texformat_z24_s8;
1634 default:
1635 ; /* fallthrough */
1636 }
1637 }
1638
1639 #if FEATURE_EXT_texture_sRGB
1640 if (ctx->Extensions.EXT_texture_sRGB) {
1641 switch (internalFormat) {
1642 case GL_SRGB_EXT:
1643 case GL_SRGB8_EXT:
1644 return &_mesa_texformat_srgb8;
1645 case GL_SRGB_ALPHA_EXT:
1646 case GL_SRGB8_ALPHA8_EXT:
1647 return &_mesa_texformat_srgba8;
1648 case GL_SLUMINANCE_EXT:
1649 case GL_SLUMINANCE8_EXT:
1650 return &_mesa_texformat_sl8;
1651 case GL_SLUMINANCE_ALPHA_EXT:
1652 case GL_SLUMINANCE8_ALPHA8_EXT:
1653 return &_mesa_texformat_sla8;
1654 case GL_COMPRESSED_SLUMINANCE_EXT:
1655 return &_mesa_texformat_sl8;
1656 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
1657 return &_mesa_texformat_sla8;
1658 case GL_COMPRESSED_SRGB_EXT:
1659 #if FEATURE_texture_s3tc
1660 if (ctx->Extensions.EXT_texture_compression_s3tc)
1661 return &_mesa_texformat_srgb_dxt1;
1662 #endif
1663 return &_mesa_texformat_srgb8;
1664 case GL_COMPRESSED_SRGB_ALPHA_EXT:
1665 #if FEATURE_texture_s3tc
1666 if (ctx->Extensions.EXT_texture_compression_s3tc)
1667 return &_mesa_texformat_srgba_dxt3; /* Not srgba_dxt1, see spec */
1668 #endif
1669 return &_mesa_texformat_srgba8;
1670 #if FEATURE_texture_s3tc
1671 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
1672 if (ctx->Extensions.EXT_texture_compression_s3tc)
1673 return &_mesa_texformat_srgb_dxt1;
1674 break;
1675 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
1676 if (ctx->Extensions.EXT_texture_compression_s3tc)
1677 return &_mesa_texformat_srgba_dxt1;
1678 break;
1679 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
1680 if (ctx->Extensions.EXT_texture_compression_s3tc)
1681 return &_mesa_texformat_srgba_dxt3;
1682 break;
1683 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
1684 if (ctx->Extensions.EXT_texture_compression_s3tc)
1685 return &_mesa_texformat_srgba_dxt5;
1686 break;
1687 #endif
1688 default:
1689 ; /* fallthrough */
1690 }
1691 }
1692 #endif /* FEATURE_EXT_texture_sRGB */
1693
1694 _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
1695 return NULL;
1696 }
1697
1698
1699
1700 /**
1701 * Return datatype and number of components per texel for the
1702 * given gl_texture_format.
1703 */
1704 void
1705 _mesa_format_to_type_and_comps(const struct gl_texture_format *format,
1706 GLenum *datatype, GLuint *comps)
1707 {
1708 switch (format->MesaFormat) {
1709 case MESA_FORMAT_RGBA8888:
1710 case MESA_FORMAT_RGBA8888_REV:
1711 case MESA_FORMAT_ARGB8888:
1712 case MESA_FORMAT_ARGB8888_REV:
1713 *datatype = CHAN_TYPE;
1714 *comps = 4;
1715 return;
1716 case MESA_FORMAT_RGB888:
1717 case MESA_FORMAT_BGR888:
1718 *datatype = GL_UNSIGNED_BYTE;
1719 *comps = 3;
1720 return;
1721 case MESA_FORMAT_RGB565:
1722 case MESA_FORMAT_RGB565_REV:
1723 *datatype = GL_UNSIGNED_SHORT_5_6_5;
1724 *comps = 3;
1725 return;
1726
1727 case MESA_FORMAT_ARGB4444:
1728 case MESA_FORMAT_ARGB4444_REV:
1729 *datatype = GL_UNSIGNED_SHORT_4_4_4_4;
1730 *comps = 4;
1731 return;
1732
1733 case MESA_FORMAT_ARGB1555:
1734 case MESA_FORMAT_ARGB1555_REV:
1735 *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
1736 *comps = 4;
1737 return;
1738
1739 case MESA_FORMAT_AL88:
1740 case MESA_FORMAT_AL88_REV:
1741 *datatype = GL_UNSIGNED_BYTE;
1742 *comps = 2;
1743 return;
1744 case MESA_FORMAT_RGB332:
1745 *datatype = GL_UNSIGNED_BYTE_3_3_2;
1746 *comps = 3;
1747 return;
1748
1749 case MESA_FORMAT_A8:
1750 case MESA_FORMAT_L8:
1751 case MESA_FORMAT_I8:
1752 case MESA_FORMAT_CI8:
1753 *datatype = GL_UNSIGNED_BYTE;
1754 *comps = 1;
1755 return;
1756
1757 case MESA_FORMAT_YCBCR:
1758 case MESA_FORMAT_YCBCR_REV:
1759 *datatype = GL_UNSIGNED_SHORT;
1760 *comps = 2;
1761 return;
1762
1763 case MESA_FORMAT_Z24_S8:
1764 *datatype = GL_UNSIGNED_INT;
1765 *comps = 1; /* XXX OK? */
1766 return;
1767
1768 case MESA_FORMAT_S8_Z24:
1769 *datatype = GL_UNSIGNED_INT;
1770 *comps = 1; /* XXX OK? */
1771 return;
1772
1773 case MESA_FORMAT_Z16:
1774 *datatype = GL_UNSIGNED_SHORT;
1775 *comps = 1;
1776 return;
1777
1778 case MESA_FORMAT_Z32:
1779 *datatype = GL_UNSIGNED_INT;
1780 *comps = 1;
1781 return;
1782
1783 #if FEATURE_EXT_texture_sRGB
1784 case MESA_FORMAT_SRGB8:
1785 *datatype = GL_UNSIGNED_BYTE;
1786 *comps = 3;
1787 return;
1788 case MESA_FORMAT_SRGBA8:
1789 case MESA_FORMAT_SARGB8:
1790 *datatype = GL_UNSIGNED_BYTE;
1791 *comps = 4;
1792 return;
1793 case MESA_FORMAT_SL8:
1794 *datatype = GL_UNSIGNED_BYTE;
1795 *comps = 1;
1796 return;
1797 case MESA_FORMAT_SLA8:
1798 *datatype = GL_UNSIGNED_BYTE;
1799 *comps = 2;
1800 return;
1801 #endif
1802
1803 #if FEATURE_texture_fxt1
1804 case MESA_FORMAT_RGB_FXT1:
1805 case MESA_FORMAT_RGBA_FXT1:
1806 #endif
1807 #if FEATURE_texture_s3tc
1808 case MESA_FORMAT_RGB_DXT1:
1809 case MESA_FORMAT_RGBA_DXT1:
1810 case MESA_FORMAT_RGBA_DXT3:
1811 case MESA_FORMAT_RGBA_DXT5:
1812 #if FEATURE_EXT_texture_sRGB
1813 case MESA_FORMAT_SRGB_DXT1:
1814 case MESA_FORMAT_SRGBA_DXT1:
1815 case MESA_FORMAT_SRGBA_DXT3:
1816 case MESA_FORMAT_SRGBA_DXT5:
1817 #endif
1818 /* XXX generate error instead? */
1819 *datatype = GL_UNSIGNED_BYTE;
1820 *comps = 0;
1821 return;
1822 #endif
1823
1824 case MESA_FORMAT_RGBA:
1825 *datatype = CHAN_TYPE;
1826 *comps = 4;
1827 return;
1828 case MESA_FORMAT_RGB:
1829 *datatype = CHAN_TYPE;
1830 *comps = 3;
1831 return;
1832 case MESA_FORMAT_LUMINANCE_ALPHA:
1833 *datatype = CHAN_TYPE;
1834 *comps = 2;
1835 return;
1836 case MESA_FORMAT_ALPHA:
1837 case MESA_FORMAT_LUMINANCE:
1838 case MESA_FORMAT_INTENSITY:
1839 *datatype = CHAN_TYPE;
1840 *comps = 1;
1841 return;
1842
1843 case MESA_FORMAT_RGBA_FLOAT32:
1844 *datatype = GL_FLOAT;
1845 *comps = 4;
1846 return;
1847 case MESA_FORMAT_RGBA_FLOAT16:
1848 *datatype = GL_HALF_FLOAT_ARB;
1849 *comps = 4;
1850 return;
1851 case MESA_FORMAT_RGB_FLOAT32:
1852 *datatype = GL_FLOAT;
1853 *comps = 3;
1854 return;
1855 case MESA_FORMAT_RGB_FLOAT16:
1856 *datatype = GL_HALF_FLOAT_ARB;
1857 *comps = 3;
1858 return;
1859 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
1860 *datatype = GL_FLOAT;
1861 *comps = 2;
1862 return;
1863 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
1864 *datatype = GL_HALF_FLOAT_ARB;
1865 *comps = 2;
1866 return;
1867 case MESA_FORMAT_ALPHA_FLOAT32:
1868 case MESA_FORMAT_LUMINANCE_FLOAT32:
1869 case MESA_FORMAT_INTENSITY_FLOAT32:
1870 *datatype = GL_FLOAT;
1871 *comps = 1;
1872 return;
1873 case MESA_FORMAT_ALPHA_FLOAT16:
1874 case MESA_FORMAT_LUMINANCE_FLOAT16:
1875 case MESA_FORMAT_INTENSITY_FLOAT16:
1876 *datatype = GL_HALF_FLOAT_ARB;
1877 *comps = 1;
1878 return;
1879
1880 default:
1881 _mesa_problem(NULL, "bad format in _mesa_format_to_type_and_comps");
1882 *datatype = 0;
1883 *comps = 1;
1884 }
1885 }