mesa: add offset_is_int32 param into _mesa_bind_vertex_buffer for glthread
[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
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 (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 bool offset_is_int32)
203 {
204 assert(index < ARRAY_SIZE(vao->BufferBinding));
205 assert(!vao->SharedAndImmutable);
206 struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index];
207
208 if (ctx->Const.VertexBufferOffsetIsInt32 && (int)offset < 0 &&
209 !offset_is_int32 && vbo) {
210 /* The offset will be interpreted as a signed int, so make sure
211 * the user supplied offset is not negative (driver limitation).
212 */
213 _mesa_warning(ctx, "Received negative int32 vertex buffer offset. "
214 "(driver limitation)\n");
215
216 /* We can't disable this binding, so use a non-negative offset value
217 * instead.
218 */
219 offset = 0;
220 }
221
222 if (binding->BufferObj != vbo ||
223 binding->Offset != offset ||
224 binding->Stride != stride) {
225
226 _mesa_reference_buffer_object(ctx, &binding->BufferObj, vbo);
227
228 binding->Offset = offset;
229 binding->Stride = stride;
230
231 if (!vbo) {
232 vao->VertexAttribBufferMask &= ~binding->_BoundArrays;
233 } else {
234 vao->VertexAttribBufferMask |= binding->_BoundArrays;
235 vbo->UsageHistory |= USAGE_ARRAY_BUFFER;
236 }
237
238 vao->NewArrays |= vao->Enabled & binding->_BoundArrays;
239 }
240 }
241
242
243 /**
244 * Sets the InstanceDivisor field in the vertex buffer binding point
245 * given by bindingIndex.
246 */
247 static void
248 vertex_binding_divisor(struct gl_context *ctx,
249 struct gl_vertex_array_object *vao,
250 GLuint bindingIndex,
251 GLuint divisor)
252 {
253 struct gl_vertex_buffer_binding *binding =
254 &vao->BufferBinding[bindingIndex];
255 assert(!vao->SharedAndImmutable);
256
257 if (binding->InstanceDivisor != divisor) {
258 binding->InstanceDivisor = divisor;
259
260 if (divisor)
261 vao->NonZeroDivisorMask |= binding->_BoundArrays;
262 else
263 vao->NonZeroDivisorMask &= ~binding->_BoundArrays;
264
265 vao->NewArrays |= vao->Enabled & binding->_BoundArrays;
266 }
267 }
268
269 /* vertex_formats[gltype - GL_BYTE][integer*2 + normalized][size - 1] */
270 static const uint16_t vertex_formats[][4][4] = {
271 { /* GL_BYTE */
272 {
273 PIPE_FORMAT_R8_SSCALED,
274 PIPE_FORMAT_R8G8_SSCALED,
275 PIPE_FORMAT_R8G8B8_SSCALED,
276 PIPE_FORMAT_R8G8B8A8_SSCALED
277 },
278 {
279 PIPE_FORMAT_R8_SNORM,
280 PIPE_FORMAT_R8G8_SNORM,
281 PIPE_FORMAT_R8G8B8_SNORM,
282 PIPE_FORMAT_R8G8B8A8_SNORM
283 },
284 {
285 PIPE_FORMAT_R8_SINT,
286 PIPE_FORMAT_R8G8_SINT,
287 PIPE_FORMAT_R8G8B8_SINT,
288 PIPE_FORMAT_R8G8B8A8_SINT
289 },
290 },
291 { /* GL_UNSIGNED_BYTE */
292 {
293 PIPE_FORMAT_R8_USCALED,
294 PIPE_FORMAT_R8G8_USCALED,
295 PIPE_FORMAT_R8G8B8_USCALED,
296 PIPE_FORMAT_R8G8B8A8_USCALED
297 },
298 {
299 PIPE_FORMAT_R8_UNORM,
300 PIPE_FORMAT_R8G8_UNORM,
301 PIPE_FORMAT_R8G8B8_UNORM,
302 PIPE_FORMAT_R8G8B8A8_UNORM
303 },
304 {
305 PIPE_FORMAT_R8_UINT,
306 PIPE_FORMAT_R8G8_UINT,
307 PIPE_FORMAT_R8G8B8_UINT,
308 PIPE_FORMAT_R8G8B8A8_UINT
309 },
310 },
311 { /* GL_SHORT */
312 {
313 PIPE_FORMAT_R16_SSCALED,
314 PIPE_FORMAT_R16G16_SSCALED,
315 PIPE_FORMAT_R16G16B16_SSCALED,
316 PIPE_FORMAT_R16G16B16A16_SSCALED
317 },
318 {
319 PIPE_FORMAT_R16_SNORM,
320 PIPE_FORMAT_R16G16_SNORM,
321 PIPE_FORMAT_R16G16B16_SNORM,
322 PIPE_FORMAT_R16G16B16A16_SNORM
323 },
324 {
325 PIPE_FORMAT_R16_SINT,
326 PIPE_FORMAT_R16G16_SINT,
327 PIPE_FORMAT_R16G16B16_SINT,
328 PIPE_FORMAT_R16G16B16A16_SINT
329 },
330 },
331 { /* GL_UNSIGNED_SHORT */
332 {
333 PIPE_FORMAT_R16_USCALED,
334 PIPE_FORMAT_R16G16_USCALED,
335 PIPE_FORMAT_R16G16B16_USCALED,
336 PIPE_FORMAT_R16G16B16A16_USCALED
337 },
338 {
339 PIPE_FORMAT_R16_UNORM,
340 PIPE_FORMAT_R16G16_UNORM,
341 PIPE_FORMAT_R16G16B16_UNORM,
342 PIPE_FORMAT_R16G16B16A16_UNORM
343 },
344 {
345 PIPE_FORMAT_R16_UINT,
346 PIPE_FORMAT_R16G16_UINT,
347 PIPE_FORMAT_R16G16B16_UINT,
348 PIPE_FORMAT_R16G16B16A16_UINT
349 },
350 },
351 { /* GL_INT */
352 {
353 PIPE_FORMAT_R32_SSCALED,
354 PIPE_FORMAT_R32G32_SSCALED,
355 PIPE_FORMAT_R32G32B32_SSCALED,
356 PIPE_FORMAT_R32G32B32A32_SSCALED
357 },
358 {
359 PIPE_FORMAT_R32_SNORM,
360 PIPE_FORMAT_R32G32_SNORM,
361 PIPE_FORMAT_R32G32B32_SNORM,
362 PIPE_FORMAT_R32G32B32A32_SNORM
363 },
364 {
365 PIPE_FORMAT_R32_SINT,
366 PIPE_FORMAT_R32G32_SINT,
367 PIPE_FORMAT_R32G32B32_SINT,
368 PIPE_FORMAT_R32G32B32A32_SINT
369 },
370 },
371 { /* GL_UNSIGNED_INT */
372 {
373 PIPE_FORMAT_R32_USCALED,
374 PIPE_FORMAT_R32G32_USCALED,
375 PIPE_FORMAT_R32G32B32_USCALED,
376 PIPE_FORMAT_R32G32B32A32_USCALED
377 },
378 {
379 PIPE_FORMAT_R32_UNORM,
380 PIPE_FORMAT_R32G32_UNORM,
381 PIPE_FORMAT_R32G32B32_UNORM,
382 PIPE_FORMAT_R32G32B32A32_UNORM
383 },
384 {
385 PIPE_FORMAT_R32_UINT,
386 PIPE_FORMAT_R32G32_UINT,
387 PIPE_FORMAT_R32G32B32_UINT,
388 PIPE_FORMAT_R32G32B32A32_UINT
389 },
390 },
391 { /* GL_FLOAT */
392 {
393 PIPE_FORMAT_R32_FLOAT,
394 PIPE_FORMAT_R32G32_FLOAT,
395 PIPE_FORMAT_R32G32B32_FLOAT,
396 PIPE_FORMAT_R32G32B32A32_FLOAT
397 },
398 {
399 PIPE_FORMAT_R32_FLOAT,
400 PIPE_FORMAT_R32G32_FLOAT,
401 PIPE_FORMAT_R32G32B32_FLOAT,
402 PIPE_FORMAT_R32G32B32A32_FLOAT
403 },
404 },
405 {{0}}, /* GL_2_BYTES */
406 {{0}}, /* GL_3_BYTES */
407 {{0}}, /* GL_4_BYTES */
408 { /* GL_DOUBLE */
409 {
410 PIPE_FORMAT_R64_FLOAT,
411 PIPE_FORMAT_R64G64_FLOAT,
412 PIPE_FORMAT_R64G64B64_FLOAT,
413 PIPE_FORMAT_R64G64B64A64_FLOAT
414 },
415 {
416 PIPE_FORMAT_R64_FLOAT,
417 PIPE_FORMAT_R64G64_FLOAT,
418 PIPE_FORMAT_R64G64B64_FLOAT,
419 PIPE_FORMAT_R64G64B64A64_FLOAT
420 },
421 },
422 { /* GL_HALF_FLOAT */
423 {
424 PIPE_FORMAT_R16_FLOAT,
425 PIPE_FORMAT_R16G16_FLOAT,
426 PIPE_FORMAT_R16G16B16_FLOAT,
427 PIPE_FORMAT_R16G16B16A16_FLOAT
428 },
429 {
430 PIPE_FORMAT_R16_FLOAT,
431 PIPE_FORMAT_R16G16_FLOAT,
432 PIPE_FORMAT_R16G16B16_FLOAT,
433 PIPE_FORMAT_R16G16B16A16_FLOAT
434 },
435 },
436 { /* GL_FIXED */
437 {
438 PIPE_FORMAT_R32_FIXED,
439 PIPE_FORMAT_R32G32_FIXED,
440 PIPE_FORMAT_R32G32B32_FIXED,
441 PIPE_FORMAT_R32G32B32A32_FIXED
442 },
443 {
444 PIPE_FORMAT_R32_FIXED,
445 PIPE_FORMAT_R32G32_FIXED,
446 PIPE_FORMAT_R32G32B32_FIXED,
447 PIPE_FORMAT_R32G32B32A32_FIXED
448 },
449 },
450 };
451
452 /**
453 * Return a PIPE_FORMAT_x for the given GL datatype and size.
454 */
455 static enum pipe_format
456 vertex_format_to_pipe_format(GLubyte size, GLenum16 type, GLenum16 format,
457 GLboolean normalized, GLboolean integer,
458 GLboolean doubles)
459 {
460 assert(size >= 1 && size <= 4);
461 assert(format == GL_RGBA || format == GL_BGRA);
462
463 /* 64-bit attributes are translated by drivers. */
464 if (doubles)
465 return PIPE_FORMAT_NONE;
466
467 switch (type) {
468 case GL_HALF_FLOAT_OES:
469 type = GL_HALF_FLOAT;
470 break;
471
472 case GL_INT_2_10_10_10_REV:
473 assert(size == 4 && !integer);
474
475 if (format == GL_BGRA) {
476 if (normalized)
477 return PIPE_FORMAT_B10G10R10A2_SNORM;
478 else
479 return PIPE_FORMAT_B10G10R10A2_SSCALED;
480 } else {
481 if (normalized)
482 return PIPE_FORMAT_R10G10B10A2_SNORM;
483 else
484 return PIPE_FORMAT_R10G10B10A2_SSCALED;
485 }
486 break;
487
488 case GL_UNSIGNED_INT_2_10_10_10_REV:
489 assert(size == 4 && !integer);
490
491 if (format == GL_BGRA) {
492 if (normalized)
493 return PIPE_FORMAT_B10G10R10A2_UNORM;
494 else
495 return PIPE_FORMAT_B10G10R10A2_USCALED;
496 } else {
497 if (normalized)
498 return PIPE_FORMAT_R10G10B10A2_UNORM;
499 else
500 return PIPE_FORMAT_R10G10B10A2_USCALED;
501 }
502 break;
503
504 case GL_UNSIGNED_INT_10F_11F_11F_REV:
505 assert(size == 3 && !integer && format == GL_RGBA);
506 return PIPE_FORMAT_R11G11B10_FLOAT;
507
508 case GL_UNSIGNED_BYTE:
509 if (format == GL_BGRA) {
510 /* this is an odd-ball case */
511 assert(normalized);
512 return PIPE_FORMAT_B8G8R8A8_UNORM;
513 }
514 break;
515 }
516
517 unsigned index = integer*2 + normalized;
518 assert(index <= 2);
519 assert(type >= GL_BYTE && type <= GL_FIXED);
520 return vertex_formats[type - GL_BYTE][index][size-1];
521 }
522
523 void
524 _mesa_set_vertex_format(struct gl_vertex_format *vertex_format,
525 GLubyte size, GLenum16 type, GLenum16 format,
526 GLboolean normalized, GLboolean integer,
527 GLboolean doubles)
528 {
529 assert(size <= 4);
530 vertex_format->Type = type;
531 vertex_format->Format = format;
532 vertex_format->Size = size;
533 vertex_format->Normalized = normalized;
534 vertex_format->Integer = integer;
535 vertex_format->Doubles = doubles;
536 vertex_format->_ElementSize = _mesa_bytes_per_vertex_attrib(size, type);
537 assert(vertex_format->_ElementSize <= 4*sizeof(double));
538 vertex_format->_PipeFormat =
539 vertex_format_to_pipe_format(size, type, format, normalized, integer,
540 doubles);
541 }
542
543
544 /**
545 * Examine the API profile and extensions to determine which types are legal
546 * for vertex arrays. This is called once from update_array_format().
547 */
548 static GLbitfield
549 get_legal_types_mask(const struct gl_context *ctx)
550 {
551 GLbitfield legalTypesMask = ALL_TYPE_BITS;
552
553 if (_mesa_is_gles(ctx)) {
554 legalTypesMask &= ~(FIXED_GL_BIT |
555 DOUBLE_BIT |
556 UNSIGNED_INT_10F_11F_11F_REV_BIT);
557
558 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
559 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
560 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
561 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
562 * quite as trivial as we'd like because it uses a different enum value
563 * for GL_HALF_FLOAT_OES.
564 */
565 if (ctx->Version < 30) {
566 legalTypesMask &= ~(UNSIGNED_INT_BIT |
567 INT_BIT |
568 UNSIGNED_INT_2_10_10_10_REV_BIT |
569 INT_2_10_10_10_REV_BIT);
570
571 if (!_mesa_has_OES_vertex_half_float(ctx))
572 legalTypesMask &= ~HALF_BIT;
573 }
574 }
575 else {
576 legalTypesMask &= ~FIXED_ES_BIT;
577
578 if (!ctx->Extensions.ARB_ES2_compatibility)
579 legalTypesMask &= ~FIXED_GL_BIT;
580
581 if (!ctx->Extensions.ARB_vertex_type_2_10_10_10_rev)
582 legalTypesMask &= ~(UNSIGNED_INT_2_10_10_10_REV_BIT |
583 INT_2_10_10_10_REV_BIT);
584
585 if (!ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev)
586 legalTypesMask &= ~UNSIGNED_INT_10F_11F_11F_REV_BIT;
587 }
588
589 return legalTypesMask;
590 }
591
592 static GLenum
593 get_array_format(const struct gl_context *ctx, GLint sizeMax, GLint *size)
594 {
595 GLenum format = GL_RGBA;
596
597 /* Do size parameter checking.
598 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
599 * must be handled specially.
600 */
601 if (ctx->Extensions.EXT_vertex_array_bgra && sizeMax == BGRA_OR_4 &&
602 *size == GL_BGRA) {
603 format = GL_BGRA;
604 *size = 4;
605 }
606
607 return format;
608 }
609
610
611 /**
612 * \param attrib The index of the attribute array
613 * \param size Components per element (1, 2, 3 or 4)
614 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
615 * \param format Either GL_RGBA or GL_BGRA.
616 * \param normalized Whether integer types are converted to floats in [-1, 1]
617 * \param integer Integer-valued values (will not be normalized to [-1, 1])
618 * \param doubles Double values not reduced to floats
619 * \param relativeOffset Offset of the first element relative to the binding
620 * offset.
621 */
622 void
623 _mesa_update_array_format(struct gl_context *ctx,
624 struct gl_vertex_array_object *vao,
625 gl_vert_attrib attrib, GLint size, GLenum type,
626 GLenum format, GLboolean normalized,
627 GLboolean integer, GLboolean doubles,
628 GLuint relativeOffset)
629 {
630 struct gl_array_attributes *const array = &vao->VertexAttrib[attrib];
631 struct gl_vertex_format new_format;
632
633 assert(!vao->SharedAndImmutable);
634 assert(size <= 4);
635
636 _mesa_set_vertex_format(&new_format, size, type, format,
637 normalized, integer, doubles);
638
639 if ((array->RelativeOffset == relativeOffset) &&
640 !memcmp(&new_format, &array->Format, sizeof(new_format)))
641 return;
642
643 array->RelativeOffset = relativeOffset;
644 array->Format = new_format;
645
646 vao->NewArrays |= vao->Enabled & VERT_BIT(attrib);
647 }
648
649 /**
650 * Does error checking of the format in an attrib array.
651 *
652 * Called by *Pointer() and VertexAttrib*Format().
653 *
654 * \param func Name of calling function used for error reporting
655 * \param attrib The index of the attribute array
656 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
657 * \param sizeMin Min allowable size value
658 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
659 * \param size Components per element (1, 2, 3 or 4)
660 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
661 * \param normalized Whether integer types are converted to floats in [-1, 1]
662 * \param integer Integer-valued values (will not be normalized to [-1, 1])
663 * \param doubles Double values not reduced to floats
664 * \param relativeOffset Offset of the first element relative to the binding offset.
665 * \return bool True if validation is successful, False otherwise.
666 */
667 static bool
668 validate_array_format(struct gl_context *ctx, const char *func,
669 struct gl_vertex_array_object *vao,
670 GLuint attrib, GLbitfield legalTypesMask,
671 GLint sizeMin, GLint sizeMax,
672 GLint size, GLenum type, GLboolean normalized,
673 GLboolean integer, GLboolean doubles,
674 GLuint relativeOffset, GLenum format)
675 {
676 GLbitfield typeBit;
677
678 /* at most, one of these bools can be true */
679 assert((int) normalized + (int) integer + (int) doubles <= 1);
680
681 if (ctx->Array.LegalTypesMask == 0 || ctx->Array.LegalTypesMaskAPI != ctx->API) {
682 /* Compute the LegalTypesMask only once, unless the context API has
683 * changed, in which case we want to compute it again. We can't do this
684 * in _mesa_init_varrays() below because extensions are not yet enabled
685 * at that point.
686 */
687 ctx->Array.LegalTypesMask = get_legal_types_mask(ctx);
688 ctx->Array.LegalTypesMaskAPI = ctx->API;
689 }
690
691 legalTypesMask &= ctx->Array.LegalTypesMask;
692
693 if (_mesa_is_gles(ctx) && sizeMax == BGRA_OR_4) {
694 /* BGRA ordering is not supported in ES contexts.
695 */
696 sizeMax = 4;
697 }
698
699 typeBit = type_to_bit(ctx, type);
700 if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) {
701 _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)",
702 func, _mesa_enum_to_string(type));
703 return false;
704 }
705
706 if (format == GL_BGRA) {
707 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
708 *
709 * "An INVALID_OPERATION error is generated under any of the following
710 * conditions:
711 * ...
712 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
713 * or UNSIGNED_INT_2_10_10_10_REV;
714 * ...
715 * • size is BGRA and normalized is FALSE;"
716 */
717 bool bgra_error = false;
718
719 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev) {
720 if (type != GL_UNSIGNED_INT_2_10_10_10_REV &&
721 type != GL_INT_2_10_10_10_REV &&
722 type != GL_UNSIGNED_BYTE)
723 bgra_error = true;
724 } else if (type != GL_UNSIGNED_BYTE)
725 bgra_error = true;
726
727 if (bgra_error) {
728 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)",
729 func, _mesa_enum_to_string(type));
730 return false;
731 }
732
733 if (!normalized) {
734 _mesa_error(ctx, GL_INVALID_OPERATION,
735 "%s(size=GL_BGRA and normalized=GL_FALSE)", func);
736 return false;
737 }
738 }
739 else if (size < sizeMin || size > sizeMax || size > 4) {
740 _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d)", func, size);
741 return false;
742 }
743
744 if (ctx->Extensions.ARB_vertex_type_2_10_10_10_rev &&
745 (type == GL_UNSIGNED_INT_2_10_10_10_REV ||
746 type == GL_INT_2_10_10_10_REV) && size != 4) {
747 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
748 return false;
749 }
750
751 /* The ARB_vertex_attrib_binding_spec says:
752 *
753 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
754 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
755 */
756 if (relativeOffset > ctx->Const.MaxVertexAttribRelativeOffset) {
757 _mesa_error(ctx, GL_INVALID_VALUE,
758 "%s(relativeOffset=%d > "
759 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
760 func, relativeOffset);
761 return false;
762 }
763
764 if (ctx->Extensions.ARB_vertex_type_10f_11f_11f_rev &&
765 type == GL_UNSIGNED_INT_10F_11F_11F_REV && size != 3) {
766 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=%d)", func, size);
767 return false;
768 }
769
770 return true;
771 }
772
773 /**
774 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
775 *
776 * \param func name of calling function used for error reporting
777 * \param vao the vao to update
778 * \param obj the bound buffer object
779 * \param attrib the attribute array index to update
780 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
781 * \param sizeMin min allowable size value
782 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
783 * \param size components per element (1, 2, 3 or 4)
784 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
785 * \param stride stride between elements, in elements
786 * \param normalized are integer types converted to floats in [-1, 1]?
787 * \param integer integer-valued values (will not be normalized to [-1,1])
788 * \param doubles Double values not reduced to floats
789 * \param ptr the address (or offset inside VBO) of the array data
790 */
791 static void
792 validate_array(struct gl_context *ctx, const char *func,
793 struct gl_vertex_array_object *vao,
794 struct gl_buffer_object *obj,
795 GLuint attrib, GLbitfield legalTypesMask,
796 GLint sizeMin, GLint sizeMax,
797 GLint size, GLenum type, GLsizei stride,
798 GLboolean normalized, GLboolean integer, GLboolean doubles,
799 const GLvoid *ptr)
800 {
801 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
802 *
803 * "Client vertex arrays - all vertex array attribute pointers must
804 * refer to buffer objects (section 2.9.2). The default vertex array
805 * object (the name zero) is also deprecated. Calling
806 * VertexAttribPointer when no buffer object or no vertex array object
807 * is bound will generate an INVALID_OPERATION error..."
808 *
809 * The check for VBOs is handled below.
810 */
811 if (ctx->API == API_OPENGL_CORE && (vao == ctx->Array.DefaultVAO)) {
812 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)",
813 func);
814 return;
815 }
816
817 if (stride < 0) {
818 _mesa_error( ctx, GL_INVALID_VALUE, "%s(stride=%d)", func, stride );
819 return;
820 }
821
822 if (_mesa_is_desktop_gl(ctx) && ctx->Version >= 44 &&
823 stride > ctx->Const.MaxVertexAttribStride) {
824 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
825 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
826 return;
827 }
828
829 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
830 *
831 * "An INVALID_OPERATION error is generated under any of the following
832 * conditions:
833 *
834 * ...
835 *
836 * * any of the *Pointer commands specifying the location and
837 * organization of vertex array data are called while zero is bound
838 * to the ARRAY_BUFFER buffer object binding point (see section
839 * 2.9.6), and the pointer argument is not NULL."
840 */
841 if (ptr != NULL && vao != ctx->Array.DefaultVAO &&
842 !obj) {
843 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func);
844 return;
845 }
846 }
847
848
849 static bool
850 validate_array_and_format(struct gl_context *ctx, const char *func,
851 struct gl_vertex_array_object *vao,
852 struct gl_buffer_object *obj,
853 GLuint attrib, GLbitfield legalTypes,
854 GLint sizeMin, GLint sizeMax,
855 GLint size, GLenum type, GLsizei stride,
856 GLboolean normalized, GLboolean integer,
857 GLboolean doubles, GLenum format, const GLvoid *ptr)
858 {
859 validate_array(ctx, func, vao, obj, attrib, legalTypes, sizeMin, sizeMax,
860 size, type, stride, normalized, integer, doubles, ptr);
861
862 return validate_array_format(ctx, func, vao, attrib, legalTypes, sizeMin,
863 sizeMax, size, type, normalized, integer,
864 doubles, 0, format);
865 }
866
867
868 /**
869 * Update state for glVertex/Color/TexCoord/...Pointer functions.
870 *
871 * \param vao the vao to update
872 * \param obj the bound buffer object
873 * \param attrib the attribute array index to update
874 * \param format Either GL_RGBA or GL_BGRA.
875 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
876 * \param size components per element (1, 2, 3 or 4)
877 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
878 * \param stride stride between elements, in elements
879 * \param normalized are integer types converted to floats in [-1, 1]?
880 * \param integer integer-valued values (will not be normalized to [-1,1])
881 * \param doubles Double values not reduced to floats
882 * \param ptr the address (or offset inside VBO) of the array data
883 */
884 static void
885 update_array(struct gl_context *ctx,
886 struct gl_vertex_array_object *vao,
887 struct gl_buffer_object *obj,
888 GLuint attrib, GLenum format,
889 GLint sizeMax,
890 GLint size, GLenum type, GLsizei stride,
891 GLboolean normalized, GLboolean integer, GLboolean doubles,
892 const GLvoid *ptr)
893 {
894 _mesa_update_array_format(ctx, vao, attrib, size, type, format,
895 normalized, integer, doubles, 0);
896
897 /* Reset the vertex attrib binding */
898 _mesa_vertex_attrib_binding(ctx, vao, attrib, attrib);
899
900 /* The Stride and Ptr fields are not set by update_array_format() */
901 struct gl_array_attributes *array = &vao->VertexAttrib[attrib];
902 if ((array->Stride != stride) || (array->Ptr != ptr)) {
903 array->Stride = stride;
904 array->Ptr = ptr;
905 vao->NewArrays |= vao->Enabled & VERT_BIT(attrib);
906 }
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, false);
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 _mesa_update_derived_primitive_restart_state(ctx);
2757 }
2758
2759
2760 /**
2761 * GL_NV_primitive_restart and GL 3.1
2762 */
2763 void GLAPIENTRY
2764 _mesa_PrimitiveRestartIndex_no_error(GLuint index)
2765 {
2766 GET_CURRENT_CONTEXT(ctx);
2767 primitive_restart_index(ctx, index);
2768 }
2769
2770
2771 void GLAPIENTRY
2772 _mesa_PrimitiveRestartIndex(GLuint index)
2773 {
2774 GET_CURRENT_CONTEXT(ctx);
2775
2776 if (!ctx->Extensions.NV_primitive_restart && ctx->Version < 31) {
2777 _mesa_error(ctx, GL_INVALID_OPERATION, "glPrimitiveRestartIndexNV()");
2778 return;
2779 }
2780
2781 primitive_restart_index(ctx, index);
2782 }
2783
2784
2785 void GLAPIENTRY
2786 _mesa_VertexAttribDivisor_no_error(GLuint index, GLuint divisor)
2787 {
2788 GET_CURRENT_CONTEXT(ctx);
2789
2790 const gl_vert_attrib genericIndex = VERT_ATTRIB_GENERIC(index);
2791 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
2792
2793 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
2794
2795 /* The ARB_vertex_attrib_binding spec says:
2796 *
2797 * "The command
2798 *
2799 * void VertexAttribDivisor(uint index, uint divisor);
2800 *
2801 * is equivalent to (assuming no errors are generated):
2802 *
2803 * VertexAttribBinding(index, index);
2804 * VertexBindingDivisor(index, divisor);"
2805 */
2806 _mesa_vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
2807 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
2808 }
2809
2810
2811 /**
2812 * See GL_ARB_instanced_arrays.
2813 * Note that the instance divisor only applies to generic arrays, not
2814 * the legacy vertex arrays.
2815 */
2816 void GLAPIENTRY
2817 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor)
2818 {
2819 GET_CURRENT_CONTEXT(ctx);
2820
2821 const gl_vert_attrib genericIndex = VERT_ATTRIB_GENERIC(index);
2822 struct gl_vertex_array_object * const vao = ctx->Array.VAO;
2823
2824 if (!ctx->Extensions.ARB_instanced_arrays) {
2825 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()");
2826 return;
2827 }
2828
2829 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2830 _mesa_error(ctx, GL_INVALID_VALUE,
2831 "glVertexAttribDivisor(index = %u)", index);
2832 return;
2833 }
2834
2835 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
2836
2837 /* The ARB_vertex_attrib_binding spec says:
2838 *
2839 * "The command
2840 *
2841 * void VertexAttribDivisor(uint index, uint divisor);
2842 *
2843 * is equivalent to (assuming no errors are generated):
2844 *
2845 * VertexAttribBinding(index, index);
2846 * VertexBindingDivisor(index, divisor);"
2847 */
2848 _mesa_vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
2849 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
2850 }
2851
2852
2853 void GLAPIENTRY
2854 _mesa_VertexArrayVertexAttribDivisorEXT(GLuint vaobj, GLuint index, GLuint divisor)
2855 {
2856 GET_CURRENT_CONTEXT(ctx);
2857
2858 const gl_vert_attrib genericIndex = VERT_ATTRIB_GENERIC(index);
2859 struct gl_vertex_array_object * vao;
2860 /* The ARB_instanced_arrays spec says:
2861 *
2862 * "The vertex array object named by vaobj must
2863 * be generated by GenVertexArrays (and not since deleted);
2864 * otherwise an INVALID_OPERATION error is generated."
2865 */
2866 vao = _mesa_lookup_vao_err(ctx, vaobj,
2867 false,
2868 "glVertexArrayVertexAttribDivisorEXT");
2869 if (!vao)
2870 return;
2871
2872 if (!ctx->Extensions.ARB_instanced_arrays) {
2873 _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexArrayVertexAttribDivisorEXT()");
2874 return;
2875 }
2876
2877 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
2878 _mesa_error(ctx, GL_INVALID_VALUE,
2879 "glVertexArrayVertexAttribDivisorEXT(index = %u)", index);
2880 return;
2881 }
2882
2883 assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib));
2884
2885 /* The ARB_vertex_attrib_binding spec says:
2886 *
2887 * "The command
2888 *
2889 * void VertexAttribDivisor(uint index, uint divisor);
2890 *
2891 * is equivalent to (assuming no errors are generated):
2892 *
2893 * VertexAttribBinding(index, index);
2894 * VertexBindingDivisor(index, divisor);"
2895 */
2896 _mesa_vertex_attrib_binding(ctx, vao, genericIndex, genericIndex);
2897 vertex_binding_divisor(ctx, vao, genericIndex, divisor);
2898 }
2899
2900
2901
2902 static ALWAYS_INLINE void
2903 vertex_array_vertex_buffer(struct gl_context *ctx,
2904 struct gl_vertex_array_object *vao,
2905 GLuint bindingIndex, GLuint buffer, GLintptr offset,
2906 GLsizei stride, bool no_error, const char *func)
2907 {
2908 struct gl_buffer_object *vbo;
2909 struct gl_buffer_object *current_buf =
2910 vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj;
2911
2912 if (current_buf && buffer == current_buf->Name) {
2913 vbo = current_buf;
2914 } else if (buffer != 0) {
2915 vbo = _mesa_lookup_bufferobj(ctx, buffer);
2916
2917 if (!no_error && !vbo && _mesa_is_gles31(ctx)) {
2918 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-gen name)", func);
2919 return;
2920 }
2921 /* From the GL_ARB_vertex_attrib_array spec:
2922 *
2923 * "[Core profile only:]
2924 * An INVALID_OPERATION error is generated if buffer is not zero or a
2925 * name returned from a previous call to GenBuffers, or if such a name
2926 * has since been deleted with DeleteBuffers.
2927 *
2928 * Otherwise, we fall back to the same compat profile behavior as other
2929 * object references (automatically gen it).
2930 */
2931 if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &vbo, func))
2932 return;
2933 } else {
2934 /* The ARB_vertex_attrib_binding spec says:
2935 *
2936 * "If <buffer> is zero, any buffer object attached to this
2937 * bindpoint is detached."
2938 */
2939 vbo = NULL;
2940 }
2941
2942 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex),
2943 vbo, offset, stride, false);
2944 }
2945
2946
2947 /**
2948 * GL_ARB_vertex_attrib_binding
2949 */
2950 static void
2951 vertex_array_vertex_buffer_err(struct gl_context *ctx,
2952 struct gl_vertex_array_object *vao,
2953 GLuint bindingIndex, GLuint buffer,
2954 GLintptr offset, GLsizei stride,
2955 const char *func)
2956 {
2957 ASSERT_OUTSIDE_BEGIN_END(ctx);
2958
2959 /* The ARB_vertex_attrib_binding spec says:
2960 *
2961 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2962 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2963 */
2964 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
2965 _mesa_error(ctx, GL_INVALID_VALUE,
2966 "%s(bindingindex=%u > "
2967 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2968 func, bindingIndex);
2969 return;
2970 }
2971
2972 /* The ARB_vertex_attrib_binding spec says:
2973 *
2974 * "The error INVALID_VALUE is generated if <stride> or <offset>
2975 * are negative."
2976 */
2977 if (offset < 0) {
2978 _mesa_error(ctx, GL_INVALID_VALUE,
2979 "%s(offset=%" PRId64 " < 0)",
2980 func, (int64_t) offset);
2981 return;
2982 }
2983
2984 if (stride < 0) {
2985 _mesa_error(ctx, GL_INVALID_VALUE,
2986 "%s(stride=%d < 0)", func, stride);
2987 return;
2988 }
2989
2990 if (((_mesa_is_desktop_gl(ctx) && ctx->Version >= 44) || _mesa_is_gles31(ctx)) &&
2991 stride > ctx->Const.MaxVertexAttribStride) {
2992 _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > "
2993 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride);
2994 return;
2995 }
2996
2997 vertex_array_vertex_buffer(ctx, vao, bindingIndex, buffer, offset,
2998 stride, false, func);
2999 }
3000
3001
3002 void GLAPIENTRY
3003 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex, GLuint buffer,
3004 GLintptr offset, GLsizei stride)
3005 {
3006 GET_CURRENT_CONTEXT(ctx);
3007 vertex_array_vertex_buffer(ctx, ctx->Array.VAO, bindingIndex,
3008 buffer, offset, stride, true,
3009 "glBindVertexBuffer");
3010 }
3011
3012
3013 void GLAPIENTRY
3014 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
3015 GLsizei stride)
3016 {
3017 GET_CURRENT_CONTEXT(ctx);
3018
3019 /* The ARB_vertex_attrib_binding spec says:
3020 *
3021 * "An INVALID_OPERATION error is generated if no vertex array object
3022 * is bound."
3023 */
3024 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
3025 ctx->Array.VAO == ctx->Array.DefaultVAO) {
3026 _mesa_error(ctx, GL_INVALID_OPERATION,
3027 "glBindVertexBuffer(No array object bound)");
3028 return;
3029 }
3030
3031 vertex_array_vertex_buffer_err(ctx, ctx->Array.VAO, bindingIndex,
3032 buffer, offset, stride,
3033 "glBindVertexBuffer");
3034 }
3035
3036
3037 void GLAPIENTRY
3038 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj, GLuint bindingIndex,
3039 GLuint buffer, GLintptr offset,
3040 GLsizei stride)
3041 {
3042 GET_CURRENT_CONTEXT(ctx);
3043
3044 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
3045 vertex_array_vertex_buffer(ctx, vao, bindingIndex, buffer, offset,
3046 stride, true, "glVertexArrayVertexBuffer");
3047 }
3048
3049
3050 void GLAPIENTRY
3051 _mesa_VertexArrayVertexBuffer(GLuint vaobj, GLuint bindingIndex, GLuint buffer,
3052 GLintptr offset, GLsizei stride)
3053 {
3054 GET_CURRENT_CONTEXT(ctx);
3055 struct gl_vertex_array_object *vao;
3056
3057 /* The ARB_direct_state_access specification says:
3058 *
3059 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
3060 * if <vaobj> is not [compatibility profile: zero or] the name of an
3061 * existing vertex array object."
3062 */
3063 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glVertexArrayVertexBuffer");
3064 if (!vao)
3065 return;
3066
3067 vertex_array_vertex_buffer_err(ctx, vao, bindingIndex, buffer, offset,
3068 stride, "glVertexArrayVertexBuffer");
3069 }
3070
3071
3072 void GLAPIENTRY
3073 _mesa_VertexArrayBindVertexBufferEXT(GLuint vaobj, GLuint bindingIndex, GLuint buffer,
3074 GLintptr offset, GLsizei stride)
3075 {
3076 GET_CURRENT_CONTEXT(ctx);
3077 struct gl_vertex_array_object *vao;
3078 vao = _mesa_lookup_vao_err(ctx, vaobj, true, "glVertexArrayBindVertexBufferEXT");
3079 if (!vao)
3080 return;
3081
3082 vertex_array_vertex_buffer_err(ctx, vao, bindingIndex, buffer, offset,
3083 stride, "glVertexArrayBindVertexBufferEXT");
3084 }
3085
3086
3087 static ALWAYS_INLINE void
3088 vertex_array_vertex_buffers(struct gl_context *ctx,
3089 struct gl_vertex_array_object *vao,
3090 GLuint first, GLsizei count, const GLuint *buffers,
3091 const GLintptr *offsets, const GLsizei *strides,
3092 bool no_error, const char *func)
3093 {
3094 GLint i;
3095
3096 if (!buffers) {
3097 /**
3098 * The ARB_multi_bind spec says:
3099 *
3100 * "If <buffers> is NULL, each affected vertex buffer binding point
3101 * from <first> through <first>+<count>-1 will be reset to have no
3102 * bound buffer object. In this case, the offsets and strides
3103 * associated with the binding points are set to default values,
3104 * ignoring <offsets> and <strides>."
3105 */
3106 for (i = 0; i < count; i++)
3107 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
3108 NULL, 0, 16, false);
3109
3110 return;
3111 }
3112
3113 /* Note that the error semantics for multi-bind commands differ from
3114 * those of other GL commands.
3115 *
3116 * The Issues section in the ARB_multi_bind spec says:
3117 *
3118 * "(11) Typically, OpenGL specifies that if an error is generated by
3119 * a command, that command has no effect. This is somewhat
3120 * unfortunate for multi-bind commands, because it would require
3121 * a first pass to scan the entire list of bound objects for
3122 * errors and then a second pass to actually perform the
3123 * bindings. Should we have different error semantics?
3124 *
3125 * RESOLVED: Yes. In this specification, when the parameters for
3126 * one of the <count> binding points are invalid, that binding
3127 * point is not updated and an error will be generated. However,
3128 * other binding points in the same command will be updated if
3129 * their parameters are valid and no other error occurs."
3130 */
3131
3132 _mesa_HashLockMutex(ctx->Shared->BufferObjects);
3133
3134 for (i = 0; i < count; i++) {
3135 struct gl_buffer_object *vbo;
3136
3137 if (!no_error) {
3138 /* The ARB_multi_bind spec says:
3139 *
3140 * "An INVALID_VALUE error is generated if any value in
3141 * <offsets> or <strides> is negative (per binding)."
3142 */
3143 if (offsets[i] < 0) {
3144 _mesa_error(ctx, GL_INVALID_VALUE,
3145 "%s(offsets[%u]=%" PRId64 " < 0)",
3146 func, i, (int64_t) offsets[i]);
3147 continue;
3148 }
3149
3150 if (strides[i] < 0) {
3151 _mesa_error(ctx, GL_INVALID_VALUE,
3152 "%s(strides[%u]=%d < 0)",
3153 func, i, strides[i]);
3154 continue;
3155 }
3156
3157 if (_mesa_is_desktop_gl(ctx) && ctx->Version >= 44 &&
3158 strides[i] > ctx->Const.MaxVertexAttribStride) {
3159 _mesa_error(ctx, GL_INVALID_VALUE,
3160 "%s(strides[%u]=%d > "
3161 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, i, strides[i]);
3162 continue;
3163 }
3164 }
3165
3166 if (buffers[i]) {
3167 struct gl_vertex_buffer_binding *binding =
3168 &vao->BufferBinding[VERT_ATTRIB_GENERIC(first + i)];
3169
3170 if (buffers[i] == 0)
3171 vbo = NULL;
3172 else if (binding->BufferObj && binding->BufferObj->Name == buffers[i])
3173 vbo = binding->BufferObj;
3174 else {
3175 bool error;
3176 vbo = _mesa_multi_bind_lookup_bufferobj(ctx, buffers, i, func,
3177 &error);
3178 if (error)
3179 continue;
3180 }
3181 } else {
3182 vbo = NULL;
3183 }
3184
3185 _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i),
3186 vbo, offsets[i], strides[i], false);
3187 }
3188
3189 _mesa_HashUnlockMutex(ctx->Shared->BufferObjects);
3190 }
3191
3192
3193 static void
3194 vertex_array_vertex_buffers_err(struct gl_context *ctx,
3195 struct gl_vertex_array_object *vao,
3196 GLuint first, GLsizei count,
3197 const GLuint *buffers, const GLintptr *offsets,
3198 const GLsizei *strides, const char *func)
3199 {
3200 ASSERT_OUTSIDE_BEGIN_END(ctx);
3201
3202 /* The ARB_multi_bind spec says:
3203 *
3204 * "An INVALID_OPERATION error is generated if <first> + <count>
3205 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
3206 */
3207 if (first + count > ctx->Const.MaxVertexAttribBindings) {
3208 _mesa_error(ctx, GL_INVALID_OPERATION,
3209 "%s(first=%u + count=%d > the value of "
3210 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
3211 func, first, count, ctx->Const.MaxVertexAttribBindings);
3212 return;
3213 }
3214
3215 vertex_array_vertex_buffers(ctx, vao, first, count, buffers, offsets,
3216 strides, false, func);
3217 }
3218
3219
3220 void GLAPIENTRY
3221 _mesa_BindVertexBuffers_no_error(GLuint first, GLsizei count,
3222 const GLuint *buffers, const GLintptr *offsets,
3223 const GLsizei *strides)
3224 {
3225 GET_CURRENT_CONTEXT(ctx);
3226
3227 vertex_array_vertex_buffers(ctx, ctx->Array.VAO, first, count,
3228 buffers, offsets, strides, true,
3229 "glBindVertexBuffers");
3230 }
3231
3232
3233 void GLAPIENTRY
3234 _mesa_BindVertexBuffers(GLuint first, GLsizei count, const GLuint *buffers,
3235 const GLintptr *offsets, const GLsizei *strides)
3236 {
3237 GET_CURRENT_CONTEXT(ctx);
3238
3239 /* The ARB_vertex_attrib_binding spec says:
3240 *
3241 * "An INVALID_OPERATION error is generated if no
3242 * vertex array object is bound."
3243 */
3244 if (ctx->API == API_OPENGL_CORE &&
3245 ctx->Array.VAO == ctx->Array.DefaultVAO) {
3246 _mesa_error(ctx, GL_INVALID_OPERATION,
3247 "glBindVertexBuffers(No array object bound)");
3248 return;
3249 }
3250
3251 vertex_array_vertex_buffers_err(ctx, ctx->Array.VAO, first, count,
3252 buffers, offsets, strides,
3253 "glBindVertexBuffers");
3254 }
3255
3256
3257 void GLAPIENTRY
3258 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj, GLuint first,
3259 GLsizei count, const GLuint *buffers,
3260 const GLintptr *offsets,
3261 const GLsizei *strides)
3262 {
3263 GET_CURRENT_CONTEXT(ctx);
3264
3265 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
3266 vertex_array_vertex_buffers(ctx, vao, first, count,
3267 buffers, offsets, strides, true,
3268 "glVertexArrayVertexBuffers");
3269 }
3270
3271
3272 void GLAPIENTRY
3273 _mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count,
3274 const GLuint *buffers,
3275 const GLintptr *offsets, const GLsizei *strides)
3276 {
3277 GET_CURRENT_CONTEXT(ctx);
3278 struct gl_vertex_array_object *vao;
3279
3280 /* The ARB_direct_state_access specification says:
3281 *
3282 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
3283 * if <vaobj> is not [compatibility profile: zero or] the name of an
3284 * existing vertex array object."
3285 */
3286 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glVertexArrayVertexBuffers");
3287 if (!vao)
3288 return;
3289
3290 vertex_array_vertex_buffers_err(ctx, vao, first, count,
3291 buffers, offsets, strides,
3292 "glVertexArrayVertexBuffers");
3293 }
3294
3295
3296 static void
3297 vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type,
3298 GLboolean normalized, GLboolean integer,
3299 GLboolean doubles, GLbitfield legalTypes,
3300 GLsizei sizeMax, GLuint relativeOffset,
3301 const char *func)
3302 {
3303 GET_CURRENT_CONTEXT(ctx);
3304 ASSERT_OUTSIDE_BEGIN_END(ctx);
3305
3306 GLenum format = get_array_format(ctx, sizeMax, &size);
3307
3308 if (!_mesa_is_no_error_enabled(ctx)) {
3309 /* The ARB_vertex_attrib_binding spec says:
3310 *
3311 * "An INVALID_OPERATION error is generated under any of the
3312 * following conditions:
3313 * - if no vertex array object is currently bound (see section
3314 * 2.10);
3315 * - ..."
3316 *
3317 * This error condition only applies to VertexAttribFormat and
3318 * VertexAttribIFormat in the extension spec, but we assume that this
3319 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
3320 * to all three functions.
3321 */
3322 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
3323 ctx->Array.VAO == ctx->Array.DefaultVAO) {
3324 _mesa_error(ctx, GL_INVALID_OPERATION,
3325 "%s(No array object bound)", func);
3326 return;
3327 }
3328
3329 /* The ARB_vertex_attrib_binding spec says:
3330 *
3331 * "The error INVALID_VALUE is generated if index is greater than or
3332 * equal to the value of MAX_VERTEX_ATTRIBS."
3333 */
3334 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
3335 _mesa_error(ctx, GL_INVALID_VALUE,
3336 "%s(attribindex=%u > "
3337 "GL_MAX_VERTEX_ATTRIBS)",
3338 func, attribIndex);
3339 return;
3340 }
3341
3342 if (!validate_array_format(ctx, func, ctx->Array.VAO,
3343 VERT_ATTRIB_GENERIC(attribIndex),
3344 legalTypes, 1, sizeMax, size, type,
3345 normalized, integer, doubles, relativeOffset,
3346 format)) {
3347 return;
3348 }
3349 }
3350
3351 _mesa_update_array_format(ctx, ctx->Array.VAO,
3352 VERT_ATTRIB_GENERIC(attribIndex), size, type,
3353 format, normalized, integer, doubles,
3354 relativeOffset);
3355 }
3356
3357
3358 void GLAPIENTRY
3359 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
3360 GLboolean normalized, GLuint relativeOffset)
3361 {
3362 vertex_attrib_format(attribIndex, size, type, normalized,
3363 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
3364 BGRA_OR_4, relativeOffset,
3365 "glVertexAttribFormat");
3366 }
3367
3368
3369 void GLAPIENTRY
3370 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
3371 GLuint relativeOffset)
3372 {
3373 vertex_attrib_format(attribIndex, size, type, GL_FALSE,
3374 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK, 4,
3375 relativeOffset, "glVertexAttribIFormat");
3376 }
3377
3378
3379 void GLAPIENTRY
3380 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
3381 GLuint relativeOffset)
3382 {
3383 vertex_attrib_format(attribIndex, size, type, GL_FALSE, GL_FALSE,
3384 GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK, 4,
3385 relativeOffset, "glVertexAttribLFormat");
3386 }
3387
3388
3389 static void
3390 vertex_array_attrib_format(GLuint vaobj, bool isExtDsa, GLuint attribIndex,
3391 GLint size, GLenum type, GLboolean normalized,
3392 GLboolean integer, GLboolean doubles,
3393 GLbitfield legalTypes, GLsizei sizeMax,
3394 GLuint relativeOffset, const char *func)
3395 {
3396 GET_CURRENT_CONTEXT(ctx);
3397 struct gl_vertex_array_object *vao;
3398
3399 ASSERT_OUTSIDE_BEGIN_END(ctx);
3400
3401 GLenum format = get_array_format(ctx, sizeMax, &size);
3402
3403 if (_mesa_is_no_error_enabled(ctx)) {
3404 vao = _mesa_lookup_vao(ctx, vaobj);
3405 if (!vao)
3406 return;
3407 } else {
3408 vao = _mesa_lookup_vao_err(ctx, vaobj, isExtDsa, func);
3409 if (!vao)
3410 return;
3411
3412 /* The ARB_vertex_attrib_binding spec says:
3413 *
3414 * "The error INVALID_VALUE is generated if index is greater than or
3415 * equal to the value of MAX_VERTEX_ATTRIBS."
3416 */
3417 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
3418 _mesa_error(ctx, GL_INVALID_VALUE,
3419 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
3420 func, attribIndex);
3421 return;
3422 }
3423
3424 if (!validate_array_format(ctx, func, vao,
3425 VERT_ATTRIB_GENERIC(attribIndex),
3426 legalTypes, 1, sizeMax, size, type,
3427 normalized, integer, doubles, relativeOffset,
3428 format)) {
3429 return;
3430 }
3431 }
3432
3433 _mesa_update_array_format(ctx, vao, VERT_ATTRIB_GENERIC(attribIndex), size,
3434 type, format, normalized, integer, doubles,
3435 relativeOffset);
3436 }
3437
3438
3439 void GLAPIENTRY
3440 _mesa_VertexArrayAttribFormat(GLuint vaobj, GLuint attribIndex, GLint size,
3441 GLenum type, GLboolean normalized,
3442 GLuint relativeOffset)
3443 {
3444 vertex_array_attrib_format(vaobj, false, attribIndex, size, type, normalized,
3445 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
3446 BGRA_OR_4, relativeOffset,
3447 "glVertexArrayAttribFormat");
3448 }
3449
3450
3451 void GLAPIENTRY
3452 _mesa_VertexArrayVertexAttribFormatEXT(GLuint vaobj, GLuint attribIndex, GLint size,
3453 GLenum type, GLboolean normalized,
3454 GLuint relativeOffset)
3455 {
3456 vertex_array_attrib_format(vaobj, true, attribIndex, size, type, normalized,
3457 GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK,
3458 BGRA_OR_4, relativeOffset,
3459 "glVertexArrayVertexAttribFormatEXT");
3460 }
3461
3462
3463 void GLAPIENTRY
3464 _mesa_VertexArrayAttribIFormat(GLuint vaobj, GLuint attribIndex,
3465 GLint size, GLenum type,
3466 GLuint relativeOffset)
3467 {
3468 vertex_array_attrib_format(vaobj, false, attribIndex, size, type, GL_FALSE,
3469 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK,
3470 4, relativeOffset,
3471 "glVertexArrayAttribIFormat");
3472 }
3473
3474
3475 void GLAPIENTRY
3476 _mesa_VertexArrayVertexAttribIFormatEXT(GLuint vaobj, GLuint attribIndex,
3477 GLint size, GLenum type,
3478 GLuint relativeOffset)
3479 {
3480 vertex_array_attrib_format(vaobj, true, attribIndex, size, type, GL_FALSE,
3481 GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK,
3482 4, relativeOffset,
3483 "glVertexArrayVertexAttribIFormatEXT");
3484 }
3485
3486
3487 void GLAPIENTRY
3488 _mesa_VertexArrayAttribLFormat(GLuint vaobj, GLuint attribIndex,
3489 GLint size, GLenum type,
3490 GLuint relativeOffset)
3491 {
3492 vertex_array_attrib_format(vaobj, false, attribIndex, size, type, GL_FALSE,
3493 GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK,
3494 4, relativeOffset,
3495 "glVertexArrayAttribLFormat");
3496 }
3497
3498
3499 void GLAPIENTRY
3500 _mesa_VertexArrayVertexAttribLFormatEXT(GLuint vaobj, GLuint attribIndex,
3501 GLint size, GLenum type,
3502 GLuint relativeOffset)
3503 {
3504 vertex_array_attrib_format(vaobj, true, attribIndex, size, type, GL_FALSE,
3505 GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK,
3506 4, relativeOffset,
3507 "glVertexArrayVertexAttribLFormatEXT");
3508 }
3509
3510
3511 static void
3512 vertex_array_attrib_binding(struct gl_context *ctx,
3513 struct gl_vertex_array_object *vao,
3514 GLuint attribIndex, GLuint bindingIndex,
3515 const char *func)
3516 {
3517 ASSERT_OUTSIDE_BEGIN_END(ctx);
3518
3519 /* The ARB_vertex_attrib_binding spec says:
3520 *
3521 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
3522 * <bindingindex> must be less than the value of
3523 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
3524 * is generated."
3525 */
3526 if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
3527 _mesa_error(ctx, GL_INVALID_VALUE,
3528 "%s(attribindex=%u >= "
3529 "GL_MAX_VERTEX_ATTRIBS)",
3530 func, attribIndex);
3531 return;
3532 }
3533
3534 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
3535 _mesa_error(ctx, GL_INVALID_VALUE,
3536 "%s(bindingindex=%u >= "
3537 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
3538 func, bindingIndex);
3539 return;
3540 }
3541
3542 assert(VERT_ATTRIB_GENERIC(attribIndex) < ARRAY_SIZE(vao->VertexAttrib));
3543
3544 _mesa_vertex_attrib_binding(ctx, vao,
3545 VERT_ATTRIB_GENERIC(attribIndex),
3546 VERT_ATTRIB_GENERIC(bindingIndex));
3547 }
3548
3549
3550 void GLAPIENTRY
3551 _mesa_VertexAttribBinding_no_error(GLuint attribIndex, GLuint bindingIndex)
3552 {
3553 GET_CURRENT_CONTEXT(ctx);
3554 _mesa_vertex_attrib_binding(ctx, ctx->Array.VAO,
3555 VERT_ATTRIB_GENERIC(attribIndex),
3556 VERT_ATTRIB_GENERIC(bindingIndex));
3557 }
3558
3559
3560 void GLAPIENTRY
3561 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3562 {
3563 GET_CURRENT_CONTEXT(ctx);
3564
3565 /* The ARB_vertex_attrib_binding spec says:
3566 *
3567 * "An INVALID_OPERATION error is generated if no vertex array object
3568 * is bound."
3569 */
3570 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
3571 ctx->Array.VAO == ctx->Array.DefaultVAO) {
3572 _mesa_error(ctx, GL_INVALID_OPERATION,
3573 "glVertexAttribBinding(No array object bound)");
3574 return;
3575 }
3576
3577 vertex_array_attrib_binding(ctx, ctx->Array.VAO,
3578 attribIndex, bindingIndex,
3579 "glVertexAttribBinding");
3580 }
3581
3582
3583 void GLAPIENTRY
3584 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj, GLuint attribIndex,
3585 GLuint bindingIndex)
3586 {
3587 GET_CURRENT_CONTEXT(ctx);
3588
3589 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
3590 _mesa_vertex_attrib_binding(ctx, vao,
3591 VERT_ATTRIB_GENERIC(attribIndex),
3592 VERT_ATTRIB_GENERIC(bindingIndex));
3593 }
3594
3595
3596 void GLAPIENTRY
3597 _mesa_VertexArrayAttribBinding(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex)
3598 {
3599 GET_CURRENT_CONTEXT(ctx);
3600 struct gl_vertex_array_object *vao;
3601
3602 /* The ARB_direct_state_access specification says:
3603 *
3604 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
3605 * if <vaobj> is not [compatibility profile: zero or] the name of an
3606 * existing vertex array object."
3607 */
3608 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glVertexArrayAttribBinding");
3609 if (!vao)
3610 return;
3611
3612 vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex,
3613 "glVertexArrayAttribBinding");
3614 }
3615
3616
3617 void GLAPIENTRY
3618 _mesa_VertexArrayVertexAttribBindingEXT(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex)
3619 {
3620 GET_CURRENT_CONTEXT(ctx);
3621 struct gl_vertex_array_object *vao;
3622 vao = _mesa_lookup_vao_err(ctx, vaobj, true, "glVertexArrayVertexAttribBindingEXT");
3623 if (!vao)
3624 return;
3625
3626 vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex,
3627 "glVertexArrayVertexAttribBindingEXT");
3628 }
3629
3630
3631 static void
3632 vertex_array_binding_divisor(struct gl_context *ctx,
3633 struct gl_vertex_array_object *vao,
3634 GLuint bindingIndex, GLuint divisor,
3635 const char *func)
3636 {
3637 ASSERT_OUTSIDE_BEGIN_END(ctx);
3638
3639 if (!ctx->Extensions.ARB_instanced_arrays) {
3640 _mesa_error(ctx, GL_INVALID_OPERATION, "%s()", func);
3641 return;
3642 }
3643
3644 /* The ARB_vertex_attrib_binding spec says:
3645 *
3646 * "An INVALID_VALUE error is generated if <bindingindex> is greater
3647 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
3648 */
3649 if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) {
3650 _mesa_error(ctx, GL_INVALID_VALUE,
3651 "%s(bindingindex=%u > "
3652 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
3653 func, bindingIndex);
3654 return;
3655 }
3656
3657 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
3658 }
3659
3660
3661 void GLAPIENTRY
3662 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex, GLuint divisor)
3663 {
3664 GET_CURRENT_CONTEXT(ctx);
3665 vertex_binding_divisor(ctx, ctx->Array.VAO,
3666 VERT_ATTRIB_GENERIC(bindingIndex), divisor);
3667 }
3668
3669
3670 void GLAPIENTRY
3671 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3672 {
3673 GET_CURRENT_CONTEXT(ctx);
3674
3675 /* The ARB_vertex_attrib_binding spec says:
3676 *
3677 * "An INVALID_OPERATION error is generated if no vertex array object
3678 * is bound."
3679 */
3680 if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) &&
3681 ctx->Array.VAO == ctx->Array.DefaultVAO) {
3682 _mesa_error(ctx, GL_INVALID_OPERATION,
3683 "glVertexBindingDivisor(No array object bound)");
3684 return;
3685 }
3686
3687 vertex_array_binding_divisor(ctx, ctx->Array.VAO,
3688 bindingIndex, divisor,
3689 "glVertexBindingDivisor");
3690 }
3691
3692
3693 void GLAPIENTRY
3694 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj, GLuint bindingIndex,
3695 GLuint divisor)
3696 {
3697 GET_CURRENT_CONTEXT(ctx);
3698
3699 struct gl_vertex_array_object *vao = _mesa_lookup_vao(ctx, vaobj);
3700 vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor);
3701 }
3702
3703
3704 void GLAPIENTRY
3705 _mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex,
3706 GLuint divisor)
3707 {
3708 struct gl_vertex_array_object *vao;
3709 GET_CURRENT_CONTEXT(ctx);
3710
3711 /* The ARB_direct_state_access specification says:
3712 *
3713 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
3714 * if <vaobj> is not [compatibility profile: zero or] the name of an
3715 * existing vertex array object."
3716 */
3717 vao = _mesa_lookup_vao_err(ctx, vaobj, false, "glVertexArrayBindingDivisor");
3718 if (!vao)
3719 return;
3720
3721 vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor,
3722 "glVertexArrayBindingDivisor");
3723 }
3724
3725
3726 void GLAPIENTRY
3727 _mesa_VertexArrayVertexBindingDivisorEXT(GLuint vaobj, GLuint bindingIndex,
3728 GLuint divisor)
3729 {
3730 struct gl_vertex_array_object *vao;
3731 GET_CURRENT_CONTEXT(ctx);
3732
3733 /* The ARB_direct_state_access specification says:
3734 *
3735 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
3736 * if <vaobj> is not [compatibility profile: zero or] the name of an
3737 * existing vertex array object."
3738 */
3739 vao = _mesa_lookup_vao_err(ctx, vaobj, true, "glVertexArrayVertexBindingDivisorEXT");
3740 if (!vao)
3741 return;
3742
3743 vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor,
3744 "glVertexArrayVertexBindingDivisorEXT");
3745 }
3746
3747
3748 void
3749 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
3750 struct gl_array_attributes *dst,
3751 const struct gl_array_attributes *src)
3752 {
3753 dst->Ptr = src->Ptr;
3754 dst->RelativeOffset = src->RelativeOffset;
3755 dst->Format = src->Format;
3756 dst->Stride = src->Stride;
3757 dst->BufferBindingIndex = src->BufferBindingIndex;
3758 dst->_EffBufferBindingIndex = src->_EffBufferBindingIndex;
3759 dst->_EffRelativeOffset = src->_EffRelativeOffset;
3760 }
3761
3762 void
3763 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
3764 struct gl_vertex_buffer_binding *dst,
3765 const struct gl_vertex_buffer_binding *src)
3766 {
3767 dst->Offset = src->Offset;
3768 dst->Stride = src->Stride;
3769 dst->InstanceDivisor = src->InstanceDivisor;
3770 dst->_BoundArrays = src->_BoundArrays;
3771 dst->_EffBoundArrays = src->_EffBoundArrays;
3772 dst->_EffOffset = src->_EffOffset;
3773
3774 _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj);
3775 }
3776
3777 /**
3778 * Print current vertex object/array info. For debug.
3779 */
3780 void
3781 _mesa_print_arrays(struct gl_context *ctx)
3782 {
3783 const struct gl_vertex_array_object *vao = ctx->Array.VAO;
3784
3785 fprintf(stderr, "Array Object %u\n", vao->Name);
3786
3787 GLbitfield mask = vao->Enabled;
3788 while (mask) {
3789 const gl_vert_attrib i = u_bit_scan(&mask);
3790 const struct gl_array_attributes *array = &vao->VertexAttrib[i];
3791
3792 const struct gl_vertex_buffer_binding *binding =
3793 &vao->BufferBinding[array->BufferBindingIndex];
3794 const struct gl_buffer_object *bo = binding->BufferObj;
3795
3796 fprintf(stderr, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
3797 "Stride=%d, Buffer=%u(Size %lu)\n",
3798 gl_vert_attrib_name((gl_vert_attrib)i),
3799 array->Ptr, _mesa_enum_to_string(array->Format.Type),
3800 array->Format.Size,
3801 array->Format._ElementSize, binding->Stride, bo ? bo->Name : 0,
3802 (unsigned long)(bo ? bo->Size : 0));
3803 }
3804 }
3805
3806 /**
3807 * Initialize attributes of a vertex array within a vertex array object.
3808 * \param vao the container vertex array object
3809 * \param index which array in the VAO to initialize
3810 * \param size number of components (1, 2, 3 or 4) per attribute
3811 * \param type datatype of the attribute (GL_FLOAT, GL_INT, etc).
3812 */
3813 static void
3814 init_array(struct gl_context *ctx,
3815 struct gl_vertex_array_object *vao,
3816 gl_vert_attrib index, GLint size, GLint type)
3817 {
3818 assert(index < ARRAY_SIZE(vao->VertexAttrib));
3819 struct gl_array_attributes *array = &vao->VertexAttrib[index];
3820 assert(index < ARRAY_SIZE(vao->BufferBinding));
3821 struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index];
3822
3823 _mesa_set_vertex_format(&array->Format, size, type, GL_RGBA,
3824 GL_FALSE, GL_FALSE, GL_FALSE);
3825 array->Stride = 0;
3826 array->Ptr = NULL;
3827 array->RelativeOffset = 0;
3828 ASSERT_BITFIELD_SIZE(struct gl_array_attributes, BufferBindingIndex,
3829 VERT_ATTRIB_MAX - 1);
3830 array->BufferBindingIndex = index;
3831
3832 binding->Offset = 0;
3833 binding->Stride = array->Format._ElementSize;
3834 binding->BufferObj = NULL;
3835 binding->_BoundArrays = BITFIELD_BIT(index);
3836 }
3837
3838 static void
3839 init_default_vao_state(struct gl_context *ctx)
3840 {
3841 struct gl_vertex_array_object *vao = &ctx->Array.DefaultVAOState;
3842
3843 vao->RefCount = 1;
3844 vao->SharedAndImmutable = false;
3845
3846 /* Init the individual arrays */
3847 for (unsigned i = 0; i < ARRAY_SIZE(vao->VertexAttrib); i++) {
3848 switch (i) {
3849 case VERT_ATTRIB_NORMAL:
3850 init_array(ctx, vao, VERT_ATTRIB_NORMAL, 3, GL_FLOAT);
3851 break;
3852 case VERT_ATTRIB_COLOR1:
3853 init_array(ctx, vao, VERT_ATTRIB_COLOR1, 3, GL_FLOAT);
3854 break;
3855 case VERT_ATTRIB_FOG:
3856 init_array(ctx, vao, VERT_ATTRIB_FOG, 1, GL_FLOAT);
3857 break;
3858 case VERT_ATTRIB_COLOR_INDEX:
3859 init_array(ctx, vao, VERT_ATTRIB_COLOR_INDEX, 1, GL_FLOAT);
3860 break;
3861 case VERT_ATTRIB_EDGEFLAG:
3862 init_array(ctx, vao, VERT_ATTRIB_EDGEFLAG, 1, GL_UNSIGNED_BYTE);
3863 break;
3864 case VERT_ATTRIB_POINT_SIZE:
3865 init_array(ctx, vao, VERT_ATTRIB_POINT_SIZE, 1, GL_FLOAT);
3866 break;
3867 default:
3868 init_array(ctx, vao, i, 4, GL_FLOAT);
3869 break;
3870 }
3871 }
3872
3873 vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_IDENTITY;
3874 }
3875
3876 /**
3877 * Initialize vertex array state for given context.
3878 */
3879 void
3880 _mesa_init_varray(struct gl_context *ctx)
3881 {
3882 init_default_vao_state(ctx);
3883
3884 ctx->Array.DefaultVAO = _mesa_new_vao(ctx, 0);
3885 _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO);
3886 ctx->Array._EmptyVAO = _mesa_new_vao(ctx, ~0u);
3887 _mesa_reference_vao(ctx, &ctx->Array._DrawVAO, ctx->Array._EmptyVAO);
3888 ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */
3889
3890 ctx->Array.Objects = _mesa_NewHashTable();
3891 }
3892
3893
3894 /**
3895 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
3896 */
3897 static void
3898 delete_arrayobj_cb(GLuint id, void *data, void *userData)
3899 {
3900 struct gl_vertex_array_object *vao = (struct gl_vertex_array_object *) data;
3901 struct gl_context *ctx = (struct gl_context *) userData;
3902 _mesa_delete_vao(ctx, vao);
3903 }
3904
3905
3906 /**
3907 * Free vertex array state for given context.
3908 */
3909 void
3910 _mesa_free_varray_data(struct gl_context *ctx)
3911 {
3912 _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);
3913 _mesa_DeleteHashTable(ctx->Array.Objects);
3914 }
3915
3916 void GLAPIENTRY
3917 _mesa_GetVertexArrayIntegervEXT(GLuint vaobj, GLenum pname, GLint *param)
3918 {
3919 GET_CURRENT_CONTEXT(ctx);
3920 struct gl_vertex_array_object* vao;
3921 struct gl_buffer_object *buf;
3922 void* ptr;
3923
3924 vao = _mesa_lookup_vao_err(ctx, vaobj, true,
3925 "glGetVertexArrayIntegervEXT");
3926 if (!vao)
3927 return;
3928
3929 /* The EXT_direct_state_access spec says:
3930 *
3931 * "For GetVertexArrayIntegervEXT, pname must be one of the "Get value" tokens
3932 * in tables 6.6, 6.7, 6.8, and 6.9 that use GetIntegerv, IsEnabled, or
3933 * GetPointerv for their "Get command" (so excluding the VERTEX_ATTRIB_*
3934 * tokens)."
3935 */
3936 switch (pname) {
3937 /* Tokens using GetIntegerv */
3938 case GL_CLIENT_ACTIVE_TEXTURE:
3939 *param = GL_TEXTURE0_ARB + ctx->Array.ActiveTexture;
3940 break;
3941 case GL_VERTEX_ARRAY_SIZE:
3942 *param = vao->VertexAttrib[VERT_ATTRIB_POS].Format.Size;
3943 break;
3944 case GL_VERTEX_ARRAY_TYPE:
3945 *param = vao->VertexAttrib[VERT_ATTRIB_POS].Format.Type;
3946 break;
3947 case GL_VERTEX_ARRAY_STRIDE:
3948 *param = vao->VertexAttrib[VERT_ATTRIB_POS].Stride;
3949 break;
3950 case GL_VERTEX_ARRAY_BUFFER_BINDING:
3951 buf = vao->BufferBinding[VERT_ATTRIB_POS].BufferObj;
3952 *param = buf ? buf->Name : 0;
3953 break;
3954 case GL_COLOR_ARRAY_SIZE:
3955 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR0].Format.Size;
3956 break;
3957 case GL_COLOR_ARRAY_TYPE:
3958 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR0].Format.Type;
3959 break;
3960 case GL_COLOR_ARRAY_STRIDE:
3961 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR0].Stride;
3962 break;
3963 case GL_COLOR_ARRAY_BUFFER_BINDING:
3964 buf = vao->BufferBinding[VERT_ATTRIB_COLOR0].BufferObj;
3965 *param = buf ? buf->Name : 0;
3966 break;
3967 case GL_EDGE_FLAG_ARRAY_STRIDE:
3968 *param = vao->VertexAttrib[VERT_ATTRIB_EDGEFLAG].Stride;
3969 break;
3970 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING:
3971 buf = vao->BufferBinding[VERT_ATTRIB_EDGEFLAG].BufferObj;
3972 *param = buf ? buf->Name : 0;
3973 break;
3974 case GL_INDEX_ARRAY_TYPE:
3975 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Format.Type;
3976 break;
3977 case GL_INDEX_ARRAY_STRIDE:
3978 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Stride;
3979 break;
3980 case GL_INDEX_ARRAY_BUFFER_BINDING:
3981 buf = vao->BufferBinding[VERT_ATTRIB_COLOR_INDEX].BufferObj;
3982 *param = buf ? buf->Name : 0;
3983 break;
3984 case GL_NORMAL_ARRAY_TYPE:
3985 *param = vao->VertexAttrib[VERT_ATTRIB_NORMAL].Format.Type;
3986 break;
3987 case GL_NORMAL_ARRAY_STRIDE:
3988 *param = vao->VertexAttrib[VERT_ATTRIB_NORMAL].Stride;
3989 break;
3990 case GL_NORMAL_ARRAY_BUFFER_BINDING:
3991 buf = vao->BufferBinding[VERT_ATTRIB_NORMAL].BufferObj;
3992 *param = buf ? buf->Name : 0;
3993 break;
3994 case GL_TEXTURE_COORD_ARRAY_SIZE:
3995 *param = vao->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Format.Size;
3996 break;
3997 case GL_TEXTURE_COORD_ARRAY_TYPE:
3998 *param = vao->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Format.Type;
3999 break;
4000 case GL_TEXTURE_COORD_ARRAY_STRIDE:
4001 *param = vao->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].Stride;
4002 break;
4003 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
4004 buf = vao->BufferBinding[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].BufferObj;
4005 *param = buf ? buf->Name : 0;
4006 break;
4007 case GL_FOG_COORD_ARRAY_TYPE:
4008 *param = vao->VertexAttrib[VERT_ATTRIB_FOG].Format.Type;
4009 break;
4010 case GL_FOG_COORD_ARRAY_STRIDE:
4011 *param = vao->VertexAttrib[VERT_ATTRIB_FOG].Stride;
4012 break;
4013 case GL_FOG_COORD_ARRAY_BUFFER_BINDING:
4014 buf = vao->BufferBinding[VERT_ATTRIB_FOG].BufferObj;
4015 *param = buf ? buf->Name : 0;
4016 break;
4017 case GL_SECONDARY_COLOR_ARRAY_SIZE:
4018 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR1].Format.Size;
4019 break;
4020 case GL_SECONDARY_COLOR_ARRAY_TYPE:
4021 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR1].Format.Type;
4022 break;
4023 case GL_SECONDARY_COLOR_ARRAY_STRIDE:
4024 *param = vao->VertexAttrib[VERT_ATTRIB_COLOR1].Stride;
4025 break;
4026 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING:
4027 buf = vao->BufferBinding[VERT_ATTRIB_COLOR1].BufferObj;
4028 *param = buf ? buf->Name : 0;
4029 break;
4030
4031 /* Tokens using IsEnabled */
4032 case GL_VERTEX_ARRAY:
4033 *param = !!(vao->Enabled & VERT_BIT_POS);
4034 break;
4035 case GL_COLOR_ARRAY:
4036 *param = !!(vao->Enabled & VERT_BIT_COLOR0);
4037 break;
4038 case GL_EDGE_FLAG_ARRAY:
4039 *param = !!(vao->Enabled & VERT_BIT_EDGEFLAG);
4040 break;
4041 case GL_INDEX_ARRAY:
4042 *param = !!(vao->Enabled & VERT_BIT_COLOR_INDEX);
4043 break;
4044 case GL_NORMAL_ARRAY:
4045 *param = !!(vao->Enabled & VERT_BIT_NORMAL);
4046 break;
4047 case GL_TEXTURE_COORD_ARRAY:
4048 *param = !!(vao->Enabled & VERT_BIT_TEX(ctx->Array.ActiveTexture));
4049 break;
4050 case GL_FOG_COORD_ARRAY:
4051 *param = !!(vao->Enabled & VERT_BIT_FOG);
4052 break;
4053 case GL_SECONDARY_COLOR_ARRAY:
4054 *param = !!(vao->Enabled & VERT_BIT_COLOR1);
4055 break;
4056
4057 /* Tokens using GetPointerv */
4058 case GL_VERTEX_ARRAY_POINTER:
4059 case GL_COLOR_ARRAY_POINTER:
4060 case GL_EDGE_FLAG_ARRAY_POINTER:
4061 case GL_INDEX_ARRAY_POINTER:
4062 case GL_NORMAL_ARRAY_POINTER:
4063 case GL_TEXTURE_COORD_ARRAY_POINTER:
4064 case GL_FOG_COORD_ARRAY_POINTER:
4065 case GL_SECONDARY_COLOR_ARRAY_POINTER:
4066 _get_vao_pointerv(pname, vao, &ptr, "glGetVertexArrayIntegervEXT");
4067 *param = (int) ((intptr_t) ptr & 0xFFFFFFFF);
4068 break;
4069
4070 default:
4071 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayIntegervEXT(pname)");
4072 }
4073 }
4074
4075 void GLAPIENTRY
4076 _mesa_GetVertexArrayPointervEXT(GLuint vaobj, GLenum pname, GLvoid** param)
4077 {
4078 GET_CURRENT_CONTEXT(ctx);
4079 struct gl_vertex_array_object* vao;
4080
4081 vao = _mesa_lookup_vao_err(ctx, vaobj, true,
4082 "glGetVertexArrayPointervEXT");
4083 if (!vao)
4084 return;
4085
4086 /* The EXT_direct_state_access spec says:
4087 *
4088 * "For GetVertexArrayPointervEXT, pname must be a *_ARRAY_POINTER token from
4089 * tables 6.6, 6.7, and 6.8 excluding VERTEX_ATTRIB_ARRAY_POINT."
4090 */
4091 switch (pname) {
4092 case GL_VERTEX_ARRAY_POINTER:
4093 case GL_COLOR_ARRAY_POINTER:
4094 case GL_EDGE_FLAG_ARRAY_POINTER:
4095 case GL_INDEX_ARRAY_POINTER:
4096 case GL_NORMAL_ARRAY_POINTER:
4097 case GL_TEXTURE_COORD_ARRAY_POINTER:
4098 case GL_FOG_COORD_ARRAY_POINTER:
4099 case GL_SECONDARY_COLOR_ARRAY_POINTER:
4100 break;
4101
4102 default:
4103 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayPointervEXT(pname)");
4104 return;
4105 }
4106
4107 /* pname has been validated, we can now use the helper function */
4108 _get_vao_pointerv(pname, vao, param, "glGetVertexArrayPointervEXT");
4109 }
4110
4111 void GLAPIENTRY
4112 _mesa_GetVertexArrayIntegeri_vEXT(GLuint vaobj, GLuint index, GLenum pname, GLint *param)
4113 {
4114 GET_CURRENT_CONTEXT(ctx);
4115 struct gl_vertex_array_object* vao;
4116 struct gl_buffer_object *buf;
4117
4118 vao = _mesa_lookup_vao_err(ctx, vaobj, true,
4119 "glGetVertexArrayIntegeri_vEXT");
4120 if (!vao)
4121 return;
4122
4123
4124 /* The EXT_direct_state_access spec says:
4125 *
4126 * "For GetVertexArrayIntegeri_vEXT, pname must be one of the
4127 * "Get value" tokens in tables 6.8 and 6.9 that use GetVertexAttribiv
4128 * or GetVertexAttribPointerv (so allowing only the VERTEX_ATTRIB_*
4129 * tokens) or a token of the form TEXTURE_COORD_ARRAY (the enable) or
4130 * TEXTURE_COORD_ARRAY_*; index identifies the vertex attribute
4131 * array to query or texture coordinate set index respectively."
4132 */
4133
4134 switch (pname) {
4135 case GL_TEXTURE_COORD_ARRAY:
4136 *param = !!(vao->Enabled & VERT_BIT_TEX(index));
4137 break;
4138 case GL_TEXTURE_COORD_ARRAY_SIZE:
4139 *param = vao->VertexAttrib[VERT_ATTRIB_TEX(index)].Format.Size;
4140 break;
4141 case GL_TEXTURE_COORD_ARRAY_TYPE:
4142 *param = vao->VertexAttrib[VERT_ATTRIB_TEX(index)].Format.Type;
4143 break;
4144 case GL_TEXTURE_COORD_ARRAY_STRIDE:
4145 *param = vao->VertexAttrib[VERT_ATTRIB_TEX(index)].Stride;
4146 break;
4147 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
4148 buf = vao->BufferBinding[VERT_ATTRIB_TEX(index)].BufferObj;
4149 *param = buf ? buf->Name : 0;
4150 break;
4151 default:
4152 *param = get_vertex_array_attrib(ctx, vao, index, pname, "glGetVertexArrayIntegeri_vEXT");
4153 }
4154 }
4155
4156 void GLAPIENTRY
4157 _mesa_GetVertexArrayPointeri_vEXT(GLuint vaobj, GLuint index, GLenum pname, GLvoid** param)
4158 {
4159 GET_CURRENT_CONTEXT(ctx);
4160 struct gl_vertex_array_object* vao;
4161
4162 vao = _mesa_lookup_vao_err(ctx, vaobj, true,
4163 "glGetVertexArrayPointeri_vEXT");
4164 if (!vao)
4165 return;
4166
4167 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) {
4168 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexArrayPointeri_vEXT(index)");
4169 return;
4170 }
4171
4172 /* The EXT_direct_state_access spec says:
4173 *
4174 * "For GetVertexArrayPointeri_vEXT, pname must be VERTEX_ATTRIB_ARRAY_POINTER
4175 * or TEXTURE_COORD_ARRAY_POINTER with the index parameter indicating the vertex
4176 * attribute or texture coordindate set index."
4177 */
4178 switch(pname) {
4179 case GL_VERTEX_ATTRIB_ARRAY_POINTER:
4180 *param = (GLvoid *) vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr;
4181 break;
4182 case GL_TEXTURE_COORD_ARRAY_POINTER:
4183 *param = (GLvoid *) vao->VertexAttrib[VERT_ATTRIB_TEX(index)].Ptr;
4184 break;
4185 default:
4186 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayPointeri_vEXT(pname)");
4187 }
4188 }