swrast: Fix fixed-function fragment processing
[mesa.git] / src / mesa / swrast / s_aalinetemp.h
index 3a68e528a73e625a09c11abc9f579f94519c76d3..ba9f8abb9c34a0bf47cdc456e2da01f687950cf4 100644 (file)
@@ -1,9 +1,8 @@
-
 /*
  * Mesa 3-D graphics library
- * Version:  5.1
+ * Version:  7.1
  *
- * Copyright (C) 1999-2003  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"),
 
 /*
  * Function to render each fragment in the AA line.
+ * \param ix  - integer fragment window X coordiante
+ * \param iy  - integer fragment window Y coordiante
  */
 static void
-NAME(plot)(GLcontext *ctx, struct LineInfo *line, int ix, int iy)
+NAME(plot)(struct gl_context *ctx, struct LineInfo *line, int ix, int iy)
 {
+   const SWcontext *swrast = SWRAST_CONTEXT(ctx);
    const GLfloat fx = (GLfloat) ix;
    const GLfloat fy = (GLfloat) iy;
    const GLfloat coverage = compute_coveragef(line, ix, iy);
    const GLuint i = line->span.end;
 
+   (void) swrast;
+
    if (coverage == 0.0)
       return;
 
@@ -53,59 +57,42 @@ NAME(plot)(GLcontext *ctx, struct LineInfo *line, int ix, int iy)
     * solving the plane equations at (ix,iy).
     */
 #ifdef DO_Z
-   line->span.array->z[i] = (GLdepth) IROUND(solve_plane(fx, fy, line->zPlane));
-#endif
-#ifdef DO_FOG
-   line->span.array->fog[i] = solve_plane(fx, fy, line->fPlane);
+   line->span.array->z[i] = (GLuint) solve_plane(fx, fy, line->zPlane);
 #endif
-#ifdef DO_RGBA
    line->span.array->rgba[i][RCOMP] = solve_plane_chan(fx, fy, line->rPlane);
    line->span.array->rgba[i][GCOMP] = solve_plane_chan(fx, fy, line->gPlane);
    line->span.array->rgba[i][BCOMP] = solve_plane_chan(fx, fy, line->bPlane);
    line->span.array->rgba[i][ACOMP] = solve_plane_chan(fx, fy, line->aPlane);
-#endif
-#ifdef DO_INDEX
-   line->span.array->index[i] = (GLint) solve_plane(fx, fy, line->iPlane);
-#endif
-#ifdef DO_SPEC
-   line->span.array->spec[i][RCOMP] = solve_plane_chan(fx, fy, line->srPlane);
-   line->span.array->spec[i][GCOMP] = solve_plane_chan(fx, fy, line->sgPlane);
-   line->span.array->spec[i][BCOMP] = solve_plane_chan(fx, fy, line->sbPlane);
-#endif
-#ifdef DO_TEX
-   {
-      const GLfloat invQ = solve_plane_recip(fx, fy, line->vPlane[0]);
-      line->span.array->texcoords[0][i][0] = solve_plane(fx, fy, line->sPlane[0]) * invQ;
-      line->span.array->texcoords[0][i][1] = solve_plane(fx, fy, line->tPlane[0]) * invQ;
-      line->span.array->texcoords[0][i][2] = solve_plane(fx, fy, line->uPlane[0]) * invQ;
-      line->span.array->lambda[0][i] = compute_lambda(line->sPlane[0], line->tPlane[0], invQ,
-                                          line->texWidth[0], line->texHeight[0]);
-   }
-#elif defined(DO_MULTITEX)
-   {
-      GLuint unit;
-      for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
-         if (ctx->Texture.Unit[unit]._ReallyEnabled) {
-            const GLfloat invQ = solve_plane_recip(fx, fy, line->vPlane[unit]);
-            line->span.array->texcoords[unit][i][0] = solve_plane(fx, fy, line->sPlane[unit]) * invQ;
-            line->span.array->texcoords[unit][i][1] = solve_plane(fx, fy, line->tPlane[unit]) * invQ;
-            line->span.array->texcoords[unit][i][2] = solve_plane(fx, fy, line->uPlane[unit]) * invQ;
-            line->span.array->lambda[unit][i] = compute_lambda(line->sPlane[unit],
-                                               line->tPlane[unit], invQ,
-                                               line->texWidth[unit], line->texHeight[unit]);
+#if defined(DO_ATTRIBS)
+   ATTRIB_LOOP_BEGIN
+      GLfloat (*attribArray)[4] = line->span.array->attribs[attr];
+      if (attr >= FRAG_ATTRIB_TEX0 && attr < FRAG_ATTRIB_VAR0
+          && !_swrast_use_fragment_program(ctx)) {
+         /* texcoord w/ divide by Q */
+         const GLuint unit = attr - FRAG_ATTRIB_TEX0;
+         const GLfloat invQ = solve_plane_recip(fx, fy, line->attrPlane[attr][3]);
+         GLuint c;
+         for (c = 0; c < 3; c++) {
+            attribArray[i][c] = solve_plane(fx, fy, line->attrPlane[attr][c]) * invQ;
          }
+         line->span.array->lambda[unit][i]
+            = compute_lambda(line->attrPlane[attr][0],
+                             line->attrPlane[attr][1], invQ,
+                             line->texWidth[attr], line->texHeight[attr]);
       }
-   }
+      else {
+         /* non-texture attrib */
+         const GLfloat invW = solve_plane_recip(fx, fy, line->wPlane);
+         GLuint c;
+         for (c = 0; c < 4; c++) {
+            attribArray[i][c] = solve_plane(fx, fy, line->attrPlane[attr][c]) * invW;
+         }
+      }
+   ATTRIB_LOOP_END
 #endif
 
    if (line->span.end == MAX_WIDTH) {
-#if defined(DO_TEX) || defined(DO_MULTITEX)
-      _swrast_write_texture_span(ctx, &(line->span));
-#elif defined(DO_RGBA)
       _swrast_write_rgba_span(ctx, &(line->span));
-#else
-      _swrast_write_index_span(ctx, &(line->span));
-#endif
       line->span.end = 0; /* reset counter */
    }
 }
@@ -116,7 +103,7 @@ NAME(plot)(GLcontext *ctx, struct LineInfo *line, int ix, int iy)
  * Line setup
  */
 static void
-NAME(line)(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1)
+NAME(line)(struct gl_context *ctx, const SWvertex *v0, const SWvertex *v1)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
    GLfloat tStart, tEnd;   /* segment start, end along line length */
@@ -125,34 +112,31 @@ NAME(line)(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1)
 
    /* Init the LineInfo struct */
    struct LineInfo line;
-   line.x0 = v0->win[0];
-   line.y0 = v0->win[1];
-   line.x1 = v1->win[0];
-   line.y1 = v1->win[1];
+   line.x0 = v0->attrib[FRAG_ATTRIB_WPOS][0];
+   line.y0 = v0->attrib[FRAG_ATTRIB_WPOS][1];
+   line.x1 = v1->attrib[FRAG_ATTRIB_WPOS][0];
+   line.y1 = v1->attrib[FRAG_ATTRIB_WPOS][1];
    line.dx = line.x1 - line.x0;
    line.dy = line.y1 - line.y0;
    line.len = SQRTF(line.dx * line.dx + line.dy * line.dy);
-   line.halfWidth = 0.5F * ctx->Line.Width;
+   line.halfWidth = 0.5F * CLAMP(ctx->Line.Width,
+                                 ctx->Const.MinLineWidthAA,
+                                 ctx->Const.MaxLineWidthAA);
 
    if (line.len == 0.0 || IS_INF_OR_NAN(line.len))
       return;
 
-   INIT_SPAN(line.span, GL_LINE, 0, 0, SPAN_XY | SPAN_COVERAGE);
-
+   INIT_SPAN(line.span, GL_LINE);
+   line.span.arrayMask = SPAN_XY | SPAN_COVERAGE;
+   line.span.facing = swrast->PointLineFacing;
    line.xAdj = line.dx / line.len * line.halfWidth;
    line.yAdj = line.dy / line.len * line.halfWidth;
 
 #ifdef DO_Z
    line.span.arrayMask |= SPAN_Z;
    compute_plane(line.x0, line.y0, line.x1, line.y1,
-                 v0->win[2], v1->win[2], line.zPlane);
-#endif
-#ifdef DO_FOG
-   line.span.arrayMask |= SPAN_FOG;
-   compute_plane(line.x0, line.y0, line.x1, line.y1,
-                 v0->fog, v1->fog, line.fPlane);
+                 v0->attrib[FRAG_ATTRIB_WPOS][2], v1->attrib[FRAG_ATTRIB_WPOS][2], line.zPlane);
 #endif
-#ifdef DO_RGBA
    line.span.arrayMask |= SPAN_RGBA;
    if (ctx->Light.ShadeModel == GL_SMOOTH) {
       compute_plane(line.x0, line.y0, line.x1, line.y1,
@@ -170,81 +154,36 @@ NAME(line)(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1)
       constant_plane(v1->color[BCOMP], line.bPlane);
       constant_plane(v1->color[ACOMP], line.aPlane);
    }
-#endif
-#ifdef DO_SPEC
-   line.span.arrayMask |= SPAN_SPEC;
-   if (ctx->Light.ShadeModel == GL_SMOOTH) {
-      compute_plane(line.x0, line.y0, line.x1, line.y1,
-                    v0->specular[RCOMP], v1->specular[RCOMP], line.srPlane);
-      compute_plane(line.x0, line.y0, line.x1, line.y1,
-                    v0->specular[GCOMP], v1->specular[GCOMP], line.sgPlane);
-      compute_plane(line.x0, line.y0, line.x1, line.y1,
-                    v0->specular[BCOMP], v1->specular[BCOMP], line.sbPlane);
-   }
-   else {
-      constant_plane(v1->specular[RCOMP], line.srPlane);
-      constant_plane(v1->specular[GCOMP], line.sgPlane);
-      constant_plane(v1->specular[BCOMP], line.sbPlane);
-   }
-#endif
-#ifdef DO_INDEX
-   line.span.arrayMask |= SPAN_INDEX;
-   if (ctx->Light.ShadeModel == GL_SMOOTH) {
-      compute_plane(line.x0, line.y0, line.x1, line.y1,
-                    (GLfloat) v0->index, (GLfloat) v1->index, line.iPlane);
-   }
-   else {
-      constant_plane((GLfloat) v1->index, line.iPlane);
-   }
-#endif
-#ifdef DO_TEX
-   {
-      const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current;
-      const struct gl_texture_image *texImage = obj->Image[0][obj->BaseLevel];
-      const GLfloat invW0 = v0->win[3];
-      const GLfloat invW1 = v1->win[3];
-      const GLfloat s0 = v0->texcoord[0][0] * invW0;
-      const GLfloat s1 = v1->texcoord[0][0] * invW1;
-      const GLfloat t0 = v0->texcoord[0][1] * invW0;
-      const GLfloat t1 = v1->texcoord[0][1] * invW0;
-      const GLfloat r0 = v0->texcoord[0][2] * invW0;
-      const GLfloat r1 = v1->texcoord[0][2] * invW0;
-      const GLfloat q0 = v0->texcoord[0][3] * invW0;
-      const GLfloat q1 = v1->texcoord[0][3] * invW0;
-      line.span.arrayMask |= (SPAN_TEXTURE | SPAN_LAMBDA);
-      compute_plane(line.x0, line.y0, line.x1, line.y1, s0, s1, line.sPlane[0]);
-      compute_plane(line.x0, line.y0, line.x1, line.y1, t0, t1, line.tPlane[0]);
-      compute_plane(line.x0, line.y0, line.x1, line.y1, r0, r1, line.uPlane[0]);
-      compute_plane(line.x0, line.y0, line.x1, line.y1, q0, q1, line.vPlane[0]);
-      line.texWidth[0] = (GLfloat) texImage->Width;
-      line.texHeight[0] = (GLfloat) texImage->Height;
-   }
-#elif defined(DO_MULTITEX)
+#if defined(DO_ATTRIBS)
    {
-      GLuint u;
-      line.span.arrayMask |= (SPAN_TEXTURE | SPAN_LAMBDA);
-      for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-         if (ctx->Texture.Unit[u]._ReallyEnabled) {
+      const GLfloat invW0 = v0->attrib[FRAG_ATTRIB_WPOS][3];
+      const GLfloat invW1 = v1->attrib[FRAG_ATTRIB_WPOS][3];
+      line.span.arrayMask |= SPAN_LAMBDA;
+      compute_plane(line.x0, line.y0, line.x1, line.y1, invW0, invW1, line.wPlane);
+      ATTRIB_LOOP_BEGIN
+         GLuint c;
+         if (swrast->_InterpMode[attr] == GL_FLAT) {
+            for (c = 0; c < 4; c++) {
+               constant_plane(v1->attrib[attr][c], line.attrPlane[attr][c]);
+            }
+         }
+         else {
+            for (c = 0; c < 4; c++) {
+               const GLfloat a0 = v0->attrib[attr][c] * invW0;
+               const GLfloat a1 = v1->attrib[attr][c] * invW1;
+               compute_plane(line.x0, line.y0, line.x1, line.y1, a0, a1,
+                             line.attrPlane[attr][c]);
+            }
+         }
+         line.span.arrayAttribs |= BITFIELD64_BIT(attr);
+         if (attr >= FRAG_ATTRIB_TEX0 && attr < FRAG_ATTRIB_VAR0) {
+            const GLuint u = attr - FRAG_ATTRIB_TEX0;
             const struct gl_texture_object *obj = ctx->Texture.Unit[u]._Current;
             const struct gl_texture_image *texImage = obj->Image[0][obj->BaseLevel];
-            const GLfloat invW0 = v0->win[3];
-            const GLfloat invW1 = v1->win[3];
-            const GLfloat s0 = v0->texcoord[u][0] * invW0;
-            const GLfloat s1 = v1->texcoord[u][0] * invW1;
-            const GLfloat t0 = v0->texcoord[u][1] * invW0;
-            const GLfloat t1 = v1->texcoord[u][1] * invW0;
-            const GLfloat r0 = v0->texcoord[u][2] * invW0;
-            const GLfloat r1 = v1->texcoord[u][2] * invW0;
-            const GLfloat q0 = v0->texcoord[u][3] * invW0;
-            const GLfloat q1 = v1->texcoord[u][3] * invW0;
-            compute_plane(line.x0, line.y0, line.x1, line.y1, s0, s1, line.sPlane[u]);
-            compute_plane(line.x0, line.y0, line.x1, line.y1, t0, t1, line.tPlane[u]);
-            compute_plane(line.x0, line.y0, line.x1, line.y1, r0, r1, line.uPlane[u]);
-            compute_plane(line.x0, line.y0, line.x1, line.y1, q0, q1, line.vPlane[u]);
-            line.texWidth[u]  = (GLfloat) texImage->Width;
-            line.texHeight[u] = (GLfloat) texImage->Height;
+            line.texWidth[attr]  = (GLfloat) texImage->Width;
+            line.texHeight[attr] = (GLfloat) texImage->Height;
          }
-      }
+      ATTRIB_LOOP_END
    }
 #endif
 
@@ -292,23 +231,12 @@ NAME(line)(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1)
       segment(ctx, &line, NAME(plot), 0.0, 1.0);
    }
 
-#if defined(DO_TEX) || defined(DO_MULTITEX)
-   _swrast_write_texture_span(ctx, &(line.span));
-#elif defined(DO_RGBA)
    _swrast_write_rgba_span(ctx, &(line.span));
-#else
-   _swrast_write_index_span(ctx, &(line.span));
-#endif
 }
 
 
 
 
 #undef DO_Z
-#undef DO_FOG
-#undef DO_RGBA
-#undef DO_INDEX
-#undef DO_SPEC
-#undef DO_TEX
-#undef DO_MULTITEX
+#undef DO_ATTRIBS
 #undef NAME