2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
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.
28 * \file texfetch_tmp.h
29 * Texel fetch functions template.
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.
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.
38 * \author Gareth Hughes
45 #define TEXEL_ADDR( type, image, i, j, k, size ) \
46 ((void) (j), (void) (k), ((type *)(image)->Map + (i) * (size)))
48 #define FETCH(x) fetch_texel_1d_##x
52 #define TEXEL_ADDR( type, image, i, j, k, size ) \
54 ((type *)(image)->Map + ((image)->RowStride * (j) + (i)) * (size)))
56 #define FETCH(x) fetch_texel_2d_##x
60 #define TEXEL_ADDR( type, image, i, j, k, size ) \
61 ((type *)(image)->Map + ((image)->ImageOffsets[k] \
62 + (image)->RowStride * (j) + (i)) * (size))
64 #define FETCH(x) fetch_texel_3d_##x
67 #error illegal number of texture dimensions
71 /* MESA_FORMAT_Z32 ***********************************************************/
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.
77 static void FETCH(f_z32
)( const struct swrast_texture_image
*texImage
,
78 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
80 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
81 texel
[0] = src
[0] * (1.0F
/ 0xffffffff);
85 /* MESA_FORMAT_Z16 ***********************************************************/
87 /* Fetch depth texel from 1D, 2D or 3D 16-bit depth texture,
88 * returning 1 GLfloat.
89 * Note: no GLchan version of this function.
91 static void FETCH(f_z16
)(const struct swrast_texture_image
*texImage
,
92 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
94 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
95 texel
[0] = src
[0] * (1.0F
/ 65535.0F
);
101 * Begin Hardware formats
104 /* MESA_FORMAT_RGBA8888 ******************************************************/
106 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
107 static void FETCH(f_rgba8888
)( const struct swrast_texture_image
*texImage
,
108 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
110 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
111 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
112 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
113 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
114 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
122 /* MESA_FORMAT_RGBA888_REV ***************************************************/
124 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
125 static void FETCH(f_rgba8888_rev
)( const struct swrast_texture_image
*texImage
,
126 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
128 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
129 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
130 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
131 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
132 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
138 /* MESA_FORMAT_ARGB8888 ******************************************************/
140 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
141 static void FETCH(f_argb8888
)( const struct swrast_texture_image
*texImage
,
142 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
144 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
145 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
146 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
147 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
148 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
154 /* MESA_FORMAT_ARGB8888_REV **************************************************/
156 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
157 static void FETCH(f_argb8888_rev
)( const struct swrast_texture_image
*texImage
,
158 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
160 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
161 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
162 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
163 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
164 texel
[ACOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
170 /* MESA_FORMAT_RGBX8888 ******************************************************/
172 /* Fetch texel from 1D, 2D or 3D rgbx8888 texture, return 4 GLfloats */
173 static void FETCH(f_rgbx8888
)( const struct swrast_texture_image
*texImage
,
174 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
176 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
177 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
178 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
179 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
186 /* MESA_FORMAT_RGBX888_REV ***************************************************/
188 /* Fetch texel from 1D, 2D or 3D rgbx8888_rev texture, return 4 GLchans */
189 static void FETCH(f_rgbx8888_rev
)( const struct swrast_texture_image
*texImage
,
190 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
192 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
193 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
194 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
195 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
202 /* MESA_FORMAT_XRGB8888 ******************************************************/
204 /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
205 static void FETCH(f_xrgb8888
)( const struct swrast_texture_image
*texImage
,
206 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
208 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
209 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
210 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
211 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
) & 0xff );
218 /* MESA_FORMAT_XRGB8888_REV **************************************************/
220 /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
221 static void FETCH(f_xrgb8888_rev
)( const struct swrast_texture_image
*texImage
,
222 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
224 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
225 texel
[RCOMP
] = UBYTE_TO_FLOAT( (s
>> 8) & 0xff );
226 texel
[GCOMP
] = UBYTE_TO_FLOAT( (s
>> 16) & 0xff );
227 texel
[BCOMP
] = UBYTE_TO_FLOAT( (s
>> 24) );
234 /* MESA_FORMAT_RGB888 ********************************************************/
236 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
237 static void FETCH(f_rgb888
)( const struct swrast_texture_image
*texImage
,
238 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
240 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
241 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[2] );
242 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
243 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
250 /* MESA_FORMAT_BGR888 ********************************************************/
252 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
253 static void FETCH(f_bgr888
)( const struct swrast_texture_image
*texImage
,
254 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
256 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 3);
257 texel
[RCOMP
] = UBYTE_TO_FLOAT( src
[0] );
258 texel
[GCOMP
] = UBYTE_TO_FLOAT( src
[1] );
259 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[2] );
266 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
267 instead of slow (g << 2) * 255 / 252 (always rounds down) */
269 /* MESA_FORMAT_RGB565 ********************************************************/
271 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
272 static void FETCH(f_rgb565
)( const struct swrast_texture_image
*texImage
,
273 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
275 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
276 const GLushort s
= *src
;
277 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
278 texel
[GCOMP
] = ((s
>> 5 ) & 0x3f) * (1.0F
/ 63.0F
);
279 texel
[BCOMP
] = ((s
) & 0x1f) * (1.0F
/ 31.0F
);
286 /* MESA_FORMAT_RGB565_REV ****************************************************/
288 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
289 static void FETCH(f_rgb565_rev
)( const struct swrast_texture_image
*texImage
,
290 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
292 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
293 const GLushort s
= (*src
>> 8) | (*src
<< 8); /* byte swap */
294 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 8) & 0xf8) | ((s
>> 13) & 0x7) );
295 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 3) & 0xfc) | ((s
>> 9) & 0x3) );
296 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
303 /* MESA_FORMAT_ARGB4444 ******************************************************/
305 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
306 static void FETCH(f_argb4444
)( const struct swrast_texture_image
*texImage
,
307 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
309 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
310 const GLushort s
= *src
;
311 texel
[RCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
312 texel
[GCOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
313 texel
[BCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
314 texel
[ACOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
320 /* MESA_FORMAT_ARGB4444_REV **************************************************/
322 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
323 static void FETCH(f_argb4444_rev
)( const struct swrast_texture_image
*texImage
,
324 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
326 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
327 texel
[RCOMP
] = ((s
) & 0xf) * (1.0F
/ 15.0F
);
328 texel
[GCOMP
] = ((s
>> 12) & 0xf) * (1.0F
/ 15.0F
);
329 texel
[BCOMP
] = ((s
>> 8) & 0xf) * (1.0F
/ 15.0F
);
330 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
335 /* MESA_FORMAT_RGBA5551 ******************************************************/
337 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
338 static void FETCH(f_rgba5551
)( const struct swrast_texture_image
*texImage
,
339 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
341 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
342 const GLushort s
= *src
;
343 texel
[RCOMP
] = ((s
>> 11) & 0x1f) * (1.0F
/ 31.0F
);
344 texel
[GCOMP
] = ((s
>> 6) & 0x1f) * (1.0F
/ 31.0F
);
345 texel
[BCOMP
] = ((s
>> 1) & 0x1f) * (1.0F
/ 31.0F
);
346 texel
[ACOMP
] = ((s
) & 0x01) * 1.0F
;
351 /* MESA_FORMAT_ARGB1555 ******************************************************/
353 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
354 static void FETCH(f_argb1555
)( const struct swrast_texture_image
*texImage
,
355 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
357 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
358 const GLushort s
= *src
;
359 texel
[RCOMP
] = ((s
>> 10) & 0x1f) * (1.0F
/ 31.0F
);
360 texel
[GCOMP
] = ((s
>> 5) & 0x1f) * (1.0F
/ 31.0F
);
361 texel
[BCOMP
] = ((s
>> 0) & 0x1f) * (1.0F
/ 31.0F
);
362 texel
[ACOMP
] = ((s
>> 15) & 0x01) * 1.0F
;
368 /* MESA_FORMAT_ARGB1555_REV **************************************************/
370 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
371 static void FETCH(f_argb1555_rev
)( const struct swrast_texture_image
*texImage
,
372 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
374 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
375 const GLushort s
= (*src
<< 8) | (*src
>> 8); /* byteswap */
376 texel
[RCOMP
] = UBYTE_TO_FLOAT( ((s
>> 7) & 0xf8) | ((s
>> 12) & 0x7) );
377 texel
[GCOMP
] = UBYTE_TO_FLOAT( ((s
>> 2) & 0xf8) | ((s
>> 7) & 0x7) );
378 texel
[BCOMP
] = UBYTE_TO_FLOAT( ((s
<< 3) & 0xf8) | ((s
>> 2) & 0x7) );
379 texel
[ACOMP
] = UBYTE_TO_FLOAT( ((s
>> 15) & 0x01) * 255 );
385 /* MESA_FORMAT_AL44 **********************************************************/
387 /* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
388 static void FETCH(f_al44
)( const struct swrast_texture_image
*texImage
,
389 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
391 const GLubyte s
= *TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
394 texel
[BCOMP
] = (s
& 0xf) * (1.0F
/ 15.0F
);
395 texel
[ACOMP
] = ((s
>> 4) & 0xf) * (1.0F
/ 15.0F
);
401 /* MESA_FORMAT_AL88 **********************************************************/
403 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
404 static void FETCH(f_al88
)( const struct swrast_texture_image
*texImage
,
405 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
407 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
410 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
411 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
417 /* MESA_FORMAT_AL88_REV ******************************************************/
419 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
420 static void FETCH(f_al88_rev
)( const struct swrast_texture_image
*texImage
,
421 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
423 const GLushort s
= *TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
426 texel
[BCOMP
] = UBYTE_TO_FLOAT( s
>> 8 );
427 texel
[ACOMP
] = UBYTE_TO_FLOAT( s
& 0xff );
433 /* MESA_FORMAT_AL1616 ********************************************************/
435 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
436 static void FETCH(f_al1616
)( const struct swrast_texture_image
*texImage
,
437 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
439 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
442 texel
[BCOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
443 texel
[ACOMP
] = USHORT_TO_FLOAT( s
>> 16 );
449 /* MESA_FORMAT_AL1616_REV ****************************************************/
451 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
452 static void FETCH(f_al1616_rev
)( const struct swrast_texture_image
*texImage
,
453 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
455 const GLuint s
= *TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
458 texel
[BCOMP
] = USHORT_TO_FLOAT( s
>> 16 );
459 texel
[ACOMP
] = USHORT_TO_FLOAT( s
& 0xffff );
465 /* MESA_FORMAT_RGB332 ********************************************************/
467 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
468 static void FETCH(f_rgb332
)( const struct swrast_texture_image
*texImage
,
469 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
471 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
472 const GLubyte s
= *src
;
473 texel
[RCOMP
] = ((s
>> 5) & 0x7) * (1.0F
/ 7.0F
);
474 texel
[GCOMP
] = ((s
>> 2) & 0x7) * (1.0F
/ 7.0F
);
475 texel
[BCOMP
] = ((s
) & 0x3) * (1.0F
/ 3.0F
);
482 /* MESA_FORMAT_A8 ************************************************************/
484 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
485 static void FETCH(f_a8
)( const struct swrast_texture_image
*texImage
,
486 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
488 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
492 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
498 /* MESA_FORMAT_A16 ************************************************************/
500 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
501 static void FETCH(f_a16
)( const struct swrast_texture_image
*texImage
,
502 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
504 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
508 texel
[ACOMP
] = USHORT_TO_FLOAT( src
[0] );
514 /* MESA_FORMAT_L8 ************************************************************/
516 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
517 static void FETCH(f_l8
)( const struct swrast_texture_image
*texImage
,
518 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
520 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
523 texel
[BCOMP
] = UBYTE_TO_FLOAT( src
[0] );
530 /* MESA_FORMAT_L16 ***********************************************************/
532 /* Fetch texel from 1D, 2D or 3D l16 texture, return 4 GLchans */
533 static void FETCH(f_l16
)( const struct swrast_texture_image
*texImage
,
534 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
536 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
539 texel
[BCOMP
] = USHORT_TO_FLOAT( src
[0] );
546 /* MESA_FORMAT_I8 ************************************************************/
548 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
549 static void FETCH(f_i8
)( const struct swrast_texture_image
*texImage
,
550 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
552 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 1);
556 texel
[ACOMP
] = UBYTE_TO_FLOAT( src
[0] );
562 /* MESA_FORMAT_I16 ***********************************************************/
564 /* Fetch texel from 1D, 2D or 3D i16 texture, return 4 GLchans */
565 static void FETCH(f_i16
)( const struct swrast_texture_image
*texImage
,
566 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
568 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 1);
572 texel
[ACOMP
] = USHORT_TO_FLOAT( src
[0] );
576 /* MESA_FORMAT_RGBA_INT8 **************************************************/
579 FETCH(rgba_int8
)(const struct swrast_texture_image
*texImage
,
580 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
582 const GLbyte
*src
= TEXEL_ADDR(GLbyte
, texImage
, i
, j
, k
, 4);
583 texel
[RCOMP
] = (GLfloat
) src
[0];
584 texel
[GCOMP
] = (GLfloat
) src
[1];
585 texel
[BCOMP
] = (GLfloat
) src
[2];
586 texel
[ACOMP
] = (GLfloat
) src
[3];
592 /* MESA_FORMAT_RGBA_INT16 **************************************************/
595 FETCH(rgba_int16
)(const struct swrast_texture_image
*texImage
,
596 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
598 const GLshort
*src
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
599 texel
[RCOMP
] = (GLfloat
) src
[0];
600 texel
[GCOMP
] = (GLfloat
) src
[1];
601 texel
[BCOMP
] = (GLfloat
) src
[2];
602 texel
[ACOMP
] = (GLfloat
) src
[3];
608 /* MESA_FORMAT_RGBA_INT32 **************************************************/
611 FETCH(rgba_int32
)(const struct swrast_texture_image
*texImage
,
612 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
614 const GLint
*src
= TEXEL_ADDR(GLint
, texImage
, i
, j
, k
, 4);
615 texel
[RCOMP
] = (GLfloat
) src
[0];
616 texel
[GCOMP
] = (GLfloat
) src
[1];
617 texel
[BCOMP
] = (GLfloat
) src
[2];
618 texel
[ACOMP
] = (GLfloat
) src
[3];
624 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
627 FETCH(rgba_uint8
)(const struct swrast_texture_image
*texImage
,
628 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
630 const GLubyte
*src
= TEXEL_ADDR(GLubyte
, texImage
, i
, j
, k
, 4);
631 texel
[RCOMP
] = (GLfloat
) src
[0];
632 texel
[GCOMP
] = (GLfloat
) src
[1];
633 texel
[BCOMP
] = (GLfloat
) src
[2];
634 texel
[ACOMP
] = (GLfloat
) src
[3];
640 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
643 FETCH(rgba_uint16
)(const struct swrast_texture_image
*texImage
,
644 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
646 const GLushort
*src
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
647 texel
[RCOMP
] = (GLfloat
) src
[0];
648 texel
[GCOMP
] = (GLfloat
) src
[1];
649 texel
[BCOMP
] = (GLfloat
) src
[2];
650 texel
[ACOMP
] = (GLfloat
) src
[3];
656 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
659 FETCH(rgba_uint32
)(const struct swrast_texture_image
*texImage
,
660 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
662 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 4);
663 texel
[RCOMP
] = (GLfloat
) src
[0];
664 texel
[GCOMP
] = (GLfloat
) src
[1];
665 texel
[BCOMP
] = (GLfloat
) src
[2];
666 texel
[ACOMP
] = (GLfloat
) src
[3];
671 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
674 FETCH(signed_rgba_16
)(const struct swrast_texture_image
*texImage
,
675 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
677 const GLshort
*s
= TEXEL_ADDR(GLshort
, texImage
, i
, j
, k
, 4);
678 texel
[RCOMP
] = SHORT_TO_FLOAT_TEX( s
[0] );
679 texel
[GCOMP
] = SHORT_TO_FLOAT_TEX( s
[1] );
680 texel
[BCOMP
] = SHORT_TO_FLOAT_TEX( s
[2] );
681 texel
[ACOMP
] = SHORT_TO_FLOAT_TEX( s
[3] );
688 /* MESA_FORMAT_RGBA_16 ***********************************************/
691 FETCH(rgba_16
)(const struct swrast_texture_image
*texImage
,
692 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
694 const GLushort
*s
= TEXEL_ADDR(GLushort
, texImage
, i
, j
, k
, 4);
695 texel
[RCOMP
] = USHORT_TO_FLOAT( s
[0] );
696 texel
[GCOMP
] = USHORT_TO_FLOAT( s
[1] );
697 texel
[BCOMP
] = USHORT_TO_FLOAT( s
[2] );
698 texel
[ACOMP
] = USHORT_TO_FLOAT( s
[3] );
705 /* MESA_FORMAT_YCBCR *********************************************************/
707 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
708 * We convert YCbCr to RGB here.
710 static void FETCH(f_ycbcr
)( const struct swrast_texture_image
*texImage
,
711 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
713 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
714 const GLushort
*src1
= src0
+ 1; /* odd */
715 const GLubyte y0
= (*src0
>> 8) & 0xff; /* luminance */
716 const GLubyte cb
= *src0
& 0xff; /* chroma U */
717 const GLubyte y1
= (*src1
>> 8) & 0xff; /* luminance */
718 const GLubyte cr
= *src1
& 0xff; /* chroma V */
719 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
720 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
721 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
722 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
723 r
*= (1.0F
/ 255.0F
);
724 g
*= (1.0F
/ 255.0F
);
725 b
*= (1.0F
/ 255.0F
);
726 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
727 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
728 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
735 /* MESA_FORMAT_YCBCR_REV *****************************************************/
737 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
738 * We convert YCbCr to RGB here.
740 static void FETCH(f_ycbcr_rev
)( const struct swrast_texture_image
*texImage
,
741 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
743 const GLushort
*src0
= TEXEL_ADDR(GLushort
, texImage
, (i
& ~1), j
, k
, 1); /* even */
744 const GLushort
*src1
= src0
+ 1; /* odd */
745 const GLubyte y0
= *src0
& 0xff; /* luminance */
746 const GLubyte cr
= (*src0
>> 8) & 0xff; /* chroma V */
747 const GLubyte y1
= *src1
& 0xff; /* luminance */
748 const GLubyte cb
= (*src1
>> 8) & 0xff; /* chroma U */
749 const GLubyte y
= (i
& 1) ? y1
: y0
; /* choose even/odd luminance */
750 GLfloat r
= 1.164F
* (y
- 16) + 1.596F
* (cr
- 128);
751 GLfloat g
= 1.164F
* (y
- 16) - 0.813F
* (cr
- 128) - 0.391F
* (cb
- 128);
752 GLfloat b
= 1.164F
* (y
- 16) + 2.018F
* (cb
- 128);
753 r
*= (1.0F
/ 255.0F
);
754 g
*= (1.0F
/ 255.0F
);
755 b
*= (1.0F
/ 255.0F
);
756 texel
[RCOMP
] = CLAMP(r
, 0.0F
, 1.0F
);
757 texel
[GCOMP
] = CLAMP(g
, 0.0F
, 1.0F
);
758 texel
[BCOMP
] = CLAMP(b
, 0.0F
, 1.0F
);
765 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
767 static void FETCH(f_z24_s8
)( const struct swrast_texture_image
*texImage
,
768 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
770 /* only return Z, not stencil data */
771 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
772 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
773 texel
[0] = ((*src
) >> 8) * scale
;
774 ASSERT(texImage
->Base
.TexFormat
== MESA_FORMAT_Z24_S8
||
775 texImage
->Base
.TexFormat
== MESA_FORMAT_Z24_X8
);
776 ASSERT(texel
[0] >= 0.0F
);
777 ASSERT(texel
[0] <= 1.0F
);
783 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
785 static void FETCH(f_s8_z24
)( const struct swrast_texture_image
*texImage
,
786 GLint i
, GLint j
, GLint k
, GLfloat
*texel
)
788 /* only return Z, not stencil data */
789 const GLuint
*src
= TEXEL_ADDR(GLuint
, texImage
, i
, j
, k
, 1);
790 const GLdouble scale
= 1.0 / (GLdouble
) 0xffffff;
791 texel
[0] = ((*src
) & 0x00ffffff) * scale
;
792 ASSERT(texImage
->Base
.TexFormat
== MESA_FORMAT_S8_Z24
||
793 texImage
->Base
.TexFormat
== MESA_FORMAT_X8_Z24
);
794 ASSERT(texel
[0] >= 0.0F
);
795 ASSERT(texel
[0] <= 1.0F
);