9d57ad7679bd2a59b8d5acca0746ba7f1412d7e0
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
, 4);
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
*src
= (const GLfloat
*) texel
;
167 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 4);
168 dst
[0] = _mesa_float_to_half(src
[RCOMP
]);
169 dst
[1] = _mesa_float_to_half(src
[GCOMP
]);
170 dst
[2] = _mesa_float_to_half(src
[BCOMP
]);
171 dst
[3] = _mesa_float_to_half(src
[ACOMP
]);
175 /* MESA_FORMAT_RGB_F32 *******************************************************/
177 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
178 * returning 4 GLfloats.
180 static void FETCH(f_rgb_f32
)( const struct gl_texture_image
*texImage
,
181 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
183 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 3);
184 texel
[RCOMP
] = src
[0];
185 texel
[GCOMP
] = src
[1];
186 texel
[BCOMP
] = src
[2];
191 static void store_texel_rgb_f32(struct gl_texture_image
*texImage
,
192 GLint i
, GLint j
, GLint k
, const void *texel
)
194 const GLfloat
*src
= (const GLfloat
*) texel
;
195 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 3);
203 /* MESA_FORMAT_RGB_F16 *******************************************************/
205 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
206 * returning 4 GLfloats.
208 static void FETCH(f_rgb_f16
)( const struct gl_texture_image
*texImage
,
209 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
211 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 3);
212 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
213 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
214 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
219 static void store_texel_rgb_f16(struct gl_texture_image
*texImage
,
220 GLint i
, GLint j
, GLint k
, const void *texel
)
222 const GLfloat
*src
= (const GLfloat
*) texel
;
223 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 3);
224 dst
[0] = _mesa_float_to_half(src
[RCOMP
]);
225 dst
[1] = _mesa_float_to_half(src
[GCOMP
]);
226 dst
[2] = _mesa_float_to_half(src
[BCOMP
]);
231 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
233 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
234 * returning 4 GLfloats.
236 static void FETCH(f_alpha_f32
)( const struct gl_texture_image
*texImage
,
237 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
239 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
243 texel
[ACOMP
] = src
[0];
247 static void store_texel_alpha_f32(struct gl_texture_image
*texImage
,
248 GLint i
, GLint j
, GLint k
, const void *texel
)
250 const GLfloat
*rgba
= (const GLfloat
*) texel
;
251 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
252 dst
[0] = rgba
[ACOMP
];
257 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
259 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
260 * returning 4 GLfloats.
262 static void FETCH(f_alpha_f16
)( const struct gl_texture_image
*texImage
,
263 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
265 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
269 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
273 static void store_texel_alpha_f16(struct gl_texture_image
*texImage
,
274 GLint i
, GLint j
, GLint k
, const void *texel
)
276 const GLfloat
*rgba
= (const GLfloat
*) texel
;
277 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
278 dst
[0] = _mesa_float_to_half(rgba
[ACOMP
]);
283 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
285 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
286 * returning 4 GLfloats.
288 static void FETCH(f_luminance_f32
)( const struct gl_texture_image
*texImage
,
289 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
291 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
294 texel
[BCOMP
] = src
[0];
299 static void store_texel_luminance_f32(struct gl_texture_image
*texImage
,
300 GLint i
, GLint j
, GLint k
, const void *texel
)
302 const GLfloat
*rgba
= (const GLfloat
*) texel
;
303 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
304 dst
[0] = rgba
[RCOMP
];
309 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
311 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
312 * returning 4 GLfloats.
314 static void FETCH(f_luminance_f16
)( const struct gl_texture_image
*texImage
,
315 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
317 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
320 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
325 static void store_texel_luminance_f16(struct gl_texture_image
*texImage
,
326 GLint i
, GLint j
, GLint k
, const void *texel
)
328 const GLfloat
*rgba
= (const GLfloat
*) texel
;
329 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
330 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
335 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
337 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
338 * returning 4 GLfloats.
340 static void FETCH(f_luminance_alpha_f32
)( const struct gl_texture_image
*texImage
,
341 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
343 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
346 texel
[BCOMP
] = src
[0];
347 texel
[ACOMP
] = src
[1];
351 static void store_texel_luminance_alpha_f32(struct gl_texture_image
*texImage
,
352 GLint i
, GLint j
, GLint k
, const void *texel
)
354 const GLfloat
*rgba
= (const GLfloat
*) texel
;
355 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
356 dst
[0] = rgba
[RCOMP
];
357 dst
[1] = rgba
[ACOMP
];
362 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
364 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
365 * returning 4 GLfloats.
367 static void FETCH(f_luminance_alpha_f16
)( const struct gl_texture_image
*texImage
,
368 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
370 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
373 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
374 texel
[ACOMP
] = _mesa_half_to_float(src
[1]);
378 static void store_texel_luminance_alpha_f16(struct gl_texture_image
*texImage
,
379 GLint i
, GLint j
, GLint k
, const void *texel
)
381 const GLfloat
*rgba
= (const GLfloat
*) texel
;
382 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
383 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
384 dst
[1] = _mesa_float_to_half(rgba
[ACOMP
]);
389 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
391 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
392 * returning 4 GLfloats.
394 static void FETCH(f_intensity_f32
)( const struct gl_texture_image
*texImage
,
395 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
397 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
401 texel
[ACOMP
] = src
[0];
405 static void store_texel_intensity_f32(struct gl_texture_image
*texImage
,
406 GLint i
, GLint j
, GLint k
, const void *texel
)
408 const GLfloat
*rgba
= (const GLfloat
*) texel
;
409 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
410 dst
[0] = rgba
[RCOMP
];
415 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
417 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
418 * returning 4 GLfloats.
420 static void FETCH(f_intensity_f16
)( const struct gl_texture_image
*texImage
,
421 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
423 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
427 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
431 static void store_texel_intensity_f16(struct gl_texture_image
*texImage
,
432 GLint i
, GLint j
, GLint k
, const void *texel
)
434 const GLfloat
*rgba
= (const GLfloat
*) texel
;
435 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
436 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
444 * Begin Hardware formats
447 /* MESA_FORMAT_RGBA8888 ******************************************************/
449 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
450 static void FETCH(f_rgba8888
)( const struct gl_texture_image
*texImage
,
451 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
453 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
454 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
455 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
456 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
457 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
463 static void store_texel_rgba8888(struct gl_texture_image
*texImage
,
464 GLint i
, GLint j
, GLint k
, const void *texel
)
466 const GLubyte
*rgba
= (const GLubyte
*) texel
;
467 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
468 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
473 /* MESA_FORMAT_RGBA888_REV ***************************************************/
475 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
476 static void FETCH(f_rgba8888_rev
)( const struct gl_texture_image
*texImage
,
477 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
479 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
480 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
481 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
482 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
483 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
487 static void store_texel_rgba8888_rev(struct gl_texture_image
*texImage
,
488 GLint i
, GLint j
, GLint k
, const void *texel
)
490 const GLubyte
*rgba
= (const GLubyte
*) texel
;
491 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
492 *dst
= PACK_COLOR_8888_REV(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
497 /* MESA_FORMAT_ARGB8888 ******************************************************/
499 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
500 static void FETCH(f_argb8888
)( const struct gl_texture_image
*texImage
,
501 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
503 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
504 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
505 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
506 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
507 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
511 static void store_texel_argb8888(struct gl_texture_image
*texImage
,
512 GLint i
, GLint j
, GLint k
, const void *texel
)
514 const GLubyte
*rgba
= (const GLubyte
*) texel
;
515 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
516 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
521 /* MESA_FORMAT_ARGB8888_REV **************************************************/
523 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
524 static void FETCH(f_argb8888_rev
)( const struct gl_texture_image
*texImage
,
525 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
527 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
528 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
529 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
530 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
531 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
535 static void store_texel_argb8888_rev(struct gl_texture_image
*texImage
,
536 GLint i
, GLint j
, GLint k
, const void *texel
)
538 const GLubyte
*rgba
= (const GLubyte
*) texel
;
539 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
540 *dst
= PACK_COLOR_8888(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
], rgba
[ACOMP
]);
545 /* MESA_FORMAT_XRGB8888 ******************************************************/
547 /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
548 static void FETCH(f_xrgb8888
)( const struct gl_texture_image
*texImage
,
549 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
551 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
552 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
553 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
554 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
559 static void store_texel_xrgb8888(struct gl_texture_image
*texImage
,
560 GLint i
, GLint j
, GLint k
, const void *texel
)
562 const GLubyte
*rgba
= (const GLubyte
*) texel
;
563 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
564 *dst
= PACK_COLOR_8888(0xff, rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
569 /* MESA_FORMAT_XRGB8888_REV **************************************************/
571 /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
572 static void FETCH(f_xrgb8888_rev
)( const struct gl_texture_image
*texImage
,
573 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
575 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
576 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
577 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
578 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
583 static void store_texel_xrgb8888_rev(struct gl_texture_image
*texImage
,
584 GLint i
, GLint j
, GLint k
, const void *texel
)
586 const GLubyte
*rgba
= (const GLubyte
*) texel
;
587 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
588 *dst
= PACK_COLOR_8888(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
], 0xff);
593 /* MESA_FORMAT_RGB888 ********************************************************/
595 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
596 static void FETCH(f_rgb888
)( const struct gl_texture_image
*texImage
,
597 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
599 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
600 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
601 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
602 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
607 static void store_texel_rgb888(struct gl_texture_image
*texImage
,
608 GLint i
, GLint j
, GLint k
, const void *texel
)
610 const GLubyte
*rgba
= (const GLubyte
*) texel
;
611 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
612 dst
[0] = rgba
[BCOMP
];
613 dst
[1] = rgba
[GCOMP
];
614 dst
[2] = rgba
[RCOMP
];
619 /* MESA_FORMAT_BGR888 ********************************************************/
621 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
622 static void FETCH(f_bgr888
)( const struct gl_texture_image
*texImage
,
623 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
625 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
626 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[0] );
627 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
628 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[2] );
633 static void store_texel_bgr888(struct gl_texture_image
*texImage
,
634 GLint i
, GLint j
, GLint k
, const void *texel
)
636 const GLubyte
*rgba
= (const GLubyte
*) texel
;
637 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
638 dst
[0] = rgba
[RCOMP
];
639 dst
[1] = rgba
[GCOMP
];
640 dst
[2] = rgba
[BCOMP
];
645 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
646 instead of slow (g << 2) * 255 / 252 (always rounds down) */
648 /* MESA_FORMAT_RGB565 ********************************************************/
650 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
651 static void FETCH(f_rgb565
)( const struct gl_texture_image
*texImage
,
652 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
654 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
655 const GLushort s
= *src
;
656 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
657 texel
[GCOMP
] = ((s
>> 5 ) & 0x3f) * (1.0F
/ 63.0F
);
658 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
663 static void store_texel_rgb565(struct gl_texture_image
*texImage
,
664 GLint i
, GLint j
, GLint k
, const void *texel
)
666 const GLubyte
*rgba
= (const GLubyte
*) texel
;
667 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
668 *dst
= PACK_COLOR_565(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
673 /* MESA_FORMAT_RGB565_REV ****************************************************/
675 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
676 static void FETCH(f_rgb565_rev
)( const struct gl_texture_image
*texImage
,
677 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
679 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
680 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
681 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
682 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
683 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
688 static void store_texel_rgb565_rev(struct gl_texture_image
*texImage
,
689 GLint i
, GLint j
, GLint k
, const void *texel
)
691 const GLubyte
*rgba
= (const GLubyte
*) texel
;
692 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
693 *dst
= PACK_COLOR_565(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
698 /* MESA_FORMAT_ARGB4444 ******************************************************/
700 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
701 static void FETCH(f_argb4444
)( const struct gl_texture_image
*texImage
,
702 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
704 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
705 const GLushort s
= *src
;
706 texel
[RCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
707 texel
[GCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
708 texel
[BCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
709 texel
[ACOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
713 static void store_texel_argb4444(struct gl_texture_image
*texImage
,
714 GLint i
, GLint j
, GLint k
, const void *texel
)
716 const GLubyte
*rgba
= (const GLubyte
*) texel
;
717 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
718 *dst
= PACK_COLOR_4444(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
723 /* MESA_FORMAT_ARGB4444_REV **************************************************/
725 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
726 static void FETCH(f_argb4444_rev
)( const struct gl_texture_image
*texImage
,
727 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
729 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
730 texel
[RCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
731 texel
[GCOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
732 texel
[BCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
733 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
737 static void store_texel_argb4444_rev(struct gl_texture_image
*texImage
,
738 GLint i
, GLint j
, GLint k
, const void *texel
)
740 const GLubyte
*rgba
= (const GLubyte
*) texel
;
741 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
742 *dst
= PACK_COLOR_4444(rgba
[ACOMP
], rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
746 /* MESA_FORMAT_RGBA5551 ******************************************************/
748 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
749 static void FETCH(f_rgba5551
)( const struct gl_texture_image
*texImage
,
750 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
752 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
753 const GLushort s
= *src
;
754 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
755 texel
[GCOMP
] = ((s
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
756 texel
[BCOMP
] = ((s
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
757 texel
[ACOMP
] = ((s
) & 0x01) * 1.0F
;
761 static void store_texel_rgba5551(struct gl_texture_image
*texImage
,
762 GLint i
, GLint j
, GLint k
, const void *texel
)
764 const GLubyte
*rgba
= (const GLubyte
*) texel
;
765 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
766 *dst
= PACK_COLOR_5551(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
770 /* MESA_FORMAT_ARGB1555 ******************************************************/
772 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
773 static void FETCH(f_argb1555
)( const struct gl_texture_image
*texImage
,
774 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
776 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
777 const GLushort s
= *src
;
778 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
779 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
780 texel
[BCOMP
] = ((s
>> 0) & 0x1f) * (1.0F
/ 31.0F
);
781 texel
[ACOMP
] = ((s
>> 15) & 0x01) * 1.0F
;
785 static void store_texel_argb1555(struct gl_texture_image
*texImage
,
786 GLint i
, GLint j
, GLint k
, const void *texel
)
788 const GLubyte
*rgba
= (const GLubyte
*) texel
;
789 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
790 *dst
= PACK_COLOR_1555(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
795 /* MESA_FORMAT_ARGB1555_REV **************************************************/
797 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
798 static void FETCH(f_argb1555_rev
)( const struct gl_texture_image
*texImage
,
799 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
801 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
802 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
803 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
804 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
805 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
806 texel
[ACOMP
] = UBYTE_TO_FLOAT( ((s
>> 15) & 0x01) * 255 );
810 static void store_texel_argb1555_rev(struct gl_texture_image
*texImage
,
811 GLint i
, GLint j
, GLint k
, const void *texel
)
813 const GLubyte
*rgba
= (const GLubyte
*) texel
;
814 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
815 *dst
= PACK_COLOR_1555_REV(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
820 /* MESA_FORMAT_ARGB2101010 ***************************************************/
822 /* Fetch texel from 1D, 2D or 3D argb2101010 texture, return 4 GLchans */
823 static void FETCH(f_argb2101010
)( const struct gl_texture_image
*texImage
,
824 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
826 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
827 const GLuint s
= *src
;
828 texel
[RCOMP
] = ((s
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
829 texel
[GCOMP
] = ((s
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
830 texel
[BCOMP
] = ((s
>> 0) & 0x3ff) * (1.0F
/ 1023.0F
);
831 texel
[ACOMP
] = ((s
>> 30) & 0x03) * (1.0F
/ 3.0F
);
835 static void store_texel_argb2101010(struct gl_texture_image
*texImage
,
836 GLint i
, GLint j
, GLint k
, const void *texel
)
838 const GLubyte
*rgba
= (const GLubyte
*) texel
;
839 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
840 *dst
= PACK_COLOR_2101010(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
845 /* MESA_FORMAT_RG88 **********************************************************/
847 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
848 static void FETCH(f_rg88
)( const struct gl_texture_image
*texImage
,
849 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
851 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
852 texel
[RCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
853 texel
[GCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
859 static void store_texel_rg88(struct gl_texture_image
*texImage
,
860 GLint i
, GLint j
, GLint k
, const void *texel
)
862 const GLubyte
*rgba
= (const GLubyte
*) texel
;
863 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
864 *dst
= PACK_COLOR_88(rgba
[RCOMP
], rgba
[GCOMP
]);
869 /* MESA_FORMAT_RG88_REV ******************************************************/
871 /* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
872 static void FETCH(f_rg88_rev
)( const struct gl_texture_image
*texImage
,
873 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
875 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
876 texel
[RCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
877 texel
[GCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
883 static void store_texel_rg88_rev(struct gl_texture_image
*texImage
,
884 GLint i
, GLint j
, GLint k
, const void *texel
)
886 const GLubyte
*rgba
= (const GLubyte
*) texel
;
887 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
888 *dst
= PACK_COLOR_88(rgba
[GCOMP
], rgba
[RCOMP
]);
893 /* MESA_FORMAT_AL44 **********************************************************/
895 /* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
896 static void FETCH(f_al44
)( const struct gl_texture_image
*texImage
,
897 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
899 const GLubyte s
= *TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
902 texel
[BCOMP
] = (s
& 0xf) * (1.0F
/ 15.0F
);
903 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
907 static void store_texel_al44(struct gl_texture_image
*texImage
,
908 GLint i
, GLint j
, GLint k
, const void *texel
)
910 const GLubyte
*rgba
= (const GLubyte
*) texel
;
911 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
912 *dst
= PACK_COLOR_44(rgba
[ACOMP
], rgba
[RCOMP
]);
917 /* MESA_FORMAT_AL88 **********************************************************/
919 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
920 static void FETCH(f_al88
)( const struct gl_texture_image
*texImage
,
921 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
923 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
926 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
927 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
931 static void store_texel_al88(struct gl_texture_image
*texImage
,
932 GLint i
, GLint j
, GLint k
, const void *texel
)
934 const GLubyte
*rgba
= (const GLubyte
*) texel
;
935 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
936 *dst
= PACK_COLOR_88(rgba
[ACOMP
], rgba
[RCOMP
]);
941 /* MESA_FORMAT_R8 ************************************************************/
943 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
944 static void FETCH(f_r8
)(const struct gl_texture_image
*texImage
,
945 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
947 const GLubyte s
= *TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
948 texel
[RCOMP
] = UBYTE_TO_FLOAT(s
);
955 static void store_texel_r8(struct gl_texture_image
*texImage
,
956 GLint i
, GLint j
, GLint k
, const void *texel
)
958 const GLubyte
*rgba
= (const GLubyte
*) texel
;
959 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
965 /* MESA_FORMAT_R16 ***********************************************************/
967 /* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
968 static void FETCH(f_r16
)(const struct gl_texture_image
*texImage
,
969 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
971 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
972 texel
[RCOMP
] = USHORT_TO_FLOAT(s
);
979 static void store_texel_r16(struct gl_texture_image
*texImage
,
980 GLint i
, GLint j
, GLint k
, const void *texel
)
982 const GLushort
*rgba
= (const GLushort
*) texel
;
983 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
989 /* MESA_FORMAT_AL88_REV ******************************************************/
991 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
992 static void FETCH(f_al88_rev
)( const struct gl_texture_image
*texImage
,
993 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
995 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
998 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
999 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
1003 static void store_texel_al88_rev(struct gl_texture_image
*texImage
,
1004 GLint i
, GLint j
, GLint k
, const void *texel
)
1006 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1007 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1008 *dst
= PACK_COLOR_88(rgba
[RCOMP
], rgba
[ACOMP
]);
1013 /* MESA_FORMAT_RG1616 ********************************************************/
1015 /* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
1016 static void FETCH(f_rg1616
)( const struct gl_texture_image
*texImage
,
1017 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1019 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1020 texel
[RCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
1021 texel
[GCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
1027 static void store_texel_rg1616(struct gl_texture_image
*texImage
,
1028 GLint i
, GLint j
, GLint k
, const void *texel
)
1030 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1031 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1032 *dst
= PACK_COLOR_1616(rgba
[RCOMP
], rgba
[GCOMP
]);
1037 /* MESA_FORMAT_RG1616_REV ****************************************************/
1039 /* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
1040 static void FETCH(f_rg1616_rev
)( const struct gl_texture_image
*texImage
,
1041 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1043 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1044 texel
[RCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
1045 texel
[GCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
1051 static void store_texel_rg1616_rev(struct gl_texture_image
*texImage
,
1052 GLint i
, GLint j
, GLint k
, const void *texel
)
1054 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1055 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1056 *dst
= PACK_COLOR_1616(rgba
[GCOMP
], rgba
[RCOMP
]);
1061 /* MESA_FORMAT_AL1616 ********************************************************/
1063 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
1064 static void FETCH(f_al1616
)( const struct gl_texture_image
*texImage
,
1065 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1067 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1070 texel
[BCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
1071 texel
[ACOMP
] = USHORT_TO_FLOAT( s
>> 16 );
1075 static void store_texel_al1616(struct gl_texture_image
*texImage
,
1076 GLint i
, GLint j
, GLint k
, const void *texel
)
1078 const GLushort
*rgba
= (const GLushort
*) texel
;
1079 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1080 *dst
= PACK_COLOR_1616(rgba
[ACOMP
], rgba
[RCOMP
]);
1085 /* MESA_FORMAT_AL1616_REV ****************************************************/
1087 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
1088 static void FETCH(f_al1616_rev
)( const struct gl_texture_image
*texImage
,
1089 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1091 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1094 texel
[BCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
1095 texel
[ACOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
1099 static void store_texel_al1616_rev(struct gl_texture_image
*texImage
,
1100 GLint i
, GLint j
, GLint k
, const void *texel
)
1102 const GLushort
*rgba
= (const GLushort
*) texel
;
1103 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1104 *dst
= PACK_COLOR_1616(rgba
[RCOMP
], rgba
[ACOMP
]);
1109 /* MESA_FORMAT_RGB332 ********************************************************/
1111 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1112 static void FETCH(f_rgb332
)( const struct gl_texture_image
*texImage
,
1113 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1115 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1116 const GLubyte s
= *src
;
1117 texel
[RCOMP
] = ((s
>> 5) & 0x7) * (1.0F
/ 7.0F
);
1118 texel
[GCOMP
] = ((s
>> 2) & 0x7) * (1.0F
/ 7.0F
);
1119 texel
[BCOMP
] = ((s
) & 0x3) * (1.0F
/ 3.0F
);
1120 texel
[ACOMP
] = 1.0F
;
1124 static void store_texel_rgb332(struct gl_texture_image
*texImage
,
1125 GLint i
, GLint j
, GLint k
, const void *texel
)
1127 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1128 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1129 *dst
= PACK_COLOR_332(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1134 /* MESA_FORMAT_A8 ************************************************************/
1136 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1137 static void FETCH(f_a8
)( const struct gl_texture_image
*texImage
,
1138 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1140 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1143 texel
[BCOMP
] = 0.0F
;
1144 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1148 static void store_texel_a8(struct gl_texture_image
*texImage
,
1149 GLint i
, GLint j
, GLint k
, const void *texel
)
1151 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1152 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1158 /* MESA_FORMAT_A16 ************************************************************/
1160 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1161 static void FETCH(f_a16
)( const struct gl_texture_image
*texImage
,
1162 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1164 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1167 texel
[BCOMP
] = 0.0F
;
1168 texel
[ACOMP
] = USHORT_TO_FLOAT( src
[0] );
1172 static void store_texel_a16(struct gl_texture_image
*texImage
,
1173 GLint i
, GLint j
, GLint k
, const void *texel
)
1175 const GLushort
*rgba
= (const GLushort
*) texel
;
1176 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1182 /* MESA_FORMAT_L8 ************************************************************/
1184 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1185 static void FETCH(f_l8
)( const struct gl_texture_image
*texImage
,
1186 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1188 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1191 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
1192 texel
[ACOMP
] = 1.0F
;
1196 static void store_texel_l8(struct gl_texture_image
*texImage
,
1197 GLint i
, GLint j
, GLint k
, const void *texel
)
1199 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1200 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1206 /* MESA_FORMAT_L16 ***********************************************************/
1208 /* Fetch texel from 1D, 2D or 3D l16 texture, return 4 GLchans */
1209 static void FETCH(f_l16
)( const struct gl_texture_image
*texImage
,
1210 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1212 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1215 texel
[BCOMP
] = USHORT_TO_FLOAT( src
[0] );
1216 texel
[ACOMP
] = 1.0F
;
1220 static void store_texel_l16(struct gl_texture_image
*texImage
,
1221 GLint i
, GLint j
, GLint k
, const void *texel
)
1223 const GLushort
*rgba
= (const GLushort
*) texel
;
1224 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1230 /* MESA_FORMAT_I8 ************************************************************/
1232 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1233 static void FETCH(f_i8
)( const struct gl_texture_image
*texImage
,
1234 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1236 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1240 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1244 static void store_texel_i8(struct gl_texture_image
*texImage
,
1245 GLint i
, GLint j
, GLint k
, const void *texel
)
1247 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1248 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1254 /* MESA_FORMAT_I16 ***********************************************************/
1256 /* Fetch texel from 1D, 2D or 3D i16 texture, return 4 GLchans */
1257 static void FETCH(f_i16
)( const struct gl_texture_image
*texImage
,
1258 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1260 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1264 texel
[ACOMP
] = USHORT_TO_FLOAT( src
[0] );
1268 static void store_texel_i16(struct gl_texture_image
*texImage
,
1269 GLint i
, GLint j
, GLint k
, const void *texel
)
1271 const GLushort
*rgba
= (const GLushort
*) texel
;
1272 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1278 /* MESA_FORMAT_CI8 ***********************************************************/
1280 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1281 * color table, and return 4 GLchans.
1283 static void FETCH(f_ci8
)( const struct gl_texture_image
*texImage
,
1284 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1286 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1287 const struct gl_color_table
*palette
;
1289 GET_CURRENT_CONTEXT(ctx
);
1291 if (ctx
->Texture
.SharedPalette
) {
1292 palette
= &ctx
->Texture
.Palette
;
1295 palette
= &texImage
->TexObject
->Palette
;
1297 if (palette
->Size
== 0)
1298 return; /* undefined results */
1300 /* Mask the index against size of palette to avoid going out of bounds */
1301 index
= (*src
) & (palette
->Size
- 1);
1304 const GLfloat
*table
= palette
->TableF
;
1305 switch (palette
->_BaseFormat
) {
1309 texel
[BCOMP
] = 0.0F
;
1310 texel
[ACOMP
] = table
[index
];
1315 texel
[BCOMP
] = table
[index
];
1316 texel
[ACOMP
] = 1.0F
;
1322 texel
[ACOMP
] = table
[index
];
1324 case GL_LUMINANCE_ALPHA
:
1327 texel
[BCOMP
] = table
[index
* 2 + 0];
1328 texel
[ACOMP
] = table
[index
* 2 + 1];
1331 texel
[RCOMP
] = table
[index
* 3 + 0];
1332 texel
[GCOMP
] = table
[index
* 3 + 1];
1333 texel
[BCOMP
] = table
[index
* 3 + 2];
1334 texel
[ACOMP
] = 1.0F
;
1337 texel
[RCOMP
] = table
[index
* 4 + 0];
1338 texel
[GCOMP
] = table
[index
* 4 + 1];
1339 texel
[BCOMP
] = table
[index
* 4 + 2];
1340 texel
[ACOMP
] = table
[index
* 4 + 3];
1343 _mesa_problem(ctx
, "Bad palette format in fetch_texel_ci8");
1350 static void store_texel_ci8(struct gl_texture_image
*texImage
,
1351 GLint i
, GLint j
, GLint k
, const void *texel
)
1353 const GLubyte
*index
= (const GLubyte
*) texel
;
1354 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1360 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1361 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1362 static void FETCH(srgb8
)(const struct gl_texture_image
*texImage
,
1363 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1365 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1366 texel
[RCOMP
] = nonlinear_to_linear(src
[2]);
1367 texel
[GCOMP
] = nonlinear_to_linear(src
[1]);
1368 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1369 texel
[ACOMP
] = 1.0F
;
1373 static void store_texel_srgb8(struct gl_texture_image
*texImage
,
1374 GLint i
, GLint j
, GLint k
, const void *texel
)
1376 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1377 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1378 dst
[0] = rgba
[BCOMP
]; /* no conversion */
1379 dst
[1] = rgba
[GCOMP
];
1380 dst
[2] = rgba
[RCOMP
];
1384 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1385 static void FETCH(srgba8
)(const struct gl_texture_image
*texImage
,
1386 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1388 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1389 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 24) );
1390 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1391 texel
[BCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1392 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff ); /* linear! */
1396 static void store_texel_srgba8(struct gl_texture_image
*texImage
,
1397 GLint i
, GLint j
, GLint k
, const void *texel
)
1399 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1400 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1401 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1405 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1406 static void FETCH(sargb8
)(const struct gl_texture_image
*texImage
,
1407 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1409 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1410 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1411 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1412 texel
[BCOMP
] = nonlinear_to_linear( (s
) & 0xff );
1413 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) ); /* linear! */
1417 static void store_texel_sargb8(struct gl_texture_image
*texImage
,
1418 GLint i
, GLint j
, GLint k
, const void *texel
)
1420 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1421 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1422 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1426 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1427 static void FETCH(sl8
)(const struct gl_texture_image
*texImage
,
1428 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1430 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1433 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1434 texel
[ACOMP
] = 1.0F
;
1438 static void store_texel_sl8(struct gl_texture_image
*texImage
,
1439 GLint i
, GLint j
, GLint k
, const void *texel
)
1441 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1442 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1443 dst
[0] = rgba
[RCOMP
];
1447 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1448 static void FETCH(sla8
)(const struct gl_texture_image
*texImage
,
1449 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1451 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1454 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1455 texel
[ACOMP
] = UBYTE_TO_FLOAT(src
[1]); /* linear */
1459 static void store_texel_sla8(struct gl_texture_image
*texImage
,
1460 GLint i
, GLint j
, GLint k
, const void *texel
)
1462 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1463 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1464 dst
[0] = rgba
[RCOMP
];
1465 dst
[1] = rgba
[ACOMP
];
1470 /* MESA_FORMAT_RGBA_INT8 **************************************************/
1473 FETCH(rgba_int8
)(const struct gl_texture_image
*texImage
,
1474 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1476 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 4);
1477 texel
[RCOMP
] = (GLfloat
) src
[0];
1478 texel
[GCOMP
] = (GLfloat
) src
[1];
1479 texel
[BCOMP
] = (GLfloat
) src
[2];
1480 texel
[ACOMP
] = (GLfloat
) src
[3];
1485 store_texel_rgba_int8(struct gl_texture_image
*texImage
,
1486 GLint i
, GLint j
, GLint k
, const void *texel
)
1488 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1489 GLbyte
*dst
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 4);
1490 dst
[0] = rgba
[RCOMP
];
1491 dst
[1] = rgba
[GCOMP
];
1492 dst
[2] = rgba
[BCOMP
];
1493 dst
[3] = rgba
[ACOMP
];
1498 /* MESA_FORMAT_RGBA_INT16 **************************************************/
1501 FETCH(rgba_int16
)(const struct gl_texture_image
*texImage
,
1502 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1504 const GLshort
*src
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1505 texel
[RCOMP
] = (GLfloat
) src
[0];
1506 texel
[GCOMP
] = (GLfloat
) src
[1];
1507 texel
[BCOMP
] = (GLfloat
) src
[2];
1508 texel
[ACOMP
] = (GLfloat
) src
[3];
1513 store_texel_rgba_int16(struct gl_texture_image
*texImage
,
1514 GLint i
, GLint j
, GLint k
, const void *texel
)
1516 const GLshort
*rgba
= (const GLshort
*) texel
;
1517 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1518 dst
[0] = rgba
[RCOMP
];
1519 dst
[1] = rgba
[GCOMP
];
1520 dst
[2] = rgba
[BCOMP
];
1521 dst
[3] = rgba
[ACOMP
];
1526 /* MESA_FORMAT_RGBA_INT32 **************************************************/
1529 FETCH(rgba_int32
)(const struct gl_texture_image
*texImage
,
1530 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1532 const GLint
*src
= TEXEL_ADDR(GLint
, texImage
, i
, j
, k
, 4);
1533 texel
[RCOMP
] = (GLfloat
) src
[0];
1534 texel
[GCOMP
] = (GLfloat
) src
[1];
1535 texel
[BCOMP
] = (GLfloat
) src
[2];
1536 texel
[ACOMP
] = (GLfloat
) src
[3];
1541 store_texel_rgba_int32(struct gl_texture_image
*texImage
,
1542 GLint i
, GLint j
, GLint k
, const void *texel
)
1544 const GLint
*rgba
= (const GLint
*) texel
;
1545 GLint
*dst
= TEXEL_ADDR(GLint
, texImage
, i
, j
, k
, 4);
1546 dst
[0] = rgba
[RCOMP
];
1547 dst
[1] = rgba
[GCOMP
];
1548 dst
[2] = rgba
[BCOMP
];
1549 dst
[3] = rgba
[ACOMP
];
1554 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
1557 FETCH(rgba_uint8
)(const struct gl_texture_image
*texImage
,
1558 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1560 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 4);
1561 texel
[RCOMP
] = (GLfloat
) src
[0];
1562 texel
[GCOMP
] = (GLfloat
) src
[1];
1563 texel
[BCOMP
] = (GLfloat
) src
[2];
1564 texel
[ACOMP
] = (GLfloat
) src
[3];
1569 store_texel_rgba_uint8(struct gl_texture_image
*texImage
,
1570 GLint i
, GLint j
, GLint k
, const void *texel
)
1572 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1573 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 4);
1574 dst
[0] = rgba
[RCOMP
];
1575 dst
[1] = rgba
[GCOMP
];
1576 dst
[2] = rgba
[BCOMP
];
1577 dst
[3] = rgba
[ACOMP
];
1582 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
1585 FETCH(rgba_uint16
)(const struct gl_texture_image
*texImage
,
1586 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1588 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1589 texel
[RCOMP
] = (GLfloat
) src
[0];
1590 texel
[GCOMP
] = (GLfloat
) src
[1];
1591 texel
[BCOMP
] = (GLfloat
) src
[2];
1592 texel
[ACOMP
] = (GLfloat
) src
[3];
1597 store_texel_rgba_uint16(struct gl_texture_image
*texImage
,
1598 GLint i
, GLint j
, GLint k
, const void *texel
)
1600 const GLushort
*rgba
= (const GLushort
*) texel
;
1601 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1602 dst
[0] = rgba
[RCOMP
];
1603 dst
[1] = rgba
[GCOMP
];
1604 dst
[2] = rgba
[BCOMP
];
1605 dst
[3] = rgba
[ACOMP
];
1610 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
1613 FETCH(rgba_uint32
)(const struct gl_texture_image
*texImage
,
1614 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1616 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 4);
1617 texel
[RCOMP
] = (GLfloat
) src
[0];
1618 texel
[GCOMP
] = (GLfloat
) src
[1];
1619 texel
[BCOMP
] = (GLfloat
) src
[2];
1620 texel
[ACOMP
] = (GLfloat
) src
[3];
1625 store_texel_rgba_uint32(struct gl_texture_image
*texImage
,
1626 GLint i
, GLint j
, GLint k
, const void *texel
)
1628 const GLuint
*rgba
= (const GLuint
*) texel
;
1629 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 4);
1630 dst
[0] = rgba
[RCOMP
];
1631 dst
[1] = rgba
[GCOMP
];
1632 dst
[2] = rgba
[BCOMP
];
1633 dst
[3] = rgba
[ACOMP
];
1638 /* MESA_FORMAT_DUDV8 ********************************************************/
1640 /* this format by definition produces 0,0,0,1 as rgba values,
1641 however we'll return the dudv values as rg and fix up elsewhere */
1642 static void FETCH(dudv8
)(const struct gl_texture_image
*texImage
,
1643 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1645 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 2);
1646 texel
[RCOMP
] = BYTE_TO_FLOAT(src
[0]);
1647 texel
[GCOMP
] = BYTE_TO_FLOAT(src
[1]);
1653 /* MESA_FORMAT_SIGNED_R8 ***********************************************/
1655 static void FETCH(signed_r8
)( const struct gl_texture_image
*texImage
,
1656 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1658 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1659 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( s
);
1660 texel
[GCOMP
] = 0.0F
;
1661 texel
[BCOMP
] = 0.0F
;
1662 texel
[ACOMP
] = 1.0F
;
1666 static void store_texel_signed_r8(struct gl_texture_image
*texImage
,
1667 GLint i
, GLint j
, GLint k
, const void *texel
)
1669 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1670 GLbyte
*dst
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1676 /* MESA_FORMAT_SIGNED_RG88 ***********************************************/
1678 static void FETCH(signed_rg88
)( const struct gl_texture_image
*texImage
,
1679 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1681 const GLushort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1682 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1683 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
& 0xff) );
1684 texel
[BCOMP
] = 0.0F
;
1685 texel
[ACOMP
] = 1.0F
;
1689 static void store_texel_signed_rg88(struct gl_texture_image
*texImage
,
1690 GLint i
, GLint j
, GLint k
, const void *texel
)
1692 const GLbyte
*rg
= (const GLbyte
*) texel
;
1693 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 2);
1694 *dst
= PACK_COLOR_88(rg
[RCOMP
], rg
[GCOMP
]);
1699 /* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
1701 static void FETCH(signed_rgbx8888
)( const struct gl_texture_image
*texImage
,
1702 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1704 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1705 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1706 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1707 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1708 texel
[ACOMP
] = 1.0f
;
1712 static void store_texel_signed_rgbx8888(struct gl_texture_image
*texImage
,
1713 GLint i
, GLint j
, GLint k
, const void *texel
)
1715 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1716 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1717 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], 255);
1722 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1724 static void FETCH(signed_rgba8888
)( const struct gl_texture_image
*texImage
,
1725 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1727 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1728 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1729 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1730 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1731 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
) );
1735 static void store_texel_signed_rgba8888(struct gl_texture_image
*texImage
,
1736 GLint i
, GLint j
, GLint k
, const void *texel
)
1738 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1739 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1740 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1744 static void FETCH(signed_rgba8888_rev
)( const struct gl_texture_image
*texImage
,
1745 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1747 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1748 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
) );
1749 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1750 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1751 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1755 static void store_texel_signed_rgba8888_rev(struct gl_texture_image
*texImage
,
1756 GLint i
, GLint j
, GLint k
, const void *texel
)
1758 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1759 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1760 *dst
= PACK_COLOR_8888_REV(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1766 /* MESA_FORMAT_SIGNED_R_16 ***********************************************/
1769 FETCH(signed_r_16
)(const struct gl_texture_image
*texImage
,
1770 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1772 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1773 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
);
1774 texel
[GCOMP
] = 0.0F
;
1775 texel
[BCOMP
] = 0.0F
;
1776 texel
[ACOMP
] = 1.0F
;
1781 store_texel_signed_r_16(struct gl_texture_image
*texImage
,
1782 GLint i
, GLint j
, GLint k
, const void *texel
)
1784 const GLshort
*rgba
= (const GLshort
*) texel
;
1785 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1791 /* MESA_FORMAT_SIGNED_RG_16 ***********************************************/
1794 FETCH(signed_rg_16
)(const struct gl_texture_image
*texImage
,
1795 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1797 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
1798 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1799 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1800 texel
[BCOMP
] = 0.0F
;
1801 texel
[ACOMP
] = 1.0F
;
1806 store_texel_signed_rg_16(struct gl_texture_image
*texImage
,
1807 GLint i
, GLint j
, GLint k
, const void *texel
)
1809 const GLshort
*rgba
= (const GLshort
*) texel
;
1810 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
1811 dst
[0] = rgba
[RCOMP
];
1812 dst
[1] = rgba
[GCOMP
];
1817 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
1820 FETCH(signed_rgb_16
)(const struct gl_texture_image
*texImage
,
1821 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1823 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 3);
1824 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1825 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1826 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
1827 texel
[ACOMP
] = 1.0F
;
1832 store_texel_signed_rgb_16(struct gl_texture_image
*texImage
,
1833 GLint i
, GLint j
, GLint k
, const void *texel
)
1835 const GLshort
*rgba
= (const GLshort
*) texel
;
1836 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 3);
1837 dst
[0] = rgba
[RCOMP
];
1838 dst
[1] = rgba
[GCOMP
];
1839 dst
[2] = rgba
[BCOMP
];
1844 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
1847 FETCH(signed_rgba_16
)(const struct gl_texture_image
*texImage
,
1848 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1850 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1851 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1852 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1853 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
1854 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
[3] );
1859 store_texel_signed_rgba_16(struct gl_texture_image
*texImage
,
1860 GLint i
, GLint j
, GLint k
, const void *texel
)
1862 const GLshort
*rgba
= (const GLshort
*) texel
;
1863 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1864 dst
[0] = rgba
[RCOMP
];
1865 dst
[1] = rgba
[GCOMP
];
1866 dst
[2] = rgba
[BCOMP
];
1867 dst
[3] = rgba
[ACOMP
];
1873 /* MESA_FORMAT_RGBA_16 ***********************************************/
1876 FETCH(rgba_16
)(const struct gl_texture_image
*texImage
,
1877 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1879 const GLushort
*s
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1880 texel
[RCOMP
] = USHORT_TO_FLOAT( s
[0] );
1881 texel
[GCOMP
] = USHORT_TO_FLOAT( s
[1] );
1882 texel
[BCOMP
] = USHORT_TO_FLOAT( s
[2] );
1883 texel
[ACOMP
] = USHORT_TO_FLOAT( s
[3] );
1888 store_texel_rgba_16(struct gl_texture_image
*texImage
,
1889 GLint i
, GLint j
, GLint k
, const void *texel
)
1891 const GLushort
*rgba
= (const GLushort
*) texel
;
1892 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1893 dst
[0] = rgba
[RCOMP
];
1894 dst
[1] = rgba
[GCOMP
];
1895 dst
[2] = rgba
[BCOMP
];
1896 dst
[3] = rgba
[ACOMP
];
1902 /* MESA_FORMAT_YCBCR *********************************************************/
1904 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
1905 * We convert YCbCr to RGB here.
1907 static void FETCH(f_ycbcr
)( const struct gl_texture_image
*texImage
,
1908 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1910 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1911 const GLushort
*src1
= src0
+ 1; /* odd */
1912 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1913 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1914 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1915 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1916 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1917 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1918 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1919 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1920 r
*= (1.0F
/ 255.0F
);
1921 g
*= (1.0F
/ 255.0F
);
1922 b
*= (1.0F
/ 255.0F
);
1923 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1924 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1925 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1926 texel
[ACOMP
] = 1.0F
;
1930 static void store_texel_ycbcr(struct gl_texture_image
*texImage
,
1931 GLint i
, GLint j
, GLint k
, const void *texel
)
1943 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1945 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
1946 * We convert YCbCr to RGB here.
1948 static void FETCH(f_ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1949 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1951 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1952 const GLushort
*src1
= src0
+ 1; /* odd */
1953 const GLubyte y0
= *src0
& 0xff; /* luminance */
1954 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1955 const GLubyte y1
= *src1
& 0xff; /* luminance */
1956 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1957 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1958 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1959 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1960 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1961 r
*= (1.0F
/ 255.0F
);
1962 g
*= (1.0F
/ 255.0F
);
1963 b
*= (1.0F
/ 255.0F
);
1964 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1965 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1966 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1967 texel
[ACOMP
] = 1.0F
;
1971 static void store_texel_ycbcr_rev(struct gl_texture_image
*texImage
,
1972 GLint i
, GLint j
, GLint k
, const void *texel
)
1984 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1986 static void FETCH(f_z24_s8
)( const struct gl_texture_image
*texImage
,
1987 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1989 /* only return Z, not stencil data */
1990 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1991 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
1992 texel
[0] = ((*src
) >> 8) * scale
;
1993 ASSERT(texImage
->TexFormat
== MESA_FORMAT_Z24_S8
);
1994 ASSERT(texel
[0] >= 0.0F
);
1995 ASSERT(texel
[0] <= 1.0F
);
1999 static void store_texel_z24_s8(struct gl_texture_image
*texImage
,
2000 GLint i
, GLint j
, GLint k
, const void *texel
)
2002 /* only store Z, not stencil */
2003 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
2004 GLfloat depth
= *((GLfloat
*) texel
);
2005 GLuint zi
= ((GLuint
) (depth
* 0xffffff)) << 8;
2006 *dst
= zi
| (*dst
& 0xff);
2011 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
2013 static void FETCH(f_s8_z24
)( const struct gl_texture_image
*texImage
,
2014 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2016 /* only return Z, not stencil data */
2017 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
2018 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
2019 texel
[0] = ((*src
) & 0x00ffffff) * scale
;
2020 ASSERT(texImage
->TexFormat
== MESA_FORMAT_S8_Z24
);
2021 ASSERT(texel
[0] >= 0.0F
);
2022 ASSERT(texel
[0] <= 1.0F
);
2026 static void store_texel_s8_z24(struct gl_texture_image
*texImage
,
2027 GLint i
, GLint j
, GLint k
, const void *texel
)
2029 /* only store Z, not stencil */
2030 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
2031 GLfloat depth
= *((GLfloat
*) texel
);
2032 GLuint zi
= (GLuint
) (depth
* 0xffffff);
2033 *dst
= zi
| (*dst
& 0xff000000);