2 * mesa 3-D graphics library
4 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
27 * Types, functions, etc which are private to the VBO module.
35 #include "vbo/vbo_attrib.h"
36 #include "vbo/vbo_exec.h"
37 #include "vbo/vbo_save.h"
38 #include "main/varray.h"
46 struct gl_vertex_buffer_binding binding
;
47 struct gl_array_attributes current
[VBO_ATTRIB_MAX
];
49 struct gl_vertex_array_object
*VAO
;
51 struct vbo_exec_context exec
;
52 struct vbo_save_context save
;
56 static inline struct vbo_context
*
57 vbo_context(struct gl_context
*ctx
)
59 return ctx
->vbo_context
;
63 static inline const struct vbo_context
*
64 vbo_context_const(const struct gl_context
*ctx
)
66 return ctx
->vbo_context
;
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.
76 _vbo_attribute_alias_map
[VP_MODE_MAX
][VERT_ATTRIB_MAX
];
80 * Return if format is integer. The immediate mode commands only emit floats
81 * for non-integer types, thus everything else is integer.
83 static inline GLboolean
84 vbo_attrtype_to_integer_flag(GLenum format
)
92 case GL_UNSIGNED_INT64_ARB
:
95 unreachable("Bad vertex attribute type");
100 static inline GLboolean
101 vbo_attrtype_to_double_flag(GLenum format
)
106 case GL_UNSIGNED_INT
:
108 case GL_UNSIGNED_INT64_ARB
:
112 unreachable("Bad vertex attribute type");
119 vbo_set_vertex_format(struct gl_vertex_format
* vertex_format
,
120 GLubyte size
, GLenum16 type
)
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
));
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.
133 static inline const fi_type
*
134 vbo_get_default_vals_as_union(GLenum format
)
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 };
143 return (fi_type
*)default_float
;
145 case GL_UNSIGNED_INT
:
146 return (fi_type
*)default_int
;
148 return (fi_type
*)default_double
;
149 case GL_UNSIGNED_INT64_ARB
:
150 return (fi_type
*)default_uint64
;
152 unreachable("Bad vertex format");
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.
163 static inline unsigned
164 vbo_compute_max_verts(const struct vbo_exec_context
*exec
)
166 unsigned n
= (exec
->ctx
->Const
.glBeginEndBufferSize
-
167 exec
->vtx
.buffer_used
) /
168 (exec
->vtx
.vertex_size
* sizeof(GLfloat
));
171 /* Subtract one so we're always sure to have room for an extra
172 * vertex for GL_LINE_LOOP -> GL_LINE_STRIP conversion.
180 vbo_try_prim_conversion(struct _mesa_prim
*p
);
183 vbo_merge_draws(struct gl_context
*ctx
, bool in_dlist
,
184 struct _mesa_prim
*p0
, const struct _mesa_prim
*p1
);
187 vbo_copy_vertices(struct gl_context
*ctx
,
189 struct _mesa_prim
*last_prim
,
190 unsigned vertex_size
,
196 * Get the filter mask for vbo draws depending on the vertex_processing_mode.
198 static inline GLbitfield
199 _vbo_get_vao_filter(gl_vertex_processing_mode vertex_processing_mode
)
201 if (vertex_processing_mode
== VP_MODE_FF
) {
202 /* The materials mapped into the generic arrays */
203 return VERT_BIT_FF_ALL
| VERT_BIT_MAT_ALL
;
211 * Translate the bitmask of VBO_ATTRIB_BITs to VERT_ATTRIB_BITS.
212 * Note that position/generic0 attribute aliasing is done
213 * generically in the VAO.
215 static inline GLbitfield
216 _vbo_get_vao_enabled_from_vbo(gl_vertex_processing_mode vertex_processing_mode
,
217 GLbitfield64 enabled
)
219 if (vertex_processing_mode
== VP_MODE_FF
) {
220 /* The materials mapped into the generic arrays */
221 return (((GLbitfield
)enabled
) & VERT_BIT_FF_ALL
)
222 | (((GLbitfield
)(enabled
>> VBO_MATERIAL_SHIFT
)) & VERT_BIT_MAT_ALL
);
224 return ((GLbitfield
)enabled
) & VERT_BIT_ALL
;
230 * Set the vertex attrib for vbo draw use.
233 _vbo_set_attrib_format(struct gl_context
*ctx
,
234 struct gl_vertex_array_object
*vao
,
235 gl_vert_attrib attr
, GLintptr buffer_offset
,
236 GLubyte size
, GLenum16 type
, GLuint offset
)
238 const GLboolean integer
= vbo_attrtype_to_integer_flag(type
);
239 const GLboolean doubles
= vbo_attrtype_to_double_flag(type
);
243 _mesa_update_array_format(ctx
, vao
, attr
, size
, type
, GL_RGBA
,
244 GL_FALSE
, integer
, doubles
, offset
);
245 /* Ptr for userspace arrays.
246 * For updating the pointer we would need to add the vao->NewArrays flag
247 * to the VAO. But but that is done already unconditionally in
248 * _mesa_update_array_format called above.
250 assert((vao
->NewArrays
| ~vao
->Enabled
) & VERT_BIT(attr
));
251 vao
->VertexAttrib
[attr
].Ptr
= ADD_POINTERS(buffer_offset
, offset
);
255 #endif /* VBO_PRIVATE_H */