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
,
54 bool is_ext_dsa
, const char *caller
);
56 extern struct gl_vertex_array_object
*
57 _mesa_new_vao(struct gl_context
*ctx
, GLuint name
);
60 _mesa_unbind_array_object_vbos(struct gl_context
*ctx
,
61 struct gl_vertex_array_object
*obj
);
64 _mesa_delete_vao(struct gl_context
*ctx
, struct gl_vertex_array_object
*obj
);
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(struct gl_context
*ctx
,
73 struct gl_vertex_array_object
**ptr
,
74 struct gl_vertex_array_object
*vao
)
77 _mesa_reference_vao_(ctx
, ptr
, vao
);
82 _mesa_initialize_vao(struct gl_context
*ctx
,
83 struct gl_vertex_array_object
*obj
, GLuint name
);
87 _mesa_update_vao_derived_arrays(struct gl_context
*ctx
,
88 struct gl_vertex_array_object
*vao
);
92 * Mark the vao as shared and immutable, do remaining updates.
95 _mesa_set_vao_immutable(struct gl_context
*ctx
,
96 struct gl_vertex_array_object
*vao
);
99 /* Returns true if all varying arrays reside in vbos */
101 _mesa_all_varyings_in_vbos(const struct gl_vertex_array_object
*vao
);
103 /* Returns true if all vbos are unmapped */
105 _mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object
*vao
);
109 _mesa_vao_map_arrays(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
113 _mesa_vao_map(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
118 _mesa_vao_unmap_arrays(struct gl_context
*ctx
,
119 struct gl_vertex_array_object
*vao
);
122 _mesa_vao_unmap(struct gl_context
*ctx
,
123 struct gl_vertex_array_object
*vao
);
127 * Array to apply the position/generic0 aliasing map to
128 * an attribute value used in vertex processing inputs to an attribute
129 * as they appear in the vao.
132 _mesa_vao_attribute_map
[ATTRIBUTE_MAP_MODE_MAX
][VERT_ATTRIB_MAX
];
136 * Apply the position/generic0 aliasing map to a bitfield from the vao.
137 * Use for example to convert gl_vertex_array_object::Enabled
138 * or gl_vertex_buffer_binding::_VertexBinding from the vao numbering to
139 * the numbering used with vertex processing inputs.
141 static inline GLbitfield
142 _mesa_vao_enable_to_vp_inputs(gl_attribute_map_mode mode
, GLbitfield enabled
)
145 case ATTRIBUTE_MAP_MODE_IDENTITY
:
147 case ATTRIBUTE_MAP_MODE_POSITION
:
148 /* Copy VERT_ATTRIB_POS enable bit into GENERIC0 position */
149 return (enabled
& ~VERT_BIT_GENERIC0
)
150 | ((enabled
& VERT_BIT_POS
) << VERT_ATTRIB_GENERIC0
);
151 case ATTRIBUTE_MAP_MODE_GENERIC0
:
152 /* Copy VERT_ATTRIB_GENERIC0 enable bit into POS position */
153 return (enabled
& ~VERT_BIT_POS
)
154 | ((enabled
& VERT_BIT_GENERIC0
) >> VERT_ATTRIB_GENERIC0
);
162 * Return the vp_inputs enabled bitmask after application of
163 * the position/generic0 aliasing map.
165 static inline GLbitfield
166 _mesa_get_vao_vp_inputs(const struct gl_vertex_array_object
*vao
)
168 const gl_attribute_map_mode mode
= vao
->_AttributeMapMode
;
169 return _mesa_vao_enable_to_vp_inputs(mode
, vao
->Enabled
);
174 * Helper functions for consuming backends to walk the
175 * ctx->Array._DrawVAO for driver side array setup.
176 * Note that mesa provides preprocessed minimal binding information
177 * in the VAO. See _mesa_update_vao_derived_arrays for documentation.
181 * Return enabled vertex attribute bits for draw.
183 static inline GLbitfield
184 _mesa_draw_array_bits(const struct gl_context
*ctx
)
186 return ctx
->Array
._DrawVAOEnabledAttribs
;
191 * Return enabled buffer object vertex attribute bits for draw.
193 * Needs the a fully updated VAO ready for draw.
195 static inline GLbitfield
196 _mesa_draw_vbo_array_bits(const struct gl_context
*ctx
)
198 const struct gl_vertex_array_object
*const vao
= ctx
->Array
._DrawVAO
;
199 assert(vao
->NewArrays
== 0);
200 return vao
->_EffEnabledVBO
& ctx
->Array
._DrawVAOEnabledAttribs
;
205 * Return enabled user space vertex attribute bits for draw.
207 * Needs the a fully updated VAO ready for draw.
209 static inline GLbitfield
210 _mesa_draw_user_array_bits(const struct gl_context
*ctx
)
212 const struct gl_vertex_array_object
*const vao
= ctx
->Array
._DrawVAO
;
213 assert(vao
->NewArrays
== 0);
214 return ~vao
->_EffEnabledVBO
& ctx
->Array
._DrawVAOEnabledAttribs
;
219 * Return which enabled vertex attributes have a non-zero instance divisor.
221 * Needs the a fully updated VAO ready for draw.
223 static inline GLbitfield
224 _mesa_draw_nonzero_divisor_bits(const struct gl_context
*ctx
)
226 const struct gl_vertex_array_object
*const vao
= ctx
->Array
._DrawVAO
;
227 assert(vao
->NewArrays
== 0);
228 return vao
->_EffEnabledNonZeroDivisor
& ctx
->Array
._DrawVAOEnabledAttribs
;
233 * Return enabled current values attribute bits for draw.
235 static inline GLbitfield
236 _mesa_draw_current_bits(const struct gl_context
*ctx
)
238 return ~ctx
->Array
._DrawVAOEnabledAttribs
& VERT_BIT_ALL
;
243 * Return vertex buffer binding provided the attribute struct.
245 * Needs the a fully updated VAO ready for draw.
247 static inline const struct gl_vertex_buffer_binding
*
248 _mesa_draw_buffer_binding_from_attrib(const struct gl_vertex_array_object
*vao
,
249 const struct gl_array_attributes
*attrib
)
251 assert(vao
->NewArrays
== 0);
252 return &vao
->BufferBinding
[attrib
->_EffBufferBindingIndex
];
257 * Return vertex array attribute provided the attribute number.
259 static inline const struct gl_array_attributes
*
260 _mesa_draw_array_attrib(const struct gl_vertex_array_object
*vao
,
263 assert(vao
->NewArrays
== 0);
264 const gl_attribute_map_mode map_mode
= vao
->_AttributeMapMode
;
265 return &vao
->VertexAttrib
[_mesa_vao_attribute_map
[map_mode
][attr
]];
270 * Return a vertex array vertex format provided the attribute number.
272 static inline const struct gl_vertex_format
*
273 _mesa_draw_array_format(const struct gl_vertex_array_object
*vao
,
276 return &_mesa_draw_array_attrib(vao
, attr
)->Format
;
281 * Return vertex buffer binding provided an attribute number.
283 static inline const struct gl_vertex_buffer_binding
*
284 _mesa_draw_buffer_binding(const struct gl_vertex_array_object
*vao
,
287 const struct gl_array_attributes
*const attrib
288 = _mesa_draw_array_attrib(vao
, attr
);
289 return _mesa_draw_buffer_binding_from_attrib(vao
, attrib
);
294 * Return vertex attribute bits bound at the provided binding.
296 * Needs the a fully updated VAO ready for draw.
298 static inline GLbitfield
299 _mesa_draw_bound_attrib_bits(const struct gl_vertex_buffer_binding
*binding
)
301 return binding
->_EffBoundArrays
;
306 * Return the vertex offset bound at the provided binding.
308 * Needs the a fully updated VAO ready for draw.
310 static inline GLintptr
311 _mesa_draw_binding_offset(const struct gl_vertex_buffer_binding
*binding
)
313 return binding
->_EffOffset
;
318 * Return the relative offset of the provided attrib.
320 * Needs the a fully updated VAO ready for draw.
322 static inline GLushort
323 _mesa_draw_attributes_relative_offset(const struct gl_array_attributes
*attrib
)
325 return attrib
->_EffRelativeOffset
;
330 * Return a current value vertex array attribute provided the attribute number.
332 static inline const struct gl_array_attributes
*
333 _mesa_draw_current_attrib(const struct gl_context
*ctx
, gl_vert_attrib attr
)
335 return _vbo_current_attrib(ctx
, attr
);
340 * Return a current value vertex format provided the attribute number.
342 static inline const struct gl_vertex_format
*
343 _mesa_draw_current_format(const struct gl_context
*ctx
, gl_vert_attrib attr
)
345 return &_vbo_current_attrib(ctx
, attr
)->Format
;
350 * Return true if we have the VERT_ATTRIB_EDGEFLAG array enabled.
353 _mesa_draw_edge_flag_array_enabled(const struct gl_context
*ctx
)
355 return ctx
->Array
._DrawVAOEnabledAttribs
& VERT_BIT_EDGEFLAG
;
365 _mesa_BindVertexArray_no_error(GLuint id
);
367 void GLAPIENTRY
_mesa_BindVertexArray( GLuint id
);
370 _mesa_DeleteVertexArrays_no_error(GLsizei n
, const GLuint
*ids
);
372 void GLAPIENTRY
_mesa_DeleteVertexArrays(GLsizei n
, const GLuint
*ids
);
375 _mesa_GenVertexArrays_no_error(GLsizei n
, GLuint
*arrays
);
377 void GLAPIENTRY
_mesa_GenVertexArrays(GLsizei n
, GLuint
*arrays
);
380 _mesa_CreateVertexArrays_no_error(GLsizei n
, GLuint
*arrays
);
382 void GLAPIENTRY
_mesa_CreateVertexArrays(GLsizei n
, GLuint
*arrays
);
384 GLboolean GLAPIENTRY
_mesa_IsVertexArray( GLuint id
);
387 _mesa_VertexArrayElementBuffer_no_error(GLuint vaobj
, GLuint buffer
);
389 void GLAPIENTRY
_mesa_VertexArrayElementBuffer(GLuint vaobj
, GLuint buffer
);
391 void GLAPIENTRY
_mesa_GetVertexArrayiv(GLuint vaobj
, GLenum pname
, GLint
*param
);
393 #endif /* ARRAYOBJ_H */