glsl: Handle continuation characters in preprocessor.
[mesa.git] / src / mesa / tnl_dd / t_dd_tritmp.h
index 055ee559a04dfd85a6fb512e022151888c3224fa..1ae70f4059f221c252b991e3b1dd0aa2502b8ec5 100644 (file)
@@ -1,9 +1,8 @@
-
 /*
  * Mesa 3-D graphics library
- * Version:  3.5
+ * Version:  6.3
  *
- * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2005  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"),
@@ -49,7 +48,8 @@
  * VERT_X(v): Alias for vertex x value.
  * VERT_Y(v): Alias for vertex y value.
  * VERT_Z(v): Alias for vertex z value.
- * DEPTH_SCALE: Scale for offset.
+ * DEPTH_SCALE: Scale for constant offset.
+ * REVERSE_DEPTH: Viewport depth range reversed.
  *
  * VERTEX: Hardware vertex type.
  * GET_VERTEX(n): Retreive vertex with index n.
 #define VERT_Z_ADD(v,val) VERT_Z(v) += val
 #endif
 
+#ifndef REVERSE_DEPTH
+#define REVERSE_DEPTH 0
+#endif
+
 /* disable twostencil for un-aware drivers */
 #ifndef HAVE_STENCIL_TWOSIDE
 #define HAVE_STENCIL_TWOSIDE 0
@@ -127,10 +131,10 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
 {
    struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
    VERTEX *v[3];
-   GLfloat offset;
+   GLfloat offset = 0;
    GLfloat z[3];
    GLenum mode = GL_FILL;
-   GLuint facing;
+   GLuint facing = 0;
    LOCAL_VARS(3);
 
 /*     fprintf(stderr, "%s\n", __FUNCTION__); */
@@ -151,10 +155,6 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
       {
         facing = AREA_IS_CCW( cc ) ^ ctx->Polygon._FrontBit;
 
-         if (DO_TWOSTENCIL && ctx->Stencil.TestTwoSide) {
-            ctx->_Facing = facing; /* mixed mode rendering: for 2-sided stencil test */
-         }
-
         if (DO_UNFILLED) {
            if (facing) {
               mode = ctx->Polygon.BackMode;
@@ -196,20 +196,34 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
               }
               else {
                  GLfloat (*vbcolor)[4] = VB->ColorPtr[1]->data;
-                 ASSERT(VB->ColorPtr[1]->stride == 4*sizeof(GLfloat));
                  (void) vbcolor;
 
                  if (!DO_FLAT) {
                     VERT_SAVE_RGBA( 0 );
                     VERT_SAVE_RGBA( 1 );
-                    VERT_SET_RGBA( v[0], vbcolor[e0] );
-                    VERT_SET_RGBA( v[1], vbcolor[e1] );
                  }
                  VERT_SAVE_RGBA( 2 );
-                 VERT_SET_RGBA( v[2], vbcolor[e2] );
+
+                 if (VB->ColorPtr[1]->stride) {
+                    ASSERT(VB->ColorPtr[1]->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] );
+                 }
+                 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->SecondaryColorPtr[1]) {
                     GLfloat (*vbspec)[4] = VB->SecondaryColorPtr[1]->data;
+                    ASSERT(VB->SecondaryColorPtr[1]->stride == 4*sizeof(GLfloat));
 
                     if (!DO_FLAT) {
                        VERT_SAVE_SPEC( 0 );
@@ -253,9 +267,9 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
            GLfloat bc  = b * ic;
            if ( ac < 0.0f ) ac = -ac;
            if ( bc < 0.0f ) bc = -bc;
-           offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor;
+           offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor / ctx->DrawBuffer->_MRD;
         }
-        offset *= ctx->MRD;
+        offset *= ctx->DrawBuffer->_MRD * (REVERSE_DEPTH ? -1.0 : 1.0);
       }
    }
 
@@ -375,15 +389,15 @@ static void TAG(triangle)( GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 )
 
 #if DO_QUAD
 #if DO_FULL_QUAD
-static void TAG(quad)( GLcontext *ctx,
+static void TAG(quadr)( GLcontext *ctx,
                       GLuint e0, GLuint e1, GLuint e2, GLuint e3 )
 {
    struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
    VERTEX *v[4];
-   GLfloat offset;
+   GLfloat offset = 0;
    GLfloat z[4];
    GLenum mode = GL_FILL;
-   GLuint facing;
+   GLuint facing = 0;
    LOCAL_VARS(4);
 
    v[0] = (VERTEX *)GET_VERTEX(e0);
@@ -403,10 +417,6 @@ static void TAG(quad)( GLcontext *ctx,
       {
         facing = AREA_IS_CCW( cc ) ^ ctx->Polygon._FrontBit;
 
-         if (DO_TWOSTENCIL && ctx->Stencil.TestTwoSide) {
-            ctx->_Facing = facing; /* mixed mode rendering: for 2-sided stencil test */
-         }
-
         if (DO_UNFILLED) {
            if (facing) {
               mode = ctx->Polygon.BackMode;
@@ -458,12 +468,25 @@ static void TAG(quad)( GLcontext *ctx,
                     VERT_SAVE_RGBA( 0 );
                     VERT_SAVE_RGBA( 1 );
                     VERT_SAVE_RGBA( 2 );
-                    VERT_SET_RGBA( v[0], vbcolor[e0] );
-                    VERT_SET_RGBA( v[1], vbcolor[e1] );
-                    VERT_SET_RGBA( v[2], vbcolor[e2] );
-                 }
+                 }
                  VERT_SAVE_RGBA( 3 );
-                 VERT_SET_RGBA( v[3], vbcolor[e3] );
+
+                 if (VB->ColorPtr[1]->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 (HAVE_SPEC && VB->SecondaryColorPtr[1]) {
                     GLfloat (*vbspec)[4] = VB->SecondaryColorPtr[1]->data;
@@ -516,9 +539,9 @@ static void TAG(quad)( GLcontext *ctx,
            GLfloat bc  = b * ic;
            if ( ac < 0.0f ) ac = -ac;
            if ( bc < 0.0f ) bc = -bc;
-           offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor;
+           offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor / ctx->DrawBuffer->_MRD;
         }
-        offset *= ctx->MRD;
+        offset *= ctx->DrawBuffer->_MRD * (REVERSE_DEPTH ? -1.0 : 1.0);
       }
    }
 
@@ -584,7 +607,7 @@ static void TAG(quad)( GLcontext *ctx,
         VERT_Z_ADD(v[2], offset);
         VERT_Z_ADD(v[3], offset);
       }
-      RASTERIZE( GL_TRIANGLES );
+      RASTERIZE( GL_QUADS );
       if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
          SETUP_STENCIL(facing);
          QUAD( (v[0]), (v[1]), (v[2]), (v[3]) );
@@ -650,7 +673,7 @@ static void TAG(quad)( GLcontext *ctx,
    }
 }
 #else
-static void TAG(quad)( GLcontext *ctx, GLuint e0,
+static void TAG(quadr)( GLcontext *ctx, GLuint e0,
                       GLuint e1, GLuint e2, GLuint e3 )
 {
    if (DO_UNFILLED) {
@@ -717,7 +740,7 @@ static void TAG(line)( GLcontext *ctx, GLuint e0, GLuint e1 )
 static void TAG(points)( GLcontext *ctx, GLuint first, GLuint last )
 {
    struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
-   int i;
+   GLuint i;
    LOCAL_VARS(1);
 
    if (VB->Elts == 0) {
@@ -742,7 +765,7 @@ static void TAG(points)( GLcontext *ctx, GLuint first, GLuint last )
 static void TAG(init)( void )
 {
 #if DO_QUAD
-   TAB[IND].quad = TAG(quad);
+   TAB[IND].quad = TAG(quadr);
 #endif
 #if DO_TRI
    TAB[IND].triangle = TAG(triangle);