vbo_save_api.c revision f9995b30756140724f41daf963fa06167912be7f
1fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/************************************************************************** 2fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 337c74af01ce52b603f565a6c8a9094500d5cb87aBrian PaulCopyright 2002-2008 Tungsten Graphics Inc., Cedar Park, Texas. 4fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 5fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith WhitwellAll Rights Reserved. 6fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 7fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith WhitwellPermission is hereby granted, free of charge, to any person obtaining a 8fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellcopy of this software and associated documentation files (the "Software"), 9fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellto deal in the Software without restriction, including without limitation 10fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellon the rights to use, copy, modify, merge, publish, distribute, sub 11fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwelllicense, and/or sell copies of the Software, and to permit persons to whom 12fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellthe Software is furnished to do so, subject to the following conditions: 13fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 14fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith WhitwellThe above copyright notice and this permission notice (including the next 15fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellparagraph) shall be included in all copies or substantial portions of the 16fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith WhitwellSoftware. 17fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 18fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith WhitwellTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith WhitwellIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith WhitwellFITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 21fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith WhitwellTUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 22fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith WhitwellDAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith WhitwellOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 24fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith WhitwellUSE OR OTHER DEALINGS IN THE SOFTWARE. 25fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 26fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell**************************************************************************/ 27fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 28fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* 29fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Authors: 30fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Keith Whitwell <keith@tungstengraphics.com> 31fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 32fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 33fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 34fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 35fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* Display list compiler attempts to store lists of vertices with the 36fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * same vertex layout. Additionally it attempts to minimize the need 37fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * for execute-time fixup of these vertex lists, allowing them to be 38fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * cached on hardware. 39fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 40fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * There are still some circumstances where this can be thwarted, for 41fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * example by building a list that consists of one very long primitive 42fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * (eg Begin(Triangles), 1000 vertices, End), and calling that list 43fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * from inside a different begin/end object (Begin(Lines), CallList, 44fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * End). 45fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 46fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * In that case the code will have to replay the list as individual 47fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * commands through the Exec dispatch table, or fix up the copied 48fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * vertices at execute-time. 49fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 50fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * The other case where fixup is required is when a vertex attribute 51fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * is introduced in the middle of a primitive. Eg: 52fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Begin(Lines) 53fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * TexCoord1f() Vertex2f() 54fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * TexCoord1f() Color3f() Vertex2f() 55fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * End() 56fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 57fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * If the current value of Color isn't known at compile-time, this 58fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * primitive will require fixup. 59fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 60fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 61fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * The list compiler currently doesn't attempt to compile lists 62fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * containing EvalCoord or EvalPoint commands. On encountering one of 63fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * these, compilation falls back to opcodes. 64fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 65fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * This could be improved to fallback only when a mix of EvalCoord and 66fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Vertex commands are issued within a single primitive. 67fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 68fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 69fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 70c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/glheader.h" 7137c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul#include "main/bufferobj.h" 72c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/context.h" 73c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/dlist.h" 74c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/enums.h" 75aefa1f6ab1d9267b223b06ae205ab34c8e0d7c02Chia-I Wu#include "main/eval.h" 76c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/macros.h" 7760b08eb1fdf287d28ec66b9282513ab35a61aee0Eric Anholt#include "main/api_noop.h" 78c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/api_validate.h" 79c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/api_arrayelt.h" 80c223c6b663cd5db39ba19c2be74b88cc3b8f53f3Brian#include "main/vtxfmt.h" 812cf44390d1e819f23e1d7ceb3199276c9148c647Chia-I Wu#include "main/dispatch.h" 82fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 83fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell#include "vbo_context.h" 84fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 85fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 868d5c83c467f83b44f5f2e271c4f9cca2d45af518Chia-I Wu#if FEATURE_dlist 878d5c83c467f83b44f5f2e271c4f9cca2d45af518Chia-I Wu 888d5c83c467f83b44f5f2e271c4f9cca2d45af518Chia-I Wu 8937aca21129d87946d2dc6b45fa5bacd514921550zhang#ifdef ERROR 9037aca21129d87946d2dc6b45fa5bacd514921550zhang#undef ERROR 9137aca21129d87946d2dc6b45fa5bacd514921550zhang#endif 9237aca21129d87946d2dc6b45fa5bacd514921550zhang 93fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 9437c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul/* An interesting VBO number/name to help with debugging */ 9537c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul#define VBO_BUF_ID 12345 9637c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul 9737c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul 98fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* 99fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * NOTE: Old 'parity' issue is gone, but copying can still be 100fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * wrong-footed on replay. 101fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 102f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic GLuint _save_copy_vertices( struct gl_context *ctx, 103fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const struct vbo_save_vertex_list *node, 104fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const GLfloat *src_buffer) 105fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 106fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context( ctx )->save; 107fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const struct _mesa_prim *prim = &node->prim[node->prim_count-1]; 108fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint nr = prim->count; 109fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint sz = save->vertex_size; 110fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const GLfloat *src = src_buffer + prim->start * sz; 111fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLfloat *dst = save->copied.buffer; 112fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint ovf, i; 113fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 114fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (prim->end) 115fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 0; 116fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 117fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell switch( prim->mode ) 118fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell { 119fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_POINTS: 120fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 0; 121fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_LINES: 122fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ovf = nr&1; 123fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < ovf ; i++) 124c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) ); 125fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return i; 126fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_TRIANGLES: 127fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ovf = nr%3; 128fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < ovf ; i++) 129c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) ); 130fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return i; 131fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_QUADS: 132fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ovf = nr&3; 133fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < ovf ; i++) 134c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) ); 135fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return i; 136fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_LINE_STRIP: 137fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (nr == 0) 138fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 0; 139fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell else { 140c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke memcpy( dst, src+(nr-1)*sz, sz*sizeof(GLfloat) ); 141fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 1; 142fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 143fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_LINE_LOOP: 144fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_TRIANGLE_FAN: 145fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_POLYGON: 146fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (nr == 0) 147fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 0; 148fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell else if (nr == 1) { 149c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke memcpy( dst, src+0, sz*sizeof(GLfloat) ); 150fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 1; 151fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } else { 152c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke memcpy( dst, src+0, sz*sizeof(GLfloat) ); 153c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke memcpy( dst+sz, src+(nr-1)*sz, sz*sizeof(GLfloat) ); 154fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 2; 155fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 156fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_TRIANGLE_STRIP: 157fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_QUAD_STRIP: 158fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell switch (nr) { 159fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case 0: ovf = 0; break; 160fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case 1: ovf = 1; break; 161fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell default: ovf = 2 + (nr&1); break; 162fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 163fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < ovf ; i++) 164c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz*sizeof(GLfloat) ); 165fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return i; 166fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell default: 167fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(0); 168fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return 0; 169fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 170fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 171fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 172fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 173f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic struct vbo_save_vertex_store *alloc_vertex_store( struct gl_context *ctx ) 174fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 175fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_vertex_store *vertex_store = CALLOC_STRUCT(vbo_save_vertex_store); 176fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 177fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* obj->Name needs to be non-zero, but won't ever be examined more 178fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * closely than that. In particular these buffers won't be entered 179fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * into the hash and can never be confused with ones visible to the 180fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * user. Perhaps there could be a special number for internal 181fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * buffers: 182fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 18337c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul vertex_store->bufferobj = ctx->Driver.NewBufferObject(ctx, 18437c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul VBO_BUF_ID, 18537c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul GL_ARRAY_BUFFER_ARB); 186fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 187fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Driver.BufferData( ctx, 188fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GL_ARRAY_BUFFER_ARB, 189fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell VBO_SAVE_BUFFER_SIZE * sizeof(GLfloat), 190fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell NULL, 191fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GL_STATIC_DRAW_ARB, 192fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vertex_store->bufferobj); 193fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 194fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vertex_store->buffer = NULL; 195fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vertex_store->used = 0; 196fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vertex_store->refcount = 1; 197fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 198fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return vertex_store; 199fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 200fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 201f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void free_vertex_store( struct gl_context *ctx, struct vbo_save_vertex_store *vertex_store ) 202fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 203fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(!vertex_store->buffer); 204fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 20537c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul if (vertex_store->bufferobj) { 20637c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul _mesa_reference_buffer_object(ctx, &vertex_store->bufferobj, NULL); 20737c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul } 208fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 209fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell FREE( vertex_store ); 210fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 211fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 212f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic GLfloat *map_vertex_store( struct gl_context *ctx, struct vbo_save_vertex_store *vertex_store ) 213fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 214fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(vertex_store->bufferobj); 215fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(!vertex_store->buffer); 216fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vertex_store->buffer = (GLfloat *)ctx->Driver.MapBuffer(ctx, 217fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GL_ARRAY_BUFFER_ARB, /* not used */ 2182cb3594af9cd1434aa2c408cd6f8d51bcd12e8eaAapo Tahkola GL_WRITE_ONLY, /* not used */ 219fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vertex_store->bufferobj); 220fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 221fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(vertex_store->buffer); 222fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return vertex_store->buffer + vertex_store->used; 223fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 224fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 225f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void unmap_vertex_store( struct gl_context *ctx, struct vbo_save_vertex_store *vertex_store ) 226fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 227fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Driver.UnmapBuffer( ctx, GL_ARRAY_BUFFER_ARB, vertex_store->bufferobj ); 228fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vertex_store->buffer = NULL; 229fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 230fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 231fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 232f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic struct vbo_save_primitive_store *alloc_prim_store( struct gl_context *ctx ) 233fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 234fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_primitive_store *store = CALLOC_STRUCT(vbo_save_primitive_store); 235fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (void) ctx; 236fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell store->used = 0; 237fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell store->refcount = 1; 238fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return store; 239fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 240fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 241f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void _save_reset_counters( struct gl_context *ctx ) 242fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 243fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 244fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 245fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim = save->prim_store->buffer + save->prim_store->used; 246fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->buffer = (save->vertex_store->buffer + 247fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->vertex_store->used); 248fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 249c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell assert(save->buffer == save->buffer_ptr); 250fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 251fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (save->vertex_size) 252fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->max_vert = ((VBO_SAVE_BUFFER_SIZE - save->vertex_store->used) / 253fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->vertex_size); 254fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell else 255fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->max_vert = 0; 256fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 257fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->vert_count = 0; 258fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim_count = 0; 259fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim_max = VBO_SAVE_PRIM_SIZE - save->prim_store->used; 260fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->dangling_attr_ref = 0; 261fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 262fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 263fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 264fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* Insert the active immediate struct onto the display list currently 265fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * being built. 266fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 267f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void _save_compile_vertex_list( struct gl_context *ctx ) 268fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 269fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 270fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_vertex_list *node; 271fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 272fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Allocate space for this structure in the display list currently 273fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * being compiled. 274fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 275fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node = (struct vbo_save_vertex_list *) 2766e1697bee72a95f7d605e42ce60e2cb4a545106fBrian Paul _mesa_dlist_alloc(ctx, save->opcode_vertex_list, sizeof(*node)); 277fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 278fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (!node) 279fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return; 280fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 281fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Duplicate our template, increment refcounts to the storage structs: 282fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 283c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke memcpy(node->attrsz, save->attrsz, sizeof(node->attrsz)); 284fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->vertex_size = save->vertex_size; 285fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->buffer_offset = (save->buffer - save->vertex_store->buffer) * sizeof(GLfloat); 286fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->count = save->vert_count; 287fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->wrap_count = save->copied.nr; 288fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->dangling_attr_ref = save->dangling_attr_ref; 289fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->prim = save->prim; 290fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->prim_count = save->prim_count; 291fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->vertex_store = save->vertex_store; 292fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->prim_store = save->prim_store; 293fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 294fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->vertex_store->refcount++; 295fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->prim_store->refcount++; 296fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 2978b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell 2988b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell node->current_size = node->vertex_size - node->attrsz[0]; 2998b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell node->current_data = NULL; 3008b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell 3018b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell if (node->current_size) { 3028b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell /* If the malloc fails, we just pull the data out of the VBO 3038b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell * later instead. 3048b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell */ 3058b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell node->current_data = MALLOC( node->current_size * sizeof(GLfloat) ); 3068b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell if (node->current_data) { 3078b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell const char *buffer = (const char *)save->vertex_store->buffer; 3088b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell unsigned attr_offset = node->attrsz[0] * sizeof(GLfloat); 3098b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell unsigned vertex_offset = 0; 3108b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell 3118b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell if (node->count) 3128b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell vertex_offset = (node->count-1) * node->vertex_size * sizeof(GLfloat); 3138b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell 3148b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell memcpy( node->current_data, 3158b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell buffer + node->buffer_offset + vertex_offset + attr_offset, 3168b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell node->current_size * sizeof(GLfloat) ); 3178b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell } 3188b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell } 3198b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell 3208b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell 3218b2ebd15310cbd5d905b08761b5e950f8e2580e5Keith Whitwell 322fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(node->attrsz[VBO_ATTRIB_POS] != 0 || 323fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->count == 0); 324fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 325fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (save->dangling_attr_ref) 326446abc2799a143c32c4c48472f3f964f9288a623Brian ctx->ListState.CurrentList->Flags |= DLIST_DANGLING_REFS; 327fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 328fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->vertex_store->used += save->vertex_size * node->count; 329fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim_store->used += node->prim_count; 330fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 331fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 332fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Copy duplicated vertices 333fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 334fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->copied.nr = _save_copy_vertices( ctx, node, save->buffer ); 335fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 336fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 337fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Deal with GL_COMPILE_AND_EXECUTE: 338fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 339fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (ctx->ExecuteFlag) { 340fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct _glapi_table *dispatch = GET_DISPATCH(); 341fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 342fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _glapi_set_dispatch(ctx->Exec); 343fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 344fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vbo_loopback_vertex_list( ctx, 345fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (const GLfloat *)((const char *)save->vertex_store->buffer + 346fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->buffer_offset), 347fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->attrsz, 348fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->prim, 349fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->prim_count, 350fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->wrap_count, 351fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell node->vertex_size); 352fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 353fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _glapi_set_dispatch(dispatch); 354fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 355fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 356fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 357fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Decide whether the storage structs are full, or can be used for 358fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * the next vertex lists as well. 359fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 360fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (save->vertex_store->used > 361fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell VBO_SAVE_BUFFER_SIZE - 16 * (save->vertex_size + 4)) { 362fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 363fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Unmap old store: 364fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 365fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell unmap_vertex_store( ctx, save->vertex_store ); 366fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 367fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Release old reference: 368fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 369fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->vertex_store->refcount--; 370fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(save->vertex_store->refcount != 0); 371fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->vertex_store = NULL; 372fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 373fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Allocate and map new store: 374fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 375fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->vertex_store = alloc_vertex_store( ctx ); 376c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell save->buffer_ptr = map_vertex_store( ctx, save->vertex_store ); 377fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 378fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 379fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (save->prim_store->used > VBO_SAVE_PRIM_SIZE - 6) { 380fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim_store->refcount--; 381fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(save->prim_store->refcount != 0); 382fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim_store = alloc_prim_store( ctx ); 383fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 384fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 385fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Reset our structures for the next run of vertices: 386fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 387fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_reset_counters( ctx ); 388fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 389fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 390fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 391fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* TODO -- If no new vertices have been stored, don't bother saving 392fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * it. 393fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 394f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void _save_wrap_buffers( struct gl_context *ctx ) 395fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 396fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 397fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLint i = save->prim_count - 1; 398fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLenum mode; 399fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLboolean weak; 400fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 401fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(i < (GLint) save->prim_max); 402fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(i >= 0); 403fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 404fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Close off in-progress primitive. 405fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 406fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[i].count = (save->vert_count - 407fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[i].start); 408fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell mode = save->prim[i].mode; 409fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell weak = save->prim[i].weak; 410fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 411fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* store the copied vertices, and allocate a new list. 412fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 413fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_compile_vertex_list( ctx ); 414fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 415fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Restart interrupted primitive 416fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 417fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[0].mode = mode; 418fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[0].weak = weak; 419fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[0].begin = 0; 420fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[0].end = 0; 421fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[0].pad = 0; 422fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[0].start = 0; 423fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[0].count = 0; 4243b7ac45162412a79c3cd4d4dbc16bd54db597608Brian Paul save->prim[0].num_instances = 1; 425fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim_count = 1; 426fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 427fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 428fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 429fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 430fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* Called only when buffers are wrapped as the result of filling the 431fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * vertex_store struct. 432fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 433f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void _save_wrap_filled_vertex( struct gl_context *ctx ) 434fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 435fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 436fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLfloat *data = save->copied.buffer; 437fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint i; 438fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 439fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Emit a glEnd to close off the last vertex list. 440fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 441fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_wrap_buffers( ctx ); 442fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 443fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Copy stored stored vertices to start of new list. 444fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 445fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(save->max_vert - save->vert_count > save->copied.nr); 446fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 447fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < save->copied.nr ; i++) { 448c7ac486261ad30ef654f6d0b1608da4e8483cd40Kenneth Graunke memcpy( save->buffer_ptr, data, save->vertex_size * sizeof(GLfloat)); 449fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell data += save->vertex_size; 450c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell save->buffer_ptr += save->vertex_size; 451fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->vert_count++; 452fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 453fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 454fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 455fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 456f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void _save_copy_to_current( struct gl_context *ctx ) 457fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 458fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 459fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint i; 460fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 4612421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell for (i = VBO_ATTRIB_POS+1 ; i < VBO_ATTRIB_MAX ; i++) { 462fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (save->attrsz[i]) { 463fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->currentsz[i][0] = save->attrsz[i]; 464fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell COPY_CLEAN_4V(save->current[i], 4652421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell save->attrsz[i], 4662421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell save->attrptr[i]); 467fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 468fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 469fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 470fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 471fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 472f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void _save_copy_from_current( struct gl_context *ctx ) 473fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 474fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 475fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLint i; 476fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 4772421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell for (i = VBO_ATTRIB_POS+1 ; i < VBO_ATTRIB_MAX ; i++) { 478fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell switch (save->attrsz[i]) { 479fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case 4: save->attrptr[i][3] = save->current[i][3]; 480fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case 3: save->attrptr[i][2] = save->current[i][2]; 481fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case 2: save->attrptr[i][1] = save->current[i][1]; 482fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case 1: save->attrptr[i][0] = save->current[i][0]; 483fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case 0: break; 484fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 485fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 486fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 487fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 488fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 489fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 490fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 491fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* Flush existing data, set new attrib size, replay copied vertices. 492fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 493f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void _save_upgrade_vertex( struct gl_context *ctx, 494fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint attr, 495fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint newsz ) 496fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 497fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 498fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint oldsz; 499fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint i; 500fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLfloat *tmp; 501fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 502fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Store the current run of vertices, and emit a GL_END. Emit a 503fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * BEGIN in the new buffer. 504fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 505fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (save->vert_count) 506fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_wrap_buffers( ctx ); 507fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell else 508fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert( save->copied.nr == 0 ); 509fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 510fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Do a COPY_TO_CURRENT to ensure back-copying works for the case 511fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * when the attribute already exists in the vertex and is having 512fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * its size increased. 513fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 514fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_copy_to_current( ctx ); 515fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 516fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Fix up sizes: 517fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 518fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell oldsz = save->attrsz[attr]; 519fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->attrsz[attr] = newsz; 520fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 521fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->vertex_size += newsz - oldsz; 522fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->max_vert = ((VBO_SAVE_BUFFER_SIZE - save->vertex_store->used) / 523fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->vertex_size); 524fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->vert_count = 0; 525fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 526fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Recalculate all the attrptr[] values: 527fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 528fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0, tmp = save->vertex ; i < VBO_ATTRIB_MAX ; i++) { 529fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (save->attrsz[i]) { 530fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->attrptr[i] = tmp; 531fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell tmp += save->attrsz[i]; 532fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 533fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell else 534fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->attrptr[i] = NULL; /* will not be dereferenced. */ 535fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 536fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 537fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Copy from current to repopulate the vertex with correct values. 538fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 539fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_copy_from_current( ctx ); 540fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 541fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Replay stored vertices to translate them to new format here. 542fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 543fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * If there are copied vertices and the new (upgraded) attribute 544fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * has not been defined before, this list is somewhat degenerate, 545fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * and will need fixup at runtime. 546fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 547fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (save->copied.nr) 548fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell { 549fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLfloat *data = save->copied.buffer; 550fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLfloat *dest = save->buffer; 551fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint j; 552fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 553fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Need to note this and fix up at runtime (or loopback): 554fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 555dd60eaa6d9f61735141976db0e83d25176ac73c7Keith Whitwell if (attr != VBO_ATTRIB_POS && save->currentsz[attr][0] == 0) { 556fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(oldsz == 0); 557fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->dangling_attr_ref = GL_TRUE; 558fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 559fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 560fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < save->copied.nr ; i++) { 561fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (j = 0 ; j < VBO_ATTRIB_MAX ; j++) { 562fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (save->attrsz[j]) { 563fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (j == attr) { 564fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (oldsz) { 565fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell COPY_CLEAN_4V( dest, oldsz, data ); 566fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell data += oldsz; 567fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell dest += newsz; 568fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 569fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell else { 570fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell COPY_SZ_4V( dest, newsz, save->current[attr] ); 571fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell dest += newsz; 572fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 573fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 574fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell else { 575fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLint sz = save->attrsz[j]; 576fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell COPY_SZ_4V( dest, sz, data ); 577fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell data += sz; 578fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell dest += sz; 579fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 580fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 581fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 582fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 583fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 584c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell save->buffer_ptr = dest; 585fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->vert_count += save->copied.nr; 586fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 587fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 588fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 589f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void save_fixup_vertex( struct gl_context *ctx, GLuint attr, GLuint sz ) 590fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 591fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 592fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 593fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (sz > save->attrsz[attr]) { 594fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* New size is larger. Need to flush existing vertices and get 595fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * an enlarged vertex format. 596fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 597fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_upgrade_vertex( ctx, attr, sz ); 598fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 599fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell else if (sz < save->active_sz[attr]) { 600fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell static GLfloat id[4] = { 0, 0, 0, 1 }; 601fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint i; 602fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 603fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* New size is equal or smaller - just need to fill in some 604fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * zeros. 605fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 606fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = sz ; i <= save->attrsz[attr] ; i++) 607fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->attrptr[attr][i-1] = id[i-1]; 608fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 609fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 610fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->active_sz[attr] = sz; 611fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 612fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 613f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void _save_reset_vertex( struct gl_context *ctx ) 614fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 615fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 616fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint i; 617fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 618fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < VBO_ATTRIB_MAX ; i++) { 619fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->attrsz[i] = 0; 620fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->active_sz[i] = 0; 621fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 622fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 623fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->vertex_size = 0; 624fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 625fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 626fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 627fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 628fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell#define ERROR() _mesa_compile_error( ctx, GL_INVALID_ENUM, __FUNCTION__ ); 629fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 630fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 631fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* Only one size for each attribute may be active at once. Eg. if 632fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Color3f is installed/active, then Color4f may not be, even if the 633fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * vertex actually contains 4 color coordinates. This is because the 634fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * 3f version won't otherwise set color[3] to 1.0 -- this is the job 635fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * of the chooser function when switching between Color4f and Color3f. 636fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 637fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell#define ATTR( A, N, V0, V1, V2, V3 ) \ 638fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwelldo { \ 639fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; \ 640fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell \ 641fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (save->active_sz[A] != N) \ 642fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save_fixup_vertex(ctx, A, N); \ 643fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell \ 644fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell { \ 645fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLfloat *dest = save->attrptr[A]; \ 646fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (N>0) dest[0] = V0; \ 647fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (N>1) dest[1] = V1; \ 648fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (N>2) dest[2] = V2; \ 649fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (N>3) dest[3] = V3; \ 650fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } \ 651fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell \ 652fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if ((A) == 0) { \ 653fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint i; \ 654fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell \ 655fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0; i < save->vertex_size; i++) \ 656c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell save->buffer_ptr[i] = save->vertex[i]; \ 657fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell \ 658c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell save->buffer_ptr += save->vertex_size; \ 659fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell \ 660fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (++save->vert_count >= save->max_vert) \ 661fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_wrap_filled_vertex( ctx ); \ 662fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } \ 663fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} while (0) 664fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 665fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell#define TAG(x) _save_##x 666fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 667fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell#include "vbo_attrib_tmp.h" 668fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 669fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 670fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 671fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 672fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* Cope with EvalCoord/CallList called within a begin/end object: 673fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * -- Flush current buffer 674fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * -- Fallback to opcodes for the rest of the begin/end object. 675fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 676f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void DO_FALLBACK( struct gl_context *ctx ) 6771fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell{ 6781fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 6791fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell 6801fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell if (save->vert_count || save->prim_count) { 6811fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell GLint i = save->prim_count - 1; 6821fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell 6831fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell /* Close off in-progress primitive. 6841fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell */ 6851fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell save->prim[i].count = (save->vert_count - 6861fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell save->prim[i].start); 6871fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell 6881fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell /* Need to replay this display list with loopback, 6891fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell * unfortunately, otherwise this primitive won't be handled 6901fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell * properly: 6911fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell */ 6921fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell save->dangling_attr_ref = 1; 6931fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell 6941fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell _save_compile_vertex_list( ctx ); 6951fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell } 6961fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell 6971fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell _save_copy_to_current( ctx ); 6981fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell _save_reset_vertex( ctx ); 6991fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell _save_reset_counters( ctx ); 7001fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt ); 7011fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell ctx->Driver.SaveNeedFlush = 0; 7021fa4cde757cc94c0afa40d855309911247974e98Keith Whitwell} 703fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 704fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_EvalCoord1f( GLfloat u ) 705fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 706fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 707fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell DO_FALLBACK(ctx); 708fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Save->EvalCoord1f( u ); 709fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 710fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 711fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_EvalCoord1fv( const GLfloat *v ) 712fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 713fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 714fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell DO_FALLBACK(ctx); 715fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Save->EvalCoord1fv( v ); 716fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 717fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 718fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_EvalCoord2f( GLfloat u, GLfloat v ) 719fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 720fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 721fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell DO_FALLBACK(ctx); 722fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Save->EvalCoord2f( u, v ); 723fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 724fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 725fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_EvalCoord2fv( const GLfloat *v ) 726fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 727fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 728fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell DO_FALLBACK(ctx); 729fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Save->EvalCoord2fv( v ); 730fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 731fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 732fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_EvalPoint1( GLint i ) 733fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 734fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 735fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell DO_FALLBACK(ctx); 736fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Save->EvalPoint1( i ); 737fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 738fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 739fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_EvalPoint2( GLint i, GLint j ) 740fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 741fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 742fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell DO_FALLBACK(ctx); 743fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Save->EvalPoint2( i, j ); 744fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 745fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 746fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_CallList( GLuint l ) 747fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 748fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 749fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell DO_FALLBACK(ctx); 750fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Save->CallList( l ); 751fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 752fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 753fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_CallLists( GLsizei n, GLenum type, const GLvoid *v ) 754fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 755fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 756fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell DO_FALLBACK(ctx); 757fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Save->CallLists( n, type, v ); 758fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 759fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 760fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 761fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 762fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 763fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* This begin is hooked into ... Updating of 764fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * ctx->Driver.CurrentSavePrimitive is already taken care of. 765fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 766f9995b30756140724f41daf963fa06167912be7fKristian HøgsbergGLboolean vbo_save_NotifyBegin( struct gl_context *ctx, GLenum mode ) 767fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 768fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 769fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 770fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint i = save->prim_count++; 771fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 772fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(i < save->prim_max); 773fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[i].mode = mode & ~VBO_SAVE_PRIM_WEAK; 774fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[i].begin = 1; 775fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[i].end = 0; 776fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[i].weak = (mode & VBO_SAVE_PRIM_WEAK) ? 1 : 0; 777fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[i].pad = 0; 778fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[i].start = save->vert_count; 779fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[i].count = 0; 7803b7ac45162412a79c3cd4d4dbc16bd54db597608Brian Paul save->prim[i].num_instances = 1; 781fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 782fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_install_save_vtxfmt( ctx, &save->vtxfmt ); 783fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Driver.SaveNeedFlush = 1; 784fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return GL_TRUE; 785fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 786fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 787fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 788fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 789fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_End( void ) 790fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 791fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT( ctx ); 792fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 793fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLint i = save->prim_count - 1; 794fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 795fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END; 796fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[i].end = 1; 797fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[i].count = (save->vert_count - 798fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim[i].start); 799fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 800fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (i == (GLint) save->prim_max - 1) { 801fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_compile_vertex_list( ctx ); 802fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(save->copied.nr == 0); 803fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 804fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 805fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Swap out this vertex format while outside begin/end. Any color, 806fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * etc. received between here and the next begin will be compiled 807fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * as opcodes. 808fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 809fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt ); 810fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 811fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 812fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 813fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* These are all errors as this vtxfmt is only installed inside 814fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * begin/end pairs. 815fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 816fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_DrawElements(GLenum mode, GLsizei count, GLenum type, 817fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const GLvoid *indices) 818fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 819fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 820fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (void) mode; (void) count; (void) type; (void) indices; 821fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawElements" ); 822fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 823fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 824fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 825fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_DrawRangeElements(GLenum mode, 826fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint start, GLuint end, 827fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLsizei count, GLenum type, 828fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const GLvoid *indices) 829fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 830fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 831fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (void) mode; (void) start; (void) end; (void) count; (void) type; (void) indices; 832fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawRangeElements" ); 833fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 834fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 83592d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholtstatic void GLAPIENTRY _save_DrawElementsBaseVertex(GLenum mode, 83692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt GLsizei count, 83792d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt GLenum type, 83892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt const GLvoid *indices, 83992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt GLint basevertex) 84092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt{ 84192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt GET_CURRENT_CONTEXT(ctx); 84292d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt (void) mode; (void) count; (void) type; (void) indices; (void)basevertex; 84392d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 84492d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawElements" ); 84592d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt} 84692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 84792d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholtstatic void GLAPIENTRY _save_DrawRangeElementsBaseVertex(GLenum mode, 84892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt GLuint start, 84992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt GLuint end, 85092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt GLsizei count, 85192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt GLenum type, 85292d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt const GLvoid *indices, 85392d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt GLint basevertex) 85492d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt{ 85592d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt GET_CURRENT_CONTEXT(ctx); 85692d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt (void) mode; (void) start; (void) end; (void) count; (void) type; 85792d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt (void) indices; (void)basevertex; 85892d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 85992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawRangeElements" ); 86092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt} 86192d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt 862fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_DrawArrays(GLenum mode, GLint start, GLsizei count) 863fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 864fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 865fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (void) mode; (void) start; (void) count; 866fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glDrawArrays" ); 867fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 868fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 869fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 ) 870fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 871fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 872fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (void) x1; (void) y1; (void) x2; (void) y2; 873fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glRectf" ); 874fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 875fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 876fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_EvalMesh1( GLenum mode, GLint i1, GLint i2 ) 877fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 878fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 879fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (void) mode; (void) i1; (void) i2; 880fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glEvalMesh1" ); 881fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 882fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 883fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_EvalMesh2( GLenum mode, GLint i1, GLint i2, 884fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLint j1, GLint j2 ) 885fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 886fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 887fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (void) mode; (void) i1; (void) i2; (void) j1; (void) j2; 888fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_compile_error( ctx, GL_INVALID_OPERATION, "glEvalMesh2" ); 889fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 890fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 891fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_Begin( GLenum mode ) 892fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 893fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT( ctx ); 894fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (void) mode; 895fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_compile_error( ctx, GL_INVALID_OPERATION, "Recursive glBegin" ); 896fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 897fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 898fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 899fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* Unlike the functions above, these are to be hooked into the vtxfmt 900fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * maintained in ctx->ListState, active when the list is known or 901fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * suspected to be outside any begin/end primitive. 902fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 903fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_OBE_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 ) 904fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 905fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 906fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vbo_save_NotifyBegin( ctx, GL_QUADS | VBO_SAVE_PRIM_WEAK ); 907fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_Vertex2f(GET_DISPATCH(), ( x1, y1 )); 908fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_Vertex2f(GET_DISPATCH(), ( x2, y1 )); 909fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_Vertex2f(GET_DISPATCH(), ( x2, y2 )); 910fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_Vertex2f(GET_DISPATCH(), ( x1, y2 )); 911fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_End(GET_DISPATCH(), ()); 912fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 913fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 914fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 915fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_OBE_DrawArrays(GLenum mode, GLint start, GLsizei count) 916fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 917fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 918fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLint i; 919fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 920fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (!_mesa_validate_DrawArrays( ctx, mode, start, count )) 921fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return; 922fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 923b97947972193b6b004a0ee49da31146230d43dd8Keith Whitwell _ae_map_vbos( ctx ); 924b97947972193b6b004a0ee49da31146230d43dd8Keith Whitwell 925fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vbo_save_NotifyBegin( ctx, mode | VBO_SAVE_PRIM_WEAK ); 9266a3fdc3a1ea6c306d9543791bf172dd1052d7382Keith Whitwell 927fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0; i < count; i++) 928fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_ArrayElement(GET_DISPATCH(), (start + i)); 929fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_End(GET_DISPATCH(), ()); 930b97947972193b6b004a0ee49da31146230d43dd8Keith Whitwell 931b97947972193b6b004a0ee49da31146230d43dd8Keith Whitwell _ae_unmap_vbos( ctx ); 932fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 933fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 934fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/* Could do better by copying the arrays and element list intact and 935fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * then emitting an indexed prim at runtime. 936fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 937fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_OBE_DrawElements(GLenum mode, GLsizei count, GLenum type, 938fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const GLvoid *indices) 939fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 940fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 941fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLint i; 942fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 94392d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices, 0 )) 944fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return; 945fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 946b97947972193b6b004a0ee49da31146230d43dd8Keith Whitwell _ae_map_vbos( ctx ); 947b97947972193b6b004a0ee49da31146230d43dd8Keith Whitwell 948bd4c6a2e503db43e81ef41f77d876308badd93ebBrian Paul if (_mesa_is_bufferobj(ctx->Array.ElementArrayBufferObj)) 949982dcb74fd19b88208d127b8019e2a2af979cac2Xiang, Haihao indices = ADD_POINTERS(ctx->Array.ElementArrayBufferObj->Pointer, indices); 950982dcb74fd19b88208d127b8019e2a2af979cac2Xiang, Haihao 951fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vbo_save_NotifyBegin( ctx, mode | VBO_SAVE_PRIM_WEAK ); 952fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 953fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell switch (type) { 954fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_UNSIGNED_BYTE: 955fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < count ; i++) 956fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_ArrayElement(GET_DISPATCH(), ( ((GLubyte *)indices)[i] )); 957fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell break; 958fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_UNSIGNED_SHORT: 959fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < count ; i++) 960fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_ArrayElement(GET_DISPATCH(), ( ((GLushort *)indices)[i] )); 961fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell break; 962fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell case GL_UNSIGNED_INT: 963fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < count ; i++) 964fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_ArrayElement(GET_DISPATCH(), ( ((GLuint *)indices)[i] )); 965fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell break; 966fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell default: 967fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_error( ctx, GL_INVALID_ENUM, "glDrawElements(type)" ); 968fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell break; 969fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 970fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 971fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell CALL_End(GET_DISPATCH(), ()); 972b97947972193b6b004a0ee49da31146230d43dd8Keith Whitwell 973b97947972193b6b004a0ee49da31146230d43dd8Keith Whitwell _ae_unmap_vbos( ctx ); 974fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 975fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 976fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellstatic void GLAPIENTRY _save_OBE_DrawRangeElements(GLenum mode, 977fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint start, GLuint end, 978fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLsizei count, GLenum type, 979fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const GLvoid *indices) 980fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 981fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GET_CURRENT_CONTEXT(ctx); 982fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (_mesa_validate_DrawRangeElements( ctx, mode, 983fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell start, end, 98492d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt count, type, indices, 0 )) 985fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_OBE_DrawElements( mode, count, type, indices ); 986fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 987fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 988fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 989fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 990fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 991fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 992f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void _save_vtxfmt_init( struct gl_context *ctx ) 993fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 994fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 995fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLvertexformat *vfmt = &save->vtxfmt; 996fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 99780630d1fed6cd32e75f5e97e2cd27509be21d093Chia-I Wu _MESA_INIT_ARRAYELT_VTXFMT(vfmt, _ae_); 99880630d1fed6cd32e75f5e97e2cd27509be21d093Chia-I Wu 999fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Begin = _save_Begin; 1000fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Color3f = _save_Color3f; 1001fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Color3fv = _save_Color3fv; 1002fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Color4f = _save_Color4f; 1003fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Color4fv = _save_Color4fv; 1004fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->EdgeFlag = _save_EdgeFlag; 1005fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->End = _save_End; 1006fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->FogCoordfEXT = _save_FogCoordfEXT; 1007fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->FogCoordfvEXT = _save_FogCoordfvEXT; 1008fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Indexf = _save_Indexf; 1009fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Indexfv = _save_Indexfv; 1010fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Materialfv = _save_Materialfv; 1011fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->MultiTexCoord1fARB = _save_MultiTexCoord1f; 1012fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->MultiTexCoord1fvARB = _save_MultiTexCoord1fv; 1013fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->MultiTexCoord2fARB = _save_MultiTexCoord2f; 1014fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->MultiTexCoord2fvARB = _save_MultiTexCoord2fv; 1015fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->MultiTexCoord3fARB = _save_MultiTexCoord3f; 1016fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->MultiTexCoord3fvARB = _save_MultiTexCoord3fv; 1017fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->MultiTexCoord4fARB = _save_MultiTexCoord4f; 1018fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->MultiTexCoord4fvARB = _save_MultiTexCoord4fv; 1019fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Normal3f = _save_Normal3f; 1020fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Normal3fv = _save_Normal3fv; 1021fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->SecondaryColor3fEXT = _save_SecondaryColor3fEXT; 1022fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->SecondaryColor3fvEXT = _save_SecondaryColor3fvEXT; 1023fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->TexCoord1f = _save_TexCoord1f; 1024fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->TexCoord1fv = _save_TexCoord1fv; 1025fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->TexCoord2f = _save_TexCoord2f; 1026fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->TexCoord2fv = _save_TexCoord2fv; 1027fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->TexCoord3f = _save_TexCoord3f; 1028fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->TexCoord3fv = _save_TexCoord3fv; 1029fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->TexCoord4f = _save_TexCoord4f; 1030fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->TexCoord4fv = _save_TexCoord4fv; 1031fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Vertex2f = _save_Vertex2f; 1032fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Vertex2fv = _save_Vertex2fv; 1033fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Vertex3f = _save_Vertex3f; 1034fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Vertex3fv = _save_Vertex3fv; 1035fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Vertex4f = _save_Vertex4f; 1036fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Vertex4fv = _save_Vertex4fv; 1037fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib1fARB = _save_VertexAttrib1fARB; 1038fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib1fvARB = _save_VertexAttrib1fvARB; 1039fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib2fARB = _save_VertexAttrib2fARB; 1040fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib2fvARB = _save_VertexAttrib2fvARB; 1041fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib3fARB = _save_VertexAttrib3fARB; 1042fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib3fvARB = _save_VertexAttrib3fvARB; 1043fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib4fARB = _save_VertexAttrib4fARB; 1044fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib4fvARB = _save_VertexAttrib4fvARB; 1045fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1046fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib1fNV = _save_VertexAttrib1fNV; 1047fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib1fvNV = _save_VertexAttrib1fvNV; 1048fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib2fNV = _save_VertexAttrib2fNV; 1049fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib2fvNV = _save_VertexAttrib2fvNV; 1050fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib3fNV = _save_VertexAttrib3fNV; 1051fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib3fvNV = _save_VertexAttrib3fvNV; 1052fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib4fNV = _save_VertexAttrib4fNV; 1053fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->VertexAttrib4fvNV = _save_VertexAttrib4fvNV; 1054fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1055fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* This will all require us to fallback to saving the list as opcodes: 1056fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 1057a73ba2d31b87e974f6846a8aaced704634f6f657Chia-I Wu _MESA_INIT_DLIST_VTXFMT(vfmt, _save_); /* inside begin/end */ 1058aefa1f6ab1d9267b223b06ae205ab34c8e0d7c02Chia-I Wu 1059aefa1f6ab1d9267b223b06ae205ab34c8e0d7c02Chia-I Wu _MESA_INIT_EVAL_VTXFMT(vfmt, _save_); 1060fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1061fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* These are all errors as we at least know we are in some sort of 1062fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * begin/end pair: 1063fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 1064fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Begin = _save_Begin; 1065fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->Rectf = _save_Rectf; 1066fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->DrawArrays = _save_DrawArrays; 1067fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->DrawElements = _save_DrawElements; 1068fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell vfmt->DrawRangeElements = _save_DrawRangeElements; 106992d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt vfmt->DrawElementsBaseVertex = _save_DrawElementsBaseVertex; 107092d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt vfmt->DrawRangeElementsBaseVertex = _save_DrawRangeElementsBaseVertex; 107160b08eb1fdf287d28ec66b9282513ab35a61aee0Eric Anholt /* Loops back into vfmt->DrawElements */ 107260b08eb1fdf287d28ec66b9282513ab35a61aee0Eric Anholt vfmt->MultiDrawElementsEXT = _mesa_noop_MultiDrawElements; 107392d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt vfmt->MultiDrawElementsBaseVertex = _mesa_noop_MultiDrawElementsBaseVertex; 1074fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 1075fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1076fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1077f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid vbo_save_SaveFlushVertices( struct gl_context *ctx ) 1078fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 1079fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 1080fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1081fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Noop when we are actually active: 1082fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 1083fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (ctx->Driver.CurrentSavePrimitive == PRIM_INSIDE_UNKNOWN_PRIM || 1084fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Driver.CurrentSavePrimitive <= GL_POLYGON) 1085fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell return; 1086fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1087fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (save->vert_count || 1088fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim_count) 1089fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_compile_vertex_list( ctx ); 1090fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1091fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_copy_to_current( ctx ); 1092fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_reset_vertex( ctx ); 1093fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_reset_counters( ctx ); 1094fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Driver.SaveNeedFlush = 0; 1095fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 1096fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1097f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid vbo_save_NewList( struct gl_context *ctx, GLuint list, GLenum mode ) 1098fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 1099fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 1100fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1101fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (void) list; (void) mode; 1102fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1103fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (!save->prim_store) 1104fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->prim_store = alloc_prim_store( ctx ); 1105fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1106fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (!save->vertex_store) 1107fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->vertex_store = alloc_vertex_store( ctx ); 1108fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1109c4d1f4607abf3dfbcfcffc5c67bb89d420d3381aKeith Whitwell save->buffer_ptr = map_vertex_store( ctx, save->vertex_store ); 1110fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1111fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_reset_vertex( ctx ); 1112fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_reset_counters( ctx ); 1113fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Driver.SaveNeedFlush = 0; 1114fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 1115fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1116f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid vbo_save_EndList( struct gl_context *ctx ) 1117fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 1118fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 1119bd953e872f22690bd232a758383883100d9347d0Keith Whitwell 1120bd953e872f22690bd232a758383883100d9347d0Keith Whitwell /* EndList called inside a (saved) Begin/End pair? 1121bd953e872f22690bd232a758383883100d9347d0Keith Whitwell */ 1122bd953e872f22690bd232a758383883100d9347d0Keith Whitwell if (ctx->Driver.CurrentSavePrimitive != PRIM_OUTSIDE_BEGIN_END) { 1123bd953e872f22690bd232a758383883100d9347d0Keith Whitwell 1124d43951192baa7b76d3e035d689f73c1d2955cddbBrian Paul if (save->prim_count > 0) { 1125d43951192baa7b76d3e035d689f73c1d2955cddbBrian Paul GLint i = save->prim_count - 1; 1126d43951192baa7b76d3e035d689f73c1d2955cddbBrian Paul ctx->Driver.CurrentSavePrimitive = PRIM_OUTSIDE_BEGIN_END; 1127d43951192baa7b76d3e035d689f73c1d2955cddbBrian Paul save->prim[i].end = 0; 1128d43951192baa7b76d3e035d689f73c1d2955cddbBrian Paul save->prim[i].count = (save->vert_count - 1129d43951192baa7b76d3e035d689f73c1d2955cddbBrian Paul save->prim[i].start); 1130d43951192baa7b76d3e035d689f73c1d2955cddbBrian Paul } 1131bd953e872f22690bd232a758383883100d9347d0Keith Whitwell 1132bd953e872f22690bd232a758383883100d9347d0Keith Whitwell /* Make sure this vertex list gets replayed by the "loopback" 1133bd953e872f22690bd232a758383883100d9347d0Keith Whitwell * mechanism: 1134bd953e872f22690bd232a758383883100d9347d0Keith Whitwell */ 1135bd953e872f22690bd232a758383883100d9347d0Keith Whitwell save->dangling_attr_ref = 1; 1136bd953e872f22690bd232a758383883100d9347d0Keith Whitwell vbo_save_SaveFlushVertices( ctx ); 1137bd953e872f22690bd232a758383883100d9347d0Keith Whitwell 1138bd953e872f22690bd232a758383883100d9347d0Keith Whitwell /* Swap out this vertex format while outside begin/end. Any color, 1139bd953e872f22690bd232a758383883100d9347d0Keith Whitwell * etc. received between here and the next begin will be compiled 1140bd953e872f22690bd232a758383883100d9347d0Keith Whitwell * as opcodes. 1141bd953e872f22690bd232a758383883100d9347d0Keith Whitwell */ 1142bd953e872f22690bd232a758383883100d9347d0Keith Whitwell _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt ); 1143bd953e872f22690bd232a758383883100d9347d0Keith Whitwell } 1144bd953e872f22690bd232a758383883100d9347d0Keith Whitwell 1145fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell unmap_vertex_store( ctx, save->vertex_store ); 1146fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1147fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell assert(save->vertex_size == 0); 1148fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 1149fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1150f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid vbo_save_BeginCallList( struct gl_context *ctx, struct gl_display_list *dlist ) 1151fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 1152fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 1153446abc2799a143c32c4c48472f3f964f9288a623Brian save->replay_flags |= dlist->Flags; 1154fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 1155fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1156f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergvoid vbo_save_EndCallList( struct gl_context *ctx ) 1157fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 1158fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 1159fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1160fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if (ctx->ListState.CallDepth == 1) { 1161fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* This is correct: want to keep only the VBO_SAVE_FALLBACK 1162fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * flag, if it is set: 1163fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 1164fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->replay_flags &= VBO_SAVE_FALLBACK; 1165fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 1166fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 1167fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1168fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1169f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void vbo_destroy_vertex_list( struct gl_context *ctx, void *data ) 1170fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 1171fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_vertex_list *node = (struct vbo_save_vertex_list *)data; 1172fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (void) ctx; 1173fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1174fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if ( --node->vertex_store->refcount == 0 ) 1175fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell free_vertex_store( ctx, node->vertex_store ); 1176fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1177fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell if ( --node->prim_store->refcount == 0 ) 1178fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell FREE( node->prim_store ); 1179ca1b71b78d9c31e9ea7ceed2542ec67f32e6e5c5Brian Paul 1180ca1b71b78d9c31e9ea7ceed2542ec67f32e6e5c5Brian Paul if (node->current_data) { 1181ca1b71b78d9c31e9ea7ceed2542ec67f32e6e5c5Brian Paul FREE(node->current_data); 1182ca1b71b78d9c31e9ea7ceed2542ec67f32e6e5c5Brian Paul node->current_data = NULL; 1183ca1b71b78d9c31e9ea7ceed2542ec67f32e6e5c5Brian Paul } 1184fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 1185fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1186fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1187f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void vbo_print_vertex_list( struct gl_context *ctx, void *data ) 1188fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 1189fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_vertex_list *node = (struct vbo_save_vertex_list *)data; 1190fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint i; 1191fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (void) ctx; 1192fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1193298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("VBO-VERTEX-LIST, %u vertices %d primitives, %d vertsize\n", 1194298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg node->count, 1195298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg node->prim_count, 1196298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg node->vertex_size); 1197fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1198fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0 ; i < node->prim_count ; i++) { 1199fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct _mesa_prim *prim = &node->prim[i]; 1200fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_debug(NULL, " prim %d: %s%s %d..%d %s %s\n", 1201fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell i, 12020846c88ec3a63ac5e4096aedcdc107cbe71f306bKeith Whitwell _mesa_lookup_prim_by_nr(prim->mode), 1203fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell prim->weak ? " (weak)" : "", 1204fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell prim->start, 1205fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell prim->start + prim->count, 1206fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (prim->begin) ? "BEGIN" : "(wrap)", 1207fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell (prim->end) ? "END" : "(wrap)"); 1208fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 1209fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 1210fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1211fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1212f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergstatic void _save_current_init( struct gl_context *ctx ) 1213fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 1214fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell struct vbo_save_context *save = &vbo_context(ctx)->save; 1215fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLint i; 1216fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 12172421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell for (i = VBO_ATTRIB_POS; i <= VBO_ATTRIB_GENERIC15; i++) { 12182421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell const GLuint j = i - VBO_ATTRIB_POS; 12192421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell ASSERT(j < VERT_ATTRIB_MAX); 12202421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell save->currentsz[i] = &ctx->ListState.ActiveAttribSize[j]; 12212421b25dd777ebfd614ae45907fd4af8c2713102Keith Whitwell save->current[i] = ctx->ListState.CurrentAttrib[j]; 1222fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 1223fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 12246a3fdc3a1ea6c306d9543791bf172dd1052d7382Keith Whitwell for (i = VBO_ATTRIB_FIRST_MATERIAL; i <= VBO_ATTRIB_LAST_MATERIAL; i++) { 1225fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell const GLuint j = i - VBO_ATTRIB_FIRST_MATERIAL; 1226fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ASSERT(j < MAT_ATTRIB_MAX); 1227fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->currentsz[i] = &ctx->ListState.ActiveMaterialSize[j]; 1228fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->current[i] = ctx->ListState.CurrentMaterial[j]; 1229fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell } 1230fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 1231fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1232fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell/** 1233fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * Initialize the display list compiler 1234fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 1235fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwellvoid vbo_save_api_init( struct vbo_save_context *save ) 1236fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell{ 1237f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = save->ctx; 1238fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell GLuint i; 1239fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1240fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->opcode_vertex_list = 12416e1697bee72a95f7d605e42ce60e2cb4a545106fBrian Paul _mesa_dlist_alloc_opcode( ctx, 12426e1697bee72a95f7d605e42ce60e2cb4a545106fBrian Paul sizeof(struct vbo_save_vertex_list), 12436e1697bee72a95f7d605e42ce60e2cb4a545106fBrian Paul vbo_save_playback_vertex_list, 12446e1697bee72a95f7d605e42ce60e2cb4a545106fBrian Paul vbo_destroy_vertex_list, 12456e1697bee72a95f7d605e42ce60e2cb4a545106fBrian Paul vbo_print_vertex_list ); 1246fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1247fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->Driver.NotifySaveBegin = vbo_save_NotifyBegin; 1248fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1249fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_vtxfmt_init( ctx ); 1250fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _save_current_init( ctx ); 1251fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 125237c74af01ce52b603f565a6c8a9094500d5cb87aBrian Paul /* These will actually get set again when binding/drawing */ 1253fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell for (i = 0; i < VBO_ATTRIB_MAX; i++) 1254fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell save->inputs[i] = &save->arrays[i]; 1255fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 1256fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell /* Hook our array functions into the outside-begin-end vtxfmt in 1257fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell * ctx->ListState. 1258fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell */ 1259fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->ListState.ListVtxfmt.Rectf = _save_OBE_Rectf; 1260fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->ListState.ListVtxfmt.DrawArrays = _save_OBE_DrawArrays; 1261fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->ListState.ListVtxfmt.DrawElements = _save_OBE_DrawElements; 1262fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell ctx->ListState.ListVtxfmt.DrawRangeElements = _save_OBE_DrawRangeElements; 126360b08eb1fdf287d28ec66b9282513ab35a61aee0Eric Anholt /* loops back into _save_OBE_DrawElements */ 126460b08eb1fdf287d28ec66b9282513ab35a61aee0Eric Anholt ctx->ListState.ListVtxfmt.MultiDrawElementsEXT = _mesa_noop_MultiDrawElements; 126592d7ed8a20d4a018ce5324e6537ae7b478b9e5bfEric Anholt ctx->ListState.ListVtxfmt.MultiDrawElementsBaseVertex = _mesa_noop_MultiDrawElementsBaseVertex; 1266fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell _mesa_install_save_vtxfmt( ctx, &ctx->ListState.ListVtxfmt ); 1267fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell} 1268fd12b37dbada6f945a94b93ecf332d0b6a8eef06Keith Whitwell 12698d5c83c467f83b44f5f2e271c4f9cca2d45af518Chia-I Wu 12708d5c83c467f83b44f5f2e271c4f9cca2d45af518Chia-I Wu#endif /* FEATURE_dlist */ 1271