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