5 * \author Gareth Hughes
9 * Mesa 3-D graphics library
12 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the "Software"),
16 * to deal in the Software without restriction, including without limitation
17 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 * and/or sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following conditions:
21 * The above copyright notice and this permission notice shall be included
22 * in all copies or substantial portions of the Software.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
28 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 #include "texformat.h"
44 /* Texel fetch routines for all supported formats
47 #include "texformat_tmp.h"
50 #include "texformat_tmp.h"
53 #include "texformat_tmp.h"
56 * Null texel fetch function.
58 * Have to have this so the FetchTexel function pointer is never NULL.
60 static void fetch_null_texel( const struct gl_texture_image
*texImage
,
61 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
67 _mesa_warning(NULL
, "fetch_null_texel() called!");
70 static void fetch_null_texelf( const struct gl_texture_image
*texImage
,
71 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
77 _mesa_warning(NULL
, "fetch_null_texelf() called!");
81 /***************************************************************/
82 /** \name Default GLchan-based formats */
85 const struct gl_texture_format _mesa_texformat_rgba
= {
86 MESA_FORMAT_RGBA
, /* MesaFormat */
87 GL_RGBA
, /* BaseFormat */
88 CHAN_BITS
, /* RedBits */
89 CHAN_BITS
, /* GreenBits */
90 CHAN_BITS
, /* BlueBits */
91 CHAN_BITS
, /* AlphaBits */
92 0, /* LuminanceBits */
93 0, /* IntensityBits */
96 4 * CHAN_BITS
/ 8, /* TexelBytes */
97 fetch_texel_1d_rgba
, /* FetchTexel1D */
98 fetch_texel_2d_rgba
, /* FetchTexel2D */
99 fetch_texel_3d_rgba
, /* FetchTexel3D */
100 fetch_texel_1d_f_rgba
, /* FetchTexel1Df */
101 fetch_texel_2d_f_rgba
, /* FetchTexel2Df */
102 fetch_texel_3d_f_rgba
, /* FetchTexel3Df */
105 const struct gl_texture_format _mesa_texformat_rgb
= {
106 MESA_FORMAT_RGB
, /* MesaFormat */
107 GL_RGB
, /* BaseFormat */
108 CHAN_BITS
, /* RedBits */
109 CHAN_BITS
, /* GreenBits */
110 CHAN_BITS
, /* BlueBits */
112 0, /* LuminanceBits */
113 0, /* IntensityBits */
116 3 * CHAN_BITS
/ 8, /* TexelBytes */
117 fetch_texel_1d_rgb
, /* FetchTexel1D */
118 fetch_texel_2d_rgb
, /* FetchTexel2D */
119 fetch_texel_3d_rgb
, /* FetchTexel3D */
120 fetch_texel_1d_f_rgb
, /* FetchTexel1Df */
121 fetch_texel_2d_f_rgb
, /* FetchTexel2Df */
122 fetch_texel_3d_f_rgb
, /* FetchTexel3Df */
125 const struct gl_texture_format _mesa_texformat_alpha
= {
126 MESA_FORMAT_ALPHA
, /* MesaFormat */
127 GL_ALPHA
, /* BaseFormat */
131 CHAN_BITS
, /* AlphaBits */
132 0, /* LuminanceBits */
133 0, /* IntensityBits */
136 CHAN_BITS
/ 8, /* TexelBytes */
137 fetch_texel_1d_alpha
, /* FetchTexel1D */
138 fetch_texel_2d_alpha
, /* FetchTexel2D */
139 fetch_texel_3d_alpha
, /* FetchTexel3D */
140 fetch_texel_1d_f_alpha
, /* FetchTexel1Df */
141 fetch_texel_2d_f_alpha
, /* FetchTexel2Df */
142 fetch_texel_3d_f_alpha
, /* FetchTexel3Df */
145 const struct gl_texture_format _mesa_texformat_luminance
= {
146 MESA_FORMAT_LUMINANCE
, /* MesaFormat */
147 GL_LUMINANCE
, /* BaseFormat */
152 CHAN_BITS
, /* LuminanceBits */
153 0, /* IntensityBits */
156 CHAN_BITS
/ 8, /* TexelBytes */
157 fetch_texel_1d_luminance
, /* FetchTexel1D */
158 fetch_texel_2d_luminance
, /* FetchTexel2D */
159 fetch_texel_3d_luminance
, /* FetchTexel3D */
160 fetch_texel_1d_f_luminance
, /* FetchTexel1Df */
161 fetch_texel_2d_f_luminance
, /* FetchTexel2Df */
162 fetch_texel_3d_f_luminance
, /* FetchTexel3Df */
165 const struct gl_texture_format _mesa_texformat_luminance_alpha
= {
166 MESA_FORMAT_LUMINANCE_ALPHA
, /* MesaFormat */
167 GL_LUMINANCE_ALPHA
, /* BaseFormat */
171 CHAN_BITS
, /* AlphaBits */
172 CHAN_BITS
, /* LuminanceBits */
173 0, /* IntensityBits */
176 2 * CHAN_BITS
/ 8, /* TexelBytes */
177 fetch_texel_1d_luminance_alpha
, /* FetchTexel1D */
178 fetch_texel_2d_luminance_alpha
, /* FetchTexel2D */
179 fetch_texel_3d_luminance_alpha
, /* FetchTexel3D */
180 fetch_texel_1d_f_luminance_alpha
, /* FetchTexel1Df */
181 fetch_texel_2d_f_luminance_alpha
, /* FetchTexel2Df */
182 fetch_texel_3d_f_luminance_alpha
, /* FetchTexel3Df */
185 const struct gl_texture_format _mesa_texformat_intensity
= {
186 MESA_FORMAT_INTENSITY
, /* MesaFormat */
187 GL_INTENSITY
, /* BaseFormat */
192 0, /* LuminanceBits */
193 CHAN_BITS
, /* IntensityBits */
196 CHAN_BITS
/ 8, /* TexelBytes */
197 fetch_texel_1d_intensity
, /* FetchTexel1D */
198 fetch_texel_2d_intensity
, /* FetchTexel2D */
199 fetch_texel_3d_intensity
, /* FetchTexel3D */
200 fetch_texel_1d_f_intensity
, /* FetchTexel1Df */
201 fetch_texel_2d_f_intensity
, /* FetchTexel2Df */
202 fetch_texel_3d_f_intensity
, /* FetchTexel3Df */
205 const struct gl_texture_format _mesa_texformat_color_index
= {
206 MESA_FORMAT_COLOR_INDEX
, /* MesaFormat */
207 GL_COLOR_INDEX
, /* BaseFormat */
212 0, /* LuminanceBits */
213 0, /* IntensityBits */
214 CHAN_BITS
, /* IndexBits */
216 CHAN_BITS
/ 8, /* TexelBytes */
217 fetch_texel_1d_color_index
, /* FetchTexel1D */
218 fetch_texel_2d_color_index
, /* FetchTexel2D */
219 fetch_texel_3d_color_index
, /* FetchTexel3D */
220 fetch_texel_1d_f_color_index
, /* FetchTexel1Df */
221 fetch_texel_2d_f_color_index
, /* FetchTexel2Df */
222 fetch_texel_3d_f_color_index
, /* FetchTexel3Df */
225 /* XXX someday implement 16, 24 and 32-bit integer depth images */
226 const struct gl_texture_format _mesa_texformat_depth_component
= {
227 MESA_FORMAT_DEPTH_COMPONENT
, /* MesaFormat */
228 GL_DEPTH_COMPONENT
, /* BaseFormat */
233 0, /* LuminanceBits */
234 0, /* IntensityBits */
236 sizeof(GLfloat
) * 8, /* DepthBits */
237 sizeof(GLfloat
), /* TexelBytes */
238 fetch_null_texel
, /* FetchTexel1D */
239 fetch_null_texel
, /* FetchTexel1D */
240 fetch_null_texel
, /* FetchTexel1D */
241 fetch_texel_1d_f_depth_component
, /* FetchTexel1Df */
242 fetch_texel_2d_f_depth_component
, /* FetchTexel2Df */
243 fetch_texel_3d_f_depth_component
, /* FetchTexel3Df */
246 const struct gl_texture_format _mesa_texformat_rgba_float32
= {
247 MESA_FORMAT_RGBA_FLOAT32
, /* MesaFormat */
248 GL_RGBA
, /* BaseFormat */
249 8 * sizeof(GLfloat
), /* RedBits */
250 8 * sizeof(GLfloat
), /* GreenBits */
251 8 * sizeof(GLfloat
), /* BlueBits */
252 8 * sizeof(GLfloat
), /* AlphaBits */
253 0, /* LuminanceBits */
254 0, /* IntensityBits */
257 4 * sizeof(GLfloat
), /* TexelBytes */
258 fetch_null_texel
, /* FetchTexel1D */
259 fetch_null_texel
, /* FetchTexel1D */
260 fetch_null_texel
, /* FetchTexel1D */
261 fetch_texel_1d_f_rgba_f32
, /* FetchTexel1Df */
262 fetch_texel_2d_f_rgba_f32
, /* FetchTexel2Df */
263 fetch_texel_3d_f_rgba_f32
, /* FetchTexel3Df */
266 const struct gl_texture_format _mesa_texformat_rgba_float16
= {
267 MESA_FORMAT_RGBA_FLOAT16
, /* MesaFormat */
268 GL_RGBA
, /* BaseFormat */
269 8 * sizeof(GLhalfNV
), /* RedBits */
270 8 * sizeof(GLhalfNV
), /* GreenBits */
271 8 * sizeof(GLhalfNV
), /* BlueBits */
272 8 * sizeof(GLhalfNV
), /* AlphaBits */
273 0, /* LuminanceBits */
274 0, /* IntensityBits */
277 4 * sizeof(GLhalfNV
), /* TexelBytes */
278 fetch_null_texel
, /* FetchTexel1D */
279 fetch_null_texel
, /* FetchTexel1D */
280 fetch_null_texel
, /* FetchTexel1D */
281 fetch_texel_1d_f_rgba_f16
, /* FetchTexel1Df */
282 fetch_texel_2d_f_rgba_f16
, /* FetchTexel2Df */
283 fetch_texel_3d_f_rgba_f16
, /* FetchTexel3Df */
286 const struct gl_texture_format _mesa_texformat_rgb_float32
= {
287 MESA_FORMAT_RGB_FLOAT32
, /* MesaFormat */
288 GL_RGB
, /* BaseFormat */
289 8 * sizeof(GLfloat
), /* RedBits */
290 8 * sizeof(GLfloat
), /* GreenBits */
291 8 * sizeof(GLfloat
), /* BlueBits */
293 0, /* LuminanceBits */
294 0, /* IntensityBits */
297 4 * sizeof(GLfloat
), /* TexelBytes */
298 fetch_null_texel
, /* FetchTexel1D */
299 fetch_null_texel
, /* FetchTexel1D */
300 fetch_null_texel
, /* FetchTexel1D */
301 fetch_texel_1d_f_rgb_f32
, /* FetchTexel1Df */
302 fetch_texel_2d_f_rgb_f32
, /* FetchTexel2Df */
303 fetch_texel_3d_f_rgb_f32
, /* FetchTexel3Df */
306 const struct gl_texture_format _mesa_texformat_rgb_float16
= {
307 MESA_FORMAT_RGB_FLOAT16
, /* MesaFormat */
308 GL_RGB
, /* BaseFormat */
309 8 * sizeof(GLhalfNV
), /* RedBits */
310 8 * sizeof(GLhalfNV
), /* GreenBits */
311 8 * sizeof(GLhalfNV
), /* BlueBits */
313 0, /* LuminanceBits */
314 0, /* IntensityBits */
317 4 * sizeof(GLhalfNV
), /* TexelBytes */
318 fetch_null_texel
, /* FetchTexel1D */
319 fetch_null_texel
, /* FetchTexel1D */
320 fetch_null_texel
, /* FetchTexel1D */
321 fetch_texel_1d_f_rgb_f16
, /* FetchTexel1Df */
322 fetch_texel_2d_f_rgb_f16
, /* FetchTexel2Df */
323 fetch_texel_3d_f_rgb_f16
, /* FetchTexel3Df */
330 /***************************************************************/
331 /** \name Hardware formats */
334 const struct gl_texture_format _mesa_texformat_rgba8888
= {
335 MESA_FORMAT_RGBA8888
, /* MesaFormat */
336 GL_RGBA
, /* BaseFormat */
341 0, /* LuminanceBits */
342 0, /* IntensityBits */
346 fetch_texel_1d_rgba8888
, /* FetchTexel1D */
347 fetch_texel_2d_rgba8888
, /* FetchTexel2D */
348 fetch_texel_3d_rgba8888
, /* FetchTexel3D */
349 fetch_texel_1d_f_rgba8888
, /* FetchTexel1Df */
350 fetch_texel_2d_f_rgba8888
, /* FetchTexel2Df */
351 fetch_texel_3d_f_rgba8888
, /* FetchTexel3Df */
354 const struct gl_texture_format _mesa_texformat_argb8888
= {
355 MESA_FORMAT_ARGB8888
, /* MesaFormat */
356 GL_RGBA
, /* BaseFormat */
361 0, /* LuminanceBits */
362 0, /* IntensityBits */
366 fetch_texel_1d_argb8888
, /* FetchTexel1D */
367 fetch_texel_2d_argb8888
, /* FetchTexel2D */
368 fetch_texel_3d_argb8888
, /* FetchTexel3D */
369 fetch_texel_1d_f_argb8888
, /* FetchTexel1Df */
370 fetch_texel_2d_f_argb8888
, /* FetchTexel2Df */
371 fetch_texel_3d_f_argb8888
, /* FetchTexel3Df */
374 const struct gl_texture_format _mesa_texformat_rgb888
= {
375 MESA_FORMAT_RGB888
, /* MesaFormat */
376 GL_RGB
, /* BaseFormat */
381 0, /* LuminanceBits */
382 0, /* IntensityBits */
386 fetch_texel_1d_rgb888
, /* FetchTexel1D */
387 fetch_texel_2d_rgb888
, /* FetchTexel2D */
388 fetch_texel_3d_rgb888
, /* FetchTexel3D */
389 fetch_texel_1d_f_rgb888
, /* FetchTexel1Df */
390 fetch_texel_2d_f_rgb888
, /* FetchTexel2Df */
391 fetch_texel_3d_f_rgb888
, /* FetchTexel3Df */
394 const struct gl_texture_format _mesa_texformat_rgb565
= {
395 MESA_FORMAT_RGB565
, /* MesaFormat */
396 GL_RGB
, /* BaseFormat */
401 0, /* LuminanceBits */
402 0, /* IntensityBits */
406 fetch_texel_1d_rgb565
, /* FetchTexel1D */
407 fetch_texel_2d_rgb565
, /* FetchTexel2D */
408 fetch_texel_3d_rgb565
, /* FetchTexel3D */
409 fetch_texel_1d_f_rgb565
, /* FetchTexel1Df */
410 fetch_texel_2d_f_rgb565
, /* FetchTexel2Df */
411 fetch_texel_3d_f_rgb565
, /* FetchTexel3Df */
414 const struct gl_texture_format _mesa_texformat_argb4444
= {
415 MESA_FORMAT_ARGB4444
, /* MesaFormat */
416 GL_RGBA
, /* BaseFormat */
421 0, /* LuminanceBits */
422 0, /* IntensityBits */
426 fetch_texel_1d_argb4444
, /* FetchTexel1D */
427 fetch_texel_2d_argb4444
, /* FetchTexel2D */
428 fetch_texel_3d_argb4444
, /* FetchTexel3D */
429 fetch_texel_1d_f_argb4444
, /* FetchTexel1Df */
430 fetch_texel_2d_f_argb4444
, /* FetchTexel2Df */
431 fetch_texel_3d_f_argb4444
, /* FetchTexel3Df */
434 const struct gl_texture_format _mesa_texformat_argb1555
= {
435 MESA_FORMAT_ARGB1555
, /* MesaFormat */
436 GL_RGBA
, /* BaseFormat */
441 0, /* LuminanceBits */
442 0, /* IntensityBits */
446 fetch_texel_1d_argb1555
, /* FetchTexel1D */
447 fetch_texel_2d_argb1555
, /* FetchTexel2D */
448 fetch_texel_3d_argb1555
, /* FetchTexel3D */
449 fetch_texel_1d_f_argb1555
, /* FetchTexel1Df */
450 fetch_texel_2d_f_argb1555
, /* FetchTexel2Df */
451 fetch_texel_3d_f_argb1555
, /* FetchTexel3Df */
454 const struct gl_texture_format _mesa_texformat_al88
= {
455 MESA_FORMAT_AL88
, /* MesaFormat */
456 GL_LUMINANCE_ALPHA
, /* BaseFormat */
461 8, /* LuminanceBits */
462 0, /* IntensityBits */
466 fetch_texel_1d_al88
, /* FetchTexel1D */
467 fetch_texel_2d_al88
, /* FetchTexel2D */
468 fetch_texel_3d_al88
, /* FetchTexel3D */
469 fetch_texel_1d_f_al88
, /* FetchTexel1Df */
470 fetch_texel_2d_f_al88
, /* FetchTexel2Df */
471 fetch_texel_3d_f_al88
, /* FetchTexel3Df */
474 const struct gl_texture_format _mesa_texformat_rgb332
= {
475 MESA_FORMAT_RGB332
, /* MesaFormat */
476 GL_RGB
, /* BaseFormat */
481 0, /* LuminanceBits */
482 0, /* IntensityBits */
486 fetch_texel_1d_rgb332
, /* FetchTexel1D */
487 fetch_texel_2d_rgb332
, /* FetchTexel2D */
488 fetch_texel_3d_rgb332
, /* FetchTexel3D */
489 fetch_texel_1d_f_rgb332
, /* FetchTexel1Df */
490 fetch_texel_2d_f_rgb332
, /* FetchTexel2Df */
491 fetch_texel_3d_f_rgb332
, /* FetchTexel3Df */
494 const struct gl_texture_format _mesa_texformat_a8
= {
495 MESA_FORMAT_A8
, /* MesaFormat */
496 GL_ALPHA
, /* BaseFormat */
501 0, /* LuminanceBits */
502 0, /* IntensityBits */
506 fetch_texel_1d_a8
, /* FetchTexel1D */
507 fetch_texel_2d_a8
, /* FetchTexel2D */
508 fetch_texel_3d_a8
, /* FetchTexel3D */
509 fetch_texel_1d_f_a8
, /* FetchTexel1Df */
510 fetch_texel_2d_f_a8
, /* FetchTexel2Df */
511 fetch_texel_3d_f_a8
, /* FetchTexel3Df */
514 const struct gl_texture_format _mesa_texformat_l8
= {
515 MESA_FORMAT_L8
, /* MesaFormat */
516 GL_LUMINANCE
, /* BaseFormat */
521 8, /* LuminanceBits */
522 0, /* IntensityBits */
526 fetch_texel_1d_l8
, /* FetchTexel1D */
527 fetch_texel_2d_l8
, /* FetchTexel2D */
528 fetch_texel_3d_l8
, /* FetchTexel3D */
529 fetch_texel_1d_f_l8
, /* FetchTexel1Df */
530 fetch_texel_2d_f_l8
, /* FetchTexel2Df */
531 fetch_texel_3d_f_l8
, /* FetchTexel3Df */
534 const struct gl_texture_format _mesa_texformat_i8
= {
535 MESA_FORMAT_I8
, /* MesaFormat */
536 GL_INTENSITY
, /* BaseFormat */
541 0, /* LuminanceBits */
542 8, /* IntensityBits */
546 fetch_texel_1d_i8
, /* FetchTexel1D */
547 fetch_texel_2d_i8
, /* FetchTexel2D */
548 fetch_texel_3d_i8
, /* FetchTexel3D */
549 fetch_texel_1d_f_i8
, /* FetchTexel1Df */
550 fetch_texel_2d_f_i8
, /* FetchTexel2Df */
551 fetch_texel_3d_f_i8
, /* FetchTexel3Df */
554 const struct gl_texture_format _mesa_texformat_ci8
= {
555 MESA_FORMAT_CI8
, /* MesaFormat */
556 GL_COLOR_INDEX
, /* BaseFormat */
561 0, /* LuminanceBits */
562 0, /* IntensityBits */
566 fetch_texel_1d_ci8
, /* FetchTexel1D */
567 fetch_texel_2d_ci8
, /* FetchTexel2D */
568 fetch_texel_3d_ci8
, /* FetchTexel3D */
569 fetch_texel_1d_f_ci8
, /* FetchTexel1Df */
570 fetch_texel_2d_f_ci8
, /* FetchTexel2Df */
571 fetch_texel_3d_f_ci8
, /* FetchTexel3Df */
574 const struct gl_texture_format _mesa_texformat_ycbcr
= {
575 MESA_FORMAT_YCBCR
, /* MesaFormat */
576 GL_YCBCR_MESA
, /* BaseFormat */
581 0, /* LuminanceBits */
582 0, /* IntensityBits */
586 fetch_texel_1d_ycbcr
, /* FetchTexel1D */
587 fetch_texel_2d_ycbcr
, /* FetchTexel2D */
588 fetch_texel_3d_ycbcr
, /* FetchTexel3D */
589 fetch_texel_1d_f_ycbcr
, /* FetchTexel1Df */
590 fetch_texel_2d_f_ycbcr
, /* FetchTexel2Df */
591 fetch_texel_3d_f_ycbcr
, /* FetchTexel3Df */
594 const struct gl_texture_format _mesa_texformat_ycbcr_rev
= {
595 MESA_FORMAT_YCBCR_REV
, /* MesaFormat */
596 GL_YCBCR_MESA
, /* BaseFormat */
601 0, /* LuminanceBits */
602 0, /* IntensityBits */
606 fetch_texel_1d_ycbcr_rev
, /* FetchTexel1D */
607 fetch_texel_2d_ycbcr_rev
, /* FetchTexel2D */
608 fetch_texel_3d_ycbcr_rev
, /* FetchTexel3D */
609 fetch_texel_1d_f_ycbcr_rev
, /* FetchTexel1Df */
610 fetch_texel_2d_f_ycbcr_rev
, /* FetchTexel2Df */
611 fetch_texel_3d_f_ycbcr_rev
, /* FetchTexel3Df */
614 const struct gl_texture_format _mesa_texformat_rgb_fxt1
= {
615 MESA_FORMAT_RGB_FXT1
, /* MesaFormat */
616 GL_RGB
, /* BaseFormat */
617 4, /*approx*/ /* RedBits */
618 4, /*approx*/ /* GreenBits */
619 4, /*approx*/ /* BlueBits */
621 0, /* LuminanceBits */
622 0, /* IntensityBits */
626 NULL
, /*impossible*/ /* FetchTexel1D */
627 fetch_texel_2d_rgb_fxt1
, /* FetchTexel2D */
628 NULL
, /*impossible*/ /* FetchTexel3D */
629 NULL
, /*impossible*/ /* FetchTexel1Df */
630 fetch_texel_2d_f_rgb_fxt1
, /* FetchTexel2Df */
631 NULL
, /*impossible*/ /* FetchTexel3Df */
634 const struct gl_texture_format _mesa_texformat_rgba_fxt1
= {
635 MESA_FORMAT_RGBA_FXT1
, /* MesaFormat */
636 GL_RGBA
, /* BaseFormat */
637 4, /*approx*/ /* RedBits */
638 4, /*approx*/ /* GreenBits */
639 4, /*approx*/ /* BlueBits */
640 1, /*approx*/ /* AlphaBits */
641 0, /* LuminanceBits */
642 0, /* IntensityBits */
646 NULL
, /*impossible*/ /* FetchTexel1D */
647 fetch_texel_2d_rgba_fxt1
, /* FetchTexel2D */
648 NULL
, /*impossible*/ /* FetchTexel3D */
649 NULL
, /*impossible*/ /* FetchTexel1Df */
650 fetch_texel_2d_f_rgba_fxt1
, /* FetchTexel2Df */
651 NULL
, /*impossible*/ /* FetchTexel3Df */
654 const struct gl_texture_format _mesa_texformat_rgb_dxt1
= {
655 MESA_FORMAT_RGB_DXT1
, /* MesaFormat */
656 GL_RGB
, /* BaseFormat */
657 4, /*approx*/ /* RedBits */
658 4, /*approx*/ /* GreenBits */
659 4, /*approx*/ /* BlueBits */
661 0, /* LuminanceBits */
662 0, /* IntensityBits */
666 NULL
, /*impossible*/ /* FetchTexel1D */
667 fetch_texel_2d_rgb_dxt1
, /* FetchTexel2D */
668 NULL
, /*impossible*/ /* FetchTexel3D */
669 NULL
, /*impossible*/ /* FetchTexel1Df */
670 fetch_texel_2d_f_rgb_dxt1
, /* FetchTexel2Df */
671 NULL
, /*impossible*/ /* FetchTexel3Df */
674 const struct gl_texture_format _mesa_texformat_rgba_dxt1
= {
675 MESA_FORMAT_RGBA_DXT1
, /* MesaFormat */
676 GL_RGBA
, /* BaseFormat */
677 4, /*approx*/ /* RedBits */
678 4, /*approx*/ /* GreenBits */
679 4, /*approx*/ /* BlueBits */
680 1, /*approx*/ /* AlphaBits */
681 0, /* LuminanceBits */
682 0, /* IntensityBits */
686 NULL
, /*impossible*/ /* FetchTexel1D */
687 fetch_texel_2d_rgba_dxt1
, /* FetchTexel2D */
688 NULL
, /*impossible*/ /* FetchTexel3D */
689 NULL
, /*impossible*/ /* FetchTexel1Df */
690 fetch_texel_2d_f_rgba_dxt1
, /* FetchTexel2Df */
691 NULL
, /*impossible*/ /* FetchTexel3Df */
694 const struct gl_texture_format _mesa_texformat_rgba_dxt3
= {
695 MESA_FORMAT_RGBA_DXT3
, /* MesaFormat */
696 GL_RGBA
, /* BaseFormat */
697 4, /*approx*/ /* RedBits */
698 4, /*approx*/ /* GreenBits */
699 4, /*approx*/ /* BlueBits */
700 4, /*approx*/ /* AlphaBits */
701 0, /* LuminanceBits */
702 0, /* IntensityBits */
706 NULL
, /*impossible*/ /* FetchTexel1D */
707 fetch_texel_2d_rgba_dxt3
, /* FetchTexel2D */
708 NULL
, /*impossible*/ /* FetchTexel3D */
709 NULL
, /*impossible*/ /* FetchTexel1Df */
710 fetch_texel_2d_f_rgba_dxt3
, /* FetchTexel2Df */
711 NULL
, /*impossible*/ /* FetchTexel3Df */
714 const struct gl_texture_format _mesa_texformat_rgba_dxt5
= {
715 MESA_FORMAT_RGBA_DXT5
, /* MesaFormat */
716 GL_RGBA
, /* BaseFormat */
717 4,/*approx*/ /* RedBits */
718 4,/*approx*/ /* GreenBits */
719 4,/*approx*/ /* BlueBits */
720 4,/*approx*/ /* AlphaBits */
721 0, /* LuminanceBits */
722 0, /* IntensityBits */
726 NULL
, /*impossible*/ /* FetchTexel1D */
727 fetch_texel_2d_rgba_dxt5
, /* FetchTexel2D */
728 NULL
, /*impossible*/ /* FetchTexel3D */
729 NULL
, /*impossible*/ /* FetchTexel1Df */
730 fetch_texel_2d_f_rgba_dxt5
, /* FetchTexel2Df */
731 NULL
, /*impossible*/ /* FetchTexel3Df */
737 const struct gl_texture_format _mesa_texformat_abgr8888
= {
738 MESA_FORMAT_ABGR8888
, /* MesaFormat */
739 GL_RGBA
, /* BaseFormat */
740 GL_UNSIGNED_INT_8_8_8_8
, /* Type */
745 0, /* LuminanceBits */
746 0, /* IntensityBits */
750 fetch_texel_1d_abgr8888
, /* FetchTexel1D */
751 fetch_texel_2d_abgr8888
, /* FetchTexel2D */
752 fetch_texel_3d_abgr8888
, /* FetchTexel3D */
753 /* XXX float fetchers */
756 const struct gl_texture_format _mesa_texformat_bgra8888
= {
757 MESA_FORMAT_BGRA8888
, /* MesaFormat */
758 GL_RGBA
, /* BaseFormat */
759 GL_UNSIGNED_INT_8_8_8_8
, /* Type */
764 0, /* LuminanceBits */
765 0, /* IntensityBits */
769 fetch_texel_1d_bgra8888
, /* FetchTexel1D */
770 fetch_texel_2d_bgra8888
, /* FetchTexel2D */
771 fetch_texel_3d_bgra8888
, /* FetchTexel3D */
772 /* XXX float fetchers */
775 const struct gl_texture_format _mesa_texformat_bgr888
= {
776 MESA_FORMAT_BGR888
, /* MesaFormat */
777 GL_RGB
, /* BaseFormat */
778 GL_UNSIGNED_BYTE
, /* Type */
783 0, /* LuminanceBits */
784 0, /* IntensityBits */
788 fetch_texel_1d_bgr888
, /* FetchTexel1D */
789 fetch_texel_2d_bgr888
, /* FetchTexel2D */
790 fetch_texel_3d_bgr888
, /* FetchTexel3D */
791 /* XXX float fetchers */
794 const struct gl_texture_format _mesa_texformat_bgr565
= {
795 MESA_FORMAT_BGR565
, /* MesaFormat */
796 GL_RGB
, /* BaseFormat */
797 GL_UNSIGNED_SHORT_5_6_5
, /* Type */
802 0, /* LuminanceBits */
803 0, /* IntensityBits */
807 fetch_texel_1d_bgr565
, /* FetchTexel1D */
808 fetch_texel_2d_bgr565
, /* FetchTexel2D */
809 fetch_texel_3d_bgr565
, /* FetchTexel3D */
810 /* XXX float fetchers */
813 const struct gl_texture_format _mesa_texformat_bgra4444
= {
814 MESA_FORMAT_BGRA4444
, /* MesaFormat */
815 GL_RGBA
, /* BaseFormat */
816 GL_UNSIGNED_SHORT_4_4_4_4_REV
, /* Type */
821 0, /* LuminanceBits */
822 0, /* IntensityBits */
826 fetch_texel_1d_bgra4444
, /* FetchTexel1D */
827 fetch_texel_2d_bgra4444
, /* FetchTexel2D */
828 fetch_texel_3d_bgra4444
, /* FetchTexel3D */
829 /* XXX float fetchers */
832 const struct gl_texture_format _mesa_texformat_bgra5551
= {
833 MESA_FORMAT_BGRA5551
, /* MesaFormat */
834 GL_RGBA
, /* BaseFormat */
835 GL_UNSIGNED_SHORT_1_5_5_5_REV
, /* Type */
840 0, /* LuminanceBits */
841 0, /* IntensityBits */
845 fetch_texel_1d_bgra1555
, /* FetchTexel1D */
846 fetch_texel_2d_bgra1555
, /* FetchTexel2D */
847 fetch_texel_3d_bgra1555
, /* FetchTexel3D */
848 /* XXX float fetchers */
851 const struct gl_texture_format _mesa_texformat_la88
= {
852 MESA_FORMAT_LA88
, /* MesaFormat */
853 GL_LUMINANCE_ALPHA
, /* BaseFormat */
854 GL_UNSIGNED_BYTE
, /* Type */
859 8, /* LuminanceBits */
860 0, /* IntensityBits */
864 fetch_texel_1d_la88
, /* FetchTexel1D */
865 fetch_texel_2d_la88
, /* FetchTexel2D */
866 fetch_texel_3d_la88
, /* FetchTexel3D */
867 /* XXX float fetchers */
870 const struct gl_texture_format _mesa_texformat_bgr233
= {
871 MESA_FORMAT_BGR233
, /* MesaFormat */
872 GL_RGB
, /* BaseFormat */
873 GL_UNSIGNED_BYTE_3_3_2
, /* Type */
878 0, /* LuminanceBits */
879 0, /* IntensityBits */
883 fetch_texel_1d_bgr233
, /* FetchTexel1D */
884 fetch_texel_2d_bgr233
, /* FetchTexel2D */
885 fetch_texel_3d_bgr233
, /* FetchTexel3D */
886 /* XXX float fetchers */
893 /***************************************************************/
894 /** \name Null format (useful for proxy textures) */
897 const struct gl_texture_format _mesa_null_texformat
= {
904 0, /* LuminanceBits */
905 0, /* IntensityBits */
909 fetch_null_texel
, /* FetchTexel1D */
910 fetch_null_texel
, /* FetchTexel2D */
911 fetch_null_texel
, /* FetchTexel3D */
912 fetch_null_texelf
, /* FetchTexel1Df */
913 fetch_null_texelf
, /* FetchTexel2Df */
914 fetch_null_texelf
, /* FetchTexel3Df */
921 * Determine whether a given texture format is a hardware texture
924 * \param format texture format.
926 * \return GL_TRUE if \p format is a hardware texture format, or GL_FALSE
929 * \p format is a hardware texture format if gl_texture_format::MesaFormat is
930 * lower than _format::MESA_FORMAT_RGBA.
933 _mesa_is_hardware_tex_format( const struct gl_texture_format
*format
)
935 return (format
->MesaFormat
< MESA_FORMAT_RGBA
);
940 * Choose an appropriate texture format given the format, type and
941 * internalFormat parameters passed to glTexImage().
943 * \param ctx the GL context.
944 * \param internalFormat user's prefered internal texture format.
945 * \param format incoming image pixel format.
946 * \param type incoming image data type.
948 * \return a pointer to a gl_texture_format object which describes the
949 * choosen texture format, or NULL on failure.
951 * This is called via dd_function_table::ChooseTextureFormat. Hardware drivers
952 * typically override this function with a specialized version.
954 const struct gl_texture_format
*
955 _mesa_choose_tex_format( GLcontext
*ctx
, GLint internalFormat
,
956 GLenum format
, GLenum type
)
961 switch ( internalFormat
) {
962 /* GH: Bias towards GL_RGB, GL_RGBA texture formats. This has
963 * got to be better than sticking them way down the end of this
966 case 4: /* Quake3 uses this... */
968 return &_mesa_texformat_rgba
;
970 case 3: /* ... and this. */
972 return &_mesa_texformat_rgb
;
974 /* GH: Okay, keep checking as normal. Still test for GL_RGB,
975 * GL_RGBA formats first.
984 return &_mesa_texformat_rgba
;
993 return &_mesa_texformat_rgb
;
1000 return &_mesa_texformat_alpha
;
1006 case GL_LUMINANCE12
:
1007 case GL_LUMINANCE16
:
1008 return &_mesa_texformat_luminance
;
1011 case GL_LUMINANCE_ALPHA
:
1012 case GL_LUMINANCE4_ALPHA4
:
1013 case GL_LUMINANCE6_ALPHA2
:
1014 case GL_LUMINANCE8_ALPHA8
:
1015 case GL_LUMINANCE12_ALPHA4
:
1016 case GL_LUMINANCE12_ALPHA12
:
1017 case GL_LUMINANCE16_ALPHA16
:
1018 return &_mesa_texformat_luminance_alpha
;
1023 case GL_INTENSITY12
:
1024 case GL_INTENSITY16
:
1025 return &_mesa_texformat_intensity
;
1027 case GL_COLOR_INDEX
:
1028 case GL_COLOR_INDEX1_EXT
:
1029 case GL_COLOR_INDEX2_EXT
:
1030 case GL_COLOR_INDEX4_EXT
:
1031 case GL_COLOR_INDEX8_EXT
:
1032 case GL_COLOR_INDEX12_EXT
:
1033 case GL_COLOR_INDEX16_EXT
:
1034 return &_mesa_texformat_color_index
;
1036 case GL_DEPTH_COMPONENT
:
1037 case GL_DEPTH_COMPONENT16_SGIX
:
1038 case GL_DEPTH_COMPONENT24_SGIX
:
1039 case GL_DEPTH_COMPONENT32_SGIX
:
1040 if (!ctx
->Extensions
.SGIX_depth_texture
)
1041 _mesa_problem(ctx
, "depth format without GL_SGIX_depth_texture");
1042 return &_mesa_texformat_depth_component
;
1044 case GL_COMPRESSED_ALPHA_ARB
:
1045 if (!ctx
->Extensions
.ARB_texture_compression
)
1046 _mesa_problem(ctx
, "texture compression extension not enabled");
1047 return &_mesa_texformat_alpha
;
1048 case GL_COMPRESSED_LUMINANCE_ARB
:
1049 if (!ctx
->Extensions
.ARB_texture_compression
)
1050 _mesa_problem(ctx
, "texture compression extension not enabled");
1051 return &_mesa_texformat_luminance
;
1052 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB
:
1053 if (!ctx
->Extensions
.ARB_texture_compression
)
1054 _mesa_problem(ctx
, "texture compression extension not enabled");
1055 return &_mesa_texformat_luminance_alpha
;
1056 case GL_COMPRESSED_INTENSITY_ARB
:
1057 if (!ctx
->Extensions
.ARB_texture_compression
)
1058 _mesa_problem(ctx
, "texture compression extension not enabled");
1059 return &_mesa_texformat_intensity
;
1060 case GL_COMPRESSED_RGB_ARB
:
1061 if (!ctx
->Extensions
.ARB_texture_compression
)
1062 _mesa_problem(ctx
, "texture compression extension not enabled");
1063 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
)
1064 return &_mesa_texformat_rgb_fxt1
;
1065 else if (ctx
->Extensions
.EXT_texture_compression_s3tc
|| ctx
->Extensions
.S3_s3tc
)
1066 return &_mesa_texformat_rgb_dxt1
;
1067 return &_mesa_texformat_rgb
;
1068 case GL_COMPRESSED_RGBA_ARB
:
1069 if (!ctx
->Extensions
.ARB_texture_compression
)
1070 _mesa_problem(ctx
, "texture compression extension not enabled");
1071 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
)
1072 return &_mesa_texformat_rgba_fxt1
;
1073 else if (ctx
->Extensions
.EXT_texture_compression_s3tc
|| ctx
->Extensions
.S3_s3tc
)
1074 return &_mesa_texformat_rgba_dxt3
; /* Not rgba_dxt1! See the spec */
1075 return &_mesa_texformat_rgba
;
1077 /* GL_MESA_ycrcr_texture */
1079 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
)
1080 return &_mesa_texformat_ycbcr
;
1082 return &_mesa_texformat_ycbcr_rev
;
1084 /* GL_3DFX_texture_compression_FXT1 */
1085 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1086 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
)
1087 return &_mesa_texformat_rgb_fxt1
;
1090 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1091 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
)
1092 return &_mesa_texformat_rgba_fxt1
;
1096 /* GL_EXT_texture_compression_s3tc */
1097 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1098 if (ctx
->Extensions
.EXT_texture_compression_s3tc
)
1099 return &_mesa_texformat_rgb_dxt1
;
1102 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1103 if (ctx
->Extensions
.EXT_texture_compression_s3tc
)
1104 return &_mesa_texformat_rgba_dxt1
;
1107 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1108 if (ctx
->Extensions
.EXT_texture_compression_s3tc
)
1109 return &_mesa_texformat_rgba_dxt3
;
1112 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1113 if (ctx
->Extensions
.EXT_texture_compression_s3tc
)
1114 return &_mesa_texformat_rgba_dxt5
;
1121 if (ctx
->Extensions
.S3_s3tc
)
1122 return &_mesa_texformat_rgb_dxt1
;
1127 if (ctx
->Extensions
.S3_s3tc
)
1128 return &_mesa_texformat_rgba_dxt3
;
1132 /* XXX prototype/example code */
1133 /* GL_ATI_texture_float or GL_NV_float_buffer */
1134 case GL_RGBA_FLOAT32_ATI
:
1135 return &_mesa_texformat_rgba_float32
;
1136 case GL_RGBA_FLOAT16_ATI
:
1137 return &_mesa_texformat_rgba_float16
;
1138 case GL_RGB_FLOAT32_ATI
:
1139 return &_mesa_texformat_rgb_float32
;
1140 case GL_RGB_FLOAT16_ATI
:
1141 return &_mesa_texformat_rgb_float16
;
1144 _mesa_problem(ctx
, "unexpected format in _mesa_choose_tex_format()");
1151 * Return the base texture format for the given compressed format
1153 * Called via dd_function_table::Driver.BaseCompressedTexFormat.
1154 * This function is used by software rasterizers. Hardware drivers
1155 * which support texture compression should not use this function but
1156 * a specialized function instead.
1159 _mesa_base_compressed_texformat(GLcontext
*ctx
, GLint intFormat
)
1161 switch (intFormat
) {
1162 case GL_COMPRESSED_ALPHA_ARB
:
1164 case GL_COMPRESSED_LUMINANCE_ARB
:
1165 return GL_LUMINANCE
;
1166 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB
:
1167 return GL_LUMINANCE_ALPHA
;
1168 case GL_COMPRESSED_INTENSITY_ARB
:
1169 return GL_INTENSITY
;
1170 case GL_COMPRESSED_RGB_ARB
:
1172 case GL_COMPRESSED_RGBA_ARB
:
1175 return -1; /* not a recognized compressed format */