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_RG88 **********************************************************/
815 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
816 static void FETCH(f_rg88
)( const struct gl_texture_image
*texImage
,
817 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
819 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
820 texel
[RCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
821 texel
[GCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
827 static void store_texel_rg88(struct gl_texture_image
*texImage
,
828 GLint i
, GLint j
, GLint k
, const void *texel
)
830 const GLubyte
*rgba
= (const GLubyte
*) texel
;
831 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
832 *dst
= PACK_COLOR_88(rgba
[RCOMP
], rgba
[GCOMP
]);
837 /* MESA_FORMAT_RG88_REV ******************************************************/
839 /* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
840 static void FETCH(f_rg88_rev
)( const struct gl_texture_image
*texImage
,
841 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
843 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
844 texel
[RCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
845 texel
[GCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
851 static void store_texel_rg88_rev(struct gl_texture_image
*texImage
,
852 GLint i
, GLint j
, GLint k
, const void *texel
)
854 const GLubyte
*rgba
= (const GLubyte
*) texel
;
855 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
856 *dst
= PACK_COLOR_88(rgba
[GCOMP
], rgba
[RCOMP
]);
861 /* MESA_FORMAT_AL88 **********************************************************/
863 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
864 static void FETCH(f_al88
)( const struct gl_texture_image
*texImage
,
865 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
867 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
870 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
871 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
875 static void store_texel_al88(struct gl_texture_image
*texImage
,
876 GLint i
, GLint j
, GLint k
, const void *texel
)
878 const GLubyte
*rgba
= (const GLubyte
*) texel
;
879 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
880 *dst
= PACK_COLOR_88(rgba
[ACOMP
], rgba
[RCOMP
]);
885 /* MESA_FORMAT_R8 ************************************************************/
887 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
888 static void FETCH(f_r8
)(const struct gl_texture_image
*texImage
,
889 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
891 const GLubyte s
= *TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
892 texel
[RCOMP
] = UBYTE_TO_FLOAT(s
);
899 static void store_texel_r8(struct gl_texture_image
*texImage
,
900 GLint i
, GLint j
, GLint k
, const void *texel
)
902 const GLubyte
*rgba
= (const GLubyte
*) texel
;
903 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
909 /* MESA_FORMAT_R16 ***********************************************************/
911 /* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
912 static void FETCH(f_r16
)(const struct gl_texture_image
*texImage
,
913 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
915 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
916 texel
[RCOMP
] = USHORT_TO_FLOAT(s
);
923 static void store_texel_r16(struct gl_texture_image
*texImage
,
924 GLint i
, GLint j
, GLint k
, const void *texel
)
926 const GLushort
*rgba
= (const GLushort
*) texel
;
927 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
933 /* MESA_FORMAT_AL88_REV ******************************************************/
935 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
936 static void FETCH(f_al88_rev
)( const struct gl_texture_image
*texImage
,
937 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
939 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
942 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
943 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
947 static void store_texel_al88_rev(struct gl_texture_image
*texImage
,
948 GLint i
, GLint j
, GLint k
, const void *texel
)
950 const GLubyte
*rgba
= (const GLubyte
*) texel
;
951 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
952 *dst
= PACK_COLOR_88(rgba
[RCOMP
], rgba
[ACOMP
]);
957 /* MESA_FORMAT_RG1616 ********************************************************/
959 /* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
960 static void FETCH(f_rg1616
)( const struct gl_texture_image
*texImage
,
961 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
963 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
964 texel
[RCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
965 texel
[GCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
971 static void store_texel_rg1616(struct gl_texture_image
*texImage
,
972 GLint i
, GLint j
, GLint k
, const void *texel
)
974 const GLubyte
*rgba
= (const GLubyte
*) texel
;
975 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
976 *dst
= PACK_COLOR_1616(rgba
[RCOMP
], rgba
[GCOMP
]);
981 /* MESA_FORMAT_RG1616_REV ****************************************************/
983 /* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
984 static void FETCH(f_rg1616_rev
)( const struct gl_texture_image
*texImage
,
985 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
987 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
988 texel
[RCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
989 texel
[GCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
995 static void store_texel_rg1616_rev(struct gl_texture_image
*texImage
,
996 GLint i
, GLint j
, GLint k
, const void *texel
)
998 const GLubyte
*rgba
= (const GLubyte
*) texel
;
999 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1000 *dst
= PACK_COLOR_1616(rgba
[GCOMP
], rgba
[RCOMP
]);
1005 /* MESA_FORMAT_AL1616 ********************************************************/
1007 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
1008 static void FETCH(f_al1616
)( const struct gl_texture_image
*texImage
,
1009 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1011 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1014 texel
[BCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
1015 texel
[ACOMP
] = USHORT_TO_FLOAT( s
>> 16 );
1019 static void store_texel_al1616(struct gl_texture_image
*texImage
,
1020 GLint i
, GLint j
, GLint k
, const void *texel
)
1022 const GLushort
*rgba
= (const GLushort
*) texel
;
1023 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1024 *dst
= PACK_COLOR_1616(rgba
[ACOMP
], rgba
[RCOMP
]);
1029 /* MESA_FORMAT_AL1616_REV ****************************************************/
1031 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
1032 static void FETCH(f_al1616_rev
)( const struct gl_texture_image
*texImage
,
1033 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1035 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1038 texel
[BCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
1039 texel
[ACOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
1043 static void store_texel_al1616_rev(struct gl_texture_image
*texImage
,
1044 GLint i
, GLint j
, GLint k
, const void *texel
)
1046 const GLushort
*rgba
= (const GLushort
*) texel
;
1047 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1048 *dst
= PACK_COLOR_1616(rgba
[RCOMP
], rgba
[ACOMP
]);
1053 /* MESA_FORMAT_RGB332 ********************************************************/
1055 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1056 static void FETCH(f_rgb332
)( const struct gl_texture_image
*texImage
,
1057 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1059 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1060 const GLubyte s
= *src
;
1061 texel
[RCOMP
] = ((s
>> 5) & 0x7) * (1.0F
/ 7.0F
);
1062 texel
[GCOMP
] = ((s
>> 2) & 0x7) * (1.0F
/ 7.0F
);
1063 texel
[BCOMP
] = ((s
) & 0x3) * (1.0F
/ 3.0F
);
1064 texel
[ACOMP
] = 1.0F
;
1068 static void store_texel_rgb332(struct gl_texture_image
*texImage
,
1069 GLint i
, GLint j
, GLint k
, const void *texel
)
1071 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1072 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1073 *dst
= PACK_COLOR_332(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1078 /* MESA_FORMAT_A8 ************************************************************/
1080 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1081 static void FETCH(f_a8
)( const struct gl_texture_image
*texImage
,
1082 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1084 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1087 texel
[BCOMP
] = 0.0F
;
1088 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1092 static void store_texel_a8(struct gl_texture_image
*texImage
,
1093 GLint i
, GLint j
, GLint k
, const void *texel
)
1095 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1096 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1102 /* MESA_FORMAT_L8 ************************************************************/
1104 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1105 static void FETCH(f_l8
)( 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);
1111 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
1112 texel
[ACOMP
] = 1.0F
;
1116 static void store_texel_l8(struct gl_texture_image
*texImage
,
1117 GLint i
, GLint j
, GLint k
, const void *texel
)
1119 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1120 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1126 /* MESA_FORMAT_I8 ************************************************************/
1128 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1129 static void FETCH(f_i8
)( const struct gl_texture_image
*texImage
,
1130 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1132 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1136 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1140 static void store_texel_i8(struct gl_texture_image
*texImage
,
1141 GLint i
, GLint j
, GLint k
, const void *texel
)
1143 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1144 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1150 /* MESA_FORMAT_CI8 ***********************************************************/
1152 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1153 * color table, and return 4 GLchans.
1155 static void FETCH(f_ci8
)( const struct gl_texture_image
*texImage
,
1156 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1158 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1159 const struct gl_color_table
*palette
;
1161 GET_CURRENT_CONTEXT(ctx
);
1163 if (ctx
->Texture
.SharedPalette
) {
1164 palette
= &ctx
->Texture
.Palette
;
1167 palette
= &texImage
->TexObject
->Palette
;
1169 if (palette
->Size
== 0)
1170 return; /* undefined results */
1172 /* Mask the index against size of palette to avoid going out of bounds */
1173 index
= (*src
) & (palette
->Size
- 1);
1176 const GLfloat
*table
= palette
->TableF
;
1177 switch (palette
->_BaseFormat
) {
1181 texel
[BCOMP
] = 0.0F
;
1182 texel
[ACOMP
] = table
[index
];
1187 texel
[BCOMP
] = table
[index
];
1188 texel
[ACOMP
] = 1.0F
;
1194 texel
[ACOMP
] = table
[index
];
1196 case GL_LUMINANCE_ALPHA
:
1199 texel
[BCOMP
] = table
[index
* 2 + 0];
1200 texel
[ACOMP
] = table
[index
* 2 + 1];
1203 texel
[RCOMP
] = table
[index
* 3 + 0];
1204 texel
[GCOMP
] = table
[index
* 3 + 1];
1205 texel
[BCOMP
] = table
[index
* 3 + 2];
1206 texel
[ACOMP
] = 1.0F
;
1209 texel
[RCOMP
] = table
[index
* 4 + 0];
1210 texel
[GCOMP
] = table
[index
* 4 + 1];
1211 texel
[BCOMP
] = table
[index
* 4 + 2];
1212 texel
[ACOMP
] = table
[index
* 4 + 3];
1215 _mesa_problem(ctx
, "Bad palette format in fetch_texel_ci8");
1222 static void store_texel_ci8(struct gl_texture_image
*texImage
,
1223 GLint i
, GLint j
, GLint k
, const void *texel
)
1225 const GLubyte
*index
= (const GLubyte
*) texel
;
1226 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1232 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1233 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1234 static void FETCH(srgb8
)(const struct gl_texture_image
*texImage
,
1235 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1237 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1238 texel
[RCOMP
] = nonlinear_to_linear(src
[2]);
1239 texel
[GCOMP
] = nonlinear_to_linear(src
[1]);
1240 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1241 texel
[ACOMP
] = 1.0F
;
1245 static void store_texel_srgb8(struct gl_texture_image
*texImage
,
1246 GLint i
, GLint j
, GLint k
, const void *texel
)
1248 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1249 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1250 dst
[0] = rgba
[BCOMP
]; /* no conversion */
1251 dst
[1] = rgba
[GCOMP
];
1252 dst
[2] = rgba
[RCOMP
];
1256 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1257 static void FETCH(srgba8
)(const struct gl_texture_image
*texImage
,
1258 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1260 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1261 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 24) );
1262 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1263 texel
[BCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1264 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff ); /* linear! */
1268 static void store_texel_srgba8(struct gl_texture_image
*texImage
,
1269 GLint i
, GLint j
, GLint k
, const void *texel
)
1271 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1272 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1273 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1277 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1278 static void FETCH(sargb8
)(const struct gl_texture_image
*texImage
,
1279 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1281 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1282 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1283 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1284 texel
[BCOMP
] = nonlinear_to_linear( (s
) & 0xff );
1285 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) ); /* linear! */
1289 static void store_texel_sargb8(struct gl_texture_image
*texImage
,
1290 GLint i
, GLint j
, GLint k
, const void *texel
)
1292 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1293 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1294 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1298 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1299 static void FETCH(sl8
)(const struct gl_texture_image
*texImage
,
1300 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1302 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1305 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1306 texel
[ACOMP
] = 1.0F
;
1310 static void store_texel_sl8(struct gl_texture_image
*texImage
,
1311 GLint i
, GLint j
, GLint k
, const void *texel
)
1313 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1314 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1315 dst
[0] = rgba
[RCOMP
];
1319 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1320 static void FETCH(sla8
)(const struct gl_texture_image
*texImage
,
1321 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1323 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1326 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1327 texel
[ACOMP
] = UBYTE_TO_FLOAT(src
[1]); /* linear */
1331 static void store_texel_sla8(struct gl_texture_image
*texImage
,
1332 GLint i
, GLint j
, GLint k
, const void *texel
)
1334 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1335 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1336 dst
[0] = rgba
[RCOMP
];
1337 dst
[1] = rgba
[ACOMP
];
1342 /* MESA_FORMAT_RGBA_INT8 **************************************************/
1345 FETCH(rgba_int8
)(const struct gl_texture_image
*texImage
,
1346 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1348 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 4);
1349 texel
[RCOMP
] = (GLfloat
) src
[0];
1350 texel
[GCOMP
] = (GLfloat
) src
[1];
1351 texel
[BCOMP
] = (GLfloat
) src
[2];
1352 texel
[ACOMP
] = (GLfloat
) src
[3];
1357 store_texel_rgba_int8(struct gl_texture_image
*texImage
,
1358 GLint i
, GLint j
, GLint k
, const void *texel
)
1360 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1361 GLbyte
*dst
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 4);
1362 dst
[0] = rgba
[RCOMP
];
1363 dst
[1] = rgba
[GCOMP
];
1364 dst
[2] = rgba
[BCOMP
];
1365 dst
[3] = rgba
[ACOMP
];
1370 /* MESA_FORMAT_RGBA_INT16 **************************************************/
1373 FETCH(rgba_int16
)(const struct gl_texture_image
*texImage
,
1374 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1376 const GLshort
*src
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1377 texel
[RCOMP
] = (GLfloat
) src
[0];
1378 texel
[GCOMP
] = (GLfloat
) src
[1];
1379 texel
[BCOMP
] = (GLfloat
) src
[2];
1380 texel
[ACOMP
] = (GLfloat
) src
[3];
1385 store_texel_rgba_int16(struct gl_texture_image
*texImage
,
1386 GLint i
, GLint j
, GLint k
, const void *texel
)
1388 const GLshort
*rgba
= (const GLshort
*) texel
;
1389 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1390 dst
[0] = rgba
[RCOMP
];
1391 dst
[1] = rgba
[GCOMP
];
1392 dst
[2] = rgba
[BCOMP
];
1393 dst
[3] = rgba
[ACOMP
];
1398 /* MESA_FORMAT_RGBA_INT32 **************************************************/
1401 FETCH(rgba_int32
)(const struct gl_texture_image
*texImage
,
1402 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1404 const GLint
*src
= TEXEL_ADDR(GLint
, texImage
, i
, j
, k
, 4);
1405 texel
[RCOMP
] = (GLfloat
) src
[0];
1406 texel
[GCOMP
] = (GLfloat
) src
[1];
1407 texel
[BCOMP
] = (GLfloat
) src
[2];
1408 texel
[ACOMP
] = (GLfloat
) src
[3];
1413 store_texel_rgba_int32(struct gl_texture_image
*texImage
,
1414 GLint i
, GLint j
, GLint k
, const void *texel
)
1416 const GLint
*rgba
= (const GLint
*) texel
;
1417 GLint
*dst
= TEXEL_ADDR(GLint
, texImage
, i
, j
, k
, 4);
1418 dst
[0] = rgba
[RCOMP
];
1419 dst
[1] = rgba
[GCOMP
];
1420 dst
[2] = rgba
[BCOMP
];
1421 dst
[3] = rgba
[ACOMP
];
1426 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
1429 FETCH(rgba_uint8
)(const struct gl_texture_image
*texImage
,
1430 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1432 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 4);
1433 texel
[RCOMP
] = (GLfloat
) src
[0];
1434 texel
[GCOMP
] = (GLfloat
) src
[1];
1435 texel
[BCOMP
] = (GLfloat
) src
[2];
1436 texel
[ACOMP
] = (GLfloat
) src
[3];
1441 store_texel_rgba_uint8(struct gl_texture_image
*texImage
,
1442 GLint i
, GLint j
, GLint k
, const void *texel
)
1444 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1445 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 4);
1446 dst
[0] = rgba
[RCOMP
];
1447 dst
[1] = rgba
[GCOMP
];
1448 dst
[2] = rgba
[BCOMP
];
1449 dst
[3] = rgba
[ACOMP
];
1454 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
1457 FETCH(rgba_uint16
)(const struct gl_texture_image
*texImage
,
1458 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1460 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1461 texel
[RCOMP
] = (GLfloat
) src
[0];
1462 texel
[GCOMP
] = (GLfloat
) src
[1];
1463 texel
[BCOMP
] = (GLfloat
) src
[2];
1464 texel
[ACOMP
] = (GLfloat
) src
[3];
1469 store_texel_rgba_uint16(struct gl_texture_image
*texImage
,
1470 GLint i
, GLint j
, GLint k
, const void *texel
)
1472 const GLushort
*rgba
= (const GLushort
*) texel
;
1473 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1474 dst
[0] = rgba
[RCOMP
];
1475 dst
[1] = rgba
[GCOMP
];
1476 dst
[2] = rgba
[BCOMP
];
1477 dst
[3] = rgba
[ACOMP
];
1482 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
1485 FETCH(rgba_uint32
)(const struct gl_texture_image
*texImage
,
1486 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1488 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 4);
1489 texel
[RCOMP
] = (GLfloat
) src
[0];
1490 texel
[GCOMP
] = (GLfloat
) src
[1];
1491 texel
[BCOMP
] = (GLfloat
) src
[2];
1492 texel
[ACOMP
] = (GLfloat
) src
[3];
1497 store_texel_rgba_uint32(struct gl_texture_image
*texImage
,
1498 GLint i
, GLint j
, GLint k
, const void *texel
)
1500 const GLuint
*rgba
= (const GLuint
*) texel
;
1501 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 4);
1502 dst
[0] = rgba
[RCOMP
];
1503 dst
[1] = rgba
[GCOMP
];
1504 dst
[2] = rgba
[BCOMP
];
1505 dst
[3] = rgba
[ACOMP
];
1510 /* MESA_FORMAT_DUDV8 ********************************************************/
1512 /* this format by definition produces 0,0,0,1 as rgba values,
1513 however we'll return the dudv values as rg and fix up elsewhere */
1514 static void FETCH(dudv8
)(const struct gl_texture_image
*texImage
,
1515 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1517 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 2);
1518 texel
[RCOMP
] = BYTE_TO_FLOAT(src
[0]);
1519 texel
[GCOMP
] = BYTE_TO_FLOAT(src
[1]);
1525 /* MESA_FORMAT_SIGNED_R8 ***********************************************/
1527 static void FETCH(signed_r8
)( const struct gl_texture_image
*texImage
,
1528 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1530 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1531 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( s
);
1532 texel
[GCOMP
] = 0.0F
;
1533 texel
[BCOMP
] = 0.0F
;
1534 texel
[ACOMP
] = 1.0F
;
1538 static void store_texel_signed_r8(struct gl_texture_image
*texImage
,
1539 GLint i
, GLint j
, GLint k
, const void *texel
)
1541 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1542 GLbyte
*dst
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1548 /* MESA_FORMAT_SIGNED_RG88 ***********************************************/
1550 static void FETCH(signed_rg88
)( const struct gl_texture_image
*texImage
,
1551 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1553 const GLushort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1554 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1555 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
& 0xff) );
1556 texel
[BCOMP
] = 0.0F
;
1557 texel
[ACOMP
] = 1.0F
;
1561 static void store_texel_signed_rg88(struct gl_texture_image
*texImage
,
1562 GLint i
, GLint j
, GLint k
, const void *texel
)
1564 const GLbyte
*rg
= (const GLbyte
*) texel
;
1565 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 2);
1566 *dst
= PACK_COLOR_88(rg
[RCOMP
], rg
[GCOMP
]);
1571 /* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
1573 static void FETCH(signed_rgbx8888
)( const struct gl_texture_image
*texImage
,
1574 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1576 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1577 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1578 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1579 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1580 texel
[ACOMP
] = 1.0f
;
1584 static void store_texel_signed_rgbx8888(struct gl_texture_image
*texImage
,
1585 GLint i
, GLint j
, GLint k
, const void *texel
)
1587 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1588 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1589 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], 255);
1594 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1596 static void FETCH(signed_rgba8888
)( const struct gl_texture_image
*texImage
,
1597 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1599 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1600 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1601 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1602 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1603 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
) );
1607 static void store_texel_signed_rgba8888(struct gl_texture_image
*texImage
,
1608 GLint i
, GLint j
, GLint k
, const void *texel
)
1610 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1611 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1612 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1616 static void FETCH(signed_rgba8888_rev
)( const struct gl_texture_image
*texImage
,
1617 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1619 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1620 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
) );
1621 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1622 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1623 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1627 static void store_texel_signed_rgba8888_rev(struct gl_texture_image
*texImage
,
1628 GLint i
, GLint j
, GLint k
, const void *texel
)
1630 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1631 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1632 *dst
= PACK_COLOR_8888_REV(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1638 /* MESA_FORMAT_SIGNED_R_16 ***********************************************/
1641 FETCH(signed_r_16
)(const struct gl_texture_image
*texImage
,
1642 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1644 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1645 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
);
1646 texel
[GCOMP
] = 0.0F
;
1647 texel
[BCOMP
] = 0.0F
;
1648 texel
[ACOMP
] = 1.0F
;
1653 store_texel_signed_r_16(struct gl_texture_image
*texImage
,
1654 GLint i
, GLint j
, GLint k
, const void *texel
)
1656 const GLshort
*rgba
= (const GLshort
*) texel
;
1657 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1663 /* MESA_FORMAT_SIGNED_RG_16 ***********************************************/
1666 FETCH(signed_rg_16
)(const struct gl_texture_image
*texImage
,
1667 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1669 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
1670 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1671 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1672 texel
[BCOMP
] = 0.0F
;
1673 texel
[ACOMP
] = 1.0F
;
1678 store_texel_signed_rg_16(struct gl_texture_image
*texImage
,
1679 GLint i
, GLint j
, GLint k
, const void *texel
)
1681 const GLshort
*rgba
= (const GLshort
*) texel
;
1682 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
1683 dst
[0] = rgba
[RCOMP
];
1684 dst
[1] = rgba
[GCOMP
];
1689 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
1692 FETCH(signed_rgb_16
)(const struct gl_texture_image
*texImage
,
1693 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1695 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 3);
1696 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1697 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1698 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
1699 texel
[ACOMP
] = 1.0F
;
1704 store_texel_signed_rgb_16(struct gl_texture_image
*texImage
,
1705 GLint i
, GLint j
, GLint k
, const void *texel
)
1707 const GLshort
*rgba
= (const GLshort
*) texel
;
1708 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 3);
1709 dst
[0] = rgba
[RCOMP
];
1710 dst
[1] = rgba
[GCOMP
];
1711 dst
[2] = rgba
[BCOMP
];
1716 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
1719 FETCH(signed_rgba_16
)(const struct gl_texture_image
*texImage
,
1720 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1722 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1723 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
1724 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
1725 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
1726 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
[3] );
1731 store_texel_signed_rgba_16(struct gl_texture_image
*texImage
,
1732 GLint i
, GLint j
, GLint k
, const void *texel
)
1734 const GLshort
*rgba
= (const GLshort
*) texel
;
1735 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1736 dst
[0] = rgba
[RCOMP
];
1737 dst
[1] = rgba
[GCOMP
];
1738 dst
[2] = rgba
[BCOMP
];
1739 dst
[3] = rgba
[ACOMP
];
1745 /* MESA_FORMAT_RGBA_16 ***********************************************/
1748 FETCH(rgba_16
)(const struct gl_texture_image
*texImage
,
1749 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1751 const GLushort
*s
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1752 texel
[RCOMP
] = USHORT_TO_FLOAT( s
[0] );
1753 texel
[GCOMP
] = USHORT_TO_FLOAT( s
[1] );
1754 texel
[BCOMP
] = USHORT_TO_FLOAT( s
[2] );
1755 texel
[ACOMP
] = USHORT_TO_FLOAT( s
[3] );
1760 store_texel_rgba_16(struct gl_texture_image
*texImage
,
1761 GLint i
, GLint j
, GLint k
, const void *texel
)
1763 const GLushort
*rgba
= (const GLushort
*) texel
;
1764 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1765 dst
[0] = rgba
[RCOMP
];
1766 dst
[1] = rgba
[GCOMP
];
1767 dst
[2] = rgba
[BCOMP
];
1768 dst
[3] = rgba
[ACOMP
];
1774 /* MESA_FORMAT_YCBCR *********************************************************/
1776 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
1777 * We convert YCbCr to RGB here.
1779 static void FETCH(f_ycbcr
)( const struct gl_texture_image
*texImage
,
1780 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1782 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1783 const GLushort
*src1
= src0
+ 1; /* odd */
1784 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1785 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1786 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1787 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1788 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1789 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1790 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1791 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1792 r
*= (1.0F
/ 255.0F
);
1793 g
*= (1.0F
/ 255.0F
);
1794 b
*= (1.0F
/ 255.0F
);
1795 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1796 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1797 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1798 texel
[ACOMP
] = 1.0F
;
1802 static void store_texel_ycbcr(struct gl_texture_image
*texImage
,
1803 GLint i
, GLint j
, GLint k
, const void *texel
)
1815 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1817 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
1818 * We convert YCbCr to RGB here.
1820 static void FETCH(f_ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1821 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1823 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1824 const GLushort
*src1
= src0
+ 1; /* odd */
1825 const GLubyte y0
= *src0
& 0xff; /* luminance */
1826 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1827 const GLubyte y1
= *src1
& 0xff; /* luminance */
1828 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1829 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1830 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1831 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1832 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1833 r
*= (1.0F
/ 255.0F
);
1834 g
*= (1.0F
/ 255.0F
);
1835 b
*= (1.0F
/ 255.0F
);
1836 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1837 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1838 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1839 texel
[ACOMP
] = 1.0F
;
1843 static void store_texel_ycbcr_rev(struct gl_texture_image
*texImage
,
1844 GLint i
, GLint j
, GLint k
, const void *texel
)
1856 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1858 static void FETCH(f_z24_s8
)( const struct gl_texture_image
*texImage
,
1859 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1861 /* only return Z, not stencil data */
1862 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1863 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
1864 texel
[0] = ((*src
) >> 8) * scale
;
1865 ASSERT(texImage
->TexFormat
== MESA_FORMAT_Z24_S8
);
1866 ASSERT(texel
[0] >= 0.0F
);
1867 ASSERT(texel
[0] <= 1.0F
);
1871 static void store_texel_z24_s8(struct gl_texture_image
*texImage
,
1872 GLint i
, GLint j
, GLint k
, const void *texel
)
1874 /* only store Z, not stencil */
1875 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1876 GLfloat depth
= *((GLfloat
*) texel
);
1877 GLuint zi
= ((GLuint
) (depth
* 0xffffff)) << 8;
1878 *dst
= zi
| (*dst
& 0xff);
1883 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1885 static void FETCH(f_s8_z24
)( const struct gl_texture_image
*texImage
,
1886 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1888 /* only return Z, not stencil data */
1889 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1890 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
1891 texel
[0] = ((*src
) & 0x00ffffff) * scale
;
1892 ASSERT(texImage
->TexFormat
== MESA_FORMAT_S8_Z24
);
1893 ASSERT(texel
[0] >= 0.0F
);
1894 ASSERT(texel
[0] <= 1.0F
);
1898 static void store_texel_s8_z24(struct gl_texture_image
*texImage
,
1899 GLint i
, GLint j
, GLint k
, const void *texel
)
1901 /* only store Z, not stencil */
1902 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1903 GLfloat depth
= *((GLfloat
*) texel
);
1904 GLuint zi
= (GLuint
) (depth
* 0xffffff);
1905 *dst
= zi
| (*dst
& 0xff000000);