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 sl8 texture, return 4 GLfloats */
1019 static void FETCH(sl8
)(const struct swrast_texture_image
*texImage
,
1020 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1022 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1025 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1026 texel
[ACOMP
] = 1.0F
;
1031 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1032 static void FETCH(sla8
)(const struct swrast_texture_image
*texImage
,
1033 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1035 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1038 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1039 texel
[ACOMP
] = UBYTE_TO_FLOAT(src
[1]); /* linear */
1045 /* MESA_FORMAT_RGBA_SINT8 **************************************************/
1048 FETCH(rgba_int8
)(const struct swrast_texture_image
*texImage
,
1049 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1051 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 4);
1052 texel
[RCOMP
] = (GLfloat
) src
[0];
1053 texel
[GCOMP
] = (GLfloat
) src
[1];
1054 texel
[BCOMP
] = (GLfloat
) src
[2];
1055 texel
[ACOMP
] = (GLfloat
) src
[3];
1061 /* MESA_FORMAT_RGBA_SINT16 **************************************************/
1064 FETCH(rgba_int16
)(const struct swrast_texture_image
*texImage
,
1065 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1067 const GLshort
*src
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1068 texel
[RCOMP
] = (GLfloat
) src
[0];
1069 texel
[GCOMP
] = (GLfloat
) src
[1];
1070 texel
[BCOMP
] = (GLfloat
) src
[2];
1071 texel
[ACOMP
] = (GLfloat
) src
[3];
1077 /* MESA_FORMAT_RGBA_SINT32 **************************************************/
1080 FETCH(rgba_int32
)(const struct swrast_texture_image
*texImage
,
1081 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1083 const GLint
*src
= TEXEL_ADDR(GLint
, texImage
, i
, j
, k
, 4);
1084 texel
[RCOMP
] = (GLfloat
) src
[0];
1085 texel
[GCOMP
] = (GLfloat
) src
[1];
1086 texel
[BCOMP
] = (GLfloat
) src
[2];
1087 texel
[ACOMP
] = (GLfloat
) src
[3];
1093 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
1096 FETCH(rgba_uint8
)(const struct swrast_texture_image
*texImage
,
1097 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1099 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 4);
1100 texel
[RCOMP
] = (GLfloat
) src
[0];
1101 texel
[GCOMP
] = (GLfloat
) src
[1];
1102 texel
[BCOMP
] = (GLfloat
) src
[2];
1103 texel
[ACOMP
] = (GLfloat
) src
[3];
1109 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
1112 FETCH(rgba_uint16
)(const struct swrast_texture_image
*texImage
,
1113 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1115 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1116 texel
[RCOMP
] = (GLfloat
) src
[0];
1117 texel
[GCOMP
] = (GLfloat
) src
[1];
1118 texel
[BCOMP
] = (GLfloat
) src
[2];
1119 texel
[ACOMP
] = (GLfloat
) src
[3];
1125 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
1128 FETCH(rgba_uint32
)(const struct swrast_texture_image
*texImage
,
1129 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1131 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 4);
1132 texel
[RCOMP
] = (GLfloat
) src
[0];
1133 texel
[GCOMP
] = (GLfloat
) src
[1];
1134 texel
[BCOMP
] = (GLfloat
) src
[2];
1135 texel
[ACOMP
] = (GLfloat
) src
[3];
1141 /* MESA_FORMAT_DUDV8 ********************************************************/
1143 /* this format by definition produces 0,0,0,1 as rgba values,
1144 however we'll return the dudv values as rg and fix up elsewhere */
1145 static void FETCH(dudv8
)(const struct swrast_texture_image
*texImage
,
1146 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1148 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 2);
1149 texel
[RCOMP
] = BYTE_TO_FLOAT(src
[0]);
1150 texel
[GCOMP
] = BYTE_TO_FLOAT(src
[1]);
1156 /* MESA_FORMAT_R_SNORM8 ***********************************************/
1158 static void FETCH(signed_r8
)( const struct swrast_texture_image
*texImage
,
1159 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1161 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1162 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( s
);
1163 texel
[GCOMP
] = 0.0F
;
1164 texel
[BCOMP
] = 0.0F
;
1165 texel
[ACOMP
] = 1.0F
;
1171 /* MESA_FORMAT_A_SNORM8 ***********************************************/
1173 static void FETCH(signed_a8
)( const struct swrast_texture_image
*texImage
,
1174 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1176 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1177 texel
[RCOMP
] = 0.0F
;
1178 texel
[GCOMP
] = 0.0F
;
1179 texel
[BCOMP
] = 0.0F
;
1180 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( s
);
1186 /* MESA_FORMAT_L_SNORM8 ***********************************************/
1188 static void FETCH(signed_l8
)( const struct swrast_texture_image
*texImage
,
1189 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1191 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1194 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( s
);
1195 texel
[ACOMP
] = 1.0F
;
1201 /* MESA_FORMAT_I_SNORM8 ***********************************************/
1203 static void FETCH(signed_i8
)( const struct swrast_texture_image
*texImage
,
1204 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1206 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1210 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( s
);
1216 /* MESA_FORMAT_R8G8_SNORM ***********************************************/
1218 static void FETCH(signed_rg88_rev
)( const struct swrast_texture_image
*texImage
,
1219 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1221 const GLushort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1222 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
& 0xff) );
1223 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1224 texel
[BCOMP
] = 0.0F
;
1225 texel
[ACOMP
] = 1.0F
;
1231 /* MESA_FORMAT_L8A8_SNORM ***********************************************/
1233 static void FETCH(signed_al88
)( const struct swrast_texture_image
*texImage
,
1234 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1236 const GLushort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1239 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
& 0xff) );
1240 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1246 /* MESA_FORMAT_X8B8G8R8_SNORM ***********************************************/
1248 static void FETCH(signed_rgbx8888
)( const struct swrast_texture_image
*texImage
,
1249 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1251 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1252 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1253 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1254 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1255 texel
[ACOMP
] = 1.0f
;
1261 /* MESA_FORMAT_A8B8G8R8_SNORM ***********************************************/
1263 static void FETCH(signed_rgba8888
)( const struct swrast_texture_image
*texImage
,
1264 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1266 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1267 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1268 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1269 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1270 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
) );
1275 static void FETCH(signed_rgba8888_rev
)( const struct swrast_texture_image
*texImage
,
1276 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1278 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1279 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
) );
1280 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1281 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1282 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1289 /* MESA_FORMAT_R_SNORM16 ***********************************************/
1292 FETCH(signed_r16
)(const struct swrast_texture_image
*texImage
,
1293 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1295 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1296 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
);
1297 texel
[GCOMP
] = 0.0F
;
1298 texel
[BCOMP
] = 0.0F
;
1299 texel
[ACOMP
] = 1.0F
;
1305 /* MESA_FORMAT_A_SNORM16 ***********************************************/
1308 FETCH(signed_a16
)(const struct swrast_texture_image
*texImage
,
1309 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1311 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1312 texel
[RCOMP
] = 0.0F
;
1313 texel
[GCOMP
] = 0.0F
;
1314 texel
[BCOMP
] = 0.0F
;
1315 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
);
1321 /* MESA_FORMAT_L_SNORM16 ***********************************************/
1324 FETCH(signed_l16
)(const struct swrast_texture_image
*texImage
,
1325 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1327 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1330 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
);
1331 texel
[ACOMP
] = 1.0F
;
1337 /* MESA_FORMAT_I_SNORM16 ***********************************************/
1340 FETCH(signed_i16
)(const struct swrast_texture_image
*texImage
,
1341 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1343 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1347 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
);
1353 /* MESA_FORMAT_G16R16_SNORM ***********************************************/
1356 FETCH(signed_rg1616
)(const struct swrast_texture_image
*texImage
,
1357 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1359 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
1360 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1361 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1362 texel
[BCOMP
] = 0.0F
;
1363 texel
[ACOMP
] = 1.0F
;
1369 /* MESA_FORMAT_LA_SNORM16 ***********************************************/
1372 FETCH(signed_al1616
)(const struct swrast_texture_image
*texImage
,
1373 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1375 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
1378 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1379 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1385 /* MESA_FORMAT_RGB_SNORM16 ***********************************************/
1388 FETCH(signed_rgb_16
)(const struct swrast_texture_image
*texImage
,
1389 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1391 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 3);
1392 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1393 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1394 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
1395 texel
[ACOMP
] = 1.0F
;
1401 /* MESA_FORMAT_RGBA_SNORM16 ***********************************************/
1404 FETCH(signed_rgba_16
)(const struct swrast_texture_image
*texImage
,
1405 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1407 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1408 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1409 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1410 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
1411 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
[3] );
1418 /* MESA_FORMAT_RGBA_UNORM16 ***********************************************/
1421 FETCH(rgba_16
)(const struct swrast_texture_image
*texImage
,
1422 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1424 const GLushort
*s
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1425 texel
[RCOMP
] = USHORT_TO_FLOAT( s
[0] );
1426 texel
[GCOMP
] = USHORT_TO_FLOAT( s
[1] );
1427 texel
[BCOMP
] = USHORT_TO_FLOAT( s
[2] );
1428 texel
[ACOMP
] = USHORT_TO_FLOAT( s
[3] );
1433 /* MESA_FORMAT_XBGR.... **********************************************/
1436 FETCH(xbgr16161616_unorm
)(const struct swrast_texture_image
*texImage
,
1437 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1439 const GLushort
*s
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1440 texel
[RCOMP
] = USHORT_TO_FLOAT(s
[0]);
1441 texel
[GCOMP
] = USHORT_TO_FLOAT(s
[1]);
1442 texel
[BCOMP
] = USHORT_TO_FLOAT(s
[2]);
1443 texel
[ACOMP
] = 1.0f
;
1447 FETCH(xbgr16161616_float
)(const struct swrast_texture_image
*texImage
,
1448 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1450 const GLhalfARB
*s
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 4);
1451 texel
[RCOMP
] = _mesa_half_to_float(s
[0]);
1452 texel
[GCOMP
] = _mesa_half_to_float(s
[1]);
1453 texel
[BCOMP
] = _mesa_half_to_float(s
[2]);
1454 texel
[ACOMP
] = 1.0f
;
1458 FETCH(xbgr32323232_float
)(const struct swrast_texture_image
*texImage
,
1459 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1461 const GLfloat
*s
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 4);
1462 texel
[RCOMP
] = s
[0];
1463 texel
[GCOMP
] = s
[1];
1464 texel
[BCOMP
] = s
[2];
1465 texel
[ACOMP
] = 1.0f
;
1468 /* XXX other XBGR formats need to be implemented here */
1472 /* MESA_FORMAT_YCBCR *********************************************************/
1474 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
1475 * We convert YCbCr to RGB here.
1477 static void FETCH(f_ycbcr
)( const struct swrast_texture_image
*texImage
,
1478 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1480 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1481 const GLushort
*src1
= src0
+ 1; /* odd */
1482 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1483 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1484 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1485 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1486 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1487 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1488 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1489 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1490 r
*= (1.0F
/ 255.0F
);
1491 g
*= (1.0F
/ 255.0F
);
1492 b
*= (1.0F
/ 255.0F
);
1493 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1494 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1495 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1496 texel
[ACOMP
] = 1.0F
;
1502 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1504 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
1505 * We convert YCbCr to RGB here.
1507 static void FETCH(f_ycbcr_rev
)( const struct swrast_texture_image
*texImage
,
1508 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1510 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1511 const GLushort
*src1
= src0
+ 1; /* odd */
1512 const GLubyte y0
= *src0
& 0xff; /* luminance */
1513 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1514 const GLubyte y1
= *src1
& 0xff; /* luminance */
1515 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1516 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1517 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1518 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1519 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1520 r
*= (1.0F
/ 255.0F
);
1521 g
*= (1.0F
/ 255.0F
);
1522 b
*= (1.0F
/ 255.0F
);
1523 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1524 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1525 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1526 texel
[ACOMP
] = 1.0F
;
1532 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1534 static void FETCH(f_z24_s8
)( const struct swrast_texture_image
*texImage
,
1535 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1537 /* only return Z, not stencil data */
1538 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1539 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
1540 texel
[0] = (GLfloat
) (((*src
) >> 8) * scale
);
1541 ASSERT(texImage
->Base
.TexFormat
== MESA_FORMAT_S8_UINT_Z24_UNORM
||
1542 texImage
->Base
.TexFormat
== MESA_FORMAT_X8Z24_UNORM
);
1543 ASSERT(texel
[0] >= 0.0F
);
1544 ASSERT(texel
[0] <= 1.0F
);
1550 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1552 static void FETCH(f_s8_z24
)( const struct swrast_texture_image
*texImage
,
1553 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1555 /* only return Z, not stencil data */
1556 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1557 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
1558 texel
[0] = (GLfloat
) (((*src
) & 0x00ffffff) * scale
);
1559 ASSERT(texImage
->Base
.TexFormat
== MESA_FORMAT_Z24_UNORM_S8_UINT
||
1560 texImage
->Base
.TexFormat
== MESA_FORMAT_Z24_UNORM_X8_UINT
);
1561 ASSERT(texel
[0] >= 0.0F
);
1562 ASSERT(texel
[0] <= 1.0F
);
1568 /* MESA_FORMAT_RGB9_E5 ******************************************************/
1570 static void FETCH(rgb9_e5
)( const struct swrast_texture_image
*texImage
,
1571 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1573 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1574 rgb9e5_to_float3(*src
, texel
);
1575 texel
[ACOMP
] = 1.0F
;
1581 /* MESA_FORMAT_R11G11B10_FLOAT *********************************************/
1583 static void FETCH(r11_g11_b10f
)( const struct swrast_texture_image
*texImage
,
1584 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1586 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1587 r11g11b10f_to_float3(*src
, texel
);
1588 texel
[ACOMP
] = 1.0F
;
1594 /* MESA_FORMAT_Z32_FLOAT_S8X24_UINT ***********************************************/
1596 static void FETCH(z32f_x24s8
)(const struct swrast_texture_image
*texImage
,
1597 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1599 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
1600 texel
[RCOMP
] = src
[0];
1601 texel
[GCOMP
] = 0.0F
;
1602 texel
[BCOMP
] = 0.0F
;
1603 texel
[ACOMP
] = 1.0F
;