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)->Map + (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)->Map + ((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)->Map + ((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 */
77static 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
85/* MESA_FORMAT_Z16 ***********************************************************/
86
87/* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
88 * returning 1 GLfloat.
89 * Note: no GLchan version of this function.
90 */
91static void FETCH(f_z16)(const struct swrast_texture_image *texImage,
92                         GLint i, GLint j, GLint k, GLfloat *texel )
93{
94   const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
95   texel[0] = src[0] * (1.0F / 65535.0F);
96}
97
98
99
100/* MESA_FORMAT_RGBA_F32 ******************************************************/
101
102/* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
103 */
104static void FETCH(f_rgba_f32)( const struct swrast_texture_image *texImage,
105                               GLint i, GLint j, GLint k, GLfloat *texel )
106{
107   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
108   texel[RCOMP] = src[0];
109   texel[GCOMP] = src[1];
110   texel[BCOMP] = src[2];
111   texel[ACOMP] = src[3];
112}
113
114
115
116
117/* MESA_FORMAT_RGBA_F16 ******************************************************/
118
119/* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
120 * returning 4 GLfloats.
121 */
122static void FETCH(f_rgba_f16)( const struct swrast_texture_image *texImage,
123                               GLint i, GLint j, GLint k, GLfloat *texel )
124{
125   const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
126   texel[RCOMP] = _mesa_half_to_float(src[0]);
127   texel[GCOMP] = _mesa_half_to_float(src[1]);
128   texel[BCOMP] = _mesa_half_to_float(src[2]);
129   texel[ACOMP] = _mesa_half_to_float(src[3]);
130}
131
132
133
134/* MESA_FORMAT_RGB_F32 *******************************************************/
135
136/* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
137 * returning 4 GLfloats.
138 */
139static void FETCH(f_rgb_f32)( const struct swrast_texture_image *texImage,
140                              GLint i, GLint j, GLint k, GLfloat *texel )
141{
142   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
143   texel[RCOMP] = src[0];
144   texel[GCOMP] = src[1];
145   texel[BCOMP] = src[2];
146   texel[ACOMP] = 1.0F;
147}
148
149
150
151
152/* MESA_FORMAT_RGB_F16 *******************************************************/
153
154/* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
155 * returning 4 GLfloats.
156 */
157static void FETCH(f_rgb_f16)( const struct swrast_texture_image *texImage,
158                              GLint i, GLint j, GLint k, GLfloat *texel )
159{
160   const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
161   texel[RCOMP] = _mesa_half_to_float(src[0]);
162   texel[GCOMP] = _mesa_half_to_float(src[1]);
163   texel[BCOMP] = _mesa_half_to_float(src[2]);
164   texel[ACOMP] = 1.0F;
165}
166
167
168
169
170/* MESA_FORMAT_ALPHA_F32 *****************************************************/
171
172/* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
173 * returning 4 GLfloats.
174 */
175static void FETCH(f_alpha_f32)( const struct swrast_texture_image *texImage,
176                              GLint i, GLint j, GLint k, GLfloat *texel )
177{
178   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
179   texel[RCOMP] =
180   texel[GCOMP] =
181   texel[BCOMP] = 0.0F;
182   texel[ACOMP] = src[0];
183}
184
185
186
187
188/* MESA_FORMAT_ALPHA_F32 *****************************************************/
189
190/* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
191 * returning 4 GLfloats.
192 */
193static void FETCH(f_alpha_f16)( const struct swrast_texture_image *texImage,
194                              GLint i, GLint j, GLint k, GLfloat *texel )
195{
196   const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
197   texel[RCOMP] =
198   texel[GCOMP] =
199   texel[BCOMP] = 0.0F;
200   texel[ACOMP] = _mesa_half_to_float(src[0]);
201}
202
203
204
205
206/* MESA_FORMAT_LUMINANCE_F32 *************************************************/
207
208/* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
209 * returning 4 GLfloats.
210 */
211static void FETCH(f_luminance_f32)( const struct swrast_texture_image *texImage,
212                                    GLint i, GLint j, GLint k, GLfloat *texel )
213{
214   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
215   texel[RCOMP] =
216   texel[GCOMP] =
217   texel[BCOMP] = src[0];
218   texel[ACOMP] = 1.0F;
219}
220
221
222
223
224/* MESA_FORMAT_LUMINANCE_F16 *************************************************/
225
226/* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
227 * returning 4 GLfloats.
228 */
229static void FETCH(f_luminance_f16)( const struct swrast_texture_image *texImage,
230                                    GLint i, GLint j, GLint k, GLfloat *texel )
231{
232   const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
233   texel[RCOMP] =
234   texel[GCOMP] =
235   texel[BCOMP] = _mesa_half_to_float(src[0]);
236   texel[ACOMP] = 1.0F;
237}
238
239
240
241
242/* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
243
244/* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
245 * returning 4 GLfloats.
246 */
247static void FETCH(f_luminance_alpha_f32)( const struct swrast_texture_image *texImage,
248                                    GLint i, GLint j, GLint k, GLfloat *texel )
249{
250   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
251   texel[RCOMP] =
252   texel[GCOMP] =
253   texel[BCOMP] = src[0];
254   texel[ACOMP] = src[1];
255}
256
257
258
259
260/* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
261
262/* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
263 * returning 4 GLfloats.
264 */
265static void FETCH(f_luminance_alpha_f16)( const struct swrast_texture_image *texImage,
266                                    GLint i, GLint j, GLint k, GLfloat *texel )
267{
268   const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
269   texel[RCOMP] =
270   texel[GCOMP] =
271   texel[BCOMP] = _mesa_half_to_float(src[0]);
272   texel[ACOMP] = _mesa_half_to_float(src[1]);
273}
274
275
276
277
278/* MESA_FORMAT_INTENSITY_F32 *************************************************/
279
280/* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
281 * returning 4 GLfloats.
282 */
283static void FETCH(f_intensity_f32)( const struct swrast_texture_image *texImage,
284                                    GLint i, GLint j, GLint k, GLfloat *texel )
285{
286   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
287   texel[RCOMP] =
288   texel[GCOMP] =
289   texel[BCOMP] =
290   texel[ACOMP] = src[0];
291}
292
293
294
295
296/* MESA_FORMAT_INTENSITY_F16 *************************************************/
297
298/* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
299 * returning 4 GLfloats.
300 */
301static void FETCH(f_intensity_f16)( const struct swrast_texture_image *texImage,
302                                    GLint i, GLint j, GLint k, GLfloat *texel )
303{
304   const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
305   texel[RCOMP] =
306   texel[GCOMP] =
307   texel[BCOMP] =
308   texel[ACOMP] = _mesa_half_to_float(src[0]);
309}
310
311
312
313
314/* MESA_FORMAT_R_FLOAT32 *****************************************************/
315
316/* Fetch texel from 1D, 2D or 3D R_FLOAT32 texture,
317 * returning 4 GLfloats.
318 */
319static void FETCH(f_r_f32)( const struct swrast_texture_image *texImage,
320                            GLint i, GLint j, GLint k, GLfloat *texel )
321{
322   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
323   texel[RCOMP] = src[0];
324   texel[GCOMP] = 0.0F;
325   texel[BCOMP] = 0.0F;
326   texel[ACOMP] = 1.0F;
327}
328
329
330
331
332/* MESA_FORMAT_R_FLOAT16 *****************************************************/
333
334/* Fetch texel from 1D, 2D or 3D R_FLOAT16 texture,
335 * returning 4 GLfloats.
336 */
337static void FETCH(f_r_f16)( const struct swrast_texture_image *texImage,
338                            GLint i, GLint j, GLint k, GLfloat *texel )
339{
340   const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
341   texel[RCOMP] = _mesa_half_to_float(src[0]);
342   texel[GCOMP] = 0.0F;
343   texel[BCOMP] = 0.0F;
344   texel[ACOMP] = 1.0F;
345}
346
347
348
349
350/* MESA_FORMAT_RG_FLOAT32 ****************************************************/
351
352/* Fetch texel from 1D, 2D or 3D RG_FLOAT32 texture,
353 * returning 4 GLfloats.
354 */
355static void FETCH(f_rg_f32)( const struct swrast_texture_image *texImage,
356                             GLint i, GLint j, GLint k, GLfloat *texel )
357{
358   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
359   texel[RCOMP] = src[0];
360   texel[GCOMP] = src[1];
361   texel[BCOMP] = 0.0F;
362   texel[ACOMP] = 1.0F;
363}
364
365
366
367
368/* MESA_FORMAT_RG_FLOAT16 ****************************************************/
369
370/* Fetch texel from 1D, 2D or 3D RG_FLOAT16 texture,
371 * returning 4 GLfloats.
372 */
373static void FETCH(f_rg_f16)( const struct swrast_texture_image *texImage,
374                             GLint i, GLint j, GLint k, GLfloat *texel )
375{
376   const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
377   texel[RCOMP] = _mesa_half_to_float(src[0]);
378   texel[GCOMP] = _mesa_half_to_float(src[1]);
379   texel[BCOMP] = 0.0F;
380   texel[ACOMP] = 1.0F;
381}
382
383
384
385
386/*
387 * Begin Hardware formats
388 */
389
390/* MESA_FORMAT_RGBA8888 ******************************************************/
391
392/* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
393static void FETCH(f_rgba8888)( const struct swrast_texture_image *texImage,
394                               GLint i, GLint j, GLint k, GLfloat *texel )
395{
396   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
397   texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
398   texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
399   texel[BCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
400   texel[ACOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
401}
402
403
404
405
406
407
408/* MESA_FORMAT_RGBA888_REV ***************************************************/
409
410/* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
411static void FETCH(f_rgba8888_rev)( const struct swrast_texture_image *texImage,
412                                   GLint i, GLint j, GLint k, GLfloat *texel )
413{
414   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
415   texel[RCOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
416   texel[GCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
417   texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
418   texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
419}
420
421
422
423
424/* MESA_FORMAT_ARGB8888 ******************************************************/
425
426/* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
427static void FETCH(f_argb8888)( const struct swrast_texture_image *texImage,
428                               GLint i, GLint j, GLint k, GLfloat *texel )
429{
430   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
431   texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
432   texel[GCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
433   texel[BCOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
434   texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
435}
436
437
438
439
440/* MESA_FORMAT_ARGB8888_REV **************************************************/
441
442/* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
443static void FETCH(f_argb8888_rev)( const struct swrast_texture_image *texImage,
444                                   GLint i, GLint j, GLint k, GLfloat *texel )
445{
446   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
447   texel[RCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
448   texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
449   texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
450   texel[ACOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
451}
452
453
454
455
456/* MESA_FORMAT_RGBX8888 ******************************************************/
457
458/* Fetch texel from 1D, 2D or 3D rgbx8888 texture, return 4 GLfloats */
459static void FETCH(f_rgbx8888)( const struct swrast_texture_image *texImage,
460                               GLint i, GLint j, GLint k, GLfloat *texel )
461{
462   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
463   texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
464   texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
465   texel[BCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
466   texel[ACOMP] = 1.0f;
467}
468
469
470
471
472/* MESA_FORMAT_RGBX888_REV ***************************************************/
473
474/* Fetch texel from 1D, 2D or 3D rgbx8888_rev texture, return 4 GLchans */
475static void FETCH(f_rgbx8888_rev)( const struct swrast_texture_image *texImage,
476                                   GLint i, GLint j, GLint k, GLfloat *texel )
477{
478   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
479   texel[RCOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
480   texel[GCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
481   texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
482   texel[ACOMP] = 1.0f;
483}
484
485
486
487
488/* MESA_FORMAT_XRGB8888 ******************************************************/
489
490/* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
491static void FETCH(f_xrgb8888)( const struct swrast_texture_image *texImage,
492                               GLint i, GLint j, GLint k, GLfloat *texel )
493{
494   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
495   texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
496   texel[GCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
497   texel[BCOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff );
498   texel[ACOMP] = 1.0f;
499}
500
501
502
503
504/* MESA_FORMAT_XRGB8888_REV **************************************************/
505
506/* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
507static void FETCH(f_xrgb8888_rev)( const struct swrast_texture_image *texImage,
508                                   GLint i, GLint j, GLint k, GLfloat *texel )
509{
510   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
511   texel[RCOMP] = UBYTE_TO_FLOAT( (s >>  8) & 0xff );
512   texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
513   texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24)        );
514   texel[ACOMP] = 1.0f;
515}
516
517
518
519
520/* MESA_FORMAT_RGB888 ********************************************************/
521
522/* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
523static void FETCH(f_rgb888)( const struct swrast_texture_image *texImage,
524                             GLint i, GLint j, GLint k, GLfloat *texel )
525{
526   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
527   texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
528   texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
529   texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
530   texel[ACOMP] = 1.0F;
531}
532
533
534
535
536/* MESA_FORMAT_BGR888 ********************************************************/
537
538/* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
539static void FETCH(f_bgr888)( const struct swrast_texture_image *texImage,
540                             GLint i, GLint j, GLint k, GLfloat *texel )
541{
542   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
543   texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
544   texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
545   texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
546   texel[ACOMP] = 1.0F;
547}
548
549
550
551
552/* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
553   instead of slow (g << 2) * 255 / 252 (always rounds down) */
554
555/* MESA_FORMAT_RGB565 ********************************************************/
556
557/* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
558static void FETCH(f_rgb565)( const struct swrast_texture_image *texImage,
559                             GLint i, GLint j, GLint k, GLfloat *texel )
560{
561   const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
562   const GLushort s = *src;
563   texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
564   texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
565   texel[BCOMP] = ((s      ) & 0x1f) * (1.0F / 31.0F);
566   texel[ACOMP] = 1.0F;
567}
568
569
570
571
572/* MESA_FORMAT_RGB565_REV ****************************************************/
573
574/* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
575static void FETCH(f_rgb565_rev)( const struct swrast_texture_image *texImage,
576                                 GLint i, GLint j, GLint k, GLfloat *texel )
577{
578   const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
579   const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
580   texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
581   texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >>  9) & 0x3) );
582   texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >>  2) & 0x7) );
583   texel[ACOMP] = 1.0F;
584}
585
586
587
588
589/* MESA_FORMAT_ARGB4444 ******************************************************/
590
591/* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
592static void FETCH(f_argb4444)( const struct swrast_texture_image *texImage,
593                               GLint i, GLint j, GLint k, GLfloat *texel )
594{
595   const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
596   const GLushort s = *src;
597   texel[RCOMP] = ((s >>  8) & 0xf) * (1.0F / 15.0F);
598   texel[GCOMP] = ((s >>  4) & 0xf) * (1.0F / 15.0F);
599   texel[BCOMP] = ((s      ) & 0xf) * (1.0F / 15.0F);
600   texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
601}
602
603
604
605
606/* MESA_FORMAT_ARGB4444_REV **************************************************/
607
608/* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
609static void FETCH(f_argb4444_rev)( const struct swrast_texture_image *texImage,
610                                   GLint i, GLint j, GLint k, GLfloat *texel )
611{
612   const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
613   texel[RCOMP] = ((s      ) & 0xf) * (1.0F / 15.0F);
614   texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
615   texel[BCOMP] = ((s >>  8) & 0xf) * (1.0F / 15.0F);
616   texel[ACOMP] = ((s >>  4) & 0xf) * (1.0F / 15.0F);
617}
618
619
620
621/* MESA_FORMAT_RGBA5551 ******************************************************/
622
623/* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
624static void FETCH(f_rgba5551)( const struct swrast_texture_image *texImage,
625                               GLint i, GLint j, GLint k, GLfloat *texel )
626{
627   const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
628   const GLushort s = *src;
629   texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
630   texel[GCOMP] = ((s >>  6) & 0x1f) * (1.0F / 31.0F);
631   texel[BCOMP] = ((s >>  1) & 0x1f) * (1.0F / 31.0F);
632   texel[ACOMP] = ((s      ) & 0x01) * 1.0F;
633}
634
635
636
637/* MESA_FORMAT_ARGB1555 ******************************************************/
638
639/* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
640static void FETCH(f_argb1555)( const struct swrast_texture_image *texImage,
641			     GLint i, GLint j, GLint k, GLfloat *texel )
642{
643   const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
644   const GLushort s = *src;
645   texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
646   texel[GCOMP] = ((s >>  5) & 0x1f) * (1.0F / 31.0F);
647   texel[BCOMP] = ((s >>  0) & 0x1f) * (1.0F / 31.0F);
648   texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
649}
650
651
652
653
654/* MESA_FORMAT_ARGB1555_REV **************************************************/
655
656/* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
657static void FETCH(f_argb1555_rev)( const struct swrast_texture_image *texImage,
658                                   GLint i, GLint j, GLint k, GLfloat *texel )
659{
660   const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
661   const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
662   texel[RCOMP] = UBYTE_TO_FLOAT( ((s >>  7) & 0xf8) | ((s >> 12) & 0x7) );
663   texel[GCOMP] = UBYTE_TO_FLOAT( ((s >>  2) & 0xf8) | ((s >>  7) & 0x7) );
664   texel[BCOMP] = UBYTE_TO_FLOAT( ((s <<  3) & 0xf8) | ((s >>  2) & 0x7) );
665   texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
666}
667
668
669
670
671/* MESA_FORMAT_ARGB2101010 ***************************************************/
672
673/* Fetch texel from 1D, 2D or 3D argb2101010 texture, return 4 GLchans */
674static void FETCH(f_argb2101010)( const struct swrast_texture_image *texImage,
675                                  GLint i, GLint j, GLint k, GLfloat *texel )
676{
677   const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
678   const GLuint s = *src;
679   texel[RCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F);
680   texel[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F);
681   texel[BCOMP] = ((s >>  0) & 0x3ff) * (1.0F / 1023.0F);
682   texel[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F);
683}
684
685
686
687
688/* MESA_FORMAT_GR88 **********************************************************/
689
690/* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
691static void FETCH(f_gr88)( const struct swrast_texture_image *texImage,
692                           GLint i, GLint j, GLint k, GLfloat *texel )
693{
694   const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
695   texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
696   texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
697   texel[BCOMP] = 0.0;
698   texel[ACOMP] = 1.0;
699}
700
701
702
703
704/* MESA_FORMAT_RG88 ******************************************************/
705
706/* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
707static void FETCH(f_rg88)( const struct swrast_texture_image *texImage,
708                           GLint i, GLint j, GLint k, GLfloat *texel )
709{
710   const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
711   texel[RCOMP] = UBYTE_TO_FLOAT( s >> 8 );
712   texel[GCOMP] = UBYTE_TO_FLOAT( s & 0xff );
713   texel[BCOMP] = 0.0;
714   texel[ACOMP] = 1.0;
715}
716
717
718
719
720/* MESA_FORMAT_AL44 **********************************************************/
721
722/* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
723static void FETCH(f_al44)( const struct swrast_texture_image *texImage,
724                           GLint i, GLint j, GLint k, GLfloat *texel )
725{
726   const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
727   texel[RCOMP] =
728   texel[GCOMP] =
729   texel[BCOMP] = (s & 0xf) * (1.0F / 15.0F);
730   texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
731}
732
733
734
735
736/* MESA_FORMAT_AL88 **********************************************************/
737
738/* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
739static void FETCH(f_al88)( const struct swrast_texture_image *texImage,
740                           GLint i, GLint j, GLint k, GLfloat *texel )
741{
742   const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
743   texel[RCOMP] =
744   texel[GCOMP] =
745   texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
746   texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
747}
748
749
750
751
752/* MESA_FORMAT_R8 ************************************************************/
753
754/* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
755static void FETCH(f_r8)(const struct swrast_texture_image *texImage,
756			GLint i, GLint j, GLint k, GLfloat *texel)
757{
758   const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
759   texel[RCOMP] = UBYTE_TO_FLOAT(s);
760   texel[GCOMP] = 0.0;
761   texel[BCOMP] = 0.0;
762   texel[ACOMP] = 1.0;
763}
764
765
766
767
768/* MESA_FORMAT_R16 ***********************************************************/
769
770/* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
771static void FETCH(f_r16)(const struct swrast_texture_image *texImage,
772			GLint i, GLint j, GLint k, GLfloat *texel)
773{
774   const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
775   texel[RCOMP] = USHORT_TO_FLOAT(s);
776   texel[GCOMP] = 0.0;
777   texel[BCOMP] = 0.0;
778   texel[ACOMP] = 1.0;
779}
780
781
782
783
784/* MESA_FORMAT_AL88_REV ******************************************************/
785
786/* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
787static void FETCH(f_al88_rev)( const struct swrast_texture_image *texImage,
788                               GLint i, GLint j, GLint k, GLfloat *texel )
789{
790   const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
791   texel[RCOMP] =
792   texel[GCOMP] =
793   texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
794   texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
795}
796
797
798
799
800/* MESA_FORMAT_RG1616 ********************************************************/
801
802/* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
803static void FETCH(f_rg1616)( const struct swrast_texture_image *texImage,
804                           GLint i, GLint j, GLint k, GLfloat *texel )
805{
806   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
807   texel[RCOMP] = USHORT_TO_FLOAT( s & 0xffff );
808   texel[GCOMP] = USHORT_TO_FLOAT( s >> 16 );
809   texel[BCOMP] = 0.0;
810   texel[ACOMP] = 1.0;
811}
812
813
814
815
816/* MESA_FORMAT_RG1616_REV ****************************************************/
817
818/* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
819static void FETCH(f_rg1616_rev)( const struct swrast_texture_image *texImage,
820                           GLint i, GLint j, GLint k, GLfloat *texel )
821{
822   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
823   texel[RCOMP] = USHORT_TO_FLOAT( s >> 16 );
824   texel[GCOMP] = USHORT_TO_FLOAT( s & 0xffff );
825   texel[BCOMP] = 0.0;
826   texel[ACOMP] = 1.0;
827}
828
829
830
831
832/* MESA_FORMAT_AL1616 ********************************************************/
833
834/* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
835static void FETCH(f_al1616)( const struct swrast_texture_image *texImage,
836			     GLint i, GLint j, GLint k, GLfloat *texel )
837{
838   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
839   texel[RCOMP] =
840   texel[GCOMP] =
841   texel[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
842   texel[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
843}
844
845
846
847
848/* MESA_FORMAT_AL1616_REV ****************************************************/
849
850/* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
851static void FETCH(f_al1616_rev)( const struct swrast_texture_image *texImage,
852				 GLint i, GLint j, GLint k, GLfloat *texel )
853{
854   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
855   texel[RCOMP] =
856   texel[GCOMP] =
857   texel[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
858   texel[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
859}
860
861
862
863
864/* MESA_FORMAT_RGB332 ********************************************************/
865
866/* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
867static void FETCH(f_rgb332)( const struct swrast_texture_image *texImage,
868                             GLint i, GLint j, GLint k, GLfloat *texel )
869{
870   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
871   const GLubyte s = *src;
872   texel[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
873   texel[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
874   texel[BCOMP] = ((s     ) & 0x3) * (1.0F / 3.0F);
875   texel[ACOMP] = 1.0F;
876}
877
878
879
880
881/* MESA_FORMAT_A8 ************************************************************/
882
883/* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
884static void FETCH(f_a8)( const struct swrast_texture_image *texImage,
885                         GLint i, GLint j, GLint k, GLfloat *texel )
886{
887   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
888   texel[RCOMP] =
889   texel[GCOMP] =
890   texel[BCOMP] = 0.0F;
891   texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
892}
893
894
895
896
897/* MESA_FORMAT_A16 ************************************************************/
898
899/* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
900static void FETCH(f_a16)( const struct swrast_texture_image *texImage,
901                          GLint i, GLint j, GLint k, GLfloat *texel )
902{
903   const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
904   texel[RCOMP] =
905   texel[GCOMP] =
906   texel[BCOMP] = 0.0F;
907   texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
908}
909
910
911
912
913/* MESA_FORMAT_L8 ************************************************************/
914
915/* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
916static void FETCH(f_l8)( const struct swrast_texture_image *texImage,
917                         GLint i, GLint j, GLint k, GLfloat *texel )
918{
919   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
920   texel[RCOMP] =
921   texel[GCOMP] =
922   texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
923   texel[ACOMP] = 1.0F;
924}
925
926
927
928
929/* MESA_FORMAT_L16 ***********************************************************/
930
931/* Fetch texel from 1D, 2D or 3D l16 texture, return 4 GLchans */
932static void FETCH(f_l16)( const struct swrast_texture_image *texImage,
933                          GLint i, GLint j, GLint k, GLfloat *texel )
934{
935   const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
936   texel[RCOMP] =
937   texel[GCOMP] =
938   texel[BCOMP] = USHORT_TO_FLOAT( src[0] );
939   texel[ACOMP] = 1.0F;
940}
941
942
943
944
945/* MESA_FORMAT_I8 ************************************************************/
946
947/* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
948static void FETCH(f_i8)( const struct swrast_texture_image *texImage,
949                         GLint i, GLint j, GLint k, GLfloat *texel )
950{
951   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
952   texel[RCOMP] =
953   texel[GCOMP] =
954   texel[BCOMP] =
955   texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
956}
957
958
959
960
961/* MESA_FORMAT_I16 ***********************************************************/
962
963/* Fetch texel from 1D, 2D or 3D i16 texture, return 4 GLchans */
964static void FETCH(f_i16)( const struct swrast_texture_image *texImage,
965                          GLint i, GLint j, GLint k, GLfloat *texel )
966{
967   const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
968   texel[RCOMP] =
969   texel[GCOMP] =
970   texel[BCOMP] =
971   texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
972}
973
974
975
976
977/* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
978/* Note: component order is same as for MESA_FORMAT_RGB888 */
979static void FETCH(srgb8)(const struct swrast_texture_image *texImage,
980                         GLint i, GLint j, GLint k, GLfloat *texel )
981{
982   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
983   texel[RCOMP] = nonlinear_to_linear(src[2]);
984   texel[GCOMP] = nonlinear_to_linear(src[1]);
985   texel[BCOMP] = nonlinear_to_linear(src[0]);
986   texel[ACOMP] = 1.0F;
987}
988
989
990
991/* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
992static void FETCH(srgba8)(const struct swrast_texture_image *texImage,
993                          GLint i, GLint j, GLint k, GLfloat *texel )
994{
995   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
996   texel[RCOMP] = nonlinear_to_linear( (s >> 24) );
997   texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
998   texel[BCOMP] = nonlinear_to_linear( (s >>  8) & 0xff );
999   texel[ACOMP] = UBYTE_TO_FLOAT( (s      ) & 0xff ); /* linear! */
1000}
1001
1002
1003
1004/* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1005static void FETCH(sargb8)(const struct swrast_texture_image *texImage,
1006                          GLint i, GLint j, GLint k, GLfloat *texel )
1007{
1008   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1009   texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1010   texel[GCOMP] = nonlinear_to_linear( (s >>  8) & 0xff );
1011   texel[BCOMP] = nonlinear_to_linear( (s      ) & 0xff );
1012   texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
1013}
1014
1015
1016
1017/* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1018static void FETCH(sl8)(const struct swrast_texture_image *texImage,
1019                       GLint i, GLint j, GLint k, GLfloat *texel )
1020{
1021   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1022   texel[RCOMP] =
1023   texel[GCOMP] =
1024   texel[BCOMP] = nonlinear_to_linear(src[0]);
1025   texel[ACOMP] = 1.0F;
1026}
1027
1028
1029
1030/* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1031static void FETCH(sla8)(const struct swrast_texture_image *texImage,
1032                       GLint i, GLint j, GLint k, GLfloat *texel )
1033{
1034   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1035   texel[RCOMP] =
1036   texel[GCOMP] =
1037   texel[BCOMP] = nonlinear_to_linear(src[0]);
1038   texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
1039}
1040
1041
1042
1043
1044/* MESA_FORMAT_RGBA_INT8 **************************************************/
1045
1046static void
1047FETCH(rgba_int8)(const struct swrast_texture_image *texImage,
1048                 GLint i, GLint j, GLint k, GLfloat *texel )
1049{
1050   const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
1051   texel[RCOMP] = (GLfloat) src[0];
1052   texel[GCOMP] = (GLfloat) src[1];
1053   texel[BCOMP] = (GLfloat) src[2];
1054   texel[ACOMP] = (GLfloat) src[3];
1055}
1056
1057
1058
1059
1060/* MESA_FORMAT_RGBA_INT16 **************************************************/
1061
1062static void
1063FETCH(rgba_int16)(const struct swrast_texture_image *texImage,
1064                  GLint i, GLint j, GLint k, GLfloat *texel )
1065{
1066   const GLshort *src = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1067   texel[RCOMP] = (GLfloat) src[0];
1068   texel[GCOMP] = (GLfloat) src[1];
1069   texel[BCOMP] = (GLfloat) src[2];
1070   texel[ACOMP] = (GLfloat) src[3];
1071}
1072
1073
1074
1075
1076/* MESA_FORMAT_RGBA_INT32 **************************************************/
1077
1078static void
1079FETCH(rgba_int32)(const struct swrast_texture_image *texImage,
1080                  GLint i, GLint j, GLint k, GLfloat *texel )
1081{
1082   const GLint *src = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
1083   texel[RCOMP] = (GLfloat) src[0];
1084   texel[GCOMP] = (GLfloat) src[1];
1085   texel[BCOMP] = (GLfloat) src[2];
1086   texel[ACOMP] = (GLfloat) src[3];
1087}
1088
1089
1090
1091
1092/* MESA_FORMAT_RGBA_UINT8 **************************************************/
1093
1094static void
1095FETCH(rgba_uint8)(const struct swrast_texture_image *texImage,
1096                 GLint i, GLint j, GLint k, GLfloat *texel )
1097{
1098   const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1099   texel[RCOMP] = (GLfloat) src[0];
1100   texel[GCOMP] = (GLfloat) src[1];
1101   texel[BCOMP] = (GLfloat) src[2];
1102   texel[ACOMP] = (GLfloat) src[3];
1103}
1104
1105
1106
1107
1108/* MESA_FORMAT_RGBA_UINT16 **************************************************/
1109
1110static void
1111FETCH(rgba_uint16)(const struct swrast_texture_image *texImage,
1112                  GLint i, GLint j, GLint k, GLfloat *texel )
1113{
1114   const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1115   texel[RCOMP] = (GLfloat) src[0];
1116   texel[GCOMP] = (GLfloat) src[1];
1117   texel[BCOMP] = (GLfloat) src[2];
1118   texel[ACOMP] = (GLfloat) src[3];
1119}
1120
1121
1122
1123
1124/* MESA_FORMAT_RGBA_UINT32 **************************************************/
1125
1126static void
1127FETCH(rgba_uint32)(const struct swrast_texture_image *texImage,
1128                  GLint i, GLint j, GLint k, GLfloat *texel )
1129{
1130   const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
1131   texel[RCOMP] = (GLfloat) src[0];
1132   texel[GCOMP] = (GLfloat) src[1];
1133   texel[BCOMP] = (GLfloat) src[2];
1134   texel[ACOMP] = (GLfloat) src[3];
1135}
1136
1137
1138
1139
1140/* MESA_FORMAT_DUDV8 ********************************************************/
1141
1142/* this format by definition produces 0,0,0,1 as rgba values,
1143   however we'll return the dudv values as rg and fix up elsewhere */
1144static void FETCH(dudv8)(const struct swrast_texture_image *texImage,
1145                         GLint i, GLint j, GLint k, GLfloat *texel )
1146{
1147   const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 2);
1148   texel[RCOMP] = BYTE_TO_FLOAT(src[0]);
1149   texel[GCOMP] = BYTE_TO_FLOAT(src[1]);
1150   texel[BCOMP] = 0;
1151   texel[ACOMP] = 0;
1152}
1153
1154
1155/* MESA_FORMAT_SIGNED_R8 ***********************************************/
1156
1157static void FETCH(signed_r8)( const struct swrast_texture_image *texImage,
1158                              GLint i, GLint j, GLint k, GLfloat *texel )
1159{
1160   const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1161   texel[RCOMP] = BYTE_TO_FLOAT_TEX( s );
1162   texel[GCOMP] = 0.0F;
1163   texel[BCOMP] = 0.0F;
1164   texel[ACOMP] = 1.0F;
1165}
1166
1167
1168
1169
1170/* MESA_FORMAT_SIGNED_A8 ***********************************************/
1171
1172static void FETCH(signed_a8)( const struct swrast_texture_image *texImage,
1173                              GLint i, GLint j, GLint k, GLfloat *texel )
1174{
1175   const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1176   texel[RCOMP] = 0.0F;
1177   texel[GCOMP] = 0.0F;
1178   texel[BCOMP] = 0.0F;
1179   texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
1180}
1181
1182
1183
1184
1185/* MESA_FORMAT_SIGNED_L8 ***********************************************/
1186
1187static void FETCH(signed_l8)( const struct swrast_texture_image *texImage,
1188                              GLint i, GLint j, GLint k, GLfloat *texel )
1189{
1190   const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1191   texel[RCOMP] =
1192   texel[GCOMP] =
1193   texel[BCOMP] = BYTE_TO_FLOAT_TEX( s );
1194   texel[ACOMP] = 1.0F;
1195}
1196
1197
1198
1199
1200/* MESA_FORMAT_SIGNED_I8 ***********************************************/
1201
1202static void FETCH(signed_i8)( const struct swrast_texture_image *texImage,
1203                              GLint i, GLint j, GLint k, GLfloat *texel )
1204{
1205   const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1206   texel[RCOMP] =
1207   texel[GCOMP] =
1208   texel[BCOMP] =
1209   texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
1210}
1211
1212
1213
1214
1215/* MESA_FORMAT_SIGNED_RG88_REV ***********************************************/
1216
1217static void FETCH(signed_rg88_rev)( const struct swrast_texture_image *texImage,
1218                                    GLint i, GLint j, GLint k, GLfloat *texel )
1219{
1220   const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1221   texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
1222   texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1223   texel[BCOMP] = 0.0F;
1224   texel[ACOMP] = 1.0F;
1225}
1226
1227
1228
1229
1230/* MESA_FORMAT_SIGNED_AL88 ***********************************************/
1231
1232static void FETCH(signed_al88)( const struct swrast_texture_image *texImage,
1233                                GLint i, GLint j, GLint k, GLfloat *texel )
1234{
1235   const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1236   texel[RCOMP] =
1237   texel[GCOMP] =
1238   texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
1239   texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1240}
1241
1242
1243
1244
1245/* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
1246
1247static void FETCH(signed_rgbx8888)( const struct swrast_texture_image *texImage,
1248			            GLint i, GLint j, GLint k, GLfloat *texel )
1249{
1250   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1251   texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1252   texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1253   texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >>  8) );
1254   texel[ACOMP] = 1.0f;
1255}
1256
1257
1258
1259
1260/* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1261
1262static void FETCH(signed_rgba8888)( const struct swrast_texture_image *texImage,
1263			            GLint i, GLint j, GLint k, GLfloat *texel )
1264{
1265   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1266   texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1267   texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1268   texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >>  8) );
1269   texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s      ) );
1270}
1271
1272
1273
1274static void FETCH(signed_rgba8888_rev)( const struct swrast_texture_image *texImage,
1275                                        GLint i, GLint j, GLint k, GLfloat *texel )
1276{
1277   const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1278   texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s      ) );
1279   texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >>  8) );
1280   texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1281   texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1282}
1283
1284
1285
1286
1287
1288/* MESA_FORMAT_SIGNED_R16 ***********************************************/
1289
1290static void
1291FETCH(signed_r16)(const struct swrast_texture_image *texImage,
1292                  GLint i, GLint j, GLint k, GLfloat *texel)
1293{
1294   const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1295   texel[RCOMP] = SHORT_TO_FLOAT_TEX( s );
1296   texel[GCOMP] = 0.0F;
1297   texel[BCOMP] = 0.0F;
1298   texel[ACOMP] = 1.0F;
1299}
1300
1301
1302
1303
1304/* MESA_FORMAT_SIGNED_A16 ***********************************************/
1305
1306static void
1307FETCH(signed_a16)(const struct swrast_texture_image *texImage,
1308                  GLint i, GLint j, GLint k, GLfloat *texel)
1309{
1310   const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1311   texel[RCOMP] = 0.0F;
1312   texel[GCOMP] = 0.0F;
1313   texel[BCOMP] = 0.0F;
1314   texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
1315}
1316
1317
1318
1319
1320/* MESA_FORMAT_SIGNED_L16 ***********************************************/
1321
1322static void
1323FETCH(signed_l16)(const struct swrast_texture_image *texImage,
1324                  GLint i, GLint j, GLint k, GLfloat *texel)
1325{
1326   const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1327   texel[RCOMP] =
1328   texel[GCOMP] =
1329   texel[BCOMP] = SHORT_TO_FLOAT_TEX( s );
1330   texel[ACOMP] = 1.0F;
1331}
1332
1333
1334
1335
1336/* MESA_FORMAT_SIGNED_I16 ***********************************************/
1337
1338static void
1339FETCH(signed_i16)(const struct swrast_texture_image *texImage,
1340                  GLint i, GLint j, GLint k, GLfloat *texel)
1341{
1342   const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1343   texel[RCOMP] =
1344   texel[GCOMP] =
1345   texel[BCOMP] =
1346   texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
1347}
1348
1349
1350
1351
1352/* MESA_FORMAT_SIGNED_RG1616 ***********************************************/
1353
1354static void
1355FETCH(signed_rg1616)(const struct swrast_texture_image *texImage,
1356                    GLint i, GLint j, GLint k, GLfloat *texel)
1357{
1358   const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
1359   texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1360   texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1361   texel[BCOMP] = 0.0F;
1362   texel[ACOMP] = 1.0F;
1363}
1364
1365
1366
1367
1368/* MESA_FORMAT_SIGNED_AL1616 ***********************************************/
1369
1370static void
1371FETCH(signed_al1616)(const struct swrast_texture_image *texImage,
1372                    GLint i, GLint j, GLint k, GLfloat *texel)
1373{
1374   const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
1375   texel[RCOMP] =
1376   texel[GCOMP] =
1377   texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1378   texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1379}
1380
1381
1382
1383
1384/* MESA_FORMAT_SIGNED_RGB_16 ***********************************************/
1385
1386static void
1387FETCH(signed_rgb_16)(const struct swrast_texture_image *texImage,
1388                     GLint i, GLint j, GLint k, GLfloat *texel)
1389{
1390   const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
1391   texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1392   texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1393   texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
1394   texel[ACOMP] = 1.0F;
1395}
1396
1397
1398
1399
1400/* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
1401
1402static void
1403FETCH(signed_rgba_16)(const struct swrast_texture_image *texImage,
1404                      GLint i, GLint j, GLint k, GLfloat *texel)
1405{
1406   const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1407   texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1408   texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1409   texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
1410   texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
1411}
1412
1413
1414
1415
1416
1417/* MESA_FORMAT_RGBA_16 ***********************************************/
1418
1419static void
1420FETCH(rgba_16)(const struct swrast_texture_image *texImage,
1421               GLint i, GLint j, GLint k, GLfloat *texel)
1422{
1423   const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1424   texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
1425   texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
1426   texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
1427   texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
1428}
1429
1430
1431
1432
1433
1434/* MESA_FORMAT_YCBCR *********************************************************/
1435
1436/* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
1437 * We convert YCbCr to RGB here.
1438 */
1439static void FETCH(f_ycbcr)( const struct swrast_texture_image *texImage,
1440                            GLint i, GLint j, GLint k, GLfloat *texel )
1441{
1442   const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1443   const GLushort *src1 = src0 + 1;                               /* odd */
1444   const GLubyte y0 = (*src0 >> 8) & 0xff;  /* luminance */
1445   const GLubyte cb = *src0 & 0xff;         /* chroma U */
1446   const GLubyte y1 = (*src1 >> 8) & 0xff;  /* luminance */
1447   const GLubyte cr = *src1 & 0xff;         /* chroma V */
1448   const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
1449   GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1450   GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1451   GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1452   r *= (1.0F / 255.0F);
1453   g *= (1.0F / 255.0F);
1454   b *= (1.0F / 255.0F);
1455   texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1456   texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1457   texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1458   texel[ACOMP] = 1.0F;
1459}
1460
1461
1462
1463
1464/* MESA_FORMAT_YCBCR_REV *****************************************************/
1465
1466/* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
1467 * We convert YCbCr to RGB here.
1468 */
1469static void FETCH(f_ycbcr_rev)( const struct swrast_texture_image *texImage,
1470                                GLint i, GLint j, GLint k, GLfloat *texel )
1471{
1472   const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1473   const GLushort *src1 = src0 + 1;                               /* odd */
1474   const GLubyte y0 = *src0 & 0xff;         /* luminance */
1475   const GLubyte cr = (*src0 >> 8) & 0xff;  /* chroma V */
1476   const GLubyte y1 = *src1 & 0xff;         /* luminance */
1477   const GLubyte cb = (*src1 >> 8) & 0xff;  /* chroma U */
1478   const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
1479   GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1480   GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1481   GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1482   r *= (1.0F / 255.0F);
1483   g *= (1.0F / 255.0F);
1484   b *= (1.0F / 255.0F);
1485   texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1486   texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1487   texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1488   texel[ACOMP] = 1.0F;
1489}
1490
1491
1492
1493
1494/* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1495
1496static void FETCH(f_z24_s8)( const struct swrast_texture_image *texImage,
1497                             GLint i, GLint j, GLint k, GLfloat *texel )
1498{
1499   /* only return Z, not stencil data */
1500   const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1501   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
1502   texel[0] = ((*src) >> 8) * scale;
1503   ASSERT(texImage->Base.TexFormat == MESA_FORMAT_Z24_S8 ||
1504	  texImage->Base.TexFormat == MESA_FORMAT_Z24_X8);
1505   ASSERT(texel[0] >= 0.0F);
1506   ASSERT(texel[0] <= 1.0F);
1507}
1508
1509
1510
1511
1512/* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1513
1514static void FETCH(f_s8_z24)( const struct swrast_texture_image *texImage,
1515                             GLint i, GLint j, GLint k, GLfloat *texel )
1516{
1517   /* only return Z, not stencil data */
1518   const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1519   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
1520   texel[0] = ((*src) & 0x00ffffff) * scale;
1521   ASSERT(texImage->Base.TexFormat == MESA_FORMAT_S8_Z24 ||
1522	  texImage->Base.TexFormat == MESA_FORMAT_X8_Z24);
1523   ASSERT(texel[0] >= 0.0F);
1524   ASSERT(texel[0] <= 1.0F);
1525}
1526
1527
1528
1529
1530/* MESA_FORMAT_RGB9_E5 ******************************************************/
1531
1532static void FETCH(rgb9_e5)( const struct swrast_texture_image *texImage,
1533                            GLint i, GLint j, GLint k, GLfloat *texel )
1534{
1535   const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1536   rgb9e5_to_float3(*src, texel);
1537   texel[ACOMP] = 1.0F;
1538}
1539
1540
1541
1542
1543/* MESA_FORMAT_R11_G11_B10_FLOAT *********************************************/
1544
1545static void FETCH(r11_g11_b10f)( const struct swrast_texture_image *texImage,
1546                                 GLint i, GLint j, GLint k, GLfloat *texel )
1547{
1548   const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1549   r11g11b10f_to_float3(*src, texel);
1550   texel[ACOMP] = 1.0F;
1551}
1552
1553
1554
1555
1556/* MESA_FORMAT_Z32_FLOAT_X24S8 ***********************************************/
1557
1558static void FETCH(z32f_x24s8)(const struct swrast_texture_image *texImage,
1559			      GLint i, GLint j, GLint k, GLfloat *texel)
1560{
1561   const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
1562   texel[RCOMP] = src[0];
1563   texel[GCOMP] = 0.0F;
1564   texel[BCOMP] = 0.0F;
1565   texel[ACOMP] = 1.0F;
1566}
1567
1568
1569
1570#undef TEXEL_ADDR
1571#undef DIM
1572#undef FETCH
1573