vbo: Remove the now unused vbo draw path.
[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 #include "main/varray.h"
40
41
42 struct _glapi_table;
43 struct _mesa_prim;
44
45
46 struct vbo_context {
47 struct gl_vertex_buffer_binding binding;
48 struct gl_array_attributes current[VBO_ATTRIB_MAX];
49
50 struct gl_vertex_array_object *VAO;
51
52 struct vbo_exec_context exec;
53 struct vbo_save_context save;
54 };
55
56
57 static inline struct vbo_context *
58 vbo_context(struct gl_context *ctx)
59 {
60 return ctx->vbo_context;
61 }
62
63
64 /**
65 * Array to apply the fixed function material aliasing map to
66 * an attribute value used in vbo processing inputs to an attribute
67 * as they appear in the vao.
68 */
69 extern const GLubyte
70 _vbo_attribute_alias_map[VP_MODE_MAX][VERT_ATTRIB_MAX];
71
72
73 /**
74 * Return if format is integer. The immediate mode commands only emit floats
75 * for non-integer types, thus everything else is integer.
76 */
77 static inline GLboolean
78 vbo_attrtype_to_integer_flag(GLenum format)
79 {
80 switch (format) {
81 case GL_FLOAT:
82 case GL_DOUBLE:
83 return GL_FALSE;
84 case GL_INT:
85 case GL_UNSIGNED_INT:
86 case GL_UNSIGNED_INT64_ARB:
87 return GL_TRUE;
88 default:
89 unreachable("Bad vertex attribute type");
90 return GL_FALSE;
91 }
92 }
93
94 static inline GLboolean
95 vbo_attrtype_to_double_flag(GLenum format)
96 {
97 switch (format) {
98 case GL_FLOAT:
99 case GL_INT:
100 case GL_UNSIGNED_INT:
101 case GL_UNSIGNED_INT64_ARB:
102 return GL_FALSE;
103 case GL_DOUBLE:
104 return GL_TRUE;
105 default:
106 unreachable("Bad vertex attribute type");
107 return GL_FALSE;
108 }
109 }
110
111
112 /**
113 * Return default component values for the given format.
114 * The return type is an array of fi_types, because that's how we declare
115 * the vertex storage : floats , integers or unsigned integers.
116 */
117 static inline const fi_type *
118 vbo_get_default_vals_as_union(GLenum format)
119 {
120 static const GLfloat default_float[4] = { 0, 0, 0, 1 };
121 static const GLint default_int[4] = { 0, 0, 0, 1 };
122
123 switch (format) {
124 case GL_FLOAT:
125 return (fi_type *)default_float;
126 case GL_INT:
127 case GL_UNSIGNED_INT:
128 return (fi_type *)default_int;
129 default:
130 unreachable("Bad vertex format");
131 return NULL;
132 }
133 }
134
135
136 /**
137 * Compute the max number of vertices which can be stored in
138 * a vertex buffer, given the current vertex size, and the amount
139 * of space already used.
140 */
141 static inline unsigned
142 vbo_compute_max_verts(const struct vbo_exec_context *exec)
143 {
144 unsigned n = (VBO_VERT_BUFFER_SIZE - exec->vtx.buffer_used) /
145 (exec->vtx.vertex_size * sizeof(GLfloat));
146 if (n == 0)
147 return 0;
148 /* Subtract one so we're always sure to have room for an extra
149 * vertex for GL_LINE_LOOP -> GL_LINE_STRIP conversion.
150 */
151 n--;
152 return n;
153 }
154
155
156 void
157 vbo_try_prim_conversion(struct _mesa_prim *p);
158
159 bool
160 vbo_can_merge_prims(const struct _mesa_prim *p0, const struct _mesa_prim *p1);
161
162 void
163 vbo_merge_prims(struct _mesa_prim *p0, const struct _mesa_prim *p1);
164
165
166 /**
167 * Get the filter mask for vbo draws depending on the vertex_processing_mode.
168 */
169 static inline GLbitfield
170 _vbo_get_vao_filter(gl_vertex_processing_mode vertex_processing_mode)
171 {
172 if (vertex_processing_mode == VP_MODE_FF) {
173 /* The materials mapped into the generic arrays */
174 return VERT_BIT_FF_ALL | VERT_BIT_MAT_ALL;
175 } else {
176 return VERT_BIT_ALL;
177 }
178 }
179
180
181 /**
182 * Translate the bitmask of VBO_ATTRIB_BITs to VERT_ATTRIB_BITS.
183 * Note that position/generic0 attribute aliasing is done
184 * generically in the VAO.
185 */
186 static inline GLbitfield
187 _vbo_get_vao_enabled_from_vbo(gl_vertex_processing_mode vertex_processing_mode,
188 GLbitfield64 enabled)
189 {
190 if (vertex_processing_mode == VP_MODE_FF) {
191 /* The materials mapped into the generic arrays */
192 return (((GLbitfield)enabled) & VERT_BIT_FF_ALL)
193 | (((GLbitfield)(enabled >> VBO_MATERIAL_SHIFT)) & VERT_BIT_MAT_ALL);
194 } else {
195 return ((GLbitfield)enabled) & VERT_BIT_ALL;
196 }
197 }
198
199
200 /**
201 * Set the vertex attrib for vbo draw use.
202 */
203 static inline void
204 _vbo_set_attrib_format(struct gl_context *ctx,
205 struct gl_vertex_array_object *vao,
206 gl_vert_attrib attr, GLintptr buffer_offset,
207 GLubyte size, GLenum16 type, GLuint offset)
208 {
209 const GLboolean integer = vbo_attrtype_to_integer_flag(type);
210 const GLboolean doubles = vbo_attrtype_to_double_flag(type);
211 _mesa_update_array_format(ctx, vao, attr, size, type, GL_RGBA,
212 GL_FALSE, integer, doubles, offset);
213 /* Ptr for userspace arrays */
214 vao->VertexAttrib[attr].Ptr = ADD_POINTERS(buffer_offset, offset);
215 }
216
217
218 #endif /* VBO_PRIVATE_H */