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
36 #include "main/colormac.h"
37 #include "main/macros.h"
38 #include "main/teximage.h"
39 #include "s_context.h"
40 #include "s_texfetch.h"
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.
49 nonlinear_to_linear(GLubyte cs8
)
51 static GLfloat table
[256];
52 static GLboolean tableReady
= GL_FALSE
;
54 /* compute lookup table now */
56 for (i
= 0; i
< 256; i
++) {
57 const GLfloat cs
= UBYTE_TO_FLOAT(i
);
59 table
[i
] = cs
/ 12.92f
;
62 table
[i
] = (GLfloat
) pow((cs
+ 0.055) / 1.055, 2.4);
72 /* Texel fetch routines for all supported formats
75 #include "s_texfetch_tmp.h"
78 #include "s_texfetch_tmp.h"
81 #include "s_texfetch_tmp.h"
84 * Null texel fetch function.
86 * Have to have this so the FetchTexel function pointer is never NULL.
88 static void fetch_null_texelf( const struct swrast_texture_image
*texImage
,
89 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
91 (void) texImage
; (void) i
; (void) j
; (void) k
;
96 _mesa_warning(NULL
, "fetch_null_texelf() called!");
101 * Table to map MESA_FORMAT_ to texel fetch/store funcs.
102 * XXX this is somewhat temporary.
106 FetchTexelFunc Fetch1D
;
107 FetchTexelFunc Fetch2D
;
108 FetchTexelFunc Fetch3D
;
110 texfetch_funcs
[MESA_FORMAT_COUNT
] =
120 MESA_FORMAT_RGBA8888
,
121 fetch_texel_1d_f_rgba8888
,
122 fetch_texel_2d_f_rgba8888
,
123 fetch_texel_3d_f_rgba8888
126 MESA_FORMAT_RGBA8888_REV
,
127 fetch_texel_1d_f_rgba8888_rev
,
128 fetch_texel_2d_f_rgba8888_rev
,
129 fetch_texel_3d_f_rgba8888_rev
132 MESA_FORMAT_ARGB8888
,
133 fetch_texel_1d_f_argb8888
,
134 fetch_texel_2d_f_argb8888
,
135 fetch_texel_3d_f_argb8888
138 MESA_FORMAT_ARGB8888_REV
,
139 fetch_texel_1d_f_argb8888_rev
,
140 fetch_texel_2d_f_argb8888_rev
,
141 fetch_texel_3d_f_argb8888_rev
144 MESA_FORMAT_RGBX8888
,
145 fetch_texel_1d_f_rgbx8888
,
146 fetch_texel_2d_f_rgbx8888
,
147 fetch_texel_3d_f_rgbx8888
150 MESA_FORMAT_RGBX8888_REV
,
151 fetch_texel_1d_f_rgbx8888_rev
,
152 fetch_texel_2d_f_rgbx8888_rev
,
153 fetch_texel_3d_f_rgbx8888_rev
156 MESA_FORMAT_XRGB8888
,
157 fetch_texel_1d_f_xrgb8888
,
158 fetch_texel_2d_f_xrgb8888
,
159 fetch_texel_3d_f_xrgb8888
162 MESA_FORMAT_XRGB8888_REV
,
163 fetch_texel_1d_f_xrgb8888_rev
,
164 fetch_texel_2d_f_xrgb8888_rev
,
165 fetch_texel_3d_f_xrgb8888_rev
169 fetch_texel_1d_f_rgb888
,
170 fetch_texel_2d_f_rgb888
,
171 fetch_texel_3d_f_rgb888
175 fetch_texel_1d_f_bgr888
,
176 fetch_texel_2d_f_bgr888
,
177 fetch_texel_3d_f_bgr888
181 fetch_texel_1d_f_rgb565
,
182 fetch_texel_2d_f_rgb565
,
183 fetch_texel_3d_f_rgb565
186 MESA_FORMAT_RGB565_REV
,
187 fetch_texel_1d_f_rgb565_rev
,
188 fetch_texel_2d_f_rgb565_rev
,
189 fetch_texel_3d_f_rgb565_rev
192 MESA_FORMAT_ARGB4444
,
193 fetch_texel_1d_f_argb4444
,
194 fetch_texel_2d_f_argb4444
,
195 fetch_texel_3d_f_argb4444
198 MESA_FORMAT_ARGB4444_REV
,
199 fetch_texel_1d_f_argb4444_rev
,
200 fetch_texel_2d_f_argb4444_rev
,
201 fetch_texel_3d_f_argb4444_rev
204 MESA_FORMAT_RGBA5551
,
205 fetch_texel_1d_f_rgba5551
,
206 fetch_texel_2d_f_rgba5551
,
207 fetch_texel_3d_f_rgba5551
210 MESA_FORMAT_ARGB1555
,
211 fetch_texel_1d_f_argb1555
,
212 fetch_texel_2d_f_argb1555
,
213 fetch_texel_3d_f_argb1555
216 MESA_FORMAT_ARGB1555_REV
,
217 fetch_texel_1d_f_argb1555_rev
,
218 fetch_texel_2d_f_argb1555_rev
,
219 fetch_texel_3d_f_argb1555_rev
223 fetch_texel_1d_f_al44
,
224 fetch_texel_2d_f_al44
,
225 fetch_texel_3d_f_al44
229 fetch_texel_1d_f_al88
,
230 fetch_texel_2d_f_al88
,
231 fetch_texel_3d_f_al88
234 MESA_FORMAT_AL88_REV
,
235 fetch_texel_1d_f_al88_rev
,
236 fetch_texel_2d_f_al88_rev
,
237 fetch_texel_3d_f_al88_rev
241 fetch_texel_1d_f_al1616
,
242 fetch_texel_2d_f_al1616
,
243 fetch_texel_3d_f_al1616
246 MESA_FORMAT_AL1616_REV
,
247 fetch_texel_1d_f_al1616_rev
,
248 fetch_texel_2d_f_al1616_rev
,
249 fetch_texel_3d_f_al1616_rev
253 fetch_texel_1d_f_rgb332
,
254 fetch_texel_2d_f_rgb332
,
255 fetch_texel_3d_f_rgb332
265 fetch_texel_1d_f_a16
,
266 fetch_texel_2d_f_a16
,
277 fetch_texel_1d_f_l16
,
278 fetch_texel_2d_f_l16
,
289 fetch_texel_1d_f_i16
,
290 fetch_texel_2d_f_i16
,
295 fetch_texel_1d_f_ycbcr
,
296 fetch_texel_2d_f_ycbcr
,
297 fetch_texel_3d_f_ycbcr
300 MESA_FORMAT_YCBCR_REV
,
301 fetch_texel_1d_f_ycbcr_rev
,
302 fetch_texel_2d_f_ycbcr_rev
,
303 fetch_texel_3d_f_ycbcr_rev
307 fetch_texel_1d_f_z16
,
308 fetch_texel_2d_f_z16
,
313 fetch_texel_1d_f_s8_z24
,
314 fetch_texel_2d_f_s8_z24
,
315 fetch_texel_3d_f_s8_z24
319 fetch_texel_1d_f_z24_s8
,
320 fetch_texel_2d_f_z24_s8
,
321 fetch_texel_3d_f_z24_s8
325 fetch_texel_1d_f_z32
,
326 fetch_texel_2d_f_z32
,
336 MESA_FORMAT_RGBA_FLOAT32
,
337 fetch_texel_1d_f_rgba_f32
,
338 fetch_texel_2d_f_rgba_f32
,
339 fetch_texel_3d_f_rgba_f32
342 MESA_FORMAT_RGBA_FLOAT16
,
343 fetch_texel_1d_f_rgba_f16
,
344 fetch_texel_2d_f_rgba_f16
,
345 fetch_texel_3d_f_rgba_f16
348 MESA_FORMAT_RGB_FLOAT32
,
349 fetch_texel_1d_f_rgb_f32
,
350 fetch_texel_2d_f_rgb_f32
,
351 fetch_texel_3d_f_rgb_f32
354 MESA_FORMAT_RGB_FLOAT16
,
355 fetch_texel_1d_f_rgb_f16
,
356 fetch_texel_2d_f_rgb_f16
,
357 fetch_texel_3d_f_rgb_f16
360 MESA_FORMAT_ALPHA_FLOAT32
,
361 fetch_texel_1d_f_alpha_f32
,
362 fetch_texel_2d_f_alpha_f32
,
363 fetch_texel_3d_f_alpha_f32
366 MESA_FORMAT_ALPHA_FLOAT16
,
367 fetch_texel_1d_f_alpha_f16
,
368 fetch_texel_2d_f_alpha_f16
,
369 fetch_texel_3d_f_alpha_f16
372 MESA_FORMAT_LUMINANCE_FLOAT32
,
373 fetch_texel_1d_f_luminance_f32
,
374 fetch_texel_2d_f_luminance_f32
,
375 fetch_texel_3d_f_luminance_f32
378 MESA_FORMAT_LUMINANCE_FLOAT16
,
379 fetch_texel_1d_f_luminance_f16
,
380 fetch_texel_2d_f_luminance_f16
,
381 fetch_texel_3d_f_luminance_f16
384 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
,
385 fetch_texel_1d_f_luminance_alpha_f32
,
386 fetch_texel_2d_f_luminance_alpha_f32
,
387 fetch_texel_3d_f_luminance_alpha_f32
390 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
,
391 fetch_texel_1d_f_luminance_alpha_f16
,
392 fetch_texel_2d_f_luminance_alpha_f16
,
393 fetch_texel_3d_f_luminance_alpha_f16
396 MESA_FORMAT_INTENSITY_FLOAT32
,
397 fetch_texel_1d_f_intensity_f32
,
398 fetch_texel_2d_f_intensity_f32
,
399 fetch_texel_3d_f_intensity_f32
402 MESA_FORMAT_INTENSITY_FLOAT16
,
403 fetch_texel_1d_f_intensity_f16
,
404 fetch_texel_2d_f_intensity_f16
,
405 fetch_texel_3d_f_intensity_f16
409 MESA_FORMAT_ALPHA_UINT8
,
416 MESA_FORMAT_ALPHA_UINT16
,
423 MESA_FORMAT_ALPHA_UINT32
,
430 MESA_FORMAT_ALPHA_INT8
,
437 MESA_FORMAT_ALPHA_INT16
,
444 MESA_FORMAT_ALPHA_INT32
,
452 MESA_FORMAT_INTENSITY_UINT8
,
459 MESA_FORMAT_INTENSITY_UINT16
,
466 MESA_FORMAT_INTENSITY_UINT32
,
473 MESA_FORMAT_INTENSITY_INT8
,
480 MESA_FORMAT_INTENSITY_INT16
,
487 MESA_FORMAT_INTENSITY_INT32
,
495 MESA_FORMAT_LUMINANCE_UINT8
,
502 MESA_FORMAT_LUMINANCE_UINT16
,
509 MESA_FORMAT_LUMINANCE_UINT32
,
516 MESA_FORMAT_LUMINANCE_INT8
,
523 MESA_FORMAT_LUMINANCE_INT16
,
530 MESA_FORMAT_LUMINANCE_INT32
,
538 MESA_FORMAT_LUMINANCE_ALPHA_UINT8
,
545 MESA_FORMAT_LUMINANCE_ALPHA_UINT16
,
552 MESA_FORMAT_LUMINANCE_ALPHA_UINT32
,
559 MESA_FORMAT_LUMINANCE_ALPHA_INT8
,
566 MESA_FORMAT_LUMINANCE_ALPHA_INT16
,
573 MESA_FORMAT_LUMINANCE_ALPHA_INT32
,
580 MESA_FORMAT_RGB_INT8
,
586 /* non-normalized, signed int */
588 MESA_FORMAT_RGBA_INT8
,
589 fetch_texel_1d_rgba_int8
,
590 fetch_texel_2d_rgba_int8
,
591 fetch_texel_3d_rgba_int8
594 MESA_FORMAT_RGB_INT16
,
600 MESA_FORMAT_RGBA_INT16
,
601 fetch_texel_1d_rgba_int16
,
602 fetch_texel_2d_rgba_int16
,
603 fetch_texel_3d_rgba_int16
606 MESA_FORMAT_RGB_INT32
,
612 MESA_FORMAT_RGBA_INT32
,
613 fetch_texel_1d_rgba_int32
,
614 fetch_texel_2d_rgba_int32
,
615 fetch_texel_3d_rgba_int32
618 /* non-normalized, unsigned int */
620 MESA_FORMAT_RGB_UINT8
,
626 MESA_FORMAT_RGBA_UINT8
,
627 fetch_texel_1d_rgba_uint8
,
628 fetch_texel_2d_rgba_uint8
,
629 fetch_texel_3d_rgba_uint8
632 MESA_FORMAT_RGB_UINT16
,
638 MESA_FORMAT_RGBA_UINT16
,
639 fetch_texel_1d_rgba_uint16
,
640 fetch_texel_2d_rgba_uint16
,
641 fetch_texel_3d_rgba_uint16
644 MESA_FORMAT_RGB_UINT32
,
650 MESA_FORMAT_RGBA_UINT32
,
651 fetch_texel_1d_rgba_uint32
,
652 fetch_texel_2d_rgba_uint32
,
653 fetch_texel_3d_rgba_uint32
656 /* signed, normalized */
658 MESA_FORMAT_SIGNED_RGBA_16
,
659 fetch_texel_1d_signed_rgba_16
,
660 fetch_texel_2d_signed_rgba_16
,
661 fetch_texel_3d_signed_rgba_16
665 fetch_texel_1d_rgba_16
,
666 fetch_texel_2d_rgba_16
,
667 fetch_texel_3d_rgba_16
673 _mesa_get_texel_fetch_func(gl_format format
, GLuint dims
)
676 /* check that the table entries are sorted by format name */
678 for (fmt
= 0; fmt
< MESA_FORMAT_COUNT
; fmt
++) {
679 assert(texfetch_funcs
[fmt
].Name
== fmt
);
683 STATIC_ASSERT(Elements(texfetch_funcs
) == MESA_FORMAT_COUNT
);
685 assert(format
< MESA_FORMAT_COUNT
);
689 return texfetch_funcs
[format
].Fetch1D
;
691 return texfetch_funcs
[format
].Fetch2D
;
693 return texfetch_funcs
[format
].Fetch3D
;
695 assert(0 && "bad dims in _mesa_get_texel_fetch_func");
702 * Initialize the texture image's FetchTexel methods.
705 set_fetch_functions(struct swrast_texture_image
*texImage
, GLuint dims
)
707 gl_format format
= texImage
->Base
.TexFormat
;
709 ASSERT(dims
== 1 || dims
== 2 || dims
== 3);
711 texImage
->FetchTexel
= _mesa_get_texel_fetch_func(format
, dims
);
712 ASSERT(texImage
->FetchTexel
);
716 _mesa_update_fetch_functions(struct gl_texture_object
*texObj
)
721 dims
= _mesa_get_texture_dimensions(texObj
->Target
);
723 for (face
= 0; face
< 6; face
++) {
724 for (i
= 0; i
< MAX_TEXTURE_LEVELS
; i
++) {
725 if (texObj
->Image
[face
][i
]) {
726 set_fetch_functions(swrast_texture_image(texObj
->Image
[face
][i
]),