b6ffdd09f946e1cdef39bff290997048522f2fc8
[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, 1);
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 *depth = (const GLfloat *) texel;
167 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
168 dst[0] = _mesa_float_to_half(*depth);
169 }
170 #endif
171
172 /* MESA_FORMAT_RGB_F32 *******************************************************/
173
174 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
175 * returning 4 GLfloats.
176 */
177 static void FETCH(f_rgb_f32)( const struct gl_texture_image *texImage,
178 GLint i, GLint j, GLint k, GLfloat *texel )
179 {
180 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
181 texel[RCOMP] = src[0];
182 texel[GCOMP] = src[1];
183 texel[BCOMP] = src[2];
184 texel[ACOMP] = 1.0F;
185 }
186
187 #if DIM == 3
188 static void store_texel_rgb_f32(struct gl_texture_image *texImage,
189 GLint i, GLint j, GLint k, const void *texel)
190 {
191 const GLfloat *depth = (const GLfloat *) texel;
192 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
193 dst[0] = *depth;
194 }
195 #endif
196
197
198 /* MESA_FORMAT_RGB_F16 *******************************************************/
199
200 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
201 * returning 4 GLfloats.
202 */
203 static void FETCH(f_rgb_f16)( const struct gl_texture_image *texImage,
204 GLint i, GLint j, GLint k, GLfloat *texel )
205 {
206 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
207 texel[RCOMP] = _mesa_half_to_float(src[0]);
208 texel[GCOMP] = _mesa_half_to_float(src[1]);
209 texel[BCOMP] = _mesa_half_to_float(src[2]);
210 texel[ACOMP] = 1.0F;
211 }
212
213 #if DIM == 3
214 static void store_texel_rgb_f16(struct gl_texture_image *texImage,
215 GLint i, GLint j, GLint k, const void *texel)
216 {
217 const GLfloat *depth = (const GLfloat *) texel;
218 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
219 dst[0] = _mesa_float_to_half(*depth);
220 }
221 #endif
222
223
224 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
225
226 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
227 * returning 4 GLfloats.
228 */
229 static void FETCH(f_alpha_f32)( const struct gl_texture_image *texImage,
230 GLint i, GLint j, GLint k, GLfloat *texel )
231 {
232 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
233 texel[RCOMP] =
234 texel[GCOMP] =
235 texel[BCOMP] = 0.0F;
236 texel[ACOMP] = src[0];
237 }
238
239 #if DIM == 3
240 static void store_texel_alpha_f32(struct gl_texture_image *texImage,
241 GLint i, GLint j, GLint k, const void *texel)
242 {
243 const GLfloat *rgba = (const GLfloat *) texel;
244 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
245 dst[0] = rgba[ACOMP];
246 }
247 #endif
248
249
250 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
251
252 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
253 * returning 4 GLfloats.
254 */
255 static void FETCH(f_alpha_f16)( const struct gl_texture_image *texImage,
256 GLint i, GLint j, GLint k, GLfloat *texel )
257 {
258 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
259 texel[RCOMP] =
260 texel[GCOMP] =
261 texel[BCOMP] = 0.0F;
262 texel[ACOMP] = _mesa_half_to_float(src[0]);
263 }
264
265 #if DIM == 3
266 static void store_texel_alpha_f16(struct gl_texture_image *texImage,
267 GLint i, GLint j, GLint k, const void *texel)
268 {
269 const GLfloat *rgba = (const GLfloat *) texel;
270 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
271 dst[0] = _mesa_float_to_half(rgba[ACOMP]);
272 }
273 #endif
274
275
276 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
277
278 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
279 * returning 4 GLfloats.
280 */
281 static void FETCH(f_luminance_f32)( const struct gl_texture_image *texImage,
282 GLint i, GLint j, GLint k, GLfloat *texel )
283 {
284 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
285 texel[RCOMP] =
286 texel[GCOMP] =
287 texel[BCOMP] = src[0];
288 texel[ACOMP] = 1.0F;
289 }
290
291 #if DIM == 3
292 static void store_texel_luminance_f32(struct gl_texture_image *texImage,
293 GLint i, GLint j, GLint k, const void *texel)
294 {
295 const GLfloat *rgba = (const GLfloat *) texel;
296 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
297 dst[0] = rgba[RCOMP];
298 }
299 #endif
300
301
302 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
303
304 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
305 * returning 4 GLfloats.
306 */
307 static void FETCH(f_luminance_f16)( const struct gl_texture_image *texImage,
308 GLint i, GLint j, GLint k, GLfloat *texel )
309 {
310 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
311 texel[RCOMP] =
312 texel[GCOMP] =
313 texel[BCOMP] = _mesa_half_to_float(src[0]);
314 texel[ACOMP] = 1.0F;
315 }
316
317 #if DIM == 3
318 static void store_texel_luminance_f16(struct gl_texture_image *texImage,
319 GLint i, GLint j, GLint k, const void *texel)
320 {
321 const GLfloat *rgba = (const GLfloat *) texel;
322 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
323 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
324 }
325 #endif
326
327
328 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
329
330 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
331 * returning 4 GLfloats.
332 */
333 static void FETCH(f_luminance_alpha_f32)( const struct gl_texture_image *texImage,
334 GLint i, GLint j, GLint k, GLfloat *texel )
335 {
336 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
337 texel[RCOMP] =
338 texel[GCOMP] =
339 texel[BCOMP] = src[0];
340 texel[ACOMP] = src[1];
341 }
342
343 #if DIM == 3
344 static void store_texel_luminance_alpha_f32(struct gl_texture_image *texImage,
345 GLint i, GLint j, GLint k, const void *texel)
346 {
347 const GLfloat *rgba = (const GLfloat *) texel;
348 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
349 dst[0] = rgba[RCOMP];
350 dst[1] = rgba[ACOMP];
351 }
352 #endif
353
354
355 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
356
357 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
358 * returning 4 GLfloats.
359 */
360 static void FETCH(f_luminance_alpha_f16)( const struct gl_texture_image *texImage,
361 GLint i, GLint j, GLint k, GLfloat *texel )
362 {
363 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
364 texel[RCOMP] =
365 texel[GCOMP] =
366 texel[BCOMP] = _mesa_half_to_float(src[0]);
367 texel[ACOMP] = _mesa_half_to_float(src[1]);
368 }
369
370 #if DIM == 3
371 static void store_texel_luminance_alpha_f16(struct gl_texture_image *texImage,
372 GLint i, GLint j, GLint k, const void *texel)
373 {
374 const GLfloat *rgba = (const GLfloat *) texel;
375 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
376 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
377 dst[1] = _mesa_float_to_half(rgba[ACOMP]);
378 }
379 #endif
380
381
382 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
383
384 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
385 * returning 4 GLfloats.
386 */
387 static void FETCH(f_intensity_f32)( const struct gl_texture_image *texImage,
388 GLint i, GLint j, GLint k, GLfloat *texel )
389 {
390 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
391 texel[RCOMP] =
392 texel[GCOMP] =
393 texel[BCOMP] =
394 texel[ACOMP] = src[0];
395 }
396
397 #if DIM == 3
398 static void store_texel_intensity_f32(struct gl_texture_image *texImage,
399 GLint i, GLint j, GLint k, const void *texel)
400 {
401 const GLfloat *rgba = (const GLfloat *) texel;
402 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
403 dst[0] = rgba[RCOMP];
404 }
405 #endif
406
407
408 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
409
410 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
411 * returning 4 GLfloats.
412 */
413 static void FETCH(f_intensity_f16)( const struct gl_texture_image *texImage,
414 GLint i, GLint j, GLint k, GLfloat *texel )
415 {
416 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
417 texel[RCOMP] =
418 texel[GCOMP] =
419 texel[BCOMP] =
420 texel[ACOMP] = _mesa_half_to_float(src[0]);
421 }
422
423 #if DIM == 3
424 static void store_texel_intensity_f16(struct gl_texture_image *texImage,
425 GLint i, GLint j, GLint k, const void *texel)
426 {
427 const GLfloat *rgba = (const GLfloat *) texel;
428 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
429 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
430 }
431 #endif
432
433
434
435
436 /*
437 * Begin Hardware formats
438 */
439
440 /* MESA_FORMAT_RGBA8888 ******************************************************/
441
442 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
443 static void FETCH(f_rgba8888)( const struct gl_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 >> 24) );
448 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
449 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
450 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
451 }
452
453
454
455 #if DIM == 3
456 static void store_texel_rgba8888(struct gl_texture_image *texImage,
457 GLint i, GLint j, GLint k, const void *texel)
458 {
459 const GLubyte *rgba = (const GLubyte *) texel;
460 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
461 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
462 }
463 #endif
464
465
466 /* MESA_FORMAT_RGBA888_REV ***************************************************/
467
468 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
469 static void FETCH(f_rgba8888_rev)( const struct gl_texture_image *texImage,
470 GLint i, GLint j, GLint k, GLfloat *texel )
471 {
472 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
473 texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
474 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
475 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
476 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
477 }
478
479 #if DIM == 3
480 static void store_texel_rgba8888_rev(struct gl_texture_image *texImage,
481 GLint i, GLint j, GLint k, const void *texel)
482 {
483 const GLubyte *rgba = (const GLubyte *) texel;
484 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
485 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
486 }
487 #endif
488
489
490 /* MESA_FORMAT_ARGB8888 ******************************************************/
491
492 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
493 static void FETCH(f_argb8888)( const struct gl_texture_image *texImage,
494 GLint i, GLint j, GLint k, GLfloat *texel )
495 {
496 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
497 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
498 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
499 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
500 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
501 }
502
503 #if DIM == 3
504 static void store_texel_argb8888(struct gl_texture_image *texImage,
505 GLint i, GLint j, GLint k, const void *texel)
506 {
507 const GLubyte *rgba = (const GLubyte *) texel;
508 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
509 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
510 }
511 #endif
512
513
514 /* MESA_FORMAT_ARGB8888_REV **************************************************/
515
516 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
517 static void FETCH(f_argb8888_rev)( const struct gl_texture_image *texImage,
518 GLint i, GLint j, GLint k, GLfloat *texel )
519 {
520 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
521 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
522 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
523 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
524 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
525 }
526
527 #if DIM == 3
528 static void store_texel_argb8888_rev(struct gl_texture_image *texImage,
529 GLint i, GLint j, GLint k, const void *texel)
530 {
531 const GLubyte *rgba = (const GLubyte *) texel;
532 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
533 *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], rgba[ACOMP]);
534 }
535 #endif
536
537
538 /* MESA_FORMAT_XRGB8888 ******************************************************/
539
540 /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
541 static void FETCH(f_xrgb8888)( const struct gl_texture_image *texImage,
542 GLint i, GLint j, GLint k, GLfloat *texel )
543 {
544 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
545 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
546 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
547 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
548 texel[ACOMP] = 1.0f;
549 }
550
551 #if DIM == 3
552 static void store_texel_xrgb8888(struct gl_texture_image *texImage,
553 GLint i, GLint j, GLint k, const void *texel)
554 {
555 const GLubyte *rgba = (const GLubyte *) texel;
556 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
557 *dst = PACK_COLOR_8888(0xff, rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
558 }
559 #endif
560
561
562 /* MESA_FORMAT_XRGB8888_REV **************************************************/
563
564 /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
565 static void FETCH(f_xrgb8888_rev)( const struct gl_texture_image *texImage,
566 GLint i, GLint j, GLint k, GLfloat *texel )
567 {
568 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
569 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
570 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
571 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
572 texel[ACOMP] = 1.0f;
573 }
574
575 #if DIM == 3
576 static void store_texel_xrgb8888_rev(struct gl_texture_image *texImage,
577 GLint i, GLint j, GLint k, const void *texel)
578 {
579 const GLubyte *rgba = (const GLubyte *) texel;
580 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
581 *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], 0xff);
582 }
583 #endif
584
585
586 /* MESA_FORMAT_RGB888 ********************************************************/
587
588 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
589 static void FETCH(f_rgb888)( const struct gl_texture_image *texImage,
590 GLint i, GLint j, GLint k, GLfloat *texel )
591 {
592 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
593 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
594 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
595 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
596 texel[ACOMP] = 1.0F;
597 }
598
599 #if DIM == 3
600 static void store_texel_rgb888(struct gl_texture_image *texImage,
601 GLint i, GLint j, GLint k, const void *texel)
602 {
603 const GLubyte *rgba = (const GLubyte *) texel;
604 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
605 dst[0] = rgba[BCOMP];
606 dst[1] = rgba[GCOMP];
607 dst[2] = rgba[RCOMP];
608 }
609 #endif
610
611
612 /* MESA_FORMAT_BGR888 ********************************************************/
613
614 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
615 static void FETCH(f_bgr888)( const struct gl_texture_image *texImage,
616 GLint i, GLint j, GLint k, GLfloat *texel )
617 {
618 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
619 texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
620 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
621 texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
622 texel[ACOMP] = 1.0F;
623 }
624
625 #if DIM == 3
626 static void store_texel_bgr888(struct gl_texture_image *texImage,
627 GLint i, GLint j, GLint k, const void *texel)
628 {
629 const GLubyte *rgba = (const GLubyte *) texel;
630 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
631 dst[0] = rgba[RCOMP];
632 dst[1] = rgba[GCOMP];
633 dst[2] = rgba[BCOMP];
634 }
635 #endif
636
637
638 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
639 instead of slow (g << 2) * 255 / 252 (always rounds down) */
640
641 /* MESA_FORMAT_RGB565 ********************************************************/
642
643 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
644 static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
645 GLint i, GLint j, GLint k, GLfloat *texel )
646 {
647 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
648 const GLushort s = *src;
649 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
650 texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
651 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
652 texel[ACOMP] = 1.0F;
653 }
654
655 #if DIM == 3
656 static void store_texel_rgb565(struct gl_texture_image *texImage,
657 GLint i, GLint j, GLint k, const void *texel)
658 {
659 const GLubyte *rgba = (const GLubyte *) texel;
660 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
661 *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
662 }
663 #endif
664
665
666 /* MESA_FORMAT_RGB565_REV ****************************************************/
667
668 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
669 static void FETCH(f_rgb565_rev)( const struct gl_texture_image *texImage,
670 GLint i, GLint j, GLint k, GLfloat *texel )
671 {
672 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
673 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
674 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
675 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
676 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
677 texel[ACOMP] = 1.0F;
678 }
679
680 #if DIM == 3
681 static void store_texel_rgb565_rev(struct gl_texture_image *texImage,
682 GLint i, GLint j, GLint k, const void *texel)
683 {
684 const GLubyte *rgba = (const GLubyte *) texel;
685 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
686 *dst = PACK_COLOR_565(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
687 }
688 #endif
689
690
691 /* MESA_FORMAT_ARGB4444 ******************************************************/
692
693 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
694 static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
695 GLint i, GLint j, GLint k, GLfloat *texel )
696 {
697 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
698 const GLushort s = *src;
699 texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
700 texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
701 texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
702 texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
703 }
704
705 #if DIM == 3
706 static void store_texel_argb4444(struct gl_texture_image *texImage,
707 GLint i, GLint j, GLint k, const void *texel)
708 {
709 const GLubyte *rgba = (const GLubyte *) texel;
710 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
711 *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
712 }
713 #endif
714
715
716 /* MESA_FORMAT_ARGB4444_REV **************************************************/
717
718 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
719 static void FETCH(f_argb4444_rev)( const struct gl_texture_image *texImage,
720 GLint i, GLint j, GLint k, GLfloat *texel )
721 {
722 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
723 texel[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
724 texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
725 texel[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
726 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
727 }
728
729 #if DIM == 3
730 static void store_texel_argb4444_rev(struct gl_texture_image *texImage,
731 GLint i, GLint j, GLint k, const void *texel)
732 {
733 const GLubyte *rgba = (const GLubyte *) texel;
734 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
735 *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
736 }
737 #endif
738
739 /* MESA_FORMAT_RGBA5551 ******************************************************/
740
741 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
742 static void FETCH(f_rgba5551)( const struct gl_texture_image *texImage,
743 GLint i, GLint j, GLint k, GLfloat *texel )
744 {
745 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
746 const GLushort s = *src;
747 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
748 texel[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
749 texel[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
750 texel[ACOMP] = ((s ) & 0x01) * 1.0F;
751 }
752
753 #if DIM == 3
754 static void store_texel_rgba5551(struct gl_texture_image *texImage,
755 GLint i, GLint j, GLint k, const void *texel)
756 {
757 const GLubyte *rgba = (const GLubyte *) texel;
758 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
759 *dst = PACK_COLOR_5551(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
760 }
761 #endif
762
763 /* MESA_FORMAT_ARGB1555 ******************************************************/
764
765 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
766 static void FETCH(f_argb1555)( const struct gl_texture_image *texImage,
767 GLint i, GLint j, GLint k, GLfloat *texel )
768 {
769 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
770 const GLushort s = *src;
771 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
772 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
773 texel[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F);
774 texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
775 }
776
777 #if DIM == 3
778 static void store_texel_argb1555(struct gl_texture_image *texImage,
779 GLint i, GLint j, GLint k, const void *texel)
780 {
781 const GLubyte *rgba = (const GLubyte *) texel;
782 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
783 *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
784 }
785 #endif
786
787
788 /* MESA_FORMAT_ARGB1555_REV **************************************************/
789
790 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
791 static void FETCH(f_argb1555_rev)( const struct gl_texture_image *texImage,
792 GLint i, GLint j, GLint k, GLfloat *texel )
793 {
794 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
795 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
796 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
797 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
798 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
799 texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
800 }
801
802 #if DIM == 3
803 static void store_texel_argb1555_rev(struct gl_texture_image *texImage,
804 GLint i, GLint j, GLint k, const void *texel)
805 {
806 const GLubyte *rgba = (const GLubyte *) texel;
807 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
808 *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
809 }
810 #endif
811
812
813 /* MESA_FORMAT_ARGB2101010 ***************************************************/
814
815 /* Fetch texel from 1D, 2D or 3D argb2101010 texture, return 4 GLchans */
816 static void FETCH(f_argb2101010)( const struct gl_texture_image *texImage,
817 GLint i, GLint j, GLint k, GLfloat *texel )
818 {
819 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
820 const GLuint s = *src;
821 texel[RCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F);
822 texel[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F);
823 texel[BCOMP] = ((s >> 0) & 0x3ff) * (1.0F / 1023.0F);
824 texel[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F);
825 }
826
827 #if DIM == 3
828 static void store_texel_argb2101010(struct gl_texture_image *texImage,
829 GLint i, GLint j, GLint k, const void *texel)
830 {
831 const GLubyte *rgba = (const GLubyte *) texel;
832 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
833 *dst = PACK_COLOR_2101010(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
834 }
835 #endif
836
837
838 /* MESA_FORMAT_RG88 **********************************************************/
839
840 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
841 static void FETCH(f_rg88)( const struct gl_texture_image *texImage,
842 GLint i, GLint j, GLint k, GLfloat *texel )
843 {
844 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
845 texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
846 texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
847 texel[BCOMP] = 0.0;
848 texel[ACOMP] = 1.0;
849 }
850
851 #if DIM == 3
852 static void store_texel_rg88(struct gl_texture_image *texImage,
853 GLint i, GLint j, GLint k, const void *texel)
854 {
855 const GLubyte *rgba = (const GLubyte *) texel;
856 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
857 *dst = PACK_COLOR_88(rgba[RCOMP], rgba[GCOMP]);
858 }
859 #endif
860
861
862 /* MESA_FORMAT_RG88_REV ******************************************************/
863
864 /* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
865 static void FETCH(f_rg88_rev)( const struct gl_texture_image *texImage,
866 GLint i, GLint j, GLint k, GLfloat *texel )
867 {
868 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
869 texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
870 texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
871 texel[BCOMP] = 0.0;
872 texel[ACOMP] = 1.0;
873 }
874
875 #if DIM == 3
876 static void store_texel_rg88_rev(struct gl_texture_image *texImage,
877 GLint i, GLint j, GLint k, const void *texel)
878 {
879 const GLubyte *rgba = (const GLubyte *) texel;
880 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
881 *dst = PACK_COLOR_88(rgba[GCOMP], rgba[RCOMP]);
882 }
883 #endif
884
885
886 /* MESA_FORMAT_AL44 **********************************************************/
887
888 /* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
889 static void FETCH(f_al44)( const struct gl_texture_image *texImage,
890 GLint i, GLint j, GLint k, GLfloat *texel )
891 {
892 const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
893 texel[RCOMP] =
894 texel[GCOMP] =
895 texel[BCOMP] = UBYTE_TO_FLOAT( (s & 0x0f) << 4 );
896 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xf0 );
897 }
898
899 #if DIM == 3
900 static void store_texel_al44(struct gl_texture_image *texImage,
901 GLint i, GLint j, GLint k, const void *texel)
902 {
903 const GLubyte *rgba = (const GLubyte *) texel;
904 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
905 *dst = PACK_COLOR_44(rgba[ACOMP], rgba[RCOMP]);
906 }
907 #endif
908
909
910 /* MESA_FORMAT_AL88 **********************************************************/
911
912 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
913 static void FETCH(f_al88)( const struct gl_texture_image *texImage,
914 GLint i, GLint j, GLint k, GLfloat *texel )
915 {
916 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
917 texel[RCOMP] =
918 texel[GCOMP] =
919 texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
920 texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
921 }
922
923 #if DIM == 3
924 static void store_texel_al88(struct gl_texture_image *texImage,
925 GLint i, GLint j, GLint k, const void *texel)
926 {
927 const GLubyte *rgba = (const GLubyte *) texel;
928 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
929 *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
930 }
931 #endif
932
933
934 /* MESA_FORMAT_R8 ************************************************************/
935
936 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
937 static void FETCH(f_r8)(const struct gl_texture_image *texImage,
938 GLint i, GLint j, GLint k, GLfloat *texel)
939 {
940 const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
941 texel[RCOMP] = UBYTE_TO_FLOAT(s);
942 texel[GCOMP] = 0.0;
943 texel[BCOMP] = 0.0;
944 texel[ACOMP] = 1.0;
945 }
946
947 #if DIM == 3
948 static void store_texel_r8(struct gl_texture_image *texImage,
949 GLint i, GLint j, GLint k, const void *texel)
950 {
951 const GLubyte *rgba = (const GLubyte *) texel;
952 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
953 *dst = rgba[RCOMP];
954 }
955 #endif
956
957
958 /* MESA_FORMAT_R16 ***********************************************************/
959
960 /* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
961 static void FETCH(f_r16)(const struct gl_texture_image *texImage,
962 GLint i, GLint j, GLint k, GLfloat *texel)
963 {
964 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
965 texel[RCOMP] = USHORT_TO_FLOAT(s);
966 texel[GCOMP] = 0.0;
967 texel[BCOMP] = 0.0;
968 texel[ACOMP] = 1.0;
969 }
970
971 #if DIM == 3
972 static void store_texel_r16(struct gl_texture_image *texImage,
973 GLint i, GLint j, GLint k, const void *texel)
974 {
975 const GLushort *rgba = (const GLushort *) texel;
976 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
977 *dst = rgba[RCOMP];
978 }
979 #endif
980
981
982 /* MESA_FORMAT_AL88_REV ******************************************************/
983
984 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
985 static void FETCH(f_al88_rev)( const struct gl_texture_image *texImage,
986 GLint i, GLint j, GLint k, GLfloat *texel )
987 {
988 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
989 texel[RCOMP] =
990 texel[GCOMP] =
991 texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
992 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
993 }
994
995 #if DIM == 3
996 static void store_texel_al88_rev(struct gl_texture_image *texImage,
997 GLint i, GLint j, GLint k, const void *texel)
998 {
999 const GLubyte *rgba = (const GLubyte *) texel;
1000 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1001 *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
1002 }
1003 #endif
1004
1005
1006 /* MESA_FORMAT_RG1616 ********************************************************/
1007
1008 /* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
1009 static void FETCH(f_rg1616)( const struct gl_texture_image *texImage,
1010 GLint i, GLint j, GLint k, GLfloat *texel )
1011 {
1012 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1013 texel[RCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1014 texel[GCOMP] = USHORT_TO_FLOAT( s >> 16 );
1015 texel[BCOMP] = 0.0;
1016 texel[ACOMP] = 1.0;
1017 }
1018
1019 #if DIM == 3
1020 static void store_texel_rg1616(struct gl_texture_image *texImage,
1021 GLint i, GLint j, GLint k, const void *texel)
1022 {
1023 const GLubyte *rgba = (const GLubyte *) texel;
1024 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1025 *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[GCOMP]);
1026 }
1027 #endif
1028
1029
1030 /* MESA_FORMAT_RG1616_REV ****************************************************/
1031
1032 /* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
1033 static void FETCH(f_rg1616_rev)( const struct gl_texture_image *texImage,
1034 GLint i, GLint j, GLint k, GLfloat *texel )
1035 {
1036 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1037 texel[RCOMP] = USHORT_TO_FLOAT( s >> 16 );
1038 texel[GCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1039 texel[BCOMP] = 0.0;
1040 texel[ACOMP] = 1.0;
1041 }
1042
1043 #if DIM == 3
1044 static void store_texel_rg1616_rev(struct gl_texture_image *texImage,
1045 GLint i, GLint j, GLint k, const void *texel)
1046 {
1047 const GLubyte *rgba = (const GLubyte *) texel;
1048 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1049 *dst = PACK_COLOR_1616(rgba[GCOMP], rgba[RCOMP]);
1050 }
1051 #endif
1052
1053
1054 /* MESA_FORMAT_AL1616 ********************************************************/
1055
1056 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
1057 static void FETCH(f_al1616)( const struct gl_texture_image *texImage,
1058 GLint i, GLint j, GLint k, GLfloat *texel )
1059 {
1060 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1061 texel[RCOMP] =
1062 texel[GCOMP] =
1063 texel[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1064 texel[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
1065 }
1066
1067 #if DIM == 3
1068 static void store_texel_al1616(struct gl_texture_image *texImage,
1069 GLint i, GLint j, GLint k, const void *texel)
1070 {
1071 const GLushort *rgba = (const GLushort *) texel;
1072 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1073 *dst = PACK_COLOR_1616(rgba[ACOMP], rgba[RCOMP]);
1074 }
1075 #endif
1076
1077
1078 /* MESA_FORMAT_AL1616_REV ****************************************************/
1079
1080 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
1081 static void FETCH(f_al1616_rev)( const struct gl_texture_image *texImage,
1082 GLint i, GLint j, GLint k, GLfloat *texel )
1083 {
1084 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1085 texel[RCOMP] =
1086 texel[GCOMP] =
1087 texel[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
1088 texel[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
1089 }
1090
1091 #if DIM == 3
1092 static void store_texel_al1616_rev(struct gl_texture_image *texImage,
1093 GLint i, GLint j, GLint k, const void *texel)
1094 {
1095 const GLushort *rgba = (const GLushort *) texel;
1096 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1097 *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[ACOMP]);
1098 }
1099 #endif
1100
1101
1102 /* MESA_FORMAT_RGB332 ********************************************************/
1103
1104 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1105 static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
1106 GLint i, GLint j, GLint k, GLfloat *texel )
1107 {
1108 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1109 const GLubyte s = *src;
1110 texel[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
1111 texel[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
1112 texel[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F);
1113 texel[ACOMP] = 1.0F;
1114 }
1115
1116 #if DIM == 3
1117 static void store_texel_rgb332(struct gl_texture_image *texImage,
1118 GLint i, GLint j, GLint k, const void *texel)
1119 {
1120 const GLubyte *rgba = (const GLubyte *) texel;
1121 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1122 *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1123 }
1124 #endif
1125
1126
1127 /* MESA_FORMAT_A8 ************************************************************/
1128
1129 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1130 static void FETCH(f_a8)( const struct gl_texture_image *texImage,
1131 GLint i, GLint j, GLint k, GLfloat *texel )
1132 {
1133 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1134 texel[RCOMP] =
1135 texel[GCOMP] =
1136 texel[BCOMP] = 0.0F;
1137 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1138 }
1139
1140 #if DIM == 3
1141 static void store_texel_a8(struct gl_texture_image *texImage,
1142 GLint i, GLint j, GLint k, const void *texel)
1143 {
1144 const GLubyte *rgba = (const GLubyte *) texel;
1145 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1146 *dst = rgba[ACOMP];
1147 }
1148 #endif
1149
1150
1151 /* MESA_FORMAT_L8 ************************************************************/
1152
1153 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1154 static void FETCH(f_l8)( const struct gl_texture_image *texImage,
1155 GLint i, GLint j, GLint k, GLfloat *texel )
1156 {
1157 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1158 texel[RCOMP] =
1159 texel[GCOMP] =
1160 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
1161 texel[ACOMP] = 1.0F;
1162 }
1163
1164 #if DIM == 3
1165 static void store_texel_l8(struct gl_texture_image *texImage,
1166 GLint i, GLint j, GLint k, const void *texel)
1167 {
1168 const GLubyte *rgba = (const GLubyte *) texel;
1169 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1170 *dst = rgba[RCOMP];
1171 }
1172 #endif
1173
1174
1175 /* MESA_FORMAT_I8 ************************************************************/
1176
1177 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1178 static void FETCH(f_i8)( const struct gl_texture_image *texImage,
1179 GLint i, GLint j, GLint k, GLfloat *texel )
1180 {
1181 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1182 texel[RCOMP] =
1183 texel[GCOMP] =
1184 texel[BCOMP] =
1185 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1186 }
1187
1188 #if DIM == 3
1189 static void store_texel_i8(struct gl_texture_image *texImage,
1190 GLint i, GLint j, GLint k, const void *texel)
1191 {
1192 const GLubyte *rgba = (const GLubyte *) texel;
1193 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1194 *dst = rgba[RCOMP];
1195 }
1196 #endif
1197
1198
1199 /* MESA_FORMAT_CI8 ***********************************************************/
1200
1201 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1202 * color table, and return 4 GLchans.
1203 */
1204 static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
1205 GLint i, GLint j, GLint k, GLfloat *texel )
1206 {
1207 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1208 const struct gl_color_table *palette;
1209 GLuint index;
1210 GET_CURRENT_CONTEXT(ctx);
1211
1212 if (ctx->Texture.SharedPalette) {
1213 palette = &ctx->Texture.Palette;
1214 }
1215 else {
1216 palette = &texImage->TexObject->Palette;
1217 }
1218 if (palette->Size == 0)
1219 return; /* undefined results */
1220
1221 /* Mask the index against size of palette to avoid going out of bounds */
1222 index = (*src) & (palette->Size - 1);
1223
1224 {
1225 const GLfloat *table = palette->TableF;
1226 switch (palette->_BaseFormat) {
1227 case GL_ALPHA:
1228 texel[RCOMP] =
1229 texel[GCOMP] =
1230 texel[BCOMP] = 0.0F;
1231 texel[ACOMP] = table[index];
1232 break;
1233 case GL_LUMINANCE:
1234 texel[RCOMP] =
1235 texel[GCOMP] =
1236 texel[BCOMP] = table[index];
1237 texel[ACOMP] = 1.0F;
1238 break;
1239 case GL_INTENSITY:
1240 texel[RCOMP] =
1241 texel[GCOMP] =
1242 texel[BCOMP] =
1243 texel[ACOMP] = table[index];
1244 break;
1245 case GL_LUMINANCE_ALPHA:
1246 texel[RCOMP] =
1247 texel[GCOMP] =
1248 texel[BCOMP] = table[index * 2 + 0];
1249 texel[ACOMP] = table[index * 2 + 1];
1250 break;
1251 case GL_RGB:
1252 texel[RCOMP] = table[index * 3 + 0];
1253 texel[GCOMP] = table[index * 3 + 1];
1254 texel[BCOMP] = table[index * 3 + 2];
1255 texel[ACOMP] = 1.0F;
1256 break;
1257 case GL_RGBA:
1258 texel[RCOMP] = table[index * 4 + 0];
1259 texel[GCOMP] = table[index * 4 + 1];
1260 texel[BCOMP] = table[index * 4 + 2];
1261 texel[ACOMP] = table[index * 4 + 3];
1262 break;
1263 default:
1264 _mesa_problem(ctx, "Bad palette format in fetch_texel_ci8");
1265 return;
1266 }
1267 }
1268 }
1269
1270 #if DIM == 3
1271 static void store_texel_ci8(struct gl_texture_image *texImage,
1272 GLint i, GLint j, GLint k, const void *texel)
1273 {
1274 const GLubyte *index = (const GLubyte *) texel;
1275 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1276 *dst = *index;
1277 }
1278 #endif
1279
1280
1281 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1282 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1283 static void FETCH(srgb8)(const struct gl_texture_image *texImage,
1284 GLint i, GLint j, GLint k, GLfloat *texel )
1285 {
1286 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1287 texel[RCOMP] = nonlinear_to_linear(src[2]);
1288 texel[GCOMP] = nonlinear_to_linear(src[1]);
1289 texel[BCOMP] = nonlinear_to_linear(src[0]);
1290 texel[ACOMP] = 1.0F;
1291 }
1292
1293 #if DIM == 3
1294 static void store_texel_srgb8(struct gl_texture_image *texImage,
1295 GLint i, GLint j, GLint k, const void *texel)
1296 {
1297 const GLubyte *rgba = (const GLubyte *) texel;
1298 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1299 dst[0] = rgba[BCOMP]; /* no conversion */
1300 dst[1] = rgba[GCOMP];
1301 dst[2] = rgba[RCOMP];
1302 }
1303 #endif
1304
1305 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1306 static void FETCH(srgba8)(const struct gl_texture_image *texImage,
1307 GLint i, GLint j, GLint k, GLfloat *texel )
1308 {
1309 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1310 texel[RCOMP] = nonlinear_to_linear( (s >> 24) );
1311 texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1312 texel[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1313 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */
1314 }
1315
1316 #if DIM == 3
1317 static void store_texel_srgba8(struct gl_texture_image *texImage,
1318 GLint i, GLint j, GLint k, const void *texel)
1319 {
1320 const GLubyte *rgba = (const GLubyte *) texel;
1321 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1322 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1323 }
1324 #endif
1325
1326 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1327 static void FETCH(sargb8)(const struct gl_texture_image *texImage,
1328 GLint i, GLint j, GLint k, GLfloat *texel )
1329 {
1330 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1331 texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1332 texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1333 texel[BCOMP] = nonlinear_to_linear( (s ) & 0xff );
1334 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
1335 }
1336
1337 #if DIM == 3
1338 static void store_texel_sargb8(struct gl_texture_image *texImage,
1339 GLint i, GLint j, GLint k, const void *texel)
1340 {
1341 const GLubyte *rgba = (const GLubyte *) texel;
1342 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1343 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1344 }
1345 #endif
1346
1347 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1348 static void FETCH(sl8)(const struct gl_texture_image *texImage,
1349 GLint i, GLint j, GLint k, GLfloat *texel )
1350 {
1351 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1352 texel[RCOMP] =
1353 texel[GCOMP] =
1354 texel[BCOMP] = nonlinear_to_linear(src[0]);
1355 texel[ACOMP] = 1.0F;
1356 }
1357
1358 #if DIM == 3
1359 static void store_texel_sl8(struct gl_texture_image *texImage,
1360 GLint i, GLint j, GLint k, const void *texel)
1361 {
1362 const GLubyte *rgba = (const GLubyte *) texel;
1363 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1364 dst[0] = rgba[RCOMP];
1365 }
1366 #endif
1367
1368 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1369 static void FETCH(sla8)(const struct gl_texture_image *texImage,
1370 GLint i, GLint j, GLint k, GLfloat *texel )
1371 {
1372 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1373 texel[RCOMP] =
1374 texel[GCOMP] =
1375 texel[BCOMP] = nonlinear_to_linear(src[0]);
1376 texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
1377 }
1378
1379 #if DIM == 3
1380 static void store_texel_sla8(struct gl_texture_image *texImage,
1381 GLint i, GLint j, GLint k, const void *texel)
1382 {
1383 const GLubyte *rgba = (const GLubyte *) texel;
1384 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1385 dst[0] = rgba[RCOMP];
1386 dst[1] = rgba[ACOMP];
1387 }
1388 #endif
1389
1390
1391 /* MESA_FORMAT_RGBA_INT8 **************************************************/
1392
1393 static void
1394 FETCH(rgba_int8)(const struct gl_texture_image *texImage,
1395 GLint i, GLint j, GLint k, GLfloat *texel )
1396 {
1397 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
1398 texel[RCOMP] = (GLfloat) src[0];
1399 texel[GCOMP] = (GLfloat) src[1];
1400 texel[BCOMP] = (GLfloat) src[2];
1401 texel[ACOMP] = (GLfloat) src[3];
1402 }
1403
1404 #if DIM == 3
1405 static void
1406 store_texel_rgba_int8(struct gl_texture_image *texImage,
1407 GLint i, GLint j, GLint k, const void *texel)
1408 {
1409 const GLbyte *rgba = (const GLbyte *) texel;
1410 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
1411 dst[0] = rgba[RCOMP];
1412 dst[1] = rgba[GCOMP];
1413 dst[2] = rgba[BCOMP];
1414 dst[3] = rgba[ACOMP];
1415 }
1416 #endif
1417
1418
1419 /* MESA_FORMAT_RGBA_INT16 **************************************************/
1420
1421 static void
1422 FETCH(rgba_int16)(const struct gl_texture_image *texImage,
1423 GLint i, GLint j, GLint k, GLfloat *texel )
1424 {
1425 const GLshort *src = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1426 texel[RCOMP] = (GLfloat) src[0];
1427 texel[GCOMP] = (GLfloat) src[1];
1428 texel[BCOMP] = (GLfloat) src[2];
1429 texel[ACOMP] = (GLfloat) src[3];
1430 }
1431
1432 #if DIM == 3
1433 static void
1434 store_texel_rgba_int16(struct gl_texture_image *texImage,
1435 GLint i, GLint j, GLint k, const void *texel)
1436 {
1437 const GLshort *rgba = (const GLshort *) texel;
1438 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1439 dst[0] = rgba[RCOMP];
1440 dst[1] = rgba[GCOMP];
1441 dst[2] = rgba[BCOMP];
1442 dst[3] = rgba[ACOMP];
1443 }
1444 #endif
1445
1446
1447 /* MESA_FORMAT_RGBA_INT32 **************************************************/
1448
1449 static void
1450 FETCH(rgba_int32)(const struct gl_texture_image *texImage,
1451 GLint i, GLint j, GLint k, GLfloat *texel )
1452 {
1453 const GLint *src = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
1454 texel[RCOMP] = (GLfloat) src[0];
1455 texel[GCOMP] = (GLfloat) src[1];
1456 texel[BCOMP] = (GLfloat) src[2];
1457 texel[ACOMP] = (GLfloat) src[3];
1458 }
1459
1460 #if DIM == 3
1461 static void
1462 store_texel_rgba_int32(struct gl_texture_image *texImage,
1463 GLint i, GLint j, GLint k, const void *texel)
1464 {
1465 const GLint *rgba = (const GLint *) texel;
1466 GLint *dst = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
1467 dst[0] = rgba[RCOMP];
1468 dst[1] = rgba[GCOMP];
1469 dst[2] = rgba[BCOMP];
1470 dst[3] = rgba[ACOMP];
1471 }
1472 #endif
1473
1474
1475 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
1476
1477 static void
1478 FETCH(rgba_uint8)(const struct gl_texture_image *texImage,
1479 GLint i, GLint j, GLint k, GLfloat *texel )
1480 {
1481 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1482 texel[RCOMP] = (GLfloat) src[0];
1483 texel[GCOMP] = (GLfloat) src[1];
1484 texel[BCOMP] = (GLfloat) src[2];
1485 texel[ACOMP] = (GLfloat) src[3];
1486 }
1487
1488 #if DIM == 3
1489 static void
1490 store_texel_rgba_uint8(struct gl_texture_image *texImage,
1491 GLint i, GLint j, GLint k, const void *texel)
1492 {
1493 const GLubyte *rgba = (const GLubyte *) texel;
1494 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1495 dst[0] = rgba[RCOMP];
1496 dst[1] = rgba[GCOMP];
1497 dst[2] = rgba[BCOMP];
1498 dst[3] = rgba[ACOMP];
1499 }
1500 #endif
1501
1502
1503 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
1504
1505 static void
1506 FETCH(rgba_uint16)(const struct gl_texture_image *texImage,
1507 GLint i, GLint j, GLint k, GLfloat *texel )
1508 {
1509 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1510 texel[RCOMP] = (GLfloat) src[0];
1511 texel[GCOMP] = (GLfloat) src[1];
1512 texel[BCOMP] = (GLfloat) src[2];
1513 texel[ACOMP] = (GLfloat) src[3];
1514 }
1515
1516 #if DIM == 3
1517 static void
1518 store_texel_rgba_uint16(struct gl_texture_image *texImage,
1519 GLint i, GLint j, GLint k, const void *texel)
1520 {
1521 const GLushort *rgba = (const GLushort *) texel;
1522 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1523 dst[0] = rgba[RCOMP];
1524 dst[1] = rgba[GCOMP];
1525 dst[2] = rgba[BCOMP];
1526 dst[3] = rgba[ACOMP];
1527 }
1528 #endif
1529
1530
1531 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
1532
1533 static void
1534 FETCH(rgba_uint32)(const struct gl_texture_image *texImage,
1535 GLint i, GLint j, GLint k, GLfloat *texel )
1536 {
1537 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
1538 texel[RCOMP] = (GLfloat) src[0];
1539 texel[GCOMP] = (GLfloat) src[1];
1540 texel[BCOMP] = (GLfloat) src[2];
1541 texel[ACOMP] = (GLfloat) src[3];
1542 }
1543
1544 #if DIM == 3
1545 static void
1546 store_texel_rgba_uint32(struct gl_texture_image *texImage,
1547 GLint i, GLint j, GLint k, const void *texel)
1548 {
1549 const GLuint *rgba = (const GLuint *) texel;
1550 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
1551 dst[0] = rgba[RCOMP];
1552 dst[1] = rgba[GCOMP];
1553 dst[2] = rgba[BCOMP];
1554 dst[3] = rgba[ACOMP];
1555 }
1556 #endif
1557
1558
1559 /* MESA_FORMAT_DUDV8 ********************************************************/
1560
1561 /* this format by definition produces 0,0,0,1 as rgba values,
1562 however we'll return the dudv values as rg and fix up elsewhere */
1563 static void FETCH(dudv8)(const struct gl_texture_image *texImage,
1564 GLint i, GLint j, GLint k, GLfloat *texel )
1565 {
1566 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 2);
1567 texel[RCOMP] = BYTE_TO_FLOAT(src[0]);
1568 texel[GCOMP] = BYTE_TO_FLOAT(src[1]);
1569 texel[BCOMP] = 0;
1570 texel[ACOMP] = 0;
1571 }
1572
1573
1574 /* MESA_FORMAT_SIGNED_R8 ***********************************************/
1575
1576 static void FETCH(signed_r8)( const struct gl_texture_image *texImage,
1577 GLint i, GLint j, GLint k, GLfloat *texel )
1578 {
1579 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1580 texel[RCOMP] = BYTE_TO_FLOAT_TEX( s );
1581 texel[GCOMP] = 0.0F;
1582 texel[BCOMP] = 0.0F;
1583 texel[ACOMP] = 1.0F;
1584 }
1585
1586 #if DIM == 3
1587 static void store_texel_signed_r8(struct gl_texture_image *texImage,
1588 GLint i, GLint j, GLint k, const void *texel)
1589 {
1590 const GLbyte *rgba = (const GLbyte *) texel;
1591 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1592 *dst = rgba[RCOMP];
1593 }
1594 #endif
1595
1596
1597 /* MESA_FORMAT_SIGNED_RG88 ***********************************************/
1598
1599 static void FETCH(signed_rg88)( const struct gl_texture_image *texImage,
1600 GLint i, GLint j, GLint k, GLfloat *texel )
1601 {
1602 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1603 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1604 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
1605 texel[BCOMP] = 0.0F;
1606 texel[ACOMP] = 1.0F;
1607 }
1608
1609 #if DIM == 3
1610 static void store_texel_signed_rg88(struct gl_texture_image *texImage,
1611 GLint i, GLint j, GLint k, const void *texel)
1612 {
1613 const GLbyte *rg = (const GLbyte *) texel;
1614 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 2);
1615 *dst = PACK_COLOR_88(rg[RCOMP], rg[GCOMP]);
1616 }
1617 #endif
1618
1619
1620 /* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
1621
1622 static void FETCH(signed_rgbx8888)( const struct gl_texture_image *texImage,
1623 GLint i, GLint j, GLint k, GLfloat *texel )
1624 {
1625 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1626 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1627 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1628 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1629 texel[ACOMP] = 1.0f;
1630 }
1631
1632 #if DIM == 3
1633 static void store_texel_signed_rgbx8888(struct gl_texture_image *texImage,
1634 GLint i, GLint j, GLint k, const void *texel)
1635 {
1636 const GLbyte *rgba = (const GLbyte *) texel;
1637 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1638 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 255);
1639 }
1640 #endif
1641
1642
1643 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1644
1645 static void FETCH(signed_rgba8888)( const struct gl_texture_image *texImage,
1646 GLint i, GLint j, GLint k, GLfloat *texel )
1647 {
1648 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1649 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1650 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1651 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1652 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1653 }
1654
1655 #if DIM == 3
1656 static void store_texel_signed_rgba8888(struct gl_texture_image *texImage,
1657 GLint i, GLint j, GLint k, const void *texel)
1658 {
1659 const GLbyte *rgba = (const GLbyte *) texel;
1660 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1661 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1662 }
1663 #endif
1664
1665 static void FETCH(signed_rgba8888_rev)( const struct gl_texture_image *texImage,
1666 GLint i, GLint j, GLint k, GLfloat *texel )
1667 {
1668 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1669 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1670 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1671 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1672 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1673 }
1674
1675 #if DIM == 3
1676 static void store_texel_signed_rgba8888_rev(struct gl_texture_image *texImage,
1677 GLint i, GLint j, GLint k, const void *texel)
1678 {
1679 const GLubyte *rgba = (const GLubyte *) texel;
1680 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1681 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1682 }
1683 #endif
1684
1685
1686
1687 /* MESA_FORMAT_SIGNED_R_16 ***********************************************/
1688
1689 static void
1690 FETCH(signed_r_16)(const struct gl_texture_image *texImage,
1691 GLint i, GLint j, GLint k, GLfloat *texel)
1692 {
1693 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1694 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s );
1695 texel[GCOMP] = 0.0F;
1696 texel[BCOMP] = 0.0F;
1697 texel[ACOMP] = 1.0F;
1698 }
1699
1700 #if DIM == 3
1701 static void
1702 store_texel_signed_r_16(struct gl_texture_image *texImage,
1703 GLint i, GLint j, GLint k, const void *texel)
1704 {
1705 const GLshort *rgba = (const GLshort *) texel;
1706 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1707 *dst = rgba[0];
1708 }
1709 #endif
1710
1711
1712 /* MESA_FORMAT_SIGNED_RG_16 ***********************************************/
1713
1714 static void
1715 FETCH(signed_rg_16)(const struct gl_texture_image *texImage,
1716 GLint i, GLint j, GLint k, GLfloat *texel)
1717 {
1718 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
1719 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1720 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1721 texel[BCOMP] = 0.0F;
1722 texel[ACOMP] = 1.0F;
1723 }
1724
1725 #if DIM == 3
1726 static void
1727 store_texel_signed_rg_16(struct gl_texture_image *texImage,
1728 GLint i, GLint j, GLint k, const void *texel)
1729 {
1730 const GLshort *rgba = (const GLshort *) texel;
1731 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
1732 dst[0] = rgba[RCOMP];
1733 dst[1] = rgba[GCOMP];
1734 }
1735 #endif
1736
1737
1738 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
1739
1740 static void
1741 FETCH(signed_rgb_16)(const struct gl_texture_image *texImage,
1742 GLint i, GLint j, GLint k, GLfloat *texel)
1743 {
1744 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
1745 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1746 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1747 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
1748 texel[ACOMP] = 1.0F;
1749 }
1750
1751 #if DIM == 3
1752 static void
1753 store_texel_signed_rgb_16(struct gl_texture_image *texImage,
1754 GLint i, GLint j, GLint k, const void *texel)
1755 {
1756 const GLshort *rgba = (const GLshort *) texel;
1757 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
1758 dst[0] = rgba[RCOMP];
1759 dst[1] = rgba[GCOMP];
1760 dst[2] = rgba[BCOMP];
1761 }
1762 #endif
1763
1764
1765 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
1766
1767 static void
1768 FETCH(signed_rgba_16)(const struct gl_texture_image *texImage,
1769 GLint i, GLint j, GLint k, GLfloat *texel)
1770 {
1771 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1772 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1773 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1774 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
1775 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
1776 }
1777
1778 #if DIM == 3
1779 static void
1780 store_texel_signed_rgba_16(struct gl_texture_image *texImage,
1781 GLint i, GLint j, GLint k, const void *texel)
1782 {
1783 const GLshort *rgba = (const GLshort *) texel;
1784 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1785 dst[0] = rgba[RCOMP];
1786 dst[1] = rgba[GCOMP];
1787 dst[2] = rgba[BCOMP];
1788 dst[3] = rgba[ACOMP];
1789 }
1790 #endif
1791
1792
1793
1794 /* MESA_FORMAT_RGBA_16 ***********************************************/
1795
1796 static void
1797 FETCH(rgba_16)(const struct gl_texture_image *texImage,
1798 GLint i, GLint j, GLint k, GLfloat *texel)
1799 {
1800 const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1801 texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
1802 texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
1803 texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
1804 texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
1805 }
1806
1807 #if DIM == 3
1808 static void
1809 store_texel_rgba_16(struct gl_texture_image *texImage,
1810 GLint i, GLint j, GLint k, const void *texel)
1811 {
1812 const GLushort *rgba = (const GLushort *) texel;
1813 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1814 dst[0] = rgba[RCOMP];
1815 dst[1] = rgba[GCOMP];
1816 dst[2] = rgba[BCOMP];
1817 dst[3] = rgba[ACOMP];
1818 }
1819 #endif
1820
1821
1822
1823 /* MESA_FORMAT_YCBCR *********************************************************/
1824
1825 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
1826 * We convert YCbCr to RGB here.
1827 */
1828 static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
1829 GLint i, GLint j, GLint k, GLfloat *texel )
1830 {
1831 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1832 const GLushort *src1 = src0 + 1; /* odd */
1833 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1834 const GLubyte cb = *src0 & 0xff; /* chroma U */
1835 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1836 const GLubyte cr = *src1 & 0xff; /* chroma V */
1837 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1838 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1839 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1840 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1841 r *= (1.0F / 255.0F);
1842 g *= (1.0F / 255.0F);
1843 b *= (1.0F / 255.0F);
1844 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1845 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1846 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1847 texel[ACOMP] = 1.0F;
1848 }
1849
1850 #if DIM == 3
1851 static void store_texel_ycbcr(struct gl_texture_image *texImage,
1852 GLint i, GLint j, GLint k, const void *texel)
1853 {
1854 (void) texImage;
1855 (void) i;
1856 (void) j;
1857 (void) k;
1858 (void) texel;
1859 /* XXX to do */
1860 }
1861 #endif
1862
1863
1864 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1865
1866 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
1867 * We convert YCbCr to RGB here.
1868 */
1869 static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
1870 GLint i, GLint j, GLint k, GLfloat *texel )
1871 {
1872 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1873 const GLushort *src1 = src0 + 1; /* odd */
1874 const GLubyte y0 = *src0 & 0xff; /* luminance */
1875 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1876 const GLubyte y1 = *src1 & 0xff; /* luminance */
1877 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1878 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1879 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1880 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1881 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1882 r *= (1.0F / 255.0F);
1883 g *= (1.0F / 255.0F);
1884 b *= (1.0F / 255.0F);
1885 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1886 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1887 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1888 texel[ACOMP] = 1.0F;
1889 }
1890
1891 #if DIM == 3
1892 static void store_texel_ycbcr_rev(struct gl_texture_image *texImage,
1893 GLint i, GLint j, GLint k, const void *texel)
1894 {
1895 (void) texImage;
1896 (void) i;
1897 (void) j;
1898 (void) k;
1899 (void) texel;
1900 /* XXX to do */
1901 }
1902 #endif
1903
1904
1905 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1906
1907 static void FETCH(f_z24_s8)( const struct gl_texture_image *texImage,
1908 GLint i, GLint j, GLint k, GLfloat *texel )
1909 {
1910 /* only return Z, not stencil data */
1911 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1912 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1913 texel[0] = ((*src) >> 8) * scale;
1914 ASSERT(texImage->TexFormat == MESA_FORMAT_Z24_S8);
1915 ASSERT(texel[0] >= 0.0F);
1916 ASSERT(texel[0] <= 1.0F);
1917 }
1918
1919 #if DIM == 3
1920 static void store_texel_z24_s8(struct gl_texture_image *texImage,
1921 GLint i, GLint j, GLint k, const void *texel)
1922 {
1923 /* only store Z, not stencil */
1924 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1925 GLfloat depth = *((GLfloat *) texel);
1926 GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
1927 *dst = zi | (*dst & 0xff);
1928 }
1929 #endif
1930
1931
1932 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1933
1934 static void FETCH(f_s8_z24)( const struct gl_texture_image *texImage,
1935 GLint i, GLint j, GLint k, GLfloat *texel )
1936 {
1937 /* only return Z, not stencil data */
1938 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1939 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1940 texel[0] = ((*src) & 0x00ffffff) * scale;
1941 ASSERT(texImage->TexFormat == MESA_FORMAT_S8_Z24);
1942 ASSERT(texel[0] >= 0.0F);
1943 ASSERT(texel[0] <= 1.0F);
1944 }
1945
1946 #if DIM == 3
1947 static void store_texel_s8_z24(struct gl_texture_image *texImage,
1948 GLint i, GLint j, GLint k, const void *texel)
1949 {
1950 /* only store Z, not stencil */
1951 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1952 GLfloat depth = *((GLfloat *) texel);
1953 GLuint zi = (GLuint) (depth * 0xffffff);
1954 *dst = zi | (*dst & 0xff000000);
1955 }
1956 #endif
1957
1958
1959 #undef TEXEL_ADDR
1960 #undef DIM
1961 #undef FETCH