877c29c9b74d5fbf65429b203f74a03b26ea98ea
[profile/ivi/mesa.git] / src / mesa / swrast / s_texfetch_tmp.h
1 /*
2  * Mesa 3-D graphics library
3  * Version:  7.7
4  *
5  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
6  * Copyright (c) 2008-2009  VMware, Inc.
7  *
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:
14  *
15  * The above copyright notice and this permission notice shall be included
16  * in all copies or substantial portions of the Software.
17  *
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.
24  */
25
26
27 /**
28  * \file texfetch_tmp.h
29  * Texel fetch functions template.
30  * 
31  * This template file is used by texfetch.c to generate texel fetch functions
32  * for 1-D, 2-D and 3-D texture images. 
33  *
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.
37  * 
38  * \author Gareth Hughes
39  * \author Brian Paul
40  */
41
42
43 #if DIM == 1
44
45 #define TEXEL_ADDR( type, image, i, j, k, size ) \
46         ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
47
48 #define FETCH(x) fetch_texel_1d_##x
49
50 #elif DIM == 2
51
52 #define TEXEL_ADDR( type, image, i, j, k, size )                        \
53         ((void) (k),                                                    \
54          ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
55
56 #define FETCH(x) fetch_texel_2d_##x
57
58 #elif DIM == 3
59
60 #define TEXEL_ADDR( type, image, i, j, k, size )                        \
61         ((type *)(image)->Data + ((image)->ImageOffsets[k]              \
62              + (image)->RowStride * (j) + (i)) * (size))
63
64 #define FETCH(x) fetch_texel_3d_##x
65
66 #else
67 #error  illegal number of texture dimensions
68 #endif
69
70
71 /* MESA_FORMAT_Z32 ***********************************************************/
72
73 /* Fetch depth texel from 1D, 2D or 3D 32-bit depth texture,
74  * returning 1 GLfloat.
75  * Note: no GLchan version of this function.
76  */
77 static void FETCH(f_z32)( const struct swrast_texture_image *texImage,
78                           GLint i, GLint j, GLint k, GLfloat *texel )
79 {
80    const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
81    texel[0] = src[0] * (1.0F / 0xffffffff);
82 }
83
84 #if DIM == 3
85 static void store_texel_z32(struct swrast_texture_image *texImage,
86                             GLint i, GLint j, GLint k, const void *texel)
87 {
88    const GLuint *depth = (const GLuint *) texel;
89    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
90    dst[0] = *depth;
91 }
92 #endif
93
94
95 /* MESA_FORMAT_Z16 ***********************************************************/
96
97 /* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
98  * returning 1 GLfloat.
99  * Note: no GLchan version of this function.
100  */
101 static void FETCH(f_z16)(const struct swrast_texture_image *texImage,
102                          GLint i, GLint j, GLint k, GLfloat *texel )
103 {
104    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
105    texel[0] = src[0] * (1.0F / 65535.0F);
106 }
107
108 #if DIM == 3
109 static void store_texel_z16(struct swrast_texture_image *texImage,
110                             GLint i, GLint j, GLint k, const void *texel)
111 {
112    const GLushort *depth = (const GLushort *) texel;
113    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
114    dst[0] = *depth;
115 }
116 #endif
117
118
119 /* MESA_FORMAT_RGBA_F32 ******************************************************/
120
121 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
122  */
123 static void FETCH(f_rgba_f32)( const struct swrast_texture_image *texImage,
124                                GLint i, GLint j, GLint k, GLfloat *texel )
125 {
126    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
127    texel[RCOMP] = src[0];
128    texel[GCOMP] = src[1];
129    texel[BCOMP] = src[2];
130    texel[ACOMP] = src[3];
131 }
132
133 #if DIM == 3
134 static void store_texel_rgba_f32(struct swrast_texture_image *texImage,
135                                  GLint i, GLint j, GLint k, const void *texel)
136 {
137    const GLfloat *depth = (const GLfloat *) texel;
138    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
139    dst[0] = depth[RCOMP];
140    dst[1] = depth[GCOMP];
141    dst[2] = depth[BCOMP];
142    dst[3] = depth[ACOMP];
143 }
144 #endif
145
146
147 /* MESA_FORMAT_RGBA_F16 ******************************************************/
148
149 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
150  * returning 4 GLfloats.
151  */
152 static void FETCH(f_rgba_f16)( const struct swrast_texture_image *texImage,
153                                GLint i, GLint j, GLint k, GLfloat *texel )
154 {
155    const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
156    texel[RCOMP] = _mesa_half_to_float(src[0]);
157    texel[GCOMP] = _mesa_half_to_float(src[1]);
158    texel[BCOMP] = _mesa_half_to_float(src[2]);
159    texel[ACOMP] = _mesa_half_to_float(src[3]);
160 }
161
162 #if DIM == 3
163 static void store_texel_rgba_f16(struct swrast_texture_image *texImage,
164                                  GLint i, GLint j, GLint k, const void *texel)
165 {
166    const GLfloat *src = (const GLfloat *) texel;
167    GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
168    dst[0] = _mesa_float_to_half(src[RCOMP]);
169    dst[1] = _mesa_float_to_half(src[GCOMP]);
170    dst[2] = _mesa_float_to_half(src[BCOMP]);
171    dst[3] = _mesa_float_to_half(src[ACOMP]);
172 }
173 #endif
174
175 /* MESA_FORMAT_RGB_F32 *******************************************************/
176
177 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
178  * returning 4 GLfloats.
179  */
180 static void FETCH(f_rgb_f32)( const struct swrast_texture_image *texImage,
181                               GLint i, GLint j, GLint k, GLfloat *texel )
182 {
183    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
184    texel[RCOMP] = src[0];
185    texel[GCOMP] = src[1];
186    texel[BCOMP] = src[2];
187    texel[ACOMP] = 1.0F;
188 }
189
190 #if DIM == 3
191 static void store_texel_rgb_f32(struct swrast_texture_image *texImage,
192                                  GLint i, GLint j, GLint k, const void *texel)
193 {
194    const GLfloat *src = (const GLfloat *) texel;
195    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
196    dst[0] = src[RCOMP];
197    dst[1] = src[GCOMP];
198    dst[2] = src[BCOMP];
199 }
200 #endif
201
202
203 /* MESA_FORMAT_RGB_F16 *******************************************************/
204
205 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
206  * returning 4 GLfloats.
207  */
208 static void FETCH(f_rgb_f16)( const struct swrast_texture_image *texImage,
209                               GLint i, GLint j, GLint k, GLfloat *texel )
210 {
211    const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
212    texel[RCOMP] = _mesa_half_to_float(src[0]);
213    texel[GCOMP] = _mesa_half_to_float(src[1]);
214    texel[BCOMP] = _mesa_half_to_float(src[2]);
215    texel[ACOMP] = 1.0F;
216 }
217
218 #if DIM == 3
219 static void store_texel_rgb_f16(struct swrast_texture_image *texImage,
220                                 GLint i, GLint j, GLint k, const void *texel)
221 {
222    const GLfloat *src = (const GLfloat *) texel;
223    GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
224    dst[0] = _mesa_float_to_half(src[RCOMP]);
225    dst[1] = _mesa_float_to_half(src[GCOMP]);
226    dst[2] = _mesa_float_to_half(src[BCOMP]);
227 }
228 #endif
229
230
231 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
232
233 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
234  * returning 4 GLfloats.
235  */
236 static void FETCH(f_alpha_f32)( const struct swrast_texture_image *texImage,
237                               GLint i, GLint j, GLint k, GLfloat *texel )
238 {
239    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
240    texel[RCOMP] =
241    texel[GCOMP] =
242    texel[BCOMP] = 0.0F;
243    texel[ACOMP] = src[0];
244 }
245
246 #if DIM == 3
247 static void store_texel_alpha_f32(struct swrast_texture_image *texImage,
248                                   GLint i, GLint j, GLint k, const void *texel)
249 {
250    const GLfloat *rgba = (const GLfloat *) texel;
251    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
252    dst[0] = rgba[ACOMP];
253 }
254 #endif
255
256
257 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
258
259 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
260  * returning 4 GLfloats.
261  */
262 static void FETCH(f_alpha_f16)( const struct swrast_texture_image *texImage,
263                               GLint i, GLint j, GLint k, GLfloat *texel )
264 {
265    const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
266    texel[RCOMP] =
267    texel[GCOMP] =
268    texel[BCOMP] = 0.0F;
269    texel[ACOMP] = _mesa_half_to_float(src[0]);
270 }
271
272 #if DIM == 3
273 static void store_texel_alpha_f16(struct swrast_texture_image *texImage,
274                                   GLint i, GLint j, GLint k, const void *texel)
275 {
276    const GLfloat *rgba = (const GLfloat *) texel;
277    GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
278    dst[0] = _mesa_float_to_half(rgba[ACOMP]);
279 }
280 #endif
281
282
283 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
284
285 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
286  * returning 4 GLfloats.
287  */
288 static void FETCH(f_luminance_f32)( const struct swrast_texture_image *texImage,
289                                     GLint i, GLint j, GLint k, GLfloat *texel )
290 {
291    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
292    texel[RCOMP] =
293    texel[GCOMP] =
294    texel[BCOMP] = src[0];
295    texel[ACOMP] = 1.0F;
296 }
297
298 #if DIM == 3
299 static void store_texel_luminance_f32(struct swrast_texture_image *texImage,
300                                   GLint i, GLint j, GLint k, const void *texel)
301 {
302    const GLfloat *rgba = (const GLfloat *) texel;
303    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
304    dst[0] = rgba[RCOMP];
305 }
306 #endif
307
308
309 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
310
311 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
312  * returning 4 GLfloats.
313  */
314 static void FETCH(f_luminance_f16)( const struct swrast_texture_image *texImage,
315                                     GLint i, GLint j, GLint k, GLfloat *texel )
316 {
317    const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
318    texel[RCOMP] =
319    texel[GCOMP] =
320    texel[BCOMP] = _mesa_half_to_float(src[0]);
321    texel[ACOMP] = 1.0F;
322 }
323
324 #if DIM == 3
325 static void store_texel_luminance_f16(struct swrast_texture_image *texImage,
326                                   GLint i, GLint j, GLint k, const void *texel)
327 {
328    const GLfloat *rgba = (const GLfloat *) texel;
329    GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
330    dst[0] = _mesa_float_to_half(rgba[RCOMP]);
331 }
332 #endif
333
334
335 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
336
337 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
338  * returning 4 GLfloats.
339  */
340 static void FETCH(f_luminance_alpha_f32)( const struct swrast_texture_image *texImage,
341                                     GLint i, GLint j, GLint k, GLfloat *texel )
342 {
343    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
344    texel[RCOMP] =
345    texel[GCOMP] =
346    texel[BCOMP] = src[0];
347    texel[ACOMP] = src[1];
348 }
349
350 #if DIM == 3
351 static void store_texel_luminance_alpha_f32(struct swrast_texture_image *texImage,
352                                   GLint i, GLint j, GLint k, const void *texel)
353 {
354    const GLfloat *rgba = (const GLfloat *) texel;
355    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
356    dst[0] = rgba[RCOMP];
357    dst[1] = rgba[ACOMP];
358 }
359 #endif
360
361
362 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
363
364 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
365  * returning 4 GLfloats.
366  */
367 static void FETCH(f_luminance_alpha_f16)( const struct swrast_texture_image *texImage,
368                                     GLint i, GLint j, GLint k, GLfloat *texel )
369 {
370    const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
371    texel[RCOMP] =
372    texel[GCOMP] =
373    texel[BCOMP] = _mesa_half_to_float(src[0]);
374    texel[ACOMP] = _mesa_half_to_float(src[1]);
375 }
376
377 #if DIM == 3
378 static void store_texel_luminance_alpha_f16(struct swrast_texture_image *texImage,
379                                   GLint i, GLint j, GLint k, const void *texel)
380 {
381    const GLfloat *rgba = (const GLfloat *) texel;
382    GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
383    dst[0] = _mesa_float_to_half(rgba[RCOMP]);
384    dst[1] = _mesa_float_to_half(rgba[ACOMP]);
385 }
386 #endif
387
388
389 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
390
391 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
392  * returning 4 GLfloats.
393  */
394 static void FETCH(f_intensity_f32)( const struct swrast_texture_image *texImage,
395                                     GLint i, GLint j, GLint k, GLfloat *texel )
396 {
397    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
398    texel[RCOMP] =
399    texel[GCOMP] =
400    texel[BCOMP] =
401    texel[ACOMP] = src[0];
402 }
403
404 #if DIM == 3
405 static void store_texel_intensity_f32(struct swrast_texture_image *texImage,
406                                   GLint i, GLint j, GLint k, const void *texel)
407 {
408    const GLfloat *rgba = (const GLfloat *) texel;
409    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
410    dst[0] = rgba[RCOMP];
411 }
412 #endif
413
414
415 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
416
417 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
418  * returning 4 GLfloats.
419  */
420 static void FETCH(f_intensity_f16)( const struct swrast_texture_image *texImage,
421                                     GLint i, GLint j, GLint k, GLfloat *texel )
422 {
423    const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
424    texel[RCOMP] =
425    texel[GCOMP] =
426    texel[BCOMP] =
427    texel[ACOMP] = _mesa_half_to_float(src[0]);
428 }
429
430 #if DIM == 3
431 static void store_texel_intensity_f16(struct swrast_texture_image *texImage,
432                                   GLint i, GLint j, GLint k, const void *texel)
433 {
434    const GLfloat *rgba = (const GLfloat *) texel;
435    GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
436    dst[0] = _mesa_float_to_half(rgba[RCOMP]);
437 }
438 #endif
439
440
441 /* MESA_FORMAT_R_FLOAT32 *****************************************************/
442
443 /* Fetch texel from 1D, 2D or 3D R_FLOAT32 texture,
444  * returning 4 GLfloats.
445  */
446 static void FETCH(f_r_f32)( const struct swrast_texture_image *texImage,
447                             GLint i, GLint j, GLint k, GLfloat *texel )
448 {
449    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
450    texel[RCOMP] = src[0];
451    texel[GCOMP] = 0.0F;
452    texel[BCOMP] = 0.0F;
453    texel[ACOMP] = 1.0F;
454 }
455
456 #if DIM == 3
457 static void store_texel_r_f32(struct swrast_texture_image *texImage,
458                               GLint i, GLint j, GLint k, const void *texel)
459 {
460    const GLfloat *rgba = (const GLfloat *) texel;
461    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
462    dst[0] = rgba[RCOMP];
463 }
464 #endif
465
466
467 /* MESA_FORMAT_R_FLOAT16 *****************************************************/
468
469 /* Fetch texel from 1D, 2D or 3D R_FLOAT16 texture,
470  * returning 4 GLfloats.
471  */
472 static void FETCH(f_r_f16)( const struct swrast_texture_image *texImage,
473                             GLint i, GLint j, GLint k, GLfloat *texel )
474 {
475    const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
476    texel[RCOMP] = _mesa_half_to_float(src[0]);
477    texel[GCOMP] = 0.0F;
478    texel[BCOMP] = 0.0F;
479    texel[ACOMP] = 1.0F;
480 }
481
482 #if DIM == 3
483 static void store_texel_r_f16(struct swrast_texture_image *texImage,
484                               GLint i, GLint j, GLint k, const void *texel)
485 {
486    const GLfloat *rgba = (const GLfloat *) texel;
487    GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
488    dst[0] = _mesa_float_to_half(rgba[RCOMP]);
489 }
490 #endif
491
492
493 /* MESA_FORMAT_RG_FLOAT32 ****************************************************/
494
495 /* Fetch texel from 1D, 2D or 3D RG_FLOAT32 texture,
496  * returning 4 GLfloats.
497  */
498 static void FETCH(f_rg_f32)( const struct swrast_texture_image *texImage,
499                              GLint i, GLint j, GLint k, GLfloat *texel )
500 {
501    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
502    texel[RCOMP] = src[0];
503    texel[GCOMP] = src[1];
504    texel[BCOMP] = 0.0F;
505    texel[ACOMP] = 1.0F;
506 }
507
508 #if DIM == 3
509 static void store_texel_rg_f32(struct swrast_texture_image *texImage,
510                                GLint i, GLint j, GLint k, const void *texel)
511 {
512    const GLfloat *rgba = (const GLfloat *) texel;
513    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
514    dst[0] = rgba[RCOMP];
515    dst[1] = rgba[GCOMP];
516 }
517 #endif
518
519
520 /* MESA_FORMAT_RG_FLOAT16 ****************************************************/
521
522 /* Fetch texel from 1D, 2D or 3D RG_FLOAT16 texture,
523  * returning 4 GLfloats.
524  */
525 static void FETCH(f_rg_f16)( const struct swrast_texture_image *texImage,
526                              GLint i, GLint j, GLint k, GLfloat *texel )
527 {
528    const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
529    texel[RCOMP] = _mesa_half_to_float(src[0]);
530    texel[GCOMP] = _mesa_half_to_float(src[1]);
531    texel[BCOMP] = 0.0F;
532    texel[ACOMP] = 1.0F;
533 }
534
535 #if DIM == 3
536 static void store_texel_rg_f16(struct swrast_texture_image *texImage,
537                                GLint i, GLint j, GLint k, const void *texel)
538 {
539    const GLfloat *rgba = (const GLfloat *) texel;
540    GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
541    dst[0] = _mesa_float_to_half(rgba[RCOMP]);
542    dst[1] = _mesa_float_to_half(rgba[GCOMP]);
543 }
544 #endif
545
546
547 /*
548  * Begin Hardware formats
549  */
550
551 /* MESA_FORMAT_RGBA8888 ******************************************************/
552
553 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
554 static void FETCH(f_rgba8888)( const struct swrast_texture_image *texImage,
555                                GLint i, GLint j, GLint k, GLfloat *texel )
556 {
557    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
558    texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
559    texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
560    texel[BCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
561    texel[ACOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
562 }
563
564
565
566 #if DIM == 3
567 static void store_texel_rgba8888(struct swrast_texture_image *texImage,
568                                  GLint i, GLint j, GLint k, const void *texel)
569 {
570    const GLubyte *rgba = (const GLubyte *) texel;
571    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
572    *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
573 }
574 #endif
575
576
577 /* MESA_FORMAT_RGBA888_REV ***************************************************/
578
579 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
580 static void FETCH(f_rgba8888_rev)( const struct swrast_texture_image *texImage,
581                                    GLint i, GLint j, GLint k, GLfloat *texel )
582 {
583    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
584    texel[RCOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
585    texel[GCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
586    texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
587    texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
588 }
589
590 #if DIM == 3
591 static void store_texel_rgba8888_rev(struct swrast_texture_image *texImage,
592                                   GLint i, GLint j, GLint k, const void *texel)
593 {
594    const GLubyte *rgba = (const GLubyte *) texel;
595    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
596    *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
597 }
598 #endif
599
600
601 /* MESA_FORMAT_ARGB8888 ******************************************************/
602
603 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
604 static void FETCH(f_argb8888)( const struct swrast_texture_image *texImage,
605                                GLint i, GLint j, GLint k, GLfloat *texel )
606 {
607    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
608    texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
609    texel[GCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
610    texel[BCOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
611    texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
612 }
613
614 #if DIM == 3
615 static void store_texel_argb8888(struct swrast_texture_image *texImage,
616                                  GLint i, GLint j, GLint k, const void *texel)
617 {
618    const GLubyte *rgba = (const GLubyte *) texel;
619    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
620    *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
621 }
622 #endif
623
624
625 /* MESA_FORMAT_ARGB8888_REV **************************************************/
626
627 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
628 static void FETCH(f_argb8888_rev)( const struct swrast_texture_image *texImage,
629                                    GLint i, GLint j, GLint k, GLfloat *texel )
630 {
631    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
632    texel[RCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
633    texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
634    texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
635    texel[ACOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
636 }
637
638 #if DIM == 3
639 static void store_texel_argb8888_rev(struct swrast_texture_image *texImage,
640                                   GLint i, GLint j, GLint k, const void *texel)
641 {
642    const GLubyte *rgba = (const GLubyte *) texel;
643    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
644    *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], rgba[ACOMP]);
645 }
646 #endif
647
648
649 /* MESA_FORMAT_RGBX8888 ******************************************************/
650
651 /* Fetch texel from 1D, 2D or 3D rgbx8888 texture, return 4 GLfloats */
652 static void FETCH(f_rgbx8888)( const struct swrast_texture_image *texImage,
653                                GLint i, GLint j, GLint k, GLfloat *texel )
654 {
655    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
656    texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
657    texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
658    texel[BCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
659    texel[ACOMP] = 1.0f;
660 }
661
662 #if DIM == 3
663 static void store_texel_rgbx8888(struct swrast_texture_image *texImage,
664                                  GLint i, GLint j, GLint k, const void *texel)
665 {
666    const GLubyte *rgba = (const GLubyte *) texel;
667    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
668    *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 0xff);
669 }
670 #endif
671
672
673 /* MESA_FORMAT_RGBX888_REV ***************************************************/
674
675 /* Fetch texel from 1D, 2D or 3D rgbx8888_rev texture, return 4 GLchans */
676 static void FETCH(f_rgbx8888_rev)( const struct swrast_texture_image *texImage,
677                                    GLint i, GLint j, GLint k, GLfloat *texel )
678 {
679    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
680    texel[RCOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
681    texel[GCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
682    texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
683    texel[ACOMP] = 1.0f;
684 }
685
686 #if DIM == 3
687 static void store_texel_rgbx8888_rev(struct swrast_texture_image *texImage,
688                                   GLint i, GLint j, GLint k, const void *texel)
689 {
690    const GLubyte *rgba = (const GLubyte *) texel;
691    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
692    *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 0xff);
693 }
694 #endif
695
696
697 /* MESA_FORMAT_XRGB8888 ******************************************************/
698
699 /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
700 static void FETCH(f_xrgb8888)( const struct swrast_texture_image *texImage,
701                                GLint i, GLint j, GLint k, GLfloat *texel )
702 {
703    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
704    texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
705    texel[GCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
706    texel[BCOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
707    texel[ACOMP] = 1.0f;
708 }
709
710 #if DIM == 3
711 static void store_texel_xrgb8888(struct swrast_texture_image *texImage,
712                                  GLint i, GLint j, GLint k, const void *texel)
713 {
714    const GLubyte *rgba = (const GLubyte *) texel;
715    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
716    *dst = PACK_COLOR_8888(0xff, rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
717 }
718 #endif
719
720
721 /* MESA_FORMAT_XRGB8888_REV **************************************************/
722
723 /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
724 static void FETCH(f_xrgb8888_rev)( const struct swrast_texture_image *texImage,
725                                    GLint i, GLint j, GLint k, GLfloat *texel )
726 {
727    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
728    texel[RCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
729    texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
730    texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
731    texel[ACOMP] = 1.0f;
732 }
733
734 #if DIM == 3
735 static void store_texel_xrgb8888_rev(struct swrast_texture_image *texImage,
736                                      GLint i, GLint j, GLint k, const void *texel)
737 {
738    const GLubyte *rgba = (const GLubyte *) texel;
739    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
740    *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], 0xff);
741 }
742 #endif
743
744
745 /* MESA_FORMAT_RGB888 ********************************************************/
746
747 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
748 static void FETCH(f_rgb888)( const struct swrast_texture_image *texImage,
749                              GLint i, GLint j, GLint k, GLfloat *texel )
750 {
751    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
752    texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
753    texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
754    texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
755    texel[ACOMP] = 1.0F;
756 }
757
758 #if DIM == 3
759 static void store_texel_rgb888(struct swrast_texture_image *texImage,
760                                GLint i, GLint j, GLint k, const void *texel)
761 {
762    const GLubyte *rgba = (const GLubyte *) texel;
763    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
764    dst[0] = rgba[BCOMP];
765    dst[1] = rgba[GCOMP];
766    dst[2] = rgba[RCOMP];
767 }
768 #endif
769
770
771 /* MESA_FORMAT_BGR888 ********************************************************/
772
773 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
774 static void FETCH(f_bgr888)( const struct swrast_texture_image *texImage,
775                              GLint i, GLint j, GLint k, GLfloat *texel )
776 {
777    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
778    texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
779    texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
780    texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
781    texel[ACOMP] = 1.0F;
782 }
783
784 #if DIM == 3
785 static void store_texel_bgr888(struct swrast_texture_image *texImage,
786                                GLint i, GLint j, GLint k, const void *texel)
787 {
788    const GLubyte *rgba = (const GLubyte *) texel;
789    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
790    dst[0] = rgba[RCOMP];
791    dst[1] = rgba[GCOMP];
792    dst[2] = rgba[BCOMP];
793 }
794 #endif
795
796
797 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
798    instead of slow (g << 2) * 255 / 252 (always rounds down) */
799
800 /* MESA_FORMAT_RGB565 ********************************************************/
801
802 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
803 static void FETCH(f_rgb565)( const struct swrast_texture_image *texImage,
804                              GLint i, GLint j, GLint k, GLfloat *texel )
805 {
806    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
807    const GLushort s = *src;
808    texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
809    texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
810    texel[BCOMP] = ((s      ) & 0x1f) * (1.0F / 31.0F);
811    texel[ACOMP] = 1.0F;
812 }
813
814 #if DIM == 3
815 static void store_texel_rgb565(struct swrast_texture_image *texImage,
816                                GLint i, GLint j, GLint k, const void *texel)
817 {
818    const GLubyte *rgba = (const GLubyte *) texel;
819    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
820    *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
821 }
822 #endif
823
824
825 /* MESA_FORMAT_RGB565_REV ****************************************************/
826
827 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
828 static void FETCH(f_rgb565_rev)( const struct swrast_texture_image *texImage,
829                                  GLint i, GLint j, GLint k, GLfloat *texel )
830 {
831    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
832    const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
833    texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
834    texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >>  9) & 0x3) );
835    texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >>  2) & 0x7) );
836    texel[ACOMP] = 1.0F;
837 }
838
839 #if DIM == 3
840 static void store_texel_rgb565_rev(struct swrast_texture_image *texImage,
841                                   GLint i, GLint j, GLint k, const void *texel)
842 {
843    const GLchan *rgba = (const GLchan *) texel;
844    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
845    GLushort p = PACK_COLOR_565(CHAN_TO_UBYTE(rgba[RCOMP]),
846                                CHAN_TO_UBYTE(rgba[GCOMP]),
847                                CHAN_TO_UBYTE(rgba[BCOMP]));
848    *dst = (p >> 8) | (p << 8); /* byte swap */
849 }
850 #endif
851
852
853 /* MESA_FORMAT_ARGB4444 ******************************************************/
854
855 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
856 static void FETCH(f_argb4444)( const struct swrast_texture_image *texImage,
857                                GLint i, GLint j, GLint k, GLfloat *texel )
858 {
859    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
860    const GLushort s = *src;
861    texel[RCOMP] = ((s >>  8) & 0xf) * (1.0F / 15.0F);
862    texel[GCOMP] = ((s >>  4) & 0xf) * (1.0F / 15.0F);
863    texel[BCOMP] = ((s      ) & 0xf) * (1.0F / 15.0F);
864    texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
865 }
866
867 #if DIM == 3
868 static void store_texel_argb4444(struct swrast_texture_image *texImage,
869                                  GLint i, GLint j, GLint k, const void *texel)
870 {
871    const GLchan *rgba = (const GLchan *) texel;
872    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
873    *dst = PACK_COLOR_4444(CHAN_TO_UBYTE(rgba[ACOMP]),
874                           CHAN_TO_UBYTE(rgba[RCOMP]),
875                           CHAN_TO_UBYTE(rgba[GCOMP]),
876                           CHAN_TO_UBYTE(rgba[BCOMP]));
877 }
878 #endif
879
880
881 /* MESA_FORMAT_ARGB4444_REV **************************************************/
882
883 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
884 static void FETCH(f_argb4444_rev)( const struct swrast_texture_image *texImage,
885                                    GLint i, GLint j, GLint k, GLfloat *texel )
886 {
887    const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
888    texel[RCOMP] = ((s      ) & 0xf) * (1.0F / 15.0F);
889    texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
890    texel[BCOMP] = ((s >>  8) & 0xf) * (1.0F / 15.0F);
891    texel[ACOMP] = ((s >>  4) & 0xf) * (1.0F / 15.0F);
892 }
893
894 #if DIM == 3
895 static void store_texel_argb4444_rev(struct swrast_texture_image *texImage,
896                                  GLint i, GLint j, GLint k, const void *texel)
897 {
898    const GLchan *rgba = (const GLchan *) texel;
899    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
900    *dst = PACK_COLOR_4444(CHAN_TO_UBYTE(rgba[GCOMP]),
901                           CHAN_TO_UBYTE(rgba[BCOMP]),
902                           CHAN_TO_UBYTE(rgba[ACOMP]),
903                           CHAN_TO_UBYTE(rgba[RCOMP]));
904 }
905 #endif
906
907 /* MESA_FORMAT_RGBA5551 ******************************************************/
908
909 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
910 static void FETCH(f_rgba5551)( const struct swrast_texture_image *texImage,
911                                GLint i, GLint j, GLint k, GLfloat *texel )
912 {
913    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
914    const GLushort s = *src;
915    texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
916    texel[GCOMP] = ((s >>  6) & 0x1f) * (1.0F / 31.0F);
917    texel[BCOMP] = ((s >>  1) & 0x1f) * (1.0F / 31.0F);
918    texel[ACOMP] = ((s      ) & 0x01) * 1.0F;
919 }
920
921 #if DIM == 3
922 static void store_texel_rgba5551(struct swrast_texture_image *texImage,
923                                  GLint i, GLint j, GLint k, const void *texel)
924 {
925    const GLubyte *rgba = (const GLubyte *) texel;
926    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
927    *dst = PACK_COLOR_5551(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
928 }
929 #endif
930
931 /* MESA_FORMAT_ARGB1555 ******************************************************/
932
933 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
934 static void FETCH(f_argb1555)( const struct swrast_texture_image *texImage,
935                              GLint i, GLint j, GLint k, GLfloat *texel )
936 {
937    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
938    const GLushort s = *src;
939    texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
940    texel[GCOMP] = ((s >>  5) & 0x1f) * (1.0F / 31.0F);
941    texel[BCOMP] = ((s >>  0) & 0x1f) * (1.0F / 31.0F);
942    texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
943 }
944
945 #if DIM == 3
946 static void store_texel_argb1555(struct swrast_texture_image *texImage,
947                                  GLint i, GLint j, GLint k, const void *texel)
948 {
949    const GLubyte *rgba = (const GLubyte *) texel;
950    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
951    *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
952 }
953 #endif
954
955
956 /* MESA_FORMAT_ARGB1555_REV **************************************************/
957
958 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
959 static void FETCH(f_argb1555_rev)( const struct swrast_texture_image *texImage,
960                                    GLint i, GLint j, GLint k, GLfloat *texel )
961 {
962    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
963    const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
964    texel[RCOMP] = UBYTE_TO_FLOAT( ((s >>  7) & 0xf8) | ((s >> 12) & 0x7) );
965    texel[GCOMP] = UBYTE_TO_FLOAT( ((s >>  2) & 0xf8) | ((s >>  7) & 0x7) );
966    texel[BCOMP] = UBYTE_TO_FLOAT( ((s <<  3) & 0xf8) | ((s >>  2) & 0x7) );
967    texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
968 }
969
970 #if DIM == 3
971 static void store_texel_argb1555_rev(struct swrast_texture_image *texImage,
972                                  GLint i, GLint j, GLint k, const void *texel)
973 {
974    const GLubyte *rgba = (const GLubyte *) texel;
975    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
976    *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
977 }
978 #endif
979
980
981 /* MESA_FORMAT_ARGB2101010 ***************************************************/
982
983 /* Fetch texel from 1D, 2D or 3D argb2101010 texture, return 4 GLchans */
984 static void FETCH(f_argb2101010)( const struct swrast_texture_image *texImage,
985                                   GLint i, GLint j, GLint k, GLfloat *texel )
986 {
987    const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
988    const GLuint s = *src;
989    texel[RCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F);
990    texel[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F);
991    texel[BCOMP] = ((s >>  0) & 0x3ff) * (1.0F / 1023.0F);
992    texel[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F);
993 }
994
995 #if DIM == 3
996 static void store_texel_argb2101010(struct swrast_texture_image *texImage,
997                                     GLint i, GLint j, GLint k, const void *texel)
998 {
999    const GLchan *rgba = (const GLchan *) texel;
1000    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1001    GLushort r = CHAN_TO_USHORT(rgba[RCOMP]);
1002    GLushort g = CHAN_TO_USHORT(rgba[GCOMP]);
1003    GLushort b = CHAN_TO_USHORT(rgba[BCOMP]);
1004    GLushort a = CHAN_TO_USHORT(rgba[ACOMP]);
1005    *dst = PACK_COLOR_2101010_US(a, r, g, b);
1006 }
1007 #endif
1008
1009
1010 /* MESA_FORMAT_GR88 **********************************************************/
1011
1012 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
1013 static void FETCH(f_gr88)( const struct swrast_texture_image *texImage,
1014                            GLint i, GLint j, GLint k, GLfloat *texel )
1015 {
1016    const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1017    texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
1018    texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
1019    texel[BCOMP] = 0.0;
1020    texel[ACOMP] = 1.0;
1021 }
1022
1023 #if DIM == 3
1024 static void store_texel_gr88(struct swrast_texture_image *texImage,
1025                              GLint i, GLint j, GLint k, const void *texel)
1026 {
1027    const GLchan *rgba = (const GLchan *) texel;
1028    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1029    GLubyte r = CHAN_TO_UBYTE(rgba[RCOMP]);
1030    GLubyte g = CHAN_TO_UBYTE(rgba[GCOMP]);
1031    *dst = PACK_COLOR_88(g, r);
1032 }
1033 #endif
1034
1035
1036 /* MESA_FORMAT_RG88 ******************************************************/
1037
1038 /* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
1039 static void FETCH(f_rg88)( const struct swrast_texture_image *texImage,
1040                            GLint i, GLint j, GLint k, GLfloat *texel )
1041 {
1042    const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1043    texel[RCOMP] = UBYTE_TO_FLOAT( s >> 8 );
1044    texel[GCOMP] = UBYTE_TO_FLOAT( s & 0xff );
1045    texel[BCOMP] = 0.0;
1046    texel[ACOMP] = 1.0;
1047 }
1048
1049 #if DIM == 3
1050 static void store_texel_rg88(struct swrast_texture_image *texImage,
1051                              GLint i, GLint j, GLint k, const void *texel)
1052 {
1053    const GLubyte *rgba = (const GLubyte *) texel;
1054    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1055    *dst = PACK_COLOR_88(rgba[RCOMP], rgba[GCOMP]);
1056 }
1057 #endif
1058
1059
1060 /* MESA_FORMAT_AL44 **********************************************************/
1061
1062 /* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
1063 static void FETCH(f_al44)( const struct swrast_texture_image *texImage,
1064                            GLint i, GLint j, GLint k, GLfloat *texel )
1065 {
1066    const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1067    texel[RCOMP] =
1068    texel[GCOMP] =
1069    texel[BCOMP] = (s & 0xf) * (1.0F / 15.0F);
1070    texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
1071 }
1072
1073 #if DIM == 3
1074 static void store_texel_al44(struct swrast_texture_image *texImage,
1075                              GLint i, GLint j, GLint k, const void *texel)
1076 {
1077    const GLubyte *rgba = (const GLubyte *) texel;
1078    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1079    *dst = PACK_COLOR_44(rgba[ACOMP], rgba[RCOMP]);
1080 }
1081 #endif
1082
1083
1084 /* MESA_FORMAT_AL88 **********************************************************/
1085
1086 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
1087 static void FETCH(f_al88)( const struct swrast_texture_image *texImage,
1088                            GLint i, GLint j, GLint k, GLfloat *texel )
1089 {
1090    const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1091    texel[RCOMP] = 
1092    texel[GCOMP] = 
1093    texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
1094    texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
1095 }
1096
1097 #if DIM == 3
1098 static void store_texel_al88(struct swrast_texture_image *texImage,
1099                              GLint i, GLint j, GLint k, const void *texel)
1100 {
1101    const GLubyte *rgba = (const GLubyte *) texel;
1102    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1103    *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
1104 }
1105 #endif
1106
1107
1108 /* MESA_FORMAT_R8 ************************************************************/
1109
1110 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
1111 static void FETCH(f_r8)(const struct swrast_texture_image *texImage,
1112                         GLint i, GLint j, GLint k, GLfloat *texel)
1113 {
1114    const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1115    texel[RCOMP] = UBYTE_TO_FLOAT(s);
1116    texel[GCOMP] = 0.0;
1117    texel[BCOMP] = 0.0;
1118    texel[ACOMP] = 1.0;
1119 }
1120
1121 #if DIM == 3
1122 static void store_texel_r8(struct swrast_texture_image *texImage,
1123                            GLint i, GLint j, GLint k, const void *texel)
1124 {
1125    const GLubyte *rgba = (const GLubyte *) texel;
1126    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1127    *dst = rgba[RCOMP];
1128 }
1129 #endif
1130
1131
1132 /* MESA_FORMAT_R16 ***********************************************************/
1133
1134 /* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
1135 static void FETCH(f_r16)(const struct swrast_texture_image *texImage,
1136                         GLint i, GLint j, GLint k, GLfloat *texel)
1137 {
1138    const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1139    texel[RCOMP] = USHORT_TO_FLOAT(s);
1140    texel[GCOMP] = 0.0;
1141    texel[BCOMP] = 0.0;
1142    texel[ACOMP] = 1.0;
1143 }
1144
1145 #if DIM == 3
1146 static void store_texel_r16(struct swrast_texture_image *texImage,
1147                             GLint i, GLint j, GLint k, const void *texel)
1148 {
1149    const GLchan *rgba = (const GLchan *) texel;
1150    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1151    *dst = CHAN_TO_USHORT(rgba[RCOMP]);
1152 }
1153 #endif
1154
1155
1156 /* MESA_FORMAT_AL88_REV ******************************************************/
1157
1158 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
1159 static void FETCH(f_al88_rev)( const struct swrast_texture_image *texImage,
1160                                GLint i, GLint j, GLint k, GLfloat *texel )
1161 {
1162    const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1163    texel[RCOMP] = 
1164    texel[GCOMP] = 
1165    texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
1166    texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
1167 }
1168
1169 #if DIM == 3
1170 static void store_texel_al88_rev(struct swrast_texture_image *texImage,
1171                                  GLint i, GLint j, GLint k, const void *texel)
1172 {
1173    const GLubyte *rgba = (const GLubyte *) texel;
1174    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1175    *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
1176 }
1177 #endif
1178
1179
1180 /* MESA_FORMAT_RG1616 ********************************************************/
1181
1182 /* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
1183 static void FETCH(f_rg1616)( const struct swrast_texture_image *texImage,
1184                            GLint i, GLint j, GLint k, GLfloat *texel )
1185 {
1186    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1187    texel[RCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1188    texel[GCOMP] = USHORT_TO_FLOAT( s >> 16 );
1189    texel[BCOMP] = 0.0;
1190    texel[ACOMP] = 1.0;
1191 }
1192
1193 #if DIM == 3
1194 static void store_texel_rg1616(struct swrast_texture_image *texImage,
1195                              GLint i, GLint j, GLint k, const void *texel)
1196 {
1197    const GLchan *rgba = (const GLchan *) texel;
1198    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1199    GLushort r = CHAN_TO_USHORT(rgba[RCOMP]);
1200    GLushort g = CHAN_TO_USHORT(rgba[GCOMP]);
1201    *dst = PACK_COLOR_1616(g, r);
1202 }
1203 #endif
1204
1205
1206 /* MESA_FORMAT_RG1616_REV ****************************************************/
1207
1208 /* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
1209 static void FETCH(f_rg1616_rev)( const struct swrast_texture_image *texImage,
1210                            GLint i, GLint j, GLint k, GLfloat *texel )
1211 {
1212    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1213    texel[RCOMP] = USHORT_TO_FLOAT( s >> 16 );
1214    texel[GCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1215    texel[BCOMP] = 0.0;
1216    texel[ACOMP] = 1.0;
1217 }
1218
1219 #if DIM == 3
1220 static void store_texel_rg1616_rev(struct swrast_texture_image *texImage,
1221                              GLint i, GLint j, GLint k, const void *texel)
1222 {
1223    const GLubyte *rgba = (const GLubyte *) texel;
1224    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1225    *dst = PACK_COLOR_1616(rgba[GCOMP], rgba[RCOMP]);
1226 }
1227 #endif
1228
1229
1230 /* MESA_FORMAT_AL1616 ********************************************************/
1231
1232 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
1233 static void FETCH(f_al1616)( const struct swrast_texture_image *texImage,
1234                              GLint i, GLint j, GLint k, GLfloat *texel )
1235 {
1236    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1237    texel[RCOMP] =
1238    texel[GCOMP] =
1239    texel[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1240    texel[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
1241 }
1242
1243 #if DIM == 3
1244 static void store_texel_al1616(struct swrast_texture_image *texImage,
1245                              GLint i, GLint j, GLint k, const void *texel)
1246 {
1247    const GLchan *rgba = (const GLchan *) texel;
1248    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1249    GLushort l = CHAN_TO_USHORT(rgba[RCOMP]);
1250    GLushort a = CHAN_TO_USHORT(rgba[ACOMP]);
1251    *dst = PACK_COLOR_1616(a, l);
1252 }
1253 #endif
1254
1255
1256 /* MESA_FORMAT_AL1616_REV ****************************************************/
1257
1258 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
1259 static void FETCH(f_al1616_rev)( const struct swrast_texture_image *texImage,
1260                                  GLint i, GLint j, GLint k, GLfloat *texel )
1261 {
1262    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1263    texel[RCOMP] =
1264    texel[GCOMP] =
1265    texel[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
1266    texel[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
1267 }
1268
1269 #if DIM == 3
1270 static void store_texel_al1616_rev(struct swrast_texture_image *texImage,
1271                                    GLint i, GLint j, GLint k, const void *texel)
1272 {
1273    const GLushort *rgba = (const GLushort *) texel;
1274    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1275    *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[ACOMP]);
1276 }
1277 #endif
1278
1279
1280 /* MESA_FORMAT_RGB332 ********************************************************/
1281
1282 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1283 static void FETCH(f_rgb332)( const struct swrast_texture_image *texImage,
1284                              GLint i, GLint j, GLint k, GLfloat *texel )
1285 {
1286    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1287    const GLubyte s = *src;
1288    texel[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
1289    texel[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
1290    texel[BCOMP] = ((s     ) & 0x3) * (1.0F / 3.0F);
1291    texel[ACOMP] = 1.0F;
1292 }
1293
1294 #if DIM == 3
1295 static void store_texel_rgb332(struct swrast_texture_image *texImage,
1296                                GLint i, GLint j, GLint k, const void *texel)
1297 {
1298    const GLubyte *rgba = (const GLubyte *) texel;
1299    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1300    *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1301 }
1302 #endif
1303
1304
1305 /* MESA_FORMAT_A8 ************************************************************/
1306
1307 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1308 static void FETCH(f_a8)( const struct swrast_texture_image *texImage,
1309                          GLint i, GLint j, GLint k, GLfloat *texel )
1310 {
1311    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1312    texel[RCOMP] =
1313    texel[GCOMP] =
1314    texel[BCOMP] = 0.0F;
1315    texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1316 }
1317
1318 #if DIM == 3
1319 static void store_texel_a8(struct swrast_texture_image *texImage,
1320                            GLint i, GLint j, GLint k, const void *texel)
1321 {
1322    const GLubyte *rgba = (const GLubyte *) texel;
1323    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1324    *dst = rgba[ACOMP];
1325 }
1326 #endif
1327
1328
1329 /* MESA_FORMAT_A16 ************************************************************/
1330
1331 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1332 static void FETCH(f_a16)( const struct swrast_texture_image *texImage,
1333                           GLint i, GLint j, GLint k, GLfloat *texel )
1334 {
1335    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1336    texel[RCOMP] =
1337    texel[GCOMP] =
1338    texel[BCOMP] = 0.0F;
1339    texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
1340 }
1341
1342 #if DIM == 3
1343 static void store_texel_a16(struct swrast_texture_image *texImage,
1344                             GLint i, GLint j, GLint k, const void *texel)
1345 {
1346    const GLchan *rgba = (const GLchan *) texel;
1347    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1348    *dst = CHAN_TO_USHORT(rgba[ACOMP]);
1349 }
1350 #endif
1351
1352
1353 /* MESA_FORMAT_L8 ************************************************************/
1354
1355 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1356 static void FETCH(f_l8)( const struct swrast_texture_image *texImage,
1357                          GLint i, GLint j, GLint k, GLfloat *texel )
1358 {
1359    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1360    texel[RCOMP] =
1361    texel[GCOMP] =
1362    texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
1363    texel[ACOMP] = 1.0F;
1364 }
1365
1366 #if DIM == 3
1367 static void store_texel_l8(struct swrast_texture_image *texImage,
1368                            GLint i, GLint j, GLint k, const void *texel)
1369 {
1370    const GLubyte *rgba = (const GLubyte *) texel;
1371    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1372    *dst = rgba[RCOMP];
1373 }
1374 #endif
1375
1376
1377 /* MESA_FORMAT_L16 ***********************************************************/
1378
1379 /* Fetch texel from 1D, 2D or 3D l16 texture, return 4 GLchans */
1380 static void FETCH(f_l16)( const struct swrast_texture_image *texImage,
1381                           GLint i, GLint j, GLint k, GLfloat *texel )
1382 {
1383    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1384    texel[RCOMP] =
1385    texel[GCOMP] =
1386    texel[BCOMP] = USHORT_TO_FLOAT( src[0] );
1387    texel[ACOMP] = 1.0F;
1388 }
1389
1390 #if DIM == 3
1391 static void store_texel_l16(struct swrast_texture_image *texImage,
1392                             GLint i, GLint j, GLint k, const void *texel)
1393 {
1394    const GLchan *rgba = (const GLchan *) texel;
1395    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1396    *dst = CHAN_TO_USHORT(rgba[RCOMP]);
1397 }
1398 #endif
1399
1400
1401 /* MESA_FORMAT_I8 ************************************************************/
1402
1403 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1404 static void FETCH(f_i8)( const struct swrast_texture_image *texImage,
1405                          GLint i, GLint j, GLint k, GLfloat *texel )
1406 {
1407    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1408    texel[RCOMP] =
1409    texel[GCOMP] =
1410    texel[BCOMP] =
1411    texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1412 }
1413
1414 #if DIM == 3
1415 static void store_texel_i8(struct swrast_texture_image *texImage,
1416                            GLint i, GLint j, GLint k, const void *texel)
1417 {
1418    const GLubyte *rgba = (const GLubyte *) texel;
1419    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1420    *dst = rgba[RCOMP];
1421 }
1422 #endif
1423
1424
1425 /* MESA_FORMAT_I16 ***********************************************************/
1426
1427 /* Fetch texel from 1D, 2D or 3D i16 texture, return 4 GLchans */
1428 static void FETCH(f_i16)( const struct swrast_texture_image *texImage,
1429                           GLint i, GLint j, GLint k, GLfloat *texel )
1430 {
1431    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1432    texel[RCOMP] =
1433    texel[GCOMP] =
1434    texel[BCOMP] =
1435    texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
1436 }
1437
1438 #if DIM == 3
1439 static void store_texel_i16(struct swrast_texture_image *texImage,
1440                             GLint i, GLint j, GLint k, const void *texel)
1441 {
1442    const GLchan *rgba = (const GLchan *) texel;
1443    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1444    *dst = CHAN_TO_USHORT(rgba[RCOMP]);
1445 }
1446 #endif
1447
1448
1449 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1450 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1451 static void FETCH(srgb8)(const struct swrast_texture_image *texImage,
1452                          GLint i, GLint j, GLint k, GLfloat *texel )
1453 {
1454    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1455    texel[RCOMP] = nonlinear_to_linear(src[2]);
1456    texel[GCOMP] = nonlinear_to_linear(src[1]);
1457    texel[BCOMP] = nonlinear_to_linear(src[0]);
1458    texel[ACOMP] = 1.0F;
1459 }
1460
1461 #if DIM == 3
1462 static void store_texel_srgb8(struct swrast_texture_image *texImage,
1463                               GLint i, GLint j, GLint k, const void *texel)
1464 {
1465    const GLubyte *rgba = (const GLubyte *) texel;
1466    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1467    dst[0] = rgba[BCOMP]; /* no conversion */
1468    dst[1] = rgba[GCOMP];
1469    dst[2] = rgba[RCOMP];
1470 }
1471 #endif
1472
1473 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1474 static void FETCH(srgba8)(const struct swrast_texture_image *texImage,
1475                           GLint i, GLint j, GLint k, GLfloat *texel )
1476 {
1477    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1478    texel[RCOMP] = nonlinear_to_linear( (s >> 24) );
1479    texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1480    texel[BCOMP] = nonlinear_to_linear( (s >>  8) & 0xff );
1481    texel[ACOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff ); /* linear! */
1482 }
1483
1484 #if DIM == 3
1485 static void store_texel_srgba8(struct swrast_texture_image *texImage,
1486                                GLint i, GLint j, GLint k, const void *texel)
1487 {
1488    const GLubyte *rgba = (const GLubyte *) texel;
1489    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1490    *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1491 }
1492 #endif
1493
1494 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1495 static void FETCH(sargb8)(const struct swrast_texture_image *texImage,
1496                           GLint i, GLint j, GLint k, GLfloat *texel )
1497 {
1498    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1499    texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1500    texel[GCOMP] = nonlinear_to_linear( (s >>  8) & 0xff );
1501    texel[BCOMP] = nonlinear_to_linear( (s      ) & 0xff );
1502    texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
1503 }
1504
1505 #if DIM == 3
1506 static void store_texel_sargb8(struct swrast_texture_image *texImage,
1507                                GLint i, GLint j, GLint k, const void *texel)
1508 {
1509    const GLubyte *rgba = (const GLubyte *) texel;
1510    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1511    *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1512 }
1513 #endif
1514
1515 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1516 static void FETCH(sl8)(const struct swrast_texture_image *texImage,
1517                        GLint i, GLint j, GLint k, GLfloat *texel )
1518 {
1519    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1520    texel[RCOMP] = 
1521    texel[GCOMP] = 
1522    texel[BCOMP] = nonlinear_to_linear(src[0]);
1523    texel[ACOMP] = 1.0F;
1524 }
1525
1526 #if DIM == 3
1527 static void store_texel_sl8(struct swrast_texture_image *texImage,
1528                             GLint i, GLint j, GLint k, const void *texel)
1529 {
1530    const GLubyte *rgba = (const GLubyte *) texel;
1531    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1532    dst[0] = rgba[RCOMP];
1533 }
1534 #endif
1535
1536 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1537 static void FETCH(sla8)(const struct swrast_texture_image *texImage,
1538                        GLint i, GLint j, GLint k, GLfloat *texel )
1539 {
1540    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1541    texel[RCOMP] =
1542    texel[GCOMP] =
1543    texel[BCOMP] = nonlinear_to_linear(src[0]);
1544    texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
1545 }
1546
1547 #if DIM == 3
1548 static void store_texel_sla8(struct swrast_texture_image *texImage,
1549                             GLint i, GLint j, GLint k, const void *texel)
1550 {
1551    const GLubyte *rgba = (const GLubyte *) texel;
1552    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1553    dst[0] = rgba[RCOMP];
1554    dst[1] = rgba[ACOMP];
1555 }
1556 #endif
1557
1558
1559 /* MESA_FORMAT_RGBA_INT8 **************************************************/
1560
1561 static void
1562 FETCH(rgba_int8)(const struct swrast_texture_image *texImage,
1563                  GLint i, GLint j, GLint k, GLfloat *texel )
1564 {
1565    const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
1566    texel[RCOMP] = (GLfloat) src[0];
1567    texel[GCOMP] = (GLfloat) src[1];
1568    texel[BCOMP] = (GLfloat) src[2];
1569    texel[ACOMP] = (GLfloat) src[3];
1570 }
1571
1572 #if DIM == 3
1573 static void
1574 store_texel_rgba_int8(struct swrast_texture_image *texImage,
1575                       GLint i, GLint j, GLint k, const void *texel)
1576 {
1577    const GLbyte *rgba = (const GLbyte *) texel;
1578    GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
1579    dst[0] = rgba[RCOMP];
1580    dst[1] = rgba[GCOMP];
1581    dst[2] = rgba[BCOMP];
1582    dst[3] = rgba[ACOMP];
1583 }
1584 #endif
1585
1586
1587 /* MESA_FORMAT_RGBA_INT16 **************************************************/
1588
1589 static void
1590 FETCH(rgba_int16)(const struct swrast_texture_image *texImage,
1591                   GLint i, GLint j, GLint k, GLfloat *texel )
1592 {
1593    const GLshort *src = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1594    texel[RCOMP] = (GLfloat) src[0];
1595    texel[GCOMP] = (GLfloat) src[1];
1596    texel[BCOMP] = (GLfloat) src[2];
1597    texel[ACOMP] = (GLfloat) src[3];
1598 }
1599
1600 #if DIM == 3
1601 static void
1602 store_texel_rgba_int16(struct swrast_texture_image *texImage,
1603                        GLint i, GLint j, GLint k, const void *texel)
1604 {
1605    const GLshort *rgba = (const GLshort *) texel;
1606    GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1607    dst[0] = rgba[RCOMP];
1608    dst[1] = rgba[GCOMP];
1609    dst[2] = rgba[BCOMP];
1610    dst[3] = rgba[ACOMP];
1611 }
1612 #endif
1613
1614
1615 /* MESA_FORMAT_RGBA_INT32 **************************************************/
1616
1617 static void
1618 FETCH(rgba_int32)(const struct swrast_texture_image *texImage,
1619                   GLint i, GLint j, GLint k, GLfloat *texel )
1620 {
1621    const GLint *src = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
1622    texel[RCOMP] = (GLfloat) src[0];
1623    texel[GCOMP] = (GLfloat) src[1];
1624    texel[BCOMP] = (GLfloat) src[2];
1625    texel[ACOMP] = (GLfloat) src[3];
1626 }
1627
1628 #if DIM == 3
1629 static void
1630 store_texel_rgba_int32(struct swrast_texture_image *texImage,
1631                        GLint i, GLint j, GLint k, const void *texel)
1632 {
1633    const GLint *rgba = (const GLint *) texel;
1634    GLint *dst = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
1635    dst[0] = rgba[RCOMP];
1636    dst[1] = rgba[GCOMP];
1637    dst[2] = rgba[BCOMP];
1638    dst[3] = rgba[ACOMP];
1639 }
1640 #endif
1641
1642
1643 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
1644
1645 static void
1646 FETCH(rgba_uint8)(const struct swrast_texture_image *texImage,
1647                  GLint i, GLint j, GLint k, GLfloat *texel )
1648 {
1649    const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1650    texel[RCOMP] = (GLfloat) src[0];
1651    texel[GCOMP] = (GLfloat) src[1];
1652    texel[BCOMP] = (GLfloat) src[2];
1653    texel[ACOMP] = (GLfloat) src[3];
1654 }
1655
1656 #if DIM == 3
1657 static void
1658 store_texel_rgba_uint8(struct swrast_texture_image *texImage,
1659                       GLint i, GLint j, GLint k, const void *texel)
1660 {
1661    const GLubyte *rgba = (const GLubyte *) texel;
1662    GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1663    dst[0] = rgba[RCOMP];
1664    dst[1] = rgba[GCOMP];
1665    dst[2] = rgba[BCOMP];
1666    dst[3] = rgba[ACOMP];
1667 }
1668 #endif
1669
1670
1671 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
1672
1673 static void
1674 FETCH(rgba_uint16)(const struct swrast_texture_image *texImage,
1675                   GLint i, GLint j, GLint k, GLfloat *texel )
1676 {
1677    const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1678    texel[RCOMP] = (GLfloat) src[0];
1679    texel[GCOMP] = (GLfloat) src[1];
1680    texel[BCOMP] = (GLfloat) src[2];
1681    texel[ACOMP] = (GLfloat) src[3];
1682 }
1683
1684 #if DIM == 3
1685 static void
1686 store_texel_rgba_uint16(struct swrast_texture_image *texImage,
1687                        GLint i, GLint j, GLint k, const void *texel)
1688 {
1689    const GLushort *rgba = (const GLushort *) texel;
1690    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1691    dst[0] = rgba[RCOMP];
1692    dst[1] = rgba[GCOMP];
1693    dst[2] = rgba[BCOMP];
1694    dst[3] = rgba[ACOMP];
1695 }
1696 #endif
1697
1698
1699 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
1700
1701 static void
1702 FETCH(rgba_uint32)(const struct swrast_texture_image *texImage,
1703                   GLint i, GLint j, GLint k, GLfloat *texel )
1704 {
1705    const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
1706    texel[RCOMP] = (GLfloat) src[0];
1707    texel[GCOMP] = (GLfloat) src[1];
1708    texel[BCOMP] = (GLfloat) src[2];
1709    texel[ACOMP] = (GLfloat) src[3];
1710 }
1711
1712 #if DIM == 3
1713 static void
1714 store_texel_rgba_uint32(struct swrast_texture_image *texImage,
1715                        GLint i, GLint j, GLint k, const void *texel)
1716 {
1717    const GLuint *rgba = (const GLuint *) texel;
1718    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
1719    dst[0] = rgba[RCOMP];
1720    dst[1] = rgba[GCOMP];
1721    dst[2] = rgba[BCOMP];
1722    dst[3] = rgba[ACOMP];
1723 }
1724 #endif
1725
1726
1727 /* MESA_FORMAT_DUDV8 ********************************************************/
1728
1729 /* this format by definition produces 0,0,0,1 as rgba values,
1730    however we'll return the dudv values as rg and fix up elsewhere */
1731 static void FETCH(dudv8)(const struct swrast_texture_image *texImage,
1732                          GLint i, GLint j, GLint k, GLfloat *texel )
1733 {
1734    const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 2);
1735    texel[RCOMP] = BYTE_TO_FLOAT(src[0]);
1736    texel[GCOMP] = BYTE_TO_FLOAT(src[1]);
1737    texel[BCOMP] = 0;
1738    texel[ACOMP] = 0;
1739 }
1740
1741
1742 /* MESA_FORMAT_SIGNED_R8 ***********************************************/
1743
1744 static void FETCH(signed_r8)( const struct swrast_texture_image *texImage,
1745                               GLint i, GLint j, GLint k, GLfloat *texel )
1746 {
1747    const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1748    texel[RCOMP] = BYTE_TO_FLOAT_TEX( s );
1749    texel[GCOMP] = 0.0F;
1750    texel[BCOMP] = 0.0F;
1751    texel[ACOMP] = 1.0F;
1752 }
1753
1754 #if DIM == 3
1755 static void store_texel_signed_r8(struct swrast_texture_image *texImage,
1756                                   GLint i, GLint j, GLint k, const void *texel)
1757 {
1758    const GLbyte *rgba = (const GLbyte *) texel;
1759    GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1760    *dst = rgba[RCOMP];
1761 }
1762 #endif
1763
1764
1765 /* MESA_FORMAT_SIGNED_A8 ***********************************************/
1766
1767 static void FETCH(signed_a8)( const struct swrast_texture_image *texImage,
1768                               GLint i, GLint j, GLint k, GLfloat *texel )
1769 {
1770    const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1771    texel[RCOMP] = 0.0F;
1772    texel[GCOMP] = 0.0F;
1773    texel[BCOMP] = 0.0F;
1774    texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
1775 }
1776
1777 #if DIM == 3
1778 static void store_texel_signed_a8(struct swrast_texture_image *texImage,
1779                                   GLint i, GLint j, GLint k, const void *texel)
1780 {
1781    const GLbyte *rgba = (const GLbyte *) texel;
1782    GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1783    *dst = rgba[ACOMP];
1784 }
1785 #endif
1786
1787
1788 /* MESA_FORMAT_SIGNED_L8 ***********************************************/
1789
1790 static void FETCH(signed_l8)( const struct swrast_texture_image *texImage,
1791                               GLint i, GLint j, GLint k, GLfloat *texel )
1792 {
1793    const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1794    texel[RCOMP] =
1795    texel[GCOMP] =
1796    texel[BCOMP] = BYTE_TO_FLOAT_TEX( s );
1797    texel[ACOMP] = 1.0F;
1798 }
1799
1800 #if DIM == 3
1801 static void store_texel_signed_l8(struct swrast_texture_image *texImage,
1802                                   GLint i, GLint j, GLint k, const void *texel)
1803 {
1804    const GLbyte *rgba = (const GLbyte *) texel;
1805    GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1806    *dst = rgba[RCOMP];
1807 }
1808 #endif
1809
1810
1811 /* MESA_FORMAT_SIGNED_I8 ***********************************************/
1812
1813 static void FETCH(signed_i8)( const struct swrast_texture_image *texImage,
1814                               GLint i, GLint j, GLint k, GLfloat *texel )
1815 {
1816    const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1817    texel[RCOMP] =
1818    texel[GCOMP] =
1819    texel[BCOMP] =
1820    texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
1821 }
1822
1823 #if DIM == 3
1824 static void store_texel_signed_i8(struct swrast_texture_image *texImage,
1825                                   GLint i, GLint j, GLint k, const void *texel)
1826 {
1827    const GLbyte *rgba = (const GLbyte *) texel;
1828    GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1829    *dst = rgba[RCOMP];
1830 }
1831 #endif
1832
1833
1834 /* MESA_FORMAT_SIGNED_RG88_REV ***********************************************/
1835
1836 static void FETCH(signed_rg88_rev)( const struct swrast_texture_image *texImage,
1837                                     GLint i, GLint j, GLint k, GLfloat *texel )
1838 {
1839    const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1840    texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
1841    texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1842    texel[BCOMP] = 0.0F;
1843    texel[ACOMP] = 1.0F;
1844 }
1845
1846 #if DIM == 3
1847 static void store_texel_signed_rg88_rev(struct swrast_texture_image *texImage,
1848                                         GLint i, GLint j, GLint k, const void *texel)
1849 {
1850    const GLbyte *rg = (const GLbyte *) texel;
1851    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1852    dst[0] = PACK_COLOR_88(rg[GCOMP], rg[RCOMP]);
1853 }
1854 #endif
1855
1856
1857 /* MESA_FORMAT_SIGNED_AL88 ***********************************************/
1858
1859 static void FETCH(signed_al88)( const struct swrast_texture_image *texImage,
1860                                 GLint i, GLint j, GLint k, GLfloat *texel )
1861 {
1862    const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1863    texel[RCOMP] =
1864    texel[GCOMP] =
1865    texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
1866    texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1867 }
1868
1869 #if DIM == 3
1870 static void store_texel_signed_al88(struct swrast_texture_image *texImage,
1871                                     GLint i, GLint j, GLint k, const void *texel)
1872 {
1873    const GLbyte *rg = (const GLbyte *) texel;
1874    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1875    dst[0] = PACK_COLOR_88(rg[ACOMP], rg[RCOMP]);
1876 }
1877 #endif
1878
1879
1880 /* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
1881
1882 static void FETCH(signed_rgbx8888)( const struct swrast_texture_image *texImage,
1883                                     GLint i, GLint j, GLint k, GLfloat *texel )
1884 {
1885    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1886    texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1887    texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1888    texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >>  8) );
1889    texel[ACOMP] = 1.0f;
1890 }
1891
1892 #if DIM == 3
1893 static void store_texel_signed_rgbx8888(struct swrast_texture_image *texImage,
1894                                         GLint i, GLint j, GLint k, const void *texel)
1895 {
1896    const GLbyte *rgba = (const GLbyte *) texel;
1897    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1898    *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 255);
1899 }
1900 #endif
1901
1902
1903 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1904
1905 static void FETCH(signed_rgba8888)( const struct swrast_texture_image *texImage,
1906                                     GLint i, GLint j, GLint k, GLfloat *texel )
1907 {
1908    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1909    texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1910    texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1911    texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >>  8) );
1912    texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s      ) );
1913 }
1914
1915 #if DIM == 3
1916 static void store_texel_signed_rgba8888(struct swrast_texture_image *texImage,
1917                                         GLint i, GLint j, GLint k, const void *texel)
1918 {
1919    const GLbyte *rgba = (const GLbyte *) texel;
1920    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1921    *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1922 }
1923 #endif
1924
1925 static void FETCH(signed_rgba8888_rev)( const struct swrast_texture_image *texImage,
1926                                         GLint i, GLint j, GLint k, GLfloat *texel )
1927 {
1928    const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1929    texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s      ) );
1930    texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >>  8) );
1931    texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1932    texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1933 }
1934
1935 #if DIM == 3
1936 static void store_texel_signed_rgba8888_rev(struct swrast_texture_image *texImage,
1937                                             GLint i, GLint j, GLint k, const void *texel)
1938 {
1939    const GLubyte *rgba = (const GLubyte *) texel;
1940    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1941    *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1942 }
1943 #endif
1944
1945
1946
1947 /* MESA_FORMAT_SIGNED_R16 ***********************************************/
1948
1949 static void
1950 FETCH(signed_r16)(const struct swrast_texture_image *texImage,
1951                   GLint i, GLint j, GLint k, GLfloat *texel)
1952 {
1953    const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1954    texel[RCOMP] = SHORT_TO_FLOAT_TEX( s );
1955    texel[GCOMP] = 0.0F;
1956    texel[BCOMP] = 0.0F;
1957    texel[ACOMP] = 1.0F;
1958 }
1959
1960 #if DIM == 3
1961 static void
1962 store_texel_signed_r16(struct swrast_texture_image *texImage,
1963                        GLint i, GLint j, GLint k, const void *texel)
1964 {
1965    const GLshort *rgba = (const GLshort *) texel;
1966    GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1967    *dst = rgba[0];
1968 }
1969 #endif
1970
1971
1972 /* MESA_FORMAT_SIGNED_A16 ***********************************************/
1973
1974 static void
1975 FETCH(signed_a16)(const struct swrast_texture_image *texImage,
1976                   GLint i, GLint j, GLint k, GLfloat *texel)
1977 {
1978    const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1979    texel[RCOMP] = 0.0F;
1980    texel[GCOMP] = 0.0F;
1981    texel[BCOMP] = 0.0F;
1982    texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
1983 }
1984
1985 #if DIM == 3
1986 static void
1987 store_texel_signed_a16(struct swrast_texture_image *texImage,
1988                        GLint i, GLint j, GLint k, const void *texel)
1989 {
1990    const GLshort *rgba = (const GLshort *) texel;
1991    GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1992    *dst = rgba[ACOMP];
1993 }
1994 #endif
1995
1996
1997 /* MESA_FORMAT_SIGNED_L16 ***********************************************/
1998
1999 static void
2000 FETCH(signed_l16)(const struct swrast_texture_image *texImage,
2001                   GLint i, GLint j, GLint k, GLfloat *texel)
2002 {
2003    const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
2004    texel[RCOMP] =
2005    texel[GCOMP] =
2006    texel[BCOMP] = SHORT_TO_FLOAT_TEX( s );
2007    texel[ACOMP] = 1.0F;
2008 }
2009
2010 #if DIM == 3
2011 static void
2012 store_texel_signed_l16(struct swrast_texture_image *texImage,
2013                        GLint i, GLint j, GLint k, const void *texel)
2014 {
2015    const GLshort *rgba = (const GLshort *) texel;
2016    GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
2017    *dst = rgba[RCOMP];
2018 }
2019 #endif
2020
2021
2022 /* MESA_FORMAT_SIGNED_I16 ***********************************************/
2023
2024 static void
2025 FETCH(signed_i16)(const struct swrast_texture_image *texImage,
2026                   GLint i, GLint j, GLint k, GLfloat *texel)
2027 {
2028    const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
2029    texel[RCOMP] =
2030    texel[GCOMP] =
2031    texel[BCOMP] =
2032    texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
2033 }
2034
2035 #if DIM == 3
2036 static void
2037 store_texel_signed_i16(struct swrast_texture_image *texImage,
2038                        GLint i, GLint j, GLint k, const void *texel)
2039 {
2040    const GLshort *rgba = (const GLshort *) texel;
2041    GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
2042    *dst = rgba[RCOMP];
2043 }
2044 #endif
2045
2046
2047 /* MESA_FORMAT_SIGNED_RG1616 ***********************************************/
2048
2049 static void
2050 FETCH(signed_rg1616)(const struct swrast_texture_image *texImage,
2051                     GLint i, GLint j, GLint k, GLfloat *texel)
2052 {
2053    const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2054    texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2055    texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2056    texel[BCOMP] = 0.0F;
2057    texel[ACOMP] = 1.0F;
2058 }
2059
2060 #if DIM == 3
2061 static void
2062 store_texel_signed_rg1616(struct swrast_texture_image *texImage,
2063                          GLint i, GLint j, GLint k, const void *texel)
2064 {
2065    const GLchan *rgba = (const GLchan *) texel;
2066    GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2067    dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
2068    dst[1] = CHAN_TO_SHORT(rgba[GCOMP]);
2069 }
2070 #endif
2071
2072
2073 /* MESA_FORMAT_SIGNED_AL1616 ***********************************************/
2074
2075 static void
2076 FETCH(signed_al1616)(const struct swrast_texture_image *texImage,
2077                     GLint i, GLint j, GLint k, GLfloat *texel)
2078 {
2079    const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2080    texel[RCOMP] =
2081    texel[GCOMP] =
2082    texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2083    texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2084 }
2085
2086 #if DIM == 3
2087 static void
2088 store_texel_signed_al1616(struct swrast_texture_image *texImage,
2089                          GLint i, GLint j, GLint k, const void *texel)
2090 {
2091    const GLchan *rgba = (const GLchan *) texel;
2092    GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2093    dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
2094    dst[1] = CHAN_TO_SHORT(rgba[ACOMP]);
2095 }
2096 #endif
2097
2098
2099 /* MESA_FORMAT_SIGNED_RGB_16 ***********************************************/
2100
2101 static void 
2102 FETCH(signed_rgb_16)(const struct swrast_texture_image *texImage,
2103                      GLint i, GLint j, GLint k, GLfloat *texel)
2104 {
2105    const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
2106    texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2107    texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2108    texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
2109    texel[ACOMP] = 1.0F;
2110 }
2111
2112 #if DIM == 3
2113 static void
2114 store_texel_signed_rgb_16(struct swrast_texture_image *texImage,
2115                           GLint i, GLint j, GLint k, const void *texel)
2116 {
2117    const GLchan *rgba = (const GLchan *) texel;
2118    GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
2119    dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
2120    dst[1] = CHAN_TO_SHORT(rgba[GCOMP]);
2121    dst[2] = CHAN_TO_SHORT(rgba[BCOMP]);
2122 }
2123 #endif
2124
2125
2126 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
2127
2128 static void
2129 FETCH(signed_rgba_16)(const struct swrast_texture_image *texImage,
2130                       GLint i, GLint j, GLint k, GLfloat *texel)
2131 {
2132    const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
2133    texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2134    texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2135    texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
2136    texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
2137 }
2138
2139 #if DIM == 3
2140 static void
2141 store_texel_signed_rgba_16(struct swrast_texture_image *texImage,
2142                            GLint i, GLint j, GLint k, const void *texel)
2143 {
2144    const GLchan *rgba = (const GLchan *) texel;
2145    GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
2146    dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
2147    dst[1] = CHAN_TO_SHORT(rgba[GCOMP]);
2148    dst[2] = CHAN_TO_SHORT(rgba[BCOMP]);
2149    dst[3] = CHAN_TO_SHORT(rgba[ACOMP]);
2150 }
2151 #endif
2152
2153
2154
2155 /* MESA_FORMAT_RGBA_16 ***********************************************/
2156
2157 static void
2158 FETCH(rgba_16)(const struct swrast_texture_image *texImage,
2159                GLint i, GLint j, GLint k, GLfloat *texel)
2160 {
2161    const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
2162    texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
2163    texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
2164    texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
2165    texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
2166 }
2167
2168 #if DIM == 3
2169 static void
2170 store_texel_rgba_16(struct swrast_texture_image *texImage,
2171                     GLint i, GLint j, GLint k, const void *texel)
2172 {
2173    const GLchan *rgba = (const GLchan *) texel;
2174    GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
2175    dst[0] = CHAN_TO_USHORT(rgba[RCOMP]);
2176    dst[1] = CHAN_TO_USHORT(rgba[GCOMP]);
2177    dst[2] = CHAN_TO_USHORT(rgba[BCOMP]);
2178    dst[3] = CHAN_TO_USHORT(rgba[ACOMP]);
2179 }
2180 #endif
2181
2182
2183
2184 /* MESA_FORMAT_YCBCR *********************************************************/
2185
2186 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
2187  * We convert YCbCr to RGB here.
2188  */
2189 static void FETCH(f_ycbcr)( const struct swrast_texture_image *texImage,
2190                             GLint i, GLint j, GLint k, GLfloat *texel )
2191 {
2192    const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
2193    const GLushort *src1 = src0 + 1;                               /* odd */
2194    const GLubyte y0 = (*src0 >> 8) & 0xff;  /* luminance */
2195    const GLubyte cb = *src0 & 0xff;         /* chroma U */
2196    const GLubyte y1 = (*src1 >> 8) & 0xff;  /* luminance */
2197    const GLubyte cr = *src1 & 0xff;         /* chroma V */
2198    const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
2199    GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
2200    GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
2201    GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
2202    r *= (1.0F / 255.0F);
2203    g *= (1.0F / 255.0F);
2204    b *= (1.0F / 255.0F);
2205    texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
2206    texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
2207    texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
2208    texel[ACOMP] = 1.0F;
2209 }
2210
2211 #if DIM == 3
2212 static void store_texel_ycbcr(struct swrast_texture_image *texImage,
2213                               GLint i, GLint j, GLint k, const void *texel)
2214 {
2215    (void) texImage;
2216    (void) i;
2217    (void) j;
2218    (void) k;
2219    (void) texel;
2220    /* XXX to do */
2221 }
2222 #endif
2223
2224
2225 /* MESA_FORMAT_YCBCR_REV *****************************************************/
2226
2227 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
2228  * We convert YCbCr to RGB here.
2229  */
2230 static void FETCH(f_ycbcr_rev)( const struct swrast_texture_image *texImage,
2231                                 GLint i, GLint j, GLint k, GLfloat *texel )
2232 {
2233    const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
2234    const GLushort *src1 = src0 + 1;                               /* odd */
2235    const GLubyte y0 = *src0 & 0xff;         /* luminance */
2236    const GLubyte cr = (*src0 >> 8) & 0xff;  /* chroma V */
2237    const GLubyte y1 = *src1 & 0xff;         /* luminance */
2238    const GLubyte cb = (*src1 >> 8) & 0xff;  /* chroma U */
2239    const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
2240    GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
2241    GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
2242    GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
2243    r *= (1.0F / 255.0F);
2244    g *= (1.0F / 255.0F);
2245    b *= (1.0F / 255.0F);
2246    texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
2247    texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
2248    texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
2249    texel[ACOMP] = 1.0F;
2250 }
2251
2252 #if DIM == 3
2253 static void store_texel_ycbcr_rev(struct swrast_texture_image *texImage,
2254                                   GLint i, GLint j, GLint k, const void *texel)
2255 {
2256    (void) texImage;
2257    (void) i;
2258    (void) j;
2259    (void) k;
2260    (void) texel;
2261    /* XXX to do */
2262 }
2263 #endif
2264
2265
2266 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
2267
2268 static void FETCH(f_z24_s8)( const struct swrast_texture_image *texImage,
2269                              GLint i, GLint j, GLint k, GLfloat *texel )
2270 {
2271    /* only return Z, not stencil data */
2272    const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2273    const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
2274    texel[0] = ((*src) >> 8) * scale;
2275    ASSERT(texImage->Base.TexFormat == MESA_FORMAT_Z24_S8 ||
2276           texImage->Base.TexFormat == MESA_FORMAT_Z24_X8);
2277    ASSERT(texel[0] >= 0.0F);
2278    ASSERT(texel[0] <= 1.0F);
2279 }
2280
2281 #if DIM == 3
2282 static void store_texel_z24_s8(struct swrast_texture_image *texImage,
2283                                GLint i, GLint j, GLint k, const void *texel)
2284 {
2285    /* only store Z, not stencil */
2286    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2287    GLfloat depth = *((GLfloat *) texel);
2288    GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
2289    *dst = zi | (*dst & 0xff);
2290 }
2291 #endif
2292
2293
2294 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
2295
2296 static void FETCH(f_s8_z24)( const struct swrast_texture_image *texImage,
2297                              GLint i, GLint j, GLint k, GLfloat *texel )
2298 {
2299    /* only return Z, not stencil data */
2300    const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2301    const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
2302    texel[0] = ((*src) & 0x00ffffff) * scale;
2303    ASSERT(texImage->Base.TexFormat == MESA_FORMAT_S8_Z24 ||
2304           texImage->Base.TexFormat == MESA_FORMAT_X8_Z24);
2305    ASSERT(texel[0] >= 0.0F);
2306    ASSERT(texel[0] <= 1.0F);
2307 }
2308
2309 #if DIM == 3
2310 static void store_texel_s8_z24(struct swrast_texture_image *texImage,
2311                                GLint i, GLint j, GLint k, const void *texel)
2312 {
2313    /* only store Z, not stencil */
2314    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2315    GLfloat depth = *((GLfloat *) texel);
2316    GLuint zi = (GLuint) (depth * 0xffffff);
2317    *dst = zi | (*dst & 0xff000000);
2318 }
2319 #endif
2320
2321
2322 /* MESA_FORMAT_RGB9_E5 ******************************************************/
2323
2324 static void FETCH(rgb9_e5)( const struct swrast_texture_image *texImage,
2325                             GLint i, GLint j, GLint k, GLfloat *texel )
2326 {
2327    const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2328    rgb9e5_to_float3(*src, texel);
2329    texel[ACOMP] = 1.0F;
2330 }
2331
2332 #if DIM == 3
2333 static void store_texel_rgb9_e5(struct swrast_texture_image *texImage,
2334                                 GLint i, GLint j, GLint k, const void *texel)
2335 {
2336    const GLfloat *src = (const GLfloat *) texel;
2337    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2338    *dst = float3_to_rgb9e5(src);
2339 }
2340 #endif
2341
2342
2343 /* MESA_FORMAT_R11_G11_B10_FLOAT *********************************************/
2344
2345 static void FETCH(r11_g11_b10f)( const struct swrast_texture_image *texImage,
2346                                  GLint i, GLint j, GLint k, GLfloat *texel )
2347 {
2348    const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2349    r11g11b10f_to_float3(*src, texel);
2350    texel[ACOMP] = 1.0F;
2351 }
2352
2353 #if DIM == 3
2354 static void store_texel_r11_g11_b10f(struct swrast_texture_image *texImage,
2355                                      GLint i, GLint j, GLint k, const void *texel)
2356 {
2357    const GLfloat *src = (const GLfloat *) texel;
2358    GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2359    *dst = float3_to_r11g11b10f(src);
2360 }
2361 #endif
2362
2363
2364 /* MESA_FORMAT_Z32_FLOAT_X24S8 ***********************************************/
2365
2366 static void FETCH(z32f_x24s8)(const struct swrast_texture_image *texImage,
2367                               GLint i, GLint j, GLint k, GLfloat *texel)
2368 {
2369    const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
2370    texel[RCOMP] = src[0];
2371    texel[GCOMP] = 0.0F;
2372    texel[BCOMP] = 0.0F;
2373    texel[ACOMP] = 1.0F;
2374 }
2375
2376 #if DIM == 3
2377 static void store_texel_z32f_x24s8(struct swrast_texture_image *texImage,
2378                                    GLint i, GLint j, GLint k, const void *texel)
2379 {
2380    const GLfloat *src = (const GLfloat *) texel;
2381    GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
2382    dst[0] = src[0];
2383 }
2384 #endif
2385
2386
2387 #undef TEXEL_ADDR
2388 #undef DIM
2389 #undef FETCH