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 */
31 #include "util/imports.h"
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
)
203 assert(index
< ARRAY_SIZE(vao
->BufferBinding
));
204 assert(!vao
->SharedAndImmutable
);
205 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
207 if (ctx
->Const
.VertexBufferOffsetIsInt32
&& (int)offset
< 0 &&
209 /* The offset will be interpreted as a signed int, so make sure
210 * the user supplied offset is not negative (driver limitation).
212 _mesa_warning(ctx
, "Received negative int32 vertex buffer offset. "
213 "(driver limitation)\n");
215 /* We can't disable this binding, so use a non-negative offset value
221 if (binding
->BufferObj
!= vbo
||
222 binding
->Offset
!= offset
||
223 binding
->Stride
!= stride
) {
225 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
227 binding
->Offset
= offset
;
228 binding
->Stride
= stride
;
231 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
233 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
234 vbo
->UsageHistory
|= USAGE_ARRAY_BUFFER
;
237 vao
->NewArrays
|= vao
->Enabled
& binding
->_BoundArrays
;
243 * Sets the InstanceDivisor field in the vertex buffer binding point
244 * given by bindingIndex.
247 vertex_binding_divisor(struct gl_context
*ctx
,
248 struct gl_vertex_array_object
*vao
,
252 struct gl_vertex_buffer_binding
*binding
=
253 &vao
->BufferBinding
[bindingIndex
];
254 assert(!vao
->SharedAndImmutable
);
256 if (binding
->InstanceDivisor
!= divisor
) {
257 binding
->InstanceDivisor
= divisor
;
260 vao
->NonZeroDivisorMask
|= binding
->_BoundArrays
;
262 vao
->NonZeroDivisorMask
&= ~binding
->_BoundArrays
;
264 vao
->NewArrays
|= vao
->Enabled
& binding
->_BoundArrays
;
268 /* vertex_formats[gltype - GL_BYTE][integer*2 + normalized][size - 1] */
269 static const uint16_t vertex_formats
[][4][4] = {
272 PIPE_FORMAT_R8_SSCALED
,
273 PIPE_FORMAT_R8G8_SSCALED
,
274 PIPE_FORMAT_R8G8B8_SSCALED
,
275 PIPE_FORMAT_R8G8B8A8_SSCALED
278 PIPE_FORMAT_R8_SNORM
,
279 PIPE_FORMAT_R8G8_SNORM
,
280 PIPE_FORMAT_R8G8B8_SNORM
,
281 PIPE_FORMAT_R8G8B8A8_SNORM
285 PIPE_FORMAT_R8G8_SINT
,
286 PIPE_FORMAT_R8G8B8_SINT
,
287 PIPE_FORMAT_R8G8B8A8_SINT
290 { /* GL_UNSIGNED_BYTE */
292 PIPE_FORMAT_R8_USCALED
,
293 PIPE_FORMAT_R8G8_USCALED
,
294 PIPE_FORMAT_R8G8B8_USCALED
,
295 PIPE_FORMAT_R8G8B8A8_USCALED
298 PIPE_FORMAT_R8_UNORM
,
299 PIPE_FORMAT_R8G8_UNORM
,
300 PIPE_FORMAT_R8G8B8_UNORM
,
301 PIPE_FORMAT_R8G8B8A8_UNORM
305 PIPE_FORMAT_R8G8_UINT
,
306 PIPE_FORMAT_R8G8B8_UINT
,
307 PIPE_FORMAT_R8G8B8A8_UINT
312 PIPE_FORMAT_R16_SSCALED
,
313 PIPE_FORMAT_R16G16_SSCALED
,
314 PIPE_FORMAT_R16G16B16_SSCALED
,
315 PIPE_FORMAT_R16G16B16A16_SSCALED
318 PIPE_FORMAT_R16_SNORM
,
319 PIPE_FORMAT_R16G16_SNORM
,
320 PIPE_FORMAT_R16G16B16_SNORM
,
321 PIPE_FORMAT_R16G16B16A16_SNORM
324 PIPE_FORMAT_R16_SINT
,
325 PIPE_FORMAT_R16G16_SINT
,
326 PIPE_FORMAT_R16G16B16_SINT
,
327 PIPE_FORMAT_R16G16B16A16_SINT
330 { /* GL_UNSIGNED_SHORT */
332 PIPE_FORMAT_R16_USCALED
,
333 PIPE_FORMAT_R16G16_USCALED
,
334 PIPE_FORMAT_R16G16B16_USCALED
,
335 PIPE_FORMAT_R16G16B16A16_USCALED
338 PIPE_FORMAT_R16_UNORM
,
339 PIPE_FORMAT_R16G16_UNORM
,
340 PIPE_FORMAT_R16G16B16_UNORM
,
341 PIPE_FORMAT_R16G16B16A16_UNORM
344 PIPE_FORMAT_R16_UINT
,
345 PIPE_FORMAT_R16G16_UINT
,
346 PIPE_FORMAT_R16G16B16_UINT
,
347 PIPE_FORMAT_R16G16B16A16_UINT
352 PIPE_FORMAT_R32_SSCALED
,
353 PIPE_FORMAT_R32G32_SSCALED
,
354 PIPE_FORMAT_R32G32B32_SSCALED
,
355 PIPE_FORMAT_R32G32B32A32_SSCALED
358 PIPE_FORMAT_R32_SNORM
,
359 PIPE_FORMAT_R32G32_SNORM
,
360 PIPE_FORMAT_R32G32B32_SNORM
,
361 PIPE_FORMAT_R32G32B32A32_SNORM
364 PIPE_FORMAT_R32_SINT
,
365 PIPE_FORMAT_R32G32_SINT
,
366 PIPE_FORMAT_R32G32B32_SINT
,
367 PIPE_FORMAT_R32G32B32A32_SINT
370 { /* GL_UNSIGNED_INT */
372 PIPE_FORMAT_R32_USCALED
,
373 PIPE_FORMAT_R32G32_USCALED
,
374 PIPE_FORMAT_R32G32B32_USCALED
,
375 PIPE_FORMAT_R32G32B32A32_USCALED
378 PIPE_FORMAT_R32_UNORM
,
379 PIPE_FORMAT_R32G32_UNORM
,
380 PIPE_FORMAT_R32G32B32_UNORM
,
381 PIPE_FORMAT_R32G32B32A32_UNORM
384 PIPE_FORMAT_R32_UINT
,
385 PIPE_FORMAT_R32G32_UINT
,
386 PIPE_FORMAT_R32G32B32_UINT
,
387 PIPE_FORMAT_R32G32B32A32_UINT
392 PIPE_FORMAT_R32_FLOAT
,
393 PIPE_FORMAT_R32G32_FLOAT
,
394 PIPE_FORMAT_R32G32B32_FLOAT
,
395 PIPE_FORMAT_R32G32B32A32_FLOAT
398 PIPE_FORMAT_R32_FLOAT
,
399 PIPE_FORMAT_R32G32_FLOAT
,
400 PIPE_FORMAT_R32G32B32_FLOAT
,
401 PIPE_FORMAT_R32G32B32A32_FLOAT
404 {{0}}, /* GL_2_BYTES */
405 {{0}}, /* GL_3_BYTES */
406 {{0}}, /* GL_4_BYTES */
409 PIPE_FORMAT_R64_FLOAT
,
410 PIPE_FORMAT_R64G64_FLOAT
,
411 PIPE_FORMAT_R64G64B64_FLOAT
,
412 PIPE_FORMAT_R64G64B64A64_FLOAT
415 PIPE_FORMAT_R64_FLOAT
,
416 PIPE_FORMAT_R64G64_FLOAT
,
417 PIPE_FORMAT_R64G64B64_FLOAT
,
418 PIPE_FORMAT_R64G64B64A64_FLOAT
421 { /* GL_HALF_FLOAT */
423 PIPE_FORMAT_R16_FLOAT
,
424 PIPE_FORMAT_R16G16_FLOAT
,
425 PIPE_FORMAT_R16G16B16_FLOAT
,
426 PIPE_FORMAT_R16G16B16A16_FLOAT
429 PIPE_FORMAT_R16_FLOAT
,
430 PIPE_FORMAT_R16G16_FLOAT
,
431 PIPE_FORMAT_R16G16B16_FLOAT
,
432 PIPE_FORMAT_R16G16B16A16_FLOAT
437 PIPE_FORMAT_R32_FIXED
,
438 PIPE_FORMAT_R32G32_FIXED
,
439 PIPE_FORMAT_R32G32B32_FIXED
,
440 PIPE_FORMAT_R32G32B32A32_FIXED
443 PIPE_FORMAT_R32_FIXED
,
444 PIPE_FORMAT_R32G32_FIXED
,
445 PIPE_FORMAT_R32G32B32_FIXED
,
446 PIPE_FORMAT_R32G32B32A32_FIXED
452 * Return a PIPE_FORMAT_x for the given GL datatype and size.
454 static enum pipe_format
455 vertex_format_to_pipe_format(GLubyte size
, GLenum16 type
, GLenum16 format
,
456 GLboolean normalized
, GLboolean integer
,
459 assert(size
>= 1 && size
<= 4);
460 assert(format
== GL_RGBA
|| format
== GL_BGRA
);
462 /* 64-bit attributes are translated by drivers. */
464 return PIPE_FORMAT_NONE
;
467 case GL_HALF_FLOAT_OES
:
468 type
= GL_HALF_FLOAT
;
471 case GL_INT_2_10_10_10_REV
:
472 assert(size
== 4 && !integer
);
474 if (format
== GL_BGRA
) {
476 return PIPE_FORMAT_B10G10R10A2_SNORM
;
478 return PIPE_FORMAT_B10G10R10A2_SSCALED
;
481 return PIPE_FORMAT_R10G10B10A2_SNORM
;
483 return PIPE_FORMAT_R10G10B10A2_SSCALED
;
487 case GL_UNSIGNED_INT_2_10_10_10_REV
:
488 assert(size
== 4 && !integer
);
490 if (format
== GL_BGRA
) {
492 return PIPE_FORMAT_B10G10R10A2_UNORM
;
494 return PIPE_FORMAT_B10G10R10A2_USCALED
;
497 return PIPE_FORMAT_R10G10B10A2_UNORM
;
499 return PIPE_FORMAT_R10G10B10A2_USCALED
;
503 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
504 assert(size
== 3 && !integer
&& format
== GL_RGBA
);
505 return PIPE_FORMAT_R11G11B10_FLOAT
;
507 case GL_UNSIGNED_BYTE
:
508 if (format
== GL_BGRA
) {
509 /* this is an odd-ball case */
511 return PIPE_FORMAT_B8G8R8A8_UNORM
;
516 unsigned index
= integer
*2 + normalized
;
518 assert(type
>= GL_BYTE
&& type
<= GL_FIXED
);
519 return vertex_formats
[type
- GL_BYTE
][index
][size
-1];
523 _mesa_set_vertex_format(struct gl_vertex_format
*vertex_format
,
524 GLubyte size
, GLenum16 type
, GLenum16 format
,
525 GLboolean normalized
, GLboolean integer
,
529 vertex_format
->Type
= type
;
530 vertex_format
->Format
= format
;
531 vertex_format
->Size
= size
;
532 vertex_format
->Normalized
= normalized
;
533 vertex_format
->Integer
= integer
;
534 vertex_format
->Doubles
= doubles
;
535 vertex_format
->_ElementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
536 assert(vertex_format
->_ElementSize
<= 4*sizeof(double));
537 vertex_format
->_PipeFormat
=
538 vertex_format_to_pipe_format(size
, type
, format
, normalized
, integer
,
544 * Examine the API profile and extensions to determine which types are legal
545 * for vertex arrays. This is called once from update_array_format().
548 get_legal_types_mask(const struct gl_context
*ctx
)
550 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
552 if (_mesa_is_gles(ctx
)) {
553 legalTypesMask
&= ~(FIXED_GL_BIT
|
555 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
557 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
558 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
559 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
560 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
561 * quite as trivial as we'd like because it uses a different enum value
562 * for GL_HALF_FLOAT_OES.
564 if (ctx
->Version
< 30) {
565 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
567 UNSIGNED_INT_2_10_10_10_REV_BIT
|
568 INT_2_10_10_10_REV_BIT
);
570 if (!_mesa_has_OES_vertex_half_float(ctx
))
571 legalTypesMask
&= ~HALF_BIT
;
575 legalTypesMask
&= ~FIXED_ES_BIT
;
577 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
578 legalTypesMask
&= ~FIXED_GL_BIT
;
580 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
581 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
582 INT_2_10_10_10_REV_BIT
);
584 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
585 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
588 return legalTypesMask
;
592 get_array_format(const struct gl_context
*ctx
, GLint sizeMax
, GLint
*size
)
594 GLenum format
= GL_RGBA
;
596 /* Do size parameter checking.
597 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
598 * must be handled specially.
600 if (ctx
->Extensions
.EXT_vertex_array_bgra
&& sizeMax
== BGRA_OR_4
&&
611 * \param attrib The index of the attribute array
612 * \param size Components per element (1, 2, 3 or 4)
613 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
614 * \param format Either GL_RGBA or GL_BGRA.
615 * \param normalized Whether integer types are converted to floats in [-1, 1]
616 * \param integer Integer-valued values (will not be normalized to [-1, 1])
617 * \param doubles Double values not reduced to floats
618 * \param relativeOffset Offset of the first element relative to the binding
622 _mesa_update_array_format(struct gl_context
*ctx
,
623 struct gl_vertex_array_object
*vao
,
624 gl_vert_attrib attrib
, GLint size
, GLenum type
,
625 GLenum format
, GLboolean normalized
,
626 GLboolean integer
, GLboolean doubles
,
627 GLuint relativeOffset
)
629 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
631 assert(!vao
->SharedAndImmutable
);
634 array
->RelativeOffset
= relativeOffset
;
635 _mesa_set_vertex_format(&array
->Format
, size
, type
, format
,
636 normalized
, integer
, doubles
);
638 vao
->NewArrays
|= vao
->Enabled
& VERT_BIT(attrib
);
642 * Does error checking of the format in an attrib array.
644 * Called by *Pointer() and VertexAttrib*Format().
646 * \param func Name of calling function used for error reporting
647 * \param attrib The index of the attribute array
648 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
649 * \param sizeMin Min allowable size value
650 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
651 * \param size Components per element (1, 2, 3 or 4)
652 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
653 * \param normalized Whether integer types are converted to floats in [-1, 1]
654 * \param integer Integer-valued values (will not be normalized to [-1, 1])
655 * \param doubles Double values not reduced to floats
656 * \param relativeOffset Offset of the first element relative to the binding offset.
657 * \return bool True if validation is successful, False otherwise.
660 validate_array_format(struct gl_context
*ctx
, const char *func
,
661 struct gl_vertex_array_object
*vao
,
662 GLuint attrib
, GLbitfield legalTypesMask
,
663 GLint sizeMin
, GLint sizeMax
,
664 GLint size
, GLenum type
, GLboolean normalized
,
665 GLboolean integer
, GLboolean doubles
,
666 GLuint relativeOffset
, GLenum format
)
670 /* at most, one of these bools can be true */
671 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
673 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
674 /* Compute the LegalTypesMask only once, unless the context API has
675 * changed, in which case we want to compute it again. We can't do this
676 * in _mesa_init_varrays() below because extensions are not yet enabled
679 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
680 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
683 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
685 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
686 /* BGRA ordering is not supported in ES contexts.
691 typeBit
= type_to_bit(ctx
, type
);
692 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
693 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
694 func
, _mesa_enum_to_string(type
));
698 if (format
== GL_BGRA
) {
699 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
701 * "An INVALID_OPERATION error is generated under any of the following
704 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
705 * or UNSIGNED_INT_2_10_10_10_REV;
707 * • size is BGRA and normalized is FALSE;"
709 bool bgra_error
= false;
711 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
712 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
713 type
!= GL_INT_2_10_10_10_REV
&&
714 type
!= GL_UNSIGNED_BYTE
)
716 } else if (type
!= GL_UNSIGNED_BYTE
)
720 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
721 func
, _mesa_enum_to_string(type
));
726 _mesa_error(ctx
, GL_INVALID_OPERATION
,
727 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
731 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
732 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
736 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
737 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
738 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
739 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
743 /* The ARB_vertex_attrib_binding_spec says:
745 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
746 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
748 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
749 _mesa_error(ctx
, GL_INVALID_VALUE
,
750 "%s(relativeOffset=%d > "
751 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
752 func
, relativeOffset
);
756 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
757 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
758 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
766 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
768 * \param func name of calling function used for error reporting
769 * \param vao the vao to update
770 * \param obj the bound buffer object
771 * \param attrib the attribute array index to update
772 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
773 * \param sizeMin min allowable size value
774 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
775 * \param size components per element (1, 2, 3 or 4)
776 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
777 * \param stride stride between elements, in elements
778 * \param normalized are integer types converted to floats in [-1, 1]?
779 * \param integer integer-valued values (will not be normalized to [-1,1])
780 * \param doubles Double values not reduced to floats
781 * \param ptr the address (or offset inside VBO) of the array data
784 validate_array(struct gl_context
*ctx
, const char *func
,
785 struct gl_vertex_array_object
*vao
,
786 struct gl_buffer_object
*obj
,
787 GLuint attrib
, GLbitfield legalTypesMask
,
788 GLint sizeMin
, GLint sizeMax
,
789 GLint size
, GLenum type
, GLsizei stride
,
790 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
793 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
795 * "Client vertex arrays - all vertex array attribute pointers must
796 * refer to buffer objects (section 2.9.2). The default vertex array
797 * object (the name zero) is also deprecated. Calling
798 * VertexAttribPointer when no buffer object or no vertex array object
799 * is bound will generate an INVALID_OPERATION error..."
801 * The check for VBOs is handled below.
803 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
804 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
810 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
814 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
815 stride
> ctx
->Const
.MaxVertexAttribStride
) {
816 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
817 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
821 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
823 * "An INVALID_OPERATION error is generated under any of the following
828 * * any of the *Pointer commands specifying the location and
829 * organization of vertex array data are called while zero is bound
830 * to the ARRAY_BUFFER buffer object binding point (see section
831 * 2.9.6), and the pointer argument is not NULL."
833 if (ptr
!= NULL
&& vao
!= ctx
->Array
.DefaultVAO
&&
835 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
842 validate_array_and_format(struct gl_context
*ctx
, const char *func
,
843 struct gl_vertex_array_object
*vao
,
844 struct gl_buffer_object
*obj
,
845 GLuint attrib
, GLbitfield legalTypes
,
846 GLint sizeMin
, GLint sizeMax
,
847 GLint size
, GLenum type
, GLsizei stride
,
848 GLboolean normalized
, GLboolean integer
,
849 GLboolean doubles
, GLenum format
, const GLvoid
*ptr
)
851 validate_array(ctx
, func
, vao
, obj
, attrib
, legalTypes
, sizeMin
, sizeMax
,
852 size
, type
, stride
, normalized
, integer
, doubles
, ptr
);
854 return validate_array_format(ctx
, func
, vao
, attrib
, legalTypes
, sizeMin
,
855 sizeMax
, size
, type
, normalized
, integer
,
861 * Update state for glVertex/Color/TexCoord/...Pointer functions.
863 * \param vao the vao to update
864 * \param obj the bound buffer object
865 * \param attrib the attribute array index to update
866 * \param format Either GL_RGBA or GL_BGRA.
867 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
868 * \param size components per element (1, 2, 3 or 4)
869 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
870 * \param stride stride between elements, in elements
871 * \param normalized are integer types converted to floats in [-1, 1]?
872 * \param integer integer-valued values (will not be normalized to [-1,1])
873 * \param doubles Double values not reduced to floats
874 * \param ptr the address (or offset inside VBO) of the array data
877 update_array(struct gl_context
*ctx
,
878 struct gl_vertex_array_object
*vao
,
879 struct gl_buffer_object
*obj
,
880 GLuint attrib
, GLenum format
,
882 GLint size
, GLenum type
, GLsizei stride
,
883 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
886 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
887 normalized
, integer
, doubles
, 0);
889 /* Reset the vertex attrib binding */
890 _mesa_vertex_attrib_binding(ctx
, vao
, attrib
, attrib
);
892 /* The Stride and Ptr fields are not set by update_array_format() */
893 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attrib
];
894 array
->Stride
= stride
;
895 /* For updating the pointer we would need to add the vao->NewArrays flag
896 * to the VAO. But but that is done already unconditionally in
897 * _mesa_update_array_format called above.
899 assert((vao
->NewArrays
| ~vao
->Enabled
) & VERT_BIT(attrib
));
902 /* Update the vertex buffer binding */
903 GLsizei effectiveStride
= stride
!= 0 ?
904 stride
: array
->Format
._ElementSize
;
905 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
911 /* Helper function for all EXT_direct_state_access glVertexArray* functions */
913 _lookup_vao_and_vbo_dsa(struct gl_context
*ctx
,
914 GLuint vaobj
, GLuint buffer
,
916 struct gl_vertex_array_object
** vao
,
917 struct gl_buffer_object
** vbo
,
920 *vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, caller
);
925 *vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
926 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, vbo
, caller
))
930 _mesa_error(ctx
, GL_INVALID_VALUE
,
931 "%s(negative offset with non-0 buffer)", caller
);
943 _mesa_VertexPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
946 GET_CURRENT_CONTEXT(ctx
);
948 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
949 VERT_ATTRIB_POS
, GL_RGBA
, 4, size
, type
, stride
,
950 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
955 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
957 GET_CURRENT_CONTEXT(ctx
);
959 GLenum format
= GL_RGBA
;
960 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
961 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
962 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
963 DOUBLE_BIT
| HALF_BIT
|
964 UNSIGNED_INT_2_10_10_10_REV_BIT
|
965 INT_2_10_10_10_REV_BIT
);
967 if (!validate_array_and_format(ctx
, "glVertexPointer",
968 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
969 VERT_ATTRIB_POS
, legalTypes
, 2, 4, size
,
970 type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
974 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
975 VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
976 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
981 _mesa_VertexArrayVertexOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
982 GLenum type
, GLsizei stride
, GLintptr offset
)
984 GET_CURRENT_CONTEXT(ctx
);
986 GLenum format
= GL_RGBA
;
987 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
988 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
989 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
990 DOUBLE_BIT
| HALF_BIT
|
991 UNSIGNED_INT_2_10_10_10_REV_BIT
|
992 INT_2_10_10_10_REV_BIT
);
994 struct gl_vertex_array_object
* vao
;
995 struct gl_buffer_object
* vbo
;
997 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
999 "glVertexArrayVertexOffsetEXT"))
1002 if (!validate_array_and_format(ctx
, "glVertexArrayVertexOffsetEXT",
1004 VERT_ATTRIB_POS
, legalTypes
, 2, 4, size
,
1005 type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
1006 format
, (void*) offset
))
1009 update_array(ctx
, vao
, vbo
,
1010 VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
1011 GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1016 _mesa_NormalPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1018 GET_CURRENT_CONTEXT(ctx
);
1020 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1021 VERT_ATTRIB_NORMAL
, GL_RGBA
, 3, 3, type
, stride
, GL_TRUE
,
1022 GL_FALSE
, GL_FALSE
, ptr
);
1027 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1029 GET_CURRENT_CONTEXT(ctx
);
1031 GLenum format
= GL_RGBA
;
1032 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1033 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1034 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1035 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1036 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1037 INT_2_10_10_10_REV_BIT
);
1039 if (!validate_array_and_format(ctx
, "glNormalPointer",
1040 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1041 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
1042 type
, stride
, GL_TRUE
, GL_FALSE
,
1043 GL_FALSE
, format
, ptr
))
1046 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1047 VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
1048 GL_FALSE
, GL_FALSE
, ptr
);
1053 _mesa_VertexArrayNormalOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1054 GLsizei stride
, GLintptr offset
)
1056 GET_CURRENT_CONTEXT(ctx
);
1058 GLenum format
= GL_RGBA
;
1059 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1060 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1061 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1062 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1063 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1064 INT_2_10_10_10_REV_BIT
);
1066 struct gl_vertex_array_object
* vao
;
1067 struct gl_buffer_object
* vbo
;
1069 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1074 if (!validate_array_and_format(ctx
, "glNormalPointer",
1076 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
1077 type
, stride
, GL_TRUE
, GL_FALSE
,
1078 GL_FALSE
, format
, (void*) offset
))
1081 update_array(ctx
, vao
, vbo
,
1082 VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
1083 GL_FALSE
, GL_FALSE
, (void*) offset
);
1088 _mesa_ColorPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
1091 GET_CURRENT_CONTEXT(ctx
);
1093 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1094 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1095 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
1096 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1101 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1103 GET_CURRENT_CONTEXT(ctx
);
1104 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
1106 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1107 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1108 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1109 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1110 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1111 INT_BIT
| UNSIGNED_INT_BIT
|
1112 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1113 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1114 INT_2_10_10_10_REV_BIT
);
1116 if (!validate_array_and_format(ctx
, "glColorPointer",
1117 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1118 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
1119 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
1120 GL_FALSE
, GL_FALSE
, format
, ptr
))
1123 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1124 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
1125 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1130 _mesa_VertexArrayColorOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1131 GLenum type
, GLsizei stride
, GLintptr offset
)
1133 GET_CURRENT_CONTEXT(ctx
);
1134 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
1136 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1137 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1138 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1139 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1140 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1141 INT_BIT
| UNSIGNED_INT_BIT
|
1142 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1143 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1144 INT_2_10_10_10_REV_BIT
);
1146 struct gl_vertex_array_object
* vao
;
1147 struct gl_buffer_object
* vbo
;
1149 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1151 "glVertexArrayColorOffsetEXT"))
1154 if (!validate_array_and_format(ctx
, "glVertexArrayColorOffsetEXT",
1156 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
1157 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
1158 GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1161 update_array(ctx
, vao
, vbo
,
1162 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
1163 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1168 _mesa_FogCoordPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1170 GET_CURRENT_CONTEXT(ctx
);
1172 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1173 VERT_ATTRIB_FOG
, GL_RGBA
, 1, 1, type
, stride
, GL_FALSE
,
1174 GL_FALSE
, GL_FALSE
, ptr
);
1179 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1181 GET_CURRENT_CONTEXT(ctx
);
1183 GLenum format
= GL_RGBA
;
1184 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
1186 if (!validate_array_and_format(ctx
, "glFogCoordPointer",
1187 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1188 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
1189 type
, stride
, GL_FALSE
, GL_FALSE
,
1190 GL_FALSE
, format
, ptr
))
1193 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1194 VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
1195 GL_FALSE
, GL_FALSE
, ptr
);
1200 _mesa_VertexArrayFogCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1201 GLsizei stride
, GLintptr offset
)
1203 GET_CURRENT_CONTEXT(ctx
);
1205 GLenum format
= GL_RGBA
;
1206 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
1208 struct gl_vertex_array_object
* vao
;
1209 struct gl_buffer_object
* vbo
;
1211 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1213 "glVertexArrayFogCoordOffsetEXT"))
1216 if (!validate_array_and_format(ctx
, "glVertexArrayFogCoordOffsetEXT",
1218 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
1219 type
, stride
, GL_FALSE
, GL_FALSE
,
1220 GL_FALSE
, format
, (void*) offset
))
1223 update_array(ctx
, vao
, vbo
,
1224 VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
1225 GL_FALSE
, GL_FALSE
, (void*) offset
);
1230 _mesa_IndexPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1232 GET_CURRENT_CONTEXT(ctx
);
1234 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1235 VERT_ATTRIB_COLOR_INDEX
, GL_RGBA
, 1, 1, type
, stride
,
1236 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1241 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1243 GET_CURRENT_CONTEXT(ctx
);
1245 GLenum format
= GL_RGBA
;
1246 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1247 FLOAT_BIT
| DOUBLE_BIT
);
1249 if (!validate_array_and_format(ctx
, "glIndexPointer",
1250 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1251 VERT_ATTRIB_COLOR_INDEX
,
1252 legalTypes
, 1, 1, 1, type
, stride
,
1253 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1256 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1257 VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
1258 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1263 _mesa_VertexArrayIndexOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1264 GLsizei stride
, GLintptr offset
)
1266 GET_CURRENT_CONTEXT(ctx
);
1268 GLenum format
= GL_RGBA
;
1269 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1270 FLOAT_BIT
| DOUBLE_BIT
);
1272 struct gl_vertex_array_object
* vao
;
1273 struct gl_buffer_object
* vbo
;
1275 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1277 "glVertexArrayIndexOffsetEXT"))
1280 if (!validate_array_and_format(ctx
, "glVertexArrayIndexOffsetEXT",
1282 VERT_ATTRIB_COLOR_INDEX
,
1283 legalTypes
, 1, 1, 1, type
, stride
,
1284 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1287 update_array(ctx
, vao
, vbo
,
1288 VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
1289 GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1294 _mesa_SecondaryColorPointer_no_error(GLint size
, GLenum type
,
1295 GLsizei stride
, const GLvoid
*ptr
)
1297 GET_CURRENT_CONTEXT(ctx
);
1299 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1300 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1301 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
1302 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1307 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
1308 GLsizei stride
, const GLvoid
*ptr
)
1310 GET_CURRENT_CONTEXT(ctx
);
1312 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1313 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1314 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1315 INT_BIT
| UNSIGNED_INT_BIT
|
1316 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1317 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1318 INT_2_10_10_10_REV_BIT
);
1320 if (!validate_array_and_format(ctx
, "glSecondaryColorPointer",
1321 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1322 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
1323 BGRA_OR_4
, size
, type
, stride
,
1324 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1327 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1328 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
1329 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1334 _mesa_VertexArraySecondaryColorOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1335 GLenum type
, GLsizei stride
, GLintptr offset
)
1337 GET_CURRENT_CONTEXT(ctx
);
1339 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1340 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1341 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1342 INT_BIT
| UNSIGNED_INT_BIT
|
1343 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1344 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1345 INT_2_10_10_10_REV_BIT
);
1347 struct gl_vertex_array_object
* vao
;
1348 struct gl_buffer_object
* vbo
;
1350 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1352 "glVertexArraySecondaryColorOffsetEXT"))
1355 if (!validate_array_and_format(ctx
, "glVertexArraySecondaryColorOffsetEXT",
1357 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
1358 BGRA_OR_4
, size
, type
, stride
,
1359 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1362 update_array(ctx
, vao
, vbo
,
1363 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
1364 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1369 _mesa_TexCoordPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
1372 GET_CURRENT_CONTEXT(ctx
);
1373 const GLuint unit
= ctx
->Array
.ActiveTexture
;
1375 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1376 VERT_ATTRIB_TEX(unit
), GL_RGBA
, 4, size
, type
,
1377 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1382 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
1385 GET_CURRENT_CONTEXT(ctx
);
1386 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1387 const GLuint unit
= ctx
->Array
.ActiveTexture
;
1389 GLenum format
= GL_RGBA
;
1390 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1391 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1392 : (SHORT_BIT
| INT_BIT
|
1393 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1394 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1395 INT_2_10_10_10_REV_BIT
);
1397 if (!validate_array_and_format(ctx
, "glTexCoordPointer",
1398 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1399 VERT_ATTRIB_TEX(unit
), legalTypes
,
1400 sizeMin
, 4, size
, type
, stride
,
1401 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1404 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1405 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
1406 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1411 _mesa_VertexArrayTexCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1412 GLenum type
, GLsizei stride
, GLintptr offset
)
1414 GET_CURRENT_CONTEXT(ctx
);
1415 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1416 const GLuint unit
= ctx
->Array
.ActiveTexture
;
1418 GLenum format
= GL_RGBA
;
1419 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1420 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1421 : (SHORT_BIT
| INT_BIT
|
1422 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1423 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1424 INT_2_10_10_10_REV_BIT
);
1426 struct gl_vertex_array_object
* vao
;
1427 struct gl_buffer_object
* vbo
;
1429 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1431 "glVertexArrayTexCoordOffsetEXT"))
1434 if (!validate_array_and_format(ctx
, "glVertexArrayTexCoordOffsetEXT",
1436 VERT_ATTRIB_TEX(unit
), legalTypes
,
1437 sizeMin
, 4, size
, type
, stride
,
1438 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1441 update_array(ctx
, vao
, vbo
,
1442 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
1443 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1448 _mesa_VertexArrayMultiTexCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum texunit
,
1449 GLint size
, GLenum type
, GLsizei stride
,
1452 GET_CURRENT_CONTEXT(ctx
);
1453 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1454 const GLuint unit
= texunit
- GL_TEXTURE0
;
1456 GLenum format
= GL_RGBA
;
1457 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1458 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1459 : (SHORT_BIT
| INT_BIT
|
1460 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1461 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1462 INT_2_10_10_10_REV_BIT
);
1464 struct gl_vertex_array_object
* vao
;
1465 struct gl_buffer_object
* vbo
;
1467 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1469 "glVertexArrayMultiTexCoordOffsetEXT"))
1472 if (unit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1473 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexArrayMultiTexCoordOffsetEXT(texunit=%d)",
1478 if (!validate_array_and_format(ctx
, "glVertexArrayMultiTexCoordOffsetEXT",
1480 VERT_ATTRIB_TEX(unit
), legalTypes
,
1481 sizeMin
, 4, size
, type
, stride
,
1482 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1485 update_array(ctx
, vao
, vbo
,
1486 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
1487 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1492 _mesa_EdgeFlagPointer_no_error(GLsizei stride
, const GLvoid
*ptr
)
1494 /* this is the same type that glEdgeFlag uses */
1495 const GLboolean integer
= GL_FALSE
;
1496 GET_CURRENT_CONTEXT(ctx
);
1498 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1499 VERT_ATTRIB_EDGEFLAG
, GL_RGBA
, 1, 1, GL_UNSIGNED_BYTE
,
1500 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
1505 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
1507 /* this is the same type that glEdgeFlag uses */
1508 const GLboolean integer
= GL_FALSE
;
1509 GET_CURRENT_CONTEXT(ctx
);
1511 GLenum format
= GL_RGBA
;
1512 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
1514 if (!validate_array_and_format(ctx
, "glEdgeFlagPointer",
1515 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1516 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
1517 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
1518 GL_FALSE
, integer
, GL_FALSE
, format
, ptr
))
1521 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1522 VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
1523 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
1528 _mesa_VertexArrayEdgeFlagOffsetEXT(GLuint vaobj
, GLuint buffer
, GLsizei stride
,
1531 /* this is the same type that glEdgeFlag uses */
1532 const GLboolean integer
= GL_FALSE
;
1533 GET_CURRENT_CONTEXT(ctx
);
1535 GLenum format
= GL_RGBA
;
1536 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
1538 struct gl_vertex_array_object
* vao
;
1539 struct gl_buffer_object
* vbo
;
1541 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1543 "glVertexArrayEdgeFlagOffsetEXT"))
1546 if (!validate_array_and_format(ctx
, "glVertexArrayEdgeFlagOffsetEXT",
1548 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
1549 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
1550 GL_FALSE
, integer
, GL_FALSE
, format
, (void*) offset
))
1553 update_array(ctx
, vao
, vbo
,
1554 VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
1555 stride
, GL_FALSE
, integer
, GL_FALSE
, (void*) offset
);
1560 _mesa_PointSizePointerOES_no_error(GLenum type
, GLsizei stride
,
1563 GET_CURRENT_CONTEXT(ctx
);
1565 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1566 VERT_ATTRIB_POINT_SIZE
, GL_RGBA
, 1, 1, type
, stride
,
1567 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1572 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1574 GET_CURRENT_CONTEXT(ctx
);
1576 GLenum format
= GL_RGBA
;
1577 if (ctx
->API
!= API_OPENGLES
) {
1578 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1579 "glPointSizePointer(ES 1.x only)");
1583 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
1585 if (!validate_array_and_format(ctx
, "glPointSizePointer",
1586 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1587 VERT_ATTRIB_POINT_SIZE
, legalTypes
,
1588 1, 1, 1, type
, stride
, GL_FALSE
, GL_FALSE
,
1589 GL_FALSE
, format
, ptr
))
1592 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1593 VERT_ATTRIB_POINT_SIZE
, format
, 1, 1, type
, stride
,
1594 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1599 _mesa_VertexAttribPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1600 GLboolean normalized
,
1601 GLsizei stride
, const GLvoid
*ptr
)
1603 GET_CURRENT_CONTEXT(ctx
);
1605 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1606 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1607 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1608 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
1613 * Set a generic vertex attribute array.
1614 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1615 * (position, normal, color, fog, texcoord, etc).
1618 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
1619 GLboolean normalized
,
1620 GLsizei stride
, const GLvoid
*ptr
)
1622 GET_CURRENT_CONTEXT(ctx
);
1624 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1625 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1626 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(idx)");
1630 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1631 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1632 INT_BIT
| UNSIGNED_INT_BIT
|
1633 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1634 FIXED_ES_BIT
| FIXED_GL_BIT
|
1635 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1636 INT_2_10_10_10_REV_BIT
|
1637 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1639 if (!validate_array_and_format(ctx
, "glVertexAttribPointer",
1640 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1641 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1642 1, BGRA_OR_4
, size
, type
, stride
,
1643 normalized
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1646 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1647 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1648 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
1653 _mesa_VertexArrayVertexAttribOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1654 GLenum type
, GLboolean normalized
,
1655 GLsizei stride
, GLintptr offset
)
1657 GET_CURRENT_CONTEXT(ctx
);
1658 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1659 struct gl_vertex_array_object
* vao
;
1660 struct gl_buffer_object
* vbo
;
1662 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1664 "glVertexArrayVertexAttribOffsetEXT"))
1667 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1668 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribOffsetEXT(idx)");
1672 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1673 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1674 INT_BIT
| UNSIGNED_INT_BIT
|
1675 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1676 FIXED_ES_BIT
| FIXED_GL_BIT
|
1677 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1678 INT_2_10_10_10_REV_BIT
|
1679 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1681 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribOffsetEXT",
1683 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1684 1, BGRA_OR_4
, size
, type
, stride
,
1685 normalized
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1688 update_array(ctx
, vao
, vbo
,
1689 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1690 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1695 _mesa_VertexArrayVertexAttribLOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1696 GLenum type
, GLsizei stride
, GLintptr offset
)
1698 GET_CURRENT_CONTEXT(ctx
);
1699 GLenum format
= GL_RGBA
;
1700 struct gl_vertex_array_object
* vao
;
1701 struct gl_buffer_object
* vbo
;
1703 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1705 "glVertexArrayVertexAttribLOffsetEXT"))
1708 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1709 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribLOffsetEXT(idx)");
1713 const GLbitfield legalTypes
= DOUBLE_BIT
;
1715 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribLOffsetEXT",
1717 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1718 1, 4, size
, type
, stride
,
1719 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
, (void*) offset
))
1722 update_array(ctx
, vao
, vbo
,
1723 VERT_ATTRIB_GENERIC(index
), format
, 4,
1724 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, (void*) offset
);
1729 _mesa_VertexAttribIPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1730 GLsizei stride
, const GLvoid
*ptr
)
1732 const GLboolean normalized
= GL_FALSE
;
1733 const GLboolean integer
= GL_TRUE
;
1734 GET_CURRENT_CONTEXT(ctx
);
1736 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1737 VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1738 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1743 * GL_EXT_gpu_shader4 / GL 3.0.
1744 * Set an integer-valued vertex attribute array.
1745 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1746 * (position, normal, color, fog, texcoord, etc).
1749 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
1750 GLsizei stride
, const GLvoid
*ptr
)
1752 const GLboolean normalized
= GL_FALSE
;
1753 const GLboolean integer
= GL_TRUE
;
1754 GET_CURRENT_CONTEXT(ctx
);
1756 GLenum format
= GL_RGBA
;
1757 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1758 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
1762 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1763 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1764 INT_BIT
| UNSIGNED_INT_BIT
);
1766 if (!validate_array_and_format(ctx
, "glVertexAttribIPointer",
1767 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1768 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1769 1, 4, size
, type
, stride
,
1770 normalized
, integer
, GL_FALSE
, format
, ptr
))
1773 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1774 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1775 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1780 _mesa_VertexAttribLPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1781 GLsizei stride
, const GLvoid
*ptr
)
1783 GET_CURRENT_CONTEXT(ctx
);
1785 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1786 VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1787 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1792 _mesa_VertexArrayVertexAttribIOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1793 GLenum type
, GLsizei stride
, GLintptr offset
)
1795 const GLboolean normalized
= GL_FALSE
;
1796 const GLboolean integer
= GL_TRUE
;
1797 GET_CURRENT_CONTEXT(ctx
);
1798 GLenum format
= GL_RGBA
;
1800 struct gl_vertex_array_object
* vao
;
1801 struct gl_buffer_object
* vbo
;
1803 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1805 "glVertexArrayVertexAttribIOffsetEXT"))
1808 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1809 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribIOffsetEXT(index)");
1813 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1814 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1815 INT_BIT
| UNSIGNED_INT_BIT
);
1817 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribIOffsetEXT",
1819 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1820 1, 4, size
, type
, stride
,
1821 normalized
, integer
, GL_FALSE
, format
, (void*) offset
))
1824 update_array(ctx
, vao
, vbo
,
1825 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1826 stride
, normalized
, integer
, GL_FALSE
, (void*) offset
);
1831 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
1832 GLsizei stride
, const GLvoid
*ptr
)
1834 GET_CURRENT_CONTEXT(ctx
);
1836 GLenum format
= GL_RGBA
;
1837 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1838 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
1842 const GLbitfield legalTypes
= DOUBLE_BIT
;
1844 if (!validate_array_and_format(ctx
, "glVertexAttribLPointer",
1845 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1846 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1847 1, 4, size
, type
, stride
,
1848 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
, ptr
))
1851 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1852 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1853 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1858 _mesa_enable_vertex_array_attribs(struct gl_context
*ctx
,
1859 struct gl_vertex_array_object
*vao
,
1860 GLbitfield attrib_bits
)
1862 assert((attrib_bits
& ~VERT_BIT_ALL
) == 0);
1863 assert(!vao
->SharedAndImmutable
);
1865 /* Only work on bits that are disabled */
1866 attrib_bits
&= ~vao
->Enabled
;
1868 /* was disabled, now being enabled */
1869 vao
->Enabled
|= attrib_bits
;
1870 vao
->NewArrays
|= attrib_bits
;
1872 /* Update the map mode if needed */
1873 if (attrib_bits
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1874 update_attribute_map_mode(ctx
, vao
);
1879 enable_vertex_array_attrib(struct gl_context
*ctx
,
1880 struct gl_vertex_array_object
*vao
,
1884 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1885 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
1889 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1894 _mesa_EnableVertexAttribArray(GLuint index
)
1896 GET_CURRENT_CONTEXT(ctx
);
1897 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
1898 "glEnableVertexAttribArray");
1903 _mesa_EnableVertexAttribArray_no_error(GLuint index
)
1905 GET_CURRENT_CONTEXT(ctx
);
1906 _mesa_enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1907 VERT_ATTRIB_GENERIC(index
));
1912 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1914 GET_CURRENT_CONTEXT(ctx
);
1915 struct gl_vertex_array_object
*vao
;
1917 /* The ARB_direct_state_access specification says:
1919 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1920 * and DisableVertexArrayAttrib if <vaobj> is not
1921 * [compatibility profile: zero or] the name of an existing vertex
1924 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glEnableVertexArrayAttrib");
1928 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
1932 _mesa_EnableVertexArrayAttribEXT(GLuint vaobj
, GLuint index
)
1934 GET_CURRENT_CONTEXT(ctx
);
1935 struct gl_vertex_array_object
* vao
= _mesa_lookup_vao_err(ctx
, vaobj
,
1937 "glEnableVertexArrayAttribEXT");
1941 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttribEXT");
1946 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1948 GET_CURRENT_CONTEXT(ctx
);
1949 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1950 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1955 _mesa_disable_vertex_array_attribs(struct gl_context
*ctx
,
1956 struct gl_vertex_array_object
*vao
,
1957 GLbitfield attrib_bits
)
1959 assert((attrib_bits
& ~VERT_BIT_ALL
) == 0);
1960 assert(!vao
->SharedAndImmutable
);
1962 /* Only work on bits that are enabled */
1963 attrib_bits
&= vao
->Enabled
;
1965 /* was enabled, now being disabled */
1966 vao
->Enabled
&= ~attrib_bits
;
1967 vao
->NewArrays
|= attrib_bits
;
1969 /* Update the map mode if needed */
1970 if (attrib_bits
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1971 update_attribute_map_mode(ctx
, vao
);
1977 _mesa_DisableVertexAttribArray(GLuint index
)
1979 GET_CURRENT_CONTEXT(ctx
);
1981 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1982 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexAttribArray(index)");
1986 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1987 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
1992 _mesa_DisableVertexAttribArray_no_error(GLuint index
)
1994 GET_CURRENT_CONTEXT(ctx
);
1995 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1996 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
2001 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
2003 GET_CURRENT_CONTEXT(ctx
);
2004 struct gl_vertex_array_object
*vao
;
2006 /* The ARB_direct_state_access specification says:
2008 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
2009 * and DisableVertexArrayAttrib if <vaobj> is not
2010 * [compatibility profile: zero or] the name of an existing vertex
2013 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glDisableVertexArrayAttrib");
2017 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2018 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
2022 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2023 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
2027 _mesa_DisableVertexArrayAttribEXT(GLuint vaobj
, GLuint index
)
2029 GET_CURRENT_CONTEXT(ctx
);
2030 struct gl_vertex_array_object
* vao
= _mesa_lookup_vao_err(ctx
, vaobj
,
2032 "glEnableVertexArrayAttribEXT");
2036 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2037 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
2041 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2042 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
2047 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
2049 GET_CURRENT_CONTEXT(ctx
);
2050 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2051 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2052 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
2057 * Return info for a vertex attribute array (no alias with legacy
2058 * vertex attributes (pos, normal, color, etc)). This function does
2059 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
2062 get_vertex_array_attrib(struct gl_context
*ctx
,
2063 const struct gl_vertex_array_object
*vao
,
2064 GLuint index
, GLenum pname
,
2067 const struct gl_array_attributes
*array
;
2068 struct gl_buffer_object
*buf
;
2070 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2071 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
2075 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
2077 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
2080 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
2081 return !!(vao
->Enabled
& VERT_BIT_GENERIC(index
));
2082 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
2083 return (array
->Format
.Format
== GL_BGRA
) ? GL_BGRA
: array
->Format
.Size
;
2084 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
2085 return array
->Stride
;
2086 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
2087 return array
->Format
.Type
;
2088 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
2089 return array
->Format
.Normalized
;
2090 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
2091 buf
= vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
;
2092 return buf
? buf
->Name
: 0;
2093 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
2094 if ((_mesa_is_desktop_gl(ctx
)
2095 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
2096 || _mesa_is_gles3(ctx
)) {
2097 return array
->Format
.Integer
;
2100 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
2101 if (_mesa_is_desktop_gl(ctx
)) {
2102 return array
->Format
.Doubles
;
2105 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
2106 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
2107 || _mesa_is_gles3(ctx
)) {
2108 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
2111 case GL_VERTEX_ATTRIB_BINDING
:
2112 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
2113 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
2116 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
2117 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
2118 return array
->RelativeOffset
;
2122 ; /* fall-through */
2126 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
2131 static const GLfloat
*
2132 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
2135 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
2136 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
2140 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2141 _mesa_error(ctx
, GL_INVALID_VALUE
,
2142 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
2146 assert(VERT_ATTRIB_GENERIC(index
) <
2147 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
2149 FLUSH_CURRENT(ctx
, 0);
2150 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
2154 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
2156 GET_CURRENT_CONTEXT(ctx
);
2158 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2159 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
2165 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2167 "glGetVertexAttribfv");
2173 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
2175 GET_CURRENT_CONTEXT(ctx
);
2177 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2178 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
2180 params
[0] = (GLdouble
) v
[0];
2181 params
[1] = (GLdouble
) v
[1];
2182 params
[2] = (GLdouble
) v
[2];
2183 params
[3] = (GLdouble
) v
[3];
2187 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2189 "glGetVertexAttribdv");
2194 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
2196 GET_CURRENT_CONTEXT(ctx
);
2198 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2200 (const GLdouble
*)get_current_attrib(ctx
, index
,
2201 "glGetVertexAttribLdv");
2210 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2212 "glGetVertexAttribLdv");
2217 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
2219 GET_CURRENT_CONTEXT(ctx
);
2221 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2222 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
2224 /* XXX should floats in[0,1] be scaled to full int range? */
2225 params
[0] = (GLint
) v
[0];
2226 params
[1] = (GLint
) v
[1];
2227 params
[2] = (GLint
) v
[2];
2228 params
[3] = (GLint
) v
[3];
2232 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2234 "glGetVertexAttribiv");
2239 _mesa_GetVertexAttribLui64vARB(GLuint index
, GLenum pname
, GLuint64EXT
*params
)
2241 GET_CURRENT_CONTEXT(ctx
);
2243 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2245 (const GLuint64
*)get_current_attrib(ctx
, index
,
2246 "glGetVertexAttribLui64vARB");
2255 params
[0] = (GLuint64
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2257 "glGetVertexAttribLui64vARB");
2264 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
2266 GET_CURRENT_CONTEXT(ctx
);
2268 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2269 const GLint
*v
= (const GLint
*)
2270 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
2276 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2278 "glGetVertexAttribIiv");
2285 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
2287 GET_CURRENT_CONTEXT(ctx
);
2289 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2290 const GLuint
*v
= (const GLuint
*)
2291 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
2297 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2299 "glGetVertexAttribIuiv");
2305 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
2307 GET_CURRENT_CONTEXT(ctx
);
2309 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2310 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
2314 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
2315 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
2319 assert(VERT_ATTRIB_GENERIC(index
) <
2320 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
2322 *pointer
= (GLvoid
*)
2323 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
2327 /** ARB_direct_state_access */
2329 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
2330 GLenum pname
, GLint
*params
)
2332 GET_CURRENT_CONTEXT(ctx
);
2333 struct gl_vertex_array_object
*vao
;
2334 struct gl_buffer_object
*buf
;
2336 /* The ARB_direct_state_access specification says:
2338 * "An INVALID_OPERATION error is generated if <vaobj> is not
2339 * [compatibility profile: zero or] the name of an existing
2340 * vertex array object."
2342 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glGetVertexArrayIndexediv");
2346 /* The ARB_direct_state_access specification says:
2348 * "For GetVertexArrayIndexediv, <pname> must be one of
2349 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
2350 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
2351 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
2352 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
2353 * VERTEX_ATTRIB_RELATIVE_OFFSET."
2357 * "Add GetVertexArrayIndexediv in 'Get Command' for
2358 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
2359 * VERTEX_ATTRIB_BINDING,
2360 * VERTEX_ATTRIB_RELATIVE_OFFSET,
2361 * VERTEX_BINDING_OFFSET, and
2362 * VERTEX_BINDING_STRIDE states"
2364 * The only parameter name common to both lists is
2365 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
2366 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
2367 * pretty clear however that the intent is that it should be possible
2368 * to query all vertex attrib and binding states that can be set with
2372 case GL_VERTEX_BINDING_OFFSET
:
2373 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2375 case GL_VERTEX_BINDING_STRIDE
:
2376 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
2378 case GL_VERTEX_BINDING_DIVISOR
:
2379 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
2381 case GL_VERTEX_BINDING_BUFFER
:
2382 buf
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
;
2383 params
[0] = buf
? buf
->Name
: 0;
2386 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
2387 "glGetVertexArrayIndexediv");
2394 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
2395 GLenum pname
, GLint64
*params
)
2397 GET_CURRENT_CONTEXT(ctx
);
2398 struct gl_vertex_array_object
*vao
;
2400 /* The ARB_direct_state_access specification says:
2402 * "An INVALID_OPERATION error is generated if <vaobj> is not
2403 * [compatibility profile: zero or] the name of an existing
2404 * vertex array object."
2406 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glGetVertexArrayIndexed64iv");
2410 /* The ARB_direct_state_access specification says:
2412 * "For GetVertexArrayIndexed64iv, <pname> must be
2413 * VERTEX_BINDING_OFFSET."
2417 * "An INVALID_ENUM error is generated if <pname> is not one of
2418 * the valid values listed above for the corresponding command."
2420 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
2421 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
2422 "pname != GL_VERTEX_BINDING_OFFSET)");
2426 /* The ARB_direct_state_access specification says:
2428 * "An INVALID_VALUE error is generated if <index> is greater than
2429 * or equal to the value of MAX_VERTEX_ATTRIBS."
2431 * Since the index refers to a buffer binding in this case, the intended
2432 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
2433 * required to be the same, so in practice this doesn't matter.
2435 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
2436 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
2437 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
2438 index
, ctx
->Const
.MaxVertexAttribBindings
);
2442 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2447 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
2448 GLsizei count
, const GLvoid
*ptr
)
2451 _mesa_VertexPointer(size
, type
, stride
, ptr
);
2456 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
2460 _mesa_NormalPointer(type
, stride
, ptr
);
2465 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
2469 _mesa_ColorPointer(size
, type
, stride
, ptr
);
2474 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
2478 _mesa_IndexPointer(type
, stride
, ptr
);
2483 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
2484 GLsizei count
, const GLvoid
*ptr
)
2487 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
2492 _mesa_MultiTexCoordPointerEXT(GLenum texunit
, GLint size
, GLenum type
,
2493 GLsizei stride
, const GLvoid
*ptr
)
2495 GET_CURRENT_CONTEXT(ctx
);
2496 const GLint sizeMin
= 1;
2497 const GLuint unit
= texunit
- GL_TEXTURE0
;
2499 GLenum format
= GL_RGBA
;
2500 const GLbitfield legalTypes
= (SHORT_BIT
| INT_BIT
|
2501 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
2502 UNSIGNED_INT_2_10_10_10_REV_BIT
|
2503 INT_2_10_10_10_REV_BIT
);
2505 if (!validate_array_and_format(ctx
, "glMultiTexCoordPointerEXT",
2506 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
2507 VERT_ATTRIB_TEX(unit
), legalTypes
,
2508 sizeMin
, 4, size
, type
, stride
,
2509 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
2512 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
2513 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
2514 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
2519 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
2522 _mesa_EdgeFlagPointer(stride
, ptr
);
2527 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
2529 GET_CURRENT_CONTEXT(ctx
);
2530 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
2531 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
2532 GLenum ctype
= 0; /* color type */
2533 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
2534 const GLint toffset
= 0; /* always zero */
2535 GLint defstride
; /* default stride */
2538 f
= sizeof(GLfloat
);
2539 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
2542 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
2548 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2549 tcomps
= 0; ccomps
= 0; vcomps
= 2;
2554 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2555 tcomps
= 0; ccomps
= 0; vcomps
= 3;
2560 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2561 tcomps
= 0; ccomps
= 4; vcomps
= 2;
2562 ctype
= GL_UNSIGNED_BYTE
;
2565 defstride
= c
+ 2*f
;
2568 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2569 tcomps
= 0; ccomps
= 4; vcomps
= 3;
2570 ctype
= GL_UNSIGNED_BYTE
;
2573 defstride
= c
+ 3*f
;
2576 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2577 tcomps
= 0; ccomps
= 3; vcomps
= 3;
2584 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
2585 tcomps
= 0; ccomps
= 0; vcomps
= 3;
2590 case GL_C4F_N3F_V3F
:
2591 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2592 tcomps
= 0; ccomps
= 4; vcomps
= 3;
2600 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2601 tcomps
= 2; ccomps
= 0; vcomps
= 3;
2606 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2607 tcomps
= 4; ccomps
= 0; vcomps
= 4;
2611 case GL_T2F_C4UB_V3F
:
2612 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2613 tcomps
= 2; ccomps
= 4; vcomps
= 3;
2614 ctype
= GL_UNSIGNED_BYTE
;
2619 case GL_T2F_C3F_V3F
:
2620 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2621 tcomps
= 2; ccomps
= 3; vcomps
= 3;
2627 case GL_T2F_N3F_V3F
:
2628 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
2629 tcomps
= 2; ccomps
= 0; vcomps
= 3;
2634 case GL_T2F_C4F_N3F_V3F
:
2635 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2636 tcomps
= 2; ccomps
= 4; vcomps
= 3;
2643 case GL_T4F_C4F_N3F_V4F
:
2644 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2645 tcomps
= 4; ccomps
= 4; vcomps
= 4;
2653 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
2661 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
2662 _mesa_DisableClientState( GL_INDEX_ARRAY
);
2663 /* XXX also disable secondary color and generic arrays? */
2667 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
2668 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
2669 (GLubyte
*) pointer
+ toffset
);
2672 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
2677 _mesa_EnableClientState( GL_COLOR_ARRAY
);
2678 _mesa_ColorPointer( ccomps
, ctype
, stride
,
2679 (GLubyte
*) pointer
+ coffset
);
2682 _mesa_DisableClientState( GL_COLOR_ARRAY
);
2688 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
2689 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
2692 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
2696 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
2697 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
2698 (GLubyte
*) pointer
+ voffset
);
2703 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
2705 GET_CURRENT_CONTEXT(ctx
);
2707 if (MESA_VERBOSE
& VERBOSE_API
)
2708 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
2711 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
2715 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
2718 if (ctx
->Array
.LockCount
!= 0) {
2719 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
2723 ctx
->Array
.LockFirst
= first
;
2724 ctx
->Array
.LockCount
= count
;
2729 _mesa_UnlockArraysEXT( void )
2731 GET_CURRENT_CONTEXT(ctx
);
2733 if (MESA_VERBOSE
& VERBOSE_API
)
2734 _mesa_debug(ctx
, "glUnlockArrays\n");
2736 if (ctx
->Array
.LockCount
== 0) {
2737 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
2741 ctx
->Array
.LockFirst
= 0;
2742 ctx
->Array
.LockCount
= 0;
2747 primitive_restart_index(struct gl_context
*ctx
, GLuint index
)
2749 ctx
->Array
.RestartIndex
= index
;
2750 _mesa_update_derived_primitive_restart_state(ctx
);
2755 * GL_NV_primitive_restart and GL 3.1
2758 _mesa_PrimitiveRestartIndex_no_error(GLuint index
)
2760 GET_CURRENT_CONTEXT(ctx
);
2761 primitive_restart_index(ctx
, index
);
2766 _mesa_PrimitiveRestartIndex(GLuint index
)
2768 GET_CURRENT_CONTEXT(ctx
);
2770 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
2771 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
2775 primitive_restart_index(ctx
, index
);
2780 _mesa_VertexAttribDivisor_no_error(GLuint index
, GLuint divisor
)
2782 GET_CURRENT_CONTEXT(ctx
);
2784 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2785 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2787 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2789 /* The ARB_vertex_attrib_binding spec says:
2793 * void VertexAttribDivisor(uint index, uint divisor);
2795 * is equivalent to (assuming no errors are generated):
2797 * VertexAttribBinding(index, index);
2798 * VertexBindingDivisor(index, divisor);"
2800 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2801 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2806 * See GL_ARB_instanced_arrays.
2807 * Note that the instance divisor only applies to generic arrays, not
2808 * the legacy vertex arrays.
2811 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
2813 GET_CURRENT_CONTEXT(ctx
);
2815 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2816 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2818 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2819 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
2823 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2824 _mesa_error(ctx
, GL_INVALID_VALUE
,
2825 "glVertexAttribDivisor(index = %u)", index
);
2829 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2831 /* The ARB_vertex_attrib_binding spec says:
2835 * void VertexAttribDivisor(uint index, uint divisor);
2837 * is equivalent to (assuming no errors are generated):
2839 * VertexAttribBinding(index, index);
2840 * VertexBindingDivisor(index, divisor);"
2842 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2843 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2848 _mesa_VertexArrayVertexAttribDivisorEXT(GLuint vaobj
, GLuint index
, GLuint divisor
)
2850 GET_CURRENT_CONTEXT(ctx
);
2852 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2853 struct gl_vertex_array_object
* vao
;
2854 /* The ARB_instanced_arrays spec says:
2856 * "The vertex array object named by vaobj must
2857 * be generated by GenVertexArrays (and not since deleted);
2858 * otherwise an INVALID_OPERATION error is generated."
2860 vao
= _mesa_lookup_vao_err(ctx
, vaobj
,
2862 "glVertexArrayVertexAttribDivisorEXT");
2866 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2867 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexArrayVertexAttribDivisorEXT()");
2871 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2872 _mesa_error(ctx
, GL_INVALID_VALUE
,
2873 "glVertexArrayVertexAttribDivisorEXT(index = %u)", index
);
2877 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2879 /* The ARB_vertex_attrib_binding spec says:
2883 * void VertexAttribDivisor(uint index, uint divisor);
2885 * is equivalent to (assuming no errors are generated):
2887 * VertexAttribBinding(index, index);
2888 * VertexBindingDivisor(index, divisor);"
2890 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2891 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2896 static ALWAYS_INLINE
void
2897 vertex_array_vertex_buffer(struct gl_context
*ctx
,
2898 struct gl_vertex_array_object
*vao
,
2899 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2900 GLsizei stride
, bool no_error
, const char *func
)
2902 struct gl_buffer_object
*vbo
;
2903 struct gl_buffer_object
*current_buf
=
2904 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
2906 if (current_buf
&& buffer
== current_buf
->Name
) {
2908 } else if (buffer
!= 0) {
2909 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
2911 if (!no_error
&& !vbo
&& _mesa_is_gles31(ctx
)) {
2912 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
2915 /* From the GL_ARB_vertex_attrib_array spec:
2917 * "[Core profile only:]
2918 * An INVALID_OPERATION error is generated if buffer is not zero or a
2919 * name returned from a previous call to GenBuffers, or if such a name
2920 * has since been deleted with DeleteBuffers.
2922 * Otherwise, we fall back to the same compat profile behavior as other
2923 * object references (automatically gen it).
2925 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
2928 /* The ARB_vertex_attrib_binding spec says:
2930 * "If <buffer> is zero, any buffer object attached to this
2931 * bindpoint is detached."
2936 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
2937 vbo
, offset
, stride
);
2942 * GL_ARB_vertex_attrib_binding
2945 vertex_array_vertex_buffer_err(struct gl_context
*ctx
,
2946 struct gl_vertex_array_object
*vao
,
2947 GLuint bindingIndex
, GLuint buffer
,
2948 GLintptr offset
, GLsizei stride
,
2951 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2953 /* The ARB_vertex_attrib_binding spec says:
2955 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2956 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2958 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2959 _mesa_error(ctx
, GL_INVALID_VALUE
,
2960 "%s(bindingindex=%u > "
2961 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2962 func
, bindingIndex
);
2966 /* The ARB_vertex_attrib_binding spec says:
2968 * "The error INVALID_VALUE is generated if <stride> or <offset>
2972 _mesa_error(ctx
, GL_INVALID_VALUE
,
2973 "%s(offset=%" PRId64
" < 0)",
2974 func
, (int64_t) offset
);
2979 _mesa_error(ctx
, GL_INVALID_VALUE
,
2980 "%s(stride=%d < 0)", func
, stride
);
2984 if (((_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
2985 stride
> ctx
->Const
.MaxVertexAttribStride
) {
2986 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
2987 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
2991 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2992 stride
, false, func
);
2997 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex
, GLuint buffer
,
2998 GLintptr offset
, GLsizei stride
)
3000 GET_CURRENT_CONTEXT(ctx
);
3001 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
3002 buffer
, offset
, stride
, true,
3003 "glBindVertexBuffer");
3008 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
3011 GET_CURRENT_CONTEXT(ctx
);
3013 /* The ARB_vertex_attrib_binding spec says:
3015 * "An INVALID_OPERATION error is generated if no vertex array object
3018 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3019 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3020 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3021 "glBindVertexBuffer(No array object bound)");
3025 vertex_array_vertex_buffer_err(ctx
, ctx
->Array
.VAO
, bindingIndex
,
3026 buffer
, offset
, stride
,
3027 "glBindVertexBuffer");
3032 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj
, GLuint bindingIndex
,
3033 GLuint buffer
, GLintptr offset
,
3036 GET_CURRENT_CONTEXT(ctx
);
3038 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3039 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
3040 stride
, true, "glVertexArrayVertexBuffer");
3045 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
3046 GLintptr offset
, GLsizei stride
)
3048 GET_CURRENT_CONTEXT(ctx
);
3049 struct gl_vertex_array_object
*vao
;
3051 /* The ARB_direct_state_access specification says:
3053 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
3054 * if <vaobj> is not [compatibility profile: zero or] the name of an
3055 * existing vertex array object."
3057 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayVertexBuffer");
3061 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
3062 stride
, "glVertexArrayVertexBuffer");
3067 _mesa_VertexArrayBindVertexBufferEXT(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
3068 GLintptr offset
, GLsizei stride
)
3070 GET_CURRENT_CONTEXT(ctx
);
3071 struct gl_vertex_array_object
*vao
;
3072 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, "glVertexArrayBindVertexBufferEXT");
3076 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
3077 stride
, "glVertexArrayBindVertexBufferEXT");
3081 static ALWAYS_INLINE
void
3082 vertex_array_vertex_buffers(struct gl_context
*ctx
,
3083 struct gl_vertex_array_object
*vao
,
3084 GLuint first
, GLsizei count
, const GLuint
*buffers
,
3085 const GLintptr
*offsets
, const GLsizei
*strides
,
3086 bool no_error
, const char *func
)
3092 * The ARB_multi_bind spec says:
3094 * "If <buffers> is NULL, each affected vertex buffer binding point
3095 * from <first> through <first>+<count>-1 will be reset to have no
3096 * bound buffer object. In this case, the offsets and strides
3097 * associated with the binding points are set to default values,
3098 * ignoring <offsets> and <strides>."
3100 for (i
= 0; i
< count
; i
++)
3101 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
3107 /* Note that the error semantics for multi-bind commands differ from
3108 * those of other GL commands.
3110 * The Issues section in the ARB_multi_bind spec says:
3112 * "(11) Typically, OpenGL specifies that if an error is generated by
3113 * a command, that command has no effect. This is somewhat
3114 * unfortunate for multi-bind commands, because it would require
3115 * a first pass to scan the entire list of bound objects for
3116 * errors and then a second pass to actually perform the
3117 * bindings. Should we have different error semantics?
3119 * RESOLVED: Yes. In this specification, when the parameters for
3120 * one of the <count> binding points are invalid, that binding
3121 * point is not updated and an error will be generated. However,
3122 * other binding points in the same command will be updated if
3123 * their parameters are valid and no other error occurs."
3126 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
3128 for (i
= 0; i
< count
; i
++) {
3129 struct gl_buffer_object
*vbo
;
3132 /* The ARB_multi_bind spec says:
3134 * "An INVALID_VALUE error is generated if any value in
3135 * <offsets> or <strides> is negative (per binding)."
3137 if (offsets
[i
] < 0) {
3138 _mesa_error(ctx
, GL_INVALID_VALUE
,
3139 "%s(offsets[%u]=%" PRId64
" < 0)",
3140 func
, i
, (int64_t) offsets
[i
]);
3144 if (strides
[i
] < 0) {
3145 _mesa_error(ctx
, GL_INVALID_VALUE
,
3146 "%s(strides[%u]=%d < 0)",
3147 func
, i
, strides
[i
]);
3151 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
3152 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
3153 _mesa_error(ctx
, GL_INVALID_VALUE
,
3154 "%s(strides[%u]=%d > "
3155 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
3161 struct gl_vertex_buffer_binding
*binding
=
3162 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
3164 if (buffers
[i
] == 0)
3166 else if (binding
->BufferObj
&& binding
->BufferObj
->Name
== buffers
[i
])
3167 vbo
= binding
->BufferObj
;
3170 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
,
3179 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
3180 vbo
, offsets
[i
], strides
[i
]);
3183 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
3188 vertex_array_vertex_buffers_err(struct gl_context
*ctx
,
3189 struct gl_vertex_array_object
*vao
,
3190 GLuint first
, GLsizei count
,
3191 const GLuint
*buffers
, const GLintptr
*offsets
,
3192 const GLsizei
*strides
, const char *func
)
3194 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3196 /* The ARB_multi_bind spec says:
3198 * "An INVALID_OPERATION error is generated if <first> + <count>
3199 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
3201 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
3202 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3203 "%s(first=%u + count=%d > the value of "
3204 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
3205 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
3209 vertex_array_vertex_buffers(ctx
, vao
, first
, count
, buffers
, offsets
,
3210 strides
, false, func
);
3215 _mesa_BindVertexBuffers_no_error(GLuint first
, GLsizei count
,
3216 const GLuint
*buffers
, const GLintptr
*offsets
,
3217 const GLsizei
*strides
)
3219 GET_CURRENT_CONTEXT(ctx
);
3221 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
3222 buffers
, offsets
, strides
, true,
3223 "glBindVertexBuffers");
3228 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
3229 const GLintptr
*offsets
, const GLsizei
*strides
)
3231 GET_CURRENT_CONTEXT(ctx
);
3233 /* The ARB_vertex_attrib_binding spec says:
3235 * "An INVALID_OPERATION error is generated if no
3236 * vertex array object is bound."
3238 if (ctx
->API
== API_OPENGL_CORE
&&
3239 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3240 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3241 "glBindVertexBuffers(No array object bound)");
3245 vertex_array_vertex_buffers_err(ctx
, ctx
->Array
.VAO
, first
, count
,
3246 buffers
, offsets
, strides
,
3247 "glBindVertexBuffers");
3252 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj
, GLuint first
,
3253 GLsizei count
, const GLuint
*buffers
,
3254 const GLintptr
*offsets
,
3255 const GLsizei
*strides
)
3257 GET_CURRENT_CONTEXT(ctx
);
3259 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3260 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
3261 buffers
, offsets
, strides
, true,
3262 "glVertexArrayVertexBuffers");
3267 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
3268 const GLuint
*buffers
,
3269 const GLintptr
*offsets
, const GLsizei
*strides
)
3271 GET_CURRENT_CONTEXT(ctx
);
3272 struct gl_vertex_array_object
*vao
;
3274 /* The ARB_direct_state_access specification says:
3276 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
3277 * if <vaobj> is not [compatibility profile: zero or] the name of an
3278 * existing vertex array object."
3280 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayVertexBuffers");
3284 vertex_array_vertex_buffers_err(ctx
, vao
, first
, count
,
3285 buffers
, offsets
, strides
,
3286 "glVertexArrayVertexBuffers");
3291 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
3292 GLboolean normalized
, GLboolean integer
,
3293 GLboolean doubles
, GLbitfield legalTypes
,
3294 GLsizei sizeMax
, GLuint relativeOffset
,
3297 GET_CURRENT_CONTEXT(ctx
);
3298 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3300 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
3302 if (!_mesa_is_no_error_enabled(ctx
)) {
3303 /* The ARB_vertex_attrib_binding spec says:
3305 * "An INVALID_OPERATION error is generated under any of the
3306 * following conditions:
3307 * - if no vertex array object is currently bound (see section
3311 * This error condition only applies to VertexAttribFormat and
3312 * VertexAttribIFormat in the extension spec, but we assume that this
3313 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
3314 * to all three functions.
3316 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3317 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3318 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3319 "%s(No array object bound)", func
);
3323 /* The ARB_vertex_attrib_binding spec says:
3325 * "The error INVALID_VALUE is generated if index is greater than or
3326 * equal to the value of MAX_VERTEX_ATTRIBS."
3328 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
3329 _mesa_error(ctx
, GL_INVALID_VALUE
,
3330 "%s(attribindex=%u > "
3331 "GL_MAX_VERTEX_ATTRIBS)",
3336 if (!validate_array_format(ctx
, func
, ctx
->Array
.VAO
,
3337 VERT_ATTRIB_GENERIC(attribIndex
),
3338 legalTypes
, 1, sizeMax
, size
, type
,
3339 normalized
, integer
, doubles
, relativeOffset
,
3345 _mesa_update_array_format(ctx
, ctx
->Array
.VAO
,
3346 VERT_ATTRIB_GENERIC(attribIndex
), size
, type
,
3347 format
, normalized
, integer
, doubles
,
3353 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3354 GLboolean normalized
, GLuint relativeOffset
)
3356 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
3357 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
3358 BGRA_OR_4
, relativeOffset
,
3359 "glVertexAttribFormat");
3364 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3365 GLuint relativeOffset
)
3367 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
3368 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
3369 relativeOffset
, "glVertexAttribIFormat");
3374 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3375 GLuint relativeOffset
)
3377 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
3378 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
3379 relativeOffset
, "glVertexAttribLFormat");
3384 vertex_array_attrib_format(GLuint vaobj
, bool isExtDsa
, GLuint attribIndex
,
3385 GLint size
, GLenum type
, GLboolean normalized
,
3386 GLboolean integer
, GLboolean doubles
,
3387 GLbitfield legalTypes
, GLsizei sizeMax
,
3388 GLuint relativeOffset
, const char *func
)
3390 GET_CURRENT_CONTEXT(ctx
);
3391 struct gl_vertex_array_object
*vao
;
3393 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3395 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
3397 if (_mesa_is_no_error_enabled(ctx
)) {
3398 vao
= _mesa_lookup_vao(ctx
, vaobj
);
3402 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, isExtDsa
, func
);
3406 /* The ARB_vertex_attrib_binding spec says:
3408 * "The error INVALID_VALUE is generated if index is greater than or
3409 * equal to the value of MAX_VERTEX_ATTRIBS."
3411 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
3412 _mesa_error(ctx
, GL_INVALID_VALUE
,
3413 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
3418 if (!validate_array_format(ctx
, func
, vao
,
3419 VERT_ATTRIB_GENERIC(attribIndex
),
3420 legalTypes
, 1, sizeMax
, size
, type
,
3421 normalized
, integer
, doubles
, relativeOffset
,
3427 _mesa_update_array_format(ctx
, vao
, VERT_ATTRIB_GENERIC(attribIndex
), size
,
3428 type
, format
, normalized
, integer
, doubles
,
3434 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
3435 GLenum type
, GLboolean normalized
,
3436 GLuint relativeOffset
)
3438 vertex_array_attrib_format(vaobj
, false, attribIndex
, size
, type
, normalized
,
3439 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
3440 BGRA_OR_4
, relativeOffset
,
3441 "glVertexArrayAttribFormat");
3446 _mesa_VertexArrayVertexAttribFormatEXT(GLuint vaobj
, GLuint attribIndex
, GLint size
,
3447 GLenum type
, GLboolean normalized
,
3448 GLuint relativeOffset
)
3450 vertex_array_attrib_format(vaobj
, true, attribIndex
, size
, type
, normalized
,
3451 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
3452 BGRA_OR_4
, relativeOffset
,
3453 "glVertexArrayVertexAttribFormatEXT");
3458 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
3459 GLint size
, GLenum type
,
3460 GLuint relativeOffset
)
3462 vertex_array_attrib_format(vaobj
, false, attribIndex
, size
, type
, GL_FALSE
,
3463 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
3465 "glVertexArrayAttribIFormat");
3470 _mesa_VertexArrayVertexAttribIFormatEXT(GLuint vaobj
, GLuint attribIndex
,
3471 GLint size
, GLenum type
,
3472 GLuint relativeOffset
)
3474 vertex_array_attrib_format(vaobj
, true, attribIndex
, size
, type
, GL_FALSE
,
3475 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
3477 "glVertexArrayVertexAttribIFormatEXT");
3482 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
3483 GLint size
, GLenum type
,
3484 GLuint relativeOffset
)
3486 vertex_array_attrib_format(vaobj
, false, attribIndex
, size
, type
, GL_FALSE
,
3487 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
3489 "glVertexArrayAttribLFormat");
3494 _mesa_VertexArrayVertexAttribLFormatEXT(GLuint vaobj
, GLuint attribIndex
,
3495 GLint size
, GLenum type
,
3496 GLuint relativeOffset
)
3498 vertex_array_attrib_format(vaobj
, true, attribIndex
, size
, type
, GL_FALSE
,
3499 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
3501 "glVertexArrayVertexAttribLFormatEXT");
3506 vertex_array_attrib_binding(struct gl_context
*ctx
,
3507 struct gl_vertex_array_object
*vao
,
3508 GLuint attribIndex
, GLuint bindingIndex
,
3511 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3513 /* The ARB_vertex_attrib_binding spec says:
3515 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
3516 * <bindingindex> must be less than the value of
3517 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
3520 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
3521 _mesa_error(ctx
, GL_INVALID_VALUE
,
3522 "%s(attribindex=%u >= "
3523 "GL_MAX_VERTEX_ATTRIBS)",
3528 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
3529 _mesa_error(ctx
, GL_INVALID_VALUE
,
3530 "%s(bindingindex=%u >= "
3531 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
3532 func
, bindingIndex
);
3536 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
3538 _mesa_vertex_attrib_binding(ctx
, vao
,
3539 VERT_ATTRIB_GENERIC(attribIndex
),
3540 VERT_ATTRIB_GENERIC(bindingIndex
));
3545 _mesa_VertexAttribBinding_no_error(GLuint attribIndex
, GLuint bindingIndex
)
3547 GET_CURRENT_CONTEXT(ctx
);
3548 _mesa_vertex_attrib_binding(ctx
, ctx
->Array
.VAO
,
3549 VERT_ATTRIB_GENERIC(attribIndex
),
3550 VERT_ATTRIB_GENERIC(bindingIndex
));
3555 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
3557 GET_CURRENT_CONTEXT(ctx
);
3559 /* The ARB_vertex_attrib_binding spec says:
3561 * "An INVALID_OPERATION error is generated if no vertex array object
3564 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3565 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3566 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3567 "glVertexAttribBinding(No array object bound)");
3571 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
3572 attribIndex
, bindingIndex
,
3573 "glVertexAttribBinding");
3578 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj
, GLuint attribIndex
,
3579 GLuint bindingIndex
)
3581 GET_CURRENT_CONTEXT(ctx
);
3583 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3584 _mesa_vertex_attrib_binding(ctx
, vao
,
3585 VERT_ATTRIB_GENERIC(attribIndex
),
3586 VERT_ATTRIB_GENERIC(bindingIndex
));
3591 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
3593 GET_CURRENT_CONTEXT(ctx
);
3594 struct gl_vertex_array_object
*vao
;
3596 /* The ARB_direct_state_access specification says:
3598 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
3599 * if <vaobj> is not [compatibility profile: zero or] the name of an
3600 * existing vertex array object."
3602 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayAttribBinding");
3606 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
3607 "glVertexArrayAttribBinding");
3612 _mesa_VertexArrayVertexAttribBindingEXT(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
3614 GET_CURRENT_CONTEXT(ctx
);
3615 struct gl_vertex_array_object
*vao
;
3616 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, "glVertexArrayVertexAttribBindingEXT");
3620 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
3621 "glVertexArrayVertexAttribBindingEXT");
3626 vertex_array_binding_divisor(struct gl_context
*ctx
,
3627 struct gl_vertex_array_object
*vao
,
3628 GLuint bindingIndex
, GLuint divisor
,
3631 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3633 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
3634 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
3638 /* The ARB_vertex_attrib_binding spec says:
3640 * "An INVALID_VALUE error is generated if <bindingindex> is greater
3641 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
3643 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
3644 _mesa_error(ctx
, GL_INVALID_VALUE
,
3645 "%s(bindingindex=%u > "
3646 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
3647 func
, bindingIndex
);
3651 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3656 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex
, GLuint divisor
)
3658 GET_CURRENT_CONTEXT(ctx
);
3659 vertex_binding_divisor(ctx
, ctx
->Array
.VAO
,
3660 VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3665 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
3667 GET_CURRENT_CONTEXT(ctx
);
3669 /* The ARB_vertex_attrib_binding spec says:
3671 * "An INVALID_OPERATION error is generated if no vertex array object
3674 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3675 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3676 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3677 "glVertexBindingDivisor(No array object bound)");
3681 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
3682 bindingIndex
, divisor
,
3683 "glVertexBindingDivisor");
3688 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj
, GLuint bindingIndex
,
3691 GET_CURRENT_CONTEXT(ctx
);
3693 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3694 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3699 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
3702 struct gl_vertex_array_object
*vao
;
3703 GET_CURRENT_CONTEXT(ctx
);
3705 /* The ARB_direct_state_access specification says:
3707 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
3708 * if <vaobj> is not [compatibility profile: zero or] the name of an
3709 * existing vertex array object."
3711 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayBindingDivisor");
3715 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
3716 "glVertexArrayBindingDivisor");
3721 _mesa_VertexArrayVertexBindingDivisorEXT(GLuint vaobj
, GLuint bindingIndex
,
3724 struct gl_vertex_array_object
*vao
;
3725 GET_CURRENT_CONTEXT(ctx
);
3727 /* The ARB_direct_state_access specification says:
3729 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
3730 * if <vaobj> is not [compatibility profile: zero or] the name of an
3731 * existing vertex array object."
3733 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, "glVertexArrayVertexBindingDivisorEXT");
3737 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
3738 "glVertexArrayVertexBindingDivisorEXT");
3743 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
3744 struct gl_array_attributes
*dst
,
3745 const struct gl_array_attributes
*src
)
3747 dst
->Ptr
= src
->Ptr
;
3748 dst
->RelativeOffset
= src
->RelativeOffset
;
3749 dst
->Format
= src
->Format
;
3750 dst
->Stride
= src
->Stride
;
3751 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
3752 dst
->_EffBufferBindingIndex
= src
->_EffBufferBindingIndex
;
3753 dst
->_EffRelativeOffset
= src
->_EffRelativeOffset
;
3757 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
3758 struct gl_vertex_buffer_binding
*dst
,
3759 const struct gl_vertex_buffer_binding
*src
)
3761 dst
->Offset
= src
->Offset
;
3762 dst
->Stride
= src
->Stride
;
3763 dst
->InstanceDivisor
= src
->InstanceDivisor
;
3764 dst
->_BoundArrays
= src
->_BoundArrays
;
3765 dst
->_EffBoundArrays
= src
->_EffBoundArrays
;
3766 dst
->_EffOffset
= src
->_EffOffset
;
3768 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
3772 * Print current vertex object/array info. For debug.
3775 _mesa_print_arrays(struct gl_context
*ctx
)
3777 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
3779 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
3781 GLbitfield mask
= vao
->Enabled
;
3783 const gl_vert_attrib i
= u_bit_scan(&mask
);
3784 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
3786 const struct gl_vertex_buffer_binding
*binding
=
3787 &vao
->BufferBinding
[array
->BufferBindingIndex
];
3788 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
3790 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
3791 "Stride=%d, Buffer=%u(Size %lu)\n",
3792 gl_vert_attrib_name((gl_vert_attrib
)i
),
3793 array
->Ptr
, _mesa_enum_to_string(array
->Format
.Type
),
3795 array
->Format
._ElementSize
, binding
->Stride
, bo
? bo
->Name
: 0,
3796 (unsigned long) bo
? bo
->Size
: 0);
3801 * Initialize attributes of a vertex array within a vertex array object.
3802 * \param vao the container vertex array object
3803 * \param index which array in the VAO to initialize
3804 * \param size number of components (1, 2, 3 or 4) per attribute
3805 * \param type datatype of the attribute (GL_FLOAT, GL_INT, etc).
3808 init_array(struct gl_context
*ctx
,
3809 struct gl_vertex_array_object
*vao
,
3810 gl_vert_attrib index
, GLint size
, GLint type
)
3812 assert(index
< ARRAY_SIZE(vao
->VertexAttrib
));
3813 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[index
];
3814 assert(index
< ARRAY_SIZE(vao
->BufferBinding
));
3815 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
3817 _mesa_set_vertex_format(&array
->Format
, size
, type
, GL_RGBA
,
3818 GL_FALSE
, GL_FALSE
, GL_FALSE
);
3821 array
->RelativeOffset
= 0;
3822 ASSERT_BITFIELD_SIZE(struct gl_array_attributes
, BufferBindingIndex
,
3823 VERT_ATTRIB_MAX
- 1);
3824 array
->BufferBindingIndex
= index
;
3826 binding
->Offset
= 0;
3827 binding
->Stride
= array
->Format
._ElementSize
;
3828 binding
->BufferObj
= NULL
;
3829 binding
->_BoundArrays
= BITFIELD_BIT(index
);
3833 init_default_vao_state(struct gl_context
*ctx
)
3835 struct gl_vertex_array_object
*vao
= &ctx
->Array
.DefaultVAOState
;
3838 vao
->SharedAndImmutable
= false;
3840 /* Init the individual arrays */
3841 for (unsigned i
= 0; i
< ARRAY_SIZE(vao
->VertexAttrib
); i
++) {
3843 case VERT_ATTRIB_NORMAL
:
3844 init_array(ctx
, vao
, VERT_ATTRIB_NORMAL
, 3, GL_FLOAT
);
3846 case VERT_ATTRIB_COLOR1
:
3847 init_array(ctx
, vao
, VERT_ATTRIB_COLOR1
, 3, GL_FLOAT
);
3849 case VERT_ATTRIB_FOG
:
3850 init_array(ctx
, vao
, VERT_ATTRIB_FOG
, 1, GL_FLOAT
);
3852 case VERT_ATTRIB_COLOR_INDEX
:
3853 init_array(ctx
, vao
, VERT_ATTRIB_COLOR_INDEX
, 1, GL_FLOAT
);
3855 case VERT_ATTRIB_EDGEFLAG
:
3856 init_array(ctx
, vao
, VERT_ATTRIB_EDGEFLAG
, 1, GL_UNSIGNED_BYTE
);
3858 case VERT_ATTRIB_POINT_SIZE
:
3859 init_array(ctx
, vao
, VERT_ATTRIB_POINT_SIZE
, 1, GL_FLOAT
);
3862 init_array(ctx
, vao
, i
, 4, GL_FLOAT
);
3867 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_IDENTITY
;
3871 * Initialize vertex array state for given context.
3874 _mesa_init_varray(struct gl_context
*ctx
)
3876 init_default_vao_state(ctx
);
3878 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
3879 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
3880 ctx
->Array
._EmptyVAO
= _mesa_new_vao(ctx
, ~0u);
3881 _mesa_reference_vao(ctx
, &ctx
->Array
._DrawVAO
, ctx
->Array
._EmptyVAO
);
3882 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
3884 ctx
->Array
.Objects
= _mesa_NewHashTable();
3889 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
3892 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
3894 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
3895 struct gl_context
*ctx
= (struct gl_context
*) userData
;
3896 _mesa_delete_vao(ctx
, vao
);
3901 * Free vertex array state for given context.
3904 _mesa_free_varray_data(struct gl_context
*ctx
)
3906 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
3907 _mesa_DeleteHashTable(ctx
->Array
.Objects
);
3911 _mesa_GetVertexArrayIntegervEXT(GLuint vaobj
, GLenum pname
, GLint
*param
)
3913 GET_CURRENT_CONTEXT(ctx
);
3914 struct gl_vertex_array_object
* vao
;
3915 struct gl_buffer_object
*buf
;
3918 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
3919 "glGetVertexArrayIntegervEXT");
3923 /* The EXT_direct_state_access spec says:
3925 * "For GetVertexArrayIntegervEXT, pname must be one of the "Get value" tokens
3926 * in tables 6.6, 6.7, 6.8, and 6.9 that use GetIntegerv, IsEnabled, or
3927 * GetPointerv for their "Get command" (so excluding the VERTEX_ATTRIB_*
3931 /* Tokens using GetIntegerv */
3932 case GL_CLIENT_ACTIVE_TEXTURE
:
3933 *param
= GL_TEXTURE0_ARB
+ ctx
->Array
.ActiveTexture
;
3935 case GL_VERTEX_ARRAY_SIZE
:
3936 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Format
.Size
;
3938 case GL_VERTEX_ARRAY_TYPE
:
3939 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Format
.Type
;
3941 case GL_VERTEX_ARRAY_STRIDE
:
3942 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Stride
;
3944 case GL_VERTEX_ARRAY_BUFFER_BINDING
:
3945 buf
= vao
->BufferBinding
[VERT_ATTRIB_POS
].BufferObj
;
3946 *param
= buf
? buf
->Name
: 0;
3948 case GL_COLOR_ARRAY_SIZE
:
3949 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Format
.Size
;
3951 case GL_COLOR_ARRAY_TYPE
:
3952 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Format
.Type
;
3954 case GL_COLOR_ARRAY_STRIDE
:
3955 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Stride
;
3957 case GL_COLOR_ARRAY_BUFFER_BINDING
:
3958 buf
= vao
->BufferBinding
[VERT_ATTRIB_COLOR0
].BufferObj
;
3959 *param
= buf
? buf
->Name
: 0;
3961 case GL_EDGE_FLAG_ARRAY_STRIDE
:
3962 *param
= vao
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Stride
;
3964 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING
:
3965 buf
= vao
->BufferBinding
[VERT_ATTRIB_EDGEFLAG
].BufferObj
;
3966 *param
= buf
? buf
->Name
: 0;
3968 case GL_INDEX_ARRAY_TYPE
:
3969 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Format
.Type
;
3971 case GL_INDEX_ARRAY_STRIDE
:
3972 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Stride
;
3974 case GL_INDEX_ARRAY_BUFFER_BINDING
:
3975 buf
= vao
->BufferBinding
[VERT_ATTRIB_COLOR_INDEX
].BufferObj
;
3976 *param
= buf
? buf
->Name
: 0;
3978 case GL_NORMAL_ARRAY_TYPE
:
3979 *param
= vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Format
.Type
;
3981 case GL_NORMAL_ARRAY_STRIDE
:
3982 *param
= vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Stride
;
3984 case GL_NORMAL_ARRAY_BUFFER_BINDING
:
3985 buf
= vao
->BufferBinding
[VERT_ATTRIB_NORMAL
].BufferObj
;
3986 *param
= buf
? buf
->Name
: 0;
3988 case GL_TEXTURE_COORD_ARRAY_SIZE
:
3989 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Format
.Size
;
3991 case GL_TEXTURE_COORD_ARRAY_TYPE
:
3992 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Format
.Type
;
3994 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
3995 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Stride
;
3997 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING
:
3998 buf
= vao
->BufferBinding
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].BufferObj
;
3999 *param
= buf
? buf
->Name
: 0;
4001 case GL_FOG_COORD_ARRAY_TYPE
:
4002 *param
= vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Format
.Type
;
4004 case GL_FOG_COORD_ARRAY_STRIDE
:
4005 *param
= vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Stride
;
4007 case GL_FOG_COORD_ARRAY_BUFFER_BINDING
:
4008 buf
= vao
->BufferBinding
[VERT_ATTRIB_FOG
].BufferObj
;
4009 *param
= buf
? buf
->Name
: 0;
4011 case GL_SECONDARY_COLOR_ARRAY_SIZE
:
4012 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Format
.Size
;
4014 case GL_SECONDARY_COLOR_ARRAY_TYPE
:
4015 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Format
.Type
;
4017 case GL_SECONDARY_COLOR_ARRAY_STRIDE
:
4018 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Stride
;
4020 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING
:
4021 buf
= vao
->BufferBinding
[VERT_ATTRIB_COLOR1
].BufferObj
;
4022 *param
= buf
? buf
->Name
: 0;
4025 /* Tokens using IsEnabled */
4026 case GL_VERTEX_ARRAY
:
4027 *param
= !!(vao
->Enabled
& VERT_BIT_POS
);
4029 case GL_COLOR_ARRAY
:
4030 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR0
);
4032 case GL_EDGE_FLAG_ARRAY
:
4033 *param
= !!(vao
->Enabled
& VERT_BIT_EDGEFLAG
);
4035 case GL_INDEX_ARRAY
:
4036 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR_INDEX
);
4038 case GL_NORMAL_ARRAY
:
4039 *param
= !!(vao
->Enabled
& VERT_BIT_NORMAL
);
4041 case GL_TEXTURE_COORD_ARRAY
:
4042 *param
= !!(vao
->Enabled
& VERT_BIT_TEX(ctx
->Array
.ActiveTexture
));
4044 case GL_FOG_COORD_ARRAY
:
4045 *param
= !!(vao
->Enabled
& VERT_BIT_FOG
);
4047 case GL_SECONDARY_COLOR_ARRAY
:
4048 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR1
);
4051 /* Tokens using GetPointerv */
4052 case GL_VERTEX_ARRAY_POINTER
:
4053 case GL_COLOR_ARRAY_POINTER
:
4054 case GL_EDGE_FLAG_ARRAY_POINTER
:
4055 case GL_INDEX_ARRAY_POINTER
:
4056 case GL_NORMAL_ARRAY_POINTER
:
4057 case GL_TEXTURE_COORD_ARRAY_POINTER
:
4058 case GL_FOG_COORD_ARRAY_POINTER
:
4059 case GL_SECONDARY_COLOR_ARRAY_POINTER
:
4060 _get_vao_pointerv(pname
, vao
, &ptr
, "glGetVertexArrayIntegervEXT");
4061 *param
= (int) ((intptr_t) ptr
& 0xFFFFFFFF);
4065 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIntegervEXT(pname)");
4070 _mesa_GetVertexArrayPointervEXT(GLuint vaobj
, GLenum pname
, GLvoid
** param
)
4072 GET_CURRENT_CONTEXT(ctx
);
4073 struct gl_vertex_array_object
* vao
;
4075 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
4076 "glGetVertexArrayPointervEXT");
4080 /* The EXT_direct_state_access spec says:
4082 * "For GetVertexArrayPointervEXT, pname must be a *_ARRAY_POINTER token from
4083 * tables 6.6, 6.7, and 6.8 excluding VERTEX_ATTRIB_ARRAY_POINT."
4086 case GL_VERTEX_ARRAY_POINTER
:
4087 case GL_COLOR_ARRAY_POINTER
:
4088 case GL_EDGE_FLAG_ARRAY_POINTER
:
4089 case GL_INDEX_ARRAY_POINTER
:
4090 case GL_NORMAL_ARRAY_POINTER
:
4091 case GL_TEXTURE_COORD_ARRAY_POINTER
:
4092 case GL_FOG_COORD_ARRAY_POINTER
:
4093 case GL_SECONDARY_COLOR_ARRAY_POINTER
:
4097 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayPointervEXT(pname)");
4101 /* pname has been validated, we can now use the helper function */
4102 _get_vao_pointerv(pname
, vao
, param
, "glGetVertexArrayPointervEXT");
4106 _mesa_GetVertexArrayIntegeri_vEXT(GLuint vaobj
, GLuint index
, GLenum pname
, GLint
*param
)
4108 GET_CURRENT_CONTEXT(ctx
);
4109 struct gl_vertex_array_object
* vao
;
4110 struct gl_buffer_object
*buf
;
4112 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
4113 "glGetVertexArrayIntegeri_vEXT");
4118 /* The EXT_direct_state_access spec says:
4120 * "For GetVertexArrayIntegeri_vEXT, pname must be one of the
4121 * "Get value" tokens in tables 6.8 and 6.9 that use GetVertexAttribiv
4122 * or GetVertexAttribPointerv (so allowing only the VERTEX_ATTRIB_*
4123 * tokens) or a token of the form TEXTURE_COORD_ARRAY (the enable) or
4124 * TEXTURE_COORD_ARRAY_*; index identifies the vertex attribute
4125 * array to query or texture coordinate set index respectively."
4129 case GL_TEXTURE_COORD_ARRAY
:
4130 *param
= !!(vao
->Enabled
& VERT_BIT_TEX(index
));
4132 case GL_TEXTURE_COORD_ARRAY_SIZE
:
4133 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Format
.Size
;
4135 case GL_TEXTURE_COORD_ARRAY_TYPE
:
4136 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Format
.Type
;
4138 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
4139 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Stride
;
4141 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING
:
4142 buf
= vao
->BufferBinding
[VERT_ATTRIB_TEX(index
)].BufferObj
;
4143 *param
= buf
? buf
->Name
: 0;
4146 *param
= get_vertex_array_attrib(ctx
, vao
, index
, pname
, "glGetVertexArrayIntegeri_vEXT");
4151 _mesa_GetVertexArrayPointeri_vEXT(GLuint vaobj
, GLuint index
, GLenum pname
, GLvoid
** param
)
4153 GET_CURRENT_CONTEXT(ctx
);
4154 struct gl_vertex_array_object
* vao
;
4156 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
4157 "glGetVertexArrayPointeri_vEXT");
4161 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
4162 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayPointeri_vEXT(index)");
4166 /* The EXT_direct_state_access spec says:
4168 * "For GetVertexArrayPointeri_vEXT, pname must be VERTEX_ATTRIB_ARRAY_POINTER
4169 * or TEXTURE_COORD_ARRAY_POINTER with the index parameter indicating the vertex
4170 * attribute or texture coordindate set index."
4173 case GL_VERTEX_ATTRIB_ARRAY_POINTER
:
4174 *param
= (GLvoid
*) vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
4176 case GL_TEXTURE_COORD_ARRAY_POINTER
:
4177 *param
= (GLvoid
*) vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Ptr
;
4180 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayPointeri_vEXT(pname)");