2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 #include <inttypes.h> /* for PRId64 macro */
32 #include "bufferobj.h"
36 #include "glformats.h"
44 #include "main/dispatch.h"
47 /** Used to do error checking for GL_EXT_vertex_array_bgra */
51 /** Used to indicate which GL datatypes are accepted by each of the
52 * glVertex/Color/Attrib/EtcPointer() functions.
54 #define BOOL_BIT (1 << 0)
55 #define BYTE_BIT (1 << 1)
56 #define UNSIGNED_BYTE_BIT (1 << 2)
57 #define SHORT_BIT (1 << 3)
58 #define UNSIGNED_SHORT_BIT (1 << 4)
59 #define INT_BIT (1 << 5)
60 #define UNSIGNED_INT_BIT (1 << 6)
61 #define HALF_BIT (1 << 7)
62 #define FLOAT_BIT (1 << 8)
63 #define DOUBLE_BIT (1 << 9)
64 #define FIXED_ES_BIT (1 << 10)
65 #define FIXED_GL_BIT (1 << 11)
66 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
67 #define INT_2_10_10_10_REV_BIT (1 << 13)
68 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
69 #define ALL_TYPE_BITS ((1 << 15) - 1)
71 #define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
72 SHORT_BIT | UNSIGNED_SHORT_BIT | \
73 INT_BIT | UNSIGNED_INT_BIT | \
74 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
76 UNSIGNED_INT_2_10_10_10_REV_BIT | \
77 INT_2_10_10_10_REV_BIT | \
78 UNSIGNED_INT_10F_11F_11F_REV_BIT)
80 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
81 SHORT_BIT | UNSIGNED_SHORT_BIT | \
82 INT_BIT | UNSIGNED_INT_BIT)
84 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
87 /** Convert GL datatype enum into a <type>_BIT value seen above */
89 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
96 case GL_UNSIGNED_BYTE
:
97 return UNSIGNED_BYTE_BIT
;
100 case GL_UNSIGNED_SHORT
:
101 return UNSIGNED_SHORT_BIT
;
104 case GL_UNSIGNED_INT
:
105 return UNSIGNED_INT_BIT
;
107 case GL_HALF_FLOAT_OES
:
108 if (ctx
->Extensions
.ARB_half_float_vertex
)
117 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
118 case GL_UNSIGNED_INT_2_10_10_10_REV
:
119 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
120 case GL_INT_2_10_10_10_REV
:
121 return INT_2_10_10_10_REV_BIT
;
122 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
123 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
131 * Depending on the position and generic0 attributes enable flags select
132 * the one that is used for both attributes.
133 * The generic0 attribute takes precedence.
136 update_attribute_map_mode(const struct gl_context
*ctx
,
137 struct gl_vertex_array_object
*vao
)
140 * There is no need to change the mapping away from the
141 * identity mapping if we are not in compat mode.
143 if (ctx
->API
!= API_OPENGL_COMPAT
)
145 /* The generic0 attribute superseeds the position attribute */
146 const GLbitfield enabled
= vao
->Enabled
;
147 if (enabled
& VERT_BIT_GENERIC0
)
148 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_GENERIC0
;
149 else if (enabled
& VERT_BIT_POS
)
150 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_POSITION
;
152 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_IDENTITY
;
157 * Sets the BufferBindingIndex field for the vertex attribute given by
161 _mesa_vertex_attrib_binding(struct gl_context
*ctx
,
162 struct gl_vertex_array_object
*vao
,
163 gl_vert_attrib attribIndex
,
166 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attribIndex
];
167 assert(!vao
->SharedAndImmutable
);
169 if (array
->BufferBindingIndex
!= bindingIndex
) {
170 const GLbitfield array_bit
= VERT_BIT(attribIndex
);
172 if (_mesa_is_bufferobj(vao
->BufferBinding
[bindingIndex
].BufferObj
))
173 vao
->VertexAttribBufferMask
|= array_bit
;
175 vao
->VertexAttribBufferMask
&= ~array_bit
;
177 vao
->BufferBinding
[array
->BufferBindingIndex
]._BoundArrays
&= ~array_bit
;
178 vao
->BufferBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
180 array
->BufferBindingIndex
= bindingIndex
;
182 vao
->NewArrays
|= vao
->Enabled
& array_bit
;
188 * Binds a buffer object to the vertex buffer binding point given by index,
189 * and sets the Offset and Stride fields.
192 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
193 struct gl_vertex_array_object
*vao
,
195 struct gl_buffer_object
*vbo
,
196 GLintptr offset
, GLsizei stride
)
198 assert(index
< ARRAY_SIZE(vao
->BufferBinding
));
199 assert(!vao
->SharedAndImmutable
);
200 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
202 if (ctx
->Const
.VertexBufferOffsetIsInt32
&& (int)offset
< 0 &&
203 _mesa_is_bufferobj(vbo
)) {
204 /* The offset will be interpreted as a signed int, so make sure
205 * the user supplied offset is not negative (driver limitation).
207 _mesa_warning(ctx
, "Received negative int32 vertex buffer offset. "
208 "(driver limitation)\n");
210 /* We can't disable this binding, so use a non-negative offset value
216 if (binding
->BufferObj
!= vbo
||
217 binding
->Offset
!= offset
||
218 binding
->Stride
!= stride
) {
220 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
222 binding
->Offset
= offset
;
223 binding
->Stride
= stride
;
225 if (!_mesa_is_bufferobj(vbo
)) {
226 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
228 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
229 vbo
->UsageHistory
|= USAGE_ARRAY_BUFFER
;
232 vao
->NewArrays
|= vao
->Enabled
& binding
->_BoundArrays
;
238 * Sets the InstanceDivisor field in the vertex buffer binding point
239 * given by bindingIndex.
242 vertex_binding_divisor(struct gl_context
*ctx
,
243 struct gl_vertex_array_object
*vao
,
247 struct gl_vertex_buffer_binding
*binding
=
248 &vao
->BufferBinding
[bindingIndex
];
249 assert(!vao
->SharedAndImmutable
);
251 if (binding
->InstanceDivisor
!= divisor
) {
252 binding
->InstanceDivisor
= divisor
;
253 vao
->NewArrays
|= vao
->Enabled
& binding
->_BoundArrays
;
257 /* vertex_formats[gltype - GL_BYTE][integer*2 + normalized][size - 1] */
258 static const uint16_t vertex_formats
[][4][4] = {
261 PIPE_FORMAT_R8_SSCALED
,
262 PIPE_FORMAT_R8G8_SSCALED
,
263 PIPE_FORMAT_R8G8B8_SSCALED
,
264 PIPE_FORMAT_R8G8B8A8_SSCALED
267 PIPE_FORMAT_R8_SNORM
,
268 PIPE_FORMAT_R8G8_SNORM
,
269 PIPE_FORMAT_R8G8B8_SNORM
,
270 PIPE_FORMAT_R8G8B8A8_SNORM
274 PIPE_FORMAT_R8G8_SINT
,
275 PIPE_FORMAT_R8G8B8_SINT
,
276 PIPE_FORMAT_R8G8B8A8_SINT
279 { /* GL_UNSIGNED_BYTE */
281 PIPE_FORMAT_R8_USCALED
,
282 PIPE_FORMAT_R8G8_USCALED
,
283 PIPE_FORMAT_R8G8B8_USCALED
,
284 PIPE_FORMAT_R8G8B8A8_USCALED
287 PIPE_FORMAT_R8_UNORM
,
288 PIPE_FORMAT_R8G8_UNORM
,
289 PIPE_FORMAT_R8G8B8_UNORM
,
290 PIPE_FORMAT_R8G8B8A8_UNORM
294 PIPE_FORMAT_R8G8_UINT
,
295 PIPE_FORMAT_R8G8B8_UINT
,
296 PIPE_FORMAT_R8G8B8A8_UINT
301 PIPE_FORMAT_R16_SSCALED
,
302 PIPE_FORMAT_R16G16_SSCALED
,
303 PIPE_FORMAT_R16G16B16_SSCALED
,
304 PIPE_FORMAT_R16G16B16A16_SSCALED
307 PIPE_FORMAT_R16_SNORM
,
308 PIPE_FORMAT_R16G16_SNORM
,
309 PIPE_FORMAT_R16G16B16_SNORM
,
310 PIPE_FORMAT_R16G16B16A16_SNORM
313 PIPE_FORMAT_R16_SINT
,
314 PIPE_FORMAT_R16G16_SINT
,
315 PIPE_FORMAT_R16G16B16_SINT
,
316 PIPE_FORMAT_R16G16B16A16_SINT
319 { /* GL_UNSIGNED_SHORT */
321 PIPE_FORMAT_R16_USCALED
,
322 PIPE_FORMAT_R16G16_USCALED
,
323 PIPE_FORMAT_R16G16B16_USCALED
,
324 PIPE_FORMAT_R16G16B16A16_USCALED
327 PIPE_FORMAT_R16_UNORM
,
328 PIPE_FORMAT_R16G16_UNORM
,
329 PIPE_FORMAT_R16G16B16_UNORM
,
330 PIPE_FORMAT_R16G16B16A16_UNORM
333 PIPE_FORMAT_R16_UINT
,
334 PIPE_FORMAT_R16G16_UINT
,
335 PIPE_FORMAT_R16G16B16_UINT
,
336 PIPE_FORMAT_R16G16B16A16_UINT
341 PIPE_FORMAT_R32_SSCALED
,
342 PIPE_FORMAT_R32G32_SSCALED
,
343 PIPE_FORMAT_R32G32B32_SSCALED
,
344 PIPE_FORMAT_R32G32B32A32_SSCALED
347 PIPE_FORMAT_R32_SNORM
,
348 PIPE_FORMAT_R32G32_SNORM
,
349 PIPE_FORMAT_R32G32B32_SNORM
,
350 PIPE_FORMAT_R32G32B32A32_SNORM
353 PIPE_FORMAT_R32_SINT
,
354 PIPE_FORMAT_R32G32_SINT
,
355 PIPE_FORMAT_R32G32B32_SINT
,
356 PIPE_FORMAT_R32G32B32A32_SINT
359 { /* GL_UNSIGNED_INT */
361 PIPE_FORMAT_R32_USCALED
,
362 PIPE_FORMAT_R32G32_USCALED
,
363 PIPE_FORMAT_R32G32B32_USCALED
,
364 PIPE_FORMAT_R32G32B32A32_USCALED
367 PIPE_FORMAT_R32_UNORM
,
368 PIPE_FORMAT_R32G32_UNORM
,
369 PIPE_FORMAT_R32G32B32_UNORM
,
370 PIPE_FORMAT_R32G32B32A32_UNORM
373 PIPE_FORMAT_R32_UINT
,
374 PIPE_FORMAT_R32G32_UINT
,
375 PIPE_FORMAT_R32G32B32_UINT
,
376 PIPE_FORMAT_R32G32B32A32_UINT
381 PIPE_FORMAT_R32_FLOAT
,
382 PIPE_FORMAT_R32G32_FLOAT
,
383 PIPE_FORMAT_R32G32B32_FLOAT
,
384 PIPE_FORMAT_R32G32B32A32_FLOAT
387 PIPE_FORMAT_R32_FLOAT
,
388 PIPE_FORMAT_R32G32_FLOAT
,
389 PIPE_FORMAT_R32G32B32_FLOAT
,
390 PIPE_FORMAT_R32G32B32A32_FLOAT
393 {{0}}, /* GL_2_BYTES */
394 {{0}}, /* GL_3_BYTES */
395 {{0}}, /* GL_4_BYTES */
398 PIPE_FORMAT_R64_FLOAT
,
399 PIPE_FORMAT_R64G64_FLOAT
,
400 PIPE_FORMAT_R64G64B64_FLOAT
,
401 PIPE_FORMAT_R64G64B64A64_FLOAT
404 PIPE_FORMAT_R64_FLOAT
,
405 PIPE_FORMAT_R64G64_FLOAT
,
406 PIPE_FORMAT_R64G64B64_FLOAT
,
407 PIPE_FORMAT_R64G64B64A64_FLOAT
410 { /* GL_HALF_FLOAT */
412 PIPE_FORMAT_R16_FLOAT
,
413 PIPE_FORMAT_R16G16_FLOAT
,
414 PIPE_FORMAT_R16G16B16_FLOAT
,
415 PIPE_FORMAT_R16G16B16A16_FLOAT
418 PIPE_FORMAT_R16_FLOAT
,
419 PIPE_FORMAT_R16G16_FLOAT
,
420 PIPE_FORMAT_R16G16B16_FLOAT
,
421 PIPE_FORMAT_R16G16B16A16_FLOAT
426 PIPE_FORMAT_R32_FIXED
,
427 PIPE_FORMAT_R32G32_FIXED
,
428 PIPE_FORMAT_R32G32B32_FIXED
,
429 PIPE_FORMAT_R32G32B32A32_FIXED
432 PIPE_FORMAT_R32_FIXED
,
433 PIPE_FORMAT_R32G32_FIXED
,
434 PIPE_FORMAT_R32G32B32_FIXED
,
435 PIPE_FORMAT_R32G32B32A32_FIXED
441 * Return a PIPE_FORMAT_x for the given GL datatype and size.
443 static enum pipe_format
444 vertex_format_to_pipe_format(GLubyte size
, GLenum16 type
, GLenum16 format
,
445 GLboolean normalized
, GLboolean integer
,
448 assert(size
>= 1 && size
<= 4);
449 assert(format
== GL_RGBA
|| format
== GL_BGRA
);
451 /* 64-bit attributes are translated by drivers. */
453 return PIPE_FORMAT_NONE
;
456 case GL_HALF_FLOAT_OES
:
457 type
= GL_HALF_FLOAT
;
460 case GL_INT_2_10_10_10_REV
:
461 assert(size
== 4 && !integer
);
463 if (format
== GL_BGRA
) {
465 return PIPE_FORMAT_B10G10R10A2_SNORM
;
467 return PIPE_FORMAT_B10G10R10A2_SSCALED
;
470 return PIPE_FORMAT_R10G10B10A2_SNORM
;
472 return PIPE_FORMAT_R10G10B10A2_SSCALED
;
476 case GL_UNSIGNED_INT_2_10_10_10_REV
:
477 assert(size
== 4 && !integer
);
479 if (format
== GL_BGRA
) {
481 return PIPE_FORMAT_B10G10R10A2_UNORM
;
483 return PIPE_FORMAT_B10G10R10A2_USCALED
;
486 return PIPE_FORMAT_R10G10B10A2_UNORM
;
488 return PIPE_FORMAT_R10G10B10A2_USCALED
;
492 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
493 assert(size
== 3 && !integer
&& format
== GL_RGBA
);
494 return PIPE_FORMAT_R11G11B10_FLOAT
;
496 case GL_UNSIGNED_BYTE
:
497 if (format
== GL_BGRA
) {
498 /* this is an odd-ball case */
500 return PIPE_FORMAT_B8G8R8A8_UNORM
;
505 unsigned index
= integer
*2 + normalized
;
507 assert(type
>= GL_BYTE
&& type
<= GL_FIXED
);
508 return vertex_formats
[type
- GL_BYTE
][index
][size
-1];
512 _mesa_set_vertex_format(struct gl_vertex_format
*vertex_format
,
513 GLubyte size
, GLenum16 type
, GLenum16 format
,
514 GLboolean normalized
, GLboolean integer
,
518 vertex_format
->Type
= type
;
519 vertex_format
->Format
= format
;
520 vertex_format
->Size
= size
;
521 vertex_format
->Normalized
= normalized
;
522 vertex_format
->Integer
= integer
;
523 vertex_format
->Doubles
= doubles
;
524 vertex_format
->_ElementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
525 assert(vertex_format
->_ElementSize
<= 4*sizeof(double));
526 vertex_format
->_PipeFormat
=
527 vertex_format_to_pipe_format(size
, type
, format
, normalized
, integer
,
533 * Examine the API profile and extensions to determine which types are legal
534 * for vertex arrays. This is called once from update_array_format().
537 get_legal_types_mask(const struct gl_context
*ctx
)
539 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
541 if (_mesa_is_gles(ctx
)) {
542 legalTypesMask
&= ~(FIXED_GL_BIT
|
544 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
546 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
547 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
548 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
549 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
550 * quite as trivial as we'd like because it uses a different enum value
551 * for GL_HALF_FLOAT_OES.
553 if (ctx
->Version
< 30) {
554 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
556 UNSIGNED_INT_2_10_10_10_REV_BIT
|
557 INT_2_10_10_10_REV_BIT
);
559 if (!_mesa_has_OES_vertex_half_float(ctx
))
560 legalTypesMask
&= ~HALF_BIT
;
564 legalTypesMask
&= ~FIXED_ES_BIT
;
566 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
567 legalTypesMask
&= ~FIXED_GL_BIT
;
569 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
570 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
571 INT_2_10_10_10_REV_BIT
);
573 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
574 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
577 return legalTypesMask
;
581 get_array_format(const struct gl_context
*ctx
, GLint sizeMax
, GLint
*size
)
583 GLenum format
= GL_RGBA
;
585 /* Do size parameter checking.
586 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
587 * must be handled specially.
589 if (ctx
->Extensions
.EXT_vertex_array_bgra
&& sizeMax
== BGRA_OR_4
&&
600 * \param attrib The index of the attribute array
601 * \param size Components per element (1, 2, 3 or 4)
602 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
603 * \param format Either GL_RGBA or GL_BGRA.
604 * \param normalized Whether integer types are converted to floats in [-1, 1]
605 * \param integer Integer-valued values (will not be normalized to [-1, 1])
606 * \param doubles Double values not reduced to floats
607 * \param relativeOffset Offset of the first element relative to the binding
611 _mesa_update_array_format(struct gl_context
*ctx
,
612 struct gl_vertex_array_object
*vao
,
613 gl_vert_attrib attrib
, GLint size
, GLenum type
,
614 GLenum format
, GLboolean normalized
,
615 GLboolean integer
, GLboolean doubles
,
616 GLuint relativeOffset
)
618 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
620 assert(!vao
->SharedAndImmutable
);
623 array
->RelativeOffset
= relativeOffset
;
624 _mesa_set_vertex_format(&array
->Format
, size
, type
, format
,
625 normalized
, integer
, doubles
);
627 vao
->NewArrays
|= vao
->Enabled
& VERT_BIT(attrib
);
631 * Does error checking of the format in an attrib array.
633 * Called by *Pointer() and VertexAttrib*Format().
635 * \param func Name of calling function used for error reporting
636 * \param attrib The index of the attribute array
637 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
638 * \param sizeMin Min allowable size value
639 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
640 * \param size Components per element (1, 2, 3 or 4)
641 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
642 * \param normalized Whether integer types are converted to floats in [-1, 1]
643 * \param integer Integer-valued values (will not be normalized to [-1, 1])
644 * \param doubles Double values not reduced to floats
645 * \param relativeOffset Offset of the first element relative to the binding offset.
646 * \return bool True if validation is successful, False otherwise.
649 validate_array_format(struct gl_context
*ctx
, const char *func
,
650 struct gl_vertex_array_object
*vao
,
651 GLuint attrib
, GLbitfield legalTypesMask
,
652 GLint sizeMin
, GLint sizeMax
,
653 GLint size
, GLenum type
, GLboolean normalized
,
654 GLboolean integer
, GLboolean doubles
,
655 GLuint relativeOffset
, GLenum format
)
659 /* at most, one of these bools can be true */
660 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
662 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
663 /* Compute the LegalTypesMask only once, unless the context API has
664 * changed, in which case we want to compute it again. We can't do this
665 * in _mesa_init_varrays() below because extensions are not yet enabled
668 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
669 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
672 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
674 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
675 /* BGRA ordering is not supported in ES contexts.
680 typeBit
= type_to_bit(ctx
, type
);
681 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
682 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
683 func
, _mesa_enum_to_string(type
));
687 if (format
== GL_BGRA
) {
688 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
690 * "An INVALID_OPERATION error is generated under any of the following
693 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
694 * or UNSIGNED_INT_2_10_10_10_REV;
696 * • size is BGRA and normalized is FALSE;"
698 bool bgra_error
= false;
700 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
701 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
702 type
!= GL_INT_2_10_10_10_REV
&&
703 type
!= GL_UNSIGNED_BYTE
)
705 } else if (type
!= GL_UNSIGNED_BYTE
)
709 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
710 func
, _mesa_enum_to_string(type
));
715 _mesa_error(ctx
, GL_INVALID_OPERATION
,
716 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
720 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
721 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
725 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
726 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
727 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
728 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
732 /* The ARB_vertex_attrib_binding_spec says:
734 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
735 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
737 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
738 _mesa_error(ctx
, GL_INVALID_VALUE
,
739 "%s(relativeOffset=%d > "
740 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
741 func
, relativeOffset
);
745 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
746 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
747 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
755 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
757 * \param func name of calling function used for error reporting
758 * \param vao the vao to update
759 * \param obj the bound buffer object
760 * \param attrib the attribute array index to update
761 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
762 * \param sizeMin min allowable size value
763 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
764 * \param size components per element (1, 2, 3 or 4)
765 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
766 * \param stride stride between elements, in elements
767 * \param normalized are integer types converted to floats in [-1, 1]?
768 * \param integer integer-valued values (will not be normalized to [-1,1])
769 * \param doubles Double values not reduced to floats
770 * \param ptr the address (or offset inside VBO) of the array data
773 validate_array(struct gl_context
*ctx
, const char *func
,
774 struct gl_vertex_array_object
*vao
,
775 struct gl_buffer_object
*obj
,
776 GLuint attrib
, GLbitfield legalTypesMask
,
777 GLint sizeMin
, GLint sizeMax
,
778 GLint size
, GLenum type
, GLsizei stride
,
779 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
782 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
784 * "Client vertex arrays - all vertex array attribute pointers must
785 * refer to buffer objects (section 2.9.2). The default vertex array
786 * object (the name zero) is also deprecated. Calling
787 * VertexAttribPointer when no buffer object or no vertex array object
788 * is bound will generate an INVALID_OPERATION error..."
790 * The check for VBOs is handled below.
792 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
793 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
799 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
803 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
804 stride
> ctx
->Const
.MaxVertexAttribStride
) {
805 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
806 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
810 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
812 * "An INVALID_OPERATION error is generated under any of the following
817 * * any of the *Pointer commands specifying the location and
818 * organization of vertex array data are called while zero is bound
819 * to the ARRAY_BUFFER buffer object binding point (see section
820 * 2.9.6), and the pointer argument is not NULL."
822 if (ptr
!= NULL
&& vao
!= ctx
->Array
.DefaultVAO
&&
823 !_mesa_is_bufferobj(obj
)) {
824 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
831 validate_array_and_format(struct gl_context
*ctx
, const char *func
,
832 struct gl_vertex_array_object
*vao
,
833 struct gl_buffer_object
*obj
,
834 GLuint attrib
, GLbitfield legalTypes
,
835 GLint sizeMin
, GLint sizeMax
,
836 GLint size
, GLenum type
, GLsizei stride
,
837 GLboolean normalized
, GLboolean integer
,
838 GLboolean doubles
, GLenum format
, const GLvoid
*ptr
)
840 validate_array(ctx
, func
, vao
, obj
, attrib
, legalTypes
, sizeMin
, sizeMax
,
841 size
, type
, stride
, normalized
, integer
, doubles
, ptr
);
843 return validate_array_format(ctx
, func
, vao
, attrib
, legalTypes
, sizeMin
,
844 sizeMax
, size
, type
, normalized
, integer
,
850 * Update state for glVertex/Color/TexCoord/...Pointer functions.
852 * \param vao the vao to update
853 * \param obj the bound buffer object
854 * \param attrib the attribute array index to update
855 * \param format Either GL_RGBA or GL_BGRA.
856 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
857 * \param size components per element (1, 2, 3 or 4)
858 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
859 * \param stride stride between elements, in elements
860 * \param normalized are integer types converted to floats in [-1, 1]?
861 * \param integer integer-valued values (will not be normalized to [-1,1])
862 * \param doubles Double values not reduced to floats
863 * \param ptr the address (or offset inside VBO) of the array data
866 update_array(struct gl_context
*ctx
,
867 struct gl_vertex_array_object
*vao
,
868 struct gl_buffer_object
*obj
,
869 GLuint attrib
, GLenum format
,
871 GLint size
, GLenum type
, GLsizei stride
,
872 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
875 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
876 normalized
, integer
, doubles
, 0);
878 /* Reset the vertex attrib binding */
879 _mesa_vertex_attrib_binding(ctx
, vao
, attrib
, attrib
);
881 /* The Stride and Ptr fields are not set by update_array_format() */
882 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attrib
];
883 array
->Stride
= stride
;
884 /* For updating the pointer we would need to add the vao->NewArrays flag
885 * to the VAO. But but that is done already unconditionally in
886 * _mesa_update_array_format called above.
888 assert((vao
->NewArrays
| ~vao
->Enabled
) & VERT_BIT(attrib
));
891 /* Update the vertex buffer binding */
892 GLsizei effectiveStride
= stride
!= 0 ?
893 stride
: array
->Format
._ElementSize
;
894 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
900 /* Helper function for all EXT_direct_state_access glVertexArray* functions */
902 _lookup_vao_and_vbo_dsa(struct gl_context
*ctx
,
903 GLuint vaobj
, GLuint buffer
,
905 struct gl_vertex_array_object
** vao
,
906 struct gl_buffer_object
** vbo
,
909 *vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, caller
);
914 *vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
915 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, vbo
, caller
))
919 _mesa_error(ctx
, GL_INVALID_VALUE
,
920 "%s(negative offset with non-0 buffer)", caller
);
924 *vbo
= ctx
->Shared
->NullBufferObj
;
932 _mesa_VertexPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
935 GET_CURRENT_CONTEXT(ctx
);
937 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
938 VERT_ATTRIB_POS
, GL_RGBA
, 4, size
, type
, stride
,
939 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
944 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
946 GET_CURRENT_CONTEXT(ctx
);
948 GLenum format
= GL_RGBA
;
949 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
950 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
951 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
952 DOUBLE_BIT
| HALF_BIT
|
953 UNSIGNED_INT_2_10_10_10_REV_BIT
|
954 INT_2_10_10_10_REV_BIT
);
956 if (!validate_array_and_format(ctx
, "glVertexPointer",
957 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
958 VERT_ATTRIB_POS
, legalTypes
, 2, 4, size
,
959 type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
963 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
964 VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
965 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
970 _mesa_VertexArrayVertexOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
971 GLenum type
, GLsizei stride
, GLintptr offset
)
973 GET_CURRENT_CONTEXT(ctx
);
975 GLenum format
= GL_RGBA
;
976 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
977 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
978 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
979 DOUBLE_BIT
| HALF_BIT
|
980 UNSIGNED_INT_2_10_10_10_REV_BIT
|
981 INT_2_10_10_10_REV_BIT
);
983 struct gl_vertex_array_object
* vao
;
984 struct gl_buffer_object
* vbo
;
986 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
988 "glVertexArrayVertexOffsetEXT"))
991 if (!validate_array_and_format(ctx
, "glVertexArrayVertexOffsetEXT",
993 VERT_ATTRIB_POS
, legalTypes
, 2, 4, size
,
994 type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
995 format
, (void*) offset
))
998 update_array(ctx
, vao
, vbo
,
999 VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
1000 GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1005 _mesa_NormalPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1007 GET_CURRENT_CONTEXT(ctx
);
1009 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1010 VERT_ATTRIB_NORMAL
, GL_RGBA
, 3, 3, type
, stride
, GL_TRUE
,
1011 GL_FALSE
, GL_FALSE
, ptr
);
1016 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1018 GET_CURRENT_CONTEXT(ctx
);
1020 GLenum format
= GL_RGBA
;
1021 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1022 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1023 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1024 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1025 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1026 INT_2_10_10_10_REV_BIT
);
1028 if (!validate_array_and_format(ctx
, "glNormalPointer",
1029 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1030 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
1031 type
, stride
, GL_TRUE
, GL_FALSE
,
1032 GL_FALSE
, format
, ptr
))
1035 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1036 VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
1037 GL_FALSE
, GL_FALSE
, ptr
);
1042 _mesa_VertexArrayNormalOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1043 GLsizei stride
, GLintptr offset
)
1045 GET_CURRENT_CONTEXT(ctx
);
1047 GLenum format
= GL_RGBA
;
1048 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1049 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1050 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1051 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1052 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1053 INT_2_10_10_10_REV_BIT
);
1055 struct gl_vertex_array_object
* vao
;
1056 struct gl_buffer_object
* vbo
;
1058 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1063 if (!validate_array_and_format(ctx
, "glNormalPointer",
1065 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
1066 type
, stride
, GL_TRUE
, GL_FALSE
,
1067 GL_FALSE
, format
, (void*) offset
))
1070 update_array(ctx
, vao
, vbo
,
1071 VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
1072 GL_FALSE
, GL_FALSE
, (void*) offset
);
1077 _mesa_ColorPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
1080 GET_CURRENT_CONTEXT(ctx
);
1082 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1083 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1084 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
1085 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1090 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1092 GET_CURRENT_CONTEXT(ctx
);
1093 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
1095 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1096 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1097 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1098 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1099 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1100 INT_BIT
| UNSIGNED_INT_BIT
|
1101 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1102 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1103 INT_2_10_10_10_REV_BIT
);
1105 if (!validate_array_and_format(ctx
, "glColorPointer",
1106 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1107 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
1108 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
1109 GL_FALSE
, GL_FALSE
, format
, ptr
))
1112 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1113 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
1114 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1119 _mesa_VertexArrayColorOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1120 GLenum type
, GLsizei stride
, GLintptr offset
)
1122 GET_CURRENT_CONTEXT(ctx
);
1123 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
1125 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1126 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1127 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1128 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1129 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1130 INT_BIT
| UNSIGNED_INT_BIT
|
1131 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1132 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1133 INT_2_10_10_10_REV_BIT
);
1135 struct gl_vertex_array_object
* vao
;
1136 struct gl_buffer_object
* vbo
;
1138 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1140 "glVertexArrayColorOffsetEXT"))
1143 if (!validate_array_and_format(ctx
, "glVertexArrayColorOffsetEXT",
1145 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
1146 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
1147 GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1150 update_array(ctx
, vao
, vbo
,
1151 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
1152 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1157 _mesa_FogCoordPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1159 GET_CURRENT_CONTEXT(ctx
);
1161 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1162 VERT_ATTRIB_FOG
, GL_RGBA
, 1, 1, type
, stride
, GL_FALSE
,
1163 GL_FALSE
, GL_FALSE
, ptr
);
1168 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1170 GET_CURRENT_CONTEXT(ctx
);
1172 GLenum format
= GL_RGBA
;
1173 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
1175 if (!validate_array_and_format(ctx
, "glFogCoordPointer",
1176 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1177 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
1178 type
, stride
, GL_FALSE
, GL_FALSE
,
1179 GL_FALSE
, format
, ptr
))
1182 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1183 VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
1184 GL_FALSE
, GL_FALSE
, ptr
);
1189 _mesa_VertexArrayFogCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1190 GLsizei stride
, GLintptr offset
)
1192 GET_CURRENT_CONTEXT(ctx
);
1194 GLenum format
= GL_RGBA
;
1195 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
1197 struct gl_vertex_array_object
* vao
;
1198 struct gl_buffer_object
* vbo
;
1200 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1202 "glVertexArrayFogCoordOffsetEXT"))
1205 if (!validate_array_and_format(ctx
, "glVertexArrayFogCoordOffsetEXT",
1207 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
1208 type
, stride
, GL_FALSE
, GL_FALSE
,
1209 GL_FALSE
, format
, (void*) offset
))
1212 update_array(ctx
, vao
, vbo
,
1213 VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
1214 GL_FALSE
, GL_FALSE
, (void*) offset
);
1219 _mesa_IndexPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1221 GET_CURRENT_CONTEXT(ctx
);
1223 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1224 VERT_ATTRIB_COLOR_INDEX
, GL_RGBA
, 1, 1, type
, stride
,
1225 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1230 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1232 GET_CURRENT_CONTEXT(ctx
);
1234 GLenum format
= GL_RGBA
;
1235 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1236 FLOAT_BIT
| DOUBLE_BIT
);
1238 if (!validate_array_and_format(ctx
, "glIndexPointer",
1239 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1240 VERT_ATTRIB_COLOR_INDEX
,
1241 legalTypes
, 1, 1, 1, type
, stride
,
1242 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1245 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1246 VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
1247 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1252 _mesa_VertexArrayIndexOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
1253 GLsizei stride
, GLintptr offset
)
1255 GET_CURRENT_CONTEXT(ctx
);
1257 GLenum format
= GL_RGBA
;
1258 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
1259 FLOAT_BIT
| DOUBLE_BIT
);
1261 struct gl_vertex_array_object
* vao
;
1262 struct gl_buffer_object
* vbo
;
1264 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1266 "glVertexArrayIndexOffsetEXT"))
1269 if (!validate_array_and_format(ctx
, "glVertexArrayIndexOffsetEXT",
1271 VERT_ATTRIB_COLOR_INDEX
,
1272 legalTypes
, 1, 1, 1, type
, stride
,
1273 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1276 update_array(ctx
, vao
, vbo
,
1277 VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
1278 GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1283 _mesa_SecondaryColorPointer_no_error(GLint size
, GLenum type
,
1284 GLsizei stride
, const GLvoid
*ptr
)
1286 GET_CURRENT_CONTEXT(ctx
);
1288 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1289 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1290 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
1291 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1296 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
1297 GLsizei stride
, const GLvoid
*ptr
)
1299 GET_CURRENT_CONTEXT(ctx
);
1301 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1302 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1303 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1304 INT_BIT
| UNSIGNED_INT_BIT
|
1305 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1306 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1307 INT_2_10_10_10_REV_BIT
);
1309 if (!validate_array_and_format(ctx
, "glSecondaryColorPointer",
1310 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1311 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
1312 BGRA_OR_4
, size
, type
, stride
,
1313 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1316 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1317 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
1318 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
1323 _mesa_VertexArraySecondaryColorOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1324 GLenum type
, GLsizei stride
, GLintptr offset
)
1326 GET_CURRENT_CONTEXT(ctx
);
1328 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1329 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1330 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1331 INT_BIT
| UNSIGNED_INT_BIT
|
1332 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1333 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1334 INT_2_10_10_10_REV_BIT
);
1336 struct gl_vertex_array_object
* vao
;
1337 struct gl_buffer_object
* vbo
;
1339 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1341 "glVertexArraySecondaryColorOffsetEXT"))
1344 if (!validate_array_and_format(ctx
, "glVertexArraySecondaryColorOffsetEXT",
1346 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
1347 BGRA_OR_4
, size
, type
, stride
,
1348 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1351 update_array(ctx
, vao
, vbo
,
1352 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
1353 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1358 _mesa_TexCoordPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
1361 GET_CURRENT_CONTEXT(ctx
);
1362 const GLuint unit
= ctx
->Array
.ActiveTexture
;
1364 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1365 VERT_ATTRIB_TEX(unit
), GL_RGBA
, 4, size
, type
,
1366 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1371 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
1374 GET_CURRENT_CONTEXT(ctx
);
1375 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1376 const GLuint unit
= ctx
->Array
.ActiveTexture
;
1378 GLenum format
= GL_RGBA
;
1379 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1380 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1381 : (SHORT_BIT
| INT_BIT
|
1382 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1383 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1384 INT_2_10_10_10_REV_BIT
);
1386 if (!validate_array_and_format(ctx
, "glTexCoordPointer",
1387 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1388 VERT_ATTRIB_TEX(unit
), legalTypes
,
1389 sizeMin
, 4, size
, type
, stride
,
1390 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1393 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1394 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
1395 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1400 _mesa_VertexArrayTexCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
1401 GLenum type
, GLsizei stride
, GLintptr offset
)
1403 GET_CURRENT_CONTEXT(ctx
);
1404 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1405 const GLuint unit
= ctx
->Array
.ActiveTexture
;
1407 GLenum format
= GL_RGBA
;
1408 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1409 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1410 : (SHORT_BIT
| INT_BIT
|
1411 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1412 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1413 INT_2_10_10_10_REV_BIT
);
1415 struct gl_vertex_array_object
* vao
;
1416 struct gl_buffer_object
* vbo
;
1418 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1420 "glVertexArrayTexCoordOffsetEXT"))
1423 if (!validate_array_and_format(ctx
, "glVertexArrayTexCoordOffsetEXT",
1425 VERT_ATTRIB_TEX(unit
), legalTypes
,
1426 sizeMin
, 4, size
, type
, stride
,
1427 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1430 update_array(ctx
, vao
, vbo
,
1431 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
1432 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1437 _mesa_VertexArrayMultiTexCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum texunit
,
1438 GLint size
, GLenum type
, GLsizei stride
,
1441 GET_CURRENT_CONTEXT(ctx
);
1442 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
1443 const GLuint unit
= texunit
- GL_TEXTURE0
;
1445 GLenum format
= GL_RGBA
;
1446 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
1447 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
1448 : (SHORT_BIT
| INT_BIT
|
1449 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1450 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1451 INT_2_10_10_10_REV_BIT
);
1453 struct gl_vertex_array_object
* vao
;
1454 struct gl_buffer_object
* vbo
;
1456 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1458 "glVertexArrayMultiTexCoordOffsetEXT"))
1461 if (unit
>= ctx
->Const
.MaxCombinedTextureImageUnits
) {
1462 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexArrayMultiTexCoordOffsetEXT(texunit=%d)",
1467 if (!validate_array_and_format(ctx
, "glVertexArrayMultiTexCoordOffsetEXT",
1469 VERT_ATTRIB_TEX(unit
), legalTypes
,
1470 sizeMin
, 4, size
, type
, stride
,
1471 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1474 update_array(ctx
, vao
, vbo
,
1475 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
1476 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1481 _mesa_EdgeFlagPointer_no_error(GLsizei stride
, const GLvoid
*ptr
)
1483 /* this is the same type that glEdgeFlag uses */
1484 const GLboolean integer
= GL_FALSE
;
1485 GET_CURRENT_CONTEXT(ctx
);
1487 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1488 VERT_ATTRIB_EDGEFLAG
, GL_RGBA
, 1, 1, GL_UNSIGNED_BYTE
,
1489 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
1494 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
1496 /* this is the same type that glEdgeFlag uses */
1497 const GLboolean integer
= GL_FALSE
;
1498 GET_CURRENT_CONTEXT(ctx
);
1500 GLenum format
= GL_RGBA
;
1501 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
1503 if (!validate_array_and_format(ctx
, "glEdgeFlagPointer",
1504 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1505 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
1506 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
1507 GL_FALSE
, integer
, GL_FALSE
, format
, ptr
))
1510 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1511 VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
1512 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
1517 _mesa_VertexArrayEdgeFlagOffsetEXT(GLuint vaobj
, GLuint buffer
, GLsizei stride
,
1520 /* this is the same type that glEdgeFlag uses */
1521 const GLboolean integer
= GL_FALSE
;
1522 GET_CURRENT_CONTEXT(ctx
);
1524 GLenum format
= GL_RGBA
;
1525 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
1527 struct gl_vertex_array_object
* vao
;
1528 struct gl_buffer_object
* vbo
;
1530 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1532 "glVertexArrayEdgeFlagOffsetEXT"))
1535 if (!validate_array_and_format(ctx
, "glVertexArrayEdgeFlagOffsetEXT",
1537 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
1538 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
1539 GL_FALSE
, integer
, GL_FALSE
, format
, (void*) offset
))
1542 update_array(ctx
, vao
, vbo
,
1543 VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
1544 stride
, GL_FALSE
, integer
, GL_FALSE
, (void*) offset
);
1549 _mesa_PointSizePointerOES_no_error(GLenum type
, GLsizei stride
,
1552 GET_CURRENT_CONTEXT(ctx
);
1554 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1555 VERT_ATTRIB_POINT_SIZE
, GL_RGBA
, 1, 1, type
, stride
,
1556 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1561 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1563 GET_CURRENT_CONTEXT(ctx
);
1565 GLenum format
= GL_RGBA
;
1566 if (ctx
->API
!= API_OPENGLES
) {
1567 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1568 "glPointSizePointer(ES 1.x only)");
1572 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
1574 if (!validate_array_and_format(ctx
, "glPointSizePointer",
1575 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1576 VERT_ATTRIB_POINT_SIZE
, legalTypes
,
1577 1, 1, 1, type
, stride
, GL_FALSE
, GL_FALSE
,
1578 GL_FALSE
, format
, ptr
))
1581 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1582 VERT_ATTRIB_POINT_SIZE
, format
, 1, 1, type
, stride
,
1583 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1588 _mesa_VertexAttribPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1589 GLboolean normalized
,
1590 GLsizei stride
, const GLvoid
*ptr
)
1592 GET_CURRENT_CONTEXT(ctx
);
1594 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1595 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1596 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1597 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
1602 * Set a generic vertex attribute array.
1603 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1604 * (position, normal, color, fog, texcoord, etc).
1607 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
1608 GLboolean normalized
,
1609 GLsizei stride
, const GLvoid
*ptr
)
1611 GET_CURRENT_CONTEXT(ctx
);
1613 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1614 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1615 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(idx)");
1619 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1620 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1621 INT_BIT
| UNSIGNED_INT_BIT
|
1622 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1623 FIXED_ES_BIT
| FIXED_GL_BIT
|
1624 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1625 INT_2_10_10_10_REV_BIT
|
1626 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1628 if (!validate_array_and_format(ctx
, "glVertexAttribPointer",
1629 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1630 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1631 1, BGRA_OR_4
, size
, type
, stride
,
1632 normalized
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1635 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1636 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1637 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
1642 _mesa_VertexArrayVertexAttribOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1643 GLenum type
, GLboolean normalized
,
1644 GLsizei stride
, GLintptr offset
)
1646 GET_CURRENT_CONTEXT(ctx
);
1647 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1648 struct gl_vertex_array_object
* vao
;
1649 struct gl_buffer_object
* vbo
;
1651 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1653 "glVertexArrayVertexAttribOffsetEXT"))
1656 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1657 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribOffsetEXT(idx)");
1661 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1662 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1663 INT_BIT
| UNSIGNED_INT_BIT
|
1664 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1665 FIXED_ES_BIT
| FIXED_GL_BIT
|
1666 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1667 INT_2_10_10_10_REV_BIT
|
1668 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1670 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribOffsetEXT",
1672 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1673 1, BGRA_OR_4
, size
, type
, stride
,
1674 normalized
, GL_FALSE
, GL_FALSE
, format
, (void*) offset
))
1677 update_array(ctx
, vao
, vbo
,
1678 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1679 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, (void*) offset
);
1684 _mesa_VertexArrayVertexAttribLOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1685 GLenum type
, GLsizei stride
, GLintptr offset
)
1687 GET_CURRENT_CONTEXT(ctx
);
1688 GLenum format
= GL_RGBA
;
1689 struct gl_vertex_array_object
* vao
;
1690 struct gl_buffer_object
* vbo
;
1692 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1694 "glVertexArrayVertexAttribLOffsetEXT"))
1697 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1698 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribLOffsetEXT(idx)");
1702 const GLbitfield legalTypes
= DOUBLE_BIT
;
1704 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribLOffsetEXT",
1706 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1707 1, 4, size
, type
, stride
,
1708 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
, (void*) offset
))
1711 update_array(ctx
, vao
, vbo
,
1712 VERT_ATTRIB_GENERIC(index
), format
, 4,
1713 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, (void*) offset
);
1718 _mesa_VertexAttribIPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1719 GLsizei stride
, const GLvoid
*ptr
)
1721 const GLboolean normalized
= GL_FALSE
;
1722 const GLboolean integer
= GL_TRUE
;
1723 GET_CURRENT_CONTEXT(ctx
);
1725 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1726 VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1727 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1732 * GL_EXT_gpu_shader4 / GL 3.0.
1733 * Set an integer-valued vertex attribute array.
1734 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1735 * (position, normal, color, fog, texcoord, etc).
1738 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
1739 GLsizei stride
, const GLvoid
*ptr
)
1741 const GLboolean normalized
= GL_FALSE
;
1742 const GLboolean integer
= GL_TRUE
;
1743 GET_CURRENT_CONTEXT(ctx
);
1745 GLenum format
= GL_RGBA
;
1746 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1747 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
1751 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1752 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1753 INT_BIT
| UNSIGNED_INT_BIT
);
1755 if (!validate_array_and_format(ctx
, "glVertexAttribIPointer",
1756 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1757 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1758 1, 4, size
, type
, stride
,
1759 normalized
, integer
, GL_FALSE
, format
, ptr
))
1762 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1763 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1764 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1769 _mesa_VertexAttribLPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1770 GLsizei stride
, const GLvoid
*ptr
)
1772 GET_CURRENT_CONTEXT(ctx
);
1774 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1775 VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1776 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1781 _mesa_VertexArrayVertexAttribIOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1782 GLenum type
, GLsizei stride
, GLintptr offset
)
1784 const GLboolean normalized
= GL_FALSE
;
1785 const GLboolean integer
= GL_TRUE
;
1786 GET_CURRENT_CONTEXT(ctx
);
1787 GLenum format
= GL_RGBA
;
1789 struct gl_vertex_array_object
* vao
;
1790 struct gl_buffer_object
* vbo
;
1792 if (!_lookup_vao_and_vbo_dsa(ctx
, vaobj
, buffer
, offset
,
1794 "glVertexArrayVertexAttribIOffsetEXT"))
1797 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1798 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexArrayVertexAttribIOffsetEXT(index)");
1802 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1803 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1804 INT_BIT
| UNSIGNED_INT_BIT
);
1806 if (!validate_array_and_format(ctx
, "glVertexArrayVertexAttribIOffsetEXT",
1808 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1809 1, 4, size
, type
, stride
,
1810 normalized
, integer
, GL_FALSE
, format
, (void*) offset
))
1813 update_array(ctx
, vao
, vbo
,
1814 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1815 stride
, normalized
, integer
, GL_FALSE
, (void*) offset
);
1820 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
1821 GLsizei stride
, const GLvoid
*ptr
)
1823 GET_CURRENT_CONTEXT(ctx
);
1825 GLenum format
= GL_RGBA
;
1826 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1827 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
1831 const GLbitfield legalTypes
= DOUBLE_BIT
;
1833 if (!validate_array_and_format(ctx
, "glVertexAttribLPointer",
1834 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1835 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1836 1, 4, size
, type
, stride
,
1837 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
, ptr
))
1840 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1841 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1842 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1847 _mesa_enable_vertex_array_attribs(struct gl_context
*ctx
,
1848 struct gl_vertex_array_object
*vao
,
1849 GLbitfield attrib_bits
)
1851 assert((attrib_bits
& ~VERT_BIT_ALL
) == 0);
1852 assert(!vao
->SharedAndImmutable
);
1854 /* Only work on bits that are disabled */
1855 attrib_bits
&= ~vao
->Enabled
;
1857 /* was disabled, now being enabled */
1858 vao
->Enabled
|= attrib_bits
;
1859 vao
->NewArrays
|= attrib_bits
;
1861 /* Update the map mode if needed */
1862 if (attrib_bits
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1863 update_attribute_map_mode(ctx
, vao
);
1868 enable_vertex_array_attrib(struct gl_context
*ctx
,
1869 struct gl_vertex_array_object
*vao
,
1873 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1874 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
1878 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1883 _mesa_EnableVertexAttribArray(GLuint index
)
1885 GET_CURRENT_CONTEXT(ctx
);
1886 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
1887 "glEnableVertexAttribArray");
1892 _mesa_EnableVertexAttribArray_no_error(GLuint index
)
1894 GET_CURRENT_CONTEXT(ctx
);
1895 _mesa_enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1896 VERT_ATTRIB_GENERIC(index
));
1901 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1903 GET_CURRENT_CONTEXT(ctx
);
1904 struct gl_vertex_array_object
*vao
;
1906 /* The ARB_direct_state_access specification says:
1908 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1909 * and DisableVertexArrayAttrib if <vaobj> is not
1910 * [compatibility profile: zero or] the name of an existing vertex
1913 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glEnableVertexArrayAttrib");
1917 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
1921 _mesa_EnableVertexArrayAttribEXT(GLuint vaobj
, GLuint index
)
1923 GET_CURRENT_CONTEXT(ctx
);
1924 struct gl_vertex_array_object
* vao
= _mesa_lookup_vao_err(ctx
, vaobj
,
1926 "glEnableVertexArrayAttribEXT");
1930 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttribEXT");
1935 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1937 GET_CURRENT_CONTEXT(ctx
);
1938 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1939 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1944 _mesa_disable_vertex_array_attribs(struct gl_context
*ctx
,
1945 struct gl_vertex_array_object
*vao
,
1946 GLbitfield attrib_bits
)
1948 assert((attrib_bits
& ~VERT_BIT_ALL
) == 0);
1949 assert(!vao
->SharedAndImmutable
);
1951 /* Only work on bits that are enabled */
1952 attrib_bits
&= vao
->Enabled
;
1954 /* was enabled, now being disabled */
1955 vao
->Enabled
&= ~attrib_bits
;
1956 vao
->NewArrays
|= attrib_bits
;
1958 /* Update the map mode if needed */
1959 if (attrib_bits
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1960 update_attribute_map_mode(ctx
, vao
);
1966 _mesa_DisableVertexAttribArray(GLuint index
)
1968 GET_CURRENT_CONTEXT(ctx
);
1970 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1971 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexAttribArray(index)");
1975 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1976 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
1981 _mesa_DisableVertexAttribArray_no_error(GLuint index
)
1983 GET_CURRENT_CONTEXT(ctx
);
1984 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1985 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
1990 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1992 GET_CURRENT_CONTEXT(ctx
);
1993 struct gl_vertex_array_object
*vao
;
1995 /* The ARB_direct_state_access specification says:
1997 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1998 * and DisableVertexArrayAttrib if <vaobj> is not
1999 * [compatibility profile: zero or] the name of an existing vertex
2002 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glDisableVertexArrayAttrib");
2006 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2007 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
2011 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2012 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
2016 _mesa_DisableVertexArrayAttribEXT(GLuint vaobj
, GLuint index
)
2018 GET_CURRENT_CONTEXT(ctx
);
2019 struct gl_vertex_array_object
* vao
= _mesa_lookup_vao_err(ctx
, vaobj
,
2021 "glEnableVertexArrayAttribEXT");
2025 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2026 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
2030 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2031 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
2036 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
2038 GET_CURRENT_CONTEXT(ctx
);
2039 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2040 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
2041 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
2046 * Return info for a vertex attribute array (no alias with legacy
2047 * vertex attributes (pos, normal, color, etc)). This function does
2048 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
2051 get_vertex_array_attrib(struct gl_context
*ctx
,
2052 const struct gl_vertex_array_object
*vao
,
2053 GLuint index
, GLenum pname
,
2056 const struct gl_array_attributes
*array
;
2058 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2059 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
2063 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
2065 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
2068 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
2069 return !!(vao
->Enabled
& VERT_BIT_GENERIC(index
));
2070 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
2071 return (array
->Format
.Format
== GL_BGRA
) ? GL_BGRA
: array
->Format
.Size
;
2072 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
2073 return array
->Stride
;
2074 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
2075 return array
->Format
.Type
;
2076 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
2077 return array
->Format
.Normalized
;
2078 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
2079 return vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
->Name
;
2080 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
2081 if ((_mesa_is_desktop_gl(ctx
)
2082 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
2083 || _mesa_is_gles3(ctx
)) {
2084 return array
->Format
.Integer
;
2087 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
2088 if (_mesa_is_desktop_gl(ctx
)) {
2089 return array
->Format
.Doubles
;
2092 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
2093 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
2094 || _mesa_is_gles3(ctx
)) {
2095 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
2098 case GL_VERTEX_ATTRIB_BINDING
:
2099 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
2100 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
2103 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
2104 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
2105 return array
->RelativeOffset
;
2109 ; /* fall-through */
2113 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
2118 static const GLfloat
*
2119 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
2122 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
2123 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
2127 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2128 _mesa_error(ctx
, GL_INVALID_VALUE
,
2129 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
2133 assert(VERT_ATTRIB_GENERIC(index
) <
2134 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
2136 FLUSH_CURRENT(ctx
, 0);
2137 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
2141 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
2143 GET_CURRENT_CONTEXT(ctx
);
2145 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2146 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
2152 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2154 "glGetVertexAttribfv");
2160 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
2162 GET_CURRENT_CONTEXT(ctx
);
2164 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2165 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
2167 params
[0] = (GLdouble
) v
[0];
2168 params
[1] = (GLdouble
) v
[1];
2169 params
[2] = (GLdouble
) v
[2];
2170 params
[3] = (GLdouble
) v
[3];
2174 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2176 "glGetVertexAttribdv");
2181 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
2183 GET_CURRENT_CONTEXT(ctx
);
2185 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2187 (const GLdouble
*)get_current_attrib(ctx
, index
,
2188 "glGetVertexAttribLdv");
2197 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2199 "glGetVertexAttribLdv");
2204 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
2206 GET_CURRENT_CONTEXT(ctx
);
2208 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2209 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
2211 /* XXX should floats in[0,1] be scaled to full int range? */
2212 params
[0] = (GLint
) v
[0];
2213 params
[1] = (GLint
) v
[1];
2214 params
[2] = (GLint
) v
[2];
2215 params
[3] = (GLint
) v
[3];
2219 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2221 "glGetVertexAttribiv");
2226 _mesa_GetVertexAttribLui64vARB(GLuint index
, GLenum pname
, GLuint64EXT
*params
)
2228 GET_CURRENT_CONTEXT(ctx
);
2230 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2232 (const GLuint64
*)get_current_attrib(ctx
, index
,
2233 "glGetVertexAttribLui64vARB");
2242 params
[0] = (GLuint64
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2244 "glGetVertexAttribLui64vARB");
2251 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
2253 GET_CURRENT_CONTEXT(ctx
);
2255 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2256 const GLint
*v
= (const GLint
*)
2257 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
2263 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2265 "glGetVertexAttribIiv");
2272 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
2274 GET_CURRENT_CONTEXT(ctx
);
2276 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
2277 const GLuint
*v
= (const GLuint
*)
2278 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
2284 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
2286 "glGetVertexAttribIuiv");
2292 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
2294 GET_CURRENT_CONTEXT(ctx
);
2296 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2297 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
2301 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
2302 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
2306 assert(VERT_ATTRIB_GENERIC(index
) <
2307 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
2309 *pointer
= (GLvoid
*)
2310 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
2314 /** ARB_direct_state_access */
2316 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
2317 GLenum pname
, GLint
*params
)
2319 GET_CURRENT_CONTEXT(ctx
);
2320 struct gl_vertex_array_object
*vao
;
2322 /* The ARB_direct_state_access specification says:
2324 * "An INVALID_OPERATION error is generated if <vaobj> is not
2325 * [compatibility profile: zero or] the name of an existing
2326 * vertex array object."
2328 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glGetVertexArrayIndexediv");
2332 /* The ARB_direct_state_access specification says:
2334 * "For GetVertexArrayIndexediv, <pname> must be one of
2335 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
2336 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
2337 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
2338 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
2339 * VERTEX_ATTRIB_RELATIVE_OFFSET."
2343 * "Add GetVertexArrayIndexediv in 'Get Command' for
2344 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
2345 * VERTEX_ATTRIB_BINDING,
2346 * VERTEX_ATTRIB_RELATIVE_OFFSET,
2347 * VERTEX_BINDING_OFFSET, and
2348 * VERTEX_BINDING_STRIDE states"
2350 * The only parameter name common to both lists is
2351 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
2352 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
2353 * pretty clear however that the intent is that it should be possible
2354 * to query all vertex attrib and binding states that can be set with
2358 case GL_VERTEX_BINDING_OFFSET
:
2359 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2361 case GL_VERTEX_BINDING_STRIDE
:
2362 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
2364 case GL_VERTEX_BINDING_DIVISOR
:
2365 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
2367 case GL_VERTEX_BINDING_BUFFER
:
2368 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
2371 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
2372 "glGetVertexArrayIndexediv");
2379 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
2380 GLenum pname
, GLint64
*params
)
2382 GET_CURRENT_CONTEXT(ctx
);
2383 struct gl_vertex_array_object
*vao
;
2385 /* The ARB_direct_state_access specification says:
2387 * "An INVALID_OPERATION error is generated if <vaobj> is not
2388 * [compatibility profile: zero or] the name of an existing
2389 * vertex array object."
2391 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glGetVertexArrayIndexed64iv");
2395 /* The ARB_direct_state_access specification says:
2397 * "For GetVertexArrayIndexed64iv, <pname> must be
2398 * VERTEX_BINDING_OFFSET."
2402 * "An INVALID_ENUM error is generated if <pname> is not one of
2403 * the valid values listed above for the corresponding command."
2405 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
2406 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
2407 "pname != GL_VERTEX_BINDING_OFFSET)");
2411 /* The ARB_direct_state_access specification says:
2413 * "An INVALID_VALUE error is generated if <index> is greater than
2414 * or equal to the value of MAX_VERTEX_ATTRIBS."
2416 * Since the index refers to a buffer binding in this case, the intended
2417 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
2418 * required to be the same, so in practice this doesn't matter.
2420 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
2421 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
2422 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
2423 index
, ctx
->Const
.MaxVertexAttribBindings
);
2427 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2432 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
2433 GLsizei count
, const GLvoid
*ptr
)
2436 _mesa_VertexPointer(size
, type
, stride
, ptr
);
2441 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
2445 _mesa_NormalPointer(type
, stride
, ptr
);
2450 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
2454 _mesa_ColorPointer(size
, type
, stride
, ptr
);
2459 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
2463 _mesa_IndexPointer(type
, stride
, ptr
);
2468 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
2469 GLsizei count
, const GLvoid
*ptr
)
2472 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
2477 _mesa_MultiTexCoordPointerEXT(GLenum texunit
, GLint size
, GLenum type
,
2478 GLsizei stride
, const GLvoid
*ptr
)
2480 GET_CURRENT_CONTEXT(ctx
);
2481 const GLint sizeMin
= 1;
2482 const GLuint unit
= texunit
- GL_TEXTURE0
;
2484 GLenum format
= GL_RGBA
;
2485 const GLbitfield legalTypes
= (SHORT_BIT
| INT_BIT
|
2486 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
2487 UNSIGNED_INT_2_10_10_10_REV_BIT
|
2488 INT_2_10_10_10_REV_BIT
);
2490 if (!validate_array_and_format(ctx
, "glMultiTexCoordPointerEXT",
2491 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
2492 VERT_ATTRIB_TEX(unit
), legalTypes
,
2493 sizeMin
, 4, size
, type
, stride
,
2494 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
2497 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
2498 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
2499 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
2504 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
2507 _mesa_EdgeFlagPointer(stride
, ptr
);
2512 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
2514 GET_CURRENT_CONTEXT(ctx
);
2515 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
2516 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
2517 GLenum ctype
= 0; /* color type */
2518 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
2519 const GLint toffset
= 0; /* always zero */
2520 GLint defstride
; /* default stride */
2523 f
= sizeof(GLfloat
);
2524 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
2527 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
2533 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2534 tcomps
= 0; ccomps
= 0; vcomps
= 2;
2539 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2540 tcomps
= 0; ccomps
= 0; vcomps
= 3;
2545 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2546 tcomps
= 0; ccomps
= 4; vcomps
= 2;
2547 ctype
= GL_UNSIGNED_BYTE
;
2550 defstride
= c
+ 2*f
;
2553 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2554 tcomps
= 0; ccomps
= 4; vcomps
= 3;
2555 ctype
= GL_UNSIGNED_BYTE
;
2558 defstride
= c
+ 3*f
;
2561 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2562 tcomps
= 0; ccomps
= 3; vcomps
= 3;
2569 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
2570 tcomps
= 0; ccomps
= 0; vcomps
= 3;
2575 case GL_C4F_N3F_V3F
:
2576 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2577 tcomps
= 0; ccomps
= 4; vcomps
= 3;
2585 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2586 tcomps
= 2; ccomps
= 0; vcomps
= 3;
2591 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
2592 tcomps
= 4; ccomps
= 0; vcomps
= 4;
2596 case GL_T2F_C4UB_V3F
:
2597 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2598 tcomps
= 2; ccomps
= 4; vcomps
= 3;
2599 ctype
= GL_UNSIGNED_BYTE
;
2604 case GL_T2F_C3F_V3F
:
2605 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
2606 tcomps
= 2; ccomps
= 3; vcomps
= 3;
2612 case GL_T2F_N3F_V3F
:
2613 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
2614 tcomps
= 2; ccomps
= 0; vcomps
= 3;
2619 case GL_T2F_C4F_N3F_V3F
:
2620 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2621 tcomps
= 2; ccomps
= 4; vcomps
= 3;
2628 case GL_T4F_C4F_N3F_V4F
:
2629 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
2630 tcomps
= 4; ccomps
= 4; vcomps
= 4;
2638 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
2646 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
2647 _mesa_DisableClientState( GL_INDEX_ARRAY
);
2648 /* XXX also disable secondary color and generic arrays? */
2652 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
2653 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
2654 (GLubyte
*) pointer
+ toffset
);
2657 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
2662 _mesa_EnableClientState( GL_COLOR_ARRAY
);
2663 _mesa_ColorPointer( ccomps
, ctype
, stride
,
2664 (GLubyte
*) pointer
+ coffset
);
2667 _mesa_DisableClientState( GL_COLOR_ARRAY
);
2673 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
2674 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
2677 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
2681 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
2682 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
2683 (GLubyte
*) pointer
+ voffset
);
2688 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
2690 GET_CURRENT_CONTEXT(ctx
);
2692 if (MESA_VERBOSE
& VERBOSE_API
)
2693 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
2696 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
2700 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
2703 if (ctx
->Array
.LockCount
!= 0) {
2704 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
2708 ctx
->Array
.LockFirst
= first
;
2709 ctx
->Array
.LockCount
= count
;
2714 _mesa_UnlockArraysEXT( void )
2716 GET_CURRENT_CONTEXT(ctx
);
2718 if (MESA_VERBOSE
& VERBOSE_API
)
2719 _mesa_debug(ctx
, "glUnlockArrays\n");
2721 if (ctx
->Array
.LockCount
== 0) {
2722 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
2726 ctx
->Array
.LockFirst
= 0;
2727 ctx
->Array
.LockCount
= 0;
2732 primitive_restart_index(struct gl_context
*ctx
, GLuint index
)
2734 ctx
->Array
.RestartIndex
= index
;
2739 * GL_NV_primitive_restart and GL 3.1
2742 _mesa_PrimitiveRestartIndex_no_error(GLuint index
)
2744 GET_CURRENT_CONTEXT(ctx
);
2745 primitive_restart_index(ctx
, index
);
2750 _mesa_PrimitiveRestartIndex(GLuint index
)
2752 GET_CURRENT_CONTEXT(ctx
);
2754 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
2755 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
2759 primitive_restart_index(ctx
, index
);
2764 _mesa_VertexAttribDivisor_no_error(GLuint index
, GLuint divisor
)
2766 GET_CURRENT_CONTEXT(ctx
);
2768 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2769 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2771 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2773 /* The ARB_vertex_attrib_binding spec says:
2777 * void VertexAttribDivisor(uint index, uint divisor);
2779 * is equivalent to (assuming no errors are generated):
2781 * VertexAttribBinding(index, index);
2782 * VertexBindingDivisor(index, divisor);"
2784 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2785 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2790 * See GL_ARB_instanced_arrays.
2791 * Note that the instance divisor only applies to generic arrays, not
2792 * the legacy vertex arrays.
2795 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
2797 GET_CURRENT_CONTEXT(ctx
);
2799 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2800 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2802 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2803 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
2807 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2808 _mesa_error(ctx
, GL_INVALID_VALUE
,
2809 "glVertexAttribDivisor(index = %u)", index
);
2813 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2815 /* The ARB_vertex_attrib_binding spec says:
2819 * void VertexAttribDivisor(uint index, uint divisor);
2821 * is equivalent to (assuming no errors are generated):
2823 * VertexAttribBinding(index, index);
2824 * VertexBindingDivisor(index, divisor);"
2826 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2827 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2832 _mesa_VertexArrayVertexAttribDivisorEXT(GLuint vaobj
, GLuint index
, GLuint divisor
)
2834 GET_CURRENT_CONTEXT(ctx
);
2836 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2837 struct gl_vertex_array_object
* vao
;
2838 /* The ARB_instanced_arrays spec says:
2840 * "The vertex array object named by vaobj must
2841 * be generated by GenVertexArrays (and not since deleted);
2842 * otherwise an INVALID_OPERATION error is generated."
2844 vao
= _mesa_lookup_vao_err(ctx
, vaobj
,
2846 "glVertexArrayVertexAttribDivisorEXT");
2850 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2851 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexArrayVertexAttribDivisorEXT()");
2855 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2856 _mesa_error(ctx
, GL_INVALID_VALUE
,
2857 "glVertexArrayVertexAttribDivisorEXT(index = %u)", index
);
2861 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2863 /* The ARB_vertex_attrib_binding spec says:
2867 * void VertexAttribDivisor(uint index, uint divisor);
2869 * is equivalent to (assuming no errors are generated):
2871 * VertexAttribBinding(index, index);
2872 * VertexBindingDivisor(index, divisor);"
2874 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2875 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2880 static ALWAYS_INLINE
void
2881 vertex_array_vertex_buffer(struct gl_context
*ctx
,
2882 struct gl_vertex_array_object
*vao
,
2883 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2884 GLsizei stride
, bool no_error
, const char *func
)
2886 struct gl_buffer_object
*vbo
;
2888 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
2889 vbo
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
2890 } else if (buffer
!= 0) {
2891 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
2893 if (!no_error
&& !vbo
&& _mesa_is_gles31(ctx
)) {
2894 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
2897 /* From the GL_ARB_vertex_attrib_array spec:
2899 * "[Core profile only:]
2900 * An INVALID_OPERATION error is generated if buffer is not zero or a
2901 * name returned from a previous call to GenBuffers, or if such a name
2902 * has since been deleted with DeleteBuffers.
2904 * Otherwise, we fall back to the same compat profile behavior as other
2905 * object references (automatically gen it).
2907 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
2910 /* The ARB_vertex_attrib_binding spec says:
2912 * "If <buffer> is zero, any buffer object attached to this
2913 * bindpoint is detached."
2915 vbo
= ctx
->Shared
->NullBufferObj
;
2918 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
2919 vbo
, offset
, stride
);
2924 * GL_ARB_vertex_attrib_binding
2927 vertex_array_vertex_buffer_err(struct gl_context
*ctx
,
2928 struct gl_vertex_array_object
*vao
,
2929 GLuint bindingIndex
, GLuint buffer
,
2930 GLintptr offset
, GLsizei stride
,
2933 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2935 /* The ARB_vertex_attrib_binding spec says:
2937 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2938 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2940 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2941 _mesa_error(ctx
, GL_INVALID_VALUE
,
2942 "%s(bindingindex=%u > "
2943 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2944 func
, bindingIndex
);
2948 /* The ARB_vertex_attrib_binding spec says:
2950 * "The error INVALID_VALUE is generated if <stride> or <offset>
2954 _mesa_error(ctx
, GL_INVALID_VALUE
,
2955 "%s(offset=%" PRId64
" < 0)",
2956 func
, (int64_t) offset
);
2961 _mesa_error(ctx
, GL_INVALID_VALUE
,
2962 "%s(stride=%d < 0)", func
, stride
);
2966 if (((_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
2967 stride
> ctx
->Const
.MaxVertexAttribStride
) {
2968 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
2969 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
2973 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2974 stride
, false, func
);
2979 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex
, GLuint buffer
,
2980 GLintptr offset
, GLsizei stride
)
2982 GET_CURRENT_CONTEXT(ctx
);
2983 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2984 buffer
, offset
, stride
, true,
2985 "glBindVertexBuffer");
2990 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2993 GET_CURRENT_CONTEXT(ctx
);
2995 /* The ARB_vertex_attrib_binding spec says:
2997 * "An INVALID_OPERATION error is generated if no vertex array object
3000 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3001 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3002 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3003 "glBindVertexBuffer(No array object bound)");
3007 vertex_array_vertex_buffer_err(ctx
, ctx
->Array
.VAO
, bindingIndex
,
3008 buffer
, offset
, stride
,
3009 "glBindVertexBuffer");
3014 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj
, GLuint bindingIndex
,
3015 GLuint buffer
, GLintptr offset
,
3018 GET_CURRENT_CONTEXT(ctx
);
3020 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3021 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
3022 stride
, true, "glVertexArrayVertexBuffer");
3027 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
3028 GLintptr offset
, GLsizei stride
)
3030 GET_CURRENT_CONTEXT(ctx
);
3031 struct gl_vertex_array_object
*vao
;
3033 /* The ARB_direct_state_access specification says:
3035 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
3036 * if <vaobj> is not [compatibility profile: zero or] the name of an
3037 * existing vertex array object."
3039 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayVertexBuffer");
3043 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
3044 stride
, "glVertexArrayVertexBuffer");
3049 _mesa_VertexArrayBindVertexBufferEXT(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
3050 GLintptr offset
, GLsizei stride
)
3052 GET_CURRENT_CONTEXT(ctx
);
3053 struct gl_vertex_array_object
*vao
;
3054 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, "glVertexArrayBindVertexBufferEXT");
3058 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
3059 stride
, "glVertexArrayBindVertexBufferEXT");
3063 static ALWAYS_INLINE
void
3064 vertex_array_vertex_buffers(struct gl_context
*ctx
,
3065 struct gl_vertex_array_object
*vao
,
3066 GLuint first
, GLsizei count
, const GLuint
*buffers
,
3067 const GLintptr
*offsets
, const GLsizei
*strides
,
3068 bool no_error
, const char *func
)
3074 * The ARB_multi_bind spec says:
3076 * "If <buffers> is NULL, each affected vertex buffer binding point
3077 * from <first> through <first>+<count>-1 will be reset to have no
3078 * bound buffer object. In this case, the offsets and strides
3079 * associated with the binding points are set to default values,
3080 * ignoring <offsets> and <strides>."
3082 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
3084 for (i
= 0; i
< count
; i
++)
3085 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
3091 /* Note that the error semantics for multi-bind commands differ from
3092 * those of other GL commands.
3094 * The Issues section in the ARB_multi_bind spec says:
3096 * "(11) Typically, OpenGL specifies that if an error is generated by
3097 * a command, that command has no effect. This is somewhat
3098 * unfortunate for multi-bind commands, because it would require
3099 * a first pass to scan the entire list of bound objects for
3100 * errors and then a second pass to actually perform the
3101 * bindings. Should we have different error semantics?
3103 * RESOLVED: Yes. In this specification, when the parameters for
3104 * one of the <count> binding points are invalid, that binding
3105 * point is not updated and an error will be generated. However,
3106 * other binding points in the same command will be updated if
3107 * their parameters are valid and no other error occurs."
3110 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
3112 for (i
= 0; i
< count
; i
++) {
3113 struct gl_buffer_object
*vbo
;
3116 /* The ARB_multi_bind spec says:
3118 * "An INVALID_VALUE error is generated if any value in
3119 * <offsets> or <strides> is negative (per binding)."
3121 if (offsets
[i
] < 0) {
3122 _mesa_error(ctx
, GL_INVALID_VALUE
,
3123 "%s(offsets[%u]=%" PRId64
" < 0)",
3124 func
, i
, (int64_t) offsets
[i
]);
3128 if (strides
[i
] < 0) {
3129 _mesa_error(ctx
, GL_INVALID_VALUE
,
3130 "%s(strides[%u]=%d < 0)",
3131 func
, i
, strides
[i
]);
3135 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
3136 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
3137 _mesa_error(ctx
, GL_INVALID_VALUE
,
3138 "%s(strides[%u]=%d > "
3139 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
3145 struct gl_vertex_buffer_binding
*binding
=
3146 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
3148 if (buffers
[i
] == binding
->BufferObj
->Name
)
3149 vbo
= binding
->BufferObj
;
3151 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
3156 vbo
= ctx
->Shared
->NullBufferObj
;
3159 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
3160 vbo
, offsets
[i
], strides
[i
]);
3163 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
3168 vertex_array_vertex_buffers_err(struct gl_context
*ctx
,
3169 struct gl_vertex_array_object
*vao
,
3170 GLuint first
, GLsizei count
,
3171 const GLuint
*buffers
, const GLintptr
*offsets
,
3172 const GLsizei
*strides
, const char *func
)
3174 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3176 /* The ARB_multi_bind spec says:
3178 * "An INVALID_OPERATION error is generated if <first> + <count>
3179 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
3181 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
3182 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3183 "%s(first=%u + count=%d > the value of "
3184 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
3185 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
3189 vertex_array_vertex_buffers(ctx
, vao
, first
, count
, buffers
, offsets
,
3190 strides
, false, func
);
3195 _mesa_BindVertexBuffers_no_error(GLuint first
, GLsizei count
,
3196 const GLuint
*buffers
, const GLintptr
*offsets
,
3197 const GLsizei
*strides
)
3199 GET_CURRENT_CONTEXT(ctx
);
3201 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
3202 buffers
, offsets
, strides
, true,
3203 "glBindVertexBuffers");
3208 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
3209 const GLintptr
*offsets
, const GLsizei
*strides
)
3211 GET_CURRENT_CONTEXT(ctx
);
3213 /* The ARB_vertex_attrib_binding spec says:
3215 * "An INVALID_OPERATION error is generated if no
3216 * vertex array object is bound."
3218 if (ctx
->API
== API_OPENGL_CORE
&&
3219 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3220 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3221 "glBindVertexBuffers(No array object bound)");
3225 vertex_array_vertex_buffers_err(ctx
, ctx
->Array
.VAO
, first
, count
,
3226 buffers
, offsets
, strides
,
3227 "glBindVertexBuffers");
3232 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj
, GLuint first
,
3233 GLsizei count
, const GLuint
*buffers
,
3234 const GLintptr
*offsets
,
3235 const GLsizei
*strides
)
3237 GET_CURRENT_CONTEXT(ctx
);
3239 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3240 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
3241 buffers
, offsets
, strides
, true,
3242 "glVertexArrayVertexBuffers");
3247 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
3248 const GLuint
*buffers
,
3249 const GLintptr
*offsets
, const GLsizei
*strides
)
3251 GET_CURRENT_CONTEXT(ctx
);
3252 struct gl_vertex_array_object
*vao
;
3254 /* The ARB_direct_state_access specification says:
3256 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
3257 * if <vaobj> is not [compatibility profile: zero or] the name of an
3258 * existing vertex array object."
3260 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayVertexBuffers");
3264 vertex_array_vertex_buffers_err(ctx
, vao
, first
, count
,
3265 buffers
, offsets
, strides
,
3266 "glVertexArrayVertexBuffers");
3271 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
3272 GLboolean normalized
, GLboolean integer
,
3273 GLboolean doubles
, GLbitfield legalTypes
,
3274 GLsizei sizeMax
, GLuint relativeOffset
,
3277 GET_CURRENT_CONTEXT(ctx
);
3278 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3280 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
3282 if (!_mesa_is_no_error_enabled(ctx
)) {
3283 /* The ARB_vertex_attrib_binding spec says:
3285 * "An INVALID_OPERATION error is generated under any of the
3286 * following conditions:
3287 * - if no vertex array object is currently bound (see section
3291 * This error condition only applies to VertexAttribFormat and
3292 * VertexAttribIFormat in the extension spec, but we assume that this
3293 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
3294 * to all three functions.
3296 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3297 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3298 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3299 "%s(No array object bound)", func
);
3303 /* The ARB_vertex_attrib_binding spec says:
3305 * "The error INVALID_VALUE is generated if index is greater than or
3306 * equal to the value of MAX_VERTEX_ATTRIBS."
3308 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
3309 _mesa_error(ctx
, GL_INVALID_VALUE
,
3310 "%s(attribindex=%u > "
3311 "GL_MAX_VERTEX_ATTRIBS)",
3316 if (!validate_array_format(ctx
, func
, ctx
->Array
.VAO
,
3317 VERT_ATTRIB_GENERIC(attribIndex
),
3318 legalTypes
, 1, sizeMax
, size
, type
,
3319 normalized
, integer
, doubles
, relativeOffset
,
3325 _mesa_update_array_format(ctx
, ctx
->Array
.VAO
,
3326 VERT_ATTRIB_GENERIC(attribIndex
), size
, type
,
3327 format
, normalized
, integer
, doubles
,
3333 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3334 GLboolean normalized
, GLuint relativeOffset
)
3336 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
3337 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
3338 BGRA_OR_4
, relativeOffset
,
3339 "glVertexAttribFormat");
3344 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3345 GLuint relativeOffset
)
3347 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
3348 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
3349 relativeOffset
, "glVertexAttribIFormat");
3354 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
3355 GLuint relativeOffset
)
3357 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
3358 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
3359 relativeOffset
, "glVertexAttribLFormat");
3364 vertex_array_attrib_format(GLuint vaobj
, bool isExtDsa
, GLuint attribIndex
,
3365 GLint size
, GLenum type
, GLboolean normalized
,
3366 GLboolean integer
, GLboolean doubles
,
3367 GLbitfield legalTypes
, GLsizei sizeMax
,
3368 GLuint relativeOffset
, const char *func
)
3370 GET_CURRENT_CONTEXT(ctx
);
3371 struct gl_vertex_array_object
*vao
;
3373 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3375 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
3377 if (_mesa_is_no_error_enabled(ctx
)) {
3378 vao
= _mesa_lookup_vao(ctx
, vaobj
);
3382 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, isExtDsa
, func
);
3386 /* The ARB_vertex_attrib_binding spec says:
3388 * "The error INVALID_VALUE is generated if index is greater than or
3389 * equal to the value of MAX_VERTEX_ATTRIBS."
3391 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
3392 _mesa_error(ctx
, GL_INVALID_VALUE
,
3393 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
3398 if (!validate_array_format(ctx
, func
, vao
,
3399 VERT_ATTRIB_GENERIC(attribIndex
),
3400 legalTypes
, 1, sizeMax
, size
, type
,
3401 normalized
, integer
, doubles
, relativeOffset
,
3407 _mesa_update_array_format(ctx
, vao
, VERT_ATTRIB_GENERIC(attribIndex
), size
,
3408 type
, format
, normalized
, integer
, doubles
,
3414 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
3415 GLenum type
, GLboolean normalized
,
3416 GLuint relativeOffset
)
3418 vertex_array_attrib_format(vaobj
, false, attribIndex
, size
, type
, normalized
,
3419 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
3420 BGRA_OR_4
, relativeOffset
,
3421 "glVertexArrayAttribFormat");
3426 _mesa_VertexArrayVertexAttribFormatEXT(GLuint vaobj
, GLuint attribIndex
, GLint size
,
3427 GLenum type
, GLboolean normalized
,
3428 GLuint relativeOffset
)
3430 vertex_array_attrib_format(vaobj
, true, attribIndex
, size
, type
, normalized
,
3431 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
3432 BGRA_OR_4
, relativeOffset
,
3433 "glVertexArrayVertexAttribFormatEXT");
3438 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
3439 GLint size
, GLenum type
,
3440 GLuint relativeOffset
)
3442 vertex_array_attrib_format(vaobj
, false, attribIndex
, size
, type
, GL_FALSE
,
3443 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
3445 "glVertexArrayAttribIFormat");
3450 _mesa_VertexArrayVertexAttribIFormatEXT(GLuint vaobj
, GLuint attribIndex
,
3451 GLint size
, GLenum type
,
3452 GLuint relativeOffset
)
3454 vertex_array_attrib_format(vaobj
, true, attribIndex
, size
, type
, GL_FALSE
,
3455 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
3457 "glVertexArrayVertexAttribIFormatEXT");
3462 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
3463 GLint size
, GLenum type
,
3464 GLuint relativeOffset
)
3466 vertex_array_attrib_format(vaobj
, false, attribIndex
, size
, type
, GL_FALSE
,
3467 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
3469 "glVertexArrayAttribLFormat");
3474 _mesa_VertexArrayVertexAttribLFormatEXT(GLuint vaobj
, GLuint attribIndex
,
3475 GLint size
, GLenum type
,
3476 GLuint relativeOffset
)
3478 vertex_array_attrib_format(vaobj
, true, attribIndex
, size
, type
, GL_FALSE
,
3479 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
3481 "glVertexArrayVertexAttribLFormatEXT");
3486 vertex_array_attrib_binding(struct gl_context
*ctx
,
3487 struct gl_vertex_array_object
*vao
,
3488 GLuint attribIndex
, GLuint bindingIndex
,
3491 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3493 /* The ARB_vertex_attrib_binding spec says:
3495 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
3496 * <bindingindex> must be less than the value of
3497 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
3500 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
3501 _mesa_error(ctx
, GL_INVALID_VALUE
,
3502 "%s(attribindex=%u >= "
3503 "GL_MAX_VERTEX_ATTRIBS)",
3508 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
3509 _mesa_error(ctx
, GL_INVALID_VALUE
,
3510 "%s(bindingindex=%u >= "
3511 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
3512 func
, bindingIndex
);
3516 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
3518 _mesa_vertex_attrib_binding(ctx
, vao
,
3519 VERT_ATTRIB_GENERIC(attribIndex
),
3520 VERT_ATTRIB_GENERIC(bindingIndex
));
3525 _mesa_VertexAttribBinding_no_error(GLuint attribIndex
, GLuint bindingIndex
)
3527 GET_CURRENT_CONTEXT(ctx
);
3528 _mesa_vertex_attrib_binding(ctx
, ctx
->Array
.VAO
,
3529 VERT_ATTRIB_GENERIC(attribIndex
),
3530 VERT_ATTRIB_GENERIC(bindingIndex
));
3535 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
3537 GET_CURRENT_CONTEXT(ctx
);
3539 /* The ARB_vertex_attrib_binding spec says:
3541 * "An INVALID_OPERATION error is generated if no vertex array object
3544 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3545 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3546 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3547 "glVertexAttribBinding(No array object bound)");
3551 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
3552 attribIndex
, bindingIndex
,
3553 "glVertexAttribBinding");
3558 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj
, GLuint attribIndex
,
3559 GLuint bindingIndex
)
3561 GET_CURRENT_CONTEXT(ctx
);
3563 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3564 _mesa_vertex_attrib_binding(ctx
, vao
,
3565 VERT_ATTRIB_GENERIC(attribIndex
),
3566 VERT_ATTRIB_GENERIC(bindingIndex
));
3571 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
3573 GET_CURRENT_CONTEXT(ctx
);
3574 struct gl_vertex_array_object
*vao
;
3576 /* The ARB_direct_state_access specification says:
3578 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
3579 * if <vaobj> is not [compatibility profile: zero or] the name of an
3580 * existing vertex array object."
3582 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayAttribBinding");
3586 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
3587 "glVertexArrayAttribBinding");
3592 _mesa_VertexArrayVertexAttribBindingEXT(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
3594 GET_CURRENT_CONTEXT(ctx
);
3595 struct gl_vertex_array_object
*vao
;
3596 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, "glVertexArrayVertexAttribBindingEXT");
3600 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
3601 "glVertexArrayVertexAttribBindingEXT");
3606 vertex_array_binding_divisor(struct gl_context
*ctx
,
3607 struct gl_vertex_array_object
*vao
,
3608 GLuint bindingIndex
, GLuint divisor
,
3611 ASSERT_OUTSIDE_BEGIN_END(ctx
);
3613 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
3614 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
3618 /* The ARB_vertex_attrib_binding spec says:
3620 * "An INVALID_VALUE error is generated if <bindingindex> is greater
3621 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
3623 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
3624 _mesa_error(ctx
, GL_INVALID_VALUE
,
3625 "%s(bindingindex=%u > "
3626 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
3627 func
, bindingIndex
);
3631 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3636 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex
, GLuint divisor
)
3638 GET_CURRENT_CONTEXT(ctx
);
3639 vertex_binding_divisor(ctx
, ctx
->Array
.VAO
,
3640 VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3645 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
3647 GET_CURRENT_CONTEXT(ctx
);
3649 /* The ARB_vertex_attrib_binding spec says:
3651 * "An INVALID_OPERATION error is generated if no vertex array object
3654 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
3655 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
3656 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3657 "glVertexBindingDivisor(No array object bound)");
3661 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
3662 bindingIndex
, divisor
,
3663 "glVertexBindingDivisor");
3668 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj
, GLuint bindingIndex
,
3671 GET_CURRENT_CONTEXT(ctx
);
3673 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
3674 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
3679 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
3682 struct gl_vertex_array_object
*vao
;
3683 GET_CURRENT_CONTEXT(ctx
);
3685 /* The ARB_direct_state_access specification says:
3687 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
3688 * if <vaobj> is not [compatibility profile: zero or] the name of an
3689 * existing vertex array object."
3691 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, false, "glVertexArrayBindingDivisor");
3695 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
3696 "glVertexArrayBindingDivisor");
3701 _mesa_VertexArrayVertexBindingDivisorEXT(GLuint vaobj
, GLuint bindingIndex
,
3704 struct gl_vertex_array_object
*vao
;
3705 GET_CURRENT_CONTEXT(ctx
);
3707 /* The ARB_direct_state_access specification says:
3709 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
3710 * if <vaobj> is not [compatibility profile: zero or] the name of an
3711 * existing vertex array object."
3713 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true, "glVertexArrayVertexBindingDivisorEXT");
3717 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
3718 "glVertexArrayVertexBindingDivisorEXT");
3723 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
3724 struct gl_array_attributes
*dst
,
3725 const struct gl_array_attributes
*src
)
3727 dst
->Ptr
= src
->Ptr
;
3728 dst
->RelativeOffset
= src
->RelativeOffset
;
3729 dst
->Format
= src
->Format
;
3730 dst
->Stride
= src
->Stride
;
3731 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
3732 dst
->_EffBufferBindingIndex
= src
->_EffBufferBindingIndex
;
3733 dst
->_EffRelativeOffset
= src
->_EffRelativeOffset
;
3737 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
3738 struct gl_vertex_buffer_binding
*dst
,
3739 const struct gl_vertex_buffer_binding
*src
)
3741 dst
->Offset
= src
->Offset
;
3742 dst
->Stride
= src
->Stride
;
3743 dst
->InstanceDivisor
= src
->InstanceDivisor
;
3744 dst
->_BoundArrays
= src
->_BoundArrays
;
3745 dst
->_EffBoundArrays
= src
->_EffBoundArrays
;
3746 dst
->_EffOffset
= src
->_EffOffset
;
3748 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
3752 * Print current vertex object/array info. For debug.
3755 _mesa_print_arrays(struct gl_context
*ctx
)
3757 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
3759 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
3761 GLbitfield mask
= vao
->Enabled
;
3763 const gl_vert_attrib i
= u_bit_scan(&mask
);
3764 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
3766 const struct gl_vertex_buffer_binding
*binding
=
3767 &vao
->BufferBinding
[array
->BufferBindingIndex
];
3768 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
3770 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
3771 "Stride=%d, Buffer=%u(Size %lu)\n",
3772 gl_vert_attrib_name((gl_vert_attrib
)i
),
3773 array
->Ptr
, _mesa_enum_to_string(array
->Format
.Type
),
3775 array
->Format
._ElementSize
, binding
->Stride
, bo
->Name
,
3776 (unsigned long) bo
->Size
);
3782 * Initialize vertex array state for given context.
3785 _mesa_init_varray(struct gl_context
*ctx
)
3787 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
3788 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
3789 ctx
->Array
._EmptyVAO
= _mesa_new_vao(ctx
, ~0u);
3790 _mesa_reference_vao(ctx
, &ctx
->Array
._DrawVAO
, ctx
->Array
._EmptyVAO
);
3791 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
3793 ctx
->Array
.Objects
= _mesa_NewHashTable();
3798 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
3801 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
3803 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
3804 struct gl_context
*ctx
= (struct gl_context
*) userData
;
3805 _mesa_delete_vao(ctx
, vao
);
3810 * Free vertex array state for given context.
3813 _mesa_free_varray_data(struct gl_context
*ctx
)
3815 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
3816 _mesa_DeleteHashTable(ctx
->Array
.Objects
);
3820 _mesa_GetVertexArrayIntegervEXT(GLuint vaobj
, GLenum pname
, GLint
*param
)
3822 GET_CURRENT_CONTEXT(ctx
);
3823 struct gl_vertex_array_object
* vao
;
3826 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
3827 "glGetVertexArrayIntegervEXT");
3831 /* The EXT_direct_state_access spec says:
3833 * "For GetVertexArrayIntegervEXT, pname must be one of the "Get value" tokens
3834 * in tables 6.6, 6.7, 6.8, and 6.9 that use GetIntegerv, IsEnabled, or
3835 * GetPointerv for their "Get command" (so excluding the VERTEX_ATTRIB_*
3839 /* Tokens using GetIntegerv */
3840 case GL_CLIENT_ACTIVE_TEXTURE
:
3841 *param
= GL_TEXTURE0_ARB
+ ctx
->Array
.ActiveTexture
;
3843 case GL_VERTEX_ARRAY_SIZE
:
3844 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Format
.Size
;
3846 case GL_VERTEX_ARRAY_TYPE
:
3847 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Format
.Type
;
3849 case GL_VERTEX_ARRAY_STRIDE
:
3850 *param
= vao
->VertexAttrib
[VERT_ATTRIB_POS
].Stride
;
3852 case GL_VERTEX_ARRAY_BUFFER_BINDING
:
3853 *param
= vao
->BufferBinding
[VERT_ATTRIB_POS
].BufferObj
->Name
;
3855 case GL_COLOR_ARRAY_SIZE
:
3856 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Format
.Size
;
3858 case GL_COLOR_ARRAY_TYPE
:
3859 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Format
.Type
;
3861 case GL_COLOR_ARRAY_STRIDE
:
3862 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR0
].Stride
;
3864 case GL_COLOR_ARRAY_BUFFER_BINDING
:
3865 *param
= vao
->BufferBinding
[VERT_ATTRIB_COLOR0
].BufferObj
->Name
;
3867 case GL_EDGE_FLAG_ARRAY_STRIDE
:
3868 *param
= vao
->VertexAttrib
[VERT_ATTRIB_EDGEFLAG
].Stride
;
3870 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING
:
3871 *param
= vao
->BufferBinding
[VERT_ATTRIB_EDGEFLAG
].BufferObj
->Name
;
3873 case GL_INDEX_ARRAY_TYPE
:
3874 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Format
.Type
;
3876 case GL_INDEX_ARRAY_STRIDE
:
3877 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR_INDEX
].Stride
;
3879 case GL_INDEX_ARRAY_BUFFER_BINDING
:
3880 *param
= vao
->BufferBinding
[VERT_ATTRIB_COLOR_INDEX
].BufferObj
->Name
;
3882 case GL_NORMAL_ARRAY_TYPE
:
3883 *param
= vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Format
.Type
;
3885 case GL_NORMAL_ARRAY_STRIDE
:
3886 *param
= vao
->VertexAttrib
[VERT_ATTRIB_NORMAL
].Stride
;
3888 case GL_NORMAL_ARRAY_BUFFER_BINDING
:
3889 *param
= vao
->BufferBinding
[VERT_ATTRIB_NORMAL
].BufferObj
->Name
;
3891 case GL_TEXTURE_COORD_ARRAY_SIZE
:
3892 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Format
.Size
;
3894 case GL_TEXTURE_COORD_ARRAY_TYPE
:
3895 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Format
.Type
;
3897 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
3898 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].Stride
;
3900 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING
:
3901 *param
= vao
->BufferBinding
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].BufferObj
->Name
;
3903 case GL_FOG_COORD_ARRAY_TYPE
:
3904 *param
= vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Format
.Type
;
3906 case GL_FOG_COORD_ARRAY_STRIDE
:
3907 *param
= vao
->VertexAttrib
[VERT_ATTRIB_FOG
].Stride
;
3909 case GL_FOG_COORD_ARRAY_BUFFER_BINDING
:
3910 *param
= vao
->BufferBinding
[VERT_ATTRIB_FOG
].BufferObj
->Name
;
3912 case GL_SECONDARY_COLOR_ARRAY_SIZE
:
3913 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Format
.Size
;
3915 case GL_SECONDARY_COLOR_ARRAY_TYPE
:
3916 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Format
.Type
;
3918 case GL_SECONDARY_COLOR_ARRAY_STRIDE
:
3919 *param
= vao
->VertexAttrib
[VERT_ATTRIB_COLOR1
].Stride
;
3921 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING
:
3922 *param
= vao
->BufferBinding
[VERT_ATTRIB_COLOR1
].BufferObj
->Name
;
3925 /* Tokens using IsEnabled */
3926 case GL_VERTEX_ARRAY
:
3927 *param
= !!(vao
->Enabled
& VERT_BIT_POS
);
3929 case GL_COLOR_ARRAY
:
3930 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR0
);
3932 case GL_EDGE_FLAG_ARRAY
:
3933 *param
= !!(vao
->Enabled
& VERT_BIT_EDGEFLAG
);
3935 case GL_INDEX_ARRAY
:
3936 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR_INDEX
);
3938 case GL_NORMAL_ARRAY
:
3939 *param
= !!(vao
->Enabled
& VERT_BIT_NORMAL
);
3941 case GL_TEXTURE_COORD_ARRAY
:
3942 *param
= !!(vao
->Enabled
& VERT_BIT_TEX(ctx
->Array
.ActiveTexture
));
3944 case GL_FOG_COORD_ARRAY
:
3945 *param
= !!(vao
->Enabled
& VERT_BIT_FOG
);
3947 case GL_SECONDARY_COLOR_ARRAY
:
3948 *param
= !!(vao
->Enabled
& VERT_BIT_COLOR1
);
3951 /* Tokens using GetPointerv */
3952 case GL_VERTEX_ARRAY_POINTER
:
3953 case GL_COLOR_ARRAY_POINTER
:
3954 case GL_EDGE_FLAG_ARRAY_POINTER
:
3955 case GL_INDEX_ARRAY_POINTER
:
3956 case GL_NORMAL_ARRAY_POINTER
:
3957 case GL_TEXTURE_COORD_ARRAY_POINTER
:
3958 case GL_FOG_COORD_ARRAY_POINTER
:
3959 case GL_SECONDARY_COLOR_ARRAY_POINTER
:
3960 _get_vao_pointerv(pname
, vao
, &ptr
, "glGetVertexArrayIntegervEXT");
3961 *param
= (int) ((intptr_t) ptr
& 0xFFFFFFFF);
3965 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIntegervEXT(pname)");
3970 _mesa_GetVertexArrayPointervEXT(GLuint vaobj
, GLenum pname
, GLvoid
** param
)
3972 GET_CURRENT_CONTEXT(ctx
);
3973 struct gl_vertex_array_object
* vao
;
3975 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
3976 "glGetVertexArrayPointervEXT");
3980 /* The EXT_direct_state_access spec says:
3982 * "For GetVertexArrayPointervEXT, pname must be a *_ARRAY_POINTER token from
3983 * tables 6.6, 6.7, and 6.8 excluding VERTEX_ATTRIB_ARRAY_POINT."
3986 case GL_VERTEX_ARRAY_POINTER
:
3987 case GL_COLOR_ARRAY_POINTER
:
3988 case GL_EDGE_FLAG_ARRAY_POINTER
:
3989 case GL_INDEX_ARRAY_POINTER
:
3990 case GL_NORMAL_ARRAY_POINTER
:
3991 case GL_TEXTURE_COORD_ARRAY_POINTER
:
3992 case GL_FOG_COORD_ARRAY_POINTER
:
3993 case GL_SECONDARY_COLOR_ARRAY_POINTER
:
3997 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayPointervEXT(pname)");
4001 /* pname has been validated, we can now use the helper function */
4002 _get_vao_pointerv(pname
, vao
, param
, "glGetVertexArrayPointervEXT");
4006 _mesa_GetVertexArrayIntegeri_vEXT(GLuint vaobj
, GLuint index
, GLenum pname
, GLint
*param
)
4008 GET_CURRENT_CONTEXT(ctx
);
4009 struct gl_vertex_array_object
* vao
;
4011 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
4012 "glGetVertexArrayIntegeri_vEXT");
4017 /* The EXT_direct_state_access spec says:
4019 * "For GetVertexArrayIntegeri_vEXT, pname must be one of the
4020 * "Get value" tokens in tables 6.8 and 6.9 that use GetVertexAttribiv
4021 * or GetVertexAttribPointerv (so allowing only the VERTEX_ATTRIB_*
4022 * tokens) or a token of the form TEXTURE_COORD_ARRAY (the enable) or
4023 * TEXTURE_COORD_ARRAY_*; index identifies the vertex attribute
4024 * array to query or texture coordinate set index respectively."
4028 case GL_TEXTURE_COORD_ARRAY
:
4029 *param
= !!(vao
->Enabled
& VERT_BIT_TEX(index
));
4031 case GL_TEXTURE_COORD_ARRAY_SIZE
:
4032 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Format
.Size
;
4034 case GL_TEXTURE_COORD_ARRAY_TYPE
:
4035 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Format
.Type
;
4037 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
4038 *param
= vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Stride
;
4040 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING
:
4041 *param
= vao
->BufferBinding
[VERT_ATTRIB_TEX(index
)].BufferObj
->Name
;
4044 *param
= get_vertex_array_attrib(ctx
, vao
, index
, pname
, "glGetVertexArrayIntegeri_vEXT");
4049 _mesa_GetVertexArrayPointeri_vEXT(GLuint vaobj
, GLuint index
, GLenum pname
, GLvoid
** param
)
4051 GET_CURRENT_CONTEXT(ctx
);
4052 struct gl_vertex_array_object
* vao
;
4054 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, true,
4055 "glGetVertexArrayPointeri_vEXT");
4059 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
4060 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayPointeri_vEXT(index)");
4064 /* The EXT_direct_state_access spec says:
4066 * "For GetVertexArrayPointeri_vEXT, pname must be VERTEX_ATTRIB_ARRAY_POINTER
4067 * or TEXTURE_COORD_ARRAY_POINTER with the index parameter indicating the vertex
4068 * attribute or texture coordindate set index."
4071 case GL_VERTEX_ATTRIB_ARRAY_POINTER
:
4072 *param
= (GLvoid
*) vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
4074 case GL_TEXTURE_COORD_ARRAY_POINTER
:
4075 *param
= (GLvoid
*) vao
->VertexAttrib
[VERT_ATTRIB_TEX(index
)].Ptr
;
4078 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayPointeri_vEXT(pname)");