Add render stage for unclipped vb's to fx driver.
[mesa.git] / src / mesa / drivers / glide / fxddspan.c
index 21b48ae789b7c7fe895a16b2848920dd56304df6..fceeb0e60a7be0ec4ba450bc013968fe055e1d40 100644 (file)
@@ -1,27 +1,50 @@
-/* -*- mode: C; tab-width:8;  -*-
-
-             fxdd.c - 3Dfx VooDoo Mesa span and pixel functions
-*/
 
 /*
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * Mesa 3-D graphics library
+ * Version:  3.3
+ *
+ * Copyright (C) 1999-2000  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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
+ * terms stated above.
  *
- * See the file fxapi.c for more informations about authors
+ * Thank you for your contribution, David!
  *
+ * Please make note of the above copyright/license statement.  If you
+ * contributed code or bug fixes to this code under the previous (GNU
+ * Library) license and object to the new license, your code will be
+ * removed at your request.  Please see the Mesa docs/COPYRIGHT file
+ * for more information.
+ *
+ * Additional Mesa/3Dfx driver developers:
+ *   Daryll Strauss <daryll@precisioninsight.com>
+ *   Keith Whitwell <keith@precisioninsight.com>
+ *
+ * See fxapi.h for more revision/author details.
  */
 
+
+/* fxdd.c - 3Dfx VooDoo Mesa span and pixel functions */
+
+
 #ifdef HAVE_CONFIG_H
 #include "conf.h"
 #endif
 
 #if !defined(FXMESA_USE_ARGB) 
 
+
+
+#define writeRegionClipped(fxm,dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data)             \
+  FX_grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data)
+
+
+
 /* KW: Rearranged the args in the call to grLfbWriteRegion().
  */
 #define LFB_WRITE_SPAN_MESA(dst_buffer,                \
@@ -50,7 +80,7 @@
                            src_width,          \
                            src_stride,         \
                            src_data)           \
-  grLfbWriteRegion(dst_buffer,                 \
+  writeRegionClipped(fxMesa, dst_buffer,       \
                   dst_x,                       \
                   dst_y,                       \
                   GR_LFB_SRC_FMT_8888,         \
                   src_data)                    \
 
 
-#else /* defined(FXMESA_USE_RGBA) */
+#else /* !defined(FXMESA_USE_RGBA) */
+
+#define writeRegionClipped(fxm,dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data)             \
+  FX_grLfbWriteRegion(dst_buffer,dst_x,dst_y,src_format,src_width,src_height,src_stride,src_data)
+
 
 #define MESACOLOR_TO_ARGB(c) (                         \
              ( ((unsigned int)(c[ACOMP]))<<24 ) |      \
              ( ((unsigned int)(c[GCOMP]))<<8 )  |      \
              (  (unsigned int)(c[BCOMP])) )
   
-void LFB_WRITE_SPAN_MESA(GrBuffer_t dst_buffer, 
+inline void LFB_WRITE_SPAN_MESA(GrBuffer_t dst_buffer, 
                         FxU32 dst_x, 
                         FxU32 dst_y, 
                         FxU32 src_width,
@@ -84,7 +118,7 @@ void LFB_WRITE_SPAN_MESA(GrBuffer_t dst_buffer,
    {
       argb[i] = MESACOLOR_TO_ARGB(rgba[i]);
    }
-   FX_grLfbWriteRegion(dst_buffer,
+   writeRegionClipped( /*fxMesa,*/ NULL, dst_buffer,
                       dst_x,
                       dst_y,
                       GR_LFB_SRC_FMT_8888,
@@ -93,8 +127,9 @@ void LFB_WRITE_SPAN_MESA(GrBuffer_t dst_buffer,
                       src_stride,
                       (void*)argb);
 }
+#endif /* !defined(FXMESA_USE_RGBA) */
 
-#endif
 
 /************************************************************************/
 /*****                    Span functions                            *****/
@@ -107,7 +142,7 @@ static void fxDDWriteRGBASpan(const GLcontext *ctx,
 {
   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
   GLuint i;
-  GLint bottom=fxMesa->height-1;
+  GLint bottom=fxMesa->height-1; 
 
   if (MESA_VERBOSE&VERBOSE_DRIVER) {
      fprintf(stderr,"fxmesa: fxDDWriteRGBASpan(...)\n");
@@ -188,12 +223,13 @@ static void fxDDWriteRGBSpan(const GLcontext *ctx,
 
 static void fxDDWriteMonoRGBASpan(const GLcontext *ctx, 
                                   GLuint n, GLint x, GLint y,
-                                  const GLubyte mask[])
+                                  const GLchan color[4], const GLubyte mask[])
 {
   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
   GLuint i;
   GLint bottom=fxMesa->height-1;
   GLuint data[MAX_WIDTH];
+  GrColor_t gColor = FXCOLOR4(color);
 
   if (MESA_VERBOSE&VERBOSE_DRIVER) {
      fprintf(stderr,"fxmesa: fxDDWriteMonoRGBASpan(...)\n");
@@ -204,11 +240,11 @@ static void fxDDWriteMonoRGBASpan(const GLcontext *ctx,
 
     for (i=0;i<n;i++) {
       if (mask[i]) {
-        data[span] = (GLuint) fxMesa->color;
+        data[span] = (GLuint) gColor;
         ++span;
       } else {
         if (span > 0) {
-          FX_grLfbWriteRegion( fxMesa->currentFB, x+i-span, bottom-y,
+          writeRegionClipped(fxMesa,  fxMesa->currentFB, x+i-span, bottom-y,
                             GR_LFB_SRC_FMT_8888, span, 1, 0,
                             (void *) data );
           span = 0;
@@ -217,20 +253,21 @@ static void fxDDWriteMonoRGBASpan(const GLcontext *ctx,
     }
 
     if (span > 0)
-      FX_grLfbWriteRegion( fxMesa->currentFB, x+n-span, bottom-y,
+      writeRegionClipped(fxMesa,  fxMesa->currentFB, x+n-span, bottom-y,
                         GR_LFB_SRC_FMT_8888, span, 1, 0,
                         (void *) data );
   } else {
     for (i=0;i<n;i++) {
-      data[i]=(GLuint) fxMesa->color;
+      data[i]=(GLuint) gColor;
     }
 
-    FX_grLfbWriteRegion( fxMesa->currentFB, x, bottom-y, GR_LFB_SRC_FMT_8888,
+    writeRegionClipped(fxMesa,  fxMesa->currentFB, x, bottom-y, GR_LFB_SRC_FMT_8888,
                       n, 1, 0, (void *) data );
   }
 }
 
 
+#if 0
 static void fxDDReadRGBASpan(const GLcontext *ctx, 
                              GLuint n, GLint x, GLint y, GLubyte rgba[][4])
 {
@@ -239,28 +276,79 @@ static void fxDDReadRGBASpan(const GLcontext *ctx,
   GLuint i;
   GLint bottom=fxMesa->height-1;
 
+  printf("read span %d, %d, %d\n", x,y,n);
   if (MESA_VERBOSE&VERBOSE_DRIVER) {
      fprintf(stderr,"fxmesa: fxDDReadRGBASpan(...)\n");
   }
 
   assert(n < MAX_WIDTH);
 
-  grLfbReadRegion( fxMesa->currentFB, x, bottom-y, n, 1, 0, data);
+  FX_grLfbReadRegion( fxMesa->currentFB, x, bottom-y, n, 1, 0, data);
+
   for (i=0;i<n;i++) {
-#if FXMESA_USE_ARGB
-    rgba[i][RCOMP]=(data[i] & 0xF800) >> 8;
-    rgba[i][GCOMP]=(data[i] & 0x07E0) >> 3;
-    rgba[i][BCOMP]=(data[i] & 0x001F) << 3;
-#else
-    rgba[i][RCOMP]=(data[i] & 0x001f) << 3;
-    rgba[i][GCOMP]=(data[i] & 0x07e0) >> 3;
-    rgba[i][BCOMP]=(data[i] & 0xf800) >> 8;
-#endif
-    rgba[i][ACOMP]=255;
+    GLushort pixel = data[i];
+    rgba[i][RCOMP] = FX_PixelToR[pixel];
+    rgba[i][GCOMP] = FX_PixelToG[pixel];
+    rgba[i][BCOMP] = FX_PixelToB[pixel];
+    rgba[i][ACOMP] = 255;
   }
+}
+#endif
 
+
+/*
+ * Read a span of 16-bit RGB pixels.  Note, we don't worry about cliprects
+ * since OpenGL says obscured pixels have undefined values.
+ */
+static void read_R5G6B5_span(const GLcontext *ctx, 
+                             GLuint n, GLint x, GLint y, GLubyte rgba[][4])
+{
+  fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
+  GrLfbInfo_t info;
+  BEGIN_BOARD_LOCK();
+  if (grLfbLock(GR_LFB_READ_ONLY,
+                fxMesa->currentFB,
+                GR_LFBWRITEMODE_ANY,
+                GR_ORIGIN_UPPER_LEFT,
+                FXFALSE,
+                &info)) {
+    const GLint winX = 0;
+    const GLint winY = fxMesa->height - 1;
+    const GLint srcStride = info.strideInBytes / 2; /* stride in GLushorts */
+    const GLushort *data16 = (const GLushort *) info.lfbPtr
+                           + (winY - y) * srcStride
+                           + (winX + x);
+    const GLuint *data32 = (const GLuint *) data16;
+    GLuint i, j;
+    GLuint extraPixel = (n & 1);
+    n -= extraPixel;
+    for (i = j = 0; i < n; i += 2, j++) {
+      GLuint pixel = data32[j];
+      GLuint pixel0 = pixel & 0xffff;
+      GLuint pixel1 = pixel >> 16;
+      rgba[i][RCOMP] = FX_PixelToR[pixel0];
+      rgba[i][GCOMP] = FX_PixelToG[pixel0];
+      rgba[i][BCOMP] = FX_PixelToB[pixel0];
+      rgba[i][ACOMP] = 255;
+      rgba[i+1][RCOMP] = FX_PixelToR[pixel1];
+      rgba[i+1][GCOMP] = FX_PixelToG[pixel1];
+      rgba[i+1][BCOMP] = FX_PixelToB[pixel1];
+      rgba[i+1][ACOMP] = 255;
+    }
+    if (extraPixel) {
+      GLushort pixel = data16[n];
+      rgba[n][RCOMP] = FX_PixelToR[pixel];
+      rgba[n][GCOMP] = FX_PixelToG[pixel];
+      rgba[n][BCOMP] = FX_PixelToB[pixel];
+      rgba[n][ACOMP] = 255;
+    }
+
+    grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
+  }
+  END_BOARD_LOCK();
 }
 
+
 /************************************************************************/
 /*****                    Pixel functions                           *****/
 /************************************************************************/
@@ -279,17 +367,18 @@ static void fxDDWriteRGBAPixels(const GLcontext *ctx,
 
   for(i=0;i<n;i++)
     if(mask[i])
-       LFB_WRITE_SPAN_MESA(fxMesa->currentFB,x[i],bottom-y[i],
-                       /*GR_LFB_SRC_FMT_8888,*/1,/*1,*/0,(void *)rgba[i]);
+       LFB_WRITE_SPAN_MESA(fxMesa->currentFB, x[i], bottom-y[i],
+                       1, 1, (void *)rgba[i]);
 }
 
 static void fxDDWriteMonoRGBAPixels(const GLcontext *ctx,
                                     GLuint n, const GLint x[], const GLint y[],
-                                    const GLubyte mask[])
+                                    const GLchan color[4], const GLubyte mask[])
 {
   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
   GLuint i;
   GLint bottom=fxMesa->height-1;
+  GrColor_t gColor = FXCOLOR4(color);
 
   if (MESA_VERBOSE&VERBOSE_DRIVER) {
      fprintf(stderr,"fxmesa: fxDDWriteMonoRGBAPixels(...)\n");
@@ -297,512 +386,152 @@ static void fxDDWriteMonoRGBAPixels(const GLcontext *ctx,
 
   for(i=0;i<n;i++)
     if(mask[i])
-      FX_grLfbWriteRegion(fxMesa->currentFB,x[i],bottom-y[i],
-                       GR_LFB_SRC_FMT_8888,1,1,0,(void *) &fxMesa->color);
+      writeRegionClipped(fxMesa, fxMesa->currentFB,x[i],bottom-y[i],
+                       GR_LFB_SRC_FMT_8888,1,1,0,(void *) &gColor);
 }
 
-static void fxDDReadRGBAPixels(const GLcontext *ctx,
+
+static void read_R5G6B5_pixels(const GLcontext *ctx,
                                GLuint n, const GLint x[], const GLint y[],
                                GLubyte rgba[][4], const GLubyte mask[])
 {
-  fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
-  GLuint i;
-  GLint bottom=fxMesa->height-1;
-  GLushort data;
-
-  if (MESA_VERBOSE&VERBOSE_DRIVER) {
-     fprintf(stderr,"fxmesa: fxDDReadRGBAPixels(...)\n");
+  fxMesaContext fxMesa = (fxMesaContext) ctx->DriverCtx;
+  GrLfbInfo_t info;
+  BEGIN_BOARD_LOCK();
+  if (grLfbLock(GR_LFB_READ_ONLY,
+                fxMesa->currentFB,
+                GR_LFBWRITEMODE_ANY,
+                GR_ORIGIN_UPPER_LEFT,
+                FXFALSE,
+                &info)) {
+    const GLint srcStride = info.strideInBytes / 2; /* stride in GLushorts */
+    const GLint winX = 0;
+    const GLint winY = fxMesa->height - 1;
+    GLuint i;
+    for(i=0;i<n;i++) {
+      if(mask[i]) {
+        const GLushort *data16 = (const GLushort *) info.lfbPtr
+                               + (winY - y[i]) * srcStride
+                               + (winX + x[i]);
+        const GLushort pixel = *data16;
+        rgba[i][RCOMP] = FX_PixelToR[pixel];
+        rgba[i][GCOMP] = FX_PixelToG[pixel];
+        rgba[i][BCOMP] = FX_PixelToB[pixel];
+        rgba[i][ACOMP] = 255;
+      }
+    }
+    grLfbUnlock(GR_LFB_READ_ONLY, fxMesa->currentFB);
   }
+  END_BOARD_LOCK();
+}
 
-  for(i=0;i<n;i++)
-    if(mask[i]) {
-      grLfbReadRegion(fxMesa->currentFB,x[i],bottom-y[i],1,1,0,&data);
-   #if FXMESA_USE_ARGB 
-      rgba[i][RCOMP]=(data & 0xF800) >> 8;
-      rgba[i][GCOMP]=(data & 0x07E0) >> 3;
-      rgba[i][BCOMP]=(data & 0x001F) >> 8;
-   #else
-      rgba[i][RCOMP]=(data & 0x001f) << 3;
-      rgba[i][GCOMP]=(data & 0x07e0) >> 3;
-      rgba[i][BCOMP]=(data & 0xf800) >> 8;
-   #endif
-      /* the alpha value should be read from the auxiliary buffer when required */
 
-      rgba[i][ACOMP]=255;
-    }
-}
 
 /************************************************************************/
 /*****                    Depth functions                           *****/
 /************************************************************************/
 
-void fxDDReadDepthSpanFloat(GLcontext *ctx,
-                           GLuint n, GLint x, GLint y, GLfloat depth[])
+void fxDDWriteDepthSpan(GLcontext *ctx,
+                        GLuint n, GLint x, GLint y, const GLdepth depth[],
+                        const GLubyte mask[])
 {
-  fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
-  GLuint i;
-  GLint bottom=fxMesa->height-1;
-  GLushort data[MAX_WIDTH];
+  fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx;
+  GLint bottom = fxMesa->height - 1;
 
-  if (MESA_VERBOSE&VERBOSE_DRIVER) {
-     fprintf(stderr,"fxmesa: fxDDReadDepthSpanFloat(...)\n");
+  if (MESA_VERBOSE & VERBOSE_DRIVER) {
+     fprintf(stderr, "fxmesa: fxDDWriteDepthSpan(...)\n");
   }
 
-  grLfbReadRegion(GR_BUFFER_AUXBUFFER,x,bottom-y,n,1,0,data);
 
-  /*
-    convert the read values to float values [0.0 .. 1.0].
-  */
-  for(i=0;i<n;i++)
-    depth[i]=data[i]/65535.0f;
+  if (mask) {
+    GLint i;
+    for (i = 0; i < n; i++) {
+      if (mask[i]) {
+        GLshort d = depth[i];
+        writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x + i, bottom - y,
+                           GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &d);
+      }
+    }
+  }
+  else {
+    GLushort depth16[MAX_WIDTH];
+    GLint i;
+    for (i = 0; i < n; i++) {
+      depth16[i] = depth[i];
+    }
+    writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x, bottom - y,
+                       GR_LFB_SRC_FMT_ZA16, n, 1, 0, (void *) depth16);
+  }
 }
 
-void fxDDReadDepthSpanInt(GLcontext *ctx,
-                         GLuint n, GLint x, GLint y, GLdepth depth[])
+
+void fxDDReadDepthSpan(GLcontext *ctx,
+                       GLuint n, GLint x, GLint y, GLdepth depth[])
 {
-  fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
-  GLint bottom=fxMesa->height-1;
+  fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx;
+  GLint bottom = fxMesa->height - 1;
+  GLushort depth16[MAX_WIDTH];
+  GLuint i;
 
-  if (MESA_VERBOSE&VERBOSE_DRIVER) {
-     fprintf(stderr,"fxmesa: fxDDReadDepthSpanInt(...)\n");
+  if (MESA_VERBOSE & VERBOSE_DRIVER) {
+     fprintf(stderr, "fxmesa: fxDDReadDepthSpan(...)\n");
   }
 
-  grLfbReadRegion(GR_BUFFER_AUXBUFFER,x,bottom-y,n,1,0,depth);
+  FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER, x, bottom - y, n, 1, 0, depth16);
+  for (i = 0; i < n; i++) {
+    depth[i] = depth16[i];
+  }
 }
 
-GLuint fxDDDepthTestSpanGeneric(GLcontext *ctx,
-                                       GLuint n, GLint x, GLint y, const GLdepth z[],
-                                       GLubyte mask[])
+
+
+void fxDDWriteDepthPixels(GLcontext *ctx,
+                          GLuint n, const GLint x[], const GLint y[],
+                          const GLdepth depth[], const GLubyte mask[])
 {
-  fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
-  GLushort depthdata[MAX_WIDTH];
-  GLdepth *zptr=depthdata;
-  GLubyte *m=mask;
+  fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx;
+  GLint bottom = fxMesa->height - 1;
   GLuint i;
-  GLuint passed=0;
-  GLint bottom=fxMesa->height-1;
 
-  if (MESA_VERBOSE&VERBOSE_DRIVER) {
-     fprintf(stderr,"fxmesa: fxDDDepthTestSpanGeneric(...)\n");
+  if (MESA_VERBOSE & VERBOSE_DRIVER) {
+    fprintf(stderr, "fxmesa: fxDDWriteDepthPixels(...)\n");
   }
 
-  grLfbReadRegion(GR_BUFFER_AUXBUFFER,x,bottom-y,n,1,0,depthdata);
-
-  /* switch cases ordered from most frequent to less frequent */
-  switch (ctx->Depth.Func) {
-  case GL_LESS:
-    if (ctx->Depth.Mask) {
-      /* Update Z buffer */
-      for (i=0; i<n; i++,zptr++,m++) {
-        if (*m) {
-          if (z[i] < *zptr) {
-            /* pass */
-            *zptr = z[i];
-            passed++;
-          } else {
-            /* fail */
-            *m = 0;
-          }
-        }
-      }
-    } else {
-      /* Don't update Z buffer */
-      for (i=0; i<n; i++,zptr++,m++) {
-        if (*m) {
-          if (z[i] < *zptr) {
-            /* pass */
-            passed++;
-          } else {
-            *m = 0;
-          }
-        }
-      }
+  for (i = 0; i < n; i++) {
+    if (mask[i]) {
+      int xpos = x[i];
+      int ypos = bottom - y[i];
+      GLushort d = depth[i];
+      writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, xpos, ypos,
+                         GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &d);
     }
-    break;
-  case GL_LEQUAL:
-    if (ctx->Depth.Mask) {
-      /* Update Z buffer */
-      for (i=0;i<n;i++,zptr++,m++) {
-        if (*m) {
-          if (z[i] <= *zptr) {
-            *zptr = z[i];
-            passed++;
-          } else {
-            *m = 0;
-          }
-        }
-      }
-    } else {
-      /* Don't update Z buffer */
-      for (i=0;i<n;i++,zptr++,m++) {
-        if (*m) {
-          if (z[i] <= *zptr) {
-            /* pass */
-            passed++;
-          } else {
-            *m = 0;
-          }
-        }
-      }
-    }
-    break;
-  case GL_GEQUAL:
-    if (ctx->Depth.Mask) {
-      /* Update Z buffer */
-      for (i=0;i<n;i++,zptr++,m++) {
-        if (*m) {
-          if (z[i] >= *zptr) {
-            *zptr = z[i];
-            passed++;
-          } else {
-            *m = 0;
-          }
-        }
-      }
-    } else {
-      /* Don't update Z buffer */
-      for (i=0;i<n;i++,zptr++,m++) {
-        if (*m) {
-          if (z[i] >= *zptr) {
-            /* pass */
-            passed++;
-          } else {
-            *m = 0;
-          }
-        }
-      }
-    }
-    break;
-  case GL_GREATER:
-    if (ctx->Depth.Mask) {
-      /* Update Z buffer */
-      for (i=0;i<n;i++,zptr++,m++) {
-        if (*m) {
-          if (z[i] > *zptr) {
-            *zptr = z[i];
-            passed++;
-          } else {
-            *m = 0;
-          }
-        }
-      }
-    } else {
-      /* Don't update Z buffer */
-      for (i=0;i<n;i++,zptr++,m++) {
-        if (*m) {
-          if (z[i] > *zptr) {
-            /* pass */
-            passed++;
-          } else {
-            *m = 0;
-          }
-        }
-      }
-    }
-    break;
-  case GL_NOTEQUAL:
-    if (ctx->Depth.Mask) {
-      /* Update Z buffer */
-      for (i=0;i<n;i++,zptr++,m++) {
-        if (*m) {
-          if (z[i] != *zptr) {
-            *zptr = z[i];
-            passed++;
-          } else {
-            *m = 0;
-          }
-        }
-      }
-    } else {
-      /* Don't update Z buffer */
-      for (i=0;i<n;i++,zptr++,m++) {
-        if (*m) {
-          if (z[i] != *zptr) {
-            /* pass */
-            passed++;
-          } else {
-            *m = 0;
-          }
-        }
-      }
-    }
-    break;
-  case GL_EQUAL:
-    if (ctx->Depth.Mask) {
-      /* Update Z buffer */
-      for (i=0;i<n;i++,zptr++,m++) {
-        if (*m) {
-          if (z[i] == *zptr) {
-            *zptr = z[i];
-            passed++;
-          } else {
-            *m =0;
-          }
-        }
-      }
-    } else {
-      /* Don't update Z buffer */
-      for (i=0;i<n;i++,zptr++,m++) {
-        if (*m) {
-          if (z[i] == *zptr) {
-            /* pass */
-            passed++;
-          } else {
-            *m =0;
-          }
-        }
-      }
-    }
-    break;
-  case GL_ALWAYS:
-    if (ctx->Depth.Mask) {
-      /* Update Z buffer */
-      for (i=0;i<n;i++,zptr++,m++) {
-        if (*m) {
-          *zptr = z[i];
-          passed++;
-        }
-      }
-    } else {
-      /* Don't update Z buffer or mask */
-      passed = n;
-    }
-    break;
-  case GL_NEVER:
-    for (i=0;i<n;i++) {
-      mask[i] = 0;
-    }
-    break;
-  default:
-    ;
-  } /*switch*/
-
-  if(passed)
-    FX_grLfbWriteRegion(GR_BUFFER_AUXBUFFER,x,bottom-y,GR_LFB_SRC_FMT_ZA16,n,1,0,depthdata);
-
-  return passed;
+  }
 }
 
-void fxDDDepthTestPixelsGeneric(GLcontext* ctx,
-                                       GLuint n, const GLint x[], const GLint y[],
-                                       const GLdepth z[], GLubyte mask[])
+
+void fxDDReadDepthPixels(GLcontext *ctx, GLuint n,
+                         const GLint x[], const GLint y[], GLdepth depth[])
 {
-  fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
-  GLdepth zval;
+  fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx;
+  GLint bottom = fxMesa->height - 1;
   GLuint i;
-  GLint bottom=fxMesa->height-1;
 
-  if (MESA_VERBOSE&VERBOSE_DRIVER) {
-     fprintf(stderr,"fxmesa: fxDDDepthTestPixelsGeneric(...)\n");
+  if (MESA_VERBOSE & VERBOSE_DRIVER) {
+    fprintf(stderr, "fxmesa: fxDDReadDepthPixels(...)\n");
   }
 
-  /* switch cases ordered from most frequent to less frequent */
-  switch (ctx->Depth.Func) {
-  case GL_LESS:
-    if (ctx->Depth.Mask) {
-      /* Update Z buffer */
-      for (i=0; i<n; i++) {
-        if (mask[i]) {
-          grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],1,1,0,&zval);
-          if (z[i] < zval) {
-            /* pass */
-            FX_grLfbWriteRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],GR_LFB_SRC_FMT_ZA16,1,1,0,(void*)&z[i]);
-          } else {
-            /* fail */
-            mask[i] = 0;
-          }
-        }
-      }
-    } else {
-      /* Don't update Z buffer */
-      for (i=0; i<n; i++) {
-        if (mask[i]) {
-          grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],1,1,0,&zval);
-          if (z[i] < zval) {
-            /* pass */
-          }
-          else {
-            /* fail */
-            mask[i] = 0;
-          }
-        }
-      }
-    }
-    break;
-  case GL_LEQUAL:
-    if (ctx->Depth.Mask) {
-      /* Update Z buffer */
-      for (i=0; i<n; i++) {
-        if (mask[i]) {
-          grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],1,1,0,&zval);
-          if (z[i] <= zval) {
-            /* pass */
-            FX_grLfbWriteRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],GR_LFB_SRC_FMT_ZA16,1,1,0,(void*)&z[i]);
-          } else {
-            /* fail */
-            mask[i] = 0;
-          }
-        }
-      }
-    } else {
-      /* Don't update Z buffer */
-      for (i=0; i<n; i++) {
-        if (mask[i]) {
-          grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],1,1,0,&zval);
-          if (z[i] <= zval) {
-            /* pass */
-          } else {
-            /* fail */
-            mask[i] = 0;
-          }
-        }
-      }
-    }
-    break;
-  case GL_GEQUAL:
-    if (ctx->Depth.Mask) {
-      /* Update Z buffer */
-      for (i=0; i<n; i++) {
-        if (mask[i]) {
-          grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],1,1,0,&zval);
-          if (z[i] >= zval) {
-            /* pass */
-            FX_grLfbWriteRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],GR_LFB_SRC_FMT_ZA16,1,1,0,(void*)&z[i]);
-          } else {
-            /* fail */
-            mask[i] = 0;
-          }
-        }
-      }
-    } else {
-      /* Don't update Z buffer */
-      for (i=0; i<n; i++) {
-        if (mask[i]) {
-          grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],1,1,0,&zval);
-          if (z[i] >= zval) {
-            /* pass */
-          } else {
-            /* fail */
-            mask[i] = 0;
-          }
-        }
-      }
-    }
-    break;
-  case GL_GREATER:
-    if (ctx->Depth.Mask) {
-      /* Update Z buffer */
-      for (i=0; i<n; i++) {
-        if (mask[i]) {
-          grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],1,1,0,&zval);
-          if (z[i] > zval) {
-            /* pass */
-            FX_grLfbWriteRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],GR_LFB_SRC_FMT_ZA16,1,1,0,(void*)&z[i]);
-          } else {
-            /* fail */
-            mask[i] = 0;
-          }
-        }
-      }
-    } else {
-      /* Don't update Z buffer */
-      for (i=0; i<n; i++) {
-        if (mask[i]) {
-          grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],1,1,0,&zval);
-          if (z[i] > zval) {
-            /* pass */
-          } else {
-            /* fail */
-            mask[i] = 0;
-          }
-        }
-      }
-    }
-    break;
-  case GL_NOTEQUAL:
-    if (ctx->Depth.Mask) {
-      /* Update Z buffer */
-      for (i=0; i<n; i++) {
-        if (mask[i]) {
-          grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],1,1,0,&zval);
-          if (z[i] != zval) {
-            /* pass */
-            FX_grLfbWriteRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],GR_LFB_SRC_FMT_ZA16,1,1,0,(void*)&z[i]);
-          } else {
-            /* fail */
-            mask[i] = 0;
-          }
-        }
-      }
-    } else {
-      /* Don't update Z buffer */
-      for (i=0; i<n; i++) {
-        if (mask[i]) {
-          grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],1,1,0,&zval);
-          if (z[i] != zval) {
-            /* pass */
-          }
-          else {
-            /* fail */
-            mask[i] = 0;
-          }
-        }
-      }
-    }
-    break;
-  case GL_EQUAL:
-    if (ctx->Depth.Mask) {
-      /* Update Z buffer */
-      for (i=0; i<n; i++) {
-        if (mask[i]) {
-          grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],1,1,0,&zval);
-          if (z[i] == zval) {
-            /* pass */
-            FX_grLfbWriteRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],GR_LFB_SRC_FMT_ZA16,1,1,0,(void*)&z[i]);
-          } else {
-            /* fail */
-            mask[i] = 0;
-          }
-        }
-      }
-    } else {
-      /* Don't update Z buffer */
-      for (i=0; i<n; i++) {
-        if (mask[i]) {
-          grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],1,1,0,&zval);
-          if (z[i] == zval) {
-            /* pass */
-          } else {
-            /* fail */
-            mask[i] = 0;
-          }
-        }
-      }
-    }
-    break;
-  case GL_ALWAYS:
-    if (ctx->Depth.Mask) {
-      /* Update Z buffer */
-      for (i=0; i<n; i++) {
-        if (mask[i]) {
-          FX_grLfbWriteRegion(GR_BUFFER_AUXBUFFER,x[i],bottom-y[i],GR_LFB_SRC_FMT_ZA16,1,1,0,(void*)&z[i]);
-        }
-      }
-    } else {
-      /* Don't update Z buffer or mask */
-    }
-    break;
-  case GL_NEVER:
-    /* depth test never passes */
-    for (i=0;i<n;i++) {
-      mask[i] = 0;
-    }
-    break;
-  default:
-    ;
-  } /*switch*/
+  for (i = 0; i < n; i++) {
+    int xpos = x[i];
+    int ypos = bottom - y[i];
+    GLushort d;
+    FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER, xpos, ypos, 1, 1, 0, &d);
+    depth[i] = d;
+  }
 }
 
+
+
+
 /************************************************************************/
 
 
@@ -820,8 +549,9 @@ void fxSetupDDSpanPointers(GLcontext *ctx)
   ctx->Driver.WriteCI32Pixels     =NULL;
   ctx->Driver.WriteMonoCIPixels   =NULL;
 
-  ctx->Driver.ReadRGBASpan        =fxDDReadRGBASpan;
-  ctx->Driver.ReadRGBAPixels      =fxDDReadRGBAPixels;
+  /*  ctx->Driver.ReadRGBASpan        =fxDDReadRGBASpan;*/
+  ctx->Driver.ReadRGBASpan = read_R5G6B5_span;
+  ctx->Driver.ReadRGBAPixels      = read_R5G6B5_pixels;
 
   ctx->Driver.ReadCI32Span        =NULL;
   ctx->Driver.ReadCI32Pixels      =NULL;
@@ -835,6 +565,7 @@ void fxSetupDDSpanPointers(GLcontext *ctx)
  * Need this to provide at least one external definition.
  */
 
+extern int gl_fx_dummy_function_span(void);
 int gl_fx_dummy_function_span(void)
 {
   return 0;