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 const struct gl_texture_format _mesa_texformat_depth_component
= {
226 MESA_FORMAT_DEPTH_COMPONENT
, /* MesaFormat */
227 GL_DEPTH_COMPONENT
, /* BaseFormat */
232 0, /* LuminanceBits */
233 0, /* IntensityBits */
235 sizeof(GLfloat
) * 8, /* DepthBits */
236 sizeof(GLfloat
), /* TexelBytes */
237 fetch_null_texel
, /* FetchTexel1D */
238 fetch_null_texel
, /* FetchTexel1D */
239 fetch_null_texel
, /* FetchTexel1D */
240 fetch_texel_1d_f_depth_component
, /* FetchTexel1Df */
241 fetch_texel_2d_f_depth_component
, /* FetchTexel2Df */
242 fetch_texel_3d_f_depth_component
, /* FetchTexel3Df */
248 /***************************************************************/
249 /** \name Hardware formats */
252 const struct gl_texture_format _mesa_texformat_rgba8888
= {
253 MESA_FORMAT_RGBA8888
, /* MesaFormat */
254 GL_RGBA
, /* BaseFormat */
259 0, /* LuminanceBits */
260 0, /* IntensityBits */
264 fetch_texel_1d_rgba8888
, /* FetchTexel1D */
265 fetch_texel_2d_rgba8888
, /* FetchTexel2D */
266 fetch_texel_3d_rgba8888
, /* FetchTexel3D */
267 fetch_texel_1d_f_rgba8888
, /* FetchTexel1Df */
268 fetch_texel_2d_f_rgba8888
, /* FetchTexel2Df */
269 fetch_texel_3d_f_rgba8888
, /* FetchTexel3Df */
272 const struct gl_texture_format _mesa_texformat_argb8888
= {
273 MESA_FORMAT_ARGB8888
, /* MesaFormat */
274 GL_RGBA
, /* BaseFormat */
279 0, /* LuminanceBits */
280 0, /* IntensityBits */
284 fetch_texel_1d_argb8888
, /* FetchTexel1D */
285 fetch_texel_2d_argb8888
, /* FetchTexel2D */
286 fetch_texel_3d_argb8888
, /* FetchTexel3D */
287 fetch_texel_1d_f_argb8888
, /* FetchTexel1Df */
288 fetch_texel_2d_f_argb8888
, /* FetchTexel2Df */
289 fetch_texel_3d_f_argb8888
, /* FetchTexel3Df */
292 const struct gl_texture_format _mesa_texformat_rgb888
= {
293 MESA_FORMAT_RGB888
, /* MesaFormat */
294 GL_RGB
, /* BaseFormat */
299 0, /* LuminanceBits */
300 0, /* IntensityBits */
304 fetch_texel_1d_rgb888
, /* FetchTexel1D */
305 fetch_texel_2d_rgb888
, /* FetchTexel2D */
306 fetch_texel_3d_rgb888
, /* FetchTexel3D */
307 fetch_texel_1d_f_rgb888
, /* FetchTexel1Df */
308 fetch_texel_2d_f_rgb888
, /* FetchTexel2Df */
309 fetch_texel_3d_f_rgb888
, /* FetchTexel3Df */
312 const struct gl_texture_format _mesa_texformat_rgb565
= {
313 MESA_FORMAT_RGB565
, /* MesaFormat */
314 GL_RGB
, /* BaseFormat */
319 0, /* LuminanceBits */
320 0, /* IntensityBits */
324 fetch_texel_1d_rgb565
, /* FetchTexel1D */
325 fetch_texel_2d_rgb565
, /* FetchTexel2D */
326 fetch_texel_3d_rgb565
, /* FetchTexel3D */
327 fetch_texel_1d_f_rgb565
, /* FetchTexel1Df */
328 fetch_texel_2d_f_rgb565
, /* FetchTexel2Df */
329 fetch_texel_3d_f_rgb565
, /* FetchTexel3Df */
332 const struct gl_texture_format _mesa_texformat_argb4444
= {
333 MESA_FORMAT_ARGB4444
, /* MesaFormat */
334 GL_RGBA
, /* BaseFormat */
339 0, /* LuminanceBits */
340 0, /* IntensityBits */
344 fetch_texel_1d_argb4444
, /* FetchTexel1D */
345 fetch_texel_2d_argb4444
, /* FetchTexel2D */
346 fetch_texel_3d_argb4444
, /* FetchTexel3D */
347 fetch_texel_1d_f_argb4444
, /* FetchTexel1Df */
348 fetch_texel_2d_f_argb4444
, /* FetchTexel2Df */
349 fetch_texel_3d_f_argb4444
, /* FetchTexel3Df */
352 const struct gl_texture_format _mesa_texformat_argb1555
= {
353 MESA_FORMAT_ARGB1555
, /* MesaFormat */
354 GL_RGBA
, /* BaseFormat */
359 0, /* LuminanceBits */
360 0, /* IntensityBits */
364 fetch_texel_1d_argb1555
, /* FetchTexel1D */
365 fetch_texel_2d_argb1555
, /* FetchTexel2D */
366 fetch_texel_3d_argb1555
, /* FetchTexel3D */
367 fetch_texel_1d_f_argb1555
, /* FetchTexel1Df */
368 fetch_texel_2d_f_argb1555
, /* FetchTexel2Df */
369 fetch_texel_3d_f_argb1555
, /* FetchTexel3Df */
372 const struct gl_texture_format _mesa_texformat_al88
= {
373 MESA_FORMAT_AL88
, /* MesaFormat */
374 GL_LUMINANCE_ALPHA
, /* BaseFormat */
379 8, /* LuminanceBits */
380 0, /* IntensityBits */
384 fetch_texel_1d_al88
, /* FetchTexel1D */
385 fetch_texel_2d_al88
, /* FetchTexel2D */
386 fetch_texel_3d_al88
, /* FetchTexel3D */
387 fetch_texel_1d_f_al88
, /* FetchTexel1Df */
388 fetch_texel_2d_f_al88
, /* FetchTexel2Df */
389 fetch_texel_3d_f_al88
, /* FetchTexel3Df */
392 const struct gl_texture_format _mesa_texformat_rgb332
= {
393 MESA_FORMAT_RGB332
, /* MesaFormat */
394 GL_RGB
, /* BaseFormat */
399 0, /* LuminanceBits */
400 0, /* IntensityBits */
404 fetch_texel_1d_rgb332
, /* FetchTexel1D */
405 fetch_texel_2d_rgb332
, /* FetchTexel2D */
406 fetch_texel_3d_rgb332
, /* FetchTexel3D */
407 fetch_texel_1d_f_rgb332
, /* FetchTexel1Df */
408 fetch_texel_2d_f_rgb332
, /* FetchTexel2Df */
409 fetch_texel_3d_f_rgb332
, /* FetchTexel3Df */
412 const struct gl_texture_format _mesa_texformat_a8
= {
413 MESA_FORMAT_A8
, /* MesaFormat */
414 GL_ALPHA
, /* BaseFormat */
419 0, /* LuminanceBits */
420 0, /* IntensityBits */
424 fetch_texel_1d_a8
, /* FetchTexel1D */
425 fetch_texel_2d_a8
, /* FetchTexel2D */
426 fetch_texel_3d_a8
, /* FetchTexel3D */
427 fetch_texel_1d_f_a8
, /* FetchTexel1Df */
428 fetch_texel_2d_f_a8
, /* FetchTexel2Df */
429 fetch_texel_3d_f_a8
, /* FetchTexel3Df */
432 const struct gl_texture_format _mesa_texformat_l8
= {
433 MESA_FORMAT_L8
, /* MesaFormat */
434 GL_LUMINANCE
, /* BaseFormat */
439 8, /* LuminanceBits */
440 0, /* IntensityBits */
444 fetch_texel_1d_l8
, /* FetchTexel1D */
445 fetch_texel_2d_l8
, /* FetchTexel2D */
446 fetch_texel_3d_l8
, /* FetchTexel3D */
447 fetch_texel_1d_f_l8
, /* FetchTexel1Df */
448 fetch_texel_2d_f_l8
, /* FetchTexel2Df */
449 fetch_texel_3d_f_l8
, /* FetchTexel3Df */
452 const struct gl_texture_format _mesa_texformat_i8
= {
453 MESA_FORMAT_I8
, /* MesaFormat */
454 GL_INTENSITY
, /* BaseFormat */
459 0, /* LuminanceBits */
460 8, /* IntensityBits */
464 fetch_texel_1d_i8
, /* FetchTexel1D */
465 fetch_texel_2d_i8
, /* FetchTexel2D */
466 fetch_texel_3d_i8
, /* FetchTexel3D */
467 fetch_texel_1d_f_i8
, /* FetchTexel1Df */
468 fetch_texel_2d_f_i8
, /* FetchTexel2Df */
469 fetch_texel_3d_f_i8
, /* FetchTexel3Df */
472 const struct gl_texture_format _mesa_texformat_ci8
= {
473 MESA_FORMAT_CI8
, /* MesaFormat */
474 GL_COLOR_INDEX
, /* BaseFormat */
479 0, /* LuminanceBits */
480 0, /* IntensityBits */
484 fetch_texel_1d_ci8
, /* FetchTexel1D */
485 fetch_texel_2d_ci8
, /* FetchTexel2D */
486 fetch_texel_3d_ci8
, /* FetchTexel3D */
487 fetch_texel_1d_f_ci8
, /* FetchTexel1Df */
488 fetch_texel_2d_f_ci8
, /* FetchTexel2Df */
489 fetch_texel_3d_f_ci8
, /* FetchTexel3Df */
492 const struct gl_texture_format _mesa_texformat_ycbcr
= {
493 MESA_FORMAT_YCBCR
, /* MesaFormat */
494 GL_YCBCR_MESA
, /* BaseFormat */
499 0, /* LuminanceBits */
500 0, /* IntensityBits */
504 fetch_texel_1d_ycbcr
, /* FetchTexel1D */
505 fetch_texel_2d_ycbcr
, /* FetchTexel2D */
506 fetch_texel_3d_ycbcr
, /* FetchTexel3D */
507 fetch_texel_1d_f_ycbcr
, /* FetchTexel1Df */
508 fetch_texel_2d_f_ycbcr
, /* FetchTexel2Df */
509 fetch_texel_3d_f_ycbcr
, /* FetchTexel3Df */
512 const struct gl_texture_format _mesa_texformat_ycbcr_rev
= {
513 MESA_FORMAT_YCBCR_REV
, /* MesaFormat */
514 GL_YCBCR_MESA
, /* BaseFormat */
519 0, /* LuminanceBits */
520 0, /* IntensityBits */
524 fetch_texel_1d_ycbcr_rev
, /* FetchTexel1D */
525 fetch_texel_2d_ycbcr_rev
, /* FetchTexel2D */
526 fetch_texel_3d_ycbcr_rev
, /* FetchTexel3D */
527 fetch_texel_1d_f_ycbcr_rev
, /* FetchTexel1Df */
528 fetch_texel_2d_f_ycbcr_rev
, /* FetchTexel2Df */
529 fetch_texel_3d_f_ycbcr_rev
, /* FetchTexel3Df */
532 const struct gl_texture_format _mesa_texformat_rgb_fxt1
= {
533 MESA_FORMAT_RGB_FXT1
, /* MesaFormat */
534 GL_RGB
, /* BaseFormat */
535 4, /*approx*/ /* RedBits */
536 4, /*approx*/ /* GreenBits */
537 4, /*approx*/ /* BlueBits */
539 0, /* LuminanceBits */
540 0, /* IntensityBits */
544 NULL
, /*impossible*/ /* FetchTexel1D */
545 fetch_texel_2d_rgb_fxt1
, /* FetchTexel2D */
546 NULL
, /*impossible*/ /* FetchTexel3D */
547 NULL
, /*impossible*/ /* FetchTexel1Df */
548 fetch_texel_2d_f_rgb_fxt1
, /* FetchTexel2Df */
549 NULL
, /*impossible*/ /* FetchTexel3Df */
552 const struct gl_texture_format _mesa_texformat_rgba_fxt1
= {
553 MESA_FORMAT_RGBA_FXT1
, /* MesaFormat */
554 GL_RGBA
, /* BaseFormat */
555 4, /*approx*/ /* RedBits */
556 4, /*approx*/ /* GreenBits */
557 4, /*approx*/ /* BlueBits */
558 1, /*approx*/ /* AlphaBits */
559 0, /* LuminanceBits */
560 0, /* IntensityBits */
564 NULL
, /*impossible*/ /* FetchTexel1D */
565 fetch_texel_2d_rgba_fxt1
, /* FetchTexel2D */
566 NULL
, /*impossible*/ /* FetchTexel3D */
567 NULL
, /*impossible*/ /* FetchTexel1Df */
568 fetch_texel_2d_f_rgba_fxt1
, /* FetchTexel2Df */
569 NULL
, /*impossible*/ /* FetchTexel3Df */
572 const struct gl_texture_format _mesa_texformat_rgb_dxt1
= {
573 MESA_FORMAT_RGB_DXT1
, /* MesaFormat */
574 GL_RGB
, /* BaseFormat */
575 4, /*approx*/ /* RedBits */
576 4, /*approx*/ /* GreenBits */
577 4, /*approx*/ /* BlueBits */
579 0, /* LuminanceBits */
580 0, /* IntensityBits */
584 NULL
, /*impossible*/ /* FetchTexel1D */
585 fetch_texel_2d_rgb_dxt1
, /* FetchTexel2D */
586 NULL
, /*impossible*/ /* FetchTexel3D */
587 NULL
, /*impossible*/ /* FetchTexel1Df */
588 fetch_texel_2d_f_rgb_dxt1
, /* FetchTexel2Df */
589 NULL
, /*impossible*/ /* FetchTexel3Df */
592 const struct gl_texture_format _mesa_texformat_rgba_dxt1
= {
593 MESA_FORMAT_RGBA_DXT1
, /* MesaFormat */
594 GL_RGBA
, /* BaseFormat */
595 4, /*approx*/ /* RedBits */
596 4, /*approx*/ /* GreenBits */
597 4, /*approx*/ /* BlueBits */
598 1, /*approx*/ /* AlphaBits */
599 0, /* LuminanceBits */
600 0, /* IntensityBits */
604 NULL
, /*impossible*/ /* FetchTexel1D */
605 fetch_texel_2d_rgba_dxt1
, /* FetchTexel2D */
606 NULL
, /*impossible*/ /* FetchTexel3D */
607 NULL
, /*impossible*/ /* FetchTexel1Df */
608 fetch_texel_2d_f_rgba_dxt1
, /* FetchTexel2Df */
609 NULL
, /*impossible*/ /* FetchTexel3Df */
612 const struct gl_texture_format _mesa_texformat_rgba_dxt3
= {
613 MESA_FORMAT_RGBA_DXT3
, /* MesaFormat */
614 GL_RGBA
, /* BaseFormat */
615 4, /*approx*/ /* RedBits */
616 4, /*approx*/ /* GreenBits */
617 4, /*approx*/ /* BlueBits */
618 4, /*approx*/ /* AlphaBits */
619 0, /* LuminanceBits */
620 0, /* IntensityBits */
624 NULL
, /*impossible*/ /* FetchTexel1D */
625 fetch_texel_2d_rgba_dxt3
, /* FetchTexel2D */
626 NULL
, /*impossible*/ /* FetchTexel3D */
627 NULL
, /*impossible*/ /* FetchTexel1Df */
628 fetch_texel_2d_f_rgba_dxt3
, /* FetchTexel2Df */
629 NULL
, /*impossible*/ /* FetchTexel3Df */
632 const struct gl_texture_format _mesa_texformat_rgba_dxt5
= {
633 MESA_FORMAT_RGBA_DXT5
, /* MesaFormat */
634 GL_RGBA
, /* BaseFormat */
635 4,/*approx*/ /* RedBits */
636 4,/*approx*/ /* GreenBits */
637 4,/*approx*/ /* BlueBits */
638 4,/*approx*/ /* AlphaBits */
639 0, /* LuminanceBits */
640 0, /* IntensityBits */
644 NULL
, /*impossible*/ /* FetchTexel1D */
645 fetch_texel_2d_rgba_dxt5
, /* FetchTexel2D */
646 NULL
, /*impossible*/ /* FetchTexel3D */
647 NULL
, /*impossible*/ /* FetchTexel1Df */
648 fetch_texel_2d_f_rgba_dxt5
, /* FetchTexel2Df */
649 NULL
, /*impossible*/ /* FetchTexel3Df */
655 const struct gl_texture_format _mesa_texformat_abgr8888
= {
656 MESA_FORMAT_ABGR8888
, /* MesaFormat */
657 GL_RGBA
, /* BaseFormat */
658 GL_UNSIGNED_INT_8_8_8_8
, /* Type */
663 0, /* LuminanceBits */
664 0, /* IntensityBits */
668 fetch_texel_1d_abgr8888
, /* FetchTexel1D */
669 fetch_texel_2d_abgr8888
, /* FetchTexel2D */
670 fetch_texel_3d_abgr8888
, /* FetchTexel3D */
671 /* XXX float fetchers */
674 const struct gl_texture_format _mesa_texformat_bgra8888
= {
675 MESA_FORMAT_BGRA8888
, /* MesaFormat */
676 GL_RGBA
, /* BaseFormat */
677 GL_UNSIGNED_INT_8_8_8_8
, /* Type */
682 0, /* LuminanceBits */
683 0, /* IntensityBits */
687 fetch_texel_1d_bgra8888
, /* FetchTexel1D */
688 fetch_texel_2d_bgra8888
, /* FetchTexel2D */
689 fetch_texel_3d_bgra8888
, /* FetchTexel3D */
690 /* XXX float fetchers */
693 const struct gl_texture_format _mesa_texformat_bgr888
= {
694 MESA_FORMAT_BGR888
, /* MesaFormat */
695 GL_RGB
, /* BaseFormat */
696 GL_UNSIGNED_BYTE
, /* Type */
701 0, /* LuminanceBits */
702 0, /* IntensityBits */
706 fetch_texel_1d_bgr888
, /* FetchTexel1D */
707 fetch_texel_2d_bgr888
, /* FetchTexel2D */
708 fetch_texel_3d_bgr888
, /* FetchTexel3D */
709 /* XXX float fetchers */
712 const struct gl_texture_format _mesa_texformat_bgr565
= {
713 MESA_FORMAT_BGR565
, /* MesaFormat */
714 GL_RGB
, /* BaseFormat */
715 GL_UNSIGNED_SHORT_5_6_5
, /* Type */
720 0, /* LuminanceBits */
721 0, /* IntensityBits */
725 fetch_texel_1d_bgr565
, /* FetchTexel1D */
726 fetch_texel_2d_bgr565
, /* FetchTexel2D */
727 fetch_texel_3d_bgr565
, /* FetchTexel3D */
728 /* XXX float fetchers */
731 const struct gl_texture_format _mesa_texformat_bgra4444
= {
732 MESA_FORMAT_BGRA4444
, /* MesaFormat */
733 GL_RGBA
, /* BaseFormat */
734 GL_UNSIGNED_SHORT_4_4_4_4_REV
, /* Type */
739 0, /* LuminanceBits */
740 0, /* IntensityBits */
744 fetch_texel_1d_bgra4444
, /* FetchTexel1D */
745 fetch_texel_2d_bgra4444
, /* FetchTexel2D */
746 fetch_texel_3d_bgra4444
, /* FetchTexel3D */
747 /* XXX float fetchers */
750 const struct gl_texture_format _mesa_texformat_bgra5551
= {
751 MESA_FORMAT_BGRA5551
, /* MesaFormat */
752 GL_RGBA
, /* BaseFormat */
753 GL_UNSIGNED_SHORT_1_5_5_5_REV
, /* Type */
758 0, /* LuminanceBits */
759 0, /* IntensityBits */
763 fetch_texel_1d_bgra1555
, /* FetchTexel1D */
764 fetch_texel_2d_bgra1555
, /* FetchTexel2D */
765 fetch_texel_3d_bgra1555
, /* FetchTexel3D */
766 /* XXX float fetchers */
769 const struct gl_texture_format _mesa_texformat_la88
= {
770 MESA_FORMAT_LA88
, /* MesaFormat */
771 GL_LUMINANCE_ALPHA
, /* BaseFormat */
772 GL_UNSIGNED_BYTE
, /* Type */
777 8, /* LuminanceBits */
778 0, /* IntensityBits */
782 fetch_texel_1d_la88
, /* FetchTexel1D */
783 fetch_texel_2d_la88
, /* FetchTexel2D */
784 fetch_texel_3d_la88
, /* FetchTexel3D */
785 /* XXX float fetchers */
788 const struct gl_texture_format _mesa_texformat_bgr233
= {
789 MESA_FORMAT_BGR233
, /* MesaFormat */
790 GL_RGB
, /* BaseFormat */
791 GL_UNSIGNED_BYTE_3_3_2
, /* Type */
796 0, /* LuminanceBits */
797 0, /* IntensityBits */
801 fetch_texel_1d_bgr233
, /* FetchTexel1D */
802 fetch_texel_2d_bgr233
, /* FetchTexel2D */
803 fetch_texel_3d_bgr233
, /* FetchTexel3D */
804 /* XXX float fetchers */
811 /***************************************************************/
812 /** \name Null format (useful for proxy textures) */
815 const struct gl_texture_format _mesa_null_texformat
= {
822 0, /* LuminanceBits */
823 0, /* IntensityBits */
827 fetch_null_texel
, /* FetchTexel1D */
828 fetch_null_texel
, /* FetchTexel2D */
829 fetch_null_texel
, /* FetchTexel3D */
830 fetch_null_texelf
, /* FetchTexel1Df */
831 fetch_null_texelf
, /* FetchTexel2Df */
832 fetch_null_texelf
, /* FetchTexel3Df */
839 * Determine whether a given texture format is a hardware texture
842 * \param format texture format.
844 * \return GL_TRUE if \p format is a hardware texture format, or GL_FALSE
847 * \p format is a hardware texture format if gl_texture_format::MesaFormat is
848 * lower than _format::MESA_FORMAT_RGBA.
851 _mesa_is_hardware_tex_format( const struct gl_texture_format
*format
)
853 return (format
->MesaFormat
< MESA_FORMAT_RGBA
);
858 * Choose an appropriate texture format.
860 * \param ctx GL context.
861 * \param internalFormat internal texture format.
862 * \param format pixel format.
863 * \param type data type.
865 * \return a pointer to a gl_texture_format in which to store the texture on
866 * success, or NULL on failure.
868 * This is called via dd_function_table::ChooseTextureFormat. Hardware drivers
869 * typically override this function with a specialized version.
871 const struct gl_texture_format
*
872 _mesa_choose_tex_format( GLcontext
*ctx
, GLint internalFormat
,
873 GLenum format
, GLenum type
)
878 switch ( internalFormat
) {
879 /* GH: Bias towards GL_RGB, GL_RGBA texture formats. This has
880 * got to be better than sticking them way down the end of this
883 case 4: /* Quake3 uses this... */
885 return &_mesa_texformat_rgba
;
887 case 3: /* ... and this. */
889 return &_mesa_texformat_rgb
;
891 /* GH: Okay, keep checking as normal. Still test for GL_RGB,
892 * GL_RGBA formats first.
901 return &_mesa_texformat_rgba
;
910 return &_mesa_texformat_rgb
;
917 return &_mesa_texformat_alpha
;
925 return &_mesa_texformat_luminance
;
928 case GL_LUMINANCE_ALPHA
:
929 case GL_LUMINANCE4_ALPHA4
:
930 case GL_LUMINANCE6_ALPHA2
:
931 case GL_LUMINANCE8_ALPHA8
:
932 case GL_LUMINANCE12_ALPHA4
:
933 case GL_LUMINANCE12_ALPHA12
:
934 case GL_LUMINANCE16_ALPHA16
:
935 return &_mesa_texformat_luminance_alpha
;
942 return &_mesa_texformat_intensity
;
945 case GL_COLOR_INDEX1_EXT
:
946 case GL_COLOR_INDEX2_EXT
:
947 case GL_COLOR_INDEX4_EXT
:
948 case GL_COLOR_INDEX8_EXT
:
949 case GL_COLOR_INDEX12_EXT
:
950 case GL_COLOR_INDEX16_EXT
:
951 return &_mesa_texformat_color_index
;
953 case GL_DEPTH_COMPONENT
:
954 case GL_DEPTH_COMPONENT16_SGIX
:
955 case GL_DEPTH_COMPONENT24_SGIX
:
956 case GL_DEPTH_COMPONENT32_SGIX
:
957 if (!ctx
->Extensions
.SGIX_depth_texture
)
958 _mesa_problem(ctx
, "depth format without GL_SGIX_depth_texture");
959 return &_mesa_texformat_depth_component
;
961 case GL_COMPRESSED_ALPHA_ARB
:
962 if (!ctx
->Extensions
.ARB_texture_compression
)
963 _mesa_problem(ctx
, "texture compression extension not enabled");
964 return &_mesa_texformat_alpha
;
965 case GL_COMPRESSED_LUMINANCE_ARB
:
966 if (!ctx
->Extensions
.ARB_texture_compression
)
967 _mesa_problem(ctx
, "texture compression extension not enabled");
968 return &_mesa_texformat_luminance
;
969 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB
:
970 if (!ctx
->Extensions
.ARB_texture_compression
)
971 _mesa_problem(ctx
, "texture compression extension not enabled");
972 return &_mesa_texformat_luminance_alpha
;
973 case GL_COMPRESSED_INTENSITY_ARB
:
974 if (!ctx
->Extensions
.ARB_texture_compression
)
975 _mesa_problem(ctx
, "texture compression extension not enabled");
976 return &_mesa_texformat_intensity
;
977 case GL_COMPRESSED_RGB_ARB
:
978 if (!ctx
->Extensions
.ARB_texture_compression
)
979 _mesa_problem(ctx
, "texture compression extension not enabled");
980 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
)
981 return &_mesa_texformat_rgb_fxt1
;
982 else if (ctx
->Extensions
.EXT_texture_compression_s3tc
|| ctx
->Extensions
.S3_s3tc
)
983 return &_mesa_texformat_rgb_dxt1
;
984 return &_mesa_texformat_rgb
;
985 case GL_COMPRESSED_RGBA_ARB
:
986 if (!ctx
->Extensions
.ARB_texture_compression
)
987 _mesa_problem(ctx
, "texture compression extension not enabled");
988 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
)
989 return &_mesa_texformat_rgba_fxt1
;
990 else if (ctx
->Extensions
.EXT_texture_compression_s3tc
|| ctx
->Extensions
.S3_s3tc
)
991 return &_mesa_texformat_rgba_dxt3
; /* Not rgba_dxt1! See the spec */
992 return &_mesa_texformat_rgba
;
994 /* GL_MESA_ycrcr_texture */
996 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
)
997 return &_mesa_texformat_ycbcr
;
999 return &_mesa_texformat_ycbcr_rev
;
1001 /* GL_3DFX_texture_compression_FXT1 */
1002 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1003 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
)
1004 return &_mesa_texformat_rgb_fxt1
;
1007 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1008 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
)
1009 return &_mesa_texformat_rgba_fxt1
;
1013 /* GL_EXT_texture_compression_s3tc */
1014 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1015 if (ctx
->Extensions
.EXT_texture_compression_s3tc
)
1016 return &_mesa_texformat_rgb_dxt1
;
1019 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1020 if (ctx
->Extensions
.EXT_texture_compression_s3tc
)
1021 return &_mesa_texformat_rgba_dxt1
;
1024 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1025 if (ctx
->Extensions
.EXT_texture_compression_s3tc
)
1026 return &_mesa_texformat_rgba_dxt3
;
1029 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1030 if (ctx
->Extensions
.EXT_texture_compression_s3tc
)
1031 return &_mesa_texformat_rgba_dxt5
;
1038 if (ctx
->Extensions
.S3_s3tc
)
1039 return &_mesa_texformat_rgb_dxt1
;
1044 if (ctx
->Extensions
.S3_s3tc
)
1045 return &_mesa_texformat_rgba_dxt3
;
1050 _mesa_problem(ctx
, "unexpected format in _mesa_choose_tex_format()");
1057 * Return the base texture format for the given compressed format
1059 * Called via dd_function_table::Driver.BaseCompressedTexFormat.
1060 * This function is used by software rasterizers. Hardware drivers
1061 * which support texture compression should not use this function but
1062 * a specialized function instead.
1065 _mesa_base_compressed_texformat(GLcontext
*ctx
, GLint intFormat
)
1067 switch (intFormat
) {
1068 case GL_COMPRESSED_ALPHA_ARB
:
1070 case GL_COMPRESSED_LUMINANCE_ARB
:
1071 return GL_LUMINANCE
;
1072 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB
:
1073 return GL_LUMINANCE_ALPHA
;
1074 case GL_COMPRESSED_INTENSITY_ARB
:
1075 return GL_INTENSITY
;
1076 case GL_COMPRESSED_RGB_ARB
:
1078 case GL_COMPRESSED_RGBA_ARB
:
1081 return -1; /* not a recognized compressed format */