2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * \file texformat_tmp.h
28 * Texel fetch functions template.
30 * This template file is used by texformat.c to generate texel fetch functions
31 * for 1-D, 2-D and 3-D texture images.
33 * It should be expanded by defining \p DIM as the number texture dimensions
34 * (1, 2 or 3). According to the value of \p DIM a series of macros is defined
35 * for the texel lookup in the gl_texture_image::Data.
37 * \sa texformat.c and FetchTexel.
39 * \author Gareth Hughes
46 #define CHAN_ADDR( t, i, j, k, sz ) \
47 ((void) (j), (void) (k), \
48 ((GLchan *)(t)->Data + (i) * (sz)))
49 #define UBYTE_ADDR( t, i, j, k, sz ) \
50 ((void) (j), (void) (k), \
51 ((GLubyte *)(t)->Data + (i) * (sz)))
52 #define USHORT_ADDR( t, i, j, k ) \
53 ((void) (j), (void) (k), \
54 ((GLushort *)(t)->Data + (i)))
55 #define UINT_ADDR( t, i, j, k ) \
56 ((void) (j), (void) (k), \
57 ((GLuint *)(t)->Data + (i)))
58 #define FLOAT_ADDR( t, i, j, k, sz ) \
59 ((void) (j), (void) (k), \
60 ((GLfloat *)(t)->Data + (i) * (sz)))
61 #define HALF_ADDR( t, i, j, k, sz ) \
62 ((void) (j), (void) (k), \
63 ((GLhalfARB *)(t)->Data + (i) * (sz)))
65 #define FETCH(x) fetch_texel_1d_##x
69 #define CHAN_ADDR( t, i, j, k, sz ) \
71 ((GLchan *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz)))
72 #define UBYTE_ADDR( t, i, j, k, sz ) \
74 ((GLubyte *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz)))
75 #define USHORT_ADDR( t, i, j, k ) \
77 ((GLushort *)(t)->Data + ((t)->RowStride * (j) + (i))))
78 #define UINT_ADDR( t, i, j, k ) \
80 ((GLuint *)(t)->Data + ((t)->RowStride * (j) + (i))))
81 #define FLOAT_ADDR( t, i, j, k, sz ) \
83 ((GLfloat *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz)))
84 #define HALF_ADDR( t, i, j, k, sz ) \
86 ((GLhalfARB *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz)))
88 #define FETCH(x) fetch_texel_2d_##x
92 #define CHAN_ADDR( t, i, j, k, sz ) \
93 (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \
94 (t)->RowStride + (i)) * (sz)
95 #define UBYTE_ADDR( t, i, j, k, sz ) \
96 ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \
97 (t)->RowStride + (i)) * (sz))
98 #define USHORT_ADDR( t, i, j, k ) \
99 ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \
100 (t)->RowStride + (i)))
101 #define UINT_ADDR( t, i, j, k ) \
102 ((GLuint *)(t)->Data + (((t)->Height * (k) + (j)) * \
103 (t)->RowStride + (i)))
104 #define FLOAT_ADDR( t, i, j, k, sz ) \
105 ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \
106 (t)->RowStride + (i)) * (sz))
107 #define HALF_ADDR( t, i, j, k, sz ) \
108 ((GLhalfARB *)(t)->Data + (((t)->Height * (k) + (j)) * \
109 (t)->RowStride + (i)) * (sz))
111 #define FETCH(x) fetch_texel_3d_##x
114 #error illegal number of texture dimensions
118 /* MESA_FORMAT_RGBA **********************************************************/
120 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLchans */
121 static void FETCH(rgba
)( const struct gl_texture_image
*texImage
,
122 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
124 const GLchan
*src
= CHAN_ADDR( texImage
, i
, j
, k
, 4 );
125 COPY_CHAN4( texel
, src
);
128 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
129 static void FETCH(f_rgba
)( const struct gl_texture_image
*texImage
,
130 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
132 const GLchan
*src
= CHAN_ADDR( texImage
, i
, j
, k
, 4 );
133 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
134 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
135 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
136 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[3]);
140 /* Store a GLchan RGBA texel */
141 static void store_texel_rgba(struct gl_texture_image
*texImage
,
142 GLint i
, GLint j
, GLint k
, const void *texel
)
144 const GLchan
*rgba
= (const GLchan
*) texel
;
145 GLchan
*dst
= CHAN_ADDR(texImage
, i
, j
, k
, 4);
146 dst
[0] = rgba
[RCOMP
];
147 dst
[1] = rgba
[GCOMP
];
148 dst
[2] = rgba
[BCOMP
];
149 dst
[3] = rgba
[ACOMP
];
153 /* MESA_FORMAT_RGB ***********************************************************/
155 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLchans */
156 static void FETCH(rgb
)( const struct gl_texture_image
*texImage
,
157 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
159 const GLchan
*src
= CHAN_ADDR( texImage
, i
, j
, k
, 3 );
160 texel
[RCOMP
] = src
[0];
161 texel
[GCOMP
] = src
[1];
162 texel
[BCOMP
] = src
[2];
163 texel
[ACOMP
] = CHAN_MAX
;
166 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
167 static void FETCH(f_rgb
)( const struct gl_texture_image
*texImage
,
168 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
170 const GLchan
*src
= CHAN_ADDR( texImage
, i
, j
, k
, 3 );
171 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
172 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
173 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
178 static void store_texel_rgb(struct gl_texture_image
*texImage
,
179 GLint i
, GLint j
, GLint k
, const void *texel
)
181 const GLchan
*rgba
= (const GLchan
*) texel
;
182 GLchan
*dst
= CHAN_ADDR(texImage
, i
, j
, k
, 3);
183 dst
[0] = rgba
[RCOMP
];
184 dst
[1] = rgba
[GCOMP
];
185 dst
[2] = rgba
[BCOMP
];
189 /* MESA_FORMAT_ALPHA *********************************************************/
191 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
192 static void FETCH(alpha
)( const struct gl_texture_image
*texImage
,
193 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
195 const GLchan
*src
= CHAN_ADDR( texImage
, i
, j
, k
, 1 );
199 texel
[ACOMP
] = src
[0];
202 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLfloats */
203 static void FETCH(f_alpha
)( const struct gl_texture_image
*texImage
,
204 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
206 const GLchan
*src
= CHAN_ADDR( texImage
, i
, j
, k
, 1 );
210 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[0]);
214 static void store_texel_alpha(struct gl_texture_image
*texImage
,
215 GLint i
, GLint j
, GLint k
, const void *texel
)
217 const GLchan
*rgba
= (const GLchan
*) texel
;
218 GLchan
*dst
= CHAN_ADDR(texImage
, i
, j
, k
, 1);
219 dst
[0] = rgba
[ACOMP
];
223 /* MESA_FORMAT_LUMINANCE *****************************************************/
225 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
226 static void FETCH(luminance
)( const struct gl_texture_image
*texImage
,
227 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
229 const GLchan
*src
= CHAN_ADDR( texImage
, i
, j
, k
, 1 );
232 texel
[BCOMP
] = src
[0];
233 texel
[ACOMP
] = CHAN_MAX
;
236 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLfloats */
237 static void FETCH(f_luminance
)( const struct gl_texture_image
*texImage
,
238 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
240 const GLchan
*src
= CHAN_ADDR( texImage
, i
, j
, k
, 1 );
243 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[0]);
248 static void store_texel_luminance(struct gl_texture_image
*texImage
,
249 GLint i
, GLint j
, GLint k
, const void *texel
)
251 const GLchan
*rgba
= (const GLchan
*) texel
;
252 GLchan
*dst
= CHAN_ADDR(texImage
, i
, j
, k
, 1);
253 dst
[0] = rgba
[RCOMP
];
257 /* MESA_FORMAT_LUMINANCE_ALPHA ***********************************************/
259 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
260 static void FETCH(luminance_alpha
)( const struct gl_texture_image
*texImage
,
261 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
263 const GLchan
*src
= CHAN_ADDR( texImage
, i
, j
, k
, 2 );
264 texel
[RCOMP
] = src
[0];
265 texel
[GCOMP
] = src
[0];
266 texel
[BCOMP
] = src
[0];
267 texel
[ACOMP
] = src
[1];
270 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLfloats */
271 static void FETCH(f_luminance_alpha
)( const struct gl_texture_image
*texImage
,
272 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
274 const GLchan
*src
= CHAN_ADDR( texImage
, i
, j
, k
, 2 );
277 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[0]);
278 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[1]);
282 static void store_texel_luminance_alpha(struct gl_texture_image
*texImage
,
283 GLint i
, GLint j
, GLint k
, const void *texel
)
285 const GLchan
*rgba
= (const GLchan
*) texel
;
286 GLchan
*dst
= CHAN_ADDR(texImage
, i
, j
, k
, 2);
287 dst
[0] = rgba
[RCOMP
];
288 dst
[1] = rgba
[ACOMP
];
292 /* MESA_FORMAT_INTENSITY *****************************************************/
294 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
295 static void FETCH(intensity
)( const struct gl_texture_image
*texImage
,
296 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
298 const GLchan
*src
= CHAN_ADDR( texImage
, i
, j
, k
, 1 );
299 texel
[RCOMP
] = src
[0];
300 texel
[GCOMP
] = src
[0];
301 texel
[BCOMP
] = src
[0];
302 texel
[ACOMP
] = src
[0];
305 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLfloats */
306 static void FETCH(f_intensity
)( const struct gl_texture_image
*texImage
,
307 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
309 const GLchan
*src
= CHAN_ADDR( texImage
, i
, j
, k
, 1 );
313 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[0]);
317 static void store_texel_intensity(struct gl_texture_image
*texImage
,
318 GLint i
, GLint j
, GLint k
, const void *texel
)
320 const GLchan
*rgba
= (const GLchan
*) texel
;
321 GLchan
*dst
= CHAN_ADDR(texImage
, i
, j
, k
, 1);
322 dst
[0] = rgba
[RCOMP
];
327 /* MESA_FORMAT_DEPTH_COMPONENT_F32 *******************************************/
329 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
330 * returning 1 GLfloat.
331 * Note: no GLchan version of this function.
333 static void FETCH(f_depth_component_f32
)( const struct gl_texture_image
*texImage
,
334 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
336 const GLfloat
*src
= FLOAT_ADDR( texImage
, i
, j
, k
, 1 );
341 static void store_texel_depth_component_f32(struct gl_texture_image
*texImage
,
342 GLint i
, GLint j
, GLint k
, const void *texel
)
344 const GLfloat
*depth
= (const GLfloat
*) texel
;
345 GLfloat
*dst
= FLOAT_ADDR(texImage
, i
, j
, k
, 1);
351 /* MESA_FORMAT_DEPTH_COMPONENT16 *********************************************/
353 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
354 * returning 1 GLfloat.
355 * Note: no GLchan version of this function.
357 static void FETCH(f_depth_component16
)(const struct gl_texture_image
*texImage
,
358 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
360 const GLushort
*src
= USHORT_ADDR( texImage
, i
, j
, k
);
361 texel
[0] = src
[0] * (1.0F
/ 65535.0F
);
365 static void store_texel_depth_component16(struct gl_texture_image
*texImage
,
366 GLint i
, GLint j
, GLint k
, const void *texel
)
368 const GLushort
*depth
= (const GLushort
*) texel
;
369 GLushort
*dst
= USHORT_ADDR(texImage
, i
, j
, k
);
375 /* MESA_FORMAT_RGBA_F32 ******************************************************/
377 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLchans.
379 static void FETCH(rgba_f32
)( const struct gl_texture_image
*texImage
,
380 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
382 const GLfloat
*src
= FLOAT_ADDR( texImage
, i
, j
, k
, 4 );
383 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
384 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], src
[1]);
385 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], src
[2]);
386 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], src
[3]);
389 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
391 static void FETCH(f_rgba_f32
)( const struct gl_texture_image
*texImage
,
392 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
394 const GLfloat
*src
= FLOAT_ADDR( texImage
, i
, j
, k
, 4 );
395 texel
[RCOMP
] = src
[0];
396 texel
[GCOMP
] = src
[1];
397 texel
[BCOMP
] = src
[2];
398 texel
[ACOMP
] = src
[3];
402 static void store_texel_rgba_f32(struct gl_texture_image
*texImage
,
403 GLint i
, GLint j
, GLint k
, const void *texel
)
405 const GLfloat
*depth
= (const GLfloat
*) texel
;
406 GLfloat
*dst
= FLOAT_ADDR(texImage
, i
, j
, k
, 1);
407 dst
[0] = depth
[RCOMP
];
408 dst
[1] = depth
[GCOMP
];
409 dst
[2] = depth
[BCOMP
];
410 dst
[3] = depth
[ACOMP
];
415 /* MESA_FORMAT_RGBA_F16 ******************************************************/
417 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
418 * returning 4 GLchans.
420 static void FETCH(rgba_f16
)( const struct gl_texture_image
*texImage
,
421 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
423 const GLhalfARB
*src
= HALF_ADDR( texImage
, i
, j
, k
, 4 );
424 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
425 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], _mesa_half_to_float(src
[1]));
426 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], _mesa_half_to_float(src
[2]));
427 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], _mesa_half_to_float(src
[3]));
430 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
431 * returning 4 GLfloats.
433 static void FETCH(f_rgba_f16
)( const struct gl_texture_image
*texImage
,
434 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
436 const GLhalfARB
*src
= HALF_ADDR( texImage
, i
, j
, k
, 4 );
437 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
438 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
439 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
440 texel
[ACOMP
] = _mesa_half_to_float(src
[3]);
444 static void store_texel_rgba_f16(struct gl_texture_image
*texImage
,
445 GLint i
, GLint j
, GLint k
, const void *texel
)
447 const GLfloat
*depth
= (const GLfloat
*) texel
;
448 GLhalfARB
*dst
= HALF_ADDR(texImage
, i
, j
, k
, 1);
449 dst
[0] = _mesa_float_to_half(*depth
);
453 /* MESA_FORMAT_RGB_F32 *******************************************************/
455 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
456 * returning 4 GLchans.
458 static void FETCH(rgb_f32
)( const struct gl_texture_image
*texImage
,
459 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
461 const GLfloat
*src
= FLOAT_ADDR( texImage
, i
, j
, k
, 3 );
462 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
463 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], src
[1]);
464 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], src
[2]);
465 texel
[ACOMP
] = CHAN_MAX
;
468 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
469 * returning 4 GLfloats.
471 static void FETCH(f_rgb_f32
)( const struct gl_texture_image
*texImage
,
472 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
474 const GLfloat
*src
= FLOAT_ADDR( texImage
, i
, j
, k
, 3 );
475 texel
[RCOMP
] = src
[0];
476 texel
[GCOMP
] = src
[1];
477 texel
[BCOMP
] = src
[2];
482 static void store_texel_rgb_f32(struct gl_texture_image
*texImage
,
483 GLint i
, GLint j
, GLint k
, const void *texel
)
485 const GLfloat
*depth
= (const GLfloat
*) texel
;
486 GLfloat
*dst
= FLOAT_ADDR(texImage
, i
, j
, k
, 1);
492 /* MESA_FORAMT_RGB_F16 *******************************************************/
494 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
495 * returning 4 GLchans.
497 static void FETCH(rgb_f16
)( const struct gl_texture_image
*texImage
,
498 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
500 const GLhalfARB
*src
= HALF_ADDR( texImage
, i
, j
, k
, 3 );
501 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
502 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], _mesa_half_to_float(src
[1]));
503 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], _mesa_half_to_float(src
[2]));
504 texel
[ACOMP
] = CHAN_MAX
;
507 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
508 * returning 4 GLfloats.
510 static void FETCH(f_rgb_f16
)( const struct gl_texture_image
*texImage
,
511 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
513 const GLhalfARB
*src
= HALF_ADDR( texImage
, i
, j
, k
, 3 );
514 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
515 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
516 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
521 static void store_texel_rgb_f16(struct gl_texture_image
*texImage
,
522 GLint i
, GLint j
, GLint k
, const void *texel
)
524 const GLfloat
*depth
= (const GLfloat
*) texel
;
525 GLhalfARB
*dst
= HALF_ADDR(texImage
, i
, j
, k
, 1);
526 dst
[0] = _mesa_float_to_half(*depth
);
531 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
533 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
534 * returning 4 GLchans.
536 static void FETCH(alpha_f32
)( const struct gl_texture_image
*texImage
,
537 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
539 const GLfloat
*src
= FLOAT_ADDR( texImage
, i
, j
, k
, 1 );
543 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], src
[0]);
546 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
547 * returning 4 GLfloats.
549 static void FETCH(f_alpha_f32
)( const struct gl_texture_image
*texImage
,
550 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
552 const GLfloat
*src
= FLOAT_ADDR( texImage
, i
, j
, k
, 1 );
556 texel
[ACOMP
] = src
[0];
560 static void store_texel_alpha_f32(struct gl_texture_image
*texImage
,
561 GLint i
, GLint j
, GLint k
, const void *texel
)
563 const GLfloat
*rgba
= (const GLfloat
*) texel
;
564 GLfloat
*dst
= FLOAT_ADDR(texImage
, i
, j
, k
, 1);
565 dst
[0] = rgba
[ACOMP
];
570 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
572 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
573 * returning 4 GLchans.
575 static void FETCH(alpha_f16
)( const struct gl_texture_image
*texImage
,
576 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
578 const GLhalfARB
*src
= HALF_ADDR( texImage
, i
, j
, k
, 1 );
582 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], _mesa_half_to_float(src
[0]));
585 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
586 * returning 4 GLfloats.
588 static void FETCH(f_alpha_f16
)( const struct gl_texture_image
*texImage
,
589 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
591 const GLhalfARB
*src
= HALF_ADDR( texImage
, i
, j
, k
, 1 );
595 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
599 static void store_texel_alpha_f16(struct gl_texture_image
*texImage
,
600 GLint i
, GLint j
, GLint k
, const void *texel
)
602 const GLfloat
*rgba
= (const GLfloat
*) texel
;
603 GLhalfARB
*dst
= HALF_ADDR(texImage
, i
, j
, k
, 1);
604 dst
[0] = _mesa_float_to_half(rgba
[ACOMP
]);
609 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
611 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
612 * returning 4 GLchans.
614 static void FETCH(luminance_f32
)( const struct gl_texture_image
*texImage
,
615 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
617 const GLfloat
*src
= FLOAT_ADDR( texImage
, i
, j
, k
, 1 );
618 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
620 texel
[BCOMP
] = texel
[RCOMP
];
621 texel
[ACOMP
] = CHAN_MAX
;
624 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
625 * returning 4 GLfloats.
627 static void FETCH(f_luminance_f32
)( const struct gl_texture_image
*texImage
,
628 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
630 const GLfloat
*src
= FLOAT_ADDR( texImage
, i
, j
, k
, 1 );
633 texel
[BCOMP
] = src
[0];
638 static void store_texel_luminance_f32(struct gl_texture_image
*texImage
,
639 GLint i
, GLint j
, GLint k
, const void *texel
)
641 const GLfloat
*rgba
= (const GLfloat
*) texel
;
642 GLfloat
*dst
= FLOAT_ADDR(texImage
, i
, j
, k
, 1);
643 dst
[0] = rgba
[RCOMP
];
648 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
650 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
651 * returning 4 GLchans.
653 static void FETCH(luminance_f16
)( const struct gl_texture_image
*texImage
,
654 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
656 const GLhalfARB
*src
= HALF_ADDR( texImage
, i
, j
, k
, 1 );
657 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
659 texel
[BCOMP
] = texel
[RCOMP
];
660 texel
[ACOMP
] = CHAN_MAX
;
663 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
664 * returning 4 GLfloats.
666 static void FETCH(f_luminance_f16
)( const struct gl_texture_image
*texImage
,
667 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
669 const GLhalfARB
*src
= HALF_ADDR( texImage
, i
, j
, k
, 1 );
672 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
677 static void store_texel_luminance_f16(struct gl_texture_image
*texImage
,
678 GLint i
, GLint j
, GLint k
, const void *texel
)
680 const GLfloat
*rgba
= (const GLfloat
*) texel
;
681 GLhalfARB
*dst
= HALF_ADDR(texImage
, i
, j
, k
, 1);
682 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
687 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
689 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
690 * returning 4 GLchans.
692 static void FETCH(luminance_alpha_f32
)( const struct gl_texture_image
*texImage
,
693 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
695 const GLfloat
*src
= FLOAT_ADDR( texImage
, i
, j
, k
, 2 );
696 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
698 texel
[BCOMP
] = texel
[RCOMP
];
699 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], src
[1]);
702 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
703 * returning 4 GLfloats.
705 static void FETCH(f_luminance_alpha_f32
)( const struct gl_texture_image
*texImage
,
706 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
708 const GLfloat
*src
= FLOAT_ADDR( texImage
, i
, j
, k
, 2 );
711 texel
[BCOMP
] = src
[0];
712 texel
[ACOMP
] = src
[1];
716 static void store_texel_luminance_alpha_f32(struct gl_texture_image
*texImage
,
717 GLint i
, GLint j
, GLint k
, const void *texel
)
719 const GLfloat
*rgba
= (const GLfloat
*) texel
;
720 GLfloat
*dst
= FLOAT_ADDR(texImage
, i
, j
, k
, 2);
721 dst
[0] = rgba
[RCOMP
];
722 dst
[1] = rgba
[ACOMP
];
727 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
729 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
730 * returning 4 GLfloats.
732 static void FETCH(luminance_alpha_f16
)( const struct gl_texture_image
*texImage
,
733 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
735 const GLhalfARB
*src
= HALF_ADDR( texImage
, i
, j
, k
, 2 );
736 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
738 texel
[BCOMP
] = texel
[RCOMP
];
739 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], _mesa_half_to_float(src
[1]));
742 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
743 * returning 4 GLfloats.
745 static void FETCH(f_luminance_alpha_f16
)( const struct gl_texture_image
*texImage
,
746 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
748 const GLhalfARB
*src
= HALF_ADDR( texImage
, i
, j
, k
, 2 );
751 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
752 texel
[ACOMP
] = _mesa_half_to_float(src
[1]);
756 static void store_texel_luminance_alpha_f16(struct gl_texture_image
*texImage
,
757 GLint i
, GLint j
, GLint k
, const void *texel
)
759 const GLfloat
*rgba
= (const GLfloat
*) texel
;
760 GLhalfARB
*dst
= HALF_ADDR(texImage
, i
, j
, k
, 2);
761 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
762 dst
[1] = _mesa_float_to_half(rgba
[ACOMP
]);
767 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
769 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
770 * returning 4 GLchans.
772 static void FETCH(intensity_f32
)( const struct gl_texture_image
*texImage
,
773 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
775 const GLfloat
*src
= FLOAT_ADDR( texImage
, i
, j
, k
, 1 );
776 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
779 texel
[ACOMP
] = texel
[RCOMP
];
782 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
783 * returning 4 GLfloats.
785 static void FETCH(f_intensity_f32
)( const struct gl_texture_image
*texImage
,
786 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
788 const GLfloat
*src
= FLOAT_ADDR( texImage
, i
, j
, k
, 1 );
792 texel
[ACOMP
] = src
[0];
796 static void store_texel_intensity_f32(struct gl_texture_image
*texImage
,
797 GLint i
, GLint j
, GLint k
, const void *texel
)
799 const GLfloat
*rgba
= (const GLfloat
*) texel
;
800 GLfloat
*dst
= FLOAT_ADDR(texImage
, i
, j
, k
, 1);
801 dst
[0] = rgba
[RCOMP
];
806 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
808 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
809 * returning 4 GLchans.
811 static void FETCH(intensity_f16
)( const struct gl_texture_image
*texImage
,
812 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
814 const GLhalfARB
*src
= HALF_ADDR( texImage
, i
, j
, k
, 1 );
815 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
818 texel
[ACOMP
] = texel
[RCOMP
];
821 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
822 * returning 4 GLfloats.
824 static void FETCH(f_intensity_f16
)( const struct gl_texture_image
*texImage
,
825 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
827 const GLhalfARB
*src
= HALF_ADDR( texImage
, i
, j
, k
, 1 );
831 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
835 static void store_texel_intensity_f16(struct gl_texture_image
*texImage
,
836 GLint i
, GLint j
, GLint k
, const void *texel
)
838 const GLfloat
*rgba
= (const GLfloat
*) texel
;
839 GLhalfARB
*dst
= HALF_ADDR(texImage
, i
, j
, k
, 1);
840 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
848 * Begin Hardware formats
851 /* MESA_FORMAT_RGBA8888 ******************************************************/
853 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
854 static void FETCH(rgba8888
)( const struct gl_texture_image
*texImage
,
855 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
857 const GLuint s
= *UINT_ADDR( texImage
, i
, j
, k
);
858 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
859 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
860 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
861 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
864 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
865 static void FETCH(f_rgba8888
)( const struct gl_texture_image
*texImage
,
866 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
868 const GLuint s
= *UINT_ADDR( texImage
, i
, j
, k
);
869 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
870 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
871 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
872 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
876 static void store_texel_rgba8888(struct gl_texture_image
*texImage
,
877 GLint i
, GLint j
, GLint k
, const void *texel
)
879 const GLubyte
*rgba
= (const GLubyte
*) texel
;
880 GLuint
*dst
= UINT_ADDR(texImage
, i
, j
, k
);
881 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
886 /* MESA_FORMAT_RGBA888_REV ***************************************************/
888 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
889 static void FETCH(rgba8888_rev
)( const struct gl_texture_image
*texImage
,
890 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
892 const GLuint s
= *UINT_ADDR( texImage
, i
, j
, k
);
893 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
894 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
895 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
896 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
899 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLfloats */
900 static void FETCH(f_rgba8888_rev
)( const struct gl_texture_image
*texImage
,
901 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
903 const GLuint s
= *UINT_ADDR( texImage
, i
, j
, k
);
904 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
905 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
906 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
907 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
911 static void store_texel_rgba8888_rev(struct gl_texture_image
*texImage
,
912 GLint i
, GLint j
, GLint k
, const void *texel
)
914 const GLubyte
*rgba
= (const GLubyte
*) texel
;
915 GLuint
*dst
= UINT_ADDR(texImage
, i
, j
, k
);
916 *dst
= PACK_COLOR_8888_REV(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
921 /* MESA_FORMAT_ARGB8888 ******************************************************/
923 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
924 static void FETCH(argb8888
)( const struct gl_texture_image
*texImage
,
925 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
927 const GLuint s
= *UINT_ADDR( texImage
, i
, j
, k
);
928 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
929 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
930 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
931 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
934 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLfloats */
935 static void FETCH(f_argb8888
)( const struct gl_texture_image
*texImage
,
936 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
938 const GLuint s
= *UINT_ADDR( texImage
, i
, j
, k
);
939 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
940 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
941 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
942 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
946 static void store_texel_argb8888(struct gl_texture_image
*texImage
,
947 GLint i
, GLint j
, GLint k
, const void *texel
)
949 const GLubyte
*rgba
= (const GLubyte
*) texel
;
950 GLuint
*dst
= UINT_ADDR(texImage
, i
, j
, k
);
951 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
956 /* MESA_FORMAT_ARGB8888_REV **************************************************/
958 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLchans */
959 static void FETCH(argb8888_rev
)( const struct gl_texture_image
*texImage
,
960 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
962 const GLuint s
= *UINT_ADDR( texImage
, i
, j
, k
);
963 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
964 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
965 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
966 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
969 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
970 static void FETCH(f_argb8888_rev
)( const struct gl_texture_image
*texImage
,
971 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
973 const GLuint s
= *UINT_ADDR( texImage
, i
, j
, k
);
974 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
975 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
976 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
977 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
981 static void store_texel_argb8888_rev(struct gl_texture_image
*texImage
,
982 GLint i
, GLint j
, GLint k
, const void *texel
)
984 const GLubyte
*rgba
= (const GLubyte
*) texel
;
985 GLuint
*dst
= UINT_ADDR(texImage
, i
, j
, k
);
986 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
991 /* MESA_FORMAT_RGB888 ********************************************************/
993 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
994 static void FETCH(rgb888
)( const struct gl_texture_image
*texImage
,
995 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
997 const GLubyte
*src
= UBYTE_ADDR( texImage
, i
, j
, k
, 3 );
998 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
999 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
1000 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
1001 texel
[ACOMP
] = CHAN_MAX
;
1004 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLfloats */
1005 static void FETCH(f_rgb888
)( const struct gl_texture_image
*texImage
,
1006 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1008 const GLubyte
*src
= UBYTE_ADDR( texImage
, i
, j
, k
, 3 );
1009 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
1010 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
1011 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
1012 texel
[ACOMP
] = 1.0F
;
1016 static void store_texel_rgb888(struct gl_texture_image
*texImage
,
1017 GLint i
, GLint j
, GLint k
, const void *texel
)
1019 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1020 GLubyte
*dst
= UBYTE_ADDR(texImage
, i
, j
, k
, 3);
1021 dst
[0] = rgba
[RCOMP
];
1022 dst
[1] = rgba
[GCOMP
];
1023 dst
[2] = rgba
[BCOMP
];
1028 /* MESA_FORMAT_BGR888 ********************************************************/
1030 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
1031 static void FETCH(bgr888
)( const struct gl_texture_image
*texImage
,
1032 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1034 const GLubyte
*src
= UBYTE_ADDR( texImage
, i
, j
, k
, 3 );
1035 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[0] );
1036 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
1037 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[2] );
1038 texel
[ACOMP
] = CHAN_MAX
;
1041 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLfloats */
1042 static void FETCH(f_bgr888
)( const struct gl_texture_image
*texImage
,
1043 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1045 const GLubyte
*src
= UBYTE_ADDR( texImage
, i
, j
, k
, 3 );
1046 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[0] );
1047 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
1048 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[2] );
1049 texel
[ACOMP
] = 1.0F
;
1053 static void store_texel_bgr888(struct gl_texture_image
*texImage
,
1054 GLint i
, GLint j
, GLint k
, const void *texel
)
1056 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1057 GLubyte
*dst
= UBYTE_ADDR(texImage
, i
, j
, k
, 3);
1058 dst
[0] = rgba
[BCOMP
];
1059 dst
[1] = rgba
[GCOMP
];
1060 dst
[2] = rgba
[RCOMP
];
1065 /* MESA_FORMAT_RGB565 ********************************************************/
1067 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
1068 static void FETCH(rgb565
)( const struct gl_texture_image
*texImage
,
1069 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1071 const GLushort
*src
= USHORT_ADDR( texImage
, i
, j
, k
);
1072 const GLushort s
= *src
;
1073 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) * 255 / 0xf8 );
1074 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) * 255 / 0xfc );
1075 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) * 255 / 0xf8 );
1076 texel
[ACOMP
] = CHAN_MAX
;
1079 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
1080 static void FETCH(f_rgb565
)( const struct gl_texture_image
*texImage
,
1081 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1083 const GLushort
*src
= USHORT_ADDR( texImage
, i
, j
, k
);
1084 const GLushort s
= *src
;
1085 texel
[RCOMP
] = ((s
>> 8) & 0xf8) * (1.0F
/ 248.0F
);
1086 texel
[GCOMP
] = ((s
>> 3) & 0xfc) * (1.0F
/ 252.0F
);
1087 texel
[BCOMP
] = ((s
<< 3) & 0xf8) * (1.0F
/ 248.0F
);
1088 texel
[ACOMP
] = 1.0F
;
1092 static void store_texel_rgb565(struct gl_texture_image
*texImage
,
1093 GLint i
, GLint j
, GLint k
, const void *texel
)
1095 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1096 GLushort
*dst
= USHORT_ADDR(texImage
, i
, j
, k
);
1097 *dst
= PACK_COLOR_565(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1102 /* MESA_FORMAT_RGB565_REV ****************************************************/
1104 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
1105 static void FETCH(rgb565_rev
)( const struct gl_texture_image
*texImage
,
1106 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1108 const GLushort
*src
= USHORT_ADDR( texImage
, i
, j
, k
);
1109 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
1110 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) * 255 / 0xf8 );
1111 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) * 255 / 0xfc );
1112 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) * 255 / 0xf8 );
1113 texel
[ACOMP
] = CHAN_MAX
;
1116 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLfloats */
1117 static void FETCH(f_rgb565_rev
)( const struct gl_texture_image
*texImage
,
1118 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1120 const GLushort
*src
= USHORT_ADDR( texImage
, i
, j
, k
);
1121 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
1122 texel
[RCOMP
] = ((s
>> 8) & 0xf8) * (1.0F
/ 248.0F
);
1123 texel
[GCOMP
] = ((s
>> 3) & 0xfc) * (1.0F
/ 252.0F
);
1124 texel
[BCOMP
] = ((s
<< 3) & 0xf8) * (1.0F
/ 248.0F
);
1125 texel
[ACOMP
] = 1.0F
;
1129 static void store_texel_rgb565_rev(struct gl_texture_image
*texImage
,
1130 GLint i
, GLint j
, GLint k
, const void *texel
)
1132 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1133 GLushort
*dst
= USHORT_ADDR(texImage
, i
, j
, k
);
1134 *dst
= PACK_COLOR_565(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
1139 /* MESA_FORMAT_ARGB4444 ******************************************************/
1141 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
1142 static void FETCH(argb4444
)( const struct gl_texture_image
*texImage
,
1143 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1145 const GLushort
*src
= USHORT_ADDR( texImage
, i
, j
, k
);
1146 const GLushort s
= *src
;
1147 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) * 255 / 0xf );
1148 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) * 255 / 0xf );
1149 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) * 255 / 0xf );
1150 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) * 255 / 0xf );
1153 /* Fetch texel from 1D, 2D or 3D argb4444 texture, return 4 GLfloats */
1154 static void FETCH(f_argb4444
)( const struct gl_texture_image
*texImage
,
1155 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1157 const GLushort
*src
= USHORT_ADDR( texImage
, i
, j
, k
);
1158 const GLushort s
= *src
;
1159 texel
[RCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1160 texel
[GCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1161 texel
[BCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
1162 texel
[ACOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
1166 static void store_texel_argb4444(struct gl_texture_image
*texImage
,
1167 GLint i
, GLint j
, GLint k
, const void *texel
)
1169 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1170 GLushort
*dst
= USHORT_ADDR(texImage
, i
, j
, k
);
1171 *dst
= PACK_COLOR_4444(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1176 /* MESA_FORMAT_ARGB4444_REV **************************************************/
1178 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
1179 static void FETCH(argb4444_rev
)( const struct gl_texture_image
*texImage
,
1180 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1182 const GLushort s
= *USHORT_ADDR( texImage
, i
, j
, k
);
1183 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) * 255 / 0xf );
1184 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) * 255 / 0xf );
1185 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) * 255 / 0xf );
1186 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) * 255 / 0xf );
1189 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLfloats */
1190 static void FETCH(f_argb4444_rev
)( const struct gl_texture_image
*texImage
,
1191 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1193 const GLushort s
= *USHORT_ADDR( texImage
, i
, j
, k
);
1194 texel
[RCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
1195 texel
[GCOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
1196 texel
[BCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1197 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1201 static void store_texel_argb4444_rev(struct gl_texture_image
*texImage
,
1202 GLint i
, GLint j
, GLint k
, const void *texel
)
1204 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1205 GLushort
*dst
= USHORT_ADDR(texImage
, i
, j
, k
);
1206 *dst
= PACK_COLOR_4444(rgba
[ACOMP
], rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
1211 /* MESA_FORMAT_ARGB1555 ******************************************************/
1213 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
1214 static void FETCH(argb1555
)( const struct gl_texture_image
*texImage
,
1215 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1217 const GLushort
*src
= USHORT_ADDR( texImage
, i
, j
, k
);
1218 const GLushort s
= *src
;
1219 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 10) & 0x1f) * 255 / 0x1f );
1220 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 5) & 0x1f) * 255 / 0x1f );
1221 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0x1f) * 255 / 0x1f );
1222 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
1225 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLfloats */
1226 static void FETCH(f_argb1555
)( const struct gl_texture_image
*texImage
,
1227 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1229 const GLushort
*src
= USHORT_ADDR( texImage
, i
, j
, k
);
1230 const GLushort s
= *src
;
1231 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
1232 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
1233 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
1234 texel
[ACOMP
] = ((s
>> 15) & 0x01);
1238 static void store_texel_argb1555(struct gl_texture_image
*texImage
,
1239 GLint i
, GLint j
, GLint k
, const void *texel
)
1241 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1242 GLushort
*dst
= USHORT_ADDR(texImage
, i
, j
, k
);
1243 *dst
= PACK_COLOR_1555(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1248 /* MESA_FORMAT_ARGB1555_REV **************************************************/
1250 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
1251 static void FETCH(argb1555_rev
)( const struct gl_texture_image
*texImage
,
1252 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1254 const GLushort
*src
= USHORT_ADDR( texImage
, i
, j
, k
);
1255 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
1256 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 10) & 0x1f) * 255 / 0x1f );
1257 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 5) & 0x1f) * 255 / 0x1f );
1258 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0x1f) * 255 / 0x1f );
1259 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
1262 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLfloats */
1263 static void FETCH(f_argb1555_rev
)( const struct gl_texture_image
*texImage
,
1264 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1266 const GLushort
*src
= USHORT_ADDR( texImage
, i
, j
, k
);
1267 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
1268 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
1269 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
1270 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
1271 texel
[ACOMP
] = ((s
>> 15) & 0x01);
1275 static void store_texel_argb1555_rev(struct gl_texture_image
*texImage
,
1276 GLint i
, GLint j
, GLint k
, const void *texel
)
1278 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1279 GLushort
*dst
= USHORT_ADDR(texImage
, i
, j
, k
);
1280 *dst
= PACK_COLOR_1555_REV(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1285 /* MESA_FORMAT_AL88 **********************************************************/
1287 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
1288 static void FETCH(al88
)( const struct gl_texture_image
*texImage
,
1289 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1291 const GLushort s
= *USHORT_ADDR( texImage
, i
, j
, k
);
1294 texel
[BCOMP
] = UBYTE_TO_CHAN( s
& 0xff );
1295 texel
[ACOMP
] = UBYTE_TO_CHAN( s
>> 8 );
1298 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLfloats */
1299 static void FETCH(f_al88
)( const struct gl_texture_image
*texImage
,
1300 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1302 const GLushort s
= *USHORT_ADDR( texImage
, i
, j
, k
);
1305 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
1306 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
1310 static void store_texel_al88(struct gl_texture_image
*texImage
,
1311 GLint i
, GLint j
, GLint k
, const void *texel
)
1313 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1314 GLushort
*dst
= USHORT_ADDR(texImage
, i
, j
, k
);
1315 *dst
= PACK_COLOR_88(rgba
[ACOMP
], rgba
[RCOMP
]);
1320 /* MESA_FORMAT_AL88_REV ******************************************************/
1322 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
1323 static void FETCH(al88_rev
)( const struct gl_texture_image
*texImage
,
1324 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1326 const GLushort s
= *USHORT_ADDR( texImage
, i
, j
, k
);
1329 texel
[BCOMP
] = UBYTE_TO_CHAN( s
>> 8 );
1330 texel
[ACOMP
] = UBYTE_TO_CHAN( s
& 0xff );
1333 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLfloats */
1334 static void FETCH(f_al88_rev
)( const struct gl_texture_image
*texImage
,
1335 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1337 const GLushort s
= *USHORT_ADDR( texImage
, i
, j
, k
);
1340 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
1341 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
1345 static void store_texel_al88_rev(struct gl_texture_image
*texImage
,
1346 GLint i
, GLint j
, GLint k
, const void *texel
)
1348 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1349 GLushort
*dst
= USHORT_ADDR(texImage
, i
, j
, k
);
1350 *dst
= PACK_COLOR_88(rgba
[RCOMP
], rgba
[ACOMP
]);
1355 /* MESA_FORMAT_RGB332 ********************************************************/
1357 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1358 static void FETCH(rgb332
)( const struct gl_texture_image
*texImage
,
1359 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1361 const GLubyte
*src
= UBYTE_ADDR( texImage
, i
, j
, k
, 1 );
1362 const GLubyte s
= *src
;
1363 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xe0) * 255 / 0xe0 );
1364 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xe0) * 255 / 0xe0 );
1365 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 6) & 0xc0) * 255 / 0xc0 );
1366 texel
[ACOMP
] = CHAN_MAX
;
1369 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLfloats */
1370 static void FETCH(f_rgb332
)( const struct gl_texture_image
*texImage
,
1371 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1373 const GLubyte
*src
= UBYTE_ADDR( texImage
, i
, j
, k
, 1 );
1374 const GLubyte s
= *src
;
1375 texel
[RCOMP
] = ((s
) & 0xe0) * (1.0F
/ 224.0F
);
1376 texel
[GCOMP
] = ((s
<< 3) & 0xe0) * (1.0F
/ 224.0F
);
1377 texel
[BCOMP
] = ((s
<< 6) & 0xc0) * (1.0F
/ 192.0F
);
1378 texel
[ACOMP
] = 1.0F
;
1382 static void store_texel_rgb332(struct gl_texture_image
*texImage
,
1383 GLint i
, GLint j
, GLint k
, const void *texel
)
1385 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1386 GLubyte
*dst
= UBYTE_ADDR(texImage
, i
, j
, k
, 1);
1387 *dst
= PACK_COLOR_332(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1392 /* MESA_FORMAT_A8 ************************************************************/
1394 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1395 static void FETCH(a8
)( const struct gl_texture_image
*texImage
,
1396 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1398 const GLubyte
*src
= UBYTE_ADDR( texImage
, i
, j
, k
, 1 );
1402 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
1405 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLfloats */
1406 static void FETCH(f_a8
)( const struct gl_texture_image
*texImage
,
1407 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1409 const GLubyte
*src
= UBYTE_ADDR( texImage
, i
, j
, k
, 1 );
1413 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1417 static void store_texel_a8(struct gl_texture_image
*texImage
,
1418 GLint i
, GLint j
, GLint k
, const void *texel
)
1420 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1421 GLubyte
*dst
= UBYTE_ADDR(texImage
, i
, j
, k
, 1);
1427 /* MESA_FORMAT_L8 ************************************************************/
1429 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1430 static void FETCH(l8
)( const struct gl_texture_image
*texImage
,
1431 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1433 const GLubyte
*src
= UBYTE_ADDR( texImage
, i
, j
, k
, 1 );
1436 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
1437 texel
[ACOMP
] = CHAN_MAX
;
1440 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLfloats */
1441 static void FETCH(f_l8
)( const struct gl_texture_image
*texImage
,
1442 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1444 const GLubyte
*src
= UBYTE_ADDR( texImage
, i
, j
, k
, 1 );
1447 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
1448 texel
[ACOMP
] = 1.0F
;
1452 static void store_texel_l8(struct gl_texture_image
*texImage
,
1453 GLint i
, GLint j
, GLint k
, const void *texel
)
1455 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1456 GLubyte
*dst
= UBYTE_ADDR(texImage
, i
, j
, k
, 1);
1462 /* MESA_FORMAT_I8 ************************************************************/
1464 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1465 static void FETCH(i8
)( const struct gl_texture_image
*texImage
,
1466 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1468 const GLubyte
*src
= UBYTE_ADDR( texImage
, i
, j
, k
, 1 );
1472 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
1475 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLfloats */
1476 static void FETCH(f_i8
)( const struct gl_texture_image
*texImage
,
1477 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1479 const GLubyte
*src
= UBYTE_ADDR( texImage
, i
, j
, k
, 1 );
1483 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1487 static void store_texel_i8(struct gl_texture_image
*texImage
,
1488 GLint i
, GLint j
, GLint k
, const void *texel
)
1490 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1491 GLubyte
*dst
= UBYTE_ADDR(texImage
, i
, j
, k
, 1);
1497 /* MESA_FORMAT_CI8 ***********************************************************/
1499 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1500 * color table, and return 4 GLchans.
1502 static void FETCH(ci8
)( const struct gl_texture_image
*texImage
,
1503 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1505 const GLubyte
*src
= UBYTE_ADDR( texImage
, i
, j
, k
, 1 );
1506 const struct gl_color_table
*palette
;
1507 const GLchan
*table
;
1509 GET_CURRENT_CONTEXT(ctx
);
1511 if (ctx
->Texture
.SharedPalette
) {
1512 palette
= &ctx
->Texture
.Palette
;
1515 palette
= &texImage
->TexObject
->Palette
;
1517 if (palette
->Size
== 0)
1518 return; /* undefined results */
1519 ASSERT(palette
->Type
!= GL_FLOAT
);
1520 table
= (const GLchan
*) palette
->Table
;
1522 /* Mask the index against size of palette to avoid going out of bounds */
1523 index
= (*src
) & (palette
->Size
- 1);
1525 switch (palette
->Format
) {
1530 texel
[ACOMP
] = table
[index
];
1535 texel
[BCOMP
] = table
[index
];
1536 texel
[ACOMP
] = CHAN_MAX
;
1542 texel
[ACOMP
] = table
[index
];
1544 case GL_LUMINANCE_ALPHA
:
1547 texel
[BCOMP
] = table
[index
* 2 + 0];
1548 texel
[ACOMP
] = table
[index
* 2 + 1];
1551 texel
[RCOMP
] = table
[index
* 3 + 0];
1552 texel
[GCOMP
] = table
[index
* 3 + 1];
1553 texel
[BCOMP
] = table
[index
* 3 + 2];
1554 texel
[ACOMP
] = CHAN_MAX
;
1557 texel
[RCOMP
] = table
[index
* 4 + 0];
1558 texel
[GCOMP
] = table
[index
* 4 + 1];
1559 texel
[BCOMP
] = table
[index
* 4 + 2];
1560 texel
[ACOMP
] = table
[index
* 4 + 3];
1563 _mesa_problem(ctx
, "Bad palette format in palette_sample");
1568 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1569 * color table, and return 4 GLfloats.
1571 static void FETCH(f_ci8
)( const struct gl_texture_image
*texImage
,
1572 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1575 /* Sample as GLchan */
1576 FETCH(ci8
)(texImage
, i
, j
, k
, rgba
);
1577 /* and return as floats */
1578 texel
[RCOMP
] = CHAN_TO_FLOAT(rgba
[RCOMP
]);
1579 texel
[GCOMP
] = CHAN_TO_FLOAT(rgba
[GCOMP
]);
1580 texel
[BCOMP
] = CHAN_TO_FLOAT(rgba
[BCOMP
]);
1581 texel
[ACOMP
] = CHAN_TO_FLOAT(rgba
[ACOMP
]);
1585 static void store_texel_ci8(struct gl_texture_image
*texImage
,
1586 GLint i
, GLint j
, GLint k
, const void *texel
)
1588 const GLubyte
*index
= (const GLubyte
*) texel
;
1589 GLubyte
*dst
= UBYTE_ADDR(texImage
, i
, j
, k
, 1);
1595 /* MESA_FORMAT_YCBCR *********************************************************/
1597 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
1598 /* We convert YCbCr to RGB here */
1599 /* XXX this may break if GLchan != GLubyte */
1600 static void FETCH(ycbcr
)( const struct gl_texture_image
*texImage
,
1601 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1603 const GLushort
*src0
= USHORT_ADDR( texImage
, (i
& ~1), j
, k
); /* even */
1604 const GLushort
*src1
= src0
+ 1; /* odd */
1605 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1606 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1607 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1608 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1611 /* odd pixel: use y1,cr,cb */
1612 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
1613 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1614 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
1617 /* even pixel: use y0,cr,cb */
1618 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
1619 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1620 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
1622 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
1623 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
1624 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
1625 texel
[ACOMP
] = CHAN_MAX
;
1628 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats */
1629 /* We convert YCbCr to RGB here */
1630 static void FETCH(f_ycbcr
)( const struct gl_texture_image
*texImage
,
1631 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1633 const GLushort
*src0
= USHORT_ADDR( texImage
, (i
& ~1), j
, k
); /* even */
1634 const GLushort
*src1
= src0
+ 1; /* odd */
1635 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1636 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1637 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1638 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1641 /* odd pixel: use y1,cr,cb */
1642 r
= (1.164 * (y1
-16) + 1.596 * (cr
-128));
1643 g
= (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1644 b
= (1.164 * (y1
-16) + 2.018 * (cb
-128));
1647 /* even pixel: use y0,cr,cb */
1648 r
= (1.164 * (y0
-16) + 1.596 * (cr
-128));
1649 g
= (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1650 b
= (1.164 * (y0
-16) + 2.018 * (cb
-128));
1652 /* XXX remove / 255 here by tweaking arithmetic above */
1656 /* XXX should we really clamp??? */
1657 texel
[RCOMP
] = CLAMP(r
, 0.0, 1.0);
1658 texel
[GCOMP
] = CLAMP(g
, 0.0, 1.0);
1659 texel
[BCOMP
] = CLAMP(b
, 0.0, 1.0);
1660 texel
[ACOMP
] = 1.0F
;
1664 static void store_texel_ycbcr(struct gl_texture_image
*texImage
,
1665 GLint i
, GLint j
, GLint k
, const void *texel
)
1672 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1674 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
1675 /* We convert YCbCr to RGB here */
1676 /* XXX this may break if GLchan != GLubyte */
1677 static void FETCH(ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1678 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1680 const GLushort
*src0
= USHORT_ADDR( texImage
, (i
& ~1), j
, k
); /* even */
1681 const GLushort
*src1
= src0
+ 1; /* odd */
1682 const GLubyte y0
= *src0
& 0xff; /* luminance */
1683 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1684 const GLubyte y1
= *src1
& 0xff; /* luminance */
1685 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1688 /* odd pixel: use y1,cr,cb */
1689 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
1690 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1691 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
1694 /* even pixel: use y0,cr,cb */
1695 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
1696 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1697 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
1699 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
1700 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
1701 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
1702 texel
[ACOMP
] = CHAN_MAX
;
1705 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats */
1706 /* We convert YCbCr to RGB here */
1707 static void FETCH(f_ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1708 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1710 const GLushort
*src0
= USHORT_ADDR( texImage
, (i
& ~1), j
, k
); /* even */
1711 const GLushort
*src1
= src0
+ 1; /* odd */
1712 const GLubyte y0
= *src0
& 0xff; /* luminance */
1713 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1714 const GLubyte y1
= *src1
& 0xff; /* luminance */
1715 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1718 /* odd pixel: use y1,cr,cb */
1719 r
= (1.164 * (y1
-16) + 1.596 * (cr
-128));
1720 g
= (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1721 b
= (1.164 * (y1
-16) + 2.018 * (cb
-128));
1724 /* even pixel: use y0,cr,cb */
1725 r
= (1.164 * (y0
-16) + 1.596 * (cr
-128));
1726 g
= (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1727 b
= (1.164 * (y0
-16) + 2.018 * (cb
-128));
1729 /* XXX remove / 255 here by tweaking arithmetic above */
1733 /* XXX should we really clamp??? */
1734 texel
[RCOMP
] = CLAMP(r
, 0.0, 1.0);
1735 texel
[GCOMP
] = CLAMP(g
, 0.0, 1.0);
1736 texel
[BCOMP
] = CLAMP(b
, 0.0, 1.0);
1737 texel
[ACOMP
] = 1.0F
;
1741 static void store_texel_ycbcr_rev(struct gl_texture_image
*texImage
,
1742 GLint i
, GLint j
, GLint k
, const void *texel
)