15df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/*
25df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * Mesa 3-D graphics library
3e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul * Version:  6.3
45df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *
5e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
65df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *
75df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * Permission is hereby granted, free of charge, to any person obtaining a
85df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * copy of this software and associated documentation files (the "Software"),
95df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * to deal in the Software without restriction, including without limitation
105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * the rights to use, copy, modify, merge, publish, distribute, sublicense,
115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * and/or sell copies of the Software, and to permit persons to whom the
125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * Software is furnished to do so, subject to the following conditions:
135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *
145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * The above copyright notice and this permission notice shall be included
155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * in all copies or substantial portions of the Software.
165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *
175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *
245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * Authors:
255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *    Keith Whitwell <keith@tungstengraphics.com>
265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul */
275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/* Template for building functions to plug into the driver interface
305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * of t_vb_render.c:
315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *     ctx->Driver.QuadFunc
325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *     ctx->Driver.TriangleFunc
335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *     ctx->Driver.LineFunc
345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *     ctx->Driver.PointsFunc
355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *
365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * DO_TWOSIDE:   Plug back-color values from the VB into backfacing triangles,
375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *               and restore vertices afterwards.
385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * DO_OFFSET:    Calculate offset for triangles and adjust vertices.  Restore
395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *               vertices after rendering.
405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * DO_FLAT:      For hardware without native flatshading, copy provoking colors
415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *               into the other vertices.  Restore after rendering.
425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * DO_UNFILLED:  Decompose triangles to lines and points where appropriate.
43f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca * DO_TWOSTENCIL:Gross hack for two-sided stencil.
445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *
455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * HAVE_SPEC: Vertices have secondary rgba values.
465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *
475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * VERT_X(v): Alias for vertex x value.
485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * VERT_Y(v): Alias for vertex y value.
495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * VERT_Z(v): Alias for vertex z value.
503b50f004333a922a259a4f733395c27002965dedFelix Kuehling * DEPTH_SCALE: Scale for constant offset.
513b50f004333a922a259a4f733395c27002965dedFelix Kuehling * REVERSE_DEPTH: Viewport depth range reversed.
525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *
535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * VERTEX: Hardware vertex type.
545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * GET_VERTEX(n): Retreive vertex with index n.
555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * AREA_IS_CCW(a): Return true if triangle with signed area a is ccw.
565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *
575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * VERT_SET_RGBA: Assign vertex rgba from VB color.
585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * VERT_COPY_RGBA: Copy vertex rgba another vertex.
595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * VERT_SAVE_RGBA: Save vertex rgba to a local variable.
605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * VERT_RESTORE_RGBA: Restore vertex rgba from a local variable.
6178742f8e867d8819fca49cc6559ac5ef44fdd83fIan Romanick *   --> Similar for SPEC.
625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *
635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * LOCAL_VARS(n): (At least) define local vars for save/restore rgba.
645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *
655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul */
665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if HAVE_BACK_COLORS
685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define VERT_SET_RGBA( v, c )
695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if !HAVE_SPEC
725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define VERT_SET_SPEC( v, c ) (void) c
735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define VERT_COPY_SPEC( v0, v1 )
745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define VERT_SAVE_SPEC( idx )
755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define VERT_RESTORE_SPEC( idx )
765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if HAVE_BACK_COLORS
775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define VERT_COPY_SPEC1( v )
785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#else
805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if HAVE_BACK_COLORS
815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define VERT_SET_SPEC( v, c )
825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if !HAVE_BACK_COLORS
865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define VERT_COPY_SPEC1( v )
875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define VERT_COPY_RGBA1( v )
885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#ifndef INSANE_VERTICES
915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define VERT_SET_Z(v,val) VERT_Z(v) = val
925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define VERT_Z_ADD(v,val) VERT_Z(v) += val
935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
953b50f004333a922a259a4f733395c27002965dedFelix Kuehling#ifndef REVERSE_DEPTH
963b50f004333a922a259a4f733395c27002965dedFelix Kuehling#define REVERSE_DEPTH 0
973b50f004333a922a259a4f733395c27002965dedFelix Kuehling#endif
983b50f004333a922a259a4f733395c27002965dedFelix Kuehling
99f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca/* disable twostencil for un-aware drivers */
100f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca#ifndef HAVE_STENCIL_TWOSIDE
101f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca#define HAVE_STENCIL_TWOSIDE 0
102f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca#endif
103f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca#ifndef DO_TWOSTENCIL
104f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca#define DO_TWOSTENCIL 0
105f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca#endif
106f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca#ifndef SETUP_STENCIL
107f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca#define SETUP_STENCIL(f)
108f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca#endif
109f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca#ifndef UNSET_STENCIL
110f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca#define UNSET_STENCIL(f)
111f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca#endif
112f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca
1135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if DO_TRI
114f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(triangle)( struct gl_context *ctx, GLuint e0, GLuint e1, GLuint e2 )
1155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
1165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
1175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   VERTEX *v[3];
11839e14d2cffb8627bf8b6587a6d5590f50c6910b0Keith Whitwell   GLfloat offset = 0;
119dc0a1ebc7369da62c2dfbd5ea8dec3273e099725Vinson Lee   GLfloat z[3] = { 0 };
1205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   GLenum mode = GL_FILL;
12139e14d2cffb8627bf8b6587a6d5590f50c6910b0Keith Whitwell   GLuint facing = 0;
1225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   LOCAL_VARS(3);
1235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/*     fprintf(stderr, "%s\n", __FUNCTION__); */
1255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   v[0] = (VERTEX *)GET_VERTEX(e0);
1275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   v[1] = (VERTEX *)GET_VERTEX(e1);
1285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   v[2] = (VERTEX *)GET_VERTEX(e2);
1295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
130f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca   if (DO_TWOSIDE || DO_OFFSET || DO_UNFILLED || DO_TWOSTENCIL)
1315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   {
1325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLfloat ex = VERT_X(v[0]) - VERT_X(v[2]);
1335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLfloat ey = VERT_Y(v[0]) - VERT_Y(v[2]);
1345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLfloat fx = VERT_X(v[1]) - VERT_X(v[2]);
1355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLfloat fy = VERT_Y(v[1]) - VERT_Y(v[2]);
1365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLfloat cc = ex*fy - ey*fx;
1375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
138f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      if (DO_TWOSIDE || DO_UNFILLED || DO_TWOSTENCIL)
1395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      {
1405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 facing = AREA_IS_CCW( cc ) ^ ctx->Polygon._FrontBit;
1415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 if (DO_UNFILLED) {
1435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    if (facing) {
1445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       mode = ctx->Polygon.BackMode;
1455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       if (ctx->Polygon.CullFlag &&
1465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		   ctx->Polygon.CullFaceMode != GL_FRONT) {
1475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  return;
1485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       }
1495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    } else {
1505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       mode = ctx->Polygon.FrontMode;
1515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       if (ctx->Polygon.CullFlag &&
1525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		   ctx->Polygon.CullFaceMode != GL_BACK) {
1535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  return;
1545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       }
1555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    }
1565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
1575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
158e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	 if (DO_TWOSIDE && facing == 1) {
159e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    if (HAVE_BACK_COLORS) {
160e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       if (!DO_FLAT) {
161e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SAVE_RGBA( 0 );
162e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SAVE_RGBA( 1 );
163e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_COPY_RGBA1( v[0] );
164e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_COPY_RGBA1( v[1] );
165e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       }
166e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       VERT_SAVE_RGBA( 2 );
167e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       VERT_COPY_RGBA1( v[2] );
168e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       if (HAVE_SPEC) {
1695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  if (!DO_FLAT) {
170e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SAVE_SPEC( 0 );
171e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SAVE_SPEC( 1 );
172e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_COPY_SPEC1( v[0] );
173e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_COPY_SPEC1( v[1] );
1745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  }
175e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SAVE_SPEC( 2 );
176e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_COPY_SPEC1( v[2] );
1775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       }
178e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    }
179e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    else {
180e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       GLfloat (*vbcolor)[4] = VB->BackfaceColorPtr->data;
181e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       (void) vbcolor;
1825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
183e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       if (!DO_FLAT) {
184e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SAVE_RGBA( 0 );
185e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SAVE_RGBA( 1 );
186e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       }
187e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       VERT_SAVE_RGBA( 2 );
188574f3c7daf755c6b61aee661a1d322e1226d9cbeKeith Whitwell
189e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       if (VB->BackfaceColorPtr->stride) {
190e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  ASSERT(VB->BackfaceColorPtr->stride == 4*sizeof(GLfloat));
191574f3c7daf755c6b61aee661a1d322e1226d9cbeKeith Whitwell
192e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  if (!DO_FLAT) {
193e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_RGBA( v[0], vbcolor[e0] );
194e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_RGBA( v[1], vbcolor[e1] );
195574f3c7daf755c6b61aee661a1d322e1226d9cbeKeith Whitwell		  }
196e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SET_RGBA( v[2], vbcolor[e2] );
197e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       }
198e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       else {
199e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  if (!DO_FLAT) {
200e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_RGBA( v[0], vbcolor[0] );
201e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_RGBA( v[1], vbcolor[0] );
202574f3c7daf755c6b61aee661a1d322e1226d9cbeKeith Whitwell		  }
203e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SET_RGBA( v[2], vbcolor[0] );
204e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       }
2055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
206e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       if (HAVE_SPEC && VB->BackfaceSecondaryColorPtr) {
207e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  GLfloat (*vbspec)[4] = VB->BackfaceSecondaryColorPtr->data;
208e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  ASSERT(VB->BackfaceSecondaryColorPtr->stride == 4*sizeof(GLfloat));
2095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
210e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  if (!DO_FLAT) {
211e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SAVE_SPEC( 0 );
212e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SAVE_SPEC( 1 );
213e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_SPEC( v[0], vbspec[e0] );
214e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_SPEC( v[1], vbspec[e1] );
2155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  }
216e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SAVE_SPEC( 2 );
217e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SET_SPEC( v[2], vbspec[e2] );
2185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       }
219e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    }
2205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
2215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
2225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (DO_OFFSET)
2255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      {
2265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 offset = ctx->Polygon.OffsetUnits * DEPTH_SCALE;
2275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 z[0] = VERT_Z(v[0]);
2285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 z[1] = VERT_Z(v[1]);
2295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 z[2] = VERT_Z(v[2]);
2305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 if (cc * cc > 1e-16) {
2315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLfloat ic	= 1.0 / cc;
2325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLfloat ez	= z[0] - z[2];
2335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLfloat fz	= z[1] - z[2];
2345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLfloat a	= ey*fz - ez*fy;
2355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLfloat b	= ez*fx - ex*fz;
2365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLfloat ac	= a * ic;
2375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLfloat bc	= b * ic;
2385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    if ( ac < 0.0f ) ac = -ac;
2395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    if ( bc < 0.0f ) bc = -bc;
2400c1e96e6d38c0acfd3fe6b4116f2a67f5bf62136Xiang, Haihao	    offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor / ctx->DrawBuffer->_MRD;
2415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
242e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul	 offset *= ctx->DrawBuffer->_MRD * (REVERSE_DEPTH ? -1.0 : 1.0);
2435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
2445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
2455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (DO_FLAT) {
247e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      VERT_SAVE_RGBA( 0 );
248e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      VERT_SAVE_RGBA( 1 );
249e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      VERT_COPY_RGBA( v[0], v[2] );
250e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      VERT_COPY_RGBA( v[1], v[2] );
251e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      if (HAVE_SPEC && VB->AttribPtr[_TNL_ATTRIB_COLOR1]) {
252e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	 VERT_SAVE_SPEC( 0 );
253e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	 VERT_SAVE_SPEC( 1 );
254e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	 VERT_COPY_SPEC( v[0], v[2] );
255e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	 VERT_COPY_SPEC( v[1], v[2] );
256e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      }
2575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
2585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (mode == GL_POINT) {
2605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (DO_OFFSET && ctx->Polygon.OffsetPoint) {
2615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[0], offset);
2625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[1], offset);
2635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[2], offset);
2645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
265f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
266f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         SETUP_STENCIL(facing);
267f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         UNFILLED_TRI( ctx, GL_POINT, e0, e1, e2 );
268f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         UNSET_STENCIL(facing);
269f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      } else {
270f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         UNFILLED_TRI( ctx, GL_POINT, e0, e1, e2 );
271f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      }
2725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else if (mode == GL_LINE) {
2735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (DO_OFFSET && ctx->Polygon.OffsetLine) {
2745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[0], offset);
2755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[1], offset);
2765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[2], offset);
2775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
278f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
279f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         SETUP_STENCIL(facing);
280f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         UNFILLED_TRI( ctx, GL_LINE, e0, e1, e2 );
281f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         UNSET_STENCIL(facing);
282f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      } else {
283f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         UNFILLED_TRI( ctx, GL_LINE, e0, e1, e2 );
284f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      }
2855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
2865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (DO_OFFSET && ctx->Polygon.OffsetFill) {
2875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[0], offset);
2885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[1], offset);
2895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[2], offset);
2905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
291076d609aa3336ce850fd2729faf31cc57a5fb090Ian Romanick      if (DO_UNFILLED) {
2925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 RASTERIZE( GL_TRIANGLES );
293076d609aa3336ce850fd2729faf31cc57a5fb090Ian Romanick      }
294f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
295f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         SETUP_STENCIL(facing);
296f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         TRI( v[0], v[1], v[2] );
297f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         UNSET_STENCIL(facing);
298f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      } else {
299f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         TRI( v[0], v[1], v[2] );
300f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      }
3015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
3025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (DO_OFFSET)
3045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   {
3055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      VERT_SET_Z(v[0], z[0]);
3065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      VERT_SET_Z(v[1], z[1]);
3075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      VERT_SET_Z(v[2], z[2]);
3085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
3095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
310e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick   if (DO_TWOSIDE && facing == 1) {
311e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      if (!DO_FLAT) {
312e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	 VERT_RESTORE_RGBA( 0 );
313e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	 VERT_RESTORE_RGBA( 1 );
314e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      }
315e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      VERT_RESTORE_RGBA( 2 );
316e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      if (HAVE_SPEC) {
3175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 if (!DO_FLAT) {
318e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    VERT_RESTORE_SPEC( 0 );
319e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    VERT_RESTORE_SPEC( 1 );
3205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
321e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	 VERT_RESTORE_SPEC( 2 );
322e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      }
3235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
3245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (DO_FLAT) {
3275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_RESTORE_RGBA( 0 );
3285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_RESTORE_RGBA( 1 );
3290a9187801505130738ae947c69cafa8a1dd118d1Eric Anholt	 if (HAVE_SPEC && VB->AttribPtr[_TNL_ATTRIB_COLOR1]) {
3305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERT_RESTORE_SPEC( 0 );
3315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERT_RESTORE_SPEC( 1 );
3325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
3335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
3345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
3355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
3365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if DO_QUAD
3385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if DO_FULL_QUAD
339f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(quadr)( struct gl_context *ctx,
3405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		       GLuint e0, GLuint e1, GLuint e2, GLuint e3 )
3415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
3425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
3435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   VERTEX *v[4];
34439e14d2cffb8627bf8b6587a6d5590f50c6910b0Keith Whitwell   GLfloat offset = 0;
345dc0a1ebc7369da62c2dfbd5ea8dec3273e099725Vinson Lee   GLfloat z[4] = { 0 };
3465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   GLenum mode = GL_FILL;
34739e14d2cffb8627bf8b6587a6d5590f50c6910b0Keith Whitwell   GLuint facing = 0;
3485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   LOCAL_VARS(4);
3495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   v[0] = (VERTEX *)GET_VERTEX(e0);
3515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   v[1] = (VERTEX *)GET_VERTEX(e1);
3525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   v[2] = (VERTEX *)GET_VERTEX(e2);
3535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   v[3] = (VERTEX *)GET_VERTEX(e3);
3545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
355f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca   if (DO_TWOSIDE || DO_OFFSET || DO_UNFILLED || DO_TWOSTENCIL)
3565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   {
3575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLfloat ex = VERT_X(v[2]) - VERT_X(v[0]);
3585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLfloat ey = VERT_Y(v[2]) - VERT_Y(v[0]);
3595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLfloat fx = VERT_X(v[3]) - VERT_X(v[1]);
3605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLfloat fy = VERT_Y(v[3]) - VERT_Y(v[1]);
3615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLfloat cc = ex*fy - ey*fx;
3625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
363f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      if (DO_TWOSIDE || DO_UNFILLED || DO_TWOSTENCIL)
3645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      {
3655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 facing = AREA_IS_CCW( cc ) ^ ctx->Polygon._FrontBit;
3665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 if (DO_UNFILLED) {
3685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    if (facing) {
3695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       mode = ctx->Polygon.BackMode;
3705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       if (ctx->Polygon.CullFlag &&
3715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		   ctx->Polygon.CullFaceMode != GL_FRONT) {
3725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  return;
3735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       }
3745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    } else {
3755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       mode = ctx->Polygon.FrontMode;
3765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       if (ctx->Polygon.CullFlag &&
3775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		   ctx->Polygon.CullFaceMode != GL_BACK) {
3785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  return;
3795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       }
3805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    }
3815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
3825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
383e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	 if (DO_TWOSIDE && facing == 1) {
384e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    GLfloat (*vbcolor)[4] = VB->BackfaceColorPtr->data;
385e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    (void)vbcolor;
386e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick
387e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    if (HAVE_BACK_COLORS) {
388e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       if (!DO_FLAT) {
389e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SAVE_RGBA( 0 );
390e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SAVE_RGBA( 1 );
391e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SAVE_RGBA( 2 );
392e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_COPY_RGBA1( v[0] );
393e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_COPY_RGBA1( v[1] );
394e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_COPY_RGBA1( v[2] );
395e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       }
396e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       VERT_SAVE_RGBA( 3 );
397e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       VERT_COPY_RGBA1( v[3] );
398e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       if (HAVE_SPEC) {
399e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  if (!DO_FLAT) {
400e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SAVE_SPEC( 0 );
401e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SAVE_SPEC( 1 );
402e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SAVE_SPEC( 2 );
403e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_COPY_SPEC1( v[0] );
404e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_COPY_SPEC1( v[1] );
405e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_COPY_SPEC1( v[2] );
4065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  }
407e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SAVE_SPEC( 3 );
408e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_COPY_SPEC1( v[3] );
409e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       }
410e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    }
411e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    else {
412e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       if (!DO_FLAT) {
413e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SAVE_RGBA( 0 );
414e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SAVE_RGBA( 1 );
415e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SAVE_RGBA( 2 );
416e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       }
417e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       VERT_SAVE_RGBA( 3 );
418e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick
419e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       if (VB->BackfaceColorPtr->stride) {
420e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  if (!DO_FLAT) {
421e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_RGBA( v[0], vbcolor[e0] );
422e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_RGBA( v[1], vbcolor[e1] );
423e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_RGBA( v[2], vbcolor[e2] );
4245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  }
425e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SET_RGBA( v[3], vbcolor[e3] );
4265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       }
4275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       else {
428e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  if (!DO_FLAT) {
429e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_RGBA( v[0], vbcolor[0] );
430e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_RGBA( v[1], vbcolor[0] );
431e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_RGBA( v[2], vbcolor[0] );
432574f3c7daf755c6b61aee661a1d322e1226d9cbeKeith Whitwell		  }
433e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SET_RGBA( v[3], vbcolor[0] );
434e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       }
435e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick
436e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	       if (HAVE_SPEC && VB->BackfaceSecondaryColorPtr) {
437e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  GLfloat (*vbspec)[4] = VB->BackfaceSecondaryColorPtr->data;
438e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  ASSERT(VB->BackfaceSecondaryColorPtr->stride==4*sizeof(GLfloat));
4395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
440e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  if (!DO_FLAT) {
441e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SAVE_SPEC( 0 );
442e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SAVE_SPEC( 1 );
443e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SAVE_SPEC( 2 );
444e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_SPEC( v[0], vbspec[e0] );
445e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_SPEC( v[1], vbspec[e1] );
446e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		     VERT_SET_SPEC( v[2], vbspec[e2] );
447e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  }
448e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SAVE_SPEC( 3 );
449e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick		  VERT_SET_SPEC( v[3], vbspec[e3] );
4505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       }
451e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    }
4525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
4535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
4545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (DO_OFFSET)
4575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      {
4585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 offset = ctx->Polygon.OffsetUnits * DEPTH_SCALE;
4595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 z[0] = VERT_Z(v[0]);
4605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 z[1] = VERT_Z(v[1]);
4615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 z[2] = VERT_Z(v[2]);
4625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 z[3] = VERT_Z(v[3]);
4635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 if (cc * cc > 1e-16) {
4645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLfloat ez = z[2] - z[0];
4655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLfloat fz = z[3] - z[1];
4665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLfloat a	= ey*fz - ez*fy;
4675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLfloat b	= ez*fx - ex*fz;
4685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLfloat ic	= 1.0 / cc;
4695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLfloat ac	= a * ic;
4705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLfloat bc	= b * ic;
4715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    if ( ac < 0.0f ) ac = -ac;
4725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    if ( bc < 0.0f ) bc = -bc;
4730c1e96e6d38c0acfd3fe6b4116f2a67f5bf62136Xiang, Haihao	    offset += MAX2( ac, bc ) * ctx->Polygon.OffsetFactor / ctx->DrawBuffer->_MRD;
4745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
475e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul	 offset *= ctx->DrawBuffer->_MRD * (REVERSE_DEPTH ? -1.0 : 1.0);
4765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
4775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
4785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (DO_FLAT) {
4805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_SAVE_RGBA( 0 );
4815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_SAVE_RGBA( 1 );
4825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_SAVE_RGBA( 2 );
4835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_COPY_RGBA( v[0], v[3] );
4845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_COPY_RGBA( v[1], v[3] );
4855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_COPY_RGBA( v[2], v[3] );
4860a9187801505130738ae947c69cafa8a1dd118d1Eric Anholt	 if (HAVE_SPEC && VB->AttribPtr[_TNL_ATTRIB_COLOR1]) {
4875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERT_SAVE_SPEC( 0 );
4885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERT_SAVE_SPEC( 1 );
4895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERT_SAVE_SPEC( 2 );
4905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERT_COPY_SPEC( v[0], v[3] );
4915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERT_COPY_SPEC( v[1], v[3] );
4925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERT_COPY_SPEC( v[2], v[3] );
4935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
4945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
4955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (mode == GL_POINT) {
4975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (( DO_OFFSET) && ctx->Polygon.OffsetPoint) {
4985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[0], offset);
4995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[1], offset);
5005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[2], offset);
5015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[3], offset);
5025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
503f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
504f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         SETUP_STENCIL(facing);
505f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         UNFILLED_QUAD( ctx, GL_POINT, e0, e1, e2, e3 );
506f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         UNSET_STENCIL(facing);
507f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      } else {
508f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         UNFILLED_QUAD( ctx, GL_POINT, e0, e1, e2, e3 );
509f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      }
5105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else if (mode == GL_LINE) {
5115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (DO_OFFSET && ctx->Polygon.OffsetLine) {
5125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[0], offset);
5135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[1], offset);
5145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[2], offset);
5155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[3], offset);
5165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
517f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
518f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         SETUP_STENCIL(facing);
519f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         UNFILLED_QUAD( ctx, GL_LINE, e0, e1, e2, e3 );
520f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         UNSET_STENCIL(facing);
521f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      } else {
522f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         UNFILLED_QUAD( ctx, GL_LINE, e0, e1, e2, e3 );
523f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      }
5245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
5255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (DO_OFFSET && ctx->Polygon.OffsetFill) {
5265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[0], offset);
5275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[1], offset);
5285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[2], offset);
5295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_Z_ADD(v[3], offset);
5305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
5316cf002c0c2b4025492281840fb24eb2764eccc6fRoland Scheidegger      RASTERIZE( GL_QUADS );
532f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      if (DO_TWOSTENCIL && !HAVE_STENCIL_TWOSIDE && ctx->Stencil.TestTwoSide) {
533f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         SETUP_STENCIL(facing);
534f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         QUAD( (v[0]), (v[1]), (v[2]), (v[3]) );
535f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         UNSET_STENCIL(facing);
536f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      } else {
537f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca         QUAD( (v[0]), (v[1]), (v[2]), (v[3]) );
538f37383c1c6a9cf83c556f2131fab1adef0efc17eDaniel Borca      }
5395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
5405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (DO_OFFSET)
5425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   {
5435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      VERT_SET_Z(v[0], z[0]);
5445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      VERT_SET_Z(v[1], z[1]);
5455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      VERT_SET_Z(v[2], z[2]);
5465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      VERT_SET_Z(v[3], z[3]);
5475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
5485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
549e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick   if (DO_TWOSIDE && facing == 1) {
550e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      if (!DO_FLAT) {
551e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	 VERT_RESTORE_RGBA( 0 );
552e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	 VERT_RESTORE_RGBA( 1 );
553e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	 VERT_RESTORE_RGBA( 2 );
554e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      }
555e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      VERT_RESTORE_RGBA( 3 );
556e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      if (HAVE_SPEC) {
5575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 if (!DO_FLAT) {
558e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    VERT_RESTORE_SPEC( 0 );
559e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    VERT_RESTORE_SPEC( 1 );
560e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	    VERT_RESTORE_SPEC( 2 );
5615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
562e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick	 VERT_RESTORE_SPEC( 3 );
563e00b50c39ad13090c74877a421d10483c3c5bab1Ian Romanick      }
5645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
5655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (DO_FLAT) {
5685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_RESTORE_RGBA( 0 );
5695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_RESTORE_RGBA( 1 );
5705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_RESTORE_RGBA( 2 );
5710a9187801505130738ae947c69cafa8a1dd118d1Eric Anholt	 if (HAVE_SPEC && VB->AttribPtr[_TNL_ATTRIB_COLOR1]) {
5725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERT_RESTORE_SPEC( 0 );
5735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERT_RESTORE_SPEC( 1 );
5745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERT_RESTORE_SPEC( 2 );
5755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
5765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
5775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
5785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#else
579f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(quadr)( struct gl_context *ctx, GLuint e0,
5805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		       GLuint e1, GLuint e2, GLuint e3 )
5815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
5825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (DO_UNFILLED) {
5835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
5845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLubyte ef1 = VB->EdgeFlag[e1];
5855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLubyte ef3 = VB->EdgeFlag[e3];
5865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      VB->EdgeFlag[e1] = 0;
5875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      TAG(triangle)( ctx, e0, e1, e3 );
5885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      VB->EdgeFlag[e1] = ef1;
5895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      VB->EdgeFlag[e3] = 0;
5905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      TAG(triangle)( ctx, e1, e2, e3 );
5915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      VB->EdgeFlag[e3] = ef3;
5925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
5935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      TAG(triangle)( ctx, e0, e1, e3 );
5945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      TAG(triangle)( ctx, e1, e2, e3 );
5955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
5965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
5975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
5985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
5995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if DO_LINE
601f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(line)( struct gl_context *ctx, GLuint e0, GLuint e1 )
6025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
603ae0eaf93e092ac8e8b1c98f3e986de96940663faKeith Whitwell   struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;
6045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   VERTEX *v[2];
6055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   LOCAL_VARS(2);
6065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   v[0] = (VERTEX *)GET_VERTEX(e0);
6085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   v[1] = (VERTEX *)GET_VERTEX(e1);
6095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (DO_FLAT) {
6115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_SAVE_RGBA( 0 );
6125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_COPY_RGBA( v[0], v[1] );
6130a9187801505130738ae947c69cafa8a1dd118d1Eric Anholt	 if (HAVE_SPEC && VB->AttribPtr[_TNL_ATTRIB_COLOR1]) {
6145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERT_SAVE_SPEC( 0 );
6155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERT_COPY_SPEC( v[0], v[1] );
6165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
6175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
6185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   LINE( v[0], v[1] );
6205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (DO_FLAT) {
6225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 VERT_RESTORE_RGBA( 0 );
6235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6240a9187801505130738ae947c69cafa8a1dd118d1Eric Anholt	 if (HAVE_SPEC && VB->AttribPtr[_TNL_ATTRIB_COLOR1]) {
6255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERT_RESTORE_SPEC( 0 );
6265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
6275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
6285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
6295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
6305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if DO_POINTS
632f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(points)( struct gl_context *ctx, GLuint first, GLuint last )
6335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
6345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
635fbdd7a5e7487849bfe06a7bef68b4dad75f5d58cDave Airlie   GLuint i;
6365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   LOCAL_VARS(1);
6375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (VB->Elts == 0) {
6395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for ( i = first ; i < last ; i++ ) {
6405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 if ( VB->ClipMask[i] == 0 ) {
6415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERTEX *v = (VERTEX *)GET_VERTEX(i);
6425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    POINT( v );
6435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
6445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
6455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
6465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for ( i = first ; i < last ; i++ ) {
6475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 GLuint e = VB->Elts[i];
6485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 if ( VB->ClipMask[e] == 0 ) {
6495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    VERTEX *v = (VERTEX *)GET_VERTEX(e);
6505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    POINT( v );
6515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
6525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
6535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
6545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
6555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
6565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paulstatic void TAG(init)( void )
6585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
6595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if DO_QUAD
660f30e4af73405aad3ec29b7337a3a0177e3fbe715Daniel Zhu   TAB[IND].quad = TAG(quadr);
6615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
6625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if DO_TRI
6635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAB[IND].triangle = TAG(triangle);
6645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
6655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if DO_LINE
6665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAB[IND].line = TAG(line);
6675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
6685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if DO_POINTS
6695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAB[IND].points = TAG(points);
6705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
6715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
6725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#undef IND
6745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#undef TAG
6755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if HAVE_BACK_COLORS
6775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#undef VERT_SET_RGBA
6785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
6795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if !HAVE_SPEC
6815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#undef VERT_SET_SPEC
6825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#undef VERT_COPY_SPEC
6835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#undef VERT_SAVE_SPEC
6845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#undef VERT_RESTORE_SPEC
6855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if HAVE_BACK_COLORS
6865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#undef VERT_COPY_SPEC1
6875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
6885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#else
6895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if HAVE_BACK_COLORS
6905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#undef VERT_SET_SPEC
6915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
6925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
6935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if !HAVE_BACK_COLORS
6955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#undef VERT_COPY_SPEC1
6965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#undef VERT_COPY_RGBA1
6975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
6985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#ifndef INSANE_VERTICES
7005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#undef VERT_SET_Z
7015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#undef VERT_Z_ADD
7025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
703