2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008 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 texformat_tmp.h
29 * Texel fetch functions template.
31 * This template file is used by texformat.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 * \sa texformat.c and FetchTexel.
40 * \author Gareth Hughes
47 #define TEXEL_ADDR( type, image, i, j, k, size ) \
48 ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
50 #define FETCH(x) fetch_texel_1d_##x
54 #define TEXEL_ADDR( type, image, i, j, k, size ) \
56 ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
58 #define FETCH(x) fetch_texel_2d_##x
62 #define TEXEL_ADDR( type, image, i, j, k, size ) \
63 ((type *)(image)->Data + ((image)->ImageOffsets[k] \
64 + (image)->RowStride * (j) + (i)) * (size))
66 #define FETCH(x) fetch_texel_3d_##x
69 #error illegal number of texture dimensions
73 /* MESA_FORMAT_RGBA **********************************************************/
75 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
76 static void FETCH(f_rgba
)( const struct gl_texture_image
*texImage
,
77 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
79 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 4);
80 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
81 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
82 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
83 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[3]);
87 /* Store a GLchan RGBA texel */
88 static void store_texel_rgba(struct gl_texture_image
*texImage
,
89 GLint i
, GLint j
, GLint k
, const void *texel
)
91 const GLchan
*rgba
= (const GLchan
*) texel
;
92 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 4);
100 /* MESA_FORMAT_RGB ***********************************************************/
102 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
103 static void FETCH(f_rgb
)( const struct gl_texture_image
*texImage
,
104 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
106 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 3);
107 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
108 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
109 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
114 static void store_texel_rgb(struct gl_texture_image
*texImage
,
115 GLint i
, GLint j
, GLint k
, const void *texel
)
117 const GLchan
*rgba
= (const GLchan
*) texel
;
118 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 3);
119 dst
[0] = rgba
[RCOMP
];
120 dst
[1] = rgba
[GCOMP
];
121 dst
[2] = rgba
[BCOMP
];
125 /* MESA_FORMAT_ALPHA *********************************************************/
127 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
128 static void FETCH(f_alpha
)( const struct gl_texture_image
*texImage
,
129 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
131 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
135 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[0]);
139 static void store_texel_alpha(struct gl_texture_image
*texImage
,
140 GLint i
, GLint j
, GLint k
, const void *texel
)
142 const GLchan
*rgba
= (const GLchan
*) texel
;
143 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
144 dst
[0] = rgba
[ACOMP
];
148 /* MESA_FORMAT_LUMINANCE *****************************************************/
150 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
151 static void FETCH(f_luminance
)( const struct gl_texture_image
*texImage
,
152 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
154 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
157 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[0]);
162 static void store_texel_luminance(struct gl_texture_image
*texImage
,
163 GLint i
, GLint j
, GLint k
, const void *texel
)
165 const GLchan
*rgba
= (const GLchan
*) texel
;
166 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
167 dst
[0] = rgba
[RCOMP
];
171 /* MESA_FORMAT_LUMINANCE_ALPHA ***********************************************/
173 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
174 static void FETCH(f_luminance_alpha
)(const struct gl_texture_image
*texImage
,
175 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
177 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 2);
180 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[0]);
181 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[1]);
185 static void store_texel_luminance_alpha(struct gl_texture_image
*texImage
,
186 GLint i
, GLint j
, GLint k
, const void *texel
)
188 const GLchan
*rgba
= (const GLchan
*) texel
;
189 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 2);
190 dst
[0] = rgba
[RCOMP
];
191 dst
[1] = rgba
[ACOMP
];
195 /* MESA_FORMAT_INTENSITY *****************************************************/
197 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
198 static void FETCH(f_intensity
)( const struct gl_texture_image
*texImage
,
199 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
201 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
205 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[0]);
209 static void store_texel_intensity(struct gl_texture_image
*texImage
,
210 GLint i
, GLint j
, GLint k
, const void *texel
)
212 const GLchan
*rgba
= (const GLchan
*) texel
;
213 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
214 dst
[0] = rgba
[RCOMP
];
219 /* MESA_FORMAT_Z32 ***********************************************************/
221 /* Fetch depth texel from 1D, 2D or 3D 32-bit depth texture,
222 * returning 1 GLfloat.
223 * Note: no GLchan version of this function.
225 static void FETCH(f_z32
)( const struct gl_texture_image
*texImage
,
226 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
228 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
229 texel
[0] = src
[0] * (1.0F
/ 0xffffffff);
233 static void store_texel_z32(struct gl_texture_image
*texImage
,
234 GLint i
, GLint j
, GLint k
, const void *texel
)
236 const GLuint
*depth
= (const GLuint
*) texel
;
237 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
243 /* MESA_FORMAT_Z16 ***********************************************************/
245 /* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
246 * returning 1 GLfloat.
247 * Note: no GLchan version of this function.
249 static void FETCH(f_z16
)(const struct gl_texture_image
*texImage
,
250 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
252 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
253 texel
[0] = src
[0] * (1.0F
/ 65535.0F
);
257 static void store_texel_z16(struct gl_texture_image
*texImage
,
258 GLint i
, GLint j
, GLint k
, const void *texel
)
260 const GLushort
*depth
= (const GLushort
*) texel
;
261 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
267 /* MESA_FORMAT_RGBA_F32 ******************************************************/
269 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
271 static void FETCH(f_rgba_f32
)( const struct gl_texture_image
*texImage
,
272 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
274 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 4);
275 texel
[RCOMP
] = src
[0];
276 texel
[GCOMP
] = src
[1];
277 texel
[BCOMP
] = src
[2];
278 texel
[ACOMP
] = src
[3];
282 static void store_texel_rgba_f32(struct gl_texture_image
*texImage
,
283 GLint i
, GLint j
, GLint k
, const void *texel
)
285 const GLfloat
*depth
= (const GLfloat
*) texel
;
286 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
287 dst
[0] = depth
[RCOMP
];
288 dst
[1] = depth
[GCOMP
];
289 dst
[2] = depth
[BCOMP
];
290 dst
[3] = depth
[ACOMP
];
295 /* MESA_FORMAT_RGBA_F16 ******************************************************/
297 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
298 * returning 4 GLfloats.
300 static void FETCH(f_rgba_f16
)( const struct gl_texture_image
*texImage
,
301 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
303 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 4);
304 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
305 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
306 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
307 texel
[ACOMP
] = _mesa_half_to_float(src
[3]);
311 static void store_texel_rgba_f16(struct gl_texture_image
*texImage
,
312 GLint i
, GLint j
, GLint k
, const void *texel
)
314 const GLfloat
*depth
= (const GLfloat
*) texel
;
315 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
316 dst
[0] = _mesa_float_to_half(*depth
);
320 /* MESA_FORMAT_RGB_F32 *******************************************************/
322 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
323 * returning 4 GLfloats.
325 static void FETCH(f_rgb_f32
)( const struct gl_texture_image
*texImage
,
326 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
328 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 3);
329 texel
[RCOMP
] = src
[0];
330 texel
[GCOMP
] = src
[1];
331 texel
[BCOMP
] = src
[2];
336 static void store_texel_rgb_f32(struct gl_texture_image
*texImage
,
337 GLint i
, GLint j
, GLint k
, const void *texel
)
339 const GLfloat
*depth
= (const GLfloat
*) texel
;
340 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
346 /* MESA_FORMAT_RGB_F16 *******************************************************/
348 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
349 * returning 4 GLfloats.
351 static void FETCH(f_rgb_f16
)( const struct gl_texture_image
*texImage
,
352 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
354 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 3);
355 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
356 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
357 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
362 static void store_texel_rgb_f16(struct gl_texture_image
*texImage
,
363 GLint i
, GLint j
, GLint k
, const void *texel
)
365 const GLfloat
*depth
= (const GLfloat
*) texel
;
366 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
367 dst
[0] = _mesa_float_to_half(*depth
);
372 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
374 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
375 * returning 4 GLfloats.
377 static void FETCH(f_alpha_f32
)( const struct gl_texture_image
*texImage
,
378 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
380 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
384 texel
[ACOMP
] = src
[0];
388 static void store_texel_alpha_f32(struct gl_texture_image
*texImage
,
389 GLint i
, GLint j
, GLint k
, const void *texel
)
391 const GLfloat
*rgba
= (const GLfloat
*) texel
;
392 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
393 dst
[0] = rgba
[ACOMP
];
398 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
400 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
401 * returning 4 GLfloats.
403 static void FETCH(f_alpha_f16
)( const struct gl_texture_image
*texImage
,
404 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
406 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
410 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
414 static void store_texel_alpha_f16(struct gl_texture_image
*texImage
,
415 GLint i
, GLint j
, GLint k
, const void *texel
)
417 const GLfloat
*rgba
= (const GLfloat
*) texel
;
418 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
419 dst
[0] = _mesa_float_to_half(rgba
[ACOMP
]);
424 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
426 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
427 * returning 4 GLfloats.
429 static void FETCH(f_luminance_f32
)( const struct gl_texture_image
*texImage
,
430 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
432 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
435 texel
[BCOMP
] = src
[0];
440 static void store_texel_luminance_f32(struct gl_texture_image
*texImage
,
441 GLint i
, GLint j
, GLint k
, const void *texel
)
443 const GLfloat
*rgba
= (const GLfloat
*) texel
;
444 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
445 dst
[0] = rgba
[RCOMP
];
450 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
452 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
453 * returning 4 GLfloats.
455 static void FETCH(f_luminance_f16
)( const struct gl_texture_image
*texImage
,
456 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
458 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
461 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
466 static void store_texel_luminance_f16(struct gl_texture_image
*texImage
,
467 GLint i
, GLint j
, GLint k
, const void *texel
)
469 const GLfloat
*rgba
= (const GLfloat
*) texel
;
470 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
471 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
476 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
478 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
479 * returning 4 GLfloats.
481 static void FETCH(f_luminance_alpha_f32
)( const struct gl_texture_image
*texImage
,
482 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
484 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
487 texel
[BCOMP
] = src
[0];
488 texel
[ACOMP
] = src
[1];
492 static void store_texel_luminance_alpha_f32(struct gl_texture_image
*texImage
,
493 GLint i
, GLint j
, GLint k
, const void *texel
)
495 const GLfloat
*rgba
= (const GLfloat
*) texel
;
496 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
497 dst
[0] = rgba
[RCOMP
];
498 dst
[1] = rgba
[ACOMP
];
503 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
505 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
506 * returning 4 GLfloats.
508 static void FETCH(f_luminance_alpha_f16
)( const struct gl_texture_image
*texImage
,
509 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
511 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
514 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
515 texel
[ACOMP
] = _mesa_half_to_float(src
[1]);
519 static void store_texel_luminance_alpha_f16(struct gl_texture_image
*texImage
,
520 GLint i
, GLint j
, GLint k
, const void *texel
)
522 const GLfloat
*rgba
= (const GLfloat
*) texel
;
523 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
524 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
525 dst
[1] = _mesa_float_to_half(rgba
[ACOMP
]);
530 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
532 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
533 * returning 4 GLfloats.
535 static void FETCH(f_intensity_f32
)( const struct gl_texture_image
*texImage
,
536 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
538 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
542 texel
[ACOMP
] = src
[0];
546 static void store_texel_intensity_f32(struct gl_texture_image
*texImage
,
547 GLint i
, GLint j
, GLint k
, const void *texel
)
549 const GLfloat
*rgba
= (const GLfloat
*) texel
;
550 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
551 dst
[0] = rgba
[RCOMP
];
556 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
558 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
559 * returning 4 GLfloats.
561 static void FETCH(f_intensity_f16
)( const struct gl_texture_image
*texImage
,
562 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
564 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
568 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
572 static void store_texel_intensity_f16(struct gl_texture_image
*texImage
,
573 GLint i
, GLint j
, GLint k
, const void *texel
)
575 const GLfloat
*rgba
= (const GLfloat
*) texel
;
576 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
577 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
585 * Begin Hardware formats
588 /* MESA_FORMAT_RGBA8888 ******************************************************/
590 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
591 static void FETCH(f_rgba8888
)( const struct gl_texture_image
*texImage
,
592 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
594 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
595 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
596 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
597 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
598 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
604 static void store_texel_rgba8888(struct gl_texture_image
*texImage
,
605 GLint i
, GLint j
, GLint k
, const void *texel
)
607 const GLubyte
*rgba
= (const GLubyte
*) texel
;
608 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
609 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
614 /* MESA_FORMAT_RGBA888_REV ***************************************************/
616 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
617 static void FETCH(f_rgba8888_rev
)( const struct gl_texture_image
*texImage
,
618 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
620 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
621 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
622 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
623 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
624 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
628 static void store_texel_rgba8888_rev(struct gl_texture_image
*texImage
,
629 GLint i
, GLint j
, GLint k
, const void *texel
)
631 const GLubyte
*rgba
= (const GLubyte
*) texel
;
632 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
633 *dst
= PACK_COLOR_8888_REV(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
638 /* MESA_FORMAT_ARGB8888 ******************************************************/
640 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
641 static void FETCH(f_argb8888
)( const struct gl_texture_image
*texImage
,
642 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
644 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
645 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
646 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
647 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
648 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
652 static void store_texel_argb8888(struct gl_texture_image
*texImage
,
653 GLint i
, GLint j
, GLint k
, const void *texel
)
655 const GLubyte
*rgba
= (const GLubyte
*) texel
;
656 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
657 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
662 /* MESA_FORMAT_ARGB8888_REV **************************************************/
664 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
665 static void FETCH(f_argb8888_rev
)( const struct gl_texture_image
*texImage
,
666 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
668 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
669 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
670 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
671 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
672 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
676 static void store_texel_argb8888_rev(struct gl_texture_image
*texImage
,
677 GLint i
, GLint j
, GLint k
, const void *texel
)
679 const GLubyte
*rgba
= (const GLubyte
*) texel
;
680 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
681 *dst
= PACK_COLOR_8888(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
], rgba
[ACOMP
]);
686 /* MESA_FORMAT_RGB888 ********************************************************/
688 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
689 static void FETCH(f_rgb888
)( const struct gl_texture_image
*texImage
,
690 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
692 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
693 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
694 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
695 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
700 static void store_texel_rgb888(struct gl_texture_image
*texImage
,
701 GLint i
, GLint j
, GLint k
, const void *texel
)
703 const GLubyte
*rgba
= (const GLubyte
*) texel
;
704 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
705 dst
[0] = rgba
[BCOMP
];
706 dst
[1] = rgba
[GCOMP
];
707 dst
[2] = rgba
[RCOMP
];
712 /* MESA_FORMAT_BGR888 ********************************************************/
714 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
715 static void FETCH(f_bgr888
)( const struct gl_texture_image
*texImage
,
716 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
718 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
719 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[0] );
720 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
721 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[2] );
726 static void store_texel_bgr888(struct gl_texture_image
*texImage
,
727 GLint i
, GLint j
, GLint k
, const void *texel
)
729 const GLubyte
*rgba
= (const GLubyte
*) texel
;
730 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
731 dst
[0] = rgba
[RCOMP
];
732 dst
[1] = rgba
[GCOMP
];
733 dst
[2] = rgba
[BCOMP
];
738 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
739 instead of slow (g << 2) * 255 / 252 (always rounds down) */
741 /* MESA_FORMAT_RGB565 ********************************************************/
743 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
744 static void FETCH(f_rgb565
)( const struct gl_texture_image
*texImage
,
745 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
747 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
748 const GLushort s
= *src
;
749 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
750 texel
[GCOMP
] = ((s
>> 5 ) & 0x3f) * (1.0F
/ 63.0F
);
751 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
756 static void store_texel_rgb565(struct gl_texture_image
*texImage
,
757 GLint i
, GLint j
, GLint k
, const void *texel
)
759 const GLubyte
*rgba
= (const GLubyte
*) texel
;
760 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
761 *dst
= PACK_COLOR_565(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
766 /* MESA_FORMAT_RGB565_REV ****************************************************/
768 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
769 static void FETCH(f_rgb565_rev
)( const struct gl_texture_image
*texImage
,
770 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
772 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
773 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
774 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
775 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
776 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
781 static void store_texel_rgb565_rev(struct gl_texture_image
*texImage
,
782 GLint i
, GLint j
, GLint k
, const void *texel
)
784 const GLubyte
*rgba
= (const GLubyte
*) texel
;
785 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
786 *dst
= PACK_COLOR_565(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
790 /* MESA_FORMAT_RGBA4444 ******************************************************/
792 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
793 static void FETCH(f_rgba4444
)( const struct gl_texture_image
*texImage
,
794 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
796 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
797 const GLushort s
= *src
;
798 texel
[RCOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
799 texel
[GCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
800 texel
[BCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
801 texel
[ACOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
805 static void store_texel_rgba4444(struct gl_texture_image
*texImage
,
806 GLint i
, GLint j
, GLint k
, const void *texel
)
808 const GLubyte
*rgba
= (const GLubyte
*) texel
;
809 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
810 *dst
= PACK_COLOR_4444(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
815 /* MESA_FORMAT_ARGB4444 ******************************************************/
817 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
818 static void FETCH(f_argb4444
)( const struct gl_texture_image
*texImage
,
819 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
821 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
822 const GLushort s
= *src
;
823 texel
[RCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
824 texel
[GCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
825 texel
[BCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
826 texel
[ACOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
830 static void store_texel_argb4444(struct gl_texture_image
*texImage
,
831 GLint i
, GLint j
, GLint k
, const void *texel
)
833 const GLubyte
*rgba
= (const GLubyte
*) texel
;
834 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
835 *dst
= PACK_COLOR_4444(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
840 /* MESA_FORMAT_ARGB4444_REV **************************************************/
842 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
843 static void FETCH(f_argb4444_rev
)( const struct gl_texture_image
*texImage
,
844 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
846 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
847 texel
[RCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
848 texel
[GCOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
849 texel
[BCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
850 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
854 static void store_texel_argb4444_rev(struct gl_texture_image
*texImage
,
855 GLint i
, GLint j
, GLint k
, const void *texel
)
857 const GLubyte
*rgba
= (const GLubyte
*) texel
;
858 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
859 *dst
= PACK_COLOR_4444(rgba
[ACOMP
], rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
863 /* MESA_FORMAT_RGBA5551 ******************************************************/
865 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
866 static void FETCH(f_rgba5551
)( const struct gl_texture_image
*texImage
,
867 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
869 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
870 const GLushort s
= *src
;
871 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
872 texel
[GCOMP
] = ((s
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
873 texel
[BCOMP
] = ((s
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
874 texel
[ACOMP
] = ((s
) & 0x01) * 1.0F
;
878 static void store_texel_rgba5551(struct gl_texture_image
*texImage
,
879 GLint i
, GLint j
, GLint k
, const void *texel
)
881 const GLubyte
*rgba
= (const GLubyte
*) texel
;
882 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
883 *dst
= PACK_COLOR_5551(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
887 /* MESA_FORMAT_ARGB1555 ******************************************************/
889 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
890 static void FETCH(f_argb1555
)( const struct gl_texture_image
*texImage
,
891 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
893 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
894 const GLushort s
= *src
;
895 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
896 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
897 texel
[BCOMP
] = ((s
>> 0) & 0x1f) * (1.0F
/ 31.0F
);
898 texel
[ACOMP
] = ((s
>> 15) & 0x01) * 1.0F
;
902 static void store_texel_argb1555(struct gl_texture_image
*texImage
,
903 GLint i
, GLint j
, GLint k
, const void *texel
)
905 const GLubyte
*rgba
= (const GLubyte
*) texel
;
906 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
907 *dst
= PACK_COLOR_1555(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
912 /* MESA_FORMAT_ARGB1555_REV **************************************************/
914 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
915 static void FETCH(f_argb1555_rev
)( const struct gl_texture_image
*texImage
,
916 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
918 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
919 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
920 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
921 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
922 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
923 texel
[ACOMP
] = UBYTE_TO_FLOAT( ((s
>> 15) & 0x01) * 255 );
927 static void store_texel_argb1555_rev(struct gl_texture_image
*texImage
,
928 GLint i
, GLint j
, GLint k
, const void *texel
)
930 const GLubyte
*rgba
= (const GLubyte
*) texel
;
931 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
932 *dst
= PACK_COLOR_1555_REV(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
937 /* MESA_FORMAT_AL88 **********************************************************/
939 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
940 static void FETCH(f_al88
)( const struct gl_texture_image
*texImage
,
941 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
943 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
946 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
947 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
951 static void store_texel_al88(struct gl_texture_image
*texImage
,
952 GLint i
, GLint j
, GLint k
, const void *texel
)
954 const GLubyte
*rgba
= (const GLubyte
*) texel
;
955 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
956 *dst
= PACK_COLOR_88(rgba
[ACOMP
], rgba
[RCOMP
]);
961 /* MESA_FORMAT_AL88_REV ******************************************************/
963 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
964 static void FETCH(f_al88_rev
)( const struct gl_texture_image
*texImage
,
965 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
967 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
970 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
971 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
975 static void store_texel_al88_rev(struct gl_texture_image
*texImage
,
976 GLint i
, GLint j
, GLint k
, const void *texel
)
978 const GLubyte
*rgba
= (const GLubyte
*) texel
;
979 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
980 *dst
= PACK_COLOR_88(rgba
[RCOMP
], rgba
[ACOMP
]);
985 /* MESA_FORMAT_RGB332 ********************************************************/
987 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
988 static void FETCH(f_rgb332
)( const struct gl_texture_image
*texImage
,
989 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
991 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
992 const GLubyte s
= *src
;
993 texel
[RCOMP
] = ((s
>> 5) & 0x7) * (1.0F
/ 7.0F
);
994 texel
[GCOMP
] = ((s
>> 2) & 0x7) * (1.0F
/ 7.0F
);
995 texel
[BCOMP
] = ((s
) & 0x3) * (1.0F
/ 3.0F
);
1000 static void store_texel_rgb332(struct gl_texture_image
*texImage
,
1001 GLint i
, GLint j
, GLint k
, const void *texel
)
1003 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1004 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1005 *dst
= PACK_COLOR_332(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1010 /* MESA_FORMAT_A8 ************************************************************/
1012 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1013 static void FETCH(f_a8
)( const struct gl_texture_image
*texImage
,
1014 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1016 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1019 texel
[BCOMP
] = 0.0F
;
1020 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1024 static void store_texel_a8(struct gl_texture_image
*texImage
,
1025 GLint i
, GLint j
, GLint k
, const void *texel
)
1027 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1028 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1034 /* MESA_FORMAT_L8 ************************************************************/
1036 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1037 static void FETCH(f_l8
)( const struct gl_texture_image
*texImage
,
1038 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1040 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1043 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
1044 texel
[ACOMP
] = 1.0F
;
1048 static void store_texel_l8(struct gl_texture_image
*texImage
,
1049 GLint i
, GLint j
, GLint k
, const void *texel
)
1051 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1052 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1058 /* MESA_FORMAT_I8 ************************************************************/
1060 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1061 static void FETCH(f_i8
)( const struct gl_texture_image
*texImage
,
1062 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1064 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1068 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1072 static void store_texel_i8(struct gl_texture_image
*texImage
,
1073 GLint i
, GLint j
, GLint k
, const void *texel
)
1075 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1076 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1082 /* MESA_FORMAT_CI8 ***********************************************************/
1084 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1085 * color table, and return 4 GLchans.
1087 static void FETCH(f_ci8
)( const struct gl_texture_image
*texImage
,
1088 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1090 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1091 const struct gl_color_table
*palette
;
1093 GET_CURRENT_CONTEXT(ctx
);
1095 if (ctx
->Texture
.SharedPalette
) {
1096 palette
= &ctx
->Texture
.Palette
;
1099 palette
= &texImage
->TexObject
->Palette
;
1101 if (palette
->Size
== 0)
1102 return; /* undefined results */
1104 /* Mask the index against size of palette to avoid going out of bounds */
1105 index
= (*src
) & (palette
->Size
- 1);
1108 const GLfloat
*table
= palette
->TableF
;
1109 switch (palette
->_BaseFormat
) {
1113 texel
[BCOMP
] = 0.0F
;
1114 texel
[ACOMP
] = table
[index
];
1119 texel
[BCOMP
] = table
[index
];
1120 texel
[ACOMP
] = 1.0F
;
1126 texel
[ACOMP
] = table
[index
];
1128 case GL_LUMINANCE_ALPHA
:
1131 texel
[BCOMP
] = table
[index
* 2 + 0];
1132 texel
[ACOMP
] = table
[index
* 2 + 1];
1135 texel
[RCOMP
] = table
[index
* 3 + 0];
1136 texel
[GCOMP
] = table
[index
* 3 + 1];
1137 texel
[BCOMP
] = table
[index
* 3 + 2];
1138 texel
[ACOMP
] = 1.0F
;
1141 texel
[RCOMP
] = table
[index
* 4 + 0];
1142 texel
[GCOMP
] = table
[index
* 4 + 1];
1143 texel
[BCOMP
] = table
[index
* 4 + 2];
1144 texel
[ACOMP
] = table
[index
* 4 + 3];
1147 _mesa_problem(ctx
, "Bad palette format in fetch_texel_ci8");
1154 static void store_texel_ci8(struct gl_texture_image
*texImage
,
1155 GLint i
, GLint j
, GLint k
, const void *texel
)
1157 const GLubyte
*index
= (const GLubyte
*) texel
;
1158 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1164 #if FEATURE_EXT_texture_sRGB
1166 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1167 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1168 static void FETCH(srgb8
)(const struct gl_texture_image
*texImage
,
1169 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1171 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1172 texel
[RCOMP
] = nonlinear_to_linear(src
[2]);
1173 texel
[GCOMP
] = nonlinear_to_linear(src
[1]);
1174 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1175 texel
[ACOMP
] = 1.0F
;
1179 static void store_texel_srgb8(struct gl_texture_image
*texImage
,
1180 GLint i
, GLint j
, GLint k
, const void *texel
)
1182 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1183 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1184 dst
[0] = rgba
[BCOMP
]; /* no conversion */
1185 dst
[1] = rgba
[GCOMP
];
1186 dst
[2] = rgba
[RCOMP
];
1190 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1191 static void FETCH(srgba8
)(const struct gl_texture_image
*texImage
,
1192 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1194 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1195 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 24) );
1196 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1197 texel
[BCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1198 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff ); /* linear! */
1202 static void store_texel_srgba8(struct gl_texture_image
*texImage
,
1203 GLint i
, GLint j
, GLint k
, const void *texel
)
1205 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1206 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1207 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1211 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1212 static void FETCH(sargb8
)(const struct gl_texture_image
*texImage
,
1213 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1215 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1216 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1217 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1218 texel
[BCOMP
] = nonlinear_to_linear( (s
) & 0xff );
1219 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) ); /* linear! */
1223 static void store_texel_sargb8(struct gl_texture_image
*texImage
,
1224 GLint i
, GLint j
, GLint k
, const void *texel
)
1226 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1227 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1228 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1232 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1233 static void FETCH(sl8
)(const struct gl_texture_image
*texImage
,
1234 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1236 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1239 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1240 texel
[ACOMP
] = 1.0F
;
1244 static void store_texel_sl8(struct gl_texture_image
*texImage
,
1245 GLint i
, GLint j
, GLint k
, const void *texel
)
1247 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1248 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1249 dst
[0] = rgba
[RCOMP
];
1253 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1254 static void FETCH(sla8
)(const struct gl_texture_image
*texImage
,
1255 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1257 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1260 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1261 texel
[ACOMP
] = UBYTE_TO_FLOAT(src
[1]); /* linear */
1265 static void store_texel_sla8(struct gl_texture_image
*texImage
,
1266 GLint i
, GLint j
, GLint k
, const void *texel
)
1268 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1269 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1270 dst
[0] = rgba
[RCOMP
];
1271 dst
[1] = rgba
[ACOMP
];
1275 #endif /* FEATURE_EXT_texture_sRGB */
1278 /* MESA_FORMAT_DUDV8 ********************************************************/
1280 /* this format by definition produces 0,0,0,1 as rgba values,
1281 however we'll return the dudv values as rg and fix up elsewhere */
1282 static void FETCH(dudv8
)(const struct gl_texture_image
*texImage
,
1283 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1285 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 2);
1286 texel
[RCOMP
] = BYTE_TO_FLOAT(src
[0]);
1287 texel
[GCOMP
] = BYTE_TO_FLOAT(src
[1]);
1292 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1294 static void FETCH(signed_rgba8888
)( const struct gl_texture_image
*texImage
,
1295 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1297 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1298 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (s
>> 24) );
1299 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (s
>> 16) & 0xff );
1300 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (s
>> 8) & 0xff );
1301 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (s
) & 0xff );
1305 static void store_texel_signed_rgba8888(struct gl_texture_image
*texImage
,
1306 GLint i
, GLint j
, GLint k
, const void *texel
)
1308 const GLbyte
*rgba
= (const GLbyte
*) texel
;
1309 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1310 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1314 static void FETCH(signed_rgba8888_rev
)( const struct gl_texture_image
*texImage
,
1315 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1317 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1318 texel
[RCOMP
] = BYTE_TO_FLOAT_TEX( (s
) & 0xff );
1319 texel
[GCOMP
] = BYTE_TO_FLOAT_TEX( (s
>> 8) & 0xff );
1320 texel
[BCOMP
] = BYTE_TO_FLOAT_TEX( (s
>> 16) & 0xff );
1321 texel
[ACOMP
] = BYTE_TO_FLOAT_TEX( (s
>> 24) );
1325 static void store_texel_signed_rgba8888_rev(struct gl_texture_image
*texImage
,
1326 GLint i
, GLint j
, GLint k
, const void *texel
)
1328 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1329 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1330 *dst
= PACK_COLOR_8888_REV(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1336 /* MESA_FORMAT_YCBCR *********************************************************/
1338 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
1339 * We convert YCbCr to RGB here.
1341 static void FETCH(f_ycbcr
)( const struct gl_texture_image
*texImage
,
1342 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1344 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1345 const GLushort
*src1
= src0
+ 1; /* odd */
1346 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1347 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1348 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1349 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1350 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1351 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1352 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1353 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1354 r
*= (1.0F
/ 255.0F
);
1355 g
*= (1.0F
/ 255.0F
);
1356 b
*= (1.0F
/ 255.0F
);
1357 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1358 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1359 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1360 texel
[ACOMP
] = 1.0F
;
1364 static void store_texel_ycbcr(struct gl_texture_image
*texImage
,
1365 GLint i
, GLint j
, GLint k
, const void *texel
)
1377 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1379 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
1380 * We convert YCbCr to RGB here.
1382 static void FETCH(f_ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1383 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1385 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1386 const GLushort
*src1
= src0
+ 1; /* odd */
1387 const GLubyte y0
= *src0
& 0xff; /* luminance */
1388 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1389 const GLubyte y1
= *src1
& 0xff; /* luminance */
1390 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1391 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
1392 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
1393 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
1394 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
1395 r
*= (1.0F
/ 255.0F
);
1396 g
*= (1.0F
/ 255.0F
);
1397 b
*= (1.0F
/ 255.0F
);
1398 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
1399 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
1400 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
1401 texel
[ACOMP
] = 1.0F
;
1405 static void store_texel_ycbcr_rev(struct gl_texture_image
*texImage
,
1406 GLint i
, GLint j
, GLint k
, const void *texel
)
1418 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1420 static void FETCH(f_z24_s8
)( const struct gl_texture_image
*texImage
,
1421 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1423 /* only return Z, not stencil data */
1424 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1425 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
1426 texel
[0] = ((*src
) >> 8) * scale
;
1427 ASSERT(texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_Z24_S8
);
1428 ASSERT(texel
[0] >= 0.0F
);
1429 ASSERT(texel
[0] <= 1.0F
);
1433 static void store_texel_z24_s8(struct gl_texture_image
*texImage
,
1434 GLint i
, GLint j
, GLint k
, const void *texel
)
1436 /* only store Z, not stencil */
1437 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1438 GLfloat depth
= *((GLfloat
*) texel
);
1439 GLuint zi
= ((GLuint
) (depth
* 0xffffff)) << 8;
1440 *dst
= zi
| (*dst
& 0xff);
1445 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1447 static void FETCH(f_s8_z24
)( const struct gl_texture_image
*texImage
,
1448 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1450 /* only return Z, not stencil data */
1451 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1452 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
1453 texel
[0] = ((*src
) & 0x00ffffff) * scale
;
1454 ASSERT(texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_S8_Z24
);
1455 ASSERT(texel
[0] >= 0.0F
);
1456 ASSERT(texel
[0] <= 1.0F
);
1460 static void store_texel_s8_z24(struct gl_texture_image
*texImage
,
1461 GLint i
, GLint j
, GLint k
, const void *texel
)
1463 /* only store Z, not stencil */
1464 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1465 GLfloat depth
= *((GLfloat
*) texel
);
1466 GLuint zi
= (GLuint
) (depth
* 0xffffff);
1467 *dst
= zi
| (*dst
& 0xff000000);