Merge branch 'mesa_7_5_branch'
[mesa.git] / src / mesa / main / texformat_tmp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.1
4 *
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008 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 texformat_tmp.h
29 * Texel fetch functions template.
30 *
31 * This template file is used by texformat.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 * \sa texformat.c and FetchTexel.
39 *
40 * \author Gareth Hughes
41 * \author Brian Paul
42 */
43
44
45 #if DIM == 1
46
47 #define TEXEL_ADDR( type, image, i, j, k, size ) \
48 ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
49
50 #define FETCH(x) fetch_texel_1d_##x
51
52 #elif DIM == 2
53
54 #define TEXEL_ADDR( type, image, i, j, k, size ) \
55 ((void) (k), \
56 ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
57
58 #define FETCH(x) fetch_texel_2d_##x
59
60 #elif DIM == 3
61
62 #define TEXEL_ADDR( type, image, i, j, k, size ) \
63 ((type *)(image)->Data + ((image)->ImageOffsets[k] \
64 + (image)->RowStride * (j) + (i)) * (size))
65
66 #define FETCH(x) fetch_texel_3d_##x
67
68 #else
69 #error illegal number of texture dimensions
70 #endif
71
72
73 /* MESA_FORMAT_RGBA **********************************************************/
74
75 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
76 static void FETCH(f_rgba)( const struct gl_texture_image *texImage,
77 GLint i, GLint j, GLint k, GLfloat *texel )
78 {
79 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 4);
80 texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
81 texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
82 texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
83 texel[ACOMP] = CHAN_TO_FLOAT(src[3]);
84 }
85
86 #if DIM == 3
87 /* Store a GLchan RGBA texel */
88 static void store_texel_rgba(struct gl_texture_image *texImage,
89 GLint i, GLint j, GLint k, const void *texel)
90 {
91 const GLchan *rgba = (const GLchan *) texel;
92 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 4);
93 dst[0] = rgba[RCOMP];
94 dst[1] = rgba[GCOMP];
95 dst[2] = rgba[BCOMP];
96 dst[3] = rgba[ACOMP];
97 }
98 #endif
99
100 /* MESA_FORMAT_RGB ***********************************************************/
101
102 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
103 static void FETCH(f_rgb)( const struct gl_texture_image *texImage,
104 GLint i, GLint j, GLint k, GLfloat *texel )
105 {
106 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 3);
107 texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
108 texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
109 texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
110 texel[ACOMP] = 1.0F;
111 }
112
113 #if DIM == 3
114 static void store_texel_rgb(struct gl_texture_image *texImage,
115 GLint i, GLint j, GLint k, const void *texel)
116 {
117 const GLchan *rgba = (const GLchan *) texel;
118 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 3);
119 dst[0] = rgba[RCOMP];
120 dst[1] = rgba[GCOMP];
121 dst[2] = rgba[BCOMP];
122 }
123 #endif
124
125 /* MESA_FORMAT_ALPHA *********************************************************/
126
127 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
128 static void FETCH(f_alpha)( const struct gl_texture_image *texImage,
129 GLint i, GLint j, GLint k, GLfloat *texel )
130 {
131 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
132 texel[RCOMP] =
133 texel[GCOMP] =
134 texel[BCOMP] = 0.0F;
135 texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
136 }
137
138 #if DIM == 3
139 static void store_texel_alpha(struct gl_texture_image *texImage,
140 GLint i, GLint j, GLint k, const void *texel)
141 {
142 const GLchan *rgba = (const GLchan *) texel;
143 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
144 dst[0] = rgba[ACOMP];
145 }
146 #endif
147
148 /* MESA_FORMAT_LUMINANCE *****************************************************/
149
150 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
151 static void FETCH(f_luminance)( const struct gl_texture_image *texImage,
152 GLint i, GLint j, GLint k, GLfloat *texel )
153 {
154 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
155 texel[RCOMP] =
156 texel[GCOMP] =
157 texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
158 texel[ACOMP] = 1.0F;
159 }
160
161 #if DIM == 3
162 static void store_texel_luminance(struct gl_texture_image *texImage,
163 GLint i, GLint j, GLint k, const void *texel)
164 {
165 const GLchan *rgba = (const GLchan *) texel;
166 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
167 dst[0] = rgba[RCOMP];
168 }
169 #endif
170
171 /* MESA_FORMAT_LUMINANCE_ALPHA ***********************************************/
172
173 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
174 static void FETCH(f_luminance_alpha)(const struct gl_texture_image *texImage,
175 GLint i, GLint j, GLint k, GLfloat *texel)
176 {
177 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 2);
178 texel[RCOMP] =
179 texel[GCOMP] =
180 texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
181 texel[ACOMP] = CHAN_TO_FLOAT(src[1]);
182 }
183
184 #if DIM == 3
185 static void store_texel_luminance_alpha(struct gl_texture_image *texImage,
186 GLint i, GLint j, GLint k, const void *texel)
187 {
188 const GLchan *rgba = (const GLchan *) texel;
189 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 2);
190 dst[0] = rgba[RCOMP];
191 dst[1] = rgba[ACOMP];
192 }
193 #endif
194
195 /* MESA_FORMAT_INTENSITY *****************************************************/
196
197 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
198 static void FETCH(f_intensity)( const struct gl_texture_image *texImage,
199 GLint i, GLint j, GLint k, GLfloat *texel )
200 {
201 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
202 texel[RCOMP] =
203 texel[GCOMP] =
204 texel[BCOMP] =
205 texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
206 }
207
208 #if DIM == 3
209 static void store_texel_intensity(struct gl_texture_image *texImage,
210 GLint i, GLint j, GLint k, const void *texel)
211 {
212 const GLchan *rgba = (const GLchan *) texel;
213 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
214 dst[0] = rgba[RCOMP];
215 }
216 #endif
217
218
219 /* MESA_FORMAT_Z32 ***********************************************************/
220
221 /* Fetch depth texel from 1D, 2D or 3D 32-bit depth texture,
222 * returning 1 GLfloat.
223 * Note: no GLchan version of this function.
224 */
225 static void FETCH(f_z32)( const struct gl_texture_image *texImage,
226 GLint i, GLint j, GLint k, GLfloat *texel )
227 {
228 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
229 texel[0] = src[0] * (1.0F / 0xffffffff);
230 }
231
232 #if DIM == 3
233 static void store_texel_z32(struct gl_texture_image *texImage,
234 GLint i, GLint j, GLint k, const void *texel)
235 {
236 const GLuint *depth = (const GLuint *) texel;
237 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
238 dst[0] = *depth;
239 }
240 #endif
241
242
243 /* MESA_FORMAT_Z16 ***********************************************************/
244
245 /* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
246 * returning 1 GLfloat.
247 * Note: no GLchan version of this function.
248 */
249 static void FETCH(f_z16)(const struct gl_texture_image *texImage,
250 GLint i, GLint j, GLint k, GLfloat *texel )
251 {
252 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
253 texel[0] = src[0] * (1.0F / 65535.0F);
254 }
255
256 #if DIM == 3
257 static void store_texel_z16(struct gl_texture_image *texImage,
258 GLint i, GLint j, GLint k, const void *texel)
259 {
260 const GLushort *depth = (const GLushort *) texel;
261 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
262 dst[0] = *depth;
263 }
264 #endif
265
266
267 /* MESA_FORMAT_RGBA_F32 ******************************************************/
268
269 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
270 */
271 static void FETCH(f_rgba_f32)( const struct gl_texture_image *texImage,
272 GLint i, GLint j, GLint k, GLfloat *texel )
273 {
274 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
275 texel[RCOMP] = src[0];
276 texel[GCOMP] = src[1];
277 texel[BCOMP] = src[2];
278 texel[ACOMP] = src[3];
279 }
280
281 #if DIM == 3
282 static void store_texel_rgba_f32(struct gl_texture_image *texImage,
283 GLint i, GLint j, GLint k, const void *texel)
284 {
285 const GLfloat *depth = (const GLfloat *) texel;
286 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
287 dst[0] = depth[RCOMP];
288 dst[1] = depth[GCOMP];
289 dst[2] = depth[BCOMP];
290 dst[3] = depth[ACOMP];
291 }
292 #endif
293
294
295 /* MESA_FORMAT_RGBA_F16 ******************************************************/
296
297 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
298 * returning 4 GLfloats.
299 */
300 static void FETCH(f_rgba_f16)( const struct gl_texture_image *texImage,
301 GLint i, GLint j, GLint k, GLfloat *texel )
302 {
303 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
304 texel[RCOMP] = _mesa_half_to_float(src[0]);
305 texel[GCOMP] = _mesa_half_to_float(src[1]);
306 texel[BCOMP] = _mesa_half_to_float(src[2]);
307 texel[ACOMP] = _mesa_half_to_float(src[3]);
308 }
309
310 #if DIM == 3
311 static void store_texel_rgba_f16(struct gl_texture_image *texImage,
312 GLint i, GLint j, GLint k, const void *texel)
313 {
314 const GLfloat *depth = (const GLfloat *) texel;
315 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
316 dst[0] = _mesa_float_to_half(*depth);
317 }
318 #endif
319
320 /* MESA_FORMAT_RGB_F32 *******************************************************/
321
322 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
323 * returning 4 GLfloats.
324 */
325 static void FETCH(f_rgb_f32)( const struct gl_texture_image *texImage,
326 GLint i, GLint j, GLint k, GLfloat *texel )
327 {
328 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
329 texel[RCOMP] = src[0];
330 texel[GCOMP] = src[1];
331 texel[BCOMP] = src[2];
332 texel[ACOMP] = 1.0F;
333 }
334
335 #if DIM == 3
336 static void store_texel_rgb_f32(struct gl_texture_image *texImage,
337 GLint i, GLint j, GLint k, const void *texel)
338 {
339 const GLfloat *depth = (const GLfloat *) texel;
340 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
341 dst[0] = *depth;
342 }
343 #endif
344
345
346 /* MESA_FORMAT_RGB_F16 *******************************************************/
347
348 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
349 * returning 4 GLfloats.
350 */
351 static void FETCH(f_rgb_f16)( const struct gl_texture_image *texImage,
352 GLint i, GLint j, GLint k, GLfloat *texel )
353 {
354 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
355 texel[RCOMP] = _mesa_half_to_float(src[0]);
356 texel[GCOMP] = _mesa_half_to_float(src[1]);
357 texel[BCOMP] = _mesa_half_to_float(src[2]);
358 texel[ACOMP] = 1.0F;
359 }
360
361 #if DIM == 3
362 static void store_texel_rgb_f16(struct gl_texture_image *texImage,
363 GLint i, GLint j, GLint k, const void *texel)
364 {
365 const GLfloat *depth = (const GLfloat *) texel;
366 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
367 dst[0] = _mesa_float_to_half(*depth);
368 }
369 #endif
370
371
372 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
373
374 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
375 * returning 4 GLfloats.
376 */
377 static void FETCH(f_alpha_f32)( const struct gl_texture_image *texImage,
378 GLint i, GLint j, GLint k, GLfloat *texel )
379 {
380 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
381 texel[RCOMP] =
382 texel[GCOMP] =
383 texel[BCOMP] = 0.0F;
384 texel[ACOMP] = src[0];
385 }
386
387 #if DIM == 3
388 static void store_texel_alpha_f32(struct gl_texture_image *texImage,
389 GLint i, GLint j, GLint k, const void *texel)
390 {
391 const GLfloat *rgba = (const GLfloat *) texel;
392 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
393 dst[0] = rgba[ACOMP];
394 }
395 #endif
396
397
398 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
399
400 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
401 * returning 4 GLfloats.
402 */
403 static void FETCH(f_alpha_f16)( const struct gl_texture_image *texImage,
404 GLint i, GLint j, GLint k, GLfloat *texel )
405 {
406 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
407 texel[RCOMP] =
408 texel[GCOMP] =
409 texel[BCOMP] = 0.0F;
410 texel[ACOMP] = _mesa_half_to_float(src[0]);
411 }
412
413 #if DIM == 3
414 static void store_texel_alpha_f16(struct gl_texture_image *texImage,
415 GLint i, GLint j, GLint k, const void *texel)
416 {
417 const GLfloat *rgba = (const GLfloat *) texel;
418 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
419 dst[0] = _mesa_float_to_half(rgba[ACOMP]);
420 }
421 #endif
422
423
424 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
425
426 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
427 * returning 4 GLfloats.
428 */
429 static void FETCH(f_luminance_f32)( const struct gl_texture_image *texImage,
430 GLint i, GLint j, GLint k, GLfloat *texel )
431 {
432 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
433 texel[RCOMP] =
434 texel[GCOMP] =
435 texel[BCOMP] = src[0];
436 texel[ACOMP] = 1.0F;
437 }
438
439 #if DIM == 3
440 static void store_texel_luminance_f32(struct gl_texture_image *texImage,
441 GLint i, GLint j, GLint k, const void *texel)
442 {
443 const GLfloat *rgba = (const GLfloat *) texel;
444 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
445 dst[0] = rgba[RCOMP];
446 }
447 #endif
448
449
450 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
451
452 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
453 * returning 4 GLfloats.
454 */
455 static void FETCH(f_luminance_f16)( const struct gl_texture_image *texImage,
456 GLint i, GLint j, GLint k, GLfloat *texel )
457 {
458 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
459 texel[RCOMP] =
460 texel[GCOMP] =
461 texel[BCOMP] = _mesa_half_to_float(src[0]);
462 texel[ACOMP] = 1.0F;
463 }
464
465 #if DIM == 3
466 static void store_texel_luminance_f16(struct gl_texture_image *texImage,
467 GLint i, GLint j, GLint k, const void *texel)
468 {
469 const GLfloat *rgba = (const GLfloat *) texel;
470 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
471 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
472 }
473 #endif
474
475
476 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
477
478 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
479 * returning 4 GLfloats.
480 */
481 static void FETCH(f_luminance_alpha_f32)( const struct gl_texture_image *texImage,
482 GLint i, GLint j, GLint k, GLfloat *texel )
483 {
484 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
485 texel[RCOMP] =
486 texel[GCOMP] =
487 texel[BCOMP] = src[0];
488 texel[ACOMP] = src[1];
489 }
490
491 #if DIM == 3
492 static void store_texel_luminance_alpha_f32(struct gl_texture_image *texImage,
493 GLint i, GLint j, GLint k, const void *texel)
494 {
495 const GLfloat *rgba = (const GLfloat *) texel;
496 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
497 dst[0] = rgba[RCOMP];
498 dst[1] = rgba[ACOMP];
499 }
500 #endif
501
502
503 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
504
505 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
506 * returning 4 GLfloats.
507 */
508 static void FETCH(f_luminance_alpha_f16)( const struct gl_texture_image *texImage,
509 GLint i, GLint j, GLint k, GLfloat *texel )
510 {
511 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
512 texel[RCOMP] =
513 texel[GCOMP] =
514 texel[BCOMP] = _mesa_half_to_float(src[0]);
515 texel[ACOMP] = _mesa_half_to_float(src[1]);
516 }
517
518 #if DIM == 3
519 static void store_texel_luminance_alpha_f16(struct gl_texture_image *texImage,
520 GLint i, GLint j, GLint k, const void *texel)
521 {
522 const GLfloat *rgba = (const GLfloat *) texel;
523 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
524 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
525 dst[1] = _mesa_float_to_half(rgba[ACOMP]);
526 }
527 #endif
528
529
530 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
531
532 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
533 * returning 4 GLfloats.
534 */
535 static void FETCH(f_intensity_f32)( const struct gl_texture_image *texImage,
536 GLint i, GLint j, GLint k, GLfloat *texel )
537 {
538 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
539 texel[RCOMP] =
540 texel[GCOMP] =
541 texel[BCOMP] =
542 texel[ACOMP] = src[0];
543 }
544
545 #if DIM == 3
546 static void store_texel_intensity_f32(struct gl_texture_image *texImage,
547 GLint i, GLint j, GLint k, const void *texel)
548 {
549 const GLfloat *rgba = (const GLfloat *) texel;
550 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
551 dst[0] = rgba[RCOMP];
552 }
553 #endif
554
555
556 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
557
558 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
559 * returning 4 GLfloats.
560 */
561 static void FETCH(f_intensity_f16)( const struct gl_texture_image *texImage,
562 GLint i, GLint j, GLint k, GLfloat *texel )
563 {
564 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
565 texel[RCOMP] =
566 texel[GCOMP] =
567 texel[BCOMP] =
568 texel[ACOMP] = _mesa_half_to_float(src[0]);
569 }
570
571 #if DIM == 3
572 static void store_texel_intensity_f16(struct gl_texture_image *texImage,
573 GLint i, GLint j, GLint k, const void *texel)
574 {
575 const GLfloat *rgba = (const GLfloat *) texel;
576 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
577 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
578 }
579 #endif
580
581
582
583
584 /*
585 * Begin Hardware formats
586 */
587
588 /* MESA_FORMAT_RGBA8888 ******************************************************/
589
590 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
591 static void FETCH(f_rgba8888)( const struct gl_texture_image *texImage,
592 GLint i, GLint j, GLint k, GLfloat *texel )
593 {
594 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
595 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
596 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
597 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
598 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
599 }
600
601
602
603 #if DIM == 3
604 static void store_texel_rgba8888(struct gl_texture_image *texImage,
605 GLint i, GLint j, GLint k, const void *texel)
606 {
607 const GLubyte *rgba = (const GLubyte *) texel;
608 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
609 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
610 }
611 #endif
612
613
614 /* MESA_FORMAT_RGBA888_REV ***************************************************/
615
616 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
617 static void FETCH(f_rgba8888_rev)( const struct gl_texture_image *texImage,
618 GLint i, GLint j, GLint k, GLfloat *texel )
619 {
620 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
621 texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
622 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
623 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
624 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
625 }
626
627 #if DIM == 3
628 static void store_texel_rgba8888_rev(struct gl_texture_image *texImage,
629 GLint i, GLint j, GLint k, const void *texel)
630 {
631 const GLubyte *rgba = (const GLubyte *) texel;
632 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
633 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
634 }
635 #endif
636
637
638 /* MESA_FORMAT_ARGB8888 ******************************************************/
639
640 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
641 static void FETCH(f_argb8888)( const struct gl_texture_image *texImage,
642 GLint i, GLint j, GLint k, GLfloat *texel )
643 {
644 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
645 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
646 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
647 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
648 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
649 }
650
651 #if DIM == 3
652 static void store_texel_argb8888(struct gl_texture_image *texImage,
653 GLint i, GLint j, GLint k, const void *texel)
654 {
655 const GLubyte *rgba = (const GLubyte *) texel;
656 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
657 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
658 }
659 #endif
660
661
662 /* MESA_FORMAT_ARGB8888_REV **************************************************/
663
664 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
665 static void FETCH(f_argb8888_rev)( const struct gl_texture_image *texImage,
666 GLint i, GLint j, GLint k, GLfloat *texel )
667 {
668 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
669 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
670 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
671 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
672 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
673 }
674
675 #if DIM == 3
676 static void store_texel_argb8888_rev(struct gl_texture_image *texImage,
677 GLint i, GLint j, GLint k, const void *texel)
678 {
679 const GLubyte *rgba = (const GLubyte *) texel;
680 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
681 *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], rgba[ACOMP]);
682 }
683 #endif
684
685
686 /* MESA_FORMAT_RGB888 ********************************************************/
687
688 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
689 static void FETCH(f_rgb888)( const struct gl_texture_image *texImage,
690 GLint i, GLint j, GLint k, GLfloat *texel )
691 {
692 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
693 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
694 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
695 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
696 texel[ACOMP] = 1.0F;
697 }
698
699 #if DIM == 3
700 static void store_texel_rgb888(struct gl_texture_image *texImage,
701 GLint i, GLint j, GLint k, const void *texel)
702 {
703 const GLubyte *rgba = (const GLubyte *) texel;
704 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
705 dst[0] = rgba[BCOMP];
706 dst[1] = rgba[GCOMP];
707 dst[2] = rgba[RCOMP];
708 }
709 #endif
710
711
712 /* MESA_FORMAT_BGR888 ********************************************************/
713
714 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
715 static void FETCH(f_bgr888)( const struct gl_texture_image *texImage,
716 GLint i, GLint j, GLint k, GLfloat *texel )
717 {
718 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
719 texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
720 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
721 texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
722 texel[ACOMP] = 1.0F;
723 }
724
725 #if DIM == 3
726 static void store_texel_bgr888(struct gl_texture_image *texImage,
727 GLint i, GLint j, GLint k, const void *texel)
728 {
729 const GLubyte *rgba = (const GLubyte *) texel;
730 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
731 dst[0] = rgba[RCOMP];
732 dst[1] = rgba[GCOMP];
733 dst[2] = rgba[BCOMP];
734 }
735 #endif
736
737
738 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
739 instead of slow (g << 2) * 255 / 252 (always rounds down) */
740
741 /* MESA_FORMAT_RGB565 ********************************************************/
742
743 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
744 static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
745 GLint i, GLint j, GLint k, GLfloat *texel )
746 {
747 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
748 const GLushort s = *src;
749 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
750 texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
751 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
752 texel[ACOMP] = 1.0F;
753 }
754
755 #if DIM == 3
756 static void store_texel_rgb565(struct gl_texture_image *texImage,
757 GLint i, GLint j, GLint k, const void *texel)
758 {
759 const GLubyte *rgba = (const GLubyte *) texel;
760 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
761 *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
762 }
763 #endif
764
765
766 /* MESA_FORMAT_RGB565_REV ****************************************************/
767
768 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
769 static void FETCH(f_rgb565_rev)( const struct gl_texture_image *texImage,
770 GLint i, GLint j, GLint k, GLfloat *texel )
771 {
772 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
773 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
774 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
775 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
776 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
777 texel[ACOMP] = 1.0F;
778 }
779
780 #if DIM == 3
781 static void store_texel_rgb565_rev(struct gl_texture_image *texImage,
782 GLint i, GLint j, GLint k, const void *texel)
783 {
784 const GLubyte *rgba = (const GLubyte *) texel;
785 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
786 *dst = PACK_COLOR_565(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
787 }
788 #endif
789
790 /* MESA_FORMAT_RGBA4444 ******************************************************/
791
792 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
793 static void FETCH(f_rgba4444)( const struct gl_texture_image *texImage,
794 GLint i, GLint j, GLint k, GLfloat *texel )
795 {
796 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
797 const GLushort s = *src;
798 texel[RCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
799 texel[GCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
800 texel[BCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
801 texel[ACOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
802 }
803
804 #if DIM == 3
805 static void store_texel_rgba4444(struct gl_texture_image *texImage,
806 GLint i, GLint j, GLint k, const void *texel)
807 {
808 const GLubyte *rgba = (const GLubyte *) texel;
809 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
810 *dst = PACK_COLOR_4444(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
811 }
812 #endif
813
814
815 /* MESA_FORMAT_ARGB4444 ******************************************************/
816
817 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
818 static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
819 GLint i, GLint j, GLint k, GLfloat *texel )
820 {
821 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
822 const GLushort s = *src;
823 texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
824 texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
825 texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
826 texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
827 }
828
829 #if DIM == 3
830 static void store_texel_argb4444(struct gl_texture_image *texImage,
831 GLint i, GLint j, GLint k, const void *texel)
832 {
833 const GLubyte *rgba = (const GLubyte *) texel;
834 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
835 *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
836 }
837 #endif
838
839
840 /* MESA_FORMAT_ARGB4444_REV **************************************************/
841
842 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
843 static void FETCH(f_argb4444_rev)( const struct gl_texture_image *texImage,
844 GLint i, GLint j, GLint k, GLfloat *texel )
845 {
846 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
847 texel[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
848 texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
849 texel[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
850 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
851 }
852
853 #if DIM == 3
854 static void store_texel_argb4444_rev(struct gl_texture_image *texImage,
855 GLint i, GLint j, GLint k, const void *texel)
856 {
857 const GLubyte *rgba = (const GLubyte *) texel;
858 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
859 *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
860 }
861 #endif
862
863 /* MESA_FORMAT_RGBA5551 ******************************************************/
864
865 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
866 static void FETCH(f_rgba5551)( const struct gl_texture_image *texImage,
867 GLint i, GLint j, GLint k, GLfloat *texel )
868 {
869 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
870 const GLushort s = *src;
871 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
872 texel[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
873 texel[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
874 texel[ACOMP] = ((s ) & 0x01) * 1.0F;
875 }
876
877 #if DIM == 3
878 static void store_texel_rgba5551(struct gl_texture_image *texImage,
879 GLint i, GLint j, GLint k, const void *texel)
880 {
881 const GLubyte *rgba = (const GLubyte *) texel;
882 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
883 *dst = PACK_COLOR_5551(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
884 }
885 #endif
886
887 /* MESA_FORMAT_ARGB1555 ******************************************************/
888
889 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
890 static void FETCH(f_argb1555)( const struct gl_texture_image *texImage,
891 GLint i, GLint j, GLint k, GLfloat *texel )
892 {
893 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
894 const GLushort s = *src;
895 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
896 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
897 texel[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F);
898 texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
899 }
900
901 #if DIM == 3
902 static void store_texel_argb1555(struct gl_texture_image *texImage,
903 GLint i, GLint j, GLint k, const void *texel)
904 {
905 const GLubyte *rgba = (const GLubyte *) texel;
906 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
907 *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
908 }
909 #endif
910
911
912 /* MESA_FORMAT_ARGB1555_REV **************************************************/
913
914 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
915 static void FETCH(f_argb1555_rev)( const struct gl_texture_image *texImage,
916 GLint i, GLint j, GLint k, GLfloat *texel )
917 {
918 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
919 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
920 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
921 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
922 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
923 texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
924 }
925
926 #if DIM == 3
927 static void store_texel_argb1555_rev(struct gl_texture_image *texImage,
928 GLint i, GLint j, GLint k, const void *texel)
929 {
930 const GLubyte *rgba = (const GLubyte *) texel;
931 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
932 *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
933 }
934 #endif
935
936
937 /* MESA_FORMAT_AL88 **********************************************************/
938
939 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
940 static void FETCH(f_al88)( const struct gl_texture_image *texImage,
941 GLint i, GLint j, GLint k, GLfloat *texel )
942 {
943 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
944 texel[RCOMP] =
945 texel[GCOMP] =
946 texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
947 texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
948 }
949
950 #if DIM == 3
951 static void store_texel_al88(struct gl_texture_image *texImage,
952 GLint i, GLint j, GLint k, const void *texel)
953 {
954 const GLubyte *rgba = (const GLubyte *) texel;
955 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
956 *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
957 }
958 #endif
959
960
961 /* MESA_FORMAT_AL88_REV ******************************************************/
962
963 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
964 static void FETCH(f_al88_rev)( const struct gl_texture_image *texImage,
965 GLint i, GLint j, GLint k, GLfloat *texel )
966 {
967 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
968 texel[RCOMP] =
969 texel[GCOMP] =
970 texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
971 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
972 }
973
974 #if DIM == 3
975 static void store_texel_al88_rev(struct gl_texture_image *texImage,
976 GLint i, GLint j, GLint k, const void *texel)
977 {
978 const GLubyte *rgba = (const GLubyte *) texel;
979 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
980 *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
981 }
982 #endif
983
984
985 /* MESA_FORMAT_RGB332 ********************************************************/
986
987 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
988 static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
989 GLint i, GLint j, GLint k, GLfloat *texel )
990 {
991 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
992 const GLubyte s = *src;
993 texel[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
994 texel[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
995 texel[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F);
996 texel[ACOMP] = 1.0F;
997 }
998
999 #if DIM == 3
1000 static void store_texel_rgb332(struct gl_texture_image *texImage,
1001 GLint i, GLint j, GLint k, const void *texel)
1002 {
1003 const GLubyte *rgba = (const GLubyte *) texel;
1004 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1005 *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1006 }
1007 #endif
1008
1009
1010 /* MESA_FORMAT_A8 ************************************************************/
1011
1012 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1013 static void FETCH(f_a8)( const struct gl_texture_image *texImage,
1014 GLint i, GLint j, GLint k, GLfloat *texel )
1015 {
1016 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1017 texel[RCOMP] =
1018 texel[GCOMP] =
1019 texel[BCOMP] = 0.0F;
1020 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1021 }
1022
1023 #if DIM == 3
1024 static void store_texel_a8(struct gl_texture_image *texImage,
1025 GLint i, GLint j, GLint k, const void *texel)
1026 {
1027 const GLubyte *rgba = (const GLubyte *) texel;
1028 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1029 *dst = rgba[ACOMP];
1030 }
1031 #endif
1032
1033
1034 /* MESA_FORMAT_L8 ************************************************************/
1035
1036 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1037 static void FETCH(f_l8)( const struct gl_texture_image *texImage,
1038 GLint i, GLint j, GLint k, GLfloat *texel )
1039 {
1040 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1041 texel[RCOMP] =
1042 texel[GCOMP] =
1043 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
1044 texel[ACOMP] = 1.0F;
1045 }
1046
1047 #if DIM == 3
1048 static void store_texel_l8(struct gl_texture_image *texImage,
1049 GLint i, GLint j, GLint k, const void *texel)
1050 {
1051 const GLubyte *rgba = (const GLubyte *) texel;
1052 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1053 *dst = rgba[RCOMP];
1054 }
1055 #endif
1056
1057
1058 /* MESA_FORMAT_I8 ************************************************************/
1059
1060 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1061 static void FETCH(f_i8)( const struct gl_texture_image *texImage,
1062 GLint i, GLint j, GLint k, GLfloat *texel )
1063 {
1064 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1065 texel[RCOMP] =
1066 texel[GCOMP] =
1067 texel[BCOMP] =
1068 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1069 }
1070
1071 #if DIM == 3
1072 static void store_texel_i8(struct gl_texture_image *texImage,
1073 GLint i, GLint j, GLint k, const void *texel)
1074 {
1075 const GLubyte *rgba = (const GLubyte *) texel;
1076 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1077 *dst = rgba[RCOMP];
1078 }
1079 #endif
1080
1081
1082 /* MESA_FORMAT_CI8 ***********************************************************/
1083
1084 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1085 * color table, and return 4 GLchans.
1086 */
1087 static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
1088 GLint i, GLint j, GLint k, GLfloat *texel )
1089 {
1090 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1091 const struct gl_color_table *palette;
1092 GLuint index;
1093 GET_CURRENT_CONTEXT(ctx);
1094
1095 if (ctx->Texture.SharedPalette) {
1096 palette = &ctx->Texture.Palette;
1097 }
1098 else {
1099 palette = &texImage->TexObject->Palette;
1100 }
1101 if (palette->Size == 0)
1102 return; /* undefined results */
1103
1104 /* Mask the index against size of palette to avoid going out of bounds */
1105 index = (*src) & (palette->Size - 1);
1106
1107 {
1108 const GLfloat *table = palette->TableF;
1109 switch (palette->_BaseFormat) {
1110 case GL_ALPHA:
1111 texel[RCOMP] =
1112 texel[GCOMP] =
1113 texel[BCOMP] = 0.0F;
1114 texel[ACOMP] = table[index];
1115 break;
1116 case GL_LUMINANCE:
1117 texel[RCOMP] =
1118 texel[GCOMP] =
1119 texel[BCOMP] = table[index];
1120 texel[ACOMP] = 1.0F;
1121 break;
1122 case GL_INTENSITY:
1123 texel[RCOMP] =
1124 texel[GCOMP] =
1125 texel[BCOMP] =
1126 texel[ACOMP] = table[index];
1127 break;
1128 case GL_LUMINANCE_ALPHA:
1129 texel[RCOMP] =
1130 texel[GCOMP] =
1131 texel[BCOMP] = table[index * 2 + 0];
1132 texel[ACOMP] = table[index * 2 + 1];
1133 break;
1134 case GL_RGB:
1135 texel[RCOMP] = table[index * 3 + 0];
1136 texel[GCOMP] = table[index * 3 + 1];
1137 texel[BCOMP] = table[index * 3 + 2];
1138 texel[ACOMP] = 1.0F;
1139 break;
1140 case GL_RGBA:
1141 texel[RCOMP] = table[index * 4 + 0];
1142 texel[GCOMP] = table[index * 4 + 1];
1143 texel[BCOMP] = table[index * 4 + 2];
1144 texel[ACOMP] = table[index * 4 + 3];
1145 break;
1146 default:
1147 _mesa_problem(ctx, "Bad palette format in fetch_texel_ci8");
1148 return;
1149 }
1150 }
1151 }
1152
1153 #if DIM == 3
1154 static void store_texel_ci8(struct gl_texture_image *texImage,
1155 GLint i, GLint j, GLint k, const void *texel)
1156 {
1157 const GLubyte *index = (const GLubyte *) texel;
1158 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1159 *dst = *index;
1160 }
1161 #endif
1162
1163
1164 #if FEATURE_EXT_texture_sRGB
1165
1166 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1167 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1168 static void FETCH(srgb8)(const struct gl_texture_image *texImage,
1169 GLint i, GLint j, GLint k, GLfloat *texel )
1170 {
1171 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1172 texel[RCOMP] = nonlinear_to_linear(src[2]);
1173 texel[GCOMP] = nonlinear_to_linear(src[1]);
1174 texel[BCOMP] = nonlinear_to_linear(src[0]);
1175 texel[ACOMP] = 1.0F;
1176 }
1177
1178 #if DIM == 3
1179 static void store_texel_srgb8(struct gl_texture_image *texImage,
1180 GLint i, GLint j, GLint k, const void *texel)
1181 {
1182 const GLubyte *rgba = (const GLubyte *) texel;
1183 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1184 dst[0] = rgba[BCOMP]; /* no conversion */
1185 dst[1] = rgba[GCOMP];
1186 dst[2] = rgba[RCOMP];
1187 }
1188 #endif
1189
1190 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1191 static void FETCH(srgba8)(const struct gl_texture_image *texImage,
1192 GLint i, GLint j, GLint k, GLfloat *texel )
1193 {
1194 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1195 texel[RCOMP] = nonlinear_to_linear( (s >> 24) );
1196 texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1197 texel[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1198 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */
1199 }
1200
1201 #if DIM == 3
1202 static void store_texel_srgba8(struct gl_texture_image *texImage,
1203 GLint i, GLint j, GLint k, const void *texel)
1204 {
1205 const GLubyte *rgba = (const GLubyte *) texel;
1206 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1207 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1208 }
1209 #endif
1210
1211 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1212 static void FETCH(sargb8)(const struct gl_texture_image *texImage,
1213 GLint i, GLint j, GLint k, GLfloat *texel )
1214 {
1215 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1216 texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1217 texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1218 texel[BCOMP] = nonlinear_to_linear( (s ) & 0xff );
1219 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
1220 }
1221
1222 #if DIM == 3
1223 static void store_texel_sargb8(struct gl_texture_image *texImage,
1224 GLint i, GLint j, GLint k, const void *texel)
1225 {
1226 const GLubyte *rgba = (const GLubyte *) texel;
1227 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1228 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1229 }
1230 #endif
1231
1232 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1233 static void FETCH(sl8)(const struct gl_texture_image *texImage,
1234 GLint i, GLint j, GLint k, GLfloat *texel )
1235 {
1236 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1237 texel[RCOMP] =
1238 texel[GCOMP] =
1239 texel[BCOMP] = nonlinear_to_linear(src[0]);
1240 texel[ACOMP] = 1.0F;
1241 }
1242
1243 #if DIM == 3
1244 static void store_texel_sl8(struct gl_texture_image *texImage,
1245 GLint i, GLint j, GLint k, const void *texel)
1246 {
1247 const GLubyte *rgba = (const GLubyte *) texel;
1248 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1249 dst[0] = rgba[RCOMP];
1250 }
1251 #endif
1252
1253 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1254 static void FETCH(sla8)(const struct gl_texture_image *texImage,
1255 GLint i, GLint j, GLint k, GLfloat *texel )
1256 {
1257 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1258 texel[RCOMP] =
1259 texel[GCOMP] =
1260 texel[BCOMP] = nonlinear_to_linear(src[0]);
1261 texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
1262 }
1263
1264 #if DIM == 3
1265 static void store_texel_sla8(struct gl_texture_image *texImage,
1266 GLint i, GLint j, GLint k, const void *texel)
1267 {
1268 const GLubyte *rgba = (const GLubyte *) texel;
1269 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1270 dst[0] = rgba[RCOMP];
1271 dst[1] = rgba[ACOMP];
1272 }
1273 #endif
1274
1275 #endif /* FEATURE_EXT_texture_sRGB */
1276
1277
1278 /* MESA_FORMAT_DUDV8 ********************************************************/
1279
1280 /* this format by definition produces 0,0,0,1 as rgba values,
1281 however we'll return the dudv values as rg and fix up elsewhere */
1282 static void FETCH(dudv8)(const struct gl_texture_image *texImage,
1283 GLint i, GLint j, GLint k, GLfloat *texel )
1284 {
1285 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 2);
1286 texel[RCOMP] = BYTE_TO_FLOAT(src[0]);
1287 texel[GCOMP] = BYTE_TO_FLOAT(src[1]);
1288 texel[BCOMP] = 0;
1289 texel[ACOMP] = 0;
1290 }
1291
1292 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1293
1294 static void FETCH(signed_rgba8888)( const struct gl_texture_image *texImage,
1295 GLint i, GLint j, GLint k, GLfloat *texel )
1296 {
1297 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1298 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (s >> 24) );
1299 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (s >> 16) & 0xff );
1300 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (s >> 8) & 0xff );
1301 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (s ) & 0xff );
1302 }
1303
1304 #if DIM == 3
1305 static void store_texel_signed_rgba8888(struct gl_texture_image *texImage,
1306 GLint i, GLint j, GLint k, const void *texel)
1307 {
1308 const GLbyte *rgba = (const GLbyte *) texel;
1309 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1310 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1311 }
1312 #endif
1313
1314 static void FETCH(signed_rgba8888_rev)( const struct gl_texture_image *texImage,
1315 GLint i, GLint j, GLint k, GLfloat *texel )
1316 {
1317 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1318 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (s ) & 0xff );
1319 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (s >> 8) & 0xff );
1320 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (s >> 16) & 0xff );
1321 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (s >> 24) );
1322 }
1323
1324 #if DIM == 3
1325 static void store_texel_signed_rgba8888_rev(struct gl_texture_image *texImage,
1326 GLint i, GLint j, GLint k, const void *texel)
1327 {
1328 const GLubyte *rgba = (const GLubyte *) texel;
1329 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1330 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1331 }
1332 #endif
1333
1334
1335
1336 /* MESA_FORMAT_YCBCR *********************************************************/
1337
1338 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
1339 * We convert YCbCr to RGB here.
1340 */
1341 static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
1342 GLint i, GLint j, GLint k, GLfloat *texel )
1343 {
1344 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1345 const GLushort *src1 = src0 + 1; /* odd */
1346 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1347 const GLubyte cb = *src0 & 0xff; /* chroma U */
1348 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1349 const GLubyte cr = *src1 & 0xff; /* chroma V */
1350 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1351 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1352 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1353 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1354 r *= (1.0F / 255.0F);
1355 g *= (1.0F / 255.0F);
1356 b *= (1.0F / 255.0F);
1357 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1358 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1359 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1360 texel[ACOMP] = 1.0F;
1361 }
1362
1363 #if DIM == 3
1364 static void store_texel_ycbcr(struct gl_texture_image *texImage,
1365 GLint i, GLint j, GLint k, const void *texel)
1366 {
1367 (void) texImage;
1368 (void) i;
1369 (void) j;
1370 (void) k;
1371 (void) texel;
1372 /* XXX to do */
1373 }
1374 #endif
1375
1376
1377 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1378
1379 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
1380 * We convert YCbCr to RGB here.
1381 */
1382 static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
1383 GLint i, GLint j, GLint k, GLfloat *texel )
1384 {
1385 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1386 const GLushort *src1 = src0 + 1; /* odd */
1387 const GLubyte y0 = *src0 & 0xff; /* luminance */
1388 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1389 const GLubyte y1 = *src1 & 0xff; /* luminance */
1390 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1391 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1392 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1393 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1394 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1395 r *= (1.0F / 255.0F);
1396 g *= (1.0F / 255.0F);
1397 b *= (1.0F / 255.0F);
1398 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1399 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1400 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1401 texel[ACOMP] = 1.0F;
1402 }
1403
1404 #if DIM == 3
1405 static void store_texel_ycbcr_rev(struct gl_texture_image *texImage,
1406 GLint i, GLint j, GLint k, const void *texel)
1407 {
1408 (void) texImage;
1409 (void) i;
1410 (void) j;
1411 (void) k;
1412 (void) texel;
1413 /* XXX to do */
1414 }
1415 #endif
1416
1417
1418 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1419
1420 static void FETCH(f_z24_s8)( const struct gl_texture_image *texImage,
1421 GLint i, GLint j, GLint k, GLfloat *texel )
1422 {
1423 /* only return Z, not stencil data */
1424 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1425 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1426 texel[0] = ((*src) >> 8) * scale;
1427 ASSERT(texImage->TexFormat->MesaFormat == MESA_FORMAT_Z24_S8);
1428 ASSERT(texel[0] >= 0.0F);
1429 ASSERT(texel[0] <= 1.0F);
1430 }
1431
1432 #if DIM == 3
1433 static void store_texel_z24_s8(struct gl_texture_image *texImage,
1434 GLint i, GLint j, GLint k, const void *texel)
1435 {
1436 /* only store Z, not stencil */
1437 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1438 GLfloat depth = *((GLfloat *) texel);
1439 GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
1440 *dst = zi | (*dst & 0xff);
1441 }
1442 #endif
1443
1444
1445 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1446
1447 static void FETCH(f_s8_z24)( const struct gl_texture_image *texImage,
1448 GLint i, GLint j, GLint k, GLfloat *texel )
1449 {
1450 /* only return Z, not stencil data */
1451 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1452 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1453 texel[0] = ((*src) & 0x00ffffff) * scale;
1454 ASSERT(texImage->TexFormat->MesaFormat == MESA_FORMAT_S8_Z24);
1455 ASSERT(texel[0] >= 0.0F);
1456 ASSERT(texel[0] <= 1.0F);
1457 }
1458
1459 #if DIM == 3
1460 static void store_texel_s8_z24(struct gl_texture_image *texImage,
1461 GLint i, GLint j, GLint k, const void *texel)
1462 {
1463 /* only store Z, not stencil */
1464 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1465 GLfloat depth = *((GLfloat *) texel);
1466 GLuint zi = (GLuint) (depth * 0xffffff);
1467 *dst = zi | (*dst & 0xff000000);
1468 }
1469 #endif
1470
1471
1472 #undef TEXEL_ADDR
1473 #undef DIM
1474 #undef FETCH