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