cc6ed1cc936cf592a94dd9a493aadf76ccada802
2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 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];
157 static void store_texel_alpha(struct gl_texture_image
*texImage
,
158 GLint i
, GLint j
, GLint k
, const void *texel
)
160 const GLchan
*rgba
= (const GLchan
*) texel
;
161 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
162 dst
[0] = rgba
[ACOMP
];
166 /* MESA_FORMAT_LUMINANCE *****************************************************/
168 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
169 static void FETCH(luminance
)( const struct gl_texture_image
*texImage
,
170 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
172 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
175 texel
[BCOMP
] = src
[0];
176 texel
[ACOMP
] = CHAN_MAX
;
180 static void store_texel_luminance(struct gl_texture_image
*texImage
,
181 GLint i
, GLint j
, GLint k
, const void *texel
)
183 const GLchan
*rgba
= (const GLchan
*) texel
;
184 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
185 dst
[0] = rgba
[RCOMP
];
189 /* MESA_FORMAT_LUMINANCE_ALPHA ***********************************************/
191 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
192 static void FETCH(luminance_alpha
)( const struct gl_texture_image
*texImage
,
193 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
195 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 2);
196 texel
[RCOMP
] = src
[0];
197 texel
[GCOMP
] = src
[0];
198 texel
[BCOMP
] = src
[0];
199 texel
[ACOMP
] = src
[1];
203 static void store_texel_luminance_alpha(struct gl_texture_image
*texImage
,
204 GLint i
, GLint j
, GLint k
, const void *texel
)
206 const GLchan
*rgba
= (const GLchan
*) texel
;
207 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 2);
208 dst
[0] = rgba
[RCOMP
];
209 dst
[1] = rgba
[ACOMP
];
213 /* MESA_FORMAT_INTENSITY *****************************************************/
215 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
216 static void FETCH(intensity
)( const struct gl_texture_image
*texImage
,
217 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
219 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
220 texel
[RCOMP
] = src
[0];
221 texel
[GCOMP
] = src
[0];
222 texel
[BCOMP
] = src
[0];
223 texel
[ACOMP
] = src
[0];
227 static void store_texel_intensity(struct gl_texture_image
*texImage
,
228 GLint i
, GLint j
, GLint k
, const void *texel
)
230 const GLchan
*rgba
= (const GLchan
*) texel
;
231 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
232 dst
[0] = rgba
[RCOMP
];
237 /* MESA_FORMAT_DEPTH_COMPONENT_F32 *******************************************/
239 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
240 * returning 1 GLfloat.
241 * Note: no GLchan version of this function.
243 static void FETCH(f_depth_component_f32
)( const struct gl_texture_image
*texImage
,
244 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
246 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
251 static void store_texel_depth_component_f32(struct gl_texture_image
*texImage
,
252 GLint i
, GLint j
, GLint k
, const void *texel
)
254 const GLfloat
*depth
= (const GLfloat
*) texel
;
255 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
261 /* MESA_FORMAT_DEPTH_COMPONENT16 *********************************************/
263 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
264 * returning 1 GLfloat.
265 * Note: no GLchan version of this function.
267 static void FETCH(f_depth_component16
)(const struct gl_texture_image
*texImage
,
268 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
270 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
271 texel
[0] = src
[0] * (1.0F
/ 65535.0F
);
275 static void store_texel_depth_component16(struct gl_texture_image
*texImage
,
276 GLint i
, GLint j
, GLint k
, const void *texel
)
278 const GLushort
*depth
= (const GLushort
*) texel
;
279 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
285 /* MESA_FORMAT_RGBA_F32 ******************************************************/
287 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
289 static void FETCH(f_rgba_f32
)( const struct gl_texture_image
*texImage
,
290 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
292 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 4);
293 texel
[RCOMP
] = src
[0];
294 texel
[GCOMP
] = src
[1];
295 texel
[BCOMP
] = src
[2];
296 texel
[ACOMP
] = src
[3];
300 static void store_texel_rgba_f32(struct gl_texture_image
*texImage
,
301 GLint i
, GLint j
, GLint k
, const void *texel
)
303 const GLfloat
*depth
= (const GLfloat
*) texel
;
304 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
305 dst
[0] = depth
[RCOMP
];
306 dst
[1] = depth
[GCOMP
];
307 dst
[2] = depth
[BCOMP
];
308 dst
[3] = depth
[ACOMP
];
313 /* MESA_FORMAT_RGBA_F16 ******************************************************/
315 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
316 * returning 4 GLfloats.
318 static void FETCH(f_rgba_f16
)( const struct gl_texture_image
*texImage
,
319 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
321 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 4);
322 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
323 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
324 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
325 texel
[ACOMP
] = _mesa_half_to_float(src
[3]);
329 static void store_texel_rgba_f16(struct gl_texture_image
*texImage
,
330 GLint i
, GLint j
, GLint k
, const void *texel
)
332 const GLfloat
*depth
= (const GLfloat
*) texel
;
333 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
334 dst
[0] = _mesa_float_to_half(*depth
);
338 /* MESA_FORMAT_RGB_F32 *******************************************************/
340 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
341 * returning 4 GLfloats.
343 static void FETCH(f_rgb_f32
)( const struct gl_texture_image
*texImage
,
344 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
346 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 3);
347 texel
[RCOMP
] = src
[0];
348 texel
[GCOMP
] = src
[1];
349 texel
[BCOMP
] = src
[2];
354 static void store_texel_rgb_f32(struct gl_texture_image
*texImage
,
355 GLint i
, GLint j
, GLint k
, const void *texel
)
357 const GLfloat
*depth
= (const GLfloat
*) texel
;
358 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
364 /* MESA_FORMAT_RGB_F16 *******************************************************/
366 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
367 * returning 4 GLfloats.
369 static void FETCH(f_rgb_f16
)( const struct gl_texture_image
*texImage
,
370 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
372 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 3);
373 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
374 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
375 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
380 static void store_texel_rgb_f16(struct gl_texture_image
*texImage
,
381 GLint i
, GLint j
, GLint k
, const void *texel
)
383 const GLfloat
*depth
= (const GLfloat
*) texel
;
384 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
385 dst
[0] = _mesa_float_to_half(*depth
);
390 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
392 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
393 * returning 4 GLfloats.
395 static void FETCH(f_alpha_f32
)( const struct gl_texture_image
*texImage
,
396 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
398 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
402 texel
[ACOMP
] = src
[0];
406 static void store_texel_alpha_f32(struct gl_texture_image
*texImage
,
407 GLint i
, GLint j
, GLint k
, const void *texel
)
409 const GLfloat
*rgba
= (const GLfloat
*) texel
;
410 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
411 dst
[0] = rgba
[ACOMP
];
416 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
418 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
419 * returning 4 GLfloats.
421 static void FETCH(f_alpha_f16
)( const struct gl_texture_image
*texImage
,
422 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
424 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
428 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
432 static void store_texel_alpha_f16(struct gl_texture_image
*texImage
,
433 GLint i
, GLint j
, GLint k
, const void *texel
)
435 const GLfloat
*rgba
= (const GLfloat
*) texel
;
436 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
437 dst
[0] = _mesa_float_to_half(rgba
[ACOMP
]);
442 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
444 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
445 * returning 4 GLfloats.
447 static void FETCH(f_luminance_f32
)( const struct gl_texture_image
*texImage
,
448 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
450 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
453 texel
[BCOMP
] = src
[0];
458 static void store_texel_luminance_f32(struct gl_texture_image
*texImage
,
459 GLint i
, GLint j
, GLint k
, const void *texel
)
461 const GLfloat
*rgba
= (const GLfloat
*) texel
;
462 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
463 dst
[0] = rgba
[RCOMP
];
468 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
470 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
471 * returning 4 GLfloats.
473 static void FETCH(f_luminance_f16
)( const struct gl_texture_image
*texImage
,
474 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
476 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
479 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
484 static void store_texel_luminance_f16(struct gl_texture_image
*texImage
,
485 GLint i
, GLint j
, GLint k
, const void *texel
)
487 const GLfloat
*rgba
= (const GLfloat
*) texel
;
488 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
489 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
494 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
496 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
497 * returning 4 GLfloats.
499 static void FETCH(f_luminance_alpha_f32
)( const struct gl_texture_image
*texImage
,
500 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
502 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
505 texel
[BCOMP
] = src
[0];
506 texel
[ACOMP
] = src
[1];
510 static void store_texel_luminance_alpha_f32(struct gl_texture_image
*texImage
,
511 GLint i
, GLint j
, GLint k
, const void *texel
)
513 const GLfloat
*rgba
= (const GLfloat
*) texel
;
514 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
515 dst
[0] = rgba
[RCOMP
];
516 dst
[1] = rgba
[ACOMP
];
521 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
523 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
524 * returning 4 GLfloats.
526 static void FETCH(f_luminance_alpha_f16
)( const struct gl_texture_image
*texImage
,
527 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
529 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
532 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
533 texel
[ACOMP
] = _mesa_half_to_float(src
[1]);
537 static void store_texel_luminance_alpha_f16(struct gl_texture_image
*texImage
,
538 GLint i
, GLint j
, GLint k
, const void *texel
)
540 const GLfloat
*rgba
= (const GLfloat
*) texel
;
541 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
542 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
543 dst
[1] = _mesa_float_to_half(rgba
[ACOMP
]);
548 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
550 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
551 * returning 4 GLfloats.
553 static void FETCH(f_intensity_f32
)( const struct gl_texture_image
*texImage
,
554 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
556 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
560 texel
[ACOMP
] = src
[0];
564 static void store_texel_intensity_f32(struct gl_texture_image
*texImage
,
565 GLint i
, GLint j
, GLint k
, const void *texel
)
567 const GLfloat
*rgba
= (const GLfloat
*) texel
;
568 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
569 dst
[0] = rgba
[RCOMP
];
574 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
576 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
577 * returning 4 GLfloats.
579 static void FETCH(f_intensity_f16
)( const struct gl_texture_image
*texImage
,
580 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
582 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
586 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
590 static void store_texel_intensity_f16(struct gl_texture_image
*texImage
,
591 GLint i
, GLint j
, GLint k
, const void *texel
)
593 const GLfloat
*rgba
= (const GLfloat
*) texel
;
594 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
595 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
603 * Begin Hardware formats
606 /* MESA_FORMAT_RGBA8888 ******************************************************/
608 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
609 static void FETCH(rgba8888
)( const struct gl_texture_image
*texImage
,
610 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
612 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
613 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
614 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
615 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
616 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
620 static void store_texel_rgba8888(struct gl_texture_image
*texImage
,
621 GLint i
, GLint j
, GLint k
, const void *texel
)
623 const GLubyte
*rgba
= (const GLubyte
*) texel
;
624 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
625 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
630 /* MESA_FORMAT_RGBA888_REV ***************************************************/
632 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
633 static void FETCH(rgba8888_rev
)( const struct gl_texture_image
*texImage
,
634 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
636 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
637 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
638 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
639 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
640 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
644 static void store_texel_rgba8888_rev(struct gl_texture_image
*texImage
,
645 GLint i
, GLint j
, GLint k
, const void *texel
)
647 const GLubyte
*rgba
= (const GLubyte
*) texel
;
648 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
649 *dst
= PACK_COLOR_8888_REV(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
654 /* MESA_FORMAT_ARGB8888 ******************************************************/
656 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
657 static void FETCH(argb8888
)( const struct gl_texture_image
*texImage
,
658 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
660 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
661 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
662 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
663 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
664 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
668 static void store_texel_argb8888(struct gl_texture_image
*texImage
,
669 GLint i
, GLint j
, GLint k
, const void *texel
)
671 const GLubyte
*rgba
= (const GLubyte
*) texel
;
672 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
673 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
678 /* MESA_FORMAT_ARGB8888_REV **************************************************/
680 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLchans */
681 static void FETCH(argb8888_rev
)( const struct gl_texture_image
*texImage
,
682 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
684 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
685 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
686 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
687 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
688 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
692 static void store_texel_argb8888_rev(struct gl_texture_image
*texImage
,
693 GLint i
, GLint j
, GLint k
, const void *texel
)
695 const GLubyte
*rgba
= (const GLubyte
*) texel
;
696 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
697 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
702 /* MESA_FORMAT_RGB888 ********************************************************/
704 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
705 static void FETCH(rgb888
)( const struct gl_texture_image
*texImage
,
706 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
708 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
709 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
710 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
711 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
712 texel
[ACOMP
] = CHAN_MAX
;
716 static void store_texel_rgb888(struct gl_texture_image
*texImage
,
717 GLint i
, GLint j
, GLint k
, const void *texel
)
719 const GLubyte
*rgba
= (const GLubyte
*) texel
;
720 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
721 dst
[0] = rgba
[RCOMP
];
722 dst
[1] = rgba
[GCOMP
];
723 dst
[2] = rgba
[BCOMP
];
728 /* MESA_FORMAT_BGR888 ********************************************************/
730 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
731 static void FETCH(bgr888
)( const struct gl_texture_image
*texImage
,
732 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
734 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
735 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[0] );
736 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
737 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[2] );
738 texel
[ACOMP
] = CHAN_MAX
;
742 static void store_texel_bgr888(struct gl_texture_image
*texImage
,
743 GLint i
, GLint j
, GLint k
, const void *texel
)
745 const GLubyte
*rgba
= (const GLubyte
*) texel
;
746 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
747 dst
[0] = rgba
[BCOMP
];
748 dst
[1] = rgba
[GCOMP
];
749 dst
[2] = rgba
[RCOMP
];
754 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
755 instead of slow (g << 2) * 255 / 252 (always rounds down) */
757 /* MESA_FORMAT_RGB565 ********************************************************/
759 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
760 static void FETCH(rgb565
)( const struct gl_texture_image
*texImage
,
761 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
763 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
764 const GLushort s
= *src
;
765 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
766 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
767 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
768 texel
[ACOMP
] = CHAN_MAX
;
772 static void store_texel_rgb565(struct gl_texture_image
*texImage
,
773 GLint i
, GLint j
, GLint k
, const void *texel
)
775 const GLubyte
*rgba
= (const GLubyte
*) texel
;
776 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
777 *dst
= PACK_COLOR_565(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
782 /* MESA_FORMAT_RGB565_REV ****************************************************/
784 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
785 static void FETCH(rgb565_rev
)( const struct gl_texture_image
*texImage
,
786 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
788 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
789 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
790 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
791 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
792 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
793 texel
[ACOMP
] = CHAN_MAX
;
797 static void store_texel_rgb565_rev(struct gl_texture_image
*texImage
,
798 GLint i
, GLint j
, GLint k
, const void *texel
)
800 const GLubyte
*rgba
= (const GLubyte
*) texel
;
801 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
802 *dst
= PACK_COLOR_565(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
807 /* MESA_FORMAT_ARGB4444 ******************************************************/
809 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
810 static void FETCH(argb4444
)( const struct gl_texture_image
*texImage
,
811 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
813 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
814 const GLushort s
= *src
;
815 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) | ((s
>> 4) & 0xf0) );
816 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) | ((s
) & 0xf0) );
817 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) | ((s
<< 4) & 0xf0) );
818 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) | ((s
>> 8) & 0xf0) );
822 static void store_texel_argb4444(struct gl_texture_image
*texImage
,
823 GLint i
, GLint j
, GLint k
, const void *texel
)
825 const GLubyte
*rgba
= (const GLubyte
*) texel
;
826 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
827 *dst
= PACK_COLOR_4444(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
832 /* MESA_FORMAT_ARGB4444_REV **************************************************/
834 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
835 static void FETCH(argb4444_rev
)( const struct gl_texture_image
*texImage
,
836 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
838 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
839 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) | ((s
<< 4) & 0xf0) );
840 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) | ((s
>> 8) & 0xf0) );
841 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) | ((s
>> 4) & 0xf0) );
842 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) | ((s
) & 0xf0) );
846 static void store_texel_argb4444_rev(struct gl_texture_image
*texImage
,
847 GLint i
, GLint j
, GLint k
, const void *texel
)
849 const GLubyte
*rgba
= (const GLubyte
*) texel
;
850 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
851 *dst
= PACK_COLOR_4444(rgba
[ACOMP
], rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
856 /* MESA_FORMAT_ARGB1555 ******************************************************/
858 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
859 static void FETCH(argb1555
)( const struct gl_texture_image
*texImage
,
860 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
862 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
863 const GLushort s
= *src
;
864 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
865 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
866 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
867 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
871 static void store_texel_argb1555(struct gl_texture_image
*texImage
,
872 GLint i
, GLint j
, GLint k
, const void *texel
)
874 const GLubyte
*rgba
= (const GLubyte
*) texel
;
875 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
876 *dst
= PACK_COLOR_1555(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
881 /* MESA_FORMAT_ARGB1555_REV **************************************************/
883 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
884 static void FETCH(argb1555_rev
)( const struct gl_texture_image
*texImage
,
885 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
887 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
888 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
889 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
890 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
891 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
892 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
896 static void store_texel_argb1555_rev(struct gl_texture_image
*texImage
,
897 GLint i
, GLint j
, GLint k
, const void *texel
)
899 const GLubyte
*rgba
= (const GLubyte
*) texel
;
900 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
901 *dst
= PACK_COLOR_1555_REV(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
906 /* MESA_FORMAT_AL88 **********************************************************/
908 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
909 static void FETCH(al88
)( const struct gl_texture_image
*texImage
,
910 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
912 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
915 texel
[BCOMP
] = UBYTE_TO_CHAN( s
& 0xff );
916 texel
[ACOMP
] = UBYTE_TO_CHAN( s
>> 8 );
920 static void store_texel_al88(struct gl_texture_image
*texImage
,
921 GLint i
, GLint j
, GLint k
, const void *texel
)
923 const GLubyte
*rgba
= (const GLubyte
*) texel
;
924 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
925 *dst
= PACK_COLOR_88(rgba
[ACOMP
], rgba
[RCOMP
]);
930 /* MESA_FORMAT_AL88_REV ******************************************************/
932 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
933 static void FETCH(al88_rev
)( const struct gl_texture_image
*texImage
,
934 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
936 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
939 texel
[BCOMP
] = UBYTE_TO_CHAN( s
>> 8 );
940 texel
[ACOMP
] = UBYTE_TO_CHAN( s
& 0xff );
944 static void store_texel_al88_rev(struct gl_texture_image
*texImage
,
945 GLint i
, GLint j
, GLint k
, const void *texel
)
947 const GLubyte
*rgba
= (const GLubyte
*) texel
;
948 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
949 *dst
= PACK_COLOR_88(rgba
[RCOMP
], rgba
[ACOMP
]);
954 /* MESA_FORMAT_RGB332 ********************************************************/
956 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
957 static void FETCH(rgb332
)( const struct gl_texture_image
*texImage
,
958 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
960 static const GLubyte lut2to8
[4] = {0, 85, 170, 255};
961 static const GLubyte lut3to8
[8] = {0, 36, 73, 109, 146, 182, 219, 255};
962 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
963 const GLubyte s
= *src
;
964 texel
[RCOMP
] = UBYTE_TO_CHAN( lut3to8
[(s
>> 5) & 0x7] );
965 texel
[GCOMP
] = UBYTE_TO_CHAN( lut3to8
[(s
>> 2) & 0x7] );
966 texel
[BCOMP
] = UBYTE_TO_CHAN( lut2to8
[(s
) & 0x3] );
967 texel
[ACOMP
] = CHAN_MAX
;
971 static void store_texel_rgb332(struct gl_texture_image
*texImage
,
972 GLint i
, GLint j
, GLint k
, const void *texel
)
974 const GLubyte
*rgba
= (const GLubyte
*) texel
;
975 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
976 *dst
= PACK_COLOR_332(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
981 /* MESA_FORMAT_A8 ************************************************************/
983 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
984 static void FETCH(a8
)( const struct gl_texture_image
*texImage
,
985 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
987 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
991 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
995 static void store_texel_a8(struct gl_texture_image
*texImage
,
996 GLint i
, GLint j
, GLint k
, const void *texel
)
998 const GLubyte
*rgba
= (const GLubyte
*) texel
;
999 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1005 /* MESA_FORMAT_L8 ************************************************************/
1007 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1008 static void FETCH(l8
)( const struct gl_texture_image
*texImage
,
1009 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1011 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1014 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
1015 texel
[ACOMP
] = CHAN_MAX
;
1019 static void store_texel_l8(struct gl_texture_image
*texImage
,
1020 GLint i
, GLint j
, GLint k
, const void *texel
)
1022 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1023 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1029 /* MESA_FORMAT_I8 ************************************************************/
1031 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1032 static void FETCH(i8
)( const struct gl_texture_image
*texImage
,
1033 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1035 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1039 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
1043 static void store_texel_i8(struct gl_texture_image
*texImage
,
1044 GLint i
, GLint j
, GLint k
, const void *texel
)
1046 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1047 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1053 /* MESA_FORMAT_CI8 ***********************************************************/
1055 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1056 * color table, and return 4 GLchans.
1058 static void FETCH(ci8
)( const struct gl_texture_image
*texImage
,
1059 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1061 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1062 const struct gl_color_table
*palette
;
1064 GET_CURRENT_CONTEXT(ctx
);
1066 if (ctx
->Texture
.SharedPalette
) {
1067 palette
= &ctx
->Texture
.Palette
;
1070 palette
= &texImage
->TexObject
->Palette
;
1072 if (palette
->Size
== 0)
1073 return; /* undefined results */
1075 /* Mask the index against size of palette to avoid going out of bounds */
1076 index
= (*src
) & (palette
->Size
- 1);
1078 if (palette
->Type
== GL_FLOAT
) {
1079 const GLfloat
*ftable
= (const GLfloat
*) palette
->Table
;
1080 switch (palette
->_BaseFormat
) {
1085 texel
[ACOMP
] = (GLchan
) (ftable
[index
] * CHAN_MAX
);
1090 texel
[BCOMP
] = (GLchan
) (ftable
[index
] * CHAN_MAX
);
1091 texel
[ACOMP
] = CHAN_MAX
;
1097 texel
[ACOMP
] = ftable
[index
] * CHAN_MAX
;
1099 case GL_LUMINANCE_ALPHA
:
1102 texel
[BCOMP
] = (GLchan
) (ftable
[index
* 2 + 0] * CHAN_MAX
);
1103 texel
[ACOMP
] = (GLchan
) (ftable
[index
* 2 + 1] * CHAN_MAX
);
1106 texel
[RCOMP
] = (GLchan
) (ftable
[index
* 3 + 0] * CHAN_MAX
);
1107 texel
[GCOMP
] = (GLchan
) (ftable
[index
* 3 + 1] * CHAN_MAX
);
1108 texel
[BCOMP
] = (GLchan
) (ftable
[index
* 3 + 2] * CHAN_MAX
);
1109 texel
[ACOMP
] = CHAN_MAX
;
1112 texel
[RCOMP
] = (GLchan
) (ftable
[index
* 4 + 0] * CHAN_MAX
);
1113 texel
[GCOMP
] = (GLchan
) (ftable
[index
* 4 + 1] * CHAN_MAX
);
1114 texel
[BCOMP
] = (GLchan
) (ftable
[index
* 4 + 2] * CHAN_MAX
);
1115 texel
[ACOMP
] = (GLchan
) (ftable
[index
* 4 + 3] * CHAN_MAX
);
1118 _mesa_problem(ctx
, "Bad palette format in fetch_texel_ci8");
1122 const GLchan
*table
= (const GLchan
*) palette
->Table
;
1123 switch (palette
->_BaseFormat
) {
1128 texel
[ACOMP
] = table
[index
];
1133 texel
[BCOMP
] = table
[index
];
1134 texel
[ACOMP
] = CHAN_MAX
;
1140 texel
[ACOMP
] = table
[index
];
1142 case GL_LUMINANCE_ALPHA
:
1145 texel
[BCOMP
] = table
[index
* 2 + 0];
1146 texel
[ACOMP
] = table
[index
* 2 + 1];
1149 texel
[RCOMP
] = table
[index
* 3 + 0];
1150 texel
[GCOMP
] = table
[index
* 3 + 1];
1151 texel
[BCOMP
] = table
[index
* 3 + 2];
1152 texel
[ACOMP
] = CHAN_MAX
;
1155 texel
[RCOMP
] = table
[index
* 4 + 0];
1156 texel
[GCOMP
] = table
[index
* 4 + 1];
1157 texel
[BCOMP
] = table
[index
* 4 + 2];
1158 texel
[ACOMP
] = table
[index
* 4 + 3];
1161 _mesa_problem(ctx
, "Bad palette format in fetch_texel_ci8");
1167 static void store_texel_ci8(struct gl_texture_image
*texImage
,
1168 GLint i
, GLint j
, GLint k
, const void *texel
)
1170 const GLubyte
*index
= (const GLubyte
*) texel
;
1171 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1177 /* MESA_FORMAT_YCBCR *********************************************************/
1179 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
1180 /* We convert YCbCr to RGB here */
1181 /* XXX this may break if GLchan != GLubyte */
1182 static void FETCH(ycbcr
)( const struct gl_texture_image
*texImage
,
1183 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1185 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1186 const GLushort
*src1
= src0
+ 1; /* odd */
1187 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1188 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1189 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1190 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1193 /* odd pixel: use y1,cr,cb */
1194 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
1195 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1196 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
1199 /* even pixel: use y0,cr,cb */
1200 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
1201 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1202 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
1204 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
1205 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
1206 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
1207 texel
[ACOMP
] = CHAN_MAX
;
1211 static void store_texel_ycbcr(struct gl_texture_image
*texImage
,
1212 GLint i
, GLint j
, GLint k
, const void *texel
)
1219 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1221 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
1222 /* We convert YCbCr to RGB here */
1223 /* XXX this may break if GLchan != GLubyte */
1224 static void FETCH(ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1225 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1227 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1228 const GLushort
*src1
= src0
+ 1; /* odd */
1229 const GLubyte y0
= *src0
& 0xff; /* luminance */
1230 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1231 const GLubyte y1
= *src1
& 0xff; /* luminance */
1232 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1235 /* odd pixel: use y1,cr,cb */
1236 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
1237 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1238 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
1241 /* even pixel: use y0,cr,cb */
1242 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
1243 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1244 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
1246 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
1247 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
1248 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
1249 texel
[ACOMP
] = CHAN_MAX
;
1253 static void store_texel_ycbcr_rev(struct gl_texture_image
*texImage
,
1254 GLint i
, GLint j
, GLint k
, const void *texel
)
1261 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1263 static void FETCH(f_z24_s8
)( const struct gl_texture_image
*texImage
,
1264 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1266 /* only return Z, not stencil data */
1267 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1268 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
1269 texel
[0] = ((*src
) >> 8) * scale
;
1270 ASSERT(texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_Z24_S8
);
1271 ASSERT(texel
[0] >= 0.0F
);
1272 ASSERT(texel
[0] <= 1.0F
);
1276 static void store_texel_z24_s8(struct gl_texture_image
*texImage
,
1277 GLint i
, GLint j
, GLint k
, const void *texel
)
1279 /* only store Z, not stencil */
1280 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1281 GLfloat depth
= *((GLfloat
*) texel
);
1282 GLuint zi
= ((GLuint
) (depth
* 0xffffff)) << 8;
1283 *dst
= zi
| (*dst
& 0xff);