From 328a039413fd2b8649511f1ca130df2a59f2c71c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 24 Sep 2004 14:30:13 +0000 Subject: [PATCH] patches for clearing hw depth buffers from software fallback (Nicolai Haehnle) --- src/mesa/drivers/dri/common/depthtmp.h | 36 ++++++++++++++++++++ src/mesa/drivers/dri/common/spantmp.h | 62 +++++++++++++++++++++++++++++----- src/mesa/swrast/s_depth.c | 22 +++++++++++- src/mesa/swrast/swrast.h | 7 ++++ 4 files changed, 117 insertions(+), 10 deletions(-) diff --git a/src/mesa/drivers/dri/common/depthtmp.h b/src/mesa/drivers/dri/common/depthtmp.h index f3da61e..74ebd6d 100644 --- a/src/mesa/drivers/dri/common/depthtmp.h +++ b/src/mesa/drivers/dri/common/depthtmp.h @@ -64,6 +64,42 @@ static void TAG(WriteDepthSpan)( GLcontext *ctx, HW_WRITE_UNLOCK(); } +static void TAG(WriteMonoDepthSpan)( GLcontext *ctx, + GLuint n, GLint x, GLint y, + const GLdepth depth, + const GLubyte mask[] ) +{ + HW_WRITE_LOCK() + { + GLint x1; + GLint n1; + LOCAL_DEPTH_VARS; + + y = Y_FLIP( y ); + + HW_CLIPLOOP() + { + GLint i = 0; + CLIPSPAN( x, y, n, x1, n1, i ); + + if ( DBG ) fprintf( stderr, "%s %d..%d (x1 %d) = %u\n", + __FUNCTION__, (int)i, (int)n1, (int)x1, (uint)depth ); + + if ( mask ) { + for ( ; i < n1 ; i++, x1++ ) { + if ( mask[i] ) WRITE_DEPTH( x1, y, depth ); + } + } else { + for ( ; i < n1 ; i++, x1++ ) { + WRITE_DEPTH( x1, y, depth ); + } + } + } + HW_ENDCLIPLOOP(); + } + HW_WRITE_UNLOCK(); +} + static void TAG(WriteDepthPixels)( GLcontext *ctx, GLuint n, const GLint x[], diff --git a/src/mesa/drivers/dri/common/spantmp.h b/src/mesa/drivers/dri/common/spantmp.h index 888be04..39d0221 100644 --- a/src/mesa/drivers/dri/common/spantmp.h +++ b/src/mesa/drivers/dri/common/spantmp.h @@ -123,15 +123,29 @@ static void TAG(WriteRGBAPixels)( const GLcontext *ctx, HW_WRITE_CLIPLOOP() { - for (i=0;i0;i++,x1++,n1--) - if (mask[i]) + if (mask) + { + for (;n1>0;i++,x1++,n1--) + if (mask[i]) + WRITE_PIXEL( x1, y, p ); + } + else + { + for (;n1>0;i++,x1++,n1--) WRITE_PIXEL( x1, y, p ); + } } HW_ENDCLIPLOOP(); } @@ -186,12 +208,23 @@ static void TAG(WriteMonoRGBAPixels)( const GLcontext *ctx, HW_WRITE_CLIPLOOP() { - for (i=0;iVisual.depthBits == 0 - || !ctx->DrawBuffer->DepthBuffer || !ctx->Depth.Mask) { /* no depth buffer, or writing to it is disabled */ return; } + if (swrast->Driver.WriteMonoDepthSpan) { + const GLdepth clearValue = (GLdepth)(ctx->Depth.Clear * ctx->DepthMax); + const GLint x = ctx->DrawBuffer->_Xmin; + const GLint y = ctx->DrawBuffer->_Ymin; + const GLint height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin; + const GLint width = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin; + GLint i; + + for (i = 0; i < height; i++) { + (*swrast->Driver.WriteMonoDepthSpan)( ctx, width, x, y + i, + clearValue, NULL ); + } + + return; + } + + if (!ctx->DrawBuffer->DepthBuffer) + return; + /* The loops in this function have been written so the IRIX 5.3 * C compiler can unroll them. Hopefully other compilers can too! */ diff --git a/src/mesa/swrast/swrast.h b/src/mesa/swrast/swrast.h index 9447e99..7fb0d2a 100644 --- a/src/mesa/swrast/swrast.h +++ b/src/mesa/swrast/swrast.h @@ -403,6 +403,13 @@ struct swrast_device_driver { * depth[i] value if mask[i] is nonzero. */ + void (*WriteMonoDepthSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, + const GLdepth depth, const GLubyte mask[] ); + /* Write a horizontal run of depth values. + * If mask is NULL, draw all pixels. + * If mask is not null, only draw pixel [i] when mask [i] is true. + */ + void (*ReadDepthSpan)( GLcontext *ctx, GLuint n, GLint x, GLint y, GLdepth depth[] ); /* Read a horizontal span of values from the depth buffer. -- 2.7.4