radeon: Fix memory leak in radeonCreateScreen2.
[mesa.git] / src / mesa / swrast / s_aaline.c
index 663d43ec87d8df9cd1507af991eff6afbaa3b481..d36d876974e3301919d97a78c53ce08c4f7a7bde 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: s_aaline.c,v 1.16 2002/08/07 00:45:07 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  4.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"),
  */
 
 
-#include "glheader.h"
+#include "main/glheader.h"
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/mtypes.h"
 #include "swrast/s_aaline.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
@@ -60,23 +59,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];
-
-   struct sw_span span;
+   /* DO_ATTRIBS */
+   GLfloat wPlane[4];
+   GLfloat attrPlane[FRAG_ATTRIB_MAX][4][4];
+   GLfloat lambda[FRAG_ATTRIB_MAX];
+   GLfloat texWidth[FRAG_ATTRIB_MAX];
+   GLfloat texHeight[FRAG_ATTRIB_MAX];
+
+   SWspan span;
 };
 
 
@@ -138,7 +130,7 @@ compute_plane(GLfloat x0, GLfloat y0, GLfloat x1, GLfloat y1,
 }
 
 
-static INLINE void
+static inline void
 constant_plane(GLfloat value, GLfloat plane[4])
 {
    plane[0] = 0.0;
@@ -148,7 +140,7 @@ constant_plane(GLfloat value, GLfloat plane[4])
 }
 
 
-static INLINE GLfloat
+static inline GLfloat
 solve_plane(GLfloat x, GLfloat y, const GLfloat plane[4])
 {
    const GLfloat z = (plane[3] + plane[0] * x + plane[1] * y) / -plane[2];
@@ -162,7 +154,7 @@ 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])
 {
    const GLfloat denom = plane[3] + plane[0] * x + plane[1] * y;
@@ -176,22 +168,26 @@ solve_plane_recip(GLfloat x, GLfloat y, const GLfloat plane[4])
 /*
  * 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 (GLchan) 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)
 {
@@ -206,7 +202,7 @@ compute_lambda(const GLfloat sPlane[4], const GLfloat tPlane[4],
    if (rho2 == 0.0F)
       return 0.0;
    else
-      return (GLfloat) (log(rho2) * 1.442695 * 0.5);/* 1.442695 = 1/log(2) */
+      return (GLfloat) (LOGF(rho2) * 1.442695 * 0.5);/* 1.442695 = 1/log(2) */
 }
 
 
@@ -327,8 +323,7 @@ compute_coveragef(const struct LineInfo *info,
 }
 
 
-
-typedef void (*plot_func)(GLcontext *ctx, struct LineInfo *line,
+typedef void (*plot_func)(struct gl_context *ctx, struct LineInfo *line,
                           int ix, int iy);
                          
 
@@ -337,7 +332,7 @@ typedef void (*plot_func)(GLcontext *ctx, struct LineInfo *line,
  * 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,
         GLfloat t0, GLfloat t1)
@@ -464,74 +459,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 NAME(x)  aa_general_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 DO_Z
-#define DO_FOG
-#define DO_RGBA
-#define DO_MULTITEX
-#include "s_aalinetemp.h"
-
-
-#define NAME(x)  aa_multitex_spec_##x
-#define DO_Z
-#define DO_FOG
-#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._EnabledUnits != 0) {
-         if (ctx->Texture._EnabledUnits > 1) {
-            /* Multitextured! */
-            if (ctx->Light.Model.ColorControl==GL_SEPARATE_SPECULAR_COLOR || 
-                ctx->Fog.ColorSumEnabled)
-               swrast->Line = aa_multitex_spec_line;
-            else
-               swrast->Line = aa_multitex_rgba_line;
-         }
-         else {
-            swrast->Line = aa_tex_rgba_line;
-         }
-      }
-      else {
-         swrast->Line = aa_rgba_line;
-      }
+   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;
    }
 }