2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 #include <inttypes.h> /* for PRId64 macro */
31 #include "util/imports.h"
32 #include "bufferobj.h"
36 #include "glformats.h"
44 #include "main/dispatch.h"
47 /** Used to do error checking for GL_EXT_vertex_array_bgra */
51 /** Used to indicate which GL datatypes are accepted by each of the
52 * glVertex/Color/Attrib/EtcPointer() functions.
54 #define BOOL_BIT (1 << 0)
55 #define BYTE_BIT (1 << 1)
56 #define UNSIGNED_BYTE_BIT (1 << 2)
57 #define SHORT_BIT (1 << 3)
58 #define UNSIGNED_SHORT_BIT (1 << 4)
59 #define INT_BIT (1 << 5)
60 #define UNSIGNED_INT_BIT (1 << 6)
61 #define HALF_BIT (1 << 7)
62 #define FLOAT_BIT (1 << 8)
63 #define DOUBLE_BIT (1 << 9)
64 #define FIXED_ES_BIT (1 << 10)
65 #define FIXED_GL_BIT (1 << 11)
66 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
67 #define INT_2_10_10_10_REV_BIT (1 << 13)
68 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
69 #define ALL_TYPE_BITS ((1 << 15) - 1)
71 #define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
72 SHORT_BIT | UNSIGNED_SHORT_BIT | \
73 INT_BIT | UNSIGNED_INT_BIT | \
74 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
76 UNSIGNED_INT_2_10_10_10_REV_BIT | \
77 INT_2_10_10_10_REV_BIT | \
78 UNSIGNED_INT_10F_11F_11F_REV_BIT)
80 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
81 SHORT_BIT | UNSIGNED_SHORT_BIT | \
82 INT_BIT | UNSIGNED_INT_BIT)
84 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
87 /** Convert GL datatype enum into a <type>_BIT value seen above */
89 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
96 case GL_UNSIGNED_BYTE
:
97 return UNSIGNED_BYTE_BIT
;
100 case GL_UNSIGNED_SHORT
:
101 return UNSIGNED_SHORT_BIT
;
104 case GL_UNSIGNED_INT
:
105 return UNSIGNED_INT_BIT
;
107 case GL_HALF_FLOAT_OES
:
108 if (ctx
->Extensions
.ARB_half_float_vertex
)
117 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
118 case GL_UNSIGNED_INT_2_10_10_10_REV
:
119 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
120 case GL_INT_2_10_10_10_REV
:
121 return INT_2_10_10_10_REV_BIT
;
122 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
123 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
131 * Depending on the position and generic0 attributes enable flags select
132 * the one that is used for both attributes.
133 * The generic0 attribute takes precedence.
136 update_attribute_map_mode(const struct gl_context
*ctx
,
137 struct gl_vertex_array_object
*vao
)
140 * There is no need to change the mapping away from the
141 * identity mapping if we are not in compat mode.
143 if (ctx
->API
!= API_OPENGL_COMPAT
)
145 /* The generic0 attribute superseeds the position attribute */
146 const GLbitfield enabled
= vao
->Enabled
;
147 if (enabled
& VERT_BIT_GENERIC0
)
148 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_GENERIC0
;
149 else if (enabled
& VERT_BIT_POS
)
150 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_POSITION
;
152 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_IDENTITY
;
157 * Sets the BufferBindingIndex field for the vertex attribute given by
161 _mesa_vertex_attrib_binding(struct gl_context
*ctx
,
162 struct gl_vertex_array_object
*vao
,
163 gl_vert_attrib attribIndex
,
166 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attribIndex
];
167 assert(!vao
->SharedAndImmutable
);
169 if (array
->BufferBindingIndex
!= bindingIndex
) {
170 const GLbitfield array_bit
= VERT_BIT(attribIndex
);
172 if (_mesa_is_bufferobj(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 assert(vbo
!= ctx
->Shared
->NullBufferObj
);
209 if (ctx
->Const
.VertexBufferOffsetIsInt32
&& (int)offset
< 0 &&
210 _mesa_is_bufferobj(vbo
)) {
211 /* The offset will be interpreted as a signed int, so make sure
212 * the user supplied offset is not negative (driver limitation).
214 _mesa_warning(ctx
, "Received negative int32 vertex buffer offset. "
215 "(driver limitation)\n");
217 /* We can't disable this binding, so use a non-negative offset value
223 if (binding
->BufferObj
!= vbo
||
224 binding
->Offset
!= offset
||
225 binding
->Stride
!= stride
) {
227 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
229 binding
->Offset
= offset
;
230 binding
->Stride
= stride
;
232 if (!_mesa_is_bufferobj(vbo
)) {
233 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
235 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
236 vbo
->UsageHistory
|= USAGE_ARRAY_BUFFER
;
239 vao
->NewArrays
|= vao
->Enabled
& binding
->_BoundArrays
;
245 * Sets the InstanceDivisor field in the vertex buffer binding point
246 * given by bindingIndex.
249 vertex_binding_divisor(struct gl_context
*ctx
,
250 struct gl_vertex_array_object
*vao
,
254 struct gl_vertex_buffer_binding
*binding
=
255 &vao
->BufferBinding
[bindingIndex
];
256 assert(!vao
->SharedAndImmutable
);
258 if (binding
->InstanceDivisor
!= divisor
) {
259 binding
->InstanceDivisor
= divisor
;
262 vao
->NonZeroDivisorMask
|= binding
->_BoundArrays
;
264 vao
->NonZeroDivisorMask
&= ~binding
->_BoundArrays
;
266 vao
->NewArrays
|= vao
->Enabled
& binding
->_BoundArrays
;
270 /* vertex_formats[gltype - GL_BYTE][integer*2 + normalized][size - 1] */
271 static const uint16_t vertex_formats
[][4][4] = {
274 PIPE_FORMAT_R8_SSCALED
,
275 PIPE_FORMAT_R8G8_SSCALED
,
276 PIPE_FORMAT_R8G8B8_SSCALED
,
277 PIPE_FORMAT_R8G8B8A8_SSCALED
280 PIPE_FORMAT_R8_SNORM
,
281 PIPE_FORMAT_R8G8_SNORM
,
282 PIPE_FORMAT_R8G8B8_SNORM
,
283 PIPE_FORMAT_R8G8B8A8_SNORM
287 PIPE_FORMAT_R8G8_SINT
,
288 PIPE_FORMAT_R8G8B8_SINT
,
289 PIPE_FORMAT_R8G8B8A8_SINT
292 { /* GL_UNSIGNED_BYTE */
294 PIPE_FORMAT_R8_USCALED
,
295 PIPE_FORMAT_R8G8_USCALED
,
296 PIPE_FORMAT_R8G8B8_USCALED
,
297 PIPE_FORMAT_R8G8B8A8_USCALED
300 PIPE_FORMAT_R8_UNORM
,
301 PIPE_FORMAT_R8G8_UNORM
,
302 PIPE_FORMAT_R8G8B8_UNORM
,
303 PIPE_FORMAT_R8G8B8A8_UNORM
307 PIPE_FORMAT_R8G8_UINT
,
308 PIPE_FORMAT_R8G8B8_UINT
,
309 PIPE_FORMAT_R8G8B8A8_UINT
314 PIPE_FORMAT_R16_SSCALED
,
315 PIPE_FORMAT_R16G16_SSCALED
,
316 PIPE_FORMAT_R16G16B16_SSCALED
,
317 PIPE_FORMAT_R16G16B16A16_SSCALED
320 PIPE_FORMAT_R16_SNORM
,
321 PIPE_FORMAT_R16G16_SNORM
,
322 PIPE_FORMAT_R16G16B16_SNORM
,
323 PIPE_FORMAT_R16G16B16A16_SNORM
326 PIPE_FORMAT_R16_SINT
,
327 PIPE_FORMAT_R16G16_SINT
,
328 PIPE_FORMAT_R16G16B16_SINT
,
329 PIPE_FORMAT_R16G16B16A16_SINT
332 { /* GL_UNSIGNED_SHORT */
334 PIPE_FORMAT_R16_USCALED
,
335 PIPE_FORMAT_R16G16_USCALED
,
336 PIPE_FORMAT_R16G16B16_USCALED
,
337 PIPE_FORMAT_R16G16B16A16_USCALED
340 PIPE_FORMAT_R16_UNORM
,
341 PIPE_FORMAT_R16G16_UNORM
,
342 PIPE_FORMAT_R16G16B16_UNORM
,
343 PIPE_FORMAT_R16G16B16A16_UNORM
346 PIPE_FORMAT_R16_UINT
,
347 PIPE_FORMAT_R16G16_UINT
,
348 PIPE_FORMAT_R16G16B16_UINT
,
349 PIPE_FORMAT_R16G16B16A16_UINT
354 PIPE_FORMAT_R32_SSCALED
,
355 PIPE_FORMAT_R32G32_SSCALED
,
356 PIPE_FORMAT_R32G32B32_SSCALED
,
357 PIPE_FORMAT_R32G32B32A32_SSCALED
360 PIPE_FORMAT_R32_SNORM
,
361 PIPE_FORMAT_R32G32_SNORM
,
362 PIPE_FORMAT_R32G32B32_SNORM
,
363 PIPE_FORMAT_R32G32B32A32_SNORM
366 PIPE_FORMAT_R32_SINT
,
367 PIPE_FORMAT_R32G32_SINT
,
368 PIPE_FORMAT_R32G32B32_SINT
,
369 PIPE_FORMAT_R32G32B32A32_SINT
372 { /* GL_UNSIGNED_INT */
374 PIPE_FORMAT_R32_USCALED
,
375 PIPE_FORMAT_R32G32_USCALED
,
376 PIPE_FORMAT_R32G32B32_USCALED
,
377 PIPE_FORMAT_R32G32B32A32_USCALED
380 PIPE_FORMAT_R32_UNORM
,
381 PIPE_FORMAT_R32G32_UNORM
,
382 PIPE_FORMAT_R32G32B32_UNORM
,
383 PIPE_FORMAT_R32G32B32A32_UNORM
386 PIPE_FORMAT_R32_UINT
,
387 PIPE_FORMAT_R32G32_UINT
,
388 PIPE_FORMAT_R32G32B32_UINT
,
389 PIPE_FORMAT_R32G32B32A32_UINT
394 PIPE_FORMAT_R32_FLOAT
,
395 PIPE_FORMAT_R32G32_FLOAT
,
396 PIPE_FORMAT_R32G32B32_FLOAT
,
397 PIPE_FORMAT_R32G32B32A32_FLOAT
400 PIPE_FORMAT_R32_FLOAT
,
401 PIPE_FORMAT_R32G32_FLOAT
,
402 PIPE_FORMAT_R32G32B32_FLOAT
,
403 PIPE_FORMAT_R32G32B32A32_FLOAT
406 {{0}}, /* GL_2_BYTES */
407 {{0}}, /* GL_3_BYTES */
408 {{0}}, /* GL_4_BYTES */
411 PIPE_FORMAT_R64_FLOAT
,
412 PIPE_FORMAT_R64G64_FLOAT
,
413 PIPE_FORMAT_R64G64B64_FLOAT
,
414 PIPE_FORMAT_R64G64B64A64_FLOAT
417 PIPE_FORMAT_R64_FLOAT
,
418 PIPE_FORMAT_R64G64_FLOAT
,
419 PIPE_FORMAT_R64G64B64_FLOAT
,
420 PIPE_FORMAT_R64G64B64A64_FLOAT
423 { /* GL_HALF_FLOAT */
425 PIPE_FORMAT_R16_FLOAT
,
426 PIPE_FORMAT_R16G16_FLOAT
,
427 PIPE_FORMAT_R16G16B16_FLOAT
,
428 PIPE_FORMAT_R16G16B16A16_FLOAT
431 PIPE_FORMAT_R16_FLOAT
,
432 PIPE_FORMAT_R16G16_FLOAT
,
433 PIPE_FORMAT_R16G16B16_FLOAT
,
434 PIPE_FORMAT_R16G16B16A16_FLOAT
439 PIPE_FORMAT_R32_FIXED
,
440 PIPE_FORMAT_R32G32_FIXED
,
441 PIPE_FORMAT_R32G32B32_FIXED
,
442 PIPE_FORMAT_R32G32B32A32_FIXED
445 PIPE_FORMAT_R32_FIXED
,
446 PIPE_FORMAT_R32G32_FIXED
,
447 PIPE_FORMAT_R32G32B32_FIXED
,
448 PIPE_FORMAT_R32G32B32A32_FIXED
454 * Return a PIPE_FORMAT_x for the given GL datatype and size.
456 static enum pipe_format
457 vertex_format_to_pipe_format(GLubyte size
, GLenum16 type
, GLenum16 format
,
458 GLboolean normalized
, GLboolean integer
,
461 assert(size
>= 1 && size
<= 4);
462 assert(format
== GL_RGBA
|| format
== GL_BGRA
);
464 /* 64-bit attributes are translated by drivers. */
466 return PIPE_FORMAT_NONE
;
469 case GL_HALF_FLOAT_OES
:
470 type
= GL_HALF_FLOAT
;
473 case GL_INT_2_10_10_10_REV
:
474 assert(size
== 4 && !integer
);
476 if (format
== GL_BGRA
) {
478 return PIPE_FORMAT_B10G10R10A2_SNORM
;
480 return PIPE_FORMAT_B10G10R10A2_SSCALED
;
483 return PIPE_FORMAT_R10G10B10A2_SNORM
;
485 return PIPE_FORMAT_R10G10B10A2_SSCALED
;
489 case GL_UNSIGNED_INT_2_10_10_10_REV
:
490 assert(size
== 4 && !integer
);
492 if (format
== GL_BGRA
) {
494 return PIPE_FORMAT_B10G10R10A2_UNORM
;
496 return PIPE_FORMAT_B10G10R10A2_USCALED
;
499 return PIPE_FORMAT_R10G10B10A2_UNORM
;
501 return PIPE_FORMAT_R10G10B10A2_USCALED
;
505 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
506 assert(size
== 3 && !integer
&& format
== GL_RGBA
);
507 return PIPE_FORMAT_R11G11B10_FLOAT
;
509 case GL_UNSIGNED_BYTE
:
510 if (format
== GL_BGRA
) {
511 /* this is an odd-ball case */
513 return PIPE_FORMAT_B8G8R8A8_UNORM
;
518 unsigned index
= integer
*2 + normalized
;
520 assert(type
>= GL_BYTE
&& type
<= GL_FIXED
);
521 return vertex_formats
[type
- GL_BYTE
][index
][size
-1];
525 _mesa_set_vertex_format(struct gl_vertex_format
*vertex_format
,
526 GLubyte size
, GLenum16 type
, GLenum16 format
,
527 GLboolean normalized
, GLboolean integer
,
531 vertex_format
->Type
= type
;
532 vertex_format
->Format
= format
;
533 vertex_format
->Size
= size
;
534 vertex_format
->Normalized
= normalized
;
535 vertex_format
->Integer
= integer
;
536 vertex_format
->Doubles
= doubles
;
537 vertex_format
->_ElementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
538 assert(vertex_format
->_ElementSize
<= 4*sizeof(double));
539 vertex_format
->_PipeFormat
=
540 vertex_format_to_pipe_format(size
, type
, format
, normalized
, integer
,
546 * Examine the API profile and extensions to determine which types are legal
547 * for vertex arrays. This is called once from update_array_format().
550 get_legal_types_mask(const struct gl_context
*ctx
)
552 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
554 if (_mesa_is_gles(ctx
)) {
555 legalTypesMask
&= ~(FIXED_GL_BIT
|
557 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
559 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
560 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
561 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
562 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
563 * quite as trivial as we'd like because it uses a different enum value
564 * for GL_HALF_FLOAT_OES.
566 if (ctx
->Version
< 30) {
567 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
569 UNSIGNED_INT_2_10_10_10_REV_BIT
|
570 INT_2_10_10_10_REV_BIT
);
572 if (!_mesa_has_OES_vertex_half_float(ctx
))
573 legalTypesMask
&= ~HALF_BIT
;
577 legalTypesMask
&= ~FIXED_ES_BIT
;
579 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
580 legalTypesMask
&= ~FIXED_GL_BIT
;
582 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
583 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
584 INT_2_10_10_10_REV_BIT
);
586 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
587 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
590 return legalTypesMask
;
594 get_array_format(const struct gl_context
*ctx
, GLint sizeMax
, GLint
*size
)
596 GLenum format
= GL_RGBA
;
598 /* Do size parameter checking.
599 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
600 * must be handled specially.
602 if (ctx
->Extensions
.EXT_vertex_array_bgra
&& sizeMax
== BGRA_OR_4
&&
613 * \param attrib The index of the attribute array
614 * \param size Components per element (1, 2, 3 or 4)
615 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
616 * \param format Either GL_RGBA or GL_BGRA.
617 * \param normalized Whether integer types are converted to floats in [-1, 1]
618 * \param integer Integer-valued values (will not be normalized to [-1, 1])
619 * \param doubles Double values not reduced to floats
620 * \param relativeOffset Offset of the first element relative to the binding
624 _mesa_update_array_format(struct gl_context
*ctx
,
625 struct gl_vertex_array_object
*vao
,
626 gl_vert_attrib attrib
, GLint size
, GLenum type
,
627 GLenum format
, GLboolean normalized
,
628 GLboolean integer
, GLboolean doubles
,
629 GLuint relativeOffset
)
631 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
633 assert(!vao
->SharedAndImmutable
);
636 array
->RelativeOffset
= relativeOffset
;
637 _mesa_set_vertex_format(&array
->Format
, size
, type
, format
,
638 normalized
, integer
, doubles
);
640 vao
->NewArrays
|= vao
->Enabled
& VERT_BIT(attrib
);
644 * Does error checking of the format in an attrib array.
646 * Called by *Pointer() and VertexAttrib*Format().
648 * \param func Name of calling function used for error reporting
649 * \param attrib The index of the attribute array
650 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
651 * \param sizeMin Min allowable size value
652 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
653 * \param size Components per element (1, 2, 3 or 4)
654 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
655 * \param normalized Whether integer types are converted to floats in [-1, 1]
656 * \param integer Integer-valued values (will not be normalized to [-1, 1])
657 * \param doubles Double values not reduced to floats
658 * \param relativeOffset Offset of the first element relative to the binding offset.
659 * \return bool True if validation is successful, False otherwise.
662 validate_array_format(struct gl_context
*ctx
, const char *func
,
663 struct gl_vertex_array_object
*vao
,
664 GLuint attrib
, GLbitfield legalTypesMask
,
665 GLint sizeMin
, GLint sizeMax
,
666 GLint size
, GLenum type
, GLboolean normalized
,
667 GLboolean integer
, GLboolean doubles
,
668 GLuint relativeOffset
, GLenum format
)
672 /* at most, one of these bools can be true */
673 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
675 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
676 /* Compute the LegalTypesMask only once, unless the context API has
677 * changed, in which case we want to compute it again. We can't do this
678 * in _mesa_init_varrays() below because extensions are not yet enabled
681 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
682 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
685 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
687 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
688 /* BGRA ordering is not supported in ES contexts.
693 typeBit
= type_to_bit(ctx
, type
);
694 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
695 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
696 func
, _mesa_enum_to_string(type
));
700 if (format
== GL_BGRA
) {
701 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
703 * "An INVALID_OPERATION error is generated under any of the following
706 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
707 * or UNSIGNED_INT_2_10_10_10_REV;
709 * • size is BGRA and normalized is FALSE;"
711 bool bgra_error
= false;
713 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
714 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
715 type
!= GL_INT_2_10_10_10_REV
&&
716 type
!= GL_UNSIGNED_BYTE
)
718 } else if (type
!= GL_UNSIGNED_BYTE
)
722 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
723 func
, _mesa_enum_to_string(type
));
728 _mesa_error(ctx
, GL_INVALID_OPERATION
,
729 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
733 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
734 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
738 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
739 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
740 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
741 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
745 /* The ARB_vertex_attrib_binding_spec says:
747 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
748 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
750 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
751 _mesa_error(ctx
, GL_INVALID_VALUE
,
752 "%s(relativeOffset=%d > "
753 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
754 func
, relativeOffset
);
758 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
759 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
760 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
768 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
770 * \param func name of calling function used for error reporting
771 * \param vao the vao to update
772 * \param obj the bound buffer object
773 * \param attrib the attribute array index to update
774 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
775 * \param sizeMin min allowable size value
776 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
777 * \param size components per element (1, 2, 3 or 4)
778 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
779 * \param stride stride between elements, in elements
780 * \param normalized are integer types converted to floats in [-1, 1]?
781 * \param integer integer-valued values (will not be normalized to [-1,1])
782 * \param doubles Double values not reduced to floats
783 * \param ptr the address (or offset inside VBO) of the array data
786 validate_array(struct gl_context
*ctx
, const char *func
,
787 struct gl_vertex_array_object
*vao
,
788 struct gl_buffer_object
*obj
,
789 GLuint attrib
, GLbitfield legalTypesMask
,
790 GLint sizeMin
, GLint sizeMax
,
791 GLint size
, GLenum type
, GLsizei stride
,
792 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
795 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
797 * "Client vertex arrays - all vertex array attribute pointers must
798 * refer to buffer objects (section 2.9.2). The default vertex array
799 * object (the name zero) is also deprecated. Calling
800 * VertexAttribPointer when no buffer object or no vertex array object
801 * is bound will generate an INVALID_OPERATION error..."
803 * The check for VBOs is handled below.
805 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
806 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
812 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
816 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
817 stride
> ctx
->Const
.MaxVertexAttribStride
) {
818 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
819 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
823 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
825 * "An INVALID_OPERATION error is generated under any of the following
830 * * any of the *Pointer commands specifying the location and
831 * organization of vertex array data are called while zero is bound
832 * to the ARRAY_BUFFER buffer object binding point (see section
833 * 2.9.6), and the pointer argument is not NULL."
835 if (ptr
!= NULL
&& vao
!= ctx
->Array
.DefaultVAO
&&
836 !_mesa_is_bufferobj(obj
)) {
837 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
844 validate_array_and_format(struct gl_context
*ctx
, const char *func
,
845 struct gl_vertex_array_object
*vao
,
846 struct gl_buffer_object
*obj
,
847 GLuint attrib
, GLbitfield legalTypes
,
848 GLint sizeMin
, GLint sizeMax
,
849 GLint size
, GLenum type
, GLsizei stride
,
850 GLboolean normalized
, GLboolean integer
,
851 GLboolean doubles
, GLenum format
, const GLvoid
*ptr
)
853 validate_array(ctx
, func
, vao
, obj
, attrib
, legalTypes
, sizeMin
, sizeMax
,
854 size
, type
, stride
, normalized
, integer
, doubles
, ptr
);
856 return validate_array_format(ctx
, func
, vao
, attrib
, legalTypes
, sizeMin
,
857 sizeMax
, size
, type
, normalized
, integer
,
863 * Update state for glVertex/Color/TexCoord/...Pointer functions.
865 * \param vao the vao to update
866 * \param obj the bound buffer object
867 * \param attrib the attribute array index to update
868 * \param format Either GL_RGBA or GL_BGRA.
869 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
870 * \param size components per element (1, 2, 3 or 4)
871 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
872 * \param stride stride between elements, in elements
873 * \param normalized are integer types converted to floats in [-1, 1]?
874 * \param integer integer-valued values (will not be normalized to [-1,1])
875 * \param doubles Double values not reduced to floats
876 * \param ptr the address (or offset inside VBO) of the array data
879 update_array(struct gl_context
*ctx
,
880 struct gl_vertex_array_object
*vao
,
881 struct gl_buffer_object
*obj
,
882 GLuint attrib
, GLenum format
,
884 GLint size
, GLenum type
, GLsizei stride
,
885 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
888 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
889 normalized
, integer
, doubles
, 0);
891 /* Reset the vertex attrib binding */
892 _mesa_vertex_attrib_binding(ctx
, vao
, attrib
, attrib
);
894 /* The Stride and Ptr fields are not set by update_array_format() */
895 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attrib
];
896 array
->Stride
= stride
;
897 /* For updating the pointer we would need to add the vao->NewArrays flag
898 * to the VAO. But but that is done already unconditionally in
899 * _mesa_update_array_format called above.
901 assert((vao
->NewArrays
| ~vao
->Enabled
) & VERT_BIT(attrib
));
904 /* TODO: remove this hack by not using NullBufferObj in callers */
905 if (obj
== ctx
->Shared
->NullBufferObj
)
908 /* Update the vertex buffer binding */
909 GLsizei effectiveStride
= stride
!= 0 ?
910 stride
: array
->Format
._ElementSize
;
911 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
917 /* Helper function for all EXT_direct_state_access glVertexArray* functions */
919 _lookup_vao_and_vbo_dsa(struct gl_context
*ctx
,
920 GLuint vaobj
, GLuint buffer
,
922 struct gl_vertex_array_object
** vao
,
923 struct gl_buffer_object
** vbo
,
926 *vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, caller
);
931 *vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
932 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, vbo
, caller
))
936 _mesa_error(ctx
, GL_INVALID_VALUE
,
937 "%s(negative offset with non-0 buffer)", caller
);
949 _mesa_VertexPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
952 GET_CURRENT_CONTEXT(ctx
);
954 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
955 VERT_ATTRIB_POS
, GL_RGBA
, 4, size
, type
, stride
,
956 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
961 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
963 GET_CURRENT_CONTEXT(ctx
);
965 GLenum format
= GL_RGBA
;
966 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
967 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
968 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
969 DOUBLE_BIT
| HALF_BIT
|
970 UNSIGNED_INT_2_10_10_10_REV_BIT
|
971 INT_2_10_10_10_REV_BIT
);
973 if (!validate_array_and_format(ctx
, "glVertexPointer",
974 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
975 VERT_ATTRIB_POS
, legalTypes
, 2, 4, size
,
976 type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
980 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
981 VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
982 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
987 _mesa_VertexArrayVertexOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
988 GLenum type
, GLsizei stride
, GLintptr offset
)
990 GET_CURRENT_CONTEXT(ctx
);
992 GLenum format
= GL_RGBA
;
993 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
994 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
995 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
996 DOUBLE_BIT
| HALF_BIT
|
997 UNSIGNED_INT_2_10_10_10_REV_BIT
|
998 INT_2_10_10_10_REV_BIT
);
1000 struct gl_vertex_array_object
* vao
;
1001 struct gl_buffer_object
* vbo
;
1003 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1005 "glVertexArrayVertexOffsetEXT"))
1008 if (!validate_array_and_format(ctx
, "glVertexArrayVertexOffsetEXT",
1010 VERT_ATTRIB_POS
, legalTypes
, 2, 4, size
,
1011 type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
1012 format
, (void*) offset
))
1015 update_array(ctx
, vao
, vbo
,
1016 VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
1017 GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1022 _mesa_NormalPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1024 GET_CURRENT_CONTEXT(ctx
);
1026 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1027 VERT_ATTRIB_NORMAL
, GL_RGBA
, 3, 3, type
, stride
, GL_TRUE
,
1028 GL_FALSE
, GL_FALSE
, ptr
);
1033 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1035 GET_CURRENT_CONTEXT(ctx
);
1037 GLenum format
= GL_RGBA
;
1038 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1039 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1040 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1041 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1042 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1043 INT_2_10_10_10_REV_BIT
);
1045 if (!validate_array_and_format(ctx
, "glNormalPointer",
1046 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1047 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
1048 type
, stride
, GL_TRUE
, GL_FALSE
,
1049 GL_FALSE
, format
, ptr
))
1052 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1053 VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
1054 GL_FALSE
, GL_FALSE
, ptr
);
1059 _mesa_VertexArrayNormalOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1060 GLsizei stride
, GLintptr offset
)
1062 GET_CURRENT_CONTEXT(ctx
);
1064 GLenum format
= GL_RGBA
;
1065 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1066 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1067 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1068 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1069 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1070 INT_2_10_10_10_REV_BIT
);
1072 struct gl_vertex_array_object
* vao
;
1073 struct gl_buffer_object
* vbo
;
1075 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1080 if (!validate_array_and_format(ctx
, "glNormalPointer",
1082 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
1083 type
, stride
, GL_TRUE
, GL_FALSE
,
1084 GL_FALSE
, format
, (void*) offset
))
1087 update_array(ctx
, vao
, vbo
,
1088 VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
1089 GL_FALSE
, GL_FALSE
, (void*) offset
);
1094 _mesa_ColorPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
1097 GET_CURRENT_CONTEXT(ctx
);
1099 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1100 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1101 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
1102 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1107 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1109 GET_CURRENT_CONTEXT(ctx
);
1110 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
1112 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1113 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1114 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1115 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1116 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1117 INT_BIT
| UNSIGNED_INT_BIT
|
1118 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1119 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1120 INT_2_10_10_10_REV_BIT
);
1122 if (!validate_array_and_format(ctx
, "glColorPointer",
1123 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1124 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
1125 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
1126 GL_FALSE
, GL_FALSE
, format
, ptr
))
1129 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1130 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
1131 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1136 _mesa_VertexArrayColorOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1137 GLenum type
, GLsizei stride
, GLintptr offset
)
1139 GET_CURRENT_CONTEXT(ctx
);
1140 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
1142 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1143 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1144 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1145 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1146 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1147 INT_BIT
| UNSIGNED_INT_BIT
|
1148 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1149 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1150 INT_2_10_10_10_REV_BIT
);
1152 struct gl_vertex_array_object
* vao
;
1153 struct gl_buffer_object
* vbo
;
1155 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1157 "glVertexArrayColorOffsetEXT"))
1160 if (!validate_array_and_format(ctx
, "glVertexArrayColorOffsetEXT",
1162 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
1163 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
1164 GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1167 update_array(ctx
, vao
, vbo
,
1168 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
1169 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1174 _mesa_FogCoordPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1176 GET_CURRENT_CONTEXT(ctx
);
1178 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1179 VERT_ATTRIB_FOG
, GL_RGBA
, 1, 1, type
, stride
, GL_FALSE
,
1180 GL_FALSE
, GL_FALSE
, ptr
);
1185 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1187 GET_CURRENT_CONTEXT(ctx
);
1189 GLenum format
= GL_RGBA
;
1190 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
1192 if (!validate_array_and_format(ctx
, "glFogCoordPointer",
1193 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1194 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
1195 type
, stride
, GL_FALSE
, GL_FALSE
,
1196 GL_FALSE
, format
, ptr
))
1199 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1200 VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
1201 GL_FALSE
, GL_FALSE
, ptr
);
1206 _mesa_VertexArrayFogCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1207 GLsizei stride
, GLintptr offset
)
1209 GET_CURRENT_CONTEXT(ctx
);
1211 GLenum format
= GL_RGBA
;
1212 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
1214 struct gl_vertex_array_object
* vao
;
1215 struct gl_buffer_object
* vbo
;
1217 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1219 "glVertexArrayFogCoordOffsetEXT"))
1222 if (!validate_array_and_format(ctx
, "glVertexArrayFogCoordOffsetEXT",
1224 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
1225 type
, stride
, GL_FALSE
, GL_FALSE
,
1226 GL_FALSE
, format
, (void*) offset
))
1229 update_array(ctx
, vao
, vbo
,
1230 VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
1231 GL_FALSE
, GL_FALSE
, (void*) offset
);
1236 _mesa_IndexPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1238 GET_CURRENT_CONTEXT(ctx
);
1240 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1241 VERT_ATTRIB_COLOR_INDEX
, GL_RGBA
, 1, 1, type
, stride
,
1242 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1247 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1249 GET_CURRENT_CONTEXT(ctx
);
1251 GLenum format
= GL_RGBA
;
1252 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1253 FLOAT_BIT
| DOUBLE_BIT
);
1255 if (!validate_array_and_format(ctx
, "glIndexPointer",
1256 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1257 VERT_ATTRIB_COLOR_INDEX
,
1258 legalTypes
, 1, 1, 1, type
, stride
,
1259 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1262 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1263 VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
1264 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1269 _mesa_VertexArrayIndexOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1270 GLsizei stride
, GLintptr offset
)
1272 GET_CURRENT_CONTEXT(ctx
);
1274 GLenum format
= GL_RGBA
;
1275 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1276 FLOAT_BIT
| DOUBLE_BIT
);
1278 struct gl_vertex_array_object
* vao
;
1279 struct gl_buffer_object
* vbo
;
1281 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1283 "glVertexArrayIndexOffsetEXT"))
1286 if (!validate_array_and_format(ctx
, "glVertexArrayIndexOffsetEXT",
1288 VERT_ATTRIB_COLOR_INDEX
,
1289 legalTypes
, 1, 1, 1, type
, stride
,
1290 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1293 update_array(ctx
, vao
, vbo
,
1294 VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
1295 GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1300 _mesa_SecondaryColorPointer_no_error(GLint size
, GLenum type
,
1301 GLsizei stride
, const GLvoid
*ptr
)
1303 GET_CURRENT_CONTEXT(ctx
);
1305 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1306 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1307 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
1308 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1313 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
1314 GLsizei stride
, const GLvoid
*ptr
)
1316 GET_CURRENT_CONTEXT(ctx
);
1318 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1319 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1320 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1321 INT_BIT
| UNSIGNED_INT_BIT
|
1322 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1323 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1324 INT_2_10_10_10_REV_BIT
);
1326 if (!validate_array_and_format(ctx
, "glSecondaryColorPointer",
1327 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1328 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
1329 BGRA_OR_4
, size
, type
, stride
,
1330 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1333 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1334 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
1335 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1340 _mesa_VertexArraySecondaryColorOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1341 GLenum type
, GLsizei stride
, GLintptr offset
)
1343 GET_CURRENT_CONTEXT(ctx
);
1345 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1346 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1347 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1348 INT_BIT
| UNSIGNED_INT_BIT
|
1349 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1350 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1351 INT_2_10_10_10_REV_BIT
);
1353 struct gl_vertex_array_object
* vao
;
1354 struct gl_buffer_object
* vbo
;
1356 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1358 "glVertexArraySecondaryColorOffsetEXT"))
1361 if (!validate_array_and_format(ctx
, "glVertexArraySecondaryColorOffsetEXT",
1363 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
1364 BGRA_OR_4
, size
, type
, stride
,
1365 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1368 update_array(ctx
, vao
, vbo
,
1369 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
1370 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1375 _mesa_TexCoordPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
1378 GET_CURRENT_CONTEXT(ctx
);
1379 const GLuint unit
= ctx
->Array
.ActiveTexture
;
1381 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1382 VERT_ATTRIB_TEX(unit
), GL_RGBA
, 4, size
, type
,
1383 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1388 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
1391 GET_CURRENT_CONTEXT(ctx
);
1392 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1393 const GLuint unit
= ctx
->Array
.ActiveTexture
;
1395 GLenum format
= GL_RGBA
;
1396 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1397 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1398 : (SHORT_BIT
| INT_BIT
|
1399 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1400 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1401 INT_2_10_10_10_REV_BIT
);
1403 if (!validate_array_and_format(ctx
, "glTexCoordPointer",
1404 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1405 VERT_ATTRIB_TEX(unit
), legalTypes
,
1406 sizeMin
, 4, size
, type
, stride
,
1407 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1410 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1411 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
1412 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1417 _mesa_VertexArrayTexCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1418 GLenum type
, GLsizei stride
, GLintptr offset
)
1420 GET_CURRENT_CONTEXT(ctx
);
1421 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1422 const GLuint unit
= ctx
->Array
.ActiveTexture
;
1424 GLenum format
= GL_RGBA
;
1425 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1426 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1427 : (SHORT_BIT
| INT_BIT
|
1428 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1429 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1430 INT_2_10_10_10_REV_BIT
);
1432 struct gl_vertex_array_object
* vao
;
1433 struct gl_buffer_object
* vbo
;
1435 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1437 "glVertexArrayTexCoordOffsetEXT"))
1440 if (!validate_array_and_format(ctx
, "glVertexArrayTexCoordOffsetEXT",
1442 VERT_ATTRIB_TEX(unit
), legalTypes
,
1443 sizeMin
, 4, size
, type
, stride
,
1444 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1447 update_array(ctx
, vao
, vbo
,
1448 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
1449 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1454 _mesa_VertexArrayMultiTexCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum texunit
,
1455 GLint size
, GLenum type
, GLsizei stride
,
1458 GET_CURRENT_CONTEXT(ctx
);
1459 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1460 const GLuint unit
= texunit
- GL_TEXTURE0
;
1462 GLenum format
= GL_RGBA
;
1463 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1464 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1465 : (SHORT_BIT
| INT_BIT
|
1466 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1467 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1468 INT_2_10_10_10_REV_BIT
);
1470 struct gl_vertex_array_object
* vao
;
1471 struct gl_buffer_object
* vbo
;
1473 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1475 "glVertexArrayMultiTexCoordOffsetEXT"))
1478 if (unit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1479 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexArrayMultiTexCoordOffsetEXT(texunit=%d)",
1484 if (!validate_array_and_format(ctx
, "glVertexArrayMultiTexCoordOffsetEXT",
1486 VERT_ATTRIB_TEX(unit
), legalTypes
,
1487 sizeMin
, 4, size
, type
, stride
,
1488 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1491 update_array(ctx
, vao
, vbo
,
1492 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
1493 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1498 _mesa_EdgeFlagPointer_no_error(GLsizei stride
, const GLvoid
*ptr
)
1500 /* this is the same type that glEdgeFlag uses */
1501 const GLboolean integer
= GL_FALSE
;
1502 GET_CURRENT_CONTEXT(ctx
);
1504 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1505 VERT_ATTRIB_EDGEFLAG
, GL_RGBA
, 1, 1, GL_UNSIGNED_BYTE
,
1506 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
1511 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
1513 /* this is the same type that glEdgeFlag uses */
1514 const GLboolean integer
= GL_FALSE
;
1515 GET_CURRENT_CONTEXT(ctx
);
1517 GLenum format
= GL_RGBA
;
1518 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
1520 if (!validate_array_and_format(ctx
, "glEdgeFlagPointer",
1521 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1522 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
1523 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
1524 GL_FALSE
, integer
, GL_FALSE
, format
, ptr
))
1527 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1528 VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
1529 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
1534 _mesa_VertexArrayEdgeFlagOffsetEXT(GLuint vaobj
, GLuint buffer
, GLsizei stride
,
1537 /* this is the same type that glEdgeFlag uses */
1538 const GLboolean integer
= GL_FALSE
;
1539 GET_CURRENT_CONTEXT(ctx
);
1541 GLenum format
= GL_RGBA
;
1542 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
1544 struct gl_vertex_array_object
* vao
;
1545 struct gl_buffer_object
* vbo
;
1547 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1549 "glVertexArrayEdgeFlagOffsetEXT"))
1552 if (!validate_array_and_format(ctx
, "glVertexArrayEdgeFlagOffsetEXT",
1554 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
1555 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
1556 GL_FALSE
, integer
, GL_FALSE
, format
, (void*) offset
))
1559 update_array(ctx
, vao
, vbo
,
1560 VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
1561 stride
, GL_FALSE
, integer
, GL_FALSE
, (void*) offset
);
1566 _mesa_PointSizePointerOES_no_error(GLenum type
, GLsizei stride
,
1569 GET_CURRENT_CONTEXT(ctx
);
1571 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1572 VERT_ATTRIB_POINT_SIZE
, GL_RGBA
, 1, 1, type
, stride
,
1573 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1578 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1580 GET_CURRENT_CONTEXT(ctx
);
1582 GLenum format
= GL_RGBA
;
1583 if (ctx
->API
!= API_OPENGLES
) {
1584 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1585 "glPointSizePointer(ES 1.x only)");
1589 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
1591 if (!validate_array_and_format(ctx
, "glPointSizePointer",
1592 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1593 VERT_ATTRIB_POINT_SIZE
, legalTypes
,
1594 1, 1, 1, type
, stride
, GL_FALSE
, GL_FALSE
,
1595 GL_FALSE
, format
, ptr
))
1598 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1599 VERT_ATTRIB_POINT_SIZE
, format
, 1, 1, type
, stride
,
1600 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1605 _mesa_VertexAttribPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1606 GLboolean normalized
,
1607 GLsizei stride
, const GLvoid
*ptr
)
1609 GET_CURRENT_CONTEXT(ctx
);
1611 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1612 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1613 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1614 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
1619 * Set a generic vertex attribute array.
1620 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1621 * (position, normal, color, fog, texcoord, etc).
1624 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
1625 GLboolean normalized
,
1626 GLsizei stride
, const GLvoid
*ptr
)
1628 GET_CURRENT_CONTEXT(ctx
);
1630 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1631 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1632 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(idx)");
1636 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1637 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1638 INT_BIT
| UNSIGNED_INT_BIT
|
1639 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1640 FIXED_ES_BIT
| FIXED_GL_BIT
|
1641 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1642 INT_2_10_10_10_REV_BIT
|
1643 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1645 if (!validate_array_and_format(ctx
, "glVertexAttribPointer",
1646 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1647 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1648 1, BGRA_OR_4
, size
, type
, stride
,
1649 normalized
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1652 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1653 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1654 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
1659 _mesa_VertexArrayVertexAttribOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1660 GLenum type
, GLboolean normalized
,
1661 GLsizei stride
, GLintptr offset
)
1663 GET_CURRENT_CONTEXT(ctx
);
1664 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1665 struct gl_vertex_array_object
* vao
;
1666 struct gl_buffer_object
* vbo
;
1668 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1670 "glVertexArrayVertexAttribOffsetEXT"))
1673 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1674 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribOffsetEXT(idx)");
1678 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1679 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1680 INT_BIT
| UNSIGNED_INT_BIT
|
1681 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1682 FIXED_ES_BIT
| FIXED_GL_BIT
|
1683 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1684 INT_2_10_10_10_REV_BIT
|
1685 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1687 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribOffsetEXT",
1689 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1690 1, BGRA_OR_4
, size
, type
, stride
,
1691 normalized
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1694 update_array(ctx
, vao
, vbo
,
1695 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1696 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1701 _mesa_VertexArrayVertexAttribLOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1702 GLenum type
, GLsizei stride
, GLintptr offset
)
1704 GET_CURRENT_CONTEXT(ctx
);
1705 GLenum format
= GL_RGBA
;
1706 struct gl_vertex_array_object
* vao
;
1707 struct gl_buffer_object
* vbo
;
1709 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1711 "glVertexArrayVertexAttribLOffsetEXT"))
1714 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1715 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribLOffsetEXT(idx)");
1719 const GLbitfield legalTypes
= DOUBLE_BIT
;
1721 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribLOffsetEXT",
1723 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1724 1, 4, size
, type
, stride
,
1725 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
, (void*) offset
))
1728 update_array(ctx
, vao
, vbo
,
1729 VERT_ATTRIB_GENERIC(index
), format
, 4,
1730 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, (void*) offset
);
1735 _mesa_VertexAttribIPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1736 GLsizei stride
, const GLvoid
*ptr
)
1738 const GLboolean normalized
= GL_FALSE
;
1739 const GLboolean integer
= GL_TRUE
;
1740 GET_CURRENT_CONTEXT(ctx
);
1742 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1743 VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1744 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1749 * GL_EXT_gpu_shader4 / GL 3.0.
1750 * Set an integer-valued vertex attribute array.
1751 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1752 * (position, normal, color, fog, texcoord, etc).
1755 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
1756 GLsizei stride
, const GLvoid
*ptr
)
1758 const GLboolean normalized
= GL_FALSE
;
1759 const GLboolean integer
= GL_TRUE
;
1760 GET_CURRENT_CONTEXT(ctx
);
1762 GLenum format
= GL_RGBA
;
1763 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1764 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
1768 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1769 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1770 INT_BIT
| UNSIGNED_INT_BIT
);
1772 if (!validate_array_and_format(ctx
, "glVertexAttribIPointer",
1773 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1774 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1775 1, 4, size
, type
, stride
,
1776 normalized
, integer
, GL_FALSE
, format
, ptr
))
1779 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1780 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1781 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1786 _mesa_VertexAttribLPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1787 GLsizei stride
, const GLvoid
*ptr
)
1789 GET_CURRENT_CONTEXT(ctx
);
1791 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1792 VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1793 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1798 _mesa_VertexArrayVertexAttribIOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1799 GLenum type
, GLsizei stride
, GLintptr offset
)
1801 const GLboolean normalized
= GL_FALSE
;
1802 const GLboolean integer
= GL_TRUE
;
1803 GET_CURRENT_CONTEXT(ctx
);
1804 GLenum format
= GL_RGBA
;
1806 struct gl_vertex_array_object
* vao
;
1807 struct gl_buffer_object
* vbo
;
1809 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1811 "glVertexArrayVertexAttribIOffsetEXT"))
1814 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1815 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribIOffsetEXT(index)");
1819 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1820 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1821 INT_BIT
| UNSIGNED_INT_BIT
);
1823 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribIOffsetEXT",
1825 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1826 1, 4, size
, type
, stride
,
1827 normalized
, integer
, GL_FALSE
, format
, (void*) offset
))
1830 update_array(ctx
, vao
, vbo
,
1831 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1832 stride
, normalized
, integer
, GL_FALSE
, (void*) offset
);
1837 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
1838 GLsizei stride
, const GLvoid
*ptr
)
1840 GET_CURRENT_CONTEXT(ctx
);
1842 GLenum format
= GL_RGBA
;
1843 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1844 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
1848 const GLbitfield legalTypes
= DOUBLE_BIT
;
1850 if (!validate_array_and_format(ctx
, "glVertexAttribLPointer",
1851 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1852 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1853 1, 4, size
, type
, stride
,
1854 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
, ptr
))
1857 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1858 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1859 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1864 _mesa_enable_vertex_array_attribs(struct gl_context
*ctx
,
1865 struct gl_vertex_array_object
*vao
,
1866 GLbitfield attrib_bits
)
1868 assert((attrib_bits
& ~VERT_BIT_ALL
) == 0);
1869 assert(!vao
->SharedAndImmutable
);
1871 /* Only work on bits that are disabled */
1872 attrib_bits
&= ~vao
->Enabled
;
1874 /* was disabled, now being enabled */
1875 vao
->Enabled
|= attrib_bits
;
1876 vao
->NewArrays
|= attrib_bits
;
1878 /* Update the map mode if needed */
1879 if (attrib_bits
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1880 update_attribute_map_mode(ctx
, vao
);
1885 enable_vertex_array_attrib(struct gl_context
*ctx
,
1886 struct gl_vertex_array_object
*vao
,
1890 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1891 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
1895 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1900 _mesa_EnableVertexAttribArray(GLuint index
)
1902 GET_CURRENT_CONTEXT(ctx
);
1903 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
1904 "glEnableVertexAttribArray");
1909 _mesa_EnableVertexAttribArray_no_error(GLuint index
)
1911 GET_CURRENT_CONTEXT(ctx
);
1912 _mesa_enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1913 VERT_ATTRIB_GENERIC(index
));
1918 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1920 GET_CURRENT_CONTEXT(ctx
);
1921 struct gl_vertex_array_object
*vao
;
1923 /* The ARB_direct_state_access specification says:
1925 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1926 * and DisableVertexArrayAttrib if <vaobj> is not
1927 * [compatibility profile: zero or] the name of an existing vertex
1930 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glEnableVertexArrayAttrib");
1934 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
1938 _mesa_EnableVertexArrayAttribEXT(GLuint vaobj
, GLuint index
)
1940 GET_CURRENT_CONTEXT(ctx
);
1941 struct gl_vertex_array_object
* vao
= _mesa_lookup_vao_err(ctx
, vaobj
,
1943 "glEnableVertexArrayAttribEXT");
1947 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttribEXT");
1952 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1954 GET_CURRENT_CONTEXT(ctx
);
1955 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1956 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1961 _mesa_disable_vertex_array_attribs(struct gl_context
*ctx
,
1962 struct gl_vertex_array_object
*vao
,
1963 GLbitfield attrib_bits
)
1965 assert((attrib_bits
& ~VERT_BIT_ALL
) == 0);
1966 assert(!vao
->SharedAndImmutable
);
1968 /* Only work on bits that are enabled */
1969 attrib_bits
&= vao
->Enabled
;
1971 /* was enabled, now being disabled */
1972 vao
->Enabled
&= ~attrib_bits
;
1973 vao
->NewArrays
|= attrib_bits
;
1975 /* Update the map mode if needed */
1976 if (attrib_bits
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1977 update_attribute_map_mode(ctx
, vao
);
1983 _mesa_DisableVertexAttribArray(GLuint index
)
1985 GET_CURRENT_CONTEXT(ctx
);
1987 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1988 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexAttribArray(index)");
1992 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1993 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
1998 _mesa_DisableVertexAttribArray_no_error(GLuint index
)
2000 GET_CURRENT_CONTEXT(ctx
);
2001 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2002 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
2007 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
2009 GET_CURRENT_CONTEXT(ctx
);
2010 struct gl_vertex_array_object
*vao
;
2012 /* The ARB_direct_state_access specification says:
2014 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
2015 * and DisableVertexArrayAttrib if <vaobj> is not
2016 * [compatibility profile: zero or] the name of an existing vertex
2019 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glDisableVertexArrayAttrib");
2023 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2024 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
2028 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2029 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
2033 _mesa_DisableVertexArrayAttribEXT(GLuint vaobj
, GLuint index
)
2035 GET_CURRENT_CONTEXT(ctx
);
2036 struct gl_vertex_array_object
* vao
= _mesa_lookup_vao_err(ctx
, vaobj
,
2038 "glEnableVertexArrayAttribEXT");
2042 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2043 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
2047 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2048 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
2053 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
2055 GET_CURRENT_CONTEXT(ctx
);
2056 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2057 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2058 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
2063 * Return info for a vertex attribute array (no alias with legacy
2064 * vertex attributes (pos, normal, color, etc)). This function does
2065 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
2068 get_vertex_array_attrib(struct gl_context
*ctx
,
2069 const struct gl_vertex_array_object
*vao
,
2070 GLuint index
, GLenum pname
,
2073 const struct gl_array_attributes
*array
;
2074 struct gl_buffer_object
*buf
;
2076 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2077 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
2081 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
2083 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
2086 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
2087 return !!(vao
->Enabled
& VERT_BIT_GENERIC(index
));
2088 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
2089 return (array
->Format
.Format
== GL_BGRA
) ? GL_BGRA
: array
->Format
.Size
;
2090 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
2091 return array
->Stride
;
2092 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
2093 return array
->Format
.Type
;
2094 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
2095 return array
->Format
.Normalized
;
2096 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
2097 buf
= vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
;
2098 return buf
? buf
->Name
: 0;
2099 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
2100 if ((_mesa_is_desktop_gl(ctx
)
2101 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
2102 || _mesa_is_gles3(ctx
)) {
2103 return array
->Format
.Integer
;
2106 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
2107 if (_mesa_is_desktop_gl(ctx
)) {
2108 return array
->Format
.Doubles
;
2111 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
2112 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
2113 || _mesa_is_gles3(ctx
)) {
2114 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
2117 case GL_VERTEX_ATTRIB_BINDING
:
2118 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
2119 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
2122 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
2123 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
2124 return array
->RelativeOffset
;
2128 ; /* fall-through */
2132 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
2137 static const GLfloat
*
2138 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
2141 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
2142 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
2146 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2147 _mesa_error(ctx
, GL_INVALID_VALUE
,
2148 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
2152 assert(VERT_ATTRIB_GENERIC(index
) <
2153 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
2155 FLUSH_CURRENT(ctx
, 0);
2156 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
2160 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
2162 GET_CURRENT_CONTEXT(ctx
);
2164 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2165 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
2171 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2173 "glGetVertexAttribfv");
2179 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
2181 GET_CURRENT_CONTEXT(ctx
);
2183 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2184 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
2186 params
[0] = (GLdouble
) v
[0];
2187 params
[1] = (GLdouble
) v
[1];
2188 params
[2] = (GLdouble
) v
[2];
2189 params
[3] = (GLdouble
) v
[3];
2193 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2195 "glGetVertexAttribdv");
2200 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
2202 GET_CURRENT_CONTEXT(ctx
);
2204 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2206 (const GLdouble
*)get_current_attrib(ctx
, index
,
2207 "glGetVertexAttribLdv");
2216 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2218 "glGetVertexAttribLdv");
2223 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
2225 GET_CURRENT_CONTEXT(ctx
);
2227 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2228 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
2230 /* XXX should floats in[0,1] be scaled to full int range? */
2231 params
[0] = (GLint
) v
[0];
2232 params
[1] = (GLint
) v
[1];
2233 params
[2] = (GLint
) v
[2];
2234 params
[3] = (GLint
) v
[3];
2238 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2240 "glGetVertexAttribiv");
2245 _mesa_GetVertexAttribLui64vARB(GLuint index
, GLenum pname
, GLuint64EXT
*params
)
2247 GET_CURRENT_CONTEXT(ctx
);
2249 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2251 (const GLuint64
*)get_current_attrib(ctx
, index
,
2252 "glGetVertexAttribLui64vARB");
2261 params
[0] = (GLuint64
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2263 "glGetVertexAttribLui64vARB");
2270 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
2272 GET_CURRENT_CONTEXT(ctx
);
2274 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2275 const GLint
*v
= (const GLint
*)
2276 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
2282 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2284 "glGetVertexAttribIiv");
2291 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
2293 GET_CURRENT_CONTEXT(ctx
);
2295 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2296 const GLuint
*v
= (const GLuint
*)
2297 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
2303 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2305 "glGetVertexAttribIuiv");
2311 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
2313 GET_CURRENT_CONTEXT(ctx
);
2315 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2316 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
2320 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
2321 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
2325 assert(VERT_ATTRIB_GENERIC(index
) <
2326 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
2328 *pointer
= (GLvoid
*)
2329 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
2333 /** ARB_direct_state_access */
2335 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
2336 GLenum pname
, GLint
*params
)
2338 GET_CURRENT_CONTEXT(ctx
);
2339 struct gl_vertex_array_object
*vao
;
2340 struct gl_buffer_object
*buf
;
2342 /* The ARB_direct_state_access specification says:
2344 * "An INVALID_OPERATION error is generated if <vaobj> is not
2345 * [compatibility profile: zero or] the name of an existing
2346 * vertex array object."
2348 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glGetVertexArrayIndexediv");
2352 /* The ARB_direct_state_access specification says:
2354 * "For GetVertexArrayIndexediv, <pname> must be one of
2355 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
2356 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
2357 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
2358 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
2359 * VERTEX_ATTRIB_RELATIVE_OFFSET."
2363 * "Add GetVertexArrayIndexediv in 'Get Command' for
2364 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
2365 * VERTEX_ATTRIB_BINDING,
2366 * VERTEX_ATTRIB_RELATIVE_OFFSET,
2367 * VERTEX_BINDING_OFFSET, and
2368 * VERTEX_BINDING_STRIDE states"
2370 * The only parameter name common to both lists is
2371 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
2372 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
2373 * pretty clear however that the intent is that it should be possible
2374 * to query all vertex attrib and binding states that can be set with
2378 case GL_VERTEX_BINDING_OFFSET
:
2379 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2381 case GL_VERTEX_BINDING_STRIDE
:
2382 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
2384 case GL_VERTEX_BINDING_DIVISOR
:
2385 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
2387 case GL_VERTEX_BINDING_BUFFER
:
2388 buf
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
;
2389 params
[0] = buf
? buf
->Name
: 0;
2392 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
2393 "glGetVertexArrayIndexediv");
2400 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
2401 GLenum pname
, GLint64
*params
)
2403 GET_CURRENT_CONTEXT(ctx
);
2404 struct gl_vertex_array_object
*vao
;
2406 /* The ARB_direct_state_access specification says:
2408 * "An INVALID_OPERATION error is generated if <vaobj> is not
2409 * [compatibility profile: zero or] the name of an existing
2410 * vertex array object."
2412 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glGetVertexArrayIndexed64iv");
2416 /* The ARB_direct_state_access specification says:
2418 * "For GetVertexArrayIndexed64iv, <pname> must be
2419 * VERTEX_BINDING_OFFSET."
2423 * "An INVALID_ENUM error is generated if <pname> is not one of
2424 * the valid values listed above for the corresponding command."
2426 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
2427 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
2428 "pname != GL_VERTEX_BINDING_OFFSET)");
2432 /* The ARB_direct_state_access specification says:
2434 * "An INVALID_VALUE error is generated if <index> is greater than
2435 * or equal to the value of MAX_VERTEX_ATTRIBS."
2437 * Since the index refers to a buffer binding in this case, the intended
2438 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
2439 * required to be the same, so in practice this doesn't matter.
2441 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
2442 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
2443 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
2444 index
, ctx
->Const
.MaxVertexAttribBindings
);
2448 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2453 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
2454 GLsizei count
, const GLvoid
*ptr
)
2457 _mesa_VertexPointer(size
, type
, stride
, ptr
);
2462 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
2466 _mesa_NormalPointer(type
, stride
, ptr
);
2471 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
2475 _mesa_ColorPointer(size
, type
, stride
, ptr
);
2480 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
2484 _mesa_IndexPointer(type
, stride
, ptr
);
2489 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
2490 GLsizei count
, const GLvoid
*ptr
)
2493 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
2498 _mesa_MultiTexCoordPointerEXT(GLenum texunit
, GLint size
, GLenum type
,
2499 GLsizei stride
, const GLvoid
*ptr
)
2501 GET_CURRENT_CONTEXT(ctx
);
2502 const GLint sizeMin
= 1;
2503 const GLuint unit
= texunit
- GL_TEXTURE0
;
2505 GLenum format
= GL_RGBA
;
2506 const GLbitfield legalTypes
= (SHORT_BIT
| INT_BIT
|
2507 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
2508 UNSIGNED_INT_2_10_10_10_REV_BIT
|
2509 INT_2_10_10_10_REV_BIT
);
2511 if (!validate_array_and_format(ctx
, "glMultiTexCoordPointerEXT",
2512 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
2513 VERT_ATTRIB_TEX(unit
), legalTypes
,
2514 sizeMin
, 4, size
, type
, stride
,
2515 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
2518 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
2519 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
2520 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
2525 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
2528 _mesa_EdgeFlagPointer(stride
, ptr
);
2533 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
2535 GET_CURRENT_CONTEXT(ctx
);
2536 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
2537 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
2538 GLenum ctype
= 0; /* color type */
2539 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
2540 const GLint toffset
= 0; /* always zero */
2541 GLint defstride
; /* default stride */
2544 f
= sizeof(GLfloat
);
2545 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
2548 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
2554 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2555 tcomps
= 0; ccomps
= 0; vcomps
= 2;
2560 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2561 tcomps
= 0; ccomps
= 0; vcomps
= 3;
2566 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2567 tcomps
= 0; ccomps
= 4; vcomps
= 2;
2568 ctype
= GL_UNSIGNED_BYTE
;
2571 defstride
= c
+ 2*f
;
2574 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2575 tcomps
= 0; ccomps
= 4; vcomps
= 3;
2576 ctype
= GL_UNSIGNED_BYTE
;
2579 defstride
= c
+ 3*f
;
2582 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2583 tcomps
= 0; ccomps
= 3; vcomps
= 3;
2590 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
2591 tcomps
= 0; ccomps
= 0; vcomps
= 3;
2596 case GL_C4F_N3F_V3F
:
2597 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2598 tcomps
= 0; ccomps
= 4; vcomps
= 3;
2606 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2607 tcomps
= 2; ccomps
= 0; vcomps
= 3;
2612 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2613 tcomps
= 4; ccomps
= 0; vcomps
= 4;
2617 case GL_T2F_C4UB_V3F
:
2618 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2619 tcomps
= 2; ccomps
= 4; vcomps
= 3;
2620 ctype
= GL_UNSIGNED_BYTE
;
2625 case GL_T2F_C3F_V3F
:
2626 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2627 tcomps
= 2; ccomps
= 3; vcomps
= 3;
2633 case GL_T2F_N3F_V3F
:
2634 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
2635 tcomps
= 2; ccomps
= 0; vcomps
= 3;
2640 case GL_T2F_C4F_N3F_V3F
:
2641 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2642 tcomps
= 2; ccomps
= 4; vcomps
= 3;
2649 case GL_T4F_C4F_N3F_V4F
:
2650 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2651 tcomps
= 4; ccomps
= 4; vcomps
= 4;
2659 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
2667 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
2668 _mesa_DisableClientState( GL_INDEX_ARRAY
);
2669 /* XXX also disable secondary color and generic arrays? */
2673 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
2674 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
2675 (GLubyte
*) pointer
+ toffset
);
2678 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
2683 _mesa_EnableClientState( GL_COLOR_ARRAY
);
2684 _mesa_ColorPointer( ccomps
, ctype
, stride
,
2685 (GLubyte
*) pointer
+ coffset
);
2688 _mesa_DisableClientState( GL_COLOR_ARRAY
);
2694 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
2695 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
2698 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
2702 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
2703 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
2704 (GLubyte
*) pointer
+ voffset
);
2709 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
2711 GET_CURRENT_CONTEXT(ctx
);
2713 if (MESA_VERBOSE
& VERBOSE_API
)
2714 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
2717 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
2721 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
2724 if (ctx
->Array
.LockCount
!= 0) {
2725 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
2729 ctx
->Array
.LockFirst
= first
;
2730 ctx
->Array
.LockCount
= count
;
2735 _mesa_UnlockArraysEXT( void )
2737 GET_CURRENT_CONTEXT(ctx
);
2739 if (MESA_VERBOSE
& VERBOSE_API
)
2740 _mesa_debug(ctx
, "glUnlockArrays\n");
2742 if (ctx
->Array
.LockCount
== 0) {
2743 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
2747 ctx
->Array
.LockFirst
= 0;
2748 ctx
->Array
.LockCount
= 0;
2753 primitive_restart_index(struct gl_context
*ctx
, GLuint index
)
2755 ctx
->Array
.RestartIndex
= index
;
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
;
3174 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
3178 /* TODO: remove this hack */
3179 if (vbo
== ctx
->Shared
->NullBufferObj
)
3186 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
3187 vbo
, offsets
[i
], strides
[i
]);
3190 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
3195 vertex_array_vertex_buffers_err(struct gl_context
*ctx
,
3196 struct gl_vertex_array_object
*vao
,
3197 GLuint first
, GLsizei count
,
3198 const GLuint
*buffers
, const GLintptr
*offsets
,
3199 const GLsizei
*strides
, const char *func
)
3201 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3203 /* The ARB_multi_bind spec says:
3205 * "An INVALID_OPERATION error is generated if <first> + <count>
3206 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
3208 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
3209 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3210 "%s(first=%u + count=%d > the value of "
3211 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
3212 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
3216 vertex_array_vertex_buffers(ctx
, vao
, first
, count
, buffers
, offsets
,
3217 strides
, false, func
);
3222 _mesa_BindVertexBuffers_no_error(GLuint first
, GLsizei count
,
3223 const GLuint
*buffers
, const GLintptr
*offsets
,
3224 const GLsizei
*strides
)
3226 GET_CURRENT_CONTEXT(ctx
);
3228 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
3229 buffers
, offsets
, strides
, true,
3230 "glBindVertexBuffers");
3235 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
3236 const GLintptr
*offsets
, const GLsizei
*strides
)
3238 GET_CURRENT_CONTEXT(ctx
);
3240 /* The ARB_vertex_attrib_binding spec says:
3242 * "An INVALID_OPERATION error is generated if no
3243 * vertex array object is bound."
3245 if (ctx
->API
== API_OPENGL_CORE
&&
3246 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3247 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3248 "glBindVertexBuffers(No array object bound)");
3252 vertex_array_vertex_buffers_err(ctx
, ctx
->Array
.VAO
, first
, count
,
3253 buffers
, offsets
, strides
,
3254 "glBindVertexBuffers");
3259 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj
, GLuint first
,
3260 GLsizei count
, const GLuint
*buffers
,
3261 const GLintptr
*offsets
,
3262 const GLsizei
*strides
)
3264 GET_CURRENT_CONTEXT(ctx
);
3266 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3267 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
3268 buffers
, offsets
, strides
, true,
3269 "glVertexArrayVertexBuffers");
3274 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
3275 const GLuint
*buffers
,
3276 const GLintptr
*offsets
, const GLsizei
*strides
)
3278 GET_CURRENT_CONTEXT(ctx
);
3279 struct gl_vertex_array_object
*vao
;
3281 /* The ARB_direct_state_access specification says:
3283 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
3284 * if <vaobj> is not [compatibility profile: zero or] the name of an
3285 * existing vertex array object."
3287 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayVertexBuffers");
3291 vertex_array_vertex_buffers_err(ctx
, vao
, first
, count
,
3292 buffers
, offsets
, strides
,
3293 "glVertexArrayVertexBuffers");
3298 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
3299 GLboolean normalized
, GLboolean integer
,
3300 GLboolean doubles
, GLbitfield legalTypes
,
3301 GLsizei sizeMax
, GLuint relativeOffset
,
3304 GET_CURRENT_CONTEXT(ctx
);
3305 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3307 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
3309 if (!_mesa_is_no_error_enabled(ctx
)) {
3310 /* The ARB_vertex_attrib_binding spec says:
3312 * "An INVALID_OPERATION error is generated under any of the
3313 * following conditions:
3314 * - if no vertex array object is currently bound (see section
3318 * This error condition only applies to VertexAttribFormat and
3319 * VertexAttribIFormat in the extension spec, but we assume that this
3320 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
3321 * to all three functions.
3323 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3324 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3325 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3326 "%s(No array object bound)", func
);
3330 /* The ARB_vertex_attrib_binding spec says:
3332 * "The error INVALID_VALUE is generated if index is greater than or
3333 * equal to the value of MAX_VERTEX_ATTRIBS."
3335 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
3336 _mesa_error(ctx
, GL_INVALID_VALUE
,
3337 "%s(attribindex=%u > "
3338 "GL_MAX_VERTEX_ATTRIBS)",
3343 if (!validate_array_format(ctx
, func
, ctx
->Array
.VAO
,
3344 VERT_ATTRIB_GENERIC(attribIndex
),
3345 legalTypes
, 1, sizeMax
, size
, type
,
3346 normalized
, integer
, doubles
, relativeOffset
,
3352 _mesa_update_array_format(ctx
, ctx
->Array
.VAO
,
3353 VERT_ATTRIB_GENERIC(attribIndex
), size
, type
,
3354 format
, normalized
, integer
, doubles
,
3360 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3361 GLboolean normalized
, GLuint relativeOffset
)
3363 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
3364 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
3365 BGRA_OR_4
, relativeOffset
,
3366 "glVertexAttribFormat");
3371 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3372 GLuint relativeOffset
)
3374 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
3375 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
3376 relativeOffset
, "glVertexAttribIFormat");
3381 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3382 GLuint relativeOffset
)
3384 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
3385 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
3386 relativeOffset
, "glVertexAttribLFormat");
3391 vertex_array_attrib_format(GLuint vaobj
, bool isExtDsa
, GLuint attribIndex
,
3392 GLint size
, GLenum type
, GLboolean normalized
,
3393 GLboolean integer
, GLboolean doubles
,
3394 GLbitfield legalTypes
, GLsizei sizeMax
,
3395 GLuint relativeOffset
, const char *func
)
3397 GET_CURRENT_CONTEXT(ctx
);
3398 struct gl_vertex_array_object
*vao
;
3400 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3402 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
3404 if (_mesa_is_no_error_enabled(ctx
)) {
3405 vao
= _mesa_lookup_vao(ctx
, vaobj
);
3409 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, isExtDsa
, func
);
3413 /* The ARB_vertex_attrib_binding spec says:
3415 * "The error INVALID_VALUE is generated if index is greater than or
3416 * equal to the value of MAX_VERTEX_ATTRIBS."
3418 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
3419 _mesa_error(ctx
, GL_INVALID_VALUE
,
3420 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
3425 if (!validate_array_format(ctx
, func
, vao
,
3426 VERT_ATTRIB_GENERIC(attribIndex
),
3427 legalTypes
, 1, sizeMax
, size
, type
,
3428 normalized
, integer
, doubles
, relativeOffset
,
3434 _mesa_update_array_format(ctx
, vao
, VERT_ATTRIB_GENERIC(attribIndex
), size
,
3435 type
, format
, normalized
, integer
, doubles
,
3441 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
3442 GLenum type
, GLboolean normalized
,
3443 GLuint relativeOffset
)
3445 vertex_array_attrib_format(vaobj
, false, attribIndex
, size
, type
, normalized
,
3446 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
3447 BGRA_OR_4
, relativeOffset
,
3448 "glVertexArrayAttribFormat");
3453 _mesa_VertexArrayVertexAttribFormatEXT(GLuint vaobj
, GLuint attribIndex
, GLint size
,
3454 GLenum type
, GLboolean normalized
,
3455 GLuint relativeOffset
)
3457 vertex_array_attrib_format(vaobj
, true, attribIndex
, size
, type
, normalized
,
3458 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
3459 BGRA_OR_4
, relativeOffset
,
3460 "glVertexArrayVertexAttribFormatEXT");
3465 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
3466 GLint size
, GLenum type
,
3467 GLuint relativeOffset
)
3469 vertex_array_attrib_format(vaobj
, false, attribIndex
, size
, type
, GL_FALSE
,
3470 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
3472 "glVertexArrayAttribIFormat");
3477 _mesa_VertexArrayVertexAttribIFormatEXT(GLuint vaobj
, GLuint attribIndex
,
3478 GLint size
, GLenum type
,
3479 GLuint relativeOffset
)
3481 vertex_array_attrib_format(vaobj
, true, attribIndex
, size
, type
, GL_FALSE
,
3482 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
3484 "glVertexArrayVertexAttribIFormatEXT");
3489 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
3490 GLint size
, GLenum type
,
3491 GLuint relativeOffset
)
3493 vertex_array_attrib_format(vaobj
, false, attribIndex
, size
, type
, GL_FALSE
,
3494 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
3496 "glVertexArrayAttribLFormat");
3501 _mesa_VertexArrayVertexAttribLFormatEXT(GLuint vaobj
, GLuint attribIndex
,
3502 GLint size
, GLenum type
,
3503 GLuint relativeOffset
)
3505 vertex_array_attrib_format(vaobj
, true, attribIndex
, size
, type
, GL_FALSE
,
3506 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
3508 "glVertexArrayVertexAttribLFormatEXT");
3513 vertex_array_attrib_binding(struct gl_context
*ctx
,
3514 struct gl_vertex_array_object
*vao
,
3515 GLuint attribIndex
, GLuint bindingIndex
,
3518 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3520 /* The ARB_vertex_attrib_binding spec says:
3522 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
3523 * <bindingindex> must be less than the value of
3524 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
3527 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
3528 _mesa_error(ctx
, GL_INVALID_VALUE
,
3529 "%s(attribindex=%u >= "
3530 "GL_MAX_VERTEX_ATTRIBS)",
3535 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
3536 _mesa_error(ctx
, GL_INVALID_VALUE
,
3537 "%s(bindingindex=%u >= "
3538 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
3539 func
, bindingIndex
);
3543 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
3545 _mesa_vertex_attrib_binding(ctx
, vao
,
3546 VERT_ATTRIB_GENERIC(attribIndex
),
3547 VERT_ATTRIB_GENERIC(bindingIndex
));
3552 _mesa_VertexAttribBinding_no_error(GLuint attribIndex
, GLuint bindingIndex
)
3554 GET_CURRENT_CONTEXT(ctx
);
3555 _mesa_vertex_attrib_binding(ctx
, ctx
->Array
.VAO
,
3556 VERT_ATTRIB_GENERIC(attribIndex
),
3557 VERT_ATTRIB_GENERIC(bindingIndex
));
3562 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
3564 GET_CURRENT_CONTEXT(ctx
);
3566 /* The ARB_vertex_attrib_binding spec says:
3568 * "An INVALID_OPERATION error is generated if no vertex array object
3571 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3572 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3573 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3574 "glVertexAttribBinding(No array object bound)");
3578 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
3579 attribIndex
, bindingIndex
,
3580 "glVertexAttribBinding");
3585 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj
, GLuint attribIndex
,
3586 GLuint bindingIndex
)
3588 GET_CURRENT_CONTEXT(ctx
);
3590 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3591 _mesa_vertex_attrib_binding(ctx
, vao
,
3592 VERT_ATTRIB_GENERIC(attribIndex
),
3593 VERT_ATTRIB_GENERIC(bindingIndex
));
3598 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
3600 GET_CURRENT_CONTEXT(ctx
);
3601 struct gl_vertex_array_object
*vao
;
3603 /* The ARB_direct_state_access specification says:
3605 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
3606 * if <vaobj> is not [compatibility profile: zero or] the name of an
3607 * existing vertex array object."
3609 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayAttribBinding");
3613 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
3614 "glVertexArrayAttribBinding");
3619 _mesa_VertexArrayVertexAttribBindingEXT(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
3621 GET_CURRENT_CONTEXT(ctx
);
3622 struct gl_vertex_array_object
*vao
;
3623 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, "glVertexArrayVertexAttribBindingEXT");
3627 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
3628 "glVertexArrayVertexAttribBindingEXT");
3633 vertex_array_binding_divisor(struct gl_context
*ctx
,
3634 struct gl_vertex_array_object
*vao
,
3635 GLuint bindingIndex
, GLuint divisor
,
3638 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3640 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
3641 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
3645 /* The ARB_vertex_attrib_binding spec says:
3647 * "An INVALID_VALUE error is generated if <bindingindex> is greater
3648 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
3650 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
3651 _mesa_error(ctx
, GL_INVALID_VALUE
,
3652 "%s(bindingindex=%u > "
3653 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
3654 func
, bindingIndex
);
3658 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3663 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex
, GLuint divisor
)
3665 GET_CURRENT_CONTEXT(ctx
);
3666 vertex_binding_divisor(ctx
, ctx
->Array
.VAO
,
3667 VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3672 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
3674 GET_CURRENT_CONTEXT(ctx
);
3676 /* The ARB_vertex_attrib_binding spec says:
3678 * "An INVALID_OPERATION error is generated if no vertex array object
3681 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3682 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3683 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3684 "glVertexBindingDivisor(No array object bound)");
3688 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
3689 bindingIndex
, divisor
,
3690 "glVertexBindingDivisor");
3695 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj
, GLuint bindingIndex
,
3698 GET_CURRENT_CONTEXT(ctx
);
3700 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3701 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3706 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
3709 struct gl_vertex_array_object
*vao
;
3710 GET_CURRENT_CONTEXT(ctx
);
3712 /* The ARB_direct_state_access specification says:
3714 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
3715 * if <vaobj> is not [compatibility profile: zero or] the name of an
3716 * existing vertex array object."
3718 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayBindingDivisor");
3722 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
3723 "glVertexArrayBindingDivisor");
3728 _mesa_VertexArrayVertexBindingDivisorEXT(GLuint vaobj
, GLuint bindingIndex
,
3731 struct gl_vertex_array_object
*vao
;
3732 GET_CURRENT_CONTEXT(ctx
);
3734 /* The ARB_direct_state_access specification says:
3736 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
3737 * if <vaobj> is not [compatibility profile: zero or] the name of an
3738 * existing vertex array object."
3740 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, "glVertexArrayVertexBindingDivisorEXT");
3744 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
3745 "glVertexArrayVertexBindingDivisorEXT");
3750 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
3751 struct gl_array_attributes
*dst
,
3752 const struct gl_array_attributes
*src
)
3754 dst
->Ptr
= src
->Ptr
;
3755 dst
->RelativeOffset
= src
->RelativeOffset
;
3756 dst
->Format
= src
->Format
;
3757 dst
->Stride
= src
->Stride
;
3758 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
3759 dst
->_EffBufferBindingIndex
= src
->_EffBufferBindingIndex
;
3760 dst
->_EffRelativeOffset
= src
->_EffRelativeOffset
;
3764 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
3765 struct gl_vertex_buffer_binding
*dst
,
3766 const struct gl_vertex_buffer_binding
*src
)
3768 dst
->Offset
= src
->Offset
;
3769 dst
->Stride
= src
->Stride
;
3770 dst
->InstanceDivisor
= src
->InstanceDivisor
;
3771 dst
->_BoundArrays
= src
->_BoundArrays
;
3772 dst
->_EffBoundArrays
= src
->_EffBoundArrays
;
3773 dst
->_EffOffset
= src
->_EffOffset
;
3775 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
3779 * Print current vertex object/array info. For debug.
3782 _mesa_print_arrays(struct gl_context
*ctx
)
3784 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
3786 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
3788 GLbitfield mask
= vao
->Enabled
;
3790 const gl_vert_attrib i
= u_bit_scan(&mask
);
3791 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
3793 const struct gl_vertex_buffer_binding
*binding
=
3794 &vao
->BufferBinding
[array
->BufferBindingIndex
];
3795 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
3797 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
3798 "Stride=%d, Buffer=%u(Size %lu)\n",
3799 gl_vert_attrib_name((gl_vert_attrib
)i
),
3800 array
->Ptr
, _mesa_enum_to_string(array
->Format
.Type
),
3802 array
->Format
._ElementSize
, binding
->Stride
, bo
? bo
->Name
: 0,
3803 (unsigned long) bo
? bo
->Size
: 0);
3808 * Initialize attributes of a vertex array within a vertex array object.
3809 * \param vao the container vertex array object
3810 * \param index which array in the VAO to initialize
3811 * \param size number of components (1, 2, 3 or 4) per attribute
3812 * \param type datatype of the attribute (GL_FLOAT, GL_INT, etc).
3815 init_array(struct gl_context
*ctx
,
3816 struct gl_vertex_array_object
*vao
,
3817 gl_vert_attrib index
, GLint size
, GLint type
)
3819 assert(index
< ARRAY_SIZE(vao
->VertexAttrib
));
3820 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[index
];
3821 assert(index
< ARRAY_SIZE(vao
->BufferBinding
));
3822 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
3824 _mesa_set_vertex_format(&array
->Format
, size
, type
, GL_RGBA
,
3825 GL_FALSE
, GL_FALSE
, GL_FALSE
);
3828 array
->RelativeOffset
= 0;
3829 ASSERT_BITFIELD_SIZE(struct gl_array_attributes
, BufferBindingIndex
,
3830 VERT_ATTRIB_MAX
- 1);
3831 array
->BufferBindingIndex
= index
;
3833 binding
->Offset
= 0;
3834 binding
->Stride
= array
->Format
._ElementSize
;
3835 binding
->BufferObj
= NULL
;
3836 binding
->_BoundArrays
= BITFIELD_BIT(index
);
3840 init_default_vao_state(struct gl_context
*ctx
)
3842 struct gl_vertex_array_object
*vao
= &ctx
->Array
.DefaultVAOState
;
3845 vao
->SharedAndImmutable
= false;
3847 /* Init the individual arrays */
3848 for (unsigned i
= 0; i
< ARRAY_SIZE(vao
->VertexAttrib
); i
++) {
3850 case VERT_ATTRIB_NORMAL
:
3851 init_array(ctx
, vao
, VERT_ATTRIB_NORMAL
, 3, GL_FLOAT
);
3853 case VERT_ATTRIB_COLOR1
:
3854 init_array(ctx
, vao
, VERT_ATTRIB_COLOR1
, 3, GL_FLOAT
);
3856 case VERT_ATTRIB_FOG
:
3857 init_array(ctx
, vao
, VERT_ATTRIB_FOG
, 1, GL_FLOAT
);
3859 case VERT_ATTRIB_COLOR_INDEX
:
3860 init_array(ctx
, vao
, VERT_ATTRIB_COLOR_INDEX
, 1, GL_FLOAT
);
3862 case VERT_ATTRIB_EDGEFLAG
:
3863 init_array(ctx
, vao
, VERT_ATTRIB_EDGEFLAG
, 1, GL_UNSIGNED_BYTE
);
3865 case VERT_ATTRIB_POINT_SIZE
:
3866 init_array(ctx
, vao
, VERT_ATTRIB_POINT_SIZE
, 1, GL_FLOAT
);
3869 init_array(ctx
, vao
, i
, 4, GL_FLOAT
);
3874 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_IDENTITY
;
3878 * Initialize vertex array state for given context.
3881 _mesa_init_varray(struct gl_context
*ctx
)
3883 init_default_vao_state(ctx
);
3885 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
3886 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
3887 ctx
->Array
._EmptyVAO
= _mesa_new_vao(ctx
, ~0u);
3888 _mesa_reference_vao(ctx
, &ctx
->Array
._DrawVAO
, ctx
->Array
._EmptyVAO
);
3889 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
3891 ctx
->Array
.Objects
= _mesa_NewHashTable();
3896 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
3899 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
3901 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
3902 struct gl_context
*ctx
= (struct gl_context
*) userData
;
3903 _mesa_delete_vao(ctx
, vao
);
3908 * Free vertex array state for given context.
3911 _mesa_free_varray_data(struct gl_context
*ctx
)
3913 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
3914 _mesa_DeleteHashTable(ctx
->Array
.Objects
);
3918 _mesa_GetVertexArrayIntegervEXT(GLuint vaobj
, GLenum pname
, GLint
*param
)
3920 GET_CURRENT_CONTEXT(ctx
);
3921 struct gl_vertex_array_object
* vao
;
3922 struct gl_buffer_object
*buf
;
3925 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
3926 "glGetVertexArrayIntegervEXT");
3930 /* The EXT_direct_state_access spec says:
3932 * "For GetVertexArrayIntegervEXT, pname must be one of the "Get value" tokens
3933 * in tables 6.6, 6.7, 6.8, and 6.9 that use GetIntegerv, IsEnabled, or
3934 * GetPointerv for their "Get command" (so excluding the VERTEX_ATTRIB_*
3938 /* Tokens using GetIntegerv */
3939 case GL_CLIENT_ACTIVE_TEXTURE
:
3940 *param
= GL_TEXTURE0_ARB
+ ctx
->Array
.ActiveTexture
;
3942 case GL_VERTEX_ARRAY_SIZE
:
3943 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Format
.Size
;
3945 case GL_VERTEX_ARRAY_TYPE
:
3946 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Format
.Type
;
3948 case GL_VERTEX_ARRAY_STRIDE
:
3949 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Stride
;
3951 case GL_VERTEX_ARRAY_BUFFER_BINDING
:
3952 buf
= vao
->BufferBinding
[VERT_ATTRIB_POS
].BufferObj
;
3953 *param
= buf
? buf
->Name
: 0;
3955 case GL_COLOR_ARRAY_SIZE
:
3956 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Format
.Size
;
3958 case GL_COLOR_ARRAY_TYPE
:
3959 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Format
.Type
;
3961 case GL_COLOR_ARRAY_STRIDE
:
3962 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Stride
;
3964 case GL_COLOR_ARRAY_BUFFER_BINDING
:
3965 buf
= vao
->BufferBinding
[VERT_ATTRIB_COLOR0
].BufferObj
;
3966 *param
= buf
? buf
->Name
: 0;
3968 case GL_EDGE_FLAG_ARRAY_STRIDE
:
3969 *param
= vao
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Stride
;
3971 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING
:
3972 buf
= vao
->BufferBinding
[VERT_ATTRIB_EDGEFLAG
].BufferObj
;
3973 *param
= buf
? buf
->Name
: 0;
3975 case GL_INDEX_ARRAY_TYPE
:
3976 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Format
.Type
;
3978 case GL_INDEX_ARRAY_STRIDE
:
3979 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Stride
;
3981 case GL_INDEX_ARRAY_BUFFER_BINDING
:
3982 buf
= vao
->BufferBinding
[VERT_ATTRIB_COLOR_INDEX
].BufferObj
;
3983 *param
= buf
? buf
->Name
: 0;
3985 case GL_NORMAL_ARRAY_TYPE
:
3986 *param
= vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Format
.Type
;
3988 case GL_NORMAL_ARRAY_STRIDE
:
3989 *param
= vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Stride
;
3991 case GL_NORMAL_ARRAY_BUFFER_BINDING
:
3992 buf
= vao
->BufferBinding
[VERT_ATTRIB_NORMAL
].BufferObj
;
3993 *param
= buf
? buf
->Name
: 0;
3995 case GL_TEXTURE_COORD_ARRAY_SIZE
:
3996 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Format
.Size
;
3998 case GL_TEXTURE_COORD_ARRAY_TYPE
:
3999 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Format
.Type
;
4001 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
4002 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Stride
;
4004 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING
:
4005 buf
= vao
->BufferBinding
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].BufferObj
;
4006 *param
= buf
? buf
->Name
: 0;
4008 case GL_FOG_COORD_ARRAY_TYPE
:
4009 *param
= vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Format
.Type
;
4011 case GL_FOG_COORD_ARRAY_STRIDE
:
4012 *param
= vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Stride
;
4014 case GL_FOG_COORD_ARRAY_BUFFER_BINDING
:
4015 buf
= vao
->BufferBinding
[VERT_ATTRIB_FOG
].BufferObj
;
4016 *param
= buf
? buf
->Name
: 0;
4018 case GL_SECONDARY_COLOR_ARRAY_SIZE
:
4019 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Format
.Size
;
4021 case GL_SECONDARY_COLOR_ARRAY_TYPE
:
4022 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Format
.Type
;
4024 case GL_SECONDARY_COLOR_ARRAY_STRIDE
:
4025 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Stride
;
4027 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING
:
4028 buf
= vao
->BufferBinding
[VERT_ATTRIB_COLOR1
].BufferObj
;
4029 *param
= buf
? buf
->Name
: 0;
4032 /* Tokens using IsEnabled */
4033 case GL_VERTEX_ARRAY
:
4034 *param
= !!(vao
->Enabled
& VERT_BIT_POS
);
4036 case GL_COLOR_ARRAY
:
4037 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR0
);
4039 case GL_EDGE_FLAG_ARRAY
:
4040 *param
= !!(vao
->Enabled
& VERT_BIT_EDGEFLAG
);
4042 case GL_INDEX_ARRAY
:
4043 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR_INDEX
);
4045 case GL_NORMAL_ARRAY
:
4046 *param
= !!(vao
->Enabled
& VERT_BIT_NORMAL
);
4048 case GL_TEXTURE_COORD_ARRAY
:
4049 *param
= !!(vao
->Enabled
& VERT_BIT_TEX(ctx
->Array
.ActiveTexture
));
4051 case GL_FOG_COORD_ARRAY
:
4052 *param
= !!(vao
->Enabled
& VERT_BIT_FOG
);
4054 case GL_SECONDARY_COLOR_ARRAY
:
4055 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR1
);
4058 /* Tokens using GetPointerv */
4059 case GL_VERTEX_ARRAY_POINTER
:
4060 case GL_COLOR_ARRAY_POINTER
:
4061 case GL_EDGE_FLAG_ARRAY_POINTER
:
4062 case GL_INDEX_ARRAY_POINTER
:
4063 case GL_NORMAL_ARRAY_POINTER
:
4064 case GL_TEXTURE_COORD_ARRAY_POINTER
:
4065 case GL_FOG_COORD_ARRAY_POINTER
:
4066 case GL_SECONDARY_COLOR_ARRAY_POINTER
:
4067 _get_vao_pointerv(pname
, vao
, &ptr
, "glGetVertexArrayIntegervEXT");
4068 *param
= (int) ((intptr_t) ptr
& 0xFFFFFFFF);
4072 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIntegervEXT(pname)");
4077 _mesa_GetVertexArrayPointervEXT(GLuint vaobj
, GLenum pname
, GLvoid
** param
)
4079 GET_CURRENT_CONTEXT(ctx
);
4080 struct gl_vertex_array_object
* vao
;
4082 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
4083 "glGetVertexArrayPointervEXT");
4087 /* The EXT_direct_state_access spec says:
4089 * "For GetVertexArrayPointervEXT, pname must be a *_ARRAY_POINTER token from
4090 * tables 6.6, 6.7, and 6.8 excluding VERTEX_ATTRIB_ARRAY_POINT."
4093 case GL_VERTEX_ARRAY_POINTER
:
4094 case GL_COLOR_ARRAY_POINTER
:
4095 case GL_EDGE_FLAG_ARRAY_POINTER
:
4096 case GL_INDEX_ARRAY_POINTER
:
4097 case GL_NORMAL_ARRAY_POINTER
:
4098 case GL_TEXTURE_COORD_ARRAY_POINTER
:
4099 case GL_FOG_COORD_ARRAY_POINTER
:
4100 case GL_SECONDARY_COLOR_ARRAY_POINTER
:
4104 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayPointervEXT(pname)");
4108 /* pname has been validated, we can now use the helper function */
4109 _get_vao_pointerv(pname
, vao
, param
, "glGetVertexArrayPointervEXT");
4113 _mesa_GetVertexArrayIntegeri_vEXT(GLuint vaobj
, GLuint index
, GLenum pname
, GLint
*param
)
4115 GET_CURRENT_CONTEXT(ctx
);
4116 struct gl_vertex_array_object
* vao
;
4117 struct gl_buffer_object
*buf
;
4119 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
4120 "glGetVertexArrayIntegeri_vEXT");
4125 /* The EXT_direct_state_access spec says:
4127 * "For GetVertexArrayIntegeri_vEXT, pname must be one of the
4128 * "Get value" tokens in tables 6.8 and 6.9 that use GetVertexAttribiv
4129 * or GetVertexAttribPointerv (so allowing only the VERTEX_ATTRIB_*
4130 * tokens) or a token of the form TEXTURE_COORD_ARRAY (the enable) or
4131 * TEXTURE_COORD_ARRAY_*; index identifies the vertex attribute
4132 * array to query or texture coordinate set index respectively."
4136 case GL_TEXTURE_COORD_ARRAY
:
4137 *param
= !!(vao
->Enabled
& VERT_BIT_TEX(index
));
4139 case GL_TEXTURE_COORD_ARRAY_SIZE
:
4140 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Format
.Size
;
4142 case GL_TEXTURE_COORD_ARRAY_TYPE
:
4143 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Format
.Type
;
4145 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
4146 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Stride
;
4148 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING
:
4149 buf
= vao
->BufferBinding
[VERT_ATTRIB_TEX(index
)].BufferObj
;
4150 *param
= buf
? buf
->Name
: 0;
4153 *param
= get_vertex_array_attrib(ctx
, vao
, index
, pname
, "glGetVertexArrayIntegeri_vEXT");
4158 _mesa_GetVertexArrayPointeri_vEXT(GLuint vaobj
, GLuint index
, GLenum pname
, GLvoid
** param
)
4160 GET_CURRENT_CONTEXT(ctx
);
4161 struct gl_vertex_array_object
* vao
;
4163 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
4164 "glGetVertexArrayPointeri_vEXT");
4168 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
4169 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayPointeri_vEXT(index)");
4173 /* The EXT_direct_state_access spec says:
4175 * "For GetVertexArrayPointeri_vEXT, pname must be VERTEX_ATTRIB_ARRAY_POINTER
4176 * or TEXTURE_COORD_ARRAY_POINTER with the index parameter indicating the vertex
4177 * attribute or texture coordindate set index."
4180 case GL_VERTEX_ATTRIB_ARRAY_POINTER
:
4181 *param
= (GLvoid
*) vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
4183 case GL_TEXTURE_COORD_ARRAY_POINTER
:
4184 *param
= (GLvoid
*) vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Ptr
;
4187 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayPointeri_vEXT(pname)");