vbo: Remove now duplicate _DrawVAO notification.
[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 "main/mtypes.h"
38 #include "vbo.h"
39 #include "vbo_attrib.h"
40
41
42 struct vbo_save_copied_vtx {
43 fi_type 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 */
63 struct vbo_save_vertex_list {
64 struct gl_vertex_array_object *VAO[VP_MODE_MAX];
65
66 /* Copy of the final vertex from node->vertex_store->bufferobj.
67 * Keep this in regular (non-VBO) memory to avoid repeated
68 * map/unmap of the VBO when updating GL current data.
69 */
70 fi_type *current_data;
71
72 GLuint vertex_count; /**< number of vertices in this list */
73 GLuint wrap_count; /* number of copied vertices at start */
74
75 struct _mesa_prim *prims;
76 GLuint prim_count;
77
78 struct vbo_save_primitive_store *prim_store;
79 };
80
81
82 /**
83 * Return the stride in bytes of the display list node.
84 */
85 static inline GLsizei
86 _vbo_save_get_stride(const struct vbo_save_vertex_list *node)
87 {
88 return node->VAO[0]->BufferBinding[0].Stride;
89 }
90
91
92 /**
93 * Return the first referenced vertex index in the display list node.
94 */
95 static inline GLuint
96 _vbo_save_get_min_index(const struct vbo_save_vertex_list *node)
97 {
98 assert(node->prim_count > 0);
99 return node->prims[0].start;
100 }
101
102
103 /**
104 * Return the last referenced vertex index in the display list node.
105 */
106 static inline GLuint
107 _vbo_save_get_max_index(const struct vbo_save_vertex_list *node)
108 {
109 assert(node->prim_count > 0);
110 const struct _mesa_prim *last_prim = &node->prims[node->prim_count - 1];
111 return last_prim->start + last_prim->count - 1;
112 }
113
114
115 /**
116 * Return the vertex count in the display list node.
117 */
118 static inline GLuint
119 _vbo_save_get_vertex_count(const struct vbo_save_vertex_list *node)
120 {
121 assert(node->prim_count > 0);
122 const struct _mesa_prim *first_prim = &node->prims[0];
123 const struct _mesa_prim *last_prim = &node->prims[node->prim_count - 1];
124 return last_prim->start - first_prim->start + last_prim->count;
125 }
126
127
128 /* These buffers should be a reasonable size to support upload to
129 * hardware. Current vbo implementation will re-upload on any
130 * changes, so don't make too big or apps which dynamically create
131 * dlists and use only a few times will suffer.
132 *
133 * Consider stategy of uploading regions from the VBO on demand in the
134 * case of dynamic vbos. Then make the dlist code signal that
135 * likelyhood as it occurs. No reason we couldn't change usage
136 * internally even though this probably isn't allowed for client VBOs?
137 */
138 #define VBO_SAVE_BUFFER_SIZE (256*1024) /* dwords */
139 #define VBO_SAVE_PRIM_SIZE 128
140 #define VBO_SAVE_PRIM_MODE_MASK 0x3f
141 #define VBO_SAVE_PRIM_WEAK 0x40
142 #define VBO_SAVE_PRIM_NO_CURRENT_UPDATE 0x80
143
144 #define VBO_SAVE_FALLBACK 0x10000000
145
146 struct vbo_save_vertex_store {
147 struct gl_buffer_object *bufferobj;
148 fi_type *buffer_map;
149 GLuint used; /**< Number of 4-byte words used in buffer */
150 };
151
152 /* Storage to be shared among several vertex_lists.
153 */
154 struct vbo_save_primitive_store {
155 struct _mesa_prim prims[VBO_SAVE_PRIM_SIZE];
156 GLuint used;
157 GLuint refcount;
158 };
159
160
161 struct vbo_save_context {
162 struct gl_context *ctx;
163 GLvertexformat vtxfmt;
164 GLvertexformat vtxfmt_noop; /**< Used if out_of_memory is true */
165
166 GLbitfield64 enabled; /**< mask of enabled vbo arrays. */
167 GLubyte attrsz[VBO_ATTRIB_MAX]; /**< 1, 2, 3 or 4 */
168 GLenum16 attrtype[VBO_ATTRIB_MAX]; /**< GL_FLOAT, GL_INT, etc */
169 GLubyte active_sz[VBO_ATTRIB_MAX]; /**< 1, 2, 3 or 4 */
170 GLuint vertex_size; /**< size in GLfloats */
171 struct gl_vertex_array_object *VAO[VP_MODE_MAX];
172
173 GLboolean out_of_memory; /**< True if last VBO allocation failed */
174
175 GLbitfield replay_flags;
176
177 struct _mesa_prim *prims;
178 GLuint prim_count, prim_max;
179
180 struct vbo_save_vertex_store *vertex_store;
181 struct vbo_save_primitive_store *prim_store;
182
183 fi_type *buffer_map; /**< Mapping of vertex_store's buffer */
184 fi_type *buffer_ptr; /**< cursor, points into buffer_map */
185 fi_type vertex[VBO_ATTRIB_MAX*4]; /* current values */
186 fi_type *attrptr[VBO_ATTRIB_MAX];
187 GLuint vert_count;
188 GLuint max_vert;
189 GLboolean dangling_attr_ref;
190
191 GLuint opcode_vertex_list;
192
193 struct vbo_save_copied_vtx copied;
194
195 fi_type *current[VBO_ATTRIB_MAX]; /* points into ctx->ListState */
196 GLubyte *currentsz[VBO_ATTRIB_MAX];
197 };
198
199 void vbo_save_init(struct gl_context *ctx);
200 void vbo_save_destroy(struct gl_context *ctx);
201 void vbo_save_fallback(struct gl_context *ctx, GLboolean fallback);
202
203 /* save_loopback.c:
204 */
205 void _vbo_loopback_vertex_list(struct gl_context *ctx,
206 const struct vbo_save_vertex_list* node);
207
208 /* Callbacks:
209 */
210 void
211 vbo_save_playback_vertex_list(struct gl_context *ctx, void *data);
212
213 void
214 vbo_save_api_init(struct vbo_save_context *save);
215
216 fi_type *
217 vbo_save_map_vertex_store(struct gl_context *ctx,
218 struct vbo_save_vertex_store *vertex_store);
219
220 void
221 vbo_save_unmap_vertex_store(struct gl_context *ctx,
222 struct vbo_save_vertex_store *vertex_store);
223
224 #endif /* VBO_SAVE_H */