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