d341c7864ae96f489ec3ea917ce6420cce1c62f1
[reactos.git] / reactos / lib / mesa32 / src / main / texformat_tmp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.1
4 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25
26 /**
27 * \file texformat_tmp.h
28 * Texel fetch functions template.
29 *
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.
32 *
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.
36 *
37 * \sa texformat.c and FetchTexel.
38 *
39 * \author Gareth Hughes
40 * \author Brian Paul
41 */
42
43
44 #if DIM == 1
45
46 #define CHAN_SRC( t, i, j, k, sz ) \
47 ((void) (j), (void) (k), \
48 ((GLchan *)(t)->Data + (i) * (sz)))
49 #define UBYTE_SRC( t, i, j, k, sz ) \
50 ((void) (j), (void) (k), \
51 ((GLubyte *)(t)->Data + (i) * (sz)))
52 #define USHORT_SRC( t, i, j, k ) \
53 ((void) (j), (void) (k), \
54 ((GLushort *)(t)->Data + (i)))
55 #define UINT_SRC( t, i, j, k ) \
56 ((void) (j), (void) (k), \
57 ((GLuint *)(t)->Data + (i)))
58 #define FLOAT_SRC( t, i, j, k, sz ) \
59 ((void) (j), (void) (k), \
60 ((GLfloat *)(t)->Data + (i) * (sz)))
61 #define HALF_SRC( t, i, j, k, sz ) \
62 ((void) (j), (void) (k), \
63 ((GLhalfARB *)(t)->Data + (i) * (sz)))
64
65 #define FETCH(x) fetch_texel_1d_##x
66
67 #elif DIM == 2
68
69 #define CHAN_SRC( t, i, j, k, sz ) \
70 ((void) (k), \
71 ((GLchan *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz)))
72 #define UBYTE_SRC( t, i, j, k, sz ) \
73 ((void) (k), \
74 ((GLubyte *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz)))
75 #define USHORT_SRC( t, i, j, k ) \
76 ((void) (k), \
77 ((GLushort *)(t)->Data + ((t)->RowStride * (j) + (i))))
78 #define UINT_SRC( t, i, j, k ) \
79 ((void) (k), \
80 ((GLuint *)(t)->Data + ((t)->RowStride * (j) + (i))))
81 #define FLOAT_SRC( t, i, j, k, sz ) \
82 ((void) (k), \
83 ((GLfloat *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz)))
84 #define HALF_SRC( t, i, j, k, sz ) \
85 ((void) (k), \
86 ((GLhalfARB *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz)))
87
88 #define FETCH(x) fetch_texel_2d_##x
89
90 #elif DIM == 3
91
92 #define CHAN_SRC( t, i, j, k, sz ) \
93 (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \
94 (t)->RowStride + (i)) * (sz)
95 #define UBYTE_SRC( t, i, j, k, sz ) \
96 ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \
97 (t)->RowStride + (i)) * (sz))
98 #define USHORT_SRC( t, i, j, k ) \
99 ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \
100 (t)->RowStride + (i)))
101 #define UINT_SRC( t, i, j, k ) \
102 ((GLuint *)(t)->Data + (((t)->Height * (k) + (j)) * \
103 (t)->RowStride + (i)))
104 #define FLOAT_SRC( t, i, j, k, sz ) \
105 ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \
106 (t)->RowStride + (i)) * (sz))
107 #define HALF_SRC( t, i, j, k, sz ) \
108 ((GLhalfARB *)(t)->Data + (((t)->Height * (k) + (j)) * \
109 (t)->RowStride + (i)) * (sz))
110
111 #define FETCH(x) fetch_texel_3d_##x
112
113 #else
114 #error illegal number of texture dimensions
115 #endif
116
117
118 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLchans */
119 static void FETCH(rgba)( const struct gl_texture_image *texImage,
120 GLint i, GLint j, GLint k, GLchan *texel )
121 {
122 const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 );
123 COPY_CHAN4( texel, src );
124 }
125
126 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
127 static void FETCH(f_rgba)( const struct gl_texture_image *texImage,
128 GLint i, GLint j, GLint k, GLfloat *texel )
129 {
130 const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 );
131 texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
132 texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
133 texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
134 texel[ACOMP] = CHAN_TO_FLOAT(src[3]);
135 }
136
137
138 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLchans */
139 static void FETCH(rgb)( const struct gl_texture_image *texImage,
140 GLint i, GLint j, GLint k, GLchan *texel )
141 {
142 const GLchan *src = CHAN_SRC( texImage, i, j, k, 3 );
143 texel[RCOMP] = src[0];
144 texel[GCOMP] = src[1];
145 texel[BCOMP] = src[2];
146 texel[ACOMP] = CHAN_MAX;
147 }
148
149 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
150 static void FETCH(f_rgb)( const struct gl_texture_image *texImage,
151 GLint i, GLint j, GLint k, GLfloat *texel )
152 {
153 const GLchan *src = CHAN_SRC( texImage, i, j, k, 3 );
154 texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
155 texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
156 texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
157 texel[ACOMP] = CHAN_MAXF;
158 }
159
160 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
161 static void FETCH(alpha)( const struct gl_texture_image *texImage,
162 GLint i, GLint j, GLint k, GLchan *texel )
163 {
164 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
165 texel[RCOMP] =
166 texel[GCOMP] =
167 texel[BCOMP] = 0;
168 texel[ACOMP] = src[0];
169 }
170
171 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLfloats */
172 static void FETCH(f_alpha)( const struct gl_texture_image *texImage,
173 GLint i, GLint j, GLint k, GLfloat *texel )
174 {
175 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
176 texel[RCOMP] =
177 texel[GCOMP] =
178 texel[BCOMP] = 0.0;
179 texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
180 }
181
182 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
183 static void FETCH(luminance)( const struct gl_texture_image *texImage,
184 GLint i, GLint j, GLint k, GLchan *texel )
185 {
186 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
187 texel[RCOMP] =
188 texel[GCOMP] =
189 texel[BCOMP] = src[0];
190 texel[ACOMP] = CHAN_MAX;
191 }
192
193 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
194 static void FETCH(f_luminance)( const struct gl_texture_image *texImage,
195 GLint i, GLint j, GLint k, GLfloat *texel )
196 {
197 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
198 texel[RCOMP] =
199 texel[GCOMP] =
200 texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
201 texel[ACOMP] = CHAN_MAXF;
202 }
203
204 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
205 static void FETCH(luminance_alpha)( const struct gl_texture_image *texImage,
206 GLint i, GLint j, GLint k, GLchan *texel )
207 {
208 const GLchan *src = CHAN_SRC( texImage, i, j, k, 2 );
209 texel[RCOMP] = src[0];
210 texel[GCOMP] = src[0];
211 texel[BCOMP] = src[0];
212 texel[ACOMP] = src[1];
213 }
214
215 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLfloats */
216 static void FETCH(f_luminance_alpha)( const struct gl_texture_image *texImage,
217 GLint i, GLint j, GLint k, GLfloat *texel )
218 {
219 const GLchan *src = CHAN_SRC( texImage, i, j, k, 2 );
220 texel[RCOMP] =
221 texel[GCOMP] =
222 texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
223 texel[ACOMP] = CHAN_TO_FLOAT(src[1]);
224 }
225
226
227 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
228 static void FETCH(intensity)( const struct gl_texture_image *texImage,
229 GLint i, GLint j, GLint k, GLchan *texel )
230 {
231 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
232 texel[RCOMP] = src[0];
233 texel[GCOMP] = src[0];
234 texel[BCOMP] = src[0];
235 texel[ACOMP] = src[0];
236 }
237
238 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLfloats */
239 static void FETCH(f_intensity)( const struct gl_texture_image *texImage,
240 GLint i, GLint j, GLint k, GLfloat *texel )
241 {
242 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
243 texel[RCOMP] =
244 texel[GCOMP] =
245 texel[BCOMP] =
246 texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
247 }
248
249
250 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
251 * returning 1 GLfloat.
252 * Note: no GLchan version of this function.
253 */
254 static void FETCH(f_depth_component_f32)( const struct gl_texture_image *texImage,
255 GLint i, GLint j, GLint k, GLfloat *texel )
256 {
257 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
258 texel[0] = src[0];
259 }
260
261
262 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
263 * returning 1 GLfloat.
264 * Note: no GLchan version of this function.
265 */
266 static void FETCH(f_depth_component16)( const struct gl_texture_image *texImage,
267 GLint i, GLint j, GLint k, GLfloat *texel )
268 {
269 const GLushort *src = USHORT_SRC( texImage, i, j, k );
270 texel[0] = src[0] * (1.0F / 65535.0F);
271 }
272
273
274 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture,
275 * returning 4 GLchans.
276 */
277 static void FETCH(rgba_f32)( const struct gl_texture_image *texImage,
278 GLint i, GLint j, GLint k, GLchan *texel )
279 {
280 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 4 );
281 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
282 UNCLAMPED_FLOAT_TO_CHAN(texel[GCOMP], src[1]);
283 UNCLAMPED_FLOAT_TO_CHAN(texel[BCOMP], src[2]);
284 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], src[3]);
285 }
286
287 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture,
288 * returning 4 GLfloats.
289 */
290 static void FETCH(f_rgba_f32)( const struct gl_texture_image *texImage,
291 GLint i, GLint j, GLint k, GLfloat *texel )
292 {
293 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 4 );
294 texel[RCOMP] = src[0];
295 texel[GCOMP] = src[1];
296 texel[BCOMP] = src[2];
297 texel[ACOMP] = src[3];
298 }
299
300 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
301 * returning 4 GLchans.
302 */
303 static void FETCH(rgba_f16)( const struct gl_texture_image *texImage,
304 GLint i, GLint j, GLint k, GLchan *texel )
305 {
306 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 4 );
307 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
308 UNCLAMPED_FLOAT_TO_CHAN(texel[GCOMP], _mesa_half_to_float(src[1]));
309 UNCLAMPED_FLOAT_TO_CHAN(texel[BCOMP], _mesa_half_to_float(src[2]));
310 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], _mesa_half_to_float(src[3]));
311 }
312
313 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
314 * returning 4 GLfloats.
315 */
316 static void FETCH(f_rgba_f16)( const struct gl_texture_image *texImage,
317 GLint i, GLint j, GLint k, GLfloat *texel )
318 {
319 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 4 );
320 texel[RCOMP] = _mesa_half_to_float(src[0]);
321 texel[GCOMP] = _mesa_half_to_float(src[1]);
322 texel[BCOMP] = _mesa_half_to_float(src[2]);
323 texel[ACOMP] = _mesa_half_to_float(src[3]);
324 }
325
326 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
327 * returning 4 GLchans.
328 */
329 static void FETCH(rgb_f32)( const struct gl_texture_image *texImage,
330 GLint i, GLint j, GLint k, GLchan *texel )
331 {
332 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 3 );
333 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
334 UNCLAMPED_FLOAT_TO_CHAN(texel[GCOMP], src[1]);
335 UNCLAMPED_FLOAT_TO_CHAN(texel[BCOMP], src[2]);
336 texel[ACOMP] = CHAN_MAX;
337 }
338
339 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
340 * returning 4 GLfloats.
341 */
342 static void FETCH(f_rgb_f32)( const struct gl_texture_image *texImage,
343 GLint i, GLint j, GLint k, GLfloat *texel )
344 {
345 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 3 );
346 texel[RCOMP] = src[0];
347 texel[GCOMP] = src[1];
348 texel[BCOMP] = src[2];
349 texel[ACOMP] = CHAN_MAXF;
350 }
351
352 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
353 * returning 4 GLchans.
354 */
355 static void FETCH(rgb_f16)( const struct gl_texture_image *texImage,
356 GLint i, GLint j, GLint k, GLchan *texel )
357 {
358 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 3 );
359 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
360 UNCLAMPED_FLOAT_TO_CHAN(texel[GCOMP], _mesa_half_to_float(src[1]));
361 UNCLAMPED_FLOAT_TO_CHAN(texel[BCOMP], _mesa_half_to_float(src[2]));
362 texel[ACOMP] = CHAN_MAX;
363 }
364
365 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
366 * returning 4 GLfloats.
367 */
368 static void FETCH(f_rgb_f16)( const struct gl_texture_image *texImage,
369 GLint i, GLint j, GLint k, GLfloat *texel )
370 {
371 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 3 );
372 texel[RCOMP] = _mesa_half_to_float(src[0]);
373 texel[GCOMP] = _mesa_half_to_float(src[1]);
374 texel[BCOMP] = _mesa_half_to_float(src[2]);
375 texel[ACOMP] = CHAN_MAXF;
376 }
377
378 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
379 * returning 4 GLchans.
380 */
381 static void FETCH(alpha_f32)( const struct gl_texture_image *texImage,
382 GLint i, GLint j, GLint k, GLchan *texel )
383 {
384 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
385 texel[RCOMP] =
386 texel[GCOMP] =
387 texel[BCOMP] = 0;
388 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], src[0]);
389 }
390
391 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
392 * returning 4 GLfloats.
393 */
394 static void FETCH(f_alpha_f32)( const struct gl_texture_image *texImage,
395 GLint i, GLint j, GLint k, GLfloat *texel )
396 {
397 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
398 texel[RCOMP] =
399 texel[GCOMP] =
400 texel[BCOMP] = 0.0F;
401 texel[ACOMP] = src[0];
402 }
403
404 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
405 * returning 4 GLchans.
406 */
407 static void FETCH(alpha_f16)( const struct gl_texture_image *texImage,
408 GLint i, GLint j, GLint k, GLchan *texel )
409 {
410 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 1 );
411 texel[RCOMP] =
412 texel[GCOMP] =
413 texel[BCOMP] = 0;
414 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], _mesa_half_to_float(src[0]));
415 }
416
417 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
418 * returning 4 GLfloats.
419 */
420 static void FETCH(f_alpha_f16)( const struct gl_texture_image *texImage,
421 GLint i, GLint j, GLint k, GLfloat *texel )
422 {
423 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 1 );
424 texel[RCOMP] =
425 texel[GCOMP] =
426 texel[BCOMP] = 0.0F;
427 texel[ACOMP] = _mesa_half_to_float(src[0]);
428 }
429
430 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
431 * returning 4 GLchans.
432 */
433 static void FETCH(luminance_f32)( const struct gl_texture_image *texImage,
434 GLint i, GLint j, GLint k, GLchan *texel )
435 {
436 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
437 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
438 texel[GCOMP] =
439 texel[BCOMP] = texel[RCOMP];
440 texel[ACOMP] = CHAN_MAX;
441 }
442
443 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
444 * returning 4 GLfloats.
445 */
446 static void FETCH(f_luminance_f32)( const struct gl_texture_image *texImage,
447 GLint i, GLint j, GLint k, GLfloat *texel )
448 {
449 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
450 texel[RCOMP] =
451 texel[GCOMP] =
452 texel[BCOMP] = src[0];
453 texel[ACOMP] = CHAN_MAXF;
454 }
455
456 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
457 * returning 4 GLchans.
458 */
459 static void FETCH(luminance_f16)( const struct gl_texture_image *texImage,
460 GLint i, GLint j, GLint k, GLchan *texel )
461 {
462 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 1 );
463 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
464 texel[GCOMP] =
465 texel[BCOMP] = texel[RCOMP];
466 texel[ACOMP] = CHAN_MAX;
467 }
468
469 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
470 * returning 4 GLfloats.
471 */
472 static void FETCH(f_luminance_f16)( const struct gl_texture_image *texImage,
473 GLint i, GLint j, GLint k, GLfloat *texel )
474 {
475 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 1 );
476 texel[RCOMP] =
477 texel[GCOMP] =
478 texel[BCOMP] = _mesa_half_to_float(src[0]);
479 texel[ACOMP] = CHAN_MAXF;
480 }
481
482 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
483 * returning 4 GLchans.
484 */
485 static void FETCH(luminance_alpha_f32)( const struct gl_texture_image *texImage,
486 GLint i, GLint j, GLint k, GLchan *texel )
487 {
488 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 2 );
489 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
490 texel[GCOMP] =
491 texel[BCOMP] = texel[RCOMP];
492 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], src[1]);
493 }
494
495 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
496 * returning 4 GLfloats.
497 */
498 static void FETCH(f_luminance_alpha_f32)( const struct gl_texture_image *texImage,
499 GLint i, GLint j, GLint k, GLfloat *texel )
500 {
501 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 2 );
502 texel[RCOMP] =
503 texel[GCOMP] =
504 texel[BCOMP] = src[0];
505 texel[ACOMP] = src[1];
506 }
507
508 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
509 * returning 4 GLfloats.
510 */
511 static void FETCH(luminance_alpha_f16)( const struct gl_texture_image *texImage,
512 GLint i, GLint j, GLint k, GLchan *texel )
513 {
514 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 2 );
515 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
516 texel[GCOMP] =
517 texel[BCOMP] = texel[RCOMP];
518 UNCLAMPED_FLOAT_TO_CHAN(texel[ACOMP], _mesa_half_to_float(src[1]));
519 }
520
521 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
522 * returning 4 GLfloats.
523 */
524 static void FETCH(f_luminance_alpha_f16)( const struct gl_texture_image *texImage,
525 GLint i, GLint j, GLint k, GLfloat *texel )
526 {
527 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 2 );
528 texel[RCOMP] =
529 texel[GCOMP] =
530 texel[BCOMP] = _mesa_half_to_float(src[0]);
531 texel[ACOMP] = _mesa_half_to_float(src[1]);
532 }
533
534 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
535 * returning 4 GLchans.
536 */
537 static void FETCH(intensity_f32)( const struct gl_texture_image *texImage,
538 GLint i, GLint j, GLint k, GLchan *texel )
539 {
540 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
541 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], src[0]);
542 texel[GCOMP] =
543 texel[BCOMP] =
544 texel[ACOMP] = texel[RCOMP];
545 }
546
547 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
548 * returning 4 GLfloats.
549 */
550 static void FETCH(f_intensity_f32)( const struct gl_texture_image *texImage,
551 GLint i, GLint j, GLint k, GLfloat *texel )
552 {
553 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
554 texel[RCOMP] =
555 texel[GCOMP] =
556 texel[BCOMP] =
557 texel[ACOMP] = src[0];
558 }
559
560 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
561 * returning 4 GLchans.
562 */
563 static void FETCH(intensity_f16)( const struct gl_texture_image *texImage,
564 GLint i, GLint j, GLint k, GLchan *texel )
565 {
566 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 1 );
567 UNCLAMPED_FLOAT_TO_CHAN(texel[RCOMP], _mesa_half_to_float(src[0]));
568 texel[GCOMP] =
569 texel[BCOMP] =
570 texel[ACOMP] = texel[RCOMP];
571 }
572
573 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
574 * returning 4 GLfloats.
575 */
576 static void FETCH(f_intensity_f16)( const struct gl_texture_image *texImage,
577 GLint i, GLint j, GLint k, GLfloat *texel )
578 {
579 const GLhalfARB *src = HALF_SRC( texImage, i, j, k, 1 );
580 texel[RCOMP] =
581 texel[GCOMP] =
582 texel[BCOMP] =
583 texel[ACOMP] = _mesa_half_to_float(src[0]);
584 }
585
586
587
588 /*
589 * Begin Hardware formats
590 */
591
592 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
593 static void FETCH(rgba8888)( const struct gl_texture_image *texImage,
594 GLint i, GLint j, GLint k, GLchan *texel )
595 {
596 const GLuint s = *UINT_SRC( texImage, i, j, k );
597 texel[RCOMP] = UBYTE_TO_CHAN( (s >> 24) );
598 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
599 texel[BCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
600 texel[ACOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
601 }
602
603 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
604 static void FETCH(f_rgba8888)( const struct gl_texture_image *texImage,
605 GLint i, GLint j, GLint k, GLfloat *texel )
606 {
607 const GLuint s = *UINT_SRC( texImage, i, j, k );
608 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
609 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
610 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
611 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
612 }
613
614
615 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
616 static void FETCH(rgba8888_rev)( const struct gl_texture_image *texImage,
617 GLint i, GLint j, GLint k, GLchan *texel )
618 {
619 const GLuint s = *UINT_SRC( texImage, i, j, k );
620 texel[RCOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
621 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
622 texel[BCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
623 texel[ACOMP] = UBYTE_TO_CHAN( (s >> 24) );
624 }
625
626 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLfloats */
627 static void FETCH(f_rgba8888_rev)( const struct gl_texture_image *texImage,
628 GLint i, GLint j, GLint k, GLfloat *texel )
629 {
630 const GLuint s = *UINT_SRC( texImage, i, j, k );
631 texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
632 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
633 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
634 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
635 }
636
637
638 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
639 static void FETCH(argb8888)( const struct gl_texture_image *texImage,
640 GLint i, GLint j, GLint k, GLchan *texel )
641 {
642 const GLuint s = *UINT_SRC( texImage, i, j, k );
643 texel[RCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
644 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
645 texel[BCOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
646 texel[ACOMP] = UBYTE_TO_CHAN( (s >> 24) );
647 }
648
649 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLfloats */
650 static void FETCH(f_argb8888)( const struct gl_texture_image *texImage,
651 GLint i, GLint j, GLint k, GLfloat *texel )
652 {
653 const GLuint s = *UINT_SRC( texImage, i, j, k );
654 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
655 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
656 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
657 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
658 }
659
660
661 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLchans */
662 static void FETCH(argb8888_rev)( const struct gl_texture_image *texImage,
663 GLint i, GLint j, GLint k, GLchan *texel )
664 {
665 const GLuint s = *UINT_SRC( texImage, i, j, k );
666 texel[RCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
667 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
668 texel[BCOMP] = UBYTE_TO_CHAN( (s >> 24) );
669 texel[ACOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
670 }
671
672
673 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
674 static void FETCH(f_argb8888_rev)( const struct gl_texture_image *texImage,
675 GLint i, GLint j, GLint k, GLfloat *texel )
676 {
677 const GLuint s = *UINT_SRC( texImage, i, j, k );
678 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
679 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
680 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
681 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
682 }
683
684
685 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
686 static void FETCH(rgb888)( const struct gl_texture_image *texImage,
687 GLint i, GLint j, GLint k, GLchan *texel )
688 {
689 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
690 texel[RCOMP] = UBYTE_TO_CHAN( src[2] );
691 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
692 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
693 texel[ACOMP] = CHAN_MAX;
694 }
695
696 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLfloats */
697 static void FETCH(f_rgb888)( const struct gl_texture_image *texImage,
698 GLint i, GLint j, GLint k, GLfloat *texel )
699 {
700 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
701 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
702 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
703 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
704 texel[ACOMP] = CHAN_MAXF;
705 }
706
707
708 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
709 static void FETCH(bgr888)( const struct gl_texture_image *texImage,
710 GLint i, GLint j, GLint k, GLchan *texel )
711 {
712 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
713 texel[RCOMP] = UBYTE_TO_CHAN( src[0] );
714 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
715 texel[BCOMP] = UBYTE_TO_CHAN( src[2] );
716 texel[ACOMP] = CHAN_MAX;
717 }
718
719 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLfloats */
720 static void FETCH(f_bgr888)( const struct gl_texture_image *texImage,
721 GLint i, GLint j, GLint k, GLfloat *texel )
722 {
723 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
724 texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
725 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
726 texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
727 texel[ACOMP] = CHAN_MAXF;
728 }
729
730
731 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
732 static void FETCH(rgb565)( const struct gl_texture_image *texImage,
733 GLint i, GLint j, GLint k, GLchan *texel )
734 {
735 const GLushort *src = USHORT_SRC( texImage, i, j, k );
736 const GLushort s = *src;
737 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) * 255 / 0xf8 );
738 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) * 255 / 0xfc );
739 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) * 255 / 0xf8 );
740 texel[ACOMP] = CHAN_MAX;
741 }
742
743 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
744 static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
745 GLint i, GLint j, GLint k, GLfloat *texel )
746 {
747 const GLushort *src = USHORT_SRC( texImage, i, j, k );
748 const GLushort s = *src;
749 texel[RCOMP] = ((s >> 8) & 0xf8) * (1.0F / 248.0F);
750 texel[GCOMP] = ((s >> 3) & 0xfc) * (1.0F / 252.0F);
751 texel[BCOMP] = ((s << 3) & 0xf8) * (1.0F / 248.0F);
752 texel[ACOMP] = CHAN_MAXF;
753 }
754
755
756 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
757 static void FETCH(rgb565_rev)( const struct gl_texture_image *texImage,
758 GLint i, GLint j, GLint k, GLchan *texel )
759 {
760 const GLushort *src = USHORT_SRC( texImage, i, j, k );
761 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
762 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) * 255 / 0xf8 );
763 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) * 255 / 0xfc );
764 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) * 255 / 0xf8 );
765 texel[ACOMP] = CHAN_MAX;
766 }
767
768 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLfloats */
769 static void FETCH(f_rgb565_rev)( const struct gl_texture_image *texImage,
770 GLint i, GLint j, GLint k, GLfloat *texel )
771 {
772 const GLushort *src = USHORT_SRC( texImage, i, j, k );
773 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
774 texel[RCOMP] = ((s >> 8) & 0xf8) * (1.0F / 248.0F);
775 texel[GCOMP] = ((s >> 3) & 0xfc) * (1.0F / 252.0F);
776 texel[BCOMP] = ((s << 3) & 0xf8) * (1.0F / 248.0F);
777 texel[ACOMP] = CHAN_MAXF;
778 }
779
780
781 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
782 static void FETCH(argb4444)( const struct gl_texture_image *texImage,
783 GLint i, GLint j, GLint k, GLchan *texel )
784 {
785 const GLushort *src = USHORT_SRC( texImage, i, j, k );
786 const GLushort s = *src;
787 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf );
788 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf );
789 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf );
790 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) * 255 / 0xf );
791 }
792
793 /* Fetch texel from 1D, 2D or 3D argb4444 texture, return 4 GLfloats */
794 static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
795 GLint i, GLint j, GLint k, GLfloat *texel )
796 {
797 const GLushort *src = USHORT_SRC( texImage, i, j, k );
798 const GLushort s = *src;
799 texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
800 texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
801 texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
802 texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
803 }
804
805
806 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
807 static void FETCH(argb4444_rev)( const struct gl_texture_image *texImage,
808 GLint i, GLint j, GLint k, GLchan *texel )
809 {
810 const GLushort s = *USHORT_SRC( texImage, i, j, k );
811 texel[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf );
812 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) * 255 / 0xf );
813 texel[BCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf );
814 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf );
815 }
816
817 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLfloats */
818 static void FETCH(f_argb4444_rev)( const struct gl_texture_image *texImage,
819 GLint i, GLint j, GLint k, GLfloat *texel )
820 {
821 const GLushort s = *USHORT_SRC( texImage, i, j, k );
822 texel[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
823 texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
824 texel[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
825 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
826 }
827
828
829 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
830 static void FETCH(argb1555)( const struct gl_texture_image *texImage,
831 GLint i, GLint j, GLint k, GLchan *texel )
832 {
833 const GLushort *src = USHORT_SRC( texImage, i, j, k );
834 const GLushort s = *src;
835 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0x1f) * 255 / 0x1f );
836 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0x1f) * 255 / 0x1f );
837 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0x1f) * 255 / 0x1f );
838 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
839 }
840
841 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLfloats */
842 static void FETCH(f_argb1555)( const struct gl_texture_image *texImage,
843 GLint i, GLint j, GLint k, GLfloat *texel )
844 {
845 const GLushort *src = USHORT_SRC( texImage, i, j, k );
846 const GLushort s = *src;
847 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
848 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
849 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
850 texel[ACOMP] = ((s >> 15) & 0x01);
851 }
852
853
854 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
855 static void FETCH(argb1555_rev)( const struct gl_texture_image *texImage,
856 GLint i, GLint j, GLint k, GLchan *texel )
857 {
858 const GLushort *src = USHORT_SRC( texImage, i, j, k );
859 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
860 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0x1f) * 255 / 0x1f );
861 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0x1f) * 255 / 0x1f );
862 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0x1f) * 255 / 0x1f );
863 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
864 }
865
866 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLfloats */
867 static void FETCH(f_argb1555_rev)( const struct gl_texture_image *texImage,
868 GLint i, GLint j, GLint k, GLfloat *texel )
869 {
870 const GLushort *src = USHORT_SRC( texImage, i, j, k );
871 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
872 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
873 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
874 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
875 texel[ACOMP] = ((s >> 15) & 0x01);
876 }
877
878
879 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
880 static void FETCH(al88)( const struct gl_texture_image *texImage,
881 GLint i, GLint j, GLint k, GLchan *texel )
882 {
883 const GLushort s = *USHORT_SRC( texImage, i, j, k );
884 texel[RCOMP] =
885 texel[GCOMP] =
886 texel[BCOMP] = UBYTE_TO_CHAN( s & 0xff );
887 texel[ACOMP] = UBYTE_TO_CHAN( s >> 8 );
888 }
889
890 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLfloats */
891 static void FETCH(f_al88)( const struct gl_texture_image *texImage,
892 GLint i, GLint j, GLint k, GLfloat *texel )
893 {
894 const GLushort s = *USHORT_SRC( texImage, i, j, k );
895 texel[RCOMP] =
896 texel[GCOMP] =
897 texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
898 texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
899 }
900
901
902 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
903 static void FETCH(al88_rev)( const struct gl_texture_image *texImage,
904 GLint i, GLint j, GLint k, GLchan *texel )
905 {
906 const GLushort s = *USHORT_SRC( texImage, i, j, k );
907 texel[RCOMP] =
908 texel[GCOMP] =
909 texel[BCOMP] = UBYTE_TO_CHAN( s >> 8 );
910 texel[ACOMP] = UBYTE_TO_CHAN( s & 0xff );
911 }
912
913 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLfloats */
914 static void FETCH(f_al88_rev)( const struct gl_texture_image *texImage,
915 GLint i, GLint j, GLint k, GLfloat *texel )
916 {
917 const GLushort s = *USHORT_SRC( texImage, i, j, k );
918 texel[RCOMP] =
919 texel[GCOMP] =
920 texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
921 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
922 }
923
924
925 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
926 static void FETCH(rgb332)( const struct gl_texture_image *texImage,
927 GLint i, GLint j, GLint k, GLchan *texel )
928 {
929 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
930 const GLubyte s = *src;
931 texel[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xe0) * 255 / 0xe0 );
932 texel[GCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xe0) * 255 / 0xe0 );
933 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 6) & 0xc0) * 255 / 0xc0 );
934 texel[ACOMP] = CHAN_MAX;
935 }
936
937 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLfloats */
938 static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
939 GLint i, GLint j, GLint k, GLfloat *texel )
940 {
941 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
942 const GLubyte s = *src;
943 texel[RCOMP] = ((s ) & 0xe0) * (1.0F / 224.0F);
944 texel[GCOMP] = ((s << 3) & 0xe0) * (1.0F / 224.0F);
945 texel[BCOMP] = ((s << 6) & 0xc0) * (1.0F / 192.0F);
946 texel[ACOMP] = CHAN_MAXF;
947 }
948
949
950 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
951 static void FETCH(a8)( const struct gl_texture_image *texImage,
952 GLint i, GLint j, GLint k, GLchan *texel )
953 {
954 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
955 texel[RCOMP] =
956 texel[GCOMP] =
957 texel[BCOMP] = 0;
958 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
959 }
960
961 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLfloats */
962 static void FETCH(f_a8)( const struct gl_texture_image *texImage,
963 GLint i, GLint j, GLint k, GLfloat *texel )
964 {
965 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
966 texel[RCOMP] =
967 texel[GCOMP] =
968 texel[BCOMP] = 0.0;
969 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
970 }
971
972
973 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
974 static void FETCH(l8)( const struct gl_texture_image *texImage,
975 GLint i, GLint j, GLint k, GLchan *texel )
976 {
977 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
978 texel[RCOMP] =
979 texel[GCOMP] =
980 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
981 texel[ACOMP] = CHAN_MAX;
982 }
983
984 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLfloats */
985 static void FETCH(f_l8)( const struct gl_texture_image *texImage,
986 GLint i, GLint j, GLint k, GLfloat *texel )
987 {
988 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
989 texel[RCOMP] =
990 texel[GCOMP] =
991 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
992 texel[ACOMP] = CHAN_MAXF;
993 }
994
995
996 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
997 static void FETCH(i8)( const struct gl_texture_image *texImage,
998 GLint i, GLint j, GLint k, GLchan *texel )
999 {
1000 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
1001 texel[RCOMP] =
1002 texel[GCOMP] =
1003 texel[BCOMP] =
1004 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
1005 }
1006
1007 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLfloats */
1008 static void FETCH(f_i8)( const struct gl_texture_image *texImage,
1009 GLint i, GLint j, GLint k, GLfloat *texel )
1010 {
1011 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
1012 texel[RCOMP] =
1013 texel[GCOMP] =
1014 texel[BCOMP] =
1015 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1016 }
1017
1018
1019 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1020 * color table, and return 4 GLchans.
1021 */
1022 static void FETCH(ci8)( const struct gl_texture_image *texImage,
1023 GLint i, GLint j, GLint k, GLchan *texel )
1024 {
1025 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
1026 const GLuint index = *src;
1027 const struct gl_color_table *palette;
1028 const GLchan *table;
1029 GET_CURRENT_CONTEXT(ctx);
1030
1031 if (ctx->Texture.SharedPalette) {
1032 palette = &ctx->Texture.Palette;
1033 }
1034 else {
1035 palette = &texImage->TexObject->Palette;
1036 }
1037 if (palette->Size == 0)
1038 return; /* undefined results */
1039 ASSERT(palette->Type != GL_FLOAT);
1040 table = (const GLchan *) palette->Table;
1041
1042 switch (palette->Format) {
1043 case GL_ALPHA:
1044 texel[RCOMP] =
1045 texel[GCOMP] =
1046 texel[BCOMP] = 0;
1047 texel[ACOMP] = table[index];
1048 return;
1049 case GL_LUMINANCE:
1050 texel[RCOMP] =
1051 texel[GCOMP] =
1052 texel[BCOMP] = table[index];
1053 texel[ACOMP] = CHAN_MAX;
1054 break;
1055 case GL_INTENSITY:
1056 texel[RCOMP] =
1057 texel[GCOMP] =
1058 texel[BCOMP] =
1059 texel[ACOMP] = table[index];
1060 return;
1061 case GL_LUMINANCE_ALPHA:
1062 texel[RCOMP] =
1063 texel[GCOMP] =
1064 texel[BCOMP] = table[index * 2 + 0];
1065 texel[ACOMP] = table[index * 2 + 1];
1066 return;
1067 case GL_RGB:
1068 texel[RCOMP] = table[index * 3 + 0];
1069 texel[GCOMP] = table[index * 3 + 1];
1070 texel[BCOMP] = table[index * 3 + 2];
1071 texel[ACOMP] = CHAN_MAX;
1072 return;
1073 case GL_RGBA:
1074 texel[RCOMP] = table[index * 4 + 0];
1075 texel[GCOMP] = table[index * 4 + 1];
1076 texel[BCOMP] = table[index * 4 + 2];
1077 texel[ACOMP] = table[index * 4 + 3];
1078 return;
1079 default:
1080 _mesa_problem(ctx, "Bad palette format in palette_sample");
1081 }
1082 }
1083
1084
1085 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1086 * color table, and return 4 GLfloats.
1087 */
1088 static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
1089 GLint i, GLint j, GLint k, GLfloat *texel )
1090 {
1091 GLchan rgba[4];
1092 /* Sample as GLchan */
1093 FETCH(ci8)(texImage, i, j, k, rgba);
1094 /* and return as floats */
1095 texel[RCOMP] = CHAN_TO_FLOAT(rgba[RCOMP]);
1096 texel[GCOMP] = CHAN_TO_FLOAT(rgba[GCOMP]);
1097 texel[BCOMP] = CHAN_TO_FLOAT(rgba[BCOMP]);
1098 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
1099 }
1100
1101
1102 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
1103 /* We convert YCbCr to RGB here */
1104 /* XXX this may break if GLchan != GLubyte */
1105 static void FETCH(ycbcr)( const struct gl_texture_image *texImage,
1106 GLint i, GLint j, GLint k, GLchan *texel )
1107 {
1108 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
1109 const GLushort *src1 = src0 + 1; /* odd */
1110 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1111 const GLubyte cb = *src0 & 0xff; /* chroma U */
1112 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1113 const GLubyte cr = *src1 & 0xff; /* chroma V */
1114 GLint r, g, b;
1115 if (i & 1) {
1116 /* odd pixel: use y1,cr,cb */
1117 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
1118 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1119 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
1120 }
1121 else {
1122 /* even pixel: use y0,cr,cb */
1123 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
1124 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1125 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
1126 }
1127 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
1128 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
1129 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
1130 texel[ACOMP] = CHAN_MAX;
1131 }
1132
1133 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats */
1134 /* We convert YCbCr to RGB here */
1135 static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
1136 GLint i, GLint j, GLint k, GLfloat *texel )
1137 {
1138 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
1139 const GLushort *src1 = src0 + 1; /* odd */
1140 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1141 const GLubyte cb = *src0 & 0xff; /* chroma U */
1142 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1143 const GLubyte cr = *src1 & 0xff; /* chroma V */
1144 GLfloat r, g, b;
1145 if (i & 1) {
1146 /* odd pixel: use y1,cr,cb */
1147 r = (1.164 * (y1-16) + 1.596 * (cr-128));
1148 g = (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1149 b = (1.164 * (y1-16) + 2.018 * (cb-128));
1150 }
1151 else {
1152 /* even pixel: use y0,cr,cb */
1153 r = (1.164 * (y0-16) + 1.596 * (cr-128));
1154 g = (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1155 b = (1.164 * (y0-16) + 2.018 * (cb-128));
1156 }
1157 /* XXX remove / 255 here by tweaking arithmetic above */
1158 r /= 255.0;
1159 g /= 255.0;
1160 b /= 255.0;
1161 /* XXX should we really clamp??? */
1162 texel[RCOMP] = CLAMP(r, 0.0, 1.0);
1163 texel[GCOMP] = CLAMP(g, 0.0, 1.0);
1164 texel[BCOMP] = CLAMP(b, 0.0, 1.0);
1165 texel[ACOMP] = CHAN_MAXF;
1166 }
1167
1168
1169 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
1170 /* We convert YCbCr to RGB here */
1171 /* XXX this may break if GLchan != GLubyte */
1172 static void FETCH(ycbcr_rev)( const struct gl_texture_image *texImage,
1173 GLint i, GLint j, GLint k, GLchan *texel )
1174 {
1175 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
1176 const GLushort *src1 = src0 + 1; /* odd */
1177 const GLubyte y0 = *src0 & 0xff; /* luminance */
1178 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1179 const GLubyte y1 = *src1 & 0xff; /* luminance */
1180 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1181 GLint r, g, b;
1182 if (i & 1) {
1183 /* odd pixel: use y1,cr,cb */
1184 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
1185 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1186 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
1187 }
1188 else {
1189 /* even pixel: use y0,cr,cb */
1190 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
1191 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1192 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
1193 }
1194 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
1195 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
1196 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
1197 texel[ACOMP] = CHAN_MAX;
1198 }
1199
1200 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats */
1201 /* We convert YCbCr to RGB here */
1202 static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
1203 GLint i, GLint j, GLint k, GLfloat *texel )
1204 {
1205 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
1206 const GLushort *src1 = src0 + 1; /* odd */
1207 const GLubyte y0 = *src0 & 0xff; /* luminance */
1208 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1209 const GLubyte y1 = *src1 & 0xff; /* luminance */
1210 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1211 GLfloat r, g, b;
1212 if (i & 1) {
1213 /* odd pixel: use y1,cr,cb */
1214 r = (1.164 * (y1-16) + 1.596 * (cr-128));
1215 g = (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1216 b = (1.164 * (y1-16) + 2.018 * (cb-128));
1217 }
1218 else {
1219 /* even pixel: use y0,cr,cb */
1220 r = (1.164 * (y0-16) + 1.596 * (cr-128));
1221 g = (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1222 b = (1.164 * (y0-16) + 2.018 * (cb-128));
1223 }
1224 /* XXX remove / 255 here by tweaking arithmetic above */
1225 r /= 255.0;
1226 g /= 255.0;
1227 b /= 255.0;
1228 /* XXX should we really clamp??? */
1229 texel[RCOMP] = CLAMP(r, 0.0, 1.0);
1230 texel[GCOMP] = CLAMP(g, 0.0, 1.0);
1231 texel[BCOMP] = CLAMP(b, 0.0, 1.0);
1232 texel[ACOMP] = CHAN_MAXF;
1233 }
1234
1235
1236
1237 #undef CHAN_SRC
1238 #undef UBYTE_SRC
1239 #undef USHORT_SRC
1240 #undef UINT_SRC
1241 #undef FLOAT_SRC
1242 #undef HALF_SRC
1243 #undef FETCH
1244 #undef DIM