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