Merge ../mesa into vulkan
[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) || _mesa_is_gles31(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) || _mesa_is_gles31(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) <
937 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
938
939 FLUSH_CURRENT(ctx, 0);
940 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
941 }
942
943 void GLAPIENTRY
944 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
945 {
946 GET_CURRENT_CONTEXT(ctx);
947
948 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
949 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
950 if (v != NULL) {
951 COPY_4V(params, v);
952 }
953 }
954 else {
955 params[0] = (GLfloat) get_vertex_array_attrib(ctx, ctx->Array.VAO,
956 index, pname,
957 "glGetVertexAttribfv");
958 }
959 }
960
961
962 void GLAPIENTRY
963 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
964 {
965 GET_CURRENT_CONTEXT(ctx);
966
967 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
968 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
969 if (v != NULL) {
970 params[0] = (GLdouble) v[0];
971 params[1] = (GLdouble) v[1];
972 params[2] = (GLdouble) v[2];
973 params[3] = (GLdouble) v[3];
974 }
975 }
976 else {
977 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
978 index, pname,
979 "glGetVertexAttribdv");
980 }
981 }
982
983 void GLAPIENTRY
984 _mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params)
985 {
986 GET_CURRENT_CONTEXT(ctx);
987
988 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
989 const GLdouble *v =
990 (const GLdouble *)get_current_attrib(ctx, index,
991 "glGetVertexAttribLdv");
992 if (v != NULL) {
993 params[0] = v[0];
994 params[1] = v[1];
995 params[2] = v[2];
996 params[3] = v[3];
997 }
998 }
999 else {
1000 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1001 index, pname,
1002 "glGetVertexAttribLdv");
1003 }
1004 }
1005
1006 void GLAPIENTRY
1007 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
1008 {
1009 GET_CURRENT_CONTEXT(ctx);
1010
1011 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1012 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
1013 if (v != NULL) {
1014 /* XXX should floats in[0,1] be scaled to full int range? */
1015 params[0] = (GLint) v[0];
1016 params[1] = (GLint) v[1];
1017 params[2] = (GLint) v[2];
1018 params[3] = (GLint) v[3];
1019 }
1020 }
1021 else {
1022 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1023 index, pname,
1024 "glGetVertexAttribiv");
1025 }
1026 }
1027
1028
1029 /** GL 3.0 */
1030 void GLAPIENTRY
1031 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
1032 {
1033 GET_CURRENT_CONTEXT(ctx);
1034
1035 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1036 const GLint *v = (const GLint *)
1037 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
1038 if (v != NULL) {
1039 COPY_4V(params, v);
1040 }
1041 }
1042 else {
1043 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1044 index, pname,
1045 "glGetVertexAttribIiv");
1046 }
1047 }
1048
1049
1050 /** GL 3.0 */
1051 void GLAPIENTRY
1052 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
1053 {
1054 GET_CURRENT_CONTEXT(ctx);
1055
1056 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1057 const GLuint *v = (const GLuint *)
1058 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
1059 if (v != NULL) {
1060 COPY_4V(params, v);
1061 }
1062 }
1063 else {
1064 params[0] = get_vertex_array_attrib(ctx, ctx->Array.VAO,
1065 index, pname,
1066 "glGetVertexAttribIuiv");
1067 }
1068 }
1069
1070
1071 void GLAPIENTRY
1072 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
1073 {
1074 GET_CURRENT_CONTEXT(ctx);
1075
1076 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1077 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
1078 return;
1079 }
1080
1081 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
1082 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
1083 return;
1084 }
1085
1086 assert(VERT_ATTRIB_GENERIC(index) <
1087 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1088
1089 *pointer = (GLvoid *)
1090 ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
1091 }
1092
1093
1094 /** ARB_direct_state_access */
1095 void GLAPIENTRY
1096 _mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index,
1097 GLenum pname, GLint *params)
1098 {
1099 GET_CURRENT_CONTEXT(ctx);
1100 struct gl_vertex_array_object *vao;
1101
1102 /* The ARB_direct_state_access specification says:
1103 *
1104 * "An INVALID_OPERATION error is generated if <vaobj> is not
1105 * [compatibility profile: zero or] the name of an existing
1106 * vertex array object."
1107 */
1108 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexediv");
1109 if (!vao)
1110 return;
1111
1112 /* The ARB_direct_state_access specification says:
1113 *
1114 * "For GetVertexArrayIndexediv, <pname> must be one of
1115 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1116 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1117 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1118 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1119 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1120 *
1121 * and:
1122 *
1123 * "Add GetVertexArrayIndexediv in 'Get Command' for
1124 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1125 * VERTEX_ATTRIB_BINDING,
1126 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1127 * VERTEX_BINDING_OFFSET, and
1128 * VERTEX_BINDING_STRIDE states"
1129 *
1130 * The only parameter name common to both lists is
1131 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1132 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1133 * pretty clear however that the intent is that it should be possible
1134 * to query all vertex attrib and binding states that can be set with
1135 * a DSA function.
1136 */
1137 switch (pname) {
1138 case GL_VERTEX_BINDING_OFFSET:
1139 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1140 break;
1141 case GL_VERTEX_BINDING_STRIDE:
1142 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Stride;
1143 break;
1144 case GL_VERTEX_BINDING_DIVISOR:
1145 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
1146 break;
1147 case GL_VERTEX_BINDING_BUFFER:
1148 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name;
1149 break;
1150 default:
1151 params[0] = get_vertex_array_attrib(ctx, vao, index, pname,
1152 "glGetVertexArrayIndexediv");
1153 break;
1154 }
1155 }
1156
1157
1158 void GLAPIENTRY
1159 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj, GLuint index,
1160 GLenum pname, GLint64 *params)
1161 {
1162 GET_CURRENT_CONTEXT(ctx);
1163 struct gl_vertex_array_object *vao;
1164
1165 /* The ARB_direct_state_access specification says:
1166 *
1167 * "An INVALID_OPERATION error is generated if <vaobj> is not
1168 * [compatibility profile: zero or] the name of an existing
1169 * vertex array object."
1170 */
1171 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexed64iv");
1172 if (!vao)
1173 return;
1174
1175 /* The ARB_direct_state_access specification says:
1176 *
1177 * "For GetVertexArrayIndexed64iv, <pname> must be
1178 * VERTEX_BINDING_OFFSET."
1179 *
1180 * and:
1181 *
1182 * "An INVALID_ENUM error is generated if <pname> is not one of
1183 * the valid values listed above for the corresponding command."
1184 */
1185 if (pname != GL_VERTEX_BINDING_OFFSET) {
1186 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayIndexed64iv("
1187 "pname != GL_VERTEX_BINDING_OFFSET)");
1188 return;
1189 }
1190
1191 /* The ARB_direct_state_access specification says:
1192 *
1193 * "An INVALID_VALUE error is generated if <index> is greater than
1194 * or equal to the value of MAX_VERTEX_ATTRIBS."
1195 *
1196 * Since the index refers to a buffer binding in this case, the intended
1197 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1198 * required to be the same, so in practice this doesn't matter.
1199 */
1200 if (index >= ctx->Const.MaxVertexAttribBindings) {
1201 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexArrayIndexed64iv(index"
1202 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1203 index, ctx->Const.MaxVertexAttribBindings);
1204 return;
1205 }
1206
1207 params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1208 }
1209
1210
1211 void GLAPIENTRY
1212 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
1213 GLsizei count, const GLvoid *ptr)
1214 {
1215 (void) count;
1216 _mesa_VertexPointer(size, type, stride, ptr);
1217 }
1218
1219
1220 void GLAPIENTRY
1221 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1222 const GLvoid *ptr)
1223 {
1224 (void) count;
1225 _mesa_NormalPointer(type, stride, ptr);
1226 }
1227
1228
1229 void GLAPIENTRY
1230 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
1231 const GLvoid *ptr)
1232 {
1233 (void) count;
1234 _mesa_ColorPointer(size, type, stride, ptr);
1235 }
1236
1237
1238 void GLAPIENTRY
1239 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1240 const GLvoid *ptr)
1241 {
1242 (void) count;
1243 _mesa_IndexPointer(type, stride, ptr);
1244 }
1245
1246
1247 void GLAPIENTRY
1248 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
1249 GLsizei count, const GLvoid *ptr)
1250 {
1251 (void) count;
1252 _mesa_TexCoordPointer(size, type, stride, ptr);
1253 }
1254
1255
1256 void GLAPIENTRY
1257 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
1258 {
1259 (void) count;
1260 _mesa_EdgeFlagPointer(stride, ptr);
1261 }
1262
1263
1264 void GLAPIENTRY
1265 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
1266 {
1267 GET_CURRENT_CONTEXT(ctx);
1268 GLboolean tflag, cflag, nflag; /* enable/disable flags */
1269 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
1270 GLenum ctype = 0; /* color type */
1271 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
1272 const GLint toffset = 0; /* always zero */
1273 GLint defstride; /* default stride */
1274 GLint c, f;
1275
1276 FLUSH_VERTICES(ctx, 0);
1277
1278 f = sizeof(GLfloat);
1279 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
1280
1281 if (stride < 0) {
1282 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
1283 return;
1284 }
1285
1286 switch (format) {
1287 case GL_V2F:
1288 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1289 tcomps = 0; ccomps = 0; vcomps = 2;
1290 voffset = 0;
1291 defstride = 2*f;
1292 break;
1293 case GL_V3F:
1294 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1295 tcomps = 0; ccomps = 0; vcomps = 3;
1296 voffset = 0;
1297 defstride = 3*f;
1298 break;
1299 case GL_C4UB_V2F:
1300 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1301 tcomps = 0; ccomps = 4; vcomps = 2;
1302 ctype = GL_UNSIGNED_BYTE;
1303 coffset = 0;
1304 voffset = c;
1305 defstride = c + 2*f;
1306 break;
1307 case GL_C4UB_V3F:
1308 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1309 tcomps = 0; ccomps = 4; vcomps = 3;
1310 ctype = GL_UNSIGNED_BYTE;
1311 coffset = 0;
1312 voffset = c;
1313 defstride = c + 3*f;
1314 break;
1315 case GL_C3F_V3F:
1316 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1317 tcomps = 0; ccomps = 3; vcomps = 3;
1318 ctype = GL_FLOAT;
1319 coffset = 0;
1320 voffset = 3*f;
1321 defstride = 6*f;
1322 break;
1323 case GL_N3F_V3F:
1324 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1325 tcomps = 0; ccomps = 0; vcomps = 3;
1326 noffset = 0;
1327 voffset = 3*f;
1328 defstride = 6*f;
1329 break;
1330 case GL_C4F_N3F_V3F:
1331 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1332 tcomps = 0; ccomps = 4; vcomps = 3;
1333 ctype = GL_FLOAT;
1334 coffset = 0;
1335 noffset = 4*f;
1336 voffset = 7*f;
1337 defstride = 10*f;
1338 break;
1339 case GL_T2F_V3F:
1340 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1341 tcomps = 2; ccomps = 0; vcomps = 3;
1342 voffset = 2*f;
1343 defstride = 5*f;
1344 break;
1345 case GL_T4F_V4F:
1346 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1347 tcomps = 4; ccomps = 0; vcomps = 4;
1348 voffset = 4*f;
1349 defstride = 8*f;
1350 break;
1351 case GL_T2F_C4UB_V3F:
1352 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1353 tcomps = 2; ccomps = 4; vcomps = 3;
1354 ctype = GL_UNSIGNED_BYTE;
1355 coffset = 2*f;
1356 voffset = c+2*f;
1357 defstride = c+5*f;
1358 break;
1359 case GL_T2F_C3F_V3F:
1360 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1361 tcomps = 2; ccomps = 3; vcomps = 3;
1362 ctype = GL_FLOAT;
1363 coffset = 2*f;
1364 voffset = 5*f;
1365 defstride = 8*f;
1366 break;
1367 case GL_T2F_N3F_V3F:
1368 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1369 tcomps = 2; ccomps = 0; vcomps = 3;
1370 noffset = 2*f;
1371 voffset = 5*f;
1372 defstride = 8*f;
1373 break;
1374 case GL_T2F_C4F_N3F_V3F:
1375 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1376 tcomps = 2; ccomps = 4; vcomps = 3;
1377 ctype = GL_FLOAT;
1378 coffset = 2*f;
1379 noffset = 6*f;
1380 voffset = 9*f;
1381 defstride = 12*f;
1382 break;
1383 case GL_T4F_C4F_N3F_V4F:
1384 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1385 tcomps = 4; ccomps = 4; vcomps = 4;
1386 ctype = GL_FLOAT;
1387 coffset = 4*f;
1388 noffset = 8*f;
1389 voffset = 11*f;
1390 defstride = 15*f;
1391 break;
1392 default:
1393 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
1394 return;
1395 }
1396
1397 if (stride==0) {
1398 stride = defstride;
1399 }
1400
1401 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1402 _mesa_DisableClientState( GL_INDEX_ARRAY );
1403 /* XXX also disable secondary color and generic arrays? */
1404
1405 /* Texcoords */
1406 if (tflag) {
1407 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1408 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
1409 (GLubyte *) pointer + toffset );
1410 }
1411 else {
1412 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
1413 }
1414
1415 /* Color */
1416 if (cflag) {
1417 _mesa_EnableClientState( GL_COLOR_ARRAY );
1418 _mesa_ColorPointer( ccomps, ctype, stride,
1419 (GLubyte *) pointer + coffset );
1420 }
1421 else {
1422 _mesa_DisableClientState( GL_COLOR_ARRAY );
1423 }
1424
1425
1426 /* Normals */
1427 if (nflag) {
1428 _mesa_EnableClientState( GL_NORMAL_ARRAY );
1429 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
1430 }
1431 else {
1432 _mesa_DisableClientState( GL_NORMAL_ARRAY );
1433 }
1434
1435 /* Vertices */
1436 _mesa_EnableClientState( GL_VERTEX_ARRAY );
1437 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
1438 (GLubyte *) pointer + voffset );
1439 }
1440
1441
1442 void GLAPIENTRY
1443 _mesa_LockArraysEXT(GLint first, GLsizei count)
1444 {
1445 GET_CURRENT_CONTEXT(ctx);
1446
1447 FLUSH_VERTICES(ctx, 0);
1448
1449 if (MESA_VERBOSE & VERBOSE_API)
1450 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
1451
1452 if (first < 0) {
1453 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1454 return;
1455 }
1456 if (count <= 0) {
1457 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1458 return;
1459 }
1460 if (ctx->Array.LockCount != 0) {
1461 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1462 return;
1463 }
1464
1465 ctx->Array.LockFirst = first;
1466 ctx->Array.LockCount = count;
1467
1468 ctx->NewState |= _NEW_ARRAY;
1469 }
1470
1471
1472 void GLAPIENTRY
1473 _mesa_UnlockArraysEXT( void )
1474 {
1475 GET_CURRENT_CONTEXT(ctx);
1476
1477 FLUSH_VERTICES(ctx, 0);
1478
1479 if (MESA_VERBOSE & VERBOSE_API)
1480 _mesa_debug(ctx, "glUnlockArrays\n");
1481
1482 if (ctx->Array.LockCount == 0) {
1483 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1484 return;
1485 }
1486
1487 ctx->Array.LockFirst = 0;
1488 ctx->Array.LockCount = 0;
1489 ctx->NewState |= _NEW_ARRAY;
1490 }
1491
1492
1493 /* GL_EXT_multi_draw_arrays */
1494 void GLAPIENTRY
1495 _mesa_MultiDrawArrays( GLenum mode, const GLint *first,
1496 const GLsizei *count, GLsizei primcount )
1497 {
1498 GET_CURRENT_CONTEXT(ctx);
1499 GLint i;
1500
1501 FLUSH_VERTICES(ctx, 0);
1502
1503 for (i = 0; i < primcount; i++) {
1504 if (count[i] > 0) {
1505 CALL_DrawArrays(ctx->CurrentDispatch, (mode, first[i], count[i]));
1506 }
1507 }
1508 }
1509
1510
1511 /* GL_IBM_multimode_draw_arrays */
1512 void GLAPIENTRY
1513 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1514 const GLsizei * count,
1515 GLsizei primcount, GLint modestride )
1516 {
1517 GET_CURRENT_CONTEXT(ctx);
1518 GLint i;
1519
1520 FLUSH_VERTICES(ctx, 0);
1521
1522 for ( i = 0 ; i < primcount ; i++ ) {
1523 if ( count[i] > 0 ) {
1524 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1525 CALL_DrawArrays(ctx->CurrentDispatch, ( m, first[i], count[i] ));
1526 }
1527 }
1528 }
1529
1530
1531 /* GL_IBM_multimode_draw_arrays */
1532 void GLAPIENTRY
1533 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1534 GLenum type, const GLvoid * const * indices,
1535 GLsizei primcount, GLint modestride )
1536 {
1537 GET_CURRENT_CONTEXT(ctx);
1538 GLint i;
1539
1540 FLUSH_VERTICES(ctx, 0);
1541
1542 /* XXX not sure about ARB_vertex_buffer_object handling here */
1543
1544 for ( i = 0 ; i < primcount ; i++ ) {
1545 if ( count[i] > 0 ) {
1546 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1547 CALL_DrawElements(ctx->CurrentDispatch, ( m, count[i], type,
1548 indices[i] ));
1549 }
1550 }
1551 }
1552
1553
1554 /**
1555 * GL_NV_primitive_restart and GL 3.1
1556 */
1557 void GLAPIENTRY
1558 _mesa_PrimitiveRestartIndex(GLuint index)
1559 {
1560 GET_CURRENT_CONTEXT(ctx);
1561
1562 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
1563 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
1564 return;
1565 }
1566
1567 if (ctx->Array.RestartIndex != index) {
1568 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
1569 ctx->Array.RestartIndex = index;
1570 }
1571 }
1572
1573
1574 /**
1575 * See GL_ARB_instanced_arrays.
1576 * Note that the instance divisor only applies to generic arrays, not
1577 * the legacy vertex arrays.
1578 */
1579 void GLAPIENTRY
1580 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
1581 {
1582 GET_CURRENT_CONTEXT(ctx);
1583
1584 const GLuint genericIndex = VERT_ATTRIB_GENERIC(index);
1585 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
1586
1587 if (!ctx->Extensions.ARB_instanced_arrays) {
1588 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
1589 return;
1590 }
1591
1592 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1593 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribDivisor(index = %u)",
1594 index);
1595 return;
1596 }
1597
1598 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
1599
1600 /* The ARB_vertex_attrib_binding spec says:
1601 *
1602 * "The command
1603 *
1604 * void VertexAttribDivisor(uint index, uint divisor);
1605 *
1606 * is equivalent to (assuming no errors are generated):
1607 *
1608 * VertexAttribBinding(index, index);
1609 * VertexBindingDivisor(index, divisor);"
1610 */
1611 vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
1612 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
1613 }
1614
1615
1616 unsigned
1617 _mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type)
1618 {
1619 /* From the OpenGL 4.3 core specification, page 302:
1620 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1621 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1622 * is used."
1623 */
1624 if (ctx->Array.PrimitiveRestartFixedIndex) {
1625 switch (ib_type) {
1626 case GL_UNSIGNED_BYTE:
1627 return 0xff;
1628 case GL_UNSIGNED_SHORT:
1629 return 0xffff;
1630 case GL_UNSIGNED_INT:
1631 return 0xffffffff;
1632 default:
1633 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1634 }
1635 }
1636
1637 return ctx->Array.RestartIndex;
1638 }
1639
1640
1641 /**
1642 * GL_ARB_vertex_attrib_binding
1643 */
1644 static void
1645 vertex_array_vertex_buffer(struct gl_context *ctx,
1646 struct gl_vertex_array_object *vao,
1647 GLuint bindingIndex, GLuint buffer, GLintptr offset,
1648 GLsizei stride, const char *func)
1649 {
1650 struct gl_buffer_object *vbo;
1651
1652 ASSERT_OUTSIDE_BEGIN_END(ctx);
1653
1654 /* The ARB_vertex_attrib_binding spec says:
1655 *
1656 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1657 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1658 */
1659 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1660 _mesa_error(ctx, GL_INVALID_VALUE,
1661 "%s(bindingindex=%u > "
1662 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1663 func, bindingIndex);
1664 return;
1665 }
1666
1667 /* The ARB_vertex_attrib_binding spec says:
1668 *
1669 * "The error INVALID_VALUE is generated if <stride> or <offset>
1670 * are negative."
1671 */
1672 if (offset < 0) {
1673 _mesa_error(ctx, GL_INVALID_VALUE,
1674 "%s(offset=%" PRId64 " < 0)",
1675 func, (int64_t) offset);
1676 return;
1677 }
1678
1679 if (stride < 0) {
1680 _mesa_error(ctx, GL_INVALID_VALUE,
1681 "%s(stride=%d < 0)", func, stride);
1682 return;
1683 }
1684
1685 if (((ctx->API == API_OPENGL_CORE && ctx->Version >= 44) || _mesa_is_gles31(ctx)) &&
1686 stride > ctx->Const.MaxVertexAttribStride) {
1687 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
1688 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
1689 return;
1690 }
1691
1692 if (buffer ==
1693 vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) {
1694 vbo = vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
1695 } else if (buffer != 0) {
1696 vbo = _mesa_lookup_bufferobj(ctx, buffer);
1697
1698 /* From the GL_ARB_vertex_attrib_array spec:
1699 *
1700 * "[Core profile only:]
1701 * An INVALID_OPERATION error is generated if buffer is not zero or a
1702 * name returned from a previous call to GenBuffers, or if such a name
1703 * has since been deleted with DeleteBuffers.
1704 *
1705 * Otherwise, we fall back to the same compat profile behavior as other
1706 * object references (automatically gen it).
1707 */
1708 if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &vbo, func))
1709 return;
1710 } else {
1711 /* The ARB_vertex_attrib_binding spec says:
1712 *
1713 * "If <buffer> is zero, any buffer object attached to this
1714 * bindpoint is detached."
1715 */
1716 vbo = ctx->Shared->NullBufferObj;
1717 }
1718
1719 bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex),
1720 vbo, offset, stride);
1721 }
1722
1723
1724 void GLAPIENTRY
1725 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
1726 GLsizei stride)
1727 {
1728 GET_CURRENT_CONTEXT(ctx);
1729
1730 /* The ARB_vertex_attrib_binding spec says:
1731 *
1732 * "An INVALID_OPERATION error is generated if no vertex array object
1733 * is bound."
1734 */
1735 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
1736 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1737 _mesa_error(ctx, GL_INVALID_OPERATION,
1738 "glBindVertexBuffer(No array object bound)");
1739 return;
1740 }
1741
1742 vertex_array_vertex_buffer(ctx, ctx->Array.VAO, bindingIndex,
1743 buffer, offset, stride, "glBindVertexBuffer");
1744 }
1745
1746
1747 void GLAPIENTRY
1748 _mesa_VertexArrayVertexBuffer(GLuint vaobj, GLuint bindingIndex, GLuint buffer,
1749 GLintptr offset, GLsizei stride)
1750 {
1751 GET_CURRENT_CONTEXT(ctx);
1752 struct gl_vertex_array_object *vao;
1753
1754 /* The ARB_direct_state_access specification says:
1755 *
1756 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1757 * if <vaobj> is not [compatibility profile: zero or] the name of an
1758 * existing vertex array object."
1759 */
1760 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffer");
1761 if (!vao)
1762 return;
1763
1764 vertex_array_vertex_buffer(ctx, vao, bindingIndex,
1765 buffer, offset, stride,
1766 "glVertexArrayVertexBuffer");
1767 }
1768
1769
1770 static void
1771 vertex_array_vertex_buffers(struct gl_context *ctx,
1772 struct gl_vertex_array_object *vao,
1773 GLuint first, GLsizei count, const GLuint *buffers,
1774 const GLintptr *offsets, const GLsizei *strides,
1775 const char *func)
1776 {
1777 GLuint i;
1778
1779 ASSERT_OUTSIDE_BEGIN_END(ctx);
1780
1781 /* The ARB_multi_bind spec says:
1782 *
1783 * "An INVALID_OPERATION error is generated if <first> + <count>
1784 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1785 */
1786 if (first + count > ctx->Const.MaxVertexAttribBindings) {
1787 _mesa_error(ctx, GL_INVALID_OPERATION,
1788 "%s(first=%u + count=%d > the value of "
1789 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1790 func, first, count, ctx->Const.MaxVertexAttribBindings);
1791 return;
1792 }
1793
1794 if (!buffers) {
1795 /**
1796 * The ARB_multi_bind spec says:
1797 *
1798 * "If <buffers> is NULL, each affected vertex buffer binding point
1799 * from <first> through <first>+<count>-1 will be reset to have no
1800 * bound buffer object. In this case, the offsets and strides
1801 * associated with the binding points are set to default values,
1802 * ignoring <offsets> and <strides>."
1803 */
1804 struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj;
1805
1806 for (i = 0; i < count; i++)
1807 bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
1808 vbo, 0, 16);
1809
1810 return;
1811 }
1812
1813 /* Note that the error semantics for multi-bind commands differ from
1814 * those of other GL commands.
1815 *
1816 * The Issues section in the ARB_multi_bind spec says:
1817 *
1818 * "(11) Typically, OpenGL specifies that if an error is generated by
1819 * a command, that command has no effect. This is somewhat
1820 * unfortunate for multi-bind commands, because it would require
1821 * a first pass to scan the entire list of bound objects for
1822 * errors and then a second pass to actually perform the
1823 * bindings. Should we have different error semantics?
1824 *
1825 * RESOLVED: Yes. In this specification, when the parameters for
1826 * one of the <count> binding points are invalid, that binding
1827 * point is not updated and an error will be generated. However,
1828 * other binding points in the same command will be updated if
1829 * their parameters are valid and no other error occurs."
1830 */
1831
1832 _mesa_begin_bufferobj_lookups(ctx);
1833
1834 for (i = 0; i < count; i++) {
1835 struct gl_buffer_object *vbo;
1836
1837 /* The ARB_multi_bind spec says:
1838 *
1839 * "An INVALID_VALUE error is generated if any value in
1840 * <offsets> or <strides> is negative (per binding)."
1841 */
1842 if (offsets[i] < 0) {
1843 _mesa_error(ctx, GL_INVALID_VALUE,
1844 "%s(offsets[%u]=%" PRId64 " < 0)",
1845 func, i, (int64_t) offsets[i]);
1846 continue;
1847 }
1848
1849 if (strides[i] < 0) {
1850 _mesa_error(ctx, GL_INVALID_VALUE,
1851 "%s(strides[%u]=%d < 0)",
1852 func, i, strides[i]);
1853 continue;
1854 }
1855
1856 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
1857 strides[i] > ctx->Const.MaxVertexAttribStride) {
1858 _mesa_error(ctx, GL_INVALID_VALUE,
1859 "%s(strides[%u]=%d > "
1860 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, i, strides[i]);
1861 continue;
1862 }
1863
1864 if (buffers[i]) {
1865 struct gl_vertex_buffer_binding *binding =
1866 &vao->VertexBinding[VERT_ATTRIB_GENERIC(first + i)];
1867
1868 if (buffers[i] == binding->BufferObj->Name)
1869 vbo = binding->BufferObj;
1870 else
1871 vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, func);
1872
1873 if (!vbo)
1874 continue;
1875 } else {
1876 vbo = ctx->Shared->NullBufferObj;
1877 }
1878
1879 bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
1880 vbo, offsets[i], strides[i]);
1881 }
1882
1883 _mesa_end_bufferobj_lookups(ctx);
1884 }
1885
1886
1887 void GLAPIENTRY
1888 _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
1889 const GLintptr *offsets, const GLsizei *strides)
1890 {
1891 GET_CURRENT_CONTEXT(ctx);
1892
1893 /* The ARB_vertex_attrib_binding spec says:
1894 *
1895 * "An INVALID_OPERATION error is generated if no
1896 * vertex array object is bound."
1897 */
1898 if (ctx->API == API_OPENGL_CORE &&
1899 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1900 _mesa_error(ctx, GL_INVALID_OPERATION,
1901 "glBindVertexBuffers(No array object bound)");
1902 return;
1903 }
1904
1905 vertex_array_vertex_buffers(ctx, ctx->Array.VAO, first, count,
1906 buffers, offsets, strides,
1907 "glBindVertexBuffers");
1908 }
1909
1910
1911 void GLAPIENTRY
1912 _mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count,
1913 const GLuint *buffers,
1914 const GLintptr *offsets, const GLsizei *strides)
1915 {
1916 GET_CURRENT_CONTEXT(ctx);
1917 struct gl_vertex_array_object *vao;
1918
1919 /* The ARB_direct_state_access specification says:
1920 *
1921 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1922 * if <vaobj> is not [compatibility profile: zero or] the name of an
1923 * existing vertex array object."
1924 */
1925 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffers");
1926 if (!vao)
1927 return;
1928
1929 vertex_array_vertex_buffers(ctx, vao, first, count,
1930 buffers, offsets, strides,
1931 "glVertexArrayVertexBuffers");
1932 }
1933
1934
1935 static void
1936 vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type,
1937 GLboolean normalized, GLboolean integer,
1938 GLboolean doubles, GLbitfield legalTypes,
1939 GLsizei maxSize, GLuint relativeOffset,
1940 const char *func)
1941 {
1942 GET_CURRENT_CONTEXT(ctx);
1943 ASSERT_OUTSIDE_BEGIN_END(ctx);
1944
1945 /* The ARB_vertex_attrib_binding spec says:
1946 *
1947 * "An INVALID_OPERATION error is generated under any of the following
1948 * conditions:
1949 * - if no vertex array object is currently bound (see section 2.10);
1950 * - ..."
1951 *
1952 * This error condition only applies to VertexAttribFormat and
1953 * VertexAttribIFormat in the extension spec, but we assume that this
1954 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
1955 * to all three functions.
1956 */
1957 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
1958 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1959 _mesa_error(ctx, GL_INVALID_OPERATION,
1960 "%s(No array object bound)", func);
1961 return;
1962 }
1963
1964 /* The ARB_vertex_attrib_binding spec says:
1965 *
1966 * "The error INVALID_VALUE is generated if index is greater than or equal
1967 * to the value of MAX_VERTEX_ATTRIBS."
1968 */
1969 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1970 _mesa_error(ctx, GL_INVALID_VALUE,
1971 "%s(attribindex=%u > "
1972 "GL_MAX_VERTEX_ATTRIBS)",
1973 func, attribIndex);
1974 return;
1975 }
1976
1977 FLUSH_VERTICES(ctx, 0);
1978
1979 update_array_format(ctx, func, ctx->Array.VAO,
1980 VERT_ATTRIB_GENERIC(attribIndex),
1981 legalTypes, 1, maxSize, size, type,
1982 normalized, integer, doubles, relativeOffset);
1983 }
1984
1985
1986 void GLAPIENTRY
1987 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
1988 GLboolean normalized, GLuint relativeOffset)
1989 {
1990 vertex_attrib_format(attribIndex, size, type, normalized,
1991 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
1992 BGRA_OR_4, relativeOffset,
1993 "glVertexAttribFormat");
1994 }
1995
1996
1997 void GLAPIENTRY
1998 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
1999 GLuint relativeOffset)
2000 {
2001 vertex_attrib_format(attribIndex, size, type, GL_FALSE,
2002 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK, 4,
2003 relativeOffset, "glVertexAttribIFormat");
2004 }
2005
2006
2007 void GLAPIENTRY
2008 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
2009 GLuint relativeOffset)
2010 {
2011 vertex_attrib_format(attribIndex, size, type, GL_FALSE, GL_FALSE,
2012 GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK, 4,
2013 relativeOffset, "glVertexAttribLFormat");
2014 }
2015
2016
2017 static void
2018 vertex_array_attrib_format(GLuint vaobj, GLuint attribIndex, GLint size,
2019 GLenum type, GLboolean normalized,
2020 GLboolean integer, GLboolean doubles,
2021 GLbitfield legalTypes, GLsizei maxSize,
2022 GLuint relativeOffset, const char *func)
2023 {
2024 GET_CURRENT_CONTEXT(ctx);
2025 struct gl_vertex_array_object *vao;
2026
2027 ASSERT_OUTSIDE_BEGIN_END(ctx);
2028
2029 /* The ARB_direct_state_access spec says:
2030 *
2031 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
2032 * if <vaobj> is not [compatibility profile: zero or] the name of an
2033 * existing vertex array object."
2034 */
2035 vao = _mesa_lookup_vao_err(ctx, vaobj, func);
2036 if (!vao)
2037 return;
2038
2039 /* The ARB_vertex_attrib_binding spec says:
2040 *
2041 * "The error INVALID_VALUE is generated if index is greater than or equal
2042 * to the value of MAX_VERTEX_ATTRIBS."
2043 */
2044 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2045 _mesa_error(ctx, GL_INVALID_VALUE,
2046 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2047 func, attribIndex);
2048 return;
2049 }
2050
2051 FLUSH_VERTICES(ctx, 0);
2052
2053 update_array_format(ctx, func, vao,
2054 VERT_ATTRIB_GENERIC(attribIndex),
2055 legalTypes, 1, maxSize, size, type, normalized,
2056 integer, doubles, relativeOffset);
2057 }
2058
2059
2060 void GLAPIENTRY
2061 _mesa_VertexArrayAttribFormat(GLuint vaobj, GLuint attribIndex, GLint size,
2062 GLenum type, GLboolean normalized,
2063 GLuint relativeOffset)
2064 {
2065 vertex_array_attrib_format(vaobj, attribIndex, size, type, normalized,
2066 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
2067 BGRA_OR_4, relativeOffset,
2068 "glVertexArrayAttribFormat");
2069 }
2070
2071
2072 void GLAPIENTRY
2073 _mesa_VertexArrayAttribIFormat(GLuint vaobj, GLuint attribIndex,
2074 GLint size, GLenum type,
2075 GLuint relativeOffset)
2076 {
2077 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2078 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK,
2079 4, relativeOffset,
2080 "glVertexArrayAttribIFormat");
2081 }
2082
2083
2084 void GLAPIENTRY
2085 _mesa_VertexArrayAttribLFormat(GLuint vaobj, GLuint attribIndex,
2086 GLint size, GLenum type,
2087 GLuint relativeOffset)
2088 {
2089 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2090 GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK,
2091 4, relativeOffset,
2092 "glVertexArrayAttribLFormat");
2093 }
2094
2095
2096 static void
2097 vertex_array_attrib_binding(struct gl_context *ctx,
2098 struct gl_vertex_array_object *vao,
2099 GLuint attribIndex, GLuint bindingIndex,
2100 const char *func)
2101 {
2102 ASSERT_OUTSIDE_BEGIN_END(ctx);
2103
2104 /* The ARB_vertex_attrib_binding spec says:
2105 *
2106 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2107 * <bindingindex> must be less than the value of
2108 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2109 * is generated."
2110 */
2111 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2112 _mesa_error(ctx, GL_INVALID_VALUE,
2113 "%s(attribindex=%u >= "
2114 "GL_MAX_VERTEX_ATTRIBS)",
2115 func, attribIndex);
2116 return;
2117 }
2118
2119 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2120 _mesa_error(ctx, GL_INVALID_VALUE,
2121 "%s(bindingindex=%u >= "
2122 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2123 func, bindingIndex);
2124 return;
2125 }
2126
2127 assert(VERT_ATTRIB_GENERIC(attribIndex) < ARRAY_SIZE(vao->VertexAttrib));
2128
2129 vertex_attrib_binding(ctx, vao,
2130 VERT_ATTRIB_GENERIC(attribIndex),
2131 VERT_ATTRIB_GENERIC(bindingIndex));
2132 }
2133
2134
2135 void GLAPIENTRY
2136 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
2137 {
2138 GET_CURRENT_CONTEXT(ctx);
2139
2140 /* The ARB_vertex_attrib_binding spec says:
2141 *
2142 * "An INVALID_OPERATION error is generated if no vertex array object
2143 * is bound."
2144 */
2145 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2146 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2147 _mesa_error(ctx, GL_INVALID_OPERATION,
2148 "glVertexAttribBinding(No array object bound)");
2149 return;
2150 }
2151
2152 vertex_array_attrib_binding(ctx, ctx->Array.VAO,
2153 attribIndex, bindingIndex,
2154 "glVertexAttribBinding");
2155 }
2156
2157
2158 void GLAPIENTRY
2159 _mesa_VertexArrayAttribBinding(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex)
2160 {
2161 GET_CURRENT_CONTEXT(ctx);
2162 struct gl_vertex_array_object *vao;
2163
2164 /* The ARB_direct_state_access specification says:
2165 *
2166 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2167 * if <vaobj> is not [compatibility profile: zero or] the name of an
2168 * existing vertex array object."
2169 */
2170 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayAttribBinding");
2171 if (!vao)
2172 return;
2173
2174 vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex,
2175 "glVertexArrayAttribBinding");
2176 }
2177
2178
2179 static void
2180 vertex_array_binding_divisor(struct gl_context *ctx,
2181 struct gl_vertex_array_object *vao,
2182 GLuint bindingIndex, GLuint divisor,
2183 const char *func)
2184 {
2185 ASSERT_OUTSIDE_BEGIN_END(ctx);
2186
2187 if (!ctx->Extensions.ARB_instanced_arrays) {
2188 _mesa_error(ctx, GL_INVALID_OPERATION, "%s()", func);
2189 return;
2190 }
2191
2192 /* The ARB_vertex_attrib_binding spec says:
2193 *
2194 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2195 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2196 */
2197 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2198 _mesa_error(ctx, GL_INVALID_VALUE,
2199 "%s(bindingindex=%u > "
2200 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2201 func, bindingIndex);
2202 return;
2203 }
2204
2205 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
2206 }
2207
2208
2209 void GLAPIENTRY
2210 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
2211 {
2212 GET_CURRENT_CONTEXT(ctx);
2213
2214 /* The ARB_vertex_attrib_binding spec says:
2215 *
2216 * "An INVALID_OPERATION error is generated if no vertex array object
2217 * is bound."
2218 */
2219 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2220 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2221 _mesa_error(ctx, GL_INVALID_OPERATION,
2222 "glVertexBindingDivisor(No array object bound)");
2223 return;
2224 }
2225
2226 vertex_array_binding_divisor(ctx, ctx->Array.VAO,
2227 bindingIndex, divisor,
2228 "glVertexBindingDivisor");
2229 }
2230
2231
2232 void GLAPIENTRY
2233 _mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex,
2234 GLuint divisor)
2235 {
2236 struct gl_vertex_array_object *vao;
2237 GET_CURRENT_CONTEXT(ctx);
2238
2239 /* The ARB_direct_state_access specification says:
2240 *
2241 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2242 * if <vaobj> is not [compatibility profile: zero or] the name of an
2243 * existing vertex array object."
2244 */
2245 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayBindingDivisor");
2246 if (!vao)
2247 return;
2248
2249 vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor,
2250 "glVertexArrayBindingDivisor");
2251 }
2252
2253
2254 /**
2255 * Copy one client vertex array to another.
2256 */
2257 void
2258 _mesa_copy_client_array(struct gl_context *ctx,
2259 struct gl_client_array *dst,
2260 struct gl_client_array *src)
2261 {
2262 dst->Size = src->Size;
2263 dst->Type = src->Type;
2264 dst->Format = src->Format;
2265 dst->Stride = src->Stride;
2266 dst->StrideB = src->StrideB;
2267 dst->Ptr = src->Ptr;
2268 dst->Enabled = src->Enabled;
2269 dst->Normalized = src->Normalized;
2270 dst->Integer = src->Integer;
2271 dst->Doubles = src->Doubles;
2272 dst->InstanceDivisor = src->InstanceDivisor;
2273 dst->_ElementSize = src->_ElementSize;
2274 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
2275 }
2276
2277 void
2278 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
2279 struct gl_vertex_attrib_array *dst,
2280 const struct gl_vertex_attrib_array *src)
2281 {
2282 dst->Size = src->Size;
2283 dst->Type = src->Type;
2284 dst->Format = src->Format;
2285 dst->VertexBinding = src->VertexBinding;
2286 dst->RelativeOffset = src->RelativeOffset;
2287 dst->Format = src->Format;
2288 dst->Integer = src->Integer;
2289 dst->Doubles = src->Doubles;
2290 dst->Normalized = src->Normalized;
2291 dst->Ptr = src->Ptr;
2292 dst->Enabled = src->Enabled;
2293 dst->_ElementSize = src->_ElementSize;
2294 }
2295
2296 void
2297 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
2298 struct gl_vertex_buffer_binding *dst,
2299 const struct gl_vertex_buffer_binding *src)
2300 {
2301 dst->Offset = src->Offset;
2302 dst->Stride = src->Stride;
2303 dst->InstanceDivisor = src->InstanceDivisor;
2304 dst->_BoundArrays = src->_BoundArrays;
2305
2306 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
2307 }
2308
2309 /**
2310 * Print vertex array's fields.
2311 */
2312 static void
2313 print_array(const char *name, GLint index, const struct gl_client_array *array)
2314 {
2315 if (index >= 0)
2316 fprintf(stderr, " %s[%d]: ", name, index);
2317 else
2318 fprintf(stderr, " %s: ", name);
2319 fprintf(stderr, "Ptr=%p, Type=%s, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
2320 array->Ptr, _mesa_enum_to_string(array->Type), array->Size,
2321 array->_ElementSize, array->StrideB, array->BufferObj->Name,
2322 (unsigned long) array->BufferObj->Size);
2323 }
2324
2325
2326 /**
2327 * Print current vertex object/array info. For debug.
2328 */
2329 void
2330 _mesa_print_arrays(struct gl_context *ctx)
2331 {
2332 struct gl_vertex_array_object *vao = ctx->Array.VAO;
2333 GLuint i;
2334
2335 printf("Array Object %u\n", vao->Name);
2336 if (vao->_VertexAttrib[VERT_ATTRIB_POS].Enabled)
2337 print_array("Vertex", -1, &vao->_VertexAttrib[VERT_ATTRIB_POS]);
2338 if (vao->_VertexAttrib[VERT_ATTRIB_NORMAL].Enabled)
2339 print_array("Normal", -1, &vao->_VertexAttrib[VERT_ATTRIB_NORMAL]);
2340 if (vao->_VertexAttrib[VERT_ATTRIB_COLOR0].Enabled)
2341 print_array("Color", -1, &vao->_VertexAttrib[VERT_ATTRIB_COLOR0]);
2342 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++)
2343 if (vao->_VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled)
2344 print_array("TexCoord", i, &vao->_VertexAttrib[VERT_ATTRIB_TEX(i)]);
2345 for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++)
2346 if (vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled)
2347 print_array("Attrib", i, &vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)]);
2348 }
2349
2350
2351 /**
2352 * Initialize vertex array state for given context.
2353 */
2354 void
2355 _mesa_init_varray(struct gl_context *ctx)
2356 {
2357 ctx->Array.DefaultVAO = _mesa_new_vao(ctx, 0);
2358 _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO);
2359 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
2360
2361 ctx->Array.Objects = _mesa_NewHashTable();
2362 }
2363
2364
2365 /**
2366 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2367 */
2368 static void
2369 delete_arrayobj_cb(GLuint id, void *data, void *userData)
2370 {
2371 struct gl_vertex_array_object *vao = (struct gl_vertex_array_object *) data;
2372 struct gl_context *ctx = (struct gl_context *) userData;
2373 _mesa_delete_vao(ctx, vao);
2374 }
2375
2376
2377 /**
2378 * Free vertex array state for given context.
2379 */
2380 void
2381 _mesa_free_varray_data(struct gl_context *ctx)
2382 {
2383 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
2384 _mesa_DeleteHashTable(ctx->Array.Objects);
2385 }