mesa: Delete VAO _MaxElement code and index buffer bounds checking.
[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 <inttypes.h> /* for PRId64 macro */
28
29 #include "glheader.h"
30 #include "imports.h"
31 #include "bufferobj.h"
32 #include "context.h"
33 #include "enable.h"
34 #include "enums.h"
35 #include "hash.h"
36 #include "image.h"
37 #include "macros.h"
38 #include "mtypes.h"
39 #include "varray.h"
40 #include "arrayobj.h"
41 #include "main/dispatch.h"
42
43
44 /** Used to do error checking for GL_EXT_vertex_array_bgra */
45 #define BGRA_OR_4 5
46
47
48 /** Used to indicate which GL datatypes are accepted by each of the
49 * glVertex/Color/Attrib/EtcPointer() functions.
50 */
51 #define BOOL_BIT (1 << 0)
52 #define BYTE_BIT (1 << 1)
53 #define UNSIGNED_BYTE_BIT (1 << 2)
54 #define SHORT_BIT (1 << 3)
55 #define UNSIGNED_SHORT_BIT (1 << 4)
56 #define INT_BIT (1 << 5)
57 #define UNSIGNED_INT_BIT (1 << 6)
58 #define HALF_BIT (1 << 7)
59 #define FLOAT_BIT (1 << 8)
60 #define DOUBLE_BIT (1 << 9)
61 #define FIXED_ES_BIT (1 << 10)
62 #define FIXED_GL_BIT (1 << 11)
63 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
64 #define INT_2_10_10_10_REV_BIT (1 << 13)
65 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
66 #define ALL_TYPE_BITS ((1 << 15) - 1)
67
68
69 /** Convert GL datatype enum into a <type>_BIT value seen above */
70 static GLbitfield
71 type_to_bit(const struct gl_context *ctx, GLenum type)
72 {
73 switch (type) {
74 case GL_BOOL:
75 return BOOL_BIT;
76 case GL_BYTE:
77 return BYTE_BIT;
78 case GL_UNSIGNED_BYTE:
79 return UNSIGNED_BYTE_BIT;
80 case GL_SHORT:
81 return SHORT_BIT;
82 case GL_UNSIGNED_SHORT:
83 return UNSIGNED_SHORT_BIT;
84 case GL_INT:
85 return INT_BIT;
86 case GL_UNSIGNED_INT:
87 return UNSIGNED_INT_BIT;
88 case GL_HALF_FLOAT:
89 if (ctx->Extensions.ARB_half_float_vertex)
90 return HALF_BIT;
91 else
92 return 0x0;
93 case GL_FLOAT:
94 return FLOAT_BIT;
95 case GL_DOUBLE:
96 return DOUBLE_BIT;
97 case GL_FIXED:
98 return _mesa_is_desktop_gl(ctx) ? FIXED_GL_BIT : FIXED_ES_BIT;
99 case GL_UNSIGNED_INT_2_10_10_10_REV:
100 return UNSIGNED_INT_2_10_10_10_REV_BIT;
101 case GL_INT_2_10_10_10_REV:
102 return INT_2_10_10_10_REV_BIT;
103 case GL_UNSIGNED_INT_10F_11F_11F_REV:
104 return UNSIGNED_INT_10F_11F_11F_REV_BIT;
105 default:
106 return 0;
107 }
108 }
109
110
111 /**
112 * Sets the VertexBinding field in the vertex attribute given by attribIndex.
113 */
114 static void
115 vertex_attrib_binding(struct gl_context *ctx, GLuint attribIndex,
116 GLuint bindingIndex)
117 {
118 struct gl_vertex_array_object *vao = ctx->Array.VAO;
119 struct gl_vertex_attrib_array *array = &vao->VertexAttrib[attribIndex];
120
121 if (array->VertexBinding != bindingIndex) {
122 const GLbitfield64 array_bit = VERT_BIT(attribIndex);
123
124 FLUSH_VERTICES(ctx, _NEW_ARRAY);
125
126 vao->VertexBinding[array->VertexBinding]._BoundArrays &= ~array_bit;
127 vao->VertexBinding[bindingIndex]._BoundArrays |= array_bit;
128
129 array->VertexBinding = bindingIndex;
130
131 vao->NewArrays |= array_bit;
132 }
133 }
134
135
136 /**
137 * Binds a buffer object to the vertex buffer binding point given by index,
138 * and sets the Offset and Stride fields.
139 */
140 static void
141 bind_vertex_buffer(struct gl_context *ctx, GLuint index,
142 struct gl_buffer_object *vbo,
143 GLintptr offset, GLsizei stride)
144 {
145 struct gl_vertex_array_object *vao = ctx->Array.VAO;
146 struct gl_vertex_buffer_binding *binding = &vao->VertexBinding[index];
147
148 if (binding->BufferObj != vbo ||
149 binding->Offset != offset ||
150 binding->Stride != stride) {
151
152 FLUSH_VERTICES(ctx, _NEW_ARRAY);
153
154 _mesa_reference_buffer_object(ctx, &binding->BufferObj, vbo);
155
156 binding->Offset = offset;
157 binding->Stride = stride;
158
159 vao->NewArrays |= binding->_BoundArrays;
160 }
161 }
162
163
164 /**
165 * Sets the InstanceDivisor field in the vertex buffer binding point
166 * given by bindingIndex.
167 */
168 static void
169 vertex_binding_divisor(struct gl_context *ctx, GLuint bindingIndex,
170 GLuint divisor)
171 {
172 struct gl_vertex_array_object *vao = ctx->Array.VAO;
173 struct gl_vertex_buffer_binding *binding =
174 &vao->VertexBinding[bindingIndex];
175
176 if (binding->InstanceDivisor != divisor) {
177 FLUSH_VERTICES(ctx, _NEW_ARRAY);
178 binding->InstanceDivisor = divisor;
179 vao->NewArrays |= binding->_BoundArrays;
180 }
181 }
182
183
184 /**
185 * Examine the API profile and extensions to determine which types are legal
186 * for vertex arrays. This is called once from update_array_format().
187 */
188 static GLbitfield
189 get_legal_types_mask(const struct gl_context *ctx)
190 {
191 GLbitfield legalTypesMask = ALL_TYPE_BITS;
192
193 if (_mesa_is_gles(ctx)) {
194 legalTypesMask &= ~(FIXED_GL_BIT |
195 DOUBLE_BIT |
196 UNSIGNED_INT_10F_11F_11F_REV_BIT);
197
198 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
199 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
200 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
201 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
202 * quite as trivial as we'd like because it uses a different enum value
203 * for GL_HALF_FLOAT_OES.
204 */
205 if (ctx->Version < 30) {
206 legalTypesMask &= ~(UNSIGNED_INT_BIT |
207 INT_BIT |
208 UNSIGNED_INT_2_10_10_10_REV_BIT |
209 INT_2_10_10_10_REV_BIT |
210 HALF_BIT);
211 }
212 }
213 else {
214 legalTypesMask &= ~FIXED_ES_BIT;
215
216 if (!ctx->Extensions.ARB_ES2_compatibility)
217 legalTypesMask &= ~FIXED_GL_BIT;
218
219 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
220 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
221 INT_2_10_10_10_REV_BIT);
222
223 if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev)
224 legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT;
225 }
226
227 return legalTypesMask;
228 }
229
230
231 /**
232 * Does error checking and updates the format in an attrib array.
233 *
234 * Called by update_array() and VertexAttrib*Format().
235 *
236 * \param func Name of calling function used for error reporting
237 * \param attrib The index of the attribute array
238 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
239 * \param sizeMin Min allowable size value
240 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
241 * \param size Components per element (1, 2, 3 or 4)
242 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
243 * \param normalized Whether integer types are converted to floats in [-1, 1]
244 * \param integer Integer-valued values (will not be normalized to [-1, 1])
245 * \param relativeOffset Offset of the first element relative to the binding offset.
246 */
247 static bool
248 update_array_format(struct gl_context *ctx,
249 const char *func,
250 GLuint attrib, GLbitfield legalTypesMask,
251 GLint sizeMin, GLint sizeMax,
252 GLint size, GLenum type,
253 GLboolean normalized, GLboolean integer,
254 GLuint relativeOffset)
255 {
256 struct gl_vertex_attrib_array *array;
257 GLbitfield typeBit;
258 GLuint elementSize;
259 GLenum format = GL_RGBA;
260
261 if (ctx->Array.LegalTypesMask == 0) {
262 /* One-time initialization. We can't do this in _mesa_init_varrays()
263 * below because extensions are not yet enabled at that point.
264 */
265 ctx->Array.LegalTypesMask = get_legal_types_mask(ctx);
266 }
267
268 legalTypesMask &= ctx->Array.LegalTypesMask;
269
270 if (_mesa_is_gles(ctx) && sizeMax == BGRA_OR_4) {
271 /* BGRA ordering is not supported in ES contexts.
272 */
273 sizeMax = 4;
274 }
275
276 typeBit = type_to_bit(ctx, type);
277 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
278 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
279 func, _mesa_lookup_enum_by_nr(type));
280 return false;
281 }
282
283 /* Do size parameter checking.
284 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
285 * must be handled specially.
286 */
287 if (ctx->Extensions.EXT_vertex_array_bgra &&
288 sizeMax == BGRA_OR_4 &&
289 size == GL_BGRA) {
290 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
291 *
292 * "An INVALID_OPERATION error is generated under any of the following
293 * conditions:
294 * ...
295 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
296 * or UNSIGNED_INT_2_10_10_10_REV;
297 * ...
298 * • size is BGRA and normalized is FALSE;"
299 */
300 bool bgra_error = false;
301
302 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
303 if (type != GL_UNSIGNED_INT_2_10_10_10_REV &&
304 type != GL_INT_2_10_10_10_REV &&
305 type != GL_UNSIGNED_BYTE)
306 bgra_error = true;
307 } else if (type != GL_UNSIGNED_BYTE)
308 bgra_error = true;
309
310 if (bgra_error) {
311 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)",
312 func, _mesa_lookup_enum_by_nr(type));
313 return false;
314 }
315
316 if (!normalized) {
317 _mesa_error(ctx, GL_INVALID_OPERATION,
318 "%s(size=GL_BGRA and normalized=GL_FALSE)", func);
319 return false;
320 }
321
322 format = GL_BGRA;
323 size = 4;
324 }
325 else if (size < sizeMin || size > sizeMax || size > 4) {
326 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
327 return false;
328 }
329
330 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
331 (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
332 type == GL_INT_2_10_10_10_REV) && size != 4) {
333 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
334 return false;
335 }
336
337 /* The ARB_vertex_attrib_binding_spec says:
338 *
339 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
340 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
341 */
342 if (relativeOffset > ctx->Const.MaxVertexAttribRelativeOffset) {
343 _mesa_error(ctx, GL_INVALID_VALUE,
344 "%s(relativeOffset=%d > "
345 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
346 func, relativeOffset);
347 return false;
348 }
349
350 if (ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev &&
351 type == GL_UNSIGNED_INT_10F_11F_11F_REV && size != 3) {
352 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
353 return false;
354 }
355
356 ASSERT(size <= 4);
357
358 elementSize = _mesa_bytes_per_vertex_attrib(size, type);
359 assert(elementSize != -1);
360
361 array = &ctx->Array.VAO->VertexAttrib[attrib];
362 array->Size = size;
363 array->Type = type;
364 array->Format = format;
365 array->Normalized = normalized;
366 array->Integer = integer;
367 array->RelativeOffset = relativeOffset;
368 array->_ElementSize = elementSize;
369
370 ctx->Array.VAO->NewArrays |= VERT_BIT(attrib);
371 ctx->NewState |= _NEW_ARRAY;
372
373 return true;
374 }
375
376
377 /**
378 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
379 * functions.
380 *
381 * \param func name of calling function used for error reporting
382 * \param attrib the attribute array index to update
383 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
384 * \param sizeMin min allowable size value
385 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
386 * \param size components per element (1, 2, 3 or 4)
387 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
388 * \param stride stride between elements, in elements
389 * \param normalized are integer types converted to floats in [-1, 1]?
390 * \param integer integer-valued values (will not be normalized to [-1,1])
391 * \param ptr the address (or offset inside VBO) of the array data
392 */
393 static void
394 update_array(struct gl_context *ctx,
395 const char *func,
396 GLuint attrib, GLbitfield legalTypesMask,
397 GLint sizeMin, GLint sizeMax,
398 GLint size, GLenum type, GLsizei stride,
399 GLboolean normalized, GLboolean integer,
400 const GLvoid *ptr)
401 {
402 struct gl_vertex_attrib_array *array;
403 GLsizei effectiveStride;
404
405 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
406 *
407 * "Client vertex arrays - all vertex array attribute pointers must
408 * refer to buffer objects (section 2.9.2). The default vertex array
409 * object (the name zero) is also deprecated. Calling
410 * VertexAttribPointer when no buffer object or no vertex array object
411 * is bound will generate an INVALID_OPERATION error..."
412 *
413 * The check for VBOs is handled below.
414 */
415 if (ctx->API == API_OPENGL_CORE
416 && (ctx->Array.VAO == ctx->Array.DefaultVAO)) {
417 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)",
418 func);
419 return;
420 }
421
422 if (stride < 0) {
423 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
424 return;
425 }
426
427 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
428 stride > ctx->Const.MaxVertexAttribStride) {
429 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
430 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
431 return;
432 }
433
434 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
435 *
436 * "An INVALID_OPERATION error is generated under any of the following
437 * conditions:
438 *
439 * ...
440 *
441 * * any of the *Pointer commands specifying the location and
442 * organization of vertex array data are called while zero is bound
443 * to the ARRAY_BUFFER buffer object binding point (see section
444 * 2.9.6), and the pointer argument is not NULL."
445 */
446 if (ptr != NULL && ctx->Array.VAO->ARBsemantics &&
447 !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) {
448 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
449 return;
450 }
451
452 if (!update_array_format(ctx, func, attrib, legalTypesMask, sizeMin,
453 sizeMax, size, type, normalized, integer, 0)) {
454 return;
455 }
456
457 /* Reset the vertex attrib binding */
458 vertex_attrib_binding(ctx, attrib, attrib);
459
460 /* The Stride and Ptr fields are not set by update_array_format() */
461 array = &ctx->Array.VAO->VertexAttrib[attrib];
462 array->Stride = stride;
463 array->Ptr = (const GLvoid *) ptr;
464
465 /* Update the vertex buffer binding */
466 effectiveStride = stride != 0 ? stride : array->_ElementSize;
467 bind_vertex_buffer(ctx, attrib, ctx->Array.ArrayBufferObj,
468 (GLintptr) ptr, effectiveStride);
469 }
470
471
472 void GLAPIENTRY
473 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
474 {
475 GET_CURRENT_CONTEXT(ctx);
476 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
477 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
478 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
479 DOUBLE_BIT | HALF_BIT |
480 UNSIGNED_INT_2_10_10_10_REV_BIT |
481 INT_2_10_10_10_REV_BIT);
482
483 FLUSH_VERTICES(ctx, 0);
484
485 update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS,
486 legalTypes, 2, 4,
487 size, type, stride, GL_FALSE, GL_FALSE, ptr);
488 }
489
490
491 void GLAPIENTRY
492 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
493 {
494 GET_CURRENT_CONTEXT(ctx);
495 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
496 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
497 : (BYTE_BIT | SHORT_BIT | INT_BIT |
498 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
499 UNSIGNED_INT_2_10_10_10_REV_BIT |
500 INT_2_10_10_10_REV_BIT);
501
502 FLUSH_VERTICES(ctx, 0);
503
504 update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL,
505 legalTypes, 3, 3,
506 3, type, stride, GL_TRUE, GL_FALSE, ptr);
507 }
508
509
510 void GLAPIENTRY
511 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
512 {
513 GET_CURRENT_CONTEXT(ctx);
514 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
515 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
516 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
517 SHORT_BIT | UNSIGNED_SHORT_BIT |
518 INT_BIT | UNSIGNED_INT_BIT |
519 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
520 UNSIGNED_INT_2_10_10_10_REV_BIT |
521 INT_2_10_10_10_REV_BIT);
522 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
523
524 FLUSH_VERTICES(ctx, 0);
525
526 update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR0,
527 legalTypes, sizeMin, BGRA_OR_4,
528 size, type, stride, GL_TRUE, GL_FALSE, ptr);
529 }
530
531
532 void GLAPIENTRY
533 _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
534 {
535 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
536 GET_CURRENT_CONTEXT(ctx);
537
538 FLUSH_VERTICES(ctx, 0);
539
540 update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG,
541 legalTypes, 1, 1,
542 1, type, stride, GL_FALSE, GL_FALSE, ptr);
543 }
544
545
546 void GLAPIENTRY
547 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
548 {
549 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
550 FLOAT_BIT | DOUBLE_BIT);
551 GET_CURRENT_CONTEXT(ctx);
552
553 FLUSH_VERTICES(ctx, 0);
554
555 update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX,
556 legalTypes, 1, 1,
557 1, type, stride, GL_FALSE, GL_FALSE, ptr);
558 }
559
560
561 void GLAPIENTRY
562 _mesa_SecondaryColorPointer(GLint size, GLenum type,
563 GLsizei stride, const GLvoid *ptr)
564 {
565 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
566 SHORT_BIT | UNSIGNED_SHORT_BIT |
567 INT_BIT | UNSIGNED_INT_BIT |
568 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
569 UNSIGNED_INT_2_10_10_10_REV_BIT |
570 INT_2_10_10_10_REV_BIT);
571 GET_CURRENT_CONTEXT(ctx);
572
573 FLUSH_VERTICES(ctx, 0);
574
575 update_array(ctx, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1,
576 legalTypes, 3, BGRA_OR_4,
577 size, type, stride, GL_TRUE, GL_FALSE, ptr);
578 }
579
580
581 void GLAPIENTRY
582 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
583 const GLvoid *ptr)
584 {
585 GET_CURRENT_CONTEXT(ctx);
586 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
587 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
588 : (SHORT_BIT | INT_BIT |
589 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
590 UNSIGNED_INT_2_10_10_10_REV_BIT |
591 INT_2_10_10_10_REV_BIT);
592 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
593 const GLuint unit = ctx->Array.ActiveTexture;
594
595 FLUSH_VERTICES(ctx, 0);
596
597 update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX(unit),
598 legalTypes, sizeMin, 4,
599 size, type, stride, GL_FALSE, GL_FALSE,
600 ptr);
601 }
602
603
604 void GLAPIENTRY
605 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
606 {
607 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
608 /* this is the same type that glEdgeFlag uses */
609 const GLboolean integer = GL_FALSE;
610 GET_CURRENT_CONTEXT(ctx);
611
612 FLUSH_VERTICES(ctx, 0);
613
614 update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG,
615 legalTypes, 1, 1,
616 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, ptr);
617 }
618
619
620 void GLAPIENTRY
621 _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr)
622 {
623 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
624 GET_CURRENT_CONTEXT(ctx);
625
626 FLUSH_VERTICES(ctx, 0);
627
628 if (ctx->API != API_OPENGLES) {
629 _mesa_error(ctx, GL_INVALID_OPERATION,
630 "glPointSizePointer(ES 1.x only)");
631 return;
632 }
633
634 update_array(ctx, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE,
635 legalTypes, 1, 1,
636 1, type, stride, GL_FALSE, GL_FALSE, ptr);
637 }
638
639
640 /**
641 * Set a generic vertex attribute array.
642 * Note that these arrays DO NOT alias the conventional GL vertex arrays
643 * (position, normal, color, fog, texcoord, etc).
644 */
645 void GLAPIENTRY
646 _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
647 GLboolean normalized,
648 GLsizei stride, const GLvoid *ptr)
649 {
650 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
651 SHORT_BIT | UNSIGNED_SHORT_BIT |
652 INT_BIT | UNSIGNED_INT_BIT |
653 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
654 FIXED_ES_BIT | FIXED_GL_BIT |
655 UNSIGNED_INT_2_10_10_10_REV_BIT |
656 INT_2_10_10_10_REV_BIT |
657 UNSIGNED_INT_10F_11F_11F_REV_BIT);
658 GET_CURRENT_CONTEXT(ctx);
659
660 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
661 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
662 return;
663 }
664
665 update_array(ctx, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index),
666 legalTypes, 1, BGRA_OR_4,
667 size, type, stride, normalized, GL_FALSE, ptr);
668 }
669
670
671 /**
672 * GL_EXT_gpu_shader4 / GL 3.0.
673 * Set an integer-valued vertex attribute array.
674 * Note that these arrays DO NOT alias the conventional GL vertex arrays
675 * (position, normal, color, fog, texcoord, etc).
676 */
677 void GLAPIENTRY
678 _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
679 GLsizei stride, const GLvoid *ptr)
680 {
681 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
682 SHORT_BIT | UNSIGNED_SHORT_BIT |
683 INT_BIT | UNSIGNED_INT_BIT);
684 const GLboolean normalized = GL_FALSE;
685 const GLboolean integer = GL_TRUE;
686 GET_CURRENT_CONTEXT(ctx);
687
688 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
689 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
690 return;
691 }
692
693 update_array(ctx, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index),
694 legalTypes, 1, 4,
695 size, type, stride, normalized, integer, ptr);
696 }
697
698
699
700 void GLAPIENTRY
701 _mesa_EnableVertexAttribArray(GLuint index)
702 {
703 struct gl_vertex_array_object *vao;
704 GET_CURRENT_CONTEXT(ctx);
705
706 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
707 _mesa_error(ctx, GL_INVALID_VALUE,
708 "glEnableVertexAttribArrayARB(index)");
709 return;
710 }
711
712 vao = ctx->Array.VAO;
713
714 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(vao->_VertexAttrib));
715
716 if (!vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
717 /* was disabled, now being enabled */
718 FLUSH_VERTICES(ctx, _NEW_ARRAY);
719 vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_TRUE;
720 vao->_Enabled |= VERT_BIT_GENERIC(index);
721 vao->NewArrays |= VERT_BIT_GENERIC(index);
722 }
723 }
724
725
726 void GLAPIENTRY
727 _mesa_DisableVertexAttribArray(GLuint index)
728 {
729 struct gl_vertex_array_object *vao;
730 GET_CURRENT_CONTEXT(ctx);
731
732 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
733 _mesa_error(ctx, GL_INVALID_VALUE,
734 "glDisableVertexAttribArrayARB(index)");
735 return;
736 }
737
738 vao = ctx->Array.VAO;
739
740 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(vao->_VertexAttrib));
741
742 if (vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
743 /* was enabled, now being disabled */
744 FLUSH_VERTICES(ctx, _NEW_ARRAY);
745 vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE;
746 vao->_Enabled &= ~VERT_BIT_GENERIC(index);
747 vao->NewArrays |= VERT_BIT_GENERIC(index);
748 }
749 }
750
751
752 /**
753 * Return info for a vertex attribute array (no alias with legacy
754 * vertex attributes (pos, normal, color, etc)). This function does
755 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
756 */
757 static GLuint
758 get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname,
759 const char *caller)
760 {
761 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
762 const struct gl_vertex_attrib_array *array;
763
764 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
765 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
766 return 0;
767 }
768
769 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(vao->VertexAttrib));
770
771 array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
772
773 switch (pname) {
774 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
775 return array->Enabled;
776 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
777 return (array->Format == GL_BGRA) ? GL_BGRA : array->Size;
778 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
779 return array->Stride;
780 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
781 return array->Type;
782 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
783 return array->Normalized;
784 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
785 return vao->VertexBinding[array->VertexBinding].BufferObj->Name;
786 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
787 if ((_mesa_is_desktop_gl(ctx)
788 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
789 || _mesa_is_gles3(ctx)) {
790 return array->Integer;
791 }
792 goto error;
793 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
794 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
795 || _mesa_is_gles3(ctx)) {
796 return vao->VertexBinding[array->VertexBinding].InstanceDivisor;
797 }
798 goto error;
799 case GL_VERTEX_ATTRIB_BINDING:
800 if (_mesa_is_desktop_gl(ctx)) {
801 return array->VertexBinding - VERT_ATTRIB_GENERIC0;
802 }
803 goto error;
804 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
805 if (_mesa_is_desktop_gl(ctx)) {
806 return array->RelativeOffset;
807 }
808 goto error;
809 default:
810 ; /* fall-through */
811 }
812
813 error:
814 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
815 return 0;
816 }
817
818
819 static const GLfloat *
820 get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
821 {
822 if (index == 0) {
823 if (_mesa_attr_zero_aliases_vertex(ctx)) {
824 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
825 return NULL;
826 }
827 }
828 else if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
829 _mesa_error(ctx, GL_INVALID_VALUE,
830 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
831 return NULL;
832 }
833
834 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.VAO->_VertexAttrib));
835
836 FLUSH_CURRENT(ctx, 0);
837 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
838 }
839
840 void GLAPIENTRY
841 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
842 {
843 GET_CURRENT_CONTEXT(ctx);
844
845 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
846 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
847 if (v != NULL) {
848 COPY_4V(params, v);
849 }
850 }
851 else {
852 params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname,
853 "glGetVertexAttribfv");
854 }
855 }
856
857
858 void GLAPIENTRY
859 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
860 {
861 GET_CURRENT_CONTEXT(ctx);
862
863 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
864 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
865 if (v != NULL) {
866 params[0] = (GLdouble) v[0];
867 params[1] = (GLdouble) v[1];
868 params[2] = (GLdouble) v[2];
869 params[3] = (GLdouble) v[3];
870 }
871 }
872 else {
873 params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname,
874 "glGetVertexAttribdv");
875 }
876 }
877
878
879 void GLAPIENTRY
880 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
881 {
882 GET_CURRENT_CONTEXT(ctx);
883
884 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
885 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
886 if (v != NULL) {
887 /* XXX should floats in[0,1] be scaled to full int range? */
888 params[0] = (GLint) v[0];
889 params[1] = (GLint) v[1];
890 params[2] = (GLint) v[2];
891 params[3] = (GLint) v[3];
892 }
893 }
894 else {
895 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
896 "glGetVertexAttribiv");
897 }
898 }
899
900
901 /** GL 3.0 */
902 void GLAPIENTRY
903 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
904 {
905 GET_CURRENT_CONTEXT(ctx);
906
907 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
908 const GLint *v = (const GLint *)
909 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
910 if (v != NULL) {
911 COPY_4V(params, v);
912 }
913 }
914 else {
915 params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname,
916 "glGetVertexAttribIiv");
917 }
918 }
919
920
921 /** GL 3.0 */
922 void GLAPIENTRY
923 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
924 {
925 GET_CURRENT_CONTEXT(ctx);
926
927 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
928 const GLuint *v = (const GLuint *)
929 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
930 if (v != NULL) {
931 COPY_4V(params, v);
932 }
933 }
934 else {
935 params[0] = get_vertex_array_attrib(ctx, index, pname,
936 "glGetVertexAttribIuiv");
937 }
938 }
939
940
941 void GLAPIENTRY
942 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
943 {
944 GET_CURRENT_CONTEXT(ctx);
945
946 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
947 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
948 return;
949 }
950
951 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
952 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
953 return;
954 }
955
956 ASSERT(VERT_ATTRIB_GENERIC(index) < Elements(ctx->Array.VAO->_VertexAttrib));
957
958 *pointer = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
959 }
960
961
962 void GLAPIENTRY
963 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
964 GLsizei count, const GLvoid *ptr)
965 {
966 (void) count;
967 _mesa_VertexPointer(size, type, stride, ptr);
968 }
969
970
971 void GLAPIENTRY
972 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
973 const GLvoid *ptr)
974 {
975 (void) count;
976 _mesa_NormalPointer(type, stride, ptr);
977 }
978
979
980 void GLAPIENTRY
981 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
982 const GLvoid *ptr)
983 {
984 (void) count;
985 _mesa_ColorPointer(size, type, stride, ptr);
986 }
987
988
989 void GLAPIENTRY
990 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
991 const GLvoid *ptr)
992 {
993 (void) count;
994 _mesa_IndexPointer(type, stride, ptr);
995 }
996
997
998 void GLAPIENTRY
999 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
1000 GLsizei count, const GLvoid *ptr)
1001 {
1002 (void) count;
1003 _mesa_TexCoordPointer(size, type, stride, ptr);
1004 }
1005
1006
1007 void GLAPIENTRY
1008 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
1009 {
1010 (void) count;
1011 _mesa_EdgeFlagPointer(stride, ptr);
1012 }
1013
1014
1015 void GLAPIENTRY
1016 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
1017 {
1018 GET_CURRENT_CONTEXT(ctx);
1019 GLboolean tflag, cflag, nflag; /* enable/disable flags */
1020 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
1021 GLenum ctype = 0; /* color type */
1022 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
1023 const GLint toffset = 0; /* always zero */
1024 GLint defstride; /* default stride */
1025 GLint c, f;
1026
1027 FLUSH_VERTICES(ctx, 0);
1028
1029 f = sizeof(GLfloat);
1030 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
1031
1032 if (stride < 0) {
1033 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
1034 return;
1035 }
1036
1037 switch (format) {
1038 case GL_V2F:
1039 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1040 tcomps = 0; ccomps = 0; vcomps = 2;
1041 voffset = 0;
1042 defstride = 2*f;
1043 break;
1044 case GL_V3F:
1045 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1046 tcomps = 0; ccomps = 0; vcomps = 3;
1047 voffset = 0;
1048 defstride = 3*f;
1049 break;
1050 case GL_C4UB_V2F:
1051 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1052 tcomps = 0; ccomps = 4; vcomps = 2;
1053 ctype = GL_UNSIGNED_BYTE;
1054 coffset = 0;
1055 voffset = c;
1056 defstride = c + 2*f;
1057 break;
1058 case GL_C4UB_V3F:
1059 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1060 tcomps = 0; ccomps = 4; vcomps = 3;
1061 ctype = GL_UNSIGNED_BYTE;
1062 coffset = 0;
1063 voffset = c;
1064 defstride = c + 3*f;
1065 break;
1066 case GL_C3F_V3F:
1067 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1068 tcomps = 0; ccomps = 3; vcomps = 3;
1069 ctype = GL_FLOAT;
1070 coffset = 0;
1071 voffset = 3*f;
1072 defstride = 6*f;
1073 break;
1074 case GL_N3F_V3F:
1075 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1076 tcomps = 0; ccomps = 0; vcomps = 3;
1077 noffset = 0;
1078 voffset = 3*f;
1079 defstride = 6*f;
1080 break;
1081 case GL_C4F_N3F_V3F:
1082 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1083 tcomps = 0; ccomps = 4; vcomps = 3;
1084 ctype = GL_FLOAT;
1085 coffset = 0;
1086 noffset = 4*f;
1087 voffset = 7*f;
1088 defstride = 10*f;
1089 break;
1090 case GL_T2F_V3F:
1091 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1092 tcomps = 2; ccomps = 0; vcomps = 3;
1093 voffset = 2*f;
1094 defstride = 5*f;
1095 break;
1096 case GL_T4F_V4F:
1097 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1098 tcomps = 4; ccomps = 0; vcomps = 4;
1099 voffset = 4*f;
1100 defstride = 8*f;
1101 break;
1102 case GL_T2F_C4UB_V3F:
1103 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1104 tcomps = 2; ccomps = 4; vcomps = 3;
1105 ctype = GL_UNSIGNED_BYTE;
1106 coffset = 2*f;
1107 voffset = c+2*f;
1108 defstride = c+5*f;
1109 break;
1110 case GL_T2F_C3F_V3F:
1111 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1112 tcomps = 2; ccomps = 3; vcomps = 3;
1113 ctype = GL_FLOAT;
1114 coffset = 2*f;
1115 voffset = 5*f;
1116 defstride = 8*f;
1117 break;
1118 case GL_T2F_N3F_V3F:
1119 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1120 tcomps = 2; ccomps = 0; vcomps = 3;
1121 noffset = 2*f;
1122 voffset = 5*f;
1123 defstride = 8*f;
1124 break;
1125 case GL_T2F_C4F_N3F_V3F:
1126 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1127 tcomps = 2; ccomps = 4; vcomps = 3;
1128 ctype = GL_FLOAT;
1129 coffset = 2*f;
1130 noffset = 6*f;
1131 voffset = 9*f;
1132 defstride = 12*f;
1133 break;
1134 case GL_T4F_C4F_N3F_V4F:
1135 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1136 tcomps = 4; ccomps = 4; vcomps = 4;
1137 ctype = GL_FLOAT;
1138 coffset = 4*f;
1139 noffset = 8*f;
1140 voffset = 11*f;
1141 defstride = 15*f;
1142 break;
1143 default:
1144 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
1145 return;
1146 }
1147
1148 if (stride==0) {
1149 stride = defstride;
1150 }
1151
1152 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1153 _mesa_DisableClientState( GL_INDEX_ARRAY );
1154 /* XXX also disable secondary color and generic arrays? */
1155
1156 /* Texcoords */
1157 if (tflag) {
1158 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1159 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
1160 (GLubyte *) pointer + toffset );
1161 }
1162 else {
1163 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
1164 }
1165
1166 /* Color */
1167 if (cflag) {
1168 _mesa_EnableClientState( GL_COLOR_ARRAY );
1169 _mesa_ColorPointer( ccomps, ctype, stride,
1170 (GLubyte *) pointer + coffset );
1171 }
1172 else {
1173 _mesa_DisableClientState( GL_COLOR_ARRAY );
1174 }
1175
1176
1177 /* Normals */
1178 if (nflag) {
1179 _mesa_EnableClientState( GL_NORMAL_ARRAY );
1180 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
1181 }
1182 else {
1183 _mesa_DisableClientState( GL_NORMAL_ARRAY );
1184 }
1185
1186 /* Vertices */
1187 _mesa_EnableClientState( GL_VERTEX_ARRAY );
1188 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
1189 (GLubyte *) pointer + voffset );
1190 }
1191
1192
1193 void GLAPIENTRY
1194 _mesa_LockArraysEXT(GLint first, GLsizei count)
1195 {
1196 GET_CURRENT_CONTEXT(ctx);
1197
1198 FLUSH_VERTICES(ctx, 0);
1199
1200 if (MESA_VERBOSE & VERBOSE_API)
1201 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
1202
1203 if (first < 0) {
1204 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1205 return;
1206 }
1207 if (count <= 0) {
1208 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1209 return;
1210 }
1211 if (ctx->Array.LockCount != 0) {
1212 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1213 return;
1214 }
1215
1216 ctx->Array.LockFirst = first;
1217 ctx->Array.LockCount = count;
1218
1219 ctx->NewState |= _NEW_ARRAY;
1220 }
1221
1222
1223 void GLAPIENTRY
1224 _mesa_UnlockArraysEXT( void )
1225 {
1226 GET_CURRENT_CONTEXT(ctx);
1227
1228 FLUSH_VERTICES(ctx, 0);
1229
1230 if (MESA_VERBOSE & VERBOSE_API)
1231 _mesa_debug(ctx, "glUnlockArrays\n");
1232
1233 if (ctx->Array.LockCount == 0) {
1234 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1235 return;
1236 }
1237
1238 ctx->Array.LockFirst = 0;
1239 ctx->Array.LockCount = 0;
1240 ctx->NewState |= _NEW_ARRAY;
1241 }
1242
1243
1244 /* GL_EXT_multi_draw_arrays */
1245 void GLAPIENTRY
1246 _mesa_MultiDrawArrays( GLenum mode, const GLint *first,
1247 const GLsizei *count, GLsizei primcount )
1248 {
1249 GET_CURRENT_CONTEXT(ctx);
1250 GLint i;
1251
1252 FLUSH_VERTICES(ctx, 0);
1253
1254 for (i = 0; i < primcount; i++) {
1255 if (count[i] > 0) {
1256 CALL_DrawArrays(ctx->CurrentDispatch, (mode, first[i], count[i]));
1257 }
1258 }
1259 }
1260
1261
1262 /* GL_IBM_multimode_draw_arrays */
1263 void GLAPIENTRY
1264 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1265 const GLsizei * count,
1266 GLsizei primcount, GLint modestride )
1267 {
1268 GET_CURRENT_CONTEXT(ctx);
1269 GLint i;
1270
1271 FLUSH_VERTICES(ctx, 0);
1272
1273 for ( i = 0 ; i < primcount ; i++ ) {
1274 if ( count[i] > 0 ) {
1275 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1276 CALL_DrawArrays(ctx->CurrentDispatch, ( m, first[i], count[i] ));
1277 }
1278 }
1279 }
1280
1281
1282 /* GL_IBM_multimode_draw_arrays */
1283 void GLAPIENTRY
1284 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1285 GLenum type, const GLvoid * const * indices,
1286 GLsizei primcount, GLint modestride )
1287 {
1288 GET_CURRENT_CONTEXT(ctx);
1289 GLint i;
1290
1291 FLUSH_VERTICES(ctx, 0);
1292
1293 /* XXX not sure about ARB_vertex_buffer_object handling here */
1294
1295 for ( i = 0 ; i < primcount ; i++ ) {
1296 if ( count[i] > 0 ) {
1297 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1298 CALL_DrawElements(ctx->CurrentDispatch, ( m, count[i], type,
1299 indices[i] ));
1300 }
1301 }
1302 }
1303
1304
1305 /**
1306 * GL_NV_primitive_restart and GL 3.1
1307 */
1308 void GLAPIENTRY
1309 _mesa_PrimitiveRestartIndex(GLuint index)
1310 {
1311 GET_CURRENT_CONTEXT(ctx);
1312
1313 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
1314 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
1315 return;
1316 }
1317
1318 if (ctx->Array.RestartIndex != index) {
1319 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
1320 ctx->Array.RestartIndex = index;
1321 }
1322 }
1323
1324
1325 /**
1326 * See GL_ARB_instanced_arrays.
1327 * Note that the instance divisor only applies to generic arrays, not
1328 * the legacy vertex arrays.
1329 */
1330 void GLAPIENTRY
1331 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
1332 {
1333 GET_CURRENT_CONTEXT(ctx);
1334
1335 const GLuint genericIndex = VERT_ATTRIB_GENERIC(index);
1336
1337 if (!ctx->Extensions.ARB_instanced_arrays) {
1338 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
1339 return;
1340 }
1341
1342 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1343 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribDivisor(index = %u)",
1344 index);
1345 return;
1346 }
1347
1348 ASSERT(genericIndex < Elements(ctx->Array.VAO->VertexAttrib));
1349
1350 /* The ARB_vertex_attrib_binding spec says:
1351 *
1352 * "The command
1353 *
1354 * void VertexAttribDivisor(uint index, uint divisor);
1355 *
1356 * is equivalent to (assuming no errors are generated):
1357 *
1358 * VertexAttribBinding(index, index);
1359 * VertexBindingDivisor(index, divisor);"
1360 */
1361 vertex_attrib_binding(ctx, genericIndex, genericIndex);
1362 vertex_binding_divisor(ctx, genericIndex, divisor);
1363 }
1364
1365
1366 unsigned
1367 _mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type)
1368 {
1369 /* From the OpenGL 4.3 core specification, page 302:
1370 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1371 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1372 * is used."
1373 */
1374 if (ctx->Array.PrimitiveRestartFixedIndex) {
1375 switch (ib_type) {
1376 case GL_UNSIGNED_BYTE:
1377 return 0xff;
1378 case GL_UNSIGNED_SHORT:
1379 return 0xffff;
1380 case GL_UNSIGNED_INT:
1381 return 0xffffffff;
1382 default:
1383 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1384 }
1385 }
1386
1387 return ctx->Array.RestartIndex;
1388 }
1389
1390
1391 /**
1392 * GL_ARB_vertex_attrib_binding
1393 */
1394 void GLAPIENTRY
1395 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
1396 GLsizei stride)
1397 {
1398 GET_CURRENT_CONTEXT(ctx);
1399 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
1400 struct gl_buffer_object *vbo;
1401
1402 ASSERT_OUTSIDE_BEGIN_END(ctx);
1403
1404 /* The ARB_vertex_attrib_binding spec says:
1405 *
1406 * "An INVALID_OPERATION error is generated if no vertex array object
1407 * is bound."
1408 */
1409 if (ctx->API == API_OPENGL_CORE &&
1410 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1411 _mesa_error(ctx, GL_INVALID_OPERATION,
1412 "glBindVertexBuffer(No array object bound)");
1413 return;
1414 }
1415
1416 /* The ARB_vertex_attrib_binding spec says:
1417 *
1418 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1419 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1420 */
1421 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1422 _mesa_error(ctx, GL_INVALID_VALUE,
1423 "glBindVertexBuffer(bindingindex=%u > "
1424 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1425 bindingIndex);
1426 return;
1427 }
1428
1429 /* The ARB_vertex_attrib_binding spec says:
1430 *
1431 * "The error INVALID_VALUE is generated if <stride> or <offset>
1432 * are negative."
1433 */
1434 if (offset < 0) {
1435 _mesa_error(ctx, GL_INVALID_VALUE,
1436 "glBindVertexBuffer(offset=%" PRId64 " < 0)",
1437 (int64_t) offset);
1438 return;
1439 }
1440
1441 if (stride < 0) {
1442 _mesa_error(ctx, GL_INVALID_VALUE,
1443 "glBindVertexBuffer(stride=%d < 0)", stride);
1444 return;
1445 }
1446
1447 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
1448 stride > ctx->Const.MaxVertexAttribStride) {
1449 _mesa_error(ctx, GL_INVALID_VALUE, "glBindVertexBuffer(stride=%d > "
1450 "GL_MAX_VERTEX_ATTRIB_STRIDE)", stride);
1451 return;
1452 }
1453
1454 if (buffer == vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) {
1455 vbo = vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
1456 } else if (buffer != 0) {
1457 vbo = _mesa_lookup_bufferobj(ctx, buffer);
1458
1459 /* From the GL_ARB_vertex_attrib_array spec:
1460 *
1461 * "[Core profile only:]
1462 * An INVALID_OPERATION error is generated if buffer is not zero or a
1463 * name returned from a previous call to GenBuffers, or if such a name
1464 * has since been deleted with DeleteBuffers.
1465 *
1466 * Otherwise, we fall back to the same compat profile behavior as other
1467 * object references (automatically gen it).
1468 */
1469 if (!_mesa_handle_bind_buffer_gen(ctx, GL_ARRAY_BUFFER, buffer,
1470 &vbo, "glBindVertexBuffer"))
1471 return;
1472 } else {
1473 /* The ARB_vertex_attrib_binding spec says:
1474 *
1475 * "If <buffer> is zero, any buffer object attached to this
1476 * bindpoint is detached."
1477 */
1478 vbo = ctx->Shared->NullBufferObj;
1479 }
1480
1481 bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(bindingIndex),
1482 vbo, offset, stride);
1483 }
1484
1485
1486 void GLAPIENTRY
1487 _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
1488 const GLintptr *offsets, const GLsizei *strides)
1489 {
1490 GET_CURRENT_CONTEXT(ctx);
1491 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
1492 GLuint i;
1493
1494 ASSERT_OUTSIDE_BEGIN_END(ctx);
1495
1496 /* The ARB_vertex_attrib_binding spec says:
1497 *
1498 * "An INVALID_OPERATION error is generated if no
1499 * vertex array object is bound."
1500 */
1501 if (ctx->API == API_OPENGL_CORE &&
1502 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1503 _mesa_error(ctx, GL_INVALID_OPERATION,
1504 "glBindVertexBuffers(No array object bound)");
1505 return;
1506 }
1507
1508 /* The ARB_multi_bind spec says:
1509 *
1510 * "An INVALID_OPERATION error is generated if <first> + <count>
1511 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1512 */
1513 if (first + count > ctx->Const.MaxVertexAttribBindings) {
1514 _mesa_error(ctx, GL_INVALID_OPERATION,
1515 "glBindVertexBuffers(first=%u + count=%d > the value of "
1516 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1517 first, count, ctx->Const.MaxVertexAttribBindings);
1518 return;
1519 }
1520
1521 if (!buffers) {
1522 /**
1523 * The ARB_multi_bind spec says:
1524 *
1525 * "If <buffers> is NULL, each affected vertex buffer binding point
1526 * from <first> through <first>+<count>-1 will be reset to have no
1527 * bound buffer object. In this case, the offsets and strides
1528 * associated with the binding points are set to default values,
1529 * ignoring <offsets> and <strides>."
1530 */
1531 struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj;
1532
1533 for (i = 0; i < count; i++)
1534 bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(first + i), vbo, 0, 16);
1535
1536 return;
1537 }
1538
1539 /* Note that the error semantics for multi-bind commands differ from
1540 * those of other GL commands.
1541 *
1542 * The Issues section in the ARB_multi_bind spec says:
1543 *
1544 * "(11) Typically, OpenGL specifies that if an error is generated by
1545 * a command, that command has no effect. This is somewhat
1546 * unfortunate for multi-bind commands, because it would require
1547 * a first pass to scan the entire list of bound objects for
1548 * errors and then a second pass to actually perform the
1549 * bindings. Should we have different error semantics?
1550 *
1551 * RESOLVED: Yes. In this specification, when the parameters for
1552 * one of the <count> binding points are invalid, that binding
1553 * point is not updated and an error will be generated. However,
1554 * other binding points in the same command will be updated if
1555 * their parameters are valid and no other error occurs."
1556 */
1557
1558 _mesa_begin_bufferobj_lookups(ctx);
1559
1560 for (i = 0; i < count; i++) {
1561 struct gl_buffer_object *vbo;
1562
1563 /* The ARB_multi_bind spec says:
1564 *
1565 * "An INVALID_VALUE error is generated if any value in
1566 * <offsets> or <strides> is negative (per binding)."
1567 */
1568 if (offsets[i] < 0) {
1569 _mesa_error(ctx, GL_INVALID_VALUE,
1570 "glBindVertexBuffers(offsets[%u]=%" PRId64 " < 0)",
1571 i, (int64_t) offsets[i]);
1572 continue;
1573 }
1574
1575 if (strides[i] < 0) {
1576 _mesa_error(ctx, GL_INVALID_VALUE,
1577 "glBindVertexBuffers(strides[%u]=%d < 0)",
1578 i, strides[i]);
1579 continue;
1580 }
1581
1582 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
1583 strides[i] > ctx->Const.MaxVertexAttribStride) {
1584 _mesa_error(ctx, GL_INVALID_VALUE,
1585 "glBindVertexBuffers(strides[%u]=%d > "
1586 "GL_MAX_VERTEX_ATTRIB_STRIDE)", i, strides[i]);
1587 continue;
1588 }
1589
1590 if (buffers[i]) {
1591 struct gl_vertex_buffer_binding *binding =
1592 &vao->VertexBinding[VERT_ATTRIB_GENERIC(first + i)];
1593
1594 if (buffers[i] == binding->BufferObj->Name)
1595 vbo = binding->BufferObj;
1596 else
1597 vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i,
1598 "glBindVertexBuffers");
1599
1600 if (!vbo)
1601 continue;
1602 } else {
1603 vbo = ctx->Shared->NullBufferObj;
1604 }
1605
1606 bind_vertex_buffer(ctx, VERT_ATTRIB_GENERIC(first + i), vbo,
1607 offsets[i], strides[i]);
1608 }
1609
1610 _mesa_end_bufferobj_lookups(ctx);
1611 }
1612
1613
1614 void GLAPIENTRY
1615 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
1616 GLboolean normalized, GLuint relativeOffset)
1617 {
1618 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1619 SHORT_BIT | UNSIGNED_SHORT_BIT |
1620 INT_BIT | UNSIGNED_INT_BIT |
1621 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1622 FIXED_GL_BIT |
1623 UNSIGNED_INT_2_10_10_10_REV_BIT |
1624 INT_2_10_10_10_REV_BIT |
1625 UNSIGNED_INT_10F_11F_11F_REV_BIT);
1626
1627 GET_CURRENT_CONTEXT(ctx);
1628 ASSERT_OUTSIDE_BEGIN_END(ctx);
1629
1630 /* The ARB_vertex_attrib_binding spec says:
1631 *
1632 * "An INVALID_OPERATION error is generated under any of the following
1633 * conditions:
1634 * - if no vertex array object is currently bound (see section 2.10);
1635 * - ..."
1636 */
1637 if (ctx->API == API_OPENGL_CORE &&
1638 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1639 _mesa_error(ctx, GL_INVALID_OPERATION,
1640 "glVertexAttribFormat(No array object bound)");
1641 return;
1642 }
1643
1644 /* The ARB_vertex_attrib_binding spec says:
1645 *
1646 * "The error INVALID_VALUE is generated if index is greater than or equal
1647 * to the value of MAX_VERTEX_ATTRIBS."
1648 */
1649 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1650 _mesa_error(ctx, GL_INVALID_VALUE,
1651 "glVertexAttribFormat(attribindex=%u > "
1652 "GL_MAX_VERTEX_ATTRIBS)",
1653 attribIndex);
1654 return;
1655 }
1656
1657 FLUSH_VERTICES(ctx, 0);
1658
1659 update_array_format(ctx, "glVertexAttribFormat",
1660 VERT_ATTRIB_GENERIC(attribIndex),
1661 legalTypes, 1, BGRA_OR_4, size, type, normalized,
1662 GL_FALSE, relativeOffset);
1663 }
1664
1665
1666 void GLAPIENTRY
1667 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
1668 GLuint relativeOffset)
1669 {
1670 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1671 SHORT_BIT | UNSIGNED_SHORT_BIT |
1672 INT_BIT | UNSIGNED_INT_BIT);
1673
1674 GET_CURRENT_CONTEXT(ctx);
1675 ASSERT_OUTSIDE_BEGIN_END(ctx);
1676
1677 /* The ARB_vertex_attrib_binding spec says:
1678 *
1679 * "An INVALID_OPERATION error is generated under any of the following
1680 * conditions:
1681 * - if no vertex array object is currently bound (see section 2.10);
1682 * - ..."
1683 */
1684 if (ctx->API == API_OPENGL_CORE &&
1685 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1686 _mesa_error(ctx, GL_INVALID_OPERATION,
1687 "glVertexAttribIFormat(No array object bound)");
1688 return;
1689 }
1690
1691 /* The ARB_vertex_attrib_binding spec says:
1692 *
1693 * "The error INVALID_VALUE is generated if index is greater than
1694 * or equal to the value of MAX_VERTEX_ATTRIBS."
1695 */
1696 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1697 _mesa_error(ctx, GL_INVALID_VALUE,
1698 "glVertexAttribIFormat(attribindex=%u > "
1699 "GL_MAX_VERTEX_ATTRIBS)",
1700 attribIndex);
1701 return;
1702 }
1703
1704 FLUSH_VERTICES(ctx, 0);
1705
1706 update_array_format(ctx, "glVertexAttribIFormat",
1707 VERT_ATTRIB_GENERIC(attribIndex),
1708 legalTypes, 1, 4, size, type, GL_FALSE, GL_TRUE,
1709 relativeOffset);
1710 }
1711
1712
1713 void GLAPIENTRY
1714 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
1715 GLuint relativeOffset)
1716 {
1717 const GLbitfield legalTypes = DOUBLE_BIT;
1718
1719 GET_CURRENT_CONTEXT(ctx);
1720 ASSERT_OUTSIDE_BEGIN_END(ctx);
1721
1722 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
1723 *
1724 * "An INVALID_OPERATION error is generated under any of the following
1725 * conditions:
1726 * • if no vertex array object is currently bound (see section 10.4);
1727 * • ..."
1728 *
1729 * This language is missing from the extension spec, but we assume
1730 * that this is an oversight.
1731 */
1732 if (ctx->API == API_OPENGL_CORE &&
1733 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1734 _mesa_error(ctx, GL_INVALID_OPERATION,
1735 "glVertexAttribLFormat(No array object bound)");
1736 return;
1737 }
1738
1739 /* The ARB_vertex_attrib_binding spec says:
1740 *
1741 * "The error INVALID_VALUE is generated if <attribindex> is greater than
1742 * or equal to the value of MAX_VERTEX_ATTRIBS."
1743 */
1744 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1745 _mesa_error(ctx, GL_INVALID_VALUE,
1746 "glVertexAttribLFormat(attribindex=%u > "
1747 "GL_MAX_VERTEX_ATTRIBS)",
1748 attribIndex);
1749 return;
1750 }
1751
1752 FLUSH_VERTICES(ctx, 0);
1753
1754 update_array_format(ctx, "glVertexAttribLFormat",
1755 VERT_ATTRIB_GENERIC(attribIndex),
1756 legalTypes, 1, 4, size, type, GL_FALSE, GL_FALSE,
1757 relativeOffset);
1758 }
1759
1760
1761 void GLAPIENTRY
1762 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
1763 {
1764 GET_CURRENT_CONTEXT(ctx);
1765 ASSERT_OUTSIDE_BEGIN_END(ctx);
1766
1767 /* The ARB_vertex_attrib_binding spec says:
1768 *
1769 * "An INVALID_OPERATION error is generated if no vertex array object
1770 * is bound."
1771 */
1772 if (ctx->API == API_OPENGL_CORE &&
1773 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1774 _mesa_error(ctx, GL_INVALID_OPERATION,
1775 "glVertexAttribBinding(No array object bound)");
1776 return;
1777 }
1778
1779 /* The ARB_vertex_attrib_binding spec says:
1780 *
1781 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
1782 * <bindingindex> must be less than the value of
1783 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
1784 * is generated."
1785 */
1786 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1787 _mesa_error(ctx, GL_INVALID_VALUE,
1788 "glVertexAttribBinding(attribindex=%u >= "
1789 "GL_MAX_VERTEX_ATTRIBS)",
1790 attribIndex);
1791 return;
1792 }
1793
1794 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1795 _mesa_error(ctx, GL_INVALID_VALUE,
1796 "glVertexAttribBinding(bindingindex=%u >= "
1797 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1798 bindingIndex);
1799 return;
1800 }
1801
1802 ASSERT(VERT_ATTRIB_GENERIC(attribIndex) <
1803 Elements(ctx->Array.VAO->VertexAttrib));
1804
1805 vertex_attrib_binding(ctx, VERT_ATTRIB_GENERIC(attribIndex),
1806 VERT_ATTRIB_GENERIC(bindingIndex));
1807 }
1808
1809
1810 void GLAPIENTRY
1811 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
1812 {
1813 GET_CURRENT_CONTEXT(ctx);
1814 ASSERT_OUTSIDE_BEGIN_END(ctx);
1815
1816 if (!ctx->Extensions.ARB_instanced_arrays) {
1817 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexBindingDivisor()");
1818 return;
1819 }
1820
1821 /* The ARB_vertex_attrib_binding spec says:
1822 *
1823 * "An INVALID_OPERATION error is generated if no vertex array object
1824 * is bound."
1825 */
1826 if (ctx->API == API_OPENGL_CORE &&
1827 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1828 _mesa_error(ctx, GL_INVALID_OPERATION,
1829 "glVertexBindingDivisor(No array object bound)");
1830 return;
1831 }
1832
1833 /* The ARB_vertex_attrib_binding spec says:
1834 *
1835 * "An INVALID_VALUE error is generated if <bindingindex> is greater
1836 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
1837 */
1838 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1839 _mesa_error(ctx, GL_INVALID_VALUE,
1840 "glVertexBindingDivisor(bindingindex=%u > "
1841 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1842 bindingIndex);
1843 return;
1844 }
1845
1846 vertex_binding_divisor(ctx, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
1847 }
1848
1849
1850 /**
1851 * Copy one client vertex array to another.
1852 */
1853 void
1854 _mesa_copy_client_array(struct gl_context *ctx,
1855 struct gl_client_array *dst,
1856 struct gl_client_array *src)
1857 {
1858 dst->Size = src->Size;
1859 dst->Type = src->Type;
1860 dst->Format = src->Format;
1861 dst->Stride = src->Stride;
1862 dst->StrideB = src->StrideB;
1863 dst->Ptr = src->Ptr;
1864 dst->Enabled = src->Enabled;
1865 dst->Normalized = src->Normalized;
1866 dst->Integer = src->Integer;
1867 dst->InstanceDivisor = src->InstanceDivisor;
1868 dst->_ElementSize = src->_ElementSize;
1869 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
1870 }
1871
1872 void
1873 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
1874 struct gl_vertex_attrib_array *dst,
1875 const struct gl_vertex_attrib_array *src)
1876 {
1877 dst->Size = src->Size;
1878 dst->Type = src->Type;
1879 dst->Format = src->Format;
1880 dst->VertexBinding = src->VertexBinding;
1881 dst->RelativeOffset = src->RelativeOffset;
1882 dst->Format = src->Format;
1883 dst->Integer = src->Integer;
1884 dst->Normalized = src->Normalized;
1885 dst->Ptr = src->Ptr;
1886 dst->Enabled = src->Enabled;
1887 dst->_ElementSize = src->_ElementSize;
1888 }
1889
1890 void
1891 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
1892 struct gl_vertex_buffer_binding *dst,
1893 const struct gl_vertex_buffer_binding *src)
1894 {
1895 dst->Offset = src->Offset;
1896 dst->Stride = src->Stride;
1897 dst->InstanceDivisor = src->InstanceDivisor;
1898 dst->_BoundArrays = src->_BoundArrays;
1899
1900 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
1901 }
1902
1903 /**
1904 * Print vertex array's fields.
1905 */
1906 static void
1907 print_array(const char *name, GLint index, const struct gl_client_array *array)
1908 {
1909 if (index >= 0)
1910 printf(" %s[%d]: ", name, index);
1911 else
1912 printf(" %s: ", name);
1913 printf("Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n",
1914 array->Ptr, array->Type, array->Size,
1915 array->_ElementSize, array->StrideB,
1916 array->BufferObj->Name, (unsigned long) array->BufferObj->Size);
1917 }
1918
1919
1920 /**
1921 * Print current vertex object/array info. For debug.
1922 */
1923 void
1924 _mesa_print_arrays(struct gl_context *ctx)
1925 {
1926 struct gl_vertex_array_object *vao = ctx->Array.VAO;
1927 GLuint i;
1928
1929 printf("Array Object %u\n", vao->Name);
1930 if (vao->_VertexAttrib[VERT_ATTRIB_POS].Enabled)
1931 print_array("Vertex", -1, &vao->_VertexAttrib[VERT_ATTRIB_POS]);
1932 if (vao->_VertexAttrib[VERT_ATTRIB_NORMAL].Enabled)
1933 print_array("Normal", -1, &vao->_VertexAttrib[VERT_ATTRIB_NORMAL]);
1934 if (vao->_VertexAttrib[VERT_ATTRIB_COLOR0].Enabled)
1935 print_array("Color", -1, &vao->_VertexAttrib[VERT_ATTRIB_COLOR0]);
1936 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++)
1937 if (vao->_VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled)
1938 print_array("TexCoord", i, &vao->_VertexAttrib[VERT_ATTRIB_TEX(i)]);
1939 for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++)
1940 if (vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled)
1941 print_array("Attrib", i, &vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)]);
1942 }
1943
1944
1945 /**
1946 * Initialize vertex array state for given context.
1947 */
1948 void
1949 _mesa_init_varray(struct gl_context *ctx)
1950 {
1951 ctx->Array.DefaultVAO = ctx->Driver.NewArrayObject(ctx, 0);
1952 _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO);
1953 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
1954
1955 ctx->Array.Objects = _mesa_NewHashTable();
1956 }
1957
1958
1959 /**
1960 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
1961 */
1962 static void
1963 delete_arrayobj_cb(GLuint id, void *data, void *userData)
1964 {
1965 struct gl_vertex_array_object *vao = (struct gl_vertex_array_object *) data;
1966 struct gl_context *ctx = (struct gl_context *) userData;
1967 _mesa_delete_vao(ctx, vao);
1968 }
1969
1970
1971 /**
1972 * Free vertex array state for given context.
1973 */
1974 void
1975 _mesa_free_varray_data(struct gl_context *ctx)
1976 {
1977 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
1978 _mesa_DeleteHashTable(ctx->Array.Objects);
1979 }