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 "texformat_tmp.h"
83 #include "texformat_tmp.h"
86 #include "texformat_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_f_rgba
,
133 fetch_texel_2d_f_rgba
,
134 fetch_texel_3d_f_rgba
,
139 fetch_texel_1d_f_rgb
,
140 fetch_texel_2d_f_rgb
,
141 fetch_texel_3d_f_rgb
,
146 fetch_texel_1d_f_alpha
,
147 fetch_texel_2d_f_alpha
,
148 fetch_texel_3d_f_alpha
,
152 MESA_FORMAT_LUMINANCE
,
153 fetch_texel_1d_f_luminance
,
154 fetch_texel_2d_f_luminance
,
155 fetch_texel_3d_f_luminance
,
156 store_texel_luminance
159 MESA_FORMAT_LUMINANCE_ALPHA
,
160 fetch_texel_1d_f_luminance_alpha
,
161 fetch_texel_2d_f_luminance_alpha
,
162 fetch_texel_3d_f_luminance_alpha
,
163 store_texel_luminance_alpha
166 MESA_FORMAT_INTENSITY
,
167 fetch_texel_1d_f_intensity
,
168 fetch_texel_2d_f_intensity
,
169 fetch_texel_3d_f_intensity
,
170 store_texel_intensity
174 fetch_texel_1d_srgb8
,
175 fetch_texel_2d_srgb8
,
176 fetch_texel_3d_srgb8
,
181 fetch_texel_1d_srgba8
,
182 fetch_texel_2d_srgba8
,
183 fetch_texel_3d_srgba8
,
188 fetch_texel_1d_sargb8
,
189 fetch_texel_2d_sargb8
,
190 fetch_texel_3d_sargb8
,
208 MESA_FORMAT_RGB_FXT1
,
210 _mesa_fetch_texel_2d_f_rgb_fxt1
,
215 MESA_FORMAT_RGBA_FXT1
,
217 _mesa_fetch_texel_2d_f_rgba_fxt1
,
222 MESA_FORMAT_RGB_DXT1
,
224 _mesa_fetch_texel_2d_f_rgb_dxt1
,
229 MESA_FORMAT_RGBA_DXT1
,
231 _mesa_fetch_texel_2d_f_rgba_dxt1
,
236 MESA_FORMAT_RGBA_DXT3
,
238 _mesa_fetch_texel_2d_f_rgba_dxt3
,
243 MESA_FORMAT_RGBA_DXT5
,
245 _mesa_fetch_texel_2d_f_rgba_dxt5
,
250 MESA_FORMAT_SRGB_DXT1
,
252 _mesa_fetch_texel_2d_f_srgb_dxt1
,
257 MESA_FORMAT_SRGBA_DXT1
,
259 _mesa_fetch_texel_2d_f_srgba_dxt1
,
264 MESA_FORMAT_SRGBA_DXT3
,
266 _mesa_fetch_texel_2d_f_srgba_dxt3
,
271 MESA_FORMAT_SRGBA_DXT5
,
273 _mesa_fetch_texel_2d_f_srgba_dxt5
,
278 MESA_FORMAT_RGBA_FLOAT32
,
279 fetch_texel_1d_f_rgba_f32
,
280 fetch_texel_2d_f_rgba_f32
,
281 fetch_texel_3d_f_rgba_f32
,
285 MESA_FORMAT_RGBA_FLOAT16
,
286 fetch_texel_1d_f_rgba_f16
,
287 fetch_texel_2d_f_rgba_f16
,
288 fetch_texel_3d_f_rgba_f16
,
292 MESA_FORMAT_RGB_FLOAT32
,
293 fetch_texel_1d_f_rgb_f32
,
294 fetch_texel_2d_f_rgb_f32
,
295 fetch_texel_3d_f_rgb_f32
,
299 MESA_FORMAT_RGB_FLOAT16
,
300 fetch_texel_1d_f_rgb_f16
,
301 fetch_texel_2d_f_rgb_f16
,
302 fetch_texel_3d_f_rgb_f16
,
306 MESA_FORMAT_ALPHA_FLOAT32
,
307 fetch_texel_1d_f_alpha_f32
,
308 fetch_texel_2d_f_alpha_f32
,
309 fetch_texel_3d_f_alpha_f32
,
310 store_texel_alpha_f32
313 MESA_FORMAT_ALPHA_FLOAT16
,
314 fetch_texel_1d_f_alpha_f16
,
315 fetch_texel_2d_f_alpha_f16
,
316 fetch_texel_3d_f_alpha_f16
,
317 store_texel_alpha_f16
320 MESA_FORMAT_LUMINANCE_FLOAT32
,
321 fetch_texel_1d_f_luminance_f32
,
322 fetch_texel_2d_f_luminance_f32
,
323 fetch_texel_3d_f_luminance_f32
,
324 store_texel_luminance_f32
327 MESA_FORMAT_LUMINANCE_FLOAT16
,
328 fetch_texel_1d_f_luminance_f16
,
329 fetch_texel_2d_f_luminance_f16
,
330 fetch_texel_3d_f_luminance_f16
,
331 store_texel_luminance_f16
334 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
,
335 fetch_texel_1d_f_luminance_alpha_f32
,
336 fetch_texel_2d_f_luminance_alpha_f32
,
337 fetch_texel_3d_f_luminance_alpha_f32
,
338 store_texel_luminance_alpha_f32
341 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
,
342 fetch_texel_1d_f_luminance_alpha_f16
,
343 fetch_texel_2d_f_luminance_alpha_f16
,
344 fetch_texel_3d_f_luminance_alpha_f16
,
345 store_texel_luminance_alpha_f16
348 MESA_FORMAT_INTENSITY_FLOAT32
,
349 fetch_texel_1d_f_intensity_f32
,
350 fetch_texel_2d_f_intensity_f32
,
351 fetch_texel_3d_f_intensity_f32
,
352 store_texel_intensity_f32
355 MESA_FORMAT_INTENSITY_FLOAT16
,
356 fetch_texel_1d_f_intensity_f16
,
357 fetch_texel_2d_f_intensity_f16
,
358 fetch_texel_3d_f_intensity_f16
,
359 store_texel_intensity_f16
363 fetch_texel_1d_dudv8
,
364 fetch_texel_2d_dudv8
,
365 fetch_texel_3d_dudv8
,
369 MESA_FORMAT_SIGNED_RGBA8888
,
370 fetch_texel_1d_signed_rgba8888
,
371 fetch_texel_2d_signed_rgba8888
,
372 fetch_texel_3d_signed_rgba8888
,
373 store_texel_signed_rgba8888
376 MESA_FORMAT_SIGNED_RGBA8888_REV
,
377 fetch_texel_1d_signed_rgba8888_rev
,
378 fetch_texel_2d_signed_rgba8888_rev
,
379 fetch_texel_3d_signed_rgba8888_rev
,
380 store_texel_signed_rgba8888_rev
383 MESA_FORMAT_RGBA8888
,
384 fetch_texel_1d_f_rgba8888
,
385 fetch_texel_2d_f_rgba8888
,
386 fetch_texel_3d_f_rgba8888
,
390 MESA_FORMAT_RGBA8888_REV
,
391 fetch_texel_1d_f_rgba8888_rev
,
392 fetch_texel_2d_f_rgba8888_rev
,
393 fetch_texel_3d_f_rgba8888_rev
,
394 store_texel_rgba8888_rev
397 MESA_FORMAT_ARGB8888
,
398 fetch_texel_1d_f_argb8888
,
399 fetch_texel_2d_f_argb8888
,
400 fetch_texel_3d_f_argb8888
,
404 MESA_FORMAT_ARGB8888_REV
,
405 fetch_texel_1d_f_argb8888_rev
,
406 fetch_texel_2d_f_argb8888_rev
,
407 fetch_texel_3d_f_argb8888_rev
,
408 store_texel_argb8888_rev
412 fetch_texel_1d_f_rgb888
,
413 fetch_texel_2d_f_rgb888
,
414 fetch_texel_3d_f_rgb888
,
419 fetch_texel_1d_f_bgr888
,
420 fetch_texel_2d_f_bgr888
,
421 fetch_texel_3d_f_bgr888
,
426 fetch_texel_1d_f_rgb565
,
427 fetch_texel_2d_f_rgb565
,
428 fetch_texel_3d_f_rgb565
,
432 MESA_FORMAT_RGB565_REV
,
433 fetch_texel_1d_f_rgb565_rev
,
434 fetch_texel_2d_f_rgb565_rev
,
435 fetch_texel_3d_f_rgb565_rev
,
436 store_texel_rgb565_rev
439 MESA_FORMAT_RGBA4444
,
440 fetch_texel_1d_f_rgba4444
,
441 fetch_texel_2d_f_rgba4444
,
442 fetch_texel_3d_f_rgba4444
,
446 MESA_FORMAT_ARGB4444
,
447 fetch_texel_1d_f_argb4444
,
448 fetch_texel_2d_f_argb4444
,
449 fetch_texel_3d_f_argb4444
,
453 MESA_FORMAT_ARGB4444_REV
,
454 fetch_texel_1d_f_argb4444_rev
,
455 fetch_texel_2d_f_argb4444_rev
,
456 fetch_texel_3d_f_argb4444_rev
,
457 store_texel_argb4444_rev
460 MESA_FORMAT_RGBA5551
,
461 fetch_texel_1d_f_rgba5551
,
462 fetch_texel_2d_f_rgba5551
,
463 fetch_texel_3d_f_rgba5551
,
467 MESA_FORMAT_ARGB1555
,
468 fetch_texel_1d_f_argb1555
,
469 fetch_texel_2d_f_argb1555
,
470 fetch_texel_3d_f_argb1555
,
474 MESA_FORMAT_ARGB1555_REV
,
475 fetch_texel_1d_f_argb1555_rev
,
476 fetch_texel_2d_f_argb1555_rev
,
477 fetch_texel_3d_f_argb1555_rev
,
478 store_texel_argb1555_rev
482 fetch_texel_1d_f_al88
,
483 fetch_texel_2d_f_al88
,
484 fetch_texel_3d_f_al88
,
488 MESA_FORMAT_AL88_REV
,
489 fetch_texel_1d_f_al88_rev
,
490 fetch_texel_2d_f_al88_rev
,
491 fetch_texel_3d_f_al88_rev
,
496 fetch_texel_1d_f_rgb332
,
497 fetch_texel_2d_f_rgb332
,
498 fetch_texel_3d_f_rgb332
,
524 fetch_texel_1d_f_ci8
,
525 fetch_texel_2d_f_ci8
,
526 fetch_texel_3d_f_ci8
,
531 fetch_texel_1d_f_ycbcr
,
532 fetch_texel_2d_f_ycbcr
,
533 fetch_texel_3d_f_ycbcr
,
537 MESA_FORMAT_YCBCR_REV
,
538 fetch_texel_1d_f_ycbcr_rev
,
539 fetch_texel_2d_f_ycbcr_rev
,
540 fetch_texel_3d_f_ycbcr_rev
,
541 store_texel_ycbcr_rev
545 fetch_texel_1d_f_z24_s8
,
546 fetch_texel_2d_f_z24_s8
,
547 fetch_texel_3d_f_z24_s8
,
552 fetch_texel_1d_f_s8_z24
,
553 fetch_texel_2d_f_s8_z24
,
554 fetch_texel_3d_f_s8_z24
,
559 fetch_texel_1d_f_z16
,
560 fetch_texel_2d_f_z16
,
561 fetch_texel_3d_f_z16
,
566 fetch_texel_1d_f_z32
,
567 fetch_texel_2d_f_z32
,
568 fetch_texel_3d_f_z32
,
575 _mesa_get_texel_fetch_func(gl_format format
, GLuint dims
)
579 /* XXX replace loop with direct table lookup */
580 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
581 if (texfetch_funcs
[i
].Name
== format
) {
584 f
= texfetch_funcs
[i
].Fetch1D
;
587 f
= texfetch_funcs
[i
].Fetch2D
;
590 f
= texfetch_funcs
[i
].Fetch3D
;
594 f
= fetch_null_texelf
;
603 _mesa_get_texel_store_func(gl_format format
)
606 /* XXX replace loop with direct table lookup */
607 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
608 if (texfetch_funcs
[i
].Name
== format
) {
609 if (texfetch_funcs
[i
].StoreTexel
)
610 return texfetch_funcs
[i
].StoreTexel
;
612 return store_null_texel
;