mesa: s/INLINE/inline/
[mesa.git] / src / mesa / swrast / s_texfetch.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.7
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2009 VMware, Inc.
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
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.
24 */
25
26
27 /**
28 * \file s_texfetch.c
29 *
30 * Texel fetch/store functions
31 *
32 * \author Gareth Hughes
33 */
34
35
36 #include "main/colormac.h"
37 #include "main/macros.h"
38 #include "main/texcompress.h"
39 #include "main/texcompress_fxt1.h"
40 #include "main/texcompress_s3tc.h"
41 #include "main/texcompress_rgtc.h"
42 #include "main/teximage.h"
43 #include "s_context.h"
44 #include "s_texfetch.h"
45 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
46 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
47
48
49 /**
50 * Convert an 8-bit sRGB value from non-linear space to a
51 * linear RGB value in [0, 1].
52 * Implemented with a 256-entry lookup table.
53 */
54 static inline GLfloat
55 nonlinear_to_linear(GLubyte cs8)
56 {
57 static GLfloat table[256];
58 static GLboolean tableReady = GL_FALSE;
59 if (!tableReady) {
60 /* compute lookup table now */
61 GLuint i;
62 for (i = 0; i < 256; i++) {
63 const GLfloat cs = UBYTE_TO_FLOAT(i);
64 if (cs <= 0.04045) {
65 table[i] = cs / 12.92f;
66 }
67 else {
68 table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
69 }
70 }
71 tableReady = GL_TRUE;
72 }
73 return table[cs8];
74 }
75
76
77
78 /* Texel fetch routines for all supported formats
79 */
80 #define DIM 1
81 #include "s_texfetch_tmp.h"
82
83 #define DIM 2
84 #include "s_texfetch_tmp.h"
85
86 #define DIM 3
87 #include "s_texfetch_tmp.h"
88
89 /**
90 * Null texel fetch function.
91 *
92 * Have to have this so the FetchTexel function pointer is never NULL.
93 */
94 static void fetch_null_texelf( const struct swrast_texture_image *texImage,
95 GLint i, GLint j, GLint k, GLfloat *texel )
96 {
97 (void) texImage; (void) i; (void) j; (void) k;
98 texel[RCOMP] = 0.0;
99 texel[GCOMP] = 0.0;
100 texel[BCOMP] = 0.0;
101 texel[ACOMP] = 0.0;
102 _mesa_warning(NULL, "fetch_null_texelf() called!");
103 }
104
105 static void store_null_texel(struct swrast_texture_image *texImage,
106 GLint i, GLint j, GLint k, const void *texel)
107 {
108 (void) texImage;
109 (void) i;
110 (void) j;
111 (void) k;
112 (void) texel;
113 /* no-op */
114 }
115
116
117
118 /**
119 * Table to map MESA_FORMAT_ to texel fetch/store funcs.
120 * XXX this is somewhat temporary.
121 */
122 static struct {
123 gl_format Name;
124 FetchTexelFuncF Fetch1D;
125 FetchTexelFuncF Fetch2D;
126 FetchTexelFuncF Fetch3D;
127 StoreTexelFunc StoreTexel;
128 }
129 texfetch_funcs[MESA_FORMAT_COUNT] =
130 {
131 {
132 MESA_FORMAT_NONE,
133 fetch_null_texelf,
134 fetch_null_texelf,
135 fetch_null_texelf,
136 store_null_texel
137 },
138
139 {
140 MESA_FORMAT_RGBA8888,
141 fetch_texel_1d_f_rgba8888,
142 fetch_texel_2d_f_rgba8888,
143 fetch_texel_3d_f_rgba8888,
144 store_texel_rgba8888
145 },
146 {
147 MESA_FORMAT_RGBA8888_REV,
148 fetch_texel_1d_f_rgba8888_rev,
149 fetch_texel_2d_f_rgba8888_rev,
150 fetch_texel_3d_f_rgba8888_rev,
151 store_texel_rgba8888_rev
152 },
153 {
154 MESA_FORMAT_ARGB8888,
155 fetch_texel_1d_f_argb8888,
156 fetch_texel_2d_f_argb8888,
157 fetch_texel_3d_f_argb8888,
158 store_texel_argb8888
159 },
160 {
161 MESA_FORMAT_ARGB8888_REV,
162 fetch_texel_1d_f_argb8888_rev,
163 fetch_texel_2d_f_argb8888_rev,
164 fetch_texel_3d_f_argb8888_rev,
165 store_texel_argb8888_rev
166 },
167 {
168 MESA_FORMAT_XRGB8888,
169 fetch_texel_1d_f_xrgb8888,
170 fetch_texel_2d_f_xrgb8888,
171 fetch_texel_3d_f_xrgb8888,
172 store_texel_xrgb8888
173 },
174 {
175 MESA_FORMAT_XRGB8888_REV,
176 fetch_texel_1d_f_xrgb8888_rev,
177 fetch_texel_2d_f_xrgb8888_rev,
178 fetch_texel_3d_f_xrgb8888_rev,
179 store_texel_xrgb8888_rev,
180 },
181 {
182 MESA_FORMAT_RGB888,
183 fetch_texel_1d_f_rgb888,
184 fetch_texel_2d_f_rgb888,
185 fetch_texel_3d_f_rgb888,
186 store_texel_rgb888
187 },
188 {
189 MESA_FORMAT_BGR888,
190 fetch_texel_1d_f_bgr888,
191 fetch_texel_2d_f_bgr888,
192 fetch_texel_3d_f_bgr888,
193 store_texel_bgr888
194 },
195 {
196 MESA_FORMAT_RGB565,
197 fetch_texel_1d_f_rgb565,
198 fetch_texel_2d_f_rgb565,
199 fetch_texel_3d_f_rgb565,
200 store_texel_rgb565
201 },
202 {
203 MESA_FORMAT_RGB565_REV,
204 fetch_texel_1d_f_rgb565_rev,
205 fetch_texel_2d_f_rgb565_rev,
206 fetch_texel_3d_f_rgb565_rev,
207 store_texel_rgb565_rev
208 },
209 {
210 MESA_FORMAT_ARGB4444,
211 fetch_texel_1d_f_argb4444,
212 fetch_texel_2d_f_argb4444,
213 fetch_texel_3d_f_argb4444,
214 store_texel_argb4444
215 },
216 {
217 MESA_FORMAT_ARGB4444_REV,
218 fetch_texel_1d_f_argb4444_rev,
219 fetch_texel_2d_f_argb4444_rev,
220 fetch_texel_3d_f_argb4444_rev,
221 store_texel_argb4444_rev
222 },
223 {
224 MESA_FORMAT_RGBA5551,
225 fetch_texel_1d_f_rgba5551,
226 fetch_texel_2d_f_rgba5551,
227 fetch_texel_3d_f_rgba5551,
228 store_texel_rgba5551
229 },
230 {
231 MESA_FORMAT_ARGB1555,
232 fetch_texel_1d_f_argb1555,
233 fetch_texel_2d_f_argb1555,
234 fetch_texel_3d_f_argb1555,
235 store_texel_argb1555
236 },
237 {
238 MESA_FORMAT_ARGB1555_REV,
239 fetch_texel_1d_f_argb1555_rev,
240 fetch_texel_2d_f_argb1555_rev,
241 fetch_texel_3d_f_argb1555_rev,
242 store_texel_argb1555_rev
243 },
244 {
245 MESA_FORMAT_AL44,
246 fetch_texel_1d_f_al44,
247 fetch_texel_2d_f_al44,
248 fetch_texel_3d_f_al44,
249 store_texel_al44
250 },
251 {
252 MESA_FORMAT_AL88,
253 fetch_texel_1d_f_al88,
254 fetch_texel_2d_f_al88,
255 fetch_texel_3d_f_al88,
256 store_texel_al88
257 },
258 {
259 MESA_FORMAT_AL88_REV,
260 fetch_texel_1d_f_al88_rev,
261 fetch_texel_2d_f_al88_rev,
262 fetch_texel_3d_f_al88_rev,
263 store_texel_al88_rev
264 },
265 {
266 MESA_FORMAT_AL1616,
267 fetch_texel_1d_f_al1616,
268 fetch_texel_2d_f_al1616,
269 fetch_texel_3d_f_al1616,
270 store_texel_al1616
271 },
272 {
273 MESA_FORMAT_AL1616_REV,
274 fetch_texel_1d_f_al1616_rev,
275 fetch_texel_2d_f_al1616_rev,
276 fetch_texel_3d_f_al1616_rev,
277 store_texel_al1616_rev
278 },
279 {
280 MESA_FORMAT_RGB332,
281 fetch_texel_1d_f_rgb332,
282 fetch_texel_2d_f_rgb332,
283 fetch_texel_3d_f_rgb332,
284 store_texel_rgb332
285 },
286 {
287 MESA_FORMAT_A8,
288 fetch_texel_1d_f_a8,
289 fetch_texel_2d_f_a8,
290 fetch_texel_3d_f_a8,
291 store_texel_a8
292 },
293 {
294 MESA_FORMAT_A16,
295 fetch_texel_1d_f_a16,
296 fetch_texel_2d_f_a16,
297 fetch_texel_3d_f_a16,
298 store_texel_a16
299 },
300 {
301 MESA_FORMAT_L8,
302 fetch_texel_1d_f_l8,
303 fetch_texel_2d_f_l8,
304 fetch_texel_3d_f_l8,
305 store_texel_l8
306 },
307 {
308 MESA_FORMAT_L16,
309 fetch_texel_1d_f_l16,
310 fetch_texel_2d_f_l16,
311 fetch_texel_3d_f_l16,
312 store_texel_l16
313 },
314 {
315 MESA_FORMAT_I8,
316 fetch_texel_1d_f_i8,
317 fetch_texel_2d_f_i8,
318 fetch_texel_3d_f_i8,
319 store_texel_i8
320 },
321 {
322 MESA_FORMAT_I16,
323 fetch_texel_1d_f_i16,
324 fetch_texel_2d_f_i16,
325 fetch_texel_3d_f_i16,
326 store_texel_i16
327 },
328 {
329 MESA_FORMAT_YCBCR,
330 fetch_texel_1d_f_ycbcr,
331 fetch_texel_2d_f_ycbcr,
332 fetch_texel_3d_f_ycbcr,
333 store_texel_ycbcr
334 },
335 {
336 MESA_FORMAT_YCBCR_REV,
337 fetch_texel_1d_f_ycbcr_rev,
338 fetch_texel_2d_f_ycbcr_rev,
339 fetch_texel_3d_f_ycbcr_rev,
340 store_texel_ycbcr_rev
341 },
342 {
343 MESA_FORMAT_R8,
344 fetch_texel_1d_f_r8,
345 fetch_texel_2d_f_r8,
346 fetch_texel_3d_f_r8,
347 store_texel_r8,
348 },
349 {
350 MESA_FORMAT_RG88,
351 fetch_texel_1d_f_rg88,
352 fetch_texel_2d_f_rg88,
353 fetch_texel_3d_f_rg88,
354 store_texel_rg88,
355 },
356 {
357 MESA_FORMAT_RG88_REV,
358 fetch_texel_1d_f_rg88_rev,
359 fetch_texel_2d_f_rg88_rev,
360 fetch_texel_3d_f_rg88_rev,
361 store_texel_rg88_rev,
362 },
363 {
364 MESA_FORMAT_R16,
365 fetch_texel_1d_f_r16,
366 fetch_texel_2d_f_r16,
367 fetch_texel_3d_f_r16,
368 store_texel_r16,
369 },
370 {
371 MESA_FORMAT_RG1616,
372 fetch_texel_1d_f_rg1616,
373 fetch_texel_2d_f_rg1616,
374 fetch_texel_3d_f_rg1616,
375 store_texel_rg1616,
376 },
377 {
378 MESA_FORMAT_RG1616_REV,
379 fetch_texel_1d_f_rg1616_rev,
380 fetch_texel_2d_f_rg1616_rev,
381 fetch_texel_3d_f_rg1616_rev,
382 store_texel_rg1616_rev,
383 },
384 {
385 MESA_FORMAT_ARGB2101010,
386 fetch_texel_1d_f_argb2101010,
387 fetch_texel_2d_f_argb2101010,
388 fetch_texel_3d_f_argb2101010,
389 store_texel_argb2101010
390 },
391 {
392 MESA_FORMAT_Z24_S8,
393 fetch_texel_1d_f_z24_s8,
394 fetch_texel_2d_f_z24_s8,
395 fetch_texel_3d_f_z24_s8,
396 store_texel_z24_s8
397 },
398 {
399 MESA_FORMAT_S8_Z24,
400 fetch_texel_1d_f_s8_z24,
401 fetch_texel_2d_f_s8_z24,
402 fetch_texel_3d_f_s8_z24,
403 store_texel_s8_z24
404 },
405 {
406 MESA_FORMAT_Z16,
407 fetch_texel_1d_f_z16,
408 fetch_texel_2d_f_z16,
409 fetch_texel_3d_f_z16,
410 store_texel_z16
411 },
412 {
413 MESA_FORMAT_X8_Z24,
414 fetch_texel_1d_f_s8_z24,
415 fetch_texel_2d_f_s8_z24,
416 fetch_texel_3d_f_s8_z24,
417 store_texel_s8_z24
418 },
419 {
420 MESA_FORMAT_Z24_X8,
421 fetch_texel_1d_f_z24_s8,
422 fetch_texel_2d_f_z24_s8,
423 fetch_texel_3d_f_z24_s8,
424 store_texel_z24_s8
425 },
426 {
427 MESA_FORMAT_Z32,
428 fetch_texel_1d_f_z32,
429 fetch_texel_2d_f_z32,
430 fetch_texel_3d_f_z32,
431 store_texel_z32
432 },
433 {
434 MESA_FORMAT_S8,
435 NULL,
436 NULL,
437 NULL,
438 NULL
439 },
440 {
441 MESA_FORMAT_SRGB8,
442 fetch_texel_1d_srgb8,
443 fetch_texel_2d_srgb8,
444 fetch_texel_3d_srgb8,
445 store_texel_srgb8
446 },
447 {
448 MESA_FORMAT_SRGBA8,
449 fetch_texel_1d_srgba8,
450 fetch_texel_2d_srgba8,
451 fetch_texel_3d_srgba8,
452 store_texel_srgba8
453 },
454 {
455 MESA_FORMAT_SARGB8,
456 fetch_texel_1d_sargb8,
457 fetch_texel_2d_sargb8,
458 fetch_texel_3d_sargb8,
459 store_texel_sargb8
460 },
461 {
462 MESA_FORMAT_SL8,
463 fetch_texel_1d_sl8,
464 fetch_texel_2d_sl8,
465 fetch_texel_3d_sl8,
466 store_texel_sl8
467 },
468 {
469 MESA_FORMAT_SLA8,
470 fetch_texel_1d_sla8,
471 fetch_texel_2d_sla8,
472 fetch_texel_3d_sla8,
473 store_texel_sla8
474 },
475 {
476 MESA_FORMAT_SRGB_DXT1,
477 NULL,
478 _mesa_fetch_texel_2d_f_srgb_dxt1,
479 NULL,
480 NULL
481 },
482 {
483 MESA_FORMAT_SRGBA_DXT1,
484 NULL,
485 _mesa_fetch_texel_2d_f_srgba_dxt1,
486 NULL,
487 NULL
488 },
489 {
490 MESA_FORMAT_SRGBA_DXT3,
491 NULL,
492 _mesa_fetch_texel_2d_f_srgba_dxt3,
493 NULL,
494 NULL
495 },
496 {
497 MESA_FORMAT_SRGBA_DXT5,
498 NULL,
499 _mesa_fetch_texel_2d_f_srgba_dxt5,
500 NULL,
501 NULL
502 },
503
504 {
505 MESA_FORMAT_RGB_FXT1,
506 NULL,
507 _mesa_fetch_texel_2d_f_rgb_fxt1,
508 NULL,
509 NULL
510 },
511 {
512 MESA_FORMAT_RGBA_FXT1,
513 NULL,
514 _mesa_fetch_texel_2d_f_rgba_fxt1,
515 NULL,
516 NULL
517 },
518 {
519 MESA_FORMAT_RGB_DXT1,
520 NULL,
521 _mesa_fetch_texel_2d_f_rgb_dxt1,
522 NULL,
523 NULL
524 },
525 {
526 MESA_FORMAT_RGBA_DXT1,
527 NULL,
528 _mesa_fetch_texel_2d_f_rgba_dxt1,
529 NULL,
530 NULL
531 },
532 {
533 MESA_FORMAT_RGBA_DXT3,
534 NULL,
535 _mesa_fetch_texel_2d_f_rgba_dxt3,
536 NULL,
537 NULL
538 },
539 {
540 MESA_FORMAT_RGBA_DXT5,
541 NULL,
542 _mesa_fetch_texel_2d_f_rgba_dxt5,
543 NULL,
544 NULL
545 },
546 {
547 MESA_FORMAT_RGBA_FLOAT32,
548 fetch_texel_1d_f_rgba_f32,
549 fetch_texel_2d_f_rgba_f32,
550 fetch_texel_3d_f_rgba_f32,
551 store_texel_rgba_f32
552 },
553 {
554 MESA_FORMAT_RGBA_FLOAT16,
555 fetch_texel_1d_f_rgba_f16,
556 fetch_texel_2d_f_rgba_f16,
557 fetch_texel_3d_f_rgba_f16,
558 store_texel_rgba_f16
559 },
560 {
561 MESA_FORMAT_RGB_FLOAT32,
562 fetch_texel_1d_f_rgb_f32,
563 fetch_texel_2d_f_rgb_f32,
564 fetch_texel_3d_f_rgb_f32,
565 store_texel_rgb_f32
566 },
567 {
568 MESA_FORMAT_RGB_FLOAT16,
569 fetch_texel_1d_f_rgb_f16,
570 fetch_texel_2d_f_rgb_f16,
571 fetch_texel_3d_f_rgb_f16,
572 store_texel_rgb_f16
573 },
574 {
575 MESA_FORMAT_ALPHA_FLOAT32,
576 fetch_texel_1d_f_alpha_f32,
577 fetch_texel_2d_f_alpha_f32,
578 fetch_texel_3d_f_alpha_f32,
579 store_texel_alpha_f32
580 },
581 {
582 MESA_FORMAT_ALPHA_FLOAT16,
583 fetch_texel_1d_f_alpha_f16,
584 fetch_texel_2d_f_alpha_f16,
585 fetch_texel_3d_f_alpha_f16,
586 store_texel_alpha_f16
587 },
588 {
589 MESA_FORMAT_LUMINANCE_FLOAT32,
590 fetch_texel_1d_f_luminance_f32,
591 fetch_texel_2d_f_luminance_f32,
592 fetch_texel_3d_f_luminance_f32,
593 store_texel_luminance_f32
594 },
595 {
596 MESA_FORMAT_LUMINANCE_FLOAT16,
597 fetch_texel_1d_f_luminance_f16,
598 fetch_texel_2d_f_luminance_f16,
599 fetch_texel_3d_f_luminance_f16,
600 store_texel_luminance_f16
601 },
602 {
603 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
604 fetch_texel_1d_f_luminance_alpha_f32,
605 fetch_texel_2d_f_luminance_alpha_f32,
606 fetch_texel_3d_f_luminance_alpha_f32,
607 store_texel_luminance_alpha_f32
608 },
609 {
610 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
611 fetch_texel_1d_f_luminance_alpha_f16,
612 fetch_texel_2d_f_luminance_alpha_f16,
613 fetch_texel_3d_f_luminance_alpha_f16,
614 store_texel_luminance_alpha_f16
615 },
616 {
617 MESA_FORMAT_INTENSITY_FLOAT32,
618 fetch_texel_1d_f_intensity_f32,
619 fetch_texel_2d_f_intensity_f32,
620 fetch_texel_3d_f_intensity_f32,
621 store_texel_intensity_f32
622 },
623 {
624 MESA_FORMAT_INTENSITY_FLOAT16,
625 fetch_texel_1d_f_intensity_f16,
626 fetch_texel_2d_f_intensity_f16,
627 fetch_texel_3d_f_intensity_f16,
628 store_texel_intensity_f16
629 },
630 {
631 MESA_FORMAT_R_FLOAT32,
632 fetch_texel_1d_f_r_f32,
633 fetch_texel_2d_f_r_f32,
634 fetch_texel_3d_f_r_f32,
635 store_texel_r_f32
636 },
637 {
638 MESA_FORMAT_R_FLOAT16,
639 fetch_texel_1d_f_r_f16,
640 fetch_texel_2d_f_r_f16,
641 fetch_texel_3d_f_r_f16,
642 store_texel_r_f16
643 },
644 {
645 MESA_FORMAT_RG_FLOAT32,
646 fetch_texel_1d_f_rg_f32,
647 fetch_texel_2d_f_rg_f32,
648 fetch_texel_3d_f_rg_f32,
649 store_texel_rg_f32
650 },
651 {
652 MESA_FORMAT_RG_FLOAT16,
653 fetch_texel_1d_f_rg_f16,
654 fetch_texel_2d_f_rg_f16,
655 fetch_texel_3d_f_rg_f16,
656 store_texel_rg_f16
657 },
658
659 /* non-normalized, signed int */
660 {
661 MESA_FORMAT_RGBA_INT8,
662 fetch_texel_1d_rgba_int8,
663 fetch_texel_2d_rgba_int8,
664 fetch_texel_3d_rgba_int8,
665 store_texel_rgba_int8
666 },
667 {
668 MESA_FORMAT_RGBA_INT16,
669 fetch_texel_1d_rgba_int16,
670 fetch_texel_2d_rgba_int16,
671 fetch_texel_3d_rgba_int16,
672 store_texel_rgba_int16
673 },
674 {
675 MESA_FORMAT_RGBA_INT32,
676 fetch_texel_1d_rgba_int32,
677 fetch_texel_2d_rgba_int32,
678 fetch_texel_3d_rgba_int32,
679 store_texel_rgba_int32
680 },
681
682 /* non-normalized, unsigned int */
683 {
684 MESA_FORMAT_RGBA_UINT8,
685 fetch_texel_1d_rgba_uint8,
686 fetch_texel_2d_rgba_uint8,
687 fetch_texel_3d_rgba_uint8,
688 store_texel_rgba_uint8
689 },
690 {
691 MESA_FORMAT_RGBA_UINT16,
692 fetch_texel_1d_rgba_uint16,
693 fetch_texel_2d_rgba_uint16,
694 fetch_texel_3d_rgba_uint16,
695 store_texel_rgba_uint16
696 },
697 {
698 MESA_FORMAT_RGBA_UINT32,
699 fetch_texel_1d_rgba_uint32,
700 fetch_texel_2d_rgba_uint32,
701 fetch_texel_3d_rgba_uint32,
702 store_texel_rgba_uint32
703 },
704
705 /* dudv */
706 {
707 MESA_FORMAT_DUDV8,
708 fetch_texel_1d_dudv8,
709 fetch_texel_2d_dudv8,
710 fetch_texel_3d_dudv8,
711 NULL
712 },
713
714 /* signed, normalized */
715 {
716 MESA_FORMAT_SIGNED_R8,
717 fetch_texel_1d_signed_r8,
718 fetch_texel_2d_signed_r8,
719 fetch_texel_3d_signed_r8,
720 store_texel_signed_r8
721 },
722 {
723 MESA_FORMAT_SIGNED_RG88_REV,
724 fetch_texel_1d_signed_rg88_rev,
725 fetch_texel_2d_signed_rg88_rev,
726 fetch_texel_3d_signed_rg88_rev,
727 store_texel_signed_rg88_rev
728 },
729 {
730 MESA_FORMAT_SIGNED_RGBX8888,
731 fetch_texel_1d_signed_rgbx8888,
732 fetch_texel_2d_signed_rgbx8888,
733 fetch_texel_3d_signed_rgbx8888,
734 store_texel_signed_rgbx8888
735 },
736 {
737 MESA_FORMAT_SIGNED_RGBA8888,
738 fetch_texel_1d_signed_rgba8888,
739 fetch_texel_2d_signed_rgba8888,
740 fetch_texel_3d_signed_rgba8888,
741 store_texel_signed_rgba8888
742 },
743 {
744 MESA_FORMAT_SIGNED_RGBA8888_REV,
745 fetch_texel_1d_signed_rgba8888_rev,
746 fetch_texel_2d_signed_rgba8888_rev,
747 fetch_texel_3d_signed_rgba8888_rev,
748 store_texel_signed_rgba8888_rev
749 },
750 {
751 MESA_FORMAT_SIGNED_R16,
752 fetch_texel_1d_signed_r16,
753 fetch_texel_2d_signed_r16,
754 fetch_texel_3d_signed_r16,
755 store_texel_signed_r16
756 },
757 {
758 MESA_FORMAT_SIGNED_GR1616,
759 fetch_texel_1d_signed_rg1616,
760 fetch_texel_2d_signed_rg1616,
761 fetch_texel_3d_signed_rg1616,
762 store_texel_signed_rg1616
763 },
764 {
765 MESA_FORMAT_SIGNED_RGB_16,
766 fetch_texel_1d_signed_rgb_16,
767 fetch_texel_2d_signed_rgb_16,
768 fetch_texel_3d_signed_rgb_16,
769 store_texel_signed_rgb_16
770 },
771 {
772 MESA_FORMAT_SIGNED_RGBA_16,
773 fetch_texel_1d_signed_rgba_16,
774 fetch_texel_2d_signed_rgba_16,
775 fetch_texel_3d_signed_rgba_16,
776 store_texel_signed_rgba_16
777 },
778 {
779 MESA_FORMAT_RGBA_16,
780 fetch_texel_1d_rgba_16,
781 fetch_texel_2d_rgba_16,
782 fetch_texel_3d_rgba_16,
783 store_texel_rgba_16
784 },
785 {
786 MESA_FORMAT_RED_RGTC1,
787 NULL,
788 _mesa_fetch_texel_2d_f_red_rgtc1,
789 NULL,
790 NULL
791 },
792 {
793 MESA_FORMAT_SIGNED_RED_RGTC1,
794 NULL,
795 _mesa_fetch_texel_2d_f_signed_red_rgtc1,
796 NULL,
797 NULL
798 },
799 {
800 MESA_FORMAT_RG_RGTC2,
801 NULL,
802 _mesa_fetch_texel_2d_f_rg_rgtc2,
803 NULL,
804 NULL
805 },
806 {
807 MESA_FORMAT_SIGNED_RG_RGTC2,
808 NULL,
809 _mesa_fetch_texel_2d_f_signed_rg_rgtc2,
810 NULL,
811 NULL
812 },
813 {
814 MESA_FORMAT_L_LATC1,
815 NULL,
816 _mesa_fetch_texel_2d_f_l_latc1,
817 NULL,
818 NULL
819 },
820 {
821 MESA_FORMAT_SIGNED_L_LATC1,
822 NULL,
823 _mesa_fetch_texel_2d_f_signed_l_latc1,
824 NULL,
825 NULL
826 },
827 {
828 MESA_FORMAT_LA_LATC2,
829 NULL,
830 _mesa_fetch_texel_2d_f_la_latc2,
831 NULL,
832 NULL
833 },
834 {
835 MESA_FORMAT_SIGNED_LA_LATC2,
836 NULL,
837 _mesa_fetch_texel_2d_f_signed_la_latc2,
838 NULL,
839 NULL
840 },
841 {
842 MESA_FORMAT_SIGNED_A8,
843 fetch_texel_1d_signed_a8,
844 fetch_texel_2d_signed_a8,
845 fetch_texel_3d_signed_a8,
846 store_texel_signed_a8
847 },
848 {
849 MESA_FORMAT_SIGNED_L8,
850 fetch_texel_1d_signed_l8,
851 fetch_texel_2d_signed_l8,
852 fetch_texel_3d_signed_l8,
853 store_texel_signed_l8
854 },
855 {
856 MESA_FORMAT_SIGNED_AL88,
857 fetch_texel_1d_signed_al88,
858 fetch_texel_2d_signed_al88,
859 fetch_texel_3d_signed_al88,
860 store_texel_signed_al88
861 },
862 {
863 MESA_FORMAT_SIGNED_I8,
864 fetch_texel_1d_signed_i8,
865 fetch_texel_2d_signed_i8,
866 fetch_texel_3d_signed_i8,
867 store_texel_signed_i8
868 },
869 {
870 MESA_FORMAT_SIGNED_A16,
871 fetch_texel_1d_signed_a16,
872 fetch_texel_2d_signed_a16,
873 fetch_texel_3d_signed_a16,
874 store_texel_signed_a16
875 },
876 {
877 MESA_FORMAT_SIGNED_L16,
878 fetch_texel_1d_signed_l16,
879 fetch_texel_2d_signed_l16,
880 fetch_texel_3d_signed_l16,
881 store_texel_signed_l16
882 },
883 {
884 MESA_FORMAT_SIGNED_AL1616,
885 fetch_texel_1d_signed_al1616,
886 fetch_texel_2d_signed_al1616,
887 fetch_texel_3d_signed_al1616,
888 store_texel_signed_al1616
889 },
890 {
891 MESA_FORMAT_SIGNED_I16,
892 fetch_texel_1d_signed_i16,
893 fetch_texel_2d_signed_i16,
894 fetch_texel_3d_signed_i16,
895 store_texel_signed_i16
896 },
897 {
898 MESA_FORMAT_RGB9_E5_FLOAT,
899 fetch_texel_1d_rgb9_e5,
900 fetch_texel_2d_rgb9_e5,
901 fetch_texel_3d_rgb9_e5,
902 store_texel_rgb9_e5
903 },
904 {
905 MESA_FORMAT_R11_G11_B10_FLOAT,
906 fetch_texel_1d_r11_g11_b10f,
907 fetch_texel_2d_r11_g11_b10f,
908 fetch_texel_3d_r11_g11_b10f,
909 store_texel_r11_g11_b10f
910 },
911 {
912 MESA_FORMAT_Z32_FLOAT,
913 fetch_texel_1d_f_r_f32, /* Reuse the R32F functions. */
914 fetch_texel_2d_f_r_f32,
915 fetch_texel_3d_f_r_f32,
916 store_texel_r_f32
917 },
918 {
919 MESA_FORMAT_Z32_FLOAT_X24S8,
920 fetch_texel_1d_z32f_x24s8,
921 fetch_texel_2d_z32f_x24s8,
922 fetch_texel_3d_z32f_x24s8,
923 store_texel_z32f_x24s8
924 }
925 };
926
927
928 FetchTexelFuncF
929 _mesa_get_texel_fetch_func(gl_format format, GLuint dims)
930 {
931 #ifdef DEBUG
932 /* check that the table entries are sorted by format name */
933 gl_format fmt;
934 for (fmt = 0; fmt < MESA_FORMAT_COUNT; fmt++) {
935 assert(texfetch_funcs[fmt].Name == fmt);
936 }
937 #endif
938
939 assert(Elements(texfetch_funcs) == MESA_FORMAT_COUNT);
940 assert(format < MESA_FORMAT_COUNT);
941
942 switch (dims) {
943 case 1:
944 return texfetch_funcs[format].Fetch1D;
945 case 2:
946 return texfetch_funcs[format].Fetch2D;
947 case 3:
948 return texfetch_funcs[format].Fetch3D;
949 default:
950 assert(0 && "bad dims in _mesa_get_texel_fetch_func");
951 return NULL;
952 }
953 }
954
955
956 StoreTexelFunc
957 _mesa_get_texel_store_func(gl_format format)
958 {
959 assert(format < MESA_FORMAT_COUNT);
960 return texfetch_funcs[format].StoreTexel;
961 }
962
963
964 /**
965 * Adaptor for fetching a GLchan texel from a float-valued texture.
966 */
967 static void
968 fetch_texel_float_to_chan(const struct swrast_texture_image *texImage,
969 GLint i, GLint j, GLint k, GLchan *texelOut)
970 {
971 GLfloat temp[4];
972 GLenum baseFormat = _mesa_get_format_base_format(texImage->Base.TexFormat);
973
974 ASSERT(texImage->FetchTexelf);
975 texImage->FetchTexelf(texImage, i, j, k, temp);
976 if (baseFormat == GL_DEPTH_COMPONENT ||
977 baseFormat == GL_DEPTH_STENCIL_EXT) {
978 /* just one channel */
979 UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]);
980 }
981 else {
982 /* four channels */
983 UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]);
984 UNCLAMPED_FLOAT_TO_CHAN(texelOut[1], temp[1]);
985 UNCLAMPED_FLOAT_TO_CHAN(texelOut[2], temp[2]);
986 UNCLAMPED_FLOAT_TO_CHAN(texelOut[3], temp[3]);
987 }
988 }
989
990
991 #if 0
992 /**
993 * Adaptor for fetching a float texel from a GLchan-valued texture.
994 */
995 static void
996 fetch_texel_chan_to_float(const struct swrast_texture_image *texImage,
997 GLint i, GLint j, GLint k, GLfloat *texelOut)
998 {
999 GLchan temp[4];
1000 GLenum baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
1001
1002 ASSERT(texImage->FetchTexelc);
1003 texImage->FetchTexelc(texImage, i, j, k, temp);
1004 if (baseFormat == GL_DEPTH_COMPONENT ||
1005 baseFormat == GL_DEPTH_STENCIL_EXT) {
1006 /* just one channel */
1007 texelOut[0] = CHAN_TO_FLOAT(temp[0]);
1008 }
1009 else {
1010 /* four channels */
1011 texelOut[0] = CHAN_TO_FLOAT(temp[0]);
1012 texelOut[1] = CHAN_TO_FLOAT(temp[1]);
1013 texelOut[2] = CHAN_TO_FLOAT(temp[2]);
1014 texelOut[3] = CHAN_TO_FLOAT(temp[3]);
1015 }
1016 }
1017 #endif
1018
1019
1020 /**
1021 * Initialize the texture image's FetchTexelc and FetchTexelf methods.
1022 */
1023 static void
1024 set_fetch_functions(struct swrast_texture_image *texImage, GLuint dims)
1025 {
1026 gl_format format = texImage->Base.TexFormat;
1027
1028 ASSERT(dims == 1 || dims == 2 || dims == 3);
1029
1030 if (texImage->Base.TexObject->Sampler.sRGBDecode == GL_SKIP_DECODE_EXT &&
1031 _mesa_get_format_color_encoding(format) == GL_SRGB) {
1032 format = _mesa_get_srgb_format_linear(format);
1033 }
1034
1035 texImage->FetchTexelf = _mesa_get_texel_fetch_func(format, dims);
1036
1037 texImage->FetchTexelc = fetch_texel_float_to_chan;
1038
1039 ASSERT(texImage->FetchTexelc);
1040 ASSERT(texImage->FetchTexelf);
1041 }
1042
1043 void
1044 _mesa_update_fetch_functions(struct gl_texture_object *texObj)
1045 {
1046 GLuint face, i;
1047 GLuint dims;
1048
1049 dims = _mesa_get_texture_dimensions(texObj->Target);
1050
1051 for (face = 0; face < 6; face++) {
1052 for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
1053 if (texObj->Image[face][i]) {
1054 set_fetch_functions(swrast_texture_image(texObj->Image[face][i]),
1055 dims);
1056 }
1057 }
1058 }
1059 }