2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 #include <inttypes.h> /* for PRId64 macro */
32 #include "bufferobj.h"
36 #include "glformats.h"
44 #include "main/dispatch.h"
47 /** Used to do error checking for GL_EXT_vertex_array_bgra */
51 /** Used to indicate which GL datatypes are accepted by each of the
52 * glVertex/Color/Attrib/EtcPointer() functions.
54 #define BOOL_BIT (1 << 0)
55 #define BYTE_BIT (1 << 1)
56 #define UNSIGNED_BYTE_BIT (1 << 2)
57 #define SHORT_BIT (1 << 3)
58 #define UNSIGNED_SHORT_BIT (1 << 4)
59 #define INT_BIT (1 << 5)
60 #define UNSIGNED_INT_BIT (1 << 6)
61 #define HALF_BIT (1 << 7)
62 #define FLOAT_BIT (1 << 8)
63 #define DOUBLE_BIT (1 << 9)
64 #define FIXED_ES_BIT (1 << 10)
65 #define FIXED_GL_BIT (1 << 11)
66 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
67 #define INT_2_10_10_10_REV_BIT (1 << 13)
68 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
69 #define ALL_TYPE_BITS ((1 << 15) - 1)
71 #define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
72 SHORT_BIT | UNSIGNED_SHORT_BIT | \
73 INT_BIT | UNSIGNED_INT_BIT | \
74 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
76 UNSIGNED_INT_2_10_10_10_REV_BIT | \
77 INT_2_10_10_10_REV_BIT | \
78 UNSIGNED_INT_10F_11F_11F_REV_BIT)
80 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
81 SHORT_BIT | UNSIGNED_SHORT_BIT | \
82 INT_BIT | UNSIGNED_INT_BIT)
84 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
87 /** Convert GL datatype enum into a <type>_BIT value seen above */
89 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
96 case GL_UNSIGNED_BYTE
:
97 return UNSIGNED_BYTE_BIT
;
100 case GL_UNSIGNED_SHORT
:
101 return UNSIGNED_SHORT_BIT
;
104 case GL_UNSIGNED_INT
:
105 return UNSIGNED_INT_BIT
;
107 case GL_HALF_FLOAT_OES
:
108 if (ctx
->Extensions
.ARB_half_float_vertex
)
117 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
118 case GL_UNSIGNED_INT_2_10_10_10_REV
:
119 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
120 case GL_INT_2_10_10_10_REV
:
121 return INT_2_10_10_10_REV_BIT
;
122 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
123 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
131 * Depending on the position and generic0 attributes enable flags select
132 * the one that is used for both attributes.
133 * The generic0 attribute takes precedence.
136 update_attribute_map_mode(const struct gl_context
*ctx
,
137 struct gl_vertex_array_object
*vao
)
140 * There is no need to change the mapping away from the
141 * identity mapping if we are not in compat mode.
143 if (ctx
->API
!= API_OPENGL_COMPAT
)
145 /* The generic0 attribute superseeds the position attribute */
146 const GLbitfield enabled
= vao
->Enabled
;
147 if (enabled
& VERT_BIT_GENERIC0
)
148 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_GENERIC0
;
149 else if (enabled
& VERT_BIT_POS
)
150 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_POSITION
;
152 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_IDENTITY
;
157 * Sets the BufferBindingIndex field for the vertex attribute given by
161 _mesa_vertex_attrib_binding(struct gl_context
*ctx
,
162 struct gl_vertex_array_object
*vao
,
163 gl_vert_attrib attribIndex
,
166 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attribIndex
];
167 assert(!vao
->SharedAndImmutable
);
169 if (array
->BufferBindingIndex
!= bindingIndex
) {
170 const GLbitfield array_bit
= VERT_BIT(attribIndex
);
172 if (vao
->BufferBinding
[bindingIndex
].BufferObj
)
173 vao
->VertexAttribBufferMask
|= array_bit
;
175 vao
->VertexAttribBufferMask
&= ~array_bit
;
177 if (vao
->BufferBinding
[bindingIndex
].InstanceDivisor
)
178 vao
->NonZeroDivisorMask
|= array_bit
;
180 vao
->NonZeroDivisorMask
&= ~array_bit
;
182 vao
->BufferBinding
[array
->BufferBindingIndex
]._BoundArrays
&= ~array_bit
;
183 vao
->BufferBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
185 array
->BufferBindingIndex
= bindingIndex
;
187 vao
->NewArrays
|= vao
->Enabled
& array_bit
;
193 * Binds a buffer object to the vertex buffer binding point given by index,
194 * and sets the Offset and Stride fields.
197 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
198 struct gl_vertex_array_object
*vao
,
200 struct gl_buffer_object
*vbo
,
201 GLintptr offset
, GLsizei stride
)
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
];
630 struct gl_vertex_format new_format
;
632 assert(!vao
->SharedAndImmutable
);
635 _mesa_set_vertex_format(&new_format
, size
, type
, format
,
636 normalized
, integer
, doubles
);
638 if ((array
->RelativeOffset
== relativeOffset
) &&
639 !memcmp(&new_format
, &array
->Format
, sizeof(new_format
)))
642 array
->RelativeOffset
= relativeOffset
;
643 array
->Format
= new_format
;
645 vao
->NewArrays
|= vao
->Enabled
& VERT_BIT(attrib
);
649 * Does error checking of the format in an attrib array.
651 * Called by *Pointer() and VertexAttrib*Format().
653 * \param func Name of calling function used for error reporting
654 * \param attrib The index of the attribute array
655 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
656 * \param sizeMin Min allowable size value
657 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
658 * \param size Components per element (1, 2, 3 or 4)
659 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
660 * \param normalized Whether integer types are converted to floats in [-1, 1]
661 * \param integer Integer-valued values (will not be normalized to [-1, 1])
662 * \param doubles Double values not reduced to floats
663 * \param relativeOffset Offset of the first element relative to the binding offset.
664 * \return bool True if validation is successful, False otherwise.
667 validate_array_format(struct gl_context
*ctx
, const char *func
,
668 struct gl_vertex_array_object
*vao
,
669 GLuint attrib
, GLbitfield legalTypesMask
,
670 GLint sizeMin
, GLint sizeMax
,
671 GLint size
, GLenum type
, GLboolean normalized
,
672 GLboolean integer
, GLboolean doubles
,
673 GLuint relativeOffset
, GLenum format
)
677 /* at most, one of these bools can be true */
678 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
680 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
681 /* Compute the LegalTypesMask only once, unless the context API has
682 * changed, in which case we want to compute it again. We can't do this
683 * in _mesa_init_varrays() below because extensions are not yet enabled
686 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
687 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
690 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
692 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
693 /* BGRA ordering is not supported in ES contexts.
698 typeBit
= type_to_bit(ctx
, type
);
699 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
700 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
701 func
, _mesa_enum_to_string(type
));
705 if (format
== GL_BGRA
) {
706 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
708 * "An INVALID_OPERATION error is generated under any of the following
711 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
712 * or UNSIGNED_INT_2_10_10_10_REV;
714 * • size is BGRA and normalized is FALSE;"
716 bool bgra_error
= false;
718 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
719 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
720 type
!= GL_INT_2_10_10_10_REV
&&
721 type
!= GL_UNSIGNED_BYTE
)
723 } else if (type
!= GL_UNSIGNED_BYTE
)
727 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
728 func
, _mesa_enum_to_string(type
));
733 _mesa_error(ctx
, GL_INVALID_OPERATION
,
734 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
738 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
739 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
743 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
744 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
745 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
746 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
750 /* The ARB_vertex_attrib_binding_spec says:
752 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
753 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
755 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
756 _mesa_error(ctx
, GL_INVALID_VALUE
,
757 "%s(relativeOffset=%d > "
758 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
759 func
, relativeOffset
);
763 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
764 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
765 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
773 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
775 * \param func name of calling function used for error reporting
776 * \param vao the vao to update
777 * \param obj the bound buffer object
778 * \param attrib the attribute array index to update
779 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
780 * \param sizeMin min allowable size value
781 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
782 * \param size components per element (1, 2, 3 or 4)
783 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
784 * \param stride stride between elements, in elements
785 * \param normalized are integer types converted to floats in [-1, 1]?
786 * \param integer integer-valued values (will not be normalized to [-1,1])
787 * \param doubles Double values not reduced to floats
788 * \param ptr the address (or offset inside VBO) of the array data
791 validate_array(struct gl_context
*ctx
, const char *func
,
792 struct gl_vertex_array_object
*vao
,
793 struct gl_buffer_object
*obj
,
794 GLuint attrib
, GLbitfield legalTypesMask
,
795 GLint sizeMin
, GLint sizeMax
,
796 GLint size
, GLenum type
, GLsizei stride
,
797 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
800 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
802 * "Client vertex arrays - all vertex array attribute pointers must
803 * refer to buffer objects (section 2.9.2). The default vertex array
804 * object (the name zero) is also deprecated. Calling
805 * VertexAttribPointer when no buffer object or no vertex array object
806 * is bound will generate an INVALID_OPERATION error..."
808 * The check for VBOs is handled below.
810 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
811 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
817 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
821 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
822 stride
> ctx
->Const
.MaxVertexAttribStride
) {
823 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
824 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
828 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
830 * "An INVALID_OPERATION error is generated under any of the following
835 * * any of the *Pointer commands specifying the location and
836 * organization of vertex array data are called while zero is bound
837 * to the ARRAY_BUFFER buffer object binding point (see section
838 * 2.9.6), and the pointer argument is not NULL."
840 if (ptr
!= NULL
&& vao
!= ctx
->Array
.DefaultVAO
&&
842 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
849 validate_array_and_format(struct gl_context
*ctx
, const char *func
,
850 struct gl_vertex_array_object
*vao
,
851 struct gl_buffer_object
*obj
,
852 GLuint attrib
, GLbitfield legalTypes
,
853 GLint sizeMin
, GLint sizeMax
,
854 GLint size
, GLenum type
, GLsizei stride
,
855 GLboolean normalized
, GLboolean integer
,
856 GLboolean doubles
, GLenum format
, const GLvoid
*ptr
)
858 validate_array(ctx
, func
, vao
, obj
, attrib
, legalTypes
, sizeMin
, sizeMax
,
859 size
, type
, stride
, normalized
, integer
, doubles
, ptr
);
861 return validate_array_format(ctx
, func
, vao
, attrib
, legalTypes
, sizeMin
,
862 sizeMax
, size
, type
, normalized
, integer
,
868 * Update state for glVertex/Color/TexCoord/...Pointer functions.
870 * \param vao the vao to update
871 * \param obj the bound buffer object
872 * \param attrib the attribute array index to update
873 * \param format Either GL_RGBA or GL_BGRA.
874 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
875 * \param size components per element (1, 2, 3 or 4)
876 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
877 * \param stride stride between elements, in elements
878 * \param normalized are integer types converted to floats in [-1, 1]?
879 * \param integer integer-valued values (will not be normalized to [-1,1])
880 * \param doubles Double values not reduced to floats
881 * \param ptr the address (or offset inside VBO) of the array data
884 update_array(struct gl_context
*ctx
,
885 struct gl_vertex_array_object
*vao
,
886 struct gl_buffer_object
*obj
,
887 GLuint attrib
, GLenum format
,
889 GLint size
, GLenum type
, GLsizei stride
,
890 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
893 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
894 normalized
, integer
, doubles
, 0);
896 /* Reset the vertex attrib binding */
897 _mesa_vertex_attrib_binding(ctx
, vao
, attrib
, attrib
);
899 /* The Stride and Ptr fields are not set by update_array_format() */
900 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attrib
];
901 if ((array
->Stride
!= stride
) || (array
->Ptr
!= ptr
)) {
902 array
->Stride
= stride
;
904 vao
->NewArrays
|= vao
->Enabled
& VERT_BIT(attrib
);
907 /* Update the vertex buffer binding */
908 GLsizei effectiveStride
= stride
!= 0 ?
909 stride
: array
->Format
._ElementSize
;
910 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
916 /* Helper function for all EXT_direct_state_access glVertexArray* functions */
918 _lookup_vao_and_vbo_dsa(struct gl_context
*ctx
,
919 GLuint vaobj
, GLuint buffer
,
921 struct gl_vertex_array_object
** vao
,
922 struct gl_buffer_object
** vbo
,
925 *vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, caller
);
930 *vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
931 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, vbo
, caller
))
935 _mesa_error(ctx
, GL_INVALID_VALUE
,
936 "%s(negative offset with non-0 buffer)", caller
);
948 _mesa_VertexPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
951 GET_CURRENT_CONTEXT(ctx
);
953 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
954 VERT_ATTRIB_POS
, GL_RGBA
, 4, size
, type
, stride
,
955 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
960 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
962 GET_CURRENT_CONTEXT(ctx
);
964 GLenum format
= GL_RGBA
;
965 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
966 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
967 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
968 DOUBLE_BIT
| HALF_BIT
|
969 UNSIGNED_INT_2_10_10_10_REV_BIT
|
970 INT_2_10_10_10_REV_BIT
);
972 if (!validate_array_and_format(ctx
, "glVertexPointer",
973 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
974 VERT_ATTRIB_POS
, legalTypes
, 2, 4, size
,
975 type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
979 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
980 VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
981 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
986 _mesa_VertexArrayVertexOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
987 GLenum type
, GLsizei stride
, GLintptr offset
)
989 GET_CURRENT_CONTEXT(ctx
);
991 GLenum format
= GL_RGBA
;
992 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
993 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
994 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
995 DOUBLE_BIT
| HALF_BIT
|
996 UNSIGNED_INT_2_10_10_10_REV_BIT
|
997 INT_2_10_10_10_REV_BIT
);
999 struct gl_vertex_array_object
* vao
;
1000 struct gl_buffer_object
* vbo
;
1002 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1004 "glVertexArrayVertexOffsetEXT"))
1007 if (!validate_array_and_format(ctx
, "glVertexArrayVertexOffsetEXT",
1009 VERT_ATTRIB_POS
, legalTypes
, 2, 4, size
,
1010 type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
1011 format
, (void*) offset
))
1014 update_array(ctx
, vao
, vbo
,
1015 VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
1016 GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1021 _mesa_NormalPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1023 GET_CURRENT_CONTEXT(ctx
);
1025 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1026 VERT_ATTRIB_NORMAL
, GL_RGBA
, 3, 3, type
, stride
, GL_TRUE
,
1027 GL_FALSE
, GL_FALSE
, ptr
);
1032 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1034 GET_CURRENT_CONTEXT(ctx
);
1036 GLenum format
= GL_RGBA
;
1037 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1038 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1039 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1040 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1041 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1042 INT_2_10_10_10_REV_BIT
);
1044 if (!validate_array_and_format(ctx
, "glNormalPointer",
1045 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1046 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
1047 type
, stride
, GL_TRUE
, GL_FALSE
,
1048 GL_FALSE
, format
, ptr
))
1051 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1052 VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
1053 GL_FALSE
, GL_FALSE
, ptr
);
1058 _mesa_VertexArrayNormalOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1059 GLsizei stride
, GLintptr offset
)
1061 GET_CURRENT_CONTEXT(ctx
);
1063 GLenum format
= GL_RGBA
;
1064 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1065 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1066 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1067 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1068 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1069 INT_2_10_10_10_REV_BIT
);
1071 struct gl_vertex_array_object
* vao
;
1072 struct gl_buffer_object
* vbo
;
1074 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1079 if (!validate_array_and_format(ctx
, "glNormalPointer",
1081 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
1082 type
, stride
, GL_TRUE
, GL_FALSE
,
1083 GL_FALSE
, format
, (void*) offset
))
1086 update_array(ctx
, vao
, vbo
,
1087 VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
1088 GL_FALSE
, GL_FALSE
, (void*) offset
);
1093 _mesa_ColorPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
1096 GET_CURRENT_CONTEXT(ctx
);
1098 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1099 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1100 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
1101 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1106 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1108 GET_CURRENT_CONTEXT(ctx
);
1109 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
1111 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1112 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1113 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1114 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1115 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1116 INT_BIT
| UNSIGNED_INT_BIT
|
1117 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1118 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1119 INT_2_10_10_10_REV_BIT
);
1121 if (!validate_array_and_format(ctx
, "glColorPointer",
1122 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1123 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
1124 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
1125 GL_FALSE
, GL_FALSE
, format
, ptr
))
1128 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1129 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
1130 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1135 _mesa_VertexArrayColorOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1136 GLenum type
, GLsizei stride
, GLintptr offset
)
1138 GET_CURRENT_CONTEXT(ctx
);
1139 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
1141 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1142 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1143 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1144 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1145 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1146 INT_BIT
| UNSIGNED_INT_BIT
|
1147 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1148 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1149 INT_2_10_10_10_REV_BIT
);
1151 struct gl_vertex_array_object
* vao
;
1152 struct gl_buffer_object
* vbo
;
1154 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1156 "glVertexArrayColorOffsetEXT"))
1159 if (!validate_array_and_format(ctx
, "glVertexArrayColorOffsetEXT",
1161 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
1162 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
1163 GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1166 update_array(ctx
, vao
, vbo
,
1167 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
1168 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1173 _mesa_FogCoordPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1175 GET_CURRENT_CONTEXT(ctx
);
1177 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1178 VERT_ATTRIB_FOG
, GL_RGBA
, 1, 1, type
, stride
, GL_FALSE
,
1179 GL_FALSE
, GL_FALSE
, ptr
);
1184 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1186 GET_CURRENT_CONTEXT(ctx
);
1188 GLenum format
= GL_RGBA
;
1189 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
1191 if (!validate_array_and_format(ctx
, "glFogCoordPointer",
1192 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1193 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
1194 type
, stride
, GL_FALSE
, GL_FALSE
,
1195 GL_FALSE
, format
, ptr
))
1198 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1199 VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
1200 GL_FALSE
, GL_FALSE
, ptr
);
1205 _mesa_VertexArrayFogCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1206 GLsizei stride
, GLintptr offset
)
1208 GET_CURRENT_CONTEXT(ctx
);
1210 GLenum format
= GL_RGBA
;
1211 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
1213 struct gl_vertex_array_object
* vao
;
1214 struct gl_buffer_object
* vbo
;
1216 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1218 "glVertexArrayFogCoordOffsetEXT"))
1221 if (!validate_array_and_format(ctx
, "glVertexArrayFogCoordOffsetEXT",
1223 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
1224 type
, stride
, GL_FALSE
, GL_FALSE
,
1225 GL_FALSE
, format
, (void*) offset
))
1228 update_array(ctx
, vao
, vbo
,
1229 VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
1230 GL_FALSE
, GL_FALSE
, (void*) offset
);
1235 _mesa_IndexPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1237 GET_CURRENT_CONTEXT(ctx
);
1239 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1240 VERT_ATTRIB_COLOR_INDEX
, GL_RGBA
, 1, 1, type
, stride
,
1241 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1246 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1248 GET_CURRENT_CONTEXT(ctx
);
1250 GLenum format
= GL_RGBA
;
1251 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1252 FLOAT_BIT
| DOUBLE_BIT
);
1254 if (!validate_array_and_format(ctx
, "glIndexPointer",
1255 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1256 VERT_ATTRIB_COLOR_INDEX
,
1257 legalTypes
, 1, 1, 1, type
, stride
,
1258 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1261 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1262 VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
1263 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1268 _mesa_VertexArrayIndexOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1269 GLsizei stride
, GLintptr offset
)
1271 GET_CURRENT_CONTEXT(ctx
);
1273 GLenum format
= GL_RGBA
;
1274 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1275 FLOAT_BIT
| DOUBLE_BIT
);
1277 struct gl_vertex_array_object
* vao
;
1278 struct gl_buffer_object
* vbo
;
1280 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1282 "glVertexArrayIndexOffsetEXT"))
1285 if (!validate_array_and_format(ctx
, "glVertexArrayIndexOffsetEXT",
1287 VERT_ATTRIB_COLOR_INDEX
,
1288 legalTypes
, 1, 1, 1, type
, stride
,
1289 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1292 update_array(ctx
, vao
, vbo
,
1293 VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
1294 GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1299 _mesa_SecondaryColorPointer_no_error(GLint size
, GLenum type
,
1300 GLsizei stride
, const GLvoid
*ptr
)
1302 GET_CURRENT_CONTEXT(ctx
);
1304 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1305 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1306 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
1307 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1312 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
1313 GLsizei stride
, const GLvoid
*ptr
)
1315 GET_CURRENT_CONTEXT(ctx
);
1317 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1318 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1319 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1320 INT_BIT
| UNSIGNED_INT_BIT
|
1321 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1322 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1323 INT_2_10_10_10_REV_BIT
);
1325 if (!validate_array_and_format(ctx
, "glSecondaryColorPointer",
1326 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1327 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
1328 BGRA_OR_4
, size
, type
, stride
,
1329 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1332 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1333 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
1334 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1339 _mesa_VertexArraySecondaryColorOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1340 GLenum type
, GLsizei stride
, GLintptr offset
)
1342 GET_CURRENT_CONTEXT(ctx
);
1344 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1345 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1346 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1347 INT_BIT
| UNSIGNED_INT_BIT
|
1348 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1349 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1350 INT_2_10_10_10_REV_BIT
);
1352 struct gl_vertex_array_object
* vao
;
1353 struct gl_buffer_object
* vbo
;
1355 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1357 "glVertexArraySecondaryColorOffsetEXT"))
1360 if (!validate_array_and_format(ctx
, "glVertexArraySecondaryColorOffsetEXT",
1362 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
1363 BGRA_OR_4
, size
, type
, stride
,
1364 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1367 update_array(ctx
, vao
, vbo
,
1368 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
1369 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1374 _mesa_TexCoordPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
1377 GET_CURRENT_CONTEXT(ctx
);
1378 const GLuint unit
= ctx
->Array
.ActiveTexture
;
1380 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1381 VERT_ATTRIB_TEX(unit
), GL_RGBA
, 4, size
, type
,
1382 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1387 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
1390 GET_CURRENT_CONTEXT(ctx
);
1391 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1392 const GLuint unit
= ctx
->Array
.ActiveTexture
;
1394 GLenum format
= GL_RGBA
;
1395 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1396 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1397 : (SHORT_BIT
| INT_BIT
|
1398 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1399 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1400 INT_2_10_10_10_REV_BIT
);
1402 if (!validate_array_and_format(ctx
, "glTexCoordPointer",
1403 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1404 VERT_ATTRIB_TEX(unit
), legalTypes
,
1405 sizeMin
, 4, size
, type
, stride
,
1406 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1409 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1410 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
1411 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1416 _mesa_VertexArrayTexCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1417 GLenum type
, GLsizei stride
, GLintptr offset
)
1419 GET_CURRENT_CONTEXT(ctx
);
1420 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1421 const GLuint unit
= ctx
->Array
.ActiveTexture
;
1423 GLenum format
= GL_RGBA
;
1424 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1425 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1426 : (SHORT_BIT
| INT_BIT
|
1427 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1428 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1429 INT_2_10_10_10_REV_BIT
);
1431 struct gl_vertex_array_object
* vao
;
1432 struct gl_buffer_object
* vbo
;
1434 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1436 "glVertexArrayTexCoordOffsetEXT"))
1439 if (!validate_array_and_format(ctx
, "glVertexArrayTexCoordOffsetEXT",
1441 VERT_ATTRIB_TEX(unit
), legalTypes
,
1442 sizeMin
, 4, size
, type
, stride
,
1443 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1446 update_array(ctx
, vao
, vbo
,
1447 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
1448 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1453 _mesa_VertexArrayMultiTexCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum texunit
,
1454 GLint size
, GLenum type
, GLsizei stride
,
1457 GET_CURRENT_CONTEXT(ctx
);
1458 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1459 const GLuint unit
= texunit
- GL_TEXTURE0
;
1461 GLenum format
= GL_RGBA
;
1462 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1463 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1464 : (SHORT_BIT
| INT_BIT
|
1465 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1466 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1467 INT_2_10_10_10_REV_BIT
);
1469 struct gl_vertex_array_object
* vao
;
1470 struct gl_buffer_object
* vbo
;
1472 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1474 "glVertexArrayMultiTexCoordOffsetEXT"))
1477 if (unit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1478 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexArrayMultiTexCoordOffsetEXT(texunit=%d)",
1483 if (!validate_array_and_format(ctx
, "glVertexArrayMultiTexCoordOffsetEXT",
1485 VERT_ATTRIB_TEX(unit
), legalTypes
,
1486 sizeMin
, 4, size
, type
, stride
,
1487 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1490 update_array(ctx
, vao
, vbo
,
1491 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
1492 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1497 _mesa_EdgeFlagPointer_no_error(GLsizei stride
, const GLvoid
*ptr
)
1499 /* this is the same type that glEdgeFlag uses */
1500 const GLboolean integer
= GL_FALSE
;
1501 GET_CURRENT_CONTEXT(ctx
);
1503 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1504 VERT_ATTRIB_EDGEFLAG
, GL_RGBA
, 1, 1, GL_UNSIGNED_BYTE
,
1505 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
1510 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
1512 /* this is the same type that glEdgeFlag uses */
1513 const GLboolean integer
= GL_FALSE
;
1514 GET_CURRENT_CONTEXT(ctx
);
1516 GLenum format
= GL_RGBA
;
1517 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
1519 if (!validate_array_and_format(ctx
, "glEdgeFlagPointer",
1520 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1521 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
1522 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
1523 GL_FALSE
, integer
, GL_FALSE
, format
, ptr
))
1526 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1527 VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
1528 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
1533 _mesa_VertexArrayEdgeFlagOffsetEXT(GLuint vaobj
, GLuint buffer
, GLsizei stride
,
1536 /* this is the same type that glEdgeFlag uses */
1537 const GLboolean integer
= GL_FALSE
;
1538 GET_CURRENT_CONTEXT(ctx
);
1540 GLenum format
= GL_RGBA
;
1541 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
1543 struct gl_vertex_array_object
* vao
;
1544 struct gl_buffer_object
* vbo
;
1546 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1548 "glVertexArrayEdgeFlagOffsetEXT"))
1551 if (!validate_array_and_format(ctx
, "glVertexArrayEdgeFlagOffsetEXT",
1553 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
1554 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
1555 GL_FALSE
, integer
, GL_FALSE
, format
, (void*) offset
))
1558 update_array(ctx
, vao
, vbo
,
1559 VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
1560 stride
, GL_FALSE
, integer
, GL_FALSE
, (void*) offset
);
1565 _mesa_PointSizePointerOES_no_error(GLenum type
, GLsizei stride
,
1568 GET_CURRENT_CONTEXT(ctx
);
1570 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1571 VERT_ATTRIB_POINT_SIZE
, GL_RGBA
, 1, 1, type
, stride
,
1572 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1577 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1579 GET_CURRENT_CONTEXT(ctx
);
1581 GLenum format
= GL_RGBA
;
1582 if (ctx
->API
!= API_OPENGLES
) {
1583 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1584 "glPointSizePointer(ES 1.x only)");
1588 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
1590 if (!validate_array_and_format(ctx
, "glPointSizePointer",
1591 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1592 VERT_ATTRIB_POINT_SIZE
, legalTypes
,
1593 1, 1, 1, type
, stride
, GL_FALSE
, GL_FALSE
,
1594 GL_FALSE
, format
, ptr
))
1597 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1598 VERT_ATTRIB_POINT_SIZE
, format
, 1, 1, type
, stride
,
1599 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1604 _mesa_VertexAttribPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1605 GLboolean normalized
,
1606 GLsizei stride
, const GLvoid
*ptr
)
1608 GET_CURRENT_CONTEXT(ctx
);
1610 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1611 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1612 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1613 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
1618 * Set a generic vertex attribute array.
1619 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1620 * (position, normal, color, fog, texcoord, etc).
1623 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
1624 GLboolean normalized
,
1625 GLsizei stride
, const GLvoid
*ptr
)
1627 GET_CURRENT_CONTEXT(ctx
);
1629 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1630 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1631 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(idx)");
1635 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1636 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1637 INT_BIT
| UNSIGNED_INT_BIT
|
1638 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1639 FIXED_ES_BIT
| FIXED_GL_BIT
|
1640 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1641 INT_2_10_10_10_REV_BIT
|
1642 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1644 if (!validate_array_and_format(ctx
, "glVertexAttribPointer",
1645 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1646 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1647 1, BGRA_OR_4
, size
, type
, stride
,
1648 normalized
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1651 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1652 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1653 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
1658 _mesa_VertexArrayVertexAttribOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1659 GLenum type
, GLboolean normalized
,
1660 GLsizei stride
, GLintptr offset
)
1662 GET_CURRENT_CONTEXT(ctx
);
1663 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1664 struct gl_vertex_array_object
* vao
;
1665 struct gl_buffer_object
* vbo
;
1667 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1669 "glVertexArrayVertexAttribOffsetEXT"))
1672 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1673 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribOffsetEXT(idx)");
1677 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1678 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1679 INT_BIT
| UNSIGNED_INT_BIT
|
1680 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1681 FIXED_ES_BIT
| FIXED_GL_BIT
|
1682 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1683 INT_2_10_10_10_REV_BIT
|
1684 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1686 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribOffsetEXT",
1688 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1689 1, BGRA_OR_4
, size
, type
, stride
,
1690 normalized
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1693 update_array(ctx
, vao
, vbo
,
1694 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1695 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1700 _mesa_VertexArrayVertexAttribLOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1701 GLenum type
, GLsizei stride
, GLintptr offset
)
1703 GET_CURRENT_CONTEXT(ctx
);
1704 GLenum format
= GL_RGBA
;
1705 struct gl_vertex_array_object
* vao
;
1706 struct gl_buffer_object
* vbo
;
1708 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1710 "glVertexArrayVertexAttribLOffsetEXT"))
1713 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1714 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribLOffsetEXT(idx)");
1718 const GLbitfield legalTypes
= DOUBLE_BIT
;
1720 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribLOffsetEXT",
1722 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1723 1, 4, size
, type
, stride
,
1724 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
, (void*) offset
))
1727 update_array(ctx
, vao
, vbo
,
1728 VERT_ATTRIB_GENERIC(index
), format
, 4,
1729 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, (void*) offset
);
1734 _mesa_VertexAttribIPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1735 GLsizei stride
, const GLvoid
*ptr
)
1737 const GLboolean normalized
= GL_FALSE
;
1738 const GLboolean integer
= GL_TRUE
;
1739 GET_CURRENT_CONTEXT(ctx
);
1741 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1742 VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1743 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1748 * GL_EXT_gpu_shader4 / GL 3.0.
1749 * Set an integer-valued vertex attribute array.
1750 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1751 * (position, normal, color, fog, texcoord, etc).
1754 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
1755 GLsizei stride
, const GLvoid
*ptr
)
1757 const GLboolean normalized
= GL_FALSE
;
1758 const GLboolean integer
= GL_TRUE
;
1759 GET_CURRENT_CONTEXT(ctx
);
1761 GLenum format
= GL_RGBA
;
1762 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1763 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
1767 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1768 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1769 INT_BIT
| UNSIGNED_INT_BIT
);
1771 if (!validate_array_and_format(ctx
, "glVertexAttribIPointer",
1772 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1773 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1774 1, 4, size
, type
, stride
,
1775 normalized
, integer
, GL_FALSE
, format
, ptr
))
1778 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1779 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1780 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1785 _mesa_VertexAttribLPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1786 GLsizei stride
, const GLvoid
*ptr
)
1788 GET_CURRENT_CONTEXT(ctx
);
1790 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1791 VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1792 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1797 _mesa_VertexArrayVertexAttribIOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1798 GLenum type
, GLsizei stride
, GLintptr offset
)
1800 const GLboolean normalized
= GL_FALSE
;
1801 const GLboolean integer
= GL_TRUE
;
1802 GET_CURRENT_CONTEXT(ctx
);
1803 GLenum format
= GL_RGBA
;
1805 struct gl_vertex_array_object
* vao
;
1806 struct gl_buffer_object
* vbo
;
1808 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1810 "glVertexArrayVertexAttribIOffsetEXT"))
1813 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1814 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribIOffsetEXT(index)");
1818 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1819 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1820 INT_BIT
| UNSIGNED_INT_BIT
);
1822 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribIOffsetEXT",
1824 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1825 1, 4, size
, type
, stride
,
1826 normalized
, integer
, GL_FALSE
, format
, (void*) offset
))
1829 update_array(ctx
, vao
, vbo
,
1830 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1831 stride
, normalized
, integer
, GL_FALSE
, (void*) offset
);
1836 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
1837 GLsizei stride
, const GLvoid
*ptr
)
1839 GET_CURRENT_CONTEXT(ctx
);
1841 GLenum format
= GL_RGBA
;
1842 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1843 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
1847 const GLbitfield legalTypes
= DOUBLE_BIT
;
1849 if (!validate_array_and_format(ctx
, "glVertexAttribLPointer",
1850 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1851 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1852 1, 4, size
, type
, stride
,
1853 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
, ptr
))
1856 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1857 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1858 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1863 _mesa_enable_vertex_array_attribs(struct gl_context
*ctx
,
1864 struct gl_vertex_array_object
*vao
,
1865 GLbitfield attrib_bits
)
1867 assert((attrib_bits
& ~VERT_BIT_ALL
) == 0);
1868 assert(!vao
->SharedAndImmutable
);
1870 /* Only work on bits that are disabled */
1871 attrib_bits
&= ~vao
->Enabled
;
1873 /* was disabled, now being enabled */
1874 vao
->Enabled
|= attrib_bits
;
1875 vao
->NewArrays
|= attrib_bits
;
1877 /* Update the map mode if needed */
1878 if (attrib_bits
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1879 update_attribute_map_mode(ctx
, vao
);
1884 enable_vertex_array_attrib(struct gl_context
*ctx
,
1885 struct gl_vertex_array_object
*vao
,
1889 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1890 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
1894 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1899 _mesa_EnableVertexAttribArray(GLuint index
)
1901 GET_CURRENT_CONTEXT(ctx
);
1902 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
1903 "glEnableVertexAttribArray");
1908 _mesa_EnableVertexAttribArray_no_error(GLuint index
)
1910 GET_CURRENT_CONTEXT(ctx
);
1911 _mesa_enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1912 VERT_ATTRIB_GENERIC(index
));
1917 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1919 GET_CURRENT_CONTEXT(ctx
);
1920 struct gl_vertex_array_object
*vao
;
1922 /* The ARB_direct_state_access specification says:
1924 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1925 * and DisableVertexArrayAttrib if <vaobj> is not
1926 * [compatibility profile: zero or] the name of an existing vertex
1929 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glEnableVertexArrayAttrib");
1933 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
1937 _mesa_EnableVertexArrayAttribEXT(GLuint vaobj
, GLuint index
)
1939 GET_CURRENT_CONTEXT(ctx
);
1940 struct gl_vertex_array_object
* vao
= _mesa_lookup_vao_err(ctx
, vaobj
,
1942 "glEnableVertexArrayAttribEXT");
1946 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttribEXT");
1951 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1953 GET_CURRENT_CONTEXT(ctx
);
1954 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1955 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1960 _mesa_disable_vertex_array_attribs(struct gl_context
*ctx
,
1961 struct gl_vertex_array_object
*vao
,
1962 GLbitfield attrib_bits
)
1964 assert((attrib_bits
& ~VERT_BIT_ALL
) == 0);
1965 assert(!vao
->SharedAndImmutable
);
1967 /* Only work on bits that are enabled */
1968 attrib_bits
&= vao
->Enabled
;
1970 /* was enabled, now being disabled */
1971 vao
->Enabled
&= ~attrib_bits
;
1972 vao
->NewArrays
|= attrib_bits
;
1974 /* Update the map mode if needed */
1975 if (attrib_bits
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1976 update_attribute_map_mode(ctx
, vao
);
1982 _mesa_DisableVertexAttribArray(GLuint index
)
1984 GET_CURRENT_CONTEXT(ctx
);
1986 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1987 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexAttribArray(index)");
1991 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1992 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
1997 _mesa_DisableVertexAttribArray_no_error(GLuint index
)
1999 GET_CURRENT_CONTEXT(ctx
);
2000 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2001 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
2006 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
2008 GET_CURRENT_CONTEXT(ctx
);
2009 struct gl_vertex_array_object
*vao
;
2011 /* The ARB_direct_state_access specification says:
2013 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
2014 * and DisableVertexArrayAttrib if <vaobj> is not
2015 * [compatibility profile: zero or] the name of an existing vertex
2018 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glDisableVertexArrayAttrib");
2022 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2023 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
2027 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2028 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
2032 _mesa_DisableVertexArrayAttribEXT(GLuint vaobj
, GLuint index
)
2034 GET_CURRENT_CONTEXT(ctx
);
2035 struct gl_vertex_array_object
* vao
= _mesa_lookup_vao_err(ctx
, vaobj
,
2037 "glEnableVertexArrayAttribEXT");
2041 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2042 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
2046 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2047 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
2052 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
2054 GET_CURRENT_CONTEXT(ctx
);
2055 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2056 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2057 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
2062 * Return info for a vertex attribute array (no alias with legacy
2063 * vertex attributes (pos, normal, color, etc)). This function does
2064 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
2067 get_vertex_array_attrib(struct gl_context
*ctx
,
2068 const struct gl_vertex_array_object
*vao
,
2069 GLuint index
, GLenum pname
,
2072 const struct gl_array_attributes
*array
;
2073 struct gl_buffer_object
*buf
;
2075 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2076 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
2080 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
2082 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
2085 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
2086 return !!(vao
->Enabled
& VERT_BIT_GENERIC(index
));
2087 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
2088 return (array
->Format
.Format
== GL_BGRA
) ? GL_BGRA
: array
->Format
.Size
;
2089 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
2090 return array
->Stride
;
2091 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
2092 return array
->Format
.Type
;
2093 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
2094 return array
->Format
.Normalized
;
2095 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
2096 buf
= vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
;
2097 return buf
? buf
->Name
: 0;
2098 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
2099 if ((_mesa_is_desktop_gl(ctx
)
2100 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
2101 || _mesa_is_gles3(ctx
)) {
2102 return array
->Format
.Integer
;
2105 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
2106 if (_mesa_is_desktop_gl(ctx
)) {
2107 return array
->Format
.Doubles
;
2110 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
2111 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
2112 || _mesa_is_gles3(ctx
)) {
2113 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
2116 case GL_VERTEX_ATTRIB_BINDING
:
2117 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
2118 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
2121 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
2122 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
2123 return array
->RelativeOffset
;
2127 ; /* fall-through */
2131 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
2136 static const GLfloat
*
2137 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
2140 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
2141 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
2145 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2146 _mesa_error(ctx
, GL_INVALID_VALUE
,
2147 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
2151 assert(VERT_ATTRIB_GENERIC(index
) <
2152 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
2154 FLUSH_CURRENT(ctx
, 0);
2155 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
2159 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
2161 GET_CURRENT_CONTEXT(ctx
);
2163 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2164 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
2170 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2172 "glGetVertexAttribfv");
2178 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
2180 GET_CURRENT_CONTEXT(ctx
);
2182 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2183 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
2185 params
[0] = (GLdouble
) v
[0];
2186 params
[1] = (GLdouble
) v
[1];
2187 params
[2] = (GLdouble
) v
[2];
2188 params
[3] = (GLdouble
) v
[3];
2192 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2194 "glGetVertexAttribdv");
2199 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
2201 GET_CURRENT_CONTEXT(ctx
);
2203 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2205 (const GLdouble
*)get_current_attrib(ctx
, index
,
2206 "glGetVertexAttribLdv");
2215 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2217 "glGetVertexAttribLdv");
2222 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
2224 GET_CURRENT_CONTEXT(ctx
);
2226 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2227 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
2229 /* XXX should floats in[0,1] be scaled to full int range? */
2230 params
[0] = (GLint
) v
[0];
2231 params
[1] = (GLint
) v
[1];
2232 params
[2] = (GLint
) v
[2];
2233 params
[3] = (GLint
) v
[3];
2237 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2239 "glGetVertexAttribiv");
2244 _mesa_GetVertexAttribLui64vARB(GLuint index
, GLenum pname
, GLuint64EXT
*params
)
2246 GET_CURRENT_CONTEXT(ctx
);
2248 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2250 (const GLuint64
*)get_current_attrib(ctx
, index
,
2251 "glGetVertexAttribLui64vARB");
2260 params
[0] = (GLuint64
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2262 "glGetVertexAttribLui64vARB");
2269 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
2271 GET_CURRENT_CONTEXT(ctx
);
2273 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2274 const GLint
*v
= (const GLint
*)
2275 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
2281 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2283 "glGetVertexAttribIiv");
2290 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
2292 GET_CURRENT_CONTEXT(ctx
);
2294 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2295 const GLuint
*v
= (const GLuint
*)
2296 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
2302 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2304 "glGetVertexAttribIuiv");
2310 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
2312 GET_CURRENT_CONTEXT(ctx
);
2314 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2315 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
2319 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
2320 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
2324 assert(VERT_ATTRIB_GENERIC(index
) <
2325 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
2327 *pointer
= (GLvoid
*)
2328 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
2332 /** ARB_direct_state_access */
2334 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
2335 GLenum pname
, GLint
*params
)
2337 GET_CURRENT_CONTEXT(ctx
);
2338 struct gl_vertex_array_object
*vao
;
2339 struct gl_buffer_object
*buf
;
2341 /* The ARB_direct_state_access specification says:
2343 * "An INVALID_OPERATION error is generated if <vaobj> is not
2344 * [compatibility profile: zero or] the name of an existing
2345 * vertex array object."
2347 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glGetVertexArrayIndexediv");
2351 /* The ARB_direct_state_access specification says:
2353 * "For GetVertexArrayIndexediv, <pname> must be one of
2354 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
2355 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
2356 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
2357 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
2358 * VERTEX_ATTRIB_RELATIVE_OFFSET."
2362 * "Add GetVertexArrayIndexediv in 'Get Command' for
2363 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
2364 * VERTEX_ATTRIB_BINDING,
2365 * VERTEX_ATTRIB_RELATIVE_OFFSET,
2366 * VERTEX_BINDING_OFFSET, and
2367 * VERTEX_BINDING_STRIDE states"
2369 * The only parameter name common to both lists is
2370 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
2371 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
2372 * pretty clear however that the intent is that it should be possible
2373 * to query all vertex attrib and binding states that can be set with
2377 case GL_VERTEX_BINDING_OFFSET
:
2378 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2380 case GL_VERTEX_BINDING_STRIDE
:
2381 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
2383 case GL_VERTEX_BINDING_DIVISOR
:
2384 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
2386 case GL_VERTEX_BINDING_BUFFER
:
2387 buf
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
;
2388 params
[0] = buf
? buf
->Name
: 0;
2391 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
2392 "glGetVertexArrayIndexediv");
2399 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
2400 GLenum pname
, GLint64
*params
)
2402 GET_CURRENT_CONTEXT(ctx
);
2403 struct gl_vertex_array_object
*vao
;
2405 /* The ARB_direct_state_access specification says:
2407 * "An INVALID_OPERATION error is generated if <vaobj> is not
2408 * [compatibility profile: zero or] the name of an existing
2409 * vertex array object."
2411 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glGetVertexArrayIndexed64iv");
2415 /* The ARB_direct_state_access specification says:
2417 * "For GetVertexArrayIndexed64iv, <pname> must be
2418 * VERTEX_BINDING_OFFSET."
2422 * "An INVALID_ENUM error is generated if <pname> is not one of
2423 * the valid values listed above for the corresponding command."
2425 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
2426 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
2427 "pname != GL_VERTEX_BINDING_OFFSET)");
2431 /* The ARB_direct_state_access specification says:
2433 * "An INVALID_VALUE error is generated if <index> is greater than
2434 * or equal to the value of MAX_VERTEX_ATTRIBS."
2436 * Since the index refers to a buffer binding in this case, the intended
2437 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
2438 * required to be the same, so in practice this doesn't matter.
2440 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
2441 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
2442 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
2443 index
, ctx
->Const
.MaxVertexAttribBindings
);
2447 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2452 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
2453 GLsizei count
, const GLvoid
*ptr
)
2456 _mesa_VertexPointer(size
, type
, stride
, ptr
);
2461 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
2465 _mesa_NormalPointer(type
, stride
, ptr
);
2470 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
2474 _mesa_ColorPointer(size
, type
, stride
, ptr
);
2479 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
2483 _mesa_IndexPointer(type
, stride
, ptr
);
2488 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
2489 GLsizei count
, const GLvoid
*ptr
)
2492 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
2497 _mesa_MultiTexCoordPointerEXT(GLenum texunit
, GLint size
, GLenum type
,
2498 GLsizei stride
, const GLvoid
*ptr
)
2500 GET_CURRENT_CONTEXT(ctx
);
2501 const GLint sizeMin
= 1;
2502 const GLuint unit
= texunit
- GL_TEXTURE0
;
2504 GLenum format
= GL_RGBA
;
2505 const GLbitfield legalTypes
= (SHORT_BIT
| INT_BIT
|
2506 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
2507 UNSIGNED_INT_2_10_10_10_REV_BIT
|
2508 INT_2_10_10_10_REV_BIT
);
2510 if (!validate_array_and_format(ctx
, "glMultiTexCoordPointerEXT",
2511 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
2512 VERT_ATTRIB_TEX(unit
), legalTypes
,
2513 sizeMin
, 4, size
, type
, stride
,
2514 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
2517 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
2518 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
2519 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
2524 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
2527 _mesa_EdgeFlagPointer(stride
, ptr
);
2532 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
2534 GET_CURRENT_CONTEXT(ctx
);
2535 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
2536 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
2537 GLenum ctype
= 0; /* color type */
2538 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
2539 const GLint toffset
= 0; /* always zero */
2540 GLint defstride
; /* default stride */
2543 f
= sizeof(GLfloat
);
2544 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
2547 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
2553 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2554 tcomps
= 0; ccomps
= 0; vcomps
= 2;
2559 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2560 tcomps
= 0; ccomps
= 0; vcomps
= 3;
2565 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2566 tcomps
= 0; ccomps
= 4; vcomps
= 2;
2567 ctype
= GL_UNSIGNED_BYTE
;
2570 defstride
= c
+ 2*f
;
2573 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2574 tcomps
= 0; ccomps
= 4; vcomps
= 3;
2575 ctype
= GL_UNSIGNED_BYTE
;
2578 defstride
= c
+ 3*f
;
2581 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2582 tcomps
= 0; ccomps
= 3; vcomps
= 3;
2589 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
2590 tcomps
= 0; ccomps
= 0; vcomps
= 3;
2595 case GL_C4F_N3F_V3F
:
2596 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2597 tcomps
= 0; ccomps
= 4; vcomps
= 3;
2605 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2606 tcomps
= 2; ccomps
= 0; vcomps
= 3;
2611 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2612 tcomps
= 4; ccomps
= 0; vcomps
= 4;
2616 case GL_T2F_C4UB_V3F
:
2617 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2618 tcomps
= 2; ccomps
= 4; vcomps
= 3;
2619 ctype
= GL_UNSIGNED_BYTE
;
2624 case GL_T2F_C3F_V3F
:
2625 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2626 tcomps
= 2; ccomps
= 3; vcomps
= 3;
2632 case GL_T2F_N3F_V3F
:
2633 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
2634 tcomps
= 2; ccomps
= 0; vcomps
= 3;
2639 case GL_T2F_C4F_N3F_V3F
:
2640 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2641 tcomps
= 2; ccomps
= 4; vcomps
= 3;
2648 case GL_T4F_C4F_N3F_V4F
:
2649 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2650 tcomps
= 4; ccomps
= 4; vcomps
= 4;
2658 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
2666 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
2667 _mesa_DisableClientState( GL_INDEX_ARRAY
);
2668 /* XXX also disable secondary color and generic arrays? */
2672 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
2673 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
2674 (GLubyte
*) pointer
+ toffset
);
2677 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
2682 _mesa_EnableClientState( GL_COLOR_ARRAY
);
2683 _mesa_ColorPointer( ccomps
, ctype
, stride
,
2684 (GLubyte
*) pointer
+ coffset
);
2687 _mesa_DisableClientState( GL_COLOR_ARRAY
);
2693 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
2694 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
2697 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
2701 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
2702 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
2703 (GLubyte
*) pointer
+ voffset
);
2708 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
2710 GET_CURRENT_CONTEXT(ctx
);
2712 if (MESA_VERBOSE
& VERBOSE_API
)
2713 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
2716 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
2720 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
2723 if (ctx
->Array
.LockCount
!= 0) {
2724 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
2728 ctx
->Array
.LockFirst
= first
;
2729 ctx
->Array
.LockCount
= count
;
2734 _mesa_UnlockArraysEXT( void )
2736 GET_CURRENT_CONTEXT(ctx
);
2738 if (MESA_VERBOSE
& VERBOSE_API
)
2739 _mesa_debug(ctx
, "glUnlockArrays\n");
2741 if (ctx
->Array
.LockCount
== 0) {
2742 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
2746 ctx
->Array
.LockFirst
= 0;
2747 ctx
->Array
.LockCount
= 0;
2752 primitive_restart_index(struct gl_context
*ctx
, GLuint index
)
2754 ctx
->Array
.RestartIndex
= index
;
2755 _mesa_update_derived_primitive_restart_state(ctx
);
2760 * GL_NV_primitive_restart and GL 3.1
2763 _mesa_PrimitiveRestartIndex_no_error(GLuint index
)
2765 GET_CURRENT_CONTEXT(ctx
);
2766 primitive_restart_index(ctx
, index
);
2771 _mesa_PrimitiveRestartIndex(GLuint index
)
2773 GET_CURRENT_CONTEXT(ctx
);
2775 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
2776 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
2780 primitive_restart_index(ctx
, index
);
2785 _mesa_VertexAttribDivisor_no_error(GLuint index
, GLuint divisor
)
2787 GET_CURRENT_CONTEXT(ctx
);
2789 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2790 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2792 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2794 /* The ARB_vertex_attrib_binding spec says:
2798 * void VertexAttribDivisor(uint index, uint divisor);
2800 * is equivalent to (assuming no errors are generated):
2802 * VertexAttribBinding(index, index);
2803 * VertexBindingDivisor(index, divisor);"
2805 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2806 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2811 * See GL_ARB_instanced_arrays.
2812 * Note that the instance divisor only applies to generic arrays, not
2813 * the legacy vertex arrays.
2816 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
2818 GET_CURRENT_CONTEXT(ctx
);
2820 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2821 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2823 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2824 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
2828 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2829 _mesa_error(ctx
, GL_INVALID_VALUE
,
2830 "glVertexAttribDivisor(index = %u)", index
);
2834 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2836 /* The ARB_vertex_attrib_binding spec says:
2840 * void VertexAttribDivisor(uint index, uint divisor);
2842 * is equivalent to (assuming no errors are generated):
2844 * VertexAttribBinding(index, index);
2845 * VertexBindingDivisor(index, divisor);"
2847 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2848 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2853 _mesa_VertexArrayVertexAttribDivisorEXT(GLuint vaobj
, GLuint index
, GLuint divisor
)
2855 GET_CURRENT_CONTEXT(ctx
);
2857 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2858 struct gl_vertex_array_object
* vao
;
2859 /* The ARB_instanced_arrays spec says:
2861 * "The vertex array object named by vaobj must
2862 * be generated by GenVertexArrays (and not since deleted);
2863 * otherwise an INVALID_OPERATION error is generated."
2865 vao
= _mesa_lookup_vao_err(ctx
, vaobj
,
2867 "glVertexArrayVertexAttribDivisorEXT");
2871 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2872 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexArrayVertexAttribDivisorEXT()");
2876 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2877 _mesa_error(ctx
, GL_INVALID_VALUE
,
2878 "glVertexArrayVertexAttribDivisorEXT(index = %u)", index
);
2882 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2884 /* The ARB_vertex_attrib_binding spec says:
2888 * void VertexAttribDivisor(uint index, uint divisor);
2890 * is equivalent to (assuming no errors are generated):
2892 * VertexAttribBinding(index, index);
2893 * VertexBindingDivisor(index, divisor);"
2895 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2896 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2901 static ALWAYS_INLINE
void
2902 vertex_array_vertex_buffer(struct gl_context
*ctx
,
2903 struct gl_vertex_array_object
*vao
,
2904 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2905 GLsizei stride
, bool no_error
, const char *func
)
2907 struct gl_buffer_object
*vbo
;
2908 struct gl_buffer_object
*current_buf
=
2909 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
2911 if (current_buf
&& buffer
== current_buf
->Name
) {
2913 } else if (buffer
!= 0) {
2914 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
2916 if (!no_error
&& !vbo
&& _mesa_is_gles31(ctx
)) {
2917 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
2920 /* From the GL_ARB_vertex_attrib_array spec:
2922 * "[Core profile only:]
2923 * An INVALID_OPERATION error is generated if buffer is not zero or a
2924 * name returned from a previous call to GenBuffers, or if such a name
2925 * has since been deleted with DeleteBuffers.
2927 * Otherwise, we fall back to the same compat profile behavior as other
2928 * object references (automatically gen it).
2930 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
2933 /* The ARB_vertex_attrib_binding spec says:
2935 * "If <buffer> is zero, any buffer object attached to this
2936 * bindpoint is detached."
2941 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
2942 vbo
, offset
, stride
);
2947 * GL_ARB_vertex_attrib_binding
2950 vertex_array_vertex_buffer_err(struct gl_context
*ctx
,
2951 struct gl_vertex_array_object
*vao
,
2952 GLuint bindingIndex
, GLuint buffer
,
2953 GLintptr offset
, GLsizei stride
,
2956 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2958 /* The ARB_vertex_attrib_binding spec says:
2960 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2961 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2963 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2964 _mesa_error(ctx
, GL_INVALID_VALUE
,
2965 "%s(bindingindex=%u > "
2966 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2967 func
, bindingIndex
);
2971 /* The ARB_vertex_attrib_binding spec says:
2973 * "The error INVALID_VALUE is generated if <stride> or <offset>
2977 _mesa_error(ctx
, GL_INVALID_VALUE
,
2978 "%s(offset=%" PRId64
" < 0)",
2979 func
, (int64_t) offset
);
2984 _mesa_error(ctx
, GL_INVALID_VALUE
,
2985 "%s(stride=%d < 0)", func
, stride
);
2989 if (((_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
2990 stride
> ctx
->Const
.MaxVertexAttribStride
) {
2991 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
2992 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
2996 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2997 stride
, false, func
);
3002 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex
, GLuint buffer
,
3003 GLintptr offset
, GLsizei stride
)
3005 GET_CURRENT_CONTEXT(ctx
);
3006 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
3007 buffer
, offset
, stride
, true,
3008 "glBindVertexBuffer");
3013 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
3016 GET_CURRENT_CONTEXT(ctx
);
3018 /* The ARB_vertex_attrib_binding spec says:
3020 * "An INVALID_OPERATION error is generated if no vertex array object
3023 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3024 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3025 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3026 "glBindVertexBuffer(No array object bound)");
3030 vertex_array_vertex_buffer_err(ctx
, ctx
->Array
.VAO
, bindingIndex
,
3031 buffer
, offset
, stride
,
3032 "glBindVertexBuffer");
3037 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj
, GLuint bindingIndex
,
3038 GLuint buffer
, GLintptr offset
,
3041 GET_CURRENT_CONTEXT(ctx
);
3043 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3044 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
3045 stride
, true, "glVertexArrayVertexBuffer");
3050 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
3051 GLintptr offset
, GLsizei stride
)
3053 GET_CURRENT_CONTEXT(ctx
);
3054 struct gl_vertex_array_object
*vao
;
3056 /* The ARB_direct_state_access specification says:
3058 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
3059 * if <vaobj> is not [compatibility profile: zero or] the name of an
3060 * existing vertex array object."
3062 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayVertexBuffer");
3066 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
3067 stride
, "glVertexArrayVertexBuffer");
3072 _mesa_VertexArrayBindVertexBufferEXT(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
3073 GLintptr offset
, GLsizei stride
)
3075 GET_CURRENT_CONTEXT(ctx
);
3076 struct gl_vertex_array_object
*vao
;
3077 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, "glVertexArrayBindVertexBufferEXT");
3081 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
3082 stride
, "glVertexArrayBindVertexBufferEXT");
3086 static ALWAYS_INLINE
void
3087 vertex_array_vertex_buffers(struct gl_context
*ctx
,
3088 struct gl_vertex_array_object
*vao
,
3089 GLuint first
, GLsizei count
, const GLuint
*buffers
,
3090 const GLintptr
*offsets
, const GLsizei
*strides
,
3091 bool no_error
, const char *func
)
3097 * The ARB_multi_bind spec says:
3099 * "If <buffers> is NULL, each affected vertex buffer binding point
3100 * from <first> through <first>+<count>-1 will be reset to have no
3101 * bound buffer object. In this case, the offsets and strides
3102 * associated with the binding points are set to default values,
3103 * ignoring <offsets> and <strides>."
3105 for (i
= 0; i
< count
; i
++)
3106 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
3112 /* Note that the error semantics for multi-bind commands differ from
3113 * those of other GL commands.
3115 * The Issues section in the ARB_multi_bind spec says:
3117 * "(11) Typically, OpenGL specifies that if an error is generated by
3118 * a command, that command has no effect. This is somewhat
3119 * unfortunate for multi-bind commands, because it would require
3120 * a first pass to scan the entire list of bound objects for
3121 * errors and then a second pass to actually perform the
3122 * bindings. Should we have different error semantics?
3124 * RESOLVED: Yes. In this specification, when the parameters for
3125 * one of the <count> binding points are invalid, that binding
3126 * point is not updated and an error will be generated. However,
3127 * other binding points in the same command will be updated if
3128 * their parameters are valid and no other error occurs."
3131 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
3133 for (i
= 0; i
< count
; i
++) {
3134 struct gl_buffer_object
*vbo
;
3137 /* The ARB_multi_bind spec says:
3139 * "An INVALID_VALUE error is generated if any value in
3140 * <offsets> or <strides> is negative (per binding)."
3142 if (offsets
[i
] < 0) {
3143 _mesa_error(ctx
, GL_INVALID_VALUE
,
3144 "%s(offsets[%u]=%" PRId64
" < 0)",
3145 func
, i
, (int64_t) offsets
[i
]);
3149 if (strides
[i
] < 0) {
3150 _mesa_error(ctx
, GL_INVALID_VALUE
,
3151 "%s(strides[%u]=%d < 0)",
3152 func
, i
, strides
[i
]);
3156 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
3157 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
3158 _mesa_error(ctx
, GL_INVALID_VALUE
,
3159 "%s(strides[%u]=%d > "
3160 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
3166 struct gl_vertex_buffer_binding
*binding
=
3167 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
3169 if (buffers
[i
] == 0)
3171 else if (binding
->BufferObj
&& binding
->BufferObj
->Name
== buffers
[i
])
3172 vbo
= binding
->BufferObj
;
3175 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
,
3184 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
3185 vbo
, offsets
[i
], strides
[i
]);
3188 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
3193 vertex_array_vertex_buffers_err(struct gl_context
*ctx
,
3194 struct gl_vertex_array_object
*vao
,
3195 GLuint first
, GLsizei count
,
3196 const GLuint
*buffers
, const GLintptr
*offsets
,
3197 const GLsizei
*strides
, const char *func
)
3199 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3201 /* The ARB_multi_bind spec says:
3203 * "An INVALID_OPERATION error is generated if <first> + <count>
3204 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
3206 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
3207 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3208 "%s(first=%u + count=%d > the value of "
3209 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
3210 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
3214 vertex_array_vertex_buffers(ctx
, vao
, first
, count
, buffers
, offsets
,
3215 strides
, false, func
);
3220 _mesa_BindVertexBuffers_no_error(GLuint first
, GLsizei count
,
3221 const GLuint
*buffers
, const GLintptr
*offsets
,
3222 const GLsizei
*strides
)
3224 GET_CURRENT_CONTEXT(ctx
);
3226 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
3227 buffers
, offsets
, strides
, true,
3228 "glBindVertexBuffers");
3233 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
3234 const GLintptr
*offsets
, const GLsizei
*strides
)
3236 GET_CURRENT_CONTEXT(ctx
);
3238 /* The ARB_vertex_attrib_binding spec says:
3240 * "An INVALID_OPERATION error is generated if no
3241 * vertex array object is bound."
3243 if (ctx
->API
== API_OPENGL_CORE
&&
3244 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3245 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3246 "glBindVertexBuffers(No array object bound)");
3250 vertex_array_vertex_buffers_err(ctx
, ctx
->Array
.VAO
, first
, count
,
3251 buffers
, offsets
, strides
,
3252 "glBindVertexBuffers");
3257 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj
, GLuint first
,
3258 GLsizei count
, const GLuint
*buffers
,
3259 const GLintptr
*offsets
,
3260 const GLsizei
*strides
)
3262 GET_CURRENT_CONTEXT(ctx
);
3264 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3265 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
3266 buffers
, offsets
, strides
, true,
3267 "glVertexArrayVertexBuffers");
3272 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
3273 const GLuint
*buffers
,
3274 const GLintptr
*offsets
, const GLsizei
*strides
)
3276 GET_CURRENT_CONTEXT(ctx
);
3277 struct gl_vertex_array_object
*vao
;
3279 /* The ARB_direct_state_access specification says:
3281 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
3282 * if <vaobj> is not [compatibility profile: zero or] the name of an
3283 * existing vertex array object."
3285 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayVertexBuffers");
3289 vertex_array_vertex_buffers_err(ctx
, vao
, first
, count
,
3290 buffers
, offsets
, strides
,
3291 "glVertexArrayVertexBuffers");
3296 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
3297 GLboolean normalized
, GLboolean integer
,
3298 GLboolean doubles
, GLbitfield legalTypes
,
3299 GLsizei sizeMax
, GLuint relativeOffset
,
3302 GET_CURRENT_CONTEXT(ctx
);
3303 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3305 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
3307 if (!_mesa_is_no_error_enabled(ctx
)) {
3308 /* The ARB_vertex_attrib_binding spec says:
3310 * "An INVALID_OPERATION error is generated under any of the
3311 * following conditions:
3312 * - if no vertex array object is currently bound (see section
3316 * This error condition only applies to VertexAttribFormat and
3317 * VertexAttribIFormat in the extension spec, but we assume that this
3318 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
3319 * to all three functions.
3321 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3322 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3323 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3324 "%s(No array object bound)", func
);
3328 /* The ARB_vertex_attrib_binding spec says:
3330 * "The error INVALID_VALUE is generated if index is greater than or
3331 * equal to the value of MAX_VERTEX_ATTRIBS."
3333 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
3334 _mesa_error(ctx
, GL_INVALID_VALUE
,
3335 "%s(attribindex=%u > "
3336 "GL_MAX_VERTEX_ATTRIBS)",
3341 if (!validate_array_format(ctx
, func
, ctx
->Array
.VAO
,
3342 VERT_ATTRIB_GENERIC(attribIndex
),
3343 legalTypes
, 1, sizeMax
, size
, type
,
3344 normalized
, integer
, doubles
, relativeOffset
,
3350 _mesa_update_array_format(ctx
, ctx
->Array
.VAO
,
3351 VERT_ATTRIB_GENERIC(attribIndex
), size
, type
,
3352 format
, normalized
, integer
, doubles
,
3358 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3359 GLboolean normalized
, GLuint relativeOffset
)
3361 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
3362 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
3363 BGRA_OR_4
, relativeOffset
,
3364 "glVertexAttribFormat");
3369 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3370 GLuint relativeOffset
)
3372 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
3373 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
3374 relativeOffset
, "glVertexAttribIFormat");
3379 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3380 GLuint relativeOffset
)
3382 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
3383 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
3384 relativeOffset
, "glVertexAttribLFormat");
3389 vertex_array_attrib_format(GLuint vaobj
, bool isExtDsa
, GLuint attribIndex
,
3390 GLint size
, GLenum type
, GLboolean normalized
,
3391 GLboolean integer
, GLboolean doubles
,
3392 GLbitfield legalTypes
, GLsizei sizeMax
,
3393 GLuint relativeOffset
, const char *func
)
3395 GET_CURRENT_CONTEXT(ctx
);
3396 struct gl_vertex_array_object
*vao
;
3398 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3400 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
3402 if (_mesa_is_no_error_enabled(ctx
)) {
3403 vao
= _mesa_lookup_vao(ctx
, vaobj
);
3407 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, isExtDsa
, func
);
3411 /* The ARB_vertex_attrib_binding spec says:
3413 * "The error INVALID_VALUE is generated if index is greater than or
3414 * equal to the value of MAX_VERTEX_ATTRIBS."
3416 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
3417 _mesa_error(ctx
, GL_INVALID_VALUE
,
3418 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
3423 if (!validate_array_format(ctx
, func
, vao
,
3424 VERT_ATTRIB_GENERIC(attribIndex
),
3425 legalTypes
, 1, sizeMax
, size
, type
,
3426 normalized
, integer
, doubles
, relativeOffset
,
3432 _mesa_update_array_format(ctx
, vao
, VERT_ATTRIB_GENERIC(attribIndex
), size
,
3433 type
, format
, normalized
, integer
, doubles
,
3439 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
3440 GLenum type
, GLboolean normalized
,
3441 GLuint relativeOffset
)
3443 vertex_array_attrib_format(vaobj
, false, attribIndex
, size
, type
, normalized
,
3444 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
3445 BGRA_OR_4
, relativeOffset
,
3446 "glVertexArrayAttribFormat");
3451 _mesa_VertexArrayVertexAttribFormatEXT(GLuint vaobj
, GLuint attribIndex
, GLint size
,
3452 GLenum type
, GLboolean normalized
,
3453 GLuint relativeOffset
)
3455 vertex_array_attrib_format(vaobj
, true, attribIndex
, size
, type
, normalized
,
3456 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
3457 BGRA_OR_4
, relativeOffset
,
3458 "glVertexArrayVertexAttribFormatEXT");
3463 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
3464 GLint size
, GLenum type
,
3465 GLuint relativeOffset
)
3467 vertex_array_attrib_format(vaobj
, false, attribIndex
, size
, type
, GL_FALSE
,
3468 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
3470 "glVertexArrayAttribIFormat");
3475 _mesa_VertexArrayVertexAttribIFormatEXT(GLuint vaobj
, GLuint attribIndex
,
3476 GLint size
, GLenum type
,
3477 GLuint relativeOffset
)
3479 vertex_array_attrib_format(vaobj
, true, attribIndex
, size
, type
, GL_FALSE
,
3480 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
3482 "glVertexArrayVertexAttribIFormatEXT");
3487 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
3488 GLint size
, GLenum type
,
3489 GLuint relativeOffset
)
3491 vertex_array_attrib_format(vaobj
, false, attribIndex
, size
, type
, GL_FALSE
,
3492 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
3494 "glVertexArrayAttribLFormat");
3499 _mesa_VertexArrayVertexAttribLFormatEXT(GLuint vaobj
, GLuint attribIndex
,
3500 GLint size
, GLenum type
,
3501 GLuint relativeOffset
)
3503 vertex_array_attrib_format(vaobj
, true, attribIndex
, size
, type
, GL_FALSE
,
3504 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
3506 "glVertexArrayVertexAttribLFormatEXT");
3511 vertex_array_attrib_binding(struct gl_context
*ctx
,
3512 struct gl_vertex_array_object
*vao
,
3513 GLuint attribIndex
, GLuint bindingIndex
,
3516 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3518 /* The ARB_vertex_attrib_binding spec says:
3520 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
3521 * <bindingindex> must be less than the value of
3522 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
3525 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
3526 _mesa_error(ctx
, GL_INVALID_VALUE
,
3527 "%s(attribindex=%u >= "
3528 "GL_MAX_VERTEX_ATTRIBS)",
3533 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
3534 _mesa_error(ctx
, GL_INVALID_VALUE
,
3535 "%s(bindingindex=%u >= "
3536 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
3537 func
, bindingIndex
);
3541 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
3543 _mesa_vertex_attrib_binding(ctx
, vao
,
3544 VERT_ATTRIB_GENERIC(attribIndex
),
3545 VERT_ATTRIB_GENERIC(bindingIndex
));
3550 _mesa_VertexAttribBinding_no_error(GLuint attribIndex
, GLuint bindingIndex
)
3552 GET_CURRENT_CONTEXT(ctx
);
3553 _mesa_vertex_attrib_binding(ctx
, ctx
->Array
.VAO
,
3554 VERT_ATTRIB_GENERIC(attribIndex
),
3555 VERT_ATTRIB_GENERIC(bindingIndex
));
3560 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
3562 GET_CURRENT_CONTEXT(ctx
);
3564 /* The ARB_vertex_attrib_binding spec says:
3566 * "An INVALID_OPERATION error is generated if no vertex array object
3569 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3570 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3571 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3572 "glVertexAttribBinding(No array object bound)");
3576 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
3577 attribIndex
, bindingIndex
,
3578 "glVertexAttribBinding");
3583 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj
, GLuint attribIndex
,
3584 GLuint bindingIndex
)
3586 GET_CURRENT_CONTEXT(ctx
);
3588 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3589 _mesa_vertex_attrib_binding(ctx
, vao
,
3590 VERT_ATTRIB_GENERIC(attribIndex
),
3591 VERT_ATTRIB_GENERIC(bindingIndex
));
3596 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
3598 GET_CURRENT_CONTEXT(ctx
);
3599 struct gl_vertex_array_object
*vao
;
3601 /* The ARB_direct_state_access specification says:
3603 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
3604 * if <vaobj> is not [compatibility profile: zero or] the name of an
3605 * existing vertex array object."
3607 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayAttribBinding");
3611 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
3612 "glVertexArrayAttribBinding");
3617 _mesa_VertexArrayVertexAttribBindingEXT(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
3619 GET_CURRENT_CONTEXT(ctx
);
3620 struct gl_vertex_array_object
*vao
;
3621 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, "glVertexArrayVertexAttribBindingEXT");
3625 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
3626 "glVertexArrayVertexAttribBindingEXT");
3631 vertex_array_binding_divisor(struct gl_context
*ctx
,
3632 struct gl_vertex_array_object
*vao
,
3633 GLuint bindingIndex
, GLuint divisor
,
3636 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3638 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
3639 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
3643 /* The ARB_vertex_attrib_binding spec says:
3645 * "An INVALID_VALUE error is generated if <bindingindex> is greater
3646 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
3648 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
3649 _mesa_error(ctx
, GL_INVALID_VALUE
,
3650 "%s(bindingindex=%u > "
3651 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
3652 func
, bindingIndex
);
3656 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3661 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex
, GLuint divisor
)
3663 GET_CURRENT_CONTEXT(ctx
);
3664 vertex_binding_divisor(ctx
, ctx
->Array
.VAO
,
3665 VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3670 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
3672 GET_CURRENT_CONTEXT(ctx
);
3674 /* The ARB_vertex_attrib_binding spec says:
3676 * "An INVALID_OPERATION error is generated if no vertex array object
3679 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3680 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3681 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3682 "glVertexBindingDivisor(No array object bound)");
3686 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
3687 bindingIndex
, divisor
,
3688 "glVertexBindingDivisor");
3693 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj
, GLuint bindingIndex
,
3696 GET_CURRENT_CONTEXT(ctx
);
3698 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3699 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3704 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
3707 struct gl_vertex_array_object
*vao
;
3708 GET_CURRENT_CONTEXT(ctx
);
3710 /* The ARB_direct_state_access specification says:
3712 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
3713 * if <vaobj> is not [compatibility profile: zero or] the name of an
3714 * existing vertex array object."
3716 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayBindingDivisor");
3720 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
3721 "glVertexArrayBindingDivisor");
3726 _mesa_VertexArrayVertexBindingDivisorEXT(GLuint vaobj
, GLuint bindingIndex
,
3729 struct gl_vertex_array_object
*vao
;
3730 GET_CURRENT_CONTEXT(ctx
);
3732 /* The ARB_direct_state_access specification says:
3734 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
3735 * if <vaobj> is not [compatibility profile: zero or] the name of an
3736 * existing vertex array object."
3738 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, "glVertexArrayVertexBindingDivisorEXT");
3742 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
3743 "glVertexArrayVertexBindingDivisorEXT");
3748 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
3749 struct gl_array_attributes
*dst
,
3750 const struct gl_array_attributes
*src
)
3752 dst
->Ptr
= src
->Ptr
;
3753 dst
->RelativeOffset
= src
->RelativeOffset
;
3754 dst
->Format
= src
->Format
;
3755 dst
->Stride
= src
->Stride
;
3756 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
3757 dst
->_EffBufferBindingIndex
= src
->_EffBufferBindingIndex
;
3758 dst
->_EffRelativeOffset
= src
->_EffRelativeOffset
;
3762 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
3763 struct gl_vertex_buffer_binding
*dst
,
3764 const struct gl_vertex_buffer_binding
*src
)
3766 dst
->Offset
= src
->Offset
;
3767 dst
->Stride
= src
->Stride
;
3768 dst
->InstanceDivisor
= src
->InstanceDivisor
;
3769 dst
->_BoundArrays
= src
->_BoundArrays
;
3770 dst
->_EffBoundArrays
= src
->_EffBoundArrays
;
3771 dst
->_EffOffset
= src
->_EffOffset
;
3773 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
3777 * Print current vertex object/array info. For debug.
3780 _mesa_print_arrays(struct gl_context
*ctx
)
3782 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
3784 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
3786 GLbitfield mask
= vao
->Enabled
;
3788 const gl_vert_attrib i
= u_bit_scan(&mask
);
3789 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
3791 const struct gl_vertex_buffer_binding
*binding
=
3792 &vao
->BufferBinding
[array
->BufferBindingIndex
];
3793 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
3795 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
3796 "Stride=%d, Buffer=%u(Size %lu)\n",
3797 gl_vert_attrib_name((gl_vert_attrib
)i
),
3798 array
->Ptr
, _mesa_enum_to_string(array
->Format
.Type
),
3800 array
->Format
._ElementSize
, binding
->Stride
, bo
? bo
->Name
: 0,
3801 (unsigned long)(bo
? bo
->Size
: 0));
3806 * Initialize attributes of a vertex array within a vertex array object.
3807 * \param vao the container vertex array object
3808 * \param index which array in the VAO to initialize
3809 * \param size number of components (1, 2, 3 or 4) per attribute
3810 * \param type datatype of the attribute (GL_FLOAT, GL_INT, etc).
3813 init_array(struct gl_context
*ctx
,
3814 struct gl_vertex_array_object
*vao
,
3815 gl_vert_attrib index
, GLint size
, GLint type
)
3817 assert(index
< ARRAY_SIZE(vao
->VertexAttrib
));
3818 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[index
];
3819 assert(index
< ARRAY_SIZE(vao
->BufferBinding
));
3820 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
3822 _mesa_set_vertex_format(&array
->Format
, size
, type
, GL_RGBA
,
3823 GL_FALSE
, GL_FALSE
, GL_FALSE
);
3826 array
->RelativeOffset
= 0;
3827 ASSERT_BITFIELD_SIZE(struct gl_array_attributes
, BufferBindingIndex
,
3828 VERT_ATTRIB_MAX
- 1);
3829 array
->BufferBindingIndex
= index
;
3831 binding
->Offset
= 0;
3832 binding
->Stride
= array
->Format
._ElementSize
;
3833 binding
->BufferObj
= NULL
;
3834 binding
->_BoundArrays
= BITFIELD_BIT(index
);
3838 init_default_vao_state(struct gl_context
*ctx
)
3840 struct gl_vertex_array_object
*vao
= &ctx
->Array
.DefaultVAOState
;
3843 vao
->SharedAndImmutable
= false;
3845 /* Init the individual arrays */
3846 for (unsigned i
= 0; i
< ARRAY_SIZE(vao
->VertexAttrib
); i
++) {
3848 case VERT_ATTRIB_NORMAL
:
3849 init_array(ctx
, vao
, VERT_ATTRIB_NORMAL
, 3, GL_FLOAT
);
3851 case VERT_ATTRIB_COLOR1
:
3852 init_array(ctx
, vao
, VERT_ATTRIB_COLOR1
, 3, GL_FLOAT
);
3854 case VERT_ATTRIB_FOG
:
3855 init_array(ctx
, vao
, VERT_ATTRIB_FOG
, 1, GL_FLOAT
);
3857 case VERT_ATTRIB_COLOR_INDEX
:
3858 init_array(ctx
, vao
, VERT_ATTRIB_COLOR_INDEX
, 1, GL_FLOAT
);
3860 case VERT_ATTRIB_EDGEFLAG
:
3861 init_array(ctx
, vao
, VERT_ATTRIB_EDGEFLAG
, 1, GL_UNSIGNED_BYTE
);
3863 case VERT_ATTRIB_POINT_SIZE
:
3864 init_array(ctx
, vao
, VERT_ATTRIB_POINT_SIZE
, 1, GL_FLOAT
);
3867 init_array(ctx
, vao
, i
, 4, GL_FLOAT
);
3872 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_IDENTITY
;
3876 * Initialize vertex array state for given context.
3879 _mesa_init_varray(struct gl_context
*ctx
)
3881 init_default_vao_state(ctx
);
3883 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
3884 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
3885 ctx
->Array
._EmptyVAO
= _mesa_new_vao(ctx
, ~0u);
3886 _mesa_reference_vao(ctx
, &ctx
->Array
._DrawVAO
, ctx
->Array
._EmptyVAO
);
3887 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
3889 ctx
->Array
.Objects
= _mesa_NewHashTable();
3894 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
3897 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
3899 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
3900 struct gl_context
*ctx
= (struct gl_context
*) userData
;
3901 _mesa_delete_vao(ctx
, vao
);
3906 * Free vertex array state for given context.
3909 _mesa_free_varray_data(struct gl_context
*ctx
)
3911 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
3912 _mesa_DeleteHashTable(ctx
->Array
.Objects
);
3916 _mesa_GetVertexArrayIntegervEXT(GLuint vaobj
, GLenum pname
, GLint
*param
)
3918 GET_CURRENT_CONTEXT(ctx
);
3919 struct gl_vertex_array_object
* vao
;
3920 struct gl_buffer_object
*buf
;
3923 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
3924 "glGetVertexArrayIntegervEXT");
3928 /* The EXT_direct_state_access spec says:
3930 * "For GetVertexArrayIntegervEXT, pname must be one of the "Get value" tokens
3931 * in tables 6.6, 6.7, 6.8, and 6.9 that use GetIntegerv, IsEnabled, or
3932 * GetPointerv for their "Get command" (so excluding the VERTEX_ATTRIB_*
3936 /* Tokens using GetIntegerv */
3937 case GL_CLIENT_ACTIVE_TEXTURE
:
3938 *param
= GL_TEXTURE0_ARB
+ ctx
->Array
.ActiveTexture
;
3940 case GL_VERTEX_ARRAY_SIZE
:
3941 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Format
.Size
;
3943 case GL_VERTEX_ARRAY_TYPE
:
3944 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Format
.Type
;
3946 case GL_VERTEX_ARRAY_STRIDE
:
3947 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Stride
;
3949 case GL_VERTEX_ARRAY_BUFFER_BINDING
:
3950 buf
= vao
->BufferBinding
[VERT_ATTRIB_POS
].BufferObj
;
3951 *param
= buf
? buf
->Name
: 0;
3953 case GL_COLOR_ARRAY_SIZE
:
3954 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Format
.Size
;
3956 case GL_COLOR_ARRAY_TYPE
:
3957 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Format
.Type
;
3959 case GL_COLOR_ARRAY_STRIDE
:
3960 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Stride
;
3962 case GL_COLOR_ARRAY_BUFFER_BINDING
:
3963 buf
= vao
->BufferBinding
[VERT_ATTRIB_COLOR0
].BufferObj
;
3964 *param
= buf
? buf
->Name
: 0;
3966 case GL_EDGE_FLAG_ARRAY_STRIDE
:
3967 *param
= vao
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Stride
;
3969 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING
:
3970 buf
= vao
->BufferBinding
[VERT_ATTRIB_EDGEFLAG
].BufferObj
;
3971 *param
= buf
? buf
->Name
: 0;
3973 case GL_INDEX_ARRAY_TYPE
:
3974 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Format
.Type
;
3976 case GL_INDEX_ARRAY_STRIDE
:
3977 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Stride
;
3979 case GL_INDEX_ARRAY_BUFFER_BINDING
:
3980 buf
= vao
->BufferBinding
[VERT_ATTRIB_COLOR_INDEX
].BufferObj
;
3981 *param
= buf
? buf
->Name
: 0;
3983 case GL_NORMAL_ARRAY_TYPE
:
3984 *param
= vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Format
.Type
;
3986 case GL_NORMAL_ARRAY_STRIDE
:
3987 *param
= vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Stride
;
3989 case GL_NORMAL_ARRAY_BUFFER_BINDING
:
3990 buf
= vao
->BufferBinding
[VERT_ATTRIB_NORMAL
].BufferObj
;
3991 *param
= buf
? buf
->Name
: 0;
3993 case GL_TEXTURE_COORD_ARRAY_SIZE
:
3994 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Format
.Size
;
3996 case GL_TEXTURE_COORD_ARRAY_TYPE
:
3997 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Format
.Type
;
3999 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
4000 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Stride
;
4002 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING
:
4003 buf
= vao
->BufferBinding
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].BufferObj
;
4004 *param
= buf
? buf
->Name
: 0;
4006 case GL_FOG_COORD_ARRAY_TYPE
:
4007 *param
= vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Format
.Type
;
4009 case GL_FOG_COORD_ARRAY_STRIDE
:
4010 *param
= vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Stride
;
4012 case GL_FOG_COORD_ARRAY_BUFFER_BINDING
:
4013 buf
= vao
->BufferBinding
[VERT_ATTRIB_FOG
].BufferObj
;
4014 *param
= buf
? buf
->Name
: 0;
4016 case GL_SECONDARY_COLOR_ARRAY_SIZE
:
4017 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Format
.Size
;
4019 case GL_SECONDARY_COLOR_ARRAY_TYPE
:
4020 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Format
.Type
;
4022 case GL_SECONDARY_COLOR_ARRAY_STRIDE
:
4023 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Stride
;
4025 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING
:
4026 buf
= vao
->BufferBinding
[VERT_ATTRIB_COLOR1
].BufferObj
;
4027 *param
= buf
? buf
->Name
: 0;
4030 /* Tokens using IsEnabled */
4031 case GL_VERTEX_ARRAY
:
4032 *param
= !!(vao
->Enabled
& VERT_BIT_POS
);
4034 case GL_COLOR_ARRAY
:
4035 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR0
);
4037 case GL_EDGE_FLAG_ARRAY
:
4038 *param
= !!(vao
->Enabled
& VERT_BIT_EDGEFLAG
);
4040 case GL_INDEX_ARRAY
:
4041 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR_INDEX
);
4043 case GL_NORMAL_ARRAY
:
4044 *param
= !!(vao
->Enabled
& VERT_BIT_NORMAL
);
4046 case GL_TEXTURE_COORD_ARRAY
:
4047 *param
= !!(vao
->Enabled
& VERT_BIT_TEX(ctx
->Array
.ActiveTexture
));
4049 case GL_FOG_COORD_ARRAY
:
4050 *param
= !!(vao
->Enabled
& VERT_BIT_FOG
);
4052 case GL_SECONDARY_COLOR_ARRAY
:
4053 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR1
);
4056 /* Tokens using GetPointerv */
4057 case GL_VERTEX_ARRAY_POINTER
:
4058 case GL_COLOR_ARRAY_POINTER
:
4059 case GL_EDGE_FLAG_ARRAY_POINTER
:
4060 case GL_INDEX_ARRAY_POINTER
:
4061 case GL_NORMAL_ARRAY_POINTER
:
4062 case GL_TEXTURE_COORD_ARRAY_POINTER
:
4063 case GL_FOG_COORD_ARRAY_POINTER
:
4064 case GL_SECONDARY_COLOR_ARRAY_POINTER
:
4065 _get_vao_pointerv(pname
, vao
, &ptr
, "glGetVertexArrayIntegervEXT");
4066 *param
= (int) ((intptr_t) ptr
& 0xFFFFFFFF);
4070 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIntegervEXT(pname)");
4075 _mesa_GetVertexArrayPointervEXT(GLuint vaobj
, GLenum pname
, GLvoid
** param
)
4077 GET_CURRENT_CONTEXT(ctx
);
4078 struct gl_vertex_array_object
* vao
;
4080 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
4081 "glGetVertexArrayPointervEXT");
4085 /* The EXT_direct_state_access spec says:
4087 * "For GetVertexArrayPointervEXT, pname must be a *_ARRAY_POINTER token from
4088 * tables 6.6, 6.7, and 6.8 excluding VERTEX_ATTRIB_ARRAY_POINT."
4091 case GL_VERTEX_ARRAY_POINTER
:
4092 case GL_COLOR_ARRAY_POINTER
:
4093 case GL_EDGE_FLAG_ARRAY_POINTER
:
4094 case GL_INDEX_ARRAY_POINTER
:
4095 case GL_NORMAL_ARRAY_POINTER
:
4096 case GL_TEXTURE_COORD_ARRAY_POINTER
:
4097 case GL_FOG_COORD_ARRAY_POINTER
:
4098 case GL_SECONDARY_COLOR_ARRAY_POINTER
:
4102 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayPointervEXT(pname)");
4106 /* pname has been validated, we can now use the helper function */
4107 _get_vao_pointerv(pname
, vao
, param
, "glGetVertexArrayPointervEXT");
4111 _mesa_GetVertexArrayIntegeri_vEXT(GLuint vaobj
, GLuint index
, GLenum pname
, GLint
*param
)
4113 GET_CURRENT_CONTEXT(ctx
);
4114 struct gl_vertex_array_object
* vao
;
4115 struct gl_buffer_object
*buf
;
4117 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
4118 "glGetVertexArrayIntegeri_vEXT");
4123 /* The EXT_direct_state_access spec says:
4125 * "For GetVertexArrayIntegeri_vEXT, pname must be one of the
4126 * "Get value" tokens in tables 6.8 and 6.9 that use GetVertexAttribiv
4127 * or GetVertexAttribPointerv (so allowing only the VERTEX_ATTRIB_*
4128 * tokens) or a token of the form TEXTURE_COORD_ARRAY (the enable) or
4129 * TEXTURE_COORD_ARRAY_*; index identifies the vertex attribute
4130 * array to query or texture coordinate set index respectively."
4134 case GL_TEXTURE_COORD_ARRAY
:
4135 *param
= !!(vao
->Enabled
& VERT_BIT_TEX(index
));
4137 case GL_TEXTURE_COORD_ARRAY_SIZE
:
4138 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Format
.Size
;
4140 case GL_TEXTURE_COORD_ARRAY_TYPE
:
4141 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Format
.Type
;
4143 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
4144 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Stride
;
4146 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING
:
4147 buf
= vao
->BufferBinding
[VERT_ATTRIB_TEX(index
)].BufferObj
;
4148 *param
= buf
? buf
->Name
: 0;
4151 *param
= get_vertex_array_attrib(ctx
, vao
, index
, pname
, "glGetVertexArrayIntegeri_vEXT");
4156 _mesa_GetVertexArrayPointeri_vEXT(GLuint vaobj
, GLuint index
, GLenum pname
, GLvoid
** param
)
4158 GET_CURRENT_CONTEXT(ctx
);
4159 struct gl_vertex_array_object
* vao
;
4161 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
4162 "glGetVertexArrayPointeri_vEXT");
4166 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
4167 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayPointeri_vEXT(index)");
4171 /* The EXT_direct_state_access spec says:
4173 * "For GetVertexArrayPointeri_vEXT, pname must be VERTEX_ATTRIB_ARRAY_POINTER
4174 * or TEXTURE_COORD_ARRAY_POINTER with the index parameter indicating the vertex
4175 * attribute or texture coordindate set index."
4178 case GL_VERTEX_ATTRIB_ARRAY_POINTER
:
4179 *param
= (GLvoid
*) vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
4181 case GL_TEXTURE_COORD_ARRAY_POINTER
:
4182 *param
= (GLvoid
*) vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Ptr
;
4185 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayPointeri_vEXT(pname)");