15df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/*
25df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * Mesa 3-D graphics library
3a1a6ac4af4ba5b1da7c768d892b84cb1204c4c7fBrian Paul * Version:  6.5.1
45df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *
5a1a6ac4af4ba5b1da7c768d892b84cb1204c4c7fBrian Paul * Copyright (C) 1999-2006  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
29a1a6ac4af4ba5b1da7c768d892b84cb1204c4c7fBrian Paul/**
30a1a6ac4af4ba5b1da7c768d892b84cb1204c4c7fBrian Paul * \file t_dd_dmatmp.h
31a1a6ac4af4ba5b1da7c768d892b84cb1204c4c7fBrian Paul * Template for render stages which build and emit vertices directly
325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * to fixed-size dma buffers.  Useful for rendering strips and other
335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * native primitives where clipping and per-vertex tweaks such as
345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * those in t_dd_tritmp.h are not required.
355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *
365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * Produces code for both inline triangles and indexed triangles.
375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * Where various primitive types are unaccelerated by hardware, the
385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * code attempts to fallback to other primitive types (quadstrips to
395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * tristrips, lineloops to linestrips), or to indexed vertices.
405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul */
415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if !defined(HAVE_TRIANGLES)
435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#error "must have at least triangles to use render template"
445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if !HAVE_ELTS
47844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell#define ELTS_VARS(buf)
48844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell#define ALLOC_ELTS(nr) 0
495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define EMIT_ELT( offset, elt )
505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define EMIT_TWO_ELTS( offset, elt0, elt1 )
515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define INCR_ELTS( nr )
525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define ELT_INIT(prim)
535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define GET_CURRENT_VB_MAX_ELTS() 0
545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define GET_SUBSEQUENT_VB_MAX_ELTS() 0
555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define RELEASE_ELT_VERTS()
565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define EMIT_INDEXED_VERTS( ctx, start, count )
575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#ifndef EMIT_TWO_ELTS
605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#define EMIT_TWO_ELTS( offset, elt0, elt1 )	\
615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Pauldo { 						\
625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   EMIT_ELT( offset, elt0 ); 			\
635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   EMIT_ELT( offset+1, elt1 ); 			\
645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul} while (0)
655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/**********************************************************************/
695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/*                  Render whole begin/end objects                    */
705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/**********************************************************************/
715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if (HAVE_ELTS)
76f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void *TAG(emit_elts)( struct gl_context *ctx, GLuint *elts, GLuint nr,
77844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell			     void *buf)
785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   GLint i;
805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   LOCAL_VARS;
81844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell   ELTS_VARS(buf);
825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
83844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell   for ( i = 0 ; i+1 < nr ; i+=2, elts += 2 ) {
845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      EMIT_TWO_ELTS( 0, elts[0], elts[1] );
855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      INCR_ELTS( 2 );
865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
87844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
88844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell   if (i < nr) {
89844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      EMIT_ELT( 0, elts[0] );
90844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      INCR_ELTS( 1 );
91844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell   }
92844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
93844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell   return (void *)ELTPTR;
945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
97f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic __inline void *TAG(emit_verts)( struct gl_context *ctx, GLuint start,
98844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell				     GLuint count, void *buf )
99844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell{
100844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell   return EMIT_VERTS(ctx, start, count, buf);
101844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell}
1025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/***********************************************************************
1045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *                    Render non-indexed primitives.
1055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul ***********************************************************************/
1065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
107f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_points_verts)( struct gl_context *ctx,
1085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				      GLuint start,
1095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				      GLuint count,
1105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				      GLuint flags )
1115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
1125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_POINTS) {
1135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
1145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
115d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      int currentsz;
1165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
1175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      INIT( GL_POINTS );
1195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
120d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      currentsz = GET_CURRENT_VB_MAX_VERTS();
1215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8)
1225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
1235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for (j = start; j < count; j += nr ) {
1255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j );
126844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 TAG(emit_verts)( ctx, j, nr, ALLOC_VERTS(nr) );
1275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
1285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
1295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
131844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
132844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
1335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
1345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
1355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
136f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_lines_verts)( struct gl_context *ctx,
1375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				     GLuint start,
1385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				     GLuint count,
1395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				     GLuint flags )
1405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
1415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_LINES) {
1425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
1435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
144d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      int currentsz;
1455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
1465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      INIT( GL_LINES );
1485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Emit whole number of lines in total and in each buffer:
1505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
1515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      count -= (count-start) & 1;
152d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      currentsz = GET_CURRENT_VB_MAX_VERTS();
1535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz -= currentsz & 1;
1545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      dmasz -= dmasz & 1;
1555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8)
1575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
1585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for (j = start; j < count; j += nr ) {
1605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j );
161844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 TAG(emit_verts)( ctx, j, nr, ALLOC_VERTS(nr) );
1625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
1635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
1645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
166844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
167844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
1685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
1695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
1705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
172f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_line_strip_verts)( struct gl_context *ctx,
1735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					  GLuint start,
1745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					  GLuint count,
1755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					  GLuint flags )
1765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
1775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_LINE_STRIPS) {
1785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
1795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
180d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      int currentsz;
1815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
1825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      INIT( GL_LINE_STRIP );
1845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
185d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      currentsz = GET_CURRENT_VB_MAX_VERTS();
1865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8)
1875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
1885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for (j = start; j + 1 < count; j += nr - 1 ) {
1905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j );
191844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 TAG(emit_verts)( ctx, j, nr, ALLOC_VERTS(nr) );
1925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
1935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
1945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
195844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
1965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
198844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
199844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
2005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
2015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
2025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
204f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_line_loop_verts)( struct gl_context *ctx,
2055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint start,
2065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint count,
2075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint flags )
2085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
2095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_LINE_STRIPS) {
2105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
2115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
212d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      int currentsz;
2135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
2145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      INIT( GL_LINE_STRIP );
2165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (flags & PRIM_BEGIN)
2185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 j = start;
2195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      else
2205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 j = start + 1;
2215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Ensure last vertex won't wrap buffers:
2235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
224d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      currentsz = GET_CURRENT_VB_MAX_VERTS();
2255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz--;
2265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      dmasz--;
2275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8) {
2295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
2305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
2315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (j + 1 < count) {
2335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 for ( ; j + 1 < count; j += nr - 1 ) {
2345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    nr = MIN2( currentsz, count - j );
235844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
236844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    if (j + nr >= count &&
237844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell		start < count - 1 &&
238844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell		(flags & PRIM_END))
239844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    {
240844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       void *tmp;
241844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       tmp = ALLOC_VERTS(nr+1);
242844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       tmp = TAG(emit_verts)( ctx, j, nr, tmp );
243844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       tmp = TAG(emit_verts)( ctx, start, 1, tmp );
24481dcf8bdf23250dc04dd60994aaede0eb5c2dda7Vinson Lee	       (void) tmp;
245844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    }
246844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    else {
247844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       TAG(emit_verts)( ctx, j, nr, ALLOC_VERTS(nr) );
248844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       currentsz = dmasz;
249844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    }
2505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
2515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
2535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      else if (start + 1 < count && (flags & PRIM_END)) {
254844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 void *tmp;
255844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = ALLOC_VERTS(2);
256844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = TAG(emit_verts)( ctx, start+1, 1, tmp );
257844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = TAG(emit_verts)( ctx, start, 1, tmp );
258c2cee7741e877bb78480eae8b8b5bfb55b42158cVinson Lee	 (void) tmp;
2595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
2605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
261844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
2625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
264844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
265844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
2665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
2675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
2685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
270f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_triangles_verts)( struct gl_context *ctx,
2715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint start,
2725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint count,
2735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint flags )
2745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
2755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   LOCAL_VARS;
2765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   int dmasz = (GET_SUBSEQUENT_VB_MAX_VERTS()/3) * 3;
277d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell   int currentsz;
2785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   GLuint j, nr;
2795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   INIT(GL_TRIANGLES);
2815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
282d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell   currentsz = (GET_CURRENT_VB_MAX_VERTS()/3) * 3;
283d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell
2845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   /* Emit whole number of tris in total.  dmasz is already a multiple
2855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    * of 3.
2865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    */
2875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   count -= (count-start)%3;
2885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (currentsz < 8)
2905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = dmasz;
2915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   for (j = start; j < count; j += nr) {
2935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      nr = MIN2( currentsz, count - j );
294844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      TAG(emit_verts)( ctx, j, nr, ALLOC_VERTS(nr) );
2955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = dmasz;
2965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
2975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
2985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
2995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
301f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_tri_strip_verts)( struct gl_context *ctx,
3025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint start,
3035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint count,
3045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint flags )
3055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
3065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_TRI_STRIPS) {
3075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
3085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
3095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
3105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int currentsz;
3115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      INIT(GL_TRIANGLE_STRIP);
3135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = GET_CURRENT_VB_MAX_VERTS();
3155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8) {
3175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
3185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
3195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* From here on emit even numbers of tris when wrapping over buffers:
3215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
3225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      dmasz -= (dmasz & 1);
3235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz -= (currentsz & 1);
3245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for (j = start ; j + 2 < count; j += nr - 2 ) {
3265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j );
327844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 TAG(emit_verts)( ctx, j, nr, ALLOC_VERTS(nr) );
3285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
3295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
3305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
331844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
3325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
334844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
335844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
3365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
3375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
3385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
339f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_tri_fan_verts)( struct gl_context *ctx,
3405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				       GLuint start,
3415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				       GLuint count,
3425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				       GLuint flags )
3435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
3445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_TRI_FANS) {
3455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
3465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
3475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
348d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      int currentsz;
3495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      INIT(GL_TRIANGLE_FAN);
3515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
352d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      currentsz = GET_CURRENT_VB_MAX_VERTS();
3535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8) {
3545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
3555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
3565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
35736ff43b596f3bc122f2379b2c161ff9d4e05eeecKeith Whitwell      for (j = start + 1 ; j + 1 < count; j += nr - 2 ) {
358844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 void *tmp;
3595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j + 1 );
360844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = ALLOC_VERTS( nr );
361844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = TAG(emit_verts)( ctx, start, 1, tmp );
362844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = TAG(emit_verts)( ctx, j, nr - 1, tmp );
3637d529736b9a07ddd5d8127c56cc25e5f6f5f2c12Vinson Lee	 (void) tmp;
3645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
3655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
3665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
367844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
3685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
3695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   else {
3705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Could write code to emit these as indexed vertices (for the
3715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       * g400, for instance).
3725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
373844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
374844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
3755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
3765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
3775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
379f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_poly_verts)( struct gl_context *ctx,
3805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				    GLuint start,
3815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				    GLuint count,
3825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				    GLuint flags )
3835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
3845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_POLYGONS) {
3855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
3865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
3875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
388d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      int currentsz;
3895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
3905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      INIT(GL_POLYGON);
3915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
392d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      currentsz = GET_CURRENT_VB_MAX_VERTS();
3935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8) {
3945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
3955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
3965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
39736ff43b596f3bc122f2379b2c161ff9d4e05eeecKeith Whitwell      for (j = start + 1 ; j + 1 < count ; j += nr - 2 ) {
398844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 void *tmp;
3995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j + 1 );
400844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = ALLOC_VERTS( nr );
401844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = TAG(emit_verts)( ctx, start, 1, tmp );
402844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = TAG(emit_verts)( ctx, j, nr - 1, tmp );
403de9132f2740d3959af548e36e9b280e9853e59b6Vinson Lee	 (void) tmp;
4045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
4055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
4065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
407844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
4085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
409a1a6ac4af4ba5b1da7c768d892b84cb1204c4c7fBrian Paul   else if (HAVE_TRI_FANS && ctx->Light.ShadeModel == GL_SMOOTH) {
4105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      TAG(render_tri_fan_verts)( ctx, start, count, flags );
4115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
412844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
413844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
4145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
4155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
4165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
417f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_quad_strip_verts)( struct gl_context *ctx,
4185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					  GLuint start,
4195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					  GLuint count,
4205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					  GLuint flags )
4215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
4225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   GLuint j, nr;
4235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_QUAD_STRIPS) {
4255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
4265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
4275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
4285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int currentsz;
4295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      INIT(GL_QUAD_STRIP);
4315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = GET_CURRENT_VB_MAX_VERTS();
4335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8) {
4345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
4355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
4365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      dmasz -= (dmasz & 2);
4385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz -= (currentsz & 2);
4395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for (j = start ; j + 3 < count; j += nr - 2 ) {
4415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j );
442844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 TAG(emit_verts)( ctx, j, nr, ALLOC_VERTS(nr) );
4435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
4445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
4455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
446844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
4475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
44899fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell   } else if (HAVE_TRI_STRIPS &&
449a1a6ac4af4ba5b1da7c768d892b84cb1204c4c7fBrian Paul	      ctx->Light.ShadeModel == GL_FLAT &&
4500a9187801505130738ae947c69cafa8a1dd118d1Eric Anholt	      TNL_CONTEXT(ctx)->vb.AttribPtr[_TNL_ATTRIB_COLOR0]->stride) {
451844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      if (HAVE_ELTS) {
4525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 LOCAL_VARS;
4535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
4545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 int currentsz;
4555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 GLuint j, nr;
4565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
457844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell         EMIT_INDEXED_VERTS( ctx, start, count );
458844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
4595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 /* Simulate flat-shaded quadstrips using indexed vertices:
4605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	  */
4615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 ELT_INIT( GL_TRIANGLES );
4625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = GET_CURRENT_VB_MAX_ELTS();
4645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 /* Emit whole number of quads in total, and in each buffer.
4665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	  */
4675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 dmasz -= dmasz & 1;
4685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 count -= (count-start) & 1;
4695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz -= currentsz & 1;
4705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 if (currentsz < 12)
4725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    currentsz = dmasz;
4735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = currentsz/6*2;
4755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 dmasz = dmasz/6*2;
4765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 for (j = start; j + 3 < count; j += nr - 2 ) {
4785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    nr = MIN2( currentsz, count - j );
4795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    if (nr >= 4) {
4805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       GLint quads = (nr/2)-1;
4815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       GLint i;
482844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       ELTS_VARS( ALLOC_ELTS( quads*6 ) );
4835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       for ( i = j-start ; i < j-start+quads*2 ; i+=2 ) {
4855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  EMIT_TWO_ELTS( 0, (i+0), (i+1) );
4865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  EMIT_TWO_ELTS( 2, (i+2), (i+1) );
4875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  EMIT_TWO_ELTS( 4, (i+3), (i+2) );
4885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  INCR_ELTS( 6 );
4895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       }
4905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
491844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       FLUSH();
4925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    }
4935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    currentsz = dmasz;
4945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
4955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
4965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 RELEASE_ELT_VERTS();
497844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 FLUSH();
4985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
4995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      else {
50099fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell	 /* Vertices won't fit in a single buffer or elts not
50199fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell	  * available - should never happen.
5025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	  */
503844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
504844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 return;
5055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
5065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
5075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   else if (HAVE_TRI_STRIPS) {
5085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
5095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_VERTS();
510d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      int currentsz;
5115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Emit smooth-shaded quadstrips as tristrips:
5135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
514844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
5155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      INIT( GL_TRIANGLE_STRIP );
5165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Emit whole number of quads in total, and in each buffer.
5185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
5195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      dmasz -= dmasz & 1;
520d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      currentsz = GET_CURRENT_VB_MAX_VERTS();
5215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz -= currentsz & 1;
5225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      count -= (count-start) & 1;
5235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8) {
5255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
5265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
5275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for (j = start; j + 3 < count; j += nr - 2 ) {
5295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j );
530844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 TAG(emit_verts)( ctx, j, nr, ALLOC_VERTS(nr) );
5315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
5325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
5335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
534844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
5355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
537844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
538844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
5395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
5405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
5415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
543f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_quads_verts)( struct gl_context *ctx,
5445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				     GLuint start,
5455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				     GLuint count,
5465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				     GLuint flags )
5475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
5485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_QUADS) {
5495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
5505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = (GET_SUBSEQUENT_VB_MAX_VERTS()/4) * 4;
551d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      int currentsz;
5525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
5535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      INIT(GL_QUADS);
5555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Emit whole number of quads in total.  dmasz is already a multiple
5575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       * of 4.
5585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
5595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      count -= (count-start)%4;
5605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
561d8be4a54fad35da25a2f29a5b327192eeb04d014Keith Whitwell      currentsz = (GET_CURRENT_VB_MAX_VERTS()/4) * 4;
5625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8)
5635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul         currentsz = dmasz;
5645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for (j = start; j < count; j += nr) {
5665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul         nr = MIN2( currentsz, count - j );
567844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell         TAG(emit_verts)( ctx, j, nr, ALLOC_VERTS(nr) );
5685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul         currentsz = dmasz;
5695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
57099fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell   }
57199fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell   else if (HAVE_ELTS) {
5725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Hardware doesn't have a quad primitive type -- try to
5735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       * simulate it using indexed vertices and the triangle
5745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       * primitive:
5755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
5765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
5775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
5785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int currentsz;
5795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
5805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
581844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      EMIT_INDEXED_VERTS( ctx, start, count );
582844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
583844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
5845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      ELT_INIT( GL_TRIANGLES );
5855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = GET_CURRENT_VB_MAX_ELTS();
5865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Emit whole number of quads in total, and in each buffer.
5885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
5895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      dmasz -= dmasz & 3;
5905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      count -= (count-start) & 3;
5915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz -= currentsz & 3;
5925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Adjust for rendering as triangles:
5945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
5955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = currentsz/6*4;
5965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      dmasz = dmasz/6*4;
5975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
5985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8)
5995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
6005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for (j = start; j < count; j += nr ) {
6025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j );
6035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 if (nr >= 4) {
6045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLint quads = nr/4;
6055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLint i;
606844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    ELTS_VARS( ALLOC_ELTS( quads*6 ) );
6075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    for ( i = j-start ; i < j-start+quads*4 ; i+=4 ) {
6095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       EMIT_TWO_ELTS( 0, (i+0), (i+1) );
6105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       EMIT_TWO_ELTS( 2, (i+3), (i+1) );
6115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       EMIT_TWO_ELTS( 4, (i+2), (i+3) );
6125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       INCR_ELTS( 6 );
6135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    }
6145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
615844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    FLUSH();
6165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
6175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
6185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
6195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      RELEASE_ELT_VERTS();
6215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
62299fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell   else if (HAVE_TRIANGLES) {
62399fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell      /* Hardware doesn't have a quad primitive type -- try to
62499fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell       * simulate it using triangle primitive.  This is a win for
62599fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell       * gears, but is it useful in the broader world?
62699fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell       */
62799fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell      LOCAL_VARS;
62899fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell      GLuint j;
62999fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell
63099fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell      INIT(GL_TRIANGLES);
63199fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell
632b1d322a1e76f27a22b4c876ef96655728f4de692Keith Whitwell      for (j = start; j < count-3; j += 4) {
63399fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell	 void *tmp = ALLOC_VERTS( 6 );
63499fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell	 /* Send v0, v1, v3
63599fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell	  */
63699fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell	 tmp = EMIT_VERTS(ctx, j,     2, tmp);
63799fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell	 tmp = EMIT_VERTS(ctx, j + 3, 1, tmp);
63899fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell	 /* Send v1, v2, v3
63999fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell	  */
64099fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell	 tmp = EMIT_VERTS(ctx, j + 1, 3, tmp);
641c1d361bd0b3570811ca4e49d09d3282aaa5cbe01Vinson Lee	 (void) tmp;
64299fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell      }
64399fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell   }
6445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   else {
64599fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell      /* Vertices won't fit in a single buffer, should never happen.
6465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
647844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
648844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
6495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
6505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
6515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
652f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_noop)( struct gl_context *ctx,
6535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul			      GLuint start,
6545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul			      GLuint count,
6555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul			      GLuint flags )
6565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
6575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
6585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6623d38361b718d490e1e7fda64519952ec887cd149Keith Whitwellstatic tnl_render_func TAG(render_tab_verts)[GL_POLYGON+2] =
6635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
6645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_points_verts),
6655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_lines_verts),
6665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_line_loop_verts),
6675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_line_strip_verts),
6685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_triangles_verts),
6695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_tri_strip_verts),
6705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_tri_fan_verts),
6715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_quads_verts),
6725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_quad_strip_verts),
6735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_poly_verts),
6745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_noop),
6755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul};
6765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/****************************************************************************
6795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul *                 Render elts using hardware indexed verts                 *
6805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul ****************************************************************************/
6815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#if (HAVE_ELTS)
683f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_points_elts)( struct gl_context *ctx,
6845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				     GLuint start,
6855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				     GLuint count,
6865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				     GLuint flags )
6875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
6885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_POINTS) {
6895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
6905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
6915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int currentsz;
6925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
6935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
6945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      ELT_INIT( GL_POINTS );
6965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
6975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = GET_CURRENT_VB_MAX_ELTS();
6985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8)
6995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
7005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for (j = start; j < count; j += nr ) {
7025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j );
703844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 TAG(emit_elts)( ctx, elts+j, nr, ALLOC_ELTS(nr) );
704844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 FLUSH();
7055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
7065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
7075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
708844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
709844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
7105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
7115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
7125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
715f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_lines_elts)( struct gl_context *ctx,
7165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				    GLuint start,
7175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				    GLuint count,
7185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				    GLuint flags )
7195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
7205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_LINES) {
7215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
7225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
7235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int currentsz;
7245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
7255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
7265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      ELT_INIT( GL_LINES );
7285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Emit whole number of lines in total and in each buffer:
7305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
7315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      count -= (count-start) & 1;
7325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz -= currentsz & 1;
7335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      dmasz -= dmasz & 1;
7345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = GET_CURRENT_VB_MAX_ELTS();
7365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8)
7375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
7385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for (j = start; j < count; j += nr ) {
7405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j );
741844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 TAG(emit_elts)( ctx, elts+j, nr, ALLOC_ELTS(nr) );
742844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 FLUSH();
7435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
7445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
7455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
746844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
747844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
7485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
7495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
7505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
752f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_line_strip_elts)( struct gl_context *ctx,
7535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint start,
7545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint count,
7555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint flags )
7565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
7575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_LINE_STRIPS) {
7585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
7595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
7605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int currentsz;
7615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
7625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
7635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
764844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH(); /* always a new primitive */
7655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      ELT_INIT( GL_LINE_STRIP );
7665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = GET_CURRENT_VB_MAX_ELTS();
7685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8)
7695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
7705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for (j = start; j + 1 < count; j += nr - 1 ) {
7725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j );
773844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 TAG(emit_elts)( ctx, elts+j, nr, ALLOC_ELTS(nr) );
774844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 FLUSH();
7755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
7765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
7775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
7785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* TODO: Try to emit as indexed lines.
7795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
780844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
781844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
7825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
7835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
7845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
7855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
786f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_line_loop_elts)( struct gl_context *ctx,
7875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					GLuint start,
7885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					GLuint count,
7895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					GLuint flags )
7905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
7915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_LINE_STRIPS) {
7925df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
7935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
7945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int currentsz;
7955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
7965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
7975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
798844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
7995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      ELT_INIT( GL_LINE_STRIP );
8005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
8015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (flags & PRIM_BEGIN)
8025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 j = start;
8035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      else
8045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 j = start + 1;
8055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
8065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = GET_CURRENT_VB_MAX_ELTS();
8075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8) {
8085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
8095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
8105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
8115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Ensure last vertex doesn't wrap:
8125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
8135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz--;
8145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      dmasz--;
8155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
816844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      if (j + 1 < count) {
817844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 for ( ; j + 1 < count; j += nr - 1 ) {
818844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    nr = MIN2( currentsz, count - j );
8195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
820844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    if (j + nr >= count &&
821844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell		start < count - 1 &&
822844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell		(flags & PRIM_END))
823844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    {
824844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       void *tmp;
825844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       tmp = ALLOC_ELTS(nr+1);
826844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       tmp = TAG(emit_elts)( ctx, elts+j, nr, tmp );
827844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       tmp = TAG(emit_elts)( ctx, elts+start, 1, tmp );
8289dc018618d024cfbf1f342b0141bb6aab21f41b1Vinson Lee	       (void) tmp;
829844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    }
830844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    else {
831844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       TAG(emit_elts)( ctx, elts+j, nr, ALLOC_ELTS(nr) );
832844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       currentsz = dmasz;
833844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    }
834844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 }
8355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
836844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      }
837844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      else if (start + 1 < count && (flags & PRIM_END)) {
838844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 void *tmp;
839844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = ALLOC_ELTS(2);
840844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = TAG(emit_elts)( ctx, elts+start+1, 1, tmp );
841844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = TAG(emit_elts)( ctx, elts+start, 1, tmp );
8429dc018618d024cfbf1f342b0141bb6aab21f41b1Vinson Lee	 (void) tmp;
843844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      }
844844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
845844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
8465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
8475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* TODO: Try to emit as indexed lines */
848844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
849844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
8505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
8515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
8525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
8535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
8545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul/* For verts, we still eliminate the copy from main memory to dma
8555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * buffers.  For elts, this is probably no better (worse?) than the
8565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul * standard path.
8575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul */
858f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_triangles_elts)( struct gl_context *ctx,
8595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					GLuint start,
8605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					GLuint count,
8615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					GLuint flags )
8625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
8635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   LOCAL_VARS;
8645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
8655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS()/3*3;
8665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   int currentsz;
8675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   GLuint j, nr;
8685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
869844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell   FLUSH();
8705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   ELT_INIT( GL_TRIANGLES );
8715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
8725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   currentsz = GET_CURRENT_VB_MAX_ELTS();
8735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
8745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   /* Emit whole number of tris in total.  dmasz is already a multiple
8755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    * of 3.
8765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul    */
8775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   count -= (count-start)%3;
8785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   currentsz -= currentsz%3;
8795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (currentsz < 8)
8805df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = dmasz;
8815df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
8825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   for (j = start; j < count; j += nr) {
8835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      nr = MIN2( currentsz, count - j );
884844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      TAG(emit_elts)( ctx, elts+j, nr, ALLOC_ELTS(nr) );
885844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
8865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = dmasz;
8875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
8885df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
8895df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
8905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
8915df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
892f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_tri_strip_elts)( struct gl_context *ctx,
8935df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					GLuint start,
8945df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					GLuint count,
8955df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					GLuint flags )
8965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
8975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_TRI_STRIPS) {
8985df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
8995df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
9005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
9015df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
9025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int currentsz;
9035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
904844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
9055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      ELT_INIT( GL_TRIANGLE_STRIP );
9065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
9075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = GET_CURRENT_VB_MAX_ELTS();
9085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8) {
9095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
9105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
9115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
9125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Keep the same winding over multiple buffers:
9135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
9145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      dmasz -= (dmasz & 1);
9155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz -= (currentsz & 1);
9165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
9175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for (j = start ; j + 2 < count; j += nr - 2 ) {
9185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j );
919844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 TAG(emit_elts)( ctx, elts+j, nr, ALLOC_ELTS(nr) );
920844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 FLUSH();
9215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
9225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
9235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
9245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* TODO: try to emit as indexed triangles */
925844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
926844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
9275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
9285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
9295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
930f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_tri_fan_elts)( struct gl_context *ctx,
9315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				      GLuint start,
9325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				      GLuint count,
9335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				      GLuint flags )
9345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
9355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_TRI_FANS) {
9365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
9375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
9385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
9395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
9405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int currentsz;
9415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
942844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
9435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      ELT_INIT( GL_TRIANGLE_FAN );
9445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
9455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = GET_CURRENT_VB_MAX_ELTS();
9465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8) {
9475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
9485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
9495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
95036ff43b596f3bc122f2379b2c161ff9d4e05eeecKeith Whitwell      for (j = start + 1 ; j + 1 < count; j += nr - 2 ) {
951844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 void *tmp;
9525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j + 1 );
953844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = ALLOC_ELTS( nr );
954844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = TAG(emit_elts)( ctx, elts+start, 1, tmp );
955844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = TAG(emit_elts)( ctx, elts+j, nr - 1, tmp );
956af4e4a73f78cb5ccb5b0295a4683b2eae5325d8fVinson Lee	 (void) tmp;
957844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 FLUSH();
9585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
9595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
9605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
9615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* TODO: try to emit as indexed triangles */
962844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
963844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
9645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
9655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
9665df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
9675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
968f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_poly_elts)( struct gl_context *ctx,
9695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				   GLuint start,
9705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				   GLuint count,
9715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				   GLuint flags )
9725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
973844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell   if (HAVE_POLYGONS) {
9745df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
9755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
9765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
9775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
9785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int currentsz;
9795df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
980844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
981844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      ELT_INIT( GL_POLYGON );
9825df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
9835df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = GET_CURRENT_VB_MAX_ELTS();
9845df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8) {
9855df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
9865df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
9875df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
98836ff43b596f3bc122f2379b2c161ff9d4e05eeecKeith Whitwell      for (j = start + 1 ; j + 1 < count; j += nr - 2 ) {
989844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 void *tmp;
9905df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j + 1 );
991844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = ALLOC_ELTS( nr );
992844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = TAG(emit_elts)( ctx, elts+start, 1, tmp );
993844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 tmp = TAG(emit_elts)( ctx, elts+j, nr - 1, tmp );
99420590b97336c4ebe5d2bcee51d66820e1e5d26c8Vinson Lee	 (void) tmp;
995844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 FLUSH();
9965df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
9975df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
9980e6ef1b1cdb546dfe6f36b7eb3e4a9223ec01ae4Eric Anholt   } else if (HAVE_TRI_FANS && ctx->Light.ShadeModel == GL_SMOOTH) {
999844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      TAG(render_tri_fan_verts)( ctx, start, count, flags );
10005df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
1001844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      fprintf(stderr, "%s - cannot draw primitive\n", __FUNCTION__);
1002844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return;
10035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
10045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
10055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1006f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_quad_strip_elts)( struct gl_context *ctx,
10075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint start,
10085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint count,
10095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul					 GLuint flags )
10105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
10115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   if (HAVE_QUAD_STRIPS && 0) {
10125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
10135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   else if (HAVE_TRI_STRIPS) {
10145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
10155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
10165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
10175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int currentsz;
10185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
10195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1020844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
10215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = GET_CURRENT_VB_MAX_ELTS();
10225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
10235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Emit whole number of quads in total, and in each buffer.
10245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
10255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      dmasz -= dmasz & 1;
10265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      count -= (count-start) & 1;
10275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz -= currentsz & 1;
10285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
10295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 12)
10305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
10315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1032a1a6ac4af4ba5b1da7c768d892b84cb1204c4c7fBrian Paul      if (ctx->Light.ShadeModel == GL_FLAT) {
10335df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 ELT_INIT( GL_TRIANGLES );
10345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
10355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = currentsz/6*2;
10365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 dmasz = dmasz/6*2;
10375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
10385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 for (j = start; j + 3 < count; j += nr - 2 ) {
10395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    nr = MIN2( currentsz, count - j );
10405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
10415df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    if (nr >= 4)
10425df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    {
10435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       GLint i;
10445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       GLint quads = (nr/2)-1;
10453152b1586cfdb06df204c5291db7b0f3850d8cb9Ville Syrjala	       ELTS_VARS( ALLOC_ELTS( quads*6 ) );
10465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
10475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       for ( i = j-start ; i < j-start+quads ; i++, elts += 2 ) {
10485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  EMIT_TWO_ELTS( 0, elts[0], elts[1] );
10495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  EMIT_TWO_ELTS( 2, elts[2], elts[1] );
10505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  EMIT_TWO_ELTS( 4, elts[3], elts[2] );
10515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul		  INCR_ELTS( 6 );
10525df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       }
10535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1054844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       FLUSH();
10555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    }
10565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
10575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    currentsz = dmasz;
10585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
10595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
10605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      else {
10615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 ELT_INIT( GL_TRIANGLE_STRIP );
10625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
10635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 for (j = start; j + 3 < count; j += nr - 2 ) {
10645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    nr = MIN2( currentsz, count - j );
1065844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    TAG(emit_elts)( ctx, elts+j, nr, ALLOC_ELTS(nr) );
1066844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    FLUSH();
10675df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    currentsz = dmasz;
10685df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
10695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
10705df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
10715df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
10725df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
10735df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
1074f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void TAG(render_quads_elts)( struct gl_context *ctx,
10755df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				    GLuint start,
10765df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				    GLuint count,
10775df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul				    GLuint flags )
10785df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
1079844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell   if (HAVE_QUADS) {
1080844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      LOCAL_VARS;
1081844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
1082844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS()/4*4;
1083844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      int currentsz;
1084844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      GLuint j, nr;
1085844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1086844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      FLUSH();
1087844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      ELT_INIT( GL_TRIANGLES );
1088844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1089844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      currentsz = GET_CURRENT_VB_MAX_ELTS()/4*4;
1090844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1091844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      count -= (count-start)%4;
1092844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1093844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      if (currentsz < 8)
1094844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 currentsz = dmasz;
1095844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1096844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      for (j = start; j < count; j += nr) {
1097844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 nr = MIN2( currentsz, count - j );
1098844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 TAG(emit_elts)( ctx, elts+j, nr, ALLOC_ELTS(nr) );
1099844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 FLUSH();
1100844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 currentsz = dmasz;
1101844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      }
11025df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   } else {
11035df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      LOCAL_VARS;
11045df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint *elts = TNL_CONTEXT(ctx)->vb.Elts;
11055df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int dmasz = GET_SUBSEQUENT_VB_MAX_ELTS();
11065df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      int currentsz;
11075df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      GLuint j, nr;
11085df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
11095df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      ELT_INIT( GL_TRIANGLES );
11105df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = GET_CURRENT_VB_MAX_ELTS();
11115df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
11125df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Emit whole number of quads in total, and in each buffer.
11135df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
11145df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      dmasz -= dmasz & 3;
11155df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      count -= (count-start) & 3;
11165df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz -= currentsz & 3;
11175df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
11185df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      /* Adjust for rendering as triangles:
11195df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul       */
11205df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      currentsz = currentsz/6*4;
11215df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      dmasz = dmasz/6*4;
11225df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
11235df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      if (currentsz < 8)
11245df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
11255df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
11265df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      for (j = start; j + 3 < count; j += nr - 2 ) {
11275df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 nr = MIN2( currentsz, count - j );
11285df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
11295df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 if (nr >= 4)
11305df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 {
11315df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLint quads = nr/4;
11325df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    GLint i;
11333152b1586cfdb06df204c5291db7b0f3850d8cb9Ville Syrjala	    ELTS_VARS( ALLOC_ELTS( quads * 6 ) );
11345df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
11355df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    for ( i = j-start ; i < j-start+quads ; i++, elts += 4 ) {
11365df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       EMIT_TWO_ELTS( 0, elts[0], elts[1] );
11375df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       EMIT_TWO_ELTS( 2, elts[3], elts[1] );
11385df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       EMIT_TWO_ELTS( 4, elts[2], elts[3] );
11395df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	       INCR_ELTS( 6 );
11405df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	    }
1141844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1142844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    FLUSH();
11435df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 }
11445df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
11455df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul	 currentsz = dmasz;
11465df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul      }
11475df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   }
11485df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul}
11495df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
11505df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
11515df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul
11523d38361b718d490e1e7fda64519952ec887cd149Keith Whitwellstatic tnl_render_func TAG(render_tab_elts)[GL_POLYGON+2] =
11535df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul{
11545df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_points_elts),
11555df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_lines_elts),
11565df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_line_loop_elts),
11575df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_line_strip_elts),
11585df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_triangles_elts),
11595df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_tri_strip_elts),
11605df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_tri_fan_elts),
11615df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_quads_elts),
11625df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_quad_strip_elts),
11635df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_poly_elts),
11645df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul   TAG(render_noop),
11655df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul};
1166844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1167844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1168844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
11695df82c82bd53db90eb72c5aad4dd20cf6f1116b1Brian Paul#endif
1170844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1171844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1172844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
117399fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell/* Pre-check the primitives in the VB to prevent the need for
117499fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell * fallbacks later on.
1175844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell */
1176f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic GLboolean TAG(validate_render)( struct gl_context *ctx,
1177844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell				       struct vertex_buffer *VB )
1178844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell{
1179844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell   GLint i;
1180844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1181352d4dbfb24c65f327759c00c7db7d30a9482e35Keith Whitwell   if (VB->ClipOrMask & ~CLIP_CULL_BIT)
1182844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return GL_FALSE;
1183844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1184844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell   if (VB->Elts && !HAVE_ELTS)
1185844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      return GL_FALSE;
1186844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1187844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell   for (i = 0 ; i < VB->PrimitiveCount ; i++) {
1188844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      GLuint prim = VB->Primitive[i].mode;
1189844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      GLuint count = VB->Primitive[i].count;
1190844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      GLboolean ok = GL_FALSE;
1191844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1192844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      if (!count)
1193844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 continue;
1194844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1195844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      switch (prim & PRIM_MODE_MASK) {
1196844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      case GL_POINTS:
1197844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 ok = HAVE_POINTS;
1198844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 break;
1199844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      case GL_LINES:
1200844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 ok = HAVE_LINES && !ctx->Line.StippleFlag;
1201844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 break;
1202844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      case GL_LINE_STRIP:
1203844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 ok = HAVE_LINE_STRIPS && !ctx->Line.StippleFlag;
1204844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 break;
1205844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      case GL_LINE_LOOP:
1206844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 ok = HAVE_LINE_STRIPS && !ctx->Line.StippleFlag;
1207844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 break;
1208844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      case GL_TRIANGLES:
1209844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 ok = HAVE_TRIANGLES;
1210844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 break;
1211844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      case GL_TRIANGLE_STRIP:
1212844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 ok = HAVE_TRI_STRIPS;
1213844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 break;
1214844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      case GL_TRIANGLE_FAN:
1215844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 ok = HAVE_TRI_FANS;
1216844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 break;
1217844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      case GL_POLYGON:
1218844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 if (HAVE_POLYGONS) {
1219844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    ok = GL_TRUE;
1220844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 }
1221a1a6ac4af4ba5b1da7c768d892b84cb1204c4c7fBrian Paul	 else {
1222a1a6ac4af4ba5b1da7c768d892b84cb1204c4c7fBrian Paul	    ok = (HAVE_TRI_FANS && ctx->Light.ShadeModel == GL_SMOOTH);
1223a1a6ac4af4ba5b1da7c768d892b84cb1204c4c7fBrian Paul         }
1224844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 break;
1225844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      case GL_QUAD_STRIP:
1226844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 if (VB->Elts) {
1227844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    ok = HAVE_TRI_STRIPS;
1228844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 }
1229844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 else if (HAVE_QUAD_STRIPS) {
1230844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    ok = GL_TRUE;
123199fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell	 } else if (HAVE_TRI_STRIPS &&
1232a1a6ac4af4ba5b1da7c768d892b84cb1204c4c7fBrian Paul		    ctx->Light.ShadeModel == GL_FLAT &&
12330a9187801505130738ae947c69cafa8a1dd118d1Eric Anholt		    VB->AttribPtr[_TNL_ATTRIB_COLOR0]->stride != 0) {
1234844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    if (HAVE_ELTS) {
1235782a32b847d097c33a8fc44d3443be08f967e616Brian Paul	       ok = (GLint) count < GET_SUBSEQUENT_VB_MAX_ELTS();
1236844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    }
1237844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    else {
1238844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	       ok = GL_FALSE;
1239844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    }
1240844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 }
1241844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 else
1242844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    ok = HAVE_TRI_STRIPS;
1243844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 break;
1244844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      case GL_QUADS:
1245844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 if (HAVE_QUADS) {
1246844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	    ok = GL_TRUE;
1247844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 } else if (HAVE_ELTS) {
1248782a32b847d097c33a8fc44d3443be08f967e616Brian Paul	    ok = (GLint) count < GET_SUBSEQUENT_VB_MAX_ELTS();
1249844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 }
1250844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 else {
1251b1d322a1e76f27a22b4c876ef96655728f4de692Keith Whitwell	    ok = HAVE_TRIANGLES; /* flatshading is ok. */
1252844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 }
1253844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 break;
1254844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      default:
1255844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell	 break;
1256844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell      }
1257844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
125899fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell      if (!ok) {
125999fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell/* 	 fprintf(stderr, "not ok %s\n", _mesa_lookup_enum_by_nr(prim & PRIM_MODE_MASK)); */
126099fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell	 return GL_FALSE;
126199fc261c47005b0674e2e45f5c6445bc2ce0d8e4Keith Whitwell      }
1262844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell   }
1263844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1264844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell   return GL_TRUE;
1265844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell}
1266844cdaf461e3e181bcf1d4c0ba79ef5c4140cb4eKeith Whitwell
1267