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 ) \
52 ((GLfloat *)(t)->Data + (i))
54 #define FETCH(x) fetch_texel_1d_##x
58 #define CHAN_SRC( t, i, j, k, sz ) \
59 ((GLchan *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
60 #define UBYTE_SRC( t, i, j, k, sz ) \
61 ((GLubyte *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
62 #define USHORT_SRC( t, i, j, k ) \
63 ((GLushort *)(t)->Data + ((t)->RowStride * (j) + (i)))
64 #define FLOAT_SRC( t, i, j, k ) \
65 ((GLfloat *)(t)->Data + ((t)->RowStride * (j) + (i)))
67 #define FETCH(x) fetch_texel_2d_##x
71 #define CHAN_SRC( t, i, j, k, sz ) \
72 (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \
73 (t)->RowStride + (i)) * (sz)
74 #define UBYTE_SRC( t, i, j, k, sz ) \
75 ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \
76 (t)->RowStride + (i)) * (sz))
77 #define USHORT_SRC( t, i, j, k ) \
78 ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \
79 (t)->RowStride + (i)))
80 #define FLOAT_SRC( t, i, j, k ) \
81 ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \
82 (t)->RowStride + (i)))
84 #define FETCH(x) fetch_texel_3d_##x
87 #error illegal number of texture dimensions
91 /* Fetch color texel from 1D, 2D or 3D RGBA texture, returning 4 GLchans */
92 static void FETCH(rgba
)( const struct gl_texture_image
*texImage
,
93 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
95 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 4 );
96 COPY_CHAN4( texel
, src
);
99 /* Fetch color texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
100 static void FETCH(f_rgba
)( const struct gl_texture_image
*texImage
,
101 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
103 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 4 );
104 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
105 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
106 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
107 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[3]);
111 /* Fetch color texel from 1D, 2D or 3D RGB texture, returning 4 GLchans */
112 static void FETCH(rgb
)( const struct gl_texture_image
*texImage
,
113 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
115 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 3 );
116 texel
[RCOMP
] = src
[0];
117 texel
[GCOMP
] = src
[1];
118 texel
[BCOMP
] = src
[2];
119 texel
[ACOMP
] = CHAN_MAX
;
122 /* Fetch color texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
123 static void FETCH(f_rgb
)( const struct gl_texture_image
*texImage
,
124 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
126 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 3 );
127 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
128 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
129 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
130 texel
[ACOMP
] = CHAN_MAXF
;
133 /* Fetch color texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
134 static void FETCH(alpha
)( const struct gl_texture_image
*texImage
,
135 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
137 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
141 texel
[ACOMP
] = src
[0];
144 /* Fetch color texel from 1D, 2D or 3D ALPHA texture, returning 4 GLfloats */
145 static void FETCH(f_alpha
)( const struct gl_texture_image
*texImage
,
146 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
148 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
152 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[0]);
155 /* Fetch color texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
156 static void FETCH(luminance
)( const struct gl_texture_image
*texImage
,
157 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
159 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
162 texel
[BCOMP
] = src
[0];
163 texel
[ACOMP
] = CHAN_MAX
;
166 /* Fetch color texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
167 static void FETCH(f_luminance
)( const struct gl_texture_image
*texImage
,
168 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
170 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
173 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[0]);
174 texel
[ACOMP
] = CHAN_MAXF
;
177 /* Fetch color texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
178 static void FETCH(luminance_alpha
)( const struct gl_texture_image
*texImage
,
179 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
181 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 2 );
182 texel
[RCOMP
] = src
[0];
183 texel
[GCOMP
] = src
[0];
184 texel
[BCOMP
] = src
[0];
185 texel
[ACOMP
] = src
[1];
188 /* Fetch color texel from 1D, 2D or 3D L_A texture, returning 4 GLfloats */
189 static void FETCH(f_luminance_alpha
)( const struct gl_texture_image
*texImage
,
190 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
192 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 2 );
195 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[0]);
196 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[1]);
200 /* Fetch color texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
201 static void FETCH(intensity
)( const struct gl_texture_image
*texImage
,
202 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
204 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
205 texel
[RCOMP
] = src
[0];
206 texel
[GCOMP
] = src
[0];
207 texel
[BCOMP
] = src
[0];
208 texel
[ACOMP
] = src
[0];
211 /* Fetch color texel from 1D, 2D or 3D INT. texture, returning 4 GLfloats */
212 static void FETCH(f_intensity
)( const struct gl_texture_image
*texImage
,
213 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
215 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
219 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[0]);
223 /* Fetch CI texel from 1D, 2D or 3D CI texture, returning 1 GLchan */
224 static void FETCH(color_index
)( const struct gl_texture_image
*texImage
,
225 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
227 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
228 GLchan
*index
= (GLchan
*) texel
;
232 /* Fetch CI texel from 1D, 2D or 3D CI texture, returning 1 GLfloat */
233 static void FETCH(f_color_index
)( const struct gl_texture_image
*texImage
,
234 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
236 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
237 texel
[0] = (GLfloat
) src
[0];
242 /* Fetch depth texel from 1D, 2D or 3D DEPTH texture, returning 1 GLfloat */
243 static void FETCH(depth_component
)( const struct gl_texture_image
*texImage
,
244 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
247 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
);
248 GLfloat
*depth
= (GLfloat
*) texel
;
251 _mesa_problem(NULL
, "fetching depth component as non-float!");
257 /* Fetch depth texel from 1D, 2D or 3D DEPTH texture, returning 1 GLfloat */
258 static void FETCH(f_depth_component
)( const struct gl_texture_image
*texImage
,
259 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
261 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
);
266 /* Fetch color texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
267 static void FETCH(rgba8888
)( const struct gl_texture_image
*texImage
,
268 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
270 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
271 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[3] );
272 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[2] );
273 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[1] );
274 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
277 /* Fetch color texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
278 static void FETCH(f_rgba8888
)( const struct gl_texture_image
*texImage
,
279 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
281 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
282 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[3] );
283 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[2] );
284 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[1] );
285 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
289 /* Fetch color texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
290 static void FETCH(argb8888
)( const struct gl_texture_image
*texImage
,
291 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
293 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
294 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
295 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
296 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
297 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[3] );
300 /* Fetch color texel from 1D, 2D or 3D argb8888 texture, return 4 GLfloats */
301 static void FETCH(f_argb8888
)( const struct gl_texture_image
*texImage
,
302 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
304 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
305 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
306 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
307 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
308 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[3] );
312 /* Fetch color texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
313 static void FETCH(rgb888
)( const struct gl_texture_image
*texImage
,
314 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
316 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 3 );
317 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
318 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
319 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
320 texel
[ACOMP
] = CHAN_MAX
;
323 /* Fetch color texel from 1D, 2D or 3D rgb888 texture, return 4 GLfloats */
324 static void FETCH(f_rgb888
)( const struct gl_texture_image
*texImage
,
325 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
327 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 3 );
328 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
329 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
330 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
331 texel
[ACOMP
] = CHAN_MAXF
;
335 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
336 static void FETCH(rgb565
)( const struct gl_texture_image
*texImage
,
337 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
339 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
340 const GLushort s
= *src
;
341 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) * 255 / 0xf8 );
342 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) * 255 / 0xfc );
343 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) * 255 / 0xf8 );
344 texel
[ACOMP
] = CHAN_MAX
;
347 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
348 static void FETCH(f_rgb565
)( const struct gl_texture_image
*texImage
,
349 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
351 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
352 const GLushort s
= *src
;
354 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 8) & 0xf8) * 255 / 0xf8 );
355 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 3) & 0xfc) * 255 / 0xfc );
356 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) * 255 / 0xf8 );
357 texel
[ACOMP
] = CHAN_MAXF
;
361 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
362 static void FETCH(argb4444
)( const struct gl_texture_image
*texImage
,
363 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
365 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
366 const GLushort s
= *src
;
367 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) * 255 / 0xf );
368 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) * 255 / 0xf );
369 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) * 255 / 0xf );
370 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) * 255 / 0xf );
373 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
374 static void FETCH(f_argb4444
)( const struct gl_texture_image
*texImage
,
375 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
377 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
378 const GLushort s
= *src
;
380 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 8) & 0xf) * 255 / 0xf );
381 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 4) & 0xf) * 255 / 0xf );
382 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
) & 0xf) * 255 / 0xf );
383 texel
[ACOMP
] = UBYTE_TO_FLOAT( ((s
>> 12) & 0xf) * 255 / 0xf );
387 /* Fetch color texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
388 static void FETCH(argb1555
)( const struct gl_texture_image
*texImage
,
389 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
391 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
392 const GLushort s
= *src
;
393 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 10) & 0x1f) * 255 / 0x1f );
394 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 5) & 0x1f) * 255 / 0x1f );
395 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0x1f) * 255 / 0x1f );
396 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
399 /* Fetch color texel from 1D, 2D or 3D argb1555 texture, return 4 GLfloats */
400 static void FETCH(f_argb1555
)( const struct gl_texture_image
*texImage
,
401 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
403 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
404 const GLushort s
= *src
;
406 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 10) & 0x1f) * 255 / 0x1f );
407 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 5) & 0x1f) * 255 / 0x1f );
408 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
) & 0x1f) * 255 / 0x1f );
409 texel
[ACOMP
] = UBYTE_TO_FLOAT( ((s
>> 15) & 0x01) * 255 );
413 /* Fetch color texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
414 static void FETCH(al88
)( const struct gl_texture_image
*texImage
,
415 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
417 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 2 );
420 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
421 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[1] );
424 /* Fetch color texel from 1D, 2D or 3D al88 texture, return 4 GLfloats */
425 static void FETCH(f_al88
)( const struct gl_texture_image
*texImage
,
426 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
428 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 2 );
431 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
432 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[1] );
436 /* Fetch color texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
437 static void FETCH(rgb332
)( const struct gl_texture_image
*texImage
,
438 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
440 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
441 const GLubyte s
= *src
;
442 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xe0) * 255 / 0xe0 );
443 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xe0) * 255 / 0xe0 );
444 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 5) & 0xc0) * 255 / 0xc0 );
445 texel
[ACOMP
] = CHAN_MAX
;
448 /* Fetch color texel from 1D, 2D or 3D rgb332 texture, return 4 GLfloats */
449 static void FETCH(f_rgb332
)( const struct gl_texture_image
*texImage
,
450 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
452 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
453 const GLubyte s
= *src
;
455 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
) & 0xe0) * 255 / 0xe0 );
456 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xe0) * 255 / 0xe0 );
457 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 5) & 0xc0) * 255 / 0xc0 );
458 texel
[ACOMP
] = CHAN_MAXF
;
462 /* Fetch color texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
463 static void FETCH(a8
)( const struct gl_texture_image
*texImage
,
464 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
466 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
470 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
473 /* Fetch color texel from 1D, 2D or 3D a8 texture, return 4 GLfloats */
474 static void FETCH(f_a8
)( const struct gl_texture_image
*texImage
,
475 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
477 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
481 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
485 /* Fetch color texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
486 static void FETCH(l8
)( const struct gl_texture_image
*texImage
,
487 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
489 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
490 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[0] );
491 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[0] );
492 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
493 texel
[ACOMP
] = CHAN_MAX
;
496 /* Fetch color texel from 1D, 2D or 3D l8 texture, return 4 GLfloats */
497 static void FETCH(f_l8
)( const struct gl_texture_image
*texImage
,
498 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
500 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
503 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
504 texel
[ACOMP
] = CHAN_MAXF
;
508 /* Fetch color texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
509 static void FETCH(i8
)( 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 );
513 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[0] );
514 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[0] );
515 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
516 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
519 /* Fetch color texel from 1D, 2D or 3D i8 texture, return 4 GLfloats */
520 static void FETCH(f_i8
)( 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 ci8 texture, return 1 GLchan */
532 static void FETCH(ci8
)( 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 GLchan
*index
= (GLchan
*) texel
;
537 *index
= UBYTE_TO_CHAN( *src
);
541 /* Fetch color texel from 1D, 2D or 3D ci8 texture, return 1 GLfloat */
542 static void FETCH(f_ci8
)( const struct gl_texture_image
*texImage
,
543 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
545 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
546 texel
[0] = UBYTE_TO_FLOAT( *src
);
550 /* Fetch color texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
551 /* We convert YCbCr to RGB here */
552 /* XXX this may break if GLchan != GLubyte */
553 static void FETCH(ycbcr
)( const struct gl_texture_image
*texImage
,
554 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
556 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
557 const GLushort
*src1
= src0
+ 1; /* odd */
558 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
559 const GLubyte cb
= *src0
& 0xff; /* chroma U */
560 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
561 const GLubyte cr
= *src1
& 0xff; /* chroma V */
564 /* odd pixel: use y1,cr,cb */
565 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
566 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
567 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
570 /* even pixel: use y0,cr,cb */
571 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
572 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
573 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
575 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
576 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
577 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
578 texel
[ACOMP
] = CHAN_MAX
;
581 /* Fetch color texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats */
582 /* We convert YCbCr to RGB here */
583 static void FETCH(f_ycbcr
)( const struct gl_texture_image
*texImage
,
584 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
586 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
587 const GLushort
*src1
= src0
+ 1; /* odd */
588 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
589 const GLubyte cb
= *src0
& 0xff; /* chroma U */
590 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
591 const GLubyte cr
= *src1
& 0xff; /* chroma V */
594 /* odd pixel: use y1,cr,cb */
595 r
= (1.164 * (y1
-16) + 1.596 * (cr
-128));
596 g
= (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
597 b
= (1.164 * (y1
-16) + 2.018 * (cb
-128));
600 /* even pixel: use y0,cr,cb */
601 r
= (1.164 * (y0
-16) + 1.596 * (cr
-128));
602 g
= (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
603 b
= (1.164 * (y0
-16) + 2.018 * (cb
-128));
605 /* XXX remove / 255 here by tweaking arithmetic above */
609 /* XXX should we really clamp??? */
610 texel
[RCOMP
] = CLAMP(r
, 0.0, 1.0);
611 texel
[GCOMP
] = CLAMP(g
, 0.0, 1.0);
612 texel
[BCOMP
] = CLAMP(b
, 0.0, 1.0);
613 texel
[ACOMP
] = CHAN_MAXF
;
617 /* Fetch color texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
618 /* We convert YCbCr to RGB here */
619 /* XXX this may break if GLchan != GLubyte */
620 static void FETCH(ycbcr_rev
)( const struct gl_texture_image
*texImage
,
621 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
623 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
624 const GLushort
*src1
= src0
+ 1; /* odd */
625 const GLubyte y0
= *src0
& 0xff; /* luminance */
626 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
627 const GLubyte y1
= *src1
& 0xff; /* luminance */
628 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
631 /* odd pixel: use y1,cr,cb */
632 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
633 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
634 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
637 /* even pixel: use y0,cr,cb */
638 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
639 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
640 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
642 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
643 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
644 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
645 texel
[ACOMP
] = CHAN_MAX
;
648 /* Fetch color texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats */
649 /* We convert YCbCr to RGB here */
650 /* XXX this may break if GLchan != GLubyte */
651 static void FETCH(f_ycbcr_rev
)( const struct gl_texture_image
*texImage
,
652 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
654 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
655 const GLushort
*src1
= src0
+ 1; /* odd */
656 const GLubyte y0
= *src0
& 0xff; /* luminance */
657 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
658 const GLubyte y1
= *src1
& 0xff; /* luminance */
659 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
662 /* odd pixel: use y1,cr,cb */
663 r
= (1.164 * (y1
-16) + 1.596 * (cr
-128));
664 g
= (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
665 b
= (1.164 * (y1
-16) + 2.018 * (cb
-128));
668 /* even pixel: use y0,cr,cb */
669 r
= (1.164 * (y0
-16) + 1.596 * (cr
-128));
670 g
= (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
671 b
= (1.164 * (y0
-16) + 2.018 * (cb
-128));
673 /* XXX remove / 255 here by tweaking arithmetic above */
677 /* XXX should we really clamp??? */
678 texel
[RCOMP
] = CLAMP(r
, 0.0, 1.0);
679 texel
[GCOMP
] = CLAMP(g
, 0.0, 1.0);
680 texel
[BCOMP
] = CLAMP(b
, 0.0, 1.0);
681 texel
[ACOMP
] = CHAN_MAXF
;
685 #if DIM == 2 /* Only 2D compressed textures possible */
687 static void FETCH(rgb_fxt1
)( const struct gl_texture_image
*texImage
,
688 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
690 /* Extract the (i,j) pixel from texImage->Data and return it
691 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
695 static void FETCH(f_rgb_fxt1
)( const struct gl_texture_image
*texImage
,
696 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
698 /* Extract the (i,j) pixel from texImage->Data and return it
699 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
703 static void FETCH(rgba_fxt1
)( const struct gl_texture_image
*texImage
,
704 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
706 /* Extract the (i,j) pixel from texImage->Data and return it
707 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
711 static void FETCH(f_rgba_fxt1
)( const struct gl_texture_image
*texImage
,
712 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
714 /* Extract the (i,j) pixel from texImage->Data and return it
715 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
719 #endif /* if DIM == 2 */
722 #if DIM == 2 /* only 2D is valid */
724 static void FETCH(rgb_dxt1
)( const struct gl_texture_image
*texImage
,
725 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
727 /* Extract the (i,j) pixel from texImage->Data and return it
728 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
732 static void FETCH(f_rgb_dxt1
)( const struct gl_texture_image
*texImage
,
733 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
735 /* Extract the (i,j) pixel from texImage->Data and return it
736 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
741 static void FETCH(rgba_dxt1
)( const struct gl_texture_image
*texImage
,
742 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
744 /* Extract the (i,j) pixel from texImage->Data and return it
745 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
749 static void FETCH(f_rgba_dxt1
)( const struct gl_texture_image
*texImage
,
750 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
752 /* Extract the (i,j) pixel from texImage->Data and return it
753 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
758 static void FETCH(rgba_dxt3
)( const struct gl_texture_image
*texImage
,
759 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
761 /* Extract the (i,j) pixel from texImage->Data and return it
762 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
766 static void FETCH(f_rgba_dxt3
)( const struct gl_texture_image
*texImage
,
767 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
769 /* Extract the (i,j) pixel from texImage->Data and return it
770 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
775 static void FETCH(rgba_dxt5
)( const struct gl_texture_image
*texImage
,
776 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
778 /* Extract the (i,j) pixel from texImage->Data and return it
779 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
783 static void FETCH(f_rgba_dxt5
)( const struct gl_texture_image
*texImage
,
784 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
786 /* Extract the (i,j) pixel from texImage->Data and return it
787 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
798 static void FETCH(abgr8888
)( const struct gl_texture_image
*texImage
,
799 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
801 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
802 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[3] );
803 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[2] );
804 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[1] );
805 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
808 static void FETCH(bgra8888
)( const struct gl_texture_image
*texImage
,
809 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
811 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
812 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
813 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
814 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
815 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[3] );
818 static void FETCH(bgr888
)( const struct gl_texture_image
*texImage
,
819 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
821 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 3 );
822 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
823 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
824 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
825 texel
[ACOMP
] = CHAN_MAX
;
828 static void FETCH(bgr565
)( const struct gl_texture_image
*texImage
,
829 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
831 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
832 const GLushort s
= *src
;
833 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) * 255 / 0xf8 );
834 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) * 255 / 0xfc );
835 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) * 255 / 0xf8 );
836 texel
[ACOMP
] = CHAN_MAX
;
839 static void FETCH(bgra4444
)( const struct gl_texture_image
*texImage
,
840 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
842 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
843 const GLushort s
= *src
;
844 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) * 255 / 0xf );
845 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) * 255 / 0xf );
846 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) * 255 / 0xf );
847 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) * 255 / 0xf );
850 static void FETCH(bgra5551
)( const struct gl_texture_image
*texImage
,
851 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
853 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
854 const GLushort s
= *src
;
855 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 10) & 0x1f) * 255 / 0x1f );
856 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 5) & 0x1f) * 255 / 0x1f );
857 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0x1f) * 255 / 0x1f );
858 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
861 static void FETCH(la88
)( const struct gl_texture_image
*texImage
,
862 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
864 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 2 );
865 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[0] );
866 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[0] );
867 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
868 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[1] );
871 static void FETCH(bgr233
)( const struct gl_texture_image
*texImage
,
872 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
874 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
875 const GLubyte s
= *src
;
876 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xe0) * 255 / 0xe0 );
877 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xe0) * 255 / 0xe0 );
878 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 5) & 0xc0) * 255 / 0xc0 );
879 texel
[ACOMP
] = CHAN_MAX
;