1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
|
/*
* These values are used in the fixed-point arithmetic used
* for linear filtering.
*/
#define WEIGHT_SCALE 65536.0F
#define WEIGHT_SHIFT 16
/*
* Compute the remainder of a divided by b, but be careful with
* negative values so that GL_REPEAT mode works right.
*/
static INLINE GLint
repeat_remainder(GLint a, GLint b)
{
if (a >= 0)
return a % b;
else
return (a + 1) % b + b - 1;
}
/*
* Used to compute texel locations for linear sampling.
* Input:
* wrapMode = GL_REPEAT, GL_CLAMP, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER
* S = texcoord in [0,1]
* SIZE = width (or height or depth) of texture
* Output:
* U = texcoord in [0, width]
* I0, I1 = two nearest texel indexes
*/
#define COMPUTE_LINEAR_TEXEL_LOCATIONS(wrapMode, S, U, SIZE, I0, I1) \
{ \
if (wrapMode == GL_REPEAT) { \
U = S * SIZE - 0.5F; \
if (tObj->_IsPowerOfTwo) { \
I0 = IFLOOR(U) & (SIZE - 1); \
I1 = (I0 + 1) & (SIZE - 1); \
} \
else { \
I0 = repeat_remainder(IFLOOR(U), SIZE); \
I1 = repeat_remainder(I0 + 1, SIZE); \
} \
} \
else if (wrapMode == GL_CLAMP_TO_EDGE) { \
if (S <= 0.0F) \
U = 0.0F; \
else if (S >= 1.0F) \
U = (GLfloat) SIZE; \
else \
U = S * SIZE; \
U -= 0.5F; \
I0 = IFLOOR(U); \
I1 = I0 + 1; \
if (I0 < 0) \
I0 = 0; \
if (I1 >= (GLint) SIZE) \
I1 = SIZE - 1; \
} \
else if (wrapMode == GL_CLAMP_TO_BORDER) { \
const GLfloat min = -1.0F / (2.0F * SIZE); \
const GLfloat max = 1.0F - min; \
if (S <= min) \
U = min * SIZE; \
else if (S >= max) \
U = max * SIZE; \
else \
U = S * SIZE; \
U -= 0.5F; \
I0 = IFLOOR(U); \
I1 = I0 + 1; \
} \
else if (wrapMode == GL_MIRRORED_REPEAT) { \
const GLint flr = IFLOOR(S); \
if (flr & 1) \
U = 1.0F - (S - (GLfloat) flr); /* flr is odd */ \
else \
U = S - (GLfloat) flr; /* flr is even */ \
U = (U * SIZE) - 0.5F; \
I0 = IFLOOR(U); \
I1 = I0 + 1; \
if (I0 < 0) \
I0 = 0; \
if (I1 >= (GLint) SIZE) \
I1 = SIZE - 1; \
} \
else if (wrapMode == GL_MIRROR_CLAMP_EXT) { \
U = (GLfloat) fabs(S); \
if (U >= 1.0F) \
U = (GLfloat) SIZE; \
else \
U *= SIZE; \
U -= 0.5F; \
I0 = IFLOOR(U); \
I1 = I0 + 1; \
} \
else if (wrapMode == GL_MIRROR_CLAMP_TO_EDGE_EXT) { \
U = (GLfloat) fabs(S); \
if (U >= 1.0F) \
U = (GLfloat) SIZE; \
else \
U *= SIZE; \
U -= 0.5F; \
I0 = IFLOOR(U); \
I1 = I0 + 1; \
if (I0 < 0) \
I0 = 0; \
if (I1 >= (GLint) SIZE) \
I1 = SIZE - 1; \
} \
else if (wrapMode == GL_MIRROR_CLAMP_TO_BORDER_EXT) { \
const GLfloat min = -1.0F / (2.0F * SIZE); \
const GLfloat max = 1.0F - min; \
U = (GLfloat) fabs(S); \
if (U <= min) \
U = min * SIZE; \
else if (U >= max) \
U = max * SIZE; \
else \
U *= SIZE; \
U -= 0.5F; \
I0 = IFLOOR(U); \
I1 = I0 + 1; \
} \
else { \
ASSERT(wrapMode == GL_CLAMP); \
if (S <= 0.0F) \
U = 0.0F; \
else if (S >= 1.0F) \
U = (GLfloat) SIZE; \
else \
U = S * SIZE; \
U -= 0.5F; \
I0 = IFLOOR(U); \
I1 = I0 + 1; \
} \
}
/*
* Used to compute texel location for nearest sampling.
*/
#define COMPUTE_NEAREST_TEXEL_LOCATION(wrapMode, S, SIZE, I) \
{ \
if (wrapMode == GL_REPEAT) { \
/* s limited to [0,1) */ \
/* i limited to [0,size-1] */ \
I = IFLOOR(S * SIZE); \
if (tObj->_IsPowerOfTwo) \
I &= (SIZE - 1); \
else \
I = repeat_remainder(I, SIZE); \
} \
else if (wrapMode == GL_CLAMP_TO_EDGE) { \
/* s limited to [min,max] */ \
/* i limited to [0, size-1] */ \
const GLfloat min = 1.0F / (2.0F * SIZE); \
const GLfloat max = 1.0F - min; \
if (S < min) \
I = 0; \
else if (S > max) \
I = SIZE - 1; \
else \
I = IFLOOR(S * SIZE); \
} \
else if (wrapMode == GL_CLAMP_TO_BORDER) { \
/* s limited to [min,max] */ \
/* i limited to [-1, size] */ \
const GLfloat min = -1.0F / (2.0F * SIZE); \
const GLfloat max = 1.0F - min; \
if (S <= min) \
I = -1; \
else if (S >= max) \
I = SIZE; \
else \
I = IFLOOR(S * SIZE); \
} \
else if (wrapMode == GL_MIRRORED_REPEAT) { \
const GLfloat min = 1.0F / (2.0F * SIZE); \
const GLfloat max = 1.0F - min; \
const GLint flr = IFLOOR(S); \
GLfloat u; \
if (flr & 1) \
u = 1.0F - (S - (GLfloat) flr); /* flr is odd */ \
else \
u = S - (GLfloat) flr; /* flr is even */ \
if (u < min) \
I = 0; \
else if (u > max) \
I = SIZE - 1; \
else \
I = IFLOOR(u * SIZE); \
} \
else if (wrapMode == GL_MIRROR_CLAMP_EXT) { \
/* s limited to [0,1] */ \
/* i limited to [0,size-1] */ \
const GLfloat u = (GLfloat) fabs(S); \
if (u <= 0.0F) \
I = 0; \
else if (u >= 1.0F) \
I = SIZE - 1; \
else \
I = IFLOOR(u * SIZE); \
} \
else if (wrapMode == GL_MIRROR_CLAMP_TO_EDGE_EXT) { \
/* s limited to [min,max] */ \
/* i limited to [0, size-1] */ \
const GLfloat min = 1.0F / (2.0F * SIZE); \
const GLfloat max = 1.0F - min; \
const GLfloat u = (GLfloat) fabs(S); \
if (u < min) \
I = 0; \
else if (u > max) \
I = SIZE - 1; \
else \
I = IFLOOR(u * SIZE); \
} \
else if (wrapMode == GL_MIRROR_CLAMP_TO_BORDER_EXT) { \
/* s limited to [min,max] */ \
/* i limited to [0, size-1] */ \
const GLfloat min = -1.0F / (2.0F * SIZE); \
const GLfloat max = 1.0F - min; \
const GLfloat u = (GLfloat) fabs(S); \
if (u < min) \
I = -1; \
else if (u > max) \
I = SIZE; \
else \
I = IFLOOR(u * SIZE); \
} \
else { \
ASSERT(wrapMode == GL_CLAMP); \
/* s limited to [0,1] */ \
/* i limited to [0,size-1] */ \
if (S <= 0.0F) \
I = 0; \
else if (S >= 1.0F) \
I = SIZE - 1; \
else \
I = IFLOOR(S * SIZE); \
} \
}
/* Power of two image sizes only */
#define COMPUTE_LINEAR_REPEAT_TEXEL_LOCATION(S, U, SIZE, I0, I1) \
{ \
U = S * SIZE - 0.5F; \
I0 = IFLOOR(U) & (SIZE - 1); \
I1 = (I0 + 1) & (SIZE - 1); \
}
/*
* Compute linear mipmap levels for given lambda.
*/
#define COMPUTE_LINEAR_MIPMAP_LEVEL(tObj, lambda, level) \
{ \
if (lambda < 0.0F) \
level = tObj->BaseLevel; \
else if (lambda > tObj->_MaxLambda) \
level = (GLint) (tObj->BaseLevel + tObj->_MaxLambda); \
else \
level = (GLint) (tObj->BaseLevel + lambda); \
}
/*
* Compute nearest mipmap level for given lambda.
*/
#define COMPUTE_NEAREST_MIPMAP_LEVEL(tObj, lambda, level) \
{ \
GLfloat l; \
if (lambda <= 0.5F) \
l = 0.0F; \
else if (lambda > tObj->_MaxLambda + 0.4999F) \
l = tObj->_MaxLambda + 0.4999F; \
else \
l = lambda; \
level = (GLint) (tObj->BaseLevel + l + 0.5F); \
if (level > tObj->_MaxLevel) \
level = tObj->_MaxLevel; \
}
/*
* Note, the FRAC macro has to work perfectly. Otherwise you'll sometimes
* see 1-pixel bands of improperly weighted linear-sampled texels. The
* tests/texwrap.c demo is a good test.
* Also note, FRAC(x) doesn't truly return the fractional part of x for x < 0.
* Instead, if x < 0 then FRAC(x) = 1 - true_frac(x).
*/
#define FRAC(f) ((f) - IFLOOR(f))
/*
* Bitflags for texture border color sampling.
*/
#define I0BIT 1
#define I1BIT 2
#define J0BIT 4
#define J1BIT 8
#define K0BIT 16
#define K1BIT 32
#if 000
/*
* Get texture palette entry.
*/
static void
palette_sample(const GLcontext *ctx,
const struct gl_texture_object *tObj,
GLint index, GLchan rgba[4] )
{
const GLchan *palette;
GLenum format;
if (ctx->Texture.SharedPalette) {
ASSERT(ctx->Texture.Palette.Type != GL_FLOAT);
palette = (const GLchan *) ctx->Texture.Palette.Table;
format = ctx->Texture.Palette.Format;
}
else {
ASSERT(tObj->Palette.Type != GL_FLOAT);
palette = (const GLchan *) tObj->Palette.Table;
format = tObj->Palette.Format;
}
switch (format) {
case GL_ALPHA:
rgba[ACOMP] = palette[index];
return;
case GL_LUMINANCE:
case GL_INTENSITY:
rgba[RCOMP] = palette[index];
return;
case GL_LUMINANCE_ALPHA:
rgba[RCOMP] = palette[(index << 1) + 0];
rgba[ACOMP] = palette[(index << 1) + 1];
return;
case GL_RGB:
rgba[RCOMP] = palette[index * 3 + 0];
rgba[GCOMP] = palette[index * 3 + 1];
rgba[BCOMP] = palette[index * 3 + 2];
return;
case GL_RGBA:
rgba[RCOMP] = palette[(index << 2) + 0];
rgba[GCOMP] = palette[(index << 2) + 1];
rgba[BCOMP] = palette[(index << 2) + 2];
rgba[ACOMP] = palette[(index << 2) + 3];
return;
default:
_mesa_problem(ctx, "Bad palette format in palette_sample");
}
}
#endif
/**********************************************************************/
/* 1-D Texture Sampling Functions */
/**********************************************************************/
/*
* Return the texture sample for coordinate (s) using GL_NEAREST filter.
*/
static void
sample_1d_nearest(GLcontext *ctx,
const struct gl_texture_object *tObj,
const struct gl_texture_image *img,
const GLfloat texcoord[4], TYPE rgba[4])
{
const GLint width = img->Width2; /* without border */
GLint i;
COMPUTE_NEAREST_TEXEL_LOCATION(tObj->WrapS, texcoord[0], width, i);
/* skip over the border, if any */
i += img->Border;
if (i < 0 || i >= (GLint) img->Width) {
/* Need this test for GL_CLAMP_TO_BORDER mode */
#if TYPE_ENUM == GL_FLOAT
COPY_4V(rgba, tObj->BorderColor);
#else
COPY_CHAN4(rgba, tObj->_BorderChan);
#endif
}
else {
#if TYPE_ENUM == GL_FLOAT
img->FetchTexelf(img, i, 0, 0, rgba);
#else
img->FetchTexelc(img, i, 0, 0, rgba);
#endif
if (img->Format == GL_COLOR_INDEX) {
palette_sample(ctx, tObj, rgba[0], rgba);
}
}
}
/*
* Return the texture sample for coordinate (s) using GL_LINEAR filter.
*/
static void
sample_1d_linear(GLcontext *ctx,
const struct gl_texture_object *tObj,
const struct gl_texture_image *img,
const GLfloat texcoord[4], GLchan rgba[4])
{
const GLint width = img->Width2;
GLint i0, i1;
GLfloat u;
GLuint useBorderColor;
COMPUTE_LINEAR_TEXEL_LOCATIONS(tObj->WrapS, texcoord[0], u, width, i0, i1);
useBorderColor = 0;
if (img->Border) {
i0 += img->Border;
i1 += img->Border;
}
else {
if (i0 < 0 || i0 >= width) useBorderColor |= I0BIT;
if (i1 < 0 || i1 >= width) useBorderColor |= I1BIT;
}
{
const GLfloat a = FRAC(u);
#if CHAN_TYPE == GL_FLOAT || CHAN_TYPE == GL_UNSIGNED_SHORT
const GLfloat w0 = (1.0F-a);
const GLfloat w1 = a ;
#else /* CHAN_BITS == 8 */
/* compute sample weights in fixed point in [0,WEIGHT_SCALE] */
const GLint w0 = IROUND_POS((1.0F - a) * WEIGHT_SCALE);
const GLint w1 = IROUND_POS( a * WEIGHT_SCALE);
#endif
GLchan t0[4], t1[4]; /* texels */
if (useBorderColor & I0BIT) {
COPY_CHAN4(t0, tObj->_BorderChan);
}
else {
img->FetchTexelc(img, i0, 0, 0, t0);
if (img->Format == GL_COLOR_INDEX) {
palette_sample(ctx, tObj, t0[0], t0);
}
}
if (useBorderColor & I1BIT) {
COPY_CHAN4(t1, tObj->_BorderChan);
}
else {
img->FetchTexelc(img, i1, 0, 0, t1);
if (img->Format == GL_COLOR_INDEX) {
palette_sample(ctx, tObj, t1[0], t1);
}
}
#if CHAN_TYPE == GL_FLOAT
rgba[0] = w0 * t0[0] + w1 * t1[0];
rgba[1] = w0 * t0[1] + w1 * t1[1];
rgba[2] = w0 * t0[2] + w1 * t1[2];
rgba[3] = w0 * t0[3] + w1 * t1[3];
#elif CHAN_TYPE == GL_UNSIGNED_SHORT
rgba[0] = (GLchan) (w0 * t0[0] + w1 * t1[0] + 0.5);
rgba[1] = (GLchan) (w0 * t0[1] + w1 * t1[1] + 0.5);
rgba[2] = (GLchan) (w0 * t0[2] + w1 * t1[2] + 0.5);
rgba[3] = (GLchan) (w0 * t0[3] + w1 * t1[3] + 0.5);
#else /* CHAN_BITS == 8 */
rgba[0] = (GLchan) ((w0 * t0[0] + w1 * t1[0]) >> WEIGHT_SHIFT);
rgba[1] = (GLchan) ((w0 * t0[1] + w1 * t1[1]) >> WEIGHT_SHIFT);
rgba[2] = (GLchan) ((w0 * t0[2] + w1 * t1[2]) >> WEIGHT_SHIFT);
rgba[3] = (GLchan) ((w0 * t0[3] + w1 * t1[3]) >> WEIGHT_SHIFT);
#endif
}
}
static void
sample_1d_nearest_mipmap_nearest(GLcontext *ctx,
const struct gl_texture_object *tObj,
GLuint n, const GLfloat texcoord[][4],
const GLfloat lambda[], GLchan rgba[][4])
{
GLuint i;
ASSERT(lambda != NULL);
for (i = 0; i < n; i++) {
GLint level;
COMPUTE_NEAREST_MIPMAP_LEVEL(tObj, lambda[i], level);
sample_1d_nearest(ctx, tObj, tObj->Image[0][level], texcoord[i], rgba[i]);
}
}
static void
sample_1d_linear_mipmap_nearest(GLcontext *ctx,
const struct gl_texture_object *tObj,
GLuint n, const GLfloat texcoord[][4],
const GLfloat lambda[], GLchan rgba[][4])
{
GLuint i;
ASSERT(lambda != NULL);
for (i = 0; i < n; i++) {
GLint level;
COMPUTE_NEAREST_MIPMAP_LEVEL(tObj, lambda[i], level);
sample_1d_linear(ctx, tObj, tObj->Image[0][level], texcoord[i], rgba[i]);
}
}
/*
* This is really just needed in order to prevent warnings with some compilers.
*/
#if CHAN_TYPE == GL_FLOAT
#define CHAN_CAST
#else
#define CHAN_CAST (GLchan) (GLint)
#endif
static void
sample_1d_nearest_mipmap_linear(GLcontext *ctx,
const struct gl_texture_object *tObj,
GLuint n, const GLfloat texcoord[][4],
const GLfloat lambda[], GLchan rgba[][4])
{
GLuint i;
ASSERT(lambda != NULL);
for (i = 0; i < n; i++) {
GLint level;
COMPUTE_LINEAR_MIPMAP_LEVEL(tObj, lambda[i], level);
if (level >= tObj->_MaxLevel) {
sample_1d_nearest(ctx, tObj, tObj->Image[0][tObj->_MaxLevel],
texcoord[i], rgba[i]);
}
else {
GLchan t0[4], t1[4];
const GLfloat f = FRAC(lambda[i]);
sample_1d_nearest(ctx, tObj, tObj->Image[0][level ], texcoord[i], t0);
sample_1d_nearest(ctx, tObj, tObj->Image[0][level+1], texcoord[i], t1);
rgba[i][RCOMP] = CHAN_CAST ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]);
rgba[i][GCOMP] = CHAN_CAST ((1.0F-f) * t0[GCOMP] + f * t1[GCOMP]);
rgba[i][BCOMP] = CHAN_CAST ((1.0F-f) * t0[BCOMP] + f * t1[BCOMP]);
rgba[i][ACOMP] = CHAN_CAST ((1.0F-f) * t0[ACOMP] + f * t1[ACOMP]);
}
}
}
static void
sample_1d_linear_mipmap_linear(GLcontext *ctx,
const struct gl_texture_object *tObj,
GLuint n, const GLfloat texcoord[][4],
const GLfloat lambda[], GLchan rgba[][4])
{
GLuint i;
ASSERT(lambda != NULL);
for (i = 0; i < n; i++) {
GLint level;
COMPUTE_LINEAR_MIPMAP_LEVEL(tObj, lambda[i], level);
if (level >= tObj->_MaxLevel) {
sample_1d_linear(ctx, tObj, tObj->Image[0][tObj->_MaxLevel],
texcoord[i], rgba[i]);
}
else {
GLchan t0[4], t1[4];
const GLfloat f = FRAC(lambda[i]);
sample_1d_linear(ctx, tObj, tObj->Image[0][level ], texcoord[i], t0);
sample_1d_linear(ctx, tObj, tObj->Image[0][level+1], texcoord[i], t1);
rgba[i][RCOMP] = CHAN_CAST ((1.0F-f) * t0[RCOMP] + f * t1[RCOMP]);
rgba[i][GCOMP] = CHAN_CAST ((1.0F-f) * t0[GCOMP] + f * t1[GCOMP]);
rgba[i][BCOMP] = CHAN_CAST ((1.0F-f) * t0[BCOMP] + f * t1[BCOMP]);
rgba[i][ACOMP] = CHAN_CAST ((1.0F-f) * t0[ACOMP] + f * t1[ACOMP]);
}
}
}
static void
sample_nearest_1d( GLcontext *ctx, GLuint texUnit,
const struct gl_texture_object *tObj, GLuint n,
const GLfloat texcoords[][4], const GLfloat lambda[],
GLchan rgba[][4] )
{
GLuint i;
struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];
(void) lambda;
for (i=0;i<n;i++) {
sample_1d_nearest(ctx, tObj, image, texcoords[i], rgba[i]);
}
}
static void
sample_linear_1d( GLcontext *ctx, GLuint texUnit,
const struct gl_texture_object *tObj, GLuint n,
const GLfloat texcoords[][4], const GLfloat lambda[],
GLchan rgba[][4] )
{
GLuint i;
struct gl_texture_image *image = tObj->Image[0][tObj->BaseLevel];
(void) lambda;
for (i=0;i<n;i++) {
sample_1d_linear(ctx, tObj, image, texcoords[i], rgba[i]);
}
}
/*
* Given an (s) texture coordinate and lambda (level of detail) value,
* return a texture sample.
*
*/
static void
sample_lambda_1d( GLcontext *ctx, GLuint texUnit,
const struct gl_texture_object *tObj, GLuint n,
const GLfloat texcoords[][4],
const GLfloat lambda[], GLchan rgba[][4] )
{
GLuint minStart, minEnd; /* texels with minification */
GLuint magStart, magEnd; /* texels with magnification */
GLuint i;
ASSERT(lambda != NULL);
compute_min_mag_ranges(SWRAST_CONTEXT(ctx)->_MinMagThresh[texUnit],
n, lambda, &minStart, &minEnd, &magStart, &magEnd);
if (minStart < minEnd) {
/* do the minified texels */
const GLuint m = minEnd - minStart;
switch (tObj->MinFilter) {
case GL_NEAREST:
for (i = minStart; i < minEnd; i++)
sample_1d_nearest(ctx, tObj, tObj->Image[0][tObj->BaseLevel],
texcoords[i], rgba[i]);
break;
case GL_LINEAR:
for (i = minStart; i < minEnd; i++)
sample_1d_linear(ctx, tObj, tObj->Image[0][tObj->BaseLevel],
texcoords[i], rgba[i]);
break;
case GL_NEAREST_MIPMAP_NEAREST:
sample_1d_nearest_mipmap_nearest(ctx, tObj, m, texcoords + minStart,
lambda + minStart, rgba + minStart);
break;
case GL_LINEAR_MIPMAP_NEAREST:
sample_1d_linear_mipmap_nearest(ctx, tObj, m, texcoords + minStart,
lambda + minStart, rgba + minStart);
break;
case GL_NEAREST_MIPMAP_LINEAR:
sample_1d_nearest_mipmap_linear(ctx, tObj, m, texcoords + minStart,
lambda + minStart, rgba + minStart);
break;
case GL_LINEAR_MIPMAP_LINEAR:
sample_1d_linear_mipmap_linear(ctx, tObj, m, texcoords + minStart,
lambda + minStart, rgba + minStart);
break;
default:
_mesa_problem(ctx, "Bad min filter in sample_1d_texture");
return;
}
}
if (magStart < magEnd) {
/* do the magnified texels */
switch (tObj->MagFilter) {
case GL_NEAREST:
for (i = magStart; i < magEnd; i++)
sample_1d_nearest(ctx, tObj, tObj->Image[0][tObj->BaseLevel],
texcoords[i], rgba[i]);
break;
case GL_LINEAR:
for (i = magStart; i < magEnd; i++)
sample_1d_linear(ctx, tObj, tObj->Image[0][tObj->BaseLevel],
texcoords[i], rgba[i]);
break;
default:
_mesa_problem(ctx, "Bad mag filter in sample_1d_texture");
return;
}
}
}
|