da996b8a1003277ba5ff3a06f8cf4f6fcd21ac21
[reactos.git] / reactos / 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 /* MESA_FORMAT_RGBA_F32 ******************************************************/
101
102 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT32 texture, returning 4 GLfloats.
103 */
104 static void FETCH(f_rgba_f32)( const struct swrast_texture_image *texImage,
105 GLint i, GLint j, GLint k, GLfloat *texel )
106 {
107 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
108 texel[RCOMP] = src[0];
109 texel[GCOMP] = src[1];
110 texel[BCOMP] = src[2];
111 texel[ACOMP] = src[3];
112 }
113
114
115
116
117 /* MESA_FORMAT_RGBA_F16 ******************************************************/
118
119 /* Fetch texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
120 * returning 4 GLfloats.
121 */
122 static void FETCH(f_rgba_f16)( const struct swrast_texture_image *texImage,
123 GLint i, GLint j, GLint k, GLfloat *texel )
124 {
125 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
126 texel[RCOMP] = _mesa_half_to_float(src[0]);
127 texel[GCOMP] = _mesa_half_to_float(src[1]);
128 texel[BCOMP] = _mesa_half_to_float(src[2]);
129 texel[ACOMP] = _mesa_half_to_float(src[3]);
130 }
131
132
133
134 /* MESA_FORMAT_RGB_F32 *******************************************************/
135
136 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT32 texture,
137 * returning 4 GLfloats.
138 */
139 static void FETCH(f_rgb_f32)( const struct swrast_texture_image *texImage,
140 GLint i, GLint j, GLint k, GLfloat *texel )
141 {
142 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
143 texel[RCOMP] = src[0];
144 texel[GCOMP] = src[1];
145 texel[BCOMP] = src[2];
146 texel[ACOMP] = 1.0F;
147 }
148
149
150
151
152 /* MESA_FORMAT_RGB_F16 *******************************************************/
153
154 /* Fetch texel from 1D, 2D or 3D RGB_FLOAT16 texture,
155 * returning 4 GLfloats.
156 */
157 static void FETCH(f_rgb_f16)( const struct swrast_texture_image *texImage,
158 GLint i, GLint j, GLint k, GLfloat *texel )
159 {
160 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
161 texel[RCOMP] = _mesa_half_to_float(src[0]);
162 texel[GCOMP] = _mesa_half_to_float(src[1]);
163 texel[BCOMP] = _mesa_half_to_float(src[2]);
164 texel[ACOMP] = 1.0F;
165 }
166
167
168
169
170 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
171
172 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT32 texture,
173 * returning 4 GLfloats.
174 */
175 static void FETCH(f_alpha_f32)( const struct swrast_texture_image *texImage,
176 GLint i, GLint j, GLint k, GLfloat *texel )
177 {
178 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
179 texel[RCOMP] =
180 texel[GCOMP] =
181 texel[BCOMP] = 0.0F;
182 texel[ACOMP] = src[0];
183 }
184
185
186
187
188 /* MESA_FORMAT_ALPHA_F32 *****************************************************/
189
190 /* Fetch texel from 1D, 2D or 3D ALPHA_FLOAT16 texture,
191 * returning 4 GLfloats.
192 */
193 static void FETCH(f_alpha_f16)( const struct swrast_texture_image *texImage,
194 GLint i, GLint j, GLint k, GLfloat *texel )
195 {
196 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
197 texel[RCOMP] =
198 texel[GCOMP] =
199 texel[BCOMP] = 0.0F;
200 texel[ACOMP] = _mesa_half_to_float(src[0]);
201 }
202
203
204
205
206 /* MESA_FORMAT_LUMINANCE_F32 *************************************************/
207
208 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT32 texture,
209 * returning 4 GLfloats.
210 */
211 static void FETCH(f_luminance_f32)( const struct swrast_texture_image *texImage,
212 GLint i, GLint j, GLint k, GLfloat *texel )
213 {
214 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
215 texel[RCOMP] =
216 texel[GCOMP] =
217 texel[BCOMP] = src[0];
218 texel[ACOMP] = 1.0F;
219 }
220
221
222
223
224 /* MESA_FORMAT_LUMINANCE_F16 *************************************************/
225
226 /* Fetch texel from 1D, 2D or 3D LUMINANCE_FLOAT16 texture,
227 * returning 4 GLfloats.
228 */
229 static void FETCH(f_luminance_f16)( const struct swrast_texture_image *texImage,
230 GLint i, GLint j, GLint k, GLfloat *texel )
231 {
232 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
233 texel[RCOMP] =
234 texel[GCOMP] =
235 texel[BCOMP] = _mesa_half_to_float(src[0]);
236 texel[ACOMP] = 1.0F;
237 }
238
239
240
241
242 /* MESA_FORMAT_LUMINANCE_ALPHA_F32 *******************************************/
243
244 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT32 texture,
245 * returning 4 GLfloats.
246 */
247 static void FETCH(f_luminance_alpha_f32)( const struct swrast_texture_image *texImage,
248 GLint i, GLint j, GLint k, GLfloat *texel )
249 {
250 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
251 texel[RCOMP] =
252 texel[GCOMP] =
253 texel[BCOMP] = src[0];
254 texel[ACOMP] = src[1];
255 }
256
257
258
259
260 /* MESA_FORMAT_LUMINANCE_ALPHA_F16 *******************************************/
261
262 /* Fetch texel from 1D, 2D or 3D LUMINANCE_ALPHA_FLOAT16 texture,
263 * returning 4 GLfloats.
264 */
265 static void FETCH(f_luminance_alpha_f16)( const struct swrast_texture_image *texImage,
266 GLint i, GLint j, GLint k, GLfloat *texel )
267 {
268 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
269 texel[RCOMP] =
270 texel[GCOMP] =
271 texel[BCOMP] = _mesa_half_to_float(src[0]);
272 texel[ACOMP] = _mesa_half_to_float(src[1]);
273 }
274
275
276
277
278 /* MESA_FORMAT_INTENSITY_F32 *************************************************/
279
280 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT32 texture,
281 * returning 4 GLfloats.
282 */
283 static void FETCH(f_intensity_f32)( const struct swrast_texture_image *texImage,
284 GLint i, GLint j, GLint k, GLfloat *texel )
285 {
286 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
287 texel[RCOMP] =
288 texel[GCOMP] =
289 texel[BCOMP] =
290 texel[ACOMP] = src[0];
291 }
292
293
294
295
296 /* MESA_FORMAT_INTENSITY_F16 *************************************************/
297
298 /* Fetch texel from 1D, 2D or 3D INTENSITY_FLOAT16 texture,
299 * returning 4 GLfloats.
300 */
301 static void FETCH(f_intensity_f16)( const struct swrast_texture_image *texImage,
302 GLint i, GLint j, GLint k, GLfloat *texel )
303 {
304 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
305 texel[RCOMP] =
306 texel[GCOMP] =
307 texel[BCOMP] =
308 texel[ACOMP] = _mesa_half_to_float(src[0]);
309 }
310
311
312
313 /*
314 * Begin Hardware formats
315 */
316
317 /* MESA_FORMAT_RGBA8888 ******************************************************/
318
319 /* Fetch texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
320 static void FETCH(f_rgba8888)( const struct swrast_texture_image *texImage,
321 GLint i, GLint j, GLint k, GLfloat *texel )
322 {
323 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
324 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
325 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
326 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
327 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
328 }
329
330
331
332
333
334
335 /* MESA_FORMAT_RGBA888_REV ***************************************************/
336
337 /* Fetch texel from 1D, 2D or 3D abgr8888 texture, return 4 GLchans */
338 static void FETCH(f_rgba8888_rev)( const struct swrast_texture_image *texImage,
339 GLint i, GLint j, GLint k, GLfloat *texel )
340 {
341 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
342 texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
343 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
344 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
345 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
346 }
347
348
349
350
351 /* MESA_FORMAT_ARGB8888 ******************************************************/
352
353 /* Fetch texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
354 static void FETCH(f_argb8888)( const struct swrast_texture_image *texImage,
355 GLint i, GLint j, GLint k, GLfloat *texel )
356 {
357 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
358 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
359 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
360 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
361 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
362 }
363
364
365
366
367 /* MESA_FORMAT_ARGB8888_REV **************************************************/
368
369 /* Fetch texel from 1D, 2D or 3D argb8888_rev texture, return 4 GLfloats */
370 static void FETCH(f_argb8888_rev)( const struct swrast_texture_image *texImage,
371 GLint i, GLint j, GLint k, GLfloat *texel )
372 {
373 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
374 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
375 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
376 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
377 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
378 }
379
380
381
382
383 /* MESA_FORMAT_RGBX8888 ******************************************************/
384
385 /* Fetch texel from 1D, 2D or 3D rgbx8888 texture, return 4 GLfloats */
386 static void FETCH(f_rgbx8888)( const struct swrast_texture_image *texImage,
387 GLint i, GLint j, GLint k, GLfloat *texel )
388 {
389 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
390 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
391 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
392 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
393 texel[ACOMP] = 1.0f;
394 }
395
396
397
398
399 /* MESA_FORMAT_RGBX888_REV ***************************************************/
400
401 /* Fetch texel from 1D, 2D or 3D rgbx8888_rev texture, return 4 GLchans */
402 static void FETCH(f_rgbx8888_rev)( const struct swrast_texture_image *texImage,
403 GLint i, GLint j, GLint k, GLfloat *texel )
404 {
405 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
406 texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
407 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
408 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
409 texel[ACOMP] = 1.0f;
410 }
411
412
413
414
415 /* MESA_FORMAT_XRGB8888 ******************************************************/
416
417 /* Fetch texel from 1D, 2D or 3D xrgb8888 texture, return 4 GLchans */
418 static void FETCH(f_xrgb8888)( const struct swrast_texture_image *texImage,
419 GLint i, GLint j, GLint k, GLfloat *texel )
420 {
421 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
422 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
423 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
424 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
425 texel[ACOMP] = 1.0f;
426 }
427
428
429
430
431 /* MESA_FORMAT_XRGB8888_REV **************************************************/
432
433 /* Fetch texel from 1D, 2D or 3D xrgb8888_rev texture, return 4 GLfloats */
434 static void FETCH(f_xrgb8888_rev)( const struct swrast_texture_image *texImage,
435 GLint i, GLint j, GLint k, GLfloat *texel )
436 {
437 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
438 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
439 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
440 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
441 texel[ACOMP] = 1.0f;
442 }
443
444
445
446
447 /* MESA_FORMAT_RGB888 ********************************************************/
448
449 /* Fetch texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
450 static void FETCH(f_rgb888)( const struct swrast_texture_image *texImage,
451 GLint i, GLint j, GLint k, GLfloat *texel )
452 {
453 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
454 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
455 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
456 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
457 texel[ACOMP] = 1.0F;
458 }
459
460
461
462
463 /* MESA_FORMAT_BGR888 ********************************************************/
464
465 /* Fetch texel from 1D, 2D or 3D bgr888 texture, return 4 GLchans */
466 static void FETCH(f_bgr888)( const struct swrast_texture_image *texImage,
467 GLint i, GLint j, GLint k, GLfloat *texel )
468 {
469 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
470 texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
471 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
472 texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
473 texel[ACOMP] = 1.0F;
474 }
475
476
477
478
479 /* use color expansion like (g << 2) | (g >> 4) (does somewhat random rounding)
480 instead of slow (g << 2) * 255 / 252 (always rounds down) */
481
482 /* MESA_FORMAT_RGB565 ********************************************************/
483
484 /* Fetch texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
485 static void FETCH(f_rgb565)( const struct swrast_texture_image *texImage,
486 GLint i, GLint j, GLint k, GLfloat *texel )
487 {
488 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
489 const GLushort s = *src;
490 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
491 texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
492 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
493 texel[ACOMP] = 1.0F;
494 }
495
496
497
498
499 /* MESA_FORMAT_RGB565_REV ****************************************************/
500
501 /* Fetch texel from 1D, 2D or 3D rgb565_rev texture, return 4 GLchans */
502 static void FETCH(f_rgb565_rev)( const struct swrast_texture_image *texImage,
503 GLint i, GLint j, GLint k, GLfloat *texel )
504 {
505 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
506 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
507 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
508 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
509 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
510 texel[ACOMP] = 1.0F;
511 }
512
513
514
515
516 /* MESA_FORMAT_ARGB4444 ******************************************************/
517
518 /* Fetch texel from 1D, 2D or 3D argb444 texture, return 4 GLchans */
519 static void FETCH(f_argb4444)( const struct swrast_texture_image *texImage,
520 GLint i, GLint j, GLint k, GLfloat *texel )
521 {
522 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
523 const GLushort s = *src;
524 texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
525 texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
526 texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
527 texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
528 }
529
530
531
532
533 /* MESA_FORMAT_ARGB4444_REV **************************************************/
534
535 /* Fetch texel from 1D, 2D or 3D argb4444_rev texture, return 4 GLchans */
536 static void FETCH(f_argb4444_rev)( const struct swrast_texture_image *texImage,
537 GLint i, GLint j, GLint k, GLfloat *texel )
538 {
539 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
540 texel[RCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
541 texel[GCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
542 texel[BCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
543 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
544 }
545
546
547
548 /* MESA_FORMAT_RGBA5551 ******************************************************/
549
550 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
551 static void FETCH(f_rgba5551)( const struct swrast_texture_image *texImage,
552 GLint i, GLint j, GLint k, GLfloat *texel )
553 {
554 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
555 const GLushort s = *src;
556 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
557 texel[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
558 texel[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
559 texel[ACOMP] = ((s ) & 0x01) * 1.0F;
560 }
561
562
563
564 /* MESA_FORMAT_ARGB1555 ******************************************************/
565
566 /* Fetch texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
567 static void FETCH(f_argb1555)( const struct swrast_texture_image *texImage,
568 GLint i, GLint j, GLint k, GLfloat *texel )
569 {
570 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
571 const GLushort s = *src;
572 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
573 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
574 texel[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F);
575 texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
576 }
577
578
579
580
581 /* MESA_FORMAT_ARGB1555_REV **************************************************/
582
583 /* Fetch texel from 1D, 2D or 3D argb1555_rev texture, return 4 GLchans */
584 static void FETCH(f_argb1555_rev)( const struct swrast_texture_image *texImage,
585 GLint i, GLint j, GLint k, GLfloat *texel )
586 {
587 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
588 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
589 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
590 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
591 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
592 texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
593 }
594
595
596
597
598 /* MESA_FORMAT_AL44 **********************************************************/
599
600 /* Fetch texel from 1D, 2D or 3D al44 texture, return 4 GLchans */
601 static void FETCH(f_al44)( const struct swrast_texture_image *texImage,
602 GLint i, GLint j, GLint k, GLfloat *texel )
603 {
604 const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
605 texel[RCOMP] =
606 texel[GCOMP] =
607 texel[BCOMP] = (s & 0xf) * (1.0F / 15.0F);
608 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
609 }
610
611
612
613
614 /* MESA_FORMAT_AL88 **********************************************************/
615
616 /* Fetch texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
617 static void FETCH(f_al88)( const struct swrast_texture_image *texImage,
618 GLint i, GLint j, GLint k, GLfloat *texel )
619 {
620 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
621 texel[RCOMP] =
622 texel[GCOMP] =
623 texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
624 texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
625 }
626
627
628
629
630 /* MESA_FORMAT_AL88_REV ******************************************************/
631
632 /* Fetch texel from 1D, 2D or 3D al88_rev texture, return 4 GLchans */
633 static void FETCH(f_al88_rev)( const struct swrast_texture_image *texImage,
634 GLint i, GLint j, GLint k, GLfloat *texel )
635 {
636 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
637 texel[RCOMP] =
638 texel[GCOMP] =
639 texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
640 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
641 }
642
643
644
645
646 /* MESA_FORMAT_AL1616 ********************************************************/
647
648 /* Fetch texel from 1D, 2D or 3D al1616 texture, return 4 GLchans */
649 static void FETCH(f_al1616)( const struct swrast_texture_image *texImage,
650 GLint i, GLint j, GLint k, GLfloat *texel )
651 {
652 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
653 texel[RCOMP] =
654 texel[GCOMP] =
655 texel[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
656 texel[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
657 }
658
659
660
661
662 /* MESA_FORMAT_AL1616_REV ****************************************************/
663
664 /* Fetch texel from 1D, 2D or 3D al1616_rev texture, return 4 GLchans */
665 static void FETCH(f_al1616_rev)( const struct swrast_texture_image *texImage,
666 GLint i, GLint j, GLint k, GLfloat *texel )
667 {
668 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
669 texel[RCOMP] =
670 texel[GCOMP] =
671 texel[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
672 texel[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
673 }
674
675
676
677
678 /* MESA_FORMAT_RGB332 ********************************************************/
679
680 /* Fetch texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
681 static void FETCH(f_rgb332)( const struct swrast_texture_image *texImage,
682 GLint i, GLint j, GLint k, GLfloat *texel )
683 {
684 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
685 const GLubyte s = *src;
686 texel[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
687 texel[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
688 texel[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F);
689 texel[ACOMP] = 1.0F;
690 }
691
692
693
694
695 /* MESA_FORMAT_A8 ************************************************************/
696
697 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
698 static void FETCH(f_a8)( const struct swrast_texture_image *texImage,
699 GLint i, GLint j, GLint k, GLfloat *texel )
700 {
701 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
702 texel[RCOMP] =
703 texel[GCOMP] =
704 texel[BCOMP] = 0.0F;
705 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
706 }
707
708
709
710
711 /* MESA_FORMAT_A16 ************************************************************/
712
713 /* Fetch texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
714 static void FETCH(f_a16)( const struct swrast_texture_image *texImage,
715 GLint i, GLint j, GLint k, GLfloat *texel )
716 {
717 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
718 texel[RCOMP] =
719 texel[GCOMP] =
720 texel[BCOMP] = 0.0F;
721 texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
722 }
723
724
725
726
727 /* MESA_FORMAT_L8 ************************************************************/
728
729 /* Fetch texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
730 static void FETCH(f_l8)( const struct swrast_texture_image *texImage,
731 GLint i, GLint j, GLint k, GLfloat *texel )
732 {
733 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
734 texel[RCOMP] =
735 texel[GCOMP] =
736 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
737 texel[ACOMP] = 1.0F;
738 }
739
740
741
742
743 /* MESA_FORMAT_L16 ***********************************************************/
744
745 /* Fetch texel from 1D, 2D or 3D l16 texture, return 4 GLchans */
746 static void FETCH(f_l16)( const struct swrast_texture_image *texImage,
747 GLint i, GLint j, GLint k, GLfloat *texel )
748 {
749 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
750 texel[RCOMP] =
751 texel[GCOMP] =
752 texel[BCOMP] = USHORT_TO_FLOAT( src[0] );
753 texel[ACOMP] = 1.0F;
754 }
755
756
757
758
759 /* MESA_FORMAT_I8 ************************************************************/
760
761 /* Fetch texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
762 static void FETCH(f_i8)( const struct swrast_texture_image *texImage,
763 GLint i, GLint j, GLint k, GLfloat *texel )
764 {
765 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
766 texel[RCOMP] =
767 texel[GCOMP] =
768 texel[BCOMP] =
769 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
770 }
771
772
773
774
775 /* MESA_FORMAT_I16 ***********************************************************/
776
777 /* Fetch texel from 1D, 2D or 3D i16 texture, return 4 GLchans */
778 static void FETCH(f_i16)( const struct swrast_texture_image *texImage,
779 GLint i, GLint j, GLint k, GLfloat *texel )
780 {
781 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
782 texel[RCOMP] =
783 texel[GCOMP] =
784 texel[BCOMP] =
785 texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
786 }
787
788
789 /* MESA_FORMAT_RGBA_INT8 **************************************************/
790
791 static void
792 FETCH(rgba_int8)(const struct swrast_texture_image *texImage,
793 GLint i, GLint j, GLint k, GLfloat *texel )
794 {
795 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
796 texel[RCOMP] = (GLfloat) src[0];
797 texel[GCOMP] = (GLfloat) src[1];
798 texel[BCOMP] = (GLfloat) src[2];
799 texel[ACOMP] = (GLfloat) src[3];
800 }
801
802
803
804
805 /* MESA_FORMAT_RGBA_INT16 **************************************************/
806
807 static void
808 FETCH(rgba_int16)(const struct swrast_texture_image *texImage,
809 GLint i, GLint j, GLint k, GLfloat *texel )
810 {
811 const GLshort *src = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
812 texel[RCOMP] = (GLfloat) src[0];
813 texel[GCOMP] = (GLfloat) src[1];
814 texel[BCOMP] = (GLfloat) src[2];
815 texel[ACOMP] = (GLfloat) src[3];
816 }
817
818
819
820
821 /* MESA_FORMAT_RGBA_INT32 **************************************************/
822
823 static void
824 FETCH(rgba_int32)(const struct swrast_texture_image *texImage,
825 GLint i, GLint j, GLint k, GLfloat *texel )
826 {
827 const GLint *src = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
828 texel[RCOMP] = (GLfloat) src[0];
829 texel[GCOMP] = (GLfloat) src[1];
830 texel[BCOMP] = (GLfloat) src[2];
831 texel[ACOMP] = (GLfloat) src[3];
832 }
833
834
835
836
837 /* MESA_FORMAT_RGBA_UINT8 **************************************************/
838
839 static void
840 FETCH(rgba_uint8)(const struct swrast_texture_image *texImage,
841 GLint i, GLint j, GLint k, GLfloat *texel )
842 {
843 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
844 texel[RCOMP] = (GLfloat) src[0];
845 texel[GCOMP] = (GLfloat) src[1];
846 texel[BCOMP] = (GLfloat) src[2];
847 texel[ACOMP] = (GLfloat) src[3];
848 }
849
850
851
852
853 /* MESA_FORMAT_RGBA_UINT16 **************************************************/
854
855 static void
856 FETCH(rgba_uint16)(const struct swrast_texture_image *texImage,
857 GLint i, GLint j, GLint k, GLfloat *texel )
858 {
859 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
860 texel[RCOMP] = (GLfloat) src[0];
861 texel[GCOMP] = (GLfloat) src[1];
862 texel[BCOMP] = (GLfloat) src[2];
863 texel[ACOMP] = (GLfloat) src[3];
864 }
865
866
867
868
869 /* MESA_FORMAT_RGBA_UINT32 **************************************************/
870
871 static void
872 FETCH(rgba_uint32)(const struct swrast_texture_image *texImage,
873 GLint i, GLint j, GLint k, GLfloat *texel )
874 {
875 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
876 texel[RCOMP] = (GLfloat) src[0];
877 texel[GCOMP] = (GLfloat) src[1];
878 texel[BCOMP] = (GLfloat) src[2];
879 texel[ACOMP] = (GLfloat) src[3];
880 }
881
882
883
884 /* MESA_FORMAT_SIGNED_RGBA_16 ***********************************************/
885
886 static void
887 FETCH(signed_rgba_16)(const struct swrast_texture_image *texImage,
888 GLint i, GLint j, GLint k, GLfloat *texel)
889 {
890 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
891 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
892 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
893 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
894 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
895 }
896
897
898
899
900
901 /* MESA_FORMAT_RGBA_16 ***********************************************/
902
903 static void
904 FETCH(rgba_16)(const struct swrast_texture_image *texImage,
905 GLint i, GLint j, GLint k, GLfloat *texel)
906 {
907 const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
908 texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
909 texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
910 texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
911 texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
912 }
913
914
915
916
917
918 /* MESA_FORMAT_YCBCR *********************************************************/
919
920 /* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
921 * We convert YCbCr to RGB here.
922 */
923 static void FETCH(f_ycbcr)( const struct swrast_texture_image *texImage,
924 GLint i, GLint j, GLint k, GLfloat *texel )
925 {
926 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
927 const GLushort *src1 = src0 + 1; /* odd */
928 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
929 const GLubyte cb = *src0 & 0xff; /* chroma U */
930 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
931 const GLubyte cr = *src1 & 0xff; /* chroma V */
932 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
933 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
934 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
935 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
936 r *= (1.0F / 255.0F);
937 g *= (1.0F / 255.0F);
938 b *= (1.0F / 255.0F);
939 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
940 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
941 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
942 texel[ACOMP] = 1.0F;
943 }
944
945
946
947
948 /* MESA_FORMAT_YCBCR_REV *****************************************************/
949
950 /* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
951 * We convert YCbCr to RGB here.
952 */
953 static void FETCH(f_ycbcr_rev)( const struct swrast_texture_image *texImage,
954 GLint i, GLint j, GLint k, GLfloat *texel )
955 {
956 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
957 const GLushort *src1 = src0 + 1; /* odd */
958 const GLubyte y0 = *src0 & 0xff; /* luminance */
959 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
960 const GLubyte y1 = *src1 & 0xff; /* luminance */
961 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
962 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
963 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
964 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
965 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
966 r *= (1.0F / 255.0F);
967 g *= (1.0F / 255.0F);
968 b *= (1.0F / 255.0F);
969 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
970 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
971 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
972 texel[ACOMP] = 1.0F;
973 }
974
975
976
977
978 /* MESA_TEXFORMAT_Z24_S8 ***************************************************/
979
980 static void FETCH(f_z24_s8)( const struct swrast_texture_image *texImage,
981 GLint i, GLint j, GLint k, GLfloat *texel )
982 {
983 /* only return Z, not stencil data */
984 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
985 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
986 texel[0] = ((*src) >> 8) * scale;
987 ASSERT(texImage->Base.TexFormat == MESA_FORMAT_Z24_S8 ||
988 texImage->Base.TexFormat == MESA_FORMAT_Z24_X8);
989 ASSERT(texel[0] >= 0.0F);
990 ASSERT(texel[0] <= 1.0F);
991 }
992
993
994
995
996 /* MESA_TEXFORMAT_S8_Z24 ***************************************************/
997
998 static void FETCH(f_s8_z24)( const struct swrast_texture_image *texImage,
999 GLint i, GLint j, GLint k, GLfloat *texel )
1000 {
1001 /* only return Z, not stencil data */
1002 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1003 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
1004 texel[0] = ((*src) & 0x00ffffff) * scale;
1005 ASSERT(texImage->Base.TexFormat == MESA_FORMAT_S8_Z24 ||
1006 texImage->Base.TexFormat == MESA_FORMAT_X8_Z24);
1007 ASSERT(texel[0] >= 0.0F);
1008 ASSERT(texel[0] <= 1.0F);
1009 }
1010
1011
1012
1013 #undef TEXEL_ADDR
1014 #undef DIM
1015 #undef FETCH