mesa: Implement _mesa_all_varyings_in_vbos.
[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->VertexBinding); i++)
144 _mesa_reference_buffer_object(ctx, &obj->VertexBinding[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 mtx_destroy(&obj->Mutex);
173 free(obj->Label);
174 free(obj);
175 }
176
177
178 /**
179 * Set ptr to vao w/ reference counting.
180 * Note: this should only be called from the _mesa_reference_vao()
181 * inline function.
182 */
183 void
184 _mesa_reference_vao_(struct gl_context *ctx,
185 struct gl_vertex_array_object **ptr,
186 struct gl_vertex_array_object *vao)
187 {
188 assert(*ptr != vao);
189
190 if (*ptr) {
191 /* Unreference the old array object */
192 GLboolean deleteFlag = GL_FALSE;
193 struct gl_vertex_array_object *oldObj = *ptr;
194
195 mtx_lock(&oldObj->Mutex);
196 assert(oldObj->RefCount > 0);
197 oldObj->RefCount--;
198 deleteFlag = (oldObj->RefCount == 0);
199 mtx_unlock(&oldObj->Mutex);
200
201 if (deleteFlag)
202 _mesa_delete_vao(ctx, oldObj);
203
204 *ptr = NULL;
205 }
206 assert(!*ptr);
207
208 if (vao) {
209 /* reference new array object */
210 mtx_lock(&vao->Mutex);
211 if (vao->RefCount == 0) {
212 /* this array's being deleted (look just above) */
213 /* Not sure this can every really happen. Warn if it does. */
214 _mesa_problem(NULL, "referencing deleted array object");
215 *ptr = NULL;
216 }
217 else {
218 vao->RefCount++;
219 *ptr = vao;
220 }
221 mtx_unlock(&vao->Mutex);
222 }
223 }
224
225
226
227 static void
228 init_array(struct gl_context *ctx,
229 struct gl_vertex_array_object *obj, GLuint index, GLint size, GLint type)
230 {
231 struct gl_vertex_attrib_array *array = &obj->VertexAttrib[index];
232 struct gl_vertex_buffer_binding *binding = &obj->VertexBinding[index];
233
234 array->Size = size;
235 array->Type = type;
236 array->Format = GL_RGBA; /* only significant for GL_EXT_vertex_array_bgra */
237 array->Stride = 0;
238 array->Ptr = NULL;
239 array->RelativeOffset = 0;
240 array->Enabled = GL_FALSE;
241 array->Normalized = GL_FALSE;
242 array->Integer = GL_FALSE;
243 array->Doubles = GL_FALSE;
244 array->_ElementSize = size * _mesa_sizeof_type(type);
245 array->VertexBinding = index;
246
247 binding->Offset = 0;
248 binding->Stride = array->_ElementSize;
249 binding->BufferObj = NULL;
250 binding->_BoundArrays = BITFIELD64_BIT(index);
251
252 /* Vertex array buffers */
253 _mesa_reference_buffer_object(ctx, &binding->BufferObj,
254 ctx->Shared->NullBufferObj);
255 }
256
257
258 /**
259 * Initialize a gl_vertex_array_object's arrays.
260 */
261 void
262 _mesa_initialize_vao(struct gl_context *ctx,
263 struct gl_vertex_array_object *obj,
264 GLuint name)
265 {
266 GLuint i;
267
268 obj->Name = name;
269
270 mtx_init(&obj->Mutex, mtx_plain);
271 obj->RefCount = 1;
272
273 /* Init the individual arrays */
274 for (i = 0; i < ARRAY_SIZE(obj->VertexAttrib); i++) {
275 switch (i) {
276 case VERT_ATTRIB_WEIGHT:
277 init_array(ctx, obj, VERT_ATTRIB_WEIGHT, 1, GL_FLOAT);
278 break;
279 case VERT_ATTRIB_NORMAL:
280 init_array(ctx, obj, VERT_ATTRIB_NORMAL, 3, GL_FLOAT);
281 break;
282 case VERT_ATTRIB_COLOR1:
283 init_array(ctx, obj, VERT_ATTRIB_COLOR1, 3, GL_FLOAT);
284 break;
285 case VERT_ATTRIB_FOG:
286 init_array(ctx, obj, VERT_ATTRIB_FOG, 1, GL_FLOAT);
287 break;
288 case VERT_ATTRIB_COLOR_INDEX:
289 init_array(ctx, obj, VERT_ATTRIB_COLOR_INDEX, 1, GL_FLOAT);
290 break;
291 case VERT_ATTRIB_EDGEFLAG:
292 init_array(ctx, obj, VERT_ATTRIB_EDGEFLAG, 1, GL_BOOL);
293 break;
294 case VERT_ATTRIB_POINT_SIZE:
295 init_array(ctx, obj, VERT_ATTRIB_POINT_SIZE, 1, GL_FLOAT);
296 break;
297 default:
298 init_array(ctx, obj, i, 4, GL_FLOAT);
299 break;
300 }
301 }
302
303 _mesa_reference_buffer_object(ctx, &obj->IndexBufferObj,
304 ctx->Shared->NullBufferObj);
305 }
306
307
308 /**
309 * Add the given array object to the array object pool.
310 */
311 static void
312 save_array_object( struct gl_context *ctx, struct gl_vertex_array_object *obj )
313 {
314 if (obj->Name > 0) {
315 /* insert into hash table */
316 _mesa_HashInsert(ctx->Array.Objects, obj->Name, obj);
317 }
318 }
319
320
321 /**
322 * Remove the given array object from the array object pool.
323 * Do not deallocate the array object though.
324 */
325 static void
326 remove_array_object( struct gl_context *ctx, struct gl_vertex_array_object *obj )
327 {
328 if (obj->Name > 0) {
329 /* remove from hash table */
330 _mesa_HashRemove(ctx->Array.Objects, obj->Name);
331 }
332 }
333
334
335 /**
336 * Updates the derived gl_client_arrays when a gl_vertex_attrib_array
337 * or a gl_vertex_buffer_binding has changed.
338 */
339 void
340 _mesa_update_vao_client_arrays(struct gl_context *ctx,
341 struct gl_vertex_array_object *vao)
342 {
343 GLbitfield64 arrays = vao->NewArrays;
344
345 while (arrays) {
346 const int attrib = u_bit_scan64(&arrays);
347
348 struct gl_client_array *client_array;
349 struct gl_vertex_attrib_array *attrib_array;
350 struct gl_vertex_buffer_binding *buffer_binding;
351
352 attrib_array = &vao->VertexAttrib[attrib];
353 buffer_binding = &vao->VertexBinding[attrib_array->VertexBinding];
354 client_array = &vao->_VertexAttrib[attrib];
355
356 _mesa_update_client_array(ctx, client_array, attrib_array,
357 buffer_binding);
358 }
359 }
360
361
362 bool
363 _mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao)
364 {
365 /* Walk those enabled arrays that have the default vbo attached */
366 GLbitfield64 mask = vao->_Enabled & ~vao->VertexAttribBufferMask;
367
368 while (mask) {
369 /* Do not use u_bit_scan64 as we can walk multiple
370 * attrib arrays at once
371 */
372 const int i = ffsll(mask) - 1;
373 const struct gl_vertex_attrib_array *attrib_array =
374 &vao->VertexAttrib[i];
375 const struct gl_vertex_buffer_binding *buffer_binding =
376 &vao->VertexBinding[attrib_array->VertexBinding];
377
378 /* Only enabled arrays shall appear in the _Enabled bitmask */
379 assert(attrib_array->Enabled);
380 /* We have already masked out vao->VertexAttribBufferMask */
381 assert(!_mesa_is_bufferobj(buffer_binding->BufferObj));
382
383 /* Bail out once we find the first non vbo with a non zero stride */
384 if (buffer_binding->Stride != 0)
385 return false;
386
387 /* Note that we cannot use the xor variant since the _BoundArray mask
388 * may contain array attributes that are bound but not enabled.
389 */
390 mask &= ~buffer_binding->_BoundArrays;
391 }
392
393 return true;
394 }
395
396
397 /**********************************************************************/
398 /* API Functions */
399 /**********************************************************************/
400
401
402 /**
403 * Helper for _mesa_BindVertexArray() and _mesa_BindVertexArrayAPPLE().
404 * \param genRequired specifies behavour when id was not generated with
405 * glGenVertexArrays().
406 */
407 static void
408 bind_vertex_array(struct gl_context *ctx, GLuint id, GLboolean genRequired)
409 {
410 struct gl_vertex_array_object * const oldObj = ctx->Array.VAO;
411 struct gl_vertex_array_object *newObj = NULL;
412
413 assert(oldObj != NULL);
414
415 if ( oldObj->Name == id )
416 return; /* rebinding the same array object- no change */
417
418 /*
419 * Get pointer to new array object (newObj)
420 */
421 if (id == 0) {
422 /* The spec says there is no array object named 0, but we use
423 * one internally because it simplifies things.
424 */
425 newObj = ctx->Array.DefaultVAO;
426 }
427 else {
428 /* non-default array object */
429 newObj = _mesa_lookup_vao(ctx, id);
430 if (!newObj) {
431 if (genRequired) {
432 _mesa_error(ctx, GL_INVALID_OPERATION,
433 "glBindVertexArray(non-gen name)");
434 return;
435 }
436
437 /* For APPLE version, generate a new array object now */
438 newObj = _mesa_new_vao(ctx, id);
439 if (!newObj) {
440 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindVertexArrayAPPLE");
441 return;
442 }
443
444 save_array_object(ctx, newObj);
445 }
446
447 if (!newObj->EverBound) {
448 /* The "Interactions with APPLE_vertex_array_object" section of the
449 * GL_ARB_vertex_array_object spec says:
450 *
451 * "The first bind call, either BindVertexArray or
452 * BindVertexArrayAPPLE, determines the semantic of the object."
453 */
454 newObj->ARBsemantics = genRequired;
455 newObj->EverBound = GL_TRUE;
456 }
457 }
458
459 if (ctx->Array.DrawMethod == DRAW_ARRAYS) {
460 /* The _DrawArrays pointer is pointing at the VAO being unbound and
461 * that VAO may be in the process of being deleted. If it's not going
462 * to be deleted, this will have no effect, because the pointer needs
463 * to be updated by the VBO module anyway.
464 *
465 * Before the VBO module can update the pointer, we have to set it
466 * to NULL for drivers not to set up arrays which are not bound,
467 * or to prevent a crash if the VAO being unbound is going to be
468 * deleted.
469 */
470 ctx->Array._DrawArrays = NULL;
471 ctx->Array.DrawMethod = DRAW_NONE;
472 }
473
474 ctx->NewState |= _NEW_ARRAY;
475 _mesa_reference_vao(ctx, &ctx->Array.VAO, newObj);
476 }
477
478
479 /**
480 * ARB version of glBindVertexArray()
481 * This function behaves differently from glBindVertexArrayAPPLE() in
482 * that this function requires all ids to have been previously generated
483 * by glGenVertexArrays[APPLE]().
484 */
485 void GLAPIENTRY
486 _mesa_BindVertexArray( GLuint id )
487 {
488 GET_CURRENT_CONTEXT(ctx);
489 bind_vertex_array(ctx, id, GL_TRUE);
490 }
491
492
493 /**
494 * Bind a new array.
495 *
496 * \todo
497 * The binding could be done more efficiently by comparing the non-NULL
498 * pointers in the old and new objects. The only arrays that are "dirty" are
499 * the ones that are non-NULL in either object.
500 */
501 void GLAPIENTRY
502 _mesa_BindVertexArrayAPPLE( GLuint id )
503 {
504 GET_CURRENT_CONTEXT(ctx);
505 bind_vertex_array(ctx, id, GL_FALSE);
506 }
507
508
509 /**
510 * Delete a set of array objects.
511 *
512 * \param n Number of array objects to delete.
513 * \param ids Array of \c n array object IDs.
514 */
515 void GLAPIENTRY
516 _mesa_DeleteVertexArrays(GLsizei n, const GLuint *ids)
517 {
518 GET_CURRENT_CONTEXT(ctx);
519 GLsizei i;
520
521 if (n < 0) {
522 _mesa_error(ctx, GL_INVALID_VALUE, "glDeleteVertexArray(n)");
523 return;
524 }
525
526 for (i = 0; i < n; i++) {
527 struct gl_vertex_array_object *obj = _mesa_lookup_vao(ctx, ids[i]);
528
529 if ( obj != NULL ) {
530 assert( obj->Name == ids[i] );
531
532 /* If the array object is currently bound, the spec says "the binding
533 * for that object reverts to zero and the default vertex array
534 * becomes current."
535 */
536 if ( obj == ctx->Array.VAO ) {
537 _mesa_BindVertexArray(0);
538 }
539
540 /* The ID is immediately freed for re-use */
541 remove_array_object(ctx, obj);
542
543 if (ctx->Array.LastLookedUpVAO == obj)
544 _mesa_reference_vao(ctx, &ctx->Array.LastLookedUpVAO, NULL);
545
546 /* Unreference the array object.
547 * If refcount hits zero, the object will be deleted.
548 */
549 _mesa_reference_vao(ctx, &obj, NULL);
550 }
551 }
552 }
553
554
555 /**
556 * Generate a set of unique array object IDs and store them in \c arrays.
557 * Helper for _mesa_GenVertexArrays[APPLE]() and _mesa_CreateVertexArrays()
558 * below.
559 *
560 * \param n Number of IDs to generate.
561 * \param arrays Array of \c n locations to store the IDs.
562 * \param create Indicates that the objects should also be created.
563 * \param func The name of the GL entry point.
564 */
565 static void
566 gen_vertex_arrays(struct gl_context *ctx, GLsizei n, GLuint *arrays,
567 bool create, const char *func)
568 {
569 GLuint first;
570 GLint i;
571
572 if (n < 0) {
573 _mesa_error(ctx, GL_INVALID_VALUE, "%s(n < 0)", func);
574 return;
575 }
576
577 if (!arrays) {
578 return;
579 }
580
581 first = _mesa_HashFindFreeKeyBlock(ctx->Array.Objects, n);
582
583 /* For the sake of simplicity we create the array objects in both
584 * the Gen* and Create* cases. The only difference is the value of
585 * EverBound, which is set to true in the Create* case.
586 */
587 for (i = 0; i < n; i++) {
588 struct gl_vertex_array_object *obj;
589 GLuint name = first + i;
590
591 obj = _mesa_new_vao(ctx, name);
592 if (!obj) {
593 _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
594 return;
595 }
596 obj->EverBound = create;
597 save_array_object(ctx, obj);
598 arrays[i] = first + i;
599 }
600 }
601
602
603 /**
604 * ARB version of glGenVertexArrays()
605 * All arrays will be required to live in VBOs.
606 */
607 void GLAPIENTRY
608 _mesa_GenVertexArrays(GLsizei n, GLuint *arrays)
609 {
610 GET_CURRENT_CONTEXT(ctx);
611 gen_vertex_arrays(ctx, n, arrays, false, "glGenVertexArrays");
612 }
613
614
615 /**
616 * APPLE version of glGenVertexArraysAPPLE()
617 * Arrays may live in VBOs or ordinary memory.
618 */
619 void GLAPIENTRY
620 _mesa_GenVertexArraysAPPLE(GLsizei n, GLuint *arrays)
621 {
622 GET_CURRENT_CONTEXT(ctx);
623 gen_vertex_arrays(ctx, n, arrays, false, "glGenVertexArraysAPPLE");
624 }
625
626
627 /**
628 * ARB_direct_state_access
629 * Generates ID's and creates the array objects.
630 */
631 void GLAPIENTRY
632 _mesa_CreateVertexArrays(GLsizei n, GLuint *arrays)
633 {
634 GET_CURRENT_CONTEXT(ctx);
635 gen_vertex_arrays(ctx, n, arrays, true, "glCreateVertexArrays");
636 }
637
638
639 /**
640 * Determine if ID is the name of an array object.
641 *
642 * \param id ID of the potential array object.
643 * \return \c GL_TRUE if \c id is the name of a array object,
644 * \c GL_FALSE otherwise.
645 */
646 GLboolean GLAPIENTRY
647 _mesa_IsVertexArray( GLuint id )
648 {
649 struct gl_vertex_array_object * obj;
650 GET_CURRENT_CONTEXT(ctx);
651 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
652
653 if (id == 0)
654 return GL_FALSE;
655
656 obj = _mesa_lookup_vao(ctx, id);
657 if (obj == NULL)
658 return GL_FALSE;
659
660 return obj->EverBound;
661 }
662
663
664 /**
665 * Sets the element array buffer binding of a vertex array object.
666 *
667 * This is the ARB_direct_state_access equivalent of
668 * glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer).
669 */
670 void GLAPIENTRY
671 _mesa_VertexArrayElementBuffer(GLuint vaobj, GLuint buffer)
672 {
673 GET_CURRENT_CONTEXT(ctx);
674 struct gl_vertex_array_object *vao;
675 struct gl_buffer_object *bufObj;
676
677 ASSERT_OUTSIDE_BEGIN_END(ctx);
678
679 /* The GL_ARB_direct_state_access specification says:
680 *
681 * "An INVALID_OPERATION error is generated by VertexArrayElementBuffer
682 * if <vaobj> is not [compatibility profile: zero or] the name of an
683 * existing vertex array object."
684 */
685 vao =_mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayElementBuffer");
686 if (!vao)
687 return;
688
689 /* The GL_ARB_direct_state_access specification says:
690 *
691 * "An INVALID_OPERATION error is generated if <buffer> is not zero or
692 * the name of an existing buffer object."
693 */
694 if (buffer != 0)
695 bufObj = _mesa_lookup_bufferobj_err(ctx, buffer,
696 "glVertexArrayElementBuffer");
697 else
698 bufObj = ctx->Shared->NullBufferObj;
699
700 if (bufObj)
701 _mesa_reference_buffer_object(ctx, &vao->IndexBufferObj, bufObj);
702 }
703
704
705 void GLAPIENTRY
706 _mesa_GetVertexArrayiv(GLuint vaobj, GLenum pname, GLint *param)
707 {
708 GET_CURRENT_CONTEXT(ctx);
709 struct gl_vertex_array_object *vao;
710
711 ASSERT_OUTSIDE_BEGIN_END(ctx);
712
713 /* The GL_ARB_direct_state_access specification says:
714 *
715 * "An INVALID_OPERATION error is generated if <vaobj> is not
716 * [compatibility profile: zero or] the name of an existing
717 * vertex array object."
718 */
719 vao =_mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayiv");
720 if (!vao)
721 return;
722
723 /* The GL_ARB_direct_state_access specification says:
724 *
725 * "An INVALID_ENUM error is generated if <pname> is not
726 * ELEMENT_ARRAY_BUFFER_BINDING."
727 */
728 if (pname != GL_ELEMENT_ARRAY_BUFFER_BINDING) {
729 _mesa_error(ctx, GL_INVALID_ENUM,
730 "glGetVertexArrayiv(pname != "
731 "GL_ELEMENT_ARRAY_BUFFER_BINDING)");
732 return;
733 }
734
735 param[0] = vao->IndexBufferObj->Name;
736 }