swrast: fix more fetch_texel function names
[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 /**
892 * This format by definition produces 0,0,0,1 as rgba values,
893 * however we'll return the dudv values as rg and fix up elsewhere.
894 */
895 static void
896 FETCH(DUDV8)(const struct swrast_texture_image *texImage,
897 GLint i, GLint j, GLint k, GLfloat *texel)
898 {
899 const GLbyte *src = TEXEL_ADDR(GLbyte, texImage, i, j, k, 2);
900 texel[RCOMP] = BYTE_TO_FLOAT(src[0]);
901 texel[GCOMP] = BYTE_TO_FLOAT(src[1]);
902 texel[BCOMP] = 0;
903 texel[ACOMP] = 0;
904 }
905
906
907 static void
908 FETCH(R_SNORM8)(const struct swrast_texture_image *texImage,
909 GLint i, GLint j, GLint k, GLfloat *texel)
910 {
911 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
912 texel[RCOMP] = BYTE_TO_FLOAT_TEX( s );
913 texel[GCOMP] = 0.0F;
914 texel[BCOMP] = 0.0F;
915 texel[ACOMP] = 1.0F;
916 }
917
918
919 static void
920 FETCH(A_SNORM8)(const struct swrast_texture_image *texImage,
921 GLint i, GLint j, GLint k, GLfloat *texel)
922 {
923 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
924 texel[RCOMP] = 0.0F;
925 texel[GCOMP] = 0.0F;
926 texel[BCOMP] = 0.0F;
927 texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
928 }
929
930
931 static void
932 FETCH(L_SNORM8)(const struct swrast_texture_image *texImage,
933 GLint i, GLint j, GLint k, GLfloat *texel)
934 {
935 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
936 texel[RCOMP] =
937 texel[GCOMP] =
938 texel[BCOMP] = BYTE_TO_FLOAT_TEX( s );
939 texel[ACOMP] = 1.0F;
940 }
941
942
943 static void
944 FETCH(I_SNORM8)(const struct swrast_texture_image *texImage,
945 GLint i, GLint j, GLint k, GLfloat *texel)
946 {
947 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
948 texel[RCOMP] =
949 texel[GCOMP] =
950 texel[BCOMP] =
951 texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
952 }
953
954
955 static void
956 FETCH(R8G8_SNORM)(const struct swrast_texture_image *texImage,
957 GLint i, GLint j, GLint k, GLfloat *texel)
958 {
959 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
960 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
961 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
962 texel[BCOMP] = 0.0F;
963 texel[ACOMP] = 1.0F;
964 }
965
966
967 static void
968 FETCH(L8A8_SNORM)(const struct swrast_texture_image *texImage,
969 GLint i, GLint j, GLint k, GLfloat *texel)
970 {
971 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
972 texel[RCOMP] =
973 texel[GCOMP] =
974 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
975 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
976 }
977
978
979 static void
980 FETCH(X8B8G8R8_SNORM)(const struct swrast_texture_image *texImage,
981 GLint i, GLint j, GLint k, GLfloat *texel)
982 {
983 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
984 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
985 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
986 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
987 texel[ACOMP] = 1.0f;
988 }
989
990
991 static void
992 FETCH(A8B8G8R8_SNORM)(const struct swrast_texture_image *texImage,
993 GLint i, GLint j, GLint k, GLfloat *texel)
994 {
995 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
996 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
997 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
998 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
999 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1000 }
1001
1002
1003 static void
1004 FETCH(R8G8B8A8_SNORM)(const struct swrast_texture_image *texImage,
1005 GLint i, GLint j, GLint k, GLfloat *texel)
1006 {
1007 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1008 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1009 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1010 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1011 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1012 }
1013
1014
1015 static void
1016 FETCH(R_SNORM16)(const struct swrast_texture_image *texImage,
1017 GLint i, GLint j, GLint k, GLfloat *texel)
1018 {
1019 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1020 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s );
1021 texel[GCOMP] = 0.0F;
1022 texel[BCOMP] = 0.0F;
1023 texel[ACOMP] = 1.0F;
1024 }
1025
1026
1027 static void
1028 FETCH(A_SNORM16)(const struct swrast_texture_image *texImage,
1029 GLint i, GLint j, GLint k, GLfloat *texel)
1030 {
1031 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1032 texel[RCOMP] = 0.0F;
1033 texel[GCOMP] = 0.0F;
1034 texel[BCOMP] = 0.0F;
1035 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
1036 }
1037
1038
1039 static void
1040 FETCH(L_SNORM16)(const struct swrast_texture_image *texImage,
1041 GLint i, GLint j, GLint k, GLfloat *texel)
1042 {
1043 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1044 texel[RCOMP] =
1045 texel[GCOMP] =
1046 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s );
1047 texel[ACOMP] = 1.0F;
1048 }
1049
1050
1051 static void
1052 FETCH(I_SNORM16)(const struct swrast_texture_image *texImage,
1053 GLint i, GLint j, GLint k, GLfloat *texel)
1054 {
1055 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1056 texel[RCOMP] =
1057 texel[GCOMP] =
1058 texel[BCOMP] =
1059 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
1060 }
1061
1062
1063 static void
1064 FETCH(R16G16_SNORM)(const struct swrast_texture_image *texImage,
1065 GLint i, GLint j, GLint k, GLfloat *texel)
1066 {
1067 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
1068 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1069 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1070 texel[BCOMP] = 0.0F;
1071 texel[ACOMP] = 1.0F;
1072 }
1073
1074
1075 static void
1076 FETCH(LA_SNORM16)(const struct swrast_texture_image *texImage,
1077 GLint i, GLint j, GLint k, GLfloat *texel)
1078 {
1079 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
1080 texel[RCOMP] =
1081 texel[GCOMP] =
1082 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1083 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1084 }
1085
1086
1087 static void
1088
1089 FETCH(RGB_SNORM16)(const struct swrast_texture_image *texImage,
1090 GLint i, GLint j, GLint k, GLfloat *texel)
1091 {
1092 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
1093 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1094 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1095 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
1096 texel[ACOMP] = 1.0F;
1097 }
1098
1099
1100 static void
1101 FETCH(RGBA_SNORM16)(const struct swrast_texture_image *texImage,
1102 GLint i, GLint j, GLint k, GLfloat *texel)
1103 {
1104 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1105 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1106 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1107 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
1108 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
1109 }
1110
1111
1112 static void
1113 FETCH(RGBA_UNORM16)(const struct swrast_texture_image *texImage,
1114 GLint i, GLint j, GLint k, GLfloat *texel)
1115 {
1116 const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1117 texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
1118 texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
1119 texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
1120 texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
1121 }
1122
1123
1124 static void
1125 FETCH(RGBX_UNORM16)(const struct swrast_texture_image *texImage,
1126 GLint i, GLint j, GLint k, GLfloat *texel)
1127 {
1128 const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1129 texel[RCOMP] = USHORT_TO_FLOAT(s[0]);
1130 texel[GCOMP] = USHORT_TO_FLOAT(s[1]);
1131 texel[BCOMP] = USHORT_TO_FLOAT(s[2]);
1132 texel[ACOMP] = 1.0f;
1133 }
1134
1135
1136 static void
1137 FETCH(RGBX_FLOAT16)(const struct swrast_texture_image *texImage,
1138 GLint i, GLint j, GLint k, GLfloat *texel)
1139 {
1140 const GLhalfARB *s = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
1141 texel[RCOMP] = _mesa_half_to_float(s[0]);
1142 texel[GCOMP] = _mesa_half_to_float(s[1]);
1143 texel[BCOMP] = _mesa_half_to_float(s[2]);
1144 texel[ACOMP] = 1.0f;
1145 }
1146
1147
1148 static void
1149 FETCH(RGBX_FLOAT32)(const struct swrast_texture_image *texImage,
1150 GLint i, GLint j, GLint k, GLfloat *texel)
1151 {
1152 const GLfloat *s = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
1153 texel[RCOMP] = s[0];
1154 texel[GCOMP] = s[1];
1155 texel[BCOMP] = s[2];
1156 texel[ACOMP] = 1.0f;
1157 }
1158
1159
1160 /**
1161 * Fetch texel from 1D, 2D or 3D ycbcr texture, returning RGBA.
1162 */
1163 static void
1164 FETCH(YCBCR)(const struct swrast_texture_image *texImage,
1165 GLint i, GLint j, GLint k, GLfloat *texel)
1166 {
1167 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1168 const GLushort *src1 = src0 + 1; /* odd */
1169 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1170 const GLubyte cb = *src0 & 0xff; /* chroma U */
1171 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1172 const GLubyte cr = *src1 & 0xff; /* chroma V */
1173 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1174 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1175 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1176 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1177 r *= (1.0F / 255.0F);
1178 g *= (1.0F / 255.0F);
1179 b *= (1.0F / 255.0F);
1180 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1181 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1182 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1183 texel[ACOMP] = 1.0F;
1184 }
1185
1186
1187 /**
1188 * Fetch texel from 1D, 2D or 3D ycbcr texture, returning RGBA.
1189 */
1190 static void
1191 FETCH(YCBCR_REV)(const struct swrast_texture_image *texImage,
1192 GLint i, GLint j, GLint k, GLfloat *texel)
1193 {
1194 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1195 const GLushort *src1 = src0 + 1; /* odd */
1196 const GLubyte y0 = *src0 & 0xff; /* luminance */
1197 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1198 const GLubyte y1 = *src1 & 0xff; /* luminance */
1199 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1200 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1201 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1202 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1203 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1204 r *= (1.0F / 255.0F);
1205 g *= (1.0F / 255.0F);
1206 b *= (1.0F / 255.0F);
1207 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1208 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1209 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1210 texel[ACOMP] = 1.0F;
1211 }
1212
1213
1214 static void
1215 FETCH(S8_UINT_Z24_UNORM)(const struct swrast_texture_image *texImage,
1216 GLint i, GLint j, GLint k, GLfloat *texel)
1217 {
1218 /* only return Z, not stencil data */
1219 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1220 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
1221 texel[0] = (GLfloat) (((*src) >> 8) * scale);
1222 ASSERT(texImage->Base.TexFormat == MESA_FORMAT_S8_UINT_Z24_UNORM ||
1223 texImage->Base.TexFormat == MESA_FORMAT_X8_UINT_Z24_UNORM);
1224 ASSERT(texel[0] >= 0.0F);
1225 ASSERT(texel[0] <= 1.0F);
1226 }
1227
1228
1229 static void
1230 FETCH(Z24_UNORM_S8_UINT)(const struct swrast_texture_image *texImage,
1231 GLint i, GLint j, GLint k, GLfloat *texel)
1232 {
1233 /* only return Z, not stencil data */
1234 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1235 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
1236 texel[0] = (GLfloat) (((*src) & 0x00ffffff) * scale);
1237 ASSERT(texImage->Base.TexFormat == MESA_FORMAT_Z24_UNORM_S8_UINT ||
1238 texImage->Base.TexFormat == MESA_FORMAT_Z24_UNORM_X8_UINT);
1239 ASSERT(texel[0] >= 0.0F);
1240 ASSERT(texel[0] <= 1.0F);
1241 }
1242
1243
1244 static void
1245 FETCH(R9G9B9E5_FLOAT)(const struct swrast_texture_image *texImage,
1246 GLint i, GLint j, GLint k, GLfloat *texel)
1247 {
1248 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1249 rgb9e5_to_float3(*src, texel);
1250 texel[ACOMP] = 1.0F;
1251 }
1252
1253
1254 static void
1255 FETCH(R11G11B10_FLOAT)(const struct swrast_texture_image *texImage,
1256 GLint i, GLint j, GLint k, GLfloat *texel)
1257 {
1258 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1259 r11g11b10f_to_float3(*src, texel);
1260 texel[ACOMP] = 1.0F;
1261 }
1262
1263
1264 static void
1265 FETCH(Z32_FLOAT_S8X24_UINT)(const struct swrast_texture_image *texImage,
1266 GLint i, GLint j, GLint k, GLfloat *texel)
1267 {
1268 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
1269 texel[RCOMP] = src[0];
1270 texel[GCOMP] = 0.0F;
1271 texel[BCOMP] = 0.0F;
1272 texel[ACOMP] = 1.0F;
1273 }
1274
1275
1276
1277 #undef TEXEL_ADDR
1278 #undef DIM
1279 #undef FETCH