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 /* For display lists, this structure holds a run of vertices of the
41  * same format, and a strictly well-formed set of begin/end pairs,
42  * starting on the first vertex and ending at the last.  Vertex
43  * copying on buffer breaks is precomputed according to these
44  * primitives, though there are situations where the copying will need
45  * correction at execute-time, perhaps by replaying the list as
46  * immediate mode commands.
47  *
48  * On executing this list, the 'current' values may be updated with
49  * the values of the final vertex, and often no fixup of the start of
50  * the vertex list is required.
51  *
52  * Eval and other commands that don't fit into these vertex lists are
53  * compiled using the fallback opcode mechanism provided by dlist.c.
54  */
55 struct vbo_save_vertex_list {
56    /* Data used in vbo_save_playback_vertex_list */
57    struct gl_vertex_array_object *VAO[VP_MODE_MAX];
58 
59    struct {
60       struct pipe_draw_info info;
61       unsigned char *mode;
62       union {
63          struct pipe_draw_start_count_bias *start_counts;
64          struct pipe_draw_start_count_bias start_count;
65       };
66       unsigned num_draws;
67 
68       struct {
69          struct gl_context *ctx;
70          struct pipe_vertex_state *state[VP_MODE_MAX];
71          int private_refcount[VP_MODE_MAX];
72          GLbitfield enabled_attribs[VP_MODE_MAX];
73          struct pipe_draw_vertex_state_info info;
74       } gallium;
75    } merged;
76 
77    /* Cold: used during construction or to handle egde-cases */
78    struct {
79       struct _mesa_index_buffer ib;
80 
81       /* Copy of the final vertex from node->vertex_store->bufferobj.
82        * Keep this in regular (non-VBO) memory to avoid repeated
83        * map/unmap of the VBO when updating GL current data.
84        */
85       fi_type *current_data;
86 
87       GLuint vertex_count;         /**< number of vertices in this list */
88       GLuint wrap_count;		/* number of copied vertices at start */
89 
90       struct _mesa_prim *prims;
91       GLuint prim_count;
92       GLuint min_index, max_index;
93    } *cold;
94 };
95 
96 
97 /**
98  * Return the stride in bytes of the display list node.
99  */
100 static inline GLsizei
_vbo_save_get_stride(const struct vbo_save_vertex_list * node)101 _vbo_save_get_stride(const struct vbo_save_vertex_list *node)
102 {
103    return node->VAO[0]->BufferBinding[0].Stride;
104 }
105 
106 /* Default size for the buffer holding the vertices and the indices.
107  * A bigger buffer helps reducing the number of draw calls but may
108  * waste memory.
109  */
110 #define VBO_SAVE_BUFFER_SIZE (20*1024*1024)
111 #define VBO_SAVE_PRIM_MODE_MASK 0x3f
112 
113 struct vbo_save_vertex_store {
114    fi_type *buffer_in_ram;
115    GLuint buffer_in_ram_size;
116    GLuint used;           /**< Number of 4-byte words used in buffer */
117 };
118 
119 struct vbo_save_primitive_store {
120    struct _mesa_prim *prims;
121    GLuint used;
122    GLuint size;
123 };
124 
125 
126 void vbo_save_init(struct gl_context *ctx);
127 void vbo_save_destroy(struct gl_context *ctx);
128 
129 /* save_loopback.c:
130  */
131 void _vbo_loopback_vertex_list(struct gl_context *ctx,
132                                const struct vbo_save_vertex_list* node,
133                                fi_type *buffer);
134 
135 /* Callbacks:
136  */
137 void
138 vbo_save_playback_vertex_list(struct gl_context *ctx, void *data, bool copy_to_current);
139 
140 void
141 vbo_save_playback_vertex_list_loopback(struct gl_context *ctx, void *data);
142 
143 void
144 vbo_save_api_init(struct vbo_save_context *save);
145 
146 #endif /* VBO_SAVE_H */
147