vbo: Implement method to track the inputs array.
[mesa.git] / src / mesa / vbo / vbo_private.h
1 /*
2 * mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * Types, functions, etc which are private to the VBO module.
28 */
29
30
31 #ifndef VBO_PRIVATE_H
32 #define VBO_PRIVATE_H
33
34
35 #include "vbo/vbo_attrib.h"
36 #include "vbo/vbo_exec.h"
37 #include "vbo/vbo_save.h"
38 #include "main/mtypes.h"
39
40
41 struct _glapi_table;
42 struct _mesa_prim;
43
44
45 struct vbo_context {
46 struct gl_vertex_array currval[VBO_ATTRIB_MAX];
47 /* The array of inputs used for _DrawVAO draws. */
48 struct vbo_inputs draw_arrays;
49
50 struct vbo_exec_context exec;
51 struct vbo_save_context save;
52
53 /* Callback into the driver. This must always succeed, the driver
54 * is responsible for initiating any fallback actions required:
55 */
56 vbo_draw_func draw_prims;
57
58 /* Optional callback for indirect draws. This allows multidraws to not be
59 * broken up, as well as for the actual count to be passed in as a separate
60 * indirect parameter.
61 */
62 vbo_indirect_draw_func draw_indirect_prims;
63 };
64
65
66 static inline struct vbo_context *
67 vbo_context(struct gl_context *ctx)
68 {
69 return ctx->vbo_context;
70 }
71
72
73 /**
74 * Array to apply the fixed function material aliasing map to
75 * an attribute value used in vbo processing inputs to an attribute
76 * as they appear in the vao.
77 */
78 extern const GLubyte
79 _vbo_attribute_alias_map[VP_MODE_MAX][VERT_ATTRIB_MAX];
80
81
82 /**
83 * Return if format is integer. The immediate mode commands only emit floats
84 * for non-integer types, thus everything else is integer.
85 */
86 static inline GLboolean
87 vbo_attrtype_to_integer_flag(GLenum format)
88 {
89 switch (format) {
90 case GL_FLOAT:
91 case GL_DOUBLE:
92 return GL_FALSE;
93 case GL_INT:
94 case GL_UNSIGNED_INT:
95 case GL_UNSIGNED_INT64_ARB:
96 return GL_TRUE;
97 default:
98 unreachable("Bad vertex attribute type");
99 return GL_FALSE;
100 }
101 }
102
103 static inline GLboolean
104 vbo_attrtype_to_double_flag(GLenum format)
105 {
106 switch (format) {
107 case GL_FLOAT:
108 case GL_INT:
109 case GL_UNSIGNED_INT:
110 case GL_UNSIGNED_INT64_ARB:
111 return GL_FALSE;
112 case GL_DOUBLE:
113 return GL_TRUE;
114 default:
115 unreachable("Bad vertex attribute type");
116 return GL_FALSE;
117 }
118 }
119
120
121 /**
122 * Return default component values for the given format.
123 * The return type is an array of fi_types, because that's how we declare
124 * the vertex storage : floats , integers or unsigned integers.
125 */
126 static inline const fi_type *
127 vbo_get_default_vals_as_union(GLenum format)
128 {
129 static const GLfloat default_float[4] = { 0, 0, 0, 1 };
130 static const GLint default_int[4] = { 0, 0, 0, 1 };
131
132 switch (format) {
133 case GL_FLOAT:
134 return (fi_type *)default_float;
135 case GL_INT:
136 case GL_UNSIGNED_INT:
137 return (fi_type *)default_int;
138 default:
139 unreachable("Bad vertex format");
140 return NULL;
141 }
142 }
143
144
145 /**
146 * Compute the max number of vertices which can be stored in
147 * a vertex buffer, given the current vertex size, and the amount
148 * of space already used.
149 */
150 static inline unsigned
151 vbo_compute_max_verts(const struct vbo_exec_context *exec)
152 {
153 unsigned n = (VBO_VERT_BUFFER_SIZE - exec->vtx.buffer_used) /
154 (exec->vtx.vertex_size * sizeof(GLfloat));
155 if (n == 0)
156 return 0;
157 /* Subtract one so we're always sure to have room for an extra
158 * vertex for GL_LINE_LOOP -> GL_LINE_STRIP conversion.
159 */
160 n--;
161 return n;
162 }
163
164
165 void
166 vbo_try_prim_conversion(struct _mesa_prim *p);
167
168 bool
169 vbo_can_merge_prims(const struct _mesa_prim *p0, const struct _mesa_prim *p1);
170
171 void
172 vbo_merge_prims(struct _mesa_prim *p0, const struct _mesa_prim *p1);
173
174
175 #endif /* VBO_PRIVATE_H */