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"
39 #include "main/macros.h"
44 static inline struct vbo_context
*
45 vbo_context(struct gl_context
*ctx
)
47 return &ctx
->vbo_context
;
51 static inline const struct vbo_context
*
52 vbo_context_const(const struct gl_context
*ctx
)
54 return &ctx
->vbo_context
;
59 * Array to apply the fixed function material aliasing map to
60 * an attribute value used in vbo processing inputs to an attribute
61 * as they appear in the vao.
64 _vbo_attribute_alias_map
[VP_MODE_MAX
][VERT_ATTRIB_MAX
];
68 * Return if format is integer. The immediate mode commands only emit floats
69 * for non-integer types, thus everything else is integer.
71 static inline GLboolean
72 vbo_attrtype_to_integer_flag(GLenum format
)
80 case GL_UNSIGNED_INT64_ARB
:
83 unreachable("Bad vertex attribute type");
88 static inline GLboolean
89 vbo_attrtype_to_double_flag(GLenum format
)
96 case GL_UNSIGNED_INT64_ARB
:
100 unreachable("Bad vertex attribute type");
107 vbo_set_vertex_format(struct gl_vertex_format
* vertex_format
,
108 GLubyte size
, GLenum16 type
)
110 _mesa_set_vertex_format(vertex_format
, size
, type
, GL_RGBA
, GL_FALSE
,
111 vbo_attrtype_to_integer_flag(type
),
112 vbo_attrtype_to_double_flag(type
));
117 * Return default component values for the given format.
118 * The return type is an array of fi_types, because that's how we declare
119 * the vertex storage : floats , integers or unsigned integers.
121 static inline const fi_type
*
122 vbo_get_default_vals_as_union(GLenum format
)
124 static const GLfloat default_float
[4] = { 0, 0, 0, 1 };
125 static const GLint default_int
[4] = { 0, 0, 0, 1 };
126 static const GLdouble default_double
[4] = { 0, 0, 0, 1 };
127 static const uint64_t default_uint64
[4] = { 0, 0, 0, 1 };
131 return (fi_type
*)default_float
;
133 case GL_UNSIGNED_INT
:
134 return (fi_type
*)default_int
;
136 return (fi_type
*)default_double
;
137 case GL_UNSIGNED_INT64_ARB
:
138 return (fi_type
*)default_uint64
;
140 unreachable("Bad vertex format");
147 * Compute the max number of vertices which can be stored in
148 * a vertex buffer, given the current vertex size, and the amount
149 * of space already used.
151 static inline unsigned
152 vbo_compute_max_verts(const struct vbo_exec_context
*exec
)
154 unsigned n
= (exec
->ctx
->Const
.glBeginEndBufferSize
-
155 exec
->vtx
.buffer_used
) /
156 (exec
->vtx
.vertex_size
* sizeof(GLfloat
));
159 /* Subtract one so we're always sure to have room for an extra
160 * vertex for GL_LINE_LOOP -> GL_LINE_STRIP conversion.
168 vbo_try_prim_conversion(struct _mesa_prim
*p
);
171 vbo_merge_draws(struct gl_context
*ctx
, bool in_dlist
,
172 struct _mesa_prim
*p0
, const struct _mesa_prim
*p1
);
175 vbo_copy_vertices(struct gl_context
*ctx
,
177 struct _mesa_prim
*last_prim
,
178 unsigned vertex_size
,
184 * Get the filter mask for vbo draws depending on the vertex_processing_mode.
186 static inline GLbitfield
187 _vbo_get_vao_filter(gl_vertex_processing_mode vertex_processing_mode
)
189 if (vertex_processing_mode
== VP_MODE_FF
) {
190 /* The materials mapped into the generic arrays */
191 return VERT_BIT_FF_ALL
| VERT_BIT_MAT_ALL
;
199 * Translate the bitmask of VBO_ATTRIB_BITs to VERT_ATTRIB_BITS.
200 * Note that position/generic0 attribute aliasing is done
201 * generically in the VAO.
203 static inline GLbitfield
204 _vbo_get_vao_enabled_from_vbo(gl_vertex_processing_mode vertex_processing_mode
,
205 GLbitfield64 enabled
)
207 if (vertex_processing_mode
== VP_MODE_FF
) {
208 /* The materials mapped into the generic arrays */
209 return (((GLbitfield
)enabled
) & VERT_BIT_FF_ALL
)
210 | (((GLbitfield
)(enabled
>> VBO_MATERIAL_SHIFT
)) & VERT_BIT_MAT_ALL
);
212 return ((GLbitfield
)enabled
) & VERT_BIT_ALL
;
218 * Set the vertex attrib for vbo draw use.
221 _vbo_set_attrib_format(struct gl_context
*ctx
,
222 struct gl_vertex_array_object
*vao
,
223 gl_vert_attrib attr
, GLintptr buffer_offset
,
224 GLubyte size
, GLenum16 type
, GLuint offset
)
226 const GLboolean integer
= vbo_attrtype_to_integer_flag(type
);
227 const GLboolean doubles
= vbo_attrtype_to_double_flag(type
);
231 _mesa_update_array_format(ctx
, vao
, attr
, size
, type
, GL_RGBA
,
232 GL_FALSE
, integer
, doubles
, offset
);
233 vao
->NewArrays
|= vao
->Enabled
& VERT_BIT(attr
);
234 vao
->VertexAttrib
[attr
].Ptr
= ADD_POINTERS(buffer_offset
, offset
);
238 #endif /* VBO_PRIVATE_H */