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