Fix store texel for argb4444.
[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 *
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)->ImageOffsets[k] \
63 + (image)->RowStride * (j) + (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_Z32 ***********************************************************/
238
239 /* Fetch depth texel from 1D, 2D or 3D 32-bit depth texture,
240 * returning 1 GLfloat.
241 * Note: no GLchan version of this function.
242 */
243 static void FETCH(f_z32)( const struct gl_texture_image *texImage,
244 GLint i, GLint j, GLint k, GLfloat *texel )
245 {
246 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
247 texel[0] = src[0] * (1.0F / 0xffffffff);
248 }
249
250 #if DIM == 3
251 static void store_texel_z32(struct gl_texture_image *texImage,
252 GLint i, GLint j, GLint k, const void *texel)
253 {
254 const GLuint *depth = (const GLuint *) texel;
255 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
256 dst[0] = *depth;
257 }
258 #endif
259
260
261 /* MESA_FORMAT_Z16 ***********************************************************/
262
263 /* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
264 * returning 1 GLfloat.
265 * Note: no GLchan version of this function.
266 */
267 static void FETCH(f_z16)(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_z16(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[BCOMP], rgba[GCOMP], rgba[RCOMP], rgba[ACOMP]);
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 /* MESA_FORMAT_RGBA4444 ******************************************************/
807
808 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
809 static void FETCH(rgba4444)( const struct gl_texture_image *texImage,
810 GLint i, GLint j, GLint k, GLchan *texel )
811 {
812 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
813 const GLushort s = *src;
814 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) | ((s >> 8) & 0xf0) );
815 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) | ((s >> 4) & 0xf0) );
816 texel[BCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) | ((s ) & 0xf0) );
817 texel[ACOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) | ((s << 4) & 0xf0) );
818 }
819
820 #if DIM == 3
821 static void store_texel_rgba4444(struct gl_texture_image *texImage,
822 GLint i, GLint j, GLint k, const void *texel)
823 {
824 const GLubyte *rgba = (const GLubyte *) texel;
825 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
826 *dst = PACK_COLOR_4444(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
827 }
828 #endif
829
830
831 /* MESA_FORMAT_ARGB4444 ******************************************************/
832
833 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
834 static void FETCH(argb4444)( const struct gl_texture_image *texImage,
835 GLint i, GLint j, GLint k, GLchan *texel )
836 {
837 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
838 const GLushort s = *src;
839 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) | ((s >> 4) & 0xf0) );
840 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) | ((s ) & 0xf0) );
841 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) | ((s << 4) & 0xf0) );
842 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) | ((s >> 8) & 0xf0) );
843 }
844
845 #if DIM == 3
846 static void store_texel_argb4444(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[RCOMP], rgba[GCOMP], rgba[BCOMP]);
852 }
853 #endif
854
855
856 /* MESA_FORMAT_ARGB4444_REV **************************************************/
857
858 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
859 static void FETCH(argb4444_rev)( const struct gl_texture_image *texImage,
860 GLint i, GLint j, GLint k, GLchan *texel )
861 {
862 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
863 texel[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) | ((s << 4) & 0xf0) );
864 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) | ((s >> 8) & 0xf0) );
865 texel[BCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) | ((s >> 4) & 0xf0) );
866 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) | ((s ) & 0xf0) );
867 }
868
869 #if DIM == 3
870 static void store_texel_argb4444_rev(struct gl_texture_image *texImage,
871 GLint i, GLint j, GLint k, const void *texel)
872 {
873 const GLubyte *rgba = (const GLubyte *) texel;
874 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
875 *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
876 }
877 #endif
878
879 /* MESA_FORMAT_RGBA5551 ******************************************************/
880
881 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
882 static void FETCH(rgba5551)( const struct gl_texture_image *texImage,
883 GLint i, GLint j, GLint k, GLchan *texel )
884 {
885 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
886 const GLushort s = *src;
887 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
888 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xf8) | ((s >> 8) & 0x7) );
889 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 2) & 0xf8) | ((s >> 3) & 0x7) );
890 texel[ACOMP] = UBYTE_TO_CHAN( ((s) & 0x01) ? 255 : 0);
891 }
892
893 #if DIM == 3
894 static void store_texel_rgba5551(struct gl_texture_image *texImage,
895 GLint i, GLint j, GLint k, const void *texel)
896 {
897 const GLubyte *rgba = (const GLubyte *) texel;
898 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
899 *dst = PACK_COLOR_5551(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
900 }
901 #endif
902
903 /* MESA_FORMAT_ARGB1555 ******************************************************/
904
905 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
906 static void FETCH(argb1555)( const struct gl_texture_image *texImage,
907 GLint i, GLint j, GLint k, GLchan *texel )
908 {
909 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
910 const GLushort s = *src;
911 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
912 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
913 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
914 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
915 }
916
917 #if DIM == 3
918 static void store_texel_argb1555(struct gl_texture_image *texImage,
919 GLint i, GLint j, GLint k, const void *texel)
920 {
921 const GLubyte *rgba = (const GLubyte *) texel;
922 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
923 *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
924 }
925 #endif
926
927
928 /* MESA_FORMAT_ARGB1555_REV **************************************************/
929
930 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
931 static void FETCH(argb1555_rev)( const struct gl_texture_image *texImage,
932 GLint i, GLint j, GLint k, GLchan *texel )
933 {
934 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
935 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
936 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
937 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
938 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
939 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
940 }
941
942 #if DIM == 3
943 static void store_texel_argb1555_rev(struct gl_texture_image *texImage,
944 GLint i, GLint j, GLint k, const void *texel)
945 {
946 const GLubyte *rgba = (const GLubyte *) texel;
947 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
948 *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
949 }
950 #endif
951
952
953 /* MESA_FORMAT_AL88 **********************************************************/
954
955 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
956 static void FETCH(al88)( const struct gl_texture_image *texImage,
957 GLint i, GLint j, GLint k, GLchan *texel )
958 {
959 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
960 texel[RCOMP] =
961 texel[GCOMP] =
962 texel[BCOMP] = UBYTE_TO_CHAN( s & 0xff );
963 texel[ACOMP] = UBYTE_TO_CHAN( s >> 8 );
964 }
965
966 #if DIM == 3
967 static void store_texel_al88(struct gl_texture_image *texImage,
968 GLint i, GLint j, GLint k, const void *texel)
969 {
970 const GLubyte *rgba = (const GLubyte *) texel;
971 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
972 *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
973 }
974 #endif
975
976
977 /* MESA_FORMAT_AL88_REV ******************************************************/
978
979 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
980 static void FETCH(al88_rev)( const struct gl_texture_image *texImage,
981 GLint i, GLint j, GLint k, GLchan *texel )
982 {
983 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
984 texel[RCOMP] =
985 texel[GCOMP] =
986 texel[BCOMP] = UBYTE_TO_CHAN( s >> 8 );
987 texel[ACOMP] = UBYTE_TO_CHAN( s & 0xff );
988 }
989
990 #if DIM == 3
991 static void store_texel_al88_rev(struct gl_texture_image *texImage,
992 GLint i, GLint j, GLint k, const void *texel)
993 {
994 const GLubyte *rgba = (const GLubyte *) texel;
995 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
996 *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
997 }
998 #endif
999
1000
1001 /* MESA_FORMAT_RGB332 ********************************************************/
1002
1003 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1004 static void FETCH(rgb332)( const struct gl_texture_image *texImage,
1005 GLint i, GLint j, GLint k, GLchan *texel )
1006 {
1007 static const GLubyte lut2to8[4] = {0, 85, 170, 255};
1008 static const GLubyte lut3to8[8] = {0, 36, 73, 109, 146, 182, 219, 255};
1009 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1010 const GLubyte s = *src;
1011 texel[RCOMP] = UBYTE_TO_CHAN( lut3to8[(s >> 5) & 0x7] );
1012 texel[GCOMP] = UBYTE_TO_CHAN( lut3to8[(s >> 2) & 0x7] );
1013 texel[BCOMP] = UBYTE_TO_CHAN( lut2to8[(s ) & 0x3] );
1014 texel[ACOMP] = CHAN_MAX;
1015 }
1016
1017 #if DIM == 3
1018 static void store_texel_rgb332(struct gl_texture_image *texImage,
1019 GLint i, GLint j, GLint k, const void *texel)
1020 {
1021 const GLubyte *rgba = (const GLubyte *) texel;
1022 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1023 *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1024 }
1025 #endif
1026
1027
1028 /* MESA_FORMAT_A8 ************************************************************/
1029
1030 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1031 static void FETCH(a8)( const struct gl_texture_image *texImage,
1032 GLint i, GLint j, GLint k, GLchan *texel )
1033 {
1034 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1035 texel[RCOMP] =
1036 texel[GCOMP] =
1037 texel[BCOMP] = 0;
1038 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
1039 }
1040
1041 #if DIM == 3
1042 static void store_texel_a8(struct gl_texture_image *texImage,
1043 GLint i, GLint j, GLint k, const void *texel)
1044 {
1045 const GLubyte *rgba = (const GLubyte *) texel;
1046 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1047 *dst = rgba[ACOMP];
1048 }
1049 #endif
1050
1051
1052 /* MESA_FORMAT_L8 ************************************************************/
1053
1054 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1055 static void FETCH(l8)( const struct gl_texture_image *texImage,
1056 GLint i, GLint j, GLint k, GLchan *texel )
1057 {
1058 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1059 texel[RCOMP] =
1060 texel[GCOMP] =
1061 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
1062 texel[ACOMP] = CHAN_MAX;
1063 }
1064
1065 #if DIM == 3
1066 static void store_texel_l8(struct gl_texture_image *texImage,
1067 GLint i, GLint j, GLint k, const void *texel)
1068 {
1069 const GLubyte *rgba = (const GLubyte *) texel;
1070 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1071 *dst = rgba[RCOMP];
1072 }
1073 #endif
1074
1075
1076 /* MESA_FORMAT_I8 ************************************************************/
1077
1078 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1079 static void FETCH(i8)( const struct gl_texture_image *texImage,
1080 GLint i, GLint j, GLint k, GLchan *texel )
1081 {
1082 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1083 texel[RCOMP] =
1084 texel[GCOMP] =
1085 texel[BCOMP] =
1086 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
1087 }
1088
1089 #if DIM == 3
1090 static void store_texel_i8(struct gl_texture_image *texImage,
1091 GLint i, GLint j, GLint k, const void *texel)
1092 {
1093 const GLubyte *rgba = (const GLubyte *) texel;
1094 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1095 *dst = rgba[RCOMP];
1096 }
1097 #endif
1098
1099
1100 /* MESA_FORMAT_CI8 ***********************************************************/
1101
1102 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1103 * color table, and return 4 GLchans.
1104 */
1105 static void FETCH(ci8)( const struct gl_texture_image *texImage,
1106 GLint i, GLint j, GLint k, GLchan *texel )
1107 {
1108 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1109 const struct gl_color_table *palette;
1110 GLubyte texelUB[4];
1111 GLuint index;
1112 GET_CURRENT_CONTEXT(ctx);
1113
1114 if (ctx->Texture.SharedPalette) {
1115 palette = &ctx->Texture.Palette;
1116 }
1117 else {
1118 palette = &texImage->TexObject->Palette;
1119 }
1120 if (palette->Size == 0)
1121 return; /* undefined results */
1122
1123 /* Mask the index against size of palette to avoid going out of bounds */
1124 index = (*src) & (palette->Size - 1);
1125
1126 {
1127 const GLubyte *table = palette->TableUB;
1128 switch (palette->_BaseFormat) {
1129 case GL_ALPHA:
1130 texelUB[RCOMP] =
1131 texelUB[GCOMP] =
1132 texelUB[BCOMP] = 0;
1133 texelUB[ACOMP] = table[index];
1134 break;;
1135 case GL_LUMINANCE:
1136 texelUB[RCOMP] =
1137 texelUB[GCOMP] =
1138 texelUB[BCOMP] = table[index];
1139 texelUB[ACOMP] = 255;
1140 break;
1141 case GL_INTENSITY:
1142 texelUB[RCOMP] =
1143 texelUB[GCOMP] =
1144 texelUB[BCOMP] =
1145 texelUB[ACOMP] = table[index];
1146 break;;
1147 case GL_LUMINANCE_ALPHA:
1148 texelUB[RCOMP] =
1149 texelUB[GCOMP] =
1150 texelUB[BCOMP] = table[index * 2 + 0];
1151 texelUB[ACOMP] = table[index * 2 + 1];
1152 break;;
1153 case GL_RGB:
1154 texelUB[RCOMP] = table[index * 3 + 0];
1155 texelUB[GCOMP] = table[index * 3 + 1];
1156 texelUB[BCOMP] = table[index * 3 + 2];
1157 texelUB[ACOMP] = 255;
1158 break;;
1159 case GL_RGBA:
1160 texelUB[RCOMP] = table[index * 4 + 0];
1161 texelUB[GCOMP] = table[index * 4 + 1];
1162 texelUB[BCOMP] = table[index * 4 + 2];
1163 texelUB[ACOMP] = table[index * 4 + 3];
1164 break;;
1165 default:
1166 _mesa_problem(ctx, "Bad palette format in fetch_texel_ci8");
1167 return;
1168 }
1169 #if CHAN_TYPE == GL_UNSIGNED_BYTE
1170 COPY_4UBV(texel, texelUB);
1171 #elif CHAN_TYPE == GL_UNSIGNED_SHORT
1172 texel[0] = UBYTE_TO_USHORT(texelUB[0]);
1173 texel[1] = UBYTE_TO_USHORT(texelUB[1]);
1174 texel[2] = UBYTE_TO_USHORT(texelUB[2]);
1175 texel[3] = UBYTE_TO_USHORT(texelUB[3]);
1176 #else
1177 texel[0] = UBYTE_TO_FLOAT(texelUB[0]);
1178 texel[1] = UBYTE_TO_FLOAT(texelUB[1]);
1179 texel[2] = UBYTE_TO_FLOAT(texelUB[2]);
1180 texel[3] = UBYTE_TO_FLOAT(texelUB[3]);
1181 #endif
1182 }
1183 }
1184
1185 #if DIM == 3
1186 static void store_texel_ci8(struct gl_texture_image *texImage,
1187 GLint i, GLint j, GLint k, const void *texel)
1188 {
1189 const GLubyte *index = (const GLubyte *) texel;
1190 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1191 *dst = *index;
1192 }
1193 #endif
1194
1195
1196 #if FEATURE_EXT_texture_sRGB
1197
1198 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1199 static void FETCH(srgb8)(const struct gl_texture_image *texImage,
1200 GLint i, GLint j, GLint k, GLfloat *texel )
1201 {
1202 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1203 texel[RCOMP] = nonlinear_to_linear(src[0]);
1204 texel[GCOMP] = nonlinear_to_linear(src[1]);
1205 texel[BCOMP] = nonlinear_to_linear(src[2]);
1206 texel[ACOMP] = CHAN_MAX;
1207 }
1208
1209 #if DIM == 3
1210 static void store_texel_srgb8(struct gl_texture_image *texImage,
1211 GLint i, GLint j, GLint k, const void *texel)
1212 {
1213 const GLubyte *rgba = (const GLubyte *) texel;
1214 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1215 dst[0] = rgba[RCOMP]; /* no conversion */
1216 dst[1] = rgba[GCOMP];
1217 dst[2] = rgba[BCOMP];
1218 }
1219 #endif
1220
1221 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1222 static void FETCH(srgba8)(const struct gl_texture_image *texImage,
1223 GLint i, GLint j, GLint k, GLfloat *texel )
1224 {
1225 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1226 texel[RCOMP] = nonlinear_to_linear(src[0]);
1227 texel[GCOMP] = nonlinear_to_linear(src[1]);
1228 texel[BCOMP] = nonlinear_to_linear(src[2]);
1229 texel[ACOMP] = UBYTE_TO_FLOAT(src[3]); /* linear! */
1230 }
1231
1232 #if DIM == 3
1233 static void store_texel_srgba8(struct gl_texture_image *texImage,
1234 GLint i, GLint j, GLint k, const void *texel)
1235 {
1236 const GLubyte *rgba = (const GLubyte *) texel;
1237 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1238 dst[0] = rgba[RCOMP];
1239 dst[1] = rgba[GCOMP];
1240 dst[2] = rgba[BCOMP];
1241 }
1242 #endif
1243
1244 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1245 static void FETCH(sl8)(const struct gl_texture_image *texImage,
1246 GLint i, GLint j, GLint k, GLfloat *texel )
1247 {
1248 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1249 texel[RCOMP] =
1250 texel[GCOMP] =
1251 texel[BCOMP] = nonlinear_to_linear(src[0]);
1252 texel[ACOMP] = CHAN_MAX;
1253 }
1254
1255 #if DIM == 3
1256 static void store_texel_sl8(struct gl_texture_image *texImage,
1257 GLint i, GLint j, GLint k, const void *texel)
1258 {
1259 const GLubyte *rgba = (const GLubyte *) texel;
1260 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1261 dst[0] = rgba[RCOMP];
1262 }
1263 #endif
1264
1265 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1266 static void FETCH(sla8)(const struct gl_texture_image *texImage,
1267 GLint i, GLint j, GLint k, GLfloat *texel )
1268 {
1269 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1270 texel[RCOMP] =
1271 texel[GCOMP] =
1272 texel[BCOMP] = nonlinear_to_linear(src[0]);
1273 texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
1274 }
1275
1276 #if DIM == 3
1277 static void store_texel_sla8(struct gl_texture_image *texImage,
1278 GLint i, GLint j, GLint k, const void *texel)
1279 {
1280 const GLubyte *rgba = (const GLubyte *) texel;
1281 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1282 dst[0] = rgba[RCOMP];
1283 dst[1] = rgba[ACOMP];
1284 }
1285 #endif
1286
1287
1288
1289 #endif /* FEATURE_EXT_texture_sRGB */
1290
1291
1292
1293 /* MESA_FORMAT_YCBCR *********************************************************/
1294
1295 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
1296 /* We convert YCbCr to RGB here */
1297 /* XXX this may break if GLchan != GLubyte */
1298 static void FETCH(ycbcr)( const struct gl_texture_image *texImage,
1299 GLint i, GLint j, GLint k, GLchan *texel )
1300 {
1301 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1302 const GLushort *src1 = src0 + 1; /* odd */
1303 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1304 const GLubyte cb = *src0 & 0xff; /* chroma U */
1305 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1306 const GLubyte cr = *src1 & 0xff; /* chroma V */
1307 GLint r, g, b;
1308 if (i & 1) {
1309 /* odd pixel: use y1,cr,cb */
1310 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
1311 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1312 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
1313 }
1314 else {
1315 /* even pixel: use y0,cr,cb */
1316 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
1317 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1318 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
1319 }
1320 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
1321 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
1322 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
1323 texel[ACOMP] = CHAN_MAX;
1324 }
1325
1326 #if DIM == 3
1327 static void store_texel_ycbcr(struct gl_texture_image *texImage,
1328 GLint i, GLint j, GLint k, const void *texel)
1329 {
1330 (void) texImage;
1331 (void) i;
1332 (void) j;
1333 (void) k;
1334 (void) texel;
1335 /* XXX to do */
1336 }
1337 #endif
1338
1339
1340 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1341
1342 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
1343 /* We convert YCbCr to RGB here */
1344 /* XXX this may break if GLchan != GLubyte */
1345 static void FETCH(ycbcr_rev)( const struct gl_texture_image *texImage,
1346 GLint i, GLint j, GLint k, GLchan *texel )
1347 {
1348 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1349 const GLushort *src1 = src0 + 1; /* odd */
1350 const GLubyte y0 = *src0 & 0xff; /* luminance */
1351 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1352 const GLubyte y1 = *src1 & 0xff; /* luminance */
1353 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1354 GLint r, g, b;
1355 if (i & 1) {
1356 /* odd pixel: use y1,cr,cb */
1357 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
1358 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1359 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
1360 }
1361 else {
1362 /* even pixel: use y0,cr,cb */
1363 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
1364 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
1365 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
1366 }
1367 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
1368 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
1369 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
1370 texel[ACOMP] = CHAN_MAX;
1371 }
1372
1373 #if DIM == 3
1374 static void store_texel_ycbcr_rev(struct gl_texture_image *texImage,
1375 GLint i, GLint j, GLint k, const void *texel)
1376 {
1377 (void) texImage;
1378 (void) i;
1379 (void) j;
1380 (void) k;
1381 (void) texel;
1382 /* XXX to do */
1383 }
1384 #endif
1385
1386
1387 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1388
1389 static void FETCH(f_z24_s8)( const struct gl_texture_image *texImage,
1390 GLint i, GLint j, GLint k, GLfloat *texel )
1391 {
1392 /* only return Z, not stencil data */
1393 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1394 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1395 texel[0] = ((*src) >> 8) * scale;
1396 ASSERT(texImage->TexFormat->MesaFormat == MESA_FORMAT_Z24_S8);
1397 ASSERT(texel[0] >= 0.0F);
1398 ASSERT(texel[0] <= 1.0F);
1399 }
1400
1401 #if DIM == 3
1402 static void store_texel_z24_s8(struct gl_texture_image *texImage,
1403 GLint i, GLint j, GLint k, const void *texel)
1404 {
1405 /* only store Z, not stencil */
1406 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1407 GLfloat depth = *((GLfloat *) texel);
1408 GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
1409 *dst = zi | (*dst & 0xff);
1410 }
1411 #endif
1412
1413
1414 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1415
1416 static void FETCH(f_s8_z24)( const struct gl_texture_image *texImage,
1417 GLint i, GLint j, GLint k, GLfloat *texel )
1418 {
1419 /* only return Z, not stencil data */
1420 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1421 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1422 texel[0] = ((*src) & 0x00ffffff) * scale;
1423 ASSERT(texImage->TexFormat->MesaFormat == MESA_FORMAT_S8_Z24);
1424 ASSERT(texel[0] >= 0.0F);
1425 ASSERT(texel[0] <= 1.0F);
1426 }
1427
1428 #if DIM == 3
1429 static void store_texel_s8_z24(struct gl_texture_image *texImage,
1430 GLint i, GLint j, GLint k, const void *texel)
1431 {
1432 /* only store Z, not stencil */
1433 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1434 GLfloat depth = *((GLfloat *) texel);
1435 GLuint zi = (GLuint) (depth * 0xffffff);
1436 *dst = zi | (*dst & 0xff000000);
1437 }
1438 #endif
1439
1440
1441 #undef TEXEL_ADDR
1442 #undef DIM
1443 #undef FETCH