mesa: Remove target parameter from _mesa_handle_bind_buffer_gen
[mesa.git] / src / mesa / main / varray.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 #include <stdio.h>
28 #include <inttypes.h> /* for PRId64 macro */
29
30 #include "glheader.h"
31 #include "imports.h"
32 #include "bufferobj.h"
33 #include "context.h"
34 #include "enable.h"
35 #include "enums.h"
36 #include "hash.h"
37 #include "image.h"
38 #include "macros.h"
39 #include "mtypes.h"
40 #include "varray.h"
41 #include "arrayobj.h"
42 #include "main/dispatch.h"
43
44
45 /** Used to do error checking for GL_EXT_vertex_array_bgra */
46 #define BGRA_OR_4 5
47
48
49 /** Used to indicate which GL datatypes are accepted by each of the
50 * glVertex/Color/Attrib/EtcPointer() functions.
51 */
52 #define BOOL_BIT (1 << 0)
53 #define BYTE_BIT (1 << 1)
54 #define UNSIGNED_BYTE_BIT (1 << 2)
55 #define SHORT_BIT (1 << 3)
56 #define UNSIGNED_SHORT_BIT (1 << 4)
57 #define INT_BIT (1 << 5)
58 #define UNSIGNED_INT_BIT (1 << 6)
59 #define HALF_BIT (1 << 7)
60 #define FLOAT_BIT (1 << 8)
61 #define DOUBLE_BIT (1 << 9)
62 #define FIXED_ES_BIT (1 << 10)
63 #define FIXED_GL_BIT (1 << 11)
64 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
65 #define INT_2_10_10_10_REV_BIT (1 << 13)
66 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
67 #define ALL_TYPE_BITS ((1 << 15) - 1)
68
69 #define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
70 SHORT_BIT | UNSIGNED_SHORT_BIT | \
71 INT_BIT | UNSIGNED_INT_BIT | \
72 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
73 FIXED_GL_BIT | \
74 UNSIGNED_INT_2_10_10_10_REV_BIT | \
75 INT_2_10_10_10_REV_BIT | \
76 UNSIGNED_INT_10F_11F_11F_REV_BIT)
77
78 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
79 SHORT_BIT | UNSIGNED_SHORT_BIT | \
80 INT_BIT | UNSIGNED_INT_BIT)
81
82 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
83
84
85 /** Convert GL datatype enum into a <type>_BIT value seen above */
86 static GLbitfield
87 type_to_bit(const struct gl_context *ctx, GLenum type)
88 {
89 switch (type) {
90 case GL_BOOL:
91 return BOOL_BIT;
92 case GL_BYTE:
93 return BYTE_BIT;
94 case GL_UNSIGNED_BYTE:
95 return UNSIGNED_BYTE_BIT;
96 case GL_SHORT:
97 return SHORT_BIT;
98 case GL_UNSIGNED_SHORT:
99 return UNSIGNED_SHORT_BIT;
100 case GL_INT:
101 return INT_BIT;
102 case GL_UNSIGNED_INT:
103 return UNSIGNED_INT_BIT;
104 case GL_HALF_FLOAT:
105 if (ctx->Extensions.ARB_half_float_vertex)
106 return HALF_BIT;
107 else
108 return 0x0;
109 case GL_FLOAT:
110 return FLOAT_BIT;
111 case GL_DOUBLE:
112 return DOUBLE_BIT;
113 case GL_FIXED:
114 return _mesa_is_desktop_gl(ctx) ? FIXED_GL_BIT : FIXED_ES_BIT;
115 case GL_UNSIGNED_INT_2_10_10_10_REV:
116 return UNSIGNED_INT_2_10_10_10_REV_BIT;
117 case GL_INT_2_10_10_10_REV:
118 return INT_2_10_10_10_REV_BIT;
119 case GL_UNSIGNED_INT_10F_11F_11F_REV:
120 return UNSIGNED_INT_10F_11F_11F_REV_BIT;
121 default:
122 return 0;
123 }
124 }
125
126
127 /**
128 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
129 */
130 static void
131 vertex_attrib_binding(struct gl_context *ctx,
132 struct gl_vertex_array_object *vao,
133 GLuint attribIndex,
134 GLuint bindingIndex)
135 {
136 struct gl_vertex_attrib_array *array = &vao->VertexAttrib[attribIndex];
137
138 if (array->VertexBinding != bindingIndex) {
139 const GLbitfield64 array_bit = VERT_BIT(attribIndex);
140
141 FLUSH_VERTICES(ctx, _NEW_ARRAY);
142
143 vao->VertexBinding[array->VertexBinding]._BoundArrays &= ~array_bit;
144 vao->VertexBinding[bindingIndex]._BoundArrays |= array_bit;
145
146 array->VertexBinding = bindingIndex;
147
148 vao->NewArrays |= array_bit;
149 }
150 }
151
152
153 /**
154 * Binds a buffer object to the vertex buffer binding point given by index,
155 * and sets the Offset and Stride fields.
156 */
157 static void
158 bind_vertex_buffer(struct gl_context *ctx,
159 struct gl_vertex_array_object *vao,
160 GLuint index,
161 struct gl_buffer_object *vbo,
162 GLintptr offset, GLsizei stride)
163 {
164 struct gl_vertex_buffer_binding *binding = &vao->VertexBinding[index];
165
166 if (binding->BufferObj != vbo ||
167 binding->Offset != offset ||
168 binding->Stride != stride) {
169
170 FLUSH_VERTICES(ctx, _NEW_ARRAY);
171
172 _mesa_reference_buffer_object(ctx, &binding->BufferObj, vbo);
173
174 binding->Offset = offset;
175 binding->Stride = stride;
176
177 vao->NewArrays |= binding->_BoundArrays;
178 }
179 }
180
181
182 /**
183 * Sets the InstanceDivisor field in the vertex buffer binding point
184 * given by bindingIndex.
185 */
186 static void
187 vertex_binding_divisor(struct gl_context *ctx,
188 struct gl_vertex_array_object *vao,
189 GLuint bindingIndex,
190 GLuint divisor)
191 {
192 struct gl_vertex_buffer_binding *binding =
193 &vao->VertexBinding[bindingIndex];
194
195 if (binding->InstanceDivisor != divisor) {
196 FLUSH_VERTICES(ctx, _NEW_ARRAY);
197 binding->InstanceDivisor = divisor;
198 vao->NewArrays |= binding->_BoundArrays;
199 }
200 }
201
202
203 /**
204 * Examine the API profile and extensions to determine which types are legal
205 * for vertex arrays. This is called once from update_array_format().
206 */
207 static GLbitfield
208 get_legal_types_mask(const struct gl_context *ctx)
209 {
210 GLbitfield legalTypesMask = ALL_TYPE_BITS;
211
212 if (_mesa_is_gles(ctx)) {
213 legalTypesMask &= ~(FIXED_GL_BIT |
214 DOUBLE_BIT |
215 UNSIGNED_INT_10F_11F_11F_REV_BIT);
216
217 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
218 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
219 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
220 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
221 * quite as trivial as we'd like because it uses a different enum value
222 * for GL_HALF_FLOAT_OES.
223 */
224 if (ctx->Version < 30) {
225 legalTypesMask &= ~(UNSIGNED_INT_BIT |
226 INT_BIT |
227 UNSIGNED_INT_2_10_10_10_REV_BIT |
228 INT_2_10_10_10_REV_BIT |
229 HALF_BIT);
230 }
231 }
232 else {
233 legalTypesMask &= ~FIXED_ES_BIT;
234
235 if (!ctx->Extensions.ARB_ES2_compatibility)
236 legalTypesMask &= ~FIXED_GL_BIT;
237
238 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
239 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
240 INT_2_10_10_10_REV_BIT);
241
242 if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev)
243 legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT;
244 }
245
246 return legalTypesMask;
247 }
248
249
250 /**
251 * Does error checking and updates the format in an attrib array.
252 *
253 * Called by update_array() and VertexAttrib*Format().
254 *
255 * \param func Name of calling function used for error reporting
256 * \param attrib The index of the attribute array
257 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
258 * \param sizeMin Min allowable size value
259 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
260 * \param size Components per element (1, 2, 3 or 4)
261 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
262 * \param normalized Whether integer types are converted to floats in [-1, 1]
263 * \param integer Integer-valued values (will not be normalized to [-1, 1])
264 * \param doubles Double values not reduced to floats
265 * \param relativeOffset Offset of the first element relative to the binding offset.
266 */
267 static bool
268 update_array_format(struct gl_context *ctx,
269 const char *func,
270 struct gl_vertex_array_object *vao,
271 GLuint attrib, GLbitfield legalTypesMask,
272 GLint sizeMin, GLint sizeMax,
273 GLint size, GLenum type,
274 GLboolean normalized, GLboolean integer, GLboolean doubles,
275 GLuint relativeOffset)
276 {
277 struct gl_vertex_attrib_array *array;
278 GLbitfield typeBit;
279 GLint elementSize;
280 GLenum format = GL_RGBA;
281
282 if (ctx->Array.LegalTypesMask == 0 || ctx->Array.LegalTypesMaskAPI != ctx->API) {
283 /* Compute the LegalTypesMask only once, unless the context API has
284 * changed, in which case we want to compute it again. We can't do this
285 * in _mesa_init_varrays() below because extensions are not yet enabled
286 * at that point.
287 */
288 ctx->Array.LegalTypesMask = get_legal_types_mask(ctx);
289 ctx->Array.LegalTypesMaskAPI = ctx->API;
290 }
291
292 legalTypesMask &= ctx->Array.LegalTypesMask;
293
294 if (_mesa_is_gles(ctx) && sizeMax == BGRA_OR_4) {
295 /* BGRA ordering is not supported in ES contexts.
296 */
297 sizeMax = 4;
298 }
299
300 typeBit = type_to_bit(ctx, type);
301 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
302 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
303 func, _mesa_enum_to_string(type));
304 return false;
305 }
306
307 /* Do size parameter checking.
308 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
309 * must be handled specially.
310 */
311 if (ctx->Extensions.EXT_vertex_array_bgra &&
312 sizeMax == BGRA_OR_4 &&
313 size == GL_BGRA) {
314 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
315 *
316 * "An INVALID_OPERATION error is generated under any of the following
317 * conditions:
318 * ...
319 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
320 * or UNSIGNED_INT_2_10_10_10_REV;
321 * ...
322 * • size is BGRA and normalized is FALSE;"
323 */
324 bool bgra_error = false;
325
326 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
327 if (type != GL_UNSIGNED_INT_2_10_10_10_REV &&
328 type != GL_INT_2_10_10_10_REV &&
329 type != GL_UNSIGNED_BYTE)
330 bgra_error = true;
331 } else if (type != GL_UNSIGNED_BYTE)
332 bgra_error = true;
333
334 if (bgra_error) {
335 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)",
336 func, _mesa_enum_to_string(type));
337 return false;
338 }
339
340 if (!normalized) {
341 _mesa_error(ctx, GL_INVALID_OPERATION,
342 "%s(size=GL_BGRA and normalized=GL_FALSE)", func);
343 return false;
344 }
345
346 format = GL_BGRA;
347 size = 4;
348 }
349 else if (size < sizeMin || size > sizeMax || size > 4) {
350 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
351 return false;
352 }
353
354 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
355 (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
356 type == GL_INT_2_10_10_10_REV) && size != 4) {
357 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
358 return false;
359 }
360
361 /* The ARB_vertex_attrib_binding_spec says:
362 *
363 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
364 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
365 */
366 if (relativeOffset > ctx->Const.MaxVertexAttribRelativeOffset) {
367 _mesa_error(ctx, GL_INVALID_VALUE,
368 "%s(relativeOffset=%d > "
369 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
370 func, relativeOffset);
371 return false;
372 }
373
374 if (ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev &&
375 type == GL_UNSIGNED_INT_10F_11F_11F_REV && size != 3) {
376 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
377 return false;
378 }
379
380 assert(size <= 4);
381
382 elementSize = _mesa_bytes_per_vertex_attrib(size, type);
383 assert(elementSize != -1);
384
385 array = &vao->VertexAttrib[attrib];
386 array->Size = size;
387 array->Type = type;
388 array->Format = format;
389 array->Normalized = normalized;
390 array->Integer = integer;
391 array->Doubles = doubles;
392 array->RelativeOffset = relativeOffset;
393 array->_ElementSize = elementSize;
394
395 vao->NewArrays |= VERT_BIT(attrib);
396 ctx->NewState |= _NEW_ARRAY;
397
398 return true;
399 }
400
401
402 /**
403 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
404 * functions.
405 *
406 * \param func name of calling function used for error reporting
407 * \param attrib the attribute array index to update
408 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
409 * \param sizeMin min allowable size value
410 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
411 * \param size components per element (1, 2, 3 or 4)
412 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
413 * \param stride stride between elements, in elements
414 * \param normalized are integer types converted to floats in [-1, 1]?
415 * \param integer integer-valued values (will not be normalized to [-1,1])
416 * \param doubles Double values not reduced to floats
417 * \param ptr the address (or offset inside VBO) of the array data
418 */
419 static void
420 update_array(struct gl_context *ctx,
421 const char *func,
422 GLuint attrib, GLbitfield legalTypesMask,
423 GLint sizeMin, GLint sizeMax,
424 GLint size, GLenum type, GLsizei stride,
425 GLboolean normalized, GLboolean integer, GLboolean doubles,
426 const GLvoid *ptr)
427 {
428 struct gl_vertex_attrib_array *array;
429 GLsizei effectiveStride;
430
431 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
432 *
433 * "Client vertex arrays - all vertex array attribute pointers must
434 * refer to buffer objects (section 2.9.2). The default vertex array
435 * object (the name zero) is also deprecated. Calling
436 * VertexAttribPointer when no buffer object or no vertex array object
437 * is bound will generate an INVALID_OPERATION error..."
438 *
439 * The check for VBOs is handled below.
440 */
441 if (ctx->API == API_OPENGL_CORE
442 && (ctx->Array.VAO == ctx->Array.DefaultVAO)) {
443 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)",
444 func);
445 return;
446 }
447
448 if (stride < 0) {
449 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
450 return;
451 }
452
453 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
454 stride > ctx->Const.MaxVertexAttribStride) {
455 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
456 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
457 return;
458 }
459
460 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
461 *
462 * "An INVALID_OPERATION error is generated under any of the following
463 * conditions:
464 *
465 * ...
466 *
467 * * any of the *Pointer commands specifying the location and
468 * organization of vertex array data are called while zero is bound
469 * to the ARRAY_BUFFER buffer object binding point (see section
470 * 2.9.6), and the pointer argument is not NULL."
471 */
472 if (ptr != NULL && ctx->Array.VAO->ARBsemantics &&
473 !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) {
474 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
475 return;
476 }
477
478 if (!update_array_format(ctx, func, ctx->Array.VAO, attrib,
479 legalTypesMask, sizeMin, sizeMax,
480 size, type, normalized, integer, doubles, 0)) {
481 return;
482 }
483
484 /* Reset the vertex attrib binding */
485 vertex_attrib_binding(ctx, ctx->Array.VAO, attrib, attrib);
486
487 /* The Stride and Ptr fields are not set by update_array_format() */
488 array = &ctx->Array.VAO->VertexAttrib[attrib];
489 array->Stride = stride;
490 array->Ptr = (const GLvoid *) ptr;
491
492 /* Update the vertex buffer binding */
493 effectiveStride = stride != 0 ? stride : array->_ElementSize;
494 bind_vertex_buffer(ctx, ctx->Array.VAO, attrib, ctx->Array.ArrayBufferObj,
495 (GLintptr) ptr, effectiveStride);
496 }
497
498
499 void GLAPIENTRY
500 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
501 {
502 GET_CURRENT_CONTEXT(ctx);
503 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
504 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
505 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
506 DOUBLE_BIT | HALF_BIT |
507 UNSIGNED_INT_2_10_10_10_REV_BIT |
508 INT_2_10_10_10_REV_BIT);
509
510 FLUSH_VERTICES(ctx, 0);
511
512 update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS,
513 legalTypes, 2, 4,
514 size, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
515 }
516
517
518 void GLAPIENTRY
519 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
520 {
521 GET_CURRENT_CONTEXT(ctx);
522 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
523 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
524 : (BYTE_BIT | SHORT_BIT | INT_BIT |
525 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
526 UNSIGNED_INT_2_10_10_10_REV_BIT |
527 INT_2_10_10_10_REV_BIT);
528
529 FLUSH_VERTICES(ctx, 0);
530
531 update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL,
532 legalTypes, 3, 3,
533 3, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
534 }
535
536
537 void GLAPIENTRY
538 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
539 {
540 GET_CURRENT_CONTEXT(ctx);
541 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
542 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
543 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
544 SHORT_BIT | UNSIGNED_SHORT_BIT |
545 INT_BIT | UNSIGNED_INT_BIT |
546 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
547 UNSIGNED_INT_2_10_10_10_REV_BIT |
548 INT_2_10_10_10_REV_BIT);
549 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
550
551 FLUSH_VERTICES(ctx, 0);
552
553 update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR0,
554 legalTypes, sizeMin, BGRA_OR_4,
555 size, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
556 }
557
558
559 void GLAPIENTRY
560 _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
561 {
562 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
563 GET_CURRENT_CONTEXT(ctx);
564
565 FLUSH_VERTICES(ctx, 0);
566
567 update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG,
568 legalTypes, 1, 1,
569 1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
570 }
571
572
573 void GLAPIENTRY
574 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
575 {
576 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
577 FLOAT_BIT | DOUBLE_BIT);
578 GET_CURRENT_CONTEXT(ctx);
579
580 FLUSH_VERTICES(ctx, 0);
581
582 update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX,
583 legalTypes, 1, 1,
584 1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
585 }
586
587
588 void GLAPIENTRY
589 _mesa_SecondaryColorPointer(GLint size, GLenum type,
590 GLsizei stride, const GLvoid *ptr)
591 {
592 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
593 SHORT_BIT | UNSIGNED_SHORT_BIT |
594 INT_BIT | UNSIGNED_INT_BIT |
595 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
596 UNSIGNED_INT_2_10_10_10_REV_BIT |
597 INT_2_10_10_10_REV_BIT);
598 GET_CURRENT_CONTEXT(ctx);
599
600 FLUSH_VERTICES(ctx, 0);
601
602 update_array(ctx, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1,
603 legalTypes, 3, BGRA_OR_4,
604 size, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
605 }
606
607
608 void GLAPIENTRY
609 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
610 const GLvoid *ptr)
611 {
612 GET_CURRENT_CONTEXT(ctx);
613 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
614 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
615 : (SHORT_BIT | INT_BIT |
616 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
617 UNSIGNED_INT_2_10_10_10_REV_BIT |
618 INT_2_10_10_10_REV_BIT);
619 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
620 const GLuint unit = ctx->Array.ActiveTexture;
621
622 FLUSH_VERTICES(ctx, 0);
623
624 update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX(unit),
625 legalTypes, sizeMin, 4,
626 size, type, stride, GL_FALSE, GL_FALSE, GL_FALSE,
627 ptr);
628 }
629
630
631 void GLAPIENTRY
632 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
633 {
634 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
635 /* this is the same type that glEdgeFlag uses */
636 const GLboolean integer = GL_FALSE;
637 GET_CURRENT_CONTEXT(ctx);
638
639 FLUSH_VERTICES(ctx, 0);
640
641 update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG,
642 legalTypes, 1, 1,
643 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, GL_FALSE, ptr);
644 }
645
646
647 void GLAPIENTRY
648 _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr)
649 {
650 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
651 GET_CURRENT_CONTEXT(ctx);
652
653 FLUSH_VERTICES(ctx, 0);
654
655 if (ctx->API != API_OPENGLES) {
656 _mesa_error(ctx, GL_INVALID_OPERATION,
657 "glPointSizePointer(ES 1.x only)");
658 return;
659 }
660
661 update_array(ctx, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE,
662 legalTypes, 1, 1,
663 1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
664 }
665
666
667 /**
668 * Set a generic vertex attribute array.
669 * Note that these arrays DO NOT alias the conventional GL vertex arrays
670 * (position, normal, color, fog, texcoord, etc).
671 */
672 void GLAPIENTRY
673 _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
674 GLboolean normalized,
675 GLsizei stride, const GLvoid *ptr)
676 {
677 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
678 SHORT_BIT | UNSIGNED_SHORT_BIT |
679 INT_BIT | UNSIGNED_INT_BIT |
680 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
681 FIXED_ES_BIT | FIXED_GL_BIT |
682 UNSIGNED_INT_2_10_10_10_REV_BIT |
683 INT_2_10_10_10_REV_BIT |
684 UNSIGNED_INT_10F_11F_11F_REV_BIT);
685 GET_CURRENT_CONTEXT(ctx);
686
687 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
688 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
689 return;
690 }
691
692 update_array(ctx, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index),
693 legalTypes, 1, BGRA_OR_4,
694 size, type, stride, normalized, GL_FALSE, GL_FALSE, ptr);
695 }
696
697
698 /**
699 * GL_EXT_gpu_shader4 / GL 3.0.
700 * Set an integer-valued vertex attribute array.
701 * Note that these arrays DO NOT alias the conventional GL vertex arrays
702 * (position, normal, color, fog, texcoord, etc).
703 */
704 void GLAPIENTRY
705 _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
706 GLsizei stride, const GLvoid *ptr)
707 {
708 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
709 SHORT_BIT | UNSIGNED_SHORT_BIT |
710 INT_BIT | UNSIGNED_INT_BIT);
711 const GLboolean normalized = GL_FALSE;
712 const GLboolean integer = GL_TRUE;
713 GET_CURRENT_CONTEXT(ctx);
714
715 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
716 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
717 return;
718 }
719
720 update_array(ctx, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index),
721 legalTypes, 1, 4,
722 size, type, stride, normalized, integer, GL_FALSE, ptr);
723 }
724
725 void GLAPIENTRY
726 _mesa_VertexAttribLPointer(GLuint index, GLint size, GLenum type,
727 GLsizei stride, const GLvoid *ptr)
728 {
729 GET_CURRENT_CONTEXT(ctx);
730 const GLbitfield legalTypes = (DOUBLE_BIT);
731 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
732 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribLPointer(index)");
733 return;
734 }
735
736 update_array(ctx, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index),
737 legalTypes, 1, 4,
738 size, type, stride, GL_TRUE, GL_FALSE, GL_TRUE, ptr);
739 }
740
741
742 static void
743 enable_vertex_array_attrib(struct gl_context *ctx,
744 struct gl_vertex_array_object *vao,
745 GLuint index,
746 const char *func)
747 {
748 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
749 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
750 return;
751 }
752
753 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
754
755 if (!vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
756 /* was disabled, now being enabled */
757 FLUSH_VERTICES(ctx, _NEW_ARRAY);
758 vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_TRUE;
759 vao->_Enabled |= VERT_BIT_GENERIC(index);
760 vao->NewArrays |= VERT_BIT_GENERIC(index);
761 }
762 }
763
764
765 void GLAPIENTRY
766 _mesa_EnableVertexAttribArray(GLuint index)
767 {
768 GET_CURRENT_CONTEXT(ctx);
769 enable_vertex_array_attrib(ctx, ctx->Array.VAO, index,
770 "glEnableVertexAttribArray");
771 }
772
773
774 void GLAPIENTRY
775 _mesa_EnableVertexArrayAttrib(GLuint vaobj, GLuint index)
776 {
777 GET_CURRENT_CONTEXT(ctx);
778 struct gl_vertex_array_object *vao;
779
780 /* The ARB_direct_state_access specification says:
781 *
782 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
783 * and DisableVertexArrayAttrib if <vaobj> is not
784 * [compatibility profile: zero or] the name of an existing vertex
785 * array object."
786 */
787 vao = _mesa_lookup_vao_err(ctx, vaobj, "glEnableVertexArrayAttrib");
788 if (!vao)
789 return;
790
791 enable_vertex_array_attrib(ctx, vao, index, "glEnableVertexArrayAttrib");
792 }
793
794
795 static void
796 disable_vertex_array_attrib(struct gl_context *ctx,
797 struct gl_vertex_array_object *vao,
798 GLuint index,
799 const char *func)
800 {
801 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
802 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
803 return;
804 }
805
806 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
807
808 if (vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
809 /* was enabled, now being disabled */
810 FLUSH_VERTICES(ctx, _NEW_ARRAY);
811 vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE;
812 vao->_Enabled &= ~VERT_BIT_GENERIC(index);
813 vao->NewArrays |= VERT_BIT_GENERIC(index);
814 }
815 }
816
817
818 void GLAPIENTRY
819 _mesa_DisableVertexAttribArray(GLuint index)
820 {
821 GET_CURRENT_CONTEXT(ctx);
822 disable_vertex_array_attrib(ctx, ctx->Array.VAO, index,
823 "glDisableVertexAttribArray");
824 }
825
826
827 void GLAPIENTRY
828 _mesa_DisableVertexArrayAttrib(GLuint vaobj, GLuint index)
829 {
830 GET_CURRENT_CONTEXT(ctx);
831 struct gl_vertex_array_object *vao;
832
833 /* The ARB_direct_state_access specification says:
834 *
835 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
836 * and DisableVertexArrayAttrib if <vaobj> is not
837 * [compatibility profile: zero or] the name of an existing vertex
838 * array object."
839 */
840 vao = _mesa_lookup_vao_err(ctx, vaobj, "glDisableVertexArrayAttrib");
841 if (!vao)
842 return;
843
844 disable_vertex_array_attrib(ctx, vao, index, "glDisableVertexArrayAttrib");
845 }
846
847
848 /**
849 * Return info for a vertex attribute array (no alias with legacy
850 * vertex attributes (pos, normal, color, etc)). This function does
851 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
852 */
853 static GLuint
854 get_vertex_array_attrib(struct gl_context *ctx,
855 const struct gl_vertex_array_object *vao,
856 GLuint index, GLenum pname,
857 const char *caller)
858 {
859 const struct gl_vertex_attrib_array *array;
860
861 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
862 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
863 return 0;
864 }
865
866 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
867
868 array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
869
870 switch (pname) {
871 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
872 return array->Enabled;
873 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
874 return (array->Format == GL_BGRA) ? GL_BGRA : array->Size;
875 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
876 return array->Stride;
877 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
878 return array->Type;
879 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
880 return array->Normalized;
881 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
882 return vao->VertexBinding[array->VertexBinding].BufferObj->Name;
883 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
884 if ((_mesa_is_desktop_gl(ctx)
885 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
886 || _mesa_is_gles3(ctx)) {
887 return array->Integer;
888 }
889 goto error;
890 case GL_VERTEX_ATTRIB_ARRAY_LONG:
891 if (_mesa_is_desktop_gl(ctx)) {
892 return array->Doubles;
893 }
894 goto error;
895 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
896 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
897 || _mesa_is_gles3(ctx)) {
898 return vao->VertexBinding[array->VertexBinding].InstanceDivisor;
899 }
900 goto error;
901 case GL_VERTEX_ATTRIB_BINDING:
902 if (_mesa_is_desktop_gl(ctx)) {
903 return array->VertexBinding - VERT_ATTRIB_GENERIC0;
904 }
905 goto error;
906 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
907 if (_mesa_is_desktop_gl(ctx)) {
908 return array->RelativeOffset;
909 }
910 goto error;
911 default:
912 ; /* fall-through */
913 }
914
915 error:
916 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
917 return 0;
918 }
919
920
921 static const GLfloat *
922 get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
923 {
924 if (index == 0) {
925 if (_mesa_attr_zero_aliases_vertex(ctx)) {
926 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
927 return NULL;
928 }
929 }
930 else if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
931 _mesa_error(ctx, GL_INVALID_VALUE,
932 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
933 return NULL;
934 }
935
936 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
937
938 FLUSH_CURRENT(ctx, 0);
939 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
940 }
941
942 void GLAPIENTRY
943 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
944 {
945 GET_CURRENT_CONTEXT(ctx);
946
947 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
948 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
949 if (v != NULL) {
950 COPY_4V(params, v);
951 }
952 }
953 else {
954 params[0] = (GLfloat) get_vertex_array_attrib(ctx, ctx->Array.VAO,
955 index, pname,
956 "glGetVertexAttribfv");
957 }
958 }
959
960
961 void GLAPIENTRY
962 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
963 {
964 GET_CURRENT_CONTEXT(ctx);
965
966 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
967 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
968 if (v != NULL) {
969 params[0] = (GLdouble) v[0];
970 params[1] = (GLdouble) v[1];
971 params[2] = (GLdouble) v[2];
972 params[3] = (GLdouble) v[3];
973 }
974 }
975 else {
976 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
977 index, pname,
978 "glGetVertexAttribdv");
979 }
980 }
981
982 void GLAPIENTRY
983 _mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params)
984 {
985 GET_CURRENT_CONTEXT(ctx);
986
987 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
988 const GLdouble *v = (const GLdouble *)get_current_attrib(ctx, index, "glGetVertexAttribLdv");
989 if (v != NULL) {
990 params[0] = v[0];
991 params[1] = v[1];
992 params[2] = v[2];
993 params[3] = v[3];
994 }
995 }
996 else {
997 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
998 index, pname,
999 "glGetVertexAttribLdv");
1000 }
1001 }
1002
1003 void GLAPIENTRY
1004 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
1005 {
1006 GET_CURRENT_CONTEXT(ctx);
1007
1008 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1009 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
1010 if (v != NULL) {
1011 /* XXX should floats in[0,1] be scaled to full int range? */
1012 params[0] = (GLint) v[0];
1013 params[1] = (GLint) v[1];
1014 params[2] = (GLint) v[2];
1015 params[3] = (GLint) v[3];
1016 }
1017 }
1018 else {
1019 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1020 index, pname,
1021 "glGetVertexAttribiv");
1022 }
1023 }
1024
1025
1026 /** GL 3.0 */
1027 void GLAPIENTRY
1028 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
1029 {
1030 GET_CURRENT_CONTEXT(ctx);
1031
1032 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1033 const GLint *v = (const GLint *)
1034 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
1035 if (v != NULL) {
1036 COPY_4V(params, v);
1037 }
1038 }
1039 else {
1040 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1041 index, pname,
1042 "glGetVertexAttribIiv");
1043 }
1044 }
1045
1046
1047 /** GL 3.0 */
1048 void GLAPIENTRY
1049 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
1050 {
1051 GET_CURRENT_CONTEXT(ctx);
1052
1053 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1054 const GLuint *v = (const GLuint *)
1055 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
1056 if (v != NULL) {
1057 COPY_4V(params, v);
1058 }
1059 }
1060 else {
1061 params[0] = get_vertex_array_attrib(ctx, ctx->Array.VAO,
1062 index, pname,
1063 "glGetVertexAttribIuiv");
1064 }
1065 }
1066
1067
1068 void GLAPIENTRY
1069 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
1070 {
1071 GET_CURRENT_CONTEXT(ctx);
1072
1073 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1074 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
1075 return;
1076 }
1077
1078 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
1079 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
1080 return;
1081 }
1082
1083 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1084
1085 *pointer = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
1086 }
1087
1088
1089 /** ARB_direct_state_access */
1090 void GLAPIENTRY
1091 _mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index,
1092 GLenum pname, GLint *params)
1093 {
1094 GET_CURRENT_CONTEXT(ctx);
1095 struct gl_vertex_array_object *vao;
1096
1097 /* The ARB_direct_state_access specification says:
1098 *
1099 * "An INVALID_OPERATION error is generated if <vaobj> is not
1100 * [compatibility profile: zero or] the name of an existing
1101 * vertex array object."
1102 */
1103 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexediv");
1104 if (!vao)
1105 return;
1106
1107 /* The ARB_direct_state_access specification says:
1108 *
1109 * "For GetVertexArrayIndexediv, <pname> must be one of
1110 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1111 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1112 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1113 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1114 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1115 *
1116 * and:
1117 *
1118 * "Add GetVertexArrayIndexediv in 'Get Command' for
1119 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1120 * VERTEX_ATTRIB_BINDING,
1121 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1122 * VERTEX_BINDING_OFFSET, and
1123 * VERTEX_BINDING_STRIDE states"
1124 *
1125 * The only parameter name common to both lists is
1126 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1127 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1128 * pretty clear however that the intent is that it should be possible
1129 * to query all vertex attrib and binding states that can be set with
1130 * a DSA function.
1131 */
1132 switch (pname) {
1133 case GL_VERTEX_BINDING_OFFSET:
1134 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1135 break;
1136 case GL_VERTEX_BINDING_STRIDE:
1137 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Stride;
1138 break;
1139 case GL_VERTEX_BINDING_DIVISOR:
1140 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
1141 break;
1142 case GL_VERTEX_BINDING_BUFFER:
1143 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name;
1144 break;
1145 default:
1146 params[0] = get_vertex_array_attrib(ctx, vao, index, pname,
1147 "glGetVertexArrayIndexediv");
1148 break;
1149 }
1150 }
1151
1152
1153 void GLAPIENTRY
1154 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj, GLuint index,
1155 GLenum pname, GLint64 *params)
1156 {
1157 GET_CURRENT_CONTEXT(ctx);
1158 struct gl_vertex_array_object *vao;
1159
1160 /* The ARB_direct_state_access specification says:
1161 *
1162 * "An INVALID_OPERATION error is generated if <vaobj> is not
1163 * [compatibility profile: zero or] the name of an existing
1164 * vertex array object."
1165 */
1166 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexed64iv");
1167 if (!vao)
1168 return;
1169
1170 /* The ARB_direct_state_access specification says:
1171 *
1172 * "For GetVertexArrayIndexed64iv, <pname> must be
1173 * VERTEX_BINDING_OFFSET."
1174 *
1175 * and:
1176 *
1177 * "An INVALID_ENUM error is generated if <pname> is not one of
1178 * the valid values listed above for the corresponding command."
1179 */
1180 if (pname != GL_VERTEX_BINDING_OFFSET) {
1181 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayIndexed64iv("
1182 "pname != GL_VERTEX_BINDING_OFFSET)");
1183 return;
1184 }
1185
1186 /* The ARB_direct_state_access specification says:
1187 *
1188 * "An INVALID_VALUE error is generated if <index> is greater than
1189 * or equal to the value of MAX_VERTEX_ATTRIBS."
1190 *
1191 * Since the index refers to a buffer binding in this case, the intended
1192 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1193 * required to be the same, so in practice this doesn't matter.
1194 */
1195 if (index >= ctx->Const.MaxVertexAttribBindings) {
1196 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexArrayIndexed64iv("
1197 "index %d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1198 index, ctx->Const.MaxVertexAttribBindings);
1199 return;
1200 }
1201
1202 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1203 }
1204
1205
1206 void GLAPIENTRY
1207 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
1208 GLsizei count, const GLvoid *ptr)
1209 {
1210 (void) count;
1211 _mesa_VertexPointer(size, type, stride, ptr);
1212 }
1213
1214
1215 void GLAPIENTRY
1216 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1217 const GLvoid *ptr)
1218 {
1219 (void) count;
1220 _mesa_NormalPointer(type, stride, ptr);
1221 }
1222
1223
1224 void GLAPIENTRY
1225 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
1226 const GLvoid *ptr)
1227 {
1228 (void) count;
1229 _mesa_ColorPointer(size, type, stride, ptr);
1230 }
1231
1232
1233 void GLAPIENTRY
1234 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1235 const GLvoid *ptr)
1236 {
1237 (void) count;
1238 _mesa_IndexPointer(type, stride, ptr);
1239 }
1240
1241
1242 void GLAPIENTRY
1243 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
1244 GLsizei count, const GLvoid *ptr)
1245 {
1246 (void) count;
1247 _mesa_TexCoordPointer(size, type, stride, ptr);
1248 }
1249
1250
1251 void GLAPIENTRY
1252 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
1253 {
1254 (void) count;
1255 _mesa_EdgeFlagPointer(stride, ptr);
1256 }
1257
1258
1259 void GLAPIENTRY
1260 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
1261 {
1262 GET_CURRENT_CONTEXT(ctx);
1263 GLboolean tflag, cflag, nflag; /* enable/disable flags */
1264 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
1265 GLenum ctype = 0; /* color type */
1266 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
1267 const GLint toffset = 0; /* always zero */
1268 GLint defstride; /* default stride */
1269 GLint c, f;
1270
1271 FLUSH_VERTICES(ctx, 0);
1272
1273 f = sizeof(GLfloat);
1274 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
1275
1276 if (stride < 0) {
1277 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
1278 return;
1279 }
1280
1281 switch (format) {
1282 case GL_V2F:
1283 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1284 tcomps = 0; ccomps = 0; vcomps = 2;
1285 voffset = 0;
1286 defstride = 2*f;
1287 break;
1288 case GL_V3F:
1289 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1290 tcomps = 0; ccomps = 0; vcomps = 3;
1291 voffset = 0;
1292 defstride = 3*f;
1293 break;
1294 case GL_C4UB_V2F:
1295 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1296 tcomps = 0; ccomps = 4; vcomps = 2;
1297 ctype = GL_UNSIGNED_BYTE;
1298 coffset = 0;
1299 voffset = c;
1300 defstride = c + 2*f;
1301 break;
1302 case GL_C4UB_V3F:
1303 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1304 tcomps = 0; ccomps = 4; vcomps = 3;
1305 ctype = GL_UNSIGNED_BYTE;
1306 coffset = 0;
1307 voffset = c;
1308 defstride = c + 3*f;
1309 break;
1310 case GL_C3F_V3F:
1311 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1312 tcomps = 0; ccomps = 3; vcomps = 3;
1313 ctype = GL_FLOAT;
1314 coffset = 0;
1315 voffset = 3*f;
1316 defstride = 6*f;
1317 break;
1318 case GL_N3F_V3F:
1319 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1320 tcomps = 0; ccomps = 0; vcomps = 3;
1321 noffset = 0;
1322 voffset = 3*f;
1323 defstride = 6*f;
1324 break;
1325 case GL_C4F_N3F_V3F:
1326 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1327 tcomps = 0; ccomps = 4; vcomps = 3;
1328 ctype = GL_FLOAT;
1329 coffset = 0;
1330 noffset = 4*f;
1331 voffset = 7*f;
1332 defstride = 10*f;
1333 break;
1334 case GL_T2F_V3F:
1335 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1336 tcomps = 2; ccomps = 0; vcomps = 3;
1337 voffset = 2*f;
1338 defstride = 5*f;
1339 break;
1340 case GL_T4F_V4F:
1341 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1342 tcomps = 4; ccomps = 0; vcomps = 4;
1343 voffset = 4*f;
1344 defstride = 8*f;
1345 break;
1346 case GL_T2F_C4UB_V3F:
1347 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1348 tcomps = 2; ccomps = 4; vcomps = 3;
1349 ctype = GL_UNSIGNED_BYTE;
1350 coffset = 2*f;
1351 voffset = c+2*f;
1352 defstride = c+5*f;
1353 break;
1354 case GL_T2F_C3F_V3F:
1355 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1356 tcomps = 2; ccomps = 3; vcomps = 3;
1357 ctype = GL_FLOAT;
1358 coffset = 2*f;
1359 voffset = 5*f;
1360 defstride = 8*f;
1361 break;
1362 case GL_T2F_N3F_V3F:
1363 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1364 tcomps = 2; ccomps = 0; vcomps = 3;
1365 noffset = 2*f;
1366 voffset = 5*f;
1367 defstride = 8*f;
1368 break;
1369 case GL_T2F_C4F_N3F_V3F:
1370 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1371 tcomps = 2; ccomps = 4; vcomps = 3;
1372 ctype = GL_FLOAT;
1373 coffset = 2*f;
1374 noffset = 6*f;
1375 voffset = 9*f;
1376 defstride = 12*f;
1377 break;
1378 case GL_T4F_C4F_N3F_V4F:
1379 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1380 tcomps = 4; ccomps = 4; vcomps = 4;
1381 ctype = GL_FLOAT;
1382 coffset = 4*f;
1383 noffset = 8*f;
1384 voffset = 11*f;
1385 defstride = 15*f;
1386 break;
1387 default:
1388 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
1389 return;
1390 }
1391
1392 if (stride==0) {
1393 stride = defstride;
1394 }
1395
1396 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1397 _mesa_DisableClientState( GL_INDEX_ARRAY );
1398 /* XXX also disable secondary color and generic arrays? */
1399
1400 /* Texcoords */
1401 if (tflag) {
1402 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1403 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
1404 (GLubyte *) pointer + toffset );
1405 }
1406 else {
1407 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
1408 }
1409
1410 /* Color */
1411 if (cflag) {
1412 _mesa_EnableClientState( GL_COLOR_ARRAY );
1413 _mesa_ColorPointer( ccomps, ctype, stride,
1414 (GLubyte *) pointer + coffset );
1415 }
1416 else {
1417 _mesa_DisableClientState( GL_COLOR_ARRAY );
1418 }
1419
1420
1421 /* Normals */
1422 if (nflag) {
1423 _mesa_EnableClientState( GL_NORMAL_ARRAY );
1424 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
1425 }
1426 else {
1427 _mesa_DisableClientState( GL_NORMAL_ARRAY );
1428 }
1429
1430 /* Vertices */
1431 _mesa_EnableClientState( GL_VERTEX_ARRAY );
1432 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
1433 (GLubyte *) pointer + voffset );
1434 }
1435
1436
1437 void GLAPIENTRY
1438 _mesa_LockArraysEXT(GLint first, GLsizei count)
1439 {
1440 GET_CURRENT_CONTEXT(ctx);
1441
1442 FLUSH_VERTICES(ctx, 0);
1443
1444 if (MESA_VERBOSE & VERBOSE_API)
1445 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
1446
1447 if (first < 0) {
1448 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1449 return;
1450 }
1451 if (count <= 0) {
1452 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1453 return;
1454 }
1455 if (ctx->Array.LockCount != 0) {
1456 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1457 return;
1458 }
1459
1460 ctx->Array.LockFirst = first;
1461 ctx->Array.LockCount = count;
1462
1463 ctx->NewState |= _NEW_ARRAY;
1464 }
1465
1466
1467 void GLAPIENTRY
1468 _mesa_UnlockArraysEXT( void )
1469 {
1470 GET_CURRENT_CONTEXT(ctx);
1471
1472 FLUSH_VERTICES(ctx, 0);
1473
1474 if (MESA_VERBOSE & VERBOSE_API)
1475 _mesa_debug(ctx, "glUnlockArrays\n");
1476
1477 if (ctx->Array.LockCount == 0) {
1478 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1479 return;
1480 }
1481
1482 ctx->Array.LockFirst = 0;
1483 ctx->Array.LockCount = 0;
1484 ctx->NewState |= _NEW_ARRAY;
1485 }
1486
1487
1488 /* GL_EXT_multi_draw_arrays */
1489 void GLAPIENTRY
1490 _mesa_MultiDrawArrays( GLenum mode, const GLint *first,
1491 const GLsizei *count, GLsizei primcount )
1492 {
1493 GET_CURRENT_CONTEXT(ctx);
1494 GLint i;
1495
1496 FLUSH_VERTICES(ctx, 0);
1497
1498 for (i = 0; i < primcount; i++) {
1499 if (count[i] > 0) {
1500 CALL_DrawArrays(ctx->CurrentDispatch, (mode, first[i], count[i]));
1501 }
1502 }
1503 }
1504
1505
1506 /* GL_IBM_multimode_draw_arrays */
1507 void GLAPIENTRY
1508 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1509 const GLsizei * count,
1510 GLsizei primcount, GLint modestride )
1511 {
1512 GET_CURRENT_CONTEXT(ctx);
1513 GLint i;
1514
1515 FLUSH_VERTICES(ctx, 0);
1516
1517 for ( i = 0 ; i < primcount ; i++ ) {
1518 if ( count[i] > 0 ) {
1519 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1520 CALL_DrawArrays(ctx->CurrentDispatch, ( m, first[i], count[i] ));
1521 }
1522 }
1523 }
1524
1525
1526 /* GL_IBM_multimode_draw_arrays */
1527 void GLAPIENTRY
1528 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1529 GLenum type, const GLvoid * const * indices,
1530 GLsizei primcount, GLint modestride )
1531 {
1532 GET_CURRENT_CONTEXT(ctx);
1533 GLint i;
1534
1535 FLUSH_VERTICES(ctx, 0);
1536
1537 /* XXX not sure about ARB_vertex_buffer_object handling here */
1538
1539 for ( i = 0 ; i < primcount ; i++ ) {
1540 if ( count[i] > 0 ) {
1541 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1542 CALL_DrawElements(ctx->CurrentDispatch, ( m, count[i], type,
1543 indices[i] ));
1544 }
1545 }
1546 }
1547
1548
1549 /**
1550 * GL_NV_primitive_restart and GL 3.1
1551 */
1552 void GLAPIENTRY
1553 _mesa_PrimitiveRestartIndex(GLuint index)
1554 {
1555 GET_CURRENT_CONTEXT(ctx);
1556
1557 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
1558 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
1559 return;
1560 }
1561
1562 if (ctx->Array.RestartIndex != index) {
1563 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
1564 ctx->Array.RestartIndex = index;
1565 }
1566 }
1567
1568
1569 /**
1570 * See GL_ARB_instanced_arrays.
1571 * Note that the instance divisor only applies to generic arrays, not
1572 * the legacy vertex arrays.
1573 */
1574 void GLAPIENTRY
1575 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
1576 {
1577 GET_CURRENT_CONTEXT(ctx);
1578
1579 const GLuint genericIndex = VERT_ATTRIB_GENERIC(index);
1580 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
1581
1582 if (!ctx->Extensions.ARB_instanced_arrays) {
1583 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
1584 return;
1585 }
1586
1587 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1588 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribDivisor(index = %u)",
1589 index);
1590 return;
1591 }
1592
1593 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
1594
1595 /* The ARB_vertex_attrib_binding spec says:
1596 *
1597 * "The command
1598 *
1599 * void VertexAttribDivisor(uint index, uint divisor);
1600 *
1601 * is equivalent to (assuming no errors are generated):
1602 *
1603 * VertexAttribBinding(index, index);
1604 * VertexBindingDivisor(index, divisor);"
1605 */
1606 vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
1607 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
1608 }
1609
1610
1611 unsigned
1612 _mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type)
1613 {
1614 /* From the OpenGL 4.3 core specification, page 302:
1615 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1616 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1617 * is used."
1618 */
1619 if (ctx->Array.PrimitiveRestartFixedIndex) {
1620 switch (ib_type) {
1621 case GL_UNSIGNED_BYTE:
1622 return 0xff;
1623 case GL_UNSIGNED_SHORT:
1624 return 0xffff;
1625 case GL_UNSIGNED_INT:
1626 return 0xffffffff;
1627 default:
1628 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1629 }
1630 }
1631
1632 return ctx->Array.RestartIndex;
1633 }
1634
1635
1636 /**
1637 * GL_ARB_vertex_attrib_binding
1638 */
1639 static void
1640 vertex_array_vertex_buffer(struct gl_context *ctx, struct gl_vertex_array_object *vao,
1641 GLuint bindingIndex, GLuint buffer, GLintptr offset,
1642 GLsizei stride, const char *func)
1643 {
1644 struct gl_buffer_object *vbo;
1645
1646 ASSERT_OUTSIDE_BEGIN_END(ctx);
1647
1648 /* The ARB_vertex_attrib_binding spec says:
1649 *
1650 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1651 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1652 */
1653 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1654 _mesa_error(ctx, GL_INVALID_VALUE,
1655 "%s(bindingindex=%u > "
1656 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1657 func, bindingIndex);
1658 return;
1659 }
1660
1661 /* The ARB_vertex_attrib_binding spec says:
1662 *
1663 * "The error INVALID_VALUE is generated if <stride> or <offset>
1664 * are negative."
1665 */
1666 if (offset < 0) {
1667 _mesa_error(ctx, GL_INVALID_VALUE,
1668 "%s(offset=%" PRId64 " < 0)",
1669 func, (int64_t) offset);
1670 return;
1671 }
1672
1673 if (stride < 0) {
1674 _mesa_error(ctx, GL_INVALID_VALUE,
1675 "%s(stride=%d < 0)", func, stride);
1676 return;
1677 }
1678
1679 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
1680 stride > ctx->Const.MaxVertexAttribStride) {
1681 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
1682 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
1683 return;
1684 }
1685
1686 if (buffer == vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) {
1687 vbo = vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
1688 } else if (buffer != 0) {
1689 vbo = _mesa_lookup_bufferobj(ctx, buffer);
1690
1691 /* From the GL_ARB_vertex_attrib_array spec:
1692 *
1693 * "[Core profile only:]
1694 * An INVALID_OPERATION error is generated if buffer is not zero or a
1695 * name returned from a previous call to GenBuffers, or if such a name
1696 * has since been deleted with DeleteBuffers.
1697 *
1698 * Otherwise, we fall back to the same compat profile behavior as other
1699 * object references (automatically gen it).
1700 */
1701 if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &vbo, func))
1702 return;
1703 } else {
1704 /* The ARB_vertex_attrib_binding spec says:
1705 *
1706 * "If <buffer> is zero, any buffer object attached to this
1707 * bindpoint is detached."
1708 */
1709 vbo = ctx->Shared->NullBufferObj;
1710 }
1711
1712 bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex),
1713 vbo, offset, stride);
1714 }
1715
1716
1717 void GLAPIENTRY
1718 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
1719 GLsizei stride)
1720 {
1721 GET_CURRENT_CONTEXT(ctx);
1722
1723 /* The ARB_vertex_attrib_binding spec says:
1724 *
1725 * "An INVALID_OPERATION error is generated if no vertex array object
1726 * is bound."
1727 */
1728 if (ctx->API == API_OPENGL_CORE &&
1729 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1730 _mesa_error(ctx, GL_INVALID_OPERATION,
1731 "glBindVertexBuffer(No array object bound)");
1732 return;
1733 }
1734
1735 vertex_array_vertex_buffer(ctx, ctx->Array.VAO, bindingIndex,
1736 buffer, offset, stride, "glBindVertexBuffer");
1737 }
1738
1739
1740 void GLAPIENTRY
1741 _mesa_VertexArrayVertexBuffer(GLuint vaobj, GLuint bindingIndex, GLuint buffer,
1742 GLintptr offset, GLsizei stride)
1743 {
1744 GET_CURRENT_CONTEXT(ctx);
1745 struct gl_vertex_array_object *vao;
1746
1747 /* The ARB_direct_state_access specification says:
1748 *
1749 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1750 * if <vaobj> is not [compatibility profile: zero or] the name of an
1751 * existing vertex array object."
1752 */
1753 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffer");
1754 if (!vao)
1755 return;
1756
1757 vertex_array_vertex_buffer(ctx, vao, bindingIndex,
1758 buffer, offset, stride,
1759 "glVertexArrayVertexBuffer");
1760 }
1761
1762
1763 static void
1764 vertex_array_vertex_buffers(struct gl_context *ctx,
1765 struct gl_vertex_array_object *vao,
1766 GLuint first, GLsizei count, const GLuint *buffers,
1767 const GLintptr *offsets, const GLsizei *strides,
1768 const char *func)
1769 {
1770 GLuint i;
1771
1772 ASSERT_OUTSIDE_BEGIN_END(ctx);
1773
1774 /* The ARB_multi_bind spec says:
1775 *
1776 * "An INVALID_OPERATION error is generated if <first> + <count>
1777 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1778 */
1779 if (first + count > ctx->Const.MaxVertexAttribBindings) {
1780 _mesa_error(ctx, GL_INVALID_OPERATION,
1781 "%s(first=%u + count=%d > the value of "
1782 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1783 func, first, count, ctx->Const.MaxVertexAttribBindings);
1784 return;
1785 }
1786
1787 if (!buffers) {
1788 /**
1789 * The ARB_multi_bind spec says:
1790 *
1791 * "If <buffers> is NULL, each affected vertex buffer binding point
1792 * from <first> through <first>+<count>-1 will be reset to have no
1793 * bound buffer object. In this case, the offsets and strides
1794 * associated with the binding points are set to default values,
1795 * ignoring <offsets> and <strides>."
1796 */
1797 struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj;
1798
1799 for (i = 0; i < count; i++)
1800 bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
1801 vbo, 0, 16);
1802
1803 return;
1804 }
1805
1806 /* Note that the error semantics for multi-bind commands differ from
1807 * those of other GL commands.
1808 *
1809 * The Issues section in the ARB_multi_bind spec says:
1810 *
1811 * "(11) Typically, OpenGL specifies that if an error is generated by
1812 * a command, that command has no effect. This is somewhat
1813 * unfortunate for multi-bind commands, because it would require
1814 * a first pass to scan the entire list of bound objects for
1815 * errors and then a second pass to actually perform the
1816 * bindings. Should we have different error semantics?
1817 *
1818 * RESOLVED: Yes. In this specification, when the parameters for
1819 * one of the <count> binding points are invalid, that binding
1820 * point is not updated and an error will be generated. However,
1821 * other binding points in the same command will be updated if
1822 * their parameters are valid and no other error occurs."
1823 */
1824
1825 _mesa_begin_bufferobj_lookups(ctx);
1826
1827 for (i = 0; i < count; i++) {
1828 struct gl_buffer_object *vbo;
1829
1830 /* The ARB_multi_bind spec says:
1831 *
1832 * "An INVALID_VALUE error is generated if any value in
1833 * <offsets> or <strides> is negative (per binding)."
1834 */
1835 if (offsets[i] < 0) {
1836 _mesa_error(ctx, GL_INVALID_VALUE,
1837 "%s(offsets[%u]=%" PRId64 " < 0)",
1838 func, i, (int64_t) offsets[i]);
1839 continue;
1840 }
1841
1842 if (strides[i] < 0) {
1843 _mesa_error(ctx, GL_INVALID_VALUE,
1844 "%s(strides[%u]=%d < 0)",
1845 func, i, strides[i]);
1846 continue;
1847 }
1848
1849 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
1850 strides[i] > ctx->Const.MaxVertexAttribStride) {
1851 _mesa_error(ctx, GL_INVALID_VALUE,
1852 "%s(strides[%u]=%d > "
1853 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, i, strides[i]);
1854 continue;
1855 }
1856
1857 if (buffers[i]) {
1858 struct gl_vertex_buffer_binding *binding =
1859 &vao->VertexBinding[VERT_ATTRIB_GENERIC(first + i)];
1860
1861 if (buffers[i] == binding->BufferObj->Name)
1862 vbo = binding->BufferObj;
1863 else
1864 vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, func);
1865
1866 if (!vbo)
1867 continue;
1868 } else {
1869 vbo = ctx->Shared->NullBufferObj;
1870 }
1871
1872 bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
1873 vbo, offsets[i], strides[i]);
1874 }
1875
1876 _mesa_end_bufferobj_lookups(ctx);
1877 }
1878
1879
1880 void GLAPIENTRY
1881 _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
1882 const GLintptr *offsets, const GLsizei *strides)
1883 {
1884 GET_CURRENT_CONTEXT(ctx);
1885
1886 /* The ARB_vertex_attrib_binding spec says:
1887 *
1888 * "An INVALID_OPERATION error is generated if no
1889 * vertex array object is bound."
1890 */
1891 if (ctx->API == API_OPENGL_CORE &&
1892 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1893 _mesa_error(ctx, GL_INVALID_OPERATION,
1894 "glBindVertexBuffers(No array object bound)");
1895 return;
1896 }
1897
1898 vertex_array_vertex_buffers(ctx, ctx->Array.VAO, first, count,
1899 buffers, offsets, strides,
1900 "glBindVertexBuffers");
1901 }
1902
1903
1904 void GLAPIENTRY
1905 _mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count,
1906 const GLuint *buffers,
1907 const GLintptr *offsets, const GLsizei *strides)
1908 {
1909 GET_CURRENT_CONTEXT(ctx);
1910 struct gl_vertex_array_object *vao;
1911
1912 /* The ARB_direct_state_access specification says:
1913 *
1914 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1915 * if <vaobj> is not [compatibility profile: zero or] the name of an
1916 * existing vertex array object."
1917 */
1918 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffers");
1919 if (!vao)
1920 return;
1921
1922 vertex_array_vertex_buffers(ctx, vao, first, count,
1923 buffers, offsets, strides,
1924 "glVertexArrayVertexBuffers");
1925 }
1926
1927
1928 static void
1929 vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type,
1930 GLboolean normalized, GLboolean integer,
1931 GLboolean doubles, GLbitfield legalTypes,
1932 GLsizei maxSize, GLuint relativeOffset,
1933 const char *func)
1934 {
1935 GET_CURRENT_CONTEXT(ctx);
1936 ASSERT_OUTSIDE_BEGIN_END(ctx);
1937
1938 /* The ARB_vertex_attrib_binding spec says:
1939 *
1940 * "An INVALID_OPERATION error is generated under any of the following
1941 * conditions:
1942 * - if no vertex array object is currently bound (see section 2.10);
1943 * - ..."
1944 *
1945 * This error condition only applies to VertexAttribFormat and
1946 * VertexAttribIFormat in the extension spec, but we assume that this
1947 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
1948 * to all three functions.
1949 */
1950 if (ctx->API == API_OPENGL_CORE &&
1951 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1952 _mesa_error(ctx, GL_INVALID_OPERATION,
1953 "%s(No array object bound)", func);
1954 return;
1955 }
1956
1957 /* The ARB_vertex_attrib_binding spec says:
1958 *
1959 * "The error INVALID_VALUE is generated if index is greater than or equal
1960 * to the value of MAX_VERTEX_ATTRIBS."
1961 */
1962 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1963 _mesa_error(ctx, GL_INVALID_VALUE,
1964 "%s(attribindex=%u > "
1965 "GL_MAX_VERTEX_ATTRIBS)",
1966 func, attribIndex);
1967 return;
1968 }
1969
1970 FLUSH_VERTICES(ctx, 0);
1971
1972 update_array_format(ctx, func, ctx->Array.VAO,
1973 VERT_ATTRIB_GENERIC(attribIndex),
1974 legalTypes, 1, maxSize, size, type,
1975 normalized, integer, doubles, relativeOffset);
1976 }
1977
1978
1979 void GLAPIENTRY
1980 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
1981 GLboolean normalized, GLuint relativeOffset)
1982 {
1983 vertex_attrib_format(attribIndex, size, type, normalized,
1984 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
1985 BGRA_OR_4, relativeOffset,
1986 "glVertexAttribFormat");
1987 }
1988
1989
1990 void GLAPIENTRY
1991 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
1992 GLuint relativeOffset)
1993 {
1994 vertex_attrib_format(attribIndex, size, type, GL_FALSE,
1995 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK, 4,
1996 relativeOffset, "glVertexAttribIFormat");
1997 }
1998
1999
2000 void GLAPIENTRY
2001 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
2002 GLuint relativeOffset)
2003 {
2004 vertex_attrib_format(attribIndex, size, type, GL_FALSE, GL_FALSE,
2005 GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK, 4,
2006 relativeOffset, "glVertexAttribLFormat");
2007 }
2008
2009
2010 static void
2011 vertex_array_attrib_format(GLuint vaobj, GLuint attribIndex, GLint size,
2012 GLenum type, GLboolean normalized,
2013 GLboolean integer, GLboolean doubles,
2014 GLbitfield legalTypes, GLsizei maxSize,
2015 GLuint relativeOffset, const char *func)
2016 {
2017 GET_CURRENT_CONTEXT(ctx);
2018 struct gl_vertex_array_object *vao;
2019
2020 ASSERT_OUTSIDE_BEGIN_END(ctx);
2021
2022 /* The ARB_direct_state_access spec says:
2023 *
2024 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
2025 * if <vaobj> is not [compatibility profile: zero or] the name of an
2026 * existing vertex array object."
2027 */
2028 vao = _mesa_lookup_vao_err(ctx, vaobj, func);
2029 if (!vao)
2030 return;
2031
2032 /* The ARB_vertex_attrib_binding spec says:
2033 *
2034 * "The error INVALID_VALUE is generated if index is greater than or equal
2035 * to the value of MAX_VERTEX_ATTRIBS."
2036 */
2037 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2038 _mesa_error(ctx, GL_INVALID_VALUE,
2039 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2040 func, attribIndex);
2041 return;
2042 }
2043
2044 FLUSH_VERTICES(ctx, 0);
2045
2046 update_array_format(ctx, func, vao,
2047 VERT_ATTRIB_GENERIC(attribIndex),
2048 legalTypes, 1, maxSize, size, type, normalized,
2049 integer, doubles, relativeOffset);
2050 }
2051
2052
2053 void GLAPIENTRY
2054 _mesa_VertexArrayAttribFormat(GLuint vaobj, GLuint attribIndex, GLint size,
2055 GLenum type, GLboolean normalized,
2056 GLuint relativeOffset)
2057 {
2058 vertex_array_attrib_format(vaobj, attribIndex, size, type, normalized,
2059 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
2060 BGRA_OR_4, relativeOffset,
2061 "glVertexArrayAttribFormat");
2062 }
2063
2064
2065 void GLAPIENTRY
2066 _mesa_VertexArrayAttribIFormat(GLuint vaobj, GLuint attribIndex,
2067 GLint size, GLenum type,
2068 GLuint relativeOffset)
2069 {
2070 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2071 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK,
2072 4, relativeOffset,
2073 "glVertexArrayAttribIFormat");
2074 }
2075
2076
2077 void GLAPIENTRY
2078 _mesa_VertexArrayAttribLFormat(GLuint vaobj, GLuint attribIndex,
2079 GLint size, GLenum type,
2080 GLuint relativeOffset)
2081 {
2082 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2083 GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK,
2084 4, relativeOffset,
2085 "glVertexArrayAttribLFormat");
2086 }
2087
2088
2089 static void
2090 vertex_array_attrib_binding(struct gl_context *ctx,
2091 struct gl_vertex_array_object *vao,
2092 GLuint attribIndex, GLuint bindingIndex,
2093 const char *func)
2094 {
2095 ASSERT_OUTSIDE_BEGIN_END(ctx);
2096
2097 /* The ARB_vertex_attrib_binding spec says:
2098 *
2099 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2100 * <bindingindex> must be less than the value of
2101 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2102 * is generated."
2103 */
2104 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2105 _mesa_error(ctx, GL_INVALID_VALUE,
2106 "%s(attribindex=%u >= "
2107 "GL_MAX_VERTEX_ATTRIBS)",
2108 func, attribIndex);
2109 return;
2110 }
2111
2112 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2113 _mesa_error(ctx, GL_INVALID_VALUE,
2114 "%s(bindingindex=%u >= "
2115 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2116 func, bindingIndex);
2117 return;
2118 }
2119
2120 assert(VERT_ATTRIB_GENERIC(attribIndex) < ARRAY_SIZE(vao->VertexAttrib));
2121
2122 vertex_attrib_binding(ctx, vao,
2123 VERT_ATTRIB_GENERIC(attribIndex),
2124 VERT_ATTRIB_GENERIC(bindingIndex));
2125 }
2126
2127
2128 void GLAPIENTRY
2129 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
2130 {
2131 GET_CURRENT_CONTEXT(ctx);
2132
2133 /* The ARB_vertex_attrib_binding spec says:
2134 *
2135 * "An INVALID_OPERATION error is generated if no vertex array object
2136 * is bound."
2137 */
2138 if (ctx->API == API_OPENGL_CORE &&
2139 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2140 _mesa_error(ctx, GL_INVALID_OPERATION,
2141 "glVertexAttribBinding(No array object bound)");
2142 return;
2143 }
2144
2145 vertex_array_attrib_binding(ctx, ctx->Array.VAO,
2146 attribIndex, bindingIndex,
2147 "glVertexAttribBinding");
2148 }
2149
2150
2151 void GLAPIENTRY
2152 _mesa_VertexArrayAttribBinding(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex)
2153 {
2154 GET_CURRENT_CONTEXT(ctx);
2155 struct gl_vertex_array_object *vao;
2156
2157 /* The ARB_direct_state_access specification says:
2158 *
2159 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2160 * if <vaobj> is not [compatibility profile: zero or] the name of an
2161 * existing vertex array object."
2162 */
2163 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayAttribBinding");
2164 if (!vao)
2165 return;
2166
2167 vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex,
2168 "glVertexArrayAttribBinding");
2169 }
2170
2171
2172 static void
2173 vertex_array_binding_divisor(struct gl_context *ctx,
2174 struct gl_vertex_array_object *vao,
2175 GLuint bindingIndex, GLuint divisor,
2176 const char *func)
2177 {
2178 ASSERT_OUTSIDE_BEGIN_END(ctx);
2179
2180 if (!ctx->Extensions.ARB_instanced_arrays) {
2181 _mesa_error(ctx, GL_INVALID_OPERATION, "%s()", func);
2182 return;
2183 }
2184
2185 /* The ARB_vertex_attrib_binding spec says:
2186 *
2187 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2188 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2189 */
2190 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2191 _mesa_error(ctx, GL_INVALID_VALUE,
2192 "%s(bindingindex=%u > "
2193 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2194 func, bindingIndex);
2195 return;
2196 }
2197
2198 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
2199 }
2200
2201
2202 void GLAPIENTRY
2203 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
2204 {
2205 GET_CURRENT_CONTEXT(ctx);
2206
2207 /* The ARB_vertex_attrib_binding spec says:
2208 *
2209 * "An INVALID_OPERATION error is generated if no vertex array object
2210 * is bound."
2211 */
2212 if (ctx->API == API_OPENGL_CORE &&
2213 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2214 _mesa_error(ctx, GL_INVALID_OPERATION,
2215 "glVertexBindingDivisor(No array object bound)");
2216 return;
2217 }
2218
2219 vertex_array_binding_divisor(ctx, ctx->Array.VAO,
2220 bindingIndex, divisor,
2221 "glVertexBindingDivisor");
2222 }
2223
2224
2225 void GLAPIENTRY
2226 _mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex, GLuint divisor)
2227 {
2228 struct gl_vertex_array_object *vao;
2229 GET_CURRENT_CONTEXT(ctx);
2230
2231 /* The ARB_direct_state_access specification says:
2232 *
2233 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2234 * if <vaobj> is not [compatibility profile: zero or] the name of an
2235 * existing vertex array object."
2236 */
2237 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayBindingDivisor");
2238 if (!vao)
2239 return;
2240
2241 vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor,
2242 "glVertexArrayBindingDivisor");
2243 }
2244
2245
2246 /**
2247 * Copy one client vertex array to another.
2248 */
2249 void
2250 _mesa_copy_client_array(struct gl_context *ctx,
2251 struct gl_client_array *dst,
2252 struct gl_client_array *src)
2253 {
2254 dst->Size = src->Size;
2255 dst->Type = src->Type;
2256 dst->Format = src->Format;
2257 dst->Stride = src->Stride;
2258 dst->StrideB = src->StrideB;
2259 dst->Ptr = src->Ptr;
2260 dst->Enabled = src->Enabled;
2261 dst->Normalized = src->Normalized;
2262 dst->Integer = src->Integer;
2263 dst->Doubles = src->Doubles;
2264 dst->InstanceDivisor = src->InstanceDivisor;
2265 dst->_ElementSize = src->_ElementSize;
2266 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
2267 }
2268
2269 void
2270 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
2271 struct gl_vertex_attrib_array *dst,
2272 const struct gl_vertex_attrib_array *src)
2273 {
2274 dst->Size = src->Size;
2275 dst->Type = src->Type;
2276 dst->Format = src->Format;
2277 dst->VertexBinding = src->VertexBinding;
2278 dst->RelativeOffset = src->RelativeOffset;
2279 dst->Format = src->Format;
2280 dst->Integer = src->Integer;
2281 dst->Doubles = src->Doubles;
2282 dst->Normalized = src->Normalized;
2283 dst->Ptr = src->Ptr;
2284 dst->Enabled = src->Enabled;
2285 dst->_ElementSize = src->_ElementSize;
2286 }
2287
2288 void
2289 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
2290 struct gl_vertex_buffer_binding *dst,
2291 const struct gl_vertex_buffer_binding *src)
2292 {
2293 dst->Offset = src->Offset;
2294 dst->Stride = src->Stride;
2295 dst->InstanceDivisor = src->InstanceDivisor;
2296 dst->_BoundArrays = src->_BoundArrays;
2297
2298 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
2299 }
2300
2301 /**
2302 * Print vertex array's fields.
2303 */
2304 static void
2305 print_array(const char *name, GLint index, const struct gl_client_array *array)
2306 {
2307 if (index >= 0)
2308 fprintf(stderr, " %s[%d]: ", name, index);
2309 else
2310 fprintf(stderr, " %s: ", name);
2311 fprintf(stderr, "Ptr=%p, Type=%s, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
2312 array->Ptr, _mesa_enum_to_string(array->Type), array->Size,
2313 array->_ElementSize, array->StrideB, array->BufferObj->Name,
2314 (unsigned long) array->BufferObj->Size);
2315 }
2316
2317
2318 /**
2319 * Print current vertex object/array info. For debug.
2320 */
2321 void
2322 _mesa_print_arrays(struct gl_context *ctx)
2323 {
2324 struct gl_vertex_array_object *vao = ctx->Array.VAO;
2325 GLuint i;
2326
2327 printf("Array Object %u\n", vao->Name);
2328 if (vao->_VertexAttrib[VERT_ATTRIB_POS].Enabled)
2329 print_array("Vertex", -1, &vao->_VertexAttrib[VERT_ATTRIB_POS]);
2330 if (vao->_VertexAttrib[VERT_ATTRIB_NORMAL].Enabled)
2331 print_array("Normal", -1, &vao->_VertexAttrib[VERT_ATTRIB_NORMAL]);
2332 if (vao->_VertexAttrib[VERT_ATTRIB_COLOR0].Enabled)
2333 print_array("Color", -1, &vao->_VertexAttrib[VERT_ATTRIB_COLOR0]);
2334 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++)
2335 if (vao->_VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled)
2336 print_array("TexCoord", i, &vao->_VertexAttrib[VERT_ATTRIB_TEX(i)]);
2337 for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++)
2338 if (vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled)
2339 print_array("Attrib", i, &vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)]);
2340 }
2341
2342
2343 /**
2344 * Initialize vertex array state for given context.
2345 */
2346 void
2347 _mesa_init_varray(struct gl_context *ctx)
2348 {
2349 ctx->Array.DefaultVAO = ctx->Driver.NewArrayObject(ctx, 0);
2350 _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO);
2351 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
2352
2353 ctx->Array.Objects = _mesa_NewHashTable();
2354 }
2355
2356
2357 /**
2358 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2359 */
2360 static void
2361 delete_arrayobj_cb(GLuint id, void *data, void *userData)
2362 {
2363 struct gl_vertex_array_object *vao = (struct gl_vertex_array_object *) data;
2364 struct gl_context *ctx = (struct gl_context *) userData;
2365 _mesa_delete_vao(ctx, vao);
2366 }
2367
2368
2369 /**
2370 * Free vertex array state for given context.
2371 */
2372 void
2373 _mesa_free_varray_data(struct gl_context *ctx)
2374 {
2375 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
2376 _mesa_DeleteHashTable(ctx->Array.Objects);
2377 }