GL_(UN)PACK_SKIP_IMAGES should only be applied to 3D texture pack/unpacking
[mesa.git] / src / mesa / drivers / x11 / xm_tri.c
index f0aef4c0ec61031abf531af5583269d0e4201b57..01585b05b4d5bb82ee7e4ccf95ed4bb0693fe530 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: xm_tri.c,v 1.23 2002/06/15 02:38:17 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
+ * Version:  6.3
  *
- * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -35,8 +33,7 @@
 #include "glxheader.h"
 #include "depth.h"
 #include "macros.h"
-#include "mem.h"
-#include "mmath.h"
+#include "imports.h"
 #include "mtypes.h"
 #include "xmesaP.h"
 
 /*
  * XImage, smooth, depth-buffered, PF_TRUECOLOR triangle.
  */
-static void smooth_TRUECOLOR_z_triangle( GLcontext *ctx,
-                                         const SWvertex *v0,
-                                        const SWvertex *v1,
-                                        const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   XMesaImage *img = xmesa->xm_buffer->backimage;
+#define NAME smooth_TRUECOLOR_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   XMesaImage *img = xmesa->xm_buffer->backimage;
 
 #define RENDER_SPAN( span )                                    \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
    GLuint i;                                                   \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
          unsigned long p;                                      \
-         PACK_TRUECOLOR(p, FixedToInt(span->red),              \
-            FixedToInt(span->green), FixedToInt(span->blue));  \
+         PACK_TRUECOLOR(p, FixedToInt(span.red),               \
+            FixedToInt(span.green), FixedToInt(span.blue));    \
          XMesaPutPixel(img, x, y, p);                          \
          zRow[i] = z;                                          \
       }                                                                \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
-      span->z += span->zStep;                                  \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
+      span.z += span.zStep;                                    \
    }
 
 #include "swrast/s_tritemp.h"
-}
+
 
 
 
 /*
  * XImage, smooth, depth-buffered, PF_8A8B8G8R triangle.
  */
-static void smooth_8A8B8G8R_z_triangle( GLcontext *ctx,
-                                       const SWvertex *v0,
-                                       const SWvertex *v1,
-                                       const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME smooth_8A8B8G8R_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
 
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   for (i = 0; i < span->end; i++) {                           \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   for (i = 0; i < span.end; i++) {                            \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
-         pRow[i] = PACK_8B8G8R(FixedToInt(span->red),          \
-            FixedToInt(span->green), FixedToInt(span->blue));  \
+         pRow[i] = PACK_8B8G8R(FixedToInt(span.red),           \
+            FixedToInt(span.green), FixedToInt(span.blue));    \
          zRow[i] = z;                                          \
       }                                                                \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
-      span->z += span->zStep;                                  \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
+      span.z += span.zStep;                                    \
    }
 
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, depth-buffered, PF_8R8G8B triangle.
  */
-static void smooth_8R8G8B_z_triangle( GLcontext *ctx,
-                                     const SWvertex *v0,
-                                     const SWvertex *v1,
-                                     const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME smooth_8R8G8B_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
 
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   for (i = 0; i < span->end; i++) {                           \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   for (i = 0; i < span.end; i++) {                            \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
-         pRow[i] = PACK_8R8G8B(FixedToInt(span->red),          \
-            FixedToInt(span->green), FixedToInt(span->blue));  \
+         pRow[i] = PACK_8R8G8B(FixedToInt(span.red),           \
+            FixedToInt(span.green), FixedToInt(span.blue));    \
          zRow[i] = z;                                          \
       }                                                                \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
-      span->z += span->zStep;                                  \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
+      span.z += span.zStep;                                    \
    }
 
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, depth-buffered, PF_8R8G8B24 triangle.
  */
-static void smooth_8R8G8B24_z_triangle( GLcontext *ctx,
-                                        const SWvertex *v0,
-                                       const SWvertex *v1,
-                                       const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME smooth_8R8G8B24_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
 #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)
-
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   for (i = 0; i < span->end; i++) {                           \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   for (i = 0; i < span.end; i++) {                            \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
         PIXEL_TYPE *ptr = pRow + i;                            \
-         ptr->r = FixedToInt(span->red);                               \
-         ptr->g = FixedToInt(span->green);                     \
-         ptr->b = FixedToInt(span->blue);                      \
+         ptr->r = FixedToInt(span.red);                                \
+         ptr->g = FixedToInt(span.green);                      \
+         ptr->b = FixedToInt(span.blue);                       \
          zRow[i] = z;                                          \
       }                                                                \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
-      span->z += span->zStep;                                  \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
+      span.z += span.zStep;                                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, depth-buffered, PF_TRUEDITHER triangle.
  */
-static void smooth_TRUEDITHER_z_triangle( GLcontext *ctx,
-                                         const SWvertex *v0,
-                                         const SWvertex *v1,
-                                         const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   XMesaImage *img = xmesa->xm_buffer->backimage;
+#define NAME smooth_TRUEDITHER_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
-
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   XMesaImage *img = xmesa->xm_buffer->backimage;
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
          unsigned long p;                                      \
-         PACK_TRUEDITHER(p, x, y, FixedToInt(span->red),               \
-            FixedToInt(span->green), FixedToInt(span->blue));  \
+         PACK_TRUEDITHER(p, x, y, FixedToInt(span.red),                \
+            FixedToInt(span.green), FixedToInt(span.blue));    \
          XMesaPutPixel(img, x, y, p);                          \
          zRow[i] = z;                                          \
       }                                                                \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
-      span->z += span->zStep;                                  \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
+      span.z += span.zStep;                                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, depth-buffered, PF_5R6G5B triangle.
  */
-static void smooth_5R6G5B_z_triangle( GLcontext *ctx,
-                                      const SWvertex *v0,
-                                     const SWvertex *v1,
-                                     const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME smooth_5R6G5B_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   for (i = 0; i < span->end; i++) {                           \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   for (i = 0; i < span.end; i++) {                            \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
-         pRow[i] = PACK_5R6G5B(FixedToInt(span->red),          \
-            FixedToInt(span->green), FixedToInt(span->blue));  \
+         pRow[i] = PACK_5R6G5B(FixedToInt(span.red),           \
+            FixedToInt(span.green), FixedToInt(span.blue));    \
          zRow[i] = z;                                          \
       }                                                                \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
-      span->z += span->zStep;                                  \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
+      span.z += span.zStep;                                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, depth-buffered, PF_DITHER_5R6G5B triangle.
  */
-static void smooth_DITHER_5R6G5B_z_triangle( GLcontext *ctx,
-                                             const SWvertex *v0,
-                                            const SWvertex *v1,
-                                            const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME smooth_DITHER_5R6G5B_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
-         PACK_TRUEDITHER(pRow[i], x, y, FixedToInt(span->red), \
-            FixedToInt(span->green), FixedToInt(span->blue));  \
+         PACK_TRUEDITHER(pRow[i], x, y, FixedToInt(span.red),  \
+            FixedToInt(span.green), FixedToInt(span.blue));    \
          zRow[i] = z;                                          \
       }                                                                \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
-      span->z += span->zStep;                                  \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
+      span.z += span.zStep;                                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, depth-buffered, 8-bit, PF_DITHER8 triangle.
  */
-static void smooth_DITHER8_z_triangle( GLcontext *ctx,
-                                       const SWvertex *v0,
-                                      const SWvertex *v1,
-                                      const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME smooth_DITHER8_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
    XDITHER_SETUP(y);                                           \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
-         pRow[i] = (PIXEL_TYPE) XDITHER(x, FixedToInt(span->red),\
-            FixedToInt(span->green), FixedToInt(span->blue) ); \
+         pRow[i] = (PIXEL_TYPE) XDITHER(x, FixedToInt(span.red),\
+            FixedToInt(span.green), FixedToInt(span.blue) );   \
          zRow[i] = z;                                          \
       }                                                                \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
-      span->z += span->zStep;                                  \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
+      span.z += span.zStep;                                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, depth-buffered, PF_DITHER triangle.
  */
-static void smooth_DITHER_z_triangle( GLcontext *ctx,
-                                     const SWvertex *v0,
-                                     const SWvertex *v1,
-                                     const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   XMesaImage *img = xmesa->xm_buffer->backimage;
+#define NAME smooth_DITHER_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
-
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   XMesaImage *img = xmesa->xm_buffer->backimage;
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
    XDITHER_SETUP(y);                                           \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
-         unsigned long p = XDITHER(x, FixedToInt(span->red),   \
-            FixedToInt(span->green), FixedToInt(span->blue));  \
+         unsigned long p = XDITHER(x, FixedToInt(span.red),    \
+            FixedToInt(span.green), FixedToInt(span.blue));    \
         XMesaPutPixel(img, x, y, p);                           \
          zRow[i] = z;                                          \
       }                                                                \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
-      span->z += span->zStep;                                  \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
+      span.z += span.zStep;                                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, depth-buffered, 8-bit PF_LOOKUP triangle.
  */
-static void smooth_LOOKUP8_z_triangle( GLcontext *ctx,
-                                      const SWvertex *v0,
-                                      const SWvertex *v1,
-                                      const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME smooth_LOOKUP8_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
    LOOKUP_SETUP;                                               \
-   for (i = 0; i < span->end; i++) {                           \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   for (i = 0; i < span.end; i++) {                            \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
-         pRow[i] = LOOKUP(FixedToInt(span->red),                       \
-            FixedToInt(span->green), FixedToInt(span->blue));  \
+         pRow[i] = LOOKUP(FixedToInt(span.red),                        \
+            FixedToInt(span.green), FixedToInt(span.blue));    \
          zRow[i] = z;                                          \
       }                                                                \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
-      span->z += span->zStep;                                  \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
+      span.z += span.zStep;                                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
 
 
 
 /*
  * XImage, smooth, depth-buffered, 8-bit PF_HPCR triangle.
  */
-static void smooth_HPCR_z_triangle( GLcontext *ctx,
-                                   const SWvertex *v0,
-                                   const SWvertex *v1,
-                                   const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME smooth_HPCR_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
-         pRow[i] = DITHER_HPCR(x, y, FixedToInt(span->red),    \
-            FixedToInt(span->green), FixedToInt(span->blue) ); \
+         pRow[i] = DITHER_HPCR(x, y, FixedToInt(span.red),     \
+            FixedToInt(span.green), FixedToInt(span.blue) );   \
          zRow[i] = z;                                          \
       }                                                                \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
-      span->z += span->zStep;                                  \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
+      span.z += span.zStep;                                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, depth-buffered, PF_TRUECOLOR triangle.
  */
-static void flat_TRUECOLOR_z_triangle( GLcontext *ctx,
-                                      const SWvertex *v0,
-                                      const SWvertex *v1,
-                                      const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   XMesaImage *img = xmesa->xm_buffer->backimage;
+#define NAME flat_TRUECOLOR_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   XMesaImage *img = xmesa->xm_buffer->backimage;              \
    unsigned long pixel;                                                \
    PACK_TRUECOLOR(pixel, v2->color[0], v2->color[1], v2->color[2]);
-
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
          XMesaPutPixel(img, x, y, pixel);                      \
          zRow[i] = z;                                          \
       }                                                                \
-      span->z += span->zStep;                                  \
+      span.z += span.zStep;                                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, depth-buffered, PF_8A8B8G8R triangle.
  */
-static void flat_8A8B8G8R_z_triangle( GLcontext *ctx,
-                                     const SWvertex *v0,
-                                     const SWvertex *v1,
-                                     const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME flat_8A8B8G8R_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #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( v2->color[0],        \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);            \
+   unsigned long p = PACK_8B8G8R( v2->color[0],                \
                 v2->color[1], v2->color[2] );
 #define RENDER_SPAN( span )                            \
    GLuint i;                                           \
-   for (i = 0; i < span->end; i++) {                   \
-      const DEPTH_TYPE z = FixedToDepth(span->z);      \
+   for (i = 0; i < span.end; i++) {                    \
+      const DEPTH_TYPE z = FixedToDepth(span.z);       \
       if (z < zRow[i]) {                               \
         pRow[i] = (PIXEL_TYPE) p;                      \
          zRow[i] = z;                                  \
       }                                                        \
-      span->z += span->zStep;                          \
+      span.z += span.zStep;                            \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, depth-buffered, PF_8R8G8B triangle.
  */
-static void flat_8R8G8B_z_triangle( GLcontext *ctx,
-                                   const SWvertex *v0,
-                                   const SWvertex *v1,
-                                   const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME flat_8R8G8B_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #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( v2->color[0],        \
+#define SETUP_CODE                                     \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);            \
+   unsigned long p = PACK_8R8G8B( v2->color[0],                \
                 v2->color[1], v2->color[2] );
 #define RENDER_SPAN( span )                    \
    GLuint i;                                   \
-   for (i = 0; i < span->end; i++) {           \
-      DEPTH_TYPE z = FixedToDepth(span->z);    \
+   for (i = 0; i < span.end; i++) {            \
+      DEPTH_TYPE z = FixedToDepth(span.z);     \
       if (z < zRow[i]) {                       \
         pRow[i] = (PIXEL_TYPE) p;              \
          zRow[i] = z;                          \
       }                                                \
-      span->z += span->zStep;                  \
+      span.z += span.zStep;                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, depth-buffered, PF_8R8G8B24 triangle.
  */
-static void flat_8R8G8B24_z_triangle( GLcontext *ctx,
-                                     const SWvertex *v0,
-                                     const SWvertex *v1,
-                                     const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = v2->color;
+#define NAME flat_8R8G8B24_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #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)
+#define SETUP_CODE                                     \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);            \
+   const GLubyte *color = v2->color;
 #define RENDER_SPAN( span )                            \
    GLuint i;                                           \
-   for (i = 0; i < span->end; i++) {                   \
-      const DEPTH_TYPE z = FixedToDepth(span->z);      \
+   for (i = 0; i < span.end; i++) {                    \
+      const DEPTH_TYPE z = FixedToDepth(span.z);       \
       if (z < zRow[i]) {                               \
         PIXEL_TYPE *ptr = pRow + i;                    \
          ptr->r = color[RCOMP];                                \
@@ -572,30 +500,26 @@ static void flat_8R8G8B24_z_triangle( GLcontext *ctx,
          ptr->b = color[BCOMP];                                \
          zRow[i] = z;                                  \
       }                                                        \
-      span->z += span->zStep;                          \
+      span.z += span.zStep;                            \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, depth-buffered, PF_TRUEDITHER triangle.
  */
-static void flat_TRUEDITHER_z_triangle( GLcontext *ctx,
-                                       const SWvertex *v0,
-                                       const SWvertex *v1,
-                                       const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   XMesaImage *img = xmesa->xm_buffer->backimage;
+#define NAME flat_TRUEDITHER_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   XMesaImage *img = xmesa->xm_buffer->backimage;
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
          unsigned long p;                                      \
          PACK_TRUEDITHER(p, x, y, v2->color[0],                        \
@@ -603,896 +527,759 @@ static void flat_TRUEDITHER_z_triangle( GLcontext *ctx,
          XMesaPutPixel(img, x, y, p);                          \
          zRow[i] = z;                                          \
       }                                                                \
-      span->z += span->zStep;                                  \
+      span.z += span.zStep;                                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, depth-buffered, PF_5R6G5B triangle.
  */
-static void flat_5R6G5B_z_triangle( GLcontext *ctx,
-                                   const SWvertex *v0,
-                                   const SWvertex *v1,
-                                   const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME flat_5R6G5B_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #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                                     \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);            \
    unsigned long p = PACK_5R6G5B( v2->color[0],                \
             v2->color[1], v2->color[2] );
 #define RENDER_SPAN( span )                            \
    GLuint i;                                           \
-   for (i = 0; i < span->end; i++) {                   \
-      const DEPTH_TYPE z = FixedToDepth(span->z);      \
+   for (i = 0; i < span.end; i++) {                    \
+      const DEPTH_TYPE z = FixedToDepth(span.z);       \
       if (z < zRow[i]) {                               \
         pRow[i] = (PIXEL_TYPE) p;                      \
          zRow[i] = z;                                  \
       }                                                        \
-      span->z += span->zStep;                          \
+      span.z += span.zStep;                            \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, depth-buffered, PF_DITHER_5R6G5B triangle.
  */
-static void flat_DITHER_5R6G5B_z_triangle( GLcontext *ctx,
-                                          const SWvertex *v0,
-                                          const SWvertex *v1,
-                                          const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = v2->color;
+#define NAME flat_DITHER_5R6G5B_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   const GLubyte *color = v2->color;
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
         PACK_TRUEDITHER(pRow[i], x, y, color[RCOMP],           \
                         color[GCOMP], color[BCOMP]);           \
          zRow[i] = z;                                          \
       }                                                                \
-      span->z += span->zStep;                                  \
+      span.z += span.zStep;                                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, depth-buffered, 8-bit PF_DITHER triangle.
  */
-static void flat_DITHER8_z_triangle( GLcontext *ctx,
-                                    const SWvertex *v0,
-                                    const SWvertex *v1,
-                                    const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME flat_DITHER8_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #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     \
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
    FLAT_DITHER_SETUP( v2->color[0], v2->color[1], v2->color[2] );
-
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
    FLAT_DITHER_ROW_SETUP(FLIP(xmesa->xm_buffer, y));           \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
         pRow[i] = (PIXEL_TYPE) FLAT_DITHER(x);                 \
          zRow[i] = z;                                          \
       }                                                                \
-      span->z += span->zStep;                                  \
+      span.z += span.zStep;                                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, depth-buffered, PF_DITHER triangle.
  */
-static void flat_DITHER_z_triangle( GLcontext *ctx,
-                                   const SWvertex *v0,
-                                   const SWvertex *v1,
-                                   const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   XMesaImage *img = xmesa->xm_buffer->backimage;
+#define NAME flat_DITHER_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
-#define SETUP_CODE     \
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   XMesaImage *img = xmesa->xm_buffer->backimage;              \
    FLAT_DITHER_SETUP( v2->color[0], v2->color[1], v2->color[2] );
-
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
    FLAT_DITHER_ROW_SETUP(y);                                   \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
          unsigned long p = FLAT_DITHER(x);                     \
         XMesaPutPixel(img, x, y, p);                           \
          zRow[i] = z;                                          \
       }                                                                \
-      span->z += span->zStep;                                  \
+      span.z += span.zStep;                                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, depth-buffered, 8-bit PF_HPCR triangle.
  */
-static void flat_HPCR_z_triangle( GLcontext *ctx,
-                                 const SWvertex *v0,
-                                 const SWvertex *v1,
-                                 const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME flat_HPCR_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #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 = v2->color[0];   \
-   GLubyte g = v2->color[1];   \
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   GLubyte r = v2->color[0];                                   \
+   GLubyte g = v2->color[1];                                   \
    GLubyte b = v2->color[2];
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      const DEPTH_TYPE z = FixedToDepth(span->z);              \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      const DEPTH_TYPE z = FixedToDepth(span.z);               \
       if (z < zRow[i]) {                                       \
         pRow[i] = (PIXEL_TYPE) DITHER_HPCR(x, y, r, g, b);     \
          zRow[i] = z;                                          \
       }                                                                \
-      span->z += span->zStep;                                  \
+      span.z += span.zStep;                                    \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, depth-buffered, 8-bit PF_LOOKUP triangle.
  */
-static void flat_LOOKUP8_z_triangle( GLcontext *ctx,
-                                    const SWvertex *v0,
-                                    const SWvertex *v1,
-                                    const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME flat_LOOKUP8_z_triangle
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #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                             \
-   LOOKUP_SETUP;                               \
-   GLubyte r = v2->color[0];   \
-   GLubyte g = v2->color[1];   \
-   GLubyte b = v2->color[2];   \
+#define SETUP_CODE                                     \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);            \
+   LOOKUP_SETUP;                                       \
+   GLubyte r = v2->color[0];                           \
+   GLubyte g = v2->color[1];                           \
+   GLubyte b = v2->color[2];                           \
    GLubyte p = LOOKUP(r,g,b);
 #define RENDER_SPAN( span )                            \
    GLuint i;                                           \
-   for (i = 0; i < span->end; i++) {                   \
-      const DEPTH_TYPE z = FixedToDepth(span->z);      \
+   for (i = 0; i < span.end; i++) {                    \
+      const DEPTH_TYPE z = FixedToDepth(span.z);       \
       if (z < zRow[i]) {                               \
         pRow[i] = p;                                   \
          zRow[i] = z;                                  \
       }                                                        \
-      span->z += span->zStep;                          \
+      span.z += span.zStep;                            \
    }
-
 #include "swrast/s_tritemp.h"
-}
 
 
 
 /*
  * XImage, smooth, NON-depth-buffered, PF_TRUECOLOR triangle.
  */
-static void smooth_TRUECOLOR_triangle( GLcontext *ctx,
-                                      const SWvertex *v0,
-                                      const SWvertex *v1,
-                                      const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   XMesaImage *img = xmesa->xm_buffer->backimage;
+#define NAME smooth_TRUECOLOR_triangle
 #define INTERP_RGB 1
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   XMesaImage *img = xmesa->xm_buffer->backimage;
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
       unsigned long p;                                         \
-      PACK_TRUECOLOR(p, FixedToInt(span->red),                 \
-         FixedToInt(span->green), FixedToInt(span->blue));     \
+      PACK_TRUECOLOR(p, FixedToInt(span.red),                  \
+         FixedToInt(span.green), FixedToInt(span.blue));       \
       XMesaPutPixel(img, x, y, p);                             \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, NON-depth-buffered, PF_8A8B8G8R triangle.
  */
-static void smooth_8A8B8G8R_triangle( GLcontext *ctx,
-                                     const SWvertex *v0,
-                                     const SWvertex *v1,
-                                     const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME smooth_8A8B8G8R_triangle
 #define INTERP_RGB 1
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   for (i = 0; i < span->end; i++) {                           \
-      pRow[i] = PACK_8B8G8R(FixedToInt(span->red),             \
-         FixedToInt(span->green), FixedToInt(span->blue) );    \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
-   }                                                           \
-
+   for (i = 0; i < span.end; i++) {                            \
+      pRow[i] = PACK_8B8G8R(FixedToInt(span.red),              \
+         FixedToInt(span.green), FixedToInt(span.blue) );      \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
+   }
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
  */
-static void smooth_8R8G8B_triangle( GLcontext *ctx,
-                                   const SWvertex *v0,
-                                   const SWvertex *v1,
-                                   const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME smooth_8R8G8B_triangle
 #define INTERP_RGB 1
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   for (i = 0; i < span->end; i++) {                           \
-      pRow[i] = PACK_8R8G8B(FixedToInt(span->red),             \
-         FixedToInt(span->green), FixedToInt(span->blue) );    \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
+   for (i = 0; i < span.end; i++) {                            \
+      pRow[i] = PACK_8R8G8B(FixedToInt(span.red),              \
+         FixedToInt(span.green), FixedToInt(span.blue) );      \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle.
  */
-static void smooth_8R8G8B24_triangle( GLcontext *ctx,
-                                     const SWvertex *v0,
-                                     const SWvertex *v1,
-                                     const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME smooth_8R8G8B24_triangle
 #define INTERP_RGB 1
 #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)
+#define SETUP_CODE                                     \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
 #define RENDER_SPAN( span )                            \
    GLuint i;                                           \
    PIXEL_TYPE *pixel = pRow;                           \
-   for (i = 0; i < span->end; i++, pixel++) {          \
-      pixel->r = FixedToInt(span->red);                        \
-      pixel->g = FixedToInt(span->green);              \
-      pixel->b = FixedToInt(span->blue);                       \
-      span->red += span->redStep;                              \
-      span->green += span->greenStep;                  \
-      span->blue += span->blueStep;                    \
+   for (i = 0; i < span.end; i++, pixel++) {           \
+      pixel->r = FixedToInt(span.red);                 \
+      pixel->g = FixedToInt(span.green);               \
+      pixel->b = FixedToInt(span.blue);                        \
+      span.red += span.redStep;                                \
+      span.green += span.greenStep;                    \
+      span.blue += span.blueStep;                      \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, NON-depth-buffered, PF_TRUEDITHER triangle.
  */
-static void smooth_TRUEDITHER_triangle( GLcontext *ctx,
-                                       const SWvertex *v0,
-                                       const SWvertex *v1,
-                                       const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   XMesaImage *img = xmesa->xm_buffer->backimage;
+#define NAME smooth_TRUEDITHER_triangle
 #define INTERP_RGB 1
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   XMesaImage *img = xmesa->xm_buffer->backimage;
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
       unsigned long p;                                         \
-      PACK_TRUEDITHER(p, x, y, FixedToInt(span->red),          \
-         FixedToInt(span->green), FixedToInt(span->blue));     \
+      PACK_TRUEDITHER(p, x, y, FixedToInt(span.red),           \
+         FixedToInt(span.green), FixedToInt(span.blue));       \
       XMesaPutPixel(img, x, y, p );                            \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, NON-depth-buffered, PF_5R6G5B triangle.
  */
-static void smooth_5R6G5B_triangle( GLcontext *ctx,
-                                   const SWvertex *v0,
-                                   const SWvertex *v1,
-                                   const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME smooth_5R6G5B_triangle
 #define INTERP_RGB 1
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   for (i = 0; i < span->end; i++) {                           \
-      pRow[i] = (PIXEL_TYPE) PACK_5R6G5B(FixedToInt(span->red),        \
-         FixedToInt(span->green), FixedToInt(span->blue));     \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
+   for (i = 0; i < span.end; i++) {                            \
+      pRow[i] = (PIXEL_TYPE) PACK_5R6G5B(FixedToInt(span.red), \
+         FixedToInt(span.green), FixedToInt(span.blue));       \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, NON-depth-buffered, PF_DITHER_5R6G5B triangle.
  */
-static void smooth_DITHER_5R6G5B_triangle( GLcontext *ctx,
-                                          const SWvertex *v0,
-                                          const SWvertex *v1,
-                                          const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME smooth_DITHER_5R6G5B_triangle
 #define INTERP_RGB 1
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      PACK_TRUEDITHER(pRow[i], x, y, FixedToInt(span->red),    \
-         FixedToInt(span->green), FixedToInt(span->blue));     \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      PACK_TRUEDITHER(pRow[i], x, y, FixedToInt(span.red),     \
+         FixedToInt(span.green), FixedToInt(span.blue));       \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, NON-depth-buffered, 8-bit PF_DITHER triangle.
  */
-static void smooth_DITHER8_triangle( GLcontext *ctx,
-                                    const SWvertex *v0,
-                                    const SWvertex *v1,
-                                    const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME smooth_DITHER8_triangle
 #define INTERP_RGB 1
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
    XDITHER_SETUP(y);                                           \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      pRow[i] = (PIXEL_TYPE) XDITHER(x, FixedToInt(span->red), \
-         FixedToInt(span->green), FixedToInt(span->blue) );    \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      pRow[i] = (PIXEL_TYPE) XDITHER(x, FixedToInt(span.red),  \
+         FixedToInt(span.green), FixedToInt(span.blue) );      \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, NON-depth-buffered, PF_DITHER triangle.
  */
-static void smooth_DITHER_triangle( GLcontext *ctx,
-                                   const SWvertex *v0,
-                                   const SWvertex *v1,
-                                   const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   XMesaImage *img = xmesa->xm_buffer->backimage;
-
+#define NAME smooth_DITHER_triangle
 #define INTERP_RGB 1
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   XMesaImage *img = xmesa->xm_buffer->backimage;
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
    XDITHER_SETUP(y);                                           \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      unsigned long p = XDITHER(x, FixedToInt(span->red),      \
-         FixedToInt(span->green), FixedToInt(span->blue) );    \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      unsigned long p = XDITHER(x, FixedToInt(span.red),       \
+         FixedToInt(span.green), FixedToInt(span.blue) );      \
       XMesaPutPixel(img, x, y, p);                             \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, smooth, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
  */
-static void smooth_LOOKUP8_triangle( GLcontext *ctx,
-                                    const SWvertex *v0,
-                                    const SWvertex *v1,
-                                    const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-
+#define NAME smooth_LOOKUP8_triangle
 #define INTERP_RGB 1
 #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 RENDER_SPAN( span )                            \
-   GLuint i;                                           \
-   LOOKUP_SETUP;                                       \
-   for (i = 0; i < span->end; i++) {                   \
-      pRow[i] = LOOKUP(FixedToInt(span->red),          \
-         FixedToInt(span->green), FixedToInt(span->blue));\
-      span->red += span->redStep;                              \
-      span->green += span->greenStep;                  \
-      span->blue += span->blueStep;                    \
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
+#define RENDER_SPAN( span )                                    \
+   GLuint i;                                                   \
+   LOOKUP_SETUP;                                               \
+   for (i = 0; i < span.end; i++) {                            \
+      pRow[i] = LOOKUP(FixedToInt(span.red),                   \
+         FixedToInt(span.green), FixedToInt(span.blue));       \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
    }
-
 #include "swrast/s_tritemp.h"
-}
 
 
 
 /*
  * XImage, smooth, NON-depth-buffered, 8-bit PF_HPCR triangle.
  */
-static void smooth_HPCR_triangle( GLcontext *ctx,
-                                 const SWvertex *v0,
-                                 const SWvertex *v1,
-                                 const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-
+#define NAME smooth_HPCR_triangle
 #define INTERP_RGB 1
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
-      pRow[i] = DITHER_HPCR(x, y, FixedToInt(span->red),               \
-         FixedToInt(span->green), FixedToInt(span->blue));     \
-      span->red += span->redStep;                                      \
-      span->green += span->greenStep;                          \
-      span->blue += span->blueStep;                            \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
+      pRow[i] = DITHER_HPCR(x, y, FixedToInt(span.red),                \
+         FixedToInt(span.green), FixedToInt(span.blue));       \
+      span.red += span.redStep;                                        \
+      span.green += span.greenStep;                            \
+      span.blue += span.blueStep;                              \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, NON-depth-buffered, PF_TRUECOLOR triangle.
  */
-static void flat_TRUECOLOR_triangle( GLcontext *ctx,
-                                    const SWvertex *v0,
-                                    const SWvertex *v1,
-                                    const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   XMesaImage *img = xmesa->xm_buffer->backimage;
+#define NAME flat_TRUECOLOR_triangle
 #define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   XMesaImage *img = xmesa->xm_buffer->backimage;              \
    unsigned long pixel;                                                \
    PACK_TRUECOLOR(pixel, v2->color[0], v2->color[1], v2->color[2]);
-
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
       XMesaPutPixel(img, x, y, pixel);                         \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, NON-depth-buffered, PF_8A8B8G8R triangle.
  */
-static void flat_8A8B8G8R_triangle( GLcontext *ctx,
-                                   const SWvertex *v0,
-                                   const SWvertex *v1,
-                                   const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME flat_8A8B8G8R_triangle
 #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                                     \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);            \
    unsigned long p = PACK_8B8G8R( v2->color[0],                \
                 v2->color[1], v2->color[2] );
-#define RENDER_SPAN( span )                    \
-   GLuint i;                                   \
-   for (i = 0; i < span->end; i++) {           \
-      pRow[i] = (PIXEL_TYPE) p;                        \
+#define RENDER_SPAN( span )                            \
+   GLuint i;                                           \
+   for (i = 0; i < span.end; i++) {                    \
+      pRow[i] = (PIXEL_TYPE) p;                                \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, NON-depth-buffered, PF_8R8G8B triangle.
  */
-static void flat_8R8G8B_triangle( GLcontext *ctx,
-                                 const SWvertex *v0,
-                                 const SWvertex *v1,
-                                 const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME flat_8R8G8B_triangle
 #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( v2->color[0],        \
+#define SETUP_CODE                                     \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);            \
+   unsigned long p = PACK_8R8G8B( v2->color[0],                \
                 v2->color[1], v2->color[2] );
-#define RENDER_SPAN( span )                    \
-   GLuint i;                                   \
-   for (i = 0; i < span->end; i++) {           \
-      pRow[i] = (PIXEL_TYPE) p;                        \
+#define RENDER_SPAN( span )                            \
+   GLuint i;                                           \
+   for (i = 0; i < span.end; i++) {                    \
+      pRow[i] = (PIXEL_TYPE) p;                                \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, NON-depth-buffered, PF_8R8G8B24 triangle.
  */
-static void flat_8R8G8B24_triangle( GLcontext *ctx,
-                                   const SWvertex *v0,
-                                   const SWvertex *v1,
-                                   const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = v2->color;
+#define NAME flat_8R8G8B24_triangle
 #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)
+#define SETUP_CODE                                     \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);            \
+   const GLubyte *color = v2->color;
 #define RENDER_SPAN( span )                            \
    GLuint i;                                           \
    PIXEL_TYPE *pixel = pRow;                           \
-   for (i = 0; i < span->end; i++, pixel++) {          \
+   for (i = 0; i < span.end; i++, pixel++) {           \
       pixel->r = color[RCOMP];                         \
       pixel->g = color[GCOMP];                         \
       pixel->b = color[BCOMP];                         \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
+
 
 /*
  * XImage, flat, NON-depth-buffered, PF_TRUEDITHER triangle.
  */
-static void flat_TRUEDITHER_triangle( GLcontext *ctx,
-                                     const SWvertex *v0,
-                                     const SWvertex *v1,
-                                     const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME flat_TRUEDITHER_triangle
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
    XMesaImage *img = xmesa->xm_buffer->backimage;
-
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
       unsigned long p;                                         \
       PACK_TRUEDITHER(p, x, y, v2->color[0],                   \
                v2->color[1], v2->color[2] );                   \
       XMesaPutPixel(img, x, y, p);                             \
    }
-
 #include "swrast/s_tritemp.h"
-}
 
 
 
 /*
  * XImage, flat, NON-depth-buffered, PF_5R6G5B triangle.
  */
-static void flat_5R6G5B_triangle( GLcontext *ctx,
-                                 const SWvertex *v0,
-                                 const SWvertex *v1,
-                                 const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME flat_5R6G5B_triangle
 #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( v2->color[0],        \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);            \
+   unsigned long p = PACK_5R6G5B( v2->color[0],                \
                 v2->color[1], v2->color[2] );
-#define RENDER_SPAN( span )                    \
-   GLuint i;                                   \
-   for (i = 0; i < span->end; i++) {           \
-      pRow[i] = (PIXEL_TYPE) p;                        \
+#define RENDER_SPAN( span )                            \
+   GLuint i;                                           \
+   for (i = 0; i < span.end; i++) {                    \
+      pRow[i] = (PIXEL_TYPE) p;                                \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, NON-depth-buffered, PF_DITHER_5R6G5B triangle.
  */
-static void flat_DITHER_5R6G5B_triangle( GLcontext *ctx,
-                                        const SWvertex *v0,
-                                        const SWvertex *v1,
-                                        const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   const GLubyte *color = v2->color;
+#define NAME flat_DITHER_5R6G5B_triangle
 #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                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   const GLubyte *color = v2->color;
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
       PACK_TRUEDITHER(pRow[i], x, y, color[RCOMP],             \
          color[GCOMP], color[BCOMP]);                          \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, NON-depth-buffered, 8-bit PF_DITHER triangle.
  */
-static void flat_DITHER8_triangle( GLcontext *ctx,
-                                  const SWvertex *v0,
-                                  const SWvertex *v1,
-                                  const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME flat_DITHER8_triangle
 #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     \
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
    FLAT_DITHER_SETUP( v2->color[0], v2->color[1], v2->color[2] );
-
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
    FLAT_DITHER_ROW_SETUP(FLIP(xmesa->xm_buffer, y));           \
-   for (i = 0; i < span->end; i++, x++) {                      \
+   for (i = 0; i < span.end; i++, x++) {                       \
       pRow[i] = (PIXEL_TYPE) FLAT_DITHER(x);                   \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, NON-depth-buffered, PF_DITHER triangle.
  */
-static void flat_DITHER_triangle( GLcontext *ctx,
-                                 const SWvertex *v0,
-                                 const SWvertex *v1,
-                                 const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
-   XMesaImage *img = xmesa->xm_buffer->backimage;
-#define SETUP_CODE     \
+#define NAME flat_DITHER_triangle
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   XMesaImage *img = xmesa->xm_buffer->backimage;              \
    FLAT_DITHER_SETUP( v2->color[0], v2->color[1], v2->color[2] );
-
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
    FLAT_DITHER_ROW_SETUP(y);                                   \
-   for (i = 0; i < span->end; i++, x++) {                      \
+   for (i = 0; i < span.end; i++, x++) {                       \
       unsigned long p = FLAT_DITHER(x);                                \
       XMesaPutPixel(img, x, y, p );                            \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, NON-depth-buffered, 8-bit PF_HPCR triangle.
  */
-static void flat_HPCR_triangle( GLcontext *ctx,
-                               const SWvertex *v0,
-                               const SWvertex *v1,
-                               const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME flat_HPCR_triangle
 #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 = v2->color[0];   \
-   GLubyte g = v2->color[1];   \
+#define SETUP_CODE                                             \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);                    \
+   GLubyte r = v2->color[0];                                   \
+   GLubyte g = v2->color[1];                                   \
    GLubyte b = v2->color[2];
-#define RENDER_SPAN( span )                            \
+#define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
-   GLint x = span->x, y = FLIP(xmesa->xm_buffer, span->y);     \
-   for (i = 0; i < span->end; i++, x++) {                      \
+   GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y);       \
+   for (i = 0; i < span.end; i++, x++) {                       \
       pRow[i] = (PIXEL_TYPE) DITHER_HPCR(x, y, r, g, b);       \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 /*
  * XImage, flat, NON-depth-buffered, 8-bit PF_LOOKUP triangle.
  */
-static void flat_LOOKUP8_triangle( GLcontext *ctx,
-                                  const SWvertex *v0,
-                                  const SWvertex *v1,
-                                  const SWvertex *v2 )
-{
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+#define NAME flat_LOOKUP8_triangle
 #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                             \
-   LOOKUP_SETUP;                               \
-   GLubyte r = v2->color[0];                   \
-   GLubyte g = v2->color[1];                   \
-   GLubyte b = v2->color[2];                   \
+#define SETUP_CODE                                     \
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);            \
+   LOOKUP_SETUP;                                       \
+   GLubyte r = v2->color[0];                           \
+   GLubyte g = v2->color[1];                           \
+   GLubyte b = v2->color[2];                           \
    GLubyte p = LOOKUP(r,g,b);
-#define RENDER_SPAN( span )                    \
-   GLuint i;                                   \
-   for (i = 0; i < span->end; i++) {           \
-      pRow[i] = (PIXEL_TYPE) p;                        \
+#define RENDER_SPAN( span )                            \
+   GLuint i;                                           \
+   for (i = 0; i < span.end; i++) {                    \
+      pRow[i] = (PIXEL_TYPE) p;                                \
    }
-
 #include "swrast/s_tritemp.h"
-}
+
 
 
 #ifdef DEBUG
 extern void _xmesa_print_triangle_func( swrast_tri_func triFunc );
 void _xmesa_print_triangle_func( swrast_tri_func triFunc )
 {
-   printf("XMesa tri func = ");
+   _mesa_printf("XMesa tri func = ");
    if (triFunc ==smooth_TRUECOLOR_z_triangle)
-      printf("smooth_TRUECOLOR_z_triangle\n");
+      _mesa_printf("smooth_TRUECOLOR_z_triangle\n");
    else if (triFunc ==smooth_8A8B8G8R_z_triangle)
-      printf("smooth_8A8B8G8R_z_triangle\n");
+      _mesa_printf("smooth_8A8B8G8R_z_triangle\n");
    else if (triFunc ==smooth_8R8G8B_z_triangle)
-      printf("smooth_8R8G8B_z_triangle\n");
+      _mesa_printf("smooth_8R8G8B_z_triangle\n");
    else if (triFunc ==smooth_8R8G8B24_z_triangle)
-      printf("smooth_8R8G8B24_z_triangle\n");
+      _mesa_printf("smooth_8R8G8B24_z_triangle\n");
    else if (triFunc ==smooth_TRUEDITHER_z_triangle)
-      printf("smooth_TRUEDITHER_z_triangle\n");
+      _mesa_printf("smooth_TRUEDITHER_z_triangle\n");
    else if (triFunc ==smooth_5R6G5B_z_triangle)
-      printf("smooth_5R6G5B_z_triangle\n");
+      _mesa_printf("smooth_5R6G5B_z_triangle\n");
    else if (triFunc ==smooth_DITHER_5R6G5B_z_triangle)
-      printf("smooth_DITHER_5R6G5B_z_triangle\n");
+      _mesa_printf("smooth_DITHER_5R6G5B_z_triangle\n");
    else if (triFunc ==smooth_HPCR_z_triangle)
-      printf("smooth_HPCR_z_triangle\n");
+      _mesa_printf("smooth_HPCR_z_triangle\n");
    else if (triFunc ==smooth_DITHER8_z_triangle)
-      printf("smooth_DITHER8_z_triangle\n");
+      _mesa_printf("smooth_DITHER8_z_triangle\n");
    else if (triFunc ==smooth_LOOKUP8_z_triangle)
-      printf("smooth_LOOKUP8_z_triangle\n");
+      _mesa_printf("smooth_LOOKUP8_z_triangle\n");
    else if (triFunc ==flat_TRUECOLOR_z_triangle)
-      printf("flat_TRUECOLOR_z_triangle\n");
+      _mesa_printf("flat_TRUECOLOR_z_triangle\n");
    else if (triFunc ==flat_8A8B8G8R_z_triangle)
-      printf("flat_8A8B8G8R_z_triangle\n");
+      _mesa_printf("flat_8A8B8G8R_z_triangle\n");
    else if (triFunc ==flat_8R8G8B_z_triangle)
-      printf("flat_8R8G8B_z_triangle\n");
+      _mesa_printf("flat_8R8G8B_z_triangle\n");
    else if (triFunc ==flat_8R8G8B24_z_triangle)
-      printf("flat_8R8G8B24_z_triangle\n");
+      _mesa_printf("flat_8R8G8B24_z_triangle\n");
    else if (triFunc ==flat_TRUEDITHER_z_triangle)
-      printf("flat_TRUEDITHER_z_triangle\n");
+      _mesa_printf("flat_TRUEDITHER_z_triangle\n");
    else if (triFunc ==flat_5R6G5B_z_triangle)
-      printf("flat_5R6G5B_z_triangle\n");
+      _mesa_printf("flat_5R6G5B_z_triangle\n");
    else if (triFunc ==flat_DITHER_5R6G5B_z_triangle)
-      printf("flat_DITHER_5R6G5B_z_triangle\n");
+      _mesa_printf("flat_DITHER_5R6G5B_z_triangle\n");
    else if (triFunc ==flat_HPCR_z_triangle)
-      printf("flat_HPCR_z_triangle\n");
+      _mesa_printf("flat_HPCR_z_triangle\n");
    else if (triFunc ==flat_DITHER8_z_triangle)
-      printf("flat_DITHER8_z_triangle\n");
+      _mesa_printf("flat_DITHER8_z_triangle\n");
    else if (triFunc ==flat_LOOKUP8_z_triangle)
-      printf("flat_LOOKUP8_z_triangle\n");
+      _mesa_printf("flat_LOOKUP8_z_triangle\n");
    else if (triFunc ==smooth_TRUECOLOR_triangle)
-      printf("smooth_TRUECOLOR_triangle\n");
+      _mesa_printf("smooth_TRUECOLOR_triangle\n");
    else if (triFunc ==smooth_8A8B8G8R_triangle)
-      printf("smooth_8A8B8G8R_triangle\n");
+      _mesa_printf("smooth_8A8B8G8R_triangle\n");
    else if (triFunc ==smooth_8R8G8B_triangle)
-      printf("smooth_8R8G8B_triangle\n");
+      _mesa_printf("smooth_8R8G8B_triangle\n");
    else if (triFunc ==smooth_8R8G8B24_triangle)
-      printf("smooth_8R8G8B24_triangle\n");
+      _mesa_printf("smooth_8R8G8B24_triangle\n");
    else if (triFunc ==smooth_TRUEDITHER_triangle)
-      printf("smooth_TRUEDITHER_triangle\n");
+      _mesa_printf("smooth_TRUEDITHER_triangle\n");
    else if (triFunc ==smooth_5R6G5B_triangle)
-      printf("smooth_5R6G5B_triangle\n");
+      _mesa_printf("smooth_5R6G5B_triangle\n");
    else if (triFunc ==smooth_DITHER_5R6G5B_triangle)
-      printf("smooth_DITHER_5R6G5B_triangle\n");
+      _mesa_printf("smooth_DITHER_5R6G5B_triangle\n");
    else if (triFunc ==smooth_HPCR_triangle)
-      printf("smooth_HPCR_triangle\n");
+      _mesa_printf("smooth_HPCR_triangle\n");
    else if (triFunc ==smooth_DITHER8_triangle)
-      printf("smooth_DITHER8_triangle\n");
+      _mesa_printf("smooth_DITHER8_triangle\n");
    else if (triFunc ==smooth_LOOKUP8_triangle)
-      printf("smooth_LOOKUP8_triangle\n");
+      _mesa_printf("smooth_LOOKUP8_triangle\n");
    else if (triFunc ==flat_TRUECOLOR_triangle)
-      printf("flat_TRUECOLOR_triangle\n");
+      _mesa_printf("flat_TRUECOLOR_triangle\n");
    else if (triFunc ==flat_TRUEDITHER_triangle)
-      printf("flat_TRUEDITHER_triangle\n");
+      _mesa_printf("flat_TRUEDITHER_triangle\n");
    else if (triFunc ==flat_8A8B8G8R_triangle)
-      printf("flat_8A8B8G8R_triangle\n");
+      _mesa_printf("flat_8A8B8G8R_triangle\n");
    else if (triFunc ==flat_8R8G8B_triangle)
-      printf("flat_8R8G8B_triangle\n");
+      _mesa_printf("flat_8R8G8B_triangle\n");
    else if (triFunc ==flat_8R8G8B24_triangle)
-      printf("flat_8R8G8B24_triangle\n");
+      _mesa_printf("flat_8R8G8B24_triangle\n");
    else if (triFunc ==flat_5R6G5B_triangle)
-      printf("flat_5R6G5B_triangle\n");
+      _mesa_printf("flat_5R6G5B_triangle\n");
    else if (triFunc ==flat_DITHER_5R6G5B_triangle)
-      printf("flat_DITHER_5R6G5B_triangle\n");
+      _mesa_printf("flat_DITHER_5R6G5B_triangle\n");
    else if (triFunc ==flat_HPCR_triangle)
-      printf("flat_HPCR_triangle\n");
+      _mesa_printf("flat_HPCR_triangle\n");
    else if (triFunc ==flat_DITHER8_triangle)
-      printf("flat_DITHER8_triangle\n");
+      _mesa_printf("flat_DITHER8_triangle\n");
    else if (triFunc ==flat_LOOKUP8_triangle)
-      printf("flat_LOOKUP8_triangle\n");
+      _mesa_printf("flat_LOOKUP8_triangle\n");
    else
-      printf("???\n");
+      _mesa_printf("???\n");
 }
 #endif
 
@@ -1518,19 +1305,22 @@ do {                                   \
 static swrast_tri_func get_triangle_func( GLcontext *ctx )
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
-   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
+   XMesaContext xmesa = XMESA_CONTEXT(ctx);
    int depth = GET_VISUAL_DEPTH(xmesa->xm_visual);
 
-   (void) kernel1;
-
 #ifdef DEBUG
    triFuncName = NULL;
 #endif
 
+   if ((ctx->Color._DrawDestMask[0] & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) ==0)
+      return (swrast_tri_func) NULL;
    if (ctx->RenderMode != GL_RENDER)  return (swrast_tri_func) NULL;
    if (ctx->Polygon.SmoothFlag)       return (swrast_tri_func) NULL;
-   if (ctx->Texture._ReallyEnabled)   return (swrast_tri_func) NULL;
+   if (ctx->Texture._EnabledUnits)    return (swrast_tri_func) NULL;
    if (swrast->_RasterMask & MULTI_DRAW_BIT) return (swrast_tri_func) NULL;
+   if (ctx->Polygon.CullFlag && 
+       ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
+                                        return (swrast_tri_func) NULL;
 
    if (xmesa->xm_buffer->buffer==XIMAGE) {
       if (   ctx->Light.ShadeModel==GL_SMOOTH
@@ -1540,7 +1330,7 @@ static swrast_tri_func get_triangle_func( GLcontext *ctx )
           && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS
           && ctx->Polygon.StippleFlag==GL_FALSE) {
          switch (xmesa->pixelformat) {
-            case PF_TRUECOLOR:
+            case PF_Truecolor:
               USE(smooth_TRUECOLOR_z_triangle);
             case PF_8A8B8G8R:
                USE(smooth_8A8B8G8R_z_triangle);
@@ -1548,21 +1338,21 @@ static swrast_tri_func get_triangle_func( GLcontext *ctx )
                USE(smooth_8R8G8B_z_triangle);
             case PF_8R8G8B24:
                USE(smooth_8R8G8B24_z_triangle);
-            case PF_TRUEDITHER:
+            case PF_Dither_True:
                USE(smooth_TRUEDITHER_z_triangle);
             case PF_5R6G5B:
                USE(smooth_5R6G5B_z_triangle);
-            case PF_DITHER_5R6G5B:
+            case PF_Dither_5R6G5B:
                USE(smooth_DITHER_5R6G5B_z_triangle);
             case PF_HPCR:
               USE(smooth_HPCR_z_triangle);
-            case PF_DITHER:
+            case PF_Dither:
                if (depth == 8)
                   USE(smooth_DITHER8_z_triangle);
                else
                   USE(smooth_DITHER_z_triangle);
                break;
-            case PF_LOOKUP:
+            case PF_Lookup:
                if (depth == 8)
                   USE(smooth_LOOKUP8_z_triangle);
                else
@@ -1578,7 +1368,7 @@ static swrast_tri_func get_triangle_func( GLcontext *ctx )
           && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS
           && ctx->Polygon.StippleFlag==GL_FALSE) {
          switch (xmesa->pixelformat) {
-            case PF_TRUECOLOR:
+            case PF_Truecolor:
               USE(flat_TRUECOLOR_z_triangle);
             case PF_8A8B8G8R:
                USE(flat_8A8B8G8R_z_triangle);
@@ -1586,21 +1376,21 @@ static swrast_tri_func get_triangle_func( GLcontext *ctx )
                USE(flat_8R8G8B_z_triangle);
             case PF_8R8G8B24:
                USE(flat_8R8G8B24_z_triangle);
-            case PF_TRUEDITHER:
+            case PF_Dither_True:
                USE(flat_TRUEDITHER_z_triangle);
             case PF_5R6G5B:
                USE(flat_5R6G5B_z_triangle);
-            case PF_DITHER_5R6G5B:
+            case PF_Dither_5R6G5B:
                USE(flat_DITHER_5R6G5B_z_triangle);
             case PF_HPCR:
               USE(flat_HPCR_z_triangle);
-            case PF_DITHER:
+            case PF_Dither:
                if (depth == 8)
                   USE(flat_DITHER8_z_triangle);
                else
                   USE(flat_DITHER_z_triangle);
                break;
-            case PF_LOOKUP:
+            case PF_Lookup:
                if (depth == 8)
                   USE(flat_LOOKUP8_z_triangle);
                else
@@ -1613,7 +1403,7 @@ static swrast_tri_func get_triangle_func( GLcontext *ctx )
           && ctx->Light.ShadeModel==GL_SMOOTH
           && ctx->Polygon.StippleFlag==GL_FALSE) {
          switch (xmesa->pixelformat) {
-            case PF_TRUECOLOR:
+            case PF_Truecolor:
               USE(smooth_TRUECOLOR_triangle);
             case PF_8A8B8G8R:
                USE(smooth_8A8B8G8R_triangle);
@@ -1621,21 +1411,21 @@ static swrast_tri_func get_triangle_func( GLcontext *ctx )
                USE(smooth_8R8G8B_triangle);
             case PF_8R8G8B24:
                USE(smooth_8R8G8B24_triangle);
-            case PF_TRUEDITHER:
+            case PF_Dither_True:
                USE(smooth_TRUEDITHER_triangle);
             case PF_5R6G5B:
                USE(smooth_5R6G5B_triangle);
-            case PF_DITHER_5R6G5B:
+            case PF_Dither_5R6G5B:
                USE(smooth_DITHER_5R6G5B_triangle);
             case PF_HPCR:
               USE(smooth_HPCR_triangle);
-            case PF_DITHER:
+            case PF_Dither:
                if (depth == 8)
                   USE(smooth_DITHER8_triangle);
                else
                   USE(smooth_DITHER_triangle);
                break;
-            case PF_LOOKUP:
+            case PF_Lookup:
                if (depth == 8)
                   USE(smooth_LOOKUP8_triangle);
                else
@@ -1649,9 +1439,9 @@ static swrast_tri_func get_triangle_func( GLcontext *ctx )
           && ctx->Light.ShadeModel==GL_FLAT
           && ctx->Polygon.StippleFlag==GL_FALSE) {
          switch (xmesa->pixelformat) {
-            case PF_TRUECOLOR:
+            case PF_Truecolor:
               USE(flat_TRUECOLOR_triangle);
-            case PF_TRUEDITHER:
+            case PF_Dither_True:
               USE(flat_TRUEDITHER_triangle);
             case PF_8A8B8G8R:
                USE(flat_8A8B8G8R_triangle);
@@ -1661,17 +1451,17 @@ static swrast_tri_func get_triangle_func( GLcontext *ctx )
                USE(flat_8R8G8B24_triangle);
             case PF_5R6G5B:
                USE(flat_5R6G5B_triangle);
-            case PF_DITHER_5R6G5B:
+            case PF_Dither_5R6G5B:
                USE(flat_DITHER_5R6G5B_triangle);
             case PF_HPCR:
               USE(flat_HPCR_triangle);
-            case PF_DITHER:
+            case PF_Dither:
                if (depth == 8)
                   USE(flat_DITHER8_triangle);
                else
                   USE(flat_DITHER_triangle);
                break;
-            case PF_LOOKUP:
+            case PF_Lookup:
                if (depth == 8)
                   USE(flat_LOOKUP8_triangle);
                else