mesa: added unsigned 16-bit/channel tex format
[mesa.git] / src / mesa / main / 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 gl_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 gl_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 gl_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 gl_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 gl_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 gl_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, 1);
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 gl_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 gl_texture_image *texImage,
164 GLint i, GLint j, GLint k, const void *texel)
165 {
166 const GLfloat *depth = (const GLfloat *) texel;
167 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
168 dst[0] = _mesa_float_to_half(*depth);
169 }
170 #endif
171
172 /* MESA_FORMAT_RGB_F32 *******************************************************/
173
174 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
175 * returning 4 GLfloats.
176 */
177 static void FETCH(f_rgb_f32)( const struct gl_texture_image *texImage,
178 GLint i, GLint j, GLint k, GLfloat *texel )
179 {
180 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
181 texel[RCOMP] = src[0];
182 texel[GCOMP] = src[1];
183 texel[BCOMP] = src[2];
184 texel[ACOMP] = 1.0F;
185 }
186
187 #if DIM == 3
188 static void store_texel_rgb_f32(struct gl_texture_image *texImage,
189 GLint i, GLint j, GLint k, const void *texel)
190 {
191 const GLfloat *depth = (const GLfloat *) texel;
192 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
193 dst[0] = *depth;
194 }
195 #endif
196
197
198 /* MESA_FORMAT_RGB_F16 *******************************************************/
199
200 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
201 * returning 4 GLfloats.
202 */
203 static void FETCH(f_rgb_f16)( const struct gl_texture_image *texImage,
204 GLint i, GLint j, GLint k, GLfloat *texel )
205 {
206 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
207 texel[RCOMP] = _mesa_half_to_float(src[0]);
208 texel[GCOMP] = _mesa_half_to_float(src[1]);
209 texel[BCOMP] = _mesa_half_to_float(src[2]);
210 texel[ACOMP] = 1.0F;
211 }
212
213 #if DIM == 3
214 static void store_texel_rgb_f16(struct gl_texture_image *texImage,
215 GLint i, GLint j, GLint k, const void *texel)
216 {
217 const GLfloat *depth = (const GLfloat *) texel;
218 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
219 dst[0] = _mesa_float_to_half(*depth);
220 }
221 #endif
222
223
224 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
225
226 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
227 * returning 4 GLfloats.
228 */
229 static void FETCH(f_alpha_f32)( const struct gl_texture_image *texImage,
230 GLint i, GLint j, GLint k, GLfloat *texel )
231 {
232 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
233 texel[RCOMP] =
234 texel[GCOMP] =
235 texel[BCOMP] = 0.0F;
236 texel[ACOMP] = src[0];
237 }
238
239 #if DIM == 3
240 static void store_texel_alpha_f32(struct gl_texture_image *texImage,
241 GLint i, GLint j, GLint k, const void *texel)
242 {
243 const GLfloat *rgba = (const GLfloat *) texel;
244 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
245 dst[0] = rgba[ACOMP];
246 }
247 #endif
248
249
250 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
251
252 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
253 * returning 4 GLfloats.
254 */
255 static void FETCH(f_alpha_f16)( const struct gl_texture_image *texImage,
256 GLint i, GLint j, GLint k, GLfloat *texel )
257 {
258 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
259 texel[RCOMP] =
260 texel[GCOMP] =
261 texel[BCOMP] = 0.0F;
262 texel[ACOMP] = _mesa_half_to_float(src[0]);
263 }
264
265 #if DIM == 3
266 static void store_texel_alpha_f16(struct gl_texture_image *texImage,
267 GLint i, GLint j, GLint k, const void *texel)
268 {
269 const GLfloat *rgba = (const GLfloat *) texel;
270 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
271 dst[0] = _mesa_float_to_half(rgba[ACOMP]);
272 }
273 #endif
274
275
276 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
277
278 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
279 * returning 4 GLfloats.
280 */
281 static void FETCH(f_luminance_f32)( const struct gl_texture_image *texImage,
282 GLint i, GLint j, GLint k, GLfloat *texel )
283 {
284 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
285 texel[RCOMP] =
286 texel[GCOMP] =
287 texel[BCOMP] = src[0];
288 texel[ACOMP] = 1.0F;
289 }
290
291 #if DIM == 3
292 static void store_texel_luminance_f32(struct gl_texture_image *texImage,
293 GLint i, GLint j, GLint k, const void *texel)
294 {
295 const GLfloat *rgba = (const GLfloat *) texel;
296 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
297 dst[0] = rgba[RCOMP];
298 }
299 #endif
300
301
302 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
303
304 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
305 * returning 4 GLfloats.
306 */
307 static void FETCH(f_luminance_f16)( const struct gl_texture_image *texImage,
308 GLint i, GLint j, GLint k, GLfloat *texel )
309 {
310 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
311 texel[RCOMP] =
312 texel[GCOMP] =
313 texel[BCOMP] = _mesa_half_to_float(src[0]);
314 texel[ACOMP] = 1.0F;
315 }
316
317 #if DIM == 3
318 static void store_texel_luminance_f16(struct gl_texture_image *texImage,
319 GLint i, GLint j, GLint k, const void *texel)
320 {
321 const GLfloat *rgba = (const GLfloat *) texel;
322 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
323 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
324 }
325 #endif
326
327
328 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
329
330 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
331 * returning 4 GLfloats.
332 */
333 static void FETCH(f_luminance_alpha_f32)( const struct gl_texture_image *texImage,
334 GLint i, GLint j, GLint k, GLfloat *texel )
335 {
336 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
337 texel[RCOMP] =
338 texel[GCOMP] =
339 texel[BCOMP] = src[0];
340 texel[ACOMP] = src[1];
341 }
342
343 #if DIM == 3
344 static void store_texel_luminance_alpha_f32(struct gl_texture_image *texImage,
345 GLint i, GLint j, GLint k, const void *texel)
346 {
347 const GLfloat *rgba = (const GLfloat *) texel;
348 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
349 dst[0] = rgba[RCOMP];
350 dst[1] = rgba[ACOMP];
351 }
352 #endif
353
354
355 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
356
357 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
358 * returning 4 GLfloats.
359 */
360 static void FETCH(f_luminance_alpha_f16)( const struct gl_texture_image *texImage,
361 GLint i, GLint j, GLint k, GLfloat *texel )
362 {
363 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
364 texel[RCOMP] =
365 texel[GCOMP] =
366 texel[BCOMP] = _mesa_half_to_float(src[0]);
367 texel[ACOMP] = _mesa_half_to_float(src[1]);
368 }
369
370 #if DIM == 3
371 static void store_texel_luminance_alpha_f16(struct gl_texture_image *texImage,
372 GLint i, GLint j, GLint k, const void *texel)
373 {
374 const GLfloat *rgba = (const GLfloat *) texel;
375 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
376 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
377 dst[1] = _mesa_float_to_half(rgba[ACOMP]);
378 }
379 #endif
380
381
382 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
383
384 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
385 * returning 4 GLfloats.
386 */
387 static void FETCH(f_intensity_f32)( const struct gl_texture_image *texImage,
388 GLint i, GLint j, GLint k, GLfloat *texel )
389 {
390 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
391 texel[RCOMP] =
392 texel[GCOMP] =
393 texel[BCOMP] =
394 texel[ACOMP] = src[0];
395 }
396
397 #if DIM == 3
398 static void store_texel_intensity_f32(struct gl_texture_image *texImage,
399 GLint i, GLint j, GLint k, const void *texel)
400 {
401 const GLfloat *rgba = (const GLfloat *) texel;
402 GLfloat *dst = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
403 dst[0] = rgba[RCOMP];
404 }
405 #endif
406
407
408 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
409
410 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
411 * returning 4 GLfloats.
412 */
413 static void FETCH(f_intensity_f16)( const struct gl_texture_image *texImage,
414 GLint i, GLint j, GLint k, GLfloat *texel )
415 {
416 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
417 texel[RCOMP] =
418 texel[GCOMP] =
419 texel[BCOMP] =
420 texel[ACOMP] = _mesa_half_to_float(src[0]);
421 }
422
423 #if DIM == 3
424 static void store_texel_intensity_f16(struct gl_texture_image *texImage,
425 GLint i, GLint j, GLint k, const void *texel)
426 {
427 const GLfloat *rgba = (const GLfloat *) texel;
428 GLhalfARB *dst = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
429 dst[0] = _mesa_float_to_half(rgba[RCOMP]);
430 }
431 #endif
432
433
434
435
436 /*
437 * Begin Hardware formats
438 */
439
440 /* MESA_FORMAT_RGBA8888 ******************************************************/
441
442 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
443 static void FETCH(f_rgba8888)( const struct gl_texture_image *texImage,
444 GLint i, GLint j, GLint k, GLfloat *texel )
445 {
446 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
447 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
448 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
449 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
450 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
451 }
452
453
454
455 #if DIM == 3
456 static void store_texel_rgba8888(struct gl_texture_image *texImage,
457 GLint i, GLint j, GLint k, const void *texel)
458 {
459 const GLubyte *rgba = (const GLubyte *) texel;
460 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
461 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
462 }
463 #endif
464
465
466 /* MESA_FORMAT_RGBA888_REV ***************************************************/
467
468 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
469 static void FETCH(f_rgba8888_rev)( const struct gl_texture_image *texImage,
470 GLint i, GLint j, GLint k, GLfloat *texel )
471 {
472 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
473 texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
474 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
475 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
476 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
477 }
478
479 #if DIM == 3
480 static void store_texel_rgba8888_rev(struct gl_texture_image *texImage,
481 GLint i, GLint j, GLint k, const void *texel)
482 {
483 const GLubyte *rgba = (const GLubyte *) texel;
484 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
485 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
486 }
487 #endif
488
489
490 /* MESA_FORMAT_ARGB8888 ******************************************************/
491
492 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
493 static void FETCH(f_argb8888)( const struct gl_texture_image *texImage,
494 GLint i, GLint j, GLint k, GLfloat *texel )
495 {
496 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
497 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
498 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
499 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
500 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
501 }
502
503 #if DIM == 3
504 static void store_texel_argb8888(struct gl_texture_image *texImage,
505 GLint i, GLint j, GLint k, const void *texel)
506 {
507 const GLubyte *rgba = (const GLubyte *) texel;
508 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
509 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
510 }
511 #endif
512
513
514 /* MESA_FORMAT_ARGB8888_REV **************************************************/
515
516 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
517 static void FETCH(f_argb8888_rev)( const struct gl_texture_image *texImage,
518 GLint i, GLint j, GLint k, GLfloat *texel )
519 {
520 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
521 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
522 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
523 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
524 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
525 }
526
527 #if DIM == 3
528 static void store_texel_argb8888_rev(struct gl_texture_image *texImage,
529 GLint i, GLint j, GLint k, const void *texel)
530 {
531 const GLubyte *rgba = (const GLubyte *) texel;
532 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
533 *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], rgba[ACOMP]);
534 }
535 #endif
536
537
538 /* MESA_FORMAT_XRGB8888 ******************************************************/
539
540 /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
541 static void FETCH(f_xrgb8888)( const struct gl_texture_image *texImage,
542 GLint i, GLint j, GLint k, GLfloat *texel )
543 {
544 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
545 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
546 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
547 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
548 texel[ACOMP] = 1.0f;
549 }
550
551 #if DIM == 3
552 static void store_texel_xrgb8888(struct gl_texture_image *texImage,
553 GLint i, GLint j, GLint k, const void *texel)
554 {
555 const GLubyte *rgba = (const GLubyte *) texel;
556 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
557 *dst = PACK_COLOR_8888(0xff, rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
558 }
559 #endif
560
561
562 /* MESA_FORMAT_XRGB8888_REV **************************************************/
563
564 /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
565 static void FETCH(f_xrgb8888_rev)( const struct gl_texture_image *texImage,
566 GLint i, GLint j, GLint k, GLfloat *texel )
567 {
568 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
569 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
570 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
571 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
572 texel[ACOMP] = 1.0f;
573 }
574
575 #if DIM == 3
576 static void store_texel_xrgb8888_rev(struct gl_texture_image *texImage,
577 GLint i, GLint j, GLint k, const void *texel)
578 {
579 const GLubyte *rgba = (const GLubyte *) texel;
580 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
581 *dst = PACK_COLOR_8888(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP], 0xff);
582 }
583 #endif
584
585
586 /* MESA_FORMAT_RGB888 ********************************************************/
587
588 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
589 static void FETCH(f_rgb888)( const struct gl_texture_image *texImage,
590 GLint i, GLint j, GLint k, GLfloat *texel )
591 {
592 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
593 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
594 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
595 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
596 texel[ACOMP] = 1.0F;
597 }
598
599 #if DIM == 3
600 static void store_texel_rgb888(struct gl_texture_image *texImage,
601 GLint i, GLint j, GLint k, const void *texel)
602 {
603 const GLubyte *rgba = (const GLubyte *) texel;
604 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
605 dst[0] = rgba[BCOMP];
606 dst[1] = rgba[GCOMP];
607 dst[2] = rgba[RCOMP];
608 }
609 #endif
610
611
612 /* MESA_FORMAT_BGR888 ********************************************************/
613
614 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
615 static void FETCH(f_bgr888)( const struct gl_texture_image *texImage,
616 GLint i, GLint j, GLint k, GLfloat *texel )
617 {
618 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
619 texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
620 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
621 texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
622 texel[ACOMP] = 1.0F;
623 }
624
625 #if DIM == 3
626 static void store_texel_bgr888(struct gl_texture_image *texImage,
627 GLint i, GLint j, GLint k, const void *texel)
628 {
629 const GLubyte *rgba = (const GLubyte *) texel;
630 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
631 dst[0] = rgba[RCOMP];
632 dst[1] = rgba[GCOMP];
633 dst[2] = rgba[BCOMP];
634 }
635 #endif
636
637
638 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
639 instead of slow (g << 2) * 255 / 252 (always rounds down) */
640
641 /* MESA_FORMAT_RGB565 ********************************************************/
642
643 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
644 static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
645 GLint i, GLint j, GLint k, GLfloat *texel )
646 {
647 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
648 const GLushort s = *src;
649 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
650 texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
651 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
652 texel[ACOMP] = 1.0F;
653 }
654
655 #if DIM == 3
656 static void store_texel_rgb565(struct gl_texture_image *texImage,
657 GLint i, GLint j, GLint k, const void *texel)
658 {
659 const GLubyte *rgba = (const GLubyte *) texel;
660 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
661 *dst = PACK_COLOR_565(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
662 }
663 #endif
664
665
666 /* MESA_FORMAT_RGB565_REV ****************************************************/
667
668 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
669 static void FETCH(f_rgb565_rev)( const struct gl_texture_image *texImage,
670 GLint i, GLint j, GLint k, GLfloat *texel )
671 {
672 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
673 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
674 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
675 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
676 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
677 texel[ACOMP] = 1.0F;
678 }
679
680 #if DIM == 3
681 static void store_texel_rgb565_rev(struct gl_texture_image *texImage,
682 GLint i, GLint j, GLint k, const void *texel)
683 {
684 const GLubyte *rgba = (const GLubyte *) texel;
685 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
686 *dst = PACK_COLOR_565(rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
687 }
688 #endif
689
690
691 /* MESA_FORMAT_ARGB4444 ******************************************************/
692
693 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
694 static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
695 GLint i, GLint j, GLint k, GLfloat *texel )
696 {
697 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
698 const GLushort s = *src;
699 texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
700 texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
701 texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
702 texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
703 }
704
705 #if DIM == 3
706 static void store_texel_argb4444(struct gl_texture_image *texImage,
707 GLint i, GLint j, GLint k, const void *texel)
708 {
709 const GLubyte *rgba = (const GLubyte *) texel;
710 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
711 *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
712 }
713 #endif
714
715
716 /* MESA_FORMAT_ARGB4444_REV **************************************************/
717
718 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
719 static void FETCH(f_argb4444_rev)( const struct gl_texture_image *texImage,
720 GLint i, GLint j, GLint k, GLfloat *texel )
721 {
722 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
723 texel[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
724 texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
725 texel[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
726 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
727 }
728
729 #if DIM == 3
730 static void store_texel_argb4444_rev(struct gl_texture_image *texImage,
731 GLint i, GLint j, GLint k, const void *texel)
732 {
733 const GLubyte *rgba = (const GLubyte *) texel;
734 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
735 *dst = PACK_COLOR_4444(rgba[ACOMP], rgba[BCOMP], rgba[GCOMP], rgba[RCOMP]);
736 }
737 #endif
738
739 /* MESA_FORMAT_RGBA5551 ******************************************************/
740
741 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
742 static void FETCH(f_rgba5551)( const struct gl_texture_image *texImage,
743 GLint i, GLint j, GLint k, GLfloat *texel )
744 {
745 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
746 const GLushort s = *src;
747 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
748 texel[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
749 texel[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
750 texel[ACOMP] = ((s ) & 0x01) * 1.0F;
751 }
752
753 #if DIM == 3
754 static void store_texel_rgba5551(struct gl_texture_image *texImage,
755 GLint i, GLint j, GLint k, const void *texel)
756 {
757 const GLubyte *rgba = (const GLubyte *) texel;
758 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
759 *dst = PACK_COLOR_5551(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
760 }
761 #endif
762
763 /* MESA_FORMAT_ARGB1555 ******************************************************/
764
765 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
766 static void FETCH(f_argb1555)( const struct gl_texture_image *texImage,
767 GLint i, GLint j, GLint k, GLfloat *texel )
768 {
769 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
770 const GLushort s = *src;
771 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
772 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
773 texel[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F);
774 texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
775 }
776
777 #if DIM == 3
778 static void store_texel_argb1555(struct gl_texture_image *texImage,
779 GLint i, GLint j, GLint k, const void *texel)
780 {
781 const GLubyte *rgba = (const GLubyte *) texel;
782 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
783 *dst = PACK_COLOR_1555(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
784 }
785 #endif
786
787
788 /* MESA_FORMAT_ARGB1555_REV **************************************************/
789
790 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
791 static void FETCH(f_argb1555_rev)( const struct gl_texture_image *texImage,
792 GLint i, GLint j, GLint k, GLfloat *texel )
793 {
794 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
795 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
796 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
797 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
798 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
799 texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
800 }
801
802 #if DIM == 3
803 static void store_texel_argb1555_rev(struct gl_texture_image *texImage,
804 GLint i, GLint j, GLint k, const void *texel)
805 {
806 const GLubyte *rgba = (const GLubyte *) texel;
807 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
808 *dst = PACK_COLOR_1555_REV(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
809 }
810 #endif
811
812
813 /* MESA_FORMAT_AL88 **********************************************************/
814
815 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
816 static void FETCH(f_al88)( const struct gl_texture_image *texImage,
817 GLint i, GLint j, GLint k, GLfloat *texel )
818 {
819 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
820 texel[RCOMP] =
821 texel[GCOMP] =
822 texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
823 texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
824 }
825
826 #if DIM == 3
827 static void store_texel_al88(struct gl_texture_image *texImage,
828 GLint i, GLint j, GLint k, const void *texel)
829 {
830 const GLubyte *rgba = (const GLubyte *) texel;
831 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
832 *dst = PACK_COLOR_88(rgba[ACOMP], rgba[RCOMP]);
833 }
834 #endif
835
836
837 /* MESA_FORMAT_AL88_REV ******************************************************/
838
839 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
840 static void FETCH(f_al88_rev)( const struct gl_texture_image *texImage,
841 GLint i, GLint j, GLint k, GLfloat *texel )
842 {
843 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
844 texel[RCOMP] =
845 texel[GCOMP] =
846 texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
847 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
848 }
849
850 #if DIM == 3
851 static void store_texel_al88_rev(struct gl_texture_image *texImage,
852 GLint i, GLint j, GLint k, const void *texel)
853 {
854 const GLubyte *rgba = (const GLubyte *) texel;
855 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
856 *dst = PACK_COLOR_88(rgba[RCOMP], rgba[ACOMP]);
857 }
858 #endif
859
860
861 /* MESA_FORMAT_AL1616 ********************************************************/
862
863 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
864 static void FETCH(f_al1616)( const struct gl_texture_image *texImage,
865 GLint i, GLint j, GLint k, GLfloat *texel )
866 {
867 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
868 texel[RCOMP] =
869 texel[GCOMP] =
870 texel[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
871 texel[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
872 }
873
874 #if DIM == 3
875 static void store_texel_al1616(struct gl_texture_image *texImage,
876 GLint i, GLint j, GLint k, const void *texel)
877 {
878 const GLushort *rgba = (const GLushort *) texel;
879 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
880 *dst = PACK_COLOR_1616(rgba[ACOMP], rgba[RCOMP]);
881 }
882 #endif
883
884
885 /* MESA_FORMAT_AL1616_REV ****************************************************/
886
887 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
888 static void FETCH(f_al1616_rev)( const struct gl_texture_image *texImage,
889 GLint i, GLint j, GLint k, GLfloat *texel )
890 {
891 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
892 texel[RCOMP] =
893 texel[GCOMP] =
894 texel[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
895 texel[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
896 }
897
898 #if DIM == 3
899 static void store_texel_al1616_rev(struct gl_texture_image *texImage,
900 GLint i, GLint j, GLint k, const void *texel)
901 {
902 const GLushort *rgba = (const GLushort *) texel;
903 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
904 *dst = PACK_COLOR_1616(rgba[RCOMP], rgba[ACOMP]);
905 }
906 #endif
907
908
909 /* MESA_FORMAT_RGB332 ********************************************************/
910
911 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
912 static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
913 GLint i, GLint j, GLint k, GLfloat *texel )
914 {
915 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
916 const GLubyte s = *src;
917 texel[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
918 texel[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
919 texel[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F);
920 texel[ACOMP] = 1.0F;
921 }
922
923 #if DIM == 3
924 static void store_texel_rgb332(struct gl_texture_image *texImage,
925 GLint i, GLint j, GLint k, const void *texel)
926 {
927 const GLubyte *rgba = (const GLubyte *) texel;
928 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
929 *dst = PACK_COLOR_332(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
930 }
931 #endif
932
933
934 /* MESA_FORMAT_A8 ************************************************************/
935
936 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
937 static void FETCH(f_a8)( const struct gl_texture_image *texImage,
938 GLint i, GLint j, GLint k, GLfloat *texel )
939 {
940 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
941 texel[RCOMP] =
942 texel[GCOMP] =
943 texel[BCOMP] = 0.0F;
944 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
945 }
946
947 #if DIM == 3
948 static void store_texel_a8(struct gl_texture_image *texImage,
949 GLint i, GLint j, GLint k, const void *texel)
950 {
951 const GLubyte *rgba = (const GLubyte *) texel;
952 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
953 *dst = rgba[ACOMP];
954 }
955 #endif
956
957
958 /* MESA_FORMAT_L8 ************************************************************/
959
960 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
961 static void FETCH(f_l8)( const struct gl_texture_image *texImage,
962 GLint i, GLint j, GLint k, GLfloat *texel )
963 {
964 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
965 texel[RCOMP] =
966 texel[GCOMP] =
967 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
968 texel[ACOMP] = 1.0F;
969 }
970
971 #if DIM == 3
972 static void store_texel_l8(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 = rgba[RCOMP];
978 }
979 #endif
980
981
982 /* MESA_FORMAT_I8 ************************************************************/
983
984 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
985 static void FETCH(f_i8)( const struct gl_texture_image *texImage,
986 GLint i, GLint j, GLint k, GLfloat *texel )
987 {
988 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
989 texel[RCOMP] =
990 texel[GCOMP] =
991 texel[BCOMP] =
992 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
993 }
994
995 #if DIM == 3
996 static void store_texel_i8(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[RCOMP];
1002 }
1003 #endif
1004
1005
1006 /* MESA_FORMAT_CI8 ***********************************************************/
1007
1008 /* Fetch CI texel from 1D, 2D or 3D ci8 texture, lookup the index in a
1009 * color table, and return 4 GLchans.
1010 */
1011 static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
1012 GLint i, GLint j, GLint k, GLfloat *texel )
1013 {
1014 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1015 const struct gl_color_table *palette;
1016 GLuint index;
1017 GET_CURRENT_CONTEXT(ctx);
1018
1019 if (ctx->Texture.SharedPalette) {
1020 palette = &ctx->Texture.Palette;
1021 }
1022 else {
1023 palette = &texImage->TexObject->Palette;
1024 }
1025 if (palette->Size == 0)
1026 return; /* undefined results */
1027
1028 /* Mask the index against size of palette to avoid going out of bounds */
1029 index = (*src) & (palette->Size - 1);
1030
1031 {
1032 const GLfloat *table = palette->TableF;
1033 switch (palette->_BaseFormat) {
1034 case GL_ALPHA:
1035 texel[RCOMP] =
1036 texel[GCOMP] =
1037 texel[BCOMP] = 0.0F;
1038 texel[ACOMP] = table[index];
1039 break;
1040 case GL_LUMINANCE:
1041 texel[RCOMP] =
1042 texel[GCOMP] =
1043 texel[BCOMP] = table[index];
1044 texel[ACOMP] = 1.0F;
1045 break;
1046 case GL_INTENSITY:
1047 texel[RCOMP] =
1048 texel[GCOMP] =
1049 texel[BCOMP] =
1050 texel[ACOMP] = table[index];
1051 break;
1052 case GL_LUMINANCE_ALPHA:
1053 texel[RCOMP] =
1054 texel[GCOMP] =
1055 texel[BCOMP] = table[index * 2 + 0];
1056 texel[ACOMP] = table[index * 2 + 1];
1057 break;
1058 case GL_RGB:
1059 texel[RCOMP] = table[index * 3 + 0];
1060 texel[GCOMP] = table[index * 3 + 1];
1061 texel[BCOMP] = table[index * 3 + 2];
1062 texel[ACOMP] = 1.0F;
1063 break;
1064 case GL_RGBA:
1065 texel[RCOMP] = table[index * 4 + 0];
1066 texel[GCOMP] = table[index * 4 + 1];
1067 texel[BCOMP] = table[index * 4 + 2];
1068 texel[ACOMP] = table[index * 4 + 3];
1069 break;
1070 default:
1071 _mesa_problem(ctx, "Bad palette format in fetch_texel_ci8");
1072 return;
1073 }
1074 }
1075 }
1076
1077 #if DIM == 3
1078 static void store_texel_ci8(struct gl_texture_image *texImage,
1079 GLint i, GLint j, GLint k, const void *texel)
1080 {
1081 const GLubyte *index = (const GLubyte *) texel;
1082 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1083 *dst = *index;
1084 }
1085 #endif
1086
1087
1088 /* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
1089 /* Note: component order is same as for MESA_FORMAT_RGB888 */
1090 static void FETCH(srgb8)(const struct gl_texture_image *texImage,
1091 GLint i, GLint j, GLint k, GLfloat *texel )
1092 {
1093 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1094 texel[RCOMP] = nonlinear_to_linear(src[2]);
1095 texel[GCOMP] = nonlinear_to_linear(src[1]);
1096 texel[BCOMP] = nonlinear_to_linear(src[0]);
1097 texel[ACOMP] = 1.0F;
1098 }
1099
1100 #if DIM == 3
1101 static void store_texel_srgb8(struct gl_texture_image *texImage,
1102 GLint i, GLint j, GLint k, const void *texel)
1103 {
1104 const GLubyte *rgba = (const GLubyte *) texel;
1105 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
1106 dst[0] = rgba[BCOMP]; /* no conversion */
1107 dst[1] = rgba[GCOMP];
1108 dst[2] = rgba[RCOMP];
1109 }
1110 #endif
1111
1112 /* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
1113 static void FETCH(srgba8)(const struct gl_texture_image *texImage,
1114 GLint i, GLint j, GLint k, GLfloat *texel )
1115 {
1116 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1117 texel[RCOMP] = nonlinear_to_linear( (s >> 24) );
1118 texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1119 texel[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1120 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */
1121 }
1122
1123 #if DIM == 3
1124 static void store_texel_srgba8(struct gl_texture_image *texImage,
1125 GLint i, GLint j, GLint k, const void *texel)
1126 {
1127 const GLubyte *rgba = (const GLubyte *) texel;
1128 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1129 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1130 }
1131 #endif
1132
1133 /* Fetch texel from 1D, 2D or 3D sargb8 texture, return 4 GLfloats */
1134 static void FETCH(sargb8)(const struct gl_texture_image *texImage,
1135 GLint i, GLint j, GLint k, GLfloat *texel )
1136 {
1137 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1138 texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
1139 texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
1140 texel[BCOMP] = nonlinear_to_linear( (s ) & 0xff );
1141 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
1142 }
1143
1144 #if DIM == 3
1145 static void store_texel_sargb8(struct gl_texture_image *texImage,
1146 GLint i, GLint j, GLint k, const void *texel)
1147 {
1148 const GLubyte *rgba = (const GLubyte *) texel;
1149 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1150 *dst = PACK_COLOR_8888(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
1151 }
1152 #endif
1153
1154 /* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
1155 static void FETCH(sl8)(const struct gl_texture_image *texImage,
1156 GLint i, GLint j, GLint k, GLfloat *texel )
1157 {
1158 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1159 texel[RCOMP] =
1160 texel[GCOMP] =
1161 texel[BCOMP] = nonlinear_to_linear(src[0]);
1162 texel[ACOMP] = 1.0F;
1163 }
1164
1165 #if DIM == 3
1166 static void store_texel_sl8(struct gl_texture_image *texImage,
1167 GLint i, GLint j, GLint k, const void *texel)
1168 {
1169 const GLubyte *rgba = (const GLubyte *) texel;
1170 GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
1171 dst[0] = rgba[RCOMP];
1172 }
1173 #endif
1174
1175 /* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
1176 static void FETCH(sla8)(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, 2);
1180 texel[RCOMP] =
1181 texel[GCOMP] =
1182 texel[BCOMP] = nonlinear_to_linear(src[0]);
1183 texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
1184 }
1185
1186 #if DIM == 3
1187 static void store_texel_sla8(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, 2);
1192 dst[0] = rgba[RCOMP];
1193 dst[1] = rgba[ACOMP];
1194 }
1195 #endif
1196
1197
1198 /* MESA_FORMAT_DUDV8 ********************************************************/
1199
1200 /* this format by definition produces 0,0,0,1 as rgba values,
1201 however we'll return the dudv values as rg and fix up elsewhere */
1202 static void FETCH(dudv8)(const struct gl_texture_image *texImage,
1203 GLint i, GLint j, GLint k, GLfloat *texel )
1204 {
1205 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 2);
1206 texel[RCOMP] = BYTE_TO_FLOAT(src[0]);
1207 texel[GCOMP] = BYTE_TO_FLOAT(src[1]);
1208 texel[BCOMP] = 0;
1209 texel[ACOMP] = 0;
1210 }
1211
1212
1213 /* MESA_FORMAT_SIGNED_R8 ***********************************************/
1214
1215 static void FETCH(signed_r8)( const struct gl_texture_image *texImage,
1216 GLint i, GLint j, GLint k, GLfloat *texel )
1217 {
1218 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1219 texel[RCOMP] = BYTE_TO_FLOAT_TEX( s );
1220 texel[GCOMP] = 0.0F;
1221 texel[BCOMP] = 0.0F;
1222 texel[ACOMP] = 1.0F;
1223 }
1224
1225 #if DIM == 3
1226 static void store_texel_signed_r8(struct gl_texture_image *texImage,
1227 GLint i, GLint j, GLint k, const void *texel)
1228 {
1229 const GLbyte *rgba = (const GLbyte *) texel;
1230 GLbyte *dst = TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
1231 *dst = rgba[RCOMP];
1232 }
1233 #endif
1234
1235
1236 /* MESA_FORMAT_SIGNED_RG88 ***********************************************/
1237
1238 static void FETCH(signed_rg88)( const struct gl_texture_image *texImage,
1239 GLint i, GLint j, GLint k, GLfloat *texel )
1240 {
1241 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1242 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1243 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
1244 texel[BCOMP] = 0.0F;
1245 texel[ACOMP] = 1.0F;
1246 }
1247
1248 #if DIM == 3
1249 static void store_texel_signed_rg88(struct gl_texture_image *texImage,
1250 GLint i, GLint j, GLint k, const void *texel)
1251 {
1252 const GLbyte *rg = (const GLbyte *) texel;
1253 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 2);
1254 *dst = PACK_COLOR_88(rg[RCOMP], rg[GCOMP]);
1255 }
1256 #endif
1257
1258
1259 /* MESA_FORMAT_SIGNED_RGBX8888 ***********************************************/
1260
1261 static void FETCH(signed_rgbx8888)( const struct gl_texture_image *texImage,
1262 GLint i, GLint j, GLint k, GLfloat *texel )
1263 {
1264 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1265 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1266 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1267 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1268 texel[ACOMP] = 1.0f;
1269 }
1270
1271 #if DIM == 3
1272 static void store_texel_signed_rgbx8888(struct gl_texture_image *texImage,
1273 GLint i, GLint j, GLint k, const void *texel)
1274 {
1275 const GLbyte *rgba = (const GLbyte *) texel;
1276 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1277 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], 255);
1278 }
1279 #endif
1280
1281
1282 /* MESA_FORMAT_SIGNED_RGBA8888 ***********************************************/
1283
1284 static void FETCH(signed_rgba8888)( const struct gl_texture_image *texImage,
1285 GLint i, GLint j, GLint k, GLfloat *texel )
1286 {
1287 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1288 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1289 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1290 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1291 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1292 }
1293
1294 #if DIM == 3
1295 static void store_texel_signed_rgba8888(struct gl_texture_image *texImage,
1296 GLint i, GLint j, GLint k, const void *texel)
1297 {
1298 const GLbyte *rgba = (const GLbyte *) texel;
1299 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1300 *dst = PACK_COLOR_8888(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1301 }
1302 #endif
1303
1304 static void FETCH(signed_rgba8888_rev)( const struct gl_texture_image *texImage,
1305 GLint i, GLint j, GLint k, GLfloat *texel )
1306 {
1307 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1308 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1309 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1310 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1311 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1312 }
1313
1314 #if DIM == 3
1315 static void store_texel_signed_rgba8888_rev(struct gl_texture_image *texImage,
1316 GLint i, GLint j, GLint k, const void *texel)
1317 {
1318 const GLubyte *rgba = (const GLubyte *) texel;
1319 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1320 *dst = PACK_COLOR_8888_REV(rgba[RCOMP], rgba[GCOMP], rgba[BCOMP], rgba[ACOMP]);
1321 }
1322 #endif
1323
1324
1325
1326 /* MESA_FORMAT_SIGNED_R_16 ***********************************************/
1327
1328 static void
1329 FETCH(signed_r_16)(const struct gl_texture_image *texImage,
1330 GLint i, GLint j, GLint k, GLfloat *texel)
1331 {
1332 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1333 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s );
1334 texel[GCOMP] = 0.0F;
1335 texel[BCOMP] = 0.0F;
1336 texel[ACOMP] = 1.0F;
1337 }
1338
1339 #if DIM == 3
1340 static void
1341 store_texel_signed_r_16(struct gl_texture_image *texImage,
1342 GLint i, GLint j, GLint k, const void *texel)
1343 {
1344 const GLshort *rgba = (const GLshort *) texel;
1345 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1346 *dst = rgba[0];
1347 }
1348 #endif
1349
1350
1351 /* MESA_FORMAT_SIGNED_RG_16 ***********************************************/
1352
1353 static void
1354 FETCH(signed_rg_16)(const struct gl_texture_image *texImage,
1355 GLint i, GLint j, GLint k, GLfloat *texel)
1356 {
1357 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
1358 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1359 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1360 texel[BCOMP] = 0.0F;
1361 texel[ACOMP] = 1.0F;
1362 }
1363
1364 #if DIM == 3
1365 static void
1366 store_texel_signed_rg_16(struct gl_texture_image *texImage,
1367 GLint i, GLint j, GLint k, const void *texel)
1368 {
1369 const GLshort *rgba = (const GLshort *) texel;
1370 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
1371 dst[0] = rgba[RCOMP];
1372 dst[1] = rgba[GCOMP];
1373 }
1374 #endif
1375
1376
1377 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
1378
1379 static void
1380 FETCH(signed_rgb_16)(const struct gl_texture_image *texImage,
1381 GLint i, GLint j, GLint k, GLfloat *texel)
1382 {
1383 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
1384 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1385 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1386 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[3] );
1387 texel[ACOMP] = 1.0F;
1388 }
1389
1390 #if DIM == 3
1391 static void
1392 store_texel_signed_rgb_16(struct gl_texture_image *texImage,
1393 GLint i, GLint j, GLint k, const void *texel)
1394 {
1395 const GLshort *rgba = (const GLshort *) texel;
1396 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
1397 dst[0] = rgba[RCOMP];
1398 dst[1] = rgba[GCOMP];
1399 dst[2] = rgba[BCOMP];
1400 }
1401 #endif
1402
1403
1404 /* MESA_FORMAT_SIGNED_RGB_16 ***********************************************/
1405
1406 static void
1407 FETCH(signed_rgba_16)(const struct gl_texture_image *texImage,
1408 GLint i, GLint j, GLint k, GLfloat *texel)
1409 {
1410 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1411 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1412 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1413 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[3] );
1414 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[4] );
1415 }
1416
1417 #if DIM == 3
1418 static void
1419 store_texel_signed_rgba_16(struct gl_texture_image *texImage,
1420 GLint i, GLint j, GLint k, const void *texel)
1421 {
1422 const GLshort *rgba = (const GLshort *) texel;
1423 GLshort *dst = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1424 dst[0] = rgba[RCOMP];
1425 dst[1] = rgba[GCOMP];
1426 dst[2] = rgba[BCOMP];
1427 dst[3] = rgba[ACOMP];
1428 }
1429 #endif
1430
1431
1432
1433 /* MESA_FORMAT_RGBA_16 ***********************************************/
1434
1435 static void
1436 FETCH(rgba_16)(const struct gl_texture_image *texImage,
1437 GLint i, GLint j, GLint k, GLfloat *texel)
1438 {
1439 const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1440 texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
1441 texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
1442 texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
1443 texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
1444 }
1445
1446 #if DIM == 3
1447 static void
1448 store_texel_rgba_16(struct gl_texture_image *texImage,
1449 GLint i, GLint j, GLint k, const void *texel)
1450 {
1451 const GLushort *rgba = (const GLushort *) texel;
1452 GLushort *dst = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1453 dst[0] = rgba[RCOMP];
1454 dst[1] = rgba[GCOMP];
1455 dst[2] = rgba[BCOMP];
1456 dst[3] = rgba[ACOMP];
1457 }
1458 #endif
1459
1460
1461
1462 /* MESA_FORMAT_YCBCR *********************************************************/
1463
1464 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
1465 * We convert YCbCr to RGB here.
1466 */
1467 static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
1468 GLint i, GLint j, GLint k, GLfloat *texel )
1469 {
1470 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1471 const GLushort *src1 = src0 + 1; /* odd */
1472 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1473 const GLubyte cb = *src0 & 0xff; /* chroma U */
1474 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1475 const GLubyte cr = *src1 & 0xff; /* chroma V */
1476 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1477 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1478 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1479 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1480 r *= (1.0F / 255.0F);
1481 g *= (1.0F / 255.0F);
1482 b *= (1.0F / 255.0F);
1483 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1484 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1485 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1486 texel[ACOMP] = 1.0F;
1487 }
1488
1489 #if DIM == 3
1490 static void store_texel_ycbcr(struct gl_texture_image *texImage,
1491 GLint i, GLint j, GLint k, const void *texel)
1492 {
1493 (void) texImage;
1494 (void) i;
1495 (void) j;
1496 (void) k;
1497 (void) texel;
1498 /* XXX to do */
1499 }
1500 #endif
1501
1502
1503 /* MESA_FORMAT_YCBCR_REV *****************************************************/
1504
1505 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
1506 * We convert YCbCr to RGB here.
1507 */
1508 static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
1509 GLint i, GLint j, GLint k, GLfloat *texel )
1510 {
1511 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1512 const GLushort *src1 = src0 + 1; /* odd */
1513 const GLubyte y0 = *src0 & 0xff; /* luminance */
1514 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1515 const GLubyte y1 = *src1 & 0xff; /* luminance */
1516 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1517 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1518 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1519 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1520 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1521 r *= (1.0F / 255.0F);
1522 g *= (1.0F / 255.0F);
1523 b *= (1.0F / 255.0F);
1524 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1525 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1526 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1527 texel[ACOMP] = 1.0F;
1528 }
1529
1530 #if DIM == 3
1531 static void store_texel_ycbcr_rev(struct gl_texture_image *texImage,
1532 GLint i, GLint j, GLint k, const void *texel)
1533 {
1534 (void) texImage;
1535 (void) i;
1536 (void) j;
1537 (void) k;
1538 (void) texel;
1539 /* XXX to do */
1540 }
1541 #endif
1542
1543
1544 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
1545
1546 static void FETCH(f_z24_s8)( const struct gl_texture_image *texImage,
1547 GLint i, GLint j, GLint k, GLfloat *texel )
1548 {
1549 /* only return Z, not stencil data */
1550 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1551 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1552 texel[0] = ((*src) >> 8) * scale;
1553 ASSERT(texImage->TexFormat == MESA_FORMAT_Z24_S8);
1554 ASSERT(texel[0] >= 0.0F);
1555 ASSERT(texel[0] <= 1.0F);
1556 }
1557
1558 #if DIM == 3
1559 static void store_texel_z24_s8(struct gl_texture_image *texImage,
1560 GLint i, GLint j, GLint k, const void *texel)
1561 {
1562 /* only store Z, not stencil */
1563 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1564 GLfloat depth = *((GLfloat *) texel);
1565 GLuint zi = ((GLuint) (depth * 0xffffff)) << 8;
1566 *dst = zi | (*dst & 0xff);
1567 }
1568 #endif
1569
1570
1571 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
1572
1573 static void FETCH(f_s8_z24)( const struct gl_texture_image *texImage,
1574 GLint i, GLint j, GLint k, GLfloat *texel )
1575 {
1576 /* only return Z, not stencil data */
1577 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1578 const GLfloat scale = 1.0F / (GLfloat) 0xffffff;
1579 texel[0] = ((*src) & 0x00ffffff) * scale;
1580 ASSERT(texImage->TexFormat == MESA_FORMAT_S8_Z24);
1581 ASSERT(texel[0] >= 0.0F);
1582 ASSERT(texel[0] <= 1.0F);
1583 }
1584
1585 #if DIM == 3
1586 static void store_texel_s8_z24(struct gl_texture_image *texImage,
1587 GLint i, GLint j, GLint k, const void *texel)
1588 {
1589 /* only store Z, not stencil */
1590 GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1591 GLfloat depth = *((GLfloat *) texel);
1592 GLuint zi = (GLuint) (depth * 0xffffff);
1593 *dst = zi | (*dst & 0xff000000);
1594 }
1595 #endif
1596
1597
1598 #undef TEXEL_ADDR
1599 #undef DIM
1600 #undef FETCH