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
]);
441 /* MESA_FORMAT_R_FLOAT32 *****************************************************/
443 /* Fetch texel from 1D, 2D or 3D R_FLOAT32 texture,
444 * returning 4 GLfloats.
446 static void FETCH(f_r_f32
)( const struct gl_texture_image
*texImage
,
447 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
449 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
450 texel
[RCOMP
] = src
[0];
457 static void store_texel_r_f32(struct gl_texture_image
*texImage
,
458 GLint i
, GLint j
, GLint k
, const void *texel
)
460 const GLfloat
*rgba
= (const GLfloat
*) texel
;
461 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
462 dst
[0] = rgba
[RCOMP
];
467 /* MESA_FORMAT_R_FLOAT16 *****************************************************/
469 /* Fetch texel from 1D, 2D or 3D R_FLOAT16 texture,
470 * returning 4 GLfloats.
472 static void FETCH(f_r_f16
)( const struct gl_texture_image
*texImage
,
473 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
475 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
476 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
483 static void store_texel_r_f16(struct gl_texture_image
*texImage
,
484 GLint i
, GLint j
, GLint k
, const void *texel
)
486 const GLfloat
*rgba
= (const GLfloat
*) texel
;
487 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
488 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
493 /* MESA_FORMAT_RG_FLOAT32 ****************************************************/
495 /* Fetch texel from 1D, 2D or 3D RG_FLOAT32 texture,
496 * returning 4 GLfloats.
498 static void FETCH(f_rg_f32
)( const struct gl_texture_image
*texImage
,
499 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
501 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
502 texel
[RCOMP
] = src
[0];
503 texel
[GCOMP
] = src
[1];
509 static void store_texel_rg_f32(struct gl_texture_image
*texImage
,
510 GLint i
, GLint j
, GLint k
, const void *texel
)
512 const GLfloat
*rgba
= (const GLfloat
*) texel
;
513 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
514 dst
[0] = rgba
[RCOMP
];
515 dst
[1] = rgba
[GCOMP
];
520 /* MESA_FORMAT_RG_FLOAT16 ****************************************************/
522 /* Fetch texel from 1D, 2D or 3D RG_FLOAT16 texture,
523 * returning 4 GLfloats.
525 static void FETCH(f_rg_f16
)( const struct gl_texture_image
*texImage
,
526 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
528 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
529 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
530 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
536 static void store_texel_rg_f16(struct gl_texture_image
*texImage
,
537 GLint i
, GLint j
, GLint k
, const void *texel
)
539 const GLfloat
*rgba
= (const GLfloat
*) texel
;
540 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
541 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
542 dst
[1] = _mesa_float_to_half(rgba
[GCOMP
]);
548 * Begin Hardware formats
551 /* MESA_FORMAT_RGBA8888 ******************************************************/
553 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
554 static void FETCH(f_rgba8888
)( const struct gl_texture_image
*texImage
,
555 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
557 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
558 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
559 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
560 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
561 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
567 static void store_texel_rgba8888(struct gl_texture_image
*texImage
,
568 GLint i
, GLint j
, GLint k
, const void *texel
)
570 const GLubyte
*rgba
= (const GLubyte
*) texel
;
571 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
572 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
577 /* MESA_FORMAT_RGBA888_REV ***************************************************/
579 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
580 static void FETCH(f_rgba8888_rev
)( const struct gl_texture_image
*texImage
,
581 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
583 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
584 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
585 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
586 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
587 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
591 static void store_texel_rgba8888_rev(struct gl_texture_image
*texImage
,
592 GLint i
, GLint j
, GLint k
, const void *texel
)
594 const GLubyte
*rgba
= (const GLubyte
*) texel
;
595 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
596 *dst
= PACK_COLOR_8888_REV(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
601 /* MESA_FORMAT_ARGB8888 ******************************************************/
603 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
604 static void FETCH(f_argb8888
)( const struct gl_texture_image
*texImage
,
605 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
607 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
608 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
609 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
610 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
611 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
615 static void store_texel_argb8888(struct gl_texture_image
*texImage
,
616 GLint i
, GLint j
, GLint k
, const void *texel
)
618 const GLubyte
*rgba
= (const GLubyte
*) texel
;
619 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
620 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
625 /* MESA_FORMAT_ARGB8888_REV **************************************************/
627 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
628 static void FETCH(f_argb8888_rev
)( const struct gl_texture_image
*texImage
,
629 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
631 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
632 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
633 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
634 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
635 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
639 static void store_texel_argb8888_rev(struct gl_texture_image
*texImage
,
640 GLint i
, GLint j
, GLint k
, const void *texel
)
642 const GLubyte
*rgba
= (const GLubyte
*) texel
;
643 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
644 *dst
= PACK_COLOR_8888(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
], rgba
[ACOMP
]);
649 /* MESA_FORMAT_XRGB8888 ******************************************************/
651 /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
652 static void FETCH(f_xrgb8888
)( const struct gl_texture_image
*texImage
,
653 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
655 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
656 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
657 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
658 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
663 static void store_texel_xrgb8888(struct gl_texture_image
*texImage
,
664 GLint i
, GLint j
, GLint k
, const void *texel
)
666 const GLubyte
*rgba
= (const GLubyte
*) texel
;
667 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
668 *dst
= PACK_COLOR_8888(0xff, rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
673 /* MESA_FORMAT_XRGB8888_REV **************************************************/
675 /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
676 static void FETCH(f_xrgb8888_rev
)( const struct gl_texture_image
*texImage
,
677 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
679 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
680 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
681 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
682 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
687 static void store_texel_xrgb8888_rev(struct gl_texture_image
*texImage
,
688 GLint i
, GLint j
, GLint k
, const void *texel
)
690 const GLubyte
*rgba
= (const GLubyte
*) texel
;
691 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
692 *dst
= PACK_COLOR_8888(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
], 0xff);
697 /* MESA_FORMAT_RGB888 ********************************************************/
699 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
700 static void FETCH(f_rgb888
)( const struct gl_texture_image
*texImage
,
701 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
703 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
704 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
705 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
706 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
711 static void store_texel_rgb888(struct gl_texture_image
*texImage
,
712 GLint i
, GLint j
, GLint k
, const void *texel
)
714 const GLubyte
*rgba
= (const GLubyte
*) texel
;
715 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
716 dst
[0] = rgba
[BCOMP
];
717 dst
[1] = rgba
[GCOMP
];
718 dst
[2] = rgba
[RCOMP
];
723 /* MESA_FORMAT_BGR888 ********************************************************/
725 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
726 static void FETCH(f_bgr888
)( const struct gl_texture_image
*texImage
,
727 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
729 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
730 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[0] );
731 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
732 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[2] );
737 static void store_texel_bgr888(struct gl_texture_image
*texImage
,
738 GLint i
, GLint j
, GLint k
, const void *texel
)
740 const GLubyte
*rgba
= (const GLubyte
*) texel
;
741 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
742 dst
[0] = rgba
[RCOMP
];
743 dst
[1] = rgba
[GCOMP
];
744 dst
[2] = rgba
[BCOMP
];
749 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
750 instead of slow (g << 2) * 255 / 252 (always rounds down) */
752 /* MESA_FORMAT_RGB565 ********************************************************/
754 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
755 static void FETCH(f_rgb565
)( const struct gl_texture_image
*texImage
,
756 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
758 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
759 const GLushort s
= *src
;
760 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
761 texel
[GCOMP
] = ((s
>> 5 ) & 0x3f) * (1.0F
/ 63.0F
);
762 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
767 static void store_texel_rgb565(struct gl_texture_image
*texImage
,
768 GLint i
, GLint j
, GLint k
, const void *texel
)
770 const GLubyte
*rgba
= (const GLubyte
*) texel
;
771 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
772 *dst
= PACK_COLOR_565(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
777 /* MESA_FORMAT_RGB565_REV ****************************************************/
779 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
780 static void FETCH(f_rgb565_rev
)( const struct gl_texture_image
*texImage
,
781 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
783 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
784 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
785 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
786 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
787 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
792 static void store_texel_rgb565_rev(struct gl_texture_image
*texImage
,
793 GLint i
, GLint j
, GLint k
, const void *texel
)
795 const GLubyte
*rgba
= (const GLubyte
*) texel
;
796 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
797 *dst
= PACK_COLOR_565(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
802 /* MESA_FORMAT_ARGB4444 ******************************************************/
804 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
805 static void FETCH(f_argb4444
)( const struct gl_texture_image
*texImage
,
806 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
808 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
809 const GLushort s
= *src
;
810 texel
[RCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
811 texel
[GCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
812 texel
[BCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
813 texel
[ACOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
817 static void store_texel_argb4444(struct gl_texture_image
*texImage
,
818 GLint i
, GLint j
, GLint k
, const void *texel
)
820 const GLubyte
*rgba
= (const GLubyte
*) texel
;
821 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
822 *dst
= PACK_COLOR_4444(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
827 /* MESA_FORMAT_ARGB4444_REV **************************************************/
829 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
830 static void FETCH(f_argb4444_rev
)( const struct gl_texture_image
*texImage
,
831 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
833 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
834 texel
[RCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
835 texel
[GCOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
836 texel
[BCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
837 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
841 static void store_texel_argb4444_rev(struct gl_texture_image
*texImage
,
842 GLint i
, GLint j
, GLint k
, const void *texel
)
844 const GLubyte
*rgba
= (const GLubyte
*) texel
;
845 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
846 *dst
= PACK_COLOR_4444(rgba
[ACOMP
], rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
850 /* MESA_FORMAT_RGBA5551 ******************************************************/
852 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
853 static void FETCH(f_rgba5551
)( const struct gl_texture_image
*texImage
,
854 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
856 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
857 const GLushort s
= *src
;
858 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
859 texel
[GCOMP
] = ((s
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
860 texel
[BCOMP
] = ((s
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
861 texel
[ACOMP
] = ((s
) & 0x01) * 1.0F
;
865 static void store_texel_rgba5551(struct gl_texture_image
*texImage
,
866 GLint i
, GLint j
, GLint k
, const void *texel
)
868 const GLubyte
*rgba
= (const GLubyte
*) texel
;
869 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
870 *dst
= PACK_COLOR_5551(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
874 /* MESA_FORMAT_ARGB1555 ******************************************************/
876 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
877 static void FETCH(f_argb1555
)( const struct gl_texture_image
*texImage
,
878 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
880 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
881 const GLushort s
= *src
;
882 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
883 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
884 texel
[BCOMP
] = ((s
>> 0) & 0x1f) * (1.0F
/ 31.0F
);
885 texel
[ACOMP
] = ((s
>> 15) & 0x01) * 1.0F
;
889 static void store_texel_argb1555(struct gl_texture_image
*texImage
,
890 GLint i
, GLint j
, GLint k
, const void *texel
)
892 const GLubyte
*rgba
= (const GLubyte
*) texel
;
893 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
894 *dst
= PACK_COLOR_1555(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
899 /* MESA_FORMAT_ARGB1555_REV **************************************************/
901 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
902 static void FETCH(f_argb1555_rev
)( const struct gl_texture_image
*texImage
,
903 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
905 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
906 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
907 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
908 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
909 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
910 texel
[ACOMP
] = UBYTE_TO_FLOAT( ((s
>> 15) & 0x01) * 255 );
914 static void store_texel_argb1555_rev(struct gl_texture_image
*texImage
,
915 GLint i
, GLint j
, GLint k
, const void *texel
)
917 const GLubyte
*rgba
= (const GLubyte
*) texel
;
918 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
919 *dst
= PACK_COLOR_1555_REV(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
924 /* MESA_FORMAT_ARGB2101010 ***************************************************/
926 /* Fetch texel from 1D, 2D or 3D argb2101010 texture, return 4 GLchans */
927 static void FETCH(f_argb2101010
)( const struct gl_texture_image
*texImage
,
928 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
930 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
931 const GLuint s
= *src
;
932 texel
[RCOMP
] = ((s
>> 20) & 0x3ff) * (1.0F
/ 1023.0F
);
933 texel
[GCOMP
] = ((s
>> 10) & 0x3ff) * (1.0F
/ 1023.0F
);
934 texel
[BCOMP
] = ((s
>> 0) & 0x3ff) * (1.0F
/ 1023.0F
);
935 texel
[ACOMP
] = ((s
>> 30) & 0x03) * (1.0F
/ 3.0F
);
939 static void store_texel_argb2101010(struct gl_texture_image
*texImage
,
940 GLint i
, GLint j
, GLint k
, const void *texel
)
942 const GLubyte
*rgba
= (const GLubyte
*) texel
;
943 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
944 *dst
= PACK_COLOR_2101010_UB(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
949 /* MESA_FORMAT_RG88 **********************************************************/
951 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
952 static void FETCH(f_rg88
)( const struct gl_texture_image
*texImage
,
953 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
955 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
956 texel
[RCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
957 texel
[GCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
963 static void store_texel_rg88(struct gl_texture_image
*texImage
,
964 GLint i
, GLint j
, GLint k
, const void *texel
)
966 const GLubyte
*rgba
= (const GLubyte
*) texel
;
967 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
968 *dst
= PACK_COLOR_88(rgba
[RCOMP
], rgba
[GCOMP
]);
973 /* MESA_FORMAT_RG88_REV ******************************************************/
975 /* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
976 static void FETCH(f_rg88_rev
)( const struct gl_texture_image
*texImage
,
977 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
979 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
980 texel
[RCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
981 texel
[GCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
987 static void store_texel_rg88_rev(struct gl_texture_image
*texImage
,
988 GLint i
, GLint j
, GLint k
, const void *texel
)
990 const GLubyte
*rgba
= (const GLubyte
*) texel
;
991 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
992 *dst
= PACK_COLOR_88(rgba
[GCOMP
], rgba
[RCOMP
]);
997 /* MESA_FORMAT_AL44 **********************************************************/
999 /* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
1000 static void FETCH(f_al44
)( const struct gl_texture_image
*texImage
,
1001 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1003 const GLubyte s
= *TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1006 texel
[BCOMP
] = (s
& 0xf) * (1.0F
/ 15.0F
);
1007 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1011 static void store_texel_al44(struct gl_texture_image
*texImage
,
1012 GLint i
, GLint j
, GLint k
, const void *texel
)
1014 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1015 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1016 *dst
= PACK_COLOR_44(rgba
[ACOMP
], rgba
[RCOMP
]);
1021 /* MESA_FORMAT_AL88 **********************************************************/
1023 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
1024 static void FETCH(f_al88
)( const struct gl_texture_image
*texImage
,
1025 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1027 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1030 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
1031 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
1035 static void store_texel_al88(struct gl_texture_image
*texImage
,
1036 GLint i
, GLint j
, GLint k
, const void *texel
)
1038 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1039 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1040 *dst
= PACK_COLOR_88(rgba
[ACOMP
], rgba
[RCOMP
]);
1045 /* MESA_FORMAT_R8 ************************************************************/
1047 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
1048 static void FETCH(f_r8
)(const struct gl_texture_image
*texImage
,
1049 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1051 const GLubyte s
= *TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1052 texel
[RCOMP
] = UBYTE_TO_FLOAT(s
);
1059 static void store_texel_r8(struct gl_texture_image
*texImage
,
1060 GLint i
, GLint j
, GLint k
, const void *texel
)
1062 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1063 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1069 /* MESA_FORMAT_R16 ***********************************************************/
1071 /* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
1072 static void FETCH(f_r16
)(const struct gl_texture_image
*texImage
,
1073 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1075 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1076 texel
[RCOMP
] = USHORT_TO_FLOAT(s
);
1083 static void store_texel_r16(struct gl_texture_image
*texImage
,
1084 GLint i
, GLint j
, GLint k
, const void *texel
)
1086 const GLushort
*rgba
= (const GLushort
*) texel
;
1087 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1093 /* MESA_FORMAT_AL88_REV ******************************************************/
1095 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
1096 static void FETCH(f_al88_rev
)( const struct gl_texture_image
*texImage
,
1097 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1099 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1102 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
1103 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
1107 static void store_texel_al88_rev(struct gl_texture_image
*texImage
,
1108 GLint i
, GLint j
, GLint k
, const void *texel
)
1110 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1111 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1112 *dst
= PACK_COLOR_88(rgba
[RCOMP
], rgba
[ACOMP
]);
1117 /* MESA_FORMAT_RG1616 ********************************************************/
1119 /* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
1120 static void FETCH(f_rg1616
)( const struct gl_texture_image
*texImage
,
1121 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1123 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1124 texel
[RCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
1125 texel
[GCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
1131 static void store_texel_rg1616(struct gl_texture_image
*texImage
,
1132 GLint i
, GLint j
, GLint k
, const void *texel
)
1134 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1135 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1136 *dst
= PACK_COLOR_1616(rgba
[RCOMP
], rgba
[GCOMP
]);
1141 /* MESA_FORMAT_RG1616_REV ****************************************************/
1143 /* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
1144 static void FETCH(f_rg1616_rev
)( const struct gl_texture_image
*texImage
,
1145 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1147 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1148 texel
[RCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
1149 texel
[GCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
1155 static void store_texel_rg1616_rev(struct gl_texture_image
*texImage
,
1156 GLint i
, GLint j
, GLint k
, const void *texel
)
1158 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1159 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1160 *dst
= PACK_COLOR_1616(rgba
[GCOMP
], rgba
[RCOMP
]);
1165 /* MESA_FORMAT_AL1616 ********************************************************/
1167 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
1168 static void FETCH(f_al1616
)( const struct gl_texture_image
*texImage
,
1169 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1171 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1174 texel
[BCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
1175 texel
[ACOMP
] = USHORT_TO_FLOAT( s
>> 16 );
1179 static void store_texel_al1616(struct gl_texture_image
*texImage
,
1180 GLint i
, GLint j
, GLint k
, const void *texel
)
1182 const GLushort
*rgba
= (const GLushort
*) texel
;
1183 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1184 *dst
= PACK_COLOR_1616(rgba
[ACOMP
], rgba
[RCOMP
]);
1189 /* MESA_FORMAT_AL1616_REV ****************************************************/
1191 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
1192 static void FETCH(f_al1616_rev
)( const struct gl_texture_image
*texImage
,
1193 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1195 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1198 texel
[BCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
1199 texel
[ACOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
1203 static void store_texel_al1616_rev(struct gl_texture_image
*texImage
,
1204 GLint i
, GLint j
, GLint k
, const void *texel
)
1206 const GLushort
*rgba
= (const GLushort
*) texel
;
1207 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1208 *dst
= PACK_COLOR_1616(rgba
[RCOMP
], rgba
[ACOMP
]);
1213 /* MESA_FORMAT_RGB332 ********************************************************/
1215 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1216 static void FETCH(f_rgb332
)( const struct gl_texture_image
*texImage
,
1217 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1219 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1220 const GLubyte s
= *src
;
1221 texel
[RCOMP
] = ((s
>> 5) & 0x7) * (1.0F
/ 7.0F
);
1222 texel
[GCOMP
] = ((s
>> 2) & 0x7) * (1.0F
/ 7.0F
);
1223 texel
[BCOMP
] = ((s
) & 0x3) * (1.0F
/ 3.0F
);
1224 texel
[ACOMP
] = 1.0F
;
1228 static void store_texel_rgb332(struct gl_texture_image
*texImage
,
1229 GLint i
, GLint j
, GLint k
, const void *texel
)
1231 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1232 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1233 *dst
= PACK_COLOR_332(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1238 /* MESA_FORMAT_A8 ************************************************************/
1240 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1241 static void FETCH(f_a8
)( const struct gl_texture_image
*texImage
,
1242 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1244 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1247 texel
[BCOMP
] = 0.0F
;
1248 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1252 static void store_texel_a8(struct gl_texture_image
*texImage
,
1253 GLint i
, GLint j
, GLint k
, const void *texel
)
1255 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1256 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1262 /* MESA_FORMAT_A16 ************************************************************/
1264 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1265 static void FETCH(f_a16
)( const struct gl_texture_image
*texImage
,
1266 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1268 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1271 texel
[BCOMP
] = 0.0F
;
1272 texel
[ACOMP
] = USHORT_TO_FLOAT( src
[0] );
1276 static void store_texel_a16(struct gl_texture_image
*texImage
,
1277 GLint i
, GLint j
, GLint k
, const void *texel
)
1279 const GLushort
*rgba
= (const GLushort
*) texel
;
1280 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1286 /* MESA_FORMAT_L8 ************************************************************/
1288 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1289 static void FETCH(f_l8
)( const struct gl_texture_image
*texImage
,
1290 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1292 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1295 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
1296 texel
[ACOMP
] = 1.0F
;
1300 static void store_texel_l8(struct gl_texture_image
*texImage
,
1301 GLint i
, GLint j
, GLint k
, const void *texel
)
1303 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1304 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1310 /* MESA_FORMAT_L16 ***********************************************************/
1312 /* Fetch texel from 1D, 2D or 3D l16 texture, return 4 GLchans */
1313 static void FETCH(f_l16
)( const struct gl_texture_image
*texImage
,
1314 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1316 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1319 texel
[BCOMP
] = USHORT_TO_FLOAT( src
[0] );
1320 texel
[ACOMP
] = 1.0F
;
1324 static void store_texel_l16(struct gl_texture_image
*texImage
,
1325 GLint i
, GLint j
, GLint k
, const void *texel
)
1327 const GLushort
*rgba
= (const GLushort
*) texel
;
1328 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1334 /* MESA_FORMAT_I8 ************************************************************/
1336 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1337 static void FETCH(f_i8
)( const struct gl_texture_image
*texImage
,
1338 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1340 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1344 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1348 static void store_texel_i8(struct gl_texture_image
*texImage
,
1349 GLint i
, GLint j
, GLint k
, const void *texel
)
1351 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1352 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1358 /* MESA_FORMAT_I16 ***********************************************************/
1360 /* Fetch texel from 1D, 2D or 3D i16 texture, return 4 GLchans */
1361 static void FETCH(f_i16
)( const struct gl_texture_image
*texImage
,
1362 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1364 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1368 texel
[ACOMP
] = USHORT_TO_FLOAT( src
[0] );
1372 static void store_texel_i16(struct gl_texture_image
*texImage
,
1373 GLint i
, GLint j
, GLint k
, const void *texel
)
1375 const GLushort
*rgba
= (const GLushort
*) texel
;
1376 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1382 /* MESA_FORMAT_CI8 ***********************************************************/
1384 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1385 * color table, and return 4 GLchans.
1387 static void FETCH(f_ci8
)( const struct gl_texture_image
*texImage
,
1388 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1390 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1391 const struct gl_color_table
*palette
;
1393 GET_CURRENT_CONTEXT(ctx
);
1395 if (ctx
->Texture
.SharedPalette
) {
1396 palette
= &ctx
->Texture
.Palette
;
1399 palette
= &texImage
->TexObject
->Palette
;
1401 if (palette
->Size
== 0)
1402 return; /* undefined results */
1404 /* Mask the index against size of palette to avoid going out of bounds */
1405 index
= (*src
) & (palette
->Size
- 1);
1408 const GLfloat
*table
= palette
->TableF
;
1409 switch (palette
->_BaseFormat
) {
1413 texel
[BCOMP
] = 0.0F
;
1414 texel
[ACOMP
] = table
[index
];
1419 texel
[BCOMP
] = table
[index
];
1420 texel
[ACOMP
] = 1.0F
;
1426 texel
[ACOMP
] = table
[index
];
1428 case GL_LUMINANCE_ALPHA
:
1431 texel
[BCOMP
] = table
[index
* 2 + 0];
1432 texel
[ACOMP
] = table
[index
* 2 + 1];
1435 texel
[RCOMP
] = table
[index
* 3 + 0];
1436 texel
[GCOMP
] = table
[index
* 3 + 1];
1437 texel
[BCOMP
] = table
[index
* 3 + 2];
1438 texel
[ACOMP
] = 1.0F
;
1441 texel
[RCOMP
] = table
[index
* 4 + 0];
1442 texel
[GCOMP
] = table
[index
* 4 + 1];
1443 texel
[BCOMP
] = table
[index
* 4 + 2];
1444 texel
[ACOMP
] = table
[index
* 4 + 3];
1447 _mesa_problem(ctx
, "Bad palette format in fetch_texel_ci8");
1454 static void store_texel_ci8(struct gl_texture_image
*texImage
,
1455 GLint i
, GLint j
, GLint k
, const void *texel
)
1457 const GLubyte
*index
= (const GLubyte
*) texel
;
1458 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1464 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1465 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1466 static void FETCH(srgb8
)(const struct gl_texture_image
*texImage
,
1467 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1469 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1470 texel
[RCOMP
] = nonlinear_to_linear(src
[2]);
1471 texel
[GCOMP
] = nonlinear_to_linear(src
[1]);
1472 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1473 texel
[ACOMP
] = 1.0F
;
1477 static void store_texel_srgb8(struct gl_texture_image
*texImage
,
1478 GLint i
, GLint j
, GLint k
, const void *texel
)
1480 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1481 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1482 dst
[0] = rgba
[BCOMP
]; /* no conversion */
1483 dst
[1] = rgba
[GCOMP
];
1484 dst
[2] = rgba
[RCOMP
];
1488 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1489 static void FETCH(srgba8
)(const struct gl_texture_image
*texImage
,
1490 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1492 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1493 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 24) );
1494 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1495 texel
[BCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1496 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff ); /* linear! */
1500 static void store_texel_srgba8(struct gl_texture_image
*texImage
,
1501 GLint i
, GLint j
, GLint k
, const void *texel
)
1503 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1504 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1505 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1509 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1510 static void FETCH(sargb8
)(const struct gl_texture_image
*texImage
,
1511 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1513 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1514 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1515 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1516 texel
[BCOMP
] = nonlinear_to_linear( (s
) & 0xff );
1517 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) ); /* linear! */
1521 static void store_texel_sargb8(struct gl_texture_image
*texImage
,
1522 GLint i
, GLint j
, GLint k
, const void *texel
)
1524 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1525 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1526 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1530 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1531 static void FETCH(sl8
)(const struct gl_texture_image
*texImage
,
1532 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1534 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1537 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1538 texel
[ACOMP
] = 1.0F
;
1542 static void store_texel_sl8(struct gl_texture_image
*texImage
,
1543 GLint i
, GLint j
, GLint k
, const void *texel
)
1545 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1546 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1547 dst
[0] = rgba
[RCOMP
];
1551 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1552 static void FETCH(sla8
)(const struct gl_texture_image
*texImage
,
1553 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1555 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1558 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1559 texel
[ACOMP
] = UBYTE_TO_FLOAT(src
[1]); /* linear */
1563 static void store_texel_sla8(struct gl_texture_image
*texImage
,
1564 GLint i
, GLint j
, GLint k
, const void *texel
)
1566 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1567 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1568 dst
[0] = rgba
[RCOMP
];
1569 dst
[1] = rgba
[ACOMP
];
1574 /* MESA_FORMAT_RGBA_INT8 **************************************************/
1577 FETCH(rgba_int8
)(const struct gl_texture_image
*texImage
,
1578 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1580 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 4);
1581 texel
[RCOMP
] = (GLfloat
) src
[0];
1582 texel
[GCOMP
] = (GLfloat
) src
[1];
1583 texel
[BCOMP
] = (GLfloat
) src
[2];
1584 texel
[ACOMP
] = (GLfloat
) src
[3];
1589 store_texel_rgba_int8(struct gl_texture_image
*texImage
,
1590 GLint i
, GLint j
, GLint k
, const void *texel
)
1592 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1593 GLbyte
*dst
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 4);
1594 dst
[0] = rgba
[RCOMP
];
1595 dst
[1] = rgba
[GCOMP
];
1596 dst
[2] = rgba
[BCOMP
];
1597 dst
[3] = rgba
[ACOMP
];
1602 /* MESA_FORMAT_RGBA_INT16 **************************************************/
1605 FETCH(rgba_int16
)(const struct gl_texture_image
*texImage
,
1606 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1608 const GLshort
*src
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1609 texel
[RCOMP
] = (GLfloat
) src
[0];
1610 texel
[GCOMP
] = (GLfloat
) src
[1];
1611 texel
[BCOMP
] = (GLfloat
) src
[2];
1612 texel
[ACOMP
] = (GLfloat
) src
[3];
1617 store_texel_rgba_int16(struct gl_texture_image
*texImage
,
1618 GLint i
, GLint j
, GLint k
, const void *texel
)
1620 const GLshort
*rgba
= (const GLshort
*) texel
;
1621 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
1622 dst
[0] = rgba
[RCOMP
];
1623 dst
[1] = rgba
[GCOMP
];
1624 dst
[2] = rgba
[BCOMP
];
1625 dst
[3] = rgba
[ACOMP
];
1630 /* MESA_FORMAT_RGBA_INT32 **************************************************/
1633 FETCH(rgba_int32
)(const struct gl_texture_image
*texImage
,
1634 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1636 const GLint
*src
= TEXEL_ADDR(GLint
, texImage
, i
, j
, k
, 4);
1637 texel
[RCOMP
] = (GLfloat
) src
[0];
1638 texel
[GCOMP
] = (GLfloat
) src
[1];
1639 texel
[BCOMP
] = (GLfloat
) src
[2];
1640 texel
[ACOMP
] = (GLfloat
) src
[3];
1645 store_texel_rgba_int32(struct gl_texture_image
*texImage
,
1646 GLint i
, GLint j
, GLint k
, const void *texel
)
1648 const GLint
*rgba
= (const GLint
*) texel
;
1649 GLint
*dst
= TEXEL_ADDR(GLint
, texImage
, i
, j
, k
, 4);
1650 dst
[0] = rgba
[RCOMP
];
1651 dst
[1] = rgba
[GCOMP
];
1652 dst
[2] = rgba
[BCOMP
];
1653 dst
[3] = rgba
[ACOMP
];
1658 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
1661 FETCH(rgba_uint8
)(const struct gl_texture_image
*texImage
,
1662 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1664 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 4);
1665 texel
[RCOMP
] = (GLfloat
) src
[0];
1666 texel
[GCOMP
] = (GLfloat
) src
[1];
1667 texel
[BCOMP
] = (GLfloat
) src
[2];
1668 texel
[ACOMP
] = (GLfloat
) src
[3];
1673 store_texel_rgba_uint8(struct gl_texture_image
*texImage
,
1674 GLint i
, GLint j
, GLint k
, const void *texel
)
1676 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1677 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 4);
1678 dst
[0] = rgba
[RCOMP
];
1679 dst
[1] = rgba
[GCOMP
];
1680 dst
[2] = rgba
[BCOMP
];
1681 dst
[3] = rgba
[ACOMP
];
1686 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
1689 FETCH(rgba_uint16
)(const struct gl_texture_image
*texImage
,
1690 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1692 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1693 texel
[RCOMP
] = (GLfloat
) src
[0];
1694 texel
[GCOMP
] = (GLfloat
) src
[1];
1695 texel
[BCOMP
] = (GLfloat
) src
[2];
1696 texel
[ACOMP
] = (GLfloat
) src
[3];
1701 store_texel_rgba_uint16(struct gl_texture_image
*texImage
,
1702 GLint i
, GLint j
, GLint k
, const void *texel
)
1704 const GLushort
*rgba
= (const GLushort
*) texel
;
1705 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
1706 dst
[0] = rgba
[RCOMP
];
1707 dst
[1] = rgba
[GCOMP
];
1708 dst
[2] = rgba
[BCOMP
];
1709 dst
[3] = rgba
[ACOMP
];
1714 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
1717 FETCH(rgba_uint32
)(const struct gl_texture_image
*texImage
,
1718 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1720 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 4);
1721 texel
[RCOMP
] = (GLfloat
) src
[0];
1722 texel
[GCOMP
] = (GLfloat
) src
[1];
1723 texel
[BCOMP
] = (GLfloat
) src
[2];
1724 texel
[ACOMP
] = (GLfloat
) src
[3];
1729 store_texel_rgba_uint32(struct gl_texture_image
*texImage
,
1730 GLint i
, GLint j
, GLint k
, const void *texel
)
1732 const GLuint
*rgba
= (const GLuint
*) texel
;
1733 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 4);
1734 dst
[0] = rgba
[RCOMP
];
1735 dst
[1] = rgba
[GCOMP
];
1736 dst
[2] = rgba
[BCOMP
];
1737 dst
[3] = rgba
[ACOMP
];
1742 /* MESA_FORMAT_DUDV8 ********************************************************/
1744 /* this format by definition produces 0,0,0,1 as rgba values,
1745 however we'll return the dudv values as rg and fix up elsewhere */
1746 static void FETCH(dudv8
)(const struct gl_texture_image
*texImage
,
1747 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1749 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 2);
1750 texel
[RCOMP
] = BYTE_TO_FLOAT(src
[0]);
1751 texel
[GCOMP
] = BYTE_TO_FLOAT(src
[1]);
1757 /* MESA_FORMAT_SIGNED_R8 ***********************************************/
1759 static void FETCH(signed_r8
)( const struct gl_texture_image
*texImage
,
1760 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1762 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1763 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( s
);
1764 texel
[GCOMP
] = 0.0F
;
1765 texel
[BCOMP
] = 0.0F
;
1766 texel
[ACOMP
] = 1.0F
;
1770 static void store_texel_signed_r8(struct gl_texture_image
*texImage
,
1771 GLint i
, GLint j
, GLint k
, const void *texel
)
1773 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1774 GLbyte
*dst
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1780 /* MESA_FORMAT_SIGNED_A8 ***********************************************/
1782 static void FETCH(signed_a8
)( const struct gl_texture_image
*texImage
,
1783 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1785 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1786 texel
[RCOMP
] = 0.0F
;
1787 texel
[GCOMP
] = 0.0F
;
1788 texel
[BCOMP
] = 0.0F
;
1789 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( s
);
1793 static void store_texel_signed_a8(struct gl_texture_image
*texImage
,
1794 GLint i
, GLint j
, GLint k
, const void *texel
)
1796 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1797 GLbyte
*dst
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1803 /* MESA_FORMAT_SIGNED_L8 ***********************************************/
1805 static void FETCH(signed_l8
)( const struct gl_texture_image
*texImage
,
1806 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1808 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1811 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( s
);
1812 texel
[ACOMP
] = 1.0F
;
1816 static void store_texel_signed_l8(struct gl_texture_image
*texImage
,
1817 GLint i
, GLint j
, GLint k
, const void *texel
)
1819 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1820 GLbyte
*dst
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1826 /* MESA_FORMAT_SIGNED_I8 ***********************************************/
1828 static void FETCH(signed_i8
)( const struct gl_texture_image
*texImage
,
1829 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1831 const GLbyte s
= *TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1835 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( s
);
1839 static void store_texel_signed_i8(struct gl_texture_image
*texImage
,
1840 GLint i
, GLint j
, GLint k
, const void *texel
)
1842 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1843 GLbyte
*dst
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 1);
1849 /* MESA_FORMAT_SIGNED_RG88_REV ***********************************************/
1851 static void FETCH(signed_rg88_rev
)( const struct gl_texture_image
*texImage
,
1852 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1854 const GLushort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1855 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
& 0xff) );
1856 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1857 texel
[BCOMP
] = 0.0F
;
1858 texel
[ACOMP
] = 1.0F
;
1862 static void store_texel_signed_rg88_rev(struct gl_texture_image
*texImage
,
1863 GLint i
, GLint j
, GLint k
, const void *texel
)
1865 const GLbyte
*rg
= (const GLbyte
*) texel
;
1866 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1867 dst
[0] = PACK_COLOR_88(rg
[GCOMP
], rg
[RCOMP
]);
1872 /* MESA_FORMAT_SIGNED_AL88 ***********************************************/
1874 static void FETCH(signed_al88
)( const struct gl_texture_image
*texImage
,
1875 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1877 const GLushort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1880 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
& 0xff) );
1881 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1885 static void store_texel_signed_al88(struct gl_texture_image
*texImage
,
1886 GLint i
, GLint j
, GLint k
, const void *texel
)
1888 const GLbyte
*rg
= (const GLbyte
*) texel
;
1889 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1890 dst
[0] = PACK_COLOR_88(rg
[ACOMP
], rg
[RCOMP
]);
1895 /* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
1897 static void FETCH(signed_rgbx8888
)( const struct gl_texture_image
*texImage
,
1898 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1900 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1901 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1902 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1903 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1904 texel
[ACOMP
] = 1.0f
;
1908 static void store_texel_signed_rgbx8888(struct gl_texture_image
*texImage
,
1909 GLint i
, GLint j
, GLint k
, const void *texel
)
1911 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1912 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1913 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], 255);
1918 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1920 static void FETCH(signed_rgba8888
)( const struct gl_texture_image
*texImage
,
1921 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1923 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1924 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1925 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1926 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1927 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
) );
1931 static void store_texel_signed_rgba8888(struct gl_texture_image
*texImage
,
1932 GLint i
, GLint j
, GLint k
, const void *texel
)
1934 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1935 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1936 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1940 static void FETCH(signed_rgba8888_rev
)( const struct gl_texture_image
*texImage
,
1941 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1943 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1944 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
) );
1945 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 8) );
1946 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 16) );
1947 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (GLbyte
) (s
>> 24) );
1951 static void store_texel_signed_rgba8888_rev(struct gl_texture_image
*texImage
,
1952 GLint i
, GLint j
, GLint k
, const void *texel
)
1954 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1955 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1956 *dst
= PACK_COLOR_8888_REV(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1962 /* MESA_FORMAT_SIGNED_R16 ***********************************************/
1965 FETCH(signed_r16
)(const struct gl_texture_image
*texImage
,
1966 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1968 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1969 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
);
1970 texel
[GCOMP
] = 0.0F
;
1971 texel
[BCOMP
] = 0.0F
;
1972 texel
[ACOMP
] = 1.0F
;
1977 store_texel_signed_r16(struct gl_texture_image
*texImage
,
1978 GLint i
, GLint j
, GLint k
, const void *texel
)
1980 const GLshort
*rgba
= (const GLshort
*) texel
;
1981 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1987 /* MESA_FORMAT_SIGNED_A16 ***********************************************/
1990 FETCH(signed_a16
)(const struct gl_texture_image
*texImage
,
1991 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1993 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
1994 texel
[RCOMP
] = 0.0F
;
1995 texel
[GCOMP
] = 0.0F
;
1996 texel
[BCOMP
] = 0.0F
;
1997 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
);
2002 store_texel_signed_a16(struct gl_texture_image
*texImage
,
2003 GLint i
, GLint j
, GLint k
, const void *texel
)
2005 const GLshort
*rgba
= (const GLshort
*) texel
;
2006 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
2012 /* MESA_FORMAT_SIGNED_L16 ***********************************************/
2015 FETCH(signed_l16
)(const struct gl_texture_image
*texImage
,
2016 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2018 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
2021 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
);
2022 texel
[ACOMP
] = 1.0F
;
2027 store_texel_signed_l16(struct gl_texture_image
*texImage
,
2028 GLint i
, GLint j
, GLint k
, const void *texel
)
2030 const GLshort
*rgba
= (const GLshort
*) texel
;
2031 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
2037 /* MESA_FORMAT_SIGNED_I16 ***********************************************/
2040 FETCH(signed_i16
)(const struct gl_texture_image
*texImage
,
2041 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2043 const GLshort s
= *TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
2047 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
);
2052 store_texel_signed_i16(struct gl_texture_image
*texImage
,
2053 GLint i
, GLint j
, GLint k
, const void *texel
)
2055 const GLshort
*rgba
= (const GLshort
*) texel
;
2056 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 1);
2062 /* MESA_FORMAT_SIGNED_RG1616 ***********************************************/
2065 FETCH(signed_rg1616
)(const struct gl_texture_image
*texImage
,
2066 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2068 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
2069 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
2070 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
2071 texel
[BCOMP
] = 0.0F
;
2072 texel
[ACOMP
] = 1.0F
;
2077 store_texel_signed_rg1616(struct gl_texture_image
*texImage
,
2078 GLint i
, GLint j
, GLint k
, const void *texel
)
2080 const GLshort
*rgba
= (const GLshort
*) texel
;
2081 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
2082 dst
[0] = rgba
[RCOMP
];
2083 dst
[1] = rgba
[GCOMP
];
2088 /* MESA_FORMAT_SIGNED_AL1616 ***********************************************/
2091 FETCH(signed_al1616
)(const struct gl_texture_image
*texImage
,
2092 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2094 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
2097 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
2098 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
2103 store_texel_signed_al1616(struct gl_texture_image
*texImage
,
2104 GLint i
, GLint j
, GLint k
, const void *texel
)
2106 const GLshort
*rgba
= (const GLshort
*) texel
;
2107 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 2);
2108 dst
[0] = rgba
[RCOMP
];
2109 dst
[1] = rgba
[ACOMP
];
2114 /* MESA_FORMAT_SIGNED_RGB_16 ***********************************************/
2117 FETCH(signed_rgb_16
)(const struct gl_texture_image
*texImage
,
2118 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2120 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 3);
2121 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
2122 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
2123 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
2124 texel
[ACOMP
] = 1.0F
;
2129 store_texel_signed_rgb_16(struct gl_texture_image
*texImage
,
2130 GLint i
, GLint j
, GLint k
, const void *texel
)
2132 const GLshort
*rgba
= (const GLshort
*) texel
;
2133 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 3);
2134 dst
[0] = rgba
[RCOMP
];
2135 dst
[1] = rgba
[GCOMP
];
2136 dst
[2] = rgba
[BCOMP
];
2141 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
2144 FETCH(signed_rgba_16
)(const struct gl_texture_image
*texImage
,
2145 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2147 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
2148 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
2149 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
2150 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
2151 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
[3] );
2156 store_texel_signed_rgba_16(struct gl_texture_image
*texImage
,
2157 GLint i
, GLint j
, GLint k
, const void *texel
)
2159 const GLshort
*rgba
= (const GLshort
*) texel
;
2160 GLshort
*dst
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
2161 dst
[0] = rgba
[RCOMP
];
2162 dst
[1] = rgba
[GCOMP
];
2163 dst
[2] = rgba
[BCOMP
];
2164 dst
[3] = rgba
[ACOMP
];
2170 /* MESA_FORMAT_RGBA_16 ***********************************************/
2173 FETCH(rgba_16
)(const struct gl_texture_image
*texImage
,
2174 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2176 const GLushort
*s
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
2177 texel
[RCOMP
] = USHORT_TO_FLOAT( s
[0] );
2178 texel
[GCOMP
] = USHORT_TO_FLOAT( s
[1] );
2179 texel
[BCOMP
] = USHORT_TO_FLOAT( s
[2] );
2180 texel
[ACOMP
] = USHORT_TO_FLOAT( s
[3] );
2185 store_texel_rgba_16(struct gl_texture_image
*texImage
,
2186 GLint i
, GLint j
, GLint k
, const void *texel
)
2188 const GLushort
*rgba
= (const GLushort
*) texel
;
2189 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
2190 dst
[0] = rgba
[RCOMP
];
2191 dst
[1] = rgba
[GCOMP
];
2192 dst
[2] = rgba
[BCOMP
];
2193 dst
[3] = rgba
[ACOMP
];
2199 /* MESA_FORMAT_YCBCR *********************************************************/
2201 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
2202 * We convert YCbCr to RGB here.
2204 static void FETCH(f_ycbcr
)( const struct gl_texture_image
*texImage
,
2205 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2207 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
2208 const GLushort
*src1
= src0
+ 1; /* odd */
2209 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
2210 const GLubyte cb
= *src0
& 0xff; /* chroma U */
2211 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
2212 const GLubyte cr
= *src1
& 0xff; /* chroma V */
2213 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
2214 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
2215 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
2216 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
2217 r
*= (1.0F
/ 255.0F
);
2218 g
*= (1.0F
/ 255.0F
);
2219 b
*= (1.0F
/ 255.0F
);
2220 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
2221 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
2222 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
2223 texel
[ACOMP
] = 1.0F
;
2227 static void store_texel_ycbcr(struct gl_texture_image
*texImage
,
2228 GLint i
, GLint j
, GLint k
, const void *texel
)
2240 /* MESA_FORMAT_YCBCR_REV *****************************************************/
2242 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
2243 * We convert YCbCr to RGB here.
2245 static void FETCH(f_ycbcr_rev
)( const struct gl_texture_image
*texImage
,
2246 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2248 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
2249 const GLushort
*src1
= src0
+ 1; /* odd */
2250 const GLubyte y0
= *src0
& 0xff; /* luminance */
2251 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
2252 const GLubyte y1
= *src1
& 0xff; /* luminance */
2253 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
2254 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
2255 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
2256 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
2257 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
2258 r
*= (1.0F
/ 255.0F
);
2259 g
*= (1.0F
/ 255.0F
);
2260 b
*= (1.0F
/ 255.0F
);
2261 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
2262 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
2263 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
2264 texel
[ACOMP
] = 1.0F
;
2268 static void store_texel_ycbcr_rev(struct gl_texture_image
*texImage
,
2269 GLint i
, GLint j
, GLint k
, const void *texel
)
2281 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
2283 static void FETCH(f_z24_s8
)( const struct gl_texture_image
*texImage
,
2284 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2286 /* only return Z, not stencil data */
2287 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
2288 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
2289 texel
[0] = ((*src
) >> 8) * scale
;
2290 ASSERT(texImage
->TexFormat
== MESA_FORMAT_Z24_S8
||
2291 texImage
->TexFormat
== MESA_FORMAT_Z24_X8
);
2292 ASSERT(texel
[0] >= 0.0F
);
2293 ASSERT(texel
[0] <= 1.0F
);
2297 static void store_texel_z24_s8(struct gl_texture_image
*texImage
,
2298 GLint i
, GLint j
, GLint k
, const void *texel
)
2300 /* only store Z, not stencil */
2301 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
2302 GLfloat depth
= *((GLfloat
*) texel
);
2303 GLuint zi
= ((GLuint
) (depth
* 0xffffff)) << 8;
2304 *dst
= zi
| (*dst
& 0xff);
2309 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
2311 static void FETCH(f_s8_z24
)( const struct gl_texture_image
*texImage
,
2312 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2314 /* only return Z, not stencil data */
2315 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
2316 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
2317 texel
[0] = ((*src
) & 0x00ffffff) * scale
;
2318 ASSERT(texImage
->TexFormat
== MESA_FORMAT_S8_Z24
||
2319 texImage
->TexFormat
== MESA_FORMAT_X8_Z24
);
2320 ASSERT(texel
[0] >= 0.0F
);
2321 ASSERT(texel
[0] <= 1.0F
);
2325 static void store_texel_s8_z24(struct gl_texture_image
*texImage
,
2326 GLint i
, GLint j
, GLint k
, const void *texel
)
2328 /* only store Z, not stencil */
2329 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
2330 GLfloat depth
= *((GLfloat
*) texel
);
2331 GLuint zi
= (GLuint
) (depth
* 0xffffff);
2332 *dst
= zi
| (*dst
& 0xff000000);
2337 /* MESA_FORMAT_RGB9_E5 ******************************************************/
2339 static void FETCH(rgb9_e5
)( const struct gl_texture_image
*texImage
,
2340 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2342 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
2343 rgb9e5_to_float3(*src
, texel
);
2344 texel
[ACOMP
] = 1.0F
;
2348 static void store_texel_rgb9_e5(struct gl_texture_image
*texImage
,
2349 GLint i
, GLint j
, GLint k
, const void *texel
)
2351 const GLfloat
*src
= (const GLfloat
*) texel
;
2352 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
2353 *dst
= float3_to_rgb9e5(src
);
2358 /* MESA_FORMAT_R11_G11_B10_FLOAT *********************************************/
2360 static void FETCH(r11_g11_b10f
)( const struct gl_texture_image
*texImage
,
2361 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2363 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
2364 r11g11b10f_to_float3(*src
, texel
);
2365 texel
[ACOMP
] = 1.0F
;
2369 static void store_texel_r11_g11_b10f(struct gl_texture_image
*texImage
,
2370 GLint i
, GLint j
, GLint k
, const void *texel
)
2372 const GLfloat
*src
= (const GLfloat
*) texel
;
2373 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
2374 *dst
= float3_to_r11g11b10f(src
);
2379 /* MESA_FORMAT_Z32_FLOAT_X24S8 ***********************************************/
2381 static void FETCH(z32f_x24s8
)(const struct gl_texture_image
*texImage
,
2382 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
2384 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
2385 texel
[RCOMP
] = src
[0];
2386 texel
[GCOMP
] = 0.0F
;
2387 texel
[BCOMP
] = 0.0F
;
2388 texel
[ACOMP
] = 1.0F
;
2392 static void store_texel_z32f_x24s8(struct gl_texture_image
*texImage
,
2393 GLint i
, GLint j
, GLint k
, const void *texel
)
2395 const GLfloat
*src
= (const GLfloat
*) texel
;
2396 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);