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 if (flush_vertices
) {
176 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
179 vao
->BufferBinding
[array
->BufferBindingIndex
]._BoundArrays
&= ~array_bit
;
180 vao
->BufferBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
182 array
->BufferBindingIndex
= bindingIndex
;
184 vao
->NewArrays
|= vao
->_Enabled
& array_bit
;
190 * Binds a buffer object to the vertex buffer binding point given by index,
191 * and sets the Offset and Stride fields.
194 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
195 struct gl_vertex_array_object
*vao
,
197 struct gl_buffer_object
*vbo
,
198 GLintptr offset
, GLsizei stride
, bool flush_vertices
)
200 assert(index
< ARRAY_SIZE(vao
->BufferBinding
));
201 assert(!vao
->SharedAndImmutable
);
202 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
204 if (binding
->BufferObj
!= vbo
||
205 binding
->Offset
!= offset
||
206 binding
->Stride
!= stride
) {
207 if (flush_vertices
) {
208 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
211 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
213 binding
->Offset
= offset
;
214 binding
->Stride
= stride
;
216 if (!_mesa_is_bufferobj(vbo
))
217 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
219 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
221 vao
->NewArrays
|= vao
->_Enabled
& binding
->_BoundArrays
;
227 * Sets the InstanceDivisor field in the vertex buffer binding point
228 * given by bindingIndex.
231 vertex_binding_divisor(struct gl_context
*ctx
,
232 struct gl_vertex_array_object
*vao
,
236 struct gl_vertex_buffer_binding
*binding
=
237 &vao
->BufferBinding
[bindingIndex
];
238 assert(!vao
->SharedAndImmutable
);
240 if (binding
->InstanceDivisor
!= divisor
) {
241 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
242 binding
->InstanceDivisor
= divisor
;
243 vao
->NewArrays
|= vao
->_Enabled
& binding
->_BoundArrays
;
249 * Examine the API profile and extensions to determine which types are legal
250 * for vertex arrays. This is called once from update_array_format().
253 get_legal_types_mask(const struct gl_context
*ctx
)
255 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
257 if (_mesa_is_gles(ctx
)) {
258 legalTypesMask
&= ~(FIXED_GL_BIT
|
260 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
262 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
263 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
264 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
265 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
266 * quite as trivial as we'd like because it uses a different enum value
267 * for GL_HALF_FLOAT_OES.
269 if (ctx
->Version
< 30) {
270 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
272 UNSIGNED_INT_2_10_10_10_REV_BIT
|
273 INT_2_10_10_10_REV_BIT
);
275 if (!_mesa_has_OES_vertex_half_float(ctx
))
276 legalTypesMask
&= ~HALF_BIT
;
280 legalTypesMask
&= ~FIXED_ES_BIT
;
282 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
283 legalTypesMask
&= ~FIXED_GL_BIT
;
285 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
286 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
287 INT_2_10_10_10_REV_BIT
);
289 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
290 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
293 return legalTypesMask
;
297 get_array_format(const struct gl_context
*ctx
, GLint sizeMax
, GLint
*size
)
299 GLenum format
= GL_RGBA
;
301 /* Do size parameter checking.
302 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
303 * must be handled specially.
305 if (ctx
->Extensions
.EXT_vertex_array_bgra
&& sizeMax
== BGRA_OR_4
&&
316 * \param attrib The index of the attribute array
317 * \param size Components per element (1, 2, 3 or 4)
318 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
319 * \param format Either GL_RGBA or GL_BGRA.
320 * \param normalized Whether integer types are converted to floats in [-1, 1]
321 * \param integer Integer-valued values (will not be normalized to [-1, 1])
322 * \param doubles Double values not reduced to floats
323 * \param relativeOffset Offset of the first element relative to the binding
325 * \param flush_verties Should \c FLUSH_VERTICES be invoked before updating
329 _mesa_update_array_format(struct gl_context
*ctx
,
330 struct gl_vertex_array_object
*vao
,
331 gl_vert_attrib attrib
, GLint size
, GLenum type
,
332 GLenum format
, GLboolean normalized
,
333 GLboolean integer
, GLboolean doubles
,
334 GLuint relativeOffset
)
336 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
339 assert(!vao
->SharedAndImmutable
);
342 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
343 assert(elementSize
!= -1);
347 array
->Format
= format
;
348 array
->Normalized
= normalized
;
349 array
->Integer
= integer
;
350 array
->Doubles
= doubles
;
351 array
->RelativeOffset
= relativeOffset
;
352 array
->_ElementSize
= elementSize
;
354 vao
->NewArrays
|= vao
->_Enabled
& VERT_BIT(attrib
);
355 ctx
->NewState
|= _NEW_ARRAY
;
359 * Does error checking of the format in an attrib array.
361 * Called by *Pointer() and VertexAttrib*Format().
363 * \param func Name of calling function used for error reporting
364 * \param attrib The index of the attribute array
365 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
366 * \param sizeMin Min allowable size value
367 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
368 * \param size Components per element (1, 2, 3 or 4)
369 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
370 * \param normalized Whether integer types are converted to floats in [-1, 1]
371 * \param integer Integer-valued values (will not be normalized to [-1, 1])
372 * \param doubles Double values not reduced to floats
373 * \param relativeOffset Offset of the first element relative to the binding offset.
374 * \return bool True if validation is successful, False otherwise.
377 validate_array_format(struct gl_context
*ctx
, const char *func
,
378 struct gl_vertex_array_object
*vao
,
379 GLuint attrib
, GLbitfield legalTypesMask
,
380 GLint sizeMin
, GLint sizeMax
,
381 GLint size
, GLenum type
, GLboolean normalized
,
382 GLboolean integer
, GLboolean doubles
,
383 GLuint relativeOffset
, GLenum format
)
387 /* at most, one of these bools can be true */
388 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
390 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
391 /* Compute the LegalTypesMask only once, unless the context API has
392 * changed, in which case we want to compute it again. We can't do this
393 * in _mesa_init_varrays() below because extensions are not yet enabled
396 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
397 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
400 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
402 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
403 /* BGRA ordering is not supported in ES contexts.
408 typeBit
= type_to_bit(ctx
, type
);
409 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
410 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
411 func
, _mesa_enum_to_string(type
));
415 if (format
== GL_BGRA
) {
416 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
418 * "An INVALID_OPERATION error is generated under any of the following
421 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
422 * or UNSIGNED_INT_2_10_10_10_REV;
424 * • size is BGRA and normalized is FALSE;"
426 bool bgra_error
= false;
428 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
429 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
430 type
!= GL_INT_2_10_10_10_REV
&&
431 type
!= GL_UNSIGNED_BYTE
)
433 } else if (type
!= GL_UNSIGNED_BYTE
)
437 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
438 func
, _mesa_enum_to_string(type
));
443 _mesa_error(ctx
, GL_INVALID_OPERATION
,
444 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
448 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
449 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
453 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
454 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
455 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
456 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
460 /* The ARB_vertex_attrib_binding_spec says:
462 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
463 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
465 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
466 _mesa_error(ctx
, GL_INVALID_VALUE
,
467 "%s(relativeOffset=%d > "
468 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
469 func
, relativeOffset
);
473 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
474 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
475 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
483 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
485 * \param func name of calling function used for error reporting
486 * \param attrib the attribute array index to update
487 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
488 * \param sizeMin min allowable size value
489 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
490 * \param size components per element (1, 2, 3 or 4)
491 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
492 * \param stride stride between elements, in elements
493 * \param normalized are integer types converted to floats in [-1, 1]?
494 * \param integer integer-valued values (will not be normalized to [-1,1])
495 * \param doubles Double values not reduced to floats
496 * \param ptr the address (or offset inside VBO) of the array data
499 validate_array(struct gl_context
*ctx
, const char *func
,
500 GLuint attrib
, GLbitfield legalTypesMask
,
501 GLint sizeMin
, GLint sizeMax
,
502 GLint size
, GLenum type
, GLsizei stride
,
503 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
506 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
508 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
510 * "Client vertex arrays - all vertex array attribute pointers must
511 * refer to buffer objects (section 2.9.2). The default vertex array
512 * object (the name zero) is also deprecated. Calling
513 * VertexAttribPointer when no buffer object or no vertex array object
514 * is bound will generate an INVALID_OPERATION error..."
516 * The check for VBOs is handled below.
518 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
519 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
525 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
529 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
530 stride
> ctx
->Const
.MaxVertexAttribStride
) {
531 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
532 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
536 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
538 * "An INVALID_OPERATION error is generated under any of the following
543 * * any of the *Pointer commands specifying the location and
544 * organization of vertex array data are called while zero is bound
545 * to the ARRAY_BUFFER buffer object binding point (see section
546 * 2.9.6), and the pointer argument is not NULL."
548 if (ptr
!= NULL
&& vao
!= ctx
->Array
.DefaultVAO
&&
549 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
550 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
557 validate_array_and_format(struct gl_context
*ctx
, const char *func
,
558 GLuint attrib
, GLbitfield legalTypes
,
559 GLint sizeMin
, GLint sizeMax
,
560 GLint size
, GLenum type
, GLsizei stride
,
561 GLboolean normalized
, GLboolean integer
,
562 GLboolean doubles
, GLenum format
, const GLvoid
*ptr
,
563 struct gl_vertex_array_object
*vao
)
565 validate_array(ctx
, func
, attrib
, legalTypes
, sizeMin
, sizeMax
, size
,
566 type
, stride
, normalized
, integer
, doubles
, ptr
);
568 return validate_array_format(ctx
, func
, vao
, attrib
, legalTypes
, sizeMin
,
569 sizeMax
, size
, type
, normalized
, integer
,
575 * Update state for glVertex/Color/TexCoord/...Pointer functions.
577 * \param attrib the attribute array index to update
578 * \param format Either GL_RGBA or GL_BGRA.
579 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
580 * \param size components per element (1, 2, 3 or 4)
581 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
582 * \param stride stride between elements, in elements
583 * \param normalized are integer types converted to floats in [-1, 1]?
584 * \param integer integer-valued values (will not be normalized to [-1,1])
585 * \param doubles Double values not reduced to floats
586 * \param ptr the address (or offset inside VBO) of the array data
589 update_array(struct gl_context
*ctx
,
590 GLuint attrib
, GLenum format
,
592 GLint size
, GLenum type
, GLsizei stride
,
593 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
596 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
598 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
599 normalized
, integer
, doubles
, 0);
601 /* Reset the vertex attrib binding */
602 _mesa_vertex_attrib_binding(ctx
, vao
, attrib
, attrib
, true);
604 /* The Stride and Ptr fields are not set by update_array_format() */
605 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attrib
];
606 array
->Stride
= stride
;
607 /* For updating the pointer we would need to add the vao->NewArrays flag
608 * to the VAO. But but that is done already unconditionally in
609 * _mesa_update_array_format called above.
611 assert((vao
->NewArrays
| ~vao
->_Enabled
) & VERT_BIT(attrib
));
614 /* Update the vertex buffer binding */
615 GLsizei effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
616 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
617 ctx
->Array
.ArrayBufferObj
, (GLintptr
) ptr
,
618 effectiveStride
, true);
622 _mesa_VertexPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
625 GET_CURRENT_CONTEXT(ctx
);
626 FLUSH_VERTICES(ctx
, 0);
628 update_array(ctx
, VERT_ATTRIB_POS
, GL_RGBA
, 4, size
, type
, stride
,
629 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
634 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
636 GET_CURRENT_CONTEXT(ctx
);
638 FLUSH_VERTICES(ctx
, 0);
640 GLenum format
= GL_RGBA
;
641 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
642 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
643 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
644 DOUBLE_BIT
| HALF_BIT
|
645 UNSIGNED_INT_2_10_10_10_REV_BIT
|
646 INT_2_10_10_10_REV_BIT
);
648 if (!validate_array_and_format(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
649 legalTypes
, 2, 4, size
, type
, stride
,
650 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
,
651 ptr
, ctx
->Array
.VAO
))
654 update_array(ctx
, VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
655 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
660 _mesa_NormalPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
662 GET_CURRENT_CONTEXT(ctx
);
663 FLUSH_VERTICES(ctx
, 0);
665 update_array(ctx
, VERT_ATTRIB_NORMAL
, GL_RGBA
, 3, 3, type
, stride
, GL_TRUE
,
666 GL_FALSE
, GL_FALSE
, ptr
);
671 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
673 GET_CURRENT_CONTEXT(ctx
);
675 FLUSH_VERTICES(ctx
, 0);
677 GLenum format
= GL_RGBA
;
678 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
679 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
680 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
681 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
682 UNSIGNED_INT_2_10_10_10_REV_BIT
|
683 INT_2_10_10_10_REV_BIT
);
685 if (!validate_array_and_format(ctx
, "glNormalPointer",
686 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
687 type
, stride
, GL_TRUE
, GL_FALSE
,
688 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
691 update_array(ctx
, VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
692 GL_FALSE
, GL_FALSE
, ptr
);
697 _mesa_ColorPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
700 GET_CURRENT_CONTEXT(ctx
);
701 FLUSH_VERTICES(ctx
, 0);
703 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
704 update_array(ctx
, VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
705 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
710 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
712 GET_CURRENT_CONTEXT(ctx
);
713 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
715 FLUSH_VERTICES(ctx
, 0);
717 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
718 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
719 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
720 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
721 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
722 INT_BIT
| UNSIGNED_INT_BIT
|
723 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
724 UNSIGNED_INT_2_10_10_10_REV_BIT
|
725 INT_2_10_10_10_REV_BIT
);
727 if (!validate_array_and_format(ctx
, "glColorPointer",
728 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
729 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
730 GL_FALSE
, GL_FALSE
, format
, ptr
,
734 update_array(ctx
, VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
735 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
740 _mesa_FogCoordPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
742 GET_CURRENT_CONTEXT(ctx
);
743 FLUSH_VERTICES(ctx
, 0);
745 update_array(ctx
, VERT_ATTRIB_FOG
, GL_RGBA
, 1, 1, type
, stride
, GL_FALSE
,
746 GL_FALSE
, GL_FALSE
, ptr
);
751 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
753 GET_CURRENT_CONTEXT(ctx
);
755 FLUSH_VERTICES(ctx
, 0);
757 GLenum format
= GL_RGBA
;
758 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
760 if (!validate_array_and_format(ctx
, "glFogCoordPointer",
761 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
762 type
, stride
, GL_FALSE
, GL_FALSE
,
763 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
766 update_array(ctx
, VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
767 GL_FALSE
, GL_FALSE
, ptr
);
772 _mesa_IndexPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
774 GET_CURRENT_CONTEXT(ctx
);
775 FLUSH_VERTICES(ctx
, 0);
777 update_array(ctx
, VERT_ATTRIB_COLOR_INDEX
, GL_RGBA
, 1, 1, type
, stride
,
778 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
783 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
785 GET_CURRENT_CONTEXT(ctx
);
787 FLUSH_VERTICES(ctx
, 0);
789 GLenum format
= GL_RGBA
;
790 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
791 FLOAT_BIT
| DOUBLE_BIT
);
793 if (!validate_array_and_format(ctx
, "glIndexPointer",
794 VERT_ATTRIB_COLOR_INDEX
,
795 legalTypes
, 1, 1, 1, type
, stride
,
796 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
,
797 ptr
, ctx
->Array
.VAO
))
800 update_array(ctx
, VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
801 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
806 _mesa_SecondaryColorPointer_no_error(GLint size
, GLenum type
,
807 GLsizei stride
, const GLvoid
*ptr
)
809 GET_CURRENT_CONTEXT(ctx
);
810 FLUSH_VERTICES(ctx
, 0);
812 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
813 update_array(ctx
, VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
814 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
819 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
820 GLsizei stride
, const GLvoid
*ptr
)
822 GET_CURRENT_CONTEXT(ctx
);
824 FLUSH_VERTICES(ctx
, 0);
826 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
827 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
828 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
829 INT_BIT
| UNSIGNED_INT_BIT
|
830 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
831 UNSIGNED_INT_2_10_10_10_REV_BIT
|
832 INT_2_10_10_10_REV_BIT
);
834 if (!validate_array_and_format(ctx
, "glSecondaryColorPointer",
835 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
836 BGRA_OR_4
, size
, type
, stride
,
837 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, ptr
,
841 update_array(ctx
, VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
842 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
847 _mesa_TexCoordPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
850 GET_CURRENT_CONTEXT(ctx
);
851 const GLuint unit
= ctx
->Array
.ActiveTexture
;
852 FLUSH_VERTICES(ctx
, 0);
854 update_array(ctx
, VERT_ATTRIB_TEX(unit
), GL_RGBA
, 4, size
, type
,
855 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
860 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
863 GET_CURRENT_CONTEXT(ctx
);
864 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
865 const GLuint unit
= ctx
->Array
.ActiveTexture
;
867 FLUSH_VERTICES(ctx
, 0);
869 GLenum format
= GL_RGBA
;
870 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
871 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
872 : (SHORT_BIT
| INT_BIT
|
873 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
874 UNSIGNED_INT_2_10_10_10_REV_BIT
|
875 INT_2_10_10_10_REV_BIT
);
877 if (!validate_array_and_format(ctx
, "glTexCoordPointer",
878 VERT_ATTRIB_TEX(unit
), legalTypes
,
879 sizeMin
, 4, size
, type
, stride
,
880 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
,
884 update_array(ctx
, VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
885 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
890 _mesa_EdgeFlagPointer_no_error(GLsizei stride
, const GLvoid
*ptr
)
892 /* this is the same type that glEdgeFlag uses */
893 const GLboolean integer
= GL_FALSE
;
894 GET_CURRENT_CONTEXT(ctx
);
895 FLUSH_VERTICES(ctx
, 0);
897 update_array(ctx
, VERT_ATTRIB_EDGEFLAG
, GL_RGBA
, 1, 1, GL_UNSIGNED_BYTE
,
898 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
903 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
905 /* this is the same type that glEdgeFlag uses */
906 const GLboolean integer
= GL_FALSE
;
907 GET_CURRENT_CONTEXT(ctx
);
909 FLUSH_VERTICES(ctx
, 0);
911 GLenum format
= GL_RGBA
;
912 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
914 if (!validate_array_and_format(ctx
, "glEdgeFlagPointer",
915 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
916 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
917 GL_FALSE
, integer
, GL_FALSE
, format
, ptr
,
921 update_array(ctx
, VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
922 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
927 _mesa_PointSizePointerOES_no_error(GLenum type
, GLsizei stride
,
930 GET_CURRENT_CONTEXT(ctx
);
931 FLUSH_VERTICES(ctx
, 0);
933 update_array(ctx
, VERT_ATTRIB_POINT_SIZE
, GL_RGBA
, 1, 1, type
, stride
,
934 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
939 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
941 GET_CURRENT_CONTEXT(ctx
);
943 FLUSH_VERTICES(ctx
, 0);
945 GLenum format
= GL_RGBA
;
946 if (ctx
->API
!= API_OPENGLES
) {
947 _mesa_error(ctx
, GL_INVALID_OPERATION
,
948 "glPointSizePointer(ES 1.x only)");
952 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
954 if (!validate_array_and_format(ctx
, "glPointSizePointer",
955 VERT_ATTRIB_POINT_SIZE
, legalTypes
,
956 1, 1, 1, type
, stride
, GL_FALSE
, GL_FALSE
,
957 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
960 update_array(ctx
, VERT_ATTRIB_POINT_SIZE
, format
, 1, 1, type
, stride
,
961 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
966 _mesa_VertexAttribPointer_no_error(GLuint index
, GLint size
, GLenum type
,
967 GLboolean normalized
,
968 GLsizei stride
, const GLvoid
*ptr
)
970 GET_CURRENT_CONTEXT(ctx
);
972 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
973 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
974 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
979 * Set a generic vertex attribute array.
980 * Note that these arrays DO NOT alias the conventional GL vertex arrays
981 * (position, normal, color, fog, texcoord, etc).
984 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
985 GLboolean normalized
,
986 GLsizei stride
, const GLvoid
*ptr
)
988 GET_CURRENT_CONTEXT(ctx
);
990 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
991 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
992 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(idx)");
996 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
997 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
998 INT_BIT
| UNSIGNED_INT_BIT
|
999 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1000 FIXED_ES_BIT
| FIXED_GL_BIT
|
1001 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1002 INT_2_10_10_10_REV_BIT
|
1003 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1005 if (!validate_array_and_format(ctx
, "glVertexAttribPointer",
1006 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1007 1, BGRA_OR_4
, size
, type
, stride
,
1008 normalized
, GL_FALSE
, GL_FALSE
, format
,
1009 ptr
, ctx
->Array
.VAO
))
1012 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1013 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
1018 _mesa_VertexAttribIPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1019 GLsizei stride
, const GLvoid
*ptr
)
1021 const GLboolean normalized
= GL_FALSE
;
1022 const GLboolean integer
= GL_TRUE
;
1023 GET_CURRENT_CONTEXT(ctx
);
1025 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1026 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1031 * GL_EXT_gpu_shader4 / GL 3.0.
1032 * Set an integer-valued vertex attribute array.
1033 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1034 * (position, normal, color, fog, texcoord, etc).
1037 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
1038 GLsizei stride
, const GLvoid
*ptr
)
1040 const GLboolean normalized
= GL_FALSE
;
1041 const GLboolean integer
= GL_TRUE
;
1042 GET_CURRENT_CONTEXT(ctx
);
1044 GLenum format
= GL_RGBA
;
1045 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1046 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
1050 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1051 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1052 INT_BIT
| UNSIGNED_INT_BIT
);
1054 if (!validate_array_and_format(ctx
, "glVertexAttribIPointer",
1055 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1056 1, 4, size
, type
, stride
,
1057 normalized
, integer
, GL_FALSE
, format
,
1058 ptr
, ctx
->Array
.VAO
))
1061 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1062 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1067 _mesa_VertexAttribLPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1068 GLsizei stride
, const GLvoid
*ptr
)
1070 GET_CURRENT_CONTEXT(ctx
);
1072 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1073 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1078 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
1079 GLsizei stride
, const GLvoid
*ptr
)
1081 GET_CURRENT_CONTEXT(ctx
);
1083 GLenum format
= GL_RGBA
;
1084 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1085 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
1089 const GLbitfield legalTypes
= DOUBLE_BIT
;
1091 if (!validate_array_and_format(ctx
, "glVertexAttribLPointer",
1092 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1093 1, 4, size
, type
, stride
,
1094 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
,
1095 ptr
, ctx
->Array
.VAO
))
1098 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1099 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1104 _mesa_enable_vertex_array_attrib(struct gl_context
*ctx
,
1105 struct gl_vertex_array_object
*vao
,
1106 gl_vert_attrib attrib
, bool flush_vertices
)
1108 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
1109 assert(!vao
->SharedAndImmutable
);
1111 if (!vao
->VertexAttrib
[attrib
].Enabled
) {
1112 /* was disabled, now being enabled */
1113 if (flush_vertices
) {
1114 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1117 vao
->VertexAttrib
[attrib
].Enabled
= GL_TRUE
;
1118 const GLbitfield array_bit
= VERT_BIT(attrib
);
1119 vao
->_Enabled
|= array_bit
;
1120 vao
->NewArrays
|= array_bit
;
1122 /* Update the map mode if needed */
1123 if (array_bit
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1124 update_attribute_map_mode(ctx
, vao
);
1129 enable_vertex_array_attrib(struct gl_context
*ctx
,
1130 struct gl_vertex_array_object
*vao
,
1134 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1135 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
1139 _mesa_enable_vertex_array_attrib(ctx
, vao
,
1140 VERT_ATTRIB_GENERIC(index
), true);
1145 _mesa_EnableVertexAttribArray(GLuint index
)
1147 GET_CURRENT_CONTEXT(ctx
);
1148 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
1149 "glEnableVertexAttribArray");
1154 _mesa_EnableVertexAttribArray_no_error(GLuint index
)
1156 GET_CURRENT_CONTEXT(ctx
);
1157 _mesa_enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1158 VERT_ATTRIB_GENERIC(index
), true);
1163 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1165 GET_CURRENT_CONTEXT(ctx
);
1166 struct gl_vertex_array_object
*vao
;
1168 /* The ARB_direct_state_access specification says:
1170 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1171 * and DisableVertexArrayAttrib if <vaobj> is not
1172 * [compatibility profile: zero or] the name of an existing vertex
1175 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
1179 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
1184 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1186 GET_CURRENT_CONTEXT(ctx
);
1187 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1188 _mesa_enable_vertex_array_attrib(ctx
, vao
,
1189 VERT_ATTRIB_GENERIC(index
), true);
1194 _mesa_disable_vertex_array_attrib(struct gl_context
*ctx
,
1195 struct gl_vertex_array_object
*vao
,
1196 gl_vert_attrib attrib
, bool flush_vertices
)
1198 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
1199 assert(!vao
->SharedAndImmutable
);
1201 if (vao
->VertexAttrib
[attrib
].Enabled
) {
1202 /* was enabled, now being disabled */
1203 if (flush_vertices
) {
1204 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1207 vao
->VertexAttrib
[attrib
].Enabled
= GL_FALSE
;
1208 const GLbitfield array_bit
= VERT_BIT(attrib
);
1209 vao
->_Enabled
&= ~array_bit
;
1210 vao
->NewArrays
|= array_bit
;
1212 /* Update the map mode if needed */
1213 if (array_bit
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1214 update_attribute_map_mode(ctx
, vao
);
1220 _mesa_DisableVertexAttribArray(GLuint index
)
1222 GET_CURRENT_CONTEXT(ctx
);
1224 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1225 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexAttribArray(index)");
1229 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1230 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
, true);
1235 _mesa_DisableVertexAttribArray_no_error(GLuint index
)
1237 GET_CURRENT_CONTEXT(ctx
);
1238 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1239 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
, true);
1244 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1246 GET_CURRENT_CONTEXT(ctx
);
1247 struct gl_vertex_array_object
*vao
;
1249 /* The ARB_direct_state_access specification says:
1251 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1252 * and DisableVertexArrayAttrib if <vaobj> is not
1253 * [compatibility profile: zero or] the name of an existing vertex
1256 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
1260 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1261 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
1265 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1266 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
, true);
1271 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1273 GET_CURRENT_CONTEXT(ctx
);
1274 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1275 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1276 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
, true);
1281 * Return info for a vertex attribute array (no alias with legacy
1282 * vertex attributes (pos, normal, color, etc)). This function does
1283 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
1286 get_vertex_array_attrib(struct gl_context
*ctx
,
1287 const struct gl_vertex_array_object
*vao
,
1288 GLuint index
, GLenum pname
,
1291 const struct gl_array_attributes
*array
;
1293 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1294 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
1298 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
1300 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
1303 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
1304 return array
->Enabled
;
1305 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
1306 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
1307 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
1308 return array
->Stride
;
1309 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
1311 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
1312 return array
->Normalized
;
1313 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
1314 return vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
->Name
;
1315 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
1316 if ((_mesa_is_desktop_gl(ctx
)
1317 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
1318 || _mesa_is_gles3(ctx
)) {
1319 return array
->Integer
;
1322 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
1323 if (_mesa_is_desktop_gl(ctx
)) {
1324 return array
->Doubles
;
1327 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
1328 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
1329 || _mesa_is_gles3(ctx
)) {
1330 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
1333 case GL_VERTEX_ATTRIB_BINDING
:
1334 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1335 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
1338 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
1339 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1340 return array
->RelativeOffset
;
1344 ; /* fall-through */
1348 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
1353 static const GLfloat
*
1354 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
1357 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
1358 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
1362 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1363 _mesa_error(ctx
, GL_INVALID_VALUE
,
1364 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
1368 assert(VERT_ATTRIB_GENERIC(index
) <
1369 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1371 FLUSH_CURRENT(ctx
, 0);
1372 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
1376 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
1378 GET_CURRENT_CONTEXT(ctx
);
1380 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1381 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
1387 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1389 "glGetVertexAttribfv");
1395 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1397 GET_CURRENT_CONTEXT(ctx
);
1399 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1400 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
1402 params
[0] = (GLdouble
) v
[0];
1403 params
[1] = (GLdouble
) v
[1];
1404 params
[2] = (GLdouble
) v
[2];
1405 params
[3] = (GLdouble
) v
[3];
1409 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1411 "glGetVertexAttribdv");
1416 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1418 GET_CURRENT_CONTEXT(ctx
);
1420 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1422 (const GLdouble
*)get_current_attrib(ctx
, index
,
1423 "glGetVertexAttribLdv");
1432 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1434 "glGetVertexAttribLdv");
1439 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1441 GET_CURRENT_CONTEXT(ctx
);
1443 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1444 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1446 /* XXX should floats in[0,1] be scaled to full int range? */
1447 params
[0] = (GLint
) v
[0];
1448 params
[1] = (GLint
) v
[1];
1449 params
[2] = (GLint
) v
[2];
1450 params
[3] = (GLint
) v
[3];
1454 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1456 "glGetVertexAttribiv");
1461 _mesa_GetVertexAttribLui64vARB(GLuint index
, GLenum pname
, GLuint64EXT
*params
)
1463 GET_CURRENT_CONTEXT(ctx
);
1465 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1467 (const GLuint64
*)get_current_attrib(ctx
, index
,
1468 "glGetVertexAttribLui64vARB");
1477 params
[0] = (GLuint64
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1479 "glGetVertexAttribLui64vARB");
1486 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1488 GET_CURRENT_CONTEXT(ctx
);
1490 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1491 const GLint
*v
= (const GLint
*)
1492 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1498 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1500 "glGetVertexAttribIiv");
1507 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1509 GET_CURRENT_CONTEXT(ctx
);
1511 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1512 const GLuint
*v
= (const GLuint
*)
1513 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1519 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1521 "glGetVertexAttribIuiv");
1527 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1529 GET_CURRENT_CONTEXT(ctx
);
1531 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1532 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1536 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1537 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1541 assert(VERT_ATTRIB_GENERIC(index
) <
1542 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1544 *pointer
= (GLvoid
*)
1545 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1549 /** ARB_direct_state_access */
1551 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1552 GLenum pname
, GLint
*params
)
1554 GET_CURRENT_CONTEXT(ctx
);
1555 struct gl_vertex_array_object
*vao
;
1557 /* The ARB_direct_state_access specification says:
1559 * "An INVALID_OPERATION error is generated if <vaobj> is not
1560 * [compatibility profile: zero or] the name of an existing
1561 * vertex array object."
1563 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexediv");
1567 /* The ARB_direct_state_access specification says:
1569 * "For GetVertexArrayIndexediv, <pname> must be one of
1570 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1571 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1572 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1573 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1574 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1578 * "Add GetVertexArrayIndexediv in 'Get Command' for
1579 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1580 * VERTEX_ATTRIB_BINDING,
1581 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1582 * VERTEX_BINDING_OFFSET, and
1583 * VERTEX_BINDING_STRIDE states"
1585 * The only parameter name common to both lists is
1586 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1587 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1588 * pretty clear however that the intent is that it should be possible
1589 * to query all vertex attrib and binding states that can be set with
1593 case GL_VERTEX_BINDING_OFFSET
:
1594 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1596 case GL_VERTEX_BINDING_STRIDE
:
1597 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1599 case GL_VERTEX_BINDING_DIVISOR
:
1600 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1602 case GL_VERTEX_BINDING_BUFFER
:
1603 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1606 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1607 "glGetVertexArrayIndexediv");
1614 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1615 GLenum pname
, GLint64
*params
)
1617 GET_CURRENT_CONTEXT(ctx
);
1618 struct gl_vertex_array_object
*vao
;
1620 /* The ARB_direct_state_access specification says:
1622 * "An INVALID_OPERATION error is generated if <vaobj> is not
1623 * [compatibility profile: zero or] the name of an existing
1624 * vertex array object."
1626 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1630 /* The ARB_direct_state_access specification says:
1632 * "For GetVertexArrayIndexed64iv, <pname> must be
1633 * VERTEX_BINDING_OFFSET."
1637 * "An INVALID_ENUM error is generated if <pname> is not one of
1638 * the valid values listed above for the corresponding command."
1640 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1641 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1642 "pname != GL_VERTEX_BINDING_OFFSET)");
1646 /* The ARB_direct_state_access specification says:
1648 * "An INVALID_VALUE error is generated if <index> is greater than
1649 * or equal to the value of MAX_VERTEX_ATTRIBS."
1651 * Since the index refers to a buffer binding in this case, the intended
1652 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1653 * required to be the same, so in practice this doesn't matter.
1655 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1656 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1657 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1658 index
, ctx
->Const
.MaxVertexAttribBindings
);
1662 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1667 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1668 GLsizei count
, const GLvoid
*ptr
)
1671 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1676 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1680 _mesa_NormalPointer(type
, stride
, ptr
);
1685 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1689 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1694 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1698 _mesa_IndexPointer(type
, stride
, ptr
);
1703 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1704 GLsizei count
, const GLvoid
*ptr
)
1707 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1712 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1715 _mesa_EdgeFlagPointer(stride
, ptr
);
1720 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1722 GET_CURRENT_CONTEXT(ctx
);
1723 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1724 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1725 GLenum ctype
= 0; /* color type */
1726 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1727 const GLint toffset
= 0; /* always zero */
1728 GLint defstride
; /* default stride */
1731 FLUSH_VERTICES(ctx
, 0);
1733 f
= sizeof(GLfloat
);
1734 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1737 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1743 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1744 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1749 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1750 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1755 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1756 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1757 ctype
= GL_UNSIGNED_BYTE
;
1760 defstride
= c
+ 2*f
;
1763 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1764 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1765 ctype
= GL_UNSIGNED_BYTE
;
1768 defstride
= c
+ 3*f
;
1771 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1772 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1779 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1780 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1785 case GL_C4F_N3F_V3F
:
1786 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1787 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1795 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1796 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1801 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1802 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1806 case GL_T2F_C4UB_V3F
:
1807 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1808 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1809 ctype
= GL_UNSIGNED_BYTE
;
1814 case GL_T2F_C3F_V3F
:
1815 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1816 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1822 case GL_T2F_N3F_V3F
:
1823 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1824 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1829 case GL_T2F_C4F_N3F_V3F
:
1830 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1831 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1838 case GL_T4F_C4F_N3F_V4F
:
1839 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1840 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1848 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1856 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1857 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1858 /* XXX also disable secondary color and generic arrays? */
1862 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1863 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1864 (GLubyte
*) pointer
+ toffset
);
1867 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1872 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1873 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1874 (GLubyte
*) pointer
+ coffset
);
1877 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1883 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1884 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1887 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1891 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1892 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1893 (GLubyte
*) pointer
+ voffset
);
1898 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1900 GET_CURRENT_CONTEXT(ctx
);
1902 FLUSH_VERTICES(ctx
, 0);
1904 if (MESA_VERBOSE
& VERBOSE_API
)
1905 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1908 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1912 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1915 if (ctx
->Array
.LockCount
!= 0) {
1916 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1920 ctx
->Array
.LockFirst
= first
;
1921 ctx
->Array
.LockCount
= count
;
1923 ctx
->NewState
|= _NEW_ARRAY
;
1928 _mesa_UnlockArraysEXT( void )
1930 GET_CURRENT_CONTEXT(ctx
);
1932 FLUSH_VERTICES(ctx
, 0);
1934 if (MESA_VERBOSE
& VERBOSE_API
)
1935 _mesa_debug(ctx
, "glUnlockArrays\n");
1937 if (ctx
->Array
.LockCount
== 0) {
1938 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1942 ctx
->Array
.LockFirst
= 0;
1943 ctx
->Array
.LockCount
= 0;
1944 ctx
->NewState
|= _NEW_ARRAY
;
1948 /* GL_IBM_multimode_draw_arrays */
1950 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1951 const GLsizei
* count
,
1952 GLsizei primcount
, GLint modestride
)
1954 GET_CURRENT_CONTEXT(ctx
);
1957 FLUSH_VERTICES(ctx
, 0);
1959 for ( i
= 0 ; i
< primcount
; i
++ ) {
1960 if ( count
[i
] > 0 ) {
1961 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1962 CALL_DrawArrays(ctx
->CurrentServerDispatch
, ( m
, first
[i
], count
[i
] ));
1968 /* GL_IBM_multimode_draw_arrays */
1970 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1971 GLenum type
, const GLvoid
* const * indices
,
1972 GLsizei primcount
, GLint modestride
)
1974 GET_CURRENT_CONTEXT(ctx
);
1977 FLUSH_VERTICES(ctx
, 0);
1979 /* XXX not sure about ARB_vertex_buffer_object handling here */
1981 for ( i
= 0 ; i
< primcount
; i
++ ) {
1982 if ( count
[i
] > 0 ) {
1983 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1984 CALL_DrawElements(ctx
->CurrentServerDispatch
, ( m
, count
[i
], type
,
1992 primitive_restart_index(struct gl_context
*ctx
, GLuint index
)
1994 if (ctx
->Array
.RestartIndex
!= index
) {
1995 FLUSH_VERTICES(ctx
, 0);
1996 ctx
->Array
.RestartIndex
= index
;
2002 * GL_NV_primitive_restart and GL 3.1
2005 _mesa_PrimitiveRestartIndex_no_error(GLuint index
)
2007 GET_CURRENT_CONTEXT(ctx
);
2008 primitive_restart_index(ctx
, index
);
2013 _mesa_PrimitiveRestartIndex(GLuint index
)
2015 GET_CURRENT_CONTEXT(ctx
);
2017 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
2018 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
2022 primitive_restart_index(ctx
, index
);
2027 _mesa_VertexAttribDivisor_no_error(GLuint index
, GLuint divisor
)
2029 GET_CURRENT_CONTEXT(ctx
);
2031 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2032 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2034 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2036 /* The ARB_vertex_attrib_binding spec says:
2040 * void VertexAttribDivisor(uint index, uint divisor);
2042 * is equivalent to (assuming no errors are generated):
2044 * VertexAttribBinding(index, index);
2045 * VertexBindingDivisor(index, divisor);"
2047 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
, true);
2048 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2053 * See GL_ARB_instanced_arrays.
2054 * Note that the instance divisor only applies to generic arrays, not
2055 * the legacy vertex arrays.
2058 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
2060 GET_CURRENT_CONTEXT(ctx
);
2062 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2063 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2065 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2066 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
2070 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2071 _mesa_error(ctx
, GL_INVALID_VALUE
,
2072 "glVertexAttribDivisor(index = %u)", index
);
2076 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2078 /* The ARB_vertex_attrib_binding spec says:
2082 * void VertexAttribDivisor(uint index, uint divisor);
2084 * is equivalent to (assuming no errors are generated):
2086 * VertexAttribBinding(index, index);
2087 * VertexBindingDivisor(index, divisor);"
2089 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
, true);
2090 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2094 static ALWAYS_INLINE
void
2095 vertex_array_vertex_buffer(struct gl_context
*ctx
,
2096 struct gl_vertex_array_object
*vao
,
2097 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2098 GLsizei stride
, bool no_error
, const char *func
)
2100 struct gl_buffer_object
*vbo
;
2102 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
2103 vbo
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
2104 } else if (buffer
!= 0) {
2105 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
2107 if (!no_error
&& !vbo
&& _mesa_is_gles31(ctx
)) {
2108 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
2111 /* From the GL_ARB_vertex_attrib_array spec:
2113 * "[Core profile only:]
2114 * An INVALID_OPERATION error is generated if buffer is not zero or a
2115 * name returned from a previous call to GenBuffers, or if such a name
2116 * has since been deleted with DeleteBuffers.
2118 * Otherwise, we fall back to the same compat profile behavior as other
2119 * object references (automatically gen it).
2121 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
2124 /* The ARB_vertex_attrib_binding spec says:
2126 * "If <buffer> is zero, any buffer object attached to this
2127 * bindpoint is detached."
2129 vbo
= ctx
->Shared
->NullBufferObj
;
2132 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
2133 vbo
, offset
, stride
, true);
2138 * GL_ARB_vertex_attrib_binding
2141 vertex_array_vertex_buffer_err(struct gl_context
*ctx
,
2142 struct gl_vertex_array_object
*vao
,
2143 GLuint bindingIndex
, GLuint buffer
,
2144 GLintptr offset
, GLsizei stride
,
2147 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2149 /* The ARB_vertex_attrib_binding spec says:
2151 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2152 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2154 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2155 _mesa_error(ctx
, GL_INVALID_VALUE
,
2156 "%s(bindingindex=%u > "
2157 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2158 func
, bindingIndex
);
2162 /* The ARB_vertex_attrib_binding spec says:
2164 * "The error INVALID_VALUE is generated if <stride> or <offset>
2168 _mesa_error(ctx
, GL_INVALID_VALUE
,
2169 "%s(offset=%" PRId64
" < 0)",
2170 func
, (int64_t) offset
);
2175 _mesa_error(ctx
, GL_INVALID_VALUE
,
2176 "%s(stride=%d < 0)", func
, stride
);
2180 if (((_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
2181 stride
> ctx
->Const
.MaxVertexAttribStride
) {
2182 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
2183 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
2187 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2188 stride
, false, func
);
2193 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex
, GLuint buffer
,
2194 GLintptr offset
, GLsizei stride
)
2196 GET_CURRENT_CONTEXT(ctx
);
2197 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2198 buffer
, offset
, stride
, true,
2199 "glBindVertexBuffer");
2204 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2207 GET_CURRENT_CONTEXT(ctx
);
2209 /* The ARB_vertex_attrib_binding spec says:
2211 * "An INVALID_OPERATION error is generated if no vertex array object
2214 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2215 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2216 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2217 "glBindVertexBuffer(No array object bound)");
2221 vertex_array_vertex_buffer_err(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2222 buffer
, offset
, stride
,
2223 "glBindVertexBuffer");
2228 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj
, GLuint bindingIndex
,
2229 GLuint buffer
, GLintptr offset
,
2232 GET_CURRENT_CONTEXT(ctx
);
2234 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2235 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2236 stride
, true, "glVertexArrayVertexBuffer");
2241 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
2242 GLintptr offset
, GLsizei stride
)
2244 GET_CURRENT_CONTEXT(ctx
);
2245 struct gl_vertex_array_object
*vao
;
2247 /* The ARB_direct_state_access specification says:
2249 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2250 * if <vaobj> is not [compatibility profile: zero or] the name of an
2251 * existing vertex array object."
2253 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
2257 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
2258 stride
, "glVertexArrayVertexBuffer");
2262 static ALWAYS_INLINE
void
2263 vertex_array_vertex_buffers(struct gl_context
*ctx
,
2264 struct gl_vertex_array_object
*vao
,
2265 GLuint first
, GLsizei count
, const GLuint
*buffers
,
2266 const GLintptr
*offsets
, const GLsizei
*strides
,
2267 bool no_error
, const char *func
)
2273 * The ARB_multi_bind spec says:
2275 * "If <buffers> is NULL, each affected vertex buffer binding point
2276 * from <first> through <first>+<count>-1 will be reset to have no
2277 * bound buffer object. In this case, the offsets and strides
2278 * associated with the binding points are set to default values,
2279 * ignoring <offsets> and <strides>."
2281 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
2283 for (i
= 0; i
< count
; i
++)
2284 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2290 /* Note that the error semantics for multi-bind commands differ from
2291 * those of other GL commands.
2293 * The Issues section in the ARB_multi_bind spec says:
2295 * "(11) Typically, OpenGL specifies that if an error is generated by
2296 * a command, that command has no effect. This is somewhat
2297 * unfortunate for multi-bind commands, because it would require
2298 * a first pass to scan the entire list of bound objects for
2299 * errors and then a second pass to actually perform the
2300 * bindings. Should we have different error semantics?
2302 * RESOLVED: Yes. In this specification, when the parameters for
2303 * one of the <count> binding points are invalid, that binding
2304 * point is not updated and an error will be generated. However,
2305 * other binding points in the same command will be updated if
2306 * their parameters are valid and no other error occurs."
2309 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
2311 for (i
= 0; i
< count
; i
++) {
2312 struct gl_buffer_object
*vbo
;
2315 /* The ARB_multi_bind spec says:
2317 * "An INVALID_VALUE error is generated if any value in
2318 * <offsets> or <strides> is negative (per binding)."
2320 if (offsets
[i
] < 0) {
2321 _mesa_error(ctx
, GL_INVALID_VALUE
,
2322 "%s(offsets[%u]=%" PRId64
" < 0)",
2323 func
, i
, (int64_t) offsets
[i
]);
2327 if (strides
[i
] < 0) {
2328 _mesa_error(ctx
, GL_INVALID_VALUE
,
2329 "%s(strides[%u]=%d < 0)",
2330 func
, i
, strides
[i
]);
2334 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
2335 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
2336 _mesa_error(ctx
, GL_INVALID_VALUE
,
2337 "%s(strides[%u]=%d > "
2338 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
2344 struct gl_vertex_buffer_binding
*binding
=
2345 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
2347 if (buffers
[i
] == binding
->BufferObj
->Name
)
2348 vbo
= binding
->BufferObj
;
2350 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
2355 vbo
= ctx
->Shared
->NullBufferObj
;
2358 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2359 vbo
, offsets
[i
], strides
[i
], true);
2362 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
2367 vertex_array_vertex_buffers_err(struct gl_context
*ctx
,
2368 struct gl_vertex_array_object
*vao
,
2369 GLuint first
, GLsizei count
,
2370 const GLuint
*buffers
, const GLintptr
*offsets
,
2371 const GLsizei
*strides
, const char *func
)
2373 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2375 /* The ARB_multi_bind spec says:
2377 * "An INVALID_OPERATION error is generated if <first> + <count>
2378 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
2380 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
2381 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2382 "%s(first=%u + count=%d > the value of "
2383 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
2384 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
2388 vertex_array_vertex_buffers(ctx
, vao
, first
, count
, buffers
, offsets
,
2389 strides
, false, func
);
2394 _mesa_BindVertexBuffers_no_error(GLuint first
, GLsizei count
,
2395 const GLuint
*buffers
, const GLintptr
*offsets
,
2396 const GLsizei
*strides
)
2398 GET_CURRENT_CONTEXT(ctx
);
2400 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
2401 buffers
, offsets
, strides
, true,
2402 "glBindVertexBuffers");
2407 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
2408 const GLintptr
*offsets
, const GLsizei
*strides
)
2410 GET_CURRENT_CONTEXT(ctx
);
2412 /* The ARB_vertex_attrib_binding spec says:
2414 * "An INVALID_OPERATION error is generated if no
2415 * vertex array object is bound."
2417 if (ctx
->API
== API_OPENGL_CORE
&&
2418 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2419 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2420 "glBindVertexBuffers(No array object bound)");
2424 vertex_array_vertex_buffers_err(ctx
, ctx
->Array
.VAO
, first
, count
,
2425 buffers
, offsets
, strides
,
2426 "glBindVertexBuffers");
2431 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj
, GLuint first
,
2432 GLsizei count
, const GLuint
*buffers
,
2433 const GLintptr
*offsets
,
2434 const GLsizei
*strides
)
2436 GET_CURRENT_CONTEXT(ctx
);
2438 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2439 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
2440 buffers
, offsets
, strides
, true,
2441 "glVertexArrayVertexBuffers");
2446 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
2447 const GLuint
*buffers
,
2448 const GLintptr
*offsets
, const GLsizei
*strides
)
2450 GET_CURRENT_CONTEXT(ctx
);
2451 struct gl_vertex_array_object
*vao
;
2453 /* The ARB_direct_state_access specification says:
2455 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2456 * if <vaobj> is not [compatibility profile: zero or] the name of an
2457 * existing vertex array object."
2459 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
2463 vertex_array_vertex_buffers_err(ctx
, vao
, first
, count
,
2464 buffers
, offsets
, strides
,
2465 "glVertexArrayVertexBuffers");
2470 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
2471 GLboolean normalized
, GLboolean integer
,
2472 GLboolean doubles
, GLbitfield legalTypes
,
2473 GLsizei sizeMax
, GLuint relativeOffset
,
2476 GET_CURRENT_CONTEXT(ctx
);
2477 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2479 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2481 if (!_mesa_is_no_error_enabled(ctx
)) {
2482 /* The ARB_vertex_attrib_binding spec says:
2484 * "An INVALID_OPERATION error is generated under any of the
2485 * following conditions:
2486 * - if no vertex array object is currently bound (see section
2490 * This error condition only applies to VertexAttribFormat and
2491 * VertexAttribIFormat in the extension spec, but we assume that this
2492 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2493 * to all three functions.
2495 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2496 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2497 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2498 "%s(No array object bound)", func
);
2502 /* The ARB_vertex_attrib_binding spec says:
2504 * "The error INVALID_VALUE is generated if index is greater than or
2505 * equal to the value of MAX_VERTEX_ATTRIBS."
2507 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2508 _mesa_error(ctx
, GL_INVALID_VALUE
,
2509 "%s(attribindex=%u > "
2510 "GL_MAX_VERTEX_ATTRIBS)",
2515 if (!validate_array_format(ctx
, func
, ctx
->Array
.VAO
,
2516 VERT_ATTRIB_GENERIC(attribIndex
),
2517 legalTypes
, 1, sizeMax
, size
, type
,
2518 normalized
, integer
, doubles
, relativeOffset
,
2524 FLUSH_VERTICES(ctx
, 0);
2526 _mesa_update_array_format(ctx
, ctx
->Array
.VAO
,
2527 VERT_ATTRIB_GENERIC(attribIndex
), size
, type
,
2528 format
, normalized
, integer
, doubles
,
2534 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2535 GLboolean normalized
, GLuint relativeOffset
)
2537 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
2538 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2539 BGRA_OR_4
, relativeOffset
,
2540 "glVertexAttribFormat");
2545 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2546 GLuint relativeOffset
)
2548 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2549 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2550 relativeOffset
, "glVertexAttribIFormat");
2555 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2556 GLuint relativeOffset
)
2558 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2559 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2560 relativeOffset
, "glVertexAttribLFormat");
2565 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2566 GLenum type
, GLboolean normalized
,
2567 GLboolean integer
, GLboolean doubles
,
2568 GLbitfield legalTypes
, GLsizei sizeMax
,
2569 GLuint relativeOffset
, const char *func
)
2571 GET_CURRENT_CONTEXT(ctx
);
2572 struct gl_vertex_array_object
*vao
;
2574 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2576 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2578 if (_mesa_is_no_error_enabled(ctx
)) {
2579 vao
= _mesa_lookup_vao(ctx
, vaobj
);
2583 /* The ARB_direct_state_access spec says:
2585 * "An INVALID_OPERATION error is generated by
2586 * VertexArrayAttrib*Format if <vaobj> is not [compatibility profile:
2587 * zero or] the name of an existing vertex array object."
2589 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2593 /* The ARB_vertex_attrib_binding spec says:
2595 * "The error INVALID_VALUE is generated if index is greater than or
2596 * equal to the value of MAX_VERTEX_ATTRIBS."
2598 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2599 _mesa_error(ctx
, GL_INVALID_VALUE
,
2600 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2605 if (!validate_array_format(ctx
, func
, vao
,
2606 VERT_ATTRIB_GENERIC(attribIndex
),
2607 legalTypes
, 1, sizeMax
, size
, type
,
2608 normalized
, integer
, doubles
, relativeOffset
,
2614 FLUSH_VERTICES(ctx
, 0);
2616 _mesa_update_array_format(ctx
, vao
, VERT_ATTRIB_GENERIC(attribIndex
), size
,
2617 type
, format
, normalized
, integer
, doubles
,
2623 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2624 GLenum type
, GLboolean normalized
,
2625 GLuint relativeOffset
)
2627 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2628 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2629 BGRA_OR_4
, relativeOffset
,
2630 "glVertexArrayAttribFormat");
2635 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2636 GLint size
, GLenum type
,
2637 GLuint relativeOffset
)
2639 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2640 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2642 "glVertexArrayAttribIFormat");
2647 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2648 GLint size
, GLenum type
,
2649 GLuint relativeOffset
)
2651 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2652 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2654 "glVertexArrayAttribLFormat");
2659 vertex_array_attrib_binding(struct gl_context
*ctx
,
2660 struct gl_vertex_array_object
*vao
,
2661 GLuint attribIndex
, GLuint bindingIndex
,
2664 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2666 /* The ARB_vertex_attrib_binding spec says:
2668 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2669 * <bindingindex> must be less than the value of
2670 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2673 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2674 _mesa_error(ctx
, GL_INVALID_VALUE
,
2675 "%s(attribindex=%u >= "
2676 "GL_MAX_VERTEX_ATTRIBS)",
2681 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2682 _mesa_error(ctx
, GL_INVALID_VALUE
,
2683 "%s(bindingindex=%u >= "
2684 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2685 func
, bindingIndex
);
2689 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2691 _mesa_vertex_attrib_binding(ctx
, vao
,
2692 VERT_ATTRIB_GENERIC(attribIndex
),
2693 VERT_ATTRIB_GENERIC(bindingIndex
), true);
2698 _mesa_VertexAttribBinding_no_error(GLuint attribIndex
, GLuint bindingIndex
)
2700 GET_CURRENT_CONTEXT(ctx
);
2701 _mesa_vertex_attrib_binding(ctx
, ctx
->Array
.VAO
,
2702 VERT_ATTRIB_GENERIC(attribIndex
),
2703 VERT_ATTRIB_GENERIC(bindingIndex
), true);
2708 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2710 GET_CURRENT_CONTEXT(ctx
);
2712 /* The ARB_vertex_attrib_binding spec says:
2714 * "An INVALID_OPERATION error is generated if no vertex array object
2717 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2718 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2719 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2720 "glVertexAttribBinding(No array object bound)");
2724 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2725 attribIndex
, bindingIndex
,
2726 "glVertexAttribBinding");
2731 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj
, GLuint attribIndex
,
2732 GLuint bindingIndex
)
2734 GET_CURRENT_CONTEXT(ctx
);
2736 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2737 _mesa_vertex_attrib_binding(ctx
, vao
,
2738 VERT_ATTRIB_GENERIC(attribIndex
),
2739 VERT_ATTRIB_GENERIC(bindingIndex
), true);
2744 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2746 GET_CURRENT_CONTEXT(ctx
);
2747 struct gl_vertex_array_object
*vao
;
2749 /* The ARB_direct_state_access specification says:
2751 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2752 * if <vaobj> is not [compatibility profile: zero or] the name of an
2753 * existing vertex array object."
2755 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2759 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2760 "glVertexArrayAttribBinding");
2765 vertex_array_binding_divisor(struct gl_context
*ctx
,
2766 struct gl_vertex_array_object
*vao
,
2767 GLuint bindingIndex
, GLuint divisor
,
2770 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2772 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2773 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2777 /* The ARB_vertex_attrib_binding spec says:
2779 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2780 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2782 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2783 _mesa_error(ctx
, GL_INVALID_VALUE
,
2784 "%s(bindingindex=%u > "
2785 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2786 func
, bindingIndex
);
2790 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2795 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex
, GLuint divisor
)
2797 GET_CURRENT_CONTEXT(ctx
);
2798 vertex_binding_divisor(ctx
, ctx
->Array
.VAO
,
2799 VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2804 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2806 GET_CURRENT_CONTEXT(ctx
);
2808 /* The ARB_vertex_attrib_binding spec says:
2810 * "An INVALID_OPERATION error is generated if no vertex array object
2813 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2814 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2815 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2816 "glVertexBindingDivisor(No array object bound)");
2820 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2821 bindingIndex
, divisor
,
2822 "glVertexBindingDivisor");
2827 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj
, GLuint bindingIndex
,
2830 GET_CURRENT_CONTEXT(ctx
);
2832 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2833 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2838 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2841 struct gl_vertex_array_object
*vao
;
2842 GET_CURRENT_CONTEXT(ctx
);
2844 /* The ARB_direct_state_access specification says:
2846 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2847 * if <vaobj> is not [compatibility profile: zero or] the name of an
2848 * existing vertex array object."
2850 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2854 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2855 "glVertexArrayBindingDivisor");
2860 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2861 struct gl_array_attributes
*dst
,
2862 const struct gl_array_attributes
*src
)
2864 dst
->Size
= src
->Size
;
2865 dst
->Type
= src
->Type
;
2866 dst
->Format
= src
->Format
;
2867 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
2868 dst
->RelativeOffset
= src
->RelativeOffset
;
2869 dst
->Format
= src
->Format
;
2870 dst
->Integer
= src
->Integer
;
2871 dst
->Doubles
= src
->Doubles
;
2872 dst
->Normalized
= src
->Normalized
;
2873 dst
->Ptr
= src
->Ptr
;
2874 dst
->Enabled
= src
->Enabled
;
2875 dst
->_ElementSize
= src
->_ElementSize
;
2876 dst
->_EffBufferBindingIndex
= src
->_EffBufferBindingIndex
;
2877 dst
->_EffRelativeOffset
= src
->_EffRelativeOffset
;
2881 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2882 struct gl_vertex_buffer_binding
*dst
,
2883 const struct gl_vertex_buffer_binding
*src
)
2885 dst
->Offset
= src
->Offset
;
2886 dst
->Stride
= src
->Stride
;
2887 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2888 dst
->_BoundArrays
= src
->_BoundArrays
;
2889 dst
->_EffBoundArrays
= src
->_EffBoundArrays
;
2890 dst
->_EffOffset
= src
->_EffOffset
;
2892 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2896 * Print current vertex object/array info. For debug.
2899 _mesa_print_arrays(struct gl_context
*ctx
)
2901 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2903 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
2906 for (i
= 0; i
< VERT_ATTRIB_MAX
; ++i
) {
2907 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
2908 if (!array
->Enabled
)
2911 const struct gl_vertex_buffer_binding
*binding
=
2912 &vao
->BufferBinding
[array
->BufferBindingIndex
];
2913 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
2915 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2916 "Stride=%d, Buffer=%u(Size %lu)\n",
2917 gl_vert_attrib_name((gl_vert_attrib
)i
),
2918 array
->Ptr
, _mesa_enum_to_string(array
->Type
), array
->Size
,
2919 array
->_ElementSize
, binding
->Stride
, bo
->Name
,
2920 (unsigned long) bo
->Size
);
2926 * Initialize vertex array state for given context.
2929 _mesa_init_varray(struct gl_context
*ctx
)
2931 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2932 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2933 ctx
->Array
._EmptyVAO
= _mesa_new_vao(ctx
, ~0u);
2934 _mesa_reference_vao(ctx
, &ctx
->Array
._DrawVAO
, ctx
->Array
._EmptyVAO
);
2935 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2937 ctx
->Array
.Objects
= _mesa_NewHashTable();
2942 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2945 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2947 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2948 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2949 _mesa_delete_vao(ctx
, vao
);
2954 * Free vertex array state for given context.
2957 _mesa_free_varray_data(struct gl_context
*ctx
)
2959 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2960 _mesa_DeleteHashTable(ctx
->Array
.Objects
);