Merge branch 'mesa_7_6_branch'
[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_RGB888 ********************************************************/
563
564 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
565 static void FETCH(f_rgb888)( const struct gl_texture_image *texImage,
566 GLint i, GLint j, GLint k, GLfloat *texel )
567 {
568 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
569 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
570 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
571 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
572 texel[ACOMP] = 1.0F;
573 }
574
575 #if DIM == 3
576 static void store_texel_rgb888(struct gl_texture_image *texImage,
577 GLint i, GLint j, GLint k, const void *texel)
578 {
579 const GLubyte *rgba = (const GLubyte *) texel;
580 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
581 dst[0] = rgba[BCOMP];
582 dst[1] = rgba[GCOMP];
583 dst[2] = rgba[RCOMP];
584 }
585 #endif
586
587
588 /* MESA_FORMAT_BGR888 ********************************************************/
589
590 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
591 static void FETCH(f_bgr888)( const struct gl_texture_image *texImage,
592 GLint i, GLint j, GLint k, GLfloat *texel )
593 {
594 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
595 texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
596 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
597 texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
598 texel[ACOMP] = 1.0F;
599 }
600
601 #if DIM == 3
602 static void store_texel_bgr888(struct gl_texture_image *texImage,
603 GLint i, GLint j, GLint k, const void *texel)
604 {
605 const GLubyte *rgba = (const GLubyte *) texel;
606 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
607 dst[0] = rgba[RCOMP];
608 dst[1] = rgba[GCOMP];
609 dst[2] = rgba[BCOMP];
610 }
611 #endif
612
613
614 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
615 instead of slow (g << 2) * 255 / 252 (always rounds down) */
616
617 /* MESA_FORMAT_RGB565 ********************************************************/
618
619 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
620 static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
621 GLint i, GLint j, GLint k, GLfloat *texel )
622 {
623 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
624 const GLushort s = *src;
625 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
626 texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
627 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
628 texel[ACOMP] = 1.0F;
629 }
630
631 #if DIM == 3
632 static void store_texel_rgb565(struct gl_texture_image *texImage,
633 GLint i, GLint j, GLint k, const void *texel)
634 {
635 const GLubyte *rgba = (const GLubyte *) texel;
636 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
637 *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
638 }
639 #endif
640
641
642 /* MESA_FORMAT_RGB565_REV ****************************************************/
643
644 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
645 static void FETCH(f_rgb565_rev)( const struct gl_texture_image *texImage,
646 GLint i, GLint j, GLint k, GLfloat *texel )
647 {
648 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
649 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
650 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
651 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
652 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
653 texel[ACOMP] = 1.0F;
654 }
655
656 #if DIM == 3
657 static void store_texel_rgb565_rev(struct gl_texture_image *texImage,
658 GLint i, GLint j, GLint k, const void *texel)
659 {
660 const GLubyte *rgba = (const GLubyte *) texel;
661 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
662 *dst = PACK_COLOR_565(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
663 }
664 #endif
665
666
667 /* MESA_FORMAT_ARGB4444 ******************************************************/
668
669 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
670 static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
671 GLint i, GLint j, GLint k, GLfloat *texel )
672 {
673 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
674 const GLushort s = *src;
675 texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
676 texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
677 texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
678 texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
679 }
680
681 #if DIM == 3
682 static void store_texel_argb4444(struct gl_texture_image *texImage,
683 GLint i, GLint j, GLint k, const void *texel)
684 {
685 const GLubyte *rgba = (const GLubyte *) texel;
686 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
687 *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
688 }
689 #endif
690
691
692 /* MESA_FORMAT_ARGB4444_REV **************************************************/
693
694 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
695 static void FETCH(f_argb4444_rev)( const struct gl_texture_image *texImage,
696 GLint i, GLint j, GLint k, GLfloat *texel )
697 {
698 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
699 texel[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
700 texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
701 texel[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
702 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
703 }
704
705 #if DIM == 3
706 static void store_texel_argb4444_rev(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[BCOMP], rgba[GCOMP], rgba[RCOMP]);
712 }
713 #endif
714
715 /* MESA_FORMAT_RGBA5551 ******************************************************/
716
717 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
718 static void FETCH(f_rgba5551)( const struct gl_texture_image *texImage,
719 GLint i, GLint j, GLint k, GLfloat *texel )
720 {
721 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
722 const GLushort s = *src;
723 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
724 texel[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
725 texel[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
726 texel[ACOMP] = ((s ) & 0x01) * 1.0F;
727 }
728
729 #if DIM == 3
730 static void store_texel_rgba5551(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_5551(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
736 }
737 #endif
738
739 /* MESA_FORMAT_ARGB1555 ******************************************************/
740
741 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
742 static void FETCH(f_argb1555)( 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 >> 10) & 0x1f) * (1.0F / 31.0F);
748 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
749 texel[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F);
750 texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
751 }
752
753 #if DIM == 3
754 static void store_texel_argb1555(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_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
760 }
761 #endif
762
763
764 /* MESA_FORMAT_ARGB1555_REV **************************************************/
765
766 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
767 static void FETCH(f_argb1555_rev)( const struct gl_texture_image *texImage,
768 GLint i, GLint j, GLint k, GLfloat *texel )
769 {
770 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
771 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
772 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
773 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
774 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
775 texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
776 }
777
778 #if DIM == 3
779 static void store_texel_argb1555_rev(struct gl_texture_image *texImage,
780 GLint i, GLint j, GLint k, const void *texel)
781 {
782 const GLubyte *rgba = (const GLubyte *) texel;
783 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
784 *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
785 }
786 #endif
787
788
789 /* MESA_FORMAT_AL88 **********************************************************/
790
791 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
792 static void FETCH(f_al88)( const struct gl_texture_image *texImage,
793 GLint i, GLint j, GLint k, GLfloat *texel )
794 {
795 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
796 texel[RCOMP] =
797 texel[GCOMP] =
798 texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
799 texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
800 }
801
802 #if DIM == 3
803 static void store_texel_al88(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_88(rgba[ACOMP], rgba[RCOMP]);
809 }
810 #endif
811
812
813 /* MESA_FORMAT_AL88_REV ******************************************************/
814
815 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
816 static void FETCH(f_al88_rev)( const struct gl_texture_image *texImage,
817 GLint i, GLint j, GLint k, GLfloat *texel )
818 {
819 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
820 texel[RCOMP] =
821 texel[GCOMP] =
822 texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
823 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
824 }
825
826 #if DIM == 3
827 static void store_texel_al88_rev(struct gl_texture_image *texImage,
828 GLint i, GLint j, GLint k, const void *texel)
829 {
830 const GLubyte *rgba = (const GLubyte *) texel;
831 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
832 *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
833 }
834 #endif
835
836
837 /* MESA_FORMAT_RGB332 ********************************************************/
838
839 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
840 static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
841 GLint i, GLint j, GLint k, GLfloat *texel )
842 {
843 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
844 const GLubyte s = *src;
845 texel[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
846 texel[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
847 texel[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F);
848 texel[ACOMP] = 1.0F;
849 }
850
851 #if DIM == 3
852 static void store_texel_rgb332(struct gl_texture_image *texImage,
853 GLint i, GLint j, GLint k, const void *texel)
854 {
855 const GLubyte *rgba = (const GLubyte *) texel;
856 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
857 *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
858 }
859 #endif
860
861
862 /* MESA_FORMAT_A8 ************************************************************/
863
864 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
865 static void FETCH(f_a8)( const struct gl_texture_image *texImage,
866 GLint i, GLint j, GLint k, GLfloat *texel )
867 {
868 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
869 texel[RCOMP] =
870 texel[GCOMP] =
871 texel[BCOMP] = 0.0F;
872 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
873 }
874
875 #if DIM == 3
876 static void store_texel_a8(struct gl_texture_image *texImage,
877 GLint i, GLint j, GLint k, const void *texel)
878 {
879 const GLubyte *rgba = (const GLubyte *) texel;
880 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
881 *dst = rgba[ACOMP];
882 }
883 #endif
884
885
886 /* MESA_FORMAT_L8 ************************************************************/
887
888 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
889 static void FETCH(f_l8)( const struct gl_texture_image *texImage,
890 GLint i, GLint j, GLint k, GLfloat *texel )
891 {
892 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
893 texel[RCOMP] =
894 texel[GCOMP] =
895 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
896 texel[ACOMP] = 1.0F;
897 }
898
899 #if DIM == 3
900 static void store_texel_l8(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 = rgba[RCOMP];
906 }
907 #endif
908
909
910 /* MESA_FORMAT_I8 ************************************************************/
911
912 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
913 static void FETCH(f_i8)( const struct gl_texture_image *texImage,
914 GLint i, GLint j, GLint k, GLfloat *texel )
915 {
916 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
917 texel[RCOMP] =
918 texel[GCOMP] =
919 texel[BCOMP] =
920 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
921 }
922
923 #if DIM == 3
924 static void store_texel_i8(struct gl_texture_image *texImage,
925 GLint i, GLint j, GLint k, const void *texel)
926 {
927 const GLubyte *rgba = (const GLubyte *) texel;
928 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
929 *dst = rgba[RCOMP];
930 }
931 #endif
932
933
934 /* MESA_FORMAT_CI8 ***********************************************************/
935
936 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
937 * color table, and return 4 GLchans.
938 */
939 static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
940 GLint i, GLint j, GLint k, GLfloat *texel )
941 {
942 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
943 const struct gl_color_table *palette;
944 GLuint index;
945 GET_CURRENT_CONTEXT(ctx);
946
947 if (ctx->Texture.SharedPalette) {
948 palette = &ctx->Texture.Palette;
949 }
950 else {
951 palette = &texImage->TexObject->Palette;
952 }
953 if (palette->Size == 0)
954 return; /* undefined results */
955
956 /* Mask the index against size of palette to avoid going out of bounds */
957 index = (*src) & (palette->Size - 1);
958
959 {
960 const GLfloat *table = palette->TableF;
961 switch (palette->_BaseFormat) {
962 case GL_ALPHA:
963 texel[RCOMP] =
964 texel[GCOMP] =
965 texel[BCOMP] = 0.0F;
966 texel[ACOMP] = table[index];
967 break;
968 case GL_LUMINANCE:
969 texel[RCOMP] =
970 texel[GCOMP] =
971 texel[BCOMP] = table[index];
972 texel[ACOMP] = 1.0F;
973 break;
974 case GL_INTENSITY:
975 texel[RCOMP] =
976 texel[GCOMP] =
977 texel[BCOMP] =
978 texel[ACOMP] = table[index];
979 break;
980 case GL_LUMINANCE_ALPHA:
981 texel[RCOMP] =
982 texel[GCOMP] =
983 texel[BCOMP] = table[index * 2 + 0];
984 texel[ACOMP] = table[index * 2 + 1];
985 break;
986 case GL_RGB:
987 texel[RCOMP] = table[index * 3 + 0];
988 texel[GCOMP] = table[index * 3 + 1];
989 texel[BCOMP] = table[index * 3 + 2];
990 texel[ACOMP] = 1.0F;
991 break;
992 case GL_RGBA:
993 texel[RCOMP] = table[index * 4 + 0];
994 texel[GCOMP] = table[index * 4 + 1];
995 texel[BCOMP] = table[index * 4 + 2];
996 texel[ACOMP] = table[index * 4 + 3];
997 break;
998 default:
999 _mesa_problem(ctx, "Bad palette format in fetch_texel_ci8");
1000 return;
1001 }
1002 }
1003 }
1004
1005 #if DIM == 3
1006 static void store_texel_ci8(struct gl_texture_image *texImage,
1007 GLint i, GLint j, GLint k, const void *texel)
1008 {
1009 const GLubyte *index = (const GLubyte *) texel;
1010 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1011 *dst = *index;
1012 }
1013 #endif
1014
1015
1016 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1017 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1018 static void FETCH(srgb8)(const struct gl_texture_image *texImage,
1019 GLint i, GLint j, GLint k, GLfloat *texel )
1020 {
1021 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1022 texel[RCOMP] = nonlinear_to_linear(src[2]);
1023 texel[GCOMP] = nonlinear_to_linear(src[1]);
1024 texel[BCOMP] = nonlinear_to_linear(src[0]);
1025 texel[ACOMP] = 1.0F;
1026 }
1027
1028 #if DIM == 3
1029 static void store_texel_srgb8(struct gl_texture_image *texImage,
1030 GLint i, GLint j, GLint k, const void *texel)
1031 {
1032 const GLubyte *rgba = (const GLubyte *) texel;
1033 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1034 dst[0] = rgba[BCOMP]; /* no conversion */
1035 dst[1] = rgba[GCOMP];
1036 dst[2] = rgba[RCOMP];
1037 }
1038 #endif
1039
1040 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1041 static void FETCH(srgba8)(const struct gl_texture_image *texImage,
1042 GLint i, GLint j, GLint k, GLfloat *texel )
1043 {
1044 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1045 texel[RCOMP] = nonlinear_to_linear( (s >> 24) );
1046 texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1047 texel[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1048 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */
1049 }
1050
1051 #if DIM == 3
1052 static void store_texel_srgba8(struct gl_texture_image *texImage,
1053 GLint i, GLint j, GLint k, const void *texel)
1054 {
1055 const GLubyte *rgba = (const GLubyte *) texel;
1056 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1057 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1058 }
1059 #endif
1060
1061 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1062 static void FETCH(sargb8)(const struct gl_texture_image *texImage,
1063 GLint i, GLint j, GLint k, GLfloat *texel )
1064 {
1065 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1066 texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1067 texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1068 texel[BCOMP] = nonlinear_to_linear( (s ) & 0xff );
1069 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
1070 }
1071
1072 #if DIM == 3
1073 static void store_texel_sargb8(struct gl_texture_image *texImage,
1074 GLint i, GLint j, GLint k, const void *texel)
1075 {
1076 const GLubyte *rgba = (const GLubyte *) texel;
1077 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1078 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1079 }
1080 #endif
1081
1082 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1083 static void FETCH(sl8)(const struct gl_texture_image *texImage,
1084 GLint i, GLint j, GLint k, GLfloat *texel )
1085 {
1086 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1087 texel[RCOMP] =
1088 texel[GCOMP] =
1089 texel[BCOMP] = nonlinear_to_linear(src[0]);
1090 texel[ACOMP] = 1.0F;
1091 }
1092
1093 #if DIM == 3
1094 static void store_texel_sl8(struct gl_texture_image *texImage,
1095 GLint i, GLint j, GLint k, const void *texel)
1096 {
1097 const GLubyte *rgba = (const GLubyte *) texel;
1098 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1099 dst[0] = rgba[RCOMP];
1100 }
1101 #endif
1102
1103 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1104 static void FETCH(sla8)(const struct gl_texture_image *texImage,
1105 GLint i, GLint j, GLint k, GLfloat *texel )
1106 {
1107 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1108 texel[RCOMP] =
1109 texel[GCOMP] =
1110 texel[BCOMP] = nonlinear_to_linear(src[0]);
1111 texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
1112 }
1113
1114 #if DIM == 3
1115 static void store_texel_sla8(struct gl_texture_image *texImage,
1116 GLint i, GLint j, GLint k, const void *texel)
1117 {
1118 const GLubyte *rgba = (const GLubyte *) texel;
1119 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1120 dst[0] = rgba[RCOMP];
1121 dst[1] = rgba[ACOMP];
1122 }
1123 #endif
1124
1125
1126 /* MESA_FORMAT_DUDV8 ********************************************************/
1127
1128 /* this format by definition produces 0,0,0,1 as rgba values,
1129 however we'll return the dudv values as rg and fix up elsewhere */
1130 static void FETCH(dudv8)(const struct gl_texture_image *texImage,
1131 GLint i, GLint j, GLint k, GLfloat *texel )
1132 {
1133 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 2);
1134 texel[RCOMP] = BYTE_TO_FLOAT(src[0]);
1135 texel[GCOMP] = BYTE_TO_FLOAT(src[1]);
1136 texel[BCOMP] = 0;
1137 texel[ACOMP] = 0;
1138 }
1139
1140 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1141
1142 static void FETCH(signed_rgba8888)( const struct gl_texture_image *texImage,
1143 GLint i, GLint j, GLint k, GLfloat *texel )
1144 {
1145 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1146 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (s >> 24) );
1147 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (s >> 16) & 0xff );
1148 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (s >> 8) & 0xff );
1149 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (s ) & 0xff );
1150 }
1151
1152 #if DIM == 3
1153 static void store_texel_signed_rgba8888(struct gl_texture_image *texImage,
1154 GLint i, GLint j, GLint k, const void *texel)
1155 {
1156 const GLbyte *rgba = (const GLbyte *) texel;
1157 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1158 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1159 }
1160 #endif
1161
1162 static void FETCH(signed_rgba8888_rev)( const struct gl_texture_image *texImage,
1163 GLint i, GLint j, GLint k, GLfloat *texel )
1164 {
1165 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1166 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (s ) & 0xff );
1167 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (s >> 8) & 0xff );
1168 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (s >> 16) & 0xff );
1169 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (s >> 24) );
1170 }
1171
1172 #if DIM == 3
1173 static void store_texel_signed_rgba8888_rev(struct gl_texture_image *texImage,
1174 GLint i, GLint j, GLint k, const void *texel)
1175 {
1176 const GLubyte *rgba = (const GLubyte *) texel;
1177 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1178 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1179 }
1180 #endif
1181
1182
1183
1184 /* MESA_FORMAT_YCBCR *********************************************************/
1185
1186 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
1187 * We convert YCbCr to RGB here.
1188 */
1189 static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
1190 GLint i, GLint j, GLint k, GLfloat *texel )
1191 {
1192 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1193 const GLushort *src1 = src0 + 1; /* odd */
1194 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1195 const GLubyte cb = *src0 & 0xff; /* chroma U */
1196 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1197 const GLubyte cr = *src1 & 0xff; /* chroma V */
1198 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1199 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1200 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1201 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1202 r *= (1.0F / 255.0F);
1203 g *= (1.0F / 255.0F);
1204 b *= (1.0F / 255.0F);
1205 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1206 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1207 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1208 texel[ACOMP] = 1.0F;
1209 }
1210
1211 #if DIM == 3
1212 static void store_texel_ycbcr(struct gl_texture_image *texImage,
1213 GLint i, GLint j, GLint k, const void *texel)
1214 {
1215 (void) texImage;
1216 (void) i;
1217 (void) j;
1218 (void) k;
1219 (void) texel;
1220 /* XXX to do */
1221 }
1222 #endif
1223
1224
1225 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1226
1227 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
1228 * We convert YCbCr to RGB here.
1229 */
1230 static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
1231 GLint i, GLint j, GLint k, GLfloat *texel )
1232 {
1233 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1234 const GLushort *src1 = src0 + 1; /* odd */
1235 const GLubyte y0 = *src0 & 0xff; /* luminance */
1236 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1237 const GLubyte y1 = *src1 & 0xff; /* luminance */
1238 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1239 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1240 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1241 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1242 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1243 r *= (1.0F / 255.0F);
1244 g *= (1.0F / 255.0F);
1245 b *= (1.0F / 255.0F);
1246 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1247 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1248 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1249 texel[ACOMP] = 1.0F;
1250 }
1251
1252 #if DIM == 3
1253 static void store_texel_ycbcr_rev(struct gl_texture_image *texImage,
1254 GLint i, GLint j, GLint k, const void *texel)
1255 {
1256 (void) texImage;
1257 (void) i;
1258 (void) j;
1259 (void) k;
1260 (void) texel;
1261 /* XXX to do */
1262 }
1263 #endif
1264
1265
1266 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1267
1268 static void FETCH(f_z24_s8)( const struct gl_texture_image *texImage,
1269 GLint i, GLint j, GLint k, GLfloat *texel )
1270 {
1271 /* only return Z, not stencil data */
1272 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1273 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1274 texel[0] = ((*src) >> 8) * scale;
1275 ASSERT(texImage->TexFormat == MESA_FORMAT_Z24_S8);
1276 ASSERT(texel[0] >= 0.0F);
1277 ASSERT(texel[0] <= 1.0F);
1278 }
1279
1280 #if DIM == 3
1281 static void store_texel_z24_s8(struct gl_texture_image *texImage,
1282 GLint i, GLint j, GLint k, const void *texel)
1283 {
1284 /* only store Z, not stencil */
1285 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1286 GLfloat depth = *((GLfloat *) texel);
1287 GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
1288 *dst = zi | (*dst & 0xff);
1289 }
1290 #endif
1291
1292
1293 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1294
1295 static void FETCH(f_s8_z24)( const struct gl_texture_image *texImage,
1296 GLint i, GLint j, GLint k, GLfloat *texel )
1297 {
1298 /* only return Z, not stencil data */
1299 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1300 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1301 texel[0] = ((*src) & 0x00ffffff) * scale;
1302 ASSERT(texImage->TexFormat == MESA_FORMAT_S8_Z24);
1303 ASSERT(texel[0] >= 0.0F);
1304 ASSERT(texel[0] <= 1.0F);
1305 }
1306
1307 #if DIM == 3
1308 static void store_texel_s8_z24(struct gl_texture_image *texImage,
1309 GLint i, GLint j, GLint k, const void *texel)
1310 {
1311 /* only store Z, not stencil */
1312 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1313 GLfloat depth = *((GLfloat *) texel);
1314 GLuint zi = (GLuint) (depth * 0xffffff);
1315 *dst = zi | (*dst & 0xff000000);
1316 }
1317 #endif
1318
1319
1320 #undef TEXEL_ADDR
1321 #undef DIM
1322 #undef FETCH