Add disabled support for GL_EXT_fog_coord. While it seems correct to me, it's
[mesa.git] / src / mesa / drivers / dri / sis / sis_context.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: xc/lib/GL/mesa/src/drv/sis/sis_ctx.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ */
28
29 /*
30 * Authors:
31 * Sung-Ching Lin <sclin@sis.com.tw>
32 * Eric Anholt <anholt@FreeBSD.org>
33 */
34
35 #include "sis_dri.h"
36
37 #include "sis_context.h"
38 #include "sis_state.h"
39 #include "sis_dd.h"
40 #include "sis_span.h"
41 #include "sis_stencil.h"
42 #include "sis_tex.h"
43 #include "sis_tris.h"
44 #include "sis_alloc.h"
45
46 #include "imports.h"
47 #include "matrix.h"
48 #include "extensions.h"
49 #include "utils.h"
50 #include "framebuffer.h"
51
52 #include "drivers/common/driverfuncs.h"
53
54 #include "swrast/swrast.h"
55 #include "swrast_setup/swrast_setup.h"
56 #include "array_cache/acache.h"
57
58 #include "tnl/tnl.h"
59 #include "tnl/t_pipeline.h"
60
61 #define need_GL_ARB_multisample
62 #define need_GL_ARB_texture_compression
63 #define need_GL_EXT_fog_coord
64 #define need_GL_EXT_secondary_color
65 #include "extension_helper.h"
66
67 #ifndef SIS_DEBUG
68 int SIS_DEBUG = 0;
69 #endif
70
71 int GlobalCurrentHwcx = -1;
72 int GlobalHwcxCountBase = 1;
73 int GlobalCmdQueueLen = 0;
74
75 struct dri_extension card_extensions[] =
76 {
77 { "GL_ARB_multisample", GL_ARB_multisample_functions },
78 { "GL_ARB_multitexture", NULL },
79 { "GL_ARB_texture_border_clamp", NULL },
80 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions },
81 { "GL_ARB_texture_mirrored_repeat", NULL },
82 /*{ "GL_EXT_fog_coord", GL_EXT_fog_coord_functions },*/
83 { "GL_EXT_texture_lod_bias", NULL },
84 { "GL_EXT_secondary_color", GL_EXT_secondary_color_functions },
85 { "GL_EXT_stencil_wrap", NULL },
86 { "GL_MESA_ycbcr_texture", NULL },
87 { "GL_NV_blend_square", NULL },
88 { NULL, NULL }
89 };
90
91 struct dri_extension card_extensions_6326[] =
92 {
93 { "GL_ARB_multisample", GL_ARB_multisample_functions },
94 /*{ "GL_ARB_texture_border_clamp", NULL },*/
95 { "GL_ARB_texture_compression", GL_ARB_texture_compression_functions },
96 /*{ "GL_ARB_texture_mirrored_repeat", NULL },*/
97 /*{ "GL_MESA_ycbcr_texture", NULL },*/
98 { NULL, NULL }
99 };
100
101 static const struct dri_debug_control debug_control[] =
102 {
103 { "fall", DEBUG_FALLBACKS },
104 { NULL, 0 }
105 };
106
107 void
108 WaitEngIdle (sisContextPtr smesa)
109 {
110 GLuint engineState;
111
112 if (smesa->is6326) {
113 do {
114 engineState = MMIO_READ(REG_3D_EngineFire); /* XXX right reg? */
115 } while ((engineState & ENG_3DIDLEQE) != 0);
116 } else {
117 do {
118 engineState = MMIO_READ(REG_CommandQueue);
119 } while ((engineState & SiS_EngIdle) != SiS_EngIdle);
120 }
121 }
122
123 void
124 Wait2DEngIdle (sisContextPtr smesa)
125 {
126 GLuint engineState;
127
128 if (smesa->is6326) {
129 do {
130 engineState = MMIO_READ(REG_6326_BitBlt_Cmd);
131 } while ((engineState & BLT_BUSY) != 0);
132 } else {
133 do {
134 engineState = MMIO_READ(REG_CommandQueue);
135 } while ((engineState & SiS_EngIdle2d) != SiS_EngIdle2d);
136 }
137 }
138
139 /* To be called from mWait3DCmdQueue. Separate function for profiling
140 * purposes, and speed doesn't matter because we're spinning anyway.
141 */
142 void
143 WaitingFor3dIdle(sisContextPtr smesa, int wLen)
144 {
145 if (smesa->is6326) {
146 while (*(smesa->CurrentQueueLenPtr) < wLen) {
147 *(smesa->CurrentQueueLenPtr) =
148 ((GLuint)MMIO_READ(REG_3D_EngineFire) >> 16) * 2;
149 }
150 } else {
151 while (*(smesa->CurrentQueueLenPtr) < wLen) {
152 *(smesa->CurrentQueueLenPtr) =
153 (MMIO_READ(REG_CommandQueue) & MASK_QueueLen) - 20;
154 }
155 }
156 }
157
158 void sisReAllocateBuffers(GLcontext *ctx, GLframebuffer *drawbuffer,
159 GLuint width, GLuint height)
160 {
161 sisContextPtr smesa = SIS_CONTEXT(ctx);
162
163 sisUpdateBufferSize(smesa);
164
165 _mesa_resize_framebuffer(ctx, drawbuffer, width, height);
166 }
167
168 GLboolean
169 sisCreateContext( const __GLcontextModes *glVisual,
170 __DRIcontextPrivate *driContextPriv,
171 void *sharedContextPrivate )
172 {
173 GLcontext *ctx, *shareCtx;
174 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
175 sisContextPtr smesa;
176 sisScreenPtr sisScreen;
177 int i;
178 struct dd_function_table functions;
179
180 smesa = (sisContextPtr)CALLOC( sizeof(*smesa) );
181 if (smesa == NULL)
182 return GL_FALSE;
183
184 /* Init default driver functions then plug in our SIS-specific functions
185 * (the texture functions are especially important)
186 */
187 _mesa_init_driver_functions(&functions);
188 sisInitDriverFuncs(&functions);
189 sisInitTextureFuncs(&functions);
190
191 /* Allocate the Mesa context */
192 if (sharedContextPrivate)
193 shareCtx = ((sisContextPtr)sharedContextPrivate)->glCtx;
194 else
195 shareCtx = NULL;
196 smesa->glCtx = _mesa_create_context( glVisual, shareCtx,
197 &functions, (void *) smesa);
198 if (!smesa->glCtx) {
199 FREE(smesa);
200 return GL_FALSE;
201 }
202 driContextPriv->driverPrivate = smesa;
203 ctx = smesa->glCtx;
204
205 sisScreen = smesa->sisScreen = (sisScreenPtr)(sPriv->private);
206
207 smesa->is6326 = GL_FALSE; /* XXX */
208 smesa->driContext = driContextPriv;
209 smesa->driScreen = sPriv;
210 smesa->driDrawable = NULL;
211 smesa->hHWContext = driContextPriv->hHWContext;
212 smesa->driHwLock = &sPriv->pSAREA->lock;
213 smesa->driFd = sPriv->fd;
214
215 smesa->virtualX = sisScreen->screenX;
216 smesa->virtualY = sisScreen->screenY;
217 smesa->bytesPerPixel = sisScreen->cpp;
218 smesa->IOBase = sisScreen->mmio.map;
219 smesa->Chipset = sisScreen->deviceID;
220
221 smesa->FbBase = sPriv->pFB;
222 smesa->displayWidth = sPriv->fbWidth;
223 smesa->front.pitch = sPriv->fbStride;
224
225 smesa->sarea = (SISSAREAPriv *)((char *)sPriv->pSAREA +
226 sisScreen->sarea_priv_offset);
227
228 /* support ARGB8888 and RGB565 */
229 switch (smesa->bytesPerPixel)
230 {
231 case 4:
232 smesa->redMask = 0x00ff0000;
233 smesa->greenMask = 0x0000ff00;
234 smesa->blueMask = 0x000000ff;
235 smesa->alphaMask = 0xff000000;
236 smesa->colorFormat = DST_FORMAT_ARGB_8888;
237 break;
238 case 2:
239 smesa->redMask = 0xf800;
240 smesa->greenMask = 0x07e0;
241 smesa->blueMask = 0x001f;
242 smesa->alphaMask = 0;
243 smesa->colorFormat = DST_FORMAT_RGB_565;
244 break;
245 default:
246 sis_fatal_error("Bad bytesPerPixel %d.\n", smesa->bytesPerPixel);
247 }
248
249 if (smesa->is6326) {
250 ctx->Const.MaxTextureUnits = 1;
251 ctx->Const.MaxTextureLevels = 9;
252 } else {
253 ctx->Const.MaxTextureUnits = 2;
254 ctx->Const.MaxTextureLevels = 11;
255 }
256 ctx->Const.MaxTextureImageUnits = ctx->Const.MaxTextureUnits;
257 ctx->Const.MaxTextureCoordUnits = ctx->Const.MaxTextureUnits;
258
259 /* Parse configuration files */
260 driParseConfigFiles (&smesa->optionCache, &sisScreen->optionCache,
261 sisScreen->driScreen->myNum, "sis");
262
263 #if DO_DEBUG
264 SIS_DEBUG = driParseDebugString(getenv("SIS_DEBUG"), debug_control);
265 #endif
266
267 /* TODO: index mode */
268
269 smesa->CurrentQueueLenPtr = &(smesa->sarea->QueueLength);
270 smesa->FrameCountPtr = &(smesa->sarea->FrameCount);
271
272 /* set AGP */
273 smesa->AGPSize = sisScreen->agp.size;
274 smesa->AGPBase = sisScreen->agp.map;
275 smesa->AGPAddr = sisScreen->agp.handle;
276
277 /* Create AGP command buffer */
278 if (smesa->AGPSize != 0 &&
279 !driQueryOptionb(&smesa->optionCache, "agp_disable"))
280 {
281 smesa->vb = sisAllocAGP(smesa, 64 * 1024, &smesa->vb_agp_handle);
282 if (smesa->vb != NULL) {
283 smesa->using_agp = GL_TRUE;
284 smesa->vb_cur = smesa->vb;
285 smesa->vb_last = smesa->vb;
286 smesa->vb_end = smesa->vb + 64 * 1024;
287 smesa->vb_agp_offset = ((long)smesa->vb - (long)smesa->AGPBase +
288 (long)smesa->AGPAddr);
289 }
290 }
291 if (!smesa->using_agp) {
292 smesa->vb = malloc(64 * 1024);
293 if (smesa->vb == NULL) {
294 FREE(smesa);
295 return GL_FALSE;
296 }
297 smesa->vb_cur = smesa->vb;
298 smesa->vb_last = smesa->vb;
299 smesa->vb_end = smesa->vb + 64 * 1024;
300 }
301
302 smesa->GlobalFlag = 0L;
303
304 smesa->Fallback = 0;
305
306 /* Initialize the software rasterizer and helper modules.
307 */
308 _swrast_CreateContext( ctx );
309 _ac_CreateContext( ctx );
310 _tnl_CreateContext( ctx );
311 _swsetup_CreateContext( ctx );
312
313 _swrast_allow_pixel_fog( ctx, GL_TRUE );
314 _swrast_allow_vertex_fog( ctx, GL_FALSE );
315 _tnl_allow_pixel_fog( ctx, GL_TRUE );
316 _tnl_allow_vertex_fog( ctx, GL_FALSE );
317
318 /* XXX these should really go right after _mesa_init_driver_functions() */
319 if (smesa->is6326) {
320 sis6326DDInitStateFuncs( ctx );
321 sis6326DDInitState( smesa ); /* Initializes smesa->zFormat, important */
322 } else {
323 sisDDInitStateFuncs( ctx );
324 sisDDInitState( smesa ); /* Initializes smesa->zFormat, important */
325 sisDDInitStencilFuncs( ctx );
326 }
327 sisInitTriFuncs( ctx );
328 sisDDInitSpanFuncs( ctx );
329
330 driInitExtensions( ctx, card_extensions, GL_FALSE );
331
332 for (i = 0; i < SIS_MAX_TEXTURES; i++) {
333 smesa->TexStates[i] = 0;
334 smesa->PrevTexFormat[i] = 0;
335 }
336
337 if (driQueryOptionb(&smesa->optionCache, "no_rast")) {
338 fprintf(stderr, "disabling 3D acceleration\n");
339 FALLBACK(smesa, SIS_FALLBACK_DISABLE, 1);
340 }
341 smesa->texture_depth = driQueryOptioni(&smesa->optionCache, "texture_depth");
342
343 return GL_TRUE;
344 }
345
346 void
347 sisDestroyContext ( __DRIcontextPrivate *driContextPriv )
348 {
349 sisContextPtr smesa = (sisContextPtr)driContextPriv->driverPrivate;
350
351 assert( smesa != NULL );
352
353 if ( smesa != NULL ) {
354 _swsetup_DestroyContext( smesa->glCtx );
355 _tnl_DestroyContext( smesa->glCtx );
356 _ac_DestroyContext( smesa->glCtx );
357 _swrast_DestroyContext( smesa->glCtx );
358
359 if (smesa->using_agp)
360 sisFreeAGP(smesa, smesa->vb_agp_handle);
361
362 /* free the Mesa context */
363 /* XXX: Is the next line needed? The DriverCtx (smesa) reference is
364 * needed for sisDDDeleteTexture, since it needs to call the FB/AGP free
365 * function.
366 */
367 /* smesa->glCtx->DriverCtx = NULL; */
368 _mesa_destroy_context(smesa->glCtx);
369 }
370
371 FREE( smesa );
372 }
373
374 GLboolean
375 sisMakeCurrent( __DRIcontextPrivate *driContextPriv,
376 __DRIdrawablePrivate *driDrawPriv,
377 __DRIdrawablePrivate *driReadPriv )
378 {
379 if ( driContextPriv ) {
380 GET_CURRENT_CONTEXT(ctx);
381 sisContextPtr oldSisCtx = ctx ? SIS_CONTEXT(ctx) : NULL;
382 sisContextPtr newSisCtx = (sisContextPtr) driContextPriv->driverPrivate;
383 struct gl_framebuffer *drawBuffer, *readBuffer;
384
385 if ( newSisCtx != oldSisCtx) {
386 newSisCtx->GlobalFlag = GFLAG_ALL;
387 }
388
389 newSisCtx->driDrawable = driDrawPriv;
390
391 drawBuffer = (GLframebuffer *)driDrawPriv->driverPrivate;
392 readBuffer = (GLframebuffer *)driReadPriv->driverPrivate;
393
394 _mesa_make_current( newSisCtx->glCtx, drawBuffer, readBuffer );
395
396 sisUpdateBufferSize( newSisCtx );
397 sisUpdateClipping( newSisCtx->glCtx );
398 } else {
399 _mesa_make_current( NULL, NULL, NULL );
400 }
401
402 return GL_TRUE;
403 }
404
405 GLboolean
406 sisUnbindContext( __DRIcontextPrivate *driContextPriv )
407 {
408 return GL_TRUE;
409 }
410
411 void
412 sis_update_render_state( sisContextPtr smesa )
413 {
414 __GLSiSHardware *prev = &smesa->prev;
415
416 mWait3DCmdQueue (45);
417
418 if (smesa->GlobalFlag & GFLAG_ENABLESETTING) {
419 if (!smesa->clearTexCache) {
420 MMIO(REG_3D_TEnable, prev->hwCapEnable);
421 } else {
422 MMIO(REG_3D_TEnable, prev->hwCapEnable | MASK_TextureCacheClear);
423 MMIO(REG_3D_TEnable, prev->hwCapEnable);
424 smesa->clearTexCache = GL_FALSE;
425 }
426 }
427
428 if (smesa->GlobalFlag & GFLAG_ENABLESETTING2)
429 MMIO(REG_3D_TEnable2, prev->hwCapEnable2);
430
431 /* Z Setting */
432 if (smesa->GlobalFlag & GFLAG_ZSETTING)
433 {
434 MMIO(REG_3D_ZSet, prev->hwZ);
435 MMIO(REG_3D_ZStWriteMask, prev->hwZMask);
436 MMIO(REG_3D_ZAddress, prev->hwOffsetZ);
437 }
438
439 /* Alpha Setting */
440 if (smesa->GlobalFlag & GFLAG_ALPHASETTING)
441 MMIO(REG_3D_AlphaSet, prev->hwAlpha);
442
443 if (smesa->GlobalFlag & GFLAG_DESTSETTING) {
444 MMIO(REG_3D_DstSet, prev->hwDstSet);
445 MMIO(REG_3D_DstAlphaWriteMask, prev->hwDstMask);
446 MMIO(REG_3D_DstAddress, prev->hwOffsetDest);
447 }
448
449 /* Line Setting */
450 #if 0
451 if (smesa->GlobalFlag & GFLAG_LINESETTING)
452 MMIO(REG_3D_LinePattern, prev->hwLinePattern);
453 #endif
454
455 /* Fog Setting */
456 if (smesa->GlobalFlag & GFLAG_FOGSETTING)
457 {
458 MMIO(REG_3D_FogSet, prev->hwFog);
459 MMIO(REG_3D_FogInverseDistance, prev->hwFogInverse);
460 MMIO(REG_3D_FogFarDistance, prev->hwFogFar);
461 MMIO(REG_3D_FogFactorDensity, prev->hwFogDensity);
462 }
463
464 /* Stencil Setting */
465 if (smesa->GlobalFlag & GFLAG_STENCILSETTING) {
466 MMIO(REG_3D_StencilSet, prev->hwStSetting);
467 MMIO(REG_3D_StencilSet2, prev->hwStSetting2);
468 }
469
470 /* Miscellaneous Setting */
471 if (smesa->GlobalFlag & GFLAG_DSTBLEND)
472 MMIO(REG_3D_DstBlendMode, prev->hwDstSrcBlend);
473 if (smesa->GlobalFlag & GFLAG_CLIPPING) {
474 MMIO(REG_3D_ClipTopBottom, prev->clipTopBottom);
475 MMIO(REG_3D_ClipLeftRight, prev->clipLeftRight);
476 }
477
478 smesa->GlobalFlag &= ~GFLAG_RENDER_STATES;
479 }
480
481 void
482 sis_update_texture_state (sisContextPtr smesa)
483 {
484 __GLSiSHardware *prev = &smesa->prev;
485
486 mWait3DCmdQueue (55);
487 if (smesa->clearTexCache || (smesa->GlobalFlag & GFLAG_TEXTUREADDRESS)) {
488 MMIO(REG_3D_TEnable, prev->hwCapEnable | MASK_TextureCacheClear);
489 MMIO(REG_3D_TEnable, prev->hwCapEnable);
490 smesa->clearTexCache = GL_FALSE;
491 }
492
493 /* Texture Setting */
494 if (smesa->GlobalFlag & CFLAG_TEXTURERESET)
495 MMIO(REG_3D_TextureSet, prev->texture[0].hwTextureSet);
496
497 if (smesa->GlobalFlag & GFLAG_TEXTUREMIPMAP)
498 MMIO(REG_3D_TextureMip, prev->texture[0].hwTextureMip);
499
500 /*
501 MMIO(REG_3D_TextureTransparencyColorHigh, prev->texture[0].hwTextureClrHigh);
502 MMIO(REG_3D_TextureTransparencyColorLow, prev->texture[0].hwTextureClrLow);
503 */
504
505 if (smesa->GlobalFlag & GFLAG_TEXBORDERCOLOR)
506 MMIO(REG_3D_TextureBorderColor, prev->texture[0].hwTextureBorderColor);
507
508 if (smesa->GlobalFlag & GFLAG_TEXTUREADDRESS) {
509 switch ((prev->texture[0].hwTextureSet & MASK_TextureLevel) >> 8)
510 {
511 case 11:
512 MMIO(REG_3D_TextureAddress11, prev->texture[0].texOffset11);
513 case 10:
514 MMIO(REG_3D_TextureAddress10, prev->texture[0].texOffset10);
515 MMIO(REG_3D_TexturePitch10, prev->texture[0].texPitch10);
516 case 9:
517 MMIO(REG_3D_TextureAddress9, prev->texture[0].texOffset9);
518 case 8:
519 MMIO(REG_3D_TextureAddress8, prev->texture[0].texOffset8);
520 MMIO(REG_3D_TexturePitch8, prev->texture[0].texPitch89);
521 case 7:
522 MMIO(REG_3D_TextureAddress7, prev->texture[0].texOffset7);
523 case 6:
524 MMIO(REG_3D_TextureAddress6, prev->texture[0].texOffset6);
525 MMIO(REG_3D_TexturePitch6, prev->texture[0].texPitch67);
526 case 5:
527 MMIO(REG_3D_TextureAddress5, prev->texture[0].texOffset5);
528 case 4:
529 MMIO(REG_3D_TextureAddress4, prev->texture[0].texOffset4);
530 MMIO(REG_3D_TexturePitch4, prev->texture[0].texPitch45);
531 case 3:
532 MMIO(REG_3D_TextureAddress3, prev->texture[0].texOffset3);
533 case 2:
534 MMIO(REG_3D_TextureAddress2, prev->texture[0].texOffset2);
535 MMIO(REG_3D_TexturePitch2, prev->texture[0].texPitch23);
536 case 1:
537 MMIO(REG_3D_TextureAddress1, prev->texture[0].texOffset1);
538 case 0:
539 MMIO(REG_3D_TextureAddress0, prev->texture[0].texOffset0);
540 MMIO(REG_3D_TexturePitch0, prev->texture[0].texPitch01);
541 }
542 }
543 if (smesa->GlobalFlag & CFLAG_TEXTURERESET_1)
544 MMIO(REG_3D_Texture1Set, prev->texture[1].hwTextureSet);
545 if (smesa->GlobalFlag & GFLAG_TEXTUREMIPMAP_1)
546 MMIO(REG_3D_Texture1Mip, prev->texture[1].hwTextureMip);
547
548 if (smesa->GlobalFlag & GFLAG_TEXBORDERCOLOR_1) {
549 MMIO(REG_3D_Texture1BorderColor,
550 prev->texture[1].hwTextureBorderColor);
551 }
552 if (smesa->GlobalFlag & GFLAG_TEXTUREADDRESS_1) {
553 switch ((prev->texture[1].hwTextureSet & MASK_TextureLevel) >> 8)
554 {
555 case 11:
556 MMIO(REG_3D_Texture1Address11, prev->texture[1].texOffset11);
557 case 10:
558 MMIO(REG_3D_Texture1Address10, prev->texture[1].texOffset10);
559 MMIO(REG_3D_Texture1Pitch10, prev->texture[1].texPitch10);
560 case 9:
561 MMIO(REG_3D_Texture1Address9, prev->texture[1].texOffset9);
562 case 8:
563 MMIO(REG_3D_Texture1Address8, prev->texture[1].texOffset8);
564 MMIO(REG_3D_Texture1Pitch8, prev->texture[1].texPitch89);
565 case 7:
566 MMIO(REG_3D_Texture1Address7, prev->texture[1].texOffset7);
567 case 6:
568 MMIO(REG_3D_Texture1Address6, prev->texture[1].texOffset6);
569 MMIO(REG_3D_Texture1Pitch6, prev->texture[1].texPitch67);
570 case 5:
571 MMIO(REG_3D_Texture1Address5, prev->texture[1].texOffset5);
572 case 4:
573 MMIO(REG_3D_Texture1Address4, prev->texture[1].texOffset4);
574 MMIO(REG_3D_Texture1Pitch4, prev->texture[1].texPitch45);
575 case 3:
576 MMIO(REG_3D_Texture1Address3, prev->texture[1].texOffset3);
577 case 2:
578 MMIO(REG_3D_Texture1Address2, prev->texture[1].texOffset2);
579 MMIO(REG_3D_Texture1Pitch2, prev->texture[1].texPitch23);
580 case 1:
581 MMIO(REG_3D_Texture1Address1, prev->texture[1].texOffset1);
582 case 0:
583 MMIO(REG_3D_Texture1Address0, prev->texture[1].texOffset0);
584 MMIO(REG_3D_Texture1Pitch0, prev->texture[1].texPitch01);
585 }
586 }
587
588 /* texture environment */
589 if (smesa->GlobalFlag & GFLAG_TEXTUREENV) {
590 MMIO(REG_3D_TextureBlendFactor, prev->hwTexEnvColor);
591 MMIO(REG_3D_TextureColorBlendSet0, prev->hwTexBlendColor0);
592 MMIO(REG_3D_TextureAlphaBlendSet0, prev->hwTexBlendAlpha0);
593 }
594 if (smesa->GlobalFlag & GFLAG_TEXTUREENV_1) {
595 MMIO(REG_3D_TextureBlendFactor, prev->hwTexEnvColor);
596 MMIO(REG_3D_TextureColorBlendSet1, prev->hwTexBlendColor1);
597 MMIO(REG_3D_TextureAlphaBlendSet1, prev->hwTexBlendAlpha1);
598 }
599
600 smesa->GlobalFlag &= ~GFLAG_TEXTURE_STATES;
601 }
602
603 void
604 sis6326_update_render_state( sisContextPtr smesa )
605 {
606 __GLSiSHardware *prev = &smesa->prev;
607
608 mWait3DCmdQueue (45);
609
610 if (smesa->GlobalFlag & GFLAG_ENABLESETTING) {
611 if (!smesa->clearTexCache) {
612 MMIO(REG_6326_3D_TEnable, prev->hwCapEnable);
613 } else {
614 MMIO(REG_6326_3D_TEnable, prev->hwCapEnable & ~S_ENABLE_TextureCache);
615 MMIO(REG_6326_3D_TEnable, prev->hwCapEnable);
616 smesa->clearTexCache = GL_FALSE;
617 }
618 }
619
620 /* Z Setting */
621 if (smesa->GlobalFlag & GFLAG_ZSETTING) {
622 MMIO(REG_6326_3D_ZSet, prev->hwZ);
623 MMIO(REG_6326_3D_ZAddress, prev->hwOffsetZ);
624 }
625
626 /* Alpha Setting */
627 if (smesa->GlobalFlag & GFLAG_ALPHASETTING)
628 MMIO(REG_6326_3D_AlphaSet, prev->hwAlpha);
629
630 if (smesa->GlobalFlag & GFLAG_DESTSETTING) {
631 MMIO(REG_6326_3D_DstSet, prev->hwDstSet);
632 MMIO(REG_6326_3D_DstAddress, prev->hwOffsetDest);
633 }
634
635 /* Fog Setting */
636 if (smesa->GlobalFlag & GFLAG_FOGSETTING) {
637 MMIO(REG_6326_3D_FogSet, prev->hwFog);
638 }
639
640 /* Miscellaneous Setting */
641 if (smesa->GlobalFlag & GFLAG_DSTBLEND)
642 MMIO(REG_6326_3D_DstSrcBlendMode, prev->hwDstSrcBlend);
643
644 if (smesa->GlobalFlag & GFLAG_CLIPPING) {
645 MMIO(REG_6326_3D_ClipTopBottom, prev->clipTopBottom);
646 MMIO(REG_6326_3D_ClipLeftRight, prev->clipLeftRight);
647 }
648
649 smesa->GlobalFlag &= ~GFLAG_RENDER_STATES;
650 }
651
652 void
653 sis6326_update_texture_state (sisContextPtr smesa)
654 {
655 __GLSiSHardware *prev = &smesa->prev;
656
657 mWait3DCmdQueue (55);
658 if (smesa->clearTexCache || (smesa->GlobalFlag & GFLAG_TEXTUREADDRESS)) {
659 MMIO(REG_6326_3D_TEnable, prev->hwCapEnable & ~S_ENABLE_TextureCache);
660 MMIO(REG_6326_3D_TEnable, prev->hwCapEnable);
661 smesa->clearTexCache = GL_FALSE;
662 }
663
664 /* Texture Setting */
665 if (smesa->GlobalFlag & CFLAG_TEXTURERESET)
666 MMIO(REG_6326_3D_TextureSet, prev->texture[0].hwTextureSet);
667
668 if (smesa->GlobalFlag & GFLAG_TEXTUREMIPMAP)
669 MMIO(REG_6326_3D_TextureWidthHeight, prev->texture[0].hwTexWidthHeight);
670
671 /*
672 MMIO(REG_3D_TextureTransparencyColorHigh, prev->texture[0].hwTextureClrHigh);
673 MMIO(REG_3D_TextureTransparencyColorLow, prev->texture[0].hwTextureClrLow);
674 */
675
676 if (smesa->GlobalFlag & GFLAG_TEXBORDERCOLOR)
677 MMIO(REG_6326_3D_TextureBorderColor, prev->texture[0].hwTextureBorderColor);
678
679 if (smesa->GlobalFlag & GFLAG_TEXTUREADDRESS) {
680 switch ((prev->texture[0].hwTextureSet & MASK_6326_TextureLevel) >> 8)
681 {
682 case 9:
683 MMIO(REG_6326_3D_TextureAddress9, prev->texture[0].texOffset9);
684 /* FALLTHROUGH */
685 case 8:
686 MMIO(REG_6326_3D_TextureAddress8, prev->texture[0].texOffset8);
687 MMIO(REG_6326_3D_TexturePitch89, prev->texture[0].texPitch89);
688 /* FALLTHROUGH */
689 case 7:
690 MMIO(REG_6326_3D_TextureAddress7, prev->texture[0].texOffset7);
691 /* FALLTHROUGH */
692 case 6:
693 MMIO(REG_6326_3D_TextureAddress6, prev->texture[0].texOffset6);
694 MMIO(REG_6326_3D_TexturePitch67, prev->texture[0].texPitch67);
695 /* FALLTHROUGH */
696 case 5:
697 MMIO(REG_6326_3D_TextureAddress5, prev->texture[0].texOffset5);
698 /* FALLTHROUGH */
699 case 4:
700 MMIO(REG_6326_3D_TextureAddress4, prev->texture[0].texOffset4);
701 MMIO(REG_6326_3D_TexturePitch45, prev->texture[0].texPitch45);
702 /* FALLTHROUGH */
703 case 3:
704 MMIO(REG_6326_3D_TextureAddress3, prev->texture[0].texOffset3);
705 /* FALLTHROUGH */
706 case 2:
707 MMIO(REG_6326_3D_TextureAddress2, prev->texture[0].texOffset2);
708 MMIO(REG_6326_3D_TexturePitch23, prev->texture[0].texPitch23);
709 /* FALLTHROUGH */
710 case 1:
711 MMIO(REG_6326_3D_TextureAddress1, prev->texture[0].texOffset1);
712 /* FALLTHROUGH */
713 case 0:
714 MMIO(REG_6326_3D_TextureAddress0, prev->texture[0].texOffset0);
715 MMIO(REG_6326_3D_TexturePitch01, prev->texture[0].texPitch01);
716 break;
717 }
718 }
719
720 /* texture environment */
721 if (smesa->GlobalFlag & GFLAG_TEXTUREENV) {
722 MMIO(REG_6326_3D_TextureBlendSet, prev->hwTexBlendSet);
723 }
724
725 smesa->GlobalFlag &= ~GFLAG_TEXTURE_STATES;
726 }