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