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)->Map + (i) * (size)))
48 #define FETCH(x) fetch_texel_1d_##x
52 #define TEXEL_ADDR( type, image, i, j, k, size ) \
54 ((type *)(image)->Map + ((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)->Map + ((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 /* MESA_FORMAT_Z16 ***********************************************************/
87 /* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
88 * returning 1 GLfloat.
89 * Note: no GLchan version of this function.
91 static void FETCH(f_z16
)(const struct swrast_texture_image
*texImage
,
92 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
94 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
95 texel
[0] = src
[0] * (1.0F
/ 65535.0F
);
100 /* MESA_FORMAT_RGBA_F32 ******************************************************/
102 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
104 static void FETCH(f_rgba_f32
)( const struct swrast_texture_image
*texImage
,
105 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
107 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 4);
108 texel
[RCOMP
] = src
[0];
109 texel
[GCOMP
] = src
[1];
110 texel
[BCOMP
] = src
[2];
111 texel
[ACOMP
] = src
[3];
117 /* MESA_FORMAT_RGBA_F16 ******************************************************/
119 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
120 * returning 4 GLfloats.
122 static void FETCH(f_rgba_f16
)( const struct swrast_texture_image
*texImage
,
123 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
125 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 4);
126 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
127 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
128 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
129 texel
[ACOMP
] = _mesa_half_to_float(src
[3]);
134 /* MESA_FORMAT_RGB_F32 *******************************************************/
136 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
137 * returning 4 GLfloats.
139 static void FETCH(f_rgb_f32
)( const struct swrast_texture_image
*texImage
,
140 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
142 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 3);
143 texel
[RCOMP
] = src
[0];
144 texel
[GCOMP
] = src
[1];
145 texel
[BCOMP
] = src
[2];
152 /* MESA_FORMAT_RGB_F16 *******************************************************/
154 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
155 * returning 4 GLfloats.
157 static void FETCH(f_rgb_f16
)( const struct swrast_texture_image
*texImage
,
158 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
160 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 3);
161 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
162 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
163 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
170 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
172 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
173 * returning 4 GLfloats.
175 static void FETCH(f_alpha_f32
)( const struct swrast_texture_image
*texImage
,
176 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
178 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
182 texel
[ACOMP
] = src
[0];
188 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
190 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
191 * returning 4 GLfloats.
193 static void FETCH(f_alpha_f16
)( const struct swrast_texture_image
*texImage
,
194 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
196 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
200 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
206 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
208 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
209 * returning 4 GLfloats.
211 static void FETCH(f_luminance_f32
)( const struct swrast_texture_image
*texImage
,
212 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
214 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
217 texel
[BCOMP
] = src
[0];
224 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
226 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
227 * returning 4 GLfloats.
229 static void FETCH(f_luminance_f16
)( const struct swrast_texture_image
*texImage
,
230 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
232 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
235 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
242 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
244 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
245 * returning 4 GLfloats.
247 static void FETCH(f_luminance_alpha_f32
)( const struct swrast_texture_image
*texImage
,
248 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
250 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
253 texel
[BCOMP
] = src
[0];
254 texel
[ACOMP
] = src
[1];
260 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
262 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
263 * returning 4 GLfloats.
265 static void FETCH(f_luminance_alpha_f16
)( const struct swrast_texture_image
*texImage
,
266 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
268 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
271 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
272 texel
[ACOMP
] = _mesa_half_to_float(src
[1]);
278 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
280 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
281 * returning 4 GLfloats.
283 static void FETCH(f_intensity_f32
)( const struct swrast_texture_image
*texImage
,
284 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
286 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
290 texel
[ACOMP
] = src
[0];
296 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
298 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
299 * returning 4 GLfloats.
301 static void FETCH(f_intensity_f16
)( const struct swrast_texture_image
*texImage
,
302 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
304 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
308 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
314 /* MESA_FORMAT_R_FLOAT32 *****************************************************/
316 /* Fetch texel from 1D, 2D or 3D R_FLOAT32 texture,
317 * returning 4 GLfloats.
319 static void FETCH(f_r_f32
)( const struct swrast_texture_image
*texImage
,
320 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
322 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
323 texel
[RCOMP
] = src
[0];
332 /* MESA_FORMAT_R_FLOAT16 *****************************************************/
334 /* Fetch texel from 1D, 2D or 3D R_FLOAT16 texture,
335 * returning 4 GLfloats.
337 static void FETCH(f_r_f16
)( const struct swrast_texture_image
*texImage
,
338 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
340 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
341 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
350 /* MESA_FORMAT_RG_FLOAT32 ****************************************************/
352 /* Fetch texel from 1D, 2D or 3D RG_FLOAT32 texture,
353 * returning 4 GLfloats.
355 static void FETCH(f_rg_f32
)( const struct swrast_texture_image
*texImage
,
356 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
358 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
359 texel
[RCOMP
] = src
[0];
360 texel
[GCOMP
] = src
[1];
368 /* MESA_FORMAT_RG_FLOAT16 ****************************************************/
370 /* Fetch texel from 1D, 2D or 3D RG_FLOAT16 texture,
371 * returning 4 GLfloats.
373 static void FETCH(f_rg_f16
)( const struct swrast_texture_image
*texImage
,
374 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
376 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
377 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
378 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
387 * Begin Hardware formats
390 /* MESA_FORMAT_RGBA8888 ******************************************************/
392 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
393 static void FETCH(f_rgba8888
)( const struct swrast_texture_image
*texImage
,
394 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
396 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
397 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
398 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
399 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
400 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
408 /* MESA_FORMAT_RGBA888_REV ***************************************************/
410 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
411 static void FETCH(f_rgba8888_rev
)( const struct swrast_texture_image
*texImage
,
412 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
414 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
415 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
416 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
417 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
418 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
424 /* MESA_FORMAT_ARGB8888 ******************************************************/
426 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
427 static void FETCH(f_argb8888
)( const struct swrast_texture_image
*texImage
,
428 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
430 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
431 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
432 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
433 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
434 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
440 /* MESA_FORMAT_ARGB8888_REV **************************************************/
442 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
443 static void FETCH(f_argb8888_rev
)( const struct swrast_texture_image
*texImage
,
444 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
446 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
447 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
448 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
449 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
450 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
456 /* MESA_FORMAT_RGBX8888 ******************************************************/
458 /* Fetch texel from 1D, 2D or 3D rgbx8888 texture, return 4 GLfloats */
459 static void FETCH(f_rgbx8888
)( const struct swrast_texture_image
*texImage
,
460 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
462 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
463 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
464 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
465 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
472 /* MESA_FORMAT_RGBX888_REV ***************************************************/
474 /* Fetch texel from 1D, 2D or 3D rgbx8888_rev texture, return 4 GLchans */
475 static void FETCH(f_rgbx8888_rev
)( const struct swrast_texture_image
*texImage
,
476 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
478 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
479 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
480 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
481 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
488 /* MESA_FORMAT_XRGB8888 ******************************************************/
490 /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
491 static void FETCH(f_xrgb8888
)( const struct swrast_texture_image
*texImage
,
492 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
494 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
495 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
496 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
497 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
504 /* MESA_FORMAT_XRGB8888_REV **************************************************/
506 /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
507 static void FETCH(f_xrgb8888_rev
)( const struct swrast_texture_image
*texImage
,
508 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
510 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
511 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
512 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
513 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
520 /* MESA_FORMAT_RGB888 ********************************************************/
522 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
523 static void FETCH(f_rgb888
)( const struct swrast_texture_image
*texImage
,
524 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
526 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
527 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
528 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
529 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
536 /* MESA_FORMAT_BGR888 ********************************************************/
538 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
539 static void FETCH(f_bgr888
)( const struct swrast_texture_image
*texImage
,
540 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
542 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
543 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[0] );
544 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
545 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[2] );
552 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
553 instead of slow (g << 2) * 255 / 252 (always rounds down) */
555 /* MESA_FORMAT_RGB565 ********************************************************/
557 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
558 static void FETCH(f_rgb565
)( const struct swrast_texture_image
*texImage
,
559 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
561 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
562 const GLushort s
= *src
;
563 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
564 texel
[GCOMP
] = ((s
>> 5 ) & 0x3f) * (1.0F
/ 63.0F
);
565 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
572 /* MESA_FORMAT_RGB565_REV ****************************************************/
574 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
575 static void FETCH(f_rgb565_rev
)( const struct swrast_texture_image
*texImage
,
576 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
578 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
579 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
580 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
581 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
582 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
589 /* MESA_FORMAT_ARGB4444 ******************************************************/
591 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
592 static void FETCH(f_argb4444
)( const struct swrast_texture_image
*texImage
,
593 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
595 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
596 const GLushort s
= *src
;
597 texel
[RCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
598 texel
[GCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
599 texel
[BCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
600 texel
[ACOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
606 /* MESA_FORMAT_ARGB4444_REV **************************************************/
608 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
609 static void FETCH(f_argb4444_rev
)( const struct swrast_texture_image
*texImage
,
610 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
612 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
613 texel
[RCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
614 texel
[GCOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
615 texel
[BCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
616 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
621 /* MESA_FORMAT_RGBA5551 ******************************************************/
623 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
624 static void FETCH(f_rgba5551
)( const struct swrast_texture_image
*texImage
,
625 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
627 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
628 const GLushort s
= *src
;
629 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
630 texel
[GCOMP
] = ((s
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
631 texel
[BCOMP
] = ((s
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
632 texel
[ACOMP
] = ((s
) & 0x01) * 1.0F
;
637 /* MESA_FORMAT_ARGB1555 ******************************************************/
639 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
640 static void FETCH(f_argb1555
)( const struct swrast_texture_image
*texImage
,
641 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
643 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
644 const GLushort s
= *src
;
645 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
646 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
647 texel
[BCOMP
] = ((s
>> 0) & 0x1f) * (1.0F
/ 31.0F
);
648 texel
[ACOMP
] = ((s
>> 15) & 0x01) * 1.0F
;
654 /* MESA_FORMAT_ARGB1555_REV **************************************************/
656 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
657 static void FETCH(f_argb1555_rev
)( const struct swrast_texture_image
*texImage
,
658 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
660 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
661 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
662 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
663 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
664 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
665 texel
[ACOMP
] = UBYTE_TO_FLOAT( ((s
>> 15) & 0x01) * 255 );
671 /* MESA_FORMAT_ARGB2101010 ***************************************************/
673 /* Fetch texel from 1D, 2D or 3D argb2101010 texture, return 4 GLchans */
674 static void FETCH(f_argb2101010
)( const struct swrast_texture_image
*texImage
,
675 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
677 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
678 const GLuint s
= *src
;
679 texel
[RCOMP
] = ((s
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
680 texel
[GCOMP
] = ((s
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
681 texel
[BCOMP
] = ((s
>> 0) & 0x3ff) * (1.0F
/ 1023.0F
);
682 texel
[ACOMP
] = ((s
>> 30) & 0x03) * (1.0F
/ 3.0F
);
688 /* MESA_FORMAT_GR88 **********************************************************/
690 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
691 static void FETCH(f_gr88
)( const struct swrast_texture_image
*texImage
,
692 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
694 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
695 texel
[RCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
696 texel
[GCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
704 /* MESA_FORMAT_RG88 ******************************************************/
706 /* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
707 static void FETCH(f_rg88
)( const struct swrast_texture_image
*texImage
,
708 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
710 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
711 texel
[RCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
712 texel
[GCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
720 /* MESA_FORMAT_AL44 **********************************************************/
722 /* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
723 static void FETCH(f_al44
)( const struct swrast_texture_image
*texImage
,
724 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
726 const GLubyte s
= *TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
729 texel
[BCOMP
] = (s
& 0xf) * (1.0F
/ 15.0F
);
730 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
736 /* MESA_FORMAT_AL88 **********************************************************/
738 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
739 static void FETCH(f_al88
)( const struct swrast_texture_image
*texImage
,
740 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
742 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
745 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
746 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
752 /* MESA_FORMAT_R8 ************************************************************/
754 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
755 static void FETCH(f_r8
)(const struct swrast_texture_image
*texImage
,
756 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
758 const GLubyte s
= *TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
759 texel
[RCOMP
] = UBYTE_TO_FLOAT(s
);
768 /* MESA_FORMAT_R16 ***********************************************************/
770 /* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
771 static void FETCH(f_r16
)(const struct swrast_texture_image
*texImage
,
772 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
774 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
775 texel
[RCOMP
] = USHORT_TO_FLOAT(s
);
784 /* MESA_FORMAT_AL88_REV ******************************************************/
786 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
787 static void FETCH(f_al88_rev
)( const struct swrast_texture_image
*texImage
,
788 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
790 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
793 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
794 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
800 /* MESA_FORMAT_GR1616 ********************************************************/
802 /* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
803 static void FETCH(f_rg1616
)( const struct swrast_texture_image
*texImage
,
804 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
806 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
807 texel
[RCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
808 texel
[GCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
816 /* MESA_FORMAT_RG1616 ****************************************************/
818 /* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
819 static void FETCH(f_rg1616_rev
)( const struct swrast_texture_image
*texImage
,
820 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
822 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
823 texel
[RCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
824 texel
[GCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
832 /* MESA_FORMAT_AL1616 ********************************************************/
834 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
835 static void FETCH(f_al1616
)( const struct swrast_texture_image
*texImage
,
836 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
838 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
841 texel
[BCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
842 texel
[ACOMP
] = USHORT_TO_FLOAT( s
>> 16 );
848 /* MESA_FORMAT_AL1616_REV ****************************************************/
850 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
851 static void FETCH(f_al1616_rev
)( const struct swrast_texture_image
*texImage
,
852 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
854 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
857 texel
[BCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
858 texel
[ACOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
864 /* MESA_FORMAT_RGB332 ********************************************************/
866 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
867 static void FETCH(f_rgb332
)( const struct swrast_texture_image
*texImage
,
868 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
870 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
871 const GLubyte s
= *src
;
872 texel
[RCOMP
] = ((s
>> 5) & 0x7) * (1.0F
/ 7.0F
);
873 texel
[GCOMP
] = ((s
>> 2) & 0x7) * (1.0F
/ 7.0F
);
874 texel
[BCOMP
] = ((s
) & 0x3) * (1.0F
/ 3.0F
);
881 /* MESA_FORMAT_A8 ************************************************************/
883 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
884 static void FETCH(f_a8
)( const struct swrast_texture_image
*texImage
,
885 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
887 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
891 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
897 /* MESA_FORMAT_A16 ************************************************************/
899 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
900 static void FETCH(f_a16
)( const struct swrast_texture_image
*texImage
,
901 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
903 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
907 texel
[ACOMP
] = USHORT_TO_FLOAT( src
[0] );
913 /* MESA_FORMAT_L8 ************************************************************/
915 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
916 static void FETCH(f_l8
)( const struct swrast_texture_image
*texImage
,
917 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
919 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
922 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
929 /* MESA_FORMAT_L16 ***********************************************************/
931 /* Fetch texel from 1D, 2D or 3D l16 texture, return 4 GLchans */
932 static void FETCH(f_l16
)( const struct swrast_texture_image
*texImage
,
933 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
935 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
938 texel
[BCOMP
] = USHORT_TO_FLOAT( src
[0] );
945 /* MESA_FORMAT_I8 ************************************************************/
947 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
948 static void FETCH(f_i8
)( const struct swrast_texture_image
*texImage
,
949 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
951 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
955 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
961 /* MESA_FORMAT_I16 ***********************************************************/
963 /* Fetch texel from 1D, 2D or 3D i16 texture, return 4 GLchans */
964 static void FETCH(f_i16
)( const struct swrast_texture_image
*texImage
,
965 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
967 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
971 texel
[ACOMP
] = USHORT_TO_FLOAT( src
[0] );
977 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
978 /* Note: component order is same as for MESA_FORMAT_RGB888 */
979 static void FETCH(srgb8
)(const struct swrast_texture_image
*texImage
,
980 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
982 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
983 texel
[RCOMP
] = nonlinear_to_linear(src
[2]);
984 texel
[GCOMP
] = nonlinear_to_linear(src
[1]);
985 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
991 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
992 static void FETCH(srgba8
)(const struct swrast_texture_image
*texImage
,
993 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
995 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
996 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 24) );
997 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
998 texel
[BCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
999 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff ); /* linear! */
1004 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1005 static void FETCH(sargb8
)(const struct swrast_texture_image
*texImage
,
1006 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1008 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1009 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1010 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1011 texel
[BCOMP
] = nonlinear_to_linear( (s
) & 0xff );
1012 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) ); /* linear! */
1017 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1018 static void FETCH(sl8
)(const struct swrast_texture_image
*texImage
,
1019 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1021 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1024 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1025 texel
[ACOMP
] = 1.0F
;
1030 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1031 static void FETCH(sla8
)(const struct swrast_texture_image
*texImage
,
1032 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1034 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1037 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1038 texel
[ACOMP
] = UBYTE_TO_FLOAT(src
[1]); /* linear */
1044 /* MESA_FORMAT_RGBA_INT8 **************************************************/
1047 FETCH(rgba_int8
)(const struct swrast_texture_image
*texImage
,
1048 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1050 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 4);
1051 texel
[RCOMP
] = (GLfloat
) src
[0];
1052 texel
[GCOMP
] = (GLfloat
) src
[1];
1053 texel
[BCOMP
] = (GLfloat
) src
[2];
1054 texel
[ACOMP
] = (GLfloat
) src
[3];
1060 /* MESA_FORMAT_RGBA_INT16 **************************************************/
1063 FETCH(rgba_int16
)(const struct swrast_texture_image
*texImage
,
1064 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1066 const GLshort
*src
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1067 texel
[RCOMP
] = (GLfloat
) src
[0];
1068 texel
[GCOMP
] = (GLfloat
) src
[1];
1069 texel
[BCOMP
] = (GLfloat
) src
[2];
1070 texel
[ACOMP
] = (GLfloat
) src
[3];
1076 /* MESA_FORMAT_RGBA_INT32 **************************************************/
1079 FETCH(rgba_int32
)(const struct swrast_texture_image
*texImage
,
1080 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1082 const GLint
*src
= TEXEL_ADDR(GLint
, texImage
, i
, j
, k
, 4);
1083 texel
[RCOMP
] = (GLfloat
) src
[0];
1084 texel
[GCOMP
] = (GLfloat
) src
[1];
1085 texel
[BCOMP
] = (GLfloat
) src
[2];
1086 texel
[ACOMP
] = (GLfloat
) src
[3];
1092 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
1095 FETCH(rgba_uint8
)(const struct swrast_texture_image
*texImage
,
1096 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1098 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 4);
1099 texel
[RCOMP
] = (GLfloat
) src
[0];
1100 texel
[GCOMP
] = (GLfloat
) src
[1];
1101 texel
[BCOMP
] = (GLfloat
) src
[2];
1102 texel
[ACOMP
] = (GLfloat
) src
[3];
1108 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
1111 FETCH(rgba_uint16
)(const struct swrast_texture_image
*texImage
,
1112 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1114 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1115 texel
[RCOMP
] = (GLfloat
) src
[0];
1116 texel
[GCOMP
] = (GLfloat
) src
[1];
1117 texel
[BCOMP
] = (GLfloat
) src
[2];
1118 texel
[ACOMP
] = (GLfloat
) src
[3];
1124 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
1127 FETCH(rgba_uint32
)(const struct swrast_texture_image
*texImage
,
1128 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1130 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 4);
1131 texel
[RCOMP
] = (GLfloat
) src
[0];
1132 texel
[GCOMP
] = (GLfloat
) src
[1];
1133 texel
[BCOMP
] = (GLfloat
) src
[2];
1134 texel
[ACOMP
] = (GLfloat
) src
[3];
1140 /* MESA_FORMAT_DUDV8 ********************************************************/
1142 /* this format by definition produces 0,0,0,1 as rgba values,
1143 however we'll return the dudv values as rg and fix up elsewhere */
1144 static void FETCH(dudv8
)(const struct swrast_texture_image
*texImage
,
1145 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1147 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 2);
1148 texel
[RCOMP
] = BYTE_TO_FLOAT(src
[0]);
1149 texel
[GCOMP
] = BYTE_TO_FLOAT(src
[1]);
1155 /* MESA_FORMAT_SIGNED_R8 ***********************************************/
1157 static void FETCH(signed_r8
)( const struct swrast_texture_image
*texImage
,
1158 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1160 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1161 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( s
);
1162 texel
[GCOMP
] = 0.0F
;
1163 texel
[BCOMP
] = 0.0F
;
1164 texel
[ACOMP
] = 1.0F
;
1170 /* MESA_FORMAT_SIGNED_A8 ***********************************************/
1172 static void FETCH(signed_a8
)( const struct swrast_texture_image
*texImage
,
1173 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1175 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1176 texel
[RCOMP
] = 0.0F
;
1177 texel
[GCOMP
] = 0.0F
;
1178 texel
[BCOMP
] = 0.0F
;
1179 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( s
);
1185 /* MESA_FORMAT_SIGNED_L8 ***********************************************/
1187 static void FETCH(signed_l8
)( const struct swrast_texture_image
*texImage
,
1188 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1190 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1193 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( s
);
1194 texel
[ACOMP
] = 1.0F
;
1200 /* MESA_FORMAT_SIGNED_I8 ***********************************************/
1202 static void FETCH(signed_i8
)( const struct swrast_texture_image
*texImage
,
1203 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1205 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1209 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( s
);
1215 /* MESA_FORMAT_SIGNED_RG88_REV ***********************************************/
1217 static void FETCH(signed_rg88_rev
)( const struct swrast_texture_image
*texImage
,
1218 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1220 const GLushort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1221 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
& 0xff) );
1222 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1223 texel
[BCOMP
] = 0.0F
;
1224 texel
[ACOMP
] = 1.0F
;
1230 /* MESA_FORMAT_SIGNED_AL88 ***********************************************/
1232 static void FETCH(signed_al88
)( const struct swrast_texture_image
*texImage
,
1233 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1235 const GLushort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1238 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
& 0xff) );
1239 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1245 /* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
1247 static void FETCH(signed_rgbx8888
)( const struct swrast_texture_image
*texImage
,
1248 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1250 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1251 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1252 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1253 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1254 texel
[ACOMP
] = 1.0f
;
1260 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1262 static void FETCH(signed_rgba8888
)( const struct swrast_texture_image
*texImage
,
1263 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1265 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1266 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1267 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1268 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1269 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
) );
1274 static void FETCH(signed_rgba8888_rev
)( const struct swrast_texture_image
*texImage
,
1275 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1277 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1278 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
) );
1279 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1280 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1281 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1288 /* MESA_FORMAT_SIGNED_R16 ***********************************************/
1291 FETCH(signed_r16
)(const struct swrast_texture_image
*texImage
,
1292 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1294 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1295 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
);
1296 texel
[GCOMP
] = 0.0F
;
1297 texel
[BCOMP
] = 0.0F
;
1298 texel
[ACOMP
] = 1.0F
;
1304 /* MESA_FORMAT_SIGNED_A16 ***********************************************/
1307 FETCH(signed_a16
)(const struct swrast_texture_image
*texImage
,
1308 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1310 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1311 texel
[RCOMP
] = 0.0F
;
1312 texel
[GCOMP
] = 0.0F
;
1313 texel
[BCOMP
] = 0.0F
;
1314 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
);
1320 /* MESA_FORMAT_SIGNED_L16 ***********************************************/
1323 FETCH(signed_l16
)(const struct swrast_texture_image
*texImage
,
1324 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1326 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1329 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
);
1330 texel
[ACOMP
] = 1.0F
;
1336 /* MESA_FORMAT_SIGNED_I16 ***********************************************/
1339 FETCH(signed_i16
)(const struct swrast_texture_image
*texImage
,
1340 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1342 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1346 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
);
1352 /* MESA_FORMAT_SIGNED_RG1616 ***********************************************/
1355 FETCH(signed_rg1616
)(const struct swrast_texture_image
*texImage
,
1356 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1358 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
1359 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1360 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1361 texel
[BCOMP
] = 0.0F
;
1362 texel
[ACOMP
] = 1.0F
;
1368 /* MESA_FORMAT_SIGNED_AL1616 ***********************************************/
1371 FETCH(signed_al1616
)(const struct swrast_texture_image
*texImage
,
1372 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1374 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
1377 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1378 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1384 /* MESA_FORMAT_SIGNED_RGB_16 ***********************************************/
1387 FETCH(signed_rgb_16
)(const struct swrast_texture_image
*texImage
,
1388 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1390 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 3);
1391 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1392 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1393 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
1394 texel
[ACOMP
] = 1.0F
;
1400 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
1403 FETCH(signed_rgba_16
)(const struct swrast_texture_image
*texImage
,
1404 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1406 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1407 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1408 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1409 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
1410 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
[3] );
1417 /* MESA_FORMAT_RGBA_16 ***********************************************/
1420 FETCH(rgba_16
)(const struct swrast_texture_image
*texImage
,
1421 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1423 const GLushort
*s
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1424 texel
[RCOMP
] = USHORT_TO_FLOAT( s
[0] );
1425 texel
[GCOMP
] = USHORT_TO_FLOAT( s
[1] );
1426 texel
[BCOMP
] = USHORT_TO_FLOAT( s
[2] );
1427 texel
[ACOMP
] = USHORT_TO_FLOAT( s
[3] );
1434 /* MESA_FORMAT_YCBCR *********************************************************/
1436 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
1437 * We convert YCbCr to RGB here.
1439 static void FETCH(f_ycbcr
)( const struct swrast_texture_image
*texImage
,
1440 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1442 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1443 const GLushort
*src1
= src0
+ 1; /* odd */
1444 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1445 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1446 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1447 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1448 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1449 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1450 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1451 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1452 r
*= (1.0F
/ 255.0F
);
1453 g
*= (1.0F
/ 255.0F
);
1454 b
*= (1.0F
/ 255.0F
);
1455 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1456 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1457 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1458 texel
[ACOMP
] = 1.0F
;
1464 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1466 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
1467 * We convert YCbCr to RGB here.
1469 static void FETCH(f_ycbcr_rev
)( const struct swrast_texture_image
*texImage
,
1470 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1472 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1473 const GLushort
*src1
= src0
+ 1; /* odd */
1474 const GLubyte y0
= *src0
& 0xff; /* luminance */
1475 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1476 const GLubyte y1
= *src1
& 0xff; /* luminance */
1477 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1478 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1479 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1480 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1481 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1482 r
*= (1.0F
/ 255.0F
);
1483 g
*= (1.0F
/ 255.0F
);
1484 b
*= (1.0F
/ 255.0F
);
1485 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1486 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1487 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1488 texel
[ACOMP
] = 1.0F
;
1494 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1496 static void FETCH(f_z24_s8
)( const struct swrast_texture_image
*texImage
,
1497 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1499 /* only return Z, not stencil data */
1500 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1501 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
1502 texel
[0] = ((*src
) >> 8) * scale
;
1503 ASSERT(texImage
->Base
.TexFormat
== MESA_FORMAT_Z24_S8
||
1504 texImage
->Base
.TexFormat
== MESA_FORMAT_Z24_X8
);
1505 ASSERT(texel
[0] >= 0.0F
);
1506 ASSERT(texel
[0] <= 1.0F
);
1512 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1514 static void FETCH(f_s8_z24
)( const struct swrast_texture_image
*texImage
,
1515 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1517 /* only return Z, not stencil data */
1518 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1519 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
1520 texel
[0] = ((*src
) & 0x00ffffff) * scale
;
1521 ASSERT(texImage
->Base
.TexFormat
== MESA_FORMAT_S8_Z24
||
1522 texImage
->Base
.TexFormat
== MESA_FORMAT_X8_Z24
);
1523 ASSERT(texel
[0] >= 0.0F
);
1524 ASSERT(texel
[0] <= 1.0F
);
1530 /* MESA_FORMAT_RGB9_E5 ******************************************************/
1532 static void FETCH(rgb9_e5
)( const struct swrast_texture_image
*texImage
,
1533 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1535 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1536 rgb9e5_to_float3(*src
, texel
);
1537 texel
[ACOMP
] = 1.0F
;
1543 /* MESA_FORMAT_R11_G11_B10_FLOAT *********************************************/
1545 static void FETCH(r11_g11_b10f
)( const struct swrast_texture_image
*texImage
,
1546 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1548 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1549 r11g11b10f_to_float3(*src
, texel
);
1550 texel
[ACOMP
] = 1.0F
;
1556 /* MESA_FORMAT_Z32_FLOAT_X24S8 ***********************************************/
1558 static void FETCH(z32f_x24s8
)(const struct swrast_texture_image
*texImage
,
1559 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1561 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
1562 texel
[RCOMP
] = src
[0];
1563 texel
[GCOMP
] = 0.0F
;
1564 texel
[BCOMP
] = 0.0F
;
1565 texel
[ACOMP
] = 1.0F
;