Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1901 serge 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 "macros.h"
38
#include "texcompress.h"
39
#include "texcompress_fxt1.h"
40
#include "texcompress_s3tc.h"
41
#include "texfetch.h"
42
 
43
 
44
/**
45
 * Convert an 8-bit sRGB value from non-linear space to a
46
 * linear RGB value in [0, 1].
47
 * Implemented with a 256-entry lookup table.
48
 */
49
static INLINE GLfloat
50
nonlinear_to_linear(GLubyte cs8)
51
{
52
   static GLfloat table[256];
53
   static GLboolean tableReady = GL_FALSE;
54
   if (!tableReady) {
55
      /* compute lookup table now */
56
      GLuint i;
57
      for (i = 0; i < 256; i++) {
58
         const GLfloat cs = UBYTE_TO_FLOAT(i);
59
         if (cs <= 0.04045) {
60
            table[i] = cs / 12.92f;
61
         }
62
         else {
63
            table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
64
         }
65
      }
66
      tableReady = GL_TRUE;
67
   }
68
   return table[cs8];
69
}
70
 
71
 
72
 
73
/* Texel fetch routines for all supported formats
74
 */
75
#define DIM 1
76
#include "texfetch_tmp.h"
77
 
78
#define DIM 2
79
#include "texfetch_tmp.h"
80
 
81
#define DIM 3
82
#include "texfetch_tmp.h"
83
 
84
/**
85
 * Null texel fetch function.
86
 *
87
 * Have to have this so the FetchTexel function pointer is never NULL.
88
 */
89
static void fetch_null_texelf( const struct gl_texture_image *texImage,
90
                               GLint i, GLint j, GLint k, GLfloat *texel )
91
{
92
   (void) texImage; (void) i; (void) j; (void) k;
93
   texel[RCOMP] = 0.0;
94
   texel[GCOMP] = 0.0;
95
   texel[BCOMP] = 0.0;
96
   texel[ACOMP] = 0.0;
97
   _mesa_warning(NULL, "fetch_null_texelf() called!");
98
}
99
 
100
static void store_null_texel(struct gl_texture_image *texImage,
101
                             GLint i, GLint j, GLint k, const void *texel)
102
{
103
   (void) texImage;
104
   (void) i;
105
   (void) j;
106
   (void) k;
107
   (void) texel;
108
   /* no-op */
109
}
110
 
111
 
112
 
113
/**
114
 * Table to map MESA_FORMAT_ to texel fetch/store funcs.
115
 * XXX this is somewhat temporary.
116
 */
117
static struct {
118
   gl_format Name;
119
   FetchTexelFuncF Fetch1D;
120
   FetchTexelFuncF Fetch2D;
121
   FetchTexelFuncF Fetch3D;
122
   StoreTexelFunc StoreTexel;
123
}
124
texfetch_funcs[MESA_FORMAT_COUNT] =
125
{
126
   {
127
      MESA_FORMAT_NONE,
128
      fetch_null_texelf,
129
      fetch_null_texelf,
130
      fetch_null_texelf,
131
      store_null_texel
132
   },
133
 
134
   {
135
      MESA_FORMAT_RGBA8888,
136
      fetch_texel_1d_f_rgba8888,
137
      fetch_texel_2d_f_rgba8888,
138
      fetch_texel_3d_f_rgba8888,
139
      store_texel_rgba8888
140
   },
141
   {
142
      MESA_FORMAT_RGBA8888_REV,
143
      fetch_texel_1d_f_rgba8888_rev,
144
      fetch_texel_2d_f_rgba8888_rev,
145
      fetch_texel_3d_f_rgba8888_rev,
146
      store_texel_rgba8888_rev
147
   },
148
   {
149
      MESA_FORMAT_ARGB8888,
150
      fetch_texel_1d_f_argb8888,
151
      fetch_texel_2d_f_argb8888,
152
      fetch_texel_3d_f_argb8888,
153
      store_texel_argb8888
154
   },
155
   {
156
      MESA_FORMAT_ARGB8888_REV,
157
      fetch_texel_1d_f_argb8888_rev,
158
      fetch_texel_2d_f_argb8888_rev,
159
      fetch_texel_3d_f_argb8888_rev,
160
      store_texel_argb8888_rev
161
   },
162
   {
163
      MESA_FORMAT_XRGB8888,
164
      fetch_texel_1d_f_xrgb8888,
165
      fetch_texel_2d_f_xrgb8888,
166
      fetch_texel_3d_f_xrgb8888,
167
      store_texel_xrgb8888
168
   },
169
   {
170
      MESA_FORMAT_XRGB8888_REV,
171
      fetch_texel_1d_f_xrgb8888_rev,
172
      fetch_texel_2d_f_xrgb8888_rev,
173
      fetch_texel_3d_f_xrgb8888_rev,
174
      store_texel_xrgb8888_rev,
175
   },
176
   {
177
      MESA_FORMAT_RGB888,
178
      fetch_texel_1d_f_rgb888,
179
      fetch_texel_2d_f_rgb888,
180
      fetch_texel_3d_f_rgb888,
181
      store_texel_rgb888
182
   },
183
   {
184
      MESA_FORMAT_BGR888,
185
      fetch_texel_1d_f_bgr888,
186
      fetch_texel_2d_f_bgr888,
187
      fetch_texel_3d_f_bgr888,
188
      store_texel_bgr888
189
   },
190
   {
191
      MESA_FORMAT_RGB565,
192
      fetch_texel_1d_f_rgb565,
193
      fetch_texel_2d_f_rgb565,
194
      fetch_texel_3d_f_rgb565,
195
      store_texel_rgb565
196
   },
197
   {
198
      MESA_FORMAT_RGB565_REV,
199
      fetch_texel_1d_f_rgb565_rev,
200
      fetch_texel_2d_f_rgb565_rev,
201
      fetch_texel_3d_f_rgb565_rev,
202
      store_texel_rgb565_rev
203
   },
204
   {
205
      MESA_FORMAT_ARGB4444,
206
      fetch_texel_1d_f_argb4444,
207
      fetch_texel_2d_f_argb4444,
208
      fetch_texel_3d_f_argb4444,
209
      store_texel_argb4444
210
   },
211
   {
212
      MESA_FORMAT_ARGB4444_REV,
213
      fetch_texel_1d_f_argb4444_rev,
214
      fetch_texel_2d_f_argb4444_rev,
215
      fetch_texel_3d_f_argb4444_rev,
216
      store_texel_argb4444_rev
217
   },
218
   {
219
      MESA_FORMAT_RGBA5551,
220
      fetch_texel_1d_f_rgba5551,
221
      fetch_texel_2d_f_rgba5551,
222
      fetch_texel_3d_f_rgba5551,
223
      store_texel_rgba5551
224
   },
225
   {
226
      MESA_FORMAT_ARGB1555,
227
      fetch_texel_1d_f_argb1555,
228
      fetch_texel_2d_f_argb1555,
229
      fetch_texel_3d_f_argb1555,
230
      store_texel_argb1555
231
   },
232
   {
233
      MESA_FORMAT_ARGB1555_REV,
234
      fetch_texel_1d_f_argb1555_rev,
235
      fetch_texel_2d_f_argb1555_rev,
236
      fetch_texel_3d_f_argb1555_rev,
237
      store_texel_argb1555_rev
238
   },
239
   {
240
      MESA_FORMAT_AL88,
241
      fetch_texel_1d_f_al88,
242
      fetch_texel_2d_f_al88,
243
      fetch_texel_3d_f_al88,
244
      store_texel_al88
245
   },
246
   {
247
      MESA_FORMAT_AL88_REV,
248
      fetch_texel_1d_f_al88_rev,
249
      fetch_texel_2d_f_al88_rev,
250
      fetch_texel_3d_f_al88_rev,
251
      store_texel_al88_rev
252
   },
253
   {
254
      MESA_FORMAT_AL1616,
255
      fetch_texel_1d_f_al1616,
256
      fetch_texel_2d_f_al1616,
257
      fetch_texel_3d_f_al1616,
258
      store_texel_al1616
259
   },
260
   {
261
      MESA_FORMAT_AL1616_REV,
262
      fetch_texel_1d_f_al1616_rev,
263
      fetch_texel_2d_f_al1616_rev,
264
      fetch_texel_3d_f_al1616_rev,
265
      store_texel_al1616_rev
266
   },
267
   {
268
      MESA_FORMAT_RGB332,
269
      fetch_texel_1d_f_rgb332,
270
      fetch_texel_2d_f_rgb332,
271
      fetch_texel_3d_f_rgb332,
272
      store_texel_rgb332
273
   },
274
   {
275
      MESA_FORMAT_A8,
276
      fetch_texel_1d_f_a8,
277
      fetch_texel_2d_f_a8,
278
      fetch_texel_3d_f_a8,
279
      store_texel_a8
280
   },
281
   {
282
      MESA_FORMAT_L8,
283
      fetch_texel_1d_f_l8,
284
      fetch_texel_2d_f_l8,
285
      fetch_texel_3d_f_l8,
286
      store_texel_l8
287
   },
288
   {
289
      MESA_FORMAT_I8,
290
      fetch_texel_1d_f_i8,
291
      fetch_texel_2d_f_i8,
292
      fetch_texel_3d_f_i8,
293
      store_texel_i8
294
   },
295
   {
296
      MESA_FORMAT_CI8,
297
      fetch_texel_1d_f_ci8,
298
      fetch_texel_2d_f_ci8,
299
      fetch_texel_3d_f_ci8,
300
      store_texel_ci8
301
   },
302
   {
303
      MESA_FORMAT_YCBCR,
304
      fetch_texel_1d_f_ycbcr,
305
      fetch_texel_2d_f_ycbcr,
306
      fetch_texel_3d_f_ycbcr,
307
      store_texel_ycbcr
308
   },
309
   {
310
      MESA_FORMAT_YCBCR_REV,
311
      fetch_texel_1d_f_ycbcr_rev,
312
      fetch_texel_2d_f_ycbcr_rev,
313
      fetch_texel_3d_f_ycbcr_rev,
314
      store_texel_ycbcr_rev
315
   },
316
   {
317
      MESA_FORMAT_R8,
318
      fetch_texel_1d_f_r8,
319
      fetch_texel_2d_f_r8,
320
      fetch_texel_3d_f_r8,
321
      store_texel_r8,
322
   },
323
   {
324
      MESA_FORMAT_RG88,
325
      fetch_texel_1d_f_rg88,
326
      fetch_texel_2d_f_rg88,
327
      fetch_texel_3d_f_rg88,
328
      store_texel_rg88,
329
   },
330
   {
331
      MESA_FORMAT_RG88_REV,
332
      fetch_texel_1d_f_rg88_rev,
333
      fetch_texel_2d_f_rg88_rev,
334
      fetch_texel_3d_f_rg88_rev,
335
      store_texel_rg88_rev,
336
   },
337
   {
338
      MESA_FORMAT_R16,
339
      fetch_texel_1d_f_r16,
340
      fetch_texel_2d_f_r16,
341
      fetch_texel_3d_f_r16,
342
      store_texel_r16,
343
   },
344
   {
345
      MESA_FORMAT_RG1616,
346
      fetch_texel_1d_f_rg1616,
347
      fetch_texel_2d_f_rg1616,
348
      fetch_texel_3d_f_rg1616,
349
      store_texel_rg1616,
350
   },
351
   {
352
      MESA_FORMAT_RG1616_REV,
353
      fetch_texel_1d_f_rg1616_rev,
354
      fetch_texel_2d_f_rg1616_rev,
355
      fetch_texel_3d_f_rg1616_rev,
356
      store_texel_rg1616_rev,
357
   },
358
   {
359
      MESA_FORMAT_Z24_S8,
360
      fetch_texel_1d_f_z24_s8,
361
      fetch_texel_2d_f_z24_s8,
362
      fetch_texel_3d_f_z24_s8,
363
      store_texel_z24_s8
364
   },
365
   {
366
      MESA_FORMAT_S8_Z24,
367
      fetch_texel_1d_f_s8_z24,
368
      fetch_texel_2d_f_s8_z24,
369
      fetch_texel_3d_f_s8_z24,
370
      store_texel_s8_z24
371
   },
372
   {
373
      MESA_FORMAT_Z16,
374
      fetch_texel_1d_f_z16,
375
      fetch_texel_2d_f_z16,
376
      fetch_texel_3d_f_z16,
377
      store_texel_z16
378
   },
379
   {
380
      MESA_FORMAT_X8_Z24,
381
      fetch_texel_1d_f_s8_z24,
382
      fetch_texel_2d_f_s8_z24,
383
      fetch_texel_3d_f_s8_z24,
384
      store_texel_s8_z24
385
   },
386
   {
387
      MESA_FORMAT_Z24_X8,
388
      fetch_texel_1d_f_z24_s8,
389
      fetch_texel_2d_f_z24_s8,
390
      fetch_texel_3d_f_z24_s8,
391
      store_texel_z24_s8
392
   },
393
   {
394
      MESA_FORMAT_Z32,
395
      fetch_texel_1d_f_z32,
396
      fetch_texel_2d_f_z32,
397
      fetch_texel_3d_f_z32,
398
      store_texel_z32
399
   },
400
   {
401
      MESA_FORMAT_S8,
402
      NULL,
403
      NULL,
404
      NULL,
405
      NULL
406
   },
407
   {
408
      MESA_FORMAT_SRGB8,
409
      fetch_texel_1d_srgb8,
410
      fetch_texel_2d_srgb8,
411
      fetch_texel_3d_srgb8,
412
      store_texel_srgb8
413
   },
414
   {
415
      MESA_FORMAT_SRGBA8,
416
      fetch_texel_1d_srgba8,
417
      fetch_texel_2d_srgba8,
418
      fetch_texel_3d_srgba8,
419
      store_texel_srgba8
420
   },
421
   {
422
      MESA_FORMAT_SARGB8,
423
      fetch_texel_1d_sargb8,
424
      fetch_texel_2d_sargb8,
425
      fetch_texel_3d_sargb8,
426
      store_texel_sargb8
427
   },
428
   {
429
      MESA_FORMAT_SL8,
430
      fetch_texel_1d_sl8,
431
      fetch_texel_2d_sl8,
432
      fetch_texel_3d_sl8,
433
      store_texel_sl8
434
   },
435
   {
436
      MESA_FORMAT_SLA8,
437
      fetch_texel_1d_sla8,
438
      fetch_texel_2d_sla8,
439
      fetch_texel_3d_sla8,
440
      store_texel_sla8
441
   },
442
   {
443
      MESA_FORMAT_SRGB_DXT1,
444
      NULL,
445
      _mesa_fetch_texel_2d_f_srgb_dxt1,
446
      NULL,
447
      NULL
448
   },
449
   {
450
      MESA_FORMAT_SRGBA_DXT1,
451
      NULL,
452
      _mesa_fetch_texel_2d_f_srgba_dxt1,
453
      NULL,
454
      NULL
455
   },
456
   {
457
      MESA_FORMAT_SRGBA_DXT3,
458
      NULL,
459
      _mesa_fetch_texel_2d_f_srgba_dxt3,
460
      NULL,
461
      NULL
462
   },
463
   {
464
      MESA_FORMAT_SRGBA_DXT5,
465
      NULL,
466
      _mesa_fetch_texel_2d_f_srgba_dxt5,
467
      NULL,
468
      NULL
469
   },
470
 
471
   {
472
      MESA_FORMAT_RGB_FXT1,
473
      NULL,
474
      _mesa_fetch_texel_2d_f_rgb_fxt1,
475
      NULL,
476
      NULL
477
   },
478
   {
479
      MESA_FORMAT_RGBA_FXT1,
480
      NULL,
481
      _mesa_fetch_texel_2d_f_rgba_fxt1,
482
      NULL,
483
      NULL
484
   },
485
   {
486
      MESA_FORMAT_RGB_DXT1,
487
      NULL,
488
      _mesa_fetch_texel_2d_f_rgb_dxt1,
489
      NULL,
490
      NULL
491
   },
492
   {
493
      MESA_FORMAT_RGBA_DXT1,
494
      NULL,
495
      _mesa_fetch_texel_2d_f_rgba_dxt1,
496
      NULL,
497
      NULL
498
   },
499
   {
500
      MESA_FORMAT_RGBA_DXT3,
501
      NULL,
502
      _mesa_fetch_texel_2d_f_rgba_dxt3,
503
      NULL,
504
      NULL
505
   },
506
   {
507
      MESA_FORMAT_RGBA_DXT5,
508
      NULL,
509
      _mesa_fetch_texel_2d_f_rgba_dxt5,
510
      NULL,
511
      NULL
512
   },
513
   {
514
      MESA_FORMAT_RGBA_FLOAT32,
515
      fetch_texel_1d_f_rgba_f32,
516
      fetch_texel_2d_f_rgba_f32,
517
      fetch_texel_3d_f_rgba_f32,
518
      store_texel_rgba_f32
519
   },
520
   {
521
      MESA_FORMAT_RGBA_FLOAT16,
522
      fetch_texel_1d_f_rgba_f16,
523
      fetch_texel_2d_f_rgba_f16,
524
      fetch_texel_3d_f_rgba_f16,
525
      store_texel_rgba_f16
526
   },
527
   {
528
      MESA_FORMAT_RGB_FLOAT32,
529
      fetch_texel_1d_f_rgb_f32,
530
      fetch_texel_2d_f_rgb_f32,
531
      fetch_texel_3d_f_rgb_f32,
532
      store_texel_rgb_f32
533
   },
534
   {
535
      MESA_FORMAT_RGB_FLOAT16,
536
      fetch_texel_1d_f_rgb_f16,
537
      fetch_texel_2d_f_rgb_f16,
538
      fetch_texel_3d_f_rgb_f16,
539
      store_texel_rgb_f16
540
   },
541
   {
542
      MESA_FORMAT_ALPHA_FLOAT32,
543
      fetch_texel_1d_f_alpha_f32,
544
      fetch_texel_2d_f_alpha_f32,
545
      fetch_texel_3d_f_alpha_f32,
546
      store_texel_alpha_f32
547
   },
548
   {
549
      MESA_FORMAT_ALPHA_FLOAT16,
550
      fetch_texel_1d_f_alpha_f16,
551
      fetch_texel_2d_f_alpha_f16,
552
      fetch_texel_3d_f_alpha_f16,
553
      store_texel_alpha_f16
554
   },
555
   {
556
      MESA_FORMAT_LUMINANCE_FLOAT32,
557
      fetch_texel_1d_f_luminance_f32,
558
      fetch_texel_2d_f_luminance_f32,
559
      fetch_texel_3d_f_luminance_f32,
560
      store_texel_luminance_f32
561
   },
562
   {
563
      MESA_FORMAT_LUMINANCE_FLOAT16,
564
      fetch_texel_1d_f_luminance_f16,
565
      fetch_texel_2d_f_luminance_f16,
566
      fetch_texel_3d_f_luminance_f16,
567
      store_texel_luminance_f16
568
   },
569
   {
570
      MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
571
      fetch_texel_1d_f_luminance_alpha_f32,
572
      fetch_texel_2d_f_luminance_alpha_f32,
573
      fetch_texel_3d_f_luminance_alpha_f32,
574
      store_texel_luminance_alpha_f32
575
   },
576
   {
577
      MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
578
      fetch_texel_1d_f_luminance_alpha_f16,
579
      fetch_texel_2d_f_luminance_alpha_f16,
580
      fetch_texel_3d_f_luminance_alpha_f16,
581
      store_texel_luminance_alpha_f16
582
   },
583
   {
584
      MESA_FORMAT_INTENSITY_FLOAT32,
585
      fetch_texel_1d_f_intensity_f32,
586
      fetch_texel_2d_f_intensity_f32,
587
      fetch_texel_3d_f_intensity_f32,
588
      store_texel_intensity_f32
589
   },
590
   {
591
      MESA_FORMAT_INTENSITY_FLOAT16,
592
      fetch_texel_1d_f_intensity_f16,
593
      fetch_texel_2d_f_intensity_f16,
594
      fetch_texel_3d_f_intensity_f16,
595
      store_texel_intensity_f16
596
   },
597
 
598
   /* non-normalized, signed int */
599
   {
600
      MESA_FORMAT_RGBA_INT8,
601
      fetch_texel_1d_rgba_int8,
602
      fetch_texel_2d_rgba_int8,
603
      fetch_texel_3d_rgba_int8,
604
      store_texel_rgba_int8
605
   },
606
   {
607
      MESA_FORMAT_RGBA_INT16,
608
      fetch_texel_1d_rgba_int16,
609
      fetch_texel_2d_rgba_int16,
610
      fetch_texel_3d_rgba_int16,
611
      store_texel_rgba_int16
612
   },
613
   {
614
      MESA_FORMAT_RGBA_INT32,
615
      fetch_texel_1d_rgba_int32,
616
      fetch_texel_2d_rgba_int32,
617
      fetch_texel_3d_rgba_int32,
618
      store_texel_rgba_int32
619
   },
620
 
621
   /* non-normalized, unsigned int */
622
   {
623
      MESA_FORMAT_RGBA_UINT8,
624
      fetch_texel_1d_rgba_uint8,
625
      fetch_texel_2d_rgba_uint8,
626
      fetch_texel_3d_rgba_uint8,
627
      store_texel_rgba_uint8
628
   },
629
   {
630
      MESA_FORMAT_RGBA_UINT16,
631
      fetch_texel_1d_rgba_uint16,
632
      fetch_texel_2d_rgba_uint16,
633
      fetch_texel_3d_rgba_uint16,
634
      store_texel_rgba_uint16
635
   },
636
   {
637
      MESA_FORMAT_RGBA_UINT32,
638
      fetch_texel_1d_rgba_uint32,
639
      fetch_texel_2d_rgba_uint32,
640
      fetch_texel_3d_rgba_uint32,
641
      store_texel_rgba_uint32
642
   },
643
 
644
   /* dudv */
645
   {
646
      MESA_FORMAT_DUDV8,
647
      fetch_texel_1d_dudv8,
648
      fetch_texel_2d_dudv8,
649
      fetch_texel_3d_dudv8,
650
      NULL
651
   },
652
 
653
   /* signed, normalized */
654
   {
655
      MESA_FORMAT_SIGNED_R8,
656
      fetch_texel_1d_signed_r8,
657
      fetch_texel_2d_signed_r8,
658
      fetch_texel_3d_signed_r8,
659
      store_texel_signed_r8
660
   },
661
   {
662
      MESA_FORMAT_SIGNED_RG88,
663
      fetch_texel_1d_signed_rg88,
664
      fetch_texel_2d_signed_rg88,
665
      fetch_texel_3d_signed_rg88,
666
      store_texel_signed_rg88
667
   },
668
   {
669
      MESA_FORMAT_SIGNED_RGBX8888,
670
      fetch_texel_1d_signed_rgbx8888,
671
      fetch_texel_2d_signed_rgbx8888,
672
      fetch_texel_3d_signed_rgbx8888,
673
      store_texel_signed_rgbx8888
674
   },
675
   {
676
      MESA_FORMAT_SIGNED_RGBA8888,
677
      fetch_texel_1d_signed_rgba8888,
678
      fetch_texel_2d_signed_rgba8888,
679
      fetch_texel_3d_signed_rgba8888,
680
      store_texel_signed_rgba8888
681
   },
682
   {
683
      MESA_FORMAT_SIGNED_RGBA8888_REV,
684
      fetch_texel_1d_signed_rgba8888_rev,
685
      fetch_texel_2d_signed_rgba8888_rev,
686
      fetch_texel_3d_signed_rgba8888_rev,
687
      store_texel_signed_rgba8888_rev
688
   },
689
   {
690
      MESA_FORMAT_SIGNED_R_16,
691
      fetch_texel_1d_signed_r_16,
692
      fetch_texel_2d_signed_r_16,
693
      fetch_texel_3d_signed_r_16,
694
      store_texel_signed_r_16
695
   },
696
   {
697
      MESA_FORMAT_SIGNED_RG_16,
698
      fetch_texel_1d_signed_rg_16,
699
      fetch_texel_2d_signed_rg_16,
700
      fetch_texel_3d_signed_rg_16,
701
      store_texel_signed_rg_16
702
   },
703
   {
704
      MESA_FORMAT_SIGNED_RGB_16,
705
      fetch_texel_1d_signed_rgb_16,
706
      fetch_texel_2d_signed_rgb_16,
707
      fetch_texel_3d_signed_rgb_16,
708
      store_texel_signed_rgb_16
709
   },
710
   {
711
      MESA_FORMAT_SIGNED_RGBA_16,
712
      fetch_texel_1d_signed_rgba_16,
713
      fetch_texel_2d_signed_rgba_16,
714
      fetch_texel_3d_signed_rgba_16,
715
      store_texel_signed_rgba_16
716
   },
717
   {
718
      MESA_FORMAT_RGBA_16,
719
      fetch_texel_1d_rgba_16,
720
      fetch_texel_2d_rgba_16,
721
      fetch_texel_3d_rgba_16,
722
      store_texel_rgba_16
723
   }
724
};
725
 
726
 
727
static FetchTexelFuncF
728
_mesa_get_texel_fetch_func(gl_format format, GLuint dims)
729
{
730
#ifdef DEBUG
731
   /* check that the table entries are sorted by format name */
732
   gl_format fmt;
733
   for (fmt = 0; fmt < MESA_FORMAT_COUNT; fmt++) {
734
      assert(texfetch_funcs[fmt].Name == fmt);
735
   }
736
#endif
737
 
738
   assert(Elements(texfetch_funcs) == MESA_FORMAT_COUNT);
739
   assert(format < MESA_FORMAT_COUNT);
740
 
741
   switch (dims) {
742
   case 1:
743
      return texfetch_funcs[format].Fetch1D;
744
   case 2:
745
      return texfetch_funcs[format].Fetch2D;
746
   case 3:
747
      return texfetch_funcs[format].Fetch3D;
748
   default:
749
      assert(0 && "bad dims in _mesa_get_texel_fetch_func");
750
      return NULL;
751
   }
752
}
753
 
754
 
755
StoreTexelFunc
756
_mesa_get_texel_store_func(gl_format format)
757
{
758
   assert(format < MESA_FORMAT_COUNT);
759
   return texfetch_funcs[format].StoreTexel;
760
}
761
 
762
 
763
/**
764
 * Adaptor for fetching a GLchan texel from a float-valued texture.
765
 */
766
static void
767
fetch_texel_float_to_chan(const struct gl_texture_image *texImage,
768
                          GLint i, GLint j, GLint k, GLchan *texelOut)
769
{
770
   GLfloat temp[4];
771
   GLenum baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
772
 
773
   ASSERT(texImage->FetchTexelf);
774
   texImage->FetchTexelf(texImage, i, j, k, temp);
775
   if (baseFormat == GL_DEPTH_COMPONENT ||
776
       baseFormat == GL_DEPTH_STENCIL_EXT) {
777
      /* just one channel */
778
      UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]);
779
   }
780
   else {
781
      /* four channels */
782
      UNCLAMPED_FLOAT_TO_CHAN(texelOut[0], temp[0]);
783
      UNCLAMPED_FLOAT_TO_CHAN(texelOut[1], temp[1]);
784
      UNCLAMPED_FLOAT_TO_CHAN(texelOut[2], temp[2]);
785
      UNCLAMPED_FLOAT_TO_CHAN(texelOut[3], temp[3]);
786
   }
787
}
788
 
789
 
790
#if 0
791
/**
792
 * Adaptor for fetching a float texel from a GLchan-valued texture.
793
 */
794
static void
795
fetch_texel_chan_to_float(const struct gl_texture_image *texImage,
796
                          GLint i, GLint j, GLint k, GLfloat *texelOut)
797
{
798
   GLchan temp[4];
799
   GLenum baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
800
 
801
   ASSERT(texImage->FetchTexelc);
802
   texImage->FetchTexelc(texImage, i, j, k, temp);
803
   if (baseFormat == GL_DEPTH_COMPONENT ||
804
       baseFormat == GL_DEPTH_STENCIL_EXT) {
805
      /* just one channel */
806
      texelOut[0] = CHAN_TO_FLOAT(temp[0]);
807
   }
808
   else {
809
      /* four channels */
810
      texelOut[0] = CHAN_TO_FLOAT(temp[0]);
811
      texelOut[1] = CHAN_TO_FLOAT(temp[1]);
812
      texelOut[2] = CHAN_TO_FLOAT(temp[2]);
813
      texelOut[3] = CHAN_TO_FLOAT(temp[3]);
814
   }
815
}
816
#endif
817
 
818
 
819
/**
820
 * Initialize the texture image's FetchTexelc and FetchTexelf methods.
821
 */
822
void
823
_mesa_set_fetch_functions(struct gl_texture_image *texImage, GLuint dims)
824
{
825
   ASSERT(dims == 1 || dims == 2 || dims == 3);
826
 
827
   texImage->FetchTexelf =
828
      _mesa_get_texel_fetch_func(texImage->TexFormat, dims);
829
 
830
   texImage->FetchTexelc = fetch_texel_float_to_chan;
831
 
832
   ASSERT(texImage->FetchTexelc);
833
   ASSERT(texImage->FetchTexelf);
834
}