2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (c) 2008-2009 VMware, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * 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)->ImageSlices[0] + (i) * (size)))
48 #define FETCH(x) fetch_texel_1d_##x
52 #define TEXEL_ADDR( type, image, i, j, k, size ) \
54 ((type *)((GLubyte *) (image)->ImageSlices[0] + (image)->RowStride * (j)) + \
57 #define FETCH(x) fetch_texel_2d_##x
61 #define TEXEL_ADDR( type, image, i, j, k, size ) \
62 ((type *)((GLubyte *) (image)->ImageSlices[k] + \
63 (image)->RowStride * (j)) + (i) * (size))
65 #define FETCH(x) fetch_texel_3d_##x
68 #error illegal number of texture dimensions
72 /* MESA_FORMAT_Z_UNORM32 ***********************************************************/
74 /* Fetch depth texel from 1D, 2D or 3D 32-bit depth texture,
75 * returning 1 GLfloat.
76 * Note: no GLchan version of this function.
78 static void FETCH(f_z32
)( const struct swrast_texture_image
*texImage
,
79 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
81 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
82 texel
[0] = src
[0] * (1.0F
/ 0xffffffff);
86 /* MESA_FORMAT_Z_UNORM16 ***********************************************************/
88 /* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
89 * returning 1 GLfloat.
90 * Note: no GLchan version of this function.
92 static void FETCH(f_z16
)(const struct swrast_texture_image
*texImage
,
93 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
95 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
96 texel
[0] = src
[0] * (1.0F
/ 65535.0F
);
101 /* MESA_FORMAT_RGBA_F32 ******************************************************/
103 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
105 static void FETCH(f_rgba_f32
)( const struct swrast_texture_image
*texImage
,
106 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
108 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 4);
109 texel
[RCOMP
] = src
[0];
110 texel
[GCOMP
] = src
[1];
111 texel
[BCOMP
] = src
[2];
112 texel
[ACOMP
] = src
[3];
118 /* MESA_FORMAT_RGBA_F16 ******************************************************/
120 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
121 * returning 4 GLfloats.
123 static void FETCH(f_rgba_f16
)( const struct swrast_texture_image
*texImage
,
124 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
126 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 4);
127 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
128 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
129 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
130 texel
[ACOMP
] = _mesa_half_to_float(src
[3]);
135 /* MESA_FORMAT_RGB_F32 *******************************************************/
137 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
138 * returning 4 GLfloats.
140 static void FETCH(f_rgb_f32
)( const struct swrast_texture_image
*texImage
,
141 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
143 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 3);
144 texel
[RCOMP
] = src
[0];
145 texel
[GCOMP
] = src
[1];
146 texel
[BCOMP
] = src
[2];
153 /* MESA_FORMAT_RGB_F16 *******************************************************/
155 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
156 * returning 4 GLfloats.
158 static void FETCH(f_rgb_f16
)( const struct swrast_texture_image
*texImage
,
159 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
161 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 3);
162 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
163 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
164 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
171 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
173 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
174 * returning 4 GLfloats.
176 static void FETCH(f_alpha_f32
)( const struct swrast_texture_image
*texImage
,
177 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
179 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
183 texel
[ACOMP
] = src
[0];
189 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
191 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
192 * returning 4 GLfloats.
194 static void FETCH(f_alpha_f16
)( const struct swrast_texture_image
*texImage
,
195 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
197 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
201 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
207 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
209 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
210 * returning 4 GLfloats.
212 static void FETCH(f_luminance_f32
)( const struct swrast_texture_image
*texImage
,
213 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
215 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
218 texel
[BCOMP
] = src
[0];
225 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
227 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
228 * returning 4 GLfloats.
230 static void FETCH(f_luminance_f16
)( const struct swrast_texture_image
*texImage
,
231 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
233 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
236 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
243 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
245 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
246 * returning 4 GLfloats.
248 static void FETCH(f_luminance_alpha_f32
)( const struct swrast_texture_image
*texImage
,
249 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
251 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
254 texel
[BCOMP
] = src
[0];
255 texel
[ACOMP
] = src
[1];
261 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
263 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
264 * returning 4 GLfloats.
266 static void FETCH(f_luminance_alpha_f16
)( const struct swrast_texture_image
*texImage
,
267 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
269 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
272 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
273 texel
[ACOMP
] = _mesa_half_to_float(src
[1]);
279 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
281 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
282 * returning 4 GLfloats.
284 static void FETCH(f_intensity_f32
)( const struct swrast_texture_image
*texImage
,
285 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
287 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
291 texel
[ACOMP
] = src
[0];
297 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
299 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
300 * returning 4 GLfloats.
302 static void FETCH(f_intensity_f16
)( const struct swrast_texture_image
*texImage
,
303 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
305 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
309 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
315 /* MESA_FORMAT_R_FLOAT32 *****************************************************/
317 /* Fetch texel from 1D, 2D or 3D R_FLOAT32 texture,
318 * returning 4 GLfloats.
320 static void FETCH(f_r_f32
)( const struct swrast_texture_image
*texImage
,
321 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
323 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
324 texel
[RCOMP
] = src
[0];
333 /* MESA_FORMAT_R_FLOAT16 *****************************************************/
335 /* Fetch texel from 1D, 2D or 3D R_FLOAT16 texture,
336 * returning 4 GLfloats.
338 static void FETCH(f_r_f16
)( const struct swrast_texture_image
*texImage
,
339 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
341 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
342 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
351 /* MESA_FORMAT_RG_FLOAT32 ****************************************************/
353 /* Fetch texel from 1D, 2D or 3D RG_FLOAT32 texture,
354 * returning 4 GLfloats.
356 static void FETCH(f_rg_f32
)( const struct swrast_texture_image
*texImage
,
357 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
359 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
360 texel
[RCOMP
] = src
[0];
361 texel
[GCOMP
] = src
[1];
369 /* MESA_FORMAT_RG_FLOAT16 ****************************************************/
371 /* Fetch texel from 1D, 2D or 3D RG_FLOAT16 texture,
372 * returning 4 GLfloats.
374 static void FETCH(f_rg_f16
)( const struct swrast_texture_image
*texImage
,
375 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
377 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
378 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
379 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
388 * Begin Hardware formats
391 /* MESA_FORMAT_A8B8G8R8_UNORM ******************************************************/
393 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
394 static void FETCH(f_rgba8888
)( const struct swrast_texture_image
*texImage
,
395 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
397 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
398 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
399 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
400 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
401 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
409 /* MESA_FORMAT_RGBA888_REV ***************************************************/
411 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
412 static void FETCH(f_rgba8888_rev
)( const struct swrast_texture_image
*texImage
,
413 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
415 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
416 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
417 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
418 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
419 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
425 /* MESA_FORMAT_B8G8R8A8_UNORM ******************************************************/
427 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
428 static void FETCH(f_argb8888
)( const struct swrast_texture_image
*texImage
,
429 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
431 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
432 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
433 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
434 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
435 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
441 /* MESA_FORMAT_A8R8G8B8_UNORM **************************************************/
443 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
444 static void FETCH(f_argb8888_rev
)( const struct swrast_texture_image
*texImage
,
445 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
447 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
448 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
449 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
450 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
451 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
457 /* MESA_FORMAT_X8B8G8R8_UNORM ******************************************************/
459 /* Fetch texel from 1D, 2D or 3D rgbx8888 texture, return 4 GLfloats */
460 static void FETCH(f_rgbx8888
)( const struct swrast_texture_image
*texImage
,
461 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
463 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
464 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
465 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
466 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
473 /* MESA_FORMAT_RGBX888_REV ***************************************************/
475 /* Fetch texel from 1D, 2D or 3D rgbx8888_rev texture, return 4 GLchans */
476 static void FETCH(f_rgbx8888_rev
)( const struct swrast_texture_image
*texImage
,
477 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
479 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
480 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
481 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
482 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
489 /* MESA_FORMAT_B8G8R8X8_UNORM ******************************************************/
491 /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
492 static void FETCH(f_xrgb8888
)( const struct swrast_texture_image
*texImage
,
493 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
495 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
496 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
497 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
498 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
505 /* MESA_FORMAT_X8R8G8B8_UNORM **************************************************/
507 /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
508 static void FETCH(f_xrgb8888_rev
)( const struct swrast_texture_image
*texImage
,
509 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
511 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
512 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
513 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
514 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
521 /* MESA_FORMAT_BGR_UNORM8 ********************************************************/
523 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
524 static void FETCH(f_rgb888
)( const struct swrast_texture_image
*texImage
,
525 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
527 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
528 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
529 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
530 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
537 /* MESA_FORMAT_RGB_UNORM8 ********************************************************/
539 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
540 static void FETCH(f_bgr888
)( const struct swrast_texture_image
*texImage
,
541 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
543 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
544 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[0] );
545 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
546 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[2] );
553 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
554 instead of slow (g << 2) * 255 / 252 (always rounds down) */
556 /* MESA_FORMAT_B5G6R5_UNORM ********************************************************/
558 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
559 static void FETCH(f_rgb565
)( const struct swrast_texture_image
*texImage
,
560 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
562 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
563 const GLushort s
= *src
;
564 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
565 texel
[GCOMP
] = ((s
>> 5 ) & 0x3f) * (1.0F
/ 63.0F
);
566 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
573 /* MESA_FORMAT_R5G6B5_UNORM ****************************************************/
575 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
576 static void FETCH(f_rgb565_rev
)( const struct swrast_texture_image
*texImage
,
577 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
579 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
580 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
581 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
582 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
583 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
590 /* MESA_FORMAT_B4G4R4A4_UNORM ******************************************************/
592 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
593 static void FETCH(f_argb4444
)( const struct swrast_texture_image
*texImage
,
594 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
596 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
597 const GLushort s
= *src
;
598 texel
[RCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
599 texel
[GCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
600 texel
[BCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
601 texel
[ACOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
607 /* MESA_FORMAT_A4R4G4B4_UNORM **************************************************/
609 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
610 static void FETCH(f_argb4444_rev
)( const struct swrast_texture_image
*texImage
,
611 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
613 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
614 texel
[RCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
615 texel
[GCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
616 texel
[BCOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
617 texel
[ACOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
622 /* MESA_FORMAT_A1B5G5R5_UNORM ******************************************************/
624 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
625 static void FETCH(f_rgba5551
)( const struct swrast_texture_image
*texImage
,
626 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
628 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
629 const GLushort s
= *src
;
630 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
631 texel
[GCOMP
] = ((s
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
632 texel
[BCOMP
] = ((s
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
633 texel
[ACOMP
] = ((s
) & 0x01) * 1.0F
;
638 /* MESA_FORMAT_B5G5R5A1_UNORM ******************************************************/
640 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
641 static void FETCH(f_argb1555
)( const struct swrast_texture_image
*texImage
,
642 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
644 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
645 const GLushort s
= *src
;
646 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
647 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
648 texel
[BCOMP
] = ((s
>> 0) & 0x1f) * (1.0F
/ 31.0F
);
649 texel
[ACOMP
] = ((s
>> 15) & 0x01) * 1.0F
;
655 /* MESA_FORMAT_A1R5G5B5_UNORM **************************************************/
657 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
658 static void FETCH(f_argb1555_rev
)( const struct swrast_texture_image
*texImage
,
659 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
661 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
662 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
663 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
664 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
665 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
666 texel
[ACOMP
] = UBYTE_TO_FLOAT( ((s
>> 15) & 0x01) * 255 );
672 /* MESA_FORMAT_B10G10R10A2_UNORM ***************************************************/
674 /* Fetch texel from 1D, 2D or 3D argb2101010 texture, return 4 GLchans */
675 static void FETCH(f_argb2101010
)( const struct swrast_texture_image
*texImage
,
676 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
678 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
679 const GLuint s
= *src
;
680 texel
[RCOMP
] = ((s
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
681 texel
[GCOMP
] = ((s
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
682 texel
[BCOMP
] = ((s
>> 0) & 0x3ff) * (1.0F
/ 1023.0F
);
683 texel
[ACOMP
] = ((s
>> 30) & 0x03) * (1.0F
/ 3.0F
);
689 /* MESA_FORMAT_R8G8_UNORM **********************************************************/
691 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
692 static void FETCH(f_gr88
)( const struct swrast_texture_image
*texImage
,
693 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
695 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
696 texel
[RCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
697 texel
[GCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
705 /* MESA_FORMAT_G8R8_UNORM ******************************************************/
707 /* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
708 static void FETCH(f_rg88
)( const struct swrast_texture_image
*texImage
,
709 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
711 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
712 texel
[RCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
713 texel
[GCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
721 /* MESA_FORMAT_L4A4_UNORM **********************************************************/
723 /* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
724 static void FETCH(f_al44
)( const struct swrast_texture_image
*texImage
,
725 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
727 const GLubyte s
= *TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
730 texel
[BCOMP
] = (s
& 0xf) * (1.0F
/ 15.0F
);
731 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
737 /* MESA_FORMAT_L8A8_UNORM **********************************************************/
739 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
740 static void FETCH(f_al88
)( const struct swrast_texture_image
*texImage
,
741 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
743 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
746 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
747 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
753 /* MESA_FORMAT_R_UNORM8 ************************************************************/
755 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
756 static void FETCH(f_r8
)(const struct swrast_texture_image
*texImage
,
757 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
759 const GLubyte s
= *TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
760 texel
[RCOMP
] = UBYTE_TO_FLOAT(s
);
769 /* MESA_FORMAT_R_UNORM16 ***********************************************************/
771 /* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
772 static void FETCH(f_r16
)(const struct swrast_texture_image
*texImage
,
773 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
775 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
776 texel
[RCOMP
] = USHORT_TO_FLOAT(s
);
785 /* MESA_FORMAT_A8L8_UNORM ******************************************************/
787 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
788 static void FETCH(f_al88_rev
)( const struct swrast_texture_image
*texImage
,
789 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
791 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
794 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
795 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
801 /* MESA_FORMAT_R16G16_UNORM ********************************************************/
803 /* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
804 static void FETCH(f_rg1616
)( const struct swrast_texture_image
*texImage
,
805 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
807 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
808 texel
[RCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
809 texel
[GCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
817 /* MESA_FORMAT_G16R16_UNORM ****************************************************/
819 /* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
820 static void FETCH(f_rg1616_rev
)( const struct swrast_texture_image
*texImage
,
821 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
823 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
824 texel
[RCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
825 texel
[GCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
833 /* MESA_FORMAT_L16A16_UNORM ********************************************************/
835 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
836 static void FETCH(f_al1616
)( const struct swrast_texture_image
*texImage
,
837 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
839 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
842 texel
[BCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
843 texel
[ACOMP
] = USHORT_TO_FLOAT( s
>> 16 );
849 /* MESA_FORMAT_A16L16_UNORM ****************************************************/
851 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
852 static void FETCH(f_al1616_rev
)( const struct swrast_texture_image
*texImage
,
853 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
855 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
858 texel
[BCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
859 texel
[ACOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
865 /* MESA_FORMAT_B2G3R3_UNORM ********************************************************/
867 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
868 static void FETCH(f_rgb332
)( const struct swrast_texture_image
*texImage
,
869 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
871 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
872 const GLubyte s
= *src
;
873 texel
[RCOMP
] = ((s
>> 5) & 0x7) * (1.0F
/ 7.0F
);
874 texel
[GCOMP
] = ((s
>> 2) & 0x7) * (1.0F
/ 7.0F
);
875 texel
[BCOMP
] = ((s
) & 0x3) * (1.0F
/ 3.0F
);
882 /* MESA_FORMAT_A_UNORM8 ************************************************************/
884 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
885 static void FETCH(f_a8
)( const struct swrast_texture_image
*texImage
,
886 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
888 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
892 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
898 /* MESA_FORMAT_A_UNORM16 ************************************************************/
900 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
901 static void FETCH(f_a16
)( const struct swrast_texture_image
*texImage
,
902 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
904 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
908 texel
[ACOMP
] = USHORT_TO_FLOAT( src
[0] );
914 /* MESA_FORMAT_L_UNORM8 ************************************************************/
916 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
917 static void FETCH(f_l8
)( const struct swrast_texture_image
*texImage
,
918 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
920 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
923 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
930 /* MESA_FORMAT_L_UNORM16 ***********************************************************/
932 /* Fetch texel from 1D, 2D or 3D l16 texture, return 4 GLchans */
933 static void FETCH(f_l16
)( const struct swrast_texture_image
*texImage
,
934 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
936 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
939 texel
[BCOMP
] = USHORT_TO_FLOAT( src
[0] );
946 /* MESA_FORMAT_I_UNORM8 ************************************************************/
948 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
949 static void FETCH(f_i8
)( const struct swrast_texture_image
*texImage
,
950 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
952 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
956 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
962 /* MESA_FORMAT_I_UNORM16 ***********************************************************/
964 /* Fetch texel from 1D, 2D or 3D i16 texture, return 4 GLchans */
965 static void FETCH(f_i16
)( const struct swrast_texture_image
*texImage
,
966 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
968 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
972 texel
[ACOMP
] = USHORT_TO_FLOAT( src
[0] );
978 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
979 /* Note: component order is same as for MESA_FORMAT_BGR_UNORM8 */
980 static void FETCH(srgb8
)(const struct swrast_texture_image
*texImage
,
981 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
983 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
984 texel
[RCOMP
] = nonlinear_to_linear(src
[2]);
985 texel
[GCOMP
] = nonlinear_to_linear(src
[1]);
986 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
992 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
993 static void FETCH(srgba8
)(const struct swrast_texture_image
*texImage
,
994 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
996 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
997 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 24) );
998 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
999 texel
[BCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1000 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff ); /* linear! */
1005 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1006 static void FETCH(sargb8
)(const struct swrast_texture_image
*texImage
,
1007 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1009 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1010 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1011 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1012 texel
[BCOMP
] = nonlinear_to_linear( (s
) & 0xff );
1013 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) ); /* linear! */
1018 /* Fetch texel from 1D, 2D or 3D sabgr8 texture, return 4 GLfloats */
1019 static void FETCH(sabgr8
)(const struct swrast_texture_image
*texImage
,
1020 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1022 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1023 texel
[RCOMP
] = nonlinear_to_linear( (s
) & 0xff );
1024 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1025 texel
[BCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1026 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) ); /* linear! */
1030 /* Fetch texel from 1D, 2D or 3D sabgr8 texture, return 4 GLfloats */
1031 static void FETCH(sxbgr8
)(const struct swrast_texture_image
*texImage
,
1032 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1034 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1035 texel
[RCOMP
] = nonlinear_to_linear( (s
) & 0xff );
1036 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1037 texel
[BCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1038 texel
[ACOMP
] = 1.0f
;
1042 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1043 static void FETCH(sl8
)(const struct swrast_texture_image
*texImage
,
1044 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1046 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1049 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1050 texel
[ACOMP
] = 1.0F
;
1055 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1056 static void FETCH(sla8
)(const struct swrast_texture_image
*texImage
,
1057 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1059 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1062 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1063 texel
[ACOMP
] = UBYTE_TO_FLOAT(src
[1]); /* linear */
1069 /* MESA_FORMAT_RGBA_SINT8 **************************************************/
1072 FETCH(rgba_int8
)(const struct swrast_texture_image
*texImage
,
1073 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1075 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 4);
1076 texel
[RCOMP
] = (GLfloat
) src
[0];
1077 texel
[GCOMP
] = (GLfloat
) src
[1];
1078 texel
[BCOMP
] = (GLfloat
) src
[2];
1079 texel
[ACOMP
] = (GLfloat
) src
[3];
1085 /* MESA_FORMAT_RGBA_SINT16 **************************************************/
1088 FETCH(rgba_int16
)(const struct swrast_texture_image
*texImage
,
1089 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1091 const GLshort
*src
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1092 texel
[RCOMP
] = (GLfloat
) src
[0];
1093 texel
[GCOMP
] = (GLfloat
) src
[1];
1094 texel
[BCOMP
] = (GLfloat
) src
[2];
1095 texel
[ACOMP
] = (GLfloat
) src
[3];
1101 /* MESA_FORMAT_RGBA_SINT32 **************************************************/
1104 FETCH(rgba_int32
)(const struct swrast_texture_image
*texImage
,
1105 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1107 const GLint
*src
= TEXEL_ADDR(GLint
, texImage
, i
, j
, k
, 4);
1108 texel
[RCOMP
] = (GLfloat
) src
[0];
1109 texel
[GCOMP
] = (GLfloat
) src
[1];
1110 texel
[BCOMP
] = (GLfloat
) src
[2];
1111 texel
[ACOMP
] = (GLfloat
) src
[3];
1117 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
1120 FETCH(rgba_uint8
)(const struct swrast_texture_image
*texImage
,
1121 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1123 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 4);
1124 texel
[RCOMP
] = (GLfloat
) src
[0];
1125 texel
[GCOMP
] = (GLfloat
) src
[1];
1126 texel
[BCOMP
] = (GLfloat
) src
[2];
1127 texel
[ACOMP
] = (GLfloat
) src
[3];
1133 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
1136 FETCH(rgba_uint16
)(const struct swrast_texture_image
*texImage
,
1137 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1139 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1140 texel
[RCOMP
] = (GLfloat
) src
[0];
1141 texel
[GCOMP
] = (GLfloat
) src
[1];
1142 texel
[BCOMP
] = (GLfloat
) src
[2];
1143 texel
[ACOMP
] = (GLfloat
) src
[3];
1149 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
1152 FETCH(rgba_uint32
)(const struct swrast_texture_image
*texImage
,
1153 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1155 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 4);
1156 texel
[RCOMP
] = (GLfloat
) src
[0];
1157 texel
[GCOMP
] = (GLfloat
) src
[1];
1158 texel
[BCOMP
] = (GLfloat
) src
[2];
1159 texel
[ACOMP
] = (GLfloat
) src
[3];
1165 /* MESA_FORMAT_DUDV8 ********************************************************/
1167 /* this format by definition produces 0,0,0,1 as rgba values,
1168 however we'll return the dudv values as rg and fix up elsewhere */
1169 static void FETCH(dudv8
)(const struct swrast_texture_image
*texImage
,
1170 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1172 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 2);
1173 texel
[RCOMP
] = BYTE_TO_FLOAT(src
[0]);
1174 texel
[GCOMP
] = BYTE_TO_FLOAT(src
[1]);
1180 /* MESA_FORMAT_R_SNORM8 ***********************************************/
1182 static void FETCH(signed_r8
)( const struct swrast_texture_image
*texImage
,
1183 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1185 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1186 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( s
);
1187 texel
[GCOMP
] = 0.0F
;
1188 texel
[BCOMP
] = 0.0F
;
1189 texel
[ACOMP
] = 1.0F
;
1195 /* MESA_FORMAT_A_SNORM8 ***********************************************/
1197 static void FETCH(signed_a8
)( const struct swrast_texture_image
*texImage
,
1198 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1200 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1201 texel
[RCOMP
] = 0.0F
;
1202 texel
[GCOMP
] = 0.0F
;
1203 texel
[BCOMP
] = 0.0F
;
1204 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( s
);
1210 /* MESA_FORMAT_L_SNORM8 ***********************************************/
1212 static void FETCH(signed_l8
)( const struct swrast_texture_image
*texImage
,
1213 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1215 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1218 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( s
);
1219 texel
[ACOMP
] = 1.0F
;
1225 /* MESA_FORMAT_I_SNORM8 ***********************************************/
1227 static void FETCH(signed_i8
)( const struct swrast_texture_image
*texImage
,
1228 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1230 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1234 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( s
);
1240 /* MESA_FORMAT_R8G8_SNORM ***********************************************/
1242 static void FETCH(signed_rg88_rev
)( const struct swrast_texture_image
*texImage
,
1243 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1245 const GLushort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1246 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
& 0xff) );
1247 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1248 texel
[BCOMP
] = 0.0F
;
1249 texel
[ACOMP
] = 1.0F
;
1255 /* MESA_FORMAT_L8A8_SNORM ***********************************************/
1257 static void FETCH(signed_al88
)( const struct swrast_texture_image
*texImage
,
1258 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1260 const GLushort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1263 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
& 0xff) );
1264 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1270 /* MESA_FORMAT_X8B8G8R8_SNORM ***********************************************/
1272 static void FETCH(signed_rgbx8888
)( const struct swrast_texture_image
*texImage
,
1273 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1275 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1276 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1277 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1278 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1279 texel
[ACOMP
] = 1.0f
;
1285 /* MESA_FORMAT_A8B8G8R8_SNORM ***********************************************/
1287 static void FETCH(signed_rgba8888
)( const struct swrast_texture_image
*texImage
,
1288 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1290 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1291 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1292 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1293 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1294 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
) );
1299 static void FETCH(signed_rgba8888_rev
)( const struct swrast_texture_image
*texImage
,
1300 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1302 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1303 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
) );
1304 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1305 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1306 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1313 /* MESA_FORMAT_R_SNORM16 ***********************************************/
1316 FETCH(signed_r16
)(const struct swrast_texture_image
*texImage
,
1317 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1319 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1320 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
);
1321 texel
[GCOMP
] = 0.0F
;
1322 texel
[BCOMP
] = 0.0F
;
1323 texel
[ACOMP
] = 1.0F
;
1329 /* MESA_FORMAT_A_SNORM16 ***********************************************/
1332 FETCH(signed_a16
)(const struct swrast_texture_image
*texImage
,
1333 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1335 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1336 texel
[RCOMP
] = 0.0F
;
1337 texel
[GCOMP
] = 0.0F
;
1338 texel
[BCOMP
] = 0.0F
;
1339 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
);
1345 /* MESA_FORMAT_L_SNORM16 ***********************************************/
1348 FETCH(signed_l16
)(const struct swrast_texture_image
*texImage
,
1349 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1351 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1354 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
);
1355 texel
[ACOMP
] = 1.0F
;
1361 /* MESA_FORMAT_I_SNORM16 ***********************************************/
1364 FETCH(signed_i16
)(const struct swrast_texture_image
*texImage
,
1365 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1367 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1371 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
);
1377 /* MESA_FORMAT_G16R16_SNORM ***********************************************/
1380 FETCH(signed_rg1616
)(const struct swrast_texture_image
*texImage
,
1381 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1383 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
1384 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1385 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1386 texel
[BCOMP
] = 0.0F
;
1387 texel
[ACOMP
] = 1.0F
;
1393 /* MESA_FORMAT_LA_SNORM16 ***********************************************/
1396 FETCH(signed_al1616
)(const struct swrast_texture_image
*texImage
,
1397 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1399 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
1402 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1403 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1409 /* MESA_FORMAT_RGB_SNORM16 ***********************************************/
1412 FETCH(signed_rgb_16
)(const struct swrast_texture_image
*texImage
,
1413 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1415 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 3);
1416 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1417 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1418 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
1419 texel
[ACOMP
] = 1.0F
;
1425 /* MESA_FORMAT_RGBA_SNORM16 ***********************************************/
1428 FETCH(signed_rgba_16
)(const struct swrast_texture_image
*texImage
,
1429 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1431 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1432 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1433 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1434 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
1435 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
[3] );
1442 /* MESA_FORMAT_RGBA_UNORM16 ***********************************************/
1445 FETCH(rgba_16
)(const struct swrast_texture_image
*texImage
,
1446 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1448 const GLushort
*s
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1449 texel
[RCOMP
] = USHORT_TO_FLOAT( s
[0] );
1450 texel
[GCOMP
] = USHORT_TO_FLOAT( s
[1] );
1451 texel
[BCOMP
] = USHORT_TO_FLOAT( s
[2] );
1452 texel
[ACOMP
] = USHORT_TO_FLOAT( s
[3] );
1457 /* MESA_FORMAT_XBGR.... **********************************************/
1460 FETCH(xbgr16161616_unorm
)(const struct swrast_texture_image
*texImage
,
1461 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1463 const GLushort
*s
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1464 texel
[RCOMP
] = USHORT_TO_FLOAT(s
[0]);
1465 texel
[GCOMP
] = USHORT_TO_FLOAT(s
[1]);
1466 texel
[BCOMP
] = USHORT_TO_FLOAT(s
[2]);
1467 texel
[ACOMP
] = 1.0f
;
1471 FETCH(xbgr16161616_float
)(const struct swrast_texture_image
*texImage
,
1472 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1474 const GLhalfARB
*s
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 4);
1475 texel
[RCOMP
] = _mesa_half_to_float(s
[0]);
1476 texel
[GCOMP
] = _mesa_half_to_float(s
[1]);
1477 texel
[BCOMP
] = _mesa_half_to_float(s
[2]);
1478 texel
[ACOMP
] = 1.0f
;
1482 FETCH(xbgr32323232_float
)(const struct swrast_texture_image
*texImage
,
1483 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1485 const GLfloat
*s
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 4);
1486 texel
[RCOMP
] = s
[0];
1487 texel
[GCOMP
] = s
[1];
1488 texel
[BCOMP
] = s
[2];
1489 texel
[ACOMP
] = 1.0f
;
1492 /* XXX other XBGR formats need to be implemented here */
1496 /* MESA_FORMAT_YCBCR *********************************************************/
1498 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
1499 * We convert YCbCr to RGB here.
1501 static void FETCH(f_ycbcr
)( const struct swrast_texture_image
*texImage
,
1502 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1504 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1505 const GLushort
*src1
= src0
+ 1; /* odd */
1506 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1507 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1508 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1509 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1510 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1511 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1512 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1513 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1514 r
*= (1.0F
/ 255.0F
);
1515 g
*= (1.0F
/ 255.0F
);
1516 b
*= (1.0F
/ 255.0F
);
1517 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1518 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1519 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1520 texel
[ACOMP
] = 1.0F
;
1526 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1528 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
1529 * We convert YCbCr to RGB here.
1531 static void FETCH(f_ycbcr_rev
)( const struct swrast_texture_image
*texImage
,
1532 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1534 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1535 const GLushort
*src1
= src0
+ 1; /* odd */
1536 const GLubyte y0
= *src0
& 0xff; /* luminance */
1537 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1538 const GLubyte y1
= *src1
& 0xff; /* luminance */
1539 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1540 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1541 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1542 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1543 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1544 r
*= (1.0F
/ 255.0F
);
1545 g
*= (1.0F
/ 255.0F
);
1546 b
*= (1.0F
/ 255.0F
);
1547 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1548 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1549 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1550 texel
[ACOMP
] = 1.0F
;
1556 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1558 static void FETCH(f_z24_s8
)( const struct swrast_texture_image
*texImage
,
1559 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1561 /* only return Z, not stencil data */
1562 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1563 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
1564 texel
[0] = (GLfloat
) (((*src
) >> 8) * scale
);
1565 ASSERT(texImage
->Base
.TexFormat
== MESA_FORMAT_S8_UINT_Z24_UNORM
||
1566 texImage
->Base
.TexFormat
== MESA_FORMAT_X8Z24_UNORM
);
1567 ASSERT(texel
[0] >= 0.0F
);
1568 ASSERT(texel
[0] <= 1.0F
);
1574 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1576 static void FETCH(f_s8_z24
)( const struct swrast_texture_image
*texImage
,
1577 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1579 /* only return Z, not stencil data */
1580 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1581 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
1582 texel
[0] = (GLfloat
) (((*src
) & 0x00ffffff) * scale
);
1583 ASSERT(texImage
->Base
.TexFormat
== MESA_FORMAT_Z24_UNORM_S8_UINT
||
1584 texImage
->Base
.TexFormat
== MESA_FORMAT_Z24_UNORM_X8_UINT
);
1585 ASSERT(texel
[0] >= 0.0F
);
1586 ASSERT(texel
[0] <= 1.0F
);
1592 /* MESA_FORMAT_RGB9_E5 ******************************************************/
1594 static void FETCH(rgb9_e5
)( const struct swrast_texture_image
*texImage
,
1595 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1597 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1598 rgb9e5_to_float3(*src
, texel
);
1599 texel
[ACOMP
] = 1.0F
;
1605 /* MESA_FORMAT_R11G11B10_FLOAT *********************************************/
1607 static void FETCH(r11_g11_b10f
)( const struct swrast_texture_image
*texImage
,
1608 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1610 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1611 r11g11b10f_to_float3(*src
, texel
);
1612 texel
[ACOMP
] = 1.0F
;
1618 /* MESA_FORMAT_Z32_FLOAT_S8X24_UINT ***********************************************/
1620 static void FETCH(z32f_x24s8
)(const struct swrast_texture_image
*texImage
,
1621 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1623 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
1624 texel
[RCOMP
] = src
[0];
1625 texel
[GCOMP
] = 0.0F
;
1626 texel
[BCOMP
] = 0.0F
;
1627 texel
[ACOMP
] = 1.0F
;