2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
28 #include <inttypes.h> /* for PRId64 macro */
32 #include "bufferobj.h"
36 #include "glformats.h"
44 #include "main/dispatch.h"
47 /** Used to do error checking for GL_EXT_vertex_array_bgra */
51 /** Used to indicate which GL datatypes are accepted by each of the
52 * glVertex/Color/Attrib/EtcPointer() functions.
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)
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 | \
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)
80 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
81 SHORT_BIT | UNSIGNED_SHORT_BIT | \
82 INT_BIT | UNSIGNED_INT_BIT)
84 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
87 /** Convert GL datatype enum into a <type>_BIT value seen above */
89 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
96 case GL_UNSIGNED_BYTE
:
97 return UNSIGNED_BYTE_BIT
;
100 case GL_UNSIGNED_SHORT
:
101 return UNSIGNED_SHORT_BIT
;
104 case GL_UNSIGNED_INT
:
105 return UNSIGNED_INT_BIT
;
107 case GL_HALF_FLOAT_OES
:
108 if (ctx
->Extensions
.ARB_half_float_vertex
)
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
;
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.
136 update_attribute_map_mode(const struct gl_context
*ctx
,
137 struct gl_vertex_array_object
*vao
)
140 * There is no need to change the mapping away from the
141 * identity mapping if we are not in compat mode.
143 if (ctx
->API
!= API_OPENGL_COMPAT
)
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
;
152 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_IDENTITY
;
157 * Sets the BufferBindingIndex field for the vertex attribute given by
161 _mesa_vertex_attrib_binding(struct gl_context
*ctx
,
162 struct gl_vertex_array_object
*vao
,
163 gl_vert_attrib attribIndex
,
166 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attribIndex
];
167 assert(!vao
->SharedAndImmutable
);
169 if (array
->BufferBindingIndex
!= bindingIndex
) {
170 const GLbitfield array_bit
= VERT_BIT(attribIndex
);
172 if (vao
->BufferBinding
[bindingIndex
].BufferObj
)
173 vao
->VertexAttribBufferMask
|= array_bit
;
175 vao
->VertexAttribBufferMask
&= ~array_bit
;
177 if (vao
->BufferBinding
[bindingIndex
].InstanceDivisor
)
178 vao
->NonZeroDivisorMask
|= array_bit
;
180 vao
->NonZeroDivisorMask
&= ~array_bit
;
182 vao
->BufferBinding
[array
->BufferBindingIndex
]._BoundArrays
&= ~array_bit
;
183 vao
->BufferBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
185 array
->BufferBindingIndex
= bindingIndex
;
187 vao
->NewArrays
|= vao
->Enabled
& array_bit
;
193 * Binds a buffer object to the vertex buffer binding point given by index,
194 * and sets the Offset and Stride fields.
197 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
198 struct gl_vertex_array_object
*vao
,
200 struct gl_buffer_object
*vbo
,
201 GLintptr offset
, GLsizei stride
,
202 bool offset_is_int32
)
204 assert(index
< ARRAY_SIZE(vao
->BufferBinding
));
205 assert(!vao
->SharedAndImmutable
);
206 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
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).
213 _mesa_warning(ctx
, "Received negative int32 vertex buffer offset. "
214 "(driver limitation)\n");
216 /* We can't disable this binding, so use a non-negative offset value
222 if (binding
->BufferObj
!= vbo
||
223 binding
->Offset
!= offset
||
224 binding
->Stride
!= stride
) {
226 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
228 binding
->Offset
= offset
;
229 binding
->Stride
= stride
;
232 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
234 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
235 vbo
->UsageHistory
|= USAGE_ARRAY_BUFFER
;
238 vao
->NewArrays
|= vao
->Enabled
& binding
->_BoundArrays
;
244 * Sets the InstanceDivisor field in the vertex buffer binding point
245 * given by bindingIndex.
248 vertex_binding_divisor(struct gl_context
*ctx
,
249 struct gl_vertex_array_object
*vao
,
253 struct gl_vertex_buffer_binding
*binding
=
254 &vao
->BufferBinding
[bindingIndex
];
255 assert(!vao
->SharedAndImmutable
);
257 if (binding
->InstanceDivisor
!= divisor
) {
258 binding
->InstanceDivisor
= divisor
;
261 vao
->NonZeroDivisorMask
|= binding
->_BoundArrays
;
263 vao
->NonZeroDivisorMask
&= ~binding
->_BoundArrays
;
265 vao
->NewArrays
|= vao
->Enabled
& binding
->_BoundArrays
;
269 /* vertex_formats[gltype - GL_BYTE][integer*2 + normalized][size - 1] */
270 static const uint16_t vertex_formats
[][4][4] = {
273 PIPE_FORMAT_R8_SSCALED
,
274 PIPE_FORMAT_R8G8_SSCALED
,
275 PIPE_FORMAT_R8G8B8_SSCALED
,
276 PIPE_FORMAT_R8G8B8A8_SSCALED
279 PIPE_FORMAT_R8_SNORM
,
280 PIPE_FORMAT_R8G8_SNORM
,
281 PIPE_FORMAT_R8G8B8_SNORM
,
282 PIPE_FORMAT_R8G8B8A8_SNORM
286 PIPE_FORMAT_R8G8_SINT
,
287 PIPE_FORMAT_R8G8B8_SINT
,
288 PIPE_FORMAT_R8G8B8A8_SINT
291 { /* GL_UNSIGNED_BYTE */
293 PIPE_FORMAT_R8_USCALED
,
294 PIPE_FORMAT_R8G8_USCALED
,
295 PIPE_FORMAT_R8G8B8_USCALED
,
296 PIPE_FORMAT_R8G8B8A8_USCALED
299 PIPE_FORMAT_R8_UNORM
,
300 PIPE_FORMAT_R8G8_UNORM
,
301 PIPE_FORMAT_R8G8B8_UNORM
,
302 PIPE_FORMAT_R8G8B8A8_UNORM
306 PIPE_FORMAT_R8G8_UINT
,
307 PIPE_FORMAT_R8G8B8_UINT
,
308 PIPE_FORMAT_R8G8B8A8_UINT
313 PIPE_FORMAT_R16_SSCALED
,
314 PIPE_FORMAT_R16G16_SSCALED
,
315 PIPE_FORMAT_R16G16B16_SSCALED
,
316 PIPE_FORMAT_R16G16B16A16_SSCALED
319 PIPE_FORMAT_R16_SNORM
,
320 PIPE_FORMAT_R16G16_SNORM
,
321 PIPE_FORMAT_R16G16B16_SNORM
,
322 PIPE_FORMAT_R16G16B16A16_SNORM
325 PIPE_FORMAT_R16_SINT
,
326 PIPE_FORMAT_R16G16_SINT
,
327 PIPE_FORMAT_R16G16B16_SINT
,
328 PIPE_FORMAT_R16G16B16A16_SINT
331 { /* GL_UNSIGNED_SHORT */
333 PIPE_FORMAT_R16_USCALED
,
334 PIPE_FORMAT_R16G16_USCALED
,
335 PIPE_FORMAT_R16G16B16_USCALED
,
336 PIPE_FORMAT_R16G16B16A16_USCALED
339 PIPE_FORMAT_R16_UNORM
,
340 PIPE_FORMAT_R16G16_UNORM
,
341 PIPE_FORMAT_R16G16B16_UNORM
,
342 PIPE_FORMAT_R16G16B16A16_UNORM
345 PIPE_FORMAT_R16_UINT
,
346 PIPE_FORMAT_R16G16_UINT
,
347 PIPE_FORMAT_R16G16B16_UINT
,
348 PIPE_FORMAT_R16G16B16A16_UINT
353 PIPE_FORMAT_R32_SSCALED
,
354 PIPE_FORMAT_R32G32_SSCALED
,
355 PIPE_FORMAT_R32G32B32_SSCALED
,
356 PIPE_FORMAT_R32G32B32A32_SSCALED
359 PIPE_FORMAT_R32_SNORM
,
360 PIPE_FORMAT_R32G32_SNORM
,
361 PIPE_FORMAT_R32G32B32_SNORM
,
362 PIPE_FORMAT_R32G32B32A32_SNORM
365 PIPE_FORMAT_R32_SINT
,
366 PIPE_FORMAT_R32G32_SINT
,
367 PIPE_FORMAT_R32G32B32_SINT
,
368 PIPE_FORMAT_R32G32B32A32_SINT
371 { /* GL_UNSIGNED_INT */
373 PIPE_FORMAT_R32_USCALED
,
374 PIPE_FORMAT_R32G32_USCALED
,
375 PIPE_FORMAT_R32G32B32_USCALED
,
376 PIPE_FORMAT_R32G32B32A32_USCALED
379 PIPE_FORMAT_R32_UNORM
,
380 PIPE_FORMAT_R32G32_UNORM
,
381 PIPE_FORMAT_R32G32B32_UNORM
,
382 PIPE_FORMAT_R32G32B32A32_UNORM
385 PIPE_FORMAT_R32_UINT
,
386 PIPE_FORMAT_R32G32_UINT
,
387 PIPE_FORMAT_R32G32B32_UINT
,
388 PIPE_FORMAT_R32G32B32A32_UINT
393 PIPE_FORMAT_R32_FLOAT
,
394 PIPE_FORMAT_R32G32_FLOAT
,
395 PIPE_FORMAT_R32G32B32_FLOAT
,
396 PIPE_FORMAT_R32G32B32A32_FLOAT
399 PIPE_FORMAT_R32_FLOAT
,
400 PIPE_FORMAT_R32G32_FLOAT
,
401 PIPE_FORMAT_R32G32B32_FLOAT
,
402 PIPE_FORMAT_R32G32B32A32_FLOAT
405 {{0}}, /* GL_2_BYTES */
406 {{0}}, /* GL_3_BYTES */
407 {{0}}, /* GL_4_BYTES */
410 PIPE_FORMAT_R64_FLOAT
,
411 PIPE_FORMAT_R64G64_FLOAT
,
412 PIPE_FORMAT_R64G64B64_FLOAT
,
413 PIPE_FORMAT_R64G64B64A64_FLOAT
416 PIPE_FORMAT_R64_FLOAT
,
417 PIPE_FORMAT_R64G64_FLOAT
,
418 PIPE_FORMAT_R64G64B64_FLOAT
,
419 PIPE_FORMAT_R64G64B64A64_FLOAT
422 { /* GL_HALF_FLOAT */
424 PIPE_FORMAT_R16_FLOAT
,
425 PIPE_FORMAT_R16G16_FLOAT
,
426 PIPE_FORMAT_R16G16B16_FLOAT
,
427 PIPE_FORMAT_R16G16B16A16_FLOAT
430 PIPE_FORMAT_R16_FLOAT
,
431 PIPE_FORMAT_R16G16_FLOAT
,
432 PIPE_FORMAT_R16G16B16_FLOAT
,
433 PIPE_FORMAT_R16G16B16A16_FLOAT
438 PIPE_FORMAT_R32_FIXED
,
439 PIPE_FORMAT_R32G32_FIXED
,
440 PIPE_FORMAT_R32G32B32_FIXED
,
441 PIPE_FORMAT_R32G32B32A32_FIXED
444 PIPE_FORMAT_R32_FIXED
,
445 PIPE_FORMAT_R32G32_FIXED
,
446 PIPE_FORMAT_R32G32B32_FIXED
,
447 PIPE_FORMAT_R32G32B32A32_FIXED
453 * Return a PIPE_FORMAT_x for the given GL datatype and size.
455 static enum pipe_format
456 vertex_format_to_pipe_format(GLubyte size
, GLenum16 type
, GLenum16 format
,
457 GLboolean normalized
, GLboolean integer
,
460 assert(size
>= 1 && size
<= 4);
461 assert(format
== GL_RGBA
|| format
== GL_BGRA
);
463 /* 64-bit attributes are translated by drivers. */
465 return PIPE_FORMAT_NONE
;
468 case GL_HALF_FLOAT_OES
:
469 type
= GL_HALF_FLOAT
;
472 case GL_INT_2_10_10_10_REV
:
473 assert(size
== 4 && !integer
);
475 if (format
== GL_BGRA
) {
477 return PIPE_FORMAT_B10G10R10A2_SNORM
;
479 return PIPE_FORMAT_B10G10R10A2_SSCALED
;
482 return PIPE_FORMAT_R10G10B10A2_SNORM
;
484 return PIPE_FORMAT_R10G10B10A2_SSCALED
;
488 case GL_UNSIGNED_INT_2_10_10_10_REV
:
489 assert(size
== 4 && !integer
);
491 if (format
== GL_BGRA
) {
493 return PIPE_FORMAT_B10G10R10A2_UNORM
;
495 return PIPE_FORMAT_B10G10R10A2_USCALED
;
498 return PIPE_FORMAT_R10G10B10A2_UNORM
;
500 return PIPE_FORMAT_R10G10B10A2_USCALED
;
504 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
505 assert(size
== 3 && !integer
&& format
== GL_RGBA
);
506 return PIPE_FORMAT_R11G11B10_FLOAT
;
508 case GL_UNSIGNED_BYTE
:
509 if (format
== GL_BGRA
) {
510 /* this is an odd-ball case */
512 return PIPE_FORMAT_B8G8R8A8_UNORM
;
517 unsigned index
= integer
*2 + normalized
;
519 assert(type
>= GL_BYTE
&& type
<= GL_FIXED
);
520 return vertex_formats
[type
- GL_BYTE
][index
][size
-1];
524 _mesa_set_vertex_format(struct gl_vertex_format
*vertex_format
,
525 GLubyte size
, GLenum16 type
, GLenum16 format
,
526 GLboolean normalized
, GLboolean integer
,
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
,
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().
549 get_legal_types_mask(const struct gl_context
*ctx
)
551 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
553 if (_mesa_is_gles(ctx
)) {
554 legalTypesMask
&= ~(FIXED_GL_BIT
|
556 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
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.
565 if (ctx
->Version
< 30) {
566 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
568 UNSIGNED_INT_2_10_10_10_REV_BIT
|
569 INT_2_10_10_10_REV_BIT
);
571 if (!_mesa_has_OES_vertex_half_float(ctx
))
572 legalTypesMask
&= ~HALF_BIT
;
576 legalTypesMask
&= ~FIXED_ES_BIT
;
578 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
579 legalTypesMask
&= ~FIXED_GL_BIT
;
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
);
585 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
586 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
589 return legalTypesMask
;
593 get_array_format(const struct gl_context
*ctx
, GLint sizeMax
, GLint
*size
)
595 GLenum format
= GL_RGBA
;
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.
601 if (ctx
->Extensions
.EXT_vertex_array_bgra
&& sizeMax
== BGRA_OR_4
&&
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
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
)
630 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
631 struct gl_vertex_format new_format
;
633 assert(!vao
->SharedAndImmutable
);
636 _mesa_set_vertex_format(&new_format
, size
, type
, format
,
637 normalized
, integer
, doubles
);
639 if ((array
->RelativeOffset
== relativeOffset
) &&
640 !memcmp(&new_format
, &array
->Format
, sizeof(new_format
)))
643 array
->RelativeOffset
= relativeOffset
;
644 array
->Format
= new_format
;
646 vao
->NewArrays
|= vao
->Enabled
& VERT_BIT(attrib
);
650 * Does error checking of the format in an attrib array.
652 * Called by *Pointer() and VertexAttrib*Format().
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.
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
)
678 /* at most, one of these bools can be true */
679 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
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
687 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
688 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
691 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
693 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
694 /* BGRA ordering is not supported in ES contexts.
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
));
706 if (format
== GL_BGRA
) {
707 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
709 * "An INVALID_OPERATION error is generated under any of the following
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;
715 * • size is BGRA and normalized is FALSE;"
717 bool bgra_error
= false;
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
)
724 } else if (type
!= GL_UNSIGNED_BYTE
)
728 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
729 func
, _mesa_enum_to_string(type
));
734 _mesa_error(ctx
, GL_INVALID_OPERATION
,
735 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
739 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
740 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
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
);
751 /* The ARB_vertex_attrib_binding_spec says:
753 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
754 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
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
);
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
);
774 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
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
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
,
801 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
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..."
809 * The check for VBOs is handled below.
811 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
812 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
818 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
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
);
829 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
831 * "An INVALID_OPERATION error is generated under any of the following
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."
841 if (ptr
!= NULL
&& vao
!= ctx
->Array
.DefaultVAO
&&
843 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
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
)
859 validate_array(ctx
, func
, vao
, obj
, attrib
, legalTypes
, sizeMin
, sizeMax
,
860 size
, type
, stride
, normalized
, integer
, doubles
, ptr
);
862 return validate_array_format(ctx
, func
, vao
, attrib
, legalTypes
, sizeMin
,
863 sizeMax
, size
, type
, normalized
, integer
,
869 * Update state for glVertex/Color/TexCoord/...Pointer functions.
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
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
,
890 GLint size
, GLenum type
, GLsizei stride
,
891 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
894 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
895 normalized
, integer
, doubles
, 0);
897 /* Reset the vertex attrib binding */
898 _mesa_vertex_attrib_binding(ctx
, vao
, attrib
, attrib
);
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
;
905 vao
->NewArrays
|= vao
->Enabled
& VERT_BIT(attrib
);
908 /* Update the vertex buffer binding */
909 GLsizei effectiveStride
= stride
!= 0 ?
910 stride
: array
->Format
._ElementSize
;
911 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
913 effectiveStride
, false);
917 /* Helper function for all EXT_direct_state_access glVertexArray* functions */
919 _lookup_vao_and_vbo_dsa(struct gl_context
*ctx
,
920 GLuint vaobj
, GLuint buffer
,
922 struct gl_vertex_array_object
** vao
,
923 struct gl_buffer_object
** vbo
,
926 *vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, caller
);
931 *vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
932 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, vbo
, caller
))
936 _mesa_error(ctx
, GL_INVALID_VALUE
,
937 "%s(negative offset with non-0 buffer)", caller
);
949 _mesa_VertexPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
952 GET_CURRENT_CONTEXT(ctx
);
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
);
961 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
963 GET_CURRENT_CONTEXT(ctx
);
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
);
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
,
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
);
987 _mesa_VertexArrayVertexOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
988 GLenum type
, GLsizei stride
, GLintptr offset
)
990 GET_CURRENT_CONTEXT(ctx
);
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
);
1000 struct gl_vertex_array_object
* vao
;
1001 struct gl_buffer_object
* vbo
;
1003 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1005 "glVertexArrayVertexOffsetEXT"))
1008 if (!validate_array_and_format(ctx
, "glVertexArrayVertexOffsetEXT",
1010 VERT_ATTRIB_POS
, legalTypes
, 2, 4, size
,
1011 type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
1012 format
, (void*) offset
))
1015 update_array(ctx
, vao
, vbo
,
1016 VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
1017 GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1022 _mesa_NormalPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1024 GET_CURRENT_CONTEXT(ctx
);
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
);
1033 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1035 GET_CURRENT_CONTEXT(ctx
);
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
);
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
))
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
);
1059 _mesa_VertexArrayNormalOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1060 GLsizei stride
, GLintptr offset
)
1062 GET_CURRENT_CONTEXT(ctx
);
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
);
1072 struct gl_vertex_array_object
* vao
;
1073 struct gl_buffer_object
* vbo
;
1075 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1080 if (!validate_array_and_format(ctx
, "glNormalPointer",
1082 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
1083 type
, stride
, GL_TRUE
, GL_FALSE
,
1084 GL_FALSE
, format
, (void*) offset
))
1087 update_array(ctx
, vao
, vbo
,
1088 VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
1089 GL_FALSE
, GL_FALSE
, (void*) offset
);
1094 _mesa_ColorPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
1097 GET_CURRENT_CONTEXT(ctx
);
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
);
1107 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1109 GET_CURRENT_CONTEXT(ctx
);
1110 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
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
);
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
))
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
);
1136 _mesa_VertexArrayColorOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1137 GLenum type
, GLsizei stride
, GLintptr offset
)
1139 GET_CURRENT_CONTEXT(ctx
);
1140 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
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
);
1152 struct gl_vertex_array_object
* vao
;
1153 struct gl_buffer_object
* vbo
;
1155 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1157 "glVertexArrayColorOffsetEXT"))
1160 if (!validate_array_and_format(ctx
, "glVertexArrayColorOffsetEXT",
1162 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
1163 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
1164 GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
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
);
1174 _mesa_FogCoordPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1176 GET_CURRENT_CONTEXT(ctx
);
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
);
1185 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1187 GET_CURRENT_CONTEXT(ctx
);
1189 GLenum format
= GL_RGBA
;
1190 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
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
))
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
);
1206 _mesa_VertexArrayFogCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1207 GLsizei stride
, GLintptr offset
)
1209 GET_CURRENT_CONTEXT(ctx
);
1211 GLenum format
= GL_RGBA
;
1212 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
1214 struct gl_vertex_array_object
* vao
;
1215 struct gl_buffer_object
* vbo
;
1217 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1219 "glVertexArrayFogCoordOffsetEXT"))
1222 if (!validate_array_and_format(ctx
, "glVertexArrayFogCoordOffsetEXT",
1224 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
1225 type
, stride
, GL_FALSE
, GL_FALSE
,
1226 GL_FALSE
, format
, (void*) offset
))
1229 update_array(ctx
, vao
, vbo
,
1230 VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
1231 GL_FALSE
, GL_FALSE
, (void*) offset
);
1236 _mesa_IndexPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1238 GET_CURRENT_CONTEXT(ctx
);
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
);
1247 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1249 GET_CURRENT_CONTEXT(ctx
);
1251 GLenum format
= GL_RGBA
;
1252 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1253 FLOAT_BIT
| DOUBLE_BIT
);
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
))
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
);
1269 _mesa_VertexArrayIndexOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1270 GLsizei stride
, GLintptr offset
)
1272 GET_CURRENT_CONTEXT(ctx
);
1274 GLenum format
= GL_RGBA
;
1275 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1276 FLOAT_BIT
| DOUBLE_BIT
);
1278 struct gl_vertex_array_object
* vao
;
1279 struct gl_buffer_object
* vbo
;
1281 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1283 "glVertexArrayIndexOffsetEXT"))
1286 if (!validate_array_and_format(ctx
, "glVertexArrayIndexOffsetEXT",
1288 VERT_ATTRIB_COLOR_INDEX
,
1289 legalTypes
, 1, 1, 1, type
, stride
,
1290 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
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
);
1300 _mesa_SecondaryColorPointer_no_error(GLint size
, GLenum type
,
1301 GLsizei stride
, const GLvoid
*ptr
)
1303 GET_CURRENT_CONTEXT(ctx
);
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
);
1313 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
1314 GLsizei stride
, const GLvoid
*ptr
)
1316 GET_CURRENT_CONTEXT(ctx
);
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
);
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
))
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
);
1340 _mesa_VertexArraySecondaryColorOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1341 GLenum type
, GLsizei stride
, GLintptr offset
)
1343 GET_CURRENT_CONTEXT(ctx
);
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
);
1353 struct gl_vertex_array_object
* vao
;
1354 struct gl_buffer_object
* vbo
;
1356 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1358 "glVertexArraySecondaryColorOffsetEXT"))
1361 if (!validate_array_and_format(ctx
, "glVertexArraySecondaryColorOffsetEXT",
1363 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
1364 BGRA_OR_4
, size
, type
, stride
,
1365 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
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
);
1375 _mesa_TexCoordPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
1378 GET_CURRENT_CONTEXT(ctx
);
1379 const GLuint unit
= ctx
->Array
.ActiveTexture
;
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
);
1388 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
1391 GET_CURRENT_CONTEXT(ctx
);
1392 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1393 const GLuint unit
= ctx
->Array
.ActiveTexture
;
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
);
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
))
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
);
1417 _mesa_VertexArrayTexCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1418 GLenum type
, GLsizei stride
, GLintptr offset
)
1420 GET_CURRENT_CONTEXT(ctx
);
1421 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1422 const GLuint unit
= ctx
->Array
.ActiveTexture
;
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
);
1432 struct gl_vertex_array_object
* vao
;
1433 struct gl_buffer_object
* vbo
;
1435 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1437 "glVertexArrayTexCoordOffsetEXT"))
1440 if (!validate_array_and_format(ctx
, "glVertexArrayTexCoordOffsetEXT",
1442 VERT_ATTRIB_TEX(unit
), legalTypes
,
1443 sizeMin
, 4, size
, type
, stride
,
1444 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
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
);
1454 _mesa_VertexArrayMultiTexCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum texunit
,
1455 GLint size
, GLenum type
, GLsizei stride
,
1458 GET_CURRENT_CONTEXT(ctx
);
1459 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1460 const GLuint unit
= texunit
- GL_TEXTURE0
;
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
);
1470 struct gl_vertex_array_object
* vao
;
1471 struct gl_buffer_object
* vbo
;
1473 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1475 "glVertexArrayMultiTexCoordOffsetEXT"))
1478 if (unit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1479 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexArrayMultiTexCoordOffsetEXT(texunit=%d)",
1484 if (!validate_array_and_format(ctx
, "glVertexArrayMultiTexCoordOffsetEXT",
1486 VERT_ATTRIB_TEX(unit
), legalTypes
,
1487 sizeMin
, 4, size
, type
, stride
,
1488 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
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
);
1498 _mesa_EdgeFlagPointer_no_error(GLsizei stride
, const GLvoid
*ptr
)
1500 /* this is the same type that glEdgeFlag uses */
1501 const GLboolean integer
= GL_FALSE
;
1502 GET_CURRENT_CONTEXT(ctx
);
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
);
1511 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
1513 /* this is the same type that glEdgeFlag uses */
1514 const GLboolean integer
= GL_FALSE
;
1515 GET_CURRENT_CONTEXT(ctx
);
1517 GLenum format
= GL_RGBA
;
1518 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
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
))
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
);
1534 _mesa_VertexArrayEdgeFlagOffsetEXT(GLuint vaobj
, GLuint buffer
, GLsizei stride
,
1537 /* this is the same type that glEdgeFlag uses */
1538 const GLboolean integer
= GL_FALSE
;
1539 GET_CURRENT_CONTEXT(ctx
);
1541 GLenum format
= GL_RGBA
;
1542 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
1544 struct gl_vertex_array_object
* vao
;
1545 struct gl_buffer_object
* vbo
;
1547 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1549 "glVertexArrayEdgeFlagOffsetEXT"))
1552 if (!validate_array_and_format(ctx
, "glVertexArrayEdgeFlagOffsetEXT",
1554 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
1555 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
1556 GL_FALSE
, integer
, GL_FALSE
, format
, (void*) offset
))
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
);
1566 _mesa_PointSizePointerOES_no_error(GLenum type
, GLsizei stride
,
1569 GET_CURRENT_CONTEXT(ctx
);
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
);
1578 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1580 GET_CURRENT_CONTEXT(ctx
);
1582 GLenum format
= GL_RGBA
;
1583 if (ctx
->API
!= API_OPENGLES
) {
1584 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1585 "glPointSizePointer(ES 1.x only)");
1589 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
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
))
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
);
1605 _mesa_VertexAttribPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1606 GLboolean normalized
,
1607 GLsizei stride
, const GLvoid
*ptr
)
1609 GET_CURRENT_CONTEXT(ctx
);
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
);
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).
1624 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
1625 GLboolean normalized
,
1626 GLsizei stride
, const GLvoid
*ptr
)
1628 GET_CURRENT_CONTEXT(ctx
);
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)");
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
);
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
))
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
);
1659 _mesa_VertexArrayVertexAttribOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1660 GLenum type
, GLboolean normalized
,
1661 GLsizei stride
, GLintptr offset
)
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
;
1668 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1670 "glVertexArrayVertexAttribOffsetEXT"))
1673 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1674 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribOffsetEXT(idx)");
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
);
1687 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribOffsetEXT",
1689 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1690 1, BGRA_OR_4
, size
, type
, stride
,
1691 normalized
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
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
);
1701 _mesa_VertexArrayVertexAttribLOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1702 GLenum type
, GLsizei stride
, GLintptr offset
)
1704 GET_CURRENT_CONTEXT(ctx
);
1705 GLenum format
= GL_RGBA
;
1706 struct gl_vertex_array_object
* vao
;
1707 struct gl_buffer_object
* vbo
;
1709 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1711 "glVertexArrayVertexAttribLOffsetEXT"))
1714 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1715 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribLOffsetEXT(idx)");
1719 const GLbitfield legalTypes
= DOUBLE_BIT
;
1721 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribLOffsetEXT",
1723 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1724 1, 4, size
, type
, stride
,
1725 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
, (void*) offset
))
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
);
1735 _mesa_VertexAttribIPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1736 GLsizei stride
, const GLvoid
*ptr
)
1738 const GLboolean normalized
= GL_FALSE
;
1739 const GLboolean integer
= GL_TRUE
;
1740 GET_CURRENT_CONTEXT(ctx
);
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
);
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).
1755 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
1756 GLsizei stride
, const GLvoid
*ptr
)
1758 const GLboolean normalized
= GL_FALSE
;
1759 const GLboolean integer
= GL_TRUE
;
1760 GET_CURRENT_CONTEXT(ctx
);
1762 GLenum format
= GL_RGBA
;
1763 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1764 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
1768 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1769 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1770 INT_BIT
| UNSIGNED_INT_BIT
);
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
))
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
);
1786 _mesa_VertexAttribLPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1787 GLsizei stride
, const GLvoid
*ptr
)
1789 GET_CURRENT_CONTEXT(ctx
);
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
);
1798 _mesa_VertexArrayVertexAttribIOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1799 GLenum type
, GLsizei stride
, GLintptr offset
)
1801 const GLboolean normalized
= GL_FALSE
;
1802 const GLboolean integer
= GL_TRUE
;
1803 GET_CURRENT_CONTEXT(ctx
);
1804 GLenum format
= GL_RGBA
;
1806 struct gl_vertex_array_object
* vao
;
1807 struct gl_buffer_object
* vbo
;
1809 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1811 "glVertexArrayVertexAttribIOffsetEXT"))
1814 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1815 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribIOffsetEXT(index)");
1819 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1820 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1821 INT_BIT
| UNSIGNED_INT_BIT
);
1823 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribIOffsetEXT",
1825 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1826 1, 4, size
, type
, stride
,
1827 normalized
, integer
, GL_FALSE
, format
, (void*) offset
))
1830 update_array(ctx
, vao
, vbo
,
1831 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1832 stride
, normalized
, integer
, GL_FALSE
, (void*) offset
);
1837 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
1838 GLsizei stride
, const GLvoid
*ptr
)
1840 GET_CURRENT_CONTEXT(ctx
);
1842 GLenum format
= GL_RGBA
;
1843 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1844 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
1848 const GLbitfield legalTypes
= DOUBLE_BIT
;
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
))
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
);
1864 _mesa_enable_vertex_array_attribs(struct gl_context
*ctx
,
1865 struct gl_vertex_array_object
*vao
,
1866 GLbitfield attrib_bits
)
1868 assert((attrib_bits
& ~VERT_BIT_ALL
) == 0);
1869 assert(!vao
->SharedAndImmutable
);
1871 /* Only work on bits that are disabled */
1872 attrib_bits
&= ~vao
->Enabled
;
1874 /* was disabled, now being enabled */
1875 vao
->Enabled
|= attrib_bits
;
1876 vao
->NewArrays
|= attrib_bits
;
1878 /* Update the map mode if needed */
1879 if (attrib_bits
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1880 update_attribute_map_mode(ctx
, vao
);
1885 enable_vertex_array_attrib(struct gl_context
*ctx
,
1886 struct gl_vertex_array_object
*vao
,
1890 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1891 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
1895 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1900 _mesa_EnableVertexAttribArray(GLuint index
)
1902 GET_CURRENT_CONTEXT(ctx
);
1903 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
1904 "glEnableVertexAttribArray");
1909 _mesa_EnableVertexAttribArray_no_error(GLuint index
)
1911 GET_CURRENT_CONTEXT(ctx
);
1912 _mesa_enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1913 VERT_ATTRIB_GENERIC(index
));
1918 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1920 GET_CURRENT_CONTEXT(ctx
);
1921 struct gl_vertex_array_object
*vao
;
1923 /* The ARB_direct_state_access specification says:
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
1930 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glEnableVertexArrayAttrib");
1934 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
1938 _mesa_EnableVertexArrayAttribEXT(GLuint vaobj
, GLuint index
)
1940 GET_CURRENT_CONTEXT(ctx
);
1941 struct gl_vertex_array_object
* vao
= _mesa_lookup_vao_err(ctx
, vaobj
,
1943 "glEnableVertexArrayAttribEXT");
1947 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttribEXT");
1952 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
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
));
1961 _mesa_disable_vertex_array_attribs(struct gl_context
*ctx
,
1962 struct gl_vertex_array_object
*vao
,
1963 GLbitfield attrib_bits
)
1965 assert((attrib_bits
& ~VERT_BIT_ALL
) == 0);
1966 assert(!vao
->SharedAndImmutable
);
1968 /* Only work on bits that are enabled */
1969 attrib_bits
&= vao
->Enabled
;
1971 /* was enabled, now being disabled */
1972 vao
->Enabled
&= ~attrib_bits
;
1973 vao
->NewArrays
|= attrib_bits
;
1975 /* Update the map mode if needed */
1976 if (attrib_bits
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1977 update_attribute_map_mode(ctx
, vao
);
1983 _mesa_DisableVertexAttribArray(GLuint index
)
1985 GET_CURRENT_CONTEXT(ctx
);
1987 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1988 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexAttribArray(index)");
1992 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1993 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
1998 _mesa_DisableVertexAttribArray_no_error(GLuint index
)
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
);
2007 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
2009 GET_CURRENT_CONTEXT(ctx
);
2010 struct gl_vertex_array_object
*vao
;
2012 /* The ARB_direct_state_access specification says:
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
2019 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glDisableVertexArrayAttrib");
2023 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2024 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
2028 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2029 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
2033 _mesa_DisableVertexArrayAttribEXT(GLuint vaobj
, GLuint index
)
2035 GET_CURRENT_CONTEXT(ctx
);
2036 struct gl_vertex_array_object
* vao
= _mesa_lookup_vao_err(ctx
, vaobj
,
2038 "glEnableVertexArrayAttribEXT");
2042 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2043 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
2047 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2048 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
2053 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
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
);
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.
2068 get_vertex_array_attrib(struct gl_context
*ctx
,
2069 const struct gl_vertex_array_object
*vao
,
2070 GLuint index
, GLenum pname
,
2073 const struct gl_array_attributes
*array
;
2074 struct gl_buffer_object
*buf
;
2076 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2077 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
2081 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
2083 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
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
;
2106 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
2107 if (_mesa_is_desktop_gl(ctx
)) {
2108 return array
->Format
.Doubles
;
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
;
2117 case GL_VERTEX_ATTRIB_BINDING
:
2118 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
2119 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
2122 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
2123 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
2124 return array
->RelativeOffset
;
2128 ; /* fall-through */
2132 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
2137 static const GLfloat
*
2138 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
2141 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
2142 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
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
);
2152 assert(VERT_ATTRIB_GENERIC(index
) <
2153 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
2155 FLUSH_CURRENT(ctx
, 0);
2156 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
2160 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
2162 GET_CURRENT_CONTEXT(ctx
);
2164 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2165 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
2171 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2173 "glGetVertexAttribfv");
2179 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
2181 GET_CURRENT_CONTEXT(ctx
);
2183 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2184 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
2186 params
[0] = (GLdouble
) v
[0];
2187 params
[1] = (GLdouble
) v
[1];
2188 params
[2] = (GLdouble
) v
[2];
2189 params
[3] = (GLdouble
) v
[3];
2193 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2195 "glGetVertexAttribdv");
2200 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
2202 GET_CURRENT_CONTEXT(ctx
);
2204 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2206 (const GLdouble
*)get_current_attrib(ctx
, index
,
2207 "glGetVertexAttribLdv");
2216 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2218 "glGetVertexAttribLdv");
2223 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
2225 GET_CURRENT_CONTEXT(ctx
);
2227 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2228 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
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];
2238 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2240 "glGetVertexAttribiv");
2245 _mesa_GetVertexAttribLui64vARB(GLuint index
, GLenum pname
, GLuint64EXT
*params
)
2247 GET_CURRENT_CONTEXT(ctx
);
2249 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2251 (const GLuint64
*)get_current_attrib(ctx
, index
,
2252 "glGetVertexAttribLui64vARB");
2261 params
[0] = (GLuint64
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2263 "glGetVertexAttribLui64vARB");
2270 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
2272 GET_CURRENT_CONTEXT(ctx
);
2274 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2275 const GLint
*v
= (const GLint
*)
2276 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
2282 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2284 "glGetVertexAttribIiv");
2291 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
2293 GET_CURRENT_CONTEXT(ctx
);
2295 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2296 const GLuint
*v
= (const GLuint
*)
2297 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
2303 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2305 "glGetVertexAttribIuiv");
2311 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
2313 GET_CURRENT_CONTEXT(ctx
);
2315 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2316 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
2320 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
2321 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
2325 assert(VERT_ATTRIB_GENERIC(index
) <
2326 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
2328 *pointer
= (GLvoid
*)
2329 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
2333 /** ARB_direct_state_access */
2335 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
2336 GLenum pname
, GLint
*params
)
2338 GET_CURRENT_CONTEXT(ctx
);
2339 struct gl_vertex_array_object
*vao
;
2340 struct gl_buffer_object
*buf
;
2342 /* The ARB_direct_state_access specification says:
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."
2348 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glGetVertexArrayIndexediv");
2352 /* The ARB_direct_state_access specification says:
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."
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"
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
2378 case GL_VERTEX_BINDING_OFFSET
:
2379 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2381 case GL_VERTEX_BINDING_STRIDE
:
2382 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
2384 case GL_VERTEX_BINDING_DIVISOR
:
2385 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
2387 case GL_VERTEX_BINDING_BUFFER
:
2388 buf
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
;
2389 params
[0] = buf
? buf
->Name
: 0;
2392 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
2393 "glGetVertexArrayIndexediv");
2400 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
2401 GLenum pname
, GLint64
*params
)
2403 GET_CURRENT_CONTEXT(ctx
);
2404 struct gl_vertex_array_object
*vao
;
2406 /* The ARB_direct_state_access specification says:
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."
2412 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glGetVertexArrayIndexed64iv");
2416 /* The ARB_direct_state_access specification says:
2418 * "For GetVertexArrayIndexed64iv, <pname> must be
2419 * VERTEX_BINDING_OFFSET."
2423 * "An INVALID_ENUM error is generated if <pname> is not one of
2424 * the valid values listed above for the corresponding command."
2426 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
2427 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
2428 "pname != GL_VERTEX_BINDING_OFFSET)");
2432 /* The ARB_direct_state_access specification says:
2434 * "An INVALID_VALUE error is generated if <index> is greater than
2435 * or equal to the value of MAX_VERTEX_ATTRIBS."
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.
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
);
2448 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2453 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
2454 GLsizei count
, const GLvoid
*ptr
)
2457 _mesa_VertexPointer(size
, type
, stride
, ptr
);
2462 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
2466 _mesa_NormalPointer(type
, stride
, ptr
);
2471 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
2475 _mesa_ColorPointer(size
, type
, stride
, ptr
);
2480 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
2484 _mesa_IndexPointer(type
, stride
, ptr
);
2489 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
2490 GLsizei count
, const GLvoid
*ptr
)
2493 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
2498 _mesa_MultiTexCoordPointerEXT(GLenum texunit
, GLint size
, GLenum type
,
2499 GLsizei stride
, const GLvoid
*ptr
)
2501 GET_CURRENT_CONTEXT(ctx
);
2502 const GLint sizeMin
= 1;
2503 const GLuint unit
= texunit
- GL_TEXTURE0
;
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
);
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
))
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
);
2525 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
2528 _mesa_EdgeFlagPointer(stride
, ptr
);
2533 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
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 */
2544 f
= sizeof(GLfloat
);
2545 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
2548 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
2554 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2555 tcomps
= 0; ccomps
= 0; vcomps
= 2;
2560 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2561 tcomps
= 0; ccomps
= 0; vcomps
= 3;
2566 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2567 tcomps
= 0; ccomps
= 4; vcomps
= 2;
2568 ctype
= GL_UNSIGNED_BYTE
;
2571 defstride
= c
+ 2*f
;
2574 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2575 tcomps
= 0; ccomps
= 4; vcomps
= 3;
2576 ctype
= GL_UNSIGNED_BYTE
;
2579 defstride
= c
+ 3*f
;
2582 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2583 tcomps
= 0; ccomps
= 3; vcomps
= 3;
2590 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
2591 tcomps
= 0; ccomps
= 0; vcomps
= 3;
2596 case GL_C4F_N3F_V3F
:
2597 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2598 tcomps
= 0; ccomps
= 4; vcomps
= 3;
2606 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2607 tcomps
= 2; ccomps
= 0; vcomps
= 3;
2612 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2613 tcomps
= 4; ccomps
= 0; vcomps
= 4;
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
;
2625 case GL_T2F_C3F_V3F
:
2626 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2627 tcomps
= 2; ccomps
= 3; vcomps
= 3;
2633 case GL_T2F_N3F_V3F
:
2634 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
2635 tcomps
= 2; ccomps
= 0; vcomps
= 3;
2640 case GL_T2F_C4F_N3F_V3F
:
2641 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2642 tcomps
= 2; ccomps
= 4; vcomps
= 3;
2649 case GL_T4F_C4F_N3F_V4F
:
2650 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2651 tcomps
= 4; ccomps
= 4; vcomps
= 4;
2659 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
2667 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
2668 _mesa_DisableClientState( GL_INDEX_ARRAY
);
2669 /* XXX also disable secondary color and generic arrays? */
2673 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
2674 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
2675 (GLubyte
*) pointer
+ toffset
);
2678 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
2683 _mesa_EnableClientState( GL_COLOR_ARRAY
);
2684 _mesa_ColorPointer( ccomps
, ctype
, stride
,
2685 (GLubyte
*) pointer
+ coffset
);
2688 _mesa_DisableClientState( GL_COLOR_ARRAY
);
2694 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
2695 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
2698 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
2702 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
2703 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
2704 (GLubyte
*) pointer
+ voffset
);
2709 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
2711 GET_CURRENT_CONTEXT(ctx
);
2713 if (MESA_VERBOSE
& VERBOSE_API
)
2714 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
2717 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
2721 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
2724 if (ctx
->Array
.LockCount
!= 0) {
2725 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
2729 ctx
->Array
.LockFirst
= first
;
2730 ctx
->Array
.LockCount
= count
;
2735 _mesa_UnlockArraysEXT( void )
2737 GET_CURRENT_CONTEXT(ctx
);
2739 if (MESA_VERBOSE
& VERBOSE_API
)
2740 _mesa_debug(ctx
, "glUnlockArrays\n");
2742 if (ctx
->Array
.LockCount
== 0) {
2743 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
2747 ctx
->Array
.LockFirst
= 0;
2748 ctx
->Array
.LockCount
= 0;
2753 primitive_restart_index(struct gl_context
*ctx
, GLuint index
)
2755 ctx
->Array
.RestartIndex
= index
;
2756 _mesa_update_derived_primitive_restart_state(ctx
);
2761 * GL_NV_primitive_restart and GL 3.1
2764 _mesa_PrimitiveRestartIndex_no_error(GLuint index
)
2766 GET_CURRENT_CONTEXT(ctx
);
2767 primitive_restart_index(ctx
, index
);
2772 _mesa_PrimitiveRestartIndex(GLuint index
)
2774 GET_CURRENT_CONTEXT(ctx
);
2776 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
2777 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
2781 primitive_restart_index(ctx
, index
);
2786 _mesa_VertexAttribDivisor_no_error(GLuint index
, GLuint divisor
)
2788 GET_CURRENT_CONTEXT(ctx
);
2790 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2791 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2793 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2795 /* The ARB_vertex_attrib_binding spec says:
2799 * void VertexAttribDivisor(uint index, uint divisor);
2801 * is equivalent to (assuming no errors are generated):
2803 * VertexAttribBinding(index, index);
2804 * VertexBindingDivisor(index, divisor);"
2806 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2807 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2812 * See GL_ARB_instanced_arrays.
2813 * Note that the instance divisor only applies to generic arrays, not
2814 * the legacy vertex arrays.
2817 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
2819 GET_CURRENT_CONTEXT(ctx
);
2821 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2822 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2824 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2825 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
2829 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2830 _mesa_error(ctx
, GL_INVALID_VALUE
,
2831 "glVertexAttribDivisor(index = %u)", index
);
2835 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2837 /* The ARB_vertex_attrib_binding spec says:
2841 * void VertexAttribDivisor(uint index, uint divisor);
2843 * is equivalent to (assuming no errors are generated):
2845 * VertexAttribBinding(index, index);
2846 * VertexBindingDivisor(index, divisor);"
2848 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2849 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2854 _mesa_VertexArrayVertexAttribDivisorEXT(GLuint vaobj
, GLuint index
, GLuint divisor
)
2856 GET_CURRENT_CONTEXT(ctx
);
2858 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2859 struct gl_vertex_array_object
* vao
;
2860 /* The ARB_instanced_arrays spec says:
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."
2866 vao
= _mesa_lookup_vao_err(ctx
, vaobj
,
2868 "glVertexArrayVertexAttribDivisorEXT");
2872 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2873 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexArrayVertexAttribDivisorEXT()");
2877 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2878 _mesa_error(ctx
, GL_INVALID_VALUE
,
2879 "glVertexArrayVertexAttribDivisorEXT(index = %u)", index
);
2883 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2885 /* The ARB_vertex_attrib_binding spec says:
2889 * void VertexAttribDivisor(uint index, uint divisor);
2891 * is equivalent to (assuming no errors are generated):
2893 * VertexAttribBinding(index, index);
2894 * VertexBindingDivisor(index, divisor);"
2896 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2897 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
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
)
2908 struct gl_buffer_object
*vbo
;
2909 struct gl_buffer_object
*current_buf
=
2910 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
2912 if (current_buf
&& buffer
== current_buf
->Name
) {
2914 } else if (buffer
!= 0) {
2915 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
2917 if (!no_error
&& !vbo
&& _mesa_is_gles31(ctx
)) {
2918 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
2921 /* From the GL_ARB_vertex_attrib_array spec:
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.
2928 * Otherwise, we fall back to the same compat profile behavior as other
2929 * object references (automatically gen it).
2931 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
2934 /* The ARB_vertex_attrib_binding spec says:
2936 * "If <buffer> is zero, any buffer object attached to this
2937 * bindpoint is detached."
2942 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
2943 vbo
, offset
, stride
, false);
2948 * GL_ARB_vertex_attrib_binding
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
,
2957 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2959 /* The ARB_vertex_attrib_binding spec says:
2961 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2962 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
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
);
2972 /* The ARB_vertex_attrib_binding spec says:
2974 * "The error INVALID_VALUE is generated if <stride> or <offset>
2978 _mesa_error(ctx
, GL_INVALID_VALUE
,
2979 "%s(offset=%" PRId64
" < 0)",
2980 func
, (int64_t) offset
);
2985 _mesa_error(ctx
, GL_INVALID_VALUE
,
2986 "%s(stride=%d < 0)", func
, stride
);
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
);
2997 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2998 stride
, false, func
);
3003 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex
, GLuint buffer
,
3004 GLintptr offset
, GLsizei stride
)
3006 GET_CURRENT_CONTEXT(ctx
);
3007 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
3008 buffer
, offset
, stride
, true,
3009 "glBindVertexBuffer");
3014 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
3017 GET_CURRENT_CONTEXT(ctx
);
3019 /* The ARB_vertex_attrib_binding spec says:
3021 * "An INVALID_OPERATION error is generated if no vertex array object
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)");
3031 vertex_array_vertex_buffer_err(ctx
, ctx
->Array
.VAO
, bindingIndex
,
3032 buffer
, offset
, stride
,
3033 "glBindVertexBuffer");
3038 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj
, GLuint bindingIndex
,
3039 GLuint buffer
, GLintptr offset
,
3042 GET_CURRENT_CONTEXT(ctx
);
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");
3051 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
3052 GLintptr offset
, GLsizei stride
)
3054 GET_CURRENT_CONTEXT(ctx
);
3055 struct gl_vertex_array_object
*vao
;
3057 /* The ARB_direct_state_access specification says:
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."
3063 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayVertexBuffer");
3067 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
3068 stride
, "glVertexArrayVertexBuffer");
3073 _mesa_VertexArrayBindVertexBufferEXT(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
3074 GLintptr offset
, GLsizei stride
)
3076 GET_CURRENT_CONTEXT(ctx
);
3077 struct gl_vertex_array_object
*vao
;
3078 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, "glVertexArrayBindVertexBufferEXT");
3082 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
3083 stride
, "glVertexArrayBindVertexBufferEXT");
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
)
3098 * The ARB_multi_bind spec says:
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>."
3106 for (i
= 0; i
< count
; i
++)
3107 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
3108 NULL
, 0, 16, false);
3113 /* Note that the error semantics for multi-bind commands differ from
3114 * those of other GL commands.
3116 * The Issues section in the ARB_multi_bind spec says:
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?
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."
3132 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
3134 for (i
= 0; i
< count
; i
++) {
3135 struct gl_buffer_object
*vbo
;
3138 /* The ARB_multi_bind spec says:
3140 * "An INVALID_VALUE error is generated if any value in
3141 * <offsets> or <strides> is negative (per binding)."
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
]);
3150 if (strides
[i
] < 0) {
3151 _mesa_error(ctx
, GL_INVALID_VALUE
,
3152 "%s(strides[%u]=%d < 0)",
3153 func
, i
, strides
[i
]);
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
]);
3167 struct gl_vertex_buffer_binding
*binding
=
3168 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
3170 if (buffers
[i
] == 0)
3172 else if (binding
->BufferObj
&& binding
->BufferObj
->Name
== buffers
[i
])
3173 vbo
= binding
->BufferObj
;
3176 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
,
3185 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
3186 vbo
, offsets
[i
], strides
[i
], false);
3189 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
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
)
3200 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3202 /* The ARB_multi_bind spec says:
3204 * "An INVALID_OPERATION error is generated if <first> + <count>
3205 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
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
);
3215 vertex_array_vertex_buffers(ctx
, vao
, first
, count
, buffers
, offsets
,
3216 strides
, false, func
);
3221 _mesa_BindVertexBuffers_no_error(GLuint first
, GLsizei count
,
3222 const GLuint
*buffers
, const GLintptr
*offsets
,
3223 const GLsizei
*strides
)
3225 GET_CURRENT_CONTEXT(ctx
);
3227 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
3228 buffers
, offsets
, strides
, true,
3229 "glBindVertexBuffers");
3234 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
3235 const GLintptr
*offsets
, const GLsizei
*strides
)
3237 GET_CURRENT_CONTEXT(ctx
);
3239 /* The ARB_vertex_attrib_binding spec says:
3241 * "An INVALID_OPERATION error is generated if no
3242 * vertex array object is bound."
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)");
3251 vertex_array_vertex_buffers_err(ctx
, ctx
->Array
.VAO
, first
, count
,
3252 buffers
, offsets
, strides
,
3253 "glBindVertexBuffers");
3258 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj
, GLuint first
,
3259 GLsizei count
, const GLuint
*buffers
,
3260 const GLintptr
*offsets
,
3261 const GLsizei
*strides
)
3263 GET_CURRENT_CONTEXT(ctx
);
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");
3273 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
3274 const GLuint
*buffers
,
3275 const GLintptr
*offsets
, const GLsizei
*strides
)
3277 GET_CURRENT_CONTEXT(ctx
);
3278 struct gl_vertex_array_object
*vao
;
3280 /* The ARB_direct_state_access specification says:
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."
3286 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayVertexBuffers");
3290 vertex_array_vertex_buffers_err(ctx
, vao
, first
, count
,
3291 buffers
, offsets
, strides
,
3292 "glVertexArrayVertexBuffers");
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
,
3303 GET_CURRENT_CONTEXT(ctx
);
3304 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3306 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
3308 if (!_mesa_is_no_error_enabled(ctx
)) {
3309 /* The ARB_vertex_attrib_binding spec says:
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
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.
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
);
3329 /* The ARB_vertex_attrib_binding spec says:
3331 * "The error INVALID_VALUE is generated if index is greater than or
3332 * equal to the value of MAX_VERTEX_ATTRIBS."
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)",
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
,
3351 _mesa_update_array_format(ctx
, ctx
->Array
.VAO
,
3352 VERT_ATTRIB_GENERIC(attribIndex
), size
, type
,
3353 format
, normalized
, integer
, doubles
,
3359 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3360 GLboolean normalized
, GLuint relativeOffset
)
3362 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
3363 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
3364 BGRA_OR_4
, relativeOffset
,
3365 "glVertexAttribFormat");
3370 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3371 GLuint relativeOffset
)
3373 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
3374 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
3375 relativeOffset
, "glVertexAttribIFormat");
3380 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3381 GLuint relativeOffset
)
3383 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
3384 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
3385 relativeOffset
, "glVertexAttribLFormat");
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
)
3396 GET_CURRENT_CONTEXT(ctx
);
3397 struct gl_vertex_array_object
*vao
;
3399 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3401 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
3403 if (_mesa_is_no_error_enabled(ctx
)) {
3404 vao
= _mesa_lookup_vao(ctx
, vaobj
);
3408 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, isExtDsa
, func
);
3412 /* The ARB_vertex_attrib_binding spec says:
3414 * "The error INVALID_VALUE is generated if index is greater than or
3415 * equal to the value of MAX_VERTEX_ATTRIBS."
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)",
3424 if (!validate_array_format(ctx
, func
, vao
,
3425 VERT_ATTRIB_GENERIC(attribIndex
),
3426 legalTypes
, 1, sizeMax
, size
, type
,
3427 normalized
, integer
, doubles
, relativeOffset
,
3433 _mesa_update_array_format(ctx
, vao
, VERT_ATTRIB_GENERIC(attribIndex
), size
,
3434 type
, format
, normalized
, integer
, doubles
,
3440 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
3441 GLenum type
, GLboolean normalized
,
3442 GLuint relativeOffset
)
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");
3452 _mesa_VertexArrayVertexAttribFormatEXT(GLuint vaobj
, GLuint attribIndex
, GLint size
,
3453 GLenum type
, GLboolean normalized
,
3454 GLuint relativeOffset
)
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");
3464 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
3465 GLint size
, GLenum type
,
3466 GLuint relativeOffset
)
3468 vertex_array_attrib_format(vaobj
, false, attribIndex
, size
, type
, GL_FALSE
,
3469 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
3471 "glVertexArrayAttribIFormat");
3476 _mesa_VertexArrayVertexAttribIFormatEXT(GLuint vaobj
, GLuint attribIndex
,
3477 GLint size
, GLenum type
,
3478 GLuint relativeOffset
)
3480 vertex_array_attrib_format(vaobj
, true, attribIndex
, size
, type
, GL_FALSE
,
3481 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
3483 "glVertexArrayVertexAttribIFormatEXT");
3488 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
3489 GLint size
, GLenum type
,
3490 GLuint relativeOffset
)
3492 vertex_array_attrib_format(vaobj
, false, attribIndex
, size
, type
, GL_FALSE
,
3493 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
3495 "glVertexArrayAttribLFormat");
3500 _mesa_VertexArrayVertexAttribLFormatEXT(GLuint vaobj
, GLuint attribIndex
,
3501 GLint size
, GLenum type
,
3502 GLuint relativeOffset
)
3504 vertex_array_attrib_format(vaobj
, true, attribIndex
, size
, type
, GL_FALSE
,
3505 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
3507 "glVertexArrayVertexAttribLFormatEXT");
3512 vertex_array_attrib_binding(struct gl_context
*ctx
,
3513 struct gl_vertex_array_object
*vao
,
3514 GLuint attribIndex
, GLuint bindingIndex
,
3517 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3519 /* The ARB_vertex_attrib_binding spec says:
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
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)",
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
);
3542 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
3544 _mesa_vertex_attrib_binding(ctx
, vao
,
3545 VERT_ATTRIB_GENERIC(attribIndex
),
3546 VERT_ATTRIB_GENERIC(bindingIndex
));
3551 _mesa_VertexAttribBinding_no_error(GLuint attribIndex
, GLuint bindingIndex
)
3553 GET_CURRENT_CONTEXT(ctx
);
3554 _mesa_vertex_attrib_binding(ctx
, ctx
->Array
.VAO
,
3555 VERT_ATTRIB_GENERIC(attribIndex
),
3556 VERT_ATTRIB_GENERIC(bindingIndex
));
3561 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
3563 GET_CURRENT_CONTEXT(ctx
);
3565 /* The ARB_vertex_attrib_binding spec says:
3567 * "An INVALID_OPERATION error is generated if no vertex array object
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)");
3577 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
3578 attribIndex
, bindingIndex
,
3579 "glVertexAttribBinding");
3584 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj
, GLuint attribIndex
,
3585 GLuint bindingIndex
)
3587 GET_CURRENT_CONTEXT(ctx
);
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
));
3597 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
3599 GET_CURRENT_CONTEXT(ctx
);
3600 struct gl_vertex_array_object
*vao
;
3602 /* The ARB_direct_state_access specification says:
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."
3608 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayAttribBinding");
3612 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
3613 "glVertexArrayAttribBinding");
3618 _mesa_VertexArrayVertexAttribBindingEXT(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
3620 GET_CURRENT_CONTEXT(ctx
);
3621 struct gl_vertex_array_object
*vao
;
3622 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, "glVertexArrayVertexAttribBindingEXT");
3626 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
3627 "glVertexArrayVertexAttribBindingEXT");
3632 vertex_array_binding_divisor(struct gl_context
*ctx
,
3633 struct gl_vertex_array_object
*vao
,
3634 GLuint bindingIndex
, GLuint divisor
,
3637 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3639 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
3640 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
3644 /* The ARB_vertex_attrib_binding spec says:
3646 * "An INVALID_VALUE error is generated if <bindingindex> is greater
3647 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
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
);
3657 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3662 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex
, GLuint divisor
)
3664 GET_CURRENT_CONTEXT(ctx
);
3665 vertex_binding_divisor(ctx
, ctx
->Array
.VAO
,
3666 VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3671 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
3673 GET_CURRENT_CONTEXT(ctx
);
3675 /* The ARB_vertex_attrib_binding spec says:
3677 * "An INVALID_OPERATION error is generated if no vertex array object
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)");
3687 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
3688 bindingIndex
, divisor
,
3689 "glVertexBindingDivisor");
3694 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj
, GLuint bindingIndex
,
3697 GET_CURRENT_CONTEXT(ctx
);
3699 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3700 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3705 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
3708 struct gl_vertex_array_object
*vao
;
3709 GET_CURRENT_CONTEXT(ctx
);
3711 /* The ARB_direct_state_access specification says:
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."
3717 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayBindingDivisor");
3721 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
3722 "glVertexArrayBindingDivisor");
3727 _mesa_VertexArrayVertexBindingDivisorEXT(GLuint vaobj
, GLuint bindingIndex
,
3730 struct gl_vertex_array_object
*vao
;
3731 GET_CURRENT_CONTEXT(ctx
);
3733 /* The ARB_direct_state_access specification says:
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."
3739 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, "glVertexArrayVertexBindingDivisorEXT");
3743 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
3744 "glVertexArrayVertexBindingDivisorEXT");
3749 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
3750 struct gl_array_attributes
*dst
,
3751 const struct gl_array_attributes
*src
)
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
;
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
)
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
;
3774 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
3778 * Print current vertex object/array info. For debug.
3781 _mesa_print_arrays(struct gl_context
*ctx
)
3783 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
3785 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
3787 GLbitfield mask
= vao
->Enabled
;
3789 const gl_vert_attrib i
= u_bit_scan(&mask
);
3790 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
3792 const struct gl_vertex_buffer_binding
*binding
=
3793 &vao
->BufferBinding
[array
->BufferBindingIndex
];
3794 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
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
),
3801 array
->Format
._ElementSize
, binding
->Stride
, bo
? bo
->Name
: 0,
3802 (unsigned long)(bo
? bo
->Size
: 0));
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).
3814 init_array(struct gl_context
*ctx
,
3815 struct gl_vertex_array_object
*vao
,
3816 gl_vert_attrib index
, GLint size
, GLint type
)
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
];
3823 _mesa_set_vertex_format(&array
->Format
, size
, type
, GL_RGBA
,
3824 GL_FALSE
, GL_FALSE
, GL_FALSE
);
3827 array
->RelativeOffset
= 0;
3828 ASSERT_BITFIELD_SIZE(struct gl_array_attributes
, BufferBindingIndex
,
3829 VERT_ATTRIB_MAX
- 1);
3830 array
->BufferBindingIndex
= index
;
3832 binding
->Offset
= 0;
3833 binding
->Stride
= array
->Format
._ElementSize
;
3834 binding
->BufferObj
= NULL
;
3835 binding
->_BoundArrays
= BITFIELD_BIT(index
);
3839 init_default_vao_state(struct gl_context
*ctx
)
3841 struct gl_vertex_array_object
*vao
= &ctx
->Array
.DefaultVAOState
;
3844 vao
->SharedAndImmutable
= false;
3846 /* Init the individual arrays */
3847 for (unsigned i
= 0; i
< ARRAY_SIZE(vao
->VertexAttrib
); i
++) {
3849 case VERT_ATTRIB_NORMAL
:
3850 init_array(ctx
, vao
, VERT_ATTRIB_NORMAL
, 3, GL_FLOAT
);
3852 case VERT_ATTRIB_COLOR1
:
3853 init_array(ctx
, vao
, VERT_ATTRIB_COLOR1
, 3, GL_FLOAT
);
3855 case VERT_ATTRIB_FOG
:
3856 init_array(ctx
, vao
, VERT_ATTRIB_FOG
, 1, GL_FLOAT
);
3858 case VERT_ATTRIB_COLOR_INDEX
:
3859 init_array(ctx
, vao
, VERT_ATTRIB_COLOR_INDEX
, 1, GL_FLOAT
);
3861 case VERT_ATTRIB_EDGEFLAG
:
3862 init_array(ctx
, vao
, VERT_ATTRIB_EDGEFLAG
, 1, GL_UNSIGNED_BYTE
);
3864 case VERT_ATTRIB_POINT_SIZE
:
3865 init_array(ctx
, vao
, VERT_ATTRIB_POINT_SIZE
, 1, GL_FLOAT
);
3868 init_array(ctx
, vao
, i
, 4, GL_FLOAT
);
3873 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_IDENTITY
;
3877 * Initialize vertex array state for given context.
3880 _mesa_init_varray(struct gl_context
*ctx
)
3882 init_default_vao_state(ctx
);
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 */
3890 ctx
->Array
.Objects
= _mesa_NewHashTable();
3895 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
3898 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
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
);
3907 * Free vertex array state for given context.
3910 _mesa_free_varray_data(struct gl_context
*ctx
)
3912 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
3913 _mesa_DeleteHashTable(ctx
->Array
.Objects
);
3917 _mesa_GetVertexArrayIntegervEXT(GLuint vaobj
, GLenum pname
, GLint
*param
)
3919 GET_CURRENT_CONTEXT(ctx
);
3920 struct gl_vertex_array_object
* vao
;
3921 struct gl_buffer_object
*buf
;
3924 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
3925 "glGetVertexArrayIntegervEXT");
3929 /* The EXT_direct_state_access spec says:
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_*
3937 /* Tokens using GetIntegerv */
3938 case GL_CLIENT_ACTIVE_TEXTURE
:
3939 *param
= GL_TEXTURE0_ARB
+ ctx
->Array
.ActiveTexture
;
3941 case GL_VERTEX_ARRAY_SIZE
:
3942 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Format
.Size
;
3944 case GL_VERTEX_ARRAY_TYPE
:
3945 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Format
.Type
;
3947 case GL_VERTEX_ARRAY_STRIDE
:
3948 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Stride
;
3950 case GL_VERTEX_ARRAY_BUFFER_BINDING
:
3951 buf
= vao
->BufferBinding
[VERT_ATTRIB_POS
].BufferObj
;
3952 *param
= buf
? buf
->Name
: 0;
3954 case GL_COLOR_ARRAY_SIZE
:
3955 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Format
.Size
;
3957 case GL_COLOR_ARRAY_TYPE
:
3958 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Format
.Type
;
3960 case GL_COLOR_ARRAY_STRIDE
:
3961 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Stride
;
3963 case GL_COLOR_ARRAY_BUFFER_BINDING
:
3964 buf
= vao
->BufferBinding
[VERT_ATTRIB_COLOR0
].BufferObj
;
3965 *param
= buf
? buf
->Name
: 0;
3967 case GL_EDGE_FLAG_ARRAY_STRIDE
:
3968 *param
= vao
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Stride
;
3970 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING
:
3971 buf
= vao
->BufferBinding
[VERT_ATTRIB_EDGEFLAG
].BufferObj
;
3972 *param
= buf
? buf
->Name
: 0;
3974 case GL_INDEX_ARRAY_TYPE
:
3975 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Format
.Type
;
3977 case GL_INDEX_ARRAY_STRIDE
:
3978 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Stride
;
3980 case GL_INDEX_ARRAY_BUFFER_BINDING
:
3981 buf
= vao
->BufferBinding
[VERT_ATTRIB_COLOR_INDEX
].BufferObj
;
3982 *param
= buf
? buf
->Name
: 0;
3984 case GL_NORMAL_ARRAY_TYPE
:
3985 *param
= vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Format
.Type
;
3987 case GL_NORMAL_ARRAY_STRIDE
:
3988 *param
= vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Stride
;
3990 case GL_NORMAL_ARRAY_BUFFER_BINDING
:
3991 buf
= vao
->BufferBinding
[VERT_ATTRIB_NORMAL
].BufferObj
;
3992 *param
= buf
? buf
->Name
: 0;
3994 case GL_TEXTURE_COORD_ARRAY_SIZE
:
3995 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Format
.Size
;
3997 case GL_TEXTURE_COORD_ARRAY_TYPE
:
3998 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Format
.Type
;
4000 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
4001 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Stride
;
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;
4007 case GL_FOG_COORD_ARRAY_TYPE
:
4008 *param
= vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Format
.Type
;
4010 case GL_FOG_COORD_ARRAY_STRIDE
:
4011 *param
= vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Stride
;
4013 case GL_FOG_COORD_ARRAY_BUFFER_BINDING
:
4014 buf
= vao
->BufferBinding
[VERT_ATTRIB_FOG
].BufferObj
;
4015 *param
= buf
? buf
->Name
: 0;
4017 case GL_SECONDARY_COLOR_ARRAY_SIZE
:
4018 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Format
.Size
;
4020 case GL_SECONDARY_COLOR_ARRAY_TYPE
:
4021 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Format
.Type
;
4023 case GL_SECONDARY_COLOR_ARRAY_STRIDE
:
4024 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Stride
;
4026 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING
:
4027 buf
= vao
->BufferBinding
[VERT_ATTRIB_COLOR1
].BufferObj
;
4028 *param
= buf
? buf
->Name
: 0;
4031 /* Tokens using IsEnabled */
4032 case GL_VERTEX_ARRAY
:
4033 *param
= !!(vao
->Enabled
& VERT_BIT_POS
);
4035 case GL_COLOR_ARRAY
:
4036 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR0
);
4038 case GL_EDGE_FLAG_ARRAY
:
4039 *param
= !!(vao
->Enabled
& VERT_BIT_EDGEFLAG
);
4041 case GL_INDEX_ARRAY
:
4042 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR_INDEX
);
4044 case GL_NORMAL_ARRAY
:
4045 *param
= !!(vao
->Enabled
& VERT_BIT_NORMAL
);
4047 case GL_TEXTURE_COORD_ARRAY
:
4048 *param
= !!(vao
->Enabled
& VERT_BIT_TEX(ctx
->Array
.ActiveTexture
));
4050 case GL_FOG_COORD_ARRAY
:
4051 *param
= !!(vao
->Enabled
& VERT_BIT_FOG
);
4053 case GL_SECONDARY_COLOR_ARRAY
:
4054 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR1
);
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);
4071 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIntegervEXT(pname)");
4076 _mesa_GetVertexArrayPointervEXT(GLuint vaobj
, GLenum pname
, GLvoid
** param
)
4078 GET_CURRENT_CONTEXT(ctx
);
4079 struct gl_vertex_array_object
* vao
;
4081 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
4082 "glGetVertexArrayPointervEXT");
4086 /* The EXT_direct_state_access spec says:
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."
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
:
4103 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayPointervEXT(pname)");
4107 /* pname has been validated, we can now use the helper function */
4108 _get_vao_pointerv(pname
, vao
, param
, "glGetVertexArrayPointervEXT");
4112 _mesa_GetVertexArrayIntegeri_vEXT(GLuint vaobj
, GLuint index
, GLenum pname
, GLint
*param
)
4114 GET_CURRENT_CONTEXT(ctx
);
4115 struct gl_vertex_array_object
* vao
;
4116 struct gl_buffer_object
*buf
;
4118 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
4119 "glGetVertexArrayIntegeri_vEXT");
4124 /* The EXT_direct_state_access spec says:
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."
4135 case GL_TEXTURE_COORD_ARRAY
:
4136 *param
= !!(vao
->Enabled
& VERT_BIT_TEX(index
));
4138 case GL_TEXTURE_COORD_ARRAY_SIZE
:
4139 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Format
.Size
;
4141 case GL_TEXTURE_COORD_ARRAY_TYPE
:
4142 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Format
.Type
;
4144 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
4145 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Stride
;
4147 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING
:
4148 buf
= vao
->BufferBinding
[VERT_ATTRIB_TEX(index
)].BufferObj
;
4149 *param
= buf
? buf
->Name
: 0;
4152 *param
= get_vertex_array_attrib(ctx
, vao
, index
, pname
, "glGetVertexArrayIntegeri_vEXT");
4157 _mesa_GetVertexArrayPointeri_vEXT(GLuint vaobj
, GLuint index
, GLenum pname
, GLvoid
** param
)
4159 GET_CURRENT_CONTEXT(ctx
);
4160 struct gl_vertex_array_object
* vao
;
4162 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
4163 "glGetVertexArrayPointeri_vEXT");
4167 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
4168 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayPointeri_vEXT(index)");
4172 /* The EXT_direct_state_access spec says:
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."
4179 case GL_VERTEX_ATTRIB_ARRAY_POINTER
:
4180 *param
= (GLvoid
*) vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
4182 case GL_TEXTURE_COORD_ARRAY_POINTER
:
4183 *param
= (GLvoid
*) vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Ptr
;
4186 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayPointeri_vEXT(pname)");