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"
56 #include "util/u_math.h"
60 _mesa_vao_attribute_map
[ATTRIBUTE_MAP_MODE_MAX
][VERT_ATTRIB_MAX
] =
62 /* ATTRIBUTE_MAP_MODE_IDENTITY
64 * Grab vertex processing attribute VERT_ATTRIB_POS from
65 * the VAO attribute VERT_ATTRIB_POS, and grab vertex processing
66 * attribute VERT_ATTRIB_GENERIC0 from the VAO attribute
67 * VERT_ATTRIB_GENERIC0.
70 VERT_ATTRIB_POS
, /* VERT_ATTRIB_POS */
71 VERT_ATTRIB_NORMAL
, /* VERT_ATTRIB_NORMAL */
72 VERT_ATTRIB_COLOR0
, /* VERT_ATTRIB_COLOR0 */
73 VERT_ATTRIB_COLOR1
, /* VERT_ATTRIB_COLOR1 */
74 VERT_ATTRIB_FOG
, /* VERT_ATTRIB_FOG */
75 VERT_ATTRIB_COLOR_INDEX
, /* VERT_ATTRIB_COLOR_INDEX */
76 VERT_ATTRIB_EDGEFLAG
, /* VERT_ATTRIB_EDGEFLAG */
77 VERT_ATTRIB_TEX0
, /* VERT_ATTRIB_TEX0 */
78 VERT_ATTRIB_TEX1
, /* VERT_ATTRIB_TEX1 */
79 VERT_ATTRIB_TEX2
, /* VERT_ATTRIB_TEX2 */
80 VERT_ATTRIB_TEX3
, /* VERT_ATTRIB_TEX3 */
81 VERT_ATTRIB_TEX4
, /* VERT_ATTRIB_TEX4 */
82 VERT_ATTRIB_TEX5
, /* VERT_ATTRIB_TEX5 */
83 VERT_ATTRIB_TEX6
, /* VERT_ATTRIB_TEX6 */
84 VERT_ATTRIB_TEX7
, /* VERT_ATTRIB_TEX7 */
85 VERT_ATTRIB_POINT_SIZE
, /* VERT_ATTRIB_POINT_SIZE */
86 VERT_ATTRIB_GENERIC0
, /* VERT_ATTRIB_GENERIC0 */
87 VERT_ATTRIB_GENERIC1
, /* VERT_ATTRIB_GENERIC1 */
88 VERT_ATTRIB_GENERIC2
, /* VERT_ATTRIB_GENERIC2 */
89 VERT_ATTRIB_GENERIC3
, /* VERT_ATTRIB_GENERIC3 */
90 VERT_ATTRIB_GENERIC4
, /* VERT_ATTRIB_GENERIC4 */
91 VERT_ATTRIB_GENERIC5
, /* VERT_ATTRIB_GENERIC5 */
92 VERT_ATTRIB_GENERIC6
, /* VERT_ATTRIB_GENERIC6 */
93 VERT_ATTRIB_GENERIC7
, /* VERT_ATTRIB_GENERIC7 */
94 VERT_ATTRIB_GENERIC8
, /* VERT_ATTRIB_GENERIC8 */
95 VERT_ATTRIB_GENERIC9
, /* VERT_ATTRIB_GENERIC9 */
96 VERT_ATTRIB_GENERIC10
, /* VERT_ATTRIB_GENERIC10 */
97 VERT_ATTRIB_GENERIC11
, /* VERT_ATTRIB_GENERIC11 */
98 VERT_ATTRIB_GENERIC12
, /* VERT_ATTRIB_GENERIC12 */
99 VERT_ATTRIB_GENERIC13
, /* VERT_ATTRIB_GENERIC13 */
100 VERT_ATTRIB_GENERIC14
, /* VERT_ATTRIB_GENERIC14 */
101 VERT_ATTRIB_GENERIC15
/* VERT_ATTRIB_GENERIC15 */
104 /* ATTRIBUTE_MAP_MODE_POSITION
106 * Grab vertex processing attribute VERT_ATTRIB_POS as well as
107 * vertex processing attribute VERT_ATTRIB_GENERIC0 from the
108 * VAO attribute VERT_ATTRIB_POS.
111 VERT_ATTRIB_POS
, /* VERT_ATTRIB_POS */
112 VERT_ATTRIB_NORMAL
, /* VERT_ATTRIB_NORMAL */
113 VERT_ATTRIB_COLOR0
, /* VERT_ATTRIB_COLOR0 */
114 VERT_ATTRIB_COLOR1
, /* VERT_ATTRIB_COLOR1 */
115 VERT_ATTRIB_FOG
, /* VERT_ATTRIB_FOG */
116 VERT_ATTRIB_COLOR_INDEX
, /* VERT_ATTRIB_COLOR_INDEX */
117 VERT_ATTRIB_EDGEFLAG
, /* VERT_ATTRIB_EDGEFLAG */
118 VERT_ATTRIB_TEX0
, /* VERT_ATTRIB_TEX0 */
119 VERT_ATTRIB_TEX1
, /* VERT_ATTRIB_TEX1 */
120 VERT_ATTRIB_TEX2
, /* VERT_ATTRIB_TEX2 */
121 VERT_ATTRIB_TEX3
, /* VERT_ATTRIB_TEX3 */
122 VERT_ATTRIB_TEX4
, /* VERT_ATTRIB_TEX4 */
123 VERT_ATTRIB_TEX5
, /* VERT_ATTRIB_TEX5 */
124 VERT_ATTRIB_TEX6
, /* VERT_ATTRIB_TEX6 */
125 VERT_ATTRIB_TEX7
, /* VERT_ATTRIB_TEX7 */
126 VERT_ATTRIB_POINT_SIZE
, /* VERT_ATTRIB_POINT_SIZE */
127 VERT_ATTRIB_POS
, /* VERT_ATTRIB_GENERIC0 */
128 VERT_ATTRIB_GENERIC1
, /* VERT_ATTRIB_GENERIC1 */
129 VERT_ATTRIB_GENERIC2
, /* VERT_ATTRIB_GENERIC2 */
130 VERT_ATTRIB_GENERIC3
, /* VERT_ATTRIB_GENERIC3 */
131 VERT_ATTRIB_GENERIC4
, /* VERT_ATTRIB_GENERIC4 */
132 VERT_ATTRIB_GENERIC5
, /* VERT_ATTRIB_GENERIC5 */
133 VERT_ATTRIB_GENERIC6
, /* VERT_ATTRIB_GENERIC6 */
134 VERT_ATTRIB_GENERIC7
, /* VERT_ATTRIB_GENERIC7 */
135 VERT_ATTRIB_GENERIC8
, /* VERT_ATTRIB_GENERIC8 */
136 VERT_ATTRIB_GENERIC9
, /* VERT_ATTRIB_GENERIC9 */
137 VERT_ATTRIB_GENERIC10
, /* VERT_ATTRIB_GENERIC10 */
138 VERT_ATTRIB_GENERIC11
, /* VERT_ATTRIB_GENERIC11 */
139 VERT_ATTRIB_GENERIC12
, /* VERT_ATTRIB_GENERIC12 */
140 VERT_ATTRIB_GENERIC13
, /* VERT_ATTRIB_GENERIC13 */
141 VERT_ATTRIB_GENERIC14
, /* VERT_ATTRIB_GENERIC14 */
142 VERT_ATTRIB_GENERIC15
/* VERT_ATTRIB_GENERIC15 */
145 /* ATTRIBUTE_MAP_MODE_GENERIC0
147 * Grab vertex processing attribute VERT_ATTRIB_POS as well as
148 * vertex processing attribute VERT_ATTRIB_GENERIC0 from the
149 * VAO attribute VERT_ATTRIB_GENERIC0.
152 VERT_ATTRIB_GENERIC0
, /* VERT_ATTRIB_POS */
153 VERT_ATTRIB_NORMAL
, /* VERT_ATTRIB_NORMAL */
154 VERT_ATTRIB_COLOR0
, /* VERT_ATTRIB_COLOR0 */
155 VERT_ATTRIB_COLOR1
, /* VERT_ATTRIB_COLOR1 */
156 VERT_ATTRIB_FOG
, /* VERT_ATTRIB_FOG */
157 VERT_ATTRIB_COLOR_INDEX
, /* VERT_ATTRIB_COLOR_INDEX */
158 VERT_ATTRIB_EDGEFLAG
, /* VERT_ATTRIB_EDGEFLAG */
159 VERT_ATTRIB_TEX0
, /* VERT_ATTRIB_TEX0 */
160 VERT_ATTRIB_TEX1
, /* VERT_ATTRIB_TEX1 */
161 VERT_ATTRIB_TEX2
, /* VERT_ATTRIB_TEX2 */
162 VERT_ATTRIB_TEX3
, /* VERT_ATTRIB_TEX3 */
163 VERT_ATTRIB_TEX4
, /* VERT_ATTRIB_TEX4 */
164 VERT_ATTRIB_TEX5
, /* VERT_ATTRIB_TEX5 */
165 VERT_ATTRIB_TEX6
, /* VERT_ATTRIB_TEX6 */
166 VERT_ATTRIB_TEX7
, /* VERT_ATTRIB_TEX7 */
167 VERT_ATTRIB_POINT_SIZE
, /* VERT_ATTRIB_POINT_SIZE */
168 VERT_ATTRIB_GENERIC0
, /* VERT_ATTRIB_GENERIC0 */
169 VERT_ATTRIB_GENERIC1
, /* VERT_ATTRIB_GENERIC1 */
170 VERT_ATTRIB_GENERIC2
, /* VERT_ATTRIB_GENERIC2 */
171 VERT_ATTRIB_GENERIC3
, /* VERT_ATTRIB_GENERIC3 */
172 VERT_ATTRIB_GENERIC4
, /* VERT_ATTRIB_GENERIC4 */
173 VERT_ATTRIB_GENERIC5
, /* VERT_ATTRIB_GENERIC5 */
174 VERT_ATTRIB_GENERIC6
, /* VERT_ATTRIB_GENERIC6 */
175 VERT_ATTRIB_GENERIC7
, /* VERT_ATTRIB_GENERIC7 */
176 VERT_ATTRIB_GENERIC8
, /* VERT_ATTRIB_GENERIC8 */
177 VERT_ATTRIB_GENERIC9
, /* VERT_ATTRIB_GENERIC9 */
178 VERT_ATTRIB_GENERIC10
, /* VERT_ATTRIB_GENERIC10 */
179 VERT_ATTRIB_GENERIC11
, /* VERT_ATTRIB_GENERIC11 */
180 VERT_ATTRIB_GENERIC12
, /* VERT_ATTRIB_GENERIC12 */
181 VERT_ATTRIB_GENERIC13
, /* VERT_ATTRIB_GENERIC13 */
182 VERT_ATTRIB_GENERIC14
, /* VERT_ATTRIB_GENERIC14 */
183 VERT_ATTRIB_GENERIC15
/* VERT_ATTRIB_GENERIC15 */
189 * Look up the array object for the given ID.
192 * Either a pointer to the array object with the specified ID or \c NULL for
193 * a non-existent ID. The spec defines ID 0 as being technically
197 struct gl_vertex_array_object
*
198 _mesa_lookup_vao(struct gl_context
*ctx
, GLuint id
)
200 /* The ARB_direct_state_access specification says:
202 * "<vaobj> is [compatibility profile:
203 * zero, indicating the default vertex array object, or]
204 * the name of the vertex array object."
207 if (ctx
->API
== API_OPENGL_COMPAT
)
208 return ctx
->Array
.DefaultVAO
;
212 struct gl_vertex_array_object
*vao
;
214 if (ctx
->Array
.LastLookedUpVAO
&&
215 ctx
->Array
.LastLookedUpVAO
->Name
== id
) {
216 vao
= ctx
->Array
.LastLookedUpVAO
;
218 vao
= (struct gl_vertex_array_object
*)
219 _mesa_HashLookupLocked(ctx
->Array
.Objects
, id
);
221 _mesa_reference_vao(ctx
, &ctx
->Array
.LastLookedUpVAO
, vao
);
230 * Looks up the array object for the given ID.
232 * While _mesa_lookup_vao doesn't generate an error if the object does not
233 * exist, this function comes in two variants.
234 * If is_ext_dsa is false, this function generates a GL_INVALID_OPERATION
235 * error if the array object does not exist. It also returns the default
236 * array object when ctx is a compatibility profile context and id is zero.
237 * If is_ext_dsa is true, 0 is not a valid name. If the name exists but
238 * the object has never been bound, it is initialized.
240 struct gl_vertex_array_object
*
241 _mesa_lookup_vao_err(struct gl_context
*ctx
, GLuint id
,
242 bool is_ext_dsa
, const char *caller
)
244 /* The ARB_direct_state_access specification says:
246 * "<vaobj> is [compatibility profile:
247 * zero, indicating the default vertex array object, or]
248 * the name of the vertex array object."
251 if (is_ext_dsa
|| ctx
->API
== API_OPENGL_CORE
) {
252 _mesa_error(ctx
, GL_INVALID_OPERATION
,
253 "%s(zero is not valid vaobj name%s)",
255 is_ext_dsa
? "" : " in a core profile context");
259 return ctx
->Array
.DefaultVAO
;
261 struct gl_vertex_array_object
*vao
;
263 if (ctx
->Array
.LastLookedUpVAO
&&
264 ctx
->Array
.LastLookedUpVAO
->Name
== id
) {
265 vao
= ctx
->Array
.LastLookedUpVAO
;
267 vao
= (struct gl_vertex_array_object
*)
268 _mesa_HashLookupLocked(ctx
->Array
.Objects
, id
);
270 /* The ARB_direct_state_access specification says:
272 * "An INVALID_OPERATION error is generated if <vaobj> is not
273 * [compatibility profile: zero or] the name of an existing
274 * vertex array object."
276 if (!vao
|| (!is_ext_dsa
&& !vao
->EverBound
)) {
277 _mesa_error(ctx
, GL_INVALID_OPERATION
,
278 "%s(non-existent vaobj=%u)", caller
, id
);
282 /* The EXT_direct_state_access specification says:
284 * "If the vertex array object named by the vaobj parameter has not
285 * been previously bound but has been generated (without subsequent
286 * deletion) by GenVertexArrays, the GL first creates a new state
287 * vector in the same manner as when BindVertexArray creates a new
288 * vertex array object."
290 if (vao
&& is_ext_dsa
&& !vao
->EverBound
)
291 vao
->EverBound
= true;
293 _mesa_reference_vao(ctx
, &ctx
->Array
.LastLookedUpVAO
, vao
);
302 * For all the vertex binding points in the array object, unbind any pointers
303 * to any buffer objects (VBOs).
304 * This is done just prior to array object destruction.
307 unbind_array_object_vbos(struct gl_context
*ctx
, struct gl_vertex_array_object
*obj
)
311 for (i
= 0; i
< ARRAY_SIZE(obj
->BufferBinding
); i
++)
312 _mesa_reference_buffer_object(ctx
, &obj
->BufferBinding
[i
].BufferObj
, NULL
);
317 * Allocate and initialize a new vertex array object.
319 struct gl_vertex_array_object
*
320 _mesa_new_vao(struct gl_context
*ctx
, GLuint name
)
322 struct gl_vertex_array_object
*obj
= CALLOC_STRUCT(gl_vertex_array_object
);
324 _mesa_initialize_vao(ctx
, obj
, name
);
330 * Delete an array object.
333 _mesa_delete_vao(struct gl_context
*ctx
, struct gl_vertex_array_object
*obj
)
335 unbind_array_object_vbos(ctx
, obj
);
336 _mesa_reference_buffer_object(ctx
, &obj
->IndexBufferObj
, NULL
);
343 * Set ptr to vao w/ reference counting.
344 * Note: this should only be called from the _mesa_reference_vao()
348 _mesa_reference_vao_(struct gl_context
*ctx
,
349 struct gl_vertex_array_object
**ptr
,
350 struct gl_vertex_array_object
*vao
)
355 /* Unreference the old array object */
356 struct gl_vertex_array_object
*oldObj
= *ptr
;
359 if (oldObj
->SharedAndImmutable
) {
360 deleteFlag
= p_atomic_dec_zero(&oldObj
->RefCount
);
362 assert(oldObj
->RefCount
> 0);
364 deleteFlag
= (oldObj
->RefCount
== 0);
368 _mesa_delete_vao(ctx
, oldObj
);
375 /* reference new array object */
376 if (vao
->SharedAndImmutable
) {
377 p_atomic_inc(&vao
->RefCount
);
379 assert(vao
->RefCount
> 0);
389 * Initialize attributes of a vertex array within a vertex array object.
390 * \param vao the container vertex array object
391 * \param index which array in the VAO to initialize
392 * \param size number of components (1, 2, 3 or 4) per attribute
393 * \param type datatype of the attribute (GL_FLOAT, GL_INT, etc).
396 init_array(struct gl_context
*ctx
,
397 struct gl_vertex_array_object
*vao
,
398 gl_vert_attrib index
, GLint size
, GLint type
)
400 assert(index
< ARRAY_SIZE(vao
->VertexAttrib
));
401 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[index
];
402 assert(index
< ARRAY_SIZE(vao
->BufferBinding
));
403 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
405 _mesa_set_vertex_format(&array
->Format
, size
, type
, GL_RGBA
,
406 GL_FALSE
, GL_FALSE
, GL_FALSE
);
409 array
->RelativeOffset
= 0;
410 ASSERT_BITFIELD_SIZE(struct gl_array_attributes
, BufferBindingIndex
,
411 VERT_ATTRIB_MAX
- 1);
412 array
->BufferBindingIndex
= index
;
415 binding
->Stride
= array
->Format
._ElementSize
;
416 binding
->BufferObj
= NULL
;
417 binding
->_BoundArrays
= BITFIELD_BIT(index
);
419 /* Vertex array buffers */
420 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
,
421 ctx
->Shared
->NullBufferObj
);
426 * Initialize a gl_vertex_array_object's arrays.
429 _mesa_initialize_vao(struct gl_context
*ctx
,
430 struct gl_vertex_array_object
*vao
,
438 vao
->SharedAndImmutable
= false;
440 /* Init the individual arrays */
441 for (i
= 0; i
< ARRAY_SIZE(vao
->VertexAttrib
); i
++) {
443 case VERT_ATTRIB_NORMAL
:
444 init_array(ctx
, vao
, VERT_ATTRIB_NORMAL
, 3, GL_FLOAT
);
446 case VERT_ATTRIB_COLOR1
:
447 init_array(ctx
, vao
, VERT_ATTRIB_COLOR1
, 3, GL_FLOAT
);
449 case VERT_ATTRIB_FOG
:
450 init_array(ctx
, vao
, VERT_ATTRIB_FOG
, 1, GL_FLOAT
);
452 case VERT_ATTRIB_COLOR_INDEX
:
453 init_array(ctx
, vao
, VERT_ATTRIB_COLOR_INDEX
, 1, GL_FLOAT
);
455 case VERT_ATTRIB_EDGEFLAG
:
456 init_array(ctx
, vao
, VERT_ATTRIB_EDGEFLAG
, 1, GL_UNSIGNED_BYTE
);
458 case VERT_ATTRIB_POINT_SIZE
:
459 init_array(ctx
, vao
, VERT_ATTRIB_POINT_SIZE
, 1, GL_FLOAT
);
462 init_array(ctx
, vao
, i
, 4, GL_FLOAT
);
467 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_IDENTITY
;
469 _mesa_reference_buffer_object(ctx
, &vao
->IndexBufferObj
,
470 ctx
->Shared
->NullBufferObj
);
475 * Compute the offset range for the provided binding.
477 * This is a helper function for the below.
480 compute_vbo_offset_range(const struct gl_vertex_array_object
*vao
,
481 const struct gl_vertex_buffer_binding
*binding
,
482 GLsizeiptr
* min
, GLsizeiptr
* max
)
484 /* The function is meant to work on VBO bindings */
485 assert(_mesa_is_bufferobj(binding
->BufferObj
));
487 /* Start with an inverted range of relative offsets. */
488 GLuint min_offset
= ~(GLuint
)0;
489 GLuint max_offset
= 0;
491 /* We work on the unmapped originaly VAO array entries. */
492 GLbitfield mask
= vao
->Enabled
& binding
->_BoundArrays
;
493 /* The binding should be active somehow, not to return inverted ranges */
496 const int i
= u_bit_scan(&mask
);
497 const GLuint off
= vao
->VertexAttrib
[i
].RelativeOffset
;
498 min_offset
= MIN2(off
, min_offset
);
499 max_offset
= MAX2(off
, max_offset
);
502 *min
= binding
->Offset
+ (GLsizeiptr
)min_offset
;
503 *max
= binding
->Offset
+ (GLsizeiptr
)max_offset
;
508 * Update the unique binding and pos/generic0 map tracking in the vao.
510 * The idea is to build up information in the vao so that a consuming
511 * backend can execute the following to set up buffer and vertex element
514 * const GLbitfield inputs_read = VERT_BIT_ALL; // backend vp inputs
516 * // Attribute data is in a VBO.
517 * GLbitfield vbomask = inputs_read & _mesa_draw_vbo_array_bits(ctx);
519 * // The attribute index to start pulling a binding
520 * const gl_vert_attrib i = ffs(vbomask) - 1;
521 * const struct gl_vertex_buffer_binding *const binding
522 * = _mesa_draw_buffer_binding(vao, i);
524 * <insert code to handle the vertex buffer object at binding>
526 * const GLbitfield boundmask = _mesa_draw_bound_attrib_bits(binding);
527 * GLbitfield attrmask = vbomask & boundmask;
529 * // Walk attributes belonging to the binding
531 * const gl_vert_attrib attr = u_bit_scan(&attrmask);
532 * const struct gl_array_attributes *const attrib
533 * = _mesa_draw_array_attrib(vao, attr);
535 * <insert code to handle the vertex element refering to the binding>
537 * vbomask &= ~boundmask;
540 * // Process user space buffers
541 * GLbitfield usermask = inputs_read & _mesa_draw_user_array_bits(ctx);
543 * // The attribute index to start pulling a binding
544 * const gl_vert_attrib i = ffs(usermask) - 1;
545 * const struct gl_vertex_buffer_binding *const binding
546 * = _mesa_draw_buffer_binding(vao, i);
548 * <insert code to handle a set of interleaved user space arrays at binding>
550 * const GLbitfield boundmask = _mesa_draw_bound_attrib_bits(binding);
551 * GLbitfield attrmask = usermask & boundmask;
553 * // Walk interleaved attributes with a common stride and instance divisor
555 * const gl_vert_attrib attr = u_bit_scan(&attrmask);
556 * const struct gl_array_attributes *const attrib
557 * = _mesa_draw_array_attrib(vao, attr);
559 * <insert code to handle non vbo vertex arrays>
561 * usermask &= ~boundmask;
564 * // Process values that should have better been uniforms in the application
565 * GLbitfield curmask = inputs_read & _mesa_draw_current_bits(ctx);
567 * const gl_vert_attrib attr = u_bit_scan(&curmask);
568 * const struct gl_array_attributes *const attrib
569 * = _mesa_draw_current_attrib(ctx, attr);
571 * <insert code to handle current values>
575 * Note that the scan below must not incoporate any context state.
576 * The rationale is that once a VAO is finalized it should not
577 * be touched anymore. That means, do not incorporate the
578 * gl_context::Array._DrawVAOEnabledAttribs bitmask into this scan.
579 * A backend driver may further reduce the handled vertex processing
580 * inputs based on their vertex shader inputs. But scanning for
581 * collapsable binding points to reduce relocs is done based on the
583 * Also VAOs may be shared between contexts due to their use in dlists
584 * thus no context state should bleed into the VAO.
587 _mesa_update_vao_derived_arrays(struct gl_context
*ctx
,
588 struct gl_vertex_array_object
*vao
)
590 /* Make sure we do not run into problems with shared objects */
591 assert(!vao
->SharedAndImmutable
|| vao
->NewArrays
== 0);
593 /* Limit used for common binding scanning below. */
594 const GLsizeiptr MaxRelativeOffset
=
595 ctx
->Const
.MaxVertexAttribRelativeOffset
;
597 /* The gl_vertex_array_object::_AttributeMapMode denotes the way
598 * VERT_ATTRIB_{POS,GENERIC0} mapping is done.
600 * This mapping is used to map between the OpenGL api visible
601 * VERT_ATTRIB_* arrays to mesa driver arrayinputs or shader inputs.
602 * The mapping only depends on the enabled bits of the
603 * VERT_ATTRIB_{POS,GENERIC0} arrays and is tracked in the VAO.
605 * This map needs to be applied when finally translating to the bitmasks
606 * as consumed by the driver backends. The duplicate scanning is here
607 * can as well be done in the OpenGL API numbering without this map.
609 const gl_attribute_map_mode mode
= vao
->_AttributeMapMode
;
610 /* Enabled array bits. */
611 const GLbitfield enabled
= vao
->Enabled
;
612 /* VBO array bits. */
613 const GLbitfield vbos
= vao
->VertexAttribBufferMask
;
615 /* Compute and store effectively enabled and mapped vbo arrays */
616 vao
->_EffEnabledVBO
= _mesa_vao_enable_to_vp_inputs(mode
, enabled
& vbos
);
617 /* Walk those enabled arrays that have a real vbo attached */
618 GLbitfield mask
= enabled
;
620 /* Do not use u_bit_scan as we can walk multiple attrib arrays at once */
621 const int i
= ffs(mask
) - 1;
622 /* The binding from the first to be processed attribute. */
623 const GLuint bindex
= vao
->VertexAttrib
[i
].BufferBindingIndex
;
624 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[bindex
];
626 /* The scan goes different for user space arrays than vbos */
627 if (_mesa_is_bufferobj(binding
->BufferObj
)) {
628 /* The bound arrays. */
629 const GLbitfield bound
= enabled
& binding
->_BoundArrays
;
631 /* Start this current effective binding with the actual bound arrays */
632 GLbitfield eff_bound_arrays
= bound
;
635 * If there is nothing left to scan just update the effective binding
636 * information. If the VAO is already only using a single binding point
637 * we end up here. So the overhead of this scan for an application
638 * carefully preparing the VAO for draw is low.
641 GLbitfield scanmask
= mask
& vbos
& ~bound
;
642 /* Is there something left to scan? */
644 /* Just update the back reference from the attrib to the binding and
645 * the effective offset.
647 GLbitfield attrmask
= eff_bound_arrays
;
649 const int j
= u_bit_scan(&attrmask
);
650 struct gl_array_attributes
*attrib2
= &vao
->VertexAttrib
[j
];
652 /* Update the index into the common binding point and offset */
653 attrib2
->_EffBufferBindingIndex
= bindex
;
654 attrib2
->_EffRelativeOffset
= attrib2
->RelativeOffset
;
655 assert(attrib2
->_EffRelativeOffset
<= MaxRelativeOffset
);
657 /* Finally this is the set of effectively bound arrays with the
658 * original binding offset.
660 binding
->_EffOffset
= binding
->Offset
;
661 /* The bound arrays past the VERT_ATTRIB_{POS,GENERIC0} mapping. */
662 binding
->_EffBoundArrays
=
663 _mesa_vao_enable_to_vp_inputs(mode
, eff_bound_arrays
);
666 /* In the VBO case, scan for attribute/binding
667 * combinations with relative bindings in the range of
668 * [0, ctx->Const.MaxVertexAttribRelativeOffset].
669 * Note that this does also go beyond just interleaved arrays
670 * as long as they use the same VBO, binding parameters and the
671 * offsets stay within bounds that the backend still can handle.
674 GLsizeiptr min_offset
, max_offset
;
675 compute_vbo_offset_range(vao
, binding
, &min_offset
, &max_offset
);
676 assert(max_offset
<= min_offset
+ MaxRelativeOffset
);
680 /* Do not use u_bit_scan as we can walk multiple
681 * attrib arrays at once
683 const int j
= ffs(scanmask
) - 1;
684 const struct gl_array_attributes
*attrib2
=
685 &vao
->VertexAttrib
[j
];
686 const struct gl_vertex_buffer_binding
*binding2
=
687 &vao
->BufferBinding
[attrib2
->BufferBindingIndex
];
689 /* Remove those attrib bits from the mask that are bound to the
690 * same effective binding point.
692 const GLbitfield bound2
= enabled
& binding2
->_BoundArrays
;
695 /* Check if we have an identical binding */
696 if (binding
->Stride
!= binding2
->Stride
)
698 if (binding
->InstanceDivisor
!= binding2
->InstanceDivisor
)
700 if (binding
->BufferObj
!= binding2
->BufferObj
)
702 /* Check if we can fold both bindings into a common binding */
703 GLsizeiptr min_offset2
, max_offset2
;
704 compute_vbo_offset_range(vao
, binding2
,
705 &min_offset2
, &max_offset2
);
706 /* If the relative offset is within the limits ... */
707 if (min_offset
+ MaxRelativeOffset
< max_offset2
)
709 if (min_offset2
+ MaxRelativeOffset
< max_offset
)
711 /* ... add this array to the effective binding */
712 eff_bound_arrays
|= bound2
;
713 min_offset
= MIN2(min_offset
, min_offset2
);
714 max_offset
= MAX2(max_offset
, max_offset2
);
715 assert(max_offset
<= min_offset
+ MaxRelativeOffset
);
718 /* Update the back reference from the attrib to the binding */
719 GLbitfield attrmask
= eff_bound_arrays
;
721 const int j
= u_bit_scan(&attrmask
);
722 struct gl_array_attributes
*attrib2
= &vao
->VertexAttrib
[j
];
723 const struct gl_vertex_buffer_binding
*binding2
=
724 &vao
->BufferBinding
[attrib2
->BufferBindingIndex
];
726 /* Update the index into the common binding point and offset */
727 attrib2
->_EffBufferBindingIndex
= bindex
;
728 attrib2
->_EffRelativeOffset
=
729 binding2
->Offset
+ attrib2
->RelativeOffset
- min_offset
;
730 assert(attrib2
->_EffRelativeOffset
<= MaxRelativeOffset
);
732 /* Finally this is the set of effectively bound arrays */
733 binding
->_EffOffset
= min_offset
;
734 /* The bound arrays past the VERT_ATTRIB_{POS,GENERIC0} mapping. */
735 binding
->_EffBoundArrays
=
736 _mesa_vao_enable_to_vp_inputs(mode
, eff_bound_arrays
);
739 /* Mark all the effective bound arrays as processed. */
740 mask
&= ~eff_bound_arrays
;
743 /* Scanning of common bindings for user space arrays.
746 const struct gl_array_attributes
*attrib
= &vao
->VertexAttrib
[i
];
747 const GLbitfield bound
= VERT_BIT(i
);
749 /* Note that user space array pointers can only happen using a one
750 * to one binding point to array mapping.
751 * The OpenGL 4.x/ARB_vertex_attrib_binding api does not support
752 * user space arrays collected at multiple binding points.
753 * The only provider of user space interleaved arrays with a single
754 * binding point is the mesa internal vbo module. But that one
755 * provides a perfect interleaved set of arrays.
757 * If this would not be true we would potentially get attribute arrays
758 * with user space pointers that may not lie within the
759 * MaxRelativeOffset range but still attached to a single binding.
760 * Then we would need to store the effective attribute and binding
761 * grouping information in a seperate array beside
762 * gl_array_attributes/gl_vertex_buffer_binding.
764 assert(util_bitcount(binding
->_BoundArrays
& vao
->Enabled
) == 1
765 || (vao
->Enabled
& ~binding
->_BoundArrays
) == 0);
767 /* Start this current effective binding with the array */
768 GLbitfield eff_bound_arrays
= bound
;
770 const GLubyte
*ptr
= attrib
->Ptr
;
771 unsigned vertex_end
= attrib
->Format
._ElementSize
;
773 /* Walk other user space arrays and see which are interleaved
774 * using the same binding parameters.
776 GLbitfield scanmask
= mask
& ~vbos
& ~bound
;
778 const int j
= u_bit_scan(&scanmask
);
779 const struct gl_array_attributes
*attrib2
= &vao
->VertexAttrib
[j
];
780 const struct gl_vertex_buffer_binding
*binding2
=
781 &vao
->BufferBinding
[attrib2
->BufferBindingIndex
];
783 /* See the comment at the same assert above. */
784 assert(util_bitcount(binding2
->_BoundArrays
& vao
->Enabled
) == 1
785 || (vao
->Enabled
& ~binding
->_BoundArrays
) == 0);
787 /* Check if we have an identical binding */
788 if (binding
->Stride
!= binding2
->Stride
)
790 if (binding
->InstanceDivisor
!= binding2
->InstanceDivisor
)
792 if (ptr
<= attrib2
->Ptr
) {
793 if (ptr
+ binding
->Stride
< attrib2
->Ptr
+
794 attrib2
->Format
._ElementSize
)
796 unsigned end
= attrib2
->Ptr
+ attrib2
->Format
._ElementSize
- ptr
;
797 vertex_end
= MAX2(vertex_end
, end
);
799 if (attrib2
->Ptr
+ binding
->Stride
< ptr
+ vertex_end
)
801 vertex_end
+= (GLsizei
)(ptr
- attrib2
->Ptr
);
805 /* User space buffer object */
806 assert(!_mesa_is_bufferobj(binding2
->BufferObj
));
808 eff_bound_arrays
|= VERT_BIT(j
);
811 /* Update the back reference from the attrib to the binding */
812 GLbitfield attrmask
= eff_bound_arrays
;
814 const int j
= u_bit_scan(&attrmask
);
815 struct gl_array_attributes
*attrib2
= &vao
->VertexAttrib
[j
];
817 /* Update the index into the common binding point and the offset */
818 attrib2
->_EffBufferBindingIndex
= bindex
;
819 attrib2
->_EffRelativeOffset
= attrib2
->Ptr
- ptr
;
820 assert(attrib2
->_EffRelativeOffset
<= binding
->Stride
);
822 /* Finally this is the set of effectively bound arrays */
823 binding
->_EffOffset
= (GLintptr
)ptr
;
824 /* The bound arrays past the VERT_ATTRIB_{POS,GENERIC0} mapping. */
825 binding
->_EffBoundArrays
=
826 _mesa_vao_enable_to_vp_inputs(mode
, eff_bound_arrays
);
828 /* Mark all the effective bound arrays as processed. */
829 mask
&= ~eff_bound_arrays
;
834 /* Make sure the above code works as expected. */
835 for (gl_vert_attrib attr
= 0; attr
< VERT_ATTRIB_MAX
; ++attr
) {
836 /* Query the original api defined attrib/binding information ... */
837 const unsigned char *const map
=_mesa_vao_attribute_map
[mode
];
838 if (vao
->Enabled
& VERT_BIT(map
[attr
])) {
839 const struct gl_array_attributes
*attrib
=
840 &vao
->VertexAttrib
[map
[attr
]];
841 const struct gl_vertex_buffer_binding
*binding
=
842 &vao
->BufferBinding
[attrib
->BufferBindingIndex
];
843 /* ... and compare that with the computed attrib/binding */
844 const struct gl_vertex_buffer_binding
*binding2
=
845 &vao
->BufferBinding
[attrib
->_EffBufferBindingIndex
];
846 assert(binding
->Stride
== binding2
->Stride
);
847 assert(binding
->InstanceDivisor
== binding2
->InstanceDivisor
);
848 assert(binding
->BufferObj
== binding2
->BufferObj
);
849 if (_mesa_is_bufferobj(binding
->BufferObj
)) {
850 assert(attrib
->_EffRelativeOffset
<= MaxRelativeOffset
);
851 assert(binding
->Offset
+ attrib
->RelativeOffset
==
852 binding2
->_EffOffset
+ attrib
->_EffRelativeOffset
);
854 assert(attrib
->_EffRelativeOffset
< binding
->Stride
);
855 assert((GLintptr
)attrib
->Ptr
==
856 binding2
->_EffOffset
+ attrib
->_EffRelativeOffset
);
865 _mesa_set_vao_immutable(struct gl_context
*ctx
,
866 struct gl_vertex_array_object
*vao
)
868 _mesa_update_vao_derived_arrays(ctx
, vao
);
870 vao
->SharedAndImmutable
= true;
875 _mesa_all_varyings_in_vbos(const struct gl_vertex_array_object
*vao
)
877 /* Walk those enabled arrays that have the default vbo attached */
878 GLbitfield mask
= vao
->Enabled
& ~vao
->VertexAttribBufferMask
;
881 /* Do not use u_bit_scan64 as we can walk multiple
882 * attrib arrays at once
884 const int i
= ffs(mask
) - 1;
885 const struct gl_array_attributes
*attrib_array
=
886 &vao
->VertexAttrib
[i
];
887 const struct gl_vertex_buffer_binding
*buffer_binding
=
888 &vao
->BufferBinding
[attrib_array
->BufferBindingIndex
];
890 /* We have already masked out vao->VertexAttribBufferMask */
891 assert(!_mesa_is_bufferobj(buffer_binding
->BufferObj
));
893 /* Bail out once we find the first non vbo with a non zero stride */
894 if (buffer_binding
->Stride
!= 0)
897 /* Note that we cannot use the xor variant since the _BoundArray mask
898 * may contain array attributes that are bound but not enabled.
900 mask
&= ~buffer_binding
->_BoundArrays
;
907 _mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object
*vao
)
909 /* Walk the enabled arrays that have a vbo attached */
910 GLbitfield mask
= vao
->Enabled
& vao
->VertexAttribBufferMask
;
913 const int i
= ffs(mask
) - 1;
914 const struct gl_array_attributes
*attrib_array
=
915 &vao
->VertexAttrib
[i
];
916 const struct gl_vertex_buffer_binding
*buffer_binding
=
917 &vao
->BufferBinding
[attrib_array
->BufferBindingIndex
];
919 /* We have already masked with vao->VertexAttribBufferMask */
920 assert(_mesa_is_bufferobj(buffer_binding
->BufferObj
));
922 /* Bail out once we find the first disallowed mapping */
923 if (_mesa_check_disallowed_mapping(buffer_binding
->BufferObj
))
926 /* We have handled everything that is bound to this buffer_binding. */
927 mask
&= ~buffer_binding
->_BoundArrays
;
935 * Map buffer objects used in attribute arrays.
938 _mesa_vao_map_arrays(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
941 GLbitfield mask
= vao
->Enabled
& vao
->VertexAttribBufferMask
;
943 /* Do not use u_bit_scan as we can walk multiple attrib arrays at once */
944 const gl_vert_attrib attr
= ffs(mask
) - 1;
945 const GLubyte bindex
= vao
->VertexAttrib
[attr
].BufferBindingIndex
;
946 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[bindex
];
947 mask
&= ~binding
->_BoundArrays
;
949 struct gl_buffer_object
*bo
= binding
->BufferObj
;
950 assert(_mesa_is_bufferobj(bo
));
951 if (_mesa_bufferobj_mapped(bo
, MAP_INTERNAL
))
954 ctx
->Driver
.MapBufferRange(ctx
, 0, bo
->Size
, access
, bo
, MAP_INTERNAL
);
960 * Map buffer objects used in the vao, attribute arrays and index buffer.
963 _mesa_vao_map(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
,
966 struct gl_buffer_object
*bo
= vao
->IndexBufferObj
;
968 /* map the index buffer, if there is one, and not already mapped */
969 if (_mesa_is_bufferobj(bo
) && !_mesa_bufferobj_mapped(bo
, MAP_INTERNAL
))
970 ctx
->Driver
.MapBufferRange(ctx
, 0, bo
->Size
, access
, bo
, MAP_INTERNAL
);
972 _mesa_vao_map_arrays(ctx
, vao
, access
);
977 * Unmap buffer objects used in attribute arrays.
980 _mesa_vao_unmap_arrays(struct gl_context
*ctx
,
981 struct gl_vertex_array_object
*vao
)
983 GLbitfield mask
= vao
->Enabled
& vao
->VertexAttribBufferMask
;
985 /* Do not use u_bit_scan as we can walk multiple attrib arrays at once */
986 const gl_vert_attrib attr
= ffs(mask
) - 1;
987 const GLubyte bindex
= vao
->VertexAttrib
[attr
].BufferBindingIndex
;
988 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[bindex
];
989 mask
&= ~binding
->_BoundArrays
;
991 struct gl_buffer_object
*bo
= binding
->BufferObj
;
992 assert(_mesa_is_bufferobj(bo
));
993 if (!_mesa_bufferobj_mapped(bo
, MAP_INTERNAL
))
996 ctx
->Driver
.UnmapBuffer(ctx
, bo
, MAP_INTERNAL
);
1002 * Unmap buffer objects used in the vao, attribute arrays and index buffer.
1005 _mesa_vao_unmap(struct gl_context
*ctx
, struct gl_vertex_array_object
*vao
)
1007 struct gl_buffer_object
*bo
= vao
->IndexBufferObj
;
1009 /* unmap the index buffer, if there is one, and still mapped */
1010 if (_mesa_is_bufferobj(bo
) && _mesa_bufferobj_mapped(bo
, MAP_INTERNAL
))
1011 ctx
->Driver
.UnmapBuffer(ctx
, bo
, MAP_INTERNAL
);
1013 _mesa_vao_unmap_arrays(ctx
, vao
);
1017 /**********************************************************************/
1019 /**********************************************************************/
1023 * ARB version of glBindVertexArray()
1025 static ALWAYS_INLINE
void
1026 bind_vertex_array(struct gl_context
*ctx
, GLuint id
, bool no_error
)
1028 struct gl_vertex_array_object
*const oldObj
= ctx
->Array
.VAO
;
1029 struct gl_vertex_array_object
*newObj
= NULL
;
1031 assert(oldObj
!= NULL
);
1033 if (oldObj
->Name
== id
)
1034 return; /* rebinding the same array object- no change */
1037 * Get pointer to new array object (newObj)
1040 /* The spec says there is no array object named 0, but we use
1041 * one internally because it simplifies things.
1043 newObj
= ctx
->Array
.DefaultVAO
;
1046 /* non-default array object */
1047 newObj
= _mesa_lookup_vao(ctx
, id
);
1048 if (!no_error
&& !newObj
) {
1049 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1050 "glBindVertexArray(non-gen name)");
1054 newObj
->EverBound
= GL_TRUE
;
1057 /* The _DrawArrays pointer is pointing at the VAO being unbound and
1058 * that VAO may be in the process of being deleted. If it's not going
1059 * to be deleted, this will have no effect, because the pointer needs
1060 * to be updated by the VBO module anyway.
1062 * Before the VBO module can update the pointer, we have to set it
1063 * to NULL for drivers not to set up arrays which are not bound,
1064 * or to prevent a crash if the VAO being unbound is going to be
1067 _mesa_set_draw_vao(ctx
, ctx
->Array
._EmptyVAO
, 0);
1069 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, newObj
);
1074 _mesa_BindVertexArray_no_error(GLuint id
)
1076 GET_CURRENT_CONTEXT(ctx
);
1077 bind_vertex_array(ctx
, id
, true);
1082 _mesa_BindVertexArray(GLuint id
)
1084 GET_CURRENT_CONTEXT(ctx
);
1085 bind_vertex_array(ctx
, id
, false);
1090 * Delete a set of array objects.
1092 * \param n Number of array objects to delete.
1093 * \param ids Array of \c n array object IDs.
1096 delete_vertex_arrays(struct gl_context
*ctx
, GLsizei n
, const GLuint
*ids
)
1100 for (i
= 0; i
< n
; i
++) {
1101 /* IDs equal to 0 should be silently ignored. */
1105 struct gl_vertex_array_object
*obj
= _mesa_lookup_vao(ctx
, ids
[i
]);
1108 assert(obj
->Name
== ids
[i
]);
1110 /* If the array object is currently bound, the spec says "the binding
1111 * for that object reverts to zero and the default vertex array
1114 if (obj
== ctx
->Array
.VAO
)
1115 _mesa_BindVertexArray_no_error(0);
1117 /* The ID is immediately freed for re-use */
1118 _mesa_HashRemoveLocked(ctx
->Array
.Objects
, obj
->Name
);
1120 if (ctx
->Array
.LastLookedUpVAO
== obj
)
1121 _mesa_reference_vao(ctx
, &ctx
->Array
.LastLookedUpVAO
, NULL
);
1122 if (ctx
->Array
._DrawVAO
== obj
)
1123 _mesa_set_draw_vao(ctx
, ctx
->Array
._EmptyVAO
, 0);
1125 /* Unreference the array object.
1126 * If refcount hits zero, the object will be deleted.
1128 _mesa_reference_vao(ctx
, &obj
, NULL
);
1135 _mesa_DeleteVertexArrays_no_error(GLsizei n
, const GLuint
*ids
)
1137 GET_CURRENT_CONTEXT(ctx
);
1138 delete_vertex_arrays(ctx
, n
, ids
);
1143 _mesa_DeleteVertexArrays(GLsizei n
, const GLuint
*ids
)
1145 GET_CURRENT_CONTEXT(ctx
);
1148 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteVertexArray(n)");
1152 delete_vertex_arrays(ctx
, n
, ids
);
1157 * Generate a set of unique array object IDs and store them in \c arrays.
1158 * Helper for _mesa_GenVertexArrays() and _mesa_CreateVertexArrays()
1161 * \param n Number of IDs to generate.
1162 * \param arrays Array of \c n locations to store the IDs.
1163 * \param create Indicates that the objects should also be created.
1164 * \param func The name of the GL entry point.
1167 gen_vertex_arrays(struct gl_context
*ctx
, GLsizei n
, GLuint
*arrays
,
1168 bool create
, const char *func
)
1176 first
= _mesa_HashFindFreeKeyBlock(ctx
->Array
.Objects
, n
);
1178 /* For the sake of simplicity we create the array objects in both
1179 * the Gen* and Create* cases. The only difference is the value of
1180 * EverBound, which is set to true in the Create* case.
1182 for (i
= 0; i
< n
; i
++) {
1183 struct gl_vertex_array_object
*obj
;
1184 GLuint name
= first
+ i
;
1186 obj
= _mesa_new_vao(ctx
, name
);
1188 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
1191 obj
->EverBound
= create
;
1192 _mesa_HashInsertLocked(ctx
->Array
.Objects
, obj
->Name
, obj
);
1193 arrays
[i
] = first
+ i
;
1199 gen_vertex_arrays_err(struct gl_context
*ctx
, GLsizei n
, GLuint
*arrays
,
1200 bool create
, const char *func
)
1203 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
1207 gen_vertex_arrays(ctx
, n
, arrays
, create
, func
);
1212 * ARB version of glGenVertexArrays()
1213 * All arrays will be required to live in VBOs.
1216 _mesa_GenVertexArrays_no_error(GLsizei n
, GLuint
*arrays
)
1218 GET_CURRENT_CONTEXT(ctx
);
1219 gen_vertex_arrays(ctx
, n
, arrays
, false, "glGenVertexArrays");
1224 _mesa_GenVertexArrays(GLsizei n
, GLuint
*arrays
)
1226 GET_CURRENT_CONTEXT(ctx
);
1227 gen_vertex_arrays_err(ctx
, n
, arrays
, false, "glGenVertexArrays");
1232 * ARB_direct_state_access
1233 * Generates ID's and creates the array objects.
1236 _mesa_CreateVertexArrays_no_error(GLsizei n
, GLuint
*arrays
)
1238 GET_CURRENT_CONTEXT(ctx
);
1239 gen_vertex_arrays(ctx
, n
, arrays
, true, "glCreateVertexArrays");
1244 _mesa_CreateVertexArrays(GLsizei n
, GLuint
*arrays
)
1246 GET_CURRENT_CONTEXT(ctx
);
1247 gen_vertex_arrays_err(ctx
, n
, arrays
, true, "glCreateVertexArrays");
1252 * Determine if ID is the name of an array object.
1254 * \param id ID of the potential array object.
1255 * \return \c GL_TRUE if \c id is the name of a array object,
1256 * \c GL_FALSE otherwise.
1258 GLboolean GLAPIENTRY
1259 _mesa_IsVertexArray( GLuint id
)
1261 struct gl_vertex_array_object
* obj
;
1262 GET_CURRENT_CONTEXT(ctx
);
1263 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1265 obj
= _mesa_lookup_vao(ctx
, id
);
1267 return obj
!= NULL
&& obj
->EverBound
;
1272 * Sets the element array buffer binding of a vertex array object.
1274 * This is the ARB_direct_state_access equivalent of
1275 * glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer).
1277 static ALWAYS_INLINE
void
1278 vertex_array_element_buffer(struct gl_context
*ctx
, GLuint vaobj
, GLuint buffer
,
1281 struct gl_vertex_array_object
*vao
;
1282 struct gl_buffer_object
*bufObj
;
1284 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1287 /* The GL_ARB_direct_state_access specification says:
1289 * "An INVALID_OPERATION error is generated by
1290 * VertexArrayElementBuffer if <vaobj> is not [compatibility profile:
1291 * zero or] the name of an existing vertex array object."
1293 vao
=_mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayElementBuffer");
1297 vao
= _mesa_lookup_vao(ctx
, vaobj
);
1302 /* The GL_ARB_direct_state_access specification says:
1304 * "An INVALID_OPERATION error is generated if <buffer> is not zero
1305 * or the name of an existing buffer object."
1307 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
1308 "glVertexArrayElementBuffer");
1310 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
1313 bufObj
= ctx
->Shared
->NullBufferObj
;
1317 bufObj
->UsageHistory
|= USAGE_ELEMENT_ARRAY_BUFFER
;
1318 _mesa_reference_buffer_object(ctx
, &vao
->IndexBufferObj
, bufObj
);
1324 _mesa_VertexArrayElementBuffer_no_error(GLuint vaobj
, GLuint buffer
)
1326 GET_CURRENT_CONTEXT(ctx
);
1327 vertex_array_element_buffer(ctx
, vaobj
, buffer
, true);
1332 _mesa_VertexArrayElementBuffer(GLuint vaobj
, GLuint buffer
)
1334 GET_CURRENT_CONTEXT(ctx
);
1335 vertex_array_element_buffer(ctx
, vaobj
, buffer
, false);
1340 _mesa_GetVertexArrayiv(GLuint vaobj
, GLenum pname
, GLint
*param
)
1342 GET_CURRENT_CONTEXT(ctx
);
1343 struct gl_vertex_array_object
*vao
;
1345 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1347 /* The GL_ARB_direct_state_access specification says:
1349 * "An INVALID_OPERATION error is generated if <vaobj> is not
1350 * [compatibility profile: zero or] the name of an existing
1351 * vertex array object."
1353 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glGetVertexArrayiv");
1357 /* The GL_ARB_direct_state_access specification says:
1359 * "An INVALID_ENUM error is generated if <pname> is not
1360 * ELEMENT_ARRAY_BUFFER_BINDING."
1362 if (pname
!= GL_ELEMENT_ARRAY_BUFFER_BINDING
) {
1363 _mesa_error(ctx
, GL_INVALID_ENUM
,
1364 "glGetVertexArrayiv(pname != "
1365 "GL_ELEMENT_ARRAY_BUFFER_BINDING)");
1369 param
[0] = vao
->IndexBufferObj
->Name
;