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 vertex_attrib_binding(struct gl_context
*ctx
,
160 struct gl_vertex_array_object
*vao
,
161 gl_vert_attrib attribIndex
,
164 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attribIndex
];
166 if (array
->BufferBindingIndex
!= bindingIndex
) {
167 const GLbitfield array_bit
= VERT_BIT(attribIndex
);
169 if (_mesa_is_bufferobj(vao
->BufferBinding
[bindingIndex
].BufferObj
))
170 vao
->VertexAttribBufferMask
|= array_bit
;
172 vao
->VertexAttribBufferMask
&= ~array_bit
;
174 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
176 vao
->BufferBinding
[array
->BufferBindingIndex
]._BoundArrays
&= ~array_bit
;
177 vao
->BufferBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
179 array
->BufferBindingIndex
= bindingIndex
;
181 vao
->NewArrays
|= vao
->_Enabled
& array_bit
;
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
)
197 assert(index
< ARRAY_SIZE(vao
->BufferBinding
));
198 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
200 if (binding
->BufferObj
!= vbo
||
201 binding
->Offset
!= offset
||
202 binding
->Stride
!= stride
) {
204 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
206 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
208 binding
->Offset
= offset
;
209 binding
->Stride
= stride
;
211 if (!_mesa_is_bufferobj(vbo
))
212 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
214 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
216 vao
->NewArrays
|= vao
->_Enabled
& binding
->_BoundArrays
;
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
];
234 if (binding
->InstanceDivisor
!= divisor
) {
235 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
236 binding
->InstanceDivisor
= divisor
;
237 vao
->NewArrays
|= vao
->_Enabled
& binding
->_BoundArrays
;
243 * Examine the API profile and extensions to determine which types are legal
244 * for vertex arrays. This is called once from update_array_format().
247 get_legal_types_mask(const struct gl_context
*ctx
)
249 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
251 if (_mesa_is_gles(ctx
)) {
252 legalTypesMask
&= ~(FIXED_GL_BIT
|
254 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
256 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
257 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
258 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
259 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
260 * quite as trivial as we'd like because it uses a different enum value
261 * for GL_HALF_FLOAT_OES.
263 if (ctx
->Version
< 30) {
264 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
266 UNSIGNED_INT_2_10_10_10_REV_BIT
|
267 INT_2_10_10_10_REV_BIT
);
269 if (!_mesa_has_OES_vertex_half_float(ctx
))
270 legalTypesMask
&= ~HALF_BIT
;
274 legalTypesMask
&= ~FIXED_ES_BIT
;
276 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
277 legalTypesMask
&= ~FIXED_GL_BIT
;
279 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
280 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
281 INT_2_10_10_10_REV_BIT
);
283 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
284 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
287 return legalTypesMask
;
291 get_array_format(const struct gl_context
*ctx
, GLint sizeMax
, GLint
*size
)
293 GLenum format
= GL_RGBA
;
295 /* Do size parameter checking.
296 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
297 * must be handled specially.
299 if (ctx
->Extensions
.EXT_vertex_array_bgra
&& sizeMax
== BGRA_OR_4
&&
310 * \param attrib The index of the attribute array
311 * \param size Components per element (1, 2, 3 or 4)
312 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
313 * \param format Either GL_RGBA or GL_BGRA.
314 * \param normalized Whether integer types are converted to floats in [-1, 1]
315 * \param integer Integer-valued values (will not be normalized to [-1, 1])
316 * \param doubles Double values not reduced to floats
317 * \param relativeOffset Offset of the first element relative to the binding
319 * \param flush_verties Should \c FLUSH_VERTICES be invoked before updating
323 _mesa_update_array_format(struct gl_context
*ctx
,
324 struct gl_vertex_array_object
*vao
,
325 gl_vert_attrib attrib
, GLint size
, GLenum type
,
326 GLenum format
, GLboolean normalized
,
327 GLboolean integer
, GLboolean doubles
,
328 GLuint relativeOffset
)
330 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
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 (ctx
->API
== API_OPENGL_CORE
&& 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 vertex_attrib_binding(ctx
, vao
, attrib
, attrib
);
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
;
602 /* Update the vertex buffer binding */
603 GLsizei effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
604 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
605 ctx
->Array
.ArrayBufferObj
, (GLintptr
) ptr
,
610 _mesa_VertexPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
613 GET_CURRENT_CONTEXT(ctx
);
614 FLUSH_VERTICES(ctx
, 0);
616 update_array(ctx
, VERT_ATTRIB_POS
, GL_RGBA
, 4, size
, type
, stride
,
617 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
622 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
624 GET_CURRENT_CONTEXT(ctx
);
626 FLUSH_VERTICES(ctx
, 0);
628 GLenum format
= GL_RGBA
;
629 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
630 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
631 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
632 DOUBLE_BIT
| HALF_BIT
|
633 UNSIGNED_INT_2_10_10_10_REV_BIT
|
634 INT_2_10_10_10_REV_BIT
);
636 if (!validate_array_and_format(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
637 legalTypes
, 2, 4, size
, type
, stride
,
638 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
,
639 ptr
, ctx
->Array
.VAO
))
642 update_array(ctx
, VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
643 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
648 _mesa_NormalPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
650 GET_CURRENT_CONTEXT(ctx
);
651 FLUSH_VERTICES(ctx
, 0);
653 update_array(ctx
, VERT_ATTRIB_NORMAL
, GL_RGBA
, 3, 3, type
, stride
, GL_TRUE
,
654 GL_FALSE
, GL_FALSE
, ptr
);
659 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
661 GET_CURRENT_CONTEXT(ctx
);
663 FLUSH_VERTICES(ctx
, 0);
665 GLenum format
= GL_RGBA
;
666 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
667 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
668 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
669 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
670 UNSIGNED_INT_2_10_10_10_REV_BIT
|
671 INT_2_10_10_10_REV_BIT
);
673 if (!validate_array_and_format(ctx
, "glNormalPointer",
674 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
675 type
, stride
, GL_TRUE
, GL_FALSE
,
676 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
679 update_array(ctx
, VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
680 GL_FALSE
, GL_FALSE
, ptr
);
685 _mesa_ColorPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
688 GET_CURRENT_CONTEXT(ctx
);
689 FLUSH_VERTICES(ctx
, 0);
691 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
692 update_array(ctx
, VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
693 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
698 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
700 GET_CURRENT_CONTEXT(ctx
);
701 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
703 FLUSH_VERTICES(ctx
, 0);
705 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
706 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
707 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
708 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
709 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
710 INT_BIT
| UNSIGNED_INT_BIT
|
711 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
712 UNSIGNED_INT_2_10_10_10_REV_BIT
|
713 INT_2_10_10_10_REV_BIT
);
715 if (!validate_array_and_format(ctx
, "glColorPointer",
716 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
717 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
718 GL_FALSE
, GL_FALSE
, format
, ptr
,
722 update_array(ctx
, VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
723 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
728 _mesa_FogCoordPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
730 GET_CURRENT_CONTEXT(ctx
);
731 FLUSH_VERTICES(ctx
, 0);
733 update_array(ctx
, VERT_ATTRIB_FOG
, GL_RGBA
, 1, 1, type
, stride
, GL_FALSE
,
734 GL_FALSE
, GL_FALSE
, ptr
);
739 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
741 GET_CURRENT_CONTEXT(ctx
);
743 FLUSH_VERTICES(ctx
, 0);
745 GLenum format
= GL_RGBA
;
746 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
748 if (!validate_array_and_format(ctx
, "glFogCoordPointer",
749 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
750 type
, stride
, GL_FALSE
, GL_FALSE
,
751 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
754 update_array(ctx
, VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
755 GL_FALSE
, GL_FALSE
, ptr
);
760 _mesa_IndexPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
762 GET_CURRENT_CONTEXT(ctx
);
763 FLUSH_VERTICES(ctx
, 0);
765 update_array(ctx
, VERT_ATTRIB_COLOR_INDEX
, GL_RGBA
, 1, 1, type
, stride
,
766 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
771 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
773 GET_CURRENT_CONTEXT(ctx
);
775 FLUSH_VERTICES(ctx
, 0);
777 GLenum format
= GL_RGBA
;
778 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
779 FLOAT_BIT
| DOUBLE_BIT
);
781 if (!validate_array_and_format(ctx
, "glIndexPointer",
782 VERT_ATTRIB_COLOR_INDEX
,
783 legalTypes
, 1, 1, 1, type
, stride
,
784 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
,
785 ptr
, ctx
->Array
.VAO
))
788 update_array(ctx
, VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
789 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
794 _mesa_SecondaryColorPointer_no_error(GLint size
, GLenum type
,
795 GLsizei stride
, const GLvoid
*ptr
)
797 GET_CURRENT_CONTEXT(ctx
);
798 FLUSH_VERTICES(ctx
, 0);
800 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
801 update_array(ctx
, VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
802 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
807 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
808 GLsizei stride
, const GLvoid
*ptr
)
810 GET_CURRENT_CONTEXT(ctx
);
812 FLUSH_VERTICES(ctx
, 0);
814 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
815 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
816 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
817 INT_BIT
| UNSIGNED_INT_BIT
|
818 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
819 UNSIGNED_INT_2_10_10_10_REV_BIT
|
820 INT_2_10_10_10_REV_BIT
);
822 if (!validate_array_and_format(ctx
, "glSecondaryColorPointer",
823 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
824 BGRA_OR_4
, size
, type
, stride
,
825 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, ptr
,
829 update_array(ctx
, VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
830 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
835 _mesa_TexCoordPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
838 GET_CURRENT_CONTEXT(ctx
);
839 const GLuint unit
= ctx
->Array
.ActiveTexture
;
840 FLUSH_VERTICES(ctx
, 0);
842 update_array(ctx
, VERT_ATTRIB_TEX(unit
), GL_RGBA
, 4, size
, type
,
843 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
848 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
851 GET_CURRENT_CONTEXT(ctx
);
852 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
853 const GLuint unit
= ctx
->Array
.ActiveTexture
;
855 FLUSH_VERTICES(ctx
, 0);
857 GLenum format
= GL_RGBA
;
858 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
859 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
860 : (SHORT_BIT
| INT_BIT
|
861 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
862 UNSIGNED_INT_2_10_10_10_REV_BIT
|
863 INT_2_10_10_10_REV_BIT
);
865 if (!validate_array_and_format(ctx
, "glTexCoordPointer",
866 VERT_ATTRIB_TEX(unit
), legalTypes
,
867 sizeMin
, 4, size
, type
, stride
,
868 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
,
872 update_array(ctx
, VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
873 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
878 _mesa_EdgeFlagPointer_no_error(GLsizei stride
, const GLvoid
*ptr
)
880 /* this is the same type that glEdgeFlag uses */
881 const GLboolean integer
= GL_FALSE
;
882 GET_CURRENT_CONTEXT(ctx
);
883 FLUSH_VERTICES(ctx
, 0);
885 update_array(ctx
, VERT_ATTRIB_EDGEFLAG
, GL_RGBA
, 1, 1, GL_UNSIGNED_BYTE
,
886 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
891 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
893 /* this is the same type that glEdgeFlag uses */
894 const GLboolean integer
= GL_FALSE
;
895 GET_CURRENT_CONTEXT(ctx
);
897 FLUSH_VERTICES(ctx
, 0);
899 GLenum format
= GL_RGBA
;
900 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
902 if (!validate_array_and_format(ctx
, "glEdgeFlagPointer",
903 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
904 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
905 GL_FALSE
, integer
, GL_FALSE
, format
, ptr
,
909 update_array(ctx
, VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
910 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
915 _mesa_PointSizePointerOES_no_error(GLenum type
, GLsizei stride
,
918 GET_CURRENT_CONTEXT(ctx
);
919 FLUSH_VERTICES(ctx
, 0);
921 update_array(ctx
, VERT_ATTRIB_POINT_SIZE
, GL_RGBA
, 1, 1, type
, stride
,
922 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
927 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
929 GET_CURRENT_CONTEXT(ctx
);
931 FLUSH_VERTICES(ctx
, 0);
933 GLenum format
= GL_RGBA
;
934 if (ctx
->API
!= API_OPENGLES
) {
935 _mesa_error(ctx
, GL_INVALID_OPERATION
,
936 "glPointSizePointer(ES 1.x only)");
940 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
942 if (!validate_array_and_format(ctx
, "glPointSizePointer",
943 VERT_ATTRIB_POINT_SIZE
, legalTypes
,
944 1, 1, 1, type
, stride
, GL_FALSE
, GL_FALSE
,
945 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
948 update_array(ctx
, VERT_ATTRIB_POINT_SIZE
, format
, 1, 1, type
, stride
,
949 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
954 _mesa_VertexAttribPointer_no_error(GLuint index
, GLint size
, GLenum type
,
955 GLboolean normalized
,
956 GLsizei stride
, const GLvoid
*ptr
)
958 GET_CURRENT_CONTEXT(ctx
);
960 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
961 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
962 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
967 * Set a generic vertex attribute array.
968 * Note that these arrays DO NOT alias the conventional GL vertex arrays
969 * (position, normal, color, fog, texcoord, etc).
972 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
973 GLboolean normalized
,
974 GLsizei stride
, const GLvoid
*ptr
)
976 GET_CURRENT_CONTEXT(ctx
);
978 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
979 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
980 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(idx)");
984 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
985 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
986 INT_BIT
| UNSIGNED_INT_BIT
|
987 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
988 FIXED_ES_BIT
| FIXED_GL_BIT
|
989 UNSIGNED_INT_2_10_10_10_REV_BIT
|
990 INT_2_10_10_10_REV_BIT
|
991 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
993 if (!validate_array_and_format(ctx
, "glVertexAttribPointer",
994 VERT_ATTRIB_GENERIC(index
), legalTypes
,
995 1, BGRA_OR_4
, size
, type
, stride
,
996 normalized
, GL_FALSE
, GL_FALSE
, format
,
997 ptr
, ctx
->Array
.VAO
))
1000 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1001 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
1006 _mesa_VertexAttribIPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1007 GLsizei stride
, const GLvoid
*ptr
)
1009 const GLboolean normalized
= GL_FALSE
;
1010 const GLboolean integer
= GL_TRUE
;
1011 GET_CURRENT_CONTEXT(ctx
);
1013 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1014 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1019 * GL_EXT_gpu_shader4 / GL 3.0.
1020 * Set an integer-valued vertex attribute array.
1021 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1022 * (position, normal, color, fog, texcoord, etc).
1025 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
1026 GLsizei stride
, const GLvoid
*ptr
)
1028 const GLboolean normalized
= GL_FALSE
;
1029 const GLboolean integer
= GL_TRUE
;
1030 GET_CURRENT_CONTEXT(ctx
);
1032 GLenum format
= GL_RGBA
;
1033 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1034 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
1038 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1039 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1040 INT_BIT
| UNSIGNED_INT_BIT
);
1042 if (!validate_array_and_format(ctx
, "glVertexAttribIPointer",
1043 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1044 1, 4, size
, type
, stride
,
1045 normalized
, integer
, GL_FALSE
, format
,
1046 ptr
, ctx
->Array
.VAO
))
1049 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1050 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1055 _mesa_VertexAttribLPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1056 GLsizei stride
, const GLvoid
*ptr
)
1058 GET_CURRENT_CONTEXT(ctx
);
1060 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1061 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1066 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
1067 GLsizei stride
, const GLvoid
*ptr
)
1069 GET_CURRENT_CONTEXT(ctx
);
1071 GLenum format
= GL_RGBA
;
1072 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1073 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
1077 const GLbitfield legalTypes
= DOUBLE_BIT
;
1079 if (!validate_array_and_format(ctx
, "glVertexAttribLPointer",
1080 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1081 1, 4, size
, type
, stride
,
1082 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
,
1083 ptr
, ctx
->Array
.VAO
))
1086 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1087 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1092 _mesa_enable_vertex_array_attrib(struct gl_context
*ctx
,
1093 struct gl_vertex_array_object
*vao
,
1094 gl_vert_attrib attrib
)
1096 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
1098 if (!vao
->VertexAttrib
[attrib
].Enabled
) {
1099 /* was disabled, now being enabled */
1100 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1101 vao
->VertexAttrib
[attrib
].Enabled
= GL_TRUE
;
1102 const GLbitfield array_bit
= VERT_BIT(attrib
);
1103 vao
->_Enabled
|= array_bit
;
1104 vao
->NewArrays
|= array_bit
;
1106 /* Update the map mode if needed */
1107 if (array_bit
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1108 update_attribute_map_mode(ctx
, vao
);
1113 enable_vertex_array_attrib(struct gl_context
*ctx
,
1114 struct gl_vertex_array_object
*vao
,
1118 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1119 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
1123 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1128 _mesa_EnableVertexAttribArray(GLuint index
)
1130 GET_CURRENT_CONTEXT(ctx
);
1131 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
1132 "glEnableVertexAttribArray");
1137 _mesa_EnableVertexAttribArray_no_error(GLuint index
)
1139 GET_CURRENT_CONTEXT(ctx
);
1140 _mesa_enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1141 VERT_ATTRIB_GENERIC(index
));
1146 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1148 GET_CURRENT_CONTEXT(ctx
);
1149 struct gl_vertex_array_object
*vao
;
1151 /* The ARB_direct_state_access specification says:
1153 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1154 * and DisableVertexArrayAttrib if <vaobj> is not
1155 * [compatibility profile: zero or] the name of an existing vertex
1158 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
1162 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
1167 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1169 GET_CURRENT_CONTEXT(ctx
);
1170 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1171 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1176 _mesa_disable_vertex_array_attrib(struct gl_context
*ctx
,
1177 struct gl_vertex_array_object
*vao
,
1178 gl_vert_attrib attrib
)
1180 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
1182 if (vao
->VertexAttrib
[attrib
].Enabled
) {
1183 /* was enabled, now being disabled */
1184 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1185 vao
->VertexAttrib
[attrib
].Enabled
= GL_FALSE
;
1186 const GLbitfield array_bit
= VERT_BIT(attrib
);
1187 vao
->_Enabled
&= ~array_bit
;
1188 vao
->NewArrays
|= array_bit
;
1190 /* Update the map mode if needed */
1191 if (array_bit
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1192 update_attribute_map_mode(ctx
, vao
);
1198 _mesa_DisableVertexAttribArray(GLuint index
)
1200 GET_CURRENT_CONTEXT(ctx
);
1202 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1203 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexAttribArray(index)");
1207 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1208 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
1213 _mesa_DisableVertexAttribArray_no_error(GLuint index
)
1215 GET_CURRENT_CONTEXT(ctx
);
1216 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1217 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
1222 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1224 GET_CURRENT_CONTEXT(ctx
);
1225 struct gl_vertex_array_object
*vao
;
1227 /* The ARB_direct_state_access specification says:
1229 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1230 * and DisableVertexArrayAttrib if <vaobj> is not
1231 * [compatibility profile: zero or] the name of an existing vertex
1234 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
1238 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1239 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
1243 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1244 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
1249 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1251 GET_CURRENT_CONTEXT(ctx
);
1252 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1253 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1254 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
1259 * Return info for a vertex attribute array (no alias with legacy
1260 * vertex attributes (pos, normal, color, etc)). This function does
1261 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
1264 get_vertex_array_attrib(struct gl_context
*ctx
,
1265 const struct gl_vertex_array_object
*vao
,
1266 GLuint index
, GLenum pname
,
1269 const struct gl_array_attributes
*array
;
1271 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1272 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
1276 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
1278 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
1281 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
1282 return array
->Enabled
;
1283 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
1284 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
1285 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
1286 return array
->Stride
;
1287 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
1289 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
1290 return array
->Normalized
;
1291 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
1292 return vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
->Name
;
1293 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
1294 if ((_mesa_is_desktop_gl(ctx
)
1295 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
1296 || _mesa_is_gles3(ctx
)) {
1297 return array
->Integer
;
1300 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
1301 if (_mesa_is_desktop_gl(ctx
)) {
1302 return array
->Doubles
;
1305 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
1306 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
1307 || _mesa_is_gles3(ctx
)) {
1308 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
1311 case GL_VERTEX_ATTRIB_BINDING
:
1312 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1313 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
1316 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
1317 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1318 return array
->RelativeOffset
;
1322 ; /* fall-through */
1326 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
1331 static const GLfloat
*
1332 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
1335 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
1336 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
1340 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1341 _mesa_error(ctx
, GL_INVALID_VALUE
,
1342 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
1346 assert(VERT_ATTRIB_GENERIC(index
) <
1347 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1349 FLUSH_CURRENT(ctx
, 0);
1350 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
1354 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
1356 GET_CURRENT_CONTEXT(ctx
);
1358 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1359 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
1365 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1367 "glGetVertexAttribfv");
1373 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1375 GET_CURRENT_CONTEXT(ctx
);
1377 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1378 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
1380 params
[0] = (GLdouble
) v
[0];
1381 params
[1] = (GLdouble
) v
[1];
1382 params
[2] = (GLdouble
) v
[2];
1383 params
[3] = (GLdouble
) v
[3];
1387 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1389 "glGetVertexAttribdv");
1394 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1396 GET_CURRENT_CONTEXT(ctx
);
1398 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1400 (const GLdouble
*)get_current_attrib(ctx
, index
,
1401 "glGetVertexAttribLdv");
1410 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1412 "glGetVertexAttribLdv");
1417 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1419 GET_CURRENT_CONTEXT(ctx
);
1421 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1422 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1424 /* XXX should floats in[0,1] be scaled to full int range? */
1425 params
[0] = (GLint
) v
[0];
1426 params
[1] = (GLint
) v
[1];
1427 params
[2] = (GLint
) v
[2];
1428 params
[3] = (GLint
) v
[3];
1432 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1434 "glGetVertexAttribiv");
1439 _mesa_GetVertexAttribLui64vARB(GLuint index
, GLenum pname
, GLuint64EXT
*params
)
1441 GET_CURRENT_CONTEXT(ctx
);
1443 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1445 (const GLuint64
*)get_current_attrib(ctx
, index
,
1446 "glGetVertexAttribLui64vARB");
1455 params
[0] = (GLuint64
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1457 "glGetVertexAttribLui64vARB");
1464 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1466 GET_CURRENT_CONTEXT(ctx
);
1468 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1469 const GLint
*v
= (const GLint
*)
1470 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1476 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1478 "glGetVertexAttribIiv");
1485 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1487 GET_CURRENT_CONTEXT(ctx
);
1489 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1490 const GLuint
*v
= (const GLuint
*)
1491 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1497 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1499 "glGetVertexAttribIuiv");
1505 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1507 GET_CURRENT_CONTEXT(ctx
);
1509 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1510 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1514 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1515 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1519 assert(VERT_ATTRIB_GENERIC(index
) <
1520 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1522 *pointer
= (GLvoid
*)
1523 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1527 /** ARB_direct_state_access */
1529 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1530 GLenum pname
, GLint
*params
)
1532 GET_CURRENT_CONTEXT(ctx
);
1533 struct gl_vertex_array_object
*vao
;
1535 /* The ARB_direct_state_access specification says:
1537 * "An INVALID_OPERATION error is generated if <vaobj> is not
1538 * [compatibility profile: zero or] the name of an existing
1539 * vertex array object."
1541 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexediv");
1545 /* The ARB_direct_state_access specification says:
1547 * "For GetVertexArrayIndexediv, <pname> must be one of
1548 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1549 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1550 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1551 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1552 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1556 * "Add GetVertexArrayIndexediv in 'Get Command' for
1557 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1558 * VERTEX_ATTRIB_BINDING,
1559 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1560 * VERTEX_BINDING_OFFSET, and
1561 * VERTEX_BINDING_STRIDE states"
1563 * The only parameter name common to both lists is
1564 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1565 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1566 * pretty clear however that the intent is that it should be possible
1567 * to query all vertex attrib and binding states that can be set with
1571 case GL_VERTEX_BINDING_OFFSET
:
1572 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1574 case GL_VERTEX_BINDING_STRIDE
:
1575 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1577 case GL_VERTEX_BINDING_DIVISOR
:
1578 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1580 case GL_VERTEX_BINDING_BUFFER
:
1581 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1584 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1585 "glGetVertexArrayIndexediv");
1592 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1593 GLenum pname
, GLint64
*params
)
1595 GET_CURRENT_CONTEXT(ctx
);
1596 struct gl_vertex_array_object
*vao
;
1598 /* The ARB_direct_state_access specification says:
1600 * "An INVALID_OPERATION error is generated if <vaobj> is not
1601 * [compatibility profile: zero or] the name of an existing
1602 * vertex array object."
1604 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1608 /* The ARB_direct_state_access specification says:
1610 * "For GetVertexArrayIndexed64iv, <pname> must be
1611 * VERTEX_BINDING_OFFSET."
1615 * "An INVALID_ENUM error is generated if <pname> is not one of
1616 * the valid values listed above for the corresponding command."
1618 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1619 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1620 "pname != GL_VERTEX_BINDING_OFFSET)");
1624 /* The ARB_direct_state_access specification says:
1626 * "An INVALID_VALUE error is generated if <index> is greater than
1627 * or equal to the value of MAX_VERTEX_ATTRIBS."
1629 * Since the index refers to a buffer binding in this case, the intended
1630 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1631 * required to be the same, so in practice this doesn't matter.
1633 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1634 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1635 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1636 index
, ctx
->Const
.MaxVertexAttribBindings
);
1640 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1645 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1646 GLsizei count
, const GLvoid
*ptr
)
1649 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1654 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1658 _mesa_NormalPointer(type
, stride
, ptr
);
1663 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1667 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1672 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1676 _mesa_IndexPointer(type
, stride
, ptr
);
1681 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1682 GLsizei count
, const GLvoid
*ptr
)
1685 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1690 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1693 _mesa_EdgeFlagPointer(stride
, ptr
);
1698 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1700 GET_CURRENT_CONTEXT(ctx
);
1701 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1702 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1703 GLenum ctype
= 0; /* color type */
1704 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1705 const GLint toffset
= 0; /* always zero */
1706 GLint defstride
; /* default stride */
1709 FLUSH_VERTICES(ctx
, 0);
1711 f
= sizeof(GLfloat
);
1712 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1715 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1721 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1722 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1727 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1728 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1733 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1734 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1735 ctype
= GL_UNSIGNED_BYTE
;
1738 defstride
= c
+ 2*f
;
1741 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1742 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1743 ctype
= GL_UNSIGNED_BYTE
;
1746 defstride
= c
+ 3*f
;
1749 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1750 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1757 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1758 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1763 case GL_C4F_N3F_V3F
:
1764 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1765 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1773 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1774 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1779 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1780 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1784 case GL_T2F_C4UB_V3F
:
1785 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1786 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1787 ctype
= GL_UNSIGNED_BYTE
;
1792 case GL_T2F_C3F_V3F
:
1793 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1794 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1800 case GL_T2F_N3F_V3F
:
1801 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1802 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1807 case GL_T2F_C4F_N3F_V3F
:
1808 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1809 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1816 case GL_T4F_C4F_N3F_V4F
:
1817 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1818 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1826 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1834 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1835 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1836 /* XXX also disable secondary color and generic arrays? */
1840 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1841 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1842 (GLubyte
*) pointer
+ toffset
);
1845 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1850 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1851 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1852 (GLubyte
*) pointer
+ coffset
);
1855 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1861 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1862 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1865 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1869 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1870 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1871 (GLubyte
*) pointer
+ voffset
);
1876 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1878 GET_CURRENT_CONTEXT(ctx
);
1880 FLUSH_VERTICES(ctx
, 0);
1882 if (MESA_VERBOSE
& VERBOSE_API
)
1883 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1886 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1890 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1893 if (ctx
->Array
.LockCount
!= 0) {
1894 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1898 ctx
->Array
.LockFirst
= first
;
1899 ctx
->Array
.LockCount
= count
;
1901 ctx
->NewState
|= _NEW_ARRAY
;
1906 _mesa_UnlockArraysEXT( void )
1908 GET_CURRENT_CONTEXT(ctx
);
1910 FLUSH_VERTICES(ctx
, 0);
1912 if (MESA_VERBOSE
& VERBOSE_API
)
1913 _mesa_debug(ctx
, "glUnlockArrays\n");
1915 if (ctx
->Array
.LockCount
== 0) {
1916 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1920 ctx
->Array
.LockFirst
= 0;
1921 ctx
->Array
.LockCount
= 0;
1922 ctx
->NewState
|= _NEW_ARRAY
;
1926 /* GL_IBM_multimode_draw_arrays */
1928 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1929 const GLsizei
* count
,
1930 GLsizei primcount
, GLint modestride
)
1932 GET_CURRENT_CONTEXT(ctx
);
1935 FLUSH_VERTICES(ctx
, 0);
1937 for ( i
= 0 ; i
< primcount
; i
++ ) {
1938 if ( count
[i
] > 0 ) {
1939 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1940 CALL_DrawArrays(ctx
->CurrentServerDispatch
, ( m
, first
[i
], count
[i
] ));
1946 /* GL_IBM_multimode_draw_arrays */
1948 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1949 GLenum type
, const GLvoid
* const * indices
,
1950 GLsizei primcount
, GLint modestride
)
1952 GET_CURRENT_CONTEXT(ctx
);
1955 FLUSH_VERTICES(ctx
, 0);
1957 /* XXX not sure about ARB_vertex_buffer_object handling here */
1959 for ( i
= 0 ; i
< primcount
; i
++ ) {
1960 if ( count
[i
] > 0 ) {
1961 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1962 CALL_DrawElements(ctx
->CurrentServerDispatch
, ( m
, count
[i
], type
,
1970 primitive_restart_index(struct gl_context
*ctx
, GLuint index
)
1972 if (ctx
->Array
.RestartIndex
!= index
) {
1973 FLUSH_VERTICES(ctx
, 0);
1974 ctx
->Array
.RestartIndex
= index
;
1980 * GL_NV_primitive_restart and GL 3.1
1983 _mesa_PrimitiveRestartIndex_no_error(GLuint index
)
1985 GET_CURRENT_CONTEXT(ctx
);
1986 primitive_restart_index(ctx
, index
);
1991 _mesa_PrimitiveRestartIndex(GLuint index
)
1993 GET_CURRENT_CONTEXT(ctx
);
1995 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1996 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
2000 primitive_restart_index(ctx
, index
);
2005 _mesa_VertexAttribDivisor_no_error(GLuint index
, GLuint divisor
)
2007 GET_CURRENT_CONTEXT(ctx
);
2009 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2010 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2012 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2014 /* The ARB_vertex_attrib_binding spec says:
2018 * void VertexAttribDivisor(uint index, uint divisor);
2020 * is equivalent to (assuming no errors are generated):
2022 * VertexAttribBinding(index, index);
2023 * VertexBindingDivisor(index, divisor);"
2025 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2026 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2031 * See GL_ARB_instanced_arrays.
2032 * Note that the instance divisor only applies to generic arrays, not
2033 * the legacy vertex arrays.
2036 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
2038 GET_CURRENT_CONTEXT(ctx
);
2040 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2041 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2043 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2044 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
2048 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2049 _mesa_error(ctx
, GL_INVALID_VALUE
,
2050 "glVertexAttribDivisor(index = %u)", index
);
2054 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2056 /* The ARB_vertex_attrib_binding spec says:
2060 * void VertexAttribDivisor(uint index, uint divisor);
2062 * is equivalent to (assuming no errors are generated):
2064 * VertexAttribBinding(index, index);
2065 * VertexBindingDivisor(index, divisor);"
2067 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2068 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2072 static ALWAYS_INLINE
void
2073 vertex_array_vertex_buffer(struct gl_context
*ctx
,
2074 struct gl_vertex_array_object
*vao
,
2075 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2076 GLsizei stride
, bool no_error
, const char *func
)
2078 struct gl_buffer_object
*vbo
;
2080 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
2081 vbo
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
2082 } else if (buffer
!= 0) {
2083 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
2085 if (!no_error
&& !vbo
&& _mesa_is_gles31(ctx
)) {
2086 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
2089 /* From the GL_ARB_vertex_attrib_array spec:
2091 * "[Core profile only:]
2092 * An INVALID_OPERATION error is generated if buffer is not zero or a
2093 * name returned from a previous call to GenBuffers, or if such a name
2094 * has since been deleted with DeleteBuffers.
2096 * Otherwise, we fall back to the same compat profile behavior as other
2097 * object references (automatically gen it).
2099 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
2102 /* The ARB_vertex_attrib_binding spec says:
2104 * "If <buffer> is zero, any buffer object attached to this
2105 * bindpoint is detached."
2107 vbo
= ctx
->Shared
->NullBufferObj
;
2110 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
2111 vbo
, offset
, stride
);
2116 * GL_ARB_vertex_attrib_binding
2119 vertex_array_vertex_buffer_err(struct gl_context
*ctx
,
2120 struct gl_vertex_array_object
*vao
,
2121 GLuint bindingIndex
, GLuint buffer
,
2122 GLintptr offset
, GLsizei stride
,
2125 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2127 /* The ARB_vertex_attrib_binding spec says:
2129 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2130 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2132 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2133 _mesa_error(ctx
, GL_INVALID_VALUE
,
2134 "%s(bindingindex=%u > "
2135 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2136 func
, bindingIndex
);
2140 /* The ARB_vertex_attrib_binding spec says:
2142 * "The error INVALID_VALUE is generated if <stride> or <offset>
2146 _mesa_error(ctx
, GL_INVALID_VALUE
,
2147 "%s(offset=%" PRId64
" < 0)",
2148 func
, (int64_t) offset
);
2153 _mesa_error(ctx
, GL_INVALID_VALUE
,
2154 "%s(stride=%d < 0)", func
, stride
);
2158 if (((ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
2159 stride
> ctx
->Const
.MaxVertexAttribStride
) {
2160 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
2161 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
2165 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2166 stride
, false, func
);
2171 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex
, GLuint buffer
,
2172 GLintptr offset
, GLsizei stride
)
2174 GET_CURRENT_CONTEXT(ctx
);
2175 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2176 buffer
, offset
, stride
, true,
2177 "glBindVertexBuffer");
2182 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2185 GET_CURRENT_CONTEXT(ctx
);
2187 /* The ARB_vertex_attrib_binding spec says:
2189 * "An INVALID_OPERATION error is generated if no vertex array object
2192 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2193 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2194 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2195 "glBindVertexBuffer(No array object bound)");
2199 vertex_array_vertex_buffer_err(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2200 buffer
, offset
, stride
,
2201 "glBindVertexBuffer");
2206 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj
, GLuint bindingIndex
,
2207 GLuint buffer
, GLintptr offset
,
2210 GET_CURRENT_CONTEXT(ctx
);
2212 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2213 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2214 stride
, true, "glVertexArrayVertexBuffer");
2219 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
2220 GLintptr offset
, GLsizei stride
)
2222 GET_CURRENT_CONTEXT(ctx
);
2223 struct gl_vertex_array_object
*vao
;
2225 /* The ARB_direct_state_access specification says:
2227 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2228 * if <vaobj> is not [compatibility profile: zero or] the name of an
2229 * existing vertex array object."
2231 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
2235 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
2236 stride
, "glVertexArrayVertexBuffer");
2240 static ALWAYS_INLINE
void
2241 vertex_array_vertex_buffers(struct gl_context
*ctx
,
2242 struct gl_vertex_array_object
*vao
,
2243 GLuint first
, GLsizei count
, const GLuint
*buffers
,
2244 const GLintptr
*offsets
, const GLsizei
*strides
,
2245 bool no_error
, const char *func
)
2251 * The ARB_multi_bind spec says:
2253 * "If <buffers> is NULL, each affected vertex buffer binding point
2254 * from <first> through <first>+<count>-1 will be reset to have no
2255 * bound buffer object. In this case, the offsets and strides
2256 * associated with the binding points are set to default values,
2257 * ignoring <offsets> and <strides>."
2259 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
2261 for (i
= 0; i
< count
; i
++)
2262 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2268 /* Note that the error semantics for multi-bind commands differ from
2269 * those of other GL commands.
2271 * The Issues section in the ARB_multi_bind spec says:
2273 * "(11) Typically, OpenGL specifies that if an error is generated by
2274 * a command, that command has no effect. This is somewhat
2275 * unfortunate for multi-bind commands, because it would require
2276 * a first pass to scan the entire list of bound objects for
2277 * errors and then a second pass to actually perform the
2278 * bindings. Should we have different error semantics?
2280 * RESOLVED: Yes. In this specification, when the parameters for
2281 * one of the <count> binding points are invalid, that binding
2282 * point is not updated and an error will be generated. However,
2283 * other binding points in the same command will be updated if
2284 * their parameters are valid and no other error occurs."
2287 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
2289 for (i
= 0; i
< count
; i
++) {
2290 struct gl_buffer_object
*vbo
;
2293 /* The ARB_multi_bind spec says:
2295 * "An INVALID_VALUE error is generated if any value in
2296 * <offsets> or <strides> is negative (per binding)."
2298 if (offsets
[i
] < 0) {
2299 _mesa_error(ctx
, GL_INVALID_VALUE
,
2300 "%s(offsets[%u]=%" PRId64
" < 0)",
2301 func
, i
, (int64_t) offsets
[i
]);
2305 if (strides
[i
] < 0) {
2306 _mesa_error(ctx
, GL_INVALID_VALUE
,
2307 "%s(strides[%u]=%d < 0)",
2308 func
, i
, strides
[i
]);
2312 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
2313 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
2314 _mesa_error(ctx
, GL_INVALID_VALUE
,
2315 "%s(strides[%u]=%d > "
2316 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
2322 struct gl_vertex_buffer_binding
*binding
=
2323 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
2325 if (buffers
[i
] == binding
->BufferObj
->Name
)
2326 vbo
= binding
->BufferObj
;
2328 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
2333 vbo
= ctx
->Shared
->NullBufferObj
;
2336 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2337 vbo
, offsets
[i
], strides
[i
]);
2340 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
2345 vertex_array_vertex_buffers_err(struct gl_context
*ctx
,
2346 struct gl_vertex_array_object
*vao
,
2347 GLuint first
, GLsizei count
,
2348 const GLuint
*buffers
, const GLintptr
*offsets
,
2349 const GLsizei
*strides
, const char *func
)
2351 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2353 /* The ARB_multi_bind spec says:
2355 * "An INVALID_OPERATION error is generated if <first> + <count>
2356 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
2358 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
2359 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2360 "%s(first=%u + count=%d > the value of "
2361 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
2362 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
2366 vertex_array_vertex_buffers(ctx
, vao
, first
, count
, buffers
, offsets
,
2367 strides
, false, func
);
2372 _mesa_BindVertexBuffers_no_error(GLuint first
, GLsizei count
,
2373 const GLuint
*buffers
, const GLintptr
*offsets
,
2374 const GLsizei
*strides
)
2376 GET_CURRENT_CONTEXT(ctx
);
2378 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
2379 buffers
, offsets
, strides
, true,
2380 "glBindVertexBuffers");
2385 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
2386 const GLintptr
*offsets
, const GLsizei
*strides
)
2388 GET_CURRENT_CONTEXT(ctx
);
2390 /* The ARB_vertex_attrib_binding spec says:
2392 * "An INVALID_OPERATION error is generated if no
2393 * vertex array object is bound."
2395 if (ctx
->API
== API_OPENGL_CORE
&&
2396 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2397 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2398 "glBindVertexBuffers(No array object bound)");
2402 vertex_array_vertex_buffers_err(ctx
, ctx
->Array
.VAO
, first
, count
,
2403 buffers
, offsets
, strides
,
2404 "glBindVertexBuffers");
2409 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj
, GLuint first
,
2410 GLsizei count
, const GLuint
*buffers
,
2411 const GLintptr
*offsets
,
2412 const GLsizei
*strides
)
2414 GET_CURRENT_CONTEXT(ctx
);
2416 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2417 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
2418 buffers
, offsets
, strides
, true,
2419 "glVertexArrayVertexBuffers");
2424 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
2425 const GLuint
*buffers
,
2426 const GLintptr
*offsets
, const GLsizei
*strides
)
2428 GET_CURRENT_CONTEXT(ctx
);
2429 struct gl_vertex_array_object
*vao
;
2431 /* The ARB_direct_state_access specification says:
2433 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2434 * if <vaobj> is not [compatibility profile: zero or] the name of an
2435 * existing vertex array object."
2437 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
2441 vertex_array_vertex_buffers_err(ctx
, vao
, first
, count
,
2442 buffers
, offsets
, strides
,
2443 "glVertexArrayVertexBuffers");
2448 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
2449 GLboolean normalized
, GLboolean integer
,
2450 GLboolean doubles
, GLbitfield legalTypes
,
2451 GLsizei sizeMax
, GLuint relativeOffset
,
2454 GET_CURRENT_CONTEXT(ctx
);
2455 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2457 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2459 if (!_mesa_is_no_error_enabled(ctx
)) {
2460 /* The ARB_vertex_attrib_binding spec says:
2462 * "An INVALID_OPERATION error is generated under any of the
2463 * following conditions:
2464 * - if no vertex array object is currently bound (see section
2468 * This error condition only applies to VertexAttribFormat and
2469 * VertexAttribIFormat in the extension spec, but we assume that this
2470 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2471 * to all three functions.
2473 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2474 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2475 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2476 "%s(No array object bound)", func
);
2480 /* The ARB_vertex_attrib_binding spec says:
2482 * "The error INVALID_VALUE is generated if index is greater than or
2483 * equal to the value of MAX_VERTEX_ATTRIBS."
2485 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2486 _mesa_error(ctx
, GL_INVALID_VALUE
,
2487 "%s(attribindex=%u > "
2488 "GL_MAX_VERTEX_ATTRIBS)",
2493 if (!validate_array_format(ctx
, func
, ctx
->Array
.VAO
,
2494 VERT_ATTRIB_GENERIC(attribIndex
),
2495 legalTypes
, 1, sizeMax
, size
, type
,
2496 normalized
, integer
, doubles
, relativeOffset
,
2502 FLUSH_VERTICES(ctx
, 0);
2504 _mesa_update_array_format(ctx
, ctx
->Array
.VAO
,
2505 VERT_ATTRIB_GENERIC(attribIndex
), size
, type
,
2506 format
, normalized
, integer
, doubles
,
2512 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2513 GLboolean normalized
, GLuint relativeOffset
)
2515 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
2516 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2517 BGRA_OR_4
, relativeOffset
,
2518 "glVertexAttribFormat");
2523 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2524 GLuint relativeOffset
)
2526 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2527 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2528 relativeOffset
, "glVertexAttribIFormat");
2533 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2534 GLuint relativeOffset
)
2536 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2537 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2538 relativeOffset
, "glVertexAttribLFormat");
2543 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2544 GLenum type
, GLboolean normalized
,
2545 GLboolean integer
, GLboolean doubles
,
2546 GLbitfield legalTypes
, GLsizei sizeMax
,
2547 GLuint relativeOffset
, const char *func
)
2549 GET_CURRENT_CONTEXT(ctx
);
2550 struct gl_vertex_array_object
*vao
;
2552 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2554 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2556 if (_mesa_is_no_error_enabled(ctx
)) {
2557 vao
= _mesa_lookup_vao(ctx
, vaobj
);
2561 /* The ARB_direct_state_access spec says:
2563 * "An INVALID_OPERATION error is generated by
2564 * VertexArrayAttrib*Format if <vaobj> is not [compatibility profile:
2565 * zero or] the name of an existing vertex array object."
2567 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2571 /* The ARB_vertex_attrib_binding spec says:
2573 * "The error INVALID_VALUE is generated if index is greater than or
2574 * equal to the value of MAX_VERTEX_ATTRIBS."
2576 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2577 _mesa_error(ctx
, GL_INVALID_VALUE
,
2578 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2583 if (!validate_array_format(ctx
, func
, vao
,
2584 VERT_ATTRIB_GENERIC(attribIndex
),
2585 legalTypes
, 1, sizeMax
, size
, type
,
2586 normalized
, integer
, doubles
, relativeOffset
,
2592 FLUSH_VERTICES(ctx
, 0);
2594 _mesa_update_array_format(ctx
, vao
, VERT_ATTRIB_GENERIC(attribIndex
), size
,
2595 type
, format
, normalized
, integer
, doubles
,
2601 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2602 GLenum type
, GLboolean normalized
,
2603 GLuint relativeOffset
)
2605 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2606 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2607 BGRA_OR_4
, relativeOffset
,
2608 "glVertexArrayAttribFormat");
2613 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2614 GLint size
, GLenum type
,
2615 GLuint relativeOffset
)
2617 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2618 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2620 "glVertexArrayAttribIFormat");
2625 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2626 GLint size
, GLenum type
,
2627 GLuint relativeOffset
)
2629 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2630 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2632 "glVertexArrayAttribLFormat");
2637 vertex_array_attrib_binding(struct gl_context
*ctx
,
2638 struct gl_vertex_array_object
*vao
,
2639 GLuint attribIndex
, GLuint bindingIndex
,
2642 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2644 /* The ARB_vertex_attrib_binding spec says:
2646 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2647 * <bindingindex> must be less than the value of
2648 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2651 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2652 _mesa_error(ctx
, GL_INVALID_VALUE
,
2653 "%s(attribindex=%u >= "
2654 "GL_MAX_VERTEX_ATTRIBS)",
2659 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2660 _mesa_error(ctx
, GL_INVALID_VALUE
,
2661 "%s(bindingindex=%u >= "
2662 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2663 func
, bindingIndex
);
2667 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2669 vertex_attrib_binding(ctx
, vao
,
2670 VERT_ATTRIB_GENERIC(attribIndex
),
2671 VERT_ATTRIB_GENERIC(bindingIndex
));
2676 _mesa_VertexAttribBinding_no_error(GLuint attribIndex
, GLuint bindingIndex
)
2678 GET_CURRENT_CONTEXT(ctx
);
2679 vertex_attrib_binding(ctx
, ctx
->Array
.VAO
,
2680 VERT_ATTRIB_GENERIC(attribIndex
),
2681 VERT_ATTRIB_GENERIC(bindingIndex
));
2686 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2688 GET_CURRENT_CONTEXT(ctx
);
2690 /* The ARB_vertex_attrib_binding spec says:
2692 * "An INVALID_OPERATION error is generated if no vertex array object
2695 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2696 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2697 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2698 "glVertexAttribBinding(No array object bound)");
2702 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2703 attribIndex
, bindingIndex
,
2704 "glVertexAttribBinding");
2709 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj
, GLuint attribIndex
,
2710 GLuint bindingIndex
)
2712 GET_CURRENT_CONTEXT(ctx
);
2714 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2715 vertex_attrib_binding(ctx
, vao
,
2716 VERT_ATTRIB_GENERIC(attribIndex
),
2717 VERT_ATTRIB_GENERIC(bindingIndex
));
2722 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2724 GET_CURRENT_CONTEXT(ctx
);
2725 struct gl_vertex_array_object
*vao
;
2727 /* The ARB_direct_state_access specification says:
2729 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2730 * if <vaobj> is not [compatibility profile: zero or] the name of an
2731 * existing vertex array object."
2733 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2737 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2738 "glVertexArrayAttribBinding");
2743 vertex_array_binding_divisor(struct gl_context
*ctx
,
2744 struct gl_vertex_array_object
*vao
,
2745 GLuint bindingIndex
, GLuint divisor
,
2748 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2750 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2751 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2755 /* The ARB_vertex_attrib_binding spec says:
2757 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2758 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2760 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2761 _mesa_error(ctx
, GL_INVALID_VALUE
,
2762 "%s(bindingindex=%u > "
2763 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2764 func
, bindingIndex
);
2768 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2773 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex
, GLuint divisor
)
2775 GET_CURRENT_CONTEXT(ctx
);
2776 vertex_binding_divisor(ctx
, ctx
->Array
.VAO
,
2777 VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2782 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2784 GET_CURRENT_CONTEXT(ctx
);
2786 /* The ARB_vertex_attrib_binding spec says:
2788 * "An INVALID_OPERATION error is generated if no vertex array object
2791 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2792 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2793 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2794 "glVertexBindingDivisor(No array object bound)");
2798 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2799 bindingIndex
, divisor
,
2800 "glVertexBindingDivisor");
2805 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj
, GLuint bindingIndex
,
2808 GET_CURRENT_CONTEXT(ctx
);
2810 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2811 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2816 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2819 struct gl_vertex_array_object
*vao
;
2820 GET_CURRENT_CONTEXT(ctx
);
2822 /* The ARB_direct_state_access specification says:
2824 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2825 * if <vaobj> is not [compatibility profile: zero or] the name of an
2826 * existing vertex array object."
2828 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2832 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2833 "glVertexArrayBindingDivisor");
2838 * Copy one vertex array to another.
2841 _mesa_copy_vertex_array(struct gl_context
*ctx
,
2842 struct gl_vertex_array
*dst
,
2843 struct gl_vertex_array
*src
)
2845 dst
->Size
= src
->Size
;
2846 dst
->Type
= src
->Type
;
2847 dst
->Format
= src
->Format
;
2848 dst
->StrideB
= src
->StrideB
;
2849 dst
->Ptr
= src
->Ptr
;
2850 dst
->Normalized
= src
->Normalized
;
2851 dst
->Integer
= src
->Integer
;
2852 dst
->Doubles
= src
->Doubles
;
2853 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2854 dst
->_ElementSize
= src
->_ElementSize
;
2855 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2859 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2860 struct gl_array_attributes
*dst
,
2861 const struct gl_array_attributes
*src
)
2863 dst
->Size
= src
->Size
;
2864 dst
->Type
= src
->Type
;
2865 dst
->Format
= src
->Format
;
2866 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
2867 dst
->RelativeOffset
= src
->RelativeOffset
;
2868 dst
->Format
= src
->Format
;
2869 dst
->Integer
= src
->Integer
;
2870 dst
->Doubles
= src
->Doubles
;
2871 dst
->Normalized
= src
->Normalized
;
2872 dst
->Ptr
= src
->Ptr
;
2873 dst
->Enabled
= src
->Enabled
;
2874 dst
->_ElementSize
= src
->_ElementSize
;
2878 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2879 struct gl_vertex_buffer_binding
*dst
,
2880 const struct gl_vertex_buffer_binding
*src
)
2882 dst
->Offset
= src
->Offset
;
2883 dst
->Stride
= src
->Stride
;
2884 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2885 dst
->_BoundArrays
= src
->_BoundArrays
;
2887 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2891 * Print current vertex object/array info. For debug.
2894 _mesa_print_arrays(struct gl_context
*ctx
)
2896 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2898 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
2901 for (i
= 0; i
< VERT_ATTRIB_MAX
; ++i
) {
2902 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
2903 if (!array
->Enabled
)
2906 const struct gl_vertex_buffer_binding
*binding
=
2907 &vao
->BufferBinding
[array
->BufferBindingIndex
];
2908 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
2910 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2911 "Stride=%d, Buffer=%u(Size %lu)\n",
2912 gl_vert_attrib_name((gl_vert_attrib
)i
),
2913 array
->Ptr
, _mesa_enum_to_string(array
->Type
), array
->Size
,
2914 array
->_ElementSize
, binding
->Stride
, bo
->Name
,
2915 (unsigned long) bo
->Size
);
2921 * Initialize vertex array state for given context.
2924 _mesa_init_varray(struct gl_context
*ctx
)
2926 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2927 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2928 ctx
->Array
._EmptyVAO
= _mesa_new_vao(ctx
, ~0u);
2929 _mesa_reference_vao(ctx
, &ctx
->Array
._DrawVAO
, ctx
->Array
._EmptyVAO
);
2930 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2932 ctx
->Array
.Objects
= _mesa_NewHashTable();
2937 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2940 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2942 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2943 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2944 _mesa_delete_vao(ctx
, vao
);
2949 * Free vertex array state for given context.
2952 _mesa_free_varray_data(struct gl_context
*ctx
)
2954 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2955 _mesa_DeleteHashTable(ctx
->Array
.Objects
);