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
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
|
/*
* Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
* Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sub license,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <stdio.h>
#include "glheader.h"
#include "macros.h"
#include "mtypes.h"
#include "simple_list.h"
#include "enums.h"
#include "context.h"
#include "texformat.h"
#include "mm.h"
#include "via_context.h"
#include "via_tex.h"
#include "via_state.h"
#include "via_ioctl.h"
GLint texSize8bpp[12][12] = {
{32,32,32,32,32,32,64,128,256,512,1024,2048},
{64,64,64,64,64,64,128,256,512,1024,2048,4096},
{128,128,128,128,128,128,256,512,1024,2048,4096,8192},
{256,256,256,256,256,256,512,1024,2048,4096,8192,16384},
{512,512,512,512,512,512,1024,2048,4096,8192,16384,32768},
{1024,1024,1024,1024,1024,1024,2048,4096,8192,16384,32768,65536},
{2048,2048,2048,2048,2048,2048,4096,8192,16384,32768,65536,131072},
{4096,4096,4096,4096,4096,4096,8192,16384,32768,65536,131072,262144},
{8192,8192,8192,8192,8192,8192,16384,32768,65536,131072,262144,524288},
{16384,16384,16384,16384,16384,16384,32768,65536,131072,262144,524288,1048576},
{32768,32768,32768,32768,32768,32768,65536,131072,262144,524288,1048576,2097152},
{65536,65536,65536,65536,65536,65536,131072,262144,524288,1048576,2097152,4194304
}
};
GLint texSize16bpp[12][12] = {
{32,32,32,32,32,64,128,256,512,1024,2048,4096},
{64,64,64,64,64,128,256,512,1024,2048,4096,8192},
{128,128,128,128,128,256,512,1024,2048,4096,8192,16384},
{256,256,256,256,256,512,1024,2048,4096,8192,16384,32768},
{512,512,512,512,512,1024,2048,4096,8192,16384,32768,65536},
{1024,1024,1024,1024,1024,2048,4096,8192,16384,32768,65536,131072},
{2048,2048,2048,2048,2048,4096,8192,16384,32768,65536,131072,262144},
{4096,4096,4096,4096,4096,8192,16384,32768,65536,131072,262144,524288},
{8192,8192,8192,8192,8192,16384,32768,65536,131072,262144,524288,1048576},
{16384,16384,16384,16384,16384,32768,65536,131072,262144,524288,1048576,2097152},
{32768,32768,32768,32768,32768,65536,131072,262144,524288,1048576,2097152,4194304},
{65536,65536,65536,65536,65536,131072,262144,524288,1048576,2097152,4194304,8388608}
};
GLint texSize32bpp[12][12] = {
{32,32,32,32,64,128,256,512,1024,2048,4096,8192},
{64,64,64,64,128,256,512,1024,2048,4096,8192,16384},
{128,128,128,128,256,512,1024,2048,4096,8192,16384,32768},
{256,256,256,256,512,1024,2048,4096,8192,16384,32768,65536},
{512,512,512,512,1024,2048,4096,8192,16384,32768,65536,131072},
{1024,1024,1024,1024,2048,4096,8192,16384,32768,65536,131072,262144},
{2048,2048,2048,2048,4096,8192,16384,32768,65536,131072,262144,524288},
{4096,4096,4096,4096,8192,16384,32768,65536,131072,262144,524288,1048576},
{8192,8192,8192,8192,16384,32768,65536,131072,262144,524288,1048576,2097152},
{16384,16384,16384,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304},
{32768,32768,32768,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608},
{65536,65536,65536,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216}
};
GLint mipmapTexSize8bpp[12][12] = {
{32,64,96,128,160,192,256,384,640,1152,2176,4224},
{96,96,128,160,192,224,320,512,896,1664,3200,6272},
{224,224,224,256,288,320,480,832,1536,2944,5760,11392},
{480,480,480,480,512,544,832,1504,2880,5632,11136,22144},
{992,992,992,992,992,1024,1568,2880,5600,11072,22016,43904},
{2016,2016,2016,2016,2016,2016,3072,5664,11072,21984,43840,87552},
{4064,4064,4064,4064,4064,4064,6112,11264,22048,43840,87520,174912},
{8160,8160,8160,8160,8160,8160,12256,22496,44032,87584,174912,349664},
{16352,16352,16352,16352,16352,16352,24544,45024,88032,175104,349728,699200},
{32736,32736,32736,32736,32736,32736,49120,90080,176096,350176,699392,1398304},
{65504,65504,65504,65504,65504,65504,98272,180192,352224,700384,1398752,2796544},
{131040,131040,131040,131040,131040,131040,196576,360416,704480,1400800,2797536,5593056
}
};
GLint mipmapTexSize16bpp[12][12] = {
{32,64,96,128,160,224,352,608,1120,2144,4192,8288},
{96,96,128,160,192,288,480,864,1632,3168,6240,12384},
{224,224,224,256,288,448,800,1504,2912,5728,11360,22624},
{480,480,480,480,512,800,1472,2848,5600,11104,22112,44128},
{992,992,992,992,992,1536,2848,5568,11040,21984,43872,87648},
{2016,2016,2016,2016,2016,3040,5632,11040,21952,43808,87520,174944},
{4064,4064,4064,4064,4064,6112,11232,22016,43808,87488,174880,349664},
{8160,8160,8160,8160,8160,12256,22496,44000,87552,174880,349632,699168},
{16352,16352,16352,16352,16352,24544,45024,88032,175072,349696,699168,1398208},
{32736,32736,32736,32736,32736,49120,90080,176096,350176,699360,1398272,2796320},
{65504,65504,65504,65504,65504,98272,180192,352224,700384,1398752,2796512,5592576},
{131040,131040,131040,131040,131040,196576,360416,704480,1400800,2797536,5593056,11185120}
};
GLint mipmapTexSize32bpp[12][12] = {
{32,64,96,128,192,320,576,1088,2112,4160,8256,16448},
{96,96,128,160,256,448,832,1600,3136,6208,12352,24640},
{224,224,224,256,416,768,1472,2880,5696,11328,22592,45120},
{480,480,480,480,768,1440,2816,5568,11072,22080,44096,88128},
{992,992,992,992,1504,2816,5536,11008,21952,43840,87616,175168},
{2016,2016,2016,2016,3040,5600,11008,21920,43776,87488,174912,349760},
{4064,4064,4064,4064,6112,11232,21984,43776,87456,174848,349632,699200},
{8160,8160,8160,8160,12256,22496,44000,87520,174848,349600,699136,1398208},
{16352,16352,16352,16352,24544,45024,88032,175072,349664,699136,1398176,2796288},
{32736,32736,32736,32736,49120,90080,176096,350176,699360,1398240,2796288,5592480},
{65504,65504,65504,65504,98272,180192,352224,700384,1398752,2796512,5592544,11184896},
{131040,131040,131040,131040,196576,360416,704480,1400800,2797536,5593056,11185120,22369760}
};
static int logbase2(int n)
{
GLint i = 1;
GLint log2 = 0;
if (n < 0) {
return -1;
}
while (n > i) {
i *= 2;
log2++;
}
if (i != n) {
return -1;
}
else {
return log2;
}
}
static void viaSetTexImages(viaContextPtr vmesa,
struct gl_texture_object *tObj)
{
GLuint texFormat;
viaTextureObjectPtr t = (viaTextureObjectPtr)tObj->DriverData;
const struct gl_texture_image *baseImage = tObj->Image[tObj->BaseLevel];
GLint firstLevel, lastLevel, numLevels;
GLint log2Width, log2Height, log2Pitch;
GLint (*texSize)[12][12];
GLint w, h, p;
GLint i, j, k, l, m;
GLint mipmapSize;
GLuint texBase;
GLuint basH = 0;
GLuint widthExp = 0;
GLuint heightExp = 0;
#ifdef DEBUG
if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
#endif
switch (baseImage->TexFormat->MesaFormat) {
case MESA_FORMAT_ARGB8888:
if (t->image[tObj->BaseLevel].internalFormat == GL_RGB)
texFormat = HC_HTXnFM_ARGB0888;
else
texFormat = HC_HTXnFM_ARGB8888;
break;
case MESA_FORMAT_ARGB4444:
texFormat = HC_HTXnFM_ARGB4444;
break;
case MESA_FORMAT_RGB565:
texFormat = HC_HTXnFM_RGB565;
break;
case MESA_FORMAT_ARGB1555:
texFormat = HC_HTXnFM_ARGB1555;
break;
case MESA_FORMAT_L8:
texFormat = HC_HTXnFM_L8;
break;
case MESA_FORMAT_I8:
texFormat = HC_HTXnFM_T8;
break;
case MESA_FORMAT_CI8:
texFormat = HC_HTXnFM_Index8;
break;
case MESA_FORMAT_AL88:
texFormat = HC_HTXnFM_AL88;
break;
/*=* John Sheng [2003.7.18] texenv *=*/
case MESA_FORMAT_A8:
texFormat = HC_HTXnFM_A8;
break;
default:
_mesa_problem(vmesa->glCtx, "Bad texture format in viaSetTexImages");
fprintf(stderr, "-- TexFormat = %d\n",baseImage->TexFormat->MesaFormat);
};
/* Compute which mipmap levels we really want to send to the hardware.
* This depends on the base image size, GL_TEXTURE_MIN_LOD,
* GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL, and GL_TEXTURE_MAX_LEVEL.
* Yes, this looks overly complicated, but it's all needed.
*/
if (tObj->MinFilter == GL_LINEAR || tObj->MinFilter == GL_NEAREST) {
firstLevel = lastLevel = tObj->BaseLevel;
}
else {
firstLevel = tObj->BaseLevel + (GLint)(tObj->MinLod + 0.5);
firstLevel = MAX2(firstLevel, tObj->BaseLevel);
lastLevel = tObj->BaseLevel + (GLint)(tObj->MaxLod + 0.5);
lastLevel = MAX2(lastLevel, tObj->BaseLevel);
lastLevel = MIN2(lastLevel, tObj->BaseLevel + baseImage->MaxLog2);
lastLevel = MIN2(lastLevel, tObj->MaxLevel);
lastLevel = MAX2(firstLevel, lastLevel); /* need at least one level */
}
/* save these values */
t->firstLevel = firstLevel;
t->lastLevel = lastLevel;
numLevels = lastLevel - firstLevel + 1;
/*=* [DBG] fgfs : fix mipmap level 11 over hw limitations and result in segmentation fault *=*/
if(numLevels > 10) {
numLevels = 10;
t->lastLevel = firstLevel + 9;
}
log2Width = tObj->Image[firstLevel]->WidthLog2;
log2Height = tObj->Image[firstLevel]->HeightLog2;
log2Pitch = logbase2(tObj->Image[firstLevel]->Width * baseImage->TexFormat->TexelBytes);
for (i = 0; i < numLevels; i++) {
t->image[i].image = tObj->Image[i];
t->image[i].internalFormat = baseImage->Format;
}
if (baseImage->TexFormat->TexelBytes == 1) {
if (numLevels > 1)
texSize = &mipmapTexSize8bpp;
else
texSize = &texSize8bpp;
}
else if (baseImage->TexFormat->TexelBytes == 2) {
if (numLevels > 1)
texSize = &mipmapTexSize16bpp;
else
texSize = &texSize16bpp;
}
else {
if (numLevels > 1)
texSize = &mipmapTexSize32bpp;
else
texSize = &texSize32bpp;
}
t->totalSize = (*texSize)[log2Height][log2Width];
t->texMem.size = t->totalSize;
t->maxLevel = i - 1;
t->dirty = VIA_UPLOAD_TEX0 | VIA_UPLOAD_TEX1;
#ifdef DEBUG
if (VIA_DEBUG) {
fprintf(stderr, "log2Width = %d\n", log2Width);
fprintf(stderr, "log2Height = %d\n", log2Height);
fprintf(stderr, "log2Pitch = %d\n", log2Pitch);
fprintf(stderr, "bytePerTexel = %d\n", baseImage->TexFormat->TexelBytes);
fprintf(stderr, "total size = %d\n", t->totalSize);
fprintf(stderr, "actual level = %d\n", t->actualLevel);
fprintf(stderr, "numlevel = %d\n", numLevels);
}
#endif
{
w = log2Width;
h = log2Height;
for (i = 0; i < numLevels; i++) {
t->image[i].offset = t->totalSize - (*texSize)[h][w];
if (w) w--;
if (h) h--;
}
}
viaUploadTexImages(vmesa, t);
if (t->bufAddr) {
if (t->inAGP)
t->regTexFM = (HC_SubA_HTXnFM << 24) | HC_HTXnLoc_AGP | texFormat;
else
t->regTexFM = (HC_SubA_HTXnFM << 24) | HC_HTXnLoc_Local | texFormat;
w = log2Width;
h = log2Height;
p = log2Pitch;
mipmapSize = 0;
for (i = 0; i < numLevels; i++) {
if (i == (numLevels - 1))
mipmapSize = 0;
else
mipmapSize = (*texSize)[h][w];
/*=* John Sheng [2003.5.31] agp tex *=*/
if (t->inAGP)
texBase = (GLuint)vmesa->agpBase + t->texMem.offset + t->image[i].offset;
else
texBase = t->texMem.offset + t->image[i].offset;
#ifdef DEBUG
if (VIA_DEBUG) {
fprintf(stderr, "texmem offset = %x\n", t->texMem.offset);
fprintf(stderr, "mipmap%d addr = %x\n", i, t->image[i].offset);
fprintf(stderr, "mipmap%d size = %d, h = %d, w = %d\n", i, (*texSize)[h][w], h, w);
fprintf(stderr, "texBase%d = %x\n", i, texBase);
}
#endif
t->regTexBaseAndPitch[i].baseL = ((HC_SubA_HTXnL0BasL + i) << 24) | (texBase & 0xFFFFFF);
if (p < 5) {
t->regTexBaseAndPitch[i].pitchLog2 = ((HC_SubA_HTXnL0Pit + i) << 24) |
(0x5 << 20);
}
else {
t->regTexBaseAndPitch[i].pitchLog2 = ((HC_SubA_HTXnL0Pit + i) << 24) |
((GLuint)p << 20);
}
j = i / 3;
k = 3 - (i % 3);
basH |= ((texBase & 0xFF000000) >> (k << 3));
if (k == 1) {
t->regTexBaseH[j] = ((j + HC_SubA_HTXnL012BasH) << 24) | basH;
basH = 0;
}
l = i / 6;
m = i % 6;
widthExp |= (((GLuint)w & 0xF) << (m << 2));
heightExp |= (((GLuint)h & 0xF) << (m << 2));
if (m == 5) {
t->regTexWidthLog2[l] = ((l + HC_SubA_HTXnL0_5WE) << 24 | widthExp);
t->regTexHeightLog2[l] = ((l + HC_SubA_HTXnL0_5HE) << 24 | heightExp);
widthExp = 0;
heightExp = 0;
}
if (w) w--;
if (h) h--;
if (p) p--;
}
if (k != 1) {
t->regTexBaseH[j] = ((j + HC_SubA_HTXnL012BasH) << 24) | basH;
}
if (m != 5) {
t->regTexWidthLog2[l] = ((l + HC_SubA_HTXnL0_5WE) << 24 | widthExp);
t->regTexHeightLog2[l] = ((l + HC_SubA_HTXnL0_5HE) << 24 | heightExp);
}
}
#ifdef DEBUG
if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
#endif
}
/* ================================================================
* Texture combine functions
*/
#define VIA_DISABLE 0
#define VIA_PASSTHRU 1
#define VIA_REPLACE 2
#define VIA_MODULATE 3
#define VIA_DECAL 4
#define VIA_BLEND 5
#define VIA_ALPHA_BLEND 6
#define VIA_ADD 7
#define VIA_MAX_COMBFUNC 8
static GLuint via_color_combine[][VIA_MAX_COMBFUNC] =
{
/* Unit 0:
*/
{
/* Disable combiner stage
*/
0,
/* Passthru
*/
1,
/* GL_REPLACE
*/
2,
/* GL_MODULATE
*/
3,
/* GL_DECAL
*/
4,
/* GL_BLEND
*/
5,
/* GL_BLEND according to alpha
*/
6,
/* GL_ADD
*/
7,
},
/* Unit 1:
*/
{
/* Disable combiner stage (Note: disables all subsequent stages)
*/
0,
/* Passthru
*/
1,
/* GL_REPLACE
*/
2,
/* GL_MODULATE
*/
3,
/* GL_DECAL
*/
4,
/* GL_BLEND
*/
5,
/* GL_BLEND according to alpha
*/
6,
/* GL_ADD
*/
7,
}
};
static GLuint via_alpha_combine[][VIA_MAX_COMBFUNC] =
{
/* Unit 0:
*/
{
/* Disable combiner stage
*/
0,
/* Passthru
*/
1,
/* GL_REPLACE
*/
2,
/* GL_MODULATE
*/
3,
/* GL_DECAL
*/
4,
/* GL_BLEND
*/
5,
/* GL_BLEND according to alpha (same as above)
*/
6,
/* GL_ADD
*/
7,
},
/* Unit 1:
*/
{
/* Disable combiner stage
*/
0,
/* Passthru
*/
1,
/* GL_REPLACE
*/
2,
/* GL_MODULATE
*/
3,
/* GL_DECAL
*/
4,
/* GL_BLEND
*/
5,
/* GL_BLEND according to alpha (same as above)
*/
6,
/* GL_ADD
*/
7,
}
};
static void viaUpdateTexEnv(GLcontext *ctx, GLuint unit)
{
const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
const struct gl_texture_object *tObj = texUnit->_Current;
const GLuint format = tObj->Image[tObj->BaseLevel]->Format;
GLuint color_combine, alpha_combine;
#ifdef DEBUG
if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
#endif
switch (texUnit->EnvMode) {
case GL_REPLACE:
if (format == GL_ALPHA) {
color_combine = via_color_combine[unit][VIA_PASSTHRU];
alpha_combine = via_alpha_combine[unit][VIA_REPLACE];
}
else if (format == GL_LUMINANCE || format == GL_RGB) {
color_combine = via_color_combine[unit][VIA_REPLACE];
alpha_combine = via_alpha_combine[unit][VIA_PASSTHRU];
}
else {
color_combine = via_color_combine[unit][VIA_REPLACE];
alpha_combine = via_alpha_combine[unit][VIA_REPLACE];
}
break;
case GL_MODULATE:
if (format == GL_ALPHA) {
color_combine = via_color_combine[unit][VIA_PASSTHRU];
alpha_combine = via_alpha_combine[unit][VIA_MODULATE];
}
else {
color_combine = via_color_combine[unit][VIA_MODULATE];
alpha_combine = via_alpha_combine[unit][VIA_MODULATE];
}
break;
case GL_DECAL:
switch (format) {
case GL_RGBA:
color_combine = via_color_combine[unit][VIA_ALPHA_BLEND];
alpha_combine = via_alpha_combine[unit][VIA_PASSTHRU];
break;
case GL_RGB:
color_combine = via_color_combine[unit][VIA_REPLACE];
alpha_combine = via_alpha_combine[unit][VIA_PASSTHRU];
break;
case GL_ALPHA:
case GL_LUMINANCE:
case GL_LUMINANCE_ALPHA:
case GL_INTENSITY:
color_combine = via_color_combine[unit][VIA_PASSTHRU];
alpha_combine = via_alpha_combine[unit][VIA_PASSTHRU];
break;
case GL_COLOR_INDEX:
default:
return;
}
break;
case GL_BLEND:
switch (format) {
case GL_RGB:
case GL_LUMINANCE:
color_combine = via_color_combine[unit][VIA_BLEND];
alpha_combine = via_alpha_combine[unit][VIA_PASSTHRU];
break;
case GL_RGBA:
case GL_LUMINANCE_ALPHA:
color_combine = via_color_combine[unit][VIA_BLEND];
alpha_combine = via_alpha_combine[unit][VIA_MODULATE];
break;
case GL_ALPHA:
color_combine = via_color_combine[unit][VIA_PASSTHRU];
alpha_combine = via_alpha_combine[unit][VIA_MODULATE];
break;
case GL_INTENSITY:
color_combine = via_color_combine[unit][VIA_BLEND];
alpha_combine = via_alpha_combine[unit][VIA_BLEND];
break;
case GL_COLOR_INDEX:
default:
return;
}
break;
case GL_ADD:
switch (format) {
case GL_RGB:
case GL_LUMINANCE:
color_combine = via_color_combine[unit][VIA_ADD];
alpha_combine = via_alpha_combine[unit][VIA_PASSTHRU];
break;
case GL_RGBA:
case GL_LUMINANCE_ALPHA:
color_combine = via_color_combine[unit][VIA_ADD];
alpha_combine = via_alpha_combine[unit][VIA_MODULATE];
break;
case GL_ALPHA:
color_combine = via_color_combine[unit][VIA_PASSTHRU];
alpha_combine = via_alpha_combine[unit][VIA_MODULATE];
break;
case GL_INTENSITY:
color_combine = via_color_combine[unit][VIA_ADD];
alpha_combine = via_alpha_combine[unit][VIA_ADD];
break;
case GL_COLOR_INDEX:
default:
return;
}
break;
default:
return;
}
#ifdef DEBUG
if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
#endif
}
static void viaUpdateTexUnit(GLcontext *ctx, GLuint unit)
{
viaContextPtr vmesa = VIA_CONTEXT(ctx);
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
#ifdef DEBUG
if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
#endif
if (texUnit->_ReallyEnabled) {
struct gl_texture_object *tObj = texUnit->_Current;
viaTextureObjectPtr t = (viaTextureObjectPtr)tObj->DriverData;
/* Upload teximages (not pipelined)
*/
if (t->dirtyImages) {
VIA_FIREVERTICES(vmesa);
viaSetTexImages(vmesa, tObj);
if (!t->bufAddr) {
FALLBACK(vmesa, VIA_FALLBACK_TEXTURE, GL_TRUE);
return;
}
}
if (tObj->Image[tObj->BaseLevel]->Border > 0) {
FALLBACK(vmesa, VIA_FALLBACK_TEXTURE, GL_TRUE);
return;
}
/* Update state if this is a different texture object to last
* time.
*/
if (vmesa->CurrentTexObj[unit] != t) {
VIA_STATECHANGE(vmesa, (VIA_UPLOAD_TEX0 << unit));
vmesa->CurrentTexObj[unit] = t;
viaUpdateTexLRU(vmesa, t); /* done too often */
}
/* Update texture environment if texture object image format or
* texture environment state has changed.
*/
if (tObj->Image[tObj->BaseLevel]->Format != vmesa->TexEnvImageFmt[unit]) {
vmesa->TexEnvImageFmt[unit] = tObj->Image[tObj->BaseLevel]->Format;
viaUpdateTexEnv(ctx, unit);
}
}
else {
vmesa->CurrentTexObj[unit] = 0;
vmesa->TexEnvImageFmt[unit] = 0;
vmesa->dirty &= ~(VIA_UPLOAD_TEX0 << unit);
VIA_STATECHANGE(vmesa, VIA_UPLOAD_CTX);
}
#ifdef DEBUG
if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
#endif
}
void viaUpdateTextureState(GLcontext *ctx)
{
viaContextPtr vmesa = VIA_CONTEXT(ctx);
#ifdef DEBUG
if (VIA_DEBUG) fprintf(stderr, "%s - in\n", __FUNCTION__);
#endif
FALLBACK(vmesa, VIA_FALLBACK_TEXTURE, GL_FALSE);
viaUpdateTexUnit(ctx, 0);
viaUpdateTexUnit(ctx, 1);
#ifdef DEBUG
if (VIA_DEBUG) fprintf(stderr, "%s - out\n", __FUNCTION__);
#endif
}
|