2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-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.
28 * \file texfetch_tmp.h
29 * Texel fetch functions template.
31 * This template file is used by texfetch.c to generate texel fetch functions
32 * for 1-D, 2-D and 3-D texture images.
34 * It should be expanded by defining \p DIM as the number texture dimensions
35 * (1, 2 or 3). According to the value of \p DIM a series of macros is defined
36 * for the texel lookup in the gl_texture_image::Data.
38 * \author Gareth Hughes
45 #define TEXEL_ADDR( type, image, i, j, k, size ) \
46 ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
48 #define FETCH(x) fetch_texel_1d_##x
52 #define TEXEL_ADDR( type, image, i, j, k, size ) \
54 ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
56 #define FETCH(x) fetch_texel_2d_##x
60 #define TEXEL_ADDR( type, image, i, j, k, size ) \
61 ((type *)(image)->Data + ((image)->ImageOffsets[k] \
62 + (image)->RowStride * (j) + (i)) * (size))
64 #define FETCH(x) fetch_texel_3d_##x
67 #error illegal number of texture dimensions
71 /* MESA_FORMAT_Z32 ***********************************************************/
73 /* Fetch depth texel from 1D, 2D or 3D 32-bit depth texture,
74 * returning 1 GLfloat.
75 * Note: no GLchan version of this function.
77 static void FETCH(f_z32)( const struct swrast_texture_image *texImage,
78 GLint i, GLint j, GLint k, GLfloat *texel )
80 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
81 texel[0] = src[0] * (1.0F / 0xffffffff);
85 static void store_texel_z32(struct swrast_texture_image *texImage,
86 GLint i, GLint j, GLint k, const void *texel)
88 const GLuint *depth = (const GLuint *) texel;
89 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
95 /* MESA_FORMAT_Z16 ***********************************************************/
97 /* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
98 * returning 1 GLfloat.
99 * Note: no GLchan version of this function.
101 static void FETCH(f_z16)(const struct swrast_texture_image *texImage,
102 GLint i, GLint j, GLint k, GLfloat *texel )
104 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
105 texel[0] = src[0] * (1.0F / 65535.0F);
109 static void store_texel_z16(struct swrast_texture_image *texImage,
110 GLint i, GLint j, GLint k, const void *texel)
112 const GLushort *depth = (const GLushort *) texel;
113 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
119 /* MESA_FORMAT_RGBA_F32 ******************************************************/
121 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
123 static void FETCH(f_rgba_f32)( const struct swrast_texture_image *texImage,
124 GLint i, GLint j, GLint k, GLfloat *texel )
126 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
127 texel[RCOMP] = src[0];
128 texel[GCOMP] = src[1];
129 texel[BCOMP] = src[2];
130 texel[ACOMP] = src[3];
134 static void store_texel_rgba_f32(struct swrast_texture_image *texImage,
135 GLint i, GLint j, GLint k, const void *texel)
137 const GLfloat *depth = (const GLfloat *) texel;
138 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
139 dst[0] = depth[RCOMP];
140 dst[1] = depth[GCOMP];
141 dst[2] = depth[BCOMP];
142 dst[3] = depth[ACOMP];
147 /* MESA_FORMAT_RGBA_F16 ******************************************************/
149 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
150 * returning 4 GLfloats.
152 static void FETCH(f_rgba_f16)( const struct swrast_texture_image *texImage,
153 GLint i, GLint j, GLint k, GLfloat *texel )
155 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
156 texel[RCOMP] = _mesa_half_to_float(src[0]);
157 texel[GCOMP] = _mesa_half_to_float(src[1]);
158 texel[BCOMP] = _mesa_half_to_float(src[2]);
159 texel[ACOMP] = _mesa_half_to_float(src[3]);
163 static void store_texel_rgba_f16(struct swrast_texture_image *texImage,
164 GLint i, GLint j, GLint k, const void *texel)
166 const GLfloat *src = (const GLfloat *) texel;
167 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
168 dst[0] = _mesa_float_to_half(src[RCOMP]);
169 dst[1] = _mesa_float_to_half(src[GCOMP]);
170 dst[2] = _mesa_float_to_half(src[BCOMP]);
171 dst[3] = _mesa_float_to_half(src[ACOMP]);
175 /* MESA_FORMAT_RGB_F32 *******************************************************/
177 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
178 * returning 4 GLfloats.
180 static void FETCH(f_rgb_f32)( const struct swrast_texture_image *texImage,
181 GLint i, GLint j, GLint k, GLfloat *texel )
183 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
184 texel[RCOMP] = src[0];
185 texel[GCOMP] = src[1];
186 texel[BCOMP] = src[2];
191 static void store_texel_rgb_f32(struct swrast_texture_image *texImage,
192 GLint i, GLint j, GLint k, const void *texel)
194 const GLfloat *src = (const GLfloat *) texel;
195 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
203 /* MESA_FORMAT_RGB_F16 *******************************************************/
205 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
206 * returning 4 GLfloats.
208 static void FETCH(f_rgb_f16)( const struct swrast_texture_image *texImage,
209 GLint i, GLint j, GLint k, GLfloat *texel )
211 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
212 texel[RCOMP] = _mesa_half_to_float(src[0]);
213 texel[GCOMP] = _mesa_half_to_float(src[1]);
214 texel[BCOMP] = _mesa_half_to_float(src[2]);
219 static void store_texel_rgb_f16(struct swrast_texture_image *texImage,
220 GLint i, GLint j, GLint k, const void *texel)
222 const GLfloat *src = (const GLfloat *) texel;
223 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
224 dst[0] = _mesa_float_to_half(src[RCOMP]);
225 dst[1] = _mesa_float_to_half(src[GCOMP]);
226 dst[2] = _mesa_float_to_half(src[BCOMP]);
231 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
233 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
234 * returning 4 GLfloats.
236 static void FETCH(f_alpha_f32)( const struct swrast_texture_image *texImage,
237 GLint i, GLint j, GLint k, GLfloat *texel )
239 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
243 texel[ACOMP] = src[0];
247 static void store_texel_alpha_f32(struct swrast_texture_image *texImage,
248 GLint i, GLint j, GLint k, const void *texel)
250 const GLfloat *rgba = (const GLfloat *) texel;
251 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
252 dst[0] = rgba[ACOMP];
257 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
259 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
260 * returning 4 GLfloats.
262 static void FETCH(f_alpha_f16)( const struct swrast_texture_image *texImage,
263 GLint i, GLint j, GLint k, GLfloat *texel )
265 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
269 texel[ACOMP] = _mesa_half_to_float(src[0]);
273 static void store_texel_alpha_f16(struct swrast_texture_image *texImage,
274 GLint i, GLint j, GLint k, const void *texel)
276 const GLfloat *rgba = (const GLfloat *) texel;
277 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
278 dst[0] = _mesa_float_to_half(rgba[ACOMP]);
283 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
285 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
286 * returning 4 GLfloats.
288 static void FETCH(f_luminance_f32)( const struct swrast_texture_image *texImage,
289 GLint i, GLint j, GLint k, GLfloat *texel )
291 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
294 texel[BCOMP] = src[0];
299 static void store_texel_luminance_f32(struct swrast_texture_image *texImage,
300 GLint i, GLint j, GLint k, const void *texel)
302 const GLfloat *rgba = (const GLfloat *) texel;
303 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
304 dst[0] = rgba[RCOMP];
309 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
311 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
312 * returning 4 GLfloats.
314 static void FETCH(f_luminance_f16)( const struct swrast_texture_image *texImage,
315 GLint i, GLint j, GLint k, GLfloat *texel )
317 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
320 texel[BCOMP] = _mesa_half_to_float(src[0]);
325 static void store_texel_luminance_f16(struct swrast_texture_image *texImage,
326 GLint i, GLint j, GLint k, const void *texel)
328 const GLfloat *rgba = (const GLfloat *) texel;
329 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
330 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
335 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
337 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
338 * returning 4 GLfloats.
340 static void FETCH(f_luminance_alpha_f32)( const struct swrast_texture_image *texImage,
341 GLint i, GLint j, GLint k, GLfloat *texel )
343 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
346 texel[BCOMP] = src[0];
347 texel[ACOMP] = src[1];
351 static void store_texel_luminance_alpha_f32(struct swrast_texture_image *texImage,
352 GLint i, GLint j, GLint k, const void *texel)
354 const GLfloat *rgba = (const GLfloat *) texel;
355 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
356 dst[0] = rgba[RCOMP];
357 dst[1] = rgba[ACOMP];
362 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
364 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
365 * returning 4 GLfloats.
367 static void FETCH(f_luminance_alpha_f16)( const struct swrast_texture_image *texImage,
368 GLint i, GLint j, GLint k, GLfloat *texel )
370 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
373 texel[BCOMP] = _mesa_half_to_float(src[0]);
374 texel[ACOMP] = _mesa_half_to_float(src[1]);
378 static void store_texel_luminance_alpha_f16(struct swrast_texture_image *texImage,
379 GLint i, GLint j, GLint k, const void *texel)
381 const GLfloat *rgba = (const GLfloat *) texel;
382 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
383 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
384 dst[1] = _mesa_float_to_half(rgba[ACOMP]);
389 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
391 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
392 * returning 4 GLfloats.
394 static void FETCH(f_intensity_f32)( const struct swrast_texture_image *texImage,
395 GLint i, GLint j, GLint k, GLfloat *texel )
397 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
401 texel[ACOMP] = src[0];
405 static void store_texel_intensity_f32(struct swrast_texture_image *texImage,
406 GLint i, GLint j, GLint k, const void *texel)
408 const GLfloat *rgba = (const GLfloat *) texel;
409 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
410 dst[0] = rgba[RCOMP];
415 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
417 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
418 * returning 4 GLfloats.
420 static void FETCH(f_intensity_f16)( const struct swrast_texture_image *texImage,
421 GLint i, GLint j, GLint k, GLfloat *texel )
423 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
427 texel[ACOMP] = _mesa_half_to_float(src[0]);
431 static void store_texel_intensity_f16(struct swrast_texture_image *texImage,
432 GLint i, GLint j, GLint k, const void *texel)
434 const GLfloat *rgba = (const GLfloat *) texel;
435 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
436 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
441 /* MESA_FORMAT_R_FLOAT32 *****************************************************/
443 /* Fetch texel from 1D, 2D or 3D R_FLOAT32 texture,
444 * returning 4 GLfloats.
446 static void FETCH(f_r_f32)( const struct swrast_texture_image *texImage,
447 GLint i, GLint j, GLint k, GLfloat *texel )
449 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
450 texel[RCOMP] = src[0];
457 static void store_texel_r_f32(struct swrast_texture_image *texImage,
458 GLint i, GLint j, GLint k, const void *texel)
460 const GLfloat *rgba = (const GLfloat *) texel;
461 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
462 dst[0] = rgba[RCOMP];
467 /* MESA_FORMAT_R_FLOAT16 *****************************************************/
469 /* Fetch texel from 1D, 2D or 3D R_FLOAT16 texture,
470 * returning 4 GLfloats.
472 static void FETCH(f_r_f16)( const struct swrast_texture_image *texImage,
473 GLint i, GLint j, GLint k, GLfloat *texel )
475 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
476 texel[RCOMP] = _mesa_half_to_float(src[0]);
483 static void store_texel_r_f16(struct swrast_texture_image *texImage,
484 GLint i, GLint j, GLint k, const void *texel)
486 const GLfloat *rgba = (const GLfloat *) texel;
487 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
488 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
493 /* MESA_FORMAT_RG_FLOAT32 ****************************************************/
495 /* Fetch texel from 1D, 2D or 3D RG_FLOAT32 texture,
496 * returning 4 GLfloats.
498 static void FETCH(f_rg_f32)( const struct swrast_texture_image *texImage,
499 GLint i, GLint j, GLint k, GLfloat *texel )
501 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
502 texel[RCOMP] = src[0];
503 texel[GCOMP] = src[1];
509 static void store_texel_rg_f32(struct swrast_texture_image *texImage,
510 GLint i, GLint j, GLint k, const void *texel)
512 const GLfloat *rgba = (const GLfloat *) texel;
513 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
514 dst[0] = rgba[RCOMP];
515 dst[1] = rgba[GCOMP];
520 /* MESA_FORMAT_RG_FLOAT16 ****************************************************/
522 /* Fetch texel from 1D, 2D or 3D RG_FLOAT16 texture,
523 * returning 4 GLfloats.
525 static void FETCH(f_rg_f16)( const struct swrast_texture_image *texImage,
526 GLint i, GLint j, GLint k, GLfloat *texel )
528 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
529 texel[RCOMP] = _mesa_half_to_float(src[0]);
530 texel[GCOMP] = _mesa_half_to_float(src[1]);
536 static void store_texel_rg_f16(struct swrast_texture_image *texImage,
537 GLint i, GLint j, GLint k, const void *texel)
539 const GLfloat *rgba = (const GLfloat *) texel;
540 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
541 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
542 dst[1] = _mesa_float_to_half(rgba[GCOMP]);
548 * Begin Hardware formats
551 /* MESA_FORMAT_RGBA8888 ******************************************************/
553 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
554 static void FETCH(f_rgba8888)( const struct swrast_texture_image *texImage,
555 GLint i, GLint j, GLint k, GLfloat *texel )
557 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
558 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
559 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
560 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
561 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
567 static void store_texel_rgba8888(struct swrast_texture_image *texImage,
568 GLint i, GLint j, GLint k, const void *texel)
570 const GLubyte *rgba = (const GLubyte *) texel;
571 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
572 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
577 /* MESA_FORMAT_RGBA888_REV ***************************************************/
579 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
580 static void FETCH(f_rgba8888_rev)( const struct swrast_texture_image *texImage,
581 GLint i, GLint j, GLint k, GLfloat *texel )
583 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
584 texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
585 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
586 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
587 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
591 static void store_texel_rgba8888_rev(struct swrast_texture_image *texImage,
592 GLint i, GLint j, GLint k, const void *texel)
594 const GLubyte *rgba = (const GLubyte *) texel;
595 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
596 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
601 /* MESA_FORMAT_ARGB8888 ******************************************************/
603 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
604 static void FETCH(f_argb8888)( const struct swrast_texture_image *texImage,
605 GLint i, GLint j, GLint k, GLfloat *texel )
607 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
608 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
609 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
610 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
611 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
615 static void store_texel_argb8888(struct swrast_texture_image *texImage,
616 GLint i, GLint j, GLint k, const void *texel)
618 const GLubyte *rgba = (const GLubyte *) texel;
619 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
620 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
625 /* MESA_FORMAT_ARGB8888_REV **************************************************/
627 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
628 static void FETCH(f_argb8888_rev)( const struct swrast_texture_image *texImage,
629 GLint i, GLint j, GLint k, GLfloat *texel )
631 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
632 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
633 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
634 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
635 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
639 static void store_texel_argb8888_rev(struct swrast_texture_image *texImage,
640 GLint i, GLint j, GLint k, const void *texel)
642 const GLubyte *rgba = (const GLubyte *) texel;
643 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
644 *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], rgba[ACOMP]);
649 /* MESA_FORMAT_RGBX8888 ******************************************************/
651 /* Fetch texel from 1D, 2D or 3D rgbx8888 texture, return 4 GLfloats */
652 static void FETCH(f_rgbx8888)( const struct swrast_texture_image *texImage,
653 GLint i, GLint j, GLint k, GLfloat *texel )
655 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
656 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
657 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
658 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
663 static void store_texel_rgbx8888(struct swrast_texture_image *texImage,
664 GLint i, GLint j, GLint k, const void *texel)
666 const GLubyte *rgba = (const GLubyte *) texel;
667 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
668 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 0xff);
673 /* MESA_FORMAT_RGBX888_REV ***************************************************/
675 /* Fetch texel from 1D, 2D or 3D rgbx8888_rev texture, return 4 GLchans */
676 static void FETCH(f_rgbx8888_rev)( const struct swrast_texture_image *texImage,
677 GLint i, GLint j, GLint k, GLfloat *texel )
679 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
680 texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
681 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
682 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
687 static void store_texel_rgbx8888_rev(struct swrast_texture_image *texImage,
688 GLint i, GLint j, GLint k, const void *texel)
690 const GLubyte *rgba = (const GLubyte *) texel;
691 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
692 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 0xff);
697 /* MESA_FORMAT_XRGB8888 ******************************************************/
699 /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
700 static void FETCH(f_xrgb8888)( const struct swrast_texture_image *texImage,
701 GLint i, GLint j, GLint k, GLfloat *texel )
703 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
704 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
705 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
706 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
711 static void store_texel_xrgb8888(struct swrast_texture_image *texImage,
712 GLint i, GLint j, GLint k, const void *texel)
714 const GLubyte *rgba = (const GLubyte *) texel;
715 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
716 *dst = PACK_COLOR_8888(0xff, rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
721 /* MESA_FORMAT_XRGB8888_REV **************************************************/
723 /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
724 static void FETCH(f_xrgb8888_rev)( const struct swrast_texture_image *texImage,
725 GLint i, GLint j, GLint k, GLfloat *texel )
727 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
728 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
729 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
730 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
735 static void store_texel_xrgb8888_rev(struct swrast_texture_image *texImage,
736 GLint i, GLint j, GLint k, const void *texel)
738 const GLubyte *rgba = (const GLubyte *) texel;
739 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
740 *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], 0xff);
745 /* MESA_FORMAT_RGB888 ********************************************************/
747 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
748 static void FETCH(f_rgb888)( const struct swrast_texture_image *texImage,
749 GLint i, GLint j, GLint k, GLfloat *texel )
751 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
752 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
753 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
754 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
759 static void store_texel_rgb888(struct swrast_texture_image *texImage,
760 GLint i, GLint j, GLint k, const void *texel)
762 const GLubyte *rgba = (const GLubyte *) texel;
763 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
764 dst[0] = rgba[BCOMP];
765 dst[1] = rgba[GCOMP];
766 dst[2] = rgba[RCOMP];
771 /* MESA_FORMAT_BGR888 ********************************************************/
773 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
774 static void FETCH(f_bgr888)( const struct swrast_texture_image *texImage,
775 GLint i, GLint j, GLint k, GLfloat *texel )
777 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
778 texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
779 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
780 texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
785 static void store_texel_bgr888(struct swrast_texture_image *texImage,
786 GLint i, GLint j, GLint k, const void *texel)
788 const GLubyte *rgba = (const GLubyte *) texel;
789 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
790 dst[0] = rgba[RCOMP];
791 dst[1] = rgba[GCOMP];
792 dst[2] = rgba[BCOMP];
797 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
798 instead of slow (g << 2) * 255 / 252 (always rounds down) */
800 /* MESA_FORMAT_RGB565 ********************************************************/
802 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
803 static void FETCH(f_rgb565)( const struct swrast_texture_image *texImage,
804 GLint i, GLint j, GLint k, GLfloat *texel )
806 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
807 const GLushort s = *src;
808 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
809 texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
810 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
815 static void store_texel_rgb565(struct swrast_texture_image *texImage,
816 GLint i, GLint j, GLint k, const void *texel)
818 const GLubyte *rgba = (const GLubyte *) texel;
819 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
820 *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
825 /* MESA_FORMAT_RGB565_REV ****************************************************/
827 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
828 static void FETCH(f_rgb565_rev)( const struct swrast_texture_image *texImage,
829 GLint i, GLint j, GLint k, GLfloat *texel )
831 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
832 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
833 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
834 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
835 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
840 static void store_texel_rgb565_rev(struct swrast_texture_image *texImage,
841 GLint i, GLint j, GLint k, const void *texel)
843 const GLchan *rgba = (const GLchan *) texel;
844 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
845 GLushort p = PACK_COLOR_565(CHAN_TO_UBYTE(rgba[RCOMP]),
846 CHAN_TO_UBYTE(rgba[GCOMP]),
847 CHAN_TO_UBYTE(rgba[BCOMP]));
848 *dst = (p >> 8) | (p << 8); /* byte swap */
853 /* MESA_FORMAT_ARGB4444 ******************************************************/
855 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
856 static void FETCH(f_argb4444)( const struct swrast_texture_image *texImage,
857 GLint i, GLint j, GLint k, GLfloat *texel )
859 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
860 const GLushort s = *src;
861 texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
862 texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
863 texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
864 texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
868 static void store_texel_argb4444(struct swrast_texture_image *texImage,
869 GLint i, GLint j, GLint k, const void *texel)
871 const GLchan *rgba = (const GLchan *) texel;
872 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
873 *dst = PACK_COLOR_4444(CHAN_TO_UBYTE(rgba[ACOMP]),
874 CHAN_TO_UBYTE(rgba[RCOMP]),
875 CHAN_TO_UBYTE(rgba[GCOMP]),
876 CHAN_TO_UBYTE(rgba[BCOMP]));
881 /* MESA_FORMAT_ARGB4444_REV **************************************************/
883 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
884 static void FETCH(f_argb4444_rev)( const struct swrast_texture_image *texImage,
885 GLint i, GLint j, GLint k, GLfloat *texel )
887 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
888 texel[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
889 texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
890 texel[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
891 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
895 static void store_texel_argb4444_rev(struct swrast_texture_image *texImage,
896 GLint i, GLint j, GLint k, const void *texel)
898 const GLchan *rgba = (const GLchan *) texel;
899 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
900 *dst = PACK_COLOR_4444(CHAN_TO_UBYTE(rgba[GCOMP]),
901 CHAN_TO_UBYTE(rgba[BCOMP]),
902 CHAN_TO_UBYTE(rgba[ACOMP]),
903 CHAN_TO_UBYTE(rgba[RCOMP]));
907 /* MESA_FORMAT_RGBA5551 ******************************************************/
909 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
910 static void FETCH(f_rgba5551)( const struct swrast_texture_image *texImage,
911 GLint i, GLint j, GLint k, GLfloat *texel )
913 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
914 const GLushort s = *src;
915 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
916 texel[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
917 texel[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
918 texel[ACOMP] = ((s ) & 0x01) * 1.0F;
922 static void store_texel_rgba5551(struct swrast_texture_image *texImage,
923 GLint i, GLint j, GLint k, const void *texel)
925 const GLubyte *rgba = (const GLubyte *) texel;
926 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
927 *dst = PACK_COLOR_5551(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
931 /* MESA_FORMAT_ARGB1555 ******************************************************/
933 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
934 static void FETCH(f_argb1555)( const struct swrast_texture_image *texImage,
935 GLint i, GLint j, GLint k, GLfloat *texel )
937 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
938 const GLushort s = *src;
939 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
940 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
941 texel[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F);
942 texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
946 static void store_texel_argb1555(struct swrast_texture_image *texImage,
947 GLint i, GLint j, GLint k, const void *texel)
949 const GLubyte *rgba = (const GLubyte *) texel;
950 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
951 *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
956 /* MESA_FORMAT_ARGB1555_REV **************************************************/
958 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
959 static void FETCH(f_argb1555_rev)( const struct swrast_texture_image *texImage,
960 GLint i, GLint j, GLint k, GLfloat *texel )
962 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
963 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
964 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
965 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
966 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
967 texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
971 static void store_texel_argb1555_rev(struct swrast_texture_image *texImage,
972 GLint i, GLint j, GLint k, const void *texel)
974 const GLubyte *rgba = (const GLubyte *) texel;
975 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
976 *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
981 /* MESA_FORMAT_ARGB2101010 ***************************************************/
983 /* Fetch texel from 1D, 2D or 3D argb2101010 texture, return 4 GLchans */
984 static void FETCH(f_argb2101010)( const struct swrast_texture_image *texImage,
985 GLint i, GLint j, GLint k, GLfloat *texel )
987 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
988 const GLuint s = *src;
989 texel[RCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F);
990 texel[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F);
991 texel[BCOMP] = ((s >> 0) & 0x3ff) * (1.0F / 1023.0F);
992 texel[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F);
996 static void store_texel_argb2101010(struct swrast_texture_image *texImage,
997 GLint i, GLint j, GLint k, const void *texel)
999 const GLchan *rgba = (const GLchan *) texel;
1000 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1001 GLushort r = CHAN_TO_USHORT(rgba[RCOMP]);
1002 GLushort g = CHAN_TO_USHORT(rgba[GCOMP]);
1003 GLushort b = CHAN_TO_USHORT(rgba[BCOMP]);
1004 GLushort a = CHAN_TO_USHORT(rgba[ACOMP]);
1005 *dst = PACK_COLOR_2101010_US(a, r, g, b);
1010 /* MESA_FORMAT_GR88 **********************************************************/
1012 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
1013 static void FETCH(f_gr88)( const struct swrast_texture_image *texImage,
1014 GLint i, GLint j, GLint k, GLfloat *texel )
1016 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1017 texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
1018 texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
1024 static void store_texel_gr88(struct swrast_texture_image *texImage,
1025 GLint i, GLint j, GLint k, const void *texel)
1027 const GLchan *rgba = (const GLchan *) texel;
1028 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1029 GLubyte r = CHAN_TO_UBYTE(rgba[RCOMP]);
1030 GLubyte g = CHAN_TO_UBYTE(rgba[GCOMP]);
1031 *dst = PACK_COLOR_88(g, r);
1036 /* MESA_FORMAT_RG88 ******************************************************/
1038 /* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
1039 static void FETCH(f_rg88)( const struct swrast_texture_image *texImage,
1040 GLint i, GLint j, GLint k, GLfloat *texel )
1042 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1043 texel[RCOMP] = UBYTE_TO_FLOAT( s >> 8 );
1044 texel[GCOMP] = UBYTE_TO_FLOAT( s & 0xff );
1050 static void store_texel_rg88(struct swrast_texture_image *texImage,
1051 GLint i, GLint j, GLint k, const void *texel)
1053 const GLubyte *rgba = (const GLubyte *) texel;
1054 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1055 *dst = PACK_COLOR_88(rgba[RCOMP], rgba[GCOMP]);
1060 /* MESA_FORMAT_AL44 **********************************************************/
1062 /* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
1063 static void FETCH(f_al44)( const struct swrast_texture_image *texImage,
1064 GLint i, GLint j, GLint k, GLfloat *texel )
1066 const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1069 texel[BCOMP] = (s & 0xf) * (1.0F / 15.0F);
1070 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
1074 static void store_texel_al44(struct swrast_texture_image *texImage,
1075 GLint i, GLint j, GLint k, const void *texel)
1077 const GLubyte *rgba = (const GLubyte *) texel;
1078 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1079 *dst = PACK_COLOR_44(rgba[ACOMP], rgba[RCOMP]);
1084 /* MESA_FORMAT_AL88 **********************************************************/
1086 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
1087 static void FETCH(f_al88)( const struct swrast_texture_image *texImage,
1088 GLint i, GLint j, GLint k, GLfloat *texel )
1090 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1093 texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
1094 texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
1098 static void store_texel_al88(struct swrast_texture_image *texImage,
1099 GLint i, GLint j, GLint k, const void *texel)
1101 const GLubyte *rgba = (const GLubyte *) texel;
1102 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1103 *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
1108 /* MESA_FORMAT_R8 ************************************************************/
1110 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
1111 static void FETCH(f_r8)(const struct swrast_texture_image *texImage,
1112 GLint i, GLint j, GLint k, GLfloat *texel)
1114 const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1115 texel[RCOMP] = UBYTE_TO_FLOAT(s);
1122 static void store_texel_r8(struct swrast_texture_image *texImage,
1123 GLint i, GLint j, GLint k, const void *texel)
1125 const GLubyte *rgba = (const GLubyte *) texel;
1126 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1132 /* MESA_FORMAT_R16 ***********************************************************/
1134 /* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
1135 static void FETCH(f_r16)(const struct swrast_texture_image *texImage,
1136 GLint i, GLint j, GLint k, GLfloat *texel)
1138 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1139 texel[RCOMP] = USHORT_TO_FLOAT(s);
1146 static void store_texel_r16(struct swrast_texture_image *texImage,
1147 GLint i, GLint j, GLint k, const void *texel)
1149 const GLchan *rgba = (const GLchan *) texel;
1150 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1151 *dst = CHAN_TO_USHORT(rgba[RCOMP]);
1156 /* MESA_FORMAT_AL88_REV ******************************************************/
1158 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
1159 static void FETCH(f_al88_rev)( const struct swrast_texture_image *texImage,
1160 GLint i, GLint j, GLint k, GLfloat *texel )
1162 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1165 texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
1166 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
1170 static void store_texel_al88_rev(struct swrast_texture_image *texImage,
1171 GLint i, GLint j, GLint k, const void *texel)
1173 const GLubyte *rgba = (const GLubyte *) texel;
1174 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1175 *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
1180 /* MESA_FORMAT_RG1616 ********************************************************/
1182 /* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
1183 static void FETCH(f_rg1616)( const struct swrast_texture_image *texImage,
1184 GLint i, GLint j, GLint k, GLfloat *texel )
1186 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1187 texel[RCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1188 texel[GCOMP] = USHORT_TO_FLOAT( s >> 16 );
1194 static void store_texel_rg1616(struct swrast_texture_image *texImage,
1195 GLint i, GLint j, GLint k, const void *texel)
1197 const GLchan *rgba = (const GLchan *) texel;
1198 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1199 GLushort r = CHAN_TO_USHORT(rgba[RCOMP]);
1200 GLushort g = CHAN_TO_USHORT(rgba[GCOMP]);
1201 *dst = PACK_COLOR_1616(g, r);
1206 /* MESA_FORMAT_RG1616_REV ****************************************************/
1208 /* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
1209 static void FETCH(f_rg1616_rev)( const struct swrast_texture_image *texImage,
1210 GLint i, GLint j, GLint k, GLfloat *texel )
1212 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1213 texel[RCOMP] = USHORT_TO_FLOAT( s >> 16 );
1214 texel[GCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1220 static void store_texel_rg1616_rev(struct swrast_texture_image *texImage,
1221 GLint i, GLint j, GLint k, const void *texel)
1223 const GLubyte *rgba = (const GLubyte *) texel;
1224 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1225 *dst = PACK_COLOR_1616(rgba[GCOMP], rgba[RCOMP]);
1230 /* MESA_FORMAT_AL1616 ********************************************************/
1232 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
1233 static void FETCH(f_al1616)( const struct swrast_texture_image *texImage,
1234 GLint i, GLint j, GLint k, GLfloat *texel )
1236 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1239 texel[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1240 texel[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
1244 static void store_texel_al1616(struct swrast_texture_image *texImage,
1245 GLint i, GLint j, GLint k, const void *texel)
1247 const GLchan *rgba = (const GLchan *) texel;
1248 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1249 GLushort l = CHAN_TO_USHORT(rgba[RCOMP]);
1250 GLushort a = CHAN_TO_USHORT(rgba[ACOMP]);
1251 *dst = PACK_COLOR_1616(a, l);
1256 /* MESA_FORMAT_AL1616_REV ****************************************************/
1258 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
1259 static void FETCH(f_al1616_rev)( const struct swrast_texture_image *texImage,
1260 GLint i, GLint j, GLint k, GLfloat *texel )
1262 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1265 texel[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
1266 texel[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
1270 static void store_texel_al1616_rev(struct swrast_texture_image *texImage,
1271 GLint i, GLint j, GLint k, const void *texel)
1273 const GLushort *rgba = (const GLushort *) texel;
1274 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1275 *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[ACOMP]);
1280 /* MESA_FORMAT_RGB332 ********************************************************/
1282 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1283 static void FETCH(f_rgb332)( const struct swrast_texture_image *texImage,
1284 GLint i, GLint j, GLint k, GLfloat *texel )
1286 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1287 const GLubyte s = *src;
1288 texel[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
1289 texel[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
1290 texel[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F);
1291 texel[ACOMP] = 1.0F;
1295 static void store_texel_rgb332(struct swrast_texture_image *texImage,
1296 GLint i, GLint j, GLint k, const void *texel)
1298 const GLubyte *rgba = (const GLubyte *) texel;
1299 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1300 *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1305 /* MESA_FORMAT_A8 ************************************************************/
1307 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1308 static void FETCH(f_a8)( const struct swrast_texture_image *texImage,
1309 GLint i, GLint j, GLint k, GLfloat *texel )
1311 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1314 texel[BCOMP] = 0.0F;
1315 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1319 static void store_texel_a8(struct swrast_texture_image *texImage,
1320 GLint i, GLint j, GLint k, const void *texel)
1322 const GLubyte *rgba = (const GLubyte *) texel;
1323 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1329 /* MESA_FORMAT_A16 ************************************************************/
1331 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1332 static void FETCH(f_a16)( const struct swrast_texture_image *texImage,
1333 GLint i, GLint j, GLint k, GLfloat *texel )
1335 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1338 texel[BCOMP] = 0.0F;
1339 texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
1343 static void store_texel_a16(struct swrast_texture_image *texImage,
1344 GLint i, GLint j, GLint k, const void *texel)
1346 const GLchan *rgba = (const GLchan *) texel;
1347 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1348 *dst = CHAN_TO_USHORT(rgba[ACOMP]);
1353 /* MESA_FORMAT_L8 ************************************************************/
1355 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1356 static void FETCH(f_l8)( const struct swrast_texture_image *texImage,
1357 GLint i, GLint j, GLint k, GLfloat *texel )
1359 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1362 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
1363 texel[ACOMP] = 1.0F;
1367 static void store_texel_l8(struct swrast_texture_image *texImage,
1368 GLint i, GLint j, GLint k, const void *texel)
1370 const GLubyte *rgba = (const GLubyte *) texel;
1371 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1377 /* MESA_FORMAT_L16 ***********************************************************/
1379 /* Fetch texel from 1D, 2D or 3D l16 texture, return 4 GLchans */
1380 static void FETCH(f_l16)( const struct swrast_texture_image *texImage,
1381 GLint i, GLint j, GLint k, GLfloat *texel )
1383 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1386 texel[BCOMP] = USHORT_TO_FLOAT( src[0] );
1387 texel[ACOMP] = 1.0F;
1391 static void store_texel_l16(struct swrast_texture_image *texImage,
1392 GLint i, GLint j, GLint k, const void *texel)
1394 const GLchan *rgba = (const GLchan *) texel;
1395 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1396 *dst = CHAN_TO_USHORT(rgba[RCOMP]);
1401 /* MESA_FORMAT_I8 ************************************************************/
1403 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1404 static void FETCH(f_i8)( const struct swrast_texture_image *texImage,
1405 GLint i, GLint j, GLint k, GLfloat *texel )
1407 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1411 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1415 static void store_texel_i8(struct swrast_texture_image *texImage,
1416 GLint i, GLint j, GLint k, const void *texel)
1418 const GLubyte *rgba = (const GLubyte *) texel;
1419 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1425 /* MESA_FORMAT_I16 ***********************************************************/
1427 /* Fetch texel from 1D, 2D or 3D i16 texture, return 4 GLchans */
1428 static void FETCH(f_i16)( const struct swrast_texture_image *texImage,
1429 GLint i, GLint j, GLint k, GLfloat *texel )
1431 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1435 texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
1439 static void store_texel_i16(struct swrast_texture_image *texImage,
1440 GLint i, GLint j, GLint k, const void *texel)
1442 const GLchan *rgba = (const GLchan *) texel;
1443 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1444 *dst = CHAN_TO_USHORT(rgba[RCOMP]);
1449 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1450 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1451 static void FETCH(srgb8)(const struct swrast_texture_image *texImage,
1452 GLint i, GLint j, GLint k, GLfloat *texel )
1454 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1455 texel[RCOMP] = nonlinear_to_linear(src[2]);
1456 texel[GCOMP] = nonlinear_to_linear(src[1]);
1457 texel[BCOMP] = nonlinear_to_linear(src[0]);
1458 texel[ACOMP] = 1.0F;
1462 static void store_texel_srgb8(struct swrast_texture_image *texImage,
1463 GLint i, GLint j, GLint k, const void *texel)
1465 const GLubyte *rgba = (const GLubyte *) texel;
1466 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1467 dst[0] = rgba[BCOMP]; /* no conversion */
1468 dst[1] = rgba[GCOMP];
1469 dst[2] = rgba[RCOMP];
1473 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1474 static void FETCH(srgba8)(const struct swrast_texture_image *texImage,
1475 GLint i, GLint j, GLint k, GLfloat *texel )
1477 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1478 texel[RCOMP] = nonlinear_to_linear( (s >> 24) );
1479 texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1480 texel[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1481 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */
1485 static void store_texel_srgba8(struct swrast_texture_image *texImage,
1486 GLint i, GLint j, GLint k, const void *texel)
1488 const GLubyte *rgba = (const GLubyte *) texel;
1489 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1490 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1494 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1495 static void FETCH(sargb8)(const struct swrast_texture_image *texImage,
1496 GLint i, GLint j, GLint k, GLfloat *texel )
1498 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1499 texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1500 texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1501 texel[BCOMP] = nonlinear_to_linear( (s ) & 0xff );
1502 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
1506 static void store_texel_sargb8(struct swrast_texture_image *texImage,
1507 GLint i, GLint j, GLint k, const void *texel)
1509 const GLubyte *rgba = (const GLubyte *) texel;
1510 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1511 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1515 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1516 static void FETCH(sl8)(const struct swrast_texture_image *texImage,
1517 GLint i, GLint j, GLint k, GLfloat *texel )
1519 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1522 texel[BCOMP] = nonlinear_to_linear(src[0]);
1523 texel[ACOMP] = 1.0F;
1527 static void store_texel_sl8(struct swrast_texture_image *texImage,
1528 GLint i, GLint j, GLint k, const void *texel)
1530 const GLubyte *rgba = (const GLubyte *) texel;
1531 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1532 dst[0] = rgba[RCOMP];
1536 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1537 static void FETCH(sla8)(const struct swrast_texture_image *texImage,
1538 GLint i, GLint j, GLint k, GLfloat *texel )
1540 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1543 texel[BCOMP] = nonlinear_to_linear(src[0]);
1544 texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
1548 static void store_texel_sla8(struct swrast_texture_image *texImage,
1549 GLint i, GLint j, GLint k, const void *texel)
1551 const GLubyte *rgba = (const GLubyte *) texel;
1552 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1553 dst[0] = rgba[RCOMP];
1554 dst[1] = rgba[ACOMP];
1559 /* MESA_FORMAT_RGBA_INT8 **************************************************/
1562 FETCH(rgba_int8)(const struct swrast_texture_image *texImage,
1563 GLint i, GLint j, GLint k, GLfloat *texel )
1565 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
1566 texel[RCOMP] = (GLfloat) src[0];
1567 texel[GCOMP] = (GLfloat) src[1];
1568 texel[BCOMP] = (GLfloat) src[2];
1569 texel[ACOMP] = (GLfloat) src[3];
1574 store_texel_rgba_int8(struct swrast_texture_image *texImage,
1575 GLint i, GLint j, GLint k, const void *texel)
1577 const GLbyte *rgba = (const GLbyte *) texel;
1578 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
1579 dst[0] = rgba[RCOMP];
1580 dst[1] = rgba[GCOMP];
1581 dst[2] = rgba[BCOMP];
1582 dst[3] = rgba[ACOMP];
1587 /* MESA_FORMAT_RGBA_INT16 **************************************************/
1590 FETCH(rgba_int16)(const struct swrast_texture_image *texImage,
1591 GLint i, GLint j, GLint k, GLfloat *texel )
1593 const GLshort *src = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1594 texel[RCOMP] = (GLfloat) src[0];
1595 texel[GCOMP] = (GLfloat) src[1];
1596 texel[BCOMP] = (GLfloat) src[2];
1597 texel[ACOMP] = (GLfloat) src[3];
1602 store_texel_rgba_int16(struct swrast_texture_image *texImage,
1603 GLint i, GLint j, GLint k, const void *texel)
1605 const GLshort *rgba = (const GLshort *) texel;
1606 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1607 dst[0] = rgba[RCOMP];
1608 dst[1] = rgba[GCOMP];
1609 dst[2] = rgba[BCOMP];
1610 dst[3] = rgba[ACOMP];
1615 /* MESA_FORMAT_RGBA_INT32 **************************************************/
1618 FETCH(rgba_int32)(const struct swrast_texture_image *texImage,
1619 GLint i, GLint j, GLint k, GLfloat *texel )
1621 const GLint *src = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
1622 texel[RCOMP] = (GLfloat) src[0];
1623 texel[GCOMP] = (GLfloat) src[1];
1624 texel[BCOMP] = (GLfloat) src[2];
1625 texel[ACOMP] = (GLfloat) src[3];
1630 store_texel_rgba_int32(struct swrast_texture_image *texImage,
1631 GLint i, GLint j, GLint k, const void *texel)
1633 const GLint *rgba = (const GLint *) texel;
1634 GLint *dst = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
1635 dst[0] = rgba[RCOMP];
1636 dst[1] = rgba[GCOMP];
1637 dst[2] = rgba[BCOMP];
1638 dst[3] = rgba[ACOMP];
1643 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
1646 FETCH(rgba_uint8)(const struct swrast_texture_image *texImage,
1647 GLint i, GLint j, GLint k, GLfloat *texel )
1649 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1650 texel[RCOMP] = (GLfloat) src[0];
1651 texel[GCOMP] = (GLfloat) src[1];
1652 texel[BCOMP] = (GLfloat) src[2];
1653 texel[ACOMP] = (GLfloat) src[3];
1658 store_texel_rgba_uint8(struct swrast_texture_image *texImage,
1659 GLint i, GLint j, GLint k, const void *texel)
1661 const GLubyte *rgba = (const GLubyte *) texel;
1662 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1663 dst[0] = rgba[RCOMP];
1664 dst[1] = rgba[GCOMP];
1665 dst[2] = rgba[BCOMP];
1666 dst[3] = rgba[ACOMP];
1671 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
1674 FETCH(rgba_uint16)(const struct swrast_texture_image *texImage,
1675 GLint i, GLint j, GLint k, GLfloat *texel )
1677 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1678 texel[RCOMP] = (GLfloat) src[0];
1679 texel[GCOMP] = (GLfloat) src[1];
1680 texel[BCOMP] = (GLfloat) src[2];
1681 texel[ACOMP] = (GLfloat) src[3];
1686 store_texel_rgba_uint16(struct swrast_texture_image *texImage,
1687 GLint i, GLint j, GLint k, const void *texel)
1689 const GLushort *rgba = (const GLushort *) texel;
1690 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1691 dst[0] = rgba[RCOMP];
1692 dst[1] = rgba[GCOMP];
1693 dst[2] = rgba[BCOMP];
1694 dst[3] = rgba[ACOMP];
1699 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
1702 FETCH(rgba_uint32)(const struct swrast_texture_image *texImage,
1703 GLint i, GLint j, GLint k, GLfloat *texel )
1705 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
1706 texel[RCOMP] = (GLfloat) src[0];
1707 texel[GCOMP] = (GLfloat) src[1];
1708 texel[BCOMP] = (GLfloat) src[2];
1709 texel[ACOMP] = (GLfloat) src[3];
1714 store_texel_rgba_uint32(struct swrast_texture_image *texImage,
1715 GLint i, GLint j, GLint k, const void *texel)
1717 const GLuint *rgba = (const GLuint *) texel;
1718 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
1719 dst[0] = rgba[RCOMP];
1720 dst[1] = rgba[GCOMP];
1721 dst[2] = rgba[BCOMP];
1722 dst[3] = rgba[ACOMP];
1727 /* MESA_FORMAT_DUDV8 ********************************************************/
1729 /* this format by definition produces 0,0,0,1 as rgba values,
1730 however we'll return the dudv values as rg and fix up elsewhere */
1731 static void FETCH(dudv8)(const struct swrast_texture_image *texImage,
1732 GLint i, GLint j, GLint k, GLfloat *texel )
1734 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 2);
1735 texel[RCOMP] = BYTE_TO_FLOAT(src[0]);
1736 texel[GCOMP] = BYTE_TO_FLOAT(src[1]);
1742 /* MESA_FORMAT_SIGNED_R8 ***********************************************/
1744 static void FETCH(signed_r8)( const struct swrast_texture_image *texImage,
1745 GLint i, GLint j, GLint k, GLfloat *texel )
1747 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1748 texel[RCOMP] = BYTE_TO_FLOAT_TEX( s );
1749 texel[GCOMP] = 0.0F;
1750 texel[BCOMP] = 0.0F;
1751 texel[ACOMP] = 1.0F;
1755 static void store_texel_signed_r8(struct swrast_texture_image *texImage,
1756 GLint i, GLint j, GLint k, const void *texel)
1758 const GLbyte *rgba = (const GLbyte *) texel;
1759 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1765 /* MESA_FORMAT_SIGNED_A8 ***********************************************/
1767 static void FETCH(signed_a8)( const struct swrast_texture_image *texImage,
1768 GLint i, GLint j, GLint k, GLfloat *texel )
1770 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1771 texel[RCOMP] = 0.0F;
1772 texel[GCOMP] = 0.0F;
1773 texel[BCOMP] = 0.0F;
1774 texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
1778 static void store_texel_signed_a8(struct swrast_texture_image *texImage,
1779 GLint i, GLint j, GLint k, const void *texel)
1781 const GLbyte *rgba = (const GLbyte *) texel;
1782 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1788 /* MESA_FORMAT_SIGNED_L8 ***********************************************/
1790 static void FETCH(signed_l8)( const struct swrast_texture_image *texImage,
1791 GLint i, GLint j, GLint k, GLfloat *texel )
1793 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1796 texel[BCOMP] = BYTE_TO_FLOAT_TEX( s );
1797 texel[ACOMP] = 1.0F;
1801 static void store_texel_signed_l8(struct swrast_texture_image *texImage,
1802 GLint i, GLint j, GLint k, const void *texel)
1804 const GLbyte *rgba = (const GLbyte *) texel;
1805 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1811 /* MESA_FORMAT_SIGNED_I8 ***********************************************/
1813 static void FETCH(signed_i8)( const struct swrast_texture_image *texImage,
1814 GLint i, GLint j, GLint k, GLfloat *texel )
1816 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1820 texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
1824 static void store_texel_signed_i8(struct swrast_texture_image *texImage,
1825 GLint i, GLint j, GLint k, const void *texel)
1827 const GLbyte *rgba = (const GLbyte *) texel;
1828 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1834 /* MESA_FORMAT_SIGNED_RG88_REV ***********************************************/
1836 static void FETCH(signed_rg88_rev)( const struct swrast_texture_image *texImage,
1837 GLint i, GLint j, GLint k, GLfloat *texel )
1839 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1840 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
1841 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1842 texel[BCOMP] = 0.0F;
1843 texel[ACOMP] = 1.0F;
1847 static void store_texel_signed_rg88_rev(struct swrast_texture_image *texImage,
1848 GLint i, GLint j, GLint k, const void *texel)
1850 const GLbyte *rg = (const GLbyte *) texel;
1851 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1852 dst[0] = PACK_COLOR_88(rg[GCOMP], rg[RCOMP]);
1857 /* MESA_FORMAT_SIGNED_AL88 ***********************************************/
1859 static void FETCH(signed_al88)( const struct swrast_texture_image *texImage,
1860 GLint i, GLint j, GLint k, GLfloat *texel )
1862 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1865 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
1866 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1870 static void store_texel_signed_al88(struct swrast_texture_image *texImage,
1871 GLint i, GLint j, GLint k, const void *texel)
1873 const GLbyte *rg = (const GLbyte *) texel;
1874 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1875 dst[0] = PACK_COLOR_88(rg[ACOMP], rg[RCOMP]);
1880 /* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
1882 static void FETCH(signed_rgbx8888)( const struct swrast_texture_image *texImage,
1883 GLint i, GLint j, GLint k, GLfloat *texel )
1885 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1886 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1887 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1888 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1889 texel[ACOMP] = 1.0f;
1893 static void store_texel_signed_rgbx8888(struct swrast_texture_image *texImage,
1894 GLint i, GLint j, GLint k, const void *texel)
1896 const GLbyte *rgba = (const GLbyte *) texel;
1897 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1898 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 255);
1903 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1905 static void FETCH(signed_rgba8888)( const struct swrast_texture_image *texImage,
1906 GLint i, GLint j, GLint k, GLfloat *texel )
1908 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1909 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1910 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1911 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1912 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1916 static void store_texel_signed_rgba8888(struct swrast_texture_image *texImage,
1917 GLint i, GLint j, GLint k, const void *texel)
1919 const GLbyte *rgba = (const GLbyte *) texel;
1920 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1921 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1925 static void FETCH(signed_rgba8888_rev)( const struct swrast_texture_image *texImage,
1926 GLint i, GLint j, GLint k, GLfloat *texel )
1928 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1929 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1930 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1931 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1932 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1936 static void store_texel_signed_rgba8888_rev(struct swrast_texture_image *texImage,
1937 GLint i, GLint j, GLint k, const void *texel)
1939 const GLubyte *rgba = (const GLubyte *) texel;
1940 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1941 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1947 /* MESA_FORMAT_SIGNED_R16 ***********************************************/
1950 FETCH(signed_r16)(const struct swrast_texture_image *texImage,
1951 GLint i, GLint j, GLint k, GLfloat *texel)
1953 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1954 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s );
1955 texel[GCOMP] = 0.0F;
1956 texel[BCOMP] = 0.0F;
1957 texel[ACOMP] = 1.0F;
1962 store_texel_signed_r16(struct swrast_texture_image *texImage,
1963 GLint i, GLint j, GLint k, const void *texel)
1965 const GLshort *rgba = (const GLshort *) texel;
1966 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1972 /* MESA_FORMAT_SIGNED_A16 ***********************************************/
1975 FETCH(signed_a16)(const struct swrast_texture_image *texImage,
1976 GLint i, GLint j, GLint k, GLfloat *texel)
1978 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1979 texel[RCOMP] = 0.0F;
1980 texel[GCOMP] = 0.0F;
1981 texel[BCOMP] = 0.0F;
1982 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
1987 store_texel_signed_a16(struct swrast_texture_image *texImage,
1988 GLint i, GLint j, GLint k, const void *texel)
1990 const GLshort *rgba = (const GLshort *) texel;
1991 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1997 /* MESA_FORMAT_SIGNED_L16 ***********************************************/
2000 FETCH(signed_l16)(const struct swrast_texture_image *texImage,
2001 GLint i, GLint j, GLint k, GLfloat *texel)
2003 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
2006 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s );
2007 texel[ACOMP] = 1.0F;
2012 store_texel_signed_l16(struct swrast_texture_image *texImage,
2013 GLint i, GLint j, GLint k, const void *texel)
2015 const GLshort *rgba = (const GLshort *) texel;
2016 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
2022 /* MESA_FORMAT_SIGNED_I16 ***********************************************/
2025 FETCH(signed_i16)(const struct swrast_texture_image *texImage,
2026 GLint i, GLint j, GLint k, GLfloat *texel)
2028 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
2032 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
2037 store_texel_signed_i16(struct swrast_texture_image *texImage,
2038 GLint i, GLint j, GLint k, const void *texel)
2040 const GLshort *rgba = (const GLshort *) texel;
2041 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
2047 /* MESA_FORMAT_SIGNED_RG1616 ***********************************************/
2050 FETCH(signed_rg1616)(const struct swrast_texture_image *texImage,
2051 GLint i, GLint j, GLint k, GLfloat *texel)
2053 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2054 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2055 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2056 texel[BCOMP] = 0.0F;
2057 texel[ACOMP] = 1.0F;
2062 store_texel_signed_rg1616(struct swrast_texture_image *texImage,
2063 GLint i, GLint j, GLint k, const void *texel)
2065 const GLchan *rgba = (const GLchan *) texel;
2066 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2067 dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
2068 dst[1] = CHAN_TO_SHORT(rgba[GCOMP]);
2073 /* MESA_FORMAT_SIGNED_AL1616 ***********************************************/
2076 FETCH(signed_al1616)(const struct swrast_texture_image *texImage,
2077 GLint i, GLint j, GLint k, GLfloat *texel)
2079 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2082 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2083 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2088 store_texel_signed_al1616(struct swrast_texture_image *texImage,
2089 GLint i, GLint j, GLint k, const void *texel)
2091 const GLchan *rgba = (const GLchan *) texel;
2092 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2093 dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
2094 dst[1] = CHAN_TO_SHORT(rgba[ACOMP]);
2099 /* MESA_FORMAT_SIGNED_RGB_16 ***********************************************/
2102 FETCH(signed_rgb_16)(const struct swrast_texture_image *texImage,
2103 GLint i, GLint j, GLint k, GLfloat *texel)
2105 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
2106 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2107 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2108 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
2109 texel[ACOMP] = 1.0F;
2114 store_texel_signed_rgb_16(struct swrast_texture_image *texImage,
2115 GLint i, GLint j, GLint k, const void *texel)
2117 const GLchan *rgba = (const GLchan *) texel;
2118 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
2119 dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
2120 dst[1] = CHAN_TO_SHORT(rgba[GCOMP]);
2121 dst[2] = CHAN_TO_SHORT(rgba[BCOMP]);
2126 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
2129 FETCH(signed_rgba_16)(const struct swrast_texture_image *texImage,
2130 GLint i, GLint j, GLint k, GLfloat *texel)
2132 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
2133 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2134 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2135 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
2136 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
2141 store_texel_signed_rgba_16(struct swrast_texture_image *texImage,
2142 GLint i, GLint j, GLint k, const void *texel)
2144 const GLchan *rgba = (const GLchan *) texel;
2145 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
2146 dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
2147 dst[1] = CHAN_TO_SHORT(rgba[GCOMP]);
2148 dst[2] = CHAN_TO_SHORT(rgba[BCOMP]);
2149 dst[3] = CHAN_TO_SHORT(rgba[ACOMP]);
2155 /* MESA_FORMAT_RGBA_16 ***********************************************/
2158 FETCH(rgba_16)(const struct swrast_texture_image *texImage,
2159 GLint i, GLint j, GLint k, GLfloat *texel)
2161 const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
2162 texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
2163 texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
2164 texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
2165 texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
2170 store_texel_rgba_16(struct swrast_texture_image *texImage,
2171 GLint i, GLint j, GLint k, const void *texel)
2173 const GLchan *rgba = (const GLchan *) texel;
2174 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
2175 dst[0] = CHAN_TO_USHORT(rgba[RCOMP]);
2176 dst[1] = CHAN_TO_USHORT(rgba[GCOMP]);
2177 dst[2] = CHAN_TO_USHORT(rgba[BCOMP]);
2178 dst[3] = CHAN_TO_USHORT(rgba[ACOMP]);
2184 /* MESA_FORMAT_YCBCR *********************************************************/
2186 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
2187 * We convert YCbCr to RGB here.
2189 static void FETCH(f_ycbcr)( const struct swrast_texture_image *texImage,
2190 GLint i, GLint j, GLint k, GLfloat *texel )
2192 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
2193 const GLushort *src1 = src0 + 1; /* odd */
2194 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
2195 const GLubyte cb = *src0 & 0xff; /* chroma U */
2196 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
2197 const GLubyte cr = *src1 & 0xff; /* chroma V */
2198 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
2199 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
2200 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
2201 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
2202 r *= (1.0F / 255.0F);
2203 g *= (1.0F / 255.0F);
2204 b *= (1.0F / 255.0F);
2205 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
2206 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
2207 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
2208 texel[ACOMP] = 1.0F;
2212 static void store_texel_ycbcr(struct swrast_texture_image *texImage,
2213 GLint i, GLint j, GLint k, const void *texel)
2225 /* MESA_FORMAT_YCBCR_REV *****************************************************/
2227 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
2228 * We convert YCbCr to RGB here.
2230 static void FETCH(f_ycbcr_rev)( const struct swrast_texture_image *texImage,
2231 GLint i, GLint j, GLint k, GLfloat *texel )
2233 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
2234 const GLushort *src1 = src0 + 1; /* odd */
2235 const GLubyte y0 = *src0 & 0xff; /* luminance */
2236 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
2237 const GLubyte y1 = *src1 & 0xff; /* luminance */
2238 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
2239 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
2240 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
2241 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
2242 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
2243 r *= (1.0F / 255.0F);
2244 g *= (1.0F / 255.0F);
2245 b *= (1.0F / 255.0F);
2246 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
2247 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
2248 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
2249 texel[ACOMP] = 1.0F;
2253 static void store_texel_ycbcr_rev(struct swrast_texture_image *texImage,
2254 GLint i, GLint j, GLint k, const void *texel)
2266 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
2268 static void FETCH(f_z24_s8)( const struct swrast_texture_image *texImage,
2269 GLint i, GLint j, GLint k, GLfloat *texel )
2271 /* only return Z, not stencil data */
2272 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2273 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
2274 texel[0] = ((*src) >> 8) * scale;
2275 ASSERT(texImage->Base.TexFormat == MESA_FORMAT_Z24_S8 ||
2276 texImage->Base.TexFormat == MESA_FORMAT_Z24_X8);
2277 ASSERT(texel[0] >= 0.0F);
2278 ASSERT(texel[0] <= 1.0F);
2282 static void store_texel_z24_s8(struct swrast_texture_image *texImage,
2283 GLint i, GLint j, GLint k, const void *texel)
2285 /* only store Z, not stencil */
2286 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2287 GLfloat depth = *((GLfloat *) texel);
2288 GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
2289 *dst = zi | (*dst & 0xff);
2294 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
2296 static void FETCH(f_s8_z24)( const struct swrast_texture_image *texImage,
2297 GLint i, GLint j, GLint k, GLfloat *texel )
2299 /* only return Z, not stencil data */
2300 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2301 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
2302 texel[0] = ((*src) & 0x00ffffff) * scale;
2303 ASSERT(texImage->Base.TexFormat == MESA_FORMAT_S8_Z24 ||
2304 texImage->Base.TexFormat == MESA_FORMAT_X8_Z24);
2305 ASSERT(texel[0] >= 0.0F);
2306 ASSERT(texel[0] <= 1.0F);
2310 static void store_texel_s8_z24(struct swrast_texture_image *texImage,
2311 GLint i, GLint j, GLint k, const void *texel)
2313 /* only store Z, not stencil */
2314 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2315 GLfloat depth = *((GLfloat *) texel);
2316 GLuint zi = (GLuint) (depth * 0xffffff);
2317 *dst = zi | (*dst & 0xff000000);
2322 /* MESA_FORMAT_RGB9_E5 ******************************************************/
2324 static void FETCH(rgb9_e5)( const struct swrast_texture_image *texImage,
2325 GLint i, GLint j, GLint k, GLfloat *texel )
2327 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2328 rgb9e5_to_float3(*src, texel);
2329 texel[ACOMP] = 1.0F;
2333 static void store_texel_rgb9_e5(struct swrast_texture_image *texImage,
2334 GLint i, GLint j, GLint k, const void *texel)
2336 const GLfloat *src = (const GLfloat *) texel;
2337 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2338 *dst = float3_to_rgb9e5(src);
2343 /* MESA_FORMAT_R11_G11_B10_FLOAT *********************************************/
2345 static void FETCH(r11_g11_b10f)( const struct swrast_texture_image *texImage,
2346 GLint i, GLint j, GLint k, GLfloat *texel )
2348 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2349 r11g11b10f_to_float3(*src, texel);
2350 texel[ACOMP] = 1.0F;
2354 static void store_texel_r11_g11_b10f(struct swrast_texture_image *texImage,
2355 GLint i, GLint j, GLint k, const void *texel)
2357 const GLfloat *src = (const GLfloat *) texel;
2358 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2359 *dst = float3_to_r11g11b10f(src);
2364 /* MESA_FORMAT_Z32_FLOAT_X24S8 ***********************************************/
2366 static void FETCH(z32f_x24s8)(const struct swrast_texture_image *texImage,
2367 GLint i, GLint j, GLint k, GLfloat *texel)
2369 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
2370 texel[RCOMP] = src[0];
2371 texel[GCOMP] = 0.0F;
2372 texel[BCOMP] = 0.0F;
2373 texel[ACOMP] = 1.0F;
2377 static void store_texel_z32f_x24s8(struct swrast_texture_image *texImage,
2378 GLint i, GLint j, GLint k, const void *texel)
2380 const GLfloat *src = (const GLfloat *) texel;
2381 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);