vbo: remove redundant code in vbo_exec_fixup_vertex
[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 static inline void
119 vbo_set_vertex_format(struct gl_vertex_format* vertex_format,
120 GLubyte size, GLenum16 type)
121 {
122 _mesa_set_vertex_format(vertex_format, size, type, GL_RGBA, GL_FALSE,
123 vbo_attrtype_to_integer_flag(type),
124 vbo_attrtype_to_double_flag(type));
125 }
126
127
128 /**
129 * Return default component values for the given format.
130 * The return type is an array of fi_types, because that's how we declare
131 * the vertex storage : floats , integers or unsigned integers.
132 */
133 static inline const fi_type *
134 vbo_get_default_vals_as_union(GLenum format)
135 {
136 static const GLfloat default_float[4] = { 0, 0, 0, 1 };
137 static const GLint default_int[4] = { 0, 0, 0, 1 };
138 static const GLdouble default_double[4] = { 0, 0, 0, 1 };
139 static const uint64_t default_uint64[4] = { 0, 0, 0, 1 };
140
141 switch (format) {
142 case GL_FLOAT:
143 return (fi_type *)default_float;
144 case GL_INT:
145 case GL_UNSIGNED_INT:
146 return (fi_type *)default_int;
147 case GL_DOUBLE:
148 return (fi_type *)default_double;
149 case GL_UNSIGNED_INT64_ARB:
150 return (fi_type *)default_uint64;
151 default:
152 unreachable("Bad vertex format");
153 return NULL;
154 }
155 }
156
157
158 /**
159 * Compute the max number of vertices which can be stored in
160 * a vertex buffer, given the current vertex size, and the amount
161 * of space already used.
162 */
163 static inline unsigned
164 vbo_compute_max_verts(const struct vbo_exec_context *exec)
165 {
166 unsigned n = (VBO_VERT_BUFFER_SIZE - exec->vtx.buffer_used) /
167 (exec->vtx.vertex_size * sizeof(GLfloat));
168 if (n == 0)
169 return 0;
170 /* Subtract one so we're always sure to have room for an extra
171 * vertex for GL_LINE_LOOP -> GL_LINE_STRIP conversion.
172 */
173 n--;
174 return n;
175 }
176
177
178 void
179 vbo_try_prim_conversion(struct _mesa_prim *p);
180
181 bool
182 vbo_can_merge_prims(const struct _mesa_prim *p0, const struct _mesa_prim *p1);
183
184 void
185 vbo_merge_prims(struct _mesa_prim *p0, const struct _mesa_prim *p1);
186
187
188 /**
189 * Get the filter mask for vbo draws depending on the vertex_processing_mode.
190 */
191 static inline GLbitfield
192 _vbo_get_vao_filter(gl_vertex_processing_mode vertex_processing_mode)
193 {
194 if (vertex_processing_mode == VP_MODE_FF) {
195 /* The materials mapped into the generic arrays */
196 return VERT_BIT_FF_ALL | VERT_BIT_MAT_ALL;
197 } else {
198 return VERT_BIT_ALL;
199 }
200 }
201
202
203 /**
204 * Translate the bitmask of VBO_ATTRIB_BITs to VERT_ATTRIB_BITS.
205 * Note that position/generic0 attribute aliasing is done
206 * generically in the VAO.
207 */
208 static inline GLbitfield
209 _vbo_get_vao_enabled_from_vbo(gl_vertex_processing_mode vertex_processing_mode,
210 GLbitfield64 enabled)
211 {
212 if (vertex_processing_mode == VP_MODE_FF) {
213 /* The materials mapped into the generic arrays */
214 return (((GLbitfield)enabled) & VERT_BIT_FF_ALL)
215 | (((GLbitfield)(enabled >> VBO_MATERIAL_SHIFT)) & VERT_BIT_MAT_ALL);
216 } else {
217 return ((GLbitfield)enabled) & VERT_BIT_ALL;
218 }
219 }
220
221
222 /**
223 * Set the vertex attrib for vbo draw use.
224 */
225 static inline void
226 _vbo_set_attrib_format(struct gl_context *ctx,
227 struct gl_vertex_array_object *vao,
228 gl_vert_attrib attr, GLintptr buffer_offset,
229 GLubyte size, GLenum16 type, GLuint offset)
230 {
231 const GLboolean integer = vbo_attrtype_to_integer_flag(type);
232 const GLboolean doubles = vbo_attrtype_to_double_flag(type);
233
234 if (doubles)
235 size /= 2;
236 _mesa_update_array_format(ctx, vao, attr, size, type, GL_RGBA,
237 GL_FALSE, integer, doubles, offset);
238 /* Ptr for userspace arrays.
239 * For updating the pointer we would need to add the vao->NewArrays flag
240 * to the VAO. But but that is done already unconditionally in
241 * _mesa_update_array_format called above.
242 */
243 assert((vao->NewArrays | ~vao->Enabled) & VERT_BIT(attr));
244 vao->VertexAttrib[attr].Ptr = ADD_POINTERS(buffer_offset, offset);
245 }
246
247
248 #endif /* VBO_PRIVATE_H */