OSDN Git Service

Use the new software rasterizer. Reworked optimized line,tri,point
authorKeith Whitwell <keith@tungstengraphics.com>
Sun, 5 Nov 2000 18:26:12 +0000 (18:26 +0000)
committerKeith Whitwell <keith@tungstengraphics.com>
Sun, 5 Nov 2000 18:26:12 +0000 (18:26 +0000)
functions to fit into the framework provided for extending the
software rasterizer.

src/mesa/drivers/x11/xm_api.c
src/mesa/drivers/x11/xm_dd.c
src/mesa/drivers/x11/xm_line.c
src/mesa/drivers/x11/xm_tri.c
src/mesa/drivers/x11/xmesaP.h

index 6e8fa3c..3120b24 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: xm_api.c,v 1.5 2000/10/31 18:09:46 keithw Exp $ */
+/* $Id: xm_api.c,v 1.6 2000/11/05 18:26:12 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -77,6 +77,7 @@
 #endif
 #include "macros.h"
 #include "swrast/swrast.h"
+#include "swrast_setup/swrast_setup.h"
 
 #ifndef GLX_NONE_EXT
 #define GLX_NONE_EXT 0x8000
@@ -1616,6 +1617,7 @@ void XMesaDestroyVisual( XMesaVisual v )
 XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list )
 {
    XMesaContext c;
+   GLcontext *ctx;
    GLboolean direct = GL_TRUE; /* XXXX */
    /* NOT_DONE: should this be GL_FALSE??? */
    static GLboolean firstTime = GL_TRUE;
@@ -1630,7 +1632,7 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list )
       return NULL;
    }
 
-   c->gl_ctx = _mesa_create_context( v->gl_visual,
+   ctx = c->gl_ctx = _mesa_create_context( v->gl_visual,
                       share_list ? share_list->gl_ctx : (GLcontext *) NULL,
                       (void *) c, direct );
    if (!c->gl_ctx) {
@@ -1638,9 +1640,9 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list )
       return NULL;
    }
 
-   gl_extensions_enable(c->gl_ctx, "GL_HP_occlusion_test");
-   gl_extensions_enable(c->gl_ctx, "GL_ARB_texture_cube_map");
-   gl_extensions_enable(c->gl_ctx, "GL_EXT_texture_env_combine");
+   gl_extensions_enable(ctx, "GL_HP_occlusion_test");
+   gl_extensions_enable(ctx, "GL_ARB_texture_cube_map");
+   gl_extensions_enable(ctx, "GL_EXT_texture_env_combine");
 
    if (CHECK_BYTE_ORDER(v)) {
       c->swapbytes = GL_FALSE;
@@ -1654,30 +1656,32 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list )
    c->display = v->display;
    c->pixelformat = v->dithered_pf;      /* Dithering is enabled by default */
 
-   c->gl_ctx->Driver.UpdateState = xmesa_update_state;
-
-   /* These flags cover all the tests made in UpdateState, plus what
-    * the software rasterizer needs to choose line,point and triangle
-    * functions.
-    */
-   c->gl_ctx->Driver.UpdateStateNotify = (_NEW_POINT|
-                                         _NEW_TEXTURE|
-                                         _NEW_LINE|
-                                         _NEW_LIGHT|
-                                         _NEW_DEPTH|
-                                         _NEW_POLYGON|
-                                         _NEW_TEXTURE|
-                                         _SWRAST_NEW_RASTERMASK|
-                                         _SWRAST_NEW_TRIANGLE|
-                                         _SWRAST_NEW_LINE|
-                                         _SWRAST_NEW_POINT);
+   ctx->Driver.UpdateState = xmesa_update_state;
+   ctx->Driver.UpdateStateNotify = ~0;
 
 #if defined(GLX_DIRECT_RENDERING) && !defined(XFree86Server)
    c->driContextPriv = driContextPriv;
 #endif
 
-   /* Run the config file */
-   _mesa_context_initialize( c->gl_ctx );
+   /* Set up some constant pointers:
+    */
+   xmesa_init_pointers( ctx );
+
+   if (ctx->VB) 
+      _swsetup_RegisterVB( ctx->VB );
+
+
+   /* Initialize the software rasterizer and helper modules.
+    */
+   _swrast_CreateContext( ctx );
+   _swsetup_CreateContext( ctx );
+
+   xmesa_register_swrast_functions( ctx );
+
+   /* Run the config file 
+    */
+   _mesa_context_initialize( ctx );
+
 
    return c;
 }
@@ -1691,8 +1695,11 @@ void XMesaDestroyContext( XMesaContext c )
    if (c->xm_buffer && c->xm_buffer->FXctx)
       fxMesaDestroyContext(c->xm_buffer->FXctx);
 #endif
-   if (c->gl_ctx)
+   if (c->gl_ctx) {
+      _swsetup_DestroyContext( c->gl_ctx );
+      _swrast_DestroyContext( c->gl_ctx );
       _mesa_destroy_context( c->gl_ctx );
+   }
 
    /* Disassociate old buffer with this context */
    if (c->xm_buffer)
index f10684d..79adf4e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: xm_dd.c,v 1.2 2000/09/08 21:44:57 brianp Exp $ */
+/* $Id: xm_dd.c,v 1.3 2000/11/05 18:26:12 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -36,7 +36,8 @@
 #include "types.h"
 #include "xmesaP.h"
 #include "extensions.h"
-
+#include "swrast/swrast.h"
+#include "swrast_setup/swrast_setup.h"
 
 /*
  * Return the size (width,height of the current color buffer.
@@ -142,40 +143,6 @@ flush( GLcontext *ctx )
 }
 
 
-#if 0
-static GLboolean
-set_buffer( GLcontext *ctx, GLenum mode )
-{
-   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   if (mode == GL_FRONT_LEFT) {
-      /* read/write front buffer */
-      xmesa->xm_buffer->buffer = xmesa->xm_buffer->frontbuffer;
-      ctx->NewState |= NEW_RASTER_OPS;
-      gl_update_state(ctx);
-      return GL_TRUE;
-   }
-   else if (mode==GL_BACK_LEFT && xmesa->xm_buffer->db_state) {
-      /* read/write back buffer */
-      if (xmesa->xm_buffer->backpixmap) {
-         xmesa->xm_buffer->buffer =
-            (XMesaDrawable)xmesa->xm_buffer->backpixmap;
-      }
-      else if (xmesa->xm_buffer->backimage) {
-         xmesa->xm_buffer->buffer = None;
-      }
-      else {
-         /* just in case there wasn't enough memory for back buffer */
-         xmesa->xm_buffer->buffer = xmesa->xm_buffer->frontbuffer;
-      }
-      ctx->NewState |= NEW_RASTER_OPS;
-      gl_update_state(ctx);
-      return GL_TRUE;
-   }
-   else {
-      return GL_FALSE;
-   }
-}
-#endif
 
 
 static GLboolean
@@ -823,7 +790,7 @@ clear_buffers( GLcontext *ctx, GLbitfield mask,
 
 
 
-#ifndef XFree86Server
+#if 0
 /*
  * This function implements glDrawPixels() with an XPutImage call when
  * drawing to the front buffer (X Window drawable).
@@ -922,27 +889,59 @@ enable( GLcontext *ctx, GLenum pname, GLboolean state )
 }
 
 
-
-/*
- * Initialize all the DD.* function pointers depending on the color
- * buffer configuration.  This is mainly called by XMesaMakeCurrent.
- */
-void
-xmesa_update_state( GLcontext *ctx )
+void xmesa_update_state( GLcontext *ctx )
 {
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   /*int depth=GET_VISUAL_DEPTH(xmesa->xm_visual);*/
-
-   (void) DitherValues;  /* silenced unused var warning */
-#ifndef XFree86Server
-   (void) drawpixels_8R8G8B;
-#endif
+   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
-   /*
-    * Always the same:
+   /* Propogate statechange information to swrast and swrast_setup
+    * modules.  The X11 driver has no internal GL-dependent state.
     */
+   _swrast_InvalidateState( ctx, ctx->NewState );
+   _swsetup_InvalidateState( ctx, ctx->NewState );
+
+
+   /* setup pointers to front and back buffer clear functions */
+   xmesa->xm_buffer->front_clear_func = clear_front_pixmap;
+   if (xmesa->xm_buffer->backpixmap != XIMAGE) {
+      xmesa->xm_buffer->back_clear_func = clear_back_pixmap;
+   }
+   else if (sizeof(GLushort)!=2 || sizeof(GLuint)!=4) {
+      xmesa->xm_buffer->back_clear_func = clear_nbit_ximage;
+   }
+   else switch (xmesa->xm_visual->BitsPerPixel) {
+   case 8:
+      if (xmesa->xm_visual->hpcr_clear_flag) {
+        xmesa->xm_buffer->back_clear_func = clear_HPCR_ximage;
+      }
+      else {
+        xmesa->xm_buffer->back_clear_func = clear_8bit_ximage;
+      }
+      break;
+   case 16:
+      xmesa->xm_buffer->back_clear_func = clear_16bit_ximage;
+      break;
+   case 24:
+      xmesa->xm_buffer->back_clear_func = clear_24bit_ximage;
+      break;
+   case 32:
+      xmesa->xm_buffer->back_clear_func = clear_32bit_ximage;
+      break;
+   default:
+      xmesa->xm_buffer->back_clear_func = clear_nbit_ximage;
+      break;
+   }
+
+   xmesa_update_span_funcs(ctx); 
+}
+
+
+
+/* Setup pointers and other driver state that is constant for the life
+ * of a context.
+ */
+void xmesa_init_pointers( GLcontext *ctx )
+{
    ctx->Driver.GetString = get_string;
-   ctx->Driver.UpdateState = xmesa_update_state;
    ctx->Driver.GetBufferSize = get_buffer_size;
    ctx->Driver.Flush = flush;
    ctx->Driver.Finish = finish;
@@ -962,48 +961,13 @@ xmesa_update_state( GLcontext *ctx )
    ctx->Driver.ColorMask = color_mask;
    ctx->Driver.Enable = enable;
 
-   ctx->Driver.PointsFunc = xmesa_get_points_func( ctx );
-   ctx->Driver.LineFunc = xmesa_get_line_func( ctx );
-   ctx->Driver.TriangleFunc = xmesa_get_triangle_func( ctx );
+   ctx->Driver.PointsFunc = _swsetup_Points;
+   ctx->Driver.LineFunc = _swsetup_Line;
+   ctx->Driver.TriangleFunc = _swsetup_Triangle;
+   ctx->Driver.QuadFunc = _swsetup_Quad;
+   ctx->Driver.RasterSetup = _swsetup_RasterSetup;
+   ctx->Driver.RegisterVB = _swsetup_RegisterVB;
+   ctx->Driver.UnregisterVB = _swsetup_UnregisterVB;
 
-/*     ctx->Driver.TriangleCaps = DD_TRI_CULL; */
-
-   /* setup pointers to front and back buffer clear functions */
-   /* XXX this bit of code could be moved to a one-time init */
-   xmesa->xm_buffer->front_clear_func = clear_front_pixmap;
-   if (xmesa->xm_buffer->backpixmap != XIMAGE) {
-      /* back buffer is a pixmap */
-      xmesa->xm_buffer->back_clear_func = clear_back_pixmap;
-   }
-   else if (sizeof(GLushort)!=2 || sizeof(GLuint)!=4) {
-      /* Do this on Crays */
-      xmesa->xm_buffer->back_clear_func = clear_nbit_ximage;
-   }
-   else {
-      /* Do this on most machines */
-      switch (xmesa->xm_visual->BitsPerPixel) {
-         case 8:
-           if (xmesa->xm_visual->hpcr_clear_flag) {
-               xmesa->xm_buffer->back_clear_func = clear_HPCR_ximage;
-            }
-            else {
-               xmesa->xm_buffer->back_clear_func = clear_8bit_ximage;
-            }
-            break;
-         case 16:
-            xmesa->xm_buffer->back_clear_func = clear_16bit_ximage;
-            break;
-         case 24:
-            xmesa->xm_buffer->back_clear_func = clear_24bit_ximage;
-            break;
-         case 32:
-            xmesa->xm_buffer->back_clear_func = clear_32bit_ximage;
-            break;
-         default:
-            xmesa->xm_buffer->back_clear_func = clear_nbit_ximage;
-            break;
-      }
-   }
-
-   xmesa_update_span_funcs(ctx);
+   (void) DitherValues;  /* silenced unused var warning */
 }
index ac8713f..00e9df6 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: xm_line.c,v 1.5 2000/10/31 18:09:46 keithw Exp $ */
+/* $Id: xm_line.c,v 1.6 2000/11/05 18:26:12 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -42,6 +42,9 @@
 /* Internal swrast includes:
  */
 #include "swrast/s_depth.h"
+#include "swrast/s_points.h"
+#include "swrast/s_lines.h"
+#include "swrast/s_context.h"
 
 
 /**********************************************************************/
 /*
  * Render an array of points into a pixmap, any pixel format.
  */
-static void draw_points_ANY_pixmap( GLcontext *ctx, GLuint first, GLuint last )
+static void draw_points_ANY_pixmap( GLcontext *ctx, SWvertex *vert )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
    XMesaDisplay *dpy = xmesa->xm_visual->display;
    XMesaDrawable buffer = xmesa->xm_buffer->buffer;
    XMesaGC gc = xmesa->xm_buffer->gc2;
-   struct vertex_buffer *VB = ctx->VB;
-   register GLuint i;
 
    if (xmesa->xm_visual->gl_visual->RGBAflag) {
-      /* RGB mode */
-      for (i=first;i<=last;i++) {
-         if (VB->ClipMask[i]==0) {
-            register int x, y;
-           const GLubyte *color = VB->ColorPtr->data[i];
-            unsigned long pixel = xmesa_color_to_pixel( xmesa,
-                          color[0], color[1], color[2], color[3], xmesa->pixelformat);
-            XMesaSetForeground( dpy, gc, pixel );
-            x =                         (GLint) VB->Win.data[i][0];
-            y = FLIP( xmesa->xm_buffer, (GLint) VB->Win.data[i][1] );
-            XMesaDrawPoint( dpy, buffer, gc, x, y);
-         }
-      }
+      register int x, y;
+      const GLubyte *color = vert->color;
+      unsigned long pixel = xmesa_color_to_pixel( xmesa,
+                                                 color[0], color[1], 
+                                                 color[2], color[3], 
+                                                 xmesa->pixelformat);
+      XMesaSetForeground( dpy, gc, pixel );
+      x =                         (GLint) vert->win[0];
+      y = FLIP( xmesa->xm_buffer, (GLint) vert->win[1] );
+      XMesaDrawPoint( dpy, buffer, gc, x, y);
    }
    else {
       /* Color index mode */
-      for (i=first;i<=last;i++) {
-         if (VB->ClipMask[i]==0) {
-            register int x, y;
-            XMesaSetForeground( dpy, gc, VB->IndexPtr->data[i] );
-            x =                         (GLint) VB->Win.data[i][0];
-            y = FLIP( xmesa->xm_buffer, (GLint) VB->Win.data[i][1] );
-            XMesaDrawPoint( dpy, buffer, gc, x, y);
-         }
-      }
+      register int x, y;
+      XMesaSetForeground( dpy, gc, vert->index );
+      x =                         (GLint) vert->win[0];
+      y = FLIP( xmesa->xm_buffer, (GLint) vert->win[1] );
+      XMesaDrawPoint( dpy, buffer, gc, x, y);
    }
 }
 
 
 
-/*
- * Analyze context state to see if we can provide a fast points drawing
- * function, like those in points.c.  Otherwise, return NULL.
+/* Override the swrast point-selection function.  Try to use one of
+ * our internal point functions, otherwise fall back to the standard
+ * swrast functions.
  */
-points_func xmesa_get_points_func( GLcontext *ctx )
+void xmesa_choose_point( GLcontext *ctx )
 {
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
 
-   if (ctx->Point.Size==1.0F && !ctx->Point.SmoothFlag && ctx->RasterMask==0
-       && !ctx->Texture.ReallyEnabled) {
-      if (xmesa->xm_buffer->buffer==XIMAGE) {
-         return (points_func) NULL; /*draw_points_ximage;*/
-      }
-      else {
-         return draw_points_ANY_pixmap;
-      }
+   if (ctx->Point.Size==1.0F && !ctx->Point.SmoothFlag 
+       && swrast->_RasterMask==0
+       && !ctx->Texture._ReallyEnabled) {
+      swrast->Point = draw_points_ANY_pixmap;
    }
-   else {
-      return (points_func) NULL;
+   else { 
+      _swrast_choose_point( ctx );
    }
 }
 
@@ -126,28 +116,27 @@ points_func xmesa_get_points_func( GLcontext *ctx )
  * Render a line into a pixmap, any pixel format.
  */
 static void flat_pixmap_line( GLcontext *ctx,
-                              GLuint vert0, GLuint vert1, GLuint pv )
+                              SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   struct vertex_buffer *VB = ctx->VB;
    register int x0, y0, x1, y1;
    XMesaGC gc;
    unsigned long pixel;
    if (xmesa->xm_visual->gl_visual->RGBAflag) {
-      const GLubyte *color = VB->ColorPtr->data[pv];
+      const GLubyte *color = vert0->color;
       pixel = xmesa_color_to_pixel( xmesa, color[0], color[1], color[2], color[3],
                                     xmesa->pixelformat );
    }
    else {
-      pixel = VB->IndexPtr->data[pv];
+      pixel = vert0->index;
    }
    gc = xmesa->xm_buffer->gc2;
    XMesaSetForeground( xmesa->display, gc, pixel );
 
-   x0 =                         (GLint) VB->Win.data[vert0][0];
-   y0 = FLIP( xmesa->xm_buffer, (GLint) VB->Win.data[vert0][1] );
-   x1 =                         (GLint) VB->Win.data[vert1][0];
-   y1 = FLIP( xmesa->xm_buffer, (GLint) VB->Win.data[vert1][1] );
+   x0 =                         (GLint) vert0->win[0];
+   y0 = FLIP( xmesa->xm_buffer, (GLint) vert0->win[1] );
+   x1 =                         (GLint) vert1->win[0];
+   y1 = FLIP( xmesa->xm_buffer, (GLint) vert1->win[1] );
    XMesaDrawLine( xmesa->display, xmesa->xm_buffer->buffer, gc,
                  x0, y0, x1, y1 );
 }
@@ -158,10 +147,10 @@ static void flat_pixmap_line( GLcontext *ctx,
  * Draw a flat-shaded, PF_TRUECOLOR line into an XImage.
  */
 static void flat_TRUECOLOR_line( GLcontext *ctx,
-                                 GLuint vert0, GLuint vert1, GLuint pv )
+                                 SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
    XMesaImage *img = xmesa->xm_buffer->backimage;
    unsigned long pixel;
    PACK_TRUECOLOR( pixel, color[0], color[1], color[2] );
@@ -179,10 +168,10 @@ static void flat_TRUECOLOR_line( GLcontext *ctx,
  * Draw a flat-shaded, PF_8A8B8G8R line into an XImage.
  */
 static void flat_8A8B8G8R_line( GLcontext *ctx,
-                                GLuint vert0, GLuint vert1, GLuint pv )
+                                SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
    GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] );
 
 #define PIXEL_TYPE GLuint
@@ -199,10 +188,10 @@ static void flat_8A8B8G8R_line( GLcontext *ctx,
  * Draw a flat-shaded, PF_8R8G8B line into an XImage.
  */
 static void flat_8R8G8B_line( GLcontext *ctx,
-                              GLuint vert0, GLuint vert1, GLuint pv )
+                              SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
    GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
 
 #define PIXEL_TYPE GLuint
@@ -219,10 +208,10 @@ static void flat_8R8G8B_line( GLcontext *ctx,
  * Draw a flat-shaded, PF_8R8G8B24 line into an XImage.
  */
 static void flat_8R8G8B24_line( GLcontext *ctx,
-                              GLuint vert0, GLuint vert1, GLuint pv )
+                              SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
 
 #define PIXEL_TYPE bgr_t
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
@@ -242,10 +231,10 @@ static void flat_8R8G8B24_line( GLcontext *ctx,
  * Draw a flat-shaded, PF_5R6G5B line into an XImage.
  */
 static void flat_5R6G5B_line( GLcontext *ctx,
-                              GLuint vert0, GLuint vert1, GLuint pv )
+                              SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
    GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] );
 
 #define PIXEL_TYPE GLushort
@@ -262,10 +251,10 @@ static void flat_5R6G5B_line( GLcontext *ctx,
  * Draw a flat-shaded, PF_DITHER_5R6G5B line into an XImage.
  */
 static void flat_DITHER_5R6G5B_line( GLcontext *ctx,
-                                     GLuint vert0, GLuint vert1, GLuint pv )
+                                     SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
 
 #define PIXEL_TYPE GLushort
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
@@ -282,10 +271,10 @@ static void flat_DITHER_5R6G5B_line( GLcontext *ctx,
  * Draw a flat-shaded, PF_DITHER 8-bit line into an XImage.
  */
 static void flat_DITHER8_line( GLcontext *ctx,
-                               GLuint vert0, GLuint vert1, GLuint pv )
+                               SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
    GLint r = color[0], g = color[1], b = color[2];
    DITHER_SETUP;
 
@@ -304,10 +293,10 @@ static void flat_DITHER8_line( GLcontext *ctx,
  * Draw a flat-shaded, PF_LOOKUP 8-bit line into an XImage.
  */
 static void flat_LOOKUP8_line( GLcontext *ctx,
-                               GLuint vert0, GLuint vert1, GLuint pv )
+                               SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
    GLubyte pixel;
    LOOKUP_SETUP;
    pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] );
@@ -326,10 +315,10 @@ static void flat_LOOKUP8_line( GLcontext *ctx,
  * Draw a flat-shaded, PF_HPCR line into an XImage.
  */
 static void flat_HPCR_line( GLcontext *ctx,
-                            GLuint vert0, GLuint vert1, GLuint pv )
+                            SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
    GLint r = color[0], g = color[1], b = color[2];
 
 #define INTERP_XY 1
@@ -348,10 +337,10 @@ static void flat_HPCR_line( GLcontext *ctx,
  * Draw a flat-shaded, Z-less, PF_TRUECOLOR line into an XImage.
  */
 static void flat_TRUECOLOR_z_line( GLcontext *ctx,
-                                   GLuint vert0, GLuint vert1, GLuint pv )
+                                   SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
    XMesaImage *img = xmesa->xm_buffer->backimage;
    unsigned long pixel;
    PACK_TRUECOLOR( pixel, color[0], color[1], color[2] );
@@ -374,10 +363,10 @@ static void flat_TRUECOLOR_z_line( GLcontext *ctx,
  * Draw a flat-shaded, Z-less, PF_8A8B8G8R line into an XImage.
  */
 static void flat_8A8B8G8R_z_line( GLcontext *ctx,
-                                  GLuint vert0, GLuint vert1, GLuint pv )
+                                  SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
    GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] );
 
 #define INTERP_Z 1
@@ -400,10 +389,10 @@ static void flat_8A8B8G8R_z_line( GLcontext *ctx,
  * Draw a flat-shaded, Z-less, PF_8R8G8B line into an XImage.
  */
 static void flat_8R8G8B_z_line( GLcontext *ctx,
-                                GLuint vert0, GLuint vert1, GLuint pv )
+                                SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
    GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] );
 
 #define INTERP_Z 1
@@ -426,10 +415,10 @@ static void flat_8R8G8B_z_line( GLcontext *ctx,
  * Draw a flat-shaded, Z-less, PF_8R8G8B24 line into an XImage.
  */
 static void flat_8R8G8B24_z_line( GLcontext *ctx,
-                                    GLuint vert0, GLuint vert1, GLuint pv )
+                                    SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
 
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
@@ -453,10 +442,10 @@ static void flat_8R8G8B24_z_line( GLcontext *ctx,
  * Draw a flat-shaded, Z-less, PF_5R6G5B line into an XImage.
  */
 static void flat_5R6G5B_z_line( GLcontext *ctx,
-                                GLuint vert0, GLuint vert1, GLuint pv )
+                                SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
    GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] );
 
 #define INTERP_Z 1
@@ -478,10 +467,10 @@ static void flat_5R6G5B_z_line( GLcontext *ctx,
  * Draw a flat-shaded, Z-less, PF_DITHER_5R6G5B line into an XImage.
  */
 static void flat_DITHER_5R6G5B_z_line( GLcontext *ctx,
-                                       GLuint vert0, GLuint vert1, GLuint pv )
+                                       SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
 
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
@@ -502,10 +491,10 @@ static void flat_DITHER_5R6G5B_z_line( GLcontext *ctx,
  * Draw a flat-shaded, Z-less, PF_DITHER 8-bit line into an XImage.
  */
 static void flat_DITHER8_z_line( GLcontext *ctx,
-                                 GLuint vert0, GLuint vert1, GLuint pv )
+                                 SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
    GLint r = color[0], g = color[1], b = color[2];
    DITHER_SETUP;
 
@@ -529,10 +518,10 @@ static void flat_DITHER8_z_line( GLcontext *ctx,
  * Draw a flat-shaded, Z-less, PF_LOOKUP 8-bit line into an XImage.
  */
 static void flat_LOOKUP8_z_line( GLcontext *ctx,
-                                 GLuint vert0, GLuint vert1, GLuint pv )
+                                 SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
    GLubyte pixel;
    LOOKUP_SETUP;
    pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] );
@@ -557,10 +546,10 @@ static void flat_LOOKUP8_z_line( GLcontext *ctx,
  * Draw a flat-shaded, Z-less, PF_HPCR line into an XImage.
  */
 static void flat_HPCR_z_line( GLcontext *ctx,
-                              GLuint vert0, GLuint vert1, GLuint pv )
+                              SWvertex *vert0, SWvertex *vert1 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = vert0->color;
    GLint r = color[0], g = color[1], b = color[2];
 
 #define INTERP_XY 1
@@ -662,28 +651,24 @@ fprintf (stderr, "\n");
 }
 #endif
 
-
-
-/*
- * Analyze context state to see if we can provide a fast line drawing
- * function, like those in lines.c.  Otherwise, return NULL.
- */
-line_func xmesa_get_line_func( GLcontext *ctx )
+static swrast_line_func get_line_func( GLcontext *ctx )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
    int depth = GET_VISUAL_DEPTH(xmesa->xm_visual);
 
    (void) DitherValues;  /* silence unused var warning */
    (void) kernel1;  /* silence unused var warning */
 
-   if (ctx->Line.SmoothFlag)              return (line_func)NULL;
-   if (ctx->Texture.ReallyEnabled)        return (line_func)NULL;
-   if (ctx->Light.ShadeModel!=GL_FLAT)    return (line_func)NULL;
+   if (ctx->Line.SmoothFlag)              return (swrast_line_func)NULL;
+   if (ctx->Texture._ReallyEnabled)        return (swrast_line_func)NULL;
+   if (ctx->Light.ShadeModel!=GL_FLAT)    return (swrast_line_func)NULL;
    /* X line stippling doesn't match OpenGL stippling */
-   if (ctx->Line.StippleFlag==GL_TRUE)    return (line_func)NULL;
+   if (ctx->Line.StippleFlag==GL_TRUE)    return (swrast_line_func)NULL;
 
    if (xmesa->xm_buffer->buffer==XIMAGE
-       && ctx->RasterMask==DEPTH_BIT
+       && swrast->_RasterMask==DEPTH_BIT
        && ctx->Depth.Func==GL_LESS
        && ctx->Depth.Mask==GL_TRUE
        && ctx->Visual.DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS
@@ -702,17 +687,17 @@ line_func xmesa_get_line_func( GLcontext *ctx )
          case PF_DITHER_5R6G5B:
             return flat_DITHER_5R6G5B_z_line;
          case PF_DITHER:
-            return (depth==8) ? flat_DITHER8_z_line : (line_func)NULL;
+            return (depth==8) ? flat_DITHER8_z_line : (swrast_line_func)NULL;
          case PF_LOOKUP:
-            return (depth==8) ? flat_LOOKUP8_z_line : (line_func)NULL;
+            return (depth==8) ? flat_LOOKUP8_z_line : (swrast_line_func)NULL;
          case PF_HPCR:
             return flat_HPCR_z_line;
          default:
-            return (line_func)NULL;
+            return (swrast_line_func)NULL;
       }
    }
    if (xmesa->xm_buffer->buffer==XIMAGE
-       && ctx->RasterMask==0
+       && swrast->_RasterMask==0
        && ctx->Line.Width==1.0F) {
       switch (xmesa->pixelformat) {
          case PF_TRUECOLOR:
@@ -728,13 +713,13 @@ line_func xmesa_get_line_func( GLcontext *ctx )
          case PF_DITHER_5R6G5B:
             return flat_DITHER_5R6G5B_line;
          case PF_DITHER:
-            return (depth==8) ? flat_DITHER8_line : (line_func)NULL;
+            return (depth==8) ? flat_DITHER8_line : (swrast_line_func)NULL;
          case PF_LOOKUP:
-            return (depth==8) ? flat_LOOKUP8_line : (line_func)NULL;
+            return (depth==8) ? flat_LOOKUP8_line : (swrast_line_func)NULL;
          case PF_HPCR:
             return flat_HPCR_line;
         default:
-           return (line_func)NULL;
+           return (swrast_line_func)NULL;
       }
    }
 #if 0
@@ -742,10 +727,46 @@ line_func xmesa_get_line_func( GLcontext *ctx )
     * software Mesa's.  This causes the linehv.c conformance test to fail.
     * In the future, we might provide a config option to enable this.
     */
-   if (xmesa->xm_buffer->buffer!=XIMAGE && ctx->RasterMask==0) {
+   if (xmesa->xm_buffer->buffer!=XIMAGE && ctx->_RasterMask==0) {
       setup_x_line_options( ctx );
       return flat_pixmap_line;
    }
 #endif
-   return (line_func)NULL;
+   return (swrast_line_func)NULL;
+}
+
+/* Override for the swrast line-selection function.  Try to use one
+ * of our internal line functions, otherwise fall back to the
+ * standard swrast functions.  
+ */
+void xmesa_choose_line( GLcontext *ctx )
+{
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+
+   if (!(swrast->Line = get_line_func( ctx )))
+      _swrast_choose_line( ctx );
+}
+
+
+#define XMESA_NEW_POINT  (_NEW_POINT|_SWRAST_NEW_RASTERMASK)
+#define XMESA_NEW_LINE   (_NEW_LINE|_NEW_TEXTURE|_NEW_LIGHT|\
+                          _NEW_DEPTH|_SWRAST_NEW_RASTERMASK)
+#define XMESA_NEW_TRIANGLE (_NEW_POLYGON|_NEW_TEXTURE|_NEW_LIGHT|\
+                            _SWRAST_NEW_RASTERMASK|_NEW_DEPTH)
+
+
+/* Extend the software rasterizer with our line/point/triangle 
+ * functions.
+ */
+void xmesa_register_swrast_functions( GLcontext *ctx )
+{
+   SWcontext *swrast = SWRAST_CONTEXT( ctx );
+   
+   swrast->choose_point = xmesa_choose_point;
+   swrast->choose_line = xmesa_choose_line;
+   swrast->choose_triangle = xmesa_choose_triangle;
+   
+   swrast->invalidate_point |= XMESA_NEW_POINT;
+   swrast->invalidate_line |= XMESA_NEW_LINE;
+   swrast->invalidate_triangle |= XMESA_NEW_TRIANGLE;
 }
index 6d60e31..3c25265 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: xm_tri.c,v 1.6 2000/10/31 18:09:47 keithw Exp $ */
+/* $Id: xm_tri.c,v 1.7 2000/11/05 18:26:12 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -41,7 +41,9 @@
 
 /* Internal swrast includes:
  */
+#include "swrast/s_context.h"
 #include "swrast/s_depth.h"
+#include "swrast/s_triangle.h"
 
 
 
  * no raster ops.
  */
 static void flat_pixmap_triangle( GLcontext *ctx,
-                                 GLuint v0, GLuint v1, GLuint v2, GLuint pv )
+                                 SWvertex *v0,
+                                 SWvertex *v1,
+                                 SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   struct vertex_buffer *VB = ctx->VB;
    XMesaPoint p[3];
    XMesaGC gc;
 
-   if (0 /*VB->MonoColor*/) {
-      gc = xmesa->xm_buffer->gc1;  /* use current color */
-   }
-   else {
+   {
       unsigned long pixel;
       if (xmesa->xm_visual->gl_visual->RGBAflag) {
          pixel = xmesa_color_to_pixel( xmesa,
-                         VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1],
-                         VB->ColorPtr->data[pv][2], VB->ColorPtr->data[pv][3],
+                         v0->color[0], v0->color[1],
+                         v0->color[2], v0->color[3],
                          xmesa->pixelformat );
       }
       else {
-         pixel = VB->IndexPtr->data[pv];
+         pixel = v0->index;
       }
       gc = xmesa->xm_buffer->gc2;
       XMesaSetForeground( xmesa->display, gc, pixel );
    }
-   p[0].x =                         (GLint) (VB->Win.data[v0][0] + 0.5f);
-   p[0].y = FLIP( xmesa->xm_buffer, (GLint) (VB->Win.data[v0][1] - 0.5f) );
-   p[1].x =                         (GLint) (VB->Win.data[v1][0] + 0.5f);
-   p[1].y = FLIP( xmesa->xm_buffer, (GLint) (VB->Win.data[v1][1] - 0.5f) );
-   p[2].x =                         (GLint) (VB->Win.data[v2][0] + 0.5f);
-   p[2].y = FLIP( xmesa->xm_buffer, (GLint) (VB->Win.data[v2][1] - 0.5f) );
+   p[0].x =                         (GLint) (v0->win[0] + 0.5f);
+   p[0].y = FLIP( xmesa->xm_buffer, (GLint) (v0->win[1] - 0.5f) );
+   p[1].x =                         (GLint) (v1->win[0] + 0.5f);
+   p[1].y = FLIP( xmesa->xm_buffer, (GLint) (v1->win[1] - 0.5f) );
+   p[2].x =                         (GLint) (v2->win[0] + 0.5f);
+   p[2].y = FLIP( xmesa->xm_buffer, (GLint) (v2->win[1] - 0.5f) );
    XMesaFillPolygon( xmesa->display, xmesa->xm_buffer->buffer, gc,
                     p, 3, Convex, CoordModeOrigin );
 }
@@ -97,12 +97,12 @@ static void flat_pixmap_triangle( GLcontext *ctx,
  * XImage, smooth, depth-buffered, PF_TRUECOLOR triangle.
  */
 static void smooth_TRUECOLOR_z_triangle( GLcontext *ctx,
-                                         GLuint v0, GLuint v1, GLuint v2,
-                                         GLuint pv )
+                                         SWvertex *v0,
+                                        SWvertex *v1,
+                                        SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
    XMesaImage *img = xmesa->xm_buffer->backimage;
-   (void) pv;
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
@@ -132,11 +132,11 @@ static void smooth_TRUECOLOR_z_triangle( GLcontext *ctx,
  * XImage, smooth, depth-buffered, PF_8A8B8G8R triangle.
  */
 static void smooth_8A8B8G8R_z_triangle( GLcontext *ctx,
-                                         GLuint v0, GLuint v1, GLuint v2,
-                                         GLuint pv )
+                                       SWvertex *v0,
+                                       SWvertex *v1,
+                                       SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
@@ -166,11 +166,11 @@ static void smooth_8A8B8G8R_z_triangle( GLcontext *ctx,
  * XImage, smooth, depth-buffered, PF_8R8G8B triangle.
  */
 static void smooth_8R8G8B_z_triangle( GLcontext *ctx,
-                                         GLuint v0, GLuint v1, GLuint v2,
-                                         GLuint pv )
+                                     SWvertex *v0,
+                                     SWvertex *v1,
+                                     SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
@@ -200,11 +200,11 @@ static void smooth_8R8G8B_z_triangle( GLcontext *ctx,
  * XImage, smooth, depth-buffered, PF_8R8G8B24 triangle.
  */
 static void smooth_8R8G8B24_z_triangle( GLcontext *ctx,
-                                        GLuint v0, GLuint v1, GLuint v2,
-                                        GLuint pv )
+                                        SWvertex *v0,
+                                       SWvertex *v1,
+                                       SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
@@ -236,12 +236,12 @@ static void smooth_8R8G8B24_z_triangle( GLcontext *ctx,
  * XImage, smooth, depth-buffered, PF_TRUEDITHER triangle.
  */
 static void smooth_TRUEDITHER_z_triangle( GLcontext *ctx,
-                                         GLuint v0, GLuint v1, GLuint v2,
-                                         GLuint pv )
+                                         SWvertex *v0,
+                                         SWvertex *v1,
+                                         SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
    XMesaImage *img = xmesa->xm_buffer->backimage;
-   (void) pv;
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
@@ -270,11 +270,11 @@ static void smooth_TRUEDITHER_z_triangle( GLcontext *ctx,
  * XImage, smooth, depth-buffered, PF_5R6G5B triangle.
  */
 static void smooth_5R6G5B_z_triangle( GLcontext *ctx,
-                                      GLuint v0, GLuint v1, GLuint v2,
-                                      GLuint pv )
+                                      SWvertex *v0,
+                                     SWvertex *v1,
+                                     SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
@@ -304,11 +304,11 @@ static void smooth_5R6G5B_z_triangle( GLcontext *ctx,
  * XImage, smooth, depth-buffered, PF_DITHER_5R6G5B triangle.
  */
 static void smooth_DITHER_5R6G5B_z_triangle( GLcontext *ctx,
-                                             GLuint v0, GLuint v1, GLuint v2,
-                                             GLuint pv )
+                                             SWvertex *v0,
+                                            SWvertex *v1,
+                                            SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
@@ -338,11 +338,11 @@ static void smooth_DITHER_5R6G5B_z_triangle( GLcontext *ctx,
  * XImage, smooth, depth-buffered, 8-bit, PF_DITHER8 triangle.
  */
 static void smooth_DITHER8_z_triangle( GLcontext *ctx,
-                                       GLuint v0, GLuint v1, GLuint v2,
-                                       GLuint pv )
+                                       SWvertex *v0,
+                                      SWvertex *v1,
+                                      SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
@@ -373,12 +373,12 @@ static void smooth_DITHER8_z_triangle( GLcontext *ctx,
  * XImage, smooth, depth-buffered, PF_DITHER triangle.
  */
 static void smooth_DITHER_z_triangle( GLcontext *ctx,
-                                       GLuint v0, GLuint v1, GLuint v2,
-                                       GLuint pv )
+                                     SWvertex *v0,
+                                     SWvertex *v1,
+                                     SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
    XMesaImage *img = xmesa->xm_buffer->backimage;
-   (void) pv;
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
@@ -409,11 +409,12 @@ static void smooth_DITHER_z_triangle( GLcontext *ctx,
 /*
  * XImage, smooth, depth-buffered, 8-bit PF_LOOKUP triangle.
  */
-static void smooth_LOOKUP8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                       GLuint v2, GLuint pv )
+static void smooth_LOOKUP8_z_triangle( GLcontext *ctx, 
+                                      SWvertex *v0,
+                                      SWvertex *v1,
+                                      SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
@@ -444,11 +445,12 @@ static void smooth_LOOKUP8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, smooth, depth-buffered, 8-bit PF_HPCR triangle.
  */
-static void smooth_HPCR_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                    GLuint v2, GLuint pv )
+static void smooth_HPCR_z_triangle( GLcontext *ctx, 
+                                   SWvertex *v0,
+                                   SWvertex *v1,
+                                   SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
@@ -478,8 +480,9 @@ static void smooth_HPCR_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
  * XImage, flat, depth-buffered, PF_TRUECOLOR triangle.
  */
 static void flat_TRUECOLOR_z_triangle( GLcontext *ctx,
-                                      GLuint v0, GLuint v1, GLuint v2,
-                                       GLuint pv )
+                                      SWvertex *v0,
+                                      SWvertex *v1,
+                                      SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
    XMesaImage *img = xmesa->xm_buffer->backimage;
@@ -487,7 +490,7 @@ static void flat_TRUECOLOR_z_triangle( GLcontext *ctx,
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define SETUP_CODE                                             \
    unsigned long pixel;                                                \
-   PACK_TRUECOLOR(pixel, VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2]);
+   PACK_TRUECOLOR(pixel, v0->color[0], v0->color[1], v0->color[2]);
 
 #define INNER_LOOP( LEFT, RIGHT, Y )                                   \
 {                                                                      \
@@ -509,8 +512,10 @@ static void flat_TRUECOLOR_z_triangle( GLcontext *ctx,
 /*
  * XImage, flat, depth-buffered, PF_8A8B8G8R triangle.
  */
-static void flat_8A8B8G8R_z_triangle( GLcontext *ctx, GLuint v0,
-                                     GLuint v1, GLuint v2, GLuint pv )
+static void flat_8A8B8G8R_z_triangle( GLcontext *ctx, 
+                                     SWvertex *v0,
+                                     SWvertex *v1,
+                                     SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 #define INTERP_Z 1
@@ -519,8 +524,8 @@ static void flat_8A8B8G8R_z_triangle( GLcontext *ctx, GLuint v0,
 #define PIXEL_TYPE GLuint
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
 #define SETUP_CODE                                     \
-   unsigned long p = PACK_8B8G8R( VB->ColorPtr->data[pv][0],   \
-                VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+   unsigned long p = PACK_8B8G8R( v0->color[0],        \
+                v0->color[1], v0->color[2] );
 #define INNER_LOOP( LEFT, RIGHT, Y )                                   \
 {                                                                      \
    GLint i, len = RIGHT-LEFT;                                          \
@@ -541,8 +546,10 @@ static void flat_8A8B8G8R_z_triangle( GLcontext *ctx, GLuint v0,
 /*
  * XImage, flat, depth-buffered, PF_8R8G8B triangle.
  */
-static void flat_8R8G8B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                    GLuint v2, GLuint pv )
+static void flat_8R8G8B_z_triangle( GLcontext *ctx, 
+                                   SWvertex *v0,
+                                   SWvertex *v1,
+                                   SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 #define INTERP_Z 1
@@ -551,8 +558,8 @@ static void flat_8R8G8B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 #define PIXEL_TYPE GLuint
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
 #define SETUP_CODE                                     \
-   unsigned long p = PACK_8R8G8B( VB->ColorPtr->data[pv][0],   \
-                VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+   unsigned long p = PACK_8R8G8B( v0->color[0],        \
+                v0->color[1], v0->color[2] );
 #define INNER_LOOP( LEFT, RIGHT, Y )                   \
 {                                                      \
    GLint i, len = RIGHT-LEFT;                          \
@@ -573,11 +580,13 @@ static void flat_8R8G8B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, depth-buffered, PF_8R8G8B24 triangle.
  */
-static void flat_8R8G8B24_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                      GLuint v2, GLuint pv )
+static void flat_8R8G8B24_z_triangle( GLcontext *ctx, 
+                                     SWvertex *v0,
+                                     SWvertex *v1,
+                                     SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = v0->color;
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
@@ -606,8 +615,10 @@ static void flat_8R8G8B24_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, depth-buffered, PF_TRUEDITHER triangle.
  */
-static void flat_TRUEDITHER_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                    GLuint v2, GLuint pv )
+static void flat_TRUEDITHER_z_triangle( GLcontext *ctx, 
+                                       SWvertex *v0,
+                                       SWvertex *v1,
+                                       SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
    XMesaImage *img = xmesa->xm_buffer->backimage;
@@ -621,8 +632,8 @@ static void flat_TRUEDITHER_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
       GLdepth z = FixedToDepth(ffz);                                   \
       if (z < zRow[i]) {                                               \
          unsigned long p;                                              \
-         PACK_TRUEDITHER( p, xx, yy, VB->ColorPtr->data[pv][0],                \
-            VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );    \
+         PACK_TRUEDITHER( p, xx, yy, v0->color[0],             \
+            v0->color[1], v0->color[2] );      \
          XMesaPutPixel( img, xx, yy, p );                              \
          zRow[i] = z;                                                  \
       }                                                                        \
@@ -636,8 +647,10 @@ static void flat_TRUEDITHER_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, depth-buffered, PF_5R6G5B triangle.
  */
-static void flat_5R6G5B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                    GLuint v2, GLuint pv )
+static void flat_5R6G5B_z_triangle( GLcontext *ctx, 
+                                   SWvertex *v0,
+                                   SWvertex *v1,
+                                   SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 #define INTERP_Z 1
@@ -646,8 +659,8 @@ static void flat_5R6G5B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 #define PIXEL_TYPE GLushort
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
 #define SETUP_CODE                                                     \
-   unsigned long p = PACK_5R6G5B( VB->ColorPtr->data[pv][0],           \
-            VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+   unsigned long p = PACK_5R6G5B( v0->color[0],                \
+            v0->color[1], v0->color[2] );
 #define INNER_LOOP( LEFT, RIGHT, Y )                   \
 {                                                      \
    GLint i, len = RIGHT-LEFT;                          \
@@ -668,11 +681,13 @@ static void flat_5R6G5B_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, depth-buffered, PF_DITHER_5R6G5B triangle.
  */
-static void flat_DITHER_5R6G5B_z_triangle( GLcontext *ctx, GLuint v0,
-                                           GLuint v1, GLuint v2, GLuint pv )
+static void flat_DITHER_5R6G5B_z_triangle( GLcontext *ctx, 
+                                          SWvertex *v0,
+                                          SWvertex *v1,
+                                          SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = v0->color;
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
@@ -699,8 +714,10 @@ static void flat_DITHER_5R6G5B_z_triangle( GLcontext *ctx, GLuint v0,
 /*
  * XImage, flat, depth-buffered, 8-bit PF_DITHER triangle.
  */
-static void flat_DITHER8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                     GLuint v2, GLuint pv )
+static void flat_DITHER8_z_triangle( GLcontext *ctx, 
+                                    SWvertex *v0,
+                                    SWvertex *v1,
+                                    SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 #define INTERP_Z 1
@@ -709,7 +726,7 @@ static void flat_DITHER8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 #define PIXEL_TYPE GLubyte
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
 #define SETUP_CODE     \
-   FLAT_DITHER_SETUP( VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+   FLAT_DITHER_SETUP( v0->color[0], v0->color[1], v0->color[2] );
 
 #define INNER_LOOP( LEFT, RIGHT, Y )                           \
 {                                                              \
@@ -732,15 +749,17 @@ static void flat_DITHER8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, depth-buffered, PF_DITHER triangle.
  */
-static void flat_DITHER_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                    GLuint v2, GLuint pv )
+static void flat_DITHER_z_triangle( GLcontext *ctx, 
+                                   SWvertex *v0,
+                                   SWvertex *v1,
+                                   SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
    XMesaImage *img = xmesa->xm_buffer->backimage;
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define SETUP_CODE     \
-   FLAT_DITHER_SETUP( VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+   FLAT_DITHER_SETUP( v0->color[0], v0->color[1], v0->color[2] );
 
 #define INNER_LOOP( LEFT, RIGHT, Y )                                   \
 {                                                                      \
@@ -764,8 +783,10 @@ static void flat_DITHER_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, depth-buffered, 8-bit PF_HPCR triangle.
  */
-static void flat_HPCR_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                  GLuint v2, GLuint pv )
+static void flat_HPCR_z_triangle( GLcontext *ctx, 
+                                 SWvertex *v0,
+                                 SWvertex *v1,
+                                 SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 #define INTERP_Z 1
@@ -774,9 +795,9 @@ static void flat_HPCR_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 #define PIXEL_TYPE GLubyte
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
 #define SETUP_CODE                             \
-   GLubyte r = VB->ColorPtr->data[pv][0];      \
-   GLubyte g = VB->ColorPtr->data[pv][1];      \
-   GLubyte b = VB->ColorPtr->data[pv][2];
+   GLubyte r = v0->color[0];   \
+   GLubyte g = v0->color[1];   \
+   GLubyte b = v0->color[2];
 #define INNER_LOOP( LEFT, RIGHT, Y )                                   \
 {                                                                      \
    GLint i, xx = LEFT, yy = FLIP(xmesa->xm_buffer,Y), len = RIGHT-LEFT;        \
@@ -797,8 +818,10 @@ static void flat_HPCR_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, depth-buffered, 8-bit PF_LOOKUP triangle.
  */
-static void flat_LOOKUP8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                    GLuint v2, GLuint pv )
+static void flat_LOOKUP8_z_triangle( GLcontext *ctx, 
+                                    SWvertex *v0,
+                                    SWvertex *v1,
+                                    SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 #define INTERP_Z 1
@@ -808,9 +831,9 @@ static void flat_LOOKUP8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
 #define SETUP_CODE                             \
    LOOKUP_SETUP;                               \
-   GLubyte r = VB->ColorPtr->data[pv][0];      \
-   GLubyte g = VB->ColorPtr->data[pv][1];      \
-   GLubyte b = VB->ColorPtr->data[pv][2];      \
+   GLubyte r = v0->color[0];   \
+   GLubyte g = v0->color[1];   \
+   GLubyte b = v0->color[2];   \
    GLubyte p = LOOKUP(r,g,b);
 #define INNER_LOOP( LEFT, RIGHT, Y )                   \
 {                                                      \
@@ -833,12 +856,13 @@ static void flat_LOOKUP8_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, smooth, NON-depth-buffered, PF_TRUECOLOR triangle.
  */
-static void smooth_TRUECOLOR_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                       GLuint v2, GLuint pv )
+static void smooth_TRUECOLOR_triangle( GLcontext *ctx, 
+                                      SWvertex *v0,
+                                      SWvertex *v1,
+                                      SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
    XMesaImage *img = xmesa->xm_buffer->backimage;
-   (void) pv;
 #define INTERP_RGB 1
 #define INNER_LOOP( LEFT, RIGHT, Y )                                   \
 {                                                                      \
@@ -857,11 +881,12 @@ static void smooth_TRUECOLOR_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, smooth, NON-depth-buffered, PF_8A8B8G8R triangle.
  */
-static void smooth_8A8B8G8R_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                     GLuint v2, GLuint pv )
+static void smooth_8A8B8G8R_triangle( GLcontext *ctx, 
+                                     SWvertex *v0,
+                                     SWvertex *v1,
+                                     SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
 #define INTERP_RGB 1
 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE GLuint
@@ -883,11 +908,12 @@ static void smooth_8A8B8G8R_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
  */
-static void smooth_8R8G8B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                    GLuint v2, GLuint pv )
+static void smooth_8R8G8B_triangle( GLcontext *ctx, 
+                                   SWvertex *v0,
+                                   SWvertex *v1,
+                                   SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
 #define INTERP_RGB 1
 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE GLuint
@@ -909,11 +935,12 @@ static void smooth_8R8G8B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
  */
-static void smooth_8R8G8B24_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                      GLuint v2, GLuint pv )
+static void smooth_8R8G8B24_triangle( GLcontext *ctx, 
+                                     SWvertex *v0,
+                                     SWvertex *v1,
+                                     SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
 #define INTERP_RGB 1
 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE bgr_t
@@ -937,12 +964,13 @@ static void smooth_8R8G8B24_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, smooth, NON-depth-buffered, PF_TRUEDITHER triangle.
  */
-static void smooth_TRUEDITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                   GLuint v2, GLuint pv )
+static void smooth_TRUEDITHER_triangle( GLcontext *ctx, 
+                                       SWvertex *v0,
+                                       SWvertex *v1,
+                                       SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
    XMesaImage *img = xmesa->xm_buffer->backimage;
-   (void) pv;
 #define INTERP_RGB 1
 #define INNER_LOOP( LEFT, RIGHT, Y )                                   \
 {                                                                      \
@@ -962,11 +990,12 @@ static void smooth_TRUEDITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, smooth, NON-depth-buffered, PF_5R6G5B triangle.
  */
-static void smooth_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                   GLuint v2, GLuint pv )
+static void smooth_5R6G5B_triangle( GLcontext *ctx, 
+                                   SWvertex *v0,
+                                   SWvertex *v1,
+                                   SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
 #define INTERP_RGB 1
 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE GLushort
@@ -988,11 +1017,12 @@ static void smooth_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, smooth, NON-depth-buffered, PF_DITHER_5R6G5B triangle.
  */
-static void smooth_DITHER_5R6G5B_triangle( GLcontext *ctx, GLuint v0,
-                                           GLuint v1, GLuint v2, GLuint pv )
+static void smooth_DITHER_5R6G5B_triangle( GLcontext *ctx, 
+                                          SWvertex *v0,
+                                          SWvertex *v1,
+                                          SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
 #define INTERP_RGB 1
 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE GLushort
@@ -1014,11 +1044,12 @@ static void smooth_DITHER_5R6G5B_triangle( GLcontext *ctx, GLuint v0,
 /*
  * XImage, smooth, NON-depth-buffered, 8-bit PF_DITHER triangle.
  */
-static void smooth_DITHER8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                    GLuint v2, GLuint pv )
+static void smooth_DITHER8_triangle( GLcontext *ctx, 
+                                    SWvertex *v0,
+                                    SWvertex *v1,
+                                    SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
 #define INTERP_RGB 1
 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE GLubyte
@@ -1041,12 +1072,14 @@ static void smooth_DITHER8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, smooth, NON-depth-buffered, PF_DITHER triangle.
  */
-static void smooth_DITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                    GLuint v2, GLuint pv )
+static void smooth_DITHER_triangle( GLcontext *ctx, 
+                                   SWvertex *v0,
+                                   SWvertex *v1,
+                                   SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
    XMesaImage *img = xmesa->xm_buffer->backimage;
-   (void) pv;
+
 #define INTERP_RGB 1
 #define INNER_LOOP( LEFT, RIGHT, Y )                                   \
 {                                                                      \
@@ -1066,11 +1099,13 @@ static void smooth_DITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, smooth, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
  */
-static void smooth_LOOKUP8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                     GLuint v2, GLuint pv )
+static void smooth_LOOKUP8_triangle( GLcontext *ctx, 
+                                    SWvertex *v0,
+                                    SWvertex *v1,
+                                    SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
+
 #define INTERP_RGB 1
 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE GLubyte
@@ -1094,11 +1129,13 @@ static void smooth_LOOKUP8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, smooth, NON-depth-buffered, 8-bit PF_HPCR triangle.
  */
-static void smooth_HPCR_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                  GLuint v2, GLuint pv )
+static void smooth_HPCR_triangle( GLcontext *ctx, 
+                                 SWvertex *v0,
+                                 SWvertex *v1,
+                                 SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   (void) pv;
+
 #define INTERP_RGB 1
 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE GLubyte
@@ -1120,14 +1157,16 @@ static void smooth_HPCR_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, NON-depth-buffered, PF_TRUECOLOR triangle.
  */
-static void flat_TRUECOLOR_triangle( GLcontext *ctx, GLuint v0,
-                                     GLuint v1, GLuint v2, GLuint pv )
+static void flat_TRUECOLOR_triangle( GLcontext *ctx, 
+                                    SWvertex *v0,
+                                    SWvertex *v1,
+                                    SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
    XMesaImage *img = xmesa->xm_buffer->backimage;
 #define SETUP_CODE                                             \
    unsigned long pixel;                                                \
-   PACK_TRUECOLOR(pixel, VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2]);
+   PACK_TRUECOLOR(pixel, v0->color[0], v0->color[1], v0->color[2]);
 
 #define INNER_LOOP( LEFT, RIGHT, Y )                           \
 {                                                              \
@@ -1143,16 +1182,18 @@ static void flat_TRUECOLOR_triangle( GLcontext *ctx, GLuint v0,
 /*
  * XImage, flat, NON-depth-buffered, PF_8A8B8G8R triangle.
  */
-static void flat_8A8B8G8R_triangle( GLcontext *ctx, GLuint v0,
-                                   GLuint v1, GLuint v2, GLuint pv )
+static void flat_8A8B8G8R_triangle( GLcontext *ctx, 
+                                   SWvertex *v0,
+                                   SWvertex *v1,
+                                   SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE GLuint
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
 #define SETUP_CODE                                     \
-   unsigned long p = PACK_8B8G8R( VB->ColorPtr->data[pv][0],   \
-                VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+   unsigned long p = PACK_8B8G8R( v0->color[0],        \
+                v0->color[1], v0->color[2] );
 #define INNER_LOOP( LEFT, RIGHT, Y )                   \
 {                                                      \
    GLint xx;                                           \
@@ -1168,16 +1209,18 @@ static void flat_8A8B8G8R_triangle( GLcontext *ctx, GLuint v0,
 /*
  * XImage, flat, NON-depth-buffered, PF_8R8G8B triangle.
  */
-static void flat_8R8G8B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                  GLuint v2, GLuint pv )
+static void flat_8R8G8B_triangle( GLcontext *ctx, 
+                                 SWvertex *v0,
+                                 SWvertex *v1,
+                                 SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 #define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE GLuint
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
 #define SETUP_CODE                                     \
-   unsigned long p = PACK_8R8G8B( VB->ColorPtr->data[pv][0],   \
-                VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+   unsigned long p = PACK_8R8G8B( v0->color[0],        \
+                v0->color[1], v0->color[2] );
 #define INNER_LOOP( LEFT, RIGHT, Y )                   \
 {                                                      \
    GLint xx;                                           \
@@ -1193,11 +1236,13 @@ static void flat_8R8G8B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, NON-depth-buffered, PF_8R8G8B24 triangle.
  */
-static void flat_8R8G8B24_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                    GLuint v2, GLuint pv )
+static void flat_8R8G8B24_triangle( GLcontext *ctx, 
+                                   SWvertex *v0,
+                                   SWvertex *v1,
+                                   SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = v0->color;
 #define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE bgr_t
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
@@ -1218,8 +1263,10 @@ static void flat_8R8G8B24_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, NON-depth-buffered, PF_TRUEDITHER triangle.
  */
-static void flat_TRUEDITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                     GLuint v2, GLuint pv )
+static void flat_TRUEDITHER_triangle( GLcontext *ctx, 
+                                     SWvertex *v0,
+                                     SWvertex *v1,
+                                     SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
    XMesaImage *img = xmesa->xm_buffer->backimage;
@@ -1228,8 +1275,8 @@ static void flat_TRUEDITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
    GLint xx, yy = FLIP(xmesa->xm_buffer, Y);                           \
    for (xx=LEFT;xx<RIGHT;xx++) {                                       \
       unsigned long p;                                                 \
-      PACK_TRUEDITHER( p, xx, yy, VB->ColorPtr->data[pv][0],           \
-               VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] ); \
+      PACK_TRUEDITHER( p, xx, yy, v0->color[0],                \
+               v0->color[1], v0->color[2] );   \
       XMesaPutPixel( img, xx, yy, p );                                 \
    }                                                                   \
 }
@@ -1241,16 +1288,18 @@ static void flat_TRUEDITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, NON-depth-buffered, PF_5R6G5B triangle.
  */
-static void flat_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                  GLuint v2, GLuint pv )
+static void flat_5R6G5B_triangle( GLcontext *ctx, 
+                                 SWvertex *v0,
+                                 SWvertex *v1,
+                                 SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE GLushort
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
 #define SETUP_CODE                                     \
-   unsigned long p = PACK_5R6G5B( VB->ColorPtr->data[pv][0],   \
-                VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+   unsigned long p = PACK_5R6G5B( v0->color[0],        \
+                v0->color[1], v0->color[2] );
 #define INNER_LOOP( LEFT, RIGHT, Y )                   \
 {                                                      \
    GLint xx;                                           \
@@ -1266,11 +1315,13 @@ static void flat_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, NON-depth-buffered, PF_DITHER_5R6G5B triangle.
  */
-static void flat_DITHER_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                         GLuint v2, GLuint pv )
+static void flat_DITHER_5R6G5B_triangle( GLcontext *ctx, 
+                                        SWvertex *v0,
+                                        SWvertex *v1,
+                                        SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = ctx->VB->ColorPtr->data[pv];
+   const GLubyte *color = v0->color;
 #define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE GLushort
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
@@ -1290,15 +1341,17 @@ static void flat_DITHER_5R6G5B_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, NON-depth-buffered, 8-bit PF_DITHER triangle.
  */
-static void flat_DITHER8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                   GLuint v2, GLuint pv )
+static void flat_DITHER8_triangle( GLcontext *ctx, 
+                                  SWvertex *v0,
+                                  SWvertex *v1,
+                                  SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE GLubyte
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
 #define SETUP_CODE     \
-   FLAT_DITHER_SETUP( VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+   FLAT_DITHER_SETUP( v0->color[0], v0->color[1], v0->color[2] );
 
 #define INNER_LOOP( LEFT, RIGHT, Y )                   \
 {                                                      \
@@ -1316,13 +1369,15 @@ static void flat_DITHER8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, NON-depth-buffered, PF_DITHER triangle.
  */
-static void flat_DITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                  GLuint v2, GLuint pv )
+static void flat_DITHER_triangle( GLcontext *ctx, 
+                                 SWvertex *v0,
+                                 SWvertex *v1,
+                                 SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
    XMesaImage *img = xmesa->xm_buffer->backimage;
 #define SETUP_CODE     \
-   FLAT_DITHER_SETUP( VB->ColorPtr->data[pv][0], VB->ColorPtr->data[pv][1], VB->ColorPtr->data[pv][2] );
+   FLAT_DITHER_SETUP( v0->color[0], v0->color[1], v0->color[2] );
 
 #define INNER_LOOP( LEFT, RIGHT, Y )                   \
 {                                                      \
@@ -1340,17 +1395,19 @@ static void flat_DITHER_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, NON-depth-buffered, 8-bit PF_HPCR triangle.
  */
-static void flat_HPCR_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                GLuint v2, GLuint pv )
+static void flat_HPCR_triangle( GLcontext *ctx, 
+                               SWvertex *v0,
+                               SWvertex *v1,
+                               SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
 #define PIXEL_TYPE GLubyte
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
 #define SETUP_CODE                             \
-   GLubyte r = VB->ColorPtr->data[pv][0];      \
-   GLubyte g = VB->ColorPtr->data[pv][1];      \
-   GLubyte b = VB->ColorPtr->data[pv][2];
+   GLubyte r = v0->color[0];   \
+   GLubyte g = v0->color[1];   \
+   GLubyte b = v0->color[2];
 #define INNER_LOOP( LEFT, RIGHT, Y )                           \
 {                                                              \
    GLint xx, yy = FLIP(xmesa->xm_buffer, Y);                   \
@@ -1366,8 +1423,10 @@ static void flat_HPCR_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 /*
  * XImage, flat, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
  */
-static void flat_LOOKUP8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
-                                  GLuint v2, GLuint pv )
+static void flat_LOOKUP8_triangle( GLcontext *ctx, 
+                                  SWvertex *v0,
+                                  SWvertex *v1,
+                                  SWvertex *v2 )
 {
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 #define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y)
@@ -1375,9 +1434,9 @@ static void flat_LOOKUP8_triangle( GLcontext *ctx, GLuint v0, GLuint v1,
 #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line)
 #define SETUP_CODE                             \
    LOOKUP_SETUP;                               \
-   GLubyte r = VB->ColorPtr->data[pv][0];              \
-   GLubyte g = VB->ColorPtr->data[pv][1];              \
-   GLubyte b = VB->ColorPtr->data[pv][2];              \
+   GLubyte r = v0->color[0];           \
+   GLubyte g = v0->color[1];           \
+   GLubyte b = v0->color[2];           \
    GLubyte p = LOOKUP(r,g,b);
 #define INNER_LOOP( LEFT, RIGHT, Y )           \
 {                                              \
@@ -1468,9 +1527,10 @@ static void setup_x_polygon_options( GLcontext *ctx )
 #endif
 
 
+
 #ifdef DEBUG
 void
-_xmesa_print_triangle_func( triangle_func triFunc )
+_xmesa_print_triangle_func( swrast_tri_func triFunc )
 {
    printf("XMesa tri func = ");
    if (triFunc ==smooth_TRUECOLOR_z_triangle)
@@ -1559,19 +1619,20 @@ _xmesa_print_triangle_func( triangle_func triFunc )
 #endif
 
 
-triangle_func xmesa_get_triangle_func( GLcontext *ctx )
+static swrast_tri_func get_triangle_func( GLcontext *ctx )
 {
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
    XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
    int depth = GET_VISUAL_DEPTH(xmesa->xm_visual);
 
    (void) kernel1;
 
-   if (ctx->Polygon.SmoothFlag)     return (triangle_func)NULL;
-   if (ctx->Texture.ReallyEnabled)  return (triangle_func)NULL;
+   if (ctx->Polygon.SmoothFlag)     return (swrast_tri_func)NULL;
+   if (ctx->Texture._ReallyEnabled)  return (swrast_tri_func)NULL;
 
    if (xmesa->xm_buffer->buffer==XIMAGE) {
       if (   ctx->Light.ShadeModel==GL_SMOOTH
-          && ctx->RasterMask==DEPTH_BIT
+          && swrast->_RasterMask==DEPTH_BIT
           && ctx->Depth.Func==GL_LESS
           && ctx->Depth.Mask==GL_TRUE
           && ctx->Visual.DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS
@@ -1597,13 +1658,13 @@ triangle_func xmesa_get_triangle_func( GLcontext *ctx )
                return (depth==8) ? smooth_DITHER8_z_triangle
                                         : smooth_DITHER_z_triangle;
             case PF_LOOKUP:
-               return (depth==8) ? smooth_LOOKUP8_z_triangle : (triangle_func)NULL;
+               return (depth==8) ? smooth_LOOKUP8_z_triangle : (swrast_tri_func)NULL;
             default:
-               return (triangle_func)NULL;
+               return (swrast_tri_func)NULL;
          }
       }
       if (   ctx->Light.ShadeModel==GL_FLAT
-          && ctx->RasterMask==DEPTH_BIT
+          && swrast->_RasterMask==DEPTH_BIT
           && ctx->Depth.Func==GL_LESS
           && ctx->Depth.Mask==GL_TRUE
           && ctx->Visual.DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS
@@ -1629,12 +1690,12 @@ triangle_func xmesa_get_triangle_func( GLcontext *ctx )
                return (depth==8) ? flat_DITHER8_z_triangle
                                         : flat_DITHER_z_triangle;
             case PF_LOOKUP:
-               return (depth==8) ? flat_LOOKUP8_z_triangle : (triangle_func)NULL;
+               return (depth==8) ? flat_LOOKUP8_z_triangle : (swrast_tri_func)NULL;
             default:
-               return (triangle_func)NULL;
+               return (swrast_tri_func)NULL;
          }
       }
-      if (   ctx->RasterMask==0   /* no depth test */
+      if (   swrast->_RasterMask==0   /* no depth test */
           && ctx->Light.ShadeModel==GL_SMOOTH
           && ctx->Polygon.StippleFlag==GL_FALSE) {
          switch (xmesa->pixelformat) {
@@ -1658,13 +1719,13 @@ triangle_func xmesa_get_triangle_func( GLcontext *ctx )
                return (depth==8) ? smooth_DITHER8_triangle
                                         : smooth_DITHER_triangle;
             case PF_LOOKUP:
-               return (depth==8) ? smooth_LOOKUP8_triangle : (triangle_func)NULL;
+               return (depth==8) ? smooth_LOOKUP8_triangle : (swrast_tri_func)NULL;
             default:
-               return (triangle_func)NULL;
+               return (swrast_tri_func)NULL;
          }
       }
 
-      if (   ctx->RasterMask==0   /* no depth test */
+      if (   swrast->_RasterMask==0   /* no depth test */
           && ctx->Light.ShadeModel==GL_FLAT
           && ctx->Polygon.StippleFlag==GL_FALSE) {
          switch (xmesa->pixelformat) {
@@ -1688,13 +1749,13 @@ triangle_func xmesa_get_triangle_func( GLcontext *ctx )
                return (depth==8) ? flat_DITHER8_triangle
                                         : flat_DITHER_triangle;
             case PF_LOOKUP:
-               return (depth==8) ? flat_LOOKUP8_triangle : (triangle_func)NULL;
+               return (depth==8) ? flat_LOOKUP8_triangle : (swrast_tri_func)NULL;
             default:
-               return (triangle_func)NULL;
+               return (swrast_tri_func)NULL;
          }
       }
 
-      return (triangle_func)NULL;
+      return (swrast_tri_func)NULL;
    }
    else {
       /* draw to pixmap */
@@ -1704,13 +1765,27 @@ triangle_func xmesa_get_triangle_func( GLcontext *ctx )
        * test failure in the conformance tests.
        * In the future, we might provide a config option to enable this.
        */
-      if (ctx->Light.ShadeModel==GL_FLAT && ctx->RasterMask==0) {
+      if (ctx->Light.ShadeModel==GL_FLAT && ctx->_RasterMask==0) {
          if (ctx->Color.DitherFlag && depth < 24)
-            return (triangle_func)NULL;
+            return (swrast_tri_func)NULL;
          setup_x_polygon_options( ctx );
          return flat_pixmap_triangle;
       }
 #endif
-      return (triangle_func)NULL;
+      return (swrast_tri_func)NULL;
    }
 }
+
+
+/* Override for the swrast tri-selection function.  Try to use one
+ * of our internal tri functions, otherwise fall back to the
+ * standard swrast functions.  
+ */
+void xmesa_choose_triangle( GLcontext *ctx )
+{
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+
+   if (!(swrast->Triangle = get_triangle_func( ctx )))
+      _swrast_choose_triangle( ctx );
+}
+
index ebea739..00787b4 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: xmesaP.h,v 1.13 2000/09/26 20:54:13 brianp Exp $ */
+/* $Id: xmesaP.h,v 1.14 2000/11/05 18:26:12 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -522,15 +522,20 @@ xmesa_color_to_pixel( XMesaContext xmesa,
 
 extern void xmesa_alloc_back_buffer( XMesaBuffer b );
 
+extern void xmesa_init_pointers( GLcontext *ctx );
 extern void xmesa_update_state( GLcontext *ctx );
 
-extern points_func xmesa_get_points_func( GLcontext *ctx );
+extern void xmesa_update_span_funcs( GLcontext *ctx );
 
-extern line_func xmesa_get_line_func( GLcontext *ctx );
+/* Plugged into the software rasterizer.  Try to use internal
+ * swrast-style point, line and triangle functions.
+ */
+extern void xmesa_choose_point( GLcontext *ctx );
+extern void xmesa_choose_line( GLcontext *ctx );
+extern void xmesa_choose_triangle( GLcontext *ctx );
 
-extern triangle_func xmesa_get_triangle_func( GLcontext *ctx );
 
-extern void xmesa_update_span_funcs( GLcontext *ctx );
+extern void xmesa_register_swrast_functions( GLcontext *ctx );