mesa: add EXT_dsa EnableVertexArrayAttribEXT / DisableVertexArrayAttribEXT
[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
629 /* Helper function for all EXT_direct_state_access glVertexArray* functions */
630 static bool
631 _lookup_vao_and_vbo_dsa(struct gl_context *ctx,
632 GLuint vaobj, GLuint buffer,
633 GLintptr offset,
634 struct gl_vertex_array_object** vao,
635 struct gl_buffer_object** vbo,
636 const char* caller)
637 {
638 *vao = _mesa_lookup_vao_err(ctx, vaobj, true, caller);
639 if (!(*vao))
640 return false;
641
642 if (buffer != 0) {
643 *vbo = _mesa_lookup_bufferobj(ctx, buffer);
644 if (!_mesa_handle_bind_buffer_gen(ctx, buffer, vbo, caller))
645 return false;
646
647 if (offset < 0) {
648 _mesa_error(ctx, GL_INVALID_VALUE,
649 "%s(negative offset with non-0 buffer)", caller);
650 return false;
651 }
652 } else {
653 *vbo = ctx->Shared->NullBufferObj;
654 }
655
656 return true;
657 }
658
659
660 void GLAPIENTRY
661 _mesa_VertexPointer_no_error(GLint size, GLenum type, GLsizei stride,
662 const GLvoid *ptr)
663 {
664 GET_CURRENT_CONTEXT(ctx);
665
666 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
667 VERT_ATTRIB_POS, GL_RGBA, 4, size, type, stride,
668 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
669 }
670
671
672 void GLAPIENTRY
673 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
674 {
675 GET_CURRENT_CONTEXT(ctx);
676
677 GLenum format = GL_RGBA;
678 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
679 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
680 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
681 DOUBLE_BIT | HALF_BIT |
682 UNSIGNED_INT_2_10_10_10_REV_BIT |
683 INT_2_10_10_10_REV_BIT);
684
685 if (!validate_array_and_format(ctx, "glVertexPointer",
686 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
687 VERT_ATTRIB_POS, legalTypes, 2, 4, size,
688 type, stride, GL_FALSE, GL_FALSE, GL_FALSE,
689 format, ptr))
690 return;
691
692 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
693 VERT_ATTRIB_POS, format, 4, size, type, stride,
694 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
695 }
696
697
698 void GLAPIENTRY
699 _mesa_VertexArrayVertexOffsetEXT(GLuint vaobj, GLuint buffer, GLint size,
700 GLenum type, GLsizei stride, GLintptr offset)
701 {
702 GET_CURRENT_CONTEXT(ctx);
703
704 GLenum format = GL_RGBA;
705 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
706 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
707 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
708 DOUBLE_BIT | HALF_BIT |
709 UNSIGNED_INT_2_10_10_10_REV_BIT |
710 INT_2_10_10_10_REV_BIT);
711
712 struct gl_vertex_array_object* vao;
713 struct gl_buffer_object* vbo;
714
715 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
716 &vao, &vbo,
717 "glVertexArrayVertexOffsetEXT"))
718 return;
719
720 if (!validate_array_and_format(ctx, "glVertexArrayVertexOffsetEXT",
721 vao, vbo,
722 VERT_ATTRIB_POS, legalTypes, 2, 4, size,
723 type, stride, GL_FALSE, GL_FALSE, GL_FALSE,
724 format, (void*) offset))
725 return;
726
727 update_array(ctx, vao, vbo,
728 VERT_ATTRIB_POS, format, 4, size, type, stride,
729 GL_FALSE, GL_FALSE, GL_FALSE, (void*) offset);
730 }
731
732
733 void GLAPIENTRY
734 _mesa_NormalPointer_no_error(GLenum type, GLsizei stride, const GLvoid *ptr )
735 {
736 GET_CURRENT_CONTEXT(ctx);
737
738 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
739 VERT_ATTRIB_NORMAL, GL_RGBA, 3, 3, type, stride, GL_TRUE,
740 GL_FALSE, GL_FALSE, ptr);
741 }
742
743
744 void GLAPIENTRY
745 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
746 {
747 GET_CURRENT_CONTEXT(ctx);
748
749 GLenum format = GL_RGBA;
750 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
751 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
752 : (BYTE_BIT | SHORT_BIT | INT_BIT |
753 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
754 UNSIGNED_INT_2_10_10_10_REV_BIT |
755 INT_2_10_10_10_REV_BIT);
756
757 if (!validate_array_and_format(ctx, "glNormalPointer",
758 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
759 VERT_ATTRIB_NORMAL, legalTypes, 3, 3, 3,
760 type, stride, GL_TRUE, GL_FALSE,
761 GL_FALSE, format, ptr))
762 return;
763
764 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
765 VERT_ATTRIB_NORMAL, format, 3, 3, type, stride, GL_TRUE,
766 GL_FALSE, GL_FALSE, ptr);
767 }
768
769
770 void GLAPIENTRY
771 _mesa_VertexArrayNormalOffsetEXT(GLuint vaobj, GLuint buffer, GLenum type,
772 GLsizei stride, GLintptr offset)
773 {
774 GET_CURRENT_CONTEXT(ctx);
775
776 GLenum format = GL_RGBA;
777 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
778 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
779 : (BYTE_BIT | SHORT_BIT | INT_BIT |
780 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
781 UNSIGNED_INT_2_10_10_10_REV_BIT |
782 INT_2_10_10_10_REV_BIT);
783
784 struct gl_vertex_array_object* vao;
785 struct gl_buffer_object* vbo;
786
787 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
788 &vao, &vbo,
789 "glNormalPointer"))
790 return;
791
792 if (!validate_array_and_format(ctx, "glNormalPointer",
793 vao, vbo,
794 VERT_ATTRIB_NORMAL, legalTypes, 3, 3, 3,
795 type, stride, GL_TRUE, GL_FALSE,
796 GL_FALSE, format, (void*) offset))
797 return;
798
799 update_array(ctx, vao, vbo,
800 VERT_ATTRIB_NORMAL, format, 3, 3, type, stride, GL_TRUE,
801 GL_FALSE, GL_FALSE, (void*) offset);
802 }
803
804
805 void GLAPIENTRY
806 _mesa_ColorPointer_no_error(GLint size, GLenum type, GLsizei stride,
807 const GLvoid *ptr)
808 {
809 GET_CURRENT_CONTEXT(ctx);
810
811 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
812 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
813 VERT_ATTRIB_COLOR0, format, BGRA_OR_4, size,
814 type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
815 }
816
817
818 void GLAPIENTRY
819 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
820 {
821 GET_CURRENT_CONTEXT(ctx);
822 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
823
824 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
825 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
826 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
827 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
828 SHORT_BIT | UNSIGNED_SHORT_BIT |
829 INT_BIT | UNSIGNED_INT_BIT |
830 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
831 UNSIGNED_INT_2_10_10_10_REV_BIT |
832 INT_2_10_10_10_REV_BIT);
833
834 if (!validate_array_and_format(ctx, "glColorPointer",
835 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
836 VERT_ATTRIB_COLOR0, legalTypes, sizeMin,
837 BGRA_OR_4, size, type, stride, GL_TRUE,
838 GL_FALSE, GL_FALSE, format, ptr))
839 return;
840
841 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
842 VERT_ATTRIB_COLOR0, format, BGRA_OR_4, size,
843 type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
844 }
845
846
847 void GLAPIENTRY
848 _mesa_VertexArrayColorOffsetEXT(GLuint vaobj, GLuint buffer, GLint size,
849 GLenum type, GLsizei stride, GLintptr offset)
850 {
851 GET_CURRENT_CONTEXT(ctx);
852 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
853
854 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
855 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
856 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
857 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
858 SHORT_BIT | UNSIGNED_SHORT_BIT |
859 INT_BIT | UNSIGNED_INT_BIT |
860 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
861 UNSIGNED_INT_2_10_10_10_REV_BIT |
862 INT_2_10_10_10_REV_BIT);
863
864 struct gl_vertex_array_object* vao;
865 struct gl_buffer_object* vbo;
866
867 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
868 &vao, &vbo,
869 "glVertexArrayColorOffsetEXT"))
870 return;
871
872 if (!validate_array_and_format(ctx, "glVertexArrayColorOffsetEXT",
873 vao, vbo,
874 VERT_ATTRIB_COLOR0, legalTypes, sizeMin,
875 BGRA_OR_4, size, type, stride, GL_TRUE,
876 GL_FALSE, GL_FALSE, format, (void*) offset))
877 return;
878
879 update_array(ctx, vao, vbo,
880 VERT_ATTRIB_COLOR0, format, BGRA_OR_4, size,
881 type, stride, GL_TRUE, GL_FALSE, GL_FALSE, (void*) offset);
882 }
883
884
885 void GLAPIENTRY
886 _mesa_FogCoordPointer_no_error(GLenum type, GLsizei stride, const GLvoid *ptr)
887 {
888 GET_CURRENT_CONTEXT(ctx);
889
890 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
891 VERT_ATTRIB_FOG, GL_RGBA, 1, 1, type, stride, GL_FALSE,
892 GL_FALSE, GL_FALSE, ptr);
893 }
894
895
896 void GLAPIENTRY
897 _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
898 {
899 GET_CURRENT_CONTEXT(ctx);
900
901 GLenum format = GL_RGBA;
902 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
903
904 if (!validate_array_and_format(ctx, "glFogCoordPointer",
905 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
906 VERT_ATTRIB_FOG, legalTypes, 1, 1, 1,
907 type, stride, GL_FALSE, GL_FALSE,
908 GL_FALSE, format, ptr))
909 return;
910
911 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
912 VERT_ATTRIB_FOG, format, 1, 1, type, stride, GL_FALSE,
913 GL_FALSE, GL_FALSE, ptr);
914 }
915
916
917 void GLAPIENTRY
918 _mesa_VertexArrayFogCoordOffsetEXT(GLuint vaobj, GLuint buffer, GLenum type,
919 GLsizei stride, GLintptr offset)
920 {
921 GET_CURRENT_CONTEXT(ctx);
922
923 GLenum format = GL_RGBA;
924 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
925
926 struct gl_vertex_array_object* vao;
927 struct gl_buffer_object* vbo;
928
929 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
930 &vao, &vbo,
931 "glVertexArrayFogCoordOffsetEXT"))
932 return;
933
934 if (!validate_array_and_format(ctx, "glVertexArrayFogCoordOffsetEXT",
935 vao, vbo,
936 VERT_ATTRIB_FOG, legalTypes, 1, 1, 1,
937 type, stride, GL_FALSE, GL_FALSE,
938 GL_FALSE, format, (void*) offset))
939 return;
940
941 update_array(ctx, vao, vbo,
942 VERT_ATTRIB_FOG, format, 1, 1, type, stride, GL_FALSE,
943 GL_FALSE, GL_FALSE, (void*) offset);
944 }
945
946
947 void GLAPIENTRY
948 _mesa_IndexPointer_no_error(GLenum type, GLsizei stride, const GLvoid *ptr)
949 {
950 GET_CURRENT_CONTEXT(ctx);
951
952 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
953 VERT_ATTRIB_COLOR_INDEX, GL_RGBA, 1, 1, type, stride,
954 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
955 }
956
957
958 void GLAPIENTRY
959 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
960 {
961 GET_CURRENT_CONTEXT(ctx);
962
963 GLenum format = GL_RGBA;
964 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
965 FLOAT_BIT | DOUBLE_BIT);
966
967 if (!validate_array_and_format(ctx, "glIndexPointer",
968 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
969 VERT_ATTRIB_COLOR_INDEX,
970 legalTypes, 1, 1, 1, type, stride,
971 GL_FALSE, GL_FALSE, GL_FALSE, format, ptr))
972 return;
973
974 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
975 VERT_ATTRIB_COLOR_INDEX, format, 1, 1, type, stride,
976 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
977 }
978
979
980 void GLAPIENTRY
981 _mesa_VertexArrayIndexOffsetEXT(GLuint vaobj, GLuint buffer, GLenum type,
982 GLsizei stride, GLintptr offset)
983 {
984 GET_CURRENT_CONTEXT(ctx);
985
986 GLenum format = GL_RGBA;
987 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
988 FLOAT_BIT | DOUBLE_BIT);
989
990 struct gl_vertex_array_object* vao;
991 struct gl_buffer_object* vbo;
992
993 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
994 &vao, &vbo,
995 "glVertexArrayIndexOffsetEXT"))
996 return;
997
998 if (!validate_array_and_format(ctx, "glVertexArrayIndexOffsetEXT",
999 vao, vbo,
1000 VERT_ATTRIB_COLOR_INDEX,
1001 legalTypes, 1, 1, 1, type, stride,
1002 GL_FALSE, GL_FALSE, GL_FALSE, format, (void*) offset))
1003 return;
1004
1005 update_array(ctx, vao, vbo,
1006 VERT_ATTRIB_COLOR_INDEX, format, 1, 1, type, stride,
1007 GL_FALSE, GL_FALSE, GL_FALSE, (void*) offset);
1008 }
1009
1010
1011 void GLAPIENTRY
1012 _mesa_SecondaryColorPointer_no_error(GLint size, GLenum type,
1013 GLsizei stride, const GLvoid *ptr)
1014 {
1015 GET_CURRENT_CONTEXT(ctx);
1016
1017 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1018 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1019 VERT_ATTRIB_COLOR1, format, BGRA_OR_4, size, type,
1020 stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
1021 }
1022
1023
1024 void GLAPIENTRY
1025 _mesa_SecondaryColorPointer(GLint size, GLenum type,
1026 GLsizei stride, const GLvoid *ptr)
1027 {
1028 GET_CURRENT_CONTEXT(ctx);
1029
1030 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1031 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1032 SHORT_BIT | UNSIGNED_SHORT_BIT |
1033 INT_BIT | UNSIGNED_INT_BIT |
1034 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1035 UNSIGNED_INT_2_10_10_10_REV_BIT |
1036 INT_2_10_10_10_REV_BIT);
1037
1038 if (!validate_array_and_format(ctx, "glSecondaryColorPointer",
1039 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1040 VERT_ATTRIB_COLOR1, legalTypes, 3,
1041 BGRA_OR_4, size, type, stride,
1042 GL_TRUE, GL_FALSE, GL_FALSE, format, ptr))
1043 return;
1044
1045 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1046 VERT_ATTRIB_COLOR1, format, BGRA_OR_4, size, type,
1047 stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
1048 }
1049
1050
1051 void GLAPIENTRY
1052 _mesa_VertexArraySecondaryColorOffsetEXT(GLuint vaobj, GLuint buffer, GLint size,
1053 GLenum type, GLsizei stride, GLintptr offset)
1054 {
1055 GET_CURRENT_CONTEXT(ctx);
1056
1057 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1058 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1059 SHORT_BIT | UNSIGNED_SHORT_BIT |
1060 INT_BIT | UNSIGNED_INT_BIT |
1061 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1062 UNSIGNED_INT_2_10_10_10_REV_BIT |
1063 INT_2_10_10_10_REV_BIT);
1064
1065 struct gl_vertex_array_object* vao;
1066 struct gl_buffer_object* vbo;
1067
1068 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1069 &vao, &vbo,
1070 "glVertexArraySecondaryColorOffsetEXT"))
1071 return;
1072
1073 if (!validate_array_and_format(ctx, "glVertexArraySecondaryColorOffsetEXT",
1074 vao, vbo,
1075 VERT_ATTRIB_COLOR1, legalTypes, 3,
1076 BGRA_OR_4, size, type, stride,
1077 GL_TRUE, GL_FALSE, GL_FALSE, format, (void*) offset))
1078 return;
1079
1080 update_array(ctx, vao, vbo,
1081 VERT_ATTRIB_COLOR1, format, BGRA_OR_4, size, type,
1082 stride, GL_TRUE, GL_FALSE, GL_FALSE, (void*) offset);
1083 }
1084
1085
1086 void GLAPIENTRY
1087 _mesa_TexCoordPointer_no_error(GLint size, GLenum type, GLsizei stride,
1088 const GLvoid *ptr)
1089 {
1090 GET_CURRENT_CONTEXT(ctx);
1091 const GLuint unit = ctx->Array.ActiveTexture;
1092
1093 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1094 VERT_ATTRIB_TEX(unit), GL_RGBA, 4, size, type,
1095 stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
1096 }
1097
1098
1099 void GLAPIENTRY
1100 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
1101 const GLvoid *ptr)
1102 {
1103 GET_CURRENT_CONTEXT(ctx);
1104 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
1105 const GLuint unit = ctx->Array.ActiveTexture;
1106
1107 GLenum format = GL_RGBA;
1108 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
1109 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
1110 : (SHORT_BIT | INT_BIT |
1111 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1112 UNSIGNED_INT_2_10_10_10_REV_BIT |
1113 INT_2_10_10_10_REV_BIT);
1114
1115 if (!validate_array_and_format(ctx, "glTexCoordPointer",
1116 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1117 VERT_ATTRIB_TEX(unit), legalTypes,
1118 sizeMin, 4, size, type, stride,
1119 GL_FALSE, GL_FALSE, GL_FALSE, format, ptr))
1120 return;
1121
1122 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1123 VERT_ATTRIB_TEX(unit), format, 4, size, type,
1124 stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
1125 }
1126
1127
1128 void GLAPIENTRY
1129 _mesa_VertexArrayTexCoordOffsetEXT(GLuint vaobj, GLuint buffer, GLint size,
1130 GLenum type, GLsizei stride, GLintptr offset)
1131 {
1132 GET_CURRENT_CONTEXT(ctx);
1133 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
1134 const GLuint unit = ctx->Array.ActiveTexture;
1135
1136 GLenum format = GL_RGBA;
1137 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
1138 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
1139 : (SHORT_BIT | INT_BIT |
1140 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1141 UNSIGNED_INT_2_10_10_10_REV_BIT |
1142 INT_2_10_10_10_REV_BIT);
1143
1144 struct gl_vertex_array_object* vao;
1145 struct gl_buffer_object* vbo;
1146
1147 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1148 &vao, &vbo,
1149 "glVertexArrayTexCoordOffsetEXT"))
1150 return;
1151
1152 if (!validate_array_and_format(ctx, "glVertexArrayTexCoordOffsetEXT",
1153 vao, vbo,
1154 VERT_ATTRIB_TEX(unit), legalTypes,
1155 sizeMin, 4, size, type, stride,
1156 GL_FALSE, GL_FALSE, GL_FALSE, format, (void*) offset))
1157 return;
1158
1159 update_array(ctx, vao, vbo,
1160 VERT_ATTRIB_TEX(unit), format, 4, size, type,
1161 stride, GL_FALSE, GL_FALSE, GL_FALSE, (void*) offset);
1162 }
1163
1164
1165 void GLAPIENTRY
1166 _mesa_VertexArrayMultiTexCoordOffsetEXT(GLuint vaobj, GLuint buffer, GLenum texunit,
1167 GLint size, GLenum type, GLsizei stride,
1168 GLintptr offset)
1169 {
1170 GET_CURRENT_CONTEXT(ctx);
1171 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
1172 const GLuint unit = texunit - GL_TEXTURE0;
1173
1174 GLenum format = GL_RGBA;
1175 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
1176 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
1177 : (SHORT_BIT | INT_BIT |
1178 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1179 UNSIGNED_INT_2_10_10_10_REV_BIT |
1180 INT_2_10_10_10_REV_BIT);
1181
1182 struct gl_vertex_array_object* vao;
1183 struct gl_buffer_object* vbo;
1184
1185 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1186 &vao, &vbo,
1187 "glVertexArrayMultiTexCoordOffsetEXT"))
1188 return;
1189
1190 if (unit >= ctx->Const.MaxCombinedTextureImageUnits) {
1191 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexArrayMultiTexCoordOffsetEXT(texunit=%d)",
1192 texunit);
1193 return;
1194 }
1195
1196 if (!validate_array_and_format(ctx, "glVertexArrayMultiTexCoordOffsetEXT",
1197 vao, vbo,
1198 VERT_ATTRIB_TEX(unit), legalTypes,
1199 sizeMin, 4, size, type, stride,
1200 GL_FALSE, GL_FALSE, GL_FALSE, format, (void*) offset))
1201 return;
1202
1203 update_array(ctx, vao, vbo,
1204 VERT_ATTRIB_TEX(unit), format, 4, size, type,
1205 stride, GL_FALSE, GL_FALSE, GL_FALSE, (void*) offset);
1206 }
1207
1208
1209 void GLAPIENTRY
1210 _mesa_EdgeFlagPointer_no_error(GLsizei stride, const GLvoid *ptr)
1211 {
1212 /* this is the same type that glEdgeFlag uses */
1213 const GLboolean integer = GL_FALSE;
1214 GET_CURRENT_CONTEXT(ctx);
1215
1216 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1217 VERT_ATTRIB_EDGEFLAG, GL_RGBA, 1, 1, GL_UNSIGNED_BYTE,
1218 stride, GL_FALSE, integer, GL_FALSE, ptr);
1219 }
1220
1221
1222 void GLAPIENTRY
1223 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
1224 {
1225 /* this is the same type that glEdgeFlag uses */
1226 const GLboolean integer = GL_FALSE;
1227 GET_CURRENT_CONTEXT(ctx);
1228
1229 GLenum format = GL_RGBA;
1230 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
1231
1232 if (!validate_array_and_format(ctx, "glEdgeFlagPointer",
1233 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1234 VERT_ATTRIB_EDGEFLAG, legalTypes,
1235 1, 1, 1, GL_UNSIGNED_BYTE, stride,
1236 GL_FALSE, integer, GL_FALSE, format, ptr))
1237 return;
1238
1239 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1240 VERT_ATTRIB_EDGEFLAG, format, 1, 1, GL_UNSIGNED_BYTE,
1241 stride, GL_FALSE, integer, GL_FALSE, ptr);
1242 }
1243
1244
1245 void GLAPIENTRY
1246 _mesa_VertexArrayEdgeFlagOffsetEXT(GLuint vaobj, GLuint buffer, GLsizei stride,
1247 GLintptr offset)
1248 {
1249 /* this is the same type that glEdgeFlag uses */
1250 const GLboolean integer = GL_FALSE;
1251 GET_CURRENT_CONTEXT(ctx);
1252
1253 GLenum format = GL_RGBA;
1254 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
1255
1256 struct gl_vertex_array_object* vao;
1257 struct gl_buffer_object* vbo;
1258
1259 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1260 &vao, &vbo,
1261 "glVertexArrayEdgeFlagOffsetEXT"))
1262 return;
1263
1264 if (!validate_array_and_format(ctx, "glVertexArrayEdgeFlagOffsetEXT",
1265 vao, vbo,
1266 VERT_ATTRIB_EDGEFLAG, legalTypes,
1267 1, 1, 1, GL_UNSIGNED_BYTE, stride,
1268 GL_FALSE, integer, GL_FALSE, format, (void*) offset))
1269 return;
1270
1271 update_array(ctx, vao, vbo,
1272 VERT_ATTRIB_EDGEFLAG, format, 1, 1, GL_UNSIGNED_BYTE,
1273 stride, GL_FALSE, integer, GL_FALSE, (void*) offset);
1274 }
1275
1276
1277 void GLAPIENTRY
1278 _mesa_PointSizePointerOES_no_error(GLenum type, GLsizei stride,
1279 const GLvoid *ptr)
1280 {
1281 GET_CURRENT_CONTEXT(ctx);
1282
1283 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1284 VERT_ATTRIB_POINT_SIZE, GL_RGBA, 1, 1, type, stride,
1285 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
1286 }
1287
1288
1289 void GLAPIENTRY
1290 _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr)
1291 {
1292 GET_CURRENT_CONTEXT(ctx);
1293
1294 GLenum format = GL_RGBA;
1295 if (ctx->API != API_OPENGLES) {
1296 _mesa_error(ctx, GL_INVALID_OPERATION,
1297 "glPointSizePointer(ES 1.x only)");
1298 return;
1299 }
1300
1301 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
1302
1303 if (!validate_array_and_format(ctx, "glPointSizePointer",
1304 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1305 VERT_ATTRIB_POINT_SIZE, legalTypes,
1306 1, 1, 1, type, stride, GL_FALSE, GL_FALSE,
1307 GL_FALSE, format, ptr))
1308 return;
1309
1310 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1311 VERT_ATTRIB_POINT_SIZE, format, 1, 1, type, stride,
1312 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
1313 }
1314
1315
1316 void GLAPIENTRY
1317 _mesa_VertexAttribPointer_no_error(GLuint index, GLint size, GLenum type,
1318 GLboolean normalized,
1319 GLsizei stride, const GLvoid *ptr)
1320 {
1321 GET_CURRENT_CONTEXT(ctx);
1322
1323 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1324 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1325 VERT_ATTRIB_GENERIC(index), format, BGRA_OR_4,
1326 size, type, stride, normalized, GL_FALSE, GL_FALSE, ptr);
1327 }
1328
1329
1330 /**
1331 * Set a generic vertex attribute array.
1332 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1333 * (position, normal, color, fog, texcoord, etc).
1334 */
1335 void GLAPIENTRY
1336 _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
1337 GLboolean normalized,
1338 GLsizei stride, const GLvoid *ptr)
1339 {
1340 GET_CURRENT_CONTEXT(ctx);
1341
1342 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1343 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1344 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(idx)");
1345 return;
1346 }
1347
1348 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1349 SHORT_BIT | UNSIGNED_SHORT_BIT |
1350 INT_BIT | UNSIGNED_INT_BIT |
1351 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1352 FIXED_ES_BIT | FIXED_GL_BIT |
1353 UNSIGNED_INT_2_10_10_10_REV_BIT |
1354 INT_2_10_10_10_REV_BIT |
1355 UNSIGNED_INT_10F_11F_11F_REV_BIT);
1356
1357 if (!validate_array_and_format(ctx, "glVertexAttribPointer",
1358 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1359 VERT_ATTRIB_GENERIC(index), legalTypes,
1360 1, BGRA_OR_4, size, type, stride,
1361 normalized, GL_FALSE, GL_FALSE, format, ptr))
1362 return;
1363
1364 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1365 VERT_ATTRIB_GENERIC(index), format, BGRA_OR_4,
1366 size, type, stride, normalized, GL_FALSE, GL_FALSE, ptr);
1367 }
1368
1369
1370 void GLAPIENTRY
1371 _mesa_VertexArrayVertexAttribOffsetEXT(GLuint vaobj, GLuint buffer, GLuint index, GLint size,
1372 GLenum type, GLboolean normalized,
1373 GLsizei stride, GLintptr offset)
1374 {
1375 GET_CURRENT_CONTEXT(ctx);
1376 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1377 struct gl_vertex_array_object* vao;
1378 struct gl_buffer_object* vbo;
1379
1380 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1381 &vao, &vbo,
1382 "glVertexArrayVertexAttribOffsetEXT"))
1383 return;
1384
1385 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1386 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexArrayVertexAttribOffsetEXT(idx)");
1387 return;
1388 }
1389
1390 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1391 SHORT_BIT | UNSIGNED_SHORT_BIT |
1392 INT_BIT | UNSIGNED_INT_BIT |
1393 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1394 FIXED_ES_BIT | FIXED_GL_BIT |
1395 UNSIGNED_INT_2_10_10_10_REV_BIT |
1396 INT_2_10_10_10_REV_BIT |
1397 UNSIGNED_INT_10F_11F_11F_REV_BIT);
1398
1399 if (!validate_array_and_format(ctx, "glVertexArrayVertexAttribOffsetEXT",
1400 vao, vbo,
1401 VERT_ATTRIB_GENERIC(index), legalTypes,
1402 1, BGRA_OR_4, size, type, stride,
1403 normalized, GL_FALSE, GL_FALSE, format, (void*) offset))
1404 return;
1405
1406 update_array(ctx, vao, vbo,
1407 VERT_ATTRIB_GENERIC(index), format, BGRA_OR_4,
1408 size, type, stride, normalized, GL_FALSE, GL_FALSE, (void*) offset);
1409 }
1410
1411
1412 void GLAPIENTRY
1413 _mesa_VertexAttribIPointer_no_error(GLuint index, GLint size, GLenum type,
1414 GLsizei stride, const GLvoid *ptr)
1415 {
1416 const GLboolean normalized = GL_FALSE;
1417 const GLboolean integer = GL_TRUE;
1418 GET_CURRENT_CONTEXT(ctx);
1419
1420 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1421 VERT_ATTRIB_GENERIC(index), GL_RGBA, 4, size, type,
1422 stride, normalized, integer, GL_FALSE, ptr);
1423 }
1424
1425
1426 /**
1427 * GL_EXT_gpu_shader4 / GL 3.0.
1428 * Set an integer-valued vertex attribute array.
1429 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1430 * (position, normal, color, fog, texcoord, etc).
1431 */
1432 void GLAPIENTRY
1433 _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
1434 GLsizei stride, const GLvoid *ptr)
1435 {
1436 const GLboolean normalized = GL_FALSE;
1437 const GLboolean integer = GL_TRUE;
1438 GET_CURRENT_CONTEXT(ctx);
1439
1440 GLenum format = GL_RGBA;
1441 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1442 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
1443 return;
1444 }
1445
1446 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1447 SHORT_BIT | UNSIGNED_SHORT_BIT |
1448 INT_BIT | UNSIGNED_INT_BIT);
1449
1450 if (!validate_array_and_format(ctx, "glVertexAttribIPointer",
1451 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1452 VERT_ATTRIB_GENERIC(index), legalTypes,
1453 1, 4, size, type, stride,
1454 normalized, integer, GL_FALSE, format, ptr))
1455 return;
1456
1457 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1458 VERT_ATTRIB_GENERIC(index), format, 4, size, type,
1459 stride, normalized, integer, GL_FALSE, ptr);
1460 }
1461
1462
1463 void GLAPIENTRY
1464 _mesa_VertexAttribLPointer_no_error(GLuint index, GLint size, GLenum type,
1465 GLsizei stride, const GLvoid *ptr)
1466 {
1467 GET_CURRENT_CONTEXT(ctx);
1468
1469 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1470 VERT_ATTRIB_GENERIC(index), GL_RGBA, 4, size, type,
1471 stride, GL_FALSE, GL_FALSE, GL_TRUE, ptr);
1472 }
1473
1474
1475 void GLAPIENTRY
1476 _mesa_VertexArrayVertexAttribIOffsetEXT(GLuint vaobj, GLuint buffer, GLuint index, GLint size,
1477 GLenum type, GLsizei stride, GLintptr offset)
1478 {
1479 const GLboolean normalized = GL_FALSE;
1480 const GLboolean integer = GL_TRUE;
1481 GET_CURRENT_CONTEXT(ctx);
1482 GLenum format = GL_RGBA;
1483
1484 struct gl_vertex_array_object* vao;
1485 struct gl_buffer_object* vbo;
1486
1487 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1488 &vao, &vbo,
1489 "glVertexArrayVertexAttribIOffsetEXT"))
1490 return;
1491
1492 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1493 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexArrayVertexAttribIOffsetEXT(index)");
1494 return;
1495 }
1496
1497 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1498 SHORT_BIT | UNSIGNED_SHORT_BIT |
1499 INT_BIT | UNSIGNED_INT_BIT);
1500
1501 if (!validate_array_and_format(ctx, "glVertexArrayVertexAttribIOffsetEXT",
1502 vao, vbo,
1503 VERT_ATTRIB_GENERIC(index), legalTypes,
1504 1, 4, size, type, stride,
1505 normalized, integer, GL_FALSE, format, (void*) offset))
1506 return;
1507
1508 update_array(ctx, vao, vbo,
1509 VERT_ATTRIB_GENERIC(index), format, 4, size, type,
1510 stride, normalized, integer, GL_FALSE, (void*) offset);
1511 }
1512
1513
1514 void GLAPIENTRY
1515 _mesa_VertexAttribLPointer(GLuint index, GLint size, GLenum type,
1516 GLsizei stride, const GLvoid *ptr)
1517 {
1518 GET_CURRENT_CONTEXT(ctx);
1519
1520 GLenum format = GL_RGBA;
1521 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1522 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribLPointer(index)");
1523 return;
1524 }
1525
1526 const GLbitfield legalTypes = DOUBLE_BIT;
1527
1528 if (!validate_array_and_format(ctx, "glVertexAttribLPointer",
1529 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1530 VERT_ATTRIB_GENERIC(index), legalTypes,
1531 1, 4, size, type, stride,
1532 GL_FALSE, GL_FALSE, GL_TRUE, format, ptr))
1533 return;
1534
1535 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1536 VERT_ATTRIB_GENERIC(index), format, 4, size, type,
1537 stride, GL_FALSE, GL_FALSE, GL_TRUE, ptr);
1538 }
1539
1540
1541 void
1542 _mesa_enable_vertex_array_attribs(struct gl_context *ctx,
1543 struct gl_vertex_array_object *vao,
1544 GLbitfield attrib_bits)
1545 {
1546 assert((attrib_bits & ~VERT_BIT_ALL) == 0);
1547 assert(!vao->SharedAndImmutable);
1548
1549 /* Only work on bits that are disabled */
1550 attrib_bits &= ~vao->Enabled;
1551 if (attrib_bits) {
1552 /* was disabled, now being enabled */
1553 vao->Enabled |= attrib_bits;
1554 vao->NewArrays |= attrib_bits;
1555
1556 /* Update the map mode if needed */
1557 if (attrib_bits & (VERT_BIT_POS|VERT_BIT_GENERIC0))
1558 update_attribute_map_mode(ctx, vao);
1559 }
1560 }
1561
1562 static void
1563 enable_vertex_array_attrib(struct gl_context *ctx,
1564 struct gl_vertex_array_object *vao,
1565 GLuint index,
1566 const char *func)
1567 {
1568 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1569 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
1570 return;
1571 }
1572
1573 _mesa_enable_vertex_array_attrib(ctx, vao, VERT_ATTRIB_GENERIC(index));
1574 }
1575
1576
1577 void GLAPIENTRY
1578 _mesa_EnableVertexAttribArray(GLuint index)
1579 {
1580 GET_CURRENT_CONTEXT(ctx);
1581 enable_vertex_array_attrib(ctx, ctx->Array.VAO, index,
1582 "glEnableVertexAttribArray");
1583 }
1584
1585
1586 void GLAPIENTRY
1587 _mesa_EnableVertexAttribArray_no_error(GLuint index)
1588 {
1589 GET_CURRENT_CONTEXT(ctx);
1590 _mesa_enable_vertex_array_attrib(ctx, ctx->Array.VAO,
1591 VERT_ATTRIB_GENERIC(index));
1592 }
1593
1594
1595 void GLAPIENTRY
1596 _mesa_EnableVertexArrayAttrib(GLuint vaobj, GLuint index)
1597 {
1598 GET_CURRENT_CONTEXT(ctx);
1599 struct gl_vertex_array_object *vao;
1600
1601 /* The ARB_direct_state_access specification says:
1602 *
1603 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1604 * and DisableVertexArrayAttrib if <vaobj> is not
1605 * [compatibility profile: zero or] the name of an existing vertex
1606 * array object."
1607 */
1608 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glEnableVertexArrayAttrib");
1609 if (!vao)
1610 return;
1611
1612 enable_vertex_array_attrib(ctx, vao, index, "glEnableVertexArrayAttrib");
1613 }
1614
1615 void GLAPIENTRY
1616 _mesa_EnableVertexArrayAttribEXT(GLuint vaobj, GLuint index)
1617 {
1618 GET_CURRENT_CONTEXT(ctx);
1619 struct gl_vertex_array_object* vao = _mesa_lookup_vao_err(ctx, vaobj,
1620 true,
1621 "glEnableVertexArrayAttribEXT");
1622 if (!vao)
1623 return;
1624
1625 enable_vertex_array_attrib(ctx, vao, index, "glEnableVertexArrayAttribEXT");
1626 }
1627
1628
1629 void GLAPIENTRY
1630 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj, GLuint index)
1631 {
1632 GET_CURRENT_CONTEXT(ctx);
1633 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
1634 _mesa_enable_vertex_array_attrib(ctx, vao, VERT_ATTRIB_GENERIC(index));
1635 }
1636
1637
1638 void
1639 _mesa_disable_vertex_array_attribs(struct gl_context *ctx,
1640 struct gl_vertex_array_object *vao,
1641 GLbitfield attrib_bits)
1642 {
1643 assert((attrib_bits & ~VERT_BIT_ALL) == 0);
1644 assert(!vao->SharedAndImmutable);
1645
1646 /* Only work on bits that are enabled */
1647 attrib_bits &= vao->Enabled;
1648 if (attrib_bits) {
1649 /* was enabled, now being disabled */
1650 vao->Enabled &= ~attrib_bits;
1651 vao->NewArrays |= attrib_bits;
1652
1653 /* Update the map mode if needed */
1654 if (attrib_bits & (VERT_BIT_POS|VERT_BIT_GENERIC0))
1655 update_attribute_map_mode(ctx, vao);
1656 }
1657 }
1658
1659
1660 void GLAPIENTRY
1661 _mesa_DisableVertexAttribArray(GLuint index)
1662 {
1663 GET_CURRENT_CONTEXT(ctx);
1664
1665 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1666 _mesa_error(ctx, GL_INVALID_VALUE, "glDisableVertexAttribArray(index)");
1667 return;
1668 }
1669
1670 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
1671 _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attrib);
1672 }
1673
1674
1675 void GLAPIENTRY
1676 _mesa_DisableVertexAttribArray_no_error(GLuint index)
1677 {
1678 GET_CURRENT_CONTEXT(ctx);
1679 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
1680 _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attrib);
1681 }
1682
1683
1684 void GLAPIENTRY
1685 _mesa_DisableVertexArrayAttrib(GLuint vaobj, GLuint index)
1686 {
1687 GET_CURRENT_CONTEXT(ctx);
1688 struct gl_vertex_array_object *vao;
1689
1690 /* The ARB_direct_state_access specification says:
1691 *
1692 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1693 * and DisableVertexArrayAttrib if <vaobj> is not
1694 * [compatibility profile: zero or] the name of an existing vertex
1695 * array object."
1696 */
1697 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glDisableVertexArrayAttrib");
1698 if (!vao)
1699 return;
1700
1701 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1702 _mesa_error(ctx, GL_INVALID_VALUE, "glDisableVertexArrayAttrib(index)");
1703 return;
1704 }
1705
1706 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
1707 _mesa_disable_vertex_array_attrib(ctx, vao, attrib);
1708 }
1709
1710 void GLAPIENTRY
1711 _mesa_DisableVertexArrayAttribEXT(GLuint vaobj, GLuint index)
1712 {
1713 GET_CURRENT_CONTEXT(ctx);
1714 struct gl_vertex_array_object* vao = _mesa_lookup_vao_err(ctx, vaobj,
1715 true,
1716 "glEnableVertexArrayAttribEXT");
1717 if (!vao)
1718 return;
1719
1720 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1721 _mesa_error(ctx, GL_INVALID_VALUE, "glDisableVertexArrayAttrib(index)");
1722 return;
1723 }
1724
1725 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
1726 _mesa_disable_vertex_array_attrib(ctx, vao, attrib);
1727 }
1728
1729
1730 void GLAPIENTRY
1731 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj, GLuint index)
1732 {
1733 GET_CURRENT_CONTEXT(ctx);
1734 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
1735 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
1736 _mesa_disable_vertex_array_attrib(ctx, vao, attrib);
1737 }
1738
1739
1740 /**
1741 * Return info for a vertex attribute array (no alias with legacy
1742 * vertex attributes (pos, normal, color, etc)). This function does
1743 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
1744 */
1745 static GLuint
1746 get_vertex_array_attrib(struct gl_context *ctx,
1747 const struct gl_vertex_array_object *vao,
1748 GLuint index, GLenum pname,
1749 const char *caller)
1750 {
1751 const struct gl_array_attributes *array;
1752
1753 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1754 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
1755 return 0;
1756 }
1757
1758 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
1759
1760 array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
1761
1762 switch (pname) {
1763 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
1764 return !!(vao->Enabled & VERT_BIT_GENERIC(index));
1765 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
1766 return (array->Format.Format == GL_BGRA) ? GL_BGRA : array->Format.Size;
1767 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
1768 return array->Stride;
1769 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
1770 return array->Format.Type;
1771 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
1772 return array->Format.Normalized;
1773 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
1774 return vao->BufferBinding[array->BufferBindingIndex].BufferObj->Name;
1775 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
1776 if ((_mesa_is_desktop_gl(ctx)
1777 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
1778 || _mesa_is_gles3(ctx)) {
1779 return array->Format.Integer;
1780 }
1781 goto error;
1782 case GL_VERTEX_ATTRIB_ARRAY_LONG:
1783 if (_mesa_is_desktop_gl(ctx)) {
1784 return array->Format.Doubles;
1785 }
1786 goto error;
1787 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
1788 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
1789 || _mesa_is_gles3(ctx)) {
1790 return vao->BufferBinding[array->BufferBindingIndex].InstanceDivisor;
1791 }
1792 goto error;
1793 case GL_VERTEX_ATTRIB_BINDING:
1794 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
1795 return array->BufferBindingIndex - VERT_ATTRIB_GENERIC0;
1796 }
1797 goto error;
1798 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
1799 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
1800 return array->RelativeOffset;
1801 }
1802 goto error;
1803 default:
1804 ; /* fall-through */
1805 }
1806
1807 error:
1808 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
1809 return 0;
1810 }
1811
1812
1813 static const GLfloat *
1814 get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
1815 {
1816 if (index == 0) {
1817 if (_mesa_attr_zero_aliases_vertex(ctx)) {
1818 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
1819 return NULL;
1820 }
1821 }
1822 else if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1823 _mesa_error(ctx, GL_INVALID_VALUE,
1824 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
1825 return NULL;
1826 }
1827
1828 assert(VERT_ATTRIB_GENERIC(index) <
1829 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1830
1831 FLUSH_CURRENT(ctx, 0);
1832 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
1833 }
1834
1835 void GLAPIENTRY
1836 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
1837 {
1838 GET_CURRENT_CONTEXT(ctx);
1839
1840 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1841 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
1842 if (v != NULL) {
1843 COPY_4V(params, v);
1844 }
1845 }
1846 else {
1847 params[0] = (GLfloat) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1848 index, pname,
1849 "glGetVertexAttribfv");
1850 }
1851 }
1852
1853
1854 void GLAPIENTRY
1855 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
1856 {
1857 GET_CURRENT_CONTEXT(ctx);
1858
1859 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1860 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
1861 if (v != NULL) {
1862 params[0] = (GLdouble) v[0];
1863 params[1] = (GLdouble) v[1];
1864 params[2] = (GLdouble) v[2];
1865 params[3] = (GLdouble) v[3];
1866 }
1867 }
1868 else {
1869 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1870 index, pname,
1871 "glGetVertexAttribdv");
1872 }
1873 }
1874
1875 void GLAPIENTRY
1876 _mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params)
1877 {
1878 GET_CURRENT_CONTEXT(ctx);
1879
1880 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1881 const GLdouble *v =
1882 (const GLdouble *)get_current_attrib(ctx, index,
1883 "glGetVertexAttribLdv");
1884 if (v != NULL) {
1885 params[0] = v[0];
1886 params[1] = v[1];
1887 params[2] = v[2];
1888 params[3] = v[3];
1889 }
1890 }
1891 else {
1892 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1893 index, pname,
1894 "glGetVertexAttribLdv");
1895 }
1896 }
1897
1898 void GLAPIENTRY
1899 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
1900 {
1901 GET_CURRENT_CONTEXT(ctx);
1902
1903 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1904 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
1905 if (v != NULL) {
1906 /* XXX should floats in[0,1] be scaled to full int range? */
1907 params[0] = (GLint) v[0];
1908 params[1] = (GLint) v[1];
1909 params[2] = (GLint) v[2];
1910 params[3] = (GLint) v[3];
1911 }
1912 }
1913 else {
1914 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1915 index, pname,
1916 "glGetVertexAttribiv");
1917 }
1918 }
1919
1920 void GLAPIENTRY
1921 _mesa_GetVertexAttribLui64vARB(GLuint index, GLenum pname, GLuint64EXT *params)
1922 {
1923 GET_CURRENT_CONTEXT(ctx);
1924
1925 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1926 const GLuint64 *v =
1927 (const GLuint64 *)get_current_attrib(ctx, index,
1928 "glGetVertexAttribLui64vARB");
1929 if (v != NULL) {
1930 params[0] = v[0];
1931 params[1] = v[1];
1932 params[2] = v[2];
1933 params[3] = v[3];
1934 }
1935 }
1936 else {
1937 params[0] = (GLuint64) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1938 index, pname,
1939 "glGetVertexAttribLui64vARB");
1940 }
1941 }
1942
1943
1944 /** GL 3.0 */
1945 void GLAPIENTRY
1946 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
1947 {
1948 GET_CURRENT_CONTEXT(ctx);
1949
1950 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1951 const GLint *v = (const GLint *)
1952 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
1953 if (v != NULL) {
1954 COPY_4V(params, v);
1955 }
1956 }
1957 else {
1958 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1959 index, pname,
1960 "glGetVertexAttribIiv");
1961 }
1962 }
1963
1964
1965 /** GL 3.0 */
1966 void GLAPIENTRY
1967 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
1968 {
1969 GET_CURRENT_CONTEXT(ctx);
1970
1971 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1972 const GLuint *v = (const GLuint *)
1973 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
1974 if (v != NULL) {
1975 COPY_4V(params, v);
1976 }
1977 }
1978 else {
1979 params[0] = get_vertex_array_attrib(ctx, ctx->Array.VAO,
1980 index, pname,
1981 "glGetVertexAttribIuiv");
1982 }
1983 }
1984
1985
1986 void GLAPIENTRY
1987 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
1988 {
1989 GET_CURRENT_CONTEXT(ctx);
1990
1991 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1992 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
1993 return;
1994 }
1995
1996 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
1997 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
1998 return;
1999 }
2000
2001 assert(VERT_ATTRIB_GENERIC(index) <
2002 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
2003
2004 *pointer = (GLvoid *)
2005 ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
2006 }
2007
2008
2009 /** ARB_direct_state_access */
2010 void GLAPIENTRY
2011 _mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index,
2012 GLenum pname, GLint *params)
2013 {
2014 GET_CURRENT_CONTEXT(ctx);
2015 struct gl_vertex_array_object *vao;
2016
2017 /* The ARB_direct_state_access specification says:
2018 *
2019 * "An INVALID_OPERATION error is generated if <vaobj> is not
2020 * [compatibility profile: zero or] the name of an existing
2021 * vertex array object."
2022 */
2023 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glGetVertexArrayIndexediv");
2024 if (!vao)
2025 return;
2026
2027 /* The ARB_direct_state_access specification says:
2028 *
2029 * "For GetVertexArrayIndexediv, <pname> must be one of
2030 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
2031 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
2032 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
2033 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
2034 * VERTEX_ATTRIB_RELATIVE_OFFSET."
2035 *
2036 * and:
2037 *
2038 * "Add GetVertexArrayIndexediv in 'Get Command' for
2039 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
2040 * VERTEX_ATTRIB_BINDING,
2041 * VERTEX_ATTRIB_RELATIVE_OFFSET,
2042 * VERTEX_BINDING_OFFSET, and
2043 * VERTEX_BINDING_STRIDE states"
2044 *
2045 * The only parameter name common to both lists is
2046 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
2047 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
2048 * pretty clear however that the intent is that it should be possible
2049 * to query all vertex attrib and binding states that can be set with
2050 * a DSA function.
2051 */
2052 switch (pname) {
2053 case GL_VERTEX_BINDING_OFFSET:
2054 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
2055 break;
2056 case GL_VERTEX_BINDING_STRIDE:
2057 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Stride;
2058 break;
2059 case GL_VERTEX_BINDING_DIVISOR:
2060 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
2061 break;
2062 case GL_VERTEX_BINDING_BUFFER:
2063 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name;
2064 break;
2065 default:
2066 params[0] = get_vertex_array_attrib(ctx, vao, index, pname,
2067 "glGetVertexArrayIndexediv");
2068 break;
2069 }
2070 }
2071
2072
2073 void GLAPIENTRY
2074 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj, GLuint index,
2075 GLenum pname, GLint64 *params)
2076 {
2077 GET_CURRENT_CONTEXT(ctx);
2078 struct gl_vertex_array_object *vao;
2079
2080 /* The ARB_direct_state_access specification says:
2081 *
2082 * "An INVALID_OPERATION error is generated if <vaobj> is not
2083 * [compatibility profile: zero or] the name of an existing
2084 * vertex array object."
2085 */
2086 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glGetVertexArrayIndexed64iv");
2087 if (!vao)
2088 return;
2089
2090 /* The ARB_direct_state_access specification says:
2091 *
2092 * "For GetVertexArrayIndexed64iv, <pname> must be
2093 * VERTEX_BINDING_OFFSET."
2094 *
2095 * and:
2096 *
2097 * "An INVALID_ENUM error is generated if <pname> is not one of
2098 * the valid values listed above for the corresponding command."
2099 */
2100 if (pname != GL_VERTEX_BINDING_OFFSET) {
2101 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayIndexed64iv("
2102 "pname != GL_VERTEX_BINDING_OFFSET)");
2103 return;
2104 }
2105
2106 /* The ARB_direct_state_access specification says:
2107 *
2108 * "An INVALID_VALUE error is generated if <index> is greater than
2109 * or equal to the value of MAX_VERTEX_ATTRIBS."
2110 *
2111 * Since the index refers to a buffer binding in this case, the intended
2112 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
2113 * required to be the same, so in practice this doesn't matter.
2114 */
2115 if (index >= ctx->Const.MaxVertexAttribBindings) {
2116 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexArrayIndexed64iv(index"
2117 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
2118 index, ctx->Const.MaxVertexAttribBindings);
2119 return;
2120 }
2121
2122 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
2123 }
2124
2125
2126 void GLAPIENTRY
2127 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
2128 GLsizei count, const GLvoid *ptr)
2129 {
2130 (void) count;
2131 _mesa_VertexPointer(size, type, stride, ptr);
2132 }
2133
2134
2135 void GLAPIENTRY
2136 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
2137 const GLvoid *ptr)
2138 {
2139 (void) count;
2140 _mesa_NormalPointer(type, stride, ptr);
2141 }
2142
2143
2144 void GLAPIENTRY
2145 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
2146 const GLvoid *ptr)
2147 {
2148 (void) count;
2149 _mesa_ColorPointer(size, type, stride, ptr);
2150 }
2151
2152
2153 void GLAPIENTRY
2154 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
2155 const GLvoid *ptr)
2156 {
2157 (void) count;
2158 _mesa_IndexPointer(type, stride, ptr);
2159 }
2160
2161
2162 void GLAPIENTRY
2163 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
2164 GLsizei count, const GLvoid *ptr)
2165 {
2166 (void) count;
2167 _mesa_TexCoordPointer(size, type, stride, ptr);
2168 }
2169
2170
2171 void GLAPIENTRY
2172 _mesa_MultiTexCoordPointerEXT(GLenum texunit, GLint size, GLenum type,
2173 GLsizei stride, const GLvoid *ptr)
2174 {
2175 GET_CURRENT_CONTEXT(ctx);
2176 const GLint sizeMin = 1;
2177 const GLuint unit = texunit - GL_TEXTURE0;
2178
2179 GLenum format = GL_RGBA;
2180 const GLbitfield legalTypes = (SHORT_BIT | INT_BIT |
2181 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
2182 UNSIGNED_INT_2_10_10_10_REV_BIT |
2183 INT_2_10_10_10_REV_BIT);
2184
2185 if (!validate_array_and_format(ctx, "glMultiTexCoordPointerEXT",
2186 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
2187 VERT_ATTRIB_TEX(unit), legalTypes,
2188 sizeMin, 4, size, type, stride,
2189 GL_FALSE, GL_FALSE, GL_FALSE, format, ptr))
2190 return;
2191
2192 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
2193 VERT_ATTRIB_TEX(unit), format, 4, size, type,
2194 stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
2195 }
2196
2197
2198 void GLAPIENTRY
2199 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
2200 {
2201 (void) count;
2202 _mesa_EdgeFlagPointer(stride, ptr);
2203 }
2204
2205
2206 void GLAPIENTRY
2207 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
2208 {
2209 GET_CURRENT_CONTEXT(ctx);
2210 GLboolean tflag, cflag, nflag; /* enable/disable flags */
2211 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
2212 GLenum ctype = 0; /* color type */
2213 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
2214 const GLint toffset = 0; /* always zero */
2215 GLint defstride; /* default stride */
2216 GLint c, f;
2217
2218 f = sizeof(GLfloat);
2219 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
2220
2221 if (stride < 0) {
2222 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
2223 return;
2224 }
2225
2226 switch (format) {
2227 case GL_V2F:
2228 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
2229 tcomps = 0; ccomps = 0; vcomps = 2;
2230 voffset = 0;
2231 defstride = 2*f;
2232 break;
2233 case GL_V3F:
2234 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
2235 tcomps = 0; ccomps = 0; vcomps = 3;
2236 voffset = 0;
2237 defstride = 3*f;
2238 break;
2239 case GL_C4UB_V2F:
2240 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
2241 tcomps = 0; ccomps = 4; vcomps = 2;
2242 ctype = GL_UNSIGNED_BYTE;
2243 coffset = 0;
2244 voffset = c;
2245 defstride = c + 2*f;
2246 break;
2247 case GL_C4UB_V3F:
2248 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
2249 tcomps = 0; ccomps = 4; vcomps = 3;
2250 ctype = GL_UNSIGNED_BYTE;
2251 coffset = 0;
2252 voffset = c;
2253 defstride = c + 3*f;
2254 break;
2255 case GL_C3F_V3F:
2256 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
2257 tcomps = 0; ccomps = 3; vcomps = 3;
2258 ctype = GL_FLOAT;
2259 coffset = 0;
2260 voffset = 3*f;
2261 defstride = 6*f;
2262 break;
2263 case GL_N3F_V3F:
2264 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
2265 tcomps = 0; ccomps = 0; vcomps = 3;
2266 noffset = 0;
2267 voffset = 3*f;
2268 defstride = 6*f;
2269 break;
2270 case GL_C4F_N3F_V3F:
2271 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
2272 tcomps = 0; ccomps = 4; vcomps = 3;
2273 ctype = GL_FLOAT;
2274 coffset = 0;
2275 noffset = 4*f;
2276 voffset = 7*f;
2277 defstride = 10*f;
2278 break;
2279 case GL_T2F_V3F:
2280 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
2281 tcomps = 2; ccomps = 0; vcomps = 3;
2282 voffset = 2*f;
2283 defstride = 5*f;
2284 break;
2285 case GL_T4F_V4F:
2286 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
2287 tcomps = 4; ccomps = 0; vcomps = 4;
2288 voffset = 4*f;
2289 defstride = 8*f;
2290 break;
2291 case GL_T2F_C4UB_V3F:
2292 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
2293 tcomps = 2; ccomps = 4; vcomps = 3;
2294 ctype = GL_UNSIGNED_BYTE;
2295 coffset = 2*f;
2296 voffset = c+2*f;
2297 defstride = c+5*f;
2298 break;
2299 case GL_T2F_C3F_V3F:
2300 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
2301 tcomps = 2; ccomps = 3; vcomps = 3;
2302 ctype = GL_FLOAT;
2303 coffset = 2*f;
2304 voffset = 5*f;
2305 defstride = 8*f;
2306 break;
2307 case GL_T2F_N3F_V3F:
2308 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
2309 tcomps = 2; ccomps = 0; vcomps = 3;
2310 noffset = 2*f;
2311 voffset = 5*f;
2312 defstride = 8*f;
2313 break;
2314 case GL_T2F_C4F_N3F_V3F:
2315 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
2316 tcomps = 2; ccomps = 4; vcomps = 3;
2317 ctype = GL_FLOAT;
2318 coffset = 2*f;
2319 noffset = 6*f;
2320 voffset = 9*f;
2321 defstride = 12*f;
2322 break;
2323 case GL_T4F_C4F_N3F_V4F:
2324 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
2325 tcomps = 4; ccomps = 4; vcomps = 4;
2326 ctype = GL_FLOAT;
2327 coffset = 4*f;
2328 noffset = 8*f;
2329 voffset = 11*f;
2330 defstride = 15*f;
2331 break;
2332 default:
2333 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
2334 return;
2335 }
2336
2337 if (stride==0) {
2338 stride = defstride;
2339 }
2340
2341 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
2342 _mesa_DisableClientState( GL_INDEX_ARRAY );
2343 /* XXX also disable secondary color and generic arrays? */
2344
2345 /* Texcoords */
2346 if (tflag) {
2347 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
2348 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
2349 (GLubyte *) pointer + toffset );
2350 }
2351 else {
2352 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
2353 }
2354
2355 /* Color */
2356 if (cflag) {
2357 _mesa_EnableClientState( GL_COLOR_ARRAY );
2358 _mesa_ColorPointer( ccomps, ctype, stride,
2359 (GLubyte *) pointer + coffset );
2360 }
2361 else {
2362 _mesa_DisableClientState( GL_COLOR_ARRAY );
2363 }
2364
2365
2366 /* Normals */
2367 if (nflag) {
2368 _mesa_EnableClientState( GL_NORMAL_ARRAY );
2369 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
2370 }
2371 else {
2372 _mesa_DisableClientState( GL_NORMAL_ARRAY );
2373 }
2374
2375 /* Vertices */
2376 _mesa_EnableClientState( GL_VERTEX_ARRAY );
2377 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
2378 (GLubyte *) pointer + voffset );
2379 }
2380
2381
2382 void GLAPIENTRY
2383 _mesa_LockArraysEXT(GLint first, GLsizei count)
2384 {
2385 GET_CURRENT_CONTEXT(ctx);
2386
2387 if (MESA_VERBOSE & VERBOSE_API)
2388 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
2389
2390 if (first < 0) {
2391 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
2392 return;
2393 }
2394 if (count <= 0) {
2395 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
2396 return;
2397 }
2398 if (ctx->Array.LockCount != 0) {
2399 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
2400 return;
2401 }
2402
2403 ctx->Array.LockFirst = first;
2404 ctx->Array.LockCount = count;
2405 }
2406
2407
2408 void GLAPIENTRY
2409 _mesa_UnlockArraysEXT( void )
2410 {
2411 GET_CURRENT_CONTEXT(ctx);
2412
2413 if (MESA_VERBOSE & VERBOSE_API)
2414 _mesa_debug(ctx, "glUnlockArrays\n");
2415
2416 if (ctx->Array.LockCount == 0) {
2417 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
2418 return;
2419 }
2420
2421 ctx->Array.LockFirst = 0;
2422 ctx->Array.LockCount = 0;
2423 }
2424
2425
2426 static void
2427 primitive_restart_index(struct gl_context *ctx, GLuint index)
2428 {
2429 ctx->Array.RestartIndex = index;
2430 }
2431
2432
2433 /**
2434 * GL_NV_primitive_restart and GL 3.1
2435 */
2436 void GLAPIENTRY
2437 _mesa_PrimitiveRestartIndex_no_error(GLuint index)
2438 {
2439 GET_CURRENT_CONTEXT(ctx);
2440 primitive_restart_index(ctx, index);
2441 }
2442
2443
2444 void GLAPIENTRY
2445 _mesa_PrimitiveRestartIndex(GLuint index)
2446 {
2447 GET_CURRENT_CONTEXT(ctx);
2448
2449 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
2450 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
2451 return;
2452 }
2453
2454 primitive_restart_index(ctx, index);
2455 }
2456
2457
2458 void GLAPIENTRY
2459 _mesa_VertexAttribDivisor_no_error(GLuint index, GLuint divisor)
2460 {
2461 GET_CURRENT_CONTEXT(ctx);
2462
2463 const gl_vert_attrib genericIndex = VERT_ATTRIB_GENERIC(index);
2464 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
2465
2466 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
2467
2468 /* The ARB_vertex_attrib_binding spec says:
2469 *
2470 * "The command
2471 *
2472 * void VertexAttribDivisor(uint index, uint divisor);
2473 *
2474 * is equivalent to (assuming no errors are generated):
2475 *
2476 * VertexAttribBinding(index, index);
2477 * VertexBindingDivisor(index, divisor);"
2478 */
2479 _mesa_vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
2480 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
2481 }
2482
2483
2484 /**
2485 * See GL_ARB_instanced_arrays.
2486 * Note that the instance divisor only applies to generic arrays, not
2487 * the legacy vertex arrays.
2488 */
2489 void GLAPIENTRY
2490 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
2491 {
2492 GET_CURRENT_CONTEXT(ctx);
2493
2494 const gl_vert_attrib genericIndex = VERT_ATTRIB_GENERIC(index);
2495 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
2496
2497 if (!ctx->Extensions.ARB_instanced_arrays) {
2498 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
2499 return;
2500 }
2501
2502 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2503 _mesa_error(ctx, GL_INVALID_VALUE,
2504 "glVertexAttribDivisor(index = %u)", index);
2505 return;
2506 }
2507
2508 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
2509
2510 /* The ARB_vertex_attrib_binding spec says:
2511 *
2512 * "The command
2513 *
2514 * void VertexAttribDivisor(uint index, uint divisor);
2515 *
2516 * is equivalent to (assuming no errors are generated):
2517 *
2518 * VertexAttribBinding(index, index);
2519 * VertexBindingDivisor(index, divisor);"
2520 */
2521 _mesa_vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
2522 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
2523 }
2524
2525
2526 static ALWAYS_INLINE void
2527 vertex_array_vertex_buffer(struct gl_context *ctx,
2528 struct gl_vertex_array_object *vao,
2529 GLuint bindingIndex, GLuint buffer, GLintptr offset,
2530 GLsizei stride, bool no_error, const char *func)
2531 {
2532 struct gl_buffer_object *vbo;
2533 if (buffer ==
2534 vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) {
2535 vbo = vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
2536 } else if (buffer != 0) {
2537 vbo = _mesa_lookup_bufferobj(ctx, buffer);
2538
2539 if (!no_error && !vbo && _mesa_is_gles31(ctx)) {
2540 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-gen name)", func);
2541 return;
2542 }
2543 /* From the GL_ARB_vertex_attrib_array spec:
2544 *
2545 * "[Core profile only:]
2546 * An INVALID_OPERATION error is generated if buffer is not zero or a
2547 * name returned from a previous call to GenBuffers, or if such a name
2548 * has since been deleted with DeleteBuffers.
2549 *
2550 * Otherwise, we fall back to the same compat profile behavior as other
2551 * object references (automatically gen it).
2552 */
2553 if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &vbo, func))
2554 return;
2555 } else {
2556 /* The ARB_vertex_attrib_binding spec says:
2557 *
2558 * "If <buffer> is zero, any buffer object attached to this
2559 * bindpoint is detached."
2560 */
2561 vbo = ctx->Shared->NullBufferObj;
2562 }
2563
2564 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex),
2565 vbo, offset, stride);
2566 }
2567
2568
2569 /**
2570 * GL_ARB_vertex_attrib_binding
2571 */
2572 static void
2573 vertex_array_vertex_buffer_err(struct gl_context *ctx,
2574 struct gl_vertex_array_object *vao,
2575 GLuint bindingIndex, GLuint buffer,
2576 GLintptr offset, GLsizei stride,
2577 const char *func)
2578 {
2579 ASSERT_OUTSIDE_BEGIN_END(ctx);
2580
2581 /* The ARB_vertex_attrib_binding spec says:
2582 *
2583 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2584 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2585 */
2586 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2587 _mesa_error(ctx, GL_INVALID_VALUE,
2588 "%s(bindingindex=%u > "
2589 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2590 func, bindingIndex);
2591 return;
2592 }
2593
2594 /* The ARB_vertex_attrib_binding spec says:
2595 *
2596 * "The error INVALID_VALUE is generated if <stride> or <offset>
2597 * are negative."
2598 */
2599 if (offset < 0) {
2600 _mesa_error(ctx, GL_INVALID_VALUE,
2601 "%s(offset=%" PRId64 " < 0)",
2602 func, (int64_t) offset);
2603 return;
2604 }
2605
2606 if (stride < 0) {
2607 _mesa_error(ctx, GL_INVALID_VALUE,
2608 "%s(stride=%d < 0)", func, stride);
2609 return;
2610 }
2611
2612 if (((_mesa_is_desktop_gl(ctx) && ctx->Version >= 44) || _mesa_is_gles31(ctx)) &&
2613 stride > ctx->Const.MaxVertexAttribStride) {
2614 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
2615 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
2616 return;
2617 }
2618
2619 vertex_array_vertex_buffer(ctx, vao, bindingIndex, buffer, offset,
2620 stride, false, func);
2621 }
2622
2623
2624 void GLAPIENTRY
2625 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex, GLuint buffer,
2626 GLintptr offset, GLsizei stride)
2627 {
2628 GET_CURRENT_CONTEXT(ctx);
2629 vertex_array_vertex_buffer(ctx, ctx->Array.VAO, bindingIndex,
2630 buffer, offset, stride, true,
2631 "glBindVertexBuffer");
2632 }
2633
2634
2635 void GLAPIENTRY
2636 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
2637 GLsizei stride)
2638 {
2639 GET_CURRENT_CONTEXT(ctx);
2640
2641 /* The ARB_vertex_attrib_binding spec says:
2642 *
2643 * "An INVALID_OPERATION error is generated if no vertex array object
2644 * is bound."
2645 */
2646 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2647 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2648 _mesa_error(ctx, GL_INVALID_OPERATION,
2649 "glBindVertexBuffer(No array object bound)");
2650 return;
2651 }
2652
2653 vertex_array_vertex_buffer_err(ctx, ctx->Array.VAO, bindingIndex,
2654 buffer, offset, stride,
2655 "glBindVertexBuffer");
2656 }
2657
2658
2659 void GLAPIENTRY
2660 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj, GLuint bindingIndex,
2661 GLuint buffer, GLintptr offset,
2662 GLsizei stride)
2663 {
2664 GET_CURRENT_CONTEXT(ctx);
2665
2666 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2667 vertex_array_vertex_buffer(ctx, vao, bindingIndex, buffer, offset,
2668 stride, true, "glVertexArrayVertexBuffer");
2669 }
2670
2671
2672 void GLAPIENTRY
2673 _mesa_VertexArrayVertexBuffer(GLuint vaobj, GLuint bindingIndex, GLuint buffer,
2674 GLintptr offset, GLsizei stride)
2675 {
2676 GET_CURRENT_CONTEXT(ctx);
2677 struct gl_vertex_array_object *vao;
2678
2679 /* The ARB_direct_state_access specification says:
2680 *
2681 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2682 * if <vaobj> is not [compatibility profile: zero or] the name of an
2683 * existing vertex array object."
2684 */
2685 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glVertexArrayVertexBuffer");
2686 if (!vao)
2687 return;
2688
2689 vertex_array_vertex_buffer_err(ctx, vao, bindingIndex, buffer, offset,
2690 stride, "glVertexArrayVertexBuffer");
2691 }
2692
2693
2694 static ALWAYS_INLINE void
2695 vertex_array_vertex_buffers(struct gl_context *ctx,
2696 struct gl_vertex_array_object *vao,
2697 GLuint first, GLsizei count, const GLuint *buffers,
2698 const GLintptr *offsets, const GLsizei *strides,
2699 bool no_error, const char *func)
2700 {
2701 GLint i;
2702
2703 if (!buffers) {
2704 /**
2705 * The ARB_multi_bind spec says:
2706 *
2707 * "If <buffers> is NULL, each affected vertex buffer binding point
2708 * from <first> through <first>+<count>-1 will be reset to have no
2709 * bound buffer object. In this case, the offsets and strides
2710 * associated with the binding points are set to default values,
2711 * ignoring <offsets> and <strides>."
2712 */
2713 struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj;
2714
2715 for (i = 0; i < count; i++)
2716 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
2717 vbo, 0, 16);
2718
2719 return;
2720 }
2721
2722 /* Note that the error semantics for multi-bind commands differ from
2723 * those of other GL commands.
2724 *
2725 * The Issues section in the ARB_multi_bind spec says:
2726 *
2727 * "(11) Typically, OpenGL specifies that if an error is generated by
2728 * a command, that command has no effect. This is somewhat
2729 * unfortunate for multi-bind commands, because it would require
2730 * a first pass to scan the entire list of bound objects for
2731 * errors and then a second pass to actually perform the
2732 * bindings. Should we have different error semantics?
2733 *
2734 * RESOLVED: Yes. In this specification, when the parameters for
2735 * one of the <count> binding points are invalid, that binding
2736 * point is not updated and an error will be generated. However,
2737 * other binding points in the same command will be updated if
2738 * their parameters are valid and no other error occurs."
2739 */
2740
2741 _mesa_HashLockMutex(ctx->Shared->BufferObjects);
2742
2743 for (i = 0; i < count; i++) {
2744 struct gl_buffer_object *vbo;
2745
2746 if (!no_error) {
2747 /* The ARB_multi_bind spec says:
2748 *
2749 * "An INVALID_VALUE error is generated if any value in
2750 * <offsets> or <strides> is negative (per binding)."
2751 */
2752 if (offsets[i] < 0) {
2753 _mesa_error(ctx, GL_INVALID_VALUE,
2754 "%s(offsets[%u]=%" PRId64 " < 0)",
2755 func, i, (int64_t) offsets[i]);
2756 continue;
2757 }
2758
2759 if (strides[i] < 0) {
2760 _mesa_error(ctx, GL_INVALID_VALUE,
2761 "%s(strides[%u]=%d < 0)",
2762 func, i, strides[i]);
2763 continue;
2764 }
2765
2766 if (_mesa_is_desktop_gl(ctx) && ctx->Version >= 44 &&
2767 strides[i] > ctx->Const.MaxVertexAttribStride) {
2768 _mesa_error(ctx, GL_INVALID_VALUE,
2769 "%s(strides[%u]=%d > "
2770 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, i, strides[i]);
2771 continue;
2772 }
2773 }
2774
2775 if (buffers[i]) {
2776 struct gl_vertex_buffer_binding *binding =
2777 &vao->BufferBinding[VERT_ATTRIB_GENERIC(first + i)];
2778
2779 if (buffers[i] == binding->BufferObj->Name)
2780 vbo = binding->BufferObj;
2781 else
2782 vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, func);
2783
2784 if (!vbo)
2785 continue;
2786 } else {
2787 vbo = ctx->Shared->NullBufferObj;
2788 }
2789
2790 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
2791 vbo, offsets[i], strides[i]);
2792 }
2793
2794 _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
2795 }
2796
2797
2798 static void
2799 vertex_array_vertex_buffers_err(struct gl_context *ctx,
2800 struct gl_vertex_array_object *vao,
2801 GLuint first, GLsizei count,
2802 const GLuint *buffers, const GLintptr *offsets,
2803 const GLsizei *strides, const char *func)
2804 {
2805 ASSERT_OUTSIDE_BEGIN_END(ctx);
2806
2807 /* The ARB_multi_bind spec says:
2808 *
2809 * "An INVALID_OPERATION error is generated if <first> + <count>
2810 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
2811 */
2812 if (first + count > ctx->Const.MaxVertexAttribBindings) {
2813 _mesa_error(ctx, GL_INVALID_OPERATION,
2814 "%s(first=%u + count=%d > the value of "
2815 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
2816 func, first, count, ctx->Const.MaxVertexAttribBindings);
2817 return;
2818 }
2819
2820 vertex_array_vertex_buffers(ctx, vao, first, count, buffers, offsets,
2821 strides, false, func);
2822 }
2823
2824
2825 void GLAPIENTRY
2826 _mesa_BindVertexBuffers_no_error(GLuint first, GLsizei count,
2827 const GLuint *buffers, const GLintptr *offsets,
2828 const GLsizei *strides)
2829 {
2830 GET_CURRENT_CONTEXT(ctx);
2831
2832 vertex_array_vertex_buffers(ctx, ctx->Array.VAO, first, count,
2833 buffers, offsets, strides, true,
2834 "glBindVertexBuffers");
2835 }
2836
2837
2838 void GLAPIENTRY
2839 _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
2840 const GLintptr *offsets, const GLsizei *strides)
2841 {
2842 GET_CURRENT_CONTEXT(ctx);
2843
2844 /* The ARB_vertex_attrib_binding spec says:
2845 *
2846 * "An INVALID_OPERATION error is generated if no
2847 * vertex array object is bound."
2848 */
2849 if (ctx->API == API_OPENGL_CORE &&
2850 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2851 _mesa_error(ctx, GL_INVALID_OPERATION,
2852 "glBindVertexBuffers(No array object bound)");
2853 return;
2854 }
2855
2856 vertex_array_vertex_buffers_err(ctx, ctx->Array.VAO, first, count,
2857 buffers, offsets, strides,
2858 "glBindVertexBuffers");
2859 }
2860
2861
2862 void GLAPIENTRY
2863 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj, GLuint first,
2864 GLsizei count, const GLuint *buffers,
2865 const GLintptr *offsets,
2866 const GLsizei *strides)
2867 {
2868 GET_CURRENT_CONTEXT(ctx);
2869
2870 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2871 vertex_array_vertex_buffers(ctx, vao, first, count,
2872 buffers, offsets, strides, true,
2873 "glVertexArrayVertexBuffers");
2874 }
2875
2876
2877 void GLAPIENTRY
2878 _mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count,
2879 const GLuint *buffers,
2880 const GLintptr *offsets, const GLsizei *strides)
2881 {
2882 GET_CURRENT_CONTEXT(ctx);
2883 struct gl_vertex_array_object *vao;
2884
2885 /* The ARB_direct_state_access specification says:
2886 *
2887 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2888 * if <vaobj> is not [compatibility profile: zero or] the name of an
2889 * existing vertex array object."
2890 */
2891 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glVertexArrayVertexBuffers");
2892 if (!vao)
2893 return;
2894
2895 vertex_array_vertex_buffers_err(ctx, vao, first, count,
2896 buffers, offsets, strides,
2897 "glVertexArrayVertexBuffers");
2898 }
2899
2900
2901 static void
2902 vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type,
2903 GLboolean normalized, GLboolean integer,
2904 GLboolean doubles, GLbitfield legalTypes,
2905 GLsizei sizeMax, GLuint relativeOffset,
2906 const char *func)
2907 {
2908 GET_CURRENT_CONTEXT(ctx);
2909 ASSERT_OUTSIDE_BEGIN_END(ctx);
2910
2911 GLenum format = get_array_format(ctx, sizeMax, &size);
2912
2913 if (!_mesa_is_no_error_enabled(ctx)) {
2914 /* The ARB_vertex_attrib_binding spec says:
2915 *
2916 * "An INVALID_OPERATION error is generated under any of the
2917 * following conditions:
2918 * - if no vertex array object is currently bound (see section
2919 * 2.10);
2920 * - ..."
2921 *
2922 * This error condition only applies to VertexAttribFormat and
2923 * VertexAttribIFormat in the extension spec, but we assume that this
2924 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2925 * to all three functions.
2926 */
2927 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2928 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2929 _mesa_error(ctx, GL_INVALID_OPERATION,
2930 "%s(No array object bound)", func);
2931 return;
2932 }
2933
2934 /* The ARB_vertex_attrib_binding spec says:
2935 *
2936 * "The error INVALID_VALUE is generated if index is greater than or
2937 * equal to the value of MAX_VERTEX_ATTRIBS."
2938 */
2939 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2940 _mesa_error(ctx, GL_INVALID_VALUE,
2941 "%s(attribindex=%u > "
2942 "GL_MAX_VERTEX_ATTRIBS)",
2943 func, attribIndex);
2944 return;
2945 }
2946
2947 if (!validate_array_format(ctx, func, ctx->Array.VAO,
2948 VERT_ATTRIB_GENERIC(attribIndex),
2949 legalTypes, 1, sizeMax, size, type,
2950 normalized, integer, doubles, relativeOffset,
2951 format)) {
2952 return;
2953 }
2954 }
2955
2956 _mesa_update_array_format(ctx, ctx->Array.VAO,
2957 VERT_ATTRIB_GENERIC(attribIndex), size, type,
2958 format, normalized, integer, doubles,
2959 relativeOffset);
2960 }
2961
2962
2963 void GLAPIENTRY
2964 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
2965 GLboolean normalized, GLuint relativeOffset)
2966 {
2967 vertex_attrib_format(attribIndex, size, type, normalized,
2968 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
2969 BGRA_OR_4, relativeOffset,
2970 "glVertexAttribFormat");
2971 }
2972
2973
2974 void GLAPIENTRY
2975 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
2976 GLuint relativeOffset)
2977 {
2978 vertex_attrib_format(attribIndex, size, type, GL_FALSE,
2979 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK, 4,
2980 relativeOffset, "glVertexAttribIFormat");
2981 }
2982
2983
2984 void GLAPIENTRY
2985 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
2986 GLuint relativeOffset)
2987 {
2988 vertex_attrib_format(attribIndex, size, type, GL_FALSE, GL_FALSE,
2989 GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK, 4,
2990 relativeOffset, "glVertexAttribLFormat");
2991 }
2992
2993
2994 static void
2995 vertex_array_attrib_format(GLuint vaobj, GLuint attribIndex, GLint size,
2996 GLenum type, GLboolean normalized,
2997 GLboolean integer, GLboolean doubles,
2998 GLbitfield legalTypes, GLsizei sizeMax,
2999 GLuint relativeOffset, const char *func)
3000 {
3001 GET_CURRENT_CONTEXT(ctx);
3002 struct gl_vertex_array_object *vao;
3003
3004 ASSERT_OUTSIDE_BEGIN_END(ctx);
3005
3006 GLenum format = get_array_format(ctx, sizeMax, &size);
3007
3008 if (_mesa_is_no_error_enabled(ctx)) {
3009 vao = _mesa_lookup_vao(ctx, vaobj);
3010 if (!vao)
3011 return;
3012 } else {
3013 /* The ARB_direct_state_access spec says:
3014 *
3015 * "An INVALID_OPERATION error is generated by
3016 * VertexArrayAttrib*Format if <vaobj> is not [compatibility profile:
3017 * zero or] the name of an existing vertex array object."
3018 */
3019 vao = _mesa_lookup_vao_err(ctx, false, vaobj, func);
3020 if (!vao)
3021 return;
3022
3023 /* The ARB_vertex_attrib_binding spec says:
3024 *
3025 * "The error INVALID_VALUE is generated if index is greater than or
3026 * equal to the value of MAX_VERTEX_ATTRIBS."
3027 */
3028 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
3029 _mesa_error(ctx, GL_INVALID_VALUE,
3030 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
3031 func, attribIndex);
3032 return;
3033 }
3034
3035 if (!validate_array_format(ctx, func, vao,
3036 VERT_ATTRIB_GENERIC(attribIndex),
3037 legalTypes, 1, sizeMax, size, type,
3038 normalized, integer, doubles, relativeOffset,
3039 format)) {
3040 return;
3041 }
3042 }
3043
3044 _mesa_update_array_format(ctx, vao, VERT_ATTRIB_GENERIC(attribIndex), size,
3045 type, format, normalized, integer, doubles,
3046 relativeOffset);
3047 }
3048
3049
3050 void GLAPIENTRY
3051 _mesa_VertexArrayAttribFormat(GLuint vaobj, GLuint attribIndex, GLint size,
3052 GLenum type, GLboolean normalized,
3053 GLuint relativeOffset)
3054 {
3055 vertex_array_attrib_format(vaobj, attribIndex, size, type, normalized,
3056 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
3057 BGRA_OR_4, relativeOffset,
3058 "glVertexArrayAttribFormat");
3059 }
3060
3061
3062 void GLAPIENTRY
3063 _mesa_VertexArrayAttribIFormat(GLuint vaobj, GLuint attribIndex,
3064 GLint size, GLenum type,
3065 GLuint relativeOffset)
3066 {
3067 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
3068 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK,
3069 4, relativeOffset,
3070 "glVertexArrayAttribIFormat");
3071 }
3072
3073
3074 void GLAPIENTRY
3075 _mesa_VertexArrayAttribLFormat(GLuint vaobj, GLuint attribIndex,
3076 GLint size, GLenum type,
3077 GLuint relativeOffset)
3078 {
3079 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
3080 GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK,
3081 4, relativeOffset,
3082 "glVertexArrayAttribLFormat");
3083 }
3084
3085
3086 static void
3087 vertex_array_attrib_binding(struct gl_context *ctx,
3088 struct gl_vertex_array_object *vao,
3089 GLuint attribIndex, GLuint bindingIndex,
3090 const char *func)
3091 {
3092 ASSERT_OUTSIDE_BEGIN_END(ctx);
3093
3094 /* The ARB_vertex_attrib_binding spec says:
3095 *
3096 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
3097 * <bindingindex> must be less than the value of
3098 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
3099 * is generated."
3100 */
3101 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
3102 _mesa_error(ctx, GL_INVALID_VALUE,
3103 "%s(attribindex=%u >= "
3104 "GL_MAX_VERTEX_ATTRIBS)",
3105 func, attribIndex);
3106 return;
3107 }
3108
3109 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
3110 _mesa_error(ctx, GL_INVALID_VALUE,
3111 "%s(bindingindex=%u >= "
3112 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
3113 func, bindingIndex);
3114 return;
3115 }
3116
3117 assert(VERT_ATTRIB_GENERIC(attribIndex) < ARRAY_SIZE(vao->VertexAttrib));
3118
3119 _mesa_vertex_attrib_binding(ctx, vao,
3120 VERT_ATTRIB_GENERIC(attribIndex),
3121 VERT_ATTRIB_GENERIC(bindingIndex));
3122 }
3123
3124
3125 void GLAPIENTRY
3126 _mesa_VertexAttribBinding_no_error(GLuint attribIndex, GLuint bindingIndex)
3127 {
3128 GET_CURRENT_CONTEXT(ctx);
3129 _mesa_vertex_attrib_binding(ctx, ctx->Array.VAO,
3130 VERT_ATTRIB_GENERIC(attribIndex),
3131 VERT_ATTRIB_GENERIC(bindingIndex));
3132 }
3133
3134
3135 void GLAPIENTRY
3136 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3137 {
3138 GET_CURRENT_CONTEXT(ctx);
3139
3140 /* The ARB_vertex_attrib_binding spec says:
3141 *
3142 * "An INVALID_OPERATION error is generated if no vertex array object
3143 * is bound."
3144 */
3145 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
3146 ctx->Array.VAO == ctx->Array.DefaultVAO) {
3147 _mesa_error(ctx, GL_INVALID_OPERATION,
3148 "glVertexAttribBinding(No array object bound)");
3149 return;
3150 }
3151
3152 vertex_array_attrib_binding(ctx, ctx->Array.VAO,
3153 attribIndex, bindingIndex,
3154 "glVertexAttribBinding");
3155 }
3156
3157
3158 void GLAPIENTRY
3159 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj, GLuint attribIndex,
3160 GLuint bindingIndex)
3161 {
3162 GET_CURRENT_CONTEXT(ctx);
3163
3164 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
3165 _mesa_vertex_attrib_binding(ctx, vao,
3166 VERT_ATTRIB_GENERIC(attribIndex),
3167 VERT_ATTRIB_GENERIC(bindingIndex));
3168 }
3169
3170
3171 void GLAPIENTRY
3172 _mesa_VertexArrayAttribBinding(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex)
3173 {
3174 GET_CURRENT_CONTEXT(ctx);
3175 struct gl_vertex_array_object *vao;
3176
3177 /* The ARB_direct_state_access specification says:
3178 *
3179 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
3180 * if <vaobj> is not [compatibility profile: zero or] the name of an
3181 * existing vertex array object."
3182 */
3183 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glVertexArrayAttribBinding");
3184 if (!vao)
3185 return;
3186
3187 vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex,
3188 "glVertexArrayAttribBinding");
3189 }
3190
3191
3192 static void
3193 vertex_array_binding_divisor(struct gl_context *ctx,
3194 struct gl_vertex_array_object *vao,
3195 GLuint bindingIndex, GLuint divisor,
3196 const char *func)
3197 {
3198 ASSERT_OUTSIDE_BEGIN_END(ctx);
3199
3200 if (!ctx->Extensions.ARB_instanced_arrays) {
3201 _mesa_error(ctx, GL_INVALID_OPERATION, "%s()", func);
3202 return;
3203 }
3204
3205 /* The ARB_vertex_attrib_binding spec says:
3206 *
3207 * "An INVALID_VALUE error is generated if <bindingindex> is greater
3208 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
3209 */
3210 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
3211 _mesa_error(ctx, GL_INVALID_VALUE,
3212 "%s(bindingindex=%u > "
3213 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
3214 func, bindingIndex);
3215 return;
3216 }
3217
3218 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
3219 }
3220
3221
3222 void GLAPIENTRY
3223 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex, GLuint divisor)
3224 {
3225 GET_CURRENT_CONTEXT(ctx);
3226 vertex_binding_divisor(ctx, ctx->Array.VAO,
3227 VERT_ATTRIB_GENERIC(bindingIndex), divisor);
3228 }
3229
3230
3231 void GLAPIENTRY
3232 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3233 {
3234 GET_CURRENT_CONTEXT(ctx);
3235
3236 /* The ARB_vertex_attrib_binding spec says:
3237 *
3238 * "An INVALID_OPERATION error is generated if no vertex array object
3239 * is bound."
3240 */
3241 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
3242 ctx->Array.VAO == ctx->Array.DefaultVAO) {
3243 _mesa_error(ctx, GL_INVALID_OPERATION,
3244 "glVertexBindingDivisor(No array object bound)");
3245 return;
3246 }
3247
3248 vertex_array_binding_divisor(ctx, ctx->Array.VAO,
3249 bindingIndex, divisor,
3250 "glVertexBindingDivisor");
3251 }
3252
3253
3254 void GLAPIENTRY
3255 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj, GLuint bindingIndex,
3256 GLuint divisor)
3257 {
3258 GET_CURRENT_CONTEXT(ctx);
3259
3260 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
3261 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
3262 }
3263
3264
3265 void GLAPIENTRY
3266 _mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex,
3267 GLuint divisor)
3268 {
3269 struct gl_vertex_array_object *vao;
3270 GET_CURRENT_CONTEXT(ctx);
3271
3272 /* The ARB_direct_state_access specification says:
3273 *
3274 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
3275 * if <vaobj> is not [compatibility profile: zero or] the name of an
3276 * existing vertex array object."
3277 */
3278 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glVertexArrayBindingDivisor");
3279 if (!vao)
3280 return;
3281
3282 vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor,
3283 "glVertexArrayBindingDivisor");
3284 }
3285
3286
3287 void
3288 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
3289 struct gl_array_attributes *dst,
3290 const struct gl_array_attributes *src)
3291 {
3292 dst->Ptr = src->Ptr;
3293 dst->RelativeOffset = src->RelativeOffset;
3294 dst->Format = src->Format;
3295 dst->Stride = src->Stride;
3296 dst->BufferBindingIndex = src->BufferBindingIndex;
3297 dst->_EffBufferBindingIndex = src->_EffBufferBindingIndex;
3298 dst->_EffRelativeOffset = src->_EffRelativeOffset;
3299 }
3300
3301 void
3302 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
3303 struct gl_vertex_buffer_binding *dst,
3304 const struct gl_vertex_buffer_binding *src)
3305 {
3306 dst->Offset = src->Offset;
3307 dst->Stride = src->Stride;
3308 dst->InstanceDivisor = src->InstanceDivisor;
3309 dst->_BoundArrays = src->_BoundArrays;
3310 dst->_EffBoundArrays = src->_EffBoundArrays;
3311 dst->_EffOffset = src->_EffOffset;
3312
3313 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
3314 }
3315
3316 /**
3317 * Print current vertex object/array info. For debug.
3318 */
3319 void
3320 _mesa_print_arrays(struct gl_context *ctx)
3321 {
3322 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
3323
3324 fprintf(stderr, "Array Object %u\n", vao->Name);
3325
3326 GLbitfield mask = vao->Enabled;
3327 while (mask) {
3328 const gl_vert_attrib i = u_bit_scan(&mask);
3329 const struct gl_array_attributes *array = &vao->VertexAttrib[i];
3330
3331 const struct gl_vertex_buffer_binding *binding =
3332 &vao->BufferBinding[array->BufferBindingIndex];
3333 const struct gl_buffer_object *bo = binding->BufferObj;
3334
3335 fprintf(stderr, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
3336 "Stride=%d, Buffer=%u(Size %lu)\n",
3337 gl_vert_attrib_name((gl_vert_attrib)i),
3338 array->Ptr, _mesa_enum_to_string(array->Format.Type),
3339 array->Format.Size,
3340 array->Format._ElementSize, binding->Stride, bo->Name,
3341 (unsigned long) bo->Size);
3342 }
3343 }
3344
3345
3346 /**
3347 * Initialize vertex array state for given context.
3348 */
3349 void
3350 _mesa_init_varray(struct gl_context *ctx)
3351 {
3352 ctx->Array.DefaultVAO = _mesa_new_vao(ctx, 0);
3353 _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO);
3354 ctx->Array._EmptyVAO = _mesa_new_vao(ctx, ~0u);
3355 _mesa_reference_vao(ctx, &ctx->Array._DrawVAO, ctx->Array._EmptyVAO);
3356 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
3357
3358 ctx->Array.Objects = _mesa_NewHashTable();
3359 }
3360
3361
3362 /**
3363 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
3364 */
3365 static void
3366 delete_arrayobj_cb(GLuint id, void *data, void *userData)
3367 {
3368 struct gl_vertex_array_object *vao = (struct gl_vertex_array_object *) data;
3369 struct gl_context *ctx = (struct gl_context *) userData;
3370 _mesa_delete_vao(ctx, vao);
3371 }
3372
3373
3374 /**
3375 * Free vertex array state for given context.
3376 */
3377 void
3378 _mesa_free_varray_data(struct gl_context *ctx)
3379 {
3380 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
3381 _mesa_DeleteHashTable(ctx->Array.Objects);
3382 }