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