2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
5 * (C) Copyright IBM Corporation 2006
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
32 #include "glformats.h"
39 * Functions for the GL_ARB_vertex_array_object extension.
41 * \author Ian Romanick <idr@us.ibm.com>
49 extern struct gl_vertex_array_object
*
50 _mesa_lookup_vao(struct gl_context
*ctx
, GLuint id
);
52 extern struct gl_vertex_array_object
*
53 _mesa_lookup_vao_err(struct gl_context
*ctx
, GLuint id
, const char *caller
);
55 extern struct gl_vertex_array_object
*
56 _mesa_new_vao(struct gl_context
*ctx
, GLuint name
);
59 _mesa_delete_vao(struct gl_context
*ctx
, struct gl_vertex_array_object
*obj
);
62 _mesa_reference_vao_(struct gl_context
*ctx
,
63 struct gl_vertex_array_object
**ptr
,
64 struct gl_vertex_array_object
*vao
);
67 _mesa_reference_vao(struct gl_context
*ctx
,
68 struct gl_vertex_array_object
**ptr
,
69 struct gl_vertex_array_object
*vao
)
72 _mesa_reference_vao_(ctx
, ptr
, vao
);
77 _mesa_initialize_vao(struct gl_context
*ctx
,
78 struct gl_vertex_array_object
*obj
, GLuint name
);
82 _mesa_update_vao_derived_arrays(struct gl_context
*ctx
,
83 struct gl_vertex_array_object
*vao
);
87 * Mark the vao as shared and immutable, do remaining updates.
90 _mesa_set_vao_immutable(struct gl_context
*ctx
,
91 struct gl_vertex_array_object
*vao
);
94 /* Returns true if all varying arrays reside in vbos */
96 _mesa_all_varyings_in_vbos(const struct gl_vertex_array_object
*vao
);
98 /* Returns true if all vbos are unmapped */
100 _mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object
*vao
);
104 _mesa_vao_map_arrays(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
108 _mesa_vao_map(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
113 _mesa_vao_unmap_arrays(struct gl_context
*ctx
,
114 struct gl_vertex_array_object
*vao
);
117 _mesa_vao_unmap(struct gl_context
*ctx
,
118 struct gl_vertex_array_object
*vao
);
122 * Array to apply the position/generic0 aliasing map to
123 * an attribute value used in vertex processing inputs to an attribute
124 * as they appear in the vao.
127 _mesa_vao_attribute_map
[ATTRIBUTE_MAP_MODE_MAX
][VERT_ATTRIB_MAX
];
131 * Apply the position/generic0 aliasing map to a bitfield from the vao.
132 * Use for example to convert gl_vertex_array_object::Enabled
133 * or gl_vertex_buffer_binding::_VertexBinding from the vao numbering to
134 * the numbering used with vertex processing inputs.
136 static inline GLbitfield
137 _mesa_vao_enable_to_vp_inputs(gl_attribute_map_mode mode
, GLbitfield enabled
)
140 case ATTRIBUTE_MAP_MODE_IDENTITY
:
142 case ATTRIBUTE_MAP_MODE_POSITION
:
143 /* Copy VERT_ATTRIB_POS enable bit into GENERIC0 position */
144 return (enabled
& ~VERT_BIT_GENERIC0
)
145 | ((enabled
& VERT_BIT_POS
) << VERT_ATTRIB_GENERIC0
);
146 case ATTRIBUTE_MAP_MODE_GENERIC0
:
147 /* Copy VERT_ATTRIB_GENERIC0 enable bit into POS position */
148 return (enabled
& ~VERT_BIT_POS
)
149 | ((enabled
& VERT_BIT_GENERIC0
) >> VERT_ATTRIB_GENERIC0
);
157 * Return the vp_inputs enabled bitmask after application of
158 * the position/generic0 aliasing map.
160 static inline GLbitfield
161 _mesa_get_vao_vp_inputs(const struct gl_vertex_array_object
*vao
)
163 const gl_attribute_map_mode mode
= vao
->_AttributeMapMode
;
164 return _mesa_vao_enable_to_vp_inputs(mode
, vao
->Enabled
);
169 * Helper functions for consuming backends to walk the
170 * ctx->Array._DrawVAO for driver side array setup.
171 * Note that mesa provides preprocessed minimal binding information
172 * in the VAO. See _mesa_update_vao_derived_arrays for documentation.
176 * Return enabled vertex attribute bits for draw.
178 static inline GLbitfield
179 _mesa_draw_array_bits(const struct gl_context
*ctx
)
181 return ctx
->Array
._DrawVAOEnabledAttribs
;
186 * Return enabled buffer object vertex attribute bits for draw.
188 * Needs the a fully updated VAO ready for draw.
190 static inline GLbitfield
191 _mesa_draw_vbo_array_bits(const struct gl_context
*ctx
)
193 const struct gl_vertex_array_object
*const vao
= ctx
->Array
._DrawVAO
;
194 assert(vao
->NewArrays
== 0);
195 return vao
->_EffEnabledVBO
& ctx
->Array
._DrawVAOEnabledAttribs
;
200 * Return enabled user space vertex attribute bits for draw.
202 * Needs the a fully updated VAO ready for draw.
204 static inline GLbitfield
205 _mesa_draw_user_array_bits(const struct gl_context
*ctx
)
207 const struct gl_vertex_array_object
*const vao
= ctx
->Array
._DrawVAO
;
208 assert(vao
->NewArrays
== 0);
209 return ~vao
->_EffEnabledVBO
& ctx
->Array
._DrawVAOEnabledAttribs
;
214 * Return enabled current values attribute bits for draw.
216 static inline GLbitfield
217 _mesa_draw_current_bits(const struct gl_context
*ctx
)
219 return ~ctx
->Array
._DrawVAOEnabledAttribs
& VERT_BIT_ALL
;
224 * Return vertex buffer binding provided the attribute struct.
226 * Needs the a fully updated VAO ready for draw.
228 static inline const struct gl_vertex_buffer_binding
*
229 _mesa_draw_buffer_binding_from_attrib(const struct gl_vertex_array_object
*vao
,
230 const struct gl_array_attributes
*attrib
)
232 assert(vao
->NewArrays
== 0);
233 return &vao
->BufferBinding
[attrib
->_EffBufferBindingIndex
];
238 * Return vertex array attribute provided the attribute number.
240 static inline const struct gl_array_attributes
*
241 _mesa_draw_array_attrib(const struct gl_vertex_array_object
*vao
,
244 assert(vao
->NewArrays
== 0);
245 const gl_attribute_map_mode map_mode
= vao
->_AttributeMapMode
;
246 return &vao
->VertexAttrib
[_mesa_vao_attribute_map
[map_mode
][attr
]];
251 * Return vertex buffer binding provided an attribute number.
253 static inline const struct gl_vertex_buffer_binding
*
254 _mesa_draw_buffer_binding(const struct gl_vertex_array_object
*vao
,
257 const struct gl_array_attributes
*const attrib
258 = _mesa_draw_array_attrib(vao
, attr
);
259 return _mesa_draw_buffer_binding_from_attrib(vao
, attrib
);
264 * Return vertex attribute bits bound at the provided binding.
266 * Needs the a fully updated VAO ready for draw.
268 static inline GLbitfield
269 _mesa_draw_bound_attrib_bits(const struct gl_vertex_buffer_binding
*binding
)
271 return binding
->_EffBoundArrays
;
276 * Return the vertex offset bound at the provided binding.
278 * Needs the a fully updated VAO ready for draw.
280 static inline GLintptr
281 _mesa_draw_binding_offset(const struct gl_vertex_buffer_binding
*binding
)
283 return binding
->_EffOffset
;
288 * Return the relative offset of the provided attrib.
290 * Needs the a fully updated VAO ready for draw.
292 static inline GLushort
293 _mesa_draw_attributes_relative_offset(const struct gl_array_attributes
*attrib
)
295 return attrib
->_EffRelativeOffset
;
300 * Return a current value vertex array attribute provided the attribute number.
302 static inline const struct gl_array_attributes
*
303 _mesa_draw_current_attrib(const struct gl_context
*ctx
, gl_vert_attrib attr
)
305 return _vbo_current_attrib(ctx
, attr
);
310 * Return true if we have the VERT_ATTRIB_EDGEFLAG array enabled.
313 _mesa_draw_edge_flag_array_enabled(const struct gl_context
*ctx
)
315 return ctx
->Array
._DrawVAOEnabledAttribs
& VERT_BIT_EDGEFLAG
;
320 * Return the attrib for the given attribute.
322 static inline const struct gl_array_attributes
*
323 _mesa_draw_attrib(const struct gl_context
*ctx
, gl_vert_attrib attr
)
325 if (ctx
->Array
._DrawVAOEnabledAttribs
& VERT_BIT(attr
)) {
326 const struct gl_vertex_array_object
*vao
= ctx
->Array
._DrawVAO
;
327 return _mesa_draw_array_attrib(vao
, attr
);
329 return _vbo_current_attrib(ctx
, attr
);
335 * Return the attrib, binding pair for the given attribute.
338 _mesa_draw_attrib_and_binding(const struct gl_context
*ctx
, gl_vert_attrib attr
,
339 const struct gl_array_attributes
**attrib
,
340 const struct gl_vertex_buffer_binding
**binding
)
342 if (ctx
->Array
._DrawVAOEnabledAttribs
& VERT_BIT(attr
)) {
343 const struct gl_vertex_array_object
*vao
= ctx
->Array
._DrawVAO
;
344 *attrib
= _mesa_draw_array_attrib(vao
, attr
);
345 *binding
= _mesa_draw_buffer_binding_from_attrib(vao
, *attrib
);
347 *attrib
= _vbo_current_attrib(ctx
, attr
);
348 *binding
= _vbo_current_binding(ctx
);
359 _mesa_BindVertexArray_no_error(GLuint id
);
361 void GLAPIENTRY
_mesa_BindVertexArray( GLuint id
);
364 _mesa_DeleteVertexArrays_no_error(GLsizei n
, const GLuint
*ids
);
366 void GLAPIENTRY
_mesa_DeleteVertexArrays(GLsizei n
, const GLuint
*ids
);
369 _mesa_GenVertexArrays_no_error(GLsizei n
, GLuint
*arrays
);
371 void GLAPIENTRY
_mesa_GenVertexArrays(GLsizei n
, GLuint
*arrays
);
374 _mesa_CreateVertexArrays_no_error(GLsizei n
, GLuint
*arrays
);
376 void GLAPIENTRY
_mesa_CreateVertexArrays(GLsizei n
, GLuint
*arrays
);
378 GLboolean GLAPIENTRY
_mesa_IsVertexArray( GLuint id
);
381 _mesa_VertexArrayElementBuffer_no_error(GLuint vaobj
, GLuint buffer
);
383 void GLAPIENTRY
_mesa_VertexArrayElementBuffer(GLuint vaobj
, GLuint buffer
);
385 void GLAPIENTRY
_mesa_GetVertexArrayiv(GLuint vaobj
, GLenum pname
, GLint
*param
);
387 #endif /* ARRAYOBJ_H */