From 41bddcfa7bbc65bcd2fc60ada9761d3065e71388 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 12 Apr 2005 01:41:04 +0000 Subject: [PATCH] PF_8A8R8G8B pixel format (Dave Reveman) --- src/mesa/drivers/x11/xm_api.c | 9 +- src/mesa/drivers/x11/xm_line.c | 44 ++++++ src/mesa/drivers/x11/xm_span.c | 242 ++++++++++++++++++++++++++++++++- src/mesa/drivers/x11/xm_tri.c | 118 ++++++++++++++++ src/mesa/drivers/x11/xmesaP.h | 9 +- 5 files changed, 419 insertions(+), 3 deletions(-) diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index 873d196c940..665b0bc8296 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -1100,7 +1100,10 @@ static void setup_truecolor( XMesaVisual v, XMesaBuffer buffer, && sizeof(GLuint)==4 && v->RedGamma==1.0 && v->GreenGamma==1.0 && v->BlueGamma==1.0) { /* common 32 bpp config used on Linux, HP, IBM */ - v->undithered_pf = v->dithered_pf = PF_8R8G8B; + if (GET_VISUAL_DEPTH(v)==32) + v->undithered_pf = v->dithered_pf = PF_8A8R8G8B; + else + v->undithered_pf = v->dithered_pf = PF_8R8G8B; } else if (GET_REDMASK(v) ==0xff0000 && GET_GREENMASK(v)==0x00ff00 @@ -1349,6 +1352,8 @@ xmesa_color_to_pixel( XMesaContext xmesa, GLubyte r, GLubyte g, GLubyte b, GLuby } case PF_8A8B8G8R: return PACK_8A8B8G8R( r, g, b, a ); + case PF_8A8R8G8B: + return PACK_8A8R8G8B( r, g, b, a ); case PF_8R8G8B: /* fall through */ case PF_8R8G8B24: @@ -2616,6 +2621,8 @@ unsigned long XMesaDitherColor( XMesaContext xmesa, GLint x, GLint y, } case PF_8A8B8G8R: return PACK_8A8B8G8R( r, g, b, a ); + case PF_8A8R8G8B: + return PACK_8A8R8G8B( r, g, b, a ); case PF_8R8G8B: return PACK_8R8G8B( r, g, b ); case PF_5R6G5B: diff --git a/src/mesa/drivers/x11/xm_line.c b/src/mesa/drivers/x11/xm_line.c index ccb54a391cb..24e09ce344f 100644 --- a/src/mesa/drivers/x11/xm_line.c +++ b/src/mesa/drivers/x11/xm_line.c @@ -150,6 +150,23 @@ void xmesa_choose_point( GLcontext *ctx ) +/* + * Draw a flat-shaded, PF_8A8R8G8B line into an XImage. + */ +#define NAME flat_8A8R8G8B_line +#define SETUP_CODE \ + XMesaContext xmesa = XMESA_CONTEXT(ctx); \ + 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 CLIP_HACK 1 +#define PLOT(X,Y) *pixelPtr = pixel; +#include "swrast/s_linetemp.h" + + + /* * Draw a flat-shaded, PF_8R8G8B line into an XImage. */ @@ -321,6 +338,29 @@ void xmesa_choose_point( GLcontext *ctx ) +/* + * Draw a flat-shaded, Z-less, PF_8A8R8G8B line into an XImage. + */ +#define NAME flat_8A8R8G8B_z_line +#define SETUP_CODE \ + XMesaContext xmesa = XMESA_CONTEXT(ctx); \ + 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 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. */ @@ -511,6 +551,8 @@ static swrast_line_func get_line_func( GLcontext *ctx ) 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: @@ -537,6 +579,8 @@ static swrast_line_func get_line_func( GLcontext *ctx ) 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: diff --git a/src/mesa/drivers/x11/xm_span.c b/src/mesa/drivers/x11/xm_span.c index 594554469c9..397d596c0c0 100644 --- a/src/mesa/drivers/x11/xm_span.c +++ b/src/mesa/drivers/x11/xm_span.c @@ -374,6 +374,69 @@ static void write_span_rgb_8A8B8G8R_pixmap( RGB_SPAN_ARGS ) } } +/* + * Write a span of PF_8A8R8G8B pixels to a pixmap. + */ +static void write_span_8A8R8G8B_pixmap( RGBA_SPAN_ARGS ) +{ + const XMesaContext xmesa = XMESA_CONTEXT(ctx); + XMesaDisplay *dpy = xmesa->xm_visual->display; + XMesaDrawable buffer = xmesa->xm_buffer->buffer; + XMesaGC gc = xmesa->xm_buffer->gc; + register GLuint i; + y = FLIP(xmesa->xm_buffer, y); + if (mask) { + for (i=0;ixm_buffer->rowimage; + register GLuint *ptr4 = (GLuint *) rowimg->data; + for (i=0;ixm_visual->display; + XMesaDrawable buffer = xmesa->xm_buffer->buffer; + XMesaGC gc = xmesa->xm_buffer->gc; + register GLuint i; + y = FLIP(xmesa->xm_buffer, y); + if (mask) { + for (i=0;ixm_buffer->rowimage; + register GLuint *ptr4 = (GLuint *) rowimg->data; + for (i=0;ixm_buffer, x, y ); + if (mask) { + for (i=0;ixm_buffer, x, y ); + if (mask) { + for (i=0;ixm_visual->display; + XMesaDrawable buffer = xmesa->xm_buffer->buffer; + XMesaGC gc = xmesa->xm_buffer->gc; + register GLuint i; + for (i=0;ixm_buffer, y[i]) ); + } + } +} /* * Write an array of PF_8R8G8B pixels to a pixmap. @@ -2322,6 +2450,21 @@ static void write_pixels_8A8B8G8R_ximage( RGBA_PIXEL_ARGS ) } } +/* + * Write an array of PF_8A8R8G8B pixels to an ximage. + */ +static void write_pixels_8A8R8G8B_ximage( RGBA_PIXEL_ARGS ) +{ + const XMesaContext xmesa = XMESA_CONTEXT(ctx); + register GLuint i; + for (i=0;ixm_buffer, x[i], y[i] ); + *ptr = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] ); + } + } +} + /* * Write an array of PF_8R8G8B pixels to an ximage. @@ -2750,6 +2893,23 @@ static void write_span_mono_8A8B8G8R_ximage( MONO_SPAN_ARGS ) } } +/* + * Write a span of identical 8A8R8G8B pixels to an XImage. + */ +static void write_span_mono_8A8R8G8B_ximage( MONO_SPAN_ARGS ) +{ + const XMesaContext xmesa = XMESA_CONTEXT(ctx); + GLuint i, *ptr; + const unsigned long pixel = xmesa_color_to_pixel(xmesa, color[RCOMP], + color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat); + ptr = PIXELADDR4( xmesa->xm_buffer, x, y ); + for (i=0;ixm_buffer, x[i], y[i] ); + *ptr = p; + } + } +} /* * Write an array of identical 8R8G8B pixels to an XImage. @@ -3648,6 +3824,19 @@ static void read_color_span( const GLcontext *ctx, } } break; + case PF_8A8R8G8B: + { + const GLuint *ptr4 = (GLuint *) span->data; + GLuint i; + for (i=0;i> 16) & 0xff); + rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff); + rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff); + rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff); + } + } + break; case PF_8R8G8B: { const GLuint *ptr4 = (GLuint *) span->data; @@ -3835,6 +4024,19 @@ static void read_color_span( const GLcontext *ctx, } } break; + case PF_8A8R8G8B: + { + const GLuint *ptr4 = PIXELADDR4( source, x, y ); + GLuint i; + for (i=0;i> 16) & 0xff); + rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff); + rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff); + rgba[i][ACOMP] = (GLint) ((p4 >> 24) & 0xff); + } + } + break; case PF_8R8G8B: { const GLuint *ptr4 = PIXELADDR4( source, x, y ); @@ -4012,6 +4214,18 @@ static void read_color_pixels( const GLcontext *ctx, } } break; + case PF_8A8R8G8B: + for (i=0;i> 16) & 0xff); + rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff); + rgba[i][BCOMP] = (GLubyte) ( p & 0xff); + rgba[i][ACOMP] = (GLubyte) ((p >> 24) & 0xff); + } + } + break; case PF_8R8G8B: for (i=0;i> 16) & 0xff); + rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff); + rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff); + rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff); + } + } + break; case PF_8R8G8B: for (i=0;iWriteRGBAPixels = write_pixels_8A8B8G8R_pixmap; dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap; break; + case PF_8A8R8G8B: + dd->WriteRGBASpan = write_span_8A8R8G8B_pixmap; + dd->WriteRGBSpan = write_span_rgb_8A8R8G8B_pixmap; + dd->WriteMonoRGBASpan = write_span_mono_pixmap; + dd->WriteRGBAPixels = write_pixels_8A8R8G8B_pixmap; + dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap; + break; case PF_8R8G8B: dd->WriteRGBASpan = write_span_8R8G8B_pixmap; dd->WriteRGBSpan = write_span_rgb_8R8G8B_pixmap; @@ -4430,7 +4663,14 @@ void xmesa_update_span_funcs( GLcontext *ctx ) dd->WriteRGBAPixels = write_pixels_8A8B8G8R_ximage; dd->WriteMonoRGBAPixels = write_pixels_mono_8A8B8G8R_ximage; break; - case PF_8R8G8B: + case PF_8A8R8G8B: + dd->WriteRGBASpan = write_span_8A8R8G8B_ximage; + dd->WriteRGBSpan = write_span_rgb_8A8R8G8B_ximage; + dd->WriteMonoRGBASpan = write_span_mono_8A8R8G8B_ximage; + dd->WriteRGBAPixels = write_pixels_8A8R8G8B_ximage; + dd->WriteMonoRGBAPixels = write_pixels_mono_8A8R8G8B_ximage; + break; + case PF_8R8G8B: dd->WriteRGBASpan = write_span_8R8G8B_ximage; dd->WriteRGBSpan = write_span_rgb_8R8G8B_ximage; dd->WriteMonoRGBASpan = write_span_mono_8R8G8B_ximage; diff --git a/src/mesa/drivers/x11/xm_tri.c b/src/mesa/drivers/x11/xm_tri.c index 35d9d071f91..8fd22ccf4e8 100644 --- a/src/mesa/drivers/x11/xm_tri.c +++ b/src/mesa/drivers/x11/xm_tri.c @@ -116,6 +116,38 @@ +/* + * XImage, smooth, depth-buffered, PF_8A8R8G8B triangle. + */ +#define NAME smooth_8A8R8G8B_z_triangle +#define INTERP_Z 1 +#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE +#define INTERP_RGB 1 +#define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y) +#define PIXEL_TYPE GLuint +#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) +#define SETUP_CODE \ + XMesaContext xmesa = XMESA_CONTEXT(ctx); \ + +#define RENDER_SPAN( span ) \ + GLuint i; \ + for (i = 0; i < span.end; i++) { \ + const DEPTH_TYPE z = FixedToDepth(span.z); \ + if (z < zRow[i]) { \ + pRow[i] = PACK_8R8G8B(FixedToInt(span.red), \ + FixedToInt(span.green), FixedToInt(span.blue)); \ + zRow[i] = z; \ + } \ + span.red += span.redStep; \ + span.green += span.greenStep; \ + span.blue += span.blueStep; \ + span.z += span.zStep; \ + } + +#include "swrast/s_tritemp.h" + + + /* * XImage, smooth, depth-buffered, PF_8R8G8B triangle. */ @@ -450,6 +482,33 @@ +/* + * XImage, flat, depth-buffered, PF_8A8R8G8B triangle. + */ +#define NAME flat_8A8R8G8B_z_triangle +#define INTERP_Z 1 +#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE +#define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y) +#define PIXEL_TYPE GLuint +#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) +#define SETUP_CODE \ + XMesaContext xmesa = XMESA_CONTEXT(ctx); \ + unsigned long p = PACK_8R8G8B( v2->color[0], \ + v2->color[1], v2->color[2] ); +#define RENDER_SPAN( span ) \ + GLuint i; \ + for (i = 0; i < span.end; i++) { \ + const DEPTH_TYPE z = FixedToDepth(span.z); \ + if (z < zRow[i]) { \ + pRow[i] = (PIXEL_TYPE) p; \ + zRow[i] = z; \ + } \ + span.z += span.zStep; \ + } +#include "swrast/s_tritemp.h" + + + /* * XImage, flat, depth-buffered, PF_8R8G8B triangle. */ @@ -749,6 +808,29 @@ +/* + * XImage, smooth, NON-depth-buffered, PF_8A8R8G8B triangle. + */ +#define NAME smooth_8A8R8G8B_triangle +#define INTERP_RGB 1 +#define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y) +#define PIXEL_TYPE GLuint +#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) +#define SETUP_CODE \ + XMesaContext xmesa = XMESA_CONTEXT(ctx); +#define RENDER_SPAN( span ) \ + GLuint i; \ + for (i = 0; i < span.end; i++) { \ + pRow[i] = PACK_8R8G8B(FixedToInt(span.red), \ + FixedToInt(span.green), FixedToInt(span.blue) ); \ + span.red += span.redStep; \ + span.green += span.greenStep; \ + span.blue += span.blueStep; \ + } +#include "swrast/s_tritemp.h" + + + /* * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle. */ @@ -1004,6 +1086,26 @@ +/* + * XImage, flat, NON-depth-buffered, PF_8A8R8G8B triangle. + */ +#define NAME flat_8A8R8G8B_triangle +#define PIXEL_ADDRESS(X,Y) PIXELADDR4(xmesa->xm_buffer,X,Y) +#define PIXEL_TYPE GLuint +#define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) +#define SETUP_CODE \ + XMesaContext xmesa = XMESA_CONTEXT(ctx); \ + unsigned long p = PACK_8R8G8B( v2->color[0], \ + v2->color[1], v2->color[2] ); +#define RENDER_SPAN( span ) \ + GLuint i; \ + for (i = 0; i < span.end; i++) { \ + pRow[i] = (PIXEL_TYPE) p; \ + } +#include "swrast/s_tritemp.h" + + + /* * XImage, flat, NON-depth-buffered, PF_8R8G8B triangle. */ @@ -1202,6 +1304,8 @@ void _xmesa_print_triangle_func( swrast_tri_func triFunc ) _mesa_printf("smooth_TRUECOLOR_z_triangle\n"); else if (triFunc ==smooth_8A8B8G8R_z_triangle) _mesa_printf("smooth_8A8B8G8R_z_triangle\n"); + else if (triFunc ==smooth_8A8R8G8B_z_triangle) + _mesa_printf("smooth_8A8R8G8B_z_triangle\n"); else if (triFunc ==smooth_8R8G8B_z_triangle) _mesa_printf("smooth_8R8G8B_z_triangle\n"); else if (triFunc ==smooth_8R8G8B24_z_triangle) @@ -1222,6 +1326,8 @@ void _xmesa_print_triangle_func( swrast_tri_func triFunc ) _mesa_printf("flat_TRUECOLOR_z_triangle\n"); else if (triFunc ==flat_8A8B8G8R_z_triangle) _mesa_printf("flat_8A8B8G8R_z_triangle\n"); + else if (triFunc ==flat_8A8R8G8B_z_triangle) + _mesa_printf("flat_8A8R8G8B_z_triangle\n"); else if (triFunc ==flat_8R8G8B_z_triangle) _mesa_printf("flat_8R8G8B_z_triangle\n"); else if (triFunc ==flat_8R8G8B24_z_triangle) @@ -1242,6 +1348,8 @@ void _xmesa_print_triangle_func( swrast_tri_func triFunc ) _mesa_printf("smooth_TRUECOLOR_triangle\n"); else if (triFunc ==smooth_8A8B8G8R_triangle) _mesa_printf("smooth_8A8B8G8R_triangle\n"); + else if (triFunc ==smooth_8A8R8G8B_triangle) + _mesa_printf("smooth_8A8R8G8B_triangle\n"); else if (triFunc ==smooth_8R8G8B_triangle) _mesa_printf("smooth_8R8G8B_triangle\n"); else if (triFunc ==smooth_8R8G8B24_triangle) @@ -1264,6 +1372,8 @@ void _xmesa_print_triangle_func( swrast_tri_func triFunc ) _mesa_printf("flat_TRUEDITHER_triangle\n"); else if (triFunc ==flat_8A8B8G8R_triangle) _mesa_printf("flat_8A8B8G8R_triangle\n"); + else if (triFunc ==flat_8A8R8G8B_triangle) + _mesa_printf("flat_8A8R8G8B_triangle\n"); else if (triFunc ==flat_8R8G8B_triangle) _mesa_printf("flat_8R8G8B_triangle\n"); else if (triFunc ==flat_8R8G8B24_triangle) @@ -1334,6 +1444,8 @@ static swrast_tri_func get_triangle_func( GLcontext *ctx ) USE(smooth_TRUECOLOR_z_triangle); case PF_8A8B8G8R: USE(smooth_8A8B8G8R_z_triangle); + case PF_8A8R8G8B: + USE(smooth_8A8R8G8B_z_triangle); case PF_8R8G8B: USE(smooth_8R8G8B_z_triangle); case PF_8R8G8B24: @@ -1371,6 +1483,8 @@ static swrast_tri_func get_triangle_func( GLcontext *ctx ) USE(flat_TRUECOLOR_z_triangle); case PF_8A8B8G8R: USE(flat_8A8B8G8R_z_triangle); + case PF_8A8R8G8B: + USE(flat_8A8R8G8B_z_triangle); case PF_8R8G8B: USE(flat_8R8G8B_z_triangle); case PF_8R8G8B24: @@ -1405,6 +1519,8 @@ static swrast_tri_func get_triangle_func( GLcontext *ctx ) USE(smooth_TRUECOLOR_triangle); case PF_8A8B8G8R: USE(smooth_8A8B8G8R_triangle); + case PF_8A8R8G8B: + USE(smooth_8A8R8G8B_triangle); case PF_8R8G8B: USE(smooth_8R8G8B_triangle); case PF_8R8G8B24: @@ -1442,6 +1558,8 @@ static swrast_tri_func get_triangle_func( GLcontext *ctx ) USE(flat_TRUEDITHER_triangle); case PF_8A8B8G8R: USE(flat_8A8B8G8R_triangle); + case PF_8A8R8G8B: + USE(flat_8A8R8G8B_triangle); case PF_8R8G8B: USE(flat_8R8G8B_triangle); case PF_8R8G8B24: diff --git a/src/mesa/drivers/x11/xmesaP.h b/src/mesa/drivers/x11/xmesaP.h index de989260aef..43712ff21f8 100644 --- a/src/mesa/drivers/x11/xmesaP.h +++ b/src/mesa/drivers/x11/xmesaP.h @@ -74,7 +74,8 @@ enum pixel_format { PF_1Bit, /**< monochrome dithering of RGB */ PF_Grayscale, /**< Grayscale or StaticGray */ PF_8R8G8B24, /**< 24-bit TrueColor: 8-R, 8-G, 8-B bits */ - PF_Dither_5R6G5B /**< 16-bit dithered TrueColor: 5-R, 6-G, 5-B */ + PF_Dither_5R6G5B, /**< 16-bit dithered TrueColor: 5-R, 6-G, 5-B */ + PF_8A8R8G8B /**< 32-bit TrueColor: 8-A, 8-R, 8-G, 8-B */ }; @@ -303,6 +304,12 @@ struct xmesa_buffer { #define PACK_5R6G5B( R, G, B) ( (((R) & 0xf8) << 8) | (((G) & 0xfc) << 3) | ((B) >> 3) ) +/* + * If pixelformat==PF_8A8R8G8B: + */ +#define PACK_8A8R8G8B( R, G, B, A ) \ + ( ((A) << 24) | ((R) << 16) | ((G) << 8) | (B) ) + /* -- 2.30.2