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