Bug #4615: Fix the SiS driver for the renderbuffer changes. Previously, all
[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 #if 1 /* XXX Blending broken */
126 FALLBACK(smesa, SIS_FALLBACK_TEXENV0, 1);
127 #else
128 FALLBACK(smesa, SIS_FALLBACK_TEXENV0, 0);
129 current->hwTexEnvColor =
130 ((GLint) (texture_unit->EnvColor[3])) << 24 |
131 ((GLint) (texture_unit->EnvColor[0])) << 16 |
132 ((GLint) (texture_unit->EnvColor[1])) << 8 |
133 ((GLint) (texture_unit->EnvColor[2]));
134 switch (t->format)
135 {
136 case GL_ALPHA:
137 current->hwTexBlendColor0 = STAGE0_C_CF;
138 current->hwTexBlendAlpha0 = STAGE0_A_AFAS;
139 break;
140 case GL_LUMINANCE:
141 case GL_RGB:
142 current->hwTexBlendColor0 = STAGE0_C_CFOMCS_CCCS;
143 current->hwTexBlendAlpha0 = STAGE0_A_AF;
144 break;
145 case GL_INTENSITY:
146 current->hwTexBlendColor0 = STAGE0_C_CFOMCS_CCCS;
147 current->hwTexBlendAlpha0 = STAGE0_A_AFOMAS_ACAS;
148 break;
149 case GL_LUMINANCE_ALPHA:
150 case GL_RGBA:
151 current->hwTexBlendColor0 = STAGE0_C_CFOMCS_CCCS;
152 current->hwTexBlendAlpha0 = STAGE0_A_AFAS;
153 break;
154 }
155 break;
156 #endif
157 }
158
159 if ((current->hwTexBlendColor0 != prev->hwTexBlendColor0) ||
160 (current->hwTexBlendAlpha0 != prev->hwTexBlendAlpha0) ||
161 (current->hwTexEnvColor != prev->hwTexEnvColor))
162 {
163 prev->hwTexEnvColor = current->hwTexEnvColor;
164 prev->hwTexBlendColor0 = current->hwTexBlendColor0;
165 prev->hwTexBlendAlpha0 = current->hwTexBlendAlpha0;
166 smesa->GlobalFlag |= GFLAG_TEXTUREENV;
167 }
168 }
169
170 /* Handle texenv stuff, called from validate_texture (renderstart) */
171 static void
172 sis_set_texture_env1( GLcontext *ctx, struct gl_texture_object *texObj,
173 int unit)
174 {
175 sisContextPtr smesa = SIS_CONTEXT(ctx);
176
177 __GLSiSHardware *prev = &smesa->prev;
178 __GLSiSHardware *current = &smesa->current;
179
180 struct gl_texture_unit *texture_unit = &ctx->Texture.Unit[unit];
181
182 sisTexObjPtr t = texObj->DriverData;
183
184 switch (texture_unit->EnvMode)
185 {
186 case GL_REPLACE:
187 FALLBACK(smesa, SIS_FALLBACK_TEXENV1, 0);
188 switch (t->format)
189 {
190 case GL_ALPHA:
191 current->hwTexBlendColor1 = STAGE1_C_CF;
192 current->hwTexBlendAlpha1 = STAGE1_A_AS;
193 break;
194 case GL_LUMINANCE:
195 case GL_RGB:
196 current->hwTexBlendColor1 = STAGE1_C_CS;
197 current->hwTexBlendAlpha1 = STAGE1_A_AF;
198 break;
199 case GL_INTENSITY:
200 case GL_LUMINANCE_ALPHA:
201 case GL_RGBA:
202 current->hwTexBlendColor1 = STAGE1_C_CS;
203 current->hwTexBlendAlpha1 = STAGE1_A_AS;
204 break;
205 }
206 break;
207
208 case GL_MODULATE:
209 FALLBACK(smesa, SIS_FALLBACK_TEXENV1, 0);
210 switch (t->format)
211 {
212 case GL_ALPHA:
213 current->hwTexBlendColor1 = STAGE1_C_CF;
214 current->hwTexBlendAlpha1 = STAGE1_A_AFAS;
215 break;
216 case GL_LUMINANCE:
217 case GL_RGB:
218 current->hwTexBlendColor1 = STAGE1_C_CFCS;
219 current->hwTexBlendAlpha1 = STAGE1_A_AF;
220 break;
221 case GL_INTENSITY:
222 case GL_LUMINANCE_ALPHA:
223 case GL_RGBA:
224 current->hwTexBlendColor1 = STAGE1_C_CFCS;
225 current->hwTexBlendAlpha1 = STAGE1_A_AFAS;
226 break;
227 }
228 break;
229
230 case GL_DECAL:
231 FALLBACK(smesa, SIS_FALLBACK_TEXENV1, 0);
232 switch (t->format)
233 {
234 case GL_RGB:
235 current->hwTexBlendColor1 = STAGE1_C_CS;
236 current->hwTexBlendAlpha1 = STAGE1_A_AF;
237 break;
238 case GL_RGBA:
239 current->hwTexBlendColor1 = STAGE1_C_CFOMAS_CSAS;
240 current->hwTexBlendAlpha1 = STAGE1_A_AF;
241 break;
242 }
243 break;
244
245 case GL_BLEND:
246 FALLBACK(smesa, SIS_FALLBACK_TEXENV1, 1);
247 #if 0 /* XXX Blending broken */
248 current->hwTexEnvColor =
249 ((GLint) (texture_unit->EnvColor[3])) << 24 |
250 ((GLint) (texture_unit->EnvColor[0])) << 16 |
251 ((GLint) (texture_unit->EnvColor[1])) << 8 |
252 ((GLint) (texture_unit->EnvColor[2]));
253 switch (t->format)
254 {
255 case GL_ALPHA:
256 current->hwTexBlendColor1 = STAGE1_C_CF;
257 current->hwTexBlendAlpha1 = STAGE1_A_AFAS;
258 break;
259 case GL_LUMINANCE:
260 case GL_RGB:
261 current->hwTexBlendColor1 = STAGE1_C_CFOMCS_CCCS;
262 current->hwTexBlendAlpha1 = STAGE1_A_AF;
263 break;
264 case GL_INTENSITY:
265 current->hwTexBlendColor1 = STAGE1_C_CFOMCS_CCCS;
266 current->hwTexBlendAlpha1 = STAGE1_A_AFOMAS_ACAS;
267 break;
268 case GL_LUMINANCE_ALPHA:
269 case GL_RGBA:
270 current->hwTexBlendColor1 = STAGE1_C_CFOMCS_CCCS;
271 current->hwTexBlendAlpha1 = STAGE1_A_AFAS;
272 break;
273 }
274 break;
275 #endif
276 }
277
278 if ((current->hwTexBlendColor1 != prev->hwTexBlendColor1) ||
279 (current->hwTexBlendAlpha1 != prev->hwTexBlendAlpha1) ||
280 (current->hwTexEnvColor != prev->hwTexEnvColor))
281 {
282 prev->hwTexBlendColor1 = current->hwTexBlendColor1;
283 prev->hwTexBlendAlpha1 = current->hwTexBlendAlpha1;
284 prev->hwTexEnvColor = current->hwTexEnvColor;
285 smesa->GlobalFlag |= GFLAG_TEXTUREENV_1;
286 }
287 }
288
289 /* Returns 0 if a software fallback is necessary */
290 static GLboolean
291 sis_set_texobj_parm( GLcontext *ctx, struct gl_texture_object *texObj,
292 int hw_unit )
293 {
294 sisContextPtr smesa = SIS_CONTEXT(ctx);
295 int ok = 1;
296
297 __GLSiSHardware *prev = &smesa->prev;
298 __GLSiSHardware *current = &smesa->current;
299
300 sisTexObjPtr t = texObj->DriverData;
301
302 GLint firstLevel, lastLevel;
303 GLint i;
304
305 current->texture[hw_unit].hwTextureMip = 0UL;
306 current->texture[hw_unit].hwTextureSet = t->hwformat;
307
308 if ((texObj->MinFilter == GL_NEAREST) || (texObj->MinFilter == GL_LINEAR)) {
309 firstLevel = lastLevel = texObj->BaseLevel;
310 } else {
311 /* Compute which mipmap levels we really want to send to the hardware.
312 * This depends on the base image size, GL_TEXTURE_MIN_LOD,
313 * GL_TEXTURE_MAX_LOD, GL_TEXTURE_BASE_LEVEL and GL_TEXTURE_MAX_LEVEL.
314 * Yes, this looks overly complicated, but it's all needed.
315 */
316
317 firstLevel = texObj->BaseLevel + (GLint)(texObj->MinLod + 0.5);
318 firstLevel = MAX2(firstLevel, texObj->BaseLevel);
319 lastLevel = texObj->BaseLevel + (GLint)(texObj->MaxLod + 0.5);
320 lastLevel = MAX2(lastLevel, texObj->BaseLevel);
321 lastLevel = MIN2(lastLevel, texObj->BaseLevel +
322 texObj->Image[0][texObj->BaseLevel]->MaxLog2);
323 lastLevel = MIN2(lastLevel, texObj->MaxLevel);
324 lastLevel = MAX2(firstLevel, lastLevel); /* need at least one level */
325 }
326
327 current->texture[hw_unit].hwTextureSet |= (lastLevel << 8);
328
329 switch (texObj->MagFilter)
330 {
331 case GL_NEAREST:
332 current->texture[hw_unit].hwTextureMip |= TEXTURE_FILTER_NEAREST;
333 break;
334 case GL_LINEAR:
335 current->texture[hw_unit].hwTextureMip |= (TEXTURE_FILTER_LINEAR << 3);
336 break;
337 }
338
339 {
340 GLint b;
341
342 /* The mipmap lod biasing is based on experiment. It seems there's a
343 * limit of around +4/-4 to the bias value; we're being conservative.
344 */
345 b = (GLint) (ctx->Texture.Unit[hw_unit].LodBias * 32.0);
346 if (b > 127)
347 b = 127;
348 else if (b < -128)
349 b = -128;
350
351 current->texture[hw_unit].hwTextureMip |= ((b << 4) &
352 MASK_TextureMipmapLodBias);
353 }
354
355 switch (texObj->MinFilter)
356 {
357 case GL_NEAREST:
358 current->texture[hw_unit].hwTextureMip |= TEXTURE_FILTER_NEAREST;
359 break;
360 case GL_LINEAR:
361 current->texture[hw_unit].hwTextureMip |= TEXTURE_FILTER_LINEAR;
362 break;
363 case GL_NEAREST_MIPMAP_NEAREST:
364 current->texture[hw_unit].hwTextureMip |=
365 TEXTURE_FILTER_NEAREST_MIP_NEAREST;
366 break;
367 case GL_NEAREST_MIPMAP_LINEAR:
368 current->texture[hw_unit].hwTextureMip |=
369 TEXTURE_FILTER_NEAREST_MIP_LINEAR;
370 break;
371 case GL_LINEAR_MIPMAP_NEAREST:
372 current->texture[hw_unit].hwTextureMip |=
373 TEXTURE_FILTER_LINEAR_MIP_NEAREST;
374 break;
375 case GL_LINEAR_MIPMAP_LINEAR:
376 current->texture[hw_unit].hwTextureMip |=
377 TEXTURE_FILTER_LINEAR_MIP_LINEAR;
378 break;
379 }
380
381 switch (texObj->WrapS)
382 {
383 case GL_REPEAT:
384 current->texture[hw_unit].hwTextureSet |= MASK_TextureWrapU;
385 break;
386 case GL_CLAMP:
387 current->texture[hw_unit].hwTextureSet |= MASK_TextureClampU;
388 break;
389 case GL_CLAMP_TO_EDGE:
390 /*
391 * ?? not support yet
392 */
393 ok = 0;
394 break;
395 }
396
397 switch (texObj->WrapT)
398 {
399 case GL_REPEAT:
400 current->texture[hw_unit].hwTextureSet |= MASK_TextureWrapV;
401 break;
402 case GL_CLAMP:
403 current->texture[hw_unit].hwTextureSet |= MASK_TextureClampV;
404 break;
405 case GL_CLAMP_TO_EDGE:
406 /*
407 * ?? not support yet
408 */
409 ok = 0;
410 break;
411 }
412
413 /*
414 if (current->texture[hw_unit].hwTextureSet & MASK_TextureClampU) {
415 current->texture[hw_unit].hwTextureSet &= ~MASK_TextureClampU;
416 current->texture[hw_unit].hwTextureSet |= MASK_TextureBorderU;
417 }
418
419 if (current->texture[hw_unit].hwTextureSet & MASK_TextureClampV) {
420 current->texture[hw_unit].hwTextureSet &= ~MASK_TextureClampV;
421 current->texture[hw_unit].hwTextureSet |= MASK_TextureBorderV;
422 }
423 */
424 current->texture[hw_unit].hwTextureBorderColor =
425 ((GLuint) texObj->BorderColor[3] << 24) +
426 ((GLuint) texObj->BorderColor[0] << 16) +
427 ((GLuint) texObj->BorderColor[1] << 8) +
428 ((GLuint) texObj->BorderColor[2]);
429
430 if (current->texture[hw_unit].hwTextureBorderColor !=
431 prev->texture[hw_unit].hwTextureBorderColor)
432 {
433 prev->texture[hw_unit].hwTextureBorderColor =
434 current->texture[hw_unit].hwTextureBorderColor;
435 if (hw_unit == 1)
436 smesa->GlobalFlag |= GFLAG_TEXBORDERCOLOR_1;
437 else
438 smesa->GlobalFlag |= GFLAG_TEXBORDERCOLOR;
439 }
440
441 current->texture[hw_unit].hwTextureSet |=
442 texObj->Image[0][firstLevel]->WidthLog2 << 4;
443 current->texture[hw_unit].hwTextureSet |=
444 texObj->Image[0][firstLevel]->HeightLog2;
445
446 if (hw_unit == 0)
447 smesa->GlobalFlag |= GFLAG_TEXTUREADDRESS;
448 else
449 smesa->GlobalFlag |= GFLAG_TEXTUREADDRESS_1;
450
451 for (i = firstLevel; i <= lastLevel; i++)
452 {
453 GLuint texOffset = 0;
454 GLuint texPitch = TransferTexturePitch( t->image[i].pitch );
455
456 switch (t->image[i].memType)
457 {
458 case VIDEO_TYPE:
459 texOffset = ((unsigned long)t->image[i].Data - (unsigned long)smesa->FbBase);
460 break;
461 case AGP_TYPE:
462 texOffset = ((unsigned long)t->image[i].Data - (unsigned long)smesa->AGPBase) +
463 (unsigned long) smesa->AGPAddr;
464 current->texture[hw_unit].hwTextureMip |=
465 (MASK_TextureLevel0InSystem << i);
466 break;
467 }
468
469 switch (i)
470 {
471 case 0:
472 prev->texture[hw_unit].texOffset0 = texOffset;
473 prev->texture[hw_unit].texPitch01 = texPitch << 16;
474 break;
475 case 1:
476 prev->texture[hw_unit].texOffset1 = texOffset;
477 prev->texture[hw_unit].texPitch01 |= texPitch;
478 break;
479 case 2:
480 prev->texture[hw_unit].texOffset2 = texOffset;
481 prev->texture[hw_unit].texPitch23 = texPitch << 16;
482 break;
483 case 3:
484 prev->texture[hw_unit].texOffset3 = texOffset;
485 prev->texture[hw_unit].texPitch23 |= texPitch;
486 break;
487 case 4:
488 prev->texture[hw_unit].texOffset4 = texOffset;
489 prev->texture[hw_unit].texPitch45 = texPitch << 16;
490 break;
491 case 5:
492 prev->texture[hw_unit].texOffset5 = texOffset;
493 prev->texture[hw_unit].texPitch45 |= texPitch;
494 break;
495 case 6:
496 prev->texture[hw_unit].texOffset6 = texOffset;
497 prev->texture[hw_unit].texPitch67 = texPitch << 16;
498 break;
499 case 7:
500 prev->texture[hw_unit].texOffset7 = texOffset;
501 prev->texture[hw_unit].texPitch67 |= texPitch;
502 break;
503 case 8:
504 prev->texture[hw_unit].texOffset8 = texOffset;
505 prev->texture[hw_unit].texPitch89 = texPitch << 16;
506 break;
507 case 9:
508 prev->texture[hw_unit].texOffset9 = texOffset;
509 prev->texture[hw_unit].texPitch89 |= texPitch;
510 break;
511 case 10:
512 prev->texture[hw_unit].texOffset10 = texOffset;
513 prev->texture[hw_unit].texPitch10 = texPitch << 16;
514 break;
515 case 11:
516 prev->texture[hw_unit].texOffset11 = texOffset;
517 prev->texture[hw_unit].texPitch10 |= texPitch;
518 break;
519 }
520 }
521
522 if (current->texture[hw_unit].hwTextureSet !=
523 prev->texture[hw_unit].hwTextureSet)
524 {
525 prev->texture[hw_unit].hwTextureSet =
526 current->texture[hw_unit].hwTextureSet;
527 if (hw_unit == 1)
528 smesa->GlobalFlag |= CFLAG_TEXTURERESET_1;
529 else
530 smesa->GlobalFlag |= CFLAG_TEXTURERESET;
531 }
532 if (current->texture[hw_unit].hwTextureMip !=
533 prev->texture[hw_unit].hwTextureMip)
534 {
535 prev->texture[hw_unit].hwTextureMip =
536 current->texture[hw_unit].hwTextureMip;
537 if (hw_unit == 1)
538 smesa->GlobalFlag |= GFLAG_TEXTUREMIPMAP_1;
539 else
540 smesa->GlobalFlag |= GFLAG_TEXTUREMIPMAP;
541 }
542
543 return ok;
544 }
545
546 /* Disable a texture unit, called from validate_texture */
547 static void
548 sis_reset_texture_env (GLcontext *ctx, int hw_unit)
549 {
550 sisContextPtr smesa = SIS_CONTEXT(ctx);
551
552 __GLSiSHardware *prev = &smesa->prev;
553 __GLSiSHardware *current = &smesa->current;
554
555 if (hw_unit == 1)
556 {
557 current->hwTexBlendColor1 = STAGE1_C_CF;
558 current->hwTexBlendAlpha1 = STAGE1_A_AF;
559
560 if ((current->hwTexBlendColor1 != prev->hwTexBlendColor1) ||
561 (current->hwTexBlendAlpha1 != prev->hwTexBlendAlpha1) ||
562 (current->hwTexEnvColor != prev->hwTexEnvColor))
563 {
564 prev->hwTexBlendColor1 = current->hwTexBlendColor1;
565 prev->hwTexBlendAlpha1 = current->hwTexBlendAlpha1;
566 prev->hwTexEnvColor = current->hwTexEnvColor;
567 smesa->GlobalFlag |= GFLAG_TEXTUREENV_1;
568 }
569 } else {
570 current->hwTexBlendColor0 = STAGE0_C_CF;
571 current->hwTexBlendAlpha0 = STAGE0_A_AF;
572
573 if ((current->hwTexBlendColor0 != prev->hwTexBlendColor0) ||
574 (current->hwTexBlendAlpha0 != prev->hwTexBlendAlpha0) ||
575 (current->hwTexEnvColor != prev->hwTexEnvColor))
576 {
577 prev->hwTexBlendColor0 = current->hwTexBlendColor0;
578 prev->hwTexBlendAlpha0 = current->hwTexBlendAlpha0;
579 prev->hwTexEnvColor = current->hwTexEnvColor;
580 smesa->GlobalFlag |= GFLAG_TEXTUREENV;
581 }
582 }
583 }
584
585 static void updateTextureUnit( GLcontext *ctx, int unit )
586 {
587 sisContextPtr smesa = SIS_CONTEXT( ctx );
588 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
589 struct gl_texture_object *texObj = texUnit->_Current;
590 GLint fallbackbit;
591
592 if (unit == 0)
593 fallbackbit = SIS_FALLBACK_TEXTURE0;
594 else
595 fallbackbit = SIS_FALLBACK_TEXTURE1;
596
597 if (texUnit->_ReallyEnabled & (TEXTURE_1D_BIT | TEXTURE_2D_BIT)) {
598 if (smesa->TexStates[unit] & NEW_TEXTURING) {
599 GLboolean ok;
600
601 ok = sis_set_texobj_parm (ctx, texObj, unit);
602 FALLBACK( smesa, fallbackbit, !ok );
603 }
604 if (smesa->TexStates[unit] & NEW_TEXTURE_ENV) {
605 if (unit == 0)
606 sis_set_texture_env0( ctx, texObj, unit );
607 else
608 sis_set_texture_env1( ctx, texObj, unit );
609 }
610 smesa->TexStates[unit] = 0;
611 } else if ( texUnit->_ReallyEnabled ) {
612 /* fallback */
613 FALLBACK( smesa, fallbackbit, 1 );
614 } else {
615 sis_reset_texture_env( ctx, unit );
616 FALLBACK( smesa, fallbackbit, 0 );
617 }
618 }
619
620
621 void sisUpdateTextureState( GLcontext *ctx )
622 {
623 sisContextPtr smesa = SIS_CONTEXT( ctx );
624 int i;
625 __GLSiSHardware *current = &smesa->current;
626
627 #if 1
628 /* TODO : if unmark these, error in multitexture */ /* XXX */
629 for (i = 0; i < SIS_MAX_TEXTURES; i++)
630 smesa->TexStates[i] |= (NEW_TEXTURING | NEW_TEXTURE_ENV);
631 #endif
632
633 updateTextureUnit( ctx, 0 );
634 updateTextureUnit( ctx, 1 );
635
636 /* XXX Issues with the 2nd unit but not the first being enabled? */
637 if ( ctx->Texture.Unit[0]._ReallyEnabled &
638 (TEXTURE_1D_BIT | TEXTURE_2D_BIT) ||
639 ctx->Texture.Unit[1]._ReallyEnabled &
640 (TEXTURE_1D_BIT | TEXTURE_2D_BIT) )
641 {
642 current->hwCapEnable |= MASK_TextureEnable;
643 current->hwCapEnable &= ~MASK_TextureNumUsed;
644 if (ctx->Texture.Unit[1]._ReallyEnabled)
645 current->hwCapEnable |= 0x00002000;
646 else
647 current->hwCapEnable |= 0x00001000;
648 } else {
649 current->hwCapEnable &= ~MASK_TextureEnable;
650 }
651 }
652
653 static GLint
654 BitScanForward( GLshort w )
655 {
656 GLint i;
657
658 for (i = 0; i < 16; i++) {
659 if (w & (1 << i))
660 break;
661 }
662 return i;
663 }
664
665 static GLint
666 TransferTexturePitch( GLint dwPitch )
667 {
668 GLint dwRet, i;
669
670 i = BitScanForward( (GLshort)dwPitch );
671 dwRet = dwPitch >> i;
672 dwRet |= i << 9;
673 return dwRet;
674 }