r300: Further reduced the radeon_span.c diff.
[mesa.git] / src / mesa / swrast / s_pointtemp.h
index d0e2b54a03999b09249f9b2d99d6dd44668411be..dddc2f7f40c630b83fdbaf67ccab15f0cc5174cc 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: s_pointtemp.h,v 1.23 2003/03/25 02:23:47 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  6.5.3
  *
- * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
+ * 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"),
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+/*
+ * Regarding GL_NV_point_sprite:
+ *
+ * Portions of this software may use or implement intellectual
+ * property owned and licensed by NVIDIA Corporation. NVIDIA disclaims
+ * any and all warranties with respect to such intellectual property,
+ * including any use thereof or modifications thereto.
+ */
+
 
 /*
  * Point rendering template code.
  *
  *   RGBA = do rgba instead of color index
  *   SMOOTH = do antialiasing
- *   TEXTURE = do texture coords
+ *   ATTRIBS = general attributes (texcoords, etc)
  *   SPECULAR = do separate specular color
  *   LARGE = do points with diameter > 1 pixel
  *   ATTENUATE = compute point size attenuation
- *   SPRITE = GL_NV_point_sprite
+ *   SPRITE = GL_ARB_point_sprite / GL_NV_point_sprite
  *
  * Notes: LARGE and ATTENUATE are exclusive of each other.
- *        TEXTURE requires RGBA
- *        SPECULAR requires TEXTURE
+ *        ATTRIBS requires RGBA
  */
 
 
  */
 
 
-
 static void
 NAME ( GLcontext *ctx, const SWvertex *vert )
 {
 #if FLAGS & (ATTENUATE | LARGE | SMOOTH | SPRITE)
    GLfloat size;
 #endif
-#if FLAGS & ATTENUATE
+#if FLAGS & RGBA
+#if (FLAGS & ATTENUATE) && (FLAGS & SMOOTH)
    GLfloat alphaAtten;
 #endif
-#if FLAGS & RGBA
    const GLchan red   = vert->color[0];
    const GLchan green = vert->color[1];
    const GLchan blue  = vert->color[2];
@@ -79,14 +84,13 @@ NAME ( GLcontext *ctx, const SWvertex *vert )
    const GLchan specBlue  = vert->specular[2];
 #endif
 #if FLAGS & INDEX
-   const GLuint colorIndex = vert->index;
+   const GLuint colorIndex = (GLuint) vert->index; /* XXX round? */
 #endif
-#if FLAGS & TEXTURE
-   GLfloat texcoord[MAX_TEXTURE_COORD_UNITS][4];
-   GLuint u;
+#if FLAGS & ATTRIBS
+   GLfloat attrib[FRAG_ATTRIB_MAX][4]; /* texture & varying */
 #endif
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
-   struct sw_span *span = &(swrast->PointSpan);
+   SWspan *span = &(swrast->PointSpan);
 
    /* Cull primitives with malformed coordinates.
     */
@@ -101,8 +105,9 @@ NAME ( GLcontext *ctx, const SWvertex *vert )
     */
    span->interpMask = SPAN_FOG;
    span->arrayMask = SPAN_XY | SPAN_Z;
-   span->fog = vert->fog;
-   span->fogStep = 0.0;
+   span->attrStart[FRAG_ATTRIB_FOGC][0] = vert->attrib[FRAG_ATTRIB_FOGC][0];
+   span->attrStepX[FRAG_ATTRIB_FOGC][0] = 0.0;
+   span->attrStepY[FRAG_ATTRIB_FOGC][0] = 0.0;
 #if FLAGS & RGBA
    span->arrayMask |= SPAN_RGBA;
 #endif
@@ -112,48 +117,79 @@ NAME ( GLcontext *ctx, const SWvertex *vert )
 #if FLAGS & INDEX
    span->arrayMask |= SPAN_INDEX;
 #endif
-#if FLAGS & TEXTURE
-   span->arrayMask |= SPAN_TEXTURE;
-   for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-      if (ctx->Texture.Unit[u]._ReallyEnabled) {
-         const GLfloat q = vert->texcoord[u][3];
+#if FLAGS & ATTRIBS
+   span->arrayMask |= (SPAN_TEXTURE | SPAN_LAMBDA);
+   if (ctx->FragmentProgram._Active) {
+      /* Don't divide texture s,t,r by q (use TXP to do that) */
+      ATTRIB_LOOP_BEGIN
+         COPY_4V(attrib[attr], vert->attrib[attr]);
+      ATTRIB_LOOP_END
+   }
+   else {
+      /* Divide texture s,t,r by q here */
+      ATTRIB_LOOP_BEGIN
+         const GLfloat q = vert->attrib[attr][3];
          const GLfloat invQ = (q == 0.0F || q == 1.0F) ? 1.0F : (1.0F / q);
-         texcoord[u][0] = vert->texcoord[u][0] * invQ;
-         texcoord[u][1] = vert->texcoord[u][1] * invQ;
-         texcoord[u][2] = vert->texcoord[u][2] * invQ;
-         texcoord[u][3] = q;
-      }
+         attrib[attr][0] = vert->attrib[attr][0] * invQ;
+         attrib[attr][1] = vert->attrib[attr][1] * invQ;
+         attrib[attr][2] = vert->attrib[attr][2] * invQ;
+         attrib[attr][3] = q;
+      ATTRIB_LOOP_END
    }
+   /* 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;
 #endif
 #if FLAGS & SMOOTH
    span->arrayMask |= SPAN_COVERAGE;
 #endif
 #if FLAGS & SPRITE
-   span->arrayMask |= SPAN_TEXTURE;
+   span->arrayMask |= (SPAN_TEXTURE | SPAN_LAMBDA);
 #endif
 
+   /* Compute point size if not known to be one */
 #if FLAGS & ATTENUATE
-   if (vert->pointSize >= ctx->Point.Threshold) {
-      size = MIN2(vert->pointSize, ctx->Point.MaxSize);
-      alphaAtten = 1.0F;
+   /* first, clamp attenuated size to the user-specifed range */
+   size = CLAMP(vert->pointSize, ctx->Point.MinSize, ctx->Point.MaxSize);
+#if (FLAGS & RGBA) && (FLAGS & SMOOTH)
+   /* only if multisampling, compute the 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;
+      }
    }
    else {
-      GLfloat dsize = vert->pointSize / ctx->Point.Threshold;
-      size = MAX2(ctx->Point.Threshold, ctx->Point.MinSize);
-      alphaAtten = dsize * dsize;
+      alphaAtten = 1.0;
    }
+#endif
 #elif FLAGS & (LARGE | SMOOTH | SPRITE)
-   size = ctx->Point._Size;
+   /* constant, non-attenuated size */
+   size = ctx->Point._Size; /* this is already clamped */
 #endif
 
+
 #if FLAGS & (ATTENUATE | LARGE | SMOOTH | SPRITE)
-   /*
-    * Multi-pixel points
-    */
+   /***
+    *** Multi-pixel points
+    ***/
+
+   /* do final clamping now */
+   if (ctx->Point.SmoothFlag) {
+      size = CLAMP(size, ctx->Const.MinPointSizeAA, ctx->Const.MaxPointSizeAA);
+   }
+   else {
+      size = CLAMP(size, ctx->Const.MinPointSize, ctx->Const.MaxPointSize);
+   }
+
    {{
       GLint x, y;
       const GLfloat radius = 0.5F * size;
-      const GLint z = (GLint) (vert->win[2] + 0.5F);
+      const GLuint z = (GLuint) (vert->win[2] + 0.5F);
       GLuint count;
 #if FLAGS & SMOOTH
       const GLfloat rmin = radius - 0.7071F;  /* 0.7071 = sqrt(2)/2 */
@@ -191,17 +227,14 @@ 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
+         if (span->end > 0) {
+#if FLAGS & RGBA
             _swrast_write_rgba_span(ctx, span);
-#elif FLAGS & RGBA
-         _swrast_write_rgba_span(ctx, span);
 #else
-         _swrast_write_index_span(ctx, span);
+            _swrast_write_index_span(ctx, span);
 #endif
-         span->end = 0;
+            span->end = 0;
+         }
       }
 
       /*
@@ -210,8 +243,18 @@ NAME ( GLcontext *ctx, const SWvertex *vert )
       count = span->end;
       (void) radius;
       for (y = ymin; y <= ymax; y++) {
+         /* check if we need to flush */
+         if (count + (xmax-xmin+1) >= MAX_WIDTH) {
+            span->end = count;
+#if FLAGS & RGBA
+            _swrast_write_rgba_span(ctx, span);
+#else
+            _swrast_write_index_span(ctx, span);
+#endif
+            count = span->end = 0;
+         }
          for (x = xmin; x <= xmax; x++) {
-#if FLAGS & (SPRITE | TEXTURE)
+#if FLAGS & SPRITE
             GLuint u;
 #endif
 
@@ -229,12 +272,14 @@ NAME ( GLcontext *ctx, const SWvertex *vert )
 #if FLAGS & INDEX
             span->array->index[count] = colorIndex;
 #endif
-#if FLAGS & TEXTURE
-            for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-               if (ctx->Texture.Unit[u]._ReallyEnabled) {
-                  COPY_4V(span->array->texcoords[u][count], texcoord[u]);
+#if FLAGS & ATTRIBS
+            ATTRIB_LOOP_BEGIN
+               COPY_4V(span->array->attribs[attr][count], attrib[attr]);
+               if (attr < FRAG_ATTRIB_VAR0 && attr >= FRAG_ATTRIB_TEX0) {
+                  const GLuint u = attr - FRAG_ATTRIB_TEX0;
+                  span->array->lambda[u][count] = 0.0;
                }
-            }
+            ATTRIB_LOOP_END
 #endif
 
 #if FLAGS & SMOOTH
@@ -279,22 +324,30 @@ NAME ( GLcontext *ctx, const SWvertex *vert )
 
 #if FLAGS & SPRITE
             for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
+               GLuint attr = FRAG_ATTRIB_TEX0 + u;
                if (ctx->Texture.Unit[u]._ReallyEnabled) {
                   if (ctx->Point.CoordReplace[u]) {
                      GLfloat s = 0.5F + (x + 0.5F - vert->win[0]) / size;
-                     GLfloat t = 0.5F - (y + 0.5F - vert->win[1]) / size;
-                     span->array->texcoords[u][count][0] = s;
-                     span->array->texcoords[u][count][1] = t;
-                     span->array->texcoords[u][count][3] = 1.0F;
+                     GLfloat t, r;
+                     if (ctx->Point.SpriteOrigin == GL_LOWER_LEFT)
+                        t = 0.5F + (y + 0.5F - vert->win[1]) / size;
+                     else /* GL_UPPER_LEFT */
+                        t = 0.5F - (y + 0.5F - vert->win[1]) / size;
                      if (ctx->Point.SpriteRMode == GL_ZERO)
-                        span->array->texcoords[u][count][2] = 0.0F;
+                        r = 0.0F;
                      else if (ctx->Point.SpriteRMode == GL_S)
-                        span->array->texcoords[u][count][2] = vert->texcoord[u][0];
+                        r = vert->attrib[attr][0];
                      else /* GL_R */
-                        span->array->texcoords[u][count][2] = vert->texcoord[u][2];
+                        r = vert->attrib[attr][2];
+                     span->array->attribs[attr][count][0] = s;
+                     span->array->attribs[attr][count][1] = t;
+                     span->array->attribs[attr][count][2] = r;
+                     span->array->attribs[attr][count][3] = 1.0F;
+                     span->array->lambda[u][count] = 0.0; /* XXX fix? */
                   }
                   else {
-                     COPY_4V(span->array->texcoords[u][count], vert->texcoord[u]);
+                     COPY_4V(span->array->attribs[attr][count],
+                             vert->attrib[attr]);
                   }
                }
             }
@@ -311,21 +364,16 @@ NAME ( GLcontext *ctx, const SWvertex *vert )
 
 #else /* LARGE | ATTENUATE | SMOOTH | SPRITE */
 
-   /*
-    * Single-pixel points
-    */
+   /***
+    *** Single-pixel points
+    ***/
    {{
       GLuint count;
 
       /* 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);
@@ -349,12 +397,10 @@ NAME ( GLcontext *ctx, const SWvertex *vert )
 #if FLAGS & INDEX
       span->array->index[count] = colorIndex;
 #endif
-#if FLAGS & TEXTURE
-      for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-         if (ctx->Texture.Unit[u]._ReallyEnabled) {
-            COPY_4V(span->array->texcoords[u][count], texcoord[u]);
-         }
-      }
+#if FLAGS & ATTRIBS
+      ATTRIB_LOOP_BEGIN
+         COPY_4V(span->array->attribs[attr][count], attribs[attr]);
+      ATTRIB_LOOP_END
 #endif
 
       span->array->x[count] = (GLint) vert->win[0];