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