mesa: remove MESA_FORMAT_RGBA4444
[mesa.git] / src / mesa / main / texfetch.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.7
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2009 VMware, Inc.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /**
28 * \file texfetch.c
29 *
30 * Texel fetch/store functions
31 *
32 * \author Gareth Hughes
33 */
34
35
36 #include "colormac.h"
37 #include "context.h"
38 #include "texcompress.h"
39 #include "texcompress_fxt1.h"
40 #include "texcompress_s3tc.h"
41 #include "texfetch.h"
42
43
44 #if FEATURE_EXT_texture_sRGB
45
46 /**
47 * Convert an 8-bit sRGB value from non-linear space to a
48 * linear RGB value in [0, 1].
49 * Implemented with a 256-entry lookup table.
50 */
51 static INLINE GLfloat
52 nonlinear_to_linear(GLubyte cs8)
53 {
54 static GLfloat table[256];
55 static GLboolean tableReady = GL_FALSE;
56 if (!tableReady) {
57 /* compute lookup table now */
58 GLuint i;
59 for (i = 0; i < 256; i++) {
60 const GLfloat cs = UBYTE_TO_FLOAT(i);
61 if (cs <= 0.04045) {
62 table[i] = cs / 12.92f;
63 }
64 else {
65 table[i] = (GLfloat) _mesa_pow((cs + 0.055) / 1.055, 2.4);
66 }
67 }
68 tableReady = GL_TRUE;
69 }
70 return table[cs8];
71 }
72
73
74 #endif /* FEATURE_EXT_texture_sRGB */
75
76
77 /* Texel fetch routines for all supported formats
78 */
79 #define DIM 1
80 #include "texformat_tmp.h"
81
82 #define DIM 2
83 #include "texformat_tmp.h"
84
85 #define DIM 3
86 #include "texformat_tmp.h"
87
88 /**
89 * Null texel fetch function.
90 *
91 * Have to have this so the FetchTexel function pointer is never NULL.
92 */
93 static void fetch_null_texelf( const struct gl_texture_image *texImage,
94 GLint i, GLint j, GLint k, GLfloat *texel )
95 {
96 (void) texImage; (void) i; (void) j; (void) k;
97 texel[RCOMP] = 0.0;
98 texel[GCOMP] = 0.0;
99 texel[BCOMP] = 0.0;
100 texel[ACOMP] = 0.0;
101 _mesa_warning(NULL, "fetch_null_texelf() called!");
102 }
103
104 static void store_null_texel(struct gl_texture_image *texImage,
105 GLint i, GLint j, GLint k, const void *texel)
106 {
107 (void) texImage;
108 (void) i;
109 (void) j;
110 (void) k;
111 (void) texel;
112 /* no-op */
113 }
114
115
116
117 /**
118 * Table to map MESA_FORMAT_ to texel fetch/store funcs.
119 * XXX this is somewhat temporary.
120 */
121 static struct {
122 GLuint Name;
123 FetchTexelFuncF Fetch1D;
124 FetchTexelFuncF Fetch2D;
125 FetchTexelFuncF Fetch3D;
126 StoreTexelFunc StoreTexel;
127 }
128 texfetch_funcs[MESA_FORMAT_COUNT] =
129 {
130 {
131 MESA_FORMAT_SRGB8,
132 fetch_texel_1d_srgb8,
133 fetch_texel_2d_srgb8,
134 fetch_texel_3d_srgb8,
135 store_texel_srgb8
136 },
137 {
138 MESA_FORMAT_SRGBA8,
139 fetch_texel_1d_srgba8,
140 fetch_texel_2d_srgba8,
141 fetch_texel_3d_srgba8,
142 store_texel_srgba8
143 },
144 {
145 MESA_FORMAT_SARGB8,
146 fetch_texel_1d_sargb8,
147 fetch_texel_2d_sargb8,
148 fetch_texel_3d_sargb8,
149 store_texel_sargb8
150 },
151 {
152 MESA_FORMAT_SL8,
153 fetch_texel_1d_sl8,
154 fetch_texel_2d_sl8,
155 fetch_texel_3d_sl8,
156 store_texel_sl8
157 },
158 {
159 MESA_FORMAT_SLA8,
160 fetch_texel_1d_sla8,
161 fetch_texel_2d_sla8,
162 fetch_texel_3d_sla8,
163 store_texel_sla8
164 },
165 {
166 MESA_FORMAT_RGB_FXT1,
167 NULL,
168 _mesa_fetch_texel_2d_f_rgb_fxt1,
169 NULL,
170 NULL
171 },
172 {
173 MESA_FORMAT_RGBA_FXT1,
174 NULL,
175 _mesa_fetch_texel_2d_f_rgba_fxt1,
176 NULL,
177 NULL
178 },
179 {
180 MESA_FORMAT_RGB_DXT1,
181 NULL,
182 _mesa_fetch_texel_2d_f_rgb_dxt1,
183 NULL,
184 NULL
185 },
186 {
187 MESA_FORMAT_RGBA_DXT1,
188 NULL,
189 _mesa_fetch_texel_2d_f_rgba_dxt1,
190 NULL,
191 NULL
192 },
193 {
194 MESA_FORMAT_RGBA_DXT3,
195 NULL,
196 _mesa_fetch_texel_2d_f_rgba_dxt3,
197 NULL,
198 NULL
199 },
200 {
201 MESA_FORMAT_RGBA_DXT5,
202 NULL,
203 _mesa_fetch_texel_2d_f_rgba_dxt5,
204 NULL,
205 NULL
206 },
207 {
208 MESA_FORMAT_SRGB_DXT1,
209 NULL,
210 _mesa_fetch_texel_2d_f_srgb_dxt1,
211 NULL,
212 NULL
213 },
214 {
215 MESA_FORMAT_SRGBA_DXT1,
216 NULL,
217 _mesa_fetch_texel_2d_f_srgba_dxt1,
218 NULL,
219 NULL
220 },
221 {
222 MESA_FORMAT_SRGBA_DXT3,
223 NULL,
224 _mesa_fetch_texel_2d_f_srgba_dxt3,
225 NULL,
226 NULL
227 },
228 {
229 MESA_FORMAT_SRGBA_DXT5,
230 NULL,
231 _mesa_fetch_texel_2d_f_srgba_dxt5,
232 NULL,
233 NULL
234 },
235 {
236 MESA_FORMAT_RGBA_FLOAT32,
237 fetch_texel_1d_f_rgba_f32,
238 fetch_texel_2d_f_rgba_f32,
239 fetch_texel_3d_f_rgba_f32,
240 store_texel_rgba_f32
241 },
242 {
243 MESA_FORMAT_RGBA_FLOAT16,
244 fetch_texel_1d_f_rgba_f16,
245 fetch_texel_2d_f_rgba_f16,
246 fetch_texel_3d_f_rgba_f16,
247 store_texel_rgba_f16
248 },
249 {
250 MESA_FORMAT_RGB_FLOAT32,
251 fetch_texel_1d_f_rgb_f32,
252 fetch_texel_2d_f_rgb_f32,
253 fetch_texel_3d_f_rgb_f32,
254 store_texel_rgb_f32
255 },
256 {
257 MESA_FORMAT_RGB_FLOAT16,
258 fetch_texel_1d_f_rgb_f16,
259 fetch_texel_2d_f_rgb_f16,
260 fetch_texel_3d_f_rgb_f16,
261 store_texel_rgb_f16
262 },
263 {
264 MESA_FORMAT_ALPHA_FLOAT32,
265 fetch_texel_1d_f_alpha_f32,
266 fetch_texel_2d_f_alpha_f32,
267 fetch_texel_3d_f_alpha_f32,
268 store_texel_alpha_f32
269 },
270 {
271 MESA_FORMAT_ALPHA_FLOAT16,
272 fetch_texel_1d_f_alpha_f16,
273 fetch_texel_2d_f_alpha_f16,
274 fetch_texel_3d_f_alpha_f16,
275 store_texel_alpha_f16
276 },
277 {
278 MESA_FORMAT_LUMINANCE_FLOAT32,
279 fetch_texel_1d_f_luminance_f32,
280 fetch_texel_2d_f_luminance_f32,
281 fetch_texel_3d_f_luminance_f32,
282 store_texel_luminance_f32
283 },
284 {
285 MESA_FORMAT_LUMINANCE_FLOAT16,
286 fetch_texel_1d_f_luminance_f16,
287 fetch_texel_2d_f_luminance_f16,
288 fetch_texel_3d_f_luminance_f16,
289 store_texel_luminance_f16
290 },
291 {
292 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
293 fetch_texel_1d_f_luminance_alpha_f32,
294 fetch_texel_2d_f_luminance_alpha_f32,
295 fetch_texel_3d_f_luminance_alpha_f32,
296 store_texel_luminance_alpha_f32
297 },
298 {
299 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
300 fetch_texel_1d_f_luminance_alpha_f16,
301 fetch_texel_2d_f_luminance_alpha_f16,
302 fetch_texel_3d_f_luminance_alpha_f16,
303 store_texel_luminance_alpha_f16
304 },
305 {
306 MESA_FORMAT_INTENSITY_FLOAT32,
307 fetch_texel_1d_f_intensity_f32,
308 fetch_texel_2d_f_intensity_f32,
309 fetch_texel_3d_f_intensity_f32,
310 store_texel_intensity_f32
311 },
312 {
313 MESA_FORMAT_INTENSITY_FLOAT16,
314 fetch_texel_1d_f_intensity_f16,
315 fetch_texel_2d_f_intensity_f16,
316 fetch_texel_3d_f_intensity_f16,
317 store_texel_intensity_f16
318 },
319 {
320 MESA_FORMAT_DUDV8,
321 fetch_texel_1d_dudv8,
322 fetch_texel_2d_dudv8,
323 fetch_texel_3d_dudv8,
324 NULL
325 },
326 {
327 MESA_FORMAT_SIGNED_RGBA8888,
328 fetch_texel_1d_signed_rgba8888,
329 fetch_texel_2d_signed_rgba8888,
330 fetch_texel_3d_signed_rgba8888,
331 store_texel_signed_rgba8888
332 },
333 {
334 MESA_FORMAT_SIGNED_RGBA8888_REV,
335 fetch_texel_1d_signed_rgba8888_rev,
336 fetch_texel_2d_signed_rgba8888_rev,
337 fetch_texel_3d_signed_rgba8888_rev,
338 store_texel_signed_rgba8888_rev
339 },
340 {
341 MESA_FORMAT_RGBA8888,
342 fetch_texel_1d_f_rgba8888,
343 fetch_texel_2d_f_rgba8888,
344 fetch_texel_3d_f_rgba8888,
345 store_texel_rgba8888
346 },
347 {
348 MESA_FORMAT_RGBA8888_REV,
349 fetch_texel_1d_f_rgba8888_rev,
350 fetch_texel_2d_f_rgba8888_rev,
351 fetch_texel_3d_f_rgba8888_rev,
352 store_texel_rgba8888_rev
353 },
354 {
355 MESA_FORMAT_ARGB8888,
356 fetch_texel_1d_f_argb8888,
357 fetch_texel_2d_f_argb8888,
358 fetch_texel_3d_f_argb8888,
359 store_texel_argb8888
360 },
361 {
362 MESA_FORMAT_ARGB8888_REV,
363 fetch_texel_1d_f_argb8888_rev,
364 fetch_texel_2d_f_argb8888_rev,
365 fetch_texel_3d_f_argb8888_rev,
366 store_texel_argb8888_rev
367 },
368 {
369 MESA_FORMAT_RGB888,
370 fetch_texel_1d_f_rgb888,
371 fetch_texel_2d_f_rgb888,
372 fetch_texel_3d_f_rgb888,
373 store_texel_rgb888
374 },
375 {
376 MESA_FORMAT_BGR888,
377 fetch_texel_1d_f_bgr888,
378 fetch_texel_2d_f_bgr888,
379 fetch_texel_3d_f_bgr888,
380 store_texel_bgr888
381 },
382 {
383 MESA_FORMAT_RGB565,
384 fetch_texel_1d_f_rgb565,
385 fetch_texel_2d_f_rgb565,
386 fetch_texel_3d_f_rgb565,
387 store_texel_rgb565
388 },
389 {
390 MESA_FORMAT_RGB565_REV,
391 fetch_texel_1d_f_rgb565_rev,
392 fetch_texel_2d_f_rgb565_rev,
393 fetch_texel_3d_f_rgb565_rev,
394 store_texel_rgb565_rev
395 },
396 {
397 MESA_FORMAT_ARGB4444,
398 fetch_texel_1d_f_argb4444,
399 fetch_texel_2d_f_argb4444,
400 fetch_texel_3d_f_argb4444,
401 store_texel_argb4444
402 },
403 {
404 MESA_FORMAT_ARGB4444_REV,
405 fetch_texel_1d_f_argb4444_rev,
406 fetch_texel_2d_f_argb4444_rev,
407 fetch_texel_3d_f_argb4444_rev,
408 store_texel_argb4444_rev
409 },
410 {
411 MESA_FORMAT_RGBA5551,
412 fetch_texel_1d_f_rgba5551,
413 fetch_texel_2d_f_rgba5551,
414 fetch_texel_3d_f_rgba5551,
415 store_texel_rgba5551
416 },
417 {
418 MESA_FORMAT_ARGB1555,
419 fetch_texel_1d_f_argb1555,
420 fetch_texel_2d_f_argb1555,
421 fetch_texel_3d_f_argb1555,
422 store_texel_argb1555
423 },
424 {
425 MESA_FORMAT_ARGB1555_REV,
426 fetch_texel_1d_f_argb1555_rev,
427 fetch_texel_2d_f_argb1555_rev,
428 fetch_texel_3d_f_argb1555_rev,
429 store_texel_argb1555_rev
430 },
431 {
432 MESA_FORMAT_AL88,
433 fetch_texel_1d_f_al88,
434 fetch_texel_2d_f_al88,
435 fetch_texel_3d_f_al88,
436 store_texel_al88
437 },
438 {
439 MESA_FORMAT_AL88_REV,
440 fetch_texel_1d_f_al88_rev,
441 fetch_texel_2d_f_al88_rev,
442 fetch_texel_3d_f_al88_rev,
443 store_texel_al88_rev
444 },
445 {
446 MESA_FORMAT_RGB332,
447 fetch_texel_1d_f_rgb332,
448 fetch_texel_2d_f_rgb332,
449 fetch_texel_3d_f_rgb332,
450 store_texel_rgb332
451 },
452 {
453 MESA_FORMAT_A8,
454 fetch_texel_1d_f_a8,
455 fetch_texel_2d_f_a8,
456 fetch_texel_3d_f_a8,
457 store_texel_a8
458 },
459 {
460 MESA_FORMAT_L8,
461 fetch_texel_1d_f_l8,
462 fetch_texel_2d_f_l8,
463 fetch_texel_3d_f_l8,
464 store_texel_l8
465 },
466 {
467 MESA_FORMAT_I8,
468 fetch_texel_1d_f_i8,
469 fetch_texel_2d_f_i8,
470 fetch_texel_3d_f_i8,
471 store_texel_i8
472 },
473 {
474 MESA_FORMAT_CI8,
475 fetch_texel_1d_f_ci8,
476 fetch_texel_2d_f_ci8,
477 fetch_texel_3d_f_ci8,
478 store_texel_ci8
479 },
480 {
481 MESA_FORMAT_YCBCR,
482 fetch_texel_1d_f_ycbcr,
483 fetch_texel_2d_f_ycbcr,
484 fetch_texel_3d_f_ycbcr,
485 store_texel_ycbcr
486 },
487 {
488 MESA_FORMAT_YCBCR_REV,
489 fetch_texel_1d_f_ycbcr_rev,
490 fetch_texel_2d_f_ycbcr_rev,
491 fetch_texel_3d_f_ycbcr_rev,
492 store_texel_ycbcr_rev
493 },
494 {
495 MESA_FORMAT_Z24_S8,
496 fetch_texel_1d_f_z24_s8,
497 fetch_texel_2d_f_z24_s8,
498 fetch_texel_3d_f_z24_s8,
499 store_texel_z24_s8
500 },
501 {
502 MESA_FORMAT_S8_Z24,
503 fetch_texel_1d_f_s8_z24,
504 fetch_texel_2d_f_s8_z24,
505 fetch_texel_3d_f_s8_z24,
506 store_texel_s8_z24
507 },
508 {
509 MESA_FORMAT_Z16,
510 fetch_texel_1d_f_z16,
511 fetch_texel_2d_f_z16,
512 fetch_texel_3d_f_z16,
513 store_texel_z16
514 },
515 {
516 MESA_FORMAT_Z32,
517 fetch_texel_1d_f_z32,
518 fetch_texel_2d_f_z32,
519 fetch_texel_3d_f_z32,
520 store_texel_z32
521 }
522 };
523
524
525 FetchTexelFuncF
526 _mesa_get_texel_fetch_func(gl_format format, GLuint dims)
527 {
528 FetchTexelFuncF f;
529 GLuint i;
530 /* XXX replace loop with direct table lookup */
531 for (i = 0; i < MESA_FORMAT_COUNT; i++) {
532 if (texfetch_funcs[i].Name == format) {
533 switch (dims) {
534 case 1:
535 f = texfetch_funcs[i].Fetch1D;
536 break;
537 case 2:
538 f = texfetch_funcs[i].Fetch2D;
539 break;
540 case 3:
541 f = texfetch_funcs[i].Fetch3D;
542 break;
543 }
544 if (!f)
545 f = fetch_null_texelf;
546 return f;
547 }
548 }
549 return NULL;
550 }
551
552
553 StoreTexelFunc
554 _mesa_get_texel_store_func(gl_format format)
555 {
556 GLuint i;
557 /* XXX replace loop with direct table lookup */
558 for (i = 0; i < MESA_FORMAT_COUNT; i++) {
559 if (texfetch_funcs[i].Name == format) {
560 if (texfetch_funcs[i].StoreTexel)
561 return texfetch_funcs[i].StoreTexel;
562 else
563 return store_null_texel;
564 }
565 }
566 return NULL;
567 }