mesa: Add Android to list of platforms that define fpclassify()
[mesa.git] / src / mesa / main / 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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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_XRGB8888 ******************************************************/
650
651 /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
652 static void FETCH(f_xrgb8888)( const struct gl_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 >> 16) & 0xff );
657 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
658 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
659 texel[ACOMP] = 1.0f;
660 }
661
662 #if DIM == 3
663 static void store_texel_xrgb8888(struct gl_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(0xff, rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
669 }
670 #endif
671
672
673 /* MESA_FORMAT_XRGB8888_REV **************************************************/
674
675 /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
676 static void FETCH(f_xrgb8888_rev)( const struct gl_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 >> 8) & 0xff );
681 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
682 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
683 texel[ACOMP] = 1.0f;
684 }
685
686 #if DIM == 3
687 static void store_texel_xrgb8888_rev(struct gl_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(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], 0xff);
693 }
694 #endif
695
696
697 /* MESA_FORMAT_RGB888 ********************************************************/
698
699 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
700 static void FETCH(f_rgb888)( const struct gl_texture_image *texImage,
701 GLint i, GLint j, GLint k, GLfloat *texel )
702 {
703 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
704 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
705 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
706 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
707 texel[ACOMP] = 1.0F;
708 }
709
710 #if DIM == 3
711 static void store_texel_rgb888(struct gl_texture_image *texImage,
712 GLint i, GLint j, GLint k, const void *texel)
713 {
714 const GLubyte *rgba = (const GLubyte *) texel;
715 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
716 dst[0] = rgba[BCOMP];
717 dst[1] = rgba[GCOMP];
718 dst[2] = rgba[RCOMP];
719 }
720 #endif
721
722
723 /* MESA_FORMAT_BGR888 ********************************************************/
724
725 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
726 static void FETCH(f_bgr888)( const struct gl_texture_image *texImage,
727 GLint i, GLint j, GLint k, GLfloat *texel )
728 {
729 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
730 texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
731 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
732 texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
733 texel[ACOMP] = 1.0F;
734 }
735
736 #if DIM == 3
737 static void store_texel_bgr888(struct gl_texture_image *texImage,
738 GLint i, GLint j, GLint k, const void *texel)
739 {
740 const GLubyte *rgba = (const GLubyte *) texel;
741 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
742 dst[0] = rgba[RCOMP];
743 dst[1] = rgba[GCOMP];
744 dst[2] = rgba[BCOMP];
745 }
746 #endif
747
748
749 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
750 instead of slow (g << 2) * 255 / 252 (always rounds down) */
751
752 /* MESA_FORMAT_RGB565 ********************************************************/
753
754 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
755 static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
756 GLint i, GLint j, GLint k, GLfloat *texel )
757 {
758 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
759 const GLushort s = *src;
760 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
761 texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
762 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
763 texel[ACOMP] = 1.0F;
764 }
765
766 #if DIM == 3
767 static void store_texel_rgb565(struct gl_texture_image *texImage,
768 GLint i, GLint j, GLint k, const void *texel)
769 {
770 const GLubyte *rgba = (const GLubyte *) texel;
771 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
772 *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
773 }
774 #endif
775
776
777 /* MESA_FORMAT_RGB565_REV ****************************************************/
778
779 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
780 static void FETCH(f_rgb565_rev)( const struct gl_texture_image *texImage,
781 GLint i, GLint j, GLint k, GLfloat *texel )
782 {
783 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
784 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
785 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
786 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
787 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
788 texel[ACOMP] = 1.0F;
789 }
790
791 #if DIM == 3
792 static void store_texel_rgb565_rev(struct gl_texture_image *texImage,
793 GLint i, GLint j, GLint k, const void *texel)
794 {
795 const GLubyte *rgba = (const GLubyte *) texel;
796 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
797 *dst = PACK_COLOR_565(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
798 }
799 #endif
800
801
802 /* MESA_FORMAT_ARGB4444 ******************************************************/
803
804 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
805 static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
806 GLint i, GLint j, GLint k, GLfloat *texel )
807 {
808 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
809 const GLushort s = *src;
810 texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
811 texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
812 texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
813 texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
814 }
815
816 #if DIM == 3
817 static void store_texel_argb4444(struct gl_texture_image *texImage,
818 GLint i, GLint j, GLint k, const void *texel)
819 {
820 const GLubyte *rgba = (const GLubyte *) texel;
821 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
822 *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
823 }
824 #endif
825
826
827 /* MESA_FORMAT_ARGB4444_REV **************************************************/
828
829 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
830 static void FETCH(f_argb4444_rev)( const struct gl_texture_image *texImage,
831 GLint i, GLint j, GLint k, GLfloat *texel )
832 {
833 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
834 texel[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
835 texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
836 texel[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
837 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
838 }
839
840 #if DIM == 3
841 static void store_texel_argb4444_rev(struct gl_texture_image *texImage,
842 GLint i, GLint j, GLint k, const void *texel)
843 {
844 const GLubyte *rgba = (const GLubyte *) texel;
845 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
846 *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
847 }
848 #endif
849
850 /* MESA_FORMAT_RGBA5551 ******************************************************/
851
852 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
853 static void FETCH(f_rgba5551)( const struct gl_texture_image *texImage,
854 GLint i, GLint j, GLint k, GLfloat *texel )
855 {
856 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
857 const GLushort s = *src;
858 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
859 texel[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
860 texel[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
861 texel[ACOMP] = ((s ) & 0x01) * 1.0F;
862 }
863
864 #if DIM == 3
865 static void store_texel_rgba5551(struct gl_texture_image *texImage,
866 GLint i, GLint j, GLint k, const void *texel)
867 {
868 const GLubyte *rgba = (const GLubyte *) texel;
869 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
870 *dst = PACK_COLOR_5551(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
871 }
872 #endif
873
874 /* MESA_FORMAT_ARGB1555 ******************************************************/
875
876 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
877 static void FETCH(f_argb1555)( const struct gl_texture_image *texImage,
878 GLint i, GLint j, GLint k, GLfloat *texel )
879 {
880 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
881 const GLushort s = *src;
882 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
883 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
884 texel[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F);
885 texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
886 }
887
888 #if DIM == 3
889 static void store_texel_argb1555(struct gl_texture_image *texImage,
890 GLint i, GLint j, GLint k, const void *texel)
891 {
892 const GLubyte *rgba = (const GLubyte *) texel;
893 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
894 *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
895 }
896 #endif
897
898
899 /* MESA_FORMAT_ARGB1555_REV **************************************************/
900
901 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
902 static void FETCH(f_argb1555_rev)( const struct gl_texture_image *texImage,
903 GLint i, GLint j, GLint k, GLfloat *texel )
904 {
905 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
906 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
907 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
908 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
909 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
910 texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
911 }
912
913 #if DIM == 3
914 static void store_texel_argb1555_rev(struct gl_texture_image *texImage,
915 GLint i, GLint j, GLint k, const void *texel)
916 {
917 const GLubyte *rgba = (const GLubyte *) texel;
918 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
919 *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
920 }
921 #endif
922
923
924 /* MESA_FORMAT_ARGB2101010 ***************************************************/
925
926 /* Fetch texel from 1D, 2D or 3D argb2101010 texture, return 4 GLchans */
927 static void FETCH(f_argb2101010)( const struct gl_texture_image *texImage,
928 GLint i, GLint j, GLint k, GLfloat *texel )
929 {
930 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
931 const GLuint s = *src;
932 texel[RCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F);
933 texel[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F);
934 texel[BCOMP] = ((s >> 0) & 0x3ff) * (1.0F / 1023.0F);
935 texel[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F);
936 }
937
938 #if DIM == 3
939 static void store_texel_argb2101010(struct gl_texture_image *texImage,
940 GLint i, GLint j, GLint k, const void *texel)
941 {
942 const GLubyte *rgba = (const GLubyte *) texel;
943 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
944 *dst = PACK_COLOR_2101010_UB(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
945 }
946 #endif
947
948
949 /* MESA_FORMAT_RG88 **********************************************************/
950
951 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
952 static void FETCH(f_rg88)( const struct gl_texture_image *texImage,
953 GLint i, GLint j, GLint k, GLfloat *texel )
954 {
955 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
956 texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
957 texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
958 texel[BCOMP] = 0.0;
959 texel[ACOMP] = 1.0;
960 }
961
962 #if DIM == 3
963 static void store_texel_rg88(struct gl_texture_image *texImage,
964 GLint i, GLint j, GLint k, const void *texel)
965 {
966 const GLubyte *rgba = (const GLubyte *) texel;
967 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
968 *dst = PACK_COLOR_88(rgba[RCOMP], rgba[GCOMP]);
969 }
970 #endif
971
972
973 /* MESA_FORMAT_RG88_REV ******************************************************/
974
975 /* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
976 static void FETCH(f_rg88_rev)( const struct gl_texture_image *texImage,
977 GLint i, GLint j, GLint k, GLfloat *texel )
978 {
979 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
980 texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
981 texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
982 texel[BCOMP] = 0.0;
983 texel[ACOMP] = 1.0;
984 }
985
986 #if DIM == 3
987 static void store_texel_rg88_rev(struct gl_texture_image *texImage,
988 GLint i, GLint j, GLint k, const void *texel)
989 {
990 const GLubyte *rgba = (const GLubyte *) texel;
991 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
992 *dst = PACK_COLOR_88(rgba[GCOMP], rgba[RCOMP]);
993 }
994 #endif
995
996
997 /* MESA_FORMAT_AL44 **********************************************************/
998
999 /* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
1000 static void FETCH(f_al44)( const struct gl_texture_image *texImage,
1001 GLint i, GLint j, GLint k, GLfloat *texel )
1002 {
1003 const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1004 texel[RCOMP] =
1005 texel[GCOMP] =
1006 texel[BCOMP] = (s & 0xf) * (1.0F / 15.0F);
1007 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
1008 }
1009
1010 #if DIM == 3
1011 static void store_texel_al44(struct gl_texture_image *texImage,
1012 GLint i, GLint j, GLint k, const void *texel)
1013 {
1014 const GLubyte *rgba = (const GLubyte *) texel;
1015 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1016 *dst = PACK_COLOR_44(rgba[ACOMP], rgba[RCOMP]);
1017 }
1018 #endif
1019
1020
1021 /* MESA_FORMAT_AL88 **********************************************************/
1022
1023 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
1024 static void FETCH(f_al88)( const struct gl_texture_image *texImage,
1025 GLint i, GLint j, GLint k, GLfloat *texel )
1026 {
1027 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1028 texel[RCOMP] =
1029 texel[GCOMP] =
1030 texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
1031 texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
1032 }
1033
1034 #if DIM == 3
1035 static void store_texel_al88(struct gl_texture_image *texImage,
1036 GLint i, GLint j, GLint k, const void *texel)
1037 {
1038 const GLubyte *rgba = (const GLubyte *) texel;
1039 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1040 *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
1041 }
1042 #endif
1043
1044
1045 /* MESA_FORMAT_R8 ************************************************************/
1046
1047 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
1048 static void FETCH(f_r8)(const struct gl_texture_image *texImage,
1049 GLint i, GLint j, GLint k, GLfloat *texel)
1050 {
1051 const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1052 texel[RCOMP] = UBYTE_TO_FLOAT(s);
1053 texel[GCOMP] = 0.0;
1054 texel[BCOMP] = 0.0;
1055 texel[ACOMP] = 1.0;
1056 }
1057
1058 #if DIM == 3
1059 static void store_texel_r8(struct gl_texture_image *texImage,
1060 GLint i, GLint j, GLint k, const void *texel)
1061 {
1062 const GLubyte *rgba = (const GLubyte *) texel;
1063 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1064 *dst = rgba[RCOMP];
1065 }
1066 #endif
1067
1068
1069 /* MESA_FORMAT_R16 ***********************************************************/
1070
1071 /* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
1072 static void FETCH(f_r16)(const struct gl_texture_image *texImage,
1073 GLint i, GLint j, GLint k, GLfloat *texel)
1074 {
1075 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1076 texel[RCOMP] = USHORT_TO_FLOAT(s);
1077 texel[GCOMP] = 0.0;
1078 texel[BCOMP] = 0.0;
1079 texel[ACOMP] = 1.0;
1080 }
1081
1082 #if DIM == 3
1083 static void store_texel_r16(struct gl_texture_image *texImage,
1084 GLint i, GLint j, GLint k, const void *texel)
1085 {
1086 const GLushort *rgba = (const GLushort *) texel;
1087 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1088 *dst = rgba[RCOMP];
1089 }
1090 #endif
1091
1092
1093 /* MESA_FORMAT_AL88_REV ******************************************************/
1094
1095 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
1096 static void FETCH(f_al88_rev)( const struct gl_texture_image *texImage,
1097 GLint i, GLint j, GLint k, GLfloat *texel )
1098 {
1099 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1100 texel[RCOMP] =
1101 texel[GCOMP] =
1102 texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
1103 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
1104 }
1105
1106 #if DIM == 3
1107 static void store_texel_al88_rev(struct gl_texture_image *texImage,
1108 GLint i, GLint j, GLint k, const void *texel)
1109 {
1110 const GLubyte *rgba = (const GLubyte *) texel;
1111 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1112 *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
1113 }
1114 #endif
1115
1116
1117 /* MESA_FORMAT_RG1616 ********************************************************/
1118
1119 /* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
1120 static void FETCH(f_rg1616)( const struct gl_texture_image *texImage,
1121 GLint i, GLint j, GLint k, GLfloat *texel )
1122 {
1123 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1124 texel[RCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1125 texel[GCOMP] = USHORT_TO_FLOAT( s >> 16 );
1126 texel[BCOMP] = 0.0;
1127 texel[ACOMP] = 1.0;
1128 }
1129
1130 #if DIM == 3
1131 static void store_texel_rg1616(struct gl_texture_image *texImage,
1132 GLint i, GLint j, GLint k, const void *texel)
1133 {
1134 const GLubyte *rgba = (const GLubyte *) texel;
1135 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1136 *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[GCOMP]);
1137 }
1138 #endif
1139
1140
1141 /* MESA_FORMAT_RG1616_REV ****************************************************/
1142
1143 /* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
1144 static void FETCH(f_rg1616_rev)( const struct gl_texture_image *texImage,
1145 GLint i, GLint j, GLint k, GLfloat *texel )
1146 {
1147 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1148 texel[RCOMP] = USHORT_TO_FLOAT( s >> 16 );
1149 texel[GCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1150 texel[BCOMP] = 0.0;
1151 texel[ACOMP] = 1.0;
1152 }
1153
1154 #if DIM == 3
1155 static void store_texel_rg1616_rev(struct gl_texture_image *texImage,
1156 GLint i, GLint j, GLint k, const void *texel)
1157 {
1158 const GLubyte *rgba = (const GLubyte *) texel;
1159 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1160 *dst = PACK_COLOR_1616(rgba[GCOMP], rgba[RCOMP]);
1161 }
1162 #endif
1163
1164
1165 /* MESA_FORMAT_AL1616 ********************************************************/
1166
1167 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
1168 static void FETCH(f_al1616)( const struct gl_texture_image *texImage,
1169 GLint i, GLint j, GLint k, GLfloat *texel )
1170 {
1171 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1172 texel[RCOMP] =
1173 texel[GCOMP] =
1174 texel[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1175 texel[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
1176 }
1177
1178 #if DIM == 3
1179 static void store_texel_al1616(struct gl_texture_image *texImage,
1180 GLint i, GLint j, GLint k, const void *texel)
1181 {
1182 const GLushort *rgba = (const GLushort *) texel;
1183 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1184 *dst = PACK_COLOR_1616(rgba[ACOMP], rgba[RCOMP]);
1185 }
1186 #endif
1187
1188
1189 /* MESA_FORMAT_AL1616_REV ****************************************************/
1190
1191 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
1192 static void FETCH(f_al1616_rev)( const struct gl_texture_image *texImage,
1193 GLint i, GLint j, GLint k, GLfloat *texel )
1194 {
1195 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1196 texel[RCOMP] =
1197 texel[GCOMP] =
1198 texel[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
1199 texel[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
1200 }
1201
1202 #if DIM == 3
1203 static void store_texel_al1616_rev(struct gl_texture_image *texImage,
1204 GLint i, GLint j, GLint k, const void *texel)
1205 {
1206 const GLushort *rgba = (const GLushort *) texel;
1207 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1208 *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[ACOMP]);
1209 }
1210 #endif
1211
1212
1213 /* MESA_FORMAT_RGB332 ********************************************************/
1214
1215 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1216 static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
1217 GLint i, GLint j, GLint k, GLfloat *texel )
1218 {
1219 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1220 const GLubyte s = *src;
1221 texel[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
1222 texel[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
1223 texel[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F);
1224 texel[ACOMP] = 1.0F;
1225 }
1226
1227 #if DIM == 3
1228 static void store_texel_rgb332(struct gl_texture_image *texImage,
1229 GLint i, GLint j, GLint k, const void *texel)
1230 {
1231 const GLubyte *rgba = (const GLubyte *) texel;
1232 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1233 *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1234 }
1235 #endif
1236
1237
1238 /* MESA_FORMAT_A8 ************************************************************/
1239
1240 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1241 static void FETCH(f_a8)( const struct gl_texture_image *texImage,
1242 GLint i, GLint j, GLint k, GLfloat *texel )
1243 {
1244 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1245 texel[RCOMP] =
1246 texel[GCOMP] =
1247 texel[BCOMP] = 0.0F;
1248 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1249 }
1250
1251 #if DIM == 3
1252 static void store_texel_a8(struct gl_texture_image *texImage,
1253 GLint i, GLint j, GLint k, const void *texel)
1254 {
1255 const GLubyte *rgba = (const GLubyte *) texel;
1256 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1257 *dst = rgba[ACOMP];
1258 }
1259 #endif
1260
1261
1262 /* MESA_FORMAT_A16 ************************************************************/
1263
1264 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1265 static void FETCH(f_a16)( const struct gl_texture_image *texImage,
1266 GLint i, GLint j, GLint k, GLfloat *texel )
1267 {
1268 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1269 texel[RCOMP] =
1270 texel[GCOMP] =
1271 texel[BCOMP] = 0.0F;
1272 texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
1273 }
1274
1275 #if DIM == 3
1276 static void store_texel_a16(struct gl_texture_image *texImage,
1277 GLint i, GLint j, GLint k, const void *texel)
1278 {
1279 const GLushort *rgba = (const GLushort *) texel;
1280 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1281 *dst = rgba[ACOMP];
1282 }
1283 #endif
1284
1285
1286 /* MESA_FORMAT_L8 ************************************************************/
1287
1288 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1289 static void FETCH(f_l8)( const struct gl_texture_image *texImage,
1290 GLint i, GLint j, GLint k, GLfloat *texel )
1291 {
1292 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1293 texel[RCOMP] =
1294 texel[GCOMP] =
1295 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
1296 texel[ACOMP] = 1.0F;
1297 }
1298
1299 #if DIM == 3
1300 static void store_texel_l8(struct gl_texture_image *texImage,
1301 GLint i, GLint j, GLint k, const void *texel)
1302 {
1303 const GLubyte *rgba = (const GLubyte *) texel;
1304 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1305 *dst = rgba[RCOMP];
1306 }
1307 #endif
1308
1309
1310 /* MESA_FORMAT_L16 ***********************************************************/
1311
1312 /* Fetch texel from 1D, 2D or 3D l16 texture, return 4 GLchans */
1313 static void FETCH(f_l16)( const struct gl_texture_image *texImage,
1314 GLint i, GLint j, GLint k, GLfloat *texel )
1315 {
1316 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1317 texel[RCOMP] =
1318 texel[GCOMP] =
1319 texel[BCOMP] = USHORT_TO_FLOAT( src[0] );
1320 texel[ACOMP] = 1.0F;
1321 }
1322
1323 #if DIM == 3
1324 static void store_texel_l16(struct gl_texture_image *texImage,
1325 GLint i, GLint j, GLint k, const void *texel)
1326 {
1327 const GLushort *rgba = (const GLushort *) texel;
1328 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1329 *dst = rgba[RCOMP];
1330 }
1331 #endif
1332
1333
1334 /* MESA_FORMAT_I8 ************************************************************/
1335
1336 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1337 static void FETCH(f_i8)( const struct gl_texture_image *texImage,
1338 GLint i, GLint j, GLint k, GLfloat *texel )
1339 {
1340 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1341 texel[RCOMP] =
1342 texel[GCOMP] =
1343 texel[BCOMP] =
1344 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1345 }
1346
1347 #if DIM == 3
1348 static void store_texel_i8(struct gl_texture_image *texImage,
1349 GLint i, GLint j, GLint k, const void *texel)
1350 {
1351 const GLubyte *rgba = (const GLubyte *) texel;
1352 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1353 *dst = rgba[RCOMP];
1354 }
1355 #endif
1356
1357
1358 /* MESA_FORMAT_I16 ***********************************************************/
1359
1360 /* Fetch texel from 1D, 2D or 3D i16 texture, return 4 GLchans */
1361 static void FETCH(f_i16)( const struct gl_texture_image *texImage,
1362 GLint i, GLint j, GLint k, GLfloat *texel )
1363 {
1364 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1365 texel[RCOMP] =
1366 texel[GCOMP] =
1367 texel[BCOMP] =
1368 texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
1369 }
1370
1371 #if DIM == 3
1372 static void store_texel_i16(struct gl_texture_image *texImage,
1373 GLint i, GLint j, GLint k, const void *texel)
1374 {
1375 const GLushort *rgba = (const GLushort *) texel;
1376 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1377 *dst = rgba[RCOMP];
1378 }
1379 #endif
1380
1381
1382 /* MESA_FORMAT_CI8 ***********************************************************/
1383
1384 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1385 * color table, and return 4 GLchans.
1386 */
1387 static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
1388 GLint i, GLint j, GLint k, GLfloat *texel )
1389 {
1390 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1391 const struct gl_color_table *palette;
1392 GLuint index;
1393 GET_CURRENT_CONTEXT(ctx);
1394
1395 if (ctx->Texture.SharedPalette) {
1396 palette = &ctx->Texture.Palette;
1397 }
1398 else {
1399 palette = &texImage->TexObject->Palette;
1400 }
1401 if (palette->Size == 0)
1402 return; /* undefined results */
1403
1404 /* Mask the index against size of palette to avoid going out of bounds */
1405 index = (*src) & (palette->Size - 1);
1406
1407 {
1408 const GLfloat *table = palette->TableF;
1409 switch (palette->_BaseFormat) {
1410 case GL_ALPHA:
1411 texel[RCOMP] =
1412 texel[GCOMP] =
1413 texel[BCOMP] = 0.0F;
1414 texel[ACOMP] = table[index];
1415 break;
1416 case GL_LUMINANCE:
1417 texel[RCOMP] =
1418 texel[GCOMP] =
1419 texel[BCOMP] = table[index];
1420 texel[ACOMP] = 1.0F;
1421 break;
1422 case GL_INTENSITY:
1423 texel[RCOMP] =
1424 texel[GCOMP] =
1425 texel[BCOMP] =
1426 texel[ACOMP] = table[index];
1427 break;
1428 case GL_LUMINANCE_ALPHA:
1429 texel[RCOMP] =
1430 texel[GCOMP] =
1431 texel[BCOMP] = table[index * 2 + 0];
1432 texel[ACOMP] = table[index * 2 + 1];
1433 break;
1434 case GL_RGB:
1435 texel[RCOMP] = table[index * 3 + 0];
1436 texel[GCOMP] = table[index * 3 + 1];
1437 texel[BCOMP] = table[index * 3 + 2];
1438 texel[ACOMP] = 1.0F;
1439 break;
1440 case GL_RGBA:
1441 texel[RCOMP] = table[index * 4 + 0];
1442 texel[GCOMP] = table[index * 4 + 1];
1443 texel[BCOMP] = table[index * 4 + 2];
1444 texel[ACOMP] = table[index * 4 + 3];
1445 break;
1446 default:
1447 _mesa_problem(ctx, "Bad palette format in fetch_texel_ci8");
1448 return;
1449 }
1450 }
1451 }
1452
1453 #if DIM == 3
1454 static void store_texel_ci8(struct gl_texture_image *texImage,
1455 GLint i, GLint j, GLint k, const void *texel)
1456 {
1457 const GLubyte *index = (const GLubyte *) texel;
1458 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1459 *dst = *index;
1460 }
1461 #endif
1462
1463
1464 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1465 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1466 static void FETCH(srgb8)(const struct gl_texture_image *texImage,
1467 GLint i, GLint j, GLint k, GLfloat *texel )
1468 {
1469 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1470 texel[RCOMP] = nonlinear_to_linear(src[2]);
1471 texel[GCOMP] = nonlinear_to_linear(src[1]);
1472 texel[BCOMP] = nonlinear_to_linear(src[0]);
1473 texel[ACOMP] = 1.0F;
1474 }
1475
1476 #if DIM == 3
1477 static void store_texel_srgb8(struct gl_texture_image *texImage,
1478 GLint i, GLint j, GLint k, const void *texel)
1479 {
1480 const GLubyte *rgba = (const GLubyte *) texel;
1481 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1482 dst[0] = rgba[BCOMP]; /* no conversion */
1483 dst[1] = rgba[GCOMP];
1484 dst[2] = rgba[RCOMP];
1485 }
1486 #endif
1487
1488 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1489 static void FETCH(srgba8)(const struct gl_texture_image *texImage,
1490 GLint i, GLint j, GLint k, GLfloat *texel )
1491 {
1492 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1493 texel[RCOMP] = nonlinear_to_linear( (s >> 24) );
1494 texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1495 texel[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1496 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */
1497 }
1498
1499 #if DIM == 3
1500 static void store_texel_srgba8(struct gl_texture_image *texImage,
1501 GLint i, GLint j, GLint k, const void *texel)
1502 {
1503 const GLubyte *rgba = (const GLubyte *) texel;
1504 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1505 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1506 }
1507 #endif
1508
1509 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1510 static void FETCH(sargb8)(const struct gl_texture_image *texImage,
1511 GLint i, GLint j, GLint k, GLfloat *texel )
1512 {
1513 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1514 texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1515 texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1516 texel[BCOMP] = nonlinear_to_linear( (s ) & 0xff );
1517 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
1518 }
1519
1520 #if DIM == 3
1521 static void store_texel_sargb8(struct gl_texture_image *texImage,
1522 GLint i, GLint j, GLint k, const void *texel)
1523 {
1524 const GLubyte *rgba = (const GLubyte *) texel;
1525 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1526 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1527 }
1528 #endif
1529
1530 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1531 static void FETCH(sl8)(const struct gl_texture_image *texImage,
1532 GLint i, GLint j, GLint k, GLfloat *texel )
1533 {
1534 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1535 texel[RCOMP] =
1536 texel[GCOMP] =
1537 texel[BCOMP] = nonlinear_to_linear(src[0]);
1538 texel[ACOMP] = 1.0F;
1539 }
1540
1541 #if DIM == 3
1542 static void store_texel_sl8(struct gl_texture_image *texImage,
1543 GLint i, GLint j, GLint k, const void *texel)
1544 {
1545 const GLubyte *rgba = (const GLubyte *) texel;
1546 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1547 dst[0] = rgba[RCOMP];
1548 }
1549 #endif
1550
1551 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1552 static void FETCH(sla8)(const struct gl_texture_image *texImage,
1553 GLint i, GLint j, GLint k, GLfloat *texel )
1554 {
1555 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1556 texel[RCOMP] =
1557 texel[GCOMP] =
1558 texel[BCOMP] = nonlinear_to_linear(src[0]);
1559 texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
1560 }
1561
1562 #if DIM == 3
1563 static void store_texel_sla8(struct gl_texture_image *texImage,
1564 GLint i, GLint j, GLint k, const void *texel)
1565 {
1566 const GLubyte *rgba = (const GLubyte *) texel;
1567 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1568 dst[0] = rgba[RCOMP];
1569 dst[1] = rgba[ACOMP];
1570 }
1571 #endif
1572
1573
1574 /* MESA_FORMAT_RGBA_INT8 **************************************************/
1575
1576 static void
1577 FETCH(rgba_int8)(const struct gl_texture_image *texImage,
1578 GLint i, GLint j, GLint k, GLfloat *texel )
1579 {
1580 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
1581 texel[RCOMP] = (GLfloat) src[0];
1582 texel[GCOMP] = (GLfloat) src[1];
1583 texel[BCOMP] = (GLfloat) src[2];
1584 texel[ACOMP] = (GLfloat) src[3];
1585 }
1586
1587 #if DIM == 3
1588 static void
1589 store_texel_rgba_int8(struct gl_texture_image *texImage,
1590 GLint i, GLint j, GLint k, const void *texel)
1591 {
1592 const GLbyte *rgba = (const GLbyte *) texel;
1593 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
1594 dst[0] = rgba[RCOMP];
1595 dst[1] = rgba[GCOMP];
1596 dst[2] = rgba[BCOMP];
1597 dst[3] = rgba[ACOMP];
1598 }
1599 #endif
1600
1601
1602 /* MESA_FORMAT_RGBA_INT16 **************************************************/
1603
1604 static void
1605 FETCH(rgba_int16)(const struct gl_texture_image *texImage,
1606 GLint i, GLint j, GLint k, GLfloat *texel )
1607 {
1608 const GLshort *src = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1609 texel[RCOMP] = (GLfloat) src[0];
1610 texel[GCOMP] = (GLfloat) src[1];
1611 texel[BCOMP] = (GLfloat) src[2];
1612 texel[ACOMP] = (GLfloat) src[3];
1613 }
1614
1615 #if DIM == 3
1616 static void
1617 store_texel_rgba_int16(struct gl_texture_image *texImage,
1618 GLint i, GLint j, GLint k, const void *texel)
1619 {
1620 const GLshort *rgba = (const GLshort *) texel;
1621 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1622 dst[0] = rgba[RCOMP];
1623 dst[1] = rgba[GCOMP];
1624 dst[2] = rgba[BCOMP];
1625 dst[3] = rgba[ACOMP];
1626 }
1627 #endif
1628
1629
1630 /* MESA_FORMAT_RGBA_INT32 **************************************************/
1631
1632 static void
1633 FETCH(rgba_int32)(const struct gl_texture_image *texImage,
1634 GLint i, GLint j, GLint k, GLfloat *texel )
1635 {
1636 const GLint *src = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
1637 texel[RCOMP] = (GLfloat) src[0];
1638 texel[GCOMP] = (GLfloat) src[1];
1639 texel[BCOMP] = (GLfloat) src[2];
1640 texel[ACOMP] = (GLfloat) src[3];
1641 }
1642
1643 #if DIM == 3
1644 static void
1645 store_texel_rgba_int32(struct gl_texture_image *texImage,
1646 GLint i, GLint j, GLint k, const void *texel)
1647 {
1648 const GLint *rgba = (const GLint *) texel;
1649 GLint *dst = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
1650 dst[0] = rgba[RCOMP];
1651 dst[1] = rgba[GCOMP];
1652 dst[2] = rgba[BCOMP];
1653 dst[3] = rgba[ACOMP];
1654 }
1655 #endif
1656
1657
1658 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
1659
1660 static void
1661 FETCH(rgba_uint8)(const struct gl_texture_image *texImage,
1662 GLint i, GLint j, GLint k, GLfloat *texel )
1663 {
1664 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1665 texel[RCOMP] = (GLfloat) src[0];
1666 texel[GCOMP] = (GLfloat) src[1];
1667 texel[BCOMP] = (GLfloat) src[2];
1668 texel[ACOMP] = (GLfloat) src[3];
1669 }
1670
1671 #if DIM == 3
1672 static void
1673 store_texel_rgba_uint8(struct gl_texture_image *texImage,
1674 GLint i, GLint j, GLint k, const void *texel)
1675 {
1676 const GLubyte *rgba = (const GLubyte *) texel;
1677 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1678 dst[0] = rgba[RCOMP];
1679 dst[1] = rgba[GCOMP];
1680 dst[2] = rgba[BCOMP];
1681 dst[3] = rgba[ACOMP];
1682 }
1683 #endif
1684
1685
1686 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
1687
1688 static void
1689 FETCH(rgba_uint16)(const struct gl_texture_image *texImage,
1690 GLint i, GLint j, GLint k, GLfloat *texel )
1691 {
1692 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1693 texel[RCOMP] = (GLfloat) src[0];
1694 texel[GCOMP] = (GLfloat) src[1];
1695 texel[BCOMP] = (GLfloat) src[2];
1696 texel[ACOMP] = (GLfloat) src[3];
1697 }
1698
1699 #if DIM == 3
1700 static void
1701 store_texel_rgba_uint16(struct gl_texture_image *texImage,
1702 GLint i, GLint j, GLint k, const void *texel)
1703 {
1704 const GLushort *rgba = (const GLushort *) texel;
1705 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1706 dst[0] = rgba[RCOMP];
1707 dst[1] = rgba[GCOMP];
1708 dst[2] = rgba[BCOMP];
1709 dst[3] = rgba[ACOMP];
1710 }
1711 #endif
1712
1713
1714 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
1715
1716 static void
1717 FETCH(rgba_uint32)(const struct gl_texture_image *texImage,
1718 GLint i, GLint j, GLint k, GLfloat *texel )
1719 {
1720 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
1721 texel[RCOMP] = (GLfloat) src[0];
1722 texel[GCOMP] = (GLfloat) src[1];
1723 texel[BCOMP] = (GLfloat) src[2];
1724 texel[ACOMP] = (GLfloat) src[3];
1725 }
1726
1727 #if DIM == 3
1728 static void
1729 store_texel_rgba_uint32(struct gl_texture_image *texImage,
1730 GLint i, GLint j, GLint k, const void *texel)
1731 {
1732 const GLuint *rgba = (const GLuint *) texel;
1733 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
1734 dst[0] = rgba[RCOMP];
1735 dst[1] = rgba[GCOMP];
1736 dst[2] = rgba[BCOMP];
1737 dst[3] = rgba[ACOMP];
1738 }
1739 #endif
1740
1741
1742 /* MESA_FORMAT_DUDV8 ********************************************************/
1743
1744 /* this format by definition produces 0,0,0,1 as rgba values,
1745 however we'll return the dudv values as rg and fix up elsewhere */
1746 static void FETCH(dudv8)(const struct gl_texture_image *texImage,
1747 GLint i, GLint j, GLint k, GLfloat *texel )
1748 {
1749 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 2);
1750 texel[RCOMP] = BYTE_TO_FLOAT(src[0]);
1751 texel[GCOMP] = BYTE_TO_FLOAT(src[1]);
1752 texel[BCOMP] = 0;
1753 texel[ACOMP] = 0;
1754 }
1755
1756
1757 /* MESA_FORMAT_SIGNED_R8 ***********************************************/
1758
1759 static void FETCH(signed_r8)( const struct gl_texture_image *texImage,
1760 GLint i, GLint j, GLint k, GLfloat *texel )
1761 {
1762 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1763 texel[RCOMP] = BYTE_TO_FLOAT_TEX( s );
1764 texel[GCOMP] = 0.0F;
1765 texel[BCOMP] = 0.0F;
1766 texel[ACOMP] = 1.0F;
1767 }
1768
1769 #if DIM == 3
1770 static void store_texel_signed_r8(struct gl_texture_image *texImage,
1771 GLint i, GLint j, GLint k, const void *texel)
1772 {
1773 const GLbyte *rgba = (const GLbyte *) texel;
1774 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1775 *dst = rgba[RCOMP];
1776 }
1777 #endif
1778
1779
1780 /* MESA_FORMAT_SIGNED_A8 ***********************************************/
1781
1782 static void FETCH(signed_a8)( const struct gl_texture_image *texImage,
1783 GLint i, GLint j, GLint k, GLfloat *texel )
1784 {
1785 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1786 texel[RCOMP] = 0.0F;
1787 texel[GCOMP] = 0.0F;
1788 texel[BCOMP] = 0.0F;
1789 texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
1790 }
1791
1792 #if DIM == 3
1793 static void store_texel_signed_a8(struct gl_texture_image *texImage,
1794 GLint i, GLint j, GLint k, const void *texel)
1795 {
1796 const GLbyte *rgba = (const GLbyte *) texel;
1797 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1798 *dst = rgba[ACOMP];
1799 }
1800 #endif
1801
1802
1803 /* MESA_FORMAT_SIGNED_L8 ***********************************************/
1804
1805 static void FETCH(signed_l8)( const struct gl_texture_image *texImage,
1806 GLint i, GLint j, GLint k, GLfloat *texel )
1807 {
1808 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1809 texel[RCOMP] =
1810 texel[GCOMP] =
1811 texel[BCOMP] = BYTE_TO_FLOAT_TEX( s );
1812 texel[ACOMP] = 1.0F;
1813 }
1814
1815 #if DIM == 3
1816 static void store_texel_signed_l8(struct gl_texture_image *texImage,
1817 GLint i, GLint j, GLint k, const void *texel)
1818 {
1819 const GLbyte *rgba = (const GLbyte *) texel;
1820 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1821 *dst = rgba[RCOMP];
1822 }
1823 #endif
1824
1825
1826 /* MESA_FORMAT_SIGNED_I8 ***********************************************/
1827
1828 static void FETCH(signed_i8)( const struct gl_texture_image *texImage,
1829 GLint i, GLint j, GLint k, GLfloat *texel )
1830 {
1831 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1832 texel[RCOMP] =
1833 texel[GCOMP] =
1834 texel[BCOMP] =
1835 texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
1836 }
1837
1838 #if DIM == 3
1839 static void store_texel_signed_i8(struct gl_texture_image *texImage,
1840 GLint i, GLint j, GLint k, const void *texel)
1841 {
1842 const GLbyte *rgba = (const GLbyte *) texel;
1843 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1844 *dst = rgba[RCOMP];
1845 }
1846 #endif
1847
1848
1849 /* MESA_FORMAT_SIGNED_RG88_REV ***********************************************/
1850
1851 static void FETCH(signed_rg88_rev)( const struct gl_texture_image *texImage,
1852 GLint i, GLint j, GLint k, GLfloat *texel )
1853 {
1854 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1855 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
1856 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1857 texel[BCOMP] = 0.0F;
1858 texel[ACOMP] = 1.0F;
1859 }
1860
1861 #if DIM == 3
1862 static void store_texel_signed_rg88_rev(struct gl_texture_image *texImage,
1863 GLint i, GLint j, GLint k, const void *texel)
1864 {
1865 const GLbyte *rg = (const GLbyte *) texel;
1866 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1867 dst[0] = PACK_COLOR_88(rg[GCOMP], rg[RCOMP]);
1868 }
1869 #endif
1870
1871
1872 /* MESA_FORMAT_SIGNED_AL88 ***********************************************/
1873
1874 static void FETCH(signed_al88)( const struct gl_texture_image *texImage,
1875 GLint i, GLint j, GLint k, GLfloat *texel )
1876 {
1877 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1878 texel[RCOMP] =
1879 texel[GCOMP] =
1880 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
1881 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1882 }
1883
1884 #if DIM == 3
1885 static void store_texel_signed_al88(struct gl_texture_image *texImage,
1886 GLint i, GLint j, GLint k, const void *texel)
1887 {
1888 const GLbyte *rg = (const GLbyte *) texel;
1889 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1890 dst[0] = PACK_COLOR_88(rg[ACOMP], rg[RCOMP]);
1891 }
1892 #endif
1893
1894
1895 /* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
1896
1897 static void FETCH(signed_rgbx8888)( const struct gl_texture_image *texImage,
1898 GLint i, GLint j, GLint k, GLfloat *texel )
1899 {
1900 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1901 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1902 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1903 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1904 texel[ACOMP] = 1.0f;
1905 }
1906
1907 #if DIM == 3
1908 static void store_texel_signed_rgbx8888(struct gl_texture_image *texImage,
1909 GLint i, GLint j, GLint k, const void *texel)
1910 {
1911 const GLbyte *rgba = (const GLbyte *) texel;
1912 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1913 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 255);
1914 }
1915 #endif
1916
1917
1918 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1919
1920 static void FETCH(signed_rgba8888)( const struct gl_texture_image *texImage,
1921 GLint i, GLint j, GLint k, GLfloat *texel )
1922 {
1923 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1924 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1925 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1926 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1927 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1928 }
1929
1930 #if DIM == 3
1931 static void store_texel_signed_rgba8888(struct gl_texture_image *texImage,
1932 GLint i, GLint j, GLint k, const void *texel)
1933 {
1934 const GLbyte *rgba = (const GLbyte *) texel;
1935 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1936 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1937 }
1938 #endif
1939
1940 static void FETCH(signed_rgba8888_rev)( const struct gl_texture_image *texImage,
1941 GLint i, GLint j, GLint k, GLfloat *texel )
1942 {
1943 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1944 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1945 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1946 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1947 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1948 }
1949
1950 #if DIM == 3
1951 static void store_texel_signed_rgba8888_rev(struct gl_texture_image *texImage,
1952 GLint i, GLint j, GLint k, const void *texel)
1953 {
1954 const GLubyte *rgba = (const GLubyte *) texel;
1955 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1956 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1957 }
1958 #endif
1959
1960
1961
1962 /* MESA_FORMAT_SIGNED_R16 ***********************************************/
1963
1964 static void
1965 FETCH(signed_r16)(const struct gl_texture_image *texImage,
1966 GLint i, GLint j, GLint k, GLfloat *texel)
1967 {
1968 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1969 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s );
1970 texel[GCOMP] = 0.0F;
1971 texel[BCOMP] = 0.0F;
1972 texel[ACOMP] = 1.0F;
1973 }
1974
1975 #if DIM == 3
1976 static void
1977 store_texel_signed_r16(struct gl_texture_image *texImage,
1978 GLint i, GLint j, GLint k, const void *texel)
1979 {
1980 const GLshort *rgba = (const GLshort *) texel;
1981 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1982 *dst = rgba[0];
1983 }
1984 #endif
1985
1986
1987 /* MESA_FORMAT_SIGNED_A16 ***********************************************/
1988
1989 static void
1990 FETCH(signed_a16)(const struct gl_texture_image *texImage,
1991 GLint i, GLint j, GLint k, GLfloat *texel)
1992 {
1993 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1994 texel[RCOMP] = 0.0F;
1995 texel[GCOMP] = 0.0F;
1996 texel[BCOMP] = 0.0F;
1997 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
1998 }
1999
2000 #if DIM == 3
2001 static void
2002 store_texel_signed_a16(struct gl_texture_image *texImage,
2003 GLint i, GLint j, GLint k, const void *texel)
2004 {
2005 const GLshort *rgba = (const GLshort *) texel;
2006 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
2007 *dst = rgba[ACOMP];
2008 }
2009 #endif
2010
2011
2012 /* MESA_FORMAT_SIGNED_L16 ***********************************************/
2013
2014 static void
2015 FETCH(signed_l16)(const struct gl_texture_image *texImage,
2016 GLint i, GLint j, GLint k, GLfloat *texel)
2017 {
2018 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
2019 texel[RCOMP] =
2020 texel[GCOMP] =
2021 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s );
2022 texel[ACOMP] = 1.0F;
2023 }
2024
2025 #if DIM == 3
2026 static void
2027 store_texel_signed_l16(struct gl_texture_image *texImage,
2028 GLint i, GLint j, GLint k, const void *texel)
2029 {
2030 const GLshort *rgba = (const GLshort *) texel;
2031 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
2032 *dst = rgba[RCOMP];
2033 }
2034 #endif
2035
2036
2037 /* MESA_FORMAT_SIGNED_I16 ***********************************************/
2038
2039 static void
2040 FETCH(signed_i16)(const struct gl_texture_image *texImage,
2041 GLint i, GLint j, GLint k, GLfloat *texel)
2042 {
2043 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
2044 texel[RCOMP] =
2045 texel[GCOMP] =
2046 texel[BCOMP] =
2047 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
2048 }
2049
2050 #if DIM == 3
2051 static void
2052 store_texel_signed_i16(struct gl_texture_image *texImage,
2053 GLint i, GLint j, GLint k, const void *texel)
2054 {
2055 const GLshort *rgba = (const GLshort *) texel;
2056 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
2057 *dst = rgba[RCOMP];
2058 }
2059 #endif
2060
2061
2062 /* MESA_FORMAT_SIGNED_RG1616 ***********************************************/
2063
2064 static void
2065 FETCH(signed_rg1616)(const struct gl_texture_image *texImage,
2066 GLint i, GLint j, GLint k, GLfloat *texel)
2067 {
2068 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2069 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2070 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2071 texel[BCOMP] = 0.0F;
2072 texel[ACOMP] = 1.0F;
2073 }
2074
2075 #if DIM == 3
2076 static void
2077 store_texel_signed_rg1616(struct gl_texture_image *texImage,
2078 GLint i, GLint j, GLint k, const void *texel)
2079 {
2080 const GLshort *rgba = (const GLshort *) texel;
2081 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2082 dst[0] = rgba[RCOMP];
2083 dst[1] = rgba[GCOMP];
2084 }
2085 #endif
2086
2087
2088 /* MESA_FORMAT_SIGNED_AL1616 ***********************************************/
2089
2090 static void
2091 FETCH(signed_al1616)(const struct gl_texture_image *texImage,
2092 GLint i, GLint j, GLint k, GLfloat *texel)
2093 {
2094 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2095 texel[RCOMP] =
2096 texel[GCOMP] =
2097 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2098 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2099 }
2100
2101 #if DIM == 3
2102 static void
2103 store_texel_signed_al1616(struct gl_texture_image *texImage,
2104 GLint i, GLint j, GLint k, const void *texel)
2105 {
2106 const GLshort *rgba = (const GLshort *) texel;
2107 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2108 dst[0] = rgba[RCOMP];
2109 dst[1] = rgba[ACOMP];
2110 }
2111 #endif
2112
2113
2114 /* MESA_FORMAT_SIGNED_RGB_16 ***********************************************/
2115
2116 static void
2117 FETCH(signed_rgb_16)(const struct gl_texture_image *texImage,
2118 GLint i, GLint j, GLint k, GLfloat *texel)
2119 {
2120 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
2121 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2122 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2123 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
2124 texel[ACOMP] = 1.0F;
2125 }
2126
2127 #if DIM == 3
2128 static void
2129 store_texel_signed_rgb_16(struct gl_texture_image *texImage,
2130 GLint i, GLint j, GLint k, const void *texel)
2131 {
2132 const GLshort *rgba = (const GLshort *) texel;
2133 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
2134 dst[0] = rgba[RCOMP];
2135 dst[1] = rgba[GCOMP];
2136 dst[2] = rgba[BCOMP];
2137 }
2138 #endif
2139
2140
2141 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
2142
2143 static void
2144 FETCH(signed_rgba_16)(const struct gl_texture_image *texImage,
2145 GLint i, GLint j, GLint k, GLfloat *texel)
2146 {
2147 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
2148 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2149 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2150 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
2151 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
2152 }
2153
2154 #if DIM == 3
2155 static void
2156 store_texel_signed_rgba_16(struct gl_texture_image *texImage,
2157 GLint i, GLint j, GLint k, const void *texel)
2158 {
2159 const GLshort *rgba = (const GLshort *) texel;
2160 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
2161 dst[0] = rgba[RCOMP];
2162 dst[1] = rgba[GCOMP];
2163 dst[2] = rgba[BCOMP];
2164 dst[3] = rgba[ACOMP];
2165 }
2166 #endif
2167
2168
2169
2170 /* MESA_FORMAT_RGBA_16 ***********************************************/
2171
2172 static void
2173 FETCH(rgba_16)(const struct gl_texture_image *texImage,
2174 GLint i, GLint j, GLint k, GLfloat *texel)
2175 {
2176 const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
2177 texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
2178 texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
2179 texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
2180 texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
2181 }
2182
2183 #if DIM == 3
2184 static void
2185 store_texel_rgba_16(struct gl_texture_image *texImage,
2186 GLint i, GLint j, GLint k, const void *texel)
2187 {
2188 const GLushort *rgba = (const GLushort *) texel;
2189 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
2190 dst[0] = rgba[RCOMP];
2191 dst[1] = rgba[GCOMP];
2192 dst[2] = rgba[BCOMP];
2193 dst[3] = rgba[ACOMP];
2194 }
2195 #endif
2196
2197
2198
2199 /* MESA_FORMAT_YCBCR *********************************************************/
2200
2201 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
2202 * We convert YCbCr to RGB here.
2203 */
2204 static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
2205 GLint i, GLint j, GLint k, GLfloat *texel )
2206 {
2207 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
2208 const GLushort *src1 = src0 + 1; /* odd */
2209 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
2210 const GLubyte cb = *src0 & 0xff; /* chroma U */
2211 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
2212 const GLubyte cr = *src1 & 0xff; /* chroma V */
2213 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
2214 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
2215 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
2216 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
2217 r *= (1.0F / 255.0F);
2218 g *= (1.0F / 255.0F);
2219 b *= (1.0F / 255.0F);
2220 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
2221 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
2222 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
2223 texel[ACOMP] = 1.0F;
2224 }
2225
2226 #if DIM == 3
2227 static void store_texel_ycbcr(struct gl_texture_image *texImage,
2228 GLint i, GLint j, GLint k, const void *texel)
2229 {
2230 (void) texImage;
2231 (void) i;
2232 (void) j;
2233 (void) k;
2234 (void) texel;
2235 /* XXX to do */
2236 }
2237 #endif
2238
2239
2240 /* MESA_FORMAT_YCBCR_REV *****************************************************/
2241
2242 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
2243 * We convert YCbCr to RGB here.
2244 */
2245 static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
2246 GLint i, GLint j, GLint k, GLfloat *texel )
2247 {
2248 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
2249 const GLushort *src1 = src0 + 1; /* odd */
2250 const GLubyte y0 = *src0 & 0xff; /* luminance */
2251 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
2252 const GLubyte y1 = *src1 & 0xff; /* luminance */
2253 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
2254 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
2255 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
2256 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
2257 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
2258 r *= (1.0F / 255.0F);
2259 g *= (1.0F / 255.0F);
2260 b *= (1.0F / 255.0F);
2261 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
2262 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
2263 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
2264 texel[ACOMP] = 1.0F;
2265 }
2266
2267 #if DIM == 3
2268 static void store_texel_ycbcr_rev(struct gl_texture_image *texImage,
2269 GLint i, GLint j, GLint k, const void *texel)
2270 {
2271 (void) texImage;
2272 (void) i;
2273 (void) j;
2274 (void) k;
2275 (void) texel;
2276 /* XXX to do */
2277 }
2278 #endif
2279
2280
2281 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
2282
2283 static void FETCH(f_z24_s8)( const struct gl_texture_image *texImage,
2284 GLint i, GLint j, GLint k, GLfloat *texel )
2285 {
2286 /* only return Z, not stencil data */
2287 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2288 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
2289 texel[0] = ((*src) >> 8) * scale;
2290 ASSERT(texImage->TexFormat == MESA_FORMAT_Z24_S8 ||
2291 texImage->TexFormat == MESA_FORMAT_Z24_X8);
2292 ASSERT(texel[0] >= 0.0F);
2293 ASSERT(texel[0] <= 1.0F);
2294 }
2295
2296 #if DIM == 3
2297 static void store_texel_z24_s8(struct gl_texture_image *texImage,
2298 GLint i, GLint j, GLint k, const void *texel)
2299 {
2300 /* only store Z, not stencil */
2301 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2302 GLfloat depth = *((GLfloat *) texel);
2303 GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
2304 *dst = zi | (*dst & 0xff);
2305 }
2306 #endif
2307
2308
2309 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
2310
2311 static void FETCH(f_s8_z24)( const struct gl_texture_image *texImage,
2312 GLint i, GLint j, GLint k, GLfloat *texel )
2313 {
2314 /* only return Z, not stencil data */
2315 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2316 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
2317 texel[0] = ((*src) & 0x00ffffff) * scale;
2318 ASSERT(texImage->TexFormat == MESA_FORMAT_S8_Z24 ||
2319 texImage->TexFormat == MESA_FORMAT_X8_Z24);
2320 ASSERT(texel[0] >= 0.0F);
2321 ASSERT(texel[0] <= 1.0F);
2322 }
2323
2324 #if DIM == 3
2325 static void store_texel_s8_z24(struct gl_texture_image *texImage,
2326 GLint i, GLint j, GLint k, const void *texel)
2327 {
2328 /* only store Z, not stencil */
2329 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2330 GLfloat depth = *((GLfloat *) texel);
2331 GLuint zi = (GLuint) (depth * 0xffffff);
2332 *dst = zi | (*dst & 0xff000000);
2333 }
2334 #endif
2335
2336
2337 /* MESA_FORMAT_RGB9_E5 ******************************************************/
2338
2339 static void FETCH(rgb9_e5)( const struct gl_texture_image *texImage,
2340 GLint i, GLint j, GLint k, GLfloat *texel )
2341 {
2342 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2343 rgb9e5_to_float3(*src, texel);
2344 texel[ACOMP] = 1.0F;
2345 }
2346
2347 #if DIM == 3
2348 static void store_texel_rgb9_e5(struct gl_texture_image *texImage,
2349 GLint i, GLint j, GLint k, const void *texel)
2350 {
2351 const GLfloat *src = (const GLfloat *) texel;
2352 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2353 *dst = float3_to_rgb9e5(src);
2354 }
2355 #endif
2356
2357
2358 /* MESA_FORMAT_R11_G11_B10_FLOAT *********************************************/
2359
2360 static void FETCH(r11_g11_b10f)( const struct gl_texture_image *texImage,
2361 GLint i, GLint j, GLint k, GLfloat *texel )
2362 {
2363 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2364 r11g11b10f_to_float3(*src, texel);
2365 texel[ACOMP] = 1.0F;
2366 }
2367
2368 #if DIM == 3
2369 static void store_texel_r11_g11_b10f(struct gl_texture_image *texImage,
2370 GLint i, GLint j, GLint k, const void *texel)
2371 {
2372 const GLfloat *src = (const GLfloat *) texel;
2373 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2374 *dst = float3_to_r11g11b10f(src);
2375 }
2376 #endif
2377
2378
2379 /* MESA_FORMAT_Z32_FLOAT_X24S8 ***********************************************/
2380
2381 static void FETCH(z32f_x24s8)(const struct gl_texture_image *texImage,
2382 GLint i, GLint j, GLint k, GLfloat *texel)
2383 {
2384 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
2385 texel[RCOMP] = src[0];
2386 texel[GCOMP] = 0.0F;
2387 texel[BCOMP] = 0.0F;
2388 texel[ACOMP] = 1.0F;
2389 }
2390
2391 #if DIM == 3
2392 static void store_texel_z32f_x24s8(struct gl_texture_image *texImage,
2393 GLint i, GLint j, GLint k, const void *texel)
2394 {
2395 const GLfloat *src = (const GLfloat *) texel;
2396 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
2397 dst[0] = src[0];
2398 }
2399 #endif
2400
2401
2402 #undef TEXEL_ADDR
2403 #undef DIM
2404 #undef FETCH