t_dd_dmatmp: Use addition instead of subtraction in loop bounds
[mesa.git] / src / mesa / tnl_dd / t_dd_tritmp.h
index 708f7560edacc84ab6adc7f7f2fbc5e5f5057a56..2176f1f1667387affee656dd033c9b1a6623dc3f 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.3
  *
  * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
  *
  * 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.
  *
  * Authors:
- *    Keith Whitwell <keith@tungstengraphics.com>
+ *    Keith Whitwell <keithw@vmware.com>
  */
 
 
 #endif
 
 #if DO_TRI
-static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
+static void TAG(triangle)( struct gl_context *ctx, GLuint e0, GLuint e1, GLuint e2 )
 {
    struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
    VERTEX *v[3];
@@ -121,7 +121,7 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
    GLuint facing = 0;
    LOCAL_VARS(3);
 
-/*     fprintf(stderr, "%s\n", __FUNCTION__); */
+/*     fprintf(stderr, "%s\n", __func__); */
 
    v[0] = (VERTEX *)GET_VERTEX(e0);
    v[1] = (VERTEX *)GET_VERTEX(e1);
@@ -155,69 +155,68 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
            }
         }
 
-        if (DO_TWOSIDE && facing == 1)
-        {
-              if (HAVE_BACK_COLORS) {
+        if (DO_TWOSIDE && facing == 1) {
+           if (HAVE_BACK_COLORS) {
+              if (!DO_FLAT) {
+                 VERT_SAVE_RGBA( 0 );
+                 VERT_SAVE_RGBA( 1 );
+                 VERT_COPY_RGBA1( v[0] );
+                 VERT_COPY_RGBA1( v[1] );
+              }
+              VERT_SAVE_RGBA( 2 );
+              VERT_COPY_RGBA1( v[2] );
+              if (HAVE_SPEC) {
                  if (!DO_FLAT) {
-                    VERT_SAVE_RGBA( 0 );
-                    VERT_SAVE_RGBA( 1 );
-                    VERT_COPY_RGBA1( v[0] );
-                    VERT_COPY_RGBA1( v[1] );
-                 }
-                 VERT_SAVE_RGBA( 2 );
-                 VERT_COPY_RGBA1( v[2] );
-                 if (HAVE_SPEC) {
-                    if (!DO_FLAT) {
-                       VERT_SAVE_SPEC( 0 );
-                       VERT_SAVE_SPEC( 1 );
-                       VERT_COPY_SPEC1( v[0] );
-                       VERT_COPY_SPEC1( v[1] );
-                    }
-                    VERT_SAVE_SPEC( 2 );
-                    VERT_COPY_SPEC1( v[2] );
+                    VERT_SAVE_SPEC( 0 );
+                    VERT_SAVE_SPEC( 1 );
+                    VERT_COPY_SPEC1( v[0] );
+                    VERT_COPY_SPEC1( v[1] );
                  }
+                 VERT_SAVE_SPEC( 2 );
+                 VERT_COPY_SPEC1( v[2] );
               }
-              else {
-                 GLfloat (*vbcolor)[4] = VB->BackfaceColorPtr->data;
-                 (void) vbcolor;
+           }
+           else {
+              GLfloat (*vbcolor)[4] = VB->BackfaceColorPtr->data;
+              (void) vbcolor;
 
-                 if (!DO_FLAT) {
-                    VERT_SAVE_RGBA( 0 );
-                    VERT_SAVE_RGBA( 1 );
-                 }
-                 VERT_SAVE_RGBA( 2 );
+              if (!DO_FLAT) {
+                 VERT_SAVE_RGBA( 0 );
+                 VERT_SAVE_RGBA( 1 );
+              }
+              VERT_SAVE_RGBA( 2 );
 
-                 if (VB->BackfaceColorPtr->stride) {
-                    ASSERT(VB->BackfaceColorPtr->stride == 4*sizeof(GLfloat));
+              if (VB->BackfaceColorPtr->stride) {
+                 assert(VB->BackfaceColorPtr->stride == 4*sizeof(GLfloat));
 
-                    if (!DO_FLAT) {              
-                       VERT_SET_RGBA( v[0], vbcolor[e0] );
-                       VERT_SET_RGBA( v[1], vbcolor[e1] );
-                    }
-                    VERT_SET_RGBA( v[2], vbcolor[e2] );
+                 if (!DO_FLAT) {
+                    VERT_SET_RGBA( v[0], vbcolor[e0] );
+                    VERT_SET_RGBA( v[1], vbcolor[e1] );
                  }
-                 else {
-                    if (!DO_FLAT) {              
-                       VERT_SET_RGBA( v[0], vbcolor[0] );
-                       VERT_SET_RGBA( v[1], vbcolor[0] );
-                    }
-                    VERT_SET_RGBA( v[2], vbcolor[0] );
+                 VERT_SET_RGBA( v[2], vbcolor[e2] );
+              }
+              else {
+                 if (!DO_FLAT) {
+                    VERT_SET_RGBA( v[0], vbcolor[0] );
+                    VERT_SET_RGBA( v[1], vbcolor[0] );
                  }
+                 VERT_SET_RGBA( v[2], vbcolor[0] );
+              }
 
-                 if (HAVE_SPEC && VB->BackfaceSecondaryColorPtr) {
-                    GLfloat (*vbspec)[4] = VB->BackfaceSecondaryColorPtr->data;
-                    ASSERT(VB->BackfaceSecondaryColorPtr->stride == 4*sizeof(GLfloat));
+              if (HAVE_SPEC && VB->BackfaceSecondaryColorPtr) {
+                 GLfloat (*vbspec)[4] = VB->BackfaceSecondaryColorPtr->data;
+                 assert(VB->BackfaceSecondaryColorPtr->stride == 4*sizeof(GLfloat));
 
-                    if (!DO_FLAT) {
-                       VERT_SAVE_SPEC( 0 );
-                       VERT_SAVE_SPEC( 1 );
-                       VERT_SET_SPEC( v[0], vbspec[e0] );
-                       VERT_SET_SPEC( v[1], vbspec[e1] );
-                    }
-                    VERT_SAVE_SPEC( 2 );
-                    VERT_SET_SPEC( v[2], vbspec[e2] );
+                 if (!DO_FLAT) {
+                    VERT_SAVE_SPEC( 0 );
+                    VERT_SAVE_SPEC( 1 );
+                    VERT_SET_SPEC( v[0], vbspec[e0] );
+                    VERT_SET_SPEC( v[1], vbspec[e1] );
                  }
+                 VERT_SAVE_SPEC( 2 );
+                 VERT_SET_SPEC( v[2], vbspec[e2] );
               }
+           }
         }
       }
 
@@ -245,16 +244,16 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
    }
 
    if (DO_FLAT) {
-        VERT_SAVE_RGBA( 0 );
-        VERT_SAVE_RGBA( 1 );
-        VERT_COPY_RGBA( v[0], v[2] );
-        VERT_COPY_RGBA( v[1], v[2] );
-        if (HAVE_SPEC && VB->AttribPtr[_TNL_ATTRIB_COLOR1]) {
-           VERT_SAVE_SPEC( 0 );
-           VERT_SAVE_SPEC( 1 );
-           VERT_COPY_SPEC( v[0], v[2] );
-           VERT_COPY_SPEC( v[1], v[2] );
-        }
+      VERT_SAVE_RGBA( 0 );
+      VERT_SAVE_RGBA( 1 );
+      VERT_COPY_RGBA( v[0], v[2] );
+      VERT_COPY_RGBA( v[1], v[2] );
+      if (HAVE_SPEC && VB->AttribPtr[_TNL_ATTRIB_COLOR1]) {
+        VERT_SAVE_SPEC( 0 );
+        VERT_SAVE_SPEC( 1 );
+        VERT_COPY_SPEC( v[0], v[2] );
+        VERT_COPY_SPEC( v[1], v[2] );
+      }
    }
 
    if (mode == GL_POINT) {
@@ -289,8 +288,9 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
         VERT_Z_ADD(v[1], offset);
         VERT_Z_ADD(v[2], offset);
       }
-      if (DO_UNFILLED)
+      if (DO_UNFILLED) {
         RASTERIZE( GL_TRIANGLES );
+      }
       if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
          SETUP_STENCIL(facing);
          TRI( v[0], v[1], v[2] );
@@ -307,20 +307,19 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
       VERT_SET_Z(v[2], z[2]);
    }
 
-   if (DO_TWOSIDE && facing == 1)
-   {
+   if (DO_TWOSIDE && facing == 1) {
+      if (!DO_FLAT) {
+        VERT_RESTORE_RGBA( 0 );
+        VERT_RESTORE_RGBA( 1 );
+      }
+      VERT_RESTORE_RGBA( 2 );
+      if (HAVE_SPEC) {
         if (!DO_FLAT) {
-           VERT_RESTORE_RGBA( 0 );
-           VERT_RESTORE_RGBA( 1 );
-        }
-        VERT_RESTORE_RGBA( 2 );
-        if (HAVE_SPEC) {
-           if (!DO_FLAT) {
-              VERT_RESTORE_SPEC( 0 );
-              VERT_RESTORE_SPEC( 1 );
-           }
-           VERT_RESTORE_SPEC( 2 );
+           VERT_RESTORE_SPEC( 0 );
+           VERT_RESTORE_SPEC( 1 );
         }
+        VERT_RESTORE_SPEC( 2 );
+      }
    }
 
 
@@ -337,7 +336,7 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
 
 #if DO_QUAD
 #if DO_FULL_QUAD
-static void TAG(quadr)( GLcontext *ctx,
+static void TAG(quadr)( struct gl_context *ctx,
                       GLuint e0, GLuint e1, GLuint e2, GLuint e3 )
 {
    struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
@@ -381,76 +380,75 @@ static void TAG(quadr)( GLcontext *ctx,
            }
         }
 
-        if (DO_TWOSIDE && facing == 1)
-        {
-              GLfloat (*vbcolor)[4] = VB->BackfaceColorPtr->data;
-              (void)vbcolor;
-
-              if (HAVE_BACK_COLORS) {
-                  if (!DO_FLAT) {
-                     VERT_SAVE_RGBA( 0 );
-                     VERT_SAVE_RGBA( 1 );
-                     VERT_SAVE_RGBA( 2 );
-                    VERT_COPY_RGBA1( v[0] );
-                    VERT_COPY_RGBA1( v[1] );
-                    VERT_COPY_RGBA1( v[2] );
+        if (DO_TWOSIDE && facing == 1) {
+           GLfloat (*vbcolor)[4] = VB->BackfaceColorPtr->data;
+           (void)vbcolor;
+
+           if (HAVE_BACK_COLORS) {
+              if (!DO_FLAT) {
+                 VERT_SAVE_RGBA( 0 );
+                 VERT_SAVE_RGBA( 1 );
+                 VERT_SAVE_RGBA( 2 );
+                 VERT_COPY_RGBA1( v[0] );
+                 VERT_COPY_RGBA1( v[1] );
+                 VERT_COPY_RGBA1( v[2] );
+              }
+              VERT_SAVE_RGBA( 3 );
+              VERT_COPY_RGBA1( v[3] );
+              if (HAVE_SPEC) {
+                 if (!DO_FLAT) {
+                    VERT_SAVE_SPEC( 0 );
+                    VERT_SAVE_SPEC( 1 );
+                    VERT_SAVE_SPEC( 2 );
+                    VERT_COPY_SPEC1( v[0] );
+                    VERT_COPY_SPEC1( v[1] );
+                    VERT_COPY_SPEC1( v[2] );
                  }
-                 VERT_SAVE_RGBA( 3 );
-                 VERT_COPY_RGBA1( v[3] );
-                 if (HAVE_SPEC) {
-                     if (!DO_FLAT) {
-                        VERT_SAVE_SPEC( 0 );
-                        VERT_SAVE_SPEC( 1 );
-                        VERT_SAVE_SPEC( 2 );
-                       VERT_COPY_SPEC1( v[0] );
-                       VERT_COPY_SPEC1( v[1] );
-                       VERT_COPY_SPEC1( v[2] );
-                    }
-                    VERT_SAVE_SPEC( 3 );
-                    VERT_COPY_SPEC1( v[3] );
+                 VERT_SAVE_SPEC( 3 );
+                 VERT_COPY_SPEC1( v[3] );
+              }
+           }
+           else {
+              if (!DO_FLAT) {
+                 VERT_SAVE_RGBA( 0 );
+                 VERT_SAVE_RGBA( 1 );
+                 VERT_SAVE_RGBA( 2 );
+              }
+              VERT_SAVE_RGBA( 3 );
+
+              if (VB->BackfaceColorPtr->stride) {
+                 if (!DO_FLAT) {
+                    VERT_SET_RGBA( v[0], vbcolor[e0] );
+                    VERT_SET_RGBA( v[1], vbcolor[e1] );
+                    VERT_SET_RGBA( v[2], vbcolor[e2] );
                  }
+                 VERT_SET_RGBA( v[3], vbcolor[e3] );
               }
               else {
-                 if (!DO_FLAT) {
-                    VERT_SAVE_RGBA( 0 );
-                    VERT_SAVE_RGBA( 1 );
-                    VERT_SAVE_RGBA( 2 );
-                 }
-                 VERT_SAVE_RGBA( 3 );
-
-                 if (VB->BackfaceColorPtr->stride) {
-                    if (!DO_FLAT) {
-                       VERT_SET_RGBA( v[0], vbcolor[e0] );
-                       VERT_SET_RGBA( v[1], vbcolor[e1] );
-                       VERT_SET_RGBA( v[2], vbcolor[e2] );
-                    }
-                    VERT_SET_RGBA( v[3], vbcolor[e3] );
-                 }
-                 else {
-                    if (!DO_FLAT) {
-                       VERT_SET_RGBA( v[0], vbcolor[0] );
-                       VERT_SET_RGBA( v[1], vbcolor[0] );
-                       VERT_SET_RGBA( v[2], vbcolor[0] );
-                    }
-                    VERT_SET_RGBA( v[3], vbcolor[0] );
+                 if (!DO_FLAT) {
+                    VERT_SET_RGBA( v[0], vbcolor[0] );
+                    VERT_SET_RGBA( v[1], vbcolor[0] );
+                    VERT_SET_RGBA( v[2], vbcolor[0] );
                  }
+                 VERT_SET_RGBA( v[3], vbcolor[0] );
+              }
 
-                 if (HAVE_SPEC && VB->BackfaceSecondaryColorPtr) {
-                    GLfloat (*vbspec)[4] = VB->BackfaceSecondaryColorPtr->data;
-                    ASSERT(VB->BackfaceSecondaryColorPtr->stride==4*sizeof(GLfloat));
-
-                    if (!DO_FLAT) {
-                       VERT_SAVE_SPEC( 0 );
-                       VERT_SAVE_SPEC( 1 );
-                       VERT_SAVE_SPEC( 2 );
-                       VERT_SET_SPEC( v[0], vbspec[e0] );
-                       VERT_SET_SPEC( v[1], vbspec[e1] );
-                       VERT_SET_SPEC( v[2], vbspec[e2] );
-                    }
-                    VERT_SAVE_SPEC( 3 );
-                    VERT_SET_SPEC( v[3], vbspec[e3] );
-                 }
+              if (HAVE_SPEC && VB->BackfaceSecondaryColorPtr) {
+                 GLfloat (*vbspec)[4] = VB->BackfaceSecondaryColorPtr->data;
+                 assert(VB->BackfaceSecondaryColorPtr->stride==4*sizeof(GLfloat));
+
+                 if (!DO_FLAT) {
+                    VERT_SAVE_SPEC( 0 );
+                    VERT_SAVE_SPEC( 1 );
+                    VERT_SAVE_SPEC( 2 );
+                    VERT_SET_SPEC( v[0], vbspec[e0] );
+                    VERT_SET_SPEC( v[1], vbspec[e1] );
+                    VERT_SET_SPEC( v[2], vbspec[e2] );
+                 }
+                 VERT_SAVE_SPEC( 3 );
+                 VERT_SET_SPEC( v[3], vbspec[e3] );
               }
+           }
         }
       }
 
@@ -548,22 +546,21 @@ static void TAG(quadr)( GLcontext *ctx,
       VERT_SET_Z(v[3], z[3]);
    }
 
-   if (DO_TWOSIDE && facing == 1)
-   {
+   if (DO_TWOSIDE && facing == 1) {
+      if (!DO_FLAT) {
+        VERT_RESTORE_RGBA( 0 );
+        VERT_RESTORE_RGBA( 1 );
+        VERT_RESTORE_RGBA( 2 );
+      }
+      VERT_RESTORE_RGBA( 3 );
+      if (HAVE_SPEC) {
         if (!DO_FLAT) {
-           VERT_RESTORE_RGBA( 0 );
-           VERT_RESTORE_RGBA( 1 );
-           VERT_RESTORE_RGBA( 2 );
-        }
-        VERT_RESTORE_RGBA( 3 );
-        if (HAVE_SPEC) {
-           if (!DO_FLAT) {
-              VERT_RESTORE_SPEC( 0 );
-              VERT_RESTORE_SPEC( 1 );
-              VERT_RESTORE_SPEC( 2 );
-           }
-           VERT_RESTORE_SPEC( 3 );
+           VERT_RESTORE_SPEC( 0 );
+           VERT_RESTORE_SPEC( 1 );
+           VERT_RESTORE_SPEC( 2 );
         }
+        VERT_RESTORE_SPEC( 3 );
+      }
    }
 
 
@@ -579,7 +576,7 @@ static void TAG(quadr)( GLcontext *ctx,
    }
 }
 #else
-static void TAG(quadr)( GLcontext *ctx, GLuint e0,
+static void TAG(quadr)( struct gl_context *ctx, GLuint e0,
                       GLuint e1, GLuint e2, GLuint e3 )
 {
    if (DO_UNFILLED) {
@@ -601,7 +598,7 @@ static void TAG(quadr)( GLcontext *ctx, GLuint e0,
 #endif
 
 #if DO_LINE
-static void TAG(line)( GLcontext *ctx, GLuint e0, GLuint e1 )
+static void TAG(line)( struct gl_context *ctx, GLuint e0, GLuint e1 )
 {
    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
    VERTEX *v[2];
@@ -632,7 +629,7 @@ static void TAG(line)( GLcontext *ctx, GLuint e0, GLuint e1 )
 #endif
 
 #if DO_POINTS
-static void TAG(points)( GLcontext *ctx, GLuint first, GLuint last )
+static void TAG(points)( struct gl_context *ctx, GLuint first, GLuint last )
 {
    struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
    GLuint i;