vbo_exec_draw.c revision 298be2b028263b2c343a707662c6fbfa18293cb2
1fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/*
2fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Mesa 3-D graphics library
337c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul * Version:  7.2
4fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell *
537c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
6fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell *
7fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
8fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * copy of this software and associated documentation files (the "Software"),
9fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * to deal in the Software without restriction, including without limitation
10fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * and/or sell copies of the Software, and to permit persons to whom the
12fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Software is furnished to do so, subject to the following conditions:
13fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell *
14fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * The above copyright notice and this permission notice shall be included
15fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * in all copies or substantial portions of the Software.
16fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell *
17fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell *
24fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Authors:
25fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell *    Keith Whitwell <keith@tungstengraphics.com>
26fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */
27fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
28c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/glheader.h"
2937c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul#include "main/bufferobj.h"
30c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/context.h"
31c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/enums.h"
32c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/state.h"
33fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
34fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell#include "vbo_context.h"
35fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
36fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
37cef97267d696d37f4dccb22951499ca25d5d87adChia-I Wu#if FEATURE_beginend
38cef97267d696d37f4dccb22951499ca25d5d87adChia-I Wu
39cef97267d696d37f4dccb22951499ca25d5d87adChia-I Wu
404b55e3695279daef221669ff063631cf3675da0cBrian Paulstatic void
414b55e3695279daef221669ff063631cf3675da0cBrian Paulvbo_exec_debug_verts( struct vbo_exec_context *exec )
42fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{
43fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   GLuint count = exec->vtx.vert_count;
44fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   GLuint i;
45fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
46298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg   printf("%s: %u vertices %d primitives, %d vertsize\n",
47298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg	  __FUNCTION__,
48298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg	  count,
49298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg	  exec->vtx.prim_count,
50298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg	  exec->vtx.vertex_size);
51fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
52fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   for (i = 0 ; i < exec->vtx.prim_count ; i++) {
53fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      struct _mesa_prim *prim = &exec->vtx.prim[i];
54298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg      printf("   prim %d: %s%s %d..%d %s %s\n",
55298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg	     i,
56298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg	     _mesa_lookup_prim_by_nr(prim->mode),
57298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg	     prim->weak ? " (weak)" : "",
58298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg	     prim->start,
59298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg	     prim->start + prim->count,
60298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg	     prim->begin ? "BEGIN" : "(wrap)",
61298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg	     prim->end ? "END" : "(wrap)");
62fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   }
63fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell}
64fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
65fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
66fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/*
67fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * NOTE: Need to have calculated primitives by this point -- do it on the fly.
68fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * NOTE: Old 'parity' issue is gone.
69fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */
704b55e3695279daef221669ff063631cf3675da0cBrian Paulstatic GLuint
714b55e3695279daef221669ff063631cf3675da0cBrian Paulvbo_copy_vertices( struct vbo_exec_context *exec )
72fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{
73fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   GLuint nr = exec->vtx.prim[exec->vtx.prim_count-1].count;
74fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   GLuint ovf, i;
75fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   GLuint sz = exec->vtx.vertex_size;
76fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   GLfloat *dst = exec->vtx.copied.buffer;
774b55e3695279daef221669ff063631cf3675da0cBrian Paul   const GLfloat *src = (exec->vtx.buffer_map +
784b55e3695279daef221669ff063631cf3675da0cBrian Paul                         exec->vtx.prim[exec->vtx.prim_count-1].start *
794b55e3695279daef221669ff063631cf3675da0cBrian Paul                         exec->vtx.vertex_size);
80fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
81fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
824b55e3695279daef221669ff063631cf3675da0cBrian Paul   switch (exec->ctx->Driver.CurrentExecPrimitive) {
83fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   case GL_POINTS:
84fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      return 0;
85fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   case GL_LINES:
86fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      ovf = nr&1;
87fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      for (i = 0 ; i < ovf ; i++)
88c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke	 memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
89fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      return i;
90fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   case GL_TRIANGLES:
91fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      ovf = nr%3;
92fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      for (i = 0 ; i < ovf ; i++)
93c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke	 memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
94fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      return i;
95fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   case GL_QUADS:
96fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      ovf = nr&3;
97fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      for (i = 0 ; i < ovf ; i++)
98c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke	 memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
99fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      return i;
100fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   case GL_LINE_STRIP:
1014b55e3695279daef221669ff063631cf3675da0cBrian Paul      if (nr == 0) {
102fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell	 return 0;
1034b55e3695279daef221669ff063631cf3675da0cBrian Paul      }
104fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      else {
105c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke	 memcpy( dst, src+(nr-1)*sz, sz * sizeof(GLfloat) );
106fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell	 return 1;
107fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      }
108fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   case GL_LINE_LOOP:
109fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   case GL_TRIANGLE_FAN:
110fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   case GL_POLYGON:
1114b55e3695279daef221669ff063631cf3675da0cBrian Paul      if (nr == 0) {
112fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell	 return 0;
1134b55e3695279daef221669ff063631cf3675da0cBrian Paul      }
114fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      else if (nr == 1) {
115c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke	 memcpy( dst, src+0, sz * sizeof(GLfloat) );
116fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell	 return 1;
1174b55e3695279daef221669ff063631cf3675da0cBrian Paul      }
1184b55e3695279daef221669ff063631cf3675da0cBrian Paul      else {
119c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke	 memcpy( dst, src+0, sz * sizeof(GLfloat) );
120c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke	 memcpy( dst+sz, src+(nr-1)*sz, sz * sizeof(GLfloat) );
121fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell	 return 2;
122fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      }
123fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   case GL_TRIANGLE_STRIP:
1245970400476c5c0a1223a49e9ec2eb511ae94b246Roland Scheidegger      /* no parity issue, but need to make sure the tri is not drawn twice */
1255970400476c5c0a1223a49e9ec2eb511ae94b246Roland Scheidegger      if (nr & 1) {
1265970400476c5c0a1223a49e9ec2eb511ae94b246Roland Scheidegger	 exec->vtx.prim[exec->vtx.prim_count-1].count--;
1275970400476c5c0a1223a49e9ec2eb511ae94b246Roland Scheidegger      }
1285970400476c5c0a1223a49e9ec2eb511ae94b246Roland Scheidegger      /* fallthrough */
129fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   case GL_QUAD_STRIP:
130fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      switch (nr) {
1314b55e3695279daef221669ff063631cf3675da0cBrian Paul      case 0:
1324b55e3695279daef221669ff063631cf3675da0cBrian Paul         ovf = 0;
1334b55e3695279daef221669ff063631cf3675da0cBrian Paul         break;
1344b55e3695279daef221669ff063631cf3675da0cBrian Paul      case 1:
1354b55e3695279daef221669ff063631cf3675da0cBrian Paul         ovf = 1;
1364b55e3695279daef221669ff063631cf3675da0cBrian Paul         break;
1374b55e3695279daef221669ff063631cf3675da0cBrian Paul      default:
1384b55e3695279daef221669ff063631cf3675da0cBrian Paul         ovf = 2 + (nr & 1);
1394b55e3695279daef221669ff063631cf3675da0cBrian Paul         break;
140fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      }
141fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      for (i = 0 ; i < ovf ; i++)
142c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke	 memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) );
143fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      return i;
1449acf207277b4de91b917b37a92f6b612f4710c80Brian Paul   case PRIM_OUTSIDE_BEGIN_END:
145fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      return 0;
146fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   default:
147fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      assert(0);
148fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      return 0;
149fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   }
150fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell}
151fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
152fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
15399efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell
154fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* TODO: populate these as the vertex is defined:
155fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */
1564b55e3695279daef221669ff063631cf3675da0cBrian Paulstatic void
1574b55e3695279daef221669ff063631cf3675da0cBrian Paulvbo_exec_bind_arrays( GLcontext *ctx )
158fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{
15999efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell   struct vbo_context *vbo = vbo_context(ctx);
16099efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell   struct vbo_exec_context *exec = &vbo->exec;
161fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   struct gl_client_array *arrays = exec->vtx.arrays;
1624b55e3695279daef221669ff063631cf3675da0cBrian Paul   const GLuint count = exec->vtx.vert_count;
1634b55e3695279daef221669ff063631cf3675da0cBrian Paul   const GLubyte *data = (GLubyte *) exec->vtx.buffer_map;
16499efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell   const GLuint *map;
165fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   GLuint attr;
166239617fbe22d4dd7b2794510a6665f09602b5adfBrian Paul   GLbitfield varying_inputs = 0x0;
167fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
16899efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell   /* Install the default (ie Current) attributes first, then overlay
16999efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell    * all active ones.
17099efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell    */
17199efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell   switch (get_program_mode(exec->ctx)) {
17299efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell   case VP_NONE:
17337c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul      for (attr = 0; attr < 16; attr++) {
17437c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul         exec->vtx.inputs[attr] = &vbo->legacy_currval[attr];
17537c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul      }
17637c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul      for (attr = 0; attr < MAT_ATTRIB_MAX; attr++) {
1771c3f7ab74ce492d6c92f2e3a0f29957fa9a71d96Brian Paul         ASSERT(attr + 16 < Elements(exec->vtx.inputs));
17837c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul         exec->vtx.inputs[attr + 16] = &vbo->mat_currval[attr];
17937c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul      }
18099efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell      map = vbo->map_vp_none;
18199efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell      break;
18299efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell   case VP_NV:
18399efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell   case VP_ARB:
18499efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell      /* The aliasing of attributes for NV vertex programs has already
18599efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell       * occurred.  NV vertex programs cannot access material values,
18699efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell       * nor attributes greater than VERT_ATTRIB_TEX7.
18799efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell       */
18837c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul      for (attr = 0; attr < 16; attr++) {
18937c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul         exec->vtx.inputs[attr] = &vbo->legacy_currval[attr];
1901c3f7ab74ce492d6c92f2e3a0f29957fa9a71d96Brian Paul         ASSERT(attr + 16 < Elements(exec->vtx.inputs));
19137c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul         exec->vtx.inputs[attr + 16] = &vbo->generic_currval[attr];
19237c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul      }
19399efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell      map = vbo->map_vp_arb;
194dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul
195dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul      /* check if VERT_ATTRIB_POS is not read but VERT_BIT_GENERIC0 is read.
196dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul       * In that case we effectively need to route the data from
197dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul       * glVertexAttrib(0, val) calls to feed into the GENERIC0 input.
198dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul       */
199dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul      if ((ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_POS) == 0 &&
200dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul          (ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_GENERIC0)) {
201dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul         exec->vtx.inputs[16] = exec->vtx.inputs[0];
202dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul         exec->vtx.attrsz[16] = exec->vtx.attrsz[0];
203c3538969e1ae3e626a618934aa8f35a7a22ddb39Brian Paul         exec->vtx.attrptr[16] = exec->vtx.attrptr[0];
204dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul         exec->vtx.attrsz[0] = 0;
205dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul      }
20699efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell      break;
207dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul   default:
208dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul      assert(0);
20999efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell   }
210fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
211fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   /* Make all active attributes (including edgeflag) available as
212fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell    * arrays of floats.
213fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell    */
21499efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell   for (attr = 0; attr < VERT_ATTRIB_MAX ; attr++) {
2156f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian      const GLuint src = map[attr];
21699efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell
21799efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell      if (exec->vtx.attrsz[src]) {
21837c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul         /* override the default array set above */
2191c3f7ab74ce492d6c92f2e3a0f29957fa9a71d96Brian Paul         ASSERT(attr < Elements(exec->vtx.inputs));
2201c3f7ab74ce492d6c92f2e3a0f29957fa9a71d96Brian Paul         ASSERT(attr < Elements(exec->vtx.arrays)); /* arrays[] */
22137c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul         exec->vtx.inputs[attr] = &arrays[attr];
22237c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul
223bd4c6a2e503db43e81ef41f77d876308badd93ebBrian Paul         if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
2246f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian            /* a real buffer obj: Ptr is an offset, not a pointer*/
225460e5b11c98e07d12c655e5bf2f1e993d05bd7a1Brian Paul            GLsizeiptr offset;
2266f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian            assert(exec->vtx.bufferobj->Pointer);  /* buf should be mapped */
2278096aa521369c3bcf5226c060efa6dd06e48ddc8Eric Anholt            offset = (GLbyte *) data -
2288096aa521369c3bcf5226c060efa6dd06e48ddc8Eric Anholt	       (GLbyte *) exec->vtx.bufferobj->Pointer +
2298096aa521369c3bcf5226c060efa6dd06e48ddc8Eric Anholt	       exec->vtx.bufferobj->Offset;
2306f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian            assert(offset >= 0);
2316f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian            arrays[attr].Ptr = (void *) offset;
2326f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian         }
2336f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian         else {
2346f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian            /* Ptr into ordinary app memory */
2356f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian            arrays[attr].Ptr = (void *) data;
2366f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian         }
23799efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell	 arrays[attr].Size = exec->vtx.attrsz[src];
238fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell	 arrays[attr].StrideB = exec->vtx.vertex_size * sizeof(GLfloat);
239fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell	 arrays[attr].Stride = exec->vtx.vertex_size * sizeof(GLfloat);
240fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell	 arrays[attr].Type = GL_FLOAT;
241ded949ed06e02ef26b1168b101daba04be78155eBrian Paul         arrays[attr].Format = GL_RGBA;
242fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell	 arrays[attr].Enabled = 1;
24337c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul         _mesa_reference_buffer_object(ctx,
24437c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul                                       &arrays[attr].BufferObj,
24537c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul                                       exec->vtx.bufferobj);
246fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell	 arrays[attr]._MaxElement = count; /* ??? */
247fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
248a2e6beade196aef269bda6bb3efb68809f85a683Brian Paul	 data += exec->vtx.attrsz[src] * sizeof(GLfloat);
2494b55e3695279daef221669ff063631cf3675da0cBrian Paul         varying_inputs |= 1 << attr;
250fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      }
251fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   }
2521680ef869625dc1fe9cf481b180382a34e0738e7Keith Whitwell
2531680ef869625dc1fe9cf481b180382a34e0738e7Keith Whitwell   _mesa_set_varying_vp_inputs( ctx, varying_inputs );
254fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell}
255fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
256fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
2574b55e3695279daef221669ff063631cf3675da0cBrian Paulstatic void
2584b55e3695279daef221669ff063631cf3675da0cBrian Paulvbo_exec_vtx_unmap( struct vbo_exec_context *exec )
259c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell{
260c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell   GLenum target = GL_ARRAY_BUFFER_ARB;
261c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
262bd4c6a2e503db43e81ef41f77d876308badd93ebBrian Paul   if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
263c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      GLcontext *ctx = exec->ctx;
264cfd5298f240612ef69ae321aebbc425710a8d731José Fonseca
2654b55e3695279daef221669ff063631cf3675da0cBrian Paul      if (ctx->Driver.FlushMappedBufferRange) {
2668ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca         GLintptr offset = exec->vtx.buffer_used - exec->vtx.bufferobj->Offset;
2678ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca         GLsizeiptr length = (exec->vtx.buffer_ptr - exec->vtx.buffer_map) * sizeof(float);
2688ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca
2694b55e3695279daef221669ff063631cf3675da0cBrian Paul         if (length)
2708ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca            ctx->Driver.FlushMappedBufferRange(ctx, target,
2718ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca                                               offset, length,
2728ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca                                               exec->vtx.bufferobj);
2738ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca      }
274c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
275c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      exec->vtx.buffer_used += (exec->vtx.buffer_ptr -
276c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell                                exec->vtx.buffer_map) * sizeof(float);
277368ca83a3fdfbe8dfe591ab73d29c500d1a91c0aKeith Whitwell
278368ca83a3fdfbe8dfe591ab73d29c500d1a91c0aKeith Whitwell      assert(exec->vtx.buffer_used <= VBO_VERT_BUFFER_SIZE);
279368ca83a3fdfbe8dfe591ab73d29c500d1a91c0aKeith Whitwell      assert(exec->vtx.buffer_ptr != NULL);
280368ca83a3fdfbe8dfe591ab73d29c500d1a91c0aKeith Whitwell
281c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      ctx->Driver.UnmapBuffer(ctx, target, exec->vtx.bufferobj);
282c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      exec->vtx.buffer_map = NULL;
283c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      exec->vtx.buffer_ptr = NULL;
284c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      exec->vtx.max_vert = 0;
285c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell   }
286c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell}
287c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
2884b55e3695279daef221669ff063631cf3675da0cBrian Paul
2894b55e3695279daef221669ff063631cf3675da0cBrian Paulvoid
2904b55e3695279daef221669ff063631cf3675da0cBrian Paulvbo_exec_vtx_map( struct vbo_exec_context *exec )
291c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell{
292c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell   GLcontext *ctx = exec->ctx;
2936e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca   const GLenum target = GL_ARRAY_BUFFER_ARB;
2946e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca   const GLenum access = GL_READ_WRITE_ARB; /* for MapBuffer */
2956e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca   const GLenum accessRange = GL_MAP_WRITE_BIT |  /* for MapBufferRange */
2966e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca                              GL_MAP_INVALIDATE_RANGE_BIT |
2976e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca                              GL_MAP_UNSYNCHRONIZED_BIT |
2986e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca                              GL_MAP_FLUSH_EXPLICIT_BIT |
2996e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca                              MESA_MAP_NOWAIT_BIT;
3006e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca   const GLenum usage = GL_STREAM_DRAW_ARB;
301c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
302bd4c6a2e503db43e81ef41f77d876308badd93ebBrian Paul   if (!_mesa_is_bufferobj(exec->vtx.bufferobj))
303c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      return;
304c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
305c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell   if (exec->vtx.buffer_map != NULL) {
306c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      assert(0);
307c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      exec->vtx.buffer_map = NULL;
308368ca83a3fdfbe8dfe591ab73d29c500d1a91c0aKeith Whitwell      exec->vtx.buffer_ptr = NULL;
309c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell   }
310c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
311c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell   if (VBO_VERT_BUFFER_SIZE > exec->vtx.buffer_used + 1024 &&
3124b55e3695279daef221669ff063631cf3675da0cBrian Paul       ctx->Driver.MapBufferRange) {
313c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      exec->vtx.buffer_map =
314c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell         (GLfloat *)ctx->Driver.MapBufferRange(ctx,
315c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell                                               target,
316c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell                                               exec->vtx.buffer_used,
317c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell                                               (VBO_VERT_BUFFER_SIZE -
318c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell                                                exec->vtx.buffer_used),
3196e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca                                               accessRange,
320c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell                                               exec->vtx.bufferobj);
321368ca83a3fdfbe8dfe591ab73d29c500d1a91c0aKeith Whitwell      exec->vtx.buffer_ptr = exec->vtx.buffer_map;
322c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell   }
323004d8f11882c6c149a395cf2e86d5d5fb3fa114bJosé Fonseca
324004d8f11882c6c149a395cf2e86d5d5fb3fa114bJosé Fonseca   if (!exec->vtx.buffer_map) {
325c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      exec->vtx.buffer_used = 0;
326c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
327c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      ctx->Driver.BufferData(ctx, target,
328c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell                             VBO_VERT_BUFFER_SIZE,
329c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell                             NULL, usage, exec->vtx.bufferobj);
330c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
3316e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca
3326e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca      if (ctx->Driver.MapBufferRange)
3336e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca         exec->vtx.buffer_map =
3346e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca            (GLfloat *)ctx->Driver.MapBufferRange(ctx, target,
3356e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca                                                  0, VBO_VERT_BUFFER_SIZE,
3366e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca                                                  accessRange,
3376e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca                                                  exec->vtx.bufferobj);
3389a0b570ab64169cee66f848d97d65f22c43d13ecCorbin Simpson      if (!exec->vtx.buffer_map)
3396e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca         exec->vtx.buffer_map =
3406e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca            (GLfloat *)ctx->Driver.MapBuffer(ctx, target, access, exec->vtx.bufferobj);
3419a0b570ab64169cee66f848d97d65f22c43d13ecCorbin Simpson      assert(exec->vtx.buffer_map);
342368ca83a3fdfbe8dfe591ab73d29c500d1a91c0aKeith Whitwell      exec->vtx.buffer_ptr = exec->vtx.buffer_map;
343c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell   }
344c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
3454b55e3695279daef221669ff063631cf3675da0cBrian Paul   if (0)
346298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg      printf("map %d..\n", exec->vtx.buffer_used);
347c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell}
348c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
349c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
350c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
351fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/**
352fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Execute the buffer and save copied verts.
353fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */
3544b55e3695279daef221669ff063631cf3675da0cBrian Paulvoid
3554b55e3695279daef221669ff063631cf3675da0cBrian Paulvbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap )
356fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{
357fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   if (0)
358fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      vbo_exec_debug_verts( exec );
359fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
360fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   if (exec->vtx.prim_count &&
361fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell       exec->vtx.vert_count) {
362fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
363fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      exec->vtx.copied.nr = vbo_copy_vertices( exec );
364fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
365fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      if (exec->vtx.copied.nr != exec->vtx.vert_count) {
366fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell	 GLcontext *ctx = exec->ctx;
36733fef8be825ee8ec6abc0c2ffd9a3a967d84df88Keith Whitwell
368c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell	 /* Before the update_state() as this may raise _NEW_ARRAY
369c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell          * from _mesa_set_varying_vp_inputs().
37033fef8be825ee8ec6abc0c2ffd9a3a967d84df88Keith Whitwell	  */
37199efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell	 vbo_exec_bind_arrays( ctx );
372fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
3731680ef869625dc1fe9cf481b180382a34e0738e7Keith Whitwell         if (ctx->NewState)
3741680ef869625dc1fe9cf481b180382a34e0738e7Keith Whitwell            _mesa_update_state( ctx );
3751680ef869625dc1fe9cf481b180382a34e0738e7Keith Whitwell
376bd4c6a2e503db43e81ef41f77d876308badd93ebBrian Paul         if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
377c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell            vbo_exec_vtx_unmap( exec );
3786222eb3fcd12147ea2e7ccc20a71a921cebbb0d2Brian Paul         }
37933fef8be825ee8ec6abc0c2ffd9a3a967d84df88Keith Whitwell
3804b55e3695279daef221669ff063631cf3675da0cBrian Paul         if (0)
381298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg            printf("%s %d %d\n", __FUNCTION__, exec->vtx.prim_count,
382298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg		   exec->vtx.vert_count);
3839d4ab42f4be3a26f702729cc79ef67f8afc2eca5Keith Whitwell
384fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell	 vbo_context(ctx)->draw_prims( ctx,
385fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell				       exec->vtx.inputs,
386fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell				       exec->vtx.prim,
387fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell				       exec->vtx.prim_count,
388fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell				       NULL,
3892708ddfb06a36d8568e2aa130bf1f7d551fcd309Eric Anholt				       GL_TRUE,
390fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell				       0,
391c080123998f28d9317331aec7ddfcd1074b29dafAapo Tahkola				       exec->vtx.vert_count - 1);
39233fef8be825ee8ec6abc0c2ffd9a3a967d84df88Keith Whitwell
393c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell	 /* If using a real VBO, get new storage -- unless asked not to.
394c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell          */
395bd4c6a2e503db43e81ef41f77d876308badd93ebBrian Paul         if (_mesa_is_bufferobj(exec->vtx.bufferobj) && !unmap) {
396c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell            vbo_exec_vtx_map( exec );
3974b55e3695279daef221669ff063631cf3675da0cBrian Paul         }
398fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell      }
399fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   }
400fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell
401c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell   /* May have to unmap explicitly if we didn't draw:
402c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell    */
403c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell   if (unmap &&
404bd4c6a2e503db43e81ef41f77d876308badd93ebBrian Paul       _mesa_is_bufferobj(exec->vtx.bufferobj) &&
405c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell       exec->vtx.buffer_map) {
406c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      vbo_exec_vtx_unmap( exec );
407c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell   }
408c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
409c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
41093aa0fd81c44c7a5f29f30e8f730e060597b06adBrian Paul   if (unmap || exec->vtx.vertex_size == 0)
411c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      exec->vtx.max_vert = 0;
412c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell   else
413c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell      exec->vtx.max_vert = ((VBO_VERT_BUFFER_SIZE - exec->vtx.buffer_used) /
414c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell                            (exec->vtx.vertex_size * sizeof(GLfloat)));
415c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell
416c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell   exec->vtx.buffer_ptr = exec->vtx.buffer_map;
417fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   exec->vtx.prim_count = 0;
418fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell   exec->vtx.vert_count = 0;
419fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell}
420cef97267d696d37f4dccb22951499ca25d5d87adChia-I Wu
421cef97267d696d37f4dccb22951499ca25d5d87adChia-I Wu
422cef97267d696d37f4dccb22951499ca25d5d87adChia-I Wu#endif /* FEATURE_beginend */
423