summaryrefslogtreecommitdiff
path: root/src/mesa/swrast/s_span.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/swrast/s_span.c')
-rw-r--r--src/mesa/swrast/s_span.c1380
1 files changed, 478 insertions, 902 deletions
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index fce8d33c97..4e4bdf298f 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.23 2002/01/21 18:12:34 brianp Exp $ */
+/* $Id: s_span.c,v 1.24 2002/01/27 18:32:03 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -50,11 +50,356 @@
#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);
+
+/*
+ * Init span's Z interpolation values to the RasterPos Z.
+ * Used during setup for glDraw/CopyPixels.
+ */
+void
+_mesa_span_default_z( GLcontext *ctx, struct sw_span *span )
+{
+ if (ctx->Visual.depthBits <= 16)
+ span->z = FloatToFixed(ctx->Current.RasterPos[2] * ctx->DepthMax);
+ else
+ span->z = (GLint) (ctx->Current.RasterPos[2] * ctx->DepthMax);
+ span->zStep = 0;
+ span->interpMask |= SPAN_Z;
+}
+
+
+/*
+ * Init span's fog interpolation values to the RasterPos fog.
+ * Used during setup for glDraw/CopyPixels.
+ */
+void
+_mesa_span_default_fog( GLcontext *ctx, struct sw_span *span )
+{
+ if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
+ span->fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterFogCoord);
+ else
+ span->fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
+ span->fogStep = 0;
+ span->interpMask |= SPAN_FOG;
+}
+
+
+/*
+ * Init span's color or index interpolation values to the RasterPos color.
+ * Used during setup for glDraw/CopyPixels.
+ */
+void
+_mesa_span_default_color( GLcontext *ctx, struct sw_span *span )
+{
+ if (ctx->Visual.rgbMode) {
+ GLchan r, g, b, a;
+ UNCLAMPED_FLOAT_TO_CHAN(r, ctx->Current.RasterColor[0]);
+ UNCLAMPED_FLOAT_TO_CHAN(g, ctx->Current.RasterColor[1]);
+ UNCLAMPED_FLOAT_TO_CHAN(b, ctx->Current.RasterColor[2]);
+ UNCLAMPED_FLOAT_TO_CHAN(a, ctx->Current.RasterColor[3]);
+#if CHAN_TYPE == GL_FLOAT
+ span->red = r;
+ span->green = g;
+ span->blue = b;
+ span->alpha = a;
+#else
+ span->red = IntToFixed(r);
+ span->green = IntToFixed(g);
+ span->blue = IntToFixed(b);
+ span->alpha = IntToFixed(a);
+#endif
+ span->redStep = 0;
+ span->greenStep = 0;
+ span->blueStep = 0;
+ span->alphaStep = 0;
+ span->interpMask |= SPAN_RGBA;
+ }
+ else {
+ span->index = IntToFixed(ctx->Current.RasterIndex);
+ span->indexStep = 0;
+ span->interpMask |= SPAN_INDEX;
+ }
+}
+
+
+/* Fill in the span.color.rgba array from the interpolation values */
+static void
+interpolate_colors(GLcontext *ctx, struct sw_span *span)
+{
+ GLfixed r = span->red;
+ GLfixed g = span->green;
+ GLfixed b = span->blue;
+ GLfixed a = span->alpha;
+ const GLint dr = span->redStep;
+ const GLint dg = span->greenStep;
+ const GLint db = span->blueStep;
+ const GLint da = span->alphaStep;
+ const GLuint n = span->end;
+ GLchan (*rgba)[4] = span->color.rgba;
+ GLuint i;
+
+ ASSERT(span->interpMask & SPAN_RGBA);
+
+ /*
+ SW_SPAN_SET_FLAG(span->filledColor);
+ SW_SPAN_SET_FLAG(span->filledAlpha);
+ */
+
+ if (span->interpMask & SPAN_FLAT) {
+ /* constant color */
+ GLchan color[4];
+ color[RCOMP] = FixedToChan(r);
+ color[GCOMP] = FixedToChan(g);
+ color[BCOMP] = FixedToChan(b);
+ color[ACOMP] = FixedToChan(a);
+ for (i = 0; i < n; i++) {
+ COPY_CHAN4(span->color.rgba[i], color);
+ }
+ }
+ else {
+ /* interpolate */
+ for (i = 0; i < n; i++) {
+ rgba[i][RCOMP] = FixedToChan(r);
+ rgba[i][GCOMP] = FixedToChan(g);
+ rgba[i][BCOMP] = FixedToChan(b);
+ rgba[i][ACOMP] = FixedToChan(a);
+ r += dr;
+ g += dg;
+ b += db;
+ a += da;
+ }
+ }
+ span->arrayMask |= SPAN_RGBA;
+}
+
+
+/* Fill in the span.color.index array from the interpolation values */
+static void
+interpolate_indexes(GLcontext *ctx, struct sw_span *span)
+{
+ GLfixed index = span->index;
+ const GLint indexStep = span->indexStep;
+ const GLuint n = span->end;
+ GLuint *indexes = span->color.index;
+ GLuint i;
+ ASSERT(span->interpMask & SPAN_INDEX);
+
+ if ((span->interpMask & SPAN_FLAT) || (indexStep == 0)) {
+ /* constant color */
+ index = FixedToInt(index);
+ for (i = 0; i < n; i++) {
+ indexes[i] = index;
+ }
+ }
+ else {
+ /* interpolate */
+ for (i = 0; i < n; i++) {
+ indexes[i] = FixedToInt(index);
+ index += indexStep;
+ }
+ }
+ span->arrayMask |= SPAN_INDEX;
+}
+
+
+/* Fill in the span.specArray array from the interpolation values */
+static void
+interpolate_specular(GLcontext *ctx, struct sw_span *span)
+{
+ if (span->interpMask & SPAN_FLAT) {
+ /* constant color */
+ 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->end; i++) {
+ span->specArray[i][RCOMP] = r;
+ span->specArray[i][GCOMP] = g;
+ span->specArray[i][BCOMP] = b;
+ }
+ }
+ else {
+ /* interpolate */
+#if CHAN_TYPE == GL_FLOAT
+ GLfloat r = span->specRed;
+ GLfloat g = span->specGreen;
+ GLfloat b = span->specBlue;
+#else
+ GLfixed r = span->specRed;
+ GLfixed g = span->specGreen;
+ GLfixed b = span->specBlue;
+#endif
+ GLuint i;
+ for (i = 0; i < span->end; i++) {
+ span->specArray[i][RCOMP] = FixedToChan(r);
+ span->specArray[i][GCOMP] = FixedToChan(g);
+ span->specArray[i][BCOMP] = FixedToChan(b);
+ r += span->specRedStep;
+ g += span->specGreenStep;
+ b += span->specBlueStep;
+ }
+ }
+ span->arrayMask |= SPAN_SPEC;
+}
+
+
+/* Fill in the span.zArray array from the interpolation values */
+static void
+interpolate_z(GLcontext *ctx, struct sw_span *span)
+{
+ const GLuint n = span->end;
+ GLuint i;
+
+ ASSERT(span->interpMask & SPAN_Z);
+
+ /* SW_SPAN_SET_FLAG(span->filledDepth);*/
+
+ if (ctx->Visual.depthBits <= 16) {
+ GLfixed zval = span->z;
+ for (i = 0; i < n; i++) {
+ span->zArray[i] = FixedToInt(zval);
+ zval += span->zStep;
+ }
+ }
+ else {
+ /* Deep Z buffer, no fixed->int shift */
+ GLfixed zval = span->z;
+ for (i = 0; i < n; i++) {
+ span->zArray[i] = zval;
+ zval += span->zStep;
+ }
+ }
+ span->arrayMask |= SPAN_Z;
+}
+
+
+
+/* Fill in the span.texcoords array from the interpolation values */
+static void
+interpolate_texcoords(GLcontext *ctx, struct sw_span *span)
+{
+ ASSERT(span->interpMask & SPAN_TEXTURE);
+
+ if (ctx->Texture._ReallyEnabled & ~TEXTURE0_ANY) {
+ if (span->interpMask & SPAN_LAMBDA) {
+ /* multitexture, lambda */
+ GLuint u;
+ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
+ if (ctx->Texture.Unit[u]._ReallyEnabled) {
+ const GLfloat ds = span->texStep[u][0];
+ const GLfloat dt = span->texStep[u][1];
+ const GLfloat dr = span->texStep[u][2];
+ const GLfloat dq = span->texStep[u][3];
+ 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;
+ 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 += ds;
+ t += dt;
+ r += dr;
+ q += dq;
+ }
+ }
+ }
+ span->arrayMask |= SPAN_LAMBDA;
+ }
+ else {
+ /* multitexture, no lambda */
+ GLuint u;
+ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
+ if (ctx->Texture.Unit[u]._ReallyEnabled) {
+ const GLfloat ds = span->texStep[u][0];
+ const GLfloat dt = span->texStep[u][1];
+ const GLfloat dr = span->texStep[u][2];
+ const GLfloat dq = span->texStep[u][3];
+ 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;
+ 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 += ds;
+ t += dt;
+ r += dr;
+ q += dq;
+ }
+ }
+ }
+ }
+ }
+ else {
+#ifdef DEBUG
+ {GLint i;
+ for (i=0; i<ctx->Const.MaxTextureUnits; i++) {
+ ASSERT(span->filledTex[i] == GL_FALSE &&
+ span->filledLambda[i] == GL_FALSE);
+ }}
+#endif
+ if (span->interpMask & SPAN_LAMBDA) {
+ /* just texture unit 0, with lambda */
+ const GLfloat ds = span->texStep[0][0];
+ const GLfloat dt = span->texStep[0][1];
+ const GLfloat dr = span->texStep[0][2];
+ const GLfloat dq = span->texStep[0][3];
+ GLfloat s = span->tex[0][0];
+ GLfloat t = span->tex[0][1];
+ 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]);
+ 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 += ds;
+ t += dt;
+ r += dr;
+ q += dq;
+ }
+ span->arrayMask |= SPAN_LAMBDA;
+ }
+ else {
+ /* just texture 0, witout lambda */
+ const GLfloat ds = span->texStep[0][0];
+ const GLfloat dt = span->texStep[0][1];
+ const GLfloat dr = span->texStep[0][2];
+ const GLfloat dq = span->texStep[0][3];
+ GLfloat s = span->tex[0][0];
+ GLfloat t = span->tex[0][1];
+ GLfloat r = span->tex[0][2];
+ GLfloat q = span->tex[0][3];
+ GLuint i;
+ SW_SPAN_SET_FLAG(span->filledTex[0]);
+ 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 += ds;
+ t += dt;
+ r += dr;
+ q += dq;
+ }
+ }
+ }
}
@@ -82,6 +427,7 @@ old_stipple_polygon_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
}
}
+
/*
* Apply the current polygon stipple pattern to a span of pixels.
*/
@@ -91,8 +437,6 @@ 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);
@@ -162,8 +506,6 @@ 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;
@@ -323,267 +665,19 @@ multi_write_rgba_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
/*
* Write a horizontal span of color index pixels to the frame buffer.
* Stenciling, Depth-testing, etc. 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]
- * index - array of [n] color indexes
- * primitive - either GL_POINT, GL_LINE, GL_POLYGON, or GL_BITMAP
- */
-void
-_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 )
-{
- const GLuint modBits = FOG_BIT | BLEND_BIT | MASKING_BIT | LOGIC_OP_BIT;
- GLubyte mask[MAX_WIDTH];
- GLuint indexBackup[MAX_WIDTH];
- GLuint *index; /* points to indexIn or indexBackup */
- 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 = old_clip_span(ctx,n,x,y,mask)) == 0) {
- return;
- }
- }
-
- if ((primitive==GL_BITMAP && (swrast->_RasterMask & modBits))
- || (swrast->_RasterMask & MULTI_DRAW_BIT)) {
- /* Make copy of color indexes */
- MEMCPY( indexBackup, indexIn, n * sizeof(GLuint) );
- index = indexBackup;
- }
- else {
- index = indexIn;
- }
-
-
- /* Do the scissor test */
- if (ctx->Scissor.Enabled) {
- if ((n = _old_scissor_span( ctx, n, x, y, mask )) == 0) {
- return;
- }
- }
-
- /* Polygon Stippling */
- if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) {
- old_stipple_polygon_span( ctx, n, x, y, mask );
- }
-
- if (ctx->Stencil.Enabled) {
- /* first stencil test */
- if (_old_stencil_and_ztest_span(ctx, n, x, y, z, mask) == GL_FALSE) {
- return;
- }
- }
- else if (ctx->Depth.Test) {
- /* regular depth testing */
- if (_old_depth_test_span( ctx, n, x, y, z, mask ) == 0)
- return;
- }
-
- /* 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_ci_pixels( ctx, n, fog, index );
- else
- _old_depth_fog_ci_pixels( ctx, n, z, index );
- }
-
- /* Antialias coverage application */
- if (coverage) {
- GLuint i;
- for (i = 0; i < n; i++) {
- ASSERT(coverage[i] < 16);
- index[i] = (index[i] & ~0xf) | coverage[i];
- }
- }
-
- if (swrast->_RasterMask & MULTI_DRAW_BIT) {
- /* draw to zero or two or more buffers */
- multi_write_index_span( ctx, n, x, y, index, mask );
- }
- else {
- /* normal situation: draw to exactly one buffer */
- if (ctx->Color.IndexLogicOpEnabled) {
- _mesa_logicop_ci_span( ctx, n, x, y, index, mask );
- }
-
- if (ctx->Color.IndexMask == 0) {
- return;
- }
- else if (ctx->Color.IndexMask != 0xffffffff) {
- _mesa_mask_index_span( ctx, n, x, y, index );
- }
-
- /* write pixels */
- (*swrast->Driver.WriteCI32Span)( ctx, n, x, y, index, mask );
- }
-}
-
-
-/*
- * 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
-_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 )
-{
- 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);
-
- if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) {
- 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 (_old_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,
- const GLfloat fog[MAX_WIDTH], GLenum primitive)
+_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 */
+ GLuint *index; /* points to span->color.index or indexBackup */
SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ const GLuint origArrayMask = span->arrayMask;
-
- SET_MASK_TO_ONE(span);
+ MEMSET(span->mask, 1, span->end);
if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) {
if (clip_span(ctx,span) == GL_FALSE) {
@@ -616,38 +710,23 @@ _mesa_write_index_span( GLcontext *ctx, struct sw_span *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 (span->interpMask & SPAN_Z)
+ interpolate_z(ctx, span);
if (ctx->Stencil.Enabled) {
/* first stencil test */
- if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE)
+ if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE) {
+ span->arrayMask = origArrayMask;
return;
+ }
}
else if (ctx->Depth.Test) {
/* regular depth testing */
- if (_mesa_depth_test_span(ctx, span) == 0)
+ if (_mesa_depth_test_span(ctx, span) == 0) {
+ span->arrayMask = origArrayMask;
return;
+ }
}
/* if we get here, something passed the depth test */
@@ -655,28 +734,30 @@ _mesa_write_index_span( GLcontext *ctx, struct sw_span *span,
if (ctx->Color.DrawBuffer == GL_NONE) {
/* write no pixels */
+ span->arrayMask = origArrayMask;
return;
}
+ if (span->interpMask & SPAN_INDEX)
+ interpolate_indexes(ctx, span);
+
if (ctx->Fog.Enabled) {
- if (fog != NULL && !swrast->_PreferPixelFog)
- _mesa_fog_ci_pixels_with_array( ctx, span, fog, index);
- else if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
- _mesa_fog_ci_pixels( ctx, span, index);
- else
- _mesa_depth_fog_ci_pixels( ctx, span, index);
+ if ((span->arrayMask & SPAN_FOG) && !swrast->_PreferPixelFog)
+ _mesa_fog_ci_pixels_with_array( ctx, span, span->fogArray, index);
+ else if ((span->interpMask & 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];
- }
+ if (span->arrayMask & SPAN_COVERAGE) {
+ GLuint i;
+ for (i = 0; i < span->end; i++) {
+ ASSERT(span->coverage[i] < 16);
+ index[i] = (index[i] & ~0xf) | ((GLuint) (span->coverage[i]));
+ }
}
-#endif
if (swrast->_RasterMask & MULTI_DRAW_BIT) {
/* draw to zero or two or more buffers */
@@ -701,148 +782,8 @@ _mesa_write_index_span( GLcontext *ctx, struct sw_span *span,
(*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, 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
- || ctx->Color.IndexLogicOpEnabled
- || ctx->Color.IndexMask != 0xffffffff
-#if 0
- || span->coverage) {
-#else
- ) {
-#endif
- /* different index per pixel */
- GLuint indexes[MAX_WIDTH];
- for (i = 0; i < span->end; i++) {
- indexes[i] = index;
- }
-
- if (ctx->Fog.Enabled) {
- if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
- _mesa_fog_ci_pixels( ctx, span, indexes );
- else
- _mesa_depth_fog_ci_pixels( ctx, span, indexes );
- }
- /* Antialias coverage application */
-#if 0
- if (span->coverage) {
- GLuint 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, 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, 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, span->end, span->x, span->y, indexes );
- }
- (*swrast->Driver.WriteCI32Span)( ctx, span->end, span->x, span->y, indexes, span->mask );
- }
- }
- else {
- /* same color index for all pixels */
- ASSERT(!ctx->Color.IndexLogicOpEnabled);
- ASSERT(ctx->Color.IndexMask == 0xffffffff);
- if (swrast->_RasterMask & MULTI_DRAW_BIT) {
- /* draw to zero or two or more buffers */
- GLuint indexes[MAX_WIDTH];
- for (i = 0; i < span->end; i++)
- indexes[i] = index;
- 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, span->end, span->x, span->y, index, span->mask );
- }
- }
+ span->arrayMask = origArrayMask;
}
@@ -853,16 +794,16 @@ _mesa_write_monoindex_span( GLcontext *ctx, struct sw_span *span,
*/
void
_mesa_write_rgba_span( GLcontext *ctx, struct sw_span *span,
- const GLfloat fog[MAX_WIDTH], GLenum primitive)
+ GLenum primitive)
{
const GLuint modBits = FOG_BIT | BLEND_BIT | MASKING_BIT |
LOGIC_OP_BIT | TEXTURE_BIT;
GLchan rgbaBackup[MAX_WIDTH][4];
GLchan (*rgba)[4];
SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ const GLuint origArrayMask = span->arrayMask;
-
- SET_MASK_TO_ONE(span);
+ MEMSET(span->mask, 1, span->end);
if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) {
if (clip_span( ctx,span ) == GL_FALSE) {
@@ -870,7 +811,6 @@ _mesa_write_rgba_span( GLcontext *ctx, struct sw_span *span,
}
}
-
/* Do the scissor test */
if (ctx->Scissor.Enabled) {
if (_mesa_scissor_span( ctx, span ) == GL_FALSE) {
@@ -878,12 +818,14 @@ _mesa_write_rgba_span( GLcontext *ctx, struct sw_span *span,
}
}
-
/* Polygon Stippling */
if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) {
stipple_polygon_span( ctx, span);
}
+ if ((span->interpMask & SPAN_RGBA) && (span->arrayMask & SPAN_RGBA) == 0) {
+ interpolate_colors(ctx, span);
+ }
if ((primitive==GL_BITMAP && (swrast->_RasterMask & modBits))
|| (swrast->_RasterMask & MULTI_DRAW_BIT)) {
@@ -895,23 +837,25 @@ _mesa_write_rgba_span( GLcontext *ctx, struct sw_span *span,
rgba = span->color.rgba;
}
-
/* Do the alpha test */
if (ctx->Color.AlphaEnabled) {
if (_mesa_alpha_test( ctx, span, (const GLchan (*)[4]) rgba) == 0) {
+ span->arrayMask = origArrayMask;
return;
}
}
/* I have to think where to put this!! */
- if (span->activeMask & SPAN_Z) {
- SW_SPAN_SET_FLAG(span->filledDepth);
+ if (span->interpMask & SPAN_Z) {
+#ifdef DEBUG
+ span->filledDepth = GL_TRUE;
+#endif
if (ctx->Visual.depthBits <= 16) {
GLuint i;
GLfixed zval = span->z;
for (i = 0; i < span->end; i++) {
- span->depth[i] = FixedToInt(zval);
+ span->zArray[i] = FixedToInt(zval);
zval += span->zStep;
}
}
@@ -920,21 +864,26 @@ _mesa_write_rgba_span( GLcontext *ctx, struct sw_span *span,
GLuint i;
GLfixed zval = span->z;
for (i = 0; i < span->end; i++) {
- span->depth[i] = zval;
+ span->zArray[i] = zval;
zval += span->zStep;
}
}
+ span->arrayMask |= SPAN_Z;
}
if (ctx->Stencil.Enabled) {
/* first stencil test */
- if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE)
+ if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE) {
+ span->arrayMask = origArrayMask;
return;
+ }
}
else if (ctx->Depth.Test) {
/* regular depth testing */
- if (_mesa_depth_test_span(ctx, span) == GL_FALSE)
+ if (_mesa_depth_test_span(ctx, span) == GL_FALSE) {
+ span->arrayMask = origArrayMask;
return;
+ }
}
/* if we get here, something passed the depth test */
@@ -942,23 +891,21 @@ _mesa_write_rgba_span( GLcontext *ctx, struct sw_span *span,
/* Per-pixel fog */
if (ctx->Fog.Enabled) {
- if (fog != NULL && !swrast->_PreferPixelFog)
- _mesa_fog_rgba_pixels_with_array( ctx, span, fog, rgba);
- else if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
+ if ((span->arrayMask & SPAN_FOG) && !swrast->_PreferPixelFog)
+ _mesa_fog_rgba_pixels_with_array( ctx, span, span->fogArray, rgba);
+ else if ((span->interpMask & SPAN_FOG) && !swrast->_PreferPixelFog)
_mesa_fog_rgba_pixels( ctx, span, rgba );
else
_mesa_depth_fog_rgba_pixels( ctx, span, rgba );
}
/* Antialias coverage application */
-#if 0
- if (span->coverage) {
+ if (span->arrayMask & SPAN_COVERAGE) {
GLuint 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, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, span->mask );
@@ -977,6 +924,7 @@ _mesa_write_rgba_span( GLcontext *ctx, struct sw_span *span,
/* Color component masking */
if (colorMask == 0x0) {
+ span->arrayMask = origArrayMask;
return;
}
else if (colorMask != 0xffffffff) {
@@ -994,6 +942,8 @@ _mesa_write_rgba_span( GLcontext *ctx, struct sw_span *span,
span->writeAll ? ((const GLubyte *) NULL) : span->mask );
}
}
+
+ span->arrayMask = origArrayMask;
}
@@ -1013,8 +963,7 @@ _mesa_write_monocolor_span( GLcontext *ctx, struct sw_span *span,
GLchan rgba[MAX_WIDTH][4];
SWcontext *swrast = SWRAST_CONTEXT(ctx);
-
- SET_MASK_TO_ONE(span);
+ MEMSET(span->mask, 1, span->end);
if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) {
if (clip_span(ctx,span) == GL_FALSE) {
@@ -1046,14 +995,14 @@ _mesa_write_monocolor_span( GLcontext *ctx, struct sw_span *span,
}
/* I have to think where to put this!! */
- if (span->activeMask & SPAN_Z) {
+ if (span->interpMask & 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);
+ span->zArray[i] = FixedToInt(zval);
zval += span->zStep;
}
}
@@ -1062,10 +1011,11 @@ _mesa_write_monocolor_span( GLcontext *ctx, struct sw_span *span,
GLuint i;
GLfixed zval = span->z;
for (i = 0; i < span->end; i++) {
- span->depth[i] = zval;
+ span->zArray[i] = zval;
zval += span->zStep;
}
}
+ span->arrayMask |= SPAN_Z;
}
if (ctx->Stencil.Enabled) {
@@ -1087,12 +1037,10 @@ _mesa_write_monocolor_span( GLcontext *ctx, struct sw_span *span,
return;
}
- if (ctx->Color.ColorLogicOpEnabled || colorMask != 0xffffffff ||
-#if 0
- (swrast->_RasterMask & (BLEND_BIT | FOG_BIT)) || coverage) {
-#else
- (swrast->_RasterMask & (BLEND_BIT | FOG_BIT))) {
-#endif
+ if (ctx->Color.ColorLogicOpEnabled ||
+ colorMask != 0xffffffff ||
+ (swrast->_RasterMask & (BLEND_BIT | FOG_BIT)) ||
+ (span->arrayMask & SPAN_COVERAGE)) {
/* assign same color to each pixel */
SW_SPAN_SET_FLAG(span->filledColor);
for (i = 0; i < span->end; i++) {
@@ -1103,21 +1051,19 @@ _mesa_write_monocolor_span( GLcontext *ctx, struct sw_span *span,
/* Per-pixel fog */
if (ctx->Fog.Enabled) {
- if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
+ if ((span->interpMask & SPAN_FOG) && !swrast->_PreferPixelFog)
_mesa_fog_rgba_pixels( ctx, span, rgba );
else
_mesa_depth_fog_rgba_pixels( ctx, span, rgba );
}
/* Antialias coverage application */
-#if 0
- if (span->coverage) {
+ if (span->arrayMask & SPAN_COVERAGE) {
GLuint 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, span->end, span->x, span->y,
@@ -1126,10 +1072,12 @@ _mesa_write_monocolor_span( GLcontext *ctx, struct sw_span *span,
else {
/* normal: write to exactly one buffer */
if (ctx->Color.ColorLogicOpEnabled) {
- _mesa_logicop_rgba_span( ctx, span->end, span->x, span->y, rgba, span->mask );
+ _mesa_logicop_rgba_span( ctx, span->end, span->x, span->y,
+ rgba, span->mask );
}
else if (ctx->Color.BlendEnabled) {
- _mesa_blend_span( ctx, span->end, span->x, span->y, rgba, span->mask );
+ _mesa_blend_span( ctx, span->end, span->x, span->y,
+ rgba, span->mask );
}
/* Color component masking */
@@ -1142,12 +1090,12 @@ _mesa_write_monocolor_span( GLcontext *ctx, struct sw_span *span,
/* write pixels */
(*swrast->Driver.WriteRGBASpan)( ctx, span->end, span->x, span->y,
- (const GLchan (*)[4]) rgba,
- span->writeAll ? ((const GLubyte *) NULL) : span->mask );
+ (const GLchan (*)[4]) rgba,
+ span->writeAll ? ((const GLubyte *) NULL) : span->mask );
if (swrast->_RasterMask & ALPHABUF_BIT) {
_mesa_write_alpha_span( ctx, span->end, span->x, span->y,
- (const GLchan (*)[4]) rgba,
- span->writeAll ? ((const GLubyte *) NULL) : span->mask );
+ (const GLchan (*)[4]) rgba,
+ span->writeAll ? ((const GLubyte *) NULL) : span->mask );
}
}
}
@@ -1167,11 +1115,12 @@ _mesa_write_monocolor_span( GLcontext *ctx, struct sw_span *span,
(const GLchan (*)[4]) rgba, span->mask );
}
else {
- (*swrast->Driver.WriteMonoRGBASpan)( ctx, span->end, span->x, span->y, color, span->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, span->end, span->x, span->y,
- (GLchan) color[ACOMP],
- span->writeAll ? ((const GLubyte *) NULL) : span->mask );
+ (GLchan) color[ACOMP],
+ span->writeAll ? ((const GLubyte *) NULL) : span->mask );
}
}
}
@@ -1181,25 +1130,26 @@ _mesa_write_monocolor_span( GLcontext *ctx, struct sw_span *span,
/*
* Add specular color to base color. This is used only when
- * GL_LIGHT_MODEL_COLOR_CONTROL = GL_SEPARATE_SPECULAR_COLOR.
+ * GL_LIGHT_MODEL_COLOR_CONTROL = GL_SEPARATE_SPECULAR_COLOR
+ * or GL_COLOR_SUM_EXT is enabled.
*/
static void
add_colors(CONST struct sw_span *span, GLchan rgba[][4])
{
GLuint i;
- ASSERT(span->filledSpecular == GL_TRUE);
- ASSERT(span->filledColor == GL_TRUE);
+ assert(span->arrayMask & SPAN_RGBA);
+ assert(span->arrayMask & SPAN_SPEC);
for (i = 0; i < span->end; i++) {
#if CHAN_TYPE == GL_FLOAT
/* no clamping */
- rgba[i][RCOMP] += span->specular[i][RCOMP];
- rgba[i][GCOMP] += span->specular[i][GCOMP];
- rgba[i][BCOMP] += span->specular[i][BCOMP];
+ rgba[i][RCOMP] += span->specArray[i][RCOMP];
+ rgba[i][GCOMP] += span->specArray[i][GCOMP];
+ rgba[i][BCOMP] += span->specArray[i][BCOMP];
#else
- 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];
+ GLint r = rgba[i][RCOMP] + span->specArray[i][RCOMP];
+ GLint g = rgba[i][GCOMP] + span->specArray[i][GCOMP];
+ GLint b = rgba[i][BCOMP] + span->specArray[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);
@@ -1219,14 +1169,14 @@ add_colors(CONST struct sw_span *span, GLchan rgba[][4])
*/
void
_mesa_write_texture_span( GLcontext *ctx, struct sw_span *span,
- const GLfloat fog[MAX_WIDTH], GLenum primitive )
+ GLenum primitive )
{
const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask);
GLchan rgbaBackup[MAX_WIDTH][4];
GLchan (*rgba)[4]; /* points to either rgbaIn or rgbaBackup */
SWcontext *swrast = SWRAST_CONTEXT(ctx);
- SET_MASK_TO_ONE(span);
+ MEMSET(span->mask, 1, span->end);
if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) {
if (clip_span(ctx,span) == GL_FALSE) {
@@ -1292,17 +1242,18 @@ _mesa_write_texture_span( GLcontext *ctx, struct sw_span *span,
/* Add base and specular colors */
- if ((span->activeMask & SPAN_SPEC) && /* Is this right test ???*/
+ if ((span->arrayMask & SPAN_SPEC) && /* Is this right test ???*/
(ctx->Fog.ColorSumEnabled ||
(ctx->Light.Enabled &&
- ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)))
- add_colors(span, rgba); /* rgba = rgba + spec */
-
+ ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR))) {
+ add_colors(span, rgba); /* rgba = rgba + span->spec */
+ }
+
/* Per-pixel fog */
if (ctx->Fog.Enabled) {
- if (fog != NULL && !swrast->_PreferPixelFog)
- _mesa_fog_rgba_pixels_with_array( ctx, span, fog, rgba);
- else if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
+ if ((span->arrayMask & SPAN_FOG) && !swrast->_PreferPixelFog)
+ _mesa_fog_rgba_pixels_with_array( ctx, span, span->fogArray, rgba);
+ else if ((span->interpMask & SPAN_FOG) && !swrast->_PreferPixelFog)
_mesa_fog_rgba_pixels( ctx, span, rgba );
else
_mesa_depth_fog_rgba_pixels(ctx, span, rgba);
@@ -1310,14 +1261,12 @@ _mesa_write_texture_span( GLcontext *ctx, struct sw_span *span,
/* Antialias coverage application */
-#if 0
- if (span->coverage) {
+ if (span->arrayMask & SPAN_COVERAGE) {
GLuint 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, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, span->mask );
@@ -1416,30 +1365,28 @@ masked_texture_span( GLcontext *ctx, struct sw_span *span)
/* Add base and specular colors */
- if ((span->activeMask & SPAN_SPEC) && /* Is this right test ???*/
+ if ((span->interpMask & SPAN_SPEC) && /* Is this right test ???*/
(ctx->Fog.ColorSumEnabled ||
(ctx->Light.Enabled &&
ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)))
- add_colors(span, rgba); /* rgba = rgba + spec */
+ add_colors(span, rgba); /* rgba = rgba + span->spec */
/* Per-pixel fog */
if (ctx->Fog.Enabled) {
/* Is this the right 'if' ?? */
- if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
+ if ((span->interpMask & SPAN_FOG) && !swrast->_PreferPixelFog)
_mesa_fog_rgba_pixels(ctx, span, rgba);
else
_mesa_depth_fog_rgba_pixels(ctx, span, rgba);
}
/* Antialias coverage application */
-#if 0
- if (span->coverage) {
+ if (span->arrayMask & SPAN_COVERAGE) {
GLuint 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, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, span->mask );
@@ -1526,30 +1473,28 @@ masked_multitexture_span( GLcontext *ctx, struct sw_span *span)
/* Add base and specular colors */
- if ((span->activeMask & SPAN_SPEC) && /* Is this right test ???*/
+ if ((span->interpMask & SPAN_SPEC) && /* Is this right test ???*/
(ctx->Fog.ColorSumEnabled ||
(ctx->Light.Enabled &&
ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)))
- add_colors(span, rgba); /* rgba = rgba + spec */
+ add_colors(span, rgba); /* rgba = rgba + span->spec */
/* Per-pixel fog */
if (ctx->Fog.Enabled) {
/* Is this the right 'if' ?? */
- if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
+ if ((span->interpMask & SPAN_FOG) && !swrast->_PreferPixelFog)
_mesa_fog_rgba_pixels( ctx, span, rgba );
else
_mesa_depth_fog_rgba_pixels( ctx, span, rgba );
}
/* Antialias coverage application */
-#if 0
- if (span->coverage) {
+ if (span->arrayMask & SPAN_COVERAGE) {
GLuint 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, span->end, span->x, span->y,
@@ -1597,8 +1542,7 @@ _mesa_rasterize_span(GLcontext *ctx, struct sw_span *span)
{
SWcontext *swrast = SWRAST_CONTEXT(ctx);
- SET_MASK_TO_ONE(span);
-
+ MEMSET(span->mask, 1, span->end);
if (swrast->_RasterMask & WINCLIP_BIT) {
if (clip_span(ctx, span) == GL_FALSE) {
@@ -1619,14 +1563,14 @@ _mesa_rasterize_span(GLcontext *ctx, struct sw_span *span)
}
/* I have to think where to put this!! */
- if (span->activeMask & SPAN_Z) {
+ if (span->interpMask & 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);
+ span->zArray[i] = FixedToInt(zval);
zval += span->zStep;
}
}
@@ -1635,17 +1579,18 @@ _mesa_rasterize_span(GLcontext *ctx, struct sw_span *span)
GLuint i;
GLfixed zval = span->z;
for (i = 0; i < span->end; i++) {
- span->depth[i] = zval;
+ span->zArray[i] = zval;
zval += span->zStep;
}
}
+ span->arrayMask |= SPAN_Z;
}
/* Correct order: texturing --> alpha test --> depth test. But if
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 (span->activeMask & SPAN_Z && !ctx->Color.AlphaEnabled) {
+ if (span->interpMask & SPAN_Z && !ctx->Color.AlphaEnabled) {
if (ctx->Stencil.Enabled) {
/* first stencil test */
if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE)
@@ -1659,229 +1604,20 @@ _mesa_rasterize_span(GLcontext *ctx, struct sw_span *span)
}
}
- if (span->activeMask & SPAN_RGBA) {
- SW_SPAN_SET_FLAG(span->filledColor);
- SW_SPAN_SET_FLAG(span->filledAlpha);
- if (span->activeMask & SPAN_FLAT) {
- GLuint i;
- GLchan color[4];
- color[RCOMP] = FixedToChan(span->red);
- color[GCOMP] = FixedToChan(span->green);
- color[BCOMP] = FixedToChan(span->blue);
- color[ACOMP] = FixedToChan(span->alpha);
- for (i = 0; i < span->end; i++) {
- COPY_CHAN4(span->color.rgba[i], color);
- }
- }
- else {
- /* smooth interpolation */
-#if CHAN_TYPE == GL_FLOAT
- GLfloat r = span->red;
- GLfloat g = span->green;
- GLfloat b = span->blue;
- GLfloat a = span->alpha;
-#else
- GLfixed r = span->red;
- GLfixed g = span->green;
- GLfixed b = span->blue;
- GLfixed a = span->alpha;
-#endif
- GLuint i;
- 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;
- a += span->alphaStep;
- }
- }
- }
+ if (span->interpMask & SPAN_RGBA)
+ interpolate_colors(ctx, 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->end; i++) {
- span->specular[i][RCOMP] = r;
- span->specular[i][GCOMP] = g;
- span->specular[i][BCOMP] = b;
- }
- }
- else {
- /* smooth interpolation */
-#if CHAN_TYPE == GL_FLOAT
- GLfloat r = span->specRed;
- GLfloat g = span->specGreen;
- GLfloat b = span->specBlue;
-#else
- GLfixed r = span->specRed;
- GLfixed g = span->specGreen;
- GLfixed b = span->specBlue;
-#endif
- GLuint i;
- 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;
- }
- }
- }
+ if (span->interpMask & SPAN_SPEC)
+ interpolate_specular(ctx, 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->end; i++) {
- span->color.index[i] = indx;
- }
- }
- else {
- /* smooth interpolation */
- GLuint i;
- GLfixed ind = span->index;
- for (i = 0; i < span->end; i++) {
- span->color.index[i] = FixedToInt(ind);
- ind += span->indexStep;
- }
- }
- }
+ if (span->interpMask & SPAN_INDEX)
+ interpolate_indexes(ctx, span);
- if (span->activeMask & SPAN_TEXTURE) {
- if (ctx->Texture._ReallyEnabled & ~TEXTURE0_ANY) {
- /* multitexture */
- if (span->activeMask & SPAN_LAMBDA) {
- /* with lambda */
- GLuint u;
- /* multitexture, lambda */
- for (u = 0; u < MAX_TEXTURE_UNITS; u++) {
- 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;
- 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) {
- 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;
- 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];
- GLfloat t = span->tex[0][1];
- 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->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 */
- GLfloat s = span->tex[0][0];
- GLfloat t = span->tex[0][1];
- 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->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) {
- GLfixed s = span->intTex[0];
- GLfixed t = span->intTex[1];
- GLuint i;
- 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) {
+ if (span->interpMask & SPAN_TEXTURE)
+ interpolate_texcoords(ctx, span);
+
+ /* examine interpMask and call a s_span.c function */
+ if (span->interpMask & SPAN_TEXTURE) {
if (ctx->Texture._ReallyEnabled & ~TEXTURE0_ANY) {
/* multi texture */
@@ -1925,166 +1661,6 @@ _old_add_colors(GLuint n, GLchan rgba[][4], GLchan specular[][4] )
/*
- * Write a horizontal span of textured pixels to the frame buffer.
- * The color of each pixel is different.
- * 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]
- * s, t - array of (s,t) texture coordinates for each pixel
- * lambda - array of texture lambda values
- * rgba - array of [n] color components
- * primitive - either GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP.
- */
-void
-_old_write_texture_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
- const GLdepth z[], const GLfloat fog[],
- GLfloat texcoord[][4],
- GLfloat lambda[],
- GLchan rgbaIn[][4], GLchan spec[][4],
- const GLfloat coverage[], GLenum primitive )
-{
- const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask);
- GLubyte mask[MAX_WIDTH];
- GLboolean write_all = GL_TRUE;
- GLchan rgbaBackup[MAX_WIDTH][4];
- GLchan (*rgba)[4]; /* points to either rgbaIn or rgbaBackup */
- 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=old_clip_span(ctx, n, x, y, mask)) == 0) {
- return;
- }
- if (mask[0] == 0)
- write_all = GL_FALSE;
- }
-
-
- if (primitive==GL_BITMAP || (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;
- }
-
- /* Texture with alpha test */
- if (ctx->Color.AlphaEnabled) {
- /* Texturing without alpha is done after depth-testing which
- gives a potential speed-up. */
- ASSERT(ctx->Texture._ReallyEnabled);
- _old_swrast_texture_fragments( ctx, 0, n, texcoord, lambda,
- (CONST GLchan (*)[4]) rgba, rgba );
-
- /* Do the alpha test */
- if (_old_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;
-
- /* Texture without alpha test */
- if (! ctx->Color.AlphaEnabled) {
- ASSERT(ctx->Texture._ReallyEnabled);
- _old_swrast_texture_fragments( ctx, 0, n, texcoord, lambda,
- (CONST GLchan (*)[4]) rgba, rgba );
- }
-
- /* Add base and specular colors */
- if (spec &&
- (ctx->Fog.ColorSumEnabled ||
- (ctx->Light.Enabled &&
- ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)))
- _old_add_colors( n, rgba, spec ); /* rgba = rgba + spec */
-
- /* 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 */
- 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 );
- }
- if (colorMask == 0x0) {
- return;
- }
- else if (colorMask != 0xffffffff) {
- _mesa_mask_rgba_span( ctx, n, x, y, rgba );
- }
-
- (*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 );
- }
- }
-}
-
-
-
-/*
* As above but perform multiple stages of texture application.
*/
void