diff options
Diffstat (limited to 'src/mesa/drivers/x11/xm_line.c')
-rw-r--r-- | src/mesa/drivers/x11/xm_line.c | 233 |
1 files changed, 127 insertions, 106 deletions
diff --git a/src/mesa/drivers/x11/xm_line.c b/src/mesa/drivers/x11/xm_line.c index ac8713f416a..00e9df68f37 100644 --- a/src/mesa/drivers/x11/xm_line.c +++ b/src/mesa/drivers/x11/xm_line.c @@ -1,4 +1,4 @@ -/* $Id: xm_line.c,v 1.5 2000/10/31 18:09:46 keithw Exp $ */ +/* $Id: xm_line.c,v 1.6 2000/11/05 18:26:12 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -42,6 +42,9 @@ /* Internal swrast includes: */ #include "swrast/s_depth.h" +#include "swrast/s_points.h" +#include "swrast/s_lines.h" +#include "swrast/s_context.h" /**********************************************************************/ @@ -52,65 +55,52 @@ /* * Render an array of points into a pixmap, any pixel format. */ -static void draw_points_ANY_pixmap( GLcontext *ctx, GLuint first, GLuint last ) +static void draw_points_ANY_pixmap( GLcontext *ctx, SWvertex *vert ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; XMesaDisplay *dpy = xmesa->xm_visual->display; XMesaDrawable buffer = xmesa->xm_buffer->buffer; XMesaGC gc = xmesa->xm_buffer->gc2; - struct vertex_buffer *VB = ctx->VB; - register GLuint i; if (xmesa->xm_visual->gl_visual->RGBAflag) { - /* RGB mode */ - for (i=first;i<=last;i++) { - if (VB->ClipMask[i]==0) { - register int x, y; - const GLubyte *color = VB->ColorPtr->data[i]; - unsigned long pixel = xmesa_color_to_pixel( xmesa, - color[0], color[1], color[2], color[3], xmesa->pixelformat); - XMesaSetForeground( dpy, gc, pixel ); - x = (GLint) VB->Win.data[i][0]; - y = FLIP( xmesa->xm_buffer, (GLint) VB->Win.data[i][1] ); - XMesaDrawPoint( dpy, buffer, gc, x, y); - } - } + register int x, y; + const GLubyte *color = vert->color; + unsigned long pixel = xmesa_color_to_pixel( xmesa, + color[0], color[1], + color[2], color[3], + xmesa->pixelformat); + XMesaSetForeground( dpy, gc, pixel ); + x = (GLint) vert->win[0]; + y = FLIP( xmesa->xm_buffer, (GLint) vert->win[1] ); + XMesaDrawPoint( dpy, buffer, gc, x, y); } else { /* Color index mode */ - for (i=first;i<=last;i++) { - if (VB->ClipMask[i]==0) { - register int x, y; - XMesaSetForeground( dpy, gc, VB->IndexPtr->data[i] ); - x = (GLint) VB->Win.data[i][0]; - y = FLIP( xmesa->xm_buffer, (GLint) VB->Win.data[i][1] ); - XMesaDrawPoint( dpy, buffer, gc, x, y); - } - } + register int x, y; + XMesaSetForeground( dpy, gc, vert->index ); + x = (GLint) vert->win[0]; + y = FLIP( xmesa->xm_buffer, (GLint) vert->win[1] ); + XMesaDrawPoint( dpy, buffer, gc, x, y); } } -/* - * Analyze context state to see if we can provide a fast points drawing - * function, like those in points.c. Otherwise, return NULL. +/* Override the swrast point-selection function. Try to use one of + * our internal point functions, otherwise fall back to the standard + * swrast functions. */ -points_func xmesa_get_points_func( GLcontext *ctx ) +void xmesa_choose_point( GLcontext *ctx ) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; + SWcontext *swrast = SWRAST_CONTEXT(ctx); - if (ctx->Point.Size==1.0F && !ctx->Point.SmoothFlag && ctx->RasterMask==0 - && !ctx->Texture.ReallyEnabled) { - if (xmesa->xm_buffer->buffer==XIMAGE) { - return (points_func) NULL; /*draw_points_ximage;*/ - } - else { - return draw_points_ANY_pixmap; - } + if (ctx->Point.Size==1.0F && !ctx->Point.SmoothFlag + && swrast->_RasterMask==0 + && !ctx->Texture._ReallyEnabled) { + swrast->Point = draw_points_ANY_pixmap; } - else { - return (points_func) NULL; + else { + _swrast_choose_point( ctx ); } } @@ -126,28 +116,27 @@ points_func xmesa_get_points_func( GLcontext *ctx ) * Render a line into a pixmap, any pixel format. */ static void flat_pixmap_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - struct vertex_buffer *VB = ctx->VB; register int x0, y0, x1, y1; XMesaGC gc; unsigned long pixel; if (xmesa->xm_visual->gl_visual->RGBAflag) { - const GLubyte *color = VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; pixel = xmesa_color_to_pixel( xmesa, color[0], color[1], color[2], color[3], xmesa->pixelformat ); } else { - pixel = VB->IndexPtr->data[pv]; + pixel = vert0->index; } gc = xmesa->xm_buffer->gc2; XMesaSetForeground( xmesa->display, gc, pixel ); - x0 = (GLint) VB->Win.data[vert0][0]; - y0 = FLIP( xmesa->xm_buffer, (GLint) VB->Win.data[vert0][1] ); - x1 = (GLint) VB->Win.data[vert1][0]; - y1 = FLIP( xmesa->xm_buffer, (GLint) VB->Win.data[vert1][1] ); + x0 = (GLint) vert0->win[0]; + y0 = FLIP( xmesa->xm_buffer, (GLint) vert0->win[1] ); + x1 = (GLint) vert1->win[0]; + y1 = FLIP( xmesa->xm_buffer, (GLint) vert1->win[1] ); XMesaDrawLine( xmesa->display, xmesa->xm_buffer->buffer, gc, x0, y0, x1, y1 ); } @@ -158,10 +147,10 @@ static void flat_pixmap_line( GLcontext *ctx, * Draw a flat-shaded, PF_TRUECOLOR line into an XImage. */ static void flat_TRUECOLOR_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; XMesaImage *img = xmesa->xm_buffer->backimage; unsigned long pixel; PACK_TRUECOLOR( pixel, color[0], color[1], color[2] ); @@ -179,10 +168,10 @@ static void flat_TRUECOLOR_line( GLcontext *ctx, * Draw a flat-shaded, PF_8A8B8G8R line into an XImage. */ static void flat_8A8B8G8R_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] ); #define PIXEL_TYPE GLuint @@ -199,10 +188,10 @@ static void flat_8A8B8G8R_line( GLcontext *ctx, * Draw a flat-shaded, PF_8R8G8B line into an XImage. */ static void flat_8R8G8B_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] ); #define PIXEL_TYPE GLuint @@ -219,10 +208,10 @@ static void flat_8R8G8B_line( GLcontext *ctx, * Draw a flat-shaded, PF_8R8G8B24 line into an XImage. */ static void flat_8R8G8B24_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; #define PIXEL_TYPE bgr_t #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) @@ -242,10 +231,10 @@ static void flat_8R8G8B24_line( GLcontext *ctx, * Draw a flat-shaded, PF_5R6G5B line into an XImage. */ static void flat_5R6G5B_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] ); #define PIXEL_TYPE GLushort @@ -262,10 +251,10 @@ static void flat_5R6G5B_line( GLcontext *ctx, * Draw a flat-shaded, PF_DITHER_5R6G5B line into an XImage. */ static void flat_DITHER_5R6G5B_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; #define PIXEL_TYPE GLushort #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) @@ -282,10 +271,10 @@ static void flat_DITHER_5R6G5B_line( GLcontext *ctx, * Draw a flat-shaded, PF_DITHER 8-bit line into an XImage. */ static void flat_DITHER8_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; GLint r = color[0], g = color[1], b = color[2]; DITHER_SETUP; @@ -304,10 +293,10 @@ static void flat_DITHER8_line( GLcontext *ctx, * Draw a flat-shaded, PF_LOOKUP 8-bit line into an XImage. */ static void flat_LOOKUP8_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; GLubyte pixel; LOOKUP_SETUP; pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] ); @@ -326,10 +315,10 @@ static void flat_LOOKUP8_line( GLcontext *ctx, * Draw a flat-shaded, PF_HPCR line into an XImage. */ static void flat_HPCR_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; GLint r = color[0], g = color[1], b = color[2]; #define INTERP_XY 1 @@ -348,10 +337,10 @@ static void flat_HPCR_line( GLcontext *ctx, * Draw a flat-shaded, Z-less, PF_TRUECOLOR line into an XImage. */ static void flat_TRUECOLOR_z_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; XMesaImage *img = xmesa->xm_buffer->backimage; unsigned long pixel; PACK_TRUECOLOR( pixel, color[0], color[1], color[2] ); @@ -374,10 +363,10 @@ static void flat_TRUECOLOR_z_line( GLcontext *ctx, * Draw a flat-shaded, Z-less, PF_8A8B8G8R line into an XImage. */ static void flat_8A8B8G8R_z_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] ); #define INTERP_Z 1 @@ -400,10 +389,10 @@ static void flat_8A8B8G8R_z_line( GLcontext *ctx, * Draw a flat-shaded, Z-less, PF_8R8G8B line into an XImage. */ static void flat_8R8G8B_z_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] ); #define INTERP_Z 1 @@ -426,10 +415,10 @@ static void flat_8R8G8B_z_line( GLcontext *ctx, * Draw a flat-shaded, Z-less, PF_8R8G8B24 line into an XImage. */ static void flat_8R8G8B24_z_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; #define INTERP_Z 1 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE @@ -453,10 +442,10 @@ static void flat_8R8G8B24_z_line( GLcontext *ctx, * Draw a flat-shaded, Z-less, PF_5R6G5B line into an XImage. */ static void flat_5R6G5B_z_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] ); #define INTERP_Z 1 @@ -478,10 +467,10 @@ static void flat_5R6G5B_z_line( GLcontext *ctx, * Draw a flat-shaded, Z-less, PF_DITHER_5R6G5B line into an XImage. */ static void flat_DITHER_5R6G5B_z_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; #define INTERP_Z 1 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE @@ -502,10 +491,10 @@ static void flat_DITHER_5R6G5B_z_line( GLcontext *ctx, * Draw a flat-shaded, Z-less, PF_DITHER 8-bit line into an XImage. */ static void flat_DITHER8_z_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; GLint r = color[0], g = color[1], b = color[2]; DITHER_SETUP; @@ -529,10 +518,10 @@ static void flat_DITHER8_z_line( GLcontext *ctx, * Draw a flat-shaded, Z-less, PF_LOOKUP 8-bit line into an XImage. */ static void flat_LOOKUP8_z_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; GLubyte pixel; LOOKUP_SETUP; pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] ); @@ -557,10 +546,10 @@ static void flat_LOOKUP8_z_line( GLcontext *ctx, * Draw a flat-shaded, Z-less, PF_HPCR line into an XImage. */ static void flat_HPCR_z_line( GLcontext *ctx, - GLuint vert0, GLuint vert1, GLuint pv ) + SWvertex *vert0, SWvertex *vert1 ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = ctx->VB->ColorPtr->data[pv]; + const GLubyte *color = vert0->color; GLint r = color[0], g = color[1], b = color[2]; #define INTERP_XY 1 @@ -662,28 +651,24 @@ fprintf (stderr, "\n"); } #endif - - -/* - * Analyze context state to see if we can provide a fast line drawing - * function, like those in lines.c. Otherwise, return NULL. - */ -line_func xmesa_get_line_func( GLcontext *ctx ) + +static swrast_line_func get_line_func( GLcontext *ctx ) { XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; + SWcontext *swrast = SWRAST_CONTEXT(ctx); int depth = GET_VISUAL_DEPTH(xmesa->xm_visual); (void) DitherValues; /* silence unused var warning */ (void) kernel1; /* silence unused var warning */ - if (ctx->Line.SmoothFlag) return (line_func)NULL; - if (ctx->Texture.ReallyEnabled) return (line_func)NULL; - if (ctx->Light.ShadeModel!=GL_FLAT) return (line_func)NULL; + if (ctx->Line.SmoothFlag) return (swrast_line_func)NULL; + if (ctx->Texture._ReallyEnabled) return (swrast_line_func)NULL; + if (ctx->Light.ShadeModel!=GL_FLAT) return (swrast_line_func)NULL; /* X line stippling doesn't match OpenGL stippling */ - if (ctx->Line.StippleFlag==GL_TRUE) return (line_func)NULL; + if (ctx->Line.StippleFlag==GL_TRUE) return (swrast_line_func)NULL; if (xmesa->xm_buffer->buffer==XIMAGE - && ctx->RasterMask==DEPTH_BIT + && swrast->_RasterMask==DEPTH_BIT && ctx->Depth.Func==GL_LESS && ctx->Depth.Mask==GL_TRUE && ctx->Visual.DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS @@ -702,17 +687,17 @@ line_func xmesa_get_line_func( GLcontext *ctx ) case PF_DITHER_5R6G5B: return flat_DITHER_5R6G5B_z_line; case PF_DITHER: - return (depth==8) ? flat_DITHER8_z_line : (line_func)NULL; + return (depth==8) ? flat_DITHER8_z_line : (swrast_line_func)NULL; case PF_LOOKUP: - return (depth==8) ? flat_LOOKUP8_z_line : (line_func)NULL; + return (depth==8) ? flat_LOOKUP8_z_line : (swrast_line_func)NULL; case PF_HPCR: return flat_HPCR_z_line; default: - return (line_func)NULL; + return (swrast_line_func)NULL; } } if (xmesa->xm_buffer->buffer==XIMAGE - && ctx->RasterMask==0 + && swrast->_RasterMask==0 && ctx->Line.Width==1.0F) { switch (xmesa->pixelformat) { case PF_TRUECOLOR: @@ -728,13 +713,13 @@ line_func xmesa_get_line_func( GLcontext *ctx ) case PF_DITHER_5R6G5B: return flat_DITHER_5R6G5B_line; case PF_DITHER: - return (depth==8) ? flat_DITHER8_line : (line_func)NULL; + return (depth==8) ? flat_DITHER8_line : (swrast_line_func)NULL; case PF_LOOKUP: - return (depth==8) ? flat_LOOKUP8_line : (line_func)NULL; + return (depth==8) ? flat_LOOKUP8_line : (swrast_line_func)NULL; case PF_HPCR: return flat_HPCR_line; default: - return (line_func)NULL; + return (swrast_line_func)NULL; } } #if 0 @@ -742,10 +727,46 @@ line_func xmesa_get_line_func( GLcontext *ctx ) * software Mesa's. This causes the linehv.c conformance test to fail. * In the future, we might provide a config option to enable this. */ - if (xmesa->xm_buffer->buffer!=XIMAGE && ctx->RasterMask==0) { + if (xmesa->xm_buffer->buffer!=XIMAGE && ctx->_RasterMask==0) { setup_x_line_options( ctx ); return flat_pixmap_line; } #endif - return (line_func)NULL; + return (swrast_line_func)NULL; +} + +/* Override for the swrast line-selection function. Try to use one + * of our internal line functions, otherwise fall back to the + * standard swrast functions. + */ +void xmesa_choose_line( GLcontext *ctx ) +{ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + + if (!(swrast->Line = get_line_func( ctx ))) + _swrast_choose_line( ctx ); +} + + +#define XMESA_NEW_POINT (_NEW_POINT|_SWRAST_NEW_RASTERMASK) +#define XMESA_NEW_LINE (_NEW_LINE|_NEW_TEXTURE|_NEW_LIGHT|\ + _NEW_DEPTH|_SWRAST_NEW_RASTERMASK) +#define XMESA_NEW_TRIANGLE (_NEW_POLYGON|_NEW_TEXTURE|_NEW_LIGHT|\ + _SWRAST_NEW_RASTERMASK|_NEW_DEPTH) + + +/* Extend the software rasterizer with our line/point/triangle + * functions. + */ +void xmesa_register_swrast_functions( GLcontext *ctx ) +{ + SWcontext *swrast = SWRAST_CONTEXT( ctx ); + + swrast->choose_point = xmesa_choose_point; + swrast->choose_line = xmesa_choose_line; + swrast->choose_triangle = xmesa_choose_triangle; + + swrast->invalidate_point |= XMESA_NEW_POINT; + swrast->invalidate_line |= XMESA_NEW_LINE; + swrast->invalidate_triangle |= XMESA_NEW_TRIANGLE; } |