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