Consolidate _swrast_write_texture_span() into _swrast_write_rgba_span().
authorBrian Paul <brian.paul@tungstengraphics.com>
Sat, 18 Dec 2004 22:03:07 +0000 (22:03 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Sat, 18 Dec 2004 22:03:07 +0000 (22:03 +0000)
src/mesa/swrast/s_aalinetemp.h
src/mesa/swrast/s_aatriangle.c
src/mesa/swrast/s_aatritemp.h
src/mesa/swrast/s_context.c
src/mesa/swrast/s_lines.c
src/mesa/swrast/s_pixeltex.c
src/mesa/swrast/s_pointtemp.h
src/mesa/swrast/s_span.c
src/mesa/swrast/s_span.h
src/mesa/swrast/s_triangle.c

index 337a9606aca7627e2e397c973d5ae60dcf172c96..4ffa5b81fbbcb7619fa65a125505ec6178266a43 100644 (file)
@@ -30,6 +30,8 @@
 
 /*
  * Function to render each fragment in the AA line.
+ * \param ix  - integer fragment window X coordiante
+ * \param iy  - integer fragment window Y coordiante
  */
 static void
 NAME(plot)(GLcontext *ctx, struct LineInfo *line, int ix, int iy)
@@ -77,34 +79,46 @@ NAME(plot)(GLcontext *ctx, struct LineInfo *line, int ix, int iy)
 #endif
 #ifdef DO_TEX
    {
-      const GLfloat invQ = solve_plane_recip(fx, fy, line->vPlane[0]);
+      GLfloat invQ;
+      if (ctx->FragmentProgram._Enabled) {
+         invQ = 1.0F;
+      }
+      else {
+         invQ = solve_plane_recip(fx, fy, line->vPlane[0]);
+      }
       line->span.array->texcoords[0][i][0] = solve_plane(fx, fy, line->sPlane[0]) * invQ;
       line->span.array->texcoords[0][i][1] = solve_plane(fx, fy, line->tPlane[0]) * invQ;
       line->span.array->texcoords[0][i][2] = solve_plane(fx, fy, line->uPlane[0]) * invQ;
-      line->span.array->lambda[0][i] = compute_lambda(line->sPlane[0], line->tPlane[0], invQ,
-                                          line->texWidth[0], line->texHeight[0]);
+      line->span.array->lambda[0][i] = compute_lambda(line->sPlane[0],
+                                                      line->tPlane[0], invQ,
+                                                      line->texWidth[0],
+                                                      line->texHeight[0]);
    }
 #elif defined(DO_MULTITEX)
    {
       GLuint unit;
       for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
          if (ctx->Texture.Unit[unit]._ReallyEnabled) {
-            const GLfloat invQ = solve_plane_recip(fx, fy, line->vPlane[unit]);
+            GLfloat invQ;
+            if (ctx->FragmentProgram._Enabled) {
+               invQ = 1.0F;
+            }
+            else {
+               invQ = solve_plane_recip(fx, fy, line->vPlane[unit]);
+            }
             line->span.array->texcoords[unit][i][0] = solve_plane(fx, fy, line->sPlane[unit]) * invQ;
             line->span.array->texcoords[unit][i][1] = solve_plane(fx, fy, line->tPlane[unit]) * invQ;
             line->span.array->texcoords[unit][i][2] = solve_plane(fx, fy, line->uPlane[unit]) * invQ;
             line->span.array->lambda[unit][i] = compute_lambda(line->sPlane[unit],
-                                               line->tPlane[unit], invQ,
-                                               line->texWidth[unit], line->texHeight[unit]);
+                                                               line->tPlane[unit], invQ,
+                                                               line->texWidth[unit], line->texHeight[unit]);
          }
       }
    }
 #endif
 
    if (line->span.end == MAX_WIDTH) {
-#if defined(DO_TEX) || defined(DO_MULTITEX)
-      _swrast_write_texture_span(ctx, &(line->span));
-#elif defined(DO_RGBA)
+#if defined(DO_RGBA)
       _swrast_write_rgba_span(ctx, &(line->span));
 #else
       _swrast_write_index_span(ctx, &(line->span));
@@ -295,9 +309,7 @@ NAME(line)(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1)
       segment(ctx, &line, NAME(plot), 0.0, 1.0);
    }
 
-#if defined(DO_TEX) || defined(DO_MULTITEX)
-   _swrast_write_texture_span(ctx, &(line.span));
-#elif defined(DO_RGBA)
+#if defined(DO_RGBA)
    _swrast_write_rgba_span(ctx, &(line.span));
 #else
    _swrast_write_index_span(ctx, &(line.span));
index 1bcaa95d3300b81b211d4e91c012ed721f5550a4..5509f34c953f94c52d76415db408b8aa88ad4f9a 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  6.3
  *
- * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
index 53dd59fa9f66b58f2d0ae258ee7303e9bb3b4ea3..16e26d3f8a591b509841f8ecc515e1a15c13e972 100644 (file)
@@ -1,9 +1,8 @@
-
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  6.3
  *
- * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
          span.y = iy;
          span.end = (GLuint) ix - (GLuint) startX;
          ASSERT(span.interpMask == 0);
-#if defined(DO_MULTITEX) || defined(DO_TEX)
-         _swrast_write_texture_span(ctx, &span);
-#elif defined(DO_RGBA)
+#if defined(DO_RGBA)
          _swrast_write_rgba_span(ctx, &span);
-#elif defined(DO_INDEX)
+#else
          _swrast_write_index_span(ctx, &span);
 #endif
       }
          span.y = iy;
          span.end = n;
          ASSERT(span.interpMask == 0);
-#if defined(DO_MULTITEX) || defined(DO_TEX)
-         _swrast_write_texture_span(ctx, &span);
-#elif defined(DO_RGBA)
+#if defined(DO_RGBA)
          _swrast_write_rgba_span(ctx, &span);
-#elif defined(DO_INDEX)
+#else
          _swrast_write_index_span(ctx, &span);
 #endif
       }
index a8716d80f509500f8a39a11433caf672e31d58d0..f81fc11835a01d169cd4339f08f98dd17625520c 100644 (file)
@@ -692,10 +692,7 @@ _swrast_flush( GLcontext *ctx )
    /* flush any pending fragments from rendering points */
    if (swrast->PointSpan.end > 0) {
       if (ctx->Visual.rgbMode) {
-         if (ctx->Texture._EnabledCoordUnits)
-            _swrast_write_texture_span(ctx, &(swrast->PointSpan));
-         else
-            _swrast_write_rgba_span(ctx, &(swrast->PointSpan));
+         _swrast_write_rgba_span(ctx, &(swrast->PointSpan));
       }
       else {
          _swrast_write_index_span(ctx, &(swrast->PointSpan));
index a5a612335e0b60dd075efd4b90bef43786213b58..20d32b25a0c534b575e4e0da125519b0336101b9 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  6.3
  *
- * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -88,9 +88,7 @@ draw_wide_line( GLcontext *ctx, struct sw_span *span, GLboolean xMajor )
             for (i = 0; i < span->end; i++)
                y[i]++;
          }
-         if ((span->interpMask | span->arrayMask) & SPAN_TEXTURE)
-            _swrast_write_texture_span(ctx, span);
-         else if ((span->interpMask | span->arrayMask) & SPAN_RGBA)
+         if (ctx->Visual.rgbMode)
             _swrast_write_rgba_span(ctx, span);
          else
             _swrast_write_index_span(ctx, span);
@@ -109,9 +107,7 @@ draw_wide_line( GLcontext *ctx, struct sw_span *span, GLboolean xMajor )
             for (i = 0; i < span->end; i++)
                x[i]++;
          }
-         if ((span->interpMask | span->arrayMask) & SPAN_TEXTURE)
-            _swrast_write_texture_span(ctx, span);
-         else if ((span->interpMask | span->arrayMask) & SPAN_RGBA)
+         if (ctx->Visual.rgbMode)
             _swrast_write_rgba_span(ctx, span);
          else
             _swrast_write_index_span(ctx, span);
@@ -191,7 +187,7 @@ draw_wide_line( GLcontext *ctx, struct sw_span *span, GLboolean xMajor )
       draw_wide_line(ctx, &span, (GLboolean)(dx > dy));                \
    }                                                           \
    else {                                                      \
-      _swrast_write_texture_span(ctx, &span);                  \
+      _swrast_write_rgba_span(ctx, &span);                     \
    }
 #include "s_linetemp.h"
 
@@ -212,7 +208,7 @@ draw_wide_line( GLcontext *ctx, struct sw_span *span, GLboolean xMajor )
       draw_wide_line(ctx, &span, (GLboolean)(dx > dy));                \
    }                                                           \
    else {                                                      \
-      _swrast_write_texture_span(ctx, &span);                  \
+      _swrast_write_rgba_span(ctx, &span);                     \
    }
 #include "s_linetemp.h"
 
index 776a38c9153532a3317657decb328fd31ba3889e..1c65290d40d687ab4d98902593c9f692bbdee5c9 100644 (file)
@@ -1,9 +1,8 @@
-
 /*
  * Mesa 3-D graphics library
- * Version:  4.1
+ * Version:  6.3
  *
- * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -95,6 +94,7 @@ _swrast_pixel_texture(GLcontext *ctx, struct sw_span *span)
 
    ASSERT(!(span->arrayMask & SPAN_TEXTURE));
    span->arrayMask |= SPAN_TEXTURE;
+   span->interpMask &= ~SPAN_TEXTURE;
 
    /* convert colors into texture coordinates */
    pixeltexgen( ctx, span->end,
@@ -108,10 +108,4 @@ _swrast_pixel_texture(GLcontext *ctx, struct sw_span *span)
                  span->end * 4 * sizeof(GLfloat) );
       }
    }
-
-   /* apply texture mapping */
-   _swrast_texture_span( ctx, span );
-
-   /* this is a work-around to be fixed by initializing again span */
-   span->arrayMask &= ~SPAN_TEXTURE;
 }
index 25a6a31772cfdda7d0d6717116a04eafb713b28f..ef48d239ec40c99296015e3e6977770e317dcca0 100644 (file)
@@ -216,12 +216,7 @@ NAME ( GLcontext *ctx, const SWvertex *vert )
       /* check if we need to flush */
       if (span->end + (xmax-xmin+1) * (ymax-ymin+1) >= MAX_WIDTH ||
           (swrast->_RasterMask & (BLEND_BIT | LOGIC_OP_BIT | MASKING_BIT))) {
-#if FLAGS & (TEXTURE | SPRITE)
-         if (ctx->Texture._EnabledUnits)
-            _swrast_write_texture_span(ctx, span);
-         else
-            _swrast_write_rgba_span(ctx, span);
-#elif FLAGS & RGBA
+#if FLAGS & RGBA
          _swrast_write_rgba_span(ctx, span);
 #else
          _swrast_write_index_span(ctx, span);
@@ -238,12 +233,7 @@ NAME ( GLcontext *ctx, const SWvertex *vert )
          /* check if we need to flush */
          if (count + (xmax-xmin+1) >= MAX_WIDTH) {
             span->end = count;
-#if FLAGS & (TEXTURE | SPRITE)
-            if (ctx->Texture._EnabledUnits)
-               _swrast_write_texture_span(ctx, span);
-            else
-               _swrast_write_rgba_span(ctx, span);
-#elif FLAGS & RGBA
+#if FLAGS & RGBA
             _swrast_write_rgba_span(ctx, span);
 #else
             _swrast_write_index_span(ctx, span);
@@ -364,12 +354,7 @@ NAME ( GLcontext *ctx, const SWvertex *vert )
       /* check if we need to flush */
       if (span->end >= MAX_WIDTH ||
           (swrast->_RasterMask & (BLEND_BIT | LOGIC_OP_BIT | MASKING_BIT))) {
-#if FLAGS & (TEXTURE | SPRITE)
-         if (ctx->Texture._EnabledUnits)
-            _swrast_write_texture_span(ctx, span);
-         else
-            _swrast_write_rgba_span(ctx, span);
-#elif FLAGS & RGBA
+#if FLAGS & RGBA
          _swrast_write_rgba_span(ctx, span);
 #else
          _swrast_write_index_span(ctx, span);
index 247c7ee688ca7f1cd38d3461076d8f0f8be48908..84415309569220421d87fc3725fa6233a8c2b65a 100644 (file)
@@ -80,7 +80,7 @@ _swrast_span_default_fog( GLcontext *ctx, struct sw_span *span )
 
 
 /**
- * Init span's color or index interpolation values to the RasterPos color.
+ * Init span's rgba or index interpolation values to the RasterPos color.
  * Used during setup for glDraw/CopyPixels.
  */
 void
@@ -127,7 +127,10 @@ _swrast_span_default_texcoords( GLcontext *ctx, struct sw_span *span )
    GLuint i;
    for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
       const GLfloat *tc = ctx->Current.RasterTexCoords[i];
-      if (tc[3] > 0.0F) {
+      if (ctx->FragmentProgram._Enabled) {
+         COPY_4V(span->tex[i], tc);
+      }
+      else if (tc[3] > 0.0F) {
          /* use (s/q, t/q, r/q, 1) */
          span->tex[i][0] = tc[0] / tc[3];
          span->tex[i][1] = tc[1] / tc[3];
@@ -884,7 +887,7 @@ _swrast_write_index_span( GLcontext *ctx, struct sw_span *span)
       span->writeAll = GL_FALSE;
    }
    else {
-      MEMSET(span->array->mask, 1, span->end);
+      _mesa_memset(span->array->mask, 1, span->end);
       span->writeAll = GL_TRUE;
    }
 
@@ -903,6 +906,7 @@ _swrast_write_index_span( GLcontext *ctx, struct sw_span *span)
    }
 
 #ifdef DEBUG
+   /* Make sure all fragments are within window bounds */
    if (span->arrayMask & SPAN_XY) {
       GLuint i;
       for (i = 0; i < span->end; i++) {
@@ -1036,262 +1040,6 @@ _swrast_write_index_span( GLcontext *ctx, struct sw_span *span)
 }
 
 
-/**
- * This function may modify any of the array values in the span.
- * span->interpMask and span->arrayMask may be changed but will be restored
- * to their original values before returning.
- */
-void
-_swrast_write_rgba_span( GLcontext *ctx, struct sw_span *span)
-{
-   SWcontext *swrast = SWRAST_CONTEXT(ctx);
-   const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask);
-   const GLuint origInterpMask = span->interpMask;
-   const GLuint origArrayMask = span->arrayMask;
-   GLboolean monoColor;
-
-   ASSERT(span->end <= MAX_WIDTH);
-   ASSERT(span->primitive == GL_POINT  ||  span->primitive == GL_LINE ||
-         span->primitive == GL_POLYGON  ||  span->primitive == GL_BITMAP);
-   ASSERT((span->interpMask & span->arrayMask) == 0);
-   ASSERT((span->interpMask | span->arrayMask) & SPAN_RGBA);
-#ifdef DEBUG
-   if (ctx->Fog.Enabled)
-      ASSERT((span->interpMask | span->arrayMask) & SPAN_FOG);
-   if (ctx->Depth.Test)
-      ASSERT((span->interpMask | span->arrayMask) & SPAN_Z);
-#endif
-
-   if (span->arrayMask & SPAN_MASK) {
-      /* mask was initialized by caller, probably glBitmap */
-      span->writeAll = GL_FALSE;
-   }
-   else {
-      MEMSET(span->array->mask, 1, span->end);
-      span->writeAll = GL_TRUE;
-   }
-
-   /* Determine if we have mono-chromatic colors */
-   monoColor = (span->interpMask & SPAN_RGBA) &&
-      span->redStep == 0 && span->greenStep == 0 &&
-      span->blueStep == 0 && span->alphaStep == 0;
-
-   /* Clipping */
-   if ((swrast->_RasterMask & CLIP_BIT) || (span->primitive != GL_POLYGON)) {
-      if (!clip_span(ctx, span)) {
-         return;
-      }
-   }
-
-   /* Depth bounds test */
-   if (ctx->Depth.BoundsTest && ctx->Visual.depthBits > 0) {
-      if (!_swrast_depth_bounds_test(ctx, span)) {
-         return;
-      }
-   }
-
-#ifdef DEBUG
-   if (span->arrayMask & SPAN_XY) {
-      GLuint i;
-      for (i = 0; i < span->end; i++) {
-         if (span->array->mask[i]) {
-            assert(span->array->x[i] >= ctx->DrawBuffer->_Xmin);
-            assert(span->array->x[i] < ctx->DrawBuffer->_Xmax);
-            assert(span->array->y[i] >= ctx->DrawBuffer->_Ymin);
-            assert(span->array->y[i] < ctx->DrawBuffer->_Ymax);
-         }
-      }
-   }
-#endif
-
-   /* Polygon Stippling */
-   if (ctx->Polygon.StippleFlag && span->primitive == GL_POLYGON) {
-      stipple_polygon_span(ctx, span);
-   }
-
-   /* Fragment program */
-   if (ctx->FragmentProgram._Enabled) {
-      /* Now we may need to interpolate the colors and texcoords */
-      if ((span->interpMask & SPAN_RGBA) &&
-          (span->arrayMask & SPAN_RGBA) == 0) {
-         interpolate_colors(ctx, span);
-         span->interpMask &= ~SPAN_RGBA;
-      }
-      if (span->interpMask & SPAN_SPEC) {
-         interpolate_specular(ctx, span);
-      }
-      if ((span->interpMask & SPAN_TEXTURE)
-          && (span->arrayMask & SPAN_TEXTURE) == 0)
-         interpolate_texcoords(ctx, span);
-      _swrast_exec_fragment_program(ctx, span);
-      monoColor = GL_FALSE;
-   }
-
-   /* Do the alpha test */
-   if (ctx->Color.AlphaEnabled) {
-      if (!_swrast_alpha_test(ctx, span)) {
-         span->interpMask = origInterpMask;
-         span->arrayMask = origArrayMask;
-        return;
-      }
-   }
-
-   /* Stencil and Z testing */
-   if (ctx->Stencil.Enabled || ctx->Depth.Test) {
-      if (span->interpMask & SPAN_Z)
-         _swrast_span_interpolate_z(ctx, span);
-
-      if (ctx->Stencil.Enabled) {
-         if (!_swrast_stencil_and_ztest_span(ctx, span)) {
-            span->interpMask = origInterpMask;
-            span->arrayMask = origArrayMask;
-            return;
-         }
-      }
-      else {
-         ASSERT(ctx->Depth.Test);
-         ASSERT(span->arrayMask & SPAN_Z);
-         /* regular depth testing */
-         if (!_swrast_depth_test_span(ctx, span)) {
-            span->interpMask = origInterpMask;
-            span->arrayMask = origArrayMask;
-            return;
-         }
-      }
-   }
-
-   /* if we get here, something passed the depth test */
-   if (ctx->Depth.OcclusionTest) {
-      ctx->OcclusionResult = GL_TRUE;
-   }
-
-#if FEATURE_ARB_occlusion_query
-   if (ctx->Occlusion.Active) {
-      /* update count of 'passed' fragments */
-      GLuint i;
-      for (i = 0; i < span->end; i++)
-         ctx->Occlusion.PassedCounter += span->array->mask[i];
-   }
-#endif
-
-   /* can't abort span-writing until after occlusion testing */
-   if (colorMask == 0x0) {
-      span->interpMask = origInterpMask;
-      span->arrayMask = origArrayMask;
-      return;
-   }
-
-   /* Now we may need to interpolate the colors */
-   if ((span->interpMask & SPAN_RGBA) && (span->arrayMask & SPAN_RGBA) == 0) {
-      interpolate_colors(ctx, span);
-      /* clear the bit - this allows the WriteMonoCISpan optimization below */
-      span->interpMask &= ~SPAN_RGBA;
-   }
-
-   /* Fog */
-   if (swrast->_FogEnabled) {
-      _swrast_fog_rgba_span(ctx, span);
-      monoColor = GL_FALSE;
-   }
-
-   /* Antialias coverage application */
-   if (span->arrayMask & SPAN_COVERAGE) {
-      GLchan (*rgba)[4] = span->array->rgba;
-      GLfloat *coverage = span->array->coverage;
-      GLuint i;
-      for (i = 0; i < span->end; i++) {
-         rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * coverage[i]);
-      }
-      monoColor = GL_FALSE;
-   }
-
-   if (swrast->_RasterMask & MULTI_DRAW_BIT) {
-      multi_write_rgba_span(ctx, span);
-   }
-   else {
-      /* normal: write to exactly one buffer */
-      if (ctx->Color._LogicOpEnabled) {
-         _swrast_logicop_rgba_span(ctx, span, span->array->rgba);
-         monoColor = GL_FALSE;
-      }
-      else if (ctx->Color.BlendEnabled) {
-         _swrast_blend_span(ctx, span, span->array->rgba);
-         monoColor = GL_FALSE;
-      }
-
-      /* Color component masking */
-      if (colorMask != 0xffffffff) {
-         _swrast_mask_rgba_span(ctx, span, span->array->rgba);
-         monoColor = GL_FALSE;
-      }
-
-      /* write pixels */
-      if (span->arrayMask & SPAN_XY) {
-         /* array of pixel coords */
-         if (monoColor) {
-            /* all pixels have same color */
-            GLchan color[4];
-            color[RCOMP] = FixedToChan(span->red);
-            color[GCOMP] = FixedToChan(span->green);
-            color[BCOMP] = FixedToChan(span->blue);
-            color[ACOMP] = FixedToChan(span->alpha);
-            (*swrast->Driver.WriteMonoRGBAPixels)(ctx, span->end,
-                     span->array->x, span->array->y, color, span->array->mask);
-            if (SWRAST_CONTEXT(ctx)->_RasterMask & ALPHABUF_BIT) {
-               _swrast_write_mono_alpha_pixels(ctx, span->end,
-                                              span->array->x, span->array->y,
-                                              color[ACOMP], span->array->mask);
-            }
-         }
-         else {
-            (*swrast->Driver.WriteRGBAPixels)(ctx, span->end,
-                                       span->array->x, span->array->y,
-                                       (const GLchan (*)[4]) span->array->rgba,
-                                       span->array->mask);
-            if (SWRAST_CONTEXT(ctx)->_RasterMask & ALPHABUF_BIT) {
-               _swrast_write_alpha_pixels(ctx, span->end,
-                                       span->array->x, span->array->y,
-                                       (const GLchan (*)[4]) span->array->rgba,
-                                       span->array->mask);
-            }
-         }
-      }
-      else {
-         /* horizontal run of pixels */
-         if (monoColor) {
-            /* all pixels have same color */
-            GLchan color[4];
-            color[RCOMP] = FixedToChan(span->red);
-            color[GCOMP] = FixedToChan(span->green);
-            color[BCOMP] = FixedToChan(span->blue);
-            color[ACOMP] = FixedToChan(span->alpha);
-            (*swrast->Driver.WriteMonoRGBASpan)(ctx, span->end, span->x,
-                                           span->y, color, span->array->mask);
-            if (swrast->_RasterMask & ALPHABUF_BIT) {
-               _swrast_write_mono_alpha_span(ctx, span->end, span->x, span->y,
-                      color[ACOMP],
-                      span->writeAll ? ((const GLubyte *) NULL) : span->array->mask);
-            }
-         }
-         else {
-            /* each pixel is a different color */
-            (*swrast->Driver.WriteRGBASpan)(ctx, span->end, span->x, span->y,
-                      (const GLchan (*)[4]) span->array->rgba,
-                      span->writeAll ? ((const GLubyte *) NULL) : span->array->mask);
-            if (swrast->_RasterMask & ALPHABUF_BIT) {
-               _swrast_write_alpha_span(ctx, span->end, span->x, span->y,
-                      (const GLchan (*)[4]) span->array->rgba,
-                      span->writeAll ? ((const GLubyte *) NULL) : span->array->mask);
-            }
-         }
-      }
-   }
-
-   span->interpMask = origInterpMask;
-   span->arrayMask = origArrayMask;
-}
-
-
 /**
  * Add specular color to base color.  This is used only when
  * GL_LIGHT_MODEL_COLOR_CONTROL = GL_SEPARATE_SPECULAR_COLOR.
@@ -1319,12 +1067,14 @@ add_colors(GLuint n, GLchan rgba[][4], GLchan specular[][4] )
 
 
 /**
+ * Apply all the per-fragment operations to a span.
+ * This now includes texturing (_swrast_write_texture_span() is history).
  * This function may modify any of the array values in the span.
  * span->interpMask and span->arrayMask may be changed but will be restored
  * to their original values before returning.
  */
 void
-_swrast_write_texture_span( GLcontext *ctx, struct sw_span *span)
+_swrast_write_rgba_span( GLcontext *ctx, struct sw_span *span)
 {
    const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask);
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
@@ -1335,10 +1085,10 @@ _swrast_write_texture_span( GLcontext *ctx, struct sw_span *span)
          span->primitive == GL_POLYGON  ||  span->primitive == GL_BITMAP);
    ASSERT(span->end <= MAX_WIDTH);
    ASSERT((span->interpMask & span->arrayMask) == 0);
-   ASSERT(ctx->Texture._EnabledCoordUnits || ctx->FragmentProgram._Enabled);
 
    /*
-   printf("%s()  interp 0x%x  array 0x%x\n", __FUNCTION__, span->interpMask, span->arrayMask);
+   printf("%s()  interp 0x%x  array 0x%x\n", __FUNCTION__,
+          span->interpMask, span->arrayMask);
    */
 
    if (span->arrayMask & SPAN_MASK) {
@@ -1346,11 +1096,11 @@ _swrast_write_texture_span( GLcontext *ctx, struct sw_span *span)
       span->writeAll = GL_FALSE;
    }
    else {
-      MEMSET(span->array->mask, 1, span->end);
+      _mesa_memset(span->array->mask, 1, span->end);
       span->writeAll = GL_TRUE;
    }
 
-   /* Clipping */
+   /* Clip to window/scissor box */
    if ((swrast->_RasterMask & CLIP_BIT) || (span->primitive != GL_POLYGON)) {
       if (!clip_span(ctx, span)) {
         return;
@@ -1358,6 +1108,7 @@ _swrast_write_texture_span( GLcontext *ctx, struct sw_span *span)
    }
 
 #ifdef DEBUG
+   /* Make sure all fragments are within window bounds */
    if (span->arrayMask & SPAN_XY) {
       GLuint i;
       for (i = 0; i < span->end; i++) {
@@ -1376,28 +1127,33 @@ _swrast_write_texture_span( GLcontext *ctx, struct sw_span *span)
       stipple_polygon_span(ctx, span);
    }
 
-   /* Need texture coordinates now */
-   if ((span->interpMask & SPAN_TEXTURE)
-       && (span->arrayMask & SPAN_TEXTURE) == 0)
+   /* Interpolate texcoords? */
+   if (ctx->Texture._EnabledCoordUnits
+       && (span->interpMask & SPAN_TEXTURE)
+       && (span->arrayMask & SPAN_TEXTURE) == 0) {
       interpolate_texcoords(ctx, span);
+   }
 
-   /* Texture with alpha test */
+   /* If the alpha test is enabled, we have to compute the fragment colors
+    * at this point and do the alpha test.
+    * Else, if alpha test is not enabled, we'll try to defer fragment
+    * color computation (by interpolation, texture mapping, fragment program)
+    * until after the Z/stencil tests in the hope that many fragments will
+    * get culled, leaving less work to do.
+    */
    if (ctx->Color.AlphaEnabled) {
-
       /* Now we need the rgba array, fill it in if needed */
       if ((span->interpMask & SPAN_RGBA) && (span->arrayMask & SPAN_RGBA) == 0)
          interpolate_colors(ctx, span);
 
-      if (span->interpMask & SPAN_SPEC) {
+      if (span->interpMask & SPAN_SPEC)
          interpolate_specular(ctx, span);
-      }
 
-      /* Texturing without alpha is done after depth-testing which
-       * gives a potential speed-up.
-       */
+      /* Compute fragment colors with fragment program or texture lookups */
       if (ctx->FragmentProgram._Enabled)
+         /* XXX interpolate depth values here??? */
          _swrast_exec_fragment_program( ctx, span );
-      else
+      else if (ctx->Texture._EnabledUnits)
          _swrast_texture_span( ctx, span );
 
       /* Do the alpha test */
@@ -1413,6 +1169,7 @@ _swrast_write_texture_span( GLcontext *ctx, struct sw_span *span)
          _swrast_span_interpolate_z(ctx, span);
 
       if (ctx->Stencil.Enabled) {
+         /* Combined Z/stencil tests */
          if (!_swrast_stencil_and_ztest_span(ctx, span)) {
             span->interpMask = origInterpMask;
             span->arrayMask = origArrayMask;
@@ -1420,9 +1177,9 @@ _swrast_write_texture_span( GLcontext *ctx, struct sw_span *span)
          }
       }
       else {
+         /* Just regular depth testing */
          ASSERT(ctx->Depth.Test);
          ASSERT(span->arrayMask & SPAN_Z);
-         /* regular depth testing */
          if (!_swrast_depth_test_span(ctx, span)) {
             span->interpMask = origInterpMask;
             span->arrayMask = origArrayMask;
@@ -1445,7 +1202,7 @@ _swrast_write_texture_span( GLcontext *ctx, struct sw_span *span)
    }
 #endif
 
-   /* We had to wait until now to check for glColorMask(F,F,F,F) because of
+   /* We had to wait until now to check for glColorMask(0,0,0,0) because of
     * the occlusion test.
     */
    if (colorMask == 0x0) {
@@ -1454,20 +1211,21 @@ _swrast_write_texture_span( GLcontext *ctx, struct sw_span *span)
       return;
    }
 
-   /* Texture without alpha test */
+   /* If the alpha test isn't enabled, we're able to defer computing fragment
+    * colors (by interpolation, texturing, fragment program) until now.
+    * Hopefully, Z/stencil tests culled many of the fragments!
+    */
    if (!ctx->Color.AlphaEnabled) {
-
       /* Now we need the rgba array, fill it in if needed */
       if ((span->interpMask & SPAN_RGBA) && (span->arrayMask & SPAN_RGBA) == 0)
          interpolate_colors(ctx, span);
 
-      if (span->interpMask & SPAN_SPEC) {
+      if (span->interpMask & SPAN_SPEC)
          interpolate_specular(ctx, span);
-      }
 
       if (ctx->FragmentProgram._Enabled)
          _swrast_exec_fragment_program( ctx, span );
-      else
+      else if (ctx->Texture._EnabledUnits)
          _swrast_texture_span( ctx, span );
    }
 
@@ -1481,8 +1239,14 @@ _swrast_write_texture_span( GLcontext *ctx, struct sw_span *span)
          if (span->interpMask & SPAN_SPEC) {
             interpolate_specular(ctx, span);
          }
-         ASSERT(span->arrayMask & SPAN_SPEC);
-         add_colors( span->end, span->array->rgba, span->array->spec );
+         if (span->arrayMask & SPAN_SPEC) {
+            add_colors( span->end, span->array->rgba, span->array->spec );
+         }
+         else {
+            /* We probably added the base/specular colors during the
+             * vertex stage!
+             */
+         }
       }
    }
 
@@ -1502,6 +1266,7 @@ _swrast_write_texture_span( GLcontext *ctx, struct sw_span *span)
    }
 
    if (swrast->_RasterMask & MULTI_DRAW_BIT) {
+      /* need to do blend/logicop separately for each color buffer */
       multi_write_rgba_span(ctx, span);
    }
    else {
@@ -1518,11 +1283,12 @@ _swrast_write_texture_span( GLcontext *ctx, struct sw_span *span)
          _swrast_mask_rgba_span(ctx, span, span->array->rgba);
       }
 
-      /* write pixels */
+      /* Finally, write the pixels to a color buffer */
       if (span->arrayMask & SPAN_XY) {
          /* array of pixel coords */
-         (*swrast->Driver.WriteRGBAPixels)(ctx, span->end, span->array->x,
-             span->array->y, (const GLchan (*)[4]) span->array->rgba, span->array->mask);
+         swrast->Driver.WriteRGBAPixels(ctx, span->end, span->array->x,
+                       span->array->y, (const GLchan (*)[4]) span->array->rgba,
+                       span->array->mask);
          if (SWRAST_CONTEXT(ctx)->_RasterMask & ALPHABUF_BIT) {
             _swrast_write_alpha_pixels(ctx, span->end,
                                      span->array->x, span->array->y,
@@ -1532,9 +1298,9 @@ _swrast_write_texture_span( GLcontext *ctx, struct sw_span *span)
       }
       else {
          /* horizontal run of pixels */
-         (*swrast->Driver.WriteRGBASpan)(ctx, span->end, span->x, span->y,
-                                       (const GLchan (*)[4]) span->array->rgba,
-                                       span->writeAll ? NULL : span->array->mask);
+         swrast->Driver.WriteRGBASpan(ctx, span->end, span->x, span->y,
+                                    (const GLchan (*)[4]) span->array->rgba,
+                                    span->writeAll ? NULL : span->array->mask);
          if (swrast->_RasterMask & ALPHABUF_BIT) {
             _swrast_write_alpha_span(ctx, span->end, span->x, span->y,
                                    (const GLchan (*)[4]) span->array->rgba,
@@ -1555,7 +1321,7 @@ _swrast_write_texture_span( GLcontext *ctx, struct sw_span *span)
  */
 void
 _swrast_read_rgba_span( GLcontext *ctx, GLframebuffer *buffer,
-                      GLuint n, GLint x, GLint y, GLchan rgba[][4] )
+                        GLuint n, GLint x, GLint y, GLchan rgba[][4] )
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    const GLint bufWidth = (GLint) buffer->Width;
@@ -1609,7 +1375,7 @@ _swrast_read_rgba_span( GLcontext *ctx, GLframebuffer *buffer,
  */
 void
 _swrast_read_index_span( GLcontext *ctx, GLframebuffer *buffer,
-                       GLuint n, GLint x, GLint y, GLuint indx[] )
+                         GLuint n, GLint x, GLint y, GLuint indx[] )
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    const GLint bufWidth = (GLint) buffer->Width;
index ee78a0e8e042978f46b205f640b0799ef4c5e95f..29c485c4d0cc32415f53a8238cfab0fc7d38e4fd 100644 (file)
@@ -1,9 +1,8 @@
-
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  6.3
  *
- * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -49,8 +48,8 @@ _swrast_span_default_texcoords( GLcontext *ctx, struct sw_span *span );
 
 extern GLfloat
 _swrast_compute_lambda(GLfloat dsdx, GLfloat dsdy, GLfloat dtdx, GLfloat dtdy,
-                     GLfloat dqdx, GLfloat dqdy, GLfloat texW, GLfloat texH,
-                     GLfloat s, GLfloat t, GLfloat q, GLfloat invQ);
+                       GLfloat dqdx, GLfloat dqdy, GLfloat texW, GLfloat texH,
+                       GLfloat s, GLfloat t, GLfloat q, GLfloat invQ);
 
 extern void
 _swrast_write_index_span( GLcontext *ctx, struct sw_span *span);
@@ -60,16 +59,12 @@ extern void
 _swrast_write_rgba_span( GLcontext *ctx, struct sw_span *span);
 
 
-extern void
-_swrast_write_texture_span( GLcontext *ctx, struct sw_span *span);
-
-
 extern void
 _swrast_read_rgba_span( GLcontext *ctx, GLframebuffer *buffer,
-                      GLuint n, GLint x, GLint y, GLchan rgba[][4] );
+                        GLuint n, GLint x, GLint y, GLchan rgba[][4] );
 
 extern void
 _swrast_read_index_span( GLcontext *ctx, GLframebuffer *buffer,
-                       GLuint n, GLint x, GLint y, GLuint indx[] );
+                         GLuint n, GLint x, GLint y, GLuint indx[] );
 
 #endif
index a1a629c18d284c75b5e1120adf4079231a7c4360..c236e525709641a3798e8a71fc96b788311f026c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.1
+ * Version:  6.3
  *
  * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
  *
@@ -676,6 +676,9 @@ fast_persp_span(GLcontext *ctx, struct sw_span *span,
    GLfloat tex_coord[3], tex_step[3];
    GLchan *dest = span->array->rgba[0];
 
+   const GLuint savedTexEnable = ctx->Texture._EnabledUnits;
+   ctx->Texture._EnabledUnits = 0;
+
    tex_coord[0] = span->tex[0][0]  * (info->smask + 1);
    tex_step[0] = span->texStepX[0][0] * (info->smask + 1);
    tex_coord[1] = span->tex[0][1] * (info->tmask + 1);
@@ -785,6 +788,9 @@ fast_persp_span(GLcontext *ctx, struct sw_span *span,
 
 #undef SPAN_NEAREST
 #undef SPAN_LINEAR
+
+   /* restore state */
+   ctx->Texture._EnabledUnits = savedTexEnable;
 }
 
 
@@ -873,7 +879,7 @@ fast_persp_span(GLcontext *ctx, struct sw_span *span,
 #define INTERP_SPEC 1
 #define INTERP_ALPHA 1
 #define INTERP_TEX 1
-#define RENDER_SPAN( span )   _swrast_write_texture_span(ctx, &span);
+#define RENDER_SPAN( span )   _swrast_write_rgba_span(ctx, &span);
 #include "s_tritemp.h"
 
 
@@ -891,7 +897,7 @@ fast_persp_span(GLcontext *ctx, struct sw_span *span,
 #define INTERP_ALPHA 1
 #define INTERP_SPEC 1
 #define INTERP_MULTITEX 1
-#define RENDER_SPAN( span )   _swrast_write_texture_span(ctx, &span);
+#define RENDER_SPAN( span )   _swrast_write_rgba_span(ctx, &span);
 #include "s_tritemp.h"