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