mesa: move gl_texture_image::Data, RowStride, ImageOffsets to swrast
[mesa.git] / src / mesa / swrast / s_texfetch_tmp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.7
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 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 texfetch_tmp.h
29 * Texel fetch functions template.
30 *
31 * This template file is used by texfetch.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 * \author Gareth Hughes
39 * \author Brian Paul
40 */
41
42
43 #if DIM == 1
44
45 #define TEXEL_ADDR( type, image, i, j, k, size ) \
46 ((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
47
48 #define FETCH(x) fetch_texel_1d_##x
49
50 #elif DIM == 2
51
52 #define TEXEL_ADDR( type, image, i, j, k, size ) \
53 ((void) (k), \
54 ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
55
56 #define FETCH(x) fetch_texel_2d_##x
57
58 #elif DIM == 3
59
60 #define TEXEL_ADDR( type, image, i, j, k, size ) \
61 ((type *)(image)->Data + ((image)->ImageOffsets[k] \
62 + (image)->RowStride * (j) + (i)) * (size))
63
64 #define FETCH(x) fetch_texel_3d_##x
65
66 #else
67 #error illegal number of texture dimensions
68 #endif
69
70
71 /* MESA_FORMAT_Z32 ***********************************************************/
72
73 /* Fetch depth texel from 1D, 2D or 3D 32-bit depth texture,
74 * returning 1 GLfloat.
75 * Note: no GLchan version of this function.
76 */
77 static void FETCH(f_z32)( const struct swrast_texture_image *texImage,
78 GLint i, GLint j, GLint k, GLfloat *texel )
79 {
80 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
81 texel[0] = src[0] * (1.0F / 0xffffffff);
82 }
83
84 #if DIM == 3
85 static void store_texel_z32(struct swrast_texture_image *texImage,
86 GLint i, GLint j, GLint k, const void *texel)
87 {
88 const GLuint *depth = (const GLuint *) texel;
89 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
90 dst[0] = *depth;
91 }
92 #endif
93
94
95 /* MESA_FORMAT_Z16 ***********************************************************/
96
97 /* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
98 * returning 1 GLfloat.
99 * Note: no GLchan version of this function.
100 */
101 static void FETCH(f_z16)(const struct swrast_texture_image *texImage,
102 GLint i, GLint j, GLint k, GLfloat *texel )
103 {
104 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
105 texel[0] = src[0] * (1.0F / 65535.0F);
106 }
107
108 #if DIM == 3
109 static void store_texel_z16(struct swrast_texture_image *texImage,
110 GLint i, GLint j, GLint k, const void *texel)
111 {
112 const GLushort *depth = (const GLushort *) texel;
113 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
114 dst[0] = *depth;
115 }
116 #endif
117
118
119 /* MESA_FORMAT_RGBA_F32 ******************************************************/
120
121 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
122 */
123 static void FETCH(f_rgba_f32)( const struct swrast_texture_image *texImage,
124 GLint i, GLint j, GLint k, GLfloat *texel )
125 {
126 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
127 texel[RCOMP] = src[0];
128 texel[GCOMP] = src[1];
129 texel[BCOMP] = src[2];
130 texel[ACOMP] = src[3];
131 }
132
133 #if DIM == 3
134 static void store_texel_rgba_f32(struct swrast_texture_image *texImage,
135 GLint i, GLint j, GLint k, const void *texel)
136 {
137 const GLfloat *depth = (const GLfloat *) texel;
138 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
139 dst[0] = depth[RCOMP];
140 dst[1] = depth[GCOMP];
141 dst[2] = depth[BCOMP];
142 dst[3] = depth[ACOMP];
143 }
144 #endif
145
146
147 /* MESA_FORMAT_RGBA_F16 ******************************************************/
148
149 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
150 * returning 4 GLfloats.
151 */
152 static void FETCH(f_rgba_f16)( const struct swrast_texture_image *texImage,
153 GLint i, GLint j, GLint k, GLfloat *texel )
154 {
155 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
156 texel[RCOMP] = _mesa_half_to_float(src[0]);
157 texel[GCOMP] = _mesa_half_to_float(src[1]);
158 texel[BCOMP] = _mesa_half_to_float(src[2]);
159 texel[ACOMP] = _mesa_half_to_float(src[3]);
160 }
161
162 #if DIM == 3
163 static void store_texel_rgba_f16(struct swrast_texture_image *texImage,
164 GLint i, GLint j, GLint k, const void *texel)
165 {
166 const GLfloat *src = (const GLfloat *) texel;
167 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
168 dst[0] = _mesa_float_to_half(src[RCOMP]);
169 dst[1] = _mesa_float_to_half(src[GCOMP]);
170 dst[2] = _mesa_float_to_half(src[BCOMP]);
171 dst[3] = _mesa_float_to_half(src[ACOMP]);
172 }
173 #endif
174
175 /* MESA_FORMAT_RGB_F32 *******************************************************/
176
177 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
178 * returning 4 GLfloats.
179 */
180 static void FETCH(f_rgb_f32)( const struct swrast_texture_image *texImage,
181 GLint i, GLint j, GLint k, GLfloat *texel )
182 {
183 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
184 texel[RCOMP] = src[0];
185 texel[GCOMP] = src[1];
186 texel[BCOMP] = src[2];
187 texel[ACOMP] = 1.0F;
188 }
189
190 #if DIM == 3
191 static void store_texel_rgb_f32(struct swrast_texture_image *texImage,
192 GLint i, GLint j, GLint k, const void *texel)
193 {
194 const GLfloat *src = (const GLfloat *) texel;
195 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
196 dst[0] = src[RCOMP];
197 dst[1] = src[GCOMP];
198 dst[2] = src[BCOMP];
199 }
200 #endif
201
202
203 /* MESA_FORMAT_RGB_F16 *******************************************************/
204
205 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
206 * returning 4 GLfloats.
207 */
208 static void FETCH(f_rgb_f16)( const struct swrast_texture_image *texImage,
209 GLint i, GLint j, GLint k, GLfloat *texel )
210 {
211 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
212 texel[RCOMP] = _mesa_half_to_float(src[0]);
213 texel[GCOMP] = _mesa_half_to_float(src[1]);
214 texel[BCOMP] = _mesa_half_to_float(src[2]);
215 texel[ACOMP] = 1.0F;
216 }
217
218 #if DIM == 3
219 static void store_texel_rgb_f16(struct swrast_texture_image *texImage,
220 GLint i, GLint j, GLint k, const void *texel)
221 {
222 const GLfloat *src = (const GLfloat *) texel;
223 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
224 dst[0] = _mesa_float_to_half(src[RCOMP]);
225 dst[1] = _mesa_float_to_half(src[GCOMP]);
226 dst[2] = _mesa_float_to_half(src[BCOMP]);
227 }
228 #endif
229
230
231 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
232
233 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
234 * returning 4 GLfloats.
235 */
236 static void FETCH(f_alpha_f32)( const struct swrast_texture_image *texImage,
237 GLint i, GLint j, GLint k, GLfloat *texel )
238 {
239 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
240 texel[RCOMP] =
241 texel[GCOMP] =
242 texel[BCOMP] = 0.0F;
243 texel[ACOMP] = src[0];
244 }
245
246 #if DIM == 3
247 static void store_texel_alpha_f32(struct swrast_texture_image *texImage,
248 GLint i, GLint j, GLint k, const void *texel)
249 {
250 const GLfloat *rgba = (const GLfloat *) texel;
251 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
252 dst[0] = rgba[ACOMP];
253 }
254 #endif
255
256
257 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
258
259 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
260 * returning 4 GLfloats.
261 */
262 static void FETCH(f_alpha_f16)( const struct swrast_texture_image *texImage,
263 GLint i, GLint j, GLint k, GLfloat *texel )
264 {
265 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
266 texel[RCOMP] =
267 texel[GCOMP] =
268 texel[BCOMP] = 0.0F;
269 texel[ACOMP] = _mesa_half_to_float(src[0]);
270 }
271
272 #if DIM == 3
273 static void store_texel_alpha_f16(struct swrast_texture_image *texImage,
274 GLint i, GLint j, GLint k, const void *texel)
275 {
276 const GLfloat *rgba = (const GLfloat *) texel;
277 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
278 dst[0] = _mesa_float_to_half(rgba[ACOMP]);
279 }
280 #endif
281
282
283 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
284
285 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
286 * returning 4 GLfloats.
287 */
288 static void FETCH(f_luminance_f32)( const struct swrast_texture_image *texImage,
289 GLint i, GLint j, GLint k, GLfloat *texel )
290 {
291 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
292 texel[RCOMP] =
293 texel[GCOMP] =
294 texel[BCOMP] = src[0];
295 texel[ACOMP] = 1.0F;
296 }
297
298 #if DIM == 3
299 static void store_texel_luminance_f32(struct swrast_texture_image *texImage,
300 GLint i, GLint j, GLint k, const void *texel)
301 {
302 const GLfloat *rgba = (const GLfloat *) texel;
303 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
304 dst[0] = rgba[RCOMP];
305 }
306 #endif
307
308
309 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
310
311 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
312 * returning 4 GLfloats.
313 */
314 static void FETCH(f_luminance_f16)( const struct swrast_texture_image *texImage,
315 GLint i, GLint j, GLint k, GLfloat *texel )
316 {
317 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
318 texel[RCOMP] =
319 texel[GCOMP] =
320 texel[BCOMP] = _mesa_half_to_float(src[0]);
321 texel[ACOMP] = 1.0F;
322 }
323
324 #if DIM == 3
325 static void store_texel_luminance_f16(struct swrast_texture_image *texImage,
326 GLint i, GLint j, GLint k, const void *texel)
327 {
328 const GLfloat *rgba = (const GLfloat *) texel;
329 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
330 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
331 }
332 #endif
333
334
335 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
336
337 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
338 * returning 4 GLfloats.
339 */
340 static void FETCH(f_luminance_alpha_f32)( const struct swrast_texture_image *texImage,
341 GLint i, GLint j, GLint k, GLfloat *texel )
342 {
343 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
344 texel[RCOMP] =
345 texel[GCOMP] =
346 texel[BCOMP] = src[0];
347 texel[ACOMP] = src[1];
348 }
349
350 #if DIM == 3
351 static void store_texel_luminance_alpha_f32(struct swrast_texture_image *texImage,
352 GLint i, GLint j, GLint k, const void *texel)
353 {
354 const GLfloat *rgba = (const GLfloat *) texel;
355 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
356 dst[0] = rgba[RCOMP];
357 dst[1] = rgba[ACOMP];
358 }
359 #endif
360
361
362 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
363
364 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
365 * returning 4 GLfloats.
366 */
367 static void FETCH(f_luminance_alpha_f16)( const struct swrast_texture_image *texImage,
368 GLint i, GLint j, GLint k, GLfloat *texel )
369 {
370 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
371 texel[RCOMP] =
372 texel[GCOMP] =
373 texel[BCOMP] = _mesa_half_to_float(src[0]);
374 texel[ACOMP] = _mesa_half_to_float(src[1]);
375 }
376
377 #if DIM == 3
378 static void store_texel_luminance_alpha_f16(struct swrast_texture_image *texImage,
379 GLint i, GLint j, GLint k, const void *texel)
380 {
381 const GLfloat *rgba = (const GLfloat *) texel;
382 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
383 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
384 dst[1] = _mesa_float_to_half(rgba[ACOMP]);
385 }
386 #endif
387
388
389 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
390
391 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
392 * returning 4 GLfloats.
393 */
394 static void FETCH(f_intensity_f32)( const struct swrast_texture_image *texImage,
395 GLint i, GLint j, GLint k, GLfloat *texel )
396 {
397 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
398 texel[RCOMP] =
399 texel[GCOMP] =
400 texel[BCOMP] =
401 texel[ACOMP] = src[0];
402 }
403
404 #if DIM == 3
405 static void store_texel_intensity_f32(struct swrast_texture_image *texImage,
406 GLint i, GLint j, GLint k, const void *texel)
407 {
408 const GLfloat *rgba = (const GLfloat *) texel;
409 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
410 dst[0] = rgba[RCOMP];
411 }
412 #endif
413
414
415 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
416
417 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
418 * returning 4 GLfloats.
419 */
420 static void FETCH(f_intensity_f16)( const struct swrast_texture_image *texImage,
421 GLint i, GLint j, GLint k, GLfloat *texel )
422 {
423 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
424 texel[RCOMP] =
425 texel[GCOMP] =
426 texel[BCOMP] =
427 texel[ACOMP] = _mesa_half_to_float(src[0]);
428 }
429
430 #if DIM == 3
431 static void store_texel_intensity_f16(struct swrast_texture_image *texImage,
432 GLint i, GLint j, GLint k, const void *texel)
433 {
434 const GLfloat *rgba = (const GLfloat *) texel;
435 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
436 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
437 }
438 #endif
439
440
441 /* MESA_FORMAT_R_FLOAT32 *****************************************************/
442
443 /* Fetch texel from 1D, 2D or 3D R_FLOAT32 texture,
444 * returning 4 GLfloats.
445 */
446 static void FETCH(f_r_f32)( const struct swrast_texture_image *texImage,
447 GLint i, GLint j, GLint k, GLfloat *texel )
448 {
449 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
450 texel[RCOMP] = src[0];
451 texel[GCOMP] = 0.0F;
452 texel[BCOMP] = 0.0F;
453 texel[ACOMP] = 1.0F;
454 }
455
456 #if DIM == 3
457 static void store_texel_r_f32(struct swrast_texture_image *texImage,
458 GLint i, GLint j, GLint k, const void *texel)
459 {
460 const GLfloat *rgba = (const GLfloat *) texel;
461 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
462 dst[0] = rgba[RCOMP];
463 }
464 #endif
465
466
467 /* MESA_FORMAT_R_FLOAT16 *****************************************************/
468
469 /* Fetch texel from 1D, 2D or 3D R_FLOAT16 texture,
470 * returning 4 GLfloats.
471 */
472 static void FETCH(f_r_f16)( const struct swrast_texture_image *texImage,
473 GLint i, GLint j, GLint k, GLfloat *texel )
474 {
475 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
476 texel[RCOMP] = _mesa_half_to_float(src[0]);
477 texel[GCOMP] = 0.0F;
478 texel[BCOMP] = 0.0F;
479 texel[ACOMP] = 1.0F;
480 }
481
482 #if DIM == 3
483 static void store_texel_r_f16(struct swrast_texture_image *texImage,
484 GLint i, GLint j, GLint k, const void *texel)
485 {
486 const GLfloat *rgba = (const GLfloat *) texel;
487 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
488 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
489 }
490 #endif
491
492
493 /* MESA_FORMAT_RG_FLOAT32 ****************************************************/
494
495 /* Fetch texel from 1D, 2D or 3D RG_FLOAT32 texture,
496 * returning 4 GLfloats.
497 */
498 static void FETCH(f_rg_f32)( const struct swrast_texture_image *texImage,
499 GLint i, GLint j, GLint k, GLfloat *texel )
500 {
501 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
502 texel[RCOMP] = src[0];
503 texel[GCOMP] = src[1];
504 texel[BCOMP] = 0.0F;
505 texel[ACOMP] = 1.0F;
506 }
507
508 #if DIM == 3
509 static void store_texel_rg_f32(struct swrast_texture_image *texImage,
510 GLint i, GLint j, GLint k, const void *texel)
511 {
512 const GLfloat *rgba = (const GLfloat *) texel;
513 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
514 dst[0] = rgba[RCOMP];
515 dst[1] = rgba[GCOMP];
516 }
517 #endif
518
519
520 /* MESA_FORMAT_RG_FLOAT16 ****************************************************/
521
522 /* Fetch texel from 1D, 2D or 3D RG_FLOAT16 texture,
523 * returning 4 GLfloats.
524 */
525 static void FETCH(f_rg_f16)( const struct swrast_texture_image *texImage,
526 GLint i, GLint j, GLint k, GLfloat *texel )
527 {
528 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
529 texel[RCOMP] = _mesa_half_to_float(src[0]);
530 texel[GCOMP] = _mesa_half_to_float(src[1]);
531 texel[BCOMP] = 0.0F;
532 texel[ACOMP] = 1.0F;
533 }
534
535 #if DIM == 3
536 static void store_texel_rg_f16(struct swrast_texture_image *texImage,
537 GLint i, GLint j, GLint k, const void *texel)
538 {
539 const GLfloat *rgba = (const GLfloat *) texel;
540 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
541 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
542 dst[1] = _mesa_float_to_half(rgba[GCOMP]);
543 }
544 #endif
545
546
547 /*
548 * Begin Hardware formats
549 */
550
551 /* MESA_FORMAT_RGBA8888 ******************************************************/
552
553 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
554 static void FETCH(f_rgba8888)( const struct swrast_texture_image *texImage,
555 GLint i, GLint j, GLint k, GLfloat *texel )
556 {
557 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
558 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
559 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
560 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
561 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
562 }
563
564
565
566 #if DIM == 3
567 static void store_texel_rgba8888(struct swrast_texture_image *texImage,
568 GLint i, GLint j, GLint k, const void *texel)
569 {
570 const GLubyte *rgba = (const GLubyte *) texel;
571 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
572 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
573 }
574 #endif
575
576
577 /* MESA_FORMAT_RGBA888_REV ***************************************************/
578
579 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
580 static void FETCH(f_rgba8888_rev)( const struct swrast_texture_image *texImage,
581 GLint i, GLint j, GLint k, GLfloat *texel )
582 {
583 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
584 texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
585 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
586 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
587 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
588 }
589
590 #if DIM == 3
591 static void store_texel_rgba8888_rev(struct swrast_texture_image *texImage,
592 GLint i, GLint j, GLint k, const void *texel)
593 {
594 const GLubyte *rgba = (const GLubyte *) texel;
595 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
596 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
597 }
598 #endif
599
600
601 /* MESA_FORMAT_ARGB8888 ******************************************************/
602
603 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
604 static void FETCH(f_argb8888)( const struct swrast_texture_image *texImage,
605 GLint i, GLint j, GLint k, GLfloat *texel )
606 {
607 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
608 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
609 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
610 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
611 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
612 }
613
614 #if DIM == 3
615 static void store_texel_argb8888(struct swrast_texture_image *texImage,
616 GLint i, GLint j, GLint k, const void *texel)
617 {
618 const GLubyte *rgba = (const GLubyte *) texel;
619 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
620 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
621 }
622 #endif
623
624
625 /* MESA_FORMAT_ARGB8888_REV **************************************************/
626
627 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
628 static void FETCH(f_argb8888_rev)( const struct swrast_texture_image *texImage,
629 GLint i, GLint j, GLint k, GLfloat *texel )
630 {
631 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
632 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
633 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
634 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
635 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
636 }
637
638 #if DIM == 3
639 static void store_texel_argb8888_rev(struct swrast_texture_image *texImage,
640 GLint i, GLint j, GLint k, const void *texel)
641 {
642 const GLubyte *rgba = (const GLubyte *) texel;
643 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
644 *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], rgba[ACOMP]);
645 }
646 #endif
647
648
649 /* MESA_FORMAT_XRGB8888 ******************************************************/
650
651 /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
652 static void FETCH(f_xrgb8888)( const struct swrast_texture_image *texImage,
653 GLint i, GLint j, GLint k, GLfloat *texel )
654 {
655 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
656 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
657 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
658 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
659 texel[ACOMP] = 1.0f;
660 }
661
662 #if DIM == 3
663 static void store_texel_xrgb8888(struct swrast_texture_image *texImage,
664 GLint i, GLint j, GLint k, const void *texel)
665 {
666 const GLubyte *rgba = (const GLubyte *) texel;
667 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
668 *dst = PACK_COLOR_8888(0xff, rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
669 }
670 #endif
671
672
673 /* MESA_FORMAT_XRGB8888_REV **************************************************/
674
675 /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
676 static void FETCH(f_xrgb8888_rev)( const struct swrast_texture_image *texImage,
677 GLint i, GLint j, GLint k, GLfloat *texel )
678 {
679 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
680 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
681 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
682 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
683 texel[ACOMP] = 1.0f;
684 }
685
686 #if DIM == 3
687 static void store_texel_xrgb8888_rev(struct swrast_texture_image *texImage,
688 GLint i, GLint j, GLint k, const void *texel)
689 {
690 const GLubyte *rgba = (const GLubyte *) texel;
691 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
692 *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], 0xff);
693 }
694 #endif
695
696
697 /* MESA_FORMAT_RGB888 ********************************************************/
698
699 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
700 static void FETCH(f_rgb888)( const struct swrast_texture_image *texImage,
701 GLint i, GLint j, GLint k, GLfloat *texel )
702 {
703 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
704 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
705 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
706 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
707 texel[ACOMP] = 1.0F;
708 }
709
710 #if DIM == 3
711 static void store_texel_rgb888(struct swrast_texture_image *texImage,
712 GLint i, GLint j, GLint k, const void *texel)
713 {
714 const GLubyte *rgba = (const GLubyte *) texel;
715 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
716 dst[0] = rgba[BCOMP];
717 dst[1] = rgba[GCOMP];
718 dst[2] = rgba[RCOMP];
719 }
720 #endif
721
722
723 /* MESA_FORMAT_BGR888 ********************************************************/
724
725 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
726 static void FETCH(f_bgr888)( const struct swrast_texture_image *texImage,
727 GLint i, GLint j, GLint k, GLfloat *texel )
728 {
729 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
730 texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
731 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
732 texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
733 texel[ACOMP] = 1.0F;
734 }
735
736 #if DIM == 3
737 static void store_texel_bgr888(struct swrast_texture_image *texImage,
738 GLint i, GLint j, GLint k, const void *texel)
739 {
740 const GLubyte *rgba = (const GLubyte *) texel;
741 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
742 dst[0] = rgba[RCOMP];
743 dst[1] = rgba[GCOMP];
744 dst[2] = rgba[BCOMP];
745 }
746 #endif
747
748
749 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
750 instead of slow (g << 2) * 255 / 252 (always rounds down) */
751
752 /* MESA_FORMAT_RGB565 ********************************************************/
753
754 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
755 static void FETCH(f_rgb565)( const struct swrast_texture_image *texImage,
756 GLint i, GLint j, GLint k, GLfloat *texel )
757 {
758 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
759 const GLushort s = *src;
760 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
761 texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
762 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
763 texel[ACOMP] = 1.0F;
764 }
765
766 #if DIM == 3
767 static void store_texel_rgb565(struct swrast_texture_image *texImage,
768 GLint i, GLint j, GLint k, const void *texel)
769 {
770 const GLubyte *rgba = (const GLubyte *) texel;
771 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
772 *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
773 }
774 #endif
775
776
777 /* MESA_FORMAT_RGB565_REV ****************************************************/
778
779 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
780 static void FETCH(f_rgb565_rev)( const struct swrast_texture_image *texImage,
781 GLint i, GLint j, GLint k, GLfloat *texel )
782 {
783 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
784 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
785 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
786 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
787 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
788 texel[ACOMP] = 1.0F;
789 }
790
791 #if DIM == 3
792 static void store_texel_rgb565_rev(struct swrast_texture_image *texImage,
793 GLint i, GLint j, GLint k, const void *texel)
794 {
795 const GLchan *rgba = (const GLchan *) texel;
796 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
797 GLushort p = PACK_COLOR_565(CHAN_TO_UBYTE(rgba[RCOMP]),
798 CHAN_TO_UBYTE(rgba[GCOMP]),
799 CHAN_TO_UBYTE(rgba[BCOMP]));
800 *dst = (p >> 8) | (p << 8); /* byte swap */
801 }
802 #endif
803
804
805 /* MESA_FORMAT_ARGB4444 ******************************************************/
806
807 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
808 static void FETCH(f_argb4444)( const struct swrast_texture_image *texImage,
809 GLint i, GLint j, GLint k, GLfloat *texel )
810 {
811 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
812 const GLushort s = *src;
813 texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
814 texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
815 texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
816 texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
817 }
818
819 #if DIM == 3
820 static void store_texel_argb4444(struct swrast_texture_image *texImage,
821 GLint i, GLint j, GLint k, const void *texel)
822 {
823 const GLchan *rgba = (const GLchan *) texel;
824 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
825 *dst = PACK_COLOR_4444(CHAN_TO_UBYTE(rgba[ACOMP]),
826 CHAN_TO_UBYTE(rgba[RCOMP]),
827 CHAN_TO_UBYTE(rgba[GCOMP]),
828 CHAN_TO_UBYTE(rgba[BCOMP]));
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(f_argb4444_rev)( const struct swrast_texture_image *texImage,
837 GLint i, GLint j, GLint k, GLfloat *texel )
838 {
839 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
840 texel[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
841 texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
842 texel[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
843 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
844 }
845
846 #if DIM == 3
847 static void store_texel_argb4444_rev(struct swrast_texture_image *texImage,
848 GLint i, GLint j, GLint k, const void *texel)
849 {
850 const GLchan *rgba = (const GLchan *) texel;
851 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
852 *dst = PACK_COLOR_4444(CHAN_TO_UBYTE(rgba[GCOMP]),
853 CHAN_TO_UBYTE(rgba[BCOMP]),
854 CHAN_TO_UBYTE(rgba[ACOMP]),
855 CHAN_TO_UBYTE(rgba[RCOMP]));
856 }
857 #endif
858
859 /* MESA_FORMAT_RGBA5551 ******************************************************/
860
861 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
862 static void FETCH(f_rgba5551)( const struct swrast_texture_image *texImage,
863 GLint i, GLint j, GLint k, GLfloat *texel )
864 {
865 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
866 const GLushort s = *src;
867 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
868 texel[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
869 texel[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
870 texel[ACOMP] = ((s ) & 0x01) * 1.0F;
871 }
872
873 #if DIM == 3
874 static void store_texel_rgba5551(struct swrast_texture_image *texImage,
875 GLint i, GLint j, GLint k, const void *texel)
876 {
877 const GLubyte *rgba = (const GLubyte *) texel;
878 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
879 *dst = PACK_COLOR_5551(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
880 }
881 #endif
882
883 /* MESA_FORMAT_ARGB1555 ******************************************************/
884
885 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
886 static void FETCH(f_argb1555)( const struct swrast_texture_image *texImage,
887 GLint i, GLint j, GLint k, GLfloat *texel )
888 {
889 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
890 const GLushort s = *src;
891 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
892 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
893 texel[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F);
894 texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
895 }
896
897 #if DIM == 3
898 static void store_texel_argb1555(struct swrast_texture_image *texImage,
899 GLint i, GLint j, GLint k, const void *texel)
900 {
901 const GLubyte *rgba = (const GLubyte *) texel;
902 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
903 *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
904 }
905 #endif
906
907
908 /* MESA_FORMAT_ARGB1555_REV **************************************************/
909
910 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
911 static void FETCH(f_argb1555_rev)( const struct swrast_texture_image *texImage,
912 GLint i, GLint j, GLint k, GLfloat *texel )
913 {
914 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
915 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
916 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
917 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
918 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
919 texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
920 }
921
922 #if DIM == 3
923 static void store_texel_argb1555_rev(struct swrast_texture_image *texImage,
924 GLint i, GLint j, GLint k, const void *texel)
925 {
926 const GLubyte *rgba = (const GLubyte *) texel;
927 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
928 *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
929 }
930 #endif
931
932
933 /* MESA_FORMAT_ARGB2101010 ***************************************************/
934
935 /* Fetch texel from 1D, 2D or 3D argb2101010 texture, return 4 GLchans */
936 static void FETCH(f_argb2101010)( const struct swrast_texture_image *texImage,
937 GLint i, GLint j, GLint k, GLfloat *texel )
938 {
939 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
940 const GLuint s = *src;
941 texel[RCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F);
942 texel[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F);
943 texel[BCOMP] = ((s >> 0) & 0x3ff) * (1.0F / 1023.0F);
944 texel[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F);
945 }
946
947 #if DIM == 3
948 static void store_texel_argb2101010(struct swrast_texture_image *texImage,
949 GLint i, GLint j, GLint k, const void *texel)
950 {
951 const GLchan *rgba = (const GLchan *) texel;
952 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
953 GLushort r = CHAN_TO_USHORT(rgba[RCOMP]);
954 GLushort g = CHAN_TO_USHORT(rgba[GCOMP]);
955 GLushort b = CHAN_TO_USHORT(rgba[BCOMP]);
956 GLushort a = CHAN_TO_USHORT(rgba[ACOMP]);
957 *dst = PACK_COLOR_2101010_US(a, r, g, b);
958 }
959 #endif
960
961
962 /* MESA_FORMAT_RG88 **********************************************************/
963
964 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
965 static void FETCH(f_rg88)( const struct swrast_texture_image *texImage,
966 GLint i, GLint j, GLint k, GLfloat *texel )
967 {
968 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
969 texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
970 texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
971 texel[BCOMP] = 0.0;
972 texel[ACOMP] = 1.0;
973 }
974
975 #if DIM == 3
976 static void store_texel_rg88(struct swrast_texture_image *texImage,
977 GLint i, GLint j, GLint k, const void *texel)
978 {
979 const GLchan *rgba = (const GLchan *) texel;
980 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
981 GLubyte r = CHAN_TO_UBYTE(rgba[RCOMP]);
982 GLubyte g = CHAN_TO_UBYTE(rgba[GCOMP]);
983 *dst = PACK_COLOR_88(g, r);
984 }
985 #endif
986
987
988 /* MESA_FORMAT_RG88_REV ******************************************************/
989
990 /* Fetch texel from 1D, 2D or 3D rg88_rev texture, return 4 GLchans */
991 static void FETCH(f_rg88_rev)( const struct swrast_texture_image *texImage,
992 GLint i, GLint j, GLint k, GLfloat *texel )
993 {
994 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
995 texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
996 texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
997 texel[BCOMP] = 0.0;
998 texel[ACOMP] = 1.0;
999 }
1000
1001 #if DIM == 3
1002 static void store_texel_rg88_rev(struct swrast_texture_image *texImage,
1003 GLint i, GLint j, GLint k, const void *texel)
1004 {
1005 const GLubyte *rgba = (const GLubyte *) texel;
1006 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1007 *dst = PACK_COLOR_88(rgba[GCOMP], rgba[RCOMP]);
1008 }
1009 #endif
1010
1011
1012 /* MESA_FORMAT_AL44 **********************************************************/
1013
1014 /* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
1015 static void FETCH(f_al44)( const struct swrast_texture_image *texImage,
1016 GLint i, GLint j, GLint k, GLfloat *texel )
1017 {
1018 const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1019 texel[RCOMP] =
1020 texel[GCOMP] =
1021 texel[BCOMP] = (s & 0xf) * (1.0F / 15.0F);
1022 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
1023 }
1024
1025 #if DIM == 3
1026 static void store_texel_al44(struct swrast_texture_image *texImage,
1027 GLint i, GLint j, GLint k, const void *texel)
1028 {
1029 const GLubyte *rgba = (const GLubyte *) texel;
1030 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1031 *dst = PACK_COLOR_44(rgba[ACOMP], rgba[RCOMP]);
1032 }
1033 #endif
1034
1035
1036 /* MESA_FORMAT_AL88 **********************************************************/
1037
1038 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
1039 static void FETCH(f_al88)( const struct swrast_texture_image *texImage,
1040 GLint i, GLint j, GLint k, GLfloat *texel )
1041 {
1042 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1043 texel[RCOMP] =
1044 texel[GCOMP] =
1045 texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
1046 texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
1047 }
1048
1049 #if DIM == 3
1050 static void store_texel_al88(struct swrast_texture_image *texImage,
1051 GLint i, GLint j, GLint k, const void *texel)
1052 {
1053 const GLubyte *rgba = (const GLubyte *) texel;
1054 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1055 *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
1056 }
1057 #endif
1058
1059
1060 /* MESA_FORMAT_R8 ************************************************************/
1061
1062 /* Fetch texel from 1D, 2D or 3D rg88 texture, return 4 GLchans */
1063 static void FETCH(f_r8)(const struct swrast_texture_image *texImage,
1064 GLint i, GLint j, GLint k, GLfloat *texel)
1065 {
1066 const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1067 texel[RCOMP] = UBYTE_TO_FLOAT(s);
1068 texel[GCOMP] = 0.0;
1069 texel[BCOMP] = 0.0;
1070 texel[ACOMP] = 1.0;
1071 }
1072
1073 #if DIM == 3
1074 static void store_texel_r8(struct swrast_texture_image *texImage,
1075 GLint i, GLint j, GLint k, const void *texel)
1076 {
1077 const GLubyte *rgba = (const GLubyte *) texel;
1078 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1079 *dst = rgba[RCOMP];
1080 }
1081 #endif
1082
1083
1084 /* MESA_FORMAT_R16 ***********************************************************/
1085
1086 /* Fetch texel from 1D, 2D or 3D r16 texture, return 4 GLchans */
1087 static void FETCH(f_r16)(const struct swrast_texture_image *texImage,
1088 GLint i, GLint j, GLint k, GLfloat *texel)
1089 {
1090 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1091 texel[RCOMP] = USHORT_TO_FLOAT(s);
1092 texel[GCOMP] = 0.0;
1093 texel[BCOMP] = 0.0;
1094 texel[ACOMP] = 1.0;
1095 }
1096
1097 #if DIM == 3
1098 static void store_texel_r16(struct swrast_texture_image *texImage,
1099 GLint i, GLint j, GLint k, const void *texel)
1100 {
1101 const GLchan *rgba = (const GLchan *) texel;
1102 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1103 *dst = CHAN_TO_USHORT(rgba[RCOMP]);
1104 }
1105 #endif
1106
1107
1108 /* MESA_FORMAT_AL88_REV ******************************************************/
1109
1110 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
1111 static void FETCH(f_al88_rev)( const struct swrast_texture_image *texImage,
1112 GLint i, GLint j, GLint k, GLfloat *texel )
1113 {
1114 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1115 texel[RCOMP] =
1116 texel[GCOMP] =
1117 texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
1118 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
1119 }
1120
1121 #if DIM == 3
1122 static void store_texel_al88_rev(struct swrast_texture_image *texImage,
1123 GLint i, GLint j, GLint k, const void *texel)
1124 {
1125 const GLubyte *rgba = (const GLubyte *) texel;
1126 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1127 *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
1128 }
1129 #endif
1130
1131
1132 /* MESA_FORMAT_RG1616 ********************************************************/
1133
1134 /* Fetch texel from 1D, 2D or 3D rg1616 texture, return 4 GLchans */
1135 static void FETCH(f_rg1616)( const struct swrast_texture_image *texImage,
1136 GLint i, GLint j, GLint k, GLfloat *texel )
1137 {
1138 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1139 texel[RCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1140 texel[GCOMP] = USHORT_TO_FLOAT( s >> 16 );
1141 texel[BCOMP] = 0.0;
1142 texel[ACOMP] = 1.0;
1143 }
1144
1145 #if DIM == 3
1146 static void store_texel_rg1616(struct swrast_texture_image *texImage,
1147 GLint i, GLint j, GLint k, const void *texel)
1148 {
1149 const GLchan *rgba = (const GLchan *) texel;
1150 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1151 GLushort r = CHAN_TO_USHORT(rgba[RCOMP]);
1152 GLushort g = CHAN_TO_USHORT(rgba[GCOMP]);
1153 *dst = PACK_COLOR_1616(g, r);
1154 }
1155 #endif
1156
1157
1158 /* MESA_FORMAT_RG1616_REV ****************************************************/
1159
1160 /* Fetch texel from 1D, 2D or 3D rg1616_rev texture, return 4 GLchans */
1161 static void FETCH(f_rg1616_rev)( const struct swrast_texture_image *texImage,
1162 GLint i, GLint j, GLint k, GLfloat *texel )
1163 {
1164 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1165 texel[RCOMP] = USHORT_TO_FLOAT( s >> 16 );
1166 texel[GCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1167 texel[BCOMP] = 0.0;
1168 texel[ACOMP] = 1.0;
1169 }
1170
1171 #if DIM == 3
1172 static void store_texel_rg1616_rev(struct swrast_texture_image *texImage,
1173 GLint i, GLint j, GLint k, const void *texel)
1174 {
1175 const GLubyte *rgba = (const GLubyte *) texel;
1176 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1177 *dst = PACK_COLOR_1616(rgba[GCOMP], rgba[RCOMP]);
1178 }
1179 #endif
1180
1181
1182 /* MESA_FORMAT_AL1616 ********************************************************/
1183
1184 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
1185 static void FETCH(f_al1616)( const struct swrast_texture_image *texImage,
1186 GLint i, GLint j, GLint k, GLfloat *texel )
1187 {
1188 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1189 texel[RCOMP] =
1190 texel[GCOMP] =
1191 texel[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
1192 texel[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
1193 }
1194
1195 #if DIM == 3
1196 static void store_texel_al1616(struct swrast_texture_image *texImage,
1197 GLint i, GLint j, GLint k, const void *texel)
1198 {
1199 const GLchan *rgba = (const GLchan *) texel;
1200 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1201 GLushort l = CHAN_TO_USHORT(rgba[RCOMP]);
1202 GLushort a = CHAN_TO_USHORT(rgba[ACOMP]);
1203 *dst = PACK_COLOR_1616(a, l);
1204 }
1205 #endif
1206
1207
1208 /* MESA_FORMAT_AL1616_REV ****************************************************/
1209
1210 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
1211 static void FETCH(f_al1616_rev)( const struct swrast_texture_image *texImage,
1212 GLint i, GLint j, GLint k, GLfloat *texel )
1213 {
1214 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1215 texel[RCOMP] =
1216 texel[GCOMP] =
1217 texel[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
1218 texel[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
1219 }
1220
1221 #if DIM == 3
1222 static void store_texel_al1616_rev(struct swrast_texture_image *texImage,
1223 GLint i, GLint j, GLint k, const void *texel)
1224 {
1225 const GLushort *rgba = (const GLushort *) texel;
1226 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1227 *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[ACOMP]);
1228 }
1229 #endif
1230
1231
1232 /* MESA_FORMAT_RGB332 ********************************************************/
1233
1234 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
1235 static void FETCH(f_rgb332)( const struct swrast_texture_image *texImage,
1236 GLint i, GLint j, GLint k, GLfloat *texel )
1237 {
1238 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1239 const GLubyte s = *src;
1240 texel[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
1241 texel[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
1242 texel[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F);
1243 texel[ACOMP] = 1.0F;
1244 }
1245
1246 #if DIM == 3
1247 static void store_texel_rgb332(struct swrast_texture_image *texImage,
1248 GLint i, GLint j, GLint k, const void *texel)
1249 {
1250 const GLubyte *rgba = (const GLubyte *) texel;
1251 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1252 *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1253 }
1254 #endif
1255
1256
1257 /* MESA_FORMAT_A8 ************************************************************/
1258
1259 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1260 static void FETCH(f_a8)( const struct swrast_texture_image *texImage,
1261 GLint i, GLint j, GLint k, GLfloat *texel )
1262 {
1263 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1264 texel[RCOMP] =
1265 texel[GCOMP] =
1266 texel[BCOMP] = 0.0F;
1267 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1268 }
1269
1270 #if DIM == 3
1271 static void store_texel_a8(struct swrast_texture_image *texImage,
1272 GLint i, GLint j, GLint k, const void *texel)
1273 {
1274 const GLubyte *rgba = (const GLubyte *) texel;
1275 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1276 *dst = rgba[ACOMP];
1277 }
1278 #endif
1279
1280
1281 /* MESA_FORMAT_A16 ************************************************************/
1282
1283 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
1284 static void FETCH(f_a16)( const struct swrast_texture_image *texImage,
1285 GLint i, GLint j, GLint k, GLfloat *texel )
1286 {
1287 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1288 texel[RCOMP] =
1289 texel[GCOMP] =
1290 texel[BCOMP] = 0.0F;
1291 texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
1292 }
1293
1294 #if DIM == 3
1295 static void store_texel_a16(struct swrast_texture_image *texImage,
1296 GLint i, GLint j, GLint k, const void *texel)
1297 {
1298 const GLchan *rgba = (const GLchan *) texel;
1299 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1300 *dst = CHAN_TO_USHORT(rgba[ACOMP]);
1301 }
1302 #endif
1303
1304
1305 /* MESA_FORMAT_L8 ************************************************************/
1306
1307 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
1308 static void FETCH(f_l8)( const struct swrast_texture_image *texImage,
1309 GLint i, GLint j, GLint k, GLfloat *texel )
1310 {
1311 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1312 texel[RCOMP] =
1313 texel[GCOMP] =
1314 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
1315 texel[ACOMP] = 1.0F;
1316 }
1317
1318 #if DIM == 3
1319 static void store_texel_l8(struct swrast_texture_image *texImage,
1320 GLint i, GLint j, GLint k, const void *texel)
1321 {
1322 const GLubyte *rgba = (const GLubyte *) texel;
1323 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1324 *dst = rgba[RCOMP];
1325 }
1326 #endif
1327
1328
1329 /* MESA_FORMAT_L16 ***********************************************************/
1330
1331 /* Fetch texel from 1D, 2D or 3D l16 texture, return 4 GLchans */
1332 static void FETCH(f_l16)( const struct swrast_texture_image *texImage,
1333 GLint i, GLint j, GLint k, GLfloat *texel )
1334 {
1335 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1336 texel[RCOMP] =
1337 texel[GCOMP] =
1338 texel[BCOMP] = USHORT_TO_FLOAT( src[0] );
1339 texel[ACOMP] = 1.0F;
1340 }
1341
1342 #if DIM == 3
1343 static void store_texel_l16(struct swrast_texture_image *texImage,
1344 GLint i, GLint j, GLint k, const void *texel)
1345 {
1346 const GLchan *rgba = (const GLchan *) texel;
1347 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1348 *dst = CHAN_TO_USHORT(rgba[RCOMP]);
1349 }
1350 #endif
1351
1352
1353 /* MESA_FORMAT_I8 ************************************************************/
1354
1355 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
1356 static void FETCH(f_i8)( const struct swrast_texture_image *texImage,
1357 GLint i, GLint j, GLint k, GLfloat *texel )
1358 {
1359 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1360 texel[RCOMP] =
1361 texel[GCOMP] =
1362 texel[BCOMP] =
1363 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
1364 }
1365
1366 #if DIM == 3
1367 static void store_texel_i8(struct swrast_texture_image *texImage,
1368 GLint i, GLint j, GLint k, const void *texel)
1369 {
1370 const GLubyte *rgba = (const GLubyte *) texel;
1371 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1372 *dst = rgba[RCOMP];
1373 }
1374 #endif
1375
1376
1377 /* MESA_FORMAT_I16 ***********************************************************/
1378
1379 /* Fetch texel from 1D, 2D or 3D i16 texture, return 4 GLchans */
1380 static void FETCH(f_i16)( const struct swrast_texture_image *texImage,
1381 GLint i, GLint j, GLint k, GLfloat *texel )
1382 {
1383 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1384 texel[RCOMP] =
1385 texel[GCOMP] =
1386 texel[BCOMP] =
1387 texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
1388 }
1389
1390 #if DIM == 3
1391 static void store_texel_i16(struct swrast_texture_image *texImage,
1392 GLint i, GLint j, GLint k, const void *texel)
1393 {
1394 const GLchan *rgba = (const GLchan *) texel;
1395 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1396 *dst = CHAN_TO_USHORT(rgba[RCOMP]);
1397 }
1398 #endif
1399
1400
1401 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1402 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1403 static void FETCH(srgb8)(const struct swrast_texture_image *texImage,
1404 GLint i, GLint j, GLint k, GLfloat *texel )
1405 {
1406 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1407 texel[RCOMP] = nonlinear_to_linear(src[2]);
1408 texel[GCOMP] = nonlinear_to_linear(src[1]);
1409 texel[BCOMP] = nonlinear_to_linear(src[0]);
1410 texel[ACOMP] = 1.0F;
1411 }
1412
1413 #if DIM == 3
1414 static void store_texel_srgb8(struct swrast_texture_image *texImage,
1415 GLint i, GLint j, GLint k, const void *texel)
1416 {
1417 const GLubyte *rgba = (const GLubyte *) texel;
1418 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1419 dst[0] = rgba[BCOMP]; /* no conversion */
1420 dst[1] = rgba[GCOMP];
1421 dst[2] = rgba[RCOMP];
1422 }
1423 #endif
1424
1425 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1426 static void FETCH(srgba8)(const struct swrast_texture_image *texImage,
1427 GLint i, GLint j, GLint k, GLfloat *texel )
1428 {
1429 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1430 texel[RCOMP] = nonlinear_to_linear( (s >> 24) );
1431 texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1432 texel[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1433 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */
1434 }
1435
1436 #if DIM == 3
1437 static void store_texel_srgba8(struct swrast_texture_image *texImage,
1438 GLint i, GLint j, GLint k, const void *texel)
1439 {
1440 const GLubyte *rgba = (const GLubyte *) texel;
1441 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1442 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1443 }
1444 #endif
1445
1446 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1447 static void FETCH(sargb8)(const struct swrast_texture_image *texImage,
1448 GLint i, GLint j, GLint k, GLfloat *texel )
1449 {
1450 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1451 texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1452 texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1453 texel[BCOMP] = nonlinear_to_linear( (s ) & 0xff );
1454 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
1455 }
1456
1457 #if DIM == 3
1458 static void store_texel_sargb8(struct swrast_texture_image *texImage,
1459 GLint i, GLint j, GLint k, const void *texel)
1460 {
1461 const GLubyte *rgba = (const GLubyte *) texel;
1462 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1463 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1464 }
1465 #endif
1466
1467 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1468 static void FETCH(sl8)(const struct swrast_texture_image *texImage,
1469 GLint i, GLint j, GLint k, GLfloat *texel )
1470 {
1471 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1472 texel[RCOMP] =
1473 texel[GCOMP] =
1474 texel[BCOMP] = nonlinear_to_linear(src[0]);
1475 texel[ACOMP] = 1.0F;
1476 }
1477
1478 #if DIM == 3
1479 static void store_texel_sl8(struct swrast_texture_image *texImage,
1480 GLint i, GLint j, GLint k, const void *texel)
1481 {
1482 const GLubyte *rgba = (const GLubyte *) texel;
1483 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1484 dst[0] = rgba[RCOMP];
1485 }
1486 #endif
1487
1488 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1489 static void FETCH(sla8)(const struct swrast_texture_image *texImage,
1490 GLint i, GLint j, GLint k, GLfloat *texel )
1491 {
1492 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1493 texel[RCOMP] =
1494 texel[GCOMP] =
1495 texel[BCOMP] = nonlinear_to_linear(src[0]);
1496 texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
1497 }
1498
1499 #if DIM == 3
1500 static void store_texel_sla8(struct swrast_texture_image *texImage,
1501 GLint i, GLint j, GLint k, const void *texel)
1502 {
1503 const GLubyte *rgba = (const GLubyte *) texel;
1504 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
1505 dst[0] = rgba[RCOMP];
1506 dst[1] = rgba[ACOMP];
1507 }
1508 #endif
1509
1510
1511 /* MESA_FORMAT_RGBA_INT8 **************************************************/
1512
1513 static void
1514 FETCH(rgba_int8)(const struct swrast_texture_image *texImage,
1515 GLint i, GLint j, GLint k, GLfloat *texel )
1516 {
1517 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
1518 texel[RCOMP] = (GLfloat) src[0];
1519 texel[GCOMP] = (GLfloat) src[1];
1520 texel[BCOMP] = (GLfloat) src[2];
1521 texel[ACOMP] = (GLfloat) src[3];
1522 }
1523
1524 #if DIM == 3
1525 static void
1526 store_texel_rgba_int8(struct swrast_texture_image *texImage,
1527 GLint i, GLint j, GLint k, const void *texel)
1528 {
1529 const GLbyte *rgba = (const GLbyte *) texel;
1530 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
1531 dst[0] = rgba[RCOMP];
1532 dst[1] = rgba[GCOMP];
1533 dst[2] = rgba[BCOMP];
1534 dst[3] = rgba[ACOMP];
1535 }
1536 #endif
1537
1538
1539 /* MESA_FORMAT_RGBA_INT16 **************************************************/
1540
1541 static void
1542 FETCH(rgba_int16)(const struct swrast_texture_image *texImage,
1543 GLint i, GLint j, GLint k, GLfloat *texel )
1544 {
1545 const GLshort *src = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1546 texel[RCOMP] = (GLfloat) src[0];
1547 texel[GCOMP] = (GLfloat) src[1];
1548 texel[BCOMP] = (GLfloat) src[2];
1549 texel[ACOMP] = (GLfloat) src[3];
1550 }
1551
1552 #if DIM == 3
1553 static void
1554 store_texel_rgba_int16(struct swrast_texture_image *texImage,
1555 GLint i, GLint j, GLint k, const void *texel)
1556 {
1557 const GLshort *rgba = (const GLshort *) texel;
1558 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1559 dst[0] = rgba[RCOMP];
1560 dst[1] = rgba[GCOMP];
1561 dst[2] = rgba[BCOMP];
1562 dst[3] = rgba[ACOMP];
1563 }
1564 #endif
1565
1566
1567 /* MESA_FORMAT_RGBA_INT32 **************************************************/
1568
1569 static void
1570 FETCH(rgba_int32)(const struct swrast_texture_image *texImage,
1571 GLint i, GLint j, GLint k, GLfloat *texel )
1572 {
1573 const GLint *src = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
1574 texel[RCOMP] = (GLfloat) src[0];
1575 texel[GCOMP] = (GLfloat) src[1];
1576 texel[BCOMP] = (GLfloat) src[2];
1577 texel[ACOMP] = (GLfloat) src[3];
1578 }
1579
1580 #if DIM == 3
1581 static void
1582 store_texel_rgba_int32(struct swrast_texture_image *texImage,
1583 GLint i, GLint j, GLint k, const void *texel)
1584 {
1585 const GLint *rgba = (const GLint *) texel;
1586 GLint *dst = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
1587 dst[0] = rgba[RCOMP];
1588 dst[1] = rgba[GCOMP];
1589 dst[2] = rgba[BCOMP];
1590 dst[3] = rgba[ACOMP];
1591 }
1592 #endif
1593
1594
1595 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
1596
1597 static void
1598 FETCH(rgba_uint8)(const struct swrast_texture_image *texImage,
1599 GLint i, GLint j, GLint k, GLfloat *texel )
1600 {
1601 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1602 texel[RCOMP] = (GLfloat) src[0];
1603 texel[GCOMP] = (GLfloat) src[1];
1604 texel[BCOMP] = (GLfloat) src[2];
1605 texel[ACOMP] = (GLfloat) src[3];
1606 }
1607
1608 #if DIM == 3
1609 static void
1610 store_texel_rgba_uint8(struct swrast_texture_image *texImage,
1611 GLint i, GLint j, GLint k, const void *texel)
1612 {
1613 const GLubyte *rgba = (const GLubyte *) texel;
1614 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
1615 dst[0] = rgba[RCOMP];
1616 dst[1] = rgba[GCOMP];
1617 dst[2] = rgba[BCOMP];
1618 dst[3] = rgba[ACOMP];
1619 }
1620 #endif
1621
1622
1623 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
1624
1625 static void
1626 FETCH(rgba_uint16)(const struct swrast_texture_image *texImage,
1627 GLint i, GLint j, GLint k, GLfloat *texel )
1628 {
1629 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1630 texel[RCOMP] = (GLfloat) src[0];
1631 texel[GCOMP] = (GLfloat) src[1];
1632 texel[BCOMP] = (GLfloat) src[2];
1633 texel[ACOMP] = (GLfloat) src[3];
1634 }
1635
1636 #if DIM == 3
1637 static void
1638 store_texel_rgba_uint16(struct swrast_texture_image *texImage,
1639 GLint i, GLint j, GLint k, const void *texel)
1640 {
1641 const GLushort *rgba = (const GLushort *) texel;
1642 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1643 dst[0] = rgba[RCOMP];
1644 dst[1] = rgba[GCOMP];
1645 dst[2] = rgba[BCOMP];
1646 dst[3] = rgba[ACOMP];
1647 }
1648 #endif
1649
1650
1651 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
1652
1653 static void
1654 FETCH(rgba_uint32)(const struct swrast_texture_image *texImage,
1655 GLint i, GLint j, GLint k, GLfloat *texel )
1656 {
1657 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
1658 texel[RCOMP] = (GLfloat) src[0];
1659 texel[GCOMP] = (GLfloat) src[1];
1660 texel[BCOMP] = (GLfloat) src[2];
1661 texel[ACOMP] = (GLfloat) src[3];
1662 }
1663
1664 #if DIM == 3
1665 static void
1666 store_texel_rgba_uint32(struct swrast_texture_image *texImage,
1667 GLint i, GLint j, GLint k, const void *texel)
1668 {
1669 const GLuint *rgba = (const GLuint *) texel;
1670 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
1671 dst[0] = rgba[RCOMP];
1672 dst[1] = rgba[GCOMP];
1673 dst[2] = rgba[BCOMP];
1674 dst[3] = rgba[ACOMP];
1675 }
1676 #endif
1677
1678
1679 /* MESA_FORMAT_DUDV8 ********************************************************/
1680
1681 /* this format by definition produces 0,0,0,1 as rgba values,
1682 however we'll return the dudv values as rg and fix up elsewhere */
1683 static void FETCH(dudv8)(const struct swrast_texture_image *texImage,
1684 GLint i, GLint j, GLint k, GLfloat *texel )
1685 {
1686 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 2);
1687 texel[RCOMP] = BYTE_TO_FLOAT(src[0]);
1688 texel[GCOMP] = BYTE_TO_FLOAT(src[1]);
1689 texel[BCOMP] = 0;
1690 texel[ACOMP] = 0;
1691 }
1692
1693
1694 /* MESA_FORMAT_SIGNED_R8 ***********************************************/
1695
1696 static void FETCH(signed_r8)( const struct swrast_texture_image *texImage,
1697 GLint i, GLint j, GLint k, GLfloat *texel )
1698 {
1699 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1700 texel[RCOMP] = BYTE_TO_FLOAT_TEX( s );
1701 texel[GCOMP] = 0.0F;
1702 texel[BCOMP] = 0.0F;
1703 texel[ACOMP] = 1.0F;
1704 }
1705
1706 #if DIM == 3
1707 static void store_texel_signed_r8(struct swrast_texture_image *texImage,
1708 GLint i, GLint j, GLint k, const void *texel)
1709 {
1710 const GLbyte *rgba = (const GLbyte *) texel;
1711 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1712 *dst = rgba[RCOMP];
1713 }
1714 #endif
1715
1716
1717 /* MESA_FORMAT_SIGNED_A8 ***********************************************/
1718
1719 static void FETCH(signed_a8)( const struct swrast_texture_image *texImage,
1720 GLint i, GLint j, GLint k, GLfloat *texel )
1721 {
1722 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1723 texel[RCOMP] = 0.0F;
1724 texel[GCOMP] = 0.0F;
1725 texel[BCOMP] = 0.0F;
1726 texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
1727 }
1728
1729 #if DIM == 3
1730 static void store_texel_signed_a8(struct swrast_texture_image *texImage,
1731 GLint i, GLint j, GLint k, const void *texel)
1732 {
1733 const GLbyte *rgba = (const GLbyte *) texel;
1734 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1735 *dst = rgba[ACOMP];
1736 }
1737 #endif
1738
1739
1740 /* MESA_FORMAT_SIGNED_L8 ***********************************************/
1741
1742 static void FETCH(signed_l8)( const struct swrast_texture_image *texImage,
1743 GLint i, GLint j, GLint k, GLfloat *texel )
1744 {
1745 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1746 texel[RCOMP] =
1747 texel[GCOMP] =
1748 texel[BCOMP] = BYTE_TO_FLOAT_TEX( s );
1749 texel[ACOMP] = 1.0F;
1750 }
1751
1752 #if DIM == 3
1753 static void store_texel_signed_l8(struct swrast_texture_image *texImage,
1754 GLint i, GLint j, GLint k, const void *texel)
1755 {
1756 const GLbyte *rgba = (const GLbyte *) texel;
1757 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1758 *dst = rgba[RCOMP];
1759 }
1760 #endif
1761
1762
1763 /* MESA_FORMAT_SIGNED_I8 ***********************************************/
1764
1765 static void FETCH(signed_i8)( const struct swrast_texture_image *texImage,
1766 GLint i, GLint j, GLint k, GLfloat *texel )
1767 {
1768 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1769 texel[RCOMP] =
1770 texel[GCOMP] =
1771 texel[BCOMP] =
1772 texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
1773 }
1774
1775 #if DIM == 3
1776 static void store_texel_signed_i8(struct swrast_texture_image *texImage,
1777 GLint i, GLint j, GLint k, const void *texel)
1778 {
1779 const GLbyte *rgba = (const GLbyte *) texel;
1780 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1781 *dst = rgba[RCOMP];
1782 }
1783 #endif
1784
1785
1786 /* MESA_FORMAT_SIGNED_RG88_REV ***********************************************/
1787
1788 static void FETCH(signed_rg88_rev)( const struct swrast_texture_image *texImage,
1789 GLint i, GLint j, GLint k, GLfloat *texel )
1790 {
1791 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1792 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
1793 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1794 texel[BCOMP] = 0.0F;
1795 texel[ACOMP] = 1.0F;
1796 }
1797
1798 #if DIM == 3
1799 static void store_texel_signed_rg88_rev(struct swrast_texture_image *texImage,
1800 GLint i, GLint j, GLint k, const void *texel)
1801 {
1802 const GLbyte *rg = (const GLbyte *) texel;
1803 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1804 dst[0] = PACK_COLOR_88(rg[GCOMP], rg[RCOMP]);
1805 }
1806 #endif
1807
1808
1809 /* MESA_FORMAT_SIGNED_AL88 ***********************************************/
1810
1811 static void FETCH(signed_al88)( const struct swrast_texture_image *texImage,
1812 GLint i, GLint j, GLint k, GLfloat *texel )
1813 {
1814 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1815 texel[RCOMP] =
1816 texel[GCOMP] =
1817 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
1818 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1819 }
1820
1821 #if DIM == 3
1822 static void store_texel_signed_al88(struct swrast_texture_image *texImage,
1823 GLint i, GLint j, GLint k, const void *texel)
1824 {
1825 const GLbyte *rg = (const GLbyte *) texel;
1826 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
1827 dst[0] = PACK_COLOR_88(rg[ACOMP], rg[RCOMP]);
1828 }
1829 #endif
1830
1831
1832 /* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
1833
1834 static void FETCH(signed_rgbx8888)( const struct swrast_texture_image *texImage,
1835 GLint i, GLint j, GLint k, GLfloat *texel )
1836 {
1837 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1838 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1839 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1840 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1841 texel[ACOMP] = 1.0f;
1842 }
1843
1844 #if DIM == 3
1845 static void store_texel_signed_rgbx8888(struct swrast_texture_image *texImage,
1846 GLint i, GLint j, GLint k, const void *texel)
1847 {
1848 const GLbyte *rgba = (const GLbyte *) texel;
1849 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1850 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 255);
1851 }
1852 #endif
1853
1854
1855 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1856
1857 static void FETCH(signed_rgba8888)( const struct swrast_texture_image *texImage,
1858 GLint i, GLint j, GLint k, GLfloat *texel )
1859 {
1860 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1861 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1862 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1863 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1864 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1865 }
1866
1867 #if DIM == 3
1868 static void store_texel_signed_rgba8888(struct swrast_texture_image *texImage,
1869 GLint i, GLint j, GLint k, const void *texel)
1870 {
1871 const GLbyte *rgba = (const GLbyte *) texel;
1872 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1873 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1874 }
1875 #endif
1876
1877 static void FETCH(signed_rgba8888_rev)( const struct swrast_texture_image *texImage,
1878 GLint i, GLint j, GLint k, GLfloat *texel )
1879 {
1880 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1881 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1882 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1883 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1884 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1885 }
1886
1887 #if DIM == 3
1888 static void store_texel_signed_rgba8888_rev(struct swrast_texture_image *texImage,
1889 GLint i, GLint j, GLint k, const void *texel)
1890 {
1891 const GLubyte *rgba = (const GLubyte *) texel;
1892 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1893 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1894 }
1895 #endif
1896
1897
1898
1899 /* MESA_FORMAT_SIGNED_R16 ***********************************************/
1900
1901 static void
1902 FETCH(signed_r16)(const struct swrast_texture_image *texImage,
1903 GLint i, GLint j, GLint k, GLfloat *texel)
1904 {
1905 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1906 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s );
1907 texel[GCOMP] = 0.0F;
1908 texel[BCOMP] = 0.0F;
1909 texel[ACOMP] = 1.0F;
1910 }
1911
1912 #if DIM == 3
1913 static void
1914 store_texel_signed_r16(struct swrast_texture_image *texImage,
1915 GLint i, GLint j, GLint k, const void *texel)
1916 {
1917 const GLshort *rgba = (const GLshort *) texel;
1918 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1919 *dst = rgba[0];
1920 }
1921 #endif
1922
1923
1924 /* MESA_FORMAT_SIGNED_A16 ***********************************************/
1925
1926 static void
1927 FETCH(signed_a16)(const struct swrast_texture_image *texImage,
1928 GLint i, GLint j, GLint k, GLfloat *texel)
1929 {
1930 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1931 texel[RCOMP] = 0.0F;
1932 texel[GCOMP] = 0.0F;
1933 texel[BCOMP] = 0.0F;
1934 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
1935 }
1936
1937 #if DIM == 3
1938 static void
1939 store_texel_signed_a16(struct swrast_texture_image *texImage,
1940 GLint i, GLint j, GLint k, const void *texel)
1941 {
1942 const GLshort *rgba = (const GLshort *) texel;
1943 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1944 *dst = rgba[ACOMP];
1945 }
1946 #endif
1947
1948
1949 /* MESA_FORMAT_SIGNED_L16 ***********************************************/
1950
1951 static void
1952 FETCH(signed_l16)(const struct swrast_texture_image *texImage,
1953 GLint i, GLint j, GLint k, GLfloat *texel)
1954 {
1955 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1956 texel[RCOMP] =
1957 texel[GCOMP] =
1958 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s );
1959 texel[ACOMP] = 1.0F;
1960 }
1961
1962 #if DIM == 3
1963 static void
1964 store_texel_signed_l16(struct swrast_texture_image *texImage,
1965 GLint i, GLint j, GLint k, const void *texel)
1966 {
1967 const GLshort *rgba = (const GLshort *) texel;
1968 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1969 *dst = rgba[RCOMP];
1970 }
1971 #endif
1972
1973
1974 /* MESA_FORMAT_SIGNED_I16 ***********************************************/
1975
1976 static void
1977 FETCH(signed_i16)(const struct swrast_texture_image *texImage,
1978 GLint i, GLint j, GLint k, GLfloat *texel)
1979 {
1980 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1981 texel[RCOMP] =
1982 texel[GCOMP] =
1983 texel[BCOMP] =
1984 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
1985 }
1986
1987 #if DIM == 3
1988 static void
1989 store_texel_signed_i16(struct swrast_texture_image *texImage,
1990 GLint i, GLint j, GLint k, const void *texel)
1991 {
1992 const GLshort *rgba = (const GLshort *) texel;
1993 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1994 *dst = rgba[RCOMP];
1995 }
1996 #endif
1997
1998
1999 /* MESA_FORMAT_SIGNED_RG1616 ***********************************************/
2000
2001 static void
2002 FETCH(signed_rg1616)(const struct swrast_texture_image *texImage,
2003 GLint i, GLint j, GLint k, GLfloat *texel)
2004 {
2005 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2006 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2007 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2008 texel[BCOMP] = 0.0F;
2009 texel[ACOMP] = 1.0F;
2010 }
2011
2012 #if DIM == 3
2013 static void
2014 store_texel_signed_rg1616(struct swrast_texture_image *texImage,
2015 GLint i, GLint j, GLint k, const void *texel)
2016 {
2017 const GLchan *rgba = (const GLchan *) texel;
2018 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2019 dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
2020 dst[1] = CHAN_TO_SHORT(rgba[GCOMP]);
2021 }
2022 #endif
2023
2024
2025 /* MESA_FORMAT_SIGNED_AL1616 ***********************************************/
2026
2027 static void
2028 FETCH(signed_al1616)(const struct swrast_texture_image *texImage,
2029 GLint i, GLint j, GLint k, GLfloat *texel)
2030 {
2031 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2032 texel[RCOMP] =
2033 texel[GCOMP] =
2034 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2035 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2036 }
2037
2038 #if DIM == 3
2039 static void
2040 store_texel_signed_al1616(struct swrast_texture_image *texImage,
2041 GLint i, GLint j, GLint k, const void *texel)
2042 {
2043 const GLchan *rgba = (const GLchan *) texel;
2044 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
2045 dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
2046 dst[1] = CHAN_TO_SHORT(rgba[ACOMP]);
2047 }
2048 #endif
2049
2050
2051 /* MESA_FORMAT_SIGNED_RGB_16 ***********************************************/
2052
2053 static void
2054 FETCH(signed_rgb_16)(const struct swrast_texture_image *texImage,
2055 GLint i, GLint j, GLint k, GLfloat *texel)
2056 {
2057 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
2058 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2059 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2060 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
2061 texel[ACOMP] = 1.0F;
2062 }
2063
2064 #if DIM == 3
2065 static void
2066 store_texel_signed_rgb_16(struct swrast_texture_image *texImage,
2067 GLint i, GLint j, GLint k, const void *texel)
2068 {
2069 const GLchan *rgba = (const GLchan *) texel;
2070 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
2071 dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
2072 dst[1] = CHAN_TO_SHORT(rgba[GCOMP]);
2073 dst[2] = CHAN_TO_SHORT(rgba[BCOMP]);
2074 }
2075 #endif
2076
2077
2078 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
2079
2080 static void
2081 FETCH(signed_rgba_16)(const struct swrast_texture_image *texImage,
2082 GLint i, GLint j, GLint k, GLfloat *texel)
2083 {
2084 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
2085 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
2086 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
2087 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
2088 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
2089 }
2090
2091 #if DIM == 3
2092 static void
2093 store_texel_signed_rgba_16(struct swrast_texture_image *texImage,
2094 GLint i, GLint j, GLint k, const void *texel)
2095 {
2096 const GLchan *rgba = (const GLchan *) texel;
2097 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
2098 dst[0] = CHAN_TO_SHORT(rgba[RCOMP]);
2099 dst[1] = CHAN_TO_SHORT(rgba[GCOMP]);
2100 dst[2] = CHAN_TO_SHORT(rgba[BCOMP]);
2101 dst[3] = CHAN_TO_SHORT(rgba[ACOMP]);
2102 }
2103 #endif
2104
2105
2106
2107 /* MESA_FORMAT_RGBA_16 ***********************************************/
2108
2109 static void
2110 FETCH(rgba_16)(const struct swrast_texture_image *texImage,
2111 GLint i, GLint j, GLint k, GLfloat *texel)
2112 {
2113 const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
2114 texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
2115 texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
2116 texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
2117 texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
2118 }
2119
2120 #if DIM == 3
2121 static void
2122 store_texel_rgba_16(struct swrast_texture_image *texImage,
2123 GLint i, GLint j, GLint k, const void *texel)
2124 {
2125 const GLchan *rgba = (const GLchan *) texel;
2126 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
2127 dst[0] = CHAN_TO_USHORT(rgba[RCOMP]);
2128 dst[1] = CHAN_TO_USHORT(rgba[GCOMP]);
2129 dst[2] = CHAN_TO_USHORT(rgba[BCOMP]);
2130 dst[3] = CHAN_TO_USHORT(rgba[ACOMP]);
2131 }
2132 #endif
2133
2134
2135
2136 /* MESA_FORMAT_YCBCR *********************************************************/
2137
2138 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
2139 * We convert YCbCr to RGB here.
2140 */
2141 static void FETCH(f_ycbcr)( const struct swrast_texture_image *texImage,
2142 GLint i, GLint j, GLint k, GLfloat *texel )
2143 {
2144 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
2145 const GLushort *src1 = src0 + 1; /* odd */
2146 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
2147 const GLubyte cb = *src0 & 0xff; /* chroma U */
2148 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
2149 const GLubyte cr = *src1 & 0xff; /* chroma V */
2150 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
2151 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
2152 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
2153 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
2154 r *= (1.0F / 255.0F);
2155 g *= (1.0F / 255.0F);
2156 b *= (1.0F / 255.0F);
2157 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
2158 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
2159 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
2160 texel[ACOMP] = 1.0F;
2161 }
2162
2163 #if DIM == 3
2164 static void store_texel_ycbcr(struct swrast_texture_image *texImage,
2165 GLint i, GLint j, GLint k, const void *texel)
2166 {
2167 (void) texImage;
2168 (void) i;
2169 (void) j;
2170 (void) k;
2171 (void) texel;
2172 /* XXX to do */
2173 }
2174 #endif
2175
2176
2177 /* MESA_FORMAT_YCBCR_REV *****************************************************/
2178
2179 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
2180 * We convert YCbCr to RGB here.
2181 */
2182 static void FETCH(f_ycbcr_rev)( const struct swrast_texture_image *texImage,
2183 GLint i, GLint j, GLint k, GLfloat *texel )
2184 {
2185 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
2186 const GLushort *src1 = src0 + 1; /* odd */
2187 const GLubyte y0 = *src0 & 0xff; /* luminance */
2188 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
2189 const GLubyte y1 = *src1 & 0xff; /* luminance */
2190 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
2191 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
2192 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
2193 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
2194 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
2195 r *= (1.0F / 255.0F);
2196 g *= (1.0F / 255.0F);
2197 b *= (1.0F / 255.0F);
2198 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
2199 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
2200 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
2201 texel[ACOMP] = 1.0F;
2202 }
2203
2204 #if DIM == 3
2205 static void store_texel_ycbcr_rev(struct swrast_texture_image *texImage,
2206 GLint i, GLint j, GLint k, const void *texel)
2207 {
2208 (void) texImage;
2209 (void) i;
2210 (void) j;
2211 (void) k;
2212 (void) texel;
2213 /* XXX to do */
2214 }
2215 #endif
2216
2217
2218 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
2219
2220 static void FETCH(f_z24_s8)( const struct swrast_texture_image *texImage,
2221 GLint i, GLint j, GLint k, GLfloat *texel )
2222 {
2223 /* only return Z, not stencil data */
2224 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2225 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
2226 texel[0] = ((*src) >> 8) * scale;
2227 ASSERT(texImage->Base.TexFormat == MESA_FORMAT_Z24_S8 ||
2228 texImage->Base.TexFormat == MESA_FORMAT_Z24_X8);
2229 ASSERT(texel[0] >= 0.0F);
2230 ASSERT(texel[0] <= 1.0F);
2231 }
2232
2233 #if DIM == 3
2234 static void store_texel_z24_s8(struct swrast_texture_image *texImage,
2235 GLint i, GLint j, GLint k, const void *texel)
2236 {
2237 /* only store Z, not stencil */
2238 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2239 GLfloat depth = *((GLfloat *) texel);
2240 GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
2241 *dst = zi | (*dst & 0xff);
2242 }
2243 #endif
2244
2245
2246 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
2247
2248 static void FETCH(f_s8_z24)( const struct swrast_texture_image *texImage,
2249 GLint i, GLint j, GLint k, GLfloat *texel )
2250 {
2251 /* only return Z, not stencil data */
2252 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2253 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
2254 texel[0] = ((*src) & 0x00ffffff) * scale;
2255 ASSERT(texImage->Base.TexFormat == MESA_FORMAT_S8_Z24 ||
2256 texImage->Base.TexFormat == MESA_FORMAT_X8_Z24);
2257 ASSERT(texel[0] >= 0.0F);
2258 ASSERT(texel[0] <= 1.0F);
2259 }
2260
2261 #if DIM == 3
2262 static void store_texel_s8_z24(struct swrast_texture_image *texImage,
2263 GLint i, GLint j, GLint k, const void *texel)
2264 {
2265 /* only store Z, not stencil */
2266 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2267 GLfloat depth = *((GLfloat *) texel);
2268 GLuint zi = (GLuint) (depth * 0xffffff);
2269 *dst = zi | (*dst & 0xff000000);
2270 }
2271 #endif
2272
2273
2274 /* MESA_FORMAT_RGB9_E5 ******************************************************/
2275
2276 static void FETCH(rgb9_e5)( const struct swrast_texture_image *texImage,
2277 GLint i, GLint j, GLint k, GLfloat *texel )
2278 {
2279 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2280 rgb9e5_to_float3(*src, texel);
2281 texel[ACOMP] = 1.0F;
2282 }
2283
2284 #if DIM == 3
2285 static void store_texel_rgb9_e5(struct swrast_texture_image *texImage,
2286 GLint i, GLint j, GLint k, const void *texel)
2287 {
2288 const GLfloat *src = (const GLfloat *) texel;
2289 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2290 *dst = float3_to_rgb9e5(src);
2291 }
2292 #endif
2293
2294
2295 /* MESA_FORMAT_R11_G11_B10_FLOAT *********************************************/
2296
2297 static void FETCH(r11_g11_b10f)( const struct swrast_texture_image *texImage,
2298 GLint i, GLint j, GLint k, GLfloat *texel )
2299 {
2300 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2301 r11g11b10f_to_float3(*src, texel);
2302 texel[ACOMP] = 1.0F;
2303 }
2304
2305 #if DIM == 3
2306 static void store_texel_r11_g11_b10f(struct swrast_texture_image *texImage,
2307 GLint i, GLint j, GLint k, const void *texel)
2308 {
2309 const GLfloat *src = (const GLfloat *) texel;
2310 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
2311 *dst = float3_to_r11g11b10f(src);
2312 }
2313 #endif
2314
2315
2316 /* MESA_FORMAT_Z32_FLOAT_X24S8 ***********************************************/
2317
2318 static void FETCH(z32f_x24s8)(const struct swrast_texture_image *texImage,
2319 GLint i, GLint j, GLint k, GLfloat *texel)
2320 {
2321 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
2322 texel[RCOMP] = src[0];
2323 texel[GCOMP] = 0.0F;
2324 texel[BCOMP] = 0.0F;
2325 texel[ACOMP] = 1.0F;
2326 }
2327
2328 #if DIM == 3
2329 static void store_texel_z32f_x24s8(struct swrast_texture_image *texImage,
2330 GLint i, GLint j, GLint k, const void *texel)
2331 {
2332 const GLfloat *src = (const GLfloat *) texel;
2333 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
2334 dst[0] = src[0];
2335 }
2336 #endif
2337
2338
2339 #undef TEXEL_ADDR
2340 #undef DIM
2341 #undef FETCH