mesa: don't ever set NullBufferObj in gl_vertex_array_binding
[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 "util/imports.h"
32 #include "bufferobj.h"
33 #include "context.h"
34 #include "enable.h"
35 #include "enums.h"
36 #include "glformats.h"
37 #include "hash.h"
38 #include "image.h"
39 #include "macros.h"
40 #include "mtypes.h"
41 #include "varray.h"
42 #include "arrayobj.h"
43 #include "get.h"
44 #include "main/dispatch.h"
45
46
47 /** Used to do error checking for GL_EXT_vertex_array_bgra */
48 #define BGRA_OR_4 5
49
50
51 /** Used to indicate which GL datatypes are accepted by each of the
52 * glVertex/Color/Attrib/EtcPointer() functions.
53 */
54 #define BOOL_BIT (1 << 0)
55 #define BYTE_BIT (1 << 1)
56 #define UNSIGNED_BYTE_BIT (1 << 2)
57 #define SHORT_BIT (1 << 3)
58 #define UNSIGNED_SHORT_BIT (1 << 4)
59 #define INT_BIT (1 << 5)
60 #define UNSIGNED_INT_BIT (1 << 6)
61 #define HALF_BIT (1 << 7)
62 #define FLOAT_BIT (1 << 8)
63 #define DOUBLE_BIT (1 << 9)
64 #define FIXED_ES_BIT (1 << 10)
65 #define FIXED_GL_BIT (1 << 11)
66 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
67 #define INT_2_10_10_10_REV_BIT (1 << 13)
68 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
69 #define ALL_TYPE_BITS ((1 << 15) - 1)
70
71 #define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
72 SHORT_BIT | UNSIGNED_SHORT_BIT | \
73 INT_BIT | UNSIGNED_INT_BIT | \
74 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
75 FIXED_GL_BIT | \
76 UNSIGNED_INT_2_10_10_10_REV_BIT | \
77 INT_2_10_10_10_REV_BIT | \
78 UNSIGNED_INT_10F_11F_11F_REV_BIT)
79
80 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
81 SHORT_BIT | UNSIGNED_SHORT_BIT | \
82 INT_BIT | UNSIGNED_INT_BIT)
83
84 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
85
86
87 /** Convert GL datatype enum into a <type>_BIT value seen above */
88 static GLbitfield
89 type_to_bit(const struct gl_context *ctx, GLenum type)
90 {
91 switch (type) {
92 case GL_BOOL:
93 return BOOL_BIT;
94 case GL_BYTE:
95 return BYTE_BIT;
96 case GL_UNSIGNED_BYTE:
97 return UNSIGNED_BYTE_BIT;
98 case GL_SHORT:
99 return SHORT_BIT;
100 case GL_UNSIGNED_SHORT:
101 return UNSIGNED_SHORT_BIT;
102 case GL_INT:
103 return INT_BIT;
104 case GL_UNSIGNED_INT:
105 return UNSIGNED_INT_BIT;
106 case GL_HALF_FLOAT:
107 case GL_HALF_FLOAT_OES:
108 if (ctx->Extensions.ARB_half_float_vertex)
109 return HALF_BIT;
110 else
111 return 0x0;
112 case GL_FLOAT:
113 return FLOAT_BIT;
114 case GL_DOUBLE:
115 return DOUBLE_BIT;
116 case GL_FIXED:
117 return _mesa_is_desktop_gl(ctx) ? FIXED_GL_BIT : FIXED_ES_BIT;
118 case GL_UNSIGNED_INT_2_10_10_10_REV:
119 return UNSIGNED_INT_2_10_10_10_REV_BIT;
120 case GL_INT_2_10_10_10_REV:
121 return INT_2_10_10_10_REV_BIT;
122 case GL_UNSIGNED_INT_10F_11F_11F_REV:
123 return UNSIGNED_INT_10F_11F_11F_REV_BIT;
124 default:
125 return 0;
126 }
127 }
128
129
130 /**
131 * Depending on the position and generic0 attributes enable flags select
132 * the one that is used for both attributes.
133 * The generic0 attribute takes precedence.
134 */
135 static inline void
136 update_attribute_map_mode(const struct gl_context *ctx,
137 struct gl_vertex_array_object *vao)
138 {
139 /*
140 * There is no need to change the mapping away from the
141 * identity mapping if we are not in compat mode.
142 */
143 if (ctx->API != API_OPENGL_COMPAT)
144 return;
145 /* The generic0 attribute superseeds the position attribute */
146 const GLbitfield enabled = vao->Enabled;
147 if (enabled & VERT_BIT_GENERIC0)
148 vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_GENERIC0;
149 else if (enabled & VERT_BIT_POS)
150 vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_POSITION;
151 else
152 vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_IDENTITY;
153 }
154
155
156 /**
157 * Sets the BufferBindingIndex field for the vertex attribute given by
158 * attribIndex.
159 */
160 void
161 _mesa_vertex_attrib_binding(struct gl_context *ctx,
162 struct gl_vertex_array_object *vao,
163 gl_vert_attrib attribIndex,
164 GLuint bindingIndex)
165 {
166 struct gl_array_attributes *array = &vao->VertexAttrib[attribIndex];
167 assert(!vao->SharedAndImmutable);
168
169 if (array->BufferBindingIndex != bindingIndex) {
170 const GLbitfield array_bit = VERT_BIT(attribIndex);
171
172 if (_mesa_is_bufferobj(vao->BufferBinding[bindingIndex].BufferObj))
173 vao->VertexAttribBufferMask |= array_bit;
174 else
175 vao->VertexAttribBufferMask &= ~array_bit;
176
177 if (vao->BufferBinding[bindingIndex].InstanceDivisor)
178 vao->NonZeroDivisorMask |= array_bit;
179 else
180 vao->NonZeroDivisorMask &= ~array_bit;
181
182 vao->BufferBinding[array->BufferBindingIndex]._BoundArrays &= ~array_bit;
183 vao->BufferBinding[bindingIndex]._BoundArrays |= array_bit;
184
185 array->BufferBindingIndex = bindingIndex;
186
187 vao->NewArrays |= vao->Enabled & array_bit;
188 }
189 }
190
191
192 /**
193 * Binds a buffer object to the vertex buffer binding point given by index,
194 * and sets the Offset and Stride fields.
195 */
196 void
197 _mesa_bind_vertex_buffer(struct gl_context *ctx,
198 struct gl_vertex_array_object *vao,
199 GLuint index,
200 struct gl_buffer_object *vbo,
201 GLintptr offset, GLsizei stride)
202 {
203 assert(index < ARRAY_SIZE(vao->BufferBinding));
204 assert(!vao->SharedAndImmutable);
205 struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index];
206
207 assert(vbo != ctx->Shared->NullBufferObj);
208
209 if (ctx->Const.VertexBufferOffsetIsInt32 && (int)offset < 0 &&
210 _mesa_is_bufferobj(vbo)) {
211 /* The offset will be interpreted as a signed int, so make sure
212 * the user supplied offset is not negative (driver limitation).
213 */
214 _mesa_warning(ctx, "Received negative int32 vertex buffer offset. "
215 "(driver limitation)\n");
216
217 /* We can't disable this binding, so use a non-negative offset value
218 * instead.
219 */
220 offset = 0;
221 }
222
223 if (binding->BufferObj != vbo ||
224 binding->Offset != offset ||
225 binding->Stride != stride) {
226
227 _mesa_reference_buffer_object(ctx, &binding->BufferObj, vbo);
228
229 binding->Offset = offset;
230 binding->Stride = stride;
231
232 if (!_mesa_is_bufferobj(vbo)) {
233 vao->VertexAttribBufferMask &= ~binding->_BoundArrays;
234 } else {
235 vao->VertexAttribBufferMask |= binding->_BoundArrays;
236 vbo->UsageHistory |= USAGE_ARRAY_BUFFER;
237 }
238
239 vao->NewArrays |= vao->Enabled & binding->_BoundArrays;
240 }
241 }
242
243
244 /**
245 * Sets the InstanceDivisor field in the vertex buffer binding point
246 * given by bindingIndex.
247 */
248 static void
249 vertex_binding_divisor(struct gl_context *ctx,
250 struct gl_vertex_array_object *vao,
251 GLuint bindingIndex,
252 GLuint divisor)
253 {
254 struct gl_vertex_buffer_binding *binding =
255 &vao->BufferBinding[bindingIndex];
256 assert(!vao->SharedAndImmutable);
257
258 if (binding->InstanceDivisor != divisor) {
259 binding->InstanceDivisor = divisor;
260
261 if (divisor)
262 vao->NonZeroDivisorMask |= binding->_BoundArrays;
263 else
264 vao->NonZeroDivisorMask &= ~binding->_BoundArrays;
265
266 vao->NewArrays |= vao->Enabled & binding->_BoundArrays;
267 }
268 }
269
270 /* vertex_formats[gltype - GL_BYTE][integer*2 + normalized][size - 1] */
271 static const uint16_t vertex_formats[][4][4] = {
272 { /* GL_BYTE */
273 {
274 PIPE_FORMAT_R8_SSCALED,
275 PIPE_FORMAT_R8G8_SSCALED,
276 PIPE_FORMAT_R8G8B8_SSCALED,
277 PIPE_FORMAT_R8G8B8A8_SSCALED
278 },
279 {
280 PIPE_FORMAT_R8_SNORM,
281 PIPE_FORMAT_R8G8_SNORM,
282 PIPE_FORMAT_R8G8B8_SNORM,
283 PIPE_FORMAT_R8G8B8A8_SNORM
284 },
285 {
286 PIPE_FORMAT_R8_SINT,
287 PIPE_FORMAT_R8G8_SINT,
288 PIPE_FORMAT_R8G8B8_SINT,
289 PIPE_FORMAT_R8G8B8A8_SINT
290 },
291 },
292 { /* GL_UNSIGNED_BYTE */
293 {
294 PIPE_FORMAT_R8_USCALED,
295 PIPE_FORMAT_R8G8_USCALED,
296 PIPE_FORMAT_R8G8B8_USCALED,
297 PIPE_FORMAT_R8G8B8A8_USCALED
298 },
299 {
300 PIPE_FORMAT_R8_UNORM,
301 PIPE_FORMAT_R8G8_UNORM,
302 PIPE_FORMAT_R8G8B8_UNORM,
303 PIPE_FORMAT_R8G8B8A8_UNORM
304 },
305 {
306 PIPE_FORMAT_R8_UINT,
307 PIPE_FORMAT_R8G8_UINT,
308 PIPE_FORMAT_R8G8B8_UINT,
309 PIPE_FORMAT_R8G8B8A8_UINT
310 },
311 },
312 { /* GL_SHORT */
313 {
314 PIPE_FORMAT_R16_SSCALED,
315 PIPE_FORMAT_R16G16_SSCALED,
316 PIPE_FORMAT_R16G16B16_SSCALED,
317 PIPE_FORMAT_R16G16B16A16_SSCALED
318 },
319 {
320 PIPE_FORMAT_R16_SNORM,
321 PIPE_FORMAT_R16G16_SNORM,
322 PIPE_FORMAT_R16G16B16_SNORM,
323 PIPE_FORMAT_R16G16B16A16_SNORM
324 },
325 {
326 PIPE_FORMAT_R16_SINT,
327 PIPE_FORMAT_R16G16_SINT,
328 PIPE_FORMAT_R16G16B16_SINT,
329 PIPE_FORMAT_R16G16B16A16_SINT
330 },
331 },
332 { /* GL_UNSIGNED_SHORT */
333 {
334 PIPE_FORMAT_R16_USCALED,
335 PIPE_FORMAT_R16G16_USCALED,
336 PIPE_FORMAT_R16G16B16_USCALED,
337 PIPE_FORMAT_R16G16B16A16_USCALED
338 },
339 {
340 PIPE_FORMAT_R16_UNORM,
341 PIPE_FORMAT_R16G16_UNORM,
342 PIPE_FORMAT_R16G16B16_UNORM,
343 PIPE_FORMAT_R16G16B16A16_UNORM
344 },
345 {
346 PIPE_FORMAT_R16_UINT,
347 PIPE_FORMAT_R16G16_UINT,
348 PIPE_FORMAT_R16G16B16_UINT,
349 PIPE_FORMAT_R16G16B16A16_UINT
350 },
351 },
352 { /* GL_INT */
353 {
354 PIPE_FORMAT_R32_SSCALED,
355 PIPE_FORMAT_R32G32_SSCALED,
356 PIPE_FORMAT_R32G32B32_SSCALED,
357 PIPE_FORMAT_R32G32B32A32_SSCALED
358 },
359 {
360 PIPE_FORMAT_R32_SNORM,
361 PIPE_FORMAT_R32G32_SNORM,
362 PIPE_FORMAT_R32G32B32_SNORM,
363 PIPE_FORMAT_R32G32B32A32_SNORM
364 },
365 {
366 PIPE_FORMAT_R32_SINT,
367 PIPE_FORMAT_R32G32_SINT,
368 PIPE_FORMAT_R32G32B32_SINT,
369 PIPE_FORMAT_R32G32B32A32_SINT
370 },
371 },
372 { /* GL_UNSIGNED_INT */
373 {
374 PIPE_FORMAT_R32_USCALED,
375 PIPE_FORMAT_R32G32_USCALED,
376 PIPE_FORMAT_R32G32B32_USCALED,
377 PIPE_FORMAT_R32G32B32A32_USCALED
378 },
379 {
380 PIPE_FORMAT_R32_UNORM,
381 PIPE_FORMAT_R32G32_UNORM,
382 PIPE_FORMAT_R32G32B32_UNORM,
383 PIPE_FORMAT_R32G32B32A32_UNORM
384 },
385 {
386 PIPE_FORMAT_R32_UINT,
387 PIPE_FORMAT_R32G32_UINT,
388 PIPE_FORMAT_R32G32B32_UINT,
389 PIPE_FORMAT_R32G32B32A32_UINT
390 },
391 },
392 { /* GL_FLOAT */
393 {
394 PIPE_FORMAT_R32_FLOAT,
395 PIPE_FORMAT_R32G32_FLOAT,
396 PIPE_FORMAT_R32G32B32_FLOAT,
397 PIPE_FORMAT_R32G32B32A32_FLOAT
398 },
399 {
400 PIPE_FORMAT_R32_FLOAT,
401 PIPE_FORMAT_R32G32_FLOAT,
402 PIPE_FORMAT_R32G32B32_FLOAT,
403 PIPE_FORMAT_R32G32B32A32_FLOAT
404 },
405 },
406 {{0}}, /* GL_2_BYTES */
407 {{0}}, /* GL_3_BYTES */
408 {{0}}, /* GL_4_BYTES */
409 { /* GL_DOUBLE */
410 {
411 PIPE_FORMAT_R64_FLOAT,
412 PIPE_FORMAT_R64G64_FLOAT,
413 PIPE_FORMAT_R64G64B64_FLOAT,
414 PIPE_FORMAT_R64G64B64A64_FLOAT
415 },
416 {
417 PIPE_FORMAT_R64_FLOAT,
418 PIPE_FORMAT_R64G64_FLOAT,
419 PIPE_FORMAT_R64G64B64_FLOAT,
420 PIPE_FORMAT_R64G64B64A64_FLOAT
421 },
422 },
423 { /* GL_HALF_FLOAT */
424 {
425 PIPE_FORMAT_R16_FLOAT,
426 PIPE_FORMAT_R16G16_FLOAT,
427 PIPE_FORMAT_R16G16B16_FLOAT,
428 PIPE_FORMAT_R16G16B16A16_FLOAT
429 },
430 {
431 PIPE_FORMAT_R16_FLOAT,
432 PIPE_FORMAT_R16G16_FLOAT,
433 PIPE_FORMAT_R16G16B16_FLOAT,
434 PIPE_FORMAT_R16G16B16A16_FLOAT
435 },
436 },
437 { /* GL_FIXED */
438 {
439 PIPE_FORMAT_R32_FIXED,
440 PIPE_FORMAT_R32G32_FIXED,
441 PIPE_FORMAT_R32G32B32_FIXED,
442 PIPE_FORMAT_R32G32B32A32_FIXED
443 },
444 {
445 PIPE_FORMAT_R32_FIXED,
446 PIPE_FORMAT_R32G32_FIXED,
447 PIPE_FORMAT_R32G32B32_FIXED,
448 PIPE_FORMAT_R32G32B32A32_FIXED
449 },
450 },
451 };
452
453 /**
454 * Return a PIPE_FORMAT_x for the given GL datatype and size.
455 */
456 static enum pipe_format
457 vertex_format_to_pipe_format(GLubyte size, GLenum16 type, GLenum16 format,
458 GLboolean normalized, GLboolean integer,
459 GLboolean doubles)
460 {
461 assert(size >= 1 && size <= 4);
462 assert(format == GL_RGBA || format == GL_BGRA);
463
464 /* 64-bit attributes are translated by drivers. */
465 if (doubles)
466 return PIPE_FORMAT_NONE;
467
468 switch (type) {
469 case GL_HALF_FLOAT_OES:
470 type = GL_HALF_FLOAT;
471 break;
472
473 case GL_INT_2_10_10_10_REV:
474 assert(size == 4 && !integer);
475
476 if (format == GL_BGRA) {
477 if (normalized)
478 return PIPE_FORMAT_B10G10R10A2_SNORM;
479 else
480 return PIPE_FORMAT_B10G10R10A2_SSCALED;
481 } else {
482 if (normalized)
483 return PIPE_FORMAT_R10G10B10A2_SNORM;
484 else
485 return PIPE_FORMAT_R10G10B10A2_SSCALED;
486 }
487 break;
488
489 case GL_UNSIGNED_INT_2_10_10_10_REV:
490 assert(size == 4 && !integer);
491
492 if (format == GL_BGRA) {
493 if (normalized)
494 return PIPE_FORMAT_B10G10R10A2_UNORM;
495 else
496 return PIPE_FORMAT_B10G10R10A2_USCALED;
497 } else {
498 if (normalized)
499 return PIPE_FORMAT_R10G10B10A2_UNORM;
500 else
501 return PIPE_FORMAT_R10G10B10A2_USCALED;
502 }
503 break;
504
505 case GL_UNSIGNED_INT_10F_11F_11F_REV:
506 assert(size == 3 && !integer && format == GL_RGBA);
507 return PIPE_FORMAT_R11G11B10_FLOAT;
508
509 case GL_UNSIGNED_BYTE:
510 if (format == GL_BGRA) {
511 /* this is an odd-ball case */
512 assert(normalized);
513 return PIPE_FORMAT_B8G8R8A8_UNORM;
514 }
515 break;
516 }
517
518 unsigned index = integer*2 + normalized;
519 assert(index <= 2);
520 assert(type >= GL_BYTE && type <= GL_FIXED);
521 return vertex_formats[type - GL_BYTE][index][size-1];
522 }
523
524 void
525 _mesa_set_vertex_format(struct gl_vertex_format *vertex_format,
526 GLubyte size, GLenum16 type, GLenum16 format,
527 GLboolean normalized, GLboolean integer,
528 GLboolean doubles)
529 {
530 assert(size <= 4);
531 vertex_format->Type = type;
532 vertex_format->Format = format;
533 vertex_format->Size = size;
534 vertex_format->Normalized = normalized;
535 vertex_format->Integer = integer;
536 vertex_format->Doubles = doubles;
537 vertex_format->_ElementSize = _mesa_bytes_per_vertex_attrib(size, type);
538 assert(vertex_format->_ElementSize <= 4*sizeof(double));
539 vertex_format->_PipeFormat =
540 vertex_format_to_pipe_format(size, type, format, normalized, integer,
541 doubles);
542 }
543
544
545 /**
546 * Examine the API profile and extensions to determine which types are legal
547 * for vertex arrays. This is called once from update_array_format().
548 */
549 static GLbitfield
550 get_legal_types_mask(const struct gl_context *ctx)
551 {
552 GLbitfield legalTypesMask = ALL_TYPE_BITS;
553
554 if (_mesa_is_gles(ctx)) {
555 legalTypesMask &= ~(FIXED_GL_BIT |
556 DOUBLE_BIT |
557 UNSIGNED_INT_10F_11F_11F_REV_BIT);
558
559 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
560 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
561 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
562 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
563 * quite as trivial as we'd like because it uses a different enum value
564 * for GL_HALF_FLOAT_OES.
565 */
566 if (ctx->Version < 30) {
567 legalTypesMask &= ~(UNSIGNED_INT_BIT |
568 INT_BIT |
569 UNSIGNED_INT_2_10_10_10_REV_BIT |
570 INT_2_10_10_10_REV_BIT);
571
572 if (!_mesa_has_OES_vertex_half_float(ctx))
573 legalTypesMask &= ~HALF_BIT;
574 }
575 }
576 else {
577 legalTypesMask &= ~FIXED_ES_BIT;
578
579 if (!ctx->Extensions.ARB_ES2_compatibility)
580 legalTypesMask &= ~FIXED_GL_BIT;
581
582 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
583 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
584 INT_2_10_10_10_REV_BIT);
585
586 if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev)
587 legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT;
588 }
589
590 return legalTypesMask;
591 }
592
593 static GLenum
594 get_array_format(const struct gl_context *ctx, GLint sizeMax, GLint *size)
595 {
596 GLenum format = GL_RGBA;
597
598 /* Do size parameter checking.
599 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
600 * must be handled specially.
601 */
602 if (ctx->Extensions.EXT_vertex_array_bgra && sizeMax == BGRA_OR_4 &&
603 *size == GL_BGRA) {
604 format = GL_BGRA;
605 *size = 4;
606 }
607
608 return format;
609 }
610
611
612 /**
613 * \param attrib The index of the attribute array
614 * \param size Components per element (1, 2, 3 or 4)
615 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
616 * \param format Either GL_RGBA or GL_BGRA.
617 * \param normalized Whether integer types are converted to floats in [-1, 1]
618 * \param integer Integer-valued values (will not be normalized to [-1, 1])
619 * \param doubles Double values not reduced to floats
620 * \param relativeOffset Offset of the first element relative to the binding
621 * offset.
622 */
623 void
624 _mesa_update_array_format(struct gl_context *ctx,
625 struct gl_vertex_array_object *vao,
626 gl_vert_attrib attrib, GLint size, GLenum type,
627 GLenum format, GLboolean normalized,
628 GLboolean integer, GLboolean doubles,
629 GLuint relativeOffset)
630 {
631 struct gl_array_attributes *const array = &vao->VertexAttrib[attrib];
632
633 assert(!vao->SharedAndImmutable);
634 assert(size <= 4);
635
636 array->RelativeOffset = relativeOffset;
637 _mesa_set_vertex_format(&array->Format, size, type, format,
638 normalized, integer, doubles);
639
640 vao->NewArrays |= vao->Enabled & VERT_BIT(attrib);
641 }
642
643 /**
644 * Does error checking of the format in an attrib array.
645 *
646 * Called by *Pointer() and VertexAttrib*Format().
647 *
648 * \param func Name of calling function used for error reporting
649 * \param attrib The index of the attribute array
650 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
651 * \param sizeMin Min allowable size value
652 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
653 * \param size Components per element (1, 2, 3 or 4)
654 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
655 * \param normalized Whether integer types are converted to floats in [-1, 1]
656 * \param integer Integer-valued values (will not be normalized to [-1, 1])
657 * \param doubles Double values not reduced to floats
658 * \param relativeOffset Offset of the first element relative to the binding offset.
659 * \return bool True if validation is successful, False otherwise.
660 */
661 static bool
662 validate_array_format(struct gl_context *ctx, const char *func,
663 struct gl_vertex_array_object *vao,
664 GLuint attrib, GLbitfield legalTypesMask,
665 GLint sizeMin, GLint sizeMax,
666 GLint size, GLenum type, GLboolean normalized,
667 GLboolean integer, GLboolean doubles,
668 GLuint relativeOffset, GLenum format)
669 {
670 GLbitfield typeBit;
671
672 /* at most, one of these bools can be true */
673 assert((int) normalized + (int) integer + (int) doubles <= 1);
674
675 if (ctx->Array.LegalTypesMask == 0 || ctx->Array.LegalTypesMaskAPI != ctx->API) {
676 /* Compute the LegalTypesMask only once, unless the context API has
677 * changed, in which case we want to compute it again. We can't do this
678 * in _mesa_init_varrays() below because extensions are not yet enabled
679 * at that point.
680 */
681 ctx->Array.LegalTypesMask = get_legal_types_mask(ctx);
682 ctx->Array.LegalTypesMaskAPI = ctx->API;
683 }
684
685 legalTypesMask &= ctx->Array.LegalTypesMask;
686
687 if (_mesa_is_gles(ctx) && sizeMax == BGRA_OR_4) {
688 /* BGRA ordering is not supported in ES contexts.
689 */
690 sizeMax = 4;
691 }
692
693 typeBit = type_to_bit(ctx, type);
694 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
695 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
696 func, _mesa_enum_to_string(type));
697 return false;
698 }
699
700 if (format == GL_BGRA) {
701 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
702 *
703 * "An INVALID_OPERATION error is generated under any of the following
704 * conditions:
705 * ...
706 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
707 * or UNSIGNED_INT_2_10_10_10_REV;
708 * ...
709 * • size is BGRA and normalized is FALSE;"
710 */
711 bool bgra_error = false;
712
713 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
714 if (type != GL_UNSIGNED_INT_2_10_10_10_REV &&
715 type != GL_INT_2_10_10_10_REV &&
716 type != GL_UNSIGNED_BYTE)
717 bgra_error = true;
718 } else if (type != GL_UNSIGNED_BYTE)
719 bgra_error = true;
720
721 if (bgra_error) {
722 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)",
723 func, _mesa_enum_to_string(type));
724 return false;
725 }
726
727 if (!normalized) {
728 _mesa_error(ctx, GL_INVALID_OPERATION,
729 "%s(size=GL_BGRA and normalized=GL_FALSE)", func);
730 return false;
731 }
732 }
733 else if (size < sizeMin || size > sizeMax || size > 4) {
734 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
735 return false;
736 }
737
738 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
739 (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
740 type == GL_INT_2_10_10_10_REV) && size != 4) {
741 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
742 return false;
743 }
744
745 /* The ARB_vertex_attrib_binding_spec says:
746 *
747 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
748 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
749 */
750 if (relativeOffset > ctx->Const.MaxVertexAttribRelativeOffset) {
751 _mesa_error(ctx, GL_INVALID_VALUE,
752 "%s(relativeOffset=%d > "
753 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
754 func, relativeOffset);
755 return false;
756 }
757
758 if (ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev &&
759 type == GL_UNSIGNED_INT_10F_11F_11F_REV && size != 3) {
760 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
761 return false;
762 }
763
764 return true;
765 }
766
767 /**
768 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
769 *
770 * \param func name of calling function used for error reporting
771 * \param vao the vao to update
772 * \param obj the bound buffer object
773 * \param attrib the attribute array index to update
774 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
775 * \param sizeMin min allowable size value
776 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
777 * \param size components per element (1, 2, 3 or 4)
778 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
779 * \param stride stride between elements, in elements
780 * \param normalized are integer types converted to floats in [-1, 1]?
781 * \param integer integer-valued values (will not be normalized to [-1,1])
782 * \param doubles Double values not reduced to floats
783 * \param ptr the address (or offset inside VBO) of the array data
784 */
785 static void
786 validate_array(struct gl_context *ctx, const char *func,
787 struct gl_vertex_array_object *vao,
788 struct gl_buffer_object *obj,
789 GLuint attrib, GLbitfield legalTypesMask,
790 GLint sizeMin, GLint sizeMax,
791 GLint size, GLenum type, GLsizei stride,
792 GLboolean normalized, GLboolean integer, GLboolean doubles,
793 const GLvoid *ptr)
794 {
795 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
796 *
797 * "Client vertex arrays - all vertex array attribute pointers must
798 * refer to buffer objects (section 2.9.2). The default vertex array
799 * object (the name zero) is also deprecated. Calling
800 * VertexAttribPointer when no buffer object or no vertex array object
801 * is bound will generate an INVALID_OPERATION error..."
802 *
803 * The check for VBOs is handled below.
804 */
805 if (ctx->API == API_OPENGL_CORE && (vao == ctx->Array.DefaultVAO)) {
806 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)",
807 func);
808 return;
809 }
810
811 if (stride < 0) {
812 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
813 return;
814 }
815
816 if (_mesa_is_desktop_gl(ctx) && ctx->Version >= 44 &&
817 stride > ctx->Const.MaxVertexAttribStride) {
818 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
819 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
820 return;
821 }
822
823 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
824 *
825 * "An INVALID_OPERATION error is generated under any of the following
826 * conditions:
827 *
828 * ...
829 *
830 * * any of the *Pointer commands specifying the location and
831 * organization of vertex array data are called while zero is bound
832 * to the ARRAY_BUFFER buffer object binding point (see section
833 * 2.9.6), and the pointer argument is not NULL."
834 */
835 if (ptr != NULL && vao != ctx->Array.DefaultVAO &&
836 !_mesa_is_bufferobj(obj)) {
837 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
838 return;
839 }
840 }
841
842
843 static bool
844 validate_array_and_format(struct gl_context *ctx, const char *func,
845 struct gl_vertex_array_object *vao,
846 struct gl_buffer_object *obj,
847 GLuint attrib, GLbitfield legalTypes,
848 GLint sizeMin, GLint sizeMax,
849 GLint size, GLenum type, GLsizei stride,
850 GLboolean normalized, GLboolean integer,
851 GLboolean doubles, GLenum format, const GLvoid *ptr)
852 {
853 validate_array(ctx, func, vao, obj, attrib, legalTypes, sizeMin, sizeMax,
854 size, type, stride, normalized, integer, doubles, ptr);
855
856 return validate_array_format(ctx, func, vao, attrib, legalTypes, sizeMin,
857 sizeMax, size, type, normalized, integer,
858 doubles, 0, format);
859 }
860
861
862 /**
863 * Update state for glVertex/Color/TexCoord/...Pointer functions.
864 *
865 * \param vao the vao to update
866 * \param obj the bound buffer object
867 * \param attrib the attribute array index to update
868 * \param format Either GL_RGBA or GL_BGRA.
869 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
870 * \param size components per element (1, 2, 3 or 4)
871 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
872 * \param stride stride between elements, in elements
873 * \param normalized are integer types converted to floats in [-1, 1]?
874 * \param integer integer-valued values (will not be normalized to [-1,1])
875 * \param doubles Double values not reduced to floats
876 * \param ptr the address (or offset inside VBO) of the array data
877 */
878 static void
879 update_array(struct gl_context *ctx,
880 struct gl_vertex_array_object *vao,
881 struct gl_buffer_object *obj,
882 GLuint attrib, GLenum format,
883 GLint sizeMax,
884 GLint size, GLenum type, GLsizei stride,
885 GLboolean normalized, GLboolean integer, GLboolean doubles,
886 const GLvoid *ptr)
887 {
888 _mesa_update_array_format(ctx, vao, attrib, size, type, format,
889 normalized, integer, doubles, 0);
890
891 /* Reset the vertex attrib binding */
892 _mesa_vertex_attrib_binding(ctx, vao, attrib, attrib);
893
894 /* The Stride and Ptr fields are not set by update_array_format() */
895 struct gl_array_attributes *array = &vao->VertexAttrib[attrib];
896 array->Stride = stride;
897 /* For updating the pointer we would need to add the vao->NewArrays flag
898 * to the VAO. But but that is done already unconditionally in
899 * _mesa_update_array_format called above.
900 */
901 assert((vao->NewArrays | ~vao->Enabled) & VERT_BIT(attrib));
902 array->Ptr = ptr;
903
904 /* TODO: remove this hack by not using NullBufferObj in callers */
905 if (obj == ctx->Shared->NullBufferObj)
906 obj = NULL;
907
908 /* Update the vertex buffer binding */
909 GLsizei effectiveStride = stride != 0 ?
910 stride : array->Format._ElementSize;
911 _mesa_bind_vertex_buffer(ctx, vao, attrib,
912 obj, (GLintptr) ptr,
913 effectiveStride);
914 }
915
916
917 /* Helper function for all EXT_direct_state_access glVertexArray* functions */
918 static bool
919 _lookup_vao_and_vbo_dsa(struct gl_context *ctx,
920 GLuint vaobj, GLuint buffer,
921 GLintptr offset,
922 struct gl_vertex_array_object** vao,
923 struct gl_buffer_object** vbo,
924 const char* caller)
925 {
926 *vao = _mesa_lookup_vao_err(ctx, vaobj, true, caller);
927 if (!(*vao))
928 return false;
929
930 if (buffer != 0) {
931 *vbo = _mesa_lookup_bufferobj(ctx, buffer);
932 if (!_mesa_handle_bind_buffer_gen(ctx, buffer, vbo, caller))
933 return false;
934
935 if (offset < 0) {
936 _mesa_error(ctx, GL_INVALID_VALUE,
937 "%s(negative offset with non-0 buffer)", caller);
938 return false;
939 }
940 } else {
941 *vbo = NULL;
942 }
943
944 return true;
945 }
946
947
948 void GLAPIENTRY
949 _mesa_VertexPointer_no_error(GLint size, GLenum type, GLsizei stride,
950 const GLvoid *ptr)
951 {
952 GET_CURRENT_CONTEXT(ctx);
953
954 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
955 VERT_ATTRIB_POS, GL_RGBA, 4, size, type, stride,
956 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
957 }
958
959
960 void GLAPIENTRY
961 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
962 {
963 GET_CURRENT_CONTEXT(ctx);
964
965 GLenum format = GL_RGBA;
966 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
967 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
968 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
969 DOUBLE_BIT | HALF_BIT |
970 UNSIGNED_INT_2_10_10_10_REV_BIT |
971 INT_2_10_10_10_REV_BIT);
972
973 if (!validate_array_and_format(ctx, "glVertexPointer",
974 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
975 VERT_ATTRIB_POS, legalTypes, 2, 4, size,
976 type, stride, GL_FALSE, GL_FALSE, GL_FALSE,
977 format, ptr))
978 return;
979
980 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
981 VERT_ATTRIB_POS, format, 4, size, type, stride,
982 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
983 }
984
985
986 void GLAPIENTRY
987 _mesa_VertexArrayVertexOffsetEXT(GLuint vaobj, GLuint buffer, GLint size,
988 GLenum type, GLsizei stride, GLintptr offset)
989 {
990 GET_CURRENT_CONTEXT(ctx);
991
992 GLenum format = GL_RGBA;
993 GLbitfield legalTypes = (ctx->API == API_OPENGLES)
994 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
995 : (SHORT_BIT | INT_BIT | FLOAT_BIT |
996 DOUBLE_BIT | HALF_BIT |
997 UNSIGNED_INT_2_10_10_10_REV_BIT |
998 INT_2_10_10_10_REV_BIT);
999
1000 struct gl_vertex_array_object* vao;
1001 struct gl_buffer_object* vbo;
1002
1003 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1004 &vao, &vbo,
1005 "glVertexArrayVertexOffsetEXT"))
1006 return;
1007
1008 if (!validate_array_and_format(ctx, "glVertexArrayVertexOffsetEXT",
1009 vao, vbo,
1010 VERT_ATTRIB_POS, legalTypes, 2, 4, size,
1011 type, stride, GL_FALSE, GL_FALSE, GL_FALSE,
1012 format, (void*) offset))
1013 return;
1014
1015 update_array(ctx, vao, vbo,
1016 VERT_ATTRIB_POS, format, 4, size, type, stride,
1017 GL_FALSE, GL_FALSE, GL_FALSE, (void*) offset);
1018 }
1019
1020
1021 void GLAPIENTRY
1022 _mesa_NormalPointer_no_error(GLenum type, GLsizei stride, const GLvoid *ptr )
1023 {
1024 GET_CURRENT_CONTEXT(ctx);
1025
1026 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1027 VERT_ATTRIB_NORMAL, GL_RGBA, 3, 3, type, stride, GL_TRUE,
1028 GL_FALSE, GL_FALSE, ptr);
1029 }
1030
1031
1032 void GLAPIENTRY
1033 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr )
1034 {
1035 GET_CURRENT_CONTEXT(ctx);
1036
1037 GLenum format = GL_RGBA;
1038 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
1039 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
1040 : (BYTE_BIT | SHORT_BIT | INT_BIT |
1041 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1042 UNSIGNED_INT_2_10_10_10_REV_BIT |
1043 INT_2_10_10_10_REV_BIT);
1044
1045 if (!validate_array_and_format(ctx, "glNormalPointer",
1046 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1047 VERT_ATTRIB_NORMAL, legalTypes, 3, 3, 3,
1048 type, stride, GL_TRUE, GL_FALSE,
1049 GL_FALSE, format, ptr))
1050 return;
1051
1052 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1053 VERT_ATTRIB_NORMAL, format, 3, 3, type, stride, GL_TRUE,
1054 GL_FALSE, GL_FALSE, ptr);
1055 }
1056
1057
1058 void GLAPIENTRY
1059 _mesa_VertexArrayNormalOffsetEXT(GLuint vaobj, GLuint buffer, GLenum type,
1060 GLsizei stride, GLintptr offset)
1061 {
1062 GET_CURRENT_CONTEXT(ctx);
1063
1064 GLenum format = GL_RGBA;
1065 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
1066 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
1067 : (BYTE_BIT | SHORT_BIT | INT_BIT |
1068 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1069 UNSIGNED_INT_2_10_10_10_REV_BIT |
1070 INT_2_10_10_10_REV_BIT);
1071
1072 struct gl_vertex_array_object* vao;
1073 struct gl_buffer_object* vbo;
1074
1075 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1076 &vao, &vbo,
1077 "glNormalPointer"))
1078 return;
1079
1080 if (!validate_array_and_format(ctx, "glNormalPointer",
1081 vao, vbo,
1082 VERT_ATTRIB_NORMAL, legalTypes, 3, 3, 3,
1083 type, stride, GL_TRUE, GL_FALSE,
1084 GL_FALSE, format, (void*) offset))
1085 return;
1086
1087 update_array(ctx, vao, vbo,
1088 VERT_ATTRIB_NORMAL, format, 3, 3, type, stride, GL_TRUE,
1089 GL_FALSE, GL_FALSE, (void*) offset);
1090 }
1091
1092
1093 void GLAPIENTRY
1094 _mesa_ColorPointer_no_error(GLint size, GLenum type, GLsizei stride,
1095 const GLvoid *ptr)
1096 {
1097 GET_CURRENT_CONTEXT(ctx);
1098
1099 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1100 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1101 VERT_ATTRIB_COLOR0, format, BGRA_OR_4, size,
1102 type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
1103 }
1104
1105
1106 void GLAPIENTRY
1107 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr)
1108 {
1109 GET_CURRENT_CONTEXT(ctx);
1110 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
1111
1112 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1113 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
1114 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
1115 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
1116 SHORT_BIT | UNSIGNED_SHORT_BIT |
1117 INT_BIT | UNSIGNED_INT_BIT |
1118 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1119 UNSIGNED_INT_2_10_10_10_REV_BIT |
1120 INT_2_10_10_10_REV_BIT);
1121
1122 if (!validate_array_and_format(ctx, "glColorPointer",
1123 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1124 VERT_ATTRIB_COLOR0, legalTypes, sizeMin,
1125 BGRA_OR_4, size, type, stride, GL_TRUE,
1126 GL_FALSE, GL_FALSE, format, ptr))
1127 return;
1128
1129 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1130 VERT_ATTRIB_COLOR0, format, BGRA_OR_4, size,
1131 type, stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
1132 }
1133
1134
1135 void GLAPIENTRY
1136 _mesa_VertexArrayColorOffsetEXT(GLuint vaobj, GLuint buffer, GLint size,
1137 GLenum type, GLsizei stride, GLintptr offset)
1138 {
1139 GET_CURRENT_CONTEXT(ctx);
1140 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 4 : 3;
1141
1142 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1143 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
1144 ? (UNSIGNED_BYTE_BIT | HALF_BIT | FLOAT_BIT | FIXED_ES_BIT)
1145 : (BYTE_BIT | UNSIGNED_BYTE_BIT |
1146 SHORT_BIT | UNSIGNED_SHORT_BIT |
1147 INT_BIT | UNSIGNED_INT_BIT |
1148 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1149 UNSIGNED_INT_2_10_10_10_REV_BIT |
1150 INT_2_10_10_10_REV_BIT);
1151
1152 struct gl_vertex_array_object* vao;
1153 struct gl_buffer_object* vbo;
1154
1155 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1156 &vao, &vbo,
1157 "glVertexArrayColorOffsetEXT"))
1158 return;
1159
1160 if (!validate_array_and_format(ctx, "glVertexArrayColorOffsetEXT",
1161 vao, vbo,
1162 VERT_ATTRIB_COLOR0, legalTypes, sizeMin,
1163 BGRA_OR_4, size, type, stride, GL_TRUE,
1164 GL_FALSE, GL_FALSE, format, (void*) offset))
1165 return;
1166
1167 update_array(ctx, vao, vbo,
1168 VERT_ATTRIB_COLOR0, format, BGRA_OR_4, size,
1169 type, stride, GL_TRUE, GL_FALSE, GL_FALSE, (void*) offset);
1170 }
1171
1172
1173 void GLAPIENTRY
1174 _mesa_FogCoordPointer_no_error(GLenum type, GLsizei stride, const GLvoid *ptr)
1175 {
1176 GET_CURRENT_CONTEXT(ctx);
1177
1178 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1179 VERT_ATTRIB_FOG, GL_RGBA, 1, 1, type, stride, GL_FALSE,
1180 GL_FALSE, GL_FALSE, ptr);
1181 }
1182
1183
1184 void GLAPIENTRY
1185 _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
1186 {
1187 GET_CURRENT_CONTEXT(ctx);
1188
1189 GLenum format = GL_RGBA;
1190 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
1191
1192 if (!validate_array_and_format(ctx, "glFogCoordPointer",
1193 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1194 VERT_ATTRIB_FOG, legalTypes, 1, 1, 1,
1195 type, stride, GL_FALSE, GL_FALSE,
1196 GL_FALSE, format, ptr))
1197 return;
1198
1199 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1200 VERT_ATTRIB_FOG, format, 1, 1, type, stride, GL_FALSE,
1201 GL_FALSE, GL_FALSE, ptr);
1202 }
1203
1204
1205 void GLAPIENTRY
1206 _mesa_VertexArrayFogCoordOffsetEXT(GLuint vaobj, GLuint buffer, GLenum type,
1207 GLsizei stride, GLintptr offset)
1208 {
1209 GET_CURRENT_CONTEXT(ctx);
1210
1211 GLenum format = GL_RGBA;
1212 const GLbitfield legalTypes = (HALF_BIT | FLOAT_BIT | DOUBLE_BIT);
1213
1214 struct gl_vertex_array_object* vao;
1215 struct gl_buffer_object* vbo;
1216
1217 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1218 &vao, &vbo,
1219 "glVertexArrayFogCoordOffsetEXT"))
1220 return;
1221
1222 if (!validate_array_and_format(ctx, "glVertexArrayFogCoordOffsetEXT",
1223 vao, vbo,
1224 VERT_ATTRIB_FOG, legalTypes, 1, 1, 1,
1225 type, stride, GL_FALSE, GL_FALSE,
1226 GL_FALSE, format, (void*) offset))
1227 return;
1228
1229 update_array(ctx, vao, vbo,
1230 VERT_ATTRIB_FOG, format, 1, 1, type, stride, GL_FALSE,
1231 GL_FALSE, GL_FALSE, (void*) offset);
1232 }
1233
1234
1235 void GLAPIENTRY
1236 _mesa_IndexPointer_no_error(GLenum type, GLsizei stride, const GLvoid *ptr)
1237 {
1238 GET_CURRENT_CONTEXT(ctx);
1239
1240 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1241 VERT_ATTRIB_COLOR_INDEX, GL_RGBA, 1, 1, type, stride,
1242 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
1243 }
1244
1245
1246 void GLAPIENTRY
1247 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr)
1248 {
1249 GET_CURRENT_CONTEXT(ctx);
1250
1251 GLenum format = GL_RGBA;
1252 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
1253 FLOAT_BIT | DOUBLE_BIT);
1254
1255 if (!validate_array_and_format(ctx, "glIndexPointer",
1256 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1257 VERT_ATTRIB_COLOR_INDEX,
1258 legalTypes, 1, 1, 1, type, stride,
1259 GL_FALSE, GL_FALSE, GL_FALSE, format, ptr))
1260 return;
1261
1262 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1263 VERT_ATTRIB_COLOR_INDEX, format, 1, 1, type, stride,
1264 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
1265 }
1266
1267
1268 void GLAPIENTRY
1269 _mesa_VertexArrayIndexOffsetEXT(GLuint vaobj, GLuint buffer, GLenum type,
1270 GLsizei stride, GLintptr offset)
1271 {
1272 GET_CURRENT_CONTEXT(ctx);
1273
1274 GLenum format = GL_RGBA;
1275 const GLbitfield legalTypes = (UNSIGNED_BYTE_BIT | SHORT_BIT | INT_BIT |
1276 FLOAT_BIT | DOUBLE_BIT);
1277
1278 struct gl_vertex_array_object* vao;
1279 struct gl_buffer_object* vbo;
1280
1281 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1282 &vao, &vbo,
1283 "glVertexArrayIndexOffsetEXT"))
1284 return;
1285
1286 if (!validate_array_and_format(ctx, "glVertexArrayIndexOffsetEXT",
1287 vao, vbo,
1288 VERT_ATTRIB_COLOR_INDEX,
1289 legalTypes, 1, 1, 1, type, stride,
1290 GL_FALSE, GL_FALSE, GL_FALSE, format, (void*) offset))
1291 return;
1292
1293 update_array(ctx, vao, vbo,
1294 VERT_ATTRIB_COLOR_INDEX, format, 1, 1, type, stride,
1295 GL_FALSE, GL_FALSE, GL_FALSE, (void*) offset);
1296 }
1297
1298
1299 void GLAPIENTRY
1300 _mesa_SecondaryColorPointer_no_error(GLint size, GLenum type,
1301 GLsizei stride, const GLvoid *ptr)
1302 {
1303 GET_CURRENT_CONTEXT(ctx);
1304
1305 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1306 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1307 VERT_ATTRIB_COLOR1, format, BGRA_OR_4, size, type,
1308 stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
1309 }
1310
1311
1312 void GLAPIENTRY
1313 _mesa_SecondaryColorPointer(GLint size, GLenum type,
1314 GLsizei stride, const GLvoid *ptr)
1315 {
1316 GET_CURRENT_CONTEXT(ctx);
1317
1318 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1319 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1320 SHORT_BIT | UNSIGNED_SHORT_BIT |
1321 INT_BIT | UNSIGNED_INT_BIT |
1322 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1323 UNSIGNED_INT_2_10_10_10_REV_BIT |
1324 INT_2_10_10_10_REV_BIT);
1325
1326 if (!validate_array_and_format(ctx, "glSecondaryColorPointer",
1327 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1328 VERT_ATTRIB_COLOR1, legalTypes, 3,
1329 BGRA_OR_4, size, type, stride,
1330 GL_TRUE, GL_FALSE, GL_FALSE, format, ptr))
1331 return;
1332
1333 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1334 VERT_ATTRIB_COLOR1, format, BGRA_OR_4, size, type,
1335 stride, GL_TRUE, GL_FALSE, GL_FALSE, ptr);
1336 }
1337
1338
1339 void GLAPIENTRY
1340 _mesa_VertexArraySecondaryColorOffsetEXT(GLuint vaobj, GLuint buffer, GLint size,
1341 GLenum type, GLsizei stride, GLintptr offset)
1342 {
1343 GET_CURRENT_CONTEXT(ctx);
1344
1345 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1346 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1347 SHORT_BIT | UNSIGNED_SHORT_BIT |
1348 INT_BIT | UNSIGNED_INT_BIT |
1349 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1350 UNSIGNED_INT_2_10_10_10_REV_BIT |
1351 INT_2_10_10_10_REV_BIT);
1352
1353 struct gl_vertex_array_object* vao;
1354 struct gl_buffer_object* vbo;
1355
1356 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1357 &vao, &vbo,
1358 "glVertexArraySecondaryColorOffsetEXT"))
1359 return;
1360
1361 if (!validate_array_and_format(ctx, "glVertexArraySecondaryColorOffsetEXT",
1362 vao, vbo,
1363 VERT_ATTRIB_COLOR1, legalTypes, 3,
1364 BGRA_OR_4, size, type, stride,
1365 GL_TRUE, GL_FALSE, GL_FALSE, format, (void*) offset))
1366 return;
1367
1368 update_array(ctx, vao, vbo,
1369 VERT_ATTRIB_COLOR1, format, BGRA_OR_4, size, type,
1370 stride, GL_TRUE, GL_FALSE, GL_FALSE, (void*) offset);
1371 }
1372
1373
1374 void GLAPIENTRY
1375 _mesa_TexCoordPointer_no_error(GLint size, GLenum type, GLsizei stride,
1376 const GLvoid *ptr)
1377 {
1378 GET_CURRENT_CONTEXT(ctx);
1379 const GLuint unit = ctx->Array.ActiveTexture;
1380
1381 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1382 VERT_ATTRIB_TEX(unit), GL_RGBA, 4, size, type,
1383 stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
1384 }
1385
1386
1387 void GLAPIENTRY
1388 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
1389 const GLvoid *ptr)
1390 {
1391 GET_CURRENT_CONTEXT(ctx);
1392 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
1393 const GLuint unit = ctx->Array.ActiveTexture;
1394
1395 GLenum format = GL_RGBA;
1396 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
1397 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
1398 : (SHORT_BIT | INT_BIT |
1399 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1400 UNSIGNED_INT_2_10_10_10_REV_BIT |
1401 INT_2_10_10_10_REV_BIT);
1402
1403 if (!validate_array_and_format(ctx, "glTexCoordPointer",
1404 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1405 VERT_ATTRIB_TEX(unit), legalTypes,
1406 sizeMin, 4, size, type, stride,
1407 GL_FALSE, GL_FALSE, GL_FALSE, format, ptr))
1408 return;
1409
1410 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1411 VERT_ATTRIB_TEX(unit), format, 4, size, type,
1412 stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
1413 }
1414
1415
1416 void GLAPIENTRY
1417 _mesa_VertexArrayTexCoordOffsetEXT(GLuint vaobj, GLuint buffer, GLint size,
1418 GLenum type, GLsizei stride, GLintptr offset)
1419 {
1420 GET_CURRENT_CONTEXT(ctx);
1421 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
1422 const GLuint unit = ctx->Array.ActiveTexture;
1423
1424 GLenum format = GL_RGBA;
1425 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
1426 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
1427 : (SHORT_BIT | INT_BIT |
1428 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1429 UNSIGNED_INT_2_10_10_10_REV_BIT |
1430 INT_2_10_10_10_REV_BIT);
1431
1432 struct gl_vertex_array_object* vao;
1433 struct gl_buffer_object* vbo;
1434
1435 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1436 &vao, &vbo,
1437 "glVertexArrayTexCoordOffsetEXT"))
1438 return;
1439
1440 if (!validate_array_and_format(ctx, "glVertexArrayTexCoordOffsetEXT",
1441 vao, vbo,
1442 VERT_ATTRIB_TEX(unit), legalTypes,
1443 sizeMin, 4, size, type, stride,
1444 GL_FALSE, GL_FALSE, GL_FALSE, format, (void*) offset))
1445 return;
1446
1447 update_array(ctx, vao, vbo,
1448 VERT_ATTRIB_TEX(unit), format, 4, size, type,
1449 stride, GL_FALSE, GL_FALSE, GL_FALSE, (void*) offset);
1450 }
1451
1452
1453 void GLAPIENTRY
1454 _mesa_VertexArrayMultiTexCoordOffsetEXT(GLuint vaobj, GLuint buffer, GLenum texunit,
1455 GLint size, GLenum type, GLsizei stride,
1456 GLintptr offset)
1457 {
1458 GET_CURRENT_CONTEXT(ctx);
1459 const GLint sizeMin = (ctx->API == API_OPENGLES) ? 2 : 1;
1460 const GLuint unit = texunit - GL_TEXTURE0;
1461
1462 GLenum format = GL_RGBA;
1463 const GLbitfield legalTypes = (ctx->API == API_OPENGLES)
1464 ? (BYTE_BIT | SHORT_BIT | FLOAT_BIT | FIXED_ES_BIT)
1465 : (SHORT_BIT | INT_BIT |
1466 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1467 UNSIGNED_INT_2_10_10_10_REV_BIT |
1468 INT_2_10_10_10_REV_BIT);
1469
1470 struct gl_vertex_array_object* vao;
1471 struct gl_buffer_object* vbo;
1472
1473 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1474 &vao, &vbo,
1475 "glVertexArrayMultiTexCoordOffsetEXT"))
1476 return;
1477
1478 if (unit >= ctx->Const.MaxCombinedTextureImageUnits) {
1479 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexArrayMultiTexCoordOffsetEXT(texunit=%d)",
1480 texunit);
1481 return;
1482 }
1483
1484 if (!validate_array_and_format(ctx, "glVertexArrayMultiTexCoordOffsetEXT",
1485 vao, vbo,
1486 VERT_ATTRIB_TEX(unit), legalTypes,
1487 sizeMin, 4, size, type, stride,
1488 GL_FALSE, GL_FALSE, GL_FALSE, format, (void*) offset))
1489 return;
1490
1491 update_array(ctx, vao, vbo,
1492 VERT_ATTRIB_TEX(unit), format, 4, size, type,
1493 stride, GL_FALSE, GL_FALSE, GL_FALSE, (void*) offset);
1494 }
1495
1496
1497 void GLAPIENTRY
1498 _mesa_EdgeFlagPointer_no_error(GLsizei stride, const GLvoid *ptr)
1499 {
1500 /* this is the same type that glEdgeFlag uses */
1501 const GLboolean integer = GL_FALSE;
1502 GET_CURRENT_CONTEXT(ctx);
1503
1504 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1505 VERT_ATTRIB_EDGEFLAG, GL_RGBA, 1, 1, GL_UNSIGNED_BYTE,
1506 stride, GL_FALSE, integer, GL_FALSE, ptr);
1507 }
1508
1509
1510 void GLAPIENTRY
1511 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr)
1512 {
1513 /* this is the same type that glEdgeFlag uses */
1514 const GLboolean integer = GL_FALSE;
1515 GET_CURRENT_CONTEXT(ctx);
1516
1517 GLenum format = GL_RGBA;
1518 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
1519
1520 if (!validate_array_and_format(ctx, "glEdgeFlagPointer",
1521 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1522 VERT_ATTRIB_EDGEFLAG, legalTypes,
1523 1, 1, 1, GL_UNSIGNED_BYTE, stride,
1524 GL_FALSE, integer, GL_FALSE, format, ptr))
1525 return;
1526
1527 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1528 VERT_ATTRIB_EDGEFLAG, format, 1, 1, GL_UNSIGNED_BYTE,
1529 stride, GL_FALSE, integer, GL_FALSE, ptr);
1530 }
1531
1532
1533 void GLAPIENTRY
1534 _mesa_VertexArrayEdgeFlagOffsetEXT(GLuint vaobj, GLuint buffer, GLsizei stride,
1535 GLintptr offset)
1536 {
1537 /* this is the same type that glEdgeFlag uses */
1538 const GLboolean integer = GL_FALSE;
1539 GET_CURRENT_CONTEXT(ctx);
1540
1541 GLenum format = GL_RGBA;
1542 const GLbitfield legalTypes = UNSIGNED_BYTE_BIT;
1543
1544 struct gl_vertex_array_object* vao;
1545 struct gl_buffer_object* vbo;
1546
1547 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1548 &vao, &vbo,
1549 "glVertexArrayEdgeFlagOffsetEXT"))
1550 return;
1551
1552 if (!validate_array_and_format(ctx, "glVertexArrayEdgeFlagOffsetEXT",
1553 vao, vbo,
1554 VERT_ATTRIB_EDGEFLAG, legalTypes,
1555 1, 1, 1, GL_UNSIGNED_BYTE, stride,
1556 GL_FALSE, integer, GL_FALSE, format, (void*) offset))
1557 return;
1558
1559 update_array(ctx, vao, vbo,
1560 VERT_ATTRIB_EDGEFLAG, format, 1, 1, GL_UNSIGNED_BYTE,
1561 stride, GL_FALSE, integer, GL_FALSE, (void*) offset);
1562 }
1563
1564
1565 void GLAPIENTRY
1566 _mesa_PointSizePointerOES_no_error(GLenum type, GLsizei stride,
1567 const GLvoid *ptr)
1568 {
1569 GET_CURRENT_CONTEXT(ctx);
1570
1571 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1572 VERT_ATTRIB_POINT_SIZE, GL_RGBA, 1, 1, type, stride,
1573 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
1574 }
1575
1576
1577 void GLAPIENTRY
1578 _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr)
1579 {
1580 GET_CURRENT_CONTEXT(ctx);
1581
1582 GLenum format = GL_RGBA;
1583 if (ctx->API != API_OPENGLES) {
1584 _mesa_error(ctx, GL_INVALID_OPERATION,
1585 "glPointSizePointer(ES 1.x only)");
1586 return;
1587 }
1588
1589 const GLbitfield legalTypes = (FLOAT_BIT | FIXED_ES_BIT);
1590
1591 if (!validate_array_and_format(ctx, "glPointSizePointer",
1592 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1593 VERT_ATTRIB_POINT_SIZE, legalTypes,
1594 1, 1, 1, type, stride, GL_FALSE, GL_FALSE,
1595 GL_FALSE, format, ptr))
1596 return;
1597
1598 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1599 VERT_ATTRIB_POINT_SIZE, format, 1, 1, type, stride,
1600 GL_FALSE, GL_FALSE, GL_FALSE, ptr);
1601 }
1602
1603
1604 void GLAPIENTRY
1605 _mesa_VertexAttribPointer_no_error(GLuint index, GLint size, GLenum type,
1606 GLboolean normalized,
1607 GLsizei stride, const GLvoid *ptr)
1608 {
1609 GET_CURRENT_CONTEXT(ctx);
1610
1611 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1612 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1613 VERT_ATTRIB_GENERIC(index), format, BGRA_OR_4,
1614 size, type, stride, normalized, GL_FALSE, GL_FALSE, ptr);
1615 }
1616
1617
1618 /**
1619 * Set a generic vertex attribute array.
1620 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1621 * (position, normal, color, fog, texcoord, etc).
1622 */
1623 void GLAPIENTRY
1624 _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
1625 GLboolean normalized,
1626 GLsizei stride, const GLvoid *ptr)
1627 {
1628 GET_CURRENT_CONTEXT(ctx);
1629
1630 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1631 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1632 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribPointerARB(idx)");
1633 return;
1634 }
1635
1636 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1637 SHORT_BIT | UNSIGNED_SHORT_BIT |
1638 INT_BIT | UNSIGNED_INT_BIT |
1639 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1640 FIXED_ES_BIT | FIXED_GL_BIT |
1641 UNSIGNED_INT_2_10_10_10_REV_BIT |
1642 INT_2_10_10_10_REV_BIT |
1643 UNSIGNED_INT_10F_11F_11F_REV_BIT);
1644
1645 if (!validate_array_and_format(ctx, "glVertexAttribPointer",
1646 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1647 VERT_ATTRIB_GENERIC(index), legalTypes,
1648 1, BGRA_OR_4, size, type, stride,
1649 normalized, GL_FALSE, GL_FALSE, format, ptr))
1650 return;
1651
1652 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1653 VERT_ATTRIB_GENERIC(index), format, BGRA_OR_4,
1654 size, type, stride, normalized, GL_FALSE, GL_FALSE, ptr);
1655 }
1656
1657
1658 void GLAPIENTRY
1659 _mesa_VertexArrayVertexAttribOffsetEXT(GLuint vaobj, GLuint buffer, GLuint index, GLint size,
1660 GLenum type, GLboolean normalized,
1661 GLsizei stride, GLintptr offset)
1662 {
1663 GET_CURRENT_CONTEXT(ctx);
1664 GLenum format = get_array_format(ctx, BGRA_OR_4, &size);
1665 struct gl_vertex_array_object* vao;
1666 struct gl_buffer_object* vbo;
1667
1668 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1669 &vao, &vbo,
1670 "glVertexArrayVertexAttribOffsetEXT"))
1671 return;
1672
1673 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1674 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexArrayVertexAttribOffsetEXT(idx)");
1675 return;
1676 }
1677
1678 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1679 SHORT_BIT | UNSIGNED_SHORT_BIT |
1680 INT_BIT | UNSIGNED_INT_BIT |
1681 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
1682 FIXED_ES_BIT | FIXED_GL_BIT |
1683 UNSIGNED_INT_2_10_10_10_REV_BIT |
1684 INT_2_10_10_10_REV_BIT |
1685 UNSIGNED_INT_10F_11F_11F_REV_BIT);
1686
1687 if (!validate_array_and_format(ctx, "glVertexArrayVertexAttribOffsetEXT",
1688 vao, vbo,
1689 VERT_ATTRIB_GENERIC(index), legalTypes,
1690 1, BGRA_OR_4, size, type, stride,
1691 normalized, GL_FALSE, GL_FALSE, format, (void*) offset))
1692 return;
1693
1694 update_array(ctx, vao, vbo,
1695 VERT_ATTRIB_GENERIC(index), format, BGRA_OR_4,
1696 size, type, stride, normalized, GL_FALSE, GL_FALSE, (void*) offset);
1697 }
1698
1699
1700 void GLAPIENTRY
1701 _mesa_VertexArrayVertexAttribLOffsetEXT(GLuint vaobj, GLuint buffer, GLuint index, GLint size,
1702 GLenum type, GLsizei stride, GLintptr offset)
1703 {
1704 GET_CURRENT_CONTEXT(ctx);
1705 GLenum format = GL_RGBA;
1706 struct gl_vertex_array_object* vao;
1707 struct gl_buffer_object* vbo;
1708
1709 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1710 &vao, &vbo,
1711 "glVertexArrayVertexAttribLOffsetEXT"))
1712 return;
1713
1714 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1715 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexArrayVertexAttribLOffsetEXT(idx)");
1716 return;
1717 }
1718
1719 const GLbitfield legalTypes = DOUBLE_BIT;
1720
1721 if (!validate_array_and_format(ctx, "glVertexArrayVertexAttribLOffsetEXT",
1722 vao, vbo,
1723 VERT_ATTRIB_GENERIC(index), legalTypes,
1724 1, 4, size, type, stride,
1725 GL_FALSE, GL_FALSE, GL_TRUE, format, (void*) offset))
1726 return;
1727
1728 update_array(ctx, vao, vbo,
1729 VERT_ATTRIB_GENERIC(index), format, 4,
1730 size, type, stride, GL_FALSE, GL_FALSE, GL_TRUE, (void*) offset);
1731 }
1732
1733
1734 void GLAPIENTRY
1735 _mesa_VertexAttribIPointer_no_error(GLuint index, GLint size, GLenum type,
1736 GLsizei stride, const GLvoid *ptr)
1737 {
1738 const GLboolean normalized = GL_FALSE;
1739 const GLboolean integer = GL_TRUE;
1740 GET_CURRENT_CONTEXT(ctx);
1741
1742 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1743 VERT_ATTRIB_GENERIC(index), GL_RGBA, 4, size, type,
1744 stride, normalized, integer, GL_FALSE, ptr);
1745 }
1746
1747
1748 /**
1749 * GL_EXT_gpu_shader4 / GL 3.0.
1750 * Set an integer-valued vertex attribute array.
1751 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1752 * (position, normal, color, fog, texcoord, etc).
1753 */
1754 void GLAPIENTRY
1755 _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
1756 GLsizei stride, const GLvoid *ptr)
1757 {
1758 const GLboolean normalized = GL_FALSE;
1759 const GLboolean integer = GL_TRUE;
1760 GET_CURRENT_CONTEXT(ctx);
1761
1762 GLenum format = GL_RGBA;
1763 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1764 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribIPointer(index)");
1765 return;
1766 }
1767
1768 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1769 SHORT_BIT | UNSIGNED_SHORT_BIT |
1770 INT_BIT | UNSIGNED_INT_BIT);
1771
1772 if (!validate_array_and_format(ctx, "glVertexAttribIPointer",
1773 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1774 VERT_ATTRIB_GENERIC(index), legalTypes,
1775 1, 4, size, type, stride,
1776 normalized, integer, GL_FALSE, format, ptr))
1777 return;
1778
1779 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1780 VERT_ATTRIB_GENERIC(index), format, 4, size, type,
1781 stride, normalized, integer, GL_FALSE, ptr);
1782 }
1783
1784
1785 void GLAPIENTRY
1786 _mesa_VertexAttribLPointer_no_error(GLuint index, GLint size, GLenum type,
1787 GLsizei stride, const GLvoid *ptr)
1788 {
1789 GET_CURRENT_CONTEXT(ctx);
1790
1791 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1792 VERT_ATTRIB_GENERIC(index), GL_RGBA, 4, size, type,
1793 stride, GL_FALSE, GL_FALSE, GL_TRUE, ptr);
1794 }
1795
1796
1797 void GLAPIENTRY
1798 _mesa_VertexArrayVertexAttribIOffsetEXT(GLuint vaobj, GLuint buffer, GLuint index, GLint size,
1799 GLenum type, GLsizei stride, GLintptr offset)
1800 {
1801 const GLboolean normalized = GL_FALSE;
1802 const GLboolean integer = GL_TRUE;
1803 GET_CURRENT_CONTEXT(ctx);
1804 GLenum format = GL_RGBA;
1805
1806 struct gl_vertex_array_object* vao;
1807 struct gl_buffer_object* vbo;
1808
1809 if (!_lookup_vao_and_vbo_dsa(ctx, vaobj, buffer, offset,
1810 &vao, &vbo,
1811 "glVertexArrayVertexAttribIOffsetEXT"))
1812 return;
1813
1814 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1815 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexArrayVertexAttribIOffsetEXT(index)");
1816 return;
1817 }
1818
1819 const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT |
1820 SHORT_BIT | UNSIGNED_SHORT_BIT |
1821 INT_BIT | UNSIGNED_INT_BIT);
1822
1823 if (!validate_array_and_format(ctx, "glVertexArrayVertexAttribIOffsetEXT",
1824 vao, vbo,
1825 VERT_ATTRIB_GENERIC(index), legalTypes,
1826 1, 4, size, type, stride,
1827 normalized, integer, GL_FALSE, format, (void*) offset))
1828 return;
1829
1830 update_array(ctx, vao, vbo,
1831 VERT_ATTRIB_GENERIC(index), format, 4, size, type,
1832 stride, normalized, integer, GL_FALSE, (void*) offset);
1833 }
1834
1835
1836 void GLAPIENTRY
1837 _mesa_VertexAttribLPointer(GLuint index, GLint size, GLenum type,
1838 GLsizei stride, const GLvoid *ptr)
1839 {
1840 GET_CURRENT_CONTEXT(ctx);
1841
1842 GLenum format = GL_RGBA;
1843 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1844 _mesa_error(ctx, GL_INVALID_VALUE, "glVertexAttribLPointer(index)");
1845 return;
1846 }
1847
1848 const GLbitfield legalTypes = DOUBLE_BIT;
1849
1850 if (!validate_array_and_format(ctx, "glVertexAttribLPointer",
1851 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1852 VERT_ATTRIB_GENERIC(index), legalTypes,
1853 1, 4, size, type, stride,
1854 GL_FALSE, GL_FALSE, GL_TRUE, format, ptr))
1855 return;
1856
1857 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
1858 VERT_ATTRIB_GENERIC(index), format, 4, size, type,
1859 stride, GL_FALSE, GL_FALSE, GL_TRUE, ptr);
1860 }
1861
1862
1863 void
1864 _mesa_enable_vertex_array_attribs(struct gl_context *ctx,
1865 struct gl_vertex_array_object *vao,
1866 GLbitfield attrib_bits)
1867 {
1868 assert((attrib_bits & ~VERT_BIT_ALL) == 0);
1869 assert(!vao->SharedAndImmutable);
1870
1871 /* Only work on bits that are disabled */
1872 attrib_bits &= ~vao->Enabled;
1873 if (attrib_bits) {
1874 /* was disabled, now being enabled */
1875 vao->Enabled |= attrib_bits;
1876 vao->NewArrays |= attrib_bits;
1877
1878 /* Update the map mode if needed */
1879 if (attrib_bits & (VERT_BIT_POS|VERT_BIT_GENERIC0))
1880 update_attribute_map_mode(ctx, vao);
1881 }
1882 }
1883
1884 static void
1885 enable_vertex_array_attrib(struct gl_context *ctx,
1886 struct gl_vertex_array_object *vao,
1887 GLuint index,
1888 const char *func)
1889 {
1890 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1891 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index)", func);
1892 return;
1893 }
1894
1895 _mesa_enable_vertex_array_attrib(ctx, vao, VERT_ATTRIB_GENERIC(index));
1896 }
1897
1898
1899 void GLAPIENTRY
1900 _mesa_EnableVertexAttribArray(GLuint index)
1901 {
1902 GET_CURRENT_CONTEXT(ctx);
1903 enable_vertex_array_attrib(ctx, ctx->Array.VAO, index,
1904 "glEnableVertexAttribArray");
1905 }
1906
1907
1908 void GLAPIENTRY
1909 _mesa_EnableVertexAttribArray_no_error(GLuint index)
1910 {
1911 GET_CURRENT_CONTEXT(ctx);
1912 _mesa_enable_vertex_array_attrib(ctx, ctx->Array.VAO,
1913 VERT_ATTRIB_GENERIC(index));
1914 }
1915
1916
1917 void GLAPIENTRY
1918 _mesa_EnableVertexArrayAttrib(GLuint vaobj, GLuint index)
1919 {
1920 GET_CURRENT_CONTEXT(ctx);
1921 struct gl_vertex_array_object *vao;
1922
1923 /* The ARB_direct_state_access specification says:
1924 *
1925 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1926 * and DisableVertexArrayAttrib if <vaobj> is not
1927 * [compatibility profile: zero or] the name of an existing vertex
1928 * array object."
1929 */
1930 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glEnableVertexArrayAttrib");
1931 if (!vao)
1932 return;
1933
1934 enable_vertex_array_attrib(ctx, vao, index, "glEnableVertexArrayAttrib");
1935 }
1936
1937 void GLAPIENTRY
1938 _mesa_EnableVertexArrayAttribEXT(GLuint vaobj, GLuint index)
1939 {
1940 GET_CURRENT_CONTEXT(ctx);
1941 struct gl_vertex_array_object* vao = _mesa_lookup_vao_err(ctx, vaobj,
1942 true,
1943 "glEnableVertexArrayAttribEXT");
1944 if (!vao)
1945 return;
1946
1947 enable_vertex_array_attrib(ctx, vao, index, "glEnableVertexArrayAttribEXT");
1948 }
1949
1950
1951 void GLAPIENTRY
1952 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj, GLuint index)
1953 {
1954 GET_CURRENT_CONTEXT(ctx);
1955 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
1956 _mesa_enable_vertex_array_attrib(ctx, vao, VERT_ATTRIB_GENERIC(index));
1957 }
1958
1959
1960 void
1961 _mesa_disable_vertex_array_attribs(struct gl_context *ctx,
1962 struct gl_vertex_array_object *vao,
1963 GLbitfield attrib_bits)
1964 {
1965 assert((attrib_bits & ~VERT_BIT_ALL) == 0);
1966 assert(!vao->SharedAndImmutable);
1967
1968 /* Only work on bits that are enabled */
1969 attrib_bits &= vao->Enabled;
1970 if (attrib_bits) {
1971 /* was enabled, now being disabled */
1972 vao->Enabled &= ~attrib_bits;
1973 vao->NewArrays |= attrib_bits;
1974
1975 /* Update the map mode if needed */
1976 if (attrib_bits & (VERT_BIT_POS|VERT_BIT_GENERIC0))
1977 update_attribute_map_mode(ctx, vao);
1978 }
1979 }
1980
1981
1982 void GLAPIENTRY
1983 _mesa_DisableVertexAttribArray(GLuint index)
1984 {
1985 GET_CURRENT_CONTEXT(ctx);
1986
1987 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
1988 _mesa_error(ctx, GL_INVALID_VALUE, "glDisableVertexAttribArray(index)");
1989 return;
1990 }
1991
1992 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
1993 _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attrib);
1994 }
1995
1996
1997 void GLAPIENTRY
1998 _mesa_DisableVertexAttribArray_no_error(GLuint index)
1999 {
2000 GET_CURRENT_CONTEXT(ctx);
2001 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
2002 _mesa_disable_vertex_array_attrib(ctx, ctx->Array.VAO, attrib);
2003 }
2004
2005
2006 void GLAPIENTRY
2007 _mesa_DisableVertexArrayAttrib(GLuint vaobj, GLuint index)
2008 {
2009 GET_CURRENT_CONTEXT(ctx);
2010 struct gl_vertex_array_object *vao;
2011
2012 /* The ARB_direct_state_access specification says:
2013 *
2014 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
2015 * and DisableVertexArrayAttrib if <vaobj> is not
2016 * [compatibility profile: zero or] the name of an existing vertex
2017 * array object."
2018 */
2019 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glDisableVertexArrayAttrib");
2020 if (!vao)
2021 return;
2022
2023 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2024 _mesa_error(ctx, GL_INVALID_VALUE, "glDisableVertexArrayAttrib(index)");
2025 return;
2026 }
2027
2028 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
2029 _mesa_disable_vertex_array_attrib(ctx, vao, attrib);
2030 }
2031
2032 void GLAPIENTRY
2033 _mesa_DisableVertexArrayAttribEXT(GLuint vaobj, GLuint index)
2034 {
2035 GET_CURRENT_CONTEXT(ctx);
2036 struct gl_vertex_array_object* vao = _mesa_lookup_vao_err(ctx, vaobj,
2037 true,
2038 "glEnableVertexArrayAttribEXT");
2039 if (!vao)
2040 return;
2041
2042 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2043 _mesa_error(ctx, GL_INVALID_VALUE, "glDisableVertexArrayAttrib(index)");
2044 return;
2045 }
2046
2047 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
2048 _mesa_disable_vertex_array_attrib(ctx, vao, attrib);
2049 }
2050
2051
2052 void GLAPIENTRY
2053 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj, GLuint index)
2054 {
2055 GET_CURRENT_CONTEXT(ctx);
2056 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
2057 const gl_vert_attrib attrib = VERT_ATTRIB_GENERIC(index);
2058 _mesa_disable_vertex_array_attrib(ctx, vao, attrib);
2059 }
2060
2061
2062 /**
2063 * Return info for a vertex attribute array (no alias with legacy
2064 * vertex attributes (pos, normal, color, etc)). This function does
2065 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
2066 */
2067 static GLuint
2068 get_vertex_array_attrib(struct gl_context *ctx,
2069 const struct gl_vertex_array_object *vao,
2070 GLuint index, GLenum pname,
2071 const char *caller)
2072 {
2073 const struct gl_array_attributes *array;
2074 struct gl_buffer_object *buf;
2075
2076 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2077 _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index);
2078 return 0;
2079 }
2080
2081 assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib));
2082
2083 array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)];
2084
2085 switch (pname) {
2086 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
2087 return !!(vao->Enabled & VERT_BIT_GENERIC(index));
2088 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
2089 return (array->Format.Format == GL_BGRA) ? GL_BGRA : array->Format.Size;
2090 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
2091 return array->Stride;
2092 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
2093 return array->Format.Type;
2094 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
2095 return array->Format.Normalized;
2096 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
2097 buf = vao->BufferBinding[array->BufferBindingIndex].BufferObj;
2098 return buf ? buf->Name : 0;
2099 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
2100 if ((_mesa_is_desktop_gl(ctx)
2101 && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4))
2102 || _mesa_is_gles3(ctx)) {
2103 return array->Format.Integer;
2104 }
2105 goto error;
2106 case GL_VERTEX_ATTRIB_ARRAY_LONG:
2107 if (_mesa_is_desktop_gl(ctx)) {
2108 return array->Format.Doubles;
2109 }
2110 goto error;
2111 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
2112 if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays)
2113 || _mesa_is_gles3(ctx)) {
2114 return vao->BufferBinding[array->BufferBindingIndex].InstanceDivisor;
2115 }
2116 goto error;
2117 case GL_VERTEX_ATTRIB_BINDING:
2118 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
2119 return array->BufferBindingIndex - VERT_ATTRIB_GENERIC0;
2120 }
2121 goto error;
2122 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
2123 if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) {
2124 return array->RelativeOffset;
2125 }
2126 goto error;
2127 default:
2128 ; /* fall-through */
2129 }
2130
2131 error:
2132 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=0x%x)", caller, pname);
2133 return 0;
2134 }
2135
2136
2137 static const GLfloat *
2138 get_current_attrib(struct gl_context *ctx, GLuint index, const char *function)
2139 {
2140 if (index == 0) {
2141 if (_mesa_attr_zero_aliases_vertex(ctx)) {
2142 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(index==0)", function);
2143 return NULL;
2144 }
2145 }
2146 else if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2147 _mesa_error(ctx, GL_INVALID_VALUE,
2148 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function);
2149 return NULL;
2150 }
2151
2152 assert(VERT_ATTRIB_GENERIC(index) <
2153 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
2154
2155 FLUSH_CURRENT(ctx, 0);
2156 return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)];
2157 }
2158
2159 void GLAPIENTRY
2160 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
2161 {
2162 GET_CURRENT_CONTEXT(ctx);
2163
2164 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
2165 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribfv");
2166 if (v != NULL) {
2167 COPY_4V(params, v);
2168 }
2169 }
2170 else {
2171 params[0] = (GLfloat) get_vertex_array_attrib(ctx, ctx->Array.VAO,
2172 index, pname,
2173 "glGetVertexAttribfv");
2174 }
2175 }
2176
2177
2178 void GLAPIENTRY
2179 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params)
2180 {
2181 GET_CURRENT_CONTEXT(ctx);
2182
2183 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
2184 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribdv");
2185 if (v != NULL) {
2186 params[0] = (GLdouble) v[0];
2187 params[1] = (GLdouble) v[1];
2188 params[2] = (GLdouble) v[2];
2189 params[3] = (GLdouble) v[3];
2190 }
2191 }
2192 else {
2193 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
2194 index, pname,
2195 "glGetVertexAttribdv");
2196 }
2197 }
2198
2199 void GLAPIENTRY
2200 _mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params)
2201 {
2202 GET_CURRENT_CONTEXT(ctx);
2203
2204 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
2205 const GLdouble *v =
2206 (const GLdouble *)get_current_attrib(ctx, index,
2207 "glGetVertexAttribLdv");
2208 if (v != NULL) {
2209 params[0] = v[0];
2210 params[1] = v[1];
2211 params[2] = v[2];
2212 params[3] = v[3];
2213 }
2214 }
2215 else {
2216 params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO,
2217 index, pname,
2218 "glGetVertexAttribLdv");
2219 }
2220 }
2221
2222 void GLAPIENTRY
2223 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params)
2224 {
2225 GET_CURRENT_CONTEXT(ctx);
2226
2227 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
2228 const GLfloat *v = get_current_attrib(ctx, index, "glGetVertexAttribiv");
2229 if (v != NULL) {
2230 /* XXX should floats in[0,1] be scaled to full int range? */
2231 params[0] = (GLint) v[0];
2232 params[1] = (GLint) v[1];
2233 params[2] = (GLint) v[2];
2234 params[3] = (GLint) v[3];
2235 }
2236 }
2237 else {
2238 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
2239 index, pname,
2240 "glGetVertexAttribiv");
2241 }
2242 }
2243
2244 void GLAPIENTRY
2245 _mesa_GetVertexAttribLui64vARB(GLuint index, GLenum pname, GLuint64EXT *params)
2246 {
2247 GET_CURRENT_CONTEXT(ctx);
2248
2249 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
2250 const GLuint64 *v =
2251 (const GLuint64 *)get_current_attrib(ctx, index,
2252 "glGetVertexAttribLui64vARB");
2253 if (v != NULL) {
2254 params[0] = v[0];
2255 params[1] = v[1];
2256 params[2] = v[2];
2257 params[3] = v[3];
2258 }
2259 }
2260 else {
2261 params[0] = (GLuint64) get_vertex_array_attrib(ctx, ctx->Array.VAO,
2262 index, pname,
2263 "glGetVertexAttribLui64vARB");
2264 }
2265 }
2266
2267
2268 /** GL 3.0 */
2269 void GLAPIENTRY
2270 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
2271 {
2272 GET_CURRENT_CONTEXT(ctx);
2273
2274 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
2275 const GLint *v = (const GLint *)
2276 get_current_attrib(ctx, index, "glGetVertexAttribIiv");
2277 if (v != NULL) {
2278 COPY_4V(params, v);
2279 }
2280 }
2281 else {
2282 params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO,
2283 index, pname,
2284 "glGetVertexAttribIiv");
2285 }
2286 }
2287
2288
2289 /** GL 3.0 */
2290 void GLAPIENTRY
2291 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
2292 {
2293 GET_CURRENT_CONTEXT(ctx);
2294
2295 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
2296 const GLuint *v = (const GLuint *)
2297 get_current_attrib(ctx, index, "glGetVertexAttribIuiv");
2298 if (v != NULL) {
2299 COPY_4V(params, v);
2300 }
2301 }
2302 else {
2303 params[0] = get_vertex_array_attrib(ctx, ctx->Array.VAO,
2304 index, pname,
2305 "glGetVertexAttribIuiv");
2306 }
2307 }
2308
2309
2310 void GLAPIENTRY
2311 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
2312 {
2313 GET_CURRENT_CONTEXT(ctx);
2314
2315 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2316 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
2317 return;
2318 }
2319
2320 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
2321 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
2322 return;
2323 }
2324
2325 assert(VERT_ATTRIB_GENERIC(index) <
2326 ARRAY_SIZE(ctx->Array.VAO->VertexAttrib));
2327
2328 *pointer = (GLvoid *)
2329 ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
2330 }
2331
2332
2333 /** ARB_direct_state_access */
2334 void GLAPIENTRY
2335 _mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index,
2336 GLenum pname, GLint *params)
2337 {
2338 GET_CURRENT_CONTEXT(ctx);
2339 struct gl_vertex_array_object *vao;
2340 struct gl_buffer_object *buf;
2341
2342 /* The ARB_direct_state_access specification says:
2343 *
2344 * "An INVALID_OPERATION error is generated if <vaobj> is not
2345 * [compatibility profile: zero or] the name of an existing
2346 * vertex array object."
2347 */
2348 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glGetVertexArrayIndexediv");
2349 if (!vao)
2350 return;
2351
2352 /* The ARB_direct_state_access specification says:
2353 *
2354 * "For GetVertexArrayIndexediv, <pname> must be one of
2355 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
2356 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
2357 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
2358 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
2359 * VERTEX_ATTRIB_RELATIVE_OFFSET."
2360 *
2361 * and:
2362 *
2363 * "Add GetVertexArrayIndexediv in 'Get Command' for
2364 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
2365 * VERTEX_ATTRIB_BINDING,
2366 * VERTEX_ATTRIB_RELATIVE_OFFSET,
2367 * VERTEX_BINDING_OFFSET, and
2368 * VERTEX_BINDING_STRIDE states"
2369 *
2370 * The only parameter name common to both lists is
2371 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
2372 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
2373 * pretty clear however that the intent is that it should be possible
2374 * to query all vertex attrib and binding states that can be set with
2375 * a DSA function.
2376 */
2377 switch (pname) {
2378 case GL_VERTEX_BINDING_OFFSET:
2379 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
2380 break;
2381 case GL_VERTEX_BINDING_STRIDE:
2382 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Stride;
2383 break;
2384 case GL_VERTEX_BINDING_DIVISOR:
2385 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
2386 break;
2387 case GL_VERTEX_BINDING_BUFFER:
2388 buf = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj;
2389 params[0] = buf ? buf->Name : 0;
2390 break;
2391 default:
2392 params[0] = get_vertex_array_attrib(ctx, vao, index, pname,
2393 "glGetVertexArrayIndexediv");
2394 break;
2395 }
2396 }
2397
2398
2399 void GLAPIENTRY
2400 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj, GLuint index,
2401 GLenum pname, GLint64 *params)
2402 {
2403 GET_CURRENT_CONTEXT(ctx);
2404 struct gl_vertex_array_object *vao;
2405
2406 /* The ARB_direct_state_access specification says:
2407 *
2408 * "An INVALID_OPERATION error is generated if <vaobj> is not
2409 * [compatibility profile: zero or] the name of an existing
2410 * vertex array object."
2411 */
2412 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glGetVertexArrayIndexed64iv");
2413 if (!vao)
2414 return;
2415
2416 /* The ARB_direct_state_access specification says:
2417 *
2418 * "For GetVertexArrayIndexed64iv, <pname> must be
2419 * VERTEX_BINDING_OFFSET."
2420 *
2421 * and:
2422 *
2423 * "An INVALID_ENUM error is generated if <pname> is not one of
2424 * the valid values listed above for the corresponding command."
2425 */
2426 if (pname != GL_VERTEX_BINDING_OFFSET) {
2427 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayIndexed64iv("
2428 "pname != GL_VERTEX_BINDING_OFFSET)");
2429 return;
2430 }
2431
2432 /* The ARB_direct_state_access specification says:
2433 *
2434 * "An INVALID_VALUE error is generated if <index> is greater than
2435 * or equal to the value of MAX_VERTEX_ATTRIBS."
2436 *
2437 * Since the index refers to a buffer binding in this case, the intended
2438 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
2439 * required to be the same, so in practice this doesn't matter.
2440 */
2441 if (index >= ctx->Const.MaxVertexAttribBindings) {
2442 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexArrayIndexed64iv(index"
2443 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
2444 index, ctx->Const.MaxVertexAttribBindings);
2445 return;
2446 }
2447
2448 params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
2449 }
2450
2451
2452 void GLAPIENTRY
2453 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
2454 GLsizei count, const GLvoid *ptr)
2455 {
2456 (void) count;
2457 _mesa_VertexPointer(size, type, stride, ptr);
2458 }
2459
2460
2461 void GLAPIENTRY
2462 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
2463 const GLvoid *ptr)
2464 {
2465 (void) count;
2466 _mesa_NormalPointer(type, stride, ptr);
2467 }
2468
2469
2470 void GLAPIENTRY
2471 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
2472 const GLvoid *ptr)
2473 {
2474 (void) count;
2475 _mesa_ColorPointer(size, type, stride, ptr);
2476 }
2477
2478
2479 void GLAPIENTRY
2480 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
2481 const GLvoid *ptr)
2482 {
2483 (void) count;
2484 _mesa_IndexPointer(type, stride, ptr);
2485 }
2486
2487
2488 void GLAPIENTRY
2489 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
2490 GLsizei count, const GLvoid *ptr)
2491 {
2492 (void) count;
2493 _mesa_TexCoordPointer(size, type, stride, ptr);
2494 }
2495
2496
2497 void GLAPIENTRY
2498 _mesa_MultiTexCoordPointerEXT(GLenum texunit, GLint size, GLenum type,
2499 GLsizei stride, const GLvoid *ptr)
2500 {
2501 GET_CURRENT_CONTEXT(ctx);
2502 const GLint sizeMin = 1;
2503 const GLuint unit = texunit - GL_TEXTURE0;
2504
2505 GLenum format = GL_RGBA;
2506 const GLbitfield legalTypes = (SHORT_BIT | INT_BIT |
2507 HALF_BIT | FLOAT_BIT | DOUBLE_BIT |
2508 UNSIGNED_INT_2_10_10_10_REV_BIT |
2509 INT_2_10_10_10_REV_BIT);
2510
2511 if (!validate_array_and_format(ctx, "glMultiTexCoordPointerEXT",
2512 ctx->Array.VAO, ctx->Array.ArrayBufferObj,
2513 VERT_ATTRIB_TEX(unit), legalTypes,
2514 sizeMin, 4, size, type, stride,
2515 GL_FALSE, GL_FALSE, GL_FALSE, format, ptr))
2516 return;
2517
2518 update_array(ctx, ctx->Array.VAO, ctx->Array.ArrayBufferObj,
2519 VERT_ATTRIB_TEX(unit), format, 4, size, type,
2520 stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr);
2521 }
2522
2523
2524 void GLAPIENTRY
2525 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr)
2526 {
2527 (void) count;
2528 _mesa_EdgeFlagPointer(stride, ptr);
2529 }
2530
2531
2532 void GLAPIENTRY
2533 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer)
2534 {
2535 GET_CURRENT_CONTEXT(ctx);
2536 GLboolean tflag, cflag, nflag; /* enable/disable flags */
2537 GLint tcomps, ccomps, vcomps; /* components per texcoord, color, vertex */
2538 GLenum ctype = 0; /* color type */
2539 GLint coffset = 0, noffset = 0, voffset;/* color, normal, vertex offsets */
2540 const GLint toffset = 0; /* always zero */
2541 GLint defstride; /* default stride */
2542 GLint c, f;
2543
2544 f = sizeof(GLfloat);
2545 c = f * ((4 * sizeof(GLubyte) + (f - 1)) / f);
2546
2547 if (stride < 0) {
2548 _mesa_error( ctx, GL_INVALID_VALUE, "glInterleavedArrays(stride)" );
2549 return;
2550 }
2551
2552 switch (format) {
2553 case GL_V2F:
2554 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
2555 tcomps = 0; ccomps = 0; vcomps = 2;
2556 voffset = 0;
2557 defstride = 2*f;
2558 break;
2559 case GL_V3F:
2560 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_FALSE;
2561 tcomps = 0; ccomps = 0; vcomps = 3;
2562 voffset = 0;
2563 defstride = 3*f;
2564 break;
2565 case GL_C4UB_V2F:
2566 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
2567 tcomps = 0; ccomps = 4; vcomps = 2;
2568 ctype = GL_UNSIGNED_BYTE;
2569 coffset = 0;
2570 voffset = c;
2571 defstride = c + 2*f;
2572 break;
2573 case GL_C4UB_V3F:
2574 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
2575 tcomps = 0; ccomps = 4; vcomps = 3;
2576 ctype = GL_UNSIGNED_BYTE;
2577 coffset = 0;
2578 voffset = c;
2579 defstride = c + 3*f;
2580 break;
2581 case GL_C3F_V3F:
2582 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_FALSE;
2583 tcomps = 0; ccomps = 3; vcomps = 3;
2584 ctype = GL_FLOAT;
2585 coffset = 0;
2586 voffset = 3*f;
2587 defstride = 6*f;
2588 break;
2589 case GL_N3F_V3F:
2590 tflag = GL_FALSE; cflag = GL_FALSE; nflag = GL_TRUE;
2591 tcomps = 0; ccomps = 0; vcomps = 3;
2592 noffset = 0;
2593 voffset = 3*f;
2594 defstride = 6*f;
2595 break;
2596 case GL_C4F_N3F_V3F:
2597 tflag = GL_FALSE; cflag = GL_TRUE; nflag = GL_TRUE;
2598 tcomps = 0; ccomps = 4; vcomps = 3;
2599 ctype = GL_FLOAT;
2600 coffset = 0;
2601 noffset = 4*f;
2602 voffset = 7*f;
2603 defstride = 10*f;
2604 break;
2605 case GL_T2F_V3F:
2606 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
2607 tcomps = 2; ccomps = 0; vcomps = 3;
2608 voffset = 2*f;
2609 defstride = 5*f;
2610 break;
2611 case GL_T4F_V4F:
2612 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_FALSE;
2613 tcomps = 4; ccomps = 0; vcomps = 4;
2614 voffset = 4*f;
2615 defstride = 8*f;
2616 break;
2617 case GL_T2F_C4UB_V3F:
2618 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
2619 tcomps = 2; ccomps = 4; vcomps = 3;
2620 ctype = GL_UNSIGNED_BYTE;
2621 coffset = 2*f;
2622 voffset = c+2*f;
2623 defstride = c+5*f;
2624 break;
2625 case GL_T2F_C3F_V3F:
2626 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_FALSE;
2627 tcomps = 2; ccomps = 3; vcomps = 3;
2628 ctype = GL_FLOAT;
2629 coffset = 2*f;
2630 voffset = 5*f;
2631 defstride = 8*f;
2632 break;
2633 case GL_T2F_N3F_V3F:
2634 tflag = GL_TRUE; cflag = GL_FALSE; nflag = GL_TRUE;
2635 tcomps = 2; ccomps = 0; vcomps = 3;
2636 noffset = 2*f;
2637 voffset = 5*f;
2638 defstride = 8*f;
2639 break;
2640 case GL_T2F_C4F_N3F_V3F:
2641 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
2642 tcomps = 2; ccomps = 4; vcomps = 3;
2643 ctype = GL_FLOAT;
2644 coffset = 2*f;
2645 noffset = 6*f;
2646 voffset = 9*f;
2647 defstride = 12*f;
2648 break;
2649 case GL_T4F_C4F_N3F_V4F:
2650 tflag = GL_TRUE; cflag = GL_TRUE; nflag = GL_TRUE;
2651 tcomps = 4; ccomps = 4; vcomps = 4;
2652 ctype = GL_FLOAT;
2653 coffset = 4*f;
2654 noffset = 8*f;
2655 voffset = 11*f;
2656 defstride = 15*f;
2657 break;
2658 default:
2659 _mesa_error( ctx, GL_INVALID_ENUM, "glInterleavedArrays(format)" );
2660 return;
2661 }
2662
2663 if (stride==0) {
2664 stride = defstride;
2665 }
2666
2667 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY );
2668 _mesa_DisableClientState( GL_INDEX_ARRAY );
2669 /* XXX also disable secondary color and generic arrays? */
2670
2671 /* Texcoords */
2672 if (tflag) {
2673 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY );
2674 _mesa_TexCoordPointer( tcomps, GL_FLOAT, stride,
2675 (GLubyte *) pointer + toffset );
2676 }
2677 else {
2678 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY );
2679 }
2680
2681 /* Color */
2682 if (cflag) {
2683 _mesa_EnableClientState( GL_COLOR_ARRAY );
2684 _mesa_ColorPointer( ccomps, ctype, stride,
2685 (GLubyte *) pointer + coffset );
2686 }
2687 else {
2688 _mesa_DisableClientState( GL_COLOR_ARRAY );
2689 }
2690
2691
2692 /* Normals */
2693 if (nflag) {
2694 _mesa_EnableClientState( GL_NORMAL_ARRAY );
2695 _mesa_NormalPointer( GL_FLOAT, stride, (GLubyte *) pointer + noffset );
2696 }
2697 else {
2698 _mesa_DisableClientState( GL_NORMAL_ARRAY );
2699 }
2700
2701 /* Vertices */
2702 _mesa_EnableClientState( GL_VERTEX_ARRAY );
2703 _mesa_VertexPointer( vcomps, GL_FLOAT, stride,
2704 (GLubyte *) pointer + voffset );
2705 }
2706
2707
2708 void GLAPIENTRY
2709 _mesa_LockArraysEXT(GLint first, GLsizei count)
2710 {
2711 GET_CURRENT_CONTEXT(ctx);
2712
2713 if (MESA_VERBOSE & VERBOSE_API)
2714 _mesa_debug(ctx, "glLockArrays %d %d\n", first, count);
2715
2716 if (first < 0) {
2717 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(first)" );
2718 return;
2719 }
2720 if (count <= 0) {
2721 _mesa_error( ctx, GL_INVALID_VALUE, "glLockArraysEXT(count)" );
2722 return;
2723 }
2724 if (ctx->Array.LockCount != 0) {
2725 _mesa_error( ctx, GL_INVALID_OPERATION, "glLockArraysEXT(reentry)" );
2726 return;
2727 }
2728
2729 ctx->Array.LockFirst = first;
2730 ctx->Array.LockCount = count;
2731 }
2732
2733
2734 void GLAPIENTRY
2735 _mesa_UnlockArraysEXT( void )
2736 {
2737 GET_CURRENT_CONTEXT(ctx);
2738
2739 if (MESA_VERBOSE & VERBOSE_API)
2740 _mesa_debug(ctx, "glUnlockArrays\n");
2741
2742 if (ctx->Array.LockCount == 0) {
2743 _mesa_error( ctx, GL_INVALID_OPERATION, "glUnlockArraysEXT(reexit)" );
2744 return;
2745 }
2746
2747 ctx->Array.LockFirst = 0;
2748 ctx->Array.LockCount = 0;
2749 }
2750
2751
2752 static void
2753 primitive_restart_index(struct gl_context *ctx, GLuint index)
2754 {
2755 ctx->Array.RestartIndex = index;
2756 }
2757
2758
2759 /**
2760 * GL_NV_primitive_restart and GL 3.1
2761 */
2762 void GLAPIENTRY
2763 _mesa_PrimitiveRestartIndex_no_error(GLuint index)
2764 {
2765 GET_CURRENT_CONTEXT(ctx);
2766 primitive_restart_index(ctx, index);
2767 }
2768
2769
2770 void GLAPIENTRY
2771 _mesa_PrimitiveRestartIndex(GLuint index)
2772 {
2773 GET_CURRENT_CONTEXT(ctx);
2774
2775 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
2776 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
2777 return;
2778 }
2779
2780 primitive_restart_index(ctx, index);
2781 }
2782
2783
2784 void GLAPIENTRY
2785 _mesa_VertexAttribDivisor_no_error(GLuint index, GLuint divisor)
2786 {
2787 GET_CURRENT_CONTEXT(ctx);
2788
2789 const gl_vert_attrib genericIndex = VERT_ATTRIB_GENERIC(index);
2790 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
2791
2792 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
2793
2794 /* The ARB_vertex_attrib_binding spec says:
2795 *
2796 * "The command
2797 *
2798 * void VertexAttribDivisor(uint index, uint divisor);
2799 *
2800 * is equivalent to (assuming no errors are generated):
2801 *
2802 * VertexAttribBinding(index, index);
2803 * VertexBindingDivisor(index, divisor);"
2804 */
2805 _mesa_vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
2806 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
2807 }
2808
2809
2810 /**
2811 * See GL_ARB_instanced_arrays.
2812 * Note that the instance divisor only applies to generic arrays, not
2813 * the legacy vertex arrays.
2814 */
2815 void GLAPIENTRY
2816 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
2817 {
2818 GET_CURRENT_CONTEXT(ctx);
2819
2820 const gl_vert_attrib genericIndex = VERT_ATTRIB_GENERIC(index);
2821 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
2822
2823 if (!ctx->Extensions.ARB_instanced_arrays) {
2824 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
2825 return;
2826 }
2827
2828 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2829 _mesa_error(ctx, GL_INVALID_VALUE,
2830 "glVertexAttribDivisor(index = %u)", index);
2831 return;
2832 }
2833
2834 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
2835
2836 /* The ARB_vertex_attrib_binding spec says:
2837 *
2838 * "The command
2839 *
2840 * void VertexAttribDivisor(uint index, uint divisor);
2841 *
2842 * is equivalent to (assuming no errors are generated):
2843 *
2844 * VertexAttribBinding(index, index);
2845 * VertexBindingDivisor(index, divisor);"
2846 */
2847 _mesa_vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
2848 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
2849 }
2850
2851
2852 void GLAPIENTRY
2853 _mesa_VertexArrayVertexAttribDivisorEXT(GLuint vaobj, GLuint index, GLuint divisor)
2854 {
2855 GET_CURRENT_CONTEXT(ctx);
2856
2857 const gl_vert_attrib genericIndex = VERT_ATTRIB_GENERIC(index);
2858 struct gl_vertex_array_object * vao;
2859 /* The ARB_instanced_arrays spec says:
2860 *
2861 * "The vertex array object named by vaobj must
2862 * be generated by GenVertexArrays (and not since deleted);
2863 * otherwise an INVALID_OPERATION error is generated."
2864 */
2865 vao = _mesa_lookup_vao_err(ctx, vaobj,
2866 false,
2867 "glVertexArrayVertexAttribDivisorEXT");
2868 if (!vao)
2869 return;
2870
2871 if (!ctx->Extensions.ARB_instanced_arrays) {
2872 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexArrayVertexAttribDivisorEXT()");
2873 return;
2874 }
2875
2876 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2877 _mesa_error(ctx, GL_INVALID_VALUE,
2878 "glVertexArrayVertexAttribDivisorEXT(index = %u)", index);
2879 return;
2880 }
2881
2882 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
2883
2884 /* The ARB_vertex_attrib_binding spec says:
2885 *
2886 * "The command
2887 *
2888 * void VertexAttribDivisor(uint index, uint divisor);
2889 *
2890 * is equivalent to (assuming no errors are generated):
2891 *
2892 * VertexAttribBinding(index, index);
2893 * VertexBindingDivisor(index, divisor);"
2894 */
2895 _mesa_vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
2896 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
2897 }
2898
2899
2900
2901 static ALWAYS_INLINE void
2902 vertex_array_vertex_buffer(struct gl_context *ctx,
2903 struct gl_vertex_array_object *vao,
2904 GLuint bindingIndex, GLuint buffer, GLintptr offset,
2905 GLsizei stride, bool no_error, const char *func)
2906 {
2907 struct gl_buffer_object *vbo;
2908 struct gl_buffer_object *current_buf =
2909 vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
2910
2911 if (current_buf && buffer == current_buf->Name) {
2912 vbo = current_buf;
2913 } else if (buffer != 0) {
2914 vbo = _mesa_lookup_bufferobj(ctx, buffer);
2915
2916 if (!no_error && !vbo && _mesa_is_gles31(ctx)) {
2917 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-gen name)", func);
2918 return;
2919 }
2920 /* From the GL_ARB_vertex_attrib_array spec:
2921 *
2922 * "[Core profile only:]
2923 * An INVALID_OPERATION error is generated if buffer is not zero or a
2924 * name returned from a previous call to GenBuffers, or if such a name
2925 * has since been deleted with DeleteBuffers.
2926 *
2927 * Otherwise, we fall back to the same compat profile behavior as other
2928 * object references (automatically gen it).
2929 */
2930 if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &vbo, func))
2931 return;
2932 } else {
2933 /* The ARB_vertex_attrib_binding spec says:
2934 *
2935 * "If <buffer> is zero, any buffer object attached to this
2936 * bindpoint is detached."
2937 */
2938 vbo = NULL;
2939 }
2940
2941 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex),
2942 vbo, offset, stride);
2943 }
2944
2945
2946 /**
2947 * GL_ARB_vertex_attrib_binding
2948 */
2949 static void
2950 vertex_array_vertex_buffer_err(struct gl_context *ctx,
2951 struct gl_vertex_array_object *vao,
2952 GLuint bindingIndex, GLuint buffer,
2953 GLintptr offset, GLsizei stride,
2954 const char *func)
2955 {
2956 ASSERT_OUTSIDE_BEGIN_END(ctx);
2957
2958 /* The ARB_vertex_attrib_binding spec says:
2959 *
2960 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2961 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2962 */
2963 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2964 _mesa_error(ctx, GL_INVALID_VALUE,
2965 "%s(bindingindex=%u > "
2966 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2967 func, bindingIndex);
2968 return;
2969 }
2970
2971 /* The ARB_vertex_attrib_binding spec says:
2972 *
2973 * "The error INVALID_VALUE is generated if <stride> or <offset>
2974 * are negative."
2975 */
2976 if (offset < 0) {
2977 _mesa_error(ctx, GL_INVALID_VALUE,
2978 "%s(offset=%" PRId64 " < 0)",
2979 func, (int64_t) offset);
2980 return;
2981 }
2982
2983 if (stride < 0) {
2984 _mesa_error(ctx, GL_INVALID_VALUE,
2985 "%s(stride=%d < 0)", func, stride);
2986 return;
2987 }
2988
2989 if (((_mesa_is_desktop_gl(ctx) && ctx->Version >= 44) || _mesa_is_gles31(ctx)) &&
2990 stride > ctx->Const.MaxVertexAttribStride) {
2991 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
2992 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
2993 return;
2994 }
2995
2996 vertex_array_vertex_buffer(ctx, vao, bindingIndex, buffer, offset,
2997 stride, false, func);
2998 }
2999
3000
3001 void GLAPIENTRY
3002 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex, GLuint buffer,
3003 GLintptr offset, GLsizei stride)
3004 {
3005 GET_CURRENT_CONTEXT(ctx);
3006 vertex_array_vertex_buffer(ctx, ctx->Array.VAO, bindingIndex,
3007 buffer, offset, stride, true,
3008 "glBindVertexBuffer");
3009 }
3010
3011
3012 void GLAPIENTRY
3013 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
3014 GLsizei stride)
3015 {
3016 GET_CURRENT_CONTEXT(ctx);
3017
3018 /* The ARB_vertex_attrib_binding spec says:
3019 *
3020 * "An INVALID_OPERATION error is generated if no vertex array object
3021 * is bound."
3022 */
3023 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
3024 ctx->Array.VAO == ctx->Array.DefaultVAO) {
3025 _mesa_error(ctx, GL_INVALID_OPERATION,
3026 "glBindVertexBuffer(No array object bound)");
3027 return;
3028 }
3029
3030 vertex_array_vertex_buffer_err(ctx, ctx->Array.VAO, bindingIndex,
3031 buffer, offset, stride,
3032 "glBindVertexBuffer");
3033 }
3034
3035
3036 void GLAPIENTRY
3037 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj, GLuint bindingIndex,
3038 GLuint buffer, GLintptr offset,
3039 GLsizei stride)
3040 {
3041 GET_CURRENT_CONTEXT(ctx);
3042
3043 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
3044 vertex_array_vertex_buffer(ctx, vao, bindingIndex, buffer, offset,
3045 stride, true, "glVertexArrayVertexBuffer");
3046 }
3047
3048
3049 void GLAPIENTRY
3050 _mesa_VertexArrayVertexBuffer(GLuint vaobj, GLuint bindingIndex, GLuint buffer,
3051 GLintptr offset, GLsizei stride)
3052 {
3053 GET_CURRENT_CONTEXT(ctx);
3054 struct gl_vertex_array_object *vao;
3055
3056 /* The ARB_direct_state_access specification says:
3057 *
3058 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
3059 * if <vaobj> is not [compatibility profile: zero or] the name of an
3060 * existing vertex array object."
3061 */
3062 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glVertexArrayVertexBuffer");
3063 if (!vao)
3064 return;
3065
3066 vertex_array_vertex_buffer_err(ctx, vao, bindingIndex, buffer, offset,
3067 stride, "glVertexArrayVertexBuffer");
3068 }
3069
3070
3071 void GLAPIENTRY
3072 _mesa_VertexArrayBindVertexBufferEXT(GLuint vaobj, GLuint bindingIndex, GLuint buffer,
3073 GLintptr offset, GLsizei stride)
3074 {
3075 GET_CURRENT_CONTEXT(ctx);
3076 struct gl_vertex_array_object *vao;
3077 vao = _mesa_lookup_vao_err(ctx, vaobj, true, "glVertexArrayBindVertexBufferEXT");
3078 if (!vao)
3079 return;
3080
3081 vertex_array_vertex_buffer_err(ctx, vao, bindingIndex, buffer, offset,
3082 stride, "glVertexArrayBindVertexBufferEXT");
3083 }
3084
3085
3086 static ALWAYS_INLINE void
3087 vertex_array_vertex_buffers(struct gl_context *ctx,
3088 struct gl_vertex_array_object *vao,
3089 GLuint first, GLsizei count, const GLuint *buffers,
3090 const GLintptr *offsets, const GLsizei *strides,
3091 bool no_error, const char *func)
3092 {
3093 GLint i;
3094
3095 if (!buffers) {
3096 /**
3097 * The ARB_multi_bind spec says:
3098 *
3099 * "If <buffers> is NULL, each affected vertex buffer binding point
3100 * from <first> through <first>+<count>-1 will be reset to have no
3101 * bound buffer object. In this case, the offsets and strides
3102 * associated with the binding points are set to default values,
3103 * ignoring <offsets> and <strides>."
3104 */
3105 for (i = 0; i < count; i++)
3106 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
3107 NULL, 0, 16);
3108
3109 return;
3110 }
3111
3112 /* Note that the error semantics for multi-bind commands differ from
3113 * those of other GL commands.
3114 *
3115 * The Issues section in the ARB_multi_bind spec says:
3116 *
3117 * "(11) Typically, OpenGL specifies that if an error is generated by
3118 * a command, that command has no effect. This is somewhat
3119 * unfortunate for multi-bind commands, because it would require
3120 * a first pass to scan the entire list of bound objects for
3121 * errors and then a second pass to actually perform the
3122 * bindings. Should we have different error semantics?
3123 *
3124 * RESOLVED: Yes. In this specification, when the parameters for
3125 * one of the <count> binding points are invalid, that binding
3126 * point is not updated and an error will be generated. However,
3127 * other binding points in the same command will be updated if
3128 * their parameters are valid and no other error occurs."
3129 */
3130
3131 _mesa_HashLockMutex(ctx->Shared->BufferObjects);
3132
3133 for (i = 0; i < count; i++) {
3134 struct gl_buffer_object *vbo;
3135
3136 if (!no_error) {
3137 /* The ARB_multi_bind spec says:
3138 *
3139 * "An INVALID_VALUE error is generated if any value in
3140 * <offsets> or <strides> is negative (per binding)."
3141 */
3142 if (offsets[i] < 0) {
3143 _mesa_error(ctx, GL_INVALID_VALUE,
3144 "%s(offsets[%u]=%" PRId64 " < 0)",
3145 func, i, (int64_t) offsets[i]);
3146 continue;
3147 }
3148
3149 if (strides[i] < 0) {
3150 _mesa_error(ctx, GL_INVALID_VALUE,
3151 "%s(strides[%u]=%d < 0)",
3152 func, i, strides[i]);
3153 continue;
3154 }
3155
3156 if (_mesa_is_desktop_gl(ctx) && ctx->Version >= 44 &&
3157 strides[i] > ctx->Const.MaxVertexAttribStride) {
3158 _mesa_error(ctx, GL_INVALID_VALUE,
3159 "%s(strides[%u]=%d > "
3160 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, i, strides[i]);
3161 continue;
3162 }
3163 }
3164
3165 if (buffers[i]) {
3166 struct gl_vertex_buffer_binding *binding =
3167 &vao->BufferBinding[VERT_ATTRIB_GENERIC(first + i)];
3168
3169 if (buffers[i] == 0)
3170 vbo = NULL;
3171 else if (binding->BufferObj && binding->BufferObj->Name == buffers[i])
3172 vbo = binding->BufferObj;
3173 else {
3174 vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, func);
3175 if (!vbo)
3176 continue;
3177
3178 /* TODO: remove this hack */
3179 if (vbo == ctx->Shared->NullBufferObj)
3180 vbo = NULL;
3181 }
3182 } else {
3183 vbo = NULL;
3184 }
3185
3186 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
3187 vbo, offsets[i], strides[i]);
3188 }
3189
3190 _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
3191 }
3192
3193
3194 static void
3195 vertex_array_vertex_buffers_err(struct gl_context *ctx,
3196 struct gl_vertex_array_object *vao,
3197 GLuint first, GLsizei count,
3198 const GLuint *buffers, const GLintptr *offsets,
3199 const GLsizei *strides, const char *func)
3200 {
3201 ASSERT_OUTSIDE_BEGIN_END(ctx);
3202
3203 /* The ARB_multi_bind spec says:
3204 *
3205 * "An INVALID_OPERATION error is generated if <first> + <count>
3206 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
3207 */
3208 if (first + count > ctx->Const.MaxVertexAttribBindings) {
3209 _mesa_error(ctx, GL_INVALID_OPERATION,
3210 "%s(first=%u + count=%d > the value of "
3211 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
3212 func, first, count, ctx->Const.MaxVertexAttribBindings);
3213 return;
3214 }
3215
3216 vertex_array_vertex_buffers(ctx, vao, first, count, buffers, offsets,
3217 strides, false, func);
3218 }
3219
3220
3221 void GLAPIENTRY
3222 _mesa_BindVertexBuffers_no_error(GLuint first, GLsizei count,
3223 const GLuint *buffers, const GLintptr *offsets,
3224 const GLsizei *strides)
3225 {
3226 GET_CURRENT_CONTEXT(ctx);
3227
3228 vertex_array_vertex_buffers(ctx, ctx->Array.VAO, first, count,
3229 buffers, offsets, strides, true,
3230 "glBindVertexBuffers");
3231 }
3232
3233
3234 void GLAPIENTRY
3235 _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
3236 const GLintptr *offsets, const GLsizei *strides)
3237 {
3238 GET_CURRENT_CONTEXT(ctx);
3239
3240 /* The ARB_vertex_attrib_binding spec says:
3241 *
3242 * "An INVALID_OPERATION error is generated if no
3243 * vertex array object is bound."
3244 */
3245 if (ctx->API == API_OPENGL_CORE &&
3246 ctx->Array.VAO == ctx->Array.DefaultVAO) {
3247 _mesa_error(ctx, GL_INVALID_OPERATION,
3248 "glBindVertexBuffers(No array object bound)");
3249 return;
3250 }
3251
3252 vertex_array_vertex_buffers_err(ctx, ctx->Array.VAO, first, count,
3253 buffers, offsets, strides,
3254 "glBindVertexBuffers");
3255 }
3256
3257
3258 void GLAPIENTRY
3259 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj, GLuint first,
3260 GLsizei count, const GLuint *buffers,
3261 const GLintptr *offsets,
3262 const GLsizei *strides)
3263 {
3264 GET_CURRENT_CONTEXT(ctx);
3265
3266 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
3267 vertex_array_vertex_buffers(ctx, vao, first, count,
3268 buffers, offsets, strides, true,
3269 "glVertexArrayVertexBuffers");
3270 }
3271
3272
3273 void GLAPIENTRY
3274 _mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count,
3275 const GLuint *buffers,
3276 const GLintptr *offsets, const GLsizei *strides)
3277 {
3278 GET_CURRENT_CONTEXT(ctx);
3279 struct gl_vertex_array_object *vao;
3280
3281 /* The ARB_direct_state_access specification says:
3282 *
3283 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
3284 * if <vaobj> is not [compatibility profile: zero or] the name of an
3285 * existing vertex array object."
3286 */
3287 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glVertexArrayVertexBuffers");
3288 if (!vao)
3289 return;
3290
3291 vertex_array_vertex_buffers_err(ctx, vao, first, count,
3292 buffers, offsets, strides,
3293 "glVertexArrayVertexBuffers");
3294 }
3295
3296
3297 static void
3298 vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type,
3299 GLboolean normalized, GLboolean integer,
3300 GLboolean doubles, GLbitfield legalTypes,
3301 GLsizei sizeMax, GLuint relativeOffset,
3302 const char *func)
3303 {
3304 GET_CURRENT_CONTEXT(ctx);
3305 ASSERT_OUTSIDE_BEGIN_END(ctx);
3306
3307 GLenum format = get_array_format(ctx, sizeMax, &size);
3308
3309 if (!_mesa_is_no_error_enabled(ctx)) {
3310 /* The ARB_vertex_attrib_binding spec says:
3311 *
3312 * "An INVALID_OPERATION error is generated under any of the
3313 * following conditions:
3314 * - if no vertex array object is currently bound (see section
3315 * 2.10);
3316 * - ..."
3317 *
3318 * This error condition only applies to VertexAttribFormat and
3319 * VertexAttribIFormat in the extension spec, but we assume that this
3320 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
3321 * to all three functions.
3322 */
3323 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
3324 ctx->Array.VAO == ctx->Array.DefaultVAO) {
3325 _mesa_error(ctx, GL_INVALID_OPERATION,
3326 "%s(No array object bound)", func);
3327 return;
3328 }
3329
3330 /* The ARB_vertex_attrib_binding spec says:
3331 *
3332 * "The error INVALID_VALUE is generated if index is greater than or
3333 * equal to the value of MAX_VERTEX_ATTRIBS."
3334 */
3335 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
3336 _mesa_error(ctx, GL_INVALID_VALUE,
3337 "%s(attribindex=%u > "
3338 "GL_MAX_VERTEX_ATTRIBS)",
3339 func, attribIndex);
3340 return;
3341 }
3342
3343 if (!validate_array_format(ctx, func, ctx->Array.VAO,
3344 VERT_ATTRIB_GENERIC(attribIndex),
3345 legalTypes, 1, sizeMax, size, type,
3346 normalized, integer, doubles, relativeOffset,
3347 format)) {
3348 return;
3349 }
3350 }
3351
3352 _mesa_update_array_format(ctx, ctx->Array.VAO,
3353 VERT_ATTRIB_GENERIC(attribIndex), size, type,
3354 format, normalized, integer, doubles,
3355 relativeOffset);
3356 }
3357
3358
3359 void GLAPIENTRY
3360 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
3361 GLboolean normalized, GLuint relativeOffset)
3362 {
3363 vertex_attrib_format(attribIndex, size, type, normalized,
3364 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
3365 BGRA_OR_4, relativeOffset,
3366 "glVertexAttribFormat");
3367 }
3368
3369
3370 void GLAPIENTRY
3371 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
3372 GLuint relativeOffset)
3373 {
3374 vertex_attrib_format(attribIndex, size, type, GL_FALSE,
3375 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK, 4,
3376 relativeOffset, "glVertexAttribIFormat");
3377 }
3378
3379
3380 void GLAPIENTRY
3381 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
3382 GLuint relativeOffset)
3383 {
3384 vertex_attrib_format(attribIndex, size, type, GL_FALSE, GL_FALSE,
3385 GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK, 4,
3386 relativeOffset, "glVertexAttribLFormat");
3387 }
3388
3389
3390 static void
3391 vertex_array_attrib_format(GLuint vaobj, bool isExtDsa, GLuint attribIndex,
3392 GLint size, GLenum type, GLboolean normalized,
3393 GLboolean integer, GLboolean doubles,
3394 GLbitfield legalTypes, GLsizei sizeMax,
3395 GLuint relativeOffset, const char *func)
3396 {
3397 GET_CURRENT_CONTEXT(ctx);
3398 struct gl_vertex_array_object *vao;
3399
3400 ASSERT_OUTSIDE_BEGIN_END(ctx);
3401
3402 GLenum format = get_array_format(ctx, sizeMax, &size);
3403
3404 if (_mesa_is_no_error_enabled(ctx)) {
3405 vao = _mesa_lookup_vao(ctx, vaobj);
3406 if (!vao)
3407 return;
3408 } else {
3409 vao = _mesa_lookup_vao_err(ctx, vaobj, isExtDsa, func);
3410 if (!vao)
3411 return;
3412
3413 /* The ARB_vertex_attrib_binding spec says:
3414 *
3415 * "The error INVALID_VALUE is generated if index is greater than or
3416 * equal to the value of MAX_VERTEX_ATTRIBS."
3417 */
3418 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
3419 _mesa_error(ctx, GL_INVALID_VALUE,
3420 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
3421 func, attribIndex);
3422 return;
3423 }
3424
3425 if (!validate_array_format(ctx, func, vao,
3426 VERT_ATTRIB_GENERIC(attribIndex),
3427 legalTypes, 1, sizeMax, size, type,
3428 normalized, integer, doubles, relativeOffset,
3429 format)) {
3430 return;
3431 }
3432 }
3433
3434 _mesa_update_array_format(ctx, vao, VERT_ATTRIB_GENERIC(attribIndex), size,
3435 type, format, normalized, integer, doubles,
3436 relativeOffset);
3437 }
3438
3439
3440 void GLAPIENTRY
3441 _mesa_VertexArrayAttribFormat(GLuint vaobj, GLuint attribIndex, GLint size,
3442 GLenum type, GLboolean normalized,
3443 GLuint relativeOffset)
3444 {
3445 vertex_array_attrib_format(vaobj, false, attribIndex, size, type, normalized,
3446 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
3447 BGRA_OR_4, relativeOffset,
3448 "glVertexArrayAttribFormat");
3449 }
3450
3451
3452 void GLAPIENTRY
3453 _mesa_VertexArrayVertexAttribFormatEXT(GLuint vaobj, GLuint attribIndex, GLint size,
3454 GLenum type, GLboolean normalized,
3455 GLuint relativeOffset)
3456 {
3457 vertex_array_attrib_format(vaobj, true, attribIndex, size, type, normalized,
3458 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
3459 BGRA_OR_4, relativeOffset,
3460 "glVertexArrayVertexAttribFormatEXT");
3461 }
3462
3463
3464 void GLAPIENTRY
3465 _mesa_VertexArrayAttribIFormat(GLuint vaobj, GLuint attribIndex,
3466 GLint size, GLenum type,
3467 GLuint relativeOffset)
3468 {
3469 vertex_array_attrib_format(vaobj, false, attribIndex, size, type, GL_FALSE,
3470 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK,
3471 4, relativeOffset,
3472 "glVertexArrayAttribIFormat");
3473 }
3474
3475
3476 void GLAPIENTRY
3477 _mesa_VertexArrayVertexAttribIFormatEXT(GLuint vaobj, GLuint attribIndex,
3478 GLint size, GLenum type,
3479 GLuint relativeOffset)
3480 {
3481 vertex_array_attrib_format(vaobj, true, attribIndex, size, type, GL_FALSE,
3482 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK,
3483 4, relativeOffset,
3484 "glVertexArrayVertexAttribIFormatEXT");
3485 }
3486
3487
3488 void GLAPIENTRY
3489 _mesa_VertexArrayAttribLFormat(GLuint vaobj, GLuint attribIndex,
3490 GLint size, GLenum type,
3491 GLuint relativeOffset)
3492 {
3493 vertex_array_attrib_format(vaobj, false, attribIndex, size, type, GL_FALSE,
3494 GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK,
3495 4, relativeOffset,
3496 "glVertexArrayAttribLFormat");
3497 }
3498
3499
3500 void GLAPIENTRY
3501 _mesa_VertexArrayVertexAttribLFormatEXT(GLuint vaobj, GLuint attribIndex,
3502 GLint size, GLenum type,
3503 GLuint relativeOffset)
3504 {
3505 vertex_array_attrib_format(vaobj, true, attribIndex, size, type, GL_FALSE,
3506 GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK,
3507 4, relativeOffset,
3508 "glVertexArrayVertexAttribLFormatEXT");
3509 }
3510
3511
3512 static void
3513 vertex_array_attrib_binding(struct gl_context *ctx,
3514 struct gl_vertex_array_object *vao,
3515 GLuint attribIndex, GLuint bindingIndex,
3516 const char *func)
3517 {
3518 ASSERT_OUTSIDE_BEGIN_END(ctx);
3519
3520 /* The ARB_vertex_attrib_binding spec says:
3521 *
3522 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
3523 * <bindingindex> must be less than the value of
3524 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
3525 * is generated."
3526 */
3527 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
3528 _mesa_error(ctx, GL_INVALID_VALUE,
3529 "%s(attribindex=%u >= "
3530 "GL_MAX_VERTEX_ATTRIBS)",
3531 func, attribIndex);
3532 return;
3533 }
3534
3535 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
3536 _mesa_error(ctx, GL_INVALID_VALUE,
3537 "%s(bindingindex=%u >= "
3538 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
3539 func, bindingIndex);
3540 return;
3541 }
3542
3543 assert(VERT_ATTRIB_GENERIC(attribIndex) < ARRAY_SIZE(vao->VertexAttrib));
3544
3545 _mesa_vertex_attrib_binding(ctx, vao,
3546 VERT_ATTRIB_GENERIC(attribIndex),
3547 VERT_ATTRIB_GENERIC(bindingIndex));
3548 }
3549
3550
3551 void GLAPIENTRY
3552 _mesa_VertexAttribBinding_no_error(GLuint attribIndex, GLuint bindingIndex)
3553 {
3554 GET_CURRENT_CONTEXT(ctx);
3555 _mesa_vertex_attrib_binding(ctx, ctx->Array.VAO,
3556 VERT_ATTRIB_GENERIC(attribIndex),
3557 VERT_ATTRIB_GENERIC(bindingIndex));
3558 }
3559
3560
3561 void GLAPIENTRY
3562 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3563 {
3564 GET_CURRENT_CONTEXT(ctx);
3565
3566 /* The ARB_vertex_attrib_binding spec says:
3567 *
3568 * "An INVALID_OPERATION error is generated if no vertex array object
3569 * is bound."
3570 */
3571 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
3572 ctx->Array.VAO == ctx->Array.DefaultVAO) {
3573 _mesa_error(ctx, GL_INVALID_OPERATION,
3574 "glVertexAttribBinding(No array object bound)");
3575 return;
3576 }
3577
3578 vertex_array_attrib_binding(ctx, ctx->Array.VAO,
3579 attribIndex, bindingIndex,
3580 "glVertexAttribBinding");
3581 }
3582
3583
3584 void GLAPIENTRY
3585 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj, GLuint attribIndex,
3586 GLuint bindingIndex)
3587 {
3588 GET_CURRENT_CONTEXT(ctx);
3589
3590 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
3591 _mesa_vertex_attrib_binding(ctx, vao,
3592 VERT_ATTRIB_GENERIC(attribIndex),
3593 VERT_ATTRIB_GENERIC(bindingIndex));
3594 }
3595
3596
3597 void GLAPIENTRY
3598 _mesa_VertexArrayAttribBinding(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex)
3599 {
3600 GET_CURRENT_CONTEXT(ctx);
3601 struct gl_vertex_array_object *vao;
3602
3603 /* The ARB_direct_state_access specification says:
3604 *
3605 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
3606 * if <vaobj> is not [compatibility profile: zero or] the name of an
3607 * existing vertex array object."
3608 */
3609 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glVertexArrayAttribBinding");
3610 if (!vao)
3611 return;
3612
3613 vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex,
3614 "glVertexArrayAttribBinding");
3615 }
3616
3617
3618 void GLAPIENTRY
3619 _mesa_VertexArrayVertexAttribBindingEXT(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex)
3620 {
3621 GET_CURRENT_CONTEXT(ctx);
3622 struct gl_vertex_array_object *vao;
3623 vao = _mesa_lookup_vao_err(ctx, vaobj, true, "glVertexArrayVertexAttribBindingEXT");
3624 if (!vao)
3625 return;
3626
3627 vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex,
3628 "glVertexArrayVertexAttribBindingEXT");
3629 }
3630
3631
3632 static void
3633 vertex_array_binding_divisor(struct gl_context *ctx,
3634 struct gl_vertex_array_object *vao,
3635 GLuint bindingIndex, GLuint divisor,
3636 const char *func)
3637 {
3638 ASSERT_OUTSIDE_BEGIN_END(ctx);
3639
3640 if (!ctx->Extensions.ARB_instanced_arrays) {
3641 _mesa_error(ctx, GL_INVALID_OPERATION, "%s()", func);
3642 return;
3643 }
3644
3645 /* The ARB_vertex_attrib_binding spec says:
3646 *
3647 * "An INVALID_VALUE error is generated if <bindingindex> is greater
3648 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
3649 */
3650 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
3651 _mesa_error(ctx, GL_INVALID_VALUE,
3652 "%s(bindingindex=%u > "
3653 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
3654 func, bindingIndex);
3655 return;
3656 }
3657
3658 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
3659 }
3660
3661
3662 void GLAPIENTRY
3663 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex, GLuint divisor)
3664 {
3665 GET_CURRENT_CONTEXT(ctx);
3666 vertex_binding_divisor(ctx, ctx->Array.VAO,
3667 VERT_ATTRIB_GENERIC(bindingIndex), divisor);
3668 }
3669
3670
3671 void GLAPIENTRY
3672 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3673 {
3674 GET_CURRENT_CONTEXT(ctx);
3675
3676 /* The ARB_vertex_attrib_binding spec says:
3677 *
3678 * "An INVALID_OPERATION error is generated if no vertex array object
3679 * is bound."
3680 */
3681 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
3682 ctx->Array.VAO == ctx->Array.DefaultVAO) {
3683 _mesa_error(ctx, GL_INVALID_OPERATION,
3684 "glVertexBindingDivisor(No array object bound)");
3685 return;
3686 }
3687
3688 vertex_array_binding_divisor(ctx, ctx->Array.VAO,
3689 bindingIndex, divisor,
3690 "glVertexBindingDivisor");
3691 }
3692
3693
3694 void GLAPIENTRY
3695 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj, GLuint bindingIndex,
3696 GLuint divisor)
3697 {
3698 GET_CURRENT_CONTEXT(ctx);
3699
3700 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
3701 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
3702 }
3703
3704
3705 void GLAPIENTRY
3706 _mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex,
3707 GLuint divisor)
3708 {
3709 struct gl_vertex_array_object *vao;
3710 GET_CURRENT_CONTEXT(ctx);
3711
3712 /* The ARB_direct_state_access specification says:
3713 *
3714 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
3715 * if <vaobj> is not [compatibility profile: zero or] the name of an
3716 * existing vertex array object."
3717 */
3718 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glVertexArrayBindingDivisor");
3719 if (!vao)
3720 return;
3721
3722 vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor,
3723 "glVertexArrayBindingDivisor");
3724 }
3725
3726
3727 void GLAPIENTRY
3728 _mesa_VertexArrayVertexBindingDivisorEXT(GLuint vaobj, GLuint bindingIndex,
3729 GLuint divisor)
3730 {
3731 struct gl_vertex_array_object *vao;
3732 GET_CURRENT_CONTEXT(ctx);
3733
3734 /* The ARB_direct_state_access specification says:
3735 *
3736 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
3737 * if <vaobj> is not [compatibility profile: zero or] the name of an
3738 * existing vertex array object."
3739 */
3740 vao = _mesa_lookup_vao_err(ctx, vaobj, true, "glVertexArrayVertexBindingDivisorEXT");
3741 if (!vao)
3742 return;
3743
3744 vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor,
3745 "glVertexArrayVertexBindingDivisorEXT");
3746 }
3747
3748
3749 void
3750 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
3751 struct gl_array_attributes *dst,
3752 const struct gl_array_attributes *src)
3753 {
3754 dst->Ptr = src->Ptr;
3755 dst->RelativeOffset = src->RelativeOffset;
3756 dst->Format = src->Format;
3757 dst->Stride = src->Stride;
3758 dst->BufferBindingIndex = src->BufferBindingIndex;
3759 dst->_EffBufferBindingIndex = src->_EffBufferBindingIndex;
3760 dst->_EffRelativeOffset = src->_EffRelativeOffset;
3761 }
3762
3763 void
3764 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
3765 struct gl_vertex_buffer_binding *dst,
3766 const struct gl_vertex_buffer_binding *src)
3767 {
3768 dst->Offset = src->Offset;
3769 dst->Stride = src->Stride;
3770 dst->InstanceDivisor = src->InstanceDivisor;
3771 dst->_BoundArrays = src->_BoundArrays;
3772 dst->_EffBoundArrays = src->_EffBoundArrays;
3773 dst->_EffOffset = src->_EffOffset;
3774
3775 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
3776 }
3777
3778 /**
3779 * Print current vertex object/array info. For debug.
3780 */
3781 void
3782 _mesa_print_arrays(struct gl_context *ctx)
3783 {
3784 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
3785
3786 fprintf(stderr, "Array Object %u\n", vao->Name);
3787
3788 GLbitfield mask = vao->Enabled;
3789 while (mask) {
3790 const gl_vert_attrib i = u_bit_scan(&mask);
3791 const struct gl_array_attributes *array = &vao->VertexAttrib[i];
3792
3793 const struct gl_vertex_buffer_binding *binding =
3794 &vao->BufferBinding[array->BufferBindingIndex];
3795 const struct gl_buffer_object *bo = binding->BufferObj;
3796
3797 fprintf(stderr, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
3798 "Stride=%d, Buffer=%u(Size %lu)\n",
3799 gl_vert_attrib_name((gl_vert_attrib)i),
3800 array->Ptr, _mesa_enum_to_string(array->Format.Type),
3801 array->Format.Size,
3802 array->Format._ElementSize, binding->Stride, bo ? bo->Name : 0,
3803 (unsigned long) bo ? bo->Size : 0);
3804 }
3805 }
3806
3807 /**
3808 * Initialize attributes of a vertex array within a vertex array object.
3809 * \param vao the container vertex array object
3810 * \param index which array in the VAO to initialize
3811 * \param size number of components (1, 2, 3 or 4) per attribute
3812 * \param type datatype of the attribute (GL_FLOAT, GL_INT, etc).
3813 */
3814 static void
3815 init_array(struct gl_context *ctx,
3816 struct gl_vertex_array_object *vao,
3817 gl_vert_attrib index, GLint size, GLint type)
3818 {
3819 assert(index < ARRAY_SIZE(vao->VertexAttrib));
3820 struct gl_array_attributes *array = &vao->VertexAttrib[index];
3821 assert(index < ARRAY_SIZE(vao->BufferBinding));
3822 struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index];
3823
3824 _mesa_set_vertex_format(&array->Format, size, type, GL_RGBA,
3825 GL_FALSE, GL_FALSE, GL_FALSE);
3826 array->Stride = 0;
3827 array->Ptr = NULL;
3828 array->RelativeOffset = 0;
3829 ASSERT_BITFIELD_SIZE(struct gl_array_attributes, BufferBindingIndex,
3830 VERT_ATTRIB_MAX - 1);
3831 array->BufferBindingIndex = index;
3832
3833 binding->Offset = 0;
3834 binding->Stride = array->Format._ElementSize;
3835 binding->BufferObj = NULL;
3836 binding->_BoundArrays = BITFIELD_BIT(index);
3837 }
3838
3839 static void
3840 init_default_vao_state(struct gl_context *ctx)
3841 {
3842 struct gl_vertex_array_object *vao = &ctx->Array.DefaultVAOState;
3843
3844 vao->RefCount = 1;
3845 vao->SharedAndImmutable = false;
3846
3847 /* Init the individual arrays */
3848 for (unsigned i = 0; i < ARRAY_SIZE(vao->VertexAttrib); i++) {
3849 switch (i) {
3850 case VERT_ATTRIB_NORMAL:
3851 init_array(ctx, vao, VERT_ATTRIB_NORMAL, 3, GL_FLOAT);
3852 break;
3853 case VERT_ATTRIB_COLOR1:
3854 init_array(ctx, vao, VERT_ATTRIB_COLOR1, 3, GL_FLOAT);
3855 break;
3856 case VERT_ATTRIB_FOG:
3857 init_array(ctx, vao, VERT_ATTRIB_FOG, 1, GL_FLOAT);
3858 break;
3859 case VERT_ATTRIB_COLOR_INDEX:
3860 init_array(ctx, vao, VERT_ATTRIB_COLOR_INDEX, 1, GL_FLOAT);
3861 break;
3862 case VERT_ATTRIB_EDGEFLAG:
3863 init_array(ctx, vao, VERT_ATTRIB_EDGEFLAG, 1, GL_UNSIGNED_BYTE);
3864 break;
3865 case VERT_ATTRIB_POINT_SIZE:
3866 init_array(ctx, vao, VERT_ATTRIB_POINT_SIZE, 1, GL_FLOAT);
3867 break;
3868 default:
3869 init_array(ctx, vao, i, 4, GL_FLOAT);
3870 break;
3871 }
3872 }
3873
3874 vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_IDENTITY;
3875 }
3876
3877 /**
3878 * Initialize vertex array state for given context.
3879 */
3880 void
3881 _mesa_init_varray(struct gl_context *ctx)
3882 {
3883 init_default_vao_state(ctx);
3884
3885 ctx->Array.DefaultVAO = _mesa_new_vao(ctx, 0);
3886 _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO);
3887 ctx->Array._EmptyVAO = _mesa_new_vao(ctx, ~0u);
3888 _mesa_reference_vao(ctx, &ctx->Array._DrawVAO, ctx->Array._EmptyVAO);
3889 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
3890
3891 ctx->Array.Objects = _mesa_NewHashTable();
3892 }
3893
3894
3895 /**
3896 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
3897 */
3898 static void
3899 delete_arrayobj_cb(GLuint id, void *data, void *userData)
3900 {
3901 struct gl_vertex_array_object *vao = (struct gl_vertex_array_object *) data;
3902 struct gl_context *ctx = (struct gl_context *) userData;
3903 _mesa_delete_vao(ctx, vao);
3904 }
3905
3906
3907 /**
3908 * Free vertex array state for given context.
3909 */
3910 void
3911 _mesa_free_varray_data(struct gl_context *ctx)
3912 {
3913 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
3914 _mesa_DeleteHashTable(ctx->Array.Objects);
3915 }
3916
3917 void GLAPIENTRY
3918 _mesa_GetVertexArrayIntegervEXT(GLuint vaobj, GLenum pname, GLint *param)
3919 {
3920 GET_CURRENT_CONTEXT(ctx);
3921 struct gl_vertex_array_object* vao;
3922 struct gl_buffer_object *buf;
3923 void* ptr;
3924
3925 vao = _mesa_lookup_vao_err(ctx, vaobj, true,
3926 "glGetVertexArrayIntegervEXT");
3927 if (!vao)
3928 return;
3929
3930 /* The EXT_direct_state_access spec says:
3931 *
3932 * "For GetVertexArrayIntegervEXT, pname must be one of the "Get value" tokens
3933 * in tables 6.6, 6.7, 6.8, and 6.9 that use GetIntegerv, IsEnabled, or
3934 * GetPointerv for their "Get command" (so excluding the VERTEX_ATTRIB_*
3935 * tokens)."
3936 */
3937 switch (pname) {
3938 /* Tokens using GetIntegerv */
3939 case GL_CLIENT_ACTIVE_TEXTURE:
3940 *param = GL_TEXTURE0_ARB + ctx->Array.ActiveTexture;
3941 break;
3942 case GL_VERTEX_ARRAY_SIZE:
3943 *param = vao->VertexAttrib[VERT_ATTRIB_POS].Format.Size;
3944 break;
3945 case GL_VERTEX_ARRAY_TYPE:
3946 *param = vao->VertexAttrib[VERT_ATTRIB_POS].Format.Type;
3947 break;
3948 case GL_VERTEX_ARRAY_STRIDE:
3949 *param = vao->VertexAttrib[VERT_ATTRIB_POS].Stride;
3950 break;
3951 case GL_VERTEX_ARRAY_BUFFER_BINDING:
3952 buf = vao->BufferBinding[VERT_ATTRIB_POS].BufferObj;
3953 *param = buf ? buf->Name : 0;
3954 break;
3955 case GL_COLOR_ARRAY_SIZE:
3956 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR0].Format.Size;
3957 break;
3958 case GL_COLOR_ARRAY_TYPE:
3959 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR0].Format.Type;
3960 break;
3961 case GL_COLOR_ARRAY_STRIDE:
3962 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR0].Stride;
3963 break;
3964 case GL_COLOR_ARRAY_BUFFER_BINDING:
3965 buf = vao->BufferBinding[VERT_ATTRIB_COLOR0].BufferObj;
3966 *param = buf ? buf->Name : 0;
3967 break;
3968 case GL_EDGE_FLAG_ARRAY_STRIDE:
3969 *param = vao->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Stride;
3970 break;
3971 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING:
3972 buf = vao->BufferBinding[VERT_ATTRIB_EDGEFLAG].BufferObj;
3973 *param = buf ? buf->Name : 0;
3974 break;
3975 case GL_INDEX_ARRAY_TYPE:
3976 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Format.Type;
3977 break;
3978 case GL_INDEX_ARRAY_STRIDE:
3979 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Stride;
3980 break;
3981 case GL_INDEX_ARRAY_BUFFER_BINDING:
3982 buf = vao->BufferBinding[VERT_ATTRIB_COLOR_INDEX].BufferObj;
3983 *param = buf ? buf->Name : 0;
3984 break;
3985 case GL_NORMAL_ARRAY_TYPE:
3986 *param = vao->VertexAttrib[VERT_ATTRIB_NORMAL].Format.Type;
3987 break;
3988 case GL_NORMAL_ARRAY_STRIDE:
3989 *param = vao->VertexAttrib[VERT_ATTRIB_NORMAL].Stride;
3990 break;
3991 case GL_NORMAL_ARRAY_BUFFER_BINDING:
3992 buf = vao->BufferBinding[VERT_ATTRIB_NORMAL].BufferObj;
3993 *param = buf ? buf->Name : 0;
3994 break;
3995 case GL_TEXTURE_COORD_ARRAY_SIZE:
3996 *param = vao->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Format.Size;
3997 break;
3998 case GL_TEXTURE_COORD_ARRAY_TYPE:
3999 *param = vao->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Format.Type;
4000 break;
4001 case GL_TEXTURE_COORD_ARRAY_STRIDE:
4002 *param = vao->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Stride;
4003 break;
4004 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
4005 buf = vao->BufferBinding[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].BufferObj;
4006 *param = buf ? buf->Name : 0;
4007 break;
4008 case GL_FOG_COORD_ARRAY_TYPE:
4009 *param = vao->VertexAttrib[VERT_ATTRIB_FOG].Format.Type;
4010 break;
4011 case GL_FOG_COORD_ARRAY_STRIDE:
4012 *param = vao->VertexAttrib[VERT_ATTRIB_FOG].Stride;
4013 break;
4014 case GL_FOG_COORD_ARRAY_BUFFER_BINDING:
4015 buf = vao->BufferBinding[VERT_ATTRIB_FOG].BufferObj;
4016 *param = buf ? buf->Name : 0;
4017 break;
4018 case GL_SECONDARY_COLOR_ARRAY_SIZE:
4019 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR1].Format.Size;
4020 break;
4021 case GL_SECONDARY_COLOR_ARRAY_TYPE:
4022 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR1].Format.Type;
4023 break;
4024 case GL_SECONDARY_COLOR_ARRAY_STRIDE:
4025 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR1].Stride;
4026 break;
4027 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING:
4028 buf = vao->BufferBinding[VERT_ATTRIB_COLOR1].BufferObj;
4029 *param = buf ? buf->Name : 0;
4030 break;
4031
4032 /* Tokens using IsEnabled */
4033 case GL_VERTEX_ARRAY:
4034 *param = !!(vao->Enabled & VERT_BIT_POS);
4035 break;
4036 case GL_COLOR_ARRAY:
4037 *param = !!(vao->Enabled & VERT_BIT_COLOR0);
4038 break;
4039 case GL_EDGE_FLAG_ARRAY:
4040 *param = !!(vao->Enabled & VERT_BIT_EDGEFLAG);
4041 break;
4042 case GL_INDEX_ARRAY:
4043 *param = !!(vao->Enabled & VERT_BIT_COLOR_INDEX);
4044 break;
4045 case GL_NORMAL_ARRAY:
4046 *param = !!(vao->Enabled & VERT_BIT_NORMAL);
4047 break;
4048 case GL_TEXTURE_COORD_ARRAY:
4049 *param = !!(vao->Enabled & VERT_BIT_TEX(ctx->Array.ActiveTexture));
4050 break;
4051 case GL_FOG_COORD_ARRAY:
4052 *param = !!(vao->Enabled & VERT_BIT_FOG);
4053 break;
4054 case GL_SECONDARY_COLOR_ARRAY:
4055 *param = !!(vao->Enabled & VERT_BIT_COLOR1);
4056 break;
4057
4058 /* Tokens using GetPointerv */
4059 case GL_VERTEX_ARRAY_POINTER:
4060 case GL_COLOR_ARRAY_POINTER:
4061 case GL_EDGE_FLAG_ARRAY_POINTER:
4062 case GL_INDEX_ARRAY_POINTER:
4063 case GL_NORMAL_ARRAY_POINTER:
4064 case GL_TEXTURE_COORD_ARRAY_POINTER:
4065 case GL_FOG_COORD_ARRAY_POINTER:
4066 case GL_SECONDARY_COLOR_ARRAY_POINTER:
4067 _get_vao_pointerv(pname, vao, &ptr, "glGetVertexArrayIntegervEXT");
4068 *param = (int) ((intptr_t) ptr & 0xFFFFFFFF);
4069 break;
4070
4071 default:
4072 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayIntegervEXT(pname)");
4073 }
4074 }
4075
4076 void GLAPIENTRY
4077 _mesa_GetVertexArrayPointervEXT(GLuint vaobj, GLenum pname, GLvoid** param)
4078 {
4079 GET_CURRENT_CONTEXT(ctx);
4080 struct gl_vertex_array_object* vao;
4081
4082 vao = _mesa_lookup_vao_err(ctx, vaobj, true,
4083 "glGetVertexArrayPointervEXT");
4084 if (!vao)
4085 return;
4086
4087 /* The EXT_direct_state_access spec says:
4088 *
4089 * "For GetVertexArrayPointervEXT, pname must be a *_ARRAY_POINTER token from
4090 * tables 6.6, 6.7, and 6.8 excluding VERTEX_ATTRIB_ARRAY_POINT."
4091 */
4092 switch (pname) {
4093 case GL_VERTEX_ARRAY_POINTER:
4094 case GL_COLOR_ARRAY_POINTER:
4095 case GL_EDGE_FLAG_ARRAY_POINTER:
4096 case GL_INDEX_ARRAY_POINTER:
4097 case GL_NORMAL_ARRAY_POINTER:
4098 case GL_TEXTURE_COORD_ARRAY_POINTER:
4099 case GL_FOG_COORD_ARRAY_POINTER:
4100 case GL_SECONDARY_COLOR_ARRAY_POINTER:
4101 break;
4102
4103 default:
4104 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayPointervEXT(pname)");
4105 return;
4106 }
4107
4108 /* pname has been validated, we can now use the helper function */
4109 _get_vao_pointerv(pname, vao, param, "glGetVertexArrayPointervEXT");
4110 }
4111
4112 void GLAPIENTRY
4113 _mesa_GetVertexArrayIntegeri_vEXT(GLuint vaobj, GLuint index, GLenum pname, GLint *param)
4114 {
4115 GET_CURRENT_CONTEXT(ctx);
4116 struct gl_vertex_array_object* vao;
4117 struct gl_buffer_object *buf;
4118
4119 vao = _mesa_lookup_vao_err(ctx, vaobj, true,
4120 "glGetVertexArrayIntegeri_vEXT");
4121 if (!vao)
4122 return;
4123
4124
4125 /* The EXT_direct_state_access spec says:
4126 *
4127 * "For GetVertexArrayIntegeri_vEXT, pname must be one of the
4128 * "Get value" tokens in tables 6.8 and 6.9 that use GetVertexAttribiv
4129 * or GetVertexAttribPointerv (so allowing only the VERTEX_ATTRIB_*
4130 * tokens) or a token of the form TEXTURE_COORD_ARRAY (the enable) or
4131 * TEXTURE_COORD_ARRAY_*; index identifies the vertex attribute
4132 * array to query or texture coordinate set index respectively."
4133 */
4134
4135 switch (pname) {
4136 case GL_TEXTURE_COORD_ARRAY:
4137 *param = !!(vao->Enabled & VERT_BIT_TEX(index));
4138 break;
4139 case GL_TEXTURE_COORD_ARRAY_SIZE:
4140 *param = vao->VertexAttrib[VERT_ATTRIB_TEX(index)].Format.Size;
4141 break;
4142 case GL_TEXTURE_COORD_ARRAY_TYPE:
4143 *param = vao->VertexAttrib[VERT_ATTRIB_TEX(index)].Format.Type;
4144 break;
4145 case GL_TEXTURE_COORD_ARRAY_STRIDE:
4146 *param = vao->VertexAttrib[VERT_ATTRIB_TEX(index)].Stride;
4147 break;
4148 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
4149 buf = vao->BufferBinding[VERT_ATTRIB_TEX(index)].BufferObj;
4150 *param = buf ? buf->Name : 0;
4151 break;
4152 default:
4153 *param = get_vertex_array_attrib(ctx, vao, index, pname, "glGetVertexArrayIntegeri_vEXT");
4154 }
4155 }
4156
4157 void GLAPIENTRY
4158 _mesa_GetVertexArrayPointeri_vEXT(GLuint vaobj, GLuint index, GLenum pname, GLvoid** param)
4159 {
4160 GET_CURRENT_CONTEXT(ctx);
4161 struct gl_vertex_array_object* vao;
4162
4163 vao = _mesa_lookup_vao_err(ctx, vaobj, true,
4164 "glGetVertexArrayPointeri_vEXT");
4165 if (!vao)
4166 return;
4167
4168 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
4169 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexArrayPointeri_vEXT(index)");
4170 return;
4171 }
4172
4173 /* The EXT_direct_state_access spec says:
4174 *
4175 * "For GetVertexArrayPointeri_vEXT, pname must be VERTEX_ATTRIB_ARRAY_POINTER
4176 * or TEXTURE_COORD_ARRAY_POINTER with the index parameter indicating the vertex
4177 * attribute or texture coordindate set index."
4178 */
4179 switch(pname) {
4180 case GL_VERTEX_ATTRIB_ARRAY_POINTER:
4181 *param = (GLvoid *) vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
4182 break;
4183 case GL_TEXTURE_COORD_ARRAY_POINTER:
4184 *param = (GLvoid *) vao->VertexAttrib[VERT_ATTRIB_TEX(index)].Ptr;
4185 break;
4186 default:
4187 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayPointeri_vEXT(pname)");
4188 }
4189 }