2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 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.
31 * Implementation of Vertex Array Objects (VAOs), from OpenGL 3.1+ /
32 * the GL_ARB_vertex_array_object extension.
35 * The code in this file borrows a lot from bufferobj.c. There's a certain
36 * amount of cruft left over from that origin that may be unnecessary.
38 * \author Ian Romanick <idr@us.ibm.com>
48 #include "bufferobj.h"
54 #include "util/bitscan.h"
55 #include "util/u_atomic.h"
59 _mesa_vao_attribute_map
[ATTRIBUTE_MAP_MODE_MAX
][VERT_ATTRIB_MAX
] =
61 /* ATTRIBUTE_MAP_MODE_IDENTITY
63 * Grab vertex processing attribute VERT_ATTRIB_POS from
64 * the VAO attribute VERT_ATTRIB_POS, and grab vertex processing
65 * attribute VERT_ATTRIB_GENERIC0 from the VAO attribute
66 * VERT_ATTRIB_GENERIC0.
69 VERT_ATTRIB_POS
, /* VERT_ATTRIB_POS */
70 VERT_ATTRIB_NORMAL
, /* VERT_ATTRIB_NORMAL */
71 VERT_ATTRIB_COLOR0
, /* VERT_ATTRIB_COLOR0 */
72 VERT_ATTRIB_COLOR1
, /* VERT_ATTRIB_COLOR1 */
73 VERT_ATTRIB_FOG
, /* VERT_ATTRIB_FOG */
74 VERT_ATTRIB_COLOR_INDEX
, /* VERT_ATTRIB_COLOR_INDEX */
75 VERT_ATTRIB_EDGEFLAG
, /* VERT_ATTRIB_EDGEFLAG */
76 VERT_ATTRIB_TEX0
, /* VERT_ATTRIB_TEX0 */
77 VERT_ATTRIB_TEX1
, /* VERT_ATTRIB_TEX1 */
78 VERT_ATTRIB_TEX2
, /* VERT_ATTRIB_TEX2 */
79 VERT_ATTRIB_TEX3
, /* VERT_ATTRIB_TEX3 */
80 VERT_ATTRIB_TEX4
, /* VERT_ATTRIB_TEX4 */
81 VERT_ATTRIB_TEX5
, /* VERT_ATTRIB_TEX5 */
82 VERT_ATTRIB_TEX6
, /* VERT_ATTRIB_TEX6 */
83 VERT_ATTRIB_TEX7
, /* VERT_ATTRIB_TEX7 */
84 VERT_ATTRIB_POINT_SIZE
, /* VERT_ATTRIB_POINT_SIZE */
85 VERT_ATTRIB_GENERIC0
, /* VERT_ATTRIB_GENERIC0 */
86 VERT_ATTRIB_GENERIC1
, /* VERT_ATTRIB_GENERIC1 */
87 VERT_ATTRIB_GENERIC2
, /* VERT_ATTRIB_GENERIC2 */
88 VERT_ATTRIB_GENERIC3
, /* VERT_ATTRIB_GENERIC3 */
89 VERT_ATTRIB_GENERIC4
, /* VERT_ATTRIB_GENERIC4 */
90 VERT_ATTRIB_GENERIC5
, /* VERT_ATTRIB_GENERIC5 */
91 VERT_ATTRIB_GENERIC6
, /* VERT_ATTRIB_GENERIC6 */
92 VERT_ATTRIB_GENERIC7
, /* VERT_ATTRIB_GENERIC7 */
93 VERT_ATTRIB_GENERIC8
, /* VERT_ATTRIB_GENERIC8 */
94 VERT_ATTRIB_GENERIC9
, /* VERT_ATTRIB_GENERIC9 */
95 VERT_ATTRIB_GENERIC10
, /* VERT_ATTRIB_GENERIC10 */
96 VERT_ATTRIB_GENERIC11
, /* VERT_ATTRIB_GENERIC11 */
97 VERT_ATTRIB_GENERIC12
, /* VERT_ATTRIB_GENERIC12 */
98 VERT_ATTRIB_GENERIC13
, /* VERT_ATTRIB_GENERIC13 */
99 VERT_ATTRIB_GENERIC14
, /* VERT_ATTRIB_GENERIC14 */
100 VERT_ATTRIB_GENERIC15
/* VERT_ATTRIB_GENERIC15 */
103 /* ATTRIBUTE_MAP_MODE_POSITION
105 * Grab vertex processing attribute VERT_ATTRIB_POS as well as
106 * vertex processing attribute VERT_ATTRIB_GENERIC0 from the
107 * VAO attribute VERT_ATTRIB_POS.
110 VERT_ATTRIB_POS
, /* VERT_ATTRIB_POS */
111 VERT_ATTRIB_NORMAL
, /* VERT_ATTRIB_NORMAL */
112 VERT_ATTRIB_COLOR0
, /* VERT_ATTRIB_COLOR0 */
113 VERT_ATTRIB_COLOR1
, /* VERT_ATTRIB_COLOR1 */
114 VERT_ATTRIB_FOG
, /* VERT_ATTRIB_FOG */
115 VERT_ATTRIB_COLOR_INDEX
, /* VERT_ATTRIB_COLOR_INDEX */
116 VERT_ATTRIB_EDGEFLAG
, /* VERT_ATTRIB_EDGEFLAG */
117 VERT_ATTRIB_TEX0
, /* VERT_ATTRIB_TEX0 */
118 VERT_ATTRIB_TEX1
, /* VERT_ATTRIB_TEX1 */
119 VERT_ATTRIB_TEX2
, /* VERT_ATTRIB_TEX2 */
120 VERT_ATTRIB_TEX3
, /* VERT_ATTRIB_TEX3 */
121 VERT_ATTRIB_TEX4
, /* VERT_ATTRIB_TEX4 */
122 VERT_ATTRIB_TEX5
, /* VERT_ATTRIB_TEX5 */
123 VERT_ATTRIB_TEX6
, /* VERT_ATTRIB_TEX6 */
124 VERT_ATTRIB_TEX7
, /* VERT_ATTRIB_TEX7 */
125 VERT_ATTRIB_POINT_SIZE
, /* VERT_ATTRIB_POINT_SIZE */
126 VERT_ATTRIB_POS
, /* VERT_ATTRIB_GENERIC0 */
127 VERT_ATTRIB_GENERIC1
, /* VERT_ATTRIB_GENERIC1 */
128 VERT_ATTRIB_GENERIC2
, /* VERT_ATTRIB_GENERIC2 */
129 VERT_ATTRIB_GENERIC3
, /* VERT_ATTRIB_GENERIC3 */
130 VERT_ATTRIB_GENERIC4
, /* VERT_ATTRIB_GENERIC4 */
131 VERT_ATTRIB_GENERIC5
, /* VERT_ATTRIB_GENERIC5 */
132 VERT_ATTRIB_GENERIC6
, /* VERT_ATTRIB_GENERIC6 */
133 VERT_ATTRIB_GENERIC7
, /* VERT_ATTRIB_GENERIC7 */
134 VERT_ATTRIB_GENERIC8
, /* VERT_ATTRIB_GENERIC8 */
135 VERT_ATTRIB_GENERIC9
, /* VERT_ATTRIB_GENERIC9 */
136 VERT_ATTRIB_GENERIC10
, /* VERT_ATTRIB_GENERIC10 */
137 VERT_ATTRIB_GENERIC11
, /* VERT_ATTRIB_GENERIC11 */
138 VERT_ATTRIB_GENERIC12
, /* VERT_ATTRIB_GENERIC12 */
139 VERT_ATTRIB_GENERIC13
, /* VERT_ATTRIB_GENERIC13 */
140 VERT_ATTRIB_GENERIC14
, /* VERT_ATTRIB_GENERIC14 */
141 VERT_ATTRIB_GENERIC15
/* VERT_ATTRIB_GENERIC15 */
144 /* ATTRIBUTE_MAP_MODE_GENERIC0
146 * Grab vertex processing attribute VERT_ATTRIB_POS as well as
147 * vertex processing attribute VERT_ATTRIB_GENERIC0 from the
148 * VAO attribute VERT_ATTRIB_GENERIC0.
151 VERT_ATTRIB_GENERIC0
, /* VERT_ATTRIB_POS */
152 VERT_ATTRIB_NORMAL
, /* VERT_ATTRIB_NORMAL */
153 VERT_ATTRIB_COLOR0
, /* VERT_ATTRIB_COLOR0 */
154 VERT_ATTRIB_COLOR1
, /* VERT_ATTRIB_COLOR1 */
155 VERT_ATTRIB_FOG
, /* VERT_ATTRIB_FOG */
156 VERT_ATTRIB_COLOR_INDEX
, /* VERT_ATTRIB_COLOR_INDEX */
157 VERT_ATTRIB_EDGEFLAG
, /* VERT_ATTRIB_EDGEFLAG */
158 VERT_ATTRIB_TEX0
, /* VERT_ATTRIB_TEX0 */
159 VERT_ATTRIB_TEX1
, /* VERT_ATTRIB_TEX1 */
160 VERT_ATTRIB_TEX2
, /* VERT_ATTRIB_TEX2 */
161 VERT_ATTRIB_TEX3
, /* VERT_ATTRIB_TEX3 */
162 VERT_ATTRIB_TEX4
, /* VERT_ATTRIB_TEX4 */
163 VERT_ATTRIB_TEX5
, /* VERT_ATTRIB_TEX5 */
164 VERT_ATTRIB_TEX6
, /* VERT_ATTRIB_TEX6 */
165 VERT_ATTRIB_TEX7
, /* VERT_ATTRIB_TEX7 */
166 VERT_ATTRIB_POINT_SIZE
, /* VERT_ATTRIB_POINT_SIZE */
167 VERT_ATTRIB_GENERIC0
, /* VERT_ATTRIB_GENERIC0 */
168 VERT_ATTRIB_GENERIC1
, /* VERT_ATTRIB_GENERIC1 */
169 VERT_ATTRIB_GENERIC2
, /* VERT_ATTRIB_GENERIC2 */
170 VERT_ATTRIB_GENERIC3
, /* VERT_ATTRIB_GENERIC3 */
171 VERT_ATTRIB_GENERIC4
, /* VERT_ATTRIB_GENERIC4 */
172 VERT_ATTRIB_GENERIC5
, /* VERT_ATTRIB_GENERIC5 */
173 VERT_ATTRIB_GENERIC6
, /* VERT_ATTRIB_GENERIC6 */
174 VERT_ATTRIB_GENERIC7
, /* VERT_ATTRIB_GENERIC7 */
175 VERT_ATTRIB_GENERIC8
, /* VERT_ATTRIB_GENERIC8 */
176 VERT_ATTRIB_GENERIC9
, /* VERT_ATTRIB_GENERIC9 */
177 VERT_ATTRIB_GENERIC10
, /* VERT_ATTRIB_GENERIC10 */
178 VERT_ATTRIB_GENERIC11
, /* VERT_ATTRIB_GENERIC11 */
179 VERT_ATTRIB_GENERIC12
, /* VERT_ATTRIB_GENERIC12 */
180 VERT_ATTRIB_GENERIC13
, /* VERT_ATTRIB_GENERIC13 */
181 VERT_ATTRIB_GENERIC14
, /* VERT_ATTRIB_GENERIC14 */
182 VERT_ATTRIB_GENERIC15
/* VERT_ATTRIB_GENERIC15 */
188 * Look up the array object for the given ID.
191 * Either a pointer to the array object with the specified ID or \c NULL for
192 * a non-existent ID. The spec defines ID 0 as being technically
196 struct gl_vertex_array_object
*
197 _mesa_lookup_vao(struct gl_context
*ctx
, GLuint id
)
199 /* The ARB_direct_state_access specification says:
201 * "<vaobj> is [compatibility profile:
202 * zero, indicating the default vertex array object, or]
203 * the name of the vertex array object."
206 if (ctx
->API
== API_OPENGL_COMPAT
)
207 return ctx
->Array
.DefaultVAO
;
211 struct gl_vertex_array_object
*vao
;
213 if (ctx
->Array
.LastLookedUpVAO
&&
214 ctx
->Array
.LastLookedUpVAO
->Name
== id
) {
215 vao
= ctx
->Array
.LastLookedUpVAO
;
217 vao
= (struct gl_vertex_array_object
*)
218 _mesa_HashLookupLocked(ctx
->Array
.Objects
, id
);
220 _mesa_reference_vao(ctx
, &ctx
->Array
.LastLookedUpVAO
, vao
);
229 * Looks up the array object for the given ID.
231 * Unlike _mesa_lookup_vao, this function generates a GL_INVALID_OPERATION
232 * error if the array object does not exist. It also returns the default
233 * array object when ctx is a compatibility profile context and id is zero.
235 struct gl_vertex_array_object
*
236 _mesa_lookup_vao_err(struct gl_context
*ctx
, GLuint id
, const char *caller
)
238 /* The ARB_direct_state_access specification says:
240 * "<vaobj> is [compatibility profile:
241 * zero, indicating the default vertex array object, or]
242 * the name of the vertex array object."
245 if (ctx
->API
== API_OPENGL_CORE
) {
246 _mesa_error(ctx
, GL_INVALID_OPERATION
,
247 "%s(zero is not valid vaobj name in a core profile "
252 return ctx
->Array
.DefaultVAO
;
254 struct gl_vertex_array_object
*vao
;
256 if (ctx
->Array
.LastLookedUpVAO
&&
257 ctx
->Array
.LastLookedUpVAO
->Name
== id
) {
258 vao
= ctx
->Array
.LastLookedUpVAO
;
260 vao
= (struct gl_vertex_array_object
*)
261 _mesa_HashLookupLocked(ctx
->Array
.Objects
, id
);
263 /* The ARB_direct_state_access specification says:
265 * "An INVALID_OPERATION error is generated if <vaobj> is not
266 * [compatibility profile: zero or] the name of an existing
267 * vertex array object."
269 if (!vao
|| !vao
->EverBound
) {
270 _mesa_error(ctx
, GL_INVALID_OPERATION
,
271 "%s(non-existent vaobj=%u)", caller
, id
);
275 _mesa_reference_vao(ctx
, &ctx
->Array
.LastLookedUpVAO
, vao
);
284 * For all the vertex binding points in the array object, unbind any pointers
285 * to any buffer objects (VBOs).
286 * This is done just prior to array object destruction.
289 unbind_array_object_vbos(struct gl_context
*ctx
, struct gl_vertex_array_object
*obj
)
293 for (i
= 0; i
< ARRAY_SIZE(obj
->BufferBinding
); i
++)
294 _mesa_reference_buffer_object(ctx
, &obj
->BufferBinding
[i
].BufferObj
, NULL
);
299 * Allocate and initialize a new vertex array object.
301 struct gl_vertex_array_object
*
302 _mesa_new_vao(struct gl_context
*ctx
, GLuint name
)
304 struct gl_vertex_array_object
*obj
= CALLOC_STRUCT(gl_vertex_array_object
);
306 _mesa_initialize_vao(ctx
, obj
, name
);
312 * Delete an array object.
315 _mesa_delete_vao(struct gl_context
*ctx
, struct gl_vertex_array_object
*obj
)
317 unbind_array_object_vbos(ctx
, obj
);
318 _mesa_reference_buffer_object(ctx
, &obj
->IndexBufferObj
, NULL
);
325 * Set ptr to vao w/ reference counting.
326 * Note: this should only be called from the _mesa_reference_vao()
330 _mesa_reference_vao_(struct gl_context
*ctx
,
331 struct gl_vertex_array_object
**ptr
,
332 struct gl_vertex_array_object
*vao
)
337 /* Unreference the old array object */
338 struct gl_vertex_array_object
*oldObj
= *ptr
;
341 if (oldObj
->SharedAndImmutable
) {
342 deleteFlag
= p_atomic_dec_zero(&oldObj
->RefCount
);
344 assert(oldObj
->RefCount
> 0);
346 deleteFlag
= (oldObj
->RefCount
== 0);
350 _mesa_delete_vao(ctx
, oldObj
);
357 /* reference new array object */
358 if (vao
->SharedAndImmutable
) {
359 p_atomic_inc(&vao
->RefCount
);
361 assert(vao
->RefCount
> 0);
371 * Initialize attributes of a vertex array within a vertex array object.
372 * \param vao the container vertex array object
373 * \param index which array in the VAO to initialize
374 * \param size number of components (1, 2, 3 or 4) per attribute
375 * \param type datatype of the attribute (GL_FLOAT, GL_INT, etc).
378 init_array(struct gl_context
*ctx
,
379 struct gl_vertex_array_object
*vao
,
380 gl_vert_attrib index
, GLint size
, GLint type
)
382 assert(index
< ARRAY_SIZE(vao
->VertexAttrib
));
383 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[index
];
384 assert(index
< ARRAY_SIZE(vao
->BufferBinding
));
385 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
389 array
->Format
= GL_RGBA
; /* only significant for GL_EXT_vertex_array_bgra */
392 array
->RelativeOffset
= 0;
393 array
->Enabled
= GL_FALSE
;
394 array
->Normalized
= GL_FALSE
;
395 array
->Integer
= GL_FALSE
;
396 array
->Doubles
= GL_FALSE
;
397 array
->_ElementSize
= size
* _mesa_sizeof_type(type
);
398 ASSERT_BITFIELD_SIZE(struct gl_array_attributes
, BufferBindingIndex
,
399 VERT_ATTRIB_MAX
- 1);
400 array
->BufferBindingIndex
= index
;
403 binding
->Stride
= array
->_ElementSize
;
404 binding
->BufferObj
= NULL
;
405 binding
->_BoundArrays
= BITFIELD_BIT(index
);
407 /* Vertex array buffers */
408 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
,
409 ctx
->Shared
->NullBufferObj
);
414 * Initialize a gl_vertex_array_object's arrays.
417 _mesa_initialize_vao(struct gl_context
*ctx
,
418 struct gl_vertex_array_object
*vao
,
426 vao
->SharedAndImmutable
= false;
428 /* Init the individual arrays */
429 for (i
= 0; i
< ARRAY_SIZE(vao
->VertexAttrib
); i
++) {
431 case VERT_ATTRIB_NORMAL
:
432 init_array(ctx
, vao
, VERT_ATTRIB_NORMAL
, 3, GL_FLOAT
);
434 case VERT_ATTRIB_COLOR1
:
435 init_array(ctx
, vao
, VERT_ATTRIB_COLOR1
, 3, GL_FLOAT
);
437 case VERT_ATTRIB_FOG
:
438 init_array(ctx
, vao
, VERT_ATTRIB_FOG
, 1, GL_FLOAT
);
440 case VERT_ATTRIB_COLOR_INDEX
:
441 init_array(ctx
, vao
, VERT_ATTRIB_COLOR_INDEX
, 1, GL_FLOAT
);
443 case VERT_ATTRIB_EDGEFLAG
:
444 init_array(ctx
, vao
, VERT_ATTRIB_EDGEFLAG
, 1, GL_BOOL
);
446 case VERT_ATTRIB_POINT_SIZE
:
447 init_array(ctx
, vao
, VERT_ATTRIB_POINT_SIZE
, 1, GL_FLOAT
);
450 init_array(ctx
, vao
, i
, 4, GL_FLOAT
);
455 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_IDENTITY
;
457 _mesa_reference_buffer_object(ctx
, &vao
->IndexBufferObj
,
458 ctx
->Shared
->NullBufferObj
);
463 * Compute the offset range for the provided binding.
465 * This is a helper function for the below.
468 compute_vbo_offset_range(const struct gl_vertex_array_object
*vao
,
469 const struct gl_vertex_buffer_binding
*binding
,
470 GLsizeiptr
* min
, GLsizeiptr
* max
)
472 /* The function is meant to work on VBO bindings */
473 assert(_mesa_is_bufferobj(binding
->BufferObj
));
475 /* Start with an inverted range of relative offsets. */
476 GLuint min_offset
= ~(GLuint
)0;
477 GLuint max_offset
= 0;
479 /* We work on the unmapped originaly VAO array entries. */
480 GLbitfield mask
= vao
->_Enabled
& binding
->_BoundArrays
;
481 /* The binding should be active somehow, not to return inverted ranges */
484 const int i
= u_bit_scan(&mask
);
485 const GLuint off
= vao
->VertexAttrib
[i
].RelativeOffset
;
486 min_offset
= MIN2(off
, min_offset
);
487 max_offset
= MAX2(off
, max_offset
);
490 *min
= binding
->Offset
+ (GLsizeiptr
)min_offset
;
491 *max
= binding
->Offset
+ (GLsizeiptr
)max_offset
;
496 * Update the unique binding and pos/generic0 map tracking in the vao.
498 * The idea is to build up information in the vao so that a consuming
499 * backend can execute the following to set up buffer and vertex element
502 * const GLbitfield inputs_read = VERT_BIT_ALL; // backend vp inputs
504 * // Attribute data is in a VBO.
505 * GLbitfield vbomask = inputs_read & _mesa_draw_vbo_array_bits(ctx);
507 * // The attribute index to start pulling a binding
508 * const gl_vert_attrib i = ffs(vbomask) - 1;
509 * const struct gl_vertex_buffer_binding *const binding
510 * = _mesa_draw_buffer_binding(vao, i);
512 * <insert code to handle the vertex buffer object at binding>
514 * const GLbitfield boundmask = _mesa_draw_bound_attrib_bits(binding);
515 * GLbitfield attrmask = vbomask & boundmask;
517 * // Walk attributes belonging to the binding
519 * const gl_vert_attrib attr = u_bit_scan(&attrmask);
520 * const struct gl_array_attributes *const attrib
521 * = _mesa_draw_array_attrib(vao, attr);
523 * <insert code to handle the vertex element refering to the binding>
525 * vbomask &= ~boundmask;
528 * // Process user space buffers
529 * GLbitfield usermask = inputs_read & _mesa_draw_user_array_bits(ctx);
531 * // The attribute index to start pulling a binding
532 * const gl_vert_attrib i = ffs(usermask) - 1;
533 * const struct gl_vertex_buffer_binding *const binding
534 * = _mesa_draw_buffer_binding(vao, i);
536 * <insert code to handle a set of interleaved user space arrays at binding>
538 * const GLbitfield boundmask = _mesa_draw_bound_attrib_bits(binding);
539 * GLbitfield attrmask = usermask & boundmask;
541 * // Walk interleaved attributes with a common stride and instance divisor
543 * const gl_vert_attrib attr = u_bit_scan(&attrmask);
544 * const struct gl_array_attributes *const attrib
545 * = _mesa_draw_array_attrib(vao, attr);
547 * <insert code to handle non vbo vertex arrays>
549 * usermask &= ~boundmask;
552 * // Process values that should have better been uniforms in the application
553 * GLbitfield curmask = inputs_read & _mesa_draw_current_bits(ctx);
555 * const gl_vert_attrib attr = u_bit_scan(&curmask);
556 * const struct gl_array_attributes *const attrib
557 * = _mesa_draw_current_attrib(ctx, attr);
559 * <insert code to handle current values>
563 * Note that the scan below must not incoporate any context state.
564 * The rationale is that once a VAO is finalized it should not
565 * be touched anymore. That means, do not incorporate the
566 * gl_context::Array._DrawVAOEnabledAttribs bitmask into this scan.
567 * A backend driver may further reduce the handled vertex processing
568 * inputs based on their vertex shader inputs. But scanning for
569 * collapsable binding points to reduce relocs is done based on the
571 * Also VAOs may be shared between contexts due to their use in dlists
572 * thus no context state should bleed into the VAO.
575 _mesa_update_vao_derived_arrays(struct gl_context
*ctx
,
576 struct gl_vertex_array_object
*vao
)
578 /* Make sure we do not run into problems with shared objects */
579 assert(!vao
->SharedAndImmutable
|| vao
->NewArrays
== 0);
581 /* Limit used for common binding scanning below. */
582 const GLsizeiptr MaxRelativeOffset
=
583 ctx
->Const
.MaxVertexAttribRelativeOffset
;
585 /* The gl_vertex_array_object::_AttributeMapMode denotes the way
586 * VERT_ATTRIB_{POS,GENERIC0} mapping is done.
588 * This mapping is used to map between the OpenGL api visible
589 * VERT_ATTRIB_* arrays to mesa driver arrayinputs or shader inputs.
590 * The mapping only depends on the enabled bits of the
591 * VERT_ATTRIB_{POS,GENERIC0} arrays and is tracked in the VAO.
593 * This map needs to be applied when finally translating to the bitmasks
594 * as consumed by the driver backends. The duplicate scanning is here
595 * can as well be done in the OpenGL API numbering without this map.
597 const gl_attribute_map_mode mode
= vao
->_AttributeMapMode
;
598 /* Enabled array bits. */
599 const GLbitfield enabled
= vao
->_Enabled
;
600 /* VBO array bits. */
601 const GLbitfield vbos
= vao
->VertexAttribBufferMask
;
603 /* Compute and store effectively enabled and mapped vbo arrays */
604 vao
->_EffEnabledVBO
= _mesa_vao_enable_to_vp_inputs(mode
, enabled
& vbos
);
605 /* Walk those enabled arrays that have a real vbo attached */
606 GLbitfield mask
= enabled
;
608 /* Do not use u_bit_scan as we can walk multiple attrib arrays at once */
609 const int i
= ffs(mask
) - 1;
610 /* The binding from the first to be processed attribute. */
611 const GLuint bindex
= vao
->VertexAttrib
[i
].BufferBindingIndex
;
612 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[bindex
];
614 /* The scan goes different for user space arrays than vbos */
615 if (_mesa_is_bufferobj(binding
->BufferObj
)) {
616 /* The bound arrays. */
617 const GLbitfield bound
= enabled
& binding
->_BoundArrays
;
619 /* Start this current effective binding with the actual bound arrays */
620 GLbitfield eff_bound_arrays
= bound
;
623 * If there is nothing left to scan just update the effective binding
624 * information. If the VAO is already only using a single binding point
625 * we end up here. So the overhead of this scan for an application
626 * carefully preparing the VAO for draw is low.
629 GLbitfield scanmask
= mask
& vbos
& ~bound
;
630 /* Is there something left to scan? */
632 /* Just update the back reference from the attrib to the binding and
633 * the effective offset.
635 GLbitfield attrmask
= eff_bound_arrays
;
637 const int j
= u_bit_scan(&attrmask
);
638 struct gl_array_attributes
*attrib2
= &vao
->VertexAttrib
[j
];
640 /* Update the index into the common binding point and offset */
641 attrib2
->_EffBufferBindingIndex
= bindex
;
642 attrib2
->_EffRelativeOffset
= attrib2
->RelativeOffset
;
643 assert(attrib2
->_EffRelativeOffset
<= MaxRelativeOffset
);
645 /* Only enabled arrays shall appear in the unique bindings */
646 assert(attrib2
->Enabled
);
648 /* Finally this is the set of effectively bound arrays with the
649 * original binding offset.
651 binding
->_EffOffset
= binding
->Offset
;
652 /* The bound arrays past the VERT_ATTRIB_{POS,GENERIC0} mapping. */
653 binding
->_EffBoundArrays
=
654 _mesa_vao_enable_to_vp_inputs(mode
, eff_bound_arrays
);
657 /* In the VBO case, scan for attribute/binding
658 * combinations with relative bindings in the range of
659 * [0, ctx->Const.MaxVertexAttribRelativeOffset].
660 * Note that this does also go beyond just interleaved arrays
661 * as long as they use the same VBO, binding parameters and the
662 * offsets stay within bounds that the backend still can handle.
665 GLsizeiptr min_offset
, max_offset
;
666 compute_vbo_offset_range(vao
, binding
, &min_offset
, &max_offset
);
667 assert(max_offset
<= min_offset
+ MaxRelativeOffset
);
671 /* Do not use u_bit_scan as we can walk multiple
672 * attrib arrays at once
674 const int j
= ffs(scanmask
) - 1;
675 const struct gl_array_attributes
*attrib2
=
676 &vao
->VertexAttrib
[j
];
677 const struct gl_vertex_buffer_binding
*binding2
=
678 &vao
->BufferBinding
[attrib2
->BufferBindingIndex
];
680 /* Remove those attrib bits from the mask that are bound to the
681 * same effective binding point.
683 const GLbitfield bound2
= enabled
& binding2
->_BoundArrays
;
686 /* Check if we have an identical binding */
687 if (binding
->Stride
!= binding2
->Stride
)
689 if (binding
->InstanceDivisor
!= binding2
->InstanceDivisor
)
691 if (binding
->BufferObj
!= binding2
->BufferObj
)
693 /* Check if we can fold both bindings into a common binding */
694 GLsizeiptr min_offset2
, max_offset2
;
695 compute_vbo_offset_range(vao
, binding2
,
696 &min_offset2
, &max_offset2
);
697 /* If the relative offset is within the limits ... */
698 if (min_offset
+ MaxRelativeOffset
< max_offset2
)
700 if (min_offset2
+ MaxRelativeOffset
< max_offset
)
702 /* ... add this array to the effective binding */
703 eff_bound_arrays
|= bound2
;
704 min_offset
= MIN2(min_offset
, min_offset2
);
705 max_offset
= MAX2(max_offset
, max_offset2
);
706 assert(max_offset
<= min_offset
+ MaxRelativeOffset
);
709 /* Update the back reference from the attrib to the binding */
710 GLbitfield attrmask
= eff_bound_arrays
;
712 const int j
= u_bit_scan(&attrmask
);
713 struct gl_array_attributes
*attrib2
= &vao
->VertexAttrib
[j
];
714 const struct gl_vertex_buffer_binding
*binding2
=
715 &vao
->BufferBinding
[attrib2
->BufferBindingIndex
];
717 /* Update the index into the common binding point and offset */
718 attrib2
->_EffBufferBindingIndex
= bindex
;
719 attrib2
->_EffRelativeOffset
=
720 binding2
->Offset
+ attrib2
->RelativeOffset
- min_offset
;
721 assert(attrib2
->_EffRelativeOffset
<= MaxRelativeOffset
);
723 /* Only enabled arrays shall appear in the unique bindings */
724 assert(attrib2
->Enabled
);
726 /* Finally this is the set of effectively bound arrays */
727 binding
->_EffOffset
= min_offset
;
728 /* The bound arrays past the VERT_ATTRIB_{POS,GENERIC0} mapping. */
729 binding
->_EffBoundArrays
=
730 _mesa_vao_enable_to_vp_inputs(mode
, eff_bound_arrays
);
733 /* Mark all the effective bound arrays as processed. */
734 mask
&= ~eff_bound_arrays
;
737 /* Scanning of common bindings for user space arrays.
740 const struct gl_array_attributes
*attrib
= &vao
->VertexAttrib
[i
];
741 const GLbitfield bound
= VERT_BIT(i
);
743 /* Note that user space array pointers can only happen using a one
744 * to one binding point to array mapping.
745 * The OpenGL 4.x/ARB_vertex_attrib_binding api does not support
746 * user space arrays collected at multiple binding points.
747 * The only provider of user space interleaved arrays with a single
748 * binding point is the mesa internal vbo module. But that one
749 * provides a perfect interleaved set of arrays.
751 * If this would not be true we would potentially get attribute arrays
752 * with user space pointers that may not lie within the
753 * MaxRelativeOffset range but still attached to a single binding.
754 * Then we would need to store the effective attribute and binding
755 * grouping information in a seperate array beside
756 * gl_array_attributes/gl_vertex_buffer_binding.
758 assert(_mesa_bitcount(binding
->_BoundArrays
& vao
->_Enabled
) == 1
759 || (vao
->_Enabled
& ~binding
->_BoundArrays
) == 0);
761 /* Start this current effective binding with the array */
762 GLbitfield eff_bound_arrays
= bound
;
764 const GLubyte
*ptr
= attrib
->Ptr
;
765 unsigned vertex_end
= attrib
->_ElementSize
;
767 /* Walk other user space arrays and see which are interleaved
768 * using the same binding parameters.
770 GLbitfield scanmask
= mask
& ~vbos
& ~bound
;
772 const int j
= u_bit_scan(&scanmask
);
773 const struct gl_array_attributes
*attrib2
= &vao
->VertexAttrib
[j
];
774 const struct gl_vertex_buffer_binding
*binding2
=
775 &vao
->BufferBinding
[attrib2
->BufferBindingIndex
];
777 /* See the comment at the same assert above. */
778 assert(_mesa_bitcount(binding2
->_BoundArrays
& vao
->_Enabled
) == 1
779 || (vao
->_Enabled
& ~binding
->_BoundArrays
) == 0);
781 /* Check if we have an identical binding */
782 if (binding
->Stride
!= binding2
->Stride
)
784 if (binding
->InstanceDivisor
!= binding2
->InstanceDivisor
)
786 if (ptr
<= attrib2
->Ptr
) {
787 if (ptr
+ binding
->Stride
< attrib2
->Ptr
+ attrib2
->_ElementSize
)
789 unsigned end
= attrib2
->Ptr
+ attrib2
->_ElementSize
- ptr
;
790 vertex_end
= MAX2(vertex_end
, end
);
792 if (attrib2
->Ptr
+ binding
->Stride
< ptr
+ vertex_end
)
794 vertex_end
+= (GLsizei
)(ptr
- attrib2
->Ptr
);
798 /* User space buffer object */
799 assert(!_mesa_is_bufferobj(binding2
->BufferObj
));
801 eff_bound_arrays
|= VERT_BIT(j
);
804 /* Update the back reference from the attrib to the binding */
805 GLbitfield attrmask
= eff_bound_arrays
;
807 const int j
= u_bit_scan(&attrmask
);
808 struct gl_array_attributes
*attrib2
= &vao
->VertexAttrib
[j
];
810 /* Update the index into the common binding point and the offset */
811 attrib2
->_EffBufferBindingIndex
= bindex
;
812 attrib2
->_EffRelativeOffset
= attrib2
->Ptr
- ptr
;
813 assert(attrib2
->_EffRelativeOffset
<= binding
->Stride
);
815 /* Only enabled arrays shall appear in the unique bindings */
816 assert(attrib2
->Enabled
);
818 /* Finally this is the set of effectively bound arrays */
819 binding
->_EffOffset
= (GLintptr
)ptr
;
820 /* The bound arrays past the VERT_ATTRIB_{POS,GENERIC0} mapping. */
821 binding
->_EffBoundArrays
=
822 _mesa_vao_enable_to_vp_inputs(mode
, eff_bound_arrays
);
824 /* Mark all the effective bound arrays as processed. */
825 mask
&= ~eff_bound_arrays
;
830 /* Make sure the above code works as expected. */
831 for (gl_vert_attrib attr
= 0; attr
< VERT_ATTRIB_MAX
; ++attr
) {
832 /* Query the original api defined attrib/binding information ... */
833 const unsigned char *const map
=_mesa_vao_attribute_map
[mode
];
834 const struct gl_array_attributes
*attrib
= &vao
->VertexAttrib
[map
[attr
]];
835 if (attrib
->Enabled
) {
836 const struct gl_vertex_buffer_binding
*binding
=
837 &vao
->BufferBinding
[attrib
->BufferBindingIndex
];
838 /* ... and compare that with the computed attrib/binding */
839 const struct gl_vertex_buffer_binding
*binding2
=
840 &vao
->BufferBinding
[attrib
->_EffBufferBindingIndex
];
841 assert(binding
->Stride
== binding2
->Stride
);
842 assert(binding
->InstanceDivisor
== binding2
->InstanceDivisor
);
843 assert(binding
->BufferObj
== binding2
->BufferObj
);
844 if (_mesa_is_bufferobj(binding
->BufferObj
)) {
845 assert(attrib
->_EffRelativeOffset
<= MaxRelativeOffset
);
846 assert(binding
->Offset
+ attrib
->RelativeOffset
==
847 binding2
->_EffOffset
+ attrib
->_EffRelativeOffset
);
849 assert(attrib
->_EffRelativeOffset
< binding
->Stride
);
850 assert((GLintptr
)attrib
->Ptr
==
851 binding2
->_EffOffset
+ attrib
->_EffRelativeOffset
);
860 _mesa_set_vao_immutable(struct gl_context
*ctx
,
861 struct gl_vertex_array_object
*vao
)
863 _mesa_update_vao_derived_arrays(ctx
, vao
);
865 vao
->SharedAndImmutable
= true;
870 _mesa_all_varyings_in_vbos(const struct gl_vertex_array_object
*vao
)
872 /* Walk those enabled arrays that have the default vbo attached */
873 GLbitfield mask
= vao
->_Enabled
& ~vao
->VertexAttribBufferMask
;
876 /* Do not use u_bit_scan64 as we can walk multiple
877 * attrib arrays at once
879 const int i
= ffs(mask
) - 1;
880 const struct gl_array_attributes
*attrib_array
=
881 &vao
->VertexAttrib
[i
];
882 const struct gl_vertex_buffer_binding
*buffer_binding
=
883 &vao
->BufferBinding
[attrib_array
->BufferBindingIndex
];
885 /* Only enabled arrays shall appear in the _Enabled bitmask */
886 assert(attrib_array
->Enabled
);
887 /* We have already masked out vao->VertexAttribBufferMask */
888 assert(!_mesa_is_bufferobj(buffer_binding
->BufferObj
));
890 /* Bail out once we find the first non vbo with a non zero stride */
891 if (buffer_binding
->Stride
!= 0)
894 /* Note that we cannot use the xor variant since the _BoundArray mask
895 * may contain array attributes that are bound but not enabled.
897 mask
&= ~buffer_binding
->_BoundArrays
;
904 _mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object
*vao
)
906 /* Walk the enabled arrays that have a vbo attached */
907 GLbitfield mask
= vao
->_Enabled
& vao
->VertexAttribBufferMask
;
910 const int i
= ffs(mask
) - 1;
911 const struct gl_array_attributes
*attrib_array
=
912 &vao
->VertexAttrib
[i
];
913 const struct gl_vertex_buffer_binding
*buffer_binding
=
914 &vao
->BufferBinding
[attrib_array
->BufferBindingIndex
];
916 /* Only enabled arrays shall appear in the _Enabled bitmask */
917 assert(attrib_array
->Enabled
);
918 /* We have already masked with vao->VertexAttribBufferMask */
919 assert(_mesa_is_bufferobj(buffer_binding
->BufferObj
));
921 /* Bail out once we find the first disallowed mapping */
922 if (_mesa_check_disallowed_mapping(buffer_binding
->BufferObj
))
925 /* We have handled everything that is bound to this buffer_binding. */
926 mask
&= ~buffer_binding
->_BoundArrays
;
932 /**********************************************************************/
934 /**********************************************************************/
938 * ARB version of glBindVertexArray()
940 static ALWAYS_INLINE
void
941 bind_vertex_array(struct gl_context
*ctx
, GLuint id
, bool no_error
)
943 struct gl_vertex_array_object
*const oldObj
= ctx
->Array
.VAO
;
944 struct gl_vertex_array_object
*newObj
= NULL
;
946 assert(oldObj
!= NULL
);
948 if (oldObj
->Name
== id
)
949 return; /* rebinding the same array object- no change */
952 * Get pointer to new array object (newObj)
955 /* The spec says there is no array object named 0, but we use
956 * one internally because it simplifies things.
958 newObj
= ctx
->Array
.DefaultVAO
;
961 /* non-default array object */
962 newObj
= _mesa_lookup_vao(ctx
, id
);
963 if (!no_error
&& !newObj
) {
964 _mesa_error(ctx
, GL_INVALID_OPERATION
,
965 "glBindVertexArray(non-gen name)");
969 newObj
->EverBound
= GL_TRUE
;
972 /* The _DrawArrays pointer is pointing at the VAO being unbound and
973 * that VAO may be in the process of being deleted. If it's not going
974 * to be deleted, this will have no effect, because the pointer needs
975 * to be updated by the VBO module anyway.
977 * Before the VBO module can update the pointer, we have to set it
978 * to NULL for drivers not to set up arrays which are not bound,
979 * or to prevent a crash if the VAO being unbound is going to be
982 _mesa_set_draw_vao(ctx
, ctx
->Array
._EmptyVAO
, 0);
984 ctx
->NewState
|= _NEW_ARRAY
;
985 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, newObj
);
990 _mesa_BindVertexArray_no_error(GLuint id
)
992 GET_CURRENT_CONTEXT(ctx
);
993 bind_vertex_array(ctx
, id
, true);
998 _mesa_BindVertexArray(GLuint id
)
1000 GET_CURRENT_CONTEXT(ctx
);
1001 bind_vertex_array(ctx
, id
, false);
1006 * Delete a set of array objects.
1008 * \param n Number of array objects to delete.
1009 * \param ids Array of \c n array object IDs.
1012 delete_vertex_arrays(struct gl_context
*ctx
, GLsizei n
, const GLuint
*ids
)
1016 for (i
= 0; i
< n
; i
++) {
1017 /* IDs equal to 0 should be silently ignored. */
1021 struct gl_vertex_array_object
*obj
= _mesa_lookup_vao(ctx
, ids
[i
]);
1024 assert(obj
->Name
== ids
[i
]);
1026 /* If the array object is currently bound, the spec says "the binding
1027 * for that object reverts to zero and the default vertex array
1030 if (obj
== ctx
->Array
.VAO
)
1031 _mesa_BindVertexArray_no_error(0);
1033 /* The ID is immediately freed for re-use */
1034 _mesa_HashRemoveLocked(ctx
->Array
.Objects
, obj
->Name
);
1036 if (ctx
->Array
.LastLookedUpVAO
== obj
)
1037 _mesa_reference_vao(ctx
, &ctx
->Array
.LastLookedUpVAO
, NULL
);
1038 if (ctx
->Array
._DrawVAO
== obj
)
1039 _mesa_set_draw_vao(ctx
, ctx
->Array
._EmptyVAO
, 0);
1041 /* Unreference the array object.
1042 * If refcount hits zero, the object will be deleted.
1044 _mesa_reference_vao(ctx
, &obj
, NULL
);
1051 _mesa_DeleteVertexArrays_no_error(GLsizei n
, const GLuint
*ids
)
1053 GET_CURRENT_CONTEXT(ctx
);
1054 delete_vertex_arrays(ctx
, n
, ids
);
1059 _mesa_DeleteVertexArrays(GLsizei n
, const GLuint
*ids
)
1061 GET_CURRENT_CONTEXT(ctx
);
1064 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteVertexArray(n)");
1068 delete_vertex_arrays(ctx
, n
, ids
);
1073 * Generate a set of unique array object IDs and store them in \c arrays.
1074 * Helper for _mesa_GenVertexArrays() and _mesa_CreateVertexArrays()
1077 * \param n Number of IDs to generate.
1078 * \param arrays Array of \c n locations to store the IDs.
1079 * \param create Indicates that the objects should also be created.
1080 * \param func The name of the GL entry point.
1083 gen_vertex_arrays(struct gl_context
*ctx
, GLsizei n
, GLuint
*arrays
,
1084 bool create
, const char *func
)
1092 first
= _mesa_HashFindFreeKeyBlock(ctx
->Array
.Objects
, n
);
1094 /* For the sake of simplicity we create the array objects in both
1095 * the Gen* and Create* cases. The only difference is the value of
1096 * EverBound, which is set to true in the Create* case.
1098 for (i
= 0; i
< n
; i
++) {
1099 struct gl_vertex_array_object
*obj
;
1100 GLuint name
= first
+ i
;
1102 obj
= _mesa_new_vao(ctx
, name
);
1104 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1107 obj
->EverBound
= create
;
1108 _mesa_HashInsertLocked(ctx
->Array
.Objects
, obj
->Name
, obj
);
1109 arrays
[i
] = first
+ i
;
1115 gen_vertex_arrays_err(struct gl_context
*ctx
, GLsizei n
, GLuint
*arrays
,
1116 bool create
, const char *func
)
1119 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
1123 gen_vertex_arrays(ctx
, n
, arrays
, create
, func
);
1128 * ARB version of glGenVertexArrays()
1129 * All arrays will be required to live in VBOs.
1132 _mesa_GenVertexArrays_no_error(GLsizei n
, GLuint
*arrays
)
1134 GET_CURRENT_CONTEXT(ctx
);
1135 gen_vertex_arrays(ctx
, n
, arrays
, false, "glGenVertexArrays");
1140 _mesa_GenVertexArrays(GLsizei n
, GLuint
*arrays
)
1142 GET_CURRENT_CONTEXT(ctx
);
1143 gen_vertex_arrays_err(ctx
, n
, arrays
, false, "glGenVertexArrays");
1148 * ARB_direct_state_access
1149 * Generates ID's and creates the array objects.
1152 _mesa_CreateVertexArrays_no_error(GLsizei n
, GLuint
*arrays
)
1154 GET_CURRENT_CONTEXT(ctx
);
1155 gen_vertex_arrays(ctx
, n
, arrays
, true, "glCreateVertexArrays");
1160 _mesa_CreateVertexArrays(GLsizei n
, GLuint
*arrays
)
1162 GET_CURRENT_CONTEXT(ctx
);
1163 gen_vertex_arrays_err(ctx
, n
, arrays
, true, "glCreateVertexArrays");
1168 * Determine if ID is the name of an array object.
1170 * \param id ID of the potential array object.
1171 * \return \c GL_TRUE if \c id is the name of a array object,
1172 * \c GL_FALSE otherwise.
1174 GLboolean GLAPIENTRY
1175 _mesa_IsVertexArray( GLuint id
)
1177 struct gl_vertex_array_object
* obj
;
1178 GET_CURRENT_CONTEXT(ctx
);
1179 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1181 obj
= _mesa_lookup_vao(ctx
, id
);
1183 return obj
!= NULL
&& obj
->EverBound
;
1188 * Sets the element array buffer binding of a vertex array object.
1190 * This is the ARB_direct_state_access equivalent of
1191 * glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer).
1193 static ALWAYS_INLINE
void
1194 vertex_array_element_buffer(struct gl_context
*ctx
, GLuint vaobj
, GLuint buffer
,
1197 struct gl_vertex_array_object
*vao
;
1198 struct gl_buffer_object
*bufObj
;
1200 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1203 /* The GL_ARB_direct_state_access specification says:
1205 * "An INVALID_OPERATION error is generated by
1206 * VertexArrayElementBuffer if <vaobj> is not [compatibility profile:
1207 * zero or] the name of an existing vertex array object."
1209 vao
=_mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayElementBuffer");
1213 vao
= _mesa_lookup_vao(ctx
, vaobj
);
1218 /* The GL_ARB_direct_state_access specification says:
1220 * "An INVALID_OPERATION error is generated if <buffer> is not zero
1221 * or the name of an existing buffer object."
1223 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
1224 "glVertexArrayElementBuffer");
1226 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
1229 bufObj
= ctx
->Shared
->NullBufferObj
;
1233 _mesa_reference_buffer_object(ctx
, &vao
->IndexBufferObj
, bufObj
);
1238 _mesa_VertexArrayElementBuffer_no_error(GLuint vaobj
, GLuint buffer
)
1240 GET_CURRENT_CONTEXT(ctx
);
1241 vertex_array_element_buffer(ctx
, vaobj
, buffer
, true);
1246 _mesa_VertexArrayElementBuffer(GLuint vaobj
, GLuint buffer
)
1248 GET_CURRENT_CONTEXT(ctx
);
1249 vertex_array_element_buffer(ctx
, vaobj
, buffer
, false);
1254 _mesa_GetVertexArrayiv(GLuint vaobj
, GLenum pname
, GLint
*param
)
1256 GET_CURRENT_CONTEXT(ctx
);
1257 struct gl_vertex_array_object
*vao
;
1259 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1261 /* The GL_ARB_direct_state_access specification says:
1263 * "An INVALID_OPERATION error is generated if <vaobj> is not
1264 * [compatibility profile: zero or] the name of an existing
1265 * vertex array object."
1267 vao
=_mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayiv");
1271 /* The GL_ARB_direct_state_access specification says:
1273 * "An INVALID_ENUM error is generated if <pname> is not
1274 * ELEMENT_ARRAY_BUFFER_BINDING."
1276 if (pname
!= GL_ELEMENT_ARRAY_BUFFER_BINDING
) {
1277 _mesa_error(ctx
, GL_INVALID_ENUM
,
1278 "glGetVertexArrayiv(pname != "
1279 "GL_ELEMENT_ARRAY_BUFFER_BINDING)");
1283 param
[0] = vao
->IndexBufferObj
->Name
;