Merge remote-tracking branch 'mesa-public/master' into vulkan
[mesa.git] / src / mesa / swrast / s_aaline.c
index ac368aa85b8b73c511162d0a59c9e20f23cc27b2..de5b42b9f6bbc9c6c9e419f52b99d298d511c2ac 100644 (file)
@@ -1,10 +1,7 @@
-/* $Id: s_aaline.c,v 1.4 2001/01/23 23:39:37 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
  *
- * Copyright (C) 1999-2001  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"),
  * 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
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
-#include "glheader.h"
+#include "c99_math.h"
+#include "main/glheader.h"
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/mtypes.h"
+#include "main/teximage.h"
 #include "swrast/s_aaline.h"
-#include "swrast/s_pb.h"
 #include "swrast/s_context.h"
+#include "swrast/s_span.h"
 #include "swrast/swrast.h"
-#include "mtypes.h"
-
 
 
 #define SUB_PIXEL 4
@@ -60,21 +61,16 @@ struct LineInfo
 
    /* DO_Z */
    GLfloat zPlane[4];
-   /* DO_FOG */
-   GLfloat fPlane[4];
-   /* DO_RGBA */
+   /* DO_RGBA - always enabled */
    GLfloat rPlane[4], gPlane[4], bPlane[4], aPlane[4];
-   /* DO_INDEX */
-   GLfloat iPlane[4];
-   /* DO_SPEC */
-   GLfloat srPlane[4], sgPlane[4], sbPlane[4];
-   /* DO_TEX or DO_MULTITEX */
-   GLfloat sPlane[MAX_TEXTURE_UNITS][4];
-   GLfloat tPlane[MAX_TEXTURE_UNITS][4];
-   GLfloat uPlane[MAX_TEXTURE_UNITS][4];
-   GLfloat vPlane[MAX_TEXTURE_UNITS][4];
-   GLfloat lambda[MAX_TEXTURE_UNITS];
-   GLfloat texWidth[MAX_TEXTURE_UNITS], texHeight[MAX_TEXTURE_UNITS];
+   /* DO_ATTRIBS */
+   GLfloat wPlane[4];
+   GLfloat attrPlane[VARYING_SLOT_MAX][4][4];
+   GLfloat lambda[VARYING_SLOT_MAX];
+   GLfloat texWidth[VARYING_SLOT_MAX];
+   GLfloat texHeight[VARYING_SLOT_MAX];
+
+   SWspan span;
 };
 
 
@@ -120,28 +116,36 @@ compute_plane(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1,
    const GLfloat b = pz * py;
    const GLfloat c = px * px + py * py;
    const GLfloat d = -(a * x0 + b * y0 + c * z0);
-   plane[0] = a;
-   plane[1] = b;
-   plane[2] = c;
-   plane[3] = d;
+   if (a == 0.0F && b == 0.0F && c == 0.0F && d == 0.0F) {
+      plane[0] = 0.0F;
+      plane[1] = 0.0F;
+      plane[2] = 1.0F;
+      plane[3] = 0.0F;
+   }
+   else {
+      plane[0] = a;
+      plane[1] = b;
+      plane[2] = c;
+      plane[3] = d;
+   }
 #endif
 }
 
 
-static INLINE void
+static inline void
 constant_plane(GLfloat value, GLfloat plane[4])
 {
-   plane[0] = 0.0;
-   plane[1] = 0.0;
-   plane[2] = -1.0;
+   plane[0] = 0.0F;
+   plane[1] = 0.0F;
+   plane[2] = -1.0F;
    plane[3] = value;
 }
 
 
-static INLINE GLfloat
+static inline GLfloat
 solve_plane(GLfloat x, GLfloat y, const GLfloat plane[4])
 {
-   GLfloat z = (plane[3] + plane[0] * x + plane[1] * y) / -plane[2];
+   const GLfloat z = (plane[3] + plane[0] * x + plane[1] * y) / -plane[2];
    return z;
 }
 
@@ -152,33 +156,40 @@ solve_plane(GLfloat x, GLfloat y, const GLfloat plane[4])
 /*
  * Return 1 / solve_plane().
  */
-static INLINE GLfloat
+static inline GLfloat
 solve_plane_recip(GLfloat x, GLfloat y, const GLfloat plane[4])
 {
-   GLfloat z = -plane[2] / (plane[3] + plane[0] * x + plane[1] * y);
-   return z;
+   const GLfloat denom = plane[3] + plane[0] * x + plane[1] * y;
+   if (denom == 0.0F)
+      return 0.0F;
+   else
+      return -plane[2] / denom;
 }
 
 
 /*
  * Solve plane and return clamped GLchan value.
  */
-static INLINE GLchan
+static inline GLchan
 solve_plane_chan(GLfloat x, GLfloat y, const GLfloat plane[4])
 {
-   GLfloat z = (plane[3] + plane[0] * x + plane[1] * y) / -plane[2] + 0.5F;
-   if (z < 0.0F)
+   const GLfloat z = (plane[3] + plane[0] * x + plane[1] * y) / -plane[2];
+#if CHAN_TYPE == GL_FLOAT
+   return CLAMP(z, 0.0F, CHAN_MAXF);
+#else
+   if (z < 0)
       return 0;
-   else if (z > CHAN_MAXF)
-      return CHAN_MAXF;
-   return (GLchan) (GLint) z;
+   else if (z > CHAN_MAX)
+      return CHAN_MAX;
+   return (GLchan) IROUND_POS(z);
+#endif
 }
 
 
 /*
  * Compute mipmap level of detail.
  */
-static INLINE GLfloat
+static inline GLfloat
 compute_lambda(const GLfloat sPlane[4], const GLfloat tPlane[4],
                GLfloat invQ, GLfloat width, GLfloat height)
 {
@@ -190,7 +201,10 @@ compute_lambda(const GLfloat sPlane[4], const GLfloat tPlane[4],
    GLfloat r2 = dvdx * dvdx + dvdy * dvdy;
    GLfloat rho2 = r1 + r2;
    /* return log base 2 of rho */
-   return log(rho2) * 1.442695 * 0.5;       /* 1.442695 = 1/log(2) */
+   if (rho2 == 0.0F)
+      return 0.0;
+   else
+      return logf(rho2) * 1.442695f * 0.5f;/* 1.442695 = 1/log(2) */
 }
 
 
@@ -234,8 +248,8 @@ make_sample_table(GLint xSamples, GLint ySamples, GLfloat samples[][2])
          else {
             j = i++;
          }
-         samples[j][0] = x * dx;
-         samples[j][1] = y * dy;
+         samples[j][0] = x * dx + 0.5F * dx;
+         samples[j][1] = y * dy + 0.5F * dy;
       }
    }
 }
@@ -311,19 +325,18 @@ compute_coveragef(const struct LineInfo *info,
 }
 
 
-
-typedef void (*plot_func)(GLcontext *ctx, const struct LineInfo *line,
-                          struct pixel_buffer *pb, int ix, int iy);
+typedef void (*plot_func)(struct gl_context *ctx, struct LineInfo *line,
+                          int ix, int iy);
+                         
 
 
 /*
  * Draw an AA line segment (called many times per line when stippling)
  */
 static void
-segment(GLcontext *ctx,
+segment(struct gl_context *ctx,
         struct LineInfo *line,
         plot_func plot,
-        struct pixel_buffer *pb,
         GLfloat t0, GLfloat t1)
 {
    const GLfloat absDx = (line->dx < 0.0F) ? -line->dx : line->dx;
@@ -361,25 +374,25 @@ segment(GLcontext *ctx,
       if (x0 < x1) {
          xLeft = x0 - line->halfWidth;
          xRight = x1 + line->halfWidth;
-         if (line->dy >= 0.0) {
-            yBot = y0 - 3.0 * line->halfWidth;
+         if (line->dy >= 0.0F) {
+            yBot = y0 - 3.0F * line->halfWidth;
             yTop = y0 + line->halfWidth;
          }
          else {
             yBot = y0 - line->halfWidth;
-            yTop = y0 + 3.0 * line->halfWidth;
+            yTop = y0 + 3.0F * line->halfWidth;
          }
       }
       else {
          xLeft = x1 - line->halfWidth;
          xRight = x0 + line->halfWidth;
-         if (line->dy <= 0.0) {
-            yBot = y1 - 3.0 * line->halfWidth;
+         if (line->dy <= 0.0F) {
+            yBot = y1 - 3.0F * line->halfWidth;
             yTop = y1 + line->halfWidth;
          }
          else {
             yBot = y1 - line->halfWidth;
-            yTop = y1 + 3.0 * line->halfWidth;
+            yTop = y1 + 3.0F * line->halfWidth;
          }
       }
 
@@ -393,7 +406,7 @@ segment(GLcontext *ctx,
          GLint iy;
          /* scan across the line, bottom-to-top */
          for (iy = iyBot; iy < iyTop; iy++) {
-            (*plot)(ctx, line, pb, ix, iy);
+            (*plot)(ctx, line, ix, iy);
          }
          yBot += dydx;
          yTop += dydx;
@@ -407,25 +420,25 @@ segment(GLcontext *ctx,
       if (y0 < y1) {
          yBot = y0 - line->halfWidth;
          yTop = y1 + line->halfWidth;
-         if (line->dx >= 0.0) {
-            xLeft = x0 - 3.0 * line->halfWidth;
+         if (line->dx >= 0.0F) {
+            xLeft = x0 - 3.0F * line->halfWidth;
             xRight = x0 + line->halfWidth;
          }
          else {
             xLeft = x0 - line->halfWidth;
-            xRight = x0 + 3.0 * line->halfWidth;
+            xRight = x0 + 3.0F * line->halfWidth;
          }
       }
       else {
          yBot = y1 - line->halfWidth;
          yTop = y0 + line->halfWidth;
-         if (line->dx <= 0.0) {
-            xLeft = x1 - 3.0 * line->halfWidth;
+         if (line->dx <= 0.0F) {
+            xLeft = x1 - 3.0F * line->halfWidth;
             xRight = x1 + line->halfWidth;
          }
          else {
             xLeft = x1 - line->halfWidth;
-            xRight = x1 + 3.0 * line->halfWidth;
+            xRight = x1 + 3.0F * line->halfWidth;
          }
       }
 
@@ -439,7 +452,7 @@ segment(GLcontext *ctx,
          GLint ix;
          /* scan across the line, left-to-right */
          for (ix = ixLeft; ix < ixRight; ix++) {
-            (*plot)(ctx, line, pb, ix, iy);
+            (*plot)(ctx, line, ix, iy);
          }
          xLeft += dxdy;
          xRight += dxdy;
@@ -448,62 +461,34 @@ segment(GLcontext *ctx,
 }
 
 
-#define NAME(x) aa_ci_##x
-#define DO_Z
-#define DO_FOG
-#define DO_INDEX
-#include "s_aalinetemp.h"
-
-
 #define NAME(x) aa_rgba_##x
 #define DO_Z
-#define DO_FOG
-#define DO_RGBA
-#include "s_aalinetemp.h"
-
-
-#define NAME(x)  aa_tex_rgba_##x
-#define DO_Z
-#define DO_FOG
-#define DO_RGBA
-#define DO_TEX
 #include "s_aalinetemp.h"
 
 
-#define NAME(x)  aa_multitex_rgba_##x
+#define NAME(x)  aa_general_rgba_##x
 #define DO_Z
-#define DO_RGBA
-#define DO_MULTITEX
-#define DO_SPEC
+#define DO_ATTRIBS
 #include "s_aalinetemp.h"
 
 
 
 void
-_swrast_choose_aa_line_function(GLcontext *ctx)
+_swrast_choose_aa_line_function(struct gl_context *ctx)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
 
-   ASSERT(ctx->Line.SmoothFlag);
-
-   if (ctx->Visual.rgbMode) {
-      /* RGBA */
-      if (ctx->Texture._ReallyEnabled) {
-         if (swrast->_MultiTextureEnabled
-             || ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR
-             || ctx->Fog.ColorSumEnabled)
-            /* Multitextured! */
-            swrast->Line = aa_multitex_rgba_line;
-         else
-            swrast->Line = aa_tex_rgba_line;
-      }
-      else {
-         swrast->Line = aa_rgba_line;
-      }
+   assert(ctx->Line.SmoothFlag);
+
+   if (ctx->Texture._EnabledCoordUnits != 0
+       || _swrast_use_fragment_program(ctx)
+       || (ctx->Light.Enabled &&
+           ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)
+       || ctx->Fog.ColorSumEnabled
+       || swrast->_FogEnabled) {
+      swrast->Line = aa_general_rgba_line;
    }
    else {
-      /* Color Index */
-      swrast->Line = aa_ci_line;
+      swrast->Line = aa_rgba_line;
    }
 }
-