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
,
135 gl_vert_attrib attribIndex
,
138 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attribIndex
];
140 if (array
->BufferBindingIndex
!= bindingIndex
) {
141 const GLbitfield 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 assert(index
< ARRAY_SIZE(vao
->BufferBinding
));
170 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
172 if (binding
->BufferObj
!= vbo
||
173 binding
->Offset
!= offset
||
174 binding
->Stride
!= stride
) {
176 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
178 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
180 binding
->Offset
= offset
;
181 binding
->Stride
= stride
;
183 if (!_mesa_is_bufferobj(vbo
))
184 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
186 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
188 vao
->NewArrays
|= binding
->_BoundArrays
;
194 * Sets the InstanceDivisor field in the vertex buffer binding point
195 * given by bindingIndex.
198 vertex_binding_divisor(struct gl_context
*ctx
,
199 struct gl_vertex_array_object
*vao
,
203 struct gl_vertex_buffer_binding
*binding
=
204 &vao
->BufferBinding
[bindingIndex
];
206 if (binding
->InstanceDivisor
!= divisor
) {
207 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
208 binding
->InstanceDivisor
= divisor
;
209 vao
->NewArrays
|= binding
->_BoundArrays
;
215 * Examine the API profile and extensions to determine which types are legal
216 * for vertex arrays. This is called once from update_array_format().
219 get_legal_types_mask(const struct gl_context
*ctx
)
221 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
223 if (_mesa_is_gles(ctx
)) {
224 legalTypesMask
&= ~(FIXED_GL_BIT
|
226 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
228 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
229 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
230 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
231 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
232 * quite as trivial as we'd like because it uses a different enum value
233 * for GL_HALF_FLOAT_OES.
235 if (ctx
->Version
< 30) {
236 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
238 UNSIGNED_INT_2_10_10_10_REV_BIT
|
239 INT_2_10_10_10_REV_BIT
);
241 if (!_mesa_has_OES_vertex_half_float(ctx
))
242 legalTypesMask
&= ~HALF_BIT
;
246 legalTypesMask
&= ~FIXED_ES_BIT
;
248 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
249 legalTypesMask
&= ~FIXED_GL_BIT
;
251 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
252 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
253 INT_2_10_10_10_REV_BIT
);
255 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
256 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
259 return legalTypesMask
;
263 get_array_format(const struct gl_context
*ctx
, GLint sizeMax
, GLint
*size
)
265 GLenum format
= GL_RGBA
;
267 /* Do size parameter checking.
268 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
269 * must be handled specially.
271 if (ctx
->Extensions
.EXT_vertex_array_bgra
&& sizeMax
== BGRA_OR_4
&&
282 * \param attrib The index of the attribute array
283 * \param size Components per element (1, 2, 3 or 4)
284 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
285 * \param format Either GL_RGBA or GL_BGRA.
286 * \param normalized Whether integer types are converted to floats in [-1, 1]
287 * \param integer Integer-valued values (will not be normalized to [-1, 1])
288 * \param doubles Double values not reduced to floats
289 * \param relativeOffset Offset of the first element relative to the binding
291 * \param flush_verties Should \c FLUSH_VERTICES be invoked before updating
295 _mesa_update_array_format(struct gl_context
*ctx
,
296 struct gl_vertex_array_object
*vao
,
297 gl_vert_attrib attrib
, GLint size
, GLenum type
,
298 GLenum format
, GLboolean normalized
,
299 GLboolean integer
, GLboolean doubles
,
300 GLuint relativeOffset
)
302 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
307 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
308 assert(elementSize
!= -1);
312 array
->Format
= format
;
313 array
->Normalized
= normalized
;
314 array
->Integer
= integer
;
315 array
->Doubles
= doubles
;
316 array
->RelativeOffset
= relativeOffset
;
317 array
->_ElementSize
= elementSize
;
319 vao
->NewArrays
|= VERT_BIT(attrib
);
320 ctx
->NewState
|= _NEW_ARRAY
;
324 * Does error checking of the format in an attrib array.
326 * Called by *Pointer() and VertexAttrib*Format().
328 * \param func Name of calling function used for error reporting
329 * \param attrib The index of the attribute array
330 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
331 * \param sizeMin Min allowable size value
332 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
333 * \param size Components per element (1, 2, 3 or 4)
334 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
335 * \param normalized Whether integer types are converted to floats in [-1, 1]
336 * \param integer Integer-valued values (will not be normalized to [-1, 1])
337 * \param doubles Double values not reduced to floats
338 * \param relativeOffset Offset of the first element relative to the binding offset.
339 * \return bool True if validation is successful, False otherwise.
342 validate_array_format(struct gl_context
*ctx
, const char *func
,
343 struct gl_vertex_array_object
*vao
,
344 GLuint attrib
, GLbitfield legalTypesMask
,
345 GLint sizeMin
, GLint sizeMax
,
346 GLint size
, GLenum type
, GLboolean normalized
,
347 GLboolean integer
, GLboolean doubles
,
348 GLuint relativeOffset
, GLenum format
)
352 /* at most, one of these bools can be true */
353 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
355 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
356 /* Compute the LegalTypesMask only once, unless the context API has
357 * changed, in which case we want to compute it again. We can't do this
358 * in _mesa_init_varrays() below because extensions are not yet enabled
361 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
362 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
365 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
367 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
368 /* BGRA ordering is not supported in ES contexts.
373 typeBit
= type_to_bit(ctx
, type
);
374 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
375 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
376 func
, _mesa_enum_to_string(type
));
380 if (format
== GL_BGRA
) {
381 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
383 * "An INVALID_OPERATION error is generated under any of the following
386 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
387 * or UNSIGNED_INT_2_10_10_10_REV;
389 * • size is BGRA and normalized is FALSE;"
391 bool bgra_error
= false;
393 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
394 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
395 type
!= GL_INT_2_10_10_10_REV
&&
396 type
!= GL_UNSIGNED_BYTE
)
398 } else if (type
!= GL_UNSIGNED_BYTE
)
402 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
403 func
, _mesa_enum_to_string(type
));
408 _mesa_error(ctx
, GL_INVALID_OPERATION
,
409 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
413 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
414 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
418 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
419 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
420 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
421 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
425 /* The ARB_vertex_attrib_binding_spec says:
427 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
428 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
430 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
431 _mesa_error(ctx
, GL_INVALID_VALUE
,
432 "%s(relativeOffset=%d > "
433 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
434 func
, relativeOffset
);
438 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
439 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
440 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
448 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
450 * \param func name of calling function used for error reporting
451 * \param attrib the attribute array index to update
452 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
453 * \param sizeMin min allowable size value
454 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
455 * \param size components per element (1, 2, 3 or 4)
456 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
457 * \param stride stride between elements, in elements
458 * \param normalized are integer types converted to floats in [-1, 1]?
459 * \param integer integer-valued values (will not be normalized to [-1,1])
460 * \param doubles Double values not reduced to floats
461 * \param ptr the address (or offset inside VBO) of the array data
464 validate_array(struct gl_context
*ctx
, const char *func
,
465 GLuint attrib
, GLbitfield legalTypesMask
,
466 GLint sizeMin
, GLint sizeMax
,
467 GLint size
, GLenum type
, GLsizei stride
,
468 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
471 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
473 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
475 * "Client vertex arrays - all vertex array attribute pointers must
476 * refer to buffer objects (section 2.9.2). The default vertex array
477 * object (the name zero) is also deprecated. Calling
478 * VertexAttribPointer when no buffer object or no vertex array object
479 * is bound will generate an INVALID_OPERATION error..."
481 * The check for VBOs is handled below.
483 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
484 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
490 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
494 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
495 stride
> ctx
->Const
.MaxVertexAttribStride
) {
496 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
497 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
501 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
503 * "An INVALID_OPERATION error is generated under any of the following
508 * * any of the *Pointer commands specifying the location and
509 * organization of vertex array data are called while zero is bound
510 * to the ARRAY_BUFFER buffer object binding point (see section
511 * 2.9.6), and the pointer argument is not NULL."
513 if (ptr
!= NULL
&& vao
!= ctx
->Array
.DefaultVAO
&&
514 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
515 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
522 validate_array_and_format(struct gl_context
*ctx
, const char *func
,
523 GLuint attrib
, GLbitfield legalTypes
,
524 GLint sizeMin
, GLint sizeMax
,
525 GLint size
, GLenum type
, GLsizei stride
,
526 GLboolean normalized
, GLboolean integer
,
527 GLboolean doubles
, GLenum format
, const GLvoid
*ptr
,
528 struct gl_vertex_array_object
*vao
)
530 validate_array(ctx
, func
, attrib
, legalTypes
, sizeMin
, sizeMax
, size
,
531 type
, stride
, normalized
, integer
, doubles
, ptr
);
533 return validate_array_format(ctx
, func
, vao
, attrib
, legalTypes
, sizeMin
,
534 sizeMax
, size
, type
, normalized
, integer
,
540 * Update state for glVertex/Color/TexCoord/...Pointer functions.
542 * \param attrib the attribute array index to update
543 * \param format Either GL_RGBA or GL_BGRA.
544 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
545 * \param size components per element (1, 2, 3 or 4)
546 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
547 * \param stride stride between elements, in elements
548 * \param normalized are integer types converted to floats in [-1, 1]?
549 * \param integer integer-valued values (will not be normalized to [-1,1])
550 * \param doubles Double values not reduced to floats
551 * \param ptr the address (or offset inside VBO) of the array data
554 update_array(struct gl_context
*ctx
,
555 GLuint attrib
, GLenum format
,
557 GLint size
, GLenum type
, GLsizei stride
,
558 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
561 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
563 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
564 normalized
, integer
, doubles
, 0);
566 /* Reset the vertex attrib binding */
567 vertex_attrib_binding(ctx
, vao
, attrib
, attrib
);
569 /* The Stride and Ptr fields are not set by update_array_format() */
570 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attrib
];
571 array
->Stride
= stride
;
574 /* Update the vertex buffer binding */
575 GLsizei effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
576 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
577 ctx
->Array
.ArrayBufferObj
, (GLintptr
) ptr
,
582 _mesa_VertexPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
585 GET_CURRENT_CONTEXT(ctx
);
586 FLUSH_VERTICES(ctx
, 0);
588 update_array(ctx
, VERT_ATTRIB_POS
, GL_RGBA
, 4, size
, type
, stride
,
589 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
594 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
596 GET_CURRENT_CONTEXT(ctx
);
598 FLUSH_VERTICES(ctx
, 0);
600 GLenum format
= GL_RGBA
;
601 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
602 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
603 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
604 DOUBLE_BIT
| HALF_BIT
|
605 UNSIGNED_INT_2_10_10_10_REV_BIT
|
606 INT_2_10_10_10_REV_BIT
);
608 if (!validate_array_and_format(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
609 legalTypes
, 2, 4, size
, type
, stride
,
610 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
,
611 ptr
, ctx
->Array
.VAO
))
614 update_array(ctx
, VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
615 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
620 _mesa_NormalPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
622 GET_CURRENT_CONTEXT(ctx
);
623 FLUSH_VERTICES(ctx
, 0);
625 update_array(ctx
, VERT_ATTRIB_NORMAL
, GL_RGBA
, 3, 3, type
, stride
, GL_TRUE
,
626 GL_FALSE
, GL_FALSE
, ptr
);
631 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
633 GET_CURRENT_CONTEXT(ctx
);
635 FLUSH_VERTICES(ctx
, 0);
637 GLenum format
= GL_RGBA
;
638 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
639 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
640 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
641 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
642 UNSIGNED_INT_2_10_10_10_REV_BIT
|
643 INT_2_10_10_10_REV_BIT
);
645 if (!validate_array_and_format(ctx
, "glNormalPointer",
646 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
647 type
, stride
, GL_TRUE
, GL_FALSE
,
648 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
651 update_array(ctx
, VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
652 GL_FALSE
, GL_FALSE
, ptr
);
657 _mesa_ColorPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
660 GET_CURRENT_CONTEXT(ctx
);
661 FLUSH_VERTICES(ctx
, 0);
663 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
664 update_array(ctx
, VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
665 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
670 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
672 GET_CURRENT_CONTEXT(ctx
);
673 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
675 FLUSH_VERTICES(ctx
, 0);
677 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
678 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
679 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
680 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
681 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
682 INT_BIT
| UNSIGNED_INT_BIT
|
683 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
684 UNSIGNED_INT_2_10_10_10_REV_BIT
|
685 INT_2_10_10_10_REV_BIT
);
687 if (!validate_array_and_format(ctx
, "glColorPointer",
688 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
689 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
690 GL_FALSE
, GL_FALSE
, format
, ptr
,
694 update_array(ctx
, VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
695 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
700 _mesa_FogCoordPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
702 GET_CURRENT_CONTEXT(ctx
);
703 FLUSH_VERTICES(ctx
, 0);
705 update_array(ctx
, VERT_ATTRIB_FOG
, GL_RGBA
, 1, 1, type
, stride
, GL_FALSE
,
706 GL_FALSE
, GL_FALSE
, ptr
);
711 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
713 GET_CURRENT_CONTEXT(ctx
);
715 FLUSH_VERTICES(ctx
, 0);
717 GLenum format
= GL_RGBA
;
718 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
720 if (!validate_array_and_format(ctx
, "glFogCoordPointer",
721 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
722 type
, stride
, GL_FALSE
, GL_FALSE
,
723 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
726 update_array(ctx
, VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
727 GL_FALSE
, GL_FALSE
, ptr
);
732 _mesa_IndexPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
734 GET_CURRENT_CONTEXT(ctx
);
735 FLUSH_VERTICES(ctx
, 0);
737 update_array(ctx
, VERT_ATTRIB_COLOR_INDEX
, GL_RGBA
, 1, 1, type
, stride
,
738 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
743 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
745 GET_CURRENT_CONTEXT(ctx
);
747 FLUSH_VERTICES(ctx
, 0);
749 GLenum format
= GL_RGBA
;
750 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
751 FLOAT_BIT
| DOUBLE_BIT
);
753 if (!validate_array_and_format(ctx
, "glIndexPointer",
754 VERT_ATTRIB_COLOR_INDEX
,
755 legalTypes
, 1, 1, 1, type
, stride
,
756 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
,
757 ptr
, ctx
->Array
.VAO
))
760 update_array(ctx
, VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
761 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
766 _mesa_SecondaryColorPointer_no_error(GLint size
, GLenum type
,
767 GLsizei stride
, const GLvoid
*ptr
)
769 GET_CURRENT_CONTEXT(ctx
);
770 FLUSH_VERTICES(ctx
, 0);
772 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
773 update_array(ctx
, VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
774 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
779 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
780 GLsizei stride
, const GLvoid
*ptr
)
782 GET_CURRENT_CONTEXT(ctx
);
784 FLUSH_VERTICES(ctx
, 0);
786 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
787 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
788 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
789 INT_BIT
| UNSIGNED_INT_BIT
|
790 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
791 UNSIGNED_INT_2_10_10_10_REV_BIT
|
792 INT_2_10_10_10_REV_BIT
);
794 if (!validate_array_and_format(ctx
, "glSecondaryColorPointer",
795 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
796 BGRA_OR_4
, size
, type
, stride
,
797 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, ptr
,
801 update_array(ctx
, VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
802 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
807 _mesa_TexCoordPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
810 GET_CURRENT_CONTEXT(ctx
);
811 const GLuint unit
= ctx
->Array
.ActiveTexture
;
812 FLUSH_VERTICES(ctx
, 0);
814 update_array(ctx
, VERT_ATTRIB_TEX(unit
), GL_RGBA
, 4, size
, type
,
815 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
820 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
823 GET_CURRENT_CONTEXT(ctx
);
824 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
825 const GLuint unit
= ctx
->Array
.ActiveTexture
;
827 FLUSH_VERTICES(ctx
, 0);
829 GLenum format
= GL_RGBA
;
830 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
831 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
832 : (SHORT_BIT
| INT_BIT
|
833 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
834 UNSIGNED_INT_2_10_10_10_REV_BIT
|
835 INT_2_10_10_10_REV_BIT
);
837 if (!validate_array_and_format(ctx
, "glTexCoordPointer",
838 VERT_ATTRIB_TEX(unit
), legalTypes
,
839 sizeMin
, 4, size
, type
, stride
,
840 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
,
844 update_array(ctx
, VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
845 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
850 _mesa_EdgeFlagPointer_no_error(GLsizei stride
, const GLvoid
*ptr
)
852 /* this is the same type that glEdgeFlag uses */
853 const GLboolean integer
= GL_FALSE
;
854 GET_CURRENT_CONTEXT(ctx
);
855 FLUSH_VERTICES(ctx
, 0);
857 update_array(ctx
, VERT_ATTRIB_EDGEFLAG
, GL_RGBA
, 1, 1, GL_UNSIGNED_BYTE
,
858 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
863 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
865 /* this is the same type that glEdgeFlag uses */
866 const GLboolean integer
= GL_FALSE
;
867 GET_CURRENT_CONTEXT(ctx
);
869 FLUSH_VERTICES(ctx
, 0);
871 GLenum format
= GL_RGBA
;
872 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
874 if (!validate_array_and_format(ctx
, "glEdgeFlagPointer",
875 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
876 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
877 GL_FALSE
, integer
, GL_FALSE
, format
, ptr
,
881 update_array(ctx
, VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
882 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
887 _mesa_PointSizePointerOES_no_error(GLenum type
, GLsizei stride
,
890 GET_CURRENT_CONTEXT(ctx
);
891 FLUSH_VERTICES(ctx
, 0);
893 update_array(ctx
, VERT_ATTRIB_POINT_SIZE
, GL_RGBA
, 1, 1, type
, stride
,
894 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
899 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
901 GET_CURRENT_CONTEXT(ctx
);
903 FLUSH_VERTICES(ctx
, 0);
905 GLenum format
= GL_RGBA
;
906 if (ctx
->API
!= API_OPENGLES
) {
907 _mesa_error(ctx
, GL_INVALID_OPERATION
,
908 "glPointSizePointer(ES 1.x only)");
912 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
914 if (!validate_array_and_format(ctx
, "glPointSizePointer",
915 VERT_ATTRIB_POINT_SIZE
, legalTypes
,
916 1, 1, 1, type
, stride
, GL_FALSE
, GL_FALSE
,
917 GL_FALSE
, format
, ptr
, ctx
->Array
.VAO
))
920 update_array(ctx
, VERT_ATTRIB_POINT_SIZE
, format
, 1, 1, type
, stride
,
921 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
926 _mesa_VertexAttribPointer_no_error(GLuint index
, GLint size
, GLenum type
,
927 GLboolean normalized
,
928 GLsizei stride
, const GLvoid
*ptr
)
930 GET_CURRENT_CONTEXT(ctx
);
932 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
933 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
934 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
939 * Set a generic vertex attribute array.
940 * Note that these arrays DO NOT alias the conventional GL vertex arrays
941 * (position, normal, color, fog, texcoord, etc).
944 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
945 GLboolean normalized
,
946 GLsizei stride
, const GLvoid
*ptr
)
948 GET_CURRENT_CONTEXT(ctx
);
950 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
951 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
952 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(idx)");
956 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
957 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
958 INT_BIT
| UNSIGNED_INT_BIT
|
959 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
960 FIXED_ES_BIT
| FIXED_GL_BIT
|
961 UNSIGNED_INT_2_10_10_10_REV_BIT
|
962 INT_2_10_10_10_REV_BIT
|
963 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
965 if (!validate_array_and_format(ctx
, "glVertexAttribPointer",
966 VERT_ATTRIB_GENERIC(index
), legalTypes
,
967 1, BGRA_OR_4
, size
, type
, stride
,
968 normalized
, GL_FALSE
, GL_FALSE
, format
,
969 ptr
, ctx
->Array
.VAO
))
972 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
973 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
978 _mesa_VertexAttribIPointer_no_error(GLuint index
, GLint size
, GLenum type
,
979 GLsizei stride
, const GLvoid
*ptr
)
981 const GLboolean normalized
= GL_FALSE
;
982 const GLboolean integer
= GL_TRUE
;
983 GET_CURRENT_CONTEXT(ctx
);
985 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
986 stride
, normalized
, integer
, GL_FALSE
, ptr
);
991 * GL_EXT_gpu_shader4 / GL 3.0.
992 * Set an integer-valued vertex attribute array.
993 * Note that these arrays DO NOT alias the conventional GL vertex arrays
994 * (position, normal, color, fog, texcoord, etc).
997 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
998 GLsizei stride
, const GLvoid
*ptr
)
1000 const GLboolean normalized
= GL_FALSE
;
1001 const GLboolean integer
= GL_TRUE
;
1002 GET_CURRENT_CONTEXT(ctx
);
1004 GLenum format
= GL_RGBA
;
1005 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1006 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
1010 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1011 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1012 INT_BIT
| UNSIGNED_INT_BIT
);
1014 if (!validate_array_and_format(ctx
, "glVertexAttribIPointer",
1015 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1016 1, 4, size
, type
, stride
,
1017 normalized
, integer
, GL_FALSE
, format
,
1018 ptr
, ctx
->Array
.VAO
))
1021 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1022 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1027 _mesa_VertexAttribLPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1028 GLsizei stride
, const GLvoid
*ptr
)
1030 GET_CURRENT_CONTEXT(ctx
);
1032 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1033 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1038 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
1039 GLsizei stride
, const GLvoid
*ptr
)
1041 GET_CURRENT_CONTEXT(ctx
);
1043 GLenum format
= GL_RGBA
;
1044 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1045 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
1049 const GLbitfield legalTypes
= DOUBLE_BIT
;
1051 if (!validate_array_and_format(ctx
, "glVertexAttribLPointer",
1052 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1053 1, 4, size
, type
, stride
,
1054 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
,
1055 ptr
, ctx
->Array
.VAO
))
1058 update_array(ctx
, VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1059 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1064 _mesa_enable_vertex_array_attrib(struct gl_context
*ctx
,
1065 struct gl_vertex_array_object
*vao
,
1066 gl_vert_attrib attrib
)
1068 assert(attrib
>= VERT_ATTRIB_GENERIC0
);
1069 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
1071 if (!vao
->VertexAttrib
[attrib
].Enabled
) {
1072 /* was disabled, now being enabled */
1073 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1074 vao
->VertexAttrib
[attrib
].Enabled
= GL_TRUE
;
1075 vao
->_Enabled
|= VERT_BIT(attrib
);
1076 vao
->NewArrays
|= VERT_BIT(attrib
);
1081 enable_vertex_array_attrib(struct gl_context
*ctx
,
1082 struct gl_vertex_array_object
*vao
,
1086 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1087 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
1091 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1096 _mesa_EnableVertexAttribArray(GLuint index
)
1098 GET_CURRENT_CONTEXT(ctx
);
1099 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
1100 "glEnableVertexAttribArray");
1105 _mesa_EnableVertexAttribArray_no_error(GLuint index
)
1107 GET_CURRENT_CONTEXT(ctx
);
1108 _mesa_enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1109 VERT_ATTRIB_GENERIC(index
));
1114 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1116 GET_CURRENT_CONTEXT(ctx
);
1117 struct gl_vertex_array_object
*vao
;
1119 /* The ARB_direct_state_access specification says:
1121 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1122 * and DisableVertexArrayAttrib if <vaobj> is not
1123 * [compatibility profile: zero or] the name of an existing vertex
1126 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
1130 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
1135 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1137 GET_CURRENT_CONTEXT(ctx
);
1138 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1139 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1144 disable_vertex_array_attrib(struct gl_context
*ctx
,
1145 struct gl_vertex_array_object
*vao
,
1148 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
1150 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
1151 /* was enabled, now being disabled */
1152 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
1153 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
1154 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
1155 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
1161 _mesa_DisableVertexAttribArray(GLuint index
)
1163 GET_CURRENT_CONTEXT(ctx
);
1165 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1166 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexAttribArray(index)");
1170 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
);
1175 _mesa_DisableVertexAttribArray_no_error(GLuint index
)
1177 GET_CURRENT_CONTEXT(ctx
);
1178 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
);
1183 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1185 GET_CURRENT_CONTEXT(ctx
);
1186 struct gl_vertex_array_object
*vao
;
1188 /* The ARB_direct_state_access specification says:
1190 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1191 * and DisableVertexArrayAttrib if <vaobj> is not
1192 * [compatibility profile: zero or] the name of an existing vertex
1195 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
1199 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1200 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
1204 disable_vertex_array_attrib(ctx
, vao
, index
);
1209 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1211 GET_CURRENT_CONTEXT(ctx
);
1212 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1213 disable_vertex_array_attrib(ctx
, vao
, index
);
1218 * Return info for a vertex attribute array (no alias with legacy
1219 * vertex attributes (pos, normal, color, etc)). This function does
1220 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
1223 get_vertex_array_attrib(struct gl_context
*ctx
,
1224 const struct gl_vertex_array_object
*vao
,
1225 GLuint index
, GLenum pname
,
1228 const struct gl_array_attributes
*array
;
1230 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1231 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
1235 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
1237 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
1240 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
1241 return array
->Enabled
;
1242 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
1243 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
1244 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
1245 return array
->Stride
;
1246 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
1248 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
1249 return array
->Normalized
;
1250 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
1251 return vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
->Name
;
1252 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
1253 if ((_mesa_is_desktop_gl(ctx
)
1254 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
1255 || _mesa_is_gles3(ctx
)) {
1256 return array
->Integer
;
1259 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
1260 if (_mesa_is_desktop_gl(ctx
)) {
1261 return array
->Doubles
;
1264 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
1265 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
1266 || _mesa_is_gles3(ctx
)) {
1267 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
1270 case GL_VERTEX_ATTRIB_BINDING
:
1271 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1272 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
1275 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
1276 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1277 return array
->RelativeOffset
;
1281 ; /* fall-through */
1285 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
1290 static const GLfloat
*
1291 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
1294 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
1295 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
1299 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1300 _mesa_error(ctx
, GL_INVALID_VALUE
,
1301 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
1305 assert(VERT_ATTRIB_GENERIC(index
) <
1306 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1308 FLUSH_CURRENT(ctx
, 0);
1309 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
1313 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
1315 GET_CURRENT_CONTEXT(ctx
);
1317 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1318 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
1324 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1326 "glGetVertexAttribfv");
1332 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1334 GET_CURRENT_CONTEXT(ctx
);
1336 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1337 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
1339 params
[0] = (GLdouble
) v
[0];
1340 params
[1] = (GLdouble
) v
[1];
1341 params
[2] = (GLdouble
) v
[2];
1342 params
[3] = (GLdouble
) v
[3];
1346 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1348 "glGetVertexAttribdv");
1353 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1355 GET_CURRENT_CONTEXT(ctx
);
1357 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1359 (const GLdouble
*)get_current_attrib(ctx
, index
,
1360 "glGetVertexAttribLdv");
1369 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1371 "glGetVertexAttribLdv");
1376 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1378 GET_CURRENT_CONTEXT(ctx
);
1380 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1381 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1383 /* XXX should floats in[0,1] be scaled to full int range? */
1384 params
[0] = (GLint
) v
[0];
1385 params
[1] = (GLint
) v
[1];
1386 params
[2] = (GLint
) v
[2];
1387 params
[3] = (GLint
) v
[3];
1391 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1393 "glGetVertexAttribiv");
1398 _mesa_GetVertexAttribLui64vARB(GLuint index
, GLenum pname
, GLuint64EXT
*params
)
1400 GET_CURRENT_CONTEXT(ctx
);
1402 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1404 (const GLuint64
*)get_current_attrib(ctx
, index
,
1405 "glGetVertexAttribLui64vARB");
1414 params
[0] = (GLuint64
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1416 "glGetVertexAttribLui64vARB");
1423 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1425 GET_CURRENT_CONTEXT(ctx
);
1427 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1428 const GLint
*v
= (const GLint
*)
1429 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1435 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1437 "glGetVertexAttribIiv");
1444 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1446 GET_CURRENT_CONTEXT(ctx
);
1448 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1449 const GLuint
*v
= (const GLuint
*)
1450 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1456 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1458 "glGetVertexAttribIuiv");
1464 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1466 GET_CURRENT_CONTEXT(ctx
);
1468 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1469 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1473 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1474 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1478 assert(VERT_ATTRIB_GENERIC(index
) <
1479 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1481 *pointer
= (GLvoid
*)
1482 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1486 /** ARB_direct_state_access */
1488 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1489 GLenum pname
, GLint
*params
)
1491 GET_CURRENT_CONTEXT(ctx
);
1492 struct gl_vertex_array_object
*vao
;
1494 /* The ARB_direct_state_access specification says:
1496 * "An INVALID_OPERATION error is generated if <vaobj> is not
1497 * [compatibility profile: zero or] the name of an existing
1498 * vertex array object."
1500 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexediv");
1504 /* The ARB_direct_state_access specification says:
1506 * "For GetVertexArrayIndexediv, <pname> must be one of
1507 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1508 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1509 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1510 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1511 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1515 * "Add GetVertexArrayIndexediv in 'Get Command' for
1516 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1517 * VERTEX_ATTRIB_BINDING,
1518 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1519 * VERTEX_BINDING_OFFSET, and
1520 * VERTEX_BINDING_STRIDE states"
1522 * The only parameter name common to both lists is
1523 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1524 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1525 * pretty clear however that the intent is that it should be possible
1526 * to query all vertex attrib and binding states that can be set with
1530 case GL_VERTEX_BINDING_OFFSET
:
1531 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1533 case GL_VERTEX_BINDING_STRIDE
:
1534 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1536 case GL_VERTEX_BINDING_DIVISOR
:
1537 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1539 case GL_VERTEX_BINDING_BUFFER
:
1540 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1543 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1544 "glGetVertexArrayIndexediv");
1551 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1552 GLenum pname
, GLint64
*params
)
1554 GET_CURRENT_CONTEXT(ctx
);
1555 struct gl_vertex_array_object
*vao
;
1557 /* The ARB_direct_state_access specification says:
1559 * "An INVALID_OPERATION error is generated if <vaobj> is not
1560 * [compatibility profile: zero or] the name of an existing
1561 * vertex array object."
1563 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1567 /* The ARB_direct_state_access specification says:
1569 * "For GetVertexArrayIndexed64iv, <pname> must be
1570 * VERTEX_BINDING_OFFSET."
1574 * "An INVALID_ENUM error is generated if <pname> is not one of
1575 * the valid values listed above for the corresponding command."
1577 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1578 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1579 "pname != GL_VERTEX_BINDING_OFFSET)");
1583 /* The ARB_direct_state_access specification says:
1585 * "An INVALID_VALUE error is generated if <index> is greater than
1586 * or equal to the value of MAX_VERTEX_ATTRIBS."
1588 * Since the index refers to a buffer binding in this case, the intended
1589 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1590 * required to be the same, so in practice this doesn't matter.
1592 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1593 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1594 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1595 index
, ctx
->Const
.MaxVertexAttribBindings
);
1599 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1604 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1605 GLsizei count
, const GLvoid
*ptr
)
1608 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1613 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1617 _mesa_NormalPointer(type
, stride
, ptr
);
1622 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1626 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1631 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1635 _mesa_IndexPointer(type
, stride
, ptr
);
1640 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1641 GLsizei count
, const GLvoid
*ptr
)
1644 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1649 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1652 _mesa_EdgeFlagPointer(stride
, ptr
);
1657 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1659 GET_CURRENT_CONTEXT(ctx
);
1660 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1661 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1662 GLenum ctype
= 0; /* color type */
1663 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1664 const GLint toffset
= 0; /* always zero */
1665 GLint defstride
; /* default stride */
1668 FLUSH_VERTICES(ctx
, 0);
1670 f
= sizeof(GLfloat
);
1671 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1674 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1680 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1681 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1686 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1687 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1692 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1693 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1694 ctype
= GL_UNSIGNED_BYTE
;
1697 defstride
= c
+ 2*f
;
1700 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1701 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1702 ctype
= GL_UNSIGNED_BYTE
;
1705 defstride
= c
+ 3*f
;
1708 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1709 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1716 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1717 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1722 case GL_C4F_N3F_V3F
:
1723 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1724 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1732 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1733 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1738 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1739 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1743 case GL_T2F_C4UB_V3F
:
1744 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1745 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1746 ctype
= GL_UNSIGNED_BYTE
;
1751 case GL_T2F_C3F_V3F
:
1752 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1753 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1759 case GL_T2F_N3F_V3F
:
1760 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1761 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1766 case GL_T2F_C4F_N3F_V3F
:
1767 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1768 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1775 case GL_T4F_C4F_N3F_V4F
:
1776 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1777 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1785 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1793 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1794 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1795 /* XXX also disable secondary color and generic arrays? */
1799 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1800 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1801 (GLubyte
*) pointer
+ toffset
);
1804 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1809 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1810 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1811 (GLubyte
*) pointer
+ coffset
);
1814 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1820 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1821 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1824 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1828 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1829 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1830 (GLubyte
*) pointer
+ voffset
);
1835 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1837 GET_CURRENT_CONTEXT(ctx
);
1839 FLUSH_VERTICES(ctx
, 0);
1841 if (MESA_VERBOSE
& VERBOSE_API
)
1842 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1845 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1849 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1852 if (ctx
->Array
.LockCount
!= 0) {
1853 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1857 ctx
->Array
.LockFirst
= first
;
1858 ctx
->Array
.LockCount
= count
;
1860 ctx
->NewState
|= _NEW_ARRAY
;
1865 _mesa_UnlockArraysEXT( void )
1867 GET_CURRENT_CONTEXT(ctx
);
1869 FLUSH_VERTICES(ctx
, 0);
1871 if (MESA_VERBOSE
& VERBOSE_API
)
1872 _mesa_debug(ctx
, "glUnlockArrays\n");
1874 if (ctx
->Array
.LockCount
== 0) {
1875 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1879 ctx
->Array
.LockFirst
= 0;
1880 ctx
->Array
.LockCount
= 0;
1881 ctx
->NewState
|= _NEW_ARRAY
;
1885 /* GL_IBM_multimode_draw_arrays */
1887 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1888 const GLsizei
* count
,
1889 GLsizei primcount
, GLint modestride
)
1891 GET_CURRENT_CONTEXT(ctx
);
1894 FLUSH_VERTICES(ctx
, 0);
1896 for ( i
= 0 ; i
< primcount
; i
++ ) {
1897 if ( count
[i
] > 0 ) {
1898 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1899 CALL_DrawArrays(ctx
->CurrentServerDispatch
, ( m
, first
[i
], count
[i
] ));
1905 /* GL_IBM_multimode_draw_arrays */
1907 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1908 GLenum type
, const GLvoid
* const * indices
,
1909 GLsizei primcount
, GLint modestride
)
1911 GET_CURRENT_CONTEXT(ctx
);
1914 FLUSH_VERTICES(ctx
, 0);
1916 /* XXX not sure about ARB_vertex_buffer_object handling here */
1918 for ( i
= 0 ; i
< primcount
; i
++ ) {
1919 if ( count
[i
] > 0 ) {
1920 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1921 CALL_DrawElements(ctx
->CurrentServerDispatch
, ( m
, count
[i
], type
,
1929 primitive_restart_index(struct gl_context
*ctx
, GLuint index
)
1931 if (ctx
->Array
.RestartIndex
!= index
) {
1932 FLUSH_VERTICES(ctx
, 0);
1933 ctx
->Array
.RestartIndex
= index
;
1939 * GL_NV_primitive_restart and GL 3.1
1942 _mesa_PrimitiveRestartIndex_no_error(GLuint index
)
1944 GET_CURRENT_CONTEXT(ctx
);
1945 primitive_restart_index(ctx
, index
);
1950 _mesa_PrimitiveRestartIndex(GLuint index
)
1952 GET_CURRENT_CONTEXT(ctx
);
1954 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1955 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1959 primitive_restart_index(ctx
, index
);
1964 _mesa_VertexAttribDivisor_no_error(GLuint index
, GLuint divisor
)
1966 GET_CURRENT_CONTEXT(ctx
);
1968 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
1969 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1971 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
1973 /* The ARB_vertex_attrib_binding spec says:
1977 * void VertexAttribDivisor(uint index, uint divisor);
1979 * is equivalent to (assuming no errors are generated):
1981 * VertexAttribBinding(index, index);
1982 * VertexBindingDivisor(index, divisor);"
1984 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
1985 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
1990 * See GL_ARB_instanced_arrays.
1991 * Note that the instance divisor only applies to generic arrays, not
1992 * the legacy vertex arrays.
1995 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1997 GET_CURRENT_CONTEXT(ctx
);
1999 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2000 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2002 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2003 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
2007 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2008 _mesa_error(ctx
, GL_INVALID_VALUE
,
2009 "glVertexAttribDivisor(index = %u)", index
);
2013 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2015 /* The ARB_vertex_attrib_binding spec says:
2019 * void VertexAttribDivisor(uint index, uint divisor);
2021 * is equivalent to (assuming no errors are generated):
2023 * VertexAttribBinding(index, index);
2024 * VertexBindingDivisor(index, divisor);"
2026 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2027 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2031 static ALWAYS_INLINE
void
2032 vertex_array_vertex_buffer(struct gl_context
*ctx
,
2033 struct gl_vertex_array_object
*vao
,
2034 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2035 GLsizei stride
, bool no_error
, const char *func
)
2037 struct gl_buffer_object
*vbo
;
2039 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
2040 vbo
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
2041 } else if (buffer
!= 0) {
2042 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
2044 if (!no_error
&& !vbo
&& _mesa_is_gles31(ctx
)) {
2045 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
2048 /* From the GL_ARB_vertex_attrib_array spec:
2050 * "[Core profile only:]
2051 * An INVALID_OPERATION error is generated if buffer is not zero or a
2052 * name returned from a previous call to GenBuffers, or if such a name
2053 * has since been deleted with DeleteBuffers.
2055 * Otherwise, we fall back to the same compat profile behavior as other
2056 * object references (automatically gen it).
2058 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
2061 /* The ARB_vertex_attrib_binding spec says:
2063 * "If <buffer> is zero, any buffer object attached to this
2064 * bindpoint is detached."
2066 vbo
= ctx
->Shared
->NullBufferObj
;
2069 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
2070 vbo
, offset
, stride
);
2075 * GL_ARB_vertex_attrib_binding
2078 vertex_array_vertex_buffer_err(struct gl_context
*ctx
,
2079 struct gl_vertex_array_object
*vao
,
2080 GLuint bindingIndex
, GLuint buffer
,
2081 GLintptr offset
, GLsizei stride
,
2084 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2086 /* The ARB_vertex_attrib_binding spec says:
2088 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2089 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2091 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2092 _mesa_error(ctx
, GL_INVALID_VALUE
,
2093 "%s(bindingindex=%u > "
2094 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2095 func
, bindingIndex
);
2099 /* The ARB_vertex_attrib_binding spec says:
2101 * "The error INVALID_VALUE is generated if <stride> or <offset>
2105 _mesa_error(ctx
, GL_INVALID_VALUE
,
2106 "%s(offset=%" PRId64
" < 0)",
2107 func
, (int64_t) offset
);
2112 _mesa_error(ctx
, GL_INVALID_VALUE
,
2113 "%s(stride=%d < 0)", func
, stride
);
2117 if (((ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
2118 stride
> ctx
->Const
.MaxVertexAttribStride
) {
2119 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
2120 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
2124 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2125 stride
, false, func
);
2130 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex
, GLuint buffer
,
2131 GLintptr offset
, GLsizei stride
)
2133 GET_CURRENT_CONTEXT(ctx
);
2134 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2135 buffer
, offset
, stride
, true,
2136 "glBindVertexBuffer");
2141 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2144 GET_CURRENT_CONTEXT(ctx
);
2146 /* The ARB_vertex_attrib_binding spec says:
2148 * "An INVALID_OPERATION error is generated if no vertex array object
2151 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2152 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2153 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2154 "glBindVertexBuffer(No array object bound)");
2158 vertex_array_vertex_buffer_err(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2159 buffer
, offset
, stride
,
2160 "glBindVertexBuffer");
2165 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj
, GLuint bindingIndex
,
2166 GLuint buffer
, GLintptr offset
,
2169 GET_CURRENT_CONTEXT(ctx
);
2171 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2172 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2173 stride
, true, "glVertexArrayVertexBuffer");
2178 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
2179 GLintptr offset
, GLsizei stride
)
2181 GET_CURRENT_CONTEXT(ctx
);
2182 struct gl_vertex_array_object
*vao
;
2184 /* The ARB_direct_state_access specification says:
2186 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2187 * if <vaobj> is not [compatibility profile: zero or] the name of an
2188 * existing vertex array object."
2190 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
2194 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
2195 stride
, "glVertexArrayVertexBuffer");
2199 static ALWAYS_INLINE
void
2200 vertex_array_vertex_buffers(struct gl_context
*ctx
,
2201 struct gl_vertex_array_object
*vao
,
2202 GLuint first
, GLsizei count
, const GLuint
*buffers
,
2203 const GLintptr
*offsets
, const GLsizei
*strides
,
2204 bool no_error
, const char *func
)
2210 * The ARB_multi_bind spec says:
2212 * "If <buffers> is NULL, each affected vertex buffer binding point
2213 * from <first> through <first>+<count>-1 will be reset to have no
2214 * bound buffer object. In this case, the offsets and strides
2215 * associated with the binding points are set to default values,
2216 * ignoring <offsets> and <strides>."
2218 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
2220 for (i
= 0; i
< count
; i
++)
2221 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2227 /* Note that the error semantics for multi-bind commands differ from
2228 * those of other GL commands.
2230 * The Issues section in the ARB_multi_bind spec says:
2232 * "(11) Typically, OpenGL specifies that if an error is generated by
2233 * a command, that command has no effect. This is somewhat
2234 * unfortunate for multi-bind commands, because it would require
2235 * a first pass to scan the entire list of bound objects for
2236 * errors and then a second pass to actually perform the
2237 * bindings. Should we have different error semantics?
2239 * RESOLVED: Yes. In this specification, when the parameters for
2240 * one of the <count> binding points are invalid, that binding
2241 * point is not updated and an error will be generated. However,
2242 * other binding points in the same command will be updated if
2243 * their parameters are valid and no other error occurs."
2246 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
2248 for (i
= 0; i
< count
; i
++) {
2249 struct gl_buffer_object
*vbo
;
2252 /* The ARB_multi_bind spec says:
2254 * "An INVALID_VALUE error is generated if any value in
2255 * <offsets> or <strides> is negative (per binding)."
2257 if (offsets
[i
] < 0) {
2258 _mesa_error(ctx
, GL_INVALID_VALUE
,
2259 "%s(offsets[%u]=%" PRId64
" < 0)",
2260 func
, i
, (int64_t) offsets
[i
]);
2264 if (strides
[i
] < 0) {
2265 _mesa_error(ctx
, GL_INVALID_VALUE
,
2266 "%s(strides[%u]=%d < 0)",
2267 func
, i
, strides
[i
]);
2271 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
2272 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
2273 _mesa_error(ctx
, GL_INVALID_VALUE
,
2274 "%s(strides[%u]=%d > "
2275 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
2281 struct gl_vertex_buffer_binding
*binding
=
2282 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
2284 if (buffers
[i
] == binding
->BufferObj
->Name
)
2285 vbo
= binding
->BufferObj
;
2287 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
2292 vbo
= ctx
->Shared
->NullBufferObj
;
2295 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2296 vbo
, offsets
[i
], strides
[i
]);
2299 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
2304 vertex_array_vertex_buffers_err(struct gl_context
*ctx
,
2305 struct gl_vertex_array_object
*vao
,
2306 GLuint first
, GLsizei count
,
2307 const GLuint
*buffers
, const GLintptr
*offsets
,
2308 const GLsizei
*strides
, const char *func
)
2310 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2312 /* The ARB_multi_bind spec says:
2314 * "An INVALID_OPERATION error is generated if <first> + <count>
2315 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
2317 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
2318 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2319 "%s(first=%u + count=%d > the value of "
2320 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
2321 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
2325 vertex_array_vertex_buffers(ctx
, vao
, first
, count
, buffers
, offsets
,
2326 strides
, false, func
);
2331 _mesa_BindVertexBuffers_no_error(GLuint first
, GLsizei count
,
2332 const GLuint
*buffers
, const GLintptr
*offsets
,
2333 const GLsizei
*strides
)
2335 GET_CURRENT_CONTEXT(ctx
);
2337 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
2338 buffers
, offsets
, strides
, true,
2339 "glBindVertexBuffers");
2344 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
2345 const GLintptr
*offsets
, const GLsizei
*strides
)
2347 GET_CURRENT_CONTEXT(ctx
);
2349 /* The ARB_vertex_attrib_binding spec says:
2351 * "An INVALID_OPERATION error is generated if no
2352 * vertex array object is bound."
2354 if (ctx
->API
== API_OPENGL_CORE
&&
2355 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2356 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2357 "glBindVertexBuffers(No array object bound)");
2361 vertex_array_vertex_buffers_err(ctx
, ctx
->Array
.VAO
, first
, count
,
2362 buffers
, offsets
, strides
,
2363 "glBindVertexBuffers");
2368 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj
, GLuint first
,
2369 GLsizei count
, const GLuint
*buffers
,
2370 const GLintptr
*offsets
,
2371 const GLsizei
*strides
)
2373 GET_CURRENT_CONTEXT(ctx
);
2375 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2376 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
2377 buffers
, offsets
, strides
, true,
2378 "glVertexArrayVertexBuffers");
2383 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
2384 const GLuint
*buffers
,
2385 const GLintptr
*offsets
, const GLsizei
*strides
)
2387 GET_CURRENT_CONTEXT(ctx
);
2388 struct gl_vertex_array_object
*vao
;
2390 /* The ARB_direct_state_access specification says:
2392 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2393 * if <vaobj> is not [compatibility profile: zero or] the name of an
2394 * existing vertex array object."
2396 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
2400 vertex_array_vertex_buffers_err(ctx
, vao
, first
, count
,
2401 buffers
, offsets
, strides
,
2402 "glVertexArrayVertexBuffers");
2407 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
2408 GLboolean normalized
, GLboolean integer
,
2409 GLboolean doubles
, GLbitfield legalTypes
,
2410 GLsizei sizeMax
, GLuint relativeOffset
,
2413 GET_CURRENT_CONTEXT(ctx
);
2414 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2416 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2418 if (!_mesa_is_no_error_enabled(ctx
)) {
2419 /* The ARB_vertex_attrib_binding spec says:
2421 * "An INVALID_OPERATION error is generated under any of the
2422 * following conditions:
2423 * - if no vertex array object is currently bound (see section
2427 * This error condition only applies to VertexAttribFormat and
2428 * VertexAttribIFormat in the extension spec, but we assume that this
2429 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2430 * to all three functions.
2432 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2433 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2434 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2435 "%s(No array object bound)", func
);
2439 /* The ARB_vertex_attrib_binding spec says:
2441 * "The error INVALID_VALUE is generated if index is greater than or
2442 * equal to the value of MAX_VERTEX_ATTRIBS."
2444 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2445 _mesa_error(ctx
, GL_INVALID_VALUE
,
2446 "%s(attribindex=%u > "
2447 "GL_MAX_VERTEX_ATTRIBS)",
2452 if (!validate_array_format(ctx
, func
, ctx
->Array
.VAO
,
2453 VERT_ATTRIB_GENERIC(attribIndex
),
2454 legalTypes
, 1, sizeMax
, size
, type
,
2455 normalized
, integer
, doubles
, relativeOffset
,
2461 FLUSH_VERTICES(ctx
, 0);
2463 _mesa_update_array_format(ctx
, ctx
->Array
.VAO
,
2464 VERT_ATTRIB_GENERIC(attribIndex
), size
, type
,
2465 format
, normalized
, integer
, doubles
,
2471 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2472 GLboolean normalized
, GLuint relativeOffset
)
2474 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
2475 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2476 BGRA_OR_4
, relativeOffset
,
2477 "glVertexAttribFormat");
2482 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2483 GLuint relativeOffset
)
2485 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2486 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2487 relativeOffset
, "glVertexAttribIFormat");
2492 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2493 GLuint relativeOffset
)
2495 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2496 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2497 relativeOffset
, "glVertexAttribLFormat");
2502 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2503 GLenum type
, GLboolean normalized
,
2504 GLboolean integer
, GLboolean doubles
,
2505 GLbitfield legalTypes
, GLsizei sizeMax
,
2506 GLuint relativeOffset
, const char *func
)
2508 GET_CURRENT_CONTEXT(ctx
);
2509 struct gl_vertex_array_object
*vao
;
2511 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2513 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2515 if (_mesa_is_no_error_enabled(ctx
)) {
2516 vao
= _mesa_lookup_vao(ctx
, vaobj
);
2520 /* The ARB_direct_state_access spec says:
2522 * "An INVALID_OPERATION error is generated by
2523 * VertexArrayAttrib*Format if <vaobj> is not [compatibility profile:
2524 * zero or] the name of an existing vertex array object."
2526 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2530 /* The ARB_vertex_attrib_binding spec says:
2532 * "The error INVALID_VALUE is generated if index is greater than or
2533 * equal to the value of MAX_VERTEX_ATTRIBS."
2535 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2536 _mesa_error(ctx
, GL_INVALID_VALUE
,
2537 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2542 if (!validate_array_format(ctx
, func
, vao
,
2543 VERT_ATTRIB_GENERIC(attribIndex
),
2544 legalTypes
, 1, sizeMax
, size
, type
,
2545 normalized
, integer
, doubles
, relativeOffset
,
2551 FLUSH_VERTICES(ctx
, 0);
2553 _mesa_update_array_format(ctx
, vao
, VERT_ATTRIB_GENERIC(attribIndex
), size
,
2554 type
, format
, normalized
, integer
, doubles
,
2560 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2561 GLenum type
, GLboolean normalized
,
2562 GLuint relativeOffset
)
2564 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2565 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2566 BGRA_OR_4
, relativeOffset
,
2567 "glVertexArrayAttribFormat");
2572 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2573 GLint size
, GLenum type
,
2574 GLuint relativeOffset
)
2576 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2577 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2579 "glVertexArrayAttribIFormat");
2584 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2585 GLint size
, GLenum type
,
2586 GLuint relativeOffset
)
2588 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2589 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2591 "glVertexArrayAttribLFormat");
2596 vertex_array_attrib_binding(struct gl_context
*ctx
,
2597 struct gl_vertex_array_object
*vao
,
2598 GLuint attribIndex
, GLuint bindingIndex
,
2601 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2603 /* The ARB_vertex_attrib_binding spec says:
2605 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2606 * <bindingindex> must be less than the value of
2607 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2610 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2611 _mesa_error(ctx
, GL_INVALID_VALUE
,
2612 "%s(attribindex=%u >= "
2613 "GL_MAX_VERTEX_ATTRIBS)",
2618 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2619 _mesa_error(ctx
, GL_INVALID_VALUE
,
2620 "%s(bindingindex=%u >= "
2621 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2622 func
, bindingIndex
);
2626 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2628 vertex_attrib_binding(ctx
, vao
,
2629 VERT_ATTRIB_GENERIC(attribIndex
),
2630 VERT_ATTRIB_GENERIC(bindingIndex
));
2635 _mesa_VertexAttribBinding_no_error(GLuint attribIndex
, GLuint bindingIndex
)
2637 GET_CURRENT_CONTEXT(ctx
);
2638 vertex_attrib_binding(ctx
, ctx
->Array
.VAO
,
2639 VERT_ATTRIB_GENERIC(attribIndex
),
2640 VERT_ATTRIB_GENERIC(bindingIndex
));
2645 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2647 GET_CURRENT_CONTEXT(ctx
);
2649 /* The ARB_vertex_attrib_binding spec says:
2651 * "An INVALID_OPERATION error is generated if no vertex array object
2654 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2655 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2656 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2657 "glVertexAttribBinding(No array object bound)");
2661 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2662 attribIndex
, bindingIndex
,
2663 "glVertexAttribBinding");
2668 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj
, GLuint attribIndex
,
2669 GLuint bindingIndex
)
2671 GET_CURRENT_CONTEXT(ctx
);
2673 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2674 vertex_attrib_binding(ctx
, vao
,
2675 VERT_ATTRIB_GENERIC(attribIndex
),
2676 VERT_ATTRIB_GENERIC(bindingIndex
));
2681 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2683 GET_CURRENT_CONTEXT(ctx
);
2684 struct gl_vertex_array_object
*vao
;
2686 /* The ARB_direct_state_access specification says:
2688 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2689 * if <vaobj> is not [compatibility profile: zero or] the name of an
2690 * existing vertex array object."
2692 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2696 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2697 "glVertexArrayAttribBinding");
2702 vertex_array_binding_divisor(struct gl_context
*ctx
,
2703 struct gl_vertex_array_object
*vao
,
2704 GLuint bindingIndex
, GLuint divisor
,
2707 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2709 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2710 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2714 /* The ARB_vertex_attrib_binding spec says:
2716 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2717 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2719 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2720 _mesa_error(ctx
, GL_INVALID_VALUE
,
2721 "%s(bindingindex=%u > "
2722 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2723 func
, bindingIndex
);
2727 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2732 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex
, GLuint divisor
)
2734 GET_CURRENT_CONTEXT(ctx
);
2735 vertex_binding_divisor(ctx
, ctx
->Array
.VAO
,
2736 VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2741 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2743 GET_CURRENT_CONTEXT(ctx
);
2745 /* The ARB_vertex_attrib_binding spec says:
2747 * "An INVALID_OPERATION error is generated if no vertex array object
2750 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2751 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2752 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2753 "glVertexBindingDivisor(No array object bound)");
2757 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2758 bindingIndex
, divisor
,
2759 "glVertexBindingDivisor");
2764 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj
, GLuint bindingIndex
,
2767 GET_CURRENT_CONTEXT(ctx
);
2769 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2770 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2775 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2778 struct gl_vertex_array_object
*vao
;
2779 GET_CURRENT_CONTEXT(ctx
);
2781 /* The ARB_direct_state_access specification says:
2783 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2784 * if <vaobj> is not [compatibility profile: zero or] the name of an
2785 * existing vertex array object."
2787 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2791 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2792 "glVertexArrayBindingDivisor");
2797 * Copy one vertex array to another.
2800 _mesa_copy_vertex_array(struct gl_context
*ctx
,
2801 struct gl_vertex_array
*dst
,
2802 struct gl_vertex_array
*src
)
2804 dst
->Size
= src
->Size
;
2805 dst
->Type
= src
->Type
;
2806 dst
->Format
= src
->Format
;
2807 dst
->StrideB
= src
->StrideB
;
2808 dst
->Ptr
= src
->Ptr
;
2809 dst
->Normalized
= src
->Normalized
;
2810 dst
->Integer
= src
->Integer
;
2811 dst
->Doubles
= src
->Doubles
;
2812 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2813 dst
->_ElementSize
= src
->_ElementSize
;
2814 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2818 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2819 struct gl_array_attributes
*dst
,
2820 const struct gl_array_attributes
*src
)
2822 dst
->Size
= src
->Size
;
2823 dst
->Type
= src
->Type
;
2824 dst
->Format
= src
->Format
;
2825 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
2826 dst
->RelativeOffset
= src
->RelativeOffset
;
2827 dst
->Format
= src
->Format
;
2828 dst
->Integer
= src
->Integer
;
2829 dst
->Doubles
= src
->Doubles
;
2830 dst
->Normalized
= src
->Normalized
;
2831 dst
->Ptr
= src
->Ptr
;
2832 dst
->Enabled
= src
->Enabled
;
2833 dst
->_ElementSize
= src
->_ElementSize
;
2837 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2838 struct gl_vertex_buffer_binding
*dst
,
2839 const struct gl_vertex_buffer_binding
*src
)
2841 dst
->Offset
= src
->Offset
;
2842 dst
->Stride
= src
->Stride
;
2843 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2844 dst
->_BoundArrays
= src
->_BoundArrays
;
2846 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2850 * Print current vertex object/array info. For debug.
2853 _mesa_print_arrays(struct gl_context
*ctx
)
2855 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2857 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
2860 for (i
= 0; i
< VERT_ATTRIB_MAX
; ++i
) {
2861 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
2862 if (!array
->Enabled
)
2865 const struct gl_vertex_buffer_binding
*binding
=
2866 &vao
->BufferBinding
[array
->BufferBindingIndex
];
2867 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
2869 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2870 "Stride=%d, Buffer=%u(Size %lu)\n",
2871 gl_vert_attrib_name((gl_vert_attrib
)i
),
2872 array
->Ptr
, _mesa_enum_to_string(array
->Type
), array
->Size
,
2873 array
->_ElementSize
, binding
->Stride
, bo
->Name
,
2874 (unsigned long) bo
->Size
);
2880 * Initialize vertex array state for given context.
2883 _mesa_init_varray(struct gl_context
*ctx
)
2885 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2886 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2887 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2889 ctx
->Array
.Objects
= _mesa_NewHashTable();
2894 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2897 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2899 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2900 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2901 _mesa_delete_vao(ctx
, vao
);
2906 * Free vertex array state for given context.
2909 _mesa_free_varray_data(struct gl_context
*ctx
)
2911 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2912 _mesa_DeleteHashTable(ctx
->Array
.Objects
);