3a75cdcefe95169e881466e94b610ee77c409d12
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_XRGB8888_REV **************************************************/
564 /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
565 static void FETCH(f_xrgb8888_rev
)( const struct gl_texture_image
*texImage
,
566 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
568 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
569 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
570 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
571 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
576 static void store_texel_xrgb8888_rev(struct gl_texture_image
*texImage
,
577 GLint i
, GLint j
, GLint k
, const void *texel
)
579 const GLubyte
*rgba
= (const GLubyte
*) texel
;
580 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
581 *dst
= PACK_COLOR_8888(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
], 0xff);
586 /* MESA_FORMAT_RGB888 ********************************************************/
588 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
589 static void FETCH(f_rgb888
)( const struct gl_texture_image
*texImage
,
590 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
592 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
593 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
594 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
595 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
600 static void store_texel_rgb888(struct gl_texture_image
*texImage
,
601 GLint i
, GLint j
, GLint k
, const void *texel
)
603 const GLubyte
*rgba
= (const GLubyte
*) texel
;
604 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
605 dst
[0] = rgba
[BCOMP
];
606 dst
[1] = rgba
[GCOMP
];
607 dst
[2] = rgba
[RCOMP
];
612 /* MESA_FORMAT_BGR888 ********************************************************/
614 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
615 static void FETCH(f_bgr888
)( const struct gl_texture_image
*texImage
,
616 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
618 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
619 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[0] );
620 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
621 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[2] );
626 static void store_texel_bgr888(struct gl_texture_image
*texImage
,
627 GLint i
, GLint j
, GLint k
, const void *texel
)
629 const GLubyte
*rgba
= (const GLubyte
*) texel
;
630 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
631 dst
[0] = rgba
[RCOMP
];
632 dst
[1] = rgba
[GCOMP
];
633 dst
[2] = rgba
[BCOMP
];
638 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
639 instead of slow (g << 2) * 255 / 252 (always rounds down) */
641 /* MESA_FORMAT_RGB565 ********************************************************/
643 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
644 static void FETCH(f_rgb565
)( const struct gl_texture_image
*texImage
,
645 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
647 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
648 const GLushort s
= *src
;
649 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
650 texel
[GCOMP
] = ((s
>> 5 ) & 0x3f) * (1.0F
/ 63.0F
);
651 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
656 static void store_texel_rgb565(struct gl_texture_image
*texImage
,
657 GLint i
, GLint j
, GLint k
, const void *texel
)
659 const GLubyte
*rgba
= (const GLubyte
*) texel
;
660 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
661 *dst
= PACK_COLOR_565(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
666 /* MESA_FORMAT_RGB565_REV ****************************************************/
668 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
669 static void FETCH(f_rgb565_rev
)( const struct gl_texture_image
*texImage
,
670 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
672 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
673 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
674 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
675 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
676 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
681 static void store_texel_rgb565_rev(struct gl_texture_image
*texImage
,
682 GLint i
, GLint j
, GLint k
, const void *texel
)
684 const GLubyte
*rgba
= (const GLubyte
*) texel
;
685 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
686 *dst
= PACK_COLOR_565(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
691 /* MESA_FORMAT_ARGB4444 ******************************************************/
693 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
694 static void FETCH(f_argb4444
)( const struct gl_texture_image
*texImage
,
695 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
697 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
698 const GLushort s
= *src
;
699 texel
[RCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
700 texel
[GCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
701 texel
[BCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
702 texel
[ACOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
706 static void store_texel_argb4444(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
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
716 /* MESA_FORMAT_ARGB4444_REV **************************************************/
718 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
719 static void FETCH(f_argb4444_rev
)( const struct gl_texture_image
*texImage
,
720 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
722 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
723 texel
[RCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
724 texel
[GCOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
725 texel
[BCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
726 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
730 static void store_texel_argb4444_rev(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_4444(rgba
[ACOMP
], rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
739 /* MESA_FORMAT_RGBA5551 ******************************************************/
741 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
742 static void FETCH(f_rgba5551
)( 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
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
748 texel
[GCOMP
] = ((s
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
749 texel
[BCOMP
] = ((s
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
750 texel
[ACOMP
] = ((s
) & 0x01) * 1.0F
;
754 static void store_texel_rgba5551(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_5551(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
763 /* MESA_FORMAT_ARGB1555 ******************************************************/
765 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
766 static void FETCH(f_argb1555
)( const struct gl_texture_image
*texImage
,
767 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
769 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
770 const GLushort s
= *src
;
771 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
772 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
773 texel
[BCOMP
] = ((s
>> 0) & 0x1f) * (1.0F
/ 31.0F
);
774 texel
[ACOMP
] = ((s
>> 15) & 0x01) * 1.0F
;
778 static void store_texel_argb1555(struct gl_texture_image
*texImage
,
779 GLint i
, GLint j
, GLint k
, const void *texel
)
781 const GLubyte
*rgba
= (const GLubyte
*) texel
;
782 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
783 *dst
= PACK_COLOR_1555(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
788 /* MESA_FORMAT_ARGB1555_REV **************************************************/
790 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
791 static void FETCH(f_argb1555_rev
)( const struct gl_texture_image
*texImage
,
792 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
794 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
795 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
796 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
797 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
798 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
799 texel
[ACOMP
] = UBYTE_TO_FLOAT( ((s
>> 15) & 0x01) * 255 );
803 static void store_texel_argb1555_rev(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_1555_REV(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
813 /* MESA_FORMAT_ARGB2101010 ***************************************************/
815 /* Fetch texel from 1D, 2D or 3D argb2101010 texture, return 4 GLchans */
816 static void FETCH(f_argb2101010
)( const struct gl_texture_image
*texImage
,
817 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
819 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
820 const GLuint s
= *src
;
821 texel
[RCOMP
] = ((s
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
822 texel
[GCOMP
] = ((s
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
823 texel
[BCOMP
] = ((s
>> 0) & 0x3ff) * (1.0F
/ 1023.0F
);
824 texel
[ACOMP
] = ((s
>> 30) & 0x03) * (1.0F
/ 3.0F
);
828 static void store_texel_argb2101010(struct gl_texture_image
*texImage
,
829 GLint i
, GLint j
, GLint k
, const void *texel
)
831 const GLubyte
*rgba
= (const GLubyte
*) texel
;
832 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
833 *dst
= PACK_COLOR_2101010(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
838 /* MESA_FORMAT_RG88 **********************************************************/
840 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
841 static void FETCH(f_rg88
)( const struct gl_texture_image
*texImage
,
842 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
844 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
845 texel
[RCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
846 texel
[GCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
852 static void store_texel_rg88(struct gl_texture_image
*texImage
,
853 GLint i
, GLint j
, GLint k
, const void *texel
)
855 const GLubyte
*rgba
= (const GLubyte
*) texel
;
856 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
857 *dst
= PACK_COLOR_88(rgba
[RCOMP
], rgba
[GCOMP
]);
862 /* MESA_FORMAT_RG88_REV ******************************************************/
864 /* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
865 static void FETCH(f_rg88_rev
)( const struct gl_texture_image
*texImage
,
866 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
868 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
869 texel
[RCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
870 texel
[GCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
876 static void store_texel_rg88_rev(struct gl_texture_image
*texImage
,
877 GLint i
, GLint j
, GLint k
, const void *texel
)
879 const GLubyte
*rgba
= (const GLubyte
*) texel
;
880 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
881 *dst
= PACK_COLOR_88(rgba
[GCOMP
], rgba
[RCOMP
]);
886 /* MESA_FORMAT_AL44 **********************************************************/
888 /* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
889 static void FETCH(f_al44
)( const struct gl_texture_image
*texImage
,
890 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
892 const GLubyte s
= *TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
895 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
& 0x0f) << 4 );
896 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
& 0xf0 );
900 static void store_texel_al44(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_44(rgba
[ACOMP
], rgba
[RCOMP
]);
910 /* MESA_FORMAT_AL88 **********************************************************/
912 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
913 static void FETCH(f_al88
)( const struct gl_texture_image
*texImage
,
914 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
916 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
919 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
920 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
924 static void store_texel_al88(struct gl_texture_image
*texImage
,
925 GLint i
, GLint j
, GLint k
, const void *texel
)
927 const GLubyte
*rgba
= (const GLubyte
*) texel
;
928 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
929 *dst
= PACK_COLOR_88(rgba
[ACOMP
], rgba
[RCOMP
]);
934 /* MESA_FORMAT_R8 ************************************************************/
936 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
937 static void FETCH(f_r8
)(const struct gl_texture_image
*texImage
,
938 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
940 const GLubyte s
= *TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
941 texel
[RCOMP
] = UBYTE_TO_FLOAT(s
);
948 static void store_texel_r8(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_R16 ***********************************************************/
960 /* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
961 static void FETCH(f_r16
)(const struct gl_texture_image
*texImage
,
962 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
964 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
965 texel
[RCOMP
] = USHORT_TO_FLOAT(s
);
972 static void store_texel_r16(struct gl_texture_image
*texImage
,
973 GLint i
, GLint j
, GLint k
, const void *texel
)
975 const GLushort
*rgba
= (const GLushort
*) texel
;
976 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
982 /* MESA_FORMAT_AL88_REV ******************************************************/
984 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
985 static void FETCH(f_al88_rev
)( const struct gl_texture_image
*texImage
,
986 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
988 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
991 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
992 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
996 static void store_texel_al88_rev(struct gl_texture_image
*texImage
,
997 GLint i
, GLint j
, GLint k
, const void *texel
)
999 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1000 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1001 *dst
= PACK_COLOR_88(rgba
[RCOMP
], rgba
[ACOMP
]);
1006 /* MESA_FORMAT_RG1616 ********************************************************/
1008 /* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
1009 static void FETCH(f_rg1616
)( const struct gl_texture_image
*texImage
,
1010 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1012 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1013 texel
[RCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
1014 texel
[GCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
1020 static void store_texel_rg1616(struct gl_texture_image
*texImage
,
1021 GLint i
, GLint j
, GLint k
, const void *texel
)
1023 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1024 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1025 *dst
= PACK_COLOR_1616(rgba
[RCOMP
], rgba
[GCOMP
]);
1030 /* MESA_FORMAT_RG1616_REV ****************************************************/
1032 /* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
1033 static void FETCH(f_rg1616_rev
)( const struct gl_texture_image
*texImage
,
1034 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1036 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1037 texel
[RCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
1038 texel
[GCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
1044 static void store_texel_rg1616_rev(struct gl_texture_image
*texImage
,
1045 GLint i
, GLint j
, GLint k
, const void *texel
)
1047 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1048 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1049 *dst
= PACK_COLOR_1616(rgba
[GCOMP
], rgba
[RCOMP
]);
1054 /* MESA_FORMAT_AL1616 ********************************************************/
1056 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
1057 static void FETCH(f_al1616
)( const struct gl_texture_image
*texImage
,
1058 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1060 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1063 texel
[BCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
1064 texel
[ACOMP
] = USHORT_TO_FLOAT( s
>> 16 );
1068 static void store_texel_al1616(struct gl_texture_image
*texImage
,
1069 GLint i
, GLint j
, GLint k
, const void *texel
)
1071 const GLushort
*rgba
= (const GLushort
*) texel
;
1072 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1073 *dst
= PACK_COLOR_1616(rgba
[ACOMP
], rgba
[RCOMP
]);
1078 /* MESA_FORMAT_AL1616_REV ****************************************************/
1080 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
1081 static void FETCH(f_al1616_rev
)( const struct gl_texture_image
*texImage
,
1082 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1084 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1087 texel
[BCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
1088 texel
[ACOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
1092 static void store_texel_al1616_rev(struct gl_texture_image
*texImage
,
1093 GLint i
, GLint j
, GLint k
, const void *texel
)
1095 const GLushort
*rgba
= (const GLushort
*) texel
;
1096 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1097 *dst
= PACK_COLOR_1616(rgba
[RCOMP
], rgba
[ACOMP
]);
1102 /* MESA_FORMAT_RGB332 ********************************************************/
1104 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1105 static void FETCH(f_rgb332
)( const struct gl_texture_image
*texImage
,
1106 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1108 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1109 const GLubyte s
= *src
;
1110 texel
[RCOMP
] = ((s
>> 5) & 0x7) * (1.0F
/ 7.0F
);
1111 texel
[GCOMP
] = ((s
>> 2) & 0x7) * (1.0F
/ 7.0F
);
1112 texel
[BCOMP
] = ((s
) & 0x3) * (1.0F
/ 3.0F
);
1113 texel
[ACOMP
] = 1.0F
;
1117 static void store_texel_rgb332(struct gl_texture_image
*texImage
,
1118 GLint i
, GLint j
, GLint k
, const void *texel
)
1120 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1121 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1122 *dst
= PACK_COLOR_332(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1127 /* MESA_FORMAT_A8 ************************************************************/
1129 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1130 static void FETCH(f_a8
)( const struct gl_texture_image
*texImage
,
1131 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1133 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1136 texel
[BCOMP
] = 0.0F
;
1137 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1141 static void store_texel_a8(struct gl_texture_image
*texImage
,
1142 GLint i
, GLint j
, GLint k
, const void *texel
)
1144 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1145 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1151 /* MESA_FORMAT_A16 ************************************************************/
1153 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1154 static void FETCH(f_a16
)( const struct gl_texture_image
*texImage
,
1155 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1157 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1160 texel
[BCOMP
] = 0.0F
;
1161 texel
[ACOMP
] = USHORT_TO_FLOAT( src
[0] );
1165 static void store_texel_a16(struct gl_texture_image
*texImage
,
1166 GLint i
, GLint j
, GLint k
, const void *texel
)
1168 const GLushort
*rgba
= (const GLushort
*) texel
;
1169 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1175 /* MESA_FORMAT_L8 ************************************************************/
1177 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1178 static void FETCH(f_l8
)( const struct gl_texture_image
*texImage
,
1179 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1181 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1184 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
1185 texel
[ACOMP
] = 1.0F
;
1189 static void store_texel_l8(struct gl_texture_image
*texImage
,
1190 GLint i
, GLint j
, GLint k
, const void *texel
)
1192 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1193 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1199 /* MESA_FORMAT_I8 ************************************************************/
1201 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1202 static void FETCH(f_i8
)( const struct gl_texture_image
*texImage
,
1203 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1205 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1209 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1213 static void store_texel_i8(struct gl_texture_image
*texImage
,
1214 GLint i
, GLint j
, GLint k
, const void *texel
)
1216 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1217 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1223 /* MESA_FORMAT_CI8 ***********************************************************/
1225 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1226 * color table, and return 4 GLchans.
1228 static void FETCH(f_ci8
)( const struct gl_texture_image
*texImage
,
1229 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1231 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1232 const struct gl_color_table
*palette
;
1234 GET_CURRENT_CONTEXT(ctx
);
1236 if (ctx
->Texture
.SharedPalette
) {
1237 palette
= &ctx
->Texture
.Palette
;
1240 palette
= &texImage
->TexObject
->Palette
;
1242 if (palette
->Size
== 0)
1243 return; /* undefined results */
1245 /* Mask the index against size of palette to avoid going out of bounds */
1246 index
= (*src
) & (palette
->Size
- 1);
1249 const GLfloat
*table
= palette
->TableF
;
1250 switch (palette
->_BaseFormat
) {
1254 texel
[BCOMP
] = 0.0F
;
1255 texel
[ACOMP
] = table
[index
];
1260 texel
[BCOMP
] = table
[index
];
1261 texel
[ACOMP
] = 1.0F
;
1267 texel
[ACOMP
] = table
[index
];
1269 case GL_LUMINANCE_ALPHA
:
1272 texel
[BCOMP
] = table
[index
* 2 + 0];
1273 texel
[ACOMP
] = table
[index
* 2 + 1];
1276 texel
[RCOMP
] = table
[index
* 3 + 0];
1277 texel
[GCOMP
] = table
[index
* 3 + 1];
1278 texel
[BCOMP
] = table
[index
* 3 + 2];
1279 texel
[ACOMP
] = 1.0F
;
1282 texel
[RCOMP
] = table
[index
* 4 + 0];
1283 texel
[GCOMP
] = table
[index
* 4 + 1];
1284 texel
[BCOMP
] = table
[index
* 4 + 2];
1285 texel
[ACOMP
] = table
[index
* 4 + 3];
1288 _mesa_problem(ctx
, "Bad palette format in fetch_texel_ci8");
1295 static void store_texel_ci8(struct gl_texture_image
*texImage
,
1296 GLint i
, GLint j
, GLint k
, const void *texel
)
1298 const GLubyte
*index
= (const GLubyte
*) texel
;
1299 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1305 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1306 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1307 static void FETCH(srgb8
)(const struct gl_texture_image
*texImage
,
1308 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1310 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1311 texel
[RCOMP
] = nonlinear_to_linear(src
[2]);
1312 texel
[GCOMP
] = nonlinear_to_linear(src
[1]);
1313 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1314 texel
[ACOMP
] = 1.0F
;
1318 static void store_texel_srgb8(struct gl_texture_image
*texImage
,
1319 GLint i
, GLint j
, GLint k
, const void *texel
)
1321 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1322 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1323 dst
[0] = rgba
[BCOMP
]; /* no conversion */
1324 dst
[1] = rgba
[GCOMP
];
1325 dst
[2] = rgba
[RCOMP
];
1329 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1330 static void FETCH(srgba8
)(const struct gl_texture_image
*texImage
,
1331 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1333 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1334 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 24) );
1335 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1336 texel
[BCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1337 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff ); /* linear! */
1341 static void store_texel_srgba8(struct gl_texture_image
*texImage
,
1342 GLint i
, GLint j
, GLint k
, const void *texel
)
1344 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1345 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1346 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1350 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1351 static void FETCH(sargb8
)(const struct gl_texture_image
*texImage
,
1352 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1354 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1355 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1356 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1357 texel
[BCOMP
] = nonlinear_to_linear( (s
) & 0xff );
1358 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) ); /* linear! */
1362 static void store_texel_sargb8(struct gl_texture_image
*texImage
,
1363 GLint i
, GLint j
, GLint k
, const void *texel
)
1365 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1366 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1367 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1371 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1372 static void FETCH(sl8
)(const struct gl_texture_image
*texImage
,
1373 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1375 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1378 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1379 texel
[ACOMP
] = 1.0F
;
1383 static void store_texel_sl8(struct gl_texture_image
*texImage
,
1384 GLint i
, GLint j
, GLint k
, const void *texel
)
1386 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1387 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1388 dst
[0] = rgba
[RCOMP
];
1392 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1393 static void FETCH(sla8
)(const struct gl_texture_image
*texImage
,
1394 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1396 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1399 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1400 texel
[ACOMP
] = UBYTE_TO_FLOAT(src
[1]); /* linear */
1404 static void store_texel_sla8(struct gl_texture_image
*texImage
,
1405 GLint i
, GLint j
, GLint k
, const void *texel
)
1407 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1408 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1409 dst
[0] = rgba
[RCOMP
];
1410 dst
[1] = rgba
[ACOMP
];
1415 /* MESA_FORMAT_RGBA_INT8 **************************************************/
1418 FETCH(rgba_int8
)(const struct gl_texture_image
*texImage
,
1419 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1421 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 4);
1422 texel
[RCOMP
] = (GLfloat
) src
[0];
1423 texel
[GCOMP
] = (GLfloat
) src
[1];
1424 texel
[BCOMP
] = (GLfloat
) src
[2];
1425 texel
[ACOMP
] = (GLfloat
) src
[3];
1430 store_texel_rgba_int8(struct gl_texture_image
*texImage
,
1431 GLint i
, GLint j
, GLint k
, const void *texel
)
1433 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1434 GLbyte
*dst
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 4);
1435 dst
[0] = rgba
[RCOMP
];
1436 dst
[1] = rgba
[GCOMP
];
1437 dst
[2] = rgba
[BCOMP
];
1438 dst
[3] = rgba
[ACOMP
];
1443 /* MESA_FORMAT_RGBA_INT16 **************************************************/
1446 FETCH(rgba_int16
)(const struct gl_texture_image
*texImage
,
1447 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1449 const GLshort
*src
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1450 texel
[RCOMP
] = (GLfloat
) src
[0];
1451 texel
[GCOMP
] = (GLfloat
) src
[1];
1452 texel
[BCOMP
] = (GLfloat
) src
[2];
1453 texel
[ACOMP
] = (GLfloat
) src
[3];
1458 store_texel_rgba_int16(struct gl_texture_image
*texImage
,
1459 GLint i
, GLint j
, GLint k
, const void *texel
)
1461 const GLshort
*rgba
= (const GLshort
*) texel
;
1462 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1463 dst
[0] = rgba
[RCOMP
];
1464 dst
[1] = rgba
[GCOMP
];
1465 dst
[2] = rgba
[BCOMP
];
1466 dst
[3] = rgba
[ACOMP
];
1471 /* MESA_FORMAT_RGBA_INT32 **************************************************/
1474 FETCH(rgba_int32
)(const struct gl_texture_image
*texImage
,
1475 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1477 const GLint
*src
= TEXEL_ADDR(GLint
, texImage
, i
, j
, k
, 4);
1478 texel
[RCOMP
] = (GLfloat
) src
[0];
1479 texel
[GCOMP
] = (GLfloat
) src
[1];
1480 texel
[BCOMP
] = (GLfloat
) src
[2];
1481 texel
[ACOMP
] = (GLfloat
) src
[3];
1486 store_texel_rgba_int32(struct gl_texture_image
*texImage
,
1487 GLint i
, GLint j
, GLint k
, const void *texel
)
1489 const GLint
*rgba
= (const GLint
*) texel
;
1490 GLint
*dst
= TEXEL_ADDR(GLint
, texImage
, i
, j
, k
, 4);
1491 dst
[0] = rgba
[RCOMP
];
1492 dst
[1] = rgba
[GCOMP
];
1493 dst
[2] = rgba
[BCOMP
];
1494 dst
[3] = rgba
[ACOMP
];
1499 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
1502 FETCH(rgba_uint8
)(const struct gl_texture_image
*texImage
,
1503 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1505 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 4);
1506 texel
[RCOMP
] = (GLfloat
) src
[0];
1507 texel
[GCOMP
] = (GLfloat
) src
[1];
1508 texel
[BCOMP
] = (GLfloat
) src
[2];
1509 texel
[ACOMP
] = (GLfloat
) src
[3];
1514 store_texel_rgba_uint8(struct gl_texture_image
*texImage
,
1515 GLint i
, GLint j
, GLint k
, const void *texel
)
1517 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1518 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 4);
1519 dst
[0] = rgba
[RCOMP
];
1520 dst
[1] = rgba
[GCOMP
];
1521 dst
[2] = rgba
[BCOMP
];
1522 dst
[3] = rgba
[ACOMP
];
1527 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
1530 FETCH(rgba_uint16
)(const struct gl_texture_image
*texImage
,
1531 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1533 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1534 texel
[RCOMP
] = (GLfloat
) src
[0];
1535 texel
[GCOMP
] = (GLfloat
) src
[1];
1536 texel
[BCOMP
] = (GLfloat
) src
[2];
1537 texel
[ACOMP
] = (GLfloat
) src
[3];
1542 store_texel_rgba_uint16(struct gl_texture_image
*texImage
,
1543 GLint i
, GLint j
, GLint k
, const void *texel
)
1545 const GLushort
*rgba
= (const GLushort
*) texel
;
1546 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1547 dst
[0] = rgba
[RCOMP
];
1548 dst
[1] = rgba
[GCOMP
];
1549 dst
[2] = rgba
[BCOMP
];
1550 dst
[3] = rgba
[ACOMP
];
1555 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
1558 FETCH(rgba_uint32
)(const struct gl_texture_image
*texImage
,
1559 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1561 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 4);
1562 texel
[RCOMP
] = (GLfloat
) src
[0];
1563 texel
[GCOMP
] = (GLfloat
) src
[1];
1564 texel
[BCOMP
] = (GLfloat
) src
[2];
1565 texel
[ACOMP
] = (GLfloat
) src
[3];
1570 store_texel_rgba_uint32(struct gl_texture_image
*texImage
,
1571 GLint i
, GLint j
, GLint k
, const void *texel
)
1573 const GLuint
*rgba
= (const GLuint
*) texel
;
1574 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 4);
1575 dst
[0] = rgba
[RCOMP
];
1576 dst
[1] = rgba
[GCOMP
];
1577 dst
[2] = rgba
[BCOMP
];
1578 dst
[3] = rgba
[ACOMP
];
1583 /* MESA_FORMAT_DUDV8 ********************************************************/
1585 /* this format by definition produces 0,0,0,1 as rgba values,
1586 however we'll return the dudv values as rg and fix up elsewhere */
1587 static void FETCH(dudv8
)(const struct gl_texture_image
*texImage
,
1588 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1590 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 2);
1591 texel
[RCOMP
] = BYTE_TO_FLOAT(src
[0]);
1592 texel
[GCOMP
] = BYTE_TO_FLOAT(src
[1]);
1598 /* MESA_FORMAT_SIGNED_R8 ***********************************************/
1600 static void FETCH(signed_r8
)( const struct gl_texture_image
*texImage
,
1601 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1603 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1604 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( s
);
1605 texel
[GCOMP
] = 0.0F
;
1606 texel
[BCOMP
] = 0.0F
;
1607 texel
[ACOMP
] = 1.0F
;
1611 static void store_texel_signed_r8(struct gl_texture_image
*texImage
,
1612 GLint i
, GLint j
, GLint k
, const void *texel
)
1614 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1615 GLbyte
*dst
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1621 /* MESA_FORMAT_SIGNED_RG88 ***********************************************/
1623 static void FETCH(signed_rg88
)( const struct gl_texture_image
*texImage
,
1624 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1626 const GLushort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1627 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1628 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
& 0xff) );
1629 texel
[BCOMP
] = 0.0F
;
1630 texel
[ACOMP
] = 1.0F
;
1634 static void store_texel_signed_rg88(struct gl_texture_image
*texImage
,
1635 GLint i
, GLint j
, GLint k
, const void *texel
)
1637 const GLbyte
*rg
= (const GLbyte
*) texel
;
1638 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 2);
1639 *dst
= PACK_COLOR_88(rg
[RCOMP
], rg
[GCOMP
]);
1644 /* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
1646 static void FETCH(signed_rgbx8888
)( const struct gl_texture_image
*texImage
,
1647 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1649 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1650 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1651 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1652 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1653 texel
[ACOMP
] = 1.0f
;
1657 static void store_texel_signed_rgbx8888(struct gl_texture_image
*texImage
,
1658 GLint i
, GLint j
, GLint k
, const void *texel
)
1660 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1661 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1662 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], 255);
1667 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1669 static void FETCH(signed_rgba8888
)( const struct gl_texture_image
*texImage
,
1670 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1672 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1673 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1674 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1675 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1676 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
) );
1680 static void store_texel_signed_rgba8888(struct gl_texture_image
*texImage
,
1681 GLint i
, GLint j
, GLint k
, const void *texel
)
1683 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1684 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1685 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1689 static void FETCH(signed_rgba8888_rev
)( const struct gl_texture_image
*texImage
,
1690 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1692 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1693 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
) );
1694 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1695 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1696 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1700 static void store_texel_signed_rgba8888_rev(struct gl_texture_image
*texImage
,
1701 GLint i
, GLint j
, GLint k
, const void *texel
)
1703 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1704 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1705 *dst
= PACK_COLOR_8888_REV(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1711 /* MESA_FORMAT_SIGNED_R_16 ***********************************************/
1714 FETCH(signed_r_16
)(const struct gl_texture_image
*texImage
,
1715 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1717 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1718 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
);
1719 texel
[GCOMP
] = 0.0F
;
1720 texel
[BCOMP
] = 0.0F
;
1721 texel
[ACOMP
] = 1.0F
;
1726 store_texel_signed_r_16(struct gl_texture_image
*texImage
,
1727 GLint i
, GLint j
, GLint k
, const void *texel
)
1729 const GLshort
*rgba
= (const GLshort
*) texel
;
1730 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1736 /* MESA_FORMAT_SIGNED_RG_16 ***********************************************/
1739 FETCH(signed_rg_16
)(const struct gl_texture_image
*texImage
,
1740 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1742 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
1743 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1744 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1745 texel
[BCOMP
] = 0.0F
;
1746 texel
[ACOMP
] = 1.0F
;
1751 store_texel_signed_rg_16(struct gl_texture_image
*texImage
,
1752 GLint i
, GLint j
, GLint k
, const void *texel
)
1754 const GLshort
*rgba
= (const GLshort
*) texel
;
1755 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
1756 dst
[0] = rgba
[RCOMP
];
1757 dst
[1] = rgba
[GCOMP
];
1762 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
1765 FETCH(signed_rgb_16
)(const struct gl_texture_image
*texImage
,
1766 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1768 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 3);
1769 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1770 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1771 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
1772 texel
[ACOMP
] = 1.0F
;
1777 store_texel_signed_rgb_16(struct gl_texture_image
*texImage
,
1778 GLint i
, GLint j
, GLint k
, const void *texel
)
1780 const GLshort
*rgba
= (const GLshort
*) texel
;
1781 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 3);
1782 dst
[0] = rgba
[RCOMP
];
1783 dst
[1] = rgba
[GCOMP
];
1784 dst
[2] = rgba
[BCOMP
];
1789 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
1792 FETCH(signed_rgba_16
)(const struct gl_texture_image
*texImage
,
1793 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1795 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1796 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1797 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1798 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
1799 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
[3] );
1804 store_texel_signed_rgba_16(struct gl_texture_image
*texImage
,
1805 GLint i
, GLint j
, GLint k
, const void *texel
)
1807 const GLshort
*rgba
= (const GLshort
*) texel
;
1808 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1809 dst
[0] = rgba
[RCOMP
];
1810 dst
[1] = rgba
[GCOMP
];
1811 dst
[2] = rgba
[BCOMP
];
1812 dst
[3] = rgba
[ACOMP
];
1818 /* MESA_FORMAT_RGBA_16 ***********************************************/
1821 FETCH(rgba_16
)(const struct gl_texture_image
*texImage
,
1822 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1824 const GLushort
*s
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1825 texel
[RCOMP
] = USHORT_TO_FLOAT( s
[0] );
1826 texel
[GCOMP
] = USHORT_TO_FLOAT( s
[1] );
1827 texel
[BCOMP
] = USHORT_TO_FLOAT( s
[2] );
1828 texel
[ACOMP
] = USHORT_TO_FLOAT( s
[3] );
1833 store_texel_rgba_16(struct gl_texture_image
*texImage
,
1834 GLint i
, GLint j
, GLint k
, const void *texel
)
1836 const GLushort
*rgba
= (const GLushort
*) texel
;
1837 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1838 dst
[0] = rgba
[RCOMP
];
1839 dst
[1] = rgba
[GCOMP
];
1840 dst
[2] = rgba
[BCOMP
];
1841 dst
[3] = rgba
[ACOMP
];
1847 /* MESA_FORMAT_YCBCR *********************************************************/
1849 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
1850 * We convert YCbCr to RGB here.
1852 static void FETCH(f_ycbcr
)( const struct gl_texture_image
*texImage
,
1853 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1855 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1856 const GLushort
*src1
= src0
+ 1; /* odd */
1857 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1858 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1859 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1860 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1861 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1862 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1863 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1864 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1865 r
*= (1.0F
/ 255.0F
);
1866 g
*= (1.0F
/ 255.0F
);
1867 b
*= (1.0F
/ 255.0F
);
1868 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1869 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1870 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1871 texel
[ACOMP
] = 1.0F
;
1875 static void store_texel_ycbcr(struct gl_texture_image
*texImage
,
1876 GLint i
, GLint j
, GLint k
, const void *texel
)
1888 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1890 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
1891 * We convert YCbCr to RGB here.
1893 static void FETCH(f_ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1894 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1896 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1897 const GLushort
*src1
= src0
+ 1; /* odd */
1898 const GLubyte y0
= *src0
& 0xff; /* luminance */
1899 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1900 const GLubyte y1
= *src1
& 0xff; /* luminance */
1901 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1902 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1903 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1904 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1905 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1906 r
*= (1.0F
/ 255.0F
);
1907 g
*= (1.0F
/ 255.0F
);
1908 b
*= (1.0F
/ 255.0F
);
1909 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1910 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1911 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1912 texel
[ACOMP
] = 1.0F
;
1916 static void store_texel_ycbcr_rev(struct gl_texture_image
*texImage
,
1917 GLint i
, GLint j
, GLint k
, const void *texel
)
1929 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1931 static void FETCH(f_z24_s8
)( const struct gl_texture_image
*texImage
,
1932 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1934 /* only return Z, not stencil data */
1935 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1936 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
1937 texel
[0] = ((*src
) >> 8) * scale
;
1938 ASSERT(texImage
->TexFormat
== MESA_FORMAT_Z24_S8
);
1939 ASSERT(texel
[0] >= 0.0F
);
1940 ASSERT(texel
[0] <= 1.0F
);
1944 static void store_texel_z24_s8(struct gl_texture_image
*texImage
,
1945 GLint i
, GLint j
, GLint k
, const void *texel
)
1947 /* only store Z, not stencil */
1948 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1949 GLfloat depth
= *((GLfloat
*) texel
);
1950 GLuint zi
= ((GLuint
) (depth
* 0xffffff)) << 8;
1951 *dst
= zi
| (*dst
& 0xff);
1956 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1958 static void FETCH(f_s8_z24
)( const struct gl_texture_image
*texImage
,
1959 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1961 /* only return Z, not stencil data */
1962 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1963 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
1964 texel
[0] = ((*src
) & 0x00ffffff) * scale
;
1965 ASSERT(texImage
->TexFormat
== MESA_FORMAT_S8_Z24
);
1966 ASSERT(texel
[0] >= 0.0F
);
1967 ASSERT(texel
[0] <= 1.0F
);
1971 static void store_texel_s8_z24(struct gl_texture_image
*texImage
,
1972 GLint i
, GLint j
, GLint k
, const void *texel
)
1974 /* only store Z, not stencil */
1975 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1976 GLfloat depth
= *((GLfloat
*) texel
);
1977 GLuint zi
= (GLuint
) (depth
* 0xffffff);
1978 *dst
= zi
| (*dst
& 0xff000000);