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"
36 #include "glformats.h"
43 #include "main/dispatch.h"
46 /** Used to do error checking for GL_EXT_vertex_array_bgra */
50 /** Used to indicate which GL datatypes are accepted by each of the
51 * glVertex/Color/Attrib/EtcPointer() functions.
53 #define BOOL_BIT (1 << 0)
54 #define BYTE_BIT (1 << 1)
55 #define UNSIGNED_BYTE_BIT (1 << 2)
56 #define SHORT_BIT (1 << 3)
57 #define UNSIGNED_SHORT_BIT (1 << 4)
58 #define INT_BIT (1 << 5)
59 #define UNSIGNED_INT_BIT (1 << 6)
60 #define HALF_BIT (1 << 7)
61 #define FLOAT_BIT (1 << 8)
62 #define DOUBLE_BIT (1 << 9)
63 #define FIXED_ES_BIT (1 << 10)
64 #define FIXED_GL_BIT (1 << 11)
65 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
66 #define INT_2_10_10_10_REV_BIT (1 << 13)
67 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
68 #define ALL_TYPE_BITS ((1 << 15) - 1)
70 #define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
71 SHORT_BIT | UNSIGNED_SHORT_BIT | \
72 INT_BIT | UNSIGNED_INT_BIT | \
73 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
75 UNSIGNED_INT_2_10_10_10_REV_BIT | \
76 INT_2_10_10_10_REV_BIT | \
77 UNSIGNED_INT_10F_11F_11F_REV_BIT)
79 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
80 SHORT_BIT | UNSIGNED_SHORT_BIT | \
81 INT_BIT | UNSIGNED_INT_BIT)
83 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
86 /** Convert GL datatype enum into a <type>_BIT value seen above */
88 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
95 case GL_UNSIGNED_BYTE
:
96 return UNSIGNED_BYTE_BIT
;
99 case GL_UNSIGNED_SHORT
:
100 return UNSIGNED_SHORT_BIT
;
103 case GL_UNSIGNED_INT
:
104 return UNSIGNED_INT_BIT
;
106 case GL_HALF_FLOAT_OES
:
107 if (ctx
->Extensions
.ARB_half_float_vertex
)
116 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
117 case GL_UNSIGNED_INT_2_10_10_10_REV
:
118 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
119 case GL_INT_2_10_10_10_REV
:
120 return INT_2_10_10_10_REV_BIT
;
121 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
122 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
130 * Depending on the position and generic0 attributes enable flags select
131 * the one that is used for both attributes.
132 * The generic0 attribute takes precedence.
135 update_attribute_map_mode(const struct gl_context
*ctx
,
136 struct gl_vertex_array_object
*vao
)
139 * There is no need to change the mapping away from the
140 * identity mapping if we are not in compat mode.
142 if (ctx
->API
!= API_OPENGL_COMPAT
)
144 /* The generic0 attribute superseeds the position attribute */
145 const GLbitfield enabled
= vao
->Enabled
;
146 if (enabled
& VERT_BIT_GENERIC0
)
147 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_GENERIC0
;
148 else if (enabled
& VERT_BIT_POS
)
149 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_POSITION
;
151 vao
->_AttributeMapMode
= ATTRIBUTE_MAP_MODE_IDENTITY
;
156 * Sets the BufferBindingIndex field for the vertex attribute given by
160 _mesa_vertex_attrib_binding(struct gl_context
*ctx
,
161 struct gl_vertex_array_object
*vao
,
162 gl_vert_attrib attribIndex
,
165 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attribIndex
];
166 assert(!vao
->SharedAndImmutable
);
168 if (array
->BufferBindingIndex
!= bindingIndex
) {
169 const GLbitfield array_bit
= VERT_BIT(attribIndex
);
171 if (_mesa_is_bufferobj(vao
->BufferBinding
[bindingIndex
].BufferObj
))
172 vao
->VertexAttribBufferMask
|= array_bit
;
174 vao
->VertexAttribBufferMask
&= ~array_bit
;
176 vao
->BufferBinding
[array
->BufferBindingIndex
]._BoundArrays
&= ~array_bit
;
177 vao
->BufferBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
179 array
->BufferBindingIndex
= bindingIndex
;
181 vao
->NewArrays
|= vao
->Enabled
& array_bit
;
187 * Binds a buffer object to the vertex buffer binding point given by index,
188 * and sets the Offset and Stride fields.
191 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
192 struct gl_vertex_array_object
*vao
,
194 struct gl_buffer_object
*vbo
,
195 GLintptr offset
, GLsizei stride
)
197 assert(index
< ARRAY_SIZE(vao
->BufferBinding
));
198 assert(!vao
->SharedAndImmutable
);
199 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
201 if (binding
->BufferObj
!= vbo
||
202 binding
->Offset
!= offset
||
203 binding
->Stride
!= stride
) {
205 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
207 binding
->Offset
= offset
;
208 binding
->Stride
= stride
;
210 if (!_mesa_is_bufferobj(vbo
)) {
211 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
213 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
214 vbo
->UsageHistory
|= USAGE_ARRAY_BUFFER
;
217 vao
->NewArrays
|= vao
->Enabled
& binding
->_BoundArrays
;
223 * Sets the InstanceDivisor field in the vertex buffer binding point
224 * given by bindingIndex.
227 vertex_binding_divisor(struct gl_context
*ctx
,
228 struct gl_vertex_array_object
*vao
,
232 struct gl_vertex_buffer_binding
*binding
=
233 &vao
->BufferBinding
[bindingIndex
];
234 assert(!vao
->SharedAndImmutable
);
236 if (binding
->InstanceDivisor
!= divisor
) {
237 binding
->InstanceDivisor
= divisor
;
238 vao
->NewArrays
|= vao
->Enabled
& binding
->_BoundArrays
;
244 _mesa_set_vertex_format(struct gl_vertex_format
*vertex_format
,
245 GLubyte size
, GLenum16 type
, GLenum16 format
,
246 GLboolean normalized
, GLboolean integer
,
250 vertex_format
->Type
= type
;
251 vertex_format
->Format
= format
;
252 vertex_format
->Size
= size
;
253 vertex_format
->Normalized
= normalized
;
254 vertex_format
->Integer
= integer
;
255 vertex_format
->Doubles
= doubles
;
256 vertex_format
->_ElementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
257 assert(vertex_format
->_ElementSize
<= 4*sizeof(double));
262 * Examine the API profile and extensions to determine which types are legal
263 * for vertex arrays. This is called once from update_array_format().
266 get_legal_types_mask(const struct gl_context
*ctx
)
268 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
270 if (_mesa_is_gles(ctx
)) {
271 legalTypesMask
&= ~(FIXED_GL_BIT
|
273 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
275 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
276 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
277 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
278 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
279 * quite as trivial as we'd like because it uses a different enum value
280 * for GL_HALF_FLOAT_OES.
282 if (ctx
->Version
< 30) {
283 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
285 UNSIGNED_INT_2_10_10_10_REV_BIT
|
286 INT_2_10_10_10_REV_BIT
);
288 if (!_mesa_has_OES_vertex_half_float(ctx
))
289 legalTypesMask
&= ~HALF_BIT
;
293 legalTypesMask
&= ~FIXED_ES_BIT
;
295 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
296 legalTypesMask
&= ~FIXED_GL_BIT
;
298 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
299 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
300 INT_2_10_10_10_REV_BIT
);
302 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
303 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
306 return legalTypesMask
;
310 get_array_format(const struct gl_context
*ctx
, GLint sizeMax
, GLint
*size
)
312 GLenum format
= GL_RGBA
;
314 /* Do size parameter checking.
315 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
316 * must be handled specially.
318 if (ctx
->Extensions
.EXT_vertex_array_bgra
&& sizeMax
== BGRA_OR_4
&&
329 * \param attrib The index of the attribute array
330 * \param size Components per element (1, 2, 3 or 4)
331 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
332 * \param format Either GL_RGBA or GL_BGRA.
333 * \param normalized Whether integer types are converted to floats in [-1, 1]
334 * \param integer Integer-valued values (will not be normalized to [-1, 1])
335 * \param doubles Double values not reduced to floats
336 * \param relativeOffset Offset of the first element relative to the binding
340 _mesa_update_array_format(struct gl_context
*ctx
,
341 struct gl_vertex_array_object
*vao
,
342 gl_vert_attrib attrib
, GLint size
, GLenum type
,
343 GLenum format
, GLboolean normalized
,
344 GLboolean integer
, GLboolean doubles
,
345 GLuint relativeOffset
)
347 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
349 assert(!vao
->SharedAndImmutable
);
352 array
->RelativeOffset
= relativeOffset
;
353 _mesa_set_vertex_format(&array
->Format
, size
, type
, format
,
354 normalized
, integer
, doubles
);
356 vao
->NewArrays
|= vao
->Enabled
& VERT_BIT(attrib
);
360 * Does error checking of the format in an attrib array.
362 * Called by *Pointer() and VertexAttrib*Format().
364 * \param func Name of calling function used for error reporting
365 * \param attrib The index of the attribute array
366 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
367 * \param sizeMin Min allowable size value
368 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
369 * \param size Components per element (1, 2, 3 or 4)
370 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
371 * \param normalized Whether integer types are converted to floats in [-1, 1]
372 * \param integer Integer-valued values (will not be normalized to [-1, 1])
373 * \param doubles Double values not reduced to floats
374 * \param relativeOffset Offset of the first element relative to the binding offset.
375 * \return bool True if validation is successful, False otherwise.
378 validate_array_format(struct gl_context
*ctx
, const char *func
,
379 struct gl_vertex_array_object
*vao
,
380 GLuint attrib
, GLbitfield legalTypesMask
,
381 GLint sizeMin
, GLint sizeMax
,
382 GLint size
, GLenum type
, GLboolean normalized
,
383 GLboolean integer
, GLboolean doubles
,
384 GLuint relativeOffset
, GLenum format
)
388 /* at most, one of these bools can be true */
389 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
391 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
392 /* Compute the LegalTypesMask only once, unless the context API has
393 * changed, in which case we want to compute it again. We can't do this
394 * in _mesa_init_varrays() below because extensions are not yet enabled
397 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
398 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
401 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
403 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
404 /* BGRA ordering is not supported in ES contexts.
409 typeBit
= type_to_bit(ctx
, type
);
410 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
411 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
412 func
, _mesa_enum_to_string(type
));
416 if (format
== GL_BGRA
) {
417 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
419 * "An INVALID_OPERATION error is generated under any of the following
422 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
423 * or UNSIGNED_INT_2_10_10_10_REV;
425 * • size is BGRA and normalized is FALSE;"
427 bool bgra_error
= false;
429 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
430 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
431 type
!= GL_INT_2_10_10_10_REV
&&
432 type
!= GL_UNSIGNED_BYTE
)
434 } else if (type
!= GL_UNSIGNED_BYTE
)
438 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
439 func
, _mesa_enum_to_string(type
));
444 _mesa_error(ctx
, GL_INVALID_OPERATION
,
445 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
449 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
450 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
454 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
455 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
456 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
457 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
461 /* The ARB_vertex_attrib_binding_spec says:
463 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
464 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
466 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
467 _mesa_error(ctx
, GL_INVALID_VALUE
,
468 "%s(relativeOffset=%d > "
469 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
470 func
, relativeOffset
);
474 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
475 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
476 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
484 * Do error checking for glVertex/Color/TexCoord/...Pointer functions.
486 * \param func name of calling function used for error reporting
487 * \param vao the vao to update
488 * \param obj the bound buffer object
489 * \param attrib the attribute array index to update
490 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
491 * \param sizeMin min allowable size value
492 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
493 * \param size components per element (1, 2, 3 or 4)
494 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
495 * \param stride stride between elements, in elements
496 * \param normalized are integer types converted to floats in [-1, 1]?
497 * \param integer integer-valued values (will not be normalized to [-1,1])
498 * \param doubles Double values not reduced to floats
499 * \param ptr the address (or offset inside VBO) of the array data
502 validate_array(struct gl_context
*ctx
, const char *func
,
503 struct gl_vertex_array_object
*vao
,
504 struct gl_buffer_object
*obj
,
505 GLuint attrib
, GLbitfield legalTypesMask
,
506 GLint sizeMin
, GLint sizeMax
,
507 GLint size
, GLenum type
, GLsizei stride
,
508 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
511 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
513 * "Client vertex arrays - all vertex array attribute pointers must
514 * refer to buffer objects (section 2.9.2). The default vertex array
515 * object (the name zero) is also deprecated. Calling
516 * VertexAttribPointer when no buffer object or no vertex array object
517 * is bound will generate an INVALID_OPERATION error..."
519 * The check for VBOs is handled below.
521 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
522 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
528 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
532 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
533 stride
> ctx
->Const
.MaxVertexAttribStride
) {
534 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
535 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
539 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
541 * "An INVALID_OPERATION error is generated under any of the following
546 * * any of the *Pointer commands specifying the location and
547 * organization of vertex array data are called while zero is bound
548 * to the ARRAY_BUFFER buffer object binding point (see section
549 * 2.9.6), and the pointer argument is not NULL."
551 if (ptr
!= NULL
&& vao
!= ctx
->Array
.DefaultVAO
&&
552 !_mesa_is_bufferobj(obj
)) {
553 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
560 validate_array_and_format(struct gl_context
*ctx
, const char *func
,
561 struct gl_vertex_array_object
*vao
,
562 struct gl_buffer_object
*obj
,
563 GLuint attrib
, GLbitfield legalTypes
,
564 GLint sizeMin
, GLint sizeMax
,
565 GLint size
, GLenum type
, GLsizei stride
,
566 GLboolean normalized
, GLboolean integer
,
567 GLboolean doubles
, GLenum format
, const GLvoid
*ptr
)
569 validate_array(ctx
, func
, vao
, obj
, attrib
, legalTypes
, sizeMin
, sizeMax
,
570 size
, type
, stride
, normalized
, integer
, doubles
, ptr
);
572 return validate_array_format(ctx
, func
, vao
, attrib
, legalTypes
, sizeMin
,
573 sizeMax
, size
, type
, normalized
, integer
,
579 * Update state for glVertex/Color/TexCoord/...Pointer functions.
581 * \param vao the vao to update
582 * \param obj the bound buffer object
583 * \param attrib the attribute array index to update
584 * \param format Either GL_RGBA or GL_BGRA.
585 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
586 * \param size components per element (1, 2, 3 or 4)
587 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
588 * \param stride stride between elements, in elements
589 * \param normalized are integer types converted to floats in [-1, 1]?
590 * \param integer integer-valued values (will not be normalized to [-1,1])
591 * \param doubles Double values not reduced to floats
592 * \param ptr the address (or offset inside VBO) of the array data
595 update_array(struct gl_context
*ctx
,
596 struct gl_vertex_array_object
*vao
,
597 struct gl_buffer_object
*obj
,
598 GLuint attrib
, GLenum format
,
600 GLint size
, GLenum type
, GLsizei stride
,
601 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
604 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
605 normalized
, integer
, doubles
, 0);
607 /* Reset the vertex attrib binding */
608 _mesa_vertex_attrib_binding(ctx
, vao
, attrib
, attrib
);
610 /* The Stride and Ptr fields are not set by update_array_format() */
611 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attrib
];
612 array
->Stride
= stride
;
613 /* For updating the pointer we would need to add the vao->NewArrays flag
614 * to the VAO. But but that is done already unconditionally in
615 * _mesa_update_array_format called above.
617 assert((vao
->NewArrays
| ~vao
->Enabled
) & VERT_BIT(attrib
));
620 /* Update the vertex buffer binding */
621 GLsizei effectiveStride
= stride
!= 0 ?
622 stride
: array
->Format
._ElementSize
;
623 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
629 _mesa_VertexPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
632 GET_CURRENT_CONTEXT(ctx
);
634 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
635 VERT_ATTRIB_POS
, GL_RGBA
, 4, size
, type
, stride
,
636 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
641 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
643 GET_CURRENT_CONTEXT(ctx
);
645 GLenum format
= GL_RGBA
;
646 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
647 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
648 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
649 DOUBLE_BIT
| HALF_BIT
|
650 UNSIGNED_INT_2_10_10_10_REV_BIT
|
651 INT_2_10_10_10_REV_BIT
);
653 if (!validate_array_and_format(ctx
, "glVertexPointer",
654 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
655 VERT_ATTRIB_POS
, legalTypes
, 2, 4, size
,
656 type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
660 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
661 VERT_ATTRIB_POS
, format
, 4, size
, type
, stride
,
662 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
667 _mesa_NormalPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
669 GET_CURRENT_CONTEXT(ctx
);
671 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
672 VERT_ATTRIB_NORMAL
, GL_RGBA
, 3, 3, type
, stride
, GL_TRUE
,
673 GL_FALSE
, GL_FALSE
, ptr
);
678 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
680 GET_CURRENT_CONTEXT(ctx
);
682 GLenum format
= GL_RGBA
;
683 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
684 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
685 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
686 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
687 UNSIGNED_INT_2_10_10_10_REV_BIT
|
688 INT_2_10_10_10_REV_BIT
);
690 if (!validate_array_and_format(ctx
, "glNormalPointer",
691 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
692 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
693 type
, stride
, GL_TRUE
, GL_FALSE
,
694 GL_FALSE
, format
, ptr
))
697 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
698 VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
699 GL_FALSE
, GL_FALSE
, ptr
);
704 _mesa_ColorPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
707 GET_CURRENT_CONTEXT(ctx
);
709 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
710 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
711 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
712 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
717 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
719 GET_CURRENT_CONTEXT(ctx
);
720 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
722 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
723 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
724 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
725 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
726 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
727 INT_BIT
| UNSIGNED_INT_BIT
|
728 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
729 UNSIGNED_INT_2_10_10_10_REV_BIT
|
730 INT_2_10_10_10_REV_BIT
);
732 if (!validate_array_and_format(ctx
, "glColorPointer",
733 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
734 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
735 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
736 GL_FALSE
, GL_FALSE
, format
, ptr
))
739 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
740 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
741 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
746 _mesa_FogCoordPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
748 GET_CURRENT_CONTEXT(ctx
);
750 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
751 VERT_ATTRIB_FOG
, GL_RGBA
, 1, 1, type
, stride
, GL_FALSE
,
752 GL_FALSE
, GL_FALSE
, ptr
);
757 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
759 GET_CURRENT_CONTEXT(ctx
);
761 GLenum format
= GL_RGBA
;
762 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
764 if (!validate_array_and_format(ctx
, "glFogCoordPointer",
765 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
766 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
767 type
, stride
, GL_FALSE
, GL_FALSE
,
768 GL_FALSE
, format
, ptr
))
771 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
772 VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
773 GL_FALSE
, GL_FALSE
, ptr
);
778 _mesa_IndexPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
780 GET_CURRENT_CONTEXT(ctx
);
782 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
783 VERT_ATTRIB_COLOR_INDEX
, GL_RGBA
, 1, 1, type
, stride
,
784 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
789 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
791 GET_CURRENT_CONTEXT(ctx
);
793 GLenum format
= GL_RGBA
;
794 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
795 FLOAT_BIT
| DOUBLE_BIT
);
797 if (!validate_array_and_format(ctx
, "glIndexPointer",
798 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
799 VERT_ATTRIB_COLOR_INDEX
,
800 legalTypes
, 1, 1, 1, type
, stride
,
801 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
804 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
805 VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
806 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
811 _mesa_SecondaryColorPointer_no_error(GLint size
, GLenum type
,
812 GLsizei stride
, const GLvoid
*ptr
)
814 GET_CURRENT_CONTEXT(ctx
);
816 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
817 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
818 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
819 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
824 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
825 GLsizei stride
, const GLvoid
*ptr
)
827 GET_CURRENT_CONTEXT(ctx
);
829 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
830 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
831 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
832 INT_BIT
| UNSIGNED_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
, "glSecondaryColorPointer",
838 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
839 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
840 BGRA_OR_4
, size
, type
, stride
,
841 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
844 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
845 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
846 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
851 _mesa_TexCoordPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
854 GET_CURRENT_CONTEXT(ctx
);
855 const GLuint unit
= ctx
->Array
.ActiveTexture
;
857 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
858 VERT_ATTRIB_TEX(unit
), GL_RGBA
, 4, size
, type
,
859 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
864 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
867 GET_CURRENT_CONTEXT(ctx
);
868 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
869 const GLuint unit
= ctx
->Array
.ActiveTexture
;
871 GLenum format
= GL_RGBA
;
872 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
873 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
874 : (SHORT_BIT
| INT_BIT
|
875 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
876 UNSIGNED_INT_2_10_10_10_REV_BIT
|
877 INT_2_10_10_10_REV_BIT
);
879 if (!validate_array_and_format(ctx
, "glTexCoordPointer",
880 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
881 VERT_ATTRIB_TEX(unit
), legalTypes
,
882 sizeMin
, 4, size
, type
, stride
,
883 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
886 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
887 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
888 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
893 _mesa_EdgeFlagPointer_no_error(GLsizei stride
, const GLvoid
*ptr
)
895 /* this is the same type that glEdgeFlag uses */
896 const GLboolean integer
= GL_FALSE
;
897 GET_CURRENT_CONTEXT(ctx
);
899 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
900 VERT_ATTRIB_EDGEFLAG
, GL_RGBA
, 1, 1, GL_UNSIGNED_BYTE
,
901 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
906 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
908 /* this is the same type that glEdgeFlag uses */
909 const GLboolean integer
= GL_FALSE
;
910 GET_CURRENT_CONTEXT(ctx
);
912 GLenum format
= GL_RGBA
;
913 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
915 if (!validate_array_and_format(ctx
, "glEdgeFlagPointer",
916 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
917 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
918 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
919 GL_FALSE
, integer
, GL_FALSE
, format
, ptr
))
922 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
923 VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
924 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
929 _mesa_PointSizePointerOES_no_error(GLenum type
, GLsizei stride
,
932 GET_CURRENT_CONTEXT(ctx
);
934 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
935 VERT_ATTRIB_POINT_SIZE
, GL_RGBA
, 1, 1, type
, stride
,
936 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
941 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
943 GET_CURRENT_CONTEXT(ctx
);
945 GLenum format
= GL_RGBA
;
946 if (ctx
->API
!= API_OPENGLES
) {
947 _mesa_error(ctx
, GL_INVALID_OPERATION
,
948 "glPointSizePointer(ES 1.x only)");
952 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
954 if (!validate_array_and_format(ctx
, "glPointSizePointer",
955 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
956 VERT_ATTRIB_POINT_SIZE
, legalTypes
,
957 1, 1, 1, type
, stride
, GL_FALSE
, GL_FALSE
,
958 GL_FALSE
, format
, ptr
))
961 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
962 VERT_ATTRIB_POINT_SIZE
, format
, 1, 1, type
, stride
,
963 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
968 _mesa_VertexAttribPointer_no_error(GLuint index
, GLint size
, GLenum type
,
969 GLboolean normalized
,
970 GLsizei stride
, const GLvoid
*ptr
)
972 GET_CURRENT_CONTEXT(ctx
);
974 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
975 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
976 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
977 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
982 * Set a generic vertex attribute array.
983 * Note that these arrays DO NOT alias the conventional GL vertex arrays
984 * (position, normal, color, fog, texcoord, etc).
987 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
988 GLboolean normalized
,
989 GLsizei stride
, const GLvoid
*ptr
)
991 GET_CURRENT_CONTEXT(ctx
);
993 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
994 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
995 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(idx)");
999 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1000 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1001 INT_BIT
| UNSIGNED_INT_BIT
|
1002 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1003 FIXED_ES_BIT
| FIXED_GL_BIT
|
1004 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1005 INT_2_10_10_10_REV_BIT
|
1006 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1008 if (!validate_array_and_format(ctx
, "glVertexAttribPointer",
1009 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1010 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1011 1, BGRA_OR_4
, size
, type
, stride
,
1012 normalized
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1015 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1016 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1017 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
1022 _mesa_VertexAttribIPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1023 GLsizei stride
, const GLvoid
*ptr
)
1025 const GLboolean normalized
= GL_FALSE
;
1026 const GLboolean integer
= GL_TRUE
;
1027 GET_CURRENT_CONTEXT(ctx
);
1029 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1030 VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1031 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1036 * GL_EXT_gpu_shader4 / GL 3.0.
1037 * Set an integer-valued vertex attribute array.
1038 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1039 * (position, normal, color, fog, texcoord, etc).
1042 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
1043 GLsizei stride
, const GLvoid
*ptr
)
1045 const GLboolean normalized
= GL_FALSE
;
1046 const GLboolean integer
= GL_TRUE
;
1047 GET_CURRENT_CONTEXT(ctx
);
1049 GLenum format
= GL_RGBA
;
1050 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1051 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
1055 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1056 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1057 INT_BIT
| UNSIGNED_INT_BIT
);
1059 if (!validate_array_and_format(ctx
, "glVertexAttribIPointer",
1060 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1061 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1062 1, 4, size
, type
, stride
,
1063 normalized
, integer
, GL_FALSE
, format
, ptr
))
1066 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1067 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1068 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1073 _mesa_VertexAttribLPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1074 GLsizei stride
, const GLvoid
*ptr
)
1076 GET_CURRENT_CONTEXT(ctx
);
1078 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1079 VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1080 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1085 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
1086 GLsizei stride
, const GLvoid
*ptr
)
1088 GET_CURRENT_CONTEXT(ctx
);
1090 GLenum format
= GL_RGBA
;
1091 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1092 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
1096 const GLbitfield legalTypes
= DOUBLE_BIT
;
1098 if (!validate_array_and_format(ctx
, "glVertexAttribLPointer",
1099 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1100 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1101 1, 4, size
, type
, stride
,
1102 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
, ptr
))
1105 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1106 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1107 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1112 _mesa_enable_vertex_array_attribs(struct gl_context
*ctx
,
1113 struct gl_vertex_array_object
*vao
,
1114 GLbitfield attrib_bits
)
1116 assert((attrib_bits
& ~VERT_BIT_ALL
) == 0);
1117 assert(!vao
->SharedAndImmutable
);
1119 /* Only work on bits that are disabled */
1120 attrib_bits
&= ~vao
->Enabled
;
1122 /* was disabled, now being enabled */
1123 vao
->Enabled
|= attrib_bits
;
1124 vao
->NewArrays
|= attrib_bits
;
1126 /* Update the map mode if needed */
1127 if (attrib_bits
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1128 update_attribute_map_mode(ctx
, vao
);
1133 enable_vertex_array_attrib(struct gl_context
*ctx
,
1134 struct gl_vertex_array_object
*vao
,
1138 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1139 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
1143 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1148 _mesa_EnableVertexAttribArray(GLuint index
)
1150 GET_CURRENT_CONTEXT(ctx
);
1151 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
1152 "glEnableVertexAttribArray");
1157 _mesa_EnableVertexAttribArray_no_error(GLuint index
)
1159 GET_CURRENT_CONTEXT(ctx
);
1160 _mesa_enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1161 VERT_ATTRIB_GENERIC(index
));
1166 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1168 GET_CURRENT_CONTEXT(ctx
);
1169 struct gl_vertex_array_object
*vao
;
1171 /* The ARB_direct_state_access specification says:
1173 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1174 * and DisableVertexArrayAttrib if <vaobj> is not
1175 * [compatibility profile: zero or] the name of an existing vertex
1178 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
1182 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
1187 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1189 GET_CURRENT_CONTEXT(ctx
);
1190 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1191 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1196 _mesa_disable_vertex_array_attribs(struct gl_context
*ctx
,
1197 struct gl_vertex_array_object
*vao
,
1198 GLbitfield attrib_bits
)
1200 assert((attrib_bits
& ~VERT_BIT_ALL
) == 0);
1201 assert(!vao
->SharedAndImmutable
);
1203 /* Only work on bits that are enabled */
1204 attrib_bits
&= vao
->Enabled
;
1206 /* was enabled, now being disabled */
1207 vao
->Enabled
&= ~attrib_bits
;
1208 vao
->NewArrays
|= attrib_bits
;
1210 /* Update the map mode if needed */
1211 if (attrib_bits
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1212 update_attribute_map_mode(ctx
, vao
);
1218 _mesa_DisableVertexAttribArray(GLuint index
)
1220 GET_CURRENT_CONTEXT(ctx
);
1222 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1223 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexAttribArray(index)");
1227 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1228 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
1233 _mesa_DisableVertexAttribArray_no_error(GLuint index
)
1235 GET_CURRENT_CONTEXT(ctx
);
1236 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1237 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
1242 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1244 GET_CURRENT_CONTEXT(ctx
);
1245 struct gl_vertex_array_object
*vao
;
1247 /* The ARB_direct_state_access specification says:
1249 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1250 * and DisableVertexArrayAttrib if <vaobj> is not
1251 * [compatibility profile: zero or] the name of an existing vertex
1254 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
1258 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1259 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
1263 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1264 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
1269 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1271 GET_CURRENT_CONTEXT(ctx
);
1272 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1273 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1274 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
1279 * Return info for a vertex attribute array (no alias with legacy
1280 * vertex attributes (pos, normal, color, etc)). This function does
1281 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
1284 get_vertex_array_attrib(struct gl_context
*ctx
,
1285 const struct gl_vertex_array_object
*vao
,
1286 GLuint index
, GLenum pname
,
1289 const struct gl_array_attributes
*array
;
1291 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1292 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
1296 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
1298 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
1301 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
1302 return !!(vao
->Enabled
& VERT_BIT_GENERIC(index
));
1303 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
1304 return (array
->Format
.Format
== GL_BGRA
) ? GL_BGRA
: array
->Format
.Size
;
1305 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
1306 return array
->Stride
;
1307 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
1308 return array
->Format
.Type
;
1309 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
1310 return array
->Format
.Normalized
;
1311 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
1312 return vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
->Name
;
1313 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
1314 if ((_mesa_is_desktop_gl(ctx
)
1315 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
1316 || _mesa_is_gles3(ctx
)) {
1317 return array
->Format
.Integer
;
1320 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
1321 if (_mesa_is_desktop_gl(ctx
)) {
1322 return array
->Format
.Doubles
;
1325 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
1326 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
1327 || _mesa_is_gles3(ctx
)) {
1328 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
1331 case GL_VERTEX_ATTRIB_BINDING
:
1332 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1333 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
1336 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
1337 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1338 return array
->RelativeOffset
;
1342 ; /* fall-through */
1346 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
1351 static const GLfloat
*
1352 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
1355 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
1356 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
1360 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1361 _mesa_error(ctx
, GL_INVALID_VALUE
,
1362 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
1366 assert(VERT_ATTRIB_GENERIC(index
) <
1367 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1369 FLUSH_CURRENT(ctx
, 0);
1370 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
1374 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
1376 GET_CURRENT_CONTEXT(ctx
);
1378 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1379 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
1385 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1387 "glGetVertexAttribfv");
1393 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1395 GET_CURRENT_CONTEXT(ctx
);
1397 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1398 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
1400 params
[0] = (GLdouble
) v
[0];
1401 params
[1] = (GLdouble
) v
[1];
1402 params
[2] = (GLdouble
) v
[2];
1403 params
[3] = (GLdouble
) v
[3];
1407 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1409 "glGetVertexAttribdv");
1414 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1416 GET_CURRENT_CONTEXT(ctx
);
1418 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1420 (const GLdouble
*)get_current_attrib(ctx
, index
,
1421 "glGetVertexAttribLdv");
1430 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1432 "glGetVertexAttribLdv");
1437 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1439 GET_CURRENT_CONTEXT(ctx
);
1441 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1442 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1444 /* XXX should floats in[0,1] be scaled to full int range? */
1445 params
[0] = (GLint
) v
[0];
1446 params
[1] = (GLint
) v
[1];
1447 params
[2] = (GLint
) v
[2];
1448 params
[3] = (GLint
) v
[3];
1452 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1454 "glGetVertexAttribiv");
1459 _mesa_GetVertexAttribLui64vARB(GLuint index
, GLenum pname
, GLuint64EXT
*params
)
1461 GET_CURRENT_CONTEXT(ctx
);
1463 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1465 (const GLuint64
*)get_current_attrib(ctx
, index
,
1466 "glGetVertexAttribLui64vARB");
1475 params
[0] = (GLuint64
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1477 "glGetVertexAttribLui64vARB");
1484 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1486 GET_CURRENT_CONTEXT(ctx
);
1488 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1489 const GLint
*v
= (const GLint
*)
1490 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1496 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1498 "glGetVertexAttribIiv");
1505 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1507 GET_CURRENT_CONTEXT(ctx
);
1509 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1510 const GLuint
*v
= (const GLuint
*)
1511 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1517 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1519 "glGetVertexAttribIuiv");
1525 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1527 GET_CURRENT_CONTEXT(ctx
);
1529 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1530 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1534 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1535 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1539 assert(VERT_ATTRIB_GENERIC(index
) <
1540 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1542 *pointer
= (GLvoid
*)
1543 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1547 /** ARB_direct_state_access */
1549 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1550 GLenum pname
, GLint
*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
, "glGetVertexArrayIndexediv");
1565 /* The ARB_direct_state_access specification says:
1567 * "For GetVertexArrayIndexediv, <pname> must be one of
1568 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1569 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1570 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1571 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1572 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1576 * "Add GetVertexArrayIndexediv in 'Get Command' for
1577 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1578 * VERTEX_ATTRIB_BINDING,
1579 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1580 * VERTEX_BINDING_OFFSET, and
1581 * VERTEX_BINDING_STRIDE states"
1583 * The only parameter name common to both lists is
1584 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1585 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1586 * pretty clear however that the intent is that it should be possible
1587 * to query all vertex attrib and binding states that can be set with
1591 case GL_VERTEX_BINDING_OFFSET
:
1592 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1594 case GL_VERTEX_BINDING_STRIDE
:
1595 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1597 case GL_VERTEX_BINDING_DIVISOR
:
1598 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1600 case GL_VERTEX_BINDING_BUFFER
:
1601 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1604 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1605 "glGetVertexArrayIndexediv");
1612 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1613 GLenum pname
, GLint64
*params
)
1615 GET_CURRENT_CONTEXT(ctx
);
1616 struct gl_vertex_array_object
*vao
;
1618 /* The ARB_direct_state_access specification says:
1620 * "An INVALID_OPERATION error is generated if <vaobj> is not
1621 * [compatibility profile: zero or] the name of an existing
1622 * vertex array object."
1624 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1628 /* The ARB_direct_state_access specification says:
1630 * "For GetVertexArrayIndexed64iv, <pname> must be
1631 * VERTEX_BINDING_OFFSET."
1635 * "An INVALID_ENUM error is generated if <pname> is not one of
1636 * the valid values listed above for the corresponding command."
1638 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1639 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1640 "pname != GL_VERTEX_BINDING_OFFSET)");
1644 /* The ARB_direct_state_access specification says:
1646 * "An INVALID_VALUE error is generated if <index> is greater than
1647 * or equal to the value of MAX_VERTEX_ATTRIBS."
1649 * Since the index refers to a buffer binding in this case, the intended
1650 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1651 * required to be the same, so in practice this doesn't matter.
1653 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1654 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1655 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1656 index
, ctx
->Const
.MaxVertexAttribBindings
);
1660 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1665 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1666 GLsizei count
, const GLvoid
*ptr
)
1669 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1674 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1678 _mesa_NormalPointer(type
, stride
, ptr
);
1683 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1687 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1692 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1696 _mesa_IndexPointer(type
, stride
, ptr
);
1701 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1702 GLsizei count
, const GLvoid
*ptr
)
1705 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1710 _mesa_MultiTexCoordPointerEXT(GLenum texunit
, GLint size
, GLenum type
,
1711 GLsizei stride
, const GLvoid
*ptr
)
1713 GET_CURRENT_CONTEXT(ctx
);
1714 const GLint sizeMin
= 1;
1715 const GLuint unit
= texunit
- GL_TEXTURE0
;
1717 GLenum format
= GL_RGBA
;
1718 const GLbitfield legalTypes
= (SHORT_BIT
| INT_BIT
|
1719 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1720 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1721 INT_2_10_10_10_REV_BIT
);
1723 if (!validate_array_and_format(ctx
, "glMultiTexCoordPointerEXT",
1724 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1725 VERT_ATTRIB_TEX(unit
), legalTypes
,
1726 sizeMin
, 4, size
, type
, stride
,
1727 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1730 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1731 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
1732 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1737 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1740 _mesa_EdgeFlagPointer(stride
, ptr
);
1745 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1747 GET_CURRENT_CONTEXT(ctx
);
1748 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1749 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1750 GLenum ctype
= 0; /* color type */
1751 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1752 const GLint toffset
= 0; /* always zero */
1753 GLint defstride
; /* default stride */
1756 f
= sizeof(GLfloat
);
1757 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1760 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1766 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1767 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1772 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1773 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1778 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1779 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1780 ctype
= GL_UNSIGNED_BYTE
;
1783 defstride
= c
+ 2*f
;
1786 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1787 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1788 ctype
= GL_UNSIGNED_BYTE
;
1791 defstride
= c
+ 3*f
;
1794 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1795 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1802 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1803 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1808 case GL_C4F_N3F_V3F
:
1809 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1810 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1818 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1819 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1824 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1825 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1829 case GL_T2F_C4UB_V3F
:
1830 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1831 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1832 ctype
= GL_UNSIGNED_BYTE
;
1837 case GL_T2F_C3F_V3F
:
1838 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1839 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1845 case GL_T2F_N3F_V3F
:
1846 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1847 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1852 case GL_T2F_C4F_N3F_V3F
:
1853 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1854 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1861 case GL_T4F_C4F_N3F_V4F
:
1862 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1863 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1871 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1879 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1880 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1881 /* XXX also disable secondary color and generic arrays? */
1885 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1886 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1887 (GLubyte
*) pointer
+ toffset
);
1890 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1895 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1896 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1897 (GLubyte
*) pointer
+ coffset
);
1900 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1906 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1907 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1910 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1914 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1915 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1916 (GLubyte
*) pointer
+ voffset
);
1921 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1923 GET_CURRENT_CONTEXT(ctx
);
1925 if (MESA_VERBOSE
& VERBOSE_API
)
1926 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1929 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1933 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1936 if (ctx
->Array
.LockCount
!= 0) {
1937 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1941 ctx
->Array
.LockFirst
= first
;
1942 ctx
->Array
.LockCount
= count
;
1947 _mesa_UnlockArraysEXT( void )
1949 GET_CURRENT_CONTEXT(ctx
);
1951 if (MESA_VERBOSE
& VERBOSE_API
)
1952 _mesa_debug(ctx
, "glUnlockArrays\n");
1954 if (ctx
->Array
.LockCount
== 0) {
1955 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1959 ctx
->Array
.LockFirst
= 0;
1960 ctx
->Array
.LockCount
= 0;
1965 primitive_restart_index(struct gl_context
*ctx
, GLuint index
)
1967 ctx
->Array
.RestartIndex
= index
;
1972 * GL_NV_primitive_restart and GL 3.1
1975 _mesa_PrimitiveRestartIndex_no_error(GLuint index
)
1977 GET_CURRENT_CONTEXT(ctx
);
1978 primitive_restart_index(ctx
, index
);
1983 _mesa_PrimitiveRestartIndex(GLuint index
)
1985 GET_CURRENT_CONTEXT(ctx
);
1987 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1988 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1992 primitive_restart_index(ctx
, index
);
1997 _mesa_VertexAttribDivisor_no_error(GLuint index
, GLuint divisor
)
1999 GET_CURRENT_CONTEXT(ctx
);
2001 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2002 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2004 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2006 /* The ARB_vertex_attrib_binding spec says:
2010 * void VertexAttribDivisor(uint index, uint divisor);
2012 * is equivalent to (assuming no errors are generated):
2014 * VertexAttribBinding(index, index);
2015 * VertexBindingDivisor(index, divisor);"
2017 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2018 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2023 * See GL_ARB_instanced_arrays.
2024 * Note that the instance divisor only applies to generic arrays, not
2025 * the legacy vertex arrays.
2028 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
2030 GET_CURRENT_CONTEXT(ctx
);
2032 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2033 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2035 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2036 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
2040 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2041 _mesa_error(ctx
, GL_INVALID_VALUE
,
2042 "glVertexAttribDivisor(index = %u)", index
);
2046 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2048 /* The ARB_vertex_attrib_binding spec says:
2052 * void VertexAttribDivisor(uint index, uint divisor);
2054 * is equivalent to (assuming no errors are generated):
2056 * VertexAttribBinding(index, index);
2057 * VertexBindingDivisor(index, divisor);"
2059 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2060 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2064 static ALWAYS_INLINE
void
2065 vertex_array_vertex_buffer(struct gl_context
*ctx
,
2066 struct gl_vertex_array_object
*vao
,
2067 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2068 GLsizei stride
, bool no_error
, const char *func
)
2070 struct gl_buffer_object
*vbo
;
2072 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
2073 vbo
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
2074 } else if (buffer
!= 0) {
2075 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
2077 if (!no_error
&& !vbo
&& _mesa_is_gles31(ctx
)) {
2078 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
2081 /* From the GL_ARB_vertex_attrib_array spec:
2083 * "[Core profile only:]
2084 * An INVALID_OPERATION error is generated if buffer is not zero or a
2085 * name returned from a previous call to GenBuffers, or if such a name
2086 * has since been deleted with DeleteBuffers.
2088 * Otherwise, we fall back to the same compat profile behavior as other
2089 * object references (automatically gen it).
2091 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
2094 /* The ARB_vertex_attrib_binding spec says:
2096 * "If <buffer> is zero, any buffer object attached to this
2097 * bindpoint is detached."
2099 vbo
= ctx
->Shared
->NullBufferObj
;
2102 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
2103 vbo
, offset
, stride
);
2108 * GL_ARB_vertex_attrib_binding
2111 vertex_array_vertex_buffer_err(struct gl_context
*ctx
,
2112 struct gl_vertex_array_object
*vao
,
2113 GLuint bindingIndex
, GLuint buffer
,
2114 GLintptr offset
, GLsizei stride
,
2117 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2119 /* The ARB_vertex_attrib_binding spec says:
2121 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2122 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2124 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2125 _mesa_error(ctx
, GL_INVALID_VALUE
,
2126 "%s(bindingindex=%u > "
2127 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2128 func
, bindingIndex
);
2132 /* The ARB_vertex_attrib_binding spec says:
2134 * "The error INVALID_VALUE is generated if <stride> or <offset>
2138 _mesa_error(ctx
, GL_INVALID_VALUE
,
2139 "%s(offset=%" PRId64
" < 0)",
2140 func
, (int64_t) offset
);
2145 _mesa_error(ctx
, GL_INVALID_VALUE
,
2146 "%s(stride=%d < 0)", func
, stride
);
2150 if (((_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
2151 stride
> ctx
->Const
.MaxVertexAttribStride
) {
2152 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
2153 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
2157 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2158 stride
, false, func
);
2163 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex
, GLuint buffer
,
2164 GLintptr offset
, GLsizei stride
)
2166 GET_CURRENT_CONTEXT(ctx
);
2167 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2168 buffer
, offset
, stride
, true,
2169 "glBindVertexBuffer");
2174 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2177 GET_CURRENT_CONTEXT(ctx
);
2179 /* The ARB_vertex_attrib_binding spec says:
2181 * "An INVALID_OPERATION error is generated if no vertex array object
2184 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2185 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2186 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2187 "glBindVertexBuffer(No array object bound)");
2191 vertex_array_vertex_buffer_err(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2192 buffer
, offset
, stride
,
2193 "glBindVertexBuffer");
2198 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj
, GLuint bindingIndex
,
2199 GLuint buffer
, GLintptr offset
,
2202 GET_CURRENT_CONTEXT(ctx
);
2204 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2205 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2206 stride
, true, "glVertexArrayVertexBuffer");
2211 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
2212 GLintptr offset
, GLsizei stride
)
2214 GET_CURRENT_CONTEXT(ctx
);
2215 struct gl_vertex_array_object
*vao
;
2217 /* The ARB_direct_state_access specification says:
2219 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2220 * if <vaobj> is not [compatibility profile: zero or] the name of an
2221 * existing vertex array object."
2223 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
2227 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
2228 stride
, "glVertexArrayVertexBuffer");
2232 static ALWAYS_INLINE
void
2233 vertex_array_vertex_buffers(struct gl_context
*ctx
,
2234 struct gl_vertex_array_object
*vao
,
2235 GLuint first
, GLsizei count
, const GLuint
*buffers
,
2236 const GLintptr
*offsets
, const GLsizei
*strides
,
2237 bool no_error
, const char *func
)
2243 * The ARB_multi_bind spec says:
2245 * "If <buffers> is NULL, each affected vertex buffer binding point
2246 * from <first> through <first>+<count>-1 will be reset to have no
2247 * bound buffer object. In this case, the offsets and strides
2248 * associated with the binding points are set to default values,
2249 * ignoring <offsets> and <strides>."
2251 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
2253 for (i
= 0; i
< count
; i
++)
2254 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2260 /* Note that the error semantics for multi-bind commands differ from
2261 * those of other GL commands.
2263 * The Issues section in the ARB_multi_bind spec says:
2265 * "(11) Typically, OpenGL specifies that if an error is generated by
2266 * a command, that command has no effect. This is somewhat
2267 * unfortunate for multi-bind commands, because it would require
2268 * a first pass to scan the entire list of bound objects for
2269 * errors and then a second pass to actually perform the
2270 * bindings. Should we have different error semantics?
2272 * RESOLVED: Yes. In this specification, when the parameters for
2273 * one of the <count> binding points are invalid, that binding
2274 * point is not updated and an error will be generated. However,
2275 * other binding points in the same command will be updated if
2276 * their parameters are valid and no other error occurs."
2279 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
2281 for (i
= 0; i
< count
; i
++) {
2282 struct gl_buffer_object
*vbo
;
2285 /* The ARB_multi_bind spec says:
2287 * "An INVALID_VALUE error is generated if any value in
2288 * <offsets> or <strides> is negative (per binding)."
2290 if (offsets
[i
] < 0) {
2291 _mesa_error(ctx
, GL_INVALID_VALUE
,
2292 "%s(offsets[%u]=%" PRId64
" < 0)",
2293 func
, i
, (int64_t) offsets
[i
]);
2297 if (strides
[i
] < 0) {
2298 _mesa_error(ctx
, GL_INVALID_VALUE
,
2299 "%s(strides[%u]=%d < 0)",
2300 func
, i
, strides
[i
]);
2304 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
2305 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
2306 _mesa_error(ctx
, GL_INVALID_VALUE
,
2307 "%s(strides[%u]=%d > "
2308 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
2314 struct gl_vertex_buffer_binding
*binding
=
2315 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
2317 if (buffers
[i
] == binding
->BufferObj
->Name
)
2318 vbo
= binding
->BufferObj
;
2320 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
2325 vbo
= ctx
->Shared
->NullBufferObj
;
2328 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2329 vbo
, offsets
[i
], strides
[i
]);
2332 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
2337 vertex_array_vertex_buffers_err(struct gl_context
*ctx
,
2338 struct gl_vertex_array_object
*vao
,
2339 GLuint first
, GLsizei count
,
2340 const GLuint
*buffers
, const GLintptr
*offsets
,
2341 const GLsizei
*strides
, const char *func
)
2343 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2345 /* The ARB_multi_bind spec says:
2347 * "An INVALID_OPERATION error is generated if <first> + <count>
2348 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
2350 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
2351 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2352 "%s(first=%u + count=%d > the value of "
2353 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
2354 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
2358 vertex_array_vertex_buffers(ctx
, vao
, first
, count
, buffers
, offsets
,
2359 strides
, false, func
);
2364 _mesa_BindVertexBuffers_no_error(GLuint first
, GLsizei count
,
2365 const GLuint
*buffers
, const GLintptr
*offsets
,
2366 const GLsizei
*strides
)
2368 GET_CURRENT_CONTEXT(ctx
);
2370 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
2371 buffers
, offsets
, strides
, true,
2372 "glBindVertexBuffers");
2377 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
2378 const GLintptr
*offsets
, const GLsizei
*strides
)
2380 GET_CURRENT_CONTEXT(ctx
);
2382 /* The ARB_vertex_attrib_binding spec says:
2384 * "An INVALID_OPERATION error is generated if no
2385 * vertex array object is bound."
2387 if (ctx
->API
== API_OPENGL_CORE
&&
2388 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2389 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2390 "glBindVertexBuffers(No array object bound)");
2394 vertex_array_vertex_buffers_err(ctx
, ctx
->Array
.VAO
, first
, count
,
2395 buffers
, offsets
, strides
,
2396 "glBindVertexBuffers");
2401 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj
, GLuint first
,
2402 GLsizei count
, const GLuint
*buffers
,
2403 const GLintptr
*offsets
,
2404 const GLsizei
*strides
)
2406 GET_CURRENT_CONTEXT(ctx
);
2408 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2409 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
2410 buffers
, offsets
, strides
, true,
2411 "glVertexArrayVertexBuffers");
2416 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
2417 const GLuint
*buffers
,
2418 const GLintptr
*offsets
, const GLsizei
*strides
)
2420 GET_CURRENT_CONTEXT(ctx
);
2421 struct gl_vertex_array_object
*vao
;
2423 /* The ARB_direct_state_access specification says:
2425 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2426 * if <vaobj> is not [compatibility profile: zero or] the name of an
2427 * existing vertex array object."
2429 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
2433 vertex_array_vertex_buffers_err(ctx
, vao
, first
, count
,
2434 buffers
, offsets
, strides
,
2435 "glVertexArrayVertexBuffers");
2440 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
2441 GLboolean normalized
, GLboolean integer
,
2442 GLboolean doubles
, GLbitfield legalTypes
,
2443 GLsizei sizeMax
, GLuint relativeOffset
,
2446 GET_CURRENT_CONTEXT(ctx
);
2447 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2449 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2451 if (!_mesa_is_no_error_enabled(ctx
)) {
2452 /* The ARB_vertex_attrib_binding spec says:
2454 * "An INVALID_OPERATION error is generated under any of the
2455 * following conditions:
2456 * - if no vertex array object is currently bound (see section
2460 * This error condition only applies to VertexAttribFormat and
2461 * VertexAttribIFormat in the extension spec, but we assume that this
2462 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2463 * to all three functions.
2465 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2466 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2467 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2468 "%s(No array object bound)", func
);
2472 /* The ARB_vertex_attrib_binding spec says:
2474 * "The error INVALID_VALUE is generated if index is greater than or
2475 * equal to the value of MAX_VERTEX_ATTRIBS."
2477 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2478 _mesa_error(ctx
, GL_INVALID_VALUE
,
2479 "%s(attribindex=%u > "
2480 "GL_MAX_VERTEX_ATTRIBS)",
2485 if (!validate_array_format(ctx
, func
, ctx
->Array
.VAO
,
2486 VERT_ATTRIB_GENERIC(attribIndex
),
2487 legalTypes
, 1, sizeMax
, size
, type
,
2488 normalized
, integer
, doubles
, relativeOffset
,
2494 _mesa_update_array_format(ctx
, ctx
->Array
.VAO
,
2495 VERT_ATTRIB_GENERIC(attribIndex
), size
, type
,
2496 format
, normalized
, integer
, doubles
,
2502 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2503 GLboolean normalized
, GLuint relativeOffset
)
2505 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
2506 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2507 BGRA_OR_4
, relativeOffset
,
2508 "glVertexAttribFormat");
2513 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2514 GLuint relativeOffset
)
2516 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2517 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2518 relativeOffset
, "glVertexAttribIFormat");
2523 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2524 GLuint relativeOffset
)
2526 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2527 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2528 relativeOffset
, "glVertexAttribLFormat");
2533 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2534 GLenum type
, GLboolean normalized
,
2535 GLboolean integer
, GLboolean doubles
,
2536 GLbitfield legalTypes
, GLsizei sizeMax
,
2537 GLuint relativeOffset
, const char *func
)
2539 GET_CURRENT_CONTEXT(ctx
);
2540 struct gl_vertex_array_object
*vao
;
2542 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2544 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2546 if (_mesa_is_no_error_enabled(ctx
)) {
2547 vao
= _mesa_lookup_vao(ctx
, vaobj
);
2551 /* The ARB_direct_state_access spec says:
2553 * "An INVALID_OPERATION error is generated by
2554 * VertexArrayAttrib*Format if <vaobj> is not [compatibility profile:
2555 * zero or] the name of an existing vertex array object."
2557 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2561 /* The ARB_vertex_attrib_binding spec says:
2563 * "The error INVALID_VALUE is generated if index is greater than or
2564 * equal to the value of MAX_VERTEX_ATTRIBS."
2566 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2567 _mesa_error(ctx
, GL_INVALID_VALUE
,
2568 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2573 if (!validate_array_format(ctx
, func
, vao
,
2574 VERT_ATTRIB_GENERIC(attribIndex
),
2575 legalTypes
, 1, sizeMax
, size
, type
,
2576 normalized
, integer
, doubles
, relativeOffset
,
2582 _mesa_update_array_format(ctx
, vao
, VERT_ATTRIB_GENERIC(attribIndex
), size
,
2583 type
, format
, normalized
, integer
, doubles
,
2589 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2590 GLenum type
, GLboolean normalized
,
2591 GLuint relativeOffset
)
2593 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2594 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2595 BGRA_OR_4
, relativeOffset
,
2596 "glVertexArrayAttribFormat");
2601 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2602 GLint size
, GLenum type
,
2603 GLuint relativeOffset
)
2605 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2606 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2608 "glVertexArrayAttribIFormat");
2613 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2614 GLint size
, GLenum type
,
2615 GLuint relativeOffset
)
2617 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2618 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2620 "glVertexArrayAttribLFormat");
2625 vertex_array_attrib_binding(struct gl_context
*ctx
,
2626 struct gl_vertex_array_object
*vao
,
2627 GLuint attribIndex
, GLuint bindingIndex
,
2630 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2632 /* The ARB_vertex_attrib_binding spec says:
2634 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2635 * <bindingindex> must be less than the value of
2636 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2639 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2640 _mesa_error(ctx
, GL_INVALID_VALUE
,
2641 "%s(attribindex=%u >= "
2642 "GL_MAX_VERTEX_ATTRIBS)",
2647 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2648 _mesa_error(ctx
, GL_INVALID_VALUE
,
2649 "%s(bindingindex=%u >= "
2650 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2651 func
, bindingIndex
);
2655 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2657 _mesa_vertex_attrib_binding(ctx
, vao
,
2658 VERT_ATTRIB_GENERIC(attribIndex
),
2659 VERT_ATTRIB_GENERIC(bindingIndex
));
2664 _mesa_VertexAttribBinding_no_error(GLuint attribIndex
, GLuint bindingIndex
)
2666 GET_CURRENT_CONTEXT(ctx
);
2667 _mesa_vertex_attrib_binding(ctx
, ctx
->Array
.VAO
,
2668 VERT_ATTRIB_GENERIC(attribIndex
),
2669 VERT_ATTRIB_GENERIC(bindingIndex
));
2674 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2676 GET_CURRENT_CONTEXT(ctx
);
2678 /* The ARB_vertex_attrib_binding spec says:
2680 * "An INVALID_OPERATION error is generated if no vertex array object
2683 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2684 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2685 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2686 "glVertexAttribBinding(No array object bound)");
2690 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2691 attribIndex
, bindingIndex
,
2692 "glVertexAttribBinding");
2697 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj
, GLuint attribIndex
,
2698 GLuint bindingIndex
)
2700 GET_CURRENT_CONTEXT(ctx
);
2702 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2703 _mesa_vertex_attrib_binding(ctx
, vao
,
2704 VERT_ATTRIB_GENERIC(attribIndex
),
2705 VERT_ATTRIB_GENERIC(bindingIndex
));
2710 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2712 GET_CURRENT_CONTEXT(ctx
);
2713 struct gl_vertex_array_object
*vao
;
2715 /* The ARB_direct_state_access specification says:
2717 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2718 * if <vaobj> is not [compatibility profile: zero or] the name of an
2719 * existing vertex array object."
2721 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2725 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2726 "glVertexArrayAttribBinding");
2731 vertex_array_binding_divisor(struct gl_context
*ctx
,
2732 struct gl_vertex_array_object
*vao
,
2733 GLuint bindingIndex
, GLuint divisor
,
2736 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2738 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2739 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2743 /* The ARB_vertex_attrib_binding spec says:
2745 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2746 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2748 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2749 _mesa_error(ctx
, GL_INVALID_VALUE
,
2750 "%s(bindingindex=%u > "
2751 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2752 func
, bindingIndex
);
2756 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2761 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex
, GLuint divisor
)
2763 GET_CURRENT_CONTEXT(ctx
);
2764 vertex_binding_divisor(ctx
, ctx
->Array
.VAO
,
2765 VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2770 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2772 GET_CURRENT_CONTEXT(ctx
);
2774 /* The ARB_vertex_attrib_binding spec says:
2776 * "An INVALID_OPERATION error is generated if no vertex array object
2779 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2780 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2781 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2782 "glVertexBindingDivisor(No array object bound)");
2786 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2787 bindingIndex
, divisor
,
2788 "glVertexBindingDivisor");
2793 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj
, GLuint bindingIndex
,
2796 GET_CURRENT_CONTEXT(ctx
);
2798 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2799 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2804 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2807 struct gl_vertex_array_object
*vao
;
2808 GET_CURRENT_CONTEXT(ctx
);
2810 /* The ARB_direct_state_access specification says:
2812 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2813 * if <vaobj> is not [compatibility profile: zero or] the name of an
2814 * existing vertex array object."
2816 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2820 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2821 "glVertexArrayBindingDivisor");
2826 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2827 struct gl_array_attributes
*dst
,
2828 const struct gl_array_attributes
*src
)
2830 dst
->Ptr
= src
->Ptr
;
2831 dst
->RelativeOffset
= src
->RelativeOffset
;
2832 dst
->Format
= src
->Format
;
2833 dst
->Stride
= src
->Stride
;
2834 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
2835 dst
->_EffBufferBindingIndex
= src
->_EffBufferBindingIndex
;
2836 dst
->_EffRelativeOffset
= src
->_EffRelativeOffset
;
2840 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2841 struct gl_vertex_buffer_binding
*dst
,
2842 const struct gl_vertex_buffer_binding
*src
)
2844 dst
->Offset
= src
->Offset
;
2845 dst
->Stride
= src
->Stride
;
2846 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2847 dst
->_BoundArrays
= src
->_BoundArrays
;
2848 dst
->_EffBoundArrays
= src
->_EffBoundArrays
;
2849 dst
->_EffOffset
= src
->_EffOffset
;
2851 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2855 * Print current vertex object/array info. For debug.
2858 _mesa_print_arrays(struct gl_context
*ctx
)
2860 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2862 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
2864 GLbitfield mask
= vao
->Enabled
;
2866 const gl_vert_attrib i
= u_bit_scan(&mask
);
2867 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
2869 const struct gl_vertex_buffer_binding
*binding
=
2870 &vao
->BufferBinding
[array
->BufferBindingIndex
];
2871 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
2873 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2874 "Stride=%d, Buffer=%u(Size %lu)\n",
2875 gl_vert_attrib_name((gl_vert_attrib
)i
),
2876 array
->Ptr
, _mesa_enum_to_string(array
->Format
.Type
),
2878 array
->Format
._ElementSize
, binding
->Stride
, bo
->Name
,
2879 (unsigned long) bo
->Size
);
2885 * Initialize vertex array state for given context.
2888 _mesa_init_varray(struct gl_context
*ctx
)
2890 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2891 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2892 ctx
->Array
._EmptyVAO
= _mesa_new_vao(ctx
, ~0u);
2893 _mesa_reference_vao(ctx
, &ctx
->Array
._DrawVAO
, ctx
->Array
._EmptyVAO
);
2894 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2896 ctx
->Array
.Objects
= _mesa_NewHashTable();
2901 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2904 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2906 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2907 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2908 _mesa_delete_vao(ctx
, vao
);
2913 * Free vertex array state for given context.
2916 _mesa_free_varray_data(struct gl_context
*ctx
)
2918 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2919 _mesa_DeleteHashTable(ctx
->Array
.Objects
);