2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * \file texformat_tmp.h
28 * Texel fetch functions template.
30 * This template file is used by texformat.c to generate texel fetch functions
31 * for 1-D, 2-D and 3-D texture images.
33 * It should be expanded by defining \p DIM as the number texture dimensions
34 * (1, 2 or 3). According to the value of \p DIM a series of macros is defined
35 * for the texel lookup in the gl_texture_image::Data.
37 * \sa texformat.c and FetchTexel.
39 * \author Gareth Hughes
46 #define CHAN_SRC( t, i, j, k, sz ) \
47 ((GLchan *)(t)->Data + (i) * (sz))
48 #define UBYTE_SRC( t, i, j, k, sz ) \
49 ((GLubyte *)(t)->Data + (i) * (sz))
50 #define USHORT_SRC( t, i, j, k ) \
51 ((GLushort *)(t)->Data + (i))
52 #define FLOAT_SRC( t, i, j, k, sz ) \
53 ((GLfloat *)(t)->Data + (i) * (sz))
54 #define HALF_SRC( t, i, j, k, sz ) \
55 ((GLhalfARB *)(t)->Data + (i) * (sz))
57 #define FETCH(x) fetch_texel_1d_##x
61 #define CHAN_SRC( t, i, j, k, sz ) \
62 ((GLchan *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
63 #define UBYTE_SRC( t, i, j, k, sz ) \
64 ((GLubyte *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
65 #define USHORT_SRC( t, i, j, k ) \
66 ((GLushort *)(t)->Data + ((t)->RowStride * (j) + (i)))
67 #define FLOAT_SRC( t, i, j, k, sz ) \
68 ((GLfloat *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
69 #define HALF_SRC( t, i, j, k, sz ) \
70 ((GLhalfARB *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
72 #define FETCH(x) fetch_texel_2d_##x
76 #define CHAN_SRC( t, i, j, k, sz ) \
77 (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \
78 (t)->RowStride + (i)) * (sz)
79 #define UBYTE_SRC( t, i, j, k, sz ) \
80 ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \
81 (t)->RowStride + (i)) * (sz))
82 #define USHORT_SRC( t, i, j, k ) \
83 ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \
84 (t)->RowStride + (i)))
85 #define FLOAT_SRC( t, i, j, k, sz ) \
86 ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \
87 (t)->RowStride + (i)) * (sz))
88 #define HALF_SRC( t, i, j, k, sz ) \
89 ((GLhalfARB *)(t)->Data + (((t)->Height * (k) + (j)) * \
90 (t)->RowStride + (i)) * (sz))
92 #define FETCH(x) fetch_texel_3d_##x
95 #error illegal number of texture dimensions
99 /* Fetch color texel from 1D, 2D or 3D RGBA texture, returning 4 GLchans */
100 static void FETCH(rgba
)( const struct gl_texture_image
*texImage
,
101 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
103 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 4 );
104 COPY_CHAN4( texel
, src
);
107 /* Fetch color texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
108 static void FETCH(f_rgba
)( const struct gl_texture_image
*texImage
,
109 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
111 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 4 );
112 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
113 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
114 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
115 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[3]);
119 /* Fetch color texel from 1D, 2D or 3D RGB texture, returning 4 GLchans */
120 static void FETCH(rgb
)( const struct gl_texture_image
*texImage
,
121 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
123 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 3 );
124 texel
[RCOMP
] = src
[0];
125 texel
[GCOMP
] = src
[1];
126 texel
[BCOMP
] = src
[2];
127 texel
[ACOMP
] = CHAN_MAX
;
130 /* Fetch color texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
131 static void FETCH(f_rgb
)( const struct gl_texture_image
*texImage
,
132 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
134 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 3 );
135 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
136 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
137 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
138 texel
[ACOMP
] = CHAN_MAXF
;
141 /* Fetch color texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
142 static void FETCH(alpha
)( const struct gl_texture_image
*texImage
,
143 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
145 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
149 texel
[ACOMP
] = src
[0];
152 /* Fetch color texel from 1D, 2D or 3D ALPHA texture, returning 4 GLfloats */
153 static void FETCH(f_alpha
)( const struct gl_texture_image
*texImage
,
154 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
156 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
160 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[0]);
163 /* Fetch color texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
164 static void FETCH(luminance
)( const struct gl_texture_image
*texImage
,
165 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
167 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
170 texel
[BCOMP
] = src
[0];
171 texel
[ACOMP
] = CHAN_MAX
;
174 /* Fetch color texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
175 static void FETCH(f_luminance
)( const struct gl_texture_image
*texImage
,
176 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
178 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
181 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[0]);
182 texel
[ACOMP
] = CHAN_MAXF
;
185 /* Fetch color texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
186 static void FETCH(luminance_alpha
)( const struct gl_texture_image
*texImage
,
187 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
189 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 2 );
190 texel
[RCOMP
] = src
[0];
191 texel
[GCOMP
] = src
[0];
192 texel
[BCOMP
] = src
[0];
193 texel
[ACOMP
] = src
[1];
196 /* Fetch color texel from 1D, 2D or 3D L_A texture, returning 4 GLfloats */
197 static void FETCH(f_luminance_alpha
)( const struct gl_texture_image
*texImage
,
198 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
200 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 2 );
203 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[0]);
204 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[1]);
208 /* Fetch color texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
209 static void FETCH(intensity
)( const struct gl_texture_image
*texImage
,
210 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
212 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
213 texel
[RCOMP
] = src
[0];
214 texel
[GCOMP
] = src
[0];
215 texel
[BCOMP
] = src
[0];
216 texel
[ACOMP
] = src
[0];
219 /* Fetch color texel from 1D, 2D or 3D INT. texture, returning 4 GLfloats */
220 static void FETCH(f_intensity
)( const struct gl_texture_image
*texImage
,
221 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
223 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
227 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[0]);
231 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
232 * returning 1 GLfloat.
233 * Note: no GLchan version of this function.
235 static void FETCH(f_depth_component_f32
)( const struct gl_texture_image
*texImage
,
236 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
238 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
243 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
244 * returning 1 GLfloat.
245 * Note: no GLchan version of this function.
247 static void FETCH(f_depth_component16
)( const struct gl_texture_image
*texImage
,
248 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
250 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
251 texel
[0] = src
[0] * (1.0F
/ 65535.0F
);
255 /* Fetch color texel from 1D, 2D or 3D RGBA_FLOAT32 texture,
256 * returning 4 GLchans.
258 static void FETCH(rgba_f32
)( const struct gl_texture_image
*texImage
,
259 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
261 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 4 );
262 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
263 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], src
[1]);
264 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], src
[2]);
265 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], src
[3]);
268 /* Fetch color texel from 1D, 2D or 3D RGBA_FLOAT32 texture,
269 * returning 4 GLfloats.
271 static void FETCH(f_rgba_f32
)( const struct gl_texture_image
*texImage
,
272 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
274 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 4 );
275 texel
[RCOMP
] = src
[0];
276 texel
[GCOMP
] = src
[1];
277 texel
[BCOMP
] = src
[2];
278 texel
[ACOMP
] = src
[3];
281 /* Fetch color texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
282 * returning 4 GLchans.
284 static void FETCH(rgba_f16
)( const struct gl_texture_image
*texImage
,
285 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
287 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 4 );
288 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
289 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], _mesa_half_to_float(src
[1]));
290 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], _mesa_half_to_float(src
[2]));
291 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], _mesa_half_to_float(src
[3]));
294 /* Fetch color texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
295 * returning 4 GLfloats.
297 static void FETCH(f_rgba_f16
)( const struct gl_texture_image
*texImage
,
298 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
300 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 4 );
301 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
302 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
303 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
304 texel
[ACOMP
] = _mesa_half_to_float(src
[3]);
307 /* Fetch color texel from 1D, 2D or 3D RGB_FLOAT32 texture,
308 * returning 4 GLchans.
310 static void FETCH(rgb_f32
)( const struct gl_texture_image
*texImage
,
311 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
313 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 3 );
314 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
315 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], src
[1]);
316 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], src
[2]);
317 texel
[ACOMP
] = CHAN_MAX
;
320 /* Fetch color texel from 1D, 2D or 3D RGB_FLOAT32 texture,
321 * returning 4 GLfloats.
323 static void FETCH(f_rgb_f32
)( const struct gl_texture_image
*texImage
,
324 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
326 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 3 );
327 texel
[RCOMP
] = src
[0];
328 texel
[GCOMP
] = src
[1];
329 texel
[BCOMP
] = src
[2];
330 texel
[ACOMP
] = CHAN_MAXF
;
333 /* Fetch color texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
334 * returning 4 GLchans.
336 static void FETCH(rgb_f16
)( const struct gl_texture_image
*texImage
,
337 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
339 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 3 );
340 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
341 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], _mesa_half_to_float(src
[1]));
342 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], _mesa_half_to_float(src
[2]));
343 texel
[ACOMP
] = CHAN_MAX
;
346 /* Fetch color texel from 1D, 2D or 3D RGB_FLOAT16 texture,
347 * returning 4 GLfloats.
349 static void FETCH(f_rgb_f16
)( const struct gl_texture_image
*texImage
,
350 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
352 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 3 );
353 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
354 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
355 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
356 texel
[ACOMP
] = CHAN_MAXF
;
359 /* Fetch color texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
360 * returning 4 GLchans.
362 static void FETCH(alpha_f32
)( const struct gl_texture_image
*texImage
,
363 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
365 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
369 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], src
[0]);
372 /* Fetch color texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
373 * returning 4 GLfloats.
375 static void FETCH(f_alpha_f32
)( const struct gl_texture_image
*texImage
,
376 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
378 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
382 texel
[ACOMP
] = src
[0];
385 /* Fetch color texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
386 * returning 4 GLchans.
388 static void FETCH(alpha_f16
)( const struct gl_texture_image
*texImage
,
389 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
391 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 1 );
395 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], _mesa_half_to_float(src
[0]));
398 /* Fetch color texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
399 * returning 4 GLfloats.
401 static void FETCH(f_alpha_f16
)( const struct gl_texture_image
*texImage
,
402 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
404 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 1 );
408 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
411 /* Fetch color texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
412 * returning 4 GLchans.
414 static void FETCH(luminance_f32
)( const struct gl_texture_image
*texImage
,
415 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
417 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
418 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
420 texel
[BCOMP
] = texel
[RCOMP
];
421 texel
[ACOMP
] = CHAN_MAX
;
424 /* Fetch color texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
425 * returning 4 GLfloats.
427 static void FETCH(f_luminance_f32
)( const struct gl_texture_image
*texImage
,
428 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
430 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
433 texel
[BCOMP
] = src
[0];
434 texel
[ACOMP
] = CHAN_MAXF
;
437 /* Fetch color texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
438 * returning 4 GLchans.
440 static void FETCH(luminance_f16
)( const struct gl_texture_image
*texImage
,
441 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
443 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 1 );
444 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
446 texel
[BCOMP
] = texel
[RCOMP
];
447 texel
[ACOMP
] = CHAN_MAX
;
450 /* Fetch color texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
451 * returning 4 GLfloats.
453 static void FETCH(f_luminance_f16
)( const struct gl_texture_image
*texImage
,
454 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
456 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 1 );
459 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
460 texel
[ACOMP
] = CHAN_MAXF
;
463 /* Fetch color texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
464 * returning 4 GLchans.
466 static void FETCH(luminance_alpha_f32
)( const struct gl_texture_image
*texImage
,
467 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
469 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 2 );
470 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
472 texel
[BCOMP
] = texel
[RCOMP
];
473 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], src
[1]);
476 /* Fetch color texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
477 * returning 4 GLfloats.
479 static void FETCH(f_luminance_alpha_f32
)( const struct gl_texture_image
*texImage
,
480 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
482 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 2 );
485 texel
[BCOMP
] = src
[0];
486 texel
[ACOMP
] = src
[1];
489 /* Fetch color texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
490 * returning 4 GLfloats.
492 static void FETCH(luminance_alpha_f16
)( const struct gl_texture_image
*texImage
,
493 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
495 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 2 );
496 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
498 texel
[BCOMP
] = texel
[RCOMP
];
499 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], _mesa_half_to_float(src
[1]));
502 /* Fetch color texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
503 * returning 4 GLfloats.
505 static void FETCH(f_luminance_alpha_f16
)( const struct gl_texture_image
*texImage
,
506 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
508 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 2 );
511 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
512 texel
[ACOMP
] = _mesa_half_to_float(src
[1]);
515 /* Fetch color texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
516 * returning 4 GLchans.
518 static void FETCH(intensity_f32
)( const struct gl_texture_image
*texImage
,
519 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
521 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
522 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
525 texel
[ACOMP
] = texel
[RCOMP
];
528 /* Fetch color texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
529 * returning 4 GLfloats.
531 static void FETCH(f_intensity_f32
)( const struct gl_texture_image
*texImage
,
532 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
534 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
538 texel
[ACOMP
] = src
[0];
541 /* Fetch color texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
542 * returning 4 GLchans.
544 static void FETCH(intensity_f16
)( const struct gl_texture_image
*texImage
,
545 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
547 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 1 );
548 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
551 texel
[ACOMP
] = texel
[RCOMP
];
554 /* Fetch color texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
555 * returning 4 GLfloats.
557 static void FETCH(f_intensity_f16
)( const struct gl_texture_image
*texImage
,
558 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
560 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 1 );
564 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
570 * Begin Hardware formats
573 /* Fetch color texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
574 static void FETCH(rgba8888
)( const struct gl_texture_image
*texImage
,
575 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
577 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
578 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[3] );
579 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[2] );
580 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[1] );
581 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
584 /* Fetch color texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
585 static void FETCH(f_rgba8888
)( const struct gl_texture_image
*texImage
,
586 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
588 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
589 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[3] );
590 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[2] );
591 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[1] );
592 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
596 /* Fetch color texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
597 static void FETCH(abgr8888
)( const struct gl_texture_image
*texImage
,
598 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
600 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
601 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[0] );
602 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
603 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[2] );
604 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[3] );
607 /* Fetch color texel from 1D, 2D or 3D abgr8888 texture, return 4 GLfloats */
608 static void FETCH(f_abgr8888
)( const struct gl_texture_image
*texImage
,
609 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
611 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
612 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[0] );
613 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
614 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[2] );
615 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[3] );
619 /* Fetch color texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
620 static void FETCH(argb8888
)( const struct gl_texture_image
*texImage
,
621 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
623 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
624 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
625 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
626 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
627 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[3] );
630 /* Fetch color texel from 1D, 2D or 3D argb8888 texture, return 4 GLfloats */
631 static void FETCH(f_argb8888
)( const struct gl_texture_image
*texImage
,
632 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
634 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
635 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
636 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
637 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
638 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[3] );
642 /* Fetch color texel from 1D, 2D or 3D bgra8888 texture, return 4 GLchans */
643 static void FETCH(bgra8888
)( const struct gl_texture_image
*texImage
,
644 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
646 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
647 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[1] );
648 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[2] );
649 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[3] );
650 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
653 /* Fetch color texel from 1D, 2D or 3D bgra8888 texture, return 4 GLfloats */
654 static void FETCH(f_bgra8888
)( const struct gl_texture_image
*texImage
,
655 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
657 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 4 );
658 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[1] );
659 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[2] );
660 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[3] );
661 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
665 /* Fetch color texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
666 static void FETCH(rgb888
)( const struct gl_texture_image
*texImage
,
667 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
669 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 3 );
670 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
671 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
672 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
673 texel
[ACOMP
] = CHAN_MAX
;
676 /* Fetch color texel from 1D, 2D or 3D rgb888 texture, return 4 GLfloats */
677 static void FETCH(f_rgb888
)( const struct gl_texture_image
*texImage
,
678 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
680 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 3 );
681 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
682 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
683 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
684 texel
[ACOMP
] = CHAN_MAXF
;
688 /* Fetch color texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
689 static void FETCH(bgr888
)( const struct gl_texture_image
*texImage
,
690 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
692 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 3 );
693 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[0] );
694 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
695 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[2] );
696 texel
[ACOMP
] = CHAN_MAX
;
699 /* Fetch color texel from 1D, 2D or 3D bgr888 texture, return 4 GLfloats */
700 static void FETCH(f_bgr888
)( const struct gl_texture_image
*texImage
,
701 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
703 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 3 );
704 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[0] );
705 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
706 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[2] );
707 texel
[ACOMP
] = CHAN_MAXF
;
711 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
712 static void FETCH(rgb565
)( const struct gl_texture_image
*texImage
,
713 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
715 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
716 const GLushort s
= *src
;
717 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) * 255 / 0xf8 );
718 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) * 255 / 0xfc );
719 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) * 255 / 0xf8 );
720 texel
[ACOMP
] = CHAN_MAX
;
723 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
724 static void FETCH(f_rgb565
)( const struct gl_texture_image
*texImage
,
725 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
727 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
728 const GLushort s
= *src
;
729 texel
[RCOMP
] = ((s
>> 8) & 0xf8) * (1.0F
/ 248.0F
);
730 texel
[GCOMP
] = ((s
>> 3) & 0xfc) * (1.0F
/ 252.0F
);
731 texel
[BCOMP
] = ((s
<< 3) & 0xf8) * (1.0F
/ 248.0F
);
732 texel
[ACOMP
] = CHAN_MAXF
;
736 /* Fetch color texel from 1D, 2D or 3D bgr565 texture, return 4 GLchans */
737 static void FETCH(bgr565
)( const struct gl_texture_image
*texImage
,
738 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
740 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
741 const GLushort s
= *src
;
742 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) * 255 / 0xf8 );
743 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) * 255 / 0xfc );
744 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) * 255 / 0xf8 );
745 texel
[ACOMP
] = CHAN_MAX
;
748 /* Fetch color texel from 1D, 2D or 3D bgr565 texture, return 4 GLfloats */
749 static void FETCH(f_bgr565
)( const struct gl_texture_image
*texImage
,
750 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
752 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
753 const GLushort s
= *src
;
754 texel
[RCOMP
] = ((s
<< 3) & 0xf8) * (1.0F
/ 248.0F
);
755 texel
[GCOMP
] = ((s
>> 3) & 0xfc) * (1.0F
/ 252.0F
);
756 texel
[BCOMP
] = ((s
>> 8) & 0xf8) * (1.0F
/ 248.0F
);
757 texel
[ACOMP
] = CHAN_MAXF
;
761 /* Fetch color texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
762 static void FETCH(argb4444
)( const struct gl_texture_image
*texImage
,
763 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
765 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
766 const GLushort s
= *src
;
767 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) * 255 / 0xf );
768 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) * 255 / 0xf );
769 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) * 255 / 0xf );
770 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) * 255 / 0xf );
773 /* Fetch color texel from 1D, 2D or 3D argb4444 texture, return 4 GLfloats */
774 static void FETCH(f_argb4444
)( const struct gl_texture_image
*texImage
,
775 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
777 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
778 const GLushort s
= *src
;
779 texel
[RCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
780 texel
[GCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
781 texel
[BCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
782 texel
[ACOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
786 /* Fetch color texel from 1D, 2D or 3D bgra444 texture, return 4 GLchans */
787 static void FETCH(bgra4444
)( const struct gl_texture_image
*texImage
,
788 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
790 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
791 const GLushort s
= *src
;
792 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) * 255 / 0xf );
793 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) * 255 / 0xf );
794 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) * 255 / 0xf );
795 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) * 255 / 0xf );
798 /* Fetch color texel from 1D, 2D or 3D bgra4444 texture, return 4 GLfloats */
799 static void FETCH(f_bgra4444
)( const struct gl_texture_image
*texImage
,
800 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
802 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
803 const GLushort s
= *src
;
804 texel
[RCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
805 texel
[GCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
806 texel
[BCOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
807 texel
[ACOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
811 /* Fetch color texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
812 static void FETCH(argb1555
)( const struct gl_texture_image
*texImage
,
813 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
815 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
816 const GLushort s
= *src
;
817 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 10) & 0x1f) * 255 / 0x1f );
818 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 5) & 0x1f) * 255 / 0x1f );
819 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0x1f) * 255 / 0x1f );
820 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
823 /* Fetch color texel from 1D, 2D or 3D argb1555 texture, return 4 GLfloats */
824 static void FETCH(f_argb1555
)( const struct gl_texture_image
*texImage
,
825 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
827 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
828 const GLushort s
= *src
;
829 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
830 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
831 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
832 texel
[ACOMP
] = ((s
>> 15) & 0x01);
836 /* Fetch color texel from 1D, 2D or 3D bgra5551 texture, return 4 GLchans */
837 static void FETCH(bgra5551
)( const struct gl_texture_image
*texImage
,
838 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
840 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
841 const GLushort s
= *src
;
842 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 1) & 0x1f) * 255 / 0x1f );
843 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 6) & 0x1f) * 255 / 0x1f );
844 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
>> 11) & 0x1f) * 255 / 0x1f );
845 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
) & 0x01) * 255 );
848 /* Fetch color texel from 1D, 2D or 3D bgra5551 texture, return 4 GLfloats */
849 static void FETCH(f_bgra5551
)( const struct gl_texture_image
*texImage
,
850 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
852 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
853 const GLushort s
= *src
;
854 texel
[RCOMP
] = ((s
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
855 texel
[GCOMP
] = ((s
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
856 texel
[BCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
857 texel
[ACOMP
] = ((s
) & 0x01);
861 /* Fetch color texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
862 static void FETCH(al88
)( const struct gl_texture_image
*texImage
,
863 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
865 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 2 );
868 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
869 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[1] );
872 /* Fetch color texel from 1D, 2D or 3D al88 texture, return 4 GLfloats */
873 static void FETCH(f_al88
)( const struct gl_texture_image
*texImage
,
874 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
876 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 2 );
879 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
880 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[1] );
884 /* Fetch color texel from 1D, 2D or 3D la88 texture, return 4 GLchans */
885 static void FETCH(la88
)( const struct gl_texture_image
*texImage
,
886 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
888 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 2 );
891 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[1] );
892 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
895 /* Fetch color texel from 1D, 2D or 3D la88 texture, return 4 GLfloats */
896 static void FETCH(f_la88
)( const struct gl_texture_image
*texImage
,
897 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
899 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 2 );
902 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[1] );
903 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
907 /* Fetch color texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
908 static void FETCH(rgb332
)( const struct gl_texture_image
*texImage
,
909 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
911 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
912 const GLubyte s
= *src
;
913 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xe0) * 255 / 0xe0 );
914 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xe0) * 255 / 0xe0 );
915 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 6) & 0xc0) * 255 / 0xc0 );
916 texel
[ACOMP
] = CHAN_MAX
;
919 /* Fetch color texel from 1D, 2D or 3D rgb332 texture, return 4 GLfloats */
920 static void FETCH(f_rgb332
)( const struct gl_texture_image
*texImage
,
921 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
923 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
924 const GLubyte s
= *src
;
925 texel
[RCOMP
] = ((s
) & 0xe0) * (1.0F
/ 224.0F
);
926 texel
[GCOMP
] = ((s
<< 3) & 0xe0) * (1.0F
/ 224.0F
);
927 texel
[BCOMP
] = ((s
<< 6) & 0xc0) * (1.0F
/ 192.0F
);
928 texel
[ACOMP
] = CHAN_MAXF
;
932 /* Fetch color texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
933 static void FETCH(a8
)( const struct gl_texture_image
*texImage
,
934 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
936 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
940 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
943 /* Fetch color texel from 1D, 2D or 3D a8 texture, return 4 GLfloats */
944 static void FETCH(f_a8
)( const struct gl_texture_image
*texImage
,
945 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
947 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
951 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
955 /* Fetch color texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
956 static void FETCH(l8
)( const struct gl_texture_image
*texImage
,
957 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
959 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
962 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
963 texel
[ACOMP
] = CHAN_MAX
;
966 /* Fetch color texel from 1D, 2D or 3D l8 texture, return 4 GLfloats */
967 static void FETCH(f_l8
)( const struct gl_texture_image
*texImage
,
968 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
970 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
973 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
974 texel
[ACOMP
] = CHAN_MAXF
;
978 /* Fetch color texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
979 static void FETCH(i8
)( const struct gl_texture_image
*texImage
,
980 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
982 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
986 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
989 /* Fetch color texel from 1D, 2D or 3D i8 texture, return 4 GLfloats */
990 static void FETCH(f_i8
)( const struct gl_texture_image
*texImage
,
991 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
993 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
997 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1001 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1002 * color table, and return 4 GLchans.
1004 static void FETCH(ci8
)( const struct gl_texture_image
*texImage
,
1005 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1007 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
1008 const GLuint index
= *src
;
1009 const struct gl_color_table
*palette
;
1010 const GLchan
*table
;
1011 GET_CURRENT_CONTEXT(ctx
);
1013 if (ctx
->Texture
.SharedPalette
) {
1014 palette
= &ctx
->Texture
.Palette
;
1017 palette
= &texImage
->TexObject
->Palette
;
1019 if (palette
->Size
== 0)
1020 return; /* undefined results */
1021 ASSERT(palette
->Type
!= GL_FLOAT
);
1022 table
= (const GLchan
*) palette
->Table
;
1024 switch (palette
->Format
) {
1029 texel
[ACOMP
] = table
[index
];
1034 texel
[BCOMP
] = table
[index
];
1035 texel
[ACOMP
] = CHAN_MAX
;
1041 texel
[ACOMP
] = table
[index
];
1043 case GL_LUMINANCE_ALPHA
:
1046 texel
[BCOMP
] = table
[index
* 2 + 0];
1047 texel
[ACOMP
] = table
[index
* 2 + 1];
1050 texel
[RCOMP
] = table
[index
* 3 + 0];
1051 texel
[GCOMP
] = table
[index
* 3 + 1];
1052 texel
[BCOMP
] = table
[index
* 3 + 2];
1053 texel
[ACOMP
] = CHAN_MAX
;
1056 texel
[RCOMP
] = table
[index
* 4 + 0];
1057 texel
[GCOMP
] = table
[index
* 4 + 1];
1058 texel
[BCOMP
] = table
[index
* 4 + 2];
1059 texel
[ACOMP
] = table
[index
* 4 + 3];
1062 _mesa_problem(ctx
, "Bad palette format in palette_sample");
1067 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1068 * color table, and return 4 GLfloats.
1070 static void FETCH(f_ci8
)( const struct gl_texture_image
*texImage
,
1071 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1074 /* Sample as GLchan */
1075 FETCH(ci8
)(texImage
, i
, j
, k
, rgba
);
1076 /* and return as floats */
1077 texel
[RCOMP
] = CHAN_TO_FLOAT(rgba
[RCOMP
]);
1078 texel
[GCOMP
] = CHAN_TO_FLOAT(rgba
[GCOMP
]);
1079 texel
[BCOMP
] = CHAN_TO_FLOAT(rgba
[BCOMP
]);
1080 texel
[ACOMP
] = CHAN_TO_FLOAT(rgba
[ACOMP
]);
1084 /* Fetch color texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
1085 /* We convert YCbCr to RGB here */
1086 /* XXX this may break if GLchan != GLubyte */
1087 static void FETCH(ycbcr
)( const struct gl_texture_image
*texImage
,
1088 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1090 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
1091 const GLushort
*src1
= src0
+ 1; /* odd */
1092 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1093 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1094 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1095 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1098 /* odd pixel: use y1,cr,cb */
1099 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
1100 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1101 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
1104 /* even pixel: use y0,cr,cb */
1105 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
1106 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1107 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
1109 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
1110 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
1111 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
1112 texel
[ACOMP
] = CHAN_MAX
;
1115 /* Fetch color texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats */
1116 /* We convert YCbCr to RGB here */
1117 static void FETCH(f_ycbcr
)( const struct gl_texture_image
*texImage
,
1118 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1120 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
1121 const GLushort
*src1
= src0
+ 1; /* odd */
1122 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1123 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1124 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1125 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1128 /* odd pixel: use y1,cr,cb */
1129 r
= (1.164 * (y1
-16) + 1.596 * (cr
-128));
1130 g
= (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1131 b
= (1.164 * (y1
-16) + 2.018 * (cb
-128));
1134 /* even pixel: use y0,cr,cb */
1135 r
= (1.164 * (y0
-16) + 1.596 * (cr
-128));
1136 g
= (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1137 b
= (1.164 * (y0
-16) + 2.018 * (cb
-128));
1139 /* XXX remove / 255 here by tweaking arithmetic above */
1143 /* XXX should we really clamp??? */
1144 texel
[RCOMP
] = CLAMP(r
, 0.0, 1.0);
1145 texel
[GCOMP
] = CLAMP(g
, 0.0, 1.0);
1146 texel
[BCOMP
] = CLAMP(b
, 0.0, 1.0);
1147 texel
[ACOMP
] = CHAN_MAXF
;
1151 /* Fetch color texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
1152 /* We convert YCbCr to RGB here */
1153 /* XXX this may break if GLchan != GLubyte */
1154 static void FETCH(ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1155 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1157 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
1158 const GLushort
*src1
= src0
+ 1; /* odd */
1159 const GLubyte y0
= *src0
& 0xff; /* luminance */
1160 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1161 const GLubyte y1
= *src1
& 0xff; /* luminance */
1162 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1165 /* odd pixel: use y1,cr,cb */
1166 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
1167 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1168 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
1171 /* even pixel: use y0,cr,cb */
1172 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
1173 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1174 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
1176 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
1177 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
1178 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
1179 texel
[ACOMP
] = CHAN_MAX
;
1182 /* Fetch color texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats */
1183 /* We convert YCbCr to RGB here */
1184 static void FETCH(f_ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1185 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1187 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
1188 const GLushort
*src1
= src0
+ 1; /* odd */
1189 const GLubyte y0
= *src0
& 0xff; /* luminance */
1190 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1191 const GLubyte y1
= *src1
& 0xff; /* luminance */
1192 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1195 /* odd pixel: use y1,cr,cb */
1196 r
= (1.164 * (y1
-16) + 1.596 * (cr
-128));
1197 g
= (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1198 b
= (1.164 * (y1
-16) + 2.018 * (cb
-128));
1201 /* even pixel: use y0,cr,cb */
1202 r
= (1.164 * (y0
-16) + 1.596 * (cr
-128));
1203 g
= (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1204 b
= (1.164 * (y0
-16) + 2.018 * (cb
-128));
1206 /* XXX remove / 255 here by tweaking arithmetic above */
1210 /* XXX should we really clamp??? */
1211 texel
[RCOMP
] = CLAMP(r
, 0.0, 1.0);
1212 texel
[GCOMP
] = CLAMP(g
, 0.0, 1.0);
1213 texel
[BCOMP
] = CLAMP(b
, 0.0, 1.0);
1214 texel
[ACOMP
] = CHAN_MAXF
;