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 * Array to apply the position/generic0 aliasing map to
105 * an attribute value used in vertex processing inputs to an attribute
106 * as they appear in the vao.
109 _mesa_vao_attribute_map
[ATTRIBUTE_MAP_MODE_MAX
][VERT_ATTRIB_MAX
];
113 * Apply the position/generic0 aliasing map to a bitfield from the vao.
114 * Use for example to convert gl_vertex_array_object::_Enabled
115 * or gl_vertex_buffer_binding::_VertexBinding from the vao numbering to
116 * the numbering used with vertex processing inputs.
118 static inline GLbitfield
119 _mesa_vao_enable_to_vp_inputs(gl_attribute_map_mode mode
, GLbitfield enabled
)
122 case ATTRIBUTE_MAP_MODE_IDENTITY
:
124 case ATTRIBUTE_MAP_MODE_POSITION
:
125 /* Copy VERT_ATTRIB_POS enable bit into GENERIC0 position */
126 return (enabled
& ~VERT_BIT_GENERIC0
)
127 | ((enabled
& VERT_BIT_POS
) << VERT_ATTRIB_GENERIC0
);
128 case ATTRIBUTE_MAP_MODE_GENERIC0
:
129 /* Copy VERT_ATTRIB_GENERIC0 enable bit into POS position */
130 return (enabled
& ~VERT_BIT_POS
)
131 | ((enabled
& VERT_BIT_GENERIC0
) >> VERT_ATTRIB_GENERIC0
);
139 * Return the vp_inputs enabled bitmask after application of
140 * the position/generic0 aliasing map.
142 static inline GLbitfield
143 _mesa_get_vao_vp_inputs(const struct gl_vertex_array_object
*vao
)
145 const gl_attribute_map_mode mode
= vao
->_AttributeMapMode
;
146 return _mesa_vao_enable_to_vp_inputs(mode
, vao
->_Enabled
);
151 * Helper functions for consuming backends to walk the
152 * ctx->Array._DrawVAO for driver side array setup.
153 * Note that mesa provides preprocessed minimal binding information
154 * in the VAO. See _mesa_update_vao_derived_arrays for documentation.
158 * Return enabled vertex attribute bits for draw.
160 static inline GLbitfield
161 _mesa_draw_array_bits(const struct gl_context
*ctx
)
163 return ctx
->Array
._DrawVAOEnabledAttribs
;
168 * Return enabled buffer object vertex attribute bits for draw.
170 * Needs the a fully updated VAO ready for draw.
172 static inline GLbitfield
173 _mesa_draw_vbo_array_bits(const struct gl_context
*ctx
)
175 const struct gl_vertex_array_object
*const vao
= ctx
->Array
._DrawVAO
;
176 assert(vao
->NewArrays
== 0);
177 return vao
->_EffEnabledVBO
& ctx
->Array
._DrawVAOEnabledAttribs
;
182 * Return enabled user space vertex attribute bits for draw.
184 * Needs the a fully updated VAO ready for draw.
186 static inline GLbitfield
187 _mesa_draw_user_array_bits(const struct gl_context
*ctx
)
189 const struct gl_vertex_array_object
*const vao
= ctx
->Array
._DrawVAO
;
190 assert(vao
->NewArrays
== 0);
191 return ~vao
->_EffEnabledVBO
& ctx
->Array
._DrawVAOEnabledAttribs
;
196 * Return enabled current values attribute bits for draw.
198 static inline GLbitfield
199 _mesa_draw_current_bits(const struct gl_context
*ctx
)
201 return ~ctx
->Array
._DrawVAOEnabledAttribs
& VERT_BIT_ALL
;
206 * Return vertex buffer binding provided the attribute struct.
208 * Needs the a fully updated VAO ready for draw.
210 static inline const struct gl_vertex_buffer_binding
*
211 _mesa_draw_buffer_binding_from_attrib(const struct gl_vertex_array_object
*vao
,
212 const struct gl_array_attributes
*attrib
)
214 assert(vao
->NewArrays
== 0);
215 return &vao
->BufferBinding
[attrib
->_EffBufferBindingIndex
];
220 * Return vertex array attribute provided the attribute number.
222 static inline const struct gl_array_attributes
*
223 _mesa_draw_array_attrib(const struct gl_vertex_array_object
*vao
,
226 assert(vao
->NewArrays
== 0);
227 const gl_attribute_map_mode map_mode
= vao
->_AttributeMapMode
;
228 return &vao
->VertexAttrib
[_mesa_vao_attribute_map
[map_mode
][attr
]];
233 * Return vertex buffer binding provided an attribute number.
235 static inline const struct gl_vertex_buffer_binding
*
236 _mesa_draw_buffer_binding(const struct gl_vertex_array_object
*vao
,
239 const struct gl_array_attributes
*const attrib
240 = _mesa_draw_array_attrib(vao
, attr
);
241 return _mesa_draw_buffer_binding_from_attrib(vao
, attrib
);
246 * Return vertex attribute bits bound at the provided binding.
248 * Needs the a fully updated VAO ready for draw.
250 static inline GLbitfield
251 _mesa_draw_bound_attrib_bits(const struct gl_vertex_buffer_binding
*binding
)
253 return binding
->_EffBoundArrays
;
258 * Return the vertex offset bound at the provided binding.
260 * Needs the a fully updated VAO ready for draw.
262 static inline GLintptr
263 _mesa_draw_binding_offset(const struct gl_vertex_buffer_binding
*binding
)
265 return binding
->_EffOffset
;
270 * Return the relative offset of the provided attrib.
272 * Needs the a fully updated VAO ready for draw.
274 static inline GLushort
275 _mesa_draw_attributes_relative_offset(const struct gl_array_attributes
*attrib
)
277 return attrib
->_EffRelativeOffset
;
282 * Return a current value vertex array attribute provided the attribute number.
284 static inline const struct gl_array_attributes
*
285 _mesa_draw_current_attrib(const struct gl_context
*ctx
, gl_vert_attrib attr
)
287 return _vbo_current_attrib(ctx
, attr
);
292 * Return true if we have the VERT_ATTRIB_EDGEFLAG array enabled.
295 _mesa_draw_edge_flag_array_enabled(const struct gl_context
*ctx
)
297 return ctx
->Array
._DrawVAOEnabledAttribs
& VERT_BIT_EDGEFLAG
;
302 * Return the attrib for the given attribute.
304 static inline const struct gl_array_attributes
*
305 _mesa_draw_attrib(const struct gl_context
*ctx
, gl_vert_attrib attr
)
307 if (ctx
->Array
._DrawVAOEnabledAttribs
& VERT_BIT(attr
)) {
308 const struct gl_vertex_array_object
*vao
= ctx
->Array
._DrawVAO
;
309 return _mesa_draw_array_attrib(vao
, attr
);
311 return _vbo_current_attrib(ctx
, attr
);
317 * Return the attrib, binding pair for the given attribute.
320 _mesa_draw_attrib_and_binding(const struct gl_context
*ctx
, gl_vert_attrib attr
,
321 const struct gl_array_attributes
**attrib
,
322 const struct gl_vertex_buffer_binding
**binding
)
324 if (ctx
->Array
._DrawVAOEnabledAttribs
& VERT_BIT(attr
)) {
325 const struct gl_vertex_array_object
*vao
= ctx
->Array
._DrawVAO
;
326 *attrib
= _mesa_draw_array_attrib(vao
, attr
);
327 *binding
= _mesa_draw_buffer_binding_from_attrib(vao
, *attrib
);
329 *attrib
= _vbo_current_attrib(ctx
, attr
);
330 *binding
= _vbo_current_binding(ctx
);
341 _mesa_BindVertexArray_no_error(GLuint id
);
343 void GLAPIENTRY
_mesa_BindVertexArray( GLuint id
);
346 _mesa_DeleteVertexArrays_no_error(GLsizei n
, const GLuint
*ids
);
348 void GLAPIENTRY
_mesa_DeleteVertexArrays(GLsizei n
, const GLuint
*ids
);
351 _mesa_GenVertexArrays_no_error(GLsizei n
, GLuint
*arrays
);
353 void GLAPIENTRY
_mesa_GenVertexArrays(GLsizei n
, GLuint
*arrays
);
356 _mesa_CreateVertexArrays_no_error(GLsizei n
, GLuint
*arrays
);
358 void GLAPIENTRY
_mesa_CreateVertexArrays(GLsizei n
, GLuint
*arrays
);
360 GLboolean GLAPIENTRY
_mesa_IsVertexArray( GLuint id
);
363 _mesa_VertexArrayElementBuffer_no_error(GLuint vaobj
, GLuint buffer
);
365 void GLAPIENTRY
_mesa_VertexArrayElementBuffer(GLuint vaobj
, GLuint buffer
);
367 void GLAPIENTRY
_mesa_GetVertexArrayiv(GLuint vaobj
, GLenum pname
, GLint
*param
);
369 #endif /* ARRAYOBJ_H */