Minor r200 vertex program cleanups. Remove disabled leftovers from r300 vertex progra...
[mesa.git] / src / mesa / drivers / dri / i810 / i810context.c
index f8fcc1f1f38af093f25cbd30950826e68fc160fa..23373ef73b1dd8f5ab2488372bc7f593bb3a33db 100644 (file)
@@ -38,6 +38,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "matrix.h"
 #include "simple_list.h"
 #include "extensions.h"
+#include "framebuffer.h"
 #include "imports.h"
 
 #include "swrast/swrast.h"
@@ -47,6 +48,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "tnl/t_pipeline.h"
 
+#include "drivers/common/driverfuncs.h"
+
 #include "i810screen.h"
 #include "i810_dri.h"
 
@@ -57,21 +60,44 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "i810vb.h"
 #include "i810ioctl.h"
 
+#include "drirenderbuffer.h"
 #include "utils.h"
+
+#define need_GL_ARB_multisample
+#define need_GL_ARB_texture_compression
+#include "extension_helper.h"
+
 #ifndef I810_DEBUG
 int I810_DEBUG = (0);
 #endif
 
-const char __driConfigOptions[] = { 0 };
+PUBLIC const char __driConfigOptions[] = { 0 };
 const GLuint __driNConfigOptions = 0;
 
+#define DRIVER_DATE                     "20050821"
+
 static const GLubyte *i810GetString( GLcontext *ctx, GLenum name )
 {
+   static char buffer[128];
+
    switch (name) {
    case GL_VENDOR:
       return (GLubyte *)"Keith Whitwell";
-   case GL_RENDERER:
-      return (GLubyte *)"Mesa DRI I810 20021125";
+   case GL_RENDERER: {
+      i810ContextPtr imesa = I810_CONTEXT(ctx);
+      const char * chipset;
+      
+      switch (imesa->i810Screen->deviceID) {
+      case PCI_CHIP_I810:       chipset = "i810"; break;
+      case PCI_CHIP_I810_DC100: chipset = "i810 DC-100"; break;
+      case PCI_CHIP_I810_E:     chipset = "i810E"; break;
+      case PCI_CHIP_I815:       chipset = "i815"; break;
+      default:                  chipset = "Unknown i810-class Chipset"; break;
+      }
+
+      (void) driGetRendererString( buffer, chipset, DRIVER_DATE, 0 );
+      return (GLubyte *) buffer;
+   }
    default:
       return 0;
    }
@@ -94,20 +120,24 @@ static void i810BufferSize(GLframebuffer *buffer, GLuint *width, GLuint *height)
 
 /* Extension strings exported by the i810 driver.
  */
-static const char * const card_extensions[] =
+const struct dri_extension card_extensions[] =
 {
-   "GL_ARB_multitexture",
-   "GL_ARB_texture_env_add",
-   "GL_ARB_texture_mirrored_repeat",
-   "GL_EXT_stencil_wrap",
-   "GL_EXT_texture_edge_clamp",
-   "GL_EXT_texture_env_add",
-   "GL_EXT_texture_lod_bias",
-   "GL_IBM_texture_mirrored_repeat",
-   "GL_MESA_ycbcr_texture",
-   "GL_SGIS_generate_mipmap",
-   "GL_SGIS_texture_edge_clamp",
-   NULL
+    { "GL_ARB_multisample",                GL_ARB_multisample_functions },
+    { "GL_ARB_multitexture",               NULL },
+    { "GL_ARB_texture_compression",        GL_ARB_texture_compression_functions },
+    { "GL_ARB_texture_env_add",            NULL },
+    { "GL_ARB_texture_env_combine",        NULL },
+    { "GL_ARB_texture_env_crossbar",       NULL },
+    { "GL_ARB_texture_mirrored_repeat",    NULL },
+    { "GL_EXT_stencil_wrap",               NULL },
+    { "GL_EXT_texture_edge_clamp",         NULL },
+    { "GL_EXT_texture_env_combine",        NULL },
+    { "GL_EXT_texture_lod_bias",           NULL },
+    { "GL_EXT_texture_rectangle",          NULL },
+    { "GL_MESA_ycbcr_texture",             NULL },
+    { "GL_NV_blend_square",                NULL },
+    { "GL_SGIS_generate_mipmap",           NULL },
+    { NULL,                                NULL }
 };
 
 extern const struct tnl_pipeline_stage _i810_render_stage;
@@ -155,6 +185,7 @@ i810CreateContext( const __GLcontextModes *mesaVis,
    i810ScreenPrivate *i810Screen = (i810ScreenPrivate *)sPriv->private;
    I810SAREAPtr saPriv = (I810SAREAPtr)
       (((GLubyte *)sPriv->pSAREA) + i810Screen->sarea_priv_offset);
+   struct dd_function_table functions;
 
    /* Allocate i810 context */
    imesa = (i810ContextPtr) CALLOC_STRUCT(i810_context_t);
@@ -162,22 +193,32 @@ i810CreateContext( const __GLcontextModes *mesaVis,
       return GL_FALSE;
    }
 
+   driContextPriv->driverPrivate = imesa;
+
+   imesa->i810Screen = i810Screen;
+   imesa->driScreen = sPriv;
+   imesa->sarea = saPriv;
+   imesa->glBuffer = NULL;
+
+   /* Init default driver functions then plug in our I810-specific functions
+    * (the texture functions are especially important)
+    */
+   _mesa_init_driver_functions( &functions );
+   i810InitIoctlFuncs( &functions );
+   i810InitTextureFuncs( &functions );
+
+
    /* Allocate the Mesa context */
    if (sharedContextPrivate)
       shareCtx = ((i810ContextPtr) sharedContextPrivate)->glCtx;
    else
       shareCtx = NULL;
-   imesa->glCtx = _mesa_create_context(mesaVis, shareCtx, (void*) imesa, GL_TRUE);
+   imesa->glCtx = _mesa_create_context(mesaVis, shareCtx,
+                                       &functions, (void*) imesa);
    if (!imesa->glCtx) {
       FREE(imesa);
       return GL_FALSE;
    }
-   driContextPriv->driverPrivate = imesa;
-
-   imesa->i810Screen = i810Screen;
-   imesa->driScreen = sPriv;
-   imesa->sarea = saPriv;
-   imesa->glBuffer = NULL;
 
    (void) memset( imesa->texture_heaps, 0, sizeof( imesa->texture_heaps ) );
    make_empty_list( & imesa->swapped );
@@ -188,7 +229,7 @@ i810CreateContext( const __GLcontextModes *mesaVis,
            12,
            I810_NR_TEX_REGIONS,
            imesa->sarea->texList,
-           & imesa->sarea->texAge,
+           (unsigned *) & imesa->sarea->texAge, /* XXX we shouldn't cast! */
            & imesa->swapped,
            sizeof( struct i810_texture_object_t ),
            (destroy_texture_object_t *) i810DestroyTexObj );
@@ -220,7 +261,8 @@ i810CreateContext( const __GLcontextModes *mesaVis,
                                 0,  /* cube textures unsupported. */
                                 0,  /* texture rectangles unsupported. */
                                 12,
-                                GL_FALSE );
+                                GL_FALSE,
+                                0 );
 
    ctx->Const.MinLineWidth = 1.0;
    ctx->Const.MinLineWidthAA = 1.0;
@@ -235,7 +277,7 @@ i810CreateContext( const __GLcontextModes *mesaVis,
    ctx->Const.PointSizeGranularity = 1.0;
 
    ctx->Driver.GetBufferSize = i810BufferSize;
-   ctx->Driver.ResizeBuffers = _swrast_alloc_buffers;
+   ctx->Driver.ResizeBuffers = _mesa_resize_framebuffer;
    ctx->Driver.GetString = i810GetString;
 
    /* Who owns who?
@@ -255,10 +297,12 @@ i810CreateContext( const __GLcontextModes *mesaVis,
    _tnl_destroy_pipeline( ctx );
    _tnl_install_pipeline( ctx, i810_pipeline );
 
-   /* Configure swrast to match hardware characteristics:
+   /* Configure swrast and T&L to match hardware characteristics:
     */
    _swrast_allow_pixel_fog( ctx, GL_FALSE );
    _swrast_allow_vertex_fog( ctx, GL_TRUE );
+   _tnl_allow_pixel_fog( ctx, GL_FALSE );
+   _tnl_allow_vertex_fog( ctx, GL_TRUE );
 
    /* Dri stuff
     */
@@ -277,11 +321,10 @@ i810CreateContext( const __GLcontextModes *mesaVis,
    _math_matrix_ctr( &imesa->ViewportMatrix );
 
    driInitExtensions( ctx, card_extensions, GL_TRUE );
+   /* XXX these should really go right after _mesa_init_driver_functions() */
    i810InitStateFuncs( ctx );
-   i810InitTextureFuncs( ctx );
    i810InitTriFuncs( ctx );
    i810InitSpanFuncs( ctx );
-   i810InitIoctlFuncs( ctx );
    i810InitVB( ctx );
    i810InitState( ctx );
 
@@ -320,7 +363,7 @@ i810DestroyContext(__DRIcontextPrivate *driContextPriv)
         /* This share group is about to go away, free our private
           * texture object data.
           */
-         int i;
+        unsigned int i;
 
          for ( i = 0 ; i < imesa->nr_heaps ; i++ ) {
            driDestroyTextureHeap( imesa->texture_heaps[ i ] );
@@ -330,7 +373,7 @@ i810DestroyContext(__DRIcontextPrivate *driContextPriv)
         assert( is_empty_list( & imesa->swapped ) );
       }
 
-      Xfree(imesa);
+      FREE(imesa);
    }
 }
 
@@ -373,14 +416,14 @@ void i810XMesaSetBackClipRects( i810ContextPtr imesa )
 
 static void i810XMesaWindowMoved( i810ContextPtr imesa )
 {
-   switch (imesa->glCtx->Color._DrawDestMask) {
-   case FRONT_LEFT_BIT:
+   /* Determine current color drawing buffer */
+   switch (imesa->glCtx->DrawBuffer->_ColorDrawBufferMask[0]) {
+   case BUFFER_BIT_FRONT_LEFT:
       i810XMesaSetFrontClipRects( imesa );
       break;
-   case BACK_LEFT_BIT:
+   case BUFFER_BIT_BACK_LEFT:
       i810XMesaSetBackClipRects( imesa );
       break;
-   case GL_FRONT_LEFT:
    default:
       /* glDrawBuffer(GL_NONE or GL_FRONT_AND_BACK): software fallback */
       i810XMesaSetFrontClipRects( imesa );
@@ -414,19 +457,16 @@ i810MakeCurrent(__DRIcontextPrivate *driContextPriv,
        */
       imesa->driDrawable = driDrawPriv;
 
-      _mesa_make_current2(imesa->glCtx,
-                          (GLframebuffer *) driDrawPriv->driverPrivate,
-                          (GLframebuffer *) driReadPriv->driverPrivate);
+      _mesa_make_current(imesa->glCtx,
+                         (GLframebuffer *) driDrawPriv->driverPrivate,
+                         (GLframebuffer *) driReadPriv->driverPrivate);
 
       /* Are these necessary?
        */
       i810XMesaWindowMoved( imesa );
-      if (!imesa->glCtx->Viewport.Width)
-        _mesa_set_viewport(imesa->glCtx, 0, 0,
-                            driDrawPriv->w, driDrawPriv->h);
    }
    else {
-      _mesa_make_current(0,0);
+      _mesa_make_current(NULL, NULL, NULL);
    }
 
    return GL_TRUE;
@@ -438,11 +478,12 @@ i810UpdatePageFlipping( i810ContextPtr imesa )
    GLcontext *ctx = imesa->glCtx;
    int front = 0;
 
-   switch (ctx->Color._DrawDestMask) {
-   case FRONT_LEFT_BIT:
+   /* Determine current color drawing buffer */
+   switch (ctx->DrawBuffer->_ColorDrawBufferMask[0]) {
+   case BUFFER_BIT_FRONT_LEFT:
       front = 1;
       break;
-   case BACK_LEFT_BIT:
+   case BUFFER_BIT_BACK_LEFT:
       front = 0;
       break;
    default:
@@ -451,15 +492,13 @@ i810UpdatePageFlipping( i810ContextPtr imesa )
 
    if ( imesa->sarea->pf_current_page == 1 ) 
      front ^= 1;
+
+   driFlipRenderbuffers(ctx->WinSysDrawBuffer, front);
    
    if (front) {
       imesa->BufferSetup[I810_DESTREG_DI1] = imesa->i810Screen->fbOffset | imesa->i810Screen->backPitchBits;
-      imesa->drawMap = (char *)imesa->driScreen->pFB;
-      imesa->readMap = (char *)imesa->driScreen->pFB;
    } else {
       imesa->BufferSetup[I810_DESTREG_DI1] = imesa->i810Screen->backOffset | imesa->i810Screen->backPitchBits;
-      imesa->drawMap = imesa->i810Screen->back.map;
-      imesa->readMap = imesa->i810Screen->back.map;
    }
 
    imesa->dirty |= I810_UPLOAD_BUFFERS;
@@ -489,6 +528,7 @@ void i810GetLock( i810ContextPtr imesa, GLuint flags )
     * more broken than usual.
     */
    if (sarea->ctxOwner != me) {
+      driUpdateFramebufferSize(imesa->glCtx, dPriv);
       imesa->upload_cliprects = GL_TRUE;
       imesa->dirty = I810_UPLOAD_CTX|I810_UPLOAD_BUFFERS;
       if (imesa->CurrentTexObj[0]) imesa->dirty |= I810_UPLOAD_TEX0;