diff options
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/drivers/osmesa/osmesa.c | 7 | ||||
-rw-r--r-- | src/mesa/drivers/x11/xm_tri.c | 92 | ||||
-rw-r--r-- | src/mesa/swrast/s_aatriangle.c | 17 | ||||
-rw-r--r-- | src/mesa/swrast/s_aatritemp.h | 244 | ||||
-rw-r--r-- | src/mesa/swrast/s_context.c | 10 | ||||
-rw-r--r-- | src/mesa/swrast/s_context.h | 9 | ||||
-rw-r--r-- | src/mesa/swrast/s_copypix.c | 43 | ||||
-rw-r--r-- | src/mesa/swrast/s_depth.c | 49 | ||||
-rw-r--r-- | src/mesa/swrast/s_depth.h | 8 | ||||
-rw-r--r-- | src/mesa/swrast/s_drawpix.c | 31 | ||||
-rw-r--r-- | src/mesa/swrast/s_fog.c | 118 | ||||
-rw-r--r-- | src/mesa/swrast/s_fog.h | 28 | ||||
-rw-r--r-- | src/mesa/swrast/s_span.c | 1434 | ||||
-rw-r--r-- | src/mesa/swrast/s_span.h | 53 | ||||
-rw-r--r-- | src/mesa/swrast/s_stencil.c | 61 | ||||
-rw-r--r-- | src/mesa/swrast/s_stencil.h | 7 | ||||
-rw-r--r-- | src/mesa/swrast/s_texture.c | 298 | ||||
-rw-r--r-- | src/mesa/swrast/s_texture.h | 14 | ||||
-rw-r--r-- | src/mesa/swrast/s_trispan.h | 63 | ||||
-rw-r--r-- | src/mesa/swrast/s_tritemp.h | 12 | ||||
-rw-r--r-- | src/mesa/swrast/s_zoom.c | 16 | ||||
-rw-r--r-- | src/mesa/swrast/swrast.h | 101 |
22 files changed, 1671 insertions, 1044 deletions
diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c index 074300188c6..a85c8eeb07f 100644 --- a/src/mesa/drivers/osmesa/osmesa.c +++ b/src/mesa/drivers/osmesa/osmesa.c @@ -1,4 +1,4 @@ -/* $Id: osmesa.c,v 1.71 2001/09/25 17:38:11 keithw Exp $ */ +/* $Id: osmesa.c,v 1.72 2001/12/17 04:56:29 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -55,7 +55,6 @@ #include "swrast/s_depth.h" #include "swrast/s_lines.h" #include "swrast/s_triangle.h" -#include "swrast/s_trispan.h" #include "tnl/tnl.h" #include "tnl/t_context.h" #include "tnl/t_pipeline.h" @@ -1843,7 +1842,7 @@ static void smooth_rgba_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLchan *img = PIXELADDR4(span.x, span.y); \ - for (i = 0; i < span.count; i++, img += 4) { \ + for (i = 0; i < span.end; i++, img += 4) { \ const GLdepth z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ PACK_RGBA(img, FixedToChan(span.red), \ @@ -1887,7 +1886,7 @@ static void flat_rgba_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLuint *img = (GLuint *) PIXELADDR4(span.x, span.y); \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ const GLdepth z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ img[i] = pixel; \ diff --git a/src/mesa/drivers/x11/xm_tri.c b/src/mesa/drivers/x11/xm_tri.c index e017ed523fb..43c923e02e9 100644 --- a/src/mesa/drivers/x11/xm_tri.c +++ b/src/mesa/drivers/x11/xm_tri.c @@ -1,4 +1,4 @@ -/* $Id: xm_tri.c,v 1.20 2001/05/14 16:23:04 brianp Exp $ */ +/* $Id: xm_tri.c,v 1.21 2001/12/17 04:56:29 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -35,6 +35,7 @@ #include "glxheader.h" #include "depth.h" #include "macros.h" +#include "mem.h" #include "mmath.h" #include "mtypes.h" #include "xmesaP.h" @@ -44,7 +45,6 @@ #include "swrast/s_context.h" #include "swrast/s_depth.h" #include "swrast/s_triangle.h" -#include "swrast/s_trispan.h" @@ -70,7 +70,7 @@ static void smooth_TRUECOLOR_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ GLuint i; \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ unsigned long p; \ @@ -108,7 +108,7 @@ static void smooth_8A8B8G8R_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ pRow[i] = PACK_8B8G8R(FixedToInt(span.red), \ @@ -143,7 +143,7 @@ static void smooth_8R8G8B_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; 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), \ @@ -178,7 +178,7 @@ static void smooth_8R8G8B24_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ PIXEL_TYPE *ptr = pRow + i; \ @@ -214,7 +214,7 @@ static void smooth_TRUEDITHER_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ unsigned long p; \ @@ -251,7 +251,7 @@ static void smooth_5R6G5B_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ pRow[i] = PACK_5R6G5B(FixedToInt(span.red), \ @@ -287,7 +287,7 @@ static void smooth_DITHER_5R6G5B_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ PACK_TRUEDITHER(pRow[i], x, y, FixedToInt(span.red), \ @@ -324,7 +324,7 @@ static void smooth_DITHER8_z_triangle( GLcontext *ctx, GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ XDITHER_SETUP(y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ pRow[i] = (PIXEL_TYPE) XDITHER(x, FixedToInt(span.red),\ @@ -359,7 +359,7 @@ static void smooth_DITHER_z_triangle( GLcontext *ctx, GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ XDITHER_SETUP(y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ unsigned long p = XDITHER(x, FixedToInt(span.red), \ @@ -396,7 +396,7 @@ static void smooth_LOOKUP8_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ LOOKUP_SETUP; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ pRow[i] = LOOKUP(FixedToInt(span.red), \ @@ -433,7 +433,7 @@ static void smooth_HPCR_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ pRow[i] = DITHER_HPCR(x, y, FixedToInt(span.red), \ @@ -469,7 +469,7 @@ static void flat_TRUECOLOR_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ XMesaPutPixel(img, x, y, pixel); \ @@ -501,7 +501,7 @@ static void flat_8A8B8G8R_z_triangle( GLcontext *ctx, v2->color[1], v2->color[2] ); #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ pRow[i] = (PIXEL_TYPE) p; \ @@ -533,7 +533,7 @@ static void flat_8R8G8B_z_triangle( GLcontext *ctx, v2->color[1], v2->color[2] ); #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ pRow[i] = (PIXEL_TYPE) p; \ @@ -563,7 +563,7 @@ static void flat_8R8G8B24_z_triangle( GLcontext *ctx, #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ PIXEL_TYPE *ptr = pRow + i; \ @@ -594,7 +594,7 @@ static void flat_TRUEDITHER_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ unsigned long p; \ @@ -629,7 +629,7 @@ static void flat_5R6G5B_z_triangle( GLcontext *ctx, v2->color[1], v2->color[2] ); #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ pRow[i] = (PIXEL_TYPE) p; \ @@ -660,7 +660,7 @@ static void flat_DITHER_5R6G5B_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ PACK_TRUEDITHER(pRow[i], x, y, color[RCOMP], \ @@ -695,7 +695,7 @@ static void flat_DITHER8_z_triangle( GLcontext *ctx, GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ FLAT_DITHER_ROW_SETUP(FLIP(xmesa->xm_buffer, y)); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ pRow[i] = (PIXEL_TYPE) FLAT_DITHER(x); \ @@ -727,7 +727,7 @@ static void flat_DITHER_z_triangle( GLcontext *ctx, GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ FLAT_DITHER_ROW_SETUP(y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ unsigned long p = FLAT_DITHER(x); \ @@ -762,7 +762,7 @@ static void flat_HPCR_z_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ pRow[i] = (PIXEL_TYPE) DITHER_HPCR(x, y, r, g, b); \ @@ -797,7 +797,7 @@ static void flat_LOOKUP8_z_triangle( GLcontext *ctx, GLubyte p = LOOKUP(r,g,b); #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ const DEPTH_TYPE z = FixedToDepth(span.z); \ if (z < zRow[i]) { \ pRow[i] = p; \ @@ -825,7 +825,7 @@ static void smooth_TRUECOLOR_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ unsigned long p; \ PACK_TRUECOLOR(p, FixedToInt(span.red), \ FixedToInt(span.green), FixedToInt(span.blue)); \ @@ -854,7 +854,7 @@ static void smooth_8A8B8G8R_triangle( GLcontext *ctx, #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ pRow[i] = PACK_8B8G8R(FixedToInt(span.red), \ FixedToInt(span.green), FixedToInt(span.blue) ); \ span.red += span.redStep; \ @@ -881,7 +881,7 @@ static void smooth_8R8G8B_triangle( GLcontext *ctx, #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; 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; \ @@ -909,7 +909,7 @@ static void smooth_8R8G8B24_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ PIXEL_TYPE *pixel = pRow; \ - for (i = 0; i < span.count; i++, pixel++) { \ + for (i = 0; i < span.end; i++, pixel++) { \ pixel->r = FixedToInt(span.red); \ pixel->g = FixedToInt(span.green); \ pixel->b = FixedToInt(span.blue); \ @@ -936,7 +936,7 @@ static void smooth_TRUEDITHER_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ unsigned long p; \ PACK_TRUEDITHER(p, x, y, FixedToInt(span.red), \ FixedToInt(span.green), FixedToInt(span.blue)); \ @@ -965,7 +965,7 @@ static void smooth_5R6G5B_triangle( GLcontext *ctx, #define BYTES_PER_ROW (xmesa->xm_buffer->backimage->bytes_per_line) #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ pRow[i] = (PIXEL_TYPE) PACK_5R6G5B(FixedToInt(span.red), \ FixedToInt(span.green), FixedToInt(span.blue)); \ span.red += span.redStep; \ @@ -993,7 +993,7 @@ static void smooth_DITHER_5R6G5B_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ PACK_TRUEDITHER(pRow[i], x, y, FixedToInt(span.red), \ FixedToInt(span.green), FixedToInt(span.blue)); \ span.red += span.redStep; \ @@ -1022,7 +1022,7 @@ static void smooth_DITHER8_triangle( GLcontext *ctx, GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ XDITHER_SETUP(y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ pRow[i] = (PIXEL_TYPE) XDITHER(x, FixedToInt(span.red), \ FixedToInt(span.green), FixedToInt(span.blue) ); \ span.red += span.redStep; \ @@ -1050,7 +1050,7 @@ static void smooth_DITHER_triangle( GLcontext *ctx, GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ XDITHER_SETUP(y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ unsigned long p = XDITHER(x, FixedToInt(span.red), \ FixedToInt(span.green), FixedToInt(span.blue) ); \ XMesaPutPixel(img, x, y, p); \ @@ -1080,7 +1080,7 @@ static void smooth_LOOKUP8_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ LOOKUP_SETUP; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ pRow[i] = LOOKUP(FixedToInt(span.red), \ FixedToInt(span.green), FixedToInt(span.blue));\ span.red += span.redStep; \ @@ -1110,7 +1110,7 @@ static void smooth_HPCR_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ pRow[i] = DITHER_HPCR(x, y, FixedToInt(span.red), \ FixedToInt(span.green), FixedToInt(span.blue)); \ span.red += span.redStep; \ @@ -1139,7 +1139,7 @@ static void flat_TRUECOLOR_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ XMesaPutPixel(img, x, y, pixel); \ } @@ -1164,7 +1164,7 @@ static void flat_8A8B8G8R_triangle( GLcontext *ctx, v2->color[1], v2->color[2] ); #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ pRow[i] = (PIXEL_TYPE) p; \ } @@ -1189,7 +1189,7 @@ static void flat_8R8G8B_triangle( GLcontext *ctx, v2->color[1], v2->color[2] ); #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ pRow[i] = (PIXEL_TYPE) p; \ } @@ -1213,7 +1213,7 @@ static void flat_8R8G8B24_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ PIXEL_TYPE *pixel = pRow; \ - for (i = 0; i < span.count; i++, pixel++) { \ + for (i = 0; i < span.end; i++, pixel++) { \ pixel->r = color[RCOMP]; \ pixel->g = color[GCOMP]; \ pixel->b = color[BCOMP]; \ @@ -1236,7 +1236,7 @@ static void flat_TRUEDITHER_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ unsigned long p; \ PACK_TRUEDITHER(p, x, y, v2->color[0], \ v2->color[1], v2->color[2] ); \ @@ -1265,7 +1265,7 @@ static void flat_5R6G5B_triangle( GLcontext *ctx, v2->color[1], v2->color[2] ); #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ pRow[i] = (PIXEL_TYPE) p; \ } @@ -1289,7 +1289,7 @@ static void flat_DITHER_5R6G5B_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ PACK_TRUEDITHER(pRow[i], x, y, color[RCOMP], \ color[GCOMP], color[BCOMP]); \ } @@ -1317,7 +1317,7 @@ static void flat_DITHER8_triangle( GLcontext *ctx, GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ FLAT_DITHER_ROW_SETUP(FLIP(xmesa->xm_buffer, y)); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ pRow[i] = (PIXEL_TYPE) FLAT_DITHER(x); \ } @@ -1342,7 +1342,7 @@ static void flat_DITHER_triangle( GLcontext *ctx, GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ FLAT_DITHER_ROW_SETUP(y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ unsigned long p = FLAT_DITHER(x); \ XMesaPutPixel(img, x, y, p ); \ } @@ -1370,7 +1370,7 @@ static void flat_HPCR_triangle( GLcontext *ctx, #define RENDER_SPAN( span ) \ GLuint i; \ GLint x = span.x, y = FLIP(xmesa->xm_buffer, span.y); \ - for (i = 0; i < span.count; i++, x++) { \ + for (i = 0; i < span.end; i++, x++) { \ pRow[i] = (PIXEL_TYPE) DITHER_HPCR(x, y, r, g, b); \ } @@ -1398,7 +1398,7 @@ static void flat_LOOKUP8_triangle( GLcontext *ctx, GLubyte p = LOOKUP(r,g,b); #define RENDER_SPAN( span ) \ GLuint i; \ - for (i = 0; i < span.count; i++) { \ + for (i = 0; i < span.end; i++) { \ pRow[i] = (PIXEL_TYPE) p; \ } diff --git a/src/mesa/swrast/s_aatriangle.c b/src/mesa/swrast/s_aatriangle.c index 5f0a5c76012..dde2c89f76d 100644 --- a/src/mesa/swrast/s_aatriangle.c +++ b/src/mesa/swrast/s_aatriangle.c @@ -1,4 +1,4 @@ -/* $Id: s_aatriangle.c,v 1.20 2001/11/13 00:26:39 brianp Exp $ */ +/* $Id: s_aatriangle.c,v 1.21 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -40,6 +40,7 @@ /* * Compute coefficients of a plane using the X,Y coords of the v0, v1, v2 * vertices and the given Z values. + * A point (x,y,z) lies on plane iff a*x+b*y+c*z+d = 0. */ static INLINE void compute_plane(const GLfloat v0[], const GLfloat v1[], const GLfloat v2[], @@ -53,9 +54,15 @@ compute_plane(const GLfloat v0[], const GLfloat v1[], const GLfloat v2[], const GLfloat qy = v2[1] - v0[1]; const GLfloat qz = z2 - z0; + /* Crossproduct "(a,b,c):= dv1 x dv2" is orthogonal to plane. */ const GLfloat a = py * qz - pz * qy; const GLfloat b = pz * qx - px * qz; const GLfloat c = px * qy - py * qx; + /* Point on the plane = "r*(a,b,c) + w", with fixed "r" depending + on the distance of plane from origin and arbitrary "w" parallel + to the plane. */ + /* The scalar product "(r*(a,b,c)+w)*(a,b,c)" is "r*(a^2+b^2+c^2)", + which is equal to "-d" below. */ const GLfloat d = -(a * v0[0] + b * v0[1] + c * z0); plane[0] = a; @@ -93,8 +100,8 @@ do { \ static INLINE GLfloat solve_plane(GLfloat x, GLfloat y, const GLfloat plane[4]) { - const GLfloat z = (plane[3] + plane[0] * x + plane[1] * y) / -plane[2]; - return z; + ASSERT(plane[2] != 0.0F); + return (plane[3] + plane[0] * x + plane[1] * y) / -plane[2]; } @@ -193,7 +200,7 @@ compute_coveragef(const GLfloat v0[3], const GLfloat v1[3], #ifdef DEBUG { const GLfloat area = dx0 * dy1 - dx1 * dy0; - assert(area >= 0.0); + ASSERT(area >= 0.0); } #endif @@ -276,7 +283,7 @@ compute_coveragei(const GLfloat v0[3], const GLfloat v1[3], #ifdef DEBUG { const GLfloat area = dx0 * dy1 - dx1 * dy0; - assert(area >= 0.0); + ASSERT(area >= 0.0); } #endif diff --git a/src/mesa/swrast/s_aatritemp.h b/src/mesa/swrast/s_aatritemp.h index dac2111051e..3ca9893735e 100644 --- a/src/mesa/swrast/s_aatritemp.h +++ b/src/mesa/swrast/s_aatritemp.h @@ -1,4 +1,4 @@ -/* $Id: s_aatritemp.h,v 1.22 2001/12/05 10:24:31 keithw Exp $ */ +/* $Id: s_aatritemp.h,v 1.23 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -52,7 +52,9 @@ GLfloat yMin, yMax; GLboolean ltor; GLfloat majDx, majDy; /* major (i.e. long) edge dx and dy */ - + + struct sw_span span; + #ifdef DO_Z GLfloat zPlane[4]; GLdepth z[MAX_WIDTH]; @@ -65,52 +67,29 @@ #endif #ifdef DO_RGBA GLfloat rPlane[4], gPlane[4], bPlane[4], aPlane[4]; - DEFMARRAY(GLchan, rgba, MAX_WIDTH, 4); /* mac 32k limitation */ #endif #ifdef DO_INDEX GLfloat iPlane[4]; - GLuint index[MAX_WIDTH]; GLint icoverageSpan[MAX_WIDTH]; #else GLfloat coverageSpan[MAX_WIDTH]; #endif #ifdef DO_SPEC GLfloat srPlane[4], sgPlane[4], sbPlane[4]; - DEFMARRAY(GLchan, spec, MAX_WIDTH, 4); #endif #ifdef DO_TEX GLfloat sPlane[4], tPlane[4], uPlane[4], vPlane[4]; GLfloat texWidth, texHeight; - DEFARRAY(GLfloat, s, MAX_WIDTH); /* mac 32k limitation */ - DEFARRAY(GLfloat, t, MAX_WIDTH); - DEFARRAY(GLfloat, u, MAX_WIDTH); - DEFARRAY(GLfloat, lambda, MAX_WIDTH); #elif defined(DO_MULTITEX) GLfloat sPlane[MAX_TEXTURE_UNITS][4]; GLfloat tPlane[MAX_TEXTURE_UNITS][4]; GLfloat uPlane[MAX_TEXTURE_UNITS][4]; GLfloat vPlane[MAX_TEXTURE_UNITS][4]; GLfloat texWidth[MAX_TEXTURE_UNITS], texHeight[MAX_TEXTURE_UNITS]; - DEFMARRAY(GLfloat, s, MAX_TEXTURE_UNITS, MAX_WIDTH); /* mac 32k limit */ - DEFMARRAY(GLfloat, t, MAX_TEXTURE_UNITS, MAX_WIDTH); - DEFMARRAY(GLfloat, u, MAX_TEXTURE_UNITS, MAX_WIDTH); - DEFMARRAY(GLfloat, lambda, MAX_TEXTURE_UNITS, MAX_WIDTH); #endif GLfloat bf = SWRAST_CONTEXT(ctx)->_backface_sign; - -#ifdef DO_RGBA - CHECKARRAY(rgba, return); /* mac 32k limitation */ -#endif -#ifdef DO_SPEC - CHECKARRAY(spec, return); -#endif -#if defined(DO_TEX) || defined(DO_MULTITEX) - CHECKARRAY(s, return); - CHECKARRAY(t, return); - CHECKARRAY(u, return); - CHECKARRAY(lambda, return); -#endif - + + /* determine bottom to top order of vertices */ { GLfloat y0 = v0->win[1]; @@ -286,6 +265,8 @@ GLint ix, startX = (GLint) (x - xAdj); GLuint count, n; GLfloat coverage = 0.0F; + SW_SPAN_RESET(span); + /* skip over fragments with zero coverage */ while (startX < MAX_WIDTH) { coverage = compute_coveragef(pMin, pMid, pMax, startX, iy); @@ -312,27 +293,27 @@ fog[count] = solve_plane(cx, cy, fogPlane); #endif #ifdef DO_RGBA - rgba[count][RCOMP] = solve_plane_chan(cx, cy, rPlane); - rgba[count][GCOMP] = solve_plane_chan(cx, cy, gPlane); - rgba[count][BCOMP] = solve_plane_chan(cx, cy, bPlane); - rgba[count][ACOMP] = solve_plane_chan(cx, cy, aPlane); + span.color.rgba[count][RCOMP] = solve_plane_chan(cx, cy, rPlane); + span.color.rgba[count][GCOMP] = solve_plane_chan(cx, cy, gPlane); + span.color.rgba[count][BCOMP] = solve_plane_chan(cx, cy, bPlane); + span.color.rgba[count][ACOMP] = solve_plane_chan(cx, cy, aPlane); #endif #ifdef DO_INDEX - index[count] = (GLint) solve_plane(cx, cy, iPlane); + span.color.index[count] = (GLint) solve_plane(cx, cy, iPlane); #endif #ifdef DO_SPEC - spec[count][RCOMP] = solve_plane_chan(cx, cy, srPlane); - spec[count][GCOMP] = solve_plane_chan(cx, cy, sgPlane); - spec[count][BCOMP] = solve_plane_chan(cx, cy, sbPlane); + span.specular[count][RCOMP] = solve_plane_chan(cx, cy, srPlane); + span.specular[count][GCOMP] = solve_plane_chan(cx, cy, sgPlane); + span.specular[count][BCOMP] = solve_plane_chan(cx, cy, sbPlane); #endif #ifdef DO_TEX { const GLfloat invQ = solve_plane_recip(cx, cy, vPlane); - s[count] = solve_plane(cx, cy, sPlane) * invQ; - t[count] = solve_plane(cx, cy, tPlane) * invQ; - u[count] = solve_plane(cx, cy, uPlane) * invQ; - lambda[count] = compute_lambda(sPlane, tPlane, invQ, - texWidth, texHeight); + span.texcoords[0][count][0] = solve_plane(cx, cy, sPlane) * invQ; + span.texcoords[0][count][1] = solve_plane(cx, cy, tPlane) * invQ; + span.texcoords[0][count][2] = solve_plane(cx, cy, uPlane) * invQ; + span.lambda[0][count] = compute_lambda(sPlane, tPlane, invQ, + texWidth, texHeight); } #elif defined(DO_MULTITEX) { @@ -340,11 +321,11 @@ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { if (ctx->Texture.Unit[unit]._ReallyEnabled) { GLfloat invQ = solve_plane_recip(cx, cy, vPlane[unit]); - s[unit][count] = solve_plane(cx, cy, sPlane[unit]) * invQ; - t[unit][count] = solve_plane(cx, cy, tPlane[unit]) * invQ; - u[unit][count] = solve_plane(cx, cy, uPlane[unit]) * invQ; - lambda[unit][count] = compute_lambda(sPlane[unit], - tPlane[unit], invQ, texWidth[unit], texHeight[unit]); + span.texcoords[unit][count][0] = solve_plane(cx, cy, sPlane[unit]) * invQ; + span.texcoords[unit][count][1] = solve_plane(cx, cy, tPlane[unit]) * invQ; + span.texcoords[unit][count][2] = solve_plane(cx, cy, uPlane[unit]) * invQ; + span.lambda[unit][count] = compute_lambda(sPlane[unit], + tPlane[unit], invQ, texWidth[unit], texHeight[unit]); } } } @@ -353,46 +334,46 @@ count++; coverage = compute_coveragef(pMin, pMid, pMax, ix, iy); } - + if (ix <= startX) continue; - + n = (GLuint) ix - (GLuint) startX; #ifdef DO_MULTITEX # ifdef DO_SPEC - _mesa_write_multitexture_span(ctx, n, startX, iy, z, fog, - (const GLfloat (*)[MAX_WIDTH]) s, - (const GLfloat (*)[MAX_WIDTH]) t, - (const GLfloat (*)[MAX_WIDTH]) u, - (GLfloat (*)[MAX_WIDTH]) lambda, - rgba, (const GLchan (*)[4]) spec, - coverageSpan, GL_POLYGON); + _old_write_multitexture_span(ctx, n, startX, iy, z, fog, + span.texcoords, + span.lambda, span.color.rgba, + span.specular, + coverageSpan, GL_POLYGON); # else - _mesa_write_multitexture_span(ctx, n, startX, iy, z, fog, - (const GLfloat (*)[MAX_WIDTH]) s, - (const GLfloat (*)[MAX_WIDTH]) t, - (const GLfloat (*)[MAX_WIDTH]) u, - lambda, rgba, NULL, coverageSpan, - GL_POLYGON); + _old_write_multitexture_span(ctx, n, startX, iy, z, fog, + span.texcoords, + span.lambda, span.color.rgba, + NULL, coverageSpan, + GL_POLYGON); # endif #elif defined(DO_TEX) # ifdef DO_SPEC - _mesa_write_texture_span(ctx, n, startX, iy, z, fog, - s, t, u, lambda, rgba, - (const GLchan (*)[4]) spec, - coverageSpan, GL_POLYGON); + _old_write_texture_span(ctx, n, startX, iy, z, fog, + span.texcoords[0], + span.lambda[0], span.color.rgba, + span.specular, + coverageSpan, GL_POLYGON); # else - _mesa_write_texture_span(ctx, n, startX, iy, z, fog, - s, t, u, lambda, - rgba, NULL, coverageSpan, GL_POLYGON); + _old_write_texture_span(ctx, n, startX, iy, z, fog, + span.texcoords[0], + span.lambda[0], + span.color.rgba, NULL, + coverageSpan, GL_POLYGON); # endif #elif defined(DO_RGBA) - _mesa_write_rgba_span(ctx, n, startX, iy, z, fog, rgba, - coverageSpan, GL_POLYGON); + _old_write_rgba_span(ctx, n, startX, iy, z, fog, span.color.rgba, + coverageSpan, GL_POLYGON); #elif defined(DO_INDEX) - _mesa_write_index_span(ctx, n, startX, iy, z, fog, index, - icoverageSpan, GL_POLYGON); + _old_write_index_span(ctx, n, startX, iy, z, fog, span.color.index, + icoverageSpan, GL_POLYGON); #endif } } @@ -409,7 +390,7 @@ GLint ix, left, startX = (GLint) (x + xAdj); GLuint count, n; GLfloat coverage = 0.0F; - + /* make sure we're not past the window edge */ if (startX >= ctx->DrawBuffer->_Xmax) { startX = ctx->DrawBuffer->_Xmax - 1; @@ -422,7 +403,7 @@ break; startX--; } - + /* enter interior of triangle */ ix = startX; count = 0; @@ -441,26 +422,26 @@ fog[ix] = solve_plane(cx, cy, fogPlane); #endif #ifdef DO_RGBA - rgba[ix][RCOMP] = solve_plane_chan(cx, cy, rPlane); - rgba[ix][GCOMP] = solve_plane_chan(cx, cy, gPlane); - rgba[ix][BCOMP] = solve_plane_chan(cx, cy, bPlane); - rgba[ix][ACOMP] = solve_plane_chan(cx, cy, aPlane); + span.color.rgba[ix][RCOMP] = solve_plane_chan(cx, cy, rPlane); + span.color.rgba[ix][GCOMP] = solve_plane_chan(cx, cy, gPlane); + span.color.rgba[ix][BCOMP] = solve_plane_chan(cx, cy, bPlane); + span.color.rgba[ix][ACOMP] = solve_plane_chan(cx, cy, aPlane); #endif #ifdef DO_INDEX - index[ix] = (GLint) solve_plane(cx, cy, iPlane); + span.color.index[ix] = (GLint) solve_plane(cx, cy, iPlane); #endif #ifdef DO_SPEC - spec[ix][RCOMP] = solve_plane_chan(cx, cy, srPlane); - spec[ix][GCOMP] = solve_plane_chan(cx, cy, sgPlane); - spec[ix][BCOMP] = solve_plane_chan(cx, cy, sbPlane); + span.specular[ix][RCOMP] = solve_plane_chan(cx, cy, srPlane); + span.specular[ix][GCOMP] = solve_plane_chan(cx, cy, sgPlane); + span.specular[ix][BCOMP] = solve_plane_chan(cx, cy, sbPlane); #endif #ifdef DO_TEX { const GLfloat invQ = solve_plane_recip(cx, cy, vPlane); - s[ix] = solve_plane(cx, cy, sPlane) * invQ; - t[ix] = solve_plane(cx, cy, tPlane) * invQ; - u[ix] = solve_plane(cx, cy, uPlane) * invQ; - lambda[ix] = compute_lambda(sPlane, tPlane, invQ, + span.texcoords[0][ix][0] = solve_plane(cx, cy, sPlane) * invQ; + span.texcoords[0][ix][1] = solve_plane(cx, cy, tPlane) * invQ; + span.texcoords[0][ix][2] = solve_plane(cx, cy, uPlane) * invQ; + span.lambda[0][ix] = compute_lambda(sPlane, tPlane, invQ, texWidth, texHeight); } #elif defined(DO_MULTITEX) @@ -469,11 +450,14 @@ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { if (ctx->Texture.Unit[unit]._ReallyEnabled) { GLfloat invQ = solve_plane_recip(cx, cy, vPlane[unit]); - s[unit][ix] = solve_plane(cx, cy, sPlane[unit]) * invQ; - t[unit][ix] = solve_plane(cx, cy, tPlane[unit]) * invQ; - u[unit][ix] = solve_plane(cx, cy, uPlane[unit]) * invQ; - lambda[unit][ix] = compute_lambda(sPlane[unit], - tPlane[unit], invQ, texWidth[unit], texHeight[unit]); + span.texcoords[unit][ix][0] = solve_plane(cx, cy, sPlane[unit]) * invQ; + span.texcoords[unit][ix][1] = solve_plane(cx, cy, tPlane[unit]) * invQ; + span.texcoords[unit][ix][2] = solve_plane(cx, cy, uPlane[unit]) * invQ; + span.lambda[unit][ix] = compute_lambda(sPlane[unit], + tPlane[unit], + invQ, + texWidth[unit], + texHeight[unit]); } } } @@ -482,7 +466,7 @@ count++; coverage = compute_coveragef(pMin, pMax, pMid, ix, iy); } - + if (startX <= ix) continue; @@ -496,69 +480,55 @@ if (ctx->Texture.Unit[unit]._ReallyEnabled) { GLint j; for (j = 0; j < (GLint) n; j++) { - s[unit][j] = s[unit][j + left]; - t[unit][j] = t[unit][j + left]; - u[unit][j] = u[unit][j + left]; - lambda[unit][j] = lambda[unit][j + left]; + span.texcoords[unit][j][0] = span.texcoords[unit][j + left][0]; + span.texcoords[unit][j][1] = span.texcoords[unit][j + left][1]; + span.texcoords[unit][j][2] = span.texcoords[unit][j + left][2]; + span.lambda[unit][j] = span.lambda[unit][j + left]; } } } } # ifdef DO_SPEC - _mesa_write_multitexture_span(ctx, n, left, iy, z + left, fog + left, - (const GLfloat (*)[MAX_WIDTH]) s, - (const GLfloat (*)[MAX_WIDTH]) t, - (const GLfloat (*)[MAX_WIDTH]) u, - lambda, rgba + left, - (const GLchan (*)[4]) (spec + left), - coverageSpan + left, - GL_POLYGON); + _old_write_multitexture_span(ctx, n, left, iy, z + left, fog + left, + span.texcoords, span.lambda, + span.color.rgba + left, + span.specular + left, + coverageSpan + left, + GL_POLYGON); # else - _mesa_write_multitexture_span(ctx, n, left, iy, z + left, fog + left, - (const GLfloat (*)[MAX_WIDTH]) s, - (const GLfloat (*)[MAX_WIDTH]) t, - (const GLfloat (*)[MAX_WIDTH]) u, - lambda, - rgba + left, NULL, coverageSpan + left, - GL_POLYGON); + _old_write_multitexture_span(ctx, n, left, iy, z + left, fog + left, + span.texcoords, span.lambda, + span.color.rgba + left, NULL, + coverageSpan + left, + GL_POLYGON); # endif #elif defined(DO_TEX) # ifdef DO_SPEC - _mesa_write_texture_span(ctx, n, left, iy, z + left, fog + left, - s + left, t + left, u + left, - lambda + left, rgba + left, - (const GLchan (*)[4]) (spec + left), - coverageSpan + left, - GL_POLYGON); + _old_write_texture_span(ctx, n, left, iy, z + left, fog + left, + span.texcoords[0] + left, + span.lambda[0] + left, + span.color.rgba + left, + span.specular + left, coverageSpan + left, + GL_POLYGON); # else - _mesa_write_texture_span(ctx, n, left, iy, z + left, fog + left, - s + left, t + left, - u + left, lambda + left, - rgba + left, NULL, - coverageSpan + left, GL_POLYGON); + _old_write_texture_span(ctx, n, left, iy, z + left, fog + left, + span.texcoords[0] + left, + span.lambda[0] + left, + span.color.rgba + left, NULL, + coverageSpan + left, GL_POLYGON); # endif #elif defined(DO_RGBA) - _mesa_write_rgba_span(ctx, n, left, iy, z + left, fog + left, - rgba + left, coverageSpan + left, GL_POLYGON); + _old_write_rgba_span(ctx, n, left, iy, z + left, fog + left, + span.color.rgba + left, coverageSpan + left, GL_POLYGON); #elif defined(DO_INDEX) - _mesa_write_index_span(ctx, n, left, iy, z + left, fog + left, - index + left, icoverageSpan + left, GL_POLYGON); + _old_write_index_span(ctx, n, left, iy, z + left, fog + left, + span.color.index + left, + icoverageSpan + left, GL_POLYGON); #endif } } -#ifdef DO_RGBA - UNDEFARRAY(rgba); /* mac 32k limitation */ -#endif -#ifdef DO_SPEC - UNDEFARRAY(spec); -#endif -#if defined(DO_TEX) || defined(DO_MULTITEX) - UNDEFARRAY(s); - UNDEFARRAY(t); - UNDEFARRAY(u); - UNDEFARRAY(lambda); -#endif + } diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c index 4191dee2cf6..7e2275ec02b 100644 --- a/src/mesa/swrast/s_context.c +++ b/src/mesa/swrast/s_context.c @@ -1,4 +1,4 @@ -/* $Id: s_context.c,v 1.25 2001/07/28 19:28:49 keithw Exp $ */ +/* $Id: s_context.c,v 1.26 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -263,17 +263,15 @@ _swrast_validate_blend_func( GLcontext *ctx, GLuint n, static void _swrast_validate_texture_sample( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, - GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], - GLchan rgba[][4] ) + GLuint n, GLfloat texcoords[][3], + const GLfloat lambda[], GLchan rgba[][4] ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); _swrast_validate_derived( ctx ); _swrast_choose_texture_sample_func( ctx, texUnit, tObj ); - swrast->TextureSample[texUnit]( ctx, texUnit, tObj, n, s, t, u, + swrast->TextureSample[texUnit]( ctx, texUnit, tObj, n, texcoords, lambda, rgba ); } diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h index 88f877e883e..bf1b12fb4db 100644 --- a/src/mesa/swrast/s_context.h +++ b/src/mesa/swrast/s_context.h @@ -1,4 +1,4 @@ -/* $Id: s_context.h,v 1.12 2001/08/14 14:08:44 brianp Exp $ */ +/* $Id: s_context.h,v 1.13 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -38,10 +38,8 @@ */ typedef void (*TextureSampleFunc)( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, - GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], - GLchan rgba[][4] ); + GLuint n, GLfloat texcoords[][3], + const GLfloat lambda[], GLchan rgba[][4] ); @@ -131,6 +129,7 @@ typedef struct GLuint NewState; GLuint StateChanges; + /* Mechanism to allow driver (like X11) to register further * software rasterization routines. */ diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c index f4d08f8f85a..c28a6f78b1f 100644 --- a/src/mesa/swrast/s_copypix.c +++ b/src/mesa/swrast/s_copypix.c @@ -1,4 +1,4 @@ -/* $Id: s_copypix.c,v 1.25 2001/12/14 02:50:57 brianp Exp $ */ +/* $Id: s_copypix.c,v 1.26 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -268,6 +268,7 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy, if (ctx->Texture._ReallyEnabled && ctx->Pixel.PixelTextureEnabled) { GLfloat s[MAX_WIDTH], t[MAX_WIDTH], r[MAX_WIDTH], q[MAX_WIDTH]; + GLfloat texcoord[MAX_WIDTH][3]; GLchan primary_rgba[MAX_WIDTH][4]; GLuint unit; /* XXX not sure how multitexture is supposed to work here */ @@ -275,11 +276,20 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy, MEMCPY(primary_rgba, rgba, 4 * width * sizeof(GLchan)); for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { + GLint i; _mesa_pixeltexgen(ctx, width, (const GLchan (*)[4]) rgba, s, t, r, q); - _swrast_texture_fragments(ctx, unit, width, s, t, r, NULL, - (CONST GLchan (*)[4]) primary_rgba, - rgba); + /* this is an ugly work-around. s,t,r has to be copied to + texcoords, because the functions need different + input. */ + for (i=0; i<width; i++) { + texcoord[i][0] = s[i], + texcoord[i][1] = t[i], + texcoord[i][2] = r[i]; + } + _old_swrast_texture_fragments( ctx, unit, width, texcoord, NULL, + (CONST GLchan (*)[4]) primary_rgba, + rgba); } } @@ -295,7 +305,7 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy, (const GLchan (*)[4])rgba, desty); } else { - _mesa_write_rgba_span( ctx, width, destx, dy, zspan, fogSpan, rgba, + _old_write_rgba_span( ctx, width, destx, dy, zspan, fogSpan, rgba, NULL, GL_BITMAP ); } } @@ -530,6 +540,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy, if (ctx->Texture._ReallyEnabled && ctx->Pixel.PixelTextureEnabled) { GLuint unit; GLchan primary_rgba[MAX_WIDTH][4]; + GLfloat texcoord[MAX_WIDTH][3]; DEFARRAY(GLfloat, s, MAX_WIDTH); /* mac 32k limitation */ DEFARRAY(GLfloat, t, MAX_WIDTH); /* mac 32k limitation */ DEFARRAY(GLfloat, r, MAX_WIDTH); /* mac 32k limitation */ @@ -545,9 +556,17 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy, for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { _mesa_pixeltexgen(ctx, width, (const GLchan (*)[4]) rgba, s, t, r, q); - _swrast_texture_fragments(ctx, unit, width, s, t, r, NULL, - (CONST GLchan (*)[4]) primary_rgba, - rgba); + /* this is an ugly work-around. s,t,r has to be copied to + texcoords, because the functions need different + input. */ + for (i=0; i<width; i++) { + texcoord[i][0] = s[i], + texcoord[i][1] = t[i], + texcoord[i][2] = r[i]; + } + _old_swrast_texture_fragments( ctx, unit, width, texcoord, NULL, + (CONST GLchan (*)[4]) primary_rgba, + rgba); } UNDEFARRAY(s); /* mac 32k limitation */ @@ -565,7 +584,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy, (const GLchan (*)[4])rgba, desty); } else { - _mesa_write_rgba_span( ctx, width, destx, dy, zspan, fogSpan, rgba, + _old_write_rgba_span( ctx, width, destx, dy, zspan, fogSpan, rgba, NULL, GL_BITMAP ); } } @@ -689,7 +708,7 @@ static void copy_ci_pixels( GLcontext *ctx, indexes, desty ); } else { - _mesa_write_index_span(ctx, width, destx, dy, zspan, fogSpan, indexes, + _old_write_index_span(ctx, width, destx, dy, zspan, fogSpan, indexes, NULL, GL_BITMAP); } } @@ -819,7 +838,7 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy, fogSpan, (const GLchan (*)[4])rgba, desty ); } else { - _mesa_write_rgba_span( ctx, width, destx, dy, zspan, fogSpan, + _old_write_rgba_span( ctx, width, destx, dy, zspan, fogSpan, (GLchan (*)[4])rgba, NULL, GL_BITMAP); } } @@ -829,7 +848,7 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy, zspan, fogSpan, indexes, desty ); } else { - _mesa_write_index_span( ctx, width, destx, dy, + _old_write_index_span( ctx, width, destx, dy, zspan, fogSpan, indexes, NULL, GL_BITMAP ); } } diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c index 5001081ae04..b892ffabb35 100644 --- a/src/mesa/swrast/s_depth.c +++ b/src/mesa/swrast/s_depth.c @@ -1,4 +1,4 @@ -/* $Id: s_depth.c,v 1.9 2001/03/19 02:25:36 keithw Exp $ */ +/* $Id: s_depth.c,v 1.10 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -535,8 +535,8 @@ depth_test_span32( GLcontext *ctx, GLuint n, GLint x, GLint y, * Apply depth test to span of fragments. Hardware or software z buffer. */ GLuint -_mesa_depth_test_span( GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLdepth z[], GLubyte mask[] ) +_old_depth_test_span( GLcontext *ctx, GLuint n, GLint x, GLint y, + const GLdepth z[], GLubyte mask[] ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); if (swrast->Driver.ReadDepthSpan) { @@ -564,6 +564,49 @@ _mesa_depth_test_span( GLcontext *ctx, GLuint n, GLint x, GLint y, } } +/* + * Apply depth test to span of fragments. Hardware or software z buffer. + */ +GLuint +_mesa_depth_test_span( GLcontext *ctx, struct sw_span *span) +{ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + + ASSERT(span->activeMask & SPAN_Z); + ASSERT(span->filledMask == GL_TRUE); + ASSERT(span->filledDepth == GL_TRUE); + SW_SPAN_SET_FLAG(span->testedDepth); + + if (swrast->Driver.ReadDepthSpan) { + /* hardware-based depth buffer */ + GLdepth zbuffer[MAX_WIDTH]; + GLuint passed; + (*swrast->Driver.ReadDepthSpan)(ctx, span->end, span->x, span->y, zbuffer); + passed = depth_test_span32(ctx, span->end, span->x, span->y, + zbuffer, span->depth, span->mask); + ASSERT(swrast->Driver.WriteDepthSpan); + (*swrast->Driver.WriteDepthSpan)(ctx, span->end, span->x, span->y, zbuffer, span->mask); + if (passed < span->end) + span->write_all = GL_FALSE; + return passed; + } + else { + GLuint passed; + /* software depth buffer */ + if (ctx->Visual.depthBits <= 16) { + GLushort *zptr = (GLushort *) Z_ADDRESS16(ctx, span->x, span->y); + passed = depth_test_span16(ctx, span->end, span->x, span->y, zptr, span->depth, span->mask); + } + else { + GLuint *zptr = (GLuint *) Z_ADDRESS32(ctx, span->x, span->y); + passed = depth_test_span32(ctx, span->end, span->x, span->y, zptr, span->depth, span->mask); + } + if (passed < span->end) + span->write_all = GL_FALSE; + return passed; + } +} + diff --git a/src/mesa/swrast/s_depth.h b/src/mesa/swrast/s_depth.h index 4d53de350f1..24f813a7c64 100644 --- a/src/mesa/swrast/s_depth.h +++ b/src/mesa/swrast/s_depth.h @@ -1,4 +1,4 @@ -/* $Id: s_depth.h,v 1.3 2001/03/12 00:48:41 gareth Exp $ */ +/* $Id: s_depth.h,v 1.4 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -38,8 +38,10 @@ _mesa_zbuffer_address(GLcontext *ctx, GLint x, GLint y); extern GLuint -_mesa_depth_test_span( GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLdepth z[], GLubyte mask[] ); +_old_depth_test_span( GLcontext *ctx, GLuint n, GLint x, GLint y, + const GLdepth z[], GLubyte mask[] ); +extern GLuint +_mesa_depth_test_span( GLcontext *ctx, struct sw_span *span); extern void _mesa_depth_test_pixels( GLcontext *ctx, diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c index e618dc0a233..7f31c629416 100644 --- a/src/mesa/swrast/s_drawpix.c +++ b/src/mesa/swrast/s_drawpix.c @@ -1,4 +1,4 @@ -/* $Id: s_drawpix.c,v 1.22 2001/06/26 21:15:36 brianp Exp $ */ +/* $Id: s_drawpix.c,v 1.23 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -527,7 +527,7 @@ draw_index_pixels( GLcontext *ctx, GLint x, GLint y, indexes, desty); } else { - _mesa_write_index_span(ctx, drawWidth, x, y, zspan, fogSpan, indexes, + _old_write_index_span(ctx, drawWidth, x, y, zspan, fogSpan, indexes, NULL, GL_BITMAP); } } @@ -650,7 +650,7 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y, GLint i; for (i = 0; i < width; i++) zspan[i] = zptr[i]; - _mesa_write_rgba_span(ctx, width, x, y, zspan, 0, rgba, + _old_write_rgba_span(ctx, width, x, y, zspan, 0, rgba, NULL, GL_BITMAP); } } @@ -662,7 +662,7 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y, const GLuint *zptr = (const GLuint *) _mesa_image_address(&ctx->Unpack, pixels, width, height, GL_DEPTH_COMPONENT, type, 0, row, 0); - _mesa_write_rgba_span(ctx, width, x, y, zptr, 0, rgba, + _old_write_rgba_span(ctx, width, x, y, zptr, 0, rgba, NULL, GL_BITMAP); } } @@ -691,7 +691,7 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y, (const GLchan (*)[4]) rgba, desty); } else { - _mesa_write_rgba_span(ctx, width, x, y, zspan, 0, + _old_write_rgba_span(ctx, width, x, y, zspan, 0, rgba, NULL, GL_BITMAP); } } @@ -701,7 +701,7 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y, ispan, GL_BITMAP); } else { - _mesa_write_index_span(ctx, width, x, y, zspan, 0, + _old_write_index_span(ctx, width, x, y, zspan, 0, ispan, NULL, GL_BITMAP); } } @@ -839,6 +839,7 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y, if (ctx->Texture._ReallyEnabled && ctx->Pixel.PixelTextureEnabled) { GLchan primary_rgba[MAX_WIDTH][4]; GLuint unit; + GLfloat texcoord[MAX_WIDTH][3]; DEFARRAY(GLfloat, s, MAX_WIDTH); /* mac 32k limitation */ DEFARRAY(GLfloat, t, MAX_WIDTH); DEFARRAY(GLfloat, r, MAX_WIDTH); @@ -853,11 +854,21 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y, for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { if (ctx->Texture.Unit[unit]._ReallyEnabled) { + GLint i; _mesa_pixeltexgen(ctx, width, (const GLchan (*)[4]) rgba, s, t, r, q); - _swrast_texture_fragments(ctx, unit, width, s, t, r, NULL, - (CONST GLchan (*)[4]) primary_rgba, - rgba); + /* this is an ugly work-around. s,t,r has to be + copied to texcoords, because the functions need + different input. */ + for (i=0; i<width; i++) { + texcoord[i][0] = s[i], + texcoord[i][1] = t[i], + texcoord[i][2] = r[i]; + } + _old_swrast_texture_fragments( ctx, unit, width, + texcoord, NULL, + (CONST GLchan (*)[4]) primary_rgba, + rgba); } } UNDEFARRAY(s); /* mac 32k limitation */ @@ -875,7 +886,7 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y, (CONST GLchan (*)[4]) rgba, desty); } else { - _mesa_write_rgba_span(ctx, (GLuint) width, x, y, zspan, fogSpan, + _old_write_rgba_span(ctx, (GLuint) width, x, y, zspan, fogSpan, rgba, NULL, GL_BITMAP); } } diff --git a/src/mesa/swrast/s_fog.c b/src/mesa/swrast/s_fog.c index 6280391cc6e..dc2c6778b71 100644 --- a/src/mesa/swrast/s_fog.c +++ b/src/mesa/swrast/s_fog.c @@ -1,4 +1,4 @@ -/* $Id: s_fog.c,v 1.14 2001/09/19 20:30:44 kschultz Exp $ */ +/* $Id: s_fog.c,v 1.15 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -71,6 +71,38 @@ _mesa_z_to_fogfactor(GLcontext *ctx, GLfloat z) /* + * Apply fog to a span of RGBA pixels. + * Input: ctx - + * span - where span->fog and span->fogStep have to be set. + * red, green, blue, alpha - pixel colors + * Output: red, green, blue, alpha - fogged pixel colors + */ +void +_mesa_fog_rgba_pixels( const GLcontext *ctx, struct sw_span *span, + GLchan rgba[][4] ) +{ + GLuint i; + GLfloat fog = span->fog, Dfog = span->fogStep; + GLchan rFog, gFog, bFog; + + ASSERT(ctx->Fog.Enabled); + ASSERT(span->activeMask & SPAN_FOG); + ASSERT(span->filledColor == GL_TRUE); + + UNCLAMPED_FLOAT_TO_CHAN(rFog, ctx->Fog.Color[RCOMP]); + UNCLAMPED_FLOAT_TO_CHAN(gFog, ctx->Fog.Color[GCOMP]); + UNCLAMPED_FLOAT_TO_CHAN(bFog, ctx->Fog.Color[BCOMP]); + + for (i = 0; i < span->end; i++) { + const GLfloat one_min_fog = 1.0F - fog; + rgba[i][RCOMP] = (GLchan) (fog * rgba[i][RCOMP] + one_min_fog * rFog); + rgba[i][GCOMP] = (GLchan) (fog * rgba[i][GCOMP] + one_min_fog * gFog); + rgba[i][BCOMP] = (GLchan) (fog * rgba[i][BCOMP] + one_min_fog * bFog); + fog += Dfog; + } +} + +/* * Apply fog to an array of RGBA pixels. * Input: n - number of pixels * fog - array of fog factors in [0,1] @@ -78,7 +110,7 @@ _mesa_z_to_fogfactor(GLcontext *ctx, GLfloat z) * Output: red, green, blue, alpha - fogged pixel colors */ void -_mesa_fog_rgba_pixels( const GLcontext *ctx, +_old_fog_rgba_pixels( const GLcontext *ctx, GLuint n, const GLfloat fog[], GLchan rgba[][4] ) @@ -100,6 +132,31 @@ _mesa_fog_rgba_pixels( const GLcontext *ctx, } +/* + * Apply fog to a span of color index pixels. + * Input: ctx - + * span - where span->fog and span->fogStep have to be set. + * index - pixel color indexes + * Output: index - fogged pixel color indexes + */ +void +_mesa_fog_ci_pixels( const GLcontext *ctx, struct sw_span *span, + GLuint index[] ) +{ + GLuint idx = (GLuint) ctx->Fog.Index; + GLuint i; + GLfloat fog = span->fog, Dfog = span->fogStep; + + ASSERT(ctx->Fog.Enabled); + ASSERT(span->activeMask & SPAN_FOG); + ASSERT(span->filledColor == GL_TRUE); + + for (i = 0; i < span->end; i++) { + const GLfloat f = CLAMP(fog, 0.0F, 1.0F); + index[i] = (GLuint) ((GLfloat) index[i] + (1.0F - f) * idx); + fog += Dfog; + } +} /* * Apply fog to an array of color index pixels. @@ -109,7 +166,7 @@ _mesa_fog_rgba_pixels( const GLcontext *ctx, * Output: index - fogged pixel color indexes */ void -_mesa_fog_ci_pixels( const GLcontext *ctx, +_old_fog_ci_pixels( const GLcontext *ctx, GLuint n, const GLfloat fog[], GLuint index[] ) { GLuint idx = (GLuint) ctx->Fog.Index; @@ -264,6 +321,29 @@ compute_fog_factors_from_z( const GLcontext *ctx, /* + * Apply fog to a span of RGBA pixels. + * Input: ctx - + * span - where span->depth has to be filled. + * red, green, blue, alpha - pixel colors + * Output: red, green, blue, alpha - fogged pixel colors + */ +void +_mesa_depth_fog_rgba_pixels(const GLcontext *ctx, struct sw_span *span, + GLchan rgba[][4]) +{ + GLfloat fogFact[PB_SIZE]; + + ASSERT(ctx->Fog.Enabled); + ASSERT(span->activeMask & SPAN_Z); + ASSERT(span->end <= PB_SIZE); + ASSERT(span->filledDepth == GL_TRUE); + ASSERT(span->filledColor == GL_TRUE); + + compute_fog_factors_from_z(ctx, span->end, span->depth, fogFact ); + _old_fog_rgba_pixels( ctx, span->end, fogFact, rgba ); +} + +/* * Apply fog to an array of RGBA pixels. * Input: n - number of pixels * z - array of integer depth values @@ -271,13 +351,37 @@ compute_fog_factors_from_z( const GLcontext *ctx, * Output: red, green, blue, alpha - fogged pixel colors */ void -_mesa_depth_fog_rgba_pixels( const GLcontext *ctx, +_old_depth_fog_rgba_pixels( const GLcontext *ctx, GLuint n, const GLdepth z[], GLchan rgba[][4] ) { GLfloat fogFact[PB_SIZE]; ASSERT(n <= PB_SIZE); compute_fog_factors_from_z( ctx, n, z, fogFact ); - _mesa_fog_rgba_pixels( ctx, n, fogFact, rgba ); + _old_fog_rgba_pixels( ctx, n, fogFact, rgba ); +} + + +/* + * Apply fog to a span of color index pixels. + * Input: ctx - + * span - where span->depth has to be filled. + * index - pixel color indexes + * Output: index - fogged pixel color indexes + */ +void +_mesa_depth_fog_ci_pixels( const GLcontext *ctx, struct sw_span *span, + GLuint index[] ) +{ + GLfloat fogFact[PB_SIZE]; + + ASSERT(ctx->Fog.Enabled); + ASSERT(span->activeMask & SPAN_Z); + ASSERT(span->end <= PB_SIZE); + ASSERT(span->filledDepth == GL_TRUE); + ASSERT(span->filledColor == GL_TRUE); + + compute_fog_factors_from_z(ctx, span->end, span->depth, fogFact ); + _old_fog_ci_pixels( ctx, span->end, fogFact, index ); } @@ -289,11 +393,11 @@ _mesa_depth_fog_rgba_pixels( const GLcontext *ctx, * Output: index - fogged pixel color indexes */ void -_mesa_depth_fog_ci_pixels( const GLcontext *ctx, +_old_depth_fog_ci_pixels( const GLcontext *ctx, GLuint n, const GLdepth z[], GLuint index[] ) { GLfloat fogFact[PB_SIZE]; ASSERT(n <= PB_SIZE); compute_fog_factors_from_z( ctx, n, z, fogFact ); - _mesa_fog_ci_pixels( ctx, n, fogFact, index ); + _old_fog_ci_pixels( ctx, n, fogFact, index ); } diff --git a/src/mesa/swrast/s_fog.h b/src/mesa/swrast/s_fog.h index 497583d778d..8db6495d01e 100644 --- a/src/mesa/swrast/s_fog.h +++ b/src/mesa/swrast/s_fog.h @@ -1,4 +1,4 @@ -/* $Id: s_fog.h,v 1.5 2001/06/18 23:55:18 brianp Exp $ */ +/* $Id: s_fog.h,v 1.6 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -38,13 +38,20 @@ _mesa_z_to_fogfactor(GLcontext *ctx, GLfloat z); extern void -_mesa_fog_rgba_pixels( const GLcontext *ctx, +_old_fog_rgba_pixels( const GLcontext *ctx, GLuint n, const GLfloat fog[], GLchan rgba[][4] ); +extern void +_mesa_fog_rgba_pixels( const GLcontext *ctx, struct sw_span *span, + GLchan rgba[][4]); extern void -_mesa_fog_ci_pixels( const GLcontext *ctx, - GLuint n, const GLfloat fog[], GLuint indx[] ); +_mesa_fog_ci_pixels( const GLcontext *ctx, struct sw_span *span, + GLuint indx[]); +extern void +_old_fog_ci_pixels( const GLcontext *ctx, + GLuint n, const GLfloat fog[], + GLuint indx[] ); extern void _mesa_win_fog_coords_from_z( const GLcontext *ctx, @@ -53,12 +60,17 @@ _mesa_win_fog_coords_from_z( const GLcontext *ctx, GLfloat fogcoord[] ); extern void -_mesa_depth_fog_rgba_pixels( const GLcontext *ctx, +_mesa_depth_fog_rgba_pixels( const GLcontext *ctx, struct sw_span *span, + GLchan rgba[][4] ); +extern void +_old_depth_fog_rgba_pixels( const GLcontext *ctx, GLuint n, const GLdepth z[], GLchan rgba[][4] ); extern void -_mesa_depth_fog_ci_pixels( const GLcontext *ctx, - GLuint n, const GLdepth z[], GLuint index[] ); - +_mesa_depth_fog_ci_pixels( const GLcontext *ctx, struct sw_span *span, + GLuint index[] ); +extern void +_old_depth_fog_ci_pixels( const GLcontext *ctx, + GLuint n, const GLdepth z[], GLuint index[] ); #endif diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c index e475da3d042..201cc0b10ec 100644 --- a/src/mesa/swrast/s_span.c +++ b/src/mesa/swrast/s_span.c @@ -1,4 +1,4 @@ -/* $Id: s_span.c,v 1.19 2001/11/19 01:18:28 brianp Exp $ */ +/* $Id: s_span.c,v 1.20 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -50,13 +50,19 @@ #include "s_stencil.h" #include "s_texture.h" +INLINE +static void SET_MASK_TO_ONE(struct sw_span *span) { + SW_SPAN_SET_FLAG(span->filledMask); + /* init mask to 1's (all pixels are to be written) */ + MEMSET(span->mask, 1, span->end); +} /* * Apply the current polygon stipple pattern to a span of pixels. */ static void -stipple_polygon_span( GLcontext *ctx, GLuint n, GLint x, GLint y, +old_stipple_polygon_span( GLcontext *ctx, GLuint n, GLint x, GLint y, GLubyte mask[] ) { const GLuint highbit = 0x80000000; @@ -76,6 +82,32 @@ stipple_polygon_span( GLcontext *ctx, GLuint n, GLint x, GLint y, } } +/* + * Apply the current polygon stipple pattern to a span of pixels. + */ +static void +stipple_polygon_span( GLcontext *ctx, struct sw_span *span) +{ + const GLuint highbit = 0x80000000; + GLuint i, m, stipple; + + ASSERT (span->filledMask == GL_TRUE); + + stipple = ctx->PolygonStipple[span->y % 32]; + m = highbit >> (GLuint) (span->x % 32); + + for (i = 0; i < span->end; i++) { + if ((m & stipple) == 0) { + span->mask[i] = 0; + } + m = m >> 1; + if (m == 0) { + m = highbit; + } + } + span->write_all = GL_FALSE; +} + /* @@ -85,7 +117,7 @@ stipple_polygon_span( GLcontext *ctx, GLuint n, GLint x, GLint y, * 0 = all pixels clipped */ static GLuint -clip_span( GLcontext *ctx, GLint n, GLint x, GLint y, GLubyte mask[] ) +old_clip_span( GLcontext *ctx, GLint n, GLint x, GLint y, GLubyte mask[] ) { /* Clip to top and bottom */ if (y < 0 || y >= ctx->DrawBuffer->Height) { @@ -120,6 +152,57 @@ clip_span( GLcontext *ctx, GLint n, GLint x, GLint y, GLubyte mask[] ) } +/* + * Clip a pixel span to the current buffer/window boundaries. + * Return: GL_TRUE some pixel still visible + * GL_FALSE nothing visible + */ +static GLuint +clip_span( GLcontext *ctx, struct sw_span *span) +{ + GLint x = span->x, y = span->y, n = span->end; + + ASSERT (span->filledMask == GL_TRUE); + + /* Clip to top and bottom */ + if (y < 0 || y >= ctx->DrawBuffer->Height) { + span->end = 0; + return GL_FALSE; + } + + /* Clip to the left */ + if (x < 0) { + if (x + n <= 0) { + /* completely off left side */ + span->end = 0; + return GL_FALSE; + } + else { + /* partially off left side */ + span->write_all = GL_FALSE; + BZERO(span->mask, -x * sizeof(GLubyte)); + return GL_TRUE; + } + } + + /* Clip to right */ + if (x + n > ctx->DrawBuffer->Width) { + if (x >= ctx->DrawBuffer->Width) { + /* completely off right side */ + span->end = 0; + return GL_FALSE; + } + else { + /* partially off right side */ + span->end = ctx->DrawBuffer->Width - x; + return GL_TRUE; + } + } + + return GL_TRUE; +} + + /* * Draw to more than one color buffer (or none). @@ -169,6 +252,73 @@ multi_write_index_span( GLcontext *ctx, GLuint n, GLint x, GLint y, } +/* + * Draw to more than one RGBA color buffer (or none). + */ +static void +multi_write_rgba_span( GLcontext *ctx, GLuint n, GLint x, GLint y, + CONST GLchan rgba[][4], const GLubyte mask[] ) +{ + const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask); + GLuint bufferBit; + SWcontext *swrast = SWRAST_CONTEXT(ctx); + + if (ctx->Color.DrawBuffer == GL_NONE) + return; + + /* loop over four possible dest color buffers */ + for (bufferBit = 1; bufferBit <= 8; bufferBit = bufferBit << 1) { + if (bufferBit & ctx->Color.DrawDestMask) { + GLchan rgbaTmp[MAX_WIDTH][4]; + ASSERT(n < MAX_WIDTH); + + if (bufferBit == FRONT_LEFT_BIT) { + (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_FRONT_LEFT); + ctx->DrawBuffer->Alpha = ctx->DrawBuffer->FrontLeftAlpha; + } + else if (bufferBit == FRONT_RIGHT_BIT) { + (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_FRONT_RIGHT); + ctx->DrawBuffer->Alpha = ctx->DrawBuffer->FrontRightAlpha; + } + else if (bufferBit == BACK_LEFT_BIT) { + (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_BACK_LEFT); + ctx->DrawBuffer->Alpha = ctx->DrawBuffer->BackLeftAlpha; + } + else { + (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_BACK_RIGHT); + ctx->DrawBuffer->Alpha = ctx->DrawBuffer->BackRightAlpha; + } + + /* make copy of incoming colors */ + MEMCPY( rgbaTmp, rgba, 4 * n * sizeof(GLchan) ); + + if (ctx->Color.ColorLogicOpEnabled) { + _mesa_logicop_rgba_span( ctx, n, x, y, rgbaTmp, mask ); + } + else if (ctx->Color.BlendEnabled) { + _mesa_blend_span( ctx, n, x, y, rgbaTmp, mask ); + } + if (colorMask == 0x0) { + break; + } + else if (colorMask != 0xffffffff) { + _mesa_mask_rgba_span( ctx, n, x, y, rgbaTmp ); + } + + (*swrast->Driver.WriteRGBASpan)( ctx, n, x, y, + (const GLchan (*)[4]) rgbaTmp, mask ); + if (swrast->_RasterMask & ALPHABUF_BIT) { + _mesa_write_alpha_span( ctx, n, x, y, + (const GLchan (*)[4])rgbaTmp, mask ); + } + } + } + + /* restore default dest buffer */ + (void) (*ctx->Driver.SetDrawBuffer)( ctx, ctx->Color.DriverDrawBuffer ); +} + + /* * Write a horizontal span of color index pixels to the frame buffer. @@ -181,7 +331,7 @@ multi_write_index_span( GLcontext *ctx, GLuint n, GLint x, GLint y, * primitive - either GL_POINT, GL_LINE, GL_POLYGON, or GL_BITMAP */ void -_mesa_write_index_span( GLcontext *ctx, GLuint n, GLint x, GLint y, +_old_write_index_span( GLcontext *ctx, GLuint n, GLint x, GLint y, const GLdepth z[], const GLfloat fog[], GLuint indexIn[], const GLint coverage[], GLenum primitive ) @@ -196,7 +346,7 @@ _mesa_write_index_span( GLcontext *ctx, GLuint n, GLint x, GLint y, MEMSET(mask, 1, n); if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) { - if ((n = clip_span(ctx,n,x,y,mask)) == 0) { + if ((n = old_clip_span(ctx,n,x,y,mask)) == 0) { return; } } @@ -214,25 +364,25 @@ _mesa_write_index_span( GLcontext *ctx, GLuint n, GLint x, GLint y, /* Do the scissor test */ if (ctx->Scissor.Enabled) { - if ((n = _mesa_scissor_span( ctx, n, x, y, mask )) == 0) { + if ((n = _old_scissor_span( ctx, n, x, y, mask )) == 0) { return; } } /* Polygon Stippling */ if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) { - stipple_polygon_span( ctx, n, x, y, mask ); + old_stipple_polygon_span( ctx, n, x, y, mask ); } if (ctx->Stencil.Enabled) { /* first stencil test */ - if (_mesa_stencil_and_ztest_span(ctx, n, x, y, z, mask) == GL_FALSE) { + if (_old_stencil_and_ztest_span(ctx, n, x, y, z, mask) == GL_FALSE) { return; } } else if (ctx->Depth.Test) { /* regular depth testing */ - if (_mesa_depth_test_span( ctx, n, x, y, z, mask ) == 0) + if (_old_depth_test_span( ctx, n, x, y, z, mask ) == 0) return; } @@ -242,9 +392,9 @@ _mesa_write_index_span( GLcontext *ctx, GLuint n, GLint x, GLint y, /* Per-pixel fog */ if (ctx->Fog.Enabled) { if (fog && !swrast->_PreferPixelFog) - _mesa_fog_ci_pixels( ctx, n, fog, index ); + _old_fog_ci_pixels( ctx, n, fog, index ); else - _mesa_depth_fog_ci_pixels( ctx, n, z, index ); + _old_depth_fog_ci_pixels( ctx, n, z, index ); } /* Antialias coverage application */ @@ -279,48 +429,342 @@ _mesa_write_index_span( GLcontext *ctx, GLuint n, GLint x, GLint y, } - - +/* + * Apply fragment processing to a span of RGBA fragments. + * Input: + * n - number of fragments in the span + * x,y - location of first (left) fragment + * fog - array of fog factor values in [0,1] + */ void -_mesa_write_monoindex_span( GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLdepth z[], const GLfloat fog[], - GLuint index, const GLint coverage[], - GLenum primitive ) +_old_write_rgba_span( GLcontext *ctx, GLuint n, GLint x, GLint y, + const GLdepth z[], const GLfloat fog[], + GLchan rgbaIn[][4], const GLfloat coverage[], + GLenum primitive ) { - SWcontext *swrast = SWRAST_CONTEXT(ctx); + const GLuint modBits = FOG_BIT | BLEND_BIT | MASKING_BIT | + LOGIC_OP_BIT | TEXTURE_BIT; GLubyte mask[MAX_WIDTH]; - GLuint i; + GLboolean write_all = GL_TRUE; + GLchan rgbaBackup[MAX_WIDTH][4]; + GLchan (*rgba)[4]; + SWcontext *swrast = SWRAST_CONTEXT(ctx); /* init mask to 1's (all pixels are to be written) */ MEMSET(mask, 1, n); if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) { - if ((n = clip_span( ctx, n, x, y, mask)) == 0) { + if ((n = old_clip_span( ctx,n,x,y,mask)) == 0) { + return; + } + if (mask[0] == 0) + write_all = GL_FALSE; + } + + if ((primitive==GL_BITMAP && (swrast->_RasterMask & modBits)) + || (swrast->_RasterMask & MULTI_DRAW_BIT)) { + /* must make a copy of the colors since they may be modified */ + MEMCPY( rgbaBackup, rgbaIn, 4 * n * sizeof(GLchan) ); + rgba = rgbaBackup; + } + else { + rgba = rgbaIn; + } + + /* Do the scissor test */ + if (ctx->Scissor.Enabled) { + if ((n = _old_scissor_span( ctx, n, x, y, mask )) == 0) { + return; + } + if (mask[0] == 0) + write_all = GL_FALSE; + } + + /* Polygon Stippling */ + if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) { + old_stipple_polygon_span( ctx, n, x, y, mask ); + write_all = GL_FALSE; + } + + /* Do the alpha test */ + if (ctx->Color.AlphaEnabled) { + if (_mesa_alpha_test( ctx, n, (const GLchan (*)[4]) rgba, mask ) == 0) { return; } + write_all = GL_FALSE; } + if (ctx->Stencil.Enabled) { + /* first stencil test */ + if (_old_stencil_and_ztest_span(ctx, n, x, y, z, mask) == GL_FALSE) { + return; + } + write_all = GL_FALSE; + } + else if (ctx->Depth.Test) { + /* regular depth testing */ + GLuint m = _old_depth_test_span( ctx, n, x, y, z, mask ); + if (m == 0) { + return; + } + if (m < n) { + write_all = GL_FALSE; + } + } + + /* if we get here, something passed the depth test */ + ctx->OcclusionResult = GL_TRUE; + + /* Per-pixel fog */ + if (ctx->Fog.Enabled) { + if (fog && !swrast->_PreferPixelFog) + _old_fog_rgba_pixels( ctx, n, fog, rgba ); + else + _old_depth_fog_rgba_pixels( ctx, n, z, rgba ); + } + + /* Antialias coverage application */ + if (coverage) { + GLuint i; + for (i = 0; i < n; i++) { + rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * coverage[i]); + } + } + + if (swrast->_RasterMask & MULTI_DRAW_BIT) { + multi_write_rgba_span( ctx, n, x, y, (const GLchan (*)[4]) rgba, mask ); + } + else { + /* normal: write to exactly one buffer */ + /* logic op or blending */ + const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask); + + if (ctx->Color.ColorLogicOpEnabled) { + _mesa_logicop_rgba_span( ctx, n, x, y, rgba, mask ); + } + else if (ctx->Color.BlendEnabled) { + _mesa_blend_span( ctx, n, x, y, rgba, mask ); + } + + /* Color component masking */ + if (colorMask == 0x0) { + return; + } + else if (colorMask != 0xffffffff) { + _mesa_mask_rgba_span( ctx, n, x, y, rgba ); + } + + /* write pixels */ + (*swrast->Driver.WriteRGBASpan)( ctx, n, x, y, + (const GLchan (*)[4]) rgba, + write_all ? ((const GLubyte *) NULL) : mask ); + + if (swrast->_RasterMask & ALPHABUF_BIT) { + _mesa_write_alpha_span( ctx, n, x, y, + (const GLchan (*)[4]) rgba, + write_all ? ((const GLubyte *) NULL) : mask ); + } + } +} + + +/* + * Write a horizontal span of color index pixels to the frame buffer. + * Stenciling, Depth-testing, etc. are done as needed. + * Input: primitive - either GL_POINT, GL_LINE, GL_POLYGON, or GL_BITMAP + */ +void +_mesa_write_index_span( GLcontext *ctx, struct sw_span *span, + GLenum primitive ) +{ + const GLuint modBits = FOG_BIT | BLEND_BIT | MASKING_BIT | LOGIC_OP_BIT; + GLuint indexBackup[MAX_WIDTH]; + GLuint *index; /* points to indexIn or indexBackup */ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + + + SET_MASK_TO_ONE(span); + + if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) { + if (clip_span(ctx,span) == GL_FALSE) { + return; + } + } + + if ((primitive==GL_BITMAP && (swrast->_RasterMask & modBits)) + || (swrast->_RasterMask & MULTI_DRAW_BIT)) { + /* Make copy of color indexes */ + MEMCPY( indexBackup, span->color.index, span->end * sizeof(GLuint) ); + index = indexBackup; + } + else { + index = span->color.index; + } + + /* Do the scissor test */ if (ctx->Scissor.Enabled) { - if ((n = _mesa_scissor_span( ctx, n, x, y, mask )) == 0) { + if (_mesa_scissor_span( ctx, span ) == GL_FALSE) { return; } } /* Polygon Stippling */ if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) { - stipple_polygon_span( ctx, n, x, y, mask ); + stipple_polygon_span(ctx, span); } + + /* I have to think where to put this!! */ + if (span->activeMask & SPAN_Z) { + SW_SPAN_SET_FLAG(span->filledDepth); + + if (ctx->Visual.depthBits <= 16) { + GLuint i; + GLfixed zval = span->z; + for (i = 0; i < span->end; i++) { + span->depth[i] = FixedToInt(zval); + zval += span->zStep; + } + } + else { + /* Deep Z buffer, no fixed->int shift */ + GLuint i; + GLfixed zval = span->z; + for (i = 0; i < span->end; i++) { + span->depth[i] = zval; + zval += span->zStep; + } + } + } + + if (ctx->Stencil.Enabled) { /* first stencil test */ - if (_mesa_stencil_and_ztest_span(ctx, n, x, y, z, mask) == GL_FALSE) { + if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE) return; + } + else if (ctx->Depth.Test) { + /* regular depth testing */ + if (_mesa_depth_test_span(ctx, span) == 0) + return; + } + + /* if we get here, something passed the depth test */ + ctx->OcclusionResult = GL_TRUE; + + if (ctx->Color.DrawBuffer == GL_NONE) { + /* write no pixels */ + return; + } + + if (ctx->Fog.Enabled) { + /* Is this the right 'if' ?? */ + if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog) + _mesa_fog_ci_pixels( ctx, span, index); + else + _mesa_depth_fog_ci_pixels( ctx, span, index); + } + + /* Antialias coverage application */ +#if 0 + if (span->coverage) { + GLuint i; + for (i = 0; i < span->end; i++) { + ASSERT(span->coverage[i] < 16); + index[i] = (index[i] & ~0xf) | span->coverage[i]; + } + } +#endif + + if (swrast->_RasterMask & MULTI_DRAW_BIT) { + /* draw to zero or two or more buffers */ + multi_write_index_span( ctx, span->end, span->x, span->y, + index, span->mask ); + } + else { + /* normal situation: draw to exactly one buffer */ + if (ctx->Color.IndexLogicOpEnabled) { + _mesa_logicop_ci_span( ctx, span->end, span->x, span->y, + index, span->mask ); + } + + if (ctx->Color.IndexMask == 0) { + return; + } + else if (ctx->Color.IndexMask != 0xffffffff) { + _mesa_mask_index_span( ctx, span->end, span->x, span->y, index ); + } + + /* write pixels */ + (*swrast->Driver.WriteCI32Span)( ctx, span->end, span->x, + span->y, index, span->mask ); + } +} + + + + +void +_mesa_write_monoindex_span( GLcontext *ctx, struct sw_span *span, + GLuint index, GLenum primitive ) +{ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + GLuint i; + + + SET_MASK_TO_ONE(span); + + if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) { + if (clip_span(ctx,span) == GL_FALSE) { + return; + } + } + + /* Do the scissor test */ + if (ctx->Scissor.Enabled) { + if (_mesa_scissor_span( ctx, span ) == GL_FALSE) { + return; } } + + /* Polygon Stippling */ + if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) { + stipple_polygon_span( ctx, span); + } + + + /* I have to think where to put this!! */ + if (span->activeMask & SPAN_Z) { + SW_SPAN_SET_FLAG(span->filledDepth); + + if (ctx->Visual.depthBits <= 16) { + GLuint i; + GLfixed zval = span->z; + for (i = 0; i < span->end; i++) { + span->depth[i] = FixedToInt(zval); + zval += span->zStep; + } + } + else { + /* Deep Z buffer, no fixed->int shift */ + GLuint i; + GLfixed zval = span->z; + for (i = 0; i < span->end; i++) { + span->depth[i] = zval; + zval += span->zStep; + } + } + } + + if (ctx->Stencil.Enabled) { + /* first stencil test */ + if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE) + return; + } else if (ctx->Depth.Test) { /* regular depth testing */ - if (_mesa_depth_test_span( ctx, n, x, y, z, mask ) == 0) + if (_mesa_depth_test_span( ctx, span) == 0) return; } @@ -335,45 +779,52 @@ _mesa_write_monoindex_span( GLcontext *ctx, GLuint n, GLint x, GLint y, if (ctx->Fog.Enabled || ctx->Color.IndexLogicOpEnabled || ctx->Color.IndexMask != 0xffffffff - || coverage) { +#if 0 + || span->coverage) { +#else + ) { +#endif /* different index per pixel */ GLuint indexes[MAX_WIDTH]; - for (i = 0; i < n; i++) { + for (i = 0; i < span->end; i++) { indexes[i] = index; } if (ctx->Fog.Enabled) { - if (fog && !swrast->_PreferPixelFog) - _mesa_fog_ci_pixels( ctx, n, fog, indexes ); + /* Is this the right 'if' ?? */ + if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog) + _mesa_fog_ci_pixels( ctx, span, indexes ); else - _mesa_depth_fog_ci_pixels( ctx, n, z, indexes ); + _mesa_depth_fog_ci_pixels( ctx, span, indexes ); } /* Antialias coverage application */ - if (coverage) { +#if 0 + if (span->coverage) { GLuint i; - for (i = 0; i < n; i++) { - ASSERT(coverage[i] < 16); - indexes[i] = (indexes[i] & ~0xf) | coverage[i]; + for (i = 0; i < span->end; i++) { + ASSERT(span->coverage[i] < 16); + indexes[i] = (indexes[i] & ~0xf) | span->coverage[i]; } } +#endif if (swrast->_RasterMask & MULTI_DRAW_BIT) { /* draw to zero or two or more buffers */ - multi_write_index_span( ctx, n, x, y, indexes, mask ); + multi_write_index_span( ctx, span->end, span->x, span->y, indexes, span->mask ); } else { /* normal situation: draw to exactly one buffer */ if (ctx->Color.IndexLogicOpEnabled) { - _mesa_logicop_ci_span( ctx, n, x, y, indexes, mask ); + _mesa_logicop_ci_span( ctx, span->end, span->x, span->y, indexes, span->mask ); } if (ctx->Color.IndexMask == 0) { return; } else if (ctx->Color.IndexMask != 0xffffffff) { - _mesa_mask_index_span( ctx, n, x, y, indexes ); + _mesa_mask_index_span( ctx, span->end, span->x, span->y, indexes ); } - (*swrast->Driver.WriteCI32Span)( ctx, n, x, y, indexes, mask ); + (*swrast->Driver.WriteCI32Span)( ctx, span->end, span->x, span->y, indexes, span->mask ); } } else { @@ -383,13 +834,13 @@ _mesa_write_monoindex_span( GLcontext *ctx, GLuint n, GLint x, GLint y, if (swrast->_RasterMask & MULTI_DRAW_BIT) { /* draw to zero or two or more buffers */ GLuint indexes[MAX_WIDTH]; - for (i = 0; i < n; i++) + for (i = 0; i < span->end; i++) indexes[i] = index; - multi_write_index_span( ctx, n, x, y, indexes, mask ); + multi_write_index_span( ctx, span->end, span->x, span->y, indexes, span->mask ); } else { /* normal situation: draw to exactly one buffer */ - (*swrast->Driver.WriteMonoCISpan)( ctx, n, x, y, index, mask ); + (*swrast->Driver.WriteMonoCISpan)( ctx, span->end, span->x, span->y, index, span->mask ); } } } @@ -397,154 +848,94 @@ _mesa_write_monoindex_span( GLcontext *ctx, GLuint n, GLint x, GLint y, /* - * Draw to more than one RGBA color buffer (or none). - */ -static void -multi_write_rgba_span( GLcontext *ctx, GLuint n, GLint x, GLint y, - CONST GLchan rgba[][4], const GLubyte mask[] ) -{ - const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask); - GLuint bufferBit; - SWcontext *swrast = SWRAST_CONTEXT(ctx); - - if (ctx->Color.DrawBuffer == GL_NONE) - return; - - /* loop over four possible dest color buffers */ - for (bufferBit = 1; bufferBit <= 8; bufferBit = bufferBit << 1) { - if (bufferBit & ctx->Color.DrawDestMask) { - GLchan rgbaTmp[MAX_WIDTH][4]; - ASSERT(n < MAX_WIDTH); - - if (bufferBit == FRONT_LEFT_BIT) { - (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_FRONT_LEFT); - ctx->DrawBuffer->Alpha = ctx->DrawBuffer->FrontLeftAlpha; - } - else if (bufferBit == FRONT_RIGHT_BIT) { - (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_FRONT_RIGHT); - ctx->DrawBuffer->Alpha = ctx->DrawBuffer->FrontRightAlpha; - } - else if (bufferBit == BACK_LEFT_BIT) { - (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_BACK_LEFT); - ctx->DrawBuffer->Alpha = ctx->DrawBuffer->BackLeftAlpha; - } - else { - (void) (*ctx->Driver.SetDrawBuffer)( ctx, GL_BACK_RIGHT); - ctx->DrawBuffer->Alpha = ctx->DrawBuffer->BackRightAlpha; - } - - /* make copy of incoming colors */ - MEMCPY( rgbaTmp, rgba, 4 * n * sizeof(GLchan) ); - - if (ctx->Color.ColorLogicOpEnabled) { - _mesa_logicop_rgba_span( ctx, n, x, y, rgbaTmp, mask ); - } - else if (ctx->Color.BlendEnabled) { - _mesa_blend_span( ctx, n, x, y, rgbaTmp, mask ); - } - if (colorMask == 0x0) { - break; - } - else if (colorMask != 0xffffffff) { - _mesa_mask_rgba_span( ctx, n, x, y, rgbaTmp ); - } - - (*swrast->Driver.WriteRGBASpan)( ctx, n, x, y, - (const GLchan (*)[4]) rgbaTmp, mask ); - if (swrast->_RasterMask & ALPHABUF_BIT) { - _mesa_write_alpha_span( ctx, n, x, y, - (const GLchan (*)[4])rgbaTmp, mask ); - } - } - } - - /* restore default dest buffer */ - (void) (*ctx->Driver.SetDrawBuffer)( ctx, ctx->Color.DriverDrawBuffer ); -} - - - -/* * Apply fragment processing to a span of RGBA fragments. * Input: - * n - number of fragments in the span - * x,y - location of first (left) fragment - * fog - array of fog factor values in [0,1] */ void -_mesa_write_rgba_span( GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLdepth z[], const GLfloat fog[], - GLchan rgbaIn[][4], const GLfloat coverage[], +_mesa_write_rgba_span( GLcontext *ctx, struct sw_span *span, GLenum primitive ) { const GLuint modBits = FOG_BIT | BLEND_BIT | MASKING_BIT | LOGIC_OP_BIT | TEXTURE_BIT; - GLubyte mask[MAX_WIDTH]; - GLboolean write_all = GL_TRUE; GLchan rgbaBackup[MAX_WIDTH][4]; GLchan (*rgba)[4]; SWcontext *swrast = SWRAST_CONTEXT(ctx); - /* init mask to 1's (all pixels are to be written) */ - MEMSET(mask, 1, n); + + SET_MASK_TO_ONE(span); if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) { - if ((n = clip_span( ctx,n,x,y,mask)) == 0) { + if (clip_span( ctx,span ) == GL_FALSE) { return; } - if (mask[0] == 0) - write_all = GL_FALSE; } - if ((primitive==GL_BITMAP && (swrast->_RasterMask & modBits)) - || (swrast->_RasterMask & MULTI_DRAW_BIT)) { - /* must make a copy of the colors since they may be modified */ - MEMCPY( rgbaBackup, rgbaIn, 4 * n * sizeof(GLchan) ); - rgba = rgbaBackup; - } - else { - rgba = rgbaIn; - } /* Do the scissor test */ if (ctx->Scissor.Enabled) { - if ((n = _mesa_scissor_span( ctx, n, x, y, mask )) == 0) { + if (_mesa_scissor_span( ctx, span ) == GL_FALSE) { return; } - if (mask[0] == 0) - write_all = GL_FALSE; } + /* Polygon Stippling */ if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) { - stipple_polygon_span( ctx, n, x, y, mask ); - write_all = GL_FALSE; + stipple_polygon_span( ctx, span); + } + + + if ((primitive==GL_BITMAP && (swrast->_RasterMask & modBits)) + || (swrast->_RasterMask & MULTI_DRAW_BIT)) { + /* must make a copy of the colors since they may be modified */ + MEMCPY( rgbaBackup, span->color.rgba, 4 * span->end * sizeof(GLchan) ); + rgba = rgbaBackup; + } + else { + rgba = span->color.rgba; } + /* Do the alpha test */ if (ctx->Color.AlphaEnabled) { - if (_mesa_alpha_test( ctx, n, (const GLchan (*)[4]) rgba, mask ) == 0) { + if (_mesa_alpha_test( ctx, span->end, (const GLchan (*)[4]) rgba, span->mask ) == 0) { return; } - write_all = GL_FALSE; + span->write_all = GL_FALSE; + } + + /* I have to think where to put this!! */ + if (span->activeMask & SPAN_Z) { + SW_SPAN_SET_FLAG(span->filledDepth); + + if (ctx->Visual.depthBits <= 16) { + GLuint i; + GLfixed zval = span->z; + for (i = 0; i < span->end; i++) { + span->depth[i] = FixedToInt(zval); + zval += span->zStep; + } + } + else { + /* Deep Z buffer, no fixed->int shift */ + GLuint i; + GLfixed zval = span->z; + for (i = 0; i < span->end; i++) { + span->depth[i] = zval; + zval += span->zStep; + } + } } if (ctx->Stencil.Enabled) { /* first stencil test */ - if (_mesa_stencil_and_ztest_span(ctx, n, x, y, z, mask) == GL_FALSE) { - return; - } - write_all = GL_FALSE; + if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE) + return; } else if (ctx->Depth.Test) { /* regular depth testing */ - GLuint m = _mesa_depth_test_span( ctx, n, x, y, z, mask ); - if (m == 0) { - return; - } - if (m < n) { - write_all = GL_FALSE; - } + if (_mesa_depth_test_span(ctx, span) == GL_FALSE) + return; } /* if we get here, something passed the depth test */ @@ -552,22 +943,25 @@ _mesa_write_rgba_span( GLcontext *ctx, GLuint n, GLint x, GLint y, /* Per-pixel fog */ if (ctx->Fog.Enabled) { - if (fog && !swrast->_PreferPixelFog) - _mesa_fog_rgba_pixels( ctx, n, fog, rgba ); + /* Is this the right 'if' ?? */ + if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog) + _mesa_fog_rgba_pixels( ctx, span, rgba ); else - _mesa_depth_fog_rgba_pixels( ctx, n, z, rgba ); + _mesa_depth_fog_rgba_pixels( ctx, span, rgba ); } /* Antialias coverage application */ - if (coverage) { +#if 0 + if (span->coverage) { GLuint i; - for (i = 0; i < n; i++) { - rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * coverage[i]); + for (i = 0; i < span->end; i++) { + rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * span->coverage[i]); } } +#endif if (swrast->_RasterMask & MULTI_DRAW_BIT) { - multi_write_rgba_span( ctx, n, x, y, (const GLchan (*)[4]) rgba, mask ); + multi_write_rgba_span( ctx, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, span->mask ); } else { /* normal: write to exactly one buffer */ @@ -575,10 +969,10 @@ _mesa_write_rgba_span( GLcontext *ctx, GLuint n, GLint x, GLint y, const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask); if (ctx->Color.ColorLogicOpEnabled) { - _mesa_logicop_rgba_span( ctx, n, x, y, rgba, mask ); + _mesa_logicop_rgba_span( ctx, span->end, span->x, span->y, rgba, span->mask ); } else if (ctx->Color.BlendEnabled) { - _mesa_blend_span( ctx, n, x, y, rgba, mask ); + _mesa_blend_span( ctx, span->end, span->x, span->y, rgba, span->mask ); } /* Color component masking */ @@ -586,101 +980,103 @@ _mesa_write_rgba_span( GLcontext *ctx, GLuint n, GLint x, GLint y, return; } else if (colorMask != 0xffffffff) { - _mesa_mask_rgba_span( ctx, n, x, y, rgba ); + _mesa_mask_rgba_span( ctx, span->end, span->x, span->y, rgba ); } /* write pixels */ - (*swrast->Driver.WriteRGBASpan)( ctx, n, x, y, + (*swrast->Driver.WriteRGBASpan)( ctx, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, - write_all ? ((const GLubyte *) NULL) : mask ); + span->write_all ? ((const GLubyte *) NULL) : span->mask ); if (swrast->_RasterMask & ALPHABUF_BIT) { - _mesa_write_alpha_span( ctx, n, x, y, + _mesa_write_alpha_span( ctx, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, - write_all ? ((const GLubyte *) NULL) : mask ); + span->write_all ? ((const GLubyte *) NULL) : span->mask ); } } } - /* * Write a horizontal span of color pixels to the frame buffer. * The color is initially constant for the whole span. * Alpha-testing, stenciling, depth-testing, and blending are done as needed. - * Input: n - number of pixels in the span - * x, y - location of leftmost pixel in the span - * z - array of [n] z-values - * fog - array of fog factor values in [0,1] - * r, g, b, a - the color of the pixels + * Input: r, g, b, a - the color of the pixels * primitive - either GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP. */ void -_mesa_write_monocolor_span( GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLdepth z[], const GLfloat fog[], - const GLchan color[4], const GLfloat coverage[], - GLenum primitive ) +_mesa_write_monocolor_span( GLcontext *ctx, struct sw_span *span, + const GLchan color[4], GLenum primitive ) { const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask); GLuint i; - GLubyte mask[MAX_WIDTH]; - GLboolean write_all = GL_TRUE; GLchan rgba[MAX_WIDTH][4]; SWcontext *swrast = SWRAST_CONTEXT(ctx); - /* init mask to 1's (all pixels are to be written) */ - MEMSET(mask, 1, n); + + SET_MASK_TO_ONE(span); if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) { - if ((n = clip_span( ctx,n,x,y,mask)) == 0) { + if (clip_span(ctx,span) == GL_FALSE) { return; } - if (mask[0] == 0) - write_all = GL_FALSE; } /* Do the scissor test */ if (ctx->Scissor.Enabled) { - if ((n = _mesa_scissor_span( ctx, n, x, y, mask )) == 0) { + if (_mesa_scissor_span( ctx, span ) == GL_FALSE) { return; } - if (mask[0] == 0) - write_all = GL_FALSE; } /* Polygon Stippling */ if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) { - stipple_polygon_span( ctx, n, x, y, mask ); - write_all = GL_FALSE; + stipple_polygon_span( ctx, span); } /* Do the alpha test */ if (ctx->Color.AlphaEnabled) { - for (i = 0; i < n; i++) { + for (i = 0; i < span->end; i++) { rgba[i][ACOMP] = color[ACOMP]; } - if (_mesa_alpha_test( ctx, n, (const GLchan (*)[4])rgba, mask ) == 0) { + if (_mesa_alpha_test( ctx, span->end, (const GLchan (*)[4])rgba, span->mask ) == 0) { return; } - write_all = GL_FALSE; + span->write_all = GL_FALSE; + } + + /* I have to think where to put this!! */ + if (span->activeMask & SPAN_Z) { + SW_SPAN_SET_FLAG(span->filledDepth); + + if (ctx->Visual.depthBits <= 16) { + GLuint i; + GLfixed zval = span->z; + for (i = 0; i < span->end; i++) { + span->depth[i] = FixedToInt(zval); + zval += span->zStep; + } + } + else { + /* Deep Z buffer, no fixed->int shift */ + GLuint i; + GLfixed zval = span->z; + for (i = 0; i < span->end; i++) { + span->depth[i] = zval; + zval += span->zStep; + } + } } if (ctx->Stencil.Enabled) { /* first stencil test */ - if (_mesa_stencil_and_ztest_span(ctx, n, x, y, z, mask) == GL_FALSE) { + if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE) return; - } - write_all = GL_FALSE; } else if (ctx->Depth.Test) { /* regular depth testing */ - GLuint m = _mesa_depth_test_span( ctx, n, x, y, z, mask ); - if (m == 0) { + if (_mesa_depth_test_span(ctx, span) == 0) return; - } - if (m < n) { - write_all = GL_FALSE; - } } /* if we get here, something passed the depth test */ @@ -692,41 +1088,49 @@ _mesa_write_monocolor_span( GLcontext *ctx, GLuint n, GLint x, GLint y, } if (ctx->Color.ColorLogicOpEnabled || colorMask != 0xffffffff || +#if 0 (swrast->_RasterMask & (BLEND_BIT | FOG_BIT)) || coverage) { +#else + (swrast->_RasterMask & (BLEND_BIT | FOG_BIT))) { +#endif /* assign same color to each pixel */ - for (i = 0; i < n; i++) { - if (mask[i]) { + SW_SPAN_SET_FLAG(span->filledColor); + for (i = 0; i < span->end; i++) { + if (span->mask[i]) { COPY_CHAN4(rgba[i], color); } } /* Per-pixel fog */ if (ctx->Fog.Enabled) { - if (fog && !swrast->_PreferPixelFog) - _mesa_fog_rgba_pixels( ctx, n, fog, rgba ); + /* Is this the right 'if' ?? */ + if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog) + _mesa_fog_rgba_pixels( ctx, span, rgba ); else - _mesa_depth_fog_rgba_pixels( ctx, n, z, rgba ); + _mesa_depth_fog_rgba_pixels( ctx, span, rgba ); } /* Antialias coverage application */ - if (coverage) { +#if 0 + if (span->coverage) { GLuint i; - for (i = 0; i < n; i++) { - rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * coverage[i]); + for (i = 0; i < span->end; i++) { + rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * span->coverage[i]); } } +#endif if (swrast->_RasterMask & MULTI_DRAW_BIT) { - multi_write_rgba_span( ctx, n, x, y, - (const GLchan (*)[4]) rgba, mask ); + multi_write_rgba_span( ctx, span->end, span->x, span->y, + (const GLchan (*)[4]) rgba, span->mask ); } else { /* normal: write to exactly one buffer */ if (ctx->Color.ColorLogicOpEnabled) { - _mesa_logicop_rgba_span( ctx, n, x, y, rgba, mask ); + _mesa_logicop_rgba_span( ctx, span->end, span->x, span->y, rgba, span->mask ); } else if (ctx->Color.BlendEnabled) { - _mesa_blend_span( ctx, n, x, y, rgba, mask ); + _mesa_blend_span( ctx, span->end, span->x, span->y, rgba, span->mask ); } /* Color component masking */ @@ -734,17 +1138,17 @@ _mesa_write_monocolor_span( GLcontext *ctx, GLuint n, GLint x, GLint y, return; } else if (colorMask != 0xffffffff) { - _mesa_mask_rgba_span( ctx, n, x, y, rgba ); + _mesa_mask_rgba_span( ctx, span->end, span->x, span->y, rgba ); } /* write pixels */ - (*swrast->Driver.WriteRGBASpan)( ctx, n, x, y, + (*swrast->Driver.WriteRGBASpan)( ctx, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, - write_all ? ((const GLubyte *) NULL) : mask ); + span->write_all ? ((const GLubyte *) NULL) : span->mask ); if (swrast->_RasterMask & ALPHABUF_BIT) { - _mesa_write_alpha_span( ctx, n, x, y, + _mesa_write_alpha_span( ctx, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, - write_all ? ((const GLubyte *) NULL) : mask ); + span->write_all ? ((const GLubyte *) NULL) : span->mask ); } } } @@ -754,19 +1158,20 @@ _mesa_write_monocolor_span( GLcontext *ctx, GLuint n, GLint x, GLint y, ASSERT(!ctx->Color.ColorLogicOpEnabled); if (swrast->_RasterMask & MULTI_DRAW_BIT) { - for (i = 0; i < n; i++) { - if (mask[i]) { + SW_SPAN_SET_FLAG(span->filledColor); + for (i = 0; i < span->end; i++) { + if (span->mask[i]) { COPY_CHAN4(rgba[i], color); } } - multi_write_rgba_span( ctx, n, x, y, - (const GLchan (*)[4]) rgba, mask ); + multi_write_rgba_span( ctx, span->end, span->x, span->y, + (const GLchan (*)[4]) rgba, span->mask ); } else { - (*swrast->Driver.WriteMonoRGBASpan)( ctx, n, x, y, color, mask ); + (*swrast->Driver.WriteMonoRGBASpan)( ctx, span->end, span->x, span->y, color, span->mask ); if (swrast->_RasterMask & ALPHABUF_BIT) { - _mesa_write_mono_alpha_span( ctx, n, x, y, (GLchan) color[ACOMP], - write_all ? ((const GLubyte *) NULL) : mask ); + _mesa_write_mono_alpha_span( ctx, span->end, span->x, span->y, (GLchan) color[ACOMP], + span->write_all ? ((const GLubyte *) NULL) : span->mask ); } } } @@ -779,19 +1184,22 @@ _mesa_write_monocolor_span( GLcontext *ctx, GLuint n, GLint x, GLint y, * GL_LIGHT_MODEL_COLOR_CONTROL = GL_SEPARATE_SPECULAR_COLOR. */ static void -add_colors(GLuint n, GLchan rgba[][4], CONST GLchan specular[][4] ) +add_colors(CONST struct sw_span *span, GLchan rgba[][4]) { GLuint i; - for (i = 0; i < n; i++) { + ASSERT(span->filledSpecular == GL_TRUE); + ASSERT(span->filledColor == GL_TRUE); + + for (i = 0; i < span->end; i++) { #if CHAN_TYPE == GL_FLOAT /* no clamping */ - rgba[i][RCOMP] += specular[i][RCOMP]; - rgba[i][GCOMP] += specular[i][GCOMP]; - rgba[i][BCOMP] += specular[i][BCOMP]; + rgba[i][RCOMP] += span->specular[i][RCOMP]; + rgba[i][GCOMP] += span->specular[i][GCOMP]; + rgba[i][BCOMP] += span->specular[i][BCOMP]; #else - GLint r = rgba[i][RCOMP] + specular[i][RCOMP]; - GLint g = rgba[i][GCOMP] + specular[i][GCOMP]; - GLint b = rgba[i][BCOMP] + specular[i][BCOMP]; + GLint r = rgba[i][RCOMP] + span->specular[i][RCOMP]; + GLint g = rgba[i][GCOMP] + span->specular[i][GCOMP]; + GLint b = rgba[i][BCOMP] + span->specular[i][BCOMP]; rgba[i][RCOMP] = (GLchan) MIN2(r, CHAN_MAX); rgba[i][GCOMP] = (GLchan) MIN2(g, CHAN_MAX); rgba[i][BCOMP] = (GLchan) MIN2(b, CHAN_MAX); @@ -818,115 +1226,104 @@ add_colors(GLuint n, GLchan rgba[][4], CONST GLchan specular[][4] ) * Contributed by Klaus Niederkrueger. */ static void -masked_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLdepth z[], const GLfloat fog[], - const GLfloat s[], const GLfloat t[], - const GLfloat u[], GLfloat lambda[], - GLchan rgbaIn[][4], CONST GLchan spec[][4], - const GLfloat coverage[], GLubyte mask[], - GLboolean write_all ) +masked_texture_span( GLcontext *ctx, struct sw_span *span) { const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask); GLchan rgbaBackup[MAX_WIDTH][4]; - GLchan (*rgba)[4]; /* points to either rgbaIn or rgbaBackup */ + GLchan (*rgba)[4]; /* points to either span->color.rgba or rgbaBackup */ SWcontext *swrast = SWRAST_CONTEXT(ctx); if (swrast->_RasterMask & MULTI_DRAW_BIT) { /* must make a copy of the colors since they may be modified */ - MEMCPY(rgbaBackup, rgbaIn, 4 * n * sizeof(GLchan)); + MEMCPY(rgbaBackup, span->color.rgba, 4 * span->end * sizeof(GLchan)); rgba = rgbaBackup; } else { - rgba = rgbaIn; + rgba = span->color.rgba; } ASSERT(ctx->Texture._ReallyEnabled); - _swrast_texture_fragments( ctx, 0, n, s, t, u, lambda, - (CONST GLchan (*)[4]) rgba, rgba ); - - + _swrast_texture_fragments( ctx, 0, span, rgba ); + + /* Texture with alpha test */ if (ctx->Color.AlphaEnabled) { /* Do the alpha test */ - if (_mesa_alpha_test( ctx, n, (const GLchan (*)[4]) rgba, mask ) == 0) { + if (_mesa_alpha_test( ctx, span->end, (const GLchan (*)[4]) rgba, span->mask ) == 0) { return; } - write_all = GL_FALSE; + span->write_all = GL_FALSE; /* Depth test usually in 'rasterize_span' but if alpha test needed, we have to wait for that test before depth test can be done. */ if (ctx->Stencil.Enabled) { - /* first stencil test */ - if (_mesa_stencil_and_ztest_span(ctx, n, x, y, z, mask) == GL_FALSE) { - return; - } - write_all = GL_FALSE; + /* first stencil test */ + if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE) + return; } else if (ctx->Depth.Test) { - /* regular depth testing */ - GLuint m = _mesa_depth_test_span( ctx, n, x, y, z, mask ); - if (m == 0) { - return; - } - if (m < n) { - write_all = GL_FALSE; - } + /* regular depth testing */ + if (_mesa_depth_test_span(ctx, span) == 0) + return; } } /* if we get here, something passed the depth test */ ctx->OcclusionResult = GL_TRUE; - - + + /* Add base and specular colors */ - if (spec && + if ((span->activeMask & SPAN_SPEC) && /* Is this right test ???*/ (ctx->Fog.ColorSumEnabled || (ctx->Light.Enabled && ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR))) - add_colors( n, rgba, spec ); /* rgba = rgba + spec */ - + add_colors(span, rgba); /* rgba = rgba + spec */ + /* Per-pixel fog */ if (ctx->Fog.Enabled) { - if (fog && !swrast->_PreferPixelFog) - _mesa_fog_rgba_pixels( ctx, n, fog, rgba ); + /* Is this the right 'if' ?? */ + if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog) + _mesa_fog_rgba_pixels(ctx, span, rgba); else - _mesa_depth_fog_rgba_pixels( ctx, n, z, rgba ); + _mesa_depth_fog_rgba_pixels(ctx, span, rgba); } /* Antialias coverage application */ - if (coverage) { +#if 0 + if (span->coverage) { GLuint i; - for (i = 0; i < n; i++) { - rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * coverage[i]); + for (i = 0; i < span->end; i++) { + rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * span->coverage[i]); } } +#endif if (swrast->_RasterMask & MULTI_DRAW_BIT) { - multi_write_rgba_span( ctx, n, x, y, (const GLchan (*)[4]) rgba, mask ); + multi_write_rgba_span( ctx, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, span->mask ); } else { /* normal: write to exactly one buffer */ if (ctx->Color.ColorLogicOpEnabled) { - _mesa_logicop_rgba_span( ctx, n, x, y, rgba, mask ); + _mesa_logicop_rgba_span( ctx, span->end, span->x, span->y, rgba, span->mask ); } else if (ctx->Color.BlendEnabled) { - _mesa_blend_span( ctx, n, x, y, rgba, mask ); + _mesa_blend_span( ctx, span->end, span->x, span->y, rgba, span->mask ); } if (colorMask == 0x0) { return; } else if (colorMask != 0xffffffff) { - _mesa_mask_rgba_span( ctx, n, x, y, rgba ); + _mesa_mask_rgba_span( ctx, span->end, span->x, span->y, rgba ); } - (*swrast->Driver.WriteRGBASpan)( ctx, n, x, y, (const GLchan (*)[4])rgba, - write_all ? NULL : mask ); + (*swrast->Driver.WriteRGBASpan)( ctx, span->end, span->x, span->y, (const GLchan (*)[4])rgba, + span->write_all ? NULL : span->mask ); if (swrast->_RasterMask & ALPHABUF_BIT) { - _mesa_write_alpha_span( ctx, n, x, y, (const GLchan (*)[4]) rgba, - write_all ? NULL : mask ); + _mesa_write_alpha_span( ctx, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, + span->write_all ? NULL : span->mask ); } } } @@ -937,121 +1334,107 @@ masked_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, * Contributed by Klaus Niederkrueger. */ static void -masked_multitexture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLdepth z[], const GLfloat fog[], - CONST GLfloat s[MAX_TEXTURE_UNITS][MAX_WIDTH], - CONST GLfloat t[MAX_TEXTURE_UNITS][MAX_WIDTH], - CONST GLfloat u[MAX_TEXTURE_UNITS][MAX_WIDTH], - GLfloat lambda[][MAX_WIDTH], - GLchan rgbaIn[MAX_TEXTURE_UNITS][4], - CONST GLchan spec[MAX_TEXTURE_UNITS][4], - const GLfloat coverage[], GLubyte mask[], - GLboolean write_all ) +masked_multitexture_span( GLcontext *ctx, struct sw_span *span) { GLchan rgbaBackup[MAX_WIDTH][4]; - GLchan (*rgba)[4]; /* points to either rgbaIn or rgbaBackup */ + GLchan (*rgba)[4]; /* points to either span->color.rgba or rgbaBackup */ GLuint i; const GLuint texUnits = ctx->Const.MaxTextureUnits; SWcontext *swrast = SWRAST_CONTEXT(ctx); - + if ( (swrast->_RasterMask & MULTI_DRAW_BIT) || texUnits > 1) { /* must make a copy of the colors since they may be modified */ - MEMCPY(rgbaBackup, rgbaIn, 4 * n * sizeof(GLchan)); + MEMCPY(rgbaBackup, span->color.rgba, 4 * span->end * sizeof(GLchan)); rgba = rgbaBackup; } else { - rgba = rgbaIn; + rgba = span->color.rgba; } - - + + ASSERT(ctx->Texture._ReallyEnabled); for (i = 0; i < texUnits; i++) - _swrast_texture_fragments( ctx, i, n, s[i], t[i], u[i], lambda[i], - (CONST GLchan (*)[4]) rgbaIn, rgba ); + _swrast_texture_fragments( ctx, i, span, rgba ); /* Texture with alpha test */ if (ctx->Color.AlphaEnabled) { /* Do the alpha test */ - if (_mesa_alpha_test( ctx, n, (const GLchan (*)[4])rgba, mask ) == 0) { + if (_mesa_alpha_test( ctx, span->end, (const GLchan (*)[4])rgba, span->mask ) == 0) { return; } - write_all = GL_FALSE; + span->write_all = GL_FALSE; /* Depth test usually in 'rasterize_span' but if alpha test needed, we have to wait for that test before depth test can be done. */ if (ctx->Stencil.Enabled) { - /* first stencil test */ - if (_mesa_stencil_and_ztest_span(ctx, n, x, y, z, mask) == GL_FALSE) { - return; - } - write_all = GL_FALSE; + /* first stencil test */ + if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE) + return; } else if (ctx->Depth.Test) { - /* regular depth testing */ - GLuint m = _mesa_depth_test_span( ctx, n, x, y, z, mask ); - if (m == 0) { - return; - } - if (m < n) { - write_all = GL_FALSE; - } + /* regular depth testing */ + if (_mesa_depth_test_span(ctx, span) == GL_FALSE) + return; } } /* if we get here, something passed the depth test */ ctx->OcclusionResult = GL_TRUE; - - + + /* Add base and specular colors */ - if (spec && + if ((span->activeMask & SPAN_SPEC) && /* Is this right test ???*/ (ctx->Fog.ColorSumEnabled || (ctx->Light.Enabled && ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR))) - add_colors( n, rgba, spec ); /* rgba = rgba + spec */ - + add_colors(span, rgba); /* rgba = rgba + spec */ + /* Per-pixel fog */ if (ctx->Fog.Enabled) { - if (fog && !swrast->_PreferPixelFog) - _mesa_fog_rgba_pixels( ctx, n, fog, rgba ); + /* Is this the right 'if' ?? */ + if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog) + _mesa_fog_rgba_pixels( ctx, span, rgba ); else - _mesa_depth_fog_rgba_pixels( ctx, n, z, rgba ); + _mesa_depth_fog_rgba_pixels( ctx, span, rgba ); } - + /* Antialias coverage application */ - if (coverage) { +#if 0 + if (span->coverage) { GLuint i; - for (i = 0; i < n; i++) { - rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * coverage[i]); + for (i = 0; i < span->end; i++) { + rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * span->coverage[i]); } } +#endif if (swrast->_RasterMask & MULTI_DRAW_BIT) { - multi_write_rgba_span( ctx, n, x, y, (const GLchan (*)[4]) rgba, mask ); + multi_write_rgba_span( ctx, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, span->mask ); } else { /* normal: write to exactly one buffer */ const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask); - + if (ctx->Color.ColorLogicOpEnabled) { - _mesa_logicop_rgba_span( ctx, n, x, y, rgba, mask ); + _mesa_logicop_rgba_span( ctx, span->end, span->x, span->y, rgba, span->mask ); } else if (ctx->Color.BlendEnabled) { - _mesa_blend_span( ctx, n, x, y, rgba, mask ); + _mesa_blend_span( ctx, span->end, span->x, span->y, rgba, span->mask ); } if (colorMask == 0x0) { return; } else if (colorMask != 0xffffffff) { - _mesa_mask_rgba_span( ctx, n, x, y, rgba ); + _mesa_mask_rgba_span( ctx, span->end, span->x, span->y, rgba ); } - (*swrast->Driver.WriteRGBASpan)( ctx, n, x, y, (const GLchan (*)[4])rgba, - write_all ? NULL : mask ); + (*swrast->Driver.WriteRGBASpan)( ctx, span->end, span->x, span->y, (const GLchan (*)[4])rgba, + span->write_all ? NULL : span->mask ); if (swrast->_RasterMask & ALPHABUF_BIT) { - _mesa_write_alpha_span( ctx, n, x, y, (const GLchan (*)[4])rgba, - write_all ? NULL : mask ); + _mesa_write_alpha_span( ctx, span->end, span->x, span->y, (const GLchan (*)[4])rgba, + span->write_all ? NULL : span->mask ); } } } @@ -1065,76 +1448,40 @@ masked_multitexture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, * Contributed by Klaus Niederkrueger. */ void -_mesa_rasterize_span(GLcontext *ctx, struct triangle_span *span) +_mesa_rasterize_span(GLcontext *ctx, struct sw_span *span) { - DEFARRAY(GLubyte, mask, MAX_WIDTH); - DEFMARRAY(GLchan, rgba, MAX_WIDTH, 4); - DEFMARRAY(GLchan, spec, MAX_WIDTH, 4); - DEFARRAY(GLuint, index, MAX_WIDTH); - DEFARRAY(GLuint, z, MAX_WIDTH); - DEFARRAY(GLfloat, fog, MAX_WIDTH); - DEFARRAY(GLfloat, sTex, MAX_WIDTH); - DEFARRAY(GLfloat, tTex, MAX_WIDTH); - DEFARRAY(GLfloat, rTex, MAX_WIDTH); - DEFARRAY(GLfloat, lambda, MAX_WIDTH); - DEFMARRAY(GLfloat, msTex, MAX_TEXTURE_UNITS, MAX_WIDTH); - DEFMARRAY(GLfloat, mtTex, MAX_TEXTURE_UNITS, MAX_WIDTH); - DEFMARRAY(GLfloat, mrTex, MAX_TEXTURE_UNITS, MAX_WIDTH); - DEFMARRAY(GLfloat, mLambda, MAX_TEXTURE_UNITS, MAX_WIDTH); - - GLboolean write_all = GL_TRUE; SWcontext *swrast = SWRAST_CONTEXT(ctx); - CHECKARRAY(mask, return); - CHECKARRAY(rgba, return); - CHECKARRAY(spec, return); - CHECKARRAY(index, return); - CHECKARRAY(z, return); - CHECKARRAY(fog, return); - CHECKARRAY(sTex, return); - CHECKARRAY(tTex, return); - CHECKARRAY(rTex, return); - CHECKARRAY(lambda, return); - CHECKARRAY(msTex, return); - CHECKARRAY(mtTex, return); - CHECKARRAY(mrTex, return); - CHECKARRAY(mLambda, return); + SET_MASK_TO_ONE(span); - /* init mask to 1's (all pixels are to be written) */ - MEMSET(mask, 1, span->count); if (swrast->_RasterMask & WINCLIP_BIT) { - if ((span->count = clip_span(ctx, span->count, span->x, span->y, mask)) - == 0) { + if (clip_span(ctx, span) == GL_FALSE) { return; } - if (mask[0] == 0) - write_all = GL_FALSE; } /* Do the scissor test */ if (ctx->Scissor.Enabled) { - if ((span->count = _mesa_scissor_span(ctx, span->count, span->x, span->y, mask )) == 0) { + if (_mesa_scissor_span( ctx, span ) == GL_FALSE) { return; } - if (mask[0] == 0) - write_all = GL_FALSE; } /* Polygon Stippling */ if (ctx->Polygon.StippleFlag) { - stipple_polygon_span( ctx, span->count, span->x, span->y, mask ); - write_all = GL_FALSE; + stipple_polygon_span( ctx, span ); } - - + /* I have to think where to put this!! */ if (span->activeMask & SPAN_Z) { + SW_SPAN_SET_FLAG(span->filledDepth); + if (ctx->Visual.depthBits <= 16) { GLuint i; GLfixed zval = span->z; - for (i = 0; i < span->count; i++) { - z[i] = FixedToInt(zval); + for (i = 0; i < span->end; i++) { + span->depth[i] = FixedToInt(zval); zval += span->zStep; } } @@ -1142,8 +1489,8 @@ _mesa_rasterize_span(GLcontext *ctx, struct triangle_span *span) /* Deep Z buffer, no fixed->int shift */ GLuint i; GLfixed zval = span->z; - for (i = 0; i < span->count; i++) { - z[i] = zval; + for (i = 0; i < span->end; i++) { + span->depth[i] = zval; zval += span->zStep; } } @@ -1153,29 +1500,23 @@ _mesa_rasterize_span(GLcontext *ctx, struct triangle_span *span) no alpha test needed, we can do here the depth test and potentially avoid some of the texturing (otherwise alpha test, depth test etc. happens in masked_texture_span(). */ - if (!ctx->Color.AlphaEnabled) { + if (span->activeMask & SPAN_Z && !ctx->Color.AlphaEnabled) { if (ctx->Stencil.Enabled) { /* first stencil test */ - if (_mesa_stencil_and_ztest_span(ctx, span->count, span->x, - span->y, z, mask) == GL_FALSE) { + if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE) return; - } - write_all = GL_FALSE; } else if (ctx->Depth.Test) { /* regular depth testing */ - GLuint m = _mesa_depth_test_span( ctx, span->count, span->x, - span->y, z, mask ); - if (m == 0) { - return; - } - if (m < span->count) { - write_all = GL_FALSE; + if (_mesa_depth_test_span( ctx, span) == 0) { + return; } } } if (span->activeMask & SPAN_RGBA) { + ASSERT(span->filledColor == GL_FALSE); + SW_SPAN_SET_FLAG(span->filledColor); if (span->activeMask & SPAN_FLAT) { GLuint i; GLchan color[4]; @@ -1183,8 +1524,8 @@ _mesa_rasterize_span(GLcontext *ctx, struct triangle_span *span) color[GCOMP] = FixedToChan(span->green); color[BCOMP] = FixedToChan(span->blue); color[ACOMP] = FixedToChan(span->alpha); - for (i = 0; i < span->count; i++) { - COPY_CHAN4(rgba[i], color); + for (i = 0; i < span->end; i++) { + COPY_CHAN4(span->color.rgba[i], color); } } else { @@ -1201,11 +1542,11 @@ _mesa_rasterize_span(GLcontext *ctx, struct triangle_span *span) GLfixed a = span->alpha; #endif GLuint i; - for (i = 0; i < span->count; i++) { - rgba[i][RCOMP] = FixedToChan(r); - rgba[i][GCOMP] = FixedToChan(g); - rgba[i][BCOMP] = FixedToChan(b); - rgba[i][ACOMP] = FixedToChan(a); + for (i = 0; i < span->end; i++) { + span->color.rgba[i][RCOMP] = FixedToChan(r); + span->color.rgba[i][GCOMP] = FixedToChan(g); + span->color.rgba[i][BCOMP] = FixedToChan(b); + span->color.rgba[i][ACOMP] = FixedToChan(a); r += span->redStep; g += span->greenStep; b += span->blueStep; @@ -1215,15 +1556,16 @@ _mesa_rasterize_span(GLcontext *ctx, struct triangle_span *span) } if (span->activeMask & SPAN_SPEC) { + SW_SPAN_SET_FLAG(span->filledSpecular); if (span->activeMask & SPAN_FLAT) { const GLchan r = FixedToChan(span->specRed); const GLchan g = FixedToChan(span->specGreen); const GLchan b = FixedToChan(span->specBlue); GLuint i; - for (i = 0; i < span->count; i++) { - spec[i][RCOMP] = r; - spec[i][GCOMP] = g; - spec[i][BCOMP] = b; + for (i = 0; i < span->end; i++) { + span->specular[i][RCOMP] = r; + span->specular[i][GCOMP] = g; + span->specular[i][BCOMP] = b; } } else { @@ -1238,10 +1580,10 @@ _mesa_rasterize_span(GLcontext *ctx, struct triangle_span *span) GLfixed b = span->specBlue; #endif GLuint i; - for (i = 0; i < span->count; i++) { - spec[i][RCOMP] = FixedToChan(r); - spec[i][GCOMP] = FixedToChan(g); - spec[i][BCOMP] = FixedToChan(b); + for (i = 0; i < span->end; i++) { + span->specular[i][RCOMP] = FixedToChan(r); + span->specular[i][GCOMP] = FixedToChan(g); + span->specular[i][BCOMP] = FixedToChan(b); r += span->specRedStep; g += span->specGreenStep; b += span->specBlueStep; @@ -1250,32 +1592,25 @@ _mesa_rasterize_span(GLcontext *ctx, struct triangle_span *span) } if (span->activeMask & SPAN_INDEX) { + SW_SPAN_SET_FLAG(span->filledColor); if (span->activeMask & SPAN_FLAT) { GLuint i; const GLint indx = FixedToInt(span->index); - for (i = 0; i < span->count; i++) { - index[i] = indx; + for (i = 0; i < span->end; i++) { + span->color.index[i] = indx; } } else { /* smooth interpolation */ GLuint i; GLfixed ind = span->index; - for (i = 0; i < span->count; i++) { - index[i] = FixedToInt(ind); + for (i = 0; i < span->end; i++) { + span->color.index[i] = FixedToInt(ind); ind += span->indexStep; } } } - if (span->activeMask & SPAN_FOG) { - GLuint i; - GLfloat f = span->fog; - for (i = 0; i < span->count; i++) { - fog[i] = f; - f += span->fogStep; - } - } if (span->activeMask & SPAN_TEXTURE) { if (ctx->Texture._ReallyEnabled & ~TEXTURE0_ANY) { /* multitexture */ @@ -1284,54 +1619,64 @@ _mesa_rasterize_span(GLcontext *ctx, struct triangle_span *span) GLuint u; /* multitexture, lambda */ for (u = 0; u < MAX_TEXTURE_UNITS; u++) { - if (ctx->Texture.Unit[u]._ReallyEnabled) { + if (ctx->Texture.Unit[u]._ReallyEnabled) { GLfloat s = span->tex[u][0]; GLfloat t = span->tex[u][1]; GLfloat r = span->tex[u][2]; GLfloat q = span->tex[u][3]; GLuint i; - for (i = 0; i < span->count; i++) { - const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q); - msTex[u][i] = s * invQ; - mtTex[u][i] = t * invQ; - mrTex[u][i] = r * invQ; - mLambda[u][i] = (GLfloat) - (log(span->rho[u] * invQ * invQ) * 1.442695F * 0.5F); - s += span->texStep[u][0]; - t += span->texStep[u][1]; - r += span->texStep[u][2]; - q += span->texStep[u][3]; + SW_SPAN_SET_FLAG(span->filledLambda[u]); + SW_SPAN_SET_FLAG(span->filledTex[u]); + for (i = 0; i < span->end; i++) { + const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q); + span->texcoords[u][i][0] = s * invQ; + span->texcoords[u][i][1] = t * invQ; + span->texcoords[u][i][2] = r * invQ; + span->lambda[u][i] = (GLfloat) + (log(span->rho[u] * invQ * invQ) * 1.442695F * 0.5F); + s += span->texStep[u][0]; + t += span->texStep[u][1]; + r += span->texStep[u][2]; + q += span->texStep[u][3]; } - } - } + } + } } else { /* without lambda */ GLuint u; /* multitexture, no lambda */ for (u = 0; u < MAX_TEXTURE_UNITS; u++) { - if (ctx->Texture.Unit[u]._ReallyEnabled) { + if (ctx->Texture.Unit[u]._ReallyEnabled) { GLfloat s = span->tex[u][0]; GLfloat t = span->tex[u][1]; GLfloat r = span->tex[u][2]; GLfloat q = span->tex[u][3]; GLuint i; - for (i = 0; i < span->count; i++) { - const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q); - msTex[u][i] = s * invQ; - mtTex[u][i] = t * invQ; - mrTex[u][i] = r * invQ; - s += span->texStep[u][0]; - t += span->texStep[u][1]; - r += span->texStep[u][2]; - q += span->texStep[u][3]; + SW_SPAN_SET_FLAG(span->filledTex[u]); + for (i = 0; i < span->end; i++) { + const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q); + span->texcoords[u][i][0] = s * invQ; + span->texcoords[u][i][1] = t * invQ; + span->texcoords[u][i][2] = r * invQ; + s += span->texStep[u][0]; + t += span->texStep[u][1]; + r += span->texStep[u][2]; + q += span->texStep[u][3]; } - } - } + } + } } } else { /* just texture unit 0 */ +#ifdef DEBUG + {GLint i; + for (i=0; i<MAX_TEXTURE_UNITS; i++) { + ASSERT(span->filledTex[i] == GL_FALSE && + span->filledLambda[i] == GL_FALSE); + }} +#endif if (span->activeMask & SPAN_LAMBDA) { /* with lambda */ GLfloat s = span->tex[0][0]; @@ -1339,19 +1684,21 @@ _mesa_rasterize_span(GLcontext *ctx, struct triangle_span *span) GLfloat r = span->tex[0][2]; GLfloat q = span->tex[0][3]; GLuint i; + SW_SPAN_SET_FLAG(span->filledLambda[0]); + SW_SPAN_SET_FLAG(span->filledTex[0]); /* single texture, lambda */ - for (i = 0; i < span->count; i++) { - const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q); - sTex[i] = s * invQ; - tTex[i] = t * invQ; - rTex[i] = r * invQ; - lambda[i] = (GLfloat) - (log(span->rho[0] * invQ * invQ) * 1.442695F * 0.5F); - s += span->texStep[0][0]; - t += span->texStep[0][1]; - r += span->texStep[0][2]; - q += span->texStep[0][3]; - } + for (i = 0; i < span->end; i++) { + const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q); + span->texcoords[0][i][0] = s * invQ; + span->texcoords[0][i][1] = t * invQ; + span->texcoords[0][i][2] = r * invQ; + span->lambda[0][i] = (GLfloat) + (log(span->rho[0] * invQ * invQ) * 1.442695F * 0.5F); + s += span->texStep[0][0]; + t += span->texStep[0][1]; + r += span->texStep[0][2]; + q += span->texStep[0][3]; + } } else { /* without lambda */ @@ -1360,98 +1707,75 @@ _mesa_rasterize_span(GLcontext *ctx, struct triangle_span *span) GLfloat r = span->tex[0][2]; GLfloat q = span->tex[0][3]; GLuint i; + SW_SPAN_SET_FLAG(span->filledTex[0]); /* single texture, no lambda */ - for (i = 0; i < span->count; i++) { - const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q); - sTex[i] = s * invQ; - tTex[i] = t * invQ; - rTex[i] = r * invQ; - s += span->texStep[0][0]; - t += span->texStep[0][1]; - r += span->texStep[0][2]; - q += span->texStep[0][3]; + for (i = 0; i < span->end; i++) { + const GLfloat invQ = (q == 0.0F) ? 1.0F : (1.0F / q); + span->texcoords[0][i][0] = s * invQ; + span->texcoords[0][i][1] = t * invQ; + span->texcoords[0][i][2] = r * invQ; + s += span->texStep[0][0]; + t += span->texStep[0][1]; + r += span->texStep[0][2]; + q += span->texStep[0][3]; } } } } /* XXX keep this? */ if (span->activeMask & SPAN_INT_TEXTURE) { - GLint intTexcoord[MAX_WIDTH][2]; GLfixed s = span->intTex[0]; GLfixed t = span->intTex[1]; GLuint i; - for (i = 0; i < span->count; i++) { - intTexcoord[i][0] = FixedToInt(s); - intTexcoord[i][1] = FixedToInt(t); + for (i = 0; i < span->end; i++) { + span->itexcoords[i][0] = FixedToInt(s); + span->itexcoords[i][1] = FixedToInt(t); s += span->intTexStep[0]; t += span->intTexStep[1]; } } - + /* examine activeMask and call a s_span.c function */ if (span->activeMask & SPAN_TEXTURE) { - const GLfloat *fogPtr; - if (span->activeMask & SPAN_FOG) - fogPtr = fog; - else - fogPtr = NULL; if (ctx->Texture._ReallyEnabled & ~TEXTURE0_ANY) { - if (span->activeMask & SPAN_SPEC) { - masked_multitexture_span(ctx, span->count, span->x, span->y, - z, fogPtr, - (const GLfloat (*)[MAX_WIDTH]) msTex, - (const GLfloat (*)[MAX_WIDTH]) mtTex, - (const GLfloat (*)[MAX_WIDTH]) mrTex, - (GLfloat (*)[MAX_WIDTH]) mLambda, - rgba, (CONST GLchan (*)[4]) spec, - NULL, mask, write_all ); - } - else { - masked_multitexture_span(ctx, span->count, span->x, span->y, - z, fogPtr, - (const GLfloat (*)[MAX_WIDTH]) msTex, - (const GLfloat (*)[MAX_WIDTH]) mtTex, - (const GLfloat (*)[MAX_WIDTH]) mrTex, - (GLfloat (*)[MAX_WIDTH]) mLambda, - rgba, NULL, NULL, mask, write_all ); - } + /* multi texture */ + masked_multitexture_span(ctx, span); } else { /* single texture */ - if (span->activeMask & SPAN_SPEC) { - masked_texture_span(ctx, span->count, span->x, span->y, - z, fogPtr, sTex, tTex, rTex, - lambda, rgba, - (CONST GLchan (*)[4]) spec, - NULL, mask, write_all); - } - else { - masked_texture_span(ctx, span->count, span->x, span->y, - z, fogPtr, sTex, tTex, rTex, - lambda, rgba, NULL, NULL, - mask, write_all); - } + masked_texture_span(ctx, span); } } else { _mesa_problem(ctx, "rasterize_span() should only be used for texturing"); } - UNDEFARRAY(mask); - UNDEFARRAY(rgba); - UNDEFARRAY(spec); - UNDEFARRAY(index); - UNDEFARRAY(z); - UNDEFARRAY(fog); - UNDEFARRAY(sTex); - UNDEFARRAY(tTex); - UNDEFARRAY(rTex); - UNDEFARRAY(lambda); - UNDEFARRAY(msTex); - UNDEFARRAY(mtTex); - UNDEFARRAY(mrTex); - UNDEFARRAY(mLambda); +} + +/* + * Add specular color to base color. This is used only when + * GL_LIGHT_MODEL_COLOR_CONTROL = GL_SEPARATE_SPECULAR_COLOR. + */ +static void +_old_add_colors(GLuint n, GLchan rgba[][4], GLchan specular[][4] ) +{ + GLuint i; + for (i = 0; i < n; i++) { +#if CHAN_TYPE == GL_FLOAT + /* no clamping */ + rgba[i][RCOMP] += specular[i][RCOMP]; + rgba[i][GCOMP] += specular[i][GCOMP]; + rgba[i][BCOMP] += specular[i][BCOMP]; +#else + GLint r = rgba[i][RCOMP] + specular[i][RCOMP]; + GLint g = rgba[i][GCOMP] + specular[i][GCOMP]; + GLint b = rgba[i][BCOMP] + specular[i][BCOMP]; + rgba[i][RCOMP] = (GLchan) MIN2(r, CHAN_MAX); + rgba[i][GCOMP] = (GLchan) MIN2(g, CHAN_MAX); + rgba[i][BCOMP] = (GLchan) MIN2(b, CHAN_MAX); +#endif + } } @@ -1470,12 +1794,12 @@ _mesa_rasterize_span(GLcontext *ctx, struct triangle_span *span) * primitive - either GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP. */ void -_mesa_write_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLdepth z[], const GLfloat fog[], - const GLfloat s[], const GLfloat t[], - const GLfloat u[], GLfloat lambda[], - GLchan rgbaIn[][4], CONST GLchan spec[][4], - const GLfloat coverage[], GLenum primitive ) +_old_write_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, + const GLdepth z[], const GLfloat fog[], + GLfloat texcoord[][3], + GLfloat lambda[], + GLchan rgbaIn[][4], GLchan spec[][4], + const GLfloat coverage[], GLenum primitive ) { const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask); GLubyte mask[MAX_WIDTH]; @@ -1488,7 +1812,7 @@ _mesa_write_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, MEMSET(mask, 1, n); if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) { - if ((n=clip_span(ctx, n, x, y, mask)) == 0) { + if ((n=old_clip_span(ctx, n, x, y, mask)) == 0) { return; } if (mask[0] == 0) @@ -1507,7 +1831,7 @@ _mesa_write_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, /* Do the scissor test */ if (ctx->Scissor.Enabled) { - if ((n = _mesa_scissor_span( ctx, n, x, y, mask )) == 0) { + if ((n = _old_scissor_span( ctx, n, x, y, mask )) == 0) { return; } if (mask[0] == 0) @@ -1516,7 +1840,7 @@ _mesa_write_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, /* Polygon Stippling */ if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) { - stipple_polygon_span( ctx, n, x, y, mask ); + old_stipple_polygon_span( ctx, n, x, y, mask ); write_all = GL_FALSE; } @@ -1525,7 +1849,7 @@ _mesa_write_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, /* Texturing without alpha is done after depth-testing which gives a potential speed-up. */ ASSERT(ctx->Texture._ReallyEnabled); - _swrast_texture_fragments( ctx, 0, n, s, t, u, lambda, + _old_swrast_texture_fragments( ctx, 0, n, texcoord, lambda, (CONST GLchan (*)[4]) rgba, rgba ); /* Do the alpha test */ @@ -1537,14 +1861,14 @@ _mesa_write_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, if (ctx->Stencil.Enabled) { /* first stencil test */ - if (_mesa_stencil_and_ztest_span(ctx, n, x, y, z, mask) == GL_FALSE) { + if (_old_stencil_and_ztest_span(ctx, n, x, y, z, mask) == GL_FALSE) { return; } write_all = GL_FALSE; } else if (ctx->Depth.Test) { /* regular depth testing */ - GLuint m = _mesa_depth_test_span( ctx, n, x, y, z, mask ); + GLuint m = _old_depth_test_span( ctx, n, x, y, z, mask ); if (m == 0) { return; } @@ -1559,7 +1883,7 @@ _mesa_write_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, /* Texture without alpha test */ if (! ctx->Color.AlphaEnabled) { ASSERT(ctx->Texture._ReallyEnabled); - _swrast_texture_fragments( ctx, 0, n, s, t, u, lambda, + _old_swrast_texture_fragments( ctx, 0, n, texcoord, lambda, (CONST GLchan (*)[4]) rgba, rgba ); } @@ -1568,14 +1892,14 @@ _mesa_write_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, (ctx->Fog.ColorSumEnabled || (ctx->Light.Enabled && ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR))) - add_colors( n, rgba, spec ); /* rgba = rgba + spec */ + _old_add_colors( n, rgba, spec ); /* rgba = rgba + spec */ /* Per-pixel fog */ if (ctx->Fog.Enabled) { if (fog && !swrast->_PreferPixelFog) - _mesa_fog_rgba_pixels( ctx, n, fog, rgba ); + _old_fog_rgba_pixels( ctx, n, fog, rgba ); else - _mesa_depth_fog_rgba_pixels( ctx, n, z, rgba ); + _old_depth_fog_rgba_pixels( ctx, n, z, rgba ); } /* Antialias coverage application */ @@ -1619,16 +1943,14 @@ _mesa_write_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, * As above but perform multiple stages of texture application. */ void -_mesa_write_multitexture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLdepth z[], const GLfloat fog[], - CONST GLfloat s[MAX_TEXTURE_UNITS][MAX_WIDTH], - CONST GLfloat t[MAX_TEXTURE_UNITS][MAX_WIDTH], - CONST GLfloat u[MAX_TEXTURE_UNITS][MAX_WIDTH], - GLfloat lambda[][MAX_WIDTH], - GLchan rgbaIn[MAX_TEXTURE_UNITS][4], - CONST GLchan spec[MAX_TEXTURE_UNITS][4], - const GLfloat coverage[], - GLenum primitive ) +_old_write_multitexture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, + const GLdepth z[], const GLfloat fog[], + GLfloat texcoord[MAX_TEXTURE_UNITS][MAX_WIDTH][3], + GLfloat lambda[][MAX_WIDTH], + GLchan rgbaIn[MAX_TEXTURE_UNITS][4], + GLchan spec[MAX_TEXTURE_UNITS][4], + const GLfloat coverage[], + GLenum primitive ) { GLubyte mask[MAX_WIDTH]; GLboolean write_all = GL_TRUE; @@ -1643,7 +1965,7 @@ _mesa_write_multitexture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, MEMSET(mask, 1, n); if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) { - if ((n=clip_span(ctx, n, x, y, mask)) == 0) { + if ((n=old_clip_span(ctx, n, x, y, mask)) == 0) { return; } if (mask[0] == 0) @@ -1663,7 +1985,7 @@ _mesa_write_multitexture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, /* Do the scissor test */ if (ctx->Scissor.Enabled) { - if ((n = _mesa_scissor_span( ctx, n, x, y, mask )) == 0) { + if ((n = _old_scissor_span( ctx, n, x, y, mask )) == 0) { return; } if (mask[0] == 0) @@ -1672,7 +1994,7 @@ _mesa_write_multitexture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, /* Polygon Stippling */ if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) { - stipple_polygon_span( ctx, n, x, y, mask ); + old_stipple_polygon_span( ctx, n, x, y, mask ); write_all = GL_FALSE; } @@ -1683,7 +2005,7 @@ _mesa_write_multitexture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, */ ASSERT(ctx->Texture._ReallyEnabled); for (i = 0; i < texUnits; i++) - _swrast_texture_fragments( ctx, i, n, s[i], t[i], u[i], lambda[i], + _old_swrast_texture_fragments( ctx, i, n, texcoord[i], lambda[i], (CONST GLchan (*)[4]) rgbaIn, rgba ); /* Do the alpha test */ @@ -1695,14 +2017,14 @@ _mesa_write_multitexture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, if (ctx->Stencil.Enabled) { /* first stencil test */ - if (_mesa_stencil_and_ztest_span(ctx, n, x, y, z, mask) == GL_FALSE) { + if (_old_stencil_and_ztest_span(ctx, n, x, y, z, mask) == GL_FALSE) { return; } write_all = GL_FALSE; } else if (ctx->Depth.Test) { /* regular depth testing */ - GLuint m = _mesa_depth_test_span( ctx, n, x, y, z, mask ); + GLuint m = _old_depth_test_span( ctx, n, x, y, z, mask ); if (m == 0) { return; } @@ -1718,7 +2040,7 @@ _mesa_write_multitexture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, if (! ctx->Color.AlphaEnabled) { ASSERT(ctx->Texture._ReallyEnabled); for (i = 0; i < texUnits; i++) - _swrast_texture_fragments( ctx, i, n, s[i], t[i], u[i], lambda[i], + _old_swrast_texture_fragments( ctx, i, n, texcoord[i], lambda[i], (CONST GLchan (*)[4]) rgbaIn, rgba ); } @@ -1727,14 +2049,14 @@ _mesa_write_multitexture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, (ctx->Fog.ColorSumEnabled || (ctx->Light.Enabled && ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR))) - add_colors( n, rgba, spec ); /* rgba = rgba + spec */ + _old_add_colors( n, rgba, spec ); /* rgba = rgba + spec */ /* Per-pixel fog */ if (ctx->Fog.Enabled) { if (fog && !swrast->_PreferPixelFog) - _mesa_fog_rgba_pixels( ctx, n, fog, rgba ); + _old_fog_rgba_pixels( ctx, n, fog, rgba ); else - _mesa_depth_fog_rgba_pixels( ctx, n, z, rgba ); + _old_depth_fog_rgba_pixels( ctx, n, z, rgba ); } /* Antialias coverage application */ diff --git a/src/mesa/swrast/s_span.h b/src/mesa/swrast/s_span.h index 522ec93329c..b6bb7d8343d 100644 --- a/src/mesa/swrast/s_span.h +++ b/src/mesa/swrast/s_span.h @@ -1,4 +1,4 @@ -/* $Id: s_span.h,v 1.7 2001/11/19 01:18:28 brianp Exp $ */ +/* $Id: s_span.h,v 1.8 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -31,58 +31,55 @@ #include "mtypes.h" #include "swrast.h" -#include "s_trispan.h" extern void -_mesa_write_index_span( GLcontext *ctx, GLuint n, GLint x, GLint y, +_old_write_index_span( GLcontext *ctx, GLuint n, GLint x, GLint y, const GLdepth z[], const GLfloat fog[], GLuint index[], const GLint coverage[], GLenum primitive ); - extern void -_mesa_write_monoindex_span( GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLdepth z[], const GLfloat fog[], - GLuint index, const GLint coverage[], - GLenum primitive ); - - -extern void -_mesa_write_rgba_span( GLcontext *ctx, GLuint n, GLint x, GLint y, +_old_write_rgba_span( GLcontext *ctx, GLuint n, GLint x, GLint y, const GLdepth z[], const GLfloat fog[], GLchan rgba[][4], const GLfloat coverage[], GLenum primitive ); +void +_mesa_write_index_span( GLcontext *ctx, struct sw_span *span, + GLenum primitive); + +extern void +_mesa_write_monoindex_span( GLcontext *ctx, struct sw_span *span, + GLuint index, GLenum primitive ); + +extern void +_mesa_write_rgba_span( GLcontext *ctx, struct sw_span *span, + GLenum primitive ); extern void -_mesa_write_monocolor_span( GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLdepth z[], const GLfloat fog[], - const GLchan color[4], const GLfloat coverage[], - GLenum primitive ); +_mesa_write_monocolor_span( GLcontext *ctx, struct sw_span *span, + const GLchan color[4], GLenum primitive ); extern void -_mesa_rasterize_span(GLcontext *ctx, struct triangle_span *span); +_mesa_rasterize_span(GLcontext *ctx, struct sw_span *span); extern void -_mesa_write_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, - const GLdepth z[], const GLfloat fog[], - const GLfloat s[], const GLfloat t[], - const GLfloat u[], GLfloat lambda[], - GLchan rgba[][4], CONST GLchan spec[][4], - const GLfloat coverage[], GLenum primitive ); +_old_write_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, + const GLdepth z[], const GLfloat fog[], + GLfloat texcoord[][3], GLfloat lambda[], + GLchan rgba[][4], GLchan spec[][4], + const GLfloat coverage[], GLenum primitive ); extern void -_mesa_write_multitexture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, +_old_write_multitexture_span( GLcontext *ctx, GLuint n, GLint x, GLint y, const GLdepth z[], const GLfloat fog[], - CONST GLfloat s[MAX_TEXTURE_UNITS][MAX_WIDTH], - CONST GLfloat t[MAX_TEXTURE_UNITS][MAX_WIDTH], - CONST GLfloat u[MAX_TEXTURE_UNITS][MAX_WIDTH], + GLfloat texcoord[MAX_TEXTURE_UNITS][MAX_WIDTH][3], GLfloat lambda[MAX_TEXTURE_UNITS][MAX_WIDTH], - GLchan rgba[][4], CONST GLchan spec[][4], + GLchan rgba[][4], GLchan spec[][4], const GLfloat coverage[], GLenum primitive ); diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c index 1a80cc1b430..488ccc0559f 100644 --- a/src/mesa/swrast/s_stencil.c +++ b/src/mesa/swrast/s_stencil.c @@ -1,4 +1,4 @@ -/* $Id: s_stencil.c,v 1.12 2001/05/17 20:18:45 brianp Exp $ */ +/* $Id: s_stencil.c,v 1.13 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -457,7 +457,7 @@ stencil_and_ztest_span( GLcontext *ctx, GLuint n, GLint x, GLint y, MEMCPY(oldmask, mask, n * sizeof(GLubyte)); /* apply the depth test */ - _mesa_depth_test_span(ctx, n, x, y, z, mask); + _old_depth_test_span(ctx, n, x, y, z, mask); /* Set the stencil pass/fail flags according to result of depth testing. * if oldmask[i] == 0 then @@ -502,7 +502,7 @@ stencil_and_ztest_span( GLcontext *ctx, GLuint n, GLint x, GLint y, * */ GLboolean -_mesa_stencil_and_ztest_span( GLcontext *ctx, GLuint n, GLint x, GLint y, +_old_stencil_and_ztest_span( GLcontext *ctx, GLuint n, GLint x, GLint y, const GLdepth z[], GLubyte mask[] ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); @@ -536,6 +536,61 @@ _mesa_stencil_and_ztest_span( GLcontext *ctx, GLuint n, GLint x, GLint y, return result; } +/* + * Apply stencil and depth testing to the span of pixels. + * Both software and hardware stencil buffers are acceptable. + * Input: n - number of pixels in the span + * x, y - location of leftmost pixel in span + * z - array [n] of z values + * mask - array [n] of flags (1=test this pixel, 0=skip the pixel) + * Output: mask - array [n] of flags (1=stencil and depth test passed) + * Return: GL_TRUE - all fragments failed the testing + * GL_FALSE - one or more fragments passed the testing + * + */ +GLboolean +_mesa_stencil_and_ztest_span(GLcontext *ctx, struct sw_span *span) +{ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + + GLstencil stencilRow[MAX_WIDTH]; + GLstencil *stencil; + GLboolean result; + + ASSERT(ctx->Stencil.Enabled); + ASSERT(span->end <= MAX_WIDTH); + ASSERT(span->filledMask == GL_TRUE); + ASSERT(span->filledDepth == GL_TRUE); + SW_SPAN_SET_FLAG(span->testedDepth); + + + /* Get initial stencil values */ + if (swrast->Driver.WriteStencilSpan) { + ASSERT(swrast->Driver.ReadStencilSpan); + /* Get stencil values from the hardware stencil buffer */ + (*swrast->Driver.ReadStencilSpan)(ctx, span->end, span->x, span->y, stencilRow); + stencil = stencilRow; + } + else { + /* software stencil buffer */ + stencil = STENCIL_ADDRESS(span->x, span->y); + } + + /* do all the stencil/depth testing/updating */ + result = stencil_and_ztest_span( ctx, span->end, span->x, span->y, + span->depth, stencil, span->mask ); + + if (swrast->Driver.WriteStencilSpan) { + /* Write updated stencil values into hardware stencil buffer */ + (swrast->Driver.WriteStencilSpan)(ctx, span->end, span->x, + span->y, stencil, span->mask ); + } + + span->write_all = GL_FALSE; + + return result; +} + diff --git a/src/mesa/swrast/s_stencil.h b/src/mesa/swrast/s_stencil.h index 30394a90594..a8a3e3325e6 100644 --- a/src/mesa/swrast/s_stencil.h +++ b/src/mesa/swrast/s_stencil.h @@ -1,4 +1,4 @@ -/* $Id: s_stencil.h,v 1.3 2001/03/12 00:48:42 gareth Exp $ */ +/* $Id: s_stencil.h,v 1.4 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -34,8 +34,11 @@ extern GLboolean -_mesa_stencil_and_ztest_span( GLcontext *ctx, GLuint n, GLint x, GLint y, +_old_stencil_and_ztest_span( GLcontext *ctx, GLuint n, GLint x, GLint y, const GLdepth z[], GLubyte mask[] ); +extern GLboolean +_mesa_stencil_and_ztest_span(GLcontext *ctx, struct sw_span *span); + extern GLboolean _mesa_stencil_and_ztest_pixels( GLcontext *ctx, GLuint n, diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c index b849e191773..573888d727b 100644 --- a/src/mesa/swrast/s_texture.c +++ b/src/mesa/swrast/s_texture.c @@ -1,4 +1,4 @@ -/* $Id: s_texture.c,v 1.43 2001/12/04 23:44:56 brianp Exp $ */ +/* $Id: s_texture.c,v 1.44 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -495,17 +495,14 @@ sample_1d_linear_mipmap_linear(GLcontext *ctx, static void sample_nearest_1d( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], + GLfloat texcoords[][3], const GLfloat lambda[], GLchan rgba[][4] ) { GLuint i; struct gl_texture_image *image = tObj->Image[tObj->BaseLevel]; - (void) t; - (void) u; (void) lambda; for (i=0;i<n;i++) { - sample_1d_nearest(ctx, tObj, image, s[i], rgba[i]); + sample_1d_nearest(ctx, tObj, image, texcoords[i][0], rgba[i]); } } @@ -514,17 +511,14 @@ sample_nearest_1d( GLcontext *ctx, GLuint texUnit, static void sample_linear_1d( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], + GLfloat texcoords[][3], const GLfloat lambda[], GLchan rgba[][4] ) { GLuint i; struct gl_texture_image *image = tObj->Image[tObj->BaseLevel]; - (void) t; - (void) u; (void) lambda; for (i=0;i<n;i++) { - sample_1d_linear(ctx, tObj, image, s[i], rgba[i]); + sample_1d_linear(ctx, tObj, image, texcoords[i][0], rgba[i]); } } @@ -537,42 +531,38 @@ sample_linear_1d( GLcontext *ctx, GLuint texUnit, static void sample_lambda_1d( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], - GLchan rgba[][4] ) + GLfloat texcoords[][3], + const GLfloat lambda[], GLchan rgba[][4] ) { GLfloat MinMagThresh = SWRAST_CONTEXT(ctx)->_MinMagThresh[texUnit]; GLuint i; - (void) t; - (void) u; - for (i=0;i<n;i++) { if (lambda[i] > MinMagThresh) { /* minification */ switch (tObj->MinFilter) { case GL_NEAREST: sample_1d_nearest(ctx, tObj, tObj->Image[tObj->BaseLevel], - s[i], rgba[i]); + texcoords[i][0], rgba[i]); break; case GL_LINEAR: sample_1d_linear(ctx, tObj, tObj->Image[tObj->BaseLevel], - s[i], rgba[i]); + texcoords[i][0], rgba[i]); break; case GL_NEAREST_MIPMAP_NEAREST: - sample_1d_nearest_mipmap_nearest(ctx, tObj, lambda[i], s[i], + sample_1d_nearest_mipmap_nearest(ctx, tObj, lambda[i], texcoords[i][0], rgba[i]); break; case GL_LINEAR_MIPMAP_NEAREST: - sample_1d_linear_mipmap_nearest(ctx, tObj, s[i], lambda[i], + sample_1d_linear_mipmap_nearest(ctx, tObj, texcoords[i][0], lambda[i], rgba[i]); break; case GL_NEAREST_MIPMAP_LINEAR: - sample_1d_nearest_mipmap_linear(ctx, tObj, s[i], lambda[i], + sample_1d_nearest_mipmap_linear(ctx, tObj, texcoords[i][0], lambda[i], rgba[i]); break; case GL_LINEAR_MIPMAP_LINEAR: - sample_1d_linear_mipmap_linear(ctx, tObj, s[i], lambda[i], + sample_1d_linear_mipmap_linear(ctx, tObj, texcoords[i][0], lambda[i], rgba[i]); break; default: @@ -585,11 +575,11 @@ sample_lambda_1d( GLcontext *ctx, GLuint texUnit, switch (tObj->MagFilter) { case GL_NEAREST: sample_1d_nearest(ctx, tObj, tObj->Image[tObj->BaseLevel], - s[i], rgba[i]); + texcoords[i][0], rgba[i]); break; case GL_LINEAR: sample_1d_linear(ctx, tObj, tObj->Image[tObj->BaseLevel], - s[i], rgba[i]); + texcoords[i][0], rgba[i]); break; default: _mesa_problem(NULL, "Bad mag filter in sample_1d_texture"); @@ -847,16 +837,15 @@ sample_2d_linear_mipmap_linear(GLcontext *ctx, static void sample_nearest_2d( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], - GLchan rgba[][4] ) + GLfloat texcoords[][3], + const GLfloat lambda[], GLchan rgba[][4] ) { GLuint i; struct gl_texture_image *image = tObj->Image[tObj->BaseLevel]; - (void) u; (void) lambda; for (i=0;i<n;i++) { - sample_2d_nearest(ctx, tObj, image, s[i], t[i], rgba[i]); + sample_2d_nearest(ctx, tObj, image, texcoords[i][0], + texcoords[i][1], rgba[i]); } } @@ -865,16 +854,15 @@ sample_nearest_2d( GLcontext *ctx, GLuint texUnit, static void sample_linear_2d( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], - GLchan rgba[][4] ) + GLfloat texcoords[][3], + const GLfloat lambda[], GLchan rgba[][4] ) { GLuint i; struct gl_texture_image *image = tObj->Image[tObj->BaseLevel]; - (void) u; (void) lambda; for (i=0;i<n;i++) { - sample_2d_linear(ctx, tObj, image, s[i], t[i], rgba[i]); + sample_2d_linear(ctx, tObj, image, texcoords[i][0], + texcoords[i][1], rgba[i]); } } @@ -889,8 +877,8 @@ sample_linear_2d( GLcontext *ctx, GLuint texUnit, static void opt_sample_rgb_2d( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, - GLuint n, const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], + GLuint n, GLfloat texcoords[][3], + const GLfloat lambda[], GLchan rgba[][4] ) { const struct gl_texture_image *img = tObj->Image[tObj->BaseLevel]; @@ -900,7 +888,6 @@ opt_sample_rgb_2d( GLcontext *ctx, GLuint texUnit, const GLint rowMask = img->Height - 1; const GLint shift = img->WidthLog2; GLuint k; - (void) u; (void) lambda; ASSERT(tObj->WrapS==GL_REPEAT); ASSERT(tObj->WrapT==GL_REPEAT); @@ -908,8 +895,8 @@ opt_sample_rgb_2d( GLcontext *ctx, GLuint texUnit, ASSERT(img->Format==GL_RGB); for (k=0; k<n; k++) { - GLint i = IFLOOR(s[k] * width) & colMask; - GLint j = IFLOOR(t[k] * height) & rowMask; + GLint i = IFLOOR(texcoords[k][0] * width) & colMask; + GLint j = IFLOOR(texcoords[k][1] * height) & rowMask; GLint pos = (j << shift) | i; GLchan *texel = ((GLchan *) img->Data) + 3*pos; rgba[k][RCOMP] = texel[0]; @@ -929,8 +916,8 @@ opt_sample_rgb_2d( GLcontext *ctx, GLuint texUnit, static void opt_sample_rgba_2d( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, - GLuint n, const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], + GLuint n, GLfloat texcoords[][3], + const GLfloat lambda[], GLchan rgba[][4] ) { const struct gl_texture_image *img = tObj->Image[tObj->BaseLevel]; @@ -940,7 +927,6 @@ opt_sample_rgba_2d( GLcontext *ctx, GLuint texUnit, const GLint rowMask = img->Height - 1; const GLint shift = img->WidthLog2; GLuint i; - (void) u; (void) lambda; ASSERT(tObj->WrapS==GL_REPEAT); ASSERT(tObj->WrapT==GL_REPEAT); @@ -948,8 +934,8 @@ opt_sample_rgba_2d( GLcontext *ctx, GLuint texUnit, ASSERT(img->Format==GL_RGBA); for (i = 0; i < n; i++) { - const GLint col = IFLOOR(s[i] * width) & colMask; - const GLint row = IFLOOR(t[i] * height) & rowMask; + const GLint col = IFLOOR(texcoords[i][0] * width) & colMask; + const GLint row = IFLOOR(texcoords[i][1] * height) & rowMask; const GLint pos = (row << shift) | col; const GLchan *texel = ((GLchan *) img->Data) + (pos << 2); /* pos*4 */ COPY_CHAN4(rgba[i], texel); @@ -986,14 +972,12 @@ span_is_monotonous (GLuint n, const GLfloat lambda[]) static void sample_lambda_2d( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, - GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], + GLuint n, GLfloat texcoords[][3], + const GLfloat lambda[], GLchan rgba[][4] ) { const GLfloat minMagThresh = SWRAST_CONTEXT(ctx)->_MinMagThresh[texUnit]; GLuint i; - (void) u; #ifdef DEBUG ASSERT (span_is_monotonous(n, lambda) == GL_TRUE); @@ -1009,25 +993,25 @@ sample_lambda_2d( GLcontext *ctx, GLuint texUnit, img->Border == 0) { switch (img->Format) { case GL_RGB: - opt_sample_rgb_2d(ctx, texUnit, tObj, n, s, t, NULL, + opt_sample_rgb_2d(ctx, texUnit, tObj, n, texcoords, NULL, rgba); break; case GL_RGBA: - opt_sample_rgba_2d(ctx, texUnit, tObj, n, s, t, NULL, + opt_sample_rgba_2d(ctx, texUnit, tObj, n, texcoords, NULL, rgba); break; default: - sample_nearest_2d(ctx, texUnit, tObj, n, s, t, NULL, + sample_nearest_2d(ctx, texUnit, tObj, n, texcoords, NULL, rgba); } } else { - sample_nearest_2d(ctx, texUnit, tObj, n, s, t, NULL, + sample_nearest_2d(ctx, texUnit, tObj, n, texcoords, NULL, rgba); } break; case GL_LINEAR: - sample_linear_2d(ctx, texUnit, tObj, n, s, t, NULL, + sample_linear_2d(ctx, texUnit, tObj, n, texcoords, NULL, rgba); break; default: @@ -1041,26 +1025,26 @@ sample_lambda_2d( GLcontext *ctx, GLuint texUnit, switch (tObj->MinFilter) { case GL_NEAREST: sample_2d_nearest(ctx, tObj, tObj->Image[tObj->BaseLevel], - s[i], t[i], rgba[i]); + texcoords[i][0], texcoords[i][1], rgba[i]); break; case GL_LINEAR: sample_2d_linear(ctx, tObj, tObj->Image[tObj->BaseLevel], - s[i], t[i], rgba[i]); + texcoords[i][0], texcoords[i][1], rgba[i]); break; case GL_NEAREST_MIPMAP_NEAREST: - sample_2d_nearest_mipmap_nearest(ctx, tObj, s[i], t[i], + sample_2d_nearest_mipmap_nearest(ctx, tObj, texcoords[i][0], texcoords[i][1], lambda[i], rgba[i]); break; case GL_LINEAR_MIPMAP_NEAREST: - sample_2d_linear_mipmap_nearest(ctx,tObj, s[i], t[i], + sample_2d_linear_mipmap_nearest(ctx,tObj, texcoords[i][0], texcoords[i][1], lambda[i], rgba[i]); break; case GL_NEAREST_MIPMAP_LINEAR: - sample_2d_nearest_mipmap_linear(ctx,tObj, s[i], t[i], + sample_2d_nearest_mipmap_linear(ctx,tObj, texcoords[i][0], texcoords[i][1], lambda[i], rgba[i]); break; case GL_LINEAR_MIPMAP_LINEAR: - sample_2d_linear_mipmap_linear(ctx,tObj, s[i], t[i], + sample_2d_linear_mipmap_linear(ctx,tObj, texcoords[i][0], texcoords[i][1], lambda[i], rgba[i] ); break; default: @@ -1073,11 +1057,11 @@ sample_lambda_2d( GLcontext *ctx, GLuint texUnit, switch (tObj->MagFilter) { case GL_NEAREST: sample_2d_nearest(ctx, tObj, tObj->Image[tObj->BaseLevel], - s[i], t[i], rgba[i]); + texcoords[i][0], texcoords[i][1], rgba[i]); break; case GL_LINEAR: sample_2d_linear(ctx, tObj, tObj->Image[tObj->BaseLevel], - s[i], t[i], rgba[i] ); + texcoords[i][0], texcoords[i][1], rgba[i] ); break; default: _mesa_problem(NULL, "Bad mag filter in sample_2d_texture"); @@ -1402,15 +1386,14 @@ sample_3d_linear_mipmap_linear(GLcontext *ctx, static void sample_nearest_3d(GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], + GLfloat texcoords[][3], const GLfloat lambda[], GLchan rgba[][4]) { GLuint i; struct gl_texture_image *image = tObj->Image[tObj->BaseLevel]; (void) lambda; for (i=0;i<n;i++) { - sample_3d_nearest(ctx, tObj, image, s[i], t[i], u[i], rgba[i]); + sample_3d_nearest(ctx, tObj, image, texcoords[i][0], texcoords[i][1], texcoords[i][2], rgba[i]); } } @@ -1419,15 +1402,14 @@ sample_nearest_3d(GLcontext *ctx, GLuint texUnit, static void sample_linear_3d( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], - GLchan rgba[][4] ) + GLfloat texcoords[][3], + const GLfloat lambda[], GLchan rgba[][4] ) { GLuint i; struct gl_texture_image *image = tObj->Image[tObj->BaseLevel]; (void) lambda; for (i=0;i<n;i++) { - sample_3d_linear(ctx, tObj, image, s[i], t[i], u[i], rgba[i]); + sample_3d_linear(ctx, tObj, image, texcoords[i][0], texcoords[i][1], texcoords[i][2], rgba[i]); } } @@ -1439,8 +1421,7 @@ sample_linear_3d( GLcontext *ctx, GLuint texUnit, static void sample_lambda_3d( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], + GLfloat texcoords[][3], const GLfloat lambda[], GLchan rgba[][4] ) { GLuint i; @@ -1453,26 +1434,26 @@ sample_lambda_3d( GLcontext *ctx, GLuint texUnit, switch (tObj->MinFilter) { case GL_NEAREST: sample_3d_nearest(ctx, tObj, tObj->Image[tObj->BaseLevel], - s[i], t[i], u[i], rgba[i]); + texcoords[i][0], texcoords[i][1], texcoords[i][2], rgba[i]); break; case GL_LINEAR: sample_3d_linear(ctx, tObj, tObj->Image[tObj->BaseLevel], - s[i], t[i], u[i], rgba[i]); + texcoords[i][0], texcoords[i][1], texcoords[i][2], rgba[i]); break; case GL_NEAREST_MIPMAP_NEAREST: - sample_3d_nearest_mipmap_nearest(ctx, tObj, s[i], t[i], u[i], + sample_3d_nearest_mipmap_nearest(ctx, tObj, texcoords[i][0], texcoords[i][1], texcoords[i][2], lambda[i], rgba[i]); break; case GL_LINEAR_MIPMAP_NEAREST: - sample_3d_linear_mipmap_nearest(ctx, tObj, s[i], t[i], u[i], + sample_3d_linear_mipmap_nearest(ctx, tObj, texcoords[i][0], texcoords[i][1], texcoords[i][2], lambda[i], rgba[i]); break; case GL_NEAREST_MIPMAP_LINEAR: - sample_3d_nearest_mipmap_linear(ctx, tObj, s[i], t[i], u[i], + sample_3d_nearest_mipmap_linear(ctx, tObj, texcoords[i][0], texcoords[i][1], texcoords[i][2], lambda[i], rgba[i]); break; case GL_LINEAR_MIPMAP_LINEAR: - sample_3d_linear_mipmap_linear(ctx, tObj, s[i], t[i], u[i], + sample_3d_linear_mipmap_linear(ctx, tObj, texcoords[i][0], texcoords[i][1], texcoords[i][2], lambda[i], rgba[i]); break; default: @@ -1484,11 +1465,11 @@ sample_lambda_3d( GLcontext *ctx, GLuint texUnit, switch (tObj->MagFilter) { case GL_NEAREST: sample_3d_nearest(ctx, tObj, tObj->Image[tObj->BaseLevel], - s[i], t[i], u[i], rgba[i]); + texcoords[i][0], texcoords[i][1], texcoords[i][2], rgba[i]); break; case GL_LINEAR: sample_3d_linear(ctx, tObj, tObj->Image[tObj->BaseLevel], - s[i], t[i], u[i], rgba[i]); + texcoords[i][0], texcoords[i][1], texcoords[i][2], rgba[i]); break; default: _mesa_problem(NULL, "Bad mag filter in sample_3d_texture"); @@ -1579,8 +1560,7 @@ choose_cube_face(const struct gl_texture_object *texObj, static void sample_nearest_cube(GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], + GLfloat texcoords[][3], const GLfloat lambda[], GLchan rgba[][4]) { GLuint i; @@ -1588,7 +1568,7 @@ sample_nearest_cube(GLcontext *ctx, GLuint texUnit, for (i = 0; i < n; i++) { const struct gl_texture_image **images; GLfloat newS, newT; - images = choose_cube_face(tObj, s[i], t[i], u[i], &newS, &newT); + images = choose_cube_face(tObj, texcoords[i][0], texcoords[i][1], texcoords[i][2], &newS, &newT); sample_2d_nearest(ctx, tObj, images[tObj->BaseLevel], newS, newT, rgba[i]); } @@ -1598,16 +1578,15 @@ sample_nearest_cube(GLcontext *ctx, GLuint texUnit, static void sample_linear_cube(GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], - GLchan rgba[][4]) + GLfloat texcoords[][3], + const GLfloat lambda[], GLchan rgba[][4]) { GLuint i; (void) lambda; for (i = 0; i < n; i++) { const struct gl_texture_image **images; GLfloat newS, newT; - images = choose_cube_face(tObj, s[i], t[i], u[i], &newS, &newT); + images = choose_cube_face(tObj, texcoords[i][0], texcoords[i][1], texcoords[i][2], &newS, &newT); sample_2d_linear(ctx, tObj, images[tObj->BaseLevel], newS, newT, rgba[i]); } @@ -1711,8 +1690,7 @@ sample_cube_linear_mipmap_linear(GLcontext *ctx, static void sample_lambda_cube( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], + GLfloat texcoords[][3], const GLfloat lambda[], GLchan rgba[][4]) { GLfloat MinMagThresh = SWRAST_CONTEXT(ctx)->_MinMagThresh[texUnit]; @@ -1726,7 +1704,8 @@ sample_lambda_cube( GLcontext *ctx, GLuint texUnit, { const struct gl_texture_image **images; GLfloat newS, newT; - images = choose_cube_face(tObj, s[i], t[i], u[i], + images = choose_cube_face(tObj, texcoords[i][0], + texcoords[i][1], texcoords[i][2], &newS, &newT); sample_2d_nearest(ctx, tObj, images[tObj->BaseLevel], newS, newT, rgba[i]); @@ -1736,26 +1715,26 @@ sample_lambda_cube( GLcontext *ctx, GLuint texUnit, { const struct gl_texture_image **images; GLfloat newS, newT; - images = choose_cube_face(tObj, s[i], t[i], u[i], + images = choose_cube_face(tObj, texcoords[i][0], texcoords[i][1], texcoords[i][2], &newS, &newT); sample_2d_linear(ctx, tObj, images[tObj->BaseLevel], newS, newT, rgba[i]); } break; case GL_NEAREST_MIPMAP_NEAREST: - sample_cube_nearest_mipmap_nearest(ctx, tObj, s[i], t[i], u[i], + sample_cube_nearest_mipmap_nearest(ctx, tObj, texcoords[i][0], texcoords[i][1], texcoords[i][2], lambda[i], rgba[i]); break; case GL_LINEAR_MIPMAP_NEAREST: - sample_cube_linear_mipmap_nearest(ctx, tObj, s[i], t[i], u[i], + sample_cube_linear_mipmap_nearest(ctx, tObj, texcoords[i][0], texcoords[i][1], texcoords[i][2], lambda[i], rgba[i]); break; case GL_NEAREST_MIPMAP_LINEAR: - sample_cube_nearest_mipmap_linear(ctx, tObj, s[i], t[i], u[i], + sample_cube_nearest_mipmap_linear(ctx, tObj, texcoords[i][0], texcoords[i][1], texcoords[i][2], lambda[i], rgba[i]); break; case GL_LINEAR_MIPMAP_LINEAR: - sample_cube_linear_mipmap_linear(ctx, tObj, s[i], t[i], u[i], + sample_cube_linear_mipmap_linear(ctx, tObj, texcoords[i][0], texcoords[i][1], texcoords[i][2], lambda[i], rgba[i]); break; default: @@ -1766,7 +1745,7 @@ sample_lambda_cube( GLcontext *ctx, GLuint texUnit, /* magnification */ const struct gl_texture_image **images; GLfloat newS, newT; - images = choose_cube_face(tObj, s[i], t[i], u[i], + images = choose_cube_face(tObj, texcoords[i][0], texcoords[i][1], texcoords[i][2], &newS, &newT); switch (tObj->MagFilter) { case GL_NEAREST: @@ -1788,8 +1767,7 @@ sample_lambda_cube( GLcontext *ctx, GLuint texUnit, static void null_sample_func( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj, GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat u[], const GLfloat lambda[], + GLfloat texcoords[][3], const GLfloat lambda[], GLchan rgba[][4]) { } @@ -2711,8 +2689,7 @@ apply_texture( const GLcontext *ctx, static void sample_depth_texture(const GLcontext *ctx, const struct gl_texture_unit *texUnit, - GLuint n, - const GLfloat s[], const GLfloat t[], const GLfloat r[], + GLuint n, GLfloat texcoords[][3], GLchan texel[][4]) { const struct gl_texture_object *texObj = texUnit->_Current; @@ -2773,11 +2750,11 @@ sample_depth_texture(const GLcontext *ctx, for (i = 0; i < n; i++) { GLfloat depthSample; GLint col, row; - COMPUTE_NEAREST_TEXEL_LOCATION(texObj->WrapS, s[i], width, col); - COMPUTE_NEAREST_TEXEL_LOCATION(texObj->WrapT, t[i], height, row); + COMPUTE_NEAREST_TEXEL_LOCATION(texObj->WrapS, texcoords[i][0], width, col); + COMPUTE_NEAREST_TEXEL_LOCATION(texObj->WrapT, texcoords[i][1], height, row); depthSample = *((const GLfloat *) texImage->Data + row * width + col); - if ((r[i] <= depthSample && lequal) || - (r[i] >= depthSample && gequal)) { + if ((texcoords[i][2] <= depthSample && lequal) || + (texcoords[i][2] >= depthSample && gequal)) { result = CHAN_MAX; } else { @@ -2817,8 +2794,8 @@ sample_depth_texture(const GLcontext *ctx, GLfloat u, v; GLuint useBorderTexel; - COMPUTE_LINEAR_TEXEL_LOCATIONS(texObj->WrapS, s[i], u, width, i0, i1); - COMPUTE_LINEAR_TEXEL_LOCATIONS(texObj->WrapT, t[i], v, height,j0, j1); + COMPUTE_LINEAR_TEXEL_LOCATIONS(texObj->WrapS, texcoords[i][0], u, width, i0, i1); + COMPUTE_LINEAR_TEXEL_LOCATIONS(texObj->WrapT, texcoords[i][1], v, height,j0, j1); useBorderTexel = 0; if (texImage->Border) { @@ -2870,8 +2847,8 @@ sample_depth_texture(const GLcontext *ctx, const GLfloat w11 = ( a) * ( b); const GLfloat depthSample = w00 * depth00 + w10 * depth10 + w01 * depth01 + w11 * depth11; - if ((depthSample <= r[i] && lequal) || - (depthSample >= r[i] && gequal)) { + if ((depthSample <= texcoords[i][2] && lequal) || + (depthSample >= texcoords[i][2] && gequal)) { result = ambient; } else { @@ -2886,16 +2863,16 @@ sample_depth_texture(const GLcontext *ctx, const GLfloat d = (CHAN_MAXF - (GLfloat) ambient) * 0.25F; GLfloat luminance = CHAN_MAXF; if (lequal) { - if (depth00 <= r[i]) luminance -= d; - if (depth01 <= r[i]) luminance -= d; - if (depth10 <= r[i]) luminance -= d; - if (depth11 <= r[i]) luminance -= d; + if (depth00 <= texcoords[i][2]) luminance -= d; + if (depth01 <= texcoords[i][2]) luminance -= d; + if (depth10 <= texcoords[i][2]) luminance -= d; + if (depth11 <= texcoords[i][2]) luminance -= d; } else { - if (depth00 >= r[i]) luminance -= d; - if (depth01 >= r[i]) luminance -= d; - if (depth10 >= r[i]) luminance -= d; - if (depth11 >= r[i]) luminance -= d; + if (depth00 >= texcoords[i][2]) luminance -= d; + if (depth01 >= texcoords[i][2]) luminance -= d; + if (depth10 >= texcoords[i][2]) luminance -= d; + if (depth11 >= texcoords[i][2]) luminance -= d; } result = (GLchan) luminance; } @@ -2934,8 +2911,7 @@ sample_depth_texture(const GLcontext *ctx, static void sample_depth_texture2(const GLcontext *ctx, const struct gl_texture_unit *texUnit, - GLuint n, - const GLfloat s[], const GLfloat t[], const GLfloat r[], + GLuint n, GLfloat texcoords[][3], GLchan texel[][4]) { const struct gl_texture_object *texObj = texUnit->_Current; @@ -2981,8 +2957,10 @@ sample_depth_texture2(const GLcontext *ctx, GLint col, row, ii, jj, imin, imax, jmin, jmax, samples, count; GLfloat w; GLchan lum; - COMPUTE_NEAREST_TEXEL_LOCATION(texObj->WrapS, s[i], width, col); - COMPUTE_NEAREST_TEXEL_LOCATION(texObj->WrapT, t[i], height, row); + COMPUTE_NEAREST_TEXEL_LOCATION(texObj->WrapS, texcoords[i][0], + width, col); + COMPUTE_NEAREST_TEXEL_LOCATION(texObj->WrapT, texcoords[i][1], + height, row); imin = col - K; imax = col + K; @@ -3025,20 +3003,20 @@ sample_depth_texture2(const GLcontext *ctx, * Apply a unit of texture mapping to the incoming fragments. */ void -_swrast_texture_fragments( GLcontext *ctx, GLuint texUnit, GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat r[], GLfloat lambda[], - CONST GLchan primary_rgba[][4], GLchan rgba[][4] ) +_old_swrast_texture_fragments( GLcontext *ctx, GLuint texUnit, GLuint n, + GLfloat texcoords[][3], GLfloat lambda[], + CONST GLchan primary_rgba[][4], + GLchan rgba[][4] ) { const GLuint mask = TEXTURE0_ANY << (texUnit * 4); if (ctx->Texture._ReallyEnabled & mask) { const struct gl_texture_unit *textureUnit = &ctx->Texture.Unit[texUnit]; - + if (textureUnit->_Current) { /* XXX need this? */ const struct gl_texture_object *curObj = textureUnit->_Current; GLchan texel[PB_SIZE][4]; - + if (textureUnit->LodBias != 0.0F) { /* apply LOD bias, but don't clamp yet */ GLuint i; @@ -3046,7 +3024,7 @@ _swrast_texture_fragments( GLcontext *ctx, GLuint texUnit, GLuint n, lambda[i] += textureUnit->LodBias; } } - + if ((curObj->MinLod != -1000.0 || curObj->MaxLod != 1000.0) && lambda) { /* apply LOD clamping to lambda */ @@ -3062,13 +3040,13 @@ _swrast_texture_fragments( GLcontext *ctx, GLuint texUnit, GLuint n, /* Sample the texture. */ if (curObj->Image[curObj->BaseLevel]->Format == GL_DEPTH_COMPONENT) { /* depth texture */ - sample_depth_texture(ctx, textureUnit, n, s, t, r, texel); + sample_depth_texture(ctx, textureUnit, n, texcoords, texel); } else { /* color texture */ SWRAST_CONTEXT(ctx)->TextureSample[texUnit]( ctx, texUnit, textureUnit->_Current, - n, s, t, r, + n, texcoords, lambda, texel ); } apply_texture( ctx, textureUnit, n, primary_rgba, @@ -3076,3 +3054,67 @@ _swrast_texture_fragments( GLcontext *ctx, GLuint texUnit, GLuint n, } } } + + +/* + * Apply a unit of texture mapping to the incoming fragments. + */ +void +_swrast_texture_fragments( GLcontext *ctx, GLuint texUnit, + struct sw_span *span, + GLchan rgba[][4] ) +{ + const GLuint mask = TEXTURE0_ANY << (texUnit * 4); + + if (ctx->Texture._ReallyEnabled & mask) { + const struct gl_texture_unit *textureUnit = &ctx->Texture.Unit[texUnit]; + GLfloat *lambda = span->lambda[texUnit]; + + ASSERT(span->filledTex[texUnit] == GL_TRUE); + + if (textureUnit->_Current) { /* XXX need this? */ + const struct gl_texture_object *curObj = textureUnit->_Current; + GLchan texel[PB_SIZE][4]; + + if (textureUnit->LodBias != 0.0F) { + /* apply LOD bias, but don't clamp yet */ + GLuint i; + for (i=0;i<span->end;i++) { + lambda[i] += textureUnit->LodBias; + } + } + + if ((curObj->MinLod != -1000.0 || curObj->MaxLod != 1000.0) + && lambda) { + /* apply LOD clamping to lambda */ + const GLfloat min = curObj->MinLod; + const GLfloat max = curObj->MaxLod; + GLuint i; + for (i=0;i<span->end;i++) { + GLfloat l = lambda[i]; + lambda[i] = CLAMP(l, min, max); + } + } + + /* Sample the texture. */ + if (curObj->Image[curObj->BaseLevel]->Format == GL_DEPTH_COMPONENT) { + /* depth texture */ + sample_depth_texture(ctx, textureUnit, span->end, + span->texcoords[texUnit], texel); + } + else { + /* color texture */ + SWRAST_CONTEXT(ctx)->TextureSample[texUnit]( ctx, texUnit, + textureUnit->_Current, + span->end, + span->texcoords[texUnit], + lambda, texel ); + } + apply_texture( ctx, textureUnit, span->end, + (CONST GLchan (*)[4])span->color.rgba, + (CONST GLchan (*)[4]) texel, rgba ); + } + } +} + + diff --git a/src/mesa/swrast/s_texture.h b/src/mesa/swrast/s_texture.h index ac15c106029..253dfb59563 100644 --- a/src/mesa/swrast/s_texture.h +++ b/src/mesa/swrast/s_texture.h @@ -1,4 +1,4 @@ -/* $Id: s_texture.h,v 1.6 2001/03/12 00:48:42 gareth Exp $ */ +/* $Id: s_texture.h,v 1.7 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -40,10 +40,14 @@ _swrast_choose_texture_sample_func( GLcontext *ctx, extern void -_swrast_texture_fragments( GLcontext *ctx, GLuint texSet, GLuint n, - const GLfloat s[], const GLfloat t[], - const GLfloat r[], GLfloat lambda[], - CONST GLchan primary_rgba[][4], GLchan rgba[][4] ); +_swrast_texture_fragments( GLcontext *ctx, GLuint texSet, + struct sw_span *span, + GLchan rgba[][4] ); + +extern void +_old_swrast_texture_fragments( GLcontext *ctx, GLuint texSet, GLuint n, + GLfloat texcoords[][3], GLfloat lambda[], + CONST GLchan primary_rgba[][4], GLchan rgba[][4] ); #endif diff --git a/src/mesa/swrast/s_trispan.h b/src/mesa/swrast/s_trispan.h index 48f397e4c51..ebd5188d39e 100644 --- a/src/mesa/swrast/s_trispan.h +++ b/src/mesa/swrast/s_trispan.h @@ -1,4 +1,4 @@ -/* $Id: s_trispan.h,v 1.3 2001/09/13 22:12:54 brianp Exp $ */ +/* $Id: s_trispan.h,v 1.4 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -29,65 +29,4 @@ #define S_TRISPAN_H -/* - * The triangle_span structure is used by the triangle template code in - * s_tritemp.h. It describes how colors, Z, texcoords, etc are to be - * interpolated across each scanline of triangle. - * With this structure it's easy to hand-off span rasterization to a - * subroutine instead of doing it all inline like we used to do. - * It also cleans up the local variable namespace a great deal. - * - * It would be interesting to experiment with multiprocessor rasterization - * with this structure. The triangle rasterizer could simply emit a - * stream of these structures which would be consumed by one or more - * span-processing threads which could run in parallel. - */ - - -/* When the triangle_span struct is initialized, these flags indicates - * which values are needed for rendering the triangle. - */ -#define SPAN_RGBA 0x001 -#define SPAN_SPEC 0x002 -#define SPAN_INDEX 0x004 -#define SPAN_Z 0x008 -#define SPAN_FOG 0x010 -#define SPAN_TEXTURE 0x020 -#define SPAN_INT_TEXTURE 0x040 -#define SPAN_LAMBDA 0x080 -#define SPAN_FLAT 0x100 /* flat shading? */ - - -struct triangle_span { - GLint x, y; - GLuint count; - GLuint activeMask; /* OR of the SPAN_* flags */ -#if CHAN_TYPE == GL_FLOAT - GLfloat red, redStep; - GLfloat green, greenStep; - GLfloat blue, blueStep; - GLfloat alpha, alphaStep; - GLfloat specRed, specRedStep; - GLfloat specGreen, specGreenStep; - GLfloat specBlue, specBlueStep; -#else - GLfixed red, redStep; - GLfixed green, greenStep; - GLfixed blue, blueStep; - GLfixed alpha, alphaStep; - GLfixed specRed, specRedStep; - GLfixed specGreen, specGreenStep; - GLfixed specBlue, specBlueStep; -#endif - GLfixed index, indexStep; - GLfixed z, zStep; - GLfloat fog, fogStep; - GLfloat tex[MAX_TEXTURE_UNITS][4], texStep[MAX_TEXTURE_UNITS][4]; - GLfixed intTex[2], intTexStep[2]; - /* Needed for texture lambda (LOD) computation */ - GLfloat rho[MAX_TEXTURE_UNITS]; - GLfloat texWidth[MAX_TEXTURE_UNITS], texHeight[MAX_TEXTURE_UNITS]; -}; - - #endif /* S_TRISPAN_H */ diff --git a/src/mesa/swrast/s_tritemp.h b/src/mesa/swrast/s_tritemp.h index 4940dab17ea..29248b1c0c3 100644 --- a/src/mesa/swrast/s_tritemp.h +++ b/src/mesa/swrast/s_tritemp.h @@ -1,4 +1,4 @@ -/* $Id: s_tritemp.h,v 1.28 2001/12/05 10:24:31 keithw Exp $ */ +/* $Id: s_tritemp.h,v 1.29 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -120,7 +120,7 @@ const GLint snapMask = ~((FIXED_ONE / 16) - 1); /* for x/y coord snapping */ GLfixed vMin_fx, vMin_fy, vMid_fx, vMid_fy, vMax_fx, vMax_fy; - struct triangle_span span; + struct sw_span span; #ifdef INTERP_Z (void) fixedToDepthShift; @@ -1136,11 +1136,13 @@ /* initialize the span interpolants to the leftmost value */ /* ff = fixed-pt fragment */ const GLint right = FixedToInt(fxRightEdge); + SW_SPAN_RESET(span); span.x = FixedToInt(fxLeftEdge); + if (right <= span.x) - span.count = 0; + span.end = 0; else - span.count = right - span.x; + span.end = right - span.x; #ifdef INTERP_Z span.z = fz; @@ -1254,7 +1256,7 @@ #endif /* This is where we actually generate fragments */ - if (span.count > 0) { + if (span.end > 0) { RENDER_SPAN( span ); } diff --git a/src/mesa/swrast/s_zoom.c b/src/mesa/swrast/s_zoom.c index ff3d3f5e0c1..b331be13069 100644 --- a/src/mesa/swrast/s_zoom.c +++ b/src/mesa/swrast/s_zoom.c @@ -1,4 +1,4 @@ -/* $Id: s_zoom.c,v 1.6 2001/05/15 21:30:27 brianp Exp $ */ +/* $Id: s_zoom.c,v 1.7 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -106,7 +106,7 @@ _mesa_write_zoomed_rgba_span( GLcontext *ctx, return; } - assert( m <= MAX_WIDTH ); + ASSERT( m <= MAX_WIDTH ); /* zoom the span horizontally */ if (ctx->Pixel.ZoomX==-1.0F) { @@ -142,7 +142,7 @@ _mesa_write_zoomed_rgba_span( GLcontext *ctx, /* write the span */ for (r=r0; r<r1; r++) { - _mesa_write_rgba_span( ctx, m, x+skipcol, r, zdepth, + _old_write_rgba_span( ctx, m, x+skipcol, r, zdepth, (fog ? zfog : 0), zrgba, NULL, GL_BITMAP ); } } @@ -210,7 +210,7 @@ _mesa_write_zoomed_rgb_span( GLcontext *ctx, return; } - assert( m <= MAX_WIDTH ); + ASSERT( m <= MAX_WIDTH ); /* zoom the span horizontally */ if (ctx->Pixel.ZoomX==-1.0F) { @@ -252,7 +252,7 @@ _mesa_write_zoomed_rgb_span( GLcontext *ctx, /* write the span */ for (r=r0; r<r1; r++) { - _mesa_write_rgba_span( ctx, m, x+skipcol, r, zdepth, + _old_write_rgba_span( ctx, m, x+skipcol, r, zdepth, (fog ? zfog : 0), zrgba, NULL, GL_BITMAP ); } } @@ -323,7 +323,7 @@ _mesa_write_zoomed_index_span( GLcontext *ctx, return; } - assert( m <= MAX_WIDTH ); + ASSERT( m <= MAX_WIDTH ); /* zoom the span horizontally */ if (ctx->Pixel.ZoomX==-1.0F) { @@ -359,7 +359,7 @@ _mesa_write_zoomed_index_span( GLcontext *ctx, /* write the span */ for (r=r0; r<r1; r++) { - _mesa_write_index_span( ctx, m, x+skipcol, r, zdepth, + _old_write_index_span( ctx, m, x+skipcol, r, zdepth, (fog ? zfog : 0), zindexes, NULL, GL_BITMAP ); } } @@ -427,7 +427,7 @@ _mesa_write_zoomed_stencil_span( GLcontext *ctx, return; } - assert( m <= MAX_WIDTH ); + ASSERT( m <= MAX_WIDTH ); /* zoom the span horizontally */ if (ctx->Pixel.ZoomX==-1.0F) { diff --git a/src/mesa/swrast/swrast.h b/src/mesa/swrast/swrast.h index 76453cdaef9..5f9a2bbb53e 100644 --- a/src/mesa/swrast/swrast.h +++ b/src/mesa/swrast/swrast.h @@ -1,4 +1,4 @@ -/* $Id: swrast.h,v 1.12 2001/03/19 02:25:36 keithw Exp $ */ +/* $Id: swrast.h,v 1.13 2001/12/17 04:54:35 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -67,6 +67,105 @@ typedef struct { } SWvertex; +/* + * The sw_span structure is used by the triangle template code in + * s_tritemp.h. It describes how colors, Z, texcoords, etc are to be + * interpolated across each scanline of triangle. + * With this structure it's easy to hand-off span rasterization to a + * subroutine instead of doing it all inline like we used to do. + * It also cleans up the local variable namespace a great deal. + * + * It would be interesting to experiment with multiprocessor rasterization + * with this structure. The triangle rasterizer could simply emit a + * stream of these structures which would be consumed by one or more + * span-processing threads which could run in parallel. + */ + + +/* When the sw_span struct is initialized, these flags indicates + * which values are needed for rendering the triangle. + */ +#define SPAN_RGBA 0x001 +#define SPAN_SPEC 0x002 +#define SPAN_INDEX 0x004 +#define SPAN_Z 0x008 +#define SPAN_FOG 0x010 +#define SPAN_TEXTURE 0x020 +#define SPAN_INT_TEXTURE 0x040 +#define SPAN_LAMBDA 0x080 +#define SPAN_FLAT 0x100 /* flat shading? */ + + +struct sw_span { + GLint x, y; + GLuint start, end; /* start=first pixel in span, end=last pixel in span*/ + /* only end is used until now.(end was before called count) */ + GLuint activeMask; /* OR of the SPAN_* flags */ +#if CHAN_TYPE == GL_FLOAT + GLfloat red, redStep; + GLfloat green, greenStep; + GLfloat blue, blueStep; + GLfloat alpha, alphaStep; + GLfloat specRed, specRedStep; + GLfloat specGreen, specGreenStep; + GLfloat specBlue, specBlueStep; +#else /* CHAN_TYPE == */ + GLfixed red, redStep; + GLfixed green, greenStep; + GLfixed blue, blueStep; + GLfixed alpha, alphaStep; + GLfixed specRed, specRedStep; + GLfixed specGreen, specGreenStep; + GLfixed specBlue, specBlueStep; +#endif + GLfixed index, indexStep; + GLfixed z, zStep; + GLfloat fog, fogStep; + GLfloat tex[MAX_TEXTURE_UNITS][4], texStep[MAX_TEXTURE_UNITS][4]; + GLfixed intTex[2], intTexStep[2]; + /* Needed for texture lambda (LOD) computation */ + GLfloat rho[MAX_TEXTURE_UNITS]; + GLfloat texWidth[MAX_TEXTURE_UNITS], texHeight[MAX_TEXTURE_UNITS]; + + GLboolean write_all; /* This flag indicates that only a part of */ + /*the span is visible. */ +#ifdef DEBUG + GLboolean filledDepth, filledMask, filledAlpha; + GLboolean filledColor, filledSpecular; + GLboolean filledLambda[MAX_TEXTURE_UNITS], filledTex[MAX_TEXTURE_UNITS]; + GLboolean testedDepth, testedAlpha; +#endif + /* The interpolated fragment values */ + GLdepth depth[MAX_WIDTH]; + union { + GLchan rgb[MAX_WIDTH][3]; + GLchan rgba[MAX_WIDTH][4]; + GLuint index[MAX_WIDTH]; + } color; + GLchan specular[MAX_WIDTH][4]; + GLint itexcoords[MAX_WIDTH][2]; /* s, t */ + GLfloat texcoords[MAX_TEXTURE_UNITS][MAX_WIDTH][3]; /* s, t, r */ + GLfloat lambda[MAX_TEXTURE_UNITS][MAX_WIDTH]; + GLfloat coverage[MAX_WIDTH]; + GLubyte mask[MAX_WIDTH]; +}; + +#ifdef DEBUG +#define SW_SPAN_SET_FLAG(flag) {ASSERT((flag) == GL_FALSE);(flag) = GL_TRUE;} +#define SW_SPAN_RESET(span) { \ + (span).filledDepth = (span).filledMask = (span).filledAlpha \ + = (span).filledColor = (span).filledSpecular \ + = (span).testedDepth = (span).testedAlpha = GL_FALSE; \ + MEMSET((span).filledTex, GL_FALSE, \ + MAX_TEXTURE_UNITS*sizeof(GLboolean)); \ + MEMSET((span).filledLambda, GL_FALSE, \ + MAX_TEXTURE_UNITS*sizeof(GLboolean)); \ + (span).start = 0; (span).write_all = GL_TRUE;} +#else +#define SW_SPAN_SET_FLAG(flag) ; +#define SW_SPAN_RESET(span) {(span).start = 0;(span).write_all = GL_TRUE;} +#endif + struct swrast_device_driver; |