mesa: Make bind_vertex_buffer avilable outside varray.c
[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 void
158 _mesa_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 _mesa_bind_vertex_buffer(ctx, ctx->Array.VAO, attrib,
495 ctx->Array.ArrayBufferObj, (GLintptr) ptr,
496 effectiveStride);
497 }
498
499
500 void GLAPIENTRY
501 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
502 {
503 GET_CURRENT_CONTEXT(ctx);
504 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
505 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
506 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
507 DOUBLE_BIT | HALF_BIT |
508 UNSIGNED_INT_2_10_10_10_REV_BIT |
509 INT_2_10_10_10_REV_BIT);
510
511 FLUSH_VERTICES(ctx, 0);
512
513 update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS,
514 legalTypes, 2, 4,
515 size, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
516 }
517
518
519 void GLAPIENTRY
520 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
521 {
522 GET_CURRENT_CONTEXT(ctx);
523 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
524 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
525 : (BYTE_BIT | SHORT_BIT | INT_BIT |
526 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
527 UNSIGNED_INT_2_10_10_10_REV_BIT |
528 INT_2_10_10_10_REV_BIT);
529
530 FLUSH_VERTICES(ctx, 0);
531
532 update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL,
533 legalTypes, 3, 3,
534 3, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
535 }
536
537
538 void GLAPIENTRY
539 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
540 {
541 GET_CURRENT_CONTEXT(ctx);
542 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
543 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
544 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
545 SHORT_BIT | UNSIGNED_SHORT_BIT |
546 INT_BIT | UNSIGNED_INT_BIT |
547 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
548 UNSIGNED_INT_2_10_10_10_REV_BIT |
549 INT_2_10_10_10_REV_BIT);
550 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
551
552 FLUSH_VERTICES(ctx, 0);
553
554 update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR0,
555 legalTypes, sizeMin, BGRA_OR_4,
556 size, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
557 }
558
559
560 void GLAPIENTRY
561 _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
562 {
563 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
564 GET_CURRENT_CONTEXT(ctx);
565
566 FLUSH_VERTICES(ctx, 0);
567
568 update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG,
569 legalTypes, 1, 1,
570 1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
571 }
572
573
574 void GLAPIENTRY
575 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
576 {
577 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
578 FLOAT_BIT | DOUBLE_BIT);
579 GET_CURRENT_CONTEXT(ctx);
580
581 FLUSH_VERTICES(ctx, 0);
582
583 update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX,
584 legalTypes, 1, 1,
585 1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
586 }
587
588
589 void GLAPIENTRY
590 _mesa_SecondaryColorPointer(GLint size, GLenum type,
591 GLsizei stride, const GLvoid *ptr)
592 {
593 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
594 SHORT_BIT | UNSIGNED_SHORT_BIT |
595 INT_BIT | UNSIGNED_INT_BIT |
596 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
597 UNSIGNED_INT_2_10_10_10_REV_BIT |
598 INT_2_10_10_10_REV_BIT);
599 GET_CURRENT_CONTEXT(ctx);
600
601 FLUSH_VERTICES(ctx, 0);
602
603 update_array(ctx, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1,
604 legalTypes, 3, BGRA_OR_4,
605 size, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
606 }
607
608
609 void GLAPIENTRY
610 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
611 const GLvoid *ptr)
612 {
613 GET_CURRENT_CONTEXT(ctx);
614 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
615 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
616 : (SHORT_BIT | INT_BIT |
617 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
618 UNSIGNED_INT_2_10_10_10_REV_BIT |
619 INT_2_10_10_10_REV_BIT);
620 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
621 const GLuint unit = ctx->Array.ActiveTexture;
622
623 FLUSH_VERTICES(ctx, 0);
624
625 update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX(unit),
626 legalTypes, sizeMin, 4,
627 size, type, stride, GL_FALSE, GL_FALSE, GL_FALSE,
628 ptr);
629 }
630
631
632 void GLAPIENTRY
633 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
634 {
635 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
636 /* this is the same type that glEdgeFlag uses */
637 const GLboolean integer = GL_FALSE;
638 GET_CURRENT_CONTEXT(ctx);
639
640 FLUSH_VERTICES(ctx, 0);
641
642 update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG,
643 legalTypes, 1, 1,
644 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, GL_FALSE, ptr);
645 }
646
647
648 void GLAPIENTRY
649 _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr)
650 {
651 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
652 GET_CURRENT_CONTEXT(ctx);
653
654 FLUSH_VERTICES(ctx, 0);
655
656 if (ctx->API != API_OPENGLES) {
657 _mesa_error(ctx, GL_INVALID_OPERATION,
658 "glPointSizePointer(ES 1.x only)");
659 return;
660 }
661
662 update_array(ctx, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE,
663 legalTypes, 1, 1,
664 1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
665 }
666
667
668 /**
669 * Set a generic vertex attribute array.
670 * Note that these arrays DO NOT alias the conventional GL vertex arrays
671 * (position, normal, color, fog, texcoord, etc).
672 */
673 void GLAPIENTRY
674 _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
675 GLboolean normalized,
676 GLsizei stride, const GLvoid *ptr)
677 {
678 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
679 SHORT_BIT | UNSIGNED_SHORT_BIT |
680 INT_BIT | UNSIGNED_INT_BIT |
681 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
682 FIXED_ES_BIT | FIXED_GL_BIT |
683 UNSIGNED_INT_2_10_10_10_REV_BIT |
684 INT_2_10_10_10_REV_BIT |
685 UNSIGNED_INT_10F_11F_11F_REV_BIT);
686 GET_CURRENT_CONTEXT(ctx);
687
688 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
689 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
690 return;
691 }
692
693 update_array(ctx, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index),
694 legalTypes, 1, BGRA_OR_4,
695 size, type, stride, normalized, GL_FALSE, GL_FALSE, ptr);
696 }
697
698
699 /**
700 * GL_EXT_gpu_shader4 / GL 3.0.
701 * Set an integer-valued vertex attribute array.
702 * Note that these arrays DO NOT alias the conventional GL vertex arrays
703 * (position, normal, color, fog, texcoord, etc).
704 */
705 void GLAPIENTRY
706 _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
707 GLsizei stride, const GLvoid *ptr)
708 {
709 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
710 SHORT_BIT | UNSIGNED_SHORT_BIT |
711 INT_BIT | UNSIGNED_INT_BIT);
712 const GLboolean normalized = GL_FALSE;
713 const GLboolean integer = GL_TRUE;
714 GET_CURRENT_CONTEXT(ctx);
715
716 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
717 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
718 return;
719 }
720
721 update_array(ctx, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index),
722 legalTypes, 1, 4,
723 size, type, stride, normalized, integer, GL_FALSE, ptr);
724 }
725
726 void GLAPIENTRY
727 _mesa_VertexAttribLPointer(GLuint index, GLint size, GLenum type,
728 GLsizei stride, const GLvoid *ptr)
729 {
730 GET_CURRENT_CONTEXT(ctx);
731 const GLbitfield legalTypes = (DOUBLE_BIT);
732 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
733 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribLPointer(index)");
734 return;
735 }
736
737 update_array(ctx, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index),
738 legalTypes, 1, 4,
739 size, type, stride, GL_TRUE, GL_FALSE, GL_TRUE, ptr);
740 }
741
742
743 static void
744 enable_vertex_array_attrib(struct gl_context *ctx,
745 struct gl_vertex_array_object *vao,
746 GLuint index,
747 const char *func)
748 {
749 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
750 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
751 return;
752 }
753
754 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
755
756 if (!vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
757 /* was disabled, now being enabled */
758 FLUSH_VERTICES(ctx, _NEW_ARRAY);
759 vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_TRUE;
760 vao->_Enabled |= VERT_BIT_GENERIC(index);
761 vao->NewArrays |= VERT_BIT_GENERIC(index);
762 }
763 }
764
765
766 void GLAPIENTRY
767 _mesa_EnableVertexAttribArray(GLuint index)
768 {
769 GET_CURRENT_CONTEXT(ctx);
770 enable_vertex_array_attrib(ctx, ctx->Array.VAO, index,
771 "glEnableVertexAttribArray");
772 }
773
774
775 void GLAPIENTRY
776 _mesa_EnableVertexArrayAttrib(GLuint vaobj, GLuint index)
777 {
778 GET_CURRENT_CONTEXT(ctx);
779 struct gl_vertex_array_object *vao;
780
781 /* The ARB_direct_state_access specification says:
782 *
783 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
784 * and DisableVertexArrayAttrib if <vaobj> is not
785 * [compatibility profile: zero or] the name of an existing vertex
786 * array object."
787 */
788 vao = _mesa_lookup_vao_err(ctx, vaobj, "glEnableVertexArrayAttrib");
789 if (!vao)
790 return;
791
792 enable_vertex_array_attrib(ctx, vao, index, "glEnableVertexArrayAttrib");
793 }
794
795
796 static void
797 disable_vertex_array_attrib(struct gl_context *ctx,
798 struct gl_vertex_array_object *vao,
799 GLuint index,
800 const char *func)
801 {
802 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
803 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
804 return;
805 }
806
807 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
808
809 if (vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
810 /* was enabled, now being disabled */
811 FLUSH_VERTICES(ctx, _NEW_ARRAY);
812 vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE;
813 vao->_Enabled &= ~VERT_BIT_GENERIC(index);
814 vao->NewArrays |= VERT_BIT_GENERIC(index);
815 }
816 }
817
818
819 void GLAPIENTRY
820 _mesa_DisableVertexAttribArray(GLuint index)
821 {
822 GET_CURRENT_CONTEXT(ctx);
823 disable_vertex_array_attrib(ctx, ctx->Array.VAO, index,
824 "glDisableVertexAttribArray");
825 }
826
827
828 void GLAPIENTRY
829 _mesa_DisableVertexArrayAttrib(GLuint vaobj, GLuint index)
830 {
831 GET_CURRENT_CONTEXT(ctx);
832 struct gl_vertex_array_object *vao;
833
834 /* The ARB_direct_state_access specification says:
835 *
836 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
837 * and DisableVertexArrayAttrib if <vaobj> is not
838 * [compatibility profile: zero or] the name of an existing vertex
839 * array object."
840 */
841 vao = _mesa_lookup_vao_err(ctx, vaobj, "glDisableVertexArrayAttrib");
842 if (!vao)
843 return;
844
845 disable_vertex_array_attrib(ctx, vao, index, "glDisableVertexArrayAttrib");
846 }
847
848
849 /**
850 * Return info for a vertex attribute array (no alias with legacy
851 * vertex attributes (pos, normal, color, etc)). This function does
852 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
853 */
854 static GLuint
855 get_vertex_array_attrib(struct gl_context *ctx,
856 const struct gl_vertex_array_object *vao,
857 GLuint index, GLenum pname,
858 const char *caller)
859 {
860 const struct gl_vertex_attrib_array *array;
861
862 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
863 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
864 return 0;
865 }
866
867 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
868
869 array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
870
871 switch (pname) {
872 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
873 return array->Enabled;
874 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
875 return (array->Format == GL_BGRA) ? GL_BGRA : array->Size;
876 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
877 return array->Stride;
878 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
879 return array->Type;
880 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
881 return array->Normalized;
882 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
883 return vao->VertexBinding[array->VertexBinding].BufferObj->Name;
884 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
885 if ((_mesa_is_desktop_gl(ctx)
886 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
887 || _mesa_is_gles3(ctx)) {
888 return array->Integer;
889 }
890 goto error;
891 case GL_VERTEX_ATTRIB_ARRAY_LONG:
892 if (_mesa_is_desktop_gl(ctx)) {
893 return array->Doubles;
894 }
895 goto error;
896 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
897 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
898 || _mesa_is_gles3(ctx)) {
899 return vao->VertexBinding[array->VertexBinding].InstanceDivisor;
900 }
901 goto error;
902 case GL_VERTEX_ATTRIB_BINDING:
903 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
904 return array->VertexBinding - VERT_ATTRIB_GENERIC0;
905 }
906 goto error;
907 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
908 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
909 return array->RelativeOffset;
910 }
911 goto error;
912 default:
913 ; /* fall-through */
914 }
915
916 error:
917 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
918 return 0;
919 }
920
921
922 static const GLfloat *
923 get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
924 {
925 if (index == 0) {
926 if (_mesa_attr_zero_aliases_vertex(ctx)) {
927 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
928 return NULL;
929 }
930 }
931 else if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
932 _mesa_error(ctx, GL_INVALID_VALUE,
933 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
934 return NULL;
935 }
936
937 assert(VERT_ATTRIB_GENERIC(index) <
938 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
939
940 FLUSH_CURRENT(ctx, 0);
941 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
942 }
943
944 void GLAPIENTRY
945 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
946 {
947 GET_CURRENT_CONTEXT(ctx);
948
949 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
950 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
951 if (v != NULL) {
952 COPY_4V(params, v);
953 }
954 }
955 else {
956 params[0] = (GLfloat) get_vertex_array_attrib(ctx, ctx->Array.VAO,
957 index, pname,
958 "glGetVertexAttribfv");
959 }
960 }
961
962
963 void GLAPIENTRY
964 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
965 {
966 GET_CURRENT_CONTEXT(ctx);
967
968 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
969 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
970 if (v != NULL) {
971 params[0] = (GLdouble) v[0];
972 params[1] = (GLdouble) v[1];
973 params[2] = (GLdouble) v[2];
974 params[3] = (GLdouble) v[3];
975 }
976 }
977 else {
978 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
979 index, pname,
980 "glGetVertexAttribdv");
981 }
982 }
983
984 void GLAPIENTRY
985 _mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params)
986 {
987 GET_CURRENT_CONTEXT(ctx);
988
989 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
990 const GLdouble *v =
991 (const GLdouble *)get_current_attrib(ctx, index,
992 "glGetVertexAttribLdv");
993 if (v != NULL) {
994 params[0] = v[0];
995 params[1] = v[1];
996 params[2] = v[2];
997 params[3] = v[3];
998 }
999 }
1000 else {
1001 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1002 index, pname,
1003 "glGetVertexAttribLdv");
1004 }
1005 }
1006
1007 void GLAPIENTRY
1008 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
1009 {
1010 GET_CURRENT_CONTEXT(ctx);
1011
1012 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1013 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
1014 if (v != NULL) {
1015 /* XXX should floats in[0,1] be scaled to full int range? */
1016 params[0] = (GLint) v[0];
1017 params[1] = (GLint) v[1];
1018 params[2] = (GLint) v[2];
1019 params[3] = (GLint) v[3];
1020 }
1021 }
1022 else {
1023 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1024 index, pname,
1025 "glGetVertexAttribiv");
1026 }
1027 }
1028
1029
1030 /** GL 3.0 */
1031 void GLAPIENTRY
1032 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
1033 {
1034 GET_CURRENT_CONTEXT(ctx);
1035
1036 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1037 const GLint *v = (const GLint *)
1038 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
1039 if (v != NULL) {
1040 COPY_4V(params, v);
1041 }
1042 }
1043 else {
1044 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1045 index, pname,
1046 "glGetVertexAttribIiv");
1047 }
1048 }
1049
1050
1051 /** GL 3.0 */
1052 void GLAPIENTRY
1053 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
1054 {
1055 GET_CURRENT_CONTEXT(ctx);
1056
1057 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1058 const GLuint *v = (const GLuint *)
1059 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
1060 if (v != NULL) {
1061 COPY_4V(params, v);
1062 }
1063 }
1064 else {
1065 params[0] = get_vertex_array_attrib(ctx, ctx->Array.VAO,
1066 index, pname,
1067 "glGetVertexAttribIuiv");
1068 }
1069 }
1070
1071
1072 void GLAPIENTRY
1073 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
1074 {
1075 GET_CURRENT_CONTEXT(ctx);
1076
1077 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1078 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
1079 return;
1080 }
1081
1082 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
1083 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
1084 return;
1085 }
1086
1087 assert(VERT_ATTRIB_GENERIC(index) <
1088 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1089
1090 *pointer = (GLvoid *)
1091 ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
1092 }
1093
1094
1095 /** ARB_direct_state_access */
1096 void GLAPIENTRY
1097 _mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index,
1098 GLenum pname, GLint *params)
1099 {
1100 GET_CURRENT_CONTEXT(ctx);
1101 struct gl_vertex_array_object *vao;
1102
1103 /* The ARB_direct_state_access specification says:
1104 *
1105 * "An INVALID_OPERATION error is generated if <vaobj> is not
1106 * [compatibility profile: zero or] the name of an existing
1107 * vertex array object."
1108 */
1109 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexediv");
1110 if (!vao)
1111 return;
1112
1113 /* The ARB_direct_state_access specification says:
1114 *
1115 * "For GetVertexArrayIndexediv, <pname> must be one of
1116 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1117 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1118 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1119 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1120 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1121 *
1122 * and:
1123 *
1124 * "Add GetVertexArrayIndexediv in 'Get Command' for
1125 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1126 * VERTEX_ATTRIB_BINDING,
1127 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1128 * VERTEX_BINDING_OFFSET, and
1129 * VERTEX_BINDING_STRIDE states"
1130 *
1131 * The only parameter name common to both lists is
1132 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1133 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1134 * pretty clear however that the intent is that it should be possible
1135 * to query all vertex attrib and binding states that can be set with
1136 * a DSA function.
1137 */
1138 switch (pname) {
1139 case GL_VERTEX_BINDING_OFFSET:
1140 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1141 break;
1142 case GL_VERTEX_BINDING_STRIDE:
1143 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Stride;
1144 break;
1145 case GL_VERTEX_BINDING_DIVISOR:
1146 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
1147 break;
1148 case GL_VERTEX_BINDING_BUFFER:
1149 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name;
1150 break;
1151 default:
1152 params[0] = get_vertex_array_attrib(ctx, vao, index, pname,
1153 "glGetVertexArrayIndexediv");
1154 break;
1155 }
1156 }
1157
1158
1159 void GLAPIENTRY
1160 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj, GLuint index,
1161 GLenum pname, GLint64 *params)
1162 {
1163 GET_CURRENT_CONTEXT(ctx);
1164 struct gl_vertex_array_object *vao;
1165
1166 /* The ARB_direct_state_access specification says:
1167 *
1168 * "An INVALID_OPERATION error is generated if <vaobj> is not
1169 * [compatibility profile: zero or] the name of an existing
1170 * vertex array object."
1171 */
1172 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexed64iv");
1173 if (!vao)
1174 return;
1175
1176 /* The ARB_direct_state_access specification says:
1177 *
1178 * "For GetVertexArrayIndexed64iv, <pname> must be
1179 * VERTEX_BINDING_OFFSET."
1180 *
1181 * and:
1182 *
1183 * "An INVALID_ENUM error is generated if <pname> is not one of
1184 * the valid values listed above for the corresponding command."
1185 */
1186 if (pname != GL_VERTEX_BINDING_OFFSET) {
1187 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayIndexed64iv("
1188 "pname != GL_VERTEX_BINDING_OFFSET)");
1189 return;
1190 }
1191
1192 /* The ARB_direct_state_access specification says:
1193 *
1194 * "An INVALID_VALUE error is generated if <index> is greater than
1195 * or equal to the value of MAX_VERTEX_ATTRIBS."
1196 *
1197 * Since the index refers to a buffer binding in this case, the intended
1198 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1199 * required to be the same, so in practice this doesn't matter.
1200 */
1201 if (index >= ctx->Const.MaxVertexAttribBindings) {
1202 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexArrayIndexed64iv(index"
1203 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1204 index, ctx->Const.MaxVertexAttribBindings);
1205 return;
1206 }
1207
1208 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1209 }
1210
1211
1212 void GLAPIENTRY
1213 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
1214 GLsizei count, const GLvoid *ptr)
1215 {
1216 (void) count;
1217 _mesa_VertexPointer(size, type, stride, ptr);
1218 }
1219
1220
1221 void GLAPIENTRY
1222 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1223 const GLvoid *ptr)
1224 {
1225 (void) count;
1226 _mesa_NormalPointer(type, stride, ptr);
1227 }
1228
1229
1230 void GLAPIENTRY
1231 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
1232 const GLvoid *ptr)
1233 {
1234 (void) count;
1235 _mesa_ColorPointer(size, type, stride, ptr);
1236 }
1237
1238
1239 void GLAPIENTRY
1240 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1241 const GLvoid *ptr)
1242 {
1243 (void) count;
1244 _mesa_IndexPointer(type, stride, ptr);
1245 }
1246
1247
1248 void GLAPIENTRY
1249 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
1250 GLsizei count, const GLvoid *ptr)
1251 {
1252 (void) count;
1253 _mesa_TexCoordPointer(size, type, stride, ptr);
1254 }
1255
1256
1257 void GLAPIENTRY
1258 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
1259 {
1260 (void) count;
1261 _mesa_EdgeFlagPointer(stride, ptr);
1262 }
1263
1264
1265 void GLAPIENTRY
1266 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
1267 {
1268 GET_CURRENT_CONTEXT(ctx);
1269 GLboolean tflag, cflag, nflag; /* enable/disable flags */
1270 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
1271 GLenum ctype = 0; /* color type */
1272 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
1273 const GLint toffset = 0; /* always zero */
1274 GLint defstride; /* default stride */
1275 GLint c, f;
1276
1277 FLUSH_VERTICES(ctx, 0);
1278
1279 f = sizeof(GLfloat);
1280 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
1281
1282 if (stride < 0) {
1283 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
1284 return;
1285 }
1286
1287 switch (format) {
1288 case GL_V2F:
1289 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1290 tcomps = 0; ccomps = 0; vcomps = 2;
1291 voffset = 0;
1292 defstride = 2*f;
1293 break;
1294 case GL_V3F:
1295 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1296 tcomps = 0; ccomps = 0; vcomps = 3;
1297 voffset = 0;
1298 defstride = 3*f;
1299 break;
1300 case GL_C4UB_V2F:
1301 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1302 tcomps = 0; ccomps = 4; vcomps = 2;
1303 ctype = GL_UNSIGNED_BYTE;
1304 coffset = 0;
1305 voffset = c;
1306 defstride = c + 2*f;
1307 break;
1308 case GL_C4UB_V3F:
1309 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1310 tcomps = 0; ccomps = 4; vcomps = 3;
1311 ctype = GL_UNSIGNED_BYTE;
1312 coffset = 0;
1313 voffset = c;
1314 defstride = c + 3*f;
1315 break;
1316 case GL_C3F_V3F:
1317 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1318 tcomps = 0; ccomps = 3; vcomps = 3;
1319 ctype = GL_FLOAT;
1320 coffset = 0;
1321 voffset = 3*f;
1322 defstride = 6*f;
1323 break;
1324 case GL_N3F_V3F:
1325 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1326 tcomps = 0; ccomps = 0; vcomps = 3;
1327 noffset = 0;
1328 voffset = 3*f;
1329 defstride = 6*f;
1330 break;
1331 case GL_C4F_N3F_V3F:
1332 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1333 tcomps = 0; ccomps = 4; vcomps = 3;
1334 ctype = GL_FLOAT;
1335 coffset = 0;
1336 noffset = 4*f;
1337 voffset = 7*f;
1338 defstride = 10*f;
1339 break;
1340 case GL_T2F_V3F:
1341 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1342 tcomps = 2; ccomps = 0; vcomps = 3;
1343 voffset = 2*f;
1344 defstride = 5*f;
1345 break;
1346 case GL_T4F_V4F:
1347 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1348 tcomps = 4; ccomps = 0; vcomps = 4;
1349 voffset = 4*f;
1350 defstride = 8*f;
1351 break;
1352 case GL_T2F_C4UB_V3F:
1353 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1354 tcomps = 2; ccomps = 4; vcomps = 3;
1355 ctype = GL_UNSIGNED_BYTE;
1356 coffset = 2*f;
1357 voffset = c+2*f;
1358 defstride = c+5*f;
1359 break;
1360 case GL_T2F_C3F_V3F:
1361 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1362 tcomps = 2; ccomps = 3; vcomps = 3;
1363 ctype = GL_FLOAT;
1364 coffset = 2*f;
1365 voffset = 5*f;
1366 defstride = 8*f;
1367 break;
1368 case GL_T2F_N3F_V3F:
1369 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1370 tcomps = 2; ccomps = 0; vcomps = 3;
1371 noffset = 2*f;
1372 voffset = 5*f;
1373 defstride = 8*f;
1374 break;
1375 case GL_T2F_C4F_N3F_V3F:
1376 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1377 tcomps = 2; ccomps = 4; vcomps = 3;
1378 ctype = GL_FLOAT;
1379 coffset = 2*f;
1380 noffset = 6*f;
1381 voffset = 9*f;
1382 defstride = 12*f;
1383 break;
1384 case GL_T4F_C4F_N3F_V4F:
1385 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1386 tcomps = 4; ccomps = 4; vcomps = 4;
1387 ctype = GL_FLOAT;
1388 coffset = 4*f;
1389 noffset = 8*f;
1390 voffset = 11*f;
1391 defstride = 15*f;
1392 break;
1393 default:
1394 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
1395 return;
1396 }
1397
1398 if (stride==0) {
1399 stride = defstride;
1400 }
1401
1402 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1403 _mesa_DisableClientState( GL_INDEX_ARRAY );
1404 /* XXX also disable secondary color and generic arrays? */
1405
1406 /* Texcoords */
1407 if (tflag) {
1408 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1409 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
1410 (GLubyte *) pointer + toffset );
1411 }
1412 else {
1413 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
1414 }
1415
1416 /* Color */
1417 if (cflag) {
1418 _mesa_EnableClientState( GL_COLOR_ARRAY );
1419 _mesa_ColorPointer( ccomps, ctype, stride,
1420 (GLubyte *) pointer + coffset );
1421 }
1422 else {
1423 _mesa_DisableClientState( GL_COLOR_ARRAY );
1424 }
1425
1426
1427 /* Normals */
1428 if (nflag) {
1429 _mesa_EnableClientState( GL_NORMAL_ARRAY );
1430 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
1431 }
1432 else {
1433 _mesa_DisableClientState( GL_NORMAL_ARRAY );
1434 }
1435
1436 /* Vertices */
1437 _mesa_EnableClientState( GL_VERTEX_ARRAY );
1438 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
1439 (GLubyte *) pointer + voffset );
1440 }
1441
1442
1443 void GLAPIENTRY
1444 _mesa_LockArraysEXT(GLint first, GLsizei count)
1445 {
1446 GET_CURRENT_CONTEXT(ctx);
1447
1448 FLUSH_VERTICES(ctx, 0);
1449
1450 if (MESA_VERBOSE & VERBOSE_API)
1451 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
1452
1453 if (first < 0) {
1454 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1455 return;
1456 }
1457 if (count <= 0) {
1458 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1459 return;
1460 }
1461 if (ctx->Array.LockCount != 0) {
1462 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1463 return;
1464 }
1465
1466 ctx->Array.LockFirst = first;
1467 ctx->Array.LockCount = count;
1468
1469 ctx->NewState |= _NEW_ARRAY;
1470 }
1471
1472
1473 void GLAPIENTRY
1474 _mesa_UnlockArraysEXT( void )
1475 {
1476 GET_CURRENT_CONTEXT(ctx);
1477
1478 FLUSH_VERTICES(ctx, 0);
1479
1480 if (MESA_VERBOSE & VERBOSE_API)
1481 _mesa_debug(ctx, "glUnlockArrays\n");
1482
1483 if (ctx->Array.LockCount == 0) {
1484 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1485 return;
1486 }
1487
1488 ctx->Array.LockFirst = 0;
1489 ctx->Array.LockCount = 0;
1490 ctx->NewState |= _NEW_ARRAY;
1491 }
1492
1493
1494 /* GL_EXT_multi_draw_arrays */
1495 void GLAPIENTRY
1496 _mesa_MultiDrawArrays( GLenum mode, const GLint *first,
1497 const GLsizei *count, GLsizei primcount )
1498 {
1499 GET_CURRENT_CONTEXT(ctx);
1500 GLint i;
1501
1502 FLUSH_VERTICES(ctx, 0);
1503
1504 for (i = 0; i < primcount; i++) {
1505 if (count[i] > 0) {
1506 CALL_DrawArrays(ctx->CurrentDispatch, (mode, first[i], count[i]));
1507 }
1508 }
1509 }
1510
1511
1512 /* GL_IBM_multimode_draw_arrays */
1513 void GLAPIENTRY
1514 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1515 const GLsizei * count,
1516 GLsizei primcount, GLint modestride )
1517 {
1518 GET_CURRENT_CONTEXT(ctx);
1519 GLint i;
1520
1521 FLUSH_VERTICES(ctx, 0);
1522
1523 for ( i = 0 ; i < primcount ; i++ ) {
1524 if ( count[i] > 0 ) {
1525 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1526 CALL_DrawArrays(ctx->CurrentDispatch, ( m, first[i], count[i] ));
1527 }
1528 }
1529 }
1530
1531
1532 /* GL_IBM_multimode_draw_arrays */
1533 void GLAPIENTRY
1534 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1535 GLenum type, const GLvoid * const * indices,
1536 GLsizei primcount, GLint modestride )
1537 {
1538 GET_CURRENT_CONTEXT(ctx);
1539 GLint i;
1540
1541 FLUSH_VERTICES(ctx, 0);
1542
1543 /* XXX not sure about ARB_vertex_buffer_object handling here */
1544
1545 for ( i = 0 ; i < primcount ; i++ ) {
1546 if ( count[i] > 0 ) {
1547 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1548 CALL_DrawElements(ctx->CurrentDispatch, ( m, count[i], type,
1549 indices[i] ));
1550 }
1551 }
1552 }
1553
1554
1555 /**
1556 * GL_NV_primitive_restart and GL 3.1
1557 */
1558 void GLAPIENTRY
1559 _mesa_PrimitiveRestartIndex(GLuint index)
1560 {
1561 GET_CURRENT_CONTEXT(ctx);
1562
1563 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
1564 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
1565 return;
1566 }
1567
1568 if (ctx->Array.RestartIndex != index) {
1569 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
1570 ctx->Array.RestartIndex = index;
1571 }
1572 }
1573
1574
1575 /**
1576 * See GL_ARB_instanced_arrays.
1577 * Note that the instance divisor only applies to generic arrays, not
1578 * the legacy vertex arrays.
1579 */
1580 void GLAPIENTRY
1581 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
1582 {
1583 GET_CURRENT_CONTEXT(ctx);
1584
1585 const GLuint genericIndex = VERT_ATTRIB_GENERIC(index);
1586 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
1587
1588 if (!ctx->Extensions.ARB_instanced_arrays) {
1589 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
1590 return;
1591 }
1592
1593 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1594 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribDivisor(index = %u)",
1595 index);
1596 return;
1597 }
1598
1599 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
1600
1601 /* The ARB_vertex_attrib_binding spec says:
1602 *
1603 * "The command
1604 *
1605 * void VertexAttribDivisor(uint index, uint divisor);
1606 *
1607 * is equivalent to (assuming no errors are generated):
1608 *
1609 * VertexAttribBinding(index, index);
1610 * VertexBindingDivisor(index, divisor);"
1611 */
1612 vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
1613 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
1614 }
1615
1616
1617 unsigned
1618 _mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type)
1619 {
1620 /* From the OpenGL 4.3 core specification, page 302:
1621 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1622 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1623 * is used."
1624 */
1625 if (ctx->Array.PrimitiveRestartFixedIndex) {
1626 switch (ib_type) {
1627 case GL_UNSIGNED_BYTE:
1628 return 0xff;
1629 case GL_UNSIGNED_SHORT:
1630 return 0xffff;
1631 case GL_UNSIGNED_INT:
1632 return 0xffffffff;
1633 default:
1634 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1635 }
1636 }
1637
1638 return ctx->Array.RestartIndex;
1639 }
1640
1641
1642 /**
1643 * GL_ARB_vertex_attrib_binding
1644 */
1645 static void
1646 vertex_array_vertex_buffer(struct gl_context *ctx,
1647 struct gl_vertex_array_object *vao,
1648 GLuint bindingIndex, GLuint buffer, GLintptr offset,
1649 GLsizei stride, const char *func)
1650 {
1651 struct gl_buffer_object *vbo;
1652
1653 ASSERT_OUTSIDE_BEGIN_END(ctx);
1654
1655 /* The ARB_vertex_attrib_binding spec says:
1656 *
1657 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1658 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1659 */
1660 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1661 _mesa_error(ctx, GL_INVALID_VALUE,
1662 "%s(bindingindex=%u > "
1663 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1664 func, bindingIndex);
1665 return;
1666 }
1667
1668 /* The ARB_vertex_attrib_binding spec says:
1669 *
1670 * "The error INVALID_VALUE is generated if <stride> or <offset>
1671 * are negative."
1672 */
1673 if (offset < 0) {
1674 _mesa_error(ctx, GL_INVALID_VALUE,
1675 "%s(offset=%" PRId64 " < 0)",
1676 func, (int64_t) offset);
1677 return;
1678 }
1679
1680 if (stride < 0) {
1681 _mesa_error(ctx, GL_INVALID_VALUE,
1682 "%s(stride=%d < 0)", func, stride);
1683 return;
1684 }
1685
1686 if (((ctx->API == API_OPENGL_CORE && ctx->Version >= 44) || _mesa_is_gles31(ctx)) &&
1687 stride > ctx->Const.MaxVertexAttribStride) {
1688 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
1689 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
1690 return;
1691 }
1692
1693 if (buffer ==
1694 vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) {
1695 vbo = vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
1696 } else if (buffer != 0) {
1697 vbo = _mesa_lookup_bufferobj(ctx, buffer);
1698
1699 /* From the GL_ARB_vertex_attrib_array spec:
1700 *
1701 * "[Core profile only:]
1702 * An INVALID_OPERATION error is generated if buffer is not zero or a
1703 * name returned from a previous call to GenBuffers, or if such a name
1704 * has since been deleted with DeleteBuffers.
1705 *
1706 * Otherwise, we fall back to the same compat profile behavior as other
1707 * object references (automatically gen it).
1708 */
1709 if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &vbo, func))
1710 return;
1711 } else {
1712 /* The ARB_vertex_attrib_binding spec says:
1713 *
1714 * "If <buffer> is zero, any buffer object attached to this
1715 * bindpoint is detached."
1716 */
1717 vbo = ctx->Shared->NullBufferObj;
1718 }
1719
1720 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex),
1721 vbo, offset, stride);
1722 }
1723
1724
1725 void GLAPIENTRY
1726 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
1727 GLsizei stride)
1728 {
1729 GET_CURRENT_CONTEXT(ctx);
1730
1731 /* The ARB_vertex_attrib_binding spec says:
1732 *
1733 * "An INVALID_OPERATION error is generated if no vertex array object
1734 * is bound."
1735 */
1736 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
1737 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1738 _mesa_error(ctx, GL_INVALID_OPERATION,
1739 "glBindVertexBuffer(No array object bound)");
1740 return;
1741 }
1742
1743 vertex_array_vertex_buffer(ctx, ctx->Array.VAO, bindingIndex,
1744 buffer, offset, stride, "glBindVertexBuffer");
1745 }
1746
1747
1748 void GLAPIENTRY
1749 _mesa_VertexArrayVertexBuffer(GLuint vaobj, GLuint bindingIndex, GLuint buffer,
1750 GLintptr offset, GLsizei stride)
1751 {
1752 GET_CURRENT_CONTEXT(ctx);
1753 struct gl_vertex_array_object *vao;
1754
1755 /* The ARB_direct_state_access specification says:
1756 *
1757 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1758 * if <vaobj> is not [compatibility profile: zero or] the name of an
1759 * existing vertex array object."
1760 */
1761 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffer");
1762 if (!vao)
1763 return;
1764
1765 vertex_array_vertex_buffer(ctx, vao, bindingIndex,
1766 buffer, offset, stride,
1767 "glVertexArrayVertexBuffer");
1768 }
1769
1770
1771 static void
1772 vertex_array_vertex_buffers(struct gl_context *ctx,
1773 struct gl_vertex_array_object *vao,
1774 GLuint first, GLsizei count, const GLuint *buffers,
1775 const GLintptr *offsets, const GLsizei *strides,
1776 const char *func)
1777 {
1778 GLuint i;
1779
1780 ASSERT_OUTSIDE_BEGIN_END(ctx);
1781
1782 /* The ARB_multi_bind spec says:
1783 *
1784 * "An INVALID_OPERATION error is generated if <first> + <count>
1785 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1786 */
1787 if (first + count > ctx->Const.MaxVertexAttribBindings) {
1788 _mesa_error(ctx, GL_INVALID_OPERATION,
1789 "%s(first=%u + count=%d > the value of "
1790 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1791 func, first, count, ctx->Const.MaxVertexAttribBindings);
1792 return;
1793 }
1794
1795 if (!buffers) {
1796 /**
1797 * The ARB_multi_bind spec says:
1798 *
1799 * "If <buffers> is NULL, each affected vertex buffer binding point
1800 * from <first> through <first>+<count>-1 will be reset to have no
1801 * bound buffer object. In this case, the offsets and strides
1802 * associated with the binding points are set to default values,
1803 * ignoring <offsets> and <strides>."
1804 */
1805 struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj;
1806
1807 for (i = 0; i < count; i++)
1808 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
1809 vbo, 0, 16);
1810
1811 return;
1812 }
1813
1814 /* Note that the error semantics for multi-bind commands differ from
1815 * those of other GL commands.
1816 *
1817 * The Issues section in the ARB_multi_bind spec says:
1818 *
1819 * "(11) Typically, OpenGL specifies that if an error is generated by
1820 * a command, that command has no effect. This is somewhat
1821 * unfortunate for multi-bind commands, because it would require
1822 * a first pass to scan the entire list of bound objects for
1823 * errors and then a second pass to actually perform the
1824 * bindings. Should we have different error semantics?
1825 *
1826 * RESOLVED: Yes. In this specification, when the parameters for
1827 * one of the <count> binding points are invalid, that binding
1828 * point is not updated and an error will be generated. However,
1829 * other binding points in the same command will be updated if
1830 * their parameters are valid and no other error occurs."
1831 */
1832
1833 _mesa_begin_bufferobj_lookups(ctx);
1834
1835 for (i = 0; i < count; i++) {
1836 struct gl_buffer_object *vbo;
1837
1838 /* The ARB_multi_bind spec says:
1839 *
1840 * "An INVALID_VALUE error is generated if any value in
1841 * <offsets> or <strides> is negative (per binding)."
1842 */
1843 if (offsets[i] < 0) {
1844 _mesa_error(ctx, GL_INVALID_VALUE,
1845 "%s(offsets[%u]=%" PRId64 " < 0)",
1846 func, i, (int64_t) offsets[i]);
1847 continue;
1848 }
1849
1850 if (strides[i] < 0) {
1851 _mesa_error(ctx, GL_INVALID_VALUE,
1852 "%s(strides[%u]=%d < 0)",
1853 func, i, strides[i]);
1854 continue;
1855 }
1856
1857 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
1858 strides[i] > ctx->Const.MaxVertexAttribStride) {
1859 _mesa_error(ctx, GL_INVALID_VALUE,
1860 "%s(strides[%u]=%d > "
1861 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, i, strides[i]);
1862 continue;
1863 }
1864
1865 if (buffers[i]) {
1866 struct gl_vertex_buffer_binding *binding =
1867 &vao->VertexBinding[VERT_ATTRIB_GENERIC(first + i)];
1868
1869 if (buffers[i] == binding->BufferObj->Name)
1870 vbo = binding->BufferObj;
1871 else
1872 vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, func);
1873
1874 if (!vbo)
1875 continue;
1876 } else {
1877 vbo = ctx->Shared->NullBufferObj;
1878 }
1879
1880 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
1881 vbo, offsets[i], strides[i]);
1882 }
1883
1884 _mesa_end_bufferobj_lookups(ctx);
1885 }
1886
1887
1888 void GLAPIENTRY
1889 _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
1890 const GLintptr *offsets, const GLsizei *strides)
1891 {
1892 GET_CURRENT_CONTEXT(ctx);
1893
1894 /* The ARB_vertex_attrib_binding spec says:
1895 *
1896 * "An INVALID_OPERATION error is generated if no
1897 * vertex array object is bound."
1898 */
1899 if (ctx->API == API_OPENGL_CORE &&
1900 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1901 _mesa_error(ctx, GL_INVALID_OPERATION,
1902 "glBindVertexBuffers(No array object bound)");
1903 return;
1904 }
1905
1906 vertex_array_vertex_buffers(ctx, ctx->Array.VAO, first, count,
1907 buffers, offsets, strides,
1908 "glBindVertexBuffers");
1909 }
1910
1911
1912 void GLAPIENTRY
1913 _mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count,
1914 const GLuint *buffers,
1915 const GLintptr *offsets, const GLsizei *strides)
1916 {
1917 GET_CURRENT_CONTEXT(ctx);
1918 struct gl_vertex_array_object *vao;
1919
1920 /* The ARB_direct_state_access specification says:
1921 *
1922 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1923 * if <vaobj> is not [compatibility profile: zero or] the name of an
1924 * existing vertex array object."
1925 */
1926 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffers");
1927 if (!vao)
1928 return;
1929
1930 vertex_array_vertex_buffers(ctx, vao, first, count,
1931 buffers, offsets, strides,
1932 "glVertexArrayVertexBuffers");
1933 }
1934
1935
1936 static void
1937 vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type,
1938 GLboolean normalized, GLboolean integer,
1939 GLboolean doubles, GLbitfield legalTypes,
1940 GLsizei maxSize, GLuint relativeOffset,
1941 const char *func)
1942 {
1943 GET_CURRENT_CONTEXT(ctx);
1944 ASSERT_OUTSIDE_BEGIN_END(ctx);
1945
1946 /* The ARB_vertex_attrib_binding spec says:
1947 *
1948 * "An INVALID_OPERATION error is generated under any of the following
1949 * conditions:
1950 * - if no vertex array object is currently bound (see section 2.10);
1951 * - ..."
1952 *
1953 * This error condition only applies to VertexAttribFormat and
1954 * VertexAttribIFormat in the extension spec, but we assume that this
1955 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
1956 * to all three functions.
1957 */
1958 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
1959 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1960 _mesa_error(ctx, GL_INVALID_OPERATION,
1961 "%s(No array object bound)", func);
1962 return;
1963 }
1964
1965 /* The ARB_vertex_attrib_binding spec says:
1966 *
1967 * "The error INVALID_VALUE is generated if index is greater than or equal
1968 * to the value of MAX_VERTEX_ATTRIBS."
1969 */
1970 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1971 _mesa_error(ctx, GL_INVALID_VALUE,
1972 "%s(attribindex=%u > "
1973 "GL_MAX_VERTEX_ATTRIBS)",
1974 func, attribIndex);
1975 return;
1976 }
1977
1978 FLUSH_VERTICES(ctx, 0);
1979
1980 update_array_format(ctx, func, ctx->Array.VAO,
1981 VERT_ATTRIB_GENERIC(attribIndex),
1982 legalTypes, 1, maxSize, size, type,
1983 normalized, integer, doubles, relativeOffset);
1984 }
1985
1986
1987 void GLAPIENTRY
1988 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
1989 GLboolean normalized, GLuint relativeOffset)
1990 {
1991 vertex_attrib_format(attribIndex, size, type, normalized,
1992 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
1993 BGRA_OR_4, relativeOffset,
1994 "glVertexAttribFormat");
1995 }
1996
1997
1998 void GLAPIENTRY
1999 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
2000 GLuint relativeOffset)
2001 {
2002 vertex_attrib_format(attribIndex, size, type, GL_FALSE,
2003 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK, 4,
2004 relativeOffset, "glVertexAttribIFormat");
2005 }
2006
2007
2008 void GLAPIENTRY
2009 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
2010 GLuint relativeOffset)
2011 {
2012 vertex_attrib_format(attribIndex, size, type, GL_FALSE, GL_FALSE,
2013 GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK, 4,
2014 relativeOffset, "glVertexAttribLFormat");
2015 }
2016
2017
2018 static void
2019 vertex_array_attrib_format(GLuint vaobj, GLuint attribIndex, GLint size,
2020 GLenum type, GLboolean normalized,
2021 GLboolean integer, GLboolean doubles,
2022 GLbitfield legalTypes, GLsizei maxSize,
2023 GLuint relativeOffset, const char *func)
2024 {
2025 GET_CURRENT_CONTEXT(ctx);
2026 struct gl_vertex_array_object *vao;
2027
2028 ASSERT_OUTSIDE_BEGIN_END(ctx);
2029
2030 /* The ARB_direct_state_access spec says:
2031 *
2032 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
2033 * if <vaobj> is not [compatibility profile: zero or] the name of an
2034 * existing vertex array object."
2035 */
2036 vao = _mesa_lookup_vao_err(ctx, vaobj, func);
2037 if (!vao)
2038 return;
2039
2040 /* The ARB_vertex_attrib_binding spec says:
2041 *
2042 * "The error INVALID_VALUE is generated if index is greater than or equal
2043 * to the value of MAX_VERTEX_ATTRIBS."
2044 */
2045 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2046 _mesa_error(ctx, GL_INVALID_VALUE,
2047 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2048 func, attribIndex);
2049 return;
2050 }
2051
2052 FLUSH_VERTICES(ctx, 0);
2053
2054 update_array_format(ctx, func, vao,
2055 VERT_ATTRIB_GENERIC(attribIndex),
2056 legalTypes, 1, maxSize, size, type, normalized,
2057 integer, doubles, relativeOffset);
2058 }
2059
2060
2061 void GLAPIENTRY
2062 _mesa_VertexArrayAttribFormat(GLuint vaobj, GLuint attribIndex, GLint size,
2063 GLenum type, GLboolean normalized,
2064 GLuint relativeOffset)
2065 {
2066 vertex_array_attrib_format(vaobj, attribIndex, size, type, normalized,
2067 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
2068 BGRA_OR_4, relativeOffset,
2069 "glVertexArrayAttribFormat");
2070 }
2071
2072
2073 void GLAPIENTRY
2074 _mesa_VertexArrayAttribIFormat(GLuint vaobj, GLuint attribIndex,
2075 GLint size, GLenum type,
2076 GLuint relativeOffset)
2077 {
2078 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2079 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK,
2080 4, relativeOffset,
2081 "glVertexArrayAttribIFormat");
2082 }
2083
2084
2085 void GLAPIENTRY
2086 _mesa_VertexArrayAttribLFormat(GLuint vaobj, GLuint attribIndex,
2087 GLint size, GLenum type,
2088 GLuint relativeOffset)
2089 {
2090 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2091 GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK,
2092 4, relativeOffset,
2093 "glVertexArrayAttribLFormat");
2094 }
2095
2096
2097 static void
2098 vertex_array_attrib_binding(struct gl_context *ctx,
2099 struct gl_vertex_array_object *vao,
2100 GLuint attribIndex, GLuint bindingIndex,
2101 const char *func)
2102 {
2103 ASSERT_OUTSIDE_BEGIN_END(ctx);
2104
2105 /* The ARB_vertex_attrib_binding spec says:
2106 *
2107 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2108 * <bindingindex> must be less than the value of
2109 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2110 * is generated."
2111 */
2112 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2113 _mesa_error(ctx, GL_INVALID_VALUE,
2114 "%s(attribindex=%u >= "
2115 "GL_MAX_VERTEX_ATTRIBS)",
2116 func, attribIndex);
2117 return;
2118 }
2119
2120 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2121 _mesa_error(ctx, GL_INVALID_VALUE,
2122 "%s(bindingindex=%u >= "
2123 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2124 func, bindingIndex);
2125 return;
2126 }
2127
2128 assert(VERT_ATTRIB_GENERIC(attribIndex) < ARRAY_SIZE(vao->VertexAttrib));
2129
2130 vertex_attrib_binding(ctx, vao,
2131 VERT_ATTRIB_GENERIC(attribIndex),
2132 VERT_ATTRIB_GENERIC(bindingIndex));
2133 }
2134
2135
2136 void GLAPIENTRY
2137 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
2138 {
2139 GET_CURRENT_CONTEXT(ctx);
2140
2141 /* The ARB_vertex_attrib_binding spec says:
2142 *
2143 * "An INVALID_OPERATION error is generated if no vertex array object
2144 * is bound."
2145 */
2146 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2147 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2148 _mesa_error(ctx, GL_INVALID_OPERATION,
2149 "glVertexAttribBinding(No array object bound)");
2150 return;
2151 }
2152
2153 vertex_array_attrib_binding(ctx, ctx->Array.VAO,
2154 attribIndex, bindingIndex,
2155 "glVertexAttribBinding");
2156 }
2157
2158
2159 void GLAPIENTRY
2160 _mesa_VertexArrayAttribBinding(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex)
2161 {
2162 GET_CURRENT_CONTEXT(ctx);
2163 struct gl_vertex_array_object *vao;
2164
2165 /* The ARB_direct_state_access specification says:
2166 *
2167 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2168 * if <vaobj> is not [compatibility profile: zero or] the name of an
2169 * existing vertex array object."
2170 */
2171 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayAttribBinding");
2172 if (!vao)
2173 return;
2174
2175 vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex,
2176 "glVertexArrayAttribBinding");
2177 }
2178
2179
2180 static void
2181 vertex_array_binding_divisor(struct gl_context *ctx,
2182 struct gl_vertex_array_object *vao,
2183 GLuint bindingIndex, GLuint divisor,
2184 const char *func)
2185 {
2186 ASSERT_OUTSIDE_BEGIN_END(ctx);
2187
2188 if (!ctx->Extensions.ARB_instanced_arrays) {
2189 _mesa_error(ctx, GL_INVALID_OPERATION, "%s()", func);
2190 return;
2191 }
2192
2193 /* The ARB_vertex_attrib_binding spec says:
2194 *
2195 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2196 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2197 */
2198 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2199 _mesa_error(ctx, GL_INVALID_VALUE,
2200 "%s(bindingindex=%u > "
2201 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2202 func, bindingIndex);
2203 return;
2204 }
2205
2206 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
2207 }
2208
2209
2210 void GLAPIENTRY
2211 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
2212 {
2213 GET_CURRENT_CONTEXT(ctx);
2214
2215 /* The ARB_vertex_attrib_binding spec says:
2216 *
2217 * "An INVALID_OPERATION error is generated if no vertex array object
2218 * is bound."
2219 */
2220 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2221 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2222 _mesa_error(ctx, GL_INVALID_OPERATION,
2223 "glVertexBindingDivisor(No array object bound)");
2224 return;
2225 }
2226
2227 vertex_array_binding_divisor(ctx, ctx->Array.VAO,
2228 bindingIndex, divisor,
2229 "glVertexBindingDivisor");
2230 }
2231
2232
2233 void GLAPIENTRY
2234 _mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex,
2235 GLuint divisor)
2236 {
2237 struct gl_vertex_array_object *vao;
2238 GET_CURRENT_CONTEXT(ctx);
2239
2240 /* The ARB_direct_state_access specification says:
2241 *
2242 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2243 * if <vaobj> is not [compatibility profile: zero or] the name of an
2244 * existing vertex array object."
2245 */
2246 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayBindingDivisor");
2247 if (!vao)
2248 return;
2249
2250 vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor,
2251 "glVertexArrayBindingDivisor");
2252 }
2253
2254
2255 /**
2256 * Copy one client vertex array to another.
2257 */
2258 void
2259 _mesa_copy_client_array(struct gl_context *ctx,
2260 struct gl_client_array *dst,
2261 struct gl_client_array *src)
2262 {
2263 dst->Size = src->Size;
2264 dst->Type = src->Type;
2265 dst->Format = src->Format;
2266 dst->Stride = src->Stride;
2267 dst->StrideB = src->StrideB;
2268 dst->Ptr = src->Ptr;
2269 dst->Enabled = src->Enabled;
2270 dst->Normalized = src->Normalized;
2271 dst->Integer = src->Integer;
2272 dst->Doubles = src->Doubles;
2273 dst->InstanceDivisor = src->InstanceDivisor;
2274 dst->_ElementSize = src->_ElementSize;
2275 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
2276 }
2277
2278 void
2279 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
2280 struct gl_vertex_attrib_array *dst,
2281 const struct gl_vertex_attrib_array *src)
2282 {
2283 dst->Size = src->Size;
2284 dst->Type = src->Type;
2285 dst->Format = src->Format;
2286 dst->VertexBinding = src->VertexBinding;
2287 dst->RelativeOffset = src->RelativeOffset;
2288 dst->Format = src->Format;
2289 dst->Integer = src->Integer;
2290 dst->Doubles = src->Doubles;
2291 dst->Normalized = src->Normalized;
2292 dst->Ptr = src->Ptr;
2293 dst->Enabled = src->Enabled;
2294 dst->_ElementSize = src->_ElementSize;
2295 }
2296
2297 void
2298 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
2299 struct gl_vertex_buffer_binding *dst,
2300 const struct gl_vertex_buffer_binding *src)
2301 {
2302 dst->Offset = src->Offset;
2303 dst->Stride = src->Stride;
2304 dst->InstanceDivisor = src->InstanceDivisor;
2305 dst->_BoundArrays = src->_BoundArrays;
2306
2307 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
2308 }
2309
2310 /**
2311 * Print vertex array's fields.
2312 */
2313 static void
2314 print_array(const char *name, GLint index, const struct gl_client_array *array)
2315 {
2316 if (index >= 0)
2317 fprintf(stderr, " %s[%d]: ", name, index);
2318 else
2319 fprintf(stderr, " %s: ", name);
2320 fprintf(stderr, "Ptr=%p, Type=%s, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
2321 array->Ptr, _mesa_enum_to_string(array->Type), array->Size,
2322 array->_ElementSize, array->StrideB, array->BufferObj->Name,
2323 (unsigned long) array->BufferObj->Size);
2324 }
2325
2326
2327 /**
2328 * Print current vertex object/array info. For debug.
2329 */
2330 void
2331 _mesa_print_arrays(struct gl_context *ctx)
2332 {
2333 struct gl_vertex_array_object *vao = ctx->Array.VAO;
2334 GLuint i;
2335
2336 printf("Array Object %u\n", vao->Name);
2337 if (vao->_VertexAttrib[VERT_ATTRIB_POS].Enabled)
2338 print_array("Vertex", -1, &vao->_VertexAttrib[VERT_ATTRIB_POS]);
2339 if (vao->_VertexAttrib[VERT_ATTRIB_NORMAL].Enabled)
2340 print_array("Normal", -1, &vao->_VertexAttrib[VERT_ATTRIB_NORMAL]);
2341 if (vao->_VertexAttrib[VERT_ATTRIB_COLOR0].Enabled)
2342 print_array("Color", -1, &vao->_VertexAttrib[VERT_ATTRIB_COLOR0]);
2343 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++)
2344 if (vao->_VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled)
2345 print_array("TexCoord", i, &vao->_VertexAttrib[VERT_ATTRIB_TEX(i)]);
2346 for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++)
2347 if (vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled)
2348 print_array("Attrib", i, &vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)]);
2349 }
2350
2351
2352 /**
2353 * Initialize vertex array state for given context.
2354 */
2355 void
2356 _mesa_init_varray(struct gl_context *ctx)
2357 {
2358 ctx->Array.DefaultVAO = _mesa_new_vao(ctx, 0);
2359 _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO);
2360 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
2361
2362 ctx->Array.Objects = _mesa_NewHashTable();
2363 }
2364
2365
2366 /**
2367 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2368 */
2369 static void
2370 delete_arrayobj_cb(GLuint id, void *data, void *userData)
2371 {
2372 struct gl_vertex_array_object *vao = (struct gl_vertex_array_object *) data;
2373 struct gl_context *ctx = (struct gl_context *) userData;
2374 _mesa_delete_vao(ctx, vao);
2375 }
2376
2377
2378 /**
2379 * Free vertex array state for given context.
2380 */
2381 void
2382 _mesa_free_varray_data(struct gl_context *ctx)
2383 {
2384 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
2385 _mesa_DeleteHashTable(ctx->Array.Objects);
2386 }