2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * \file texfetch_tmp.h
29 * Texel fetch functions template.
31 * This template file is used by texfetch.c to generate texel fetch functions
32 * for 1-D, 2-D and 3-D texture images.
34 * It should be expanded by defining \p DIM as the number texture dimensions
35 * (1, 2 or 3). According to the value of \p DIM a series of macros is defined
36 * for the texel lookup in the gl_texture_image::Data.
38 * \author Gareth Hughes
45 #define TEXEL_ADDR( type, image, i, j, k, size ) \
46 ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
48 #define FETCH(x) fetch_texel_1d_##x
52 #define TEXEL_ADDR( type, image, i, j, k, size ) \
54 ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
56 #define FETCH(x) fetch_texel_2d_##x
60 #define TEXEL_ADDR( type, image, i, j, k, size ) \
61 ((type *)(image)->Data + ((image)->ImageOffsets[k] \
62 + (image)->RowStride * (j) + (i)) * (size))
64 #define FETCH(x) fetch_texel_3d_##x
67 #error illegal number of texture dimensions
71 /* MESA_FORMAT_Z32 ***********************************************************/
73 /* Fetch depth texel from 1D, 2D or 3D 32-bit depth texture,
74 * returning 1 GLfloat.
75 * Note: no GLchan version of this function.
77 static void FETCH(f_z32
)( const struct gl_texture_image
*texImage
,
78 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
80 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
81 texel
[0] = src
[0] * (1.0F
/ 0xffffffff);
85 static void store_texel_z32(struct gl_texture_image
*texImage
,
86 GLint i
, GLint j
, GLint k
, const void *texel
)
88 const GLuint
*depth
= (const GLuint
*) texel
;
89 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
95 /* MESA_FORMAT_Z16 ***********************************************************/
97 /* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
98 * returning 1 GLfloat.
99 * Note: no GLchan version of this function.
101 static void FETCH(f_z16
)(const struct gl_texture_image
*texImage
,
102 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
104 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
105 texel
[0] = src
[0] * (1.0F
/ 65535.0F
);
109 static void store_texel_z16(struct gl_texture_image
*texImage
,
110 GLint i
, GLint j
, GLint k
, const void *texel
)
112 const GLushort
*depth
= (const GLushort
*) texel
;
113 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
119 /* MESA_FORMAT_RGBA_F32 ******************************************************/
121 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
123 static void FETCH(f_rgba_f32
)( const struct gl_texture_image
*texImage
,
124 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
126 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 4);
127 texel
[RCOMP
] = src
[0];
128 texel
[GCOMP
] = src
[1];
129 texel
[BCOMP
] = src
[2];
130 texel
[ACOMP
] = src
[3];
134 static void store_texel_rgba_f32(struct gl_texture_image
*texImage
,
135 GLint i
, GLint j
, GLint k
, const void *texel
)
137 const GLfloat
*depth
= (const GLfloat
*) texel
;
138 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
139 dst
[0] = depth
[RCOMP
];
140 dst
[1] = depth
[GCOMP
];
141 dst
[2] = depth
[BCOMP
];
142 dst
[3] = depth
[ACOMP
];
147 /* MESA_FORMAT_RGBA_F16 ******************************************************/
149 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
150 * returning 4 GLfloats.
152 static void FETCH(f_rgba_f16
)( const struct gl_texture_image
*texImage
,
153 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
155 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 4);
156 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
157 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
158 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
159 texel
[ACOMP
] = _mesa_half_to_float(src
[3]);
163 static void store_texel_rgba_f16(struct gl_texture_image
*texImage
,
164 GLint i
, GLint j
, GLint k
, const void *texel
)
166 const GLfloat
*depth
= (const GLfloat
*) texel
;
167 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
168 dst
[0] = _mesa_float_to_half(*depth
);
172 /* MESA_FORMAT_RGB_F32 *******************************************************/
174 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
175 * returning 4 GLfloats.
177 static void FETCH(f_rgb_f32
)( const struct gl_texture_image
*texImage
,
178 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
180 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 3);
181 texel
[RCOMP
] = src
[0];
182 texel
[GCOMP
] = src
[1];
183 texel
[BCOMP
] = src
[2];
188 static void store_texel_rgb_f32(struct gl_texture_image
*texImage
,
189 GLint i
, GLint j
, GLint k
, const void *texel
)
191 const GLfloat
*depth
= (const GLfloat
*) texel
;
192 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
198 /* MESA_FORMAT_RGB_F16 *******************************************************/
200 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
201 * returning 4 GLfloats.
203 static void FETCH(f_rgb_f16
)( const struct gl_texture_image
*texImage
,
204 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
206 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 3);
207 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
208 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
209 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
214 static void store_texel_rgb_f16(struct gl_texture_image
*texImage
,
215 GLint i
, GLint j
, GLint k
, const void *texel
)
217 const GLfloat
*depth
= (const GLfloat
*) texel
;
218 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
219 dst
[0] = _mesa_float_to_half(*depth
);
224 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
226 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
227 * returning 4 GLfloats.
229 static void FETCH(f_alpha_f32
)( const struct gl_texture_image
*texImage
,
230 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
232 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
236 texel
[ACOMP
] = src
[0];
240 static void store_texel_alpha_f32(struct gl_texture_image
*texImage
,
241 GLint i
, GLint j
, GLint k
, const void *texel
)
243 const GLfloat
*rgba
= (const GLfloat
*) texel
;
244 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
245 dst
[0] = rgba
[ACOMP
];
250 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
252 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
253 * returning 4 GLfloats.
255 static void FETCH(f_alpha_f16
)( const struct gl_texture_image
*texImage
,
256 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
258 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
262 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
266 static void store_texel_alpha_f16(struct gl_texture_image
*texImage
,
267 GLint i
, GLint j
, GLint k
, const void *texel
)
269 const GLfloat
*rgba
= (const GLfloat
*) texel
;
270 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
271 dst
[0] = _mesa_float_to_half(rgba
[ACOMP
]);
276 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
278 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
279 * returning 4 GLfloats.
281 static void FETCH(f_luminance_f32
)( const struct gl_texture_image
*texImage
,
282 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
284 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
287 texel
[BCOMP
] = src
[0];
292 static void store_texel_luminance_f32(struct gl_texture_image
*texImage
,
293 GLint i
, GLint j
, GLint k
, const void *texel
)
295 const GLfloat
*rgba
= (const GLfloat
*) texel
;
296 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
297 dst
[0] = rgba
[RCOMP
];
302 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
304 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
305 * returning 4 GLfloats.
307 static void FETCH(f_luminance_f16
)( const struct gl_texture_image
*texImage
,
308 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
310 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
313 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
318 static void store_texel_luminance_f16(struct gl_texture_image
*texImage
,
319 GLint i
, GLint j
, GLint k
, const void *texel
)
321 const GLfloat
*rgba
= (const GLfloat
*) texel
;
322 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
323 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
328 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
330 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
331 * returning 4 GLfloats.
333 static void FETCH(f_luminance_alpha_f32
)( const struct gl_texture_image
*texImage
,
334 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
336 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
339 texel
[BCOMP
] = src
[0];
340 texel
[ACOMP
] = src
[1];
344 static void store_texel_luminance_alpha_f32(struct gl_texture_image
*texImage
,
345 GLint i
, GLint j
, GLint k
, const void *texel
)
347 const GLfloat
*rgba
= (const GLfloat
*) texel
;
348 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
349 dst
[0] = rgba
[RCOMP
];
350 dst
[1] = rgba
[ACOMP
];
355 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
357 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
358 * returning 4 GLfloats.
360 static void FETCH(f_luminance_alpha_f16
)( const struct gl_texture_image
*texImage
,
361 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
363 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
366 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
367 texel
[ACOMP
] = _mesa_half_to_float(src
[1]);
371 static void store_texel_luminance_alpha_f16(struct gl_texture_image
*texImage
,
372 GLint i
, GLint j
, GLint k
, const void *texel
)
374 const GLfloat
*rgba
= (const GLfloat
*) texel
;
375 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
376 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
377 dst
[1] = _mesa_float_to_half(rgba
[ACOMP
]);
382 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
384 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
385 * returning 4 GLfloats.
387 static void FETCH(f_intensity_f32
)( const struct gl_texture_image
*texImage
,
388 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
390 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
394 texel
[ACOMP
] = src
[0];
398 static void store_texel_intensity_f32(struct gl_texture_image
*texImage
,
399 GLint i
, GLint j
, GLint k
, const void *texel
)
401 const GLfloat
*rgba
= (const GLfloat
*) texel
;
402 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
403 dst
[0] = rgba
[RCOMP
];
408 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
410 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
411 * returning 4 GLfloats.
413 static void FETCH(f_intensity_f16
)( const struct gl_texture_image
*texImage
,
414 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
416 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
420 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
424 static void store_texel_intensity_f16(struct gl_texture_image
*texImage
,
425 GLint i
, GLint j
, GLint k
, const void *texel
)
427 const GLfloat
*rgba
= (const GLfloat
*) texel
;
428 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
429 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
437 * Begin Hardware formats
440 /* MESA_FORMAT_RGBA8888 ******************************************************/
442 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
443 static void FETCH(f_rgba8888
)( const struct gl_texture_image
*texImage
,
444 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
446 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
447 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
448 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
449 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
450 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
456 static void store_texel_rgba8888(struct gl_texture_image
*texImage
,
457 GLint i
, GLint j
, GLint k
, const void *texel
)
459 const GLubyte
*rgba
= (const GLubyte
*) texel
;
460 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
461 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
466 /* MESA_FORMAT_RGBA888_REV ***************************************************/
468 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
469 static void FETCH(f_rgba8888_rev
)( const struct gl_texture_image
*texImage
,
470 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
472 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
473 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
474 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
475 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
476 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
480 static void store_texel_rgba8888_rev(struct gl_texture_image
*texImage
,
481 GLint i
, GLint j
, GLint k
, const void *texel
)
483 const GLubyte
*rgba
= (const GLubyte
*) texel
;
484 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
485 *dst
= PACK_COLOR_8888_REV(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
490 /* MESA_FORMAT_ARGB8888 ******************************************************/
492 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
493 static void FETCH(f_argb8888
)( const struct gl_texture_image
*texImage
,
494 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
496 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
497 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
498 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
499 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
500 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
504 static void store_texel_argb8888(struct gl_texture_image
*texImage
,
505 GLint i
, GLint j
, GLint k
, const void *texel
)
507 const GLubyte
*rgba
= (const GLubyte
*) texel
;
508 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
509 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
514 /* MESA_FORMAT_ARGB8888_REV **************************************************/
516 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
517 static void FETCH(f_argb8888_rev
)( const struct gl_texture_image
*texImage
,
518 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
520 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
521 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
522 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
523 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
524 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
528 static void store_texel_argb8888_rev(struct gl_texture_image
*texImage
,
529 GLint i
, GLint j
, GLint k
, const void *texel
)
531 const GLubyte
*rgba
= (const GLubyte
*) texel
;
532 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
533 *dst
= PACK_COLOR_8888(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
], rgba
[ACOMP
]);
538 /* MESA_FORMAT_XRGB8888 ******************************************************/
540 /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
541 static void FETCH(f_xrgb8888
)( const struct gl_texture_image
*texImage
,
542 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
544 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
545 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
546 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
547 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
552 static void store_texel_xrgb8888(struct gl_texture_image
*texImage
,
553 GLint i
, GLint j
, GLint k
, const void *texel
)
555 const GLubyte
*rgba
= (const GLubyte
*) texel
;
556 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
557 *dst
= PACK_COLOR_8888(0xff, rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
562 /* MESA_FORMAT_RGB888 ********************************************************/
564 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
565 static void FETCH(f_rgb888
)( const struct gl_texture_image
*texImage
,
566 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
568 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
569 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
570 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
571 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
576 static void store_texel_rgb888(struct gl_texture_image
*texImage
,
577 GLint i
, GLint j
, GLint k
, const void *texel
)
579 const GLubyte
*rgba
= (const GLubyte
*) texel
;
580 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
581 dst
[0] = rgba
[BCOMP
];
582 dst
[1] = rgba
[GCOMP
];
583 dst
[2] = rgba
[RCOMP
];
588 /* MESA_FORMAT_BGR888 ********************************************************/
590 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
591 static void FETCH(f_bgr888
)( const struct gl_texture_image
*texImage
,
592 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
594 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
595 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[0] );
596 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
597 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[2] );
602 static void store_texel_bgr888(struct gl_texture_image
*texImage
,
603 GLint i
, GLint j
, GLint k
, const void *texel
)
605 const GLubyte
*rgba
= (const GLubyte
*) texel
;
606 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
607 dst
[0] = rgba
[RCOMP
];
608 dst
[1] = rgba
[GCOMP
];
609 dst
[2] = rgba
[BCOMP
];
614 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
615 instead of slow (g << 2) * 255 / 252 (always rounds down) */
617 /* MESA_FORMAT_RGB565 ********************************************************/
619 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
620 static void FETCH(f_rgb565
)( const struct gl_texture_image
*texImage
,
621 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
623 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
624 const GLushort s
= *src
;
625 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
626 texel
[GCOMP
] = ((s
>> 5 ) & 0x3f) * (1.0F
/ 63.0F
);
627 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
632 static void store_texel_rgb565(struct gl_texture_image
*texImage
,
633 GLint i
, GLint j
, GLint k
, const void *texel
)
635 const GLubyte
*rgba
= (const GLubyte
*) texel
;
636 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
637 *dst
= PACK_COLOR_565(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
642 /* MESA_FORMAT_RGB565_REV ****************************************************/
644 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
645 static void FETCH(f_rgb565_rev
)( const struct gl_texture_image
*texImage
,
646 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
648 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
649 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
650 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
651 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
652 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
657 static void store_texel_rgb565_rev(struct gl_texture_image
*texImage
,
658 GLint i
, GLint j
, GLint k
, const void *texel
)
660 const GLubyte
*rgba
= (const GLubyte
*) texel
;
661 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
662 *dst
= PACK_COLOR_565(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
667 /* MESA_FORMAT_ARGB4444 ******************************************************/
669 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
670 static void FETCH(f_argb4444
)( const struct gl_texture_image
*texImage
,
671 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
673 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
674 const GLushort s
= *src
;
675 texel
[RCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
676 texel
[GCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
677 texel
[BCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
678 texel
[ACOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
682 static void store_texel_argb4444(struct gl_texture_image
*texImage
,
683 GLint i
, GLint j
, GLint k
, const void *texel
)
685 const GLubyte
*rgba
= (const GLubyte
*) texel
;
686 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
687 *dst
= PACK_COLOR_4444(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
692 /* MESA_FORMAT_ARGB4444_REV **************************************************/
694 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
695 static void FETCH(f_argb4444_rev
)( const struct gl_texture_image
*texImage
,
696 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
698 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
699 texel
[RCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
700 texel
[GCOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
701 texel
[BCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
702 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
706 static void store_texel_argb4444_rev(struct gl_texture_image
*texImage
,
707 GLint i
, GLint j
, GLint k
, const void *texel
)
709 const GLubyte
*rgba
= (const GLubyte
*) texel
;
710 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
711 *dst
= PACK_COLOR_4444(rgba
[ACOMP
], rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
715 /* MESA_FORMAT_RGBA5551 ******************************************************/
717 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
718 static void FETCH(f_rgba5551
)( const struct gl_texture_image
*texImage
,
719 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
721 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
722 const GLushort s
= *src
;
723 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
724 texel
[GCOMP
] = ((s
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
725 texel
[BCOMP
] = ((s
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
726 texel
[ACOMP
] = ((s
) & 0x01) * 1.0F
;
730 static void store_texel_rgba5551(struct gl_texture_image
*texImage
,
731 GLint i
, GLint j
, GLint k
, const void *texel
)
733 const GLubyte
*rgba
= (const GLubyte
*) texel
;
734 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
735 *dst
= PACK_COLOR_5551(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
739 /* MESA_FORMAT_ARGB1555 ******************************************************/
741 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
742 static void FETCH(f_argb1555
)( const struct gl_texture_image
*texImage
,
743 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
745 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
746 const GLushort s
= *src
;
747 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
748 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
749 texel
[BCOMP
] = ((s
>> 0) & 0x1f) * (1.0F
/ 31.0F
);
750 texel
[ACOMP
] = ((s
>> 15) & 0x01) * 1.0F
;
754 static void store_texel_argb1555(struct gl_texture_image
*texImage
,
755 GLint i
, GLint j
, GLint k
, const void *texel
)
757 const GLubyte
*rgba
= (const GLubyte
*) texel
;
758 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
759 *dst
= PACK_COLOR_1555(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
764 /* MESA_FORMAT_ARGB1555_REV **************************************************/
766 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
767 static void FETCH(f_argb1555_rev
)( const struct gl_texture_image
*texImage
,
768 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
770 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
771 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
772 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
773 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
774 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
775 texel
[ACOMP
] = UBYTE_TO_FLOAT( ((s
>> 15) & 0x01) * 255 );
779 static void store_texel_argb1555_rev(struct gl_texture_image
*texImage
,
780 GLint i
, GLint j
, GLint k
, const void *texel
)
782 const GLubyte
*rgba
= (const GLubyte
*) texel
;
783 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
784 *dst
= PACK_COLOR_1555_REV(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
789 /* MESA_FORMAT_AL88 **********************************************************/
791 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
792 static void FETCH(f_al88
)( const struct gl_texture_image
*texImage
,
793 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
795 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
798 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
799 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
803 static void store_texel_al88(struct gl_texture_image
*texImage
,
804 GLint i
, GLint j
, GLint k
, const void *texel
)
806 const GLubyte
*rgba
= (const GLubyte
*) texel
;
807 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
808 *dst
= PACK_COLOR_88(rgba
[ACOMP
], rgba
[RCOMP
]);
813 /* MESA_FORMAT_AL88_REV ******************************************************/
815 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
816 static void FETCH(f_al88_rev
)( const struct gl_texture_image
*texImage
,
817 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
819 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
822 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
823 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
827 static void store_texel_al88_rev(struct gl_texture_image
*texImage
,
828 GLint i
, GLint j
, GLint k
, const void *texel
)
830 const GLubyte
*rgba
= (const GLubyte
*) texel
;
831 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
832 *dst
= PACK_COLOR_88(rgba
[RCOMP
], rgba
[ACOMP
]);
837 /* MESA_FORMAT_AL1616 ********************************************************/
839 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
840 static void FETCH(f_al1616
)( const struct gl_texture_image
*texImage
,
841 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
843 const GLuint s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
846 texel
[BCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
847 texel
[ACOMP
] = USHORT_TO_FLOAT( s
>> 16 );
851 static void store_texel_al1616(struct gl_texture_image
*texImage
,
852 GLint i
, GLint j
, GLint k
, const void *texel
)
854 const GLushort
*rgba
= (const GLushort
*) texel
;
855 GLuint
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
856 *dst
= PACK_COLOR_1616(rgba
[ACOMP
], rgba
[RCOMP
]);
861 /* MESA_FORMAT_AL1616_REV ****************************************************/
863 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
864 static void FETCH(f_al1616_rev
)( const struct gl_texture_image
*texImage
,
865 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
867 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
870 texel
[BCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
871 texel
[ACOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
875 static void store_texel_al1616_rev(struct gl_texture_image
*texImage
,
876 GLint i
, GLint j
, GLint k
, const void *texel
)
878 const GLushort
*rgba
= (const GLushort
*) texel
;
879 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
880 *dst
= PACK_COLOR_1616(rgba
[RCOMP
], rgba
[ACOMP
]);
885 /* MESA_FORMAT_RGB332 ********************************************************/
887 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
888 static void FETCH(f_rgb332
)( const struct gl_texture_image
*texImage
,
889 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
891 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
892 const GLubyte s
= *src
;
893 texel
[RCOMP
] = ((s
>> 5) & 0x7) * (1.0F
/ 7.0F
);
894 texel
[GCOMP
] = ((s
>> 2) & 0x7) * (1.0F
/ 7.0F
);
895 texel
[BCOMP
] = ((s
) & 0x3) * (1.0F
/ 3.0F
);
900 static void store_texel_rgb332(struct gl_texture_image
*texImage
,
901 GLint i
, GLint j
, GLint k
, const void *texel
)
903 const GLubyte
*rgba
= (const GLubyte
*) texel
;
904 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
905 *dst
= PACK_COLOR_332(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
910 /* MESA_FORMAT_A8 ************************************************************/
912 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
913 static void FETCH(f_a8
)( const struct gl_texture_image
*texImage
,
914 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
916 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
920 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
924 static void store_texel_a8(struct gl_texture_image
*texImage
,
925 GLint i
, GLint j
, GLint k
, const void *texel
)
927 const GLubyte
*rgba
= (const GLubyte
*) texel
;
928 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
934 /* MESA_FORMAT_L8 ************************************************************/
936 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
937 static void FETCH(f_l8
)( const struct gl_texture_image
*texImage
,
938 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
940 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
943 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
948 static void store_texel_l8(struct gl_texture_image
*texImage
,
949 GLint i
, GLint j
, GLint k
, const void *texel
)
951 const GLubyte
*rgba
= (const GLubyte
*) texel
;
952 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
958 /* MESA_FORMAT_I8 ************************************************************/
960 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
961 static void FETCH(f_i8
)( const struct gl_texture_image
*texImage
,
962 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
964 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
968 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
972 static void store_texel_i8(struct gl_texture_image
*texImage
,
973 GLint i
, GLint j
, GLint k
, const void *texel
)
975 const GLubyte
*rgba
= (const GLubyte
*) texel
;
976 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
982 /* MESA_FORMAT_CI8 ***********************************************************/
984 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
985 * color table, and return 4 GLchans.
987 static void FETCH(f_ci8
)( const struct gl_texture_image
*texImage
,
988 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
990 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
991 const struct gl_color_table
*palette
;
993 GET_CURRENT_CONTEXT(ctx
);
995 if (ctx
->Texture
.SharedPalette
) {
996 palette
= &ctx
->Texture
.Palette
;
999 palette
= &texImage
->TexObject
->Palette
;
1001 if (palette
->Size
== 0)
1002 return; /* undefined results */
1004 /* Mask the index against size of palette to avoid going out of bounds */
1005 index
= (*src
) & (palette
->Size
- 1);
1008 const GLfloat
*table
= palette
->TableF
;
1009 switch (palette
->_BaseFormat
) {
1013 texel
[BCOMP
] = 0.0F
;
1014 texel
[ACOMP
] = table
[index
];
1019 texel
[BCOMP
] = table
[index
];
1020 texel
[ACOMP
] = 1.0F
;
1026 texel
[ACOMP
] = table
[index
];
1028 case GL_LUMINANCE_ALPHA
:
1031 texel
[BCOMP
] = table
[index
* 2 + 0];
1032 texel
[ACOMP
] = table
[index
* 2 + 1];
1035 texel
[RCOMP
] = table
[index
* 3 + 0];
1036 texel
[GCOMP
] = table
[index
* 3 + 1];
1037 texel
[BCOMP
] = table
[index
* 3 + 2];
1038 texel
[ACOMP
] = 1.0F
;
1041 texel
[RCOMP
] = table
[index
* 4 + 0];
1042 texel
[GCOMP
] = table
[index
* 4 + 1];
1043 texel
[BCOMP
] = table
[index
* 4 + 2];
1044 texel
[ACOMP
] = table
[index
* 4 + 3];
1047 _mesa_problem(ctx
, "Bad palette format in fetch_texel_ci8");
1054 static void store_texel_ci8(struct gl_texture_image
*texImage
,
1055 GLint i
, GLint j
, GLint k
, const void *texel
)
1057 const GLubyte
*index
= (const GLubyte
*) texel
;
1058 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1064 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1065 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1066 static void FETCH(srgb8
)(const struct gl_texture_image
*texImage
,
1067 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1069 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1070 texel
[RCOMP
] = nonlinear_to_linear(src
[2]);
1071 texel
[GCOMP
] = nonlinear_to_linear(src
[1]);
1072 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1073 texel
[ACOMP
] = 1.0F
;
1077 static void store_texel_srgb8(struct gl_texture_image
*texImage
,
1078 GLint i
, GLint j
, GLint k
, const void *texel
)
1080 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1081 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1082 dst
[0] = rgba
[BCOMP
]; /* no conversion */
1083 dst
[1] = rgba
[GCOMP
];
1084 dst
[2] = rgba
[RCOMP
];
1088 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1089 static void FETCH(srgba8
)(const struct gl_texture_image
*texImage
,
1090 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1092 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1093 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 24) );
1094 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1095 texel
[BCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1096 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff ); /* linear! */
1100 static void store_texel_srgba8(struct gl_texture_image
*texImage
,
1101 GLint i
, GLint j
, GLint k
, const void *texel
)
1103 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1104 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1105 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1109 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1110 static void FETCH(sargb8
)(const struct gl_texture_image
*texImage
,
1111 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1113 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1114 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1115 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1116 texel
[BCOMP
] = nonlinear_to_linear( (s
) & 0xff );
1117 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) ); /* linear! */
1121 static void store_texel_sargb8(struct gl_texture_image
*texImage
,
1122 GLint i
, GLint j
, GLint k
, const void *texel
)
1124 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1125 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1126 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1130 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1131 static void FETCH(sl8
)(const struct gl_texture_image
*texImage
,
1132 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1134 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1137 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1138 texel
[ACOMP
] = 1.0F
;
1142 static void store_texel_sl8(struct gl_texture_image
*texImage
,
1143 GLint i
, GLint j
, GLint k
, const void *texel
)
1145 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1146 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1147 dst
[0] = rgba
[RCOMP
];
1151 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1152 static void FETCH(sla8
)(const struct gl_texture_image
*texImage
,
1153 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1155 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1158 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1159 texel
[ACOMP
] = UBYTE_TO_FLOAT(src
[1]); /* linear */
1163 static void store_texel_sla8(struct gl_texture_image
*texImage
,
1164 GLint i
, GLint j
, GLint k
, const void *texel
)
1166 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1167 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1168 dst
[0] = rgba
[RCOMP
];
1169 dst
[1] = rgba
[ACOMP
];
1174 /* MESA_FORMAT_DUDV8 ********************************************************/
1176 /* this format by definition produces 0,0,0,1 as rgba values,
1177 however we'll return the dudv values as rg and fix up elsewhere */
1178 static void FETCH(dudv8
)(const struct gl_texture_image
*texImage
,
1179 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1181 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 2);
1182 texel
[RCOMP
] = BYTE_TO_FLOAT(src
[0]);
1183 texel
[GCOMP
] = BYTE_TO_FLOAT(src
[1]);
1188 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1190 static void FETCH(signed_rgba8888
)( const struct gl_texture_image
*texImage
,
1191 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1193 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1194 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (s
>> 24) );
1195 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (s
>> 16) & 0xff );
1196 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (s
>> 8) & 0xff );
1197 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (s
) & 0xff );
1201 static void store_texel_signed_rgba8888(struct gl_texture_image
*texImage
,
1202 GLint i
, GLint j
, GLint k
, const void *texel
)
1204 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1205 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1206 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1210 static void FETCH(signed_rgba8888_rev
)( const struct gl_texture_image
*texImage
,
1211 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1213 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1214 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (s
) & 0xff );
1215 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (s
>> 8) & 0xff );
1216 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (s
>> 16) & 0xff );
1217 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (s
>> 24) );
1221 static void store_texel_signed_rgba8888_rev(struct gl_texture_image
*texImage
,
1222 GLint i
, GLint j
, GLint k
, const void *texel
)
1224 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1225 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1226 *dst
= PACK_COLOR_8888_REV(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1232 /* MESA_FORMAT_YCBCR *********************************************************/
1234 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
1235 * We convert YCbCr to RGB here.
1237 static void FETCH(f_ycbcr
)( const struct gl_texture_image
*texImage
,
1238 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1240 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1241 const GLushort
*src1
= src0
+ 1; /* odd */
1242 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1243 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1244 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1245 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1246 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1247 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1248 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1249 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1250 r
*= (1.0F
/ 255.0F
);
1251 g
*= (1.0F
/ 255.0F
);
1252 b
*= (1.0F
/ 255.0F
);
1253 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1254 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1255 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1256 texel
[ACOMP
] = 1.0F
;
1260 static void store_texel_ycbcr(struct gl_texture_image
*texImage
,
1261 GLint i
, GLint j
, GLint k
, const void *texel
)
1273 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1275 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
1276 * We convert YCbCr to RGB here.
1278 static void FETCH(f_ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1279 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1281 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1282 const GLushort
*src1
= src0
+ 1; /* odd */
1283 const GLubyte y0
= *src0
& 0xff; /* luminance */
1284 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1285 const GLubyte y1
= *src1
& 0xff; /* luminance */
1286 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1287 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1288 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1289 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1290 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1291 r
*= (1.0F
/ 255.0F
);
1292 g
*= (1.0F
/ 255.0F
);
1293 b
*= (1.0F
/ 255.0F
);
1294 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1295 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1296 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1297 texel
[ACOMP
] = 1.0F
;
1301 static void store_texel_ycbcr_rev(struct gl_texture_image
*texImage
,
1302 GLint i
, GLint j
, GLint k
, const void *texel
)
1314 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1316 static void FETCH(f_z24_s8
)( const struct gl_texture_image
*texImage
,
1317 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1319 /* only return Z, not stencil data */
1320 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1321 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
1322 texel
[0] = ((*src
) >> 8) * scale
;
1323 ASSERT(texImage
->TexFormat
== MESA_FORMAT_Z24_S8
);
1324 ASSERT(texel
[0] >= 0.0F
);
1325 ASSERT(texel
[0] <= 1.0F
);
1329 static void store_texel_z24_s8(struct gl_texture_image
*texImage
,
1330 GLint i
, GLint j
, GLint k
, const void *texel
)
1332 /* only store Z, not stencil */
1333 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1334 GLfloat depth
= *((GLfloat
*) texel
);
1335 GLuint zi
= ((GLuint
) (depth
* 0xffffff)) << 8;
1336 *dst
= zi
| (*dst
& 0xff);
1341 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1343 static void FETCH(f_s8_z24
)( const struct gl_texture_image
*texImage
,
1344 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1346 /* only return Z, not stencil data */
1347 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1348 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
1349 texel
[0] = ((*src
) & 0x00ffffff) * scale
;
1350 ASSERT(texImage
->TexFormat
== MESA_FORMAT_S8_Z24
);
1351 ASSERT(texel
[0] >= 0.0F
);
1352 ASSERT(texel
[0] <= 1.0F
);
1356 static void store_texel_s8_z24(struct gl_texture_image
*texImage
,
1357 GLint i
, GLint j
, GLint k
, const void *texel
)
1359 /* only store Z, not stencil */
1360 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1361 GLfloat depth
= *((GLfloat
*) texel
);
1362 GLuint zi
= (GLuint
) (depth
* 0xffffff);
1363 *dst
= zi
| (*dst
& 0xff000000);