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 * Sets the BufferBindingIndex field for the vertex attribute given by
133 vertex_attrib_binding(struct gl_context
*ctx
,
134 struct gl_vertex_array_object
*vao
,
138 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attribIndex
];
140 if (array
->BufferBindingIndex
!= bindingIndex
) {
141 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
143 if (_mesa_is_bufferobj(vao
->BufferBinding
[bindingIndex
].BufferObj
))
144 vao
->VertexAttribBufferMask
|= array_bit
;
146 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
148 vao
->BufferBinding
[array
->BufferBindingIndex
]._BoundArrays
&= ~array_bit
;
149 vao
->BufferBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
151 array
->BufferBindingIndex
= bindingIndex
;
153 vao
->NewArrays
|= array_bit
;
159 * Binds a buffer object to the vertex buffer binding point given by index,
160 * and sets the Offset and Stride fields.
163 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
164 struct gl_vertex_array_object
*vao
,
166 struct gl_buffer_object
*vbo
,
167 GLintptr offset
, GLsizei stride
)
169 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
171 if (binding
->BufferObj
!= vbo
||
172 binding
->Offset
!= offset
||
173 binding
->Stride
!= stride
) {
175 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
177 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
179 binding
->Offset
= offset
;
180 binding
->Stride
= stride
;
182 if (!_mesa_is_bufferobj(vbo
))
183 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
185 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
187 vao
->NewArrays
|= binding
->_BoundArrays
;
193 * Sets the InstanceDivisor field in the vertex buffer binding point
194 * given by bindingIndex.
197 vertex_binding_divisor(struct gl_context
*ctx
,
198 struct gl_vertex_array_object
*vao
,
202 struct gl_vertex_buffer_binding
*binding
=
203 &vao
->BufferBinding
[bindingIndex
];
205 if (binding
->InstanceDivisor
!= divisor
) {
206 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
207 binding
->InstanceDivisor
= divisor
;
208 vao
->NewArrays
|= binding
->_BoundArrays
;
214 * Examine the API profile and extensions to determine which types are legal
215 * for vertex arrays. This is called once from update_array_format().
218 get_legal_types_mask(const struct gl_context
*ctx
)
220 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
222 if (_mesa_is_gles(ctx
)) {
223 legalTypesMask
&= ~(FIXED_GL_BIT
|
225 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
227 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
228 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
229 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
230 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
231 * quite as trivial as we'd like because it uses a different enum value
232 * for GL_HALF_FLOAT_OES.
234 if (ctx
->Version
< 30) {
235 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
237 UNSIGNED_INT_2_10_10_10_REV_BIT
|
238 INT_2_10_10_10_REV_BIT
);
240 if (!_mesa_has_OES_vertex_half_float(ctx
))
241 legalTypesMask
&= ~HALF_BIT
;
245 legalTypesMask
&= ~FIXED_ES_BIT
;
247 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
248 legalTypesMask
&= ~FIXED_GL_BIT
;
250 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
251 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
252 INT_2_10_10_10_REV_BIT
);
254 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
255 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
258 return legalTypesMask
;
262 get_array_format(const struct gl_context
*ctx
, GLint sizeMax
, GLint
*size
)
264 GLenum format
= GL_RGBA
;
266 /* Do size parameter checking.
267 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
268 * must be handled specially.
270 if (ctx
->Extensions
.EXT_vertex_array_bgra
&& sizeMax
== BGRA_OR_4
&&
281 * \param attrib The index of the attribute array
282 * \param size Components per element (1, 2, 3 or 4)
283 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
284 * \param format Either GL_RGBA or GL_BGRA.
285 * \param normalized Whether integer types are converted to floats in [-1, 1]
286 * \param integer Integer-valued values (will not be normalized to [-1, 1])
287 * \param doubles Double values not reduced to floats
288 * \param relativeOffset Offset of the first element relative to the binding
290 * \param flush_verties Should \c FLUSH_VERTICES be invoked before updating
294 _mesa_update_array_format(struct gl_context
*ctx
,
295 struct gl_vertex_array_object
*vao
,
296 GLuint attrib
, GLint size
, GLenum type
,
297 GLenum format
, GLboolean normalized
,
298 GLboolean integer
, GLboolean doubles
,
299 GLuint relativeOffset
)
301 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
306 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
307 assert(elementSize
!= -1);
311 array
->Format
= format
;
312 array
->Normalized
= normalized
;
313 array
->Integer
= integer
;
314 array
->Doubles
= doubles
;
315 array
->RelativeOffset
= relativeOffset
;
316 array
->_ElementSize
= elementSize
;
318 vao
->NewArrays
|= VERT_BIT(attrib
);
319 ctx
->NewState
|= _NEW_ARRAY
;
323 * Does error checking of the format in an attrib array.
325 * Called by *Pointer() and VertexAttrib*Format().
327 * \param func Name of calling function used for error reporting
328 * \param attrib The index of the attribute array
329 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
330 * \param sizeMin Min allowable size value
331 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
332 * \param size Components per element (1, 2, 3 or 4)
333 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
334 * \param normalized Whether integer types are converted to floats in [-1, 1]
335 * \param integer Integer-valued values (will not be normalized to [-1, 1])
336 * \param doubles Double values not reduced to floats
337 * \param relativeOffset Offset of the first element relative to the binding offset.
338 * \return bool True if validation is successful, False otherwise.
341 validate_array_format(struct gl_context
*ctx
, const char *func
,
342 struct gl_vertex_array_object
*vao
,
343 GLuint attrib
, GLbitfield legalTypesMask
,
344 GLint sizeMin
, GLint sizeMax
,
345 GLint size
, GLenum type
, GLboolean normalized
,
346 GLboolean integer
, GLboolean doubles
,
347 GLuint relativeOffset
, GLenum format
)
351 /* at most, one of these bools can be true */
352 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
354 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
355 /* Compute the LegalTypesMask only once, unless the context API has
356 * changed, in which case we want to compute it again. We can't do this
357 * in _mesa_init_varrays() below because extensions are not yet enabled
360 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
361 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
364 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
366 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
367 /* BGRA ordering is not supported in ES contexts.
372 typeBit
= type_to_bit(ctx
, type
);
373 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
374 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
375 func
, _mesa_enum_to_string(type
));
379 if (format
== GL_BGRA
) {
380 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
382 * "An INVALID_OPERATION error is generated under any of the following
385 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
386 * or UNSIGNED_INT_2_10_10_10_REV;
388 * • size is BGRA and normalized is FALSE;"
390 bool bgra_error
= false;
392 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
393 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
394 type
!= GL_INT_2_10_10_10_REV
&&
395 type
!= GL_UNSIGNED_BYTE
)
397 } else if (type
!= GL_UNSIGNED_BYTE
)
401 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
402 func
, _mesa_enum_to_string(type
));
407 _mesa_error(ctx
, GL_INVALID_OPERATION
,
408 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
412 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
413 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
417 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
418 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
419 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
420 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
424 /* The ARB_vertex_attrib_binding_spec says:
426 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
427 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
429 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
430 _mesa_error(ctx
, GL_INVALID_VALUE
,
431 "%s(relativeOffset=%d > "
432 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
433 func
, relativeOffset
);
437 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
438 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
439 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
447 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
449 * \param func name of calling function used for error reporting
450 * \param attrib the attribute array index to update
451 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
452 * \param sizeMin min allowable size value
453 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
454 * \param size components per element (1, 2, 3 or 4)
455 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
456 * \param stride stride between elements, in elements
457 * \param normalized are integer types converted to floats in [-1, 1]?
458 * \param integer integer-valued values (will not be normalized to [-1,1])
459 * \param doubles Double values not reduced to floats
460 * \param ptr the address (or offset inside VBO) of the array data
463 validate_array(struct gl_context
*ctx
, const char *func
,
464 GLuint attrib
, GLbitfield legalTypesMask
,
465 GLint sizeMin
, GLint sizeMax
,
466 GLint size
, GLenum type
, GLsizei stride
,
467 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
470 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
472 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
474 * "Client vertex arrays - all vertex array attribute pointers must
475 * refer to buffer objects (section 2.9.2). The default vertex array
476 * object (the name zero) is also deprecated. Calling
477 * VertexAttribPointer when no buffer object or no vertex array object
478 * is bound will generate an INVALID_OPERATION error..."
480 * The check for VBOs is handled below.
482 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
483 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
489 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
493 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
494 stride
> ctx
->Const
.MaxVertexAttribStride
) {
495 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
496 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
500 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
502 * "An INVALID_OPERATION error is generated under any of the following
507 * * any of the *Pointer commands specifying the location and
508 * organization of vertex array data are called while zero is bound
509 * to the ARRAY_BUFFER buffer object binding point (see section
510 * 2.9.6), and the pointer argument is not NULL."
512 if (ptr
!= NULL
&& vao
!= ctx
->Array
.DefaultVAO
&&
513 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
514 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
521 validate_array_and_format(struct gl_context
*ctx
, const char *func
,
522 GLuint attrib
, GLbitfield legalTypes
,
523 GLint sizeMin
, GLint sizeMax
,
524 GLint size
, GLenum type
, GLsizei stride
,
525 GLboolean normalized
, GLboolean integer
,
526 GLboolean doubles
, GLenum format
, const GLvoid
*ptr
,
527 struct gl_vertex_array_object
*vao
)
529 validate_array(ctx
, func
, attrib
, legalTypes
, sizeMin
, sizeMax
, size
,
530 type
, stride
, normalized
, integer
, doubles
, ptr
);
532 return validate_array_format(ctx
, func
, vao
, attrib
, legalTypes
, sizeMin
,
533 sizeMax
, size
, type
, normalized
, integer
,
539 * Update state for glVertex/Color/TexCoord/...Pointer functions.
541 * \param attrib the attribute array index to update
542 * \param format Either GL_RGBA or GL_BGRA.
543 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
544 * \param size components per element (1, 2, 3 or 4)
545 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
546 * \param stride stride between elements, in elements
547 * \param normalized are integer types converted to floats in [-1, 1]?
548 * \param integer integer-valued values (will not be normalized to [-1,1])
549 * \param doubles Double values not reduced to floats
550 * \param ptr the address (or offset inside VBO) of the array data
553 update_array(struct gl_context
*ctx
,
554 GLuint attrib
, GLenum format
,
556 GLint size
, GLenum type
, GLsizei stride
,
557 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
560 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
562 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
563 normalized
, integer
, doubles
, 0);
565 /* Reset the vertex attrib binding */
566 vertex_attrib_binding(ctx
, vao
, attrib
, attrib
);
568 /* The Stride and Ptr fields are not set by update_array_format() */
569 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attrib
];
570 array
->Stride
= stride
;
573 /* Update the vertex buffer binding */
574 GLsizei effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
575 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
576 ctx
->Array
.ArrayBufferObj
, (GLintptr
) ptr
,
581 _mesa_VertexPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
584 GET_CURRENT_CONTEXT(ctx
);
585 FLUSH_VERTICES(ctx
, 0);
587 update_array(ctx
, VERT_ATTRIB_POS
, GL_RGBA
, 4, size
, type
, stride
,
588 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
593 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
595 GET_CURRENT_CONTEXT(ctx
);
597 FLUSH_VERTICES(ctx
, 0);
599 GLenum format
= GL_RGBA
;
600 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
601 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
602 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
603 DOUBLE_BIT
| HALF_BIT
|
604 UNSIGNED_INT_2_10_10_10_REV_BIT
|
605 INT_2_10_10_10_REV_BIT
);
607 if (!validate_array_and_format(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
608 legalTypes
, 2, 4, size
, type
, stride
,
609 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
,
610 ptr
, ctx
->Array
.VAO
))
613 update_array(ctx
, VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
614 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
619 _mesa_NormalPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
621 GET_CURRENT_CONTEXT(ctx
);
622 FLUSH_VERTICES(ctx
, 0);
624 update_array(ctx
, VERT_ATTRIB_NORMAL
, GL_RGBA
, 3, 3, type
, stride
, GL_TRUE
,
625 GL_FALSE
, GL_FALSE
, ptr
);
630 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
632 GET_CURRENT_CONTEXT(ctx
);
634 FLUSH_VERTICES(ctx
, 0);
636 GLenum format
= GL_RGBA
;
637 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
638 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
639 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
640 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
641 UNSIGNED_INT_2_10_10_10_REV_BIT
|
642 INT_2_10_10_10_REV_BIT
);
644 if (!validate_array_and_format(ctx
, "glNormalPointer",
645 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
646 type
, stride
, GL_TRUE
, GL_FALSE
,
647 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
650 update_array(ctx
, VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
651 GL_FALSE
, GL_FALSE
, ptr
);
656 _mesa_ColorPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
659 GET_CURRENT_CONTEXT(ctx
);
660 FLUSH_VERTICES(ctx
, 0);
662 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
663 update_array(ctx
, VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
664 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
669 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
671 GET_CURRENT_CONTEXT(ctx
);
672 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
674 FLUSH_VERTICES(ctx
, 0);
676 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
677 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
678 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
679 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
680 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
681 INT_BIT
| UNSIGNED_INT_BIT
|
682 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
683 UNSIGNED_INT_2_10_10_10_REV_BIT
|
684 INT_2_10_10_10_REV_BIT
);
686 if (!validate_array_and_format(ctx
, "glColorPointer",
687 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
688 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
689 GL_FALSE
, GL_FALSE
, format
, ptr
,
693 update_array(ctx
, VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
694 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
699 _mesa_FogCoordPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
701 GET_CURRENT_CONTEXT(ctx
);
702 FLUSH_VERTICES(ctx
, 0);
704 update_array(ctx
, VERT_ATTRIB_FOG
, GL_RGBA
, 1, 1, type
, stride
, GL_FALSE
,
705 GL_FALSE
, GL_FALSE
, ptr
);
710 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
712 GET_CURRENT_CONTEXT(ctx
);
714 FLUSH_VERTICES(ctx
, 0);
716 GLenum format
= GL_RGBA
;
717 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
719 if (!validate_array_and_format(ctx
, "glFogCoordPointer",
720 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
721 type
, stride
, GL_FALSE
, GL_FALSE
,
722 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
725 update_array(ctx
, VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
726 GL_FALSE
, GL_FALSE
, ptr
);
731 _mesa_IndexPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
733 GET_CURRENT_CONTEXT(ctx
);
734 FLUSH_VERTICES(ctx
, 0);
736 update_array(ctx
, VERT_ATTRIB_COLOR_INDEX
, GL_RGBA
, 1, 1, type
, stride
,
737 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
742 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
744 GET_CURRENT_CONTEXT(ctx
);
746 FLUSH_VERTICES(ctx
, 0);
748 GLenum format
= GL_RGBA
;
749 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
750 FLOAT_BIT
| DOUBLE_BIT
);
752 if (!validate_array_and_format(ctx
, "glIndexPointer",
753 VERT_ATTRIB_COLOR_INDEX
,
754 legalTypes
, 1, 1, 1, type
, stride
,
755 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
,
756 ptr
, ctx
->Array
.VAO
))
759 update_array(ctx
, VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
760 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
765 _mesa_SecondaryColorPointer_no_error(GLint size
, GLenum type
,
766 GLsizei stride
, const GLvoid
*ptr
)
768 GET_CURRENT_CONTEXT(ctx
);
769 FLUSH_VERTICES(ctx
, 0);
771 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
772 update_array(ctx
, VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
773 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
778 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
779 GLsizei stride
, const GLvoid
*ptr
)
781 GET_CURRENT_CONTEXT(ctx
);
783 FLUSH_VERTICES(ctx
, 0);
785 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
786 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
787 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
788 INT_BIT
| UNSIGNED_INT_BIT
|
789 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
790 UNSIGNED_INT_2_10_10_10_REV_BIT
|
791 INT_2_10_10_10_REV_BIT
);
793 if (!validate_array_and_format(ctx
, "glSecondaryColorPointer",
794 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
795 BGRA_OR_4
, size
, type
, stride
,
796 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, ptr
,
800 update_array(ctx
, VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
801 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
806 _mesa_TexCoordPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
809 GET_CURRENT_CONTEXT(ctx
);
810 const GLuint unit
= ctx
->Array
.ActiveTexture
;
811 FLUSH_VERTICES(ctx
, 0);
813 update_array(ctx
, VERT_ATTRIB_TEX(unit
), GL_RGBA
, 4, size
, type
,
814 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
819 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
822 GET_CURRENT_CONTEXT(ctx
);
823 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
824 const GLuint unit
= ctx
->Array
.ActiveTexture
;
826 FLUSH_VERTICES(ctx
, 0);
828 GLenum format
= GL_RGBA
;
829 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
830 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
831 : (SHORT_BIT
| INT_BIT
|
832 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
833 UNSIGNED_INT_2_10_10_10_REV_BIT
|
834 INT_2_10_10_10_REV_BIT
);
836 if (!validate_array_and_format(ctx
, "glTexCoordPointer",
837 VERT_ATTRIB_TEX(unit
), legalTypes
,
838 sizeMin
, 4, size
, type
, stride
,
839 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
,
843 update_array(ctx
, VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
844 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
849 _mesa_EdgeFlagPointer_no_error(GLsizei stride
, const GLvoid
*ptr
)
851 /* this is the same type that glEdgeFlag uses */
852 const GLboolean integer
= GL_FALSE
;
853 GET_CURRENT_CONTEXT(ctx
);
854 FLUSH_VERTICES(ctx
, 0);
856 update_array(ctx
, VERT_ATTRIB_EDGEFLAG
, GL_RGBA
, 1, 1, GL_UNSIGNED_BYTE
,
857 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
862 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
864 /* this is the same type that glEdgeFlag uses */
865 const GLboolean integer
= GL_FALSE
;
866 GET_CURRENT_CONTEXT(ctx
);
868 FLUSH_VERTICES(ctx
, 0);
870 GLenum format
= GL_RGBA
;
871 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
873 if (!validate_array_and_format(ctx
, "glEdgeFlagPointer",
874 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
875 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
876 GL_FALSE
, integer
, GL_FALSE
, format
, ptr
,
880 update_array(ctx
, VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
881 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
886 _mesa_PointSizePointerOES_no_error(GLenum type
, GLsizei stride
,
889 GET_CURRENT_CONTEXT(ctx
);
890 FLUSH_VERTICES(ctx
, 0);
892 update_array(ctx
, VERT_ATTRIB_POINT_SIZE
, GL_RGBA
, 1, 1, type
, stride
,
893 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
898 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
900 GET_CURRENT_CONTEXT(ctx
);
902 FLUSH_VERTICES(ctx
, 0);
904 GLenum format
= GL_RGBA
;
905 if (ctx
->API
!= API_OPENGLES
) {
906 _mesa_error(ctx
, GL_INVALID_OPERATION
,
907 "glPointSizePointer(ES 1.x only)");
911 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
913 if (!validate_array_and_format(ctx
, "glPointSizePointer",
914 VERT_ATTRIB_POINT_SIZE
, legalTypes
,
915 1, 1, 1, type
, stride
, GL_FALSE
, GL_FALSE
,
916 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
919 update_array(ctx
, VERT_ATTRIB_POINT_SIZE
, format
, 1, 1, type
, stride
,
920 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
925 _mesa_VertexAttribPointer_no_error(GLuint index
, GLint size
, GLenum type
,
926 GLboolean normalized
,
927 GLsizei stride
, const GLvoid
*ptr
)
929 GET_CURRENT_CONTEXT(ctx
);
931 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
932 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
933 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
938 * Set a generic vertex attribute array.
939 * Note that these arrays DO NOT alias the conventional GL vertex arrays
940 * (position, normal, color, fog, texcoord, etc).
943 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
944 GLboolean normalized
,
945 GLsizei stride
, const GLvoid
*ptr
)
947 GET_CURRENT_CONTEXT(ctx
);
949 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
950 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
951 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(idx)");
955 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
956 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
957 INT_BIT
| UNSIGNED_INT_BIT
|
958 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
959 FIXED_ES_BIT
| FIXED_GL_BIT
|
960 UNSIGNED_INT_2_10_10_10_REV_BIT
|
961 INT_2_10_10_10_REV_BIT
|
962 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
964 if (!validate_array_and_format(ctx
, "glVertexAttribPointer",
965 VERT_ATTRIB_GENERIC(index
), legalTypes
,
966 1, BGRA_OR_4
, size
, type
, stride
,
967 normalized
, GL_FALSE
, GL_FALSE
, format
,
968 ptr
, ctx
->Array
.VAO
))
971 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
972 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
977 _mesa_VertexAttribIPointer_no_error(GLuint index
, GLint size
, GLenum type
,
978 GLsizei stride
, const GLvoid
*ptr
)
980 const GLboolean normalized
= GL_FALSE
;
981 const GLboolean integer
= GL_TRUE
;
982 GET_CURRENT_CONTEXT(ctx
);
984 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
985 stride
, normalized
, integer
, GL_FALSE
, ptr
);
990 * GL_EXT_gpu_shader4 / GL 3.0.
991 * Set an integer-valued vertex attribute array.
992 * Note that these arrays DO NOT alias the conventional GL vertex arrays
993 * (position, normal, color, fog, texcoord, etc).
996 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
997 GLsizei stride
, const GLvoid
*ptr
)
999 const GLboolean normalized
= GL_FALSE
;
1000 const GLboolean integer
= GL_TRUE
;
1001 GET_CURRENT_CONTEXT(ctx
);
1003 GLenum format
= GL_RGBA
;
1004 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1005 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
1009 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1010 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1011 INT_BIT
| UNSIGNED_INT_BIT
);
1013 if (!validate_array_and_format(ctx
, "glVertexAttribIPointer",
1014 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1015 1, 4, size
, type
, stride
,
1016 normalized
, integer
, GL_FALSE
, format
,
1017 ptr
, ctx
->Array
.VAO
))
1020 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1021 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1026 _mesa_VertexAttribLPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1027 GLsizei stride
, const GLvoid
*ptr
)
1029 GET_CURRENT_CONTEXT(ctx
);
1031 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1032 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1037 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
1038 GLsizei stride
, const GLvoid
*ptr
)
1040 GET_CURRENT_CONTEXT(ctx
);
1042 GLenum format
= GL_RGBA
;
1043 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1044 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
1048 const GLbitfield legalTypes
= DOUBLE_BIT
;
1050 if (!validate_array_and_format(ctx
, "glVertexAttribLPointer",
1051 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1052 1, 4, size
, type
, stride
,
1053 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
,
1054 ptr
, ctx
->Array
.VAO
))
1057 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1058 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1063 _mesa_enable_vertex_array_attrib(struct gl_context
*ctx
,
1064 struct gl_vertex_array_object
*vao
,
1067 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
1069 if (!vao
->VertexAttrib
[attrib
].Enabled
) {
1070 /* was disabled, now being enabled */
1071 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1072 vao
->VertexAttrib
[attrib
].Enabled
= GL_TRUE
;
1073 vao
->_Enabled
|= VERT_BIT(attrib
);
1074 vao
->NewArrays
|= VERT_BIT(attrib
);
1079 enable_vertex_array_attrib(struct gl_context
*ctx
,
1080 struct gl_vertex_array_object
*vao
,
1084 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1085 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
1089 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1094 _mesa_EnableVertexAttribArray(GLuint index
)
1096 GET_CURRENT_CONTEXT(ctx
);
1097 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
1098 "glEnableVertexAttribArray");
1103 _mesa_EnableVertexAttribArray_no_error(GLuint index
)
1105 GET_CURRENT_CONTEXT(ctx
);
1106 _mesa_enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1107 VERT_ATTRIB_GENERIC(index
));
1112 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1114 GET_CURRENT_CONTEXT(ctx
);
1115 struct gl_vertex_array_object
*vao
;
1117 /* The ARB_direct_state_access specification says:
1119 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1120 * and DisableVertexArrayAttrib if <vaobj> is not
1121 * [compatibility profile: zero or] the name of an existing vertex
1124 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
1128 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
1133 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1135 GET_CURRENT_CONTEXT(ctx
);
1136 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1137 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1142 disable_vertex_array_attrib(struct gl_context
*ctx
,
1143 struct gl_vertex_array_object
*vao
,
1146 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
1148 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
1149 /* was enabled, now being disabled */
1150 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1151 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
1152 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
1153 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
1159 _mesa_DisableVertexAttribArray(GLuint index
)
1161 GET_CURRENT_CONTEXT(ctx
);
1163 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1164 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexAttribArray(index)");
1168 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
);
1173 _mesa_DisableVertexAttribArray_no_error(GLuint index
)
1175 GET_CURRENT_CONTEXT(ctx
);
1176 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
);
1181 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1183 GET_CURRENT_CONTEXT(ctx
);
1184 struct gl_vertex_array_object
*vao
;
1186 /* The ARB_direct_state_access specification says:
1188 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1189 * and DisableVertexArrayAttrib if <vaobj> is not
1190 * [compatibility profile: zero or] the name of an existing vertex
1193 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
1197 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1198 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
1202 disable_vertex_array_attrib(ctx
, vao
, index
);
1207 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1209 GET_CURRENT_CONTEXT(ctx
);
1210 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1211 disable_vertex_array_attrib(ctx
, vao
, index
);
1216 * Return info for a vertex attribute array (no alias with legacy
1217 * vertex attributes (pos, normal, color, etc)). This function does
1218 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
1221 get_vertex_array_attrib(struct gl_context
*ctx
,
1222 const struct gl_vertex_array_object
*vao
,
1223 GLuint index
, GLenum pname
,
1226 const struct gl_array_attributes
*array
;
1228 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1229 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
1233 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
1235 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
1238 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
1239 return array
->Enabled
;
1240 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
1241 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
1242 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
1243 return array
->Stride
;
1244 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
1246 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
1247 return array
->Normalized
;
1248 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
1249 return vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
->Name
;
1250 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
1251 if ((_mesa_is_desktop_gl(ctx
)
1252 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
1253 || _mesa_is_gles3(ctx
)) {
1254 return array
->Integer
;
1257 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
1258 if (_mesa_is_desktop_gl(ctx
)) {
1259 return array
->Doubles
;
1262 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
1263 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
1264 || _mesa_is_gles3(ctx
)) {
1265 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
1268 case GL_VERTEX_ATTRIB_BINDING
:
1269 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1270 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
1273 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
1274 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1275 return array
->RelativeOffset
;
1279 ; /* fall-through */
1283 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
1288 static const GLfloat
*
1289 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
1292 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
1293 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
1297 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1298 _mesa_error(ctx
, GL_INVALID_VALUE
,
1299 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
1303 assert(VERT_ATTRIB_GENERIC(index
) <
1304 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1306 FLUSH_CURRENT(ctx
, 0);
1307 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
1311 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
1313 GET_CURRENT_CONTEXT(ctx
);
1315 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1316 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
1322 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1324 "glGetVertexAttribfv");
1330 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1332 GET_CURRENT_CONTEXT(ctx
);
1334 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1335 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
1337 params
[0] = (GLdouble
) v
[0];
1338 params
[1] = (GLdouble
) v
[1];
1339 params
[2] = (GLdouble
) v
[2];
1340 params
[3] = (GLdouble
) v
[3];
1344 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1346 "glGetVertexAttribdv");
1351 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1353 GET_CURRENT_CONTEXT(ctx
);
1355 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1357 (const GLdouble
*)get_current_attrib(ctx
, index
,
1358 "glGetVertexAttribLdv");
1367 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1369 "glGetVertexAttribLdv");
1374 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1376 GET_CURRENT_CONTEXT(ctx
);
1378 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1379 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1381 /* XXX should floats in[0,1] be scaled to full int range? */
1382 params
[0] = (GLint
) v
[0];
1383 params
[1] = (GLint
) v
[1];
1384 params
[2] = (GLint
) v
[2];
1385 params
[3] = (GLint
) v
[3];
1389 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1391 "glGetVertexAttribiv");
1396 _mesa_GetVertexAttribLui64vARB(GLuint index
, GLenum pname
, GLuint64EXT
*params
)
1398 GET_CURRENT_CONTEXT(ctx
);
1400 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1402 (const GLuint64
*)get_current_attrib(ctx
, index
,
1403 "glGetVertexAttribLui64vARB");
1412 params
[0] = (GLuint64
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1414 "glGetVertexAttribLui64vARB");
1421 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1423 GET_CURRENT_CONTEXT(ctx
);
1425 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1426 const GLint
*v
= (const GLint
*)
1427 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1433 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1435 "glGetVertexAttribIiv");
1442 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1444 GET_CURRENT_CONTEXT(ctx
);
1446 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1447 const GLuint
*v
= (const GLuint
*)
1448 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1454 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1456 "glGetVertexAttribIuiv");
1462 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1464 GET_CURRENT_CONTEXT(ctx
);
1466 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1467 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1471 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1472 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1476 assert(VERT_ATTRIB_GENERIC(index
) <
1477 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1479 *pointer
= (GLvoid
*)
1480 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1484 /** ARB_direct_state_access */
1486 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1487 GLenum pname
, GLint
*params
)
1489 GET_CURRENT_CONTEXT(ctx
);
1490 struct gl_vertex_array_object
*vao
;
1492 /* The ARB_direct_state_access specification says:
1494 * "An INVALID_OPERATION error is generated if <vaobj> is not
1495 * [compatibility profile: zero or] the name of an existing
1496 * vertex array object."
1498 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexediv");
1502 /* The ARB_direct_state_access specification says:
1504 * "For GetVertexArrayIndexediv, <pname> must be one of
1505 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1506 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1507 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1508 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1509 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1513 * "Add GetVertexArrayIndexediv in 'Get Command' for
1514 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1515 * VERTEX_ATTRIB_BINDING,
1516 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1517 * VERTEX_BINDING_OFFSET, and
1518 * VERTEX_BINDING_STRIDE states"
1520 * The only parameter name common to both lists is
1521 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1522 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1523 * pretty clear however that the intent is that it should be possible
1524 * to query all vertex attrib and binding states that can be set with
1528 case GL_VERTEX_BINDING_OFFSET
:
1529 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1531 case GL_VERTEX_BINDING_STRIDE
:
1532 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1534 case GL_VERTEX_BINDING_DIVISOR
:
1535 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1537 case GL_VERTEX_BINDING_BUFFER
:
1538 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1541 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1542 "glGetVertexArrayIndexediv");
1549 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1550 GLenum pname
, GLint64
*params
)
1552 GET_CURRENT_CONTEXT(ctx
);
1553 struct gl_vertex_array_object
*vao
;
1555 /* The ARB_direct_state_access specification says:
1557 * "An INVALID_OPERATION error is generated if <vaobj> is not
1558 * [compatibility profile: zero or] the name of an existing
1559 * vertex array object."
1561 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1565 /* The ARB_direct_state_access specification says:
1567 * "For GetVertexArrayIndexed64iv, <pname> must be
1568 * VERTEX_BINDING_OFFSET."
1572 * "An INVALID_ENUM error is generated if <pname> is not one of
1573 * the valid values listed above for the corresponding command."
1575 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1576 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1577 "pname != GL_VERTEX_BINDING_OFFSET)");
1581 /* The ARB_direct_state_access specification says:
1583 * "An INVALID_VALUE error is generated if <index> is greater than
1584 * or equal to the value of MAX_VERTEX_ATTRIBS."
1586 * Since the index refers to a buffer binding in this case, the intended
1587 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1588 * required to be the same, so in practice this doesn't matter.
1590 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1591 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1592 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1593 index
, ctx
->Const
.MaxVertexAttribBindings
);
1597 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1602 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1603 GLsizei count
, const GLvoid
*ptr
)
1606 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1611 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1615 _mesa_NormalPointer(type
, stride
, ptr
);
1620 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1624 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1629 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1633 _mesa_IndexPointer(type
, stride
, ptr
);
1638 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1639 GLsizei count
, const GLvoid
*ptr
)
1642 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1647 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1650 _mesa_EdgeFlagPointer(stride
, ptr
);
1655 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1657 GET_CURRENT_CONTEXT(ctx
);
1658 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1659 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1660 GLenum ctype
= 0; /* color type */
1661 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1662 const GLint toffset
= 0; /* always zero */
1663 GLint defstride
; /* default stride */
1666 FLUSH_VERTICES(ctx
, 0);
1668 f
= sizeof(GLfloat
);
1669 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1672 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1678 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1679 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1684 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1685 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1690 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1691 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1692 ctype
= GL_UNSIGNED_BYTE
;
1695 defstride
= c
+ 2*f
;
1698 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1699 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1700 ctype
= GL_UNSIGNED_BYTE
;
1703 defstride
= c
+ 3*f
;
1706 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1707 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1714 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1715 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1720 case GL_C4F_N3F_V3F
:
1721 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1722 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1730 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1731 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1736 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1737 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1741 case GL_T2F_C4UB_V3F
:
1742 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1743 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1744 ctype
= GL_UNSIGNED_BYTE
;
1749 case GL_T2F_C3F_V3F
:
1750 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1751 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1757 case GL_T2F_N3F_V3F
:
1758 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1759 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1764 case GL_T2F_C4F_N3F_V3F
:
1765 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1766 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1773 case GL_T4F_C4F_N3F_V4F
:
1774 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1775 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1783 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1791 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1792 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1793 /* XXX also disable secondary color and generic arrays? */
1797 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1798 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1799 (GLubyte
*) pointer
+ toffset
);
1802 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1807 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1808 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1809 (GLubyte
*) pointer
+ coffset
);
1812 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1818 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1819 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1822 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1826 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1827 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1828 (GLubyte
*) pointer
+ voffset
);
1833 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1835 GET_CURRENT_CONTEXT(ctx
);
1837 FLUSH_VERTICES(ctx
, 0);
1839 if (MESA_VERBOSE
& VERBOSE_API
)
1840 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1843 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1847 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1850 if (ctx
->Array
.LockCount
!= 0) {
1851 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1855 ctx
->Array
.LockFirst
= first
;
1856 ctx
->Array
.LockCount
= count
;
1858 ctx
->NewState
|= _NEW_ARRAY
;
1863 _mesa_UnlockArraysEXT( void )
1865 GET_CURRENT_CONTEXT(ctx
);
1867 FLUSH_VERTICES(ctx
, 0);
1869 if (MESA_VERBOSE
& VERBOSE_API
)
1870 _mesa_debug(ctx
, "glUnlockArrays\n");
1872 if (ctx
->Array
.LockCount
== 0) {
1873 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1877 ctx
->Array
.LockFirst
= 0;
1878 ctx
->Array
.LockCount
= 0;
1879 ctx
->NewState
|= _NEW_ARRAY
;
1883 /* GL_IBM_multimode_draw_arrays */
1885 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1886 const GLsizei
* count
,
1887 GLsizei primcount
, GLint modestride
)
1889 GET_CURRENT_CONTEXT(ctx
);
1892 FLUSH_VERTICES(ctx
, 0);
1894 for ( i
= 0 ; i
< primcount
; i
++ ) {
1895 if ( count
[i
] > 0 ) {
1896 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1897 CALL_DrawArrays(ctx
->CurrentServerDispatch
, ( m
, first
[i
], count
[i
] ));
1903 /* GL_IBM_multimode_draw_arrays */
1905 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1906 GLenum type
, const GLvoid
* const * indices
,
1907 GLsizei primcount
, GLint modestride
)
1909 GET_CURRENT_CONTEXT(ctx
);
1912 FLUSH_VERTICES(ctx
, 0);
1914 /* XXX not sure about ARB_vertex_buffer_object handling here */
1916 for ( i
= 0 ; i
< primcount
; i
++ ) {
1917 if ( count
[i
] > 0 ) {
1918 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1919 CALL_DrawElements(ctx
->CurrentServerDispatch
, ( m
, count
[i
], type
,
1927 primitive_restart_index(struct gl_context
*ctx
, GLuint index
)
1929 if (ctx
->Array
.RestartIndex
!= index
) {
1930 FLUSH_VERTICES(ctx
, 0);
1931 ctx
->Array
.RestartIndex
= index
;
1937 * GL_NV_primitive_restart and GL 3.1
1940 _mesa_PrimitiveRestartIndex(GLuint index
)
1942 GET_CURRENT_CONTEXT(ctx
);
1944 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1945 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1949 primitive_restart_index(ctx
, index
);
1954 _mesa_VertexAttribDivisor_no_error(GLuint index
, GLuint divisor
)
1956 GET_CURRENT_CONTEXT(ctx
);
1958 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1959 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1961 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
1963 /* The ARB_vertex_attrib_binding spec says:
1967 * void VertexAttribDivisor(uint index, uint divisor);
1969 * is equivalent to (assuming no errors are generated):
1971 * VertexAttribBinding(index, index);
1972 * VertexBindingDivisor(index, divisor);"
1974 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
1975 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
1980 * See GL_ARB_instanced_arrays.
1981 * Note that the instance divisor only applies to generic arrays, not
1982 * the legacy vertex arrays.
1985 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1987 GET_CURRENT_CONTEXT(ctx
);
1989 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1990 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1992 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1993 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1997 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1998 _mesa_error(ctx
, GL_INVALID_VALUE
,
1999 "glVertexAttribDivisor(index = %u)", index
);
2003 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2005 /* The ARB_vertex_attrib_binding spec says:
2009 * void VertexAttribDivisor(uint index, uint divisor);
2011 * is equivalent to (assuming no errors are generated):
2013 * VertexAttribBinding(index, index);
2014 * VertexBindingDivisor(index, divisor);"
2016 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2017 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2021 static ALWAYS_INLINE
void
2022 vertex_array_vertex_buffer(struct gl_context
*ctx
,
2023 struct gl_vertex_array_object
*vao
,
2024 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2025 GLsizei stride
, bool no_error
, const char *func
)
2027 struct gl_buffer_object
*vbo
;
2029 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
2030 vbo
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
2031 } else if (buffer
!= 0) {
2032 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
2034 if (!no_error
&& !vbo
&& _mesa_is_gles31(ctx
)) {
2035 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
2038 /* From the GL_ARB_vertex_attrib_array spec:
2040 * "[Core profile only:]
2041 * An INVALID_OPERATION error is generated if buffer is not zero or a
2042 * name returned from a previous call to GenBuffers, or if such a name
2043 * has since been deleted with DeleteBuffers.
2045 * Otherwise, we fall back to the same compat profile behavior as other
2046 * object references (automatically gen it).
2048 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
2051 /* The ARB_vertex_attrib_binding spec says:
2053 * "If <buffer> is zero, any buffer object attached to this
2054 * bindpoint is detached."
2056 vbo
= ctx
->Shared
->NullBufferObj
;
2059 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
2060 vbo
, offset
, stride
);
2065 * GL_ARB_vertex_attrib_binding
2068 vertex_array_vertex_buffer_err(struct gl_context
*ctx
,
2069 struct gl_vertex_array_object
*vao
,
2070 GLuint bindingIndex
, GLuint buffer
,
2071 GLintptr offset
, GLsizei stride
,
2074 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2076 /* The ARB_vertex_attrib_binding spec says:
2078 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2079 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2081 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2082 _mesa_error(ctx
, GL_INVALID_VALUE
,
2083 "%s(bindingindex=%u > "
2084 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2085 func
, bindingIndex
);
2089 /* The ARB_vertex_attrib_binding spec says:
2091 * "The error INVALID_VALUE is generated if <stride> or <offset>
2095 _mesa_error(ctx
, GL_INVALID_VALUE
,
2096 "%s(offset=%" PRId64
" < 0)",
2097 func
, (int64_t) offset
);
2102 _mesa_error(ctx
, GL_INVALID_VALUE
,
2103 "%s(stride=%d < 0)", func
, stride
);
2107 if (((ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
2108 stride
> ctx
->Const
.MaxVertexAttribStride
) {
2109 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
2110 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
2114 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2115 stride
, false, func
);
2120 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex
, GLuint buffer
,
2121 GLintptr offset
, GLsizei stride
)
2123 GET_CURRENT_CONTEXT(ctx
);
2124 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2125 buffer
, offset
, stride
, true,
2126 "glBindVertexBuffer");
2131 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2134 GET_CURRENT_CONTEXT(ctx
);
2136 /* The ARB_vertex_attrib_binding spec says:
2138 * "An INVALID_OPERATION error is generated if no vertex array object
2141 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2142 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2143 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2144 "glBindVertexBuffer(No array object bound)");
2148 vertex_array_vertex_buffer_err(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2149 buffer
, offset
, stride
,
2150 "glBindVertexBuffer");
2155 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj
, GLuint bindingIndex
,
2156 GLuint buffer
, GLintptr offset
,
2159 GET_CURRENT_CONTEXT(ctx
);
2161 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2162 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2163 stride
, true, "glVertexArrayVertexBuffer");
2168 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
2169 GLintptr offset
, GLsizei stride
)
2171 GET_CURRENT_CONTEXT(ctx
);
2172 struct gl_vertex_array_object
*vao
;
2174 /* The ARB_direct_state_access specification says:
2176 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2177 * if <vaobj> is not [compatibility profile: zero or] the name of an
2178 * existing vertex array object."
2180 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
2184 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
2185 stride
, "glVertexArrayVertexBuffer");
2189 static ALWAYS_INLINE
void
2190 vertex_array_vertex_buffers(struct gl_context
*ctx
,
2191 struct gl_vertex_array_object
*vao
,
2192 GLuint first
, GLsizei count
, const GLuint
*buffers
,
2193 const GLintptr
*offsets
, const GLsizei
*strides
,
2194 bool no_error
, const char *func
)
2200 * The ARB_multi_bind spec says:
2202 * "If <buffers> is NULL, each affected vertex buffer binding point
2203 * from <first> through <first>+<count>-1 will be reset to have no
2204 * bound buffer object. In this case, the offsets and strides
2205 * associated with the binding points are set to default values,
2206 * ignoring <offsets> and <strides>."
2208 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
2210 for (i
= 0; i
< count
; i
++)
2211 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2217 /* Note that the error semantics for multi-bind commands differ from
2218 * those of other GL commands.
2220 * The Issues section in the ARB_multi_bind spec says:
2222 * "(11) Typically, OpenGL specifies that if an error is generated by
2223 * a command, that command has no effect. This is somewhat
2224 * unfortunate for multi-bind commands, because it would require
2225 * a first pass to scan the entire list of bound objects for
2226 * errors and then a second pass to actually perform the
2227 * bindings. Should we have different error semantics?
2229 * RESOLVED: Yes. In this specification, when the parameters for
2230 * one of the <count> binding points are invalid, that binding
2231 * point is not updated and an error will be generated. However,
2232 * other binding points in the same command will be updated if
2233 * their parameters are valid and no other error occurs."
2236 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
2238 for (i
= 0; i
< count
; i
++) {
2239 struct gl_buffer_object
*vbo
;
2242 /* The ARB_multi_bind spec says:
2244 * "An INVALID_VALUE error is generated if any value in
2245 * <offsets> or <strides> is negative (per binding)."
2247 if (offsets
[i
] < 0) {
2248 _mesa_error(ctx
, GL_INVALID_VALUE
,
2249 "%s(offsets[%u]=%" PRId64
" < 0)",
2250 func
, i
, (int64_t) offsets
[i
]);
2254 if (strides
[i
] < 0) {
2255 _mesa_error(ctx
, GL_INVALID_VALUE
,
2256 "%s(strides[%u]=%d < 0)",
2257 func
, i
, strides
[i
]);
2261 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
2262 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
2263 _mesa_error(ctx
, GL_INVALID_VALUE
,
2264 "%s(strides[%u]=%d > "
2265 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
2271 struct gl_vertex_buffer_binding
*binding
=
2272 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
2274 if (buffers
[i
] == binding
->BufferObj
->Name
)
2275 vbo
= binding
->BufferObj
;
2277 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
2282 vbo
= ctx
->Shared
->NullBufferObj
;
2285 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2286 vbo
, offsets
[i
], strides
[i
]);
2289 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
2294 vertex_array_vertex_buffers_err(struct gl_context
*ctx
,
2295 struct gl_vertex_array_object
*vao
,
2296 GLuint first
, GLsizei count
,
2297 const GLuint
*buffers
, const GLintptr
*offsets
,
2298 const GLsizei
*strides
, const char *func
)
2300 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2302 /* The ARB_multi_bind spec says:
2304 * "An INVALID_OPERATION error is generated if <first> + <count>
2305 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
2307 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
2308 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2309 "%s(first=%u + count=%d > the value of "
2310 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
2311 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
2315 vertex_array_vertex_buffers(ctx
, vao
, first
, count
, buffers
, offsets
,
2316 strides
, false, func
);
2321 _mesa_BindVertexBuffers_no_error(GLuint first
, GLsizei count
,
2322 const GLuint
*buffers
, const GLintptr
*offsets
,
2323 const GLsizei
*strides
)
2325 GET_CURRENT_CONTEXT(ctx
);
2327 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
2328 buffers
, offsets
, strides
, true,
2329 "glBindVertexBuffers");
2334 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
2335 const GLintptr
*offsets
, const GLsizei
*strides
)
2337 GET_CURRENT_CONTEXT(ctx
);
2339 /* The ARB_vertex_attrib_binding spec says:
2341 * "An INVALID_OPERATION error is generated if no
2342 * vertex array object is bound."
2344 if (ctx
->API
== API_OPENGL_CORE
&&
2345 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2346 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2347 "glBindVertexBuffers(No array object bound)");
2351 vertex_array_vertex_buffers_err(ctx
, ctx
->Array
.VAO
, first
, count
,
2352 buffers
, offsets
, strides
,
2353 "glBindVertexBuffers");
2358 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj
, GLuint first
,
2359 GLsizei count
, const GLuint
*buffers
,
2360 const GLintptr
*offsets
,
2361 const GLsizei
*strides
)
2363 GET_CURRENT_CONTEXT(ctx
);
2365 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2366 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
2367 buffers
, offsets
, strides
, true,
2368 "glVertexArrayVertexBuffers");
2373 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
2374 const GLuint
*buffers
,
2375 const GLintptr
*offsets
, const GLsizei
*strides
)
2377 GET_CURRENT_CONTEXT(ctx
);
2378 struct gl_vertex_array_object
*vao
;
2380 /* The ARB_direct_state_access specification says:
2382 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2383 * if <vaobj> is not [compatibility profile: zero or] the name of an
2384 * existing vertex array object."
2386 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
2390 vertex_array_vertex_buffers_err(ctx
, vao
, first
, count
,
2391 buffers
, offsets
, strides
,
2392 "glVertexArrayVertexBuffers");
2397 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
2398 GLboolean normalized
, GLboolean integer
,
2399 GLboolean doubles
, GLbitfield legalTypes
,
2400 GLsizei sizeMax
, GLuint relativeOffset
,
2403 GET_CURRENT_CONTEXT(ctx
);
2404 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2406 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2408 if (!_mesa_is_no_error_enabled(ctx
)) {
2409 /* The ARB_vertex_attrib_binding spec says:
2411 * "An INVALID_OPERATION error is generated under any of the
2412 * following conditions:
2413 * - if no vertex array object is currently bound (see section
2417 * This error condition only applies to VertexAttribFormat and
2418 * VertexAttribIFormat in the extension spec, but we assume that this
2419 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2420 * to all three functions.
2422 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2423 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2424 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2425 "%s(No array object bound)", func
);
2429 /* The ARB_vertex_attrib_binding spec says:
2431 * "The error INVALID_VALUE is generated if index is greater than or
2432 * equal to the value of MAX_VERTEX_ATTRIBS."
2434 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2435 _mesa_error(ctx
, GL_INVALID_VALUE
,
2436 "%s(attribindex=%u > "
2437 "GL_MAX_VERTEX_ATTRIBS)",
2442 if (!validate_array_format(ctx
, func
, ctx
->Array
.VAO
,
2443 VERT_ATTRIB_GENERIC(attribIndex
),
2444 legalTypes
, 1, sizeMax
, size
, type
,
2445 normalized
, integer
, doubles
, relativeOffset
,
2451 FLUSH_VERTICES(ctx
, 0);
2453 _mesa_update_array_format(ctx
, ctx
->Array
.VAO
,
2454 VERT_ATTRIB_GENERIC(attribIndex
), size
, type
,
2455 format
, normalized
, integer
, doubles
,
2461 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2462 GLboolean normalized
, GLuint relativeOffset
)
2464 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
2465 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2466 BGRA_OR_4
, relativeOffset
,
2467 "glVertexAttribFormat");
2472 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2473 GLuint relativeOffset
)
2475 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2476 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2477 relativeOffset
, "glVertexAttribIFormat");
2482 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2483 GLuint relativeOffset
)
2485 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2486 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2487 relativeOffset
, "glVertexAttribLFormat");
2492 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2493 GLenum type
, GLboolean normalized
,
2494 GLboolean integer
, GLboolean doubles
,
2495 GLbitfield legalTypes
, GLsizei sizeMax
,
2496 GLuint relativeOffset
, const char *func
)
2498 GET_CURRENT_CONTEXT(ctx
);
2499 struct gl_vertex_array_object
*vao
;
2501 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2503 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2505 if (_mesa_is_no_error_enabled(ctx
)) {
2506 vao
= _mesa_lookup_vao(ctx
, vaobj
);
2510 /* The ARB_direct_state_access spec says:
2512 * "An INVALID_OPERATION error is generated by
2513 * VertexArrayAttrib*Format if <vaobj> is not [compatibility profile:
2514 * zero or] the name of an existing vertex array object."
2516 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2520 /* The ARB_vertex_attrib_binding spec says:
2522 * "The error INVALID_VALUE is generated if index is greater than or
2523 * equal to the value of MAX_VERTEX_ATTRIBS."
2525 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2526 _mesa_error(ctx
, GL_INVALID_VALUE
,
2527 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2532 if (!validate_array_format(ctx
, func
, vao
,
2533 VERT_ATTRIB_GENERIC(attribIndex
),
2534 legalTypes
, 1, sizeMax
, size
, type
,
2535 normalized
, integer
, doubles
, relativeOffset
,
2541 FLUSH_VERTICES(ctx
, 0);
2543 _mesa_update_array_format(ctx
, vao
, VERT_ATTRIB_GENERIC(attribIndex
), size
,
2544 type
, format
, normalized
, integer
, doubles
,
2550 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2551 GLenum type
, GLboolean normalized
,
2552 GLuint relativeOffset
)
2554 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2555 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2556 BGRA_OR_4
, relativeOffset
,
2557 "glVertexArrayAttribFormat");
2562 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2563 GLint size
, GLenum type
,
2564 GLuint relativeOffset
)
2566 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2567 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2569 "glVertexArrayAttribIFormat");
2574 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2575 GLint size
, GLenum type
,
2576 GLuint relativeOffset
)
2578 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2579 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2581 "glVertexArrayAttribLFormat");
2586 vertex_array_attrib_binding(struct gl_context
*ctx
,
2587 struct gl_vertex_array_object
*vao
,
2588 GLuint attribIndex
, GLuint bindingIndex
,
2591 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2593 /* The ARB_vertex_attrib_binding spec says:
2595 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2596 * <bindingindex> must be less than the value of
2597 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2600 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2601 _mesa_error(ctx
, GL_INVALID_VALUE
,
2602 "%s(attribindex=%u >= "
2603 "GL_MAX_VERTEX_ATTRIBS)",
2608 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2609 _mesa_error(ctx
, GL_INVALID_VALUE
,
2610 "%s(bindingindex=%u >= "
2611 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2612 func
, bindingIndex
);
2616 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2618 vertex_attrib_binding(ctx
, vao
,
2619 VERT_ATTRIB_GENERIC(attribIndex
),
2620 VERT_ATTRIB_GENERIC(bindingIndex
));
2625 _mesa_VertexAttribBinding_no_error(GLuint attribIndex
, GLuint bindingIndex
)
2627 GET_CURRENT_CONTEXT(ctx
);
2628 vertex_attrib_binding(ctx
, ctx
->Array
.VAO
,
2629 VERT_ATTRIB_GENERIC(attribIndex
),
2630 VERT_ATTRIB_GENERIC(bindingIndex
));
2635 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2637 GET_CURRENT_CONTEXT(ctx
);
2639 /* The ARB_vertex_attrib_binding spec says:
2641 * "An INVALID_OPERATION error is generated if no vertex array object
2644 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2645 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2646 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2647 "glVertexAttribBinding(No array object bound)");
2651 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2652 attribIndex
, bindingIndex
,
2653 "glVertexAttribBinding");
2658 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj
, GLuint attribIndex
,
2659 GLuint bindingIndex
)
2661 GET_CURRENT_CONTEXT(ctx
);
2663 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2664 vertex_attrib_binding(ctx
, vao
,
2665 VERT_ATTRIB_GENERIC(attribIndex
),
2666 VERT_ATTRIB_GENERIC(bindingIndex
));
2671 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2673 GET_CURRENT_CONTEXT(ctx
);
2674 struct gl_vertex_array_object
*vao
;
2676 /* The ARB_direct_state_access specification says:
2678 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2679 * if <vaobj> is not [compatibility profile: zero or] the name of an
2680 * existing vertex array object."
2682 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2686 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2687 "glVertexArrayAttribBinding");
2692 vertex_array_binding_divisor(struct gl_context
*ctx
,
2693 struct gl_vertex_array_object
*vao
,
2694 GLuint bindingIndex
, GLuint divisor
,
2697 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2699 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2700 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2704 /* The ARB_vertex_attrib_binding spec says:
2706 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2707 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2709 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2710 _mesa_error(ctx
, GL_INVALID_VALUE
,
2711 "%s(bindingindex=%u > "
2712 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2713 func
, bindingIndex
);
2717 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2722 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex
, GLuint divisor
)
2724 GET_CURRENT_CONTEXT(ctx
);
2725 vertex_binding_divisor(ctx
, ctx
->Array
.VAO
,
2726 VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2731 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2733 GET_CURRENT_CONTEXT(ctx
);
2735 /* The ARB_vertex_attrib_binding spec says:
2737 * "An INVALID_OPERATION error is generated if no vertex array object
2740 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2741 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2742 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2743 "glVertexBindingDivisor(No array object bound)");
2747 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2748 bindingIndex
, divisor
,
2749 "glVertexBindingDivisor");
2754 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj
, GLuint bindingIndex
,
2757 GET_CURRENT_CONTEXT(ctx
);
2759 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2760 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2765 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2768 struct gl_vertex_array_object
*vao
;
2769 GET_CURRENT_CONTEXT(ctx
);
2771 /* The ARB_direct_state_access specification says:
2773 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2774 * if <vaobj> is not [compatibility profile: zero or] the name of an
2775 * existing vertex array object."
2777 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2781 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2782 "glVertexArrayBindingDivisor");
2787 * Copy one client vertex array to another.
2790 _mesa_copy_client_array(struct gl_context
*ctx
,
2791 struct gl_vertex_array
*dst
,
2792 struct gl_vertex_array
*src
)
2794 dst
->Size
= src
->Size
;
2795 dst
->Type
= src
->Type
;
2796 dst
->Format
= src
->Format
;
2797 dst
->StrideB
= src
->StrideB
;
2798 dst
->Ptr
= src
->Ptr
;
2799 dst
->Normalized
= src
->Normalized
;
2800 dst
->Integer
= src
->Integer
;
2801 dst
->Doubles
= src
->Doubles
;
2802 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2803 dst
->_ElementSize
= src
->_ElementSize
;
2804 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2808 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2809 struct gl_array_attributes
*dst
,
2810 const struct gl_array_attributes
*src
)
2812 dst
->Size
= src
->Size
;
2813 dst
->Type
= src
->Type
;
2814 dst
->Format
= src
->Format
;
2815 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
2816 dst
->RelativeOffset
= src
->RelativeOffset
;
2817 dst
->Format
= src
->Format
;
2818 dst
->Integer
= src
->Integer
;
2819 dst
->Doubles
= src
->Doubles
;
2820 dst
->Normalized
= src
->Normalized
;
2821 dst
->Ptr
= src
->Ptr
;
2822 dst
->Enabled
= src
->Enabled
;
2823 dst
->_ElementSize
= src
->_ElementSize
;
2827 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2828 struct gl_vertex_buffer_binding
*dst
,
2829 const struct gl_vertex_buffer_binding
*src
)
2831 dst
->Offset
= src
->Offset
;
2832 dst
->Stride
= src
->Stride
;
2833 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2834 dst
->_BoundArrays
= src
->_BoundArrays
;
2836 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2840 * Print current vertex object/array info. For debug.
2843 _mesa_print_arrays(struct gl_context
*ctx
)
2845 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2847 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
2850 for (i
= 0; i
< VERT_ATTRIB_MAX
; ++i
) {
2851 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
2852 if (!array
->Enabled
)
2855 const struct gl_vertex_buffer_binding
*binding
=
2856 &vao
->BufferBinding
[array
->BufferBindingIndex
];
2857 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
2859 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2860 "Stride=%d, Buffer=%u(Size %lu)\n",
2861 gl_vert_attrib_name((gl_vert_attrib
)i
),
2862 array
->Ptr
, _mesa_enum_to_string(array
->Type
), array
->Size
,
2863 array
->_ElementSize
, binding
->Stride
, bo
->Name
,
2864 (unsigned long) bo
->Size
);
2870 * Initialize vertex array state for given context.
2873 _mesa_init_varray(struct gl_context
*ctx
)
2875 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2876 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2877 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2879 ctx
->Array
.Objects
= _mesa_NewHashTable();
2884 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2887 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2889 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2890 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2891 _mesa_delete_vao(ctx
, vao
);
2896 * Free vertex array state for given context.
2899 _mesa_free_varray_data(struct gl_context
*ctx
)
2901 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2902 _mesa_DeleteHashTable(ctx
->Array
.Objects
);