2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2009 VMware, Inc.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
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.
30 * Texel fetch/store functions
32 * \author Gareth Hughes
38 #include "texcompress.h"
39 #include "texcompress_fxt1.h"
40 #include "texcompress_s3tc.h"
41 #include "texcompress_rgtc.h"
48 * Convert an 8-bit sRGB value from non-linear space to a
49 * linear RGB value in [0, 1].
50 * Implemented with a 256-entry lookup table.
53 nonlinear_to_linear(GLubyte cs8
)
55 static GLfloat table
[256];
56 static GLboolean tableReady
= GL_FALSE
;
58 /* compute lookup table now */
60 for (i
= 0; i
< 256; i
++) {
61 const GLfloat cs
= UBYTE_TO_FLOAT(i
);
63 table
[i
] = cs
/ 12.92f
;
66 table
[i
] = (GLfloat
) pow((cs
+ 0.055) / 1.055, 2.4);
76 /* Texel fetch routines for all supported formats
79 #include "texfetch_tmp.h"
82 #include "texfetch_tmp.h"
85 #include "texfetch_tmp.h"
88 * Null texel fetch function.
90 * Have to have this so the FetchTexel function pointer is never NULL.
92 static void fetch_null_texelf( const struct gl_texture_image
*texImage
,
93 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
95 (void) texImage
; (void) i
; (void) j
; (void) k
;
100 _mesa_warning(NULL
, "fetch_null_texelf() called!");
103 static void store_null_texel(struct gl_texture_image
*texImage
,
104 GLint i
, GLint j
, GLint k
, const void *texel
)
117 * Table to map MESA_FORMAT_ to texel fetch/store funcs.
118 * XXX this is somewhat temporary.
122 FetchTexelFuncF Fetch1D
;
123 FetchTexelFuncF Fetch2D
;
124 FetchTexelFuncF Fetch3D
;
125 StoreTexelFunc StoreTexel
;
127 texfetch_funcs
[MESA_FORMAT_COUNT
] =
138 MESA_FORMAT_RGBA8888
,
139 fetch_texel_1d_f_rgba8888
,
140 fetch_texel_2d_f_rgba8888
,
141 fetch_texel_3d_f_rgba8888
,
145 MESA_FORMAT_RGBA8888_REV
,
146 fetch_texel_1d_f_rgba8888_rev
,
147 fetch_texel_2d_f_rgba8888_rev
,
148 fetch_texel_3d_f_rgba8888_rev
,
149 store_texel_rgba8888_rev
152 MESA_FORMAT_ARGB8888
,
153 fetch_texel_1d_f_argb8888
,
154 fetch_texel_2d_f_argb8888
,
155 fetch_texel_3d_f_argb8888
,
159 MESA_FORMAT_ARGB8888_REV
,
160 fetch_texel_1d_f_argb8888_rev
,
161 fetch_texel_2d_f_argb8888_rev
,
162 fetch_texel_3d_f_argb8888_rev
,
163 store_texel_argb8888_rev
166 MESA_FORMAT_XRGB8888
,
167 fetch_texel_1d_f_xrgb8888
,
168 fetch_texel_2d_f_xrgb8888
,
169 fetch_texel_3d_f_xrgb8888
,
173 MESA_FORMAT_XRGB8888_REV
,
174 fetch_texel_1d_f_xrgb8888_rev
,
175 fetch_texel_2d_f_xrgb8888_rev
,
176 fetch_texel_3d_f_xrgb8888_rev
,
177 store_texel_xrgb8888_rev
,
181 fetch_texel_1d_f_rgb888
,
182 fetch_texel_2d_f_rgb888
,
183 fetch_texel_3d_f_rgb888
,
188 fetch_texel_1d_f_bgr888
,
189 fetch_texel_2d_f_bgr888
,
190 fetch_texel_3d_f_bgr888
,
195 fetch_texel_1d_f_rgb565
,
196 fetch_texel_2d_f_rgb565
,
197 fetch_texel_3d_f_rgb565
,
201 MESA_FORMAT_RGB565_REV
,
202 fetch_texel_1d_f_rgb565_rev
,
203 fetch_texel_2d_f_rgb565_rev
,
204 fetch_texel_3d_f_rgb565_rev
,
205 store_texel_rgb565_rev
208 MESA_FORMAT_ARGB4444
,
209 fetch_texel_1d_f_argb4444
,
210 fetch_texel_2d_f_argb4444
,
211 fetch_texel_3d_f_argb4444
,
215 MESA_FORMAT_ARGB4444_REV
,
216 fetch_texel_1d_f_argb4444_rev
,
217 fetch_texel_2d_f_argb4444_rev
,
218 fetch_texel_3d_f_argb4444_rev
,
219 store_texel_argb4444_rev
222 MESA_FORMAT_RGBA5551
,
223 fetch_texel_1d_f_rgba5551
,
224 fetch_texel_2d_f_rgba5551
,
225 fetch_texel_3d_f_rgba5551
,
229 MESA_FORMAT_ARGB1555
,
230 fetch_texel_1d_f_argb1555
,
231 fetch_texel_2d_f_argb1555
,
232 fetch_texel_3d_f_argb1555
,
236 MESA_FORMAT_ARGB1555_REV
,
237 fetch_texel_1d_f_argb1555_rev
,
238 fetch_texel_2d_f_argb1555_rev
,
239 fetch_texel_3d_f_argb1555_rev
,
240 store_texel_argb1555_rev
244 fetch_texel_1d_f_al44
,
245 fetch_texel_2d_f_al44
,
246 fetch_texel_3d_f_al44
,
251 fetch_texel_1d_f_al88
,
252 fetch_texel_2d_f_al88
,
253 fetch_texel_3d_f_al88
,
257 MESA_FORMAT_AL88_REV
,
258 fetch_texel_1d_f_al88_rev
,
259 fetch_texel_2d_f_al88_rev
,
260 fetch_texel_3d_f_al88_rev
,
265 fetch_texel_1d_f_al1616
,
266 fetch_texel_2d_f_al1616
,
267 fetch_texel_3d_f_al1616
,
271 MESA_FORMAT_AL1616_REV
,
272 fetch_texel_1d_f_al1616_rev
,
273 fetch_texel_2d_f_al1616_rev
,
274 fetch_texel_3d_f_al1616_rev
,
275 store_texel_al1616_rev
279 fetch_texel_1d_f_rgb332
,
280 fetch_texel_2d_f_rgb332
,
281 fetch_texel_3d_f_rgb332
,
293 fetch_texel_1d_f_a16
,
294 fetch_texel_2d_f_a16
,
295 fetch_texel_3d_f_a16
,
307 fetch_texel_1d_f_l16
,
308 fetch_texel_2d_f_l16
,
309 fetch_texel_3d_f_l16
,
321 fetch_texel_1d_f_i16
,
322 fetch_texel_2d_f_i16
,
323 fetch_texel_3d_f_i16
,
328 fetch_texel_1d_f_ci8
,
329 fetch_texel_2d_f_ci8
,
330 fetch_texel_3d_f_ci8
,
335 fetch_texel_1d_f_ycbcr
,
336 fetch_texel_2d_f_ycbcr
,
337 fetch_texel_3d_f_ycbcr
,
341 MESA_FORMAT_YCBCR_REV
,
342 fetch_texel_1d_f_ycbcr_rev
,
343 fetch_texel_2d_f_ycbcr_rev
,
344 fetch_texel_3d_f_ycbcr_rev
,
345 store_texel_ycbcr_rev
356 fetch_texel_1d_f_rg88
,
357 fetch_texel_2d_f_rg88
,
358 fetch_texel_3d_f_rg88
,
362 MESA_FORMAT_RG88_REV
,
363 fetch_texel_1d_f_rg88_rev
,
364 fetch_texel_2d_f_rg88_rev
,
365 fetch_texel_3d_f_rg88_rev
,
366 store_texel_rg88_rev
,
370 fetch_texel_1d_f_r16
,
371 fetch_texel_2d_f_r16
,
372 fetch_texel_3d_f_r16
,
377 fetch_texel_1d_f_rg1616
,
378 fetch_texel_2d_f_rg1616
,
379 fetch_texel_3d_f_rg1616
,
383 MESA_FORMAT_RG1616_REV
,
384 fetch_texel_1d_f_rg1616_rev
,
385 fetch_texel_2d_f_rg1616_rev
,
386 fetch_texel_3d_f_rg1616_rev
,
387 store_texel_rg1616_rev
,
390 MESA_FORMAT_ARGB2101010
,
391 fetch_texel_1d_f_argb2101010
,
392 fetch_texel_2d_f_argb2101010
,
393 fetch_texel_3d_f_argb2101010
,
394 store_texel_argb2101010
398 fetch_texel_1d_f_z24_s8
,
399 fetch_texel_2d_f_z24_s8
,
400 fetch_texel_3d_f_z24_s8
,
405 fetch_texel_1d_f_s8_z24
,
406 fetch_texel_2d_f_s8_z24
,
407 fetch_texel_3d_f_s8_z24
,
412 fetch_texel_1d_f_z16
,
413 fetch_texel_2d_f_z16
,
414 fetch_texel_3d_f_z16
,
419 fetch_texel_1d_f_s8_z24
,
420 fetch_texel_2d_f_s8_z24
,
421 fetch_texel_3d_f_s8_z24
,
426 fetch_texel_1d_f_z24_s8
,
427 fetch_texel_2d_f_z24_s8
,
428 fetch_texel_3d_f_z24_s8
,
433 fetch_texel_1d_f_z32
,
434 fetch_texel_2d_f_z32
,
435 fetch_texel_3d_f_z32
,
447 fetch_texel_1d_srgb8
,
448 fetch_texel_2d_srgb8
,
449 fetch_texel_3d_srgb8
,
454 fetch_texel_1d_srgba8
,
455 fetch_texel_2d_srgba8
,
456 fetch_texel_3d_srgba8
,
461 fetch_texel_1d_sargb8
,
462 fetch_texel_2d_sargb8
,
463 fetch_texel_3d_sargb8
,
481 MESA_FORMAT_SRGB_DXT1
,
483 _mesa_fetch_texel_2d_f_srgb_dxt1
,
488 MESA_FORMAT_SRGBA_DXT1
,
490 _mesa_fetch_texel_2d_f_srgba_dxt1
,
495 MESA_FORMAT_SRGBA_DXT3
,
497 _mesa_fetch_texel_2d_f_srgba_dxt3
,
502 MESA_FORMAT_SRGBA_DXT5
,
504 _mesa_fetch_texel_2d_f_srgba_dxt5
,
510 MESA_FORMAT_RGB_FXT1
,
512 _mesa_fetch_texel_2d_f_rgb_fxt1
,
517 MESA_FORMAT_RGBA_FXT1
,
519 _mesa_fetch_texel_2d_f_rgba_fxt1
,
524 MESA_FORMAT_RGB_DXT1
,
526 _mesa_fetch_texel_2d_f_rgb_dxt1
,
531 MESA_FORMAT_RGBA_DXT1
,
533 _mesa_fetch_texel_2d_f_rgba_dxt1
,
538 MESA_FORMAT_RGBA_DXT3
,
540 _mesa_fetch_texel_2d_f_rgba_dxt3
,
545 MESA_FORMAT_RGBA_DXT5
,
547 _mesa_fetch_texel_2d_f_rgba_dxt5
,
552 MESA_FORMAT_RGBA_FLOAT32
,
553 fetch_texel_1d_f_rgba_f32
,
554 fetch_texel_2d_f_rgba_f32
,
555 fetch_texel_3d_f_rgba_f32
,
559 MESA_FORMAT_RGBA_FLOAT16
,
560 fetch_texel_1d_f_rgba_f16
,
561 fetch_texel_2d_f_rgba_f16
,
562 fetch_texel_3d_f_rgba_f16
,
566 MESA_FORMAT_RGB_FLOAT32
,
567 fetch_texel_1d_f_rgb_f32
,
568 fetch_texel_2d_f_rgb_f32
,
569 fetch_texel_3d_f_rgb_f32
,
573 MESA_FORMAT_RGB_FLOAT16
,
574 fetch_texel_1d_f_rgb_f16
,
575 fetch_texel_2d_f_rgb_f16
,
576 fetch_texel_3d_f_rgb_f16
,
580 MESA_FORMAT_ALPHA_FLOAT32
,
581 fetch_texel_1d_f_alpha_f32
,
582 fetch_texel_2d_f_alpha_f32
,
583 fetch_texel_3d_f_alpha_f32
,
584 store_texel_alpha_f32
587 MESA_FORMAT_ALPHA_FLOAT16
,
588 fetch_texel_1d_f_alpha_f16
,
589 fetch_texel_2d_f_alpha_f16
,
590 fetch_texel_3d_f_alpha_f16
,
591 store_texel_alpha_f16
594 MESA_FORMAT_LUMINANCE_FLOAT32
,
595 fetch_texel_1d_f_luminance_f32
,
596 fetch_texel_2d_f_luminance_f32
,
597 fetch_texel_3d_f_luminance_f32
,
598 store_texel_luminance_f32
601 MESA_FORMAT_LUMINANCE_FLOAT16
,
602 fetch_texel_1d_f_luminance_f16
,
603 fetch_texel_2d_f_luminance_f16
,
604 fetch_texel_3d_f_luminance_f16
,
605 store_texel_luminance_f16
608 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
,
609 fetch_texel_1d_f_luminance_alpha_f32
,
610 fetch_texel_2d_f_luminance_alpha_f32
,
611 fetch_texel_3d_f_luminance_alpha_f32
,
612 store_texel_luminance_alpha_f32
615 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
,
616 fetch_texel_1d_f_luminance_alpha_f16
,
617 fetch_texel_2d_f_luminance_alpha_f16
,
618 fetch_texel_3d_f_luminance_alpha_f16
,
619 store_texel_luminance_alpha_f16
622 MESA_FORMAT_INTENSITY_FLOAT32
,
623 fetch_texel_1d_f_intensity_f32
,
624 fetch_texel_2d_f_intensity_f32
,
625 fetch_texel_3d_f_intensity_f32
,
626 store_texel_intensity_f32
629 MESA_FORMAT_INTENSITY_FLOAT16
,
630 fetch_texel_1d_f_intensity_f16
,
631 fetch_texel_2d_f_intensity_f16
,
632 fetch_texel_3d_f_intensity_f16
,
633 store_texel_intensity_f16
636 MESA_FORMAT_R_FLOAT32
,
637 fetch_texel_1d_f_r_f32
,
638 fetch_texel_2d_f_r_f32
,
639 fetch_texel_3d_f_r_f32
,
643 MESA_FORMAT_R_FLOAT16
,
644 fetch_texel_1d_f_r_f16
,
645 fetch_texel_2d_f_r_f16
,
646 fetch_texel_3d_f_r_f16
,
650 MESA_FORMAT_RG_FLOAT32
,
651 fetch_texel_1d_f_rg_f32
,
652 fetch_texel_2d_f_rg_f32
,
653 fetch_texel_3d_f_rg_f32
,
657 MESA_FORMAT_RG_FLOAT16
,
658 fetch_texel_1d_f_rg_f16
,
659 fetch_texel_2d_f_rg_f16
,
660 fetch_texel_3d_f_rg_f16
,
664 /* non-normalized, signed int */
666 MESA_FORMAT_RGBA_INT8
,
667 fetch_texel_1d_rgba_int8
,
668 fetch_texel_2d_rgba_int8
,
669 fetch_texel_3d_rgba_int8
,
670 store_texel_rgba_int8
673 MESA_FORMAT_RGBA_INT16
,
674 fetch_texel_1d_rgba_int16
,
675 fetch_texel_2d_rgba_int16
,
676 fetch_texel_3d_rgba_int16
,
677 store_texel_rgba_int16
680 MESA_FORMAT_RGBA_INT32
,
681 fetch_texel_1d_rgba_int32
,
682 fetch_texel_2d_rgba_int32
,
683 fetch_texel_3d_rgba_int32
,
684 store_texel_rgba_int32
687 /* non-normalized, unsigned int */
689 MESA_FORMAT_RGBA_UINT8
,
690 fetch_texel_1d_rgba_uint8
,
691 fetch_texel_2d_rgba_uint8
,
692 fetch_texel_3d_rgba_uint8
,
693 store_texel_rgba_uint8
696 MESA_FORMAT_RGBA_UINT16
,
697 fetch_texel_1d_rgba_uint16
,
698 fetch_texel_2d_rgba_uint16
,
699 fetch_texel_3d_rgba_uint16
,
700 store_texel_rgba_uint16
703 MESA_FORMAT_RGBA_UINT32
,
704 fetch_texel_1d_rgba_uint32
,
705 fetch_texel_2d_rgba_uint32
,
706 fetch_texel_3d_rgba_uint32
,
707 store_texel_rgba_uint32
713 fetch_texel_1d_dudv8
,
714 fetch_texel_2d_dudv8
,
715 fetch_texel_3d_dudv8
,
719 /* signed, normalized */
721 MESA_FORMAT_SIGNED_R8
,
722 fetch_texel_1d_signed_r8
,
723 fetch_texel_2d_signed_r8
,
724 fetch_texel_3d_signed_r8
,
725 store_texel_signed_r8
728 MESA_FORMAT_SIGNED_RG88_REV
,
729 fetch_texel_1d_signed_rg88_rev
,
730 fetch_texel_2d_signed_rg88_rev
,
731 fetch_texel_3d_signed_rg88_rev
,
732 store_texel_signed_rg88_rev
735 MESA_FORMAT_SIGNED_RGBX8888
,
736 fetch_texel_1d_signed_rgbx8888
,
737 fetch_texel_2d_signed_rgbx8888
,
738 fetch_texel_3d_signed_rgbx8888
,
739 store_texel_signed_rgbx8888
742 MESA_FORMAT_SIGNED_RGBA8888
,
743 fetch_texel_1d_signed_rgba8888
,
744 fetch_texel_2d_signed_rgba8888
,
745 fetch_texel_3d_signed_rgba8888
,
746 store_texel_signed_rgba8888
749 MESA_FORMAT_SIGNED_RGBA8888_REV
,
750 fetch_texel_1d_signed_rgba8888_rev
,
751 fetch_texel_2d_signed_rgba8888_rev
,
752 fetch_texel_3d_signed_rgba8888_rev
,
753 store_texel_signed_rgba8888_rev
756 MESA_FORMAT_SIGNED_R16
,
757 fetch_texel_1d_signed_r16
,
758 fetch_texel_2d_signed_r16
,
759 fetch_texel_3d_signed_r16
,
760 store_texel_signed_r16
763 MESA_FORMAT_SIGNED_GR1616
,
764 fetch_texel_1d_signed_rg1616
,
765 fetch_texel_2d_signed_rg1616
,
766 fetch_texel_3d_signed_rg1616
,
767 store_texel_signed_rg1616
770 MESA_FORMAT_SIGNED_RGB_16
,
771 fetch_texel_1d_signed_rgb_16
,
772 fetch_texel_2d_signed_rgb_16
,
773 fetch_texel_3d_signed_rgb_16
,
774 store_texel_signed_rgb_16
777 MESA_FORMAT_SIGNED_RGBA_16
,
778 fetch_texel_1d_signed_rgba_16
,
779 fetch_texel_2d_signed_rgba_16
,
780 fetch_texel_3d_signed_rgba_16
,
781 store_texel_signed_rgba_16
785 fetch_texel_1d_rgba_16
,
786 fetch_texel_2d_rgba_16
,
787 fetch_texel_3d_rgba_16
,
791 MESA_FORMAT_RED_RGTC1
,
793 _mesa_fetch_texel_2d_f_red_rgtc1
,
798 MESA_FORMAT_SIGNED_RED_RGTC1
,
800 _mesa_fetch_texel_2d_f_signed_red_rgtc1
,
805 MESA_FORMAT_RG_RGTC2
,
807 _mesa_fetch_texel_2d_f_rg_rgtc2
,
812 MESA_FORMAT_SIGNED_RG_RGTC2
,
814 _mesa_fetch_texel_2d_f_signed_rg_rgtc2
,
821 _mesa_fetch_texel_2d_f_l_latc1
,
826 MESA_FORMAT_SIGNED_L_LATC1
,
828 _mesa_fetch_texel_2d_f_signed_l_latc1
,
833 MESA_FORMAT_LA_LATC2
,
835 _mesa_fetch_texel_2d_f_la_latc2
,
840 MESA_FORMAT_SIGNED_LA_LATC2
,
842 _mesa_fetch_texel_2d_f_signed_la_latc2
,
847 MESA_FORMAT_SIGNED_A8
,
848 fetch_texel_1d_signed_a8
,
849 fetch_texel_2d_signed_a8
,
850 fetch_texel_3d_signed_a8
,
851 store_texel_signed_a8
854 MESA_FORMAT_SIGNED_L8
,
855 fetch_texel_1d_signed_l8
,
856 fetch_texel_2d_signed_l8
,
857 fetch_texel_3d_signed_l8
,
858 store_texel_signed_l8
861 MESA_FORMAT_SIGNED_AL88
,
862 fetch_texel_1d_signed_al88
,
863 fetch_texel_2d_signed_al88
,
864 fetch_texel_3d_signed_al88
,
865 store_texel_signed_al88
868 MESA_FORMAT_SIGNED_I8
,
869 fetch_texel_1d_signed_i8
,
870 fetch_texel_2d_signed_i8
,
871 fetch_texel_3d_signed_i8
,
872 store_texel_signed_i8
875 MESA_FORMAT_SIGNED_A16
,
876 fetch_texel_1d_signed_a16
,
877 fetch_texel_2d_signed_a16
,
878 fetch_texel_3d_signed_a16
,
879 store_texel_signed_a16
882 MESA_FORMAT_SIGNED_L16
,
883 fetch_texel_1d_signed_l16
,
884 fetch_texel_2d_signed_l16
,
885 fetch_texel_3d_signed_l16
,
886 store_texel_signed_l16
889 MESA_FORMAT_SIGNED_AL1616
,
890 fetch_texel_1d_signed_al1616
,
891 fetch_texel_2d_signed_al1616
,
892 fetch_texel_3d_signed_al1616
,
893 store_texel_signed_al1616
896 MESA_FORMAT_SIGNED_I16
,
897 fetch_texel_1d_signed_i16
,
898 fetch_texel_2d_signed_i16
,
899 fetch_texel_3d_signed_i16
,
900 store_texel_signed_i16
903 MESA_FORMAT_RGB9_E5_FLOAT
,
904 fetch_texel_1d_rgb9_e5
,
905 fetch_texel_2d_rgb9_e5
,
906 fetch_texel_3d_rgb9_e5
,
913 _mesa_get_texel_fetch_func(gl_format format
, GLuint dims
)
916 /* check that the table entries are sorted by format name */
918 for (fmt
= 0; fmt
< MESA_FORMAT_COUNT
; fmt
++) {
919 assert(texfetch_funcs
[fmt
].Name
== fmt
);
923 assert(Elements(texfetch_funcs
) == MESA_FORMAT_COUNT
);
924 assert(format
< MESA_FORMAT_COUNT
);
928 return texfetch_funcs
[format
].Fetch1D
;
930 return texfetch_funcs
[format
].Fetch2D
;
932 return texfetch_funcs
[format
].Fetch3D
;
934 assert(0 && "bad dims in _mesa_get_texel_fetch_func");
941 _mesa_get_texel_store_func(gl_format format
)
943 assert(format
< MESA_FORMAT_COUNT
);
944 return texfetch_funcs
[format
].StoreTexel
;
949 * Adaptor for fetching a GLchan texel from a float-valued texture.
952 fetch_texel_float_to_chan(const struct gl_texture_image
*texImage
,
953 GLint i
, GLint j
, GLint k
, GLchan
*texelOut
)
956 GLenum baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
958 ASSERT(texImage
->FetchTexelf
);
959 texImage
->FetchTexelf(texImage
, i
, j
, k
, temp
);
960 if (baseFormat
== GL_DEPTH_COMPONENT
||
961 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
962 /* just one channel */
963 UNCLAMPED_FLOAT_TO_CHAN(texelOut
[0], temp
[0]);
967 UNCLAMPED_FLOAT_TO_CHAN(texelOut
[0], temp
[0]);
968 UNCLAMPED_FLOAT_TO_CHAN(texelOut
[1], temp
[1]);
969 UNCLAMPED_FLOAT_TO_CHAN(texelOut
[2], temp
[2]);
970 UNCLAMPED_FLOAT_TO_CHAN(texelOut
[3], temp
[3]);
977 * Adaptor for fetching a float texel from a GLchan-valued texture.
980 fetch_texel_chan_to_float(const struct gl_texture_image
*texImage
,
981 GLint i
, GLint j
, GLint k
, GLfloat
*texelOut
)
984 GLenum baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
986 ASSERT(texImage
->FetchTexelc
);
987 texImage
->FetchTexelc(texImage
, i
, j
, k
, temp
);
988 if (baseFormat
== GL_DEPTH_COMPONENT
||
989 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
990 /* just one channel */
991 texelOut
[0] = CHAN_TO_FLOAT(temp
[0]);
995 texelOut
[0] = CHAN_TO_FLOAT(temp
[0]);
996 texelOut
[1] = CHAN_TO_FLOAT(temp
[1]);
997 texelOut
[2] = CHAN_TO_FLOAT(temp
[2]);
998 texelOut
[3] = CHAN_TO_FLOAT(temp
[3]);
1005 * Initialize the texture image's FetchTexelc and FetchTexelf methods.
1008 _mesa_set_fetch_functions(struct gl_texture_image
*texImage
, GLuint dims
)
1010 gl_format format
= texImage
->TexFormat
;
1012 ASSERT(dims
== 1 || dims
== 2 || dims
== 3);
1014 if (texImage
->TexObject
->Sampler
.sRGBDecode
== GL_SKIP_DECODE_EXT
&&
1015 _mesa_get_format_color_encoding(format
) == GL_SRGB
) {
1016 format
= _mesa_get_srgb_format_linear(format
);
1019 texImage
->FetchTexelf
= _mesa_get_texel_fetch_func(format
, dims
);
1021 texImage
->FetchTexelc
= fetch_texel_float_to_chan
;
1023 ASSERT(texImage
->FetchTexelc
);
1024 ASSERT(texImage
->FetchTexelf
);
1028 _mesa_update_fetch_functions(struct gl_texture_object
*texObj
)
1033 dims
= _mesa_get_texture_dimensions(texObj
->Target
);
1035 for (face
= 0; face
< 6; face
++) {
1036 for (i
= 0; i
< MAX_TEXTURE_LEVELS
; i
++) {
1037 if (texObj
->Image
[face
][i
]) {
1038 _mesa_set_fetch_functions(texObj
->Image
[face
][i
], dims
);