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_VertexArrayVertexOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
668 GLenum type
, GLsizei stride
, GLintptr offset
)
675 _mesa_NormalPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
677 GET_CURRENT_CONTEXT(ctx
);
679 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
680 VERT_ATTRIB_NORMAL
, GL_RGBA
, 3, 3, type
, stride
, GL_TRUE
,
681 GL_FALSE
, GL_FALSE
, ptr
);
686 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
688 GET_CURRENT_CONTEXT(ctx
);
690 GLenum format
= GL_RGBA
;
691 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
692 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
693 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
694 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
695 UNSIGNED_INT_2_10_10_10_REV_BIT
|
696 INT_2_10_10_10_REV_BIT
);
698 if (!validate_array_and_format(ctx
, "glNormalPointer",
699 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
700 VERT_ATTRIB_NORMAL
, legalTypes
, 3, 3, 3,
701 type
, stride
, GL_TRUE
, GL_FALSE
,
702 GL_FALSE
, format
, ptr
))
705 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
706 VERT_ATTRIB_NORMAL
, format
, 3, 3, type
, stride
, GL_TRUE
,
707 GL_FALSE
, GL_FALSE
, ptr
);
712 _mesa_VertexArrayNormalOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
713 GLsizei stride
, GLintptr offset
)
720 _mesa_ColorPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
723 GET_CURRENT_CONTEXT(ctx
);
725 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
726 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
727 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
728 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
733 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
735 GET_CURRENT_CONTEXT(ctx
);
736 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
738 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
739 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
740 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
741 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
742 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
743 INT_BIT
| UNSIGNED_INT_BIT
|
744 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
745 UNSIGNED_INT_2_10_10_10_REV_BIT
|
746 INT_2_10_10_10_REV_BIT
);
748 if (!validate_array_and_format(ctx
, "glColorPointer",
749 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
750 VERT_ATTRIB_COLOR0
, legalTypes
, sizeMin
,
751 BGRA_OR_4
, size
, type
, stride
, GL_TRUE
,
752 GL_FALSE
, GL_FALSE
, format
, ptr
))
755 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
756 VERT_ATTRIB_COLOR0
, format
, BGRA_OR_4
, size
,
757 type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
762 _mesa_VertexArrayColorOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
763 GLenum type
, GLsizei stride
, GLintptr offset
)
770 _mesa_FogCoordPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
772 GET_CURRENT_CONTEXT(ctx
);
774 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
775 VERT_ATTRIB_FOG
, GL_RGBA
, 1, 1, type
, stride
, GL_FALSE
,
776 GL_FALSE
, GL_FALSE
, ptr
);
781 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
783 GET_CURRENT_CONTEXT(ctx
);
785 GLenum format
= GL_RGBA
;
786 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
788 if (!validate_array_and_format(ctx
, "glFogCoordPointer",
789 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
790 VERT_ATTRIB_FOG
, legalTypes
, 1, 1, 1,
791 type
, stride
, GL_FALSE
, GL_FALSE
,
792 GL_FALSE
, format
, ptr
))
795 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
796 VERT_ATTRIB_FOG
, format
, 1, 1, type
, stride
, GL_FALSE
,
797 GL_FALSE
, GL_FALSE
, ptr
);
802 _mesa_VertexArrayFogCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
803 GLsizei stride
, GLintptr offset
)
810 _mesa_IndexPointer_no_error(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
812 GET_CURRENT_CONTEXT(ctx
);
814 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
815 VERT_ATTRIB_COLOR_INDEX
, GL_RGBA
, 1, 1, type
, stride
,
816 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
821 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
823 GET_CURRENT_CONTEXT(ctx
);
825 GLenum format
= GL_RGBA
;
826 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
827 FLOAT_BIT
| DOUBLE_BIT
);
829 if (!validate_array_and_format(ctx
, "glIndexPointer",
830 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
831 VERT_ATTRIB_COLOR_INDEX
,
832 legalTypes
, 1, 1, 1, type
, stride
,
833 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
836 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
837 VERT_ATTRIB_COLOR_INDEX
, format
, 1, 1, type
, stride
,
838 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
843 _mesa_VertexArrayIndexOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum type
,
844 GLsizei stride
, GLintptr offset
)
851 _mesa_SecondaryColorPointer_no_error(GLint size
, GLenum type
,
852 GLsizei stride
, const GLvoid
*ptr
)
854 GET_CURRENT_CONTEXT(ctx
);
856 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
857 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
858 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
859 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
864 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
865 GLsizei stride
, const GLvoid
*ptr
)
867 GET_CURRENT_CONTEXT(ctx
);
869 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
870 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
871 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
872 INT_BIT
| UNSIGNED_INT_BIT
|
873 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
874 UNSIGNED_INT_2_10_10_10_REV_BIT
|
875 INT_2_10_10_10_REV_BIT
);
877 if (!validate_array_and_format(ctx
, "glSecondaryColorPointer",
878 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
879 VERT_ATTRIB_COLOR1
, legalTypes
, 3,
880 BGRA_OR_4
, size
, type
, stride
,
881 GL_TRUE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
884 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
885 VERT_ATTRIB_COLOR1
, format
, BGRA_OR_4
, size
, type
,
886 stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
891 _mesa_VertexArraySecondaryColorOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
892 GLenum type
, GLsizei stride
, GLintptr offset
)
899 _mesa_TexCoordPointer_no_error(GLint size
, GLenum type
, GLsizei stride
,
902 GET_CURRENT_CONTEXT(ctx
);
903 const GLuint unit
= ctx
->Array
.ActiveTexture
;
905 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
906 VERT_ATTRIB_TEX(unit
), GL_RGBA
, 4, size
, type
,
907 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
912 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
915 GET_CURRENT_CONTEXT(ctx
);
916 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
917 const GLuint unit
= ctx
->Array
.ActiveTexture
;
919 GLenum format
= GL_RGBA
;
920 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
921 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
922 : (SHORT_BIT
| INT_BIT
|
923 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
924 UNSIGNED_INT_2_10_10_10_REV_BIT
|
925 INT_2_10_10_10_REV_BIT
);
927 if (!validate_array_and_format(ctx
, "glTexCoordPointer",
928 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
929 VERT_ATTRIB_TEX(unit
), legalTypes
,
930 sizeMin
, 4, size
, type
, stride
,
931 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
934 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
935 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
936 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
941 _mesa_VertexArrayTexCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLint size
,
942 GLenum type
, GLsizei stride
, GLintptr offset
)
949 _mesa_VertexArrayMultiTexCoordOffsetEXT(GLuint vaobj
, GLuint buffer
, GLenum texunit
,
950 GLint size
, GLenum type
, GLsizei stride
,
958 _mesa_EdgeFlagPointer_no_error(GLsizei stride
, const GLvoid
*ptr
)
960 /* this is the same type that glEdgeFlag uses */
961 const GLboolean integer
= GL_FALSE
;
962 GET_CURRENT_CONTEXT(ctx
);
964 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
965 VERT_ATTRIB_EDGEFLAG
, GL_RGBA
, 1, 1, GL_UNSIGNED_BYTE
,
966 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
971 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
973 /* this is the same type that glEdgeFlag uses */
974 const GLboolean integer
= GL_FALSE
;
975 GET_CURRENT_CONTEXT(ctx
);
977 GLenum format
= GL_RGBA
;
978 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
980 if (!validate_array_and_format(ctx
, "glEdgeFlagPointer",
981 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
982 VERT_ATTRIB_EDGEFLAG
, legalTypes
,
983 1, 1, 1, GL_UNSIGNED_BYTE
, stride
,
984 GL_FALSE
, integer
, GL_FALSE
, format
, ptr
))
987 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
988 VERT_ATTRIB_EDGEFLAG
, format
, 1, 1, GL_UNSIGNED_BYTE
,
989 stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
994 _mesa_VertexArrayEdgeFlagOffsetEXT(GLuint vaobj
, GLuint buffer
, GLsizei stride
,
1002 _mesa_PointSizePointerOES_no_error(GLenum type
, GLsizei stride
,
1005 GET_CURRENT_CONTEXT(ctx
);
1007 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1008 VERT_ATTRIB_POINT_SIZE
, GL_RGBA
, 1, 1, type
, stride
,
1009 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1014 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
1016 GET_CURRENT_CONTEXT(ctx
);
1018 GLenum format
= GL_RGBA
;
1019 if (ctx
->API
!= API_OPENGLES
) {
1020 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1021 "glPointSizePointer(ES 1.x only)");
1025 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
1027 if (!validate_array_and_format(ctx
, "glPointSizePointer",
1028 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1029 VERT_ATTRIB_POINT_SIZE
, legalTypes
,
1030 1, 1, 1, type
, stride
, GL_FALSE
, GL_FALSE
,
1031 GL_FALSE
, format
, ptr
))
1034 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1035 VERT_ATTRIB_POINT_SIZE
, format
, 1, 1, type
, stride
,
1036 GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1041 _mesa_VertexAttribPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1042 GLboolean normalized
,
1043 GLsizei stride
, const GLvoid
*ptr
)
1045 GET_CURRENT_CONTEXT(ctx
);
1047 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1048 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1049 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1050 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
1055 * Set a generic vertex attribute array.
1056 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1057 * (position, normal, color, fog, texcoord, etc).
1060 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
1061 GLboolean normalized
,
1062 GLsizei stride
, const GLvoid
*ptr
)
1064 GET_CURRENT_CONTEXT(ctx
);
1066 GLenum format
= get_array_format(ctx
, BGRA_OR_4
, &size
);
1067 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1068 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(idx)");
1072 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1073 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1074 INT_BIT
| UNSIGNED_INT_BIT
|
1075 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1076 FIXED_ES_BIT
| FIXED_GL_BIT
|
1077 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1078 INT_2_10_10_10_REV_BIT
|
1079 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
1081 if (!validate_array_and_format(ctx
, "glVertexAttribPointer",
1082 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1083 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1084 1, BGRA_OR_4
, size
, type
, stride
,
1085 normalized
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1088 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1089 VERT_ATTRIB_GENERIC(index
), format
, BGRA_OR_4
,
1090 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
1095 _mesa_VertexArrayVertexAttribOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1096 GLenum type
, GLboolean normalized
,
1097 GLsizei stride
, GLintptr offset
)
1104 _mesa_VertexAttribIPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1105 GLsizei stride
, const GLvoid
*ptr
)
1107 const GLboolean normalized
= GL_FALSE
;
1108 const GLboolean integer
= GL_TRUE
;
1109 GET_CURRENT_CONTEXT(ctx
);
1111 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1112 VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1113 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1118 * GL_EXT_gpu_shader4 / GL 3.0.
1119 * Set an integer-valued vertex attribute array.
1120 * Note that these arrays DO NOT alias the conventional GL vertex arrays
1121 * (position, normal, color, fog, texcoord, etc).
1124 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
1125 GLsizei stride
, const GLvoid
*ptr
)
1127 const GLboolean normalized
= GL_FALSE
;
1128 const GLboolean integer
= GL_TRUE
;
1129 GET_CURRENT_CONTEXT(ctx
);
1131 GLenum format
= GL_RGBA
;
1132 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1133 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
1137 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
1138 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
1139 INT_BIT
| UNSIGNED_INT_BIT
);
1141 if (!validate_array_and_format(ctx
, "glVertexAttribIPointer",
1142 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1143 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1144 1, 4, size
, type
, stride
,
1145 normalized
, integer
, GL_FALSE
, format
, ptr
))
1148 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1149 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1150 stride
, normalized
, integer
, GL_FALSE
, ptr
);
1155 _mesa_VertexAttribLPointer_no_error(GLuint index
, GLint size
, GLenum type
,
1156 GLsizei stride
, const GLvoid
*ptr
)
1158 GET_CURRENT_CONTEXT(ctx
);
1160 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1161 VERT_ATTRIB_GENERIC(index
), GL_RGBA
, 4, size
, type
,
1162 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1167 _mesa_VertexArrayVertexAttribIOffsetEXT(GLuint vaobj
, GLuint buffer
, GLuint index
, GLint size
,
1168 GLenum type
, GLsizei stride
, GLintptr offset
)
1175 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
1176 GLsizei stride
, const GLvoid
*ptr
)
1178 GET_CURRENT_CONTEXT(ctx
);
1180 GLenum format
= GL_RGBA
;
1181 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1182 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
1186 const GLbitfield legalTypes
= DOUBLE_BIT
;
1188 if (!validate_array_and_format(ctx
, "glVertexAttribLPointer",
1189 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1190 VERT_ATTRIB_GENERIC(index
), legalTypes
,
1191 1, 4, size
, type
, stride
,
1192 GL_FALSE
, GL_FALSE
, GL_TRUE
, format
, ptr
))
1195 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1196 VERT_ATTRIB_GENERIC(index
), format
, 4, size
, type
,
1197 stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
1202 _mesa_enable_vertex_array_attribs(struct gl_context
*ctx
,
1203 struct gl_vertex_array_object
*vao
,
1204 GLbitfield attrib_bits
)
1206 assert((attrib_bits
& ~VERT_BIT_ALL
) == 0);
1207 assert(!vao
->SharedAndImmutable
);
1209 /* Only work on bits that are disabled */
1210 attrib_bits
&= ~vao
->Enabled
;
1212 /* was disabled, now being enabled */
1213 vao
->Enabled
|= attrib_bits
;
1214 vao
->NewArrays
|= attrib_bits
;
1216 /* Update the map mode if needed */
1217 if (attrib_bits
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1218 update_attribute_map_mode(ctx
, vao
);
1223 enable_vertex_array_attrib(struct gl_context
*ctx
,
1224 struct gl_vertex_array_object
*vao
,
1228 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1229 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
1233 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1238 _mesa_EnableVertexAttribArray(GLuint index
)
1240 GET_CURRENT_CONTEXT(ctx
);
1241 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
1242 "glEnableVertexAttribArray");
1247 _mesa_EnableVertexAttribArray_no_error(GLuint index
)
1249 GET_CURRENT_CONTEXT(ctx
);
1250 _mesa_enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1251 VERT_ATTRIB_GENERIC(index
));
1256 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1258 GET_CURRENT_CONTEXT(ctx
);
1259 struct gl_vertex_array_object
*vao
;
1261 /* The ARB_direct_state_access specification says:
1263 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1264 * and DisableVertexArrayAttrib if <vaobj> is not
1265 * [compatibility profile: zero or] the name of an existing vertex
1268 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
1272 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
1277 _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1279 GET_CURRENT_CONTEXT(ctx
);
1280 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1281 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
1286 _mesa_disable_vertex_array_attribs(struct gl_context
*ctx
,
1287 struct gl_vertex_array_object
*vao
,
1288 GLbitfield attrib_bits
)
1290 assert((attrib_bits
& ~VERT_BIT_ALL
) == 0);
1291 assert(!vao
->SharedAndImmutable
);
1293 /* Only work on bits that are enabled */
1294 attrib_bits
&= vao
->Enabled
;
1296 /* was enabled, now being disabled */
1297 vao
->Enabled
&= ~attrib_bits
;
1298 vao
->NewArrays
|= attrib_bits
;
1300 /* Update the map mode if needed */
1301 if (attrib_bits
& (VERT_BIT_POS
|VERT_BIT_GENERIC0
))
1302 update_attribute_map_mode(ctx
, vao
);
1308 _mesa_DisableVertexAttribArray(GLuint index
)
1310 GET_CURRENT_CONTEXT(ctx
);
1312 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1313 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexAttribArray(index)");
1317 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1318 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
1323 _mesa_DisableVertexAttribArray_no_error(GLuint index
)
1325 GET_CURRENT_CONTEXT(ctx
);
1326 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1327 _mesa_disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, attrib
);
1332 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
1334 GET_CURRENT_CONTEXT(ctx
);
1335 struct gl_vertex_array_object
*vao
;
1337 /* The ARB_direct_state_access specification says:
1339 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
1340 * and DisableVertexArrayAttrib if <vaobj> is not
1341 * [compatibility profile: zero or] the name of an existing vertex
1344 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
1348 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1349 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDisableVertexArrayAttrib(index)");
1353 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1354 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
1359 _mesa_DisableVertexArrayAttrib_no_error(GLuint vaobj
, GLuint index
)
1361 GET_CURRENT_CONTEXT(ctx
);
1362 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
1363 const gl_vert_attrib attrib
= VERT_ATTRIB_GENERIC(index
);
1364 _mesa_disable_vertex_array_attrib(ctx
, vao
, attrib
);
1369 * Return info for a vertex attribute array (no alias with legacy
1370 * vertex attributes (pos, normal, color, etc)). This function does
1371 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
1374 get_vertex_array_attrib(struct gl_context
*ctx
,
1375 const struct gl_vertex_array_object
*vao
,
1376 GLuint index
, GLenum pname
,
1379 const struct gl_array_attributes
*array
;
1381 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1382 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
1386 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
1388 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
1391 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
1392 return !!(vao
->Enabled
& VERT_BIT_GENERIC(index
));
1393 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
1394 return (array
->Format
.Format
== GL_BGRA
) ? GL_BGRA
: array
->Format
.Size
;
1395 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
1396 return array
->Stride
;
1397 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
1398 return array
->Format
.Type
;
1399 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
1400 return array
->Format
.Normalized
;
1401 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
1402 return vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
->Name
;
1403 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
1404 if ((_mesa_is_desktop_gl(ctx
)
1405 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
1406 || _mesa_is_gles3(ctx
)) {
1407 return array
->Format
.Integer
;
1410 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
1411 if (_mesa_is_desktop_gl(ctx
)) {
1412 return array
->Format
.Doubles
;
1415 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
1416 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
1417 || _mesa_is_gles3(ctx
)) {
1418 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
1421 case GL_VERTEX_ATTRIB_BINDING
:
1422 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1423 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
1426 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
1427 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
1428 return array
->RelativeOffset
;
1432 ; /* fall-through */
1436 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
1441 static const GLfloat
*
1442 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
1445 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
1446 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
1450 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1451 _mesa_error(ctx
, GL_INVALID_VALUE
,
1452 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
1456 assert(VERT_ATTRIB_GENERIC(index
) <
1457 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1459 FLUSH_CURRENT(ctx
, 0);
1460 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
1464 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
1466 GET_CURRENT_CONTEXT(ctx
);
1468 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1469 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
1475 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1477 "glGetVertexAttribfv");
1483 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1485 GET_CURRENT_CONTEXT(ctx
);
1487 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1488 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
1490 params
[0] = (GLdouble
) v
[0];
1491 params
[1] = (GLdouble
) v
[1];
1492 params
[2] = (GLdouble
) v
[2];
1493 params
[3] = (GLdouble
) v
[3];
1497 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1499 "glGetVertexAttribdv");
1504 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1506 GET_CURRENT_CONTEXT(ctx
);
1508 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1510 (const GLdouble
*)get_current_attrib(ctx
, index
,
1511 "glGetVertexAttribLdv");
1520 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1522 "glGetVertexAttribLdv");
1527 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1529 GET_CURRENT_CONTEXT(ctx
);
1531 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1532 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1534 /* XXX should floats in[0,1] be scaled to full int range? */
1535 params
[0] = (GLint
) v
[0];
1536 params
[1] = (GLint
) v
[1];
1537 params
[2] = (GLint
) v
[2];
1538 params
[3] = (GLint
) v
[3];
1542 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1544 "glGetVertexAttribiv");
1549 _mesa_GetVertexAttribLui64vARB(GLuint index
, GLenum pname
, GLuint64EXT
*params
)
1551 GET_CURRENT_CONTEXT(ctx
);
1553 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1555 (const GLuint64
*)get_current_attrib(ctx
, index
,
1556 "glGetVertexAttribLui64vARB");
1565 params
[0] = (GLuint64
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1567 "glGetVertexAttribLui64vARB");
1574 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1576 GET_CURRENT_CONTEXT(ctx
);
1578 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1579 const GLint
*v
= (const GLint
*)
1580 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1586 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1588 "glGetVertexAttribIiv");
1595 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1597 GET_CURRENT_CONTEXT(ctx
);
1599 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1600 const GLuint
*v
= (const GLuint
*)
1601 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1607 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1609 "glGetVertexAttribIuiv");
1615 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1617 GET_CURRENT_CONTEXT(ctx
);
1619 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1620 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1624 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1625 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1629 assert(VERT_ATTRIB_GENERIC(index
) <
1630 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1632 *pointer
= (GLvoid
*)
1633 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1637 /** ARB_direct_state_access */
1639 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1640 GLenum pname
, GLint
*params
)
1642 GET_CURRENT_CONTEXT(ctx
);
1643 struct gl_vertex_array_object
*vao
;
1645 /* The ARB_direct_state_access specification says:
1647 * "An INVALID_OPERATION error is generated if <vaobj> is not
1648 * [compatibility profile: zero or] the name of an existing
1649 * vertex array object."
1651 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexediv");
1655 /* The ARB_direct_state_access specification says:
1657 * "For GetVertexArrayIndexediv, <pname> must be one of
1658 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1659 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1660 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1661 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1662 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1666 * "Add GetVertexArrayIndexediv in 'Get Command' for
1667 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1668 * VERTEX_ATTRIB_BINDING,
1669 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1670 * VERTEX_BINDING_OFFSET, and
1671 * VERTEX_BINDING_STRIDE states"
1673 * The only parameter name common to both lists is
1674 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1675 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1676 * pretty clear however that the intent is that it should be possible
1677 * to query all vertex attrib and binding states that can be set with
1681 case GL_VERTEX_BINDING_OFFSET
:
1682 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1684 case GL_VERTEX_BINDING_STRIDE
:
1685 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1687 case GL_VERTEX_BINDING_DIVISOR
:
1688 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1690 case GL_VERTEX_BINDING_BUFFER
:
1691 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1694 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1695 "glGetVertexArrayIndexediv");
1702 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1703 GLenum pname
, GLint64
*params
)
1705 GET_CURRENT_CONTEXT(ctx
);
1706 struct gl_vertex_array_object
*vao
;
1708 /* The ARB_direct_state_access specification says:
1710 * "An INVALID_OPERATION error is generated if <vaobj> is not
1711 * [compatibility profile: zero or] the name of an existing
1712 * vertex array object."
1714 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1718 /* The ARB_direct_state_access specification says:
1720 * "For GetVertexArrayIndexed64iv, <pname> must be
1721 * VERTEX_BINDING_OFFSET."
1725 * "An INVALID_ENUM error is generated if <pname> is not one of
1726 * the valid values listed above for the corresponding command."
1728 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1729 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1730 "pname != GL_VERTEX_BINDING_OFFSET)");
1734 /* The ARB_direct_state_access specification says:
1736 * "An INVALID_VALUE error is generated if <index> is greater than
1737 * or equal to the value of MAX_VERTEX_ATTRIBS."
1739 * Since the index refers to a buffer binding in this case, the intended
1740 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1741 * required to be the same, so in practice this doesn't matter.
1743 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1744 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1745 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1746 index
, ctx
->Const
.MaxVertexAttribBindings
);
1750 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1755 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1756 GLsizei count
, const GLvoid
*ptr
)
1759 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1764 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1768 _mesa_NormalPointer(type
, stride
, ptr
);
1773 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1777 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1782 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1786 _mesa_IndexPointer(type
, stride
, ptr
);
1791 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1792 GLsizei count
, const GLvoid
*ptr
)
1795 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1800 _mesa_MultiTexCoordPointerEXT(GLenum texunit
, GLint size
, GLenum type
,
1801 GLsizei stride
, const GLvoid
*ptr
)
1803 GET_CURRENT_CONTEXT(ctx
);
1804 const GLint sizeMin
= 1;
1805 const GLuint unit
= texunit
- GL_TEXTURE0
;
1807 GLenum format
= GL_RGBA
;
1808 const GLbitfield legalTypes
= (SHORT_BIT
| INT_BIT
|
1809 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
1810 UNSIGNED_INT_2_10_10_10_REV_BIT
|
1811 INT_2_10_10_10_REV_BIT
);
1813 if (!validate_array_and_format(ctx
, "glMultiTexCoordPointerEXT",
1814 ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1815 VERT_ATTRIB_TEX(unit
), legalTypes
,
1816 sizeMin
, 4, size
, type
, stride
,
1817 GL_FALSE
, GL_FALSE
, GL_FALSE
, format
, ptr
))
1820 update_array(ctx
, ctx
->Array
.VAO
, ctx
->Array
.ArrayBufferObj
,
1821 VERT_ATTRIB_TEX(unit
), format
, 4, size
, type
,
1822 stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
1827 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1830 _mesa_EdgeFlagPointer(stride
, ptr
);
1835 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1837 GET_CURRENT_CONTEXT(ctx
);
1838 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1839 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1840 GLenum ctype
= 0; /* color type */
1841 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1842 const GLint toffset
= 0; /* always zero */
1843 GLint defstride
; /* default stride */
1846 f
= sizeof(GLfloat
);
1847 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1850 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1856 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1857 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1862 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1863 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1868 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1869 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1870 ctype
= GL_UNSIGNED_BYTE
;
1873 defstride
= c
+ 2*f
;
1876 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1877 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1878 ctype
= GL_UNSIGNED_BYTE
;
1881 defstride
= c
+ 3*f
;
1884 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1885 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1892 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1893 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1898 case GL_C4F_N3F_V3F
:
1899 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1900 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1908 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1909 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1914 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1915 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1919 case GL_T2F_C4UB_V3F
:
1920 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1921 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1922 ctype
= GL_UNSIGNED_BYTE
;
1927 case GL_T2F_C3F_V3F
:
1928 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1929 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1935 case GL_T2F_N3F_V3F
:
1936 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1937 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1942 case GL_T2F_C4F_N3F_V3F
:
1943 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1944 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1951 case GL_T4F_C4F_N3F_V4F
:
1952 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1953 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1961 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1969 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1970 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1971 /* XXX also disable secondary color and generic arrays? */
1975 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1976 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1977 (GLubyte
*) pointer
+ toffset
);
1980 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1985 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1986 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1987 (GLubyte
*) pointer
+ coffset
);
1990 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1996 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1997 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
2000 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
2004 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
2005 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
2006 (GLubyte
*) pointer
+ voffset
);
2011 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
2013 GET_CURRENT_CONTEXT(ctx
);
2015 if (MESA_VERBOSE
& VERBOSE_API
)
2016 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
2019 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
2023 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
2026 if (ctx
->Array
.LockCount
!= 0) {
2027 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
2031 ctx
->Array
.LockFirst
= first
;
2032 ctx
->Array
.LockCount
= count
;
2037 _mesa_UnlockArraysEXT( void )
2039 GET_CURRENT_CONTEXT(ctx
);
2041 if (MESA_VERBOSE
& VERBOSE_API
)
2042 _mesa_debug(ctx
, "glUnlockArrays\n");
2044 if (ctx
->Array
.LockCount
== 0) {
2045 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
2049 ctx
->Array
.LockFirst
= 0;
2050 ctx
->Array
.LockCount
= 0;
2055 primitive_restart_index(struct gl_context
*ctx
, GLuint index
)
2057 ctx
->Array
.RestartIndex
= index
;
2062 * GL_NV_primitive_restart and GL 3.1
2065 _mesa_PrimitiveRestartIndex_no_error(GLuint index
)
2067 GET_CURRENT_CONTEXT(ctx
);
2068 primitive_restart_index(ctx
, index
);
2073 _mesa_PrimitiveRestartIndex(GLuint index
)
2075 GET_CURRENT_CONTEXT(ctx
);
2077 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
2078 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
2082 primitive_restart_index(ctx
, index
);
2087 _mesa_VertexAttribDivisor_no_error(GLuint index
, GLuint divisor
)
2089 GET_CURRENT_CONTEXT(ctx
);
2091 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2092 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2094 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2096 /* The ARB_vertex_attrib_binding spec says:
2100 * void VertexAttribDivisor(uint index, uint divisor);
2102 * is equivalent to (assuming no errors are generated):
2104 * VertexAttribBinding(index, index);
2105 * VertexBindingDivisor(index, divisor);"
2107 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2108 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2113 * See GL_ARB_instanced_arrays.
2114 * Note that the instance divisor only applies to generic arrays, not
2115 * the legacy vertex arrays.
2118 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
2120 GET_CURRENT_CONTEXT(ctx
);
2122 const gl_vert_attrib genericIndex
= VERT_ATTRIB_GENERIC(index
);
2123 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
2125 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2126 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
2130 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2131 _mesa_error(ctx
, GL_INVALID_VALUE
,
2132 "glVertexAttribDivisor(index = %u)", index
);
2136 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
2138 /* The ARB_vertex_attrib_binding spec says:
2142 * void VertexAttribDivisor(uint index, uint divisor);
2144 * is equivalent to (assuming no errors are generated):
2146 * VertexAttribBinding(index, index);
2147 * VertexBindingDivisor(index, divisor);"
2149 _mesa_vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
2150 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
2154 static ALWAYS_INLINE
void
2155 vertex_array_vertex_buffer(struct gl_context
*ctx
,
2156 struct gl_vertex_array_object
*vao
,
2157 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2158 GLsizei stride
, bool no_error
, const char *func
)
2160 struct gl_buffer_object
*vbo
;
2162 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
2163 vbo
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
2164 } else if (buffer
!= 0) {
2165 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
2167 if (!no_error
&& !vbo
&& _mesa_is_gles31(ctx
)) {
2168 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
2171 /* From the GL_ARB_vertex_attrib_array spec:
2173 * "[Core profile only:]
2174 * An INVALID_OPERATION error is generated if buffer is not zero or a
2175 * name returned from a previous call to GenBuffers, or if such a name
2176 * has since been deleted with DeleteBuffers.
2178 * Otherwise, we fall back to the same compat profile behavior as other
2179 * object references (automatically gen it).
2181 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
2184 /* The ARB_vertex_attrib_binding spec says:
2186 * "If <buffer> is zero, any buffer object attached to this
2187 * bindpoint is detached."
2189 vbo
= ctx
->Shared
->NullBufferObj
;
2192 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
2193 vbo
, offset
, stride
);
2198 * GL_ARB_vertex_attrib_binding
2201 vertex_array_vertex_buffer_err(struct gl_context
*ctx
,
2202 struct gl_vertex_array_object
*vao
,
2203 GLuint bindingIndex
, GLuint buffer
,
2204 GLintptr offset
, GLsizei stride
,
2207 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2209 /* The ARB_vertex_attrib_binding spec says:
2211 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
2212 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
2214 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2215 _mesa_error(ctx
, GL_INVALID_VALUE
,
2216 "%s(bindingindex=%u > "
2217 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2218 func
, bindingIndex
);
2222 /* The ARB_vertex_attrib_binding spec says:
2224 * "The error INVALID_VALUE is generated if <stride> or <offset>
2228 _mesa_error(ctx
, GL_INVALID_VALUE
,
2229 "%s(offset=%" PRId64
" < 0)",
2230 func
, (int64_t) offset
);
2235 _mesa_error(ctx
, GL_INVALID_VALUE
,
2236 "%s(stride=%d < 0)", func
, stride
);
2240 if (((_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
2241 stride
> ctx
->Const
.MaxVertexAttribStride
) {
2242 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
2243 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
2247 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2248 stride
, false, func
);
2253 _mesa_BindVertexBuffer_no_error(GLuint bindingIndex
, GLuint buffer
,
2254 GLintptr offset
, GLsizei stride
)
2256 GET_CURRENT_CONTEXT(ctx
);
2257 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2258 buffer
, offset
, stride
, true,
2259 "glBindVertexBuffer");
2264 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
2267 GET_CURRENT_CONTEXT(ctx
);
2269 /* The ARB_vertex_attrib_binding spec says:
2271 * "An INVALID_OPERATION error is generated if no vertex array object
2274 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2275 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2276 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2277 "glBindVertexBuffer(No array object bound)");
2281 vertex_array_vertex_buffer_err(ctx
, ctx
->Array
.VAO
, bindingIndex
,
2282 buffer
, offset
, stride
,
2283 "glBindVertexBuffer");
2288 _mesa_VertexArrayVertexBuffer_no_error(GLuint vaobj
, GLuint bindingIndex
,
2289 GLuint buffer
, GLintptr offset
,
2292 GET_CURRENT_CONTEXT(ctx
);
2294 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2295 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
, buffer
, offset
,
2296 stride
, true, "glVertexArrayVertexBuffer");
2301 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
2302 GLintptr offset
, GLsizei stride
)
2304 GET_CURRENT_CONTEXT(ctx
);
2305 struct gl_vertex_array_object
*vao
;
2307 /* The ARB_direct_state_access specification says:
2309 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2310 * if <vaobj> is not [compatibility profile: zero or] the name of an
2311 * existing vertex array object."
2313 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
2317 vertex_array_vertex_buffer_err(ctx
, vao
, bindingIndex
, buffer
, offset
,
2318 stride
, "glVertexArrayVertexBuffer");
2322 static ALWAYS_INLINE
void
2323 vertex_array_vertex_buffers(struct gl_context
*ctx
,
2324 struct gl_vertex_array_object
*vao
,
2325 GLuint first
, GLsizei count
, const GLuint
*buffers
,
2326 const GLintptr
*offsets
, const GLsizei
*strides
,
2327 bool no_error
, const char *func
)
2333 * The ARB_multi_bind spec says:
2335 * "If <buffers> is NULL, each affected vertex buffer binding point
2336 * from <first> through <first>+<count>-1 will be reset to have no
2337 * bound buffer object. In this case, the offsets and strides
2338 * associated with the binding points are set to default values,
2339 * ignoring <offsets> and <strides>."
2341 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
2343 for (i
= 0; i
< count
; i
++)
2344 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2350 /* Note that the error semantics for multi-bind commands differ from
2351 * those of other GL commands.
2353 * The Issues section in the ARB_multi_bind spec says:
2355 * "(11) Typically, OpenGL specifies that if an error is generated by
2356 * a command, that command has no effect. This is somewhat
2357 * unfortunate for multi-bind commands, because it would require
2358 * a first pass to scan the entire list of bound objects for
2359 * errors and then a second pass to actually perform the
2360 * bindings. Should we have different error semantics?
2362 * RESOLVED: Yes. In this specification, when the parameters for
2363 * one of the <count> binding points are invalid, that binding
2364 * point is not updated and an error will be generated. However,
2365 * other binding points in the same command will be updated if
2366 * their parameters are valid and no other error occurs."
2369 _mesa_HashLockMutex(ctx
->Shared
->BufferObjects
);
2371 for (i
= 0; i
< count
; i
++) {
2372 struct gl_buffer_object
*vbo
;
2375 /* The ARB_multi_bind spec says:
2377 * "An INVALID_VALUE error is generated if any value in
2378 * <offsets> or <strides> is negative (per binding)."
2380 if (offsets
[i
] < 0) {
2381 _mesa_error(ctx
, GL_INVALID_VALUE
,
2382 "%s(offsets[%u]=%" PRId64
" < 0)",
2383 func
, i
, (int64_t) offsets
[i
]);
2387 if (strides
[i
] < 0) {
2388 _mesa_error(ctx
, GL_INVALID_VALUE
,
2389 "%s(strides[%u]=%d < 0)",
2390 func
, i
, strides
[i
]);
2394 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 44 &&
2395 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
2396 _mesa_error(ctx
, GL_INVALID_VALUE
,
2397 "%s(strides[%u]=%d > "
2398 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
2404 struct gl_vertex_buffer_binding
*binding
=
2405 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
2407 if (buffers
[i
] == binding
->BufferObj
->Name
)
2408 vbo
= binding
->BufferObj
;
2410 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
2415 vbo
= ctx
->Shared
->NullBufferObj
;
2418 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
2419 vbo
, offsets
[i
], strides
[i
]);
2422 _mesa_HashUnlockMutex(ctx
->Shared
->BufferObjects
);
2427 vertex_array_vertex_buffers_err(struct gl_context
*ctx
,
2428 struct gl_vertex_array_object
*vao
,
2429 GLuint first
, GLsizei count
,
2430 const GLuint
*buffers
, const GLintptr
*offsets
,
2431 const GLsizei
*strides
, const char *func
)
2433 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2435 /* The ARB_multi_bind spec says:
2437 * "An INVALID_OPERATION error is generated if <first> + <count>
2438 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
2440 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
2441 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2442 "%s(first=%u + count=%d > the value of "
2443 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
2444 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
2448 vertex_array_vertex_buffers(ctx
, vao
, first
, count
, buffers
, offsets
,
2449 strides
, false, func
);
2454 _mesa_BindVertexBuffers_no_error(GLuint first
, GLsizei count
,
2455 const GLuint
*buffers
, const GLintptr
*offsets
,
2456 const GLsizei
*strides
)
2458 GET_CURRENT_CONTEXT(ctx
);
2460 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
2461 buffers
, offsets
, strides
, true,
2462 "glBindVertexBuffers");
2467 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
2468 const GLintptr
*offsets
, const GLsizei
*strides
)
2470 GET_CURRENT_CONTEXT(ctx
);
2472 /* The ARB_vertex_attrib_binding spec says:
2474 * "An INVALID_OPERATION error is generated if no
2475 * vertex array object is bound."
2477 if (ctx
->API
== API_OPENGL_CORE
&&
2478 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2479 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2480 "glBindVertexBuffers(No array object bound)");
2484 vertex_array_vertex_buffers_err(ctx
, ctx
->Array
.VAO
, first
, count
,
2485 buffers
, offsets
, strides
,
2486 "glBindVertexBuffers");
2491 _mesa_VertexArrayVertexBuffers_no_error(GLuint vaobj
, GLuint first
,
2492 GLsizei count
, const GLuint
*buffers
,
2493 const GLintptr
*offsets
,
2494 const GLsizei
*strides
)
2496 GET_CURRENT_CONTEXT(ctx
);
2498 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2499 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
2500 buffers
, offsets
, strides
, true,
2501 "glVertexArrayVertexBuffers");
2506 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
2507 const GLuint
*buffers
,
2508 const GLintptr
*offsets
, const GLsizei
*strides
)
2510 GET_CURRENT_CONTEXT(ctx
);
2511 struct gl_vertex_array_object
*vao
;
2513 /* The ARB_direct_state_access specification says:
2515 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
2516 * if <vaobj> is not [compatibility profile: zero or] the name of an
2517 * existing vertex array object."
2519 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
2523 vertex_array_vertex_buffers_err(ctx
, vao
, first
, count
,
2524 buffers
, offsets
, strides
,
2525 "glVertexArrayVertexBuffers");
2530 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
2531 GLboolean normalized
, GLboolean integer
,
2532 GLboolean doubles
, GLbitfield legalTypes
,
2533 GLsizei sizeMax
, GLuint relativeOffset
,
2536 GET_CURRENT_CONTEXT(ctx
);
2537 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2539 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2541 if (!_mesa_is_no_error_enabled(ctx
)) {
2542 /* The ARB_vertex_attrib_binding spec says:
2544 * "An INVALID_OPERATION error is generated under any of the
2545 * following conditions:
2546 * - if no vertex array object is currently bound (see section
2550 * This error condition only applies to VertexAttribFormat and
2551 * VertexAttribIFormat in the extension spec, but we assume that this
2552 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2553 * to all three functions.
2555 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2556 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2557 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2558 "%s(No array object bound)", func
);
2562 /* The ARB_vertex_attrib_binding spec says:
2564 * "The error INVALID_VALUE is generated if index is greater than or
2565 * equal to the value of MAX_VERTEX_ATTRIBS."
2567 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2568 _mesa_error(ctx
, GL_INVALID_VALUE
,
2569 "%s(attribindex=%u > "
2570 "GL_MAX_VERTEX_ATTRIBS)",
2575 if (!validate_array_format(ctx
, func
, ctx
->Array
.VAO
,
2576 VERT_ATTRIB_GENERIC(attribIndex
),
2577 legalTypes
, 1, sizeMax
, size
, type
,
2578 normalized
, integer
, doubles
, relativeOffset
,
2584 _mesa_update_array_format(ctx
, ctx
->Array
.VAO
,
2585 VERT_ATTRIB_GENERIC(attribIndex
), size
, type
,
2586 format
, normalized
, integer
, doubles
,
2592 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2593 GLboolean normalized
, GLuint relativeOffset
)
2595 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
2596 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2597 BGRA_OR_4
, relativeOffset
,
2598 "glVertexAttribFormat");
2603 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2604 GLuint relativeOffset
)
2606 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2607 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2608 relativeOffset
, "glVertexAttribIFormat");
2613 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2614 GLuint relativeOffset
)
2616 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2617 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2618 relativeOffset
, "glVertexAttribLFormat");
2623 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2624 GLenum type
, GLboolean normalized
,
2625 GLboolean integer
, GLboolean doubles
,
2626 GLbitfield legalTypes
, GLsizei sizeMax
,
2627 GLuint relativeOffset
, const char *func
)
2629 GET_CURRENT_CONTEXT(ctx
);
2630 struct gl_vertex_array_object
*vao
;
2632 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2634 GLenum format
= get_array_format(ctx
, sizeMax
, &size
);
2636 if (_mesa_is_no_error_enabled(ctx
)) {
2637 vao
= _mesa_lookup_vao(ctx
, vaobj
);
2641 /* The ARB_direct_state_access spec says:
2643 * "An INVALID_OPERATION error is generated by
2644 * VertexArrayAttrib*Format if <vaobj> is not [compatibility profile:
2645 * zero or] the name of an existing vertex array object."
2647 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2651 /* The ARB_vertex_attrib_binding spec says:
2653 * "The error INVALID_VALUE is generated if index is greater than or
2654 * equal to the value of MAX_VERTEX_ATTRIBS."
2656 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2657 _mesa_error(ctx
, GL_INVALID_VALUE
,
2658 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2663 if (!validate_array_format(ctx
, func
, vao
,
2664 VERT_ATTRIB_GENERIC(attribIndex
),
2665 legalTypes
, 1, sizeMax
, size
, type
,
2666 normalized
, integer
, doubles
, relativeOffset
,
2672 _mesa_update_array_format(ctx
, vao
, VERT_ATTRIB_GENERIC(attribIndex
), size
,
2673 type
, format
, normalized
, integer
, doubles
,
2679 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2680 GLenum type
, GLboolean normalized
,
2681 GLuint relativeOffset
)
2683 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2684 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2685 BGRA_OR_4
, relativeOffset
,
2686 "glVertexArrayAttribFormat");
2691 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2692 GLint size
, GLenum type
,
2693 GLuint relativeOffset
)
2695 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2696 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2698 "glVertexArrayAttribIFormat");
2703 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2704 GLint size
, GLenum type
,
2705 GLuint relativeOffset
)
2707 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2708 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2710 "glVertexArrayAttribLFormat");
2715 vertex_array_attrib_binding(struct gl_context
*ctx
,
2716 struct gl_vertex_array_object
*vao
,
2717 GLuint attribIndex
, GLuint bindingIndex
,
2720 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2722 /* The ARB_vertex_attrib_binding spec says:
2724 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2725 * <bindingindex> must be less than the value of
2726 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2729 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2730 _mesa_error(ctx
, GL_INVALID_VALUE
,
2731 "%s(attribindex=%u >= "
2732 "GL_MAX_VERTEX_ATTRIBS)",
2737 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2738 _mesa_error(ctx
, GL_INVALID_VALUE
,
2739 "%s(bindingindex=%u >= "
2740 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2741 func
, bindingIndex
);
2745 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2747 _mesa_vertex_attrib_binding(ctx
, vao
,
2748 VERT_ATTRIB_GENERIC(attribIndex
),
2749 VERT_ATTRIB_GENERIC(bindingIndex
));
2754 _mesa_VertexAttribBinding_no_error(GLuint attribIndex
, GLuint bindingIndex
)
2756 GET_CURRENT_CONTEXT(ctx
);
2757 _mesa_vertex_attrib_binding(ctx
, ctx
->Array
.VAO
,
2758 VERT_ATTRIB_GENERIC(attribIndex
),
2759 VERT_ATTRIB_GENERIC(bindingIndex
));
2764 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2766 GET_CURRENT_CONTEXT(ctx
);
2768 /* The ARB_vertex_attrib_binding spec says:
2770 * "An INVALID_OPERATION error is generated if no vertex array object
2773 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2774 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2775 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2776 "glVertexAttribBinding(No array object bound)");
2780 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2781 attribIndex
, bindingIndex
,
2782 "glVertexAttribBinding");
2787 _mesa_VertexArrayAttribBinding_no_error(GLuint vaobj
, GLuint attribIndex
,
2788 GLuint bindingIndex
)
2790 GET_CURRENT_CONTEXT(ctx
);
2792 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2793 _mesa_vertex_attrib_binding(ctx
, vao
,
2794 VERT_ATTRIB_GENERIC(attribIndex
),
2795 VERT_ATTRIB_GENERIC(bindingIndex
));
2800 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2802 GET_CURRENT_CONTEXT(ctx
);
2803 struct gl_vertex_array_object
*vao
;
2805 /* The ARB_direct_state_access specification says:
2807 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2808 * if <vaobj> is not [compatibility profile: zero or] the name of an
2809 * existing vertex array object."
2811 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2815 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2816 "glVertexArrayAttribBinding");
2821 vertex_array_binding_divisor(struct gl_context
*ctx
,
2822 struct gl_vertex_array_object
*vao
,
2823 GLuint bindingIndex
, GLuint divisor
,
2826 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2828 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2829 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2833 /* The ARB_vertex_attrib_binding spec says:
2835 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2836 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2838 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2839 _mesa_error(ctx
, GL_INVALID_VALUE
,
2840 "%s(bindingindex=%u > "
2841 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2842 func
, bindingIndex
);
2846 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2851 _mesa_VertexBindingDivisor_no_error(GLuint bindingIndex
, GLuint divisor
)
2853 GET_CURRENT_CONTEXT(ctx
);
2854 vertex_binding_divisor(ctx
, ctx
->Array
.VAO
,
2855 VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2860 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
2862 GET_CURRENT_CONTEXT(ctx
);
2864 /* The ARB_vertex_attrib_binding spec says:
2866 * "An INVALID_OPERATION error is generated if no vertex array object
2869 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2870 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2871 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2872 "glVertexBindingDivisor(No array object bound)");
2876 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2877 bindingIndex
, divisor
,
2878 "glVertexBindingDivisor");
2883 _mesa_VertexArrayBindingDivisor_no_error(GLuint vaobj
, GLuint bindingIndex
,
2886 GET_CURRENT_CONTEXT(ctx
);
2888 struct gl_vertex_array_object
*vao
= _mesa_lookup_vao(ctx
, vaobj
);
2889 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2894 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2897 struct gl_vertex_array_object
*vao
;
2898 GET_CURRENT_CONTEXT(ctx
);
2900 /* The ARB_direct_state_access specification says:
2902 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2903 * if <vaobj> is not [compatibility profile: zero or] the name of an
2904 * existing vertex array object."
2906 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2910 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2911 "glVertexArrayBindingDivisor");
2916 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2917 struct gl_array_attributes
*dst
,
2918 const struct gl_array_attributes
*src
)
2920 dst
->Ptr
= src
->Ptr
;
2921 dst
->RelativeOffset
= src
->RelativeOffset
;
2922 dst
->Format
= src
->Format
;
2923 dst
->Stride
= src
->Stride
;
2924 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
2925 dst
->_EffBufferBindingIndex
= src
->_EffBufferBindingIndex
;
2926 dst
->_EffRelativeOffset
= src
->_EffRelativeOffset
;
2930 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2931 struct gl_vertex_buffer_binding
*dst
,
2932 const struct gl_vertex_buffer_binding
*src
)
2934 dst
->Offset
= src
->Offset
;
2935 dst
->Stride
= src
->Stride
;
2936 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2937 dst
->_BoundArrays
= src
->_BoundArrays
;
2938 dst
->_EffBoundArrays
= src
->_EffBoundArrays
;
2939 dst
->_EffOffset
= src
->_EffOffset
;
2941 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2945 * Print current vertex object/array info. For debug.
2948 _mesa_print_arrays(struct gl_context
*ctx
)
2950 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2952 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
2954 GLbitfield mask
= vao
->Enabled
;
2956 const gl_vert_attrib i
= u_bit_scan(&mask
);
2957 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
2959 const struct gl_vertex_buffer_binding
*binding
=
2960 &vao
->BufferBinding
[array
->BufferBindingIndex
];
2961 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
2963 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2964 "Stride=%d, Buffer=%u(Size %lu)\n",
2965 gl_vert_attrib_name((gl_vert_attrib
)i
),
2966 array
->Ptr
, _mesa_enum_to_string(array
->Format
.Type
),
2968 array
->Format
._ElementSize
, binding
->Stride
, bo
->Name
,
2969 (unsigned long) bo
->Size
);
2975 * Initialize vertex array state for given context.
2978 _mesa_init_varray(struct gl_context
*ctx
)
2980 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2981 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2982 ctx
->Array
._EmptyVAO
= _mesa_new_vao(ctx
, ~0u);
2983 _mesa_reference_vao(ctx
, &ctx
->Array
._DrawVAO
, ctx
->Array
._EmptyVAO
);
2984 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2986 ctx
->Array
.Objects
= _mesa_NewHashTable();
2991 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2994 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2996 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2997 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2998 _mesa_delete_vao(ctx
, vao
);
3003 * Free vertex array state for given context.
3006 _mesa_free_varray_data(struct gl_context
*ctx
)
3008 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
3009 _mesa_DeleteHashTable(ctx
->Array
.Objects
);