merge latest DRI sis driver changes from the DRI trunk
[mesa.git] / src / mesa / drivers / dri / sis / sis_texstate.c
1 /**************************************************************************
2
3 Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
4 Copyright 2003 Eric Anholt
5 All Rights Reserved.
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 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
16 Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27 /* $XFree86$ */
28
29 /*
30 * Authors:
31 * Sung-Ching Lin <sclin@sis.com.tw>
32 * Eric Anholt <anholt@FreeBSD.org>
33 */
34
35 #include "glheader.h"
36 #include "imports.h"
37 #include "context.h"
38 #include "macros.h"
39 #include "texformat.h"
40
41 #include "sis_context.h"
42 #include "sis_state.h"
43 #include "sis_tex.h"
44 #include "sis_tris.h"
45 #include "sis_alloc.h"
46
47 static GLint TransferTexturePitch (GLint dwPitch);
48
49 /* Handle texenv stuff, called from validate_texture (renderstart) */
50 static void
51 sis_set_texture_env0( GLcontext *ctx, struct gl_texture_object *texObj,
52 int unit )
53 {
54 sisContextPtr smesa = SIS_CONTEXT(ctx);
55
56 __GLSiSHardware *prev = &smesa->prev;
57 __GLSiSHardware *current = &smesa->current;
58
59 struct gl_texture_unit *texture_unit = &ctx->Texture.Unit[unit];
60
61 sisTexObjPtr t = texObj->DriverData;
62
63 switch (texture_unit->EnvMode)
64 {
65 case GL_REPLACE:
66 FALLBACK(smesa, SIS_FALLBACK_TEXENV0, 0);
67 switch (t->format)
68 {
69 case GL_ALPHA:
70 current->hwTexBlendColor0 = STAGE0_C_CF;
71 current->hwTexBlendAlpha0 = STAGE0_A_AS;
72 break;
73 case GL_LUMINANCE:
74 case GL_RGB:
75 current->hwTexBlendColor0 = STAGE0_C_CS;
76 current->hwTexBlendAlpha0 = STAGE0_A_AF;
77 break;
78 case GL_INTENSITY:
79 case GL_LUMINANCE_ALPHA:
80 case GL_RGBA:
81 current->hwTexBlendColor0 = STAGE0_C_CS;
82 current->hwTexBlendAlpha0 = STAGE0_A_AS;
83 break;
84 }
85 break;
86
87 case GL_MODULATE:
88 FALLBACK(smesa, SIS_FALLBACK_TEXENV0, 0);
89 switch (t->format)
90 {
91 case GL_ALPHA:
92 current->hwTexBlendColor0 = STAGE0_C_CF;
93 current->hwTexBlendAlpha0 = STAGE0_A_AFAS;
94 break;
95 case GL_LUMINANCE:
96 case GL_RGB:
97 current->hwTexBlendColor0 = STAGE0_C_CFCS;
98 current->hwTexBlendAlpha0 = STAGE0_A_AF;
99 break;
100 case GL_INTENSITY:
101 case GL_LUMINANCE_ALPHA:
102 case GL_RGBA:
103 current->hwTexBlendColor0 = STAGE0_C_CFCS;
104 current->hwTexBlendAlpha0 = STAGE0_A_AFAS;
105 break;
106 }
107 break;
108
109 case GL_DECAL:
110 FALLBACK(smesa, SIS_FALLBACK_TEXENV0, 0);
111 switch (t->format)
112 {
113 case GL_RGB:
114 current->hwTexBlendColor0 = STAGE0_C_CS;
115 current->hwTexBlendAlpha0 = STAGE0_A_AF;
116 break;
117 case GL_RGBA:
118 current->hwTexBlendColor0 = STAGE0_C_CFOMAS_CSAS;
119 current->hwTexBlendAlpha0 = STAGE0_A_AF;
120 break;
121 }
122 break;
123
124 case GL_BLEND:
125 FALLBACK(smesa, SIS_FALLBACK_TEXENV0, 1);
126 #if 0 /* XXX Blending broken */
127 current->hwTexEnvColor =
128 ((GLint) (texture_unit->EnvColor[3])) << 24 |
129 ((GLint) (texture_unit->EnvColor[0])) << 16 |
130 ((GLint) (texture_unit->EnvColor[1])) << 8 |
131 ((GLint) (texture_unit->EnvColor[2]));
132 switch (t->format)
133 {
134 case GL_ALPHA:
135 current->hwTexBlendColor0 = STAGE0_C_CF;
136 current->hwTexBlendAlpha0 = STAGE0_A_AFAS;
137 break;
138 case GL_LUMINANCE:
139 case GL_RGB:
140 current->hwTexBlendColor0 = STAGE0_C_CFOMCS_CCCS;
141 current->hwTexBlendAlpha0 = STAGE0_A_AF;
142 break;
143 case GL_INTENSITY:
144 current->hwTexBlendColor0 = STAGE0_C_CFOMCS_CCCS;
145 current->hwTexBlendAlpha0 = STAGE0_A_AFOMAS_ACAS;
146 break;
147 case GL_LUMINANCE_ALPHA:
148 case GL_RGBA:
149 current->hwTexBlendColor0 = STAGE0_C_CFOMCS_CCCS;
150 current->hwTexBlendAlpha0 = STAGE0_A_AFAS;
151 break;
152 }
153 break;
154 #endif
155 }
156
157 if ((current->hwTexBlendColor0 != prev->hwTexBlendColor0) ||
158 (current->hwTexBlendAlpha0 != prev->hwTexBlendAlpha0) ||
159 (current->hwTexEnvColor != prev->hwTexEnvColor))
160 {
161 prev->hwTexEnvColor = current->hwTexEnvColor;
162 prev->hwTexBlendColor0 = current->hwTexBlendColor0;
163 prev->hwTexBlendAlpha0 = current->hwTexBlendAlpha0;
164 smesa->GlobalFlag |= GFLAG_TEXTUREENV;
165 }
166 }
167
168 /* Handle texenv stuff, called from validate_texture (renderstart) */
169 static void
170 sis_set_texture_env1( GLcontext *ctx, struct gl_texture_object *texObj,
171 int unit)
172 {
173 sisContextPtr smesa = SIS_CONTEXT(ctx);
174
175 __GLSiSHardware *prev = &smesa->prev;
176 __GLSiSHardware *current = &smesa->current;
177
178 struct gl_texture_unit *texture_unit = &ctx->Texture.Unit[unit];
179
180 sisTexObjPtr t = texObj->DriverData;
181
182 switch (texture_unit->EnvMode)
183 {
184 case GL_REPLACE:
185 FALLBACK(smesa, SIS_FALLBACK_TEXENV1, 0);
186 switch (t->format)
187 {
188 case GL_ALPHA:
189 current->hwTexBlendColor1 = STAGE1_C_CF;
190 current->hwTexBlendAlpha1 = STAGE1_A_AS;
191 break;
192 case GL_LUMINANCE:
193 case GL_RGB:
194 current->hwTexBlendColor1 = STAGE1_C_CS;
195 current->hwTexBlendAlpha1 = STAGE1_A_AF;
196 break;
197 case GL_INTENSITY:
198 case GL_LUMINANCE_ALPHA:
199 case GL_RGBA:
200 current->hwTexBlendColor1 = STAGE1_C_CS;
201 current->hwTexBlendAlpha1 = STAGE1_A_AS;
202 break;
203 }
204 break;
205
206 case GL_MODULATE:
207 FALLBACK(smesa, SIS_FALLBACK_TEXENV1, 0);
208 switch (t->format)
209 {
210 case GL_ALPHA:
211 current->hwTexBlendColor1 = STAGE1_C_CF;
212 current->hwTexBlendAlpha1 = STAGE1_A_AFAS;
213 break;
214 case GL_LUMINANCE:
215 case GL_RGB:
216 current->hwTexBlendColor1 = STAGE1_C_CFCS;
217 current->hwTexBlendAlpha1 = STAGE1_A_AF;
218 break;
219 case GL_INTENSITY:
220 case GL_LUMINANCE_ALPHA:
221 case GL_RGBA:
222 current->hwTexBlendColor1 = STAGE1_C_CFCS;
223 current->hwTexBlendAlpha1 = STAGE1_A_AFAS;
224 break;
225 }
226 break;
227
228 case GL_DECAL:
229 FALLBACK(smesa, SIS_FALLBACK_TEXENV1, 0);
230 switch (t->format)
231 {
232 case GL_RGB:
233 current->hwTexBlendColor1 = STAGE1_C_CS;
234 current->hwTexBlendAlpha1 = STAGE1_A_AF;
235 break;
236 case GL_RGBA:
237 current->hwTexBlendColor1 = STAGE1_C_CFOMAS_CSAS;
238 current->hwTexBlendAlpha1 = STAGE1_A_AF;
239 break;
240 }
241 break;
242
243 case GL_BLEND:
244 FALLBACK(smesa, SIS_FALLBACK_TEXENV1, 1);
245 #if 0 /* XXX Blending broken */
246 current->hwTexEnvColor =
247 ((GLint) (texture_unit->EnvColor[3])) << 24 |
248 ((GLint) (texture_unit->EnvColor[0])) << 16 |
249 ((GLint) (texture_unit->EnvColor[1])) << 8 |
250 ((GLint) (texture_unit->EnvColor[2]));
251 switch (t->format)
252 {
253 case GL_ALPHA:
254 current->hwTexBlendColor1 = STAGE1_C_CF;
255 current->hwTexBlendAlpha1 = STAGE1_A_AFAS;
256 break;
257 case GL_LUMINANCE:
258 case GL_RGB:
259 current->hwTexBlendColor1 = STAGE1_C_CFOMCS_CCCS;
260 current->hwTexBlendAlpha1 = STAGE1_A_AF;
261 break;
262 case GL_INTENSITY:
263 current->hwTexBlendColor1 = STAGE1_C_CFOMCS_CCCS;
264 current->hwTexBlendAlpha1 = STAGE1_A_AFOMAS_ACAS;
265 break;
266 case GL_LUMINANCE_ALPHA:
267 case GL_RGBA:
268 current->hwTexBlendColor1 = STAGE1_C_CFOMCS_CCCS;
269 current->hwTexBlendAlpha1 = STAGE1_A_AFAS;
270 break;
271 }
272 break;
273 #endif
274 }
275
276 if ((current->hwTexBlendColor1 != prev->hwTexBlendColor1) ||
277 (current->hwTexBlendAlpha1 != prev->hwTexBlendAlpha1) ||
278 (current->hwTexEnvColor != prev->hwTexEnvColor))
279 {
280 prev->hwTexBlendColor1 = current->hwTexBlendColor1;
281 prev->hwTexBlendAlpha1 = current->hwTexBlendAlpha1;
282 prev->hwTexEnvColor = current->hwTexEnvColor;
283 smesa->GlobalFlag |= GFLAG_TEXTUREENV_1;
284 }
285 }
286
287 /* Returns 0 if a software fallback is necessary */
288 static GLboolean
289 sis_set_texobj_parm( GLcontext *ctx, struct gl_texture_object *texObj,
290 int hw_unit )
291 {
292 sisContextPtr smesa = SIS_CONTEXT(ctx);
293 int ok = 1;
294
295 __GLSiSHardware *prev = &smesa->prev;
296 __GLSiSHardware *current = &smesa->current;
297
298 sisTexObjPtr t = texObj->DriverData;
299
300 GLint firstLevel, lastLevel;
301 GLint i;
302
303 current->texture[hw_unit].hwTextureMip = 0UL;
304 current->texture[hw_unit].hwTextureSet = t->hwformat;
305
306 if ((texObj->MinFilter == GL_NEAREST) || (texObj->MinFilter == GL_LINEAR)) {
307 firstLevel = lastLevel = texObj->BaseLevel;
308 } else {
309 /* Compute which mipmap levels we really want to send to the hardware.
310 * This depends on the base image size, GL_TEXTURE_MIN_LOD,
311 * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL and GL_TEXTURE_MAX_LEVEL.
312 * Yes, this looks overly complicated, but it's all needed.
313 */
314
315 firstLevel = texObj->BaseLevel + (GLint)(texObj->MinLod + 0.5);
316 firstLevel = MAX2(firstLevel, texObj->BaseLevel);
317 lastLevel = texObj->BaseLevel + (GLint)(texObj->MaxLod + 0.5);
318 lastLevel = MAX2(lastLevel, texObj->BaseLevel);
319 lastLevel = MIN2(lastLevel, texObj->BaseLevel +
320 texObj->Image[texObj->BaseLevel]->MaxLog2);
321 lastLevel = MIN2(lastLevel, texObj->MaxLevel);
322 lastLevel = MAX2(firstLevel, lastLevel); /* need at least one level */
323 }
324
325 current->texture[hw_unit].hwTextureSet |= (lastLevel << 8);
326
327 switch (texObj->MagFilter)
328 {
329 case GL_NEAREST:
330 current->texture[hw_unit].hwTextureMip |= TEXTURE_FILTER_NEAREST;
331 break;
332 case GL_LINEAR:
333 current->texture[hw_unit].hwTextureMip |= (TEXTURE_FILTER_LINEAR << 3);
334 break;
335 }
336
337 {
338 GLint b;
339
340 /* The mipmap lod biasing is based on experiment. It seems there's a
341 * limit of around +4/-4 to the bias value; we're being conservative.
342 */
343 b = (GLint) (ctx->Texture.Unit[hw_unit].LodBias * 32.0);
344 if (b > 127)
345 b = 127;
346 else if (b < -128)
347 b = -128;
348
349 current->texture[hw_unit].hwTextureMip |= ((b << 4) &
350 MASK_TextureMipmapLodBias);
351 }
352
353 switch (texObj->MinFilter)
354 {
355 case GL_NEAREST:
356 current->texture[hw_unit].hwTextureMip |= TEXTURE_FILTER_NEAREST;
357 break;
358 case GL_LINEAR:
359 current->texture[hw_unit].hwTextureMip |= TEXTURE_FILTER_LINEAR;
360 break;
361 case GL_NEAREST_MIPMAP_NEAREST:
362 current->texture[hw_unit].hwTextureMip |=
363 TEXTURE_FILTER_NEAREST_MIP_NEAREST;
364 break;
365 case GL_NEAREST_MIPMAP_LINEAR:
366 current->texture[hw_unit].hwTextureMip |=
367 TEXTURE_FILTER_NEAREST_MIP_LINEAR;
368 break;
369 case GL_LINEAR_MIPMAP_NEAREST:
370 current->texture[hw_unit].hwTextureMip |=
371 TEXTURE_FILTER_LINEAR_MIP_NEAREST;
372 break;
373 case GL_LINEAR_MIPMAP_LINEAR:
374 current->texture[hw_unit].hwTextureMip |=
375 TEXTURE_FILTER_LINEAR_MIP_LINEAR;
376 break;
377 }
378
379 switch (texObj->WrapS)
380 {
381 case GL_REPEAT:
382 current->texture[hw_unit].hwTextureSet |= MASK_TextureWrapU;
383 break;
384 case GL_CLAMP:
385 current->texture[hw_unit].hwTextureSet |= MASK_TextureClampU;
386 break;
387 case GL_CLAMP_TO_EDGE:
388 /*
389 * ?? not support yet
390 */
391 ok = 0;
392 break;
393 }
394
395 switch (texObj->WrapT)
396 {
397 case GL_REPEAT:
398 current->texture[hw_unit].hwTextureSet |= MASK_TextureWrapV;
399 break;
400 case GL_CLAMP:
401 current->texture[hw_unit].hwTextureSet |= MASK_TextureClampV;
402 break;
403 case GL_CLAMP_TO_EDGE:
404 /*
405 * ?? not support yet
406 */
407 ok = 0;
408 break;
409 }
410
411 /*
412 if (current->texture[hw_unit].hwTextureSet & MASK_TextureClampU) {
413 current->texture[hw_unit].hwTextureSet &= ~MASK_TextureClampU;
414 current->texture[hw_unit].hwTextureSet |= MASK_TextureBorderU;
415 }
416
417 if (current->texture[hw_unit].hwTextureSet & MASK_TextureClampV) {
418 current->texture[hw_unit].hwTextureSet &= ~MASK_TextureClampV;
419 current->texture[hw_unit].hwTextureSet |= MASK_TextureBorderV;
420 }
421 */
422 current->texture[hw_unit].hwTextureBorderColor =
423 ((GLuint) texObj->BorderColor[3] << 24) +
424 ((GLuint) texObj->BorderColor[0] << 16) +
425 ((GLuint) texObj->BorderColor[1] << 8) +
426 ((GLuint) texObj->BorderColor[2]);
427
428 if (current->texture[hw_unit].hwTextureBorderColor !=
429 prev->texture[hw_unit].hwTextureBorderColor)
430 {
431 prev->texture[hw_unit].hwTextureBorderColor =
432 current->texture[hw_unit].hwTextureBorderColor;
433 if (hw_unit == 1)
434 smesa->GlobalFlag |= GFLAG_TEXBORDERCOLOR_1;
435 else
436 smesa->GlobalFlag |= GFLAG_TEXBORDERCOLOR;
437 }
438
439 current->texture[hw_unit].hwTextureSet |=
440 texObj->Image[firstLevel]->WidthLog2 << 4;
441 current->texture[hw_unit].hwTextureSet |=
442 texObj->Image[firstLevel]->HeightLog2;
443
444 if (hw_unit == 0)
445 smesa->GlobalFlag |= GFLAG_TEXTUREADDRESS;
446 else
447 smesa->GlobalFlag |= GFLAG_TEXTUREADDRESS_1;
448
449 for (i = firstLevel; i <= lastLevel; i++)
450 {
451 GLuint texOffset = 0;
452 GLuint texPitch = TransferTexturePitch( t->image[i].pitch );
453
454 switch (t->image[i].memType)
455 {
456 case VIDEO_TYPE:
457 texOffset = ((unsigned long)t->image[i].Data - (unsigned long)smesa->FbBase);
458 break;
459 case AGP_TYPE:
460 texOffset = ((unsigned long)t->image[i].Data - (unsigned long)smesa->AGPBase) +
461 (unsigned long) smesa->AGPAddr;
462 current->texture[hw_unit].hwTextureMip |=
463 (MASK_TextureLevel0InSystem << i);
464 break;
465 }
466
467 switch (i)
468 {
469 case 0:
470 prev->texture[hw_unit].texOffset0 = texOffset;
471 prev->texture[hw_unit].texPitch01 = texPitch << 16;
472 break;
473 case 1:
474 prev->texture[hw_unit].texOffset1 = texOffset;
475 prev->texture[hw_unit].texPitch01 |= texPitch;
476 break;
477 case 2:
478 prev->texture[hw_unit].texOffset2 = texOffset;
479 prev->texture[hw_unit].texPitch23 = texPitch << 16;
480 break;
481 case 3:
482 prev->texture[hw_unit].texOffset3 = texOffset;
483 prev->texture[hw_unit].texPitch23 |= texPitch;
484 break;
485 case 4:
486 prev->texture[hw_unit].texOffset4 = texOffset;
487 prev->texture[hw_unit].texPitch45 = texPitch << 16;
488 break;
489 case 5:
490 prev->texture[hw_unit].texOffset5 = texOffset;
491 prev->texture[hw_unit].texPitch45 |= texPitch;
492 break;
493 case 6:
494 prev->texture[hw_unit].texOffset6 = texOffset;
495 prev->texture[hw_unit].texPitch67 = texPitch << 16;
496 break;
497 case 7:
498 prev->texture[hw_unit].texOffset7 = texOffset;
499 prev->texture[hw_unit].texPitch67 |= texPitch;
500 break;
501 case 8:
502 prev->texture[hw_unit].texOffset8 = texOffset;
503 prev->texture[hw_unit].texPitch89 = texPitch << 16;
504 break;
505 case 9:
506 prev->texture[hw_unit].texOffset9 = texOffset;
507 prev->texture[hw_unit].texPitch89 |= texPitch;
508 break;
509 case 10:
510 prev->texture[hw_unit].texOffset10 = texOffset;
511 prev->texture[hw_unit].texPitch10 = texPitch << 16;
512 break;
513 case 11:
514 prev->texture[hw_unit].texOffset11 = texOffset;
515 prev->texture[hw_unit].texPitch10 |= texPitch;
516 break;
517 }
518 }
519
520 if (current->texture[hw_unit].hwTextureSet !=
521 prev->texture[hw_unit].hwTextureSet)
522 {
523 prev->texture[hw_unit].hwTextureSet =
524 current->texture[hw_unit].hwTextureSet;
525 if (hw_unit == 1)
526 smesa->GlobalFlag |= CFLAG_TEXTURERESET_1;
527 else
528 smesa->GlobalFlag |= CFLAG_TEXTURERESET;
529 }
530 if (current->texture[hw_unit].hwTextureMip !=
531 prev->texture[hw_unit].hwTextureMip)
532 {
533 prev->texture[hw_unit].hwTextureMip =
534 current->texture[hw_unit].hwTextureMip;
535 if (hw_unit == 1)
536 smesa->GlobalFlag |= GFLAG_TEXTUREMIPMAP_1;
537 else
538 smesa->GlobalFlag |= GFLAG_TEXTUREMIPMAP;
539 }
540
541 return ok;
542 }
543
544 /* Disable a texture unit, called from validate_texture */
545 static void
546 sis_reset_texture_env (GLcontext *ctx, int hw_unit)
547 {
548 sisContextPtr smesa = SIS_CONTEXT(ctx);
549
550 __GLSiSHardware *prev = &smesa->prev;
551 __GLSiSHardware *current = &smesa->current;
552
553 if (hw_unit == 1)
554 {
555 current->hwTexBlendColor1 = STAGE1_C_CF;
556 current->hwTexBlendAlpha1 = STAGE1_A_AF;
557
558 if ((current->hwTexBlendColor1 != prev->hwTexBlendColor1) ||
559 (current->hwTexBlendAlpha1 != prev->hwTexBlendAlpha1) ||
560 (current->hwTexEnvColor != prev->hwTexEnvColor))
561 {
562 prev->hwTexBlendColor1 = current->hwTexBlendColor1;
563 prev->hwTexBlendAlpha1 = current->hwTexBlendAlpha1;
564 prev->hwTexEnvColor = current->hwTexEnvColor;
565 smesa->GlobalFlag |= GFLAG_TEXTUREENV_1;
566 }
567 } else {
568 current->hwTexBlendColor0 = STAGE0_C_CF;
569 current->hwTexBlendAlpha0 = STAGE0_A_AF;
570
571 if ((current->hwTexBlendColor0 != prev->hwTexBlendColor0) ||
572 (current->hwTexBlendAlpha0 != prev->hwTexBlendAlpha0) ||
573 (current->hwTexEnvColor != prev->hwTexEnvColor))
574 {
575 prev->hwTexBlendColor0 = current->hwTexBlendColor0;
576 prev->hwTexBlendAlpha0 = current->hwTexBlendAlpha0;
577 prev->hwTexEnvColor = current->hwTexEnvColor;
578 smesa->GlobalFlag |= GFLAG_TEXTUREENV;
579 }
580 }
581 }
582
583 static void updateTextureUnit( GLcontext *ctx, int unit )
584 {
585 sisContextPtr smesa = SIS_CONTEXT( ctx );
586 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
587 struct gl_texture_object *texObj = texUnit->_Current;
588 GLint fallbackbit;
589
590 if (unit == 0)
591 fallbackbit = SIS_FALLBACK_TEXTURE0;
592 else
593 fallbackbit = SIS_FALLBACK_TEXTURE1;
594
595 if (texUnit->_ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) {
596 if (smesa->TexStates[unit] & NEW_TEXTURING) {
597 GLboolean ok;
598
599 ok = sis_set_texobj_parm (ctx, texObj, unit);
600 FALLBACK( smesa, fallbackbit, !ok );
601 }
602 if (smesa->TexStates[unit] & NEW_TEXTURE_ENV) {
603 if (unit == 0)
604 sis_set_texture_env0( ctx, texObj, unit );
605 else
606 sis_set_texture_env1( ctx, texObj, unit );
607 }
608 smesa->TexStates[unit] = 0;
609 } else if ( texUnit->_ReallyEnabled ) {
610 /* fallback */
611 FALLBACK( smesa, fallbackbit, 1 );
612 } else {
613 sis_reset_texture_env( ctx, unit );
614 FALLBACK( smesa, fallbackbit, 0 );
615 }
616 }
617
618
619 void sisUpdateTextureState( GLcontext *ctx )
620 {
621 sisContextPtr smesa = SIS_CONTEXT( ctx );
622 int i;
623 __GLSiSHardware *current = &smesa->current;
624
625 #if 1
626 /* TODO : if unmark these, error in multitexture */ /* XXX */
627 for (i = 0; i < SIS_MAX_TEXTURES; i++)
628 smesa->TexStates[i] |= (NEW_TEXTURING | NEW_TEXTURE_ENV);
629 #endif
630
631 updateTextureUnit( ctx, 0 );
632 updateTextureUnit( ctx, 1 );
633
634 /* XXX Issues with the 2nd unit but not the first being enabled? */
635 if ( ctx->Texture.Unit[0]._ReallyEnabled &
636 (TEXTURE_1D_BIT | TEXTURE_2D_BIT) ||
637 ctx->Texture.Unit[1]._ReallyEnabled &
638 (TEXTURE_1D_BIT | TEXTURE_2D_BIT) )
639 {
640 current->hwCapEnable |= MASK_TextureEnable;
641 current->hwCapEnable &= ~MASK_TextureNumUsed;
642 if (ctx->Texture.Unit[1]._ReallyEnabled)
643 current->hwCapEnable |= 0x00002000;
644 else
645 current->hwCapEnable |= 0x00001000;
646 } else {
647 current->hwCapEnable &= ~MASK_TextureEnable;
648 }
649 }
650
651 static GLint
652 BitScanForward( GLshort w )
653 {
654 GLint i;
655
656 for (i = 0; i < 16; i++) {
657 if (w & (1 << i))
658 break;
659 }
660 return i;
661 }
662
663 static GLint
664 TransferTexturePitch( GLint dwPitch )
665 {
666 GLint dwRet, i;
667
668 i = BitScanForward( (GLshort)dwPitch );
669 dwRet = dwPitch >> i;
670 dwRet |= i << 9;
671 return dwRet;
672 }