2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008 VMware, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * \file texformat_tmp.h
29 * Texel fetch functions template.
31 * This template file is used by texformat.c to generate texel fetch functions
32 * for 1-D, 2-D and 3-D texture images.
34 * It should be expanded by defining \p DIM as the number texture dimensions
35 * (1, 2 or 3). According to the value of \p DIM a series of macros is defined
36 * for the texel lookup in the gl_texture_image::Data.
38 * \sa texformat.c and FetchTexel.
40 * \author Gareth Hughes
47 #define TEXEL_ADDR( type, image, i, j, k, size ) \
48 ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
50 #define FETCH(x) fetch_texel_1d_##x
54 #define TEXEL_ADDR( type, image, i, j, k, size ) \
56 ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
58 #define FETCH(x) fetch_texel_2d_##x
62 #define TEXEL_ADDR( type, image, i, j, k, size ) \
63 ((type *)(image)->Data + ((image)->ImageOffsets[k] \
64 + (image)->RowStride * (j) + (i)) * (size))
66 #define FETCH(x) fetch_texel_3d_##x
69 #error illegal number of texture dimensions
73 /* MESA_FORMAT_RGBA **********************************************************/
75 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLchans */
76 static void FETCH(rgba
)( const struct gl_texture_image
*texImage
,
77 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
79 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 4);
80 COPY_CHAN4( texel
, src
);
83 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
84 static void FETCH(f_rgba
)( const struct gl_texture_image
*texImage
,
85 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
87 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 4);
88 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
89 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
90 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
91 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[3]);
95 /* Store a GLchan RGBA texel */
96 static void store_texel_rgba(struct gl_texture_image
*texImage
,
97 GLint i
, GLint j
, GLint k
, const void *texel
)
99 const GLchan
*rgba
= (const GLchan
*) texel
;
100 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 4);
101 dst
[0] = rgba
[RCOMP
];
102 dst
[1] = rgba
[GCOMP
];
103 dst
[2] = rgba
[BCOMP
];
104 dst
[3] = rgba
[ACOMP
];
108 /* MESA_FORMAT_RGB ***********************************************************/
110 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLchans */
111 static void FETCH(rgb
)( const struct gl_texture_image
*texImage
,
112 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
114 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 3);
115 texel
[RCOMP
] = src
[0];
116 texel
[GCOMP
] = src
[1];
117 texel
[BCOMP
] = src
[2];
118 texel
[ACOMP
] = CHAN_MAX
;
121 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
122 static void FETCH(f_rgb
)( const struct gl_texture_image
*texImage
,
123 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
125 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 3);
126 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
127 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
128 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
133 static void store_texel_rgb(struct gl_texture_image
*texImage
,
134 GLint i
, GLint j
, GLint k
, const void *texel
)
136 const GLchan
*rgba
= (const GLchan
*) texel
;
137 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 3);
138 dst
[0] = rgba
[RCOMP
];
139 dst
[1] = rgba
[GCOMP
];
140 dst
[2] = rgba
[BCOMP
];
144 /* MESA_FORMAT_ALPHA *********************************************************/
146 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
147 static void FETCH(alpha
)( const struct gl_texture_image
*texImage
,
148 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
150 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
154 texel
[ACOMP
] = src
[0];
158 static void store_texel_alpha(struct gl_texture_image
*texImage
,
159 GLint i
, GLint j
, GLint k
, const void *texel
)
161 const GLchan
*rgba
= (const GLchan
*) texel
;
162 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
163 dst
[0] = rgba
[ACOMP
];
167 /* MESA_FORMAT_LUMINANCE *****************************************************/
169 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
170 static void FETCH(luminance
)( const struct gl_texture_image
*texImage
,
171 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
173 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
176 texel
[BCOMP
] = src
[0];
177 texel
[ACOMP
] = CHAN_MAX
;
181 static void store_texel_luminance(struct gl_texture_image
*texImage
,
182 GLint i
, GLint j
, GLint k
, const void *texel
)
184 const GLchan
*rgba
= (const GLchan
*) texel
;
185 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
186 dst
[0] = rgba
[RCOMP
];
190 /* MESA_FORMAT_LUMINANCE_ALPHA ***********************************************/
192 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
193 static void FETCH(luminance_alpha
)( const struct gl_texture_image
*texImage
,
194 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
196 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 2);
197 texel
[RCOMP
] = src
[0];
198 texel
[GCOMP
] = src
[0];
199 texel
[BCOMP
] = src
[0];
200 texel
[ACOMP
] = src
[1];
204 static void store_texel_luminance_alpha(struct gl_texture_image
*texImage
,
205 GLint i
, GLint j
, GLint k
, const void *texel
)
207 const GLchan
*rgba
= (const GLchan
*) texel
;
208 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 2);
209 dst
[0] = rgba
[RCOMP
];
210 dst
[1] = rgba
[ACOMP
];
214 /* MESA_FORMAT_INTENSITY *****************************************************/
216 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
217 static void FETCH(intensity
)( const struct gl_texture_image
*texImage
,
218 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
220 const GLchan
*src
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
221 texel
[RCOMP
] = src
[0];
222 texel
[GCOMP
] = src
[0];
223 texel
[BCOMP
] = src
[0];
224 texel
[ACOMP
] = src
[0];
228 static void store_texel_intensity(struct gl_texture_image
*texImage
,
229 GLint i
, GLint j
, GLint k
, const void *texel
)
231 const GLchan
*rgba
= (const GLchan
*) texel
;
232 GLchan
*dst
= TEXEL_ADDR(GLchan
, texImage
, i
, j
, k
, 1);
233 dst
[0] = rgba
[RCOMP
];
238 /* MESA_FORMAT_Z32 ***********************************************************/
240 /* Fetch depth texel from 1D, 2D or 3D 32-bit depth texture,
241 * returning 1 GLfloat.
242 * Note: no GLchan version of this function.
244 static void FETCH(f_z32
)( const struct gl_texture_image
*texImage
,
245 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
247 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
248 texel
[0] = src
[0] * (1.0F
/ 0xffffffff);
252 static void store_texel_z32(struct gl_texture_image
*texImage
,
253 GLint i
, GLint j
, GLint k
, const void *texel
)
255 const GLuint
*depth
= (const GLuint
*) texel
;
256 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
262 /* MESA_FORMAT_Z16 ***********************************************************/
264 /* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
265 * returning 1 GLfloat.
266 * Note: no GLchan version of this function.
268 static void FETCH(f_z16
)(const struct gl_texture_image
*texImage
,
269 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
271 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
272 texel
[0] = src
[0] * (1.0F
/ 65535.0F
);
276 static void store_texel_z16(struct gl_texture_image
*texImage
,
277 GLint i
, GLint j
, GLint k
, const void *texel
)
279 const GLushort
*depth
= (const GLushort
*) texel
;
280 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
286 /* MESA_FORMAT_RGBA_F32 ******************************************************/
288 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
290 static void FETCH(f_rgba_f32
)( const struct gl_texture_image
*texImage
,
291 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
293 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 4);
294 texel
[RCOMP
] = src
[0];
295 texel
[GCOMP
] = src
[1];
296 texel
[BCOMP
] = src
[2];
297 texel
[ACOMP
] = src
[3];
301 static void store_texel_rgba_f32(struct gl_texture_image
*texImage
,
302 GLint i
, GLint j
, GLint k
, const void *texel
)
304 const GLfloat
*depth
= (const GLfloat
*) texel
;
305 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
306 dst
[0] = depth
[RCOMP
];
307 dst
[1] = depth
[GCOMP
];
308 dst
[2] = depth
[BCOMP
];
309 dst
[3] = depth
[ACOMP
];
314 /* MESA_FORMAT_RGBA_F16 ******************************************************/
316 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
317 * returning 4 GLfloats.
319 static void FETCH(f_rgba_f16
)( const struct gl_texture_image
*texImage
,
320 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
322 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 4);
323 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
324 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
325 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
326 texel
[ACOMP
] = _mesa_half_to_float(src
[3]);
330 static void store_texel_rgba_f16(struct gl_texture_image
*texImage
,
331 GLint i
, GLint j
, GLint k
, const void *texel
)
333 const GLfloat
*depth
= (const GLfloat
*) texel
;
334 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
335 dst
[0] = _mesa_float_to_half(*depth
);
339 /* MESA_FORMAT_RGB_F32 *******************************************************/
341 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
342 * returning 4 GLfloats.
344 static void FETCH(f_rgb_f32
)( const struct gl_texture_image
*texImage
,
345 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
347 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 3);
348 texel
[RCOMP
] = src
[0];
349 texel
[GCOMP
] = src
[1];
350 texel
[BCOMP
] = src
[2];
355 static void store_texel_rgb_f32(struct gl_texture_image
*texImage
,
356 GLint i
, GLint j
, GLint k
, const void *texel
)
358 const GLfloat
*depth
= (const GLfloat
*) texel
;
359 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
365 /* MESA_FORMAT_RGB_F16 *******************************************************/
367 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
368 * returning 4 GLfloats.
370 static void FETCH(f_rgb_f16
)( const struct gl_texture_image
*texImage
,
371 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
373 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 3);
374 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
375 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
376 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
381 static void store_texel_rgb_f16(struct gl_texture_image
*texImage
,
382 GLint i
, GLint j
, GLint k
, const void *texel
)
384 const GLfloat
*depth
= (const GLfloat
*) texel
;
385 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
386 dst
[0] = _mesa_float_to_half(*depth
);
391 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
393 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
394 * returning 4 GLfloats.
396 static void FETCH(f_alpha_f32
)( const struct gl_texture_image
*texImage
,
397 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
399 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
403 texel
[ACOMP
] = src
[0];
407 static void store_texel_alpha_f32(struct gl_texture_image
*texImage
,
408 GLint i
, GLint j
, GLint k
, const void *texel
)
410 const GLfloat
*rgba
= (const GLfloat
*) texel
;
411 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
412 dst
[0] = rgba
[ACOMP
];
417 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
419 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
420 * returning 4 GLfloats.
422 static void FETCH(f_alpha_f16
)( const struct gl_texture_image
*texImage
,
423 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
425 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
429 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
433 static void store_texel_alpha_f16(struct gl_texture_image
*texImage
,
434 GLint i
, GLint j
, GLint k
, const void *texel
)
436 const GLfloat
*rgba
= (const GLfloat
*) texel
;
437 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
438 dst
[0] = _mesa_float_to_half(rgba
[ACOMP
]);
443 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
445 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
446 * returning 4 GLfloats.
448 static void FETCH(f_luminance_f32
)( const struct gl_texture_image
*texImage
,
449 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
451 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
454 texel
[BCOMP
] = src
[0];
459 static void store_texel_luminance_f32(struct gl_texture_image
*texImage
,
460 GLint i
, GLint j
, GLint k
, const void *texel
)
462 const GLfloat
*rgba
= (const GLfloat
*) texel
;
463 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
464 dst
[0] = rgba
[RCOMP
];
469 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
471 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
472 * returning 4 GLfloats.
474 static void FETCH(f_luminance_f16
)( const struct gl_texture_image
*texImage
,
475 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
477 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
480 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
485 static void store_texel_luminance_f16(struct gl_texture_image
*texImage
,
486 GLint i
, GLint j
, GLint k
, const void *texel
)
488 const GLfloat
*rgba
= (const GLfloat
*) texel
;
489 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
490 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
495 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
497 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
498 * returning 4 GLfloats.
500 static void FETCH(f_luminance_alpha_f32
)( const struct gl_texture_image
*texImage
,
501 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
503 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
506 texel
[BCOMP
] = src
[0];
507 texel
[ACOMP
] = src
[1];
511 static void store_texel_luminance_alpha_f32(struct gl_texture_image
*texImage
,
512 GLint i
, GLint j
, GLint k
, const void *texel
)
514 const GLfloat
*rgba
= (const GLfloat
*) texel
;
515 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 2);
516 dst
[0] = rgba
[RCOMP
];
517 dst
[1] = rgba
[ACOMP
];
522 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
524 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
525 * returning 4 GLfloats.
527 static void FETCH(f_luminance_alpha_f16
)( const struct gl_texture_image
*texImage
,
528 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
530 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
533 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
534 texel
[ACOMP
] = _mesa_half_to_float(src
[1]);
538 static void store_texel_luminance_alpha_f16(struct gl_texture_image
*texImage
,
539 GLint i
, GLint j
, GLint k
, const void *texel
)
541 const GLfloat
*rgba
= (const GLfloat
*) texel
;
542 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 2);
543 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
544 dst
[1] = _mesa_float_to_half(rgba
[ACOMP
]);
549 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
551 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
552 * returning 4 GLfloats.
554 static void FETCH(f_intensity_f32
)( const struct gl_texture_image
*texImage
,
555 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
557 const GLfloat
*src
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
561 texel
[ACOMP
] = src
[0];
565 static void store_texel_intensity_f32(struct gl_texture_image
*texImage
,
566 GLint i
, GLint j
, GLint k
, const void *texel
)
568 const GLfloat
*rgba
= (const GLfloat
*) texel
;
569 GLfloat
*dst
= TEXEL_ADDR(GLfloat
, texImage
, i
, j
, k
, 1);
570 dst
[0] = rgba
[RCOMP
];
575 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
577 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
578 * returning 4 GLfloats.
580 static void FETCH(f_intensity_f16
)( const struct gl_texture_image
*texImage
,
581 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
583 const GLhalfARB
*src
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
587 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
591 static void store_texel_intensity_f16(struct gl_texture_image
*texImage
,
592 GLint i
, GLint j
, GLint k
, const void *texel
)
594 const GLfloat
*rgba
= (const GLfloat
*) texel
;
595 GLhalfARB
*dst
= TEXEL_ADDR(GLhalfARB
, texImage
, i
, j
, k
, 1);
596 dst
[0] = _mesa_float_to_half(rgba
[RCOMP
]);
604 * Begin Hardware formats
607 /* MESA_FORMAT_RGBA8888 ******************************************************/
609 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
610 static void FETCH(rgba8888
)( const struct gl_texture_image
*texImage
,
611 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
613 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
614 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
615 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
616 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
617 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
621 static void store_texel_rgba8888(struct gl_texture_image
*texImage
,
622 GLint i
, GLint j
, GLint k
, const void *texel
)
624 const GLubyte
*rgba
= (const GLubyte
*) texel
;
625 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
626 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
631 /* MESA_FORMAT_RGBA888_REV ***************************************************/
633 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
634 static void FETCH(rgba8888_rev
)( const struct gl_texture_image
*texImage
,
635 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
637 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
638 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
639 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
640 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
641 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
645 static void store_texel_rgba8888_rev(struct gl_texture_image
*texImage
,
646 GLint i
, GLint j
, GLint k
, const void *texel
)
648 const GLubyte
*rgba
= (const GLubyte
*) texel
;
649 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
650 *dst
= PACK_COLOR_8888_REV(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
655 /* MESA_FORMAT_ARGB8888 ******************************************************/
657 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
658 static void FETCH(argb8888
)( const struct gl_texture_image
*texImage
,
659 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
661 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
662 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
663 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
664 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
665 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
669 static void store_texel_argb8888(struct gl_texture_image
*texImage
,
670 GLint i
, GLint j
, GLint k
, const void *texel
)
672 const GLubyte
*rgba
= (const GLubyte
*) texel
;
673 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
674 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
679 /* MESA_FORMAT_ARGB8888_REV **************************************************/
681 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLchans */
682 static void FETCH(argb8888_rev
)( const struct gl_texture_image
*texImage
,
683 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
685 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
686 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
687 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
688 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
689 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
693 static void store_texel_argb8888_rev(struct gl_texture_image
*texImage
,
694 GLint i
, GLint j
, GLint k
, const void *texel
)
696 const GLubyte
*rgba
= (const GLubyte
*) texel
;
697 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
698 *dst
= PACK_COLOR_8888(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
], rgba
[ACOMP
]);
703 /* MESA_FORMAT_RGB888 ********************************************************/
705 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
706 static void FETCH(rgb888
)( const struct gl_texture_image
*texImage
,
707 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
709 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
710 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
711 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
712 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
713 texel
[ACOMP
] = CHAN_MAX
;
717 static void store_texel_rgb888(struct gl_texture_image
*texImage
,
718 GLint i
, GLint j
, GLint k
, const void *texel
)
720 const GLubyte
*rgba
= (const GLubyte
*) texel
;
721 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
722 dst
[0] = rgba
[RCOMP
];
723 dst
[1] = rgba
[GCOMP
];
724 dst
[2] = rgba
[BCOMP
];
729 /* MESA_FORMAT_BGR888 ********************************************************/
731 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
732 static void FETCH(bgr888
)( const struct gl_texture_image
*texImage
,
733 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
735 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
736 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[0] );
737 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
738 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[2] );
739 texel
[ACOMP
] = CHAN_MAX
;
743 static void store_texel_bgr888(struct gl_texture_image
*texImage
,
744 GLint i
, GLint j
, GLint k
, const void *texel
)
746 const GLubyte
*rgba
= (const GLubyte
*) texel
;
747 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
748 dst
[0] = rgba
[BCOMP
];
749 dst
[1] = rgba
[GCOMP
];
750 dst
[2] = rgba
[RCOMP
];
755 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
756 instead of slow (g << 2) * 255 / 252 (always rounds down) */
758 /* MESA_FORMAT_RGB565 ********************************************************/
760 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
761 static void FETCH(rgb565
)( const struct gl_texture_image
*texImage
,
762 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
764 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
765 const GLushort s
= *src
;
766 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
767 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
768 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
769 texel
[ACOMP
] = CHAN_MAX
;
773 static void store_texel_rgb565(struct gl_texture_image
*texImage
,
774 GLint i
, GLint j
, GLint k
, const void *texel
)
776 const GLubyte
*rgba
= (const GLubyte
*) texel
;
777 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
778 *dst
= PACK_COLOR_565(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
783 /* MESA_FORMAT_RGB565_REV ****************************************************/
785 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
786 static void FETCH(rgb565_rev
)( const struct gl_texture_image
*texImage
,
787 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
789 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
790 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
791 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
792 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
793 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
794 texel
[ACOMP
] = CHAN_MAX
;
798 static void store_texel_rgb565_rev(struct gl_texture_image
*texImage
,
799 GLint i
, GLint j
, GLint k
, const void *texel
)
801 const GLubyte
*rgba
= (const GLubyte
*) texel
;
802 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
803 *dst
= PACK_COLOR_565(rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
807 /* MESA_FORMAT_RGBA4444 ******************************************************/
809 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
810 static void FETCH(rgba4444
)( 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
>> 12) & 0xf) | ((s
>> 8) & 0xf0) );
816 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) | ((s
>> 4) & 0xf0) );
817 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) | ((s
) & 0xf0) );
818 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) | ((s
<< 4) & 0xf0) );
822 static void store_texel_rgba4444(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 ******************************************************/
834 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
835 static void FETCH(argb4444
)( const struct gl_texture_image
*texImage
,
836 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
838 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
839 const GLushort s
= *src
;
840 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) | ((s
>> 4) & 0xf0) );
841 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) | ((s
) & 0xf0) );
842 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) | ((s
<< 4) & 0xf0) );
843 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) | ((s
>> 8) & 0xf0) );
847 static void store_texel_argb4444(struct gl_texture_image
*texImage
,
848 GLint i
, GLint j
, GLint k
, const void *texel
)
850 const GLubyte
*rgba
= (const GLubyte
*) texel
;
851 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
852 *dst
= PACK_COLOR_4444(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
857 /* MESA_FORMAT_ARGB4444_REV **************************************************/
859 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
860 static void FETCH(argb4444_rev
)( const struct gl_texture_image
*texImage
,
861 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
863 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
864 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) | ((s
<< 4) & 0xf0) );
865 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) | ((s
>> 8) & 0xf0) );
866 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) | ((s
>> 4) & 0xf0) );
867 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) | ((s
) & 0xf0) );
871 static void store_texel_argb4444_rev(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_4444(rgba
[ACOMP
], rgba
[BCOMP
], rgba
[GCOMP
], rgba
[RCOMP
]);
880 /* MESA_FORMAT_RGBA5551 ******************************************************/
882 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
883 static void FETCH(rgba5551
)( const struct gl_texture_image
*texImage
,
884 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
886 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
887 const GLushort s
= *src
;
888 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
889 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xf8) | ((s
>> 8) & 0x7) );
890 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 2) & 0xf8) | ((s
>> 3) & 0x7) );
891 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
) & 0x01) ? 255 : 0);
895 static void store_texel_rgba5551(struct gl_texture_image
*texImage
,
896 GLint i
, GLint j
, GLint k
, const void *texel
)
898 const GLubyte
*rgba
= (const GLubyte
*) texel
;
899 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
900 *dst
= PACK_COLOR_5551(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
904 /* MESA_FORMAT_ARGB1555 ******************************************************/
906 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
907 static void FETCH(argb1555
)( const struct gl_texture_image
*texImage
,
908 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
910 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
911 const GLushort s
= *src
;
912 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
913 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
914 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
915 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
919 static void store_texel_argb1555(struct gl_texture_image
*texImage
,
920 GLint i
, GLint j
, GLint k
, const void *texel
)
922 const GLubyte
*rgba
= (const GLubyte
*) texel
;
923 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
924 *dst
= PACK_COLOR_1555(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
929 /* MESA_FORMAT_ARGB1555_REV **************************************************/
931 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
932 static void FETCH(argb1555_rev
)( const struct gl_texture_image
*texImage
,
933 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
935 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
936 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
937 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
938 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
939 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
940 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
944 static void store_texel_argb1555_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_1555_REV(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
954 /* MESA_FORMAT_AL88 **********************************************************/
956 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
957 static void FETCH(al88
)( const struct gl_texture_image
*texImage
,
958 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
960 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
963 texel
[BCOMP
] = UBYTE_TO_CHAN( s
& 0xff );
964 texel
[ACOMP
] = UBYTE_TO_CHAN( s
>> 8 );
968 static void store_texel_al88(struct gl_texture_image
*texImage
,
969 GLint i
, GLint j
, GLint k
, const void *texel
)
971 const GLubyte
*rgba
= (const GLubyte
*) texel
;
972 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
973 *dst
= PACK_COLOR_88(rgba
[ACOMP
], rgba
[RCOMP
]);
978 /* MESA_FORMAT_AL88_REV ******************************************************/
980 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
981 static void FETCH(al88_rev
)( const struct gl_texture_image
*texImage
,
982 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
984 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
987 texel
[BCOMP
] = UBYTE_TO_CHAN( s
>> 8 );
988 texel
[ACOMP
] = UBYTE_TO_CHAN( s
& 0xff );
992 static void store_texel_al88_rev(struct gl_texture_image
*texImage
,
993 GLint i
, GLint j
, GLint k
, const void *texel
)
995 const GLubyte
*rgba
= (const GLubyte
*) texel
;
996 GLushort
*dst
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
997 *dst
= PACK_COLOR_88(rgba
[RCOMP
], rgba
[ACOMP
]);
1002 /* MESA_FORMAT_RGB332 ********************************************************/
1004 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1005 static void FETCH(rgb332
)( const struct gl_texture_image
*texImage
,
1006 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1008 static const GLubyte lut2to8
[4] = {0, 85, 170, 255};
1009 static const GLubyte lut3to8
[8] = {0, 36, 73, 109, 146, 182, 219, 255};
1010 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1011 const GLubyte s
= *src
;
1012 texel
[RCOMP
] = UBYTE_TO_CHAN( lut3to8
[(s
>> 5) & 0x7] );
1013 texel
[GCOMP
] = UBYTE_TO_CHAN( lut3to8
[(s
>> 2) & 0x7] );
1014 texel
[BCOMP
] = UBYTE_TO_CHAN( lut2to8
[(s
) & 0x3] );
1015 texel
[ACOMP
] = CHAN_MAX
;
1019 static void store_texel_rgb332(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);
1024 *dst
= PACK_COLOR_332(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1029 /* MESA_FORMAT_A8 ************************************************************/
1031 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1032 static void FETCH(a8
)( 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_a8(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_L8 ************************************************************/
1055 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1056 static void FETCH(l8
)( const struct gl_texture_image
*texImage
,
1057 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1059 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1062 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
1063 texel
[ACOMP
] = CHAN_MAX
;
1067 static void store_texel_l8(struct gl_texture_image
*texImage
,
1068 GLint i
, GLint j
, GLint k
, const void *texel
)
1070 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1071 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1077 /* MESA_FORMAT_I8 ************************************************************/
1079 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1080 static void FETCH(i8
)( const struct gl_texture_image
*texImage
,
1081 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1083 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1087 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
1091 static void store_texel_i8(struct gl_texture_image
*texImage
,
1092 GLint i
, GLint j
, GLint k
, const void *texel
)
1094 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1095 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1101 /* MESA_FORMAT_CI8 ***********************************************************/
1103 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1104 * color table, and return 4 GLchans.
1106 static void FETCH(ci8
)( const struct gl_texture_image
*texImage
,
1107 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1109 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1110 const struct gl_color_table
*palette
;
1113 GET_CURRENT_CONTEXT(ctx
);
1115 if (ctx
->Texture
.SharedPalette
) {
1116 palette
= &ctx
->Texture
.Palette
;
1119 palette
= &texImage
->TexObject
->Palette
;
1121 if (palette
->Size
== 0)
1122 return; /* undefined results */
1124 /* Mask the index against size of palette to avoid going out of bounds */
1125 index
= (*src
) & (palette
->Size
- 1);
1128 const GLubyte
*table
= palette
->TableUB
;
1129 switch (palette
->_BaseFormat
) {
1134 texelUB
[ACOMP
] = table
[index
];
1139 texelUB
[BCOMP
] = table
[index
];
1140 texelUB
[ACOMP
] = 255;
1146 texelUB
[ACOMP
] = table
[index
];
1148 case GL_LUMINANCE_ALPHA
:
1151 texelUB
[BCOMP
] = table
[index
* 2 + 0];
1152 texelUB
[ACOMP
] = table
[index
* 2 + 1];
1155 texelUB
[RCOMP
] = table
[index
* 3 + 0];
1156 texelUB
[GCOMP
] = table
[index
* 3 + 1];
1157 texelUB
[BCOMP
] = table
[index
* 3 + 2];
1158 texelUB
[ACOMP
] = 255;
1161 texelUB
[RCOMP
] = table
[index
* 4 + 0];
1162 texelUB
[GCOMP
] = table
[index
* 4 + 1];
1163 texelUB
[BCOMP
] = table
[index
* 4 + 2];
1164 texelUB
[ACOMP
] = table
[index
* 4 + 3];
1167 _mesa_problem(ctx
, "Bad palette format in fetch_texel_ci8");
1170 #if CHAN_TYPE == GL_UNSIGNED_BYTE
1171 COPY_4UBV(texel
, texelUB
);
1172 #elif CHAN_TYPE == GL_UNSIGNED_SHORT
1173 texel
[0] = UBYTE_TO_USHORT(texelUB
[0]);
1174 texel
[1] = UBYTE_TO_USHORT(texelUB
[1]);
1175 texel
[2] = UBYTE_TO_USHORT(texelUB
[2]);
1176 texel
[3] = UBYTE_TO_USHORT(texelUB
[3]);
1178 texel
[0] = UBYTE_TO_FLOAT(texelUB
[0]);
1179 texel
[1] = UBYTE_TO_FLOAT(texelUB
[1]);
1180 texel
[2] = UBYTE_TO_FLOAT(texelUB
[2]);
1181 texel
[3] = UBYTE_TO_FLOAT(texelUB
[3]);
1187 static void store_texel_ci8(struct gl_texture_image
*texImage
,
1188 GLint i
, GLint j
, GLint k
, const void *texel
)
1190 const GLubyte
*index
= (const GLubyte
*) texel
;
1191 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1197 #if FEATURE_EXT_texture_sRGB
1199 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1200 static void FETCH(srgb8
)(const struct gl_texture_image
*texImage
,
1201 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1203 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1204 texel
[RCOMP
] = nonlinear_to_linear(src
[0]);
1205 texel
[GCOMP
] = nonlinear_to_linear(src
[1]);
1206 texel
[BCOMP
] = nonlinear_to_linear(src
[2]);
1207 texel
[ACOMP
] = CHAN_MAX
;
1211 static void store_texel_srgb8(struct gl_texture_image
*texImage
,
1212 GLint i
, GLint j
, GLint k
, const void *texel
)
1214 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1215 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
1216 dst
[0] = rgba
[RCOMP
]; /* no conversion */
1217 dst
[1] = rgba
[GCOMP
];
1218 dst
[2] = rgba
[BCOMP
];
1222 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1223 static void FETCH(srgba8
)(const struct gl_texture_image
*texImage
,
1224 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1226 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1227 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 24) );
1228 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1229 texel
[BCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1230 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff ); /* linear! */
1234 static void store_texel_srgba8(struct gl_texture_image
*texImage
,
1235 GLint i
, GLint j
, GLint k
, const void *texel
)
1237 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1238 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1239 *dst
= PACK_COLOR_8888(rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
], rgba
[ACOMP
]);
1243 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1244 static void FETCH(sargb8
)(const struct gl_texture_image
*texImage
,
1245 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1247 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1248 texel
[RCOMP
] = nonlinear_to_linear( (s
>> 16) & 0xff );
1249 texel
[GCOMP
] = nonlinear_to_linear( (s
>> 8) & 0xff );
1250 texel
[BCOMP
] = nonlinear_to_linear( (s
) & 0xff );
1251 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) ); /* linear! */
1255 static void store_texel_sargb8(struct gl_texture_image
*texImage
,
1256 GLint i
, GLint j
, GLint k
, const void *texel
)
1258 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1259 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1260 *dst
= PACK_COLOR_8888(rgba
[ACOMP
], rgba
[RCOMP
], rgba
[GCOMP
], rgba
[BCOMP
]);
1264 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1265 static void FETCH(sl8
)(const struct gl_texture_image
*texImage
,
1266 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1268 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1271 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1272 texel
[ACOMP
] = CHAN_MAX
;
1276 static void store_texel_sl8(struct gl_texture_image
*texImage
,
1277 GLint i
, GLint j
, GLint k
, const void *texel
)
1279 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1280 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
1281 dst
[0] = rgba
[RCOMP
];
1285 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1286 static void FETCH(sla8
)(const struct gl_texture_image
*texImage
,
1287 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1289 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1292 texel
[BCOMP
] = nonlinear_to_linear(src
[0]);
1293 texel
[ACOMP
] = UBYTE_TO_FLOAT(src
[1]); /* linear */
1297 static void store_texel_sla8(struct gl_texture_image
*texImage
,
1298 GLint i
, GLint j
, GLint k
, const void *texel
)
1300 const GLubyte
*rgba
= (const GLubyte
*) texel
;
1301 GLubyte
*dst
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 2);
1302 dst
[0] = rgba
[RCOMP
];
1303 dst
[1] = rgba
[ACOMP
];
1309 #endif /* FEATURE_EXT_texture_sRGB */
1313 /* MESA_FORMAT_YCBCR *********************************************************/
1315 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
1316 /* We convert YCbCr to RGB here */
1317 /* XXX this may break if GLchan != GLubyte */
1318 static void FETCH(ycbcr
)( const struct gl_texture_image
*texImage
,
1319 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1321 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1322 const GLushort
*src1
= src0
+ 1; /* odd */
1323 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1324 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1325 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1326 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1329 /* odd pixel: use y1,cr,cb */
1330 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
1331 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1332 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
1335 /* even pixel: use y0,cr,cb */
1336 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
1337 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1338 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
1340 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
1341 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
1342 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
1343 texel
[ACOMP
] = CHAN_MAX
;
1347 static void store_texel_ycbcr(struct gl_texture_image
*texImage
,
1348 GLint i
, GLint j
, GLint k
, const void *texel
)
1360 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1362 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
1363 /* We convert YCbCr to RGB here */
1364 /* XXX this may break if GLchan != GLubyte */
1365 static void FETCH(ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1366 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1368 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
1369 const GLushort
*src1
= src0
+ 1; /* odd */
1370 const GLubyte y0
= *src0
& 0xff; /* luminance */
1371 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1372 const GLubyte y1
= *src1
& 0xff; /* luminance */
1373 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1376 /* odd pixel: use y1,cr,cb */
1377 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
1378 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1379 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
1382 /* even pixel: use y0,cr,cb */
1383 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
1384 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1385 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
1387 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
1388 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
1389 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
1390 texel
[ACOMP
] = CHAN_MAX
;
1394 static void store_texel_ycbcr_rev(struct gl_texture_image
*texImage
,
1395 GLint i
, GLint j
, GLint k
, const void *texel
)
1407 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1409 static void FETCH(f_z24_s8
)( const struct gl_texture_image
*texImage
,
1410 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1412 /* only return Z, not stencil data */
1413 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1414 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
1415 texel
[0] = ((*src
) >> 8) * scale
;
1416 ASSERT(texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_Z24_S8
);
1417 ASSERT(texel
[0] >= 0.0F
);
1418 ASSERT(texel
[0] <= 1.0F
);
1422 static void store_texel_z24_s8(struct gl_texture_image
*texImage
,
1423 GLint i
, GLint j
, GLint k
, const void *texel
)
1425 /* only store Z, not stencil */
1426 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1427 GLfloat depth
= *((GLfloat
*) texel
);
1428 GLuint zi
= ((GLuint
) (depth
* 0xffffff)) << 8;
1429 *dst
= zi
| (*dst
& 0xff);
1434 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1436 static void FETCH(f_s8_z24
)( const struct gl_texture_image
*texImage
,
1437 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1439 /* only return Z, not stencil data */
1440 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1441 const GLfloat scale
= 1.0F
/ (GLfloat
) 0xffffff;
1442 texel
[0] = ((*src
) & 0x00ffffff) * scale
;
1443 ASSERT(texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_S8_Z24
);
1444 ASSERT(texel
[0] >= 0.0F
);
1445 ASSERT(texel
[0] <= 1.0F
);
1449 static void store_texel_s8_z24(struct gl_texture_image
*texImage
,
1450 GLint i
, GLint j
, GLint k
, const void *texel
)
1452 /* only store Z, not stencil */
1453 GLuint
*dst
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
1454 GLfloat depth
= *((GLfloat
*) texel
);
1455 GLuint zi
= (GLuint
) (depth
* 0xffffff);
1456 *dst
= zi
| (*dst
& 0xff000000);