Header file clean-up:
[mesa.git] / src / mesa / drivers / osmesa / osmesa.c
index 42de21641acc301be0f7be0522b7cbf244d1363e..5efb52391b6472c9739fcce2e54905a265b47921 100644 (file)
@@ -1,10 +1,10 @@
-/* $Id: osmesa.c,v 1.64 2001/08/28 22:46:22 brianp Exp $ */
+/* $Id: osmesa.c,v 1.93 2002/10/24 23:57:23 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
+ * Version:  4.1
  *
- * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2002  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"),
 
 #include "glheader.h"
 #include "GL/osmesa.h"
+#include "buffers.h"
 #include "context.h"
 #include "colormac.h"
 #include "depth.h"
 #include "extensions.h"
+#include "imports.h"
 #include "macros.h"
 #include "matrix.h"
-#include "mem.h"
 #include "mmath.h"
 #include "mtypes.h"
 #include "texformat.h"
@@ -55,7 +56,6 @@
 #include "swrast/s_depth.h"
 #include "swrast/s_lines.h"
 #include "swrast/s_triangle.h"
-#include "swrast/s_trispan.h"
 #include "tnl/tnl.h"
 #include "tnl/t_context.h"
 #include "tnl/t_pipeline.h"
@@ -112,7 +112,7 @@ static void osmesa_register_swrast_functions( GLcontext *ctx );
  *                     display lists.  NULL indicates no sharing.
  * Return:  an OSMesaContext or 0 if error
  */
-OSMesaContext GLAPIENTRY
+GLAPI OSMesaContext GLAPIENTRY
 OSMesaCreateContext( GLenum format, OSMesaContext sharelist )
 {
    return OSMesaCreateContextExt(format, DEFAULT_SOFTWARE_DEPTH_BITS,
@@ -126,7 +126,7 @@ OSMesaCreateContext( GLenum format, OSMesaContext sharelist )
  *
  * Create context and specify size of ancillary buffers.
  */
-OSMesaContext GLAPIENTRY
+GLAPI OSMesaContext GLAPIENTRY
 OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
                         GLint accumBits, OSMesaContext sharelist )
 {
@@ -135,12 +135,10 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
    GLint rind, gind, bind, aind;
    GLint indexBits = 0, redBits = 0, greenBits = 0, blueBits = 0, alphaBits =0;
    GLboolean rgbmode;
-   GLboolean swalpha;
    const GLuint i4 = 1;
    const GLubyte *i1 = (GLubyte *) &i4;
    const GLint little_endian = *i1;
 
-   swalpha = GL_FALSE;
    rind = gind = bind = aind = 0;
    if (format==OSMESA_COLOR_INDEX) {
       indexBits = 8;
@@ -177,15 +175,15 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
       greenBits = CHAN_BITS;
       blueBits = CHAN_BITS;
       alphaBits = CHAN_BITS;
-      rind = 2;
-      gind = 1;
       bind = 0;
+      gind = 1;
+      rind = 2;
       aind = 3;
       if (little_endian) {
-         ashift = 0;
-         rshift = 8;
-         gshift = 16;
-         bshift = 24;
+         bshift = 0;
+         gshift = 8;
+         rshift = 16;
+         ashift = 24;
       }
       else {
          bshift = 24;
@@ -201,15 +199,15 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
       greenBits = CHAN_BITS;
       blueBits = CHAN_BITS;
       alphaBits = CHAN_BITS;
+      aind = 0;
       rind = 1;
       gind = 2;
       bind = 3;
-      aind = 0;
       if (little_endian) {
-         bshift = 0;
-         gshift = 8;
-         rshift = 16;
-         ashift = 24;
+         ashift = 0;
+         rshift = 8;
+         gshift = 16;
+         bshift = 24;
       }
       else {
          ashift = 24;
@@ -233,7 +231,6 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
       gind = 1;
       bind = 2;
       rgbmode = GL_TRUE;
-      swalpha = GL_TRUE;
    }
    else if (format==OSMESA_BGR) {
       indexBits = 0;
@@ -249,7 +246,6 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
       gind = 1;
       bind = 0;
       rgbmode = GL_TRUE;
-      swalpha = GL_TRUE;
    }
    else if (format==OSMESA_RGB_565) {
       indexBits = 0;
@@ -265,7 +261,6 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
       gind = 0;
       bind = 0;
       rgbmode = GL_TRUE;
-      swalpha = GL_FALSE;
    }
    else {
       return NULL;
@@ -299,7 +294,8 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
                                     osmesa->gl_visual,
                                     sharelist ? &sharelist->gl_ctx
                                               : (GLcontext *) NULL,
-                                    (void *) osmesa, GL_TRUE )) {
+                                    (void *) osmesa,
+                                    GL_FALSE)) {
          _mesa_destroy_visual( osmesa->gl_visual );
          FREE(osmesa);
          return NULL;
@@ -307,12 +303,13 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
 
       _mesa_enable_sw_extensions(&(osmesa->gl_ctx));
       _mesa_enable_1_3_extensions(&(osmesa->gl_ctx));
+      /*_mesa_enable_1_4_extensions(&(osmesa->gl_ctx));*/
 
       osmesa->gl_buffer = _mesa_create_framebuffer( osmesa->gl_visual,
-                                          osmesa->gl_visual->depthBits > 0,
-                                          osmesa->gl_visual->stencilBits > 0,
-                                          osmesa->gl_visual->accumRedBits > 0,
-                                          swalpha );
+                           (GLboolean) ( osmesa->gl_visual->depthBits > 0 ),
+                           (GLboolean) ( osmesa->gl_visual->stencilBits > 0 ),
+                           (GLboolean) ( osmesa->gl_visual->accumRedBits > 0 ),
+                           GL_FALSE /* s/w alpha */ );
 
       if (!osmesa->gl_buffer) {
          _mesa_destroy_visual( osmesa->gl_visual );
@@ -362,7 +359,7 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
  *
  * Input:  ctx - the context to destroy
  */
-void GLAPIENTRY OSMesaDestroyContext( OSMesaContext ctx )
+GLAPI void GLAPIENTRY OSMesaDestroyContext( OSMesaContext ctx )
 {
    if (ctx) {
       _swsetup_DestroyContext( &ctx->gl_ctx );
@@ -432,24 +429,22 @@ static void compute_row_addresses( OSMesaContext ctx )
  * with the lower-left image pixel stored in the first array position
  * (ie. bottom-to-top).
  *
- * Since the only type initially supported is GL_UNSIGNED_BYTE, if the
- * context is in RGBA mode, each pixel will be stored as a 4-byte RGBA
- * value.  If the context is in color indexed mode, each pixel will be
- * stored as a 1-byte value.
- *
  * If the context's viewport hasn't been initialized yet, it will now be
  * initialized to (0,0,width,height).
  *
  * Input:  ctx - the rendering context
  *         buffer - the image buffer memory
- *         type - data type for pixel components, only GL_UNSIGNED_BYTE
- *                and GL_UNSIGNED_SHORT_5_6_5 supported now.
+ *         type - data type for pixel components
+ *            Normally, only GL_UNSIGNED_BYTE and GL_UNSIGNED_SHORT_5_6_5
+ *            are supported.  But if Mesa's been compiled with CHAN_BITS==16
+ *            then type must be GL_UNSIGNED_SHORT.  And if Mesa's been build
+ *            with CHAN_BITS==32 then type must be GL_FLOAT.
  *         width, height - size of image buffer in pixels, at least 1
  * Return:  GL_TRUE if success, GL_FALSE if error because of invalid ctx,
- *          invalid buffer address, type!=GL_UNSIGNED_BYTE, width<1, height<1,
+ *          invalid buffer address, invalid type, width<1, height<1,
  *          width>internal limit or height>internal limit.
  */
-GLboolean GLAPIENTRY
+GLAPI GLboolean GLAPIENTRY
 OSMesaMakeCurrent( OSMesaContext ctx, void *buffer, GLenum type,
                    GLsizei width, GLsizei height )
 {
@@ -481,19 +476,27 @@ OSMesaMakeCurrent( OSMesaContext ctx, void *buffer, GLenum type,
    compute_row_addresses( ctx );
 
    /* init viewport */
-   if (ctx->gl_ctx.Viewport.Width==0) {
+   if (ctx->gl_ctx.Viewport.Width == 0) {
       /* initialize viewport and scissor box to buffer size */
       _mesa_Viewport( 0, 0, width, height );
       ctx->gl_ctx.Scissor.Width = width;
       ctx->gl_ctx.Scissor.Height = height;
    }
+   else {
+      /* this will make ensure we recognize the new buffer size */
+      _mesa_ResizeBuffersMESA();
+   }
+
+   /* Added by Gerk Huisma: */
+   _tnl_MakeCurrent( &ctx->gl_ctx, ctx->gl_ctx.DrawBuffer,
+                     ctx->gl_ctx.ReadBuffer );
 
    return GL_TRUE;
 }
 
 
 
-OSMesaContext GLAPIENTRY OSMesaGetCurrentContext( void )
+GLAPI OSMesaContext GLAPIENTRY OSMesaGetCurrentContext( void )
 {
    GLcontext *ctx = _mesa_get_current_context();
    if (ctx)
@@ -504,7 +507,7 @@ OSMesaContext GLAPIENTRY OSMesaGetCurrentContext( void )
 
 
 
-void GLAPIENTRY OSMesaPixelStore( GLint pname, GLint value )
+GLAPI void GLAPIENTRY OSMesaPixelStore( GLint pname, GLint value )
 {
    OSMesaContext ctx = OSMesaGetCurrentContext();
 
@@ -530,7 +533,7 @@ void GLAPIENTRY OSMesaPixelStore( GLint pname, GLint value )
 }
 
 
-void GLAPIENTRY OSMesaGetIntegerv( GLint pname, GLint *value )
+GLAPI void GLAPIENTRY OSMesaGetIntegerv( GLint pname, GLint *value )
 {
    OSMesaContext ctx = OSMesaGetCurrentContext();
 
@@ -553,6 +556,12 @@ void GLAPIENTRY OSMesaGetIntegerv( GLint pname, GLint *value )
       case OSMESA_Y_UP:
          *value = ctx->yup;
          return;
+      case OSMESA_MAX_WIDTH:
+         *value = MAX_WIDTH;
+         return;
+      case OSMESA_MAX_HEIGHT:
+         *value = MAX_HEIGHT;
+         return;
       default:
          _mesa_error(&ctx->gl_ctx, GL_INVALID_ENUM, "OSMesaGetIntergerv(pname)");
          return;
@@ -567,7 +576,7 @@ void GLAPIENTRY OSMesaGetIntegerv( GLint pname, GLint *value )
  *          buffer - pointer to depth buffer values
  * Return:  GL_TRUE or GL_FALSE to indicate success or failure.
  */
-GLboolean GLAPIENTRY
+GLAPI GLboolean GLAPIENTRY
 OSMesaGetDepthBuffer( OSMesaContext c, GLint *width, GLint *height,
                       GLint *bytesPerValue, void **buffer )
 {
@@ -598,7 +607,7 @@ OSMesaGetDepthBuffer( OSMesaContext c, GLint *width, GLint *height,
  *          buffer - pointer to color buffer values
  * Return:  GL_TRUE or GL_FALSE to indicate success or failure.
  */
-GLboolean GLAPIENTRY
+GLAPI GLboolean GLAPIENTRY
 OSMesaGetColorBuffer( OSMesaContext c, GLint *width,
                       GLint *height, GLint *format, void **buffer )
 {
@@ -618,6 +627,39 @@ OSMesaGetColorBuffer( OSMesaContext c, GLint *width,
    }
 }
 
+
+
+struct name_address {
+   const char *Name;
+   GLvoid *Address;
+};
+
+static struct name_address functions[] = {
+   { "OSMesaCreateContext", (void *) OSMesaCreateContext },
+   { "OSMesaCreateContextExt", (void *) OSMesaCreateContextExt },
+   { "OSMesaDestroyContext", (void *) OSMesaDestroyContext },
+   { "OSMesaMakeCurrent", (void *) OSMesaMakeCurrent },
+   { "OSMesaGetCurrentContext", (void *) OSMesaGetCurrentContext },
+   { "OSMesaPixelsStore", (void *) OSMesaPixelStore },
+   { "OSMesaGetIntegerv", (void *) OSMesaGetIntegerv },
+   { "OSMesaGetDepthBuffer", (void *) OSMesaGetDepthBuffer },
+   { "OSMesaGetColorBuffer", (void *) OSMesaGetColorBuffer },
+   { "OSMesaGetProcAddress", (void *) OSMesaGetProcAddress },
+   { NULL, NULL }
+};
+
+GLAPI void * GLAPIENTRY
+OSMesaGetProcAddress( const char *funcName )
+{
+   int i;
+   for (i = 0; functions[i].Name; i++) {
+      if (strcmp(functions[i].Name, funcName) == 0)
+         return (void *) functions[i].Address;
+   }
+   return (void *) _glapi_get_proc_address(funcName);
+}
+
+
 /**********************************************************************/
 /*** Device Driver Functions                                        ***/
 /**********************************************************************/
@@ -627,6 +669,15 @@ OSMesaGetColorBuffer( OSMesaContext c, GLint *width,
  * Useful macros:
  */
 
+#if CHAN_TYPE == GL_FLOAT
+#define PACK_RGBA(DST, R, G, B, A)     \
+do {                                   \
+   (DST)[0] = MAX2( R, 0.0F );         \
+   (DST)[1] = MAX2( G, 0.0F );         \
+   (DST)[2] = MAX2( B, 0.0F );         \
+   (DST)[3] = CLAMP(A, 0.0F, CHAN_MAXF);\
+} while (0)
+#else
 #define PACK_RGBA(DST, R, G, B, A)     \
 do {                                   \
    (DST)[osmesa->rInd] = R;            \
@@ -634,6 +685,7 @@ do {                                        \
    (DST)[osmesa->bInd] = B;            \
    (DST)[osmesa->aInd] = A;            \
 } while (0)
+#endif
 
 #define PACK_RGB(DST, R, G, B)  \
 do {                           \
@@ -668,23 +720,11 @@ do {                                                                      \
 
 
 
-static GLboolean set_draw_buffer( GLcontext *ctx, GLenum mode )
-{
-   (void) ctx;
-   if (mode==GL_FRONT_LEFT) {
-      return GL_TRUE;
-   }
-   else {
-      return GL_FALSE;
-   }
-}
-
-
-static void set_read_buffer( GLcontext *ctx, GLframebuffer *buffer, GLenum mode )
+static void set_buffer( GLcontext *ctx, GLframebuffer *buffer, GLuint bufferBit )
 {
    /* separate read buffer not supported */
    ASSERT(buffer == ctx->DrawBuffer);
-   ASSERT(mode == GL_FRONT_LEFT);
+   ASSERT(bufferBit == FRONT_LEFT_BIT);
 }
 
 
@@ -726,9 +766,10 @@ static void clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
            }
         }
         else if (osmesa->format == OSMESA_RGB) {
-           const GLchan r = ctx->Color.ClearColor[0];
-           const GLchan g = ctx->Color.ClearColor[1];
-           const GLchan b = ctx->Color.ClearColor[2];
+            GLchan r, g, b;
+            CLAMPED_FLOAT_TO_CHAN(r, ctx->Color.ClearColor[0]);
+            CLAMPED_FLOAT_TO_CHAN(g, ctx->Color.ClearColor[1]);
+            CLAMPED_FLOAT_TO_CHAN(b, ctx->Color.ClearColor[2]);
            if (all) {
               /* Clear whole RGB buffer */
               GLuint n = osmesa->rowlength * osmesa->height;
@@ -752,9 +793,10 @@ static void clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
            }
         }
         else if (osmesa->format == OSMESA_BGR) {
-           const GLchan r = ctx->Color.ClearColor[0];
-           const GLchan g = ctx->Color.ClearColor[1];
-           const GLchan b = ctx->Color.ClearColor[2];
+            GLchan r, g, b;
+            CLAMPED_FLOAT_TO_CHAN(r, ctx->Color.ClearColor[0]);
+            CLAMPED_FLOAT_TO_CHAN(g, ctx->Color.ClearColor[1]);
+            CLAMPED_FLOAT_TO_CHAN(b, ctx->Color.ClearColor[2]);
            if (all) {
               /* Clear whole RGB buffer */
               const GLint n = osmesa->rowlength * osmesa->height;
@@ -778,14 +820,15 @@ static void clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
            }
         }
          else if (osmesa->format == OSMESA_RGB_565) {
-           const GLchan r = ctx->Color.ClearColor[0];
-           const GLchan g = ctx->Color.ClearColor[1];
-           const GLchan b = ctx->Color.ClearColor[2];
             GLushort clearPixel;
+            GLchan r, g, b;
+            CLAMPED_FLOAT_TO_CHAN(r, ctx->Color.ClearColor[0]);
+            CLAMPED_FLOAT_TO_CHAN(g, ctx->Color.ClearColor[1]);
+            CLAMPED_FLOAT_TO_CHAN(b, ctx->Color.ClearColor[2]);
             PACK_RGB_565(clearPixel, r, g, b);
             if (all) {
                /* Clear whole RGB buffer */
-              const GLint n = osmesa->rowlength * osmesa->height;
+              const GLuint n = osmesa->rowlength * osmesa->height;
                GLushort *ptr2 = (GLushort *) osmesa->buffer;
                GLuint  i;
                for (i = 0; i < n; i++) {
@@ -810,10 +853,10 @@ static void clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
            /* 4-byte pixel value */
            GLuint clearPixel;
            GLchan *clr = (GLchan *) &clearPixel;
-           clr[osmesa->rInd] = ctx->Color.ClearColor[0];
-           clr[osmesa->gInd] = ctx->Color.ClearColor[1];
-           clr[osmesa->bInd] = ctx->Color.ClearColor[2];
-           clr[osmesa->aInd] = ctx->Color.ClearColor[3];
+            CLAMPED_FLOAT_TO_CHAN(clr[osmesa->rInd], ctx->Color.ClearColor[0]);
+            CLAMPED_FLOAT_TO_CHAN(clr[osmesa->gInd], ctx->Color.ClearColor[1]);
+            CLAMPED_FLOAT_TO_CHAN(clr[osmesa->bInd], ctx->Color.ClearColor[2]);
+            CLAMPED_FLOAT_TO_CHAN(clr[osmesa->aInd], ctx->Color.ClearColor[3]);
            if (all) {
               /* Clear whole RGBA buffer */
               const GLuint n = osmesa->rowlength * osmesa->height;
@@ -839,10 +882,11 @@ static void clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
               }
            }
 #else
-           const GLchan r = ctx->Color.ClearColor[0];
-           const GLchan g = ctx->Color.ClearColor[1];
-           const GLchan b = ctx->Color.ClearColor[2];
-           const GLchan a = ctx->Color.ClearColor[3];
+            GLchan r, g, b, a;
+            CLAMPED_FLOAT_TO_CHAN(r, ctx->Color.ClearColor[0]);
+            CLAMPED_FLOAT_TO_CHAN(g, ctx->Color.ClearColor[1]);
+            CLAMPED_FLOAT_TO_CHAN(b, ctx->Color.ClearColor[2]);
+            CLAMPED_FLOAT_TO_CHAN(a, ctx->Color.ClearColor[3]);
            if (all) {
               /* Clear whole RGBA buffer */
               const GLuint n = osmesa->rowlength * osmesa->height;
@@ -877,11 +921,16 @@ static void clear( GLcontext *ctx, GLbitfield mask, GLboolean all,
 
 
 
-static void buffer_size( GLcontext *ctx, GLuint *width, GLuint *height )
+static void buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height )
 {
-   OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-   *width = osmesa->width;
-   *height = osmesa->height;
+   /* don't use GET_CURRENT_CONTEXT(ctx) here - it's a problem on Windows */
+   GLcontext *ctx = (GLcontext *) _glapi_get_context();
+   (void) buffer;
+   if (ctx) {
+      OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
+      *width = osmesa->width;
+      *height = osmesa->height;
+   }
 }
 
 
@@ -1547,7 +1596,7 @@ static void
 flat_rgba_line( GLcontext *ctx, const SWvertex *vert0, const SWvertex *vert1 )
 {
    const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-   const GLchan *color = vert0->color;
+   const GLchan *color = vert1->color;
 
 #define INTERP_XY 1
 #define CLIP_HACK 1
@@ -1572,7 +1621,7 @@ static void
 flat_rgba_z_line(GLcontext *ctx, const SWvertex *vert0, const SWvertex *vert1)
 {
    const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-   const GLchan *color = vert0->color;
+   const GLchan *color = vert1->color;
 
 #define INTERP_XY 1
 #define INTERP_Z 1
@@ -1611,9 +1660,9 @@ flat_blend_rgba_line( GLcontext *ctx,
    const GLint bshift = osmesa->bshift;
    const GLint avalue = vert0->color[3];
    const GLint msavalue = CHAN_MAX - avalue;
-   const GLint rvalue = vert0->color[0]*avalue;
-   const GLint gvalue = vert0->color[1]*avalue;
-   const GLint bvalue = vert0->color[2]*avalue;
+   const GLint rvalue = vert1->color[0]*avalue;
+   const GLint gvalue = vert1->color[1]*avalue;
+   const GLint bvalue = vert1->color[2]*avalue;
 
 #define INTERP_XY 1
 #define CLIP_HACK 1
@@ -1626,6 +1675,17 @@ flat_blend_rgba_line( GLcontext *ctx,
      *ptr4 = pixel;                                    \
    }
 
+#if 0  /* XXX use this in the future */
+#define PLOT(X,Y)                                                      \
+   {                                                                   \
+      GLchan *pixel = (GLchan *) PIXELADDR4(X, Y);                     \
+      pixel[rInd] = (pixel[rInd] * msavalue + rvalue) >> CHAN_BITS;    \
+      pixel[gInd] = (pixel[gInd] * msavalue + gvalue) >> CHAN_BITS;    \
+      pixel[bInd] = (pixel[bInd] * msavalue + bvalue) >> CHAN_BITS;    \
+      pixel[aInd] = (pixel[aInd] * msavalue + avalue) >> CHAN_BITS;    \
+   }
+#endif
+
 #ifdef WIN32
 #include "..\swrast\s_linetemp.h"
 #else
@@ -1636,6 +1696,7 @@ flat_blend_rgba_line( GLcontext *ctx,
 
 /*
  * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer.
+ * But don't write to Z buffer.
  * XXX update for GLchan
  */
 static void
@@ -1648,9 +1709,9 @@ flat_blend_rgba_z_line( GLcontext *ctx,
    const GLint bshift = osmesa->bshift;
    const GLint avalue = vert0->color[3];
    const GLint msavalue = 256 - avalue;
-   const GLint rvalue = vert0->color[0]*avalue;
-   const GLint gvalue = vert0->color[1]*avalue;
-   const GLint bvalue = vert0->color[2]*avalue;
+   const GLint rvalue = vert1->color[0]*avalue;
+   const GLint gvalue = vert1->color[1]*avalue;
+   const GLint bvalue = vert1->color[2]*avalue;
 
 #define INTERP_XY 1
 #define INTERP_Z 1
@@ -1666,6 +1727,17 @@ flat_blend_rgba_z_line( GLcontext *ctx,
           *ptr4 = pixel;                                               \
        }
 
+#if 0  /* XXX use this in the future */
+#define PLOT(X,Y)                                                      \
+   if (Z < *zPtr) {                                                    \
+      GLchan *pixel = (GLchan *) PIXELADDR4(X, Y);                     \
+      pixel[rInd] = (pixel[rInd] * msavalue + rvalue) >> CHAN_BITS;    \
+      pixel[gInd] = (pixel[gInd] * msavalue + gvalue) >> CHAN_BITS;    \
+      pixel[bInd] = (pixel[bInd] * msavalue + bvalue) >> CHAN_BITS;    \
+      pixel[aInd] = (pixel[aInd] * msavalue + avalue) >> CHAN_BITS;    \
+   }
+#endif
+
 #ifdef WIN32
 #include "..\swrast\s_linetemp.h"
 #else
@@ -1688,9 +1760,9 @@ flat_blend_rgba_z_line_write( GLcontext *ctx,
    const GLint bshift = osmesa->bshift;
    const GLint avalue = vert0->color[3];
    const GLint msavalue = 256 - avalue;
-   const GLint rvalue = vert0->color[0]*avalue;
-   const GLint gvalue = vert0->color[1]*avalue;
-   const GLint bvalue = vert0->color[2]*avalue;
+   const GLint rvalue = vert1->color[0]*avalue;
+   const GLint gvalue = vert1->color[1]*avalue;
+   const GLint bvalue = vert1->color[2]*avalue;
 
 #define INTERP_XY 1
 #define INTERP_Z 1
@@ -1707,6 +1779,18 @@ flat_blend_rgba_z_line_write( GLcontext *ctx,
           *zPtr = Z;                                                   \
        }
 
+#if 0  /* XXX use this in the future */
+#define PLOT(X,Y)                                                      \
+   if (Z < *zPtr) {                                                    \
+      GLchan *pixel = (GLchan *) PIXELADDR4(X, Y);                     \
+      pixel[rInd] = (pixel[rInd] * msavalue + rvalue) >> CHAN_BITS;    \
+      pixel[gInd] = (pixel[gInd] * msavalue + gvalue) >> CHAN_BITS;    \
+      pixel[bInd] = (pixel[bInd] * msavalue + bvalue) >> CHAN_BITS;    \
+      pixel[aInd] = (pixel[aInd] * msavalue + avalue) >> CHAN_BITS;    \
+      *zPtr = Z;                                                       \
+   }
+#endif
+
 #ifdef WIN32
 #include "..\swrast\s_linetemp.h"
 #else
@@ -1728,7 +1812,7 @@ osmesa_choose_line_function( GLcontext *ctx )
    if (CHAN_BITS != 8)                    return NULL;
    if (ctx->RenderMode != GL_RENDER)      return NULL;
    if (ctx->Line.SmoothFlag)              return NULL;
-   if (ctx->Texture._ReallyEnabled)       return NULL;
+   if (ctx->Texture._EnabledUnits)        return NULL;
    if (ctx->Light.ShadeModel != GL_FLAT)  return NULL;
    if (ctx->Line.Width != 1.0F)           return NULL;
    if (ctx->Line.StippleFlag)             return NULL;
@@ -1741,11 +1825,11 @@ osmesa_choose_line_function( GLcontext *ctx )
        && ctx->Depth.Func==GL_LESS
        && ctx->Depth.Mask==GL_TRUE
        && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS) {
-      return flat_rgba_z_line;
+      return (swrast_line_func) flat_rgba_z_line;
    }
 
    if (swrast->_RasterMask == 0) {
-      return flat_rgba_line;
+      return (swrast_line_func) flat_rgba_line;
    }
 
    if (swrast->_RasterMask==(DEPTH_BIT|BLEND_BIT)
@@ -1757,7 +1841,7 @@ osmesa_choose_line_function( GLcontext *ctx )
        && ctx->Color.BlendSrcA==GL_SRC_ALPHA
        && ctx->Color.BlendDstA==GL_ONE_MINUS_SRC_ALPHA
        && ctx->Color.BlendEquation==GL_FUNC_ADD_EXT) {
-      return flat_blend_rgba_z_line_write;
+      return (swrast_line_func) flat_blend_rgba_z_line_write;
    }
 
    if (swrast->_RasterMask==(DEPTH_BIT|BLEND_BIT)
@@ -1769,7 +1853,7 @@ osmesa_choose_line_function( GLcontext *ctx )
        && ctx->Color.BlendSrcA==GL_SRC_ALPHA
        && ctx->Color.BlendDstA==GL_ONE_MINUS_SRC_ALPHA
        && ctx->Color.BlendEquation==GL_FUNC_ADD_EXT) {
-      return flat_blend_rgba_z_line;
+      return (swrast_line_func) flat_blend_rgba_z_line;
    }
 
    if (swrast->_RasterMask==BLEND_BIT
@@ -1778,10 +1862,10 @@ osmesa_choose_line_function( GLcontext *ctx )
        && ctx->Color.BlendSrcA==GL_SRC_ALPHA
        && ctx->Color.BlendDstA==GL_ONE_MINUS_SRC_ALPHA
        && ctx->Color.BlendEquation==GL_FUNC_ADD_EXT) {
-      return flat_blend_rgba_line;
+      return (swrast_line_func) flat_blend_rgba_line;
    }
 
-   return NULL;
+   return (swrast_line_func) NULL;
 }
 
 
@@ -1799,7 +1883,6 @@ static void smooth_rgba_z_triangle( GLcontext *ctx,
                                     const SWvertex *v2 )
 {
    const OSMesaContext osmesa = OSMESA_CONTEXT(ctx);
-
 #define INTERP_Z 1
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define INTERP_RGB 1
@@ -1807,7 +1890,7 @@ static void smooth_rgba_z_triangle( GLcontext *ctx,
 #define RENDER_SPAN( span )                                    \
    GLuint i;                                                   \
    GLchan *img = PIXELADDR4(span.x, span.y);                   \
-   for (i = 0; i < span.count; i++, img += 4) {                        \
+   for (i = 0; i < span.end; i++, img += 4) {                  \
       const GLdepth z = FixedToDepth(span.z);                  \
       if (z < zRow[i]) {                                       \
          PACK_RGBA(img, FixedToChan(span.red),                 \
@@ -1845,13 +1928,13 @@ static void flat_rgba_z_triangle( GLcontext *ctx,
 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
 #define SETUP_CODE                                             \
    GLuint pixel;                                               \
-   PACK_RGBA((GLchan *) &pixel, v0->color[0], v0->color[1],    \
-                                v0->color[2], v0->color[3]);
+   PACK_RGBA((GLchan *) &pixel, v2->color[0], v2->color[1],    \
+                                v2->color[2], v2->color[3]);
 
 #define RENDER_SPAN( span )                            \
    GLuint i;                                           \
    GLuint *img = (GLuint *) PIXELADDR4(span.x, span.y);        \
-   for (i = 0; i < span.count; i++) {                  \
+   for (i = 0; i < span.end; i++) {                    \
       const GLdepth z = FixedToDepth(span.z);          \
       if (z < zRow[i]) {                               \
          img[i] = pixel;                               \
@@ -1882,20 +1965,23 @@ osmesa_choose_triangle_function( GLcontext *ctx )
    if (ctx->RenderMode != GL_RENDER)    return (swrast_tri_func) NULL;
    if (ctx->Polygon.SmoothFlag)         return (swrast_tri_func) NULL;
    if (ctx->Polygon.StippleFlag)        return (swrast_tri_func) NULL;
-   if (ctx->Texture._ReallyEnabled)     return (swrast_tri_func) NULL;
+   if (ctx->Texture._EnabledUnits)      return (swrast_tri_func) NULL;
    if (osmesa->format != OSMESA_RGBA &&
        osmesa->format != OSMESA_BGRA &&
        osmesa->format != OSMESA_ARGB)   return (swrast_tri_func) NULL;
+   if (ctx->Polygon.CullFlag && 
+       ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)
+                                        return (swrast_tri_func) NULL;
 
    if (swrast->_RasterMask == DEPTH_BIT &&
        ctx->Depth.Func == GL_LESS &&
        ctx->Depth.Mask == GL_TRUE &&
        ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS) {
       if (ctx->Light.ShadeModel == GL_SMOOTH) {
-         return smooth_rgba_z_triangle;
+         return (swrast_tri_func) smooth_rgba_z_triangle;
       }
       else {
-         return flat_rgba_z_triangle;
+         return (swrast_tri_func) flat_rgba_z_triangle;
       }
    }
    return (swrast_tri_func) NULL;
@@ -1961,7 +2047,13 @@ static const GLubyte *get_string( GLcontext *ctx, GLenum name )
    (void) ctx;
    switch (name) {
       case GL_RENDERER:
+#if CHAN_BITS == 32
+         return (const GLubyte *) "Mesa OffScreen32";
+#elif CHAN_BITS == 16
+         return (const GLubyte *) "Mesa OffScreen16";
+#else
          return (const GLubyte *) "Mesa OffScreen";
+#endif
       default:
          return NULL;
    }
@@ -1983,8 +2075,7 @@ static void osmesa_update_state( GLcontext *ctx, GLuint new_state )
 
    ctx->Driver.GetString = get_string;
    ctx->Driver.UpdateState = osmesa_update_state;
-   ctx->Driver.SetDrawBuffer = set_draw_buffer;
-   ctx->Driver.ResizeBuffersMESA = _swrast_alloc_buffers;
+   ctx->Driver.ResizeBuffers = _swrast_alloc_buffers;
    ctx->Driver.GetBufferSize = buffer_size;
 
    ctx->Driver.Accum = _swrast_Accum;
@@ -1993,6 +2084,7 @@ static void osmesa_update_state( GLcontext *ctx, GLuint new_state )
    ctx->Driver.CopyPixels = _swrast_CopyPixels;
    ctx->Driver.DrawPixels = _swrast_DrawPixels;
    ctx->Driver.ReadPixels = _swrast_ReadPixels;
+   ctx->Driver.DrawBuffer = _swrast_DrawBuffer;
 
    ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format;
    ctx->Driver.TexImage1D = _mesa_store_teximage1d;
@@ -2003,6 +2095,13 @@ static void osmesa_update_state( GLcontext *ctx, GLuint new_state )
    ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;
    ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;
 
+   ctx->Driver.CompressedTexImage1D = _mesa_store_compressed_teximage1d;
+   ctx->Driver.CompressedTexImage2D = _mesa_store_compressed_teximage2d;
+   ctx->Driver.CompressedTexImage3D = _mesa_store_compressed_teximage3d;
+   ctx->Driver.CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d;
+   ctx->Driver.CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d;
+   ctx->Driver.CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d;
+
    ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d;
    ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d;
    ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d;
@@ -2013,6 +2112,7 @@ static void osmesa_update_state( GLcontext *ctx, GLuint new_state )
    ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
    ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
 
+   swdd->SetBuffer = set_buffer;
 
    /* RGB(A) span/pixel functions */
    if (osmesa->format == OSMESA_RGB) {
@@ -2071,8 +2171,6 @@ static void osmesa_update_state( GLcontext *ctx, GLuint new_state )
    swdd->ReadCI32Span = read_index_span;
    swdd->ReadCI32Pixels = read_index_pixels;
 
-   swdd->SetReadBuffer = set_read_buffer;
-
    tnl->Driver.RunPipeline = _tnl_run_pipeline;
 
    _swrast_InvalidateState( ctx, new_state );