On the way to getting stencil working.
[mesa.git] / src / mesa / drivers / dri / sis / sis_context.c
index e580a405f04eee36203df3fc13273372f6d83b3e..3b23b7df4e55f26daa2c35d1ccf33e64ea02c9cb 100644 (file)
@@ -41,7 +41,7 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "sis_stencil.h"
 #include "sis_tex.h"
 #include "sis_tris.h"
-#include "sis_vb.h"
+#include "sis_alloc.h"
 
 #include "imports.h"
 #include "matrix.h"
@@ -65,6 +65,7 @@ static const char * const card_extensions[] =
 {
    "GL_ARB_multitexture",
    "GL_EXT_texture_lod_bias",
+   "GL_NV_blend_square",
    NULL
 };
 
@@ -120,6 +121,7 @@ sisCreateContext( const __GLcontextModes *glVisual,
     * (the texture functions are especially important)
     */
    _mesa_init_driver_functions(&functions);
+   sisInitDriverFuncs(&functions);
    sisInitTextureFuncs(&functions);
 
    /* Allocate the Mesa context */
@@ -181,7 +183,7 @@ sisCreateContext( const __GLcontextModes *glVisual,
       smesa->colorFormat = DST_FORMAT_RGB_565;
       break;
    default:
-      assert (0);
+      sis_fatal_error("Bad bytesPerPixel.\n");
    }
 
    /* Parse configuration files */
@@ -198,18 +200,29 @@ sisCreateContext( const __GLcontextModes *glVisual,
    smesa->AGPBase = sisScreen->agp.map;
    smesa->AGPAddr = sisScreen->agp.handle;
 
-   /* set AGP command buffer */
-   if (smesa->AGPSize != 0 && sisScreen->AGPCmdBufSize != 0 &&
+   /* Create AGP command buffer */
+   if (smesa->AGPSize != 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->vb = sisAllocAGP(smesa, 64 * 1024, &smesa->vb_agp_handle);
+      if (smesa->vb != NULL) {
+        smesa->using_agp = GL_TRUE;
+        smesa->vb_cur = smesa->vb;
+        smesa->vb_last = smesa->vb;
+        smesa->vb_end = smesa->vb + 64 * 1024;
+        smesa->vb_agp_offset = ((long)smesa->vb - (long)smesa->AGPBase +
+           (long)smesa->AGPAddr);
+      }
+   }
+   if (!smesa->using_agp) {
+      smesa->vb = malloc(64 * 1024);
+      if (smesa->vb == NULL) {
+        FREE(smesa);
+        return GL_FALSE;
+      }
+      smesa->vb_cur = smesa->vb;
+      smesa->vb_last = smesa->vb;
+      smesa->vb_end = smesa->vb + 64 * 1024;
    }
 
    smesa->GlobalFlag = 0L;
@@ -231,7 +244,6 @@ sisCreateContext( const __GLcontextModes *glVisual,
    /* XXX these should really go right after _mesa_init_driver_functions() */
    sisDDInitStateFuncs( ctx );
    sisDDInitState( smesa );    /* Initializes smesa->zFormat, important */
-   sisInitVB( ctx );
    sisInitTriFuncs( ctx );
    sisDDInitSpanFuncs( ctx );
    sisDDInitStencilFuncs( ctx );
@@ -263,6 +275,9 @@ sisDestroyContext ( __DRIcontextPrivate *driContextPriv )
       _ac_DestroyContext( smesa->glCtx );
       _swrast_DestroyContext( smesa->glCtx );
 
+      if (smesa->using_agp)
+        sisFreeAGP(smesa, smesa->vb_agp_handle);
+
       /* free the Mesa context */
       /* XXX: Is the next line needed?  The DriverCtx (smesa) reference is
        * needed for sisDDDeleteTexture, since it needs to call the FB/AGP free
@@ -297,11 +312,6 @@ sisMakeCurrent( __DRIcontextPrivate *driContextPriv,
 
       sisUpdateBufferSize( newSisCtx );
       sisUpdateClipping( newSisCtx->glCtx );
-
-      if ( newSisCtx->glCtx->Viewport.Width == 0 ) {
-         _mesa_set_viewport(newSisCtx->glCtx, 0, 0,
-                            driDrawPriv->w, driDrawPriv->h);
-      }
    } else {
       _mesa_make_current( 0, 0 );
    }
@@ -507,11 +517,3 @@ sis_update_texture_state (sisContextPtr smesa)
    smesa->GlobalFlag &= ~GFLAG_TEXTURE_STATES;
 }
 
-void
-sis_fatal_error (void)
-{
-   /* free video memory, or the framebuffer device will do it automatically */
-
-   fprintf(stderr, "Fatal errors in sis_dri.so\n");
-   exit (-1);
-}