X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fdrivers%2Fx11%2Fxm_line.c;h=c31054251599db1a0c9c0f4fff32e7f71c85416f;hb=a510bc3ee1a696da120c09ee4ec33dc033f671ac;hp=2a09dd85c609e01e4699fbf921ef7c242efc36ff;hpb=8fa6b363dbed32f4e18b4b83866658c62fba8d39;p=mesa.git diff --git a/src/mesa/drivers/x11/xm_line.c b/src/mesa/drivers/x11/xm_line.c index 2a09dd85c60..c3105425159 100644 --- a/src/mesa/drivers/x11/xm_line.c +++ b/src/mesa/drivers/x11/xm_line.c @@ -1,21 +1,19 @@ -/* $Id: xm_line.c,v 1.7 2000/11/06 15:52:48 brianp Exp $ */ - /* * Mesa 3-D graphics library - * Version: 3.5 - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * + * Version: 6.5 + * + * Copyright (C) 1999-2006 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 @@ -35,8 +33,7 @@ #include "glxheader.h" #include "depth.h" #include "macros.h" -#include "vb.h" -#include "types.h" +#include "mtypes.h" #include "xmesaP.h" /* Internal swrast includes: @@ -55,23 +52,25 @@ /* * Render an array of points into a pixmap, any pixel format. */ -static void draw_points_ANY_pixmap( GLcontext *ctx, SWvertex *vert ) +#if 000 +/* XXX don't use this, it doesn't dither correctly */ +static void draw_points_ANY_pixmap( GLcontext *ctx, const SWvertex *vert ) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; + XMesaContext xmesa = XMESA_CONTEXT(ctx); XMesaDisplay *dpy = xmesa->xm_visual->display; XMesaDrawable buffer = xmesa->xm_buffer->buffer; - XMesaGC gc = xmesa->xm_buffer->gc2; + XMesaGC gc = xmesa->xm_buffer->gc; - if (xmesa->xm_visual->gl_visual->RGBAflag) { + if (xmesa->xm_visual->mesa_visual.RGBAflag) { 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], + 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] ); + x = (GLint) vert->win[0]; + y = YFLIP( xrb, (GLint) vert->win[1] ); XMesaDrawPoint( dpy, buffer, gc, x, y); } else { @@ -79,11 +78,11 @@ static void draw_points_ANY_pixmap( GLcontext *ctx, SWvertex *vert ) register int x, y; XMesaSetForeground( dpy, gc, vert->index ); x = (GLint) vert->win[0]; - y = FLIP( xmesa->xm_buffer, (GLint) vert->win[1] ); + y = YFLIP( xrb, (GLint) vert->win[1] ); XMesaDrawPoint( dpy, buffer, gc, x, y); } } - +#endif /* Override the swrast point-selection function. Try to use one of @@ -92,18 +91,23 @@ static void draw_points_ANY_pixmap( GLcontext *ctx, SWvertex *vert ) */ void xmesa_choose_point( GLcontext *ctx ) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; +#if 0 + XMesaContext xmesa = XMESA_CONTEXT(ctx); SWcontext *swrast = SWRAST_CONTEXT(ctx); - if (ctx->Point.Size == 1.0F && !ctx->Point.SmoothFlag + if (ctx->RenderMode == GL_RENDER + && ctx->Point.Size == 1.0F && !ctx->Point.SmoothFlag && swrast->_RasterMask == 0 - && !ctx->Texture._ReallyEnabled + && !ctx->Texture._EnabledUnits && xmesa->xm_buffer->buffer != XIMAGE) { swrast->Point = draw_points_ANY_pixmap; } - else { + else { _swrast_choose_point( ctx ); } +#else + _swrast_choose_point( ctx ); +#endif } @@ -113,320 +117,294 @@ void xmesa_choose_point( GLcontext *ctx ) /**********************************************************************/ -#if 0 -/* - * Render a line into a pixmap, any pixel format. - */ -static void flat_pixmap_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - register int x0, y0, x1, y1; - XMesaGC gc; - unsigned long pixel; - if (xmesa->xm_visual->gl_visual->RGBAflag) { - const GLubyte *color = vert0->color; - pixel = xmesa_color_to_pixel( xmesa, color[0], color[1], color[2], color[3], - xmesa->pixelformat ); - } - else { - pixel = vert0->index; - } - gc = xmesa->xm_buffer->gc2; - XMesaSetForeground( xmesa->display, gc, pixel ); - - 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 ); -} -#endif +#if CHAN_BITS == 8 + + +#define GET_XRB(XRB) struct xmesa_renderbuffer *XRB = \ + xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0][0]->Wrapped) /* * Draw a flat-shaded, PF_TRUECOLOR line into an XImage. */ -static void flat_TRUECOLOR_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; - XMesaImage *img = xmesa->xm_buffer->backimage; - unsigned long pixel; +#define NAME flat_TRUECOLOR_line +#define SETUP_CODE \ + XMesaContext xmesa = XMESA_CONTEXT(ctx); \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; \ + unsigned long pixel; \ PACK_TRUECOLOR( pixel, color[0], color[1], color[2] ); - -#define INTERP_XY 1 #define CLIP_HACK 1 -#define PLOT(X,Y) XMesaPutPixel( img, X, FLIP(xmesa->xm_buffer, Y), pixel ); - +#define PLOT(X,Y) XMesaPutPixel(xrb->ximage, X, YFLIP(xrb, Y), pixel ); #include "swrast/s_linetemp.h" -} /* * Draw a flat-shaded, PF_8A8B8G8R line into an XImage. */ -static void flat_8A8B8G8R_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; +#define NAME flat_8A8B8G8R_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; \ GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] ); - #define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) #define CLIP_HACK 1 #define PLOT(X,Y) *pixelPtr = pixel; +#include "swrast/s_linetemp.h" + + +/* + * Draw a flat-shaded, PF_8A8R8G8B line into an XImage. + */ +#define NAME flat_8A8R8G8B_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; \ + GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] ); +#define PIXEL_TYPE GLuint +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) +#define CLIP_HACK 1 +#define PLOT(X,Y) *pixelPtr = pixel; #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, PF_8R8G8B line into an XImage. */ -static void flat_8R8G8B_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; +#define NAME flat_8R8G8B_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; \ GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] ); - #define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) #define CLIP_HACK 1 #define PLOT(X,Y) *pixelPtr = pixel; - #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, PF_8R8G8B24 line into an XImage. */ -static void flat_8R8G8B24_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; - +#define NAME flat_8R8G8B24_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; #define PIXEL_TYPE bgr_t -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR3(xrb, X, Y) #define CLIP_HACK 1 #define PLOT(X,Y) { \ pixelPtr->r = color[RCOMP]; \ pixelPtr->g = color[GCOMP]; \ pixelPtr->b = color[BCOMP]; \ } - #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, PF_5R6G5B line into an XImage. */ -static void flat_5R6G5B_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; +#define NAME flat_5R6G5B_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; \ GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] ); - #define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y) #define CLIP_HACK 1 #define PLOT(X,Y) *pixelPtr = pixel; - #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, PF_DITHER_5R6G5B line into an XImage. */ -static void flat_DITHER_5R6G5B_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; - +#define NAME flat_DITHER_5R6G5B_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + XMesaContext xmesa = XMESA_CONTEXT(ctx); \ + const GLubyte *color = vert1->color; #define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y) #define CLIP_HACK 1 #define PLOT(X,Y) PACK_TRUEDITHER( *pixelPtr, X, Y, color[0], color[1], color[2] ); - #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, PF_DITHER 8-bit line into an XImage. */ -static void flat_DITHER8_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; - GLint r = color[0], g = color[1], b = color[2]; +#define NAME flat_DITHER8_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; \ + GLint r = color[0], g = color[1], b = color[2]; \ DITHER_SETUP; - -#define INTERP_XY 1 #define PIXEL_TYPE GLubyte -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR1(xrb, X, Y) #define CLIP_HACK 1 #define PLOT(X,Y) *pixelPtr = DITHER(X,Y,r,g,b); - #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, PF_LOOKUP 8-bit line into an XImage. */ -static void flat_LOOKUP8_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; - GLubyte pixel; - LOOKUP_SETUP; +#define NAME flat_LOOKUP8_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; \ + GLubyte pixel; \ + LOOKUP_SETUP; \ pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] ); - #define PIXEL_TYPE GLubyte -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR1(xrb, X,Y) #define CLIP_HACK 1 #define PLOT(X,Y) *pixelPtr = pixel; - #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, PF_HPCR line into an XImage. */ -static void flat_HPCR_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; +#define NAME flat_HPCR_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + XMesaContext xmesa = XMESA_CONTEXT(ctx); \ + const GLubyte *color = vert1->color; \ GLint r = color[0], g = color[1], b = color[2]; - -#define INTERP_XY 1 #define PIXEL_TYPE GLubyte -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR1(xrb, X,Y) #define CLIP_HACK 1 #define PLOT(X,Y) *pixelPtr = (GLubyte) DITHER_HPCR(X,Y,r,g,b); - #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, Z-less, PF_TRUECOLOR line into an XImage. */ -static void flat_TRUECOLOR_z_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; - XMesaImage *img = xmesa->xm_buffer->backimage; - unsigned long pixel; +#define NAME flat_TRUECOLOR_z_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + XMesaContext xmesa = XMESA_CONTEXT(ctx); \ + const GLubyte *color = vert1->color; \ + unsigned long pixel; \ PACK_TRUECOLOR( pixel, color[0], color[1], color[2] ); - -#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) { \ *zPtr = Z; \ - XMesaPutPixel( img, X, FLIP(xmesa->xm_buffer, Y), pixel ); \ + XMesaPutPixel(xrb->ximage, X, YFLIP(xrb, Y), pixel); \ } - #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, Z-less, PF_8A8B8G8R line into an XImage. */ -static void flat_8A8B8G8R_z_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; +#define NAME flat_8A8B8G8R_z_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; \ GLuint pixel = PACK_8B8G8R( color[0], color[1], color[2] ); - #define INTERP_Z 1 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X,Y) #define CLIP_HACK 1 #define PLOT(X,Y) \ if (Z < *zPtr) { \ *zPtr = Z; \ *pixelPtr = pixel; \ } +#include "swrast/s_linetemp.h" + + +/* + * Draw a flat-shaded, Z-less, PF_8A8R8G8B line into an XImage. + */ +#define NAME flat_8A8R8G8B_z_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; \ + GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] ); +#define INTERP_Z 1 +#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE +#define PIXEL_TYPE GLuint +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X,Y) +#define CLIP_HACK 1 +#define PLOT(X,Y) \ + if (Z < *zPtr) { \ + *zPtr = Z; \ + *pixelPtr = pixel; \ + } #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, Z-less, PF_8R8G8B line into an XImage. */ -static void flat_8R8G8B_z_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; +#define NAME flat_8R8G8B_z_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; \ GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] ); - #define INTERP_Z 1 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X,Y) #define CLIP_HACK 1 #define PLOT(X,Y) \ if (Z < *zPtr) { \ *zPtr = Z; \ *pixelPtr = pixel; \ } - #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, Z-less, PF_8R8G8B24 line into an XImage. */ -static void flat_8R8G8B24_z_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; - +#define NAME flat_8R8G8B24_z_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; #define INTERP_Z 1 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define PIXEL_TYPE bgr_t -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR3(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR3(xrb, X,Y) #define CLIP_HACK 1 #define PLOT(X,Y) \ if (Z < *zPtr) { \ @@ -435,26 +413,23 @@ static void flat_8R8G8B24_z_line( GLcontext *ctx, pixelPtr->g = color[GCOMP]; \ pixelPtr->b = color[BCOMP]; \ } - #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, Z-less, PF_5R6G5B line into an XImage. */ -static void flat_5R6G5B_z_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; +#define NAME flat_5R6G5B_z_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; \ GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] ); - #define INTERP_Z 1 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X,Y) #define CLIP_HACK 1 #define PLOT(X,Y) \ if (Z < *zPtr) { \ @@ -462,23 +437,22 @@ static void flat_5R6G5B_z_line( GLcontext *ctx, *pixelPtr = pixel; \ } #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, Z-less, PF_DITHER_5R6G5B line into an XImage. */ -static void flat_DITHER_5R6G5B_z_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; - +#define NAME flat_DITHER_5R6G5B_z_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + XMesaContext xmesa = XMESA_CONTEXT(ctx); \ + const GLubyte *color = vert1->color; #define INTERP_Z 1 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR2(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X,Y) #define CLIP_HACK 1 #define PLOT(X,Y) \ if (Z < *zPtr) { \ @@ -486,26 +460,23 @@ static void flat_DITHER_5R6G5B_z_line( GLcontext *ctx, PACK_TRUEDITHER(*pixelPtr, X, Y, color[0], color[1], color[2]); \ } #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, Z-less, PF_DITHER 8-bit line into an XImage. */ -static void flat_DITHER8_z_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; - GLint r = color[0], g = color[1], b = color[2]; +#define NAME flat_DITHER8_z_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; \ + GLint r = color[0], g = color[1], b = color[2]; \ DITHER_SETUP; - -#define INTERP_XY 1 #define INTERP_Z 1 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define PIXEL_TYPE GLubyte -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR1(xrb, X,Y) #define CLIP_HACK 1 #define PLOT(X,Y) \ if (Z < *zPtr) { \ @@ -513,262 +484,209 @@ static void flat_DITHER8_z_line( GLcontext *ctx, *pixelPtr = (GLubyte) DITHER( X, Y, r, g, b); \ } #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, Z-less, PF_LOOKUP 8-bit line into an XImage. */ -static void flat_LOOKUP8_z_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; - GLubyte pixel; - LOOKUP_SETUP; +#define NAME flat_LOOKUP8_z_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + const GLubyte *color = vert1->color; \ + GLubyte pixel; \ + LOOKUP_SETUP; \ pixel = (GLubyte) LOOKUP( color[0], color[1], color[2] ); - #define INTERP_Z 1 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define PIXEL_TYPE GLubyte -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR1(xrb, X,Y) #define CLIP_HACK 1 #define PLOT(X,Y) \ if (Z < *zPtr) { \ *zPtr = Z; \ *pixelPtr = pixel; \ } - #include "swrast/s_linetemp.h" -} + /* * Draw a flat-shaded, Z-less, PF_HPCR line into an XImage. */ -static void flat_HPCR_z_line( GLcontext *ctx, - SWvertex *vert0, SWvertex *vert1 ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - const GLubyte *color = vert0->color; +#define NAME flat_HPCR_z_line +#define SETUP_CODE \ + GET_XRB(xrb); \ + XMesaContext xmesa = XMESA_CONTEXT(ctx); \ + const GLubyte *color = vert1->color; \ GLint r = color[0], g = color[1], b = color[2]; - -#define INTERP_XY 1 #define INTERP_Z 1 #define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE #define PIXEL_TYPE GLubyte -#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXELADDR1(xmesa->xm_buffer,X,Y) +#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) +#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR1(xrb, X,Y) #define CLIP_HACK 1 #define PLOT(X,Y) \ if (Z < *zPtr) { \ *zPtr = Z; \ *pixelPtr = (GLubyte) DITHER_HPCR( X, Y, r, g, b); \ } - #include "swrast/s_linetemp.h" -} - - -#if 0 -/* - * Examine ctx->Line attributes and set xmesa->xm_buffer->gc1 - * and xmesa->xm_buffer->gc2 appropriately. - */ -static void setup_x_line_options( GLcontext *ctx ) -{ - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; - int i, state, state0, new_state, len, offs; - int tbit; - char *dptr; - int n_segments = 0; - char dashes[20]; - int line_width, line_style; - - /*** Line Stipple ***/ - if (ctx->Line.StippleFlag) { - const int pattern = ctx->Line.StipplePattern; - - dptr = dashes; - state0 = state = ((pattern & 1) != 0); - - /* Decompose the pattern */ - for (i=1,tbit=2,len=1;i<16;++i,tbit=(tbit<<1)) - { - new_state = ((tbit & pattern) != 0); - if (state != new_state) - { - *dptr++ = ctx->Line.StippleFactor * len; - len = 1; - state = new_state; - } - else - ++len; - } - *dptr = ctx->Line.StippleFactor * len; - n_segments = 1 + (dptr - dashes); - /* ensure an even no. of segments, or X may toggle on/off for consecutive patterns */ - /* if (n_segments & 1) dashes [n_segments++] = 0; value of 0 not allowed in dash list */ - /* Handle case where line style starts OFF */ - if (state0 == 0) - offs = dashes[0]; - else - offs = 0; -#if 0 -fprintf (stderr, "input pattern: 0x%04x, offset %d, %d segments:", pattern, offs, n_segments); -for (i = 0; i < n_segments; i++) -fprintf (stderr, " %d", dashes[i]); -fprintf (stderr, "\n"); -#endif - XMesaSetDashes( xmesa->display, xmesa->xm_buffer->gc1, - offs, dashes, n_segments ); - XMesaSetDashes( xmesa->display, xmesa->xm_buffer->gc2, - offs, dashes, n_segments ); +#ifndef XFree86Server +/** + * Draw fast, XOR line with XDrawLine in front color buffer. + * WARNING: this isn't fully OpenGL conformant because different pixels + * will be hit versus using the other line functions. + * Don't use the code in X server GLcore module since we need a wrapper + * for the XSetLineAttributes() function call. + */ +static void +xor_line(GLcontext *ctx, const SWvertex *vert0, const SWvertex *vert1) +{ + XMesaContext xmesa = XMESA_CONTEXT(ctx); + XMesaDisplay *dpy = xmesa->xm_visual->display; + XMesaGC gc = xmesa->xm_buffer->gc; + GET_XRB(xrb); + unsigned long pixel = xmesa_color_to_pixel(ctx, + vert1->color[0], vert1->color[1], + vert1->color[2], vert1->color[3], + xmesa->pixelformat); + int x0 = (int) vert0->win[0]; + int y0 = YFLIP(xrb, (GLint) vert0->win[1]); + int x1 = (int) vert1->win[0]; + int y1 = YFLIP(xrb, (GLint) vert1->win[1]); + XMesaSetForeground(dpy, gc, pixel); + XMesaSetFunction(dpy, gc, GXxor); + XSetLineAttributes(dpy, gc, (int) ctx->Line.Width, + LineSolid, CapButt, JoinMiter); + XDrawLine(dpy, xrb->pixmap, gc, x0, y0, x1, y1); + XMesaSetFunction(dpy, gc, GXcopy); /* this gc is used elsewhere */ +} +#endif /* XFree86Server */ - line_style = LineOnOffDash; - } - else { - line_style = LineSolid; - } - /*** Line Width ***/ - line_width = (int) (ctx->Line.Width+0.5F); - if (line_width < 2) { - /* Use fast lines when possible */ - line_width = 0; - } +#endif /* CHAN_BITS == 8 */ - /*** Set GC attributes ***/ - XMesaSetLineAttributes( xmesa->display, xmesa->xm_buffer->gc1, - line_width, line_style, CapButt, JoinBevel); - XMesaSetLineAttributes( xmesa->display, xmesa->xm_buffer->gc2, - line_width, line_style, CapButt, JoinBevel); - XMesaSetFillStyle( xmesa->display, xmesa->xm_buffer->gc1, FillSolid ); - XMesaSetFillStyle( xmesa->display, xmesa->xm_buffer->gc2, FillSolid ); -} -#endif - -static swrast_line_func get_line_func( GLcontext *ctx ) +/** + * Return pointer to line drawing function, or NULL if we should use a + * swrast fallback. + */ +static swrast_line_func +get_line_func(GLcontext *ctx) { - XMesaContext xmesa = (XMesaContext) ctx->DriverCtx; +#if CHAN_BITS == 8 + XMesaContext xmesa = XMESA_CONTEXT(ctx); SWcontext *swrast = SWRAST_CONTEXT(ctx); int depth = GET_VISUAL_DEPTH(xmesa->xm_visual); + struct xmesa_renderbuffer *xrb; + + if (CHAN_BITS != 8) + return NULL; - (void) DitherValues; /* silence unused var warning */ - (void) kernel1; /* silence unused var warning */ + if ((ctx->DrawBuffer->_ColorDrawBufferMask[0] + & (BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT)) == 0) + return (swrast_line_func) NULL; + if (ctx->RenderMode != GL_RENDER) return (swrast_line_func) NULL; + if (ctx->Line.SmoothFlag) return (swrast_line_func) NULL; + if (ctx->Texture._EnabledUnits) return (swrast_line_func) NULL; + if (ctx->Light.ShadeModel != GL_FLAT) return (swrast_line_func) NULL; + if (ctx->Line.StippleFlag) return (swrast_line_func) NULL; + if (swrast->_RasterMask & MULTI_DRAW_BIT) return (swrast_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 (swrast_line_func)NULL; + xrb = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0][0]->Wrapped); - if (xmesa->xm_buffer->buffer==XIMAGE + if (xrb->ximage && swrast->_RasterMask==DEPTH_BIT && ctx->Depth.Func==GL_LESS && ctx->Depth.Mask==GL_TRUE - && ctx->Visual.DepthBits == DEFAULT_SOFTWARE_DEPTH_BITS + && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS && ctx->Line.Width==1.0F) { switch (xmesa->pixelformat) { - case PF_TRUECOLOR: + case PF_Truecolor: return flat_TRUECOLOR_z_line; case PF_8A8B8G8R: return flat_8A8B8G8R_z_line; + case PF_8A8R8G8B: + return flat_8A8R8G8B_z_line; case PF_8R8G8B: return flat_8R8G8B_z_line; case PF_8R8G8B24: return flat_8R8G8B24_z_line; case PF_5R6G5B: return flat_5R6G5B_z_line; - case PF_DITHER_5R6G5B: + case PF_Dither_5R6G5B: return flat_DITHER_5R6G5B_z_line; - case PF_DITHER: - return (depth==8) ? flat_DITHER8_z_line : (swrast_line_func)NULL; - case PF_LOOKUP: - return (depth==8) ? flat_LOOKUP8_z_line : (swrast_line_func)NULL; + case PF_Dither: + return (depth==8) ? flat_DITHER8_z_line : (swrast_line_func) NULL; + case PF_Lookup: + return (depth==8) ? flat_LOOKUP8_z_line : (swrast_line_func) NULL; case PF_HPCR: return flat_HPCR_z_line; default: return (swrast_line_func)NULL; } } - if (xmesa->xm_buffer->buffer==XIMAGE + if (xrb->ximage && swrast->_RasterMask==0 && ctx->Line.Width==1.0F) { switch (xmesa->pixelformat) { - case PF_TRUECOLOR: + case PF_Truecolor: return flat_TRUECOLOR_line; case PF_8A8B8G8R: return flat_8A8B8G8R_line; + case PF_8A8R8G8B: + return flat_8A8R8G8B_line; case PF_8R8G8B: return flat_8R8G8B_line; case PF_8R8G8B24: return flat_8R8G8B24_line; case PF_5R6G5B: return flat_5R6G5B_line; - case PF_DITHER_5R6G5B: + case PF_Dither_5R6G5B: return flat_DITHER_5R6G5B_line; - case PF_DITHER: - return (depth==8) ? flat_DITHER8_line : (swrast_line_func)NULL; - case PF_LOOKUP: - return (depth==8) ? flat_LOOKUP8_line : (swrast_line_func)NULL; + case PF_Dither: + return (depth==8) ? flat_DITHER8_line : (swrast_line_func) NULL; + case PF_Lookup: + return (depth==8) ? flat_LOOKUP8_line : (swrast_line_func) NULL; case PF_HPCR: return flat_HPCR_line; default: return (swrast_line_func)NULL; } } -#if 0 - /* XXX have to disable this because X's rasterization rules don't match - * 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) { - setup_x_line_options( ctx ); - return flat_pixmap_line; + +#ifndef XFree86Server + if (ctx->DrawBuffer->_NumColorDrawBuffers[0] == 1 + && ctx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_FRONT_LEFT + && swrast->_RasterMask == LOGIC_OP_BIT + && ctx->Color.LogicOp == GL_XOR + && !ctx->Line.StippleFlag + && !ctx->Line.SmoothFlag) { + return xor_line; } -#endif - return (swrast_line_func)NULL; +#endif /* XFree86Server */ + +#endif /* CHAN_BITS == 8 */ + return (swrast_line_func) NULL; } -/* Override for the swrast line-selection function. Try to use one + +/** + * Override for the swrast line-selection function. Try to use one * of our internal line functions, otherwise fall back to the - * standard swrast functions. + * standard swrast functions. */ -void xmesa_choose_line( GLcontext *ctx ) +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; -}