Remove the ATI_envmap_bumpmap extension
[mesa.git] / src / mesa / swrast / s_texfetch_tmp.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (c) 2008-2009 VMware, Inc.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * 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)->ImageSlices[0] + (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 *)((GLubyte *) (image)->ImageSlices[0] + (image)->RowStride * (j)) + \
55 (i) * (size)))
56
57 #define FETCH(x) fetch_texel_2d_##x
58
59 #elif DIM == 3
60
61 #define TEXEL_ADDR( type, image, i, j, k, size ) \
62 ((type *)((GLubyte *) (image)->ImageSlices[k] + \
63 (image)->RowStride * (j)) + (i) * (size))
64
65 #define FETCH(x) fetch_texel_3d_##x
66
67 #else
68 #error illegal number of texture dimensions
69 #endif
70
71
72 static void
73 FETCH(Z_UNORM32)(const struct swrast_texture_image *texImage,
74 GLint i, GLint j, GLint k, GLfloat *texel)
75 {
76 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
77 texel[0] = src[0] * (1.0F / 0xffffffff);
78 }
79
80
81 static void
82 FETCH(Z_UNORM16)(const struct swrast_texture_image *texImage,
83 GLint i, GLint j, GLint k, GLfloat *texel)
84 {
85 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
86 texel[0] = src[0] * (1.0F / 65535.0F);
87 }
88
89
90 static void
91 FETCH(RGBA_FLOAT32)(const struct swrast_texture_image *texImage,
92 GLint i, GLint j, GLint k, GLfloat *texel)
93 {
94 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
95 texel[RCOMP] = src[0];
96 texel[GCOMP] = src[1];
97 texel[BCOMP] = src[2];
98 texel[ACOMP] = src[3];
99 }
100
101
102 static void
103 FETCH(RGBA_FLOAT16)(const struct swrast_texture_image *texImage,
104 GLint i, GLint j, GLint k, GLfloat *texel)
105 {
106 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
107 texel[RCOMP] = _mesa_half_to_float(src[0]);
108 texel[GCOMP] = _mesa_half_to_float(src[1]);
109 texel[BCOMP] = _mesa_half_to_float(src[2]);
110 texel[ACOMP] = _mesa_half_to_float(src[3]);
111 }
112
113
114 static void
115 FETCH(RGB_FLOAT32)(const struct swrast_texture_image *texImage,
116 GLint i, GLint j, GLint k, GLfloat *texel)
117 {
118 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 3);
119 texel[RCOMP] = src[0];
120 texel[GCOMP] = src[1];
121 texel[BCOMP] = src[2];
122 texel[ACOMP] = 1.0F;
123 }
124
125
126 static void
127 FETCH(RGB_FLOAT16)(const struct swrast_texture_image *texImage,
128 GLint i, GLint j, GLint k, GLfloat *texel)
129 {
130 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 3);
131 texel[RCOMP] = _mesa_half_to_float(src[0]);
132 texel[GCOMP] = _mesa_half_to_float(src[1]);
133 texel[BCOMP] = _mesa_half_to_float(src[2]);
134 texel[ACOMP] = 1.0F;
135 }
136
137
138 static void
139 FETCH(A_FLOAT32)(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, 1);
143 texel[RCOMP] =
144 texel[GCOMP] =
145 texel[BCOMP] = 0.0F;
146 texel[ACOMP] = src[0];
147 }
148
149
150 static void
151 FETCH(A_FLOAT16)(const struct swrast_texture_image *texImage,
152 GLint i, GLint j, GLint k, GLfloat *texel)
153 {
154 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
155 texel[RCOMP] =
156 texel[GCOMP] =
157 texel[BCOMP] = 0.0F;
158 texel[ACOMP] = _mesa_half_to_float(src[0]);
159 }
160
161
162 static void
163 FETCH(L_FLOAT32)(const struct swrast_texture_image *texImage,
164 GLint i, GLint j, GLint k, GLfloat *texel)
165 {
166 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
167 texel[RCOMP] =
168 texel[GCOMP] =
169 texel[BCOMP] = src[0];
170 texel[ACOMP] = 1.0F;
171 }
172
173
174 static void
175 FETCH(L_FLOAT16)(const struct swrast_texture_image *texImage,
176 GLint i, GLint j, GLint k, GLfloat *texel)
177 {
178 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
179 texel[RCOMP] =
180 texel[GCOMP] =
181 texel[BCOMP] = _mesa_half_to_float(src[0]);
182 texel[ACOMP] = 1.0F;
183 }
184
185
186 static void
187 FETCH(LA_FLOAT32)(const struct swrast_texture_image *texImage,
188 GLint i, GLint j, GLint k, GLfloat *texel)
189 {
190 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
191 texel[RCOMP] =
192 texel[GCOMP] =
193 texel[BCOMP] = src[0];
194 texel[ACOMP] = src[1];
195 }
196
197
198 static void
199 FETCH(LA_FLOAT16)(const struct swrast_texture_image *texImage,
200 GLint i, GLint j, GLint k, GLfloat *texel)
201 {
202 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
203 texel[RCOMP] =
204 texel[GCOMP] =
205 texel[BCOMP] = _mesa_half_to_float(src[0]);
206 texel[ACOMP] = _mesa_half_to_float(src[1]);
207 }
208
209
210 static void
211 FETCH(I_FLOAT32)(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] =
218 texel[ACOMP] = src[0];
219 }
220
221
222 static void
223 FETCH(I_FLOAT16)(const struct swrast_texture_image *texImage,
224 GLint i, GLint j, GLint k, GLfloat *texel)
225 {
226 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
227 texel[RCOMP] =
228 texel[GCOMP] =
229 texel[BCOMP] =
230 texel[ACOMP] = _mesa_half_to_float(src[0]);
231 }
232
233
234 static void
235 FETCH(R_FLOAT32)(const struct swrast_texture_image *texImage,
236 GLint i, GLint j, GLint k, GLfloat *texel)
237 {
238 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 1);
239 texel[RCOMP] = src[0];
240 texel[GCOMP] = 0.0F;
241 texel[BCOMP] = 0.0F;
242 texel[ACOMP] = 1.0F;
243 }
244
245
246 static void
247 FETCH(R_FLOAT16)(const struct swrast_texture_image *texImage,
248 GLint i, GLint j, GLint k, GLfloat *texel)
249 {
250 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 1);
251 texel[RCOMP] = _mesa_half_to_float(src[0]);
252 texel[GCOMP] = 0.0F;
253 texel[BCOMP] = 0.0F;
254 texel[ACOMP] = 1.0F;
255 }
256
257
258 static void
259 FETCH(RG_FLOAT32)(const struct swrast_texture_image *texImage,
260 GLint i, GLint j, GLint k, GLfloat *texel)
261 {
262 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
263 texel[RCOMP] = src[0];
264 texel[GCOMP] = src[1];
265 texel[BCOMP] = 0.0F;
266 texel[ACOMP] = 1.0F;
267 }
268
269
270 static void
271 FETCH(RG_FLOAT16)(const struct swrast_texture_image *texImage,
272 GLint i, GLint j, GLint k, GLfloat *texel)
273 {
274 const GLhalfARB *src = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 2);
275 texel[RCOMP] = _mesa_half_to_float(src[0]);
276 texel[GCOMP] = _mesa_half_to_float(src[1]);
277 texel[BCOMP] = 0.0F;
278 texel[ACOMP] = 1.0F;
279 }
280
281
282 static void
283 FETCH(A8B8G8R8_UNORM)(const struct swrast_texture_image *texImage,
284 GLint i, GLint j, GLint k, GLfloat *texel)
285 {
286 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
287 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
288 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
289 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
290 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
291 }
292
293
294 static void
295 FETCH(R8G8B8A8_UNORM)(const struct swrast_texture_image *texImage,
296 GLint i, GLint j, GLint k, GLfloat *texel)
297 {
298 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
299 texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
300 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
301 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
302 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
303 }
304
305
306 static void
307 FETCH(B8G8R8A8_UNORM)(const struct swrast_texture_image *texImage,
308 GLint i, GLint j, GLint k, GLfloat *texel)
309 {
310 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
311 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
312 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
313 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
314 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) );
315 }
316
317
318 static void
319 FETCH(A8R8G8B8_UNORM)(const struct swrast_texture_image *texImage,
320 GLint i, GLint j, GLint k, GLfloat *texel)
321 {
322 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
323 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
324 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
325 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
326 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
327 }
328
329
330 static void
331 FETCH(X8B8G8R8_UNORM)(const struct swrast_texture_image *texImage,
332 GLint i, GLint j, GLint k, GLfloat *texel)
333 {
334 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
335 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
336 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
337 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
338 texel[ACOMP] = 1.0f;
339 }
340
341
342 static void
343 FETCH(R8G8B8X8_UNORM)(const struct swrast_texture_image *texImage,
344 GLint i, GLint j, GLint k, GLfloat *texel)
345 {
346 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
347 texel[RCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
348 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
349 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
350 texel[ACOMP] = 1.0f;
351 }
352
353
354 static void
355 FETCH(B8G8R8X8_UNORM)(const struct swrast_texture_image *texImage,
356 GLint i, GLint j, GLint k, GLfloat *texel)
357 {
358 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
359 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
360 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
361 texel[BCOMP] = UBYTE_TO_FLOAT( (s ) & 0xff );
362 texel[ACOMP] = 1.0f;
363 }
364
365
366 static void
367 FETCH(X8R8G8B8_UNORM)(const struct swrast_texture_image *texImage,
368 GLint i, GLint j, GLint k, GLfloat *texel)
369 {
370 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
371 texel[RCOMP] = UBYTE_TO_FLOAT( (s >> 8) & 0xff );
372 texel[GCOMP] = UBYTE_TO_FLOAT( (s >> 16) & 0xff );
373 texel[BCOMP] = UBYTE_TO_FLOAT( (s >> 24) );
374 texel[ACOMP] = 1.0f;
375 }
376
377
378 static void
379 FETCH(BGR_UNORM8)(const struct swrast_texture_image *texImage,
380 GLint i, GLint j, GLint k, GLfloat *texel)
381 {
382 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
383 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
384 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
385 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
386 texel[ACOMP] = 1.0F;
387 }
388
389
390 static void
391 FETCH(RGB_UNORM8)(const struct swrast_texture_image *texImage,
392 GLint i, GLint j, GLint k, GLfloat *texel)
393 {
394 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
395 texel[RCOMP] = UBYTE_TO_FLOAT( src[0] );
396 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
397 texel[BCOMP] = UBYTE_TO_FLOAT( src[2] );
398 texel[ACOMP] = 1.0F;
399 }
400
401
402 static void
403 FETCH(B5G6R5_UNORM)(const struct swrast_texture_image *texImage,
404 GLint i, GLint j, GLint k, GLfloat *texel)
405 {
406 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
407 const GLushort s = *src;
408 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
409 texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
410 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
411 texel[ACOMP] = 1.0F;
412 }
413
414
415 static void
416 FETCH(R5G6B5_UNORM)(const struct swrast_texture_image *texImage,
417 GLint i, GLint j, GLint k, GLfloat *texel)
418 {
419 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
420 const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */
421 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );
422 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );
423 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
424 texel[ACOMP] = 1.0F;
425 }
426
427
428 static void
429 FETCH(B4G4R4A4_UNORM)(const struct swrast_texture_image *texImage,
430 GLint i, GLint j, GLint k, GLfloat *texel)
431 {
432 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
433 const GLushort s = *src;
434 texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
435 texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
436 texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
437 texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
438 }
439
440
441 static void
442 FETCH(A4R4G4B4_UNORM)(const struct swrast_texture_image *texImage,
443 GLint i, GLint j, GLint k, GLfloat *texel)
444 {
445 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
446 texel[RCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
447 texel[GCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
448 texel[BCOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
449 texel[ACOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
450 }
451
452
453 static void
454 FETCH(A1B5G5R5_UNORM)(const struct swrast_texture_image *texImage,
455 GLint i, GLint j, GLint k, GLfloat *texel)
456 {
457 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
458 const GLushort s = *src;
459 texel[RCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
460 texel[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
461 texel[BCOMP] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
462 texel[ACOMP] = ((s ) & 0x01) * 1.0F;
463 }
464
465
466 static void
467 FETCH(B5G5R5A1_UNORM)(const struct swrast_texture_image *texImage,
468 GLint i, GLint j, GLint k, GLfloat *texel)
469 {
470 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
471 const GLushort s = *src;
472 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
473 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
474 texel[BCOMP] = ((s >> 0) & 0x1f) * (1.0F / 31.0F);
475 texel[ACOMP] = ((s >> 15) & 0x01) * 1.0F;
476 }
477
478
479 static void
480 FETCH(A1R5G5B5_UNORM)(const struct swrast_texture_image *texImage,
481 GLint i, GLint j, GLint k, GLfloat *texel)
482 {
483 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
484 const GLushort s = (*src << 8) | (*src >> 8); /* byteswap */
485 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 7) & 0xf8) | ((s >> 12) & 0x7) );
486 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 2) & 0xf8) | ((s >> 7) & 0x7) );
487 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );
488 texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
489 }
490
491
492 static void
493 FETCH(B10G10R10A2_UNORM)(const struct swrast_texture_image *texImage,
494 GLint i, GLint j, GLint k, GLfloat *texel)
495 {
496 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
497 const GLuint s = *src;
498 texel[RCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F);
499 texel[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F);
500 texel[BCOMP] = ((s >> 0) & 0x3ff) * (1.0F / 1023.0F);
501 texel[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F);
502 }
503
504
505 static void
506 FETCH(R10G10B10A2_UNORM)(const struct swrast_texture_image *texImage,
507 GLint i, GLint j, GLint k, GLfloat *texel)
508 {
509 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
510 const GLuint s = *src;
511 texel[RCOMP] = ((s >> 0) & 0x3ff) * (1.0F / 1023.0F);
512 texel[GCOMP] = ((s >> 10) & 0x3ff) * (1.0F / 1023.0F);
513 texel[BCOMP] = ((s >> 20) & 0x3ff) * (1.0F / 1023.0F);
514 texel[ACOMP] = ((s >> 30) & 0x03) * (1.0F / 3.0F);
515 }
516
517
518 static void
519 FETCH(R8G8_UNORM)(const struct swrast_texture_image *texImage,
520 GLint i, GLint j, GLint k, GLfloat *texel)
521 {
522 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
523 texel[RCOMP] = UBYTE_TO_FLOAT( s & 0xff );
524 texel[GCOMP] = UBYTE_TO_FLOAT( s >> 8 );
525 texel[BCOMP] = 0.0;
526 texel[ACOMP] = 1.0;
527 }
528
529
530 static void
531 FETCH(G8R8_UNORM)(const struct swrast_texture_image *texImage,
532 GLint i, GLint j, GLint k, GLfloat *texel)
533 {
534 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
535 texel[RCOMP] = UBYTE_TO_FLOAT( s >> 8 );
536 texel[GCOMP] = UBYTE_TO_FLOAT( s & 0xff );
537 texel[BCOMP] = 0.0;
538 texel[ACOMP] = 1.0;
539 }
540
541
542 static void
543 FETCH(L4A4_UNORM)(const struct swrast_texture_image *texImage,
544 GLint i, GLint j, GLint k, GLfloat *texel)
545 {
546 const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
547 texel[RCOMP] =
548 texel[GCOMP] =
549 texel[BCOMP] = (s & 0xf) * (1.0F / 15.0F);
550 texel[ACOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
551 }
552
553
554 static void
555 FETCH(L8A8_UNORM)(const struct swrast_texture_image *texImage,
556 GLint i, GLint j, GLint k, GLfloat *texel)
557 {
558 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
559 texel[RCOMP] =
560 texel[GCOMP] =
561 texel[BCOMP] = UBYTE_TO_FLOAT( s & 0xff );
562 texel[ACOMP] = UBYTE_TO_FLOAT( s >> 8 );
563 }
564
565
566 static void
567 FETCH(R_UNORM8)(const struct swrast_texture_image *texImage,
568 GLint i, GLint j, GLint k, GLfloat *texel)
569 {
570 const GLubyte s = *TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
571 texel[RCOMP] = UBYTE_TO_FLOAT(s);
572 texel[GCOMP] = 0.0;
573 texel[BCOMP] = 0.0;
574 texel[ACOMP] = 1.0;
575 }
576
577
578 static void
579 FETCH(R_UNORM16)(const struct swrast_texture_image *texImage,
580 GLint i, GLint j, GLint k, GLfloat *texel)
581 {
582 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
583 texel[RCOMP] = USHORT_TO_FLOAT(s);
584 texel[GCOMP] = 0.0;
585 texel[BCOMP] = 0.0;
586 texel[ACOMP] = 1.0;
587 }
588
589
590 static void
591 FETCH(A8L8_UNORM)(const struct swrast_texture_image *texImage,
592 GLint i, GLint j, GLint k, GLfloat *texel)
593 {
594 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
595 texel[RCOMP] =
596 texel[GCOMP] =
597 texel[BCOMP] = UBYTE_TO_FLOAT( s >> 8 );
598 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff );
599 }
600
601
602 static void
603 FETCH(R16G16_UNORM)(const struct swrast_texture_image *texImage,
604 GLint i, GLint j, GLint k, GLfloat *texel)
605 {
606 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
607 texel[RCOMP] = USHORT_TO_FLOAT( s & 0xffff );
608 texel[GCOMP] = USHORT_TO_FLOAT( s >> 16 );
609 texel[BCOMP] = 0.0;
610 texel[ACOMP] = 1.0;
611 }
612
613
614 static void
615 FETCH(G16R16_UNORM)(const struct swrast_texture_image *texImage,
616 GLint i, GLint j, GLint k, GLfloat *texel)
617 {
618 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
619 texel[RCOMP] = USHORT_TO_FLOAT( s >> 16 );
620 texel[GCOMP] = USHORT_TO_FLOAT( s & 0xffff );
621 texel[BCOMP] = 0.0;
622 texel[ACOMP] = 1.0;
623 }
624
625
626 static void
627 FETCH(L16A16_UNORM)(const struct swrast_texture_image *texImage,
628 GLint i, GLint j, GLint k, GLfloat *texel)
629 {
630 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
631 texel[RCOMP] =
632 texel[GCOMP] =
633 texel[BCOMP] = USHORT_TO_FLOAT( s & 0xffff );
634 texel[ACOMP] = USHORT_TO_FLOAT( s >> 16 );
635 }
636
637
638 static void
639 FETCH(A16L16_UNORM)(const struct swrast_texture_image *texImage,
640 GLint i, GLint j, GLint k, GLfloat *texel)
641 {
642 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
643 texel[RCOMP] =
644 texel[GCOMP] =
645 texel[BCOMP] = USHORT_TO_FLOAT( s >> 16 );
646 texel[ACOMP] = USHORT_TO_FLOAT( s & 0xffff );
647 }
648
649
650 static void
651 FETCH(B2G3R3_UNORM)(const struct swrast_texture_image *texImage,
652 GLint i, GLint j, GLint k, GLfloat *texel)
653 {
654 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
655 const GLubyte s = *src;
656 texel[RCOMP] = ((s >> 5) & 0x7) * (1.0F / 7.0F);
657 texel[GCOMP] = ((s >> 2) & 0x7) * (1.0F / 7.0F);
658 texel[BCOMP] = ((s ) & 0x3) * (1.0F / 3.0F);
659 texel[ACOMP] = 1.0F;
660 }
661
662
663 static void
664 FETCH(A_UNORM8)(const struct swrast_texture_image *texImage,
665 GLint i, GLint j, GLint k, GLfloat *texel)
666 {
667 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
668 texel[RCOMP] =
669 texel[GCOMP] =
670 texel[BCOMP] = 0.0F;
671 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
672 }
673
674
675 static void
676 FETCH(A_UNORM16)(const struct swrast_texture_image *texImage,
677 GLint i, GLint j, GLint k, GLfloat *texel)
678 {
679 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
680 texel[RCOMP] =
681 texel[GCOMP] =
682 texel[BCOMP] = 0.0F;
683 texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
684 }
685
686
687 static void
688 FETCH(L_UNORM8)(const struct swrast_texture_image *texImage,
689 GLint i, GLint j, GLint k, GLfloat *texel)
690 {
691 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
692 texel[RCOMP] =
693 texel[GCOMP] =
694 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
695 texel[ACOMP] = 1.0F;
696 }
697
698
699 static void
700 FETCH(L_UNORM16)(const struct swrast_texture_image *texImage,
701 GLint i, GLint j, GLint k, GLfloat *texel)
702 {
703 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
704 texel[RCOMP] =
705 texel[GCOMP] =
706 texel[BCOMP] = USHORT_TO_FLOAT( src[0] );
707 texel[ACOMP] = 1.0F;
708 }
709
710
711 static void
712 FETCH(I_UNORM8)(const struct swrast_texture_image *texImage,
713 GLint i, GLint j, GLint k, GLfloat *texel)
714 {
715 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
716 texel[RCOMP] =
717 texel[GCOMP] =
718 texel[BCOMP] =
719 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
720 }
721
722
723 static void
724 FETCH(I_UNORM16)(const struct swrast_texture_image *texImage,
725 GLint i, GLint j, GLint k, GLfloat *texel)
726 {
727 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
728 texel[RCOMP] =
729 texel[GCOMP] =
730 texel[BCOMP] =
731 texel[ACOMP] = USHORT_TO_FLOAT( src[0] );
732 }
733
734
735 static void
736 FETCH(BGR_SRGB8)(const struct swrast_texture_image *texImage,
737 GLint i, GLint j, GLint k, GLfloat *texel)
738 {
739 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
740 texel[RCOMP] = nonlinear_to_linear(src[2]);
741 texel[GCOMP] = nonlinear_to_linear(src[1]);
742 texel[BCOMP] = nonlinear_to_linear(src[0]);
743 texel[ACOMP] = 1.0F;
744 }
745
746
747 static void
748 FETCH(A8B8G8R8_SRGB)(const struct swrast_texture_image *texImage,
749 GLint i, GLint j, GLint k, GLfloat *texel)
750 {
751 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
752 texel[RCOMP] = nonlinear_to_linear( (s >> 24) );
753 texel[GCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
754 texel[BCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
755 texel[ACOMP] = UBYTE_TO_FLOAT( (s ) & 0xff ); /* linear! */
756 }
757
758
759 static void
760 FETCH(B8G8R8A8_SRGB)(const struct swrast_texture_image *texImage,
761 GLint i, GLint j, GLint k, GLfloat *texel)
762 {
763 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
764 texel[RCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
765 texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
766 texel[BCOMP] = nonlinear_to_linear( (s ) & 0xff );
767 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
768 }
769
770
771 static void
772 FETCH(R8G8B8A8_SRGB)(const struct swrast_texture_image *texImage,
773 GLint i, GLint j, GLint k, GLfloat *texel)
774 {
775 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
776 texel[RCOMP] = nonlinear_to_linear( (s ) & 0xff );
777 texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
778 texel[BCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
779 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
780 }
781
782
783 static void
784 FETCH(R8G8B8X8_SRGB)(const struct swrast_texture_image *texImage,
785 GLint i, GLint j, GLint k, GLfloat *texel)
786 {
787 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
788 texel[RCOMP] = nonlinear_to_linear( (s ) & 0xff );
789 texel[GCOMP] = nonlinear_to_linear( (s >> 8) & 0xff );
790 texel[BCOMP] = nonlinear_to_linear( (s >> 16) & 0xff );
791 texel[ACOMP] = 1.0f;
792 }
793
794
795 static void
796 FETCH(L_SRGB8)(const struct swrast_texture_image *texImage,
797 GLint i, GLint j, GLint k, GLfloat *texel)
798 {
799 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
800 texel[RCOMP] =
801 texel[GCOMP] =
802 texel[BCOMP] = nonlinear_to_linear(src[0]);
803 texel[ACOMP] = 1.0F;
804 }
805
806
807 static void
808 FETCH(L8A8_SRGB)(const struct swrast_texture_image *texImage,
809 GLint i, GLint j, GLint k, GLfloat *texel)
810 {
811 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
812 texel[RCOMP] =
813 texel[GCOMP] =
814 texel[BCOMP] = nonlinear_to_linear(src[0]);
815 texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
816 }
817
818
819 static void
820 FETCH(RGBA_SINT8)(const struct swrast_texture_image *texImage,
821 GLint i, GLint j, GLint k, GLfloat *texel)
822 {
823 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 4);
824 texel[RCOMP] = (GLfloat) src[0];
825 texel[GCOMP] = (GLfloat) src[1];
826 texel[BCOMP] = (GLfloat) src[2];
827 texel[ACOMP] = (GLfloat) src[3];
828 }
829
830
831 static void
832 FETCH(RGBA_SINT16)(const struct swrast_texture_image *texImage,
833 GLint i, GLint j, GLint k, GLfloat *texel)
834 {
835 const GLshort *src = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
836 texel[RCOMP] = (GLfloat) src[0];
837 texel[GCOMP] = (GLfloat) src[1];
838 texel[BCOMP] = (GLfloat) src[2];
839 texel[ACOMP] = (GLfloat) src[3];
840 }
841
842
843 static void
844 FETCH(RGBA_SINT32)(const struct swrast_texture_image *texImage,
845 GLint i, GLint j, GLint k, GLfloat *texel)
846 {
847 const GLint *src = TEXEL_ADDR(GLint, texImage, i, j, k, 4);
848 texel[RCOMP] = (GLfloat) src[0];
849 texel[GCOMP] = (GLfloat) src[1];
850 texel[BCOMP] = (GLfloat) src[2];
851 texel[ACOMP] = (GLfloat) src[3];
852 }
853
854
855 static void
856 FETCH(RGBA_UINT8)(const struct swrast_texture_image *texImage,
857 GLint i, GLint j, GLint k, GLfloat *texel)
858 {
859 const GLubyte *src = TEXEL_ADDR(GLubyte, 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 static void
868 FETCH(RGBA_UINT16)(const struct swrast_texture_image *texImage,
869 GLint i, GLint j, GLint k, GLfloat *texel)
870 {
871 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
872 texel[RCOMP] = (GLfloat) src[0];
873 texel[GCOMP] = (GLfloat) src[1];
874 texel[BCOMP] = (GLfloat) src[2];
875 texel[ACOMP] = (GLfloat) src[3];
876 }
877
878
879 static void
880 FETCH(RGBA_UINT32)(const struct swrast_texture_image *texImage,
881 GLint i, GLint j, GLint k, GLfloat *texel)
882 {
883 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
884 texel[RCOMP] = (GLfloat) src[0];
885 texel[GCOMP] = (GLfloat) src[1];
886 texel[BCOMP] = (GLfloat) src[2];
887 texel[ACOMP] = (GLfloat) src[3];
888 }
889
890
891 static void
892 FETCH(R_SNORM8)(const struct swrast_texture_image *texImage,
893 GLint i, GLint j, GLint k, GLfloat *texel)
894 {
895 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
896 texel[RCOMP] = BYTE_TO_FLOAT_TEX( s );
897 texel[GCOMP] = 0.0F;
898 texel[BCOMP] = 0.0F;
899 texel[ACOMP] = 1.0F;
900 }
901
902
903 static void
904 FETCH(A_SNORM8)(const struct swrast_texture_image *texImage,
905 GLint i, GLint j, GLint k, GLfloat *texel)
906 {
907 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
908 texel[RCOMP] = 0.0F;
909 texel[GCOMP] = 0.0F;
910 texel[BCOMP] = 0.0F;
911 texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
912 }
913
914
915 static void
916 FETCH(L_SNORM8)(const struct swrast_texture_image *texImage,
917 GLint i, GLint j, GLint k, GLfloat *texel)
918 {
919 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
920 texel[RCOMP] =
921 texel[GCOMP] =
922 texel[BCOMP] = BYTE_TO_FLOAT_TEX( s );
923 texel[ACOMP] = 1.0F;
924 }
925
926
927 static void
928 FETCH(I_SNORM8)(const struct swrast_texture_image *texImage,
929 GLint i, GLint j, GLint k, GLfloat *texel)
930 {
931 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
932 texel[RCOMP] =
933 texel[GCOMP] =
934 texel[BCOMP] =
935 texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
936 }
937
938
939 static void
940 FETCH(R8G8_SNORM)(const struct swrast_texture_image *texImage,
941 GLint i, GLint j, GLint k, GLfloat *texel)
942 {
943 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
944 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
945 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
946 texel[BCOMP] = 0.0F;
947 texel[ACOMP] = 1.0F;
948 }
949
950
951 static void
952 FETCH(L8A8_SNORM)(const struct swrast_texture_image *texImage,
953 GLint i, GLint j, GLint k, GLfloat *texel)
954 {
955 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
956 texel[RCOMP] =
957 texel[GCOMP] =
958 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
959 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
960 }
961
962
963 static void
964 FETCH(X8B8G8R8_SNORM)(const struct swrast_texture_image *texImage,
965 GLint i, GLint j, GLint k, GLfloat *texel)
966 {
967 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
968 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
969 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
970 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
971 texel[ACOMP] = 1.0f;
972 }
973
974
975 static void
976 FETCH(A8B8G8R8_SNORM)(const struct swrast_texture_image *texImage,
977 GLint i, GLint j, GLint k, GLfloat *texel)
978 {
979 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
980 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
981 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
982 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
983 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
984 }
985
986
987 static void
988 FETCH(R8G8B8A8_SNORM)(const struct swrast_texture_image *texImage,
989 GLint i, GLint j, GLint k, GLfloat *texel)
990 {
991 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
992 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
993 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
994 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
995 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
996 }
997
998
999 static void
1000 FETCH(R_SNORM16)(const struct swrast_texture_image *texImage,
1001 GLint i, GLint j, GLint k, GLfloat *texel)
1002 {
1003 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1004 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s );
1005 texel[GCOMP] = 0.0F;
1006 texel[BCOMP] = 0.0F;
1007 texel[ACOMP] = 1.0F;
1008 }
1009
1010
1011 static void
1012 FETCH(A_SNORM16)(const struct swrast_texture_image *texImage,
1013 GLint i, GLint j, GLint k, GLfloat *texel)
1014 {
1015 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1016 texel[RCOMP] = 0.0F;
1017 texel[GCOMP] = 0.0F;
1018 texel[BCOMP] = 0.0F;
1019 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
1020 }
1021
1022
1023 static void
1024 FETCH(L_SNORM16)(const struct swrast_texture_image *texImage,
1025 GLint i, GLint j, GLint k, GLfloat *texel)
1026 {
1027 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1028 texel[RCOMP] =
1029 texel[GCOMP] =
1030 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s );
1031 texel[ACOMP] = 1.0F;
1032 }
1033
1034
1035 static void
1036 FETCH(I_SNORM16)(const struct swrast_texture_image *texImage,
1037 GLint i, GLint j, GLint k, GLfloat *texel)
1038 {
1039 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1040 texel[RCOMP] =
1041 texel[GCOMP] =
1042 texel[BCOMP] =
1043 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
1044 }
1045
1046
1047 static void
1048 FETCH(R16G16_SNORM)(const struct swrast_texture_image *texImage,
1049 GLint i, GLint j, GLint k, GLfloat *texel)
1050 {
1051 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
1052 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1053 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1054 texel[BCOMP] = 0.0F;
1055 texel[ACOMP] = 1.0F;
1056 }
1057
1058
1059 static void
1060 FETCH(LA_SNORM16)(const struct swrast_texture_image *texImage,
1061 GLint i, GLint j, GLint k, GLfloat *texel)
1062 {
1063 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
1064 texel[RCOMP] =
1065 texel[GCOMP] =
1066 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1067 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1068 }
1069
1070
1071 static void
1072
1073 FETCH(RGB_SNORM16)(const struct swrast_texture_image *texImage,
1074 GLint i, GLint j, GLint k, GLfloat *texel)
1075 {
1076 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
1077 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1078 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1079 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
1080 texel[ACOMP] = 1.0F;
1081 }
1082
1083
1084 static void
1085 FETCH(RGBA_SNORM16)(const struct swrast_texture_image *texImage,
1086 GLint i, GLint j, GLint k, GLfloat *texel)
1087 {
1088 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1089 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1090 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1091 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
1092 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
1093 }
1094
1095
1096 static void
1097 FETCH(RGBA_UNORM16)(const struct swrast_texture_image *texImage,
1098 GLint i, GLint j, GLint k, GLfloat *texel)
1099 {
1100 const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1101 texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
1102 texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
1103 texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
1104 texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
1105 }
1106
1107
1108 static void
1109 FETCH(RGBX_UNORM16)(const struct swrast_texture_image *texImage,
1110 GLint i, GLint j, GLint k, GLfloat *texel)
1111 {
1112 const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1113 texel[RCOMP] = USHORT_TO_FLOAT(s[0]);
1114 texel[GCOMP] = USHORT_TO_FLOAT(s[1]);
1115 texel[BCOMP] = USHORT_TO_FLOAT(s[2]);
1116 texel[ACOMP] = 1.0f;
1117 }
1118
1119
1120 static void
1121 FETCH(RGBX_FLOAT16)(const struct swrast_texture_image *texImage,
1122 GLint i, GLint j, GLint k, GLfloat *texel)
1123 {
1124 const GLhalfARB *s = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
1125 texel[RCOMP] = _mesa_half_to_float(s[0]);
1126 texel[GCOMP] = _mesa_half_to_float(s[1]);
1127 texel[BCOMP] = _mesa_half_to_float(s[2]);
1128 texel[ACOMP] = 1.0f;
1129 }
1130
1131
1132 static void
1133 FETCH(RGBX_FLOAT32)(const struct swrast_texture_image *texImage,
1134 GLint i, GLint j, GLint k, GLfloat *texel)
1135 {
1136 const GLfloat *s = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
1137 texel[RCOMP] = s[0];
1138 texel[GCOMP] = s[1];
1139 texel[BCOMP] = s[2];
1140 texel[ACOMP] = 1.0f;
1141 }
1142
1143
1144 /**
1145 * Fetch texel from 1D, 2D or 3D ycbcr texture, returning RGBA.
1146 */
1147 static void
1148 FETCH(YCBCR)(const struct swrast_texture_image *texImage,
1149 GLint i, GLint j, GLint k, GLfloat *texel)
1150 {
1151 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1152 const GLushort *src1 = src0 + 1; /* odd */
1153 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1154 const GLubyte cb = *src0 & 0xff; /* chroma U */
1155 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1156 const GLubyte cr = *src1 & 0xff; /* chroma V */
1157 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1158 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1159 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1160 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1161 r *= (1.0F / 255.0F);
1162 g *= (1.0F / 255.0F);
1163 b *= (1.0F / 255.0F);
1164 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1165 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1166 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1167 texel[ACOMP] = 1.0F;
1168 }
1169
1170
1171 /**
1172 * Fetch texel from 1D, 2D or 3D ycbcr texture, returning RGBA.
1173 */
1174 static void
1175 FETCH(YCBCR_REV)(const struct swrast_texture_image *texImage,
1176 GLint i, GLint j, GLint k, GLfloat *texel)
1177 {
1178 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1179 const GLushort *src1 = src0 + 1; /* odd */
1180 const GLubyte y0 = *src0 & 0xff; /* luminance */
1181 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1182 const GLubyte y1 = *src1 & 0xff; /* luminance */
1183 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1184 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1185 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1186 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1187 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1188 r *= (1.0F / 255.0F);
1189 g *= (1.0F / 255.0F);
1190 b *= (1.0F / 255.0F);
1191 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1192 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1193 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1194 texel[ACOMP] = 1.0F;
1195 }
1196
1197
1198 static void
1199 FETCH(S8_UINT_Z24_UNORM)(const struct swrast_texture_image *texImage,
1200 GLint i, GLint j, GLint k, GLfloat *texel)
1201 {
1202 /* only return Z, not stencil data */
1203 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1204 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
1205 texel[0] = (GLfloat) (((*src) >> 8) * scale);
1206 ASSERT(texImage->Base.TexFormat == MESA_FORMAT_S8_UINT_Z24_UNORM ||
1207 texImage->Base.TexFormat == MESA_FORMAT_X8_UINT_Z24_UNORM);
1208 ASSERT(texel[0] >= 0.0F);
1209 ASSERT(texel[0] <= 1.0F);
1210 }
1211
1212
1213 static void
1214 FETCH(Z24_UNORM_S8_UINT)(const struct swrast_texture_image *texImage,
1215 GLint i, GLint j, GLint k, GLfloat *texel)
1216 {
1217 /* only return Z, not stencil data */
1218 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1219 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
1220 texel[0] = (GLfloat) (((*src) & 0x00ffffff) * scale);
1221 ASSERT(texImage->Base.TexFormat == MESA_FORMAT_Z24_UNORM_S8_UINT ||
1222 texImage->Base.TexFormat == MESA_FORMAT_Z24_UNORM_X8_UINT);
1223 ASSERT(texel[0] >= 0.0F);
1224 ASSERT(texel[0] <= 1.0F);
1225 }
1226
1227
1228 static void
1229 FETCH(R9G9B9E5_FLOAT)(const struct swrast_texture_image *texImage,
1230 GLint i, GLint j, GLint k, GLfloat *texel)
1231 {
1232 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1233 rgb9e5_to_float3(*src, texel);
1234 texel[ACOMP] = 1.0F;
1235 }
1236
1237
1238 static void
1239 FETCH(R11G11B10_FLOAT)(const struct swrast_texture_image *texImage,
1240 GLint i, GLint j, GLint k, GLfloat *texel)
1241 {
1242 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1243 r11g11b10f_to_float3(*src, texel);
1244 texel[ACOMP] = 1.0F;
1245 }
1246
1247
1248 static void
1249 FETCH(Z32_FLOAT_S8X24_UINT)(const struct swrast_texture_image *texImage,
1250 GLint i, GLint j, GLint k, GLfloat *texel)
1251 {
1252 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
1253 texel[RCOMP] = src[0];
1254 texel[GCOMP] = 0.0F;
1255 texel[BCOMP] = 0.0F;
1256 texel[ACOMP] = 1.0F;
1257 }
1258
1259
1260
1261 #undef TEXEL_ADDR
1262 #undef DIM
1263 #undef FETCH