mesa: Remove unnecessary locking from container objects.
[mesa.git] / src / mesa / main / arrayobj.c
1 /*
2 * Mesa 3-D graphics library
3 *
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.
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
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.
25 */
26
27
28 /**
29 * \file arrayobj.c
30 *
31 * Implementation of Vertex Array Objects (VAOs), from OpenGL 3.1+,
32 * the GL_ARB_vertex_array_object extension, or the older
33 * GL_APPLE_vertex_array_object extension.
34 *
35 * \todo
36 * The code in this file borrows a lot from bufferobj.c. There's a certain
37 * amount of cruft left over from that origin that may be unnecessary.
38 *
39 * \author Ian Romanick <idr@us.ibm.com>
40 * \author Brian Paul
41 */
42
43
44 #include "glheader.h"
45 #include "hash.h"
46 #include "image.h"
47 #include "imports.h"
48 #include "context.h"
49 #include "bufferobj.h"
50 #include "arrayobj.h"
51 #include "macros.h"
52 #include "mtypes.h"
53 #include "varray.h"
54 #include "main/dispatch.h"
55 #include "util/bitscan.h"
56
57
58 /**
59 * Look up the array object for the given ID.
60 *
61 * \returns
62 * Either a pointer to the array object with the specified ID or \c NULL for
63 * a non-existent ID. The spec defines ID 0 as being technically
64 * non-existent.
65 */
66
67 struct gl_vertex_array_object *
68 _mesa_lookup_vao(struct gl_context *ctx, GLuint id)
69 {
70 if (id == 0)
71 return NULL;
72 else
73 return (struct gl_vertex_array_object *)
74 _mesa_HashLookup(ctx->Array.Objects, id);
75 }
76
77
78 /**
79 * Looks up the array object for the given ID.
80 *
81 * Unlike _mesa_lookup_vao, this function generates a GL_INVALID_OPERATION
82 * error if the array object does not exist. It also returns the default
83 * array object when ctx is a compatibility profile context and id is zero.
84 */
85 struct gl_vertex_array_object *
86 _mesa_lookup_vao_err(struct gl_context *ctx, GLuint id, const char *caller)
87 {
88 /* The ARB_direct_state_access specification says:
89 *
90 * "<vaobj> is [compatibility profile:
91 * zero, indicating the default vertex array object, or]
92 * the name of the vertex array object."
93 */
94 if (id == 0) {
95 if (ctx->API == API_OPENGL_CORE) {
96 _mesa_error(ctx, GL_INVALID_OPERATION,
97 "%s(zero is not valid vaobj name in a core profile "
98 "context)", caller);
99 return NULL;
100 }
101
102 return ctx->Array.DefaultVAO;
103 } else {
104 struct gl_vertex_array_object *vao;
105
106 if (ctx->Array.LastLookedUpVAO &&
107 ctx->Array.LastLookedUpVAO->Name == id) {
108 vao = ctx->Array.LastLookedUpVAO;
109 } else {
110 vao = (struct gl_vertex_array_object *)
111 _mesa_HashLookup(ctx->Array.Objects, id);
112
113 /* The ARB_direct_state_access specification says:
114 *
115 * "An INVALID_OPERATION error is generated if <vaobj> is not
116 * [compatibility profile: zero or] the name of an existing
117 * vertex array object."
118 */
119 if (!vao || !vao->EverBound) {
120 _mesa_error(ctx, GL_INVALID_OPERATION,
121 "%s(non-existent vaobj=%u)", caller, id);
122 return NULL;
123 }
124
125 _mesa_reference_vao(ctx, &ctx->Array.LastLookedUpVAO, vao);
126 }
127
128 return vao;
129 }
130 }
131
132
133 /**
134 * For all the vertex binding points in the array object, unbind any pointers
135 * to any buffer objects (VBOs).
136 * This is done just prior to array object destruction.
137 */
138 static void
139 unbind_array_object_vbos(struct gl_context *ctx, struct gl_vertex_array_object *obj)
140 {
141 GLuint i;
142
143 for (i = 0; i < ARRAY_SIZE(obj->BufferBinding); i++)
144 _mesa_reference_buffer_object(ctx, &obj->BufferBinding[i].BufferObj, NULL);
145
146 for (i = 0; i < ARRAY_SIZE(obj->_VertexAttrib); i++)
147 _mesa_reference_buffer_object(ctx, &obj->_VertexAttrib[i].BufferObj, NULL);
148 }
149
150
151 /**
152 * Allocate and initialize a new vertex array object.
153 */
154 struct gl_vertex_array_object *
155 _mesa_new_vao(struct gl_context *ctx, GLuint name)
156 {
157 struct gl_vertex_array_object *obj = CALLOC_STRUCT(gl_vertex_array_object);
158 if (obj)
159 _mesa_initialize_vao(ctx, obj, name);
160 return obj;
161 }
162
163
164 /**
165 * Delete an array object.
166 */
167 void
168 _mesa_delete_vao(struct gl_context *ctx, struct gl_vertex_array_object *obj)
169 {
170 unbind_array_object_vbos(ctx, obj);
171 _mesa_reference_buffer_object(ctx, &obj->IndexBufferObj, NULL);
172 free(obj->Label);
173 free(obj);
174 }
175
176
177 /**
178 * Set ptr to vao w/ reference counting.
179 * Note: this should only be called from the _mesa_reference_vao()
180 * inline function.
181 */
182 void
183 _mesa_reference_vao_(struct gl_context *ctx,
184 struct gl_vertex_array_object **ptr,
185 struct gl_vertex_array_object *vao)
186 {
187 assert(*ptr != vao);
188
189 if (*ptr) {
190 /* Unreference the old array object */
191 GLboolean deleteFlag = GL_FALSE;
192 struct gl_vertex_array_object *oldObj = *ptr;
193
194 assert(oldObj->RefCount > 0);
195 oldObj->RefCount--;
196 deleteFlag = (oldObj->RefCount == 0);
197
198 if (deleteFlag)
199 _mesa_delete_vao(ctx, oldObj);
200
201 *ptr = NULL;
202 }
203 assert(!*ptr);
204
205 if (vao) {
206 /* reference new array object */
207 assert(vao->RefCount > 0);
208
209 vao->RefCount++;
210 *ptr = vao;
211 }
212 }
213
214
215 /**
216 * Initialize attribtes of a vertex array within a vertex array object.
217 * \param vao the container vertex array object
218 * \param index which array in the VAO to initialize
219 * \param size number of components (1, 2, 3 or 4) per attribute
220 * \param type datatype of the attribute (GL_FLOAT, GL_INT, etc).
221 */
222 static void
223 init_array(struct gl_context *ctx,
224 struct gl_vertex_array_object *vao,
225 GLuint index, GLint size, GLint type)
226 {
227 struct gl_array_attributes *array = &vao->VertexAttrib[index];
228 struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index];
229
230 array->Size = size;
231 array->Type = type;
232 array->Format = GL_RGBA; /* only significant for GL_EXT_vertex_array_bgra */
233 array->Stride = 0;
234 array->Ptr = NULL;
235 array->RelativeOffset = 0;
236 array->Enabled = GL_FALSE;
237 array->Normalized = GL_FALSE;
238 array->Integer = GL_FALSE;
239 array->Doubles = GL_FALSE;
240 array->_ElementSize = size * _mesa_sizeof_type(type);
241 array->BufferBindingIndex = index;
242
243 binding->Offset = 0;
244 binding->Stride = array->_ElementSize;
245 binding->BufferObj = NULL;
246 binding->_BoundArrays = BITFIELD64_BIT(index);
247
248 /* Vertex array buffers */
249 _mesa_reference_buffer_object(ctx, &binding->BufferObj,
250 ctx->Shared->NullBufferObj);
251 }
252
253
254 /**
255 * Initialize a gl_vertex_array_object's arrays.
256 */
257 void
258 _mesa_initialize_vao(struct gl_context *ctx,
259 struct gl_vertex_array_object *vao,
260 GLuint name)
261 {
262 GLuint i;
263
264 vao->Name = name;
265
266 vao->RefCount = 1;
267
268 /* Init the individual arrays */
269 for (i = 0; i < ARRAY_SIZE(vao->VertexAttrib); i++) {
270 switch (i) {
271 case VERT_ATTRIB_WEIGHT:
272 init_array(ctx, vao, VERT_ATTRIB_WEIGHT, 1, GL_FLOAT);
273 break;
274 case VERT_ATTRIB_NORMAL:
275 init_array(ctx, vao, VERT_ATTRIB_NORMAL, 3, GL_FLOAT);
276 break;
277 case VERT_ATTRIB_COLOR1:
278 init_array(ctx, vao, VERT_ATTRIB_COLOR1, 3, GL_FLOAT);
279 break;
280 case VERT_ATTRIB_FOG:
281 init_array(ctx, vao, VERT_ATTRIB_FOG, 1, GL_FLOAT);
282 break;
283 case VERT_ATTRIB_COLOR_INDEX:
284 init_array(ctx, vao, VERT_ATTRIB_COLOR_INDEX, 1, GL_FLOAT);
285 break;
286 case VERT_ATTRIB_EDGEFLAG:
287 init_array(ctx, vao, VERT_ATTRIB_EDGEFLAG, 1, GL_BOOL);
288 break;
289 case VERT_ATTRIB_POINT_SIZE:
290 init_array(ctx, vao, VERT_ATTRIB_POINT_SIZE, 1, GL_FLOAT);
291 break;
292 default:
293 init_array(ctx, vao, i, 4, GL_FLOAT);
294 break;
295 }
296 }
297
298 _mesa_reference_buffer_object(ctx, &vao->IndexBufferObj,
299 ctx->Shared->NullBufferObj);
300 }
301
302
303 /**
304 * Add the given array object to the array object pool.
305 */
306 static void
307 save_array_object(struct gl_context *ctx, struct gl_vertex_array_object *vao)
308 {
309 if (vao->Name > 0) {
310 /* insert into hash table */
311 _mesa_HashInsert(ctx->Array.Objects, vao->Name, vao);
312 }
313 }
314
315
316 /**
317 * Remove the given array object from the array object pool.
318 * Do not deallocate the array object though.
319 */
320 static void
321 remove_array_object(struct gl_context *ctx, struct gl_vertex_array_object *vao)
322 {
323 if (vao->Name > 0) {
324 /* remove from hash table */
325 _mesa_HashRemove(ctx->Array.Objects, vao->Name);
326 }
327 }
328
329
330 /**
331 * Updates the derived gl_vertex_arrays when a gl_vertex_attrib_array
332 * or a gl_vertex_buffer_binding has changed.
333 */
334 void
335 _mesa_update_vao_client_arrays(struct gl_context *ctx,
336 struct gl_vertex_array_object *vao)
337 {
338 GLbitfield64 arrays = vao->NewArrays;
339
340 while (arrays) {
341 const int attrib = u_bit_scan64(&arrays);
342 struct gl_vertex_array *client_array = &vao->_VertexAttrib[attrib];
343 const struct gl_array_attributes *attrib_array =
344 &vao->VertexAttrib[attrib];
345 const struct gl_vertex_buffer_binding *buffer_binding =
346 &vao->BufferBinding[attrib_array->BufferBindingIndex];
347
348 _mesa_update_client_array(ctx, client_array, attrib_array,
349 buffer_binding);
350 }
351 }
352
353
354 bool
355 _mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao)
356 {
357 /* Walk those enabled arrays that have the default vbo attached */
358 GLbitfield64 mask = vao->_Enabled & ~vao->VertexAttribBufferMask;
359
360 while (mask) {
361 /* Do not use u_bit_scan64 as we can walk multiple
362 * attrib arrays at once
363 */
364 const int i = ffsll(mask) - 1;
365 const struct gl_array_attributes *attrib_array =
366 &vao->VertexAttrib[i];
367 const struct gl_vertex_buffer_binding *buffer_binding =
368 &vao->BufferBinding[attrib_array->BufferBindingIndex];
369
370 /* Only enabled arrays shall appear in the _Enabled bitmask */
371 assert(attrib_array->Enabled);
372 /* We have already masked out vao->VertexAttribBufferMask */
373 assert(!_mesa_is_bufferobj(buffer_binding->BufferObj));
374
375 /* Bail out once we find the first non vbo with a non zero stride */
376 if (buffer_binding->Stride != 0)
377 return false;
378
379 /* Note that we cannot use the xor variant since the _BoundArray mask
380 * may contain array attributes that are bound but not enabled.
381 */
382 mask &= ~buffer_binding->_BoundArrays;
383 }
384
385 return true;
386 }
387
388 bool
389 _mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao)
390 {
391 /* Walk the enabled arrays that have a vbo attached */
392 GLbitfield64 mask = vao->_Enabled & vao->VertexAttribBufferMask;
393
394 while (mask) {
395 const int i = ffsll(mask) - 1;
396 const struct gl_array_attributes *attrib_array =
397 &vao->VertexAttrib[i];
398 const struct gl_vertex_buffer_binding *buffer_binding =
399 &vao->BufferBinding[attrib_array->BufferBindingIndex];
400
401 /* Only enabled arrays shall appear in the _Enabled bitmask */
402 assert(attrib_array->Enabled);
403 /* We have already masked with vao->VertexAttribBufferMask */
404 assert(_mesa_is_bufferobj(buffer_binding->BufferObj));
405
406 /* Bail out once we find the first disallowed mapping */
407 if (_mesa_check_disallowed_mapping(buffer_binding->BufferObj))
408 return false;
409
410 /* We have handled everything that is bound to this buffer_binding. */
411 mask &= ~buffer_binding->_BoundArrays;
412 }
413
414 return true;
415 }
416
417 /**********************************************************************/
418 /* API Functions */
419 /**********************************************************************/
420
421
422 /**
423 * Helper for _mesa_BindVertexArray() and _mesa_BindVertexArrayAPPLE().
424 * \param genRequired specifies behavour when id was not generated with
425 * glGenVertexArrays().
426 */
427 static void
428 bind_vertex_array(struct gl_context *ctx, GLuint id, GLboolean genRequired)
429 {
430 struct gl_vertex_array_object * const oldObj = ctx->Array.VAO;
431 struct gl_vertex_array_object *newObj = NULL;
432
433 assert(oldObj != NULL);
434
435 if ( oldObj->Name == id )
436 return; /* rebinding the same array object- no change */
437
438 /*
439 * Get pointer to new array object (newObj)
440 */
441 if (id == 0) {
442 /* The spec says there is no array object named 0, but we use
443 * one internally because it simplifies things.
444 */
445 newObj = ctx->Array.DefaultVAO;
446 }
447 else {
448 /* non-default array object */
449 newObj = _mesa_lookup_vao(ctx, id);
450 if (!newObj) {
451 if (genRequired) {
452 _mesa_error(ctx, GL_INVALID_OPERATION,
453 "glBindVertexArray(non-gen name)");
454 return;
455 }
456
457 /* For APPLE version, generate a new array object now */
458 newObj = _mesa_new_vao(ctx, id);
459 if (!newObj) {
460 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindVertexArrayAPPLE");
461 return;
462 }
463
464 save_array_object(ctx, newObj);
465 }
466
467 if (!newObj->EverBound) {
468 /* The "Interactions with APPLE_vertex_array_object" section of the
469 * GL_ARB_vertex_array_object spec says:
470 *
471 * "The first bind call, either BindVertexArray or
472 * BindVertexArrayAPPLE, determines the semantic of the object."
473 */
474 newObj->ARBsemantics = genRequired;
475 newObj->EverBound = GL_TRUE;
476 }
477 }
478
479 if (ctx->Array.DrawMethod == DRAW_ARRAYS) {
480 /* The _DrawArrays pointer is pointing at the VAO being unbound and
481 * that VAO may be in the process of being deleted. If it's not going
482 * to be deleted, this will have no effect, because the pointer needs
483 * to be updated by the VBO module anyway.
484 *
485 * Before the VBO module can update the pointer, we have to set it
486 * to NULL for drivers not to set up arrays which are not bound,
487 * or to prevent a crash if the VAO being unbound is going to be
488 * deleted.
489 */
490 ctx->Array._DrawArrays = NULL;
491 ctx->Array.DrawMethod = DRAW_NONE;
492 }
493
494 ctx->NewState |= _NEW_ARRAY;
495 _mesa_reference_vao(ctx, &ctx->Array.VAO, newObj);
496 }
497
498
499 /**
500 * ARB version of glBindVertexArray()
501 * This function behaves differently from glBindVertexArrayAPPLE() in
502 * that this function requires all ids to have been previously generated
503 * by glGenVertexArrays[APPLE]().
504 */
505 void GLAPIENTRY
506 _mesa_BindVertexArray( GLuint id )
507 {
508 GET_CURRENT_CONTEXT(ctx);
509 bind_vertex_array(ctx, id, GL_TRUE);
510 }
511
512
513 /**
514 * Bind a new array.
515 *
516 * \todo
517 * The binding could be done more efficiently by comparing the non-NULL
518 * pointers in the old and new objects. The only arrays that are "dirty" are
519 * the ones that are non-NULL in either object.
520 */
521 void GLAPIENTRY
522 _mesa_BindVertexArrayAPPLE( GLuint id )
523 {
524 GET_CURRENT_CONTEXT(ctx);
525 bind_vertex_array(ctx, id, GL_FALSE);
526 }
527
528
529 /**
530 * Delete a set of array objects.
531 *
532 * \param n Number of array objects to delete.
533 * \param ids Array of \c n array object IDs.
534 */
535 void GLAPIENTRY
536 _mesa_DeleteVertexArrays(GLsizei n, const GLuint *ids)
537 {
538 GET_CURRENT_CONTEXT(ctx);
539 GLsizei i;
540
541 if (n < 0) {
542 _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteVertexArray(n)");
543 return;
544 }
545
546 for (i = 0; i < n; i++) {
547 struct gl_vertex_array_object *obj = _mesa_lookup_vao(ctx, ids[i]);
548
549 if ( obj != NULL ) {
550 assert( obj->Name == ids[i] );
551
552 /* If the array object is currently bound, the spec says "the binding
553 * for that object reverts to zero and the default vertex array
554 * becomes current."
555 */
556 if ( obj == ctx->Array.VAO ) {
557 _mesa_BindVertexArray(0);
558 }
559
560 /* The ID is immediately freed for re-use */
561 remove_array_object(ctx, obj);
562
563 if (ctx->Array.LastLookedUpVAO == obj)
564 _mesa_reference_vao(ctx, &ctx->Array.LastLookedUpVAO, NULL);
565
566 /* Unreference the array object.
567 * If refcount hits zero, the object will be deleted.
568 */
569 _mesa_reference_vao(ctx, &obj, NULL);
570 }
571 }
572 }
573
574
575 /**
576 * Generate a set of unique array object IDs and store them in \c arrays.
577 * Helper for _mesa_GenVertexArrays[APPLE]() and _mesa_CreateVertexArrays()
578 * below.
579 *
580 * \param n Number of IDs to generate.
581 * \param arrays Array of \c n locations to store the IDs.
582 * \param create Indicates that the objects should also be created.
583 * \param func The name of the GL entry point.
584 */
585 static void
586 gen_vertex_arrays(struct gl_context *ctx, GLsizei n, GLuint *arrays,
587 bool create, const char *func)
588 {
589 GLuint first;
590 GLint i;
591
592 if (n < 0) {
593 _mesa_error(ctx, GL_INVALID_VALUE, "%s(n < 0)", func);
594 return;
595 }
596
597 if (!arrays) {
598 return;
599 }
600
601 first = _mesa_HashFindFreeKeyBlock(ctx->Array.Objects, n);
602
603 /* For the sake of simplicity we create the array objects in both
604 * the Gen* and Create* cases. The only difference is the value of
605 * EverBound, which is set to true in the Create* case.
606 */
607 for (i = 0; i < n; i++) {
608 struct gl_vertex_array_object *obj;
609 GLuint name = first + i;
610
611 obj = _mesa_new_vao(ctx, name);
612 if (!obj) {
613 _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
614 return;
615 }
616 obj->EverBound = create;
617 save_array_object(ctx, obj);
618 arrays[i] = first + i;
619 }
620 }
621
622
623 /**
624 * ARB version of glGenVertexArrays()
625 * All arrays will be required to live in VBOs.
626 */
627 void GLAPIENTRY
628 _mesa_GenVertexArrays(GLsizei n, GLuint *arrays)
629 {
630 GET_CURRENT_CONTEXT(ctx);
631 gen_vertex_arrays(ctx, n, arrays, false, "glGenVertexArrays");
632 }
633
634
635 /**
636 * APPLE version of glGenVertexArraysAPPLE()
637 * Arrays may live in VBOs or ordinary memory.
638 */
639 void GLAPIENTRY
640 _mesa_GenVertexArraysAPPLE(GLsizei n, GLuint *arrays)
641 {
642 GET_CURRENT_CONTEXT(ctx);
643 gen_vertex_arrays(ctx, n, arrays, false, "glGenVertexArraysAPPLE");
644 }
645
646
647 /**
648 * ARB_direct_state_access
649 * Generates ID's and creates the array objects.
650 */
651 void GLAPIENTRY
652 _mesa_CreateVertexArrays(GLsizei n, GLuint *arrays)
653 {
654 GET_CURRENT_CONTEXT(ctx);
655 gen_vertex_arrays(ctx, n, arrays, true, "glCreateVertexArrays");
656 }
657
658
659 /**
660 * Determine if ID is the name of an array object.
661 *
662 * \param id ID of the potential array object.
663 * \return \c GL_TRUE if \c id is the name of a array object,
664 * \c GL_FALSE otherwise.
665 */
666 GLboolean GLAPIENTRY
667 _mesa_IsVertexArray( GLuint id )
668 {
669 struct gl_vertex_array_object * obj;
670 GET_CURRENT_CONTEXT(ctx);
671 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
672
673 if (id == 0)
674 return GL_FALSE;
675
676 obj = _mesa_lookup_vao(ctx, id);
677 if (obj == NULL)
678 return GL_FALSE;
679
680 return obj->EverBound;
681 }
682
683
684 /**
685 * Sets the element array buffer binding of a vertex array object.
686 *
687 * This is the ARB_direct_state_access equivalent of
688 * glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer).
689 */
690 void GLAPIENTRY
691 _mesa_VertexArrayElementBuffer(GLuint vaobj, GLuint buffer)
692 {
693 GET_CURRENT_CONTEXT(ctx);
694 struct gl_vertex_array_object *vao;
695 struct gl_buffer_object *bufObj;
696
697 ASSERT_OUTSIDE_BEGIN_END(ctx);
698
699 /* The GL_ARB_direct_state_access specification says:
700 *
701 * "An INVALID_OPERATION error is generated by VertexArrayElementBuffer
702 * if <vaobj> is not [compatibility profile: zero or] the name of an
703 * existing vertex array object."
704 */
705 vao =_mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayElementBuffer");
706 if (!vao)
707 return;
708
709 /* The GL_ARB_direct_state_access specification says:
710 *
711 * "An INVALID_OPERATION error is generated if <buffer> is not zero or
712 * the name of an existing buffer object."
713 */
714 if (buffer != 0)
715 bufObj = _mesa_lookup_bufferobj_err(ctx, buffer,
716 "glVertexArrayElementBuffer");
717 else
718 bufObj = ctx->Shared->NullBufferObj;
719
720 if (bufObj)
721 _mesa_reference_buffer_object(ctx, &vao->IndexBufferObj, bufObj);
722 }
723
724
725 void GLAPIENTRY
726 _mesa_GetVertexArrayiv(GLuint vaobj, GLenum pname, GLint *param)
727 {
728 GET_CURRENT_CONTEXT(ctx);
729 struct gl_vertex_array_object *vao;
730
731 ASSERT_OUTSIDE_BEGIN_END(ctx);
732
733 /* The GL_ARB_direct_state_access specification says:
734 *
735 * "An INVALID_OPERATION error is generated if <vaobj> is not
736 * [compatibility profile: zero or] the name of an existing
737 * vertex array object."
738 */
739 vao =_mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayiv");
740 if (!vao)
741 return;
742
743 /* The GL_ARB_direct_state_access specification says:
744 *
745 * "An INVALID_ENUM error is generated if <pname> is not
746 * ELEMENT_ARRAY_BUFFER_BINDING."
747 */
748 if (pname != GL_ELEMENT_ARRAY_BUFFER_BINDING) {
749 _mesa_error(ctx, GL_INVALID_ENUM,
750 "glGetVertexArrayiv(pname != "
751 "GL_ELEMENT_ARRAY_BUFFER_BINDING)");
752 return;
753 }
754
755 param[0] = vao->IndexBufferObj->Name;
756 }