swrast: implement GL_ARB_texture_storage
[mesa.git] / src / mesa / swrast / s_points.c
index 6e7e7010b2b420c019139bacd83c04c6ca7076ed..11b7ef7b1f83423c948a7d632a86d5995a96e0c2 100644 (file)
@@ -1,21 +1,19 @@
-/* $Id: s_points.c,v 1.8 2000/12/08 00:18:39 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
- * 
- * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
- * 
+ * Version:  7.1
+ *
+ * Copyright (C) 1999-2007  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"),
  * to deal in the Software without restriction, including without limitation
  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  * and/or sell copies of the Software, and to permit persons to whom the
  * Software is furnished to do so, subject to the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice shall be included
  * in all copies or substantial portions of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  */
 
 
-#include "glheader.h"
-#include "context.h"
-#include "macros.h"
-#include "mmath.h"
-#include "texstate.h"
-
+#include "main/glheader.h"
+#include "main/colormac.h"
+#include "main/macros.h"
 #include "s_context.h"
 #include "s_feedback.h"
-#include "s_pb.h"
 #include "s_points.h"
 #include "s_span.h"
 
 
-/**********************************************************************/
-/*****                    Rasterization                           *****/
-/**********************************************************************/
-
-
-/*
- * There are 3 pairs (RGBA, CI) of point rendering functions:
- *   1. simple:  size=1 and no special rasterization functions (fastest)
- *   2. size1:  size=1 and any rasterization functions
- *   3. general:  any size and rasterization functions (slowest)
- *
- */
-
-
-
-
-
-/*
- * CI points with size == 1.0
- */
-static void
-size1_ci_point( GLcontext *ctx, const SWvertex *vert )
-{
-   struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
-   GLint *pbx = PB->x, *pby = PB->y;
-   GLdepth *pbz = PB->z;
-   GLfixed *pbfog = PB->fog;
-   GLuint *pbi = PB->index;
-   GLuint pbcount = PB->count;
-
-   pbx[pbcount] = (GLint) vert->win[0];
-   pby[pbcount] = (GLint) vert->win[1];
-   pbz[pbcount] = (GLint) vert->win[2];
-   pbfog[pbcount] = FloatToFixed(vert->fog);
-   pbi[pbcount] = vert->index;
-
-   PB->count++;
-   PB_CHECK_FLUSH(ctx, PB);
-}
-
-
-
-/*
- * RGBA points with size == 1.0
+/**
+ * Used to cull points with invalid coords
  */
-static void
-size1_rgba_point( GLcontext *ctx, const SWvertex *vert )
-{
-   struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
-
-   GLint x = (GLint)  vert->win[0];
-   GLint y = (GLint)  vert->win[1];
-   GLint z = (GLint) (vert->win[2]);
-   GLfixed fog = FloatToFixed( vert->fog );
-   GLubyte red   = vert->color[0];
-   GLubyte green = vert->color[1];
-   GLubyte blue  = vert->color[2];
-   GLubyte alpha = vert->color[3];
-
-   PB_WRITE_RGBA_PIXEL( PB, x, y, z, fog, red, green, blue, alpha );
-   PB_CHECK_FLUSH(ctx, PB);
-}
+#define CULL_INVALID(V)                              \
+   do {                                              \
+      float tmp = (V)->attrib[FRAG_ATTRIB_WPOS][0]   \
+                + (V)->attrib[FRAG_ATTRIB_WPOS][1];  \
+      if (IS_INF_OR_NAN(tmp))                        \
+        return;                                     \
+   } while(0)
 
 
 
-/*
- * General CI points.
+/**
+ * Get/compute the point size.
+ * The size may come from a vertex shader, or computed with attentuation
+ * or just the glPointSize value.
+ * Must also clamp to user-defined range and implmentation limits.
  */
-static void
-general_ci_point( GLcontext *ctx, const SWvertex *vert )
+static inline GLfloat
+get_size(const struct gl_context *ctx, const SWvertex *vert, GLboolean smoothed)
 {
-   struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
-   const GLint isize = (GLint) (ctx->Point._Size + 0.5F);
-   GLint radius = isize >> 1;
+   GLfloat size;
 
-   GLint x0, x1, y0, y1;
-   GLint ix, iy;
-
-   GLint x = (GLint)  vert->win[0];
-   GLint y = (GLint)  vert->win[1];
-   GLint z = (GLint) (vert->win[2]);
-
-   GLfixed fog = FloatToFixed( vert->fog );
-
-   if (isize & 1) {
-      /* odd size */
-      x0 = x - radius;
-      x1 = x + radius;
-      y0 = y - radius;
-      y1 = y + radius;
+   if (ctx->Point._Attenuated || ctx->VertexProgram.PointSizeEnabled) {
+      /* use vertex's point size */
+      size = vert->pointSize;
    }
    else {
-      /* even size */
-      x0 = (GLint) (x + 1.5F) - radius;
-      x1 = x0 + isize - 1;
-      y0 = (GLint) (y + 1.5F) - radius;
-      y1 = y0 + isize - 1;
-   }
-
-   PB_SET_INDEX( PB, vert->index );
+      /* use constant point size */
+      size = ctx->Point.Size;
+   }
+   /* always clamp to user-specified limits */
+   size = CLAMP(size, ctx->Point.MinSize, ctx->Point.MaxSize);
+   /* clamp to implementation limits */
+   if (smoothed)
+      size = CLAMP(size, ctx->Const.MinPointSizeAA, ctx->Const.MaxPointSizeAA);
+   else
+      size = CLAMP(size, ctx->Const.MinPointSize, ctx->Const.MaxPointSize);
 
-   for (iy = y0; iy <= y1; iy++) {
-      for (ix = x0; ix <= x1; ix++) {
-        PB_WRITE_PIXEL( PB, ix, iy, z, fog );
-      }
-   }
-   PB_CHECK_FLUSH(ctx,PB);
+   return size;
 }
 
 
-/*
- * General RGBA points.
+/**
+ * Draw a point sprite
  */
 static void
-general_rgba_point( GLcontext *ctx, const SWvertex *vert )
+sprite_point(struct gl_context *ctx, const SWvertex *vert)
 {
-   struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
-   GLint isize = (GLint) (ctx->Point._Size + 0.5F);
-   GLint radius = isize >> 1;
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   SWspan span;
+   GLfloat size;
+   GLuint tCoords[MAX_TEXTURE_COORD_UNITS + 1];
+   GLuint numTcoords = 0;
+   GLfloat t0, dtdy;
 
-   GLint x0, x1, y0, y1;
-   GLint ix, iy;
+   CULL_INVALID(vert);
 
-   GLint x = (GLint)  vert->win[0];
-   GLint y = (GLint)  vert->win[1];
-   GLint z = (GLint) (vert->win[2]);
+   /* z coord */
+   if (ctx->DrawBuffer->Visual.depthBits <= 16)
+      span.z = FloatToFixed(vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
+   else
+      span.z = (GLuint) (vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
+   span.zStep = 0;
+
+   size = get_size(ctx, vert, GL_FALSE);
+
+   /* span init */
+   INIT_SPAN(span, GL_POINT);
+   span.interpMask = SPAN_Z | SPAN_RGBA;
+
+   span.facing = swrast->PointLineFacing;
+
+   span.red   = ChanToFixed(vert->color[0]);
+   span.green = ChanToFixed(vert->color[1]);
+   span.blue  = ChanToFixed(vert->color[2]);
+   span.alpha = ChanToFixed(vert->color[3]);
+   span.redStep = 0;
+   span.greenStep = 0;
+   span.blueStep = 0;
+   span.alphaStep = 0;
+
+   /* need these for fragment programs */
+   span.attrStart[FRAG_ATTRIB_WPOS][3] = 1.0F;
+   span.attrStepX[FRAG_ATTRIB_WPOS][3] = 0.0F;
+   span.attrStepY[FRAG_ATTRIB_WPOS][3] = 0.0F;
+
+   {
+      GLfloat s, r, dsdx;
+
+      /* texcoord / pointcoord interpolants */
+      s = 0.0F;
+      dsdx = 1.0F / size;
+      if (ctx->Point.SpriteOrigin == GL_LOWER_LEFT) {
+         dtdy = 1.0F / size;
+         t0 = 0.5F * dtdy;
+      }
+      else {
+         /* GL_UPPER_LEFT */
+         dtdy = -1.0F / size;
+         t0 = 1.0F + 0.5F * dtdy;
+      }
 
-   GLfixed fog = FloatToFixed( vert->fog );
+      ATTRIB_LOOP_BEGIN
+         if (attr >= FRAG_ATTRIB_TEX0 && attr <= FRAG_ATTRIB_TEX7) {
+            /* a texcoord attribute */
+            const GLuint u = attr - FRAG_ATTRIB_TEX0;
+            ASSERT(u < Elements(ctx->Point.CoordReplace));
+            if (ctx->Point.CoordReplace[u]) {
+               tCoords[numTcoords++] = attr;
+
+               if (ctx->Point.SpriteRMode == GL_ZERO)
+                  r = 0.0F;
+               else if (ctx->Point.SpriteRMode == GL_S)
+                  r = vert->attrib[attr][0];
+               else /* GL_R */
+                  r = vert->attrib[attr][2];
+
+               span.attrStart[attr][0] = s;
+               span.attrStart[attr][1] = 0.0; /* overwritten below */
+               span.attrStart[attr][2] = r;
+               span.attrStart[attr][3] = 1.0;
+
+               span.attrStepX[attr][0] = dsdx;
+               span.attrStepX[attr][1] = 0.0;
+               span.attrStepX[attr][2] = 0.0;
+               span.attrStepX[attr][3] = 0.0;
+
+               span.attrStepY[attr][0] = 0.0;
+               span.attrStepY[attr][1] = dtdy;
+               span.attrStepY[attr][2] = 0.0;
+               span.attrStepY[attr][3] = 0.0;
+
+               continue;
+            }
+         }
+         else if (attr == FRAG_ATTRIB_PNTC) {
+            /* GLSL gl_PointCoord.xy (.zw undefined) */
+            span.attrStart[FRAG_ATTRIB_PNTC][0] = 0.0;
+            span.attrStart[FRAG_ATTRIB_PNTC][1] = 0.0; /* t0 set below */
+            span.attrStepX[FRAG_ATTRIB_PNTC][0] = dsdx;
+            span.attrStepX[FRAG_ATTRIB_PNTC][1] = 0.0;
+            span.attrStepY[FRAG_ATTRIB_PNTC][0] = 0.0;
+            span.attrStepY[FRAG_ATTRIB_PNTC][1] = dtdy;
+            tCoords[numTcoords++] = FRAG_ATTRIB_PNTC;
+            continue;
+         }
+         /* use vertex's texcoord/attrib */
+         COPY_4V(span.attrStart[attr], vert->attrib[attr]);
+         ASSIGN_4V(span.attrStepX[attr], 0, 0, 0, 0);
+         ASSIGN_4V(span.attrStepY[attr], 0, 0, 0, 0);
+      ATTRIB_LOOP_END;
+   }
+
+   /* compute pos, bounds and render */
+   {
+      const GLfloat x = vert->attrib[FRAG_ATTRIB_WPOS][0];
+      const GLfloat y = vert->attrib[FRAG_ATTRIB_WPOS][1];
+      GLint iSize = (GLint) (size + 0.5F);
+      GLint xmin, xmax, ymin, ymax, iy;
+      GLint iRadius;
+      GLfloat tcoord = t0;
+
+      iSize = MAX2(1, iSize);
+      iRadius = iSize / 2;
+
+      if (iSize & 1) {
+         /* odd size */
+         xmin = (GLint) (x - iRadius);
+         xmax = (GLint) (x + iRadius);
+         ymin = (GLint) (y - iRadius);
+         ymax = (GLint) (y + iRadius);
+      }
+      else {
+         /* even size */
+         /* 0.501 factor allows conformance to pass */
+         xmin = (GLint) (x + 0.501) - iRadius;
+         xmax = xmin + iSize - 1;
+         ymin = (GLint) (y + 0.501) - iRadius;
+         ymax = ymin + iSize - 1;
+      }
 
-   if (isize & 1) {
-      /* odd size */
-      x0 = x - radius;
-      x1 = x + radius;
-      y0 = y - radius;
-      y1 = y + radius;
-   }
-   else {
-      /* even size */
-      x0 = (GLint) (x + 1.5F) - radius;
-      x1 = x0 + isize - 1;
-      y0 = (GLint) (y + 1.5F) - radius;
-      y1 = y0 + isize - 1;
-   }
+      /* render spans */
+      for (iy = ymin; iy <= ymax; iy++) {
+         GLuint i;
+         /* setup texcoord T for this row */
+         for (i = 0; i < numTcoords; i++) {
+            span.attrStart[tCoords[i]][1] = tcoord;
+         }
 
-   PB_SET_COLOR( PB,
-                vert->color[0],
-                vert->color[1],
-                vert->color[2],
-                vert->color[3] );
+         /* these might get changed by span clipping */
+         span.x = xmin;
+         span.y = iy;
+         span.end = xmax - xmin + 1;
 
-   for (iy = y0; iy <= y1; iy++) {
-      for (ix = x0; ix <= x1; ix++) {
-        PB_WRITE_PIXEL( PB, ix, iy, z, fog );
+         _swrast_write_rgba_span(ctx, &span);
+
+         tcoord += dtdy;
       }
    }
-   PB_CHECK_FLUSH(ctx,PB);
 }
 
 
-
-
-/*
- * Textured RGBA points.
+/**
+ * Draw smooth/antialiased point.  RGB or CI mode.
  */
 static void
-textured_rgba_point( GLcontext *ctx, const SWvertex *vert )
+smooth_point(struct gl_context *ctx, const SWvertex *vert)
 {
-   struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
-
-   GLint x0, x1, y0, y1;
-   GLint ix, iy, radius;
-   GLint red, green, blue, alpha;
-   GLfloat s, t, u;
-
-   GLint x = (GLint)  vert->win[0];
-   GLint y = (GLint)  vert->win[1];
-   GLint z = (GLint) (vert->win[2]);
-   GLint isize = (GLint) (ctx->Point._Size + 0.5F);
+   SWcontext *swrast = SWRAST_CONTEXT(ctx);
+   SWspan span;
+   GLfloat size, alphaAtten;
 
-   GLfixed fog = FloatToFixed( vert->fog );
+   CULL_INVALID(vert);
 
-   if (isize < 1) {
-      isize = 1;
-   }
-   radius = isize >> 1;
-
-   if (isize & 1) {
-      /* odd size */
-      x0 = x - radius;
-      x1 = x + radius;
-      y0 = y - radius;
-      y1 = y + radius;
-   }
-   else {
-      /* even size */
-      x0 = (GLint) (x + 1.5F) - radius;
-      x1 = x0 + isize - 1;
-      y0 = (GLint) (y + 1.5F) - radius;
-      y1 = y0 + isize - 1;
-   }
+   /* z coord */
+   if (ctx->DrawBuffer->Visual.depthBits <= 16)
+      span.z = FloatToFixed(vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
+   else
+      span.z = (GLuint) (vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
+   span.zStep = 0;
 
-   red   = vert->color[0];
-   green = vert->color[1];
-   blue  = vert->color[2];
-   alpha = vert->color[3];
-
-   if (vert->texcoord[0][3] != 1.0) {
-      s = vert->texcoord[0][0]/vert->texcoord[0][3];
-      t = vert->texcoord[0][1]/vert->texcoord[0][3];
-      u = vert->texcoord[0][2]/vert->texcoord[0][3];
-   } else {
-      s = vert->texcoord[0][0];
-      t = vert->texcoord[0][1];
-      u = vert->texcoord[0][2];
-   }
+   size = get_size(ctx, vert, GL_TRUE);
 
-   for (iy = y0; iy <= y1; iy++) {
-      for (ix = x0; ix <= x1; ix++) {
-        PB_WRITE_TEX_PIXEL( PB, ix, iy, z, fog, red, green, blue, alpha,
-                            s, t, u );
+   /* alpha attenuation / fade factor */
+   if (ctx->Multisample._Enabled) {
+      if (vert->pointSize >= ctx->Point.Threshold) {
+         alphaAtten = 1.0F;
+      }
+      else {
+         GLfloat dsize = vert->pointSize / ctx->Point.Threshold;
+         alphaAtten = dsize * dsize;
       }
-   }
-
-   PB_CHECK_FLUSH(ctx, PB);
-}
-
-
-
-/*
- * Multitextured RGBA points.
- */
-static void
-multitextured_rgba_point( GLcontext *ctx, const SWvertex *vert )
-{
-   struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
-
-   const GLint red   = vert->color[0];
-   const GLint green = vert->color[1];
-   const GLint blue  = vert->color[2];
-   const GLint alpha = vert->color[3];
-   const GLint sRed   = vert->specular[0];
-   const GLint sGreen = vert->specular[1];
-   const GLint sBlue  = vert->specular[2];
-   const GLint x = (GLint)  vert->win[0];
-   const GLint y = (GLint)  vert->win[1];
-   const GLint z = (GLint) (vert->win[2]);
-   GLint x0, x1, y0, y1;
-   GLint ix, iy;
-   GLfloat texcoord[MAX_TEXTURE_UNITS][4];
-   GLint radius, u;
-   GLint isize = (GLint) (ctx->Point._Size + 0.5F);
-
-   GLfixed fog = FloatToFixed( vert->fog );
-
-   if (isize < 1) {
-      isize = 1;
-   }
-   radius = isize >> 1;
-
-   if (isize & 1) {
-      /* odd size */
-      x0 = x - radius;
-      x1 = x + radius;
-      y0 = y - radius;
-      y1 = y + radius;
    }
    else {
-      /* even size */
-      x0 = (GLint) (x + 1.5F) - radius;
-      x1 = x0 + isize - 1;
-      y0 = (GLint) (y + 1.5F) - radius;
-      y1 = y0 + isize - 1;
-   }
+      alphaAtten = 1.0;
+   }
+   (void) alphaAtten; /* not used */
+
+   /* span init */
+   INIT_SPAN(span, GL_POINT);
+   span.interpMask = SPAN_Z | SPAN_RGBA;
+   span.arrayMask = SPAN_COVERAGE | SPAN_MASK;
+
+   span.facing = swrast->PointLineFacing;
+
+   span.red   = ChanToFixed(vert->color[0]);
+   span.green = ChanToFixed(vert->color[1]);
+   span.blue  = ChanToFixed(vert->color[2]);
+   span.alpha = ChanToFixed(vert->color[3]);
+   span.redStep = 0;
+   span.greenStep = 0;
+   span.blueStep = 0;
+   span.alphaStep = 0;
+
+   /* need these for fragment programs */
+   span.attrStart[FRAG_ATTRIB_WPOS][3] = 1.0F;
+   span.attrStepX[FRAG_ATTRIB_WPOS][3] = 0.0F;
+   span.attrStepY[FRAG_ATTRIB_WPOS][3] = 0.0F;
+
+   ATTRIB_LOOP_BEGIN
+      COPY_4V(span.attrStart[attr], vert->attrib[attr]);
+      ASSIGN_4V(span.attrStepX[attr], 0, 0, 0, 0);
+      ASSIGN_4V(span.attrStepY[attr], 0, 0, 0, 0);
+   ATTRIB_LOOP_END
+
+   /* compute pos, bounds and render */
+   {
+      const GLfloat x = vert->attrib[FRAG_ATTRIB_WPOS][0];
+      const GLfloat y = vert->attrib[FRAG_ATTRIB_WPOS][1];
+      const GLfloat radius = 0.5F * size;
+      const GLfloat rmin = radius - 0.7071F;  /* 0.7071 = sqrt(2)/2 */
+      const GLfloat rmax = radius + 0.7071F;
+      const GLfloat rmin2 = MAX2(0.0F, rmin * rmin);
+      const GLfloat rmax2 = rmax * rmax;
+      const GLfloat cscale = 1.0F / (rmax2 - rmin2);
+      const GLint xmin = (GLint) (x - radius);
+      const GLint xmax = (GLint) (x + radius);
+      const GLint ymin = (GLint) (y - radius);
+      const GLint ymax = (GLint) (y + radius);
+      GLint ix, iy;
+
+      for (iy = ymin; iy <= ymax; iy++) {
+
+         /* these might get changed by span clipping */
+         span.x = xmin;
+         span.y = iy;
+         span.end = xmax - xmin + 1;
+
+         /* compute coverage for each pixel in span */
+         for (ix = xmin; ix <= xmax; ix++) {
+            const GLfloat dx = ix - x + 0.5F;
+            const GLfloat dy = iy - y + 0.5F;
+            const GLfloat dist2 = dx * dx + dy * dy;
+            GLfloat coverage;
+
+            if (dist2 < rmax2) {
+               if (dist2 >= rmin2) {
+                  /* compute partial coverage */
+                  coverage = 1.0F - (dist2 - rmin2) * cscale;
+               }
+               else {
+                  /* full coverage */
+                  coverage = 1.0F;
+               }
+               span.array->mask[ix - xmin] = 1;
+            }
+            else {
+               /* zero coverage - fragment outside the radius */
+               coverage = 0.0;
+               span.array->mask[ix - xmin] = 0;
+            }
+            span.array->coverage[ix - xmin] = coverage;
+         }
 
-   for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-      if (ctx->Texture.Unit[u]._ReallyEnabled) {
-        if (vert->texcoord[u][3] != 1.0) {
-           texcoord[u][0] = vert->texcoord[u][0] /
-              vert->texcoord[u][3];
-           texcoord[u][1] = vert->texcoord[u][1] /
-              vert->texcoord[u][3];
-           texcoord[u][2] = vert->texcoord[u][2] /
-              vert->texcoord[u][3];
-        }
-        else {
-           texcoord[u][0] = vert->texcoord[u][0];
-           texcoord[u][1] = vert->texcoord[u][1];
-           texcoord[u][2] = vert->texcoord[u][2];
-        }
-      }
-   }
+         /* render span */
+         _swrast_write_rgba_span(ctx, &span);
 
-   for (iy = y0; iy <= y1; iy++) {
-      for (ix = x0; ix <= x1; ix++) {
-        PB_WRITE_MULTITEX_SPEC_PIXEL( PB, ix, iy, z, fog,
-                                      red, green, blue, alpha,
-                                      sRed, sGreen, sBlue,
-                                      texcoord );
       }
    }
-   PB_CHECK_FLUSH(ctx, PB);
 }
 
 
-/*
- * NOTES on aa point rasterization:
- *
- * Let d = distance of fragment center from vertex.
- * if d < rmin2 then
- *    fragment has 100% coverage
- * else if d > rmax2 then
- *    fragment has 0% coverage
- * else
- *    fragement has % coverage = (d - rmin2) / (rmax2 - rmin2)
- */
-
-
-/*
- * Antialiased points with or without texture mapping.
+/**
+ * Draw large (size >= 1) non-AA point.  RGB or CI mode.
  */
 static void
-antialiased_rgba_point( GLcontext *ctx, const SWvertex *vert )
+large_point(struct gl_context *ctx, const SWvertex *vert)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
-   struct pixel_buffer *PB = swrast->PB;
-   const GLfloat radius = ctx->Point._Size * 0.5F;
-   const GLfloat rmin = radius - 0.7071F;  /* 0.7071 = sqrt(2)/2 */
-   const GLfloat rmax = radius + 0.7071F;
-   const GLfloat rmin2 = MAX2(0.0, rmin * rmin);
-   const GLfloat rmax2 = rmax * rmax;
-   const GLfloat cscale = 256.0F / (rmax2 - rmin2);
-
-   if (ctx->Texture._ReallyEnabled) {
-      GLint x, y;
-      GLfloat vx = vert->win[0];
-      GLfloat vy = vert->win[1];
-      const GLint xmin = (GLint) (vx - radius);
-      const GLint xmax = (GLint) (vx + radius);
-      const GLint ymin = (GLint) (vy - radius);
-      const GLint ymax = (GLint) (vy + radius);
-      const GLint z = (GLint) (vert->win[2]);
-      const GLint red   = vert->color[0];
-      const GLint green = vert->color[1];
-      const GLint blue  = vert->color[2];
-      GLfloat texcoord[MAX_TEXTURE_UNITS][4];
-      GLint u, alpha;
-
-      GLfixed fog = FloatToFixed( vert->fog );
-
-      for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-        if (ctx->Texture.Unit[u]._ReallyEnabled) {
-           if (texcoord[u][3] != 1.0) {
-              texcoord[u][0] = (vert->texcoord[u][0] /
-                                vert->texcoord[u][3]);
-              texcoord[u][1] = (vert->texcoord[u][1] /
-                                vert->texcoord[u][3]);
-              texcoord[u][2] = (vert->texcoord[u][2] /
-                                vert->texcoord[u][3]);
-           } 
-           else {
-              texcoord[u][0] = vert->texcoord[u][0];
-              texcoord[u][1] = vert->texcoord[u][1];
-              texcoord[u][2] = vert->texcoord[u][2];
-           }
-        }
-      }
+   SWspan span;
+   GLfloat size;
 
-      /* translate by a half pixel to simplify math below */
-      vx -= 0.5F;
-      vx -= 0.5F;
-
-      for (y = ymin; y <= ymax; y++) {
-        for (x = xmin; x <= xmax; x++) {
-           const GLfloat dx = x - vx;
-           const GLfloat dy = y - vy;
-           const GLfloat dist2 = dx*dx + dy*dy;
-           if (dist2 < rmax2) {
-              alpha = vert->color[3];
-              if (dist2 >= rmin2) {
-                 GLint coverage = (GLint) (256.0F - (dist2 - rmin2) * cscale);
-                 /* coverage is in [0,256] */
-                 alpha = (alpha * coverage) >> 8;
-              }
-              if (swrast->_MultiTextureEnabled) {
-                 PB_WRITE_MULTITEX_PIXEL( PB, x,y,z, fog,
-                                          red, green, blue, 
-                                          alpha, texcoord );
-              }
-              else {
-                 PB_WRITE_TEX_PIXEL( PB, x,y,z, fog,
-                                     red, green, blue, alpha,
-                                     texcoord[0][0],
-                                     texcoord[0][1],
-                                     texcoord[0][2] );
-              }
-           }
-        }
-      }
+   CULL_INVALID(vert);
 
-      PB_CHECK_FLUSH(ctx,PB);
-   }
-   else {
-      /* Not texture mapped */
-      const GLint xmin = (GLint) (vert->win[0] - 0.0 - radius);
-      const GLint xmax = (GLint) (vert->win[0] - 0.0 + radius);
-      const GLint ymin = (GLint) (vert->win[1] - 0.0 - radius);
-      const GLint ymax = (GLint) (vert->win[1] - 0.0 + radius);
-      const GLint red   = vert->color[0];
-      const GLint green = vert->color[1];
-      const GLint blue  = vert->color[2];
-      const GLint z = (GLint) (vert->win[2]);
-      GLint x, y;
-
-      GLfixed fog = FloatToFixed( vert->fog );
-
-      /*
-       printf("point %g, %g\n", vert->win[0], vert->win[1]);
-       printf("%d..%d X %d..%d\n", xmin, xmax, ymin, ymax);
-      */
-      for (y = ymin; y <= ymax; y++) {
-        for (x = xmin; x <= xmax; x++) {
-           const GLfloat dx = x + 0.5F - vert->win[0];
-           const GLfloat dy = y + 0.5F - vert->win[1];
-           const GLfloat dist2 = dx*dx + dy*dy;
-           if (dist2 < rmax2) {
-              GLint alpha = vert->color[3];
-              if (dist2 >= rmin2) {
-                 GLint coverage = (GLint) (256.0F - (dist2 - rmin2) * cscale);
-                 /* coverage is in [0,256] */
-                 alpha = (alpha * coverage) >> 8;
-              }
-              PB_WRITE_RGBA_PIXEL(PB, x, y, z, fog,
-                                  red, green, blue, alpha);
-           }
-        }
+   /* z coord */
+   if (ctx->DrawBuffer->Visual.depthBits <= 16)
+      span.z = FloatToFixed(vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
+   else
+      span.z = (GLuint) (vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
+   span.zStep = 0;
+
+   size = get_size(ctx, vert, GL_FALSE);
+
+   /* span init */
+   INIT_SPAN(span, GL_POINT);
+   span.arrayMask = SPAN_XY;
+   span.facing = swrast->PointLineFacing;
+
+   span.interpMask = SPAN_Z | SPAN_RGBA;
+   span.red   = ChanToFixed(vert->color[0]);
+   span.green = ChanToFixed(vert->color[1]);
+   span.blue  = ChanToFixed(vert->color[2]);
+   span.alpha = ChanToFixed(vert->color[3]);
+   span.redStep = 0;
+   span.greenStep = 0;
+   span.blueStep = 0;
+   span.alphaStep = 0;
+
+   /* need these for fragment programs */
+   span.attrStart[FRAG_ATTRIB_WPOS][3] = 1.0F;
+   span.attrStepX[FRAG_ATTRIB_WPOS][3] = 0.0F;
+   span.attrStepY[FRAG_ATTRIB_WPOS][3] = 0.0F;
+
+   ATTRIB_LOOP_BEGIN
+      COPY_4V(span.attrStart[attr], vert->attrib[attr]);
+      ASSIGN_4V(span.attrStepX[attr], 0, 0, 0, 0);
+      ASSIGN_4V(span.attrStepY[attr], 0, 0, 0, 0);
+   ATTRIB_LOOP_END
+
+   /* compute pos, bounds and render */
+   {
+      const GLfloat x = vert->attrib[FRAG_ATTRIB_WPOS][0];
+      const GLfloat y = vert->attrib[FRAG_ATTRIB_WPOS][1];
+      GLint iSize = (GLint) (size + 0.5F);
+      GLint xmin, xmax, ymin, ymax, ix, iy;
+      GLint iRadius;
+
+      iSize = MAX2(1, iSize);
+      iRadius = iSize / 2;
+
+      if (iSize & 1) {
+         /* odd size */
+         xmin = (GLint) (x - iRadius);
+         xmax = (GLint) (x + iRadius);
+         ymin = (GLint) (y - iRadius);
+         ymax = (GLint) (y + iRadius);
       }
-      PB_CHECK_FLUSH(ctx,PB);
-   }
-}
-
-
-
-/* Definition of the functions for GL_EXT_point_parameters */
-
-#if 000
-/* Calculates the distance attenuation formula of a vector of points in
- * eye space coordinates 
- */
-static GLfloat attenuation_distance(const GLcontext *ctx, const GLfloat *pos)
-{
-   GLfloat dist = GL_SQRT(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2]);
-   return 1.0F / (ctx->Point.Params[0] +
-                 dist * (ctx->Point.Params[1] +
-                         dist * ctx->Point.Params[2]));
-}
-#endif
-
-
-/*
- * Distance Attenuated General CI points.
- */
-static void
-dist_atten_general_ci_point( GLcontext *ctx, const SWvertex *vert )
-{
-   struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
-   GLint x0, x1, y0, y1;
-   GLint ix, iy;
-   GLint isize, radius;
-   GLint x = (GLint)  vert->win[0];
-   GLint y = (GLint)  vert->win[1];
-   GLint z = (GLint) (vert->win[2]);
-
-   GLfixed fog = FloatToFixed( vert->fog );
-
-   if (vert->pointSize >= ctx->Point.Threshold) {
-      isize = (GLint) (MIN2(vert->pointSize, ctx->Point.MaxSize) + 0.5F);
-   }
-   else {
-      isize = (GLint) (MAX2(ctx->Point.Threshold, ctx->Point.MinSize) + 0.5F);
-   }
-   radius = isize >> 1;
-
-   if (isize & 1) {
-      /* odd size */
-      x0 = x - radius;
-      x1 = x + radius;
-      y0 = y - radius;
-      y1 = y + radius;
-   }
-   else {
-      /* even size */
-      x0 = (GLint) (x + 1.5F) - radius;
-      x1 = x0 + isize - 1;
-      y0 = (GLint) (y + 1.5F) - radius;
-      y1 = y0 + isize - 1;
-   }
-
-   PB_SET_INDEX( PB, vert->index );
-
-   for (iy=y0;iy<=y1;iy++) {
-      for (ix=x0;ix<=x1;ix++) {
-        PB_WRITE_PIXEL( PB, ix, iy, z, fog );
+      else {
+         /* even size */
+         /* 0.501 factor allows conformance to pass */
+         xmin = (GLint) (x + 0.501) - iRadius;
+         xmax = xmin + iSize - 1;
+         ymin = (GLint) (y + 0.501) - iRadius;
+         ymax = ymin + iSize - 1;
       }
-   }
-   PB_CHECK_FLUSH(ctx,PB);
-}
-
-/*
- * Distance Attenuated General RGBA points.
- */
-static void
-dist_atten_general_rgba_point( GLcontext *ctx, const SWvertex *vert )
-{
-   struct pixel_buffer *PB = SWRAST_CONTEXT(ctx)->PB;
-   GLint x0, x1, y0, y1;
-   GLint ix, iy;
-   GLint isize, radius;
-   GLint x = (GLint)  vert->win[0];
-   GLint y = (GLint)  vert->win[1];
-   GLint z = (GLint) (vert->win[2]);
-   GLchan alpha;
-   GLfixed fog = FloatToFixed( vert->fog );
-
-   if (vert->pointSize >= ctx->Point.Threshold) {
-      isize = (GLint) (MIN2(vert->pointSize, ctx->Point.MaxSize) + 0.5F);
-      alpha = vert->color[3];
-   }
-   else {
-      GLfloat dsize = vert->pointSize / ctx->Point.Threshold;
-      isize = (GLint) (MAX2(ctx->Point.Threshold, ctx->Point.MinSize) + 0.5F);
-      alpha = (GLint) (vert->color[3] * (dsize * dsize));
-   }
-   radius = isize >> 1;
-
-   if (isize & 1) {
-      /* odd size */
-      x0 = x - radius;
-      x1 = x + radius;
-      y0 = y - radius;
-      y1 = y + radius;
-   }
-   else {
-      /* even size */
-      x0 = (GLint) (x + 1.5F) - radius;
-      x1 = x0 + isize - 1;
-      y0 = (GLint) (y + 1.5F) - radius;
-      y1 = y0 + isize - 1;
-   }
-
-   PB_SET_COLOR( PB,
-                vert->color[0],
-                vert->color[1],
-                vert->color[2],
-                alpha );
 
-   for (iy = y0; iy <= y1; iy++) {
-      for (ix = x0; ix <= x1; ix++) {
-        PB_WRITE_PIXEL( PB, ix, iy, z, fog );
+      /* generate fragments */
+      span.end = 0;
+      for (iy = ymin; iy <= ymax; iy++) {
+         for (ix = xmin; ix <= xmax; ix++) {
+            span.array->x[span.end] = ix;
+            span.array->y[span.end] = iy;
+            span.end++;
+         }
       }
+      assert(span.end <= MAX_WIDTH);
+      _swrast_write_rgba_span(ctx, &span);
    }
-   PB_CHECK_FLUSH(ctx,PB);
 }
 
-/*
- *  Distance Attenuated Textured RGBA points.
+
+/**
+ * Draw size=1, single-pixel point
  */
 static void
-dist_atten_textured_rgba_point( GLcontext *ctx, const SWvertex *vert )
+pixel_point(struct gl_context *ctx, const SWvertex *vert)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
-   struct pixel_buffer *PB = swrast->PB;
-   const GLint x = (GLint)  vert->win[0];
-   const GLint y = (GLint)  vert->win[1];
-   const GLint z = (GLint) (vert->win[2]);
-   const GLint red   = vert->color[0];
-   const GLint green = vert->color[1];
-   const GLint blue  = vert->color[2];
-   GLfloat texcoord[MAX_TEXTURE_UNITS][4];
-   GLint x0, x1, y0, y1;
-   GLint ix, iy, alpha, u;
-   GLint isize, radius;
-
-   GLfixed fog = FloatToFixed( vert->fog );
-
-   /* compute point size and alpha */
-   if (vert->pointSize >= ctx->Point.Threshold) {
-      isize = (GLint) (MIN2(vert->pointSize, ctx->Point.MaxSize) + 0.5F);
-      alpha = vert->color[3];
-   }
-   else {
-      GLfloat dsize = vert->pointSize / ctx->Point.Threshold;
-      isize = (GLint) (MAX2(ctx->Point.Threshold, ctx->Point.MinSize) + 0.5F);
-      alpha = (GLint) (vert->color[3] * (dsize * dsize));
-   }
-   if (isize < 1) {
-      isize = 1;
-   }
-   radius = isize >> 1;
-
-   if (isize & 1) {
-      /* odd size */
-      x0 = x - radius;
-      x1 = x + radius;
-      y0 = y - radius;
-      y1 = y + radius;
-   }
-   else {
-      /* even size */
-      x0 = (GLint) (x + 1.5F) - radius;
-      x1 = x0 + isize - 1;
-      y0 = (GLint) (y + 1.5F) - radius;
-      y1 = y0 + isize - 1;
-   }
-
-   /* get texture coordinates */
-   for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-      if (ctx->Texture.Unit[u]._ReallyEnabled) {
-        if (texcoord[u][3] != 1.0) {
-           texcoord[u][0] = vert->texcoord[u][0] /
-              vert->texcoord[u][3];
-           texcoord[u][1] = vert->texcoord[u][1] /
-              vert->texcoord[u][3];
-           texcoord[u][2] = vert->texcoord[u][2] /
-              vert->texcoord[u][3];
-        } 
-        else {
-           texcoord[u][0] = vert->texcoord[u][0];
-           texcoord[u][1] = vert->texcoord[u][1];
-           texcoord[u][2] = vert->texcoord[u][2];
-        }
-      }
-   }
-
-   for (iy = y0; iy <= y1; iy++) {
-      for (ix = x0; ix <= x1; ix++) {
-        if (swrast->_MultiTextureEnabled) {
-           PB_WRITE_MULTITEX_PIXEL( PB, ix, iy, z, fog,
-                                    red, green, blue, alpha,
-                                    texcoord );
-        }
-        else {
-           PB_WRITE_TEX_PIXEL( PB, ix, iy, z, fog,
-                               red, green, blue, alpha,
-                               texcoord[0][0],
-                               texcoord[0][1],
-                               texcoord[0][2] );
-        }
+   /*
+    * Note that unlike the other functions, we put single-pixel points
+    * into a special span array in order to render as many points as
+    * possible with a single _swrast_write_rgba_span() call.
+    */
+   SWspan *span = &(swrast->PointSpan);
+   GLuint count;
+
+   CULL_INVALID(vert);
+
+   /* Span init */
+   span->interpMask = 0;
+   span->arrayMask = SPAN_XY | SPAN_Z;
+   span->arrayMask |= SPAN_RGBA;
+   /*span->arrayMask |= SPAN_LAMBDA;*/
+   span->arrayAttribs = swrast->_ActiveAttribMask; /* we'll produce these vals */
+
+   /* need these for fragment programs */
+   span->attrStart[FRAG_ATTRIB_WPOS][3] = 1.0F;
+   span->attrStepX[FRAG_ATTRIB_WPOS][3] = 0.0F;
+   span->attrStepY[FRAG_ATTRIB_WPOS][3] = 0.0F;
+
+   /* check if we need to flush */
+   if (span->end >= MAX_WIDTH ||
+       (swrast->_RasterMask & (BLEND_BIT | LOGIC_OP_BIT | MASKING_BIT)) ||
+       span->facing != swrast->PointLineFacing) {
+      if (span->end > 0) {
+        _swrast_write_rgba_span(ctx, span);
+         span->end = 0;
       }
    }
-   PB_CHECK_FLUSH(ctx,PB);
-}
 
-/*
- * Distance Attenuated Antialiased points with or without texture mapping.
- */
-static void
-dist_atten_antialiased_rgba_point( GLcontext *ctx, const SWvertex *vert )
-{
-   SWcontext *swrast = SWRAST_CONTEXT(ctx);
-   struct pixel_buffer *PB = swrast->PB;
+   count = span->end;
 
-   if (ctx->Texture._ReallyEnabled) {
-      GLfloat radius, rmin, rmax, rmin2, rmax2, cscale, alphaAtten;
-      GLint xmin, ymin, xmax, ymax;
-      GLint x, y, z;
-      GLint red, green, blue, alpha;
-      GLfloat texcoord[MAX_TEXTURE_UNITS][4];
-      GLint u;
+   span->facing = swrast->PointLineFacing;
 
-      GLfixed fog = FloatToFixed( vert->fog );
+   /* fragment attributes */
+   span->array->rgba[count][RCOMP] = vert->color[0];
+   span->array->rgba[count][GCOMP] = vert->color[1];
+   span->array->rgba[count][BCOMP] = vert->color[2];
+   span->array->rgba[count][ACOMP] = vert->color[3];
 
-      if (vert->pointSize >= ctx->Point.Threshold) {
-        radius = MIN2(vert->pointSize, ctx->Point.MaxSize) * 0.5F;
-        alphaAtten = 1.0F;
-      }
-      else {
-        GLfloat dsize = vert->pointSize / ctx->Point.Threshold;
-        radius = (MAX2(ctx->Point.Threshold, ctx->Point.MinSize) * 0.5F);
-        alphaAtten = dsize * dsize;
-      }
-      rmin = radius - 0.7071F;  /* 0.7071 = sqrt(2)/2 */
-      rmax = radius + 0.7071F;
-      rmin2 = MAX2(0.0, rmin * rmin);
-      rmax2 = rmax * rmax;
-      cscale = 256.0F / (rmax2 - rmin2);
-
-      xmin = (GLint) (vert->win[0] - radius);
-      xmax = (GLint) (vert->win[0] + radius);
-      ymin = (GLint) (vert->win[1] - radius);
-      ymax = (GLint) (vert->win[1] + radius);
-      z = (GLint) (vert->win[2]);
-
-      red   = vert->color[0];
-      green = vert->color[1];
-      blue  = vert->color[2];
-        
-      /* get texture coordinates */
-      for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-        if (ctx->Texture.Unit[u]._ReallyEnabled) {
-           if (vert->texcoord[u][3] != 1.0 && vert->texcoord[u][3] != 0.0) {
-              texcoord[u][0] = vert->texcoord[u][0] / vert->texcoord[u][3];
-              texcoord[u][1] = vert->texcoord[u][1] / vert->texcoord[u][3];
-              texcoord[u][2] = vert->texcoord[u][2] / vert->texcoord[u][3];
-           } 
-           else {
-              texcoord[u][0] = vert->texcoord[u][0];
-              texcoord[u][1] = vert->texcoord[u][1];
-              texcoord[u][2] = vert->texcoord[u][2];
-           }
-        }
-      }
+   ATTRIB_LOOP_BEGIN
+      COPY_4V(span->array->attribs[attr][count], vert->attrib[attr]);
+   ATTRIB_LOOP_END
 
-      for (y = ymin; y <= ymax; y++) {
-        for (x = xmin; x <= xmax; x++) {
-           const GLfloat dx = x + 0.5F - vert->win[0];
-           const GLfloat dy = y + 0.5F - vert->win[1];
-           const GLfloat dist2 = dx*dx + dy*dy;
-           if (dist2 < rmax2) {
-              alpha = vert->color[3];
-              if (dist2 >= rmin2) {
-                 GLint coverage = (GLint) (256.0F - (dist2 - rmin2) * cscale);
-                 /* coverage is in [0,256] */
-                 alpha = (alpha * coverage) >> 8;
-              }
-              alpha = (GLint) (alpha * alphaAtten);
-              if (swrast->_MultiTextureEnabled) {
-                 PB_WRITE_MULTITEX_PIXEL( PB, x, y, z, fog,
-                                          red, green, blue, alpha,
-                                          texcoord );
-              }
-              else {
-                 PB_WRITE_TEX_PIXEL( PB, x,y,z, fog,
-                                     red, green, blue, alpha,
-                                     texcoord[0][0],
-                                     texcoord[0][1],
-                                     texcoord[0][2] );
-              }
-           }
-        }
-      }
-      PB_CHECK_FLUSH(ctx,PB);
-   }
-   else {
-      /* Not texture mapped */
-      GLfloat radius, rmin, rmax, rmin2, rmax2, cscale, alphaAtten;
-      GLint xmin, ymin, xmax, ymax;
-      GLint x, y, z;
-      GLfixed fog;
-      GLint red, green, blue, alpha;
+   /* fragment position */
+   span->array->x[count] = (GLint) vert->attrib[FRAG_ATTRIB_WPOS][0];
+   span->array->y[count] = (GLint) vert->attrib[FRAG_ATTRIB_WPOS][1];
+   span->array->z[count] = (GLint) (vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
 
-      if (vert->pointSize >= ctx->Point.Threshold) {
-        radius = MIN2(vert->pointSize, ctx->Point.MaxSize) * 0.5F;
-        alphaAtten = 1.0F;
-      }
-      else {
-        GLfloat dsize = vert->pointSize / ctx->Point.Threshold;
-        radius = (MAX2(ctx->Point.Threshold, ctx->Point.MinSize) * 0.5F);
-        alphaAtten = dsize * dsize;
-      }
-      rmin = radius - 0.7071F;  /* 0.7071 = sqrt(2)/2 */
-      rmax = radius + 0.7071F;
-      rmin2 = MAX2(0.0, rmin * rmin);
-      rmax2 = rmax * rmax;
-      cscale = 256.0F / (rmax2 - rmin2);
-
-      xmin = (GLint) (vert->win[0] - radius);
-      xmax = (GLint) (vert->win[0] + radius);
-      ymin = (GLint) (vert->win[1] - radius);
-      ymax = (GLint) (vert->win[1] + radius);
-      z = (GLint) (vert->win[2]);
-
-      fog = FloatToFixed( vert->fog );
-
-      red   = vert->color[0];
-      green = vert->color[1];
-      blue  = vert->color[2];
-
-      for (y = ymin; y <= ymax; y++) {
-        for (x = xmin; x <= xmax; x++) {
-           const GLfloat dx = x + 0.5F - vert->win[0];
-           const GLfloat dy = y + 0.5F - vert->win[1];
-           const GLfloat dist2 = dx * dx + dy * dy;
-           if (dist2 < rmax2) {
-              alpha = vert->color[3];
-              if (dist2 >= rmin2) {
-                 GLint coverage = (GLint) (256.0F - (dist2 - rmin2) * cscale);
-                 /* coverage is in [0,256] */
-                 alpha = (alpha * coverage) >> 8;
-              }
-              alpha = (GLint) (alpha * alphaAtten);
-              PB_WRITE_RGBA_PIXEL(PB, x, y, z, fog, 
-                                  red, green, blue, alpha);
-           }
-        }
-      }
-      PB_CHECK_FLUSH(ctx,PB);
-   }
+   span->end = count + 1;
+   ASSERT(span->end <= MAX_WIDTH);
 }
 
 
-
-#ifdef DEBUG
-extern void
-_mesa_print_point_function(GLcontext *ctx);  /* silence compiler warning */
+/**
+ * Add specular color to primary color, draw point, restore original
+ * primary color.
+ */
 void
-_mesa_print_point_function(GLcontext *ctx)
+_swrast_add_spec_terms_point(struct gl_context *ctx, const SWvertex *v0)
 {
-   SWcontext *swrast = SWRAST_CONTEXT(ctx);
-
-   printf("Point Func == ");
-   if (swrast->Point == size1_ci_point)
-      printf("size1_ci_point\n");
-   else if (swrast->Point == size1_rgba_point)
-      printf("size1_rgba_point\n");
-   else if (swrast->Point == general_ci_point)
-      printf("general_ci_point\n");
-   else if (swrast->Point == general_rgba_point)
-      printf("general_rgba_point\n");
-   else if (swrast->Point == textured_rgba_point)
-      printf("textured_rgba_point\n");
-   else if (swrast->Point == multitextured_rgba_point)
-      printf("multitextured_rgba_point\n");
-   else if (swrast->Point == antialiased_rgba_point)
-      printf("antialiased_rgba_point\n");
-   else if (swrast->Point == dist_atten_general_ci_point)
-      printf("dist_atten_general_ci_point\n");
-   else if (swrast->Point == dist_atten_general_rgba_point)
-      printf("dist_atten_general_rgba_point\n");
-   else if (swrast->Point == dist_atten_textured_rgba_point)
-      printf("dist_atten_textured_rgba_point\n");
-   else if (swrast->Point == dist_atten_antialiased_rgba_point)
-      printf("dist_atten_antialiased_rgba_point\n");
-   else if (!swrast->Point)
-      printf("NULL\n");
-   else
-      printf("Driver func %p\n", swrast->Point);
+   SWvertex *ncv0 = (SWvertex *) v0; /* cast away const */
+   GLfloat rSum, gSum, bSum;
+   GLchan cSave[4];
+
+   /* save */
+   COPY_CHAN4(cSave, ncv0->color);
+   /* sum */
+   rSum = CHAN_TO_FLOAT(ncv0->color[0]) + ncv0->attrib[FRAG_ATTRIB_COL1][0];
+   gSum = CHAN_TO_FLOAT(ncv0->color[1]) + ncv0->attrib[FRAG_ATTRIB_COL1][1];
+   bSum = CHAN_TO_FLOAT(ncv0->color[2]) + ncv0->attrib[FRAG_ATTRIB_COL1][2];
+   UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[0], rSum);
+   UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[1], gSum);
+   UNCLAMPED_FLOAT_TO_CHAN(ncv0->color[2], bSum);
+   /* draw */
+   SWRAST_CONTEXT(ctx)->SpecPoint(ctx, ncv0);
+   /* restore */
+   COPY_CHAN4(ncv0->color, cSave);
 }
-#endif
 
 
-/*
- * Examine the current context to determine which point drawing function
- * should be used.
+/**
+ * Examine current state to determine which point drawing function to use.
  */
-void 
-_swrast_choose_point( GLcontext *ctx )
+void
+_swrast_choose_point(struct gl_context *ctx)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
-   GLboolean rgbmode = ctx->Visual.RGBAflag;
+   const GLfloat size = CLAMP(ctx->Point.Size,
+                              ctx->Point.MinSize,
+                              ctx->Point.MaxSize);
 
-   if (ctx->RenderMode==GL_RENDER) {
-      if (!ctx->Point._Attenuated) {
-         if (ctx->Point.SmoothFlag && rgbmode) {
-            swrast->Point = antialiased_rgba_point;
-         }
-         else if (ctx->Texture._ReallyEnabled) {
-            if (swrast->_MultiTextureEnabled ||
-                ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR ||
-               ctx->Fog.ColorSumEnabled) {
-              swrast->Point = multitextured_rgba_point;
-            }
-            else {
-               swrast->Point = textured_rgba_point;
-            }
-         }
-         else if (ctx->Point._Size == 1.0) {
-            /* size=1, any raster ops */
-            if (rgbmode)
-               swrast->Point = size1_rgba_point;
-            else
-               swrast->Point = size1_ci_point;
-         }
-         else {
-           /* every other kind of point rendering */
-            if (rgbmode)
-               swrast->Point = general_rgba_point;
-            else
-               swrast->Point = general_ci_point;
-         }
-      } 
-      else if (ctx->Point.SmoothFlag && rgbmode) {
-         swrast->Point = dist_atten_antialiased_rgba_point;
+   if (ctx->RenderMode == GL_RENDER) {
+      if (ctx->Point.PointSprite) {
+         swrast->Point = sprite_point;
+      }
+      else if (ctx->Point.SmoothFlag) {
+         swrast->Point = smooth_point;
+      }
+      else if (size > 1.0 ||
+               ctx->Point._Attenuated ||
+               ctx->VertexProgram.PointSizeEnabled) {
+         swrast->Point = large_point;
       }
-      else if (ctx->Texture._ReallyEnabled) {
-         swrast->Point = dist_atten_textured_rgba_point;
-      } 
       else {
-         /* every other kind of point rendering */
-         if (rgbmode)
-            swrast->Point = dist_atten_general_rgba_point;
-         else
-            swrast->Point = dist_atten_general_ci_point;
-     }
+         swrast->Point = pixel_point;
+      }
    }
-   else if (ctx->RenderMode==GL_FEEDBACK) {
-      swrast->Point = gl_feedback_point;
+   else if (ctx->RenderMode == GL_FEEDBACK) {
+      swrast->Point = _swrast_feedback_point;
    }
    else {
       /* GL_SELECT mode */
-      swrast->Point = gl_select_point;
+      swrast->Point = _swrast_select_point;
    }
-
-   /*_mesa_print_points_function(ctx);*/
 }
-