egl: rename _eglMatchDriver() to _eglInitializeDisplay()
[mesa.git] / src / mesa / swrast / s_linetemp.h
index f5b2d95653f01bbd3d9808948a63ef9510e2f7d4..6706ec788b136a7b47cd35f6e83e1dc634f5c456 100644 (file)
@@ -1,8 +1,7 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
  *
- * Copyright (C) 1999-2005  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.
  */
 
 
  * The following macros may be defined to indicate what auxillary information
  * must be interplated along the line:
  *    INTERP_Z        - if defined, interpolate Z values
- *    INTERP_FOG      - if defined, interpolate FOG values
- *    INTERP_RGBA     - if defined, interpolate RGBA values
- *    INTERP_SPEC     - if defined, interpolate specular RGB values
- *    INTERP_INDEX    - if defined, interpolate color index values
- *    INTERP_TEX      - if defined, interpolate unit 0 texcoords
- *    INTERP_MULTITEX - if defined, interpolate multi-texcoords
+ *    INTERP_ATTRIBS  - if defined, interpolate attribs (texcoords, varying, etc)
  *
  * When one can directly address pixels in the color buffer the following
  * macros can be defined and used to directly compute pixel addresses during
 
 
 static void
-NAME( GLcontext *ctx, const SWvertex *vert0, const SWvertex *vert1 )
+NAME( struct gl_context *ctx, const SWvertex *vert0, const SWvertex *vert1 )
 {
+   const SWcontext *swrast = SWRAST_CONTEXT(ctx);
    SWspan span;
    GLuint interpFlags = 0;
-   GLint x0 = (GLint) vert0->win[0];
-   GLint x1 = (GLint) vert1->win[0];
-   GLint y0 = (GLint) vert0->win[1];
-   GLint y1 = (GLint) vert1->win[1];
+   GLint x0 = (GLint) vert0->attrib[VARYING_SLOT_POS][0];
+   GLint x1 = (GLint) vert1->attrib[VARYING_SLOT_POS][0];
+   GLint y0 = (GLint) vert0->attrib[VARYING_SLOT_POS][1];
+   GLint y1 = (GLint) vert1->attrib[VARYING_SLOT_POS][1];
    GLint dx, dy;
    GLint numPixels;
    GLint xstep, ystep;
 #if defined(DEPTH_TYPE)
-   const GLint depthBits = ctx->Visual.depthBits;
+   const GLint depthBits = ctx->DrawBuffer->Visual.depthBits;
    const GLint fixedToDepthShift = depthBits <= 16 ? FIXED_SHIFT : 0;
    struct gl_renderbuffer *zrb = ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
 #define FixedToDepth(F)  ((F) >> fixedToDepthShift)
    GLint zPtrXstep, zPtrYstep;
    DEPTH_TYPE *zPtr;
 #elif defined(INTERP_Z)
-   const GLint depthBits = ctx->Visual.depthBits;
+   const GLint depthBits = ctx->DrawBuffer->Visual.depthBits;
 #endif
 #ifdef PIXEL_ADDRESS
    PIXEL_TYPE *pixelPtr;
@@ -98,20 +94,26 @@ NAME( GLcontext *ctx, const SWvertex *vert0, const SWvertex *vert1 )
    SETUP_CODE
 #endif
 
+   (void) swrast;
+
    /* Cull primitives with malformed coordinates.
     */
    {
-      GLfloat tmp = vert0->win[0] + vert0->win[1]
-                  + vert1->win[0] + vert1->win[1];
-      if (IS_INF_OR_NAN(tmp))
+      GLfloat tmp = vert0->attrib[VARYING_SLOT_POS][0] + vert0->attrib[VARYING_SLOT_POS][1]
+                  + vert1->attrib[VARYING_SLOT_POS][0] + vert1->attrib[VARYING_SLOT_POS][1];
+      if (util_is_inf_or_nan(tmp))
         return;
    }
 
    /*
-   printf("%s():\n", __FUNCTION__);
+   printf("%s():\n", __func__);
    printf(" (%f, %f, %f) -> (%f, %f, %f)\n",
-          vert0->win[0], vert0->win[1], vert0->win[2],
-          vert1->win[0], vert1->win[1], vert1->win[2]);
+          vert0->attrib[VARYING_SLOT_POS][0],
+          vert0->attrib[VARYING_SLOT_POS][1],
+          vert0->attrib[VARYING_SLOT_POS][2],
+          vert1->attrib[VARYING_SLOT_POS][0],
+          vert1->attrib[VARYING_SLOT_POS][1],
+          vert1->attrib[VARYING_SLOT_POS][2]);
    printf(" (%d, %d, %d) -> (%d, %d, %d)\n",
           vert0->color[0], vert0->color[1], vert0->color[2], 
           vert1->color[0], vert1->color[1], vert1->color[2]);
@@ -151,8 +153,20 @@ NAME( GLcontext *ctx, const SWvertex *vert0, const SWvertex *vert1 )
    if (dx == 0 && dy == 0)
       return;
 
+   /*
+   printf("%s %d,%d  %g %g %g %g  %g %g %g %g\n", __func__, dx, dy,
+          vert0->attrib[VARYING_SLOT_COL1][0],
+          vert0->attrib[VARYING_SLOT_COL1][1],
+          vert0->attrib[VARYING_SLOT_COL1][2],
+          vert0->attrib[VARYING_SLOT_COL1][3],
+          vert1->attrib[VARYING_SLOT_COL1][0],
+          vert1->attrib[VARYING_SLOT_COL1][1],
+          vert1->attrib[VARYING_SLOT_COL1][2],
+          vert1->attrib[VARYING_SLOT_COL1][3]);
+   */
+
 #ifdef DEPTH_TYPE
-   zPtr = (DEPTH_TYPE *) zrb->GetPointer(ctx, zrb, x0, y0);
+   zPtr = (DEPTH_TYPE *) _swrast_pixel_address(zrb, x0, y0);
 #endif
 #ifdef PIXEL_ADDRESS
    pixelPtr = (PIXEL_TYPE *) PIXEL_ADDRESS(x0,y0);
@@ -198,15 +212,14 @@ NAME( GLcontext *ctx, const SWvertex *vert0, const SWvertex *vert1 )
 #endif
    }
 
-   ASSERT(dx >= 0);
-   ASSERT(dy >= 0);
+   assert(dx >= 0);
+   assert(dy >= 0);
 
    numPixels = MAX2(dx, dy);
 
    /*
     * Span setup: compute start and step values for all interpolated values.
     */
-#ifdef INTERP_RGBA
    interpFlags |= SPAN_RGBA;
    if (ctx->Light.ShadeModel == GL_SMOOTH) {
       span.red   = ChanToFixed(vert0->color[0]);
@@ -228,118 +241,58 @@ NAME( GLcontext *ctx, const SWvertex *vert0, const SWvertex *vert1 )
       span.blueStep  = 0;
       span.alphaStep = 0;
    }
-#endif
-#ifdef INTERP_SPEC
-   interpFlags |= SPAN_SPEC;
-   if (ctx->Light.ShadeModel == GL_SMOOTH) {
-      span.specRed       = ChanToFixed(vert0->specular[0]);
-      span.specGreen     = ChanToFixed(vert0->specular[1]);
-      span.specBlue      = ChanToFixed(vert0->specular[2]);
-      span.specRedStep   = (ChanToFixed(vert1->specular[0]) - span.specRed) / numPixels;
-      span.specGreenStep = (ChanToFixed(vert1->specular[1]) - span.specBlue) / numPixels;
-      span.specBlueStep  = (ChanToFixed(vert1->specular[2]) - span.specGreen) / numPixels;
-   }
-   else {
-      span.specRed       = ChanToFixed(vert1->specular[0]);
-      span.specGreen     = ChanToFixed(vert1->specular[1]);
-      span.specBlue      = ChanToFixed(vert1->specular[2]);
-      span.specRedStep   = 0;
-      span.specGreenStep = 0;
-      span.specBlueStep  = 0;
-   }
-#endif
-#ifdef INTERP_INDEX
-   interpFlags |= SPAN_INDEX;
-   if (ctx->Light.ShadeModel == GL_SMOOTH) {
-      span.index = FloatToFixed(vert0->index);
-      span.indexStep = FloatToFixed(vert1->index - vert0->index) / numPixels;
-   }
-   else {
-      span.index = FloatToFixed(vert1->index);
-      span.indexStep = 0;
-   }
-#endif
 #if defined(INTERP_Z) || defined(DEPTH_TYPE)
    interpFlags |= SPAN_Z;
    {
       if (depthBits <= 16) {
-         span.z = FloatToFixed(vert0->win[2]) + FIXED_HALF;
-         span.zStep = FloatToFixed(vert1->win[2] - vert0->win[2]) / numPixels;
+         span.z = FloatToFixed(vert0->attrib[VARYING_SLOT_POS][2]) + FIXED_HALF;
+         span.zStep = FloatToFixed(  vert1->attrib[VARYING_SLOT_POS][2]
+                                   - vert0->attrib[VARYING_SLOT_POS][2]) / numPixels;
       }
       else {
          /* don't use fixed point */
-         span.z = (GLint) vert0->win[2];
-         span.zStep = (GLint) ((vert1->win[2] - vert0->win[2]) / numPixels);
+         span.z = (GLuint) vert0->attrib[VARYING_SLOT_POS][2];
+         span.zStep = (GLint) ((  vert1->attrib[VARYING_SLOT_POS][2]
+                                - vert0->attrib[VARYING_SLOT_POS][2]) / numPixels);
       }
    }
 #endif
-#ifdef INTERP_FOG
-   interpFlags |= SPAN_FOG;
-   span.fog = vert0->fog;
-   span.fogStep = (vert1->fog - vert0->fog) / numPixels;
-#endif
-#ifdef INTERP_TEX
-   interpFlags |= SPAN_TEXTURE;
+#if defined(INTERP_ATTRIBS)
    {
-      const GLfloat invw0 = vert0->win[3];
-      const GLfloat invw1 = vert1->win[3];
       const GLfloat invLen = 1.0F / numPixels;
-      GLfloat ds, dt, dr, dq;
-      span.tex[0][0] = invw0 * vert0->texcoord[0][0];
-      span.tex[0][1] = invw0 * vert0->texcoord[0][1];
-      span.tex[0][2] = invw0 * vert0->texcoord[0][2];
-      span.tex[0][3] = invw0 * vert0->texcoord[0][3];
-      ds = (invw1 * vert1->texcoord[0][0]) - span.tex[0][0];
-      dt = (invw1 * vert1->texcoord[0][1]) - span.tex[0][1];
-      dr = (invw1 * vert1->texcoord[0][2]) - span.tex[0][2];
-      dq = (invw1 * vert1->texcoord[0][3]) - span.tex[0][3];
-      span.texStepX[0][0] = ds * invLen;
-      span.texStepX[0][1] = dt * invLen;
-      span.texStepX[0][2] = dr * invLen;
-      span.texStepX[0][3] = dq * invLen;
-      span.texStepY[0][0] = 0.0F;
-      span.texStepY[0][1] = 0.0F;
-      span.texStepY[0][2] = 0.0F;
-      span.texStepY[0][3] = 0.0F;
-   }
-#endif
-#ifdef INTERP_MULTITEX
-   interpFlags |= SPAN_TEXTURE;
-   {
-      const GLfloat invLen = 1.0F / numPixels;
-      GLuint u;
-      for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
-         if (ctx->Texture.Unit[u]._ReallyEnabled) {
-            const GLfloat invw0 = vert0->win[3];
-            const GLfloat invw1 = vert1->win[3];
-            GLfloat ds, dt, dr, dq;
-            span.tex[u][0] = invw0 * vert0->texcoord[u][0];
-            span.tex[u][1] = invw0 * vert0->texcoord[u][1];
-            span.tex[u][2] = invw0 * vert0->texcoord[u][2];
-            span.tex[u][3] = invw0 * vert0->texcoord[u][3];
-            ds = (invw1 * vert1->texcoord[u][0]) - span.tex[u][0];
-            dt = (invw1 * vert1->texcoord[u][1]) - span.tex[u][1];
-            dr = (invw1 * vert1->texcoord[u][2]) - span.tex[u][2];
-            dq = (invw1 * vert1->texcoord[u][3]) - span.tex[u][3];
-            span.texStepX[u][0] = ds * invLen;
-            span.texStepX[u][1] = dt * invLen;
-            span.texStepX[u][2] = dr * invLen;
-            span.texStepX[u][3] = dq * invLen;
-            span.texStepY[u][0] = 0.0F;
-            span.texStepY[u][1] = 0.0F;
-            span.texStepY[u][2] = 0.0F;
-            span.texStepY[u][3] = 0.0F;
-        }
-      }
+      const GLfloat invw0 = vert0->attrib[VARYING_SLOT_POS][3];
+      const GLfloat invw1 = vert1->attrib[VARYING_SLOT_POS][3];
+
+      span.attrStart[VARYING_SLOT_POS][3] = invw0;
+      span.attrStepX[VARYING_SLOT_POS][3] = (invw1 - invw0) * invLen;
+      span.attrStepY[VARYING_SLOT_POS][3] = 0.0;
+
+      ATTRIB_LOOP_BEGIN
+         if (swrast->_InterpMode[attr] == GL_FLAT) {
+            COPY_4V(span.attrStart[attr], vert1->attrib[attr]);
+            ASSIGN_4V(span.attrStepX[attr], 0.0, 0.0, 0.0, 0.0);
+         }
+         else {
+            GLuint c;
+            for (c = 0; c < 4; c++) {
+               float da;
+               span.attrStart[attr][c] = invw0 * vert0->attrib[attr][c];
+               da = (invw1 * vert1->attrib[attr][c]) - span.attrStart[attr][c];
+               span.attrStepX[attr][c] = da * invLen;
+            }
+         }
+         ASSIGN_4V(span.attrStepY[attr], 0.0, 0.0, 0.0, 0.0);
+      ATTRIB_LOOP_END
    }
 #endif
 
-   INIT_SPAN(span, GL_LINE, numPixels, interpFlags, SPAN_XY);
+   INIT_SPAN(span, GL_LINE);
+   span.end = numPixels;
+   span.interpMask = interpFlags;
+   span.arrayMask = SPAN_XY;
+
+   span.facing = swrast->PointLineFacing;
 
-   /* Need these for fragment prog texcoord interpolation */
-   span.w = 1.0F;
-   span.dwdx = 0.0F;
-   span.dwdy = 0.0F;
 
    /*
     * Draw
@@ -370,7 +323,7 @@ NAME( GLcontext *ctx, const SWvertex *vert0, const SWvertex *vert1 )
 #ifdef PIXEL_ADDRESS
          pixelPtr = (PIXEL_TYPE*) ((GLubyte*) pixelPtr + pixelXstep);
 #endif
-         if (error<0) {
+         if (error < 0) {
             error += errorInc;
          }
          else {
@@ -437,12 +390,7 @@ NAME( GLcontext *ctx, const SWvertex *vert0, const SWvertex *vert1 )
 
 #undef NAME
 #undef INTERP_Z
-#undef INTERP_FOG
-#undef INTERP_RGBA
-#undef INTERP_SPEC
-#undef INTERP_TEX
-#undef INTERP_MULTITEX
-#undef INTERP_INDEX
+#undef INTERP_ATTRIBS
 #undef PIXEL_ADDRESS
 #undef PIXEL_TYPE
 #undef DEPTH_TYPE