da996b8a1003277ba5ff3a06f8cf4f6fcd21ac21
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 * Begin Hardware formats
317 /* MESA_FORMAT_RGBA8888 ******************************************************/
319 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
320 static void FETCH(f_rgba8888
)( const struct swrast_texture_image
*texImage
,
321 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
323 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
324 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
325 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
326 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
327 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
335 /* MESA_FORMAT_RGBA888_REV ***************************************************/
337 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
338 static void FETCH(f_rgba8888_rev
)( const struct swrast_texture_image
*texImage
,
339 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
341 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
342 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
343 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
344 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
345 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
351 /* MESA_FORMAT_ARGB8888 ******************************************************/
353 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
354 static void FETCH(f_argb8888
)( const struct swrast_texture_image
*texImage
,
355 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
357 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
358 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
359 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
360 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
361 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
367 /* MESA_FORMAT_ARGB8888_REV **************************************************/
369 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
370 static void FETCH(f_argb8888_rev
)( const struct swrast_texture_image
*texImage
,
371 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
373 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
374 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
375 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
376 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
377 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
383 /* MESA_FORMAT_RGBX8888 ******************************************************/
385 /* Fetch texel from 1D, 2D or 3D rgbx8888 texture, return 4 GLfloats */
386 static void FETCH(f_rgbx8888
)( const struct swrast_texture_image
*texImage
,
387 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
389 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
390 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
391 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
392 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
399 /* MESA_FORMAT_RGBX888_REV ***************************************************/
401 /* Fetch texel from 1D, 2D or 3D rgbx8888_rev texture, return 4 GLchans */
402 static void FETCH(f_rgbx8888_rev
)( const struct swrast_texture_image
*texImage
,
403 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
405 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
406 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
407 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
408 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
415 /* MESA_FORMAT_XRGB8888 ******************************************************/
417 /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
418 static void FETCH(f_xrgb8888
)( const struct swrast_texture_image
*texImage
,
419 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
421 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
422 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
423 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
424 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
431 /* MESA_FORMAT_XRGB8888_REV **************************************************/
433 /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
434 static void FETCH(f_xrgb8888_rev
)( const struct swrast_texture_image
*texImage
,
435 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
437 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
438 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
439 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
440 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
447 /* MESA_FORMAT_RGB888 ********************************************************/
449 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
450 static void FETCH(f_rgb888
)( const struct swrast_texture_image
*texImage
,
451 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
453 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
454 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
455 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
456 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
463 /* MESA_FORMAT_BGR888 ********************************************************/
465 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
466 static void FETCH(f_bgr888
)( const struct swrast_texture_image
*texImage
,
467 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
469 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
470 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[0] );
471 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
472 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[2] );
479 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
480 instead of slow (g << 2) * 255 / 252 (always rounds down) */
482 /* MESA_FORMAT_RGB565 ********************************************************/
484 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
485 static void FETCH(f_rgb565
)( const struct swrast_texture_image
*texImage
,
486 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
488 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
489 const GLushort s
= *src
;
490 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
491 texel
[GCOMP
] = ((s
>> 5 ) & 0x3f) * (1.0F
/ 63.0F
);
492 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
499 /* MESA_FORMAT_RGB565_REV ****************************************************/
501 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
502 static void FETCH(f_rgb565_rev
)( const struct swrast_texture_image
*texImage
,
503 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
505 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
506 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
507 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
508 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
509 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
516 /* MESA_FORMAT_ARGB4444 ******************************************************/
518 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
519 static void FETCH(f_argb4444
)( const struct swrast_texture_image
*texImage
,
520 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
522 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
523 const GLushort s
= *src
;
524 texel
[RCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
525 texel
[GCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
526 texel
[BCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
527 texel
[ACOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
533 /* MESA_FORMAT_ARGB4444_REV **************************************************/
535 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
536 static void FETCH(f_argb4444_rev
)( const struct swrast_texture_image
*texImage
,
537 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
539 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
540 texel
[RCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
541 texel
[GCOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
542 texel
[BCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
543 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
548 /* MESA_FORMAT_RGBA5551 ******************************************************/
550 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
551 static void FETCH(f_rgba5551
)( const struct swrast_texture_image
*texImage
,
552 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
554 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
555 const GLushort s
= *src
;
556 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
557 texel
[GCOMP
] = ((s
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
558 texel
[BCOMP
] = ((s
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
559 texel
[ACOMP
] = ((s
) & 0x01) * 1.0F
;
564 /* MESA_FORMAT_ARGB1555 ******************************************************/
566 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
567 static void FETCH(f_argb1555
)( const struct swrast_texture_image
*texImage
,
568 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
570 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
571 const GLushort s
= *src
;
572 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
573 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
574 texel
[BCOMP
] = ((s
>> 0) & 0x1f) * (1.0F
/ 31.0F
);
575 texel
[ACOMP
] = ((s
>> 15) & 0x01) * 1.0F
;
581 /* MESA_FORMAT_ARGB1555_REV **************************************************/
583 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
584 static void FETCH(f_argb1555_rev
)( const struct swrast_texture_image
*texImage
,
585 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
587 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
588 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
589 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
590 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
591 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
592 texel
[ACOMP
] = UBYTE_TO_FLOAT( ((s
>> 15) & 0x01) * 255 );
598 /* MESA_FORMAT_AL44 **********************************************************/
600 /* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
601 static void FETCH(f_al44
)( const struct swrast_texture_image
*texImage
,
602 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
604 const GLubyte s
= *TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
607 texel
[BCOMP
] = (s
& 0xf) * (1.0F
/ 15.0F
);
608 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
614 /* MESA_FORMAT_AL88 **********************************************************/
616 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
617 static void FETCH(f_al88
)( const struct swrast_texture_image
*texImage
,
618 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
620 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
623 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
624 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
630 /* MESA_FORMAT_AL88_REV ******************************************************/
632 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
633 static void FETCH(f_al88_rev
)( const struct swrast_texture_image
*texImage
,
634 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
636 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
639 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
640 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
646 /* MESA_FORMAT_AL1616 ********************************************************/
648 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
649 static void FETCH(f_al1616
)( const struct swrast_texture_image
*texImage
,
650 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
652 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
655 texel
[BCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
656 texel
[ACOMP
] = USHORT_TO_FLOAT( s
>> 16 );
662 /* MESA_FORMAT_AL1616_REV ****************************************************/
664 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
665 static void FETCH(f_al1616_rev
)( const struct swrast_texture_image
*texImage
,
666 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
668 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
671 texel
[BCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
672 texel
[ACOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
678 /* MESA_FORMAT_RGB332 ********************************************************/
680 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
681 static void FETCH(f_rgb332
)( const struct swrast_texture_image
*texImage
,
682 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
684 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
685 const GLubyte s
= *src
;
686 texel
[RCOMP
] = ((s
>> 5) & 0x7) * (1.0F
/ 7.0F
);
687 texel
[GCOMP
] = ((s
>> 2) & 0x7) * (1.0F
/ 7.0F
);
688 texel
[BCOMP
] = ((s
) & 0x3) * (1.0F
/ 3.0F
);
695 /* MESA_FORMAT_A8 ************************************************************/
697 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
698 static void FETCH(f_a8
)( const struct swrast_texture_image
*texImage
,
699 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
701 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
705 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
711 /* MESA_FORMAT_A16 ************************************************************/
713 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
714 static void FETCH(f_a16
)( const struct swrast_texture_image
*texImage
,
715 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
717 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
721 texel
[ACOMP
] = USHORT_TO_FLOAT( src
[0] );
727 /* MESA_FORMAT_L8 ************************************************************/
729 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
730 static void FETCH(f_l8
)( const struct swrast_texture_image
*texImage
,
731 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
733 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
736 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
743 /* MESA_FORMAT_L16 ***********************************************************/
745 /* Fetch texel from 1D, 2D or 3D l16 texture, return 4 GLchans */
746 static void FETCH(f_l16
)( const struct swrast_texture_image
*texImage
,
747 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
749 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
752 texel
[BCOMP
] = USHORT_TO_FLOAT( src
[0] );
759 /* MESA_FORMAT_I8 ************************************************************/
761 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
762 static void FETCH(f_i8
)( const struct swrast_texture_image
*texImage
,
763 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
765 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
769 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
775 /* MESA_FORMAT_I16 ***********************************************************/
777 /* Fetch texel from 1D, 2D or 3D i16 texture, return 4 GLchans */
778 static void FETCH(f_i16
)( const struct swrast_texture_image
*texImage
,
779 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
781 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
785 texel
[ACOMP
] = USHORT_TO_FLOAT( src
[0] );
789 /* MESA_FORMAT_RGBA_INT8 **************************************************/
792 FETCH(rgba_int8
)(const struct swrast_texture_image
*texImage
,
793 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
795 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 4);
796 texel
[RCOMP
] = (GLfloat
) src
[0];
797 texel
[GCOMP
] = (GLfloat
) src
[1];
798 texel
[BCOMP
] = (GLfloat
) src
[2];
799 texel
[ACOMP
] = (GLfloat
) src
[3];
805 /* MESA_FORMAT_RGBA_INT16 **************************************************/
808 FETCH(rgba_int16
)(const struct swrast_texture_image
*texImage
,
809 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
811 const GLshort
*src
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
812 texel
[RCOMP
] = (GLfloat
) src
[0];
813 texel
[GCOMP
] = (GLfloat
) src
[1];
814 texel
[BCOMP
] = (GLfloat
) src
[2];
815 texel
[ACOMP
] = (GLfloat
) src
[3];
821 /* MESA_FORMAT_RGBA_INT32 **************************************************/
824 FETCH(rgba_int32
)(const struct swrast_texture_image
*texImage
,
825 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
827 const GLint
*src
= TEXEL_ADDR(GLint
, texImage
, i
, j
, k
, 4);
828 texel
[RCOMP
] = (GLfloat
) src
[0];
829 texel
[GCOMP
] = (GLfloat
) src
[1];
830 texel
[BCOMP
] = (GLfloat
) src
[2];
831 texel
[ACOMP
] = (GLfloat
) src
[3];
837 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
840 FETCH(rgba_uint8
)(const struct swrast_texture_image
*texImage
,
841 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
843 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 4);
844 texel
[RCOMP
] = (GLfloat
) src
[0];
845 texel
[GCOMP
] = (GLfloat
) src
[1];
846 texel
[BCOMP
] = (GLfloat
) src
[2];
847 texel
[ACOMP
] = (GLfloat
) src
[3];
853 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
856 FETCH(rgba_uint16
)(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
, 4);
860 texel
[RCOMP
] = (GLfloat
) src
[0];
861 texel
[GCOMP
] = (GLfloat
) src
[1];
862 texel
[BCOMP
] = (GLfloat
) src
[2];
863 texel
[ACOMP
] = (GLfloat
) src
[3];
869 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
872 FETCH(rgba_uint32
)(const struct swrast_texture_image
*texImage
,
873 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
875 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 4);
876 texel
[RCOMP
] = (GLfloat
) src
[0];
877 texel
[GCOMP
] = (GLfloat
) src
[1];
878 texel
[BCOMP
] = (GLfloat
) src
[2];
879 texel
[ACOMP
] = (GLfloat
) src
[3];
884 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
887 FETCH(signed_rgba_16
)(const struct swrast_texture_image
*texImage
,
888 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
890 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
891 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
892 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
893 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
894 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
[3] );
901 /* MESA_FORMAT_RGBA_16 ***********************************************/
904 FETCH(rgba_16
)(const struct swrast_texture_image
*texImage
,
905 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
907 const GLushort
*s
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
908 texel
[RCOMP
] = USHORT_TO_FLOAT( s
[0] );
909 texel
[GCOMP
] = USHORT_TO_FLOAT( s
[1] );
910 texel
[BCOMP
] = USHORT_TO_FLOAT( s
[2] );
911 texel
[ACOMP
] = USHORT_TO_FLOAT( s
[3] );
918 /* MESA_FORMAT_YCBCR *********************************************************/
920 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
921 * We convert YCbCr to RGB here.
923 static void FETCH(f_ycbcr
)( const struct swrast_texture_image
*texImage
,
924 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
926 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
927 const GLushort
*src1
= src0
+ 1; /* odd */
928 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
929 const GLubyte cb
= *src0
& 0xff; /* chroma U */
930 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
931 const GLubyte cr
= *src1
& 0xff; /* chroma V */
932 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
933 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
934 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
935 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
936 r
*= (1.0F
/ 255.0F
);
937 g
*= (1.0F
/ 255.0F
);
938 b
*= (1.0F
/ 255.0F
);
939 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
940 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
941 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
948 /* MESA_FORMAT_YCBCR_REV *****************************************************/
950 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
951 * We convert YCbCr to RGB here.
953 static void FETCH(f_ycbcr_rev
)( const struct swrast_texture_image
*texImage
,
954 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
956 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
957 const GLushort
*src1
= src0
+ 1; /* odd */
958 const GLubyte y0
= *src0
& 0xff; /* luminance */
959 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
960 const GLubyte y1
= *src1
& 0xff; /* luminance */
961 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
962 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
963 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
964 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
965 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
966 r
*= (1.0F
/ 255.0F
);
967 g
*= (1.0F
/ 255.0F
);
968 b
*= (1.0F
/ 255.0F
);
969 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
970 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
971 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
978 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
980 static void FETCH(f_z24_s8
)( const struct swrast_texture_image
*texImage
,
981 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
983 /* only return Z, not stencil data */
984 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
985 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
986 texel
[0] = ((*src
) >> 8) * scale
;
987 ASSERT(texImage
->Base
.TexFormat
== MESA_FORMAT_Z24_S8
||
988 texImage
->Base
.TexFormat
== MESA_FORMAT_Z24_X8
);
989 ASSERT(texel
[0] >= 0.0F
);
990 ASSERT(texel
[0] <= 1.0F
);
996 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
998 static void FETCH(f_s8_z24
)( const struct swrast_texture_image
*texImage
,
999 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1001 /* only return Z, not stencil data */
1002 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1003 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
1004 texel
[0] = ((*src
) & 0x00ffffff) * scale
;
1005 ASSERT(texImage
->Base
.TexFormat
== MESA_FORMAT_S8_Z24
||
1006 texImage
->Base
.TexFormat
== MESA_FORMAT_X8_Z24
);
1007 ASSERT(texel
[0] >= 0.0F
);
1008 ASSERT(texel
[0] <= 1.0F
);