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