3a75cdcefe95169e881466e94b610ee77c409d12
[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_A16 ************************************************************/
1152
1153 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1154 static void FETCH(f_a16)( const struct gl_texture_image *texImage,
1155 GLint i, GLint j, GLint k, GLfloat *texel )
1156 {
1157 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1158 texel[RCOMP] =
1159 texel[GCOMP] =
1160 texel[BCOMP] = 0.0F;
1161 texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
1162 }
1163
1164 #if DIM == 3
1165 static void store_texel_a16(struct gl_texture_image *texImage,
1166 GLint i, GLint j, GLint k, const void *texel)
1167 {
1168 const GLushort *rgba = (const GLushort *) texel;
1169 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1170 *dst = rgba[ACOMP];
1171 }
1172 #endif
1173
1174
1175 /* MESA_FORMAT_L8 ************************************************************/
1176
1177 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1178 static void FETCH(f_l8)( 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] = UBYTE_TO_FLOAT( src[0] );
1185 texel[ACOMP] = 1.0F;
1186 }
1187
1188 #if DIM == 3
1189 static void store_texel_l8(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_I8 ************************************************************/
1200
1201 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1202 static void FETCH(f_i8)( const struct gl_texture_image *texImage,
1203 GLint i, GLint j, GLint k, GLfloat *texel )
1204 {
1205 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1206 texel[RCOMP] =
1207 texel[GCOMP] =
1208 texel[BCOMP] =
1209 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1210 }
1211
1212 #if DIM == 3
1213 static void store_texel_i8(struct gl_texture_image *texImage,
1214 GLint i, GLint j, GLint k, const void *texel)
1215 {
1216 const GLubyte *rgba = (const GLubyte *) texel;
1217 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1218 *dst = rgba[RCOMP];
1219 }
1220 #endif
1221
1222
1223 /* MESA_FORMAT_CI8 ***********************************************************/
1224
1225 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1226 * color table, and return 4 GLchans.
1227 */
1228 static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
1229 GLint i, GLint j, GLint k, GLfloat *texel )
1230 {
1231 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1232 const struct gl_color_table *palette;
1233 GLuint index;
1234 GET_CURRENT_CONTEXT(ctx);
1235
1236 if (ctx->Texture.SharedPalette) {
1237 palette = &ctx->Texture.Palette;
1238 }
1239 else {
1240 palette = &texImage->TexObject->Palette;
1241 }
1242 if (palette->Size == 0)
1243 return; /* undefined results */
1244
1245 /* Mask the index against size of palette to avoid going out of bounds */
1246 index = (*src) & (palette->Size - 1);
1247
1248 {
1249 const GLfloat *table = palette->TableF;
1250 switch (palette->_BaseFormat) {
1251 case GL_ALPHA:
1252 texel[RCOMP] =
1253 texel[GCOMP] =
1254 texel[BCOMP] = 0.0F;
1255 texel[ACOMP] = table[index];
1256 break;
1257 case GL_LUMINANCE:
1258 texel[RCOMP] =
1259 texel[GCOMP] =
1260 texel[BCOMP] = table[index];
1261 texel[ACOMP] = 1.0F;
1262 break;
1263 case GL_INTENSITY:
1264 texel[RCOMP] =
1265 texel[GCOMP] =
1266 texel[BCOMP] =
1267 texel[ACOMP] = table[index];
1268 break;
1269 case GL_LUMINANCE_ALPHA:
1270 texel[RCOMP] =
1271 texel[GCOMP] =
1272 texel[BCOMP] = table[index * 2 + 0];
1273 texel[ACOMP] = table[index * 2 + 1];
1274 break;
1275 case GL_RGB:
1276 texel[RCOMP] = table[index * 3 + 0];
1277 texel[GCOMP] = table[index * 3 + 1];
1278 texel[BCOMP] = table[index * 3 + 2];
1279 texel[ACOMP] = 1.0F;
1280 break;
1281 case GL_RGBA:
1282 texel[RCOMP] = table[index * 4 + 0];
1283 texel[GCOMP] = table[index * 4 + 1];
1284 texel[BCOMP] = table[index * 4 + 2];
1285 texel[ACOMP] = table[index * 4 + 3];
1286 break;
1287 default:
1288 _mesa_problem(ctx, "Bad palette format in fetch_texel_ci8");
1289 return;
1290 }
1291 }
1292 }
1293
1294 #if DIM == 3
1295 static void store_texel_ci8(struct gl_texture_image *texImage,
1296 GLint i, GLint j, GLint k, const void *texel)
1297 {
1298 const GLubyte *index = (const GLubyte *) texel;
1299 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1300 *dst = *index;
1301 }
1302 #endif
1303
1304
1305 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1306 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1307 static void FETCH(srgb8)(const struct gl_texture_image *texImage,
1308 GLint i, GLint j, GLint k, GLfloat *texel )
1309 {
1310 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1311 texel[RCOMP] = nonlinear_to_linear(src[2]);
1312 texel[GCOMP] = nonlinear_to_linear(src[1]);
1313 texel[BCOMP] = nonlinear_to_linear(src[0]);
1314 texel[ACOMP] = 1.0F;
1315 }
1316
1317 #if DIM == 3
1318 static void store_texel_srgb8(struct gl_texture_image *texImage,
1319 GLint i, GLint j, GLint k, const void *texel)
1320 {
1321 const GLubyte *rgba = (const GLubyte *) texel;
1322 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1323 dst[0] = rgba[BCOMP]; /* no conversion */
1324 dst[1] = rgba[GCOMP];
1325 dst[2] = rgba[RCOMP];
1326 }
1327 #endif
1328
1329 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1330 static void FETCH(srgba8)(const struct gl_texture_image *texImage,
1331 GLint i, GLint j, GLint k, GLfloat *texel )
1332 {
1333 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1334 texel[RCOMP] = nonlinear_to_linear( (s >> 24) );
1335 texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1336 texel[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1337 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */
1338 }
1339
1340 #if DIM == 3
1341 static void store_texel_srgba8(struct gl_texture_image *texImage,
1342 GLint i, GLint j, GLint k, const void *texel)
1343 {
1344 const GLubyte *rgba = (const GLubyte *) texel;
1345 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1346 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1347 }
1348 #endif
1349
1350 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1351 static void FETCH(sargb8)(const struct gl_texture_image *texImage,
1352 GLint i, GLint j, GLint k, GLfloat *texel )
1353 {
1354 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1355 texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1356 texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1357 texel[BCOMP] = nonlinear_to_linear( (s ) & 0xff );
1358 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
1359 }
1360
1361 #if DIM == 3
1362 static void store_texel_sargb8(struct gl_texture_image *texImage,
1363 GLint i, GLint j, GLint k, const void *texel)
1364 {
1365 const GLubyte *rgba = (const GLubyte *) texel;
1366 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1367 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1368 }
1369 #endif
1370
1371 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1372 static void FETCH(sl8)(const struct gl_texture_image *texImage,
1373 GLint i, GLint j, GLint k, GLfloat *texel )
1374 {
1375 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1376 texel[RCOMP] =
1377 texel[GCOMP] =
1378 texel[BCOMP] = nonlinear_to_linear(src[0]);
1379 texel[ACOMP] = 1.0F;
1380 }
1381
1382 #if DIM == 3
1383 static void store_texel_sl8(struct gl_texture_image *texImage,
1384 GLint i, GLint j, GLint k, const void *texel)
1385 {
1386 const GLubyte *rgba = (const GLubyte *) texel;
1387 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1388 dst[0] = rgba[RCOMP];
1389 }
1390 #endif
1391
1392 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1393 static void FETCH(sla8)(const struct gl_texture_image *texImage,
1394 GLint i, GLint j, GLint k, GLfloat *texel )
1395 {
1396 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1397 texel[RCOMP] =
1398 texel[GCOMP] =
1399 texel[BCOMP] = nonlinear_to_linear(src[0]);
1400 texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
1401 }
1402
1403 #if DIM == 3
1404 static void store_texel_sla8(struct gl_texture_image *texImage,
1405 GLint i, GLint j, GLint k, const void *texel)
1406 {
1407 const GLubyte *rgba = (const GLubyte *) texel;
1408 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1409 dst[0] = rgba[RCOMP];
1410 dst[1] = rgba[ACOMP];
1411 }
1412 #endif
1413
1414
1415 /* MESA_FORMAT_RGBA_INT8 **************************************************/
1416
1417 static void
1418 FETCH(rgba_int8)(const struct gl_texture_image *texImage,
1419 GLint i, GLint j, GLint k, GLfloat *texel )
1420 {
1421 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
1422 texel[RCOMP] = (GLfloat) src[0];
1423 texel[GCOMP] = (GLfloat) src[1];
1424 texel[BCOMP] = (GLfloat) src[2];
1425 texel[ACOMP] = (GLfloat) src[3];
1426 }
1427
1428 #if DIM == 3
1429 static void
1430 store_texel_rgba_int8(struct gl_texture_image *texImage,
1431 GLint i, GLint j, GLint k, const void *texel)
1432 {
1433 const GLbyte *rgba = (const GLbyte *) texel;
1434 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
1435 dst[0] = rgba[RCOMP];
1436 dst[1] = rgba[GCOMP];
1437 dst[2] = rgba[BCOMP];
1438 dst[3] = rgba[ACOMP];
1439 }
1440 #endif
1441
1442
1443 /* MESA_FORMAT_RGBA_INT16 **************************************************/
1444
1445 static void
1446 FETCH(rgba_int16)(const struct gl_texture_image *texImage,
1447 GLint i, GLint j, GLint k, GLfloat *texel )
1448 {
1449 const GLshort *src = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1450 texel[RCOMP] = (GLfloat) src[0];
1451 texel[GCOMP] = (GLfloat) src[1];
1452 texel[BCOMP] = (GLfloat) src[2];
1453 texel[ACOMP] = (GLfloat) src[3];
1454 }
1455
1456 #if DIM == 3
1457 static void
1458 store_texel_rgba_int16(struct gl_texture_image *texImage,
1459 GLint i, GLint j, GLint k, const void *texel)
1460 {
1461 const GLshort *rgba = (const GLshort *) texel;
1462 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1463 dst[0] = rgba[RCOMP];
1464 dst[1] = rgba[GCOMP];
1465 dst[2] = rgba[BCOMP];
1466 dst[3] = rgba[ACOMP];
1467 }
1468 #endif
1469
1470
1471 /* MESA_FORMAT_RGBA_INT32 **************************************************/
1472
1473 static void
1474 FETCH(rgba_int32)(const struct gl_texture_image *texImage,
1475 GLint i, GLint j, GLint k, GLfloat *texel )
1476 {
1477 const GLint *src = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
1478 texel[RCOMP] = (GLfloat) src[0];
1479 texel[GCOMP] = (GLfloat) src[1];
1480 texel[BCOMP] = (GLfloat) src[2];
1481 texel[ACOMP] = (GLfloat) src[3];
1482 }
1483
1484 #if DIM == 3
1485 static void
1486 store_texel_rgba_int32(struct gl_texture_image *texImage,
1487 GLint i, GLint j, GLint k, const void *texel)
1488 {
1489 const GLint *rgba = (const GLint *) texel;
1490 GLint *dst = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
1491 dst[0] = rgba[RCOMP];
1492 dst[1] = rgba[GCOMP];
1493 dst[2] = rgba[BCOMP];
1494 dst[3] = rgba[ACOMP];
1495 }
1496 #endif
1497
1498
1499 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
1500
1501 static void
1502 FETCH(rgba_uint8)(const struct gl_texture_image *texImage,
1503 GLint i, GLint j, GLint k, GLfloat *texel )
1504 {
1505 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1506 texel[RCOMP] = (GLfloat) src[0];
1507 texel[GCOMP] = (GLfloat) src[1];
1508 texel[BCOMP] = (GLfloat) src[2];
1509 texel[ACOMP] = (GLfloat) src[3];
1510 }
1511
1512 #if DIM == 3
1513 static void
1514 store_texel_rgba_uint8(struct gl_texture_image *texImage,
1515 GLint i, GLint j, GLint k, const void *texel)
1516 {
1517 const GLubyte *rgba = (const GLubyte *) texel;
1518 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1519 dst[0] = rgba[RCOMP];
1520 dst[1] = rgba[GCOMP];
1521 dst[2] = rgba[BCOMP];
1522 dst[3] = rgba[ACOMP];
1523 }
1524 #endif
1525
1526
1527 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
1528
1529 static void
1530 FETCH(rgba_uint16)(const struct gl_texture_image *texImage,
1531 GLint i, GLint j, GLint k, GLfloat *texel )
1532 {
1533 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1534 texel[RCOMP] = (GLfloat) src[0];
1535 texel[GCOMP] = (GLfloat) src[1];
1536 texel[BCOMP] = (GLfloat) src[2];
1537 texel[ACOMP] = (GLfloat) src[3];
1538 }
1539
1540 #if DIM == 3
1541 static void
1542 store_texel_rgba_uint16(struct gl_texture_image *texImage,
1543 GLint i, GLint j, GLint k, const void *texel)
1544 {
1545 const GLushort *rgba = (const GLushort *) texel;
1546 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1547 dst[0] = rgba[RCOMP];
1548 dst[1] = rgba[GCOMP];
1549 dst[2] = rgba[BCOMP];
1550 dst[3] = rgba[ACOMP];
1551 }
1552 #endif
1553
1554
1555 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
1556
1557 static void
1558 FETCH(rgba_uint32)(const struct gl_texture_image *texImage,
1559 GLint i, GLint j, GLint k, GLfloat *texel )
1560 {
1561 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
1562 texel[RCOMP] = (GLfloat) src[0];
1563 texel[GCOMP] = (GLfloat) src[1];
1564 texel[BCOMP] = (GLfloat) src[2];
1565 texel[ACOMP] = (GLfloat) src[3];
1566 }
1567
1568 #if DIM == 3
1569 static void
1570 store_texel_rgba_uint32(struct gl_texture_image *texImage,
1571 GLint i, GLint j, GLint k, const void *texel)
1572 {
1573 const GLuint *rgba = (const GLuint *) texel;
1574 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
1575 dst[0] = rgba[RCOMP];
1576 dst[1] = rgba[GCOMP];
1577 dst[2] = rgba[BCOMP];
1578 dst[3] = rgba[ACOMP];
1579 }
1580 #endif
1581
1582
1583 /* MESA_FORMAT_DUDV8 ********************************************************/
1584
1585 /* this format by definition produces 0,0,0,1 as rgba values,
1586 however we'll return the dudv values as rg and fix up elsewhere */
1587 static void FETCH(dudv8)(const struct gl_texture_image *texImage,
1588 GLint i, GLint j, GLint k, GLfloat *texel )
1589 {
1590 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 2);
1591 texel[RCOMP] = BYTE_TO_FLOAT(src[0]);
1592 texel[GCOMP] = BYTE_TO_FLOAT(src[1]);
1593 texel[BCOMP] = 0;
1594 texel[ACOMP] = 0;
1595 }
1596
1597
1598 /* MESA_FORMAT_SIGNED_R8 ***********************************************/
1599
1600 static void FETCH(signed_r8)( const struct gl_texture_image *texImage,
1601 GLint i, GLint j, GLint k, GLfloat *texel )
1602 {
1603 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1604 texel[RCOMP] = BYTE_TO_FLOAT_TEX( s );
1605 texel[GCOMP] = 0.0F;
1606 texel[BCOMP] = 0.0F;
1607 texel[ACOMP] = 1.0F;
1608 }
1609
1610 #if DIM == 3
1611 static void store_texel_signed_r8(struct gl_texture_image *texImage,
1612 GLint i, GLint j, GLint k, const void *texel)
1613 {
1614 const GLbyte *rgba = (const GLbyte *) texel;
1615 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1616 *dst = rgba[RCOMP];
1617 }
1618 #endif
1619
1620
1621 /* MESA_FORMAT_SIGNED_RG88 ***********************************************/
1622
1623 static void FETCH(signed_rg88)( const struct gl_texture_image *texImage,
1624 GLint i, GLint j, GLint k, GLfloat *texel )
1625 {
1626 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1627 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1628 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
1629 texel[BCOMP] = 0.0F;
1630 texel[ACOMP] = 1.0F;
1631 }
1632
1633 #if DIM == 3
1634 static void store_texel_signed_rg88(struct gl_texture_image *texImage,
1635 GLint i, GLint j, GLint k, const void *texel)
1636 {
1637 const GLbyte *rg = (const GLbyte *) texel;
1638 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 2);
1639 *dst = PACK_COLOR_88(rg[RCOMP], rg[GCOMP]);
1640 }
1641 #endif
1642
1643
1644 /* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
1645
1646 static void FETCH(signed_rgbx8888)( const struct gl_texture_image *texImage,
1647 GLint i, GLint j, GLint k, GLfloat *texel )
1648 {
1649 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1650 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1651 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1652 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1653 texel[ACOMP] = 1.0f;
1654 }
1655
1656 #if DIM == 3
1657 static void store_texel_signed_rgbx8888(struct gl_texture_image *texImage,
1658 GLint i, GLint j, GLint k, const void *texel)
1659 {
1660 const GLbyte *rgba = (const GLbyte *) texel;
1661 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1662 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 255);
1663 }
1664 #endif
1665
1666
1667 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1668
1669 static void FETCH(signed_rgba8888)( const struct gl_texture_image *texImage,
1670 GLint i, GLint j, GLint k, GLfloat *texel )
1671 {
1672 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1673 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1674 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1675 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1676 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1677 }
1678
1679 #if DIM == 3
1680 static void store_texel_signed_rgba8888(struct gl_texture_image *texImage,
1681 GLint i, GLint j, GLint k, const void *texel)
1682 {
1683 const GLbyte *rgba = (const GLbyte *) texel;
1684 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1685 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1686 }
1687 #endif
1688
1689 static void FETCH(signed_rgba8888_rev)( const struct gl_texture_image *texImage,
1690 GLint i, GLint j, GLint k, GLfloat *texel )
1691 {
1692 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1693 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1694 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1695 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1696 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1697 }
1698
1699 #if DIM == 3
1700 static void store_texel_signed_rgba8888_rev(struct gl_texture_image *texImage,
1701 GLint i, GLint j, GLint k, const void *texel)
1702 {
1703 const GLubyte *rgba = (const GLubyte *) texel;
1704 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1705 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1706 }
1707 #endif
1708
1709
1710
1711 /* MESA_FORMAT_SIGNED_R_16 ***********************************************/
1712
1713 static void
1714 FETCH(signed_r_16)(const struct gl_texture_image *texImage,
1715 GLint i, GLint j, GLint k, GLfloat *texel)
1716 {
1717 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1718 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s );
1719 texel[GCOMP] = 0.0F;
1720 texel[BCOMP] = 0.0F;
1721 texel[ACOMP] = 1.0F;
1722 }
1723
1724 #if DIM == 3
1725 static void
1726 store_texel_signed_r_16(struct gl_texture_image *texImage,
1727 GLint i, GLint j, GLint k, const void *texel)
1728 {
1729 const GLshort *rgba = (const GLshort *) texel;
1730 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1731 *dst = rgba[0];
1732 }
1733 #endif
1734
1735
1736 /* MESA_FORMAT_SIGNED_RG_16 ***********************************************/
1737
1738 static void
1739 FETCH(signed_rg_16)(const struct gl_texture_image *texImage,
1740 GLint i, GLint j, GLint k, GLfloat *texel)
1741 {
1742 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
1743 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1744 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1745 texel[BCOMP] = 0.0F;
1746 texel[ACOMP] = 1.0F;
1747 }
1748
1749 #if DIM == 3
1750 static void
1751 store_texel_signed_rg_16(struct gl_texture_image *texImage,
1752 GLint i, GLint j, GLint k, const void *texel)
1753 {
1754 const GLshort *rgba = (const GLshort *) texel;
1755 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
1756 dst[0] = rgba[RCOMP];
1757 dst[1] = rgba[GCOMP];
1758 }
1759 #endif
1760
1761
1762 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
1763
1764 static void
1765 FETCH(signed_rgb_16)(const struct gl_texture_image *texImage,
1766 GLint i, GLint j, GLint k, GLfloat *texel)
1767 {
1768 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
1769 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1770 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1771 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
1772 texel[ACOMP] = 1.0F;
1773 }
1774
1775 #if DIM == 3
1776 static void
1777 store_texel_signed_rgb_16(struct gl_texture_image *texImage,
1778 GLint i, GLint j, GLint k, const void *texel)
1779 {
1780 const GLshort *rgba = (const GLshort *) texel;
1781 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
1782 dst[0] = rgba[RCOMP];
1783 dst[1] = rgba[GCOMP];
1784 dst[2] = rgba[BCOMP];
1785 }
1786 #endif
1787
1788
1789 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
1790
1791 static void
1792 FETCH(signed_rgba_16)(const struct gl_texture_image *texImage,
1793 GLint i, GLint j, GLint k, GLfloat *texel)
1794 {
1795 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1796 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1797 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1798 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
1799 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
1800 }
1801
1802 #if DIM == 3
1803 static void
1804 store_texel_signed_rgba_16(struct gl_texture_image *texImage,
1805 GLint i, GLint j, GLint k, const void *texel)
1806 {
1807 const GLshort *rgba = (const GLshort *) texel;
1808 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1809 dst[0] = rgba[RCOMP];
1810 dst[1] = rgba[GCOMP];
1811 dst[2] = rgba[BCOMP];
1812 dst[3] = rgba[ACOMP];
1813 }
1814 #endif
1815
1816
1817
1818 /* MESA_FORMAT_RGBA_16 ***********************************************/
1819
1820 static void
1821 FETCH(rgba_16)(const struct gl_texture_image *texImage,
1822 GLint i, GLint j, GLint k, GLfloat *texel)
1823 {
1824 const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1825 texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
1826 texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
1827 texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
1828 texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
1829 }
1830
1831 #if DIM == 3
1832 static void
1833 store_texel_rgba_16(struct gl_texture_image *texImage,
1834 GLint i, GLint j, GLint k, const void *texel)
1835 {
1836 const GLushort *rgba = (const GLushort *) texel;
1837 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1838 dst[0] = rgba[RCOMP];
1839 dst[1] = rgba[GCOMP];
1840 dst[2] = rgba[BCOMP];
1841 dst[3] = rgba[ACOMP];
1842 }
1843 #endif
1844
1845
1846
1847 /* MESA_FORMAT_YCBCR *********************************************************/
1848
1849 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
1850 * We convert YCbCr to RGB here.
1851 */
1852 static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
1853 GLint i, GLint j, GLint k, GLfloat *texel )
1854 {
1855 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1856 const GLushort *src1 = src0 + 1; /* odd */
1857 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1858 const GLubyte cb = *src0 & 0xff; /* chroma U */
1859 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1860 const GLubyte cr = *src1 & 0xff; /* chroma V */
1861 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1862 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1863 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1864 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1865 r *= (1.0F / 255.0F);
1866 g *= (1.0F / 255.0F);
1867 b *= (1.0F / 255.0F);
1868 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1869 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1870 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1871 texel[ACOMP] = 1.0F;
1872 }
1873
1874 #if DIM == 3
1875 static void store_texel_ycbcr(struct gl_texture_image *texImage,
1876 GLint i, GLint j, GLint k, const void *texel)
1877 {
1878 (void) texImage;
1879 (void) i;
1880 (void) j;
1881 (void) k;
1882 (void) texel;
1883 /* XXX to do */
1884 }
1885 #endif
1886
1887
1888 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1889
1890 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
1891 * We convert YCbCr to RGB here.
1892 */
1893 static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
1894 GLint i, GLint j, GLint k, GLfloat *texel )
1895 {
1896 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1897 const GLushort *src1 = src0 + 1; /* odd */
1898 const GLubyte y0 = *src0 & 0xff; /* luminance */
1899 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1900 const GLubyte y1 = *src1 & 0xff; /* luminance */
1901 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1902 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1903 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1904 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1905 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1906 r *= (1.0F / 255.0F);
1907 g *= (1.0F / 255.0F);
1908 b *= (1.0F / 255.0F);
1909 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1910 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1911 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1912 texel[ACOMP] = 1.0F;
1913 }
1914
1915 #if DIM == 3
1916 static void store_texel_ycbcr_rev(struct gl_texture_image *texImage,
1917 GLint i, GLint j, GLint k, const void *texel)
1918 {
1919 (void) texImage;
1920 (void) i;
1921 (void) j;
1922 (void) k;
1923 (void) texel;
1924 /* XXX to do */
1925 }
1926 #endif
1927
1928
1929 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1930
1931 static void FETCH(f_z24_s8)( const struct gl_texture_image *texImage,
1932 GLint i, GLint j, GLint k, GLfloat *texel )
1933 {
1934 /* only return Z, not stencil data */
1935 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1936 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1937 texel[0] = ((*src) >> 8) * scale;
1938 ASSERT(texImage->TexFormat == MESA_FORMAT_Z24_S8);
1939 ASSERT(texel[0] >= 0.0F);
1940 ASSERT(texel[0] <= 1.0F);
1941 }
1942
1943 #if DIM == 3
1944 static void store_texel_z24_s8(struct gl_texture_image *texImage,
1945 GLint i, GLint j, GLint k, const void *texel)
1946 {
1947 /* only store Z, not stencil */
1948 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1949 GLfloat depth = *((GLfloat *) texel);
1950 GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
1951 *dst = zi | (*dst & 0xff);
1952 }
1953 #endif
1954
1955
1956 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1957
1958 static void FETCH(f_s8_z24)( const struct gl_texture_image *texImage,
1959 GLint i, GLint j, GLint k, GLfloat *texel )
1960 {
1961 /* only return Z, not stencil data */
1962 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1963 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1964 texel[0] = ((*src) & 0x00ffffff) * scale;
1965 ASSERT(texImage->TexFormat == MESA_FORMAT_S8_Z24);
1966 ASSERT(texel[0] >= 0.0F);
1967 ASSERT(texel[0] <= 1.0F);
1968 }
1969
1970 #if DIM == 3
1971 static void store_texel_s8_z24(struct gl_texture_image *texImage,
1972 GLint i, GLint j, GLint k, const void *texel)
1973 {
1974 /* only store Z, not stencil */
1975 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1976 GLfloat depth = *((GLfloat *) texel);
1977 GLuint zi = (GLuint) (depth * 0xffffff);
1978 *dst = zi | (*dst & 0xff000000);
1979 }
1980 #endif
1981
1982
1983 #undef TEXEL_ADDR
1984 #undef DIM
1985 #undef FETCH