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