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"
44 #if FEATURE_EXT_texture_sRGB
47 * Convert an 8-bit sRGB value from non-linear space to a
48 * linear RGB value in [0, 1].
49 * Implemented with a 256-entry lookup table.
52 nonlinear_to_linear(GLubyte cs8
)
54 static GLfloat table
[256];
55 static GLboolean tableReady
= GL_FALSE
;
57 /* compute lookup table now */
59 for (i
= 0; i
< 256; i
++) {
60 const GLfloat cs
= UBYTE_TO_FLOAT(i
);
62 table
[i
] = cs
/ 12.92f
;
65 table
[i
] = (GLfloat
) _mesa_pow((cs
+ 0.055) / 1.055, 2.4);
74 #endif /* FEATURE_EXT_texture_sRGB */
77 /* Texel fetch routines for all supported formats
80 #include "texfetch_tmp.h"
83 #include "texfetch_tmp.h"
86 #include "texfetch_tmp.h"
89 * Null texel fetch function.
91 * Have to have this so the FetchTexel function pointer is never NULL.
93 static void fetch_null_texelf( const struct gl_texture_image
*texImage
,
94 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
96 (void) texImage
; (void) i
; (void) j
; (void) k
;
101 _mesa_warning(NULL
, "fetch_null_texelf() called!");
104 static void store_null_texel(struct gl_texture_image
*texImage
,
105 GLint i
, GLint j
, GLint k
, const void *texel
)
118 * Table to map MESA_FORMAT_ to texel fetch/store funcs.
119 * XXX this is somewhat temporary.
123 FetchTexelFuncF Fetch1D
;
124 FetchTexelFuncF Fetch2D
;
125 FetchTexelFuncF Fetch3D
;
126 StoreTexelFunc StoreTexel
;
128 texfetch_funcs
[MESA_FORMAT_COUNT
] =
132 fetch_texel_1d_srgb8
,
133 fetch_texel_2d_srgb8
,
134 fetch_texel_3d_srgb8
,
139 fetch_texel_1d_srgba8
,
140 fetch_texel_2d_srgba8
,
141 fetch_texel_3d_srgba8
,
146 fetch_texel_1d_sargb8
,
147 fetch_texel_2d_sargb8
,
148 fetch_texel_3d_sargb8
,
166 MESA_FORMAT_RGB_FXT1
,
168 _mesa_fetch_texel_2d_f_rgb_fxt1
,
173 MESA_FORMAT_RGBA_FXT1
,
175 _mesa_fetch_texel_2d_f_rgba_fxt1
,
180 MESA_FORMAT_RGB_DXT1
,
182 _mesa_fetch_texel_2d_f_rgb_dxt1
,
187 MESA_FORMAT_RGBA_DXT1
,
189 _mesa_fetch_texel_2d_f_rgba_dxt1
,
194 MESA_FORMAT_RGBA_DXT3
,
196 _mesa_fetch_texel_2d_f_rgba_dxt3
,
201 MESA_FORMAT_RGBA_DXT5
,
203 _mesa_fetch_texel_2d_f_rgba_dxt5
,
208 MESA_FORMAT_SRGB_DXT1
,
210 _mesa_fetch_texel_2d_f_srgb_dxt1
,
215 MESA_FORMAT_SRGBA_DXT1
,
217 _mesa_fetch_texel_2d_f_srgba_dxt1
,
222 MESA_FORMAT_SRGBA_DXT3
,
224 _mesa_fetch_texel_2d_f_srgba_dxt3
,
229 MESA_FORMAT_SRGBA_DXT5
,
231 _mesa_fetch_texel_2d_f_srgba_dxt5
,
236 MESA_FORMAT_RGBA_FLOAT32
,
237 fetch_texel_1d_f_rgba_f32
,
238 fetch_texel_2d_f_rgba_f32
,
239 fetch_texel_3d_f_rgba_f32
,
243 MESA_FORMAT_RGBA_FLOAT16
,
244 fetch_texel_1d_f_rgba_f16
,
245 fetch_texel_2d_f_rgba_f16
,
246 fetch_texel_3d_f_rgba_f16
,
250 MESA_FORMAT_RGB_FLOAT32
,
251 fetch_texel_1d_f_rgb_f32
,
252 fetch_texel_2d_f_rgb_f32
,
253 fetch_texel_3d_f_rgb_f32
,
257 MESA_FORMAT_RGB_FLOAT16
,
258 fetch_texel_1d_f_rgb_f16
,
259 fetch_texel_2d_f_rgb_f16
,
260 fetch_texel_3d_f_rgb_f16
,
264 MESA_FORMAT_ALPHA_FLOAT32
,
265 fetch_texel_1d_f_alpha_f32
,
266 fetch_texel_2d_f_alpha_f32
,
267 fetch_texel_3d_f_alpha_f32
,
268 store_texel_alpha_f32
271 MESA_FORMAT_ALPHA_FLOAT16
,
272 fetch_texel_1d_f_alpha_f16
,
273 fetch_texel_2d_f_alpha_f16
,
274 fetch_texel_3d_f_alpha_f16
,
275 store_texel_alpha_f16
278 MESA_FORMAT_LUMINANCE_FLOAT32
,
279 fetch_texel_1d_f_luminance_f32
,
280 fetch_texel_2d_f_luminance_f32
,
281 fetch_texel_3d_f_luminance_f32
,
282 store_texel_luminance_f32
285 MESA_FORMAT_LUMINANCE_FLOAT16
,
286 fetch_texel_1d_f_luminance_f16
,
287 fetch_texel_2d_f_luminance_f16
,
288 fetch_texel_3d_f_luminance_f16
,
289 store_texel_luminance_f16
292 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
,
293 fetch_texel_1d_f_luminance_alpha_f32
,
294 fetch_texel_2d_f_luminance_alpha_f32
,
295 fetch_texel_3d_f_luminance_alpha_f32
,
296 store_texel_luminance_alpha_f32
299 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
,
300 fetch_texel_1d_f_luminance_alpha_f16
,
301 fetch_texel_2d_f_luminance_alpha_f16
,
302 fetch_texel_3d_f_luminance_alpha_f16
,
303 store_texel_luminance_alpha_f16
306 MESA_FORMAT_INTENSITY_FLOAT32
,
307 fetch_texel_1d_f_intensity_f32
,
308 fetch_texel_2d_f_intensity_f32
,
309 fetch_texel_3d_f_intensity_f32
,
310 store_texel_intensity_f32
313 MESA_FORMAT_INTENSITY_FLOAT16
,
314 fetch_texel_1d_f_intensity_f16
,
315 fetch_texel_2d_f_intensity_f16
,
316 fetch_texel_3d_f_intensity_f16
,
317 store_texel_intensity_f16
321 fetch_texel_1d_dudv8
,
322 fetch_texel_2d_dudv8
,
323 fetch_texel_3d_dudv8
,
327 MESA_FORMAT_SIGNED_RGBA8888
,
328 fetch_texel_1d_signed_rgba8888
,
329 fetch_texel_2d_signed_rgba8888
,
330 fetch_texel_3d_signed_rgba8888
,
331 store_texel_signed_rgba8888
334 MESA_FORMAT_SIGNED_RGBA8888_REV
,
335 fetch_texel_1d_signed_rgba8888_rev
,
336 fetch_texel_2d_signed_rgba8888_rev
,
337 fetch_texel_3d_signed_rgba8888_rev
,
338 store_texel_signed_rgba8888_rev
341 MESA_FORMAT_RGBA8888
,
342 fetch_texel_1d_f_rgba8888
,
343 fetch_texel_2d_f_rgba8888
,
344 fetch_texel_3d_f_rgba8888
,
348 MESA_FORMAT_RGBA8888_REV
,
349 fetch_texel_1d_f_rgba8888_rev
,
350 fetch_texel_2d_f_rgba8888_rev
,
351 fetch_texel_3d_f_rgba8888_rev
,
352 store_texel_rgba8888_rev
355 MESA_FORMAT_ARGB8888
,
356 fetch_texel_1d_f_argb8888
,
357 fetch_texel_2d_f_argb8888
,
358 fetch_texel_3d_f_argb8888
,
362 MESA_FORMAT_ARGB8888_REV
,
363 fetch_texel_1d_f_argb8888_rev
,
364 fetch_texel_2d_f_argb8888_rev
,
365 fetch_texel_3d_f_argb8888_rev
,
366 store_texel_argb8888_rev
370 fetch_texel_1d_f_rgb888
,
371 fetch_texel_2d_f_rgb888
,
372 fetch_texel_3d_f_rgb888
,
377 fetch_texel_1d_f_bgr888
,
378 fetch_texel_2d_f_bgr888
,
379 fetch_texel_3d_f_bgr888
,
384 fetch_texel_1d_f_rgb565
,
385 fetch_texel_2d_f_rgb565
,
386 fetch_texel_3d_f_rgb565
,
390 MESA_FORMAT_RGB565_REV
,
391 fetch_texel_1d_f_rgb565_rev
,
392 fetch_texel_2d_f_rgb565_rev
,
393 fetch_texel_3d_f_rgb565_rev
,
394 store_texel_rgb565_rev
397 MESA_FORMAT_ARGB4444
,
398 fetch_texel_1d_f_argb4444
,
399 fetch_texel_2d_f_argb4444
,
400 fetch_texel_3d_f_argb4444
,
404 MESA_FORMAT_ARGB4444_REV
,
405 fetch_texel_1d_f_argb4444_rev
,
406 fetch_texel_2d_f_argb4444_rev
,
407 fetch_texel_3d_f_argb4444_rev
,
408 store_texel_argb4444_rev
411 MESA_FORMAT_RGBA5551
,
412 fetch_texel_1d_f_rgba5551
,
413 fetch_texel_2d_f_rgba5551
,
414 fetch_texel_3d_f_rgba5551
,
418 MESA_FORMAT_ARGB1555
,
419 fetch_texel_1d_f_argb1555
,
420 fetch_texel_2d_f_argb1555
,
421 fetch_texel_3d_f_argb1555
,
425 MESA_FORMAT_ARGB1555_REV
,
426 fetch_texel_1d_f_argb1555_rev
,
427 fetch_texel_2d_f_argb1555_rev
,
428 fetch_texel_3d_f_argb1555_rev
,
429 store_texel_argb1555_rev
433 fetch_texel_1d_f_al88
,
434 fetch_texel_2d_f_al88
,
435 fetch_texel_3d_f_al88
,
439 MESA_FORMAT_AL88_REV
,
440 fetch_texel_1d_f_al88_rev
,
441 fetch_texel_2d_f_al88_rev
,
442 fetch_texel_3d_f_al88_rev
,
447 fetch_texel_1d_f_rgb332
,
448 fetch_texel_2d_f_rgb332
,
449 fetch_texel_3d_f_rgb332
,
475 fetch_texel_1d_f_ci8
,
476 fetch_texel_2d_f_ci8
,
477 fetch_texel_3d_f_ci8
,
482 fetch_texel_1d_f_ycbcr
,
483 fetch_texel_2d_f_ycbcr
,
484 fetch_texel_3d_f_ycbcr
,
488 MESA_FORMAT_YCBCR_REV
,
489 fetch_texel_1d_f_ycbcr_rev
,
490 fetch_texel_2d_f_ycbcr_rev
,
491 fetch_texel_3d_f_ycbcr_rev
,
492 store_texel_ycbcr_rev
496 fetch_texel_1d_f_z24_s8
,
497 fetch_texel_2d_f_z24_s8
,
498 fetch_texel_3d_f_z24_s8
,
503 fetch_texel_1d_f_s8_z24
,
504 fetch_texel_2d_f_s8_z24
,
505 fetch_texel_3d_f_s8_z24
,
510 fetch_texel_1d_f_z16
,
511 fetch_texel_2d_f_z16
,
512 fetch_texel_3d_f_z16
,
517 fetch_texel_1d_f_z32
,
518 fetch_texel_2d_f_z32
,
519 fetch_texel_3d_f_z32
,
526 _mesa_get_texel_fetch_func(gl_format format
, GLuint dims
)
530 /* XXX replace loop with direct table lookup */
531 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
532 if (texfetch_funcs
[i
].Name
== format
) {
535 f
= texfetch_funcs
[i
].Fetch1D
;
538 f
= texfetch_funcs
[i
].Fetch2D
;
541 f
= texfetch_funcs
[i
].Fetch3D
;
545 f
= fetch_null_texelf
;
554 _mesa_get_texel_store_func(gl_format format
)
557 /* XXX replace loop with direct table lookup */
558 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
559 if (texfetch_funcs
[i
].Name
== format
) {
560 if (texfetch_funcs
[i
].StoreTexel
)
561 return texfetch_funcs
[i
].StoreTexel
;
563 return store_null_texel
;