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