vbo_exec_draw.c revision 6e09c1fd085361212c5bfccf6b2810f3f8052231
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" 33c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/macros.h" 34fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 35fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell#include "vbo_context.h" 36fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 37fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 38fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void vbo_exec_debug_verts( struct vbo_exec_context *exec ) 39fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 40fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint count = exec->vtx.vert_count; 41fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint i; 42fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 43fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_printf("%s: %u vertices %d primitives, %d vertsize\n", 44fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell __FUNCTION__, 45fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell count, 46fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell exec->vtx.prim_count, 47fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell exec->vtx.vertex_size); 48fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 49fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < exec->vtx.prim_count ; i++) { 50fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct _mesa_prim *prim = &exec->vtx.prim[i]; 51fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_printf(" prim %d: %s%s %d..%d %s %s\n", 52fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell i, 53fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_lookup_enum_by_nr(prim->mode), 54fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell prim->weak ? " (weak)" : "", 55fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell prim->start, 56fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell prim->start + prim->count, 57fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell prim->begin ? "BEGIN" : "(wrap)", 58fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell prim->end ? "END" : "(wrap)"); 59fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 60fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 61fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 62fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 63fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* 64fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * NOTE: Need to have calculated primitives by this point -- do it on the fly. 65fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * NOTE: Old 'parity' issue is gone. 66fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 67fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic GLuint vbo_copy_vertices( struct vbo_exec_context *exec ) 68fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 69fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint nr = exec->vtx.prim[exec->vtx.prim_count-1].count; 70fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint ovf, i; 71fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint sz = exec->vtx.vertex_size; 72fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLfloat *dst = exec->vtx.copied.buffer; 73c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell GLfloat *src = (exec->vtx.buffer_map + 74fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell exec->vtx.prim[exec->vtx.prim_count-1].start * 75fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell exec->vtx.vertex_size); 76fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 77fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 78fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell switch( exec->ctx->Driver.CurrentExecPrimitive ) 79fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell { 80fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_POINTS: 81fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 0; 82fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_LINES: 83fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ovf = nr&1; 84fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < ovf ; i++) 85fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) ); 86fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return i; 87fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_TRIANGLES: 88fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ovf = nr%3; 89fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < ovf ; i++) 90fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) ); 91fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return i; 92fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_QUADS: 93fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ovf = nr&3; 94fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < ovf ; i++) 95fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) ); 96fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return i; 97fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_LINE_STRIP: 98fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (nr == 0) 99fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 0; 100fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell else { 101fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_memcpy( dst, src+(nr-1)*sz, sz * sizeof(GLfloat) ); 102fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 1; 103fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 104fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_LINE_LOOP: 105fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_TRIANGLE_FAN: 106fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_POLYGON: 107fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (nr == 0) 108fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 0; 109fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell else if (nr == 1) { 110fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_memcpy( dst, src+0, sz * sizeof(GLfloat) ); 111fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 1; 112fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } else { 113fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_memcpy( dst, src+0, sz * sizeof(GLfloat) ); 114fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_memcpy( dst+sz, src+(nr-1)*sz, sz * sizeof(GLfloat) ); 115fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 2; 116fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 117fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_TRIANGLE_STRIP: 1185970400476c5c0a1223a49e9ec2eb511ae94b246Roland Scheidegger /* no parity issue, but need to make sure the tri is not drawn twice */ 1195970400476c5c0a1223a49e9ec2eb511ae94b246Roland Scheidegger if (nr & 1) { 1205970400476c5c0a1223a49e9ec2eb511ae94b246Roland Scheidegger exec->vtx.prim[exec->vtx.prim_count-1].count--; 1215970400476c5c0a1223a49e9ec2eb511ae94b246Roland Scheidegger } 1225970400476c5c0a1223a49e9ec2eb511ae94b246Roland Scheidegger /* fallthrough */ 123fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_QUAD_STRIP: 124fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell switch (nr) { 125fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case 0: ovf = 0; break; 126fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case 1: ovf = 1; break; 127fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell default: ovf = 2 + (nr&1); break; 128fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 129fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < ovf ; i++) 130fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) ); 131fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return i; 1329acf207277b4de91b917b37a92f6b612f4710c80Brian Paul case PRIM_OUTSIDE_BEGIN_END: 133fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 0; 134fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell default: 135fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(0); 136fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 0; 137fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 138fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 139fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 140fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 14199efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell 142fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* TODO: populate these as the vertex is defined: 143fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 14499efde461d3b8615863bdb7308e05289e0db0422Keith Whitwellstatic void vbo_exec_bind_arrays( GLcontext *ctx ) 145fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 14699efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell struct vbo_context *vbo = vbo_context(ctx); 14799efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell struct vbo_exec_context *exec = &vbo->exec; 148fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct gl_client_array *arrays = exec->vtx.arrays; 149fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint count = exec->vtx.vert_count; 150c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell GLubyte *data = (GLubyte *)exec->vtx.buffer_map; 15199efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell const GLuint *map; 152fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint attr; 153239617fbe22d4dd7b2794510a6665f09602b5adfBrian Paul GLbitfield varying_inputs = 0x0; 154fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 15599efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell /* Install the default (ie Current) attributes first, then overlay 15699efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell * all active ones. 15799efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell */ 15899efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell switch (get_program_mode(exec->ctx)) { 15999efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell case VP_NONE: 16037c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul for (attr = 0; attr < 16; attr++) { 16137c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul exec->vtx.inputs[attr] = &vbo->legacy_currval[attr]; 16237c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul } 16337c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul for (attr = 0; attr < MAT_ATTRIB_MAX; attr++) { 16437c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul exec->vtx.inputs[attr + 16] = &vbo->mat_currval[attr]; 16537c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul } 16699efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell map = vbo->map_vp_none; 16799efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell break; 16899efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell case VP_NV: 16999efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell case VP_ARB: 17099efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell /* The aliasing of attributes for NV vertex programs has already 17199efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell * occurred. NV vertex programs cannot access material values, 17299efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell * nor attributes greater than VERT_ATTRIB_TEX7. 17399efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell */ 17437c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul for (attr = 0; attr < 16; attr++) { 17537c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul exec->vtx.inputs[attr] = &vbo->legacy_currval[attr]; 17637c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul exec->vtx.inputs[attr + 16] = &vbo->generic_currval[attr]; 17737c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul } 17899efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell map = vbo->map_vp_arb; 179dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul 180dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul /* check if VERT_ATTRIB_POS is not read but VERT_BIT_GENERIC0 is read. 181dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul * In that case we effectively need to route the data from 182dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul * glVertexAttrib(0, val) calls to feed into the GENERIC0 input. 183dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul */ 184dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul if ((ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_POS) == 0 && 185dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul (ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_GENERIC0)) { 186dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul exec->vtx.inputs[16] = exec->vtx.inputs[0]; 187dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul exec->vtx.attrsz[16] = exec->vtx.attrsz[0]; 188c3538969e1ae3e626a618934aa8f35a7a22ddb39Brian Paul exec->vtx.attrptr[16] = exec->vtx.attrptr[0]; 189dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul exec->vtx.attrsz[0] = 0; 190dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul } 19199efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell break; 192dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul default: 193dea0d4d56326f148a42c766bdbaf1b5bb247cc59Brian Paul assert(0); 19499efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell } 195fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 196fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Make all active attributes (including edgeflag) available as 197fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * arrays of floats. 198fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 19999efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell for (attr = 0; attr < VERT_ATTRIB_MAX ; attr++) { 2006f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian const GLuint src = map[attr]; 20199efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell 20299efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell if (exec->vtx.attrsz[src]) { 20337c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul /* override the default array set above */ 20437c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul exec->vtx.inputs[attr] = &arrays[attr]; 20537c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul 2066f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian if (exec->vtx.bufferobj->Name) { 2076f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian /* a real buffer obj: Ptr is an offset, not a pointer*/ 208460e5b11c98e07d12c655e5bf2f1e993d05bd7a1Brian Paul GLsizeiptr offset; 2096f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian assert(exec->vtx.bufferobj->Pointer); /* buf should be mapped */ 2106f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian offset = (GLbyte *) data - (GLbyte *) exec->vtx.bufferobj->Pointer; 2116f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian assert(offset >= 0); 2126f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian arrays[attr].Ptr = (void *) offset; 2136f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian } 2146f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian else { 2156f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian /* Ptr into ordinary app memory */ 2166f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian arrays[attr].Ptr = (void *) data; 2176f765fbde42a4f729780aa39d2b0ed9d736dd5a8Brian } 21899efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell arrays[attr].Size = exec->vtx.attrsz[src]; 219fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell arrays[attr].StrideB = exec->vtx.vertex_size * sizeof(GLfloat); 220fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell arrays[attr].Stride = exec->vtx.vertex_size * sizeof(GLfloat); 221fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell arrays[attr].Type = GL_FLOAT; 222ded949ed06e02ef26b1168b101daba04be78155eBrian Paul arrays[attr].Format = GL_RGBA; 223fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell arrays[attr].Enabled = 1; 22437c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul _mesa_reference_buffer_object(ctx, 22537c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul &arrays[attr].BufferObj, 22637c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul exec->vtx.bufferobj); 227fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell arrays[attr]._MaxElement = count; /* ??? */ 228fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 229a2e6beade196aef269bda6bb3efb68809f85a683Brian Paul data += exec->vtx.attrsz[src] * sizeof(GLfloat); 2301680ef869625dc1fe9cf481b180382a34e0738e7Keith Whitwell varying_inputs |= 1<<attr; 231fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 232fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 2331680ef869625dc1fe9cf481b180382a34e0738e7Keith Whitwell 2341680ef869625dc1fe9cf481b180382a34e0738e7Keith Whitwell _mesa_set_varying_vp_inputs( ctx, varying_inputs ); 235fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 236fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 237fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 238c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwellstatic void vbo_exec_vtx_unmap( struct vbo_exec_context *exec ) 239c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell{ 240c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell GLenum target = GL_ARRAY_BUFFER_ARB; 241c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 242c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell if (exec->vtx.bufferobj->Name) { 243c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell GLcontext *ctx = exec->ctx; 244cfd5298f240612ef69ae321aebbc425710a8d731José Fonseca 2458ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca if(ctx->Driver.FlushMappedBufferRange) { 2468ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca GLintptr offset = exec->vtx.buffer_used - exec->vtx.bufferobj->Offset; 2478ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca GLsizeiptr length = (exec->vtx.buffer_ptr - exec->vtx.buffer_map) * sizeof(float); 2488ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca 2498ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca if(length) 2508ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca ctx->Driver.FlushMappedBufferRange(ctx, target, 2518ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca offset, length, 2528ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca exec->vtx.bufferobj); 2538ad65a23d14f82461c00b1d8dcc1393167f36ab0José Fonseca } 254c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 255c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.buffer_used += (exec->vtx.buffer_ptr - 256c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.buffer_map) * sizeof(float); 257368ca83a3fdfbe8dfe591ab73d29c500d1a91c0aKeith Whitwell 258368ca83a3fdfbe8dfe591ab73d29c500d1a91c0aKeith Whitwell assert(exec->vtx.buffer_used <= VBO_VERT_BUFFER_SIZE); 259368ca83a3fdfbe8dfe591ab73d29c500d1a91c0aKeith Whitwell assert(exec->vtx.buffer_ptr != NULL); 260368ca83a3fdfbe8dfe591ab73d29c500d1a91c0aKeith Whitwell 261c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell ctx->Driver.UnmapBuffer(ctx, target, exec->vtx.bufferobj); 262c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.buffer_map = NULL; 263c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.buffer_ptr = NULL; 264c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.max_vert = 0; 265c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell } 266c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell} 267c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 268c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwellvoid vbo_exec_vtx_map( struct vbo_exec_context *exec ) 269c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell{ 270c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell GLcontext *ctx = exec->ctx; 2716e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca const GLenum target = GL_ARRAY_BUFFER_ARB; 2726e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca const GLenum access = GL_READ_WRITE_ARB; /* for MapBuffer */ 2736e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca const GLenum accessRange = GL_MAP_WRITE_BIT | /* for MapBufferRange */ 2746e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca GL_MAP_INVALIDATE_RANGE_BIT | 2756e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca GL_MAP_UNSYNCHRONIZED_BIT | 2766e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca GL_MAP_FLUSH_EXPLICIT_BIT | 2776e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca MESA_MAP_NOWAIT_BIT; 2786e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca const GLenum usage = GL_STREAM_DRAW_ARB; 279c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 280c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell if (exec->vtx.bufferobj->Name == 0) 281c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell return; 282c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 283c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell if (exec->vtx.buffer_map != NULL) { 284c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell assert(0); 285c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.buffer_map = NULL; 286368ca83a3fdfbe8dfe591ab73d29c500d1a91c0aKeith Whitwell exec->vtx.buffer_ptr = NULL; 287c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell } 288c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 289c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell if (VBO_VERT_BUFFER_SIZE > exec->vtx.buffer_used + 1024 && 290c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell ctx->Driver.MapBufferRange) 291c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell { 292c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.buffer_map = 293c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell (GLfloat *)ctx->Driver.MapBufferRange(ctx, 294c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell target, 295c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.buffer_used, 296c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell (VBO_VERT_BUFFER_SIZE - 297c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.buffer_used), 2986e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca accessRange, 299c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.bufferobj); 300368ca83a3fdfbe8dfe591ab73d29c500d1a91c0aKeith Whitwell exec->vtx.buffer_ptr = exec->vtx.buffer_map; 301c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell } 302004d8f11882c6c149a395cf2e86d5d5fb3fa114bJosé Fonseca 303004d8f11882c6c149a395cf2e86d5d5fb3fa114bJosé Fonseca if (!exec->vtx.buffer_map) { 304c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.buffer_used = 0; 305c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 306c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell ctx->Driver.BufferData(ctx, target, 307c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell VBO_VERT_BUFFER_SIZE, 308c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell NULL, usage, exec->vtx.bufferobj); 309c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 3106e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca 3116e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca if (ctx->Driver.MapBufferRange) 3126e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca exec->vtx.buffer_map = 3136e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca (GLfloat *)ctx->Driver.MapBufferRange(ctx, target, 3146e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca 0, VBO_VERT_BUFFER_SIZE, 3156e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca accessRange, 3166e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca exec->vtx.bufferobj); 3176e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca else 3186e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca exec->vtx.buffer_map = 3196e09c1fd085361212c5bfccf6b2810f3f8052231José Fonseca (GLfloat *)ctx->Driver.MapBuffer(ctx, target, access, exec->vtx.bufferobj); 320368ca83a3fdfbe8dfe591ab73d29c500d1a91c0aKeith Whitwell exec->vtx.buffer_ptr = exec->vtx.buffer_map; 321c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell } 322c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 323c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell if (0) _mesa_printf("map %d..\n", exec->vtx.buffer_used); 324c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell} 325c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 326c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 327c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 328fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/** 329fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Execute the buffer and save copied verts. 330fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 331c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwellvoid vbo_exec_vtx_flush( struct vbo_exec_context *exec, 332c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell GLboolean unmap ) 333fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 334fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (0) 335fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vbo_exec_debug_verts( exec ); 336fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 337fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 338fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (exec->vtx.prim_count && 339fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell exec->vtx.vert_count) { 340fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 341fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell exec->vtx.copied.nr = vbo_copy_vertices( exec ); 342fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 343fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (exec->vtx.copied.nr != exec->vtx.vert_count) { 344fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLcontext *ctx = exec->ctx; 34533fef8be825ee8ec6abc0c2ffd9a3a967d84df88Keith Whitwell 346c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell /* Before the update_state() as this may raise _NEW_ARRAY 347c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell * from _mesa_set_varying_vp_inputs(). 34833fef8be825ee8ec6abc0c2ffd9a3a967d84df88Keith Whitwell */ 34999efde461d3b8615863bdb7308e05289e0db0422Keith Whitwell vbo_exec_bind_arrays( ctx ); 350fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 3511680ef869625dc1fe9cf481b180382a34e0738e7Keith Whitwell if (ctx->NewState) 3521680ef869625dc1fe9cf481b180382a34e0738e7Keith Whitwell _mesa_update_state( ctx ); 3531680ef869625dc1fe9cf481b180382a34e0738e7Keith Whitwell 3546222eb3fcd12147ea2e7ccc20a71a921cebbb0d2Brian Paul if (exec->vtx.bufferobj->Name) { 355c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell vbo_exec_vtx_unmap( exec ); 3566222eb3fcd12147ea2e7ccc20a71a921cebbb0d2Brian Paul } 35733fef8be825ee8ec6abc0c2ffd9a3a967d84df88Keith Whitwell 358c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell if (0) _mesa_printf("%s %d %d\n", __FUNCTION__, exec->vtx.prim_count, 359c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.vert_count); 3609d4ab42f4be3a26f702729cc79ef67f8afc2eca5Keith Whitwell 361fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vbo_context(ctx)->draw_prims( ctx, 362fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell exec->vtx.inputs, 363fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell exec->vtx.prim, 364fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell exec->vtx.prim_count, 365fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell NULL, 366fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 0, 367c080123998f28d9317331aec7ddfcd1074b29dafAapo Tahkola exec->vtx.vert_count - 1); 36833fef8be825ee8ec6abc0c2ffd9a3a967d84df88Keith Whitwell 369c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell /* If using a real VBO, get new storage -- unless asked not to. 370c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell */ 371c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell if (exec->vtx.bufferobj->Name && !unmap) { 372c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell vbo_exec_vtx_map( exec ); 373c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell } 374fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 375fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 376fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 377c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell /* May have to unmap explicitly if we didn't draw: 378c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell */ 379c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell if (unmap && 380c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.bufferobj->Name && 381c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.buffer_map) { 382c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell vbo_exec_vtx_unmap( exec ); 383c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell } 384c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 385c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 386c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell if (unmap) 387c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.max_vert = 0; 388c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell else 389c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.max_vert = ((VBO_VERT_BUFFER_SIZE - exec->vtx.buffer_used) / 390c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell (exec->vtx.vertex_size * sizeof(GLfloat))); 391c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 392c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell 393c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell exec->vtx.buffer_ptr = exec->vtx.buffer_map; 394fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell exec->vtx.prim_count = 0; 395fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell exec->vtx.vert_count = 0; 396fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 397