2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 #include <inttypes.h> /* for PRId64 macro */
32 #include "bufferobj.h"
42 #include "main/dispatch.h"
45 /** Used to do error checking for GL_EXT_vertex_array_bgra */
49 /** Used to indicate which GL datatypes are accepted by each of the
50 * glVertex/Color/Attrib/EtcPointer() functions.
52 #define BOOL_BIT (1 << 0)
53 #define BYTE_BIT (1 << 1)
54 #define UNSIGNED_BYTE_BIT (1 << 2)
55 #define SHORT_BIT (1 << 3)
56 #define UNSIGNED_SHORT_BIT (1 << 4)
57 #define INT_BIT (1 << 5)
58 #define UNSIGNED_INT_BIT (1 << 6)
59 #define HALF_BIT (1 << 7)
60 #define FLOAT_BIT (1 << 8)
61 #define DOUBLE_BIT (1 << 9)
62 #define FIXED_ES_BIT (1 << 10)
63 #define FIXED_GL_BIT (1 << 11)
64 #define UNSIGNED_INT_2_10_10_10_REV_BIT (1 << 12)
65 #define INT_2_10_10_10_REV_BIT (1 << 13)
66 #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14)
67 #define ALL_TYPE_BITS ((1 << 15) - 1)
69 #define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
70 SHORT_BIT | UNSIGNED_SHORT_BIT | \
71 INT_BIT | UNSIGNED_INT_BIT | \
72 HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \
74 UNSIGNED_INT_2_10_10_10_REV_BIT | \
75 INT_2_10_10_10_REV_BIT | \
76 UNSIGNED_INT_10F_11F_11F_REV_BIT)
78 #define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \
79 SHORT_BIT | UNSIGNED_SHORT_BIT | \
80 INT_BIT | UNSIGNED_INT_BIT)
82 #define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT
85 /** Convert GL datatype enum into a <type>_BIT value seen above */
87 type_to_bit(const struct gl_context
*ctx
, GLenum type
)
94 case GL_UNSIGNED_BYTE
:
95 return UNSIGNED_BYTE_BIT
;
98 case GL_UNSIGNED_SHORT
:
99 return UNSIGNED_SHORT_BIT
;
102 case GL_UNSIGNED_INT
:
103 return UNSIGNED_INT_BIT
;
105 case GL_HALF_FLOAT_OES
:
106 if (ctx
->Extensions
.ARB_half_float_vertex
)
115 return _mesa_is_desktop_gl(ctx
) ? FIXED_GL_BIT
: FIXED_ES_BIT
;
116 case GL_UNSIGNED_INT_2_10_10_10_REV
:
117 return UNSIGNED_INT_2_10_10_10_REV_BIT
;
118 case GL_INT_2_10_10_10_REV
:
119 return INT_2_10_10_10_REV_BIT
;
120 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
121 return UNSIGNED_INT_10F_11F_11F_REV_BIT
;
129 * Sets the BufferBindingIndex field for the vertex attribute given by
133 vertex_attrib_binding(struct gl_context
*ctx
,
134 struct gl_vertex_array_object
*vao
,
138 struct gl_array_attributes
*array
= &vao
->VertexAttrib
[attribIndex
];
140 if (!_mesa_is_bufferobj(vao
->BufferBinding
[bindingIndex
].BufferObj
))
141 vao
->VertexAttribBufferMask
&= ~VERT_BIT(attribIndex
);
143 vao
->VertexAttribBufferMask
|= VERT_BIT(attribIndex
);
145 if (array
->BufferBindingIndex
!= bindingIndex
) {
146 const GLbitfield64 array_bit
= VERT_BIT(attribIndex
);
148 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
150 vao
->BufferBinding
[array
->BufferBindingIndex
]._BoundArrays
&= ~array_bit
;
151 vao
->BufferBinding
[bindingIndex
]._BoundArrays
|= array_bit
;
153 array
->BufferBindingIndex
= bindingIndex
;
155 vao
->NewArrays
|= array_bit
;
161 * Binds a buffer object to the vertex buffer binding point given by index,
162 * and sets the Offset and Stride fields.
165 _mesa_bind_vertex_buffer(struct gl_context
*ctx
,
166 struct gl_vertex_array_object
*vao
,
168 struct gl_buffer_object
*vbo
,
169 GLintptr offset
, GLsizei stride
)
171 struct gl_vertex_buffer_binding
*binding
= &vao
->BufferBinding
[index
];
173 if (binding
->BufferObj
!= vbo
||
174 binding
->Offset
!= offset
||
175 binding
->Stride
!= stride
) {
177 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
179 _mesa_reference_buffer_object(ctx
, &binding
->BufferObj
, vbo
);
181 binding
->Offset
= offset
;
182 binding
->Stride
= stride
;
184 if (!_mesa_is_bufferobj(vbo
))
185 vao
->VertexAttribBufferMask
&= ~binding
->_BoundArrays
;
187 vao
->VertexAttribBufferMask
|= binding
->_BoundArrays
;
189 vao
->NewArrays
|= binding
->_BoundArrays
;
195 * Sets the InstanceDivisor field in the vertex buffer binding point
196 * given by bindingIndex.
199 vertex_binding_divisor(struct gl_context
*ctx
,
200 struct gl_vertex_array_object
*vao
,
204 struct gl_vertex_buffer_binding
*binding
=
205 &vao
->BufferBinding
[bindingIndex
];
207 if (binding
->InstanceDivisor
!= divisor
) {
208 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
209 binding
->InstanceDivisor
= divisor
;
210 vao
->NewArrays
|= binding
->_BoundArrays
;
216 * Examine the API profile and extensions to determine which types are legal
217 * for vertex arrays. This is called once from update_array_format().
220 get_legal_types_mask(const struct gl_context
*ctx
)
222 GLbitfield legalTypesMask
= ALL_TYPE_BITS
;
224 if (_mesa_is_gles(ctx
)) {
225 legalTypesMask
&= ~(FIXED_GL_BIT
|
227 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
229 /* GL_INT and GL_UNSIGNED_INT data is not allowed in OpenGL ES until
230 * 3.0. The 2_10_10_10 types are added in OpenGL ES 3.0 or
231 * GL_OES_vertex_type_10_10_10_2. GL_HALF_FLOAT data is not allowed
232 * until 3.0 or with the GL_OES_vertex_half float extension, which isn't
233 * quite as trivial as we'd like because it uses a different enum value
234 * for GL_HALF_FLOAT_OES.
236 if (ctx
->Version
< 30) {
237 legalTypesMask
&= ~(UNSIGNED_INT_BIT
|
239 UNSIGNED_INT_2_10_10_10_REV_BIT
|
240 INT_2_10_10_10_REV_BIT
);
242 if (!_mesa_has_OES_vertex_half_float(ctx
))
243 legalTypesMask
&= ~HALF_BIT
;
247 legalTypesMask
&= ~FIXED_ES_BIT
;
249 if (!ctx
->Extensions
.ARB_ES2_compatibility
)
250 legalTypesMask
&= ~FIXED_GL_BIT
;
252 if (!ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
)
253 legalTypesMask
&= ~(UNSIGNED_INT_2_10_10_10_REV_BIT
|
254 INT_2_10_10_10_REV_BIT
);
256 if (!ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
)
257 legalTypesMask
&= ~UNSIGNED_INT_10F_11F_11F_REV_BIT
;
260 return legalTypesMask
;
265 * \param attrib The index of the attribute array
266 * \param size Components per element (1, 2, 3 or 4)
267 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
268 * \param format Either GL_RGBA or GL_BGRA.
269 * \param normalized Whether integer types are converted to floats in [-1, 1]
270 * \param integer Integer-valued values (will not be normalized to [-1, 1])
271 * \param doubles Double values not reduced to floats
272 * \param relativeOffset Offset of the first element relative to the binding
274 * \param flush_verties Should \c FLUSH_VERTICES be invoked before updating
278 _mesa_update_array_format(struct gl_context
*ctx
,
279 struct gl_vertex_array_object
*vao
,
280 GLuint attrib
, GLint size
, GLenum type
,
281 GLenum format
, GLboolean normalized
,
282 GLboolean integer
, GLboolean doubles
,
283 GLuint relativeOffset
)
285 struct gl_array_attributes
*const array
= &vao
->VertexAttrib
[attrib
];
290 elementSize
= _mesa_bytes_per_vertex_attrib(size
, type
);
291 assert(elementSize
!= -1);
295 array
->Format
= format
;
296 array
->Normalized
= normalized
;
297 array
->Integer
= integer
;
298 array
->Doubles
= doubles
;
299 array
->RelativeOffset
= relativeOffset
;
300 array
->_ElementSize
= elementSize
;
302 vao
->NewArrays
|= VERT_BIT(attrib
);
303 ctx
->NewState
|= _NEW_ARRAY
;
307 * Does error checking and updates the format in an attrib array.
309 * Called by update_array() and VertexAttrib*Format().
311 * \param func Name of calling function used for error reporting
312 * \param attrib The index of the attribute array
313 * \param legalTypes Bitmask of *_BIT above indicating legal datatypes
314 * \param sizeMin Min allowable size value
315 * \param sizeMax Max allowable size value (may also be BGRA_OR_4)
316 * \param size Components per element (1, 2, 3 or 4)
317 * \param type Datatype of each component (GL_FLOAT, GL_INT, etc)
318 * \param normalized Whether integer types are converted to floats in [-1, 1]
319 * \param integer Integer-valued values (will not be normalized to [-1, 1])
320 * \param doubles Double values not reduced to floats
321 * \param relativeOffset Offset of the first element relative to the binding offset.
324 update_array_format(struct gl_context
*ctx
,
326 struct gl_vertex_array_object
*vao
,
327 GLuint attrib
, GLbitfield legalTypesMask
,
328 GLint sizeMin
, GLint sizeMax
,
329 GLint size
, GLenum type
,
330 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
331 GLuint relativeOffset
)
334 GLenum format
= GL_RGBA
;
336 /* at most, one of these bools can be true */
337 assert((int) normalized
+ (int) integer
+ (int) doubles
<= 1);
339 if (ctx
->Array
.LegalTypesMask
== 0 || ctx
->Array
.LegalTypesMaskAPI
!= ctx
->API
) {
340 /* Compute the LegalTypesMask only once, unless the context API has
341 * changed, in which case we want to compute it again. We can't do this
342 * in _mesa_init_varrays() below because extensions are not yet enabled
345 ctx
->Array
.LegalTypesMask
= get_legal_types_mask(ctx
);
346 ctx
->Array
.LegalTypesMaskAPI
= ctx
->API
;
349 legalTypesMask
&= ctx
->Array
.LegalTypesMask
;
351 if (_mesa_is_gles(ctx
) && sizeMax
== BGRA_OR_4
) {
352 /* BGRA ordering is not supported in ES contexts.
357 typeBit
= type_to_bit(ctx
, type
);
358 if (typeBit
== 0x0 || (typeBit
& legalTypesMask
) == 0x0) {
359 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)",
360 func
, _mesa_enum_to_string(type
));
364 /* Do size parameter checking.
365 * If sizeMax = BGRA_OR_4 it means that size = GL_BGRA is legal and
366 * must be handled specially.
368 if (ctx
->Extensions
.EXT_vertex_array_bgra
&&
369 sizeMax
== BGRA_OR_4
&&
371 /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says:
373 * "An INVALID_OPERATION error is generated under any of the following
376 * • size is BGRA and type is not UNSIGNED_BYTE, INT_2_10_10_10_REV
377 * or UNSIGNED_INT_2_10_10_10_REV;
379 * • size is BGRA and normalized is FALSE;"
381 bool bgra_error
= false;
383 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
) {
384 if (type
!= GL_UNSIGNED_INT_2_10_10_10_REV
&&
385 type
!= GL_INT_2_10_10_10_REV
&&
386 type
!= GL_UNSIGNED_BYTE
)
388 } else if (type
!= GL_UNSIGNED_BYTE
)
392 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=GL_BGRA and type=%s)",
393 func
, _mesa_enum_to_string(type
));
398 _mesa_error(ctx
, GL_INVALID_OPERATION
,
399 "%s(size=GL_BGRA and normalized=GL_FALSE)", func
);
406 else if (size
< sizeMin
|| size
> sizeMax
|| size
> 4) {
407 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", func
, size
);
411 if (ctx
->Extensions
.ARB_vertex_type_2_10_10_10_rev
&&
412 (type
== GL_UNSIGNED_INT_2_10_10_10_REV
||
413 type
== GL_INT_2_10_10_10_REV
) && size
!= 4) {
414 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
418 /* The ARB_vertex_attrib_binding_spec says:
420 * An INVALID_VALUE error is generated if <relativeoffset> is larger than
421 * the value of MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.
423 if (relativeOffset
> ctx
->Const
.MaxVertexAttribRelativeOffset
) {
424 _mesa_error(ctx
, GL_INVALID_VALUE
,
425 "%s(relativeOffset=%d > "
426 "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET)",
427 func
, relativeOffset
);
431 if (ctx
->Extensions
.ARB_vertex_type_10f_11f_11f_rev
&&
432 type
== GL_UNSIGNED_INT_10F_11F_11F_REV
&& size
!= 3) {
433 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(size=%d)", func
, size
);
437 _mesa_update_array_format(ctx
, vao
, attrib
, size
, type
, format
,
438 normalized
, integer
, doubles
, relativeOffset
);
445 * Do error checking and update state for glVertex/Color/TexCoord/...Pointer
448 * \param func name of calling function used for error reporting
449 * \param attrib the attribute array index to update
450 * \param legalTypes bitmask of *_BIT above indicating legal datatypes
451 * \param sizeMin min allowable size value
452 * \param sizeMax max allowable size value (may also be BGRA_OR_4)
453 * \param size components per element (1, 2, 3 or 4)
454 * \param type datatype of each component (GL_FLOAT, GL_INT, etc)
455 * \param stride stride between elements, in elements
456 * \param normalized are integer types converted to floats in [-1, 1]?
457 * \param integer integer-valued values (will not be normalized to [-1,1])
458 * \param doubles Double values not reduced to floats
459 * \param ptr the address (or offset inside VBO) of the array data
462 update_array(struct gl_context
*ctx
,
464 GLuint attrib
, GLbitfield legalTypesMask
,
465 GLint sizeMin
, GLint sizeMax
,
466 GLint size
, GLenum type
, GLsizei stride
,
467 GLboolean normalized
, GLboolean integer
, GLboolean doubles
,
470 struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
471 struct gl_array_attributes
*array
;
472 GLsizei effectiveStride
;
474 /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says:
476 * "Client vertex arrays - all vertex array attribute pointers must
477 * refer to buffer objects (section 2.9.2). The default vertex array
478 * object (the name zero) is also deprecated. Calling
479 * VertexAttribPointer when no buffer object or no vertex array object
480 * is bound will generate an INVALID_OPERATION error..."
482 * The check for VBOs is handled below.
484 if (ctx
->API
== API_OPENGL_CORE
&& (vao
== ctx
->Array
.DefaultVAO
)) {
485 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no array object bound)",
491 _mesa_error( ctx
, GL_INVALID_VALUE
, "%s(stride=%d)", func
, stride
);
495 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
496 stride
> ctx
->Const
.MaxVertexAttribStride
) {
497 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
498 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
502 /* Page 29 (page 44 of the PDF) of the OpenGL 3.3 spec says:
504 * "An INVALID_OPERATION error is generated under any of the following
509 * * any of the *Pointer commands specifying the location and
510 * organization of vertex array data are called while zero is bound
511 * to the ARRAY_BUFFER buffer object binding point (see section
512 * 2.9.6), and the pointer argument is not NULL."
514 if (ptr
!= NULL
&& vao
->ARBsemantics
&&
515 !_mesa_is_bufferobj(ctx
->Array
.ArrayBufferObj
)) {
516 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-VBO array)", func
);
520 if (!update_array_format(ctx
, func
, vao
, attrib
,
521 legalTypesMask
, sizeMin
, sizeMax
,
522 size
, type
, normalized
, integer
, doubles
, 0)) {
526 /* Reset the vertex attrib binding */
527 vertex_attrib_binding(ctx
, vao
, attrib
, attrib
);
529 /* The Stride and Ptr fields are not set by update_array_format() */
530 array
= &vao
->VertexAttrib
[attrib
];
531 array
->Stride
= stride
;
534 /* Update the vertex buffer binding */
535 effectiveStride
= stride
!= 0 ? stride
: array
->_ElementSize
;
536 _mesa_bind_vertex_buffer(ctx
, vao
, attrib
,
537 ctx
->Array
.ArrayBufferObj
, (GLintptr
) ptr
,
543 _mesa_VertexPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
545 GET_CURRENT_CONTEXT(ctx
);
546 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
547 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
548 : (SHORT_BIT
| INT_BIT
| FLOAT_BIT
|
549 DOUBLE_BIT
| HALF_BIT
|
550 UNSIGNED_INT_2_10_10_10_REV_BIT
|
551 INT_2_10_10_10_REV_BIT
);
553 FLUSH_VERTICES(ctx
, 0);
555 update_array(ctx
, "glVertexPointer", VERT_ATTRIB_POS
,
557 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
562 _mesa_NormalPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
564 GET_CURRENT_CONTEXT(ctx
);
565 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
566 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
567 : (BYTE_BIT
| SHORT_BIT
| INT_BIT
|
568 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
569 UNSIGNED_INT_2_10_10_10_REV_BIT
|
570 INT_2_10_10_10_REV_BIT
);
572 FLUSH_VERTICES(ctx
, 0);
574 update_array(ctx
, "glNormalPointer", VERT_ATTRIB_NORMAL
,
576 3, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
581 _mesa_ColorPointer(GLint size
, GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
583 GET_CURRENT_CONTEXT(ctx
);
584 const GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
585 ? (UNSIGNED_BYTE_BIT
| HALF_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
586 : (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
587 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
588 INT_BIT
| UNSIGNED_INT_BIT
|
589 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
590 UNSIGNED_INT_2_10_10_10_REV_BIT
|
591 INT_2_10_10_10_REV_BIT
);
592 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 4 : 3;
594 FLUSH_VERTICES(ctx
, 0);
596 update_array(ctx
, "glColorPointer", VERT_ATTRIB_COLOR0
,
597 legalTypes
, sizeMin
, BGRA_OR_4
,
598 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
603 _mesa_FogCoordPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
605 const GLbitfield legalTypes
= (HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
);
606 GET_CURRENT_CONTEXT(ctx
);
608 FLUSH_VERTICES(ctx
, 0);
610 update_array(ctx
, "glFogCoordPointer", VERT_ATTRIB_FOG
,
612 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
617 _mesa_IndexPointer(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
619 const GLbitfield legalTypes
= (UNSIGNED_BYTE_BIT
| SHORT_BIT
| INT_BIT
|
620 FLOAT_BIT
| DOUBLE_BIT
);
621 GET_CURRENT_CONTEXT(ctx
);
623 FLUSH_VERTICES(ctx
, 0);
625 update_array(ctx
, "glIndexPointer", VERT_ATTRIB_COLOR_INDEX
,
627 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
632 _mesa_SecondaryColorPointer(GLint size
, GLenum type
,
633 GLsizei stride
, const GLvoid
*ptr
)
635 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
636 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
637 INT_BIT
| UNSIGNED_INT_BIT
|
638 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
639 UNSIGNED_INT_2_10_10_10_REV_BIT
|
640 INT_2_10_10_10_REV_BIT
);
641 GET_CURRENT_CONTEXT(ctx
);
643 FLUSH_VERTICES(ctx
, 0);
645 update_array(ctx
, "glSecondaryColorPointer", VERT_ATTRIB_COLOR1
,
646 legalTypes
, 3, BGRA_OR_4
,
647 size
, type
, stride
, GL_TRUE
, GL_FALSE
, GL_FALSE
, ptr
);
652 _mesa_TexCoordPointer(GLint size
, GLenum type
, GLsizei stride
,
655 GET_CURRENT_CONTEXT(ctx
);
656 GLbitfield legalTypes
= (ctx
->API
== API_OPENGLES
)
657 ? (BYTE_BIT
| SHORT_BIT
| FLOAT_BIT
| FIXED_ES_BIT
)
658 : (SHORT_BIT
| INT_BIT
|
659 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
660 UNSIGNED_INT_2_10_10_10_REV_BIT
|
661 INT_2_10_10_10_REV_BIT
);
662 const GLint sizeMin
= (ctx
->API
== API_OPENGLES
) ? 2 : 1;
663 const GLuint unit
= ctx
->Array
.ActiveTexture
;
665 FLUSH_VERTICES(ctx
, 0);
667 update_array(ctx
, "glTexCoordPointer", VERT_ATTRIB_TEX(unit
),
668 legalTypes
, sizeMin
, 4,
669 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
,
675 _mesa_EdgeFlagPointer(GLsizei stride
, const GLvoid
*ptr
)
677 const GLbitfield legalTypes
= UNSIGNED_BYTE_BIT
;
678 /* this is the same type that glEdgeFlag uses */
679 const GLboolean integer
= GL_FALSE
;
680 GET_CURRENT_CONTEXT(ctx
);
682 FLUSH_VERTICES(ctx
, 0);
684 update_array(ctx
, "glEdgeFlagPointer", VERT_ATTRIB_EDGEFLAG
,
686 1, GL_UNSIGNED_BYTE
, stride
, GL_FALSE
, integer
, GL_FALSE
, ptr
);
691 _mesa_PointSizePointerOES(GLenum type
, GLsizei stride
, const GLvoid
*ptr
)
693 const GLbitfield legalTypes
= (FLOAT_BIT
| FIXED_ES_BIT
);
694 GET_CURRENT_CONTEXT(ctx
);
696 FLUSH_VERTICES(ctx
, 0);
698 if (ctx
->API
!= API_OPENGLES
) {
699 _mesa_error(ctx
, GL_INVALID_OPERATION
,
700 "glPointSizePointer(ES 1.x only)");
704 update_array(ctx
, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE
,
706 1, type
, stride
, GL_FALSE
, GL_FALSE
, GL_FALSE
, ptr
);
711 * Set a generic vertex attribute array.
712 * Note that these arrays DO NOT alias the conventional GL vertex arrays
713 * (position, normal, color, fog, texcoord, etc).
716 _mesa_VertexAttribPointer(GLuint index
, GLint size
, GLenum type
,
717 GLboolean normalized
,
718 GLsizei stride
, const GLvoid
*ptr
)
720 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
721 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
722 INT_BIT
| UNSIGNED_INT_BIT
|
723 HALF_BIT
| FLOAT_BIT
| DOUBLE_BIT
|
724 FIXED_ES_BIT
| FIXED_GL_BIT
|
725 UNSIGNED_INT_2_10_10_10_REV_BIT
|
726 INT_2_10_10_10_REV_BIT
|
727 UNSIGNED_INT_10F_11F_11F_REV_BIT
);
728 GET_CURRENT_CONTEXT(ctx
);
730 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
731 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribPointerARB(index)");
735 update_array(ctx
, "glVertexAttribPointer", VERT_ATTRIB_GENERIC(index
),
736 legalTypes
, 1, BGRA_OR_4
,
737 size
, type
, stride
, normalized
, GL_FALSE
, GL_FALSE
, ptr
);
742 * GL_EXT_gpu_shader4 / GL 3.0.
743 * Set an integer-valued vertex attribute array.
744 * Note that these arrays DO NOT alias the conventional GL vertex arrays
745 * (position, normal, color, fog, texcoord, etc).
748 _mesa_VertexAttribIPointer(GLuint index
, GLint size
, GLenum type
,
749 GLsizei stride
, const GLvoid
*ptr
)
751 const GLbitfield legalTypes
= (BYTE_BIT
| UNSIGNED_BYTE_BIT
|
752 SHORT_BIT
| UNSIGNED_SHORT_BIT
|
753 INT_BIT
| UNSIGNED_INT_BIT
);
754 const GLboolean normalized
= GL_FALSE
;
755 const GLboolean integer
= GL_TRUE
;
756 GET_CURRENT_CONTEXT(ctx
);
758 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
759 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribIPointer(index)");
763 update_array(ctx
, "glVertexAttribIPointer", VERT_ATTRIB_GENERIC(index
),
765 size
, type
, stride
, normalized
, integer
, GL_FALSE
, ptr
);
769 _mesa_VertexAttribLPointer(GLuint index
, GLint size
, GLenum type
,
770 GLsizei stride
, const GLvoid
*ptr
)
772 GET_CURRENT_CONTEXT(ctx
);
773 const GLbitfield legalTypes
= (DOUBLE_BIT
);
774 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
775 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribLPointer(index)");
779 update_array(ctx
, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index
),
781 size
, type
, stride
, GL_FALSE
, GL_FALSE
, GL_TRUE
, ptr
);
786 _mesa_enable_vertex_array_attrib(struct gl_context
*ctx
,
787 struct gl_vertex_array_object
*vao
,
790 assert(attrib
< ARRAY_SIZE(vao
->VertexAttrib
));
792 if (!vao
->VertexAttrib
[attrib
].Enabled
) {
793 /* was disabled, now being enabled */
794 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
795 vao
->VertexAttrib
[attrib
].Enabled
= GL_TRUE
;
796 vao
->_Enabled
|= VERT_BIT(attrib
);
797 vao
->NewArrays
|= VERT_BIT(attrib
);
802 enable_vertex_array_attrib(struct gl_context
*ctx
,
803 struct gl_vertex_array_object
*vao
,
807 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
808 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
812 _mesa_enable_vertex_array_attrib(ctx
, vao
, VERT_ATTRIB_GENERIC(index
));
817 _mesa_EnableVertexAttribArray(GLuint index
)
819 GET_CURRENT_CONTEXT(ctx
);
820 enable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
821 "glEnableVertexAttribArray");
826 _mesa_EnableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
828 GET_CURRENT_CONTEXT(ctx
);
829 struct gl_vertex_array_object
*vao
;
831 /* The ARB_direct_state_access specification says:
833 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
834 * and DisableVertexArrayAttrib if <vaobj> is not
835 * [compatibility profile: zero or] the name of an existing vertex
838 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glEnableVertexArrayAttrib");
842 enable_vertex_array_attrib(ctx
, vao
, index
, "glEnableVertexArrayAttrib");
847 disable_vertex_array_attrib(struct gl_context
*ctx
,
848 struct gl_vertex_array_object
*vao
,
852 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
853 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
857 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
859 if (vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
) {
860 /* was enabled, now being disabled */
861 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
862 vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Enabled
= GL_FALSE
;
863 vao
->_Enabled
&= ~VERT_BIT_GENERIC(index
);
864 vao
->NewArrays
|= VERT_BIT_GENERIC(index
);
870 _mesa_DisableVertexAttribArray(GLuint index
)
872 GET_CURRENT_CONTEXT(ctx
);
873 disable_vertex_array_attrib(ctx
, ctx
->Array
.VAO
, index
,
874 "glDisableVertexAttribArray");
879 _mesa_DisableVertexArrayAttrib(GLuint vaobj
, GLuint index
)
881 GET_CURRENT_CONTEXT(ctx
);
882 struct gl_vertex_array_object
*vao
;
884 /* The ARB_direct_state_access specification says:
886 * "An INVALID_OPERATION error is generated by EnableVertexArrayAttrib
887 * and DisableVertexArrayAttrib if <vaobj> is not
888 * [compatibility profile: zero or] the name of an existing vertex
891 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glDisableVertexArrayAttrib");
895 disable_vertex_array_attrib(ctx
, vao
, index
, "glDisableVertexArrayAttrib");
900 * Return info for a vertex attribute array (no alias with legacy
901 * vertex attributes (pos, normal, color, etc)). This function does
902 * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query.
905 get_vertex_array_attrib(struct gl_context
*ctx
,
906 const struct gl_vertex_array_object
*vao
,
907 GLuint index
, GLenum pname
,
910 const struct gl_array_attributes
*array
;
912 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
913 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index=%u)", caller
, index
);
917 assert(VERT_ATTRIB_GENERIC(index
) < ARRAY_SIZE(vao
->VertexAttrib
));
919 array
= &vao
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)];
922 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
923 return array
->Enabled
;
924 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
925 return (array
->Format
== GL_BGRA
) ? GL_BGRA
: array
->Size
;
926 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
927 return array
->Stride
;
928 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
930 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
931 return array
->Normalized
;
932 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
933 return vao
->BufferBinding
[array
->BufferBindingIndex
].BufferObj
->Name
;
934 case GL_VERTEX_ATTRIB_ARRAY_INTEGER
:
935 if ((_mesa_is_desktop_gl(ctx
)
936 && (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))
937 || _mesa_is_gles3(ctx
)) {
938 return array
->Integer
;
941 case GL_VERTEX_ATTRIB_ARRAY_LONG
:
942 if (_mesa_is_desktop_gl(ctx
)) {
943 return array
->Doubles
;
946 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB
:
947 if ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_instanced_arrays
)
948 || _mesa_is_gles3(ctx
)) {
949 return vao
->BufferBinding
[array
->BufferBindingIndex
].InstanceDivisor
;
952 case GL_VERTEX_ATTRIB_BINDING
:
953 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
954 return array
->BufferBindingIndex
- VERT_ATTRIB_GENERIC0
;
957 case GL_VERTEX_ATTRIB_RELATIVE_OFFSET
:
958 if (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
)) {
959 return array
->RelativeOffset
;
967 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=0x%x)", caller
, pname
);
972 static const GLfloat
*
973 get_current_attrib(struct gl_context
*ctx
, GLuint index
, const char *function
)
976 if (_mesa_attr_zero_aliases_vertex(ctx
)) {
977 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(index==0)", function
);
981 else if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
982 _mesa_error(ctx
, GL_INVALID_VALUE
,
983 "%s(index>=GL_MAX_VERTEX_ATTRIBS)", function
);
987 assert(VERT_ATTRIB_GENERIC(index
) <
988 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
990 FLUSH_CURRENT(ctx
, 0);
991 return ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC(index
)];
995 _mesa_GetVertexAttribfv(GLuint index
, GLenum pname
, GLfloat
*params
)
997 GET_CURRENT_CONTEXT(ctx
);
999 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1000 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribfv");
1006 params
[0] = (GLfloat
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1008 "glGetVertexAttribfv");
1014 _mesa_GetVertexAttribdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1016 GET_CURRENT_CONTEXT(ctx
);
1018 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1019 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribdv");
1021 params
[0] = (GLdouble
) v
[0];
1022 params
[1] = (GLdouble
) v
[1];
1023 params
[2] = (GLdouble
) v
[2];
1024 params
[3] = (GLdouble
) v
[3];
1028 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1030 "glGetVertexAttribdv");
1035 _mesa_GetVertexAttribLdv(GLuint index
, GLenum pname
, GLdouble
*params
)
1037 GET_CURRENT_CONTEXT(ctx
);
1039 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1041 (const GLdouble
*)get_current_attrib(ctx
, index
,
1042 "glGetVertexAttribLdv");
1051 params
[0] = (GLdouble
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1053 "glGetVertexAttribLdv");
1058 _mesa_GetVertexAttribiv(GLuint index
, GLenum pname
, GLint
*params
)
1060 GET_CURRENT_CONTEXT(ctx
);
1062 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1063 const GLfloat
*v
= get_current_attrib(ctx
, index
, "glGetVertexAttribiv");
1065 /* XXX should floats in[0,1] be scaled to full int range? */
1066 params
[0] = (GLint
) v
[0];
1067 params
[1] = (GLint
) v
[1];
1068 params
[2] = (GLint
) v
[2];
1069 params
[3] = (GLint
) v
[3];
1073 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1075 "glGetVertexAttribiv");
1082 _mesa_GetVertexAttribIiv(GLuint index
, GLenum pname
, GLint
*params
)
1084 GET_CURRENT_CONTEXT(ctx
);
1086 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1087 const GLint
*v
= (const GLint
*)
1088 get_current_attrib(ctx
, index
, "glGetVertexAttribIiv");
1094 params
[0] = (GLint
) get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1096 "glGetVertexAttribIiv");
1103 _mesa_GetVertexAttribIuiv(GLuint index
, GLenum pname
, GLuint
*params
)
1105 GET_CURRENT_CONTEXT(ctx
);
1107 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
1108 const GLuint
*v
= (const GLuint
*)
1109 get_current_attrib(ctx
, index
, "glGetVertexAttribIuiv");
1115 params
[0] = get_vertex_array_attrib(ctx
, ctx
->Array
.VAO
,
1117 "glGetVertexAttribIuiv");
1123 _mesa_GetVertexAttribPointerv(GLuint index
, GLenum pname
, GLvoid
**pointer
)
1125 GET_CURRENT_CONTEXT(ctx
);
1127 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1128 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
1132 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
1133 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
1137 assert(VERT_ATTRIB_GENERIC(index
) <
1138 ARRAY_SIZE(ctx
->Array
.VAO
->VertexAttrib
));
1140 *pointer
= (GLvoid
*)
1141 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC(index
)].Ptr
;
1145 /** ARB_direct_state_access */
1147 _mesa_GetVertexArrayIndexediv(GLuint vaobj
, GLuint index
,
1148 GLenum pname
, GLint
*params
)
1150 GET_CURRENT_CONTEXT(ctx
);
1151 struct gl_vertex_array_object
*vao
;
1153 /* The ARB_direct_state_access specification says:
1155 * "An INVALID_OPERATION error is generated if <vaobj> is not
1156 * [compatibility profile: zero or] the name of an existing
1157 * vertex array object."
1159 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexediv");
1163 /* The ARB_direct_state_access specification says:
1165 * "For GetVertexArrayIndexediv, <pname> must be one of
1166 * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE,
1167 * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE,
1168 * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER,
1169 * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or
1170 * VERTEX_ATTRIB_RELATIVE_OFFSET."
1174 * "Add GetVertexArrayIndexediv in 'Get Command' for
1175 * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING
1176 * VERTEX_ATTRIB_BINDING,
1177 * VERTEX_ATTRIB_RELATIVE_OFFSET,
1178 * VERTEX_BINDING_OFFSET, and
1179 * VERTEX_BINDING_STRIDE states"
1181 * The only parameter name common to both lists is
1182 * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER
1183 * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems
1184 * pretty clear however that the intent is that it should be possible
1185 * to query all vertex attrib and binding states that can be set with
1189 case GL_VERTEX_BINDING_OFFSET
:
1190 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1192 case GL_VERTEX_BINDING_STRIDE
:
1193 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1195 case GL_VERTEX_BINDING_DIVISOR
:
1196 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1198 case GL_VERTEX_BINDING_BUFFER
:
1199 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
1202 params
[0] = get_vertex_array_attrib(ctx
, vao
, index
, pname
,
1203 "glGetVertexArrayIndexediv");
1210 _mesa_GetVertexArrayIndexed64iv(GLuint vaobj
, GLuint index
,
1211 GLenum pname
, GLint64
*params
)
1213 GET_CURRENT_CONTEXT(ctx
);
1214 struct gl_vertex_array_object
*vao
;
1216 /* The ARB_direct_state_access specification says:
1218 * "An INVALID_OPERATION error is generated if <vaobj> is not
1219 * [compatibility profile: zero or] the name of an existing
1220 * vertex array object."
1222 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glGetVertexArrayIndexed64iv");
1226 /* The ARB_direct_state_access specification says:
1228 * "For GetVertexArrayIndexed64iv, <pname> must be
1229 * VERTEX_BINDING_OFFSET."
1233 * "An INVALID_ENUM error is generated if <pname> is not one of
1234 * the valid values listed above for the corresponding command."
1236 if (pname
!= GL_VERTEX_BINDING_OFFSET
) {
1237 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexArrayIndexed64iv("
1238 "pname != GL_VERTEX_BINDING_OFFSET)");
1242 /* The ARB_direct_state_access specification says:
1244 * "An INVALID_VALUE error is generated if <index> is greater than
1245 * or equal to the value of MAX_VERTEX_ATTRIBS."
1247 * Since the index refers to a buffer binding in this case, the intended
1248 * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently
1249 * required to be the same, so in practice this doesn't matter.
1251 if (index
>= ctx
->Const
.MaxVertexAttribBindings
) {
1252 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexArrayIndexed64iv(index"
1253 "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))",
1254 index
, ctx
->Const
.MaxVertexAttribBindings
);
1258 params
[0] = vao
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1263 _mesa_VertexPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1264 GLsizei count
, const GLvoid
*ptr
)
1267 _mesa_VertexPointer(size
, type
, stride
, ptr
);
1272 _mesa_NormalPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1276 _mesa_NormalPointer(type
, stride
, ptr
);
1281 _mesa_ColorPointerEXT(GLint size
, GLenum type
, GLsizei stride
, GLsizei count
,
1285 _mesa_ColorPointer(size
, type
, stride
, ptr
);
1290 _mesa_IndexPointerEXT(GLenum type
, GLsizei stride
, GLsizei count
,
1294 _mesa_IndexPointer(type
, stride
, ptr
);
1299 _mesa_TexCoordPointerEXT(GLint size
, GLenum type
, GLsizei stride
,
1300 GLsizei count
, const GLvoid
*ptr
)
1303 _mesa_TexCoordPointer(size
, type
, stride
, ptr
);
1308 _mesa_EdgeFlagPointerEXT(GLsizei stride
, GLsizei count
, const GLboolean
*ptr
)
1311 _mesa_EdgeFlagPointer(stride
, ptr
);
1316 _mesa_InterleavedArrays(GLenum format
, GLsizei stride
, const GLvoid
*pointer
)
1318 GET_CURRENT_CONTEXT(ctx
);
1319 GLboolean tflag
, cflag
, nflag
; /* enable/disable flags */
1320 GLint tcomps
, ccomps
, vcomps
; /* components per texcoord, color, vertex */
1321 GLenum ctype
= 0; /* color type */
1322 GLint coffset
= 0, noffset
= 0, voffset
;/* color, normal, vertex offsets */
1323 const GLint toffset
= 0; /* always zero */
1324 GLint defstride
; /* default stride */
1327 FLUSH_VERTICES(ctx
, 0);
1329 f
= sizeof(GLfloat
);
1330 c
= f
* ((4 * sizeof(GLubyte
) + (f
- 1)) / f
);
1333 _mesa_error( ctx
, GL_INVALID_VALUE
, "glInterleavedArrays(stride)" );
1339 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1340 tcomps
= 0; ccomps
= 0; vcomps
= 2;
1345 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1346 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1351 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1352 tcomps
= 0; ccomps
= 4; vcomps
= 2;
1353 ctype
= GL_UNSIGNED_BYTE
;
1356 defstride
= c
+ 2*f
;
1359 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1360 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1361 ctype
= GL_UNSIGNED_BYTE
;
1364 defstride
= c
+ 3*f
;
1367 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1368 tcomps
= 0; ccomps
= 3; vcomps
= 3;
1375 tflag
= GL_FALSE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1376 tcomps
= 0; ccomps
= 0; vcomps
= 3;
1381 case GL_C4F_N3F_V3F
:
1382 tflag
= GL_FALSE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1383 tcomps
= 0; ccomps
= 4; vcomps
= 3;
1391 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1392 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1397 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_FALSE
;
1398 tcomps
= 4; ccomps
= 0; vcomps
= 4;
1402 case GL_T2F_C4UB_V3F
:
1403 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1404 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1405 ctype
= GL_UNSIGNED_BYTE
;
1410 case GL_T2F_C3F_V3F
:
1411 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_FALSE
;
1412 tcomps
= 2; ccomps
= 3; vcomps
= 3;
1418 case GL_T2F_N3F_V3F
:
1419 tflag
= GL_TRUE
; cflag
= GL_FALSE
; nflag
= GL_TRUE
;
1420 tcomps
= 2; ccomps
= 0; vcomps
= 3;
1425 case GL_T2F_C4F_N3F_V3F
:
1426 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1427 tcomps
= 2; ccomps
= 4; vcomps
= 3;
1434 case GL_T4F_C4F_N3F_V4F
:
1435 tflag
= GL_TRUE
; cflag
= GL_TRUE
; nflag
= GL_TRUE
;
1436 tcomps
= 4; ccomps
= 4; vcomps
= 4;
1444 _mesa_error( ctx
, GL_INVALID_ENUM
, "glInterleavedArrays(format)" );
1452 _mesa_DisableClientState( GL_EDGE_FLAG_ARRAY
);
1453 _mesa_DisableClientState( GL_INDEX_ARRAY
);
1454 /* XXX also disable secondary color and generic arrays? */
1458 _mesa_EnableClientState( GL_TEXTURE_COORD_ARRAY
);
1459 _mesa_TexCoordPointer( tcomps
, GL_FLOAT
, stride
,
1460 (GLubyte
*) pointer
+ toffset
);
1463 _mesa_DisableClientState( GL_TEXTURE_COORD_ARRAY
);
1468 _mesa_EnableClientState( GL_COLOR_ARRAY
);
1469 _mesa_ColorPointer( ccomps
, ctype
, stride
,
1470 (GLubyte
*) pointer
+ coffset
);
1473 _mesa_DisableClientState( GL_COLOR_ARRAY
);
1479 _mesa_EnableClientState( GL_NORMAL_ARRAY
);
1480 _mesa_NormalPointer( GL_FLOAT
, stride
, (GLubyte
*) pointer
+ noffset
);
1483 _mesa_DisableClientState( GL_NORMAL_ARRAY
);
1487 _mesa_EnableClientState( GL_VERTEX_ARRAY
);
1488 _mesa_VertexPointer( vcomps
, GL_FLOAT
, stride
,
1489 (GLubyte
*) pointer
+ voffset
);
1494 _mesa_LockArraysEXT(GLint first
, GLsizei count
)
1496 GET_CURRENT_CONTEXT(ctx
);
1498 FLUSH_VERTICES(ctx
, 0);
1500 if (MESA_VERBOSE
& VERBOSE_API
)
1501 _mesa_debug(ctx
, "glLockArrays %d %d\n", first
, count
);
1504 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(first)" );
1508 _mesa_error( ctx
, GL_INVALID_VALUE
, "glLockArraysEXT(count)" );
1511 if (ctx
->Array
.LockCount
!= 0) {
1512 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glLockArraysEXT(reentry)" );
1516 ctx
->Array
.LockFirst
= first
;
1517 ctx
->Array
.LockCount
= count
;
1519 ctx
->NewState
|= _NEW_ARRAY
;
1524 _mesa_UnlockArraysEXT( void )
1526 GET_CURRENT_CONTEXT(ctx
);
1528 FLUSH_VERTICES(ctx
, 0);
1530 if (MESA_VERBOSE
& VERBOSE_API
)
1531 _mesa_debug(ctx
, "glUnlockArrays\n");
1533 if (ctx
->Array
.LockCount
== 0) {
1534 _mesa_error( ctx
, GL_INVALID_OPERATION
, "glUnlockArraysEXT(reexit)" );
1538 ctx
->Array
.LockFirst
= 0;
1539 ctx
->Array
.LockCount
= 0;
1540 ctx
->NewState
|= _NEW_ARRAY
;
1544 /* GL_EXT_multi_draw_arrays */
1546 _mesa_MultiDrawArrays( GLenum mode
, const GLint
*first
,
1547 const GLsizei
*count
, GLsizei primcount
)
1549 GET_CURRENT_CONTEXT(ctx
);
1552 FLUSH_VERTICES(ctx
, 0);
1554 for (i
= 0; i
< primcount
; i
++) {
1556 CALL_DrawArrays(ctx
->CurrentClientDispatch
, (mode
, first
[i
], count
[i
]));
1562 /* GL_IBM_multimode_draw_arrays */
1564 _mesa_MultiModeDrawArraysIBM( const GLenum
* mode
, const GLint
* first
,
1565 const GLsizei
* count
,
1566 GLsizei primcount
, GLint modestride
)
1568 GET_CURRENT_CONTEXT(ctx
);
1571 FLUSH_VERTICES(ctx
, 0);
1573 for ( i
= 0 ; i
< primcount
; i
++ ) {
1574 if ( count
[i
] > 0 ) {
1575 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1576 CALL_DrawArrays(ctx
->CurrentServerDispatch
, ( m
, first
[i
], count
[i
] ));
1582 /* GL_IBM_multimode_draw_arrays */
1584 _mesa_MultiModeDrawElementsIBM( const GLenum
* mode
, const GLsizei
* count
,
1585 GLenum type
, const GLvoid
* const * indices
,
1586 GLsizei primcount
, GLint modestride
)
1588 GET_CURRENT_CONTEXT(ctx
);
1591 FLUSH_VERTICES(ctx
, 0);
1593 /* XXX not sure about ARB_vertex_buffer_object handling here */
1595 for ( i
= 0 ; i
< primcount
; i
++ ) {
1596 if ( count
[i
] > 0 ) {
1597 GLenum m
= *((GLenum
*) ((GLubyte
*) mode
+ i
* modestride
));
1598 CALL_DrawElements(ctx
->CurrentServerDispatch
, ( m
, count
[i
], type
,
1606 * GL_NV_primitive_restart and GL 3.1
1609 _mesa_PrimitiveRestartIndex(GLuint index
)
1611 GET_CURRENT_CONTEXT(ctx
);
1613 if (!ctx
->Extensions
.NV_primitive_restart
&& ctx
->Version
< 31) {
1614 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glPrimitiveRestartIndexNV()");
1618 if (ctx
->Array
.RestartIndex
!= index
) {
1619 FLUSH_VERTICES(ctx
, _NEW_TRANSFORM
);
1620 ctx
->Array
.RestartIndex
= index
;
1626 * See GL_ARB_instanced_arrays.
1627 * Note that the instance divisor only applies to generic arrays, not
1628 * the legacy vertex arrays.
1631 _mesa_VertexAttribDivisor(GLuint index
, GLuint divisor
)
1633 GET_CURRENT_CONTEXT(ctx
);
1635 const GLuint genericIndex
= VERT_ATTRIB_GENERIC(index
);
1636 struct gl_vertex_array_object
* const vao
= ctx
->Array
.VAO
;
1638 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
1639 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glVertexAttribDivisor()");
1643 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
1644 _mesa_error(ctx
, GL_INVALID_VALUE
, "glVertexAttribDivisor(index = %u)",
1649 assert(genericIndex
< ARRAY_SIZE(vao
->VertexAttrib
));
1651 /* The ARB_vertex_attrib_binding spec says:
1655 * void VertexAttribDivisor(uint index, uint divisor);
1657 * is equivalent to (assuming no errors are generated):
1659 * VertexAttribBinding(index, index);
1660 * VertexBindingDivisor(index, divisor);"
1662 vertex_attrib_binding(ctx
, vao
, genericIndex
, genericIndex
);
1663 vertex_binding_divisor(ctx
, vao
, genericIndex
, divisor
);
1668 _mesa_primitive_restart_index(const struct gl_context
*ctx
, GLenum ib_type
)
1670 /* From the OpenGL 4.3 core specification, page 302:
1671 * "If both PRIMITIVE_RESTART and PRIMITIVE_RESTART_FIXED_INDEX are
1672 * enabled, the index value determined by PRIMITIVE_RESTART_FIXED_INDEX
1675 if (ctx
->Array
.PrimitiveRestartFixedIndex
) {
1677 case GL_UNSIGNED_BYTE
:
1679 case GL_UNSIGNED_SHORT
:
1681 case GL_UNSIGNED_INT
:
1684 assert(!"_mesa_primitive_restart_index: Invalid index buffer type.");
1688 return ctx
->Array
.RestartIndex
;
1693 * GL_ARB_vertex_attrib_binding
1696 vertex_array_vertex_buffer(struct gl_context
*ctx
,
1697 struct gl_vertex_array_object
*vao
,
1698 GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1699 GLsizei stride
, const char *func
)
1701 struct gl_buffer_object
*vbo
;
1703 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1705 /* The ARB_vertex_attrib_binding spec says:
1707 * "An INVALID_VALUE error is generated if <bindingindex> is greater than
1708 * the value of MAX_VERTEX_ATTRIB_BINDINGS."
1710 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
1711 _mesa_error(ctx
, GL_INVALID_VALUE
,
1712 "%s(bindingindex=%u > "
1713 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
1714 func
, bindingIndex
);
1718 /* The ARB_vertex_attrib_binding spec says:
1720 * "The error INVALID_VALUE is generated if <stride> or <offset>
1724 _mesa_error(ctx
, GL_INVALID_VALUE
,
1725 "%s(offset=%" PRId64
" < 0)",
1726 func
, (int64_t) offset
);
1731 _mesa_error(ctx
, GL_INVALID_VALUE
,
1732 "%s(stride=%d < 0)", func
, stride
);
1736 if (((ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44) || _mesa_is_gles31(ctx
)) &&
1737 stride
> ctx
->Const
.MaxVertexAttribStride
) {
1738 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride=%d > "
1739 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, stride
);
1744 vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
->Name
) {
1745 vbo
= vao
->BufferBinding
[VERT_ATTRIB_GENERIC(bindingIndex
)].BufferObj
;
1746 } else if (buffer
!= 0) {
1747 vbo
= _mesa_lookup_bufferobj(ctx
, buffer
);
1749 if (!vbo
&& _mesa_is_gles31(ctx
)) {
1750 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", func
);
1753 /* From the GL_ARB_vertex_attrib_array spec:
1755 * "[Core profile only:]
1756 * An INVALID_OPERATION error is generated if buffer is not zero or a
1757 * name returned from a previous call to GenBuffers, or if such a name
1758 * has since been deleted with DeleteBuffers.
1760 * Otherwise, we fall back to the same compat profile behavior as other
1761 * object references (automatically gen it).
1763 if (!_mesa_handle_bind_buffer_gen(ctx
, buffer
, &vbo
, func
))
1766 /* The ARB_vertex_attrib_binding spec says:
1768 * "If <buffer> is zero, any buffer object attached to this
1769 * bindpoint is detached."
1771 vbo
= ctx
->Shared
->NullBufferObj
;
1774 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
),
1775 vbo
, offset
, stride
);
1780 _mesa_BindVertexBuffer(GLuint bindingIndex
, GLuint buffer
, GLintptr offset
,
1783 GET_CURRENT_CONTEXT(ctx
);
1785 /* The ARB_vertex_attrib_binding spec says:
1787 * "An INVALID_OPERATION error is generated if no vertex array object
1790 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
1791 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1792 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1793 "glBindVertexBuffer(No array object bound)");
1797 vertex_array_vertex_buffer(ctx
, ctx
->Array
.VAO
, bindingIndex
,
1798 buffer
, offset
, stride
, "glBindVertexBuffer");
1803 _mesa_VertexArrayVertexBuffer(GLuint vaobj
, GLuint bindingIndex
, GLuint buffer
,
1804 GLintptr offset
, GLsizei stride
)
1806 GET_CURRENT_CONTEXT(ctx
);
1807 struct gl_vertex_array_object
*vao
;
1809 /* The ARB_direct_state_access specification says:
1811 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1812 * if <vaobj> is not [compatibility profile: zero or] the name of an
1813 * existing vertex array object."
1815 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffer");
1819 vertex_array_vertex_buffer(ctx
, vao
, bindingIndex
,
1820 buffer
, offset
, stride
,
1821 "glVertexArrayVertexBuffer");
1826 vertex_array_vertex_buffers(struct gl_context
*ctx
,
1827 struct gl_vertex_array_object
*vao
,
1828 GLuint first
, GLsizei count
, const GLuint
*buffers
,
1829 const GLintptr
*offsets
, const GLsizei
*strides
,
1834 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1836 /* The ARB_multi_bind spec says:
1838 * "An INVALID_OPERATION error is generated if <first> + <count>
1839 * is greater than the value of MAX_VERTEX_ATTRIB_BINDINGS."
1841 if (first
+ count
> ctx
->Const
.MaxVertexAttribBindings
) {
1842 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1843 "%s(first=%u + count=%d > the value of "
1844 "GL_MAX_VERTEX_ATTRIB_BINDINGS=%u)",
1845 func
, first
, count
, ctx
->Const
.MaxVertexAttribBindings
);
1851 * The ARB_multi_bind spec says:
1853 * "If <buffers> is NULL, each affected vertex buffer binding point
1854 * from <first> through <first>+<count>-1 will be reset to have no
1855 * bound buffer object. In this case, the offsets and strides
1856 * associated with the binding points are set to default values,
1857 * ignoring <offsets> and <strides>."
1859 struct gl_buffer_object
*vbo
= ctx
->Shared
->NullBufferObj
;
1861 for (i
= 0; i
< count
; i
++)
1862 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1868 /* Note that the error semantics for multi-bind commands differ from
1869 * those of other GL commands.
1871 * The Issues section in the ARB_multi_bind spec says:
1873 * "(11) Typically, OpenGL specifies that if an error is generated by
1874 * a command, that command has no effect. This is somewhat
1875 * unfortunate for multi-bind commands, because it would require
1876 * a first pass to scan the entire list of bound objects for
1877 * errors and then a second pass to actually perform the
1878 * bindings. Should we have different error semantics?
1880 * RESOLVED: Yes. In this specification, when the parameters for
1881 * one of the <count> binding points are invalid, that binding
1882 * point is not updated and an error will be generated. However,
1883 * other binding points in the same command will be updated if
1884 * their parameters are valid and no other error occurs."
1887 _mesa_begin_bufferobj_lookups(ctx
);
1889 for (i
= 0; i
< count
; i
++) {
1890 struct gl_buffer_object
*vbo
;
1892 /* The ARB_multi_bind spec says:
1894 * "An INVALID_VALUE error is generated if any value in
1895 * <offsets> or <strides> is negative (per binding)."
1897 if (offsets
[i
] < 0) {
1898 _mesa_error(ctx
, GL_INVALID_VALUE
,
1899 "%s(offsets[%u]=%" PRId64
" < 0)",
1900 func
, i
, (int64_t) offsets
[i
]);
1904 if (strides
[i
] < 0) {
1905 _mesa_error(ctx
, GL_INVALID_VALUE
,
1906 "%s(strides[%u]=%d < 0)",
1907 func
, i
, strides
[i
]);
1911 if (ctx
->API
== API_OPENGL_CORE
&& ctx
->Version
>= 44 &&
1912 strides
[i
] > ctx
->Const
.MaxVertexAttribStride
) {
1913 _mesa_error(ctx
, GL_INVALID_VALUE
,
1914 "%s(strides[%u]=%d > "
1915 "GL_MAX_VERTEX_ATTRIB_STRIDE)", func
, i
, strides
[i
]);
1920 struct gl_vertex_buffer_binding
*binding
=
1921 &vao
->BufferBinding
[VERT_ATTRIB_GENERIC(first
+ i
)];
1923 if (buffers
[i
] == binding
->BufferObj
->Name
)
1924 vbo
= binding
->BufferObj
;
1926 vbo
= _mesa_multi_bind_lookup_bufferobj(ctx
, buffers
, i
, func
);
1931 vbo
= ctx
->Shared
->NullBufferObj
;
1934 _mesa_bind_vertex_buffer(ctx
, vao
, VERT_ATTRIB_GENERIC(first
+ i
),
1935 vbo
, offsets
[i
], strides
[i
]);
1938 _mesa_end_bufferobj_lookups(ctx
);
1943 _mesa_BindVertexBuffers(GLuint first
, GLsizei count
, const GLuint
*buffers
,
1944 const GLintptr
*offsets
, const GLsizei
*strides
)
1946 GET_CURRENT_CONTEXT(ctx
);
1948 /* The ARB_vertex_attrib_binding spec says:
1950 * "An INVALID_OPERATION error is generated if no
1951 * vertex array object is bound."
1953 if (ctx
->API
== API_OPENGL_CORE
&&
1954 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1955 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1956 "glBindVertexBuffers(No array object bound)");
1960 vertex_array_vertex_buffers(ctx
, ctx
->Array
.VAO
, first
, count
,
1961 buffers
, offsets
, strides
,
1962 "glBindVertexBuffers");
1967 _mesa_VertexArrayVertexBuffers(GLuint vaobj
, GLuint first
, GLsizei count
,
1968 const GLuint
*buffers
,
1969 const GLintptr
*offsets
, const GLsizei
*strides
)
1971 GET_CURRENT_CONTEXT(ctx
);
1972 struct gl_vertex_array_object
*vao
;
1974 /* The ARB_direct_state_access specification says:
1976 * "An INVALID_OPERATION error is generated by VertexArrayVertexBuffer
1977 * if <vaobj> is not [compatibility profile: zero or] the name of an
1978 * existing vertex array object."
1980 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayVertexBuffers");
1984 vertex_array_vertex_buffers(ctx
, vao
, first
, count
,
1985 buffers
, offsets
, strides
,
1986 "glVertexArrayVertexBuffers");
1991 vertex_attrib_format(GLuint attribIndex
, GLint size
, GLenum type
,
1992 GLboolean normalized
, GLboolean integer
,
1993 GLboolean doubles
, GLbitfield legalTypes
,
1994 GLsizei maxSize
, GLuint relativeOffset
,
1997 GET_CURRENT_CONTEXT(ctx
);
1998 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2000 /* The ARB_vertex_attrib_binding spec says:
2002 * "An INVALID_OPERATION error is generated under any of the following
2004 * - if no vertex array object is currently bound (see section 2.10);
2007 * This error condition only applies to VertexAttribFormat and
2008 * VertexAttribIFormat in the extension spec, but we assume that this
2009 * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies
2010 * to all three functions.
2012 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2013 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2014 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2015 "%s(No array object bound)", func
);
2019 /* The ARB_vertex_attrib_binding spec says:
2021 * "The error INVALID_VALUE is generated if index is greater than or equal
2022 * to the value of MAX_VERTEX_ATTRIBS."
2024 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2025 _mesa_error(ctx
, GL_INVALID_VALUE
,
2026 "%s(attribindex=%u > "
2027 "GL_MAX_VERTEX_ATTRIBS)",
2032 FLUSH_VERTICES(ctx
, 0);
2034 update_array_format(ctx
, func
, ctx
->Array
.VAO
,
2035 VERT_ATTRIB_GENERIC(attribIndex
),
2036 legalTypes
, 1, maxSize
, size
, type
,
2037 normalized
, integer
, doubles
, relativeOffset
);
2042 _mesa_VertexAttribFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2043 GLboolean normalized
, GLuint relativeOffset
)
2045 vertex_attrib_format(attribIndex
, size
, type
, normalized
,
2046 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2047 BGRA_OR_4
, relativeOffset
,
2048 "glVertexAttribFormat");
2053 _mesa_VertexAttribIFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2054 GLuint relativeOffset
)
2056 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
,
2057 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
, 4,
2058 relativeOffset
, "glVertexAttribIFormat");
2063 _mesa_VertexAttribLFormat(GLuint attribIndex
, GLint size
, GLenum type
,
2064 GLuint relativeOffset
)
2066 vertex_attrib_format(attribIndex
, size
, type
, GL_FALSE
, GL_FALSE
,
2067 GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
, 4,
2068 relativeOffset
, "glVertexAttribLFormat");
2073 vertex_array_attrib_format(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2074 GLenum type
, GLboolean normalized
,
2075 GLboolean integer
, GLboolean doubles
,
2076 GLbitfield legalTypes
, GLsizei maxSize
,
2077 GLuint relativeOffset
, const char *func
)
2079 GET_CURRENT_CONTEXT(ctx
);
2080 struct gl_vertex_array_object
*vao
;
2082 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2084 /* The ARB_direct_state_access spec says:
2086 * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format
2087 * if <vaobj> is not [compatibility profile: zero or] the name of an
2088 * existing vertex array object."
2090 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, func
);
2094 /* The ARB_vertex_attrib_binding spec says:
2096 * "The error INVALID_VALUE is generated if index is greater than or equal
2097 * to the value of MAX_VERTEX_ATTRIBS."
2099 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2100 _mesa_error(ctx
, GL_INVALID_VALUE
,
2101 "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)",
2106 FLUSH_VERTICES(ctx
, 0);
2108 update_array_format(ctx
, func
, vao
,
2109 VERT_ATTRIB_GENERIC(attribIndex
),
2110 legalTypes
, 1, maxSize
, size
, type
, normalized
,
2111 integer
, doubles
, relativeOffset
);
2116 _mesa_VertexArrayAttribFormat(GLuint vaobj
, GLuint attribIndex
, GLint size
,
2117 GLenum type
, GLboolean normalized
,
2118 GLuint relativeOffset
)
2120 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, normalized
,
2121 GL_FALSE
, GL_FALSE
, ATTRIB_FORMAT_TYPES_MASK
,
2122 BGRA_OR_4
, relativeOffset
,
2123 "glVertexArrayAttribFormat");
2128 _mesa_VertexArrayAttribIFormat(GLuint vaobj
, GLuint attribIndex
,
2129 GLint size
, GLenum type
,
2130 GLuint relativeOffset
)
2132 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2133 GL_TRUE
, GL_FALSE
, ATTRIB_IFORMAT_TYPES_MASK
,
2135 "glVertexArrayAttribIFormat");
2140 _mesa_VertexArrayAttribLFormat(GLuint vaobj
, GLuint attribIndex
,
2141 GLint size
, GLenum type
,
2142 GLuint relativeOffset
)
2144 vertex_array_attrib_format(vaobj
, attribIndex
, size
, type
, GL_FALSE
,
2145 GL_FALSE
, GL_TRUE
, ATTRIB_LFORMAT_TYPES_MASK
,
2147 "glVertexArrayAttribLFormat");
2152 vertex_array_attrib_binding(struct gl_context
*ctx
,
2153 struct gl_vertex_array_object
*vao
,
2154 GLuint attribIndex
, GLuint bindingIndex
,
2157 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2159 /* The ARB_vertex_attrib_binding spec says:
2161 * "<attribindex> must be less than the value of MAX_VERTEX_ATTRIBS and
2162 * <bindingindex> must be less than the value of
2163 * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE
2166 if (attribIndex
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
2167 _mesa_error(ctx
, GL_INVALID_VALUE
,
2168 "%s(attribindex=%u >= "
2169 "GL_MAX_VERTEX_ATTRIBS)",
2174 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2175 _mesa_error(ctx
, GL_INVALID_VALUE
,
2176 "%s(bindingindex=%u >= "
2177 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2178 func
, bindingIndex
);
2182 assert(VERT_ATTRIB_GENERIC(attribIndex
) < ARRAY_SIZE(vao
->VertexAttrib
));
2184 vertex_attrib_binding(ctx
, vao
,
2185 VERT_ATTRIB_GENERIC(attribIndex
),
2186 VERT_ATTRIB_GENERIC(bindingIndex
));
2191 _mesa_VertexAttribBinding(GLuint attribIndex
, GLuint bindingIndex
)
2193 GET_CURRENT_CONTEXT(ctx
);
2195 /* The ARB_vertex_attrib_binding spec says:
2197 * "An INVALID_OPERATION error is generated if no vertex array object
2200 if ((ctx
->API
== API_OPENGL_CORE
|| _mesa_is_gles31(ctx
)) &&
2201 ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
2202 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2203 "glVertexAttribBinding(No array object bound)");
2207 vertex_array_attrib_binding(ctx
, ctx
->Array
.VAO
,
2208 attribIndex
, bindingIndex
,
2209 "glVertexAttribBinding");
2214 _mesa_VertexArrayAttribBinding(GLuint vaobj
, GLuint attribIndex
, GLuint bindingIndex
)
2216 GET_CURRENT_CONTEXT(ctx
);
2217 struct gl_vertex_array_object
*vao
;
2219 /* The ARB_direct_state_access specification says:
2221 * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding
2222 * if <vaobj> is not [compatibility profile: zero or] the name of an
2223 * existing vertex array object."
2225 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayAttribBinding");
2229 vertex_array_attrib_binding(ctx
, vao
, attribIndex
, bindingIndex
,
2230 "glVertexArrayAttribBinding");
2235 vertex_array_binding_divisor(struct gl_context
*ctx
,
2236 struct gl_vertex_array_object
*vao
,
2237 GLuint bindingIndex
, GLuint divisor
,
2240 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2242 if (!ctx
->Extensions
.ARB_instanced_arrays
) {
2243 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", func
);
2247 /* The ARB_vertex_attrib_binding spec says:
2249 * "An INVALID_VALUE error is generated if <bindingindex> is greater
2250 * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS."
2252 if (bindingIndex
>= ctx
->Const
.MaxVertexAttribBindings
) {
2253 _mesa_error(ctx
, GL_INVALID_VALUE
,
2254 "%s(bindingindex=%u > "
2255 "GL_MAX_VERTEX_ATTRIB_BINDINGS)",
2256 func
, bindingIndex
);
2260 vertex_binding_divisor(ctx
, vao
, VERT_ATTRIB_GENERIC(bindingIndex
), divisor
);
2265 _mesa_VertexBindingDivisor(GLuint bindingIndex
, GLuint divisor
)
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 "glVertexBindingDivisor(No array object bound)");
2281 vertex_array_binding_divisor(ctx
, ctx
->Array
.VAO
,
2282 bindingIndex
, divisor
,
2283 "glVertexBindingDivisor");
2288 _mesa_VertexArrayBindingDivisor(GLuint vaobj
, GLuint bindingIndex
,
2291 struct gl_vertex_array_object
*vao
;
2292 GET_CURRENT_CONTEXT(ctx
);
2294 /* The ARB_direct_state_access specification says:
2296 * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor
2297 * if <vaobj> is not [compatibility profile: zero or] the name of an
2298 * existing vertex array object."
2300 vao
= _mesa_lookup_vao_err(ctx
, vaobj
, "glVertexArrayBindingDivisor");
2304 vertex_array_binding_divisor(ctx
, vao
, bindingIndex
, divisor
,
2305 "glVertexArrayBindingDivisor");
2310 * Copy one client vertex array to another.
2313 _mesa_copy_client_array(struct gl_context
*ctx
,
2314 struct gl_vertex_array
*dst
,
2315 struct gl_vertex_array
*src
)
2317 dst
->Size
= src
->Size
;
2318 dst
->Type
= src
->Type
;
2319 dst
->Format
= src
->Format
;
2320 dst
->StrideB
= src
->StrideB
;
2321 dst
->Ptr
= src
->Ptr
;
2322 dst
->Normalized
= src
->Normalized
;
2323 dst
->Integer
= src
->Integer
;
2324 dst
->Doubles
= src
->Doubles
;
2325 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2326 dst
->_ElementSize
= src
->_ElementSize
;
2327 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2331 _mesa_copy_vertex_attrib_array(struct gl_context
*ctx
,
2332 struct gl_array_attributes
*dst
,
2333 const struct gl_array_attributes
*src
)
2335 dst
->Size
= src
->Size
;
2336 dst
->Type
= src
->Type
;
2337 dst
->Format
= src
->Format
;
2338 dst
->BufferBindingIndex
= src
->BufferBindingIndex
;
2339 dst
->RelativeOffset
= src
->RelativeOffset
;
2340 dst
->Format
= src
->Format
;
2341 dst
->Integer
= src
->Integer
;
2342 dst
->Doubles
= src
->Doubles
;
2343 dst
->Normalized
= src
->Normalized
;
2344 dst
->Ptr
= src
->Ptr
;
2345 dst
->Enabled
= src
->Enabled
;
2346 dst
->_ElementSize
= src
->_ElementSize
;
2350 _mesa_copy_vertex_buffer_binding(struct gl_context
*ctx
,
2351 struct gl_vertex_buffer_binding
*dst
,
2352 const struct gl_vertex_buffer_binding
*src
)
2354 dst
->Offset
= src
->Offset
;
2355 dst
->Stride
= src
->Stride
;
2356 dst
->InstanceDivisor
= src
->InstanceDivisor
;
2357 dst
->_BoundArrays
= src
->_BoundArrays
;
2359 _mesa_reference_buffer_object(ctx
, &dst
->BufferObj
, src
->BufferObj
);
2363 * Print current vertex object/array info. For debug.
2366 _mesa_print_arrays(struct gl_context
*ctx
)
2368 const struct gl_vertex_array_object
*vao
= ctx
->Array
.VAO
;
2370 fprintf(stderr
, "Array Object %u\n", vao
->Name
);
2373 for (i
= 0; i
< VERT_ATTRIB_MAX
; ++i
) {
2374 const struct gl_array_attributes
*array
= &vao
->VertexAttrib
[i
];
2375 if (!array
->Enabled
)
2378 const struct gl_vertex_buffer_binding
*binding
=
2379 &vao
->BufferBinding
[array
->BufferBindingIndex
];
2380 const struct gl_buffer_object
*bo
= binding
->BufferObj
;
2382 fprintf(stderr
, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, "
2383 "Stride=%d, Buffer=%u(Size %lu)\n",
2384 gl_vert_attrib_name((gl_vert_attrib
)i
),
2385 array
->Ptr
, _mesa_enum_to_string(array
->Type
), array
->Size
,
2386 array
->_ElementSize
, binding
->Stride
, bo
->Name
,
2387 (unsigned long) bo
->Size
);
2393 * Initialize vertex array state for given context.
2396 _mesa_init_varray(struct gl_context
*ctx
)
2398 ctx
->Array
.DefaultVAO
= _mesa_new_vao(ctx
, 0);
2399 _mesa_reference_vao(ctx
, &ctx
->Array
.VAO
, ctx
->Array
.DefaultVAO
);
2400 ctx
->Array
.ActiveTexture
= 0; /* GL_ARB_multitexture */
2402 ctx
->Array
.Objects
= _mesa_NewHashTable();
2407 * Callback for deleting an array object. Called by _mesa_HashDeleteAll().
2410 delete_arrayobj_cb(GLuint id
, void *data
, void *userData
)
2412 struct gl_vertex_array_object
*vao
= (struct gl_vertex_array_object
*) data
;
2413 struct gl_context
*ctx
= (struct gl_context
*) userData
;
2414 _mesa_delete_vao(ctx
, vao
);
2419 * Free vertex array state for given context.
2422 _mesa_free_varray_data(struct gl_context
*ctx
)
2424 _mesa_HashDeleteAll(ctx
->Array
.Objects
, delete_arrayobj_cb
, ctx
);
2425 _mesa_DeleteHashTable(ctx
->Array
.Objects
);