From ed30dfa1264ec8875a3162c3c8778bc703bf11d5 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 3 Mar 2000 17:47:39 +0000 Subject: runtime selectable depth buffer depth --- src/mesa/drivers/glide/fxddspan.c | 65 +++++++++------ src/mesa/drivers/osmesa/osmesa.c | 167 ++++++++++++++++++++++++-------------- src/mesa/drivers/x11/fakeglx.c | 29 ++++++- 3 files changed, 169 insertions(+), 92 deletions(-) (limited to 'src/mesa/drivers') diff --git a/src/mesa/drivers/glide/fxddspan.c b/src/mesa/drivers/glide/fxddspan.c index ec55134802..89abdda951 100644 --- a/src/mesa/drivers/glide/fxddspan.c +++ b/src/mesa/drivers/glide/fxddspan.c @@ -396,7 +396,7 @@ static void fxDDReadRGBAPixels(const GLcontext *ctx, { fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; GLuint i; - GLint bottom=fxMesa->y_delta-1; + GLint bottom=fxMesa->height+fxMesa->y_offset-1; if (MESA_VERBOSE&VERBOSE_DRIVER) { fprintf(stderr,"fxmesa: fxDDReadRGBAPixels(...)\n"); @@ -423,11 +423,11 @@ void fxDDWriteDepthSpan(GLcontext *ctx, GLuint n, GLint x, GLint y, const GLdepth depth[], const GLubyte mask[]) { - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLint bottom=fxMesa->height+fxMesa->y_offset-1; + fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; + GLint bottom = fxMesa->height + fxMesa->y_offset - 1; - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDReadDepthSpanInt(...)\n"); + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDWriteDepthSpan(...)\n"); } x += fxMesa->x_offset; @@ -436,14 +436,20 @@ void fxDDWriteDepthSpan(GLcontext *ctx, 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]); + GLshort d = depth[i]; + writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x + i, bottom - y, + GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &d); } } } else { - writeRegionClipped(fxMesa, GR_BUFFER_AUXBUFFER, x, bottom-y, - GR_LFB_SRC_FMT_ZA16, n, 1, 0, (void *) depth); + 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); } } @@ -451,15 +457,20 @@ void fxDDWriteDepthSpan(GLcontext *ctx, 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; + fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; + GLint bottom = fxMesa->height + fxMesa->y_offset - 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"); } - x+=fxMesa->x_offset; - FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER,x,bottom-y,n,1,0,depth); + x += fxMesa->x_offset; + FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER, x, bottom - y, n, 1, 0, depth16); + for (i = 0; i < n; i++) { + depth[i] = depth16[i]; + } } @@ -468,20 +479,21 @@ void fxDDWriteDepthPixels(GLcontext *ctx, GLuint n, const GLint x[], const GLint y[], const GLdepth depth[], const GLubyte mask[]) { - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLint bottom=fxMesa->height+fxMesa->y_offset-1; + fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; + GLint bottom = fxMesa->height + fxMesa->y_offset - 1; GLuint i; - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDReadDepthSpanInt(...)\n"); + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDWriteDepthPixels(...)\n"); } for (i = 0; i < n; i++) { if (mask[i]) { int xpos = x[i] + fxMesa->x_offset; 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 *) &depth[i]); + GR_LFB_SRC_FMT_ZA16, 1, 1, 0, (void *) &d); } } } @@ -490,19 +502,20 @@ void fxDDWriteDepthPixels(GLcontext *ctx, void fxDDReadDepthPixels(GLcontext *ctx, GLuint n, const GLint x[], const GLint y[], GLdepth depth[]) { - fxMesaContext fxMesa=(fxMesaContext)ctx->DriverCtx; - GLint bottom=fxMesa->height+fxMesa->y_offset-1; + fxMesaContext fxMesa = (fxMesaContext)ctx->DriverCtx; + GLint bottom = fxMesa->height + fxMesa->y_offset - 1; GLuint i; - if (MESA_VERBOSE&VERBOSE_DRIVER) { - fprintf(stderr,"fxmesa: fxDDReadDepthSpanInt(...)\n"); + if (MESA_VERBOSE & VERBOSE_DRIVER) { + fprintf(stderr, "fxmesa: fxDDReadDepthPixels(...)\n"); } - 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]); + GLushort d; + FX_grLfbReadRegion(GR_BUFFER_AUXBUFFER, xpos, ypos, 1, 1, 0, &d); + depth[i] = d; } } diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c index a5a71bfc2d..ea015236f0 100644 --- a/src/mesa/drivers/osmesa/osmesa.c +++ b/src/mesa/drivers/osmesa/osmesa.c @@ -1,4 +1,4 @@ -/* $Id: osmesa.c,v 1.9 2000/01/15 06:13:26 rjfrank Exp $ */ +/* $Id: osmesa.c,v 1.10 2000/03/03 17:50:09 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -206,7 +206,7 @@ OSMesaCreateContext( GLenum format, OSMesaContext sharelist ) swalpha, /* software alpha */ GL_FALSE, /* double buffer */ GL_FALSE, /* stereo */ - DEPTH_BITS, + DEFAULT_SOFTWARE_DEPTH_BITS, STENCIL_BITS, rgbmode ? ACCUM_BITS : 0, indexBits, @@ -400,7 +400,6 @@ OSMesaMakeCurrent( OSMesaContext ctx, void *buffer, GLenum type, - OSMesaContext GLAPIENTRY OSMesaGetCurrentContext( void ) { GLcontext *ctx = gl_get_current_context(); @@ -1220,6 +1219,7 @@ static void flat_rgba_z_line( GLcontext *ctx, #define INTERP_XY 1 #define INTERP_Z 1 +#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define CLIP_HACK 1 #define PLOT(X,Y) \ if (Z < *zPtr) { \ @@ -1272,6 +1272,7 @@ static void flat_blend_rgba_line( GLcontext *ctx, #endif } + /* * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer. */ @@ -1292,16 +1293,16 @@ static void flat_blend_rgba_z_line( GLcontext *ctx, #define INTERP_XY 1 #define INTERP_Z 1 +#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define CLIP_HACK 1 -#define PLOT(X,Y) \ - if (Z < *zPtr) { \ - { GLuint *ptr4 = PIXELADDR4(X,Y); \ - GLuint pixel = 0; \ - pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift);\ - pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift);\ - pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift);\ - *ptr4 = pixel; \ - } \ +#define PLOT(X,Y) \ + if (Z < *zPtr) { \ + GLuint *ptr4 = PIXELADDR4(X,Y); \ + GLuint pixel = 0; \ + pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift); \ + pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift); \ + pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift); \ + *ptr4 = pixel; \ } #ifdef WIN32 @@ -1311,6 +1312,7 @@ static void flat_blend_rgba_z_line( GLcontext *ctx, #endif } + /* * Draw a flat-shaded, Z-less, alpha-blended, RGB line into an osmesa buffer. */ @@ -1331,17 +1333,17 @@ static void flat_blend_rgba_z_line_write( GLcontext *ctx, #define INTERP_XY 1 #define INTERP_Z 1 +#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define CLIP_HACK 1 -#define PLOT(X,Y) \ - if (Z < *zPtr) { \ - { GLuint *ptr4 = PIXELADDR4(X,Y); \ - GLuint pixel = 0; \ - pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift);\ - pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift);\ - pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift);\ - *ptr4 = pixel; \ - } \ - *zPtr = Z; \ +#define PLOT(X,Y) \ + if (Z < *zPtr) { \ + GLuint *ptr4 = PIXELADDR4(X,Y); \ + GLuint pixel = 0; \ + pixel |=((((((*ptr4) >> rshift) & 0xff)*msavalue+rvalue)>>8) << rshift); \ + pixel |=((((((*ptr4) >> gshift) & 0xff)*msavalue+gvalue)>>8) << gshift); \ + pixel |=((((((*ptr4) >> bshift) & 0xff)*msavalue+bvalue)>>8) << bshift); \ + *ptr4 = pixel; \ + *zPtr = Z; \ } #ifdef WIN32 @@ -1369,7 +1371,8 @@ static line_func choose_line_function( GLcontext *ctx ) if (ctx->RasterMask==DEPTH_BIT && ctx->Depth.Func==GL_LESS - && ctx->Depth.Mask==GL_TRUE) { + && ctx->Depth.Mask==GL_TRUE + && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS) { switch(osmesa->format) { case OSMESA_RGBA: case OSMESA_BGRA: @@ -1394,6 +1397,7 @@ static line_func choose_line_function( GLcontext *ctx ) if (ctx->RasterMask==(DEPTH_BIT|BLEND_BIT) && ctx->Depth.Func==GL_LESS && ctx->Depth.Mask==GL_TRUE + && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS && ctx->Color.BlendSrcRGB==GL_SRC_ALPHA && ctx->Color.BlendDstRGB==GL_ONE_MINUS_SRC_ALPHA && ctx->Color.BlendSrcA==GL_SRC_ALPHA @@ -1412,6 +1416,7 @@ static line_func choose_line_function( GLcontext *ctx ) if (ctx->RasterMask==(DEPTH_BIT|BLEND_BIT) && ctx->Depth.Func==GL_LESS && ctx->Depth.Mask==GL_FALSE + && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS && ctx->Color.BlendSrcRGB==GL_SRC_ALPHA && ctx->Color.BlendDstRGB==GL_ONE_MINUS_SRC_ALPHA && ctx->Color.BlendSrcA==GL_SRC_ALPHA @@ -1467,6 +1472,7 @@ static void smooth_rgba_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1, (void) pv; osmesa->bVisible = GL_TRUE; /* if here, the occlusion test is misused */ #define INTERP_Z 1 +#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define INTERP_RGB 1 #define INTERP_ALPHA 1 #define INNER_LOOP( LEFT, RIGHT, Y ) \ @@ -1502,6 +1508,7 @@ static void flat_rgba_z_triangle( GLcontext *ctx, GLuint v0, GLuint v1, { OSMesaContext osmesa = (OSMesaContext) ctx; #define INTERP_Z 1 +#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define SETUP_CODE \ GLubyte r = VB->ColorPtr->data[pv][0]; \ GLubyte g = VB->ColorPtr->data[pv][1]; \ @@ -1547,6 +1554,7 @@ static triangle_func choose_triangle_function( GLcontext *ctx ) if (ctx->RasterMask==DEPTH_BIT && ctx->Depth.Func==GL_LESS && ctx->Depth.Mask==GL_TRUE + && ctx->Visual->DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS && osmesa->format!=OSMESA_COLOR_INDEX) { if (ctx->Light.ShadeModel==GL_SMOOTH) { return smooth_rgba_z_triangle; @@ -1558,6 +1566,8 @@ static triangle_func choose_triangle_function( GLcontext *ctx ) return NULL; } + + /**********************************************************************/ /***** Occlusion rendering routines *****/ /**********************************************************************/ @@ -1576,87 +1586,113 @@ static triangle_func choose_triangle_function( GLcontext *ctx ) } \ return; -/***** Color Index *****/ +/** +*** Color Index +**/ + static void write_index32_span_occ( const GLcontext *ctx, - GLuint n, GLint x, GLint y, - const GLuint index[], const GLubyte mask[] ) + GLuint n, GLint x, GLint y, + const GLuint index[], const GLubyte mask[] ) { - OCC_STD_MASK_TEST + OCC_STD_MASK_TEST } + + static void write_index8_span_occ( const GLcontext *ctx, - GLuint n, GLint x, GLint y, - const GLubyte index[], const GLubyte mask[] ) + GLuint n, GLint x, GLint y, + const GLubyte index[], const GLubyte mask[] ) { - OCC_STD_MASK_TEST + OCC_STD_MASK_TEST } + + static void write_monoindex_span_occ( const GLcontext *ctx, - GLuint n, GLint x, GLint y, - const GLubyte mask[] ) + GLuint n, GLint x, GLint y, + const GLubyte mask[] ) { - OCC_STD_MASK_TEST + OCC_STD_MASK_TEST } + + static void write_index_pixels_occ( const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - const GLuint index[], const GLubyte mask[] ) + GLuint n, const GLint x[], const GLint y[], + const GLuint index[], const GLubyte mask[] ) { - OCC_STD_MASK_TEST + OCC_STD_MASK_TEST } + + static void write_monoindex_pixels_occ( const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - const GLubyte mask[] ) + GLuint n, const GLint x[], const GLint y[], + const GLubyte mask[] ) { - OCC_STD_MASK_TEST + OCC_STD_MASK_TEST } -/***** RGB/RGBA *****/ +/** +*** RGB/RGBA +**/ static void write_rgba_span_occ( const GLcontext *ctx, - GLuint n, GLint x, GLint y, - CONST GLubyte rgba[][4], const GLubyte mask[] ) + GLuint n, GLint x, GLint y, + CONST GLubyte rgba[][4], const GLubyte mask[] ) { - OCC_STD_MASK_TEST + OCC_STD_MASK_TEST } + + static void write_rgb_span_occ( const GLcontext *ctx, - GLuint n, GLint x, GLint y, - CONST GLubyte rgb[][3], - const GLubyte mask[] ) + GLuint n, GLint x, GLint y, + CONST GLubyte rgb[][3], + const GLubyte mask[] ) { - OCC_STD_MASK_TEST + OCC_STD_MASK_TEST } + + static void write_rgba_pixels_occ( const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - CONST GLubyte rgba[][4], const GLubyte mask[] ) + GLuint n, const GLint x[], const GLint y[], + CONST GLubyte rgba[][4], const GLubyte mask[] ) { - OCC_STD_MASK_TEST + OCC_STD_MASK_TEST } + + static void write_monocolor_span_occ( const GLcontext *ctx, - GLuint n, GLint x, GLint y, - const GLubyte mask[] ) + GLuint n, GLint x, GLint y, + const GLubyte mask[] ) { - OCC_STD_MASK_TEST + OCC_STD_MASK_TEST } + + static void write_monocolor_pixels_occ( const GLcontext *ctx, - GLuint n, const GLint x[], const GLint y[], - const GLubyte mask[] ) + GLuint n, const GLint x[], const GLint y[], + const GLubyte mask[] ) { - OCC_STD_MASK_TEST + OCC_STD_MASK_TEST } -/***** Line Drawing *****/ + +/** +*** Line Drawing +**/ static void line_occ( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pvert ) + GLuint vert0, GLuint vert1, GLuint pvert ) { OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; osmesa->bVisible = GL_TRUE; } + static void line_z_occ( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pvert ) + GLuint vert0, GLuint vert1, GLuint pvert ) { OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; if (osmesa->bVisible) return; #define INTERP_XY 1 #define INTERP_Z 1 +#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define CLIP_HACK 1 #define PLOT(X,Y) \ if (Z < *zPtr) { \ @@ -1671,19 +1707,25 @@ static void line_z_occ( GLcontext *ctx, #endif } -/***** Triangle Drawing *****/ + +/** +*** Triangle Drawing +**/ static void triangle_occ( GLcontext *ctx, GLuint v0, GLuint v1, - GLuint v2, GLuint pv ) + GLuint v2, GLuint pv ) { OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; osmesa->bVisible = GL_TRUE; } + + static void triangle_z_occ( GLcontext *ctx, GLuint v0, GLuint v1, - GLuint v2, GLuint pv ) + GLuint v2, GLuint pv ) { OSMesaContext osmesa = (OSMesaContext) ctx->DriverCtx; if (osmesa->bVisible) return; #define INTERP_Z 1 +#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define INNER_LOOP( LEFT, RIGHT, Y ) \ { \ GLint i, len = RIGHT-LEFT; \ @@ -1703,6 +1745,7 @@ static void triangle_z_occ( GLcontext *ctx, GLuint v0, GLuint v1, #endif } + static const GLubyte *get_string( GLcontext *ctx, GLenum name ) { (void) ctx; diff --git a/src/mesa/drivers/x11/fakeglx.c b/src/mesa/drivers/x11/fakeglx.c index 152e661e98..af8254fed9 100644 --- a/src/mesa/drivers/x11/fakeglx.c +++ b/src/mesa/drivers/x11/fakeglx.c @@ -1,4 +1,4 @@ -/* $Id: fakeglx.c,v 1.24 2000/02/27 18:26:54 brianp Exp $ */ +/* $Id: fakeglx.c,v 1.25 2000/03/03 17:50:09 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -300,6 +300,11 @@ save_glx_visual( Display *dpy, XVisualInfo *vinfo, /* * Create a GLX visual from a regular XVisualInfo. + * This is called when Fake GLX is given an XVisualInfo which wasn't + * returned by glXChooseVisual. Since this is the first time we're + * considering this visual we'll take a guess at reasonable values + * for depth buffer size, stencil size, accum size, etc. + * This is the best we can do with a client-side emulation of GLX. */ static XMesaVisual create_glx_visual( Display *dpy, XVisualInfo *visinfo ) @@ -329,9 +334,9 @@ create_glx_visual( Display *dpy, XVisualInfo *visinfo ) GL_FALSE, /* alpha */ GL_TRUE, /* double */ GL_FALSE, /* stereo */ - 8*sizeof(GLdepth), - 8*sizeof(GLstencil), - 8*sizeof(GLaccum), + DEFAULT_SOFTWARE_DEPTH_BITS, + 8 * sizeof(GLstencil), + 8 * sizeof(GLaccum), 0 /* level */ ); } @@ -1014,6 +1019,22 @@ Fake_glXChooseVisual( Display *dpy, int screen, int *list ) } if (vis) { + /* Note: we're not exactly obeying the glXChooseVisual rules here. + * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the + * largest depth buffer size, which is 32bits/value. However, we + * return 16 to maintain performance with earlier versions of Mesa. + */ + if (depth_size == 1) + depth_size = DEFAULT_SOFTWARE_DEPTH_BITS; + else if (depth_size > 24) + depth_size = 31; + else if (depth_size > 16) + depth_size = 24; + /* we only support one size of stencil and accum buffers. */ + if (stencil_size > 0) + stencil_size = STENCIL_BITS; + if (accum_size > 0) + accum_size = ACCUM_BITS; if (!save_glx_visual( dpy, vis, rgb_flag, alpha_flag, double_flag, stereo_flag, depth_size, stencil_size, accum_size, level )) -- cgit v1.2.3