diff options
author | Brian Paul <[email protected]> | 2001-07-13 20:07:37 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2001-07-13 20:07:37 +0000 |
commit | f431a3fb4dc1bf860203d79e54657e3a62bc50df (patch) | |
tree | 51a598faf5e8b971b2bd7cf85702e021426f54c6 /src | |
parent | bc07a99cc3faeb1aa48700065b34baa76c201e7d (diff) |
assorted changes for supporting GLfloat color channels (not done)
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/drivers/osmesa/osmesa.c | 14 | ||||
-rw-r--r-- | src/mesa/main/Makefile.OSMesa16 | 4 | ||||
-rw-r--r-- | src/mesa/main/config.h | 4 | ||||
-rw-r--r-- | src/mesa/main/mtypes.h | 4 | ||||
-rw-r--r-- | src/mesa/main/pixel.c | 10 | ||||
-rw-r--r-- | src/mesa/main/teximage.c | 6 | ||||
-rw-r--r-- | src/mesa/main/texstore.c | 36 | ||||
-rw-r--r-- | src/mesa/swrast/s_aatritemp.h | 520 | ||||
-rw-r--r-- | src/mesa/swrast/s_accum.c | 102 | ||||
-rw-r--r-- | src/mesa/swrast/s_alphabuf.c | 16 | ||||
-rw-r--r-- | src/mesa/swrast/s_blend.c | 9 | ||||
-rw-r--r-- | src/mesa/swrast/s_context.c | 9 | ||||
-rw-r--r-- | src/mesa/swrast/s_context.h | 26 | ||||
-rw-r--r-- | src/mesa/swrast/s_copypix.c | 4 | ||||
-rw-r--r-- | src/mesa/swrast/s_linetemp.h | 30 | ||||
-rw-r--r-- | src/mesa/swrast/s_logic.c | 14 | ||||
-rw-r--r-- | src/mesa/swrast/s_texture.c | 118 | ||||
-rw-r--r-- | src/mesa/swrast/s_triangle.c | 84 | ||||
-rw-r--r-- | src/mesa/swrast/s_tritemp.h | 16 |
19 files changed, 603 insertions, 423 deletions
diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c index a0f2823f1d9..c1549fdaeed 100644 --- a/src/mesa/drivers/osmesa/osmesa.c +++ b/src/mesa/drivers/osmesa/osmesa.c @@ -1,4 +1,4 @@ -/* $Id: osmesa.c,v 1.61 2001/07/12 22:09:21 keithw Exp $ */ +/* $Id: osmesa.c,v 1.62 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -650,7 +650,7 @@ do { \ #define PACK_RGB_565(DST, R, G, B) \ do { \ - (DST) = (((R) << 8) & 0xf800) | (((G) << 3) & 0x7e0) | ((B) >> 3);\ + (DST) = (((int) (R) << 8) & 0xf800) | (((int) (G) << 3) & 0x7e0) | ((int) (B) >> 3);\ } while (0) @@ -1278,7 +1278,7 @@ read_rgba_pixels3( const GLcontext *ctx, static void write_rgba_span2( const GLcontext *ctx, GLuint n, GLint x, GLint y, - CONST GLubyte rgba[][4], const GLubyte mask[] ) + CONST GLchan rgba[][4], const GLubyte mask[] ) { OSMesaContext osmesa = OSMESA_CONTEXT(ctx); GLushort *ptr2 = (GLushort *) PIXELADDR2(x, y); @@ -1302,7 +1302,7 @@ write_rgba_span2( const GLcontext *ctx, static void write_rgb_span2( const GLcontext *ctx, GLuint n, GLint x, GLint y, - CONST GLubyte rgb[][3], const GLubyte mask[] ) + CONST GLchan rgb[][3], const GLubyte mask[] ) { OSMesaContext osmesa = OSMESA_CONTEXT(ctx); GLushort *ptr2 = (GLushort *) PIXELADDR2(x, y); @@ -1342,7 +1342,7 @@ write_monocolor_span2( const GLcontext *ctx, GLuint n, GLint x, GLint y, static void write_rgba_pixels2( const GLcontext *ctx, GLuint n, const GLint x[], const GLint y[], - CONST GLubyte rgba[][4], const GLubyte mask[] ) + CONST GLchan rgba[][4], const GLubyte mask[] ) { OSMesaContext osmesa = OSMESA_CONTEXT(ctx); GLuint i; @@ -1374,7 +1374,7 @@ write_monocolor_pixels2( const GLcontext *ctx, static void read_rgba_span2( const GLcontext *ctx, GLuint n, GLint x, GLint y, - GLubyte rgba[][4] ) + GLchan rgba[][4] ) { OSMesaContext osmesa = OSMESA_CONTEXT(ctx); GLuint i; @@ -1391,7 +1391,7 @@ read_rgba_span2( const GLcontext *ctx, static void read_rgba_pixels2( const GLcontext *ctx, GLuint n, const GLint x[], const GLint y[], - GLubyte rgba[][4], const GLubyte mask[] ) + GLchan rgba[][4], const GLubyte mask[] ) { OSMesaContext osmesa = OSMESA_CONTEXT(ctx); GLuint i; diff --git a/src/mesa/main/Makefile.OSMesa16 b/src/mesa/main/Makefile.OSMesa16 index b96ca802a60..43193aa36b3 100644 --- a/src/mesa/main/Makefile.OSMesa16 +++ b/src/mesa/main/Makefile.OSMesa16 @@ -1,10 +1,10 @@ -# $Id: Makefile.OSMesa16,v 1.3 2001/06/18 17:26:08 brianp Exp $ +# $Id: Makefile.OSMesa16,v 1.4 2001/07/13 20:07:37 brianp Exp $ # Mesa 3-D graphics library # Version: 3.5 # Copyright (C) 1995-2001 Brian Paul -# Makefile for building Mesa for 16-bit/channel rendering with the OSMesa +# Makefile for building Mesa for 16/32-bit/channel rendering with the OSMesa # driver. diff --git a/src/mesa/main/config.h b/src/mesa/main/config.h index 805da1e7b7f..507f499a1fc 100644 --- a/src/mesa/main/config.h +++ b/src/mesa/main/config.h @@ -1,4 +1,4 @@ -/* $Id: config.h,v 1.32 2001/06/13 14:56:14 brianp Exp $ */ +/* $Id: config.h,v 1.33 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -142,7 +142,7 @@ /* - * Bits per accumulation buffer color component: 8 or 16 + * Bits per accumulation buffer color component: 8, 16 or 32 */ #define ACCUM_BITS 16 diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 8b0eb4fd8b0..9bf185f7f39 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1,4 +1,4 @@ -/* $Id: mtypes.h,v 1.48 2001/06/26 21:15:35 brianp Exp $ */ +/* $Id: mtypes.h,v 1.49 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -74,6 +74,8 @@ typedef GLbyte GLaccum; #elif ACCUM_BITS==16 typedef GLshort GLaccum; +#elif ACCUM_BITS==32 + typedef GLfloat GLaccum; #else # error "illegal number of accumulation bits" #endif diff --git a/src/mesa/main/pixel.c b/src/mesa/main/pixel.c index 55f6b99b0f0..e0acfd5b93a 100644 --- a/src/mesa/main/pixel.c +++ b/src/mesa/main/pixel.c @@ -1,4 +1,4 @@ -/* $Id: pixel.c,v 1.29 2001/05/23 23:55:01 brianp Exp $ */ +/* $Id: pixel.c,v 1.30 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -580,13 +580,13 @@ _mesa_PixelTransferf( GLenum pname, GLfloat param ) switch (pname) { case GL_MAP_COLOR: - if (ctx->Pixel.MapColorFlag == param ? GL_TRUE : GL_FALSE) + if (ctx->Pixel.MapColorFlag == (param ? GL_TRUE : GL_FALSE)) return; FLUSH_VERTICES(ctx, _NEW_PIXEL); ctx->Pixel.MapColorFlag = param ? GL_TRUE : GL_FALSE; break; case GL_MAP_STENCIL: - if (ctx->Pixel.MapStencilFlag == param ? GL_TRUE : GL_FALSE) + if (ctx->Pixel.MapStencilFlag == (param ? GL_TRUE : GL_FALSE)) return; FLUSH_VERTICES(ctx, _NEW_PIXEL); ctx->Pixel.MapStencilFlag = param ? GL_TRUE : GL_FALSE; @@ -1290,6 +1290,9 @@ void _mesa_chan_to_float_span(const GLcontext *ctx, GLuint n, CONST GLchan rgba[][4], GLfloat rgbaf[][4]) { +#if CHAN_TYPE == GL_FLOAT + MEMCPY(rgbaf, rgba, n * 4 * sizeof(GLfloat)); +#else const GLuint rShift = CHAN_BITS - ctx->Visual.redBits; const GLuint gShift = CHAN_BITS - ctx->Visual.greenBits; const GLuint bShift = CHAN_BITS - ctx->Visual.blueBits; @@ -1319,4 +1322,5 @@ _mesa_chan_to_float_span(const GLcontext *ctx, GLuint n, rgbaf[i][BCOMP] = (GLfloat) b * bScale; rgbaf[i][ACOMP] = (GLfloat) a * aScale; } +#endif } diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index b13b4395f3c..ffddeffbabc 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -1,4 +1,4 @@ -/* $Id: teximage.c,v 1.99 2001/07/13 15:44:21 brianp Exp $ */ +/* $Id: teximage.c,v 1.100 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -58,6 +58,9 @@ #ifdef DEBUG static void PrintTexture(const struct gl_texture_image *img) { +#if CHAN_TYPE == GL_FLOAT + _mesa_problem(NULL, "PrintTexture doesn't support float channels"); +#else GLuint i, j, c; const GLchan *data = (const GLchan *) img->Data; @@ -101,6 +104,7 @@ static void PrintTexture(const struct gl_texture_image *img) } printf("\n"); } +#endif } #endif diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 6474121b702..56ec66e13ae 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -1,4 +1,4 @@ -/* $Id: texstore.c,v 1.30 2001/07/13 16:38:44 brianp Exp $ */ +/* $Id: texstore.c,v 1.31 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -1021,13 +1021,13 @@ do_row(const struct gl_texture_format *format, GLint srcWidth, for (i = j = 0, k = k0; i < dstWidth; i++, j += colStride, k += colStride) { dst[i][0] = (rowA[j][0] + rowA[k][0] + - rowB[j][0] + rowB[k][0]) >> 2; + rowB[j][0] + rowB[k][0]) / 4; dst[i][1] = (rowA[j][1] + rowA[k][1] + - rowB[j][1] + rowB[k][1]) >> 2; + rowB[j][1] + rowB[k][1]) / 4; dst[i][2] = (rowA[j][2] + rowA[k][2] + - rowB[j][2] + rowB[k][2]) >> 2; + rowB[j][2] + rowB[k][2]) / 4; dst[i][3] = (rowA[j][3] + rowA[k][3] + - rowB[j][3] + rowB[k][3]) >> 2; + rowB[j][3] + rowB[k][3]) / 4; } } return; @@ -1040,11 +1040,11 @@ do_row(const struct gl_texture_format *format, GLint srcWidth, for (i = j = 0, k = k0; i < dstWidth; i++, j += colStride, k += colStride) { dst[i][0] = (rowA[j][0] + rowA[k][0] + - rowB[j][0] + rowB[k][0]) >> 2; + rowB[j][0] + rowB[k][0]) / 4; dst[i][1] = (rowA[j][1] + rowA[k][1] + - rowB[j][1] + rowB[k][1]) >> 2; + rowB[j][1] + rowB[k][1]) / 4; dst[i][2] = (rowA[j][2] + rowA[k][2] + - rowB[j][2] + rowB[k][2]) >> 2; + rowB[j][2] + rowB[k][2]) / 4; } } return; @@ -1059,7 +1059,7 @@ do_row(const struct gl_texture_format *format, GLint srcWidth, GLchan *dst = (GLchan *) dstRow; for (i = j = 0, k = k0; i < dstWidth; i++, j += colStride, k += colStride) { - dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) >> 2; + dst[i] = (rowA[j] + rowA[k] + rowB[j] + rowB[k]) / 4; } } return; @@ -1072,9 +1072,9 @@ do_row(const struct gl_texture_format *format, GLint srcWidth, for (i = j = 0, k = k0; i < dstWidth; i++, j += colStride, k += colStride) { dst[i][0] = (rowA[j][0] + rowA[k][0] + - rowB[j][0] + rowB[k][0]) >> 2; + rowB[j][0] + rowB[k][0]) / 4; dst[i][1] = (rowA[j][1] + rowA[k][1] + - rowB[j][1] + rowB[k][1]) >> 2; + rowB[j][1] + rowB[k][1]) / 4; } } return; @@ -1101,13 +1101,13 @@ do_row(const struct gl_texture_format *format, GLint srcWidth, for (i = j = 0, k = k0; i < dstWidth; i++, j += colStride, k += colStride) { dst[i][0] = (rowA[j][0] + rowA[k][0] + - rowB[j][0] + rowB[k][0]) >> 2; + rowB[j][0] + rowB[k][0]) / 4; dst[i][1] = (rowA[j][1] + rowA[k][1] + - rowB[j][1] + rowB[k][1]) >> 2; + rowB[j][1] + rowB[k][1]) / 4; dst[i][2] = (rowA[j][2] + rowA[k][2] + - rowB[j][2] + rowB[k][2]) >> 2; + rowB[j][2] + rowB[k][2]) / 4; dst[i][3] = (rowA[j][3] + rowA[k][3] + - rowB[j][3] + rowB[k][3]) >> 2; + rowB[j][3] + rowB[k][3]) / 4; } } return; @@ -1120,11 +1120,11 @@ do_row(const struct gl_texture_format *format, GLint srcWidth, for (i = j = 0, k = k0; i < dstWidth; i++, j += colStride, k += colStride) { dst[i][0] = (rowA[j][0] + rowA[k][0] + - rowB[j][0] + rowB[k][0]) >> 2; + rowB[j][0] + rowB[k][0]) / 4; dst[i][1] = (rowA[j][1] + rowA[k][1] + - rowB[j][1] + rowB[k][1]) >> 2; + rowB[j][1] + rowB[k][1]) / 4; dst[i][2] = (rowA[j][2] + rowA[k][2] + - rowB[j][2] + rowB[k][2]) >> 2; + rowB[j][2] + rowB[k][2]) / 4; } } return; diff --git a/src/mesa/swrast/s_aatritemp.h b/src/mesa/swrast/s_aatritemp.h index 0c6a8be3ec2..060f7d988fc 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.18 2001/06/05 21:41:05 brianp Exp $ */ +/* $Id: s_aatritemp.h,v 1.19 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -48,10 +48,11 @@ const GLfloat *p1 = v1->win; const GLfloat *p2 = v2->win; const SWvertex *vMin, *vMid, *vMax; - GLint iyMin, iyMax; - GLfloat yMin, yMax; - GLboolean ltor; - GLfloat majDx, majDy; /* major (i.e. long) edge dx and dy */ + GLfloat xMin, yMin, xMid, yMid, xMax, yMax; + GLfloat majDx, majDy, botDx, botDy, topDx, topDy; + GLfloat area; + GLboolean majorOnLeft; + GLfloat bf = SWRAST_CONTEXT(ctx)->_backface_sign; #ifdef DO_Z GLfloat zPlane[4]; @@ -71,6 +72,7 @@ GLfloat iPlane[4]; GLuint index[MAX_WIDTH]; GLint icoverageSpan[MAX_WIDTH]; + GLfloat coverageSpan[MAX_WIDTH]; #else GLfloat coverageSpan[MAX_WIDTH]; #endif @@ -96,7 +98,6 @@ 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 */ @@ -140,27 +141,38 @@ } } - majDx = vMax->win[0] - vMin->win[0]; - majDy = vMax->win[1] - vMin->win[1]; - - { - const GLfloat botDx = vMid->win[0] - vMin->win[0]; - const GLfloat botDy = vMid->win[1] - vMin->win[1]; - const GLfloat area = majDx * botDy - botDx * majDy; - ltor = (GLboolean) (area < 0.0F); - /* Do backface culling */ - if (area * bf < 0 || area * area < .0025) - return; - } + xMin = vMin->win[0]; yMin = vMin->win[1]; + xMid = vMid->win[0]; yMid = vMid->win[1]; + xMax = vMax->win[0]; yMax = vMax->win[1]; + + /* the major edge is between the top and bottom vertices */ + majDx = xMax - xMin; + majDy = yMax - yMin; + /* the bottom edge is between the bottom and mid vertices */ + botDx = xMid - xMin; + botDy = yMid - yMin; + /* the top edge is between the top and mid vertices */ + topDx = xMax - xMid; + topDy = yMax - yMid; + + /* compute clockwise / counter-clockwise orientation and do BF culling */ + area = majDx * botDy - botDx * majDy; + /* Do backface culling */ + if (area * bf < 0 || area * area < .0025) + return; + majorOnLeft = (GLboolean) (area < 0.0F); #ifndef DO_OCCLUSION_TEST ctx->OcclusionResult = GL_TRUE; #endif + assert(majDy > 0.0F); + /* Plane equation setup: * We evaluate plane equations at window (x,y) coordinates in order * to compute color, Z, fog, texcoords, etc. This isn't terribly - * efficient but it's easy and reliable. + * efficient but it's easy and reliable. It also copes with computing + * interpolated data just outside the triangle's edges. */ #ifdef DO_Z compute_plane(p0, p1, p2, p0[2], p1[2], p2[2], zPlane); @@ -268,285 +280,301 @@ * edges, stopping when we find that coverage = 0. If the long edge * is on the left we scan left-to-right. Else, we scan right-to-left. */ - yMin = vMin->win[1]; - yMax = vMax->win[1]; - iyMin = (GLint) yMin; - iyMax = (GLint) yMax + 1; - - if (ltor) { - /* scan left to right */ - const GLfloat *pMin = vMin->win; - const GLfloat *pMid = vMid->win; - const GLfloat *pMax = vMax->win; - const GLfloat dxdy = majDx / majDy; - const GLfloat xAdj = dxdy < 0.0F ? -dxdy : 0.0F; - GLfloat x = pMin[0] - (yMin - iyMin) * dxdy; + { + const GLint iyMin = (GLint) yMin; + const GLint iyMax = (GLint) yMax + 1; + /* upper edge and lower edge derivatives */ + const GLfloat topDxDy = (topDy != 0.0F) ? topDx / topDy : 0.0F; + const GLfloat botDxDy = (botDy != 0.0F) ? botDx / botDy : 0.0F; + const GLfloat *pA, *pB, *pC; + const GLfloat majDxDy = majDx / majDy; + const GLfloat absMajDxDy = FABSF(majDxDy); + const GLfloat absTopDxDy = FABSF(topDxDy); + const GLfloat absBotDxDy = FABSF(botDxDy); +#if 0 + GLfloat xMaj = xMin - (yMin - (GLfloat) iyMin) * majDxDy; + GLfloat xBot = xMaj; + GLfloat xTop = xMid - (yMid - (GLint) yMid) * topDxDy; +#else + GLfloat xMaj; + GLfloat xBot; + GLfloat xTop; +#endif GLint iy; - for (iy = iyMin; iy < iyMax; iy++, x += dxdy) { - GLint ix, startX = (GLint) (x - xAdj); - GLuint count, n; + GLint k; + + /* pA, pB, pC are the vertices in counter-clockwise order */ + if (majorOnLeft) { + pA = vMin->win; + pB = vMid->win; + pC = vMax->win; + xMaj = xMin - absMajDxDy - 1.0; + xBot = xMin + absBotDxDy + 1.0; + xTop = xMid + absTopDxDy + 1.0; + } + else { + pA = vMin->win; + pB = vMax->win; + pC = vMid->win; + xMaj = xMin + absMajDxDy + 1.0; + xBot = xMin - absBotDxDy - 1.0; + xTop = xMid - absTopDxDy - 1.0; + } + + /* Scan from bottom to top */ + for (iy = iyMin; iy < iyMax; iy++, xMaj += majDxDy) { + GLint ix, i, j, len; + GLint iRight, iLeft; GLfloat coverage = 0.0F; - /* skip over fragments with zero coverage */ - while (startX < MAX_WIDTH) { - coverage = compute_coveragef(pMin, pMid, pMax, startX, iy); - if (coverage > 0.0F) - break; - startX++; + + if (majorOnLeft) { + iLeft = (GLint) (xMaj + 0.0); + /* compute right */ + if (iy <= yMid) { + /* we're in the lower part */ + iRight = (GLint) (xBot + 0.0); + xBot += botDxDy; + } + else { + /* we're in the upper part */ + iRight = (GLint) (xTop + 0.0); + xTop += topDxDy; + } + } + else { + iRight = (GLint) (xMaj + 0.0); + /* compute left */ + if (iy <= yMid) { + /* we're in the lower part */ + iLeft = (GLint) (xBot - 0.0); + xBot += botDxDy; + } + else { + /* we're in the upper part */ + iLeft = (GLint) (xTop - 0.0); + xTop += topDxDy; + } } - /* enter interior of triangle */ - ix = startX; - count = 0; - while (coverage > 0.0F) { - /* (cx,cy) = center of fragment */ - const GLfloat cx = ix + 0.5F, cy = iy + 0.5F; -#ifdef DO_INDEX - icoverageSpan[count] = compute_coveragei(pMin, pMid, pMax, ix, iy); -#else - coverageSpan[count] = coverage; +#ifdef DEBUG + for (i = 0; i < MAX_WIDTH; i++) { + coverageSpan[i] = -1.0; + } #endif + + if (iLeft < 0) + iLeft = 0; + if (iRight >= ctx->DrawBuffer->_Xmax) + iRight = ctx->DrawBuffer->_Xmax - 1; + + /*printf("%d: iLeft = %d iRight = %d\n", iy, iLeft, iRight);*/ + + /* The pixels at y in [iLeft, iRight] (inclusive) are candidates */ + + /* scan left to right until we hit 100% coverage or the right edge */ + i = iLeft; + while (i < iRight) { + coverage = compute_coveragef(pA, pB, pC, i, iy); + if (coverage == 0.0F) { + if (i == iLeft) + iLeft++; /* skip zero coverage pixels */ + else { + iRight = i; + i--; + break; /* went past right edge */ + } + } + else { + coverageSpan[i - iLeft] = coverage; + if (coverage == 1.0F) + break; + } + i++; + } + + assert(coverageSpan[i-iLeft] > 0.0 || iLeft == iRight); + + assert(i == iRight || coverage == 1.0 || coverage == 0.0); + + /* scan right to left until we hit 100% coverage or the left edge */ + j = iRight; + assert(j - iLeft >= 0); + while (1) { + coverage = compute_coveragef(pA, pB, pC, j, iy); + if (coverage == 0.0F) { + if (j == iRight && j > i) + iRight--; /* skip zero coverage pixels */ + else + break; + } + else { + if (j <= i) + break; + assert(j - iLeft >= 0); + coverageSpan[j - iLeft] = coverage; + if (coverage == 1.0F) + break; + } + /*printf("%d: coverage[%d]' = %g\n", iy, j-iLeft, coverage);*/ + j--; + } + + assert(coverageSpan[j-iLeft] > 0.0 || iRight <= iLeft); + + printf("iLeft=%d i=%d j=%d iRight=%d\n", iLeft, i, j, iRight); + + assert(iLeft >= 0); + assert(iLeft < ctx->DrawBuffer->_Xmax); + assert(iRight >= 0); + assert(iRight < ctx->DrawBuffer->_Xmax); + assert(iRight >= iLeft); + + + /* any pixels left in between must have 100% coverage */ + k = i + 1; + while (k < j) { + coverageSpan[k - iLeft] = 1.0F; + k++; + } + + len = iRight - iLeft; + /*printf("len = %d\n", len);*/ + assert(len >= 0); + assert(len < MAX_WIDTH); + + if (len == 0) + continue; + +#ifdef DEBUG + for (k = 0; k < len; k++) { + assert(coverageSpan[k] > 0.0); + } +#endif + + /* + * Compute color, texcoords, etc for the span + */ + { + const GLfloat cx = iLeft + 0.5F, cy = iy + 0.5F; #ifdef DO_Z - z[count] = (GLdepth) solve_plane(cx, cy, zPlane); + GLfloat zFrag = solve_plane(cx, cy, zPlane); + const GLfloat zStep = -zPlane[0] / zPlane[2]; #endif #ifdef DO_FOG - fog[count] = solve_plane(cx, cy, fogPlane); + GLfloat fogFrag = solve_plane(cx, cy, fogPlane); + const GLfloat fogStep = -fogPlane[0] / fogPlane[2]; #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); + /* to do */ #endif #ifdef DO_INDEX - index[count] = (GLint) solve_plane(cx, cy, iPlane); + /* to do */ #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); + /* to do */ #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); - } + GLfloat sFrag = solve_plane(cx, cy, sPlane); + GLfloat tFrag = solve_plane(cx, cy, tPlane); + GLfloat uFrag = solve_plane(cx, cy, uPlane); + GLfloat vFrag = solve_plane(cx, cy, vPlane); + const GLfloat sStep = -sPlane[0] / sPlane[2]; + const GLfloat tStep = -tPlane[0] / tPlane[2]; + const GLfloat uStep = -uPlane[0] / uPlane[2]; + const GLfloat vStep = -vPlane[0] / vPlane[2]; #elif defined(DO_MULTITEX) - { - GLuint unit; - 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]); - } - } - } -#endif - ix++; - 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); -# 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); -# 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); -# else - _mesa_write_texture_span(ctx, n, startX, iy, z, fog, - s, t, u, lambda, - rgba, NULL, coverageSpan, GL_POLYGON); -# endif -#elif defined(DO_RGBA) - _mesa_write_rgba_span(ctx, n, startX, iy, z, fog, rgba, - coverageSpan, GL_POLYGON); -#elif defined(DO_INDEX) - _mesa_write_index_span(ctx, n, startX, iy, z, fog, index, - icoverageSpan, GL_POLYGON); + /* to do */ #endif - } - } - else { - /* scan right to left */ - const GLfloat *pMin = vMin->win; - const GLfloat *pMid = vMid->win; - const GLfloat *pMax = vMax->win; - const GLfloat dxdy = majDx / majDy; - const GLfloat xAdj = dxdy > 0 ? dxdy : 0.0F; - GLfloat x = pMin[0] - (yMin - iyMin) * dxdy; - GLint iy; - for (iy = iyMin; iy < iyMax; iy++, x += dxdy) { - 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; - } + for (ix = iLeft; ix < iRight; ix++) { + const GLint k = ix - iLeft; + const GLfloat cx = ix + 0.5F, cy = iy + 0.5F; - /* skip fragments with zero coverage */ - while (startX >= 0) { - coverage = compute_coveragef(pMin, pMax, pMid, startX, iy); - if (coverage > 0.0F) - break; - startX--; - } - - /* enter interior of triangle */ - ix = startX; - count = 0; - while (coverage > 0.0F) { - /* (cx,cy) = center of fragment */ - const GLfloat cx = ix + 0.5F, cy = iy + 0.5F; -#ifdef DO_INDEX - icoverageSpan[ix] = compute_coveragei(pMin, pMid, pMax, ix, iy); -#else - coverageSpan[ix] = coverage; -#endif #ifdef DO_Z - z[ix] = (GLdepth) solve_plane(cx, cy, zPlane); + z[k] = zFrag; zFrag += zStep; #endif #ifdef DO_FOG - fog[ix] = solve_plane(cx, cy, fogPlane); + fog[k] = fogFrag; fogFrag += fogStep; #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); + rgba[k][RCOMP] = solve_plane_chan(cx, cy, rPlane); + rgba[k][GCOMP] = solve_plane_chan(cx, cy, gPlane); + rgba[k][BCOMP] = solve_plane_chan(cx, cy, bPlane); + rgba[k][ACOMP] = solve_plane_chan(cx, cy, aPlane); #endif #ifdef DO_INDEX - index[ix] = (GLint) solve_plane(cx, cy, iPlane); + index[k] = (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); + spec[k][RCOMP] = solve_plane_chan(cx, cy, srPlane); + spec[k][GCOMP] = solve_plane_chan(cx, cy, sgPlane); + spec[k][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, - texWidth, texHeight); - } + s[k] = sFrag / vFrag; + t[k] = tFrag / vFrag; + u[k] = uFrag / vFrag; + lambda[k] = compute_lambda(sPlane, tPlane, 1.0F / vFrag, + texWidth, texHeight); + sFrag += sStep; + tFrag += tStep; + uFrag += uStep; + vFrag += vStep; #elif defined(DO_MULTITEX) - { - GLuint unit; - 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]); + { + GLuint unit; + 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][k] = solve_plane(cx, cy, sPlane[unit]) * invQ; + t[unit][k] = solve_plane(cx, cy, tPlane[unit]) * invQ; + u[unit][k] = solve_plane(cx, cy, uPlane[unit]) * invQ; + lambda[unit][k] = compute_lambda(sPlane[unit], + tPlane[unit], invQ, texWidth[unit], texHeight[unit]); + } } } - } #endif - ix--; - count++; - coverage = compute_coveragef(pMin, pMax, pMid, ix, iy); + } /* for ix */ } - if (startX <= ix) - continue; - - n = (GLuint) startX - (GLuint) ix; - - left = ix + 1; + /* + * Write/process the span of fragments. + */ #ifdef DO_MULTITEX - { - GLuint unit; - for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { - 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]; - } - } - } - } -# ifdef DO_SPEC - _mesa_write_multitexture_span(ctx, n, left, iy, z + left, fog + left, + _mesa_write_multitexture_span(ctx, len, iLeft, iy, z, fog, (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); + (GLfloat (*)[MAX_WIDTH]) lambda, + rgba, +# ifdef DO_SPEC + (const GLchan (*)[4]) spec, # 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); + NULL, # endif + coverageSpan, GL_POLYGON); #elif defined(DO_TEX) + _mesa_write_texture_span(ctx, len, iLeft, iy, z, fog, + s, t, u, lambda, rgba, # 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); + (const GLchan (*)[4]) spec, # 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); + NULL, # endif + coverageSpan, GL_POLYGON); #elif defined(DO_RGBA) - _mesa_write_rgba_span(ctx, n, left, iy, z + left, fog + left, - rgba + left, coverageSpan + left, GL_POLYGON); + _mesa_write_rgba_span(ctx, len, iLeft, iy, z, fog, rgba, + coverageSpan, GL_POLYGON); #elif defined(DO_INDEX) - _mesa_write_index_span(ctx, n, left, iy, z + left, fog + left, - index + left, icoverageSpan + left, GL_POLYGON); + _mesa_write_index_span(ctx, len, iLeft, iy, z, fog, index, + icoverageSpan, GL_POLYGON); #endif - } + + } /* for iy */ } + #ifdef DO_RGBA UNDEFARRAY(rgba); /* mac 32k limitation */ #endif diff --git a/src/mesa/swrast/s_accum.c b/src/mesa/swrast/s_accum.c index 7a10b4b4b98..6d3e2feb6ab 100644 --- a/src/mesa/swrast/s_accum.c +++ b/src/mesa/swrast/s_accum.c @@ -1,4 +1,4 @@ -/* $Id: s_accum.c,v 1.11 2001/04/20 19:21:41 brianp Exp $ */ +/* $Id: s_accum.c,v 1.12 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -108,8 +108,7 @@ static void rescale_accum( GLcontext *ctx ) { SWcontext *swrast = SWRAST_CONTEXT(ctx); const GLuint n = ctx->DrawBuffer->Width * ctx->DrawBuffer->Height * 4; - const GLfloat fChanMax = (1 << (sizeof(GLchan) * 8)) - 1; - const GLfloat s = swrast->_IntegerAccumScaler * (32767.0 / fChanMax); + const GLfloat s = swrast->_IntegerAccumScaler * (32767.0 / CHAN_MAXF); GLaccum *accum = ctx->DrawBuffer->Accum; GLuint i; @@ -150,8 +149,7 @@ _mesa_clear_accum_buffer( GLcontext *ctx ) acc_scale = 32767.0; } else { - /* sizeof(GLaccum) > 2 (Cray) */ - acc_scale = (float) SHRT_MAX; + acc_scale = 1.0F; } /* number of pixels */ @@ -166,14 +164,13 @@ _mesa_clear_accum_buffer( GLcontext *ctx ) if (ctx->DrawBuffer->Accum) { if (ctx->Scissor.Enabled) { /* Limit clear to scissor box */ - GLaccum r, g, b, a; + const GLaccum r = (GLaccum) (ctx->Accum.ClearColor[0] * acc_scale); + const GLaccum g = (GLaccum) (ctx->Accum.ClearColor[1] * acc_scale); + const GLaccum b = (GLaccum) (ctx->Accum.ClearColor[2] * acc_scale); + const GLaccum a = (GLaccum) (ctx->Accum.ClearColor[3] * acc_scale); GLint i, j; GLint width, height; GLaccum *row; - r = (GLaccum) (ctx->Accum.ClearColor[0] * acc_scale); - g = (GLaccum) (ctx->Accum.ClearColor[1] * acc_scale); - b = (GLaccum) (ctx->Accum.ClearColor[2] * acc_scale); - a = (GLaccum) (ctx->Accum.ClearColor[3] * acc_scale); /* size of region to clear */ width = 4 * (ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin); height = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin; @@ -202,14 +199,12 @@ _mesa_clear_accum_buffer( GLcontext *ctx ) } else { /* Not black */ - GLaccum *acc, r, g, b, a; + const GLaccum r = (GLaccum) (ctx->Accum.ClearColor[0] * acc_scale); + const GLaccum g = (GLaccum) (ctx->Accum.ClearColor[1] * acc_scale); + const GLaccum b = (GLaccum) (ctx->Accum.ClearColor[2] * acc_scale); + const GLaccum a = (GLaccum) (ctx->Accum.ClearColor[3] * acc_scale); + GLaccum *acc = ctx->DrawBuffer->Accum; GLuint i; - - acc = ctx->DrawBuffer->Accum; - r = (GLaccum) (ctx->Accum.ClearColor[0] * acc_scale); - g = (GLaccum) (ctx->Accum.ClearColor[1] * acc_scale); - b = (GLaccum) (ctx->Accum.ClearColor[2] * acc_scale); - a = (GLaccum) (ctx->Accum.ClearColor[3] * acc_scale); for (i=0;i<buffersize;i++) { *acc++ = r; *acc++ = g; @@ -247,8 +242,6 @@ _swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value, GLfloat acc_scale; GLchan rgba[MAX_WIDTH][4]; const GLuint colorMask = *((GLuint *) &ctx->Color.ColorMask); - const GLint iChanMax = (1 << (sizeof(GLchan) * 8)) - 1; - const GLfloat fChanMax = (1 << (sizeof(GLchan) * 8)) - 1; if (SWRAST_CONTEXT(ctx)->NewState) @@ -268,8 +261,7 @@ _swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value, acc_scale = 32767.0; } else { - /* sizeof(GLaccum) > 2 (Cray) */ - acc_scale = (float) SHRT_MAX; + acc_scale = 1.0F; } width4 = 4 * width; @@ -277,16 +269,16 @@ _swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value, switch (op) { case GL_ADD: if (value != 0.0F) { - const GLaccum intVal = (GLaccum) (value * acc_scale); + const GLaccum val = (GLaccum) (value * acc_scale); GLint j; /* Leave optimized accum buffer mode */ if (swrast->_IntegerAccumMode) rescale_accum(ctx); for (j = 0; j < height; j++) { - GLaccum * acc = ctx->DrawBuffer->Accum + ypos * width4 + 4 * xpos; + GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + 4*xpos; GLuint i; for (i = 0; i < width4; i++) { - acc[i] += intVal; + acc[i] += val; } ypos++; } @@ -346,21 +338,22 @@ _swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value, } } else { - /* scaled integer accum buffer */ - const GLfloat rscale = value * acc_scale / fChanMax; - const GLfloat gscale = value * acc_scale / fChanMax; - const GLfloat bscale = value * acc_scale / fChanMax; - const GLfloat ascale = value * acc_scale / fChanMax; + /* scaled integer (or float) accum buffer */ + const GLfloat rscale = value * acc_scale / CHAN_MAXF; + const GLfloat gscale = value * acc_scale / CHAN_MAXF; + const GLfloat bscale = value * acc_scale / CHAN_MAXF; + const GLfloat ascale = value * acc_scale / CHAN_MAXF; GLint j; for (j=0;j<height;j++) { GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4; GLint i; _mesa_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba); for (i=0;i<width;i++) { - *acc += (GLaccum) ( (GLfloat) rgba[i][RCOMP] * rscale ); acc++; - *acc += (GLaccum) ( (GLfloat) rgba[i][GCOMP] * gscale ); acc++; - *acc += (GLaccum) ( (GLfloat) rgba[i][BCOMP] * bscale ); acc++; - *acc += (GLaccum) ( (GLfloat) rgba[i][ACOMP] * ascale ); acc++; + acc[0] += (GLaccum) ( (GLfloat) rgba[i][RCOMP] * rscale ); + acc[1] += (GLaccum) ( (GLfloat) rgba[i][GCOMP] * gscale ); + acc[2] += (GLaccum) ( (GLfloat) rgba[i][BCOMP] * bscale ); + acc[3] += (GLaccum) ( (GLfloat) rgba[i][ACOMP] * ascale ); + acc += 4; } ypos++; } @@ -410,21 +403,30 @@ _swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value, } } else { - /* scaled integer accum buffer */ - const GLfloat rscale = value * acc_scale / fChanMax; - const GLfloat gscale = value * acc_scale / fChanMax; - const GLfloat bscale = value * acc_scale / fChanMax; - const GLfloat ascale = value * acc_scale / fChanMax; - const GLfloat d = 3.0 / acc_scale; + /* scaled integer (or float) accum buffer */ + const GLfloat rscale = value * acc_scale / CHAN_MAXF; + const GLfloat gscale = value * acc_scale / CHAN_MAXF; + const GLfloat bscale = value * acc_scale / CHAN_MAXF; + const GLfloat ascale = value * acc_scale / CHAN_MAXF; +#if 0 + const GLfloat d = 3.0 / acc_scale; /* XXX what's this? */ +#endif GLint i, j; for (j = 0; j < height; j++) { GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos * 4; _mesa_read_rgba_span(ctx, ctx->DrawBuffer, width, xpos, ypos, rgba); for (i=0;i<width;i++) { +#if 0 *acc++ = (GLaccum) ((GLfloat) rgba[i][RCOMP] * rscale + d); *acc++ = (GLaccum) ((GLfloat) rgba[i][GCOMP] * gscale + d); *acc++ = (GLaccum) ((GLfloat) rgba[i][BCOMP] * bscale + d); *acc++ = (GLaccum) ((GLfloat) rgba[i][ACOMP] * ascale + d); +#else + *acc++ = (GLaccum) ((GLfloat) rgba[i][RCOMP] * rscale); + *acc++ = (GLaccum) ((GLfloat) rgba[i][GCOMP] * gscale); + *acc++ = (GLaccum) ((GLfloat) rgba[i][BCOMP] * bscale); + *acc++ = (GLaccum) ((GLfloat) rgba[i][ACOMP] * ascale); +#endif } ypos++; } @@ -442,6 +444,7 @@ _swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value, rescale_accum(ctx); RENDER_START(swrast,ctx); +#ifdef USE_OPTIMIZED_ACCUM if (swrast->_IntegerAccumMode && swrast->_IntegerAccumScaler > 0) { /* build lookup table to avoid many floating point multiplies */ static GLchan multTable[32768]; @@ -483,11 +486,14 @@ _swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value, ypos++; } } - else { - const GLfloat rscale = value / acc_scale * fChanMax; - const GLfloat gscale = value / acc_scale * fChanMax; - const GLfloat bscale = value / acc_scale * fChanMax; - const GLfloat ascale = value / acc_scale * fChanMax; + else +#endif /* USE_OPTIMIZED_ACCUM */ + { + /* scaled integer (or float) accum buffer */ + const GLfloat rscale = value / acc_scale * CHAN_MAXF; + const GLfloat gscale = value / acc_scale * CHAN_MAXF; + const GLfloat bscale = value / acc_scale * CHAN_MAXF; + const GLfloat ascale = value / acc_scale * CHAN_MAXF; GLint i, j; for (j=0;j<height;j++) { const GLaccum *acc = ctx->DrawBuffer->Accum + ypos * width4 + xpos*4; @@ -497,10 +503,10 @@ _swrast_Accum( GLcontext *ctx, GLenum op, GLfloat value, GLint b = IROUND( (GLfloat) (acc[2]) * bscale ); GLint a = IROUND( (GLfloat) (acc[3]) * ascale ); acc += 4; - rgba[i][RCOMP] = CLAMP( r, 0, iChanMax ); - rgba[i][GCOMP] = CLAMP( g, 0, iChanMax ); - rgba[i][BCOMP] = CLAMP( b, 0, iChanMax ); - rgba[i][ACOMP] = CLAMP( a, 0, iChanMax ); + rgba[i][RCOMP] = CLAMP( r, 0, CHAN_MAX ); + rgba[i][GCOMP] = CLAMP( g, 0, CHAN_MAX ); + rgba[i][BCOMP] = CLAMP( b, 0, CHAN_MAX ); + rgba[i][ACOMP] = CLAMP( a, 0, CHAN_MAX ); } if (colorMask != 0xffffffff) { _mesa_mask_rgba_span( ctx, width, xpos, ypos, rgba ); diff --git a/src/mesa/swrast/s_alphabuf.c b/src/mesa/swrast/s_alphabuf.c index 8c324a4588a..2a066aeee70 100644 --- a/src/mesa/swrast/s_alphabuf.c +++ b/src/mesa/swrast/s_alphabuf.c @@ -1,4 +1,4 @@ -/* $Id: s_alphabuf.c,v 1.7 2001/05/11 18:58:32 brianp Exp $ */ +/* $Id: s_alphabuf.c,v 1.8 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -162,8 +162,8 @@ _mesa_clear_alpha_buffers( GLcontext *ctx ) if (ctx->Scissor.Enabled) { /* clear scissor region */ GLint j; - GLint rowLen = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin + 1; - GLint rows = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin + 1; + GLint rowLen = ctx->DrawBuffer->_Xmax - ctx->DrawBuffer->_Xmin; + GLint rows = ctx->DrawBuffer->_Ymax - ctx->DrawBuffer->_Ymin; GLint width = ctx->DrawBuffer->Width; GLchan *aptr = buffer + ctx->DrawBuffer->_Ymin * ctx->DrawBuffer->Width @@ -174,7 +174,10 @@ _mesa_clear_alpha_buffers( GLcontext *ctx ) #elif CHAN_BITS == 16 MEMSET16( aptr, aclear, rowLen ); #else -#error unexpected CHAN_BITS value + GLint i; + for (i = 0; i < rowLen; i++) { + aptr[i] = aclear; + } #endif aptr += width; } @@ -187,7 +190,10 @@ _mesa_clear_alpha_buffers( GLcontext *ctx ) #elif CHAN_BITS == 16 MEMSET16(buffer, aclear, pixels); #else -#error unexpected CHAN_BITS value + GLuint i; + for (i = 0; i < pixels; i++) { + buffer[i] = aclear; + } #endif } } diff --git a/src/mesa/swrast/s_blend.c b/src/mesa/swrast/s_blend.c index 73ca3d1c52d..3c0e64a5fe8 100644 --- a/src/mesa/swrast/s_blend.c +++ b/src/mesa/swrast/s_blend.c @@ -1,4 +1,4 @@ -/* $Id: s_blend.c,v 1.7 2001/03/19 02:25:36 keithw Exp $ */ +/* $Id: s_blend.c,v 1.8 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -216,6 +216,12 @@ blend_modulate( GLcontext *ctx, GLuint n, const GLubyte mask[], for (i=0;i<n;i++) { if (mask[i]) { +#if CHAN_TYPE == GL_FLOAT + rgba[i][RCOMP] = rgba[i][RCOMP] * dest[i][RCOMP]; + rgba[i][GCOMP] = rgba[i][GCOMP] * dest[i][GCOMP]; + rgba[i][BCOMP] = rgba[i][BCOMP] * dest[i][BCOMP]; + rgba[i][ACOMP] = rgba[i][ACOMP] * dest[i][ACOMP]; +#else GLint r = (rgba[i][RCOMP] * dest[i][RCOMP]) >> 8; GLint g = (rgba[i][GCOMP] * dest[i][GCOMP]) >> 8; GLint b = (rgba[i][BCOMP] * dest[i][BCOMP]) >> 8; @@ -224,6 +230,7 @@ blend_modulate( GLcontext *ctx, GLuint n, const GLubyte mask[], rgba[i][GCOMP] = (GLchan) g; rgba[i][BCOMP] = (GLchan) b; rgba[i][ACOMP] = (GLchan) a; +#endif } } } diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c index 354d809e08d..200db7cd2d3 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.22 2001/07/12 22:09:21 keithw Exp $ */ +/* $Id: s_context.c,v 1.23 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -547,10 +547,17 @@ _swrast_print_vertex( GLcontext *ctx, const SWvertex *v ) v->texcoord[i][0], v->texcoord[i][1], v->texcoord[i][2], v->texcoord[i][3]); +#if CHAN_TYPE == GL_FLOAT + fprintf(stderr, "color %f %f %f %f\n", + v->color[0], v->color[1], v->color[2], v->color[3]); + fprintf(stderr, "spec %f %f %f %f\n", + v->specular[0], v->specular[1], v->specular[2], v->specular[3]); +#else fprintf(stderr, "color %d %d %d %d\n", v->color[0], v->color[1], v->color[2], v->color[3]); fprintf(stderr, "spec %d %d %d %d\n", v->specular[0], v->specular[1], v->specular[2], v->specular[3]); +#endif fprintf(stderr, "fog %f\n", v->fog); fprintf(stderr, "index %d\n", v->index); fprintf(stderr, "pointsize %f\n", v->pointSize); diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h index 03f6961001a..5aad31683ba 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.10 2001/05/17 09:32:17 keithw Exp $ */ +/* $Id: s_context.h,v 1.11 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -167,25 +167,39 @@ typedef struct } SWcontext; -void +extern void _swrast_validate_derived( GLcontext *ctx ); #define SWRAST_CONTEXT(ctx) ((SWcontext *)ctx->swrast_context) #define RENDER_START(SWctx, GLctx) \ - do { \ + do { \ if ((SWctx)->Driver.SpanRenderStart) { \ (*(SWctx)->Driver.SpanRenderStart)(GLctx); \ - } \ + } \ } while (0) #define RENDER_FINISH(SWctx, GLctx) \ - do { \ + do { \ if ((SWctx)->Driver.SpanRenderFinish) { \ (*(SWctx)->Driver.SpanRenderFinish)(GLctx); \ - } \ + } \ } while (0) + +/* + * XXX these macros are just bandages for now in order to make + * CHAN_BITS==32 compile cleanly. + * These should probably go elsewhere at some point. + */ +#if CHAN_TYPE == GL_FLOAT +#define ChanToFixed(X) FloatToFixed(X) +#define FixedToChan(X) FixedToFloat(X) +#else +#define ChanToFixed(X) IntToFixed(X) +#define FixedToChan(X) FixedToInt(X) +#endif + #endif diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c index dcdf2e16f0f..df2b91b7200 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.22 2001/07/13 15:24:34 brianp Exp $ */ +/* $Id: s_copypix.c,v 1.23 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -814,7 +814,7 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy, } else { _mesa_write_rgba_span( ctx, width, destx, dy, zspan, fogSpan, - rgba, NULL, GL_BITMAP); + (GLchan (*)[4])rgba, NULL, GL_BITMAP); } } else { diff --git a/src/mesa/swrast/s_linetemp.h b/src/mesa/swrast/s_linetemp.h index f8fa310d765..06356943408 100644 --- a/src/mesa/swrast/s_linetemp.h +++ b/src/mesa/swrast/s_linetemp.h @@ -1,4 +1,4 @@ -/* $Id: s_linetemp.h,v 1.8 2001/05/03 22:13:32 brianp Exp $ */ +/* $Id: s_linetemp.h,v 1.9 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -99,24 +99,24 @@ GLfloat dfog = vert1->fog - fog0; #endif #ifdef INTERP_RGB - GLfixed r0 = IntToFixed(vert0->color[0]); - GLfixed dr = IntToFixed(vert1->color[0]) - r0; - GLfixed g0 = IntToFixed(vert0->color[1]); - GLfixed dg = IntToFixed(vert1->color[1]) - g0; - GLfixed b0 = IntToFixed(vert0->color[2]); - GLfixed db = IntToFixed(vert1->color[2]) - b0; + GLfixed r0 = ChanToFixed(vert0->color[0]); + GLfixed dr = ChanToFixed(vert1->color[0]) - r0; + GLfixed g0 = ChanToFixed(vert0->color[1]); + GLfixed dg = ChanToFixed(vert1->color[1]) - g0; + GLfixed b0 = ChanToFixed(vert0->color[2]); + GLfixed db = ChanToFixed(vert1->color[2]) - b0; #endif #ifdef INTERP_SPEC - GLfixed sr0 = IntToFixed(vert0->specular[0]); - GLfixed dsr = IntToFixed(vert1->specular[0]) - sr0; - GLfixed sg0 = IntToFixed(vert0->specular[1]); - GLfixed dsg = IntToFixed(vert1->specular[1]) - sg0; - GLfixed sb0 = IntToFixed(vert0->specular[2]); - GLfixed dsb = IntToFixed(vert1->specular[2]) - sb0; + GLfixed sr0 = ChanToFixed(vert0->specular[0]); + GLfixed dsr = ChanToFixed(vert1->specular[0]) - sr0; + GLfixed sg0 = ChanToFixed(vert0->specular[1]); + GLfixed dsg = ChanToFixed(vert1->specular[1]) - sg0; + GLfixed sb0 = ChanToFixed(vert0->specular[2]); + GLfixed dsb = ChanToFixed(vert1->specular[2]) - sb0; #endif #ifdef INTERP_ALPHA - GLfixed a0 = IntToFixed(vert0->color[3]); - GLfixed da = IntToFixed(vert1->color[3]) - a0; + GLfixed a0 = ChanToFixed(vert0->color[3]); + GLfixed da = ChanToFixed(vert1->color[3]) - a0; #endif #ifdef INTERP_INDEX GLint i0 = vert0->index << 8; diff --git a/src/mesa/swrast/s_logic.c b/src/mesa/swrast/s_logic.c index adc885ebdf0..9d61230e63d 100644 --- a/src/mesa/swrast/s_logic.c +++ b/src/mesa/swrast/s_logic.c @@ -1,4 +1,4 @@ -/* $Id: s_logic.c,v 1.7 2001/05/10 16:54:12 brianp Exp $ */ +/* $Id: s_logic.c,v 1.8 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -334,9 +334,19 @@ static void rgba_logicop_ui( const GLcontext *ctx, GLuint n, */ static void rgba_logicop_chan( const GLcontext *ctx, GLuint n, const GLubyte mask[], - GLchan src[], const GLchan dest[] ) + GLchan srcPtr[], const GLchan destPtr[] ) { +#if CHAN_TYPE == GL_FLOAT + GLuint *src = (GLuint *) srcPtr; + const GLuint *dest = (const GLuint *) destPtr; GLuint i; + ASSERT(sizeof(GLfloat) == sizeof(GLuint)); +#else + GLchan *src = srcPtr; + const GLchan *dest = destPtr; + GLuint i; +#endif + switch (ctx->Color.LogicOp) { case GL_CLEAR: for (i=0;i<n;i++) { diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c index 1520fd079d0..f659eaa8184 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.32 2001/06/01 13:23:27 brianp Exp $ */ +/* $Id: s_texture.c,v 1.33 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -1803,6 +1803,13 @@ texture_combine(const GLcontext *ctx, GLuint i, j; const GLuint RGBshift = textureUnit->CombineScaleShiftRGB; const GLuint Ashift = textureUnit->CombineScaleShiftA; +#if CHAN_TYPE == GL_FLOAT + const GLchan RGBmult = (GLfloat) (1 << RGBshift); + const GLchan Amult = (GLfloat) (1 << Ashift); +#else + const GLint half = (CHAN_MAX + 1) / 2; +#endif + DEFMNARRAY(GLchan, ccolor, 3, 3 * MAX_WIDTH, 4); /* mac 32k limitation */ CHECKARRAY(ccolor, return); /* mac 32k limitation */ @@ -1928,9 +1935,15 @@ texture_combine(const GLcontext *ctx, const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; if (RGBshift) { for (i = 0; i < n; i++) { +#if CHAN_TYPE == GL_FLOAT + GLchan r = arg0[i][RCOMP] * RGBmult; + GLchan g = arg0[i][GCOMP] * RGBmult; + GLchan b = arg0[i][BCOMP] * RGBmult; +#else GLuint r = (GLuint) arg0[i][RCOMP] << RGBshift; GLuint g = (GLuint) arg0[i][GCOMP] << RGBshift; GLuint b = (GLuint) arg0[i][BCOMP] << RGBshift; +#endif rgba[i][RCOMP] = MIN2(r, CHAN_MAX); rgba[i][GCOMP] = MIN2(g, CHAN_MAX); rgba[i][BCOMP] = MIN2(b, CHAN_MAX); @@ -1949,11 +1962,19 @@ texture_combine(const GLcontext *ctx, { const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; +#if CHAN_TYPE != GL_FLOAT const GLint shift = 8 - RGBshift; +#endif for (i = 0; i < n; i++) { - GLuint r = PROD(arg0[i][0], arg1[i][RCOMP]) >> shift; - GLuint g = PROD(arg0[i][1], arg1[i][GCOMP]) >> shift; - GLuint b = PROD(arg0[i][2], arg1[i][BCOMP]) >> shift; +#if CHAN_TYPE == GL_FLOAT + GLchan r = arg0[i][RCOMP] * arg1[i][RCOMP] * RGBmult; + GLuint g = arg0[i][GCOMP] * arg1[i][GCOMP] * RGBmult; + GLuint b = arg0[i][BCOMP] * arg1[i][BCOMP] * RGBmult; +#else + GLuint r = PROD(arg0[i][RCOMP], arg1[i][RCOMP]) >> shift; + GLuint g = PROD(arg0[i][GCOMP], arg1[i][GCOMP]) >> shift; + GLuint b = PROD(arg0[i][BCOMP], arg1[i][BCOMP]) >> shift; +#endif rgba[i][RCOMP] = (GLchan) MIN2(r, CHAN_MAX); rgba[i][GCOMP] = (GLchan) MIN2(g, CHAN_MAX); rgba[i][BCOMP] = (GLchan) MIN2(b, CHAN_MAX); @@ -1965,9 +1986,15 @@ texture_combine(const GLcontext *ctx, const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; for (i = 0; i < n; i++) { +#if CHAN_TYPE == GL_FLOAT + GLchan r = (arg0[i][RCOMP] + arg1[i][RCOMP]) * RGBmult; + GLchan g = (arg0[i][GCOMP] + arg1[i][GCOMP]) * RGBmult; + GLchan b = (arg0[i][BCOMP] + arg1[i][BCOMP]) * RGBmult; +#else GLint r = ((GLint) arg0[i][RCOMP] + (GLint) arg1[i][RCOMP]) << RGBshift; GLint g = ((GLint) arg0[i][GCOMP] + (GLint) arg1[i][GCOMP]) << RGBshift; GLint b = ((GLint) arg0[i][BCOMP] + (GLint) arg1[i][BCOMP]) << RGBshift; +#endif rgba[i][RCOMP] = (GLchan) MIN2(r, CHAN_MAX); rgba[i][GCOMP] = (GLchan) MIN2(g, CHAN_MAX); rgba[i][BCOMP] = (GLchan) MIN2(b, CHAN_MAX); @@ -1979,12 +2006,18 @@ texture_combine(const GLcontext *ctx, const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; for (i = 0; i < n; i++) { - GLint r = (GLint) arg0[i][RCOMP] + (GLint) arg1[i][RCOMP] - 128; - GLint g = (GLint) arg0[i][GCOMP] + (GLint) arg1[i][GCOMP] - 128; - GLint b = (GLint) arg0[i][BCOMP] + (GLint) arg1[i][BCOMP] - 128; +#if CHAN_TYPE == GL_FLOAT + GLchan r = (arg0[i][RCOMP] + arg1[i][RCOMP] - 0.5) * RGBmult; + GLchan g = (arg0[i][GCOMP] + arg1[i][GCOMP] - 0.5) * RGBmult; + GLchan b = (arg0[i][BCOMP] + arg1[i][BCOMP] - 0.5) * RGBmult; +#else + GLint r = (GLint) arg0[i][RCOMP] + (GLint) arg1[i][RCOMP] -half; + GLint g = (GLint) arg0[i][GCOMP] + (GLint) arg1[i][GCOMP] -half; + GLint b = (GLint) arg0[i][BCOMP] + (GLint) arg1[i][BCOMP] -half; r = (r < 0) ? 0 : r << RGBshift; g = (g < 0) ? 0 : g << RGBshift; b = (b < 0) ? 0 : b << RGBshift; +#endif rgba[i][RCOMP] = (GLchan) MIN2(r, CHAN_MAX); rgba[i][GCOMP] = (GLchan) MIN2(g, CHAN_MAX); rgba[i][BCOMP] = (GLchan) MIN2(b, CHAN_MAX); @@ -1996,8 +2029,18 @@ texture_combine(const GLcontext *ctx, const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; const GLchan (*arg2)[4] = (const GLchan (*)[4]) argRGB[2]; +#if CHAN_TYPE != GL_FLOAT const GLint shift = 8 - RGBshift; +#endif for (i = 0; i < n; i++) { +#if CHAN_TYPE == GL_FLOAT + GLchan r = (arg0[i][RCOMP] * arg2[i][RCOMP] + + arg1[i][RCOMP] * (CHAN_MAXF - arg2[i][RCOMP])) * RGBmult; + GLchan g = (arg0[i][GCOMP] * arg2[i][GCOMP] + + arg1[i][GCOMP] * (CHAN_MAXF - arg2[i][GCOMP])) * RGBmult; + GLchan b = (arg0[i][BCOMP] * arg2[i][BCOMP] + + arg1[i][BCOMP] * (CHAN_MAXF - arg2[i][BCOMP])) * RGBmult; +#else GLuint r = (PROD(arg0[i][RCOMP], arg2[i][RCOMP]) + PROD(arg1[i][RCOMP], CHAN_MAX - arg2[i][RCOMP])) >> shift; @@ -2007,6 +2050,7 @@ texture_combine(const GLcontext *ctx, GLuint b = (PROD(arg0[i][BCOMP], arg2[i][BCOMP]) + PROD(arg1[i][BCOMP], CHAN_MAX - arg2[i][BCOMP])) >> shift; +#endif rgba[i][RCOMP] = (GLchan) MIN2(r, CHAN_MAX); rgba[i][GCOMP] = (GLchan) MIN2(g, CHAN_MAX); rgba[i][BCOMP] = (GLchan) MIN2(b, CHAN_MAX); @@ -2018,9 +2062,15 @@ texture_combine(const GLcontext *ctx, const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; for (i = 0; i < n; i++) { +#if CHAN_TYPE == GL_FLOAT + GLchan r = (arg0[i][RCOMP] - arg1[i][RCOMP]) * RGBmult; + GLchan g = (arg0[i][GCOMP] - arg1[i][GCOMP]) * RGBmult; + GLchan b = (arg0[i][BCOMP] - arg1[i][BCOMP]) * RGBmult; +#else GLint r = ((GLint) arg0[i][RCOMP] - (GLint) arg1[i][RCOMP]) << RGBshift; GLint g = ((GLint) arg0[i][GCOMP] - (GLint) arg1[i][GCOMP]) << RGBshift; GLint b = ((GLint) arg0[i][BCOMP] - (GLint) arg1[i][BCOMP]) << RGBshift; +#endif rgba[i][RCOMP] = (GLchan) CLAMP(r, 0, CHAN_MAX); rgba[i][GCOMP] = (GLchan) CLAMP(g, 0, CHAN_MAX); rgba[i][BCOMP] = (GLchan) CLAMP(b, 0, CHAN_MAX); @@ -2039,13 +2089,20 @@ texture_combine(const GLcontext *ctx, * drop the EXT extension in favour of the ARB one. */ for (i = 0; i < n; i++) { - GLint dot = (S_PROD((GLint)arg0[i][RCOMP] - 128, - (GLint)arg1[i][RCOMP] - 128) + - S_PROD((GLint)arg0[i][GCOMP] - 128, - (GLint)arg1[i][GCOMP] - 128) + - S_PROD((GLint)arg0[i][BCOMP] - 128, - (GLint)arg1[i][BCOMP] - 128)) >> 6; - dot = CLAMP(dot, 0, 255); +#if CHAN_TYPE == GL_FLOAT + GLchan dot = ((arg0[i][RCOMP]-0.5F) * (arg1[i][RCOMP]-0.5F) + + (arg0[i][GCOMP]-0.5F) * (arg1[i][GCOMP]-0.5F) + + (arg0[i][BCOMP]-0.5F) * (arg1[i][BCOMP]-0.5F)) + * 4.0F; +#else + GLint dot = (S_PROD((GLint)arg0[i][RCOMP] - half, + (GLint)arg1[i][RCOMP] - half) + + S_PROD((GLint)arg0[i][GCOMP] - half, + (GLint)arg1[i][GCOMP] - half) + + S_PROD((GLint)arg0[i][BCOMP] - half, + (GLint)arg1[i][BCOMP] - half)) >> 6; +#endif + dot = CLAMP(dot, 0, CHAN_MAX); rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = (GLchan) dot; } } @@ -2060,7 +2117,11 @@ texture_combine(const GLcontext *ctx, const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; if (Ashift) { for (i = 0; i < n; i++) { +#if CHAN_TYPE == GL_FLOAT + GLchan a = arg0[i][ACOMP] * Amult; +#else GLuint a = (GLuint) arg0[i][ACOMP] << Ashift; +#endif rgba[i][ACOMP] = (GLchan) MIN2(a, CHAN_MAX); } } @@ -2075,9 +2136,15 @@ texture_combine(const GLcontext *ctx, { const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; const GLchan (*arg1)[4] = (const GLchan (*)[4]) argA[1]; +#if CHAN_TYPE != GL_FLOAT const GLint shift = 8 - Ashift; +#endif for (i = 0; i < n; i++) { +#if CHAN_TYPE == GL_FLOAT + GLchan a = arg0[i][ACOMP] * arg1[i][ACOMP] * Amult; +#else GLuint a = (PROD(arg0[i][ACOMP], arg1[i][ACOMP]) >> shift); +#endif rgba[i][ACOMP] = (GLchan) MIN2(a, CHAN_MAX); } } @@ -2087,8 +2154,13 @@ texture_combine(const GLcontext *ctx, const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; const GLchan (*arg1)[4] = (const GLchan (*)[4]) argA[1]; for (i = 0; i < n; i++) { +#if CHAN_TYPE == GL_FLOAT + GLchan a = (arg0[i][ACOMP] + arg1[i][ACOMP]) * Amult; + rgba[i][ACOMP] = (GLchan) MIN2(a, CHAN_MAXF); +#else GLint a = ((GLint) arg0[i][ACOMP] + arg1[i][ACOMP]) << Ashift; rgba[i][ACOMP] = (GLchan) MIN2(a, CHAN_MAX); +#endif } } break; @@ -2097,8 +2169,12 @@ texture_combine(const GLcontext *ctx, const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; const GLchan (*arg1)[4] = (const GLchan (*)[4]) argA[1]; for (i = 0; i < n; i++) { - GLint a = (GLint) arg0[i][ACOMP] + (GLint) arg1[i][ACOMP] - 128; +#if CHAN_TYPE == GL_FLOAT + GLchan a = (arg0[i][ACOMP] + arg1[i][ACOMP] - 0.5F) * Amult; +#else + GLint a = (GLint) arg0[i][ACOMP] + (GLint) arg1[i][ACOMP] -half; a = (a < 0) ? 0 : a << Ashift; +#endif rgba[i][ACOMP] = (GLchan) MIN2(a, CHAN_MAX); } } @@ -2108,11 +2184,19 @@ texture_combine(const GLcontext *ctx, const GLchan (*arg0)[4] = (const GLchan (*)[4]) argA[0]; const GLchan (*arg1)[4] = (const GLchan (*)[4]) argA[1]; const GLchan (*arg2)[4] = (const GLchan (*)[4]) argA[2]; +#if CHAN_TYPE != GL_FLOAT const GLint shift = 8 - Ashift; +#endif for (i=0; i<n; i++) { +#if CHAN_TYPE == GL_FLOAT + GLchan a = (arg0[i][ACOMP] * arg2[i][ACOMP] + + arg1[i][ACOMP] * (CHAN_MAXF - arg2[i][ACOMP])) + * Amult; +#else GLuint a = (PROD(arg0[i][ACOMP], arg2[i][ACOMP]) + PROD(arg1[i][ACOMP], CHAN_MAX - arg2[i][ACOMP])) >> shift; +#endif rgba[i][ACOMP] = (GLchan) MIN2(a, CHAN_MAX); } } @@ -2122,7 +2206,11 @@ texture_combine(const GLcontext *ctx, const GLchan (*arg0)[4] = (const GLchan (*)[4]) argRGB[0]; const GLchan (*arg1)[4] = (const GLchan (*)[4]) argRGB[1]; for (i = 0; i < n; i++) { +#if CHAN_TYPE == GL_FLOAT + GLchan a = (arg0[i][ACOMP] - arg1[i][ACOMP]) * Amult; +#else GLint a = ((GLint) arg0[i][ACOMP] - (GLint) arg1[i][ACOMP]) << RGBshift; +#endif rgba[i][ACOMP] = (GLchan) CLAMP(a, 0, CHAN_MAX); } } diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c index b08830d3866..231801fbc23 100644 --- a/src/mesa/swrast/s_triangle.c +++ b/src/mesa/swrast/s_triangle.c @@ -1,4 +1,4 @@ -/* $Id: s_triangle.c,v 1.32 2001/07/09 16:24:30 brianp Exp $ */ +/* $Id: s_triangle.c,v 1.33 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -329,6 +329,7 @@ static void simple_z_textured_triangle( GLcontext *ctx, } +#if CHAN_TYPE != GL_FLOAT struct affine_info { @@ -682,6 +683,8 @@ static void affine_textured_triangle( GLcontext *ctx, } +#endif /* CHAN_BITS != GL_FLOAT */ + struct persp_info { @@ -696,6 +699,7 @@ struct persp_info GLint fixedToDepthShift; }; + static void fast_persp_span(GLcontext *ctx, struct triangle_span *span, struct persp_info *info) @@ -707,7 +711,6 @@ fast_persp_span(GLcontext *ctx, struct triangle_span *span, * and complexity. Observe that an optimizing compiler kills * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST). */ - #define SPAN_NEAREST(DO_TEX,COMP) \ for (i = 0; i < span->count; i++) { \ GLdouble invQ = tex_coord[2] ? \ @@ -1285,10 +1288,10 @@ static void general_textured_triangle( GLcontext *ctx, CHECKARRAY(tSpan, return); /* mac 32k limitation */ \ CHECKARRAY(uSpan, return); /* mac 32k limitation */ \ if (flatShade) { \ - rFlat = IntToFixed(v2->color[RCOMP]); \ - gFlat = IntToFixed(v2->color[GCOMP]); \ - bFlat = IntToFixed(v2->color[BCOMP]); \ - aFlat = IntToFixed(v2->color[ACOMP]); \ + rFlat = ChanToFixed(v2->color[RCOMP]); \ + gFlat = ChanToFixed(v2->color[GCOMP]); \ + bFlat = ChanToFixed(v2->color[BCOMP]); \ + aFlat = ChanToFixed(v2->color[ACOMP]); \ } \ span.texWidth[0] = (GLfloat) texImage->Width; \ span.texHeight[0] = (GLfloat) texImage->Height; \ @@ -1366,13 +1369,13 @@ static void general_textured_spec_triangle( GLcontext *ctx, GLfixed rFlat, gFlat, bFlat, aFlat; \ GLfixed srFlat, sgFlat, sbFlat; \ if (flatShade) { \ - rFlat = IntToFixed(v2->color[RCOMP]); \ - gFlat = IntToFixed(v2->color[GCOMP]); \ - bFlat = IntToFixed(v2->color[BCOMP]); \ - aFlat = IntToFixed(v2->color[ACOMP]); \ - srFlat = IntToFixed(v2->specular[RCOMP]); \ - sgFlat = IntToFixed(v2->specular[GCOMP]); \ - sbFlat = IntToFixed(v2->specular[BCOMP]); \ + rFlat = ChanToFixed(v2->color[RCOMP]); \ + gFlat = ChanToFixed(v2->color[GCOMP]); \ + bFlat = ChanToFixed(v2->color[BCOMP]); \ + aFlat = ChanToFixed(v2->color[ACOMP]); \ + srFlat = ChanToFixed(v2->specular[RCOMP]); \ + sgFlat = ChanToFixed(v2->specular[GCOMP]); \ + sbFlat = ChanToFixed(v2->specular[BCOMP]); \ } \ span.texWidth[0] = (GLfloat) texImage->Width; \ span.texHeight[0] = (GLfloat) texImage->Height; \ @@ -1421,13 +1424,13 @@ static void lambda_textured_triangle( GLcontext *ctx, GLfixed rFlat, gFlat, bFlat, aFlat; \ GLfixed srFlat, sgFlat, sbFlat; \ if (flatShade) { \ - rFlat = IntToFixed(v2->color[RCOMP]); \ - gFlat = IntToFixed(v2->color[GCOMP]); \ - bFlat = IntToFixed(v2->color[BCOMP]); \ - aFlat = IntToFixed(v2->color[ACOMP]); \ - srFlat = IntToFixed(v2->specular[RCOMP]); \ - sgFlat = IntToFixed(v2->specular[GCOMP]); \ - sbFlat = IntToFixed(v2->specular[BCOMP]); \ + rFlat = ChanToFixed(v2->color[RCOMP]); \ + gFlat = ChanToFixed(v2->color[GCOMP]); \ + bFlat = ChanToFixed(v2->color[BCOMP]); \ + aFlat = ChanToFixed(v2->color[ACOMP]); \ + srFlat = ChanToFixed(v2->specular[RCOMP]); \ + sgFlat = ChanToFixed(v2->specular[GCOMP]); \ + sbFlat = ChanToFixed(v2->specular[BCOMP]); \ } \ span.texWidth[0] = (GLfloat) texImage->Width; \ span.texHeight[0] = (GLfloat) texImage->Height; \ @@ -1478,13 +1481,13 @@ static void lambda_textured_spec_triangle( GLcontext *ctx, GLfixed rFlat, gFlat, bFlat, aFlat; \ GLfixed srFlat, sgFlat, sbFlat; \ if (flatShade) { \ - rFlat = IntToFixed(v2->color[RCOMP]); \ - gFlat = IntToFixed(v2->color[GCOMP]); \ - bFlat = IntToFixed(v2->color[BCOMP]); \ - aFlat = IntToFixed(v2->color[ACOMP]); \ - srFlat = IntToFixed(v2->specular[RCOMP]); \ - sgFlat = IntToFixed(v2->specular[GCOMP]); \ - sbFlat = IntToFixed(v2->specular[BCOMP]); \ + rFlat = ChanToFixed(v2->color[RCOMP]); \ + gFlat = ChanToFixed(v2->color[GCOMP]); \ + bFlat = ChanToFixed(v2->color[BCOMP]); \ + aFlat = ChanToFixed(v2->color[ACOMP]); \ + srFlat = ChanToFixed(v2->specular[RCOMP]); \ + sgFlat = ChanToFixed(v2->specular[GCOMP]); \ + sbFlat = ChanToFixed(v2->specular[BCOMP]); \ } \ span.texWidth[0] = (GLfloat) texImage->Width; \ span.texHeight[0] = (GLfloat) texImage->Height; \ @@ -1534,13 +1537,13 @@ lambda_multitextured_triangle( GLcontext *ctx, GLfixed srFlat, sgFlat, sbFlat; \ GLuint u; \ if (flatShade) { \ - rFlat = IntToFixed(v2->color[RCOMP]); \ - gFlat = IntToFixed(v2->color[GCOMP]); \ - bFlat = IntToFixed(v2->color[BCOMP]); \ - aFlat = IntToFixed(v2->color[ACOMP]); \ - srFlat = IntToFixed(v2->specular[RCOMP]); \ - sgFlat = IntToFixed(v2->specular[GCOMP]); \ - sbFlat = IntToFixed(v2->specular[BCOMP]); \ + rFlat = ChanToFixed(v2->color[RCOMP]); \ + gFlat = ChanToFixed(v2->color[GCOMP]); \ + bFlat = ChanToFixed(v2->color[BCOMP]); \ + aFlat = ChanToFixed(v2->color[ACOMP]); \ + srFlat = ChanToFixed(v2->specular[RCOMP]); \ + sgFlat = ChanToFixed(v2->specular[GCOMP]); \ + sbFlat = ChanToFixed(v2->specular[BCOMP]); \ } \ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { \ if (ctx->Texture.Unit[u]._ReallyEnabled) { \ @@ -1733,17 +1736,18 @@ _swrast_choose_triangle( GLcontext *ctx ) } } else { - /* GL_MODULATE seems also not to work !! */ - if (ctx->Texture.Unit[0].EnvMode==GL_ADD) { - USE(general_textured_triangle); - } - else { +#if CHAN_TYPE != GL_FLOAT + if (ctx->Texture.Unit[0].EnvMode != GL_ADD) { USE(affine_textured_triangle); } + else +#endif + { + USE(general_textured_triangle); + } } } else { - /* GL_MODULATE seems also not to work !! */ if (ctx->Texture.Unit[0].EnvMode==GL_ADD) { USE(general_textured_triangle); } diff --git a/src/mesa/swrast/s_tritemp.h b/src/mesa/swrast/s_tritemp.h index d4ea4f1291b..43a4b3485df 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.19 2001/06/13 14:53:52 brianp Exp $ */ +/* $Id: s_tritemp.h,v 1.20 2001/07/13 20:07:37 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -792,33 +792,33 @@ dfogOuter = dfogdy + dxOuter * span.fogStep; #endif #ifdef INTERP_RGB - fr = (GLfixed)(IntToFixed(vLower->color[0]) + fr = (GLfixed)(ChanToFixed(vLower->color[0]) + drdx * adjx + drdy * adjy) + FIXED_HALF; fdrOuter = SignedFloatToFixed(drdy + dxOuter * drdx); - fg = (GLfixed)(IntToFixed(vLower->color[1]) + fg = (GLfixed)(ChanToFixed(vLower->color[1]) + dgdx * adjx + dgdy * adjy) + FIXED_HALF; fdgOuter = SignedFloatToFixed(dgdy + dxOuter * dgdx); - fb = (GLfixed)(IntToFixed(vLower->color[2]) + fb = (GLfixed)(ChanToFixed(vLower->color[2]) + dbdx * adjx + dbdy * adjy) + FIXED_HALF; fdbOuter = SignedFloatToFixed(dbdy + dxOuter * dbdx); #endif #ifdef INTERP_ALPHA - fa = (GLfixed)(IntToFixed(vLower->color[3]) + fa = (GLfixed)(ChanToFixed(vLower->color[3]) + dadx * adjx + dady * adjy) + FIXED_HALF; fdaOuter = SignedFloatToFixed(dady + dxOuter * dadx); #endif #ifdef INTERP_SPEC - fsr = (GLfixed)(IntToFixed(vLower->specular[0]) + fsr = (GLfixed)(ChanToFixed(vLower->specular[0]) + dsrdx * adjx + dsrdy * adjy) + FIXED_HALF; fdsrOuter = SignedFloatToFixed(dsrdy + dxOuter * dsrdx); - fsg = (GLfixed)(IntToFixed(vLower->specular[1]) + fsg = (GLfixed)(ChanToFixed(vLower->specular[1]) + dsgdx * adjx + dsgdy * adjy) + FIXED_HALF; fdsgOuter = SignedFloatToFixed(dsgdy + dxOuter * dsgdx); - fsb = (GLfixed)(IntToFixed(vLower->specular[2]) + fsb = (GLfixed)(ChanToFixed(vLower->specular[2]) + dsbdx * adjx + dsbdy * adjy) + FIXED_HALF; fdsbOuter = SignedFloatToFixed(dsbdy + dxOuter * dsbdx); #endif |