1 /**************************************************************************
3 Copyright 2002 VMware, Inc.
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 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.
26 **************************************************************************/
30 * Keith Whitwell <keithw@vmware.com>
39 #include "vbo_attrib.h"
41 /* For display lists, this structure holds a run of vertices of the
42 * same format, and a strictly well-formed set of begin/end pairs,
43 * starting on the first vertex and ending at the last. Vertex
44 * copying on buffer breaks is precomputed according to these
45 * primitives, though there are situations where the copying will need
46 * correction at execute-time, perhaps by replaying the list as
47 * immediate mode commands.
49 * On executing this list, the 'current' values may be updated with
50 * the values of the final vertex, and often no fixup of the start of
51 * the vertex list is required.
53 * Eval and other commands that don't fit into these vertex lists are
54 * compiled using the fallback opcode mechanism provided by dlist.c.
56 struct vbo_save_vertex_list {
57 union gl_dlist_node header;
59 /* Data used in vbo_save_playback_vertex_list */
63 struct pipe_draw_start_count_bias *start_counts;
64 struct pipe_draw_start_count_bias start_count;
69 int16_t private_refcount[VP_MODE_MAX];
70 struct gl_context *ctx;
71 struct pipe_vertex_state *state[VP_MODE_MAX];
72 GLbitfield enabled_attribs[VP_MODE_MAX];
74 /* Cold: used during construction or to handle edge-cases.
75 * It's not part of the structure because we want display list nodes
76 * to be tightly packed to get cache hits. Without this, performance would
77 * decrease by an order of magnitude with 10k display lists.
80 struct gl_vertex_array_object *VAO[VP_MODE_MAX];
81 struct _mesa_index_buffer ib;
83 struct pipe_draw_info info;
85 /* Copy of the final vertex from node->vertex_store->bufferobj.
86 * Keep this in regular (non-VBO) memory to avoid repeated
87 * map/unmap of the VBO when updating GL current data.
89 fi_type *current_data;
91 GLuint vertex_count; /**< number of vertices in this list */
92 GLuint wrap_count; /* number of copied vertices at start */
94 struct _mesa_prim *prims;
96 GLuint min_index, max_index;
103 * Return the stride in bytes of the display list node.
105 static inline GLsizei
106 _vbo_save_get_stride(const struct vbo_save_vertex_list *node)
108 return node->cold->VAO[0]->BufferBinding[0].Stride;
111 /* Default size for the buffer holding the vertices and the indices.
112 * A bigger buffer helps reducing the number of draw calls but may
115 #define VBO_SAVE_BUFFER_SIZE (20*1024*1024)
116 #define VBO_SAVE_PRIM_MODE_MASK 0x3f
118 struct vbo_save_vertex_store {
119 fi_type *buffer_in_ram;
120 GLuint buffer_in_ram_size;
121 GLuint used; /**< Number of 4-byte words used in buffer */
124 struct vbo_save_primitive_store {
125 struct _mesa_prim *prims;
131 void vbo_save_init(struct gl_context *ctx);
132 void vbo_save_destroy(struct gl_context *ctx);
136 void _vbo_loopback_vertex_list(struct gl_context *ctx,
137 const struct vbo_save_vertex_list* node,
143 vbo_save_playback_vertex_list(struct gl_context *ctx, void *data, bool copy_to_current);
146 vbo_save_playback_vertex_list_loopback(struct gl_context *ctx, void *data);
149 vbo_save_api_init(struct vbo_save_context *save);
151 #endif /* VBO_SAVE_H */