mesa: Include macros.h in files that use symbols from macros.h.
[mesa.git] / src / mesa / main / 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 texfetch.c
29 *
30 * Texel fetch/store functions
31 *
32 * \author Gareth Hughes
33 */
34
35
36 #include "colormac.h"
37 #include "context.h"
38 #include "macros.h"
39 #include "texcompress.h"
40 #include "texcompress_fxt1.h"
41 #include "texcompress_s3tc.h"
42 #include "texfetch.h"
43
44
45 /**
46 * Convert an 8-bit sRGB value from non-linear space to a
47 * linear RGB value in [0, 1].
48 * Implemented with a 256-entry lookup table.
49 */
50 static INLINE GLfloat
51 nonlinear_to_linear(GLubyte cs8)
52 {
53 static GLfloat table[256];
54 static GLboolean tableReady = GL_FALSE;
55 if (!tableReady) {
56 /* compute lookup table now */
57 GLuint i;
58 for (i = 0; i < 256; i++) {
59 const GLfloat cs = UBYTE_TO_FLOAT(i);
60 if (cs <= 0.04045) {
61 table[i] = cs / 12.92f;
62 }
63 else {
64 table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
65 }
66 }
67 tableReady = GL_TRUE;
68 }
69 return table[cs8];
70 }
71
72
73
74 /* Texel fetch routines for all supported formats
75 */
76 #define DIM 1
77 #include "texfetch_tmp.h"
78
79 #define DIM 2
80 #include "texfetch_tmp.h"
81
82 #define DIM 3
83 #include "texfetch_tmp.h"
84
85 /**
86 * Null texel fetch function.
87 *
88 * Have to have this so the FetchTexel function pointer is never NULL.
89 */
90 static void fetch_null_texelf( const struct gl_texture_image *texImage,
91 GLint i, GLint j, GLint k, GLfloat *texel )
92 {
93 (void) texImage; (void) i; (void) j; (void) k;
94 texel[RCOMP] = 0.0;
95 texel[GCOMP] = 0.0;
96 texel[BCOMP] = 0.0;
97 texel[ACOMP] = 0.0;
98 _mesa_warning(NULL, "fetch_null_texelf() called!");
99 }
100
101 static void store_null_texel(struct gl_texture_image *texImage,
102 GLint i, GLint j, GLint k, const void *texel)
103 {
104 (void) texImage;
105 (void) i;
106 (void) j;
107 (void) k;
108 (void) texel;
109 /* no-op */
110 }
111
112
113
114 /**
115 * Table to map MESA_FORMAT_ to texel fetch/store funcs.
116 * XXX this is somewhat temporary.
117 */
118 static struct {
119 gl_format Name;
120 FetchTexelFuncF Fetch1D;
121 FetchTexelFuncF Fetch2D;
122 FetchTexelFuncF Fetch3D;
123 StoreTexelFunc StoreTexel;
124 }
125 texfetch_funcs[MESA_FORMAT_COUNT] =
126 {
127 {
128 MESA_FORMAT_NONE,
129 fetch_null_texelf,
130 fetch_null_texelf,
131 fetch_null_texelf,
132 store_null_texel
133 },
134
135 {
136 MESA_FORMAT_RGBA8888,
137 fetch_texel_1d_f_rgba8888,
138 fetch_texel_2d_f_rgba8888,
139 fetch_texel_3d_f_rgba8888,
140 store_texel_rgba8888
141 },
142 {
143 MESA_FORMAT_RGBA8888_REV,
144 fetch_texel_1d_f_rgba8888_rev,
145 fetch_texel_2d_f_rgba8888_rev,
146 fetch_texel_3d_f_rgba8888_rev,
147 store_texel_rgba8888_rev
148 },
149 {
150 MESA_FORMAT_ARGB8888,
151 fetch_texel_1d_f_argb8888,
152 fetch_texel_2d_f_argb8888,
153 fetch_texel_3d_f_argb8888,
154 store_texel_argb8888
155 },
156 {
157 MESA_FORMAT_ARGB8888_REV,
158 fetch_texel_1d_f_argb8888_rev,
159 fetch_texel_2d_f_argb8888_rev,
160 fetch_texel_3d_f_argb8888_rev,
161 store_texel_argb8888_rev
162 },
163 {
164 MESA_FORMAT_XRGB8888,
165 fetch_texel_1d_f_xrgb8888,
166 fetch_texel_2d_f_xrgb8888,
167 fetch_texel_3d_f_xrgb8888,
168 store_texel_xrgb8888
169 },
170 {
171 MESA_FORMAT_XRGB8888_REV,
172 fetch_texel_1d_f_xrgb8888_rev,
173 fetch_texel_2d_f_xrgb8888_rev,
174 fetch_texel_3d_f_xrgb8888_rev,
175 store_texel_xrgb8888_rev,
176 },
177 {
178 MESA_FORMAT_RGB888,
179 fetch_texel_1d_f_rgb888,
180 fetch_texel_2d_f_rgb888,
181 fetch_texel_3d_f_rgb888,
182 store_texel_rgb888
183 },
184 {
185 MESA_FORMAT_BGR888,
186 fetch_texel_1d_f_bgr888,
187 fetch_texel_2d_f_bgr888,
188 fetch_texel_3d_f_bgr888,
189 store_texel_bgr888
190 },
191 {
192 MESA_FORMAT_RGB565,
193 fetch_texel_1d_f_rgb565,
194 fetch_texel_2d_f_rgb565,
195 fetch_texel_3d_f_rgb565,
196 store_texel_rgb565
197 },
198 {
199 MESA_FORMAT_RGB565_REV,
200 fetch_texel_1d_f_rgb565_rev,
201 fetch_texel_2d_f_rgb565_rev,
202 fetch_texel_3d_f_rgb565_rev,
203 store_texel_rgb565_rev
204 },
205 {
206 MESA_FORMAT_ARGB4444,
207 fetch_texel_1d_f_argb4444,
208 fetch_texel_2d_f_argb4444,
209 fetch_texel_3d_f_argb4444,
210 store_texel_argb4444
211 },
212 {
213 MESA_FORMAT_ARGB4444_REV,
214 fetch_texel_1d_f_argb4444_rev,
215 fetch_texel_2d_f_argb4444_rev,
216 fetch_texel_3d_f_argb4444_rev,
217 store_texel_argb4444_rev
218 },
219 {
220 MESA_FORMAT_RGBA5551,
221 fetch_texel_1d_f_rgba5551,
222 fetch_texel_2d_f_rgba5551,
223 fetch_texel_3d_f_rgba5551,
224 store_texel_rgba5551
225 },
226 {
227 MESA_FORMAT_ARGB1555,
228 fetch_texel_1d_f_argb1555,
229 fetch_texel_2d_f_argb1555,
230 fetch_texel_3d_f_argb1555,
231 store_texel_argb1555
232 },
233 {
234 MESA_FORMAT_ARGB1555_REV,
235 fetch_texel_1d_f_argb1555_rev,
236 fetch_texel_2d_f_argb1555_rev,
237 fetch_texel_3d_f_argb1555_rev,
238 store_texel_argb1555_rev
239 },
240 {
241 MESA_FORMAT_AL88,
242 fetch_texel_1d_f_al88,
243 fetch_texel_2d_f_al88,
244 fetch_texel_3d_f_al88,
245 store_texel_al88
246 },
247 {
248 MESA_FORMAT_AL88_REV,
249 fetch_texel_1d_f_al88_rev,
250 fetch_texel_2d_f_al88_rev,
251 fetch_texel_3d_f_al88_rev,
252 store_texel_al88_rev
253 },
254 {
255 MESA_FORMAT_AL1616,
256 fetch_texel_1d_f_al1616,
257 fetch_texel_2d_f_al1616,
258 fetch_texel_3d_f_al1616,
259 store_texel_al1616
260 },
261 {
262 MESA_FORMAT_AL1616_REV,
263 fetch_texel_1d_f_al1616_rev,
264 fetch_texel_2d_f_al1616_rev,
265 fetch_texel_3d_f_al1616_rev,
266 store_texel_al1616_rev
267 },
268 {
269 MESA_FORMAT_RGB332,
270 fetch_texel_1d_f_rgb332,
271 fetch_texel_2d_f_rgb332,
272 fetch_texel_3d_f_rgb332,
273 store_texel_rgb332
274 },
275 {
276 MESA_FORMAT_A8,
277 fetch_texel_1d_f_a8,
278 fetch_texel_2d_f_a8,
279 fetch_texel_3d_f_a8,
280 store_texel_a8
281 },
282 {
283 MESA_FORMAT_L8,
284 fetch_texel_1d_f_l8,
285 fetch_texel_2d_f_l8,
286 fetch_texel_3d_f_l8,
287 store_texel_l8
288 },
289 {
290 MESA_FORMAT_I8,
291 fetch_texel_1d_f_i8,
292 fetch_texel_2d_f_i8,
293 fetch_texel_3d_f_i8,
294 store_texel_i8
295 },
296 {
297 MESA_FORMAT_CI8,
298 fetch_texel_1d_f_ci8,
299 fetch_texel_2d_f_ci8,
300 fetch_texel_3d_f_ci8,
301 store_texel_ci8
302 },
303 {
304 MESA_FORMAT_YCBCR,
305 fetch_texel_1d_f_ycbcr,
306 fetch_texel_2d_f_ycbcr,
307 fetch_texel_3d_f_ycbcr,
308 store_texel_ycbcr
309 },
310 {
311 MESA_FORMAT_YCBCR_REV,
312 fetch_texel_1d_f_ycbcr_rev,
313 fetch_texel_2d_f_ycbcr_rev,
314 fetch_texel_3d_f_ycbcr_rev,
315 store_texel_ycbcr_rev
316 },
317 {
318 MESA_FORMAT_Z24_S8,
319 fetch_texel_1d_f_z24_s8,
320 fetch_texel_2d_f_z24_s8,
321 fetch_texel_3d_f_z24_s8,
322 store_texel_z24_s8
323 },
324 {
325 MESA_FORMAT_S8_Z24,
326 fetch_texel_1d_f_s8_z24,
327 fetch_texel_2d_f_s8_z24,
328 fetch_texel_3d_f_s8_z24,
329 store_texel_s8_z24
330 },
331 {
332 MESA_FORMAT_Z16,
333 fetch_texel_1d_f_z16,
334 fetch_texel_2d_f_z16,
335 fetch_texel_3d_f_z16,
336 store_texel_z16
337 },
338 {
339 MESA_FORMAT_X8_Z24,
340 fetch_texel_1d_f_s8_z24,
341 fetch_texel_2d_f_s8_z24,
342 fetch_texel_3d_f_s8_z24,
343 store_texel_s8_z24
344 },
345 {
346 MESA_FORMAT_Z24_X8,
347 fetch_texel_1d_f_z24_s8,
348 fetch_texel_2d_f_z24_s8,
349 fetch_texel_3d_f_z24_s8,
350 store_texel_z24_s8
351 },
352 {
353 MESA_FORMAT_Z32,
354 fetch_texel_1d_f_z32,
355 fetch_texel_2d_f_z32,
356 fetch_texel_3d_f_z32,
357 store_texel_z32
358 },
359 {
360 MESA_FORMAT_S8,
361 NULL,
362 NULL,
363 NULL,
364 NULL
365 },
366 {
367 MESA_FORMAT_SRGB8,
368 fetch_texel_1d_srgb8,
369 fetch_texel_2d_srgb8,
370 fetch_texel_3d_srgb8,
371 store_texel_srgb8
372 },
373 {
374 MESA_FORMAT_SRGBA8,
375 fetch_texel_1d_srgba8,
376 fetch_texel_2d_srgba8,
377 fetch_texel_3d_srgba8,
378 store_texel_srgba8
379 },
380 {
381 MESA_FORMAT_SARGB8,
382 fetch_texel_1d_sargb8,
383 fetch_texel_2d_sargb8,
384 fetch_texel_3d_sargb8,
385 store_texel_sargb8
386 },
387 {
388 MESA_FORMAT_SL8,
389 fetch_texel_1d_sl8,
390 fetch_texel_2d_sl8,
391 fetch_texel_3d_sl8,
392 store_texel_sl8
393 },
394 {
395 MESA_FORMAT_SLA8,
396 fetch_texel_1d_sla8,
397 fetch_texel_2d_sla8,
398 fetch_texel_3d_sla8,
399 store_texel_sla8
400 },
401 {
402 MESA_FORMAT_SRGB_DXT1,
403 NULL,
404 _mesa_fetch_texel_2d_f_srgb_dxt1,
405 NULL,
406 NULL
407 },
408 {
409 MESA_FORMAT_SRGBA_DXT1,
410 NULL,
411 _mesa_fetch_texel_2d_f_srgba_dxt1,
412 NULL,
413 NULL
414 },
415 {
416 MESA_FORMAT_SRGBA_DXT3,
417 NULL,
418 _mesa_fetch_texel_2d_f_srgba_dxt3,
419 NULL,
420 NULL
421 },
422 {
423 MESA_FORMAT_SRGBA_DXT5,
424 NULL,
425 _mesa_fetch_texel_2d_f_srgba_dxt5,
426 NULL,
427 NULL
428 },
429
430 {
431 MESA_FORMAT_RGB_FXT1,
432 NULL,
433 _mesa_fetch_texel_2d_f_rgb_fxt1,
434 NULL,
435 NULL
436 },
437 {
438 MESA_FORMAT_RGBA_FXT1,
439 NULL,
440 _mesa_fetch_texel_2d_f_rgba_fxt1,
441 NULL,
442 NULL
443 },
444 {
445 MESA_FORMAT_RGB_DXT1,
446 NULL,
447 _mesa_fetch_texel_2d_f_rgb_dxt1,
448 NULL,
449 NULL
450 },
451 {
452 MESA_FORMAT_RGBA_DXT1,
453 NULL,
454 _mesa_fetch_texel_2d_f_rgba_dxt1,
455 NULL,
456 NULL
457 },
458 {
459 MESA_FORMAT_RGBA_DXT3,
460 NULL,
461 _mesa_fetch_texel_2d_f_rgba_dxt3,
462 NULL,
463 NULL
464 },
465 {
466 MESA_FORMAT_RGBA_DXT5,
467 NULL,
468 _mesa_fetch_texel_2d_f_rgba_dxt5,
469 NULL,
470 NULL
471 },
472 {
473 MESA_FORMAT_RGBA_FLOAT32,
474 fetch_texel_1d_f_rgba_f32,
475 fetch_texel_2d_f_rgba_f32,
476 fetch_texel_3d_f_rgba_f32,
477 store_texel_rgba_f32
478 },
479 {
480 MESA_FORMAT_RGBA_FLOAT16,
481 fetch_texel_1d_f_rgba_f16,
482 fetch_texel_2d_f_rgba_f16,
483 fetch_texel_3d_f_rgba_f16,
484 store_texel_rgba_f16
485 },
486 {
487 MESA_FORMAT_RGB_FLOAT32,
488 fetch_texel_1d_f_rgb_f32,
489 fetch_texel_2d_f_rgb_f32,
490 fetch_texel_3d_f_rgb_f32,
491 store_texel_rgb_f32
492 },
493 {
494 MESA_FORMAT_RGB_FLOAT16,
495 fetch_texel_1d_f_rgb_f16,
496 fetch_texel_2d_f_rgb_f16,
497 fetch_texel_3d_f_rgb_f16,
498 store_texel_rgb_f16
499 },
500 {
501 MESA_FORMAT_ALPHA_FLOAT32,
502 fetch_texel_1d_f_alpha_f32,
503 fetch_texel_2d_f_alpha_f32,
504 fetch_texel_3d_f_alpha_f32,
505 store_texel_alpha_f32
506 },
507 {
508 MESA_FORMAT_ALPHA_FLOAT16,
509 fetch_texel_1d_f_alpha_f16,
510 fetch_texel_2d_f_alpha_f16,
511 fetch_texel_3d_f_alpha_f16,
512 store_texel_alpha_f16
513 },
514 {
515 MESA_FORMAT_LUMINANCE_FLOAT32,
516 fetch_texel_1d_f_luminance_f32,
517 fetch_texel_2d_f_luminance_f32,
518 fetch_texel_3d_f_luminance_f32,
519 store_texel_luminance_f32
520 },
521 {
522 MESA_FORMAT_LUMINANCE_FLOAT16,
523 fetch_texel_1d_f_luminance_f16,
524 fetch_texel_2d_f_luminance_f16,
525 fetch_texel_3d_f_luminance_f16,
526 store_texel_luminance_f16
527 },
528 {
529 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
530 fetch_texel_1d_f_luminance_alpha_f32,
531 fetch_texel_2d_f_luminance_alpha_f32,
532 fetch_texel_3d_f_luminance_alpha_f32,
533 store_texel_luminance_alpha_f32
534 },
535 {
536 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
537 fetch_texel_1d_f_luminance_alpha_f16,
538 fetch_texel_2d_f_luminance_alpha_f16,
539 fetch_texel_3d_f_luminance_alpha_f16,
540 store_texel_luminance_alpha_f16
541 },
542 {
543 MESA_FORMAT_INTENSITY_FLOAT32,
544 fetch_texel_1d_f_intensity_f32,
545 fetch_texel_2d_f_intensity_f32,
546 fetch_texel_3d_f_intensity_f32,
547 store_texel_intensity_f32
548 },
549 {
550 MESA_FORMAT_INTENSITY_FLOAT16,
551 fetch_texel_1d_f_intensity_f16,
552 fetch_texel_2d_f_intensity_f16,
553 fetch_texel_3d_f_intensity_f16,
554 store_texel_intensity_f16
555 },
556
557 /* non-normalized, signed int */
558 {
559 MESA_FORMAT_RGBA_INT8,
560 fetch_texel_1d_rgba_int8,
561 fetch_texel_2d_rgba_int8,
562 fetch_texel_3d_rgba_int8,
563 store_texel_rgba_int8
564 },
565 {
566 MESA_FORMAT_RGBA_INT16,
567 fetch_texel_1d_rgba_int16,
568 fetch_texel_2d_rgba_int16,
569 fetch_texel_3d_rgba_int16,
570 store_texel_rgba_int16
571 },
572 {
573 MESA_FORMAT_RGBA_INT32,
574 fetch_texel_1d_rgba_int32,
575 fetch_texel_2d_rgba_int32,
576 fetch_texel_3d_rgba_int32,
577 store_texel_rgba_int32
578 },
579
580 /* non-normalized, unsigned int */
581 {
582 MESA_FORMAT_RGBA_UINT8,
583 fetch_texel_1d_rgba_uint8,
584 fetch_texel_2d_rgba_uint8,
585 fetch_texel_3d_rgba_uint8,
586 store_texel_rgba_uint8
587 },
588 {
589 MESA_FORMAT_RGBA_UINT16,
590 fetch_texel_1d_rgba_uint16,
591 fetch_texel_2d_rgba_uint16,
592 fetch_texel_3d_rgba_uint16,
593 store_texel_rgba_uint16
594 },
595 {
596 MESA_FORMAT_RGBA_UINT32,
597 fetch_texel_1d_rgba_uint32,
598 fetch_texel_2d_rgba_uint32,
599 fetch_texel_3d_rgba_uint32,
600 store_texel_rgba_uint32
601 },
602
603 /* dudv */
604 {
605 MESA_FORMAT_DUDV8,
606 fetch_texel_1d_dudv8,
607 fetch_texel_2d_dudv8,
608 fetch_texel_3d_dudv8,
609 NULL
610 },
611
612 /* signed, normalized */
613 {
614 MESA_FORMAT_SIGNED_R8,
615 fetch_texel_1d_signed_r8,
616 fetch_texel_2d_signed_r8,
617 fetch_texel_3d_signed_r8,
618 store_texel_signed_r8
619 },
620 {
621 MESA_FORMAT_SIGNED_RG88,
622 fetch_texel_1d_signed_rg88,
623 fetch_texel_2d_signed_rg88,
624 fetch_texel_3d_signed_rg88,
625 store_texel_signed_rg88
626 },
627 {
628 MESA_FORMAT_SIGNED_RGBX8888,
629 fetch_texel_1d_signed_rgbx8888,
630 fetch_texel_2d_signed_rgbx8888,
631 fetch_texel_3d_signed_rgbx8888,
632 store_texel_signed_rgbx8888
633 },
634 {
635 MESA_FORMAT_SIGNED_RGBA8888,
636 fetch_texel_1d_signed_rgba8888,
637 fetch_texel_2d_signed_rgba8888,
638 fetch_texel_3d_signed_rgba8888,
639 store_texel_signed_rgba8888
640 },
641 {
642 MESA_FORMAT_SIGNED_RGBA8888_REV,
643 fetch_texel_1d_signed_rgba8888_rev,
644 fetch_texel_2d_signed_rgba8888_rev,
645 fetch_texel_3d_signed_rgba8888_rev,
646 store_texel_signed_rgba8888_rev
647 },
648 {
649 MESA_FORMAT_SIGNED_R_16,
650 fetch_texel_1d_signed_r_16,
651 fetch_texel_2d_signed_r_16,
652 fetch_texel_3d_signed_r_16,
653 store_texel_signed_r_16
654 },
655 {
656 MESA_FORMAT_SIGNED_RG_16,
657 fetch_texel_1d_signed_rg_16,
658 fetch_texel_2d_signed_rg_16,
659 fetch_texel_3d_signed_rg_16,
660 store_texel_signed_rg_16
661 },
662 {
663 MESA_FORMAT_SIGNED_RGB_16,
664 fetch_texel_1d_signed_rgb_16,
665 fetch_texel_2d_signed_rgb_16,
666 fetch_texel_3d_signed_rgb_16,
667 store_texel_signed_rgb_16
668 },
669 {
670 MESA_FORMAT_SIGNED_RGBA_16,
671 fetch_texel_1d_signed_rgba_16,
672 fetch_texel_2d_signed_rgba_16,
673 fetch_texel_3d_signed_rgba_16,
674 store_texel_signed_rgba_16
675 },
676 {
677 MESA_FORMAT_RGBA_16,
678 fetch_texel_1d_rgba_16,
679 fetch_texel_2d_rgba_16,
680 fetch_texel_3d_rgba_16,
681 store_texel_rgba_16
682 }
683 };
684
685
686 static FetchTexelFuncF
687 _mesa_get_texel_fetch_func(gl_format format, GLuint dims)
688 {
689 #ifdef DEBUG
690 /* check that the table entries are sorted by format name */
691 gl_format fmt;
692 for (fmt = 0; fmt < MESA_FORMAT_COUNT; fmt++) {
693 assert(texfetch_funcs[fmt].Name == fmt);
694 }
695 #endif
696
697 assert(Elements(texfetch_funcs) == MESA_FORMAT_COUNT);
698 assert(format < MESA_FORMAT_COUNT);
699
700 switch (dims) {
701 case 1:
702 return texfetch_funcs[format].Fetch1D;
703 case 2:
704 return texfetch_funcs[format].Fetch2D;
705 case 3:
706 return texfetch_funcs[format].Fetch3D;
707 default:
708 assert(0 && "bad dims in _mesa_get_texel_fetch_func");
709 return NULL;
710 }
711 }
712
713
714 StoreTexelFunc
715 _mesa_get_texel_store_func(gl_format format)
716 {
717 assert(format < MESA_FORMAT_COUNT);
718 return texfetch_funcs[format].StoreTexel;
719 }
720
721
722 /**
723 * Adaptor for fetching a GLchan texel from a float-valued texture.
724 */
725 static void
726 fetch_texel_float_to_chan(const struct gl_texture_image *texImage,
727 GLint i, GLint j, GLint k, GLchan *texelOut)
728 {
729 GLfloat temp[4];
730 GLenum baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
731
732 ASSERT(texImage->FetchTexelf);
733 texImage->FetchTexelf(texImage, i, j, k, temp);
734 if (baseFormat == GL_DEPTH_COMPONENT ||
735 baseFormat == GL_DEPTH_STENCIL_EXT) {
736 /* just one channel */
737 UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]);
738 }
739 else {
740 /* four channels */
741 UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]);
742 UNCLAMPED_FLOAT_TO_CHAN(texelOut[1], temp[1]);
743 UNCLAMPED_FLOAT_TO_CHAN(texelOut[2], temp[2]);
744 UNCLAMPED_FLOAT_TO_CHAN(texelOut[3], temp[3]);
745 }
746 }
747
748
749 #if 0
750 /**
751 * Adaptor for fetching a float texel from a GLchan-valued texture.
752 */
753 static void
754 fetch_texel_chan_to_float(const struct gl_texture_image *texImage,
755 GLint i, GLint j, GLint k, GLfloat *texelOut)
756 {
757 GLchan temp[4];
758 GLenum baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
759
760 ASSERT(texImage->FetchTexelc);
761 texImage->FetchTexelc(texImage, i, j, k, temp);
762 if (baseFormat == GL_DEPTH_COMPONENT ||
763 baseFormat == GL_DEPTH_STENCIL_EXT) {
764 /* just one channel */
765 texelOut[0] = CHAN_TO_FLOAT(temp[0]);
766 }
767 else {
768 /* four channels */
769 texelOut[0] = CHAN_TO_FLOAT(temp[0]);
770 texelOut[1] = CHAN_TO_FLOAT(temp[1]);
771 texelOut[2] = CHAN_TO_FLOAT(temp[2]);
772 texelOut[3] = CHAN_TO_FLOAT(temp[3]);
773 }
774 }
775 #endif
776
777
778 /**
779 * Initialize the texture image's FetchTexelc and FetchTexelf methods.
780 */
781 void
782 _mesa_set_fetch_functions(struct gl_texture_image *texImage, GLuint dims)
783 {
784 ASSERT(dims == 1 || dims == 2 || dims == 3);
785 ASSERT(texImage->TexFormat);
786
787 if (!texImage->FetchTexelf) {
788 texImage->FetchTexelf =
789 _mesa_get_texel_fetch_func(texImage->TexFormat, dims);
790 }
791
792 /* now check if we need to use a float/chan adaptor */
793 if (!texImage->FetchTexelc) {
794 texImage->FetchTexelc = fetch_texel_float_to_chan;
795 }
796
797 ASSERT(texImage->FetchTexelc);
798 ASSERT(texImage->FetchTexelf);
799 }