st/mesa: call glthread_destroy() before _vbo_DestroyContext()
[mesa.git] / src / mesa / main / varray.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 #include <stdio.h>
28 #include <inttypes.h> /* for PRId64 macro */
29
30 #include "glheader.h"
31 #include "imports.h"
32 #include "bufferobj.h"
33 #include "context.h"
34 #include "enable.h"
35 #include "enums.h"
36 #include "hash.h"
37 #include "image.h"
38 #include "macros.h"
39 #include "mtypes.h"
40 #include "varray.h"
41 #include "arrayobj.h"
42 #include "main/dispatch.h"
43
44
45 /** Used to do error checking for GL_EXT_vertex_array_bgra */
46 #define BGRA_OR_4 5
47
48
49 /** Used to indicate which GL datatypes are accepted by each of the
50 * glVertex/Color/Attrib/EtcPointer() functions.
51 */
52 #define BOOL_BIT (1 << 0)
53 #define BYTE_BIT (1 << 1)
54 #define UNSIGNED_BYTE_BIT (1 << 2)
55 #define SHORT_BIT (1 << 3)
56 #define UNSIGNED_SHORT_BIT (1 << 4)
57 #define INT_BIT (1 << 5)
58 #define UNSIGNED_INT_BIT (1 << 6)
59 #define HALF_BIT (1 << 7)
60 #define FLOAT_BIT (1 << 8)
61 #define DOUBLE_BIT (1 << 9)
62 #define FIXED_ES_BIT (1 << 10)
63 #define FIXED_GL_BIT (1 << 11)
64 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
65 #define INT_2_10_10_10_REV_BIT (1 << 13)
66 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
67 #define ALL_TYPE_BITS ((1 << 15) - 1)
68
69 #define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
70 SHORT_BIT | UNSIGNED_SHORT_BIT | \
71 INT_BIT | UNSIGNED_INT_BIT | \
72 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
73 FIXED_GL_BIT | \
74 UNSIGNED_INT_2_10_10_10_REV_BIT | \
75 INT_2_10_10_10_REV_BIT | \
76 UNSIGNED_INT_10F_11F_11F_REV_BIT)
77
78 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
79 SHORT_BIT | UNSIGNED_SHORT_BIT | \
80 INT_BIT | UNSIGNED_INT_BIT)
81
82 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
83
84
85 /** Convert GL datatype enum into a <type>_BIT value seen above */
86 static GLbitfield
87 type_to_bit(const struct gl_context *ctx, GLenum type)
88 {
89 switch (type) {
90 case GL_BOOL:
91 return BOOL_BIT;
92 case GL_BYTE:
93 return BYTE_BIT;
94 case GL_UNSIGNED_BYTE:
95 return UNSIGNED_BYTE_BIT;
96 case GL_SHORT:
97 return SHORT_BIT;
98 case GL_UNSIGNED_SHORT:
99 return UNSIGNED_SHORT_BIT;
100 case GL_INT:
101 return INT_BIT;
102 case GL_UNSIGNED_INT:
103 return UNSIGNED_INT_BIT;
104 case GL_HALF_FLOAT:
105 case GL_HALF_FLOAT_OES:
106 if (ctx->Extensions.ARB_half_float_vertex)
107 return HALF_BIT;
108 else
109 return 0x0;
110 case GL_FLOAT:
111 return FLOAT_BIT;
112 case GL_DOUBLE:
113 return DOUBLE_BIT;
114 case GL_FIXED:
115 return _mesa_is_desktop_gl(ctx) ? FIXED_GL_BIT : FIXED_ES_BIT;
116 case GL_UNSIGNED_INT_2_10_10_10_REV:
117 return UNSIGNED_INT_2_10_10_10_REV_BIT;
118 case GL_INT_2_10_10_10_REV:
119 return INT_2_10_10_10_REV_BIT;
120 case GL_UNSIGNED_INT_10F_11F_11F_REV:
121 return UNSIGNED_INT_10F_11F_11F_REV_BIT;
122 default:
123 return 0;
124 }
125 }
126
127
128 /**
129 * Sets the BufferBindingIndex field for the vertex attribute given by
130 * attribIndex.
131 */
132 static void
133 vertex_attrib_binding(struct gl_context *ctx,
134 struct gl_vertex_array_object *vao,
135 GLuint attribIndex,
136 GLuint bindingIndex)
137 {
138 struct gl_array_attributes *array = &vao->VertexAttrib[attribIndex];
139
140 if (!_mesa_is_bufferobj(vao->BufferBinding[bindingIndex].BufferObj))
141 vao->VertexAttribBufferMask &= ~VERT_BIT(attribIndex);
142 else
143 vao->VertexAttribBufferMask |= VERT_BIT(attribIndex);
144
145 if (array->BufferBindingIndex != bindingIndex) {
146 const GLbitfield64 array_bit = VERT_BIT(attribIndex);
147
148 FLUSH_VERTICES(ctx, _NEW_ARRAY);
149
150 vao->BufferBinding[array->BufferBindingIndex]._BoundArrays &= ~array_bit;
151 vao->BufferBinding[bindingIndex]._BoundArrays |= array_bit;
152
153 array->BufferBindingIndex = bindingIndex;
154
155 vao->NewArrays |= array_bit;
156 }
157 }
158
159
160 /**
161 * Binds a buffer object to the vertex buffer binding point given by index,
162 * and sets the Offset and Stride fields.
163 */
164 void
165 _mesa_bind_vertex_buffer(struct gl_context *ctx,
166 struct gl_vertex_array_object *vao,
167 GLuint index,
168 struct gl_buffer_object *vbo,
169 GLintptr offset, GLsizei stride)
170 {
171 struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index];
172
173 if (binding->BufferObj != vbo ||
174 binding->Offset != offset ||
175 binding->Stride != stride) {
176
177 FLUSH_VERTICES(ctx, _NEW_ARRAY);
178
179 _mesa_reference_buffer_object(ctx, &binding->BufferObj, vbo);
180
181 binding->Offset = offset;
182 binding->Stride = stride;
183
184 if (!_mesa_is_bufferobj(vbo))
185 vao->VertexAttribBufferMask &= ~binding->_BoundArrays;
186 else
187 vao->VertexAttribBufferMask |= binding->_BoundArrays;
188
189 vao->NewArrays |= binding->_BoundArrays;
190 }
191 }
192
193
194 /**
195 * Sets the InstanceDivisor field in the vertex buffer binding point
196 * given by bindingIndex.
197 */
198 static void
199 vertex_binding_divisor(struct gl_context *ctx,
200 struct gl_vertex_array_object *vao,
201 GLuint bindingIndex,
202 GLuint divisor)
203 {
204 struct gl_vertex_buffer_binding *binding =
205 &vao->BufferBinding[bindingIndex];
206
207 if (binding->InstanceDivisor != divisor) {
208 FLUSH_VERTICES(ctx, _NEW_ARRAY);
209 binding->InstanceDivisor = divisor;
210 vao->NewArrays |= binding->_BoundArrays;
211 }
212 }
213
214
215 /**
216 * Examine the API profile and extensions to determine which types are legal
217 * for vertex arrays. This is called once from update_array_format().
218 */
219 static GLbitfield
220 get_legal_types_mask(const struct gl_context *ctx)
221 {
222 GLbitfield legalTypesMask = ALL_TYPE_BITS;
223
224 if (_mesa_is_gles(ctx)) {
225 legalTypesMask &= ~(FIXED_GL_BIT |
226 DOUBLE_BIT |
227 UNSIGNED_INT_10F_11F_11F_REV_BIT);
228
229 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
230 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
231 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
232 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
233 * quite as trivial as we'd like because it uses a different enum value
234 * for GL_HALF_FLOAT_OES.
235 */
236 if (ctx->Version < 30) {
237 legalTypesMask &= ~(UNSIGNED_INT_BIT |
238 INT_BIT |
239 UNSIGNED_INT_2_10_10_10_REV_BIT |
240 INT_2_10_10_10_REV_BIT);
241
242 if (!_mesa_has_OES_vertex_half_float(ctx))
243 legalTypesMask &= ~HALF_BIT;
244 }
245 }
246 else {
247 legalTypesMask &= ~FIXED_ES_BIT;
248
249 if (!ctx->Extensions.ARB_ES2_compatibility)
250 legalTypesMask &= ~FIXED_GL_BIT;
251
252 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
253 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
254 INT_2_10_10_10_REV_BIT);
255
256 if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev)
257 legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT;
258 }
259
260 return legalTypesMask;
261 }
262
263
264 /**
265 * \param attrib The index of the attribute array
266 * \param size Components per element (1, 2, 3 or 4)
267 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
268 * \param format Either GL_RGBA or GL_BGRA.
269 * \param normalized Whether integer types are converted to floats in [-1, 1]
270 * \param integer Integer-valued values (will not be normalized to [-1, 1])
271 * \param doubles Double values not reduced to floats
272 * \param relativeOffset Offset of the first element relative to the binding
273 * offset.
274 * \param flush_verties Should \c FLUSH_VERTICES be invoked before updating
275 * state?
276 */
277 void
278 _mesa_update_array_format(struct gl_context *ctx,
279 struct gl_vertex_array_object *vao,
280 GLuint attrib, GLint size, GLenum type,
281 GLenum format, GLboolean normalized,
282 GLboolean integer, GLboolean doubles,
283 GLuint relativeOffset, bool flush_vertices)
284 {
285 struct gl_array_attributes *const array = &vao->VertexAttrib[attrib];
286 GLint elementSize;
287
288 assert(size <= 4);
289
290 if (flush_vertices) {
291 FLUSH_VERTICES(ctx, 0);
292 }
293
294 elementSize = _mesa_bytes_per_vertex_attrib(size, type);
295 assert(elementSize != -1);
296
297 array->Size = size;
298 array->Type = type;
299 array->Format = format;
300 array->Normalized = normalized;
301 array->Integer = integer;
302 array->Doubles = doubles;
303 array->RelativeOffset = relativeOffset;
304 array->_ElementSize = elementSize;
305
306 vao->NewArrays |= VERT_BIT(attrib);
307 ctx->NewState |= _NEW_ARRAY;
308 }
309
310 /**
311 * Does error checking and updates the format in an attrib array.
312 *
313 * Called by update_array() and VertexAttrib*Format().
314 *
315 * \param func Name of calling function used for error reporting
316 * \param attrib The index of the attribute array
317 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
318 * \param sizeMin Min allowable size value
319 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
320 * \param size Components per element (1, 2, 3 or 4)
321 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
322 * \param normalized Whether integer types are converted to floats in [-1, 1]
323 * \param integer Integer-valued values (will not be normalized to [-1, 1])
324 * \param doubles Double values not reduced to floats
325 * \param relativeOffset Offset of the first element relative to the binding offset.
326 */
327 static bool
328 update_array_format(struct gl_context *ctx,
329 const char *func,
330 struct gl_vertex_array_object *vao,
331 GLuint attrib, GLbitfield legalTypesMask,
332 GLint sizeMin, GLint sizeMax,
333 GLint size, GLenum type,
334 GLboolean normalized, GLboolean integer, GLboolean doubles,
335 GLuint relativeOffset)
336 {
337 GLbitfield typeBit;
338 GLenum format = GL_RGBA;
339
340 /* at most, one of these bools can be true */
341 assert((int) normalized + (int) integer + (int) doubles <= 1);
342
343 if (ctx->Array.LegalTypesMask == 0 || ctx->Array.LegalTypesMaskAPI != ctx->API) {
344 /* Compute the LegalTypesMask only once, unless the context API has
345 * changed, in which case we want to compute it again. We can't do this
346 * in _mesa_init_varrays() below because extensions are not yet enabled
347 * at that point.
348 */
349 ctx->Array.LegalTypesMask = get_legal_types_mask(ctx);
350 ctx->Array.LegalTypesMaskAPI = ctx->API;
351 }
352
353 legalTypesMask &= ctx->Array.LegalTypesMask;
354
355 if (_mesa_is_gles(ctx) && sizeMax == BGRA_OR_4) {
356 /* BGRA ordering is not supported in ES contexts.
357 */
358 sizeMax = 4;
359 }
360
361 typeBit = type_to_bit(ctx, type);
362 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
363 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
364 func, _mesa_enum_to_string(type));
365 return false;
366 }
367
368 /* Do size parameter checking.
369 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
370 * must be handled specially.
371 */
372 if (ctx->Extensions.EXT_vertex_array_bgra &&
373 sizeMax == BGRA_OR_4 &&
374 size == GL_BGRA) {
375 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
376 *
377 * "An INVALID_OPERATION error is generated under any of the following
378 * conditions:
379 * ...
380 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
381 * or UNSIGNED_INT_2_10_10_10_REV;
382 * ...
383 * • size is BGRA and normalized is FALSE;"
384 */
385 bool bgra_error = false;
386
387 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
388 if (type != GL_UNSIGNED_INT_2_10_10_10_REV &&
389 type != GL_INT_2_10_10_10_REV &&
390 type != GL_UNSIGNED_BYTE)
391 bgra_error = true;
392 } else if (type != GL_UNSIGNED_BYTE)
393 bgra_error = true;
394
395 if (bgra_error) {
396 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)",
397 func, _mesa_enum_to_string(type));
398 return false;
399 }
400
401 if (!normalized) {
402 _mesa_error(ctx, GL_INVALID_OPERATION,
403 "%s(size=GL_BGRA and normalized=GL_FALSE)", func);
404 return false;
405 }
406
407 format = GL_BGRA;
408 size = 4;
409 }
410 else if (size < sizeMin || size > sizeMax || size > 4) {
411 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
412 return false;
413 }
414
415 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
416 (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
417 type == GL_INT_2_10_10_10_REV) && size != 4) {
418 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
419 return false;
420 }
421
422 /* The ARB_vertex_attrib_binding_spec says:
423 *
424 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
425 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
426 */
427 if (relativeOffset > ctx->Const.MaxVertexAttribRelativeOffset) {
428 _mesa_error(ctx, GL_INVALID_VALUE,
429 "%s(relativeOffset=%d > "
430 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
431 func, relativeOffset);
432 return false;
433 }
434
435 if (ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev &&
436 type == GL_UNSIGNED_INT_10F_11F_11F_REV && size != 3) {
437 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
438 return false;
439 }
440
441 _mesa_update_array_format(ctx, vao, attrib, size, type, format,
442 normalized, integer, doubles, relativeOffset,
443 false);
444
445 return true;
446 }
447
448
449 /**
450 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
451 * functions.
452 *
453 * \param func name of calling function used for error reporting
454 * \param attrib the attribute array index to update
455 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
456 * \param sizeMin min allowable size value
457 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
458 * \param size components per element (1, 2, 3 or 4)
459 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
460 * \param stride stride between elements, in elements
461 * \param normalized are integer types converted to floats in [-1, 1]?
462 * \param integer integer-valued values (will not be normalized to [-1,1])
463 * \param doubles Double values not reduced to floats
464 * \param ptr the address (or offset inside VBO) of the array data
465 */
466 static void
467 update_array(struct gl_context *ctx,
468 const char *func,
469 GLuint attrib, GLbitfield legalTypesMask,
470 GLint sizeMin, GLint sizeMax,
471 GLint size, GLenum type, GLsizei stride,
472 GLboolean normalized, GLboolean integer, GLboolean doubles,
473 const GLvoid *ptr)
474 {
475 struct gl_vertex_array_object *vao = ctx->Array.VAO;
476 struct gl_array_attributes *array;
477 GLsizei effectiveStride;
478
479 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
480 *
481 * "Client vertex arrays - all vertex array attribute pointers must
482 * refer to buffer objects (section 2.9.2). The default vertex array
483 * object (the name zero) is also deprecated. Calling
484 * VertexAttribPointer when no buffer object or no vertex array object
485 * is bound will generate an INVALID_OPERATION error..."
486 *
487 * The check for VBOs is handled below.
488 */
489 if (ctx->API == API_OPENGL_CORE && (vao == ctx->Array.DefaultVAO)) {
490 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)",
491 func);
492 return;
493 }
494
495 if (stride < 0) {
496 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
497 return;
498 }
499
500 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
501 stride > ctx->Const.MaxVertexAttribStride) {
502 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
503 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
504 return;
505 }
506
507 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
508 *
509 * "An INVALID_OPERATION error is generated under any of the following
510 * conditions:
511 *
512 * ...
513 *
514 * * any of the *Pointer commands specifying the location and
515 * organization of vertex array data are called while zero is bound
516 * to the ARRAY_BUFFER buffer object binding point (see section
517 * 2.9.6), and the pointer argument is not NULL."
518 */
519 if (ptr != NULL && vao->ARBsemantics &&
520 !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) {
521 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
522 return;
523 }
524
525 if (!update_array_format(ctx, func, vao, attrib,
526 legalTypesMask, sizeMin, sizeMax,
527 size, type, normalized, integer, doubles, 0)) {
528 return;
529 }
530
531 /* Reset the vertex attrib binding */
532 vertex_attrib_binding(ctx, vao, attrib, attrib);
533
534 /* The Stride and Ptr fields are not set by update_array_format() */
535 array = &vao->VertexAttrib[attrib];
536 array->Stride = stride;
537 array->Ptr = ptr;
538
539 /* Update the vertex buffer binding */
540 effectiveStride = stride != 0 ? stride : array->_ElementSize;
541 _mesa_bind_vertex_buffer(ctx, vao, attrib,
542 ctx->Array.ArrayBufferObj, (GLintptr) ptr,
543 effectiveStride);
544 }
545
546
547 void GLAPIENTRY
548 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
549 {
550 GET_CURRENT_CONTEXT(ctx);
551 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
552 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
553 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
554 DOUBLE_BIT | HALF_BIT |
555 UNSIGNED_INT_2_10_10_10_REV_BIT |
556 INT_2_10_10_10_REV_BIT);
557
558 FLUSH_VERTICES(ctx, 0);
559
560 update_array(ctx, "glVertexPointer", VERT_ATTRIB_POS,
561 legalTypes, 2, 4,
562 size, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
563 }
564
565
566 void GLAPIENTRY
567 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
568 {
569 GET_CURRENT_CONTEXT(ctx);
570 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
571 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
572 : (BYTE_BIT | SHORT_BIT | INT_BIT |
573 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
574 UNSIGNED_INT_2_10_10_10_REV_BIT |
575 INT_2_10_10_10_REV_BIT);
576
577 FLUSH_VERTICES(ctx, 0);
578
579 update_array(ctx, "glNormalPointer", VERT_ATTRIB_NORMAL,
580 legalTypes, 3, 3,
581 3, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
582 }
583
584
585 void GLAPIENTRY
586 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
587 {
588 GET_CURRENT_CONTEXT(ctx);
589 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
590 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
591 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
592 SHORT_BIT | UNSIGNED_SHORT_BIT |
593 INT_BIT | UNSIGNED_INT_BIT |
594 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
595 UNSIGNED_INT_2_10_10_10_REV_BIT |
596 INT_2_10_10_10_REV_BIT);
597 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
598
599 FLUSH_VERTICES(ctx, 0);
600
601 update_array(ctx, "glColorPointer", VERT_ATTRIB_COLOR0,
602 legalTypes, sizeMin, BGRA_OR_4,
603 size, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
604 }
605
606
607 void GLAPIENTRY
608 _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
609 {
610 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
611 GET_CURRENT_CONTEXT(ctx);
612
613 FLUSH_VERTICES(ctx, 0);
614
615 update_array(ctx, "glFogCoordPointer", VERT_ATTRIB_FOG,
616 legalTypes, 1, 1,
617 1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
618 }
619
620
621 void GLAPIENTRY
622 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
623 {
624 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
625 FLOAT_BIT | DOUBLE_BIT);
626 GET_CURRENT_CONTEXT(ctx);
627
628 FLUSH_VERTICES(ctx, 0);
629
630 update_array(ctx, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX,
631 legalTypes, 1, 1,
632 1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
633 }
634
635
636 void GLAPIENTRY
637 _mesa_SecondaryColorPointer(GLint size, GLenum type,
638 GLsizei stride, const GLvoid *ptr)
639 {
640 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
641 SHORT_BIT | UNSIGNED_SHORT_BIT |
642 INT_BIT | UNSIGNED_INT_BIT |
643 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
644 UNSIGNED_INT_2_10_10_10_REV_BIT |
645 INT_2_10_10_10_REV_BIT);
646 GET_CURRENT_CONTEXT(ctx);
647
648 FLUSH_VERTICES(ctx, 0);
649
650 update_array(ctx, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1,
651 legalTypes, 3, BGRA_OR_4,
652 size, type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
653 }
654
655
656 void GLAPIENTRY
657 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
658 const GLvoid *ptr)
659 {
660 GET_CURRENT_CONTEXT(ctx);
661 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
662 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
663 : (SHORT_BIT | INT_BIT |
664 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
665 UNSIGNED_INT_2_10_10_10_REV_BIT |
666 INT_2_10_10_10_REV_BIT);
667 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
668 const GLuint unit = ctx->Array.ActiveTexture;
669
670 FLUSH_VERTICES(ctx, 0);
671
672 update_array(ctx, "glTexCoordPointer", VERT_ATTRIB_TEX(unit),
673 legalTypes, sizeMin, 4,
674 size, type, stride, GL_FALSE, GL_FALSE, GL_FALSE,
675 ptr);
676 }
677
678
679 void GLAPIENTRY
680 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
681 {
682 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
683 /* this is the same type that glEdgeFlag uses */
684 const GLboolean integer = GL_FALSE;
685 GET_CURRENT_CONTEXT(ctx);
686
687 FLUSH_VERTICES(ctx, 0);
688
689 update_array(ctx, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG,
690 legalTypes, 1, 1,
691 1, GL_UNSIGNED_BYTE, stride, GL_FALSE, integer, GL_FALSE, ptr);
692 }
693
694
695 void GLAPIENTRY
696 _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr)
697 {
698 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
699 GET_CURRENT_CONTEXT(ctx);
700
701 FLUSH_VERTICES(ctx, 0);
702
703 if (ctx->API != API_OPENGLES) {
704 _mesa_error(ctx, GL_INVALID_OPERATION,
705 "glPointSizePointer(ES 1.x only)");
706 return;
707 }
708
709 update_array(ctx, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE,
710 legalTypes, 1, 1,
711 1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
712 }
713
714
715 /**
716 * Set a generic vertex attribute array.
717 * Note that these arrays DO NOT alias the conventional GL vertex arrays
718 * (position, normal, color, fog, texcoord, etc).
719 */
720 void GLAPIENTRY
721 _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
722 GLboolean normalized,
723 GLsizei stride, const GLvoid *ptr)
724 {
725 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
726 SHORT_BIT | UNSIGNED_SHORT_BIT |
727 INT_BIT | UNSIGNED_INT_BIT |
728 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
729 FIXED_ES_BIT | FIXED_GL_BIT |
730 UNSIGNED_INT_2_10_10_10_REV_BIT |
731 INT_2_10_10_10_REV_BIT |
732 UNSIGNED_INT_10F_11F_11F_REV_BIT);
733 GET_CURRENT_CONTEXT(ctx);
734
735 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
736 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(index)");
737 return;
738 }
739
740 update_array(ctx, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index),
741 legalTypes, 1, BGRA_OR_4,
742 size, type, stride, normalized, GL_FALSE, GL_FALSE, ptr);
743 }
744
745
746 /**
747 * GL_EXT_gpu_shader4 / GL 3.0.
748 * Set an integer-valued vertex attribute array.
749 * Note that these arrays DO NOT alias the conventional GL vertex arrays
750 * (position, normal, color, fog, texcoord, etc).
751 */
752 void GLAPIENTRY
753 _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
754 GLsizei stride, const GLvoid *ptr)
755 {
756 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
757 SHORT_BIT | UNSIGNED_SHORT_BIT |
758 INT_BIT | UNSIGNED_INT_BIT);
759 const GLboolean normalized = GL_FALSE;
760 const GLboolean integer = GL_TRUE;
761 GET_CURRENT_CONTEXT(ctx);
762
763 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
764 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
765 return;
766 }
767
768 update_array(ctx, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index),
769 legalTypes, 1, 4,
770 size, type, stride, normalized, integer, GL_FALSE, ptr);
771 }
772
773 void GLAPIENTRY
774 _mesa_VertexAttribLPointer(GLuint index, GLint size, GLenum type,
775 GLsizei stride, const GLvoid *ptr)
776 {
777 GET_CURRENT_CONTEXT(ctx);
778 const GLbitfield legalTypes = (DOUBLE_BIT);
779 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
780 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribLPointer(index)");
781 return;
782 }
783
784 update_array(ctx, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index),
785 legalTypes, 1, 4,
786 size, type, stride, GL_FALSE, GL_FALSE, GL_TRUE, ptr);
787 }
788
789
790 void
791 _mesa_enable_vertex_array_attrib(struct gl_context *ctx,
792 struct gl_vertex_array_object *vao,
793 unsigned attrib)
794 {
795 assert(attrib < ARRAY_SIZE(vao->VertexAttrib));
796
797 if (!vao->VertexAttrib[attrib].Enabled) {
798 /* was disabled, now being enabled */
799 FLUSH_VERTICES(ctx, _NEW_ARRAY);
800 vao->VertexAttrib[attrib].Enabled = GL_TRUE;
801 vao->_Enabled |= VERT_BIT(attrib);
802 vao->NewArrays |= VERT_BIT(attrib);
803 }
804 }
805
806 static void
807 enable_vertex_array_attrib(struct gl_context *ctx,
808 struct gl_vertex_array_object *vao,
809 GLuint index,
810 const char *func)
811 {
812 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
813 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
814 return;
815 }
816
817 _mesa_enable_vertex_array_attrib(ctx, vao, VERT_ATTRIB_GENERIC(index));
818 }
819
820
821 void GLAPIENTRY
822 _mesa_EnableVertexAttribArray(GLuint index)
823 {
824 GET_CURRENT_CONTEXT(ctx);
825 enable_vertex_array_attrib(ctx, ctx->Array.VAO, index,
826 "glEnableVertexAttribArray");
827 }
828
829
830 void GLAPIENTRY
831 _mesa_EnableVertexArrayAttrib(GLuint vaobj, GLuint index)
832 {
833 GET_CURRENT_CONTEXT(ctx);
834 struct gl_vertex_array_object *vao;
835
836 /* The ARB_direct_state_access specification says:
837 *
838 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
839 * and DisableVertexArrayAttrib if <vaobj> is not
840 * [compatibility profile: zero or] the name of an existing vertex
841 * array object."
842 */
843 vao = _mesa_lookup_vao_err(ctx, vaobj, "glEnableVertexArrayAttrib");
844 if (!vao)
845 return;
846
847 enable_vertex_array_attrib(ctx, vao, index, "glEnableVertexArrayAttrib");
848 }
849
850
851 static void
852 disable_vertex_array_attrib(struct gl_context *ctx,
853 struct gl_vertex_array_object *vao,
854 GLuint index,
855 const char *func)
856 {
857 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
858 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
859 return;
860 }
861
862 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
863
864 if (vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) {
865 /* was enabled, now being disabled */
866 FLUSH_VERTICES(ctx, _NEW_ARRAY);
867 vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_FALSE;
868 vao->_Enabled &= ~VERT_BIT_GENERIC(index);
869 vao->NewArrays |= VERT_BIT_GENERIC(index);
870 }
871 }
872
873
874 void GLAPIENTRY
875 _mesa_DisableVertexAttribArray(GLuint index)
876 {
877 GET_CURRENT_CONTEXT(ctx);
878 disable_vertex_array_attrib(ctx, ctx->Array.VAO, index,
879 "glDisableVertexAttribArray");
880 }
881
882
883 void GLAPIENTRY
884 _mesa_DisableVertexArrayAttrib(GLuint vaobj, GLuint index)
885 {
886 GET_CURRENT_CONTEXT(ctx);
887 struct gl_vertex_array_object *vao;
888
889 /* The ARB_direct_state_access specification says:
890 *
891 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
892 * and DisableVertexArrayAttrib if <vaobj> is not
893 * [compatibility profile: zero or] the name of an existing vertex
894 * array object."
895 */
896 vao = _mesa_lookup_vao_err(ctx, vaobj, "glDisableVertexArrayAttrib");
897 if (!vao)
898 return;
899
900 disable_vertex_array_attrib(ctx, vao, index, "glDisableVertexArrayAttrib");
901 }
902
903
904 /**
905 * Return info for a vertex attribute array (no alias with legacy
906 * vertex attributes (pos, normal, color, etc)). This function does
907 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
908 */
909 static GLuint
910 get_vertex_array_attrib(struct gl_context *ctx,
911 const struct gl_vertex_array_object *vao,
912 GLuint index, GLenum pname,
913 const char *caller)
914 {
915 const struct gl_array_attributes *array;
916
917 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
918 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
919 return 0;
920 }
921
922 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
923
924 array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
925
926 switch (pname) {
927 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
928 return array->Enabled;
929 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
930 return (array->Format == GL_BGRA) ? GL_BGRA : array->Size;
931 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
932 return array->Stride;
933 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
934 return array->Type;
935 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
936 return array->Normalized;
937 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
938 return vao->BufferBinding[array->BufferBindingIndex].BufferObj->Name;
939 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
940 if ((_mesa_is_desktop_gl(ctx)
941 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
942 || _mesa_is_gles3(ctx)) {
943 return array->Integer;
944 }
945 goto error;
946 case GL_VERTEX_ATTRIB_ARRAY_LONG:
947 if (_mesa_is_desktop_gl(ctx)) {
948 return array->Doubles;
949 }
950 goto error;
951 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
952 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
953 || _mesa_is_gles3(ctx)) {
954 return vao->BufferBinding[array->BufferBindingIndex].InstanceDivisor;
955 }
956 goto error;
957 case GL_VERTEX_ATTRIB_BINDING:
958 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
959 return array->BufferBindingIndex - VERT_ATTRIB_GENERIC0;
960 }
961 goto error;
962 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
963 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
964 return array->RelativeOffset;
965 }
966 goto error;
967 default:
968 ; /* fall-through */
969 }
970
971 error:
972 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
973 return 0;
974 }
975
976
977 static const GLfloat *
978 get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
979 {
980 if (index == 0) {
981 if (_mesa_attr_zero_aliases_vertex(ctx)) {
982 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
983 return NULL;
984 }
985 }
986 else if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
987 _mesa_error(ctx, GL_INVALID_VALUE,
988 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
989 return NULL;
990 }
991
992 assert(VERT_ATTRIB_GENERIC(index) <
993 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
994
995 FLUSH_CURRENT(ctx, 0);
996 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
997 }
998
999 void GLAPIENTRY
1000 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
1001 {
1002 GET_CURRENT_CONTEXT(ctx);
1003
1004 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1005 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
1006 if (v != NULL) {
1007 COPY_4V(params, v);
1008 }
1009 }
1010 else {
1011 params[0] = (GLfloat) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1012 index, pname,
1013 "glGetVertexAttribfv");
1014 }
1015 }
1016
1017
1018 void GLAPIENTRY
1019 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
1020 {
1021 GET_CURRENT_CONTEXT(ctx);
1022
1023 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1024 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
1025 if (v != NULL) {
1026 params[0] = (GLdouble) v[0];
1027 params[1] = (GLdouble) v[1];
1028 params[2] = (GLdouble) v[2];
1029 params[3] = (GLdouble) v[3];
1030 }
1031 }
1032 else {
1033 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1034 index, pname,
1035 "glGetVertexAttribdv");
1036 }
1037 }
1038
1039 void GLAPIENTRY
1040 _mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params)
1041 {
1042 GET_CURRENT_CONTEXT(ctx);
1043
1044 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1045 const GLdouble *v =
1046 (const GLdouble *)get_current_attrib(ctx, index,
1047 "glGetVertexAttribLdv");
1048 if (v != NULL) {
1049 params[0] = v[0];
1050 params[1] = v[1];
1051 params[2] = v[2];
1052 params[3] = v[3];
1053 }
1054 }
1055 else {
1056 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1057 index, pname,
1058 "glGetVertexAttribLdv");
1059 }
1060 }
1061
1062 void GLAPIENTRY
1063 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
1064 {
1065 GET_CURRENT_CONTEXT(ctx);
1066
1067 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1068 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
1069 if (v != NULL) {
1070 /* XXX should floats in[0,1] be scaled to full int range? */
1071 params[0] = (GLint) v[0];
1072 params[1] = (GLint) v[1];
1073 params[2] = (GLint) v[2];
1074 params[3] = (GLint) v[3];
1075 }
1076 }
1077 else {
1078 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1079 index, pname,
1080 "glGetVertexAttribiv");
1081 }
1082 }
1083
1084
1085 /** GL 3.0 */
1086 void GLAPIENTRY
1087 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
1088 {
1089 GET_CURRENT_CONTEXT(ctx);
1090
1091 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1092 const GLint *v = (const GLint *)
1093 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
1094 if (v != NULL) {
1095 COPY_4V(params, v);
1096 }
1097 }
1098 else {
1099 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
1100 index, pname,
1101 "glGetVertexAttribIiv");
1102 }
1103 }
1104
1105
1106 /** GL 3.0 */
1107 void GLAPIENTRY
1108 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
1109 {
1110 GET_CURRENT_CONTEXT(ctx);
1111
1112 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
1113 const GLuint *v = (const GLuint *)
1114 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
1115 if (v != NULL) {
1116 COPY_4V(params, v);
1117 }
1118 }
1119 else {
1120 params[0] = get_vertex_array_attrib(ctx, ctx->Array.VAO,
1121 index, pname,
1122 "glGetVertexAttribIuiv");
1123 }
1124 }
1125
1126
1127 void GLAPIENTRY
1128 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
1129 {
1130 GET_CURRENT_CONTEXT(ctx);
1131
1132 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1133 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
1134 return;
1135 }
1136
1137 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
1138 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
1139 return;
1140 }
1141
1142 assert(VERT_ATTRIB_GENERIC(index) <
1143 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
1144
1145 *pointer = (GLvoid *)
1146 ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
1147 }
1148
1149
1150 /** ARB_direct_state_access */
1151 void GLAPIENTRY
1152 _mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index,
1153 GLenum pname, GLint *params)
1154 {
1155 GET_CURRENT_CONTEXT(ctx);
1156 struct gl_vertex_array_object *vao;
1157
1158 /* The ARB_direct_state_access specification says:
1159 *
1160 * "An INVALID_OPERATION error is generated if <vaobj> is not
1161 * [compatibility profile: zero or] the name of an existing
1162 * vertex array object."
1163 */
1164 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexediv");
1165 if (!vao)
1166 return;
1167
1168 /* The ARB_direct_state_access specification says:
1169 *
1170 * "For GetVertexArrayIndexediv, <pname> must be one of
1171 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1172 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1173 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1174 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1175 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1176 *
1177 * and:
1178 *
1179 * "Add GetVertexArrayIndexediv in 'Get Command' for
1180 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1181 * VERTEX_ATTRIB_BINDING,
1182 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1183 * VERTEX_BINDING_OFFSET, and
1184 * VERTEX_BINDING_STRIDE states"
1185 *
1186 * The only parameter name common to both lists is
1187 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1188 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1189 * pretty clear however that the intent is that it should be possible
1190 * to query all vertex attrib and binding states that can be set with
1191 * a DSA function.
1192 */
1193 switch (pname) {
1194 case GL_VERTEX_BINDING_OFFSET:
1195 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1196 break;
1197 case GL_VERTEX_BINDING_STRIDE:
1198 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Stride;
1199 break;
1200 case GL_VERTEX_BINDING_DIVISOR:
1201 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
1202 break;
1203 case GL_VERTEX_BINDING_BUFFER:
1204 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name;
1205 break;
1206 default:
1207 params[0] = get_vertex_array_attrib(ctx, vao, index, pname,
1208 "glGetVertexArrayIndexediv");
1209 break;
1210 }
1211 }
1212
1213
1214 void GLAPIENTRY
1215 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj, GLuint index,
1216 GLenum pname, GLint64 *params)
1217 {
1218 GET_CURRENT_CONTEXT(ctx);
1219 struct gl_vertex_array_object *vao;
1220
1221 /* The ARB_direct_state_access specification says:
1222 *
1223 * "An INVALID_OPERATION error is generated if <vaobj> is not
1224 * [compatibility profile: zero or] the name of an existing
1225 * vertex array object."
1226 */
1227 vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexed64iv");
1228 if (!vao)
1229 return;
1230
1231 /* The ARB_direct_state_access specification says:
1232 *
1233 * "For GetVertexArrayIndexed64iv, <pname> must be
1234 * VERTEX_BINDING_OFFSET."
1235 *
1236 * and:
1237 *
1238 * "An INVALID_ENUM error is generated if <pname> is not one of
1239 * the valid values listed above for the corresponding command."
1240 */
1241 if (pname != GL_VERTEX_BINDING_OFFSET) {
1242 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayIndexed64iv("
1243 "pname != GL_VERTEX_BINDING_OFFSET)");
1244 return;
1245 }
1246
1247 /* The ARB_direct_state_access specification says:
1248 *
1249 * "An INVALID_VALUE error is generated if <index> is greater than
1250 * or equal to the value of MAX_VERTEX_ATTRIBS."
1251 *
1252 * Since the index refers to a buffer binding in this case, the intended
1253 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1254 * required to be the same, so in practice this doesn't matter.
1255 */
1256 if (index >= ctx->Const.MaxVertexAttribBindings) {
1257 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexArrayIndexed64iv(index"
1258 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1259 index, ctx->Const.MaxVertexAttribBindings);
1260 return;
1261 }
1262
1263 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1264 }
1265
1266
1267 void GLAPIENTRY
1268 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
1269 GLsizei count, const GLvoid *ptr)
1270 {
1271 (void) count;
1272 _mesa_VertexPointer(size, type, stride, ptr);
1273 }
1274
1275
1276 void GLAPIENTRY
1277 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1278 const GLvoid *ptr)
1279 {
1280 (void) count;
1281 _mesa_NormalPointer(type, stride, ptr);
1282 }
1283
1284
1285 void GLAPIENTRY
1286 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
1287 const GLvoid *ptr)
1288 {
1289 (void) count;
1290 _mesa_ColorPointer(size, type, stride, ptr);
1291 }
1292
1293
1294 void GLAPIENTRY
1295 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
1296 const GLvoid *ptr)
1297 {
1298 (void) count;
1299 _mesa_IndexPointer(type, stride, ptr);
1300 }
1301
1302
1303 void GLAPIENTRY
1304 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
1305 GLsizei count, const GLvoid *ptr)
1306 {
1307 (void) count;
1308 _mesa_TexCoordPointer(size, type, stride, ptr);
1309 }
1310
1311
1312 void GLAPIENTRY
1313 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
1314 {
1315 (void) count;
1316 _mesa_EdgeFlagPointer(stride, ptr);
1317 }
1318
1319
1320 void GLAPIENTRY
1321 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
1322 {
1323 GET_CURRENT_CONTEXT(ctx);
1324 GLboolean tflag, cflag, nflag; /* enable/disable flags */
1325 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
1326 GLenum ctype = 0; /* color type */
1327 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
1328 const GLint toffset = 0; /* always zero */
1329 GLint defstride; /* default stride */
1330 GLint c, f;
1331
1332 FLUSH_VERTICES(ctx, 0);
1333
1334 f = sizeof(GLfloat);
1335 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
1336
1337 if (stride < 0) {
1338 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
1339 return;
1340 }
1341
1342 switch (format) {
1343 case GL_V2F:
1344 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1345 tcomps = 0; ccomps = 0; vcomps = 2;
1346 voffset = 0;
1347 defstride = 2*f;
1348 break;
1349 case GL_V3F:
1350 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
1351 tcomps = 0; ccomps = 0; vcomps = 3;
1352 voffset = 0;
1353 defstride = 3*f;
1354 break;
1355 case GL_C4UB_V2F:
1356 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1357 tcomps = 0; ccomps = 4; vcomps = 2;
1358 ctype = GL_UNSIGNED_BYTE;
1359 coffset = 0;
1360 voffset = c;
1361 defstride = c + 2*f;
1362 break;
1363 case GL_C4UB_V3F:
1364 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1365 tcomps = 0; ccomps = 4; vcomps = 3;
1366 ctype = GL_UNSIGNED_BYTE;
1367 coffset = 0;
1368 voffset = c;
1369 defstride = c + 3*f;
1370 break;
1371 case GL_C3F_V3F:
1372 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
1373 tcomps = 0; ccomps = 3; vcomps = 3;
1374 ctype = GL_FLOAT;
1375 coffset = 0;
1376 voffset = 3*f;
1377 defstride = 6*f;
1378 break;
1379 case GL_N3F_V3F:
1380 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
1381 tcomps = 0; ccomps = 0; vcomps = 3;
1382 noffset = 0;
1383 voffset = 3*f;
1384 defstride = 6*f;
1385 break;
1386 case GL_C4F_N3F_V3F:
1387 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
1388 tcomps = 0; ccomps = 4; vcomps = 3;
1389 ctype = GL_FLOAT;
1390 coffset = 0;
1391 noffset = 4*f;
1392 voffset = 7*f;
1393 defstride = 10*f;
1394 break;
1395 case GL_T2F_V3F:
1396 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1397 tcomps = 2; ccomps = 0; vcomps = 3;
1398 voffset = 2*f;
1399 defstride = 5*f;
1400 break;
1401 case GL_T4F_V4F:
1402 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
1403 tcomps = 4; ccomps = 0; vcomps = 4;
1404 voffset = 4*f;
1405 defstride = 8*f;
1406 break;
1407 case GL_T2F_C4UB_V3F:
1408 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1409 tcomps = 2; ccomps = 4; vcomps = 3;
1410 ctype = GL_UNSIGNED_BYTE;
1411 coffset = 2*f;
1412 voffset = c+2*f;
1413 defstride = c+5*f;
1414 break;
1415 case GL_T2F_C3F_V3F:
1416 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
1417 tcomps = 2; ccomps = 3; vcomps = 3;
1418 ctype = GL_FLOAT;
1419 coffset = 2*f;
1420 voffset = 5*f;
1421 defstride = 8*f;
1422 break;
1423 case GL_T2F_N3F_V3F:
1424 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
1425 tcomps = 2; ccomps = 0; vcomps = 3;
1426 noffset = 2*f;
1427 voffset = 5*f;
1428 defstride = 8*f;
1429 break;
1430 case GL_T2F_C4F_N3F_V3F:
1431 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1432 tcomps = 2; ccomps = 4; vcomps = 3;
1433 ctype = GL_FLOAT;
1434 coffset = 2*f;
1435 noffset = 6*f;
1436 voffset = 9*f;
1437 defstride = 12*f;
1438 break;
1439 case GL_T4F_C4F_N3F_V4F:
1440 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
1441 tcomps = 4; ccomps = 4; vcomps = 4;
1442 ctype = GL_FLOAT;
1443 coffset = 4*f;
1444 noffset = 8*f;
1445 voffset = 11*f;
1446 defstride = 15*f;
1447 break;
1448 default:
1449 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
1450 return;
1451 }
1452
1453 if (stride==0) {
1454 stride = defstride;
1455 }
1456
1457 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
1458 _mesa_DisableClientState( GL_INDEX_ARRAY );
1459 /* XXX also disable secondary color and generic arrays? */
1460
1461 /* Texcoords */
1462 if (tflag) {
1463 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
1464 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
1465 (GLubyte *) pointer + toffset );
1466 }
1467 else {
1468 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
1469 }
1470
1471 /* Color */
1472 if (cflag) {
1473 _mesa_EnableClientState( GL_COLOR_ARRAY );
1474 _mesa_ColorPointer( ccomps, ctype, stride,
1475 (GLubyte *) pointer + coffset );
1476 }
1477 else {
1478 _mesa_DisableClientState( GL_COLOR_ARRAY );
1479 }
1480
1481
1482 /* Normals */
1483 if (nflag) {
1484 _mesa_EnableClientState( GL_NORMAL_ARRAY );
1485 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
1486 }
1487 else {
1488 _mesa_DisableClientState( GL_NORMAL_ARRAY );
1489 }
1490
1491 /* Vertices */
1492 _mesa_EnableClientState( GL_VERTEX_ARRAY );
1493 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
1494 (GLubyte *) pointer + voffset );
1495 }
1496
1497
1498 void GLAPIENTRY
1499 _mesa_LockArraysEXT(GLint first, GLsizei count)
1500 {
1501 GET_CURRENT_CONTEXT(ctx);
1502
1503 FLUSH_VERTICES(ctx, 0);
1504
1505 if (MESA_VERBOSE & VERBOSE_API)
1506 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
1507
1508 if (first < 0) {
1509 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
1510 return;
1511 }
1512 if (count <= 0) {
1513 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
1514 return;
1515 }
1516 if (ctx->Array.LockCount != 0) {
1517 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
1518 return;
1519 }
1520
1521 ctx->Array.LockFirst = first;
1522 ctx->Array.LockCount = count;
1523
1524 ctx->NewState |= _NEW_ARRAY;
1525 }
1526
1527
1528 void GLAPIENTRY
1529 _mesa_UnlockArraysEXT( void )
1530 {
1531 GET_CURRENT_CONTEXT(ctx);
1532
1533 FLUSH_VERTICES(ctx, 0);
1534
1535 if (MESA_VERBOSE & VERBOSE_API)
1536 _mesa_debug(ctx, "glUnlockArrays\n");
1537
1538 if (ctx->Array.LockCount == 0) {
1539 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
1540 return;
1541 }
1542
1543 ctx->Array.LockFirst = 0;
1544 ctx->Array.LockCount = 0;
1545 ctx->NewState |= _NEW_ARRAY;
1546 }
1547
1548
1549 /* GL_EXT_multi_draw_arrays */
1550 void GLAPIENTRY
1551 _mesa_MultiDrawArrays( GLenum mode, const GLint *first,
1552 const GLsizei *count, GLsizei primcount )
1553 {
1554 GET_CURRENT_CONTEXT(ctx);
1555 GLint i;
1556
1557 FLUSH_VERTICES(ctx, 0);
1558
1559 for (i = 0; i < primcount; i++) {
1560 if (count[i] > 0) {
1561 CALL_DrawArrays(ctx->CurrentClientDispatch, (mode, first[i], count[i]));
1562 }
1563 }
1564 }
1565
1566
1567 /* GL_IBM_multimode_draw_arrays */
1568 void GLAPIENTRY
1569 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
1570 const GLsizei * count,
1571 GLsizei primcount, GLint modestride )
1572 {
1573 GET_CURRENT_CONTEXT(ctx);
1574 GLint i;
1575
1576 FLUSH_VERTICES(ctx, 0);
1577
1578 for ( i = 0 ; i < primcount ; i++ ) {
1579 if ( count[i] > 0 ) {
1580 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1581 CALL_DrawArrays(ctx->CurrentServerDispatch, ( m, first[i], count[i] ));
1582 }
1583 }
1584 }
1585
1586
1587 /* GL_IBM_multimode_draw_arrays */
1588 void GLAPIENTRY
1589 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
1590 GLenum type, const GLvoid * const * indices,
1591 GLsizei primcount, GLint modestride )
1592 {
1593 GET_CURRENT_CONTEXT(ctx);
1594 GLint i;
1595
1596 FLUSH_VERTICES(ctx, 0);
1597
1598 /* XXX not sure about ARB_vertex_buffer_object handling here */
1599
1600 for ( i = 0 ; i < primcount ; i++ ) {
1601 if ( count[i] > 0 ) {
1602 GLenum m = *((GLenum *) ((GLubyte *) mode + i * modestride));
1603 CALL_DrawElements(ctx->CurrentServerDispatch, ( m, count[i], type,
1604 indices[i] ));
1605 }
1606 }
1607 }
1608
1609
1610 /**
1611 * GL_NV_primitive_restart and GL 3.1
1612 */
1613 void GLAPIENTRY
1614 _mesa_PrimitiveRestartIndex(GLuint index)
1615 {
1616 GET_CURRENT_CONTEXT(ctx);
1617
1618 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
1619 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
1620 return;
1621 }
1622
1623 if (ctx->Array.RestartIndex != index) {
1624 FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
1625 ctx->Array.RestartIndex = index;
1626 }
1627 }
1628
1629
1630 /**
1631 * See GL_ARB_instanced_arrays.
1632 * Note that the instance divisor only applies to generic arrays, not
1633 * the legacy vertex arrays.
1634 */
1635 void GLAPIENTRY
1636 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
1637 {
1638 GET_CURRENT_CONTEXT(ctx);
1639
1640 const GLuint genericIndex = VERT_ATTRIB_GENERIC(index);
1641 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
1642
1643 if (!ctx->Extensions.ARB_instanced_arrays) {
1644 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
1645 return;
1646 }
1647
1648 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1649 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribDivisor(index = %u)",
1650 index);
1651 return;
1652 }
1653
1654 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
1655
1656 /* The ARB_vertex_attrib_binding spec says:
1657 *
1658 * "The command
1659 *
1660 * void VertexAttribDivisor(uint index, uint divisor);
1661 *
1662 * is equivalent to (assuming no errors are generated):
1663 *
1664 * VertexAttribBinding(index, index);
1665 * VertexBindingDivisor(index, divisor);"
1666 */
1667 vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
1668 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
1669 }
1670
1671
1672 unsigned
1673 _mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type)
1674 {
1675 /* From the OpenGL 4.3 core specification, page 302:
1676 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1677 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1678 * is used."
1679 */
1680 if (ctx->Array.PrimitiveRestartFixedIndex) {
1681 switch (ib_type) {
1682 case GL_UNSIGNED_BYTE:
1683 return 0xff;
1684 case GL_UNSIGNED_SHORT:
1685 return 0xffff;
1686 case GL_UNSIGNED_INT:
1687 return 0xffffffff;
1688 default:
1689 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1690 }
1691 }
1692
1693 return ctx->Array.RestartIndex;
1694 }
1695
1696
1697 /**
1698 * GL_ARB_vertex_attrib_binding
1699 */
1700 static void
1701 vertex_array_vertex_buffer(struct gl_context *ctx,
1702 struct gl_vertex_array_object *vao,
1703 GLuint bindingIndex, GLuint buffer, GLintptr offset,
1704 GLsizei stride, const char *func)
1705 {
1706 struct gl_buffer_object *vbo;
1707
1708 ASSERT_OUTSIDE_BEGIN_END(ctx);
1709
1710 /* The ARB_vertex_attrib_binding spec says:
1711 *
1712 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1713 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1714 */
1715 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
1716 _mesa_error(ctx, GL_INVALID_VALUE,
1717 "%s(bindingindex=%u > "
1718 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1719 func, bindingIndex);
1720 return;
1721 }
1722
1723 /* The ARB_vertex_attrib_binding spec says:
1724 *
1725 * "The error INVALID_VALUE is generated if <stride> or <offset>
1726 * are negative."
1727 */
1728 if (offset < 0) {
1729 _mesa_error(ctx, GL_INVALID_VALUE,
1730 "%s(offset=%" PRId64 " < 0)",
1731 func, (int64_t) offset);
1732 return;
1733 }
1734
1735 if (stride < 0) {
1736 _mesa_error(ctx, GL_INVALID_VALUE,
1737 "%s(stride=%d < 0)", func, stride);
1738 return;
1739 }
1740
1741 if (((ctx->API == API_OPENGL_CORE && ctx->Version >= 44) || _mesa_is_gles31(ctx)) &&
1742 stride > ctx->Const.MaxVertexAttribStride) {
1743 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
1744 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
1745 return;
1746 }
1747
1748 if (buffer ==
1749 vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) {
1750 vbo = vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
1751 } else if (buffer != 0) {
1752 vbo = _mesa_lookup_bufferobj(ctx, buffer);
1753
1754 if (!vbo && _mesa_is_gles31(ctx)) {
1755 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-gen name)", func);
1756 return;
1757 }
1758 /* From the GL_ARB_vertex_attrib_array spec:
1759 *
1760 * "[Core profile only:]
1761 * An INVALID_OPERATION error is generated if buffer is not zero or a
1762 * name returned from a previous call to GenBuffers, or if such a name
1763 * has since been deleted with DeleteBuffers.
1764 *
1765 * Otherwise, we fall back to the same compat profile behavior as other
1766 * object references (automatically gen it).
1767 */
1768 if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &vbo, func))
1769 return;
1770 } else {
1771 /* The ARB_vertex_attrib_binding spec says:
1772 *
1773 * "If <buffer> is zero, any buffer object attached to this
1774 * bindpoint is detached."
1775 */
1776 vbo = ctx->Shared->NullBufferObj;
1777 }
1778
1779 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex),
1780 vbo, offset, stride);
1781 }
1782
1783
1784 void GLAPIENTRY
1785 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
1786 GLsizei stride)
1787 {
1788 GET_CURRENT_CONTEXT(ctx);
1789
1790 /* The ARB_vertex_attrib_binding spec says:
1791 *
1792 * "An INVALID_OPERATION error is generated if no vertex array object
1793 * is bound."
1794 */
1795 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
1796 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1797 _mesa_error(ctx, GL_INVALID_OPERATION,
1798 "glBindVertexBuffer(No array object bound)");
1799 return;
1800 }
1801
1802 vertex_array_vertex_buffer(ctx, ctx->Array.VAO, bindingIndex,
1803 buffer, offset, stride, "glBindVertexBuffer");
1804 }
1805
1806
1807 void GLAPIENTRY
1808 _mesa_VertexArrayVertexBuffer(GLuint vaobj, GLuint bindingIndex, GLuint buffer,
1809 GLintptr offset, GLsizei stride)
1810 {
1811 GET_CURRENT_CONTEXT(ctx);
1812 struct gl_vertex_array_object *vao;
1813
1814 /* The ARB_direct_state_access specification says:
1815 *
1816 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1817 * if <vaobj> is not [compatibility profile: zero or] the name of an
1818 * existing vertex array object."
1819 */
1820 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffer");
1821 if (!vao)
1822 return;
1823
1824 vertex_array_vertex_buffer(ctx, vao, bindingIndex,
1825 buffer, offset, stride,
1826 "glVertexArrayVertexBuffer");
1827 }
1828
1829
1830 static void
1831 vertex_array_vertex_buffers(struct gl_context *ctx,
1832 struct gl_vertex_array_object *vao,
1833 GLuint first, GLsizei count, const GLuint *buffers,
1834 const GLintptr *offsets, const GLsizei *strides,
1835 const char *func)
1836 {
1837 GLuint i;
1838
1839 ASSERT_OUTSIDE_BEGIN_END(ctx);
1840
1841 /* The ARB_multi_bind spec says:
1842 *
1843 * "An INVALID_OPERATION error is generated if <first> + <count>
1844 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1845 */
1846 if (first + count > ctx->Const.MaxVertexAttribBindings) {
1847 _mesa_error(ctx, GL_INVALID_OPERATION,
1848 "%s(first=%u + count=%d > the value of "
1849 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1850 func, first, count, ctx->Const.MaxVertexAttribBindings);
1851 return;
1852 }
1853
1854 if (!buffers) {
1855 /**
1856 * The ARB_multi_bind spec says:
1857 *
1858 * "If <buffers> is NULL, each affected vertex buffer binding point
1859 * from <first> through <first>+<count>-1 will be reset to have no
1860 * bound buffer object. In this case, the offsets and strides
1861 * associated with the binding points are set to default values,
1862 * ignoring <offsets> and <strides>."
1863 */
1864 struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj;
1865
1866 for (i = 0; i < count; i++)
1867 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
1868 vbo, 0, 16);
1869
1870 return;
1871 }
1872
1873 /* Note that the error semantics for multi-bind commands differ from
1874 * those of other GL commands.
1875 *
1876 * The Issues section in the ARB_multi_bind spec says:
1877 *
1878 * "(11) Typically, OpenGL specifies that if an error is generated by
1879 * a command, that command has no effect. This is somewhat
1880 * unfortunate for multi-bind commands, because it would require
1881 * a first pass to scan the entire list of bound objects for
1882 * errors and then a second pass to actually perform the
1883 * bindings. Should we have different error semantics?
1884 *
1885 * RESOLVED: Yes. In this specification, when the parameters for
1886 * one of the <count> binding points are invalid, that binding
1887 * point is not updated and an error will be generated. However,
1888 * other binding points in the same command will be updated if
1889 * their parameters are valid and no other error occurs."
1890 */
1891
1892 _mesa_begin_bufferobj_lookups(ctx);
1893
1894 for (i = 0; i < count; i++) {
1895 struct gl_buffer_object *vbo;
1896
1897 /* The ARB_multi_bind spec says:
1898 *
1899 * "An INVALID_VALUE error is generated if any value in
1900 * <offsets> or <strides> is negative (per binding)."
1901 */
1902 if (offsets[i] < 0) {
1903 _mesa_error(ctx, GL_INVALID_VALUE,
1904 "%s(offsets[%u]=%" PRId64 " < 0)",
1905 func, i, (int64_t) offsets[i]);
1906 continue;
1907 }
1908
1909 if (strides[i] < 0) {
1910 _mesa_error(ctx, GL_INVALID_VALUE,
1911 "%s(strides[%u]=%d < 0)",
1912 func, i, strides[i]);
1913 continue;
1914 }
1915
1916 if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 &&
1917 strides[i] > ctx->Const.MaxVertexAttribStride) {
1918 _mesa_error(ctx, GL_INVALID_VALUE,
1919 "%s(strides[%u]=%d > "
1920 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, i, strides[i]);
1921 continue;
1922 }
1923
1924 if (buffers[i]) {
1925 struct gl_vertex_buffer_binding *binding =
1926 &vao->BufferBinding[VERT_ATTRIB_GENERIC(first + i)];
1927
1928 if (buffers[i] == binding->BufferObj->Name)
1929 vbo = binding->BufferObj;
1930 else
1931 vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, func);
1932
1933 if (!vbo)
1934 continue;
1935 } else {
1936 vbo = ctx->Shared->NullBufferObj;
1937 }
1938
1939 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
1940 vbo, offsets[i], strides[i]);
1941 }
1942
1943 _mesa_end_bufferobj_lookups(ctx);
1944 }
1945
1946
1947 void GLAPIENTRY
1948 _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
1949 const GLintptr *offsets, const GLsizei *strides)
1950 {
1951 GET_CURRENT_CONTEXT(ctx);
1952
1953 /* The ARB_vertex_attrib_binding spec says:
1954 *
1955 * "An INVALID_OPERATION error is generated if no
1956 * vertex array object is bound."
1957 */
1958 if (ctx->API == API_OPENGL_CORE &&
1959 ctx->Array.VAO == ctx->Array.DefaultVAO) {
1960 _mesa_error(ctx, GL_INVALID_OPERATION,
1961 "glBindVertexBuffers(No array object bound)");
1962 return;
1963 }
1964
1965 vertex_array_vertex_buffers(ctx, ctx->Array.VAO, first, count,
1966 buffers, offsets, strides,
1967 "glBindVertexBuffers");
1968 }
1969
1970
1971 void GLAPIENTRY
1972 _mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count,
1973 const GLuint *buffers,
1974 const GLintptr *offsets, const GLsizei *strides)
1975 {
1976 GET_CURRENT_CONTEXT(ctx);
1977 struct gl_vertex_array_object *vao;
1978
1979 /* The ARB_direct_state_access specification says:
1980 *
1981 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1982 * if <vaobj> is not [compatibility profile: zero or] the name of an
1983 * existing vertex array object."
1984 */
1985 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayVertexBuffers");
1986 if (!vao)
1987 return;
1988
1989 vertex_array_vertex_buffers(ctx, vao, first, count,
1990 buffers, offsets, strides,
1991 "glVertexArrayVertexBuffers");
1992 }
1993
1994
1995 static void
1996 vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type,
1997 GLboolean normalized, GLboolean integer,
1998 GLboolean doubles, GLbitfield legalTypes,
1999 GLsizei maxSize, GLuint relativeOffset,
2000 const char *func)
2001 {
2002 GET_CURRENT_CONTEXT(ctx);
2003 ASSERT_OUTSIDE_BEGIN_END(ctx);
2004
2005 /* The ARB_vertex_attrib_binding spec says:
2006 *
2007 * "An INVALID_OPERATION error is generated under any of the following
2008 * conditions:
2009 * - if no vertex array object is currently bound (see section 2.10);
2010 * - ..."
2011 *
2012 * This error condition only applies to VertexAttribFormat and
2013 * VertexAttribIFormat in the extension spec, but we assume that this
2014 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2015 * to all three functions.
2016 */
2017 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2018 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2019 _mesa_error(ctx, GL_INVALID_OPERATION,
2020 "%s(No array object bound)", func);
2021 return;
2022 }
2023
2024 /* The ARB_vertex_attrib_binding spec says:
2025 *
2026 * "The error INVALID_VALUE is generated if index is greater than or equal
2027 * to the value of MAX_VERTEX_ATTRIBS."
2028 */
2029 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2030 _mesa_error(ctx, GL_INVALID_VALUE,
2031 "%s(attribindex=%u > "
2032 "GL_MAX_VERTEX_ATTRIBS)",
2033 func, attribIndex);
2034 return;
2035 }
2036
2037 FLUSH_VERTICES(ctx, 0);
2038
2039 update_array_format(ctx, func, ctx->Array.VAO,
2040 VERT_ATTRIB_GENERIC(attribIndex),
2041 legalTypes, 1, maxSize, size, type,
2042 normalized, integer, doubles, relativeOffset);
2043 }
2044
2045
2046 void GLAPIENTRY
2047 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
2048 GLboolean normalized, GLuint relativeOffset)
2049 {
2050 vertex_attrib_format(attribIndex, size, type, normalized,
2051 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
2052 BGRA_OR_4, relativeOffset,
2053 "glVertexAttribFormat");
2054 }
2055
2056
2057 void GLAPIENTRY
2058 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
2059 GLuint relativeOffset)
2060 {
2061 vertex_attrib_format(attribIndex, size, type, GL_FALSE,
2062 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK, 4,
2063 relativeOffset, "glVertexAttribIFormat");
2064 }
2065
2066
2067 void GLAPIENTRY
2068 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
2069 GLuint relativeOffset)
2070 {
2071 vertex_attrib_format(attribIndex, size, type, GL_FALSE, GL_FALSE,
2072 GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK, 4,
2073 relativeOffset, "glVertexAttribLFormat");
2074 }
2075
2076
2077 static void
2078 vertex_array_attrib_format(GLuint vaobj, GLuint attribIndex, GLint size,
2079 GLenum type, GLboolean normalized,
2080 GLboolean integer, GLboolean doubles,
2081 GLbitfield legalTypes, GLsizei maxSize,
2082 GLuint relativeOffset, const char *func)
2083 {
2084 GET_CURRENT_CONTEXT(ctx);
2085 struct gl_vertex_array_object *vao;
2086
2087 ASSERT_OUTSIDE_BEGIN_END(ctx);
2088
2089 /* The ARB_direct_state_access spec says:
2090 *
2091 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
2092 * if <vaobj> is not [compatibility profile: zero or] the name of an
2093 * existing vertex array object."
2094 */
2095 vao = _mesa_lookup_vao_err(ctx, vaobj, func);
2096 if (!vao)
2097 return;
2098
2099 /* The ARB_vertex_attrib_binding spec says:
2100 *
2101 * "The error INVALID_VALUE is generated if index is greater than or equal
2102 * to the value of MAX_VERTEX_ATTRIBS."
2103 */
2104 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2105 _mesa_error(ctx, GL_INVALID_VALUE,
2106 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2107 func, attribIndex);
2108 return;
2109 }
2110
2111 FLUSH_VERTICES(ctx, 0);
2112
2113 update_array_format(ctx, func, vao,
2114 VERT_ATTRIB_GENERIC(attribIndex),
2115 legalTypes, 1, maxSize, size, type, normalized,
2116 integer, doubles, relativeOffset);
2117 }
2118
2119
2120 void GLAPIENTRY
2121 _mesa_VertexArrayAttribFormat(GLuint vaobj, GLuint attribIndex, GLint size,
2122 GLenum type, GLboolean normalized,
2123 GLuint relativeOffset)
2124 {
2125 vertex_array_attrib_format(vaobj, attribIndex, size, type, normalized,
2126 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
2127 BGRA_OR_4, relativeOffset,
2128 "glVertexArrayAttribFormat");
2129 }
2130
2131
2132 void GLAPIENTRY
2133 _mesa_VertexArrayAttribIFormat(GLuint vaobj, GLuint attribIndex,
2134 GLint size, GLenum type,
2135 GLuint relativeOffset)
2136 {
2137 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2138 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK,
2139 4, relativeOffset,
2140 "glVertexArrayAttribIFormat");
2141 }
2142
2143
2144 void GLAPIENTRY
2145 _mesa_VertexArrayAttribLFormat(GLuint vaobj, GLuint attribIndex,
2146 GLint size, GLenum type,
2147 GLuint relativeOffset)
2148 {
2149 vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE,
2150 GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK,
2151 4, relativeOffset,
2152 "glVertexArrayAttribLFormat");
2153 }
2154
2155
2156 static void
2157 vertex_array_attrib_binding(struct gl_context *ctx,
2158 struct gl_vertex_array_object *vao,
2159 GLuint attribIndex, GLuint bindingIndex,
2160 const char *func)
2161 {
2162 ASSERT_OUTSIDE_BEGIN_END(ctx);
2163
2164 /* The ARB_vertex_attrib_binding spec says:
2165 *
2166 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2167 * <bindingindex> must be less than the value of
2168 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2169 * is generated."
2170 */
2171 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2172 _mesa_error(ctx, GL_INVALID_VALUE,
2173 "%s(attribindex=%u >= "
2174 "GL_MAX_VERTEX_ATTRIBS)",
2175 func, attribIndex);
2176 return;
2177 }
2178
2179 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2180 _mesa_error(ctx, GL_INVALID_VALUE,
2181 "%s(bindingindex=%u >= "
2182 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2183 func, bindingIndex);
2184 return;
2185 }
2186
2187 assert(VERT_ATTRIB_GENERIC(attribIndex) < ARRAY_SIZE(vao->VertexAttrib));
2188
2189 vertex_attrib_binding(ctx, vao,
2190 VERT_ATTRIB_GENERIC(attribIndex),
2191 VERT_ATTRIB_GENERIC(bindingIndex));
2192 }
2193
2194
2195 void GLAPIENTRY
2196 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
2197 {
2198 GET_CURRENT_CONTEXT(ctx);
2199
2200 /* The ARB_vertex_attrib_binding spec says:
2201 *
2202 * "An INVALID_OPERATION error is generated if no vertex array object
2203 * is bound."
2204 */
2205 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2206 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2207 _mesa_error(ctx, GL_INVALID_OPERATION,
2208 "glVertexAttribBinding(No array object bound)");
2209 return;
2210 }
2211
2212 vertex_array_attrib_binding(ctx, ctx->Array.VAO,
2213 attribIndex, bindingIndex,
2214 "glVertexAttribBinding");
2215 }
2216
2217
2218 void GLAPIENTRY
2219 _mesa_VertexArrayAttribBinding(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex)
2220 {
2221 GET_CURRENT_CONTEXT(ctx);
2222 struct gl_vertex_array_object *vao;
2223
2224 /* The ARB_direct_state_access specification says:
2225 *
2226 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2227 * if <vaobj> is not [compatibility profile: zero or] the name of an
2228 * existing vertex array object."
2229 */
2230 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayAttribBinding");
2231 if (!vao)
2232 return;
2233
2234 vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex,
2235 "glVertexArrayAttribBinding");
2236 }
2237
2238
2239 static void
2240 vertex_array_binding_divisor(struct gl_context *ctx,
2241 struct gl_vertex_array_object *vao,
2242 GLuint bindingIndex, GLuint divisor,
2243 const char *func)
2244 {
2245 ASSERT_OUTSIDE_BEGIN_END(ctx);
2246
2247 if (!ctx->Extensions.ARB_instanced_arrays) {
2248 _mesa_error(ctx, GL_INVALID_OPERATION, "%s()", func);
2249 return;
2250 }
2251
2252 /* The ARB_vertex_attrib_binding spec says:
2253 *
2254 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2255 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2256 */
2257 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2258 _mesa_error(ctx, GL_INVALID_VALUE,
2259 "%s(bindingindex=%u > "
2260 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2261 func, bindingIndex);
2262 return;
2263 }
2264
2265 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
2266 }
2267
2268
2269 void GLAPIENTRY
2270 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
2271 {
2272 GET_CURRENT_CONTEXT(ctx);
2273
2274 /* The ARB_vertex_attrib_binding spec says:
2275 *
2276 * "An INVALID_OPERATION error is generated if no vertex array object
2277 * is bound."
2278 */
2279 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
2280 ctx->Array.VAO == ctx->Array.DefaultVAO) {
2281 _mesa_error(ctx, GL_INVALID_OPERATION,
2282 "glVertexBindingDivisor(No array object bound)");
2283 return;
2284 }
2285
2286 vertex_array_binding_divisor(ctx, ctx->Array.VAO,
2287 bindingIndex, divisor,
2288 "glVertexBindingDivisor");
2289 }
2290
2291
2292 void GLAPIENTRY
2293 _mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex,
2294 GLuint divisor)
2295 {
2296 struct gl_vertex_array_object *vao;
2297 GET_CURRENT_CONTEXT(ctx);
2298
2299 /* The ARB_direct_state_access specification says:
2300 *
2301 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2302 * if <vaobj> is not [compatibility profile: zero or] the name of an
2303 * existing vertex array object."
2304 */
2305 vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayBindingDivisor");
2306 if (!vao)
2307 return;
2308
2309 vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor,
2310 "glVertexArrayBindingDivisor");
2311 }
2312
2313
2314 /**
2315 * Copy one client vertex array to another.
2316 */
2317 void
2318 _mesa_copy_client_array(struct gl_context *ctx,
2319 struct gl_vertex_array *dst,
2320 struct gl_vertex_array *src)
2321 {
2322 dst->Size = src->Size;
2323 dst->Type = src->Type;
2324 dst->Format = src->Format;
2325 dst->StrideB = src->StrideB;
2326 dst->Ptr = src->Ptr;
2327 dst->Normalized = src->Normalized;
2328 dst->Integer = src->Integer;
2329 dst->Doubles = src->Doubles;
2330 dst->InstanceDivisor = src->InstanceDivisor;
2331 dst->_ElementSize = src->_ElementSize;
2332 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
2333 }
2334
2335 void
2336 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
2337 struct gl_array_attributes *dst,
2338 const struct gl_array_attributes *src)
2339 {
2340 dst->Size = src->Size;
2341 dst->Type = src->Type;
2342 dst->Format = src->Format;
2343 dst->BufferBindingIndex = src->BufferBindingIndex;
2344 dst->RelativeOffset = src->RelativeOffset;
2345 dst->Format = src->Format;
2346 dst->Integer = src->Integer;
2347 dst->Doubles = src->Doubles;
2348 dst->Normalized = src->Normalized;
2349 dst->Ptr = src->Ptr;
2350 dst->Enabled = src->Enabled;
2351 dst->_ElementSize = src->_ElementSize;
2352 }
2353
2354 void
2355 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
2356 struct gl_vertex_buffer_binding *dst,
2357 const struct gl_vertex_buffer_binding *src)
2358 {
2359 dst->Offset = src->Offset;
2360 dst->Stride = src->Stride;
2361 dst->InstanceDivisor = src->InstanceDivisor;
2362 dst->_BoundArrays = src->_BoundArrays;
2363
2364 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
2365 }
2366
2367 /**
2368 * Print current vertex object/array info. For debug.
2369 */
2370 void
2371 _mesa_print_arrays(struct gl_context *ctx)
2372 {
2373 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
2374
2375 fprintf(stderr, "Array Object %u\n", vao->Name);
2376
2377 unsigned i;
2378 for (i = 0; i < VERT_ATTRIB_MAX; ++i) {
2379 const struct gl_array_attributes *array = &vao->VertexAttrib[i];
2380 if (!array->Enabled)
2381 continue;
2382
2383 const struct gl_vertex_buffer_binding *binding =
2384 &vao->BufferBinding[array->BufferBindingIndex];
2385 const struct gl_buffer_object *bo = binding->BufferObj;
2386
2387 fprintf(stderr, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2388 "Stride=%d, Buffer=%u(Size %lu)\n",
2389 gl_vert_attrib_name((gl_vert_attrib)i),
2390 array->Ptr, _mesa_enum_to_string(array->Type), array->Size,
2391 array->_ElementSize, binding->Stride, bo->Name,
2392 (unsigned long) bo->Size);
2393 }
2394 }
2395
2396
2397 /**
2398 * Initialize vertex array state for given context.
2399 */
2400 void
2401 _mesa_init_varray(struct gl_context *ctx)
2402 {
2403 ctx->Array.DefaultVAO = _mesa_new_vao(ctx, 0);
2404 _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO);
2405 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
2406
2407 ctx->Array.Objects = _mesa_NewHashTable();
2408 }
2409
2410
2411 /**
2412 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2413 */
2414 static void
2415 delete_arrayobj_cb(GLuint id, void *data, void *userData)
2416 {
2417 struct gl_vertex_array_object *vao = (struct gl_vertex_array_object *) data;
2418 struct gl_context *ctx = (struct gl_context *) userData;
2419 _mesa_delete_vao(ctx, vao);
2420 }
2421
2422
2423 /**
2424 * Free vertex array state for given context.
2425 */
2426 void
2427 _mesa_free_varray_data(struct gl_context *ctx)
2428 {
2429 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
2430 _mesa_DeleteHashTable(ctx->Array.Objects);
2431 }