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"
42 #include "main/dispatch.h"
45 /** Used to do error checking for GL_EXT_vertex_array_bgra */
49 /** Used to indicate which GL datatypes are accepted by each of the
50 * glVertex/Color/Attrib/EtcPointer() functions.
52 #define BOOL_BIT (1 << 0)
53 #define BYTE_BIT (1 << 1)
54 #define UNSIGNED_BYTE_BIT (1 << 2)
55 #define SHORT_BIT (1 << 3)
56 #define UNSIGNED_SHORT_BIT (1 << 4)
57 #define INT_BIT (1 << 5)
58 #define UNSIGNED_INT_BIT (1 << 6)
59 #define HALF_BIT (1 << 7)
60 #define FLOAT_BIT (1 << 8)
61 #define DOUBLE_BIT (1 << 9)
62 #define FIXED_ES_BIT (1 << 10)
63 #define FIXED_GL_BIT (1 << 11)
64 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
65 #define INT_2_10_10_10_REV_BIT (1 << 13)
66 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
67 #define ALL_TYPE_BITS ((1 << 15) - 1)
69 #define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
70 SHORT_BIT | UNSIGNED_SHORT_BIT | \
71 INT_BIT | UNSIGNED_INT_BIT | \
72 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
74 UNSIGNED_INT_2_10_10_10_REV_BIT | \
75 INT_2_10_10_10_REV_BIT | \
76 UNSIGNED_INT_10F_11F_11F_REV_BIT)
78 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
79 SHORT_BIT | UNSIGNED_SHORT_BIT | \
80 INT_BIT | UNSIGNED_INT_BIT)
82 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
85 /** Convert GL datatype enum into a <type>_BIT value seen above */
87 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
94 case GL_UNSIGNED_BYTE
:
95 return UNSIGNED_BYTE_BIT
;
98 case GL_UNSIGNED_SHORT
:
99 return UNSIGNED_SHORT_BIT
;
102 case GL_UNSIGNED_INT
:
103 return UNSIGNED_INT_BIT
;
105 case GL_HALF_FLOAT_OES
:
106 if (ctx
->Extensions
.ARB_half_float_vertex
)
115 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
116 case GL_UNSIGNED_INT_2_10_10_10_REV
:
117 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
118 case GL_INT_2_10_10_10_REV
:
119 return INT_2_10_10_10_REV_BIT
;
120 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
121 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
129 * Depending on the position and generic0 attributes enable flags select
130 * the one that is used for both attributes.
131 * The generic0 attribute takes precedence.
134 update_attribute_map_mode(const struct gl_context
*ctx
,
135 struct gl_vertex_array_object
*vao
)
138 * There is no need to change the mapping away from the
139 * identity mapping if we are not in compat mode.
141 if (ctx
->API
!= API_OPENGL_COMPAT
)
143 /* The generic0 attribute superseeds the position attribute */
144 const GLbitfield enabled
= vao
->_Enabled
;
145 if (enabled
& VERT_BIT_GENERIC0
)
146 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_GENERIC0
;
147 else if (enabled
& VERT_BIT_POS
)
148 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_POSITION
;
150 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_IDENTITY
;
155 * Sets the BufferBindingIndex field for the vertex attribute given by
159 _mesa_vertex_attrib_binding(struct gl_context
*ctx
,
160 struct gl_vertex_array_object
*vao
,
161 gl_vert_attrib attribIndex
,
162 GLuint bindingIndex
, bool flush_vertices
)
164 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attribIndex
];
165 assert(!vao
->SharedAndImmutable
);
167 if (array
->BufferBindingIndex
!= bindingIndex
) {
168 const GLbitfield array_bit
= VERT_BIT(attribIndex
);
170 if (_mesa_is_bufferobj(vao
->BufferBinding
[bindingIndex
].BufferObj
))
171 vao
->VertexAttribBufferMask
|= array_bit
;
173 vao
->VertexAttribBufferMask
&= ~array_bit
;
175 vao
->BufferBinding
[array
->BufferBindingIndex
]._BoundArrays
&= ~array_bit
;
176 vao
->BufferBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
178 array
->BufferBindingIndex
= bindingIndex
;
180 vao
->NewArrays
|= vao
->_Enabled
& array_bit
;
181 ctx
->NewState
|= _NEW_ARRAY
;
187 * Binds a buffer object to the vertex buffer binding point given by index,
188 * and sets the Offset and Stride fields.
191 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
192 struct gl_vertex_array_object
*vao
,
194 struct gl_buffer_object
*vbo
,
195 GLintptr offset
, GLsizei stride
, bool flush_vertices
)
197 assert(index
< ARRAY_SIZE(vao
->BufferBinding
));
198 assert(!vao
->SharedAndImmutable
);
199 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
201 if (binding
->BufferObj
!= vbo
||
202 binding
->Offset
!= offset
||
203 binding
->Stride
!= stride
) {
205 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
207 binding
->Offset
= offset
;
208 binding
->Stride
= stride
;
210 if (!_mesa_is_bufferobj(vbo
))
211 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
213 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
215 vao
->NewArrays
|= vao
->_Enabled
& binding
->_BoundArrays
;
216 ctx
->NewState
|= _NEW_ARRAY
;
222 * Sets the InstanceDivisor field in the vertex buffer binding point
223 * given by bindingIndex.
226 vertex_binding_divisor(struct gl_context
*ctx
,
227 struct gl_vertex_array_object
*vao
,
231 struct gl_vertex_buffer_binding
*binding
=
232 &vao
->BufferBinding
[bindingIndex
];
233 assert(!vao
->SharedAndImmutable
);
235 if (binding
->InstanceDivisor
!= divisor
) {
236 binding
->InstanceDivisor
= divisor
;
237 vao
->NewArrays
|= vao
->_Enabled
& binding
->_BoundArrays
;
238 ctx
->NewState
|= _NEW_ARRAY
;
244 * Examine the API profile and extensions to determine which types are legal
245 * for vertex arrays. This is called once from update_array_format().
248 get_legal_types_mask(const struct gl_context
*ctx
)
250 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
252 if (_mesa_is_gles(ctx
)) {
253 legalTypesMask
&= ~(FIXED_GL_BIT
|
255 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
257 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
258 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
259 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
260 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
261 * quite as trivial as we'd like because it uses a different enum value
262 * for GL_HALF_FLOAT_OES.
264 if (ctx
->Version
< 30) {
265 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
267 UNSIGNED_INT_2_10_10_10_REV_BIT
|
268 INT_2_10_10_10_REV_BIT
);
270 if (!_mesa_has_OES_vertex_half_float(ctx
))
271 legalTypesMask
&= ~HALF_BIT
;
275 legalTypesMask
&= ~FIXED_ES_BIT
;
277 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
278 legalTypesMask
&= ~FIXED_GL_BIT
;
280 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
281 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
282 INT_2_10_10_10_REV_BIT
);
284 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
285 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
288 return legalTypesMask
;
292 get_array_format(const struct gl_context
*ctx
, GLint sizeMax
, GLint
*size
)
294 GLenum format
= GL_RGBA
;
296 /* Do size parameter checking.
297 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
298 * must be handled specially.
300 if (ctx
->Extensions
.EXT_vertex_array_bgra
&& sizeMax
== BGRA_OR_4
&&
311 * \param attrib The index of the attribute array
312 * \param size Components per element (1, 2, 3 or 4)
313 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
314 * \param format Either GL_RGBA or GL_BGRA.
315 * \param normalized Whether integer types are converted to floats in [-1, 1]
316 * \param integer Integer-valued values (will not be normalized to [-1, 1])
317 * \param doubles Double values not reduced to floats
318 * \param relativeOffset Offset of the first element relative to the binding
322 _mesa_update_array_format(struct gl_context
*ctx
,
323 struct gl_vertex_array_object
*vao
,
324 gl_vert_attrib attrib
, GLint size
, GLenum type
,
325 GLenum format
, GLboolean normalized
,
326 GLboolean integer
, GLboolean doubles
,
327 GLuint relativeOffset
)
329 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
332 assert(!vao
->SharedAndImmutable
);
335 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
336 assert(elementSize
!= -1);
340 array
->Format
= format
;
341 array
->Normalized
= normalized
;
342 array
->Integer
= integer
;
343 array
->Doubles
= doubles
;
344 array
->RelativeOffset
= relativeOffset
;
345 array
->_ElementSize
= elementSize
;
347 vao
->NewArrays
|= vao
->_Enabled
& VERT_BIT(attrib
);
348 ctx
->NewState
|= _NEW_ARRAY
;
352 * Does error checking of the format in an attrib array.
354 * Called by *Pointer() and VertexAttrib*Format().
356 * \param func Name of calling function used for error reporting
357 * \param attrib The index of the attribute array
358 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
359 * \param sizeMin Min allowable size value
360 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
361 * \param size Components per element (1, 2, 3 or 4)
362 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
363 * \param normalized Whether integer types are converted to floats in [-1, 1]
364 * \param integer Integer-valued values (will not be normalized to [-1, 1])
365 * \param doubles Double values not reduced to floats
366 * \param relativeOffset Offset of the first element relative to the binding offset.
367 * \return bool True if validation is successful, False otherwise.
370 validate_array_format(struct gl_context
*ctx
, const char *func
,
371 struct gl_vertex_array_object
*vao
,
372 GLuint attrib
, GLbitfield legalTypesMask
,
373 GLint sizeMin
, GLint sizeMax
,
374 GLint size
, GLenum type
, GLboolean normalized
,
375 GLboolean integer
, GLboolean doubles
,
376 GLuint relativeOffset
, GLenum format
)
380 /* at most, one of these bools can be true */
381 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
383 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
384 /* Compute the LegalTypesMask only once, unless the context API has
385 * changed, in which case we want to compute it again. We can't do this
386 * in _mesa_init_varrays() below because extensions are not yet enabled
389 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
390 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
393 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
395 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
396 /* BGRA ordering is not supported in ES contexts.
401 typeBit
= type_to_bit(ctx
, type
);
402 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
403 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
404 func
, _mesa_enum_to_string(type
));
408 if (format
== GL_BGRA
) {
409 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
411 * "An INVALID_OPERATION error is generated under any of the following
414 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
415 * or UNSIGNED_INT_2_10_10_10_REV;
417 * • size is BGRA and normalized is FALSE;"
419 bool bgra_error
= false;
421 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
422 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
423 type
!= GL_INT_2_10_10_10_REV
&&
424 type
!= GL_UNSIGNED_BYTE
)
426 } else if (type
!= GL_UNSIGNED_BYTE
)
430 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
431 func
, _mesa_enum_to_string(type
));
436 _mesa_error(ctx
, GL_INVALID_OPERATION
,
437 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
441 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
442 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
446 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
447 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
448 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
449 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
453 /* The ARB_vertex_attrib_binding_spec says:
455 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
456 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
458 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
459 _mesa_error(ctx
, GL_INVALID_VALUE
,
460 "%s(relativeOffset=%d > "
461 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
462 func
, relativeOffset
);
466 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
467 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
468 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
476 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
478 * \param func name of calling function used for error reporting
479 * \param attrib the attribute array index to update
480 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
481 * \param sizeMin min allowable size value
482 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
483 * \param size components per element (1, 2, 3 or 4)
484 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
485 * \param stride stride between elements, in elements
486 * \param normalized are integer types converted to floats in [-1, 1]?
487 * \param integer integer-valued values (will not be normalized to [-1,1])
488 * \param doubles Double values not reduced to floats
489 * \param ptr the address (or offset inside VBO) of the array data
492 validate_array(struct gl_context
*ctx
, const char *func
,
493 GLuint attrib
, GLbitfield legalTypesMask
,
494 GLint sizeMin
, GLint sizeMax
,
495 GLint size
, GLenum type
, GLsizei stride
,
496 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
499 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
501 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
503 * "Client vertex arrays - all vertex array attribute pointers must
504 * refer to buffer objects (section 2.9.2). The default vertex array
505 * object (the name zero) is also deprecated. Calling
506 * VertexAttribPointer when no buffer object or no vertex array object
507 * is bound will generate an INVALID_OPERATION error..."
509 * The check for VBOs is handled below.
511 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
512 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
518 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
522 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
523 stride
> ctx
->Const
.MaxVertexAttribStride
) {
524 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
525 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
529 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
531 * "An INVALID_OPERATION error is generated under any of the following
536 * * any of the *Pointer commands specifying the location and
537 * organization of vertex array data are called while zero is bound
538 * to the ARRAY_BUFFER buffer object binding point (see section
539 * 2.9.6), and the pointer argument is not NULL."
541 if (ptr
!= NULL
&& vao
!= ctx
->Array
.DefaultVAO
&&
542 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
543 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
550 validate_array_and_format(struct gl_context
*ctx
, const char *func
,
551 GLuint attrib
, GLbitfield legalTypes
,
552 GLint sizeMin
, GLint sizeMax
,
553 GLint size
, GLenum type
, GLsizei stride
,
554 GLboolean normalized
, GLboolean integer
,
555 GLboolean doubles
, GLenum format
, const GLvoid
*ptr
,
556 struct gl_vertex_array_object
*vao
)
558 validate_array(ctx
, func
, attrib
, legalTypes
, sizeMin
, sizeMax
, size
,
559 type
, stride
, normalized
, integer
, doubles
, ptr
);
561 return validate_array_format(ctx
, func
, vao
, attrib
, legalTypes
, sizeMin
,
562 sizeMax
, size
, type
, normalized
, integer
,
568 * Update state for glVertex/Color/TexCoord/...Pointer functions.
570 * \param attrib the attribute array index to update
571 * \param format Either GL_RGBA or GL_BGRA.
572 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
573 * \param size components per element (1, 2, 3 or 4)
574 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
575 * \param stride stride between elements, in elements
576 * \param normalized are integer types converted to floats in [-1, 1]?
577 * \param integer integer-valued values (will not be normalized to [-1,1])
578 * \param doubles Double values not reduced to floats
579 * \param ptr the address (or offset inside VBO) of the array data
582 update_array(struct gl_context
*ctx
,
583 GLuint attrib
, GLenum format
,
585 GLint size
, GLenum type
, GLsizei stride
,
586 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
589 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
591 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
592 normalized
, integer
, doubles
, 0);
594 /* Reset the vertex attrib binding */
595 _mesa_vertex_attrib_binding(ctx
, vao
, attrib
, attrib
, true);
597 /* The Stride and Ptr fields are not set by update_array_format() */
598 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attrib
];
599 array
->Stride
= stride
;
600 /* For updating the pointer we would need to add the vao->NewArrays flag
601 * to the VAO. But but that is done already unconditionally in
602 * _mesa_update_array_format called above.
604 assert((vao
->NewArrays
| ~vao
->_Enabled
) & VERT_BIT(attrib
));
607 /* Update the vertex buffer binding */
608 GLsizei effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
609 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
610 ctx
->Array
.ArrayBufferObj
, (GLintptr
) ptr
,
611 effectiveStride
, true);
615 _mesa_VertexPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
618 GET_CURRENT_CONTEXT(ctx
);
620 update_array(ctx
, VERT_ATTRIB_POS
, GL_RGBA
, 4, size
, type
, stride
,
621 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
626 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
628 GET_CURRENT_CONTEXT(ctx
);
630 GLenum format
= GL_RGBA
;
631 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
632 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
633 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
634 DOUBLE_BIT
| HALF_BIT
|
635 UNSIGNED_INT_2_10_10_10_REV_BIT
|
636 INT_2_10_10_10_REV_BIT
);
638 if (!validate_array_and_format(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
639 legalTypes
, 2, 4, size
, type
, stride
,
640 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
,
641 ptr
, ctx
->Array
.VAO
))
644 update_array(ctx
, VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
645 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
650 _mesa_NormalPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
652 GET_CURRENT_CONTEXT(ctx
);
654 update_array(ctx
, VERT_ATTRIB_NORMAL
, GL_RGBA
, 3, 3, type
, stride
, GL_TRUE
,
655 GL_FALSE
, GL_FALSE
, ptr
);
660 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
662 GET_CURRENT_CONTEXT(ctx
);
664 GLenum format
= GL_RGBA
;
665 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
666 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
667 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
668 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
669 UNSIGNED_INT_2_10_10_10_REV_BIT
|
670 INT_2_10_10_10_REV_BIT
);
672 if (!validate_array_and_format(ctx
, "glNormalPointer",
673 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
674 type
, stride
, GL_TRUE
, GL_FALSE
,
675 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
678 update_array(ctx
, VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
679 GL_FALSE
, GL_FALSE
, ptr
);
684 _mesa_ColorPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
687 GET_CURRENT_CONTEXT(ctx
);
689 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
690 update_array(ctx
, VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
691 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
696 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
698 GET_CURRENT_CONTEXT(ctx
);
699 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
701 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
702 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
703 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
704 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
705 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
706 INT_BIT
| UNSIGNED_INT_BIT
|
707 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
708 UNSIGNED_INT_2_10_10_10_REV_BIT
|
709 INT_2_10_10_10_REV_BIT
);
711 if (!validate_array_and_format(ctx
, "glColorPointer",
712 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
713 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
714 GL_FALSE
, GL_FALSE
, format
, ptr
,
718 update_array(ctx
, VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
719 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
724 _mesa_FogCoordPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
726 GET_CURRENT_CONTEXT(ctx
);
728 update_array(ctx
, VERT_ATTRIB_FOG
, GL_RGBA
, 1, 1, type
, stride
, GL_FALSE
,
729 GL_FALSE
, GL_FALSE
, ptr
);
734 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
736 GET_CURRENT_CONTEXT(ctx
);
738 GLenum format
= GL_RGBA
;
739 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
741 if (!validate_array_and_format(ctx
, "glFogCoordPointer",
742 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
743 type
, stride
, GL_FALSE
, GL_FALSE
,
744 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
747 update_array(ctx
, VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
748 GL_FALSE
, GL_FALSE
, ptr
);
753 _mesa_IndexPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
755 GET_CURRENT_CONTEXT(ctx
);
757 update_array(ctx
, VERT_ATTRIB_COLOR_INDEX
, GL_RGBA
, 1, 1, type
, stride
,
758 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
763 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
765 GET_CURRENT_CONTEXT(ctx
);
767 GLenum format
= GL_RGBA
;
768 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
769 FLOAT_BIT
| DOUBLE_BIT
);
771 if (!validate_array_and_format(ctx
, "glIndexPointer",
772 VERT_ATTRIB_COLOR_INDEX
,
773 legalTypes
, 1, 1, 1, type
, stride
,
774 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
,
775 ptr
, ctx
->Array
.VAO
))
778 update_array(ctx
, VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
779 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
784 _mesa_SecondaryColorPointer_no_error(GLint size
, GLenum type
,
785 GLsizei stride
, const GLvoid
*ptr
)
787 GET_CURRENT_CONTEXT(ctx
);
789 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
790 update_array(ctx
, VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
791 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
796 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
797 GLsizei stride
, const GLvoid
*ptr
)
799 GET_CURRENT_CONTEXT(ctx
);
801 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
802 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
803 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
804 INT_BIT
| UNSIGNED_INT_BIT
|
805 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
806 UNSIGNED_INT_2_10_10_10_REV_BIT
|
807 INT_2_10_10_10_REV_BIT
);
809 if (!validate_array_and_format(ctx
, "glSecondaryColorPointer",
810 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
811 BGRA_OR_4
, size
, type
, stride
,
812 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, ptr
,
816 update_array(ctx
, VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
817 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
822 _mesa_TexCoordPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
825 GET_CURRENT_CONTEXT(ctx
);
826 const GLuint unit
= ctx
->Array
.ActiveTexture
;
828 update_array(ctx
, VERT_ATTRIB_TEX(unit
), GL_RGBA
, 4, size
, type
,
829 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
834 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
837 GET_CURRENT_CONTEXT(ctx
);
838 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
839 const GLuint unit
= ctx
->Array
.ActiveTexture
;
841 GLenum format
= GL_RGBA
;
842 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
843 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
844 : (SHORT_BIT
| INT_BIT
|
845 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
846 UNSIGNED_INT_2_10_10_10_REV_BIT
|
847 INT_2_10_10_10_REV_BIT
);
849 if (!validate_array_and_format(ctx
, "glTexCoordPointer",
850 VERT_ATTRIB_TEX(unit
), legalTypes
,
851 sizeMin
, 4, size
, type
, stride
,
852 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
,
856 update_array(ctx
, VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
857 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
862 _mesa_EdgeFlagPointer_no_error(GLsizei stride
, const GLvoid
*ptr
)
864 /* this is the same type that glEdgeFlag uses */
865 const GLboolean integer
= GL_FALSE
;
866 GET_CURRENT_CONTEXT(ctx
);
868 update_array(ctx
, VERT_ATTRIB_EDGEFLAG
, GL_RGBA
, 1, 1, GL_UNSIGNED_BYTE
,
869 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
874 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
876 /* this is the same type that glEdgeFlag uses */
877 const GLboolean integer
= GL_FALSE
;
878 GET_CURRENT_CONTEXT(ctx
);
880 GLenum format
= GL_RGBA
;
881 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
883 if (!validate_array_and_format(ctx
, "glEdgeFlagPointer",
884 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
885 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
886 GL_FALSE
, integer
, GL_FALSE
, format
, ptr
,
890 update_array(ctx
, VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
891 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
896 _mesa_PointSizePointerOES_no_error(GLenum type
, GLsizei stride
,
899 GET_CURRENT_CONTEXT(ctx
);
901 update_array(ctx
, VERT_ATTRIB_POINT_SIZE
, GL_RGBA
, 1, 1, type
, stride
,
902 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
907 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
909 GET_CURRENT_CONTEXT(ctx
);
911 GLenum format
= GL_RGBA
;
912 if (ctx
->API
!= API_OPENGLES
) {
913 _mesa_error(ctx
, GL_INVALID_OPERATION
,
914 "glPointSizePointer(ES 1.x only)");
918 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
920 if (!validate_array_and_format(ctx
, "glPointSizePointer",
921 VERT_ATTRIB_POINT_SIZE
, legalTypes
,
922 1, 1, 1, type
, stride
, GL_FALSE
, GL_FALSE
,
923 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
926 update_array(ctx
, VERT_ATTRIB_POINT_SIZE
, format
, 1, 1, type
, stride
,
927 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
932 _mesa_VertexAttribPointer_no_error(GLuint index
, GLint size
, GLenum type
,
933 GLboolean normalized
,
934 GLsizei stride
, const GLvoid
*ptr
)
936 GET_CURRENT_CONTEXT(ctx
);
938 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
939 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
940 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
945 * Set a generic vertex attribute array.
946 * Note that these arrays DO NOT alias the conventional GL vertex arrays
947 * (position, normal, color, fog, texcoord, etc).
950 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
951 GLboolean normalized
,
952 GLsizei stride
, const GLvoid
*ptr
)
954 GET_CURRENT_CONTEXT(ctx
);
956 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
957 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
958 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(idx)");
962 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
963 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
964 INT_BIT
| UNSIGNED_INT_BIT
|
965 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
966 FIXED_ES_BIT
| FIXED_GL_BIT
|
967 UNSIGNED_INT_2_10_10_10_REV_BIT
|
968 INT_2_10_10_10_REV_BIT
|
969 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
971 if (!validate_array_and_format(ctx
, "glVertexAttribPointer",
972 VERT_ATTRIB_GENERIC(index
), legalTypes
,
973 1, BGRA_OR_4
, size
, type
, stride
,
974 normalized
, GL_FALSE
, GL_FALSE
, format
,
975 ptr
, ctx
->Array
.VAO
))
978 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
979 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
984 _mesa_VertexAttribIPointer_no_error(GLuint index
, GLint size
, GLenum type
,
985 GLsizei stride
, const GLvoid
*ptr
)
987 const GLboolean normalized
= GL_FALSE
;
988 const GLboolean integer
= GL_TRUE
;
989 GET_CURRENT_CONTEXT(ctx
);
991 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
992 stride
, normalized
, integer
, GL_FALSE
, ptr
);
997 * GL_EXT_gpu_shader4 / GL 3.0.
998 * Set an integer-valued vertex attribute array.
999 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1000 * (position, normal, color, fog, texcoord, etc).
1003 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
1004 GLsizei stride
, const GLvoid
*ptr
)
1006 const GLboolean normalized
= GL_FALSE
;
1007 const GLboolean integer
= GL_TRUE
;
1008 GET_CURRENT_CONTEXT(ctx
);
1010 GLenum format
= GL_RGBA
;
1011 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1012 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
1016 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1017 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1018 INT_BIT
| UNSIGNED_INT_BIT
);
1020 if (!validate_array_and_format(ctx
, "glVertexAttribIPointer",
1021 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1022 1, 4, size
, type
, stride
,
1023 normalized
, integer
, GL_FALSE
, format
,
1024 ptr
, ctx
->Array
.VAO
))
1027 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1028 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1033 _mesa_VertexAttribLPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1034 GLsizei stride
, const GLvoid
*ptr
)
1036 GET_CURRENT_CONTEXT(ctx
);
1038 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1039 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1044 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
1045 GLsizei stride
, const GLvoid
*ptr
)
1047 GET_CURRENT_CONTEXT(ctx
);
1049 GLenum format
= GL_RGBA
;
1050 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1051 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
1055 const GLbitfield legalTypes
= DOUBLE_BIT
;
1057 if (!validate_array_and_format(ctx
, "glVertexAttribLPointer",
1058 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1059 1, 4, size
, type
, stride
,
1060 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
,
1061 ptr
, ctx
->Array
.VAO
))
1064 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1065 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1070 _mesa_enable_vertex_array_attrib(struct gl_context
*ctx
,
1071 struct gl_vertex_array_object
*vao
,
1072 gl_vert_attrib attrib
, bool flush_vertices
)
1074 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
1075 assert(!vao
->SharedAndImmutable
);
1077 if (!vao
->VertexAttrib
[attrib
].Enabled
) {
1078 /* was disabled, now being enabled */
1079 vao
->VertexAttrib
[attrib
].Enabled
= GL_TRUE
;
1080 const GLbitfield array_bit
= VERT_BIT(attrib
);
1081 vao
->_Enabled
|= array_bit
;
1082 vao
->NewArrays
|= array_bit
;
1083 ctx
->NewState
|= _NEW_ARRAY
;
1085 /* Update the map mode if needed */
1086 if (array_bit
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1087 update_attribute_map_mode(ctx
, vao
);
1092 enable_vertex_array_attrib(struct gl_context
*ctx
,
1093 struct gl_vertex_array_object
*vao
,
1097 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1098 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
1102 _mesa_enable_vertex_array_attrib(ctx
, vao
,
1103 VERT_ATTRIB_GENERIC(index
), true);
1108 _mesa_EnableVertexAttribArray(GLuint index
)
1110 GET_CURRENT_CONTEXT(ctx
);
1111 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
1112 "glEnableVertexAttribArray");
1117 _mesa_EnableVertexAttribArray_no_error(GLuint index
)
1119 GET_CURRENT_CONTEXT(ctx
);
1120 _mesa_enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1121 VERT_ATTRIB_GENERIC(index
), true);
1126 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1128 GET_CURRENT_CONTEXT(ctx
);
1129 struct gl_vertex_array_object
*vao
;
1131 /* The ARB_direct_state_access specification says:
1133 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1134 * and DisableVertexArrayAttrib if <vaobj> is not
1135 * [compatibility profile: zero or] the name of an existing vertex
1138 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
1142 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
1147 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1149 GET_CURRENT_CONTEXT(ctx
);
1150 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1151 _mesa_enable_vertex_array_attrib(ctx
, vao
,
1152 VERT_ATTRIB_GENERIC(index
), true);
1157 _mesa_disable_vertex_array_attrib(struct gl_context
*ctx
,
1158 struct gl_vertex_array_object
*vao
,
1159 gl_vert_attrib attrib
, bool flush_vertices
)
1161 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
1162 assert(!vao
->SharedAndImmutable
);
1164 if (vao
->VertexAttrib
[attrib
].Enabled
) {
1165 /* was enabled, now being disabled */
1166 vao
->VertexAttrib
[attrib
].Enabled
= GL_FALSE
;
1167 const GLbitfield array_bit
= VERT_BIT(attrib
);
1168 vao
->_Enabled
&= ~array_bit
;
1169 vao
->NewArrays
|= array_bit
;
1170 ctx
->NewState
|= _NEW_ARRAY
;
1172 /* Update the map mode if needed */
1173 if (array_bit
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1174 update_attribute_map_mode(ctx
, vao
);
1180 _mesa_DisableVertexAttribArray(GLuint index
)
1182 GET_CURRENT_CONTEXT(ctx
);
1184 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1185 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexAttribArray(index)");
1189 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1190 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
, true);
1195 _mesa_DisableVertexAttribArray_no_error(GLuint index
)
1197 GET_CURRENT_CONTEXT(ctx
);
1198 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1199 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
, true);
1204 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1206 GET_CURRENT_CONTEXT(ctx
);
1207 struct gl_vertex_array_object
*vao
;
1209 /* The ARB_direct_state_access specification says:
1211 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1212 * and DisableVertexArrayAttrib if <vaobj> is not
1213 * [compatibility profile: zero or] the name of an existing vertex
1216 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
1220 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1221 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
1225 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1226 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
, true);
1231 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1233 GET_CURRENT_CONTEXT(ctx
);
1234 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1235 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1236 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
, true);
1241 * Return info for a vertex attribute array (no alias with legacy
1242 * vertex attributes (pos, normal, color, etc)). This function does
1243 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
1246 get_vertex_array_attrib(struct gl_context
*ctx
,
1247 const struct gl_vertex_array_object
*vao
,
1248 GLuint index
, GLenum pname
,
1251 const struct gl_array_attributes
*array
;
1253 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1254 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
1258 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
1260 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
1263 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
1264 return array
->Enabled
;
1265 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
1266 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
1267 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
1268 return array
->Stride
;
1269 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
1271 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
1272 return array
->Normalized
;
1273 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
1274 return vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
->Name
;
1275 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
1276 if ((_mesa_is_desktop_gl(ctx
)
1277 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
1278 || _mesa_is_gles3(ctx
)) {
1279 return array
->Integer
;
1282 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
1283 if (_mesa_is_desktop_gl(ctx
)) {
1284 return array
->Doubles
;
1287 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
1288 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
1289 || _mesa_is_gles3(ctx
)) {
1290 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
1293 case GL_VERTEX_ATTRIB_BINDING
:
1294 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1295 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
1298 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
1299 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1300 return array
->RelativeOffset
;
1304 ; /* fall-through */
1308 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
1313 static const GLfloat
*
1314 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
1317 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
1318 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
1322 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1323 _mesa_error(ctx
, GL_INVALID_VALUE
,
1324 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
1328 assert(VERT_ATTRIB_GENERIC(index
) <
1329 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1331 FLUSH_CURRENT(ctx
, 0);
1332 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
1336 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
1338 GET_CURRENT_CONTEXT(ctx
);
1340 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1341 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
1347 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1349 "glGetVertexAttribfv");
1355 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1357 GET_CURRENT_CONTEXT(ctx
);
1359 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1360 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
1362 params
[0] = (GLdouble
) v
[0];
1363 params
[1] = (GLdouble
) v
[1];
1364 params
[2] = (GLdouble
) v
[2];
1365 params
[3] = (GLdouble
) v
[3];
1369 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1371 "glGetVertexAttribdv");
1376 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1378 GET_CURRENT_CONTEXT(ctx
);
1380 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1382 (const GLdouble
*)get_current_attrib(ctx
, index
,
1383 "glGetVertexAttribLdv");
1392 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1394 "glGetVertexAttribLdv");
1399 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1401 GET_CURRENT_CONTEXT(ctx
);
1403 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1404 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1406 /* XXX should floats in[0,1] be scaled to full int range? */
1407 params
[0] = (GLint
) v
[0];
1408 params
[1] = (GLint
) v
[1];
1409 params
[2] = (GLint
) v
[2];
1410 params
[3] = (GLint
) v
[3];
1414 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1416 "glGetVertexAttribiv");
1421 _mesa_GetVertexAttribLui64vARB(GLuint index
, GLenum pname
, GLuint64EXT
*params
)
1423 GET_CURRENT_CONTEXT(ctx
);
1425 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1427 (const GLuint64
*)get_current_attrib(ctx
, index
,
1428 "glGetVertexAttribLui64vARB");
1437 params
[0] = (GLuint64
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1439 "glGetVertexAttribLui64vARB");
1446 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1448 GET_CURRENT_CONTEXT(ctx
);
1450 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1451 const GLint
*v
= (const GLint
*)
1452 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1458 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1460 "glGetVertexAttribIiv");
1467 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1469 GET_CURRENT_CONTEXT(ctx
);
1471 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1472 const GLuint
*v
= (const GLuint
*)
1473 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1479 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1481 "glGetVertexAttribIuiv");
1487 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1489 GET_CURRENT_CONTEXT(ctx
);
1491 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1492 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1496 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1497 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1501 assert(VERT_ATTRIB_GENERIC(index
) <
1502 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1504 *pointer
= (GLvoid
*)
1505 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1509 /** ARB_direct_state_access */
1511 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1512 GLenum pname
, GLint
*params
)
1514 GET_CURRENT_CONTEXT(ctx
);
1515 struct gl_vertex_array_object
*vao
;
1517 /* The ARB_direct_state_access specification says:
1519 * "An INVALID_OPERATION error is generated if <vaobj> is not
1520 * [compatibility profile: zero or] the name of an existing
1521 * vertex array object."
1523 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexediv");
1527 /* The ARB_direct_state_access specification says:
1529 * "For GetVertexArrayIndexediv, <pname> must be one of
1530 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1531 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1532 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1533 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1534 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1538 * "Add GetVertexArrayIndexediv in 'Get Command' for
1539 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1540 * VERTEX_ATTRIB_BINDING,
1541 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1542 * VERTEX_BINDING_OFFSET, and
1543 * VERTEX_BINDING_STRIDE states"
1545 * The only parameter name common to both lists is
1546 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1547 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1548 * pretty clear however that the intent is that it should be possible
1549 * to query all vertex attrib and binding states that can be set with
1553 case GL_VERTEX_BINDING_OFFSET
:
1554 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1556 case GL_VERTEX_BINDING_STRIDE
:
1557 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1559 case GL_VERTEX_BINDING_DIVISOR
:
1560 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1562 case GL_VERTEX_BINDING_BUFFER
:
1563 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1566 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1567 "glGetVertexArrayIndexediv");
1574 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1575 GLenum pname
, GLint64
*params
)
1577 GET_CURRENT_CONTEXT(ctx
);
1578 struct gl_vertex_array_object
*vao
;
1580 /* The ARB_direct_state_access specification says:
1582 * "An INVALID_OPERATION error is generated if <vaobj> is not
1583 * [compatibility profile: zero or] the name of an existing
1584 * vertex array object."
1586 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1590 /* The ARB_direct_state_access specification says:
1592 * "For GetVertexArrayIndexed64iv, <pname> must be
1593 * VERTEX_BINDING_OFFSET."
1597 * "An INVALID_ENUM error is generated if <pname> is not one of
1598 * the valid values listed above for the corresponding command."
1600 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1601 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1602 "pname != GL_VERTEX_BINDING_OFFSET)");
1606 /* The ARB_direct_state_access specification says:
1608 * "An INVALID_VALUE error is generated if <index> is greater than
1609 * or equal to the value of MAX_VERTEX_ATTRIBS."
1611 * Since the index refers to a buffer binding in this case, the intended
1612 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1613 * required to be the same, so in practice this doesn't matter.
1615 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1616 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1617 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1618 index
, ctx
->Const
.MaxVertexAttribBindings
);
1622 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1627 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1628 GLsizei count
, const GLvoid
*ptr
)
1631 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1636 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1640 _mesa_NormalPointer(type
, stride
, ptr
);
1645 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1649 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1654 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1658 _mesa_IndexPointer(type
, stride
, ptr
);
1663 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1664 GLsizei count
, const GLvoid
*ptr
)
1667 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1672 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1675 _mesa_EdgeFlagPointer(stride
, ptr
);
1680 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1682 GET_CURRENT_CONTEXT(ctx
);
1683 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1684 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1685 GLenum ctype
= 0; /* color type */
1686 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1687 const GLint toffset
= 0; /* always zero */
1688 GLint defstride
; /* default stride */
1691 f
= sizeof(GLfloat
);
1692 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1695 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1701 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1702 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1707 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1708 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1713 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1714 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1715 ctype
= GL_UNSIGNED_BYTE
;
1718 defstride
= c
+ 2*f
;
1721 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1722 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1723 ctype
= GL_UNSIGNED_BYTE
;
1726 defstride
= c
+ 3*f
;
1729 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1730 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1737 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1738 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1743 case GL_C4F_N3F_V3F
:
1744 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1745 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1753 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1754 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1759 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1760 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1764 case GL_T2F_C4UB_V3F
:
1765 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1766 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1767 ctype
= GL_UNSIGNED_BYTE
;
1772 case GL_T2F_C3F_V3F
:
1773 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1774 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1780 case GL_T2F_N3F_V3F
:
1781 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1782 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1787 case GL_T2F_C4F_N3F_V3F
:
1788 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1789 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1796 case GL_T4F_C4F_N3F_V4F
:
1797 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1798 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1806 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1814 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1815 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1816 /* XXX also disable secondary color and generic arrays? */
1820 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1821 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1822 (GLubyte
*) pointer
+ toffset
);
1825 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1830 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1831 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1832 (GLubyte
*) pointer
+ coffset
);
1835 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1841 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1842 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1845 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1849 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1850 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1851 (GLubyte
*) pointer
+ voffset
);
1856 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1858 GET_CURRENT_CONTEXT(ctx
);
1860 if (MESA_VERBOSE
& VERBOSE_API
)
1861 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1864 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1868 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1871 if (ctx
->Array
.LockCount
!= 0) {
1872 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1876 ctx
->Array
.LockFirst
= first
;
1877 ctx
->Array
.LockCount
= count
;
1879 ctx
->NewState
|= _NEW_ARRAY
;
1884 _mesa_UnlockArraysEXT( void )
1886 GET_CURRENT_CONTEXT(ctx
);
1888 if (MESA_VERBOSE
& VERBOSE_API
)
1889 _mesa_debug(ctx
, "glUnlockArrays\n");
1891 if (ctx
->Array
.LockCount
== 0) {
1892 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1896 ctx
->Array
.LockFirst
= 0;
1897 ctx
->Array
.LockCount
= 0;
1898 ctx
->NewState
|= _NEW_ARRAY
;
1902 /* GL_IBM_multimode_draw_arrays */
1904 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1905 const GLsizei
* count
,
1906 GLsizei primcount
, GLint modestride
)
1908 GET_CURRENT_CONTEXT(ctx
);
1911 FLUSH_VERTICES(ctx
, 0);
1913 for ( i
= 0 ; i
< primcount
; i
++ ) {
1914 if ( count
[i
] > 0 ) {
1915 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1916 CALL_DrawArrays(ctx
->CurrentServerDispatch
, ( m
, first
[i
], count
[i
] ));
1922 /* GL_IBM_multimode_draw_arrays */
1924 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1925 GLenum type
, const GLvoid
* const * indices
,
1926 GLsizei primcount
, GLint modestride
)
1928 GET_CURRENT_CONTEXT(ctx
);
1931 FLUSH_VERTICES(ctx
, 0);
1933 /* XXX not sure about ARB_vertex_buffer_object handling here */
1935 for ( i
= 0 ; i
< primcount
; i
++ ) {
1936 if ( count
[i
] > 0 ) {
1937 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1938 CALL_DrawElements(ctx
->CurrentServerDispatch
, ( m
, count
[i
], type
,
1946 primitive_restart_index(struct gl_context
*ctx
, GLuint index
)
1948 ctx
->Array
.RestartIndex
= index
;
1953 * GL_NV_primitive_restart and GL 3.1
1956 _mesa_PrimitiveRestartIndex_no_error(GLuint index
)
1958 GET_CURRENT_CONTEXT(ctx
);
1959 primitive_restart_index(ctx
, index
);
1964 _mesa_PrimitiveRestartIndex(GLuint index
)
1966 GET_CURRENT_CONTEXT(ctx
);
1968 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1969 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1973 primitive_restart_index(ctx
, index
);
1978 _mesa_VertexAttribDivisor_no_error(GLuint index
, GLuint divisor
)
1980 GET_CURRENT_CONTEXT(ctx
);
1982 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
1983 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1985 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
1987 /* The ARB_vertex_attrib_binding spec says:
1991 * void VertexAttribDivisor(uint index, uint divisor);
1993 * is equivalent to (assuming no errors are generated):
1995 * VertexAttribBinding(index, index);
1996 * VertexBindingDivisor(index, divisor);"
1998 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
, true);
1999 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2004 * See GL_ARB_instanced_arrays.
2005 * Note that the instance divisor only applies to generic arrays, not
2006 * the legacy vertex arrays.
2009 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
2011 GET_CURRENT_CONTEXT(ctx
);
2013 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2014 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2016 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2017 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
2021 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2022 _mesa_error(ctx
, GL_INVALID_VALUE
,
2023 "glVertexAttribDivisor(index = %u)", index
);
2027 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2029 /* The ARB_vertex_attrib_binding spec says:
2033 * void VertexAttribDivisor(uint index, uint divisor);
2035 * is equivalent to (assuming no errors are generated):
2037 * VertexAttribBinding(index, index);
2038 * VertexBindingDivisor(index, divisor);"
2040 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
, true);
2041 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2045 static ALWAYS_INLINE
void
2046 vertex_array_vertex_buffer(struct gl_context
*ctx
,
2047 struct gl_vertex_array_object
*vao
,
2048 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2049 GLsizei stride
, bool no_error
, const char *func
)
2051 struct gl_buffer_object
*vbo
;
2053 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
2054 vbo
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
2055 } else if (buffer
!= 0) {
2056 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
2058 if (!no_error
&& !vbo
&& _mesa_is_gles31(ctx
)) {
2059 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
2062 /* From the GL_ARB_vertex_attrib_array spec:
2064 * "[Core profile only:]
2065 * An INVALID_OPERATION error is generated if buffer is not zero or a
2066 * name returned from a previous call to GenBuffers, or if such a name
2067 * has since been deleted with DeleteBuffers.
2069 * Otherwise, we fall back to the same compat profile behavior as other
2070 * object references (automatically gen it).
2072 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
2075 /* The ARB_vertex_attrib_binding spec says:
2077 * "If <buffer> is zero, any buffer object attached to this
2078 * bindpoint is detached."
2080 vbo
= ctx
->Shared
->NullBufferObj
;
2083 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
2084 vbo
, offset
, stride
, true);
2089 * GL_ARB_vertex_attrib_binding
2092 vertex_array_vertex_buffer_err(struct gl_context
*ctx
,
2093 struct gl_vertex_array_object
*vao
,
2094 GLuint bindingIndex
, GLuint buffer
,
2095 GLintptr offset
, GLsizei stride
,
2098 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2100 /* The ARB_vertex_attrib_binding spec says:
2102 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2103 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2105 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2106 _mesa_error(ctx
, GL_INVALID_VALUE
,
2107 "%s(bindingindex=%u > "
2108 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2109 func
, bindingIndex
);
2113 /* The ARB_vertex_attrib_binding spec says:
2115 * "The error INVALID_VALUE is generated if <stride> or <offset>
2119 _mesa_error(ctx
, GL_INVALID_VALUE
,
2120 "%s(offset=%" PRId64
" < 0)",
2121 func
, (int64_t) offset
);
2126 _mesa_error(ctx
, GL_INVALID_VALUE
,
2127 "%s(stride=%d < 0)", func
, stride
);
2131 if (((_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
2132 stride
> ctx
->Const
.MaxVertexAttribStride
) {
2133 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
2134 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
2138 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2139 stride
, false, func
);
2144 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex
, GLuint buffer
,
2145 GLintptr offset
, GLsizei stride
)
2147 GET_CURRENT_CONTEXT(ctx
);
2148 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2149 buffer
, offset
, stride
, true,
2150 "glBindVertexBuffer");
2155 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2158 GET_CURRENT_CONTEXT(ctx
);
2160 /* The ARB_vertex_attrib_binding spec says:
2162 * "An INVALID_OPERATION error is generated if no vertex array object
2165 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2166 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2167 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2168 "glBindVertexBuffer(No array object bound)");
2172 vertex_array_vertex_buffer_err(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2173 buffer
, offset
, stride
,
2174 "glBindVertexBuffer");
2179 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj
, GLuint bindingIndex
,
2180 GLuint buffer
, GLintptr offset
,
2183 GET_CURRENT_CONTEXT(ctx
);
2185 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2186 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2187 stride
, true, "glVertexArrayVertexBuffer");
2192 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
2193 GLintptr offset
, GLsizei stride
)
2195 GET_CURRENT_CONTEXT(ctx
);
2196 struct gl_vertex_array_object
*vao
;
2198 /* The ARB_direct_state_access specification says:
2200 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2201 * if <vaobj> is not [compatibility profile: zero or] the name of an
2202 * existing vertex array object."
2204 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
2208 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
2209 stride
, "glVertexArrayVertexBuffer");
2213 static ALWAYS_INLINE
void
2214 vertex_array_vertex_buffers(struct gl_context
*ctx
,
2215 struct gl_vertex_array_object
*vao
,
2216 GLuint first
, GLsizei count
, const GLuint
*buffers
,
2217 const GLintptr
*offsets
, const GLsizei
*strides
,
2218 bool no_error
, const char *func
)
2224 * The ARB_multi_bind spec says:
2226 * "If <buffers> is NULL, each affected vertex buffer binding point
2227 * from <first> through <first>+<count>-1 will be reset to have no
2228 * bound buffer object. In this case, the offsets and strides
2229 * associated with the binding points are set to default values,
2230 * ignoring <offsets> and <strides>."
2232 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
2234 for (i
= 0; i
< count
; i
++)
2235 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2241 /* Note that the error semantics for multi-bind commands differ from
2242 * those of other GL commands.
2244 * The Issues section in the ARB_multi_bind spec says:
2246 * "(11) Typically, OpenGL specifies that if an error is generated by
2247 * a command, that command has no effect. This is somewhat
2248 * unfortunate for multi-bind commands, because it would require
2249 * a first pass to scan the entire list of bound objects for
2250 * errors and then a second pass to actually perform the
2251 * bindings. Should we have different error semantics?
2253 * RESOLVED: Yes. In this specification, when the parameters for
2254 * one of the <count> binding points are invalid, that binding
2255 * point is not updated and an error will be generated. However,
2256 * other binding points in the same command will be updated if
2257 * their parameters are valid and no other error occurs."
2260 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
2262 for (i
= 0; i
< count
; i
++) {
2263 struct gl_buffer_object
*vbo
;
2266 /* The ARB_multi_bind spec says:
2268 * "An INVALID_VALUE error is generated if any value in
2269 * <offsets> or <strides> is negative (per binding)."
2271 if (offsets
[i
] < 0) {
2272 _mesa_error(ctx
, GL_INVALID_VALUE
,
2273 "%s(offsets[%u]=%" PRId64
" < 0)",
2274 func
, i
, (int64_t) offsets
[i
]);
2278 if (strides
[i
] < 0) {
2279 _mesa_error(ctx
, GL_INVALID_VALUE
,
2280 "%s(strides[%u]=%d < 0)",
2281 func
, i
, strides
[i
]);
2285 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
2286 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
2287 _mesa_error(ctx
, GL_INVALID_VALUE
,
2288 "%s(strides[%u]=%d > "
2289 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
2295 struct gl_vertex_buffer_binding
*binding
=
2296 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
2298 if (buffers
[i
] == binding
->BufferObj
->Name
)
2299 vbo
= binding
->BufferObj
;
2301 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
2306 vbo
= ctx
->Shared
->NullBufferObj
;
2309 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2310 vbo
, offsets
[i
], strides
[i
], true);
2313 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
2318 vertex_array_vertex_buffers_err(struct gl_context
*ctx
,
2319 struct gl_vertex_array_object
*vao
,
2320 GLuint first
, GLsizei count
,
2321 const GLuint
*buffers
, const GLintptr
*offsets
,
2322 const GLsizei
*strides
, const char *func
)
2324 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2326 /* The ARB_multi_bind spec says:
2328 * "An INVALID_OPERATION error is generated if <first> + <count>
2329 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
2331 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
2332 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2333 "%s(first=%u + count=%d > the value of "
2334 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
2335 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
2339 vertex_array_vertex_buffers(ctx
, vao
, first
, count
, buffers
, offsets
,
2340 strides
, false, func
);
2345 _mesa_BindVertexBuffers_no_error(GLuint first
, GLsizei count
,
2346 const GLuint
*buffers
, const GLintptr
*offsets
,
2347 const GLsizei
*strides
)
2349 GET_CURRENT_CONTEXT(ctx
);
2351 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
2352 buffers
, offsets
, strides
, true,
2353 "glBindVertexBuffers");
2358 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
2359 const GLintptr
*offsets
, const GLsizei
*strides
)
2361 GET_CURRENT_CONTEXT(ctx
);
2363 /* The ARB_vertex_attrib_binding spec says:
2365 * "An INVALID_OPERATION error is generated if no
2366 * vertex array object is bound."
2368 if (ctx
->API
== API_OPENGL_CORE
&&
2369 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2370 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2371 "glBindVertexBuffers(No array object bound)");
2375 vertex_array_vertex_buffers_err(ctx
, ctx
->Array
.VAO
, first
, count
,
2376 buffers
, offsets
, strides
,
2377 "glBindVertexBuffers");
2382 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj
, GLuint first
,
2383 GLsizei count
, const GLuint
*buffers
,
2384 const GLintptr
*offsets
,
2385 const GLsizei
*strides
)
2387 GET_CURRENT_CONTEXT(ctx
);
2389 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2390 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
2391 buffers
, offsets
, strides
, true,
2392 "glVertexArrayVertexBuffers");
2397 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
2398 const GLuint
*buffers
,
2399 const GLintptr
*offsets
, const GLsizei
*strides
)
2401 GET_CURRENT_CONTEXT(ctx
);
2402 struct gl_vertex_array_object
*vao
;
2404 /* The ARB_direct_state_access specification says:
2406 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2407 * if <vaobj> is not [compatibility profile: zero or] the name of an
2408 * existing vertex array object."
2410 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
2414 vertex_array_vertex_buffers_err(ctx
, vao
, first
, count
,
2415 buffers
, offsets
, strides
,
2416 "glVertexArrayVertexBuffers");
2421 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
2422 GLboolean normalized
, GLboolean integer
,
2423 GLboolean doubles
, GLbitfield legalTypes
,
2424 GLsizei sizeMax
, GLuint relativeOffset
,
2427 GET_CURRENT_CONTEXT(ctx
);
2428 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2430 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2432 if (!_mesa_is_no_error_enabled(ctx
)) {
2433 /* The ARB_vertex_attrib_binding spec says:
2435 * "An INVALID_OPERATION error is generated under any of the
2436 * following conditions:
2437 * - if no vertex array object is currently bound (see section
2441 * This error condition only applies to VertexAttribFormat and
2442 * VertexAttribIFormat in the extension spec, but we assume that this
2443 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2444 * to all three functions.
2446 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2447 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2448 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2449 "%s(No array object bound)", func
);
2453 /* The ARB_vertex_attrib_binding spec says:
2455 * "The error INVALID_VALUE is generated if index is greater than or
2456 * equal to the value of MAX_VERTEX_ATTRIBS."
2458 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2459 _mesa_error(ctx
, GL_INVALID_VALUE
,
2460 "%s(attribindex=%u > "
2461 "GL_MAX_VERTEX_ATTRIBS)",
2466 if (!validate_array_format(ctx
, func
, ctx
->Array
.VAO
,
2467 VERT_ATTRIB_GENERIC(attribIndex
),
2468 legalTypes
, 1, sizeMax
, size
, type
,
2469 normalized
, integer
, doubles
, relativeOffset
,
2475 _mesa_update_array_format(ctx
, ctx
->Array
.VAO
,
2476 VERT_ATTRIB_GENERIC(attribIndex
), size
, type
,
2477 format
, normalized
, integer
, doubles
,
2483 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2484 GLboolean normalized
, GLuint relativeOffset
)
2486 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
2487 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2488 BGRA_OR_4
, relativeOffset
,
2489 "glVertexAttribFormat");
2494 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2495 GLuint relativeOffset
)
2497 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2498 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2499 relativeOffset
, "glVertexAttribIFormat");
2504 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2505 GLuint relativeOffset
)
2507 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2508 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2509 relativeOffset
, "glVertexAttribLFormat");
2514 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2515 GLenum type
, GLboolean normalized
,
2516 GLboolean integer
, GLboolean doubles
,
2517 GLbitfield legalTypes
, GLsizei sizeMax
,
2518 GLuint relativeOffset
, const char *func
)
2520 GET_CURRENT_CONTEXT(ctx
);
2521 struct gl_vertex_array_object
*vao
;
2523 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2525 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2527 if (_mesa_is_no_error_enabled(ctx
)) {
2528 vao
= _mesa_lookup_vao(ctx
, vaobj
);
2532 /* The ARB_direct_state_access spec says:
2534 * "An INVALID_OPERATION error is generated by
2535 * VertexArrayAttrib*Format if <vaobj> is not [compatibility profile:
2536 * zero or] the name of an existing vertex array object."
2538 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2542 /* The ARB_vertex_attrib_binding spec says:
2544 * "The error INVALID_VALUE is generated if index is greater than or
2545 * equal to the value of MAX_VERTEX_ATTRIBS."
2547 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2548 _mesa_error(ctx
, GL_INVALID_VALUE
,
2549 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2554 if (!validate_array_format(ctx
, func
, vao
,
2555 VERT_ATTRIB_GENERIC(attribIndex
),
2556 legalTypes
, 1, sizeMax
, size
, type
,
2557 normalized
, integer
, doubles
, relativeOffset
,
2563 _mesa_update_array_format(ctx
, vao
, VERT_ATTRIB_GENERIC(attribIndex
), size
,
2564 type
, format
, normalized
, integer
, doubles
,
2570 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2571 GLenum type
, GLboolean normalized
,
2572 GLuint relativeOffset
)
2574 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2575 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2576 BGRA_OR_4
, relativeOffset
,
2577 "glVertexArrayAttribFormat");
2582 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2583 GLint size
, GLenum type
,
2584 GLuint relativeOffset
)
2586 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2587 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2589 "glVertexArrayAttribIFormat");
2594 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2595 GLint size
, GLenum type
,
2596 GLuint relativeOffset
)
2598 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2599 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2601 "glVertexArrayAttribLFormat");
2606 vertex_array_attrib_binding(struct gl_context
*ctx
,
2607 struct gl_vertex_array_object
*vao
,
2608 GLuint attribIndex
, GLuint bindingIndex
,
2611 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2613 /* The ARB_vertex_attrib_binding spec says:
2615 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2616 * <bindingindex> must be less than the value of
2617 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2620 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2621 _mesa_error(ctx
, GL_INVALID_VALUE
,
2622 "%s(attribindex=%u >= "
2623 "GL_MAX_VERTEX_ATTRIBS)",
2628 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2629 _mesa_error(ctx
, GL_INVALID_VALUE
,
2630 "%s(bindingindex=%u >= "
2631 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2632 func
, bindingIndex
);
2636 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2638 _mesa_vertex_attrib_binding(ctx
, vao
,
2639 VERT_ATTRIB_GENERIC(attribIndex
),
2640 VERT_ATTRIB_GENERIC(bindingIndex
), true);
2645 _mesa_VertexAttribBinding_no_error(GLuint attribIndex
, GLuint bindingIndex
)
2647 GET_CURRENT_CONTEXT(ctx
);
2648 _mesa_vertex_attrib_binding(ctx
, ctx
->Array
.VAO
,
2649 VERT_ATTRIB_GENERIC(attribIndex
),
2650 VERT_ATTRIB_GENERIC(bindingIndex
), true);
2655 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2657 GET_CURRENT_CONTEXT(ctx
);
2659 /* The ARB_vertex_attrib_binding spec says:
2661 * "An INVALID_OPERATION error is generated if no vertex array object
2664 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2665 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2666 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2667 "glVertexAttribBinding(No array object bound)");
2671 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2672 attribIndex
, bindingIndex
,
2673 "glVertexAttribBinding");
2678 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj
, GLuint attribIndex
,
2679 GLuint bindingIndex
)
2681 GET_CURRENT_CONTEXT(ctx
);
2683 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2684 _mesa_vertex_attrib_binding(ctx
, vao
,
2685 VERT_ATTRIB_GENERIC(attribIndex
),
2686 VERT_ATTRIB_GENERIC(bindingIndex
), true);
2691 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2693 GET_CURRENT_CONTEXT(ctx
);
2694 struct gl_vertex_array_object
*vao
;
2696 /* The ARB_direct_state_access specification says:
2698 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2699 * if <vaobj> is not [compatibility profile: zero or] the name of an
2700 * existing vertex array object."
2702 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2706 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2707 "glVertexArrayAttribBinding");
2712 vertex_array_binding_divisor(struct gl_context
*ctx
,
2713 struct gl_vertex_array_object
*vao
,
2714 GLuint bindingIndex
, GLuint divisor
,
2717 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2719 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2720 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2724 /* The ARB_vertex_attrib_binding spec says:
2726 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2727 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2729 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2730 _mesa_error(ctx
, GL_INVALID_VALUE
,
2731 "%s(bindingindex=%u > "
2732 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2733 func
, bindingIndex
);
2737 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2742 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex
, GLuint divisor
)
2744 GET_CURRENT_CONTEXT(ctx
);
2745 vertex_binding_divisor(ctx
, ctx
->Array
.VAO
,
2746 VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2751 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2753 GET_CURRENT_CONTEXT(ctx
);
2755 /* The ARB_vertex_attrib_binding spec says:
2757 * "An INVALID_OPERATION error is generated if no vertex array object
2760 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2761 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2762 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2763 "glVertexBindingDivisor(No array object bound)");
2767 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2768 bindingIndex
, divisor
,
2769 "glVertexBindingDivisor");
2774 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj
, GLuint bindingIndex
,
2777 GET_CURRENT_CONTEXT(ctx
);
2779 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2780 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2785 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2788 struct gl_vertex_array_object
*vao
;
2789 GET_CURRENT_CONTEXT(ctx
);
2791 /* The ARB_direct_state_access specification says:
2793 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2794 * if <vaobj> is not [compatibility profile: zero or] the name of an
2795 * existing vertex array object."
2797 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2801 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2802 "glVertexArrayBindingDivisor");
2807 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2808 struct gl_array_attributes
*dst
,
2809 const struct gl_array_attributes
*src
)
2811 dst
->Size
= src
->Size
;
2812 dst
->Type
= src
->Type
;
2813 dst
->Format
= src
->Format
;
2814 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
2815 dst
->RelativeOffset
= src
->RelativeOffset
;
2816 dst
->Format
= src
->Format
;
2817 dst
->Integer
= src
->Integer
;
2818 dst
->Doubles
= src
->Doubles
;
2819 dst
->Normalized
= src
->Normalized
;
2820 dst
->Ptr
= src
->Ptr
;
2821 dst
->Enabled
= src
->Enabled
;
2822 dst
->_ElementSize
= src
->_ElementSize
;
2823 dst
->_EffBufferBindingIndex
= src
->_EffBufferBindingIndex
;
2824 dst
->_EffRelativeOffset
= src
->_EffRelativeOffset
;
2828 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2829 struct gl_vertex_buffer_binding
*dst
,
2830 const struct gl_vertex_buffer_binding
*src
)
2832 dst
->Offset
= src
->Offset
;
2833 dst
->Stride
= src
->Stride
;
2834 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2835 dst
->_BoundArrays
= src
->_BoundArrays
;
2836 dst
->_EffBoundArrays
= src
->_EffBoundArrays
;
2837 dst
->_EffOffset
= src
->_EffOffset
;
2839 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2843 * Print current vertex object/array info. For debug.
2846 _mesa_print_arrays(struct gl_context
*ctx
)
2848 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2850 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
2853 for (i
= 0; i
< VERT_ATTRIB_MAX
; ++i
) {
2854 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
2855 if (!array
->Enabled
)
2858 const struct gl_vertex_buffer_binding
*binding
=
2859 &vao
->BufferBinding
[array
->BufferBindingIndex
];
2860 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
2862 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2863 "Stride=%d, Buffer=%u(Size %lu)\n",
2864 gl_vert_attrib_name((gl_vert_attrib
)i
),
2865 array
->Ptr
, _mesa_enum_to_string(array
->Type
), array
->Size
,
2866 array
->_ElementSize
, binding
->Stride
, bo
->Name
,
2867 (unsigned long) bo
->Size
);
2873 * Initialize vertex array state for given context.
2876 _mesa_init_varray(struct gl_context
*ctx
)
2878 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2879 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2880 ctx
->Array
._EmptyVAO
= _mesa_new_vao(ctx
, ~0u);
2881 _mesa_reference_vao(ctx
, &ctx
->Array
._DrawVAO
, ctx
->Array
._EmptyVAO
);
2882 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2884 ctx
->Array
.Objects
= _mesa_NewHashTable();
2889 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2892 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2894 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2895 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2896 _mesa_delete_vao(ctx
, vao
);
2901 * Free vertex array state for given context.
2904 _mesa_free_varray_data(struct gl_context
*ctx
)
2906 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2907 _mesa_DeleteHashTable(ctx
->Array
.Objects
);