added _tnl_allow_vertex/pixel_fog() calls
[mesa.git] / src / mesa / drivers / dri / sis / sis_context.c
index a58cb2963bd5a15145d3c78c58ac17102674cb99..e580a405f04eee36203df3fc13273372f6d83b3e 100644 (file)
@@ -18,7 +18,7 @@ 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
-ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP 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.
@@ -48,6 +48,8 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "extensions.h"
 #include "utils.h"
 
+#include "drivers/common/driverfuncs.h"
+
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
 #include "array_cache/acache.h"
@@ -69,41 +71,32 @@ static const char * const card_extensions[] =
 void
 WaitEngIdle (sisContextPtr smesa)
 {
-   GLubyte *IOBase = GET_IOBase (smesa);
-   GLbyte cEngineState;
+   GLuint engineState;
 
-   cEngineState = *((GLbyte volatile *) (IOBase + 0x8243));
-   while (((cEngineState & 0x80) == 0) ||
-         ((cEngineState & 0x40) == 0) || ((cEngineState & 0x20) == 0))
-   {
-      cEngineState = *((GLbyte volatile *) (IOBase + 0x8243));
-   }
+   do {
+      engineState = MMIO_READ(REG_CommandQueue);
+   } while ((engineState & SiS_EngIdle) != SiS_EngIdle);
 }
 
 void
 Wait2DEngIdle (sisContextPtr smesa)
 {
-   GLubyte *IOBase = GET_IOBase (smesa);
-   GLbyte cEngineState;
+   GLuint engineState;
 
-   cEngineState = *((GLbyte volatile *) (IOBase + 0x8243));
-   while (!(cEngineState & 0x80))
-   {
-      cEngineState = *((GLbyte volatile *) (IOBase + 0x8243));
-   }
+   do {
+      engineState = MMIO_READ(REG_CommandQueue);
+   } while ((engineState & SiS_EngIdle2d) != SiS_EngIdle2d);
 }
 
 /* To be called from mWait3DCmdQueue.  Separate function for profiling
  * purposes, and speed doesn't matter because we're spinning anyway.
- * This function should use usleeps to release cpu probably, but I have yet
- * to see it get called.
  */
 void
 WaitingFor3dIdle(sisContextPtr smesa, int wLen)
 {
-   while ( *(smesa->CurrentQueueLenPtr) < wLen) {
+   while (*(smesa->CurrentQueueLenPtr) < wLen) {
       *(smesa->CurrentQueueLenPtr) =
-         (*(GLint *)(GET_IOBase(smesa) + REG_QueueLen) & MASK_QueueLen) - 20;
+         (MMIO_READ(REG_CommandQueue) & MASK_QueueLen) - 20;
    }
 }
 
@@ -117,19 +110,26 @@ sisCreateContext( const __GLcontextModes *glVisual,
    sisContextPtr smesa;
    sisScreenPtr sisScreen;
    int i;
+   struct dd_function_table functions;
 
    smesa = (sisContextPtr)CALLOC( sizeof(*smesa) );
-   if ( smesa == NULL )
+   if (smesa == NULL)
       return GL_FALSE;
 
+   /* Init default driver functions then plug in our SIS-specific functions
+    * (the texture functions are especially important)
+    */
+   _mesa_init_driver_functions(&functions);
+   sisInitTextureFuncs(&functions);
+
    /* Allocate the Mesa context */
    if (sharedContextPrivate)
       shareCtx = ((sisContextPtr)sharedContextPrivate)->glCtx;
    else 
       shareCtx = NULL;
-   smesa->glCtx = _mesa_create_context( glVisual, shareCtx, (void *) smesa,
-      GL_TRUE);
-   if (smesa->glCtx == NULL) {
+   smesa->glCtx = _mesa_create_context( glVisual, shareCtx,
+                                        &functions, (void *) smesa);
+   if (!smesa->glCtx) {
       FREE(smesa);
       return GL_FALSE;
    }
@@ -184,6 +184,10 @@ sisCreateContext( const __GLcontextModes *glVisual,
       assert (0);
    }
 
+   /* Parse configuration files */
+   driParseConfigFiles (&smesa->optionCache, &sisScreen->optionCache,
+                       sisScreen->driScreen->myNum, "sis");
+
    /* TODO: index mode */
 
    smesa->CurrentQueueLenPtr = &(smesa->sarea->QueueLength);
@@ -195,16 +199,17 @@ sisCreateContext( const __GLcontextModes *glVisual,
    smesa->AGPAddr = sisScreen->agp.handle;
 
    /* set AGP command buffer */
-   smesa->AGPCmdModeEnabled = GL_FALSE;
-   if (smesa->AGPSize != 0 && getenv("SIS_NO_AGP") == NULL) {  
-      if (sisScreen->AGPCmdBufSize != 0) {
-         smesa->AGPCmdBufBase = smesa->AGPBase + sisScreen->AGPCmdBufOffset;
-         smesa->AGPCmdBufAddr = smesa->AGPAddr + sisScreen->AGPCmdBufOffset;
-         smesa->AGPCmdBufSize = sisScreen->AGPCmdBufSize;
-
-         smesa->pAGPCmdBufNext = (GLint *)&(smesa->sarea->AGPCmdBufNext);
-         smesa->AGPCmdModeEnabled = GL_TRUE;
-      }
+   if (smesa->AGPSize != 0 && sisScreen->AGPCmdBufSize != 0 &&
+      !driQueryOptionb(&smesa->optionCache, "agp_disable"))
+   {   
+      smesa->AGPCmdBufBase = smesa->AGPBase + sisScreen->AGPCmdBufOffset;
+      smesa->AGPCmdBufAddr = smesa->AGPAddr + sisScreen->AGPCmdBufOffset;
+      smesa->AGPCmdBufSize = sisScreen->AGPCmdBufSize;
+
+      smesa->pAGPCmdBufNext = (GLint *)&(smesa->sarea->AGPCmdBufNext);
+      smesa->AGPCmdModeEnabled = GL_TRUE;
+   } else {
+      smesa->AGPCmdModeEnabled = GL_FALSE;
    }
 
    smesa->GlobalFlag = 0L;
@@ -218,14 +223,18 @@ sisCreateContext( const __GLcontextModes *glVisual,
    _tnl_CreateContext( ctx );
    _swsetup_CreateContext( ctx );
 
+   _swrast_allow_pixel_fog( ctx, GL_TRUE );
+   _swrast_allow_vertex_fog( ctx, GL_FALSE );
+   _tnl_allow_pixel_fog( ctx, GL_TRUE );
+   _tnl_allow_vertex_fog( ctx, GL_FALSE );
+
+   /* XXX these should really go right after _mesa_init_driver_functions() */
    sisDDInitStateFuncs( ctx );
    sisDDInitState( smesa );    /* Initializes smesa->zFormat, important */
    sisInitVB( ctx );
    sisInitTriFuncs( ctx );
-   sisDDInitDriverFuncs( ctx );
    sisDDInitSpanFuncs( ctx );
    sisDDInitStencilFuncs( ctx );
-   sisDDInitTextureFuncs( ctx );
 
    driInitExtensions( ctx, card_extensions, GL_FALSE );
 
@@ -486,12 +495,12 @@ sis_update_texture_state (sisContextPtr smesa)
    /* texture environment */
    if (smesa->GlobalFlag & GFLAG_TEXTUREENV) {
       MMIO(REG_3D_TextureBlendFactor, prev->hwTexEnvColor);
-      MMIO(REG_3D_TextureColorBlendSet0, prev->hwTexBlendClr0);
+      MMIO(REG_3D_TextureColorBlendSet0, prev->hwTexBlendColor0);
       MMIO(REG_3D_TextureAlphaBlendSet0, prev->hwTexBlendAlpha0);
    }
    if (smesa->GlobalFlag & GFLAG_TEXTUREENV_1) {
       MMIO(REG_3D_TextureBlendFactor, prev->hwTexEnvColor);
-      MMIO(REG_3D_TextureColorBlendSet1, prev->hwTexBlendClr1);
+      MMIO(REG_3D_TextureColorBlendSet1, prev->hwTexBlendColor1);
       MMIO(REG_3D_TextureAlphaBlendSet1, prev->hwTexBlendAlpha1);
    }