1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci
3bf215546Sopenharmony_ciCopyright 2002 VMware, Inc.
4bf215546Sopenharmony_ci
5bf215546Sopenharmony_ciAll Rights Reserved.
6bf215546Sopenharmony_ci
7bf215546Sopenharmony_ciPermission is hereby granted, free of charge, to any person obtaining a
8bf215546Sopenharmony_cicopy of this software and associated documentation files (the "Software"),
9bf215546Sopenharmony_cito deal in the Software without restriction, including without limitation
10bf215546Sopenharmony_cion the rights to use, copy, modify, merge, publish, distribute, sub
11bf215546Sopenharmony_cilicense, and/or sell copies of the Software, and to permit persons to whom
12bf215546Sopenharmony_cithe Software is furnished to do so, subject to the following conditions:
13bf215546Sopenharmony_ci
14bf215546Sopenharmony_ciThe above copyright notice and this permission notice (including the next
15bf215546Sopenharmony_ciparagraph) shall be included in all copies or substantial portions of the
16bf215546Sopenharmony_ciSoftware.
17bf215546Sopenharmony_ci
18bf215546Sopenharmony_ciTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19bf215546Sopenharmony_ciIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20bf215546Sopenharmony_ciFITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21bf215546Sopenharmony_ciVMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22bf215546Sopenharmony_ciDAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23bf215546Sopenharmony_ciOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24bf215546Sopenharmony_ciUSE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci**************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci/*
29bf215546Sopenharmony_ci * Authors:
30bf215546Sopenharmony_ci *   Keith Whitwell <keithw@vmware.com>
31bf215546Sopenharmony_ci *
32bf215546Sopenharmony_ci */
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#ifndef VBO_SAVE_H
35bf215546Sopenharmony_ci#define VBO_SAVE_H
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include "dlist.h"
38bf215546Sopenharmony_ci#include "vbo.h"
39bf215546Sopenharmony_ci#include "vbo_attrib.h"
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci/* For display lists, this structure holds a run of vertices of the
42bf215546Sopenharmony_ci * same format, and a strictly well-formed set of begin/end pairs,
43bf215546Sopenharmony_ci * starting on the first vertex and ending at the last.  Vertex
44bf215546Sopenharmony_ci * copying on buffer breaks is precomputed according to these
45bf215546Sopenharmony_ci * primitives, though there are situations where the copying will need
46bf215546Sopenharmony_ci * correction at execute-time, perhaps by replaying the list as
47bf215546Sopenharmony_ci * immediate mode commands.
48bf215546Sopenharmony_ci *
49bf215546Sopenharmony_ci * On executing this list, the 'current' values may be updated with
50bf215546Sopenharmony_ci * the values of the final vertex, and often no fixup of the start of
51bf215546Sopenharmony_ci * the vertex list is required.
52bf215546Sopenharmony_ci *
53bf215546Sopenharmony_ci * Eval and other commands that don't fit into these vertex lists are
54bf215546Sopenharmony_ci * compiled using the fallback opcode mechanism provided by dlist.c.
55bf215546Sopenharmony_ci */
56bf215546Sopenharmony_cistruct vbo_save_vertex_list {
57bf215546Sopenharmony_ci   union gl_dlist_node header;
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci   /* Data used in vbo_save_playback_vertex_list */
60bf215546Sopenharmony_ci   unsigned num_draws;
61bf215546Sopenharmony_ci   uint8_t *modes;
62bf215546Sopenharmony_ci   union {
63bf215546Sopenharmony_ci      struct pipe_draw_start_count_bias *start_counts;
64bf215546Sopenharmony_ci      struct pipe_draw_start_count_bias start_count;
65bf215546Sopenharmony_ci   };
66bf215546Sopenharmony_ci   uint8_t mode;
67bf215546Sopenharmony_ci   bool draw_begins;
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_ci   int16_t private_refcount[VP_MODE_MAX];
70bf215546Sopenharmony_ci   struct gl_context *ctx;
71bf215546Sopenharmony_ci   struct pipe_vertex_state *state[VP_MODE_MAX];
72bf215546Sopenharmony_ci   GLbitfield enabled_attribs[VP_MODE_MAX];
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_ci   /* Cold: used during construction or to handle edge-cases.
75bf215546Sopenharmony_ci    * It's not part of the structure because we want display list nodes
76bf215546Sopenharmony_ci    * to be tightly packed to get cache hits. Without this, performance would
77bf215546Sopenharmony_ci    * decrease by an order of magnitude with 10k display lists.
78bf215546Sopenharmony_ci    */
79bf215546Sopenharmony_ci   struct {
80bf215546Sopenharmony_ci      struct gl_vertex_array_object *VAO[VP_MODE_MAX];
81bf215546Sopenharmony_ci      struct _mesa_index_buffer ib;
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ci      struct pipe_draw_info info;
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci      /* Copy of the final vertex from node->vertex_store->bufferobj.
86bf215546Sopenharmony_ci       * Keep this in regular (non-VBO) memory to avoid repeated
87bf215546Sopenharmony_ci       * map/unmap of the VBO when updating GL current data.
88bf215546Sopenharmony_ci       */
89bf215546Sopenharmony_ci      fi_type *current_data;
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_ci      GLuint vertex_count;         /**< number of vertices in this list */
92bf215546Sopenharmony_ci      GLuint wrap_count;		/* number of copied vertices at start */
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci      struct _mesa_prim *prims;
95bf215546Sopenharmony_ci      GLuint prim_count;
96bf215546Sopenharmony_ci      GLuint min_index, max_index;
97bf215546Sopenharmony_ci   } *cold;
98bf215546Sopenharmony_ci};
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci/**
102bf215546Sopenharmony_ci * Return the stride in bytes of the display list node.
103bf215546Sopenharmony_ci */
104bf215546Sopenharmony_cistatic inline GLsizei
105bf215546Sopenharmony_ci_vbo_save_get_stride(const struct vbo_save_vertex_list *node)
106bf215546Sopenharmony_ci{
107bf215546Sopenharmony_ci   return node->cold->VAO[0]->BufferBinding[0].Stride;
108bf215546Sopenharmony_ci}
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ci/* Default size for the buffer holding the vertices and the indices.
111bf215546Sopenharmony_ci * A bigger buffer helps reducing the number of draw calls but may
112bf215546Sopenharmony_ci * waste memory.
113bf215546Sopenharmony_ci */
114bf215546Sopenharmony_ci#define VBO_SAVE_BUFFER_SIZE (20*1024*1024)
115bf215546Sopenharmony_ci#define VBO_SAVE_PRIM_MODE_MASK 0x3f
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_cistruct vbo_save_vertex_store {
118bf215546Sopenharmony_ci   fi_type *buffer_in_ram;
119bf215546Sopenharmony_ci   GLuint buffer_in_ram_size;
120bf215546Sopenharmony_ci   GLuint used;           /**< Number of 4-byte words used in buffer */
121bf215546Sopenharmony_ci};
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_cistruct vbo_save_primitive_store {
124bf215546Sopenharmony_ci   struct _mesa_prim *prims;
125bf215546Sopenharmony_ci   GLuint used;
126bf215546Sopenharmony_ci   GLuint size;
127bf215546Sopenharmony_ci};
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_civoid vbo_save_init(struct gl_context *ctx);
131bf215546Sopenharmony_civoid vbo_save_destroy(struct gl_context *ctx);
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_ci/* save_loopback.c:
134bf215546Sopenharmony_ci */
135bf215546Sopenharmony_civoid _vbo_loopback_vertex_list(struct gl_context *ctx,
136bf215546Sopenharmony_ci                               const struct vbo_save_vertex_list* node,
137bf215546Sopenharmony_ci                               fi_type *buffer);
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ci/* Callbacks:
140bf215546Sopenharmony_ci */
141bf215546Sopenharmony_civoid
142bf215546Sopenharmony_civbo_save_playback_vertex_list(struct gl_context *ctx, void *data, bool copy_to_current);
143bf215546Sopenharmony_ci
144bf215546Sopenharmony_civoid
145bf215546Sopenharmony_civbo_save_playback_vertex_list_loopback(struct gl_context *ctx, void *data);
146bf215546Sopenharmony_ci
147bf215546Sopenharmony_civoid
148bf215546Sopenharmony_civbo_save_api_init(struct vbo_save_context *save);
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_ci#endif /* VBO_SAVE_H */
151