1 /**************************************************************************
3 Copyright 2002 Tungsten Graphics Inc., Cedar Park, Texas.
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
37 #include "main/mtypes.h"
39 #include "vbo_attrib.h"
42 struct vbo_save_copied_vtx
{
43 GLfloat buffer
[VBO_ATTRIB_MAX
* 4 * VBO_MAX_COPIED_VERTS
];
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.
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.
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.
63 struct vbo_save_vertex_list
{
64 GLubyte attrsz
[VBO_ATTRIB_MAX
];
69 GLuint wrap_count
; /* number of copied vertices at start */
70 GLboolean dangling_attr_ref
; /* current attr implicitly referenced
73 struct _mesa_prim
*prim
;
76 struct vbo_save_vertex_store
*vertex_store
;
77 struct vbo_save_primitive_store
*prim_store
;
80 /* These buffers should be a reasonable size to support upload to
81 * hardware. Current vbo implementation will re-upload on any
82 * changes, so don't make too big or apps which dynamically create
83 * dlists and use only a few times will suffer.
85 * Consider stategy of uploading regions from the VBO on demand in the
86 * case of dynamic vbos. Then make the dlist code signal that
87 * likelyhood as it occurs. No reason we couldn't change usage
88 * internally even though this probably isn't allowed for client VBOs?
90 #define VBO_SAVE_BUFFER_SIZE (8*1024) /* dwords */
91 #define VBO_SAVE_PRIM_SIZE 128
92 #define VBO_SAVE_PRIM_WEAK 0x40
94 #define VBO_SAVE_FALLBACK 0x10000000
96 /* Storage to be shared among several vertex_lists.
98 struct vbo_save_vertex_store
{
99 struct gl_buffer_object
*bufferobj
;
105 struct vbo_save_primitive_store
{
106 struct _mesa_prim buffer
[VBO_SAVE_PRIM_SIZE
];
112 struct vbo_save_context
{
114 GLvertexformat vtxfmt
;
115 struct gl_client_array arrays
[VBO_ATTRIB_MAX
];
116 const struct gl_client_array
*inputs
[VBO_ATTRIB_MAX
];
118 GLubyte attrsz
[VBO_ATTRIB_MAX
];
119 GLubyte active_sz
[VBO_ATTRIB_MAX
];
127 struct _mesa_prim
*prim
;
128 GLuint prim_count
, prim_max
;
130 struct vbo_save_vertex_store
*vertex_store
;
131 struct vbo_save_primitive_store
*prim_store
;
133 GLfloat
*vbptr
; /* cursor, points into buffer */
134 GLfloat vertex
[VBO_ATTRIB_MAX
*4]; /* current values */
135 GLfloat
*attrptr
[VBO_ATTRIB_MAX
];
138 GLboolean dangling_attr_ref
;
139 GLboolean have_materials
;
141 GLuint opcode_vertex_list
;
143 struct vbo_save_copied_vtx copied
;
145 GLfloat
*current
[VBO_ATTRIB_MAX
]; /* points into ctx->ListState */
146 GLubyte
*currentsz
[VBO_ATTRIB_MAX
];
150 void vbo_save_init( GLcontext
*ctx
);
151 void vbo_save_destroy( GLcontext
*ctx
);
152 void vbo_save_fallback( GLcontext
*ctx
, GLboolean fallback
);
156 void vbo_loopback_vertex_list( GLcontext
*ctx
,
157 const GLfloat
*buffer
,
158 const GLubyte
*attrsz
,
159 const struct _mesa_prim
*prim
,
166 void vbo_save_EndList( GLcontext
*ctx
);
167 void vbo_save_NewList( GLcontext
*ctx
, GLuint list
, GLenum mode
);
168 void vbo_save_EndCallList( GLcontext
*ctx
);
169 void vbo_save_BeginCallList( GLcontext
*ctx
, struct mesa_display_list
*list
);
170 void vbo_save_SaveFlushVertices( GLcontext
*ctx
);
171 GLboolean
vbo_save_NotifyBegin( GLcontext
*ctx
, GLenum mode
);
173 void vbo_save_playback_vertex_list( GLcontext
*ctx
, void *data
);
175 void vbo_save_api_init( struct vbo_save_context
*save
);