mesa/formats: add new mesa formats and their pack/unpack functions.
[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;
421 texel[RCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
422 texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);
423 texel[BCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
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] = ((s >> 1) & 0x1f) * (1.0F / 31.0F);
486 texel[GCOMP] = ((s >> 6) & 0x1f) * (1.0F / 31.0F);
487 texel[BCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);
488 texel[ACOMP] = ((s ) & 0x01) * 1.0F;
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] = util_format_srgb_8unorm_to_linear_float(src[2]);
741 texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(src[1]);
742 texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(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] = util_format_srgb_8unorm_to_linear_float( (s >> 24) );
753 texel[GCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 16) & 0xff );
754 texel[BCOMP] = util_format_srgb_8unorm_to_linear_float( (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] = util_format_srgb_8unorm_to_linear_float( (s >> 16) & 0xff );
765 texel[GCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 8) & 0xff );
766 texel[BCOMP] = util_format_srgb_8unorm_to_linear_float( (s ) & 0xff );
767 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
768 }
769
770
771 static void
772 FETCH(A8R8G8B8_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] = util_format_srgb_8unorm_to_linear_float( (s >> 8) & 0xff );
777 texel[GCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 16) & 0xff );
778 texel[BCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 24) );
779 texel[ACOMP] = UBYTE_TO_FLOAT( s & 0xff ); /* linear! */
780 }
781
782
783 static void
784 FETCH(R8G8B8A8_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] = util_format_srgb_8unorm_to_linear_float( (s ) & 0xff );
789 texel[GCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 8) & 0xff );
790 texel[BCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 16) & 0xff );
791 texel[ACOMP] = UBYTE_TO_FLOAT( (s >> 24) ); /* linear! */
792 }
793
794
795 static void
796 FETCH(R8G8B8X8_SRGB)(const struct swrast_texture_image *texImage,
797 GLint i, GLint j, GLint k, GLfloat *texel)
798 {
799 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
800 texel[RCOMP] = util_format_srgb_8unorm_to_linear_float( (s ) & 0xff );
801 texel[GCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 8) & 0xff );
802 texel[BCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 16) & 0xff );
803 texel[ACOMP] = 1.0f;
804 }
805
806
807 static void
808 FETCH(X8B8G8R8_SRGB)(const struct swrast_texture_image *texImage,
809 GLint i, GLint j, GLint k, GLfloat *texel)
810 {
811 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
812 texel[RCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 24) );
813 texel[GCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 16) & 0xff );
814 texel[BCOMP] = util_format_srgb_8unorm_to_linear_float( (s >> 8) & 0xff );
815 texel[ACOMP] = 1.0f;
816 }
817
818
819 static void
820 FETCH(L_SRGB8)(const struct swrast_texture_image *texImage,
821 GLint i, GLint j, GLint k, GLfloat *texel)
822 {
823 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
824 texel[RCOMP] =
825 texel[GCOMP] =
826 texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(src[0]);
827 texel[ACOMP] = 1.0F;
828 }
829
830
831 static void
832 FETCH(L8A8_SRGB)(const struct swrast_texture_image *texImage,
833 GLint i, GLint j, GLint k, GLfloat *texel)
834 {
835 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 1);
836 texel[RCOMP] =
837 texel[GCOMP] =
838 texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(s & 0xff);
839 texel[ACOMP] = UBYTE_TO_FLOAT(s >> 8); /* linear */
840 }
841
842
843 static void
844 FETCH(A8L8_SRGB)(const struct swrast_texture_image *texImage,
845 GLint i, GLint j, GLint k, GLfloat *texel)
846 {
847 const GLushort s = *TEXEL_ADDR(GLushort, texImage, i, j, k, 2);
848 texel[RCOMP] =
849 texel[GCOMP] =
850 texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(s >> 8);
851 texel[ACOMP] = UBYTE_TO_FLOAT(s & 0xff); /* linear */
852 }
853
854
855 static void
856 FETCH(RGBA_SINT8)(const struct swrast_texture_image *texImage,
857 GLint i, GLint j, GLint k, GLfloat *texel)
858 {
859 const GLbyte *src = TEXEL_ADDR(GLbyte, 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_SINT16)(const struct swrast_texture_image *texImage,
869 GLint i, GLint j, GLint k, GLfloat *texel)
870 {
871 const GLshort *src = TEXEL_ADDR(GLshort, 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_SINT32)(const struct swrast_texture_image *texImage,
881 GLint i, GLint j, GLint k, GLfloat *texel)
882 {
883 const GLint *src = TEXEL_ADDR(GLint, 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(RGBA_UINT8)(const struct swrast_texture_image *texImage,
893 GLint i, GLint j, GLint k, GLfloat *texel)
894 {
895 const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
896 texel[RCOMP] = (GLfloat) src[0];
897 texel[GCOMP] = (GLfloat) src[1];
898 texel[BCOMP] = (GLfloat) src[2];
899 texel[ACOMP] = (GLfloat) src[3];
900 }
901
902
903 static void
904 FETCH(RGBA_UINT16)(const struct swrast_texture_image *texImage,
905 GLint i, GLint j, GLint k, GLfloat *texel)
906 {
907 const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
908 texel[RCOMP] = (GLfloat) src[0];
909 texel[GCOMP] = (GLfloat) src[1];
910 texel[BCOMP] = (GLfloat) src[2];
911 texel[ACOMP] = (GLfloat) src[3];
912 }
913
914
915 static void
916 FETCH(RGBA_UINT32)(const struct swrast_texture_image *texImage,
917 GLint i, GLint j, GLint k, GLfloat *texel)
918 {
919 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 4);
920 texel[RCOMP] = (GLfloat) src[0];
921 texel[GCOMP] = (GLfloat) src[1];
922 texel[BCOMP] = (GLfloat) src[2];
923 texel[ACOMP] = (GLfloat) src[3];
924 }
925
926
927 static void
928 FETCH(R_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] = BYTE_TO_FLOAT_TEX( s );
933 texel[GCOMP] = 0.0F;
934 texel[BCOMP] = 0.0F;
935 texel[ACOMP] = 1.0F;
936 }
937
938
939 static void
940 FETCH(A_SNORM8)(const struct swrast_texture_image *texImage,
941 GLint i, GLint j, GLint k, GLfloat *texel)
942 {
943 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
944 texel[RCOMP] = 0.0F;
945 texel[GCOMP] = 0.0F;
946 texel[BCOMP] = 0.0F;
947 texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
948 }
949
950
951 static void
952 FETCH(L_SNORM8)(const struct swrast_texture_image *texImage,
953 GLint i, GLint j, GLint k, GLfloat *texel)
954 {
955 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
956 texel[RCOMP] =
957 texel[GCOMP] =
958 texel[BCOMP] = BYTE_TO_FLOAT_TEX( s );
959 texel[ACOMP] = 1.0F;
960 }
961
962
963 static void
964 FETCH(I_SNORM8)(const struct swrast_texture_image *texImage,
965 GLint i, GLint j, GLint k, GLfloat *texel)
966 {
967 const GLbyte s = *TEXEL_ADDR(GLbyte, texImage, i, j, k, 1);
968 texel[RCOMP] =
969 texel[GCOMP] =
970 texel[BCOMP] =
971 texel[ACOMP] = BYTE_TO_FLOAT_TEX( s );
972 }
973
974
975 static void
976 FETCH(R8G8_SNORM)(const struct swrast_texture_image *texImage,
977 GLint i, GLint j, GLint k, GLfloat *texel)
978 {
979 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
980 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
981 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
982 texel[BCOMP] = 0.0F;
983 texel[ACOMP] = 1.0F;
984 }
985
986
987 static void
988 FETCH(L8A8_SNORM)(const struct swrast_texture_image *texImage,
989 GLint i, GLint j, GLint k, GLfloat *texel)
990 {
991 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
992 texel[RCOMP] =
993 texel[GCOMP] =
994 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
995 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
996 }
997
998
999 static void
1000 FETCH(A8L8_SNORM)(const struct swrast_texture_image *texImage,
1001 GLint i, GLint j, GLint k, GLfloat *texel)
1002 {
1003 const GLushort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1004 texel[RCOMP] =
1005 texel[GCOMP] =
1006 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1007 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s & 0xff) );
1008 }
1009
1010
1011 static void
1012 FETCH(X8B8G8R8_SNORM)(const struct swrast_texture_image *texImage,
1013 GLint i, GLint j, GLint k, GLfloat *texel)
1014 {
1015 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1016 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1017 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1018 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1019 texel[ACOMP] = 1.0f;
1020 }
1021
1022
1023 static void
1024 FETCH(A8B8G8R8_SNORM)(const struct swrast_texture_image *texImage,
1025 GLint i, GLint j, GLint k, GLfloat *texel)
1026 {
1027 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1028 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1029 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1030 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1031 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1032 }
1033
1034
1035 static void
1036 FETCH(R8G8B8A8_SNORM)(const struct swrast_texture_image *texImage,
1037 GLint i, GLint j, GLint k, GLfloat *texel)
1038 {
1039 const GLuint s = *TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1040 texel[RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s ) );
1041 texel[GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 8) );
1042 texel[BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 16) );
1043 texel[ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s >> 24) );
1044 }
1045
1046
1047 static void
1048 FETCH(R_SNORM16)(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, 1);
1052 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s );
1053 texel[GCOMP] = 0.0F;
1054 texel[BCOMP] = 0.0F;
1055 texel[ACOMP] = 1.0F;
1056 }
1057
1058
1059 static void
1060 FETCH(A_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, 1);
1064 texel[RCOMP] = 0.0F;
1065 texel[GCOMP] = 0.0F;
1066 texel[BCOMP] = 0.0F;
1067 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
1068 }
1069
1070
1071 static void
1072 FETCH(L_SNORM16)(const struct swrast_texture_image *texImage,
1073 GLint i, GLint j, GLint k, GLfloat *texel)
1074 {
1075 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1076 texel[RCOMP] =
1077 texel[GCOMP] =
1078 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s );
1079 texel[ACOMP] = 1.0F;
1080 }
1081
1082
1083 static void
1084 FETCH(I_SNORM16)(const struct swrast_texture_image *texImage,
1085 GLint i, GLint j, GLint k, GLfloat *texel)
1086 {
1087 const GLshort s = *TEXEL_ADDR(GLshort, texImage, i, j, k, 1);
1088 texel[RCOMP] =
1089 texel[GCOMP] =
1090 texel[BCOMP] =
1091 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s );
1092 }
1093
1094
1095 static void
1096 FETCH(R16G16_SNORM)(const struct swrast_texture_image *texImage,
1097 GLint i, GLint j, GLint k, GLfloat *texel)
1098 {
1099 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
1100 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1101 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1102 texel[BCOMP] = 0.0F;
1103 texel[ACOMP] = 1.0F;
1104 }
1105
1106
1107 static void
1108 FETCH(LA_SNORM16)(const struct swrast_texture_image *texImage,
1109 GLint i, GLint j, GLint k, GLfloat *texel)
1110 {
1111 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 2);
1112 texel[RCOMP] =
1113 texel[GCOMP] =
1114 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1115 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1116 }
1117
1118
1119 static void
1120
1121 FETCH(RGB_SNORM16)(const struct swrast_texture_image *texImage,
1122 GLint i, GLint j, GLint k, GLfloat *texel)
1123 {
1124 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 3);
1125 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1126 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1127 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
1128 texel[ACOMP] = 1.0F;
1129 }
1130
1131
1132 static void
1133 FETCH(RGBA_SNORM16)(const struct swrast_texture_image *texImage,
1134 GLint i, GLint j, GLint k, GLfloat *texel)
1135 {
1136 const GLshort *s = TEXEL_ADDR(GLshort, texImage, i, j, k, 4);
1137 texel[RCOMP] = SHORT_TO_FLOAT_TEX( s[0] );
1138 texel[GCOMP] = SHORT_TO_FLOAT_TEX( s[1] );
1139 texel[BCOMP] = SHORT_TO_FLOAT_TEX( s[2] );
1140 texel[ACOMP] = SHORT_TO_FLOAT_TEX( s[3] );
1141 }
1142
1143
1144 static void
1145 FETCH(RGBA_UNORM16)(const struct swrast_texture_image *texImage,
1146 GLint i, GLint j, GLint k, GLfloat *texel)
1147 {
1148 const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1149 texel[RCOMP] = USHORT_TO_FLOAT( s[0] );
1150 texel[GCOMP] = USHORT_TO_FLOAT( s[1] );
1151 texel[BCOMP] = USHORT_TO_FLOAT( s[2] );
1152 texel[ACOMP] = USHORT_TO_FLOAT( s[3] );
1153 }
1154
1155
1156 static void
1157 FETCH(RGBX_UNORM16)(const struct swrast_texture_image *texImage,
1158 GLint i, GLint j, GLint k, GLfloat *texel)
1159 {
1160 const GLushort *s = TEXEL_ADDR(GLushort, texImage, i, j, k, 4);
1161 texel[RCOMP] = USHORT_TO_FLOAT(s[0]);
1162 texel[GCOMP] = USHORT_TO_FLOAT(s[1]);
1163 texel[BCOMP] = USHORT_TO_FLOAT(s[2]);
1164 texel[ACOMP] = 1.0f;
1165 }
1166
1167
1168 static void
1169 FETCH(RGBX_FLOAT16)(const struct swrast_texture_image *texImage,
1170 GLint i, GLint j, GLint k, GLfloat *texel)
1171 {
1172 const GLhalfARB *s = TEXEL_ADDR(GLhalfARB, texImage, i, j, k, 4);
1173 texel[RCOMP] = _mesa_half_to_float(s[0]);
1174 texel[GCOMP] = _mesa_half_to_float(s[1]);
1175 texel[BCOMP] = _mesa_half_to_float(s[2]);
1176 texel[ACOMP] = 1.0f;
1177 }
1178
1179
1180 static void
1181 FETCH(RGBX_FLOAT32)(const struct swrast_texture_image *texImage,
1182 GLint i, GLint j, GLint k, GLfloat *texel)
1183 {
1184 const GLfloat *s = TEXEL_ADDR(GLfloat, texImage, i, j, k, 4);
1185 texel[RCOMP] = s[0];
1186 texel[GCOMP] = s[1];
1187 texel[BCOMP] = s[2];
1188 texel[ACOMP] = 1.0f;
1189 }
1190
1191
1192 /**
1193 * Fetch texel from 1D, 2D or 3D ycbcr texture, returning RGBA.
1194 */
1195 static void
1196 FETCH(YCBCR)(const struct swrast_texture_image *texImage,
1197 GLint i, GLint j, GLint k, GLfloat *texel)
1198 {
1199 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1200 const GLushort *src1 = src0 + 1; /* odd */
1201 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
1202 const GLubyte cb = *src0 & 0xff; /* chroma U */
1203 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
1204 const GLubyte cr = *src1 & 0xff; /* chroma V */
1205 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1206 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1207 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1208 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1209 r *= (1.0F / 255.0F);
1210 g *= (1.0F / 255.0F);
1211 b *= (1.0F / 255.0F);
1212 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1213 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1214 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1215 texel[ACOMP] = 1.0F;
1216 }
1217
1218
1219 /**
1220 * Fetch texel from 1D, 2D or 3D ycbcr texture, returning RGBA.
1221 */
1222 static void
1223 FETCH(YCBCR_REV)(const struct swrast_texture_image *texImage,
1224 GLint i, GLint j, GLint k, GLfloat *texel)
1225 {
1226 const GLushort *src0 = TEXEL_ADDR(GLushort, texImage, (i & ~1), j, k, 1); /* even */
1227 const GLushort *src1 = src0 + 1; /* odd */
1228 const GLubyte y0 = *src0 & 0xff; /* luminance */
1229 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
1230 const GLubyte y1 = *src1 & 0xff; /* luminance */
1231 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
1232 const GLubyte y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
1233 GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
1234 GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
1235 GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
1236 r *= (1.0F / 255.0F);
1237 g *= (1.0F / 255.0F);
1238 b *= (1.0F / 255.0F);
1239 texel[RCOMP] = CLAMP(r, 0.0F, 1.0F);
1240 texel[GCOMP] = CLAMP(g, 0.0F, 1.0F);
1241 texel[BCOMP] = CLAMP(b, 0.0F, 1.0F);
1242 texel[ACOMP] = 1.0F;
1243 }
1244
1245
1246 static void
1247 FETCH(S8_UINT_Z24_UNORM)(const struct swrast_texture_image *texImage,
1248 GLint i, GLint j, GLint k, GLfloat *texel)
1249 {
1250 /* only return Z, not stencil data */
1251 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1252 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
1253 texel[0] = (GLfloat) (((*src) >> 8) * scale);
1254 ASSERT(texImage->Base.TexFormat == MESA_FORMAT_S8_UINT_Z24_UNORM ||
1255 texImage->Base.TexFormat == MESA_FORMAT_X8_UINT_Z24_UNORM);
1256 ASSERT(texel[0] >= 0.0F);
1257 ASSERT(texel[0] <= 1.0F);
1258 }
1259
1260
1261 static void
1262 FETCH(Z24_UNORM_S8_UINT)(const struct swrast_texture_image *texImage,
1263 GLint i, GLint j, GLint k, GLfloat *texel)
1264 {
1265 /* only return Z, not stencil data */
1266 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1267 const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
1268 texel[0] = (GLfloat) (((*src) & 0x00ffffff) * scale);
1269 ASSERT(texImage->Base.TexFormat == MESA_FORMAT_Z24_UNORM_S8_UINT ||
1270 texImage->Base.TexFormat == MESA_FORMAT_Z24_UNORM_X8_UINT);
1271 ASSERT(texel[0] >= 0.0F);
1272 ASSERT(texel[0] <= 1.0F);
1273 }
1274
1275
1276 static void
1277 FETCH(R9G9B9E5_FLOAT)(const struct swrast_texture_image *texImage,
1278 GLint i, GLint j, GLint k, GLfloat *texel)
1279 {
1280 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1281 rgb9e5_to_float3(*src, texel);
1282 texel[ACOMP] = 1.0F;
1283 }
1284
1285
1286 static void
1287 FETCH(R11G11B10_FLOAT)(const struct swrast_texture_image *texImage,
1288 GLint i, GLint j, GLint k, GLfloat *texel)
1289 {
1290 const GLuint *src = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
1291 r11g11b10f_to_float3(*src, texel);
1292 texel[ACOMP] = 1.0F;
1293 }
1294
1295
1296 static void
1297 FETCH(Z32_FLOAT_S8X24_UINT)(const struct swrast_texture_image *texImage,
1298 GLint i, GLint j, GLint k, GLfloat *texel)
1299 {
1300 const GLfloat *src = TEXEL_ADDR(GLfloat, texImage, i, j, k, 2);
1301 texel[RCOMP] = src[0];
1302 texel[GCOMP] = 0.0F;
1303 texel[BCOMP] = 0.0F;
1304 texel[ACOMP] = 1.0F;
1305 }
1306
1307
1308
1309 #undef TEXEL_ADDR
1310 #undef DIM
1311 #undef FETCH