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 TEXEL_ADDR( type, image, i, j, k, size ) \
47 ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
49 #define FETCH(x) fetch_texel_1d_##x
53 #define TEXEL_ADDR( type, image, i, j, k, size ) \
55 ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
57 #define FETCH(x) fetch_texel_2d_##x
61 #define TEXEL_ADDR( type, image, i, j, k, size ) \
62 ((type *)(image)->Data + (((image)->Height * (k) + (j)) * \
63 (image)->RowStride + (i)) * (size))
65 #define FETCH(x) fetch_texel_3d_##x
68 #error illegal number of texture dimensions
72 /* MESA_FORMAT_RGBA **********************************************************/
74 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLchans */
75 static void FETCH(rgba
)( const struct gl_texture_image
*texImage
,
76 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
78 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 4);
79 COPY_CHAN4( texel
, src
);
82 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
83 static void FETCH(f_rgba
)( const struct gl_texture_image
*texImage
,
84 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
86 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 4);
87 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
88 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
89 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
90 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[3]);
94 /* Store a GLchan RGBA texel */
95 static void store_texel_rgba(struct gl_texture_image
*texImage
,
96 GLint i
, GLint j
, GLint k
, const void *texel
)
98 const GLchan
*rgba
= (const GLchan
*) texel
;
99 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 4);
100 dst
[0] = rgba
[RCOMP
];
101 dst
[1] = rgba
[GCOMP
];
102 dst
[2] = rgba
[BCOMP
];
103 dst
[3] = rgba
[ACOMP
];
107 /* MESA_FORMAT_RGB ***********************************************************/
109 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLchans */
110 static void FETCH(rgb
)( const struct gl_texture_image
*texImage
,
111 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
113 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 3);
114 texel
[RCOMP
] = src
[0];
115 texel
[GCOMP
] = src
[1];
116 texel
[BCOMP
] = src
[2];
117 texel
[ACOMP
] = CHAN_MAX
;
120 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
121 static void FETCH(f_rgb
)( const struct gl_texture_image
*texImage
,
122 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
124 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 3);
125 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
126 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
127 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
132 static void store_texel_rgb(struct gl_texture_image
*texImage
,
133 GLint i
, GLint j
, GLint k
, const void *texel
)
135 const GLchan
*rgba
= (const GLchan
*) texel
;
136 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 3);
137 dst
[0] = rgba
[RCOMP
];
138 dst
[1] = rgba
[GCOMP
];
139 dst
[2] = rgba
[BCOMP
];
143 /* MESA_FORMAT_ALPHA *********************************************************/
145 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
146 static void FETCH(alpha
)( const struct gl_texture_image
*texImage
,
147 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
149 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
153 texel
[ACOMP
] = src
[0];
156 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLfloats */
157 static void FETCH(f_alpha
)( const struct gl_texture_image
*texImage
,
158 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
160 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
164 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[0]);
168 static void store_texel_alpha(struct gl_texture_image
*texImage
,
169 GLint i
, GLint j
, GLint k
, const void *texel
)
171 const GLchan
*rgba
= (const GLchan
*) texel
;
172 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
173 dst
[0] = rgba
[ACOMP
];
177 /* MESA_FORMAT_LUMINANCE *****************************************************/
179 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
180 static void FETCH(luminance
)( const struct gl_texture_image
*texImage
,
181 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
183 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
186 texel
[BCOMP
] = src
[0];
187 texel
[ACOMP
] = CHAN_MAX
;
190 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLfloats */
191 static void FETCH(f_luminance
)( const struct gl_texture_image
*texImage
,
192 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
194 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
197 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[0]);
202 static void store_texel_luminance(struct gl_texture_image
*texImage
,
203 GLint i
, GLint j
, GLint k
, const void *texel
)
205 const GLchan
*rgba
= (const GLchan
*) texel
;
206 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
207 dst
[0] = rgba
[RCOMP
];
211 /* MESA_FORMAT_LUMINANCE_ALPHA ***********************************************/
213 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
214 static void FETCH(luminance_alpha
)( const struct gl_texture_image
*texImage
,
215 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
217 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 2);
218 texel
[RCOMP
] = src
[0];
219 texel
[GCOMP
] = src
[0];
220 texel
[BCOMP
] = src
[0];
221 texel
[ACOMP
] = src
[1];
224 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLfloats */
225 static void FETCH(f_luminance_alpha
)( const struct gl_texture_image
*texImage
,
226 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
228 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 2);
231 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[0]);
232 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[1]);
236 static void store_texel_luminance_alpha(struct gl_texture_image
*texImage
,
237 GLint i
, GLint j
, GLint k
, const void *texel
)
239 const GLchan
*rgba
= (const GLchan
*) texel
;
240 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 2);
241 dst
[0] = rgba
[RCOMP
];
242 dst
[1] = rgba
[ACOMP
];
246 /* MESA_FORMAT_INTENSITY *****************************************************/
248 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
249 static void FETCH(intensity
)( const struct gl_texture_image
*texImage
,
250 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
252 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
253 texel
[RCOMP
] = src
[0];
254 texel
[GCOMP
] = src
[0];
255 texel
[BCOMP
] = src
[0];
256 texel
[ACOMP
] = src
[0];
259 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLfloats */
260 static void FETCH(f_intensity
)( const struct gl_texture_image
*texImage
,
261 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
263 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
267 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[0]);
271 static void store_texel_intensity(struct gl_texture_image
*texImage
,
272 GLint i
, GLint j
, GLint k
, const void *texel
)
274 const GLchan
*rgba
= (const GLchan
*) texel
;
275 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
276 dst
[0] = rgba
[RCOMP
];
281 /* MESA_FORMAT_DEPTH_COMPONENT_F32 *******************************************/
283 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
284 * returning 1 GLfloat.
285 * Note: no GLchan version of this function.
287 static void FETCH(f_depth_component_f32
)( const struct gl_texture_image
*texImage
,
288 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
290 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
295 static void store_texel_depth_component_f32(struct gl_texture_image
*texImage
,
296 GLint i
, GLint j
, GLint k
, const void *texel
)
298 const GLfloat
*depth
= (const GLfloat
*) texel
;
299 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
305 /* MESA_FORMAT_DEPTH_COMPONENT16 *********************************************/
307 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
308 * returning 1 GLfloat.
309 * Note: no GLchan version of this function.
311 static void FETCH(f_depth_component16
)(const struct gl_texture_image
*texImage
,
312 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
314 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
315 texel
[0] = src
[0] * (1.0F
/ 65535.0F
);
319 static void store_texel_depth_component16(struct gl_texture_image
*texImage
,
320 GLint i
, GLint j
, GLint k
, const void *texel
)
322 const GLushort
*depth
= (const GLushort
*) texel
;
323 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
329 /* MESA_FORMAT_RGBA_F32 ******************************************************/
331 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLchans.
333 static void FETCH(rgba_f32
)( const struct gl_texture_image
*texImage
,
334 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
336 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 4);
337 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
338 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], src
[1]);
339 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], src
[2]);
340 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], src
[3]);
343 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
345 static void FETCH(f_rgba_f32
)( const struct gl_texture_image
*texImage
,
346 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
348 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 4);
349 texel
[RCOMP
] = src
[0];
350 texel
[GCOMP
] = src
[1];
351 texel
[BCOMP
] = src
[2];
352 texel
[ACOMP
] = src
[3];
356 static void store_texel_rgba_f32(struct gl_texture_image
*texImage
,
357 GLint i
, GLint j
, GLint k
, const void *texel
)
359 const GLfloat
*depth
= (const GLfloat
*) texel
;
360 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
361 dst
[0] = depth
[RCOMP
];
362 dst
[1] = depth
[GCOMP
];
363 dst
[2] = depth
[BCOMP
];
364 dst
[3] = depth
[ACOMP
];
369 /* MESA_FORMAT_RGBA_F16 ******************************************************/
371 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
372 * returning 4 GLchans.
374 static void FETCH(rgba_f16
)( const struct gl_texture_image
*texImage
,
375 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
377 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 4);
378 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
379 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], _mesa_half_to_float(src
[1]));
380 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], _mesa_half_to_float(src
[2]));
381 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], _mesa_half_to_float(src
[3]));
384 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
385 * returning 4 GLfloats.
387 static void FETCH(f_rgba_f16
)( const struct gl_texture_image
*texImage
,
388 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
390 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 4);
391 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
392 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
393 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
394 texel
[ACOMP
] = _mesa_half_to_float(src
[3]);
398 static void store_texel_rgba_f16(struct gl_texture_image
*texImage
,
399 GLint i
, GLint j
, GLint k
, const void *texel
)
401 const GLfloat
*depth
= (const GLfloat
*) texel
;
402 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
403 dst
[0] = _mesa_float_to_half(*depth
);
407 /* MESA_FORMAT_RGB_F32 *******************************************************/
409 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
410 * returning 4 GLchans.
412 static void FETCH(rgb_f32
)( const struct gl_texture_image
*texImage
,
413 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
415 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 3);
416 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
417 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], src
[1]);
418 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], src
[2]);
419 texel
[ACOMP
] = CHAN_MAX
;
422 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
423 * returning 4 GLfloats.
425 static void FETCH(f_rgb_f32
)( const struct gl_texture_image
*texImage
,
426 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
428 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 3);
429 texel
[RCOMP
] = src
[0];
430 texel
[GCOMP
] = src
[1];
431 texel
[BCOMP
] = src
[2];
436 static void store_texel_rgb_f32(struct gl_texture_image
*texImage
,
437 GLint i
, GLint j
, GLint k
, const void *texel
)
439 const GLfloat
*depth
= (const GLfloat
*) texel
;
440 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
446 /* MESA_FORAMT_RGB_F16 *******************************************************/
448 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
449 * returning 4 GLchans.
451 static void FETCH(rgb_f16
)( const struct gl_texture_image
*texImage
,
452 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
454 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 3);
455 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
456 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], _mesa_half_to_float(src
[1]));
457 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], _mesa_half_to_float(src
[2]));
458 texel
[ACOMP
] = CHAN_MAX
;
461 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
462 * returning 4 GLfloats.
464 static void FETCH(f_rgb_f16
)( const struct gl_texture_image
*texImage
,
465 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
467 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 3);
468 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
469 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
470 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
475 static void store_texel_rgb_f16(struct gl_texture_image
*texImage
,
476 GLint i
, GLint j
, GLint k
, const void *texel
)
478 const GLfloat
*depth
= (const GLfloat
*) texel
;
479 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
480 dst
[0] = _mesa_float_to_half(*depth
);
485 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
487 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
488 * returning 4 GLchans.
490 static void FETCH(alpha_f32
)( const struct gl_texture_image
*texImage
,
491 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
493 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
497 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], src
[0]);
500 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
501 * returning 4 GLfloats.
503 static void FETCH(f_alpha_f32
)( const struct gl_texture_image
*texImage
,
504 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
506 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
510 texel
[ACOMP
] = src
[0];
514 static void store_texel_alpha_f32(struct gl_texture_image
*texImage
,
515 GLint i
, GLint j
, GLint k
, const void *texel
)
517 const GLfloat
*rgba
= (const GLfloat
*) texel
;
518 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
519 dst
[0] = rgba
[ACOMP
];
524 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
526 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
527 * returning 4 GLchans.
529 static void FETCH(alpha_f16
)( const struct gl_texture_image
*texImage
,
530 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
532 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
536 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], _mesa_half_to_float(src
[0]));
539 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
540 * returning 4 GLfloats.
542 static void FETCH(f_alpha_f16
)( const struct gl_texture_image
*texImage
,
543 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
545 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
549 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
553 static void store_texel_alpha_f16(struct gl_texture_image
*texImage
,
554 GLint i
, GLint j
, GLint k
, const void *texel
)
556 const GLfloat
*rgba
= (const GLfloat
*) texel
;
557 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
558 dst
[0] = _mesa_float_to_half(rgba
[ACOMP
]);
563 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
565 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
566 * returning 4 GLchans.
568 static void FETCH(luminance_f32
)( const struct gl_texture_image
*texImage
,
569 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
571 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
572 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
574 texel
[BCOMP
] = texel
[RCOMP
];
575 texel
[ACOMP
] = CHAN_MAX
;
578 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
579 * returning 4 GLfloats.
581 static void FETCH(f_luminance_f32
)( const struct gl_texture_image
*texImage
,
582 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
584 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
587 texel
[BCOMP
] = src
[0];
592 static void store_texel_luminance_f32(struct gl_texture_image
*texImage
,
593 GLint i
, GLint j
, GLint k
, const void *texel
)
595 const GLfloat
*rgba
= (const GLfloat
*) texel
;
596 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
597 dst
[0] = rgba
[RCOMP
];
602 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
604 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
605 * returning 4 GLchans.
607 static void FETCH(luminance_f16
)( const struct gl_texture_image
*texImage
,
608 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
610 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
611 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
613 texel
[BCOMP
] = texel
[RCOMP
];
614 texel
[ACOMP
] = CHAN_MAX
;
617 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
618 * returning 4 GLfloats.
620 static void FETCH(f_luminance_f16
)( const struct gl_texture_image
*texImage
,
621 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
623 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
626 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
631 static void store_texel_luminance_f16(struct gl_texture_image
*texImage
,
632 GLint i
, GLint j
, GLint k
, const void *texel
)
634 const GLfloat
*rgba
= (const GLfloat
*) texel
;
635 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
636 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
641 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
643 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
644 * returning 4 GLchans.
646 static void FETCH(luminance_alpha_f32
)( const struct gl_texture_image
*texImage
,
647 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
649 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
650 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
652 texel
[BCOMP
] = texel
[RCOMP
];
653 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], src
[1]);
656 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
657 * returning 4 GLfloats.
659 static void FETCH(f_luminance_alpha_f32
)( const struct gl_texture_image
*texImage
,
660 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
662 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
665 texel
[BCOMP
] = src
[0];
666 texel
[ACOMP
] = src
[1];
670 static void store_texel_luminance_alpha_f32(struct gl_texture_image
*texImage
,
671 GLint i
, GLint j
, GLint k
, const void *texel
)
673 const GLfloat
*rgba
= (const GLfloat
*) texel
;
674 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
675 dst
[0] = rgba
[RCOMP
];
676 dst
[1] = rgba
[ACOMP
];
681 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
683 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
684 * returning 4 GLfloats.
686 static void FETCH(luminance_alpha_f16
)( const struct gl_texture_image
*texImage
,
687 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
689 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
690 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
692 texel
[BCOMP
] = texel
[RCOMP
];
693 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], _mesa_half_to_float(src
[1]));
696 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
697 * returning 4 GLfloats.
699 static void FETCH(f_luminance_alpha_f16
)( const struct gl_texture_image
*texImage
,
700 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
702 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
705 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
706 texel
[ACOMP
] = _mesa_half_to_float(src
[1]);
710 static void store_texel_luminance_alpha_f16(struct gl_texture_image
*texImage
,
711 GLint i
, GLint j
, GLint k
, const void *texel
)
713 const GLfloat
*rgba
= (const GLfloat
*) texel
;
714 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
715 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
716 dst
[1] = _mesa_float_to_half(rgba
[ACOMP
]);
721 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
723 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
724 * returning 4 GLchans.
726 static void FETCH(intensity_f32
)( const struct gl_texture_image
*texImage
,
727 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
729 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
730 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
733 texel
[ACOMP
] = texel
[RCOMP
];
736 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
737 * returning 4 GLfloats.
739 static void FETCH(f_intensity_f32
)( const struct gl_texture_image
*texImage
,
740 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
742 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
746 texel
[ACOMP
] = src
[0];
750 static void store_texel_intensity_f32(struct gl_texture_image
*texImage
,
751 GLint i
, GLint j
, GLint k
, const void *texel
)
753 const GLfloat
*rgba
= (const GLfloat
*) texel
;
754 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
755 dst
[0] = rgba
[RCOMP
];
760 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
762 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
763 * returning 4 GLchans.
765 static void FETCH(intensity_f16
)( const struct gl_texture_image
*texImage
,
766 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
768 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
769 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
772 texel
[ACOMP
] = texel
[RCOMP
];
775 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
776 * returning 4 GLfloats.
778 static void FETCH(f_intensity_f16
)( const struct gl_texture_image
*texImage
,
779 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
781 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
785 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
789 static void store_texel_intensity_f16(struct gl_texture_image
*texImage
,
790 GLint i
, GLint j
, GLint k
, const void *texel
)
792 const GLfloat
*rgba
= (const GLfloat
*) texel
;
793 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
794 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
802 * Begin Hardware formats
805 /* MESA_FORMAT_RGBA8888 ******************************************************/
807 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
808 static void FETCH(rgba8888
)( const struct gl_texture_image
*texImage
,
809 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
811 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
812 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
813 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
814 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
815 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
818 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
819 static void FETCH(f_rgba8888
)( const struct gl_texture_image
*texImage
,
820 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
822 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
823 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
824 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
825 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
826 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
830 static void store_texel_rgba8888(struct gl_texture_image
*texImage
,
831 GLint i
, GLint j
, GLint k
, const void *texel
)
833 const GLubyte
*rgba
= (const GLubyte
*) texel
;
834 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
835 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
840 /* MESA_FORMAT_RGBA888_REV ***************************************************/
842 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
843 static void FETCH(rgba8888_rev
)( const struct gl_texture_image
*texImage
,
844 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
846 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
847 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
848 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
849 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
850 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
853 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLfloats */
854 static void FETCH(f_rgba8888_rev
)( const struct gl_texture_image
*texImage
,
855 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
857 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
858 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
859 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
860 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
861 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
865 static void store_texel_rgba8888_rev(struct gl_texture_image
*texImage
,
866 GLint i
, GLint j
, GLint k
, const void *texel
)
868 const GLubyte
*rgba
= (const GLubyte
*) texel
;
869 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
870 *dst
= PACK_COLOR_8888_REV(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
875 /* MESA_FORMAT_ARGB8888 ******************************************************/
877 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
878 static void FETCH(argb8888
)( const struct gl_texture_image
*texImage
,
879 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
881 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
882 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
883 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
884 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
885 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
888 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLfloats */
889 static void FETCH(f_argb8888
)( const struct gl_texture_image
*texImage
,
890 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
892 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
893 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
894 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
895 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
896 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
900 static void store_texel_argb8888(struct gl_texture_image
*texImage
,
901 GLint i
, GLint j
, GLint k
, const void *texel
)
903 const GLubyte
*rgba
= (const GLubyte
*) texel
;
904 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
905 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
910 /* MESA_FORMAT_ARGB8888_REV **************************************************/
912 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLchans */
913 static void FETCH(argb8888_rev
)( const struct gl_texture_image
*texImage
,
914 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
916 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
917 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
918 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
919 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
920 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
923 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
924 static void FETCH(f_argb8888_rev
)( const struct gl_texture_image
*texImage
,
925 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
927 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
928 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
929 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
930 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
931 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
935 static void store_texel_argb8888_rev(struct gl_texture_image
*texImage
,
936 GLint i
, GLint j
, GLint k
, const void *texel
)
938 const GLubyte
*rgba
= (const GLubyte
*) texel
;
939 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
940 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
945 /* MESA_FORMAT_RGB888 ********************************************************/
947 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
948 static void FETCH(rgb888
)( const struct gl_texture_image
*texImage
,
949 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
951 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
952 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
953 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
954 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
955 texel
[ACOMP
] = CHAN_MAX
;
958 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLfloats */
959 static void FETCH(f_rgb888
)( const struct gl_texture_image
*texImage
,
960 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
962 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
963 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
964 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
965 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
970 static void store_texel_rgb888(struct gl_texture_image
*texImage
,
971 GLint i
, GLint j
, GLint k
, const void *texel
)
973 const GLubyte
*rgba
= (const GLubyte
*) texel
;
974 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
975 dst
[0] = rgba
[RCOMP
];
976 dst
[1] = rgba
[GCOMP
];
977 dst
[2] = rgba
[BCOMP
];
982 /* MESA_FORMAT_BGR888 ********************************************************/
984 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
985 static void FETCH(bgr888
)( const struct gl_texture_image
*texImage
,
986 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
988 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
989 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[0] );
990 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
991 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[2] );
992 texel
[ACOMP
] = CHAN_MAX
;
995 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLfloats */
996 static void FETCH(f_bgr888
)( const struct gl_texture_image
*texImage
,
997 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
999 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1000 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[0] );
1001 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
1002 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[2] );
1003 texel
[ACOMP
] = 1.0F
;
1007 static void store_texel_bgr888(struct gl_texture_image
*texImage
,
1008 GLint i
, GLint j
, GLint k
, const void *texel
)
1010 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1011 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1012 dst
[0] = rgba
[BCOMP
];
1013 dst
[1] = rgba
[GCOMP
];
1014 dst
[2] = rgba
[RCOMP
];
1019 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
1020 instead of slow (g << 2) * 255 / 252 (always rounds down) */
1022 /* MESA_FORMAT_RGB565 ********************************************************/
1024 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
1025 static void FETCH(rgb565
)( const struct gl_texture_image
*texImage
,
1026 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1028 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1029 const GLushort s
= *src
;
1030 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
1031 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
1032 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
1033 texel
[ACOMP
] = CHAN_MAX
;
1036 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
1037 static void FETCH(f_rgb565
)( const struct gl_texture_image
*texImage
,
1038 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1040 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1041 const GLushort s
= *src
;
1042 texel
[RCOMP
] = ((s
>> 8) & 0xf8) * (1.0F
/ 248.0F
);
1043 texel
[GCOMP
] = ((s
>> 3) & 0xfc) * (1.0F
/ 252.0F
);
1044 texel
[BCOMP
] = ((s
<< 3) & 0xf8) * (1.0F
/ 248.0F
);
1045 texel
[ACOMP
] = 1.0F
;
1049 static void store_texel_rgb565(struct gl_texture_image
*texImage
,
1050 GLint i
, GLint j
, GLint k
, const void *texel
)
1052 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1053 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1054 *dst
= PACK_COLOR_565(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1059 /* MESA_FORMAT_RGB565_REV ****************************************************/
1061 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
1062 static void FETCH(rgb565_rev
)( const struct gl_texture_image
*texImage
,
1063 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1065 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1066 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
1067 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
1068 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
1069 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
1070 texel
[ACOMP
] = CHAN_MAX
;
1073 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLfloats */
1074 static void FETCH(f_rgb565_rev
)( const struct gl_texture_image
*texImage
,
1075 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1077 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1078 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
1079 texel
[RCOMP
] = ((s
>> 8) & 0xf8) * (1.0F
/ 248.0F
);
1080 texel
[GCOMP
] = ((s
>> 3) & 0xfc) * (1.0F
/ 252.0F
);
1081 texel
[BCOMP
] = ((s
<< 3) & 0xf8) * (1.0F
/ 248.0F
);
1082 texel
[ACOMP
] = 1.0F
;
1086 static void store_texel_rgb565_rev(struct gl_texture_image
*texImage
,
1087 GLint i
, GLint j
, GLint k
, const void *texel
)
1089 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1090 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1091 *dst
= PACK_COLOR_565(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
1096 /* MESA_FORMAT_ARGB4444 ******************************************************/
1098 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
1099 static void FETCH(argb4444
)( const struct gl_texture_image
*texImage
,
1100 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1102 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1103 const GLushort s
= *src
;
1104 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) | ((s
>> 4) & 0xf0) );
1105 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) | ((s
) & 0xf0) );
1106 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) | ((s
<< 4) & 0xf0) );
1107 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) | ((s
>> 8) & 0xf0) );
1110 /* Fetch texel from 1D, 2D or 3D argb4444 texture, return 4 GLfloats */
1111 static void FETCH(f_argb4444
)( const struct gl_texture_image
*texImage
,
1112 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1114 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1115 const GLushort s
= *src
;
1116 texel
[RCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1117 texel
[GCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1118 texel
[BCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
1119 texel
[ACOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
1123 static void store_texel_argb4444(struct gl_texture_image
*texImage
,
1124 GLint i
, GLint j
, GLint k
, const void *texel
)
1126 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1127 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1128 *dst
= PACK_COLOR_4444(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1133 /* MESA_FORMAT_ARGB4444_REV **************************************************/
1135 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
1136 static void FETCH(argb4444_rev
)( const struct gl_texture_image
*texImage
,
1137 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1139 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1140 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) | ((s
<< 4) & 0xf0) );
1141 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) | ((s
>> 8) & 0xf0) );
1142 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) | ((s
>> 4) & 0xf0) );
1143 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) | ((s
) & 0xf0) );
1146 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLfloats */
1147 static void FETCH(f_argb4444_rev
)( const struct gl_texture_image
*texImage
,
1148 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1150 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1151 texel
[RCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
1152 texel
[GCOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
1153 texel
[BCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
1154 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
1158 static void store_texel_argb4444_rev(struct gl_texture_image
*texImage
,
1159 GLint i
, GLint j
, GLint k
, const void *texel
)
1161 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1162 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1163 *dst
= PACK_COLOR_4444(rgba
[ACOMP
], rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
1168 /* MESA_FORMAT_ARGB1555 ******************************************************/
1170 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
1171 static void FETCH(argb1555
)( const struct gl_texture_image
*texImage
,
1172 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1174 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1175 const GLushort s
= *src
;
1176 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
1177 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
1178 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
1179 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
1182 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLfloats */
1183 static void FETCH(f_argb1555
)( const struct gl_texture_image
*texImage
,
1184 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1186 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1187 const GLushort s
= *src
;
1188 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
1189 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
1190 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
1191 texel
[ACOMP
] = ((s
>> 15) & 0x01);
1195 static void store_texel_argb1555(struct gl_texture_image
*texImage
,
1196 GLint i
, GLint j
, GLint k
, const void *texel
)
1198 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1199 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1200 *dst
= PACK_COLOR_1555(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1205 /* MESA_FORMAT_ARGB1555_REV **************************************************/
1207 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
1208 static void FETCH(argb1555_rev
)( const struct gl_texture_image
*texImage
,
1209 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1211 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1212 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
1213 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
1214 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
1215 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
1216 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
1219 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLfloats */
1220 static void FETCH(f_argb1555_rev
)( const struct gl_texture_image
*texImage
,
1221 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1223 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1224 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
1225 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
1226 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
1227 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
1228 texel
[ACOMP
] = ((s
>> 15) & 0x01);
1232 static void store_texel_argb1555_rev(struct gl_texture_image
*texImage
,
1233 GLint i
, GLint j
, GLint k
, const void *texel
)
1235 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1236 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1237 *dst
= PACK_COLOR_1555_REV(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1242 /* MESA_FORMAT_AL88 **********************************************************/
1244 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
1245 static void FETCH(al88
)( const struct gl_texture_image
*texImage
,
1246 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1248 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1251 texel
[BCOMP
] = UBYTE_TO_CHAN( s
& 0xff );
1252 texel
[ACOMP
] = UBYTE_TO_CHAN( s
>> 8 );
1255 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLfloats */
1256 static void FETCH(f_al88
)( const struct gl_texture_image
*texImage
,
1257 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1259 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1262 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
1263 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
1267 static void store_texel_al88(struct gl_texture_image
*texImage
,
1268 GLint i
, GLint j
, GLint k
, const void *texel
)
1270 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1271 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1272 *dst
= PACK_COLOR_88(rgba
[ACOMP
], rgba
[RCOMP
]);
1277 /* MESA_FORMAT_AL88_REV ******************************************************/
1279 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
1280 static void FETCH(al88_rev
)( const struct gl_texture_image
*texImage
,
1281 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1283 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1286 texel
[BCOMP
] = UBYTE_TO_CHAN( s
>> 8 );
1287 texel
[ACOMP
] = UBYTE_TO_CHAN( s
& 0xff );
1290 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLfloats */
1291 static void FETCH(f_al88_rev
)( const struct gl_texture_image
*texImage
,
1292 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1294 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1297 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
1298 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
1302 static void store_texel_al88_rev(struct gl_texture_image
*texImage
,
1303 GLint i
, GLint j
, GLint k
, const void *texel
)
1305 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1306 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
1307 *dst
= PACK_COLOR_88(rgba
[RCOMP
], rgba
[ACOMP
]);
1312 /* MESA_FORMAT_RGB332 ********************************************************/
1314 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1315 static void FETCH(rgb332
)( const struct gl_texture_image
*texImage
,
1316 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1318 static const GLubyte lut2to8
[4] = {0, 85, 170, 255};
1319 static const GLubyte lut3to8
[8] = {0, 36, 73, 109, 146, 182, 219, 255};
1320 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1321 const GLubyte s
= *src
;
1322 texel
[RCOMP
] = UBYTE_TO_CHAN( lut3to8
[(s
>> 5) & 0x7] );
1323 texel
[GCOMP
] = UBYTE_TO_CHAN( lut3to8
[(s
>> 2) & 0x7] );
1324 texel
[BCOMP
] = UBYTE_TO_CHAN( lut2to8
[(s
) & 0x3] );
1325 texel
[ACOMP
] = CHAN_MAX
;
1328 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLfloats */
1329 static void FETCH(f_rgb332
)( const struct gl_texture_image
*texImage
,
1330 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1332 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1333 const GLubyte s
= *src
;
1334 texel
[RCOMP
] = ((s
) & 0xe0) * (1.0F
/ 224.0F
);
1335 texel
[GCOMP
] = ((s
<< 3) & 0xe0) * (1.0F
/ 224.0F
);
1336 texel
[BCOMP
] = ((s
<< 6) & 0xc0) * (1.0F
/ 192.0F
);
1337 texel
[ACOMP
] = 1.0F
;
1341 static void store_texel_rgb332(struct gl_texture_image
*texImage
,
1342 GLint i
, GLint j
, GLint k
, const void *texel
)
1344 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1345 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1346 *dst
= PACK_COLOR_332(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1351 /* MESA_FORMAT_A8 ************************************************************/
1353 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1354 static void FETCH(a8
)( const struct gl_texture_image
*texImage
,
1355 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1357 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1361 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
1364 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLfloats */
1365 static void FETCH(f_a8
)( const struct gl_texture_image
*texImage
,
1366 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1368 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1372 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1376 static void store_texel_a8(struct gl_texture_image
*texImage
,
1377 GLint i
, GLint j
, GLint k
, const void *texel
)
1379 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1380 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1386 /* MESA_FORMAT_L8 ************************************************************/
1388 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1389 static void FETCH(l8
)( const struct gl_texture_image
*texImage
,
1390 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1392 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1395 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
1396 texel
[ACOMP
] = CHAN_MAX
;
1399 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLfloats */
1400 static void FETCH(f_l8
)( const struct gl_texture_image
*texImage
,
1401 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1403 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1406 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
1407 texel
[ACOMP
] = 1.0F
;
1411 static void store_texel_l8(struct gl_texture_image
*texImage
,
1412 GLint i
, GLint j
, GLint k
, const void *texel
)
1414 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1415 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1421 /* MESA_FORMAT_I8 ************************************************************/
1423 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1424 static void FETCH(i8
)( const struct gl_texture_image
*texImage
,
1425 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1427 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1431 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
1434 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLfloats */
1435 static void FETCH(f_i8
)( const struct gl_texture_image
*texImage
,
1436 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1438 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1442 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1446 static void store_texel_i8(struct gl_texture_image
*texImage
,
1447 GLint i
, GLint j
, GLint k
, const void *texel
)
1449 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1450 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1456 /* MESA_FORMAT_CI8 ***********************************************************/
1458 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1459 * color table, and return 4 GLchans.
1461 static void FETCH(ci8
)( const struct gl_texture_image
*texImage
,
1462 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1464 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1465 const struct gl_color_table
*palette
;
1466 const GLchan
*table
;
1468 GET_CURRENT_CONTEXT(ctx
);
1470 if (ctx
->Texture
.SharedPalette
) {
1471 palette
= &ctx
->Texture
.Palette
;
1474 palette
= &texImage
->TexObject
->Palette
;
1476 if (palette
->Size
== 0)
1477 return; /* undefined results */
1478 ASSERT(palette
->Type
!= GL_FLOAT
);
1479 table
= (const GLchan
*) palette
->Table
;
1481 /* Mask the index against size of palette to avoid going out of bounds */
1482 index
= (*src
) & (palette
->Size
- 1);
1484 switch (palette
->Format
) {
1489 texel
[ACOMP
] = table
[index
];
1494 texel
[BCOMP
] = table
[index
];
1495 texel
[ACOMP
] = CHAN_MAX
;
1501 texel
[ACOMP
] = table
[index
];
1503 case GL_LUMINANCE_ALPHA
:
1506 texel
[BCOMP
] = table
[index
* 2 + 0];
1507 texel
[ACOMP
] = table
[index
* 2 + 1];
1510 texel
[RCOMP
] = table
[index
* 3 + 0];
1511 texel
[GCOMP
] = table
[index
* 3 + 1];
1512 texel
[BCOMP
] = table
[index
* 3 + 2];
1513 texel
[ACOMP
] = CHAN_MAX
;
1516 texel
[RCOMP
] = table
[index
* 4 + 0];
1517 texel
[GCOMP
] = table
[index
* 4 + 1];
1518 texel
[BCOMP
] = table
[index
* 4 + 2];
1519 texel
[ACOMP
] = table
[index
* 4 + 3];
1522 _mesa_problem(ctx
, "Bad palette format in palette_sample");
1527 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1528 * color table, and return 4 GLfloats.
1530 static void FETCH(f_ci8
)( const struct gl_texture_image
*texImage
,
1531 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1534 /* Sample as GLchan */
1535 FETCH(ci8
)(texImage
, i
, j
, k
, rgba
);
1536 /* and return as floats */
1537 texel
[RCOMP
] = CHAN_TO_FLOAT(rgba
[RCOMP
]);
1538 texel
[GCOMP
] = CHAN_TO_FLOAT(rgba
[GCOMP
]);
1539 texel
[BCOMP
] = CHAN_TO_FLOAT(rgba
[BCOMP
]);
1540 texel
[ACOMP
] = CHAN_TO_FLOAT(rgba
[ACOMP
]);
1544 static void store_texel_ci8(struct gl_texture_image
*texImage
,
1545 GLint i
, GLint j
, GLint k
, const void *texel
)
1547 const GLubyte
*index
= (const GLubyte
*) texel
;
1548 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1554 /* MESA_FORMAT_YCBCR *********************************************************/
1556 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
1557 /* We convert YCbCr to RGB here */
1558 /* XXX this may break if GLchan != GLubyte */
1559 static void FETCH(ycbcr
)( const struct gl_texture_image
*texImage
,
1560 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1562 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1563 const GLushort
*src1
= src0
+ 1; /* odd */
1564 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1565 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1566 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1567 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1570 /* odd pixel: use y1,cr,cb */
1571 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
1572 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1573 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
1576 /* even pixel: use y0,cr,cb */
1577 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
1578 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1579 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
1581 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
1582 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
1583 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
1584 texel
[ACOMP
] = CHAN_MAX
;
1587 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats */
1588 /* We convert YCbCr to RGB here */
1589 static void FETCH(f_ycbcr
)( const struct gl_texture_image
*texImage
,
1590 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1592 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1593 const GLushort
*src1
= src0
+ 1; /* odd */
1594 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1595 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1596 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1597 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1600 /* odd pixel: use y1,cr,cb */
1601 r
= (1.164 * (y1
-16) + 1.596 * (cr
-128));
1602 g
= (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1603 b
= (1.164 * (y1
-16) + 2.018 * (cb
-128));
1606 /* even pixel: use y0,cr,cb */
1607 r
= (1.164 * (y0
-16) + 1.596 * (cr
-128));
1608 g
= (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1609 b
= (1.164 * (y0
-16) + 2.018 * (cb
-128));
1611 /* XXX remove / 255 here by tweaking arithmetic above */
1615 /* XXX should we really clamp??? */
1616 texel
[RCOMP
] = CLAMP(r
, 0.0, 1.0);
1617 texel
[GCOMP
] = CLAMP(g
, 0.0, 1.0);
1618 texel
[BCOMP
] = CLAMP(b
, 0.0, 1.0);
1619 texel
[ACOMP
] = 1.0F
;
1623 static void store_texel_ycbcr(struct gl_texture_image
*texImage
,
1624 GLint i
, GLint j
, GLint k
, const void *texel
)
1631 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1633 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
1634 /* We convert YCbCr to RGB here */
1635 /* XXX this may break if GLchan != GLubyte */
1636 static void FETCH(ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1637 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1639 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1640 const GLushort
*src1
= src0
+ 1; /* odd */
1641 const GLubyte y0
= *src0
& 0xff; /* luminance */
1642 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1643 const GLubyte y1
= *src1
& 0xff; /* luminance */
1644 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1647 /* odd pixel: use y1,cr,cb */
1648 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
1649 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1650 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
1653 /* even pixel: use y0,cr,cb */
1654 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
1655 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1656 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
1658 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
1659 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
1660 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
1661 texel
[ACOMP
] = CHAN_MAX
;
1664 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats */
1665 /* We convert YCbCr to RGB here */
1666 static void FETCH(f_ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1667 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1669 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1670 const GLushort
*src1
= src0
+ 1; /* odd */
1671 const GLubyte y0
= *src0
& 0xff; /* luminance */
1672 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1673 const GLubyte y1
= *src1
& 0xff; /* luminance */
1674 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1677 /* odd pixel: use y1,cr,cb */
1678 r
= (1.164 * (y1
-16) + 1.596 * (cr
-128));
1679 g
= (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1680 b
= (1.164 * (y1
-16) + 2.018 * (cb
-128));
1683 /* even pixel: use y0,cr,cb */
1684 r
= (1.164 * (y0
-16) + 1.596 * (cr
-128));
1685 g
= (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1686 b
= (1.164 * (y0
-16) + 2.018 * (cb
-128));
1688 /* XXX remove / 255 here by tweaking arithmetic above */
1692 /* XXX should we really clamp??? */
1693 texel
[RCOMP
] = CLAMP(r
, 0.0, 1.0);
1694 texel
[GCOMP
] = CLAMP(g
, 0.0, 1.0);
1695 texel
[BCOMP
] = CLAMP(b
, 0.0, 1.0);
1696 texel
[ACOMP
] = 1.0F
;
1700 static void store_texel_ycbcr_rev(struct gl_texture_image
*texImage
,
1701 GLint i
, GLint j
, GLint k
, const void *texel
)