2ced74a76c33e81af02114e1e41a465d40147ce1
[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, bool flush_vertices)
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, bool flush_vertices)
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, true);
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, true);
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, bool flush_vertices)
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,
1103 VERT_ATTRIB_GENERIC(index), true);
1104 }
1105
1106
1107 void GLAPIENTRY
1108 _mesa_EnableVertexAttribArray(GLuint index)
1109 {
1110 GET_CURRENT_CONTEXT(ctx);
1111 enable_vertex_array_attrib(ctx, ctx->Array.VAO, index,
1112 "glEnableVertexAttribArray");
1113 }
1114
1115
1116 void GLAPIENTRY
1117 _mesa_EnableVertexAttribArray_no_error(GLuint index)
1118 {
1119 GET_CURRENT_CONTEXT(ctx);
1120 _mesa_enable_vertex_array_attrib(ctx, ctx->Array.VAO,
1121 VERT_ATTRIB_GENERIC(index), true);
1122 }
1123
1124
1125 void GLAPIENTRY
1126 _mesa_EnableVertexArrayAttrib(GLuint vaobj, GLuint index)
1127 {
1128 GET_CURRENT_CONTEXT(ctx);
1129 struct gl_vertex_array_object *vao;
1130
1131 /* The ARB_direct_state_access specification says:
1132 *
1133 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1134 * and DisableVertexArrayAttrib if <vaobj> is not
1135 * [compatibility profile: zero or] the name of an existing vertex
1136 * array object."
1137 */
1138 vao = _mesa_lookup_vao_err(ctx, vaobj, "glEnableVertexArrayAttrib");
1139 if (!vao)
1140 return;
1141
1142 enable_vertex_array_attrib(ctx, vao, index, "glEnableVertexArrayAttrib");
1143 }
1144
1145
1146 void GLAPIENTRY
1147 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj, GLuint index)
1148 {
1149 GET_CURRENT_CONTEXT(ctx);
1150 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
1151 _mesa_enable_vertex_array_attrib(ctx, vao,
1152 VERT_ATTRIB_GENERIC(index), true);
1153 }
1154
1155
1156 void
1157 _mesa_disable_vertex_array_attrib(struct gl_context *ctx,
1158 struct gl_vertex_array_object *vao,
1159 gl_vert_attrib attrib, bool flush_vertices)
1160 {
1161 assert(attrib < ARRAY_SIZE(vao->VertexAttrib));
1162 assert(!vao->SharedAndImmutable);
1163
1164 if (vao->VertexAttrib[attrib].Enabled) {
1165 /* was enabled, now being disabled */
1166 vao->VertexAttrib[attrib].Enabled = GL_FALSE;
1167 const GLbitfield array_bit = VERT_BIT(attrib);
1168 vao->_Enabled &= ~array_bit;
1169 vao->NewArrays |= array_bit;
1170 ctx->NewState |= _NEW_ARRAY;
1171
1172 /* Update the map mode if needed */
1173 if (array_bit & (VERT_BIT_POS|VERT_BIT_GENERIC0))
1174 update_attribute_map_mode(ctx, vao);
1175 }
1176 }
1177
1178
1179 void GLAPIENTRY
1180 _mesa_DisableVertexAttribArray(GLuint index)
1181 {
1182 GET_CURRENT_CONTEXT(ctx);
1183
1184 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1185 _mesa_error(ctx, GL_INVALID_VALUE, "glDisableVertexAttribArray(index)");
1186 return;
1187 }
1188
1189 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
1190 _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attrib, true);
1191 }
1192
1193
1194 void GLAPIENTRY
1195 _mesa_DisableVertexAttribArray_no_error(GLuint index)
1196 {
1197 GET_CURRENT_CONTEXT(ctx);
1198 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
1199 _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attrib, true);
1200 }
1201
1202
1203 void GLAPIENTRY
1204 _mesa_DisableVertexArrayAttrib(GLuint vaobj, GLuint index)
1205 {
1206 GET_CURRENT_CONTEXT(ctx);
1207 struct gl_vertex_array_object *vao;
1208
1209 /* The ARB_direct_state_access specification says:
1210 *
1211 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1212 * and DisableVertexArrayAttrib if <vaobj> is not
1213 * [compatibility profile: zero or] the name of an existing vertex
1214 * array object."
1215 */
1216 vao = _mesa_lookup_vao_err(ctx, vaobj, "glDisableVertexArrayAttrib");
1217 if (!vao)
1218 return;
1219
1220 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1221 _mesa_error(ctx, GL_INVALID_VALUE, "glDisableVertexArrayAttrib(index)");
1222 return;
1223 }
1224
1225 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
1226 _mesa_disable_vertex_array_attrib(ctx, vao, attrib, true);
1227 }
1228
1229
1230 void GLAPIENTRY
1231 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj, GLuint index)
1232 {
1233 GET_CURRENT_CONTEXT(ctx);
1234 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
1235 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
1236 _mesa_disable_vertex_array_attrib(ctx, vao, attrib, true);
1237 }
1238
1239
1240 /**
1241 * Return info for a vertex attribute array (no alias with legacy
1242 * vertex attributes (pos, normal, color, etc)). This function does
1243 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
1244 */
1245 static GLuint
1246 get_vertex_array_attrib(struct gl_context *ctx,
1247 const struct gl_vertex_array_object *vao,
1248 GLuint index, GLenum pname,
1249 const char *caller)
1250 {
1251 const struct gl_array_attributes *array;
1252
1253 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1254 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
1255 return 0;
1256 }
1257
1258 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
1259
1260 array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
1261
1262 switch (pname) {
1263 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
1264 return array->Enabled;
1265 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
1266 return (array->Format == GL_BGRA) ? GL_BGRA : array->Size;
1267 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
1268 return array->Stride;
1269 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
1270 return array->Type;
1271 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
1272 return array->Normalized;
1273 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
1274 return vao->BufferBinding[array->BufferBindingIndex].BufferObj->Name;
1275 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
1276 if ((_mesa_is_desktop_gl(ctx)
1277 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
1278 || _mesa_is_gles3(ctx)) {
1279 return array->Integer;
1280 }
1281 goto error;
1282 case GL_VERTEX_ATTRIB_ARRAY_LONG:
1283 if (_mesa_is_desktop_gl(ctx)) {
1284 return array->Doubles;
1285 }
1286 goto error;
1287 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
1288 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
1289 || _mesa_is_gles3(ctx)) {
1290 return vao->BufferBinding[array->BufferBindingIndex].InstanceDivisor;
1291 }
1292 goto error;
1293 case GL_VERTEX_ATTRIB_BINDING:
1294 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
1295 return array->BufferBindingIndex - VERT_ATTRIB_GENERIC0;
1296 }
1297 goto error;
1298 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
1299 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
1300 return array->RelativeOffset;
1301 }
1302 goto error;
1303 default:
1304 ; /* fall-through */
1305 }
1306
1307 error:
1308 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
1309 return 0;
1310 }
1311
1312
1313 static const GLfloat *
1314 get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
1315 {
1316 if (index == 0) {
1317 if (_mesa_attr_zero_aliases_vertex(ctx)) {
1318 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
1319 return NULL;
1320 }
1321 }
1322 else if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1323 _mesa_error(ctx, GL_INVALID_VALUE,
1324 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
1325 return NULL;
1326 }
1327
1328 assert(VERT_ATTRIB_GENERIC(index) <
1329 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1330
1331 FLUSH_CURRENT(ctx, 0);
1332 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
1333 }
1334
1335 void GLAPIENTRY
1336 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
1337 {
1338 GET_CURRENT_CONTEXT(ctx);
1339
1340 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1341 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
1342 if (v != NULL) {
1343 COPY_4V(params, v);
1344 }
1345 }
1346 else {
1347 params[0] = (GLfloat) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1348 index, pname,
1349 "glGetVertexAttribfv");
1350 }
1351 }
1352
1353
1354 void GLAPIENTRY
1355 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
1356 {
1357 GET_CURRENT_CONTEXT(ctx);
1358
1359 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1360 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
1361 if (v != NULL) {
1362 params[0] = (GLdouble) v[0];
1363 params[1] = (GLdouble) v[1];
1364 params[2] = (GLdouble) v[2];
1365 params[3] = (GLdouble) v[3];
1366 }
1367 }
1368 else {
1369 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1370 index, pname,
1371 "glGetVertexAttribdv");
1372 }
1373 }
1374
1375 void GLAPIENTRY
1376 _mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params)
1377 {
1378 GET_CURRENT_CONTEXT(ctx);
1379
1380 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1381 const GLdouble *v =
1382 (const GLdouble *)get_current_attrib(ctx, index,
1383 "glGetVertexAttribLdv");
1384 if (v != NULL) {
1385 params[0] = v[0];
1386 params[1] = v[1];
1387 params[2] = v[2];
1388 params[3] = v[3];
1389 }
1390 }
1391 else {
1392 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1393 index, pname,
1394 "glGetVertexAttribLdv");
1395 }
1396 }
1397
1398 void GLAPIENTRY
1399 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
1400 {
1401 GET_CURRENT_CONTEXT(ctx);
1402
1403 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1404 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
1405 if (v != NULL) {
1406 /* XXX should floats in[0,1] be scaled to full int range? */
1407 params[0] = (GLint) v[0];
1408 params[1] = (GLint) v[1];
1409 params[2] = (GLint) v[2];
1410 params[3] = (GLint) v[3];
1411 }
1412 }
1413 else {
1414 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1415 index, pname,
1416 "glGetVertexAttribiv");
1417 }
1418 }
1419
1420 void GLAPIENTRY
1421 _mesa_GetVertexAttribLui64vARB(GLuint index, GLenum pname, GLuint64EXT *params)
1422 {
1423 GET_CURRENT_CONTEXT(ctx);
1424
1425 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1426 const GLuint64 *v =
1427 (const GLuint64 *)get_current_attrib(ctx, index,
1428 "glGetVertexAttribLui64vARB");
1429 if (v != NULL) {
1430 params[0] = v[0];
1431 params[1] = v[1];
1432 params[2] = v[2];
1433 params[3] = v[3];
1434 }
1435 }
1436 else {
1437 params[0] = (GLuint64) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1438 index, pname,
1439 "glGetVertexAttribLui64vARB");
1440 }
1441 }
1442
1443
1444 /** GL 3.0 */
1445 void GLAPIENTRY
1446 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
1447 {
1448 GET_CURRENT_CONTEXT(ctx);
1449
1450 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1451 const GLint *v = (const GLint *)
1452 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
1453 if (v != NULL) {
1454 COPY_4V(params, v);
1455 }
1456 }
1457 else {
1458 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1459 index, pname,
1460 "glGetVertexAttribIiv");
1461 }
1462 }
1463
1464
1465 /** GL 3.0 */
1466 void GLAPIENTRY
1467 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
1468 {
1469 GET_CURRENT_CONTEXT(ctx);
1470
1471 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1472 const GLuint *v = (const GLuint *)
1473 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
1474 if (v != NULL) {
1475 COPY_4V(params, v);
1476 }
1477 }
1478 else {
1479 params[0] = get_vertex_array_attrib(ctx, ctx->Array.VAO,
1480 index, pname,
1481 "glGetVertexAttribIuiv");
1482 }
1483 }
1484
1485
1486 void GLAPIENTRY
1487 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
1488 {
1489 GET_CURRENT_CONTEXT(ctx);
1490
1491 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1492 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
1493 return;
1494 }
1495
1496 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
1497 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
1498 return;
1499 }
1500
1501 assert(VERT_ATTRIB_GENERIC(index) <
1502 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1503
1504 *pointer = (GLvoid *)
1505 ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
1506 }
1507
1508
1509 /** ARB_direct_state_access */
1510 void GLAPIENTRY
1511 _mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index,
1512 GLenum pname, GLint *params)
1513 {
1514 GET_CURRENT_CONTEXT(ctx);
1515 struct gl_vertex_array_object *vao;
1516
1517 /* The ARB_direct_state_access specification says:
1518 *
1519 * "An INVALID_OPERATION error is generated if <vaobj> is not
1520 * [compatibility profile: zero or] the name of an existing
1521 * vertex array object."
1522 */
1523 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexediv");
1524 if (!vao)
1525 return;
1526
1527 /* The ARB_direct_state_access specification says:
1528 *
1529 * "For GetVertexArrayIndexediv, <pname> must be one of
1530 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1531 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1532 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1533 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1534 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1535 *
1536 * and:
1537 *
1538 * "Add GetVertexArrayIndexediv in 'Get Command' for
1539 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1540 * VERTEX_ATTRIB_BINDING,
1541 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1542 * VERTEX_BINDING_OFFSET, and
1543 * VERTEX_BINDING_STRIDE states"
1544 *
1545 * The only parameter name common to both lists is
1546 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1547 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1548 * pretty clear however that the intent is that it should be possible
1549 * to query all vertex attrib and binding states that can be set with
1550 * a DSA function.
1551 */
1552 switch (pname) {
1553 case GL_VERTEX_BINDING_OFFSET:
1554 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1555 break;
1556 case GL_VERTEX_BINDING_STRIDE:
1557 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Stride;
1558 break;
1559 case GL_VERTEX_BINDING_DIVISOR:
1560 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
1561 break;
1562 case GL_VERTEX_BINDING_BUFFER:
1563 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name;
1564 break;
1565 default:
1566 params[0] = get_vertex_array_attrib(ctx, vao, index, pname,
1567 "glGetVertexArrayIndexediv");
1568 break;
1569 }
1570 }
1571
1572
1573 void GLAPIENTRY
1574 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj, GLuint index,
1575 GLenum pname, GLint64 *params)
1576 {
1577 GET_CURRENT_CONTEXT(ctx);
1578 struct gl_vertex_array_object *vao;
1579
1580 /* The ARB_direct_state_access specification says:
1581 *
1582 * "An INVALID_OPERATION error is generated if <vaobj> is not
1583 * [compatibility profile: zero or] the name of an existing
1584 * vertex array object."
1585 */
1586 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexed64iv");
1587 if (!vao)
1588 return;
1589
1590 /* The ARB_direct_state_access specification says:
1591 *
1592 * "For GetVertexArrayIndexed64iv, <pname> must be
1593 * VERTEX_BINDING_OFFSET."
1594 *
1595 * and:
1596 *
1597 * "An INVALID_ENUM error is generated if <pname> is not one of
1598 * the valid values listed above for the corresponding command."
1599 */
1600 if (pname != GL_VERTEX_BINDING_OFFSET) {
1601 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayIndexed64iv("
1602 "pname != GL_VERTEX_BINDING_OFFSET)");
1603 return;
1604 }
1605
1606 /* The ARB_direct_state_access specification says:
1607 *
1608 * "An INVALID_VALUE error is generated if <index> is greater than
1609 * or equal to the value of MAX_VERTEX_ATTRIBS."
1610 *
1611 * Since the index refers to a buffer binding in this case, the intended
1612 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1613 * required to be the same, so in practice this doesn't matter.
1614 */
1615 if (index >= ctx->Const.MaxVertexAttribBindings) {
1616 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexArrayIndexed64iv(index"
1617 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1618 index, ctx->Const.MaxVertexAttribBindings);
1619 return;
1620 }
1621
1622 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1623 }
1624
1625
1626 void GLAPIENTRY
1627 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
1628 GLsizei count, const GLvoid *ptr)
1629 {
1630 (void) count;
1631 _mesa_VertexPointer(size, type, stride, ptr);
1632 }
1633
1634
1635 void GLAPIENTRY
1636 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1637 const GLvoid *ptr)
1638 {
1639 (void) count;
1640 _mesa_NormalPointer(type, stride, ptr);
1641 }
1642
1643
1644 void GLAPIENTRY
1645 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
1646 const GLvoid *ptr)
1647 {
1648 (void) count;
1649 _mesa_ColorPointer(size, type, stride, ptr);
1650 }
1651
1652
1653 void GLAPIENTRY
1654 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1655 const GLvoid *ptr)
1656 {
1657 (void) count;
1658 _mesa_IndexPointer(type, stride, ptr);
1659 }
1660
1661
1662 void GLAPIENTRY
1663 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
1664 GLsizei count, const GLvoid *ptr)
1665 {
1666 (void) count;
1667 _mesa_TexCoordPointer(size, type, stride, ptr);
1668 }
1669
1670
1671 void GLAPIENTRY
1672 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
1673 {
1674 (void) count;
1675 _mesa_EdgeFlagPointer(stride, ptr);
1676 }
1677
1678
1679 void GLAPIENTRY
1680 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
1681 {
1682 GET_CURRENT_CONTEXT(ctx);
1683 GLboolean tflag, cflag, nflag; /* enable/disable flags */
1684 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
1685 GLenum ctype = 0; /* color type */
1686 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
1687 const GLint toffset = 0; /* always zero */
1688 GLint defstride; /* default stride */
1689 GLint c, f;
1690
1691 f = sizeof(GLfloat);
1692 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
1693
1694 if (stride < 0) {
1695 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
1696 return;
1697 }
1698
1699 switch (format) {
1700 case GL_V2F:
1701 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1702 tcomps = 0; ccomps = 0; vcomps = 2;
1703 voffset = 0;
1704 defstride = 2*f;
1705 break;
1706 case GL_V3F:
1707 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1708 tcomps = 0; ccomps = 0; vcomps = 3;
1709 voffset = 0;
1710 defstride = 3*f;
1711 break;
1712 case GL_C4UB_V2F:
1713 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1714 tcomps = 0; ccomps = 4; vcomps = 2;
1715 ctype = GL_UNSIGNED_BYTE;
1716 coffset = 0;
1717 voffset = c;
1718 defstride = c + 2*f;
1719 break;
1720 case GL_C4UB_V3F:
1721 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1722 tcomps = 0; ccomps = 4; vcomps = 3;
1723 ctype = GL_UNSIGNED_BYTE;
1724 coffset = 0;
1725 voffset = c;
1726 defstride = c + 3*f;
1727 break;
1728 case GL_C3F_V3F:
1729 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1730 tcomps = 0; ccomps = 3; vcomps = 3;
1731 ctype = GL_FLOAT;
1732 coffset = 0;
1733 voffset = 3*f;
1734 defstride = 6*f;
1735 break;
1736 case GL_N3F_V3F:
1737 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1738 tcomps = 0; ccomps = 0; vcomps = 3;
1739 noffset = 0;
1740 voffset = 3*f;
1741 defstride = 6*f;
1742 break;
1743 case GL_C4F_N3F_V3F:
1744 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1745 tcomps = 0; ccomps = 4; vcomps = 3;
1746 ctype = GL_FLOAT;
1747 coffset = 0;
1748 noffset = 4*f;
1749 voffset = 7*f;
1750 defstride = 10*f;
1751 break;
1752 case GL_T2F_V3F:
1753 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1754 tcomps = 2; ccomps = 0; vcomps = 3;
1755 voffset = 2*f;
1756 defstride = 5*f;
1757 break;
1758 case GL_T4F_V4F:
1759 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1760 tcomps = 4; ccomps = 0; vcomps = 4;
1761 voffset = 4*f;
1762 defstride = 8*f;
1763 break;
1764 case GL_T2F_C4UB_V3F:
1765 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1766 tcomps = 2; ccomps = 4; vcomps = 3;
1767 ctype = GL_UNSIGNED_BYTE;
1768 coffset = 2*f;
1769 voffset = c+2*f;
1770 defstride = c+5*f;
1771 break;
1772 case GL_T2F_C3F_V3F:
1773 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1774 tcomps = 2; ccomps = 3; vcomps = 3;
1775 ctype = GL_FLOAT;
1776 coffset = 2*f;
1777 voffset = 5*f;
1778 defstride = 8*f;
1779 break;
1780 case GL_T2F_N3F_V3F:
1781 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1782 tcomps = 2; ccomps = 0; vcomps = 3;
1783 noffset = 2*f;
1784 voffset = 5*f;
1785 defstride = 8*f;
1786 break;
1787 case GL_T2F_C4F_N3F_V3F:
1788 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1789 tcomps = 2; ccomps = 4; vcomps = 3;
1790 ctype = GL_FLOAT;
1791 coffset = 2*f;
1792 noffset = 6*f;
1793 voffset = 9*f;
1794 defstride = 12*f;
1795 break;
1796 case GL_T4F_C4F_N3F_V4F:
1797 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1798 tcomps = 4; ccomps = 4; vcomps = 4;
1799 ctype = GL_FLOAT;
1800 coffset = 4*f;
1801 noffset = 8*f;
1802 voffset = 11*f;
1803 defstride = 15*f;
1804 break;
1805 default:
1806 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
1807 return;
1808 }
1809
1810 if (stride==0) {
1811 stride = defstride;
1812 }
1813
1814 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1815 _mesa_DisableClientState( GL_INDEX_ARRAY );
1816 /* XXX also disable secondary color and generic arrays? */
1817
1818 /* Texcoords */
1819 if (tflag) {
1820 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1821 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
1822 (GLubyte *) pointer + toffset );
1823 }
1824 else {
1825 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
1826 }
1827
1828 /* Color */
1829 if (cflag) {
1830 _mesa_EnableClientState( GL_COLOR_ARRAY );
1831 _mesa_ColorPointer( ccomps, ctype, stride,
1832 (GLubyte *) pointer + coffset );
1833 }
1834 else {
1835 _mesa_DisableClientState( GL_COLOR_ARRAY );
1836 }
1837
1838
1839 /* Normals */
1840 if (nflag) {
1841 _mesa_EnableClientState( GL_NORMAL_ARRAY );
1842 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
1843 }
1844 else {
1845 _mesa_DisableClientState( GL_NORMAL_ARRAY );
1846 }
1847
1848 /* Vertices */
1849 _mesa_EnableClientState( GL_VERTEX_ARRAY );
1850 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
1851 (GLubyte *) pointer + voffset );
1852 }
1853
1854
1855 void GLAPIENTRY
1856 _mesa_LockArraysEXT(GLint first, GLsizei count)
1857 {
1858 GET_CURRENT_CONTEXT(ctx);
1859
1860 if (MESA_VERBOSE & VERBOSE_API)
1861 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
1862
1863 if (first < 0) {
1864 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1865 return;
1866 }
1867 if (count <= 0) {
1868 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1869 return;
1870 }
1871 if (ctx->Array.LockCount != 0) {
1872 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1873 return;
1874 }
1875
1876 ctx->Array.LockFirst = first;
1877 ctx->Array.LockCount = count;
1878
1879 ctx->NewState |= _NEW_ARRAY;
1880 }
1881
1882
1883 void GLAPIENTRY
1884 _mesa_UnlockArraysEXT( void )
1885 {
1886 GET_CURRENT_CONTEXT(ctx);
1887
1888 if (MESA_VERBOSE & VERBOSE_API)
1889 _mesa_debug(ctx, "glUnlockArrays\n");
1890
1891 if (ctx->Array.LockCount == 0) {
1892 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1893 return;
1894 }
1895
1896 ctx->Array.LockFirst = 0;
1897 ctx->Array.LockCount = 0;
1898 ctx->NewState |= _NEW_ARRAY;
1899 }
1900
1901
1902 /* GL_IBM_multimode_draw_arrays */
1903 void GLAPIENTRY
1904 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1905 const GLsizei * count,
1906 GLsizei primcount, GLint modestride )
1907 {
1908 GET_CURRENT_CONTEXT(ctx);
1909 GLint i;
1910
1911 FLUSH_VERTICES(ctx, 0);
1912
1913 for ( i = 0 ; i < primcount ; i++ ) {
1914 if ( count[i] > 0 ) {
1915 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1916 CALL_DrawArrays(ctx->CurrentServerDispatch, ( m, first[i], count[i] ));
1917 }
1918 }
1919 }
1920
1921
1922 /* GL_IBM_multimode_draw_arrays */
1923 void GLAPIENTRY
1924 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1925 GLenum type, const GLvoid * const * indices,
1926 GLsizei primcount, GLint modestride )
1927 {
1928 GET_CURRENT_CONTEXT(ctx);
1929 GLint i;
1930
1931 FLUSH_VERTICES(ctx, 0);
1932
1933 /* XXX not sure about ARB_vertex_buffer_object handling here */
1934
1935 for ( i = 0 ; i < primcount ; i++ ) {
1936 if ( count[i] > 0 ) {
1937 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1938 CALL_DrawElements(ctx->CurrentServerDispatch, ( m, count[i], type,
1939 indices[i] ));
1940 }
1941 }
1942 }
1943
1944
1945 static void
1946 primitive_restart_index(struct gl_context *ctx, GLuint index)
1947 {
1948 ctx->Array.RestartIndex = index;
1949 }
1950
1951
1952 /**
1953 * GL_NV_primitive_restart and GL 3.1
1954 */
1955 void GLAPIENTRY
1956 _mesa_PrimitiveRestartIndex_no_error(GLuint index)
1957 {
1958 GET_CURRENT_CONTEXT(ctx);
1959 primitive_restart_index(ctx, index);
1960 }
1961
1962
1963 void GLAPIENTRY
1964 _mesa_PrimitiveRestartIndex(GLuint index)
1965 {
1966 GET_CURRENT_CONTEXT(ctx);
1967
1968 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
1969 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
1970 return;
1971 }
1972
1973 primitive_restart_index(ctx, index);
1974 }
1975
1976
1977 void GLAPIENTRY
1978 _mesa_VertexAttribDivisor_no_error(GLuint index, GLuint divisor)
1979 {
1980 GET_CURRENT_CONTEXT(ctx);
1981
1982 const gl_vert_attrib genericIndex = VERT_ATTRIB_GENERIC(index);
1983 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
1984
1985 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
1986
1987 /* The ARB_vertex_attrib_binding spec says:
1988 *
1989 * "The command
1990 *
1991 * void VertexAttribDivisor(uint index, uint divisor);
1992 *
1993 * is equivalent to (assuming no errors are generated):
1994 *
1995 * VertexAttribBinding(index, index);
1996 * VertexBindingDivisor(index, divisor);"
1997 */
1998 _mesa_vertex_attrib_binding(ctx, vao, genericIndex, genericIndex, true);
1999 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
2000 }
2001
2002
2003 /**
2004 * See GL_ARB_instanced_arrays.
2005 * Note that the instance divisor only applies to generic arrays, not
2006 * the legacy vertex arrays.
2007 */
2008 void GLAPIENTRY
2009 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
2010 {
2011 GET_CURRENT_CONTEXT(ctx);
2012
2013 const gl_vert_attrib genericIndex = VERT_ATTRIB_GENERIC(index);
2014 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
2015
2016 if (!ctx->Extensions.ARB_instanced_arrays) {
2017 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
2018 return;
2019 }
2020
2021 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2022 _mesa_error(ctx, GL_INVALID_VALUE,
2023 "glVertexAttribDivisor(index = %u)", index);
2024 return;
2025 }
2026
2027 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
2028
2029 /* The ARB_vertex_attrib_binding spec says:
2030 *
2031 * "The command
2032 *
2033 * void VertexAttribDivisor(uint index, uint divisor);
2034 *
2035 * is equivalent to (assuming no errors are generated):
2036 *
2037 * VertexAttribBinding(index, index);
2038 * VertexBindingDivisor(index, divisor);"
2039 */
2040 _mesa_vertex_attrib_binding(ctx, vao, genericIndex, genericIndex, true);
2041 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
2042 }
2043
2044
2045 static ALWAYS_INLINE void
2046 vertex_array_vertex_buffer(struct gl_context *ctx,
2047 struct gl_vertex_array_object *vao,
2048 GLuint bindingIndex, GLuint buffer, GLintptr offset,
2049 GLsizei stride, bool no_error, const char *func)
2050 {
2051 struct gl_buffer_object *vbo;
2052 if (buffer ==
2053 vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) {
2054 vbo = vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
2055 } else if (buffer != 0) {
2056 vbo = _mesa_lookup_bufferobj(ctx, buffer);
2057
2058 if (!no_error && !vbo && _mesa_is_gles31(ctx)) {
2059 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-gen name)", func);
2060 return;
2061 }
2062 /* From the GL_ARB_vertex_attrib_array spec:
2063 *
2064 * "[Core profile only:]
2065 * An INVALID_OPERATION error is generated if buffer is not zero or a
2066 * name returned from a previous call to GenBuffers, or if such a name
2067 * has since been deleted with DeleteBuffers.
2068 *
2069 * Otherwise, we fall back to the same compat profile behavior as other
2070 * object references (automatically gen it).
2071 */
2072 if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &vbo, func))
2073 return;
2074 } else {
2075 /* The ARB_vertex_attrib_binding spec says:
2076 *
2077 * "If <buffer> is zero, any buffer object attached to this
2078 * bindpoint is detached."
2079 */
2080 vbo = ctx->Shared->NullBufferObj;
2081 }
2082
2083 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex),
2084 vbo, offset, stride, true);
2085 }
2086
2087
2088 /**
2089 * GL_ARB_vertex_attrib_binding
2090 */
2091 static void
2092 vertex_array_vertex_buffer_err(struct gl_context *ctx,
2093 struct gl_vertex_array_object *vao,
2094 GLuint bindingIndex, GLuint buffer,
2095 GLintptr offset, GLsizei stride,
2096 const char *func)
2097 {
2098 ASSERT_OUTSIDE_BEGIN_END(ctx);
2099
2100 /* The ARB_vertex_attrib_binding spec says:
2101 *
2102 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2103 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2104 */
2105 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2106 _mesa_error(ctx, GL_INVALID_VALUE,
2107 "%s(bindingindex=%u > "
2108 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2109 func, bindingIndex);
2110 return;
2111 }
2112
2113 /* The ARB_vertex_attrib_binding spec says:
2114 *
2115 * "The error INVALID_VALUE is generated if <stride> or <offset>
2116 * are negative."
2117 */
2118 if (offset < 0) {
2119 _mesa_error(ctx, GL_INVALID_VALUE,
2120 "%s(offset=%" PRId64 " < 0)",
2121 func, (int64_t) offset);
2122 return;
2123 }
2124
2125 if (stride < 0) {
2126 _mesa_error(ctx, GL_INVALID_VALUE,
2127 "%s(stride=%d < 0)", func, stride);
2128 return;
2129 }
2130
2131 if (((_mesa_is_desktop_gl(ctx) && ctx->Version >= 44) || _mesa_is_gles31(ctx)) &&
2132 stride > ctx->Const.MaxVertexAttribStride) {
2133 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
2134 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
2135 return;
2136 }
2137
2138 vertex_array_vertex_buffer(ctx, vao, bindingIndex, buffer, offset,
2139 stride, false, func);
2140 }
2141
2142
2143 void GLAPIENTRY
2144 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex, GLuint buffer,
2145 GLintptr offset, GLsizei stride)
2146 {
2147 GET_CURRENT_CONTEXT(ctx);
2148 vertex_array_vertex_buffer(ctx, ctx->Array.VAO, bindingIndex,
2149 buffer, offset, stride, true,
2150 "glBindVertexBuffer");
2151 }
2152
2153
2154 void GLAPIENTRY
2155 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
2156 GLsizei stride)
2157 {
2158 GET_CURRENT_CONTEXT(ctx);
2159
2160 /* The ARB_vertex_attrib_binding spec says:
2161 *
2162 * "An INVALID_OPERATION error is generated if no vertex array object
2163 * is bound."
2164 */
2165 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2166 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2167 _mesa_error(ctx, GL_INVALID_OPERATION,
2168 "glBindVertexBuffer(No array object bound)");
2169 return;
2170 }
2171
2172 vertex_array_vertex_buffer_err(ctx, ctx->Array.VAO, bindingIndex,
2173 buffer, offset, stride,
2174 "glBindVertexBuffer");
2175 }
2176
2177
2178 void GLAPIENTRY
2179 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj, GLuint bindingIndex,
2180 GLuint buffer, GLintptr offset,
2181 GLsizei stride)
2182 {
2183 GET_CURRENT_CONTEXT(ctx);
2184
2185 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2186 vertex_array_vertex_buffer(ctx, vao, bindingIndex, buffer, offset,
2187 stride, true, "glVertexArrayVertexBuffer");
2188 }
2189
2190
2191 void GLAPIENTRY
2192 _mesa_VertexArrayVertexBuffer(GLuint vaobj, GLuint bindingIndex, GLuint buffer,
2193 GLintptr offset, GLsizei stride)
2194 {
2195 GET_CURRENT_CONTEXT(ctx);
2196 struct gl_vertex_array_object *vao;
2197
2198 /* The ARB_direct_state_access specification says:
2199 *
2200 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2201 * if <vaobj> is not [compatibility profile: zero or] the name of an
2202 * existing vertex array object."
2203 */
2204 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffer");
2205 if (!vao)
2206 return;
2207
2208 vertex_array_vertex_buffer_err(ctx, vao, bindingIndex, buffer, offset,
2209 stride, "glVertexArrayVertexBuffer");
2210 }
2211
2212
2213 static ALWAYS_INLINE void
2214 vertex_array_vertex_buffers(struct gl_context *ctx,
2215 struct gl_vertex_array_object *vao,
2216 GLuint first, GLsizei count, const GLuint *buffers,
2217 const GLintptr *offsets, const GLsizei *strides,
2218 bool no_error, const char *func)
2219 {
2220 GLint i;
2221
2222 if (!buffers) {
2223 /**
2224 * The ARB_multi_bind spec says:
2225 *
2226 * "If <buffers> is NULL, each affected vertex buffer binding point
2227 * from <first> through <first>+<count>-1 will be reset to have no
2228 * bound buffer object. In this case, the offsets and strides
2229 * associated with the binding points are set to default values,
2230 * ignoring <offsets> and <strides>."
2231 */
2232 struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj;
2233
2234 for (i = 0; i < count; i++)
2235 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
2236 vbo, 0, 16, true);
2237
2238 return;
2239 }
2240
2241 /* Note that the error semantics for multi-bind commands differ from
2242 * those of other GL commands.
2243 *
2244 * The Issues section in the ARB_multi_bind spec says:
2245 *
2246 * "(11) Typically, OpenGL specifies that if an error is generated by
2247 * a command, that command has no effect. This is somewhat
2248 * unfortunate for multi-bind commands, because it would require
2249 * a first pass to scan the entire list of bound objects for
2250 * errors and then a second pass to actually perform the
2251 * bindings. Should we have different error semantics?
2252 *
2253 * RESOLVED: Yes. In this specification, when the parameters for
2254 * one of the <count> binding points are invalid, that binding
2255 * point is not updated and an error will be generated. However,
2256 * other binding points in the same command will be updated if
2257 * their parameters are valid and no other error occurs."
2258 */
2259
2260 _mesa_HashLockMutex(ctx->Shared->BufferObjects);
2261
2262 for (i = 0; i < count; i++) {
2263 struct gl_buffer_object *vbo;
2264
2265 if (!no_error) {
2266 /* The ARB_multi_bind spec says:
2267 *
2268 * "An INVALID_VALUE error is generated if any value in
2269 * <offsets> or <strides> is negative (per binding)."
2270 */
2271 if (offsets[i] < 0) {
2272 _mesa_error(ctx, GL_INVALID_VALUE,
2273 "%s(offsets[%u]=%" PRId64 " < 0)",
2274 func, i, (int64_t) offsets[i]);
2275 continue;
2276 }
2277
2278 if (strides[i] < 0) {
2279 _mesa_error(ctx, GL_INVALID_VALUE,
2280 "%s(strides[%u]=%d < 0)",
2281 func, i, strides[i]);
2282 continue;
2283 }
2284
2285 if (_mesa_is_desktop_gl(ctx) && ctx->Version >= 44 &&
2286 strides[i] > ctx->Const.MaxVertexAttribStride) {
2287 _mesa_error(ctx, GL_INVALID_VALUE,
2288 "%s(strides[%u]=%d > "
2289 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, i, strides[i]);
2290 continue;
2291 }
2292 }
2293
2294 if (buffers[i]) {
2295 struct gl_vertex_buffer_binding *binding =
2296 &vao->BufferBinding[VERT_ATTRIB_GENERIC(first + i)];
2297
2298 if (buffers[i] == binding->BufferObj->Name)
2299 vbo = binding->BufferObj;
2300 else
2301 vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, func);
2302
2303 if (!vbo)
2304 continue;
2305 } else {
2306 vbo = ctx->Shared->NullBufferObj;
2307 }
2308
2309 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
2310 vbo, offsets[i], strides[i], true);
2311 }
2312
2313 _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
2314 }
2315
2316
2317 static void
2318 vertex_array_vertex_buffers_err(struct gl_context *ctx,
2319 struct gl_vertex_array_object *vao,
2320 GLuint first, GLsizei count,
2321 const GLuint *buffers, const GLintptr *offsets,
2322 const GLsizei *strides, const char *func)
2323 {
2324 ASSERT_OUTSIDE_BEGIN_END(ctx);
2325
2326 /* The ARB_multi_bind spec says:
2327 *
2328 * "An INVALID_OPERATION error is generated if <first> + <count>
2329 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
2330 */
2331 if (first + count > ctx->Const.MaxVertexAttribBindings) {
2332 _mesa_error(ctx, GL_INVALID_OPERATION,
2333 "%s(first=%u + count=%d > the value of "
2334 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
2335 func, first, count, ctx->Const.MaxVertexAttribBindings);
2336 return;
2337 }
2338
2339 vertex_array_vertex_buffers(ctx, vao, first, count, buffers, offsets,
2340 strides, false, func);
2341 }
2342
2343
2344 void GLAPIENTRY
2345 _mesa_BindVertexBuffers_no_error(GLuint first, GLsizei count,
2346 const GLuint *buffers, const GLintptr *offsets,
2347 const GLsizei *strides)
2348 {
2349 GET_CURRENT_CONTEXT(ctx);
2350
2351 vertex_array_vertex_buffers(ctx, ctx->Array.VAO, first, count,
2352 buffers, offsets, strides, true,
2353 "glBindVertexBuffers");
2354 }
2355
2356
2357 void GLAPIENTRY
2358 _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
2359 const GLintptr *offsets, const GLsizei *strides)
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
2366 * vertex array object is bound."
2367 */
2368 if (ctx->API == API_OPENGL_CORE &&
2369 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2370 _mesa_error(ctx, GL_INVALID_OPERATION,
2371 "glBindVertexBuffers(No array object bound)");
2372 return;
2373 }
2374
2375 vertex_array_vertex_buffers_err(ctx, ctx->Array.VAO, first, count,
2376 buffers, offsets, strides,
2377 "glBindVertexBuffers");
2378 }
2379
2380
2381 void GLAPIENTRY
2382 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj, GLuint first,
2383 GLsizei count, const GLuint *buffers,
2384 const GLintptr *offsets,
2385 const GLsizei *strides)
2386 {
2387 GET_CURRENT_CONTEXT(ctx);
2388
2389 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2390 vertex_array_vertex_buffers(ctx, vao, first, count,
2391 buffers, offsets, strides, true,
2392 "glVertexArrayVertexBuffers");
2393 }
2394
2395
2396 void GLAPIENTRY
2397 _mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count,
2398 const GLuint *buffers,
2399 const GLintptr *offsets, const GLsizei *strides)
2400 {
2401 GET_CURRENT_CONTEXT(ctx);
2402 struct gl_vertex_array_object *vao;
2403
2404 /* The ARB_direct_state_access specification says:
2405 *
2406 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2407 * if <vaobj> is not [compatibility profile: zero or] the name of an
2408 * existing vertex array object."
2409 */
2410 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffers");
2411 if (!vao)
2412 return;
2413
2414 vertex_array_vertex_buffers_err(ctx, vao, first, count,
2415 buffers, offsets, strides,
2416 "glVertexArrayVertexBuffers");
2417 }
2418
2419
2420 static void
2421 vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type,
2422 GLboolean normalized, GLboolean integer,
2423 GLboolean doubles, GLbitfield legalTypes,
2424 GLsizei sizeMax, GLuint relativeOffset,
2425 const char *func)
2426 {
2427 GET_CURRENT_CONTEXT(ctx);
2428 ASSERT_OUTSIDE_BEGIN_END(ctx);
2429
2430 GLenum format = get_array_format(ctx, sizeMax, &size);
2431
2432 if (!_mesa_is_no_error_enabled(ctx)) {
2433 /* The ARB_vertex_attrib_binding spec says:
2434 *
2435 * "An INVALID_OPERATION error is generated under any of the
2436 * following conditions:
2437 * - if no vertex array object is currently bound (see section
2438 * 2.10);
2439 * - ..."
2440 *
2441 * This error condition only applies to VertexAttribFormat and
2442 * VertexAttribIFormat in the extension spec, but we assume that this
2443 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2444 * to all three functions.
2445 */
2446 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2447 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2448 _mesa_error(ctx, GL_INVALID_OPERATION,
2449 "%s(No array object bound)", func);
2450 return;
2451 }
2452
2453 /* The ARB_vertex_attrib_binding spec says:
2454 *
2455 * "The error INVALID_VALUE is generated if index is greater than or
2456 * equal to the value of MAX_VERTEX_ATTRIBS."
2457 */
2458 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2459 _mesa_error(ctx, GL_INVALID_VALUE,
2460 "%s(attribindex=%u > "
2461 "GL_MAX_VERTEX_ATTRIBS)",
2462 func, attribIndex);
2463 return;
2464 }
2465
2466 if (!validate_array_format(ctx, func, ctx->Array.VAO,
2467 VERT_ATTRIB_GENERIC(attribIndex),
2468 legalTypes, 1, sizeMax, size, type,
2469 normalized, integer, doubles, relativeOffset,
2470 format)) {
2471 return;
2472 }
2473 }
2474
2475 _mesa_update_array_format(ctx, ctx->Array.VAO,
2476 VERT_ATTRIB_GENERIC(attribIndex), size, type,
2477 format, normalized, integer, doubles,
2478 relativeOffset);
2479 }
2480
2481
2482 void GLAPIENTRY
2483 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
2484 GLboolean normalized, GLuint relativeOffset)
2485 {
2486 vertex_attrib_format(attribIndex, size, type, normalized,
2487 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
2488 BGRA_OR_4, relativeOffset,
2489 "glVertexAttribFormat");
2490 }
2491
2492
2493 void GLAPIENTRY
2494 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
2495 GLuint relativeOffset)
2496 {
2497 vertex_attrib_format(attribIndex, size, type, GL_FALSE,
2498 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK, 4,
2499 relativeOffset, "glVertexAttribIFormat");
2500 }
2501
2502
2503 void GLAPIENTRY
2504 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
2505 GLuint relativeOffset)
2506 {
2507 vertex_attrib_format(attribIndex, size, type, GL_FALSE, GL_FALSE,
2508 GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK, 4,
2509 relativeOffset, "glVertexAttribLFormat");
2510 }
2511
2512
2513 static void
2514 vertex_array_attrib_format(GLuint vaobj, GLuint attribIndex, GLint size,
2515 GLenum type, GLboolean normalized,
2516 GLboolean integer, GLboolean doubles,
2517 GLbitfield legalTypes, GLsizei sizeMax,
2518 GLuint relativeOffset, const char *func)
2519 {
2520 GET_CURRENT_CONTEXT(ctx);
2521 struct gl_vertex_array_object *vao;
2522
2523 ASSERT_OUTSIDE_BEGIN_END(ctx);
2524
2525 GLenum format = get_array_format(ctx, sizeMax, &size);
2526
2527 if (_mesa_is_no_error_enabled(ctx)) {
2528 vao = _mesa_lookup_vao(ctx, vaobj);
2529 if (!vao)
2530 return;
2531 } else {
2532 /* The ARB_direct_state_access spec says:
2533 *
2534 * "An INVALID_OPERATION error is generated by
2535 * VertexArrayAttrib*Format if <vaobj> is not [compatibility profile:
2536 * zero or] the name of an existing vertex array object."
2537 */
2538 vao = _mesa_lookup_vao_err(ctx, vaobj, func);
2539 if (!vao)
2540 return;
2541
2542 /* The ARB_vertex_attrib_binding spec says:
2543 *
2544 * "The error INVALID_VALUE is generated if index is greater than or
2545 * equal to the value of MAX_VERTEX_ATTRIBS."
2546 */
2547 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2548 _mesa_error(ctx, GL_INVALID_VALUE,
2549 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2550 func, attribIndex);
2551 return;
2552 }
2553
2554 if (!validate_array_format(ctx, func, vao,
2555 VERT_ATTRIB_GENERIC(attribIndex),
2556 legalTypes, 1, sizeMax, size, type,
2557 normalized, integer, doubles, relativeOffset,
2558 format)) {
2559 return;
2560 }
2561 }
2562
2563 _mesa_update_array_format(ctx, vao, VERT_ATTRIB_GENERIC(attribIndex), size,
2564 type, format, normalized, integer, doubles,
2565 relativeOffset);
2566 }
2567
2568
2569 void GLAPIENTRY
2570 _mesa_VertexArrayAttribFormat(GLuint vaobj, GLuint attribIndex, GLint size,
2571 GLenum type, GLboolean normalized,
2572 GLuint relativeOffset)
2573 {
2574 vertex_array_attrib_format(vaobj, attribIndex, size, type, normalized,
2575 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
2576 BGRA_OR_4, relativeOffset,
2577 "glVertexArrayAttribFormat");
2578 }
2579
2580
2581 void GLAPIENTRY
2582 _mesa_VertexArrayAttribIFormat(GLuint vaobj, GLuint attribIndex,
2583 GLint size, GLenum type,
2584 GLuint relativeOffset)
2585 {
2586 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2587 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK,
2588 4, relativeOffset,
2589 "glVertexArrayAttribIFormat");
2590 }
2591
2592
2593 void GLAPIENTRY
2594 _mesa_VertexArrayAttribLFormat(GLuint vaobj, GLuint attribIndex,
2595 GLint size, GLenum type,
2596 GLuint relativeOffset)
2597 {
2598 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2599 GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK,
2600 4, relativeOffset,
2601 "glVertexArrayAttribLFormat");
2602 }
2603
2604
2605 static void
2606 vertex_array_attrib_binding(struct gl_context *ctx,
2607 struct gl_vertex_array_object *vao,
2608 GLuint attribIndex, GLuint bindingIndex,
2609 const char *func)
2610 {
2611 ASSERT_OUTSIDE_BEGIN_END(ctx);
2612
2613 /* The ARB_vertex_attrib_binding spec says:
2614 *
2615 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2616 * <bindingindex> must be less than the value of
2617 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2618 * is generated."
2619 */
2620 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2621 _mesa_error(ctx, GL_INVALID_VALUE,
2622 "%s(attribindex=%u >= "
2623 "GL_MAX_VERTEX_ATTRIBS)",
2624 func, attribIndex);
2625 return;
2626 }
2627
2628 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2629 _mesa_error(ctx, GL_INVALID_VALUE,
2630 "%s(bindingindex=%u >= "
2631 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2632 func, bindingIndex);
2633 return;
2634 }
2635
2636 assert(VERT_ATTRIB_GENERIC(attribIndex) < ARRAY_SIZE(vao->VertexAttrib));
2637
2638 _mesa_vertex_attrib_binding(ctx, vao,
2639 VERT_ATTRIB_GENERIC(attribIndex),
2640 VERT_ATTRIB_GENERIC(bindingIndex), true);
2641 }
2642
2643
2644 void GLAPIENTRY
2645 _mesa_VertexAttribBinding_no_error(GLuint attribIndex, GLuint bindingIndex)
2646 {
2647 GET_CURRENT_CONTEXT(ctx);
2648 _mesa_vertex_attrib_binding(ctx, ctx->Array.VAO,
2649 VERT_ATTRIB_GENERIC(attribIndex),
2650 VERT_ATTRIB_GENERIC(bindingIndex), true);
2651 }
2652
2653
2654 void GLAPIENTRY
2655 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
2656 {
2657 GET_CURRENT_CONTEXT(ctx);
2658
2659 /* The ARB_vertex_attrib_binding spec says:
2660 *
2661 * "An INVALID_OPERATION error is generated if no vertex array object
2662 * is bound."
2663 */
2664 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2665 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2666 _mesa_error(ctx, GL_INVALID_OPERATION,
2667 "glVertexAttribBinding(No array object bound)");
2668 return;
2669 }
2670
2671 vertex_array_attrib_binding(ctx, ctx->Array.VAO,
2672 attribIndex, bindingIndex,
2673 "glVertexAttribBinding");
2674 }
2675
2676
2677 void GLAPIENTRY
2678 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj, GLuint attribIndex,
2679 GLuint bindingIndex)
2680 {
2681 GET_CURRENT_CONTEXT(ctx);
2682
2683 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2684 _mesa_vertex_attrib_binding(ctx, vao,
2685 VERT_ATTRIB_GENERIC(attribIndex),
2686 VERT_ATTRIB_GENERIC(bindingIndex), true);
2687 }
2688
2689
2690 void GLAPIENTRY
2691 _mesa_VertexArrayAttribBinding(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex)
2692 {
2693 GET_CURRENT_CONTEXT(ctx);
2694 struct gl_vertex_array_object *vao;
2695
2696 /* The ARB_direct_state_access specification says:
2697 *
2698 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2699 * if <vaobj> is not [compatibility profile: zero or] the name of an
2700 * existing vertex array object."
2701 */
2702 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayAttribBinding");
2703 if (!vao)
2704 return;
2705
2706 vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex,
2707 "glVertexArrayAttribBinding");
2708 }
2709
2710
2711 static void
2712 vertex_array_binding_divisor(struct gl_context *ctx,
2713 struct gl_vertex_array_object *vao,
2714 GLuint bindingIndex, GLuint divisor,
2715 const char *func)
2716 {
2717 ASSERT_OUTSIDE_BEGIN_END(ctx);
2718
2719 if (!ctx->Extensions.ARB_instanced_arrays) {
2720 _mesa_error(ctx, GL_INVALID_OPERATION, "%s()", func);
2721 return;
2722 }
2723
2724 /* The ARB_vertex_attrib_binding spec says:
2725 *
2726 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2727 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2728 */
2729 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2730 _mesa_error(ctx, GL_INVALID_VALUE,
2731 "%s(bindingindex=%u > "
2732 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2733 func, bindingIndex);
2734 return;
2735 }
2736
2737 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
2738 }
2739
2740
2741 void GLAPIENTRY
2742 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex, GLuint divisor)
2743 {
2744 GET_CURRENT_CONTEXT(ctx);
2745 vertex_binding_divisor(ctx, ctx->Array.VAO,
2746 VERT_ATTRIB_GENERIC(bindingIndex), divisor);
2747 }
2748
2749
2750 void GLAPIENTRY
2751 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
2752 {
2753 GET_CURRENT_CONTEXT(ctx);
2754
2755 /* The ARB_vertex_attrib_binding spec says:
2756 *
2757 * "An INVALID_OPERATION error is generated if no vertex array object
2758 * is bound."
2759 */
2760 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2761 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2762 _mesa_error(ctx, GL_INVALID_OPERATION,
2763 "glVertexBindingDivisor(No array object bound)");
2764 return;
2765 }
2766
2767 vertex_array_binding_divisor(ctx, ctx->Array.VAO,
2768 bindingIndex, divisor,
2769 "glVertexBindingDivisor");
2770 }
2771
2772
2773 void GLAPIENTRY
2774 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj, GLuint bindingIndex,
2775 GLuint divisor)
2776 {
2777 GET_CURRENT_CONTEXT(ctx);
2778
2779 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2780 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
2781 }
2782
2783
2784 void GLAPIENTRY
2785 _mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex,
2786 GLuint divisor)
2787 {
2788 struct gl_vertex_array_object *vao;
2789 GET_CURRENT_CONTEXT(ctx);
2790
2791 /* The ARB_direct_state_access specification says:
2792 *
2793 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2794 * if <vaobj> is not [compatibility profile: zero or] the name of an
2795 * existing vertex array object."
2796 */
2797 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayBindingDivisor");
2798 if (!vao)
2799 return;
2800
2801 vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor,
2802 "glVertexArrayBindingDivisor");
2803 }
2804
2805
2806 void
2807 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
2808 struct gl_array_attributes *dst,
2809 const struct gl_array_attributes *src)
2810 {
2811 dst->Size = src->Size;
2812 dst->Type = src->Type;
2813 dst->Format = src->Format;
2814 dst->BufferBindingIndex = src->BufferBindingIndex;
2815 dst->RelativeOffset = src->RelativeOffset;
2816 dst->Format = src->Format;
2817 dst->Integer = src->Integer;
2818 dst->Doubles = src->Doubles;
2819 dst->Normalized = src->Normalized;
2820 dst->Ptr = src->Ptr;
2821 dst->Enabled = src->Enabled;
2822 dst->_ElementSize = src->_ElementSize;
2823 dst->_EffBufferBindingIndex = src->_EffBufferBindingIndex;
2824 dst->_EffRelativeOffset = src->_EffRelativeOffset;
2825 }
2826
2827 void
2828 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
2829 struct gl_vertex_buffer_binding *dst,
2830 const struct gl_vertex_buffer_binding *src)
2831 {
2832 dst->Offset = src->Offset;
2833 dst->Stride = src->Stride;
2834 dst->InstanceDivisor = src->InstanceDivisor;
2835 dst->_BoundArrays = src->_BoundArrays;
2836 dst->_EffBoundArrays = src->_EffBoundArrays;
2837 dst->_EffOffset = src->_EffOffset;
2838
2839 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
2840 }
2841
2842 /**
2843 * Print current vertex object/array info. For debug.
2844 */
2845 void
2846 _mesa_print_arrays(struct gl_context *ctx)
2847 {
2848 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
2849
2850 fprintf(stderr, "Array Object %u\n", vao->Name);
2851
2852 gl_vert_attrib i;
2853 for (i = 0; i < VERT_ATTRIB_MAX; ++i) {
2854 const struct gl_array_attributes *array = &vao->VertexAttrib[i];
2855 if (!array->Enabled)
2856 continue;
2857
2858 const struct gl_vertex_buffer_binding *binding =
2859 &vao->BufferBinding[array->BufferBindingIndex];
2860 const struct gl_buffer_object *bo = binding->BufferObj;
2861
2862 fprintf(stderr, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2863 "Stride=%d, Buffer=%u(Size %lu)\n",
2864 gl_vert_attrib_name((gl_vert_attrib)i),
2865 array->Ptr, _mesa_enum_to_string(array->Type), array->Size,
2866 array->_ElementSize, binding->Stride, bo->Name,
2867 (unsigned long) bo->Size);
2868 }
2869 }
2870
2871
2872 /**
2873 * Initialize vertex array state for given context.
2874 */
2875 void
2876 _mesa_init_varray(struct gl_context *ctx)
2877 {
2878 ctx->Array.DefaultVAO = _mesa_new_vao(ctx, 0);
2879 _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO);
2880 ctx->Array._EmptyVAO = _mesa_new_vao(ctx, ~0u);
2881 _mesa_reference_vao(ctx, &ctx->Array._DrawVAO, ctx->Array._EmptyVAO);
2882 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
2883
2884 ctx->Array.Objects = _mesa_NewHashTable();
2885 }
2886
2887
2888 /**
2889 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2890 */
2891 static void
2892 delete_arrayobj_cb(GLuint id, void *data, void *userData)
2893 {
2894 struct gl_vertex_array_object *vao = (struct gl_vertex_array_object *) data;
2895 struct gl_context *ctx = (struct gl_context *) userData;
2896 _mesa_delete_vao(ctx, vao);
2897 }
2898
2899
2900 /**
2901 * Free vertex array state for given context.
2902 */
2903 void
2904 _mesa_free_varray_data(struct gl_context *ctx)
2905 {
2906 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
2907 _mesa_DeleteHashTable(ctx->Array.Objects);
2908 }