Sync with trunk r63637.
[reactos.git] / dll / opengl / 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)->Map + (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)->Map + ((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)->Map + ((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
85 /* MESA_FORMAT_Z16 ***********************************************************/
86
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.
90 */
91 static void FETCH(f_z16)(const struct swrast_texture_image *texImage,
92 GLint i, GLint j, GLint k, GLfloat *texel )
93 {
94 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
95 texel[0] = src[0] * (1.0F / 65535.0F);
96 }
97
98
99
100 /*
101 * Begin Hardware formats
102 */
103
104 /* MESA_FORMAT_RGBA8888 ******************************************************/
105
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 )
109 {
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 );
115 }
116
117
118
119
120
121
122 /* MESA_FORMAT_RGBA888_REV ***************************************************/
123
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 )
127 {
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) );
133 }
134
135
136
137
138 /* MESA_FORMAT_ARGB8888 ******************************************************/
139
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 )
143 {
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) );
149 }
150
151
152
153
154 /* MESA_FORMAT_ARGB8888_REV **************************************************/
155
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 )
159 {
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 );
165 }
166
167
168
169
170 /* MESA_FORMAT_RGBX8888 ******************************************************/
171
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 )
175 {
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 );
180 texel[ACOMP] = 1.0f;
181 }
182
183
184
185
186 /* MESA_FORMAT_RGBX888_REV ***************************************************/
187
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 )
191 {
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 );
196 texel[ACOMP] = 1.0f;
197 }
198
199
200
201
202 /* MESA_FORMAT_XRGB8888 ******************************************************/
203
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 )
207 {
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 );
212 texel[ACOMP] = 1.0f;
213 }
214
215
216
217
218 /* MESA_FORMAT_XRGB8888_REV **************************************************/
219
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 )
223 {
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) );
228 texel[ACOMP] = 1.0f;
229 }
230
231
232
233
234 /* MESA_FORMAT_RGB888 ********************************************************/
235
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 )
239 {
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] );
244 texel[ACOMP] = 1.0F;
245 }
246
247
248
249
250 /* MESA_FORMAT_BGR888 ********************************************************/
251
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 )
255 {
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] );
260 texel[ACOMP] = 1.0F;
261 }
262
263
264
265
266 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
267 instead of slow (g << 2) * 255 / 252 (always rounds down) */
268
269 /* MESA_FORMAT_RGB565 ********************************************************/
270
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 )
274 {
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);
280 texel[ACOMP] = 1.0F;
281 }
282
283
284
285
286 /* MESA_FORMAT_RGB565_REV ****************************************************/
287
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 )
291 {
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) );
297 texel[ACOMP] = 1.0F;
298 }
299
300
301
302
303 /* MESA_FORMAT_ARGB4444 ******************************************************/
304
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 )
308 {
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);
315 }
316
317
318
319
320 /* MESA_FORMAT_ARGB4444_REV **************************************************/
321
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 )
325 {
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);
331 }
332
333
334
335 /* MESA_FORMAT_RGBA5551 ******************************************************/
336
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 )
340 {
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;
347 }
348
349
350
351 /* MESA_FORMAT_ARGB1555 ******************************************************/
352
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 )
356 {
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;
363 }
364
365
366
367
368 /* MESA_FORMAT_ARGB1555_REV **************************************************/
369
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 )
373 {
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 );
380 }
381
382
383
384
385 /* MESA_FORMAT_AL44 **********************************************************/
386
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 )
390 {
391 const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
392 texel[RCOMP] =
393 texel[GCOMP] =
394 texel[BCOMP] = (s & 0xf) * (1.0F / 15.0F);
395 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
396 }
397
398
399
400
401 /* MESA_FORMAT_AL88 **********************************************************/
402
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 )
406 {
407 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
408 texel[RCOMP] =
409 texel[GCOMP] =
410 texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
411 texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
412 }
413
414
415
416
417 /* MESA_FORMAT_AL88_REV ******************************************************/
418
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 )
422 {
423 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
424 texel[RCOMP] =
425 texel[GCOMP] =
426 texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
427 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
428 }
429
430
431
432
433 /* MESA_FORMAT_AL1616 ********************************************************/
434
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 )
438 {
439 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
440 texel[RCOMP] =
441 texel[GCOMP] =
442 texel[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
443 texel[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
444 }
445
446
447
448
449 /* MESA_FORMAT_AL1616_REV ****************************************************/
450
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 )
454 {
455 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
456 texel[RCOMP] =
457 texel[GCOMP] =
458 texel[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
459 texel[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
460 }
461
462
463
464
465 /* MESA_FORMAT_RGB332 ********************************************************/
466
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 )
470 {
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);
476 texel[ACOMP] = 1.0F;
477 }
478
479
480
481
482 /* MESA_FORMAT_A8 ************************************************************/
483
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 )
487 {
488 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
489 texel[RCOMP] =
490 texel[GCOMP] =
491 texel[BCOMP] = 0.0F;
492 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
493 }
494
495
496
497
498 /* MESA_FORMAT_A16 ************************************************************/
499
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 )
503 {
504 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
505 texel[RCOMP] =
506 texel[GCOMP] =
507 texel[BCOMP] = 0.0F;
508 texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
509 }
510
511
512
513
514 /* MESA_FORMAT_L8 ************************************************************/
515
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 )
519 {
520 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
521 texel[RCOMP] =
522 texel[GCOMP] =
523 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
524 texel[ACOMP] = 1.0F;
525 }
526
527
528
529
530 /* MESA_FORMAT_L16 ***********************************************************/
531
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 )
535 {
536 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
537 texel[RCOMP] =
538 texel[GCOMP] =
539 texel[BCOMP] = USHORT_TO_FLOAT( src[0] );
540 texel[ACOMP] = 1.0F;
541 }
542
543
544
545
546 /* MESA_FORMAT_I8 ************************************************************/
547
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 )
551 {
552 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
553 texel[RCOMP] =
554 texel[GCOMP] =
555 texel[BCOMP] =
556 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
557 }
558
559
560
561
562 /* MESA_FORMAT_I16 ***********************************************************/
563
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 )
567 {
568 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
569 texel[RCOMP] =
570 texel[GCOMP] =
571 texel[BCOMP] =
572 texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
573 }
574
575
576 /* MESA_FORMAT_RGBA_INT8 **************************************************/
577
578 static void
579 FETCH(rgba_int8)(const struct swrast_texture_image *texImage,
580 GLint i, GLint j, GLint k, GLfloat *texel )
581 {
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];
587 }
588
589
590
591
592 /* MESA_FORMAT_RGBA_INT16 **************************************************/
593
594 static void
595 FETCH(rgba_int16)(const struct swrast_texture_image *texImage,
596 GLint i, GLint j, GLint k, GLfloat *texel )
597 {
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];
603 }
604
605
606
607
608 /* MESA_FORMAT_RGBA_INT32 **************************************************/
609
610 static void
611 FETCH(rgba_int32)(const struct swrast_texture_image *texImage,
612 GLint i, GLint j, GLint k, GLfloat *texel )
613 {
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];
619 }
620
621
622
623
624 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
625
626 static void
627 FETCH(rgba_uint8)(const struct swrast_texture_image *texImage,
628 GLint i, GLint j, GLint k, GLfloat *texel )
629 {
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];
635 }
636
637
638
639
640 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
641
642 static void
643 FETCH(rgba_uint16)(const struct swrast_texture_image *texImage,
644 GLint i, GLint j, GLint k, GLfloat *texel )
645 {
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];
651 }
652
653
654
655
656 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
657
658 static void
659 FETCH(rgba_uint32)(const struct swrast_texture_image *texImage,
660 GLint i, GLint j, GLint k, GLfloat *texel )
661 {
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];
667 }
668
669
670
671 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
672
673 static void
674 FETCH(signed_rgba_16)(const struct swrast_texture_image *texImage,
675 GLint i, GLint j, GLint k, GLfloat *texel)
676 {
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] );
682 }
683
684
685
686
687
688 /* MESA_FORMAT_RGBA_16 ***********************************************/
689
690 static void
691 FETCH(rgba_16)(const struct swrast_texture_image *texImage,
692 GLint i, GLint j, GLint k, GLfloat *texel)
693 {
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] );
699 }
700
701
702
703
704
705 /* MESA_FORMAT_YCBCR *********************************************************/
706
707 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
708 * We convert YCbCr to RGB here.
709 */
710 static void FETCH(f_ycbcr)( const struct swrast_texture_image *texImage,
711 GLint i, GLint j, GLint k, GLfloat *texel )
712 {
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);
729 texel[ACOMP] = 1.0F;
730 }
731
732
733
734
735 /* MESA_FORMAT_YCBCR_REV *****************************************************/
736
737 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
738 * We convert YCbCr to RGB here.
739 */
740 static void FETCH(f_ycbcr_rev)( const struct swrast_texture_image *texImage,
741 GLint i, GLint j, GLint k, GLfloat *texel )
742 {
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);
759 texel[ACOMP] = 1.0F;
760 }
761
762
763
764
765 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
766
767 static void FETCH(f_z24_s8)( const struct swrast_texture_image *texImage,
768 GLint i, GLint j, GLint k, GLfloat *texel )
769 {
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);
778 }
779
780
781
782
783 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
784
785 static void FETCH(f_s8_z24)( const struct swrast_texture_image *texImage,
786 GLint i, GLint j, GLint k, GLfloat *texel )
787 {
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);
796 }
797
798
799
800 #undef TEXEL_ADDR
801 #undef DIM
802 #undef FETCH