added Window-isms previously in gl.h
[mesa.git] / src / mesa / main / points.c
index 6690b2a10252da731f039c868a0062a17f4723c5..1a6e9a9c30f69476c4814174db9fd614dfc7e51b 100644 (file)
@@ -1,10 +1,10 @@
-/* $Id: points.c,v 1.2 1999/09/18 20:41:23 keithw Exp $ */
+/* $Id: points.c,v 1.9 2000/05/10 22:36:05 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.1
+ * Version:  3.3
  * 
- * Copyright (C) 1999  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2000  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"),
  */
 
 
-
-
-
 #ifdef PC_HEADER
 #include "all.h"
 #else
+#include "glheader.h"
 #include "context.h"
 #include "feedback.h"
 #include "macros.h"
+#include "mmath.h"
 #include "pb.h"
+#include "points.h"
 #include "span.h"
 #include "texstate.h"
 #include "types.h"
 #include "vb.h"
-#include "mmath.h"
-#ifdef XFree86Server
-#include "GL/xf86glx.h"
-#endif
 #endif
 
 
 
-void gl_PointSize( GLcontext *ctx, GLfloat size )
+void
+_mesa_PointSize( GLfloat size )
 {
-   if (size<=0.0) {
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPointSize");
+
+   if (size <= 0.0) {
       gl_error( ctx, GL_INVALID_VALUE, "glPointSize" );
       return;
    }
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPointSize");
 
-   if (ctx->Point.Size != size) {
-      ctx->Point.Size = size;
+   if (ctx->Point.UserSize != size) {
+      ctx->Point.UserSize = size;
+      ctx->Point.Size = CLAMP(size, ctx->Const.MinPointSize, ctx->Const.MaxPointSize);
       ctx->TriangleCaps &= ~DD_POINT_SIZE;
-      if (size != 1.0) ctx->TriangleCaps |= DD_POINT_SIZE;
+      if (size != 1.0)
+         ctx->TriangleCaps |= DD_POINT_SIZE;
       ctx->NewState |= NEW_RASTER_OPS;
    }
 }
 
 
 
-void gl_PointParameterfvEXT( GLcontext *ctx, GLenum pname,
-                                    const GLfloat *params)
+void
+_mesa_PointParameterfEXT( GLenum pname, GLfloat param)
 {
+   _mesa_PointParameterfvEXT(pname, &param);
+}
+
+
+void
+_mesa_PointParameterfvEXT( GLenum pname, const GLfloat *params)
+{
+   GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPointParameterfvEXT");
-   if(pname==GL_DISTANCE_ATTENUATION_EXT) {
-      GLboolean tmp = ctx->Point.Attenuated;
-      COPY_3V(ctx->Point.Params,params);
-      ctx->Point.Attenuated = (params[0] != 1.0 ||
-                              params[1] != 0.0 ||
-                              params[2] != 0.0);
-
-      if (tmp != ctx->Point.Attenuated) {
-        ctx->Enabled ^= ENABLE_POINT_ATTEN;
-        ctx->TriangleCaps ^= DD_POINT_ATTEN;
-        ctx->NewState |= NEW_RASTER_OPS;
-      }
-   } else {
-        if (*params<0.0 ) {
+
+   switch (pname) {
+      case GL_DISTANCE_ATTENUATION_EXT:
+         {
+            const GLboolean tmp = ctx->Point.Attenuated;
+            COPY_3V(ctx->Point.Params, params);
+            ctx->Point.Attenuated = (params[0] != 1.0 ||
+                                     params[1] != 0.0 ||
+                                     params[2] != 0.0);
+
+            if (tmp != ctx->Point.Attenuated) {
+               ctx->Enabled ^= ENABLE_POINT_ATTEN;
+               ctx->TriangleCaps ^= DD_POINT_ATTEN;
+               ctx->NewState |= NEW_RASTER_OPS;
+            }
+         }
+         break;
+      case GL_POINT_SIZE_MIN_EXT:
+         if (*params < 0.0F) {
             gl_error( ctx, GL_INVALID_VALUE, "glPointParameterfvEXT" );
             return;
-        }
-        switch (pname) {
-            case GL_POINT_SIZE_MIN_EXT:
-                ctx->Point.MinSize=*params;
-                break;
-            case GL_POINT_SIZE_MAX_EXT:
-                ctx->Point.MaxSize=*params;
-                break;
-            case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
-                ctx->Point.Threshold=*params;
-                break;
-            default:
-                gl_error( ctx, GL_INVALID_ENUM, "glPointParameterfvEXT" );
-                return;
-        }
+         }
+         ctx->Point.MinSize = *params;
+         break;
+      case GL_POINT_SIZE_MAX_EXT:
+         if (*params < 0.0F) {
+            gl_error( ctx, GL_INVALID_VALUE, "glPointParameterfvEXT" );
+            return;
+         }
+         ctx->Point.MaxSize = *params;
+         break;
+      case GL_POINT_FADE_THRESHOLD_SIZE_EXT:
+         if (*params < 0.0F) {
+            gl_error( ctx, GL_INVALID_VALUE, "glPointParameterfvEXT" );
+            return;
+         }
+         ctx->Point.Threshold = *params;
+         break;
+      default:
+         gl_error( ctx, GL_INVALID_ENUM, "glPointParameterfvEXT" );
+         return;
    }
+
    ctx->NewState |= NEW_RASTER_OPS;
 }
 
@@ -128,20 +148,21 @@ void gl_PointParameterfvEXT( GLcontext *ctx, GLenum pname,
 /*
  * CI points with size == 1.0
  */
-void size1_ci_points( GLcontext *ctx, GLuint first, GLuint last )
+static void
+size1_ci_points( GLcontext *ctx, GLuint first, GLuint last )
 {
    struct vertex_buffer *VB = ctx->VB;
    struct pixel_buffer *PB = ctx->PB;
    GLfloat *win;
    GLint *pbx = PB->x, *pby = PB->y;
    GLdepth *pbz = PB->z;
-   GLuint *pbi = PB->i;
+   GLuint *pbi = PB->index;
    GLuint pbcount = PB->count;
    GLuint i;
 
    win = &VB->Win.data[first][0];
-   for (i=first;i<=last;i++) {
-      if (VB->ClipMask[i]==0) {
+   for (i = first; i <= last; i++) {
+      if (VB->ClipMask[i] == 0) {
          pbx[pbcount] = (GLint)  win[0];
          pby[pbcount] = (GLint)  win[1];
          pbz[pbcount] = (GLint) (win[2] + ctx->PointZoffset);
@@ -159,14 +180,15 @@ void size1_ci_points( GLcontext *ctx, GLuint first, GLuint last )
 /*
  * RGBA points with size == 1.0
  */
-static void size1_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
+static void
+size1_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
 {
    struct vertex_buffer *VB = ctx->VB;
    struct pixel_buffer *PB = ctx->PB;
    GLuint i;
 
-   for (i=first;i<=last;i++) {
-      if (VB->ClipMask[i]==0) {
+   for (i = first; i <= last; i++) {
+      if (VB->ClipMask[i] == 0) {
          GLint x, y, z;
          GLint red, green, blue, alpha;
 
@@ -182,7 +204,7 @@ static void size1_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
          PB_WRITE_RGBA_PIXEL( PB, x, y, z, red, green, blue, alpha );
       }
    }
-   PB_CHECK_FLUSH(ctx,PB);
+   PB_CHECK_FLUSH(ctx, PB);
 }
 
 
@@ -190,23 +212,23 @@ static void size1_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
 /*
  * General CI points.
  */
-static void general_ci_points( GLcontext *ctx, GLuint first, GLuint last )
+static void
+general_ci_points( GLcontext *ctx, GLuint first, GLuint last )
 {
    struct vertex_buffer *VB = ctx->VB;
    struct pixel_buffer *PB = ctx->PB;
-   GLuint i;
-   GLint isize = (GLint) (CLAMP(ctx->Point.Size,MIN_POINT_SIZE,MAX_POINT_SIZE) + 0.5F);
+   const GLint isize = (GLint) (ctx->Point.Size + 0.5F);
    GLint radius = isize >> 1;
+   GLuint i;
 
-   for (i=first;i<=last;i++) {
-      if (VB->ClipMask[i]==0) {
-         GLint x, y, z;
+   for (i = first; i <= last; i++) {
+      if (VB->ClipMask[i] == 0) {
          GLint x0, x1, y0, y1;
          GLint ix, iy;
 
-         x = (GLint)  VB->Win.data[i][0];
-         y = (GLint)  VB->Win.data[i][1];
-         z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
+         GLint x = (GLint)  VB->Win.data[i][0];
+         GLint y = (GLint)  VB->Win.data[i][1];
+         GLint z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
 
          if (isize & 1) {
             /* odd size */
@@ -223,10 +245,10 @@ static void general_ci_points( GLcontext *ctx, GLuint first, GLuint last )
             y1 = y0 + isize - 1;
          }
 
-         PB_SET_INDEX( ctx, PB, VB->IndexPtr->data[i] );
+         PB_SET_INDEX( PB, VB->IndexPtr->data[i] );
 
-         for (iy=y0;iy<=y1;iy++) {
-            for (ix=x0;ix<=x1;ix++) {
+         for (iy = y0; iy <= y1; iy++) {
+            for (ix = x0; ix <= x1; ix++) {
                PB_WRITE_PIXEL( PB, ix, iy, z );
             }
          }
@@ -239,23 +261,23 @@ static void general_ci_points( GLcontext *ctx, GLuint first, GLuint last )
 /*
  * General RGBA points.
  */
-static void general_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
+static void
+general_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
 {
    struct vertex_buffer *VB = ctx->VB;
    struct pixel_buffer *PB = ctx->PB;
-   GLuint i;
-   GLint isize = (GLint) (CLAMP(ctx->Point.Size,MIN_POINT_SIZE,MAX_POINT_SIZE) + 0.5F);
+   GLint isize = (GLint) (ctx->Point.Size + 0.5F);
    GLint radius = isize >> 1;
+   GLuint i;
 
-   for (i=first;i<=last;i++) {
-      if (VB->ClipMask[i]==0) {
-         GLint x, y, z;
+   for (i = first; i <= last; i++) {
+      if (VB->ClipMask[i] == 0) {
          GLint x0, x1, y0, y1;
          GLint ix, iy;
 
-         x = (GLint)  VB->Win.data[i][0];
-         y = (GLint)  VB->Win.data[i][1];
-         z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
+         GLint x = (GLint)  VB->Win.data[i][0];
+         GLint y = (GLint)  VB->Win.data[i][1];
+         GLint z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
 
          if (isize & 1) {
             /* odd size */
@@ -272,14 +294,14 @@ static void general_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
             y1 = y0 + isize - 1;
          }
 
-         PB_SET_COLOR( ctx, PB,
+         PB_SET_COLOR( PB,
                        VB->ColorPtr->data[i][0],
                        VB->ColorPtr->data[i][1],
                        VB->ColorPtr->data[i][2],
                        VB->ColorPtr->data[i][3] );
 
-         for (iy=y0;iy<=y1;iy++) {
-            for (ix=x0;ix<=x1;ix++) {
+         for (iy = y0; iy <= y1; iy++) {
+            for (ix = x0; ix <= x1; ix++) {
                PB_WRITE_PIXEL( PB, ix, iy, z );
             }
          }
@@ -294,28 +316,26 @@ static void general_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
 /*
  * Textured RGBA points.
  */
-static void textured_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
+static void
+textured_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
 {
    struct vertex_buffer *VB = ctx->VB;
    struct pixel_buffer *PB = ctx->PB;
    GLuint i;
 
-   for (i=first;i<=last;i++) {
-      if (VB->ClipMask[i]==0) {
-         GLint x, y, z;
+   for (i = first; i <= last; i++) {
+      if (VB->ClipMask[i] == 0) {
          GLint x0, x1, y0, y1;
-         GLint ix, iy;
-         GLint isize, radius;
+         GLint ix, iy, radius;
          GLint red, green, blue, alpha;
          GLfloat s, t, u;
 
-         x = (GLint)  VB->Win.data[i][0];
-         y = (GLint)  VB->Win.data[i][1];
-         z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
+         GLint x = (GLint)  VB->Win.data[i][0];
+         GLint y = (GLint)  VB->Win.data[i][1];
+         GLint z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
+         GLint isize = (GLint) (ctx->Point.Size + 0.5F);
 
-         isize = (GLint)
-                   (CLAMP(ctx->Point.Size,MIN_POINT_SIZE,MAX_POINT_SIZE) + 0.5F);
-         if (isize<1) {
+         if (isize < 1) {
             isize = 1;
          }
          radius = isize >> 1;
@@ -361,21 +381,22 @@ static void textured_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
            t = 0.0;
            u = 0.0;
            break;
+         default:
+            /* should never get here */
+            s = t = u = 0.0;
+            gl_problem(ctx, "unexpected texcoord size in textured_rgba_points()");
         }
 
-
-
-
 /*    don't think this is needed
          PB_SET_COLOR( red, green, blue, alpha );
 */
 
-         for (iy=y0;iy<=y1;iy++) {
-            for (ix=x0;ix<=x1;ix++) {
+         for (iy = y0; iy <= y1; iy++) {
+            for (ix = x0; ix <= x1; ix++) {
                PB_WRITE_TEX_PIXEL( PB, ix, iy, z, red, green, blue, alpha, s, t, u );
             }
          }
-         PB_CHECK_FLUSH(ctx,PB);
+         PB_CHECK_FLUSH(ctx, PB);
       }
    }
 }
@@ -384,29 +405,28 @@ static void textured_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
 /*
  * Multitextured RGBA points.
  */
-static void multitextured_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
+static void
+multitextured_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
 {
    struct vertex_buffer *VB = ctx->VB;
    struct pixel_buffer *PB = ctx->PB;
    GLuint i;
 
-   for (i=first;i<=last;i++) {
-      if (VB->ClipMask[i]==0) {
-         GLint x, y, z;
+   for (i = first; i <= last; i++) {
+      if (VB->ClipMask[i] == 0) {
          GLint x0, x1, y0, y1;
          GLint ix, iy;
-         GLint isize, radius;
+         GLint radius;
          GLint red, green, blue, alpha;
          GLfloat s, t, u;
          GLfloat s1, t1, u1;
 
-         x = (GLint)  VB->Win.data[i][0];
-         y = (GLint)  VB->Win.data[i][1];
-         z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
+         GLint x = (GLint)  VB->Win.data[i][0];
+         GLint y = (GLint)  VB->Win.data[i][1];
+         GLint z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
+         GLint isize = (GLint) (ctx->Point.Size + 0.5F);
 
-         isize = (GLint)
-                   (CLAMP(ctx->Point.Size,MIN_POINT_SIZE,MAX_POINT_SIZE) + 0.5F);
-         if (isize<1) {
+         if (isize < 1) {
             isize = 1;
          }
          radius = isize >> 1;
@@ -452,6 +472,10 @@ static void multitextured_rgba_points( GLcontext *ctx, GLuint first, GLuint last
            t = 0.0;
            u = 0.0;
            break;
+         default:
+            /* should never get here */
+            s = t = u = 0.0;
+            gl_problem(ctx, "unexpected texcoord size in multitextured_rgba_points()");
         }
 
         switch (VB->TexCoordPtr[1]->size) {
@@ -475,14 +499,19 @@ static void multitextured_rgba_points( GLcontext *ctx, GLuint first, GLuint last
            t1 = 0.0;
            u1 = 0.0;
            break;
+         default:
+            /* should never get here */
+            s1 = t1 = u1 = 0.0;
+            gl_problem(ctx, "unexpected texcoord size in multitextured_rgba_points()");
         }
 
          for (iy=y0;iy<=y1;iy++) {
             for (ix=x0;ix<=x1;ix++) {
-               PB_WRITE_MULTITEX_PIXEL( PB, ix, iy, z, red, green, blue, alpha, s, t, u, s1, t1, u1 );
+               PB_WRITE_MULTITEX_PIXEL( PB, ix, iy, z, red, green, blue, alpha,
+                                        s, t, u, s1, t1, u1 );
             }
          }
-         PB_CHECK_FLUSH(ctx,PB);
+         PB_CHECK_FLUSH(ctx, PB);
       }
    }
 }
@@ -493,35 +522,32 @@ static void multitextured_rgba_points( GLcontext *ctx, GLuint first, GLuint last
 /*
  * Antialiased points with or without texture mapping.
  */
-static void antialiased_rgba_points( GLcontext *ctx,
-                                     GLuint first, GLuint last )
+static void
+antialiased_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
 {
    struct vertex_buffer *VB = ctx->VB;
    struct pixel_buffer *PB = ctx->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 = rmin * rmin;
+   const GLfloat rmax2 = rmax * rmax;
+   const GLfloat cscale = 256.0F / (rmax2 - rmin2);
    GLuint i;
-   GLfloat radius, rmin, rmax, rmin2, rmax2, cscale;
-
-   radius = CLAMP( ctx->Point.Size, MIN_POINT_SIZE, MAX_POINT_SIZE ) * 0.5F;
-   rmin = radius - 0.7071F;  /* 0.7071 = sqrt(2)/2 */
-   rmax = radius + 0.7071F;
-   rmin2 = rmin*rmin;
-   rmax2 = rmax*rmax;
-   cscale = 256.0F / (rmax2-rmin2);
 
    if (ctx->Texture.ReallyEnabled) {
-      for (i=first;i<=last;i++) {
-         if (VB->ClipMask[i]==0) {
-            GLint xmin, ymin, xmax, ymax;
-            GLint x, y, z;
+      for (i = first; i <= last; i++) {
+         if (VB->ClipMask[i] == 0) {
+            GLint x, y;
             GLint red, green, blue, alpha;
             GLfloat s, t, u;
             GLfloat s1, t1, u1;
 
-            xmin = (GLint) (VB->Win.data[i][0] - radius);
-            xmax = (GLint) (VB->Win.data[i][0] + radius);
-            ymin = (GLint) (VB->Win.data[i][1] - radius);
-            ymax = (GLint) (VB->Win.data[i][1] + radius);
-            z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
+            GLint xmin = (GLint) (VB->Win.data[i][0] - radius);
+            GLint xmax = (GLint) (VB->Win.data[i][0] + radius);
+            GLint ymin = (GLint) (VB->Win.data[i][1] - radius);
+            GLint ymax = (GLint) (VB->Win.data[i][1] + radius);
+            GLint z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
 
             red   = VB->ColorPtr->data[i][0];
             green = VB->ColorPtr->data[i][1];
@@ -551,6 +577,10 @@ static void antialiased_rgba_points( GLcontext *ctx,
               t = 0.0;
               u = 0.0;
               break;
+            default:
+               /* should never get here */
+               s = t = u = 0.0;
+               gl_problem(ctx, "unexpected texcoord size in antialiased_rgba_points()");
            }
 
            if (ctx->Texture.ReallyEnabled >= TEXTURE1_1D) {
@@ -580,6 +610,10 @@ static void antialiased_rgba_points( GLcontext *ctx,
                  t1 = 0.0;
                  u1 = 0.0;
                  break;
+               default:
+                  /* should never get here */
+                  s1 = t1 = u1 = 0.0;
+                  gl_problem(ctx, "unexpected texcoord size in antialiased_rgba_points()");
               }
            }
 
@@ -656,7 +690,8 @@ static void antialiased_rgba_points( GLcontext *ctx,
 /*
  * Null rasterizer for measuring transformation speed.
  */
-static void null_points( GLcontext *ctx, GLuint first, GLuint last )
+static void
+null_points( GLcontext *ctx, GLuint first, GLuint last )
 {
    (void) ctx;
    (void) first;
@@ -670,35 +705,36 @@ static void null_points( GLcontext *ctx, GLuint first, GLuint last )
 /* Calculates the distance attenuation formula of a vector of points in
  * eye space coordinates 
  */
-static void dist3(GLfloat *out, GLuint first, GLuint last,
-                 const GLcontext *ctx, const GLvector4f *v)
+static void
+dist3(GLfloat *out, GLuint first, GLuint last,
+      const GLcontext *ctx, const GLvector4f *v)
 {
    GLuint stride = v->stride;
-   GLfloat *p = VEC_ELT(v, GLfloat, first);
+   const GLfloat *p = VEC_ELT(v, GLfloat, first);
    GLuint i;
 
-   for (i = first ; i <= last ; i++, STRIDE_F(p, stride) )
-   {
+   for (i = first ; i <= last ; i++, STRIDE_F(p, stride) ) {
       GLfloat dist = GL_SQRT(p[0]*p[0]+p[1]*p[1]+p[2]*p[2]);
-      out[i] = 1/(ctx->Point.Params[0]+ 
-                 dist * (ctx->Point.Params[1] +
-                         dist * ctx->Point.Params[2]));
+      out[i] = 1.0F / (ctx->Point.Params[0] +
+                       dist * (ctx->Point.Params[1] +
+                               dist * ctx->Point.Params[2]));
    }
 }
 
-static void dist2(GLfloat *out, GLuint first, GLuint last,
-                 const GLcontext *ctx, const GLvector4f *v)
+
+static void
+dist2(GLfloat *out, GLuint first, GLuint last,
+      const GLcontext *ctx, const GLvector4f *v)
 {
    GLuint stride = v->stride;
-   GLfloat *p = VEC_ELT(v, GLfloat, first);
+   const GLfloat *p = VEC_ELT(v, GLfloat, first);
    GLuint i;
 
-   for (i = first ; i <= last ; i++, STRIDE_F(p, stride) )
-   {
+   for (i = first ; i <= last ; i++, STRIDE_F(p, stride) ) {
       GLfloat dist = GL_SQRT(p[0]*p[0]+p[1]*p[1]);
-      out[i] = 1/(ctx->Point.Params[0]+ 
-                 dist * (ctx->Point.Params[1] +
-                         dist * ctx->Point.Params[2]));
+      out[i] = 1.0F / (ctx->Point.Params[0] +
+                       dist * (ctx->Point.Params[1] +
+                               dist * ctx->Point.Params[2]));
    }
 }
 
@@ -716,8 +752,9 @@ static dist_func eye_dist_tab[5] = {
 };
 
 
-static void clip_dist(GLfloat *out, GLuint first, GLuint last,
-                     const GLcontext *ctx, GLvector4f *clip)
+static void
+clip_dist(GLfloat *out, GLuint first, GLuint last,
+          const GLcontext *ctx, GLvector4f *clip)
 {
    /* this is never called */
    gl_problem(NULL, "clip_dist() called - dead code!\n");
@@ -748,15 +785,14 @@ static void clip_dist(GLfloat *out, GLuint first, GLuint last,
 /*
  * Distance Attenuated General CI points.
  */
-static void dist_atten_general_ci_points( GLcontext *ctx, GLuint first, 
-                                       GLuint last )
+static void
+dist_atten_general_ci_points( GLcontext *ctx, GLuint first, GLuint last )
 {
    struct vertex_buffer *VB = ctx->VB;
    struct pixel_buffer *PB = ctx->PB;
-   GLuint i;
-   GLfloat psize,dsize;
    GLfloat dist[VB_SIZE];
-   psize=CLAMP(ctx->Point.Size,MIN_POINT_SIZE,MAX_POINT_SIZE);
+   const GLfloat psize = ctx->Point.Size;
+   GLuint i;
 
    if (ctx->NeedEyeCoords)
       (eye_dist_tab[VB->EyePtr->size])( dist, first, last, ctx, VB->EyePtr );
@@ -765,20 +801,19 @@ static void dist_atten_general_ci_points( GLcontext *ctx, GLuint first,
 
    for (i=first;i<=last;i++) {
       if (VB->ClipMask[i]==0) {
-         GLint x, y, z;
          GLint x0, x1, y0, y1;
          GLint ix, iy;
          GLint isize, radius;
+         GLint x = (GLint)  VB->Win.data[i][0];
+         GLint y = (GLint)  VB->Win.data[i][1];
+         GLint z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
+         GLfloat dsize = psize * dist[i];
 
-         x = (GLint)  VB->Win.data[i][0];
-         y = (GLint)  VB->Win.data[i][1];
-         z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
-
-         dsize=psize*dist[i];
-         if(dsize>=ctx->Point.Threshold) {
-            isize=(GLint) (MIN2(dsize,ctx->Point.MaxSize)+0.5F);
-         } else {
-            isize=(GLint) (MAX2(ctx->Point.Threshold,ctx->Point.MinSize)+0.5F);
+         if (dsize >= ctx->Point.Threshold) {
+            isize = (GLint) (MIN2(dsize, ctx->Point.MaxSize) + 0.5F);
+         }
+         else {
+            isize = (GLint) (MAX2(ctx->Point.Threshold, ctx->Point.MinSize) + 0.5F);
          }
          radius = isize >> 1;
 
@@ -797,7 +832,7 @@ static void dist_atten_general_ci_points( GLcontext *ctx, GLuint first,
             y1 = y0 + isize - 1;
          }
 
-         PB_SET_INDEX( ctx, PB, VB->IndexPtr->data[i] );
+         PB_SET_INDEX( PB, VB->IndexPtr->data[i] );
 
          for (iy=y0;iy<=y1;iy++) {
             for (ix=x0;ix<=x1;ix++) {
@@ -812,16 +847,14 @@ static void dist_atten_general_ci_points( GLcontext *ctx, GLuint first,
 /*
  * Distance Attenuated General RGBA points.
  */
-static void dist_atten_general_rgba_points( GLcontext *ctx, GLuint first, 
-                               GLuint last )
+static void
+dist_atten_general_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
 {
    struct vertex_buffer *VB = ctx->VB;
    struct pixel_buffer *PB = ctx->PB;
-   GLuint i;
-   GLubyte alpha;
-   GLfloat psize,dsize;
    GLfloat dist[VB_SIZE];
-   psize=CLAMP(ctx->Point.Size,MIN_POINT_SIZE,MAX_POINT_SIZE);
+   const GLfloat psize = ctx->Point.Size;
+   GLuint i;
 
    if (ctx->NeedEyeCoords)
       (eye_dist_tab[VB->EyePtr->size])( dist, first, last, ctx, VB->EyePtr );
@@ -830,15 +863,15 @@ static void dist_atten_general_rgba_points( GLcontext *ctx, GLuint first,
 
    for (i=first;i<=last;i++) {
       if (VB->ClipMask[i]==0) {
-         GLint x, y, z;
          GLint x0, x1, y0, y1;
          GLint ix, iy;
          GLint isize, radius;
+         GLint x = (GLint)  VB->Win.data[i][0];
+         GLint y = (GLint)  VB->Win.data[i][1];
+         GLint z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
+         GLfloat dsize=psize*dist[i];
+         GLubyte alpha;
 
-         x = (GLint)  VB->Win.data[i][0];
-         y = (GLint)  VB->Win.data[i][1];
-         z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
-         dsize=psize*dist[i];
          if (dsize >= ctx->Point.Threshold) {
             isize = (GLint) (MIN2(dsize,ctx->Point.MaxSize)+0.5F);
             alpha = VB->ColorPtr->data[i][3];
@@ -865,7 +898,7 @@ static void dist_atten_general_rgba_points( GLcontext *ctx, GLuint first,
             y1 = y0 + isize - 1;
          }
 
-         PB_SET_COLOR( ctx, PB,
+         PB_SET_COLOR( PB,
                        VB->ColorPtr->data[i][0],
                        VB->ColorPtr->data[i][1],
                        VB->ColorPtr->data[i][2],
@@ -884,15 +917,14 @@ static void dist_atten_general_rgba_points( GLcontext *ctx, GLuint first,
 /*
  *  Distance Attenuated Textured RGBA points.
  */
-static void dist_atten_textured_rgba_points( GLcontext *ctx, GLuint first, 
-                                       GLuint last )
+static void
+dist_atten_textured_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
 {
    struct vertex_buffer *VB = ctx->VB;
    struct pixel_buffer *PB = ctx->PB;
-   GLuint i;
-   GLfloat psize,dsize;
    GLfloat dist[VB_SIZE];
-   psize=CLAMP(ctx->Point.Size,MIN_POINT_SIZE,MAX_POINT_SIZE);
+   const GLfloat psize = ctx->Point.Size;
+   GLuint i;
 
    if (ctx->NeedEyeCoords)
       (eye_dist_tab[VB->EyePtr->size])( dist, first, last, ctx, VB->EyePtr );
@@ -901,7 +933,6 @@ static void dist_atten_textured_rgba_points( GLcontext *ctx, GLuint first,
 
    for (i=first;i<=last;i++) {
       if (VB->ClipMask[i]==0) {
-         GLint x, y, z;
          GLint x0, x1, y0, y1;
          GLint ix, iy;
          GLint isize, radius;
@@ -909,21 +940,22 @@ static void dist_atten_textured_rgba_points( GLcontext *ctx, GLuint first,
          GLfloat s, t, u;
          GLfloat s1, t1, u1;
 
-         x = (GLint)  VB->Win.data[i][0];
-         y = (GLint)  VB->Win.data[i][1];
-         z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
+         GLint x = (GLint)  VB->Win.data[i][0];
+         GLint y = (GLint)  VB->Win.data[i][1];
+         GLint z = (GLint) (VB->Win.data[i][2] + ctx->PointZoffset);
 
-         dsize=psize*dist[i];
-         if(dsize>=ctx->Point.Threshold) {
-            isize=(GLint) (MIN2(dsize,ctx->Point.MaxSize)+0.5F);
-            alpha=VB->ColorPtr->data[i][3];
-         } else {
-            isize=(GLint) (MAX2(ctx->Point.Threshold,ctx->Point.MinSize)+0.5F);
-            dsize/=ctx->Point.Threshold;
-            alpha = (GLint) (VB->ColorPtr->data[i][3]* (dsize*dsize));
+         GLfloat dsize = psize*dist[i];
+         if(dsize >= ctx->Point.Threshold) {
+            isize = (GLint) (MIN2(dsize, ctx->Point.MaxSize) + 0.5F);
+            alpha = VB->ColorPtr->data[i][3];
+         }
+         else {
+            isize = (GLint) (MAX2(ctx->Point.Threshold, ctx->Point.MinSize) + 0.5F);
+            dsize /= ctx->Point.Threshold;
+            alpha = (GLint) (VB->ColorPtr->data[i][3] * (dsize * dsize));
          }
 
-         if (isize<1) {
+         if (isize < 1) {
             isize = 1;
          }
          radius = isize >> 1;
@@ -971,6 +1003,10 @@ static void dist_atten_textured_rgba_points( GLcontext *ctx, GLuint first,
            t = 0.0;
            u = 0.0;
            break;
+         default:
+            /* should never get here */
+            s = t = u = 0.0;
+            gl_problem(ctx, "unexpected texcoord size in dist_atten_textured_rgba_points()");
         }
 
         if (ctx->Texture.ReallyEnabled >= TEXTURE1_1D) {
@@ -1000,6 +1036,10 @@ static void dist_atten_textured_rgba_points( GLcontext *ctx, GLuint first,
               t1 = 0.0;
               u1 = 0.0;
               break;
+            default:
+               /* should never get here */
+               s1 = t1 = u1 = 0.0;
+               gl_problem(ctx, "unexpected texcoord size in dist_atten_textured_rgba_points()");
            }
         }
 
@@ -1024,16 +1064,14 @@ static void dist_atten_textured_rgba_points( GLcontext *ctx, GLuint first,
 /*
  * Distance Attenuated Antialiased points with or without texture mapping.
  */
-static void dist_atten_antialiased_rgba_points( GLcontext *ctx,
-                                     GLuint first, GLuint last )
+static void
+dist_atten_antialiased_rgba_points( GLcontext *ctx, GLuint first, GLuint last )
 {
    struct vertex_buffer *VB = ctx->VB;
    struct pixel_buffer *PB = ctx->PB;
-   GLuint i;
-   GLfloat radius, rmin, rmax, rmin2, rmax2, cscale;
-   GLfloat psize,dsize,alphaf;
    GLfloat dist[VB_SIZE];
-   psize=CLAMP(ctx->Point.Size,MIN_POINT_SIZE,MAX_POINT_SIZE);
+   const GLfloat psize = ctx->Point.Size;
+   GLuint i;
 
    if (ctx->NeedEyeCoords)
       (eye_dist_tab[VB->EyePtr->size])( dist, first, last, ctx, VB->EyePtr );
@@ -1043,20 +1081,22 @@ static void dist_atten_antialiased_rgba_points( GLcontext *ctx,
    if (ctx->Texture.ReallyEnabled) {
       for (i=first;i<=last;i++) {
          if (VB->ClipMask[i]==0) {
+            GLfloat radius, rmin, rmax, rmin2, rmax2, cscale, alphaf;
             GLint xmin, ymin, xmax, ymax;
             GLint x, y, z;
             GLint red, green, blue, alpha;
             GLfloat s, t, u;
             GLfloat s1, t1, u1;
+            GLfloat dsize = psize * dist[i];
 
-            dsize=psize*dist[i];
-            if(dsize>=ctx->Point.Threshold) {
-               radius=(MIN2(dsize,ctx->Point.MaxSize)*0.5F);
-               alphaf=1.0;
-            else {
-               radius=(MAX2(ctx->Point.Threshold,ctx->Point.MinSize)*0.5F);
-               dsize/=ctx->Point.Threshold;
-               alphaf=(dsize*dsize);
+            if (dsize >= ctx->Point.Threshold) {
+               radius = MIN2(dsize, ctx->Point.MaxSize) * 0.5F;
+               alphaf = 1.0F;
+            }
+            else {
+               radius = (MAX2(ctx->Point.Threshold, ctx->Point.MinSize) * 0.5F);
+               dsize /= ctx->Point.Threshold;
+               alphaf = (dsize*dsize);
             }
             rmin = radius - 0.7071F;  /* 0.7071 = sqrt(2)/2 */
             rmax = radius + 0.7071F;
@@ -1098,6 +1138,10 @@ static void dist_atten_antialiased_rgba_points( GLcontext *ctx,
               t = 0.0;
               u = 0.0;
               break;
+            default:
+               /* should never get here */
+               s = t = u = 0.0;
+               gl_problem(ctx, "unexpected texcoord size in dist_atten_antialiased_rgba_points()");
            }
 
            if (ctx->Texture.ReallyEnabled >= TEXTURE1_1D) {
@@ -1127,26 +1171,32 @@ static void dist_atten_antialiased_rgba_points( GLcontext *ctx,
                  t1 = 0.0;
                  u1 = 0.0;
                  break;
+               default:
+                  /* should never get here */
+                  s = t = u = 0.0;
+                  gl_problem(ctx, "unexpected texcoord size in dist_atten_antialiased_rgba_points()");
               }
            }
 
-            for (y=ymin;y<=ymax;y++) {
-               for (x=xmin;x<=xmax;x++) {
+            for (y = ymin; y <= ymax; y++) {
+               for (x = xmin; x <= xmax; x++) {
                   GLfloat dx = x/*+0.5F*/ - VB->Win.data[i][0];
                   GLfloat dy = y/*+0.5F*/ - VB->Win.data[i][1];
                   GLfloat dist2 = dx*dx + dy*dy;
-                  if (dist2<rmax2) {
+                  if (dist2 < rmax2) {
                      alpha = VB->ColorPtr->data[i][3];
-                     if (dist2>=rmin2) {
-                        GLint coverage = (GLint) (256.0F-(dist2-rmin2)*cscale);
+                     if (dist2 >= rmin2) {
+                        GLint coverage = (GLint) (256.0F - (dist2 - rmin2) * cscale);
                         /* coverage is in [0,256] */
                         alpha = (alpha * coverage) >> 8;
                      }
                      alpha = (GLint) (alpha * alphaf);
                      if (ctx->Texture.ReallyEnabled >= TEXTURE1_1D) {
-                        PB_WRITE_MULTITEX_PIXEL( PB, x,y,z, red, green, blue, alpha, s, t, u, s1, t1, u1 );
+                        PB_WRITE_MULTITEX_PIXEL( PB, x,y,z, red, green, blue,
+                                                 alpha, s, t, u, s1, t1, u1 );
                      } else {
-                        PB_WRITE_TEX_PIXEL( PB, x,y,z, red, green, blue, alpha, s, t, u );
+                        PB_WRITE_TEX_PIXEL( PB, x,y,z, red, green, blue, alpha,
+                                            s, t, u );
                      }
                   }
                }
@@ -1157,26 +1207,28 @@ static void dist_atten_antialiased_rgba_points( GLcontext *ctx,
    }
    else {
       /* Not texture mapped */
-      for (i=first;i<=last;i++) {
-         if (VB->ClipMask[i]==0) {
+      for (i = first; i <= last; i++) {
+         if (VB->ClipMask[i] == 0) {
+            GLfloat radius, rmin, rmax, rmin2, rmax2, cscale, alphaf;
             GLint xmin, ymin, xmax, ymax;
             GLint x, y, z;
             GLint red, green, blue, alpha;
+            GLfloat dsize = psize * dist[i];
 
-            dsize=psize*dist[i];
-            if(dsize>=ctx->Point.Threshold) {
-               radius=(MIN2(dsize,ctx->Point.MaxSize)*0.5F);
-               alphaf=1.0;
-            else {
-               radius=(MAX2(ctx->Point.Threshold,ctx->Point.MinSize)*0.5F);
-               dsize/=ctx->Point.Threshold;
-               alphaf=(dsize*dsize);
+            if (dsize >= ctx->Point.Threshold) {
+               radius = MIN2(dsize, ctx->Point.MaxSize) * 0.5F;
+               alphaf = 1.0F;
+            }
+            else {
+               radius = (MAX2(ctx->Point.Threshold, ctx->Point.MinSize) * 0.5F);
+               dsize /= ctx->Point.Threshold;
+               alphaf = dsize * dsize;
             }
             rmin = radius - 0.7071F;  /* 0.7071 = sqrt(2)/2 */
             rmax = radius + 0.7071F;
-            rmin2 = rmin*rmin;
-            rmax2 = rmax*rmax;
-            cscale = 256.0F / (rmax2-rmin2);
+            rmin2 = rmin * rmin;
+            rmax2 = rmax * rmax;
+            cscale = 256.0F / (rmax2 - rmin2);
 
             xmin = (GLint) (VB->Win.data[i][0] - radius);
             xmax = (GLint) (VB->Win.data[i][0] + radius);
@@ -1188,21 +1240,20 @@ static void dist_atten_antialiased_rgba_points( GLcontext *ctx,
             green = VB->ColorPtr->data[i][1];
             blue  = VB->ColorPtr->data[i][2];
 
-            for (y=ymin;y<=ymax;y++) {
-               for (x=xmin;x<=xmax;x++) {
+            for (y = ymin; y <= ymax; y++) {
+               for (x = xmin; x <= xmax; x++) {
                   GLfloat dx = x/*+0.5F*/ - VB->Win.data[i][0];
                   GLfloat dy = y/*+0.5F*/ - VB->Win.data[i][1];
-                  GLfloat dist2 = dx*dx + dy*dy;
-                  if (dist2<rmax2) {
+                  GLfloat dist2 = dx * dx + dy * dy;
+                  if (dist2 < rmax2) {
                     alpha = VB->ColorPtr->data[i][3];
-                     if (dist2>=rmin2) {
-                        GLint coverage = (GLint) (256.0F-(dist2-rmin2)*cscale);
+                     if (dist2 >= rmin2) {
+                        GLint coverage = (GLint) (256.0F - (dist2 - rmin2) * cscale);
                         /* coverage is in [0,256] */
                         alpha = (alpha * coverage) >> 8;
                      }
                      alpha = (GLint) (alpha * alphaf);
-                     PB_WRITE_RGBA_PIXEL( PB, x, y, z, red, green, blue, alpha )
-                       ;
+                     PB_WRITE_RGBA_PIXEL(PB, x, y, z, red, green, blue, alpha);
                   }
                }
             }
@@ -1213,6 +1264,43 @@ static void dist_atten_antialiased_rgba_points( GLcontext *ctx,
 }
 
 
+#ifdef DEBUG
+void
+_mesa_print_points_function(GLcontext *ctx)
+{
+   printf("Point Func == ");
+   if (ctx->Driver.PointsFunc == size1_ci_points)
+      printf("size1_ci_points\n");
+   else if (ctx->Driver.PointsFunc == size1_rgba_points)
+      printf("size1_rgba_points\n");
+   else if (ctx->Driver.PointsFunc == general_ci_points)
+      printf("general_ci_points\n");
+   else if (ctx->Driver.PointsFunc == general_rgba_points)
+      printf("general_rgba_points\n");
+   else if (ctx->Driver.PointsFunc == textured_rgba_points)
+      printf("textured_rgba_points\n");
+   else if (ctx->Driver.PointsFunc == multitextured_rgba_points)
+      printf("multitextured_rgba_points\n");
+   else if (ctx->Driver.PointsFunc == antialiased_rgba_points)
+      printf("antialiased_rgba_points\n");
+   else if (ctx->Driver.PointsFunc == null_points)
+      printf("null_points\n");
+   else if (ctx->Driver.PointsFunc == dist_atten_general_ci_points)
+      printf("dist_atten_general_ci_points\n");
+   else if (ctx->Driver.PointsFunc == dist_atten_general_rgba_points)
+      printf("dist_atten_general_rgba_points\n");
+   else if (ctx->Driver.PointsFunc == dist_atten_textured_rgba_points)
+      printf("dist_atten_textured_rgba_points\n");
+   else if (ctx->Driver.PointsFunc == dist_atten_antialiased_rgba_points)
+      printf("dist_atten_antialiased_rgba_points\n");
+   else if (!ctx->Driver.PointsFunc)
+      printf("NULL\n");
+   else
+      printf("Driver func %p\n", ctx->Driver.PointsFunc);
+}
+#endif
+
+
 /*
  * Examine the current context to determine which point drawing function
  * should be used.
@@ -1281,5 +1369,6 @@ void gl_set_point_function( GLcontext *ctx )
       ctx->Driver.PointsFunc = gl_select_points;
    }
 
+   /*_mesa_print_points_function(ctx);*/
 }