3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * \file texformat_tmp.h
29 * Texel fetch functions template.
31 * This template file is used by texformat.c to generate texel fetch functions
32 * for 1-D, 2-D and 3-D texture images.
34 * It should be expanded by defining \p DIM as the number texture dimensions
35 * (1, 2 or 3). According to the value of \p DIM a series of macros is defined
36 * for the texel lookup in the gl_texture_image::Data.
38 * \sa texformat.c and FetchTexel.
40 * \author Gareth Hughes
47 #define CHAN_SRC( t, i, j, k, sz ) \
48 ((GLchan *)(t)->Data + (i) * (sz))
49 #define UBYTE_SRC( t, i, j, k, sz ) \
50 ((GLubyte *)(t)->Data + (i) * (sz))
51 #define USHORT_SRC( t, i, j, k ) \
52 ((GLushort *)(t)->Data + (i))
53 #define UINT_SRC( t, i, j, k ) \
54 ((GLuint *)(t)->Data + (i))
55 #define FLOAT_SRC( t, i, j, k, sz ) \
56 ((GLfloat *)(t)->Data + (i) * (sz))
57 #define HALF_SRC( t, i, j, k, sz ) \
58 ((GLhalfARB *)(t)->Data + (i) * (sz))
60 #define FETCH(x) fetch_texel_1d_##x
64 #define CHAN_SRC( t, i, j, k, sz ) \
65 ((GLchan *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
66 #define UBYTE_SRC( t, i, j, k, sz ) \
67 ((GLubyte *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
68 #define USHORT_SRC( t, i, j, k ) \
69 ((GLushort *)(t)->Data + ((t)->RowStride * (j) + (i)))
70 #define UINT_SRC( t, i, j, k ) \
71 ((GLuint *)(t)->Data + ((t)->RowStride * (j) + (i)))
72 #define FLOAT_SRC( t, i, j, k, sz ) \
73 ((GLfloat *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
74 #define HALF_SRC( t, i, j, k, sz ) \
75 ((GLhalfARB *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
77 #define FETCH(x) fetch_texel_2d_##x
81 #define CHAN_SRC( t, i, j, k, sz ) \
82 (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \
83 (t)->RowStride + (i)) * (sz)
84 #define UBYTE_SRC( t, i, j, k, sz ) \
85 ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \
86 (t)->RowStride + (i)) * (sz))
87 #define USHORT_SRC( t, i, j, k ) \
88 ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \
89 (t)->RowStride + (i)))
90 #define UINT_SRC( t, i, j, k ) \
91 ((GLuint *)(t)->Data + (((t)->Height * (k) + (j)) * \
92 (t)->RowStride + (i)))
93 #define FLOAT_SRC( t, i, j, k, sz ) \
94 ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \
95 (t)->RowStride + (i)) * (sz))
96 #define HALF_SRC( t, i, j, k, sz ) \
97 ((GLhalfARB *)(t)->Data + (((t)->Height * (k) + (j)) * \
98 (t)->RowStride + (i)) * (sz))
100 #define FETCH(x) fetch_texel_3d_##x
103 #error illegal number of texture dimensions
107 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLchans */
108 static void FETCH(rgba
)( const struct gl_texture_image
*texImage
,
109 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
111 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 4 );
112 COPY_CHAN4( texel
, src
);
115 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
116 static void FETCH(f_rgba
)( const struct gl_texture_image
*texImage
,
117 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
119 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 4 );
120 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
121 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
122 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
123 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[3]);
127 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLchans */
128 static void FETCH(rgb
)( const struct gl_texture_image
*texImage
,
129 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
131 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 3 );
132 texel
[RCOMP
] = src
[0];
133 texel
[GCOMP
] = src
[1];
134 texel
[BCOMP
] = src
[2];
135 texel
[ACOMP
] = CHAN_MAX
;
138 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
139 static void FETCH(f_rgb
)( const struct gl_texture_image
*texImage
,
140 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
142 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 3 );
143 texel
[RCOMP
] = CHAN_TO_FLOAT(src
[0]);
144 texel
[GCOMP
] = CHAN_TO_FLOAT(src
[1]);
145 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[2]);
146 texel
[ACOMP
] = CHAN_MAXF
;
149 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
150 static void FETCH(alpha
)( const struct gl_texture_image
*texImage
,
151 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
153 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
157 texel
[ACOMP
] = src
[0];
160 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLfloats */
161 static void FETCH(f_alpha
)( const struct gl_texture_image
*texImage
,
162 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
164 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
168 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[0]);
171 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
172 static void FETCH(luminance
)( const struct gl_texture_image
*texImage
,
173 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
175 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
178 texel
[BCOMP
] = src
[0];
179 texel
[ACOMP
] = CHAN_MAX
;
182 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
183 static void FETCH(f_luminance
)( const struct gl_texture_image
*texImage
,
184 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
186 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
189 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[0]);
190 texel
[ACOMP
] = CHAN_MAXF
;
193 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
194 static void FETCH(luminance_alpha
)( const struct gl_texture_image
*texImage
,
195 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
197 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 2 );
198 texel
[RCOMP
] = src
[0];
199 texel
[GCOMP
] = src
[0];
200 texel
[BCOMP
] = src
[0];
201 texel
[ACOMP
] = src
[1];
204 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLfloats */
205 static void FETCH(f_luminance_alpha
)( const struct gl_texture_image
*texImage
,
206 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
208 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 2 );
211 texel
[BCOMP
] = CHAN_TO_FLOAT(src
[0]);
212 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[1]);
216 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
217 static void FETCH(intensity
)( const struct gl_texture_image
*texImage
,
218 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
220 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
221 texel
[RCOMP
] = src
[0];
222 texel
[GCOMP
] = src
[0];
223 texel
[BCOMP
] = src
[0];
224 texel
[ACOMP
] = src
[0];
227 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLfloats */
228 static void FETCH(f_intensity
)( const struct gl_texture_image
*texImage
,
229 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
231 const GLchan
*src
= CHAN_SRC( texImage
, i
, j
, k
, 1 );
235 texel
[ACOMP
] = CHAN_TO_FLOAT(src
[0]);
239 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
240 * returning 1 GLfloat.
241 * Note: no GLchan version of this function.
243 static void FETCH(f_depth_component_f32
)( const struct gl_texture_image
*texImage
,
244 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
246 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
251 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
252 * returning 1 GLfloat.
253 * Note: no GLchan version of this function.
255 static void FETCH(f_depth_component16
)( const struct gl_texture_image
*texImage
,
256 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
258 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
259 texel
[0] = src
[0] * (1.0F
/ 65535.0F
);
263 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture,
264 * returning 4 GLchans.
266 static void FETCH(rgba_f32
)( const struct gl_texture_image
*texImage
,
267 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
269 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 4 );
270 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
271 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], src
[1]);
272 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], src
[2]);
273 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], src
[3]);
276 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture,
277 * returning 4 GLfloats.
279 static void FETCH(f_rgba_f32
)( const struct gl_texture_image
*texImage
,
280 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
282 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 4 );
283 texel
[RCOMP
] = src
[0];
284 texel
[GCOMP
] = src
[1];
285 texel
[BCOMP
] = src
[2];
286 texel
[ACOMP
] = src
[3];
289 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
290 * returning 4 GLchans.
292 static void FETCH(rgba_f16
)( const struct gl_texture_image
*texImage
,
293 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
295 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 4 );
296 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
297 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], _mesa_half_to_float(src
[1]));
298 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], _mesa_half_to_float(src
[2]));
299 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], _mesa_half_to_float(src
[3]));
302 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
303 * returning 4 GLfloats.
305 static void FETCH(f_rgba_f16
)( const struct gl_texture_image
*texImage
,
306 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
308 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 4 );
309 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
310 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
311 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
312 texel
[ACOMP
] = _mesa_half_to_float(src
[3]);
315 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
316 * returning 4 GLchans.
318 static void FETCH(rgb_f32
)( const struct gl_texture_image
*texImage
,
319 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
321 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 3 );
322 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
323 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], src
[1]);
324 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], src
[2]);
325 texel
[ACOMP
] = CHAN_MAX
;
328 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
329 * returning 4 GLfloats.
331 static void FETCH(f_rgb_f32
)( const struct gl_texture_image
*texImage
,
332 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
334 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 3 );
335 texel
[RCOMP
] = src
[0];
336 texel
[GCOMP
] = src
[1];
337 texel
[BCOMP
] = src
[2];
338 texel
[ACOMP
] = CHAN_MAXF
;
341 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
342 * returning 4 GLchans.
344 static void FETCH(rgb_f16
)( const struct gl_texture_image
*texImage
,
345 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
347 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 3 );
348 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
349 UNCLAMPED_FLOAT_TO_CHAN(texel
[GCOMP
], _mesa_half_to_float(src
[1]));
350 UNCLAMPED_FLOAT_TO_CHAN(texel
[BCOMP
], _mesa_half_to_float(src
[2]));
351 texel
[ACOMP
] = CHAN_MAX
;
354 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
355 * returning 4 GLfloats.
357 static void FETCH(f_rgb_f16
)( const struct gl_texture_image
*texImage
,
358 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
360 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 3 );
361 texel
[RCOMP
] = _mesa_half_to_float(src
[0]);
362 texel
[GCOMP
] = _mesa_half_to_float(src
[1]);
363 texel
[BCOMP
] = _mesa_half_to_float(src
[2]);
364 texel
[ACOMP
] = CHAN_MAXF
;
367 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
368 * returning 4 GLchans.
370 static void FETCH(alpha_f32
)( const struct gl_texture_image
*texImage
,
371 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
373 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
377 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], src
[0]);
380 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
381 * returning 4 GLfloats.
383 static void FETCH(f_alpha_f32
)( const struct gl_texture_image
*texImage
,
384 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
386 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
390 texel
[ACOMP
] = src
[0];
393 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
394 * returning 4 GLchans.
396 static void FETCH(alpha_f16
)( const struct gl_texture_image
*texImage
,
397 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
399 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 1 );
403 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], _mesa_half_to_float(src
[0]));
406 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
407 * returning 4 GLfloats.
409 static void FETCH(f_alpha_f16
)( const struct gl_texture_image
*texImage
,
410 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
412 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 1 );
416 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
419 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
420 * returning 4 GLchans.
422 static void FETCH(luminance_f32
)( const struct gl_texture_image
*texImage
,
423 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
425 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
426 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
428 texel
[BCOMP
] = texel
[RCOMP
];
429 texel
[ACOMP
] = CHAN_MAX
;
432 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
433 * returning 4 GLfloats.
435 static void FETCH(f_luminance_f32
)( const struct gl_texture_image
*texImage
,
436 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
438 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
441 texel
[BCOMP
] = src
[0];
442 texel
[ACOMP
] = CHAN_MAXF
;
445 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
446 * returning 4 GLchans.
448 static void FETCH(luminance_f16
)( const struct gl_texture_image
*texImage
,
449 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
451 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 1 );
452 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
454 texel
[BCOMP
] = texel
[RCOMP
];
455 texel
[ACOMP
] = CHAN_MAX
;
458 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
459 * returning 4 GLfloats.
461 static void FETCH(f_luminance_f16
)( const struct gl_texture_image
*texImage
,
462 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
464 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 1 );
467 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
468 texel
[ACOMP
] = CHAN_MAXF
;
471 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
472 * returning 4 GLchans.
474 static void FETCH(luminance_alpha_f32
)( const struct gl_texture_image
*texImage
,
475 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
477 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 2 );
478 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
480 texel
[BCOMP
] = texel
[RCOMP
];
481 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], src
[1]);
484 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
485 * returning 4 GLfloats.
487 static void FETCH(f_luminance_alpha_f32
)( const struct gl_texture_image
*texImage
,
488 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
490 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 2 );
493 texel
[BCOMP
] = src
[0];
494 texel
[ACOMP
] = src
[1];
497 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
498 * returning 4 GLfloats.
500 static void FETCH(luminance_alpha_f16
)( const struct gl_texture_image
*texImage
,
501 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
503 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 2 );
504 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
506 texel
[BCOMP
] = texel
[RCOMP
];
507 UNCLAMPED_FLOAT_TO_CHAN(texel
[ACOMP
], _mesa_half_to_float(src
[1]));
510 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
511 * returning 4 GLfloats.
513 static void FETCH(f_luminance_alpha_f16
)( const struct gl_texture_image
*texImage
,
514 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
516 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 2 );
519 texel
[BCOMP
] = _mesa_half_to_float(src
[0]);
520 texel
[ACOMP
] = _mesa_half_to_float(src
[1]);
523 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
524 * returning 4 GLchans.
526 static void FETCH(intensity_f32
)( const struct gl_texture_image
*texImage
,
527 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
529 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
530 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], src
[0]);
533 texel
[ACOMP
] = texel
[RCOMP
];
536 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
537 * returning 4 GLfloats.
539 static void FETCH(f_intensity_f32
)( const struct gl_texture_image
*texImage
,
540 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
542 const GLfloat
*src
= FLOAT_SRC( texImage
, i
, j
, k
, 1 );
546 texel
[ACOMP
] = src
[0];
549 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
550 * returning 4 GLchans.
552 static void FETCH(intensity_f16
)( const struct gl_texture_image
*texImage
,
553 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
555 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 1 );
556 UNCLAMPED_FLOAT_TO_CHAN(texel
[RCOMP
], _mesa_half_to_float(src
[0]));
559 texel
[ACOMP
] = texel
[RCOMP
];
562 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
563 * returning 4 GLfloats.
565 static void FETCH(f_intensity_f16
)( const struct gl_texture_image
*texImage
,
566 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
568 const GLhalfARB
*src
= HALF_SRC( texImage
, i
, j
, k
, 1 );
572 texel
[ACOMP
] = _mesa_half_to_float(src
[0]);
578 * Begin Hardware formats
581 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
582 static void FETCH(rgba8888
)( const struct gl_texture_image
*texImage
,
583 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
585 const GLuint s
= *UINT_SRC( texImage
, i
, j
, k
);
586 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
587 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
588 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
589 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
592 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
593 static void FETCH(f_rgba8888
)( const struct gl_texture_image
*texImage
,
594 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
596 const GLuint s
= *UINT_SRC( texImage
, i
, j
, k
);
597 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
598 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
599 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
600 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
604 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
605 static void FETCH(rgba8888_rev
)( const struct gl_texture_image
*texImage
,
606 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
608 const GLuint s
= *UINT_SRC( texImage
, i
, j
, k
);
609 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
610 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
611 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
612 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
615 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLfloats */
616 static void FETCH(f_rgba8888_rev
)( const struct gl_texture_image
*texImage
,
617 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
619 const GLuint s
= *UINT_SRC( texImage
, i
, j
, k
);
620 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
621 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
622 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
623 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
627 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
628 static void FETCH(argb8888
)( const struct gl_texture_image
*texImage
,
629 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
631 const GLuint s
= *UINT_SRC( texImage
, i
, j
, k
);
632 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
633 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
634 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
635 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
638 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLfloats */
639 static void FETCH(f_argb8888
)( const struct gl_texture_image
*texImage
,
640 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
642 const GLuint s
= *UINT_SRC( texImage
, i
, j
, k
);
643 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
644 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
645 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
646 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
650 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLchans */
651 static void FETCH(argb8888_rev
)( const struct gl_texture_image
*texImage
,
652 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
654 const GLuint s
= *UINT_SRC( texImage
, i
, j
, k
);
655 texel
[RCOMP
] = UBYTE_TO_CHAN( (s
>> 8) & 0xff );
656 texel
[GCOMP
] = UBYTE_TO_CHAN( (s
>> 16) & 0xff );
657 texel
[BCOMP
] = UBYTE_TO_CHAN( (s
>> 24) );
658 texel
[ACOMP
] = UBYTE_TO_CHAN( (s
) & 0xff );
662 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
663 static void FETCH(f_argb8888_rev
)( const struct gl_texture_image
*texImage
,
664 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
666 const GLuint s
= *UINT_SRC( texImage
, i
, j
, k
);
667 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
668 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
669 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
670 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
674 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
675 static void FETCH(rgb888
)( const struct gl_texture_image
*texImage
,
676 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
678 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 3 );
679 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[2] );
680 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
681 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
682 texel
[ACOMP
] = CHAN_MAX
;
685 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLfloats */
686 static void FETCH(f_rgb888
)( const struct gl_texture_image
*texImage
,
687 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
689 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 3 );
690 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
691 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
692 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
693 texel
[ACOMP
] = CHAN_MAXF
;
697 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
698 static void FETCH(bgr888
)( const struct gl_texture_image
*texImage
,
699 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
701 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 3 );
702 texel
[RCOMP
] = UBYTE_TO_CHAN( src
[0] );
703 texel
[GCOMP
] = UBYTE_TO_CHAN( src
[1] );
704 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[2] );
705 texel
[ACOMP
] = CHAN_MAX
;
708 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLfloats */
709 static void FETCH(f_bgr888
)( const struct gl_texture_image
*texImage
,
710 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
712 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 3 );
713 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[0] );
714 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
715 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[2] );
716 texel
[ACOMP
] = CHAN_MAXF
;
720 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
721 static void FETCH(rgb565
)( const struct gl_texture_image
*texImage
,
722 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
724 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
725 const GLushort s
= *src
;
726 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) * 255 / 0xf8 );
727 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) * 255 / 0xfc );
728 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) * 255 / 0xf8 );
729 texel
[ACOMP
] = CHAN_MAX
;
732 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
733 static void FETCH(f_rgb565
)( const struct gl_texture_image
*texImage
,
734 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
736 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
737 const GLushort s
= *src
;
738 texel
[RCOMP
] = ((s
>> 8) & 0xf8) * (1.0F
/ 248.0F
);
739 texel
[GCOMP
] = ((s
>> 3) & 0xfc) * (1.0F
/ 252.0F
);
740 texel
[BCOMP
] = ((s
<< 3) & 0xf8) * (1.0F
/ 248.0F
);
741 texel
[ACOMP
] = CHAN_MAXF
;
745 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
746 static void FETCH(rgb565_rev
)( const struct gl_texture_image
*texImage
,
747 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
749 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
750 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
751 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf8) * 255 / 0xf8 );
752 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 3) & 0xfc) * 255 / 0xfc );
753 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xf8) * 255 / 0xf8 );
754 texel
[ACOMP
] = CHAN_MAX
;
757 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLfloats */
758 static void FETCH(f_rgb565_rev
)( const struct gl_texture_image
*texImage
,
759 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
761 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
762 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
763 texel
[RCOMP
] = ((s
>> 8) & 0xf8) * (1.0F
/ 248.0F
);
764 texel
[GCOMP
] = ((s
>> 3) & 0xfc) * (1.0F
/ 252.0F
);
765 texel
[BCOMP
] = ((s
<< 3) & 0xf8) * (1.0F
/ 248.0F
);
766 texel
[ACOMP
] = CHAN_MAXF
;
770 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
771 static void FETCH(argb4444
)( const struct gl_texture_image
*texImage
,
772 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
774 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
775 const GLushort s
= *src
;
776 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) * 255 / 0xf );
777 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) * 255 / 0xf );
778 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) * 255 / 0xf );
779 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) * 255 / 0xf );
782 /* Fetch texel from 1D, 2D or 3D argb4444 texture, return 4 GLfloats */
783 static void FETCH(f_argb4444
)( const struct gl_texture_image
*texImage
,
784 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
786 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
787 const GLushort s
= *src
;
788 texel
[RCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
789 texel
[GCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
790 texel
[BCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
791 texel
[ACOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
795 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
796 static void FETCH(argb4444_rev
)( const struct gl_texture_image
*texImage
,
797 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
799 const GLushort s
= *USHORT_SRC( texImage
, i
, j
, k
);
800 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xf) * 255 / 0xf );
801 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 12) & 0xf) * 255 / 0xf );
802 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
>> 8) & 0xf) * 255 / 0xf );
803 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 4) & 0xf) * 255 / 0xf );
806 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLfloats */
807 static void FETCH(f_argb4444_rev
)( const struct gl_texture_image
*texImage
,
808 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
810 const GLushort s
= *USHORT_SRC( texImage
, i
, j
, k
);
811 texel
[RCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
812 texel
[GCOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
813 texel
[BCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
814 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
818 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
819 static void FETCH(argb1555
)( const struct gl_texture_image
*texImage
,
820 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
822 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
823 const GLushort s
= *src
;
824 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 10) & 0x1f) * 255 / 0x1f );
825 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 5) & 0x1f) * 255 / 0x1f );
826 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0x1f) * 255 / 0x1f );
827 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
830 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLfloats */
831 static void FETCH(f_argb1555
)( const struct gl_texture_image
*texImage
,
832 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
834 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
835 const GLushort s
= *src
;
836 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
837 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
838 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
839 texel
[ACOMP
] = ((s
>> 15) & 0x01);
843 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
844 static void FETCH(argb1555_rev
)( const struct gl_texture_image
*texImage
,
845 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
847 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
848 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
849 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
>> 10) & 0x1f) * 255 / 0x1f );
850 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
>> 5) & 0x1f) * 255 / 0x1f );
851 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
) & 0x1f) * 255 / 0x1f );
852 texel
[ACOMP
] = UBYTE_TO_CHAN( ((s
>> 15) & 0x01) * 255 );
855 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLfloats */
856 static void FETCH(f_argb1555_rev
)( const struct gl_texture_image
*texImage
,
857 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
859 const GLushort
*src
= USHORT_SRC( texImage
, i
, j
, k
);
860 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
861 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
862 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
863 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
864 texel
[ACOMP
] = ((s
>> 15) & 0x01);
868 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
869 static void FETCH(al88
)( const struct gl_texture_image
*texImage
,
870 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
872 const GLushort s
= *USHORT_SRC( texImage
, i
, j
, k
);
875 texel
[BCOMP
] = UBYTE_TO_CHAN( s
& 0xff );
876 texel
[ACOMP
] = UBYTE_TO_CHAN( s
>> 8 );
879 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLfloats */
880 static void FETCH(f_al88
)( const struct gl_texture_image
*texImage
,
881 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
883 const GLushort s
= *USHORT_SRC( texImage
, i
, j
, k
);
886 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
887 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
891 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
892 static void FETCH(al88_rev
)( const struct gl_texture_image
*texImage
,
893 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
895 const GLushort s
= *USHORT_SRC( texImage
, i
, j
, k
);
898 texel
[BCOMP
] = UBYTE_TO_CHAN( s
>> 8 );
899 texel
[ACOMP
] = UBYTE_TO_CHAN( s
& 0xff );
902 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLfloats */
903 static void FETCH(f_al88_rev
)( const struct gl_texture_image
*texImage
,
904 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
906 const GLushort s
= *USHORT_SRC( texImage
, i
, j
, k
);
909 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
910 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
914 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
915 static void FETCH(rgb332
)( const struct gl_texture_image
*texImage
,
916 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
918 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
919 const GLubyte s
= *src
;
920 texel
[RCOMP
] = UBYTE_TO_CHAN( ((s
) & 0xe0) * 255 / 0xe0 );
921 texel
[GCOMP
] = UBYTE_TO_CHAN( ((s
<< 3) & 0xe0) * 255 / 0xe0 );
922 texel
[BCOMP
] = UBYTE_TO_CHAN( ((s
<< 6) & 0xc0) * 255 / 0xc0 );
923 texel
[ACOMP
] = CHAN_MAX
;
926 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLfloats */
927 static void FETCH(f_rgb332
)( const struct gl_texture_image
*texImage
,
928 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
930 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
931 const GLubyte s
= *src
;
932 texel
[RCOMP
] = ((s
) & 0xe0) * (1.0F
/ 224.0F
);
933 texel
[GCOMP
] = ((s
<< 3) & 0xe0) * (1.0F
/ 224.0F
);
934 texel
[BCOMP
] = ((s
<< 6) & 0xc0) * (1.0F
/ 192.0F
);
935 texel
[ACOMP
] = CHAN_MAXF
;
939 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
940 static void FETCH(a8
)( const struct gl_texture_image
*texImage
,
941 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
943 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
947 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
950 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLfloats */
951 static void FETCH(f_a8
)( const struct gl_texture_image
*texImage
,
952 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
954 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
958 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
962 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
963 static void FETCH(l8
)( const struct gl_texture_image
*texImage
,
964 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
966 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
969 texel
[BCOMP
] = UBYTE_TO_CHAN( src
[0] );
970 texel
[ACOMP
] = CHAN_MAX
;
973 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLfloats */
974 static void FETCH(f_l8
)( const struct gl_texture_image
*texImage
,
975 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
977 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
980 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
981 texel
[ACOMP
] = CHAN_MAXF
;
985 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
986 static void FETCH(i8
)( const struct gl_texture_image
*texImage
,
987 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
989 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
993 texel
[ACOMP
] = UBYTE_TO_CHAN( src
[0] );
996 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLfloats */
997 static void FETCH(f_i8
)( const struct gl_texture_image
*texImage
,
998 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1000 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
1004 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
1008 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1009 * color table, and return 4 GLchans.
1011 static void FETCH(ci8
)( const struct gl_texture_image
*texImage
,
1012 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1014 const GLubyte
*src
= UBYTE_SRC( texImage
, i
, j
, k
, 1 );
1015 const struct gl_color_table
*palette
;
1016 const GLchan
*table
;
1018 GET_CURRENT_CONTEXT(ctx
);
1020 if (ctx
->Texture
.SharedPalette
) {
1021 palette
= &ctx
->Texture
.Palette
;
1024 palette
= &texImage
->TexObject
->Palette
;
1026 if (palette
->Size
== 0)
1027 return; /* undefined results */
1028 ASSERT(palette
->Type
!= GL_FLOAT
);
1029 table
= (const GLchan
*) palette
->Table
;
1031 /* Mask the index against size of palette to avoid going out of bounds */
1032 index
= (*src
) & (palette
->Size
- 1);
1034 switch (palette
->Format
) {
1039 texel
[ACOMP
] = table
[index
];
1044 texel
[BCOMP
] = table
[index
];
1045 texel
[ACOMP
] = CHAN_MAX
;
1051 texel
[ACOMP
] = table
[index
];
1053 case GL_LUMINANCE_ALPHA
:
1056 texel
[BCOMP
] = table
[index
* 2 + 0];
1057 texel
[ACOMP
] = table
[index
* 2 + 1];
1060 texel
[RCOMP
] = table
[index
* 3 + 0];
1061 texel
[GCOMP
] = table
[index
* 3 + 1];
1062 texel
[BCOMP
] = table
[index
* 3 + 2];
1063 texel
[ACOMP
] = CHAN_MAX
;
1066 texel
[RCOMP
] = table
[index
* 4 + 0];
1067 texel
[GCOMP
] = table
[index
* 4 + 1];
1068 texel
[BCOMP
] = table
[index
* 4 + 2];
1069 texel
[ACOMP
] = table
[index
* 4 + 3];
1072 _mesa_problem(ctx
, "Bad palette format in palette_sample");
1077 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1078 * color table, and return 4 GLfloats.
1080 static void FETCH(f_ci8
)( const struct gl_texture_image
*texImage
,
1081 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1084 /* Sample as GLchan */
1085 FETCH(ci8
)(texImage
, i
, j
, k
, rgba
);
1086 /* and return as floats */
1087 texel
[RCOMP
] = CHAN_TO_FLOAT(rgba
[RCOMP
]);
1088 texel
[GCOMP
] = CHAN_TO_FLOAT(rgba
[GCOMP
]);
1089 texel
[BCOMP
] = CHAN_TO_FLOAT(rgba
[BCOMP
]);
1090 texel
[ACOMP
] = CHAN_TO_FLOAT(rgba
[ACOMP
]);
1094 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
1095 /* We convert YCbCr to RGB here */
1096 /* XXX this may break if GLchan != GLubyte */
1097 static void FETCH(ycbcr
)( const struct gl_texture_image
*texImage
,
1098 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1100 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
1101 const GLushort
*src1
= src0
+ 1; /* odd */
1102 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1103 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1104 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1105 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1108 /* odd pixel: use y1,cr,cb */
1109 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
1110 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1111 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
1114 /* even pixel: use y0,cr,cb */
1115 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
1116 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1117 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
1119 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
1120 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
1121 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
1122 texel
[ACOMP
] = CHAN_MAX
;
1125 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats */
1126 /* We convert YCbCr to RGB here */
1127 static void FETCH(f_ycbcr
)( const struct gl_texture_image
*texImage
,
1128 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1130 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
1131 const GLushort
*src1
= src0
+ 1; /* odd */
1132 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
1133 const GLubyte cb
= *src0
& 0xff; /* chroma U */
1134 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
1135 const GLubyte cr
= *src1
& 0xff; /* chroma V */
1138 /* odd pixel: use y1,cr,cb */
1139 r
= (1.164 * (y1
-16) + 1.596 * (cr
-128));
1140 g
= (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1141 b
= (1.164 * (y1
-16) + 2.018 * (cb
-128));
1144 /* even pixel: use y0,cr,cb */
1145 r
= (1.164 * (y0
-16) + 1.596 * (cr
-128));
1146 g
= (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1147 b
= (1.164 * (y0
-16) + 2.018 * (cb
-128));
1149 /* XXX remove / 255 here by tweaking arithmetic above */
1153 /* XXX should we really clamp??? */
1154 texel
[RCOMP
] = CLAMP(r
, 0.0, 1.0);
1155 texel
[GCOMP
] = CLAMP(g
, 0.0, 1.0);
1156 texel
[BCOMP
] = CLAMP(b
, 0.0, 1.0);
1157 texel
[ACOMP
] = CHAN_MAXF
;
1161 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
1162 /* We convert YCbCr to RGB here */
1163 /* XXX this may break if GLchan != GLubyte */
1164 static void FETCH(ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1165 GLint i
, GLint j
, GLint k
, GLchan
*texel
)
1167 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
1168 const GLushort
*src1
= src0
+ 1; /* odd */
1169 const GLubyte y0
= *src0
& 0xff; /* luminance */
1170 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1171 const GLubyte y1
= *src1
& 0xff; /* luminance */
1172 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1175 /* odd pixel: use y1,cr,cb */
1176 r
= (GLint
) (1.164 * (y1
-16) + 1.596 * (cr
-128));
1177 g
= (GLint
) (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1178 b
= (GLint
) (1.164 * (y1
-16) + 2.018 * (cb
-128));
1181 /* even pixel: use y0,cr,cb */
1182 r
= (GLint
) (1.164 * (y0
-16) + 1.596 * (cr
-128));
1183 g
= (GLint
) (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1184 b
= (GLint
) (1.164 * (y0
-16) + 2.018 * (cb
-128));
1186 texel
[RCOMP
] = CLAMP(r
, 0, CHAN_MAX
);
1187 texel
[GCOMP
] = CLAMP(g
, 0, CHAN_MAX
);
1188 texel
[BCOMP
] = CLAMP(b
, 0, CHAN_MAX
);
1189 texel
[ACOMP
] = CHAN_MAX
;
1192 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats */
1193 /* We convert YCbCr to RGB here */
1194 static void FETCH(f_ycbcr_rev
)( const struct gl_texture_image
*texImage
,
1195 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
1197 const GLushort
*src0
= USHORT_SRC( texImage
, (i
& ~1), j
, k
); /* even */
1198 const GLushort
*src1
= src0
+ 1; /* odd */
1199 const GLubyte y0
= *src0
& 0xff; /* luminance */
1200 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
1201 const GLubyte y1
= *src1
& 0xff; /* luminance */
1202 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
1205 /* odd pixel: use y1,cr,cb */
1206 r
= (1.164 * (y1
-16) + 1.596 * (cr
-128));
1207 g
= (1.164 * (y1
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1208 b
= (1.164 * (y1
-16) + 2.018 * (cb
-128));
1211 /* even pixel: use y0,cr,cb */
1212 r
= (1.164 * (y0
-16) + 1.596 * (cr
-128));
1213 g
= (1.164 * (y0
-16) - 0.813 * (cr
-128) - 0.391 * (cb
-128));
1214 b
= (1.164 * (y0
-16) + 2.018 * (cb
-128));
1216 /* XXX remove / 255 here by tweaking arithmetic above */
1220 /* XXX should we really clamp??? */
1221 texel
[RCOMP
] = CLAMP(r
, 0.0, 1.0);
1222 texel
[GCOMP
] = CLAMP(g
, 0.0, 1.0);
1223 texel
[BCOMP
] = CLAMP(b
, 0.0, 1.0);
1224 texel
[ACOMP
] = CHAN_MAXF
;