Merge branch 'master' into i915-unification
[mesa.git] / src / mesa / swrast / s_triangle.c
index 93df57d77c29b833316123124a684627e331c2f5..fc9d29bbf7f85a9abe0ca34c7296cfb2f500f60a 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
+ * Version:  6.5.3
  *
- * Copyright (C) 1999-2006  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"),
@@ -67,24 +67,9 @@ _swrast_culltriangle( GLcontext *ctx,
 
 
 /*
- * Render a flat-shaded color index triangle.
+ * Render a smooth or flat-shaded color index triangle.
  */
-#define NAME flat_ci_triangle
-#define INTERP_Z 1
-#define INTERP_FOG 1
-#define SETUP_CODE                     \
-   span.interpMask |= SPAN_INDEX;      \
-   span.index = FloatToFixed(v2->index);\
-   span.indexStep = 0;
-#define RENDER_SPAN( span )  _swrast_write_index_span(ctx, &span);
-#include "s_tritemp.h"
-
-
-
-/*
- * Render a smooth-shaded color index triangle.
- */
-#define NAME smooth_ci_triangle
+#define NAME ci_triangle
 #define INTERP_Z 1
 #define INTERP_FOG 1
 #define INTERP_INDEX 1
@@ -139,7 +124,7 @@ _swrast_culltriangle( GLcontext *ctx,
  * Render an RGB, GL_DECAL, textured triangle.
  * Interpolate S,T only w/out mipmapping or perspective correction.
  *
- * No fog.
+ * No fog.  No depth testing.
  */
 #define NAME simple_textured_triangle
 #define INTERP_INT_TEX 1
@@ -163,6 +148,7 @@ _swrast_culltriangle( GLcontext *ctx,
 
 #define RENDER_SPAN( span )                                            \
    GLuint i;                                                           \
+   GLchan rgb[MAX_WIDTH][3];                                           \
    span.intTex[0] -= FIXED_HALF; /* off-by-one error? */               \
    span.intTex[1] -= FIXED_HALF;                                       \
    for (i = 0; i < span.end; i++) {                                    \
@@ -170,13 +156,13 @@ _swrast_culltriangle( GLcontext *ctx,
       GLint t = FixedToInt(span.intTex[1]) & tmask;                    \
       GLint pos = (t << twidth_log2) + s;                              \
       pos = pos + pos + pos;  /* multiply by 3 */                      \
-      span.array->rgb[i][RCOMP] = texture[pos];                                \
-      span.array->rgb[i][GCOMP] = texture[pos+1];                      \
-      span.array->rgb[i][BCOMP] = texture[pos+2];                      \
+      rgb[i][RCOMP] = texture[pos];                                    \
+      rgb[i][GCOMP] = texture[pos+1];                                  \
+      rgb[i][BCOMP] = texture[pos+2];                                  \
       span.intTex[0] += span.intTexStep[0];                            \
       span.intTex[1] += span.intTexStep[1];                            \
    }                                                                   \
-   rb->PutRowRGB(ctx, rb, span.end, span.x, span.y, span.array->rgb, NULL);
+   rb->PutRowRGB(ctx, rb, span.end, span.x, span.y, rgb, NULL);
 
 #include "s_tritemp.h"
 
@@ -214,6 +200,7 @@ _swrast_culltriangle( GLcontext *ctx,
 
 #define RENDER_SPAN( span )                                            \
    GLuint i;                                                           \
+   GLchan rgb[MAX_WIDTH][3];                                           \
    span.intTex[0] -= FIXED_HALF; /* off-by-one error? */               \
    span.intTex[1] -= FIXED_HALF;                                       \
    for (i = 0; i < span.end; i++) {                                    \
@@ -223,9 +210,9 @@ _swrast_culltriangle( GLcontext *ctx,
          GLint t = FixedToInt(span.intTex[1]) & tmask;                 \
          GLint pos = (t << twidth_log2) + s;                           \
          pos = pos + pos + pos;  /* multiply by 3 */                   \
-         span.array->rgb[i][RCOMP] = texture[pos];                     \
-         span.array->rgb[i][GCOMP] = texture[pos+1];                   \
-         span.array->rgb[i][BCOMP] = texture[pos+2];                   \
+         rgb[i][RCOMP] = texture[pos];                                 \
+         rgb[i][GCOMP] = texture[pos+1];                               \
+         rgb[i][BCOMP] = texture[pos+2];                               \
          zRow[i] = z;                                                  \
          span.array->mask[i] = 1;                                      \
       }                                                                        \
@@ -236,8 +223,7 @@ _swrast_culltriangle( GLcontext *ctx,
       span.intTex[1] += span.intTexStep[1];                            \
       span.z += span.zStep;                                            \
    }                                                                   \
-   rb->PutRowRGB(ctx, rb, span.end, span.x, span.y,                    \
-                 span.array->rgb, span.array->mask);
+   rb->PutRowRGB(ctx, rb, span.end, span.x, span.y, rgb, span.array->mask);
 
 #include "s_tritemp.h"
 
@@ -278,7 +264,7 @@ ilerp_2d(GLint ia, GLint ib, GLint v00, GLint v10, GLint v01, GLint v11)
  * texture env modes.
  */
 static INLINE void
-affine_span(GLcontext *ctx, struct sw_span *span,
+affine_span(GLcontext *ctx, SWspan *span,
             struct affine_info *info)
 {
    GLchan sample[4];  /* the filtered texture sample */
@@ -601,7 +587,7 @@ struct persp_info
 
 
 static INLINE void
-fast_persp_span(GLcontext *ctx, struct sw_span *span,
+fast_persp_span(GLcontext *ctx, SWspan *span,
                struct persp_info *info)
 {
    GLchan sample[4];  /* the filtered texture sample */
@@ -675,13 +661,13 @@ fast_persp_span(GLcontext *ctx, struct sw_span *span,
    const GLuint savedTexEnable = ctx->Texture._EnabledUnits;
    ctx->Texture._EnabledUnits = 0;
 
-   tex_coord[0] = span->tex[0][0]  * (info->smask + 1);
-   tex_step[0] = span->texStepX[0][0] * (info->smask + 1);
-   tex_coord[1] = span->tex[0][1] * (info->tmask + 1);
-   tex_step[1] = span->texStepX[0][1] * (info->tmask + 1);
-   /* span->tex[0][2] only if 3D-texturing, here only 2D */
-   tex_coord[2] = span->tex[0][3];
-   tex_step[2] = span->texStepX[0][3];
+   tex_coord[0] = span->attrStart[FRAG_ATTRIB_TEX0][0]  * (info->smask + 1);
+   tex_step[0] = span->attrStepX[FRAG_ATTRIB_TEX0][0] * (info->smask + 1);
+   tex_coord[1] = span->attrStart[FRAG_ATTRIB_TEX0][1] * (info->tmask + 1);
+   tex_step[1] = span->attrStepX[FRAG_ATTRIB_TEX0][1] * (info->tmask + 1);
+   /* span->attrStart[FRAG_ATTRIB_TEX0][2] only if 3D-texturing, here only 2D */
+   tex_coord[2] = span->attrStart[FRAG_ATTRIB_TEX0][3];
+   tex_step[2] = span->attrStepX[FRAG_ATTRIB_TEX0][3];
 
    switch (info->filter) {
    case GL_NEAREST:
@@ -802,7 +788,7 @@ fast_persp_span(GLcontext *ctx, struct sw_span *span,
 #define INTERP_FOG 1
 #define INTERP_RGB 1
 #define INTERP_ALPHA 1
-#define INTERP_TEX 1
+#define INTERP_ATTRIBS 1
 
 #define SETUP_CODE                                                     \
    struct persp_info info;                                             \
@@ -864,40 +850,21 @@ fast_persp_span(GLcontext *ctx, struct sw_span *span,
 
 
 /*
- * Render a smooth-shaded, textured, RGBA triangle.
- * Interpolate S,T,R with perspective correction, w/out mipmapping.
+ * Render an RGBA triangle with arbitrary attributes.
  */
-#define NAME general_textured_triangle
+#define NAME general_triangle
 #define INTERP_Z 1
 #define INTERP_W 1
 #define INTERP_FOG 1
 #define INTERP_RGB 1
 #define INTERP_SPEC 1
 #define INTERP_ALPHA 1
-#define INTERP_TEX 1
+#define INTERP_ATTRIBS 1
 #define RENDER_SPAN( span )   _swrast_write_rgba_span(ctx, &span);
 #include "s_tritemp.h"
 
 
 
-/*
- * This is the big one!
- * Interpolate Z, RGB, Alpha, specular, fog, N sets of texture coordinates, and varying floats.
- * Yup, it's slow.
- */
-#define NAME multitextured_triangle
-#define INTERP_Z 1
-#define INTERP_W 1
-#define INTERP_FOG 1
-#define INTERP_RGB 1
-#define INTERP_ALPHA 1
-#define INTERP_SPEC 1
-#define INTERP_MULTITEX 1\r
-#define INTERP_VARYING 1
-#define RENDER_SPAN( span )   _swrast_write_rgba_span(ctx, &span);
-#include "s_tritemp.h"
-
-
 
 /*
  * Special tri function for occlusion testing
@@ -914,7 +881,7 @@ fast_persp_span(GLcontext *ctx, struct sw_span *span,
       return;                                                          \
    }
 #define RENDER_SPAN( span )                                            \
-   if (ctx->Visual.depthBits <= 16) {                                  \
+   if (rb->DepthBits <= 16) {                                          \
       GLuint i;                                                                \
       const GLushort *zRow = (const GLushort *)                                \
          rb->GetPointer(ctx, rb, span.x, span.y);                      \
@@ -1072,8 +1039,14 @@ _swrast_choose_triangle( GLcontext *ctx )
          }
       }
 
-      if (ctx->Texture._EnabledCoordUnits || ctx->FragmentProgram._Active ||\r
-          ctx->ATIFragmentShader._Enabled || ctx->ShaderObjects._FragmentShaderPresent) {
+      if (!rgbmode) {
+         USE(ci_triangle);
+         return;
+      }
+
+      if (ctx->Texture._EnabledCoordUnits ||
+          ctx->FragmentProgram._Current ||
+          ctx->ATIFragmentShader._Enabled) {
          /* Ugh, we do a _lot_ of tests to pick the best textured tri func */
          const struct gl_texture_object *texObj2D;
          const struct gl_texture_image *texImg;
@@ -1088,9 +1061,8 @@ _swrast_choose_triangle( GLcontext *ctx )
 
          /* First see if we can use an optimized 2-D texture function */
          if (ctx->Texture._EnabledCoordUnits == 0x1
-             && !ctx->FragmentProgram._Active
-             && !ctx->ATIFragmentShader._Enabled\r
-             && !ctx->ShaderObjects._FragmentShaderPresent
+             && !ctx->FragmentProgram._Current
+             && !ctx->ATIFragmentShader._Enabled
              && ctx->Texture.Unit[0]._ReallyEnabled == TEXTURE_2D_BIT
              && texObj2D->WrapS == GL_REPEAT
              && texObj2D->WrapT == GL_REPEAT
@@ -1110,7 +1082,7 @@ _swrast_choose_triangle( GLcontext *ctx )
                        && ctx->Depth.Mask == GL_TRUE)
                       || swrast->_RasterMask == TEXTURE_BIT)
                   && ctx->Polygon.StippleFlag == GL_FALSE
-                   && ctx->Visual.depthBits <= 16) {
+                   && ctx->DrawBuffer->Visual.depthBits <= 16) {
                  if (swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT)) {
                     USE(simple_z_textured_triangle);
                  }
@@ -1120,7 +1092,7 @@ _swrast_choose_triangle( GLcontext *ctx )
               }
               else {
 #if (CHAN_BITS == 16 || CHAN_BITS == 32)
-                  USE(general_textured_triangle);
+                  USE(general_triangle);
 #else
                   USE(affine_textured_triangle);
 #endif
@@ -1128,7 +1100,7 @@ _swrast_choose_triangle( GLcontext *ctx )
            }
            else {
 #if (CHAN_BITS == 16 || CHAN_BITS == 32)
-               USE(general_textured_triangle);
+               USE(general_triangle);
 #else
                USE(persp_textured_triangle);
 #endif
@@ -1136,33 +1108,18 @@ _swrast_choose_triangle( GLcontext *ctx )
         }
          else {
             /* general case textured triangles */
-            if (ctx->Texture._EnabledCoordUnits > 1) {
-               USE(multitextured_triangle);
-            }
-            else {
-               USE(general_textured_triangle);
-            }
+            USE(general_triangle);
          }
       }
       else {
          ASSERT(!ctx->Texture._EnabledCoordUnits);
         if (ctx->Light.ShadeModel==GL_SMOOTH) {
            /* smooth shaded, no texturing, stippled or some raster ops */
-            if (rgbmode) {
-              USE(smooth_rgba_triangle);
-            }
-            else {
-               USE(smooth_ci_triangle);
-            }
+            USE(smooth_rgba_triangle);
         }
         else {
            /* flat shaded, no texturing, stippled or some raster ops */
-            if (rgbmode) {
-              USE(flat_rgba_triangle);
-            }
-            else {
-               USE(flat_ci_triangle);
-            }
+            USE(flat_rgba_triangle);
         }
       }
    }