Dead code elimination and fix bufmgr_fake_wait_idle.
[mesa.git] / src / mesa / swrast / s_pointtemp.h
index 26b7da78ad34838886aa607765de6c57f5aa7758..1956eeba50b8ba8d178ab06e4913c0a3abd81b69 100644 (file)
@@ -1,21 +1,19 @@
-/* $Id: s_pointtemp.h,v 1.2 2001/01/04 15:31:38 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
- * 
- * Copyright (C) 1999-2000  Brian Paul   All Rights Reserved.
- * 
+ * Version:  6.5.3
+ *
+ * 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
  * 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.
  *   SPECULAR = do separate specular color
  *   LARGE = do points with diameter > 1 pixel
  *   ATTENUATE = compute point size attenuation
- *   SPRITE = GL_MESA_sprite_point
+ *   SPRITE = GL_ARB_point_sprite / GL_NV_point_sprite
  *
  * Notes: LARGE and ATTENUATE are exclusive of each other.
  *        TEXTURE requires RGBA
- *        SPECULAR requires TEXTURE
  */
 
 
@@ -53,7 +59,7 @@
  * else if d > rmax2 then
  *    fragment has 0% coverage
  * else
- *    fragement has % coverage = (d - rmin2) / (rmax2 - rmin2)
+ *    fragment has % coverage = (d - rmin2) / (rmax2 - rmin2)
  */
 
 
 static void
 NAME ( GLcontext *ctx, const SWvertex *vert )
 {
+#if FLAGS & (ATTENUATE | LARGE | SMOOTH | SPRITE)
+   GLfloat size;
+#endif
+#if FLAGS & RGBA
+#if (FLAGS & ATTENUATE) && (FLAGS & SMOOTH)
+   GLfloat alphaAtten;
+#endif
+   const GLchan red   = vert->color[0];
+   const GLchan green = vert->color[1];
+   const GLchan blue  = vert->color[2];
+   const GLchan alpha = vert->color[3];
+#endif
+#if FLAGS & SPECULAR
+   const GLchan specRed   = vert->specular[0];
+   const GLchan specGreen = vert->specular[1];
+   const GLchan specBlue  = vert->specular[2];
+#endif
+#if FLAGS & INDEX
+   const GLuint colorIndex = (GLuint) vert->index; /* XXX round? */
+#endif
+#if FLAGS & TEXTURE
+   GLfloat attrib[FRAG_ATTRIB_MAX][4]; /* texture & varying */
+   GLuint attr;
+#endif
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
-   struct pixel_buffer *PB = swrast->PB;
+   SWspan *span = &(swrast->PointSpan);
 
-   const GLint z = (GLint) (vert->win[2]);
-   const GLfixed fog = FloatToFixed( vert->fog );
+   /* Cull primitives with malformed coordinates.
+    */
+   {
+      float tmp = vert->win[0] + vert->win[1];
+      if (IS_INF_OR_NAN(tmp))
+        return;
+   }
 
+   /*
+    * Span init
+    */
+   span->interpMask = SPAN_FOG;
+   span->arrayMask = SPAN_XY | SPAN_Z;
+   span->attrStart[FRAG_ATTRIB_FOGC][0] = vert->fog;
+   span->attrStepX[FRAG_ATTRIB_FOGC][0] = 0.0;
+   span->attrStepY[FRAG_ATTRIB_FOGC][0] = 0.0;
 #if FLAGS & RGBA
-   const GLint red   = vert->color[0];
-   const GLint green = vert->color[1];
-   const GLint blue  = vert->color[2];
-   GLint alpha = vert->color[3];
-#if FLAGS & SPECULAR
-   const GLint sRed   = vert->specular[0];
-   const GLint sGreen = vert->specular[1];
-   const GLint sBlue  = vert->specular[2];
+   span->arrayMask |= SPAN_RGBA;
 #endif
-#else
-   GLint index = vert->index;
+#if FLAGS & SPECULAR
+   span->arrayMask |= SPAN_SPEC;
 #endif
-#if FLAGS & (ATTENUATE | LARGE | SMOOTH)
-   GLfloat size;
+#if FLAGS & INDEX
+   span->arrayMask |= SPAN_INDEX;
 #endif
-#if FLAGS & ATTENUATE
-   GLfloat alphaAtten;
-#endif
-
 #if FLAGS & TEXTURE
-   GLfloat texcoord[MAX_TEXTURE_UNITS][4];
-   GLuint u;
-   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];
+   span->arrayMask |= (SPAN_TEXTURE | SPAN_LAMBDA);
+   if (ctx->FragmentProgram._Active) {
+      /* Don't divide texture s,t,r by q (use TXP to do that) */
+      for (attr = swrast->_MinFragmentAttrib; attr < swrast->_MaxFragmentAttrib; attr++) {
+         if (swrast->_FragmentAttribs & (1 << attr)) {
+            COPY_4V(attrib[attr], vert->attrib[attr]);
+         }
+      }
+   }
+   else {
+      /* Divide texture s,t,r by q here */
+      for (attr = swrast->_MinFragmentAttrib; attr < swrast->_MaxFragmentAttrib; attr++) {
+         if (swrast->_FragmentAttribs & (1 << attr)) {
+            const GLfloat q = vert->attrib[attr][3];
+            const GLfloat invQ = (q == 0.0F || q == 1.0F) ? 1.0F : (1.0F / 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;
          }
       }
    }
+   /* 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_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;
    }
-#elif FLAGS & (LARGE | SMOOTH)
-   size = ctx->Point._Size;
+#endif
+#elif FLAGS & (LARGE | SMOOTH | SPRITE)
+   /* constant, non-attenuated size */
+   size = ctx->Point._Size; /* this is already clamped */
 #endif
 
-#if FLAGS & SPRITE
-   {
-      SWcontext *swctx = SWRAST_CONTEXT(ctx);
-      const GLfloat radius = 0.5 * vert->pointSize;  /* XXX threshold, alpha */
-      SWvertex v0, v1, v2, v3;
-      GLuint unit;
-
-      (void) red;
-      (void) green;
-      (void) blue;
-      (void) alpha;
-      (void) fog;
-      (void) z;
-
-      /* lower left corner */
-      v0 = *vert;
-      v0.win[0] -= radius;
-      v0.win[1] -= radius;
-
-      /* lower right corner */
-      v1 = *vert;
-      v1.win[0] += radius;
-      v1.win[1] -= radius;
-
-      /* upper right corner */
-      v2 = *vert;
-      v2.win[0] += radius;
-      v2.win[1] += radius;
-
-      /* upper left corner */
-      v3 = *vert;
-      v3.win[0] -= radius;
-      v3.win[1] += radius;
-
-      for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
-         if (ctx->Texture.Unit[unit]._ReallyEnabled) {
-            v0.texcoord[unit][0] = 0.0;
-            v0.texcoord[unit][1] = 0.0;
-            v1.texcoord[unit][0] = 1.0;
-            v1.texcoord[unit][1] = 0.0;
-            v2.texcoord[unit][0] = 1.0;
-            v2.texcoord[unit][1] = 1.0;
-            v3.texcoord[unit][0] = 0.0;
-            v3.texcoord[unit][1] = 1.0;
-         }
-      }
-
-      /* XXX if radius < threshold, attenuate alpha? */
 
-      /* XXX need to implement clipping!!! */
+#if FLAGS & (ATTENUATE | LARGE | SMOOTH | SPRITE)
+   /***
+    *** Multi-pixel points
+    ***/
 
-      /* render */
-      swctx->Triangle(ctx, &v0, &v1, &v2);
-      swctx->Triangle(ctx, &v0, &v2, &v3);
+   /* 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);
    }
 
-#elif FLAGS & (LARGE | ATTENUATE | SMOOTH)
-
-   {
+   {{
       GLint x, y;
       const GLfloat radius = 0.5F * size;
+      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 */
       const GLfloat rmax = radius + 0.7071F;
-      const GLfloat rmin2 = MAX2(0.0, rmin * rmin);
+      const GLfloat rmin2 = MAX2(0.0F, rmin * rmin);
       const GLfloat rmax2 = rmax * rmax;
-      const GLfloat cscale = 256.0F / (rmax2 - rmin2);
+      const GLfloat cscale = 1.0F / (rmax2 - rmin2);
       const GLint xmin = (GLint) (vert->win[0] - radius);
       const GLint xmax = (GLint) (vert->win[0] + radius);
       const GLint ymin = (GLint) (vert->win[1] - radius);
@@ -200,10 +216,10 @@ NAME ( GLcontext *ctx, const SWvertex *vert )
       iRadius = iSize / 2;
       if (iSize & 1) {
          /* odd size */
-         xmin = vert->win[0] - iRadius;
-         xmax = vert->win[0] + iRadius;
-         ymin = vert->win[1] - iRadius;
-         ymax = vert->win[1] + iRadius;
+         xmin = (GLint) (vert->win[0] - iRadius);
+         xmax = (GLint) (vert->win[0] + iRadius);
+         ymin = (GLint) (vert->win[1] - iRadius);
+         ymax = (GLint) (vert->win[1] + iRadius);
       }
       else {
          /* even size */
@@ -212,104 +228,200 @@ NAME ( GLcontext *ctx, const SWvertex *vert )
          ymin = (GLint) vert->win[1] - iRadius + 1;
          ymax = ymin + iSize - 1;
       }
-#endif
-      (void) radius;
+#endif /*SMOOTH*/
 
-      for (y = ymin; y <= ymax; y++) {
-         for (x = xmin; x <= xmax; x++) {
-#if FLAGS & SMOOTH
-            /* compute coverage */
-            const GLfloat dx = x - vert->win[0];
-            const GLfloat dy = y - vert->win[1];
-            const GLfloat dist2 = dx * dx + dy * dy;
-            if (dist2 < rmax2) {
+      /* 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 (span->end > 0) {
 #if FLAGS & RGBA
-               alpha = vert->color[3];
+            _swrast_write_rgba_span(ctx, span);
+#else
+            _swrast_write_index_span(ctx, span);
 #endif
-               if (dist2 >= rmin2) {
-                  GLint coverage = (GLint) (256.0F - (dist2 - rmin2) * cscale);
+            span->end = 0;
+         }
+      }
+
+      /*
+       * OK, generate fragments
+       */
+      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
-                 /* coverage is in [0,256] */
-                 alpha = (alpha * coverage) >> 8;
+            _swrast_write_rgba_span(ctx, span);
 #else
-                  /* 4 fractional index bits */
-                  index = (index & ~0xf) | (coverage >> 4);  /* XXX verify */
+            _swrast_write_index_span(ctx, span);
 #endif
-              }
-#endif /* SMOOTH */
-
-#if ((FLAGS & (ATTENUATE | RGBA)) == (ATTENUATE | RGBA))
-              alpha = (GLint) (alpha * alphaAtten);
+            count = span->end = 0;
+         }
+         for (x = xmin; x <= xmax; x++) {
+#if FLAGS & SPRITE
+            GLuint u;
 #endif
 
+#if FLAGS & RGBA
+            span->array->rgba[count][RCOMP] = red;
+            span->array->rgba[count][GCOMP] = green;
+            span->array->rgba[count][BCOMP] = blue;
+            span->array->rgba[count][ACOMP] = alpha;
+#endif
 #if FLAGS & SPECULAR
-               PB_WRITE_MULTITEX_SPEC_PIXEL(PB, x, y, z, fog,
-                                            red, green, blue, alpha,
-                                            sRed, sGreen, sBlue,
-                                            texcoord);
-#elif FLAGS & TEXTURE
-              if (swrast->_MultiTextureEnabled) {
-                 PB_WRITE_MULTITEX_PIXEL(PB, x, y, z, fog,
-                                         red, green, blue, alpha,
-                                         texcoord);
-              }
-              else if (ctx->Texture._ReallyEnabled) {
-                 PB_WRITE_TEX_PIXEL(PB, x,y,z, fog,
-                                    red, green, blue, alpha,
-                                    texcoord[0][0],
-                                    texcoord[0][1],
-                                    texcoord[0][2]);
-              }
-               else {
-                  PB_WRITE_RGBA_PIXEL(PB, x, y, z, fog,
-                                      red, green, blue, alpha);
+            span->array->spec[count][RCOMP] = specRed;
+            span->array->spec[count][GCOMP] = specGreen;
+            span->array->spec[count][BCOMP] = specBlue;
+#endif
+#if FLAGS & INDEX
+            span->array->index[count] = colorIndex;
+#endif
+#if FLAGS & TEXTURE
+            for (attr = swrast->_MinFragmentAttrib; attr < swrast->_MaxFragmentAttrib; attr++) {
+               if (swrast->_FragmentAttribs & (1 << attr)) {
+                  COPY_4V(span->array->attribs[attr][count], attrib[attr]);
+                  if (attr < FRAG_ATTRIB_VAR0) {
+                     const GLuint u = attr - FRAG_ATTRIB_TEX0;
+                     span->array->lambda[u][count] = 0.0;
+                  }
                }
-#elif FLAGS & RGBA
-              PB_WRITE_RGBA_PIXEL(PB, x, y, z, fog, red, green, blue, alpha);
-#else /* color index */
-               PB_WRITE_CI_PIXEL(PB, x, y, z, fog, index);
+            }
 #endif
+
 #if FLAGS & SMOOTH
-           }
+            /* compute coverage */
+            {
+               const GLfloat dx = x - vert->win[0] + 0.5F;
+               const GLfloat dy = y - vert->win[1] + 0.5F;
+               const GLfloat dist2 = dx * dx + dy * dy;
+               if (dist2 < rmax2) {
+                  if (dist2 >= rmin2) {
+                     /* compute partial coverage */
+                     span->array->coverage[count] = 1.0F - (dist2 - rmin2) * cscale;
+#if FLAGS & INDEX
+                     /* coverage in [0,15] */
+                     span->array->coverage[count] *= 15.0;
 #endif
-        }
-      }
-      PB_CHECK_FLUSH(ctx,PB);
-   }
+                  }
+                  else {
+                     /* full coverage */
+                     span->array->coverage[count] = 1.0F;
+                  }
+
+                  span->array->x[count] = x;
+                  span->array->y[count] = y;
+                  span->array->z[count] = z;
+
+#if (FLAGS & ATTENUATE) && (FLAGS & RGBA)
+                  span->array->rgba[count][ACOMP] = (GLchan) (alpha * alphaAtten);
+#elif FLAGS & RGBA
+                  span->array->rgba[count][ACOMP] = alpha;
+#endif /*ATTENUATE*/
+                  count++;
+               } /*if*/
+            }
 
-#else /* LARGE || ATTENUATE || SMOOTH*/
+#else /*SMOOTH*/
 
-   {
-      /* size == 1 */
-      GLint x = vert->win[0];
-      GLint y = vert->win[1];
-#if ((FLAGS & (SPECULAR | TEXTURE)) == (SPECULAR | TEXTURE))
-      PB_WRITE_MULTITEX_SPEC_PIXEL(PB, x, y, z, fog,
-                                   red, green, blue, alpha,
-                                   sRed, sGreen, sBlue,
-                                   texcoord);
-#elif FLAGS & TEXTURE
-      if (swrast->_MultiTextureEnabled) {
-         PB_WRITE_MULTITEX_PIXEL(PB, x, y, z, fog,
-                                 red, green, blue, alpha, texcoord );
+            /* not smooth (square points) */
+            span->array->x[count] = x;
+            span->array->y[count] = y;
+            span->array->z[count] = z;
+
+#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, 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)
+                        r = 0.0F;
+                     else if (ctx->Point.SpriteRMode == GL_S)
+                        r = vert->attrib[attr][0];
+                     else /* GL_R */
+                        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->attribs[attr][count],
+                             vert->attrib[attr]);
+                  }
+               }
+            }
+#endif /*SPRITE*/
+
+            count++;  /* square point */
+
+#endif /*SMOOTH*/
+
+        } /*for x*/
+      } /*for y*/
+      span->end = count;
+   }}
+
+#else /* LARGE | ATTENUATE | SMOOTH | SPRITE */
+
+   /***
+    *** 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 & RGBA
+         _swrast_write_rgba_span(ctx, span);
+#else
+         _swrast_write_index_span(ctx, span);
+#endif
+         span->end = 0;
       }
-      else {
-         PB_WRITE_TEX_PIXEL(PB, x, y, z, fog,
-                            red, green, blue, alpha,
-                            texcoord[0][0], texcoord[0][1], texcoord[0][2]);
+
+      count = span->end;
+
+#if FLAGS & RGBA
+      span->array->rgba[count][RCOMP] = red;
+      span->array->rgba[count][GCOMP] = green;
+      span->array->rgba[count][BCOMP] = blue;
+      span->array->rgba[count][ACOMP] = alpha;
+#endif
+#if FLAGS & SPECULAR
+      span->array->spec[count][RCOMP] = specRed;
+      span->array->spec[count][GCOMP] = specGreen;
+      span->array->spec[count][BCOMP] = specBlue;
+#endif
+#if FLAGS & INDEX
+      span->array->index[count] = colorIndex;
+#endif
+#if FLAGS & TEXTURE
+      for (attr = swrast->_MinFragmentAttrib; attr < swrast->_MaxFragmentAttrib; attr++) {
+         if (swrast->_FragmentAttribs & (1 << attr)) {
+            COPY_4V(span->array->attribs[attr][count], attribs[attr]);
+         }
       }
-#elif FLAGS & RGBA
-      /* rgba size 1 point */
-      alpha = vert->color[3];
-      PB_WRITE_RGBA_PIXEL(PB, x, y, z, fog, red, green, blue, alpha);
-#else
-      /* color index size 1 point */
-      PB_WRITE_CI_PIXEL(PB, x, y, z, fog, index);
 #endif
-   }
+
+      span->array->x[count] = (GLint) vert->win[0];
+      span->array->y[count] = (GLint) vert->win[1];
+      span->array->z[count] = (GLint) (vert->win[2] + 0.5F);
+      span->end = count + 1;
+   }}
+
 #endif /* LARGE || ATTENUATE || SMOOTH */
 
-   PB_CHECK_FLUSH(ctx, PB);
+   ASSERT(span->end <= MAX_WIDTH);
 }