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