1 /**************************************************************************
2
3 Copyright 2002 Tungsten Graphics Inc., Cedar Park, Texas.
4
5 All Rights Reserved.
6
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:
13
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
16 Software.
17
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.
25
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 *
32 */
33
34 #ifndef VBO_SAVE_H
35 #define VBO_SAVE_H
36
37 #include "main/mfeatures.h"
38 #include "main/mtypes.h"
39 #include "vbo.h"
40 #include "vbo_attrib.h"
41
42
43 struct vbo_save_copied_vtx {
44 GLfloat buffer[VBO_ATTRIB_MAX * 4 * VBO_MAX_COPIED_VERTS];
45 GLuint nr;
46 };
47
48
49 /* For display lists, this structure holds a run of vertices of the
50 * same format, and a strictly well-formed set of begin/end pairs,
51 * starting on the first vertex and ending at the last. Vertex
52 * copying on buffer breaks is precomputed according to these
53 * primitives, though there are situations where the copying will need
54 * correction at execute-time, perhaps by replaying the list as
55 * immediate mode commands.
56 *
57 * On executing this list, the 'current' values may be updated with
58 * the values of the final vertex, and often no fixup of the start of
59 * the vertex list is required.
60 *
61 * Eval and other commands that don't fit into these vertex lists are
62 * compiled using the fallback opcode mechanism provided by dlist.c.
63 */
64 struct vbo_save_vertex_list {
65 GLubyte attrsz[VBO_ATTRIB_MAX];
66 GLenum attrtype[VBO_ATTRIB_MAX];
67 GLuint vertex_size;
68
69 /* Copy of the final vertex from node->vertex_store->bufferobj.
70 * Keep this in regular (non-VBO) memory to avoid repeated
71 * map/unmap of the VBO when updating GL current data.
72 */
73 GLfloat *current_data;
74 GLuint current_size;
75
76 GLuint buffer_offset;
77 GLuint count; /**< vertex count */
78 GLuint wrap_count; /* number of copied vertices at start */
79 GLboolean dangling_attr_ref; /* current attr implicitly referenced
80 outside the list */
81
82 struct _mesa_prim *prim;
83 GLuint prim_count;
84
85 struct vbo_save_vertex_store *vertex_store;
86 struct vbo_save_primitive_store *prim_store;
87 };
88
89 /* These buffers should be a reasonable size to support upload to
90 * hardware. Current vbo implementation will re-upload on any
91 * changes, so don't make too big or apps which dynamically create
92 * dlists and use only a few times will suffer.
93 *
94 * Consider stategy of uploading regions from the VBO on demand in the
95 * case of dynamic vbos. Then make the dlist code signal that
96 * likelyhood as it occurs. No reason we couldn't change usage
97 * internally even though this probably isn't allowed for client VBOs?
98 */
99 #define VBO_SAVE_BUFFER_SIZE (8*1024) /* dwords */
100 #define VBO_SAVE_PRIM_SIZE 128
101 #define VBO_SAVE_PRIM_MODE_MASK 0x3f
102 #define VBO_SAVE_PRIM_WEAK 0x40
103 #define VBO_SAVE_PRIM_NO_CURRENT_UPDATE 0x80
104
105 #define VBO_SAVE_FALLBACK 0x10000000
106
107 /* Storage to be shared among several vertex_lists.
108 */
109 struct vbo_save_vertex_store {
110 struct gl_buffer_object *bufferobj;
111 GLfloat *buffer;
112 GLuint used;
113 GLuint refcount;
114 };
115
116 struct vbo_save_primitive_store {
117 struct _mesa_prim buffer[VBO_SAVE_PRIM_SIZE];
118 GLuint used;
119 GLuint refcount;
120 };
121
122
123 struct vbo_save_context {
124 struct gl_context *ctx;
125 GLvertexformat vtxfmt;
126 GLvertexformat vtxfmt_noop; /**< Used if out_of_memory is true */
127 struct gl_client_array arrays[VBO_ATTRIB_MAX];
128 const struct gl_client_array *inputs[VBO_ATTRIB_MAX];
129
130 GLubyte attrsz[VBO_ATTRIB_MAX];
131 GLenum attrtype[VBO_ATTRIB_MAX];
132 GLubyte active_sz[VBO_ATTRIB_MAX];
133 GLuint vertex_size;
134
135 GLboolean out_of_memory; /**< True if last VBO allocation failed */
136
137 GLfloat *buffer;
138 GLuint count;
139 GLuint wrap_count;
140 GLuint replay_flags;
141
142 struct _mesa_prim *prim;
143 GLuint prim_count, prim_max;
144
145 struct vbo_save_vertex_store *vertex_store;
146 struct vbo_save_primitive_store *prim_store;
147
148 GLfloat *buffer_ptr; /* cursor, points into buffer */
149 GLfloat vertex[VBO_ATTRIB_MAX*4]; /* current values */
150 GLfloat *attrptr[VBO_ATTRIB_MAX];
151 GLuint vert_count;
152 GLuint max_vert;
153 GLboolean dangling_attr_ref;
154
155 GLuint opcode_vertex_list;
156
157 struct vbo_save_copied_vtx copied;
158
159 GLfloat *current[VBO_ATTRIB_MAX]; /* points into ctx->ListState */
160 GLubyte *currentsz[VBO_ATTRIB_MAX];
161 };
162
163 #if FEATURE_dlist
164
165 void vbo_save_init( struct gl_context *ctx );
166 void vbo_save_destroy( struct gl_context *ctx );
167 void vbo_save_fallback( struct gl_context *ctx, GLboolean fallback );
168
169 /* save_loopback.c:
170 */
171 void vbo_loopback_vertex_list( struct gl_context *ctx,
172 const GLfloat *buffer,
173 const GLubyte *attrsz,
174 const struct _mesa_prim *prim,
175 GLuint prim_count,
176 GLuint wrap_count,
177 GLuint vertex_size);
178
179 /* Callbacks:
180 */
181 void vbo_save_EndList( struct gl_context *ctx );
182 void vbo_save_NewList( struct gl_context *ctx, GLuint list, GLenum mode );
183 void vbo_save_EndCallList( struct gl_context *ctx );
184 void vbo_save_BeginCallList( struct gl_context *ctx, struct gl_display_list *list );
185 void vbo_save_SaveFlushVertices( struct gl_context *ctx );
186 GLboolean vbo_save_NotifyBegin( struct gl_context *ctx, GLenum mode );
187
188 void vbo_save_playback_vertex_list( struct gl_context *ctx, void *data );
189
190 void vbo_save_api_init( struct vbo_save_context *save );
191
192 GLfloat *
193 vbo_save_map_vertex_store(struct gl_context *ctx,
194 struct vbo_save_vertex_store *vertex_store);
195
196 void
197 vbo_save_unmap_vertex_store(struct gl_context *ctx,
198 struct vbo_save_vertex_store *vertex_store);
199
200 #else /* FEATURE_dlist */
201
202 static inline void
vbo_save_init(struct gl_context * ctx)203 vbo_save_init( struct gl_context *ctx )
204 {
205 }
206
207 static inline void
vbo_save_destroy(struct gl_context * ctx)208 vbo_save_destroy( struct gl_context *ctx )
209 {
210 }
211
212 #endif /* FEATURE_dlist */
213
214 #endif /* VBO_SAVE_H */
215