fix broken z24_s8 fetcher
[mesa.git] / src / mesa / main / texformat_tmp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * \file texformat_tmp.h
28 * Texel fetch functions template.
29 *
30 * This template file is used by texformat.c to generate texel fetch functions
31 * for 1-D, 2-D and 3-D texture images.
32 *
33 * It should be expanded by defining \p DIM as the number texture dimensions
34 * (1, 2 or 3). According to the value of \p DIM a series of macros is defined
35 * for the texel lookup in the gl_texture_image::Data.
36 *
37 * \sa texformat.c and FetchTexel.
38 *
39 * \author Gareth Hughes
40 * \author Brian Paul
41 */
42
43
44 #if DIM == 1
45
46 #define TEXEL_ADDR( type, image, i, j, k, size ) \
47 ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
48
49 #define FETCH(x) fetch_texel_1d_##x
50
51 #elif DIM == 2
52
53 #define TEXEL_ADDR( type, image, i, j, k, size ) \
54 ((void) (k), \
55 ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
56
57 #define FETCH(x) fetch_texel_2d_##x
58
59 #elif DIM == 3
60
61 #define TEXEL_ADDR( type, image, i, j, k, size ) \
62 ((type *)(image)->Data + (((image)->Height * (k) + (j)) * \
63 (image)->RowStride + (i)) * (size))
64
65 #define FETCH(x) fetch_texel_3d_##x
66
67 #else
68 #error illegal number of texture dimensions
69 #endif
70
71
72 /* MESA_FORMAT_RGBA **********************************************************/
73
74 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLchans */
75 static void FETCH(rgba)( const struct gl_texture_image *texImage,
76 GLint i, GLint j, GLint k, GLchan *texel )
77 {
78 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 4);
79 COPY_CHAN4( texel, src );
80 }
81
82 /* Fetch texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
83 static void FETCH(f_rgba)( const struct gl_texture_image *texImage,
84 GLint i, GLint j, GLint k, GLfloat *texel )
85 {
86 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 4);
87 texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
88 texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
89 texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
90 texel[ACOMP] = CHAN_TO_FLOAT(src[3]);
91 }
92
93 #if DIM == 3
94 /* Store a GLchan RGBA texel */
95 static void store_texel_rgba(struct gl_texture_image *texImage,
96 GLint i, GLint j, GLint k, const void *texel)
97 {
98 const GLchan *rgba = (const GLchan *) texel;
99 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 4);
100 dst[0] = rgba[RCOMP];
101 dst[1] = rgba[GCOMP];
102 dst[2] = rgba[BCOMP];
103 dst[3] = rgba[ACOMP];
104 }
105 #endif
106
107 /* MESA_FORMAT_RGB ***********************************************************/
108
109 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLchans */
110 static void FETCH(rgb)( const struct gl_texture_image *texImage,
111 GLint i, GLint j, GLint k, GLchan *texel )
112 {
113 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 3);
114 texel[RCOMP] = src[0];
115 texel[GCOMP] = src[1];
116 texel[BCOMP] = src[2];
117 texel[ACOMP] = CHAN_MAX;
118 }
119
120 /* Fetch texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
121 static void FETCH(f_rgb)( const struct gl_texture_image *texImage,
122 GLint i, GLint j, GLint k, GLfloat *texel )
123 {
124 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 3);
125 texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
126 texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
127 texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
128 texel[ACOMP] = 1.0F;
129 }
130
131 #if DIM == 3
132 static void store_texel_rgb(struct gl_texture_image *texImage,
133 GLint i, GLint j, GLint k, const void *texel)
134 {
135 const GLchan *rgba = (const GLchan *) texel;
136 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 3);
137 dst[0] = rgba[RCOMP];
138 dst[1] = rgba[GCOMP];
139 dst[2] = rgba[BCOMP];
140 }
141 #endif
142
143 /* MESA_FORMAT_ALPHA *********************************************************/
144
145 /* Fetch texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
146 static void FETCH(alpha)( const struct gl_texture_image *texImage,
147 GLint i, GLint j, GLint k, GLchan *texel )
148 {
149 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
150 texel[RCOMP] =
151 texel[GCOMP] =
152 texel[BCOMP] = 0;
153 texel[ACOMP] = src[0];
154 }
155
156 #if DIM == 3
157 static void store_texel_alpha(struct gl_texture_image *texImage,
158 GLint i, GLint j, GLint k, const void *texel)
159 {
160 const GLchan *rgba = (const GLchan *) texel;
161 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
162 dst[0] = rgba[ACOMP];
163 }
164 #endif
165
166 /* MESA_FORMAT_LUMINANCE *****************************************************/
167
168 /* Fetch texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
169 static void FETCH(luminance)( const struct gl_texture_image *texImage,
170 GLint i, GLint j, GLint k, GLchan *texel )
171 {
172 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
173 texel[RCOMP] =
174 texel[GCOMP] =
175 texel[BCOMP] = src[0];
176 texel[ACOMP] = CHAN_MAX;
177 }
178
179 #if DIM == 3
180 static void store_texel_luminance(struct gl_texture_image *texImage,
181 GLint i, GLint j, GLint k, const void *texel)
182 {
183 const GLchan *rgba = (const GLchan *) texel;
184 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
185 dst[0] = rgba[RCOMP];
186 }
187 #endif
188
189 /* MESA_FORMAT_LUMINANCE_ALPHA ***********************************************/
190
191 /* Fetch texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
192 static void FETCH(luminance_alpha)( const struct gl_texture_image *texImage,
193 GLint i, GLint j, GLint k, GLchan *texel )
194 {
195 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 2);
196 texel[RCOMP] = src[0];
197 texel[GCOMP] = src[0];
198 texel[BCOMP] = src[0];
199 texel[ACOMP] = src[1];
200 }
201
202 #if DIM == 3
203 static void store_texel_luminance_alpha(struct gl_texture_image *texImage,
204 GLint i, GLint j, GLint k, const void *texel)
205 {
206 const GLchan *rgba = (const GLchan *) texel;
207 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 2);
208 dst[0] = rgba[RCOMP];
209 dst[1] = rgba[ACOMP];
210 }
211 #endif
212
213 /* MESA_FORMAT_INTENSITY *****************************************************/
214
215 /* Fetch texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
216 static void FETCH(intensity)( const struct gl_texture_image *texImage,
217 GLint i, GLint j, GLint k, GLchan *texel )
218 {
219 const GLchan *src = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
220 texel[RCOMP] = src[0];
221 texel[GCOMP] = src[0];
222 texel[BCOMP] = src[0];
223 texel[ACOMP] = src[0];
224 }
225
226 #if DIM == 3
227 static void store_texel_intensity(struct gl_texture_image *texImage,
228 GLint i, GLint j, GLint k, const void *texel)
229 {
230 const GLchan *rgba = (const GLchan *) texel;
231 GLchan *dst = TEXEL_ADDR(GLchan, texImage, i, j, k, 1);
232 dst[0] = rgba[RCOMP];
233 }
234 #endif
235
236
237 /* MESA_FORMAT_DEPTH_COMPONENT_F32 *******************************************/
238
239 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
240 * returning 1 GLfloat.
241 * Note: no GLchan version of this function.
242 */
243 static void FETCH(f_depth_component_f32)( const struct gl_texture_image *texImage,
244 GLint i, GLint j, GLint k, GLfloat *texel )
245 {
246 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
247 texel[0] = src[0];
248 }
249
250 #if DIM == 3
251 static void store_texel_depth_component_f32(struct gl_texture_image *texImage,
252 GLint i, GLint j, GLint k, const void *texel)
253 {
254 const GLfloat *depth = (const GLfloat *) texel;
255 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
256 dst[0] = *depth;
257 }
258 #endif
259
260
261 /* MESA_FORMAT_DEPTH_COMPONENT16 *********************************************/
262
263 /* Fetch depth texel from 1D, 2D or 3D float32 DEPTH texture,
264 * returning 1 GLfloat.
265 * Note: no GLchan version of this function.
266 */
267 static void FETCH(f_depth_component16)(const struct gl_texture_image *texImage,
268 GLint i, GLint j, GLint k, GLfloat *texel )
269 {
270 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
271 texel[0] = src[0] * (1.0F / 65535.0F);
272 }
273
274 #if DIM == 3
275 static void store_texel_depth_component16(struct gl_texture_image *texImage,
276 GLint i, GLint j, GLint k, const void *texel)
277 {
278 const GLushort *depth = (const GLushort *) texel;
279 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
280 dst[0] = *depth;
281 }
282 #endif
283
284
285 /* MESA_FORMAT_RGBA_F32 ******************************************************/
286
287 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
288 */
289 static void FETCH(f_rgba_f32)( const struct gl_texture_image *texImage,
290 GLint i, GLint j, GLint k, GLfloat *texel )
291 {
292 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
293 texel[RCOMP] = src[0];
294 texel[GCOMP] = src[1];
295 texel[BCOMP] = src[2];
296 texel[ACOMP] = src[3];
297 }
298
299 #if DIM == 3
300 static void store_texel_rgba_f32(struct gl_texture_image *texImage,
301 GLint i, GLint j, GLint k, const void *texel)
302 {
303 const GLfloat *depth = (const GLfloat *) texel;
304 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
305 dst[0] = depth[RCOMP];
306 dst[1] = depth[GCOMP];
307 dst[2] = depth[BCOMP];
308 dst[3] = depth[ACOMP];
309 }
310 #endif
311
312
313 /* MESA_FORMAT_RGBA_F16 ******************************************************/
314
315 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
316 * returning 4 GLfloats.
317 */
318 static void FETCH(f_rgba_f16)( const struct gl_texture_image *texImage,
319 GLint i, GLint j, GLint k, GLfloat *texel )
320 {
321 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
322 texel[RCOMP] = _mesa_half_to_float(src[0]);
323 texel[GCOMP] = _mesa_half_to_float(src[1]);
324 texel[BCOMP] = _mesa_half_to_float(src[2]);
325 texel[ACOMP] = _mesa_half_to_float(src[3]);
326 }
327
328 #if DIM == 3
329 static void store_texel_rgba_f16(struct gl_texture_image *texImage,
330 GLint i, GLint j, GLint k, const void *texel)
331 {
332 const GLfloat *depth = (const GLfloat *) texel;
333 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
334 dst[0] = _mesa_float_to_half(*depth);
335 }
336 #endif
337
338 /* MESA_FORMAT_RGB_F32 *******************************************************/
339
340 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
341 * returning 4 GLfloats.
342 */
343 static void FETCH(f_rgb_f32)( const struct gl_texture_image *texImage,
344 GLint i, GLint j, GLint k, GLfloat *texel )
345 {
346 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
347 texel[RCOMP] = src[0];
348 texel[GCOMP] = src[1];
349 texel[BCOMP] = src[2];
350 texel[ACOMP] = 1.0F;
351 }
352
353 #if DIM == 3
354 static void store_texel_rgb_f32(struct gl_texture_image *texImage,
355 GLint i, GLint j, GLint k, const void *texel)
356 {
357 const GLfloat *depth = (const GLfloat *) texel;
358 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
359 dst[0] = *depth;
360 }
361 #endif
362
363
364 /* MESA_FORMAT_RGB_F16 *******************************************************/
365
366 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
367 * returning 4 GLfloats.
368 */
369 static void FETCH(f_rgb_f16)( const struct gl_texture_image *texImage,
370 GLint i, GLint j, GLint k, GLfloat *texel )
371 {
372 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
373 texel[RCOMP] = _mesa_half_to_float(src[0]);
374 texel[GCOMP] = _mesa_half_to_float(src[1]);
375 texel[BCOMP] = _mesa_half_to_float(src[2]);
376 texel[ACOMP] = 1.0F;
377 }
378
379 #if DIM == 3
380 static void store_texel_rgb_f16(struct gl_texture_image *texImage,
381 GLint i, GLint j, GLint k, const void *texel)
382 {
383 const GLfloat *depth = (const GLfloat *) texel;
384 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
385 dst[0] = _mesa_float_to_half(*depth);
386 }
387 #endif
388
389
390 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
391
392 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
393 * returning 4 GLfloats.
394 */
395 static void FETCH(f_alpha_f32)( const struct gl_texture_image *texImage,
396 GLint i, GLint j, GLint k, GLfloat *texel )
397 {
398 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
399 texel[RCOMP] =
400 texel[GCOMP] =
401 texel[BCOMP] = 0.0F;
402 texel[ACOMP] = src[0];
403 }
404
405 #if DIM == 3
406 static void store_texel_alpha_f32(struct gl_texture_image *texImage,
407 GLint i, GLint j, GLint k, const void *texel)
408 {
409 const GLfloat *rgba = (const GLfloat *) texel;
410 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
411 dst[0] = rgba[ACOMP];
412 }
413 #endif
414
415
416 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
417
418 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
419 * returning 4 GLfloats.
420 */
421 static void FETCH(f_alpha_f16)( const struct gl_texture_image *texImage,
422 GLint i, GLint j, GLint k, GLfloat *texel )
423 {
424 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
425 texel[RCOMP] =
426 texel[GCOMP] =
427 texel[BCOMP] = 0.0F;
428 texel[ACOMP] = _mesa_half_to_float(src[0]);
429 }
430
431 #if DIM == 3
432 static void store_texel_alpha_f16(struct gl_texture_image *texImage,
433 GLint i, GLint j, GLint k, const void *texel)
434 {
435 const GLfloat *rgba = (const GLfloat *) texel;
436 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
437 dst[0] = _mesa_float_to_half(rgba[ACOMP]);
438 }
439 #endif
440
441
442 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
443
444 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
445 * returning 4 GLfloats.
446 */
447 static void FETCH(f_luminance_f32)( const struct gl_texture_image *texImage,
448 GLint i, GLint j, GLint k, GLfloat *texel )
449 {
450 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
451 texel[RCOMP] =
452 texel[GCOMP] =
453 texel[BCOMP] = src[0];
454 texel[ACOMP] = 1.0F;
455 }
456
457 #if DIM == 3
458 static void store_texel_luminance_f32(struct gl_texture_image *texImage,
459 GLint i, GLint j, GLint k, const void *texel)
460 {
461 const GLfloat *rgba = (const GLfloat *) texel;
462 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
463 dst[0] = rgba[RCOMP];
464 }
465 #endif
466
467
468 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
469
470 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
471 * returning 4 GLfloats.
472 */
473 static void FETCH(f_luminance_f16)( const struct gl_texture_image *texImage,
474 GLint i, GLint j, GLint k, GLfloat *texel )
475 {
476 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
477 texel[RCOMP] =
478 texel[GCOMP] =
479 texel[BCOMP] = _mesa_half_to_float(src[0]);
480 texel[ACOMP] = 1.0F;
481 }
482
483 #if DIM == 3
484 static void store_texel_luminance_f16(struct gl_texture_image *texImage,
485 GLint i, GLint j, GLint k, const void *texel)
486 {
487 const GLfloat *rgba = (const GLfloat *) texel;
488 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
489 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
490 }
491 #endif
492
493
494 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
495
496 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
497 * returning 4 GLfloats.
498 */
499 static void FETCH(f_luminance_alpha_f32)( const struct gl_texture_image *texImage,
500 GLint i, GLint j, GLint k, GLfloat *texel )
501 {
502 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
503 texel[RCOMP] =
504 texel[GCOMP] =
505 texel[BCOMP] = src[0];
506 texel[ACOMP] = src[1];
507 }
508
509 #if DIM == 3
510 static void store_texel_luminance_alpha_f32(struct gl_texture_image *texImage,
511 GLint i, GLint j, GLint k, const void *texel)
512 {
513 const GLfloat *rgba = (const GLfloat *) texel;
514 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
515 dst[0] = rgba[RCOMP];
516 dst[1] = rgba[ACOMP];
517 }
518 #endif
519
520
521 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
522
523 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
524 * returning 4 GLfloats.
525 */
526 static void FETCH(f_luminance_alpha_f16)( const struct gl_texture_image *texImage,
527 GLint i, GLint j, GLint k, GLfloat *texel )
528 {
529 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
530 texel[RCOMP] =
531 texel[GCOMP] =
532 texel[BCOMP] = _mesa_half_to_float(src[0]);
533 texel[ACOMP] = _mesa_half_to_float(src[1]);
534 }
535
536 #if DIM == 3
537 static void store_texel_luminance_alpha_f16(struct gl_texture_image *texImage,
538 GLint i, GLint j, GLint k, const void *texel)
539 {
540 const GLfloat *rgba = (const GLfloat *) texel;
541 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
542 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
543 dst[1] = _mesa_float_to_half(rgba[ACOMP]);
544 }
545 #endif
546
547
548 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
549
550 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
551 * returning 4 GLfloats.
552 */
553 static void FETCH(f_intensity_f32)( const struct gl_texture_image *texImage,
554 GLint i, GLint j, GLint k, GLfloat *texel )
555 {
556 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
557 texel[RCOMP] =
558 texel[GCOMP] =
559 texel[BCOMP] =
560 texel[ACOMP] = src[0];
561 }
562
563 #if DIM == 3
564 static void store_texel_intensity_f32(struct gl_texture_image *texImage,
565 GLint i, GLint j, GLint k, const void *texel)
566 {
567 const GLfloat *rgba = (const GLfloat *) texel;
568 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
569 dst[0] = rgba[RCOMP];
570 }
571 #endif
572
573
574 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
575
576 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
577 * returning 4 GLfloats.
578 */
579 static void FETCH(f_intensity_f16)( const struct gl_texture_image *texImage,
580 GLint i, GLint j, GLint k, GLfloat *texel )
581 {
582 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
583 texel[RCOMP] =
584 texel[GCOMP] =
585 texel[BCOMP] =
586 texel[ACOMP] = _mesa_half_to_float(src[0]);
587 }
588
589 #if DIM == 3
590 static void store_texel_intensity_f16(struct gl_texture_image *texImage,
591 GLint i, GLint j, GLint k, const void *texel)
592 {
593 const GLfloat *rgba = (const GLfloat *) texel;
594 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
595 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
596 }
597 #endif
598
599
600
601
602 /*
603 * Begin Hardware formats
604 */
605
606 /* MESA_FORMAT_RGBA8888 ******************************************************/
607
608 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
609 static void FETCH(rgba8888)( const struct gl_texture_image *texImage,
610 GLint i, GLint j, GLint k, GLchan *texel )
611 {
612 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
613 texel[RCOMP] = UBYTE_TO_CHAN( (s >> 24) );
614 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
615 texel[BCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
616 texel[ACOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
617 }
618
619 #if DIM == 3
620 static void store_texel_rgba8888(struct gl_texture_image *texImage,
621 GLint i, GLint j, GLint k, const void *texel)
622 {
623 const GLubyte *rgba = (const GLubyte *) texel;
624 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
625 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
626 }
627 #endif
628
629
630 /* MESA_FORMAT_RGBA888_REV ***************************************************/
631
632 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
633 static void FETCH(rgba8888_rev)( const struct gl_texture_image *texImage,
634 GLint i, GLint j, GLint k, GLchan *texel )
635 {
636 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
637 texel[RCOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
638 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
639 texel[BCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
640 texel[ACOMP] = UBYTE_TO_CHAN( (s >> 24) );
641 }
642
643 #if DIM == 3
644 static void store_texel_rgba8888_rev(struct gl_texture_image *texImage,
645 GLint i, GLint j, GLint k, const void *texel)
646 {
647 const GLubyte *rgba = (const GLubyte *) texel;
648 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
649 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
650 }
651 #endif
652
653
654 /* MESA_FORMAT_ARGB8888 ******************************************************/
655
656 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
657 static void FETCH(argb8888)( const struct gl_texture_image *texImage,
658 GLint i, GLint j, GLint k, GLchan *texel )
659 {
660 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
661 texel[RCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
662 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
663 texel[BCOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
664 texel[ACOMP] = UBYTE_TO_CHAN( (s >> 24) );
665 }
666
667 #if DIM == 3
668 static void store_texel_argb8888(struct gl_texture_image *texImage,
669 GLint i, GLint j, GLint k, const void *texel)
670 {
671 const GLubyte *rgba = (const GLubyte *) texel;
672 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
673 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
674 }
675 #endif
676
677
678 /* MESA_FORMAT_ARGB8888_REV **************************************************/
679
680 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLchans */
681 static void FETCH(argb8888_rev)( const struct gl_texture_image *texImage,
682 GLint i, GLint j, GLint k, GLchan *texel )
683 {
684 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
685 texel[RCOMP] = UBYTE_TO_CHAN( (s >> 8) & 0xff );
686 texel[GCOMP] = UBYTE_TO_CHAN( (s >> 16) & 0xff );
687 texel[BCOMP] = UBYTE_TO_CHAN( (s >> 24) );
688 texel[ACOMP] = UBYTE_TO_CHAN( (s ) & 0xff );
689 }
690
691 #if DIM == 3
692 static void store_texel_argb8888_rev(struct gl_texture_image *texImage,
693 GLint i, GLint j, GLint k, const void *texel)
694 {
695 const GLubyte *rgba = (const GLubyte *) texel;
696 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
697 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
698 }
699 #endif
700
701
702 /* MESA_FORMAT_RGB888 ********************************************************/
703
704 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
705 static void FETCH(rgb888)( const struct gl_texture_image *texImage,
706 GLint i, GLint j, GLint k, GLchan *texel )
707 {
708 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
709 texel[RCOMP] = UBYTE_TO_CHAN( src[2] );
710 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
711 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
712 texel[ACOMP] = CHAN_MAX;
713 }
714
715 #if DIM == 3
716 static void store_texel_rgb888(struct gl_texture_image *texImage,
717 GLint i, GLint j, GLint k, const void *texel)
718 {
719 const GLubyte *rgba = (const GLubyte *) texel;
720 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
721 dst[0] = rgba[RCOMP];
722 dst[1] = rgba[GCOMP];
723 dst[2] = rgba[BCOMP];
724 }
725 #endif
726
727
728 /* MESA_FORMAT_BGR888 ********************************************************/
729
730 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
731 static void FETCH(bgr888)( const struct gl_texture_image *texImage,
732 GLint i, GLint j, GLint k, GLchan *texel )
733 {
734 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
735 texel[RCOMP] = UBYTE_TO_CHAN( src[0] );
736 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
737 texel[BCOMP] = UBYTE_TO_CHAN( src[2] );
738 texel[ACOMP] = CHAN_MAX;
739 }
740
741 #if DIM == 3
742 static void store_texel_bgr888(struct gl_texture_image *texImage,
743 GLint i, GLint j, GLint k, const void *texel)
744 {
745 const GLubyte *rgba = (const GLubyte *) texel;
746 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
747 dst[0] = rgba[BCOMP];
748 dst[1] = rgba[GCOMP];
749 dst[2] = rgba[RCOMP];
750 }
751 #endif
752
753
754 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
755 instead of slow (g << 2) * 255 / 252 (always rounds down) */
756
757 /* MESA_FORMAT_RGB565 ********************************************************/
758
759 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
760 static void FETCH(rgb565)( const struct gl_texture_image *texImage,
761 GLint i, GLint j, GLint k, GLchan *texel )
762 {
763 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
764 const GLushort s = *src;
765 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
766 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
767 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
768 texel[ACOMP] = CHAN_MAX;
769 }
770
771 #if DIM == 3
772 static void store_texel_rgb565(struct gl_texture_image *texImage,
773 GLint i, GLint j, GLint k, const void *texel)
774 {
775 const GLubyte *rgba = (const GLubyte *) texel;
776 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
777 *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
778 }
779 #endif
780
781
782 /* MESA_FORMAT_RGB565_REV ****************************************************/
783
784 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
785 static void FETCH(rgb565_rev)( const struct gl_texture_image *texImage,
786 GLint i, GLint j, GLint k, GLchan *texel )
787 {
788 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
789 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
790 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
791 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
792 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
793 texel[ACOMP] = CHAN_MAX;
794 }
795
796 #if DIM == 3
797 static void store_texel_rgb565_rev(struct gl_texture_image *texImage,
798 GLint i, GLint j, GLint k, const void *texel)
799 {
800 const GLubyte *rgba = (const GLubyte *) texel;
801 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
802 *dst = PACK_COLOR_565(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
803 }
804 #endif
805
806
807 /* MESA_FORMAT_ARGB4444 ******************************************************/
808
809 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
810 static void FETCH(argb4444)( const struct gl_texture_image *texImage,
811 GLint i, GLint j, GLint k, GLchan *texel )
812 {
813 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
814 const GLushort s = *src;
815 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) | ((s >> 4) & 0xf0) );
816 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) | ((s ) & 0xf0) );
817 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) | ((s << 4) & 0xf0) );
818 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) | ((s >> 8) & 0xf0) );
819 }
820
821 #if DIM == 3
822 static void store_texel_argb4444(struct gl_texture_image *texImage,
823 GLint i, GLint j, GLint k, const void *texel)
824 {
825 const GLubyte *rgba = (const GLubyte *) texel;
826 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
827 *dst = PACK_COLOR_4444(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
828 }
829 #endif
830
831
832 /* MESA_FORMAT_ARGB4444_REV **************************************************/
833
834 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
835 static void FETCH(argb4444_rev)( const struct gl_texture_image *texImage,
836 GLint i, GLint j, GLint k, GLchan *texel )
837 {
838 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
839 texel[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) | ((s << 4) & 0xf0) );
840 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) | ((s >> 8) & 0xf0) );
841 texel[BCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) | ((s >> 4) & 0xf0) );
842 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) | ((s ) & 0xf0) );
843 }
844
845 #if DIM == 3
846 static void store_texel_argb4444_rev(struct gl_texture_image *texImage,
847 GLint i, GLint j, GLint k, const void *texel)
848 {
849 const GLubyte *rgba = (const GLubyte *) texel;
850 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
851 *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
852 }
853 #endif
854
855
856 /* MESA_FORMAT_ARGB1555 ******************************************************/
857
858 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
859 static void FETCH(argb1555)( const struct gl_texture_image *texImage,
860 GLint i, GLint j, GLint k, GLchan *texel )
861 {
862 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
863 const GLushort s = *src;
864 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
865 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
866 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
867 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
868 }
869
870 #if DIM == 3
871 static void store_texel_argb1555(struct gl_texture_image *texImage,
872 GLint i, GLint j, GLint k, const void *texel)
873 {
874 const GLubyte *rgba = (const GLubyte *) texel;
875 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
876 *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
877 }
878 #endif
879
880
881 /* MESA_FORMAT_ARGB1555_REV **************************************************/
882
883 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
884 static void FETCH(argb1555_rev)( const struct gl_texture_image *texImage,
885 GLint i, GLint j, GLint k, GLchan *texel )
886 {
887 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
888 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
889 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
890 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
891 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
892 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
893 }
894
895 #if DIM == 3
896 static void store_texel_argb1555_rev(struct gl_texture_image *texImage,
897 GLint i, GLint j, GLint k, const void *texel)
898 {
899 const GLubyte *rgba = (const GLubyte *) texel;
900 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
901 *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
902 }
903 #endif
904
905
906 /* MESA_FORMAT_AL88 **********************************************************/
907
908 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
909 static void FETCH(al88)( const struct gl_texture_image *texImage,
910 GLint i, GLint j, GLint k, GLchan *texel )
911 {
912 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
913 texel[RCOMP] =
914 texel[GCOMP] =
915 texel[BCOMP] = UBYTE_TO_CHAN( s & 0xff );
916 texel[ACOMP] = UBYTE_TO_CHAN( s >> 8 );
917 }
918
919 #if DIM == 3
920 static void store_texel_al88(struct gl_texture_image *texImage,
921 GLint i, GLint j, GLint k, const void *texel)
922 {
923 const GLubyte *rgba = (const GLubyte *) texel;
924 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
925 *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
926 }
927 #endif
928
929
930 /* MESA_FORMAT_AL88_REV ******************************************************/
931
932 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
933 static void FETCH(al88_rev)( const struct gl_texture_image *texImage,
934 GLint i, GLint j, GLint k, GLchan *texel )
935 {
936 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
937 texel[RCOMP] =
938 texel[GCOMP] =
939 texel[BCOMP] = UBYTE_TO_CHAN( s >> 8 );
940 texel[ACOMP] = UBYTE_TO_CHAN( s & 0xff );
941 }
942
943 #if DIM == 3
944 static void store_texel_al88_rev(struct gl_texture_image *texImage,
945 GLint i, GLint j, GLint k, const void *texel)
946 {
947 const GLubyte *rgba = (const GLubyte *) texel;
948 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
949 *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
950 }
951 #endif
952
953
954 /* MESA_FORMAT_RGB332 ********************************************************/
955
956 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
957 static void FETCH(rgb332)( const struct gl_texture_image *texImage,
958 GLint i, GLint j, GLint k, GLchan *texel )
959 {
960 static const GLubyte lut2to8[4] = {0, 85, 170, 255};
961 static const GLubyte lut3to8[8] = {0, 36, 73, 109, 146, 182, 219, 255};
962 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
963 const GLubyte s = *src;
964 texel[RCOMP] = UBYTE_TO_CHAN( lut3to8[(s >> 5) & 0x7] );
965 texel[GCOMP] = UBYTE_TO_CHAN( lut3to8[(s >> 2) & 0x7] );
966 texel[BCOMP] = UBYTE_TO_CHAN( lut2to8[(s ) & 0x3] );
967 texel[ACOMP] = CHAN_MAX;
968 }
969
970 #if DIM == 3
971 static void store_texel_rgb332(struct gl_texture_image *texImage,
972 GLint i, GLint j, GLint k, const void *texel)
973 {
974 const GLubyte *rgba = (const GLubyte *) texel;
975 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
976 *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
977 }
978 #endif
979
980
981 /* MESA_FORMAT_A8 ************************************************************/
982
983 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
984 static void FETCH(a8)( const struct gl_texture_image *texImage,
985 GLint i, GLint j, GLint k, GLchan *texel )
986 {
987 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
988 texel[RCOMP] =
989 texel[GCOMP] =
990 texel[BCOMP] = 0;
991 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
992 }
993
994 #if DIM == 3
995 static void store_texel_a8(struct gl_texture_image *texImage,
996 GLint i, GLint j, GLint k, const void *texel)
997 {
998 const GLubyte *rgba = (const GLubyte *) texel;
999 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1000 *dst = rgba[ACOMP];
1001 }
1002 #endif
1003
1004
1005 /* MESA_FORMAT_L8 ************************************************************/
1006
1007 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1008 static void FETCH(l8)( const struct gl_texture_image *texImage,
1009 GLint i, GLint j, GLint k, GLchan *texel )
1010 {
1011 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1012 texel[RCOMP] =
1013 texel[GCOMP] =
1014 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
1015 texel[ACOMP] = CHAN_MAX;
1016 }
1017
1018 #if DIM == 3
1019 static void store_texel_l8(struct gl_texture_image *texImage,
1020 GLint i, GLint j, GLint k, const void *texel)
1021 {
1022 const GLubyte *rgba = (const GLubyte *) texel;
1023 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1024 *dst = rgba[RCOMP];
1025 }
1026 #endif
1027
1028
1029 /* MESA_FORMAT_I8 ************************************************************/
1030
1031 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1032 static void FETCH(i8)( const struct gl_texture_image *texImage,
1033 GLint i, GLint j, GLint k, GLchan *texel )
1034 {
1035 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1036 texel[RCOMP] =
1037 texel[GCOMP] =
1038 texel[BCOMP] =
1039 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
1040 }
1041
1042 #if DIM == 3
1043 static void store_texel_i8(struct gl_texture_image *texImage,
1044 GLint i, GLint j, GLint k, const void *texel)
1045 {
1046 const GLubyte *rgba = (const GLubyte *) texel;
1047 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1048 *dst = rgba[RCOMP];
1049 }
1050 #endif
1051
1052
1053 /* MESA_FORMAT_CI8 ***********************************************************/
1054
1055 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1056 * color table, and return 4 GLchans.
1057 */
1058 static void FETCH(ci8)( const struct gl_texture_image *texImage,
1059 GLint i, GLint j, GLint k, GLchan *texel )
1060 {
1061 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1062 const struct gl_color_table *palette;
1063 const GLchan *table;
1064 GLuint index;
1065 GET_CURRENT_CONTEXT(ctx);
1066
1067 if (ctx->Texture.SharedPalette) {
1068 palette = &ctx->Texture.Palette;
1069 }
1070 else {
1071 palette = &texImage->TexObject->Palette;
1072 }
1073 if (palette->Size == 0)
1074 return; /* undefined results */
1075 ASSERT(palette->Type != GL_FLOAT);
1076 table = (const GLchan *) palette->Table;
1077
1078 /* Mask the index against size of palette to avoid going out of bounds */
1079 index = (*src) & (palette->Size - 1);
1080
1081 switch (palette->Format) {
1082 case GL_ALPHA:
1083 texel[RCOMP] =
1084 texel[GCOMP] =
1085 texel[BCOMP] = 0;
1086 texel[ACOMP] = table[index];
1087 return;
1088 case GL_LUMINANCE:
1089 texel[RCOMP] =
1090 texel[GCOMP] =
1091 texel[BCOMP] = table[index];
1092 texel[ACOMP] = CHAN_MAX;
1093 break;
1094 case GL_INTENSITY:
1095 texel[RCOMP] =
1096 texel[GCOMP] =
1097 texel[BCOMP] =
1098 texel[ACOMP] = table[index];
1099 return;
1100 case GL_LUMINANCE_ALPHA:
1101 texel[RCOMP] =
1102 texel[GCOMP] =
1103 texel[BCOMP] = table[index * 2 + 0];
1104 texel[ACOMP] = table[index * 2 + 1];
1105 return;
1106 case GL_RGB:
1107 texel[RCOMP] = table[index * 3 + 0];
1108 texel[GCOMP] = table[index * 3 + 1];
1109 texel[BCOMP] = table[index * 3 + 2];
1110 texel[ACOMP] = CHAN_MAX;
1111 return;
1112 case GL_RGBA:
1113 texel[RCOMP] = table[index * 4 + 0];
1114 texel[GCOMP] = table[index * 4 + 1];
1115 texel[BCOMP] = table[index * 4 + 2];
1116 texel[ACOMP] = table[index * 4 + 3];
1117 return;
1118 default:
1119 _mesa_problem(ctx, "Bad palette format in palette_sample");
1120 }
1121 }
1122
1123 #if DIM == 3
1124 static void store_texel_ci8(struct gl_texture_image *texImage,
1125 GLint i, GLint j, GLint k, const void *texel)
1126 {
1127 const GLubyte *index = (const GLubyte *) texel;
1128 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1129 *dst = *index;
1130 }
1131 #endif
1132
1133
1134 /* MESA_FORMAT_YCBCR *********************************************************/
1135
1136 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
1137 /* We convert YCbCr to RGB here */
1138 /* XXX this may break if GLchan != GLubyte */
1139 static void FETCH(ycbcr)( const struct gl_texture_image *texImage,
1140 GLint i, GLint j, GLint k, GLchan *texel )
1141 {
1142 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1143 const GLushort *src1 = src0 + 1; /* odd */
1144 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1145 const GLubyte cb = *src0 & 0xff; /* chroma U */
1146 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1147 const GLubyte cr = *src1 & 0xff; /* chroma V */
1148 GLint r, g, b;
1149 if (i & 1) {
1150 /* odd pixel: use y1,cr,cb */
1151 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
1152 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1153 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
1154 }
1155 else {
1156 /* even pixel: use y0,cr,cb */
1157 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
1158 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1159 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
1160 }
1161 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
1162 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
1163 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
1164 texel[ACOMP] = CHAN_MAX;
1165 }
1166
1167 #if DIM == 3
1168 static void store_texel_ycbcr(struct gl_texture_image *texImage,
1169 GLint i, GLint j, GLint k, const void *texel)
1170 {
1171 /* XXX to do */
1172 }
1173 #endif
1174
1175
1176 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1177
1178 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
1179 /* We convert YCbCr to RGB here */
1180 /* XXX this may break if GLchan != GLubyte */
1181 static void FETCH(ycbcr_rev)( const struct gl_texture_image *texImage,
1182 GLint i, GLint j, GLint k, GLchan *texel )
1183 {
1184 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1185 const GLushort *src1 = src0 + 1; /* odd */
1186 const GLubyte y0 = *src0 & 0xff; /* luminance */
1187 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1188 const GLubyte y1 = *src1 & 0xff; /* luminance */
1189 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1190 GLint r, g, b;
1191 if (i & 1) {
1192 /* odd pixel: use y1,cr,cb */
1193 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
1194 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1195 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
1196 }
1197 else {
1198 /* even pixel: use y0,cr,cb */
1199 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
1200 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1201 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
1202 }
1203 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
1204 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
1205 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
1206 texel[ACOMP] = CHAN_MAX;
1207 }
1208
1209 #if DIM == 3
1210 static void store_texel_ycbcr_rev(struct gl_texture_image *texImage,
1211 GLint i, GLint j, GLint k, const void *texel)
1212 {
1213 /* XXX to do */
1214 }
1215 #endif
1216
1217
1218 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1219
1220 static void FETCH(f_z24_s8)( const struct gl_texture_image *texImage,
1221 GLint i, GLint j, GLint k, GLfloat *texel )
1222 {
1223 /* only return Z, not stencil data */
1224 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1225 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1226 texel[0] = ((*src) >> 8) * scale;
1227 }
1228
1229 #if DIM == 3
1230 static void store_texel_z24_s8(struct gl_texture_image *texImage,
1231 GLint i, GLint j, GLint k, const void *texel)
1232 {
1233 /* only store Z, not stencil */
1234 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1235 GLfloat depth = *((GLfloat *) texel);
1236 GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
1237 *dst = zi | (*dst & 0xff);
1238 }
1239 #endif
1240
1241
1242
1243 #undef TEXEL_ADDR
1244 #undef DIM
1245 #undef FETCH