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