Merge branch 'origin' into glsl-compiler-1
[mesa.git] / src / mesa / swrast / s_aaline.c
index 34a026e1e7b3ecb30a160204b2f518b2df16175b..c81095163b0c0f6ec1b07ddf7458bb47f05ec35c 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: s_aaline.c,v 1.10 2001/05/17 09:32:17 keithw Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
+ * Version:  6.5.3
  *
- * 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"),
 
 
 #include "glheader.h"
+#include "imports.h"
+#include "macros.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"
-#include "mmath.h"
 
 
 #define SUB_PIXEL 4
@@ -68,13 +67,16 @@ struct LineInfo
    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_TEXVAR */
+   GLfloat sPlane[FRAG_ATTRIB_MAX][4];
+   GLfloat tPlane[FRAG_ATTRIB_MAX][4];
+   GLfloat uPlane[FRAG_ATTRIB_MAX][4];
+   GLfloat vPlane[FRAG_ATTRIB_MAX][4];
+   GLfloat lambda[FRAG_ATTRIB_MAX];
+   GLfloat texWidth[FRAG_ATTRIB_MAX];
+   GLfloat texHeight[FRAG_ATTRIB_MAX];
+
+   SWspan span;
 };
 
 
@@ -177,12 +179,16 @@ solve_plane_recip(GLfloat x, GLfloat y, const GLfloat plane[4])
 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 (GLchan) CHAN_MAXF;
-   return (GLchan) (GLint) z;
+   else if (z > CHAN_MAX)
+      return CHAN_MAX;
+   return (GLchan) IROUND_POS(z);
+#endif
 }
 
 
@@ -204,7 +210,7 @@ compute_lambda(const GLfloat sPlane[4], const GLfloat tPlane[4],
    if (rho2 == 0.0F)
       return 0.0;
    else
-      return log(rho2) * 1.442695 * 0.5;       /* 1.442695 = 1/log(2) */
+      return (GLfloat) (LOGF(rho2) * 1.442695 * 0.5);/* 1.442695 = 1/log(2) */
 }
 
 
@@ -248,8 +254,8 @@ make_sample_table(GLint xSamples, GLint ySamples, GLfloat samples[][2])
          else {
             j = i++;
          }
-         samples[j][0] = x * dx + 0.5 * dx;
-         samples[j][1] = y * dy + 0.5 * dy;
+         samples[j][0] = x * dx + 0.5F * dx;
+         samples[j][1] = y * dy + 0.5F * dy;
       }
    }
 }
@@ -325,9 +331,23 @@ compute_coveragef(const struct LineInfo *info,
 }
 
 
+/**
+ * Compute coverage value for color index mode.
+ * XXX this may not be quite correct.
+ * \return coverage in [0,15].
+ */
+static GLfloat
+compute_coveragei(const struct LineInfo *info,
+                  GLint winx, GLint winy)
+{
+   return compute_coveragef(info, winx, winy) * 15.0F;
+}
+
+
 
-typedef void (*plot_func)(GLcontext *ctx, const struct LineInfo *line,
-                          struct pixel_buffer *pb, int ix, int iy);
+typedef void (*plot_func)(GLcontext *ctx, struct LineInfo *line,
+                          int ix, int iy);
+                         
 
 
 /*
@@ -337,7 +357,6 @@ static void
 segment(GLcontext *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;
@@ -376,24 +395,24 @@ segment(GLcontext *ctx,
          xLeft = x0 - line->halfWidth;
          xRight = x1 + line->halfWidth;
          if (line->dy >= 0.0) {
-            yBot = y0 - 3.0 * line->halfWidth;
+            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;
+            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;
          }
       }
 
@@ -407,7 +426,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;
@@ -422,24 +441,24 @@ segment(GLcontext *ctx,
          yBot = y0 - line->halfWidth;
          yTop = y1 + line->halfWidth;
          if (line->dx >= 0.0) {
-            xLeft = x0 - 3.0 * line->halfWidth;
+            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;
+            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;
          }
       }
 
@@ -453,7 +472,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;
@@ -480,14 +499,15 @@ segment(GLcontext *ctx,
 #define DO_Z
 #define DO_FOG
 #define DO_RGBA
-#define DO_TEX
+#define DO_TEXVAR
 #include "s_aalinetemp.h"
 
 
-#define NAME(x)  aa_multitex_rgba_##x
+#define NAME(x)  aa_multitex_spec_##x
 #define DO_Z
+#define DO_FOG
 #define DO_RGBA
-#define DO_MULTITEX
+#define DO_TEXVAR
 #define DO_SPEC
 #include "s_aalinetemp.h"
 
@@ -502,14 +522,15 @@ _swrast_choose_aa_line_function(GLcontext *ctx)
 
    if (ctx->Visual.rgbMode) {
       /* RGBA */
-      if (ctx->Texture._ReallyEnabled) {
-         if (ctx->Texture._ReallyEnabled > TEXTURE0_ANY || 
-            ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR || 
-            ctx->Fog.ColorSumEnabled)
-            /* Multitextured! */
-            swrast->Line = aa_multitex_rgba_line;
+      if (ctx->Texture._EnabledCoordUnits != 0
+          || ctx->FragmentProgram._Current) {
+
+         if (ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR || 
+             ctx->Fog.ColorSumEnabled)
+            swrast->Line = aa_multitex_spec_line;
          else
             swrast->Line = aa_tex_rgba_line;
+
       }
       else {
          swrast->Line = aa_rgba_line;