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