new depth buffer functions
authorBrian Paul <brian.paul@tungstengraphics.com>
Fri, 10 Dec 1999 19:13:42 +0000 (19:13 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Fri, 10 Dec 1999 19:13:42 +0000 (19:13 +0000)
src/mesa/drivers/glide/fxdd.c
src/mesa/drivers/glide/fxddspan.c
src/mesa/drivers/glide/fxdrv.h

index 0668195..af73a4d 100644 (file)
@@ -811,11 +811,10 @@ void fxSetupDDPointers(GLcontext *ctx)
 
   ctx->Driver.UpdateState=fxDDUpdateDDPointers;
 
-  ctx->Driver.AllocDepthBuffer=fxAllocDepthBuffer;
-  ctx->Driver.DepthTestSpan=fxDDDepthTestSpanGeneric;
-  ctx->Driver.DepthTestPixels=fxDDDepthTestPixelsGeneric;
-  ctx->Driver.ReadDepthSpanFloat=fxDDReadDepthSpanFloat;
-  ctx->Driver.ReadDepthSpanInt=fxDDReadDepthSpanInt;
+  ctx->Driver.WriteDepthSpan=fxDDWriteDepthSpan;
+  ctx->Driver.WriteDepthPixels=fxDDWriteDepthPixels;
+  ctx->Driver.ReadDepthSpan=fxDDReadDepthSpan;
+  ctx->Driver.ReadDepthPixels=fxDDReadDepthPixels;
          
   ctx->Driver.GetString=fxDDGetString;
 
index 3dfc82b..b792caa 100644 (file)
@@ -122,11 +122,6 @@ void LFB_WRITE_SPAN_MESA(GrBuffer_t dst_buffer,
 
 #if defined(FX_GLIDE3) && defined(XF86DRI)
 
-static FxBool writeRegionClipped(fxMesaContext fxMesa, GrBuffer_t dst_buffer,
-                         FxU32 dst_x, FxU32 dst_y, GrLfbSrcFmt_t src_format,
-                         FxU32 src_width, FxU32 src_height, FxI32 src_stride,
-                         void *src_data);
-
 FxBool writeRegionClipped(fxMesaContext fxMesa, GrBuffer_t dst_buffer,
                          FxU32 dst_x, FxU32 dst_y, GrLfbSrcFmt_t src_format,
                          FxU32 src_width, FxU32 src_height, FxI32 src_stride,
@@ -388,7 +383,7 @@ static void fxDDReadRGBAPixels(const GLcontext *ctx,
 {
   fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx;
   GLuint i;
-  GLint bottom=fxMesa->height+fxMesa->y_offset-1;
+  GLint bottom=fxMesa->y_delta-1;
 
   if (MESA_VERBOSE&VERBOSE_DRIVER) {
      fprintf(stderr,"fxmesa: fxDDReadRGBAPixels(...)\n");
@@ -411,30 +406,37 @@ static void fxDDReadRGBAPixels(const GLcontext *ctx,
 /*****                    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+fxMesa->y_offset-1;
-  GLushort data[MAX_WIDTH];
 
   if (MESA_VERBOSE&VERBOSE_DRIVER) {
-     fprintf(stderr,"fxmesa: fxDDReadDepthSpanFloat(...)\n");
+     fprintf(stderr,"fxmesa: fxDDReadDepthSpanInt(...)\n");
   }
 
-  x+=fxMesa->x_offset;
-  FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x,bottom-y,n,1,0,data);
+  x += fxMesa->x_offset;
 
-  /*
-    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]) {
+        writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x + i, bottom-y,
+                           GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &depth[i]);
+      }
+    }
+  }
+  else {
+    writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x, bottom-y,
+                       GR_LFB_SRC_FMT_ZA16, n, 1, 0, (void *) depth);
+  }
 }
 
-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+fxMesa->y_offset-1;
@@ -447,440 +449,53 @@ void fxDDReadDepthSpanInt(GLcontext *ctx,
   FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x,bottom-y,n,1,0,depth);
 }
 
-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;
-  GLuint i;
-  GLuint passed=0;
   GLint bottom=fxMesa->height+fxMesa->y_offset-1;
+  GLuint i;
 
   if (MESA_VERBOSE&VERBOSE_DRIVER) {
-     fprintf(stderr,"fxmesa: fxDDDepthTestSpanGeneric(...)\n");
+     fprintf(stderr,"fxmesa: fxDDReadDepthSpanInt(...)\n");
   }
 
-  x+=fxMesa->x_offset;
-  FX_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] + fxMesa->x_offset;
+      int ypos = bottom - y[i];
+      writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, xpos, ypos,
+                         GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &depth[i]);
     }
-    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)
-    writeRegionClipped(fxMesa, 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;
-  GLuint i;
   GLint bottom=fxMesa->height+fxMesa->y_offset-1;
+  GLuint i;
 
   if (MESA_VERBOSE&VERBOSE_DRIVER) {
-     fprintf(stderr,"fxmesa: fxDDDepthTestPixelsGeneric(...)\n");
+     fprintf(stderr,"fxmesa: fxDDReadDepthSpanInt(...)\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]) {
-          FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
-          if (z[i] < zval) {
-            /* pass */
-            writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,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]) {
-          FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,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]) {
-          FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
-          if (z[i] <= zval) {
-            /* pass */
-            writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,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]) {
-          FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,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]) {
-          FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
-          if (z[i] >= zval) {
-            /* pass */
-            writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,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]) {
-          FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,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]) {
-          FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
-          if (z[i] > zval) {
-            /* pass */
-            writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,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]) {
-          FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,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]) {
-          FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
-          if (z[i] != zval) {
-            /* pass */
-            writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,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]) {
-          FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,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]) {
-          FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,bottom-y[i],1,1,0,&zval);
-          if (z[i] == zval) {
-            /* pass */
-            writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,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]) {
-          FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,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]) {
-          writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER,x[i]+fxMesa->x_offset,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] + fxMesa->x_offset;
+    int ypos = bottom - y[i];
+    FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,xpos,ypos,1,1,0,&depth[i]);
+  }
 }
 
+
+
+
 /************************************************************************/
 
 
index 57d35ff..d4d3ca5 100644 (file)
@@ -636,22 +636,19 @@ extern GLboolean fxDDColorMask(GLcontext *ctx,
                               GLboolean r, GLboolean g, 
                               GLboolean b, GLboolean a );
 
-extern GLuint fxDDDepthTestSpanGeneric(GLcontext *ctx,
-                                       GLuint n, GLint x, GLint y, 
-                                      const GLdepth z[],
-                                       GLubyte mask[]);
+extern void fxDDWriteDepthSpan(GLcontext *ctx, GLuint n, GLint x, GLint y,
+                               const GLdepth depth[], const GLubyte mask[]);
 
-extern void fxDDDepthTestPixelsGeneric(GLcontext* ctx,
-                                       GLuint n, 
-                                      const GLint x[], const GLint y[],
-                                       const GLdepth z[], GLubyte mask[]);
+extern void fxDDReadDepthSpan(GLcontext *ctx, GLuint n, GLint x, GLint y,
+                              GLdepth depth[]);
 
-extern void fxDDReadDepthSpanFloat(GLcontext *ctx,
-                                  GLuint n, GLint x, GLint y, GLfloat depth[]);
-
-extern void fxDDReadDepthSpanInt(GLcontext *ctx,
-                                GLuint n, GLint x, GLint y, GLdepth depth[]);
+extern void fxDDWriteDepthPixels(GLcontext *ctx, GLuint n,
+                                 const GLint x[], const GLint y[],
+                                 const GLdepth depth[], const GLubyte mask[]);
 
+extern void fxDDReadDepthPixels(GLcontext *ctx, GLuint n,
+                                const GLint x[], const GLint y[],
+                                GLdepth depth[]);
 
 extern void fxDDFastPath( struct vertex_buffer *VB );