vbo_save.h revision af69d88d
1/************************************************************************** 2 3Copyright 2002 VMware, Inc. 4 5All Rights Reserved. 6 7Permission is hereby granted, free of charge, to any person obtaining a 8copy of this software and associated documentation files (the "Software"), 9to deal in the Software without restriction, including without limitation 10on the rights to use, copy, modify, merge, publish, distribute, sub 11license, and/or sell copies of the Software, and to permit persons to whom 12the Software is furnished to do so, subject to the following conditions: 13 14The above copyright notice and this permission notice (including the next 15paragraph) shall be included in all copies or substantial portions of the 16Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 21VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 22DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 24USE OR OTHER DEALINGS IN THE SOFTWARE. 25 26**************************************************************************/ 27 28/* 29 * Authors: 30 * Keith Whitwell <keithw@vmware.com> 31 * 32 */ 33 34#ifndef VBO_SAVE_H 35#define VBO_SAVE_H 36 37#include "main/mtypes.h" 38#include "vbo.h" 39#include "vbo_attrib.h" 40 41 42struct vbo_save_copied_vtx { 43 GLfloat buffer[VBO_ATTRIB_MAX * 4 * VBO_MAX_COPIED_VERTS]; 44 GLuint nr; 45}; 46 47 48/* For display lists, this structure holds a run of vertices of the 49 * same format, and a strictly well-formed set of begin/end pairs, 50 * starting on the first vertex and ending at the last. Vertex 51 * copying on buffer breaks is precomputed according to these 52 * primitives, though there are situations where the copying will need 53 * correction at execute-time, perhaps by replaying the list as 54 * immediate mode commands. 55 * 56 * On executing this list, the 'current' values may be updated with 57 * the values of the final vertex, and often no fixup of the start of 58 * the vertex list is required. 59 * 60 * Eval and other commands that don't fit into these vertex lists are 61 * compiled using the fallback opcode mechanism provided by dlist.c. 62 */ 63struct vbo_save_vertex_list { 64 GLubyte attrsz[VBO_ATTRIB_MAX]; 65 GLenum attrtype[VBO_ATTRIB_MAX]; 66 GLuint vertex_size; /**< size in GLfloats */ 67 68 /* Copy of the final vertex from node->vertex_store->bufferobj. 69 * Keep this in regular (non-VBO) memory to avoid repeated 70 * map/unmap of the VBO when updating GL current data. 71 */ 72 GLfloat *current_data; 73 GLuint current_size; 74 75 GLuint buffer_offset; 76 GLuint count; /**< vertex count */ 77 GLuint wrap_count; /* number of copied vertices at start */ 78 GLboolean dangling_attr_ref; /* current attr implicitly referenced 79 outside the list */ 80 81 struct _mesa_prim *prim; 82 GLuint prim_count; 83 84 struct vbo_save_vertex_store *vertex_store; 85 struct vbo_save_primitive_store *prim_store; 86}; 87 88/* These buffers should be a reasonable size to support upload to 89 * hardware. Current vbo implementation will re-upload on any 90 * changes, so don't make too big or apps which dynamically create 91 * dlists and use only a few times will suffer. 92 * 93 * Consider stategy of uploading regions from the VBO on demand in the 94 * case of dynamic vbos. Then make the dlist code signal that 95 * likelyhood as it occurs. No reason we couldn't change usage 96 * internally even though this probably isn't allowed for client VBOs? 97 */ 98#define VBO_SAVE_BUFFER_SIZE (8*1024) /* dwords */ 99#define VBO_SAVE_PRIM_SIZE 128 100#define VBO_SAVE_PRIM_MODE_MASK 0x3f 101#define VBO_SAVE_PRIM_WEAK 0x40 102#define VBO_SAVE_PRIM_NO_CURRENT_UPDATE 0x80 103 104#define VBO_SAVE_FALLBACK 0x10000000 105 106/* Storage to be shared among several vertex_lists. 107 */ 108struct vbo_save_vertex_store { 109 struct gl_buffer_object *bufferobj; 110 GLfloat *buffer; 111 GLuint used; 112 GLuint refcount; 113}; 114 115struct vbo_save_primitive_store { 116 struct _mesa_prim buffer[VBO_SAVE_PRIM_SIZE]; 117 GLuint used; 118 GLuint refcount; 119}; 120 121 122struct vbo_save_context { 123 struct gl_context *ctx; 124 GLvertexformat vtxfmt; 125 GLvertexformat vtxfmt_noop; /**< Used if out_of_memory is true */ 126 struct gl_client_array arrays[VBO_ATTRIB_MAX]; 127 const struct gl_client_array *inputs[VBO_ATTRIB_MAX]; 128 129 GLubyte attrsz[VBO_ATTRIB_MAX]; /**< 1, 2, 3 or 4 */ 130 GLenum attrtype[VBO_ATTRIB_MAX]; /**< GL_FLOAT, GL_INT, etc */ 131 GLubyte active_sz[VBO_ATTRIB_MAX]; /**< 1, 2, 3 or 4 */ 132 GLuint vertex_size; /**< size in GLfloats */ 133 134 GLboolean out_of_memory; /**< True if last VBO allocation failed */ 135 136 GLfloat *buffer; 137 GLuint count; 138 GLuint wrap_count; 139 GLuint replay_flags; 140 141 struct _mesa_prim *prim; 142 GLuint prim_count, prim_max; 143 144 struct vbo_save_vertex_store *vertex_store; 145 struct vbo_save_primitive_store *prim_store; 146 147 GLfloat *buffer_ptr; /* cursor, points into buffer */ 148 GLfloat vertex[VBO_ATTRIB_MAX*4]; /* current values */ 149 GLfloat *attrptr[VBO_ATTRIB_MAX]; 150 GLuint vert_count; 151 GLuint max_vert; 152 GLboolean dangling_attr_ref; 153 154 GLuint opcode_vertex_list; 155 156 struct vbo_save_copied_vtx copied; 157 158 GLfloat *current[VBO_ATTRIB_MAX]; /* points into ctx->ListState */ 159 GLubyte *currentsz[VBO_ATTRIB_MAX]; 160}; 161 162void vbo_save_init( struct gl_context *ctx ); 163void vbo_save_destroy( struct gl_context *ctx ); 164void vbo_save_fallback( struct gl_context *ctx, GLboolean fallback ); 165 166/* save_loopback.c: 167 */ 168void vbo_loopback_vertex_list( struct gl_context *ctx, 169 const GLfloat *buffer, 170 const GLubyte *attrsz, 171 const struct _mesa_prim *prim, 172 GLuint prim_count, 173 GLuint wrap_count, 174 GLuint vertex_size); 175 176/* Callbacks: 177 */ 178void vbo_save_EndList( struct gl_context *ctx ); 179void vbo_save_NewList( struct gl_context *ctx, GLuint list, GLenum mode ); 180void vbo_save_EndCallList( struct gl_context *ctx ); 181void vbo_save_BeginCallList( struct gl_context *ctx, struct gl_display_list *list ); 182void vbo_save_SaveFlushVertices( struct gl_context *ctx ); 183GLboolean vbo_save_NotifyBegin( struct gl_context *ctx, GLenum mode ); 184 185void vbo_save_playback_vertex_list( struct gl_context *ctx, void *data ); 186 187void vbo_save_api_init( struct vbo_save_context *save ); 188 189GLfloat * 190vbo_save_map_vertex_store(struct gl_context *ctx, 191 struct vbo_save_vertex_store *vertex_store); 192 193void 194vbo_save_unmap_vertex_store(struct gl_context *ctx, 195 struct vbo_save_vertex_store *vertex_store); 196 197#endif /* VBO_SAVE_H */ 198