2 * \file texformat_tmp.h
3 * Texel fetch functions template.
5 * This template file is used by texformat.c to generate texel fetch functions
6 * for 1-D, 2-D and 3-D texture images.
8 * It should be expanded by definining \p DIM as the number texture dimensions
9 * (1, 2 or 3). According to the value of \p DIM a serie of macros is defined
10 * for the texel lookup in the gl_texture_image::Data.
12 * \sa texformat.c and FetchTexel.
14 * \author Gareth Hughes
19 * Mesa 3-D graphics library
22 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
24 * Permission is hereby granted, free of charge, to any person obtaining a
25 * copy of this software and associated documentation files (the "Software"),
26 * to deal in the Software without restriction, including without limitation
27 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
28 * and/or sell copies of the Software, and to permit persons to whom the
29 * Software is furnished to do so, subject to the following conditions:
31 * The above copyright notice and this permission notice shall be included
32 * in all copies or substantial portions of the Software.
34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
35 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
37 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
38 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45 #define CHAN_SRC( t, i, j, k, sz ) \
46 ((GLchan *)(t)->Data + (i) * (sz))
47 #define UBYTE_SRC( t, i, j, k, sz ) \
48 ((GLubyte *)(t)->Data + (i) * (sz))
49 #define USHORT_SRC( t, i, j, k ) \
50 ((GLushort *)(t)->Data + (i))
51 #define FLOAT_SRC( t, i, j, k, sz ) \
52 ((GLfloat *)(t)->Data + (i) * (sz))
53 #define HALF_SRC( t, i, j, k, sz ) \
54 ((GLhalfNV *)(t)->Data + (i) * (sz))
56 #define FETCH(x) fetch_texel_1d_##x
60 #define CHAN_SRC( t, i, j, k, sz ) \
61 ((GLchan *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
62 #define UBYTE_SRC( t, i, j, k, sz ) \
63 ((GLubyte *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
64 #define USHORT_SRC( t, i, j, k ) \
65 ((GLushort *)(t)->Data + ((t)->RowStride * (j) + (i)))
66 #define FLOAT_SRC( t, i, j, k, sz ) \
67 ((GLfloat *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
68 #define HALF_SRC( t, i, j, k, sz ) \
69 ((GLhalfNV *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
71 #define FETCH(x) fetch_texel_2d_##x
75 #define CHAN_SRC( t, i, j, k, sz ) \
76 (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \
77 (t)->RowStride + (i)) * (sz)
78 #define UBYTE_SRC( t, i, j, k, sz ) \
79 ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \
80 (t)->RowStride + (i)) * (sz))
81 #define USHORT_SRC( t, i, j, k ) \
82 ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \
83 (t)->RowStride + (i)))
84 #define FLOAT_SRC( t, i, j, k, sz ) \
85 ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \
86 (t)->RowStride + (i)) * (sz))
87 #define HALF_SRC( t, i, j, k, sz ) \
88 ((GLhalfNV *)(t)->Data + (((t)->Height * (k) + (j)) * \
89 (t)->RowStride + (i)) * (sz))
91 #define FETCH(x) fetch_texel_3d_##x
94 #error illegal number of texture dimensions
98 /* Fetch color texel from 1D, 2D or 3D RGBA texture, returning 4 GLchans */
99 static void FETCH(rgba
)( const struct gl_texture_image
*texImage
,
100 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
102 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 4 );
103 COPY_CHAN4( texel
, src
);
106 /* Fetch color texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
107 static void FETCH(f_rgba
)( const struct gl_texture_image
*texImage
,
108 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
110 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 4 );
111 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
112 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
113 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
114 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[3]);
118 /* Fetch color texel from 1D, 2D or 3D RGB texture, returning 4 GLchans */
119 static void FETCH(rgb
)( const struct gl_texture_image
*texImage
,
120 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
122 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 3 );
123 texel
[RCOMP
] = src
[0];
124 texel
[GCOMP
] = src
[1];
125 texel
[BCOMP
] = src
[2];
126 texel
[ACOMP
] = CHAN_MAX
;
129 /* Fetch color texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
130 static void FETCH(f_rgb
)( const struct gl_texture_image
*texImage
,
131 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
133 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 3 );
134 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
135 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
136 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
137 texel
[ACOMP
] = CHAN_MAXF
;
140 /* Fetch color texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
141 static void FETCH(alpha
)( const struct gl_texture_image
*texImage
,
142 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
144 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
148 texel
[ACOMP
] = src
[0];
151 /* Fetch color texel from 1D, 2D or 3D ALPHA texture, returning 4 GLfloats */
152 static void FETCH(f_alpha
)( const struct gl_texture_image
*texImage
,
153 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
155 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
159 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[0]);
162 /* Fetch color texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
163 static void FETCH(luminance
)( const struct gl_texture_image
*texImage
,
164 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
166 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
169 texel
[BCOMP
] = src
[0];
170 texel
[ACOMP
] = CHAN_MAX
;
173 /* Fetch color texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
174 static void FETCH(f_luminance
)( const struct gl_texture_image
*texImage
,
175 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
177 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
180 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[0]);
181 texel
[ACOMP
] = CHAN_MAXF
;
184 /* Fetch color texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
185 static void FETCH(luminance_alpha
)( const struct gl_texture_image
*texImage
,
186 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
188 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 2 );
189 texel
[RCOMP
] = src
[0];
190 texel
[GCOMP
] = src
[0];
191 texel
[BCOMP
] = src
[0];
192 texel
[ACOMP
] = src
[1];
195 /* Fetch color texel from 1D, 2D or 3D L_A texture, returning 4 GLfloats */
196 static void FETCH(f_luminance_alpha
)( const struct gl_texture_image
*texImage
,
197 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
199 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 2 );
202 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[0]);
203 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[1]);
207 /* Fetch color texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
208 static void FETCH(intensity
)( const struct gl_texture_image
*texImage
,
209 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
211 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
212 texel
[RCOMP
] = src
[0];
213 texel
[GCOMP
] = src
[0];
214 texel
[BCOMP
] = src
[0];
215 texel
[ACOMP
] = src
[0];
218 /* Fetch color texel from 1D, 2D or 3D INT. texture, returning 4 GLfloats */
219 static void FETCH(f_intensity
)( const struct gl_texture_image
*texImage
,
220 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
222 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
226 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[0]);
230 /* Fetch CI texel from 1D, 2D or 3D CI texture, returning 1 GLchan */
231 static void FETCH(color_index
)( const struct gl_texture_image
*texImage
,
232 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
234 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
238 /* Fetch CI texel from 1D, 2D or 3D CI texture, returning 1 GLfloat */
239 static void FETCH(f_color_index
)( const struct gl_texture_image
*texImage
,
240 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
242 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
243 texel
[0] = (GLfloat
) src
[0];
247 /* Fetch depth texel from 1D, 2D or 3D DEPTH texture, returning 1 GLfloat */
248 /* Note: no GLchan version of this function */
249 static void FETCH(f_depth_component
)( const struct gl_texture_image
*texImage
,
250 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
252 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
257 /* Fetch color texel from 1D, 2D or 3D RGBA_FLOAT32 texture,
258 * returning 4 GLfloats.
260 static void FETCH(f_rgba_f32
)( const struct gl_texture_image
*texImage
,
261 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
263 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 4 );
264 texel
[RCOMP
] = src
[0];
265 texel
[GCOMP
] = src
[1];
266 texel
[BCOMP
] = src
[2];
267 texel
[ACOMP
] = src
[3];
270 /* Fetch color texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
271 * returning 4 GLfloats.
273 static void FETCH(f_rgba_f16
)( const struct gl_texture_image
*texImage
,
274 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
276 const GLhalfNV
*src
= HALF_SRC( texImage
, i
, j
, k
, 4 );
277 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
278 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
279 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
280 texel
[ACOMP
] = _mesa_half_to_float(src
[3]);
284 /* Fetch color texel from 1D, 2D or 3D RGB_FLOAT32 texture,
285 * returning 4 GLfloats.
287 static void FETCH(f_rgb_f32
)( const struct gl_texture_image
*texImage
,
288 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
290 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 3 );
291 texel
[RCOMP
] = src
[0];
292 texel
[GCOMP
] = src
[1];
293 texel
[BCOMP
] = src
[2];
294 texel
[ACOMP
] = CHAN_MAXF
;
297 /* Fetch color texel from 1D, 2D or 3D RGB_FLOAT16 texture,
298 * returning 4 GLfloats.
300 static void FETCH(f_rgb_f16
)( const struct gl_texture_image
*texImage
,
301 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
303 const GLhalfNV
*src
= HALF_SRC( texImage
, i
, j
, k
, 3 );
304 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
305 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
306 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
307 texel
[ACOMP
] = CHAN_MAXF
;
313 * Begin Hardware formats
316 /* Fetch color texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
317 static void FETCH(rgba8888
)( const struct gl_texture_image
*texImage
,
318 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
320 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
321 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[3] );
322 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[2] );
323 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[1] );
324 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
327 /* Fetch color texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
328 static void FETCH(f_rgba8888
)( const struct gl_texture_image
*texImage
,
329 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
331 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
332 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[3] );
333 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[2] );
334 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[1] );
335 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
339 /* Fetch color texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
340 static void FETCH(argb8888
)( const struct gl_texture_image
*texImage
,
341 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
343 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
344 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
345 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
346 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
347 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[3] );
350 /* Fetch color texel from 1D, 2D or 3D argb8888 texture, return 4 GLfloats */
351 static void FETCH(f_argb8888
)( const struct gl_texture_image
*texImage
,
352 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
354 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
355 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
356 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
357 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
358 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[3] );
362 /* Fetch color texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
363 static void FETCH(rgb888
)( const struct gl_texture_image
*texImage
,
364 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
366 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 3 );
367 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
368 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
369 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
370 texel
[ACOMP
] = CHAN_MAX
;
373 /* Fetch color texel from 1D, 2D or 3D rgb888 texture, return 4 GLfloats */
374 static void FETCH(f_rgb888
)( const struct gl_texture_image
*texImage
,
375 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
377 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 3 );
378 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
379 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
380 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
381 texel
[ACOMP
] = CHAN_MAXF
;
385 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
386 static void FETCH(rgb565
)( const struct gl_texture_image
*texImage
,
387 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
389 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
390 const GLushort s
= *src
;
391 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) * 255 / 0xf8 );
392 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) * 255 / 0xfc );
393 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) * 255 / 0xf8 );
394 texel
[ACOMP
] = CHAN_MAX
;
397 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
398 static void FETCH(f_rgb565
)( const struct gl_texture_image
*texImage
,
399 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
401 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
402 const GLushort s
= *src
;
403 texel
[RCOMP
] = ((s
>> 8) & 0xf8) * (1.0F
/ 248.0F
);
404 texel
[GCOMP
] = ((s
>> 3) & 0xfc) * (1.0F
/ 252.0F
);
405 texel
[BCOMP
] = ((s
<< 3) & 0xf8) * (1.0F
/ 248.0F
);
406 texel
[ACOMP
] = CHAN_MAXF
;
410 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
411 static void FETCH(argb4444
)( const struct gl_texture_image
*texImage
,
412 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
414 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
415 const GLushort s
= *src
;
416 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) * 255 / 0xf );
417 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) * 255 / 0xf );
418 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) * 255 / 0xf );
419 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) * 255 / 0xf );
422 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
423 static void FETCH(f_argb4444
)( const struct gl_texture_image
*texImage
,
424 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
426 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
427 const GLushort s
= *src
;
428 texel
[RCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
429 texel
[GCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
430 texel
[BCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
431 texel
[ACOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
435 /* Fetch color texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
436 static void FETCH(argb1555
)( const struct gl_texture_image
*texImage
,
437 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
439 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
440 const GLushort s
= *src
;
441 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 10) & 0x1f) * 255 / 0x1f );
442 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 5) & 0x1f) * 255 / 0x1f );
443 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0x1f) * 255 / 0x1f );
444 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
447 /* Fetch color texel from 1D, 2D or 3D argb1555 texture, return 4 GLfloats */
448 static void FETCH(f_argb1555
)( const struct gl_texture_image
*texImage
,
449 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
451 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
452 const GLushort s
= *src
;
453 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
454 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
455 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
456 texel
[ACOMP
] = ((s
>> 15) & 0x01);
460 /* Fetch color texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
461 static void FETCH(al88
)( const struct gl_texture_image
*texImage
,
462 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
464 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 2 );
467 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
468 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[1] );
471 /* Fetch color texel from 1D, 2D or 3D al88 texture, return 4 GLfloats */
472 static void FETCH(f_al88
)( const struct gl_texture_image
*texImage
,
473 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
475 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 2 );
478 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
479 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[1] );
483 /* Fetch color texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
484 static void FETCH(rgb332
)( const struct gl_texture_image
*texImage
,
485 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
487 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
488 const GLubyte s
= *src
;
489 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xe0) * 255 / 0xe0 );
490 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xe0) * 255 / 0xe0 );
491 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 5) & 0xc0) * 255 / 0xc0 );
492 texel
[ACOMP
] = CHAN_MAX
;
495 /* Fetch color texel from 1D, 2D or 3D rgb332 texture, return 4 GLfloats */
496 static void FETCH(f_rgb332
)( const struct gl_texture_image
*texImage
,
497 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
499 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
500 const GLubyte s
= *src
;
501 texel
[RCOMP
] = ((s
) & 0xe0) * (1.0F
/ 224.0F
);
502 texel
[GCOMP
] = ((s
<< 3) & 0xe0) * (1.0F
/ 224.0F
);
503 texel
[BCOMP
] = ((s
<< 5) & 0xc0) * (1.0F
/ 192.0F
);
504 texel
[ACOMP
] = CHAN_MAXF
;
508 /* Fetch color texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
509 static void FETCH(a8
)( const struct gl_texture_image
*texImage
,
510 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
512 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
516 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
519 /* Fetch color texel from 1D, 2D or 3D a8 texture, return 4 GLfloats */
520 static void FETCH(f_a8
)( const struct gl_texture_image
*texImage
,
521 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
523 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
527 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
531 /* Fetch color texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
532 static void FETCH(l8
)( const struct gl_texture_image
*texImage
,
533 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
535 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
536 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[0] );
537 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[0] );
538 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
539 texel
[ACOMP
] = CHAN_MAX
;
542 /* Fetch color texel from 1D, 2D or 3D l8 texture, return 4 GLfloats */
543 static void FETCH(f_l8
)( const struct gl_texture_image
*texImage
,
544 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
546 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
549 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
550 texel
[ACOMP
] = CHAN_MAXF
;
554 /* Fetch color texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
555 static void FETCH(i8
)( const struct gl_texture_image
*texImage
,
556 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
558 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
559 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[0] );
560 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[0] );
561 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
562 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
565 /* Fetch color texel from 1D, 2D or 3D i8 texture, return 4 GLfloats */
566 static void FETCH(f_i8
)( const struct gl_texture_image
*texImage
,
567 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
569 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
573 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
577 /* Fetch color texel from 1D, 2D or 3D ci8 texture, return 1 GLchan */
578 static void FETCH(ci8
)( const struct gl_texture_image
*texImage
,
579 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
581 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
582 GLchan
*index
= (GLchan
*) texel
;
583 *index
= UBYTE_TO_CHAN( *src
);
587 /* Fetch color texel from 1D, 2D or 3D ci8 texture, return 1 GLfloat */
588 static void FETCH(f_ci8
)( const struct gl_texture_image
*texImage
,
589 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
591 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
592 texel
[0] = UBYTE_TO_FLOAT( *src
);
596 /* Fetch color texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
597 /* We convert YCbCr to RGB here */
598 /* XXX this may break if GLchan != GLubyte */
599 static void FETCH(ycbcr
)( const struct gl_texture_image
*texImage
,
600 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
602 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
603 const GLushort
*src1
= src0
+ 1; /* odd */
604 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
605 const GLubyte cb
= *src0
& 0xff; /* chroma U */
606 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
607 const GLubyte cr
= *src1
& 0xff; /* chroma V */
610 /* odd pixel: use y1,cr,cb */
611 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
612 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
613 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
616 /* even pixel: use y0,cr,cb */
617 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
618 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
619 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
621 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
622 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
623 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
624 texel
[ACOMP
] = CHAN_MAX
;
627 /* Fetch color texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats */
628 /* We convert YCbCr to RGB here */
629 static void FETCH(f_ycbcr
)( const struct gl_texture_image
*texImage
,
630 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
632 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
633 const GLushort
*src1
= src0
+ 1; /* odd */
634 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
635 const GLubyte cb
= *src0
& 0xff; /* chroma U */
636 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
637 const GLubyte cr
= *src1
& 0xff; /* chroma V */
640 /* odd pixel: use y1,cr,cb */
641 r
= (1.164 * (y1
-16) + 1.596 * (cr
-128));
642 g
= (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
643 b
= (1.164 * (y1
-16) + 2.018 * (cb
-128));
646 /* even pixel: use y0,cr,cb */
647 r
= (1.164 * (y0
-16) + 1.596 * (cr
-128));
648 g
= (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
649 b
= (1.164 * (y0
-16) + 2.018 * (cb
-128));
651 /* XXX remove / 255 here by tweaking arithmetic above */
655 /* XXX should we really clamp??? */
656 texel
[RCOMP
] = CLAMP(r
, 0.0, 1.0);
657 texel
[GCOMP
] = CLAMP(g
, 0.0, 1.0);
658 texel
[BCOMP
] = CLAMP(b
, 0.0, 1.0);
659 texel
[ACOMP
] = CHAN_MAXF
;
663 /* Fetch color texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
664 /* We convert YCbCr to RGB here */
665 /* XXX this may break if GLchan != GLubyte */
666 static void FETCH(ycbcr_rev
)( const struct gl_texture_image
*texImage
,
667 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
669 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
670 const GLushort
*src1
= src0
+ 1; /* odd */
671 const GLubyte y0
= *src0
& 0xff; /* luminance */
672 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
673 const GLubyte y1
= *src1
& 0xff; /* luminance */
674 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
677 /* odd pixel: use y1,cr,cb */
678 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
679 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
680 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
683 /* even pixel: use y0,cr,cb */
684 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
685 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
686 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
688 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
689 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
690 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
691 texel
[ACOMP
] = CHAN_MAX
;
694 /* Fetch color texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats */
695 /* We convert YCbCr to RGB here */
696 static void FETCH(f_ycbcr_rev
)( const struct gl_texture_image
*texImage
,
697 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
699 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
700 const GLushort
*src1
= src0
+ 1; /* odd */
701 const GLubyte y0
= *src0
& 0xff; /* luminance */
702 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
703 const GLubyte y1
= *src1
& 0xff; /* luminance */
704 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
707 /* odd pixel: use y1,cr,cb */
708 r
= (1.164 * (y1
-16) + 1.596 * (cr
-128));
709 g
= (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
710 b
= (1.164 * (y1
-16) + 2.018 * (cb
-128));
713 /* even pixel: use y0,cr,cb */
714 r
= (1.164 * (y0
-16) + 1.596 * (cr
-128));
715 g
= (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
716 b
= (1.164 * (y0
-16) + 2.018 * (cb
-128));
718 /* XXX remove / 255 here by tweaking arithmetic above */
722 /* XXX should we really clamp??? */
723 texel
[RCOMP
] = CLAMP(r
, 0.0, 1.0);
724 texel
[GCOMP
] = CLAMP(g
, 0.0, 1.0);
725 texel
[BCOMP
] = CLAMP(b
, 0.0, 1.0);
726 texel
[ACOMP
] = CHAN_MAXF
;
730 #if DIM == 2 /* Only 2D compressed textures possible */
732 static void FETCH(rgb_fxt1
)( const struct gl_texture_image
*texImage
,
733 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
735 /* Extract the (i,j) pixel from texImage->Data and return it
736 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
740 static void FETCH(f_rgb_fxt1
)( const struct gl_texture_image
*texImage
,
741 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
743 /* Extract the (i,j) pixel from texImage->Data and return it
744 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
748 static void FETCH(rgba_fxt1
)( const struct gl_texture_image
*texImage
,
749 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
751 /* Extract the (i,j) pixel from texImage->Data and return it
752 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
756 static void FETCH(f_rgba_fxt1
)( const struct gl_texture_image
*texImage
,
757 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
759 /* Extract the (i,j) pixel from texImage->Data and return it
760 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
764 #endif /* if DIM == 2 */
767 #if DIM == 2 /* only 2D is valid */
769 static void FETCH(rgb_dxt1
)( const struct gl_texture_image
*texImage
,
770 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
772 /* Extract the (i,j) pixel from texImage->Data and return it
773 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
777 static void FETCH(f_rgb_dxt1
)( const struct gl_texture_image
*texImage
,
778 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
780 /* Extract the (i,j) pixel from texImage->Data and return it
781 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
786 static void FETCH(rgba_dxt1
)( const struct gl_texture_image
*texImage
,
787 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
789 /* Extract the (i,j) pixel from texImage->Data and return it
790 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
794 static void FETCH(f_rgba_dxt1
)( const struct gl_texture_image
*texImage
,
795 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
797 /* Extract the (i,j) pixel from texImage->Data and return it
798 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
803 static void FETCH(rgba_dxt3
)( const struct gl_texture_image
*texImage
,
804 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
806 /* Extract the (i,j) pixel from texImage->Data and return it
807 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
811 static void FETCH(f_rgba_dxt3
)( const struct gl_texture_image
*texImage
,
812 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
814 /* Extract the (i,j) pixel from texImage->Data and return it
815 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
820 static void FETCH(rgba_dxt5
)( const struct gl_texture_image
*texImage
,
821 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
823 /* Extract the (i,j) pixel from texImage->Data and return it
824 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
828 static void FETCH(f_rgba_dxt5
)( const struct gl_texture_image
*texImage
,
829 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
831 /* Extract the (i,j) pixel from texImage->Data and return it
832 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
843 static void FETCH(abgr8888
)( const struct gl_texture_image
*texImage
,
844 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
846 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
847 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[3] );
848 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[2] );
849 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[1] );
850 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
853 static void FETCH(bgra8888
)( const struct gl_texture_image
*texImage
,
854 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
856 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
857 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
858 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
859 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
860 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[3] );
863 static void FETCH(bgr888
)( const struct gl_texture_image
*texImage
,
864 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
866 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 3 );
867 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
868 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
869 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
870 texel
[ACOMP
] = CHAN_MAX
;
873 static void FETCH(bgr565
)( const struct gl_texture_image
*texImage
,
874 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
876 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
877 const GLushort s
= *src
;
878 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) * 255 / 0xf8 );
879 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) * 255 / 0xfc );
880 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) * 255 / 0xf8 );
881 texel
[ACOMP
] = CHAN_MAX
;
884 static void FETCH(bgra4444
)( const struct gl_texture_image
*texImage
,
885 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
887 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
888 const GLushort s
= *src
;
889 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) * 255 / 0xf );
890 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) * 255 / 0xf );
891 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) * 255 / 0xf );
892 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) * 255 / 0xf );
895 static void FETCH(bgra5551
)( const struct gl_texture_image
*texImage
,
896 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
898 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
899 const GLushort s
= *src
;
900 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 10) & 0x1f) * 255 / 0x1f );
901 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 5) & 0x1f) * 255 / 0x1f );
902 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0x1f) * 255 / 0x1f );
903 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
906 static void FETCH(la88
)( const struct gl_texture_image
*texImage
,
907 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
909 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 2 );
910 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[0] );
911 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[0] );
912 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
913 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[1] );
916 static void FETCH(bgr233
)( const struct gl_texture_image
*texImage
,
917 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
919 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
920 const GLubyte s
= *src
;
921 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xe0) * 255 / 0xe0 );
922 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xe0) * 255 / 0xe0 );
923 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 5) & 0xc0) * 255 / 0xc0 );
924 texel
[ACOMP
] = CHAN_MAX
;