mesa: pass vao as a function paramter
[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 "glformats.h"
37 #include "hash.h"
38 #include "image.h"
39 #include "macros.h"
40 #include "mtypes.h"
41 #include "varray.h"
42 #include "arrayobj.h"
43 #include "main/dispatch.h"
44
45
46 /** Used to do error checking for GL_EXT_vertex_array_bgra */
47 #define BGRA_OR_4 5
48
49
50 /** Used to indicate which GL datatypes are accepted by each of the
51 * glVertex/Color/Attrib/EtcPointer() functions.
52 */
53 #define BOOL_BIT (1 << 0)
54 #define BYTE_BIT (1 << 1)
55 #define UNSIGNED_BYTE_BIT (1 << 2)
56 #define SHORT_BIT (1 << 3)
57 #define UNSIGNED_SHORT_BIT (1 << 4)
58 #define INT_BIT (1 << 5)
59 #define UNSIGNED_INT_BIT (1 << 6)
60 #define HALF_BIT (1 << 7)
61 #define FLOAT_BIT (1 << 8)
62 #define DOUBLE_BIT (1 << 9)
63 #define FIXED_ES_BIT (1 << 10)
64 #define FIXED_GL_BIT (1 << 11)
65 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
66 #define INT_2_10_10_10_REV_BIT (1 << 13)
67 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
68 #define ALL_TYPE_BITS ((1 << 15) - 1)
69
70 #define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
71 SHORT_BIT | UNSIGNED_SHORT_BIT | \
72 INT_BIT | UNSIGNED_INT_BIT | \
73 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
74 FIXED_GL_BIT | \
75 UNSIGNED_INT_2_10_10_10_REV_BIT | \
76 INT_2_10_10_10_REV_BIT | \
77 UNSIGNED_INT_10F_11F_11F_REV_BIT)
78
79 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
80 SHORT_BIT | UNSIGNED_SHORT_BIT | \
81 INT_BIT | UNSIGNED_INT_BIT)
82
83 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
84
85
86 /** Convert GL datatype enum into a <type>_BIT value seen above */
87 static GLbitfield
88 type_to_bit(const struct gl_context *ctx, GLenum type)
89 {
90 switch (type) {
91 case GL_BOOL:
92 return BOOL_BIT;
93 case GL_BYTE:
94 return BYTE_BIT;
95 case GL_UNSIGNED_BYTE:
96 return UNSIGNED_BYTE_BIT;
97 case GL_SHORT:
98 return SHORT_BIT;
99 case GL_UNSIGNED_SHORT:
100 return UNSIGNED_SHORT_BIT;
101 case GL_INT:
102 return INT_BIT;
103 case GL_UNSIGNED_INT:
104 return UNSIGNED_INT_BIT;
105 case GL_HALF_FLOAT:
106 case GL_HALF_FLOAT_OES:
107 if (ctx->Extensions.ARB_half_float_vertex)
108 return HALF_BIT;
109 else
110 return 0x0;
111 case GL_FLOAT:
112 return FLOAT_BIT;
113 case GL_DOUBLE:
114 return DOUBLE_BIT;
115 case GL_FIXED:
116 return _mesa_is_desktop_gl(ctx) ? FIXED_GL_BIT : FIXED_ES_BIT;
117 case GL_UNSIGNED_INT_2_10_10_10_REV:
118 return UNSIGNED_INT_2_10_10_10_REV_BIT;
119 case GL_INT_2_10_10_10_REV:
120 return INT_2_10_10_10_REV_BIT;
121 case GL_UNSIGNED_INT_10F_11F_11F_REV:
122 return UNSIGNED_INT_10F_11F_11F_REV_BIT;
123 default:
124 return 0;
125 }
126 }
127
128
129 /**
130 * Depending on the position and generic0 attributes enable flags select
131 * the one that is used for both attributes.
132 * The generic0 attribute takes precedence.
133 */
134 static inline void
135 update_attribute_map_mode(const struct gl_context *ctx,
136 struct gl_vertex_array_object *vao)
137 {
138 /*
139 * There is no need to change the mapping away from the
140 * identity mapping if we are not in compat mode.
141 */
142 if (ctx->API != API_OPENGL_COMPAT)
143 return;
144 /* The generic0 attribute superseeds the position attribute */
145 const GLbitfield enabled = vao->Enabled;
146 if (enabled & VERT_BIT_GENERIC0)
147 vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_GENERIC0;
148 else if (enabled & VERT_BIT_POS)
149 vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_POSITION;
150 else
151 vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_IDENTITY;
152 }
153
154
155 /**
156 * Sets the BufferBindingIndex field for the vertex attribute given by
157 * attribIndex.
158 */
159 void
160 _mesa_vertex_attrib_binding(struct gl_context *ctx,
161 struct gl_vertex_array_object *vao,
162 gl_vert_attrib attribIndex,
163 GLuint bindingIndex)
164 {
165 struct gl_array_attributes *array = &vao->VertexAttrib[attribIndex];
166 assert(!vao->SharedAndImmutable);
167
168 if (array->BufferBindingIndex != bindingIndex) {
169 const GLbitfield array_bit = VERT_BIT(attribIndex);
170
171 if (_mesa_is_bufferobj(vao->BufferBinding[bindingIndex].BufferObj))
172 vao->VertexAttribBufferMask |= array_bit;
173 else
174 vao->VertexAttribBufferMask &= ~array_bit;
175
176 vao->BufferBinding[array->BufferBindingIndex]._BoundArrays &= ~array_bit;
177 vao->BufferBinding[bindingIndex]._BoundArrays |= array_bit;
178
179 array->BufferBindingIndex = bindingIndex;
180
181 vao->NewArrays |= vao->Enabled & array_bit;
182 }
183 }
184
185
186 /**
187 * Binds a buffer object to the vertex buffer binding point given by index,
188 * and sets the Offset and Stride fields.
189 */
190 void
191 _mesa_bind_vertex_buffer(struct gl_context *ctx,
192 struct gl_vertex_array_object *vao,
193 GLuint index,
194 struct gl_buffer_object *vbo,
195 GLintptr offset, GLsizei stride)
196 {
197 assert(index < ARRAY_SIZE(vao->BufferBinding));
198 assert(!vao->SharedAndImmutable);
199 struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index];
200
201 if (binding->BufferObj != vbo ||
202 binding->Offset != offset ||
203 binding->Stride != stride) {
204
205 _mesa_reference_buffer_object(ctx, &binding->BufferObj, vbo);
206
207 binding->Offset = offset;
208 binding->Stride = stride;
209
210 if (!_mesa_is_bufferobj(vbo)) {
211 vao->VertexAttribBufferMask &= ~binding->_BoundArrays;
212 } else {
213 vao->VertexAttribBufferMask |= binding->_BoundArrays;
214 vbo->UsageHistory |= USAGE_ARRAY_BUFFER;
215 }
216
217 vao->NewArrays |= vao->Enabled & binding->_BoundArrays;
218 }
219 }
220
221
222 /**
223 * Sets the InstanceDivisor field in the vertex buffer binding point
224 * given by bindingIndex.
225 */
226 static void
227 vertex_binding_divisor(struct gl_context *ctx,
228 struct gl_vertex_array_object *vao,
229 GLuint bindingIndex,
230 GLuint divisor)
231 {
232 struct gl_vertex_buffer_binding *binding =
233 &vao->BufferBinding[bindingIndex];
234 assert(!vao->SharedAndImmutable);
235
236 if (binding->InstanceDivisor != divisor) {
237 binding->InstanceDivisor = divisor;
238 vao->NewArrays |= vao->Enabled & binding->_BoundArrays;
239 }
240 }
241
242
243 void
244 _mesa_set_vertex_format(struct gl_vertex_format *vertex_format,
245 GLubyte size, GLenum16 type, GLenum16 format,
246 GLboolean normalized, GLboolean integer,
247 GLboolean doubles)
248 {
249 assert(size <= 4);
250 vertex_format->Type = type;
251 vertex_format->Format = format;
252 vertex_format->Size = size;
253 vertex_format->Normalized = normalized;
254 vertex_format->Integer = integer;
255 vertex_format->Doubles = doubles;
256 vertex_format->_ElementSize = _mesa_bytes_per_vertex_attrib(size, type);
257 assert(vertex_format->_ElementSize <= 4*sizeof(double));
258 }
259
260
261 /**
262 * Examine the API profile and extensions to determine which types are legal
263 * for vertex arrays. This is called once from update_array_format().
264 */
265 static GLbitfield
266 get_legal_types_mask(const struct gl_context *ctx)
267 {
268 GLbitfield legalTypesMask = ALL_TYPE_BITS;
269
270 if (_mesa_is_gles(ctx)) {
271 legalTypesMask &= ~(FIXED_GL_BIT |
272 DOUBLE_BIT |
273 UNSIGNED_INT_10F_11F_11F_REV_BIT);
274
275 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
276 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
277 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
278 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
279 * quite as trivial as we'd like because it uses a different enum value
280 * for GL_HALF_FLOAT_OES.
281 */
282 if (ctx->Version < 30) {
283 legalTypesMask &= ~(UNSIGNED_INT_BIT |
284 INT_BIT |
285 UNSIGNED_INT_2_10_10_10_REV_BIT |
286 INT_2_10_10_10_REV_BIT);
287
288 if (!_mesa_has_OES_vertex_half_float(ctx))
289 legalTypesMask &= ~HALF_BIT;
290 }
291 }
292 else {
293 legalTypesMask &= ~FIXED_ES_BIT;
294
295 if (!ctx->Extensions.ARB_ES2_compatibility)
296 legalTypesMask &= ~FIXED_GL_BIT;
297
298 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
299 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
300 INT_2_10_10_10_REV_BIT);
301
302 if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev)
303 legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT;
304 }
305
306 return legalTypesMask;
307 }
308
309 static GLenum
310 get_array_format(const struct gl_context *ctx, GLint sizeMax, GLint *size)
311 {
312 GLenum format = GL_RGBA;
313
314 /* Do size parameter checking.
315 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
316 * must be handled specially.
317 */
318 if (ctx->Extensions.EXT_vertex_array_bgra && sizeMax == BGRA_OR_4 &&
319 *size == GL_BGRA) {
320 format = GL_BGRA;
321 *size = 4;
322 }
323
324 return format;
325 }
326
327
328 /**
329 * \param attrib The index of the attribute array
330 * \param size Components per element (1, 2, 3 or 4)
331 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
332 * \param format Either GL_RGBA or GL_BGRA.
333 * \param normalized Whether integer types are converted to floats in [-1, 1]
334 * \param integer Integer-valued values (will not be normalized to [-1, 1])
335 * \param doubles Double values not reduced to floats
336 * \param relativeOffset Offset of the first element relative to the binding
337 * offset.
338 */
339 void
340 _mesa_update_array_format(struct gl_context *ctx,
341 struct gl_vertex_array_object *vao,
342 gl_vert_attrib attrib, GLint size, GLenum type,
343 GLenum format, GLboolean normalized,
344 GLboolean integer, GLboolean doubles,
345 GLuint relativeOffset)
346 {
347 struct gl_array_attributes *const array = &vao->VertexAttrib[attrib];
348
349 assert(!vao->SharedAndImmutable);
350 assert(size <= 4);
351
352 array->RelativeOffset = relativeOffset;
353 _mesa_set_vertex_format(&array->Format, size, type, format,
354 normalized, integer, doubles);
355
356 vao->NewArrays |= vao->Enabled & VERT_BIT(attrib);
357 }
358
359 /**
360 * Does error checking of the format in an attrib array.
361 *
362 * Called by *Pointer() and VertexAttrib*Format().
363 *
364 * \param func Name of calling function used for error reporting
365 * \param attrib The index of the attribute array
366 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
367 * \param sizeMin Min allowable size value
368 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
369 * \param size Components per element (1, 2, 3 or 4)
370 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
371 * \param normalized Whether integer types are converted to floats in [-1, 1]
372 * \param integer Integer-valued values (will not be normalized to [-1, 1])
373 * \param doubles Double values not reduced to floats
374 * \param relativeOffset Offset of the first element relative to the binding offset.
375 * \return bool True if validation is successful, False otherwise.
376 */
377 static bool
378 validate_array_format(struct gl_context *ctx, const char *func,
379 struct gl_vertex_array_object *vao,
380 GLuint attrib, GLbitfield legalTypesMask,
381 GLint sizeMin, GLint sizeMax,
382 GLint size, GLenum type, GLboolean normalized,
383 GLboolean integer, GLboolean doubles,
384 GLuint relativeOffset, GLenum format)
385 {
386 GLbitfield typeBit;
387
388 /* at most, one of these bools can be true */
389 assert((int) normalized + (int) integer + (int) doubles <= 1);
390
391 if (ctx->Array.LegalTypesMask == 0 || ctx->Array.LegalTypesMaskAPI != ctx->API) {
392 /* Compute the LegalTypesMask only once, unless the context API has
393 * changed, in which case we want to compute it again. We can't do this
394 * in _mesa_init_varrays() below because extensions are not yet enabled
395 * at that point.
396 */
397 ctx->Array.LegalTypesMask = get_legal_types_mask(ctx);
398 ctx->Array.LegalTypesMaskAPI = ctx->API;
399 }
400
401 legalTypesMask &= ctx->Array.LegalTypesMask;
402
403 if (_mesa_is_gles(ctx) && sizeMax == BGRA_OR_4) {
404 /* BGRA ordering is not supported in ES contexts.
405 */
406 sizeMax = 4;
407 }
408
409 typeBit = type_to_bit(ctx, type);
410 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
411 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
412 func, _mesa_enum_to_string(type));
413 return false;
414 }
415
416 if (format == GL_BGRA) {
417 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
418 *
419 * "An INVALID_OPERATION error is generated under any of the following
420 * conditions:
421 * ...
422 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
423 * or UNSIGNED_INT_2_10_10_10_REV;
424 * ...
425 * • size is BGRA and normalized is FALSE;"
426 */
427 bool bgra_error = false;
428
429 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
430 if (type != GL_UNSIGNED_INT_2_10_10_10_REV &&
431 type != GL_INT_2_10_10_10_REV &&
432 type != GL_UNSIGNED_BYTE)
433 bgra_error = true;
434 } else if (type != GL_UNSIGNED_BYTE)
435 bgra_error = true;
436
437 if (bgra_error) {
438 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)",
439 func, _mesa_enum_to_string(type));
440 return false;
441 }
442
443 if (!normalized) {
444 _mesa_error(ctx, GL_INVALID_OPERATION,
445 "%s(size=GL_BGRA and normalized=GL_FALSE)", func);
446 return false;
447 }
448 }
449 else if (size < sizeMin || size > sizeMax || size > 4) {
450 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
451 return false;
452 }
453
454 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
455 (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
456 type == GL_INT_2_10_10_10_REV) && size != 4) {
457 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
458 return false;
459 }
460
461 /* The ARB_vertex_attrib_binding_spec says:
462 *
463 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
464 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
465 */
466 if (relativeOffset > ctx->Const.MaxVertexAttribRelativeOffset) {
467 _mesa_error(ctx, GL_INVALID_VALUE,
468 "%s(relativeOffset=%d > "
469 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
470 func, relativeOffset);
471 return false;
472 }
473
474 if (ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev &&
475 type == GL_UNSIGNED_INT_10F_11F_11F_REV && size != 3) {
476 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
477 return false;
478 }
479
480 return true;
481 }
482
483 /**
484 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
485 *
486 * \param func name of calling function used for error reporting
487 * \param vao the vao to update
488 * \param obj the bound buffer object
489 * \param attrib the attribute array index to update
490 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
491 * \param sizeMin min allowable size value
492 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
493 * \param size components per element (1, 2, 3 or 4)
494 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
495 * \param stride stride between elements, in elements
496 * \param normalized are integer types converted to floats in [-1, 1]?
497 * \param integer integer-valued values (will not be normalized to [-1,1])
498 * \param doubles Double values not reduced to floats
499 * \param ptr the address (or offset inside VBO) of the array data
500 */
501 static void
502 validate_array(struct gl_context *ctx, const char *func,
503 struct gl_vertex_array_object *vao,
504 struct gl_buffer_object *obj,
505 GLuint attrib, GLbitfield legalTypesMask,
506 GLint sizeMin, GLint sizeMax,
507 GLint size, GLenum type, GLsizei stride,
508 GLboolean normalized, GLboolean integer, GLboolean doubles,
509 const GLvoid *ptr)
510 {
511 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
512 *
513 * "Client vertex arrays - all vertex array attribute pointers must
514 * refer to buffer objects (section 2.9.2). The default vertex array
515 * object (the name zero) is also deprecated. Calling
516 * VertexAttribPointer when no buffer object or no vertex array object
517 * is bound will generate an INVALID_OPERATION error..."
518 *
519 * The check for VBOs is handled below.
520 */
521 if (ctx->API == API_OPENGL_CORE && (vao == ctx->Array.DefaultVAO)) {
522 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)",
523 func);
524 return;
525 }
526
527 if (stride < 0) {
528 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
529 return;
530 }
531
532 if (_mesa_is_desktop_gl(ctx) && ctx->Version >= 44 &&
533 stride > ctx->Const.MaxVertexAttribStride) {
534 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
535 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
536 return;
537 }
538
539 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
540 *
541 * "An INVALID_OPERATION error is generated under any of the following
542 * conditions:
543 *
544 * ...
545 *
546 * * any of the *Pointer commands specifying the location and
547 * organization of vertex array data are called while zero is bound
548 * to the ARRAY_BUFFER buffer object binding point (see section
549 * 2.9.6), and the pointer argument is not NULL."
550 */
551 if (ptr != NULL && vao != ctx->Array.DefaultVAO &&
552 !_mesa_is_bufferobj(obj)) {
553 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
554 return;
555 }
556 }
557
558
559 static bool
560 validate_array_and_format(struct gl_context *ctx, const char *func,
561 struct gl_vertex_array_object *vao,
562 struct gl_buffer_object *obj,
563 GLuint attrib, GLbitfield legalTypes,
564 GLint sizeMin, GLint sizeMax,
565 GLint size, GLenum type, GLsizei stride,
566 GLboolean normalized, GLboolean integer,
567 GLboolean doubles, GLenum format, const GLvoid *ptr)
568 {
569 validate_array(ctx, func, vao, obj, attrib, legalTypes, sizeMin, sizeMax,
570 size, type, stride, normalized, integer, doubles, ptr);
571
572 return validate_array_format(ctx, func, vao, attrib, legalTypes, sizeMin,
573 sizeMax, size, type, normalized, integer,
574 doubles, 0, format);
575 }
576
577
578 /**
579 * Update state for glVertex/Color/TexCoord/...Pointer functions.
580 *
581 * \param vao the vao to update
582 * \param obj the bound buffer object
583 * \param attrib the attribute array index to update
584 * \param format Either GL_RGBA or GL_BGRA.
585 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
586 * \param size components per element (1, 2, 3 or 4)
587 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
588 * \param stride stride between elements, in elements
589 * \param normalized are integer types converted to floats in [-1, 1]?
590 * \param integer integer-valued values (will not be normalized to [-1,1])
591 * \param doubles Double values not reduced to floats
592 * \param ptr the address (or offset inside VBO) of the array data
593 */
594 static void
595 update_array(struct gl_context *ctx,
596 struct gl_vertex_array_object *vao,
597 struct gl_buffer_object *obj,
598 GLuint attrib, GLenum format,
599 GLint sizeMax,
600 GLint size, GLenum type, GLsizei stride,
601 GLboolean normalized, GLboolean integer, GLboolean doubles,
602 const GLvoid *ptr)
603 {
604 _mesa_update_array_format(ctx, vao, attrib, size, type, format,
605 normalized, integer, doubles, 0);
606
607 /* Reset the vertex attrib binding */
608 _mesa_vertex_attrib_binding(ctx, vao, attrib, attrib);
609
610 /* The Stride and Ptr fields are not set by update_array_format() */
611 struct gl_array_attributes *array = &vao->VertexAttrib[attrib];
612 array->Stride = stride;
613 /* For updating the pointer we would need to add the vao->NewArrays flag
614 * to the VAO. But but that is done already unconditionally in
615 * _mesa_update_array_format called above.
616 */
617 assert((vao->NewArrays | ~vao->Enabled) & VERT_BIT(attrib));
618 array->Ptr = ptr;
619
620 /* Update the vertex buffer binding */
621 GLsizei effectiveStride = stride != 0 ?
622 stride : array->Format._ElementSize;
623 _mesa_bind_vertex_buffer(ctx, vao, attrib,
624 obj, (GLintptr) ptr,
625 effectiveStride);
626 }
627
628 void GLAPIENTRY
629 _mesa_VertexPointer_no_error(GLint size, GLenum type, GLsizei stride,
630 const GLvoid *ptr)
631 {
632 GET_CURRENT_CONTEXT(ctx);
633
634 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
635 VERT_ATTRIB_POS, GL_RGBA, 4, size, type, stride,
636 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
637 }
638
639
640 void GLAPIENTRY
641 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
642 {
643 GET_CURRENT_CONTEXT(ctx);
644
645 GLenum format = GL_RGBA;
646 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
647 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
648 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
649 DOUBLE_BIT | HALF_BIT |
650 UNSIGNED_INT_2_10_10_10_REV_BIT |
651 INT_2_10_10_10_REV_BIT);
652
653 if (!validate_array_and_format(ctx, "glVertexPointer",
654 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
655 VERT_ATTRIB_POS, legalTypes, 2, 4, size,
656 type, stride, GL_FALSE, GL_FALSE, GL_FALSE,
657 format, ptr))
658 return;
659
660 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
661 VERT_ATTRIB_POS, format, 4, size, type, stride,
662 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
663 }
664
665
666 void GLAPIENTRY
667 _mesa_NormalPointer_no_error(GLenum type, GLsizei stride, const GLvoid *ptr )
668 {
669 GET_CURRENT_CONTEXT(ctx);
670
671 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
672 VERT_ATTRIB_NORMAL, GL_RGBA, 3, 3, type, stride, GL_TRUE,
673 GL_FALSE, GL_FALSE, ptr);
674 }
675
676
677 void GLAPIENTRY
678 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
679 {
680 GET_CURRENT_CONTEXT(ctx);
681
682 GLenum format = GL_RGBA;
683 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
684 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
685 : (BYTE_BIT | SHORT_BIT | INT_BIT |
686 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
687 UNSIGNED_INT_2_10_10_10_REV_BIT |
688 INT_2_10_10_10_REV_BIT);
689
690 if (!validate_array_and_format(ctx, "glNormalPointer",
691 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
692 VERT_ATTRIB_NORMAL, legalTypes, 3, 3, 3,
693 type, stride, GL_TRUE, GL_FALSE,
694 GL_FALSE, format, ptr))
695 return;
696
697 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
698 VERT_ATTRIB_NORMAL, format, 3, 3, type, stride, GL_TRUE,
699 GL_FALSE, GL_FALSE, ptr);
700 }
701
702
703 void GLAPIENTRY
704 _mesa_ColorPointer_no_error(GLint size, GLenum type, GLsizei stride,
705 const GLvoid *ptr)
706 {
707 GET_CURRENT_CONTEXT(ctx);
708
709 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
710 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
711 VERT_ATTRIB_COLOR0, format, BGRA_OR_4, size,
712 type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
713 }
714
715
716 void GLAPIENTRY
717 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
718 {
719 GET_CURRENT_CONTEXT(ctx);
720 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
721
722 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
723 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
724 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
725 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
726 SHORT_BIT | UNSIGNED_SHORT_BIT |
727 INT_BIT | UNSIGNED_INT_BIT |
728 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
729 UNSIGNED_INT_2_10_10_10_REV_BIT |
730 INT_2_10_10_10_REV_BIT);
731
732 if (!validate_array_and_format(ctx, "glColorPointer",
733 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
734 VERT_ATTRIB_COLOR0, legalTypes, sizeMin,
735 BGRA_OR_4, size, type, stride, GL_TRUE,
736 GL_FALSE, GL_FALSE, format, ptr))
737 return;
738
739 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
740 VERT_ATTRIB_COLOR0, format, BGRA_OR_4, size,
741 type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
742 }
743
744
745 void GLAPIENTRY
746 _mesa_FogCoordPointer_no_error(GLenum type, GLsizei stride, const GLvoid *ptr)
747 {
748 GET_CURRENT_CONTEXT(ctx);
749
750 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
751 VERT_ATTRIB_FOG, GL_RGBA, 1, 1, type, stride, GL_FALSE,
752 GL_FALSE, GL_FALSE, ptr);
753 }
754
755
756 void GLAPIENTRY
757 _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
758 {
759 GET_CURRENT_CONTEXT(ctx);
760
761 GLenum format = GL_RGBA;
762 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
763
764 if (!validate_array_and_format(ctx, "glFogCoordPointer",
765 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
766 VERT_ATTRIB_FOG, legalTypes, 1, 1, 1,
767 type, stride, GL_FALSE, GL_FALSE,
768 GL_FALSE, format, ptr))
769 return;
770
771 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
772 VERT_ATTRIB_FOG, format, 1, 1, type, stride, GL_FALSE,
773 GL_FALSE, GL_FALSE, ptr);
774 }
775
776
777 void GLAPIENTRY
778 _mesa_IndexPointer_no_error(GLenum type, GLsizei stride, const GLvoid *ptr)
779 {
780 GET_CURRENT_CONTEXT(ctx);
781
782 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
783 VERT_ATTRIB_COLOR_INDEX, GL_RGBA, 1, 1, type, stride,
784 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
785 }
786
787
788 void GLAPIENTRY
789 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
790 {
791 GET_CURRENT_CONTEXT(ctx);
792
793 GLenum format = GL_RGBA;
794 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
795 FLOAT_BIT | DOUBLE_BIT);
796
797 if (!validate_array_and_format(ctx, "glIndexPointer",
798 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
799 VERT_ATTRIB_COLOR_INDEX,
800 legalTypes, 1, 1, 1, type, stride,
801 GL_FALSE, GL_FALSE, GL_FALSE, format, ptr))
802 return;
803
804 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
805 VERT_ATTRIB_COLOR_INDEX, format, 1, 1, type, stride,
806 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
807 }
808
809
810 void GLAPIENTRY
811 _mesa_SecondaryColorPointer_no_error(GLint size, GLenum type,
812 GLsizei stride, const GLvoid *ptr)
813 {
814 GET_CURRENT_CONTEXT(ctx);
815
816 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
817 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
818 VERT_ATTRIB_COLOR1, format, BGRA_OR_4, size, type,
819 stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
820 }
821
822
823 void GLAPIENTRY
824 _mesa_SecondaryColorPointer(GLint size, GLenum type,
825 GLsizei stride, const GLvoid *ptr)
826 {
827 GET_CURRENT_CONTEXT(ctx);
828
829 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
830 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
831 SHORT_BIT | UNSIGNED_SHORT_BIT |
832 INT_BIT | UNSIGNED_INT_BIT |
833 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
834 UNSIGNED_INT_2_10_10_10_REV_BIT |
835 INT_2_10_10_10_REV_BIT);
836
837 if (!validate_array_and_format(ctx, "glSecondaryColorPointer",
838 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
839 VERT_ATTRIB_COLOR1, legalTypes, 3,
840 BGRA_OR_4, size, type, stride,
841 GL_TRUE, GL_FALSE, GL_FALSE, format, ptr))
842 return;
843
844 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
845 VERT_ATTRIB_COLOR1, format, BGRA_OR_4, size, type,
846 stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
847 }
848
849
850 void GLAPIENTRY
851 _mesa_TexCoordPointer_no_error(GLint size, GLenum type, GLsizei stride,
852 const GLvoid *ptr)
853 {
854 GET_CURRENT_CONTEXT(ctx);
855 const GLuint unit = ctx->Array.ActiveTexture;
856
857 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
858 VERT_ATTRIB_TEX(unit), GL_RGBA, 4, size, type,
859 stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
860 }
861
862
863 void GLAPIENTRY
864 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
865 const GLvoid *ptr)
866 {
867 GET_CURRENT_CONTEXT(ctx);
868 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
869 const GLuint unit = ctx->Array.ActiveTexture;
870
871 GLenum format = GL_RGBA;
872 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
873 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
874 : (SHORT_BIT | INT_BIT |
875 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
876 UNSIGNED_INT_2_10_10_10_REV_BIT |
877 INT_2_10_10_10_REV_BIT);
878
879 if (!validate_array_and_format(ctx, "glTexCoordPointer",
880 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
881 VERT_ATTRIB_TEX(unit), legalTypes,
882 sizeMin, 4, size, type, stride,
883 GL_FALSE, GL_FALSE, GL_FALSE, format, ptr))
884 return;
885
886 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
887 VERT_ATTRIB_TEX(unit), format, 4, size, type,
888 stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
889 }
890
891
892 void GLAPIENTRY
893 _mesa_EdgeFlagPointer_no_error(GLsizei stride, const GLvoid *ptr)
894 {
895 /* this is the same type that glEdgeFlag uses */
896 const GLboolean integer = GL_FALSE;
897 GET_CURRENT_CONTEXT(ctx);
898
899 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
900 VERT_ATTRIB_EDGEFLAG, GL_RGBA, 1, 1, GL_UNSIGNED_BYTE,
901 stride, GL_FALSE, integer, GL_FALSE, ptr);
902 }
903
904
905 void GLAPIENTRY
906 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
907 {
908 /* this is the same type that glEdgeFlag uses */
909 const GLboolean integer = GL_FALSE;
910 GET_CURRENT_CONTEXT(ctx);
911
912 GLenum format = GL_RGBA;
913 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
914
915 if (!validate_array_and_format(ctx, "glEdgeFlagPointer",
916 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
917 VERT_ATTRIB_EDGEFLAG, legalTypes,
918 1, 1, 1, GL_UNSIGNED_BYTE, stride,
919 GL_FALSE, integer, GL_FALSE, format, ptr))
920 return;
921
922 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
923 VERT_ATTRIB_EDGEFLAG, format, 1, 1, GL_UNSIGNED_BYTE,
924 stride, GL_FALSE, integer, GL_FALSE, ptr);
925 }
926
927
928 void GLAPIENTRY
929 _mesa_PointSizePointerOES_no_error(GLenum type, GLsizei stride,
930 const GLvoid *ptr)
931 {
932 GET_CURRENT_CONTEXT(ctx);
933
934 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
935 VERT_ATTRIB_POINT_SIZE, GL_RGBA, 1, 1, type, stride,
936 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
937 }
938
939
940 void GLAPIENTRY
941 _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr)
942 {
943 GET_CURRENT_CONTEXT(ctx);
944
945 GLenum format = GL_RGBA;
946 if (ctx->API != API_OPENGLES) {
947 _mesa_error(ctx, GL_INVALID_OPERATION,
948 "glPointSizePointer(ES 1.x only)");
949 return;
950 }
951
952 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
953
954 if (!validate_array_and_format(ctx, "glPointSizePointer",
955 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
956 VERT_ATTRIB_POINT_SIZE, legalTypes,
957 1, 1, 1, type, stride, GL_FALSE, GL_FALSE,
958 GL_FALSE, format, ptr))
959 return;
960
961 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
962 VERT_ATTRIB_POINT_SIZE, format, 1, 1, type, stride,
963 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
964 }
965
966
967 void GLAPIENTRY
968 _mesa_VertexAttribPointer_no_error(GLuint index, GLint size, GLenum type,
969 GLboolean normalized,
970 GLsizei stride, const GLvoid *ptr)
971 {
972 GET_CURRENT_CONTEXT(ctx);
973
974 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
975 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
976 VERT_ATTRIB_GENERIC(index), format, BGRA_OR_4,
977 size, type, stride, normalized, GL_FALSE, GL_FALSE, ptr);
978 }
979
980
981 /**
982 * Set a generic vertex attribute array.
983 * Note that these arrays DO NOT alias the conventional GL vertex arrays
984 * (position, normal, color, fog, texcoord, etc).
985 */
986 void GLAPIENTRY
987 _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
988 GLboolean normalized,
989 GLsizei stride, const GLvoid *ptr)
990 {
991 GET_CURRENT_CONTEXT(ctx);
992
993 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
994 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
995 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(idx)");
996 return;
997 }
998
999 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1000 SHORT_BIT | UNSIGNED_SHORT_BIT |
1001 INT_BIT | UNSIGNED_INT_BIT |
1002 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1003 FIXED_ES_BIT | FIXED_GL_BIT |
1004 UNSIGNED_INT_2_10_10_10_REV_BIT |
1005 INT_2_10_10_10_REV_BIT |
1006 UNSIGNED_INT_10F_11F_11F_REV_BIT);
1007
1008 if (!validate_array_and_format(ctx, "glVertexAttribPointer",
1009 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1010 VERT_ATTRIB_GENERIC(index), legalTypes,
1011 1, BGRA_OR_4, size, type, stride,
1012 normalized, GL_FALSE, GL_FALSE, format, ptr))
1013 return;
1014
1015 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1016 VERT_ATTRIB_GENERIC(index), format, BGRA_OR_4,
1017 size, type, stride, normalized, GL_FALSE, GL_FALSE, ptr);
1018 }
1019
1020
1021 void GLAPIENTRY
1022 _mesa_VertexAttribIPointer_no_error(GLuint index, GLint size, GLenum type,
1023 GLsizei stride, const GLvoid *ptr)
1024 {
1025 const GLboolean normalized = GL_FALSE;
1026 const GLboolean integer = GL_TRUE;
1027 GET_CURRENT_CONTEXT(ctx);
1028
1029 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1030 VERT_ATTRIB_GENERIC(index), GL_RGBA, 4, size, type,
1031 stride, normalized, integer, GL_FALSE, ptr);
1032 }
1033
1034
1035 /**
1036 * GL_EXT_gpu_shader4 / GL 3.0.
1037 * Set an integer-valued vertex attribute array.
1038 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1039 * (position, normal, color, fog, texcoord, etc).
1040 */
1041 void GLAPIENTRY
1042 _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
1043 GLsizei stride, const GLvoid *ptr)
1044 {
1045 const GLboolean normalized = GL_FALSE;
1046 const GLboolean integer = GL_TRUE;
1047 GET_CURRENT_CONTEXT(ctx);
1048
1049 GLenum format = GL_RGBA;
1050 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1051 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
1052 return;
1053 }
1054
1055 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1056 SHORT_BIT | UNSIGNED_SHORT_BIT |
1057 INT_BIT | UNSIGNED_INT_BIT);
1058
1059 if (!validate_array_and_format(ctx, "glVertexAttribIPointer",
1060 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1061 VERT_ATTRIB_GENERIC(index), legalTypes,
1062 1, 4, size, type, stride,
1063 normalized, integer, GL_FALSE, format, ptr))
1064 return;
1065
1066 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1067 VERT_ATTRIB_GENERIC(index), format, 4, size, type,
1068 stride, normalized, integer, GL_FALSE, ptr);
1069 }
1070
1071
1072 void GLAPIENTRY
1073 _mesa_VertexAttribLPointer_no_error(GLuint index, GLint size, GLenum type,
1074 GLsizei stride, const GLvoid *ptr)
1075 {
1076 GET_CURRENT_CONTEXT(ctx);
1077
1078 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1079 VERT_ATTRIB_GENERIC(index), GL_RGBA, 4, size, type,
1080 stride, GL_FALSE, GL_FALSE, GL_TRUE, ptr);
1081 }
1082
1083
1084 void GLAPIENTRY
1085 _mesa_VertexAttribLPointer(GLuint index, GLint size, GLenum type,
1086 GLsizei stride, const GLvoid *ptr)
1087 {
1088 GET_CURRENT_CONTEXT(ctx);
1089
1090 GLenum format = GL_RGBA;
1091 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1092 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribLPointer(index)");
1093 return;
1094 }
1095
1096 const GLbitfield legalTypes = DOUBLE_BIT;
1097
1098 if (!validate_array_and_format(ctx, "glVertexAttribLPointer",
1099 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1100 VERT_ATTRIB_GENERIC(index), legalTypes,
1101 1, 4, size, type, stride,
1102 GL_FALSE, GL_FALSE, GL_TRUE, format, ptr))
1103 return;
1104
1105 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1106 VERT_ATTRIB_GENERIC(index), format, 4, size, type,
1107 stride, GL_FALSE, GL_FALSE, GL_TRUE, ptr);
1108 }
1109
1110
1111 void
1112 _mesa_enable_vertex_array_attribs(struct gl_context *ctx,
1113 struct gl_vertex_array_object *vao,
1114 GLbitfield attrib_bits)
1115 {
1116 assert((attrib_bits & ~VERT_BIT_ALL) == 0);
1117 assert(!vao->SharedAndImmutable);
1118
1119 /* Only work on bits that are disabled */
1120 attrib_bits &= ~vao->Enabled;
1121 if (attrib_bits) {
1122 /* was disabled, now being enabled */
1123 vao->Enabled |= attrib_bits;
1124 vao->NewArrays |= attrib_bits;
1125
1126 /* Update the map mode if needed */
1127 if (attrib_bits & (VERT_BIT_POS|VERT_BIT_GENERIC0))
1128 update_attribute_map_mode(ctx, vao);
1129 }
1130 }
1131
1132 static void
1133 enable_vertex_array_attrib(struct gl_context *ctx,
1134 struct gl_vertex_array_object *vao,
1135 GLuint index,
1136 const char *func)
1137 {
1138 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1139 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
1140 return;
1141 }
1142
1143 _mesa_enable_vertex_array_attrib(ctx, vao, VERT_ATTRIB_GENERIC(index));
1144 }
1145
1146
1147 void GLAPIENTRY
1148 _mesa_EnableVertexAttribArray(GLuint index)
1149 {
1150 GET_CURRENT_CONTEXT(ctx);
1151 enable_vertex_array_attrib(ctx, ctx->Array.VAO, index,
1152 "glEnableVertexAttribArray");
1153 }
1154
1155
1156 void GLAPIENTRY
1157 _mesa_EnableVertexAttribArray_no_error(GLuint index)
1158 {
1159 GET_CURRENT_CONTEXT(ctx);
1160 _mesa_enable_vertex_array_attrib(ctx, ctx->Array.VAO,
1161 VERT_ATTRIB_GENERIC(index));
1162 }
1163
1164
1165 void GLAPIENTRY
1166 _mesa_EnableVertexArrayAttrib(GLuint vaobj, GLuint index)
1167 {
1168 GET_CURRENT_CONTEXT(ctx);
1169 struct gl_vertex_array_object *vao;
1170
1171 /* The ARB_direct_state_access specification says:
1172 *
1173 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1174 * and DisableVertexArrayAttrib if <vaobj> is not
1175 * [compatibility profile: zero or] the name of an existing vertex
1176 * array object."
1177 */
1178 vao = _mesa_lookup_vao_err(ctx, vaobj, "glEnableVertexArrayAttrib");
1179 if (!vao)
1180 return;
1181
1182 enable_vertex_array_attrib(ctx, vao, index, "glEnableVertexArrayAttrib");
1183 }
1184
1185
1186 void GLAPIENTRY
1187 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj, GLuint index)
1188 {
1189 GET_CURRENT_CONTEXT(ctx);
1190 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
1191 _mesa_enable_vertex_array_attrib(ctx, vao, VERT_ATTRIB_GENERIC(index));
1192 }
1193
1194
1195 void
1196 _mesa_disable_vertex_array_attribs(struct gl_context *ctx,
1197 struct gl_vertex_array_object *vao,
1198 GLbitfield attrib_bits)
1199 {
1200 assert((attrib_bits & ~VERT_BIT_ALL) == 0);
1201 assert(!vao->SharedAndImmutable);
1202
1203 /* Only work on bits that are enabled */
1204 attrib_bits &= vao->Enabled;
1205 if (attrib_bits) {
1206 /* was enabled, now being disabled */
1207 vao->Enabled &= ~attrib_bits;
1208 vao->NewArrays |= attrib_bits;
1209
1210 /* Update the map mode if needed */
1211 if (attrib_bits & (VERT_BIT_POS|VERT_BIT_GENERIC0))
1212 update_attribute_map_mode(ctx, vao);
1213 }
1214 }
1215
1216
1217 void GLAPIENTRY
1218 _mesa_DisableVertexAttribArray(GLuint index)
1219 {
1220 GET_CURRENT_CONTEXT(ctx);
1221
1222 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1223 _mesa_error(ctx, GL_INVALID_VALUE, "glDisableVertexAttribArray(index)");
1224 return;
1225 }
1226
1227 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
1228 _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attrib);
1229 }
1230
1231
1232 void GLAPIENTRY
1233 _mesa_DisableVertexAttribArray_no_error(GLuint index)
1234 {
1235 GET_CURRENT_CONTEXT(ctx);
1236 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
1237 _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attrib);
1238 }
1239
1240
1241 void GLAPIENTRY
1242 _mesa_DisableVertexArrayAttrib(GLuint vaobj, GLuint index)
1243 {
1244 GET_CURRENT_CONTEXT(ctx);
1245 struct gl_vertex_array_object *vao;
1246
1247 /* The ARB_direct_state_access specification says:
1248 *
1249 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1250 * and DisableVertexArrayAttrib if <vaobj> is not
1251 * [compatibility profile: zero or] the name of an existing vertex
1252 * array object."
1253 */
1254 vao = _mesa_lookup_vao_err(ctx, vaobj, "glDisableVertexArrayAttrib");
1255 if (!vao)
1256 return;
1257
1258 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1259 _mesa_error(ctx, GL_INVALID_VALUE, "glDisableVertexArrayAttrib(index)");
1260 return;
1261 }
1262
1263 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
1264 _mesa_disable_vertex_array_attrib(ctx, vao, attrib);
1265 }
1266
1267
1268 void GLAPIENTRY
1269 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj, GLuint index)
1270 {
1271 GET_CURRENT_CONTEXT(ctx);
1272 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
1273 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
1274 _mesa_disable_vertex_array_attrib(ctx, vao, attrib);
1275 }
1276
1277
1278 /**
1279 * Return info for a vertex attribute array (no alias with legacy
1280 * vertex attributes (pos, normal, color, etc)). This function does
1281 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
1282 */
1283 static GLuint
1284 get_vertex_array_attrib(struct gl_context *ctx,
1285 const struct gl_vertex_array_object *vao,
1286 GLuint index, GLenum pname,
1287 const char *caller)
1288 {
1289 const struct gl_array_attributes *array;
1290
1291 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1292 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
1293 return 0;
1294 }
1295
1296 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
1297
1298 array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
1299
1300 switch (pname) {
1301 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
1302 return !!(vao->Enabled & VERT_BIT_GENERIC(index));
1303 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
1304 return (array->Format.Format == GL_BGRA) ? GL_BGRA : array->Format.Size;
1305 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
1306 return array->Stride;
1307 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
1308 return array->Format.Type;
1309 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
1310 return array->Format.Normalized;
1311 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
1312 return vao->BufferBinding[array->BufferBindingIndex].BufferObj->Name;
1313 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
1314 if ((_mesa_is_desktop_gl(ctx)
1315 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
1316 || _mesa_is_gles3(ctx)) {
1317 return array->Format.Integer;
1318 }
1319 goto error;
1320 case GL_VERTEX_ATTRIB_ARRAY_LONG:
1321 if (_mesa_is_desktop_gl(ctx)) {
1322 return array->Format.Doubles;
1323 }
1324 goto error;
1325 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
1326 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
1327 || _mesa_is_gles3(ctx)) {
1328 return vao->BufferBinding[array->BufferBindingIndex].InstanceDivisor;
1329 }
1330 goto error;
1331 case GL_VERTEX_ATTRIB_BINDING:
1332 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
1333 return array->BufferBindingIndex - VERT_ATTRIB_GENERIC0;
1334 }
1335 goto error;
1336 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
1337 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
1338 return array->RelativeOffset;
1339 }
1340 goto error;
1341 default:
1342 ; /* fall-through */
1343 }
1344
1345 error:
1346 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
1347 return 0;
1348 }
1349
1350
1351 static const GLfloat *
1352 get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
1353 {
1354 if (index == 0) {
1355 if (_mesa_attr_zero_aliases_vertex(ctx)) {
1356 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
1357 return NULL;
1358 }
1359 }
1360 else if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1361 _mesa_error(ctx, GL_INVALID_VALUE,
1362 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
1363 return NULL;
1364 }
1365
1366 assert(VERT_ATTRIB_GENERIC(index) <
1367 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1368
1369 FLUSH_CURRENT(ctx, 0);
1370 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
1371 }
1372
1373 void GLAPIENTRY
1374 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
1375 {
1376 GET_CURRENT_CONTEXT(ctx);
1377
1378 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1379 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
1380 if (v != NULL) {
1381 COPY_4V(params, v);
1382 }
1383 }
1384 else {
1385 params[0] = (GLfloat) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1386 index, pname,
1387 "glGetVertexAttribfv");
1388 }
1389 }
1390
1391
1392 void GLAPIENTRY
1393 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
1394 {
1395 GET_CURRENT_CONTEXT(ctx);
1396
1397 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1398 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
1399 if (v != NULL) {
1400 params[0] = (GLdouble) v[0];
1401 params[1] = (GLdouble) v[1];
1402 params[2] = (GLdouble) v[2];
1403 params[3] = (GLdouble) v[3];
1404 }
1405 }
1406 else {
1407 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1408 index, pname,
1409 "glGetVertexAttribdv");
1410 }
1411 }
1412
1413 void GLAPIENTRY
1414 _mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params)
1415 {
1416 GET_CURRENT_CONTEXT(ctx);
1417
1418 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1419 const GLdouble *v =
1420 (const GLdouble *)get_current_attrib(ctx, index,
1421 "glGetVertexAttribLdv");
1422 if (v != NULL) {
1423 params[0] = v[0];
1424 params[1] = v[1];
1425 params[2] = v[2];
1426 params[3] = v[3];
1427 }
1428 }
1429 else {
1430 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1431 index, pname,
1432 "glGetVertexAttribLdv");
1433 }
1434 }
1435
1436 void GLAPIENTRY
1437 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
1438 {
1439 GET_CURRENT_CONTEXT(ctx);
1440
1441 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1442 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
1443 if (v != NULL) {
1444 /* XXX should floats in[0,1] be scaled to full int range? */
1445 params[0] = (GLint) v[0];
1446 params[1] = (GLint) v[1];
1447 params[2] = (GLint) v[2];
1448 params[3] = (GLint) v[3];
1449 }
1450 }
1451 else {
1452 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1453 index, pname,
1454 "glGetVertexAttribiv");
1455 }
1456 }
1457
1458 void GLAPIENTRY
1459 _mesa_GetVertexAttribLui64vARB(GLuint index, GLenum pname, GLuint64EXT *params)
1460 {
1461 GET_CURRENT_CONTEXT(ctx);
1462
1463 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1464 const GLuint64 *v =
1465 (const GLuint64 *)get_current_attrib(ctx, index,
1466 "glGetVertexAttribLui64vARB");
1467 if (v != NULL) {
1468 params[0] = v[0];
1469 params[1] = v[1];
1470 params[2] = v[2];
1471 params[3] = v[3];
1472 }
1473 }
1474 else {
1475 params[0] = (GLuint64) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1476 index, pname,
1477 "glGetVertexAttribLui64vARB");
1478 }
1479 }
1480
1481
1482 /** GL 3.0 */
1483 void GLAPIENTRY
1484 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
1485 {
1486 GET_CURRENT_CONTEXT(ctx);
1487
1488 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1489 const GLint *v = (const GLint *)
1490 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
1491 if (v != NULL) {
1492 COPY_4V(params, v);
1493 }
1494 }
1495 else {
1496 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1497 index, pname,
1498 "glGetVertexAttribIiv");
1499 }
1500 }
1501
1502
1503 /** GL 3.0 */
1504 void GLAPIENTRY
1505 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
1506 {
1507 GET_CURRENT_CONTEXT(ctx);
1508
1509 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1510 const GLuint *v = (const GLuint *)
1511 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
1512 if (v != NULL) {
1513 COPY_4V(params, v);
1514 }
1515 }
1516 else {
1517 params[0] = get_vertex_array_attrib(ctx, ctx->Array.VAO,
1518 index, pname,
1519 "glGetVertexAttribIuiv");
1520 }
1521 }
1522
1523
1524 void GLAPIENTRY
1525 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
1526 {
1527 GET_CURRENT_CONTEXT(ctx);
1528
1529 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1530 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
1531 return;
1532 }
1533
1534 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
1535 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
1536 return;
1537 }
1538
1539 assert(VERT_ATTRIB_GENERIC(index) <
1540 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1541
1542 *pointer = (GLvoid *)
1543 ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
1544 }
1545
1546
1547 /** ARB_direct_state_access */
1548 void GLAPIENTRY
1549 _mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index,
1550 GLenum pname, GLint *params)
1551 {
1552 GET_CURRENT_CONTEXT(ctx);
1553 struct gl_vertex_array_object *vao;
1554
1555 /* The ARB_direct_state_access specification says:
1556 *
1557 * "An INVALID_OPERATION error is generated if <vaobj> is not
1558 * [compatibility profile: zero or] the name of an existing
1559 * vertex array object."
1560 */
1561 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexediv");
1562 if (!vao)
1563 return;
1564
1565 /* The ARB_direct_state_access specification says:
1566 *
1567 * "For GetVertexArrayIndexediv, <pname> must be one of
1568 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1569 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1570 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1571 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1572 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1573 *
1574 * and:
1575 *
1576 * "Add GetVertexArrayIndexediv in 'Get Command' for
1577 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1578 * VERTEX_ATTRIB_BINDING,
1579 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1580 * VERTEX_BINDING_OFFSET, and
1581 * VERTEX_BINDING_STRIDE states"
1582 *
1583 * The only parameter name common to both lists is
1584 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1585 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1586 * pretty clear however that the intent is that it should be possible
1587 * to query all vertex attrib and binding states that can be set with
1588 * a DSA function.
1589 */
1590 switch (pname) {
1591 case GL_VERTEX_BINDING_OFFSET:
1592 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1593 break;
1594 case GL_VERTEX_BINDING_STRIDE:
1595 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Stride;
1596 break;
1597 case GL_VERTEX_BINDING_DIVISOR:
1598 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
1599 break;
1600 case GL_VERTEX_BINDING_BUFFER:
1601 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name;
1602 break;
1603 default:
1604 params[0] = get_vertex_array_attrib(ctx, vao, index, pname,
1605 "glGetVertexArrayIndexediv");
1606 break;
1607 }
1608 }
1609
1610
1611 void GLAPIENTRY
1612 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj, GLuint index,
1613 GLenum pname, GLint64 *params)
1614 {
1615 GET_CURRENT_CONTEXT(ctx);
1616 struct gl_vertex_array_object *vao;
1617
1618 /* The ARB_direct_state_access specification says:
1619 *
1620 * "An INVALID_OPERATION error is generated if <vaobj> is not
1621 * [compatibility profile: zero or] the name of an existing
1622 * vertex array object."
1623 */
1624 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexed64iv");
1625 if (!vao)
1626 return;
1627
1628 /* The ARB_direct_state_access specification says:
1629 *
1630 * "For GetVertexArrayIndexed64iv, <pname> must be
1631 * VERTEX_BINDING_OFFSET."
1632 *
1633 * and:
1634 *
1635 * "An INVALID_ENUM error is generated if <pname> is not one of
1636 * the valid values listed above for the corresponding command."
1637 */
1638 if (pname != GL_VERTEX_BINDING_OFFSET) {
1639 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayIndexed64iv("
1640 "pname != GL_VERTEX_BINDING_OFFSET)");
1641 return;
1642 }
1643
1644 /* The ARB_direct_state_access specification says:
1645 *
1646 * "An INVALID_VALUE error is generated if <index> is greater than
1647 * or equal to the value of MAX_VERTEX_ATTRIBS."
1648 *
1649 * Since the index refers to a buffer binding in this case, the intended
1650 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1651 * required to be the same, so in practice this doesn't matter.
1652 */
1653 if (index >= ctx->Const.MaxVertexAttribBindings) {
1654 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexArrayIndexed64iv(index"
1655 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1656 index, ctx->Const.MaxVertexAttribBindings);
1657 return;
1658 }
1659
1660 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1661 }
1662
1663
1664 void GLAPIENTRY
1665 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
1666 GLsizei count, const GLvoid *ptr)
1667 {
1668 (void) count;
1669 _mesa_VertexPointer(size, type, stride, ptr);
1670 }
1671
1672
1673 void GLAPIENTRY
1674 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1675 const GLvoid *ptr)
1676 {
1677 (void) count;
1678 _mesa_NormalPointer(type, stride, ptr);
1679 }
1680
1681
1682 void GLAPIENTRY
1683 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
1684 const GLvoid *ptr)
1685 {
1686 (void) count;
1687 _mesa_ColorPointer(size, type, stride, ptr);
1688 }
1689
1690
1691 void GLAPIENTRY
1692 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1693 const GLvoid *ptr)
1694 {
1695 (void) count;
1696 _mesa_IndexPointer(type, stride, ptr);
1697 }
1698
1699
1700 void GLAPIENTRY
1701 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
1702 GLsizei count, const GLvoid *ptr)
1703 {
1704 (void) count;
1705 _mesa_TexCoordPointer(size, type, stride, ptr);
1706 }
1707
1708
1709 void GLAPIENTRY
1710 _mesa_MultiTexCoordPointerEXT(GLenum texunit, GLint size, GLenum type,
1711 GLsizei stride, const GLvoid *ptr)
1712 {
1713 GET_CURRENT_CONTEXT(ctx);
1714 const GLint sizeMin = 1;
1715 const GLuint unit = texunit - GL_TEXTURE0;
1716
1717 GLenum format = GL_RGBA;
1718 const GLbitfield legalTypes = (SHORT_BIT | INT_BIT |
1719 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1720 UNSIGNED_INT_2_10_10_10_REV_BIT |
1721 INT_2_10_10_10_REV_BIT);
1722
1723 if (!validate_array_and_format(ctx, "glMultiTexCoordPointerEXT",
1724 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1725 VERT_ATTRIB_TEX(unit), legalTypes,
1726 sizeMin, 4, size, type, stride,
1727 GL_FALSE, GL_FALSE, GL_FALSE, format, ptr))
1728 return;
1729
1730 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1731 VERT_ATTRIB_TEX(unit), format, 4, size, type,
1732 stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
1733 }
1734
1735
1736 void GLAPIENTRY
1737 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
1738 {
1739 (void) count;
1740 _mesa_EdgeFlagPointer(stride, ptr);
1741 }
1742
1743
1744 void GLAPIENTRY
1745 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
1746 {
1747 GET_CURRENT_CONTEXT(ctx);
1748 GLboolean tflag, cflag, nflag; /* enable/disable flags */
1749 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
1750 GLenum ctype = 0; /* color type */
1751 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
1752 const GLint toffset = 0; /* always zero */
1753 GLint defstride; /* default stride */
1754 GLint c, f;
1755
1756 f = sizeof(GLfloat);
1757 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
1758
1759 if (stride < 0) {
1760 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
1761 return;
1762 }
1763
1764 switch (format) {
1765 case GL_V2F:
1766 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1767 tcomps = 0; ccomps = 0; vcomps = 2;
1768 voffset = 0;
1769 defstride = 2*f;
1770 break;
1771 case GL_V3F:
1772 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1773 tcomps = 0; ccomps = 0; vcomps = 3;
1774 voffset = 0;
1775 defstride = 3*f;
1776 break;
1777 case GL_C4UB_V2F:
1778 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1779 tcomps = 0; ccomps = 4; vcomps = 2;
1780 ctype = GL_UNSIGNED_BYTE;
1781 coffset = 0;
1782 voffset = c;
1783 defstride = c + 2*f;
1784 break;
1785 case GL_C4UB_V3F:
1786 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1787 tcomps = 0; ccomps = 4; vcomps = 3;
1788 ctype = GL_UNSIGNED_BYTE;
1789 coffset = 0;
1790 voffset = c;
1791 defstride = c + 3*f;
1792 break;
1793 case GL_C3F_V3F:
1794 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1795 tcomps = 0; ccomps = 3; vcomps = 3;
1796 ctype = GL_FLOAT;
1797 coffset = 0;
1798 voffset = 3*f;
1799 defstride = 6*f;
1800 break;
1801 case GL_N3F_V3F:
1802 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1803 tcomps = 0; ccomps = 0; vcomps = 3;
1804 noffset = 0;
1805 voffset = 3*f;
1806 defstride = 6*f;
1807 break;
1808 case GL_C4F_N3F_V3F:
1809 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1810 tcomps = 0; ccomps = 4; vcomps = 3;
1811 ctype = GL_FLOAT;
1812 coffset = 0;
1813 noffset = 4*f;
1814 voffset = 7*f;
1815 defstride = 10*f;
1816 break;
1817 case GL_T2F_V3F:
1818 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1819 tcomps = 2; ccomps = 0; vcomps = 3;
1820 voffset = 2*f;
1821 defstride = 5*f;
1822 break;
1823 case GL_T4F_V4F:
1824 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1825 tcomps = 4; ccomps = 0; vcomps = 4;
1826 voffset = 4*f;
1827 defstride = 8*f;
1828 break;
1829 case GL_T2F_C4UB_V3F:
1830 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1831 tcomps = 2; ccomps = 4; vcomps = 3;
1832 ctype = GL_UNSIGNED_BYTE;
1833 coffset = 2*f;
1834 voffset = c+2*f;
1835 defstride = c+5*f;
1836 break;
1837 case GL_T2F_C3F_V3F:
1838 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1839 tcomps = 2; ccomps = 3; vcomps = 3;
1840 ctype = GL_FLOAT;
1841 coffset = 2*f;
1842 voffset = 5*f;
1843 defstride = 8*f;
1844 break;
1845 case GL_T2F_N3F_V3F:
1846 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1847 tcomps = 2; ccomps = 0; vcomps = 3;
1848 noffset = 2*f;
1849 voffset = 5*f;
1850 defstride = 8*f;
1851 break;
1852 case GL_T2F_C4F_N3F_V3F:
1853 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1854 tcomps = 2; ccomps = 4; vcomps = 3;
1855 ctype = GL_FLOAT;
1856 coffset = 2*f;
1857 noffset = 6*f;
1858 voffset = 9*f;
1859 defstride = 12*f;
1860 break;
1861 case GL_T4F_C4F_N3F_V4F:
1862 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1863 tcomps = 4; ccomps = 4; vcomps = 4;
1864 ctype = GL_FLOAT;
1865 coffset = 4*f;
1866 noffset = 8*f;
1867 voffset = 11*f;
1868 defstride = 15*f;
1869 break;
1870 default:
1871 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
1872 return;
1873 }
1874
1875 if (stride==0) {
1876 stride = defstride;
1877 }
1878
1879 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1880 _mesa_DisableClientState( GL_INDEX_ARRAY );
1881 /* XXX also disable secondary color and generic arrays? */
1882
1883 /* Texcoords */
1884 if (tflag) {
1885 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1886 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
1887 (GLubyte *) pointer + toffset );
1888 }
1889 else {
1890 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
1891 }
1892
1893 /* Color */
1894 if (cflag) {
1895 _mesa_EnableClientState( GL_COLOR_ARRAY );
1896 _mesa_ColorPointer( ccomps, ctype, stride,
1897 (GLubyte *) pointer + coffset );
1898 }
1899 else {
1900 _mesa_DisableClientState( GL_COLOR_ARRAY );
1901 }
1902
1903
1904 /* Normals */
1905 if (nflag) {
1906 _mesa_EnableClientState( GL_NORMAL_ARRAY );
1907 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
1908 }
1909 else {
1910 _mesa_DisableClientState( GL_NORMAL_ARRAY );
1911 }
1912
1913 /* Vertices */
1914 _mesa_EnableClientState( GL_VERTEX_ARRAY );
1915 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
1916 (GLubyte *) pointer + voffset );
1917 }
1918
1919
1920 void GLAPIENTRY
1921 _mesa_LockArraysEXT(GLint first, GLsizei count)
1922 {
1923 GET_CURRENT_CONTEXT(ctx);
1924
1925 if (MESA_VERBOSE & VERBOSE_API)
1926 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
1927
1928 if (first < 0) {
1929 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1930 return;
1931 }
1932 if (count <= 0) {
1933 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1934 return;
1935 }
1936 if (ctx->Array.LockCount != 0) {
1937 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1938 return;
1939 }
1940
1941 ctx->Array.LockFirst = first;
1942 ctx->Array.LockCount = count;
1943 }
1944
1945
1946 void GLAPIENTRY
1947 _mesa_UnlockArraysEXT( void )
1948 {
1949 GET_CURRENT_CONTEXT(ctx);
1950
1951 if (MESA_VERBOSE & VERBOSE_API)
1952 _mesa_debug(ctx, "glUnlockArrays\n");
1953
1954 if (ctx->Array.LockCount == 0) {
1955 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1956 return;
1957 }
1958
1959 ctx->Array.LockFirst = 0;
1960 ctx->Array.LockCount = 0;
1961 }
1962
1963
1964 static void
1965 primitive_restart_index(struct gl_context *ctx, GLuint index)
1966 {
1967 ctx->Array.RestartIndex = index;
1968 }
1969
1970
1971 /**
1972 * GL_NV_primitive_restart and GL 3.1
1973 */
1974 void GLAPIENTRY
1975 _mesa_PrimitiveRestartIndex_no_error(GLuint index)
1976 {
1977 GET_CURRENT_CONTEXT(ctx);
1978 primitive_restart_index(ctx, index);
1979 }
1980
1981
1982 void GLAPIENTRY
1983 _mesa_PrimitiveRestartIndex(GLuint index)
1984 {
1985 GET_CURRENT_CONTEXT(ctx);
1986
1987 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
1988 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
1989 return;
1990 }
1991
1992 primitive_restart_index(ctx, index);
1993 }
1994
1995
1996 void GLAPIENTRY
1997 _mesa_VertexAttribDivisor_no_error(GLuint index, GLuint divisor)
1998 {
1999 GET_CURRENT_CONTEXT(ctx);
2000
2001 const gl_vert_attrib genericIndex = VERT_ATTRIB_GENERIC(index);
2002 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
2003
2004 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
2005
2006 /* The ARB_vertex_attrib_binding spec says:
2007 *
2008 * "The command
2009 *
2010 * void VertexAttribDivisor(uint index, uint divisor);
2011 *
2012 * is equivalent to (assuming no errors are generated):
2013 *
2014 * VertexAttribBinding(index, index);
2015 * VertexBindingDivisor(index, divisor);"
2016 */
2017 _mesa_vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
2018 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
2019 }
2020
2021
2022 /**
2023 * See GL_ARB_instanced_arrays.
2024 * Note that the instance divisor only applies to generic arrays, not
2025 * the legacy vertex arrays.
2026 */
2027 void GLAPIENTRY
2028 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
2029 {
2030 GET_CURRENT_CONTEXT(ctx);
2031
2032 const gl_vert_attrib genericIndex = VERT_ATTRIB_GENERIC(index);
2033 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
2034
2035 if (!ctx->Extensions.ARB_instanced_arrays) {
2036 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
2037 return;
2038 }
2039
2040 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2041 _mesa_error(ctx, GL_INVALID_VALUE,
2042 "glVertexAttribDivisor(index = %u)", index);
2043 return;
2044 }
2045
2046 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
2047
2048 /* The ARB_vertex_attrib_binding spec says:
2049 *
2050 * "The command
2051 *
2052 * void VertexAttribDivisor(uint index, uint divisor);
2053 *
2054 * is equivalent to (assuming no errors are generated):
2055 *
2056 * VertexAttribBinding(index, index);
2057 * VertexBindingDivisor(index, divisor);"
2058 */
2059 _mesa_vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
2060 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
2061 }
2062
2063
2064 static ALWAYS_INLINE void
2065 vertex_array_vertex_buffer(struct gl_context *ctx,
2066 struct gl_vertex_array_object *vao,
2067 GLuint bindingIndex, GLuint buffer, GLintptr offset,
2068 GLsizei stride, bool no_error, const char *func)
2069 {
2070 struct gl_buffer_object *vbo;
2071 if (buffer ==
2072 vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) {
2073 vbo = vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
2074 } else if (buffer != 0) {
2075 vbo = _mesa_lookup_bufferobj(ctx, buffer);
2076
2077 if (!no_error && !vbo && _mesa_is_gles31(ctx)) {
2078 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-gen name)", func);
2079 return;
2080 }
2081 /* From the GL_ARB_vertex_attrib_array spec:
2082 *
2083 * "[Core profile only:]
2084 * An INVALID_OPERATION error is generated if buffer is not zero or a
2085 * name returned from a previous call to GenBuffers, or if such a name
2086 * has since been deleted with DeleteBuffers.
2087 *
2088 * Otherwise, we fall back to the same compat profile behavior as other
2089 * object references (automatically gen it).
2090 */
2091 if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &vbo, func))
2092 return;
2093 } else {
2094 /* The ARB_vertex_attrib_binding spec says:
2095 *
2096 * "If <buffer> is zero, any buffer object attached to this
2097 * bindpoint is detached."
2098 */
2099 vbo = ctx->Shared->NullBufferObj;
2100 }
2101
2102 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex),
2103 vbo, offset, stride);
2104 }
2105
2106
2107 /**
2108 * GL_ARB_vertex_attrib_binding
2109 */
2110 static void
2111 vertex_array_vertex_buffer_err(struct gl_context *ctx,
2112 struct gl_vertex_array_object *vao,
2113 GLuint bindingIndex, GLuint buffer,
2114 GLintptr offset, GLsizei stride,
2115 const char *func)
2116 {
2117 ASSERT_OUTSIDE_BEGIN_END(ctx);
2118
2119 /* The ARB_vertex_attrib_binding spec says:
2120 *
2121 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2122 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2123 */
2124 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2125 _mesa_error(ctx, GL_INVALID_VALUE,
2126 "%s(bindingindex=%u > "
2127 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2128 func, bindingIndex);
2129 return;
2130 }
2131
2132 /* The ARB_vertex_attrib_binding spec says:
2133 *
2134 * "The error INVALID_VALUE is generated if <stride> or <offset>
2135 * are negative."
2136 */
2137 if (offset < 0) {
2138 _mesa_error(ctx, GL_INVALID_VALUE,
2139 "%s(offset=%" PRId64 " < 0)",
2140 func, (int64_t) offset);
2141 return;
2142 }
2143
2144 if (stride < 0) {
2145 _mesa_error(ctx, GL_INVALID_VALUE,
2146 "%s(stride=%d < 0)", func, stride);
2147 return;
2148 }
2149
2150 if (((_mesa_is_desktop_gl(ctx) && ctx->Version >= 44) || _mesa_is_gles31(ctx)) &&
2151 stride > ctx->Const.MaxVertexAttribStride) {
2152 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
2153 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
2154 return;
2155 }
2156
2157 vertex_array_vertex_buffer(ctx, vao, bindingIndex, buffer, offset,
2158 stride, false, func);
2159 }
2160
2161
2162 void GLAPIENTRY
2163 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex, GLuint buffer,
2164 GLintptr offset, GLsizei stride)
2165 {
2166 GET_CURRENT_CONTEXT(ctx);
2167 vertex_array_vertex_buffer(ctx, ctx->Array.VAO, bindingIndex,
2168 buffer, offset, stride, true,
2169 "glBindVertexBuffer");
2170 }
2171
2172
2173 void GLAPIENTRY
2174 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
2175 GLsizei stride)
2176 {
2177 GET_CURRENT_CONTEXT(ctx);
2178
2179 /* The ARB_vertex_attrib_binding spec says:
2180 *
2181 * "An INVALID_OPERATION error is generated if no vertex array object
2182 * is bound."
2183 */
2184 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2185 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2186 _mesa_error(ctx, GL_INVALID_OPERATION,
2187 "glBindVertexBuffer(No array object bound)");
2188 return;
2189 }
2190
2191 vertex_array_vertex_buffer_err(ctx, ctx->Array.VAO, bindingIndex,
2192 buffer, offset, stride,
2193 "glBindVertexBuffer");
2194 }
2195
2196
2197 void GLAPIENTRY
2198 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj, GLuint bindingIndex,
2199 GLuint buffer, GLintptr offset,
2200 GLsizei stride)
2201 {
2202 GET_CURRENT_CONTEXT(ctx);
2203
2204 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2205 vertex_array_vertex_buffer(ctx, vao, bindingIndex, buffer, offset,
2206 stride, true, "glVertexArrayVertexBuffer");
2207 }
2208
2209
2210 void GLAPIENTRY
2211 _mesa_VertexArrayVertexBuffer(GLuint vaobj, GLuint bindingIndex, GLuint buffer,
2212 GLintptr offset, GLsizei stride)
2213 {
2214 GET_CURRENT_CONTEXT(ctx);
2215 struct gl_vertex_array_object *vao;
2216
2217 /* The ARB_direct_state_access specification says:
2218 *
2219 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2220 * if <vaobj> is not [compatibility profile: zero or] the name of an
2221 * existing vertex array object."
2222 */
2223 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffer");
2224 if (!vao)
2225 return;
2226
2227 vertex_array_vertex_buffer_err(ctx, vao, bindingIndex, buffer, offset,
2228 stride, "glVertexArrayVertexBuffer");
2229 }
2230
2231
2232 static ALWAYS_INLINE void
2233 vertex_array_vertex_buffers(struct gl_context *ctx,
2234 struct gl_vertex_array_object *vao,
2235 GLuint first, GLsizei count, const GLuint *buffers,
2236 const GLintptr *offsets, const GLsizei *strides,
2237 bool no_error, const char *func)
2238 {
2239 GLint i;
2240
2241 if (!buffers) {
2242 /**
2243 * The ARB_multi_bind spec says:
2244 *
2245 * "If <buffers> is NULL, each affected vertex buffer binding point
2246 * from <first> through <first>+<count>-1 will be reset to have no
2247 * bound buffer object. In this case, the offsets and strides
2248 * associated with the binding points are set to default values,
2249 * ignoring <offsets> and <strides>."
2250 */
2251 struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj;
2252
2253 for (i = 0; i < count; i++)
2254 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
2255 vbo, 0, 16);
2256
2257 return;
2258 }
2259
2260 /* Note that the error semantics for multi-bind commands differ from
2261 * those of other GL commands.
2262 *
2263 * The Issues section in the ARB_multi_bind spec says:
2264 *
2265 * "(11) Typically, OpenGL specifies that if an error is generated by
2266 * a command, that command has no effect. This is somewhat
2267 * unfortunate for multi-bind commands, because it would require
2268 * a first pass to scan the entire list of bound objects for
2269 * errors and then a second pass to actually perform the
2270 * bindings. Should we have different error semantics?
2271 *
2272 * RESOLVED: Yes. In this specification, when the parameters for
2273 * one of the <count> binding points are invalid, that binding
2274 * point is not updated and an error will be generated. However,
2275 * other binding points in the same command will be updated if
2276 * their parameters are valid and no other error occurs."
2277 */
2278
2279 _mesa_HashLockMutex(ctx->Shared->BufferObjects);
2280
2281 for (i = 0; i < count; i++) {
2282 struct gl_buffer_object *vbo;
2283
2284 if (!no_error) {
2285 /* The ARB_multi_bind spec says:
2286 *
2287 * "An INVALID_VALUE error is generated if any value in
2288 * <offsets> or <strides> is negative (per binding)."
2289 */
2290 if (offsets[i] < 0) {
2291 _mesa_error(ctx, GL_INVALID_VALUE,
2292 "%s(offsets[%u]=%" PRId64 " < 0)",
2293 func, i, (int64_t) offsets[i]);
2294 continue;
2295 }
2296
2297 if (strides[i] < 0) {
2298 _mesa_error(ctx, GL_INVALID_VALUE,
2299 "%s(strides[%u]=%d < 0)",
2300 func, i, strides[i]);
2301 continue;
2302 }
2303
2304 if (_mesa_is_desktop_gl(ctx) && ctx->Version >= 44 &&
2305 strides[i] > ctx->Const.MaxVertexAttribStride) {
2306 _mesa_error(ctx, GL_INVALID_VALUE,
2307 "%s(strides[%u]=%d > "
2308 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, i, strides[i]);
2309 continue;
2310 }
2311 }
2312
2313 if (buffers[i]) {
2314 struct gl_vertex_buffer_binding *binding =
2315 &vao->BufferBinding[VERT_ATTRIB_GENERIC(first + i)];
2316
2317 if (buffers[i] == binding->BufferObj->Name)
2318 vbo = binding->BufferObj;
2319 else
2320 vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, func);
2321
2322 if (!vbo)
2323 continue;
2324 } else {
2325 vbo = ctx->Shared->NullBufferObj;
2326 }
2327
2328 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
2329 vbo, offsets[i], strides[i]);
2330 }
2331
2332 _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
2333 }
2334
2335
2336 static void
2337 vertex_array_vertex_buffers_err(struct gl_context *ctx,
2338 struct gl_vertex_array_object *vao,
2339 GLuint first, GLsizei count,
2340 const GLuint *buffers, const GLintptr *offsets,
2341 const GLsizei *strides, const char *func)
2342 {
2343 ASSERT_OUTSIDE_BEGIN_END(ctx);
2344
2345 /* The ARB_multi_bind spec says:
2346 *
2347 * "An INVALID_OPERATION error is generated if <first> + <count>
2348 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
2349 */
2350 if (first + count > ctx->Const.MaxVertexAttribBindings) {
2351 _mesa_error(ctx, GL_INVALID_OPERATION,
2352 "%s(first=%u + count=%d > the value of "
2353 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
2354 func, first, count, ctx->Const.MaxVertexAttribBindings);
2355 return;
2356 }
2357
2358 vertex_array_vertex_buffers(ctx, vao, first, count, buffers, offsets,
2359 strides, false, func);
2360 }
2361
2362
2363 void GLAPIENTRY
2364 _mesa_BindVertexBuffers_no_error(GLuint first, GLsizei count,
2365 const GLuint *buffers, const GLintptr *offsets,
2366 const GLsizei *strides)
2367 {
2368 GET_CURRENT_CONTEXT(ctx);
2369
2370 vertex_array_vertex_buffers(ctx, ctx->Array.VAO, first, count,
2371 buffers, offsets, strides, true,
2372 "glBindVertexBuffers");
2373 }
2374
2375
2376 void GLAPIENTRY
2377 _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
2378 const GLintptr *offsets, const GLsizei *strides)
2379 {
2380 GET_CURRENT_CONTEXT(ctx);
2381
2382 /* The ARB_vertex_attrib_binding spec says:
2383 *
2384 * "An INVALID_OPERATION error is generated if no
2385 * vertex array object is bound."
2386 */
2387 if (ctx->API == API_OPENGL_CORE &&
2388 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2389 _mesa_error(ctx, GL_INVALID_OPERATION,
2390 "glBindVertexBuffers(No array object bound)");
2391 return;
2392 }
2393
2394 vertex_array_vertex_buffers_err(ctx, ctx->Array.VAO, first, count,
2395 buffers, offsets, strides,
2396 "glBindVertexBuffers");
2397 }
2398
2399
2400 void GLAPIENTRY
2401 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj, GLuint first,
2402 GLsizei count, const GLuint *buffers,
2403 const GLintptr *offsets,
2404 const GLsizei *strides)
2405 {
2406 GET_CURRENT_CONTEXT(ctx);
2407
2408 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2409 vertex_array_vertex_buffers(ctx, vao, first, count,
2410 buffers, offsets, strides, true,
2411 "glVertexArrayVertexBuffers");
2412 }
2413
2414
2415 void GLAPIENTRY
2416 _mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count,
2417 const GLuint *buffers,
2418 const GLintptr *offsets, const GLsizei *strides)
2419 {
2420 GET_CURRENT_CONTEXT(ctx);
2421 struct gl_vertex_array_object *vao;
2422
2423 /* The ARB_direct_state_access specification says:
2424 *
2425 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2426 * if <vaobj> is not [compatibility profile: zero or] the name of an
2427 * existing vertex array object."
2428 */
2429 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffers");
2430 if (!vao)
2431 return;
2432
2433 vertex_array_vertex_buffers_err(ctx, vao, first, count,
2434 buffers, offsets, strides,
2435 "glVertexArrayVertexBuffers");
2436 }
2437
2438
2439 static void
2440 vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type,
2441 GLboolean normalized, GLboolean integer,
2442 GLboolean doubles, GLbitfield legalTypes,
2443 GLsizei sizeMax, GLuint relativeOffset,
2444 const char *func)
2445 {
2446 GET_CURRENT_CONTEXT(ctx);
2447 ASSERT_OUTSIDE_BEGIN_END(ctx);
2448
2449 GLenum format = get_array_format(ctx, sizeMax, &size);
2450
2451 if (!_mesa_is_no_error_enabled(ctx)) {
2452 /* The ARB_vertex_attrib_binding spec says:
2453 *
2454 * "An INVALID_OPERATION error is generated under any of the
2455 * following conditions:
2456 * - if no vertex array object is currently bound (see section
2457 * 2.10);
2458 * - ..."
2459 *
2460 * This error condition only applies to VertexAttribFormat and
2461 * VertexAttribIFormat in the extension spec, but we assume that this
2462 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2463 * to all three functions.
2464 */
2465 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2466 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2467 _mesa_error(ctx, GL_INVALID_OPERATION,
2468 "%s(No array object bound)", func);
2469 return;
2470 }
2471
2472 /* The ARB_vertex_attrib_binding spec says:
2473 *
2474 * "The error INVALID_VALUE is generated if index is greater than or
2475 * equal to the value of MAX_VERTEX_ATTRIBS."
2476 */
2477 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2478 _mesa_error(ctx, GL_INVALID_VALUE,
2479 "%s(attribindex=%u > "
2480 "GL_MAX_VERTEX_ATTRIBS)",
2481 func, attribIndex);
2482 return;
2483 }
2484
2485 if (!validate_array_format(ctx, func, ctx->Array.VAO,
2486 VERT_ATTRIB_GENERIC(attribIndex),
2487 legalTypes, 1, sizeMax, size, type,
2488 normalized, integer, doubles, relativeOffset,
2489 format)) {
2490 return;
2491 }
2492 }
2493
2494 _mesa_update_array_format(ctx, ctx->Array.VAO,
2495 VERT_ATTRIB_GENERIC(attribIndex), size, type,
2496 format, normalized, integer, doubles,
2497 relativeOffset);
2498 }
2499
2500
2501 void GLAPIENTRY
2502 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
2503 GLboolean normalized, GLuint relativeOffset)
2504 {
2505 vertex_attrib_format(attribIndex, size, type, normalized,
2506 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
2507 BGRA_OR_4, relativeOffset,
2508 "glVertexAttribFormat");
2509 }
2510
2511
2512 void GLAPIENTRY
2513 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
2514 GLuint relativeOffset)
2515 {
2516 vertex_attrib_format(attribIndex, size, type, GL_FALSE,
2517 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK, 4,
2518 relativeOffset, "glVertexAttribIFormat");
2519 }
2520
2521
2522 void GLAPIENTRY
2523 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
2524 GLuint relativeOffset)
2525 {
2526 vertex_attrib_format(attribIndex, size, type, GL_FALSE, GL_FALSE,
2527 GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK, 4,
2528 relativeOffset, "glVertexAttribLFormat");
2529 }
2530
2531
2532 static void
2533 vertex_array_attrib_format(GLuint vaobj, GLuint attribIndex, GLint size,
2534 GLenum type, GLboolean normalized,
2535 GLboolean integer, GLboolean doubles,
2536 GLbitfield legalTypes, GLsizei sizeMax,
2537 GLuint relativeOffset, const char *func)
2538 {
2539 GET_CURRENT_CONTEXT(ctx);
2540 struct gl_vertex_array_object *vao;
2541
2542 ASSERT_OUTSIDE_BEGIN_END(ctx);
2543
2544 GLenum format = get_array_format(ctx, sizeMax, &size);
2545
2546 if (_mesa_is_no_error_enabled(ctx)) {
2547 vao = _mesa_lookup_vao(ctx, vaobj);
2548 if (!vao)
2549 return;
2550 } else {
2551 /* The ARB_direct_state_access spec says:
2552 *
2553 * "An INVALID_OPERATION error is generated by
2554 * VertexArrayAttrib*Format if <vaobj> is not [compatibility profile:
2555 * zero or] the name of an existing vertex array object."
2556 */
2557 vao = _mesa_lookup_vao_err(ctx, vaobj, func);
2558 if (!vao)
2559 return;
2560
2561 /* The ARB_vertex_attrib_binding spec says:
2562 *
2563 * "The error INVALID_VALUE is generated if index is greater than or
2564 * equal to the value of MAX_VERTEX_ATTRIBS."
2565 */
2566 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2567 _mesa_error(ctx, GL_INVALID_VALUE,
2568 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2569 func, attribIndex);
2570 return;
2571 }
2572
2573 if (!validate_array_format(ctx, func, vao,
2574 VERT_ATTRIB_GENERIC(attribIndex),
2575 legalTypes, 1, sizeMax, size, type,
2576 normalized, integer, doubles, relativeOffset,
2577 format)) {
2578 return;
2579 }
2580 }
2581
2582 _mesa_update_array_format(ctx, vao, VERT_ATTRIB_GENERIC(attribIndex), size,
2583 type, format, normalized, integer, doubles,
2584 relativeOffset);
2585 }
2586
2587
2588 void GLAPIENTRY
2589 _mesa_VertexArrayAttribFormat(GLuint vaobj, GLuint attribIndex, GLint size,
2590 GLenum type, GLboolean normalized,
2591 GLuint relativeOffset)
2592 {
2593 vertex_array_attrib_format(vaobj, attribIndex, size, type, normalized,
2594 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
2595 BGRA_OR_4, relativeOffset,
2596 "glVertexArrayAttribFormat");
2597 }
2598
2599
2600 void GLAPIENTRY
2601 _mesa_VertexArrayAttribIFormat(GLuint vaobj, GLuint attribIndex,
2602 GLint size, GLenum type,
2603 GLuint relativeOffset)
2604 {
2605 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2606 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK,
2607 4, relativeOffset,
2608 "glVertexArrayAttribIFormat");
2609 }
2610
2611
2612 void GLAPIENTRY
2613 _mesa_VertexArrayAttribLFormat(GLuint vaobj, GLuint attribIndex,
2614 GLint size, GLenum type,
2615 GLuint relativeOffset)
2616 {
2617 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2618 GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK,
2619 4, relativeOffset,
2620 "glVertexArrayAttribLFormat");
2621 }
2622
2623
2624 static void
2625 vertex_array_attrib_binding(struct gl_context *ctx,
2626 struct gl_vertex_array_object *vao,
2627 GLuint attribIndex, GLuint bindingIndex,
2628 const char *func)
2629 {
2630 ASSERT_OUTSIDE_BEGIN_END(ctx);
2631
2632 /* The ARB_vertex_attrib_binding spec says:
2633 *
2634 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2635 * <bindingindex> must be less than the value of
2636 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2637 * is generated."
2638 */
2639 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2640 _mesa_error(ctx, GL_INVALID_VALUE,
2641 "%s(attribindex=%u >= "
2642 "GL_MAX_VERTEX_ATTRIBS)",
2643 func, attribIndex);
2644 return;
2645 }
2646
2647 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2648 _mesa_error(ctx, GL_INVALID_VALUE,
2649 "%s(bindingindex=%u >= "
2650 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2651 func, bindingIndex);
2652 return;
2653 }
2654
2655 assert(VERT_ATTRIB_GENERIC(attribIndex) < ARRAY_SIZE(vao->VertexAttrib));
2656
2657 _mesa_vertex_attrib_binding(ctx, vao,
2658 VERT_ATTRIB_GENERIC(attribIndex),
2659 VERT_ATTRIB_GENERIC(bindingIndex));
2660 }
2661
2662
2663 void GLAPIENTRY
2664 _mesa_VertexAttribBinding_no_error(GLuint attribIndex, GLuint bindingIndex)
2665 {
2666 GET_CURRENT_CONTEXT(ctx);
2667 _mesa_vertex_attrib_binding(ctx, ctx->Array.VAO,
2668 VERT_ATTRIB_GENERIC(attribIndex),
2669 VERT_ATTRIB_GENERIC(bindingIndex));
2670 }
2671
2672
2673 void GLAPIENTRY
2674 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
2675 {
2676 GET_CURRENT_CONTEXT(ctx);
2677
2678 /* The ARB_vertex_attrib_binding spec says:
2679 *
2680 * "An INVALID_OPERATION error is generated if no vertex array object
2681 * is bound."
2682 */
2683 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2684 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2685 _mesa_error(ctx, GL_INVALID_OPERATION,
2686 "glVertexAttribBinding(No array object bound)");
2687 return;
2688 }
2689
2690 vertex_array_attrib_binding(ctx, ctx->Array.VAO,
2691 attribIndex, bindingIndex,
2692 "glVertexAttribBinding");
2693 }
2694
2695
2696 void GLAPIENTRY
2697 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj, GLuint attribIndex,
2698 GLuint bindingIndex)
2699 {
2700 GET_CURRENT_CONTEXT(ctx);
2701
2702 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2703 _mesa_vertex_attrib_binding(ctx, vao,
2704 VERT_ATTRIB_GENERIC(attribIndex),
2705 VERT_ATTRIB_GENERIC(bindingIndex));
2706 }
2707
2708
2709 void GLAPIENTRY
2710 _mesa_VertexArrayAttribBinding(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex)
2711 {
2712 GET_CURRENT_CONTEXT(ctx);
2713 struct gl_vertex_array_object *vao;
2714
2715 /* The ARB_direct_state_access specification says:
2716 *
2717 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2718 * if <vaobj> is not [compatibility profile: zero or] the name of an
2719 * existing vertex array object."
2720 */
2721 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayAttribBinding");
2722 if (!vao)
2723 return;
2724
2725 vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex,
2726 "glVertexArrayAttribBinding");
2727 }
2728
2729
2730 static void
2731 vertex_array_binding_divisor(struct gl_context *ctx,
2732 struct gl_vertex_array_object *vao,
2733 GLuint bindingIndex, GLuint divisor,
2734 const char *func)
2735 {
2736 ASSERT_OUTSIDE_BEGIN_END(ctx);
2737
2738 if (!ctx->Extensions.ARB_instanced_arrays) {
2739 _mesa_error(ctx, GL_INVALID_OPERATION, "%s()", func);
2740 return;
2741 }
2742
2743 /* The ARB_vertex_attrib_binding spec says:
2744 *
2745 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2746 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2747 */
2748 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2749 _mesa_error(ctx, GL_INVALID_VALUE,
2750 "%s(bindingindex=%u > "
2751 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2752 func, bindingIndex);
2753 return;
2754 }
2755
2756 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
2757 }
2758
2759
2760 void GLAPIENTRY
2761 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex, GLuint divisor)
2762 {
2763 GET_CURRENT_CONTEXT(ctx);
2764 vertex_binding_divisor(ctx, ctx->Array.VAO,
2765 VERT_ATTRIB_GENERIC(bindingIndex), divisor);
2766 }
2767
2768
2769 void GLAPIENTRY
2770 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
2771 {
2772 GET_CURRENT_CONTEXT(ctx);
2773
2774 /* The ARB_vertex_attrib_binding spec says:
2775 *
2776 * "An INVALID_OPERATION error is generated if no vertex array object
2777 * is bound."
2778 */
2779 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2780 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2781 _mesa_error(ctx, GL_INVALID_OPERATION,
2782 "glVertexBindingDivisor(No array object bound)");
2783 return;
2784 }
2785
2786 vertex_array_binding_divisor(ctx, ctx->Array.VAO,
2787 bindingIndex, divisor,
2788 "glVertexBindingDivisor");
2789 }
2790
2791
2792 void GLAPIENTRY
2793 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj, GLuint bindingIndex,
2794 GLuint divisor)
2795 {
2796 GET_CURRENT_CONTEXT(ctx);
2797
2798 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2799 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
2800 }
2801
2802
2803 void GLAPIENTRY
2804 _mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex,
2805 GLuint divisor)
2806 {
2807 struct gl_vertex_array_object *vao;
2808 GET_CURRENT_CONTEXT(ctx);
2809
2810 /* The ARB_direct_state_access specification says:
2811 *
2812 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2813 * if <vaobj> is not [compatibility profile: zero or] the name of an
2814 * existing vertex array object."
2815 */
2816 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayBindingDivisor");
2817 if (!vao)
2818 return;
2819
2820 vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor,
2821 "glVertexArrayBindingDivisor");
2822 }
2823
2824
2825 void
2826 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
2827 struct gl_array_attributes *dst,
2828 const struct gl_array_attributes *src)
2829 {
2830 dst->Ptr = src->Ptr;
2831 dst->RelativeOffset = src->RelativeOffset;
2832 dst->Format = src->Format;
2833 dst->Stride = src->Stride;
2834 dst->BufferBindingIndex = src->BufferBindingIndex;
2835 dst->_EffBufferBindingIndex = src->_EffBufferBindingIndex;
2836 dst->_EffRelativeOffset = src->_EffRelativeOffset;
2837 }
2838
2839 void
2840 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
2841 struct gl_vertex_buffer_binding *dst,
2842 const struct gl_vertex_buffer_binding *src)
2843 {
2844 dst->Offset = src->Offset;
2845 dst->Stride = src->Stride;
2846 dst->InstanceDivisor = src->InstanceDivisor;
2847 dst->_BoundArrays = src->_BoundArrays;
2848 dst->_EffBoundArrays = src->_EffBoundArrays;
2849 dst->_EffOffset = src->_EffOffset;
2850
2851 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
2852 }
2853
2854 /**
2855 * Print current vertex object/array info. For debug.
2856 */
2857 void
2858 _mesa_print_arrays(struct gl_context *ctx)
2859 {
2860 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
2861
2862 fprintf(stderr, "Array Object %u\n", vao->Name);
2863
2864 GLbitfield mask = vao->Enabled;
2865 while (mask) {
2866 const gl_vert_attrib i = u_bit_scan(&mask);
2867 const struct gl_array_attributes *array = &vao->VertexAttrib[i];
2868
2869 const struct gl_vertex_buffer_binding *binding =
2870 &vao->BufferBinding[array->BufferBindingIndex];
2871 const struct gl_buffer_object *bo = binding->BufferObj;
2872
2873 fprintf(stderr, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2874 "Stride=%d, Buffer=%u(Size %lu)\n",
2875 gl_vert_attrib_name((gl_vert_attrib)i),
2876 array->Ptr, _mesa_enum_to_string(array->Format.Type),
2877 array->Format.Size,
2878 array->Format._ElementSize, binding->Stride, bo->Name,
2879 (unsigned long) bo->Size);
2880 }
2881 }
2882
2883
2884 /**
2885 * Initialize vertex array state for given context.
2886 */
2887 void
2888 _mesa_init_varray(struct gl_context *ctx)
2889 {
2890 ctx->Array.DefaultVAO = _mesa_new_vao(ctx, 0);
2891 _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO);
2892 ctx->Array._EmptyVAO = _mesa_new_vao(ctx, ~0u);
2893 _mesa_reference_vao(ctx, &ctx->Array._DrawVAO, ctx->Array._EmptyVAO);
2894 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
2895
2896 ctx->Array.Objects = _mesa_NewHashTable();
2897 }
2898
2899
2900 /**
2901 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2902 */
2903 static void
2904 delete_arrayobj_cb(GLuint id, void *data, void *userData)
2905 {
2906 struct gl_vertex_array_object *vao = (struct gl_vertex_array_object *) data;
2907 struct gl_context *ctx = (struct gl_context *) userData;
2908 _mesa_delete_vao(ctx, vao);
2909 }
2910
2911
2912 /**
2913 * Free vertex array state for given context.
2914 */
2915 void
2916 _mesa_free_varray_data(struct gl_context *ctx)
2917 {
2918 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
2919 _mesa_DeleteHashTable(ctx->Array.Objects);
2920 }