Merge commit 'origin/gallium-0.1'
[mesa.git] / src / mesa / swrast / s_points.c
index ce73365a4ea1bd41a0fe9a84caefec0f4175b9d1..61ff4d0b84cde4395ddf641125f8bdd124f21ef8 100644 (file)
  */
 
 
-#include "glheader.h"
-#include "colormac.h"
-#include "context.h"
-#include "macros.h"
-#include "texstate.h"
+#include "main/glheader.h"
+#include "main/colormac.h"
+#include "main/context.h"
+#include "main/macros.h"
+#include "main/texstate.h"
 #include "s_context.h"
 #include "s_feedback.h"
 #include "s_points.h"
    } while(0)
 
 
+
+/**
+ * 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 INLINE GLfloat
+get_size(const GLcontext *ctx, const SWvertex *vert, GLboolean smoothed)
+{
+   GLfloat size;
+
+   if (ctx->Point._Attenuated || ctx->VertexProgram.PointSizeEnabled) {
+      /* use vertex's point size */
+      size = vert->pointSize;
+   }
+   else {
+      /* 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);
+
+   return size;
+}
+
+
 /**
  * Draw a point sprite
  */
@@ -68,23 +100,14 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
       span.z = (GLuint) (vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
    span.zStep = 0;
 
-   /* compute size */
-   if (ctx->Point._Attenuated || ctx->VertexProgram.PointSizeEnabled) {
-      /* use vertex's point size */
-      /* first, clamp attenuated size to the user-specifed range */
-      size = CLAMP(vert->pointSize, ctx->Point.MinSize, ctx->Point.MaxSize);
-   }
-   else {
-      /* use constant point size */
-      size = ctx->Point.Size;
-   }
-   /* clamp to non-AA implementation limits */
-   size = CLAMP(size, ctx->Const.MinPointSize, ctx->Const.MaxPointSize);
+   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]);
@@ -106,13 +129,13 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
       s = 0.0;
       dsdx = 1.0 / size;
       if (ctx->Point.SpriteOrigin == GL_LOWER_LEFT) {
-         t0 = 0.0;
          dtdy = 1.0 / size;
+         t0 = 0.5 * dtdy;
       }
       else {
          /* GL_UPPER_LEFT */
-         t0 = 1.0;
          dtdy = -1.0 / size;
+         t0 = 1.0 + 0.5 * dtdy;
       }
 
       ATTRIB_LOOP_BEGIN
@@ -237,21 +260,10 @@ smooth_point(GLcontext *ctx, const SWvertex *vert)
       span.z = (GLuint) (vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
    span.zStep = 0;
 
-   /* compute size */
-   if (ctx->Point._Attenuated || ctx->VertexProgram.PointSizeEnabled) {
-      /* use vertex's point size */
-      /* first, clamp attenuated size to the user-specifed range */
-      size = CLAMP(vert->pointSize, ctx->Point.MinSize, ctx->Point.MaxSize);
-   }
-   else {
-      /* use constant point size */
-      size = ctx->Point.Size;
-   }
-   /* clamp to AA implementation limits */
-   size = CLAMP(size, ctx->Const.MinPointSizeAA, ctx->Const.MaxPointSizeAA);
+   size = get_size(ctx, vert, GL_TRUE);
 
    /* alpha attenuation / fade factor */
-   if (ctx->Multisample.Enabled) {
+   if (ctx->Multisample._Enabled) {
       if (vert->pointSize >= ctx->Point.Threshold) {
          alphaAtten = 1.0F;
       }
@@ -270,6 +282,8 @@ smooth_point(GLcontext *ctx, const SWvertex *vert)
    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]);
@@ -371,22 +385,12 @@ large_point(GLcontext *ctx, const SWvertex *vert)
       span.z = (GLuint) (vert->attrib[FRAG_ATTRIB_WPOS][2] + 0.5F);
    span.zStep = 0;
 
-   /* compute size */
-   if (ctx->Point._Attenuated || ctx->VertexProgram.PointSizeEnabled) {
-      /* use vertex's point size */
-      /* first, clamp attenuated size to the user-specifed range */
-      size = CLAMP(vert->pointSize, ctx->Point.MinSize, ctx->Point.MaxSize);
-   }
-   else {
-      /* use constant point size */
-      size = ctx->Point.Size;
-   }
-   /* clamp to non-AA implementation limits */
-   size = CLAMP(size, ctx->Const.MinPointSize, ctx->Const.MaxPointSize);
+   size = get_size(ctx, vert, GL_FALSE);
 
    /* span init */
    INIT_SPAN(span, GL_POINT);
    span.arrayMask = SPAN_XY;
+   span.facing = swrast->PointLineFacing;
 
    if (ciMode) {
       span.interpMask = SPAN_Z | SPAN_INDEX;
@@ -493,16 +497,21 @@ pixel_point(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 (ciMode)
-         _swrast_write_index_span(ctx, span);
-      else
-         _swrast_write_rgba_span(ctx, span);
-      span->end = 0;
+       (swrast->_RasterMask & (BLEND_BIT | LOGIC_OP_BIT | MASKING_BIT)) ||
+       span->facing != swrast->PointLineFacing) {
+      if (span->end > 0) {
+         if (ciMode)
+            _swrast_write_index_span(ctx, span);
+         else
+            _swrast_write_rgba_span(ctx, span);
+         span->end = 0;
+      }
    }
 
    count = span->end;
 
+   span->facing = swrast->PointLineFacing;
+
    /* fragment attributes */
    if (ciMode) {
       span->array->index[count] = (GLuint) vert->attrib[FRAG_ATTRIB_CI][0];